eal: clean up interrupt handle
[dpdk.git] / drivers / net / bnx2x / bnx2x_ethdev.c
1 /*
2  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
3  *
4  * Copyright (c) 2015 QLogic Corporation.
5  * All rights reserved.
6  * www.qlogic.com
7  *
8  * See LICENSE.bnx2x_pmd for copyright and licensing details.
9  */
10
11 #include "bnx2x.h"
12 #include "bnx2x_rxtx.h"
13
14 #include <rte_dev.h>
15
16 /*
17  * The set of PCI devices this driver supports
18  */
19 #define BROADCOM_PCI_VENDOR_ID 0x14E4
20 static const struct rte_pci_id pci_id_bnx2x_map[] = {
21         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57800) },
22         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57711) },
23         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810) },
24         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811) },
25         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_OBS) },
26         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_4_10) },
27         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_2_20) },
28 #ifdef RTE_LIBRTE_BNX2X_MF_SUPPORT
29         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810_MF) },
30         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811_MF) },
31         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_MF) },
32 #endif
33         { .vendor_id = 0, }
34 };
35
36 static const struct rte_pci_id pci_id_bnx2xvf_map[] = {
37         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57800_VF) },
38         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810_VF) },
39         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811_VF) },
40         { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_VF) },
41         { .vendor_id = 0, }
42 };
43
44 struct rte_bnx2x_xstats_name_off {
45         char name[RTE_ETH_XSTATS_NAME_SIZE];
46         uint32_t offset_hi;
47         uint32_t offset_lo;
48 };
49
50 static const struct rte_bnx2x_xstats_name_off bnx2x_xstats_strings[] = {
51         {"rx_buffer_drops",
52                 offsetof(struct bnx2x_eth_stats, brb_drop_hi),
53                 offsetof(struct bnx2x_eth_stats, brb_drop_lo)},
54         {"rx_buffer_truncates",
55                 offsetof(struct bnx2x_eth_stats, brb_truncate_hi),
56                 offsetof(struct bnx2x_eth_stats, brb_truncate_lo)},
57         {"rx_buffer_truncate_discard",
58                 offsetof(struct bnx2x_eth_stats, brb_truncate_discard),
59                 offsetof(struct bnx2x_eth_stats, brb_truncate_discard)},
60         {"mac_filter_discard",
61                 offsetof(struct bnx2x_eth_stats, mac_filter_discard),
62                 offsetof(struct bnx2x_eth_stats, mac_filter_discard)},
63         {"no_match_vlan_tag_discard",
64                 offsetof(struct bnx2x_eth_stats, mf_tag_discard),
65                 offsetof(struct bnx2x_eth_stats, mf_tag_discard)},
66         {"tx_pause",
67                 offsetof(struct bnx2x_eth_stats, pause_frames_sent_hi),
68                 offsetof(struct bnx2x_eth_stats, pause_frames_sent_lo)},
69         {"rx_pause",
70                 offsetof(struct bnx2x_eth_stats, pause_frames_received_hi),
71                 offsetof(struct bnx2x_eth_stats, pause_frames_received_lo)},
72         {"tx_priority_flow_control",
73                 offsetof(struct bnx2x_eth_stats, pfc_frames_sent_hi),
74                 offsetof(struct bnx2x_eth_stats, pfc_frames_sent_lo)},
75         {"rx_priority_flow_control",
76                 offsetof(struct bnx2x_eth_stats, pfc_frames_received_hi),
77                 offsetof(struct bnx2x_eth_stats, pfc_frames_received_lo)}
78 };
79
80 static void
81 bnx2x_link_update(struct rte_eth_dev *dev)
82 {
83         struct bnx2x_softc *sc = dev->data->dev_private;
84
85         PMD_INIT_FUNC_TRACE();
86         bnx2x_link_status_update(sc);
87         mb();
88         dev->data->dev_link.link_speed = sc->link_vars.line_speed;
89         switch (sc->link_vars.duplex) {
90                 case DUPLEX_FULL:
91                         dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
92                         break;
93                 case DUPLEX_HALF:
94                         dev->data->dev_link.link_duplex = ETH_LINK_HALF_DUPLEX;
95                         break;
96         }
97         dev->data->dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
98                         ETH_LINK_SPEED_FIXED);
99         dev->data->dev_link.link_status = sc->link_vars.link_up;
100 }
101
102 static void
103 bnx2x_interrupt_action(struct rte_eth_dev *dev)
104 {
105         struct bnx2x_softc *sc = dev->data->dev_private;
106         uint32_t link_status;
107
108         PMD_DEBUG_PERIODIC_LOG(INFO, "Interrupt handled");
109
110         bnx2x_intr_legacy(sc, 0);
111
112         if (sc->periodic_flags & PERIODIC_GO)
113                 bnx2x_periodic_callout(sc);
114         link_status = REG_RD(sc, sc->link_params.shmem_base +
115                         offsetof(struct shmem_region,
116                                 port_mb[sc->link_params.port].link_status));
117         if ((link_status & LINK_STATUS_LINK_UP) != dev->data->dev_link.link_status)
118                 bnx2x_link_update(dev);
119 }
120
121 static __rte_unused void
122 bnx2x_interrupt_handler(void *param)
123 {
124         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
125         struct bnx2x_softc *sc = dev->data->dev_private;
126
127         bnx2x_interrupt_action(dev);
128         rte_intr_enable(&sc->pci_dev->intr_handle);
129 }
130
131 /*
132  * Devops - helper functions can be called from user application
133  */
134
135 static int
136 bnx2x_dev_configure(struct rte_eth_dev *dev)
137 {
138         struct bnx2x_softc *sc = dev->data->dev_private;
139         int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF);
140
141         PMD_INIT_FUNC_TRACE();
142
143         if (dev->data->dev_conf.rxmode.jumbo_frame)
144                 sc->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len;
145
146         if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) {
147                 PMD_DRV_LOG(ERR, "The number of TX queues is greater than number of RX queues");
148                 return -EINVAL;
149         }
150
151         sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
152         if (sc->num_queues > mp_ncpus) {
153                 PMD_DRV_LOG(ERR, "The number of queues is more than number of CPUs");
154                 return -EINVAL;
155         }
156
157         PMD_DRV_LOG(DEBUG, "num_queues=%d, mtu=%d",
158                        sc->num_queues, sc->mtu);
159
160         /* allocate ilt */
161         if (bnx2x_alloc_ilt_mem(sc) != 0) {
162                 PMD_DRV_LOG(ERR, "bnx2x_alloc_ilt_mem was failed");
163                 return -ENXIO;
164         }
165
166         /* allocate the host hardware/software hsi structures */
167         if (bnx2x_alloc_hsi_mem(sc) != 0) {
168                 PMD_DRV_LOG(ERR, "bnx2x_alloc_hsi_mem was failed");
169                 bnx2x_free_ilt_mem(sc);
170                 return -ENXIO;
171         }
172
173         return 0;
174 }
175
176 static int
177 bnx2x_dev_start(struct rte_eth_dev *dev)
178 {
179         struct bnx2x_softc *sc = dev->data->dev_private;
180         int ret = 0;
181
182         PMD_INIT_FUNC_TRACE();
183
184         ret = bnx2x_init(sc);
185         if (ret) {
186                 PMD_DRV_LOG(DEBUG, "bnx2x_init failed (%d)", ret);
187                 return -1;
188         }
189
190         if (IS_PF(sc)) {
191                 rte_intr_callback_register(&sc->pci_dev->intr_handle,
192                                 bnx2x_interrupt_handler, (void *)dev);
193
194                 if (rte_intr_enable(&sc->pci_dev->intr_handle))
195                         PMD_DRV_LOG(ERR, "rte_intr_enable failed");
196         }
197
198         ret = bnx2x_dev_rx_init(dev);
199         if (ret != 0) {
200                 PMD_DRV_LOG(DEBUG, "bnx2x_dev_rx_init returned error code");
201                 return -3;
202         }
203
204         /* Print important adapter info for the user. */
205         bnx2x_print_adapter_info(sc);
206
207         return ret;
208 }
209
210 static void
211 bnx2x_dev_stop(struct rte_eth_dev *dev)
212 {
213         struct bnx2x_softc *sc = dev->data->dev_private;
214         int ret = 0;
215
216         PMD_INIT_FUNC_TRACE();
217
218         if (IS_PF(sc)) {
219                 rte_intr_disable(&sc->pci_dev->intr_handle);
220                 rte_intr_callback_unregister(&sc->pci_dev->intr_handle,
221                                 bnx2x_interrupt_handler, (void *)dev);
222         }
223
224         ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE);
225         if (ret) {
226                 PMD_DRV_LOG(DEBUG, "bnx2x_nic_unload failed (%d)", ret);
227                 return;
228         }
229
230         return;
231 }
232
233 static void
234 bnx2x_dev_close(struct rte_eth_dev *dev)
235 {
236         struct bnx2x_softc *sc = dev->data->dev_private;
237
238         PMD_INIT_FUNC_TRACE();
239
240         if (IS_VF(sc))
241                 bnx2x_vf_close(sc);
242
243         bnx2x_dev_clear_queues(dev);
244         memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link));
245
246         /* free the host hardware/software hsi structures */
247         bnx2x_free_hsi_mem(sc);
248
249         /* free ilt */
250         bnx2x_free_ilt_mem(sc);
251 }
252
253 static void
254 bnx2x_promisc_enable(struct rte_eth_dev *dev)
255 {
256         struct bnx2x_softc *sc = dev->data->dev_private;
257
258         PMD_INIT_FUNC_TRACE();
259         sc->rx_mode = BNX2X_RX_MODE_PROMISC;
260         if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
261                 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
262         bnx2x_set_rx_mode(sc);
263 }
264
265 static void
266 bnx2x_promisc_disable(struct rte_eth_dev *dev)
267 {
268         struct bnx2x_softc *sc = dev->data->dev_private;
269
270         PMD_INIT_FUNC_TRACE();
271         sc->rx_mode = BNX2X_RX_MODE_NORMAL;
272         if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
273                 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
274         bnx2x_set_rx_mode(sc);
275 }
276
277 static void
278 bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev)
279 {
280         struct bnx2x_softc *sc = dev->data->dev_private;
281
282         PMD_INIT_FUNC_TRACE();
283         sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
284         if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
285                 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
286         bnx2x_set_rx_mode(sc);
287 }
288
289 static void
290 bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev)
291 {
292         struct bnx2x_softc *sc = dev->data->dev_private;
293
294         PMD_INIT_FUNC_TRACE();
295         sc->rx_mode = BNX2X_RX_MODE_NORMAL;
296         if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
297                 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
298         bnx2x_set_rx_mode(sc);
299 }
300
301 static int
302 bnx2x_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
303 {
304         PMD_INIT_FUNC_TRACE();
305
306         int old_link_status = dev->data->dev_link.link_status;
307
308         bnx2x_link_update(dev);
309
310         return old_link_status == dev->data->dev_link.link_status ? -1 : 0;
311 }
312
313 static int
314 bnx2xvf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
315 {
316         int old_link_status = dev->data->dev_link.link_status;
317         struct bnx2x_softc *sc = dev->data->dev_private;
318
319         bnx2x_link_update(dev);
320
321         bnx2x_check_bull(sc);
322         if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
323                 PMD_DRV_LOG(ERR, "PF indicated channel is down."
324                                 "VF device is no longer operational");
325                 dev->data->dev_link.link_status = ETH_LINK_DOWN;
326         }
327
328         return old_link_status == dev->data->dev_link.link_status ? -1 : 0;
329 }
330
331 static void
332 bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
333 {
334         struct bnx2x_softc *sc = dev->data->dev_private;
335         uint32_t brb_truncate_discard;
336         uint64_t brb_drops;
337         uint64_t brb_truncates;
338
339         PMD_INIT_FUNC_TRACE();
340
341         bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
342
343         memset(stats, 0, sizeof (struct rte_eth_stats));
344
345         stats->ipackets =
346                 HILO_U64(sc->eth_stats.total_unicast_packets_received_hi,
347                                 sc->eth_stats.total_unicast_packets_received_lo) +
348                 HILO_U64(sc->eth_stats.total_multicast_packets_received_hi,
349                                 sc->eth_stats.total_multicast_packets_received_lo) +
350                 HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi,
351                                 sc->eth_stats.total_broadcast_packets_received_lo);
352
353         stats->opackets =
354                 HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi,
355                                 sc->eth_stats.total_unicast_packets_transmitted_lo) +
356                 HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi,
357                                 sc->eth_stats.total_multicast_packets_transmitted_lo) +
358                 HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi,
359                                 sc->eth_stats.total_broadcast_packets_transmitted_lo);
360
361         stats->ibytes =
362                 HILO_U64(sc->eth_stats.total_bytes_received_hi,
363                                 sc->eth_stats.total_bytes_received_lo);
364
365         stats->obytes =
366                 HILO_U64(sc->eth_stats.total_bytes_transmitted_hi,
367                                 sc->eth_stats.total_bytes_transmitted_lo);
368
369         stats->ierrors =
370                 HILO_U64(sc->eth_stats.error_bytes_received_hi,
371                                 sc->eth_stats.error_bytes_received_lo);
372
373         stats->oerrors = 0;
374
375         stats->rx_nombuf =
376                 HILO_U64(sc->eth_stats.no_buff_discard_hi,
377                                 sc->eth_stats.no_buff_discard_lo);
378
379         brb_drops =
380                 HILO_U64(sc->eth_stats.brb_drop_hi,
381                          sc->eth_stats.brb_drop_lo);
382
383         brb_truncates =
384                 HILO_U64(sc->eth_stats.brb_truncate_hi,
385                          sc->eth_stats.brb_truncate_lo);
386
387         brb_truncate_discard = sc->eth_stats.brb_truncate_discard;
388
389         stats->imissed = brb_drops + brb_truncates +
390                          brb_truncate_discard + stats->rx_nombuf;
391 }
392
393 static int
394 bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev,
395                        struct rte_eth_xstat_name *xstats_names,
396                        __rte_unused unsigned limit)
397 {
398         unsigned int i, stat_cnt = RTE_DIM(bnx2x_xstats_strings);
399
400         if (xstats_names != NULL)
401                 for (i = 0; i < stat_cnt; i++)
402                         snprintf(xstats_names[i].name,
403                                 sizeof(xstats_names[i].name),
404                                 "%s",
405                                 bnx2x_xstats_strings[i].name);
406
407         return stat_cnt;
408 }
409
410 static int
411 bnx2x_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
412                      unsigned int n)
413 {
414         struct bnx2x_softc *sc = dev->data->dev_private;
415         unsigned int num = RTE_DIM(bnx2x_xstats_strings);
416
417         if (n < num)
418                 return num;
419
420         bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
421
422         for (num = 0; num < n; num++) {
423                 if (bnx2x_xstats_strings[num].offset_hi !=
424                     bnx2x_xstats_strings[num].offset_lo)
425                         xstats[num].value = HILO_U64(
426                                           *(uint32_t *)((char *)&sc->eth_stats +
427                                           bnx2x_xstats_strings[num].offset_hi),
428                                           *(uint32_t *)((char *)&sc->eth_stats +
429                                           bnx2x_xstats_strings[num].offset_lo));
430                 else
431                         xstats[num].value =
432                                           *(uint64_t *)((char *)&sc->eth_stats +
433                                           bnx2x_xstats_strings[num].offset_lo);
434                 xstats[num].id = num;
435         }
436
437         return num;
438 }
439
440 static void
441 bnx2x_dev_infos_get(struct rte_eth_dev *dev, __rte_unused struct rte_eth_dev_info *dev_info)
442 {
443         struct bnx2x_softc *sc = dev->data->dev_private;
444         dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
445         dev_info->max_rx_queues  = sc->max_rx_queues;
446         dev_info->max_tx_queues  = sc->max_tx_queues;
447         dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
448         dev_info->max_rx_pktlen  = BNX2X_MAX_RX_PKT_LEN;
449         dev_info->max_mac_addrs  = BNX2X_MAX_MAC_ADDRS;
450         dev_info->speed_capa = ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G;
451 }
452
453 static void
454 bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
455                 uint32_t index, uint32_t pool)
456 {
457         struct bnx2x_softc *sc = dev->data->dev_private;
458
459         if (sc->mac_ops.mac_addr_add)
460                 sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool);
461 }
462
463 static void
464 bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
465 {
466         struct bnx2x_softc *sc = dev->data->dev_private;
467
468         if (sc->mac_ops.mac_addr_remove)
469                 sc->mac_ops.mac_addr_remove(dev, index);
470 }
471
472 static const struct eth_dev_ops bnx2x_eth_dev_ops = {
473         .dev_configure                = bnx2x_dev_configure,
474         .dev_start                    = bnx2x_dev_start,
475         .dev_stop                     = bnx2x_dev_stop,
476         .dev_close                    = bnx2x_dev_close,
477         .promiscuous_enable           = bnx2x_promisc_enable,
478         .promiscuous_disable          = bnx2x_promisc_disable,
479         .allmulticast_enable          = bnx2x_dev_allmulticast_enable,
480         .allmulticast_disable         = bnx2x_dev_allmulticast_disable,
481         .link_update                  = bnx2x_dev_link_update,
482         .stats_get                    = bnx2x_dev_stats_get,
483         .xstats_get                   = bnx2x_dev_xstats_get,
484         .xstats_get_names             = bnx2x_get_xstats_names,
485         .dev_infos_get                = bnx2x_dev_infos_get,
486         .rx_queue_setup               = bnx2x_dev_rx_queue_setup,
487         .rx_queue_release             = bnx2x_dev_rx_queue_release,
488         .tx_queue_setup               = bnx2x_dev_tx_queue_setup,
489         .tx_queue_release             = bnx2x_dev_tx_queue_release,
490         .mac_addr_add                 = bnx2x_mac_addr_add,
491         .mac_addr_remove              = bnx2x_mac_addr_remove,
492 };
493
494 /*
495  * dev_ops for virtual function
496  */
497 static const struct eth_dev_ops bnx2xvf_eth_dev_ops = {
498         .dev_configure                = bnx2x_dev_configure,
499         .dev_start                    = bnx2x_dev_start,
500         .dev_stop                     = bnx2x_dev_stop,
501         .dev_close                    = bnx2x_dev_close,
502         .promiscuous_enable           = bnx2x_promisc_enable,
503         .promiscuous_disable          = bnx2x_promisc_disable,
504         .allmulticast_enable          = bnx2x_dev_allmulticast_enable,
505         .allmulticast_disable         = bnx2x_dev_allmulticast_disable,
506         .link_update                  = bnx2xvf_dev_link_update,
507         .stats_get                    = bnx2x_dev_stats_get,
508         .xstats_get                   = bnx2x_dev_xstats_get,
509         .xstats_get_names             = bnx2x_get_xstats_names,
510         .dev_infos_get                = bnx2x_dev_infos_get,
511         .rx_queue_setup               = bnx2x_dev_rx_queue_setup,
512         .rx_queue_release             = bnx2x_dev_rx_queue_release,
513         .tx_queue_setup               = bnx2x_dev_tx_queue_setup,
514         .tx_queue_release             = bnx2x_dev_tx_queue_release,
515         .mac_addr_add                 = bnx2x_mac_addr_add,
516         .mac_addr_remove              = bnx2x_mac_addr_remove,
517 };
518
519
520 static int
521 bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
522 {
523         int ret = 0;
524         struct rte_pci_device *pci_dev;
525         struct bnx2x_softc *sc;
526
527         PMD_INIT_FUNC_TRACE();
528
529         eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
530         pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
531
532         rte_eth_copy_pci_info(eth_dev, pci_dev);
533
534         sc = eth_dev->data->dev_private;
535         sc->pcie_bus    = pci_dev->addr.bus;
536         sc->pcie_device = pci_dev->addr.devid;
537
538         if (is_vf)
539                 sc->flags = BNX2X_IS_VF_FLAG;
540
541         sc->devinfo.vendor_id    = pci_dev->id.vendor_id;
542         sc->devinfo.device_id    = pci_dev->id.device_id;
543         sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id;
544         sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id;
545
546         sc->pcie_func = pci_dev->addr.function;
547         sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr;
548         if (is_vf)
549                 sc->bar[BAR1].base_addr = (void *)
550                         ((uintptr_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START);
551         else
552                 sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr;
553
554         assert(sc->bar[BAR0].base_addr);
555         assert(sc->bar[BAR1].base_addr);
556
557         bnx2x_load_firmware(sc);
558         assert(sc->firmware);
559
560         if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
561                 sc->udp_rss = 1;
562
563         sc->rx_budget = BNX2X_RX_BUDGET;
564         sc->hc_rx_ticks = BNX2X_RX_TICKS;
565         sc->hc_tx_ticks = BNX2X_TX_TICKS;
566
567         sc->interrupt_mode = INTR_MODE_SINGLE_MSIX;
568         sc->rx_mode = BNX2X_RX_MODE_NORMAL;
569
570         sc->pci_dev = pci_dev;
571         ret = bnx2x_attach(sc);
572         if (ret) {
573                 PMD_DRV_LOG(ERR, "bnx2x_attach failed (%d)", ret);
574                 return ret;
575         }
576
577         eth_dev->data->mac_addrs = (struct ether_addr *)sc->link_params.mac_addr;
578
579         PMD_DRV_LOG(INFO, "pcie_bus=%d, pcie_device=%d",
580                         sc->pcie_bus, sc->pcie_device);
581         PMD_DRV_LOG(INFO, "bar0.addr=%p, bar1.addr=%p",
582                         sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr);
583         PMD_DRV_LOG(INFO, "port=%d, path=%d, vnic=%d, func=%d",
584                         PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc));
585         PMD_DRV_LOG(INFO, "portID=%d vendorID=0x%x deviceID=0x%x",
586                         eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id);
587
588         if (IS_VF(sc)) {
589                 rte_spinlock_init(&sc->vf2pf_lock);
590
591                 if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg),
592                                     &sc->vf2pf_mbox_mapping, "vf2pf_mbox",
593                                     RTE_CACHE_LINE_SIZE) != 0)
594                         return -ENOMEM;
595
596                 sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *)
597                                          sc->vf2pf_mbox_mapping.vaddr;
598
599                 if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin),
600                                     &sc->pf2vf_bulletin_mapping, "vf2pf_bull",
601                                     RTE_CACHE_LINE_SIZE) != 0)
602                         return -ENOMEM;
603
604                 sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *)
605                                              sc->pf2vf_bulletin_mapping.vaddr;
606
607                 ret = bnx2x_vf_get_resources(sc, sc->max_tx_queues,
608                                              sc->max_rx_queues);
609                 if (ret)
610                         return ret;
611         }
612
613         return 0;
614 }
615
616 static int
617 eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev)
618 {
619         PMD_INIT_FUNC_TRACE();
620         return bnx2x_common_dev_init(eth_dev, 0);
621 }
622
623 static int
624 eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev)
625 {
626         PMD_INIT_FUNC_TRACE();
627         return bnx2x_common_dev_init(eth_dev, 1);
628 }
629
630 static struct eth_driver rte_bnx2x_pmd = {
631         .pci_drv = {
632                 .id_table = pci_id_bnx2x_map,
633                 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
634                 .probe = rte_eth_dev_pci_probe,
635                 .remove = rte_eth_dev_pci_remove,
636         },
637         .eth_dev_init = eth_bnx2x_dev_init,
638         .dev_private_size = sizeof(struct bnx2x_softc),
639 };
640
641 /*
642  * virtual function driver struct
643  */
644 static struct eth_driver rte_bnx2xvf_pmd = {
645         .pci_drv = {
646                 .id_table = pci_id_bnx2xvf_map,
647                 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
648                 .probe = rte_eth_dev_pci_probe,
649                 .remove = rte_eth_dev_pci_remove,
650         },
651         .eth_dev_init = eth_bnx2xvf_dev_init,
652         .dev_private_size = sizeof(struct bnx2x_softc),
653 };
654
655 RTE_PMD_REGISTER_PCI(net_bnx2x, rte_bnx2x_pmd.pci_drv);
656 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2x, pci_id_bnx2x_map);
657 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2x, "* igb_uio | uio_pci_generic | vfio");
658 RTE_PMD_REGISTER_PCI(net_bnx2xvf, rte_bnx2xvf_pmd.pci_drv);
659 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2xvf, pci_id_bnx2xvf_map);
660 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2xvf, "* igb_uio | vfio");