Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018-2025 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 <ethdev_pci.h>
12 : :
13 : : #include "ngbe_logs.h"
14 : : #include "base/ngbe.h"
15 : : #include "ngbe_ethdev.h"
16 : : #include "ngbe_rxtx.h"
17 : : #include "ngbe_regs_group.h"
18 : :
19 : : static const struct reg_info ngbevf_regs_general[] = {
20 : : {NGBE_VFRST, 1, 1, "NGBE_VFRST"},
21 : : {NGBE_VFSTATUS, 1, 1, "NGBE_VFSTATUS"},
22 : : {NGBE_VFMBCTL, 1, 1, "NGBE_VFMAILBOX"},
23 : : {NGBE_VFMBX, 16, 4, "NGBE_VFMBX"},
24 : : {NGBE_VFPBWRAP, 1, 1, "NGBE_VFPBWRAP"},
25 : : {0, 0, 0, ""}
26 : : };
27 : :
28 : : static const struct reg_info ngbevf_regs_interrupt[] = {
29 : : {0, 0, 0, ""}
30 : : };
31 : :
32 : : static const struct reg_info ngbevf_regs_rxdma[] = {
33 : : {0, 0, 0, ""}
34 : : };
35 : :
36 : : static const struct reg_info ngbevf_regs_tx[] = {
37 : : {0, 0, 0, ""}
38 : : };
39 : :
40 : : /* VF registers */
41 : : static const struct reg_info *ngbevf_regs[] = {
42 : : ngbevf_regs_general,
43 : : ngbevf_regs_interrupt,
44 : : ngbevf_regs_rxdma,
45 : : ngbevf_regs_tx,
46 : : NULL};
47 : :
48 : : #define NGBEVF_PMD_NAME "rte_ngbevf_pmd" /* PMD name */
49 : : static int ngbevf_dev_close(struct rte_eth_dev *dev);
50 : : static int ngbevf_dev_link_update(struct rte_eth_dev *dev,
51 : : int wait_to_complete);
52 : : static void ngbevf_intr_disable(struct rte_eth_dev *dev);
53 : : static void ngbevf_intr_enable(struct rte_eth_dev *dev);
54 : : static int ngbevf_dev_stats_reset(struct rte_eth_dev *dev);
55 : : static int ngbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
56 : : static void ngbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
57 : : static void ngbevf_configure_msix(struct rte_eth_dev *dev);
58 : : static int ngbevf_dev_promiscuous_enable(struct rte_eth_dev *dev);
59 : : static int ngbevf_dev_promiscuous_disable(struct rte_eth_dev *dev);
60 : : static void ngbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
61 : : static void ngbevf_dev_interrupt_handler(void *param);
62 : :
63 : : /*
64 : : * The set of PCI devices this driver supports (for VF)
65 : : */
66 : : static const struct rte_pci_id pci_id_ngbevf_map[] = {
67 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL_W_VF) },
68 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2_VF) },
69 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2S_VF) },
70 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4_VF) },
71 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4S_VF) },
72 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2_VF) },
73 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2S_VF) },
74 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4_VF) },
75 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4S_VF) },
76 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860NCSI_VF) },
77 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1_VF) },
78 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1L_VF) },
79 : : { .vendor_id = 0, /* sentinel */ },
80 : : };
81 : :
82 : : static const struct rte_eth_desc_lim rx_desc_lim = {
83 : : .nb_max = NGBE_RING_DESC_MAX,
84 : : .nb_min = NGBE_RING_DESC_MIN,
85 : : .nb_align = NGBE_RXD_ALIGN,
86 : : };
87 : :
88 : : static const struct rte_eth_desc_lim tx_desc_lim = {
89 : : .nb_max = NGBE_RING_DESC_MAX,
90 : : .nb_min = NGBE_RING_DESC_MIN,
91 : : .nb_align = NGBE_TXD_ALIGN,
92 : : .nb_seg_max = NGBE_TX_MAX_SEG,
93 : : .nb_mtu_seg_max = NGBE_TX_MAX_SEG,
94 : : };
95 : :
96 : : static const struct eth_dev_ops ngbevf_eth_dev_ops;
97 : :
98 : : static const struct rte_ngbe_xstats_name_off rte_ngbevf_stats_strings[] = {
99 : : {"rx_multicast_packets", offsetof(struct ngbevf_hw_stats, vfmprc)},
100 : : };
101 : :
102 : : #define NGBEVF_NB_XSTATS (sizeof(rte_ngbevf_stats_strings) / \
103 : : sizeof(rte_ngbevf_stats_strings[0]))
104 : :
105 : : /*
106 : : * Negotiate mailbox API version with the PF.
107 : : * After reset API version is always set to the basic one (ngbe_mbox_api_10).
108 : : * Then we try to negotiate starting with the most recent one.
109 : : * If all negotiation attempts fail, then we will proceed with
110 : : * the default one (ngbe_mbox_api_10).
111 : : */
112 : : static void
113 : 0 : ngbevf_negotiate_api(struct ngbe_hw *hw)
114 : : {
115 : : int32_t i;
116 : :
117 : : /* start with highest supported, proceed down */
118 : : static const int sup_ver[] = {
119 : : ngbe_mbox_api_13,
120 : : ngbe_mbox_api_12,
121 : : ngbe_mbox_api_11,
122 : : ngbe_mbox_api_10,
123 : : };
124 : :
125 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(sup_ver); i++) {
126 [ # # ]: 0 : if (ngbevf_negotiate_api_version(hw, sup_ver[i]) == 0)
127 : : break;
128 : : }
129 : 0 : }
130 : :
131 : : static void
132 : 0 : generate_random_mac_addr(struct rte_ether_addr *mac_addr)
133 : : {
134 : : uint64_t random;
135 : :
136 : : /* Set Organizationally Unique Identifier (OUI) prefix. */
137 : : mac_addr->addr_bytes[0] = 0x00;
138 : 0 : mac_addr->addr_bytes[1] = 0x09;
139 : 0 : mac_addr->addr_bytes[2] = 0xC0;
140 : : /* Force indication of locally assigned MAC address. */
141 : 0 : mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
142 : : /* Generate the last 3 bytes of the MAC address with a random number. */
143 : 0 : random = rte_rand();
144 : 0 : memcpy(&mac_addr->addr_bytes[3], &random, 3);
145 : 0 : }
146 : :
147 : : /*
148 : : * Virtual Function device init
149 : : */
150 : : static int
151 : 0 : eth_ngbevf_dev_init(struct rte_eth_dev *eth_dev)
152 : : {
153 : : int err;
154 : : uint32_t tc, tcs;
155 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(eth_dev, *pci_dev);
156 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
157 : : struct ngbe_hw *hw = ngbe_dev_hw(eth_dev);
158 : 0 : struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(eth_dev);
159 : : struct ngbe_hwstrip *hwstrip = NGBE_DEV_HWSTRIP(eth_dev);
160 : 0 : struct rte_ether_addr *perm_addr =
161 : : (struct rte_ether_addr *)hw->mac.perm_addr;
162 : :
163 : 0 : PMD_INIT_FUNC_TRACE();
164 : :
165 : 0 : eth_dev->dev_ops = &ngbevf_eth_dev_ops;
166 : 0 : eth_dev->rx_descriptor_status = ngbe_dev_rx_descriptor_status;
167 : 0 : eth_dev->tx_descriptor_status = ngbe_dev_tx_descriptor_status;
168 : 0 : eth_dev->rx_pkt_burst = &ngbe_recv_pkts;
169 : 0 : eth_dev->tx_pkt_burst = &ngbe_xmit_pkts;
170 : :
171 : : /* for secondary processes, we don't initialise any further as primary
172 : : * has already done this work. Only check we don't need a different
173 : : * RX function
174 : : */
175 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
176 : : struct ngbe_tx_queue *txq;
177 : 0 : uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
178 : : /* TX queue function in primary, set by last queue initialized
179 : : * Tx queue may not initialized by primary process
180 : : */
181 [ # # ]: 0 : if (eth_dev->data->tx_queues) {
182 : 0 : txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
183 : 0 : ngbe_set_tx_function(eth_dev, txq);
184 : : } else {
185 : : /* Use default TX function if we get here */
186 : 0 : PMD_INIT_LOG(NOTICE,
187 : : "No TX queues configured yet. Using default TX function.");
188 : : }
189 : :
190 : 0 : ngbe_set_rx_function(eth_dev);
191 : :
192 : 0 : return 0;
193 : : }
194 : :
195 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
196 : :
197 : 0 : hw->device_id = pci_dev->id.device_id;
198 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
199 : 0 : hw->sub_system_id = pci_dev->id.subsystem_device_id;
200 : 0 : ngbe_map_device_id(hw);
201 : 0 : hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
202 : :
203 : : /* initialize the vfta */
204 : : memset(shadow_vfta, 0, sizeof(*shadow_vfta));
205 : :
206 : : /* initialize the hw strip bitmap*/
207 : : memset(hwstrip, 0, sizeof(*hwstrip));
208 : :
209 : : /* Initialize the shared code (base driver) */
210 : 0 : err = ngbe_init_shared_code(hw);
211 [ # # ]: 0 : if (err != 0) {
212 : 0 : PMD_INIT_LOG(ERR,
213 : : "Shared code init failed for ngbevf: %d", err);
214 : 0 : return -EIO;
215 : : }
216 : :
217 : : /* init_mailbox_params */
218 : 0 : hw->mbx.init_params(hw);
219 : :
220 : : /* Reset the hw statistics */
221 : : ngbevf_dev_stats_reset(eth_dev);
222 : :
223 : : /* Disable the interrupts for VF */
224 : 0 : ngbevf_intr_disable(eth_dev);
225 : :
226 : 0 : hw->mac.num_rar_entries = 32; /* The MAX of the underlying PF */
227 : 0 : err = hw->mac.reset_hw(hw);
228 : :
229 : : /*
230 : : * The VF reset operation returns the NGBE_ERR_INVALID_MAC_ADDR when
231 : : * the underlying PF driver has not assigned a MAC address to the VF.
232 : : * In this case, assign a random MAC address.
233 : : */
234 [ # # ]: 0 : if (err != 0 && err != NGBE_ERR_INVALID_MAC_ADDR) {
235 : 0 : PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
236 : : /*
237 : : * This error code will be propagated to the app by
238 : : * rte_eth_dev_reset, so use a public error code rather than
239 : : * the internal-only NGBE_ERR_RESET_FAILED
240 : : */
241 : 0 : return -EAGAIN;
242 : : }
243 : :
244 : : /* negotiate mailbox API version to use with the PF. */
245 : 0 : ngbevf_negotiate_api(hw);
246 : :
247 : : /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
248 : 0 : ngbevf_get_queues(hw, &tcs, &tc);
249 : :
250 : : /* Allocate memory for storing MAC addresses */
251 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("ngbevf", RTE_ETHER_ADDR_LEN *
252 : 0 : hw->mac.num_rar_entries, 0);
253 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
254 : 0 : PMD_INIT_LOG(ERR,
255 : : "Failed to allocate %u bytes needed to store MAC addresses",
256 : : RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
257 : 0 : return -ENOMEM;
258 : : }
259 : :
260 : : /* Generate a random MAC address, if none was assigned by PF. */
261 [ # # ]: 0 : if (rte_is_zero_ether_addr(perm_addr)) {
262 : 0 : generate_random_mac_addr(perm_addr);
263 : 0 : err = ngbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
264 [ # # ]: 0 : if (err) {
265 : 0 : rte_free(eth_dev->data->mac_addrs);
266 : 0 : eth_dev->data->mac_addrs = NULL;
267 : 0 : return err;
268 : : }
269 : 0 : PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
270 : 0 : PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
271 : : "%02x:%02x:%02x:%02x:%02x:%02x",
272 : : perm_addr->addr_bytes[0],
273 : : perm_addr->addr_bytes[1],
274 : : perm_addr->addr_bytes[2],
275 : : perm_addr->addr_bytes[3],
276 : : perm_addr->addr_bytes[4],
277 : : perm_addr->addr_bytes[5]);
278 : : }
279 : :
280 : : /* Copy the permanent MAC address */
281 : 0 : rte_ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
282 : :
283 : : /* reset the hardware with the new settings */
284 : 0 : err = hw->mac.start_hw(hw);
285 [ # # ]: 0 : if (err) {
286 : 0 : PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
287 : 0 : return -EIO;
288 : : }
289 : :
290 : : /* enter promiscuous mode */
291 : : ngbevf_dev_promiscuous_enable(eth_dev);
292 : :
293 : 0 : rte_intr_callback_register(intr_handle,
294 : : ngbevf_dev_interrupt_handler, eth_dev);
295 : 0 : rte_intr_enable(intr_handle);
296 : 0 : ngbevf_intr_enable(eth_dev);
297 : :
298 : 0 : PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
299 : : eth_dev->data->port_id, pci_dev->id.vendor_id,
300 : : pci_dev->id.device_id, "ngbe_mac_sp_vf");
301 : :
302 : 0 : return 0;
303 : : }
304 : :
305 : : /* Virtual Function device uninit */
306 : : static int
307 : 0 : eth_ngbevf_dev_uninit(struct rte_eth_dev *eth_dev)
308 : : {
309 : 0 : PMD_INIT_FUNC_TRACE();
310 : :
311 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
312 : : return 0;
313 : :
314 : 0 : ngbevf_dev_close(eth_dev);
315 : :
316 : 0 : return 0;
317 : : }
318 : :
319 : 0 : static int eth_ngbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
320 : : struct rte_pci_device *pci_dev)
321 : : {
322 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
323 : : sizeof(struct ngbe_adapter), eth_ngbevf_dev_init);
324 : : }
325 : :
326 : 0 : static int eth_ngbevf_pci_remove(struct rte_pci_device *pci_dev)
327 : : {
328 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_ngbevf_dev_uninit);
329 : : }
330 : :
331 : : /*
332 : : * virtual function driver struct
333 : : */
334 : : static struct rte_pci_driver rte_ngbevf_pmd = {
335 : : .id_table = pci_id_ngbevf_map,
336 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
337 : : .probe = eth_ngbevf_pci_probe,
338 : : .remove = eth_ngbevf_pci_remove,
339 : : };
340 : :
341 : 0 : static int ngbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
342 : : struct rte_eth_xstat_name *xstats_names, unsigned int limit)
343 : : {
344 : : unsigned int i;
345 : :
346 [ # # ]: 0 : if (limit < NGBEVF_NB_XSTATS && xstats_names != NULL)
347 : : return -ENOMEM;
348 : :
349 [ # # ]: 0 : if (xstats_names != NULL)
350 [ # # ]: 0 : for (i = 0; i < NGBEVF_NB_XSTATS; i++)
351 : 0 : snprintf(xstats_names[i].name,
352 : : sizeof(xstats_names[i].name),
353 : : "%s", rte_ngbevf_stats_strings[i].name);
354 : : return NGBEVF_NB_XSTATS;
355 : : }
356 : :
357 : : static void
358 : 0 : ngbevf_update_stats(struct rte_eth_dev *dev)
359 : : {
360 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
361 : : struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
362 : : NGBE_DEV_STATS(dev);
363 : :
364 : : /* Good Rx packet, include VF loopback */
365 [ # # ]: 0 : NGBE_UPDCNT32(NGBE_QPRXPKT(0),
366 : : hw_stats->last_vfgprc, hw_stats->vfgprc);
367 : :
368 : : /* Good Rx octets, include VF loopback */
369 [ # # ]: 0 : NGBE_UPDCNT36(NGBE_QPRXOCTL(0),
370 : : hw_stats->last_vfgorc, hw_stats->vfgorc);
371 : :
372 : : /* Rx Multicst Packet */
373 [ # # ]: 0 : NGBE_UPDCNT32(NGBE_QPRXMPKT(0),
374 : : hw_stats->last_vfmprc, hw_stats->vfmprc);
375 : :
376 : : /* Rx Broadcast Packet */
377 [ # # ]: 0 : NGBE_UPDCNT32(NGBE_QPRXBPKT(0),
378 : : hw_stats->last_vfbprc, hw_stats->vfbprc);
379 : :
380 : 0 : hw->rx_loaded = 0;
381 : :
382 : : /* Good Tx packet, include VF loopback */
383 [ # # ]: 0 : NGBE_UPDCNT32(NGBE_QPTXPKT(0),
384 : : hw_stats->last_vfgptc, hw_stats->vfgptc);
385 : :
386 : : /* Good Tx octets, include VF loopback */
387 [ # # ]: 0 : NGBE_UPDCNT36(NGBE_QPTXOCTL(0),
388 : : hw_stats->last_vfgotc, hw_stats->vfgotc);
389 : :
390 : : /* Tx Multicst Packet */
391 [ # # ]: 0 : NGBE_UPDCNT32(NGBE_QPTXMPKT(0),
392 : : hw_stats->last_vfmprc, hw_stats->vfmprc);
393 : :
394 : : /* Tx Broadcast Packet */
395 [ # # ]: 0 : NGBE_UPDCNT32(NGBE_QPTXBPKT(0),
396 : : hw_stats->last_vfbptc, hw_stats->vfbptc);
397 : :
398 : 0 : hw->offset_loaded = 0;
399 : 0 : }
400 : :
401 : : static int
402 : 0 : ngbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
403 : : unsigned int n)
404 : : {
405 : : struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
406 : 0 : NGBE_DEV_STATS(dev);
407 : : unsigned int i;
408 : :
409 [ # # ]: 0 : if (n < NGBEVF_NB_XSTATS)
410 : : return NGBEVF_NB_XSTATS;
411 : :
412 : 0 : ngbevf_update_stats(dev);
413 : :
414 [ # # ]: 0 : if (!xstats)
415 : : return 0;
416 : :
417 : : /* Extended stats */
418 [ # # ]: 0 : for (i = 0; i < NGBEVF_NB_XSTATS; i++) {
419 : 0 : xstats[i].id = i;
420 : 0 : xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
421 : : rte_ngbevf_stats_strings[i].offset);
422 : : }
423 : :
424 : : return NGBEVF_NB_XSTATS;
425 : : }
426 : :
427 : : static int
428 : 0 : ngbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
429 : : struct eth_queue_stats *qstats __rte_unused)
430 : : {
431 : : struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
432 : 0 : NGBE_DEV_STATS(dev);
433 : :
434 : 0 : ngbevf_update_stats(dev);
435 : :
436 [ # # ]: 0 : if (stats == NULL)
437 : : return -EINVAL;
438 : :
439 : 0 : stats->ipackets = hw_stats->vfgprc;
440 : 0 : stats->ibytes = hw_stats->vfgorc;
441 : 0 : stats->opackets = hw_stats->vfgptc;
442 : 0 : stats->obytes = hw_stats->vfgotc;
443 : 0 : return 0;
444 : : }
445 : :
446 : : static int
447 : 0 : ngbevf_dev_stats_reset(struct rte_eth_dev *dev)
448 : : {
449 : : struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
450 : 0 : NGBE_DEV_STATS(dev);
451 : :
452 : : /* Sync HW register to the last stats */
453 : : ngbevf_dev_stats_get(dev, NULL, NULL);
454 : :
455 : : /* reset HW current stats*/
456 : 0 : hw_stats->vfgprc = 0;
457 : 0 : hw_stats->vfgorc = 0;
458 : 0 : hw_stats->vfgptc = 0;
459 : 0 : hw_stats->vfgotc = 0;
460 : :
461 : 0 : return 0;
462 : : }
463 : :
464 : : static int
465 : 0 : ngbevf_dev_info_get(struct rte_eth_dev *dev,
466 : : struct rte_eth_dev_info *dev_info)
467 : : {
468 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
469 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
470 : :
471 : 0 : dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
472 : 0 : dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
473 : 0 : dev_info->min_rx_bufsize = 1024;
474 : 0 : dev_info->max_rx_pktlen = NGBE_FRAME_SIZE_MAX;
475 : 0 : dev_info->max_mac_addrs = hw->mac.num_rar_entries;
476 : 0 : dev_info->max_hash_mac_addrs = NGBE_VMDQ_NUM_UC_MAC;
477 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
478 : 0 : dev_info->rx_queue_offload_capa = ngbe_get_rx_queue_offloads(dev);
479 : 0 : dev_info->rx_offload_capa = (ngbe_get_rx_port_offloads(dev) |
480 : 0 : dev_info->rx_queue_offload_capa);
481 : 0 : dev_info->tx_queue_offload_capa = 0;
482 : 0 : dev_info->tx_offload_capa = ngbe_get_tx_port_offloads(dev);
483 : 0 : dev_info->hash_key_size = NGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
484 : 0 : dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
485 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
486 : : .rx_thresh = {
487 : : .pthresh = NGBE_DEFAULT_RX_PTHRESH,
488 : : .hthresh = NGBE_DEFAULT_RX_HTHRESH,
489 : : .wthresh = NGBE_DEFAULT_RX_WTHRESH,
490 : : },
491 : : .rx_free_thresh = NGBE_DEFAULT_RX_FREE_THRESH,
492 : : .rx_drop_en = 0,
493 : : .offloads = 0,
494 : : };
495 : :
496 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
497 : : .tx_thresh = {
498 : : .pthresh = NGBE_DEFAULT_TX_PTHRESH,
499 : : .hthresh = NGBE_DEFAULT_TX_HTHRESH,
500 : : .wthresh = NGBE_DEFAULT_TX_WTHRESH,
501 : : },
502 : : .tx_free_thresh = NGBE_DEFAULT_TX_FREE_THRESH,
503 : : .offloads = 0,
504 : : };
505 : :
506 : 0 : dev_info->rx_desc_lim = rx_desc_lim;
507 : 0 : dev_info->tx_desc_lim = tx_desc_lim;
508 : :
509 : 0 : return 0;
510 : : }
511 : :
512 : : static int
513 : 0 : ngbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
514 : : {
515 : 0 : return ngbe_dev_link_update_share(dev, wait_to_complete);
516 : : }
517 : :
518 : : static void
519 : 0 : ngbevf_intr_disable(struct rte_eth_dev *dev)
520 : : {
521 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
522 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
523 : :
524 : 0 : PMD_INIT_FUNC_TRACE();
525 : :
526 : : /* Clear interrupt mask to stop from interrupts being generated */
527 : : wr32(hw, NGBE_VFIMS, NGBE_VFIMS_MASK);
528 : :
529 : : ngbe_flush(hw);
530 : :
531 : : /* Clear mask value. */
532 : 0 : intr->mask_misc = NGBE_VFIMS_MASK;
533 : 0 : }
534 : :
535 : : static void
536 : 0 : ngbevf_intr_enable(struct rte_eth_dev *dev)
537 : : {
538 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
539 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
540 : :
541 : 0 : PMD_INIT_FUNC_TRACE();
542 : :
543 : : /* VF enable interrupt autoclean */
544 : : wr32(hw, NGBE_VFIMC, NGBE_VFIMC_MASK);
545 : :
546 : : ngbe_flush(hw);
547 : :
548 : 0 : intr->mask_misc = 0;
549 : 0 : }
550 : :
551 : : static int
552 : 0 : ngbevf_dev_configure(struct rte_eth_dev *dev)
553 : : {
554 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
555 : : struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
556 : :
557 : 0 : PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
558 : : dev->data->port_id);
559 : :
560 : : /*
561 : : * VF has no ability to enable/disable HW CRC
562 : : * Keep the persistent behavior the same as Host PF
563 : : */
564 : : #ifndef RTE_LIBRTE_NGBE_PF_DISABLE_STRIP_CRC
565 [ # # ]: 0 : if (conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
566 : 0 : PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
567 : 0 : conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
568 : : }
569 : : #else
570 : : if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
571 : : PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
572 : : conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
573 : : }
574 : : #endif
575 : :
576 : : /*
577 : : * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
578 : : * allocation or vector Rx preconditions we will reset it.
579 : : */
580 : 0 : adapter->rx_bulk_alloc_allowed = true;
581 : :
582 : 0 : return 0;
583 : : }
584 : :
585 : : static int
586 : 0 : ngbevf_dev_start(struct rte_eth_dev *dev)
587 : : {
588 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
589 : : uint32_t intr_vector = 0;
590 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
591 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
592 : :
593 : : int err, mask = 0;
594 : :
595 : 0 : PMD_INIT_FUNC_TRACE();
596 : :
597 : 0 : err = hw->mac.reset_hw(hw);
598 [ # # ]: 0 : if (err) {
599 : 0 : PMD_INIT_LOG(ERR, "Unable to reset vf hardware (%d)", err);
600 : 0 : return err;
601 : : }
602 : 0 : hw->mac.get_link_status = true;
603 : :
604 : : /* negotiate mailbox API version to use with the PF. */
605 : 0 : ngbevf_negotiate_api(hw);
606 : :
607 : 0 : ngbevf_dev_tx_init(dev);
608 : :
609 : : /* This can fail when allocating mbufs for descriptor rings */
610 : 0 : err = ngbevf_dev_rx_init(dev);
611 : :
612 : : /**
613 : : * In this case, reuses the MAC address assigned by VF
614 : : * initialization.
615 : : */
616 [ # # ]: 0 : if (err != 0 && err != NGBE_ERR_INVALID_MAC_ADDR) {
617 : 0 : PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
618 : 0 : ngbe_dev_clear_queues(dev);
619 : 0 : return err;
620 : : }
621 : :
622 : : /* Set vfta */
623 : 0 : ngbevf_set_vfta_all(dev, 1);
624 : :
625 : : /* Set HW strip */
626 : : mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
627 : : RTE_ETH_VLAN_EXTEND_MASK;
628 : 0 : err = ngbevf_vlan_offload_config(dev, mask);
629 [ # # ]: 0 : if (err) {
630 : 0 : PMD_INIT_LOG(ERR, "Unable to set VLAN offload (%d)", err);
631 : 0 : ngbe_dev_clear_queues(dev);
632 : 0 : return err;
633 : : }
634 : :
635 : 0 : ngbevf_dev_rxtx_start(dev);
636 : :
637 : : /* check and configure queue intr-vector mapping */
638 [ # # ]: 0 : if (rte_intr_cap_multiple(intr_handle) &&
639 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq) {
640 : : /* According to datasheet, only vector 0/1/2 can be used,
641 : : * now only one vector is used for Rx queue
642 : : */
643 : : intr_vector = 1;
644 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector))
645 : : return -1;
646 : : }
647 : :
648 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
649 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
650 : 0 : dev->data->nb_rx_queues)) {
651 : 0 : PMD_INIT_LOG(ERR,
652 : : "Failed to allocate %d rx_queues intr_vec",
653 : : dev->data->nb_rx_queues);
654 : 0 : return -ENOMEM;
655 : : }
656 : : }
657 : :
658 : 0 : ngbevf_configure_msix(dev);
659 : :
660 : : /* When a VF port is bound to VFIO-PCI, only miscellaneous interrupt
661 : : * is mapped to VFIO vector 0 in eth_ngbevf_dev_init( ).
662 : : * If previous VFIO interrupt mapping setting in eth_ngbevf_dev_init( )
663 : : * is not cleared, it will fail when following rte_intr_enable( ) tries
664 : : * to map Rx queue interrupt to other VFIO vectors.
665 : : * So clear uio/vfio intr/evevnfd first to avoid failure.
666 : : */
667 : 0 : rte_intr_disable(intr_handle);
668 : :
669 : 0 : rte_intr_enable(intr_handle);
670 : :
671 : : /* Re-enable interrupt for VF */
672 : 0 : ngbevf_intr_enable(dev);
673 : :
674 : : /*
675 : : * Update link status right before return, because it may
676 : : * start link configuration process in a separate thread.
677 : : */
678 : : ngbevf_dev_link_update(dev, 0);
679 : :
680 : 0 : hw->adapter_stopped = false;
681 : :
682 : 0 : return 0;
683 : : }
684 : :
685 : : static int
686 [ # # ]: 0 : ngbevf_dev_stop(struct rte_eth_dev *dev)
687 : : {
688 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
689 : : struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
690 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
691 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
692 : :
693 [ # # ]: 0 : if (hw->adapter_stopped)
694 : : return 0;
695 : :
696 : 0 : PMD_INIT_FUNC_TRACE();
697 : :
698 : 0 : ngbevf_intr_disable(dev);
699 : :
700 : 0 : hw->adapter_stopped = 1;
701 : 0 : hw->mac.stop_hw(hw);
702 : :
703 : : /*
704 : : * Clear what we set, but we still keep shadow_vfta to
705 : : * restore after device starts
706 : : */
707 : 0 : ngbevf_set_vfta_all(dev, 0);
708 : :
709 : : /* Clear stored conf */
710 : 0 : dev->data->scattered_rx = 0;
711 : :
712 : 0 : ngbe_dev_clear_queues(dev);
713 : :
714 : : /* Clean datapath event and queue/vec mapping */
715 : 0 : rte_intr_efd_disable(intr_handle);
716 : 0 : rte_intr_vec_list_free(intr_handle);
717 : :
718 : 0 : adapter->rss_reta_updated = 0;
719 : :
720 : 0 : return 0;
721 : : }
722 : :
723 : : static int
724 : 0 : ngbevf_dev_close(struct rte_eth_dev *dev)
725 : : {
726 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
727 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
728 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
729 : : int ret;
730 : :
731 : 0 : PMD_INIT_FUNC_TRACE();
732 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
733 : : return 0;
734 : :
735 : 0 : hw->mac.reset_hw(hw);
736 : :
737 : 0 : ret = ngbevf_dev_stop(dev);
738 : :
739 : 0 : ngbe_dev_free_queues(dev);
740 : :
741 : : /**
742 : : * Remove the VF MAC address ro ensure
743 : : * that the VF traffic goes to the PF
744 : : * after stop, close and detach of the VF
745 : : **/
746 : 0 : ngbevf_remove_mac_addr(dev, 0);
747 : :
748 : : /* Disable the interrupts for VF */
749 : 0 : ngbevf_intr_disable(dev);
750 : :
751 : 0 : rte_free(dev->data->mac_addrs);
752 : 0 : dev->data->mac_addrs = NULL;
753 : :
754 : 0 : rte_intr_disable(intr_handle);
755 : 0 : rte_intr_callback_unregister(intr_handle,
756 : : ngbevf_dev_interrupt_handler, dev);
757 : :
758 : 0 : return ret;
759 : : }
760 : :
761 : : /*
762 : : * Reset VF device
763 : : */
764 : : static int
765 : 0 : ngbevf_dev_reset(struct rte_eth_dev *dev)
766 : : {
767 : : int ret;
768 : :
769 : 0 : ret = eth_ngbevf_dev_uninit(dev);
770 [ # # ]: 0 : if (ret)
771 : : return ret;
772 : :
773 : 0 : ret = eth_ngbevf_dev_init(dev);
774 : :
775 : 0 : return ret;
776 : : }
777 : :
778 : 0 : static void ngbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
779 : : {
780 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
781 : : struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(dev);
782 : : int i = 0, j = 0, vfta = 0, mask = 1;
783 : :
784 [ # # ]: 0 : for (i = 0; i < NGBE_VFTA_SIZE; i++) {
785 : 0 : vfta = shadow_vfta->vfta[i];
786 [ # # ]: 0 : if (vfta) {
787 : : mask = 1;
788 [ # # ]: 0 : for (j = 0; j < 32; j++) {
789 [ # # ]: 0 : if (vfta & mask)
790 : 0 : hw->mac.set_vfta(hw, (i << 5) + j, 0,
791 : : on, false);
792 : 0 : mask <<= 1;
793 : : }
794 : : }
795 : : }
796 : 0 : }
797 : :
798 : : static int
799 : 0 : ngbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
800 : : {
801 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
802 : : struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(dev);
803 : : uint32_t vid_idx = 0;
804 : : uint32_t vid_bit = 0;
805 : : int ret = 0;
806 : :
807 : 0 : PMD_INIT_FUNC_TRACE();
808 : :
809 : : /* vind is not used in VF driver, set to 0, check ngbe_set_vfta_vf */
810 : 0 : ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
811 [ # # ]: 0 : if (ret) {
812 : 0 : PMD_INIT_LOG(ERR, "Unable to set VF vlan");
813 : 0 : return ret;
814 : : }
815 : 0 : vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
816 : 0 : vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
817 : :
818 : : /* Save what we set and restore it after device reset */
819 [ # # ]: 0 : if (on)
820 : 0 : shadow_vfta->vfta[vid_idx] |= vid_bit;
821 : : else
822 : 0 : shadow_vfta->vfta[vid_idx] &= ~vid_bit;
823 : :
824 : : return 0;
825 : : }
826 : :
827 : : static void
828 : 0 : ngbevf_vlan_strip_q_set(struct rte_eth_dev *dev, uint16_t queue, int on)
829 : : {
830 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
831 : : uint32_t ctrl;
832 : :
833 : 0 : PMD_INIT_FUNC_TRACE();
834 : :
835 [ # # ]: 0 : if (queue >= hw->mac.max_rx_queues)
836 : : return;
837 : :
838 : 0 : ctrl = rd32(hw, NGBE_RXCFG(queue));
839 [ # # ]: 0 : if (on)
840 : 0 : ctrl |= NGBE_RXCFG_VLAN;
841 : : else
842 : 0 : ctrl &= ~NGBE_RXCFG_VLAN;
843 : : wr32(hw, NGBE_RXCFG(queue), ctrl);
844 : :
845 : 0 : ngbe_vlan_hw_strip_bitmap_set(dev, queue, on);
846 : : }
847 : :
848 : : static void
849 [ # # ]: 0 : ngbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
850 : : {
851 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
852 : :
853 [ # # ]: 0 : if (!hw->adapter_stopped) {
854 : 0 : PMD_DRV_LOG(ERR, "Please stop port first");
855 : 0 : return;
856 : : }
857 : :
858 : 0 : ngbevf_vlan_strip_q_set(dev, queue, on);
859 : : }
860 : :
861 : : static int
862 : 0 : ngbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
863 : : {
864 : : struct ngbe_rx_queue *rxq;
865 : : uint16_t i;
866 : : int on = 0;
867 : :
868 : : /* VF function only support hw strip feature, others are not support */
869 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
870 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
871 : 0 : rxq = dev->data->rx_queues[i];
872 : 0 : on = !!(rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
873 : 0 : ngbevf_vlan_strip_q_set(dev, i, on);
874 : : }
875 : : }
876 : :
877 : 0 : return 0;
878 : : }
879 : :
880 : : static int
881 [ # # ]: 0 : ngbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
882 : : {
883 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
884 : :
885 [ # # # # ]: 0 : if (!hw->adapter_stopped && (mask & RTE_ETH_VLAN_STRIP_MASK)) {
886 : 0 : PMD_DRV_LOG(ERR, "Please stop port first");
887 : 0 : return -EPERM;
888 : : }
889 : :
890 : 0 : ngbe_config_vlan_strip_on_all_queues(dev, mask);
891 : :
892 : 0 : ngbevf_vlan_offload_config(dev, mask);
893 : :
894 : 0 : return 0;
895 : : }
896 : :
897 : : static int
898 : 0 : ngbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
899 : : {
900 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
901 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
902 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
903 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
904 : : uint32_t vec = NGBE_MISC_VEC_ID;
905 : :
906 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
907 : : vec = NGBE_RX_VEC_START;
908 : 0 : intr->mask_misc &= ~(1 << vec);
909 : : RTE_SET_USED(queue_id);
910 : 0 : wr32(hw, NGBE_VFIMC, ~intr->mask_misc);
911 : :
912 : 0 : rte_intr_enable(intr_handle);
913 : :
914 : 0 : return 0;
915 : : }
916 : :
917 : : static int
918 : 0 : ngbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
919 : : {
920 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
921 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
922 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
923 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
924 : : uint32_t vec = NGBE_MISC_VEC_ID;
925 : :
926 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
927 : : vec = NGBE_RX_VEC_START;
928 : 0 : intr->mask_misc |= (1 << vec);
929 : : RTE_SET_USED(queue_id);
930 : : wr32(hw, NGBE_VFIMS, intr->mask_misc);
931 : :
932 : 0 : return 0;
933 : : }
934 : :
935 : : static void
936 : 0 : ngbevf_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
937 : : uint8_t queue, uint8_t msix_vector)
938 : : {
939 : : uint32_t tmp, idx;
940 : :
941 [ # # ]: 0 : if (direction == -1) {
942 : : /* other causes */
943 : 0 : msix_vector |= NGBE_VFIVAR_VLD;
944 : : tmp = rd32(hw, NGBE_VFIVARMISC);
945 : 0 : tmp &= ~0xFF;
946 : 0 : tmp |= msix_vector;
947 : : wr32(hw, NGBE_VFIVARMISC, tmp);
948 : : } else {
949 : : /* rx or tx cause */
950 : : /* Workaround for ICR lost */
951 : 0 : idx = ((16 * (queue & 1)) + (8 * direction));
952 : 0 : tmp = rd32(hw, NGBE_VFIVAR(queue >> 1));
953 : 0 : tmp &= ~(0xFF << idx);
954 : 0 : tmp |= (msix_vector << idx);
955 : : wr32(hw, NGBE_VFIVAR(queue >> 1), tmp);
956 : : }
957 : 0 : }
958 : :
959 : : static void
960 : 0 : ngbevf_configure_msix(struct rte_eth_dev *dev)
961 : : {
962 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
963 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
964 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
965 : : uint32_t q_idx;
966 : : uint32_t vector_idx = NGBE_MISC_VEC_ID;
967 : : uint32_t base = NGBE_MISC_VEC_ID;
968 : :
969 : : /* Configure VF other cause ivar */
970 : : ngbevf_set_ivar_map(hw, -1, 1, vector_idx);
971 : :
972 : : /* won't configure msix register if no mapping is done
973 : : * between intr vector and event fd.
974 : : */
975 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle))
976 : : return;
977 : :
978 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
979 : : base = NGBE_RX_VEC_START;
980 : : vector_idx = NGBE_RX_VEC_START;
981 : : }
982 : :
983 : : /* Configure all RX queues of VF */
984 [ # # ]: 0 : for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
985 : : /* Force all queue use vector 0,
986 : : * as NGBE_VF_MAXMSIVECOTR = 1
987 : : */
988 : 0 : ngbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
989 : 0 : rte_intr_vec_list_index_set(intr_handle, q_idx,
990 : : vector_idx);
991 : 0 : if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
992 [ # # ]: 0 : - 1)
993 : 0 : vector_idx++;
994 : : }
995 : :
996 : : /* As RX queue setting above show, all queues use the vector 0.
997 : : * Set only the ITR value of NGBE_MISC_VEC_ID.
998 : : */
999 : : wr32(hw, NGBE_ITR(NGBE_MISC_VEC_ID),
1000 : : NGBE_ITR_IVAL(NGBE_QUEUE_ITR_INTERVAL_DEFAULT)
1001 : : | NGBE_ITR_WRDSA);
1002 : : }
1003 : :
1004 : : static int
1005 [ # # ]: 0 : ngbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1006 : : __rte_unused uint32_t index,
1007 : : __rte_unused uint32_t pool)
1008 : : {
1009 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1010 : : int err;
1011 : :
1012 : : /*
1013 : : * On a VF, adding again the same MAC addr is not an idempotent
1014 : : * operation. Trap this case to avoid exhausting the [very limited]
1015 : : * set of PF resources used to store VF MAC addresses.
1016 : : */
1017 [ # # ]: 0 : if (memcmp(hw->mac.perm_addr, mac_addr,
1018 : : sizeof(struct rte_ether_addr)) == 0)
1019 : : return -1;
1020 : 0 : err = ngbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1021 [ # # ]: 0 : if (err != 0)
1022 : 0 : PMD_DRV_LOG(ERR, "Unable to add MAC address "
1023 : : "%02x:%02x:%02x:%02x:%02x:%02x - err=%d",
1024 : : mac_addr->addr_bytes[0],
1025 : : mac_addr->addr_bytes[1],
1026 : : mac_addr->addr_bytes[2],
1027 : : mac_addr->addr_bytes[3],
1028 : : mac_addr->addr_bytes[4],
1029 : : mac_addr->addr_bytes[5],
1030 : : err);
1031 : : return err;
1032 : : }
1033 : :
1034 : : static void
1035 : 0 : ngbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
1036 : : {
1037 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1038 : 0 : struct rte_ether_addr *perm_addr =
1039 : : (struct rte_ether_addr *)hw->mac.perm_addr;
1040 : : struct rte_ether_addr *mac_addr;
1041 : : uint32_t i;
1042 : : int err;
1043 : :
1044 : : /*
1045 : : * The NGBE_VF_SET_MACVLAN command of the ngbe-pf driver does
1046 : : * not support the deletion of a given MAC address.
1047 : : * Instead, it imposes to delete all MAC addresses, then to add again
1048 : : * all MAC addresses with the exception of the one to be deleted.
1049 : : */
1050 : 0 : (void)ngbevf_set_uc_addr_vf(hw, 0, NULL);
1051 : :
1052 : : /*
1053 : : * Add again all MAC addresses, with the exception of the deleted one
1054 : : * and of the permanent MAC address.
1055 : : */
1056 : 0 : for (i = 0, mac_addr = dev->data->mac_addrs;
1057 [ # # ]: 0 : i < hw->mac.num_rar_entries; i++, mac_addr++) {
1058 : : /* Skip the deleted MAC address */
1059 [ # # ]: 0 : if (i == index)
1060 : 0 : continue;
1061 : : /* Skip NULL MAC addresses */
1062 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac_addr))
1063 : 0 : continue;
1064 : : /* Skip the permanent MAC address */
1065 [ # # ]: 0 : if (memcmp(perm_addr, mac_addr,
1066 : : sizeof(struct rte_ether_addr)) == 0)
1067 : 0 : continue;
1068 : 0 : err = ngbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1069 [ # # ]: 0 : if (err != 0)
1070 : 0 : PMD_DRV_LOG(ERR,
1071 : : "Adding again MAC address "
1072 : : "%02x:%02x:%02x:%02x:%02x:%02x failed "
1073 : : "err=%d",
1074 : : mac_addr->addr_bytes[0],
1075 : : mac_addr->addr_bytes[1],
1076 : : mac_addr->addr_bytes[2],
1077 : : mac_addr->addr_bytes[3],
1078 : : mac_addr->addr_bytes[4],
1079 : : mac_addr->addr_bytes[5],
1080 : : err);
1081 : : }
1082 : 0 : }
1083 : :
1084 : : static int
1085 : 0 : ngbevf_set_default_mac_addr(struct rte_eth_dev *dev,
1086 : : struct rte_ether_addr *addr)
1087 : : {
1088 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1089 : :
1090 : 0 : hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
1091 : :
1092 : 0 : return 0;
1093 : : }
1094 : :
1095 : : static int
1096 : 0 : ngbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1097 : : {
1098 : : struct ngbe_hw *hw;
1099 : 0 : uint32_t max_frame = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1100 [ # # ]: 0 : struct rte_eth_dev_data *dev_data = dev->data;
1101 : :
1102 : : hw = ngbe_dev_hw(dev);
1103 : :
1104 : 0 : if (mtu < RTE_ETHER_MIN_MTU ||
1105 [ # # ]: 0 : max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
1106 : : return -EINVAL;
1107 : :
1108 : : /* If device is started, refuse mtu that requires the support of
1109 : : * scattered packets when this feature has not been enabled before.
1110 : : */
1111 [ # # ]: 0 : if (dev_data->dev_started && !dev_data->scattered_rx &&
1112 : 0 : (max_frame + 2 * RTE_VLAN_HLEN >
1113 [ # # ]: 0 : dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
1114 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
1115 : 0 : return -EINVAL;
1116 : : }
1117 : :
1118 : : /*
1119 : : * When supported by the underlying PF driver, use the NGBE_VF_SET_MTU
1120 : : * request of the version 2.0 of the mailbox API.
1121 : : * For now, use the NGBE_VF_SET_LPE request of the version 1.0
1122 : : * of the mailbox API.
1123 : : */
1124 [ # # ]: 0 : if (ngbevf_rlpml_set_vf(hw, max_frame))
1125 : 0 : return -EINVAL;
1126 : :
1127 : : return 0;
1128 : : }
1129 : :
1130 : : static int
1131 : : ngbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
1132 : : {
1133 : : int count = 0;
1134 : : int g_ind = 0;
1135 : : const struct reg_info *reg_group;
1136 : :
1137 [ # # # # ]: 0 : while ((reg_group = ngbevf_regs[g_ind++]))
1138 : 0 : count += ngbe_regs_group_count(reg_group);
1139 : :
1140 : : return count;
1141 : : }
1142 : :
1143 : : static int
1144 [ # # ]: 0 : ngbevf_get_regs(struct rte_eth_dev *dev,
1145 : : struct rte_dev_reg_info *regs)
1146 : : {
1147 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1148 : 0 : uint32_t *data = regs->data;
1149 : : int g_ind = 0;
1150 : : int count = 0;
1151 : : const struct reg_info *reg_group;
1152 : :
1153 [ # # ]: 0 : if (data == NULL) {
1154 : 0 : regs->length = ngbevf_get_reg_length(dev);
1155 : 0 : regs->width = sizeof(uint32_t);
1156 : 0 : return 0;
1157 : : }
1158 : :
1159 : : /* Support only full register dump */
1160 [ # # ]: 0 : if (regs->length == 0 ||
1161 [ # # ]: 0 : regs->length == (uint32_t)ngbevf_get_reg_length(dev)) {
1162 : 0 : regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
1163 : 0 : hw->device_id;
1164 [ # # ]: 0 : while ((reg_group = ngbevf_regs[g_ind++]))
1165 : 0 : count += ngbe_read_regs_group(dev, &data[count],
1166 : : reg_group);
1167 : : return 0;
1168 : : }
1169 : :
1170 : : return -ENOTSUP;
1171 : : }
1172 : :
1173 : : static int
1174 : 0 : ngbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1175 : : {
1176 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1177 : : int ret;
1178 : :
1179 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, NGBEVF_XCAST_MODE_PROMISC)) {
1180 : : case 0:
1181 : : ret = 0;
1182 : : break;
1183 : 0 : case NGBE_ERR_FEATURE_NOT_SUPPORTED:
1184 : : ret = -ENOTSUP;
1185 : 0 : break;
1186 : 0 : default:
1187 : : ret = -EAGAIN;
1188 : 0 : break;
1189 : : }
1190 : :
1191 : 0 : return ret;
1192 : : }
1193 : :
1194 : : static int
1195 [ # # ]: 0 : ngbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1196 : : {
1197 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1198 : : int mode = NGBEVF_XCAST_MODE_NONE;
1199 : : int ret;
1200 : :
1201 [ # # ]: 0 : if (dev->data->all_multicast)
1202 : : mode = NGBEVF_XCAST_MODE_ALLMULTI;
1203 : :
1204 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, mode)) {
1205 : : case 0:
1206 : : ret = 0;
1207 : : break;
1208 : 0 : case NGBE_ERR_FEATURE_NOT_SUPPORTED:
1209 : : ret = -ENOTSUP;
1210 : 0 : break;
1211 : 0 : default:
1212 : : ret = -EAGAIN;
1213 : 0 : break;
1214 : : }
1215 : :
1216 : 0 : return ret;
1217 : : }
1218 : :
1219 : : static int
1220 [ # # ]: 0 : ngbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1221 : : {
1222 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1223 : : int ret;
1224 : :
1225 [ # # ]: 0 : if (dev->data->promiscuous)
1226 : : return 0;
1227 : :
1228 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, NGBEVF_XCAST_MODE_ALLMULTI)) {
1229 : : case 0:
1230 : : ret = 0;
1231 : : break;
1232 : 0 : case NGBE_ERR_FEATURE_NOT_SUPPORTED:
1233 : : ret = -ENOTSUP;
1234 : 0 : break;
1235 : 0 : default:
1236 : : ret = -EAGAIN;
1237 : 0 : break;
1238 : : }
1239 : :
1240 : : return ret;
1241 : : }
1242 : :
1243 : : static int
1244 [ # # ]: 0 : ngbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1245 : : {
1246 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1247 : : int ret;
1248 : :
1249 [ # # ]: 0 : if (dev->data->promiscuous)
1250 : : return 0;
1251 : :
1252 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, NGBEVF_XCAST_MODE_MULTI)) {
1253 : : case 0:
1254 : : ret = 0;
1255 : : break;
1256 : 0 : case NGBE_ERR_FEATURE_NOT_SUPPORTED:
1257 : : ret = -ENOTSUP;
1258 : 0 : break;
1259 : 0 : default:
1260 : : ret = -EAGAIN;
1261 : 0 : break;
1262 : : }
1263 : :
1264 : : return ret;
1265 : : }
1266 : :
1267 : 0 : static void ngbevf_mbx_process(struct rte_eth_dev *dev)
1268 : : {
1269 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1270 : 0 : u32 in_msg = 0;
1271 : :
1272 : : /* peek the message first */
1273 : 0 : in_msg = rd32(hw, NGBE_VFMBX);
1274 : :
1275 : : /* PF reset VF event */
1276 [ # # ]: 0 : if (in_msg == NGBE_PF_CONTROL_MSG) {
1277 : : /* dummy mbx read to ack pf */
1278 [ # # ]: 0 : if (ngbe_read_mbx(hw, &in_msg, 1, 0))
1279 : 0 : return;
1280 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
1281 : : NULL);
1282 : : }
1283 : : }
1284 : :
1285 : : static int
1286 : 0 : ngbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
1287 : : {
1288 : : uint32_t eicr;
1289 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1290 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1291 : :
1292 : 0 : ngbevf_intr_disable(dev);
1293 : :
1294 : : /* read-on-clear nic registers here */
1295 : : eicr = rd32(hw, NGBE_VFICR);
1296 : : intr->flags = 0;
1297 : :
1298 : : /* only one misc vector supported - mailbox */
1299 : : eicr &= NGBE_VFICR_MASK;
1300 : : /* Workaround for ICR lost */
1301 : 0 : intr->flags |= NGBE_FLAG_MAILBOX;
1302 : :
1303 : : /* To avoid compiler warnings set eicr to used. */
1304 : : RTE_SET_USED(eicr);
1305 : :
1306 : 0 : return 0;
1307 : : }
1308 : :
1309 : : static int
1310 [ # # ]: 0 : ngbevf_dev_interrupt_action(struct rte_eth_dev *dev)
1311 : : {
1312 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1313 : :
1314 [ # # ]: 0 : if (intr->flags & NGBE_FLAG_MAILBOX) {
1315 : 0 : ngbevf_mbx_process(dev);
1316 : 0 : intr->flags &= ~NGBE_FLAG_MAILBOX;
1317 : : }
1318 : :
1319 : 0 : ngbevf_intr_enable(dev);
1320 : :
1321 : 0 : return 0;
1322 : : }
1323 : :
1324 : : static void
1325 : 0 : ngbevf_dev_interrupt_handler(void *param)
1326 : : {
1327 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1328 : :
1329 : 0 : ngbevf_dev_interrupt_get_status(dev);
1330 : 0 : ngbevf_dev_interrupt_action(dev);
1331 : 0 : }
1332 : :
1333 : : /*
1334 : : * dev_ops for virtual function, bare necessities for basic vf
1335 : : * operation have been implemented
1336 : : */
1337 : : static const struct eth_dev_ops ngbevf_eth_dev_ops = {
1338 : : .dev_configure = ngbevf_dev_configure,
1339 : : .dev_start = ngbevf_dev_start,
1340 : : .dev_stop = ngbevf_dev_stop,
1341 : : .link_update = ngbevf_dev_link_update,
1342 : : .stats_get = ngbevf_dev_stats_get,
1343 : : .xstats_get = ngbevf_dev_xstats_get,
1344 : : .stats_reset = ngbevf_dev_stats_reset,
1345 : : .xstats_reset = ngbevf_dev_stats_reset,
1346 : : .xstats_get_names = ngbevf_dev_xstats_get_names,
1347 : : .dev_close = ngbevf_dev_close,
1348 : : .dev_reset = ngbevf_dev_reset,
1349 : : .promiscuous_enable = ngbevf_dev_promiscuous_enable,
1350 : : .promiscuous_disable = ngbevf_dev_promiscuous_disable,
1351 : : .allmulticast_enable = ngbevf_dev_allmulticast_enable,
1352 : : .allmulticast_disable = ngbevf_dev_allmulticast_disable,
1353 : : .dev_infos_get = ngbevf_dev_info_get,
1354 : : .dev_supported_ptypes_get = ngbe_dev_supported_ptypes_get,
1355 : : .mtu_set = ngbevf_dev_set_mtu,
1356 : : .vlan_filter_set = ngbevf_vlan_filter_set,
1357 : : .vlan_strip_queue_set = ngbevf_vlan_strip_queue_set,
1358 : : .vlan_offload_set = ngbevf_vlan_offload_set,
1359 : : .rx_queue_setup = ngbe_dev_rx_queue_setup,
1360 : : .rx_queue_release = ngbe_dev_rx_queue_release,
1361 : : .tx_queue_setup = ngbe_dev_tx_queue_setup,
1362 : : .tx_queue_release = ngbe_dev_tx_queue_release,
1363 : : .rx_queue_intr_enable = ngbevf_dev_rx_queue_intr_enable,
1364 : : .rx_queue_intr_disable = ngbevf_dev_rx_queue_intr_disable,
1365 : : .mac_addr_add = ngbevf_add_mac_addr,
1366 : : .mac_addr_remove = ngbevf_remove_mac_addr,
1367 : : .set_mc_addr_list = ngbe_dev_set_mc_addr_list,
1368 : : .rxq_info_get = ngbe_rxq_info_get,
1369 : : .txq_info_get = ngbe_txq_info_get,
1370 : : .mac_addr_set = ngbevf_set_default_mac_addr,
1371 : : .get_reg = ngbevf_get_regs,
1372 : : .tx_done_cleanup = ngbe_dev_tx_done_cleanup,
1373 : : };
1374 : :
1375 : 306 : RTE_PMD_REGISTER_PCI(net_ngbe_vf, rte_ngbevf_pmd);
1376 : : RTE_PMD_REGISTER_PCI_TABLE(net_ngbe_vf, pci_id_ngbevf_map);
1377 : : RTE_PMD_REGISTER_KMOD_DEP(net_ngbe_vf, "* igb_uio | vfio-pci");
|