net/txgbe: support VF get link status
[dpdk.git] / drivers / net / txgbe / txgbe_ethdev_vf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020
3  */
4
5 #include <sys/queue.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <rte_log.h>
11 #include <ethdev_pci.h>
12
13 #include "txgbe_logs.h"
14 #include "base/txgbe.h"
15 #include "txgbe_ethdev.h"
16 #include "txgbe_rxtx.h"
17
18 static int txgbevf_dev_info_get(struct rte_eth_dev *dev,
19                                  struct rte_eth_dev_info *dev_info);
20 static int txgbevf_dev_link_update(struct rte_eth_dev *dev,
21                                    int wait_to_complete);
22 static int txgbevf_dev_close(struct rte_eth_dev *dev);
23 static void txgbevf_intr_disable(struct rte_eth_dev *dev);
24 static void txgbevf_intr_enable(struct rte_eth_dev *dev);
25 static void txgbevf_configure_msix(struct rte_eth_dev *dev);
26 static void txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
27 static void txgbevf_dev_interrupt_handler(void *param);
28
29 /*
30  * The set of PCI devices this driver supports (for VF)
31  */
32 static const struct rte_pci_id pci_id_txgbevf_map[] = {
33         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_VF) },
34         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_VF_HV) },
35         { .vendor_id = 0, /* sentinel */ },
36 };
37
38 static const struct rte_eth_desc_lim rx_desc_lim = {
39         .nb_max = TXGBE_RING_DESC_MAX,
40         .nb_min = TXGBE_RING_DESC_MIN,
41         .nb_align = TXGBE_RXD_ALIGN,
42 };
43
44 static const struct rte_eth_desc_lim tx_desc_lim = {
45         .nb_max = TXGBE_RING_DESC_MAX,
46         .nb_min = TXGBE_RING_DESC_MIN,
47         .nb_align = TXGBE_TXD_ALIGN,
48         .nb_seg_max = TXGBE_TX_MAX_SEG,
49         .nb_mtu_seg_max = TXGBE_TX_MAX_SEG,
50 };
51
52 static const struct eth_dev_ops txgbevf_eth_dev_ops;
53
54 /*
55  * Negotiate mailbox API version with the PF.
56  * After reset API version is always set to the basic one (txgbe_mbox_api_10).
57  * Then we try to negotiate starting with the most recent one.
58  * If all negotiation attempts fail, then we will proceed with
59  * the default one (txgbe_mbox_api_10).
60  */
61 static void
62 txgbevf_negotiate_api(struct txgbe_hw *hw)
63 {
64         int32_t i;
65
66         /* start with highest supported, proceed down */
67         static const int sup_ver[] = {
68                 txgbe_mbox_api_13,
69                 txgbe_mbox_api_12,
70                 txgbe_mbox_api_11,
71                 txgbe_mbox_api_10,
72         };
73
74         for (i = 0; i < ARRAY_SIZE(sup_ver); i++) {
75                 if (txgbevf_negotiate_api_version(hw, sup_ver[i]) == 0)
76                         break;
77         }
78 }
79
80 static void
81 generate_random_mac_addr(struct rte_ether_addr *mac_addr)
82 {
83         uint64_t random;
84
85         /* Set Organizationally Unique Identifier (OUI) prefix. */
86         mac_addr->addr_bytes[0] = 0x00;
87         mac_addr->addr_bytes[1] = 0x09;
88         mac_addr->addr_bytes[2] = 0xC0;
89         /* Force indication of locally assigned MAC address. */
90         mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
91         /* Generate the last 3 bytes of the MAC address with a random number. */
92         random = rte_rand();
93         memcpy(&mac_addr->addr_bytes[3], &random, 3);
94 }
95
96 /*
97  * Virtual Function device init
98  */
99 static int
100 eth_txgbevf_dev_init(struct rte_eth_dev *eth_dev)
101 {
102         int err;
103         uint32_t tc, tcs;
104         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
105         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
106         struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
107         struct rte_ether_addr *perm_addr =
108                         (struct rte_ether_addr *)hw->mac.perm_addr;
109
110         PMD_INIT_FUNC_TRACE();
111
112         eth_dev->dev_ops = &txgbevf_eth_dev_ops;
113
114         /* for secondary processes, we don't initialise any further as primary
115          * has already done this work. Only check we don't need a different
116          * RX function
117          */
118         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
119                 struct txgbe_tx_queue *txq;
120                 uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
121                 /* TX queue function in primary, set by last queue initialized
122                  * Tx queue may not initialized by primary process
123                  */
124                 if (eth_dev->data->tx_queues) {
125                         txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
126                         txgbe_set_tx_function(eth_dev, txq);
127                 } else {
128                         /* Use default TX function if we get here */
129                         PMD_INIT_LOG(NOTICE,
130                                      "No TX queues configured yet. Using default TX function.");
131                 }
132
133                 txgbe_set_rx_function(eth_dev);
134
135                 return 0;
136         }
137
138         rte_eth_copy_pci_info(eth_dev, pci_dev);
139
140         hw->device_id = pci_dev->id.device_id;
141         hw->vendor_id = pci_dev->id.vendor_id;
142         hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
143         hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
144         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
145
146         /* Initialize the shared code (base driver) */
147         err = txgbe_init_shared_code(hw);
148         if (err != 0) {
149                 PMD_INIT_LOG(ERR,
150                         "Shared code init failed for txgbevf: %d", err);
151                 return -EIO;
152         }
153
154         /* init_mailbox_params */
155         hw->mbx.init_params(hw);
156
157         /* Disable the interrupts for VF */
158         txgbevf_intr_disable(eth_dev);
159
160         hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
161         err = hw->mac.reset_hw(hw);
162
163         /*
164          * The VF reset operation returns the TXGBE_ERR_INVALID_MAC_ADDR when
165          * the underlying PF driver has not assigned a MAC address to the VF.
166          * In this case, assign a random MAC address.
167          */
168         if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
169                 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
170                 /*
171                  * This error code will be propagated to the app by
172                  * rte_eth_dev_reset, so use a public error code rather than
173                  * the internal-only TXGBE_ERR_RESET_FAILED
174                  */
175                 return -EAGAIN;
176         }
177
178         /* negotiate mailbox API version to use with the PF. */
179         txgbevf_negotiate_api(hw);
180
181         /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
182         txgbevf_get_queues(hw, &tcs, &tc);
183
184         /* Allocate memory for storing MAC addresses */
185         eth_dev->data->mac_addrs = rte_zmalloc("txgbevf", RTE_ETHER_ADDR_LEN *
186                                                hw->mac.num_rar_entries, 0);
187         if (eth_dev->data->mac_addrs == NULL) {
188                 PMD_INIT_LOG(ERR,
189                              "Failed to allocate %u bytes needed to store "
190                              "MAC addresses",
191                              RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
192                 return -ENOMEM;
193         }
194
195         /* Generate a random MAC address, if none was assigned by PF. */
196         if (rte_is_zero_ether_addr(perm_addr)) {
197                 generate_random_mac_addr(perm_addr);
198                 err = txgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
199                 if (err) {
200                         rte_free(eth_dev->data->mac_addrs);
201                         eth_dev->data->mac_addrs = NULL;
202                         return err;
203                 }
204                 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
205                 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
206                              "%02x:%02x:%02x:%02x:%02x:%02x",
207                              perm_addr->addr_bytes[0],
208                              perm_addr->addr_bytes[1],
209                              perm_addr->addr_bytes[2],
210                              perm_addr->addr_bytes[3],
211                              perm_addr->addr_bytes[4],
212                              perm_addr->addr_bytes[5]);
213         }
214
215         /* Copy the permanent MAC address */
216         rte_ether_addr_copy(perm_addr, &eth_dev->data->mac_addrs[0]);
217
218         /* reset the hardware with the new settings */
219         err = hw->mac.start_hw(hw);
220         if (err) {
221                 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
222                 return -EIO;
223         }
224
225         rte_intr_callback_register(intr_handle,
226                                    txgbevf_dev_interrupt_handler, eth_dev);
227         rte_intr_enable(intr_handle);
228         txgbevf_intr_enable(eth_dev);
229
230         PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
231                      eth_dev->data->port_id, pci_dev->id.vendor_id,
232                      pci_dev->id.device_id, "txgbe_mac_raptor_vf");
233
234         return 0;
235 }
236
237 /* Virtual Function device uninit */
238 static int
239 eth_txgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
240 {
241         PMD_INIT_FUNC_TRACE();
242
243         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
244                 return 0;
245
246         txgbevf_dev_close(eth_dev);
247
248         return 0;
249 }
250
251 static int eth_txgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
252         struct rte_pci_device *pci_dev)
253 {
254         return rte_eth_dev_pci_generic_probe(pci_dev,
255                 sizeof(struct txgbe_adapter), eth_txgbevf_dev_init);
256 }
257
258 static int eth_txgbevf_pci_remove(struct rte_pci_device *pci_dev)
259 {
260         return rte_eth_dev_pci_generic_remove(pci_dev, eth_txgbevf_dev_uninit);
261 }
262
263 /*
264  * virtual function driver struct
265  */
266 static struct rte_pci_driver rte_txgbevf_pmd = {
267         .id_table = pci_id_txgbevf_map,
268         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
269         .probe = eth_txgbevf_pci_probe,
270         .remove = eth_txgbevf_pci_remove,
271 };
272
273 static int
274 txgbevf_dev_info_get(struct rte_eth_dev *dev,
275                      struct rte_eth_dev_info *dev_info)
276 {
277         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
278         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
279
280         dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
281         dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
282         dev_info->min_rx_bufsize = 1024;
283         dev_info->max_rx_pktlen = TXGBE_FRAME_SIZE_MAX;
284         dev_info->max_mac_addrs = hw->mac.num_rar_entries;
285         dev_info->max_hash_mac_addrs = TXGBE_VMDQ_NUM_UC_MAC;
286         dev_info->max_vfs = pci_dev->max_vfs;
287         dev_info->max_vmdq_pools = ETH_64_POOLS;
288         dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
289         dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
290                                      dev_info->rx_queue_offload_capa);
291         dev_info->tx_queue_offload_capa = txgbe_get_tx_queue_offloads(dev);
292         dev_info->tx_offload_capa = txgbe_get_tx_port_offloads(dev);
293         dev_info->hash_key_size = TXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
294         dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
295         dev_info->flow_type_rss_offloads = TXGBE_RSS_OFFLOAD_ALL;
296
297         dev_info->default_rxconf = (struct rte_eth_rxconf) {
298                 .rx_thresh = {
299                         .pthresh = TXGBE_DEFAULT_RX_PTHRESH,
300                         .hthresh = TXGBE_DEFAULT_RX_HTHRESH,
301                         .wthresh = TXGBE_DEFAULT_RX_WTHRESH,
302                 },
303                 .rx_free_thresh = TXGBE_DEFAULT_RX_FREE_THRESH,
304                 .rx_drop_en = 0,
305                 .offloads = 0,
306         };
307
308         dev_info->default_txconf = (struct rte_eth_txconf) {
309                 .tx_thresh = {
310                         .pthresh = TXGBE_DEFAULT_TX_PTHRESH,
311                         .hthresh = TXGBE_DEFAULT_TX_HTHRESH,
312                         .wthresh = TXGBE_DEFAULT_TX_WTHRESH,
313                 },
314                 .tx_free_thresh = TXGBE_DEFAULT_TX_FREE_THRESH,
315                 .offloads = 0,
316         };
317
318         dev_info->rx_desc_lim = rx_desc_lim;
319         dev_info->tx_desc_lim = tx_desc_lim;
320
321         return 0;
322 }
323
324 static int
325 txgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
326 {
327         return txgbe_dev_link_update_share(dev, wait_to_complete);
328 }
329
330 /*
331  * Virtual Function operations
332  */
333 static void
334 txgbevf_intr_disable(struct rte_eth_dev *dev)
335 {
336         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
337         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
338
339         PMD_INIT_FUNC_TRACE();
340
341         /* Clear interrupt mask to stop from interrupts being generated */
342         wr32(hw, TXGBE_VFIMS, TXGBE_VFIMS_MASK);
343
344         txgbe_flush(hw);
345
346         /* Clear mask value. */
347         intr->mask_misc = TXGBE_VFIMS_MASK;
348 }
349
350 static void
351 txgbevf_intr_enable(struct rte_eth_dev *dev)
352 {
353         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
354         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
355
356         PMD_INIT_FUNC_TRACE();
357
358         /* VF enable interrupt autoclean */
359         wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
360
361         txgbe_flush(hw);
362
363         intr->mask_misc = 0;
364 }
365
366 static int
367 txgbevf_dev_close(struct rte_eth_dev *dev)
368 {
369         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
370         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
371         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
372         PMD_INIT_FUNC_TRACE();
373         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
374                 return 0;
375
376         hw->mac.reset_hw(hw);
377
378         txgbe_dev_free_queues(dev);
379
380         /**
381          * Remove the VF MAC address ro ensure
382          * that the VF traffic goes to the PF
383          * after stop, close and detach of the VF
384          **/
385         txgbevf_remove_mac_addr(dev, 0);
386
387         /* Disable the interrupts for VF */
388         txgbevf_intr_disable(dev);
389
390         rte_free(dev->data->mac_addrs);
391         dev->data->mac_addrs = NULL;
392
393         rte_intr_disable(intr_handle);
394         rte_intr_callback_unregister(intr_handle,
395                                      txgbevf_dev_interrupt_handler, dev);
396
397         return 0;
398 }
399
400 static int
401 txgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
402 {
403         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
404         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
405         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
406         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
407         uint32_t vec = TXGBE_MISC_VEC_ID;
408
409         if (rte_intr_allow_others(intr_handle))
410                 vec = TXGBE_RX_VEC_START;
411         intr->mask_misc &= ~(1 << vec);
412         RTE_SET_USED(queue_id);
413         wr32(hw, TXGBE_VFIMC, ~intr->mask_misc);
414
415         rte_intr_enable(intr_handle);
416
417         return 0;
418 }
419
420 static int
421 txgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
422 {
423         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
424         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
425         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
426         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
427         uint32_t vec = TXGBE_MISC_VEC_ID;
428
429         if (rte_intr_allow_others(intr_handle))
430                 vec = TXGBE_RX_VEC_START;
431         intr->mask_misc |= (1 << vec);
432         RTE_SET_USED(queue_id);
433         wr32(hw, TXGBE_VFIMS, intr->mask_misc);
434
435         return 0;
436 }
437
438 static void
439 txgbevf_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
440                      uint8_t queue, uint8_t msix_vector)
441 {
442         uint32_t tmp, idx;
443
444         if (direction == -1) {
445                 /* other causes */
446                 msix_vector |= TXGBE_VFIVAR_VLD;
447                 tmp = rd32(hw, TXGBE_VFIVARMISC);
448                 tmp &= ~0xFF;
449                 tmp |= msix_vector;
450                 wr32(hw, TXGBE_VFIVARMISC, tmp);
451         } else {
452                 /* rx or tx cause */
453                 /* Workround for ICR lost */
454                 idx = ((16 * (queue & 1)) + (8 * direction));
455                 tmp = rd32(hw, TXGBE_VFIVAR(queue >> 1));
456                 tmp &= ~(0xFF << idx);
457                 tmp |= (msix_vector << idx);
458                 wr32(hw, TXGBE_VFIVAR(queue >> 1), tmp);
459         }
460 }
461
462 static void
463 txgbevf_configure_msix(struct rte_eth_dev *dev)
464 {
465         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
466         struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
467         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
468         uint32_t q_idx;
469         uint32_t vector_idx = TXGBE_MISC_VEC_ID;
470         uint32_t base = TXGBE_MISC_VEC_ID;
471
472         /* Configure VF other cause ivar */
473         txgbevf_set_ivar_map(hw, -1, 1, vector_idx);
474
475         /* won't configure msix register if no mapping is done
476          * between intr vector and event fd.
477          */
478         if (!rte_intr_dp_is_en(intr_handle))
479                 return;
480
481         if (rte_intr_allow_others(intr_handle)) {
482                 base = TXGBE_RX_VEC_START;
483                 vector_idx = TXGBE_RX_VEC_START;
484         }
485
486         /* Configure all RX queues of VF */
487         for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
488                 /* Force all queue use vector 0,
489                  * as TXGBE_VF_MAXMSIVECOTR = 1
490                  */
491                 txgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
492                 intr_handle->intr_vec[q_idx] = vector_idx;
493                 if (vector_idx < base + intr_handle->nb_efd - 1)
494                         vector_idx++;
495         }
496
497         /* As RX queue setting above show, all queues use the vector 0.
498          * Set only the ITR value of TXGBE_MISC_VEC_ID.
499          */
500         wr32(hw, TXGBE_ITR(TXGBE_MISC_VEC_ID),
501                 TXGBE_ITR_IVAL(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
502                 | TXGBE_ITR_WRDSA);
503 }
504
505 static int
506 txgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
507                      __rte_unused uint32_t index,
508                      __rte_unused uint32_t pool)
509 {
510         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
511         int err;
512
513         /*
514          * On a VF, adding again the same MAC addr is not an idempotent
515          * operation. Trap this case to avoid exhausting the [very limited]
516          * set of PF resources used to store VF MAC addresses.
517          */
518         if (memcmp(hw->mac.perm_addr, mac_addr,
519                         sizeof(struct rte_ether_addr)) == 0)
520                 return -1;
521         err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
522         if (err != 0)
523                 PMD_DRV_LOG(ERR, "Unable to add MAC address "
524                             "%02x:%02x:%02x:%02x:%02x:%02x - err=%d",
525                             mac_addr->addr_bytes[0],
526                             mac_addr->addr_bytes[1],
527                             mac_addr->addr_bytes[2],
528                             mac_addr->addr_bytes[3],
529                             mac_addr->addr_bytes[4],
530                             mac_addr->addr_bytes[5],
531                             err);
532         return err;
533 }
534
535 static void
536 txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
537 {
538         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
539         struct rte_ether_addr *perm_addr =
540                         (struct rte_ether_addr *)hw->mac.perm_addr;
541         struct rte_ether_addr *mac_addr;
542         uint32_t i;
543         int err;
544
545         /*
546          * The TXGBE_VF_SET_MACVLAN command of the txgbe-pf driver does
547          * not support the deletion of a given MAC address.
548          * Instead, it imposes to delete all MAC addresses, then to add again
549          * all MAC addresses with the exception of the one to be deleted.
550          */
551         (void)txgbevf_set_uc_addr_vf(hw, 0, NULL);
552
553         /*
554          * Add again all MAC addresses, with the exception of the deleted one
555          * and of the permanent MAC address.
556          */
557         for (i = 0, mac_addr = dev->data->mac_addrs;
558              i < hw->mac.num_rar_entries; i++, mac_addr++) {
559                 /* Skip the deleted MAC address */
560                 if (i == index)
561                         continue;
562                 /* Skip NULL MAC addresses */
563                 if (rte_is_zero_ether_addr(mac_addr))
564                         continue;
565                 /* Skip the permanent MAC address */
566                 if (memcmp(perm_addr, mac_addr,
567                                 sizeof(struct rte_ether_addr)) == 0)
568                         continue;
569                 err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
570                 if (err != 0)
571                         PMD_DRV_LOG(ERR,
572                                     "Adding again MAC address "
573                                     "%02x:%02x:%02x:%02x:%02x:%02x failed "
574                                     "err=%d",
575                                     mac_addr->addr_bytes[0],
576                                     mac_addr->addr_bytes[1],
577                                     mac_addr->addr_bytes[2],
578                                     mac_addr->addr_bytes[3],
579                                     mac_addr->addr_bytes[4],
580                                     mac_addr->addr_bytes[5],
581                                     err);
582         }
583 }
584
585 static int
586 txgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
587                 struct rte_ether_addr *addr)
588 {
589         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
590
591         hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
592
593         return 0;
594 }
595
596 static void txgbevf_mbx_process(struct rte_eth_dev *dev)
597 {
598         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
599         u32 in_msg = 0;
600
601         /* peek the message first */
602         in_msg = rd32(hw, TXGBE_VFMBX);
603
604         /* PF reset VF event */
605         if (in_msg == TXGBE_PF_CONTROL_MSG) {
606                 /* dummy mbx read to ack pf */
607                 if (txgbe_read_mbx(hw, &in_msg, 1, 0))
608                         return;
609                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
610                                               NULL);
611         }
612 }
613
614 static int
615 txgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
616 {
617         uint32_t eicr;
618         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
619         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
620         txgbevf_intr_disable(dev);
621
622         /* read-on-clear nic registers here */
623         eicr = rd32(hw, TXGBE_VFICR);
624         intr->flags = 0;
625
626         /* only one misc vector supported - mailbox */
627         eicr &= TXGBE_VFICR_MASK;
628         /* Workround for ICR lost */
629         intr->flags |= TXGBE_FLAG_MAILBOX;
630
631         return 0;
632 }
633
634 static int
635 txgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
636 {
637         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
638
639         if (intr->flags & TXGBE_FLAG_MAILBOX) {
640                 txgbevf_mbx_process(dev);
641                 intr->flags &= ~TXGBE_FLAG_MAILBOX;
642         }
643
644         txgbevf_intr_enable(dev);
645
646         return 0;
647 }
648
649 static void
650 txgbevf_dev_interrupt_handler(void *param)
651 {
652         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
653
654         txgbevf_dev_interrupt_get_status(dev);
655         txgbevf_dev_interrupt_action(dev);
656 }
657
658 /*
659  * dev_ops for virtual function, bare necessities for basic vf
660  * operation have been implemented
661  */
662 static const struct eth_dev_ops txgbevf_eth_dev_ops = {
663         .link_update          = txgbevf_dev_link_update,
664         .dev_infos_get        = txgbevf_dev_info_get,
665         .rx_queue_intr_enable = txgbevf_dev_rx_queue_intr_enable,
666         .rx_queue_intr_disable = txgbevf_dev_rx_queue_intr_disable,
667         .mac_addr_add         = txgbevf_add_mac_addr,
668         .mac_addr_remove      = txgbevf_remove_mac_addr,
669         .rxq_info_get         = txgbe_rxq_info_get,
670         .txq_info_get         = txgbe_txq_info_get,
671         .mac_addr_set         = txgbevf_set_default_mac_addr,
672 };
673
674 RTE_PMD_REGISTER_PCI(net_txgbe_vf, rte_txgbevf_pmd);
675 RTE_PMD_REGISTER_PCI_TABLE(net_txgbe_vf, pci_id_txgbevf_map);
676 RTE_PMD_REGISTER_KMOD_DEP(net_txgbe_vf, "* igb_uio | vfio-pci");