1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 * Copyright(c) 2018-2019 Pensando Systems, Inc. All rights reserved.
6 #include <rte_bus_pci.h>
7 #include <rte_ethdev.h>
8 #include <rte_ethdev_driver.h>
9 #include <rte_malloc.h>
10 #include <rte_ethdev_pci.h>
12 #include "ionic_logs.h"
14 #include "ionic_dev.h"
15 #include "ionic_mac_api.h"
16 #include "ionic_lif.h"
17 #include "ionic_ethdev.h"
18 #include "ionic_rxtx.h"
20 static int eth_ionic_dev_init(struct rte_eth_dev *eth_dev, void *init_params);
21 static int eth_ionic_dev_uninit(struct rte_eth_dev *eth_dev);
22 static int ionic_dev_info_get(struct rte_eth_dev *eth_dev,
23 struct rte_eth_dev_info *dev_info);
24 static int ionic_dev_configure(struct rte_eth_dev *dev);
25 static int ionic_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
26 static int ionic_dev_start(struct rte_eth_dev *dev);
27 static int ionic_dev_stop(struct rte_eth_dev *dev);
28 static int ionic_dev_close(struct rte_eth_dev *dev);
29 static int ionic_dev_set_link_up(struct rte_eth_dev *dev);
30 static int ionic_dev_set_link_down(struct rte_eth_dev *dev);
31 static int ionic_dev_link_update(struct rte_eth_dev *eth_dev,
32 int wait_to_complete);
33 static int ionic_flow_ctrl_get(struct rte_eth_dev *eth_dev,
34 struct rte_eth_fc_conf *fc_conf);
35 static int ionic_flow_ctrl_set(struct rte_eth_dev *eth_dev,
36 struct rte_eth_fc_conf *fc_conf);
37 static int ionic_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask);
38 static int ionic_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
39 struct rte_eth_rss_reta_entry64 *reta_conf, uint16_t reta_size);
40 static int ionic_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
41 struct rte_eth_rss_reta_entry64 *reta_conf, uint16_t reta_size);
42 static int ionic_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
43 struct rte_eth_rss_conf *rss_conf);
44 static int ionic_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
45 struct rte_eth_rss_conf *rss_conf);
46 static int ionic_dev_stats_get(struct rte_eth_dev *eth_dev,
47 struct rte_eth_stats *stats);
48 static int ionic_dev_stats_reset(struct rte_eth_dev *eth_dev);
49 static int ionic_dev_xstats_get(struct rte_eth_dev *dev,
50 struct rte_eth_xstat *xstats, unsigned int n);
51 static int ionic_dev_xstats_get_by_id(struct rte_eth_dev *dev,
52 const uint64_t *ids, uint64_t *values, unsigned int n);
53 static int ionic_dev_xstats_reset(struct rte_eth_dev *dev);
54 static int ionic_dev_xstats_get_names(struct rte_eth_dev *dev,
55 struct rte_eth_xstat_name *xstats_names, unsigned int size);
56 static int ionic_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
57 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
59 static int ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev,
60 char *fw_version, size_t fw_size);
62 static const struct rte_pci_id pci_id_ionic_map[] = {
63 { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_PF) },
64 { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_VF) },
65 { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_MGMT) },
66 { .vendor_id = 0, /* sentinel */ },
69 static const struct rte_eth_desc_lim rx_desc_lim = {
70 .nb_max = IONIC_MAX_RING_DESC,
71 .nb_min = IONIC_MIN_RING_DESC,
75 static const struct rte_eth_desc_lim tx_desc_lim = {
76 .nb_max = IONIC_MAX_RING_DESC,
77 .nb_min = IONIC_MIN_RING_DESC,
79 .nb_seg_max = IONIC_TX_MAX_SG_ELEMS,
80 .nb_mtu_seg_max = IONIC_TX_MAX_SG_ELEMS,
83 static const struct eth_dev_ops ionic_eth_dev_ops = {
84 .dev_infos_get = ionic_dev_info_get,
85 .dev_configure = ionic_dev_configure,
86 .mtu_set = ionic_dev_mtu_set,
87 .dev_start = ionic_dev_start,
88 .dev_stop = ionic_dev_stop,
89 .dev_close = ionic_dev_close,
90 .link_update = ionic_dev_link_update,
91 .dev_set_link_up = ionic_dev_set_link_up,
92 .dev_set_link_down = ionic_dev_set_link_down,
93 .mac_addr_add = ionic_dev_add_mac,
94 .mac_addr_remove = ionic_dev_remove_mac,
95 .mac_addr_set = ionic_dev_set_mac,
96 .vlan_filter_set = ionic_dev_vlan_filter_set,
97 .promiscuous_enable = ionic_dev_promiscuous_enable,
98 .promiscuous_disable = ionic_dev_promiscuous_disable,
99 .allmulticast_enable = ionic_dev_allmulticast_enable,
100 .allmulticast_disable = ionic_dev_allmulticast_disable,
101 .flow_ctrl_get = ionic_flow_ctrl_get,
102 .flow_ctrl_set = ionic_flow_ctrl_set,
103 .rxq_info_get = ionic_rxq_info_get,
104 .txq_info_get = ionic_txq_info_get,
105 .rx_queue_setup = ionic_dev_rx_queue_setup,
106 .rx_queue_release = ionic_dev_rx_queue_release,
107 .rx_queue_start = ionic_dev_rx_queue_start,
108 .rx_queue_stop = ionic_dev_rx_queue_stop,
109 .tx_queue_setup = ionic_dev_tx_queue_setup,
110 .tx_queue_release = ionic_dev_tx_queue_release,
111 .tx_queue_start = ionic_dev_tx_queue_start,
112 .tx_queue_stop = ionic_dev_tx_queue_stop,
113 .vlan_offload_set = ionic_vlan_offload_set,
114 .reta_update = ionic_dev_rss_reta_update,
115 .reta_query = ionic_dev_rss_reta_query,
116 .rss_hash_conf_get = ionic_dev_rss_hash_conf_get,
117 .rss_hash_update = ionic_dev_rss_hash_update,
118 .stats_get = ionic_dev_stats_get,
119 .stats_reset = ionic_dev_stats_reset,
120 .xstats_get = ionic_dev_xstats_get,
121 .xstats_get_by_id = ionic_dev_xstats_get_by_id,
122 .xstats_reset = ionic_dev_xstats_reset,
123 .xstats_get_names = ionic_dev_xstats_get_names,
124 .xstats_get_names_by_id = ionic_dev_xstats_get_names_by_id,
125 .fw_version_get = ionic_dev_fw_version_get,
128 struct rte_ionic_xstats_name_off {
129 char name[RTE_ETH_XSTATS_NAME_SIZE];
133 static const struct rte_ionic_xstats_name_off rte_ionic_xstats_strings[] = {
135 {"rx_ucast_bytes", offsetof(struct ionic_lif_stats,
137 {"rx_ucast_packets", offsetof(struct ionic_lif_stats,
139 {"rx_mcast_bytes", offsetof(struct ionic_lif_stats,
141 {"rx_mcast_packets", offsetof(struct ionic_lif_stats,
143 {"rx_bcast_bytes", offsetof(struct ionic_lif_stats,
145 {"rx_bcast_packets", offsetof(struct ionic_lif_stats,
148 {"rx_ucast_drop_bytes", offsetof(struct ionic_lif_stats,
149 rx_ucast_drop_bytes)},
150 {"rx_ucast_drop_packets", offsetof(struct ionic_lif_stats,
151 rx_ucast_drop_packets)},
152 {"rx_mcast_drop_bytes", offsetof(struct ionic_lif_stats,
153 rx_mcast_drop_bytes)},
154 {"rx_mcast_drop_packets", offsetof(struct ionic_lif_stats,
155 rx_mcast_drop_packets)},
156 {"rx_bcast_drop_bytes", offsetof(struct ionic_lif_stats,
157 rx_bcast_drop_bytes)},
158 {"rx_bcast_drop_packets", offsetof(struct ionic_lif_stats,
159 rx_bcast_drop_packets)},
160 {"rx_dma_error", offsetof(struct ionic_lif_stats,
163 {"tx_ucast_bytes", offsetof(struct ionic_lif_stats,
165 {"tx_ucast_packets", offsetof(struct ionic_lif_stats,
167 {"tx_mcast_bytes", offsetof(struct ionic_lif_stats,
169 {"tx_mcast_packets", offsetof(struct ionic_lif_stats,
171 {"tx_bcast_bytes", offsetof(struct ionic_lif_stats,
173 {"tx_bcast_packets", offsetof(struct ionic_lif_stats,
176 {"tx_ucast_drop_bytes", offsetof(struct ionic_lif_stats,
177 tx_ucast_drop_bytes)},
178 {"tx_ucast_drop_packets", offsetof(struct ionic_lif_stats,
179 tx_ucast_drop_packets)},
180 {"tx_mcast_drop_bytes", offsetof(struct ionic_lif_stats,
181 tx_mcast_drop_bytes)},
182 {"tx_mcast_drop_packets", offsetof(struct ionic_lif_stats,
183 tx_mcast_drop_packets)},
184 {"tx_bcast_drop_bytes", offsetof(struct ionic_lif_stats,
185 tx_bcast_drop_bytes)},
186 {"tx_bcast_drop_packets", offsetof(struct ionic_lif_stats,
187 tx_bcast_drop_packets)},
188 {"tx_dma_error", offsetof(struct ionic_lif_stats,
190 /* Rx Queue/Ring drops */
191 {"rx_queue_disabled", offsetof(struct ionic_lif_stats,
193 {"rx_queue_empty", offsetof(struct ionic_lif_stats,
195 {"rx_queue_error", offsetof(struct ionic_lif_stats,
197 {"rx_desc_fetch_error", offsetof(struct ionic_lif_stats,
198 rx_desc_fetch_error)},
199 {"rx_desc_data_error", offsetof(struct ionic_lif_stats,
200 rx_desc_data_error)},
201 /* Tx Queue/Ring drops */
202 {"tx_queue_disabled", offsetof(struct ionic_lif_stats,
204 {"tx_queue_error", offsetof(struct ionic_lif_stats,
206 {"tx_desc_fetch_error", offsetof(struct ionic_lif_stats,
207 tx_desc_fetch_error)},
208 {"tx_desc_data_error", offsetof(struct ionic_lif_stats,
209 tx_desc_data_error)},
212 #define IONIC_NB_HW_STATS (sizeof(rte_ionic_xstats_strings) / \
213 sizeof(rte_ionic_xstats_strings[0]))
216 ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev,
217 char *fw_version, size_t fw_size)
219 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
220 struct ionic_adapter *adapter = lif->adapter;
222 if (fw_version == NULL || fw_size <= 0)
225 snprintf(fw_version, fw_size, "%s",
226 adapter->fw_version);
227 fw_version[fw_size - 1] = '\0';
233 * Set device link up, enable tx.
236 ionic_dev_set_link_up(struct rte_eth_dev *eth_dev)
238 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
239 struct ionic_adapter *adapter = lif->adapter;
240 struct ionic_dev *idev = &adapter->idev;
245 ionic_dev_cmd_port_state(idev, IONIC_PORT_ADMIN_STATE_UP);
247 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
249 IONIC_PRINT(WARNING, "Failed to bring port UP");
257 * Set device link down, disable tx.
260 ionic_dev_set_link_down(struct rte_eth_dev *eth_dev)
262 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
263 struct ionic_adapter *adapter = lif->adapter;
264 struct ionic_dev *idev = &adapter->idev;
269 ionic_dev_cmd_port_state(idev, IONIC_PORT_ADMIN_STATE_DOWN);
271 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
273 IONIC_PRINT(WARNING, "Failed to bring port DOWN");
281 ionic_dev_link_update(struct rte_eth_dev *eth_dev,
282 int wait_to_complete __rte_unused)
284 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
285 struct ionic_adapter *adapter = lif->adapter;
286 struct rte_eth_link link;
291 memset(&link, 0, sizeof(link));
292 link.link_autoneg = ETH_LINK_AUTONEG;
294 if (!adapter->link_up) {
295 /* Interface is down */
296 link.link_status = ETH_LINK_DOWN;
297 link.link_duplex = ETH_LINK_HALF_DUPLEX;
298 link.link_speed = ETH_SPEED_NUM_NONE;
300 /* Interface is up */
301 link.link_status = ETH_LINK_UP;
302 link.link_duplex = ETH_LINK_FULL_DUPLEX;
303 switch (adapter->link_speed) {
305 link.link_speed = ETH_SPEED_NUM_10G;
308 link.link_speed = ETH_SPEED_NUM_25G;
311 link.link_speed = ETH_SPEED_NUM_40G;
314 link.link_speed = ETH_SPEED_NUM_50G;
317 link.link_speed = ETH_SPEED_NUM_100G;
320 link.link_speed = ETH_SPEED_NUM_NONE;
325 return rte_eth_linkstatus_set(eth_dev, &link);
329 * Interrupt handler triggered by NIC for handling
330 * specific interrupt.
333 * The address of parameter registered before.
339 ionic_dev_interrupt_handler(void *param)
341 struct ionic_adapter *adapter = (struct ionic_adapter *)param;
343 IONIC_PRINT(DEBUG, "->");
346 ionic_notifyq_handler(adapter->lif, -1);
350 ionic_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
352 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
353 uint32_t max_frame_size;
359 * Note: mtu check against IONIC_MIN_MTU, IONIC_MAX_MTU
360 * is done by the the API.
364 * Max frame size is MTU + Ethernet header + VLAN + QinQ
365 * (plus ETHER_CRC_LEN if the adapter is able to keep CRC)
367 max_frame_size = mtu + RTE_ETHER_HDR_LEN + 4 + 4;
369 if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len < max_frame_size)
372 err = ionic_lif_change_mtu(lif, mtu);
380 ionic_dev_info_get(struct rte_eth_dev *eth_dev,
381 struct rte_eth_dev_info *dev_info)
383 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
384 struct ionic_adapter *adapter = lif->adapter;
385 struct ionic_identity *ident = &adapter->ident;
389 dev_info->max_rx_queues = (uint16_t)
390 ident->lif.eth.config.queue_count[IONIC_QTYPE_RXQ];
391 dev_info->max_tx_queues = (uint16_t)
392 ident->lif.eth.config.queue_count[IONIC_QTYPE_TXQ];
393 /* Also add ETHER_CRC_LEN if the adapter is able to keep CRC */
394 dev_info->min_rx_bufsize = IONIC_MIN_MTU + RTE_ETHER_HDR_LEN;
395 dev_info->max_rx_pktlen = IONIC_MAX_MTU + RTE_ETHER_HDR_LEN;
396 dev_info->max_mac_addrs = adapter->max_mac_addrs;
397 dev_info->min_mtu = IONIC_MIN_MTU;
398 dev_info->max_mtu = IONIC_MAX_MTU;
400 dev_info->hash_key_size = IONIC_RSS_HASH_KEY_SIZE;
401 dev_info->reta_size = ident->lif.eth.rss_ind_tbl_sz;
402 dev_info->flow_type_rss_offloads = IONIC_ETH_RSS_OFFLOAD_ALL;
404 dev_info->speed_capa =
412 * Per-queue capabilities. Actually most of the offloads are enabled
413 * by default on the port and can be used on selected queues (by adding
414 * packet flags at runtime when required)
417 dev_info->rx_queue_offload_capa =
418 DEV_RX_OFFLOAD_IPV4_CKSUM |
419 DEV_RX_OFFLOAD_UDP_CKSUM |
420 DEV_RX_OFFLOAD_TCP_CKSUM |
423 dev_info->tx_queue_offload_capa =
424 DEV_TX_OFFLOAD_IPV4_CKSUM |
425 DEV_TX_OFFLOAD_UDP_CKSUM |
426 DEV_TX_OFFLOAD_TCP_CKSUM |
427 DEV_TX_OFFLOAD_VLAN_INSERT |
428 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
429 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM |
433 * Per-port capabilities
434 * See ionic_set_features to request and check supported features
437 dev_info->rx_offload_capa = dev_info->rx_queue_offload_capa |
438 DEV_RX_OFFLOAD_JUMBO_FRAME |
439 DEV_RX_OFFLOAD_VLAN_FILTER |
440 DEV_RX_OFFLOAD_VLAN_STRIP |
441 DEV_RX_OFFLOAD_SCATTER |
444 dev_info->tx_offload_capa = dev_info->tx_queue_offload_capa |
445 DEV_TX_OFFLOAD_MULTI_SEGS |
446 DEV_TX_OFFLOAD_TCP_TSO |
449 dev_info->rx_desc_lim = rx_desc_lim;
450 dev_info->tx_desc_lim = tx_desc_lim;
452 /* Driver-preferred Rx/Tx parameters */
453 dev_info->default_rxportconf.burst_size = 32;
454 dev_info->default_txportconf.burst_size = 32;
455 dev_info->default_rxportconf.nb_queues = 1;
456 dev_info->default_txportconf.nb_queues = 1;
457 dev_info->default_rxportconf.ring_size = IONIC_DEF_TXRX_DESC;
458 dev_info->default_txportconf.ring_size = IONIC_DEF_TXRX_DESC;
464 ionic_flow_ctrl_get(struct rte_eth_dev *eth_dev,
465 struct rte_eth_fc_conf *fc_conf)
467 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
468 struct ionic_adapter *adapter = lif->adapter;
469 struct ionic_dev *idev = &adapter->idev;
471 if (idev->port_info) {
472 fc_conf->autoneg = idev->port_info->config.an_enable;
474 if (idev->port_info->config.pause_type)
475 fc_conf->mode = RTE_FC_FULL;
477 fc_conf->mode = RTE_FC_NONE;
484 ionic_flow_ctrl_set(struct rte_eth_dev *eth_dev,
485 struct rte_eth_fc_conf *fc_conf)
487 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
488 struct ionic_adapter *adapter = lif->adapter;
489 struct ionic_dev *idev = &adapter->idev;
490 uint8_t pause_type = IONIC_PORT_PAUSE_TYPE_NONE;
493 switch (fc_conf->mode) {
495 pause_type = IONIC_PORT_PAUSE_TYPE_NONE;
498 pause_type = IONIC_PORT_PAUSE_TYPE_LINK;
500 case RTE_FC_RX_PAUSE:
501 case RTE_FC_TX_PAUSE:
505 an_enable = fc_conf->autoneg;
507 ionic_dev_cmd_port_pause(idev, pause_type);
508 ionic_dev_cmd_port_autoneg(idev, an_enable);
514 ionic_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
516 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
517 struct rte_eth_rxmode *rxmode;
518 rxmode = ð_dev->data->dev_conf.rxmode;
521 if (mask & ETH_VLAN_STRIP_MASK) {
522 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
523 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
524 struct ionic_qcq *rxq =
525 eth_dev->data->rx_queues[i];
526 rxq->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
528 lif->features |= IONIC_ETH_HW_VLAN_RX_STRIP;
530 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
531 struct ionic_qcq *rxq =
532 eth_dev->data->rx_queues[i];
533 rxq->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
535 lif->features &= ~IONIC_ETH_HW_VLAN_RX_STRIP;
539 if (mask & ETH_VLAN_FILTER_MASK) {
540 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
541 lif->features |= IONIC_ETH_HW_VLAN_RX_FILTER;
543 lif->features &= ~IONIC_ETH_HW_VLAN_RX_FILTER;
546 ionic_lif_set_features(lif);
552 ionic_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
553 struct rte_eth_rss_reta_entry64 *reta_conf,
556 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
557 struct ionic_adapter *adapter = lif->adapter;
558 struct ionic_identity *ident = &adapter->ident;
559 uint32_t i, j, index, num;
563 if (!lif->rss_ind_tbl) {
564 IONIC_PRINT(ERR, "RSS RETA not initialized, "
565 "can't update the table");
569 if (reta_size != ident->lif.eth.rss_ind_tbl_sz) {
570 IONIC_PRINT(ERR, "The size of hash lookup table configured "
571 "(%d) does not match the number hardware can support "
573 reta_size, ident->lif.eth.rss_ind_tbl_sz);
577 num = lif->adapter->ident.lif.eth.rss_ind_tbl_sz / RTE_RETA_GROUP_SIZE;
579 for (i = 0; i < num; i++) {
580 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
581 if (reta_conf[i].mask & ((uint64_t)1 << j)) {
582 index = (i * RTE_RETA_GROUP_SIZE) + j;
583 lif->rss_ind_tbl[index] = reta_conf[i].reta[j];
588 return ionic_lif_rss_config(lif, lif->rss_types, NULL, NULL);
592 ionic_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
593 struct rte_eth_rss_reta_entry64 *reta_conf,
596 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
597 struct ionic_adapter *adapter = lif->adapter;
598 struct ionic_identity *ident = &adapter->ident;
603 if (reta_size != ident->lif.eth.rss_ind_tbl_sz) {
604 IONIC_PRINT(ERR, "The size of hash lookup table configured "
605 "(%d) does not match the number hardware can support "
607 reta_size, ident->lif.eth.rss_ind_tbl_sz);
611 if (!lif->rss_ind_tbl) {
612 IONIC_PRINT(ERR, "RSS RETA has not been built yet");
616 num = reta_size / RTE_RETA_GROUP_SIZE;
618 for (i = 0; i < num; i++) {
619 memcpy(reta_conf->reta,
620 &lif->rss_ind_tbl[i * RTE_RETA_GROUP_SIZE],
621 RTE_RETA_GROUP_SIZE);
629 ionic_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
630 struct rte_eth_rss_conf *rss_conf)
632 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
637 if (!lif->rss_ind_tbl) {
638 IONIC_PRINT(NOTICE, "RSS not enabled");
642 /* Get key value (if not null, rss_key is 40-byte) */
643 if (rss_conf->rss_key != NULL &&
644 rss_conf->rss_key_len >= IONIC_RSS_HASH_KEY_SIZE)
645 memcpy(rss_conf->rss_key, lif->rss_hash_key,
646 IONIC_RSS_HASH_KEY_SIZE);
648 if (lif->rss_types & IONIC_RSS_TYPE_IPV4)
649 rss_hf |= ETH_RSS_IPV4;
650 if (lif->rss_types & IONIC_RSS_TYPE_IPV4_TCP)
651 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
652 if (lif->rss_types & IONIC_RSS_TYPE_IPV4_UDP)
653 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
654 if (lif->rss_types & IONIC_RSS_TYPE_IPV6)
655 rss_hf |= ETH_RSS_IPV6;
656 if (lif->rss_types & IONIC_RSS_TYPE_IPV6_TCP)
657 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
658 if (lif->rss_types & IONIC_RSS_TYPE_IPV6_UDP)
659 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
661 rss_conf->rss_hf = rss_hf;
667 ionic_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
668 struct rte_eth_rss_conf *rss_conf)
670 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
671 uint32_t rss_types = 0;
676 if (rss_conf->rss_key)
677 key = rss_conf->rss_key;
679 if ((rss_conf->rss_hf & IONIC_ETH_RSS_OFFLOAD_ALL) == 0) {
681 * Can't disable rss through hash flags,
682 * if it is enabled by default during init
684 if (lif->rss_ind_tbl)
687 /* Can't enable rss if disabled by default during init */
688 if (!lif->rss_ind_tbl)
691 if (rss_conf->rss_hf & ETH_RSS_IPV4)
692 rss_types |= IONIC_RSS_TYPE_IPV4;
693 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
694 rss_types |= IONIC_RSS_TYPE_IPV4_TCP;
695 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
696 rss_types |= IONIC_RSS_TYPE_IPV4_UDP;
697 if (rss_conf->rss_hf & ETH_RSS_IPV6)
698 rss_types |= IONIC_RSS_TYPE_IPV6;
699 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
700 rss_types |= IONIC_RSS_TYPE_IPV6_TCP;
701 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
702 rss_types |= IONIC_RSS_TYPE_IPV6_UDP;
704 ionic_lif_rss_config(lif, rss_types, key, NULL);
711 ionic_dev_stats_get(struct rte_eth_dev *eth_dev,
712 struct rte_eth_stats *stats)
714 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
716 ionic_lif_get_stats(lif, stats);
722 ionic_dev_stats_reset(struct rte_eth_dev *eth_dev)
724 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
728 ionic_lif_reset_stats(lif);
734 ionic_dev_xstats_get_names(__rte_unused struct rte_eth_dev *eth_dev,
735 struct rte_eth_xstat_name *xstats_names,
736 __rte_unused unsigned int size)
740 if (xstats_names != NULL) {
741 for (i = 0; i < IONIC_NB_HW_STATS; i++) {
742 snprintf(xstats_names[i].name,
743 sizeof(xstats_names[i].name),
744 "%s", rte_ionic_xstats_strings[i].name);
748 return IONIC_NB_HW_STATS;
752 ionic_dev_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
753 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
756 struct rte_eth_xstat_name xstats_names_copy[IONIC_NB_HW_STATS];
760 if (xstats_names != NULL) {
761 for (i = 0; i < IONIC_NB_HW_STATS; i++) {
762 snprintf(xstats_names[i].name,
763 sizeof(xstats_names[i].name),
764 "%s", rte_ionic_xstats_strings[i].name);
768 return IONIC_NB_HW_STATS;
771 ionic_dev_xstats_get_names_by_id(eth_dev, xstats_names_copy, NULL,
774 for (i = 0; i < limit; i++) {
775 if (ids[i] >= IONIC_NB_HW_STATS) {
776 IONIC_PRINT(ERR, "id value isn't valid");
780 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
787 ionic_dev_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *xstats,
790 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
791 struct ionic_lif_stats hw_stats;
794 if (n < IONIC_NB_HW_STATS)
795 return IONIC_NB_HW_STATS;
797 ionic_lif_get_hw_stats(lif, &hw_stats);
799 for (i = 0; i < IONIC_NB_HW_STATS; i++) {
800 xstats[i].value = *(uint64_t *)(((char *)&hw_stats) +
801 rte_ionic_xstats_strings[i].offset);
805 return IONIC_NB_HW_STATS;
809 ionic_dev_xstats_get_by_id(struct rte_eth_dev *eth_dev, const uint64_t *ids,
810 uint64_t *values, unsigned int n)
812 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
813 struct ionic_lif_stats hw_stats;
814 uint64_t values_copy[IONIC_NB_HW_STATS];
818 if (!ids && n < IONIC_NB_HW_STATS)
819 return IONIC_NB_HW_STATS;
821 ionic_lif_get_hw_stats(lif, &hw_stats);
823 for (i = 0; i < IONIC_NB_HW_STATS; i++) {
824 values[i] = *(uint64_t *)(((char *)&hw_stats) +
825 rte_ionic_xstats_strings[i].offset);
828 return IONIC_NB_HW_STATS;
831 ionic_dev_xstats_get_by_id(eth_dev, NULL, values_copy,
834 for (i = 0; i < n; i++) {
835 if (ids[i] >= IONIC_NB_HW_STATS) {
836 IONIC_PRINT(ERR, "id value isn't valid");
840 values[i] = values_copy[ids[i]];
847 ionic_dev_xstats_reset(struct rte_eth_dev *eth_dev)
849 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
851 ionic_lif_reset_hw_stats(lif);
857 ionic_dev_configure(struct rte_eth_dev *eth_dev)
859 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
864 err = ionic_lif_configure(lif);
866 IONIC_PRINT(ERR, "Cannot configure LIF: %d", err);
873 static inline uint32_t
874 ionic_parse_link_speeds(uint16_t link_speeds)
876 if (link_speeds & ETH_LINK_SPEED_100G)
878 else if (link_speeds & ETH_LINK_SPEED_50G)
880 else if (link_speeds & ETH_LINK_SPEED_40G)
882 else if (link_speeds & ETH_LINK_SPEED_25G)
884 else if (link_speeds & ETH_LINK_SPEED_10G)
891 * Configure device link speed and setup link.
892 * It returns 0 on success.
895 ionic_dev_start(struct rte_eth_dev *eth_dev)
897 struct rte_eth_conf *dev_conf = ð_dev->data->dev_conf;
898 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
899 struct ionic_adapter *adapter = lif->adapter;
900 struct ionic_dev *idev = &adapter->idev;
901 uint32_t allowed_speeds;
907 ETH_LINK_SPEED_FIXED |
914 if (dev_conf->link_speeds & ~allowed_speeds) {
915 IONIC_PRINT(ERR, "Invalid link setting");
919 if (dev_conf->lpbk_mode)
920 IONIC_PRINT(WARNING, "Loopback mode not supported");
922 err = ionic_lif_start(lif);
924 IONIC_PRINT(ERR, "Cannot start LIF: %d", err);
928 if (eth_dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
929 uint32_t speed = ionic_parse_link_speeds(dev_conf->link_speeds);
932 ionic_dev_cmd_port_speed(idev, speed);
935 ionic_dev_link_update(eth_dev, 0);
941 * Stop device: disable rx and tx functions to allow for reconfiguring.
944 ionic_dev_stop(struct rte_eth_dev *eth_dev)
946 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
951 err = ionic_lif_stop(lif);
953 IONIC_PRINT(ERR, "Cannot stop LIF: %d", err);
958 static void ionic_unconfigure_intr(struct ionic_adapter *adapter);
961 * Reset and stop device.
964 ionic_dev_close(struct rte_eth_dev *eth_dev)
966 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
967 struct ionic_adapter *adapter = lif->adapter;
971 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
974 err = ionic_lif_stop(lif);
976 IONIC_PRINT(ERR, "Cannot stop LIF: %d", err);
980 ionic_lif_free_queues(lif);
982 IONIC_PRINT(NOTICE, "Removing device %s", eth_dev->device->name);
983 ionic_unconfigure_intr(adapter);
985 rte_eth_dev_destroy(eth_dev, eth_ionic_dev_uninit);
987 ionic_port_reset(adapter);
988 ionic_reset(adapter);
996 eth_ionic_dev_init(struct rte_eth_dev *eth_dev, void *init_params)
998 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
999 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
1000 struct ionic_adapter *adapter = (struct ionic_adapter *)init_params;
1005 eth_dev->dev_ops = &ionic_eth_dev_ops;
1006 eth_dev->rx_pkt_burst = &ionic_recv_pkts;
1007 eth_dev->tx_pkt_burst = &ionic_xmit_pkts;
1008 eth_dev->tx_pkt_prepare = &ionic_prep_pkts;
1010 /* Multi-process not supported, primary does initialization anyway */
1011 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1014 rte_eth_copy_pci_info(eth_dev, pci_dev);
1015 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1017 lif->eth_dev = eth_dev;
1018 lif->adapter = adapter;
1021 IONIC_PRINT(DEBUG, "Up to %u MAC addresses supported",
1022 adapter->max_mac_addrs);
1024 /* Allocate memory for storing MAC addresses */
1025 eth_dev->data->mac_addrs = rte_zmalloc("ionic",
1026 RTE_ETHER_ADDR_LEN * adapter->max_mac_addrs, 0);
1028 if (eth_dev->data->mac_addrs == NULL) {
1029 IONIC_PRINT(ERR, "Failed to allocate %u bytes needed to "
1030 "store MAC addresses",
1031 RTE_ETHER_ADDR_LEN * adapter->max_mac_addrs);
1036 err = ionic_lif_alloc(lif);
1038 IONIC_PRINT(ERR, "Cannot allocate LIFs: %d, aborting",
1043 err = ionic_lif_init(lif);
1045 IONIC_PRINT(ERR, "Cannot init LIFs: %d, aborting", err);
1049 /* Copy the MAC address */
1050 rte_ether_addr_copy((struct rte_ether_addr *)lif->mac_addr,
1051 ð_dev->data->mac_addrs[0]);
1053 IONIC_PRINT(DEBUG, "Port %u initialized", eth_dev->data->port_id);
1058 ionic_lif_free(lif);
1064 eth_ionic_dev_uninit(struct rte_eth_dev *eth_dev)
1066 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
1067 struct ionic_adapter *adapter = lif->adapter;
1071 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1074 adapter->lif = NULL;
1076 ionic_lif_deinit(lif);
1077 ionic_lif_free(lif);
1083 ionic_configure_intr(struct ionic_adapter *adapter)
1085 struct rte_pci_device *pci_dev = adapter->pci_dev;
1086 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1089 IONIC_PRINT(DEBUG, "Configuring %u intrs", adapter->nintrs);
1091 if (rte_intr_efd_enable(intr_handle, adapter->nintrs)) {
1092 IONIC_PRINT(ERR, "Fail to create eventfd");
1096 if (rte_intr_dp_is_en(intr_handle))
1098 "Packet I/O interrupt on datapath is enabled");
1100 if (!intr_handle->intr_vec) {
1101 intr_handle->intr_vec = rte_zmalloc("intr_vec",
1102 adapter->nintrs * sizeof(int), 0);
1104 if (!intr_handle->intr_vec) {
1105 IONIC_PRINT(ERR, "Failed to allocate %u vectors",
1111 err = rte_intr_callback_register(intr_handle,
1112 ionic_dev_interrupt_handler,
1117 "Failure registering interrupts handler (%d)",
1122 /* enable intr mapping */
1123 err = rte_intr_enable(intr_handle);
1126 IONIC_PRINT(ERR, "Failure enabling interrupts (%d)", err);
1134 ionic_unconfigure_intr(struct ionic_adapter *adapter)
1136 struct rte_pci_device *pci_dev = adapter->pci_dev;
1137 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1139 rte_intr_disable(intr_handle);
1141 rte_intr_callback_unregister(intr_handle,
1142 ionic_dev_interrupt_handler,
1147 eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1148 struct rte_pci_device *pci_dev)
1150 char name[RTE_ETH_NAME_MAX_LEN];
1151 struct rte_mem_resource *resource;
1152 struct ionic_adapter *adapter;
1153 struct ionic_hw *hw;
1157 /* Check structs (trigger error at compilation time) */
1158 ionic_struct_size_checks();
1160 /* Multi-process not supported */
1161 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1166 IONIC_PRINT(DEBUG, "Initializing device %s",
1167 pci_dev->device.name);
1169 adapter = rte_zmalloc("ionic", sizeof(*adapter), 0);
1171 IONIC_PRINT(ERR, "OOM");
1176 adapter->pci_dev = pci_dev;
1179 hw->device_id = pci_dev->id.device_id;
1180 hw->vendor_id = pci_dev->id.vendor_id;
1182 err = ionic_init_mac(hw);
1184 IONIC_PRINT(ERR, "Mac init failed: %d", err);
1186 goto err_free_adapter;
1189 adapter->num_bars = 0;
1190 for (i = 0; i < PCI_MAX_RESOURCE && i < IONIC_BARS_MAX; i++) {
1191 resource = &pci_dev->mem_resource[i];
1192 if (resource->phys_addr == 0 || resource->len == 0)
1194 adapter->bars[adapter->num_bars].vaddr = resource->addr;
1195 adapter->bars[adapter->num_bars].bus_addr = resource->phys_addr;
1196 adapter->bars[adapter->num_bars].len = resource->len;
1197 adapter->num_bars++;
1200 /* Discover ionic dev resources */
1202 err = ionic_setup(adapter);
1204 IONIC_PRINT(ERR, "Cannot setup device: %d, aborting", err);
1205 goto err_free_adapter;
1208 err = ionic_identify(adapter);
1210 IONIC_PRINT(ERR, "Cannot identify device: %d, aborting",
1212 goto err_free_adapter;
1215 err = ionic_init(adapter);
1217 IONIC_PRINT(ERR, "Cannot init device: %d, aborting", err);
1218 goto err_free_adapter;
1221 /* Configure the ports */
1222 err = ionic_port_identify(adapter);
1224 IONIC_PRINT(ERR, "Cannot identify port: %d, aborting",
1226 goto err_free_adapter;
1229 err = ionic_port_init(adapter);
1231 IONIC_PRINT(ERR, "Cannot init port: %d, aborting", err);
1232 goto err_free_adapter;
1235 /* Configure LIFs */
1236 err = ionic_lif_identify(adapter);
1238 IONIC_PRINT(ERR, "Cannot identify lif: %d, aborting", err);
1239 goto err_free_adapter;
1242 /* Allocate and init LIFs */
1243 err = ionic_lifs_size(adapter);
1245 IONIC_PRINT(ERR, "Cannot size LIFs: %d, aborting", err);
1246 goto err_free_adapter;
1249 adapter->max_mac_addrs = adapter->ident.lif.eth.max_ucast_filters;
1251 if (adapter->ident.dev.nlifs != 1) {
1252 IONIC_PRINT(ERR, "Unexpected request for %d LIFs",
1253 adapter->ident.dev.nlifs);
1254 goto err_free_adapter;
1257 snprintf(name, sizeof(name), "%s_lif", pci_dev->device.name);
1258 err = rte_eth_dev_create(&pci_dev->device,
1259 name, sizeof(struct ionic_lif),
1260 NULL, NULL, eth_ionic_dev_init, adapter);
1262 IONIC_PRINT(ERR, "Cannot create eth device for %s", name);
1263 goto err_free_adapter;
1266 err = ionic_configure_intr(adapter);
1269 IONIC_PRINT(ERR, "Failed to configure interrupts");
1270 goto err_free_adapter;
1282 eth_ionic_pci_remove(struct rte_pci_device *pci_dev)
1284 char name[RTE_ETH_NAME_MAX_LEN];
1285 struct rte_eth_dev *eth_dev;
1287 /* Adapter lookup is using the eth_dev name */
1288 snprintf(name, sizeof(name), "%s_lif", pci_dev->device.name);
1290 eth_dev = rte_eth_dev_allocated(name);
1292 ionic_dev_close(eth_dev);
1294 IONIC_PRINT(DEBUG, "Cannot find device %s",
1295 pci_dev->device.name);
1300 static struct rte_pci_driver rte_ionic_pmd = {
1301 .id_table = pci_id_ionic_map,
1302 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1303 .probe = eth_ionic_pci_probe,
1304 .remove = eth_ionic_pci_remove,
1307 RTE_PMD_REGISTER_PCI(net_ionic, rte_ionic_pmd);
1308 RTE_PMD_REGISTER_PCI_TABLE(net_ionic, pci_id_ionic_map);
1309 RTE_PMD_REGISTER_KMOD_DEP(net_ionic, "* igb_uio | uio_pci_generic | vfio-pci");
1310 RTE_LOG_REGISTER(ionic_logtype, pmd.net.ionic, NOTICE);