Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018-2019,2024-2026 NXP
3 : : */
4 : :
5 : : #ifndef _ENETC_H_
6 : : #define _ENETC_H_
7 : :
8 : : #include <rte_time.h>
9 : : #include <ethdev_pci.h>
10 : :
11 : : #include "compat.h"
12 : : #include "base/enetc_hw.h"
13 : : #include "base/enetc4_hw.h"
14 : : #include "enetc_logs.h"
15 : : #include "ntmp.h"
16 : :
17 : : #define PCI_VENDOR_ID_FREESCALE 0x1957
18 : :
19 : : /* Max TX rings per ENETC. */
20 : : #define MAX_TX_RINGS 2
21 : :
22 : : /* Max RX rings per ENTEC. */
23 : : #define MAX_RX_RINGS 1
24 : :
25 : : /* Max BD counts per Ring. */
26 : : #define MAX_BD_COUNT 64000
27 : : /* Min BD counts per Ring. */
28 : : #define MIN_BD_COUNT 32
29 : : /* BD ALIGN */
30 : : #define BD_ALIGN 8
31 : : /* Max segments per ENETC4 TX packet (scatter-gather) */
32 : : #define ENETC4_MAX_SEGS 63
33 : :
34 : : /* minimum frame size supported */
35 : : #define ENETC_MAC_MINFRM_SIZE 68
36 : : /* maximum frame size supported */
37 : : #define ENETC_MAC_MAXFRM_SIZE 9600
38 : :
39 : : /* The max frame size with default MTU */
40 : : #define ENETC_ETH_MAX_LEN (RTE_ETHER_MTU + \
41 : : RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)
42 : :
43 : : /* eth name size */
44 : : #define ENETC_ETH_NAMESIZE 20
45 : :
46 : : #define ENETC_DEFAULT_MSG_SIZE 1024 /* max size */
47 : :
48 : : /* Message length is in multiple of 32 bytes */
49 : : #define ENETC_VSI_PSI_MSG_SIZE 32
50 : :
51 : : /* size for marking hugepage non-cacheable */
52 : : #define SIZE_2MB 0x200000
53 : :
54 : : #define ENETC_TXBD(BDR, i) (&(((struct enetc_tx_bd *)((BDR).bd_base))[i]))
55 : : #define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i]))
56 : :
57 : : #define ENETC4_MBUF_F_TX_IP_IPV4 (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_IPV4)
58 : : #define ENETC4_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_IP_CKSUM | \
59 : : RTE_MBUF_F_TX_TCP_CKSUM | \
60 : : RTE_MBUF_F_TX_UDP_CKSUM)
61 : :
62 : : #define ENETC_CBD(R, i) (&(((struct enetc_cbd *)((R).bd_base))[i]))
63 : : #define ENETC_CBDR_TIMEOUT 1000 /* In multiple of ENETC_CBDR_DELAY */
64 : : #define ENETC_CBDR_DELAY 100 /* usecs */
65 : : #define ENETC_CBDR_SIZE 64
66 : : #define ENETC_CBDR_ALIGN 128
67 : :
68 : : /* supported RSS */
69 : : #define ENETC_RSS_OFFLOAD_ALL ( \
70 : : RTE_ETH_RSS_IP | \
71 : : RTE_ETH_RSS_UDP | \
72 : : RTE_ETH_RSS_TCP)
73 : :
74 : : struct enetc_swbd {
75 : : struct rte_mbuf *buffer_addr;
76 : : };
77 : :
78 : : struct enetc_bdr {
79 : : void *bd_base; /* points to Rx or Tx BD ring */
80 : : struct enetc_swbd *q_swbd;
81 : : union {
82 : : void *tcir;
83 : : void *rcir;
84 : : };
85 : : int bd_count; /* # of BDs */
86 : : int next_to_use;
87 : : int next_to_clean;
88 : : uint16_t index;
89 : : uint8_t crc_len; /* 0 if CRC stripped, 4 otherwise */
90 : : union {
91 : : void *tcisr; /* Tx */
92 : : int next_to_alloc; /* Rx */
93 : : };
94 : : struct rte_mempool *mb_pool; /* mbuf pool to populate RX ring. */
95 : : /* Partial scatter-gather chain persisted across burst calls. */
96 : : struct rte_mbuf *pkt_first_seg; /* first segment of in-progress frame */
97 : : struct rte_mbuf *pkt_last_seg; /* last segment linked so far */
98 : : struct rte_eth_dev *ndev;
99 : : uint64_t ierrors;
100 : : uint8_t rx_deferred_start;
101 : : uint8_t tx_deferred_start;
102 : : };
103 : :
104 : : struct enetc_eth_hw {
105 : : struct rte_eth_dev *ndev;
106 : : struct enetc_hw hw;
107 : : uint16_t device_id;
108 : : uint16_t vendor_id;
109 : : uint8_t revision_id;
110 : : struct enetc_eth_mac_info mac;
111 : : struct netc_cbdr cbdr;
112 : : uint32_t num_rss;
113 : : uint32_t max_rx_queues;
114 : : uint32_t max_tx_queues;
115 : : uint32_t vsi_timeout; /* VSI-PSI message wait timeout (iterations) */
116 : : uint32_t vsi_delay; /* VSI-PSI message wait delay (us) */
117 : : uint32_t *txq_prior; /* per-queue TX priority (TBMR priority bits) */
118 : : uint8_t nc_mode; /* 1 = non-cacheable BD memory, use _nc ops */
119 : : };
120 : :
121 : : /*
122 : : * Structure to store private data for each driver instance (for each port).
123 : : */
124 : : struct enetc_eth_adapter {
125 : : struct rte_eth_dev *ndev;
126 : : struct enetc_eth_hw hw;
127 : : };
128 : :
129 : : #define ENETC_DEV_PRIVATE(adapter) \
130 : : ((struct enetc_eth_adapter *)adapter)
131 : :
132 : : #define ENETC_DEV_PRIVATE_TO_HW(adapter) \
133 : : (&((struct enetc_eth_adapter *)adapter)->hw)
134 : :
135 : : #define ENETC_DEV_PRIVATE_TO_STATS(adapter) \
136 : : (&((struct enetc_eth_adapter *)adapter)->stats)
137 : :
138 : : #define ENETC_DEV_PRIVATE_TO_INTR(adapter) \
139 : : (&((struct enetc_eth_adapter *)adapter)->intr)
140 : :
141 : : /* Class ID for PSI-TO-VSI messages */
142 : : #define ENETC_MSG_CLASS_ID_CMD_SUCCESS 0x1
143 : : #define ENETC_MSG_CLASS_ID_PERMISSION_DENY 0x2
144 : : #define ENETC_MSG_CLASS_ID_CMD_NOT_SUPPORT 0x3
145 : : #define ENETC_MSG_CLASS_ID_PSI_BUSY 0x4
146 : : #define ENETC_MSG_CLASS_ID_CRC_ERROR 0x5
147 : : #define ENETC_MSG_CLASS_ID_PROTO_NOT_SUPPORT 0x6
148 : : #define ENETC_MSG_CLASS_ID_INVALID_MSG_LEN 0x7
149 : : #define ENETC_MSG_CLASS_ID_CMD_TIMEOUT 0x8
150 : : #define ENETC_MSG_CLASS_ID_CMD_DEFERED 0xf
151 : :
152 : : #define ENETC_PROMISC_DISABLE 0x41
153 : : #define ENETC_PROMISC_ENABLE 0x43
154 : : #define ENETC_ALLMULTI_PROMISC_DIS 0x81
155 : : #define ENETC_ALLMULTI_PROMISC_EN 0x83
156 : :
157 : : #define ENETC_PROMISC_VLAN_DISABLE 0x1
158 : : #define ENETC_PROMISC_VLAN_ENABLE 0x3
159 : :
160 : : /* Enum for class IDs */
161 : : enum enetc_msg_cmd_class_id {
162 : : ENETC_CLASS_ID_MAC_FILTER = 0x20,
163 : : ENETC_CLASS_ID_VLAN_FILTER = 0x21,
164 : : ENETC_CLASS_ID_LINK_STATUS = 0x80,
165 : : ENETC_CLASS_ID_LINK_SPEED = 0x81
166 : : };
167 : :
168 : : /* Enum for command IDs */
169 : : enum enetc_msg_cmd_id {
170 : : ENETC_CMD_ID_SET_PRIMARY_MAC = 0,
171 : : ENETC_MSG_ADD_EXACT_MAC_ENTRIES = 1,
172 : : ENETC_CMD_ID_SET_MAC_PROMISCUOUS = 5,
173 : : ENETC_MSG_ADD_EXACT_VLAN_ENTRIES = 0,
174 : : ENETC_MSG_REMOVE_EXACT_VLAN_ENTRIES = 1,
175 : : ENETC_CMD_ID_SET_VLAN_PROMISCUOUS = 4,
176 : : ENETC_CMD_ID_GET_LINK_STATUS = 0,
177 : : ENETC_CMD_ID_REGISTER_LINK_NOTIF = 1,
178 : : ENETC_CMD_ID_UNREGISTER_LINK_NOTIF = 2,
179 : : ENETC_CMD_ID_GET_LINK_SPEED = 0
180 : : };
181 : :
182 : : enum mac_addr_status {
183 : : ENETC_INVALID_MAC_ADDR = 0x0,
184 : : ENETC_DUPLICATE_MAC_ADDR = 0X1,
185 : : ENETC_MAC_ADDR_NOT_FOUND = 0X2,
186 : : ENETC_MAC_FILTER_NO_RESOURCE = 0x3
187 : : };
188 : :
189 : : enum vlan_status {
190 : : ENETC_INVALID_VLAN_ENTRY = 0x0,
191 : : ENETC_DUPLICATE_VLAN_ENTRY = 0X1,
192 : : ENETC_VLAN_ENTRY_NOT_FOUND = 0x2,
193 : : ENETC_VLAN_NO_RESOURCE = 0x3
194 : : };
195 : :
196 : : enum link_status {
197 : : ENETC_LINK_UP = 0x0,
198 : : ENETC_LINK_DOWN = 0x1
199 : : };
200 : :
201 : : enum speed {
202 : : ENETC_SPEED_UNKNOWN = 0x0,
203 : : ENETC_SPEED_10_HALF_DUPLEX = 0x1,
204 : : ENETC_SPEED_10_FULL_DUPLEX = 0x2,
205 : : ENETC_SPEED_100_HALF_DUPLEX = 0x3,
206 : : ENETC_SPEED_100_FULL_DUPLEX = 0x4,
207 : : ENETC_SPEED_1000 = 0x5,
208 : : ENETC_SPEED_2500 = 0x6,
209 : : ENETC_SPEED_5000 = 0x7,
210 : : ENETC_SPEED_10G = 0x8,
211 : : ENETC_SPEED_25G = 0x9,
212 : : ENETC_SPEED_50G = 0xA,
213 : : ENETC_SPEED_100G = 0xB,
214 : : ENETC_SPEED_NOT_SUPPORTED = 0xF
215 : : };
216 : :
217 : : /* PSI-VSI command header format */
218 : : struct enetc_msg_cmd_header {
219 : : uint16_t csum; /* INET_CHECKSUM */
220 : : uint8_t class_id; /* Command class type */
221 : : uint8_t cmd_id; /* Denotes the specific required action */
222 : : uint8_t proto_ver; /* Supported VSI-PSI command protocol version */
223 : : uint8_t len; /* Extended message body length */
224 : : uint8_t reserved_1;
225 : : uint8_t cookie; /* Control command execution asynchronously on PSI side */
226 : : uint64_t reserved_2;
227 : : };
228 : :
229 : : /* VF-PF set primary MAC address message format */
230 : : struct enetc_msg_cmd_set_primary_mac {
231 : : struct enetc_msg_cmd_header header;
232 : : uint8_t count; /* number of MAC addresses */
233 : : uint8_t reserved_1;
234 : : uint16_t reserved_2;
235 : : struct rte_ether_addr addr;
236 : : };
237 : :
238 : : struct enetc_msg_cmd_set_promisc {
239 : : struct enetc_msg_cmd_header header;
240 : : uint8_t op_type;
241 : : };
242 : :
243 : : struct enetc_msg_cmd_get_link_status {
244 : : struct enetc_msg_cmd_header header;
245 : : };
246 : :
247 : : struct enetc_msg_cmd_get_link_speed {
248 : : struct enetc_msg_cmd_header header;
249 : : };
250 : :
251 : : struct enetc_msg_cmd_set_vlan_promisc {
252 : : struct enetc_msg_cmd_header header;
253 : : uint8_t op;
254 : : uint8_t reserved;
255 : : };
256 : :
257 : : struct enetc_msg_vlan_exact_filter {
258 : : struct enetc_msg_cmd_header header;
259 : : uint8_t vlan_count;
260 : : uint8_t reserved_1;
261 : : uint16_t reserved_2;
262 : : uint16_t vlan_id;
263 : : uint8_t tpid;
264 : : uint8_t reserved2;
265 : : };
266 : :
267 : : struct enetc_psi_reply_msg {
268 : : uint8_t class_id;
269 : : uint8_t status;
270 : : };
271 : :
272 : : /* msg size encoding: default and max msg value of 1024B encoded as 0 */
273 : : static inline uint32_t enetc_vsi_set_msize(uint32_t size)
274 : : {
275 [ # # ]: 0 : return size < ENETC_DEFAULT_MSG_SIZE ? size >> 5 : 0;
276 : : }
277 : :
278 : : /*
279 : : * ENETC4 function prototypes
280 : : */
281 : : int enetc4_pci_remove(struct rte_pci_device *pci_dev);
282 : : int enetc4_dev_configure(struct rte_eth_dev *dev);
283 : : int enetc4_dev_close(struct rte_eth_dev *dev);
284 : : int enetc4_dev_infos_get(struct rte_eth_dev *dev,
285 : : struct rte_eth_dev_info *dev_info);
286 : : int enetc4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
287 : : uint16_t nb_rx_desc, unsigned int socket_id __rte_unused,
288 : : const struct rte_eth_rxconf *rx_conf,
289 : : struct rte_mempool *mb_pool);
290 : : int enetc4_rx_queue_start(struct rte_eth_dev *dev, uint16_t qidx);
291 : : int enetc4_rx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx);
292 : : void enetc4_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
293 : : int enetc4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
294 : : uint16_t nb_desc, unsigned int socket_id __rte_unused,
295 : : const struct rte_eth_txconf *tx_conf);
296 : : int enetc4_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx);
297 : : int enetc4_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx);
298 : : void enetc4_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
299 : : const uint32_t *enetc4_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused,
300 : : size_t *no_of_elements);
301 : :
302 : : /*
303 : : * enetc4_vf function prototype
304 : : */
305 : : int enetc4_vf_dev_stop(struct rte_eth_dev *dev);
306 : : int enetc4_vf_dev_intr(struct rte_eth_dev *eth_dev, bool enable);
307 : :
308 : : /*
309 : : * RX/TX ENETC function prototypes
310 : : */
311 : : uint16_t enetc_xmit_pkts(void *txq, struct rte_mbuf **tx_pkts,
312 : : uint16_t nb_pkts);
313 : : uint16_t enetc_xmit_pkts_nc(void *txq, struct rte_mbuf **tx_pkts,
314 : : uint16_t nb_pkts);
315 : : uint16_t enetc_recv_pkts(void *rxq, struct rte_mbuf **rx_pkts,
316 : : uint16_t nb_pkts);
317 : : uint16_t enetc_recv_pkts_nc(void *rxq, struct rte_mbuf **rx_pkts,
318 : : uint16_t nb_pkts);
319 : : uint16_t enetc_xmit_pkts_cacheable(void *txq, struct rte_mbuf **tx_pkts,
320 : : uint16_t nb_pkts);
321 : : uint16_t enetc_recv_pkts_cacheable(void *rxq, struct rte_mbuf **rx_pkts,
322 : : uint16_t nb_pkts);
323 : :
324 : : int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt);
325 : :
326 : : /*
327 : : * Cache-maintenance constants for cacheable BD ring mode.
328 : : *
329 : : * BD = 16 bytes, cache line = 64 bytes => 4 BDs per cache line.
330 : : * Every dcbf in enetc_refill_rx_ring() flushes a full 64-byte cache line.
331 : : * To ensure each dcbf covers only fully-written BDs the caller
332 : : * must pass a count rounded DOWN to a multiple of ENETC_BD_PER_CL so that
333 : : * the last partial group is left in cache to be completed and flushed in
334 : : * the next call.
335 : : */
336 : : #define ENETC_BD_PER_CL (RTE_CACHE_LINE_SIZE / sizeof(union enetc_rx_bd))
337 : : #define ENETC_BD_PER_CL_MASK (ENETC_BD_PER_CL - 1)
338 : : /* Round n DOWN to the nearest multiple of ENETC_BD_PER_CL. */
339 : : #define ENETC_BD_ALIGN_DOWN(n) ((n) & ~(unsigned int)ENETC_BD_PER_CL_MASK)
340 : :
341 : : void enetc4_dev_hw_init(struct rte_eth_dev *eth_dev);
342 : : void enetc_print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr);
343 : :
344 : : static inline int
345 : : enetc_bd_unused(struct enetc_bdr *bdr)
346 : : {
347 [ # # # # : 0 : if (bdr->next_to_clean > bdr->next_to_use)
# # # # #
# # # ]
348 : 0 : return bdr->next_to_clean - bdr->next_to_use - 1;
349 : :
350 : 0 : return bdr->bd_count + bdr->next_to_clean - bdr->next_to_use - 1;
351 : : }
352 : :
353 : : /* CBDR prototypes */
354 : : int enetc4_setup_cbdr(struct rte_eth_dev *dev, struct enetc_hw *hw,
355 : : int bd_count, struct netc_cbdr *cbdr);
356 : : void enetc_free_cbdr(struct netc_cbdr *cbdr);
357 : : int enetc_ntmp_rsst_query_or_update_entry(struct netc_cbdr *cbdr, uint32_t *table,
358 : : int count, bool query);
359 : :
360 : : #endif /* _ENETC_H_ */
|