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