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