net/octeontx2: add link stats operations
[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 /* Group 0 will be used for RSS, 1 -7 will be used for rte_flow RSS action*/
63 #define NIX_RSS_GRPS                    8
64 #define NIX_HASH_KEY_SIZE               48 /* 352 Bits */
65 #define NIX_RSS_RETA_SIZE               64
66 #define NIX_RX_MIN_DESC                 16
67 #define NIX_RX_MIN_DESC_ALIGN           16
68 #define NIX_RX_NB_SEG_MAX               6
69 #define NIX_CQ_ENTRY_SZ                 128
70
71 /* If PTP is enabled additional SEND MEM DESC is required which
72  * takes 2 words, hence max 7 iova address are possible
73  */
74 #if defined(RTE_LIBRTE_IEEE1588)
75 #define NIX_TX_NB_SEG_MAX               7
76 #else
77 #define NIX_TX_NB_SEG_MAX               9
78 #endif
79
80 #define NIX_RSS_OFFLOAD         (ETH_RSS_PORT | ETH_RSS_IP | ETH_RSS_UDP |\
81                                  ETH_RSS_TCP | ETH_RSS_SCTP | \
82                                  ETH_RSS_TUNNEL | ETH_RSS_L2_PAYLOAD)
83
84 #define NIX_TX_OFFLOAD_CAPA ( \
85         DEV_TX_OFFLOAD_MBUF_FAST_FREE   | \
86         DEV_TX_OFFLOAD_MT_LOCKFREE      | \
87         DEV_TX_OFFLOAD_VLAN_INSERT      | \
88         DEV_TX_OFFLOAD_QINQ_INSERT      | \
89         DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM | \
90         DEV_TX_OFFLOAD_OUTER_UDP_CKSUM  | \
91         DEV_TX_OFFLOAD_TCP_CKSUM        | \
92         DEV_TX_OFFLOAD_UDP_CKSUM        | \
93         DEV_TX_OFFLOAD_SCTP_CKSUM       | \
94         DEV_TX_OFFLOAD_MULTI_SEGS       | \
95         DEV_TX_OFFLOAD_IPV4_CKSUM)
96
97 #define NIX_RX_OFFLOAD_CAPA ( \
98         DEV_RX_OFFLOAD_CHECKSUM         | \
99         DEV_RX_OFFLOAD_SCTP_CKSUM       | \
100         DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM | \
101         DEV_RX_OFFLOAD_SCATTER          | \
102         DEV_RX_OFFLOAD_JUMBO_FRAME      | \
103         DEV_RX_OFFLOAD_OUTER_UDP_CKSUM | \
104         DEV_RX_OFFLOAD_VLAN_STRIP | \
105         DEV_RX_OFFLOAD_VLAN_FILTER | \
106         DEV_RX_OFFLOAD_QINQ_STRIP | \
107         DEV_RX_OFFLOAD_TIMESTAMP)
108
109 struct otx2_qint {
110         struct rte_eth_dev *eth_dev;
111         uint8_t qintx;
112 };
113
114 struct otx2_rss_info {
115         uint16_t rss_size;
116         uint8_t rss_grps;
117 };
118
119 struct otx2_npc_flow_info {
120         uint16_t channel; /*rx channel */
121         uint16_t flow_prealloc_size;
122         uint16_t flow_max_priority;
123 };
124
125 struct otx2_eth_dev {
126         OTX2_DEV; /* Base class */
127         MARKER otx2_eth_dev_data_start;
128         uint16_t sqb_size;
129         uint16_t rx_chan_base;
130         uint16_t tx_chan_base;
131         uint8_t rx_chan_cnt;
132         uint8_t tx_chan_cnt;
133         uint8_t lso_tsov4_idx;
134         uint8_t lso_tsov6_idx;
135         uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
136         uint8_t max_mac_entries;
137         uint8_t lf_tx_stats;
138         uint8_t lf_rx_stats;
139         uint16_t flags;
140         uint16_t cints;
141         uint16_t qints;
142         uint8_t configured;
143         uint8_t configured_qints;
144         uint8_t configured_nb_rx_qs;
145         uint8_t configured_nb_tx_qs;
146         uint16_t nix_msixoff;
147         uintptr_t base;
148         uintptr_t lmt_addr;
149         uint16_t scalar_ena;
150         uint16_t max_sqb_count;
151         uint16_t rx_offload_flags; /* Selected Rx offload flags(NIX_RX_*_F) */
152         uint64_t rx_offloads;
153         uint16_t tx_offload_flags; /* Selected Tx offload flags(NIX_TX_*_F) */
154         uint64_t tx_offloads;
155         uint64_t rx_offload_capa;
156         uint64_t tx_offload_capa;
157         struct otx2_qint qints_mem[RTE_MAX_QUEUES_PER_PORT];
158         struct otx2_rss_info rss_info;
159         struct otx2_npc_flow_info npc_flow;
160         struct rte_eth_dev *eth_dev;
161 } __rte_cache_aligned;
162
163 static inline struct otx2_eth_dev *
164 otx2_eth_pmd_priv(struct rte_eth_dev *eth_dev)
165 {
166         return eth_dev->data->dev_private;
167 }
168
169 /* Ops */
170 void otx2_nix_info_get(struct rte_eth_dev *eth_dev,
171                        struct rte_eth_dev_info *dev_info);
172
173 /* Link */
174 void otx2_nix_toggle_flag_link_cfg(struct otx2_eth_dev *dev, bool set);
175 int otx2_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete);
176 void otx2_eth_dev_link_status_update(struct otx2_dev *dev,
177                                      struct cgx_link_user_info *link);
178
179 /* IRQ */
180 int otx2_nix_register_irqs(struct rte_eth_dev *eth_dev);
181 int oxt2_nix_register_queue_irqs(struct rte_eth_dev *eth_dev);
182 void otx2_nix_unregister_irqs(struct rte_eth_dev *eth_dev);
183 void oxt2_nix_unregister_queue_irqs(struct rte_eth_dev *eth_dev);
184
185 /* Debug */
186 int otx2_nix_reg_dump(struct otx2_eth_dev *dev, uint64_t *data);
187 int otx2_nix_dev_get_reg(struct rte_eth_dev *eth_dev,
188                          struct rte_dev_reg_info *regs);
189 int otx2_nix_queues_ctx_dump(struct rte_eth_dev *eth_dev);
190 void otx2_nix_cqe_dump(const struct nix_cqe_hdr_s *cq);
191
192 /* CGX */
193 int otx2_cgx_rxtx_start(struct otx2_eth_dev *dev);
194 int otx2_cgx_rxtx_stop(struct otx2_eth_dev *dev);
195 int otx2_cgx_mac_addr_set(struct rte_eth_dev *eth_dev,
196                           struct rte_ether_addr *addr);
197
198 /* Mac address handling */
199 int otx2_nix_mac_addr_get(struct rte_eth_dev *eth_dev, uint8_t *addr);
200 int otx2_cgx_mac_max_entries_get(struct otx2_eth_dev *dev);
201
202 /* Devargs */
203 int otx2_ethdev_parse_devargs(struct rte_devargs *devargs,
204                               struct otx2_eth_dev *dev);
205
206 #endif /* __OTX2_ETHDEV_H__ */