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 void ionic_dev_stop(struct rte_eth_dev *dev);
28 static void 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);
64 static const struct rte_pci_id pci_id_ionic_map[] = {
65 { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_PF) },
66 { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_VF) },
67 { RTE_PCI_DEVICE(IONIC_PENSANDO_VENDOR_ID, IONIC_DEV_ID_ETH_MGMT) },
68 { .vendor_id = 0, /* sentinel */ },
71 static const struct rte_eth_desc_lim rx_desc_lim = {
72 .nb_max = IONIC_MAX_RING_DESC,
73 .nb_min = IONIC_MIN_RING_DESC,
77 static const struct rte_eth_desc_lim tx_desc_lim = {
78 .nb_max = IONIC_MAX_RING_DESC,
79 .nb_min = IONIC_MIN_RING_DESC,
81 .nb_seg_max = IONIC_TX_MAX_SG_ELEMS,
82 .nb_mtu_seg_max = IONIC_TX_MAX_SG_ELEMS,
85 static const struct eth_dev_ops ionic_eth_dev_ops = {
86 .dev_infos_get = ionic_dev_info_get,
87 .dev_configure = ionic_dev_configure,
88 .mtu_set = ionic_dev_mtu_set,
89 .dev_start = ionic_dev_start,
90 .dev_stop = ionic_dev_stop,
91 .dev_close = ionic_dev_close,
92 .link_update = ionic_dev_link_update,
93 .dev_set_link_up = ionic_dev_set_link_up,
94 .dev_set_link_down = ionic_dev_set_link_down,
95 .mac_addr_add = ionic_dev_add_mac,
96 .mac_addr_remove = ionic_dev_remove_mac,
97 .mac_addr_set = ionic_dev_set_mac,
98 .vlan_filter_set = ionic_dev_vlan_filter_set,
99 .promiscuous_enable = ionic_dev_promiscuous_enable,
100 .promiscuous_disable = ionic_dev_promiscuous_disable,
101 .allmulticast_enable = ionic_dev_allmulticast_enable,
102 .allmulticast_disable = ionic_dev_allmulticast_disable,
103 .flow_ctrl_get = ionic_flow_ctrl_get,
104 .flow_ctrl_set = ionic_flow_ctrl_set,
105 .rxq_info_get = ionic_rxq_info_get,
106 .txq_info_get = ionic_txq_info_get,
107 .rx_queue_setup = ionic_dev_rx_queue_setup,
108 .rx_queue_release = ionic_dev_rx_queue_release,
109 .rx_queue_start = ionic_dev_rx_queue_start,
110 .rx_queue_stop = ionic_dev_rx_queue_stop,
111 .tx_queue_setup = ionic_dev_tx_queue_setup,
112 .tx_queue_release = ionic_dev_tx_queue_release,
113 .tx_queue_start = ionic_dev_tx_queue_start,
114 .tx_queue_stop = ionic_dev_tx_queue_stop,
115 .vlan_offload_set = ionic_vlan_offload_set,
116 .reta_update = ionic_dev_rss_reta_update,
117 .reta_query = ionic_dev_rss_reta_query,
118 .rss_hash_conf_get = ionic_dev_rss_hash_conf_get,
119 .rss_hash_update = ionic_dev_rss_hash_update,
120 .stats_get = ionic_dev_stats_get,
121 .stats_reset = ionic_dev_stats_reset,
122 .xstats_get = ionic_dev_xstats_get,
123 .xstats_get_by_id = ionic_dev_xstats_get_by_id,
124 .xstats_reset = ionic_dev_xstats_reset,
125 .xstats_get_names = ionic_dev_xstats_get_names,
126 .xstats_get_names_by_id = ionic_dev_xstats_get_names_by_id,
127 .fw_version_get = ionic_dev_fw_version_get,
130 struct rte_ionic_xstats_name_off {
131 char name[RTE_ETH_XSTATS_NAME_SIZE];
135 static const struct rte_ionic_xstats_name_off rte_ionic_xstats_strings[] = {
137 {"rx_ucast_bytes", offsetof(struct ionic_lif_stats,
139 {"rx_ucast_packets", offsetof(struct ionic_lif_stats,
141 {"rx_mcast_bytes", offsetof(struct ionic_lif_stats,
143 {"rx_mcast_packets", offsetof(struct ionic_lif_stats,
145 {"rx_bcast_bytes", offsetof(struct ionic_lif_stats,
147 {"rx_bcast_packets", offsetof(struct ionic_lif_stats,
150 {"rx_ucast_drop_bytes", offsetof(struct ionic_lif_stats,
151 rx_ucast_drop_bytes)},
152 {"rx_ucast_drop_packets", offsetof(struct ionic_lif_stats,
153 rx_ucast_drop_packets)},
154 {"rx_mcast_drop_bytes", offsetof(struct ionic_lif_stats,
155 rx_mcast_drop_bytes)},
156 {"rx_mcast_drop_packets", offsetof(struct ionic_lif_stats,
157 rx_mcast_drop_packets)},
158 {"rx_bcast_drop_bytes", offsetof(struct ionic_lif_stats,
159 rx_bcast_drop_bytes)},
160 {"rx_bcast_drop_packets", offsetof(struct ionic_lif_stats,
161 rx_bcast_drop_packets)},
162 {"rx_dma_error", offsetof(struct ionic_lif_stats,
165 {"tx_ucast_bytes", offsetof(struct ionic_lif_stats,
167 {"tx_ucast_packets", offsetof(struct ionic_lif_stats,
169 {"tx_mcast_bytes", offsetof(struct ionic_lif_stats,
171 {"tx_mcast_packets", offsetof(struct ionic_lif_stats,
173 {"tx_bcast_bytes", offsetof(struct ionic_lif_stats,
175 {"tx_bcast_packets", offsetof(struct ionic_lif_stats,
178 {"tx_ucast_drop_bytes", offsetof(struct ionic_lif_stats,
179 tx_ucast_drop_bytes)},
180 {"tx_ucast_drop_packets", offsetof(struct ionic_lif_stats,
181 tx_ucast_drop_packets)},
182 {"tx_mcast_drop_bytes", offsetof(struct ionic_lif_stats,
183 tx_mcast_drop_bytes)},
184 {"tx_mcast_drop_packets", offsetof(struct ionic_lif_stats,
185 tx_mcast_drop_packets)},
186 {"tx_bcast_drop_bytes", offsetof(struct ionic_lif_stats,
187 tx_bcast_drop_bytes)},
188 {"tx_bcast_drop_packets", offsetof(struct ionic_lif_stats,
189 tx_bcast_drop_packets)},
190 {"tx_dma_error", offsetof(struct ionic_lif_stats,
192 /* Rx Queue/Ring drops */
193 {"rx_queue_disabled", offsetof(struct ionic_lif_stats,
195 {"rx_queue_empty", offsetof(struct ionic_lif_stats,
197 {"rx_queue_error", offsetof(struct ionic_lif_stats,
199 {"rx_desc_fetch_error", offsetof(struct ionic_lif_stats,
200 rx_desc_fetch_error)},
201 {"rx_desc_data_error", offsetof(struct ionic_lif_stats,
202 rx_desc_data_error)},
203 /* Tx Queue/Ring drops */
204 {"tx_queue_disabled", offsetof(struct ionic_lif_stats,
206 {"tx_queue_error", offsetof(struct ionic_lif_stats,
208 {"tx_desc_fetch_error", offsetof(struct ionic_lif_stats,
209 tx_desc_fetch_error)},
210 {"tx_desc_data_error", offsetof(struct ionic_lif_stats,
211 tx_desc_data_error)},
214 #define IONIC_NB_HW_STATS (sizeof(rte_ionic_xstats_strings) / \
215 sizeof(rte_ionic_xstats_strings[0]))
218 ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev,
219 char *fw_version, size_t fw_size)
221 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
222 struct ionic_adapter *adapter = lif->adapter;
224 if (fw_version == NULL || fw_size <= 0)
227 snprintf(fw_version, fw_size, "%s",
228 adapter->fw_version);
229 fw_version[fw_size - 1] = '\0';
235 * Set device link up, enable tx.
238 ionic_dev_set_link_up(struct rte_eth_dev *eth_dev)
240 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
241 struct ionic_adapter *adapter = lif->adapter;
242 struct ionic_dev *idev = &adapter->idev;
247 ionic_dev_cmd_port_state(idev, IONIC_PORT_ADMIN_STATE_UP);
249 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
251 IONIC_PRINT(WARNING, "Failed to bring port UP");
259 * Set device link down, disable tx.
262 ionic_dev_set_link_down(struct rte_eth_dev *eth_dev)
264 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
265 struct ionic_adapter *adapter = lif->adapter;
266 struct ionic_dev *idev = &adapter->idev;
271 ionic_dev_cmd_port_state(idev, IONIC_PORT_ADMIN_STATE_DOWN);
273 err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
275 IONIC_PRINT(WARNING, "Failed to bring port DOWN");
283 ionic_dev_link_update(struct rte_eth_dev *eth_dev,
284 int wait_to_complete __rte_unused)
286 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
287 struct ionic_adapter *adapter = lif->adapter;
288 struct rte_eth_link link;
293 memset(&link, 0, sizeof(link));
294 link.link_autoneg = ETH_LINK_AUTONEG;
296 if (!adapter->link_up) {
297 /* Interface is down */
298 link.link_status = ETH_LINK_DOWN;
299 link.link_duplex = ETH_LINK_HALF_DUPLEX;
300 link.link_speed = ETH_SPEED_NUM_NONE;
302 /* Interface is up */
303 link.link_status = ETH_LINK_UP;
304 link.link_duplex = ETH_LINK_FULL_DUPLEX;
305 switch (adapter->link_speed) {
307 link.link_speed = ETH_SPEED_NUM_10G;
310 link.link_speed = ETH_SPEED_NUM_25G;
313 link.link_speed = ETH_SPEED_NUM_40G;
316 link.link_speed = ETH_SPEED_NUM_50G;
319 link.link_speed = ETH_SPEED_NUM_100G;
322 link.link_speed = ETH_SPEED_NUM_NONE;
327 return rte_eth_linkstatus_set(eth_dev, &link);
331 * Interrupt handler triggered by NIC for handling
332 * specific interrupt.
335 * The address of parameter registered before.
341 ionic_dev_interrupt_handler(void *param)
343 struct ionic_adapter *adapter = (struct ionic_adapter *)param;
346 IONIC_PRINT(DEBUG, "->");
348 for (i = 0; i < adapter->nlifs; i++) {
349 if (adapter->lifs[i])
350 ionic_notifyq_handler(adapter->lifs[i], -1);
355 ionic_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
357 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
358 uint32_t max_frame_size;
364 * Note: mtu check against IONIC_MIN_MTU, IONIC_MAX_MTU
365 * is done by the the API.
369 * Max frame size is MTU + Ethernet header + VLAN + QinQ
370 * (plus ETHER_CRC_LEN if the adapter is able to keep CRC)
372 max_frame_size = mtu + RTE_ETHER_HDR_LEN + 4 + 4;
374 if (eth_dev->data->dev_conf.rxmode.max_rx_pkt_len < max_frame_size)
377 err = ionic_lif_change_mtu(lif, mtu);
385 ionic_dev_info_get(struct rte_eth_dev *eth_dev,
386 struct rte_eth_dev_info *dev_info)
388 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
389 struct ionic_adapter *adapter = lif->adapter;
390 struct ionic_identity *ident = &adapter->ident;
394 dev_info->max_rx_queues = (uint16_t)
395 ident->lif.eth.config.queue_count[IONIC_QTYPE_RXQ];
396 dev_info->max_tx_queues = (uint16_t)
397 ident->lif.eth.config.queue_count[IONIC_QTYPE_TXQ];
398 /* Also add ETHER_CRC_LEN if the adapter is able to keep CRC */
399 dev_info->min_rx_bufsize = IONIC_MIN_MTU + RTE_ETHER_HDR_LEN;
400 dev_info->max_rx_pktlen = IONIC_MAX_MTU + RTE_ETHER_HDR_LEN;
401 dev_info->max_mac_addrs = adapter->max_mac_addrs;
402 dev_info->min_mtu = IONIC_MIN_MTU;
403 dev_info->max_mtu = IONIC_MAX_MTU;
405 dev_info->hash_key_size = IONIC_RSS_HASH_KEY_SIZE;
406 dev_info->reta_size = ident->lif.eth.rss_ind_tbl_sz;
407 dev_info->flow_type_rss_offloads = IONIC_ETH_RSS_OFFLOAD_ALL;
409 dev_info->speed_capa =
417 * Per-queue capabilities. Actually most of the offloads are enabled
418 * by default on the port and can be used on selected queues (by adding
419 * packet flags at runtime when required)
422 dev_info->rx_queue_offload_capa =
423 DEV_RX_OFFLOAD_IPV4_CKSUM |
424 DEV_RX_OFFLOAD_UDP_CKSUM |
425 DEV_RX_OFFLOAD_TCP_CKSUM |
428 dev_info->tx_queue_offload_capa =
429 DEV_TX_OFFLOAD_IPV4_CKSUM |
430 DEV_TX_OFFLOAD_UDP_CKSUM |
431 DEV_TX_OFFLOAD_TCP_CKSUM |
432 DEV_TX_OFFLOAD_VLAN_INSERT |
433 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
434 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM |
438 * Per-port capabilities
439 * See ionic_set_features to request and check supported features
442 dev_info->rx_offload_capa = dev_info->rx_queue_offload_capa |
443 DEV_RX_OFFLOAD_JUMBO_FRAME |
444 DEV_RX_OFFLOAD_VLAN_FILTER |
445 DEV_RX_OFFLOAD_VLAN_STRIP |
446 DEV_RX_OFFLOAD_SCATTER |
449 dev_info->tx_offload_capa = dev_info->tx_queue_offload_capa |
450 DEV_TX_OFFLOAD_MULTI_SEGS |
451 DEV_TX_OFFLOAD_TCP_TSO |
454 dev_info->rx_desc_lim = rx_desc_lim;
455 dev_info->tx_desc_lim = tx_desc_lim;
457 /* Driver-preferred Rx/Tx parameters */
458 dev_info->default_rxportconf.burst_size = 32;
459 dev_info->default_txportconf.burst_size = 32;
460 dev_info->default_rxportconf.nb_queues = 1;
461 dev_info->default_txportconf.nb_queues = 1;
462 dev_info->default_rxportconf.ring_size = IONIC_DEF_TXRX_DESC;
463 dev_info->default_txportconf.ring_size = IONIC_DEF_TXRX_DESC;
469 ionic_flow_ctrl_get(struct rte_eth_dev *eth_dev,
470 struct rte_eth_fc_conf *fc_conf)
472 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
473 struct ionic_adapter *adapter = lif->adapter;
474 struct ionic_dev *idev = &adapter->idev;
476 if (idev->port_info) {
477 fc_conf->autoneg = idev->port_info->config.an_enable;
479 if (idev->port_info->config.pause_type)
480 fc_conf->mode = RTE_FC_FULL;
482 fc_conf->mode = RTE_FC_NONE;
489 ionic_flow_ctrl_set(struct rte_eth_dev *eth_dev,
490 struct rte_eth_fc_conf *fc_conf)
492 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
493 struct ionic_adapter *adapter = lif->adapter;
494 struct ionic_dev *idev = &adapter->idev;
495 uint8_t pause_type = IONIC_PORT_PAUSE_TYPE_NONE;
498 switch (fc_conf->mode) {
500 pause_type = IONIC_PORT_PAUSE_TYPE_NONE;
503 pause_type = IONIC_PORT_PAUSE_TYPE_LINK;
505 case RTE_FC_RX_PAUSE:
506 case RTE_FC_TX_PAUSE:
510 an_enable = fc_conf->autoneg;
512 ionic_dev_cmd_port_pause(idev, pause_type);
513 ionic_dev_cmd_port_autoneg(idev, an_enable);
519 ionic_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
521 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
522 struct rte_eth_rxmode *rxmode;
523 rxmode = ð_dev->data->dev_conf.rxmode;
526 if (mask & ETH_VLAN_STRIP_MASK) {
527 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
528 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
529 struct ionic_qcq *rxq =
530 eth_dev->data->rx_queues[i];
531 rxq->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
533 lif->features |= IONIC_ETH_HW_VLAN_RX_STRIP;
535 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
536 struct ionic_qcq *rxq =
537 eth_dev->data->rx_queues[i];
538 rxq->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
540 lif->features &= ~IONIC_ETH_HW_VLAN_RX_STRIP;
544 if (mask & ETH_VLAN_FILTER_MASK) {
545 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
546 lif->features |= IONIC_ETH_HW_VLAN_RX_FILTER;
548 lif->features &= ~IONIC_ETH_HW_VLAN_RX_FILTER;
551 ionic_lif_set_features(lif);
557 ionic_dev_rss_reta_update(struct rte_eth_dev *eth_dev,
558 struct rte_eth_rss_reta_entry64 *reta_conf,
561 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
562 struct ionic_adapter *adapter = lif->adapter;
563 struct ionic_identity *ident = &adapter->ident;
564 uint32_t i, j, index, num;
568 if (!lif->rss_ind_tbl) {
569 IONIC_PRINT(ERR, "RSS RETA not initialized, "
570 "can't update the table");
574 if (reta_size != ident->lif.eth.rss_ind_tbl_sz) {
575 IONIC_PRINT(ERR, "The size of hash lookup table configured "
576 "(%d) doesn't match the number hardware can supported "
578 reta_size, ident->lif.eth.rss_ind_tbl_sz);
582 num = lif->adapter->ident.lif.eth.rss_ind_tbl_sz / RTE_RETA_GROUP_SIZE;
584 for (i = 0; i < num; i++) {
585 for (j = 0; j < RTE_RETA_GROUP_SIZE; j++) {
586 if (reta_conf[i].mask & ((uint64_t)1 << j)) {
587 index = (i * RTE_RETA_GROUP_SIZE) + j;
588 lif->rss_ind_tbl[index] = reta_conf[i].reta[j];
593 return ionic_lif_rss_config(lif, lif->rss_types, NULL, NULL);
597 ionic_dev_rss_reta_query(struct rte_eth_dev *eth_dev,
598 struct rte_eth_rss_reta_entry64 *reta_conf,
601 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
602 struct ionic_adapter *adapter = lif->adapter;
603 struct ionic_identity *ident = &adapter->ident;
608 if (reta_size != ident->lif.eth.rss_ind_tbl_sz) {
609 IONIC_PRINT(ERR, "The size of hash lookup table configured "
610 "(%d) doesn't match the number hardware can supported "
612 reta_size, ident->lif.eth.rss_ind_tbl_sz);
616 if (!lif->rss_ind_tbl) {
617 IONIC_PRINT(ERR, "RSS RETA has not been built yet");
621 num = reta_size / RTE_RETA_GROUP_SIZE;
623 for (i = 0; i < num; i++) {
624 memcpy(reta_conf->reta,
625 &lif->rss_ind_tbl[i * RTE_RETA_GROUP_SIZE],
626 RTE_RETA_GROUP_SIZE);
634 ionic_dev_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
635 struct rte_eth_rss_conf *rss_conf)
637 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
642 if (!lif->rss_ind_tbl) {
643 IONIC_PRINT(NOTICE, "RSS not enabled");
647 /* Get key value (if not null, rss_key is 40-byte) */
648 if (rss_conf->rss_key != NULL &&
649 rss_conf->rss_key_len >= IONIC_RSS_HASH_KEY_SIZE)
650 memcpy(rss_conf->rss_key, lif->rss_hash_key,
651 IONIC_RSS_HASH_KEY_SIZE);
653 if (lif->rss_types & IONIC_RSS_TYPE_IPV4)
654 rss_hf |= ETH_RSS_IPV4;
655 if (lif->rss_types & IONIC_RSS_TYPE_IPV4_TCP)
656 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
657 if (lif->rss_types & IONIC_RSS_TYPE_IPV4_UDP)
658 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
659 if (lif->rss_types & IONIC_RSS_TYPE_IPV6)
660 rss_hf |= ETH_RSS_IPV6;
661 if (lif->rss_types & IONIC_RSS_TYPE_IPV6_TCP)
662 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
663 if (lif->rss_types & IONIC_RSS_TYPE_IPV6_UDP)
664 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
666 rss_conf->rss_hf = rss_hf;
672 ionic_dev_rss_hash_update(struct rte_eth_dev *eth_dev,
673 struct rte_eth_rss_conf *rss_conf)
675 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
676 uint32_t rss_types = 0;
681 if (rss_conf->rss_key)
682 key = rss_conf->rss_key;
684 if ((rss_conf->rss_hf & IONIC_ETH_RSS_OFFLOAD_ALL) == 0) {
686 * Can't disable rss through hash flags,
687 * if it is enabled by default during init
689 if (lif->rss_ind_tbl)
692 /* Can't enable rss if disabled by default during init */
693 if (!lif->rss_ind_tbl)
696 if (rss_conf->rss_hf & ETH_RSS_IPV4)
697 rss_types |= IONIC_RSS_TYPE_IPV4;
698 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
699 rss_types |= IONIC_RSS_TYPE_IPV4_TCP;
700 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
701 rss_types |= IONIC_RSS_TYPE_IPV4_UDP;
702 if (rss_conf->rss_hf & ETH_RSS_IPV6)
703 rss_types |= IONIC_RSS_TYPE_IPV6;
704 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
705 rss_types |= IONIC_RSS_TYPE_IPV6_TCP;
706 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
707 rss_types |= IONIC_RSS_TYPE_IPV6_UDP;
709 ionic_lif_rss_config(lif, rss_types, key, NULL);
716 ionic_dev_stats_get(struct rte_eth_dev *eth_dev,
717 struct rte_eth_stats *stats)
719 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
721 ionic_lif_get_stats(lif, stats);
727 ionic_dev_stats_reset(struct rte_eth_dev *eth_dev)
729 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
733 ionic_lif_reset_stats(lif);
739 ionic_dev_xstats_get_names(__rte_unused struct rte_eth_dev *eth_dev,
740 struct rte_eth_xstat_name *xstats_names,
741 __rte_unused unsigned int size)
745 if (xstats_names != NULL) {
746 for (i = 0; i < IONIC_NB_HW_STATS; i++) {
747 snprintf(xstats_names[i].name,
748 sizeof(xstats_names[i].name),
749 "%s", rte_ionic_xstats_strings[i].name);
753 return IONIC_NB_HW_STATS;
757 ionic_dev_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
758 struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
761 struct rte_eth_xstat_name xstats_names_copy[IONIC_NB_HW_STATS];
765 if (xstats_names != NULL) {
766 for (i = 0; i < IONIC_NB_HW_STATS; i++) {
767 snprintf(xstats_names[i].name,
768 sizeof(xstats_names[i].name),
769 "%s", rte_ionic_xstats_strings[i].name);
773 return IONIC_NB_HW_STATS;
776 ionic_dev_xstats_get_names_by_id(eth_dev, xstats_names_copy, NULL,
779 for (i = 0; i < limit; i++) {
780 if (ids[i] >= IONIC_NB_HW_STATS) {
781 IONIC_PRINT(ERR, "id value isn't valid");
785 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
792 ionic_dev_xstats_get(struct rte_eth_dev *eth_dev, struct rte_eth_xstat *xstats,
795 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
796 struct ionic_lif_stats hw_stats;
799 if (n < IONIC_NB_HW_STATS)
800 return IONIC_NB_HW_STATS;
802 ionic_lif_get_hw_stats(lif, &hw_stats);
804 for (i = 0; i < IONIC_NB_HW_STATS; i++) {
805 xstats[i].value = *(uint64_t *)(((char *)&hw_stats) +
806 rte_ionic_xstats_strings[i].offset);
810 return IONIC_NB_HW_STATS;
814 ionic_dev_xstats_get_by_id(struct rte_eth_dev *eth_dev, const uint64_t *ids,
815 uint64_t *values, unsigned int n)
817 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
818 struct ionic_lif_stats hw_stats;
819 uint64_t values_copy[IONIC_NB_HW_STATS];
823 if (!ids && n < IONIC_NB_HW_STATS)
824 return IONIC_NB_HW_STATS;
826 ionic_lif_get_hw_stats(lif, &hw_stats);
828 for (i = 0; i < IONIC_NB_HW_STATS; i++) {
829 values[i] = *(uint64_t *)(((char *)&hw_stats) +
830 rte_ionic_xstats_strings[i].offset);
833 return IONIC_NB_HW_STATS;
836 ionic_dev_xstats_get_by_id(eth_dev, NULL, values_copy,
839 for (i = 0; i < n; i++) {
840 if (ids[i] >= IONIC_NB_HW_STATS) {
841 IONIC_PRINT(ERR, "id value isn't valid");
845 values[i] = values_copy[ids[i]];
852 ionic_dev_xstats_reset(struct rte_eth_dev *eth_dev)
854 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
856 ionic_lif_reset_hw_stats(lif);
862 ionic_dev_configure(struct rte_eth_dev *eth_dev)
864 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
869 err = ionic_lif_configure(lif);
871 IONIC_PRINT(ERR, "Cannot configure LIF: %d", err);
878 static inline uint32_t
879 ionic_parse_link_speeds(uint16_t link_speeds)
881 if (link_speeds & ETH_LINK_SPEED_100G)
883 else if (link_speeds & ETH_LINK_SPEED_50G)
885 else if (link_speeds & ETH_LINK_SPEED_40G)
887 else if (link_speeds & ETH_LINK_SPEED_25G)
889 else if (link_speeds & ETH_LINK_SPEED_10G)
896 * Configure device link speed and setup link.
897 * It returns 0 on success.
900 ionic_dev_start(struct rte_eth_dev *eth_dev)
902 struct rte_eth_conf *dev_conf = ð_dev->data->dev_conf;
903 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
904 struct ionic_adapter *adapter = lif->adapter;
905 struct ionic_dev *idev = &adapter->idev;
906 uint32_t allowed_speeds;
912 ETH_LINK_SPEED_FIXED |
919 if (dev_conf->link_speeds & ~allowed_speeds) {
920 IONIC_PRINT(ERR, "Invalid link setting");
924 err = ionic_lif_start(lif);
926 IONIC_PRINT(ERR, "Cannot start LIF: %d", err);
930 if (eth_dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
931 uint32_t speed = ionic_parse_link_speeds(dev_conf->link_speeds);
934 ionic_dev_cmd_port_speed(idev, speed);
937 ionic_dev_link_update(eth_dev, 0);
943 * Stop device: disable rx and tx functions to allow for reconfiguring.
946 ionic_dev_stop(struct rte_eth_dev *eth_dev)
948 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
953 err = ionic_lif_stop(lif);
955 IONIC_PRINT(ERR, "Cannot stop LIF: %d", err);
959 * Reset and stop device.
962 ionic_dev_close(struct rte_eth_dev *eth_dev)
964 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
969 err = ionic_lif_stop(lif);
971 IONIC_PRINT(ERR, "Cannot stop LIF: %d", err);
975 err = eth_ionic_dev_uninit(eth_dev);
977 IONIC_PRINT(ERR, "Cannot destroy LIF: %d", err);
983 eth_ionic_dev_init(struct rte_eth_dev *eth_dev, void *init_params)
985 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
986 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
987 struct ionic_adapter *adapter = (struct ionic_adapter *)init_params;
992 eth_dev->dev_ops = &ionic_eth_dev_ops;
993 eth_dev->rx_pkt_burst = &ionic_recv_pkts;
994 eth_dev->tx_pkt_burst = &ionic_xmit_pkts;
995 eth_dev->tx_pkt_prepare = &ionic_prep_pkts;
997 /* Multi-process not supported, primary does initialization anyway */
998 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1001 rte_eth_copy_pci_info(eth_dev, pci_dev);
1003 lif->index = adapter->nlifs;
1004 lif->eth_dev = eth_dev;
1005 lif->adapter = adapter;
1006 adapter->lifs[adapter->nlifs] = lif;
1008 IONIC_PRINT(DEBUG, "Up to %u MAC addresses supported",
1009 adapter->max_mac_addrs);
1011 /* Allocate memory for storing MAC addresses */
1012 eth_dev->data->mac_addrs = rte_zmalloc("ionic",
1013 RTE_ETHER_ADDR_LEN * adapter->max_mac_addrs, 0);
1015 if (eth_dev->data->mac_addrs == NULL) {
1016 IONIC_PRINT(ERR, "Failed to allocate %u bytes needed to "
1017 "store MAC addresses",
1018 RTE_ETHER_ADDR_LEN * adapter->max_mac_addrs);
1023 err = ionic_lif_alloc(lif);
1025 IONIC_PRINT(ERR, "Cannot allocate LIFs: %d, aborting",
1030 err = ionic_lif_init(lif);
1032 IONIC_PRINT(ERR, "Cannot init LIFs: %d, aborting", err);
1036 /* Copy the MAC address */
1037 rte_ether_addr_copy((struct rte_ether_addr *)lif->mac_addr,
1038 ð_dev->data->mac_addrs[0]);
1040 IONIC_PRINT(DEBUG, "Port %u initialized", eth_dev->data->port_id);
1045 ionic_lif_free(lif);
1051 eth_ionic_dev_uninit(struct rte_eth_dev *eth_dev)
1053 struct ionic_lif *lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
1054 struct ionic_adapter *adapter = lif->adapter;
1058 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1061 adapter->lifs[lif->index] = NULL;
1063 ionic_lif_deinit(lif);
1064 ionic_lif_free(lif);
1066 eth_dev->dev_ops = NULL;
1067 eth_dev->rx_pkt_burst = NULL;
1068 eth_dev->tx_pkt_burst = NULL;
1069 eth_dev->tx_pkt_prepare = NULL;
1075 ionic_configure_intr(struct ionic_adapter *adapter)
1077 struct rte_pci_device *pci_dev = adapter->pci_dev;
1078 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1081 IONIC_PRINT(DEBUG, "Configuring %u intrs", adapter->nintrs);
1083 if (rte_intr_efd_enable(intr_handle, adapter->nintrs)) {
1084 IONIC_PRINT(ERR, "Fail to create eventfd");
1088 if (rte_intr_dp_is_en(intr_handle))
1090 "Packet I/O interrupt on datapath is enabled");
1092 if (!intr_handle->intr_vec) {
1093 intr_handle->intr_vec = rte_zmalloc("intr_vec",
1094 adapter->nintrs * sizeof(int), 0);
1096 if (!intr_handle->intr_vec) {
1097 IONIC_PRINT(ERR, "Failed to allocate %u vectors",
1103 err = rte_intr_callback_register(intr_handle,
1104 ionic_dev_interrupt_handler,
1109 "Failure registering interrupts handler (%d)",
1114 /* enable intr mapping */
1115 err = rte_intr_enable(intr_handle);
1118 IONIC_PRINT(ERR, "Failure enabling interrupts (%d)", err);
1126 ionic_unconfigure_intr(struct ionic_adapter *adapter)
1128 struct rte_pci_device *pci_dev = adapter->pci_dev;
1129 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1131 rte_intr_disable(intr_handle);
1133 rte_intr_callback_unregister(intr_handle,
1134 ionic_dev_interrupt_handler,
1139 eth_ionic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1140 struct rte_pci_device *pci_dev)
1142 char name[RTE_ETH_NAME_MAX_LEN];
1143 struct rte_mem_resource *resource;
1144 struct ionic_adapter *adapter;
1145 struct ionic_hw *hw;
1149 /* Check structs (trigger error at compilation time) */
1150 ionic_struct_size_checks();
1152 /* Multi-process not supported */
1153 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1158 IONIC_PRINT(DEBUG, "Initializing device %s",
1159 pci_dev->device.name);
1161 adapter = rte_zmalloc("ionic", sizeof(*adapter), 0);
1163 IONIC_PRINT(ERR, "OOM");
1168 adapter->pci_dev = pci_dev;
1171 hw->device_id = pci_dev->id.device_id;
1172 hw->vendor_id = pci_dev->id.vendor_id;
1174 err = ionic_init_mac(hw);
1176 IONIC_PRINT(ERR, "Mac init failed: %d", err);
1178 goto err_free_adapter;
1181 adapter->is_mgmt_nic = (pci_dev->id.device_id == IONIC_DEV_ID_ETH_MGMT);
1183 adapter->num_bars = 0;
1184 for (i = 0; i < PCI_MAX_RESOURCE && i < IONIC_BARS_MAX; i++) {
1185 resource = &pci_dev->mem_resource[i];
1186 if (resource->phys_addr == 0 || resource->len == 0)
1188 adapter->bars[adapter->num_bars].vaddr = resource->addr;
1189 adapter->bars[adapter->num_bars].bus_addr = resource->phys_addr;
1190 adapter->bars[adapter->num_bars].len = resource->len;
1191 adapter->num_bars++;
1194 /* Discover ionic dev resources */
1196 err = ionic_setup(adapter);
1198 IONIC_PRINT(ERR, "Cannot setup device: %d, aborting", err);
1199 goto err_free_adapter;
1202 err = ionic_identify(adapter);
1204 IONIC_PRINT(ERR, "Cannot identify device: %d, aborting",
1206 goto err_free_adapter;
1209 err = ionic_init(adapter);
1211 IONIC_PRINT(ERR, "Cannot init device: %d, aborting", err);
1212 goto err_free_adapter;
1215 /* Configure the ports */
1216 err = ionic_port_identify(adapter);
1218 IONIC_PRINT(ERR, "Cannot identify port: %d, aborting",
1220 goto err_free_adapter;
1223 err = ionic_port_init(adapter);
1225 IONIC_PRINT(ERR, "Cannot init port: %d, aborting", err);
1226 goto err_free_adapter;
1229 /* Configure LIFs */
1230 err = ionic_lif_identify(adapter);
1232 IONIC_PRINT(ERR, "Cannot identify lif: %d, aborting", err);
1233 goto err_free_adapter;
1236 /* Allocate and init LIFs */
1237 err = ionic_lifs_size(adapter);
1239 IONIC_PRINT(ERR, "Cannot size LIFs: %d, aborting", err);
1240 goto err_free_adapter;
1243 adapter->max_mac_addrs = adapter->ident.lif.eth.max_ucast_filters;
1246 for (i = 0; i < adapter->ident.dev.nlifs; i++) {
1247 snprintf(name, sizeof(name), "net_%s_lif_%lu",
1248 pci_dev->device.name, i);
1250 err = rte_eth_dev_create(&pci_dev->device, name,
1251 sizeof(struct ionic_lif),
1253 eth_ionic_dev_init, adapter);
1255 IONIC_PRINT(ERR, "Cannot create eth device for "
1256 "ionic lif %s", name);
1263 err = ionic_configure_intr(adapter);
1266 IONIC_PRINT(ERR, "Failed to configure interrupts");
1267 goto err_free_adapter;
1279 eth_ionic_pci_remove(struct rte_pci_device *pci_dev __rte_unused)
1281 char name[RTE_ETH_NAME_MAX_LEN];
1282 struct ionic_adapter *adapter = NULL;
1283 struct rte_eth_dev *eth_dev;
1284 struct ionic_lif *lif;
1287 /* Adapter lookup is using (the first) eth_dev name */
1288 snprintf(name, sizeof(name), "net_%s_lif_0",
1289 pci_dev->device.name);
1291 eth_dev = rte_eth_dev_allocated(name);
1293 lif = IONIC_ETH_DEV_TO_LIF(eth_dev);
1294 adapter = lif->adapter;
1298 ionic_unconfigure_intr(adapter);
1300 for (i = 0; i < adapter->nlifs; i++) {
1301 lif = adapter->lifs[i];
1302 rte_eth_dev_destroy(lif->eth_dev, eth_ionic_dev_uninit);
1311 static struct rte_pci_driver rte_ionic_pmd = {
1312 .id_table = pci_id_ionic_map,
1313 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1314 .probe = eth_ionic_pci_probe,
1315 .remove = eth_ionic_pci_remove,
1318 RTE_PMD_REGISTER_PCI(net_ionic, rte_ionic_pmd);
1319 RTE_PMD_REGISTER_PCI_TABLE(net_ionic, pci_id_ionic_map);
1320 RTE_PMD_REGISTER_KMOD_DEP(net_ionic, "* igb_uio | uio_pci_generic | vfio-pci");
1322 RTE_INIT(ionic_init_log)
1324 ionic_logtype = rte_log_register("pmd.net.ionic");
1325 if (ionic_logtype >= 0)
1326 rte_log_set_level(ionic_logtype, RTE_LOG_NOTICE);