bnx2x_ethdev.c revision 5b1ff351
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
20static 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
36static 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
44struct 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
50static 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
80static void
81bnx2x_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
102static void
103bnx2x_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
121static __rte_unused void
122bnx2x_interrupt_handler(__rte_unused struct rte_intr_handle *handle, void *param)
123{
124	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
125
126	bnx2x_interrupt_action(dev);
127	rte_intr_enable(&(dev->pci_dev->intr_handle));
128}
129
130/*
131 * Devops - helper functions can be called from user application
132 */
133
134static int
135bnx2x_dev_configure(struct rte_eth_dev *dev)
136{
137	struct bnx2x_softc *sc = dev->data->dev_private;
138	int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF);
139
140	PMD_INIT_FUNC_TRACE();
141
142	if (dev->data->dev_conf.rxmode.jumbo_frame)
143		sc->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len;
144
145	if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) {
146		PMD_DRV_LOG(ERR, "The number of TX queues is greater than number of RX queues");
147		return -EINVAL;
148	}
149
150	sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
151	if (sc->num_queues > mp_ncpus) {
152		PMD_DRV_LOG(ERR, "The number of queues is more than number of CPUs");
153		return -EINVAL;
154	}
155
156	PMD_DRV_LOG(DEBUG, "num_queues=%d, mtu=%d",
157		       sc->num_queues, sc->mtu);
158
159	/* allocate ilt */
160	if (bnx2x_alloc_ilt_mem(sc) != 0) {
161		PMD_DRV_LOG(ERR, "bnx2x_alloc_ilt_mem was failed");
162		return -ENXIO;
163	}
164
165	/* allocate the host hardware/software hsi structures */
166	if (bnx2x_alloc_hsi_mem(sc) != 0) {
167		PMD_DRV_LOG(ERR, "bnx2x_alloc_hsi_mem was failed");
168		bnx2x_free_ilt_mem(sc);
169		return -ENXIO;
170	}
171
172	return 0;
173}
174
175static int
176bnx2x_dev_start(struct rte_eth_dev *dev)
177{
178	struct bnx2x_softc *sc = dev->data->dev_private;
179	int ret = 0;
180
181	PMD_INIT_FUNC_TRACE();
182
183	ret = bnx2x_init(sc);
184	if (ret) {
185		PMD_DRV_LOG(DEBUG, "bnx2x_init failed (%d)", ret);
186		return -1;
187	}
188
189	if (IS_PF(sc)) {
190		rte_intr_callback_register(&(dev->pci_dev->intr_handle),
191				bnx2x_interrupt_handler, (void *)dev);
192
193		if(rte_intr_enable(&(dev->pci_dev->intr_handle)))
194			PMD_DRV_LOG(ERR, "rte_intr_enable failed");
195	}
196
197	ret = bnx2x_dev_rx_init(dev);
198	if (ret != 0) {
199		PMD_DRV_LOG(DEBUG, "bnx2x_dev_rx_init returned error code");
200		return -3;
201	}
202
203	/* Print important adapter info for the user. */
204	bnx2x_print_adapter_info(sc);
205
206	DELAY_MS(2500);
207
208	return ret;
209}
210
211static void
212bnx2x_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(&(dev->pci_dev->intr_handle));
221		rte_intr_callback_unregister(&(dev->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
234static void
235bnx2x_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
254static void
255bnx2x_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	bnx2x_set_rx_mode(sc);
262}
263
264static void
265bnx2x_promisc_disable(struct rte_eth_dev *dev)
266{
267	struct bnx2x_softc *sc = dev->data->dev_private;
268
269	PMD_INIT_FUNC_TRACE();
270	sc->rx_mode = BNX2X_RX_MODE_NORMAL;
271	bnx2x_set_rx_mode(sc);
272}
273
274static void
275bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev)
276{
277	struct bnx2x_softc *sc = dev->data->dev_private;
278
279	PMD_INIT_FUNC_TRACE();
280	sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
281	bnx2x_set_rx_mode(sc);
282}
283
284static void
285bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev)
286{
287	struct bnx2x_softc *sc = dev->data->dev_private;
288
289	PMD_INIT_FUNC_TRACE();
290	sc->rx_mode = BNX2X_RX_MODE_NORMAL;
291	bnx2x_set_rx_mode(sc);
292}
293
294static int
295bnx2x_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
296{
297	PMD_INIT_FUNC_TRACE();
298
299	int old_link_status = dev->data->dev_link.link_status;
300
301	bnx2x_link_update(dev);
302
303	return old_link_status == dev->data->dev_link.link_status ? -1 : 0;
304}
305
306static int
307bnx2xvf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
308{
309	int old_link_status = dev->data->dev_link.link_status;
310	struct bnx2x_softc *sc = dev->data->dev_private;
311
312	bnx2x_link_update(dev);
313
314	bnx2x_check_bull(sc);
315	if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
316		PMD_DRV_LOG(ERR, "PF indicated channel is down."
317				"VF device is no longer operational");
318		dev->data->dev_link.link_status = ETH_LINK_DOWN;
319	}
320
321	return old_link_status == dev->data->dev_link.link_status ? -1 : 0;
322}
323
324static void
325bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
326{
327	struct bnx2x_softc *sc = dev->data->dev_private;
328	uint32_t brb_truncate_discard;
329	uint64_t brb_drops;
330	uint64_t brb_truncates;
331
332	PMD_INIT_FUNC_TRACE();
333
334	bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
335
336	memset(stats, 0, sizeof (struct rte_eth_stats));
337
338	stats->ipackets =
339		HILO_U64(sc->eth_stats.total_unicast_packets_received_hi,
340				sc->eth_stats.total_unicast_packets_received_lo) +
341		HILO_U64(sc->eth_stats.total_multicast_packets_received_hi,
342				sc->eth_stats.total_multicast_packets_received_lo) +
343		HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi,
344				sc->eth_stats.total_broadcast_packets_received_lo);
345
346	stats->opackets =
347		HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi,
348				sc->eth_stats.total_unicast_packets_transmitted_lo) +
349		HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi,
350				sc->eth_stats.total_multicast_packets_transmitted_lo) +
351		HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi,
352				sc->eth_stats.total_broadcast_packets_transmitted_lo);
353
354	stats->ibytes =
355		HILO_U64(sc->eth_stats.total_bytes_received_hi,
356				sc->eth_stats.total_bytes_received_lo);
357
358	stats->obytes =
359		HILO_U64(sc->eth_stats.total_bytes_transmitted_hi,
360				sc->eth_stats.total_bytes_transmitted_lo);
361
362	stats->ierrors =
363		HILO_U64(sc->eth_stats.error_bytes_received_hi,
364				sc->eth_stats.error_bytes_received_lo);
365
366	stats->oerrors = 0;
367
368	stats->rx_nombuf =
369		HILO_U64(sc->eth_stats.no_buff_discard_hi,
370				sc->eth_stats.no_buff_discard_lo);
371
372	brb_drops =
373		HILO_U64(sc->eth_stats.brb_drop_hi,
374			 sc->eth_stats.brb_drop_lo);
375
376	brb_truncates =
377		HILO_U64(sc->eth_stats.brb_truncate_hi,
378			 sc->eth_stats.brb_truncate_lo);
379
380	brb_truncate_discard = sc->eth_stats.brb_truncate_discard;
381
382	stats->imissed = brb_drops + brb_truncates +
383			 brb_truncate_discard + stats->rx_nombuf;
384}
385
386static int
387bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev,
388		       struct rte_eth_xstat_name *xstats_names,
389		       __rte_unused unsigned limit)
390{
391	unsigned int i, stat_cnt = RTE_DIM(bnx2x_xstats_strings);
392
393	if (xstats_names != NULL)
394		for (i = 0; i < stat_cnt; i++)
395			snprintf(xstats_names[i].name,
396				sizeof(xstats_names[i].name),
397				"%s",
398				bnx2x_xstats_strings[i].name);
399
400	return stat_cnt;
401}
402
403static int
404bnx2x_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
405		     unsigned int n)
406{
407	struct bnx2x_softc *sc = dev->data->dev_private;
408	unsigned int num = RTE_DIM(bnx2x_xstats_strings);
409
410	if (n < num)
411		return num;
412
413	bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
414
415	for (num = 0; num < n; num++) {
416		if (bnx2x_xstats_strings[num].offset_hi !=
417		    bnx2x_xstats_strings[num].offset_lo)
418			xstats[num].value = HILO_U64(
419					  *(uint32_t *)((char *)&sc->eth_stats +
420					  bnx2x_xstats_strings[num].offset_hi),
421					  *(uint32_t *)((char *)&sc->eth_stats +
422					  bnx2x_xstats_strings[num].offset_lo));
423		else
424			xstats[num].value =
425					  *(uint64_t *)((char *)&sc->eth_stats +
426					  bnx2x_xstats_strings[num].offset_lo);
427	}
428
429	return num;
430}
431
432static void
433bnx2x_dev_infos_get(struct rte_eth_dev *dev, __rte_unused struct rte_eth_dev_info *dev_info)
434{
435	struct bnx2x_softc *sc = dev->data->dev_private;
436	dev_info->max_rx_queues  = sc->max_rx_queues;
437	dev_info->max_tx_queues  = sc->max_tx_queues;
438	dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
439	dev_info->max_rx_pktlen  = BNX2X_MAX_RX_PKT_LEN;
440	dev_info->max_mac_addrs  = BNX2X_MAX_MAC_ADDRS;
441	dev_info->speed_capa = ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G;
442}
443
444static void
445bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
446		uint32_t index, uint32_t pool)
447{
448	struct bnx2x_softc *sc = dev->data->dev_private;
449
450	if (sc->mac_ops.mac_addr_add)
451		sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool);
452}
453
454static void
455bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
456{
457	struct bnx2x_softc *sc = dev->data->dev_private;
458
459	if (sc->mac_ops.mac_addr_remove)
460		sc->mac_ops.mac_addr_remove(dev, index);
461}
462
463static const struct eth_dev_ops bnx2x_eth_dev_ops = {
464	.dev_configure                = bnx2x_dev_configure,
465	.dev_start                    = bnx2x_dev_start,
466	.dev_stop                     = bnx2x_dev_stop,
467	.dev_close                    = bnx2x_dev_close,
468	.promiscuous_enable           = bnx2x_promisc_enable,
469	.promiscuous_disable          = bnx2x_promisc_disable,
470	.allmulticast_enable          = bnx2x_dev_allmulticast_enable,
471	.allmulticast_disable         = bnx2x_dev_allmulticast_disable,
472	.link_update                  = bnx2x_dev_link_update,
473	.stats_get                    = bnx2x_dev_stats_get,
474	.xstats_get                   = bnx2x_dev_xstats_get,
475	.xstats_get_names             = bnx2x_get_xstats_names,
476	.dev_infos_get                = bnx2x_dev_infos_get,
477	.rx_queue_setup               = bnx2x_dev_rx_queue_setup,
478	.rx_queue_release             = bnx2x_dev_rx_queue_release,
479	.tx_queue_setup               = bnx2x_dev_tx_queue_setup,
480	.tx_queue_release             = bnx2x_dev_tx_queue_release,
481	.mac_addr_add                 = bnx2x_mac_addr_add,
482	.mac_addr_remove              = bnx2x_mac_addr_remove,
483};
484
485/*
486 * dev_ops for virtual function
487 */
488static const struct eth_dev_ops bnx2xvf_eth_dev_ops = {
489	.dev_configure                = bnx2x_dev_configure,
490	.dev_start                    = bnx2x_dev_start,
491	.dev_stop                     = bnx2x_dev_stop,
492	.dev_close                    = bnx2x_dev_close,
493	.promiscuous_enable           = bnx2x_promisc_enable,
494	.promiscuous_disable          = bnx2x_promisc_disable,
495	.allmulticast_enable          = bnx2x_dev_allmulticast_enable,
496	.allmulticast_disable         = bnx2x_dev_allmulticast_disable,
497	.link_update                  = bnx2xvf_dev_link_update,
498	.stats_get                    = bnx2x_dev_stats_get,
499	.xstats_get                   = bnx2x_dev_xstats_get,
500	.xstats_get_names             = bnx2x_get_xstats_names,
501	.dev_infos_get                = bnx2x_dev_infos_get,
502	.rx_queue_setup               = bnx2x_dev_rx_queue_setup,
503	.rx_queue_release             = bnx2x_dev_rx_queue_release,
504	.tx_queue_setup               = bnx2x_dev_tx_queue_setup,
505	.tx_queue_release             = bnx2x_dev_tx_queue_release,
506	.mac_addr_add                 = bnx2x_mac_addr_add,
507	.mac_addr_remove              = bnx2x_mac_addr_remove,
508};
509
510
511static int
512bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
513{
514	int ret = 0;
515	struct rte_pci_device *pci_dev;
516	struct bnx2x_softc *sc;
517
518	PMD_INIT_FUNC_TRACE();
519
520	eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
521	pci_dev = eth_dev->pci_dev;
522
523	rte_eth_copy_pci_info(eth_dev, pci_dev);
524
525	sc = eth_dev->data->dev_private;
526	sc->pcie_bus    = pci_dev->addr.bus;
527	sc->pcie_device = pci_dev->addr.devid;
528
529	if (is_vf)
530		sc->flags = BNX2X_IS_VF_FLAG;
531
532	sc->devinfo.vendor_id    = pci_dev->id.vendor_id;
533	sc->devinfo.device_id    = pci_dev->id.device_id;
534	sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id;
535	sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id;
536
537	sc->pcie_func = pci_dev->addr.function;
538	sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr;
539	if (is_vf)
540		sc->bar[BAR1].base_addr = (void *)
541			((uintptr_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START);
542	else
543		sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr;
544
545	assert(sc->bar[BAR0].base_addr);
546	assert(sc->bar[BAR1].base_addr);
547
548	bnx2x_load_firmware(sc);
549	assert(sc->firmware);
550
551	if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
552		sc->udp_rss = 1;
553
554	sc->rx_budget = BNX2X_RX_BUDGET;
555	sc->hc_rx_ticks = BNX2X_RX_TICKS;
556	sc->hc_tx_ticks = BNX2X_TX_TICKS;
557
558	sc->interrupt_mode = INTR_MODE_SINGLE_MSIX;
559	sc->rx_mode = BNX2X_RX_MODE_NORMAL;
560
561	sc->pci_dev = pci_dev;
562	ret = bnx2x_attach(sc);
563	if (ret) {
564		PMD_DRV_LOG(ERR, "bnx2x_attach failed (%d)", ret);
565		return ret;
566	}
567
568	eth_dev->data->mac_addrs = (struct ether_addr *)sc->link_params.mac_addr;
569
570	PMD_DRV_LOG(INFO, "pcie_bus=%d, pcie_device=%d",
571			sc->pcie_bus, sc->pcie_device);
572	PMD_DRV_LOG(INFO, "bar0.addr=%p, bar1.addr=%p",
573			sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr);
574	PMD_DRV_LOG(INFO, "port=%d, path=%d, vnic=%d, func=%d",
575			PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc));
576	PMD_DRV_LOG(INFO, "portID=%d vendorID=0x%x deviceID=0x%x",
577			eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id);
578
579	if (IS_VF(sc)) {
580		if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg),
581				    &sc->vf2pf_mbox_mapping, "vf2pf_mbox",
582				    RTE_CACHE_LINE_SIZE) != 0)
583			return -ENOMEM;
584
585		sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *)
586					 sc->vf2pf_mbox_mapping.vaddr;
587
588		if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin),
589				    &sc->pf2vf_bulletin_mapping, "vf2pf_bull",
590				    RTE_CACHE_LINE_SIZE) != 0)
591			return -ENOMEM;
592
593		sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *)
594					     sc->pf2vf_bulletin_mapping.vaddr;
595
596		ret = bnx2x_vf_get_resources(sc, sc->max_tx_queues,
597					     sc->max_rx_queues);
598		if (ret)
599			return ret;
600	}
601
602	return 0;
603}
604
605static int
606eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev)
607{
608	PMD_INIT_FUNC_TRACE();
609	return bnx2x_common_dev_init(eth_dev, 0);
610}
611
612static int
613eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev)
614{
615	PMD_INIT_FUNC_TRACE();
616	return bnx2x_common_dev_init(eth_dev, 1);
617}
618
619static struct eth_driver rte_bnx2x_pmd = {
620	.pci_drv = {
621		.name = "rte_bnx2x_pmd",
622		.id_table = pci_id_bnx2x_map,
623		.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
624	},
625	.eth_dev_init = eth_bnx2x_dev_init,
626	.dev_private_size = sizeof(struct bnx2x_softc),
627};
628
629/*
630 * virtual function driver struct
631 */
632static struct eth_driver rte_bnx2xvf_pmd = {
633	.pci_drv = {
634		.name = "rte_bnx2xvf_pmd",
635		.id_table = pci_id_bnx2xvf_map,
636		.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
637	},
638	.eth_dev_init = eth_bnx2xvf_dev_init,
639	.dev_private_size = sizeof(struct bnx2x_softc),
640};
641
642static int rte_bnx2x_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
643{
644	PMD_INIT_FUNC_TRACE();
645	rte_eth_driver_register(&rte_bnx2x_pmd);
646
647	return 0;
648}
649
650static int rte_bnx2xvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
651{
652	PMD_INIT_FUNC_TRACE();
653	rte_eth_driver_register(&rte_bnx2xvf_pmd);
654
655	return 0;
656}
657
658static struct rte_driver rte_bnx2x_driver = {
659	.type = PMD_PDEV,
660	.init = rte_bnx2x_pmd_init,
661};
662
663static struct rte_driver rte_bnx2xvf_driver = {
664	.type = PMD_PDEV,
665	.init = rte_bnx2xvf_pmd_init,
666};
667
668PMD_REGISTER_DRIVER(rte_bnx2x_driver, bnx2x);
669DRIVER_REGISTER_PCI_TABLE(bnx2x, pci_id_bnx2x_map);
670PMD_REGISTER_DRIVER(rte_bnx2xvf_driver, bnx2xvf);
671DRIVER_REGISTER_PCI_TABLE(bnx2xvf, pci_id_bnx2xvf_map);
672