Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2018 Intel Corporation. 3 : : */ 4 : : 5 : : #include <rte_ethdev.h> 6 : : #include <rte_pci.h> 7 : : #include <rte_malloc.h> 8 : : 9 : : #include "ethdev_driver.h" 10 : : #include "base/ixgbe_type.h" 11 : : #include "base/ixgbe_vf.h" 12 : : #include "ixgbe_ethdev.h" 13 : : #include "ixgbe_rxtx.h" 14 : : #include "rte_pmd_ixgbe.h" 15 : : 16 : : 17 : : static int 18 : 0 : ixgbe_vf_representor_link_update(struct rte_eth_dev *ethdev, 19 : : int wait_to_complete) 20 : : { 21 : 0 : struct ixgbe_vf_representor *representor = ethdev->data->dev_private; 22 : : 23 : 0 : return ixgbe_dev_link_update_share(representor->pf_ethdev, 24 : : wait_to_complete, 0); 25 : : } 26 : : 27 : : static int 28 : 0 : ixgbe_vf_representor_mac_addr_set(struct rte_eth_dev *ethdev, 29 : : struct rte_ether_addr *mac_addr) 30 : : { 31 : 0 : struct ixgbe_vf_representor *representor = ethdev->data->dev_private; 32 : : 33 : 0 : return rte_pmd_ixgbe_set_vf_mac_addr( 34 : 0 : representor->pf_ethdev->data->port_id, 35 : 0 : representor->vf_id, mac_addr); 36 : : } 37 : : 38 : : static int 39 : 0 : ixgbe_vf_representor_dev_infos_get(struct rte_eth_dev *ethdev, 40 : : struct rte_eth_dev_info *dev_info) 41 : : { 42 : 0 : struct ixgbe_vf_representor *representor = ethdev->data->dev_private; 43 : : 44 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW( 45 : : representor->pf_ethdev->data->dev_private); 46 : : 47 : 0 : dev_info->device = representor->pf_ethdev->device; 48 : : 49 : 0 : dev_info->min_rx_bufsize = 1024; 50 : : /**< Minimum size of RX buffer. */ 51 : 0 : dev_info->max_rx_pktlen = 9728; 52 : : /**< Maximum configurable length of RX pkt. */ 53 : 0 : dev_info->max_rx_queues = IXGBE_VF_MAX_RX_QUEUES; 54 : : /**< Maximum number of RX queues. */ 55 : 0 : dev_info->max_tx_queues = IXGBE_VF_MAX_TX_QUEUES; 56 : : /**< Maximum number of TX queues. */ 57 : : 58 : 0 : dev_info->max_mac_addrs = hw->mac.num_rar_entries; 59 : : /**< Maximum number of MAC addresses. */ 60 : : 61 : 0 : dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP | 62 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM | 63 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM; 64 : : /**< Device RX offload capabilities. */ 65 : : 66 : 0 : dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT | 67 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | RTE_ETH_TX_OFFLOAD_UDP_CKSUM | 68 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM | RTE_ETH_TX_OFFLOAD_SCTP_CKSUM | 69 : : RTE_ETH_TX_OFFLOAD_TCP_TSO | RTE_ETH_TX_OFFLOAD_MULTI_SEGS; 70 : : /**< Device TX offload capabilities. */ 71 : : 72 : 0 : dev_info->speed_capa = 73 : 0 : representor->pf_ethdev->data->dev_link.link_speed; 74 : : /**< Supported speeds bitmap (RTE_ETH_LINK_SPEED_). */ 75 : : 76 : 0 : dev_info->switch_info.name = 77 : 0 : representor->pf_ethdev->device->name; 78 : 0 : dev_info->switch_info.domain_id = representor->switch_domain_id; 79 : 0 : dev_info->switch_info.port_id = representor->vf_id; 80 : : 81 : 0 : return 0; 82 : : } 83 : : 84 : 0 : static int ixgbe_vf_representor_dev_configure( 85 : : __rte_unused struct rte_eth_dev *dev) 86 : : { 87 : 0 : return 0; 88 : : } 89 : : 90 : 0 : static int ixgbe_vf_representor_rx_queue_setup( 91 : : __rte_unused struct rte_eth_dev *dev, 92 : : __rte_unused uint16_t rx_queue_id, 93 : : __rte_unused uint16_t nb_rx_desc, 94 : : __rte_unused unsigned int socket_id, 95 : : __rte_unused const struct rte_eth_rxconf *rx_conf, 96 : : __rte_unused struct rte_mempool *mb_pool) 97 : : { 98 : 0 : return 0; 99 : : } 100 : : 101 : 0 : static int ixgbe_vf_representor_tx_queue_setup( 102 : : __rte_unused struct rte_eth_dev *dev, 103 : : __rte_unused uint16_t rx_queue_id, 104 : : __rte_unused uint16_t nb_rx_desc, 105 : : __rte_unused unsigned int socket_id, 106 : : __rte_unused const struct rte_eth_txconf *tx_conf) 107 : : { 108 : 0 : return 0; 109 : : } 110 : : 111 : 0 : static int ixgbe_vf_representor_dev_start(__rte_unused struct rte_eth_dev *dev) 112 : : { 113 : 0 : return 0; 114 : : } 115 : : 116 : 0 : static int ixgbe_vf_representor_dev_stop(__rte_unused struct rte_eth_dev *dev) 117 : : { 118 : 0 : return 0; 119 : : } 120 : : 121 : : static int 122 : 0 : ixgbe_vf_representor_vlan_filter_set(struct rte_eth_dev *ethdev, 123 : : uint16_t vlan_id, int on) 124 : : { 125 : 0 : struct ixgbe_vf_representor *representor = ethdev->data->dev_private; 126 : 0 : uint64_t vf_mask = 1ULL << representor->vf_id; 127 : : 128 : 0 : return rte_pmd_ixgbe_set_vf_vlan_filter( 129 : 0 : representor->pf_ethdev->data->port_id, vlan_id, vf_mask, on); 130 : : } 131 : : 132 : : static void 133 : 0 : ixgbe_vf_representor_vlan_strip_queue_set(struct rte_eth_dev *ethdev, 134 : : __rte_unused uint16_t rx_queue_id, int on) 135 : : { 136 : 0 : struct ixgbe_vf_representor *representor = ethdev->data->dev_private; 137 : : 138 : 0 : rte_pmd_ixgbe_set_vf_vlan_stripq(representor->pf_ethdev->data->port_id, 139 : 0 : representor->vf_id, on); 140 : 0 : } 141 : : 142 : : static const struct eth_dev_ops ixgbe_vf_representor_dev_ops = { 143 : : .dev_infos_get = ixgbe_vf_representor_dev_infos_get, 144 : : 145 : : .dev_start = ixgbe_vf_representor_dev_start, 146 : : .dev_configure = ixgbe_vf_representor_dev_configure, 147 : : .dev_stop = ixgbe_vf_representor_dev_stop, 148 : : 149 : : .rx_queue_setup = ixgbe_vf_representor_rx_queue_setup, 150 : : .tx_queue_setup = ixgbe_vf_representor_tx_queue_setup, 151 : : 152 : : .link_update = ixgbe_vf_representor_link_update, 153 : : 154 : : .vlan_filter_set = ixgbe_vf_representor_vlan_filter_set, 155 : : .vlan_strip_queue_set = ixgbe_vf_representor_vlan_strip_queue_set, 156 : : 157 : : .mac_addr_set = ixgbe_vf_representor_mac_addr_set, 158 : : }; 159 : : 160 : : static uint16_t 161 : 0 : ixgbe_vf_representor_rx_burst(__rte_unused void *rx_queue, 162 : : __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts) 163 : : { 164 : 0 : return 0; 165 : : } 166 : : 167 : : static uint16_t 168 : 0 : ixgbe_vf_representor_tx_burst(__rte_unused void *tx_queue, 169 : : __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts) 170 : : { 171 : 0 : return 0; 172 : : } 173 : : 174 : : int 175 : 0 : ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params) 176 : : { 177 : 0 : struct ixgbe_vf_representor *representor = ethdev->data->dev_private; 178 : : 179 : : struct ixgbe_vf_info *vf_data; 180 : : struct rte_pci_device *pci_dev; 181 : : struct rte_eth_link *link; 182 : : 183 [ # # ]: 0 : if (!representor) 184 : : return -ENOMEM; 185 : : 186 : 0 : representor->vf_id = 187 : 0 : ((struct ixgbe_vf_representor *)init_params)->vf_id; 188 : 0 : representor->switch_domain_id = 189 : 0 : ((struct ixgbe_vf_representor *)init_params)->switch_domain_id; 190 : 0 : representor->pf_ethdev = 191 : 0 : ((struct ixgbe_vf_representor *)init_params)->pf_ethdev; 192 : : 193 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(representor->pf_ethdev); 194 : : 195 [ # # ]: 0 : if (representor->vf_id >= pci_dev->max_vfs) 196 : : return -ENODEV; 197 : : 198 : 0 : ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; 199 : 0 : ethdev->data->representor_id = representor->vf_id; 200 : 0 : ethdev->data->backer_port_id = representor->pf_ethdev->data->port_id; 201 : : 202 : : /* Set representor device ops */ 203 : 0 : ethdev->dev_ops = &ixgbe_vf_representor_dev_ops; 204 : : 205 : : /* No data-path, but need stub Rx/Tx functions to avoid crash 206 : : * when testing with the likes of testpmd. 207 : : */ 208 : 0 : ethdev->rx_pkt_burst = ixgbe_vf_representor_rx_burst; 209 : 0 : ethdev->tx_pkt_burst = ixgbe_vf_representor_tx_burst; 210 : : 211 : : /* Setting the number queues allocated to the VF */ 212 : 0 : ethdev->data->nb_rx_queues = IXGBE_VF_MAX_RX_QUEUES; 213 : 0 : ethdev->data->nb_tx_queues = IXGBE_VF_MAX_RX_QUEUES; 214 : : 215 : : /* Reference VF mac address from PF data structure */ 216 : 0 : vf_data = *IXGBE_DEV_PRIVATE_TO_P_VFDATA( 217 : : representor->pf_ethdev->data->dev_private); 218 : : 219 : 0 : ethdev->data->mac_addrs = (struct rte_ether_addr *) 220 : 0 : vf_data[representor->vf_id].vf_mac_addresses; 221 : : 222 : : /* Link state. Inherited from PF */ 223 : : link = &representor->pf_ethdev->data->dev_link; 224 : : 225 : 0 : ethdev->data->dev_link.link_speed = link->link_speed; 226 : 0 : ethdev->data->dev_link.link_duplex = link->link_duplex; 227 : 0 : ethdev->data->dev_link.link_status = link->link_status; 228 : 0 : ethdev->data->dev_link.link_autoneg = link->link_autoneg; 229 : : 230 : 0 : return 0; 231 : : } 232 : : 233 : : int 234 : 0 : ixgbe_vf_representor_uninit(struct rte_eth_dev *ethdev) 235 : : { 236 : : /* mac_addrs must not be freed because part of ixgbe_vf_info */ 237 : 0 : ethdev->data->mac_addrs = NULL; 238 : : 239 : 0 : return 0; 240 : : }