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();
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->max_vmdq_pools = RTE_ETH_64_POOLS;
579 : 0 : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
580 : 0 : dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
581 : 0 : dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
582 : 0 : dev_info->rx_queue_offload_capa);
583 : 0 : dev_info->tx_queue_offload_capa = txgbe_get_tx_queue_offloads(dev);
584 : 0 : dev_info->tx_offload_capa = txgbe_get_tx_port_offloads(dev);
585 : 0 : dev_info->hash_key_size = TXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
586 : 0 : dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
587 : 0 : dev_info->flow_type_rss_offloads = TXGBE_RSS_OFFLOAD_ALL;
588 : :
589 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
590 : : .rx_thresh = {
591 : : .pthresh = TXGBE_DEFAULT_RX_PTHRESH,
592 : : .hthresh = TXGBE_DEFAULT_RX_HTHRESH,
593 : : .wthresh = TXGBE_DEFAULT_RX_WTHRESH,
594 : : },
595 : : .rx_free_thresh = TXGBE_DEFAULT_RX_FREE_THRESH,
596 : : .rx_drop_en = 0,
597 : : .offloads = 0,
598 : : };
599 : :
600 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
601 : : .tx_thresh = {
602 : : .pthresh = TXGBE_DEFAULT_TX_PTHRESH,
603 : : .hthresh = TXGBE_DEFAULT_TX_HTHRESH,
604 : : .wthresh = TXGBE_DEFAULT_TX_WTHRESH,
605 : : },
606 : : .tx_free_thresh = TXGBE_DEFAULT_TX_FREE_THRESH,
607 : : .offloads = 0,
608 : : };
609 : :
610 : 0 : dev_info->rx_desc_lim = rx_desc_lim;
611 : 0 : dev_info->tx_desc_lim = tx_desc_lim;
612 : :
613 : 0 : dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PASSIVE;
614 : :
615 : 0 : return 0;
616 : : }
617 : :
618 : : static int
619 : 0 : txgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
620 : : {
621 : 0 : return txgbe_dev_link_update_share(dev, wait_to_complete);
622 : : }
623 : :
624 : : /*
625 : : * Virtual Function operations
626 : : */
627 : : static void
628 : 0 : txgbevf_intr_disable(struct rte_eth_dev *dev)
629 : : {
630 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
631 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
632 : :
633 : 0 : PMD_INIT_FUNC_TRACE();
634 : :
635 : : /* Clear interrupt mask to stop from interrupts being generated */
636 : : wr32(hw, TXGBE_VFIMS, TXGBE_VFIMS_MASK);
637 : :
638 : : txgbe_flush(hw);
639 : :
640 : : /* Clear mask value. */
641 : 0 : intr->mask_misc = TXGBE_VFIMS_MASK;
642 : 0 : }
643 : :
644 : : static void
645 : 0 : txgbevf_intr_enable(struct rte_eth_dev *dev)
646 : : {
647 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
648 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
649 : :
650 : 0 : PMD_INIT_FUNC_TRACE();
651 : :
652 : : /* VF enable interrupt autoclean */
653 : : wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
654 : :
655 : : txgbe_flush(hw);
656 : :
657 : 0 : intr->mask_misc = 0;
658 : 0 : }
659 : :
660 : : static int
661 : 0 : txgbevf_dev_configure(struct rte_eth_dev *dev)
662 : : {
663 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
664 : 0 : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
665 : :
666 : 0 : PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
667 : : dev->data->port_id);
668 : :
669 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
670 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
671 : :
672 : : /*
673 : : * VF has no ability to enable/disable HW CRC
674 : : * Keep the persistent behavior the same as Host PF
675 : : */
676 : : #ifndef RTE_LIBRTE_TXGBE_PF_DISABLE_STRIP_CRC
677 [ # # ]: 0 : if (conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
678 : 0 : PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
679 : 0 : conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
680 : : }
681 : : #else
682 : : if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
683 : : PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
684 : : conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
685 : : }
686 : : #endif
687 : :
688 : : /*
689 : : * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
690 : : * allocation or vector Rx preconditions we will reset it.
691 : : */
692 : 0 : adapter->rx_bulk_alloc_allowed = true;
693 : 0 : adapter->rx_vec_allowed = true;
694 : :
695 : 0 : return 0;
696 : : }
697 : :
698 : : static int
699 : 0 : txgbevf_dev_start(struct rte_eth_dev *dev)
700 : : {
701 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
702 : : uint32_t intr_vector = 0;
703 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
704 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
705 : :
706 : : int err, mask = 0;
707 : :
708 : 0 : PMD_INIT_FUNC_TRACE();
709 : :
710 : : /* Stop the link setup handler before resetting the HW. */
711 : 0 : txgbe_dev_wait_setup_link_complete(dev, 0);
712 : :
713 : 0 : err = hw->mac.reset_hw(hw);
714 [ # # ]: 0 : if (err) {
715 : 0 : PMD_INIT_LOG(ERR, "Unable to reset vf hardware (%d)", err);
716 : 0 : return err;
717 : : }
718 : 0 : hw->mac.get_link_status = true;
719 : 0 : hw->dev_start = true;
720 : :
721 : : /* negotiate mailbox API version to use with the PF. */
722 : 0 : txgbevf_negotiate_api(hw);
723 : :
724 : 0 : txgbevf_dev_tx_init(dev);
725 : :
726 : : /* This can fail when allocating mbufs for descriptor rings */
727 : 0 : err = txgbevf_dev_rx_init(dev);
728 : :
729 : : /**
730 : : * In this case, reuses the MAC address assigned by VF
731 : : * initialization.
732 : : */
733 [ # # ]: 0 : if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
734 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
735 : 0 : txgbe_dev_clear_queues(dev);
736 : 0 : return err;
737 : : }
738 : :
739 : : /* Set vfta */
740 : 0 : txgbevf_set_vfta_all(dev, 1);
741 : :
742 : : /* Set HW strip */
743 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
744 : : RTE_ETH_VLAN_EXTEND_MASK;
745 : 0 : err = txgbevf_vlan_offload_config(dev, mask);
746 [ # # ]: 0 : if (err) {
747 : 0 : PMD_INIT_LOG(ERR, "Unable to set VLAN offload (%d)", err);
748 : 0 : txgbe_dev_clear_queues(dev);
749 : 0 : return err;
750 : : }
751 : :
752 : 0 : txgbevf_dev_rxtx_start(dev);
753 : :
754 : : /* check and configure queue intr-vector mapping */
755 [ # # ]: 0 : if (rte_intr_cap_multiple(intr_handle) &&
756 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq) {
757 : : /* According to datasheet, only vector 0/1/2 can be used,
758 : : * now only one vector is used for Rx queue
759 : : */
760 : : intr_vector = 1;
761 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector)) {
762 : 0 : txgbe_dev_clear_queues(dev);
763 : 0 : return -1;
764 : : }
765 : : }
766 : :
767 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
768 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
769 : 0 : dev->data->nb_rx_queues)) {
770 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
771 : : " intr_vec", dev->data->nb_rx_queues);
772 : 0 : txgbe_dev_clear_queues(dev);
773 : 0 : return -ENOMEM;
774 : : }
775 : : }
776 : 0 : txgbevf_configure_msix(dev);
777 : :
778 : : /* When a VF port is bound to VFIO-PCI, only miscellaneous interrupt
779 : : * is mapped to VFIO vector 0 in eth_txgbevf_dev_init( ).
780 : : * If previous VFIO interrupt mapping setting in eth_txgbevf_dev_init( )
781 : : * is not cleared, it will fail when following rte_intr_enable( ) tries
782 : : * to map Rx queue interrupt to other VFIO vectors.
783 : : * So clear uio/vfio intr/evevnfd first to avoid failure.
784 : : */
785 : 0 : rte_intr_disable(intr_handle);
786 : :
787 : 0 : rte_intr_enable(intr_handle);
788 : :
789 : : /* Re-enable interrupt for VF */
790 : 0 : txgbevf_intr_enable(dev);
791 : :
792 : : /*
793 : : * Update link status right before return, because it may
794 : : * start link configuration process in a separate thread.
795 : : */
796 : : txgbevf_dev_link_update(dev, 0);
797 : :
798 : 0 : hw->adapter_stopped = false;
799 : :
800 : 0 : return 0;
801 : : }
802 : :
803 : : static int
804 : 0 : txgbevf_dev_stop(struct rte_eth_dev *dev)
805 : : {
806 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
807 : : struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
808 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
809 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
810 : :
811 [ # # ]: 0 : if (hw->adapter_stopped)
812 : : return 0;
813 : :
814 : 0 : PMD_INIT_FUNC_TRACE();
815 : :
816 : 0 : txgbe_dev_wait_setup_link_complete(dev, 0);
817 : :
818 : 0 : txgbevf_intr_disable(dev);
819 : :
820 : 0 : hw->adapter_stopped = 1;
821 : 0 : hw->mac.stop_hw(hw);
822 : :
823 : : /*
824 : : * Clear what we set, but we still keep shadow_vfta to
825 : : * restore after device starts
826 : : */
827 : 0 : txgbevf_set_vfta_all(dev, 0);
828 : :
829 : : /* Clear stored conf */
830 : 0 : dev->data->scattered_rx = 0;
831 : :
832 : 0 : txgbe_dev_clear_queues(dev);
833 : :
834 : : /* Clean datapath event and queue/vec mapping */
835 : 0 : rte_intr_efd_disable(intr_handle);
836 : 0 : rte_intr_vec_list_free(intr_handle);
837 : :
838 : 0 : adapter->rss_reta_updated = 0;
839 : 0 : hw->dev_start = false;
840 : :
841 : 0 : return 0;
842 : : }
843 : :
844 : : static int
845 : 0 : txgbevf_dev_close(struct rte_eth_dev *dev)
846 : : {
847 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
848 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
849 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
850 : : int ret;
851 : :
852 : 0 : PMD_INIT_FUNC_TRACE();
853 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
854 : : return 0;
855 : :
856 : 0 : hw->mac.reset_hw(hw);
857 : :
858 : 0 : ret = txgbevf_dev_stop(dev);
859 : :
860 : 0 : txgbe_dev_free_queues(dev);
861 : :
862 : : /**
863 : : * Remove the VF MAC address ro ensure
864 : : * that the VF traffic goes to the PF
865 : : * after stop, close and detach of the VF
866 : : **/
867 : 0 : txgbevf_remove_mac_addr(dev, 0);
868 : :
869 : : /* Disable the interrupts for VF */
870 : 0 : txgbevf_intr_disable(dev);
871 : :
872 : 0 : rte_free(dev->data->mac_addrs);
873 : 0 : dev->data->mac_addrs = NULL;
874 : :
875 : 0 : rte_intr_disable(intr_handle);
876 : 0 : rte_intr_callback_unregister(intr_handle,
877 : : txgbevf_dev_interrupt_handler, dev);
878 : :
879 : : /* remove all the fdir filters & hash */
880 : 0 : txgbe_fdir_filter_uninit(dev);
881 : :
882 : : /* Remove all ntuple filters of the device */
883 : 0 : txgbe_ntuple_filter_uninit(dev);
884 : :
885 : : /* clear all the filters list */
886 : 0 : txgbe_filterlist_flush();
887 : :
888 : 0 : return ret;
889 : : }
890 : :
891 : : /*
892 : : * Reset VF device
893 : : */
894 : : static int
895 : 0 : txgbevf_dev_reset(struct rte_eth_dev *dev)
896 : : {
897 : : int ret;
898 : :
899 : 0 : ret = eth_txgbevf_dev_uninit(dev);
900 [ # # ]: 0 : if (ret)
901 : : return ret;
902 : :
903 : 0 : ret = eth_txgbevf_dev_init(dev);
904 : :
905 : 0 : return ret;
906 : : }
907 : :
908 : 0 : static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
909 : : {
910 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
911 : : struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
912 : : int i = 0, j = 0, vfta = 0, mask = 1;
913 : :
914 [ # # ]: 0 : for (i = 0; i < TXGBE_VFTA_SIZE; i++) {
915 : 0 : vfta = shadow_vfta->vfta[i];
916 [ # # ]: 0 : if (vfta) {
917 : : mask = 1;
918 [ # # ]: 0 : for (j = 0; j < 32; j++) {
919 [ # # ]: 0 : if (vfta & mask)
920 : 0 : hw->mac.set_vfta(hw, (i << 5) + j, 0,
921 : : on, false);
922 : 0 : mask <<= 1;
923 : : }
924 : : }
925 : : }
926 : 0 : }
927 : :
928 : : static int
929 : 0 : txgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
930 : : {
931 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
932 : : struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
933 : : uint32_t vid_idx = 0;
934 : : uint32_t vid_bit = 0;
935 : : int ret = 0;
936 : :
937 : 0 : PMD_INIT_FUNC_TRACE();
938 : :
939 : : /* vind is not used in VF driver, set to 0, check txgbe_set_vfta_vf */
940 : 0 : ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
941 [ # # ]: 0 : if (ret) {
942 : 0 : PMD_INIT_LOG(ERR, "Unable to set VF vlan");
943 : 0 : return ret;
944 : : }
945 : 0 : vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
946 : 0 : vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
947 : :
948 : : /* Save what we set and restore it after device reset */
949 [ # # ]: 0 : if (on)
950 : 0 : shadow_vfta->vfta[vid_idx] |= vid_bit;
951 : : else
952 : 0 : shadow_vfta->vfta[vid_idx] &= ~vid_bit;
953 : :
954 : : return 0;
955 : : }
956 : :
957 : : static void
958 : 0 : txgbevf_vlan_strip_q_set(struct rte_eth_dev *dev, uint16_t queue, int on)
959 : : {
960 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
961 : : uint32_t ctrl;
962 : :
963 : 0 : PMD_INIT_FUNC_TRACE();
964 : :
965 [ # # ]: 0 : if (queue >= hw->mac.max_rx_queues)
966 : : return;
967 : :
968 : 0 : ctrl = rd32(hw, TXGBE_RXCFG(queue));
969 [ # # ]: 0 : if (on)
970 : 0 : ctrl |= TXGBE_RXCFG_VLAN;
971 : : else
972 : 0 : ctrl &= ~TXGBE_RXCFG_VLAN;
973 : : wr32(hw, TXGBE_RXCFG(queue), ctrl);
974 : :
975 : 0 : txgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
976 : : }
977 : :
978 : : static void
979 : 0 : txgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
980 : : {
981 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
982 : :
983 [ # # ]: 0 : if (!hw->adapter_stopped) {
984 : 0 : PMD_DRV_LOG(ERR, "Please stop port first");
985 : 0 : return;
986 : : }
987 : :
988 : 0 : txgbevf_vlan_strip_q_set(dev, queue, on);
989 : : }
990 : :
991 : : static int
992 : 0 : txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
993 : : {
994 : : struct txgbe_rx_queue *rxq;
995 : : uint16_t i;
996 : : int on = 0;
997 : :
998 : : /* VF function only support hw strip feature, others are not support */
999 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1000 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1001 : 0 : rxq = dev->data->rx_queues[i];
1002 : 0 : on = !!(rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
1003 : 0 : txgbevf_vlan_strip_q_set(dev, i, on);
1004 : : }
1005 : : }
1006 : :
1007 : 0 : return 0;
1008 : : }
1009 : :
1010 : : static int
1011 : 0 : txgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1012 : : {
1013 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1014 : :
1015 [ # # # # ]: 0 : if (!hw->adapter_stopped && (mask & RTE_ETH_VLAN_STRIP_MASK)) {
1016 : 0 : PMD_DRV_LOG(ERR, "Please stop port first");
1017 : 0 : return -EPERM;
1018 : : }
1019 : :
1020 : 0 : txgbe_config_vlan_strip_on_all_queues(dev, mask);
1021 : :
1022 : 0 : txgbevf_vlan_offload_config(dev, mask);
1023 : :
1024 : 0 : return 0;
1025 : : }
1026 : :
1027 : : static int
1028 : 0 : txgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1029 : : {
1030 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1031 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1032 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1033 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1034 : : uint32_t vec = TXGBE_MISC_VEC_ID;
1035 : :
1036 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
1037 : : vec = TXGBE_RX_VEC_START;
1038 : 0 : intr->mask_misc &= ~(1 << vec);
1039 : : RTE_SET_USED(queue_id);
1040 : 0 : wr32(hw, TXGBE_VFIMC, ~intr->mask_misc);
1041 : :
1042 : 0 : rte_intr_enable(intr_handle);
1043 : :
1044 : 0 : return 0;
1045 : : }
1046 : :
1047 : : static int
1048 : 0 : txgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1049 : : {
1050 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1051 : : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1052 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1053 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1054 : : uint32_t vec = TXGBE_MISC_VEC_ID;
1055 : :
1056 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
1057 : : vec = TXGBE_RX_VEC_START;
1058 : 0 : intr->mask_misc |= (1 << vec);
1059 : : RTE_SET_USED(queue_id);
1060 : : wr32(hw, TXGBE_VFIMS, intr->mask_misc);
1061 : :
1062 : 0 : return 0;
1063 : : }
1064 : :
1065 : : static void
1066 : 0 : txgbevf_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
1067 : : uint8_t queue, uint8_t msix_vector)
1068 : : {
1069 : : uint32_t tmp, idx;
1070 : :
1071 [ # # ]: 0 : if (direction == -1) {
1072 : : /* other causes */
1073 : 0 : msix_vector |= TXGBE_VFIVAR_VLD;
1074 : : tmp = rd32(hw, TXGBE_VFIVARMISC);
1075 : 0 : tmp &= ~0xFF;
1076 : 0 : tmp |= msix_vector;
1077 : : wr32(hw, TXGBE_VFIVARMISC, tmp);
1078 : : } else {
1079 : : /* rx or tx cause */
1080 : 0 : msix_vector |= TXGBE_VFIVAR_VLD; /* Workaround for ICR lost */
1081 : 0 : idx = ((16 * (queue & 1)) + (8 * direction));
1082 : 0 : tmp = rd32(hw, TXGBE_VFIVAR(queue >> 1));
1083 : 0 : tmp &= ~(0xFF << idx);
1084 : 0 : tmp |= (msix_vector << idx);
1085 : : wr32(hw, TXGBE_VFIVAR(queue >> 1), tmp);
1086 : : }
1087 : 0 : }
1088 : :
1089 : : static void
1090 : 0 : txgbevf_configure_msix(struct rte_eth_dev *dev)
1091 : : {
1092 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1093 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1094 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1095 : : uint32_t q_idx;
1096 : : uint32_t vector_idx = TXGBE_MISC_VEC_ID;
1097 : : uint32_t base = TXGBE_MISC_VEC_ID;
1098 : :
1099 : : /* Configure VF other cause ivar */
1100 : : txgbevf_set_ivar_map(hw, -1, 1, vector_idx);
1101 : :
1102 : : /* won't configure msix register if no mapping is done
1103 : : * between intr vector and event fd.
1104 : : */
1105 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle))
1106 : : return;
1107 : :
1108 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
1109 : : base = TXGBE_RX_VEC_START;
1110 : : vector_idx = TXGBE_RX_VEC_START;
1111 : : }
1112 : :
1113 : : /* Configure all RX queues of VF */
1114 [ # # ]: 0 : for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
1115 : : /* Force all queue use vector 0,
1116 : : * as TXGBE_VF_MAXMSIVECTOR = 1
1117 : : */
1118 : 0 : txgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
1119 : 0 : rte_intr_vec_list_index_set(intr_handle, q_idx,
1120 : : vector_idx);
1121 : 0 : if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
1122 [ # # ]: 0 : - 1)
1123 : 0 : vector_idx++;
1124 : : }
1125 : :
1126 : : /* As RX queue setting above show, all queues use the vector 0.
1127 : : * Set only the ITR value of TXGBE_MISC_VEC_ID.
1128 : : */
1129 : : wr32(hw, TXGBE_ITR(TXGBE_MISC_VEC_ID),
1130 : : TXGBE_ITR_IVAL(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
1131 : : | TXGBE_ITR_WRDSA);
1132 : : }
1133 : :
1134 : : static int
1135 : 0 : txgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1136 : : __rte_unused uint32_t index,
1137 : : __rte_unused uint32_t pool)
1138 : : {
1139 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1140 : : int err;
1141 : :
1142 : : /*
1143 : : * On a VF, adding again the same MAC addr is not an idempotent
1144 : : * operation. Trap this case to avoid exhausting the [very limited]
1145 : : * set of PF resources used to store VF MAC addresses.
1146 : : */
1147 [ # # ]: 0 : if (memcmp(hw->mac.perm_addr, mac_addr,
1148 : : sizeof(struct rte_ether_addr)) == 0)
1149 : : return -1;
1150 : 0 : err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1151 [ # # ]: 0 : if (err != 0)
1152 : 0 : PMD_DRV_LOG(ERR, "Unable to add MAC address "
1153 : : RTE_ETHER_ADDR_PRT_FMT " - err=%d",
1154 : : RTE_ETHER_ADDR_BYTES(mac_addr), err);
1155 : : return err;
1156 : : }
1157 : :
1158 : : static void
1159 : 0 : txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
1160 : : {
1161 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1162 : 0 : struct rte_ether_addr *perm_addr =
1163 : : (struct rte_ether_addr *)hw->mac.perm_addr;
1164 : : struct rte_ether_addr *mac_addr;
1165 : : uint32_t i;
1166 : : int err;
1167 : :
1168 : : /*
1169 : : * The TXGBE_VF_SET_MACVLAN command of the txgbe-pf driver does
1170 : : * not support the deletion of a given MAC address.
1171 : : * Instead, it imposes to delete all MAC addresses, then to add again
1172 : : * all MAC addresses with the exception of the one to be deleted.
1173 : : */
1174 : 0 : (void)txgbevf_set_uc_addr_vf(hw, 0, NULL);
1175 : :
1176 : : /*
1177 : : * Add again all MAC addresses, with the exception of the deleted one
1178 : : * and of the permanent MAC address.
1179 : : */
1180 : 0 : for (i = 0, mac_addr = dev->data->mac_addrs;
1181 [ # # ]: 0 : i < hw->mac.num_rar_entries; i++, mac_addr++) {
1182 : : /* Skip the deleted MAC address */
1183 [ # # ]: 0 : if (i == index)
1184 : 0 : continue;
1185 : : /* Skip NULL MAC addresses */
1186 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac_addr))
1187 : 0 : continue;
1188 : : /* Skip the permanent MAC address */
1189 [ # # ]: 0 : if (memcmp(perm_addr, mac_addr,
1190 : : sizeof(struct rte_ether_addr)) == 0)
1191 : 0 : continue;
1192 : 0 : err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1193 [ # # ]: 0 : if (err != 0)
1194 : 0 : PMD_DRV_LOG(ERR,
1195 : : "Adding again MAC address "
1196 : : RTE_ETHER_ADDR_PRT_FMT " failed "
1197 : : "err=%d",
1198 : : RTE_ETHER_ADDR_BYTES(mac_addr), err);
1199 : : }
1200 : 0 : }
1201 : :
1202 : : static int
1203 : 0 : txgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
1204 : : struct rte_ether_addr *addr)
1205 : : {
1206 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1207 : :
1208 : 0 : hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
1209 : :
1210 : 0 : return 0;
1211 : : }
1212 : :
1213 : : static int
1214 : 0 : txgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1215 : : {
1216 : : struct txgbe_hw *hw;
1217 : 0 : uint32_t max_frame = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1218 : 0 : struct rte_eth_dev_data *dev_data = dev->data;
1219 : :
1220 : 0 : hw = TXGBE_DEV_HW(dev);
1221 : :
1222 : 0 : if (mtu < RTE_ETHER_MIN_MTU ||
1223 [ # # ]: 0 : max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
1224 : : return -EINVAL;
1225 : :
1226 : : /* If device is started, refuse mtu that requires the support of
1227 : : * scattered packets when this feature has not been enabled before.
1228 : : */
1229 [ # # ]: 0 : if (dev_data->dev_started && !dev_data->scattered_rx &&
1230 : 0 : (max_frame + 2 * RTE_VLAN_HLEN >
1231 [ # # ]: 0 : dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
1232 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
1233 : 0 : return -EINVAL;
1234 : : }
1235 : :
1236 : : /*
1237 : : * When supported by the underlying PF driver, use the TXGBE_VF_SET_MTU
1238 : : * request of the version 2.0 of the mailbox API.
1239 : : * For now, use the TXGBE_VF_SET_LPE request of the version 1.0
1240 : : * of the mailbox API.
1241 : : */
1242 [ # # ]: 0 : if (txgbevf_rlpml_set_vf(hw, max_frame))
1243 : 0 : return -EINVAL;
1244 : :
1245 : : return 0;
1246 : : }
1247 : :
1248 : : static int
1249 : : txgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
1250 : : {
1251 : : int count = 0;
1252 : : int g_ind = 0;
1253 : : const struct reg_info *reg_group;
1254 : :
1255 [ # # # # ]: 0 : while ((reg_group = txgbevf_regs[g_ind++]))
1256 : 0 : count += txgbe_regs_group_count(reg_group);
1257 : :
1258 : : return count;
1259 : : }
1260 : :
1261 : : static int
1262 : 0 : txgbevf_get_regs(struct rte_eth_dev *dev,
1263 : : struct rte_dev_reg_info *regs)
1264 : : {
1265 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1266 : 0 : uint32_t *data = regs->data;
1267 : : int g_ind = 0;
1268 : : int count = 0;
1269 : : const struct reg_info *reg_group;
1270 : :
1271 [ # # ]: 0 : if (data == NULL) {
1272 : 0 : regs->length = txgbevf_get_reg_length(dev);
1273 : 0 : regs->width = sizeof(uint32_t);
1274 : 0 : return 0;
1275 : : }
1276 : :
1277 : : /* Support only full register dump */
1278 [ # # ]: 0 : if (regs->length == 0 ||
1279 [ # # ]: 0 : regs->length == (uint32_t)txgbevf_get_reg_length(dev)) {
1280 : 0 : regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
1281 : 0 : hw->device_id;
1282 [ # # ]: 0 : while ((reg_group = txgbevf_regs[g_ind++]))
1283 : 0 : count += txgbe_read_regs_group(dev, &data[count],
1284 : : reg_group);
1285 : : return 0;
1286 : : }
1287 : :
1288 : : return -ENOTSUP;
1289 : : }
1290 : :
1291 : : static int
1292 : 0 : txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1293 : : {
1294 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1295 : : int ret;
1296 : :
1297 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_PROMISC)) {
1298 : : case 0:
1299 : : ret = 0;
1300 : : break;
1301 : 0 : case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1302 : : ret = -ENOTSUP;
1303 : 0 : break;
1304 : 0 : default:
1305 : : ret = -EAGAIN;
1306 : 0 : break;
1307 : : }
1308 : :
1309 : 0 : return ret;
1310 : : }
1311 : :
1312 : : static int
1313 : 0 : txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1314 : : {
1315 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1316 : : int mode = TXGBEVF_XCAST_MODE_NONE;
1317 : : int ret;
1318 : :
1319 [ # # ]: 0 : if (dev->data->all_multicast)
1320 : : mode = TXGBEVF_XCAST_MODE_ALLMULTI;
1321 : :
1322 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, mode)) {
1323 : : case 0:
1324 : : ret = 0;
1325 : : break;
1326 : 0 : case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1327 : : ret = -ENOTSUP;
1328 : 0 : break;
1329 : 0 : default:
1330 : : ret = -EAGAIN;
1331 : 0 : break;
1332 : : }
1333 : :
1334 : 0 : return ret;
1335 : : }
1336 : :
1337 : : static int
1338 : 0 : txgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1339 : : {
1340 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1341 : : int ret;
1342 : :
1343 [ # # ]: 0 : if (dev->data->promiscuous)
1344 : : return 0;
1345 : :
1346 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_ALLMULTI)) {
1347 : : case 0:
1348 : : ret = 0;
1349 : : break;
1350 : 0 : case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1351 : : ret = -ENOTSUP;
1352 : 0 : break;
1353 : 0 : default:
1354 : : ret = -EAGAIN;
1355 : 0 : break;
1356 : : }
1357 : :
1358 : : return ret;
1359 : : }
1360 : :
1361 : : static int
1362 : 0 : txgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1363 : : {
1364 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1365 : : int ret;
1366 : :
1367 [ # # ]: 0 : if (dev->data->promiscuous)
1368 : : return 0;
1369 : :
1370 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_MULTI)) {
1371 : : case 0:
1372 : : ret = 0;
1373 : : break;
1374 : 0 : case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1375 : : ret = -ENOTSUP;
1376 : 0 : break;
1377 : 0 : default:
1378 : : ret = -EAGAIN;
1379 : 0 : break;
1380 : : }
1381 : :
1382 : : return ret;
1383 : : }
1384 : :
1385 : : /**
1386 : : * txgbevf_get_pf_link_status - Get pf link/speed status
1387 : : * @hw: pointer to hardware structure
1388 : : *
1389 : : * - PF notifies status via mailbox on change
1390 : : * - VF sets its link state synchronously upon mailbox interrupt,
1391 : : * skipping hardware link detection.
1392 : : **/
1393 : 0 : static s32 txgbevf_get_pf_link_status(struct rte_eth_dev *dev)
1394 : : {
1395 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1396 : : struct txgbe_mbx_info *mbx = &hw->mbx;
1397 : : struct rte_eth_link link;
1398 : : u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
1399 : : bool link_up = false;
1400 : : u32 msgbuf[2];
1401 : : s32 retval;
1402 : :
1403 : 0 : retval = mbx->read(hw, msgbuf, 2, 0);
1404 : :
1405 : : /*
1406 : : *if the read failed it could just be a mailbox collision, best wait
1407 : : * until we are called again and don't report an error
1408 : : */
1409 [ # # ]: 0 : if (retval)
1410 : : return 0;
1411 : :
1412 [ # # ]: 0 : if (!(msgbuf[0] & TXGBE_NOFITY_VF_LINK_STATUS))
1413 : : return 0;
1414 : :
1415 : 0 : rte_eth_linkstatus_get(dev, &link);
1416 : :
1417 [ # # ]: 0 : if (!rte_atomic_load_explicit(&hw->pf_running,
1418 : : rte_memory_order_acquire)) {
1419 : 0 : link.link_status = RTE_ETH_LINK_DOWN;
1420 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1421 [ # # ]: 0 : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1422 : 0 : return rte_eth_linkstatus_set(dev, &link);
1423 : : }
1424 : :
1425 : 0 : link_up = msgbuf[1] & TXGBE_VFSTATUS_UP;
1426 : 0 : link_speed = (msgbuf[1] & 0x1FFFFE) >> 1;
1427 : :
1428 [ # # # # ]: 0 : if (link_up == link.link_status && link_speed == link.link_speed)
1429 : : return 0;
1430 : :
1431 : 0 : link.link_speed = link_speed;
1432 : 0 : link.link_status = link_up;
1433 : :
1434 [ # # ]: 0 : if (link_up)
1435 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1436 : : else
1437 : 0 : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1438 : : /*
1439 : : * Invoke the LSC interrupt callback to notify the upper app of a link
1440 : : * status change, even though the change is detected via a mailbox interrupt
1441 : : * instead of an LSC interrupt. This is because VF link status changes do
1442 : : * not trigger LSC interrupts — they rely on PF notifications.
1443 : : */
1444 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
1445 : : NULL);
1446 : : return rte_eth_linkstatus_set(dev, &link);
1447 : : }
1448 : :
1449 : 0 : static void txgbevf_check_link_for_intr(struct rte_eth_dev *dev)
1450 : : {
1451 : : struct rte_eth_link orig_link, new_link;
1452 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1453 : :
1454 : 0 : rte_eth_linkstatus_get(dev, &orig_link);
1455 : :
1456 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->pf_running,
1457 : : rte_memory_order_acquire)) {
1458 : : txgbevf_dev_link_update(dev, 0);
1459 : 0 : rte_eth_linkstatus_get(dev, &new_link);
1460 : : } else {
1461 : 0 : DEBUGOUT("PF ifconfig down, so VF link down");
1462 : 0 : new_link.link_status = RTE_ETH_LINK_DOWN;
1463 : 0 : new_link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1464 : 0 : new_link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1465 : 0 : new_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1466 : : RTE_ETH_LINK_SPEED_FIXED);
1467 : 0 : rte_eth_linkstatus_set(dev, &new_link);
1468 : : }
1469 : :
1470 : 0 : PMD_DRV_LOG(INFO, "orig_link: %d, new_link: %d",
1471 : : orig_link.link_status, new_link.link_status);
1472 : :
1473 [ # # ]: 0 : if (new_link.link_status != orig_link.link_status)
1474 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
1475 : : NULL);
1476 : 0 : }
1477 : :
1478 : 0 : static void txgbevf_mbx_process(struct rte_eth_dev *dev)
1479 : : {
1480 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1481 : : struct txgbe_mbx_info *mbx = &hw->mbx;
1482 : 0 : u32 msgbuf = 0;
1483 : : u32 in_msg = 0;
1484 : :
1485 : : /* Peek the message first */
1486 : : in_msg = rd32(hw, TXGBE_VFMBX);
1487 : :
1488 : : /* PF control message */
1489 [ # # ]: 0 : if (!(in_msg & TXGBE_PF_CONTROL_MSG))
1490 : 0 : return;
1491 : :
1492 : 0 : txgbevf_get_pf_link_status(dev);
1493 : :
1494 [ # # ]: 0 : if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
1495 : : /*
1496 : : * PF is not ready for this VF (e.g. PF ifconfig down).
1497 : : *
1498 : : * Send VF_RESET to ask the PF to reconfigure us. The PF only
1499 : : * marks this VF as ready (and starts sending CTS) after it
1500 : : * processes VF_RESET, so this request is the only way to
1501 : : * recover. If write_posted() succeeds the PF is back up and
1502 : : * we notify the application to reset the VF; otherwise the PF
1503 : : * is still down, so we mark it down and reset the stats
1504 : : * baselines (hardware counters are cleared during PF reset).
1505 : : *
1506 : : * write_posted() may busy-wait for the ACK in the interrupt
1507 : : * thread, but the PF does not send further mailbox messages
1508 : : * once it is down, so this blocking is not continuously
1509 : : * triggered.
1510 : : */
1511 : : int err;
1512 : :
1513 : 0 : msgbuf = TXGBE_VF_RESET;
1514 : 0 : err = mbx->write_posted(hw, &msgbuf, 1, 0);
1515 [ # # ]: 0 : if (err) {
1516 : 0 : rte_atomic_store_explicit(&hw->pf_running, false,
1517 : : rte_memory_order_release);
1518 : 0 : txgbevf_check_link_for_intr(dev);
1519 : 0 : hw->rx_loaded = true;
1520 : 0 : hw->offset_loaded = true;
1521 : : } else {
1522 : 0 : rte_atomic_store_explicit(&hw->pf_running, true,
1523 : : rte_memory_order_release);
1524 : 0 : rte_eth_dev_callback_process(dev,
1525 : : RTE_ETH_EVENT_INTR_RESET, NULL);
1526 : : }
1527 : 0 : return;
1528 : : }
1529 : :
1530 : : /* Check link status if pf only ping vf */
1531 [ # # ]: 0 : if (!(in_msg & TXGBE_NOFITY_VF_LINK_STATUS))
1532 : 0 : txgbevf_check_link_for_intr(dev);
1533 : : }
1534 : :
1535 : : static int
1536 : 0 : txgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
1537 : : {
1538 : : uint32_t eicr;
1539 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1540 : : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1541 : 0 : txgbevf_intr_disable(dev);
1542 : :
1543 : : /* read-on-clear nic registers here */
1544 : : eicr = rd32(hw, TXGBE_VFICR);
1545 : : intr->flags = 0;
1546 : :
1547 : : /* only one misc vector supported - mailbox */
1548 : : eicr &= TXGBE_VFICR_MASK;
1549 : : /* Workaround for ICR lost */
1550 : 0 : intr->flags |= TXGBE_FLAG_MAILBOX;
1551 : :
1552 : : /* To avoid compiler warnings set eicr to used. */
1553 : : RTE_SET_USED(eicr);
1554 : :
1555 : 0 : return 0;
1556 : : }
1557 : :
1558 : : static int
1559 : 0 : txgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
1560 : : {
1561 : 0 : struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1562 : :
1563 [ # # ]: 0 : if (intr->flags & TXGBE_FLAG_MAILBOX) {
1564 : 0 : txgbevf_mbx_process(dev);
1565 : 0 : intr->flags &= ~TXGBE_FLAG_MAILBOX;
1566 : : }
1567 : :
1568 : 0 : txgbevf_intr_enable(dev);
1569 : :
1570 : 0 : return 0;
1571 : : }
1572 : :
1573 : : static void
1574 : 0 : txgbevf_dev_interrupt_handler(void *param)
1575 : : {
1576 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1577 : :
1578 : 0 : txgbevf_dev_interrupt_get_status(dev);
1579 : 0 : txgbevf_dev_interrupt_action(dev);
1580 : 0 : }
1581 : :
1582 : : static int
1583 : 0 : txgbevf_dev_flow_ops_get(__rte_unused struct rte_eth_dev *dev,
1584 : : const struct rte_flow_ops **ops)
1585 : : {
1586 : 0 : *ops = &txgbe_flow_ops;
1587 : 0 : return 0;
1588 : : }
1589 : :
1590 : : /*
1591 : : * dev_ops for virtual function, bare necessities for basic vf
1592 : : * operation have been implemented
1593 : : */
1594 : : static const struct eth_dev_ops txgbevf_eth_dev_ops = {
1595 : : .dev_configure = txgbevf_dev_configure,
1596 : : .dev_start = txgbevf_dev_start,
1597 : : .dev_stop = txgbevf_dev_stop,
1598 : : .link_update = txgbevf_dev_link_update,
1599 : : .stats_get = txgbevf_dev_stats_get,
1600 : : .xstats_get = txgbevf_dev_xstats_get,
1601 : : .stats_reset = txgbevf_dev_stats_reset,
1602 : : .xstats_reset = txgbevf_dev_stats_reset,
1603 : : .xstats_get_names = txgbevf_dev_xstats_get_names,
1604 : : .dev_close = txgbevf_dev_close,
1605 : : .dev_reset = txgbevf_dev_reset,
1606 : : .promiscuous_enable = txgbevf_dev_promiscuous_enable,
1607 : : .promiscuous_disable = txgbevf_dev_promiscuous_disable,
1608 : : .allmulticast_enable = txgbevf_dev_allmulticast_enable,
1609 : : .allmulticast_disable = txgbevf_dev_allmulticast_disable,
1610 : : .dev_infos_get = txgbevf_dev_info_get,
1611 : : .dev_supported_ptypes_get = txgbe_dev_supported_ptypes_get,
1612 : : .mtu_set = txgbevf_dev_set_mtu,
1613 : : .vlan_filter_set = txgbevf_vlan_filter_set,
1614 : : .vlan_strip_queue_set = txgbevf_vlan_strip_queue_set,
1615 : : .vlan_offload_set = txgbevf_vlan_offload_set,
1616 : : .rx_queue_setup = txgbe_dev_rx_queue_setup,
1617 : : .rx_queue_release = txgbe_dev_rx_queue_release,
1618 : : .tx_queue_setup = txgbe_dev_tx_queue_setup,
1619 : : .tx_queue_release = txgbe_dev_tx_queue_release,
1620 : : .rx_queue_intr_enable = txgbevf_dev_rx_queue_intr_enable,
1621 : : .rx_queue_intr_disable = txgbevf_dev_rx_queue_intr_disable,
1622 : : .mac_addr_add = txgbevf_add_mac_addr,
1623 : : .mac_addr_remove = txgbevf_remove_mac_addr,
1624 : : .set_mc_addr_list = txgbe_dev_set_mc_addr_list,
1625 : : .rxq_info_get = txgbe_rxq_info_get,
1626 : : .txq_info_get = txgbe_txq_info_get,
1627 : : .mac_addr_set = txgbevf_set_default_mac_addr,
1628 : : .get_reg = txgbevf_get_regs,
1629 : : .reta_update = txgbe_dev_rss_reta_update,
1630 : : .reta_query = txgbe_dev_rss_reta_query,
1631 : : .rss_hash_update = txgbe_dev_rss_hash_update,
1632 : : .rss_hash_conf_get = txgbe_dev_rss_hash_conf_get,
1633 : : .tx_done_cleanup = txgbe_dev_tx_done_cleanup,
1634 : : .flow_ops_get = txgbevf_dev_flow_ops_get,
1635 : : };
1636 : :
1637 : 303 : RTE_PMD_REGISTER_PCI(net_txgbe_vf, rte_txgbevf_pmd);
1638 : : RTE_PMD_REGISTER_PCI_TABLE(net_txgbe_vf, pci_id_txgbevf_map);
1639 : : RTE_PMD_REGISTER_KMOD_DEP(net_txgbe_vf, "* igb_uio | vfio-pci");
|