Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
3 : : * Copyright (c) 2015-2018 Cavium Inc.
4 : : * All rights reserved.
5 : : * www.cavium.com
6 : : */
7 : :
8 : : #include "bnx2x.h"
9 : : #include "bnx2x_rxtx.h"
10 : :
11 : : #include <rte_string_fns.h>
12 : : #include <dev_driver.h>
13 : : #include <ethdev_pci.h>
14 : : #include <rte_alarm.h>
15 : :
16 : : /*
17 : : * The set of PCI devices this driver supports
18 : : */
19 : : #define BROADCOM_PCI_VENDOR_ID 0x14E4
20 : : #define QLOGIC_PCI_VENDOR_ID 0x1077
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(QLOGIC_PCI_VENDOR_ID, CHIP_NUM_57840_4_10) },
29 : : { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_2_20) },
30 : : #ifdef RTE_LIBRTE_BNX2X_MF_SUPPORT
31 : : { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810_MF) },
32 : : { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811_MF) },
33 : : { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_MF) },
34 : : { RTE_PCI_DEVICE(QLOGIC_PCI_VENDOR_ID, CHIP_NUM_57840_MF) },
35 : : #endif
36 : : { .vendor_id = 0, }
37 : : };
38 : :
39 : : static const struct rte_pci_id pci_id_bnx2xvf_map[] = {
40 : : { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57800_VF) },
41 : : { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810_VF) },
42 : : { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811_VF) },
43 : : { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_VF) },
44 : : { RTE_PCI_DEVICE(QLOGIC_PCI_VENDOR_ID, CHIP_NUM_57840_VF) },
45 : : { .vendor_id = 0, }
46 : : };
47 : :
48 : : struct rte_bnx2x_xstats_name_off {
49 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
50 : : uint32_t offset_hi;
51 : : uint32_t offset_lo;
52 : : };
53 : :
54 : : static const struct rte_bnx2x_xstats_name_off bnx2x_xstats_strings[] = {
55 : : {"rx_buffer_drops",
56 : : offsetof(struct bnx2x_eth_stats, brb_drop_hi),
57 : : offsetof(struct bnx2x_eth_stats, brb_drop_lo)},
58 : : {"rx_buffer_truncates",
59 : : offsetof(struct bnx2x_eth_stats, brb_truncate_hi),
60 : : offsetof(struct bnx2x_eth_stats, brb_truncate_lo)},
61 : : {"rx_buffer_truncate_discard",
62 : : offsetof(struct bnx2x_eth_stats, brb_truncate_discard),
63 : : offsetof(struct bnx2x_eth_stats, brb_truncate_discard)},
64 : : {"mac_filter_discard",
65 : : offsetof(struct bnx2x_eth_stats, mac_filter_discard),
66 : : offsetof(struct bnx2x_eth_stats, mac_filter_discard)},
67 : : {"no_match_vlan_tag_discard",
68 : : offsetof(struct bnx2x_eth_stats, mf_tag_discard),
69 : : offsetof(struct bnx2x_eth_stats, mf_tag_discard)},
70 : : {"tx_pause",
71 : : offsetof(struct bnx2x_eth_stats, pause_frames_sent_hi),
72 : : offsetof(struct bnx2x_eth_stats, pause_frames_sent_lo)},
73 : : {"rx_pause",
74 : : offsetof(struct bnx2x_eth_stats, pause_frames_received_hi),
75 : : offsetof(struct bnx2x_eth_stats, pause_frames_received_lo)},
76 : : {"tx_priority_flow_control",
77 : : offsetof(struct bnx2x_eth_stats, pfc_frames_sent_hi),
78 : : offsetof(struct bnx2x_eth_stats, pfc_frames_sent_lo)},
79 : : {"rx_priority_flow_control",
80 : : offsetof(struct bnx2x_eth_stats, pfc_frames_received_hi),
81 : : offsetof(struct bnx2x_eth_stats, pfc_frames_received_lo)}
82 : : };
83 : :
84 : : static int
85 : 0 : bnx2x_link_update(struct rte_eth_dev *dev)
86 : : {
87 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
88 : : struct rte_eth_link link;
89 : :
90 : 0 : PMD_INIT_FUNC_TRACE(sc);
91 : :
92 : : memset(&link, 0, sizeof(link));
93 : : mb();
94 : 0 : link.link_speed = sc->link_vars.line_speed;
95 [ # # ]: 0 : switch (sc->link_vars.duplex) {
96 : 0 : case DUPLEX_FULL:
97 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
98 : 0 : break;
99 : : case DUPLEX_HALF:
100 : : link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
101 : : break;
102 : : }
103 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
104 : : RTE_ETH_LINK_SPEED_FIXED);
105 [ # # ]: 0 : link.link_status = sc->link_vars.link_up;
106 : :
107 : 0 : return rte_eth_linkstatus_set(dev, &link);
108 : : }
109 : :
110 : : static void
111 : 0 : bnx2x_interrupt_action(struct rte_eth_dev *dev, int intr_cxt)
112 : : {
113 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
114 : : uint32_t link_status;
115 : :
116 : 0 : bnx2x_intr_legacy(sc);
117 : :
118 [ # # # # ]: 0 : if ((atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO) &&
119 : : !intr_cxt)
120 : 0 : bnx2x_periodic_callout(sc);
121 : 0 : link_status = REG_RD(sc, sc->link_params.shmem_base +
122 : : offsetof(struct shmem_region,
123 : : port_mb[sc->link_params.port].link_status));
124 [ # # ]: 0 : if ((link_status & LINK_STATUS_LINK_UP) != dev->data->dev_link.link_status)
125 : 0 : bnx2x_link_update(dev);
126 : 0 : }
127 : :
128 : : static void
129 : 0 : bnx2x_interrupt_handler(void *param)
130 : : {
131 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
132 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
133 : :
134 : : PMD_DEBUG_PERIODIC_LOG(INFO, sc, "Interrupt handled");
135 : :
136 : 0 : bnx2x_interrupt_action(dev, 1);
137 : 0 : rte_intr_ack(sc->pci_dev->intr_handle);
138 : 0 : }
139 : :
140 : 0 : static void bnx2x_periodic_start(void *param)
141 : : {
142 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
143 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
144 : : int ret = 0;
145 : :
146 : 0 : atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
147 : 0 : bnx2x_interrupt_action(dev, 0);
148 [ # # ]: 0 : if (IS_PF(sc)) {
149 : 0 : ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD,
150 : : bnx2x_periodic_start, (void *)dev);
151 [ # # ]: 0 : if (ret) {
152 : 0 : PMD_DRV_LOG(ERR, sc, "Unable to start periodic"
153 : : " timer rc %d", ret);
154 : : }
155 : : }
156 : 0 : }
157 : :
158 : 0 : void bnx2x_periodic_stop(void *param)
159 : : {
160 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
161 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
162 : :
163 : 0 : atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
164 : :
165 : 0 : rte_eal_alarm_cancel(bnx2x_periodic_start, (void *)dev);
166 : :
167 : 0 : PMD_DRV_LOG(DEBUG, sc, "Periodic poll stopped");
168 : 0 : }
169 : :
170 : : /*
171 : : * Devops - helper functions can be called from user application
172 : : */
173 : :
174 : : static int
175 : 0 : bnx2x_dev_configure(struct rte_eth_dev *dev)
176 : : {
177 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
178 : :
179 : 0 : int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF);
180 : :
181 : 0 : PMD_INIT_FUNC_TRACE(sc);
182 : :
183 : 0 : sc->mtu = dev->data->dev_conf.rxmode.mtu;
184 : :
185 [ # # ]: 0 : if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) {
186 : 0 : PMD_DRV_LOG(ERR, sc, "The number of TX queues is greater than number of RX queues");
187 : 0 : return -EINVAL;
188 : : }
189 : :
190 : 0 : sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
191 [ # # ]: 0 : if (sc->num_queues > mp_ncpus) {
192 : 0 : PMD_DRV_LOG(ERR, sc, "The number of queues is more than number of CPUs");
193 : 0 : return -EINVAL;
194 : : }
195 : :
196 : 0 : PMD_DRV_LOG(DEBUG, sc, "num_queues=%d, mtu=%d",
197 : : sc->num_queues, sc->mtu);
198 : :
199 : : /* allocate ilt */
200 [ # # ]: 0 : if (bnx2x_alloc_ilt_mem(sc) != 0) {
201 : 0 : PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_ilt_mem was failed");
202 : 0 : return -ENXIO;
203 : : }
204 : :
205 : 0 : bnx2x_dev_rxtx_init_dummy(dev);
206 : 0 : return 0;
207 : : }
208 : :
209 : : static int
210 : 0 : bnx2x_dev_start(struct rte_eth_dev *dev)
211 : : {
212 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
213 : : int ret = 0;
214 : : uint16_t i;
215 : :
216 : 0 : PMD_INIT_FUNC_TRACE(sc);
217 : :
218 : : /* start the periodic callout */
219 [ # # ]: 0 : if (IS_PF(sc)) {
220 [ # # ]: 0 : if (atomic_load_acq_long(&sc->periodic_flags) ==
221 : : PERIODIC_STOP) {
222 : 0 : bnx2x_periodic_start(dev);
223 : 0 : PMD_DRV_LOG(DEBUG, sc, "Periodic poll re-started");
224 : : }
225 : : }
226 : :
227 : 0 : ret = bnx2x_init(sc);
228 [ # # ]: 0 : if (ret) {
229 : 0 : PMD_DRV_LOG(DEBUG, sc, "bnx2x_init failed (%d)", ret);
230 : 0 : return -1;
231 : : }
232 : :
233 [ # # ]: 0 : if (IS_PF(sc)) {
234 : 0 : rte_intr_callback_register(sc->pci_dev->intr_handle,
235 : : bnx2x_interrupt_handler, (void *)dev);
236 : :
237 [ # # ]: 0 : if (rte_intr_enable(sc->pci_dev->intr_handle))
238 : 0 : PMD_DRV_LOG(ERR, sc, "rte_intr_enable failed");
239 : : }
240 : :
241 : : /* Configure the previously stored Multicast address list */
242 [ # # ]: 0 : if (IS_VF(sc))
243 : 0 : bnx2x_vfpf_set_mcast(sc, sc->mc_addrs, sc->mc_addrs_num);
244 : 0 : bnx2x_dev_rxtx_init(dev);
245 : :
246 : 0 : bnx2x_print_device_info(sc);
247 : :
248 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
249 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
250 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
251 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
252 : :
253 : : return ret;
254 : : }
255 : :
256 : : static int
257 : 0 : bnx2x_dev_stop(struct rte_eth_dev *dev)
258 : : {
259 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
260 : : int ret = 0;
261 : : uint16_t i;
262 : :
263 : 0 : PMD_INIT_FUNC_TRACE(sc);
264 : :
265 : 0 : bnx2x_dev_rxtx_init_dummy(dev);
266 : :
267 [ # # ]: 0 : if (IS_PF(sc)) {
268 : 0 : rte_intr_disable(sc->pci_dev->intr_handle);
269 : 0 : rte_intr_callback_unregister(sc->pci_dev->intr_handle,
270 : : bnx2x_interrupt_handler, (void *)dev);
271 : :
272 : : /* stop the periodic callout */
273 : 0 : bnx2x_periodic_stop(dev);
274 : : }
275 : : /* Remove the configured Multicast list
276 : : * Sending NULL for the list of address and the
277 : : * Number is set to 0 denoting DEL_CMD
278 : : */
279 [ # # ]: 0 : if (IS_VF(sc))
280 : 0 : bnx2x_vfpf_set_mcast(sc, NULL, 0);
281 : 0 : ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE);
282 [ # # ]: 0 : if (ret) {
283 : 0 : PMD_DRV_LOG(DEBUG, sc, "bnx2x_nic_unload failed (%d)", ret);
284 : 0 : return ret;
285 : : }
286 : :
287 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
288 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
289 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
290 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
291 : :
292 : : return 0;
293 : : }
294 : :
295 : : static int
296 : 0 : bnx2x_dev_close(struct rte_eth_dev *dev)
297 : : {
298 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
299 : :
300 : 0 : PMD_INIT_FUNC_TRACE(sc);
301 : :
302 : : /* only close in case of the primary process */
303 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
304 : : return 0;
305 : :
306 [ # # ]: 0 : if (IS_VF(sc))
307 : 0 : bnx2x_vf_close(sc);
308 : :
309 : 0 : bnx2x_dev_clear_queues(dev);
310 : 0 : memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link));
311 : :
312 : : /* free ilt */
313 : 0 : bnx2x_free_ilt_mem(sc);
314 : :
315 : : /* mac_addrs must not be freed alone because part of dev_private */
316 : 0 : dev->data->mac_addrs = NULL;
317 : :
318 : 0 : return 0;
319 : : }
320 : :
321 : : static int
322 : 0 : bnx2x_promisc_enable(struct rte_eth_dev *dev)
323 : : {
324 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
325 : :
326 : 0 : PMD_INIT_FUNC_TRACE(sc);
327 : 0 : sc->rx_mode = BNX2X_RX_MODE_PROMISC;
328 [ # # ]: 0 : if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
329 : 0 : sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
330 : 0 : bnx2x_set_rx_mode(sc);
331 : :
332 : 0 : return 0;
333 : : }
334 : :
335 : : static int
336 : 0 : bnx2x_promisc_disable(struct rte_eth_dev *dev)
337 : : {
338 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
339 : :
340 : 0 : PMD_INIT_FUNC_TRACE(sc);
341 : 0 : sc->rx_mode = BNX2X_RX_MODE_NORMAL;
342 [ # # ]: 0 : if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
343 : 0 : sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
344 : 0 : bnx2x_set_rx_mode(sc);
345 : :
346 : 0 : return 0;
347 : : }
348 : :
349 : : static int
350 : 0 : bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev)
351 : : {
352 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
353 : :
354 : 0 : PMD_INIT_FUNC_TRACE(sc);
355 : 0 : sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
356 [ # # ]: 0 : if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
357 : 0 : sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
358 : 0 : bnx2x_set_rx_mode(sc);
359 : :
360 : 0 : return 0;
361 : : }
362 : :
363 : : static int
364 : 0 : bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev)
365 : : {
366 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
367 : :
368 : 0 : PMD_INIT_FUNC_TRACE(sc);
369 : 0 : sc->rx_mode = BNX2X_RX_MODE_NORMAL;
370 [ # # ]: 0 : if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
371 : 0 : sc->rx_mode = BNX2X_RX_MODE_PROMISC;
372 : 0 : bnx2x_set_rx_mode(sc);
373 : :
374 : 0 : return 0;
375 : : }
376 : :
377 : : static int
378 : 0 : bnx2x_dev_set_mc_addr_list(struct rte_eth_dev *dev,
379 : : struct rte_ether_addr *mc_addrs, uint32_t mc_addrs_num)
380 : : {
381 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
382 : : int err;
383 : 0 : PMD_INIT_FUNC_TRACE(sc);
384 : : /* flush previous addresses */
385 : 0 : err = bnx2x_vfpf_set_mcast(sc, NULL, 0);
386 [ # # ]: 0 : if (err)
387 : : return err;
388 : 0 : sc->mc_addrs_num = 0;
389 : :
390 : : /* Add new ones */
391 : 0 : err = bnx2x_vfpf_set_mcast(sc, mc_addrs, mc_addrs_num);
392 [ # # ]: 0 : if (err)
393 : : return err;
394 : :
395 : 0 : sc->mc_addrs_num = mc_addrs_num;
396 : 0 : memcpy(sc->mc_addrs, mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
397 : :
398 : 0 : return 0;
399 : : }
400 : :
401 : : static int
402 : 0 : bnx2x_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
403 : : {
404 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
405 : :
406 : 0 : PMD_INIT_FUNC_TRACE(sc);
407 : :
408 : 0 : return bnx2x_link_update(dev);
409 : : }
410 : :
411 : : static int
412 : 0 : bnx2xvf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
413 : : {
414 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
415 : : int ret = 0;
416 : :
417 : 0 : ret = bnx2x_link_update(dev);
418 : :
419 : 0 : bnx2x_check_bull(sc);
420 [ # # ]: 0 : if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
421 : 0 : PMD_DRV_LOG(ERR, sc, "PF indicated channel is down."
422 : : "VF device is no longer operational");
423 : 0 : dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN;
424 : : }
425 : :
426 : 0 : return ret;
427 : : }
428 : :
429 : : static int
430 : 0 : bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
431 : : struct eth_queue_stats *qstats __rte_unused)
432 : : {
433 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
434 : : uint32_t brb_truncate_discard;
435 : : uint64_t brb_drops;
436 : : uint64_t brb_truncates;
437 : :
438 : 0 : PMD_INIT_FUNC_TRACE(sc);
439 : :
440 : 0 : bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
441 : :
442 : : memset(stats, 0, sizeof (struct rte_eth_stats));
443 : :
444 : 0 : stats->ipackets =
445 : 0 : HILO_U64(sc->eth_stats.total_unicast_packets_received_hi,
446 : 0 : sc->eth_stats.total_unicast_packets_received_lo) +
447 : 0 : HILO_U64(sc->eth_stats.total_multicast_packets_received_hi,
448 : 0 : sc->eth_stats.total_multicast_packets_received_lo) +
449 : 0 : HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi,
450 : : sc->eth_stats.total_broadcast_packets_received_lo);
451 : :
452 : 0 : stats->opackets =
453 : 0 : HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi,
454 : 0 : sc->eth_stats.total_unicast_packets_transmitted_lo) +
455 : 0 : HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi,
456 : 0 : sc->eth_stats.total_multicast_packets_transmitted_lo) +
457 : 0 : HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi,
458 : : sc->eth_stats.total_broadcast_packets_transmitted_lo);
459 : :
460 : 0 : stats->ibytes =
461 : 0 : HILO_U64(sc->eth_stats.total_bytes_received_hi,
462 : : sc->eth_stats.total_bytes_received_lo);
463 : :
464 : 0 : stats->obytes =
465 : 0 : HILO_U64(sc->eth_stats.total_bytes_transmitted_hi,
466 : : sc->eth_stats.total_bytes_transmitted_lo);
467 : :
468 : 0 : stats->ierrors =
469 : 0 : HILO_U64(sc->eth_stats.error_bytes_received_hi,
470 : : sc->eth_stats.error_bytes_received_lo);
471 : :
472 : : stats->oerrors = 0;
473 : :
474 : 0 : stats->rx_nombuf =
475 : 0 : HILO_U64(sc->eth_stats.no_buff_discard_hi,
476 : : sc->eth_stats.no_buff_discard_lo);
477 : :
478 : 0 : brb_drops =
479 : 0 : HILO_U64(sc->eth_stats.brb_drop_hi,
480 : : sc->eth_stats.brb_drop_lo);
481 : :
482 : 0 : brb_truncates =
483 : 0 : HILO_U64(sc->eth_stats.brb_truncate_hi,
484 : : sc->eth_stats.brb_truncate_lo);
485 : :
486 : 0 : brb_truncate_discard = sc->eth_stats.brb_truncate_discard;
487 : :
488 : 0 : stats->imissed = brb_drops + brb_truncates +
489 : 0 : brb_truncate_discard + stats->rx_nombuf;
490 : :
491 : 0 : return 0;
492 : : }
493 : :
494 : : static int
495 : 0 : bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev,
496 : : struct rte_eth_xstat_name *xstats_names,
497 : : __rte_unused unsigned limit)
498 : : {
499 : : unsigned int i, stat_cnt = RTE_DIM(bnx2x_xstats_strings);
500 : :
501 [ # # ]: 0 : if (xstats_names != NULL)
502 [ # # ]: 0 : for (i = 0; i < stat_cnt; i++)
503 : 0 : strlcpy(xstats_names[i].name,
504 : : bnx2x_xstats_strings[i].name,
505 : : sizeof(xstats_names[i].name));
506 : :
507 : 0 : return stat_cnt;
508 : : }
509 : :
510 : : static int
511 : 0 : bnx2x_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
512 : : unsigned int n)
513 : : {
514 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
515 : : unsigned int num = RTE_DIM(bnx2x_xstats_strings);
516 : :
517 [ # # ]: 0 : if (n < num)
518 : : return num;
519 : :
520 : 0 : bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
521 : :
522 [ # # ]: 0 : for (num = 0; num < n; num++) {
523 : 0 : if (bnx2x_xstats_strings[num].offset_hi !=
524 [ # # ]: 0 : bnx2x_xstats_strings[num].offset_lo)
525 : 0 : xstats[num].value = HILO_U64(
526 : : *(uint32_t *)((char *)&sc->eth_stats +
527 : : bnx2x_xstats_strings[num].offset_hi),
528 : : *(uint32_t *)((char *)&sc->eth_stats +
529 : : bnx2x_xstats_strings[num].offset_lo));
530 : : else
531 : 0 : xstats[num].value =
532 : 0 : *(uint64_t *)((char *)&sc->eth_stats +
533 : 0 : bnx2x_xstats_strings[num].offset_lo);
534 : 0 : xstats[num].id = num;
535 : : }
536 : :
537 : : return num;
538 : : }
539 : :
540 : : static int
541 : 0 : bnx2x_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
542 : : {
543 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
544 : :
545 : 0 : dev_info->max_rx_queues = sc->max_rx_queues;
546 : 0 : dev_info->max_tx_queues = sc->max_tx_queues;
547 : 0 : dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
548 : 0 : dev_info->max_rx_pktlen = BNX2X_MAX_RX_PKT_LEN;
549 : 0 : dev_info->max_mac_addrs = BNX2X_MAX_MAC_ADDRS;
550 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_20G;
551 : :
552 : 0 : dev_info->rx_desc_lim.nb_max = MAX_RX_AVAIL;
553 [ # # # # : 0 : dev_info->rx_desc_lim.nb_min = MIN_RX_SIZE_NONTPA;
# # ]
554 : 0 : dev_info->rx_desc_lim.nb_mtu_seg_max = 1;
555 : 0 : dev_info->tx_desc_lim.nb_max = MAX_TX_AVAIL;
556 : :
557 : 0 : return 0;
558 : : }
559 : :
560 : : static int
561 : 0 : bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
562 : : uint32_t index, uint32_t pool)
563 : : {
564 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
565 : :
566 [ # # ]: 0 : if (sc->mac_ops.mac_addr_add) {
567 : 0 : sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool);
568 : 0 : return 0;
569 : : }
570 : : return -ENOTSUP;
571 : : }
572 : :
573 : : static void
574 : 0 : bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
575 : : {
576 : 0 : struct bnx2x_softc *sc = dev->data->dev_private;
577 : :
578 [ # # ]: 0 : if (sc->mac_ops.mac_addr_remove)
579 : 0 : sc->mac_ops.mac_addr_remove(dev, index);
580 : 0 : }
581 : :
582 : : static const struct eth_dev_ops bnx2x_eth_dev_ops = {
583 : : .dev_configure = bnx2x_dev_configure,
584 : : .dev_start = bnx2x_dev_start,
585 : : .dev_stop = bnx2x_dev_stop,
586 : : .dev_close = bnx2x_dev_close,
587 : : .promiscuous_enable = bnx2x_promisc_enable,
588 : : .promiscuous_disable = bnx2x_promisc_disable,
589 : : .allmulticast_enable = bnx2x_dev_allmulticast_enable,
590 : : .allmulticast_disable = bnx2x_dev_allmulticast_disable,
591 : : .link_update = bnx2x_dev_link_update,
592 : : .stats_get = bnx2x_dev_stats_get,
593 : : .xstats_get = bnx2x_dev_xstats_get,
594 : : .xstats_get_names = bnx2x_get_xstats_names,
595 : : .dev_infos_get = bnx2x_dev_infos_get,
596 : : .rx_queue_setup = bnx2x_dev_rx_queue_setup,
597 : : .rx_queue_release = bnx2x_dev_rx_queue_release,
598 : : .tx_queue_setup = bnx2x_dev_tx_queue_setup,
599 : : .tx_queue_release = bnx2x_dev_tx_queue_release,
600 : : .mac_addr_add = bnx2x_mac_addr_add,
601 : : .mac_addr_remove = bnx2x_mac_addr_remove,
602 : : };
603 : :
604 : : /*
605 : : * dev_ops for virtual function
606 : : */
607 : : static const struct eth_dev_ops bnx2xvf_eth_dev_ops = {
608 : : .dev_configure = bnx2x_dev_configure,
609 : : .dev_start = bnx2x_dev_start,
610 : : .dev_stop = bnx2x_dev_stop,
611 : : .dev_close = bnx2x_dev_close,
612 : : .promiscuous_enable = bnx2x_promisc_enable,
613 : : .promiscuous_disable = bnx2x_promisc_disable,
614 : : .allmulticast_enable = bnx2x_dev_allmulticast_enable,
615 : : .allmulticast_disable = bnx2x_dev_allmulticast_disable,
616 : : .set_mc_addr_list = bnx2x_dev_set_mc_addr_list,
617 : : .link_update = bnx2xvf_dev_link_update,
618 : : .stats_get = bnx2x_dev_stats_get,
619 : : .xstats_get = bnx2x_dev_xstats_get,
620 : : .xstats_get_names = bnx2x_get_xstats_names,
621 : : .dev_infos_get = bnx2x_dev_infos_get,
622 : : .rx_queue_setup = bnx2x_dev_rx_queue_setup,
623 : : .rx_queue_release = bnx2x_dev_rx_queue_release,
624 : : .tx_queue_setup = bnx2x_dev_tx_queue_setup,
625 : : .tx_queue_release = bnx2x_dev_tx_queue_release,
626 : : .mac_addr_add = bnx2x_mac_addr_add,
627 : : .mac_addr_remove = bnx2x_mac_addr_remove,
628 : : };
629 : :
630 : :
631 : : static int
632 : 0 : bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
633 : : {
634 : : int ret = 0;
635 : : struct rte_pci_device *pci_dev;
636 : : struct rte_pci_addr pci_addr;
637 : : struct bnx2x_softc *sc;
638 : : static bool adapter_info = true;
639 : :
640 : : /* Extract key data structures */
641 : 0 : sc = eth_dev->data->dev_private;
642 : 0 : pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
643 : 0 : pci_addr = pci_dev->addr;
644 : :
645 : 0 : snprintf(sc->devinfo.name, NAME_SIZE, PCI_SHORT_PRI_FMT ":dpdk-port-%u",
646 : : pci_addr.bus, pci_addr.devid, pci_addr.function,
647 : 0 : eth_dev->data->port_id);
648 : :
649 : 0 : PMD_INIT_FUNC_TRACE(sc);
650 : :
651 [ # # ]: 0 : eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
652 : :
653 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
654 : 0 : PMD_DRV_LOG(ERR, sc, "Skipping device init from secondary process");
655 : 0 : return 0;
656 : : }
657 : :
658 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
659 : :
660 : 0 : sc->pcie_bus = pci_dev->addr.bus;
661 : 0 : sc->pcie_device = pci_dev->addr.devid;
662 : :
663 : 0 : sc->devinfo.vendor_id = pci_dev->id.vendor_id;
664 : 0 : sc->devinfo.device_id = pci_dev->id.device_id;
665 : 0 : sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id;
666 : 0 : sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id;
667 : :
668 [ # # ]: 0 : if (is_vf)
669 : 0 : sc->flags = BNX2X_IS_VF_FLAG;
670 : :
671 : 0 : sc->pcie_func = pci_dev->addr.function;
672 : 0 : sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr;
673 [ # # ]: 0 : if (is_vf)
674 : 0 : sc->bar[BAR1].base_addr = (void *)
675 : 0 : ((uintptr_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START);
676 : : else
677 : 0 : sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr;
678 : :
679 [ # # ]: 0 : assert(sc->bar[BAR0].base_addr);
680 [ # # ]: 0 : assert(sc->bar[BAR1].base_addr);
681 : :
682 : 0 : bnx2x_load_firmware(sc);
683 [ # # ]: 0 : assert(sc->firmware);
684 : :
685 [ # # ]: 0 : if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
686 : 0 : sc->udp_rss = 1;
687 : :
688 : 0 : sc->rx_budget = BNX2X_RX_BUDGET;
689 : 0 : sc->hc_rx_ticks = BNX2X_RX_TICKS;
690 : 0 : sc->hc_tx_ticks = BNX2X_TX_TICKS;
691 : :
692 : 0 : sc->interrupt_mode = INTR_MODE_SINGLE_MSIX;
693 : 0 : sc->rx_mode = BNX2X_RX_MODE_NORMAL;
694 : :
695 : 0 : sc->pci_dev = pci_dev;
696 : 0 : ret = bnx2x_attach(sc);
697 [ # # ]: 0 : if (ret) {
698 : 0 : PMD_DRV_LOG(ERR, sc, "bnx2x_attach failed (%d)", ret);
699 : 0 : return ret;
700 : : }
701 : :
702 : : /* Print important adapter info for the user. */
703 [ # # ]: 0 : if (adapter_info) {
704 : 0 : bnx2x_print_adapter_info(sc);
705 : 0 : adapter_info = false;
706 : : }
707 : :
708 : : /* schedule periodic poll for slowpath link events */
709 [ # # ]: 0 : if (IS_PF(sc)) {
710 : 0 : PMD_DRV_LOG(DEBUG, sc, "Scheduling periodic poll for slowpath link events");
711 : 0 : ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD,
712 : : bnx2x_periodic_start, (void *)eth_dev);
713 [ # # ]: 0 : if (ret) {
714 : 0 : PMD_DRV_LOG(ERR, sc, "Unable to start periodic"
715 : : " timer rc %d", ret);
716 : 0 : return -EINVAL;
717 : : }
718 : : }
719 : :
720 : 0 : eth_dev->data->mac_addrs =
721 : 0 : (struct rte_ether_addr *)sc->link_params.mac_addr;
722 : :
723 [ # # ]: 0 : if (IS_VF(sc)) {
724 : : rte_spinlock_init(&sc->vf2pf_lock);
725 : :
726 : 0 : ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg),
727 : : &sc->vf2pf_mbox_mapping, "vf2pf_mbox",
728 : : RTE_CACHE_LINE_SIZE);
729 [ # # ]: 0 : if (ret)
730 : 0 : goto out;
731 : :
732 : 0 : sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *)
733 : 0 : sc->vf2pf_mbox_mapping.vaddr;
734 : :
735 : 0 : ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin),
736 : : &sc->pf2vf_bulletin_mapping, "vf2pf_bull",
737 : : RTE_CACHE_LINE_SIZE);
738 [ # # ]: 0 : if (ret)
739 : 0 : goto out;
740 : :
741 : 0 : sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *)
742 : 0 : sc->pf2vf_bulletin_mapping.vaddr;
743 : :
744 : 0 : ret = bnx2x_vf_get_resources(sc, sc->max_tx_queues,
745 : 0 : sc->max_rx_queues);
746 [ # # ]: 0 : if (ret)
747 : 0 : goto out;
748 : : }
749 : :
750 : : return 0;
751 : :
752 : 0 : out:
753 [ # # ]: 0 : if (IS_PF(sc))
754 : 0 : bnx2x_periodic_stop(eth_dev);
755 : :
756 : : return ret;
757 : : }
758 : :
759 : : static int
760 : 0 : eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev)
761 : : {
762 : 0 : struct bnx2x_softc *sc = eth_dev->data->dev_private;
763 : 0 : PMD_INIT_FUNC_TRACE(sc);
764 : 0 : return bnx2x_common_dev_init(eth_dev, 0);
765 : : }
766 : :
767 : : static int
768 : 0 : eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev)
769 : : {
770 : 0 : struct bnx2x_softc *sc = eth_dev->data->dev_private;
771 : 0 : PMD_INIT_FUNC_TRACE(sc);
772 : 0 : return bnx2x_common_dev_init(eth_dev, 1);
773 : : }
774 : :
775 : 0 : static int eth_bnx2x_dev_uninit(struct rte_eth_dev *eth_dev)
776 : : {
777 : 0 : struct bnx2x_softc *sc = eth_dev->data->dev_private;
778 : 0 : PMD_INIT_FUNC_TRACE(sc);
779 : 0 : bnx2x_dev_close(eth_dev);
780 : 0 : return 0;
781 : : }
782 : :
783 : : static struct rte_pci_driver rte_bnx2x_pmd;
784 : : static struct rte_pci_driver rte_bnx2xvf_pmd;
785 : :
786 : 0 : static int eth_bnx2x_pci_probe(struct rte_pci_driver *pci_drv,
787 : : struct rte_pci_device *pci_dev)
788 : : {
789 [ # # ]: 0 : if (pci_drv == &rte_bnx2x_pmd)
790 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
791 : : sizeof(struct bnx2x_softc), eth_bnx2x_dev_init);
792 [ # # ]: 0 : else if (pci_drv == &rte_bnx2xvf_pmd)
793 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
794 : : sizeof(struct bnx2x_softc), eth_bnx2xvf_dev_init);
795 : : else
796 : : return -EINVAL;
797 : : }
798 : :
799 : 0 : static int eth_bnx2x_pci_remove(struct rte_pci_device *pci_dev)
800 : : {
801 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_bnx2x_dev_uninit);
802 : : }
803 : :
804 : : static struct rte_pci_driver rte_bnx2x_pmd = {
805 : : .id_table = pci_id_bnx2x_map,
806 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
807 : : .probe = eth_bnx2x_pci_probe,
808 : : .remove = eth_bnx2x_pci_remove,
809 : : };
810 : :
811 : : /*
812 : : * virtual function driver struct
813 : : */
814 : : static struct rte_pci_driver rte_bnx2xvf_pmd = {
815 : : .id_table = pci_id_bnx2xvf_map,
816 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
817 : : .probe = eth_bnx2x_pci_probe,
818 : : .remove = eth_bnx2x_pci_remove,
819 : : };
820 : :
821 : 253 : RTE_PMD_REGISTER_PCI(net_bnx2x, rte_bnx2x_pmd);
822 : : RTE_PMD_REGISTER_PCI_TABLE(net_bnx2x, pci_id_bnx2x_map);
823 : : RTE_PMD_REGISTER_KMOD_DEP(net_bnx2x, "* igb_uio | uio_pci_generic | vfio-pci");
824 : 253 : RTE_PMD_REGISTER_PCI(net_bnx2xvf, rte_bnx2xvf_pmd);
825 : : RTE_PMD_REGISTER_PCI_TABLE(net_bnx2xvf, pci_id_bnx2xvf_map);
826 : : RTE_PMD_REGISTER_KMOD_DEP(net_bnx2xvf, "* igb_uio | vfio-pci");
827 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(bnx2x_logtype_init, init, NOTICE);
828 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(bnx2x_logtype_driver, driver, NOTICE);
|