1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 * Copyright(c) 2018-2019 Pensando Systems, Inc. All rights reserved.
10 #include <rte_ethdev.h>
11 #include <rte_ether.h>
13 #include "ionic_osdep.h"
14 #include "ionic_dev.h"
15 #include "ionic_rx_filter.h"
17 #define IONIC_ADMINQ_LENGTH 16 /* must be a power of two */
18 #define IONIC_NOTIFYQ_LENGTH 64 /* must be a power of two */
20 #define IONIC_RSS_OFFLOAD_ALL ( \
21 IONIC_RSS_TYPE_IPV4 | \
22 IONIC_RSS_TYPE_IPV4_TCP | \
23 IONIC_RSS_TYPE_IPV4_UDP | \
24 IONIC_RSS_TYPE_IPV6 | \
25 IONIC_RSS_TYPE_IPV6_TCP | \
26 IONIC_RSS_TYPE_IPV6_UDP)
28 #define IONIC_GET_SG_CNTR_IDX(num_sg_elems) (num_sg_elems)
30 struct ionic_tx_stats {
40 struct ionic_rx_stats {
44 uint64_t bad_cq_status;
49 #define IONIC_QCQ_F_INITED BIT(0)
50 #define IONIC_QCQ_F_SG BIT(1)
51 #define IONIC_QCQ_F_INTR BIT(2)
52 #define IONIC_QCQ_F_NOTIFYQ BIT(3)
54 /* Queue / Completion Queue */
57 struct ionic_queue q; /**< Queue */
58 struct ionic_cq cq; /**< Completion Queue */
59 struct ionic_lif *lif; /**< LIF */
60 struct rte_mempool *mb_pool; /**< mbuf pool to populate the RX ring */
62 struct ionic_tx_stats tx;
63 struct ionic_rx_stats rx;
65 const struct rte_memzone *base_z;
70 struct ionic_intr_info intr;
74 #define IONIC_Q_TO_QCQ(q) container_of(q, struct ionic_qcq, q)
75 #define IONIC_Q_TO_TX_STATS(q) (&IONIC_Q_TO_QCQ(q)->stats.tx)
76 #define IONIC_Q_TO_RX_STATS(q) (&IONIC_Q_TO_QCQ(q)->stats.rx)
78 #define IONIC_LIF_F_INITED BIT(0)
79 #define IONIC_LIF_F_LINK_CHECK_NEEDED BIT(1)
81 #define IONIC_LIF_NAME_MAX_SZ (32)
84 struct ionic_adapter *adapter;
85 struct rte_eth_dev *eth_dev;
86 uint16_t port_id; /**< Device port identifier */
94 rte_spinlock_t adminq_lock;
95 rte_spinlock_t adminq_service_lock;
96 struct ionic_qcq *adminqcq;
97 struct ionic_qcq *notifyqcq;
98 struct ionic_qcq **txqcqs;
99 struct ionic_qcq **rxqcqs;
100 struct ionic_rx_filters rx_filters;
101 struct ionic_doorbell __iomem *kern_dbpage;
104 uint32_t hw_features;
106 char name[IONIC_LIF_NAME_MAX_SZ];
107 uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
109 uint8_t rss_hash_key[IONIC_RSS_HASH_KEY_SIZE];
110 uint8_t *rss_ind_tbl;
111 rte_iova_t rss_ind_tbl_pa;
112 const struct rte_memzone *rss_ind_tbl_z;
114 struct ionic_lif_info *info;
116 const struct rte_memzone *info_z;
117 struct rte_eth_stats stats_base;
118 struct ionic_lif_stats lif_stats_base;
121 int ionic_lif_identify(struct ionic_adapter *adapter);
122 int ionic_lifs_size(struct ionic_adapter *ionic);
124 int ionic_lif_alloc(struct ionic_lif *lif);
125 void ionic_lif_free(struct ionic_lif *lif);
127 int ionic_lif_init(struct ionic_lif *lif);
128 void ionic_lif_deinit(struct ionic_lif *lif);
130 int ionic_lif_start(struct ionic_lif *lif);
131 int ionic_lif_stop(struct ionic_lif *lif);
133 int ionic_lif_configure(struct ionic_lif *lif);
134 void ionic_lif_reset(struct ionic_lif *lif);
136 int ionic_intr_alloc(struct ionic_lif *lif, struct ionic_intr_info *intr);
137 void ionic_intr_free(struct ionic_lif *lif, struct ionic_intr_info *intr);
139 bool ionic_adminq_service(struct ionic_cq *cq, uint32_t cq_desc_index,
141 int ionic_qcq_service(struct ionic_qcq *qcq, int budget, ionic_cq_cb cb,
144 int ionic_lif_change_mtu(struct ionic_lif *lif, int new_mtu);
146 int ionic_dev_add_mac(struct rte_eth_dev *eth_dev,
147 struct rte_ether_addr *mac_addr,
148 uint32_t index __rte_unused, uint32_t pool __rte_unused);
149 void ionic_dev_remove_mac(struct rte_eth_dev *eth_dev,
150 uint32_t index __rte_unused);
151 int ionic_dev_set_mac(struct rte_eth_dev *eth_dev,
152 struct rte_ether_addr *mac_addr);
153 int ionic_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id,
155 int ionic_dev_promiscuous_enable(struct rte_eth_dev *dev);
156 int ionic_dev_promiscuous_disable(struct rte_eth_dev *dev);
157 int ionic_dev_allmulticast_enable(struct rte_eth_dev *dev);
158 int ionic_dev_allmulticast_disable(struct rte_eth_dev *dev);
160 int ionic_rx_qcq_alloc(struct ionic_lif *lif, uint32_t index,
161 uint16_t nrxq_descs, struct ionic_qcq **qcq);
162 int ionic_tx_qcq_alloc(struct ionic_lif *lif, uint32_t index,
163 uint16_t ntxq_descs, struct ionic_qcq **qcq);
164 void ionic_qcq_free(struct ionic_qcq *qcq);
166 int ionic_qcq_enable(struct ionic_qcq *qcq);
167 int ionic_qcq_disable(struct ionic_qcq *qcq);
169 int ionic_lif_rxq_init(struct ionic_qcq *qcq);
170 void ionic_lif_rxq_deinit(struct ionic_qcq *qcq);
172 int ionic_lif_txq_init(struct ionic_qcq *qcq);
173 void ionic_lif_txq_deinit(struct ionic_qcq *qcq);
175 int ionic_lif_rss_config(struct ionic_lif *lif, const uint16_t types,
176 const uint8_t *key, const uint32_t *indir);
178 int ionic_lif_set_features(struct ionic_lif *lif);
180 void ionic_lif_get_stats(const struct ionic_lif *lif,
181 struct rte_eth_stats *stats);
182 void ionic_lif_reset_stats(struct ionic_lif *lif);
184 void ionic_lif_get_hw_stats(struct ionic_lif *lif,
185 struct ionic_lif_stats *stats);
186 void ionic_lif_reset_hw_stats(struct ionic_lif *lif);
188 int ionic_notifyq_handler(struct ionic_lif *lif, int budget);
190 #endif /* _IONIC_LIF_H_ */