xref: /dpdk/drivers/net/ionic/ionic_lif.h (revision 2aed9865)
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  * Copyright(c) 2018-2019 Pensando Systems, Inc. All rights reserved.
3  */
4 
5 #ifndef _IONIC_LIF_H_
6 #define _IONIC_LIF_H_
7 
8 #include <inttypes.h>
9 
10 #include <rte_ethdev.h>
11 #include <rte_ether.h>
12 
13 #include "ionic_osdep.h"
14 #include "ionic_dev.h"
15 #include "ionic_rx_filter.h"
16 
17 #define IONIC_ADMINQ_LENGTH	16	/* must be a power of two */
18 #define IONIC_NOTIFYQ_LENGTH	64	/* must be a power of two */
19 
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)
27 
28 #define IONIC_GET_SG_CNTR_IDX(num_sg_elems)	(num_sg_elems)
29 
30 struct ionic_tx_stats {
31 	uint64_t packets;
32 	uint64_t bytes;
33 	uint64_t drop;
34 	uint64_t stop;
35 	uint64_t no_csum;
36 	uint64_t tso;
37 	uint64_t frags;
38 };
39 
40 struct ionic_rx_stats {
41 	uint64_t packets;
42 	uint64_t bytes;
43 	uint64_t no_cb_arg;
44 	uint64_t bad_cq_status;
45 	uint64_t no_room;
46 	uint64_t bad_len;
47 };
48 
49 #define IONIC_QCQ_F_INITED	BIT(0)
50 #define IONIC_QCQ_F_SG		BIT(1)
51 #define IONIC_QCQ_F_DEFERRED	BIT(4)
52 #define IONIC_QCQ_F_CSUM_L3	BIT(7)
53 #define IONIC_QCQ_F_CSUM_UDP	BIT(8)
54 #define IONIC_QCQ_F_CSUM_TCP	BIT(9)
55 
56 /* Queue / Completion Queue */
57 struct ionic_qcq {
58 	struct ionic_queue q;        /**< Queue */
59 	struct ionic_cq cq;          /**< Completion Queue */
60 	struct ionic_lif *lif;       /**< LIF */
61 	struct rte_mempool *mb_pool; /**< mbuf pool to populate the RX ring */
62 	union {
63 		struct ionic_tx_stats tx;
64 		struct ionic_rx_stats rx;
65 	} stats;
66 	const struct rte_memzone *base_z;
67 	void *base;
68 	rte_iova_t base_pa;
69 	uint32_t total_size;
70 	uint32_t flags;
71 	struct ionic_intr_info intr;
72 };
73 
74 #define IONIC_Q_TO_QCQ(_q)	container_of(_q, struct ionic_qcq, q)
75 #define IONIC_CQ_TO_QCQ(_cq)	container_of(_cq, struct ionic_qcq, cq)
76 #define IONIC_Q_TO_TX_STATS(q)	(&IONIC_Q_TO_QCQ(q)->stats.tx)
77 #define IONIC_Q_TO_RX_STATS(q)	(&IONIC_Q_TO_QCQ(q)->stats.rx)
78 
79 struct ionic_qtype_info {
80 	uint8_t  version;
81 	uint8_t  supported;
82 	uint64_t features;
83 	uint16_t desc_sz;
84 	uint16_t comp_sz;
85 	uint16_t sg_desc_sz;
86 	uint16_t max_sg_elems;
87 	uint16_t sg_desc_stride;
88 };
89 
90 #define IONIC_LIF_F_INITED		BIT(0)
91 #define IONIC_LIF_F_LINK_CHECK_NEEDED	BIT(1)
92 #define IONIC_LIF_F_UP			BIT(2)
93 #define IONIC_LIF_F_FW_RESET		BIT(3)
94 
95 #define IONIC_LIF_NAME_MAX_SZ		(32)
96 
97 struct ionic_lif {
98 	struct ionic_adapter *adapter;
99 	struct rte_eth_dev *eth_dev;
100 	uint16_t port_id;  /**< Device port identifier */
101 	uint32_t hw_index;
102 	uint32_t state;
103 	uint32_t ntxqcqs;
104 	uint32_t nrxqcqs;
105 	rte_spinlock_t adminq_lock;
106 	rte_spinlock_t adminq_service_lock;
107 	struct ionic_qcq *adminqcq;
108 	struct ionic_qcq *notifyqcq;
109 	struct ionic_qcq **txqcqs;
110 	struct ionic_qcq **rxqcqs;
111 	struct ionic_rx_filters rx_filters;
112 	struct ionic_doorbell __iomem *kern_dbpage;
113 	uint64_t last_eid;
114 	uint64_t features;
115 	uint32_t hw_features;
116 	uint32_t rx_mode;
117 	char name[IONIC_LIF_NAME_MAX_SZ];
118 	uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
119 	uint16_t rss_types;
120 	uint8_t rss_hash_key[IONIC_RSS_HASH_KEY_SIZE];
121 	uint8_t *rss_ind_tbl;
122 	rte_iova_t rss_ind_tbl_pa;
123 	const struct rte_memzone *rss_ind_tbl_z;
124 	uint32_t rss_ind_tbl_nrxqcqs;
125 	uint32_t info_sz;
126 	struct ionic_lif_info *info;
127 	rte_iova_t info_pa;
128 	const struct rte_memzone *info_z;
129 
130 	struct ionic_qtype_info qtype_info[IONIC_QTYPE_MAX];
131 	uint8_t qtype_ver[IONIC_QTYPE_MAX];
132 
133 	struct rte_eth_stats stats_base;
134 	struct ionic_lif_stats lif_stats_base;
135 };
136 
137 int ionic_lif_identify(struct ionic_adapter *adapter);
138 int ionic_lifs_size(struct ionic_adapter *ionic);
139 
140 int ionic_lif_alloc(struct ionic_lif *lif);
141 void ionic_lif_free(struct ionic_lif *lif);
142 void ionic_lif_free_queues(struct ionic_lif *lif);
143 
144 int ionic_lif_init(struct ionic_lif *lif);
145 void ionic_lif_deinit(struct ionic_lif *lif);
146 
147 int ionic_lif_start(struct ionic_lif *lif);
148 void ionic_lif_stop(struct ionic_lif *lif);
149 
150 void ionic_lif_configure(struct ionic_lif *lif);
151 void ionic_lif_configure_vlan_offload(struct ionic_lif *lif, int mask);
152 void ionic_lif_reset(struct ionic_lif *lif);
153 
154 int ionic_intr_alloc(struct ionic_lif *lif, struct ionic_intr_info *intr);
155 void ionic_intr_free(struct ionic_lif *lif, struct ionic_intr_info *intr);
156 
157 bool ionic_adminq_service(struct ionic_cq *cq, uint32_t cq_desc_index,
158 	void *cb_arg);
159 int ionic_qcq_service(struct ionic_qcq *qcq, int budget, ionic_cq_cb cb,
160 	void *cb_arg);
161 
162 int ionic_lif_change_mtu(struct ionic_lif *lif, int new_mtu);
163 
164 int ionic_dev_add_mac(struct rte_eth_dev *eth_dev,
165 	struct rte_ether_addr *mac_addr,
166 	uint32_t index __rte_unused, uint32_t pool __rte_unused);
167 void ionic_dev_remove_mac(struct rte_eth_dev *eth_dev,
168 	uint32_t index __rte_unused);
169 int ionic_dev_set_mac(struct rte_eth_dev *eth_dev,
170 	struct rte_ether_addr *mac_addr);
171 int ionic_dev_vlan_filter_set(struct rte_eth_dev *eth_dev, uint16_t vlan_id,
172 	int on);
173 int ionic_dev_promiscuous_enable(struct rte_eth_dev *dev);
174 int ionic_dev_promiscuous_disable(struct rte_eth_dev *dev);
175 int ionic_dev_allmulticast_enable(struct rte_eth_dev *dev);
176 int ionic_dev_allmulticast_disable(struct rte_eth_dev *dev);
177 
178 int ionic_rx_qcq_alloc(struct ionic_lif *lif, uint32_t index,
179 	uint16_t nrxq_descs, struct ionic_qcq **qcq);
180 int ionic_tx_qcq_alloc(struct ionic_lif *lif, uint32_t index,
181 	uint16_t ntxq_descs, struct ionic_qcq **qcq);
182 void ionic_qcq_free(struct ionic_qcq *qcq);
183 
184 int ionic_qcq_enable(struct ionic_qcq *qcq);
185 int ionic_qcq_disable(struct ionic_qcq *qcq);
186 
187 int ionic_lif_rxq_init(struct ionic_qcq *qcq);
188 void ionic_lif_rxq_deinit(struct ionic_qcq *qcq);
189 
190 int ionic_lif_txq_init(struct ionic_qcq *qcq);
191 void ionic_lif_txq_deinit(struct ionic_qcq *qcq);
192 
193 int ionic_lif_rss_config(struct ionic_lif *lif, const uint16_t types,
194 	const uint8_t *key, const uint32_t *indir);
195 
196 int ionic_lif_set_features(struct ionic_lif *lif);
197 
198 void ionic_lif_get_stats(const struct ionic_lif *lif,
199 	struct rte_eth_stats *stats);
200 void ionic_lif_reset_stats(struct ionic_lif *lif);
201 
202 void ionic_lif_get_hw_stats(struct ionic_lif *lif,
203 	struct ionic_lif_stats *stats);
204 void ionic_lif_reset_hw_stats(struct ionic_lif *lif);
205 
206 int ionic_notifyq_handler(struct ionic_lif *lif, int budget);
207 
208 #endif /* _IONIC_LIF_H_ */
209