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