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