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