net/octeontx2: add Rx queue setup and release
[dpdk.git] / drivers / net / octeontx2 / otx2_ethdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef __OTX2_ETHDEV_H__
6 #define __OTX2_ETHDEV_H__
7
8 #include <stdint.h>
9
10 #include <rte_common.h>
11 #include <rte_ethdev.h>
12 #include <rte_kvargs.h>
13 #include <rte_mbuf.h>
14 #include <rte_mempool.h>
15 #include <rte_string_fns.h>
16
17 #include "otx2_common.h"
18 #include "otx2_dev.h"
19 #include "otx2_irq.h"
20 #include "otx2_mempool.h"
21 #include "otx2_rx.h"
22
23 #define OTX2_ETH_DEV_PMD_VERSION        "1.0"
24
25 /* Ethdev HWCAP and Fixup flags. Use from MSB bits to avoid conflict with dev */
26
27 /* Minimum CQ size should be 4K */
28 #define OTX2_FIXUP_F_MIN_4K_Q           BIT_ULL(63)
29 #define otx2_ethdev_fixup_is_min_4k_q(dev)      \
30                                 ((dev)->hwcap & OTX2_FIXUP_F_MIN_4K_Q)
31 /* Limit CQ being full */
32 #define OTX2_FIXUP_F_LIMIT_CQ_FULL      BIT_ULL(62)
33 #define otx2_ethdev_fixup_is_limit_cq_full(dev) \
34                                 ((dev)->hwcap & OTX2_FIXUP_F_LIMIT_CQ_FULL)
35
36 /* Used for struct otx2_eth_dev::flags */
37 #define OTX2_LINK_CFG_IN_PROGRESS_F     BIT_ULL(0)
38
39 /* VLAN tag inserted by NIX_TX_VTAG_ACTION.
40  * In Tx space is always reserved for this in FRS.
41  */
42 #define NIX_MAX_VTAG_INS                2
43 #define NIX_MAX_VTAG_ACT_SIZE           (4 * NIX_MAX_VTAG_INS)
44
45 /* ETH_HLEN+ETH_FCS+2*VLAN_HLEN */
46 #define NIX_L2_OVERHEAD \
47         (RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + 8)
48
49 /* HW config of frame size doesn't include FCS */
50 #define NIX_MAX_HW_FRS                  9212
51 #define NIX_MIN_HW_FRS                  60
52
53 /* Since HW FRS includes NPC VTAG insertion space, user has reduced FRS */
54 #define NIX_MAX_FRS     \
55         (NIX_MAX_HW_FRS + RTE_ETHER_CRC_LEN - NIX_MAX_VTAG_ACT_SIZE)
56
57 #define NIX_MIN_FRS     \
58         (NIX_MIN_HW_FRS + RTE_ETHER_CRC_LEN)
59
60 #define NIX_MAX_MTU     \
61         (NIX_MAX_FRS - NIX_L2_OVERHEAD)
62
63 #define NIX_MAX_SQB                     512
64 #define NIX_MIN_SQB                     32
65 #define NIX_RSS_RETA_SIZE_MAX           256
66 /* Group 0 will be used for RSS, 1 -7 will be used for rte_flow RSS action*/
67 #define NIX_RSS_GRPS                    8
68 #define NIX_HASH_KEY_SIZE               48 /* 352 Bits */
69 #define NIX_RSS_RETA_SIZE               64
70 #define NIX_RX_MIN_DESC                 16
71 #define NIX_RX_MIN_DESC_ALIGN           16
72 #define NIX_RX_NB_SEG_MAX               6
73 #define NIX_CQ_ENTRY_SZ                 128
74 #define NIX_CQ_ALIGN                    512
75
76 /* If PTP is enabled additional SEND MEM DESC is required which
77  * takes 2 words, hence max 7 iova address are possible
78  */
79 #if defined(RTE_LIBRTE_IEEE1588)
80 #define NIX_TX_NB_SEG_MAX               7
81 #else
82 #define NIX_TX_NB_SEG_MAX               9
83 #endif
84
85 #define CQ_OP_STAT_OP_ERR       63
86 #define CQ_OP_STAT_CQ_ERR       46
87
88 #define OP_ERR                  BIT_ULL(CQ_OP_STAT_OP_ERR)
89 #define CQ_ERR                  BIT_ULL(CQ_OP_STAT_CQ_ERR)
90
91 #define NIX_RSS_OFFLOAD         (ETH_RSS_PORT | ETH_RSS_IP | ETH_RSS_UDP |\
92                                  ETH_RSS_TCP | ETH_RSS_SCTP | \
93                                  ETH_RSS_TUNNEL | ETH_RSS_L2_PAYLOAD)
94
95 #define NIX_TX_OFFLOAD_CAPA ( \
96         DEV_TX_OFFLOAD_MBUF_FAST_FREE   | \
97         DEV_TX_OFFLOAD_MT_LOCKFREE      | \
98         DEV_TX_OFFLOAD_VLAN_INSERT      | \
99         DEV_TX_OFFLOAD_QINQ_INSERT      | \
100         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM | \
101         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM  | \
102         DEV_TX_OFFLOAD_TCP_CKSUM        | \
103         DEV_TX_OFFLOAD_UDP_CKSUM        | \
104         DEV_TX_OFFLOAD_SCTP_CKSUM       | \
105         DEV_TX_OFFLOAD_MULTI_SEGS       | \
106         DEV_TX_OFFLOAD_IPV4_CKSUM)
107
108 #define NIX_RX_OFFLOAD_CAPA ( \
109         DEV_RX_OFFLOAD_CHECKSUM         | \
110         DEV_RX_OFFLOAD_SCTP_CKSUM       | \
111         DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM | \
112         DEV_RX_OFFLOAD_SCATTER          | \
113         DEV_RX_OFFLOAD_JUMBO_FRAME      | \
114         DEV_RX_OFFLOAD_OUTER_UDP_CKSUM | \
115         DEV_RX_OFFLOAD_VLAN_STRIP | \
116         DEV_RX_OFFLOAD_VLAN_FILTER | \
117         DEV_RX_OFFLOAD_QINQ_STRIP | \
118         DEV_RX_OFFLOAD_TIMESTAMP)
119
120 #define NIX_DEFAULT_RSS_CTX_GROUP  0
121 #define NIX_DEFAULT_RSS_MCAM_IDX  -1
122
123 enum nix_q_size_e {
124         nix_q_size_16,  /* 16 entries */
125         nix_q_size_64,  /* 64 entries */
126         nix_q_size_256,
127         nix_q_size_1K,
128         nix_q_size_4K,
129         nix_q_size_16K,
130         nix_q_size_64K,
131         nix_q_size_256K,
132         nix_q_size_1M,  /* Million entries */
133         nix_q_size_max
134 };
135
136 struct otx2_qint {
137         struct rte_eth_dev *eth_dev;
138         uint8_t qintx;
139 };
140
141 struct otx2_rss_info {
142         uint64_t nix_rss;
143         uint32_t flowkey_cfg;
144         uint16_t rss_size;
145         uint8_t rss_grps;
146         uint8_t alg_idx; /* Selected algo index */
147         uint16_t ind_tbl[NIX_RSS_RETA_SIZE_MAX];
148         uint8_t key[NIX_HASH_KEY_SIZE];
149 };
150
151 struct otx2_eth_qconf {
152         union {
153                 struct rte_eth_txconf tx;
154                 struct rte_eth_rxconf rx;
155         } conf;
156         void *mempool;
157         uint32_t socket_id;
158         uint16_t nb_desc;
159 };
160
161 struct otx2_npc_flow_info {
162         uint16_t channel; /*rx channel */
163         uint16_t flow_prealloc_size;
164         uint16_t flow_max_priority;
165 };
166
167 struct otx2_eth_dev {
168         OTX2_DEV; /* Base class */
169         MARKER otx2_eth_dev_data_start;
170         uint16_t sqb_size;
171         uint16_t rx_chan_base;
172         uint16_t tx_chan_base;
173         uint8_t rx_chan_cnt;
174         uint8_t tx_chan_cnt;
175         uint8_t lso_tsov4_idx;
176         uint8_t lso_tsov6_idx;
177         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
178         uint8_t max_mac_entries;
179         uint8_t lf_tx_stats;
180         uint8_t lf_rx_stats;
181         uint16_t flags;
182         uint16_t cints;
183         uint16_t qints;
184         uint8_t configured;
185         uint8_t configured_qints;
186         uint8_t configured_nb_rx_qs;
187         uint8_t configured_nb_tx_qs;
188         uint16_t nix_msixoff;
189         uintptr_t base;
190         uintptr_t lmt_addr;
191         uint16_t scalar_ena;
192         uint16_t max_sqb_count;
193         uint16_t rx_offload_flags; /* Selected Rx offload flags(NIX_RX_*_F) */
194         uint64_t rx_offloads;
195         uint16_t tx_offload_flags; /* Selected Tx offload flags(NIX_TX_*_F) */
196         uint64_t tx_offloads;
197         uint64_t rx_offload_capa;
198         uint64_t tx_offload_capa;
199         struct otx2_qint qints_mem[RTE_MAX_QUEUES_PER_PORT];
200         struct otx2_rss_info rss_info;
201         uint32_t txmap[RTE_ETHDEV_QUEUE_STAT_CNTRS];
202         uint32_t rxmap[RTE_ETHDEV_QUEUE_STAT_CNTRS];
203         struct otx2_npc_flow_info npc_flow;
204         struct rte_eth_dev *eth_dev;
205 } __rte_cache_aligned;
206
207 struct otx2_eth_rxq {
208         uint64_t mbuf_initializer;
209         uint64_t data_off;
210         uintptr_t desc;
211         void *lookup_mem;
212         uintptr_t cq_door;
213         uint64_t wdata;
214         int64_t *cq_status;
215         uint32_t head;
216         uint32_t qmask;
217         uint32_t available;
218         uint16_t rq;
219         struct otx2_timesync_info *tstamp;
220         MARKER slow_path_start;
221         uint64_t aura;
222         uint64_t offloads;
223         uint32_t qlen;
224         struct rte_mempool *pool;
225         enum nix_q_size_e qsize;
226         struct rte_eth_dev *eth_dev;
227         struct otx2_eth_qconf qconf;
228 } __rte_cache_aligned;
229
230 static inline struct otx2_eth_dev *
231 otx2_eth_pmd_priv(struct rte_eth_dev *eth_dev)
232 {
233         return eth_dev->data->dev_private;
234 }
235
236 /* Ops */
237 void otx2_nix_info_get(struct rte_eth_dev *eth_dev,
238                        struct rte_eth_dev_info *dev_info);
239
240 void otx2_nix_promisc_config(struct rte_eth_dev *eth_dev, int en);
241 void otx2_nix_promisc_enable(struct rte_eth_dev *eth_dev);
242 void otx2_nix_promisc_disable(struct rte_eth_dev *eth_dev);
243 void otx2_nix_allmulticast_enable(struct rte_eth_dev *eth_dev);
244 void otx2_nix_allmulticast_disable(struct rte_eth_dev *eth_dev);
245 uint64_t otx2_nix_rxq_mbuf_setup(struct otx2_eth_dev *dev, uint16_t port_id);
246
247 /* Link */
248 void otx2_nix_toggle_flag_link_cfg(struct otx2_eth_dev *dev, bool set);
249 int otx2_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete);
250 void otx2_eth_dev_link_status_update(struct otx2_dev *dev,
251                                      struct cgx_link_user_info *link);
252
253 /* IRQ */
254 int otx2_nix_register_irqs(struct rte_eth_dev *eth_dev);
255 int oxt2_nix_register_queue_irqs(struct rte_eth_dev *eth_dev);
256 void otx2_nix_unregister_irqs(struct rte_eth_dev *eth_dev);
257 void oxt2_nix_unregister_queue_irqs(struct rte_eth_dev *eth_dev);
258
259 /* Debug */
260 int otx2_nix_reg_dump(struct otx2_eth_dev *dev, uint64_t *data);
261 int otx2_nix_dev_get_reg(struct rte_eth_dev *eth_dev,
262                          struct rte_dev_reg_info *regs);
263 int otx2_nix_queues_ctx_dump(struct rte_eth_dev *eth_dev);
264 void otx2_nix_cqe_dump(const struct nix_cqe_hdr_s *cq);
265
266 /* Stats */
267 int otx2_nix_dev_stats_get(struct rte_eth_dev *eth_dev,
268                            struct rte_eth_stats *stats);
269 void otx2_nix_dev_stats_reset(struct rte_eth_dev *eth_dev);
270
271 int otx2_nix_queue_stats_mapping(struct rte_eth_dev *dev,
272                                  uint16_t queue_id, uint8_t stat_idx,
273                                  uint8_t is_rx);
274 int otx2_nix_xstats_get(struct rte_eth_dev *eth_dev,
275                         struct rte_eth_xstat *xstats, unsigned int n);
276 int otx2_nix_xstats_get_names(struct rte_eth_dev *eth_dev,
277                               struct rte_eth_xstat_name *xstats_names,
278                               unsigned int limit);
279 void otx2_nix_xstats_reset(struct rte_eth_dev *eth_dev);
280
281 int otx2_nix_xstats_get_by_id(struct rte_eth_dev *eth_dev,
282                               const uint64_t *ids,
283                               uint64_t *values, unsigned int n);
284 int otx2_nix_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
285                                     struct rte_eth_xstat_name *xstats_names,
286                                     const uint64_t *ids, unsigned int limit);
287
288 /* RSS */
289 void otx2_nix_rss_set_key(struct otx2_eth_dev *dev,
290                           uint8_t *key, uint32_t key_len);
291 uint32_t otx2_rss_ethdev_to_nix(struct otx2_eth_dev *dev,
292                                 uint64_t ethdev_rss, uint8_t rss_level);
293 int otx2_rss_set_hf(struct otx2_eth_dev *dev,
294                     uint32_t flowkey_cfg, uint8_t *alg_idx,
295                     uint8_t group, int mcam_index);
296 int otx2_nix_rss_tbl_init(struct otx2_eth_dev *dev, uint8_t group,
297                           uint16_t *ind_tbl);
298 int otx2_nix_rss_config(struct rte_eth_dev *eth_dev);
299
300 int otx2_nix_dev_reta_update(struct rte_eth_dev *eth_dev,
301                              struct rte_eth_rss_reta_entry64 *reta_conf,
302                              uint16_t reta_size);
303 int otx2_nix_dev_reta_query(struct rte_eth_dev *eth_dev,
304                             struct rte_eth_rss_reta_entry64 *reta_conf,
305                             uint16_t reta_size);
306 int otx2_nix_rss_hash_update(struct rte_eth_dev *eth_dev,
307                              struct rte_eth_rss_conf *rss_conf);
308
309 int otx2_nix_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
310                                struct rte_eth_rss_conf *rss_conf);
311
312 /* CGX */
313 int otx2_cgx_rxtx_start(struct otx2_eth_dev *dev);
314 int otx2_cgx_rxtx_stop(struct otx2_eth_dev *dev);
315 int otx2_cgx_mac_addr_set(struct rte_eth_dev *eth_dev,
316                           struct rte_ether_addr *addr);
317
318 /* Mac address handling */
319 int otx2_nix_mac_addr_set(struct rte_eth_dev *eth_dev,
320                           struct rte_ether_addr *addr);
321 int otx2_nix_mac_addr_get(struct rte_eth_dev *eth_dev, uint8_t *addr);
322 int otx2_nix_mac_addr_add(struct rte_eth_dev *eth_dev,
323                           struct rte_ether_addr *addr,
324                           uint32_t index, uint32_t pool);
325 void otx2_nix_mac_addr_del(struct rte_eth_dev *eth_dev, uint32_t index);
326 int otx2_cgx_mac_max_entries_get(struct otx2_eth_dev *dev);
327
328 /* Devargs */
329 int otx2_ethdev_parse_devargs(struct rte_devargs *devargs,
330                               struct otx2_eth_dev *dev);
331
332 #endif /* __OTX2_ETHDEV_H__ */