Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include <sys/queue.h>
7 : : #include <stdio.h>
8 : : #include <errno.h>
9 : : #include <stdint.h>
10 : : #include <string.h>
11 : : #include <rte_log.h>
12 : : #include <ethdev_pci.h>
13 : : #include <rte_alarm.h>
14 : :
15 : : #include "txgbe_logs.h"
16 : : #include "base/txgbe.h"
17 : : #include "txgbe_ethdev.h"
18 : : #include "txgbe_rxtx.h"
19 : : #include "txgbe_regs_group.h"
20 : :
21 : : static const struct reg_info txgbevf_regs_general[] = {
22 : : {TXGBE_VFRST, 1, 1, "TXGBE_VFRST"},
23 : : {TXGBE_VFSTATUS, 1, 1, "TXGBE_VFSTATUS"},
24 : : {TXGBE_VFMBCTL, 1, 1, "TXGBE_VFMAILBOX"},
25 : : {TXGBE_VFMBX, 16, 4, "TXGBE_VFMBX"},
26 : : {TXGBE_VFPBWRAP, 1, 1, "TXGBE_VFPBWRAP"},
27 : : {0, 0, 0, ""}
28 : : };
29 : :
30 : : static const struct reg_info txgbevf_regs_interrupt[] = {
31 : : {0, 0, 0, ""}
32 : : };
33 : :
34 : : static const struct reg_info txgbevf_regs_rxdma[] = {
35 : : {0, 0, 0, ""}
36 : : };
37 : :
38 : : static const struct reg_info txgbevf_regs_tx[] = {
39 : : {0, 0, 0, ""}
40 : : };
41 : :
42 : : /* VF registers */
43 : : static const struct reg_info *txgbevf_regs[] = {
44 : : txgbevf_regs_general,
45 : : txgbevf_regs_interrupt,
46 : : txgbevf_regs_rxdma,
47 : : txgbevf_regs_tx,
48 : : NULL};
49 : :
50 : : static int txgbevf_dev_xstats_get(struct rte_eth_dev *dev,
51 : : struct rte_eth_xstat *xstats, unsigned int n);
52 : : static int txgbevf_dev_info_get(struct rte_eth_dev *dev,
53 : : struct rte_eth_dev_info *dev_info);
54 : : static int txgbevf_dev_configure(struct rte_eth_dev *dev);
55 : : static int txgbevf_dev_start(struct rte_eth_dev *dev);
56 : : static int txgbevf_dev_link_update(struct rte_eth_dev *dev,
57 : : int wait_to_complete);
58 : : static int txgbevf_dev_stop(struct rte_eth_dev *dev);
59 : : static int txgbevf_dev_close(struct rte_eth_dev *dev);
60 : : static void txgbevf_intr_disable(struct rte_eth_dev *dev);
61 : : static void txgbevf_intr_enable(struct rte_eth_dev *dev);
62 : : static int txgbevf_dev_stats_reset(struct rte_eth_dev *dev);
63 : : static int txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
64 : : static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
65 : : static void txgbevf_configure_msix(struct rte_eth_dev *dev);
66 : : static int txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev);
67 : : static int txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev);
68 : : static void txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
69 : : static void txgbevf_dev_interrupt_handler(void *param);
70 : :
71 : : /*
72 : : * The set of PCI devices this driver supports (for VF)
73 : : */
74 : : static const struct rte_pci_id pci_id_txgbevf_map[] = {
75 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_SP1000_VF) },
76 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_WX1820_VF) },
77 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_AML_VF) },
78 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_AML5024_VF) },
79 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_AML5124_VF) },
80 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_AML503F_VF) },
81 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_AML513F_VF) },
82 : : { .vendor_id = 0, /* sentinel */ },
83 : : };
84 : :
85 : : static const struct rte_eth_desc_lim rx_desc_lim = {
86 : : .nb_max = TXGBE_RING_DESC_MAX,
87 : : .nb_min = TXGBE_RING_DESC_MIN,
88 : : .nb_align = TXGBE_RXD_ALIGN,
89 : : };
90 : :
91 : : static const struct rte_eth_desc_lim tx_desc_lim = {
92 : : .nb_max = TXGBE_RING_DESC_MAX,
93 : : .nb_min = TXGBE_RING_DESC_MIN,
94 : : .nb_align = TXGBE_TXD_ALIGN,
95 : : .nb_seg_max = TXGBE_TX_MAX_SEG,
96 : : .nb_mtu_seg_max = TXGBE_TX_MAX_SEG,
97 : : };
98 : :
99 : : static const struct eth_dev_ops txgbevf_eth_dev_ops;
100 : :
101 : : static const struct rte_txgbe_xstats_name_off rte_txgbevf_stats_strings[] = {
102 : : {"rx_multicast_packets_0",
103 : : offsetof(struct txgbevf_hw_stats, qp[0].vfmprc)},
104 : : {"rx_multicast_packets_1",
105 : : offsetof(struct txgbevf_hw_stats, qp[1].vfmprc)},
106 : : {"rx_multicast_packets_2",
107 : : offsetof(struct txgbevf_hw_stats, qp[2].vfmprc)},
108 : : {"rx_multicast_packets_3",
109 : : offsetof(struct txgbevf_hw_stats, qp[3].vfmprc)},
110 : : {"rx_multicast_packets_4",
111 : : offsetof(struct txgbevf_hw_stats, qp[4].vfmprc)},
112 : : {"rx_multicast_packets_5",
113 : : offsetof(struct txgbevf_hw_stats, qp[5].vfmprc)},
114 : : {"rx_multicast_packets_6",
115 : : offsetof(struct txgbevf_hw_stats, qp[6].vfmprc)},
116 : : {"rx_multicast_packets_7",
117 : : offsetof(struct txgbevf_hw_stats, qp[7].vfmprc)}
118 : : };
119 : :
120 : : #define TXGBEVF_NB_XSTATS (sizeof(rte_txgbevf_stats_strings) / \
121 : : sizeof(rte_txgbevf_stats_strings[0]))
122 : :
123 : : /*
124 : : * Negotiate mailbox API version with the PF.
125 : : * After reset API version is always set to the basic one (txgbe_mbox_api_10).
126 : : * Then we try to negotiate starting with the most recent one.
127 : : * If all negotiation attempts fail, then we will proceed with
128 : : * the default one (txgbe_mbox_api_10).
129 : : */
130 : : static void
131 : 0 : txgbevf_negotiate_api(struct txgbe_hw *hw)
132 : : {
133 : : int32_t i;
134 : :
135 : : /* start with highest supported, proceed down */
136 : : static const int sup_ver[] = {
137 : : txgbe_mbox_api_23,
138 : : txgbe_mbox_api_21,
139 : : txgbe_mbox_api_13,
140 : : txgbe_mbox_api_12,
141 : : txgbe_mbox_api_11,
142 : : txgbe_mbox_api_10,
143 : : };
144 : :
145 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(sup_ver); i++) {
146 [ # # ]: 0 : if (txgbevf_negotiate_api_version(hw, sup_ver[i]) == 0)
147 : : break;
148 : : }
149 : 0 : }
150 : :
151 : : static void
152 : 0 : generate_random_mac_addr(struct rte_ether_addr *mac_addr)
153 : : {
154 : : uint64_t random;
155 : :
156 : : /* Set Organizationally Unique Identifier (OUI) prefix. */
157 : : mac_addr->addr_bytes[0] = 0x00;
158 : 0 : mac_addr->addr_bytes[1] = 0x09;
159 : 0 : mac_addr->addr_bytes[2] = 0xC0;
160 : : /* Force indication of locally assigned MAC address. */
161 : 0 : mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
162 : : /* Generate the last 3 bytes of the MAC address with a random number. */
163 : 0 : random = rte_rand();
164 : 0 : memcpy(&mac_addr->addr_bytes[3], &random, 3);
165 : 0 : }
166 : :
167 : : int
168 : 0 : txgbevf_inject_5tuple_filter(struct rte_eth_dev *dev,
169 : : struct txgbe_5tuple_filter *filter)
170 : : {
171 : 0 : struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
172 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
173 : : uint32_t mask = TXGBE_5TFCTL0_MASK;
174 [ # # ]: 0 : uint16_t index = filter->index;
175 : : uint32_t msg[TXGBEVF_5T_MAX];
176 : : int err;
177 : :
178 : : memset(msg, 0, sizeof(msg));
179 : :
180 : : /* 0 means compare */
181 : : mask &= ~TXGBE_5TFCTL0_MPOOL;
182 [ # # ]: 0 : if (filter->filter_info.src_ip_mask == 0)
183 : : mask &= ~TXGBE_5TFCTL0_MSADDR;
184 [ # # ]: 0 : if (filter->filter_info.dst_ip_mask == 0)
185 : 0 : mask &= ~TXGBE_5TFCTL0_MDADDR;
186 [ # # ]: 0 : if (filter->filter_info.src_port_mask == 0)
187 : 0 : mask &= ~TXGBE_5TFCTL0_MSPORT;
188 [ # # ]: 0 : if (filter->filter_info.dst_port_mask == 0)
189 : 0 : mask &= ~TXGBE_5TFCTL0_MDPORT;
190 [ # # ]: 0 : if (filter->filter_info.proto_mask == 0)
191 : 0 : mask &= ~TXGBE_5TFCTL0_MPROTO;
192 : :
193 : : msg[TXGBEVF_5T_CTRL0] = mask;
194 : 0 : msg[TXGBEVF_5T_CTRL0] |= TXGBE_5TFCTL0_ENA;
195 : 0 : msg[TXGBEVF_5T_CTRL0] |= TXGBE_5TFCTL0_PROTO(filter->filter_info.proto);
196 : 0 : msg[TXGBEVF_5T_CTRL0] |= TXGBE_5TFCTL0_PRI(filter->filter_info.priority);
197 : 0 : msg[TXGBEVF_5T_CTRL1] = TXGBE_5TFCTL1_QP(filter->queue);
198 [ # # ]: 0 : msg[TXGBEVF_5T_PORT] = TXGBE_5TFPORT_DST(be_to_le16(filter->filter_info.dst_port));
199 [ # # ]: 0 : msg[TXGBEVF_5T_PORT] |= TXGBE_5TFPORT_SRC(be_to_le16(filter->filter_info.src_port));
200 [ # # ]: 0 : msg[TXGBEVF_5T_DA] = be_to_le32(filter->filter_info.dst_ip);
201 [ # # ]: 0 : msg[TXGBEVF_5T_SA] = be_to_le32(filter->filter_info.src_ip);
202 : :
203 : 0 : err = txgbevf_add_5tuple_filter(hw, msg, index);
204 [ # # ]: 0 : if (!err)
205 : : return 0;
206 : :
207 [ # # ]: 0 : if (msg[TXGBEVF_5T_REQ] & TXGBE_VT_MSGTYPE_SPEC) {
208 : 0 : PMD_DRV_LOG(INFO, "5tuple filters are full, switch to FDIR");
209 : 0 : filter_info->ntuple_is_full = true;
210 : 0 : return -ENOSYS;
211 : : }
212 : :
213 : 0 : PMD_DRV_LOG(ERR, "VF request PF to add 5tuple filters failed.");
214 : 0 : return err;
215 : : }
216 : :
217 : : void
218 : 0 : txgbevf_remove_5tuple_filter(struct rte_eth_dev *dev, u16 index)
219 : : {
220 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
221 : : int err;
222 : :
223 : 0 : err = txgbevf_del_5tuple_filter(hw, index);
224 [ # # ]: 0 : if (err)
225 : 0 : PMD_DRV_LOG(ERR, "VF request PF to delete 5tuple filters failed.");
226 : 0 : }
227 : :
228 : : /*
229 : : * Virtual Function device init
230 : : */
231 : : static int
232 : 0 : eth_txgbevf_dev_init(struct rte_eth_dev *eth_dev)
233 : : {
234 : : int err;
235 : : uint32_t tc, tcs;
236 : 0 : struct txgbe_adapter *ad = eth_dev->data->dev_private;
237 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *pci_dev);
238 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
239 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
240 : 0 : struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(eth_dev);
241 : 0 : struct txgbe_hwstrip *hwstrip = TXGBE_DEV_HWSTRIP(eth_dev);
242 : 0 : struct rte_ether_addr *perm_addr =
243 : : (struct rte_ether_addr *)hw->mac.perm_addr;
244 : 0 : struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(eth_dev);
245 : :
246 : 0 : PMD_INIT_FUNC_TRACE();
247 : :
248 : 0 : eth_dev->dev_ops = &txgbevf_eth_dev_ops;
249 : 0 : eth_dev->rx_descriptor_status = txgbe_dev_rx_descriptor_status;
250 : 0 : eth_dev->tx_descriptor_status = txgbe_dev_tx_descriptor_status;
251 : 0 : eth_dev->rx_pkt_burst = &txgbe_recv_pkts;
252 : 0 : eth_dev->tx_pkt_burst = &txgbe_xmit_pkts;
253 : :
254 : : /* for secondary processes, we don't initialise any further as primary
255 : : * has already done this work. Only check we don't need a different
256 : : * RX function
257 : : */
258 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
259 : : struct txgbe_tx_queue *txq;
260 : 0 : uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
261 : : /* TX queue function in primary, set by last queue initialized
262 : : * Tx queue may not initialized by primary process
263 : : */
264 [ # # ]: 0 : if (eth_dev->data->tx_queues) {
265 : 0 : txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
266 : 0 : txgbe_set_tx_function(eth_dev, txq);
267 : : } else {
268 : : /* Use default TX function if we get here */
269 : 0 : PMD_INIT_LOG(NOTICE,
270 : : "No TX queues configured yet. Using default TX function.");
271 : : }
272 : :
273 : 0 : txgbe_set_rx_function(eth_dev);
274 : :
275 : 0 : return 0;
276 : : }
277 : :
278 : 0 : rte_atomic_store_explicit(&ad->link_thread_running, 0, rte_memory_order_seq_cst);
279 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
280 : :
281 : 0 : hw->device_id = pci_dev->id.device_id;
282 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
283 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
284 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
285 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
286 : 0 : rte_atomic_store_explicit(&hw->pf_running, true,
287 : : rte_memory_order_release);
288 : :
289 : : /* initialize the vfta */
290 : : memset(shadow_vfta, 0, sizeof(*shadow_vfta));
291 : :
292 : : /* initialize the hw strip bitmap*/
293 : : memset(hwstrip, 0, sizeof(*hwstrip));
294 : :
295 : : /* Initialize the shared code (base driver) */
296 : 0 : err = txgbe_init_shared_code(hw);
297 [ # # ]: 0 : if (err != 0) {
298 : 0 : PMD_INIT_LOG(ERR,
299 : : "Shared code init failed for txgbevf: %d", err);
300 : 0 : return -EIO;
301 : : }
302 : :
303 : : /* init_mailbox_params */
304 : 0 : hw->mbx.init_params(hw);
305 : :
306 : : /* Reset the hw statistics */
307 : 0 : txgbevf_dev_stats_reset(eth_dev);
308 : :
309 : : /* Disable the interrupts for VF */
310 : 0 : txgbevf_intr_disable(eth_dev);
311 : :
312 : 0 : hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
313 : 0 : err = hw->mac.reset_hw(hw);
314 : :
315 : : /*
316 : : * The VF reset operation returns the TXGBE_ERR_INVALID_MAC_ADDR when
317 : : * the underlying PF driver has not assigned a MAC address to the VF.
318 : : * In this case, assign a random MAC address.
319 : : */
320 [ # # ]: 0 : if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
321 : 0 : PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
322 : : /*
323 : : * This error code will be propagated to the app by
324 : : * rte_eth_dev_reset, so use a public error code rather than
325 : : * the internal-only TXGBE_ERR_RESET_FAILED
326 : : */
327 : 0 : return -EAGAIN;
328 : : }
329 : :
330 : : /* negotiate mailbox API version to use with the PF. */
331 : 0 : txgbevf_negotiate_api(hw);
332 : :
333 : : /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
334 : 0 : txgbevf_get_queues(hw, &tcs, &tc);
335 : :
336 : : /* Allocate memory for storing MAC addresses */
337 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("txgbevf", RTE_ETHER_ADDR_LEN *
338 : 0 : hw->mac.num_rar_entries, 0);
339 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
340 : 0 : PMD_INIT_LOG(ERR,
341 : : "Failed to allocate %u bytes needed to store "
342 : : "MAC addresses",
343 : : RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
344 : 0 : return -ENOMEM;
345 : : }
346 : :
347 : : /* Generate a random MAC address, if none was assigned by PF. */
348 [ # # ]: 0 : if (rte_is_zero_ether_addr(perm_addr)) {
349 : 0 : generate_random_mac_addr(perm_addr);
350 : 0 : err = txgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
351 [ # # ]: 0 : if (err) {
352 : 0 : rte_free(eth_dev->data->mac_addrs);
353 : 0 : eth_dev->data->mac_addrs = NULL;
354 : 0 : return err;
355 : : }
356 : 0 : PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
357 : 0 : PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
358 : : RTE_ETHER_ADDR_PRT_FMT,
359 : : RTE_ETHER_ADDR_BYTES(perm_addr));
360 : : }
361 : :
362 : : /* Copy the permanent MAC address */
363 : 0 : rte_ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
364 : :
365 : : /* reset the hardware with the new settings */
366 : 0 : err = hw->mac.start_hw(hw);
367 [ # # ]: 0 : if (err) {
368 : 0 : PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
369 : 0 : rte_free(eth_dev->data->mac_addrs);
370 : 0 : eth_dev->data->mac_addrs = NULL;
371 : 0 : return -EIO;
372 : : }
373 : :
374 : : /* enter promiscuous mode */
375 : : txgbevf_dev_promiscuous_enable(eth_dev);
376 : :
377 : 0 : rte_intr_callback_register(intr_handle,
378 : : txgbevf_dev_interrupt_handler, eth_dev);
379 : 0 : rte_intr_enable(intr_handle);
380 : 0 : txgbevf_intr_enable(eth_dev);
381 : :
382 : : /* initialize filter info */
383 : : memset(filter_info, 0,
384 : : sizeof(struct txgbe_filter_info));
385 : :
386 : : /* initialize flow director filter list & hash */
387 : 0 : txgbe_fdir_filter_init(eth_dev);
388 : :
389 : : /* initialize 5tuple filter list */
390 : 0 : TAILQ_INIT(&filter_info->fivetuple_list);
391 : :
392 : : /* initialize flow filter lists */
393 : 0 : txgbe_filterlist_init(eth_dev);
394 : :
395 : 0 : PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
396 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
397 : : pci_dev->id.device_id, "txgbe_mac_sp_vf");
398 : :
399 : 0 : return 0;
400 : : }
401 : :
402 : : /* Virtual Function device uninit */
403 : : static int
404 : 0 : eth_txgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
405 : : {
406 : 0 : PMD_INIT_FUNC_TRACE();
407 : :
408 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
409 : : return 0;
410 : :
411 : 0 : txgbevf_dev_close(eth_dev);
412 : :
413 : 0 : return 0;
414 : : }
415 : :
416 : 0 : static int eth_txgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
417 : : struct rte_pci_device *pci_dev)
418 : : {
419 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
420 : : sizeof(struct txgbe_adapter), eth_txgbevf_dev_init);
421 : : }
422 : :
423 : 0 : static int eth_txgbevf_pci_remove(struct rte_pci_device *pci_dev)
424 : : {
425 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_txgbevf_dev_uninit);
426 : : }
427 : :
428 : : /*
429 : : * virtual function driver struct
430 : : */
431 : : static struct rte_pci_driver rte_txgbevf_pmd = {
432 : : .id_table = pci_id_txgbevf_map,
433 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
434 : : .probe = eth_txgbevf_pci_probe,
435 : : .remove = eth_txgbevf_pci_remove,
436 : : };
437 : :
438 : 0 : static int txgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
439 : : struct rte_eth_xstat_name *xstats_names, unsigned int limit)
440 : : {
441 : : unsigned int i;
442 : :
443 [ # # ]: 0 : if (limit < TXGBEVF_NB_XSTATS && xstats_names != NULL)
444 : : return -ENOMEM;
445 : :
446 [ # # ]: 0 : if (xstats_names != NULL)
447 [ # # ]: 0 : for (i = 0; i < TXGBEVF_NB_XSTATS; i++)
448 : 0 : snprintf(xstats_names[i].name,
449 : : sizeof(xstats_names[i].name),
450 : 0 : "%s", rte_txgbevf_stats_strings[i].name);
451 : : return TXGBEVF_NB_XSTATS;
452 : : }
453 : :
454 : : static void
455 : 0 : txgbevf_update_stats(struct rte_eth_dev *dev)
456 : : {
457 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
458 : : struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
459 : : TXGBE_DEV_STATS(dev);
460 : : unsigned int i;
461 : :
462 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
463 : : /* Good Rx packet, include VF loopback */
464 [ # # ]: 0 : TXGBE_UPDCNT32(TXGBE_QPRXPKT(i),
465 : : hw_stats->qp[i].last_vfgprc, hw_stats->qp[i].vfgprc);
466 : :
467 : : /* Good Rx octets, include VF loopback */
468 [ # # ]: 0 : TXGBE_UPDCNT36(TXGBE_QPRXOCTL(i),
469 : : hw_stats->qp[i].last_vfgorc, hw_stats->qp[i].vfgorc);
470 : :
471 : : /* Rx Multicst Packet */
472 [ # # ]: 0 : TXGBE_UPDCNT32(TXGBE_QPRXMPKT(i),
473 : : hw_stats->qp[i].last_vfmprc, hw_stats->qp[i].vfmprc);
474 : : }
475 : 0 : hw->rx_loaded = 0;
476 : :
477 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
478 : : /* Good Tx packet, include VF loopback */
479 [ # # ]: 0 : TXGBE_UPDCNT32(TXGBE_QPTXPKT(i),
480 : : hw_stats->qp[i].last_vfgptc, hw_stats->qp[i].vfgptc);
481 : :
482 : : /* Good Tx octets, include VF loopback */
483 [ # # ]: 0 : TXGBE_UPDCNT36(TXGBE_QPTXOCTL(i),
484 : : hw_stats->qp[i].last_vfgotc, hw_stats->qp[i].vfgotc);
485 : : }
486 : 0 : hw->offset_loaded = 0;
487 : 0 : }
488 : :
489 : : static int
490 : 0 : txgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
491 : : unsigned int n)
492 : : {
493 : 0 : struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
494 : 0 : TXGBE_DEV_STATS(dev);
495 : : unsigned int i;
496 : :
497 [ # # ]: 0 : if (n < TXGBEVF_NB_XSTATS)
498 : : return TXGBEVF_NB_XSTATS;
499 : :
500 : 0 : txgbevf_update_stats(dev);
501 : :
502 [ # # ]: 0 : if (!xstats)
503 : : return 0;
504 : :
505 : : /* Extended stats */
506 [ # # ]: 0 : for (i = 0; i < TXGBEVF_NB_XSTATS; i++) {
507 : 0 : xstats[i].id = i;
508 : 0 : xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
509 : 0 : rte_txgbevf_stats_strings[i].offset);
510 : : }
511 : :
512 : : return TXGBEVF_NB_XSTATS;
513 : : }
514 : :
515 : : static int
516 : 0 : txgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
517 : : struct eth_queue_stats *qstats __rte_unused)
518 : : {
519 : : struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
520 : 0 : TXGBE_DEV_STATS(dev);
521 : : uint32_t i;
522 : :
523 : 0 : txgbevf_update_stats(dev);
524 : :
525 [ # # ]: 0 : if (stats == NULL)
526 : : return -EINVAL;
527 : :
528 : 0 : stats->ipackets = 0;
529 : 0 : stats->ibytes = 0;
530 : 0 : stats->opackets = 0;
531 : 0 : stats->obytes = 0;
532 : :
533 [ # # ]: 0 : for (i = 0; i < 8; i++) {
534 : 0 : stats->ipackets += hw_stats->qp[i].vfgprc;
535 : 0 : stats->ibytes += hw_stats->qp[i].vfgorc;
536 : 0 : stats->opackets += hw_stats->qp[i].vfgptc;
537 : 0 : stats->obytes += hw_stats->qp[i].vfgotc;
538 : : }
539 : :
540 : : return 0;
541 : : }
542 : :
543 : : static int
544 : 0 : txgbevf_dev_stats_reset(struct rte_eth_dev *dev)
545 : : {
546 : : struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
547 : 0 : TXGBE_DEV_STATS(dev);
548 : : uint32_t i;
549 : :
550 : : /* Sync HW register to the last stats */
551 : : txgbevf_dev_stats_get(dev, NULL, NULL);
552 : :
553 : : /* reset HW current stats*/
554 [ # # ]: 0 : for (i = 0; i < 8; i++) {
555 : 0 : hw_stats->qp[i].vfgprc = 0;
556 : 0 : hw_stats->qp[i].vfgorc = 0;
557 : 0 : hw_stats->qp[i].vfgptc = 0;
558 : 0 : hw_stats->qp[i].vfgotc = 0;
559 : : }
560 : :
561 : 0 : return 0;
562 : : }
563 : :
564 : : static int
565 : 0 : txgbevf_dev_info_get(struct rte_eth_dev *dev,
566 : : struct rte_eth_dev_info *dev_info)
567 : : {
568 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
569 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
570 : :
571 : 0 : dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
572 : 0 : dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
573 : 0 : dev_info->min_rx_bufsize = 1024;
574 : 0 : dev_info->max_rx_pktlen = TXGBE_FRAME_SIZE_MAX;
575 : 0 : dev_info->max_mac_addrs = hw->mac.num_rar_entries;
576 : 0 : dev_info->max_hash_mac_addrs = TXGBE_VMDQ_NUM_UC_MAC;
577 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
578 : 0 : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
579 : 0 : dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
580 : 0 : dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
581 : 0 : dev_info->rx_queue_offload_capa);
582 : 0 : dev_info->tx_queue_offload_capa = txgbe_get_tx_queue_offloads(dev);
583 : 0 : dev_info->tx_offload_capa = txgbe_get_tx_port_offloads(dev);
584 : 0 : dev_info->hash_key_size = TXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
585 : 0 : dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
586 : 0 : dev_info->flow_type_rss_offloads = TXGBE_RSS_OFFLOAD_ALL;
587 : :
588 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
589 : : .rx_thresh = {
590 : : .pthresh = TXGBE_DEFAULT_RX_PTHRESH,
591 : : .hthresh = TXGBE_DEFAULT_RX_HTHRESH,
592 : : .wthresh = TXGBE_DEFAULT_RX_WTHRESH,
593 : : },
594 : : .rx_free_thresh = TXGBE_DEFAULT_RX_FREE_THRESH,
595 : : .rx_drop_en = 0,
596 : : .offloads = 0,
597 : : };
598 : :
599 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
600 : : .tx_thresh = {
601 : : .pthresh = TXGBE_DEFAULT_TX_PTHRESH,
602 : : .hthresh = TXGBE_DEFAULT_TX_HTHRESH,
603 : : .wthresh = TXGBE_DEFAULT_TX_WTHRESH,
604 : : },
605 : : .tx_free_thresh = TXGBE_DEFAULT_TX_FREE_THRESH,
606 : : .offloads = 0,
607 : : };
608 : :
609 : 0 : dev_info->rx_desc_lim = rx_desc_lim;
610 : 0 : dev_info->tx_desc_lim = tx_desc_lim;
611 : :
612 : 0 : dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PASSIVE;
613 : :
614 : 0 : return 0;
615 : : }
616 : :
617 : : static int
618 : 0 : txgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
619 : : {
620 : 0 : return txgbe_dev_link_update_share(dev, wait_to_complete);
621 : : }
622 : :
623 : : /*
624 : : * Virtual Function operations
625 : : */
626 : : static void
627 : 0 : txgbevf_intr_disable(struct rte_eth_dev *dev)
628 : : {
629 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
630 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
631 : :
632 : 0 : PMD_INIT_FUNC_TRACE();
633 : :
634 : : /* Clear interrupt mask to stop from interrupts being generated */
635 : : wr32(hw, TXGBE_VFIMS, TXGBE_VFIMS_MASK);
636 : :
637 : : txgbe_flush(hw);
638 : :
639 : : /* Clear mask value. */
640 : 0 : intr->mask_misc = TXGBE_VFIMS_MASK;
641 : 0 : }
642 : :
643 : : static void
644 : 0 : txgbevf_intr_enable(struct rte_eth_dev *dev)
645 : : {
646 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
647 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
648 : :
649 : 0 : PMD_INIT_FUNC_TRACE();
650 : :
651 : : /* VF enable interrupt autoclean */
652 : : wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
653 : :
654 : : txgbe_flush(hw);
655 : :
656 : 0 : intr->mask_misc = 0;
657 : 0 : }
658 : :
659 : : static int
660 : 0 : txgbevf_dev_configure(struct rte_eth_dev *dev)
661 : : {
662 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
663 : 0 : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
664 : :
665 : 0 : PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
666 : : dev->data->port_id);
667 : :
668 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
669 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
670 : :
671 : : /*
672 : : * VF has no ability to enable/disable HW CRC
673 : : * Keep the persistent behavior the same as Host PF
674 : : */
675 : : #ifndef RTE_LIBRTE_TXGBE_PF_DISABLE_STRIP_CRC
676 [ # # ]: 0 : if (conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
677 : 0 : PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
678 : 0 : conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
679 : : }
680 : : #else
681 : : if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
682 : : PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
683 : : conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
684 : : }
685 : : #endif
686 : :
687 : : /*
688 : : * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
689 : : * allocation or vector Rx preconditions we will reset it.
690 : : */
691 : 0 : adapter->rx_bulk_alloc_allowed = true;
692 : 0 : adapter->rx_vec_allowed = true;
693 : :
694 : 0 : return 0;
695 : : }
696 : :
697 : : static int
698 : 0 : txgbevf_dev_start(struct rte_eth_dev *dev)
699 : : {
700 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
701 : : uint32_t intr_vector = 0;
702 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
703 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
704 : :
705 : : int err, mask = 0;
706 : :
707 : 0 : PMD_INIT_FUNC_TRACE();
708 : :
709 : : /* Stop the link setup handler before resetting the HW. */
710 : 0 : txgbe_dev_wait_setup_link_complete(dev, 0);
711 : :
712 : 0 : err = hw->mac.reset_hw(hw);
713 [ # # ]: 0 : if (err) {
714 : 0 : PMD_INIT_LOG(ERR, "Unable to reset vf hardware (%d)", err);
715 : 0 : return err;
716 : : }
717 : 0 : hw->mac.get_link_status = true;
718 : 0 : hw->dev_start = true;
719 : :
720 : : /* negotiate mailbox API version to use with the PF. */
721 : 0 : txgbevf_negotiate_api(hw);
722 : :
723 : 0 : txgbevf_dev_tx_init(dev);
724 : :
725 : : /* This can fail when allocating mbufs for descriptor rings */
726 : 0 : err = txgbevf_dev_rx_init(dev);
727 : :
728 : : /**
729 : : * In this case, reuses the MAC address assigned by VF
730 : : * initialization.
731 : : */
732 [ # # ]: 0 : if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
733 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
734 : 0 : txgbe_dev_clear_queues(dev);
735 : 0 : return err;
736 : : }
737 : :
738 : : /* Set vfta */
739 : 0 : txgbevf_set_vfta_all(dev, 1);
740 : :
741 : : /* Set HW strip */
742 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
743 : : RTE_ETH_VLAN_EXTEND_MASK;
744 : 0 : err = txgbevf_vlan_offload_config(dev, mask);
745 [ # # ]: 0 : if (err) {
746 : 0 : PMD_INIT_LOG(ERR, "Unable to set VLAN offload (%d)", err);
747 : 0 : txgbe_dev_clear_queues(dev);
748 : 0 : return err;
749 : : }
750 : :
751 : 0 : txgbevf_dev_rxtx_start(dev);
752 : :
753 : : /* check and configure queue intr-vector mapping */
754 [ # # ]: 0 : if (rte_intr_cap_multiple(intr_handle) &&
755 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq) {
756 : : /* According to datasheet, only vector 0/1/2 can be used,
757 : : * now only one vector is used for Rx queue
758 : : */
759 : : intr_vector = 1;
760 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector)) {
761 : 0 : txgbe_dev_clear_queues(dev);
762 : 0 : return -1;
763 : : }
764 : : }
765 : :
766 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
767 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
768 : 0 : dev->data->nb_rx_queues)) {
769 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
770 : : " intr_vec", dev->data->nb_rx_queues);
771 : 0 : txgbe_dev_clear_queues(dev);
772 : 0 : return -ENOMEM;
773 : : }
774 : : }
775 : 0 : txgbevf_configure_msix(dev);
776 : :
777 : : /* When a VF port is bound to VFIO-PCI, only miscellaneous interrupt
778 : : * is mapped to VFIO vector 0 in eth_txgbevf_dev_init( ).
779 : : * If previous VFIO interrupt mapping setting in eth_txgbevf_dev_init( )
780 : : * is not cleared, it will fail when following rte_intr_enable( ) tries
781 : : * to map Rx queue interrupt to other VFIO vectors.
782 : : * So clear uio/vfio intr/evevnfd first to avoid failure.
783 : : */
784 : 0 : rte_intr_disable(intr_handle);
785 : :
786 : 0 : rte_intr_enable(intr_handle);
787 : :
788 : : /* Re-enable interrupt for VF */
789 : 0 : txgbevf_intr_enable(dev);
790 : :
791 : : /*
792 : : * Update link status right before return, because it may
793 : : * start link configuration process in a separate thread.
794 : : */
795 : : txgbevf_dev_link_update(dev, 0);
796 : :
797 : 0 : hw->adapter_stopped = false;
798 : :
799 : 0 : return 0;
800 : : }
801 : :
802 : : static int
803 : 0 : txgbevf_dev_stop(struct rte_eth_dev *dev)
804 : : {
805 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
806 : : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
807 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
808 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
809 : :
810 [ # # ]: 0 : if (hw->adapter_stopped)
811 : : return 0;
812 : :
813 : 0 : PMD_INIT_FUNC_TRACE();
814 : :
815 : 0 : txgbe_dev_wait_setup_link_complete(dev, 0);
816 : :
817 : 0 : txgbevf_intr_disable(dev);
818 : :
819 : 0 : hw->adapter_stopped = 1;
820 : 0 : hw->mac.stop_hw(hw);
821 : :
822 : : /*
823 : : * Clear what we set, but we still keep shadow_vfta to
824 : : * restore after device starts
825 : : */
826 : 0 : txgbevf_set_vfta_all(dev, 0);
827 : :
828 : : /* Clear stored conf */
829 : 0 : dev->data->scattered_rx = 0;
830 : :
831 : 0 : txgbe_dev_clear_queues(dev);
832 : :
833 : : /* Clean datapath event and queue/vec mapping */
834 : 0 : rte_intr_efd_disable(intr_handle);
835 : 0 : rte_intr_vec_list_free(intr_handle);
836 : :
837 : 0 : adapter->rss_reta_updated = 0;
838 : 0 : hw->dev_start = false;
839 : :
840 : 0 : return 0;
841 : : }
842 : :
843 : : static int
844 : 0 : txgbevf_dev_close(struct rte_eth_dev *dev)
845 : : {
846 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
847 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
848 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
849 : : int ret;
850 : :
851 : 0 : PMD_INIT_FUNC_TRACE();
852 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
853 : : return 0;
854 : :
855 : 0 : hw->mac.reset_hw(hw);
856 : :
857 : 0 : ret = txgbevf_dev_stop(dev);
858 : :
859 : 0 : txgbe_dev_free_queues(dev);
860 : :
861 : : /**
862 : : * Remove the VF MAC address ro ensure
863 : : * that the VF traffic goes to the PF
864 : : * after stop, close and detach of the VF
865 : : **/
866 : 0 : txgbevf_remove_mac_addr(dev, 0);
867 : :
868 : : /* Disable the interrupts for VF */
869 : 0 : txgbevf_intr_disable(dev);
870 : :
871 : 0 : rte_free(dev->data->mac_addrs);
872 : 0 : dev->data->mac_addrs = NULL;
873 : :
874 : 0 : rte_intr_disable(intr_handle);
875 : 0 : rte_intr_callback_unregister(intr_handle,
876 : : txgbevf_dev_interrupt_handler, dev);
877 : :
878 : : /* remove all the fdir filters & hash */
879 : 0 : txgbe_fdir_filter_uninit(dev);
880 : :
881 : : /* Remove all ntuple filters of the device */
882 : 0 : txgbe_ntuple_filter_uninit(dev);
883 : :
884 : : /* clear all the filters list */
885 : 0 : txgbe_filterlist_flush(dev);
886 : :
887 : 0 : return ret;
888 : : }
889 : :
890 : : /*
891 : : * Reset VF device
892 : : */
893 : : static int
894 : 0 : txgbevf_dev_reset(struct rte_eth_dev *dev)
895 : : {
896 : : int ret;
897 : :
898 : 0 : ret = eth_txgbevf_dev_uninit(dev);
899 [ # # ]: 0 : if (ret)
900 : : return ret;
901 : :
902 : 0 : ret = eth_txgbevf_dev_init(dev);
903 : :
904 : 0 : return ret;
905 : : }
906 : :
907 : 0 : static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
908 : : {
909 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
910 : : struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
911 : : int i = 0, j = 0, vfta = 0, mask = 1;
912 : :
913 [ # # ]: 0 : for (i = 0; i < TXGBE_VFTA_SIZE; i++) {
914 : 0 : vfta = shadow_vfta->vfta[i];
915 [ # # ]: 0 : if (vfta) {
916 : : mask = 1;
917 [ # # ]: 0 : for (j = 0; j < 32; j++) {
918 [ # # ]: 0 : if (vfta & mask)
919 : 0 : hw->mac.set_vfta(hw, (i << 5) + j, 0,
920 : : on, false);
921 : 0 : mask <<= 1;
922 : : }
923 : : }
924 : : }
925 : 0 : }
926 : :
927 : : static int
928 : 0 : txgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
929 : : {
930 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
931 : : struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
932 : : uint32_t vid_idx = 0;
933 : : uint32_t vid_bit = 0;
934 : : int ret = 0;
935 : :
936 : 0 : PMD_INIT_FUNC_TRACE();
937 : :
938 : : /* vind is not used in VF driver, set to 0, check txgbe_set_vfta_vf */
939 : 0 : ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
940 [ # # ]: 0 : if (ret) {
941 : 0 : PMD_INIT_LOG(ERR, "Unable to set VF vlan");
942 : 0 : return ret;
943 : : }
944 : 0 : vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
945 : 0 : vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
946 : :
947 : : /* Save what we set and restore it after device reset */
948 [ # # ]: 0 : if (on)
949 : 0 : shadow_vfta->vfta[vid_idx] |= vid_bit;
950 : : else
951 : 0 : shadow_vfta->vfta[vid_idx] &= ~vid_bit;
952 : :
953 : : return 0;
954 : : }
955 : :
956 : : static void
957 : 0 : txgbevf_vlan_strip_q_set(struct rte_eth_dev *dev, uint16_t queue, int on)
958 : : {
959 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
960 : : uint32_t ctrl;
961 : :
962 : 0 : PMD_INIT_FUNC_TRACE();
963 : :
964 [ # # ]: 0 : if (queue >= hw->mac.max_rx_queues)
965 : : return;
966 : :
967 : 0 : ctrl = rd32(hw, TXGBE_RXCFG(queue));
968 [ # # ]: 0 : if (on)
969 : 0 : ctrl |= TXGBE_RXCFG_VLAN;
970 : : else
971 : 0 : ctrl &= ~TXGBE_RXCFG_VLAN;
972 : : wr32(hw, TXGBE_RXCFG(queue), ctrl);
973 : :
974 : 0 : txgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
975 : : }
976 : :
977 : : static void
978 : 0 : txgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
979 : : {
980 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
981 : :
982 [ # # ]: 0 : if (!hw->adapter_stopped) {
983 : 0 : PMD_DRV_LOG(ERR, "Please stop port first");
984 : 0 : return;
985 : : }
986 : :
987 : 0 : txgbevf_vlan_strip_q_set(dev, queue, on);
988 : : }
989 : :
990 : : static int
991 : 0 : txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
992 : : {
993 : : struct txgbe_rx_queue *rxq;
994 : : uint16_t i;
995 : : int on = 0;
996 : :
997 : : /* VF function only support hw strip feature, others are not support */
998 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
999 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1000 : 0 : rxq = dev->data->rx_queues[i];
1001 : 0 : on = !!(rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
1002 : 0 : txgbevf_vlan_strip_q_set(dev, i, on);
1003 : : }
1004 : : }
1005 : :
1006 : 0 : return 0;
1007 : : }
1008 : :
1009 : : static int
1010 : 0 : txgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1011 : : {
1012 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1013 : :
1014 [ # # # # ]: 0 : if (!hw->adapter_stopped && (mask & RTE_ETH_VLAN_STRIP_MASK)) {
1015 : 0 : PMD_DRV_LOG(ERR, "Please stop port first");
1016 : 0 : return -EPERM;
1017 : : }
1018 : :
1019 : 0 : txgbe_config_vlan_strip_on_all_queues(dev, mask);
1020 : :
1021 : 0 : txgbevf_vlan_offload_config(dev, mask);
1022 : :
1023 : 0 : return 0;
1024 : : }
1025 : :
1026 : : static int
1027 : 0 : txgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1028 : : {
1029 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1030 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1031 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1032 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1033 : : uint32_t vec = TXGBE_MISC_VEC_ID;
1034 : :
1035 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
1036 : : vec = TXGBE_RX_VEC_START;
1037 : 0 : intr->mask_misc &= ~(1 << vec);
1038 : : RTE_SET_USED(queue_id);
1039 : 0 : wr32(hw, TXGBE_VFIMC, ~intr->mask_misc);
1040 : :
1041 : 0 : rte_intr_enable(intr_handle);
1042 : :
1043 : 0 : return 0;
1044 : : }
1045 : :
1046 : : static int
1047 : 0 : txgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1048 : : {
1049 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1050 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1051 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1052 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1053 : : uint32_t vec = TXGBE_MISC_VEC_ID;
1054 : :
1055 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
1056 : : vec = TXGBE_RX_VEC_START;
1057 : 0 : intr->mask_misc |= (1 << vec);
1058 : : RTE_SET_USED(queue_id);
1059 : : wr32(hw, TXGBE_VFIMS, intr->mask_misc);
1060 : :
1061 : 0 : return 0;
1062 : : }
1063 : :
1064 : : static void
1065 : 0 : txgbevf_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
1066 : : uint8_t queue, uint8_t msix_vector)
1067 : : {
1068 : : uint32_t tmp, idx;
1069 : :
1070 [ # # ]: 0 : if (direction == -1) {
1071 : : /* other causes */
1072 : 0 : msix_vector |= TXGBE_VFIVAR_VLD;
1073 : : tmp = rd32(hw, TXGBE_VFIVARMISC);
1074 : 0 : tmp &= ~0xFF;
1075 : 0 : tmp |= msix_vector;
1076 : : wr32(hw, TXGBE_VFIVARMISC, tmp);
1077 : : } else {
1078 : : /* rx or tx cause */
1079 : 0 : msix_vector |= TXGBE_VFIVAR_VLD; /* Workaround for ICR lost */
1080 : 0 : idx = ((16 * (queue & 1)) + (8 * direction));
1081 : 0 : tmp = rd32(hw, TXGBE_VFIVAR(queue >> 1));
1082 : 0 : tmp &= ~(0xFF << idx);
1083 : 0 : tmp |= (msix_vector << idx);
1084 : : wr32(hw, TXGBE_VFIVAR(queue >> 1), tmp);
1085 : : }
1086 : 0 : }
1087 : :
1088 : : static void
1089 : 0 : txgbevf_configure_msix(struct rte_eth_dev *dev)
1090 : : {
1091 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1092 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1093 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1094 : : uint32_t q_idx;
1095 : : uint32_t vector_idx = TXGBE_MISC_VEC_ID;
1096 : : uint32_t base = TXGBE_MISC_VEC_ID;
1097 : :
1098 : : /* Configure VF other cause ivar */
1099 : : txgbevf_set_ivar_map(hw, -1, 1, vector_idx);
1100 : :
1101 : : /* won't configure msix register if no mapping is done
1102 : : * between intr vector and event fd.
1103 : : */
1104 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle))
1105 : : return;
1106 : :
1107 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
1108 : : base = TXGBE_RX_VEC_START;
1109 : : vector_idx = TXGBE_RX_VEC_START;
1110 : : }
1111 : :
1112 : : /* Configure all RX queues of VF */
1113 [ # # ]: 0 : for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
1114 : : /* Force all queue use vector 0,
1115 : : * as TXGBE_VF_MAXMSIVECTOR = 1
1116 : : */
1117 : 0 : txgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
1118 : 0 : rte_intr_vec_list_index_set(intr_handle, q_idx,
1119 : : vector_idx);
1120 : 0 : if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
1121 [ # # ]: 0 : - 1)
1122 : 0 : vector_idx++;
1123 : : }
1124 : :
1125 : : /* As RX queue setting above show, all queues use the vector 0.
1126 : : * Set only the ITR value of TXGBE_MISC_VEC_ID.
1127 : : */
1128 : : wr32(hw, TXGBE_ITR(TXGBE_MISC_VEC_ID),
1129 : : TXGBE_ITR_IVAL(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
1130 : : | TXGBE_ITR_WRDSA);
1131 : : }
1132 : :
1133 : : static int
1134 : 0 : txgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1135 : : __rte_unused uint32_t index,
1136 : : __rte_unused uint32_t pool)
1137 : : {
1138 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1139 : : int err;
1140 : :
1141 : : /*
1142 : : * On a VF, adding again the same MAC addr is not an idempotent
1143 : : * operation. Trap this case to avoid exhausting the [very limited]
1144 : : * set of PF resources used to store VF MAC addresses.
1145 : : */
1146 [ # # ]: 0 : if (memcmp(hw->mac.perm_addr, mac_addr,
1147 : : sizeof(struct rte_ether_addr)) == 0)
1148 : : return -1;
1149 : 0 : err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1150 [ # # ]: 0 : if (err != 0)
1151 : 0 : PMD_DRV_LOG(ERR, "Unable to add MAC address "
1152 : : RTE_ETHER_ADDR_PRT_FMT " - err=%d",
1153 : : RTE_ETHER_ADDR_BYTES(mac_addr), err);
1154 : : return err;
1155 : : }
1156 : :
1157 : : static void
1158 : 0 : txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
1159 : : {
1160 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1161 : 0 : struct rte_ether_addr *perm_addr =
1162 : : (struct rte_ether_addr *)hw->mac.perm_addr;
1163 : : struct rte_ether_addr *mac_addr;
1164 : : uint32_t i;
1165 : : int err;
1166 : :
1167 : : /*
1168 : : * The TXGBE_VF_SET_MACVLAN command of the txgbe-pf driver does
1169 : : * not support the deletion of a given MAC address.
1170 : : * Instead, it imposes to delete all MAC addresses, then to add again
1171 : : * all MAC addresses with the exception of the one to be deleted.
1172 : : */
1173 : 0 : (void)txgbevf_set_uc_addr_vf(hw, 0, NULL);
1174 : :
1175 : : /*
1176 : : * Add again all MAC addresses, with the exception of the deleted one
1177 : : * and of the permanent MAC address.
1178 : : */
1179 : 0 : for (i = 0, mac_addr = dev->data->mac_addrs;
1180 [ # # ]: 0 : i < hw->mac.num_rar_entries; i++, mac_addr++) {
1181 : : /* Skip the deleted MAC address */
1182 [ # # ]: 0 : if (i == index)
1183 : 0 : continue;
1184 : : /* Skip NULL MAC addresses */
1185 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac_addr))
1186 : 0 : continue;
1187 : : /* Skip the permanent MAC address */
1188 [ # # ]: 0 : if (memcmp(perm_addr, mac_addr,
1189 : : sizeof(struct rte_ether_addr)) == 0)
1190 : 0 : continue;
1191 : 0 : err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1192 [ # # ]: 0 : if (err != 0)
1193 : 0 : PMD_DRV_LOG(ERR,
1194 : : "Adding again MAC address "
1195 : : RTE_ETHER_ADDR_PRT_FMT " failed "
1196 : : "err=%d",
1197 : : RTE_ETHER_ADDR_BYTES(mac_addr), err);
1198 : : }
1199 : 0 : }
1200 : :
1201 : : static int
1202 : 0 : txgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
1203 : : struct rte_ether_addr *addr)
1204 : : {
1205 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1206 : :
1207 : 0 : hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
1208 : :
1209 : 0 : return 0;
1210 : : }
1211 : :
1212 : : static int
1213 : 0 : txgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1214 : : {
1215 : : struct txgbe_hw *hw;
1216 : 0 : uint32_t max_frame = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1217 : 0 : struct rte_eth_dev_data *dev_data = dev->data;
1218 : :
1219 : 0 : hw = TXGBE_DEV_HW(dev);
1220 : :
1221 : 0 : if (mtu < RTE_ETHER_MIN_MTU ||
1222 [ # # ]: 0 : max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
1223 : : return -EINVAL;
1224 : :
1225 : : /* If device is started, refuse mtu that requires the support of
1226 : : * scattered packets when this feature has not been enabled before.
1227 : : */
1228 [ # # ]: 0 : if (dev_data->dev_started && !dev_data->scattered_rx &&
1229 : 0 : (max_frame + 2 * RTE_VLAN_HLEN >
1230 [ # # ]: 0 : dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
1231 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
1232 : 0 : return -EINVAL;
1233 : : }
1234 : :
1235 : : /*
1236 : : * When supported by the underlying PF driver, use the TXGBE_VF_SET_MTU
1237 : : * request of the version 2.0 of the mailbox API.
1238 : : * For now, use the TXGBE_VF_SET_LPE request of the version 1.0
1239 : : * of the mailbox API.
1240 : : */
1241 [ # # ]: 0 : if (txgbevf_rlpml_set_vf(hw, max_frame))
1242 : 0 : return -EINVAL;
1243 : :
1244 : : return 0;
1245 : : }
1246 : :
1247 : : static int
1248 : : txgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
1249 : : {
1250 : : int count = 0;
1251 : : int g_ind = 0;
1252 : : const struct reg_info *reg_group;
1253 : :
1254 [ # # # # ]: 0 : while ((reg_group = txgbevf_regs[g_ind++]))
1255 : 0 : count += txgbe_regs_group_count(reg_group);
1256 : :
1257 : : return count;
1258 : : }
1259 : :
1260 : : static int
1261 : 0 : txgbevf_get_regs(struct rte_eth_dev *dev,
1262 : : struct rte_dev_reg_info *regs)
1263 : : {
1264 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1265 : 0 : uint32_t *data = regs->data;
1266 : : int g_ind = 0;
1267 : : int count = 0;
1268 : : const struct reg_info *reg_group;
1269 : :
1270 [ # # ]: 0 : if (data == NULL) {
1271 : 0 : regs->length = txgbevf_get_reg_length(dev);
1272 : 0 : regs->width = sizeof(uint32_t);
1273 : 0 : return 0;
1274 : : }
1275 : :
1276 : : /* Support only full register dump */
1277 [ # # ]: 0 : if (regs->length == 0 ||
1278 [ # # ]: 0 : regs->length == (uint32_t)txgbevf_get_reg_length(dev)) {
1279 : 0 : regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
1280 : 0 : hw->device_id;
1281 [ # # ]: 0 : while ((reg_group = txgbevf_regs[g_ind++]))
1282 : 0 : count += txgbe_read_regs_group(dev, &data[count],
1283 : : reg_group);
1284 : : return 0;
1285 : : }
1286 : :
1287 : : return -ENOTSUP;
1288 : : }
1289 : :
1290 : : static int
1291 : 0 : txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1292 : : {
1293 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1294 : : int ret;
1295 : :
1296 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_PROMISC)) {
1297 : : case 0:
1298 : : ret = 0;
1299 : : break;
1300 : 0 : case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1301 : : ret = -ENOTSUP;
1302 : 0 : break;
1303 : 0 : default:
1304 : : ret = -EAGAIN;
1305 : 0 : break;
1306 : : }
1307 : :
1308 : 0 : return ret;
1309 : : }
1310 : :
1311 : : static int
1312 : 0 : txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1313 : : {
1314 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1315 : : int mode = TXGBEVF_XCAST_MODE_NONE;
1316 : : int ret;
1317 : :
1318 [ # # ]: 0 : if (dev->data->all_multicast)
1319 : : mode = TXGBEVF_XCAST_MODE_ALLMULTI;
1320 : :
1321 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, mode)) {
1322 : : case 0:
1323 : : ret = 0;
1324 : : break;
1325 : 0 : case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1326 : : ret = -ENOTSUP;
1327 : 0 : break;
1328 : 0 : default:
1329 : : ret = -EAGAIN;
1330 : 0 : break;
1331 : : }
1332 : :
1333 : 0 : return ret;
1334 : : }
1335 : :
1336 : : static int
1337 : 0 : txgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1338 : : {
1339 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1340 : : int ret;
1341 : :
1342 [ # # ]: 0 : if (dev->data->promiscuous)
1343 : : return 0;
1344 : :
1345 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_ALLMULTI)) {
1346 : : case 0:
1347 : : ret = 0;
1348 : : break;
1349 : 0 : case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1350 : : ret = -ENOTSUP;
1351 : 0 : break;
1352 : 0 : default:
1353 : : ret = -EAGAIN;
1354 : 0 : break;
1355 : : }
1356 : :
1357 : : return ret;
1358 : : }
1359 : :
1360 : : static int
1361 : 0 : txgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1362 : : {
1363 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1364 : : int ret;
1365 : :
1366 [ # # ]: 0 : if (dev->data->promiscuous)
1367 : : return 0;
1368 : :
1369 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_MULTI)) {
1370 : : case 0:
1371 : : ret = 0;
1372 : : break;
1373 : 0 : case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1374 : : ret = -ENOTSUP;
1375 : 0 : break;
1376 : 0 : default:
1377 : : ret = -EAGAIN;
1378 : 0 : break;
1379 : : }
1380 : :
1381 : : return ret;
1382 : : }
1383 : :
1384 : : /**
1385 : : * txgbevf_get_pf_link_status - Get pf link/speed status
1386 : : * @hw: pointer to hardware structure
1387 : : *
1388 : : * - PF notifies status via mailbox on change
1389 : : * - VF sets its link state synchronously upon mailbox interrupt,
1390 : : * skipping hardware link detection.
1391 : : **/
1392 : 0 : static s32 txgbevf_get_pf_link_status(struct rte_eth_dev *dev)
1393 : : {
1394 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1395 : : struct txgbe_mbx_info *mbx = &hw->mbx;
1396 : : struct rte_eth_link link;
1397 : : u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
1398 : : bool link_up = false;
1399 : : u32 msgbuf[2];
1400 : : s32 retval;
1401 : :
1402 : 0 : retval = mbx->read(hw, msgbuf, 2, 0);
1403 : :
1404 : : /*
1405 : : *if the read failed it could just be a mailbox collision, best wait
1406 : : * until we are called again and don't report an error
1407 : : */
1408 [ # # ]: 0 : if (retval)
1409 : : return 0;
1410 : :
1411 [ # # ]: 0 : if (!(msgbuf[0] & TXGBE_NOFITY_VF_LINK_STATUS))
1412 : : return 0;
1413 : :
1414 : 0 : rte_eth_linkstatus_get(dev, &link);
1415 : :
1416 [ # # ]: 0 : if (!rte_atomic_load_explicit(&hw->pf_running,
1417 : : rte_memory_order_acquire)) {
1418 : 0 : link.link_status = RTE_ETH_LINK_DOWN;
1419 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1420 [ # # ]: 0 : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1421 : 0 : return rte_eth_linkstatus_set(dev, &link);
1422 : : }
1423 : :
1424 : 0 : link_up = msgbuf[1] & TXGBE_VFSTATUS_UP;
1425 : 0 : link_speed = (msgbuf[1] & 0x1FFFFE) >> 1;
1426 : :
1427 [ # # # # ]: 0 : if (link_up == link.link_status && link_speed == link.link_speed)
1428 : : return 0;
1429 : :
1430 : 0 : link.link_speed = link_speed;
1431 : 0 : link.link_status = link_up;
1432 : :
1433 [ # # ]: 0 : if (link_up)
1434 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1435 : : else
1436 : 0 : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1437 : : /*
1438 : : * Invoke the LSC interrupt callback to notify the upper app of a link
1439 : : * status change, even though the change is detected via a mailbox interrupt
1440 : : * instead of an LSC interrupt. This is because VF link status changes do
1441 : : * not trigger LSC interrupts — they rely on PF notifications.
1442 : : */
1443 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
1444 : : NULL);
1445 : : return rte_eth_linkstatus_set(dev, &link);
1446 : : }
1447 : :
1448 : 0 : static void txgbevf_check_link_for_intr(struct rte_eth_dev *dev)
1449 : : {
1450 : : struct rte_eth_link orig_link, new_link;
1451 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1452 : :
1453 : 0 : rte_eth_linkstatus_get(dev, &orig_link);
1454 : :
1455 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->pf_running,
1456 : : rte_memory_order_acquire)) {
1457 : : txgbevf_dev_link_update(dev, 0);
1458 : 0 : rte_eth_linkstatus_get(dev, &new_link);
1459 : : } else {
1460 : 0 : DEBUGOUT("PF ifconfig down, so VF link down");
1461 : 0 : new_link.link_status = RTE_ETH_LINK_DOWN;
1462 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1463 : 0 : new_link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1464 : 0 : new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1465 : : RTE_ETH_LINK_SPEED_FIXED);
1466 : 0 : rte_eth_linkstatus_set(dev, &new_link);
1467 : : }
1468 : :
1469 : 0 : PMD_DRV_LOG(INFO, "orig_link: %d, new_link: %d",
1470 : : orig_link.link_status, new_link.link_status);
1471 : :
1472 [ # # ]: 0 : if (new_link.link_status != orig_link.link_status)
1473 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
1474 : : NULL);
1475 : 0 : }
1476 : :
1477 : 0 : static void txgbevf_mbx_process(struct rte_eth_dev *dev)
1478 : : {
1479 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1480 : : struct txgbe_mbx_info *mbx = &hw->mbx;
1481 : 0 : u32 msgbuf = 0;
1482 : : u32 in_msg = 0;
1483 : :
1484 : : /* Peek the message first */
1485 : : in_msg = rd32(hw, TXGBE_VFMBX);
1486 : :
1487 : : /* PF control message */
1488 [ # # ]: 0 : if (!(in_msg & TXGBE_PF_CONTROL_MSG))
1489 : 0 : return;
1490 : :
1491 : 0 : txgbevf_get_pf_link_status(dev);
1492 : :
1493 [ # # ]: 0 : if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
1494 : : /*
1495 : : * PF is not ready for this VF (e.g. PF ifconfig down).
1496 : : *
1497 : : * Send VF_RESET to ask the PF to reconfigure us. The PF only
1498 : : * marks this VF as ready (and starts sending CTS) after it
1499 : : * processes VF_RESET, so this request is the only way to
1500 : : * recover. If write_posted() succeeds the PF is back up and
1501 : : * we notify the application to reset the VF; otherwise the PF
1502 : : * is still down, so we mark it down and reset the stats
1503 : : * baselines (hardware counters are cleared during PF reset).
1504 : : *
1505 : : * write_posted() may busy-wait for the ACK in the interrupt
1506 : : * thread, but the PF does not send further mailbox messages
1507 : : * once it is down, so this blocking is not continuously
1508 : : * triggered.
1509 : : */
1510 : : int err;
1511 : :
1512 : 0 : msgbuf = TXGBE_VF_RESET;
1513 : 0 : err = mbx->write_posted(hw, &msgbuf, 1, 0);
1514 [ # # ]: 0 : if (err) {
1515 : 0 : rte_atomic_store_explicit(&hw->pf_running, false,
1516 : : rte_memory_order_release);
1517 : 0 : txgbevf_check_link_for_intr(dev);
1518 : 0 : hw->rx_loaded = true;
1519 : 0 : hw->offset_loaded = true;
1520 : : } else {
1521 : 0 : rte_atomic_store_explicit(&hw->pf_running, true,
1522 : : rte_memory_order_release);
1523 : 0 : rte_eth_dev_callback_process(dev,
1524 : : RTE_ETH_EVENT_INTR_RESET, NULL);
1525 : : }
1526 : 0 : return;
1527 : : }
1528 : :
1529 : : /* Check link status if pf only ping vf */
1530 [ # # ]: 0 : if (!(in_msg & TXGBE_NOFITY_VF_LINK_STATUS))
1531 : 0 : txgbevf_check_link_for_intr(dev);
1532 : : }
1533 : :
1534 : : static int
1535 : 0 : txgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
1536 : : {
1537 : : uint32_t eicr;
1538 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1539 : : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1540 : 0 : txgbevf_intr_disable(dev);
1541 : :
1542 : : /* read-on-clear nic registers here */
1543 : : eicr = rd32(hw, TXGBE_VFICR);
1544 : : intr->flags = 0;
1545 : :
1546 : : /* only one misc vector supported - mailbox */
1547 : : eicr &= TXGBE_VFICR_MASK;
1548 : : /* Workaround for ICR lost */
1549 : 0 : intr->flags |= TXGBE_FLAG_MAILBOX;
1550 : :
1551 : : /* To avoid compiler warnings set eicr to used. */
1552 : : RTE_SET_USED(eicr);
1553 : :
1554 : 0 : return 0;
1555 : : }
1556 : :
1557 : : static int
1558 : 0 : txgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
1559 : : {
1560 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1561 : :
1562 [ # # ]: 0 : if (intr->flags & TXGBE_FLAG_MAILBOX) {
1563 : 0 : txgbevf_mbx_process(dev);
1564 : 0 : intr->flags &= ~TXGBE_FLAG_MAILBOX;
1565 : : }
1566 : :
1567 : 0 : txgbevf_intr_enable(dev);
1568 : :
1569 : 0 : return 0;
1570 : : }
1571 : :
1572 : : static void
1573 : 0 : txgbevf_dev_interrupt_handler(void *param)
1574 : : {
1575 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1576 : :
1577 : 0 : txgbevf_dev_interrupt_get_status(dev);
1578 : 0 : txgbevf_dev_interrupt_action(dev);
1579 : 0 : }
1580 : :
1581 : : static int
1582 : 0 : txgbevf_dev_flow_ops_get(__rte_unused struct rte_eth_dev *dev,
1583 : : const struct rte_flow_ops **ops)
1584 : : {
1585 : 0 : *ops = &txgbe_flow_ops;
1586 : 0 : return 0;
1587 : : }
1588 : :
1589 : : /*
1590 : : * dev_ops for virtual function, bare necessities for basic vf
1591 : : * operation have been implemented
1592 : : */
1593 : : static const struct eth_dev_ops txgbevf_eth_dev_ops = {
1594 : : .dev_configure = txgbevf_dev_configure,
1595 : : .dev_start = txgbevf_dev_start,
1596 : : .dev_stop = txgbevf_dev_stop,
1597 : : .link_update = txgbevf_dev_link_update,
1598 : : .stats_get = txgbevf_dev_stats_get,
1599 : : .xstats_get = txgbevf_dev_xstats_get,
1600 : : .stats_reset = txgbevf_dev_stats_reset,
1601 : : .xstats_reset = txgbevf_dev_stats_reset,
1602 : : .xstats_get_names = txgbevf_dev_xstats_get_names,
1603 : : .dev_close = txgbevf_dev_close,
1604 : : .dev_reset = txgbevf_dev_reset,
1605 : : .promiscuous_enable = txgbevf_dev_promiscuous_enable,
1606 : : .promiscuous_disable = txgbevf_dev_promiscuous_disable,
1607 : : .allmulticast_enable = txgbevf_dev_allmulticast_enable,
1608 : : .allmulticast_disable = txgbevf_dev_allmulticast_disable,
1609 : : .dev_infos_get = txgbevf_dev_info_get,
1610 : : .dev_supported_ptypes_get = txgbe_dev_supported_ptypes_get,
1611 : : .mtu_set = txgbevf_dev_set_mtu,
1612 : : .vlan_filter_set = txgbevf_vlan_filter_set,
1613 : : .vlan_strip_queue_set = txgbevf_vlan_strip_queue_set,
1614 : : .vlan_offload_set = txgbevf_vlan_offload_set,
1615 : : .rx_queue_setup = txgbe_dev_rx_queue_setup,
1616 : : .rx_queue_release = txgbe_dev_rx_queue_release,
1617 : : .tx_queue_setup = txgbe_dev_tx_queue_setup,
1618 : : .tx_queue_release = txgbe_dev_tx_queue_release,
1619 : : .rx_queue_intr_enable = txgbevf_dev_rx_queue_intr_enable,
1620 : : .rx_queue_intr_disable = txgbevf_dev_rx_queue_intr_disable,
1621 : : .mac_addr_add = txgbevf_add_mac_addr,
1622 : : .mac_addr_remove = txgbevf_remove_mac_addr,
1623 : : .set_mc_addr_list = txgbe_dev_set_mc_addr_list,
1624 : : .rxq_info_get = txgbe_rxq_info_get,
1625 : : .txq_info_get = txgbe_txq_info_get,
1626 : : .mac_addr_set = txgbevf_set_default_mac_addr,
1627 : : .get_reg = txgbevf_get_regs,
1628 : : .reta_update = txgbe_dev_rss_reta_update,
1629 : : .reta_query = txgbe_dev_rss_reta_query,
1630 : : .rss_hash_update = txgbe_dev_rss_hash_update,
1631 : : .rss_hash_conf_get = txgbe_dev_rss_hash_conf_get,
1632 : : .tx_done_cleanup = txgbe_dev_tx_done_cleanup,
1633 : : .flow_ops_get = txgbevf_dev_flow_ops_get,
1634 : : };
1635 : :
1636 : 306 : RTE_PMD_REGISTER_PCI(net_txgbe_vf, rte_txgbevf_pmd);
1637 : : RTE_PMD_REGISTER_PCI_TABLE(net_txgbe_vf, pci_id_txgbevf_map);
1638 : : RTE_PMD_REGISTER_KMOD_DEP(net_txgbe_vf, "* igb_uio | vfio-pci");
|