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_ETH_DEV_TO_PCI(eth_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 : : {
430 : : struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
431 : 0 : NGBE_DEV_STATS(dev);
432 : :
433 : 0 : ngbevf_update_stats(dev);
434 : :
435 [ # # ]: 0 : if (stats == NULL)
436 : : return -EINVAL;
437 : :
438 : 0 : stats->ipackets = hw_stats->vfgprc;
439 : 0 : stats->ibytes = hw_stats->vfgorc;
440 : 0 : stats->opackets = hw_stats->vfgptc;
441 : 0 : stats->obytes = hw_stats->vfgotc;
442 : 0 : return 0;
443 : : }
444 : :
445 : : static int
446 : 0 : ngbevf_dev_stats_reset(struct rte_eth_dev *dev)
447 : : {
448 : : struct ngbevf_hw_stats *hw_stats = (struct ngbevf_hw_stats *)
449 : 0 : NGBE_DEV_STATS(dev);
450 : :
451 : : /* Sync HW register to the last stats */
452 : : ngbevf_dev_stats_get(dev, NULL);
453 : :
454 : : /* reset HW current stats*/
455 : 0 : hw_stats->vfgprc = 0;
456 : 0 : hw_stats->vfgorc = 0;
457 : 0 : hw_stats->vfgptc = 0;
458 : 0 : hw_stats->vfgotc = 0;
459 : :
460 : 0 : return 0;
461 : : }
462 : :
463 : : static int
464 : 0 : ngbevf_dev_info_get(struct rte_eth_dev *dev,
465 : : struct rte_eth_dev_info *dev_info)
466 : : {
467 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
468 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
469 : :
470 : 0 : dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
471 : 0 : dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
472 : 0 : dev_info->min_rx_bufsize = 1024;
473 : 0 : dev_info->max_rx_pktlen = NGBE_FRAME_SIZE_MAX;
474 : 0 : dev_info->max_mac_addrs = hw->mac.num_rar_entries;
475 : 0 : dev_info->max_hash_mac_addrs = NGBE_VMDQ_NUM_UC_MAC;
476 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
477 : 0 : dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
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_ETH_DEV_TO_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_ETH_DEV_TO_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_ETH_DEV_TO_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 : 0 : dev->rx_pkt_burst = NULL;
749 : 0 : dev->tx_pkt_burst = NULL;
750 : :
751 : : /* Disable the interrupts for VF */
752 : 0 : ngbevf_intr_disable(dev);
753 : :
754 : 0 : rte_free(dev->data->mac_addrs);
755 : 0 : dev->data->mac_addrs = NULL;
756 : :
757 : 0 : rte_intr_disable(intr_handle);
758 : 0 : rte_intr_callback_unregister(intr_handle,
759 : : ngbevf_dev_interrupt_handler, dev);
760 : :
761 : 0 : return ret;
762 : : }
763 : :
764 : : /*
765 : : * Reset VF device
766 : : */
767 : : static int
768 : 0 : ngbevf_dev_reset(struct rte_eth_dev *dev)
769 : : {
770 : : int ret;
771 : :
772 : 0 : ret = eth_ngbevf_dev_uninit(dev);
773 [ # # ]: 0 : if (ret)
774 : : return ret;
775 : :
776 : 0 : ret = eth_ngbevf_dev_init(dev);
777 : :
778 : 0 : return ret;
779 : : }
780 : :
781 : 0 : static void ngbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
782 : : {
783 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
784 : : struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(dev);
785 : : int i = 0, j = 0, vfta = 0, mask = 1;
786 : :
787 [ # # ]: 0 : for (i = 0; i < NGBE_VFTA_SIZE; i++) {
788 : 0 : vfta = shadow_vfta->vfta[i];
789 [ # # ]: 0 : if (vfta) {
790 : : mask = 1;
791 [ # # ]: 0 : for (j = 0; j < 32; j++) {
792 [ # # ]: 0 : if (vfta & mask)
793 : 0 : hw->mac.set_vfta(hw, (i << 5) + j, 0,
794 : : on, false);
795 : 0 : mask <<= 1;
796 : : }
797 : : }
798 : : }
799 : 0 : }
800 : :
801 : : static int
802 : 0 : ngbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
803 : : {
804 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
805 : : struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(dev);
806 : : uint32_t vid_idx = 0;
807 : : uint32_t vid_bit = 0;
808 : : int ret = 0;
809 : :
810 : 0 : PMD_INIT_FUNC_TRACE();
811 : :
812 : : /* vind is not used in VF driver, set to 0, check ngbe_set_vfta_vf */
813 : 0 : ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
814 [ # # ]: 0 : if (ret) {
815 : 0 : PMD_INIT_LOG(ERR, "Unable to set VF vlan");
816 : 0 : return ret;
817 : : }
818 : 0 : vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
819 : 0 : vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
820 : :
821 : : /* Save what we set and restore it after device reset */
822 [ # # ]: 0 : if (on)
823 : 0 : shadow_vfta->vfta[vid_idx] |= vid_bit;
824 : : else
825 : 0 : shadow_vfta->vfta[vid_idx] &= ~vid_bit;
826 : :
827 : : return 0;
828 : : }
829 : :
830 : : static void
831 : 0 : ngbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
832 : : {
833 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
834 : : uint32_t ctrl;
835 : :
836 : 0 : PMD_INIT_FUNC_TRACE();
837 : :
838 [ # # ]: 0 : if (queue >= hw->mac.max_rx_queues)
839 : : return;
840 : :
841 : 0 : ctrl = rd32(hw, NGBE_RXCFG(queue));
842 [ # # ]: 0 : if (on)
843 : 0 : ctrl |= NGBE_RXCFG_VLAN;
844 : : else
845 : 0 : ctrl &= ~NGBE_RXCFG_VLAN;
846 : : wr32(hw, NGBE_RXCFG(queue), ctrl);
847 : :
848 : 0 : ngbe_vlan_hw_strip_bitmap_set(dev, queue, on);
849 : : }
850 : :
851 : : static int
852 : 0 : ngbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
853 : : {
854 : : struct ngbe_rx_queue *rxq;
855 : : uint16_t i;
856 : : int on = 0;
857 : :
858 : : /* VF function only support hw strip feature, others are not support */
859 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
860 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
861 : 0 : rxq = dev->data->rx_queues[i];
862 : 0 : on = !!(rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
863 : 0 : ngbevf_vlan_strip_queue_set(dev, i, on);
864 : : }
865 : : }
866 : :
867 : 0 : return 0;
868 : : }
869 : :
870 : : static int
871 : 0 : ngbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
872 : : {
873 : 0 : ngbe_config_vlan_strip_on_all_queues(dev, mask);
874 : :
875 : 0 : ngbevf_vlan_offload_config(dev, mask);
876 : :
877 : 0 : return 0;
878 : : }
879 : :
880 : : static int
881 : 0 : ngbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
882 : : {
883 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
884 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
885 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
886 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
887 : : uint32_t vec = NGBE_MISC_VEC_ID;
888 : :
889 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
890 : : vec = NGBE_RX_VEC_START;
891 : 0 : intr->mask_misc &= ~(1 << vec);
892 : : RTE_SET_USED(queue_id);
893 : 0 : wr32(hw, NGBE_VFIMC, ~intr->mask_misc);
894 : :
895 : 0 : rte_intr_enable(intr_handle);
896 : :
897 : 0 : return 0;
898 : : }
899 : :
900 : : static int
901 : 0 : ngbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
902 : : {
903 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
904 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
905 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
906 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
907 : : uint32_t vec = NGBE_MISC_VEC_ID;
908 : :
909 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle))
910 : : vec = NGBE_RX_VEC_START;
911 : 0 : intr->mask_misc |= (1 << vec);
912 : : RTE_SET_USED(queue_id);
913 : : wr32(hw, NGBE_VFIMS, intr->mask_misc);
914 : :
915 : 0 : return 0;
916 : : }
917 : :
918 : : static void
919 : 0 : ngbevf_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
920 : : uint8_t queue, uint8_t msix_vector)
921 : : {
922 : : uint32_t tmp, idx;
923 : :
924 [ # # ]: 0 : if (direction == -1) {
925 : : /* other causes */
926 : 0 : msix_vector |= NGBE_VFIVAR_VLD;
927 : : tmp = rd32(hw, NGBE_VFIVARMISC);
928 : 0 : tmp &= ~0xFF;
929 : 0 : tmp |= msix_vector;
930 : : wr32(hw, NGBE_VFIVARMISC, tmp);
931 : : } else {
932 : : /* rx or tx cause */
933 : : /* Workaround for ICR lost */
934 : 0 : idx = ((16 * (queue & 1)) + (8 * direction));
935 : 0 : tmp = rd32(hw, NGBE_VFIVAR(queue >> 1));
936 : 0 : tmp &= ~(0xFF << idx);
937 : 0 : tmp |= (msix_vector << idx);
938 : : wr32(hw, NGBE_VFIVAR(queue >> 1), tmp);
939 : : }
940 : 0 : }
941 : :
942 : : static void
943 : 0 : ngbevf_configure_msix(struct rte_eth_dev *dev)
944 : : {
945 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
946 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
947 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
948 : : uint32_t q_idx;
949 : : uint32_t vector_idx = NGBE_MISC_VEC_ID;
950 : : uint32_t base = NGBE_MISC_VEC_ID;
951 : :
952 : : /* Configure VF other cause ivar */
953 : : ngbevf_set_ivar_map(hw, -1, 1, vector_idx);
954 : :
955 : : /* won't configure msix register if no mapping is done
956 : : * between intr vector and event fd.
957 : : */
958 [ # # ]: 0 : if (!rte_intr_dp_is_en(intr_handle))
959 : : return;
960 : :
961 [ # # ]: 0 : if (rte_intr_allow_others(intr_handle)) {
962 : : base = NGBE_RX_VEC_START;
963 : : vector_idx = NGBE_RX_VEC_START;
964 : : }
965 : :
966 : : /* Configure all RX queues of VF */
967 [ # # ]: 0 : for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
968 : : /* Force all queue use vector 0,
969 : : * as NGBE_VF_MAXMSIVECOTR = 1
970 : : */
971 : 0 : ngbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
972 : 0 : rte_intr_vec_list_index_set(intr_handle, q_idx,
973 : : vector_idx);
974 : 0 : if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
975 [ # # ]: 0 : - 1)
976 : 0 : vector_idx++;
977 : : }
978 : :
979 : : /* As RX queue setting above show, all queues use the vector 0.
980 : : * Set only the ITR value of NGBE_MISC_VEC_ID.
981 : : */
982 : : wr32(hw, NGBE_ITR(NGBE_MISC_VEC_ID),
983 : : NGBE_ITR_IVAL(NGBE_QUEUE_ITR_INTERVAL_DEFAULT)
984 : : | NGBE_ITR_WRDSA);
985 : : }
986 : :
987 : : static int
988 [ # # ]: 0 : ngbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
989 : : __rte_unused uint32_t index,
990 : : __rte_unused uint32_t pool)
991 : : {
992 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
993 : : int err;
994 : :
995 : : /*
996 : : * On a VF, adding again the same MAC addr is not an idempotent
997 : : * operation. Trap this case to avoid exhausting the [very limited]
998 : : * set of PF resources used to store VF MAC addresses.
999 : : */
1000 [ # # ]: 0 : if (memcmp(hw->mac.perm_addr, mac_addr,
1001 : : sizeof(struct rte_ether_addr)) == 0)
1002 : : return -1;
1003 : 0 : err = ngbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1004 [ # # ]: 0 : if (err != 0)
1005 : 0 : PMD_DRV_LOG(ERR, "Unable to add MAC address "
1006 : : "%02x:%02x:%02x:%02x:%02x:%02x - err=%d",
1007 : : mac_addr->addr_bytes[0],
1008 : : mac_addr->addr_bytes[1],
1009 : : mac_addr->addr_bytes[2],
1010 : : mac_addr->addr_bytes[3],
1011 : : mac_addr->addr_bytes[4],
1012 : : mac_addr->addr_bytes[5],
1013 : : err);
1014 : : return err;
1015 : : }
1016 : :
1017 : : static void
1018 : 0 : ngbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
1019 : : {
1020 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1021 : 0 : struct rte_ether_addr *perm_addr =
1022 : : (struct rte_ether_addr *)hw->mac.perm_addr;
1023 : : struct rte_ether_addr *mac_addr;
1024 : : uint32_t i;
1025 : : int err;
1026 : :
1027 : : /*
1028 : : * The NGBE_VF_SET_MACVLAN command of the ngbe-pf driver does
1029 : : * not support the deletion of a given MAC address.
1030 : : * Instead, it imposes to delete all MAC addresses, then to add again
1031 : : * all MAC addresses with the exception of the one to be deleted.
1032 : : */
1033 : 0 : (void)ngbevf_set_uc_addr_vf(hw, 0, NULL);
1034 : :
1035 : : /*
1036 : : * Add again all MAC addresses, with the exception of the deleted one
1037 : : * and of the permanent MAC address.
1038 : : */
1039 : 0 : for (i = 0, mac_addr = dev->data->mac_addrs;
1040 [ # # ]: 0 : i < hw->mac.num_rar_entries; i++, mac_addr++) {
1041 : : /* Skip the deleted MAC address */
1042 [ # # ]: 0 : if (i == index)
1043 : 0 : continue;
1044 : : /* Skip NULL MAC addresses */
1045 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac_addr))
1046 : 0 : continue;
1047 : : /* Skip the permanent MAC address */
1048 [ # # ]: 0 : if (memcmp(perm_addr, mac_addr,
1049 : : sizeof(struct rte_ether_addr)) == 0)
1050 : 0 : continue;
1051 : 0 : err = ngbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1052 [ # # ]: 0 : if (err != 0)
1053 : 0 : PMD_DRV_LOG(ERR,
1054 : : "Adding again MAC address "
1055 : : "%02x:%02x:%02x:%02x:%02x:%02x failed "
1056 : : "err=%d",
1057 : : mac_addr->addr_bytes[0],
1058 : : mac_addr->addr_bytes[1],
1059 : : mac_addr->addr_bytes[2],
1060 : : mac_addr->addr_bytes[3],
1061 : : mac_addr->addr_bytes[4],
1062 : : mac_addr->addr_bytes[5],
1063 : : err);
1064 : : }
1065 : 0 : }
1066 : :
1067 : : static int
1068 : 0 : ngbevf_set_default_mac_addr(struct rte_eth_dev *dev,
1069 : : struct rte_ether_addr *addr)
1070 : : {
1071 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1072 : :
1073 : 0 : hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
1074 : :
1075 : 0 : return 0;
1076 : : }
1077 : :
1078 : : static int
1079 : 0 : ngbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1080 : : {
1081 : : struct ngbe_hw *hw;
1082 : 0 : uint32_t max_frame = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1083 [ # # ]: 0 : struct rte_eth_dev_data *dev_data = dev->data;
1084 : :
1085 : : hw = ngbe_dev_hw(dev);
1086 : :
1087 : 0 : if (mtu < RTE_ETHER_MIN_MTU ||
1088 [ # # ]: 0 : max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
1089 : : return -EINVAL;
1090 : :
1091 : : /* If device is started, refuse mtu that requires the support of
1092 : : * scattered packets when this feature has not been enabled before.
1093 : : */
1094 [ # # ]: 0 : if (dev_data->dev_started && !dev_data->scattered_rx &&
1095 : 0 : (max_frame + 2 * RTE_VLAN_HLEN >
1096 [ # # ]: 0 : dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
1097 : 0 : PMD_INIT_LOG(ERR, "Stop port first.");
1098 : 0 : return -EINVAL;
1099 : : }
1100 : :
1101 : : /*
1102 : : * When supported by the underlying PF driver, use the NGBE_VF_SET_MTU
1103 : : * request of the version 2.0 of the mailbox API.
1104 : : * For now, use the NGBE_VF_SET_LPE request of the version 1.0
1105 : : * of the mailbox API.
1106 : : */
1107 [ # # ]: 0 : if (ngbevf_rlpml_set_vf(hw, max_frame))
1108 : 0 : return -EINVAL;
1109 : :
1110 : : return 0;
1111 : : }
1112 : :
1113 : : static int
1114 : : ngbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
1115 : : {
1116 : : int count = 0;
1117 : : int g_ind = 0;
1118 : : const struct reg_info *reg_group;
1119 : :
1120 [ # # # # ]: 0 : while ((reg_group = ngbevf_regs[g_ind++]))
1121 : 0 : count += ngbe_regs_group_count(reg_group);
1122 : :
1123 : : return count;
1124 : : }
1125 : :
1126 : : static int
1127 [ # # ]: 0 : ngbevf_get_regs(struct rte_eth_dev *dev,
1128 : : struct rte_dev_reg_info *regs)
1129 : : {
1130 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1131 : 0 : uint32_t *data = regs->data;
1132 : : int g_ind = 0;
1133 : : int count = 0;
1134 : : const struct reg_info *reg_group;
1135 : :
1136 [ # # ]: 0 : if (data == NULL) {
1137 : 0 : regs->length = ngbevf_get_reg_length(dev);
1138 : 0 : regs->width = sizeof(uint32_t);
1139 : 0 : return 0;
1140 : : }
1141 : :
1142 : : /* Support only full register dump */
1143 [ # # ]: 0 : if (regs->length == 0 ||
1144 [ # # ]: 0 : regs->length == (uint32_t)ngbevf_get_reg_length(dev)) {
1145 : 0 : regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
1146 : 0 : hw->device_id;
1147 [ # # ]: 0 : while ((reg_group = ngbevf_regs[g_ind++]))
1148 : 0 : count += ngbe_read_regs_group(dev, &data[count],
1149 : : reg_group);
1150 : : return 0;
1151 : : }
1152 : :
1153 : : return -ENOTSUP;
1154 : : }
1155 : :
1156 : : static int
1157 : 0 : ngbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1158 : : {
1159 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1160 : : int ret;
1161 : :
1162 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, NGBEVF_XCAST_MODE_PROMISC)) {
1163 : : case 0:
1164 : : ret = 0;
1165 : : break;
1166 : 0 : case NGBE_ERR_FEATURE_NOT_SUPPORTED:
1167 : : ret = -ENOTSUP;
1168 : 0 : break;
1169 : 0 : default:
1170 : : ret = -EAGAIN;
1171 : 0 : break;
1172 : : }
1173 : :
1174 : 0 : return ret;
1175 : : }
1176 : :
1177 : : static int
1178 : 0 : ngbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1179 : : {
1180 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1181 : : int ret;
1182 : :
1183 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, NGBEVF_XCAST_MODE_NONE)) {
1184 : : case 0:
1185 : : ret = 0;
1186 : : break;
1187 : 0 : case NGBE_ERR_FEATURE_NOT_SUPPORTED:
1188 : : ret = -ENOTSUP;
1189 : 0 : break;
1190 : 0 : default:
1191 : : ret = -EAGAIN;
1192 : 0 : break;
1193 : : }
1194 : :
1195 : 0 : return ret;
1196 : : }
1197 : :
1198 : : static int
1199 [ # # ]: 0 : ngbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1200 : : {
1201 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1202 : : int ret;
1203 : :
1204 [ # # ]: 0 : if (dev->data->promiscuous == 1)
1205 : : return 0;
1206 : :
1207 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, NGBEVF_XCAST_MODE_ALLMULTI)) {
1208 : : case 0:
1209 : : ret = 0;
1210 : : break;
1211 : 0 : case NGBE_ERR_FEATURE_NOT_SUPPORTED:
1212 : : ret = -ENOTSUP;
1213 : 0 : break;
1214 : 0 : default:
1215 : : ret = -EAGAIN;
1216 : 0 : break;
1217 : : }
1218 : :
1219 : : return ret;
1220 : : }
1221 : :
1222 : : static int
1223 : 0 : ngbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1224 : : {
1225 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1226 : : int ret;
1227 : :
1228 [ # # # ]: 0 : switch (hw->mac.update_xcast_mode(hw, NGBEVF_XCAST_MODE_MULTI)) {
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 : 0 : return ret;
1241 : : }
1242 : :
1243 : 0 : static void ngbevf_mbx_process(struct rte_eth_dev *dev)
1244 : : {
1245 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1246 : 0 : u32 in_msg = 0;
1247 : :
1248 : : /* peek the message first */
1249 : 0 : in_msg = rd32(hw, NGBE_VFMBX);
1250 : :
1251 : : /* PF reset VF event */
1252 [ # # ]: 0 : if (in_msg == NGBE_PF_CONTROL_MSG) {
1253 : : /* dummy mbx read to ack pf */
1254 [ # # ]: 0 : if (ngbe_read_mbx(hw, &in_msg, 1, 0))
1255 : 0 : return;
1256 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
1257 : : NULL);
1258 : : }
1259 : : }
1260 : :
1261 : : static int
1262 : 0 : ngbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
1263 : : {
1264 : : uint32_t eicr;
1265 : : struct ngbe_hw *hw = ngbe_dev_hw(dev);
1266 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1267 : :
1268 : 0 : ngbevf_intr_disable(dev);
1269 : :
1270 : : /* read-on-clear nic registers here */
1271 : : eicr = rd32(hw, NGBE_VFICR);
1272 : : intr->flags = 0;
1273 : :
1274 : : /* only one misc vector supported - mailbox */
1275 : : eicr &= NGBE_VFICR_MASK;
1276 : : /* Workaround for ICR lost */
1277 : 0 : intr->flags |= NGBE_FLAG_MAILBOX;
1278 : :
1279 : : /* To avoid compiler warnings set eicr to used. */
1280 : : RTE_SET_USED(eicr);
1281 : :
1282 : 0 : return 0;
1283 : : }
1284 : :
1285 : : static int
1286 [ # # ]: 0 : ngbevf_dev_interrupt_action(struct rte_eth_dev *dev)
1287 : : {
1288 : : struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1289 : :
1290 [ # # ]: 0 : if (intr->flags & NGBE_FLAG_MAILBOX) {
1291 : 0 : ngbevf_mbx_process(dev);
1292 : 0 : intr->flags &= ~NGBE_FLAG_MAILBOX;
1293 : : }
1294 : :
1295 : 0 : ngbevf_intr_enable(dev);
1296 : :
1297 : 0 : return 0;
1298 : : }
1299 : :
1300 : : static void
1301 : 0 : ngbevf_dev_interrupt_handler(void *param)
1302 : : {
1303 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1304 : :
1305 : 0 : ngbevf_dev_interrupt_get_status(dev);
1306 : 0 : ngbevf_dev_interrupt_action(dev);
1307 : 0 : }
1308 : :
1309 : : /*
1310 : : * dev_ops for virtual function, bare necessities for basic vf
1311 : : * operation have been implemented
1312 : : */
1313 : : static const struct eth_dev_ops ngbevf_eth_dev_ops = {
1314 : : .dev_configure = ngbevf_dev_configure,
1315 : : .dev_start = ngbevf_dev_start,
1316 : : .dev_stop = ngbevf_dev_stop,
1317 : : .link_update = ngbevf_dev_link_update,
1318 : : .stats_get = ngbevf_dev_stats_get,
1319 : : .xstats_get = ngbevf_dev_xstats_get,
1320 : : .stats_reset = ngbevf_dev_stats_reset,
1321 : : .xstats_reset = ngbevf_dev_stats_reset,
1322 : : .xstats_get_names = ngbevf_dev_xstats_get_names,
1323 : : .dev_close = ngbevf_dev_close,
1324 : : .dev_reset = ngbevf_dev_reset,
1325 : : .promiscuous_enable = ngbevf_dev_promiscuous_enable,
1326 : : .promiscuous_disable = ngbevf_dev_promiscuous_disable,
1327 : : .allmulticast_enable = ngbevf_dev_allmulticast_enable,
1328 : : .allmulticast_disable = ngbevf_dev_allmulticast_disable,
1329 : : .dev_infos_get = ngbevf_dev_info_get,
1330 : : .dev_supported_ptypes_get = ngbe_dev_supported_ptypes_get,
1331 : : .mtu_set = ngbevf_dev_set_mtu,
1332 : : .vlan_filter_set = ngbevf_vlan_filter_set,
1333 : : .vlan_strip_queue_set = ngbevf_vlan_strip_queue_set,
1334 : : .vlan_offload_set = ngbevf_vlan_offload_set,
1335 : : .rx_queue_setup = ngbe_dev_rx_queue_setup,
1336 : : .rx_queue_release = ngbe_dev_rx_queue_release,
1337 : : .tx_queue_setup = ngbe_dev_tx_queue_setup,
1338 : : .tx_queue_release = ngbe_dev_tx_queue_release,
1339 : : .rx_queue_intr_enable = ngbevf_dev_rx_queue_intr_enable,
1340 : : .rx_queue_intr_disable = ngbevf_dev_rx_queue_intr_disable,
1341 : : .mac_addr_add = ngbevf_add_mac_addr,
1342 : : .mac_addr_remove = ngbevf_remove_mac_addr,
1343 : : .set_mc_addr_list = ngbe_dev_set_mc_addr_list,
1344 : : .rxq_info_get = ngbe_rxq_info_get,
1345 : : .txq_info_get = ngbe_txq_info_get,
1346 : : .mac_addr_set = ngbevf_set_default_mac_addr,
1347 : : .get_reg = ngbevf_get_regs,
1348 : : .tx_done_cleanup = ngbe_dev_tx_done_cleanup,
1349 : : };
1350 : :
1351 : 252 : RTE_PMD_REGISTER_PCI(net_ngbe_vf, rte_ngbevf_pmd);
1352 : : RTE_PMD_REGISTER_PCI_TABLE(net_ngbe_vf, pci_id_ngbevf_map);
1353 : : RTE_PMD_REGISTER_KMOD_DEP(net_ngbe_vf, "* igb_uio | vfio-pci");
|