xref: /dpdk/drivers/net/dpaa/fmlib/fm_ext.h (revision e77506397fc8005c5129e22e9e2d15d5876790fd)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2012 Freescale Semiconductor Inc.
3  * Copyright 2017-2024 NXP
4  */
5 
6 #ifndef __FM_EXT_H
7 #define __FM_EXT_H
8 
9 #include "ncsw_ext.h"
10 #include "dpaa_integration.h"
11 
12 #define FM_IOC_TYPE_BASE	(NCSW_IOC_TYPE_BASE + 1)
13 #define FMT_IOC_TYPE_BASE	(NCSW_IOC_TYPE_BASE + 3)
14 
15 #define MODULE_FM		0x00010000
16 #define __ERR_MODULE__		MODULE_FM
17 
18 /* #define FM_LIB_DBG */
19 
20 #if defined(FM_LIB_DBG)
21 #define _fml_dbg(...) \
22 	RTE_LOG_LINE_PREFIX(DEBUG, DPAA_PMD, "%s: ", __func__, __VA_ARGS__)
23 #else
24 	#define _fml_dbg(...)
25 #endif
26 
27 /*#define FM_IOCTL_DBG*/
28 
29 #if defined(FM_IOCTL_DBG)
30 	#define _fm_ioctl_dbg(...) \
31 	RTE_LOG_LINE_PREFIX(DEBUG, DPAA_PMD, "%s: ", __func__, __VA_ARGS__)
32 #else
33 	#define _fm_ioctl_dbg(...)
34 #endif
35 
36 /*
37  * @Group	lnx_ioctl_ncsw_grp	NetCommSw Linux User-Space (IOCTL) API
38  * @{
39  */
40 
41 #define NCSW_IOC_TYPE_BASE	0xe0
42 	/**< defines the IOCTL type for all the NCSW Linux module commands */
43 
44 /*
45  * @Group	  lnx_usr_FM_grp Frame Manager API
46  *
47  * @Description   FM API functions, definitions and enums.
48  *
49  *	  The FM module is the main driver module and is a mandatory
50  *	  module for FM driver users. This module must be initialized
51  *	  first prior to any other drivers modules.
52  *	  The FM is a "singleton" module. It is responsible of the
53  *	  common HW modules: FPM, DMA, common QMI and common BMI
54  *	  initializations and run-time control routines. This module
55  *	  must be initialized always when working with any of the FM modules.
56  *	  NOTE - We assume that the FM library will be initialized only
57  *	  by core No. 0!
58  *
59  * @{
60  */
61 
62 /*
63  * @Description   Enum for defining port types
64  */
65 typedef enum e_fm_port_type {
66 	e_FM_PORT_TYPE_OH_OFFLINE_PARSING = 0,  /**< Offline parsing port */
67 	e_FM_PORT_TYPE_RX,			/**< 1G Rx port */
68 	e_FM_PORT_TYPE_RX_10G,			/**< 10G Rx port */
69 	e_FM_PORT_TYPE_TX,			/**< 1G Tx port */
70 	e_FM_PORT_TYPE_TX_10G,			/**< 10G Tx port */
71 	e_FM_PORT_TYPE_RX_2_5G,			/**< 2.5G Rx port */
72 	e_FM_PORT_TYPE_TX_2_5G,			/**< 2.5G Tx port */
73 	e_FM_PORT_TYPE_DUMMY
74 } e_fm_port_type;
75 
76 /*
77  * @Description   Parse results memory layout
78  */
79 typedef struct __rte_packed_begin t_fm_prs_result {
80 	volatile uint8_t	lpid;		/**< Logical port id */
81 	volatile uint8_t	shimr;		/**< Shim header result  */
82 	volatile uint16_t	l2r;		/**< Layer 2 result */
83 	volatile uint16_t	l3r;		/**< Layer 3 result */
84 	volatile uint8_t	l4r;		/**< Layer 4 result */
85 	volatile uint8_t	cplan;		/**< Classification plan id */
86 	volatile uint16_t	nxthdr;		/**< Next Header  */
87 	volatile uint16_t	cksum;		/**< Running-sum */
88 	volatile uint16_t	flags_frag_off;
89 			/**<Flags & fragment-offset field of the last IP-header
90 			 */
91 	volatile uint8_t	route_type;
92 			/**< Routing type field of a IPv6 routing extension
93 			 * header
94 			 */
95 	volatile uint8_t	rhp_ip_valid;
96 			/**< Routing Extension Header Present; last bit is IP
97 			 * valid
98 			 */
99 	volatile uint8_t	shim_off[2];	/**< Shim offset */
100 	volatile uint8_t	ip_pid_off;
101 			/**< IP PID (last IP-proto)offset */
102 	volatile uint8_t	eth_off;	/**< ETH offset */
103 	volatile uint8_t	llc_snap_off;	/**< LLC_SNAP offset */
104 	volatile uint8_t	vlan_off[2];	/**< VLAN offset */
105 	volatile uint8_t	etype_off;	/**< ETYPE offset */
106 	volatile uint8_t	pppoe_off;	/**< PPP offset */
107 	volatile uint8_t	mpls_off[2];	/**< MPLS offset */
108 	volatile uint8_t	ip_off[2];	/**< IP offset */
109 	volatile uint8_t	gre_off;	/**< GRE offset */
110 	volatile uint8_t	l4_off;		/**< Layer 4 offset */
111 	volatile uint8_t	nxthdr_off;	/**< Parser end point */
112 } __rte_packed_end t_fm_prs_result;
113 
114 /*
115  * @Collection   FM Parser results
116  */
117 #define FM_PR_L2_VLAN_STACK	0x00000100  /**< Parse Result: VLAN stack */
118 #define FM_PR_L2_ETHERNET	0x00008000  /**< Parse Result: Ethernet*/
119 #define FM_PR_L2_VLAN		0x00004000  /**< Parse Result: VLAN */
120 #define FM_PR_L2_LLC_SNAP	0x00002000  /**< Parse Result: LLC_SNAP */
121 #define FM_PR_L2_MPLS		0x00001000  /**< Parse Result: MPLS */
122 #define FM_PR_L2_PPPoE		0x00000800  /**< Parse Result: PPPoE */
123 /* @} */
124 
125 /*
126  * @Collection   FM Frame descriptor macros
127  */
128 #define FM_FD_CMD_FCO		0x80000000  /**< Frame queue Context Override */
129 #define FM_FD_CMD_RPD		0x40000000  /**< Read Prepended Data */
130 #define FM_FD_CMD_UPD		0x20000000  /**< Update Prepended Data */
131 #define FM_FD_CMD_DTC		0x10000000  /**< Do L4 Checksum */
132 #define FM_FD_CMD_DCL4C		0x10000000  /**< Didn't calculate L4 Checksum */
133 #define FM_FD_CMD_CFQ		0x00ffffff  /**< Confirmation Frame Queue */
134 
135 #define FM_FD_ERR_UNSUPPORTED_FORMAT	0x04000000
136 					/**< Not for Rx-Port! Unsupported Format
137 					 */
138 #define FM_FD_ERR_LENGTH	0x02000000
139 					/**< Not for Rx-Port! Length Error */
140 #define FM_FD_ERR_DMA		0x01000000  /**< DMA Data error */
141 
142 #define FM_FD_IPR		0x00000001  /**< IPR frame (not error) */
143 
144 #define FM_FD_ERR_IPR_NCSP	(0x00100000 | FM_FD_IPR)
145 						/**< IPR non-consistent-sp */
146 #define FM_FD_ERR_IPR		(0x00200000 | FM_FD_IPR) /**< IPR error */
147 #define FM_FD_ERR_IPR_TO	(0x00300000 | FM_FD_IPR) /**< IPR timeout */
148 
149 #ifdef FM_CAPWAP_SUPPORT
150 #define FM_FD_ERR_CRE		0x00200000
151 #define FM_FD_ERR_CHE		0x00100000
152 #endif /* FM_CAPWAP_SUPPORT */
153 
154 #define FM_FD_ERR_PHYSICAL	0x00080000
155 			/**< Rx FIFO overflow, FCS error, code error, running
156 			 * disparity error (SGMII and TBI modes), FIFO parity
157 			 * error. PHY Sequence error, PHY error control
158 			 * character detected.
159 			 */
160 #define FM_FD_ERR_SIZE		0x00040000
161 		/**< Frame too long OR Frame size exceeds max_length_frame */
162 #define FM_FD_ERR_CLS_DISCARD	0x00020000  /**< classification discard */
163 #define FM_FD_ERR_EXTRACTION	0x00008000  /**< Extract Out of Frame */
164 #define FM_FD_ERR_NO_SCHEME	0x00004000  /**< No Scheme Selected */
165 #define FM_FD_ERR_KEYSIZE_OVERFLOW	0x00002000  /**< Keysize Overflow */
166 #define FM_FD_ERR_COLOR_RED	0x00000800  /**< Frame color is red */
167 #define FM_FD_ERR_COLOR_YELLOW	0x00000400  /**< Frame color is yellow */
168 #define FM_FD_ERR_ILL_PLCR	0x00000200
169 				/**< Illegal Policer Profile selected */
170 #define FM_FD_ERR_PLCR_FRAME_LEN 0x00000100  /**< Policer frame length error */
171 #define FM_FD_ERR_PRS_TIMEOUT	0x00000080  /**< Parser Time out Exceed */
172 #define FM_FD_ERR_PRS_ILL_INSTRUCT 0x00000040
173 					/**< Invalid Soft Parser instruction */
174 #define FM_FD_ERR_PRS_HDR_ERR	0x00000020
175 		/**< Header error was identified during parsing */
176 #define FM_FD_ERR_BLOCK_LIMIT_EXCEEDED  0x00000008
177 			/**< Frame parsed beyond 256 first bytes */
178 
179 #define FM_FD_TX_STATUS_ERR_MASK	(FM_FD_ERR_UNSUPPORTED_FORMAT   | \
180 					FM_FD_ERR_LENGTH		| \
181 					FM_FD_ERR_DMA) /**< TX Error FD bits */
182 
183 #define FM_FD_RX_STATUS_ERR_MASK	(FM_FD_ERR_UNSUPPORTED_FORMAT   | \
184 					FM_FD_ERR_LENGTH		| \
185 					FM_FD_ERR_DMA		| \
186 					FM_FD_ERR_IPR		| \
187 					FM_FD_ERR_IPR_TO		| \
188 					FM_FD_ERR_IPR_NCSP		| \
189 					FM_FD_ERR_PHYSICAL		| \
190 					FM_FD_ERR_SIZE		| \
191 					FM_FD_ERR_CLS_DISCARD	| \
192 					FM_FD_ERR_COLOR_RED		| \
193 					FM_FD_ERR_COLOR_YELLOW	| \
194 					FM_FD_ERR_ILL_PLCR		| \
195 					FM_FD_ERR_PLCR_FRAME_LEN	| \
196 					FM_FD_ERR_EXTRACTION	| \
197 					FM_FD_ERR_NO_SCHEME		| \
198 					FM_FD_ERR_KEYSIZE_OVERFLOW	| \
199 					FM_FD_ERR_PRS_TIMEOUT	| \
200 					FM_FD_ERR_PRS_ILL_INSTRUCT	| \
201 					FM_FD_ERR_PRS_HDR_ERR	| \
202 					FM_FD_ERR_BLOCK_LIMIT_EXCEEDED)
203 					/**< RX Error FD bits */
204 
205 #define FM_FD_RX_STATUS_ERR_NON_FM	0x00400000
206 					/**< non Frame-Manager error */
207 /* @} */
208 
209 /*
210  * @Description   FM Exceptions
211  */
212 typedef enum e_fm_exceptions {
213 	e_FM_EX_DMA_BUS_ERROR = 0,	/**< DMA bus error. */
214 	e_FM_EX_DMA_READ_ECC,
215 		/**< Read Buffer ECC error (Valid for FM rev < 6)*/
216 	e_FM_EX_DMA_SYSTEM_WRITE_ECC,
217 		/**< Write Buffer ECC error on system side
218 		 * (Valid for FM rev < 6)
219 		 */
220 	e_FM_EX_DMA_FM_WRITE_ECC,
221 		/**< Write Buffer ECC error on FM side (Valid for FM rev < 6)*/
222 	e_FM_EX_DMA_SINGLE_PORT_ECC,
223 		/**< Single Port ECC error on FM side (Valid for FM rev > 6)*/
224 	e_FM_EX_FPM_STALL_ON_TASKS,	/**< Stall of tasks on FPM */
225 	e_FM_EX_FPM_SINGLE_ECC,		/**< Single ECC on FPM. */
226 	e_FM_EX_FPM_DOUBLE_ECC,
227 		/**< Double ECC error on FPM ram access */
228 	e_FM_EX_QMI_SINGLE_ECC,		/**< Single ECC on QMI. */
229 	e_FM_EX_QMI_DOUBLE_ECC,		/**< Double bit ECC occurred on QMI */
230 	e_FM_EX_QMI_DEQ_FROM_UNKNOWN_PORTID,/**< Dequeue from unknown port id */
231 	e_FM_EX_BMI_LIST_RAM_ECC,	/**< Linked List RAM ECC error */
232 	e_FM_EX_BMI_STORAGE_PROFILE_ECC,/**< Storage Profile ECC Error */
233 	e_FM_EX_BMI_STATISTICS_RAM_ECC,
234 		/**< Statistics Count RAM ECC Error Enable */
235 	e_FM_EX_BMI_DISPATCH_RAM_ECC,	/**< Dispatch RAM ECC Error Enable */
236 	e_FM_EX_IRAM_ECC,		/**< Double bit ECC occurred on IRAM*/
237 	e_FM_EX_MURAM_ECC		/**< Double bit ECC occurred on MURAM*/
238 } e_fm_exceptions;
239 
240 /*
241  * @Description   Enum for defining port DMA cache attributes
242  */
243 typedef enum e_fm_dma_cache_option {
244 	e_FM_DMA_NO_STASH = 0,	/**< Cacheable, no Allocate (No Stashing) */
245 	e_FM_DMA_STASH = 1	/**< Cacheable and Allocate (Stashing on) */
246 } e_fm_dma_cache_option;
247 /*
248  * @Group	lnx_usr_FM_init_grp FM Initialization Unit
249  *
250  * @Description   FM Initialization Unit
251  *
252  *		  Initialization Flow
253  *		  Initialization of the FM Module will be carried out by the
254  *		  application according to the following sequence:
255  *		  -  Calling the configuration routine with basic parameters.
256  *		  -  Calling the advance initialization routines to change
257  *		     driver's defaults.
258  *		  -  Calling the initialization routine.
259  *
260  * @{
261  */
262 
263 t_handle fm_open(uint8_t id);
264 void	fm_close(t_handle h_fm);
265 
266 /*
267  * @Description   A structure for defining buffer prefix area content.
268  */
269 typedef struct t_fm_buffer_prefix_content {
270 	uint16_t	priv_data_size;
271 		/**< Number of bytes to be left at the beginning of the external
272 		 * buffer Note that the private-area will start from the base of
273 		 * the buffer address.
274 		 */
275 	bool	pass_prs_result;
276 		/**< TRUE to pass the parse result to/from the FM; User may use
277 		 * fm_port_get_buffer_prs_result() in order to get the
278 		 * parser-result from a buffer.
279 		 */
280 	bool	pass_time_stamp;
281 		/**< TRUE to pass the timeStamp to/from the FM User may use
282 		 * fm_port_get_buffer_time_stamp() in order to get the
283 		 * parser-result from a buffer.
284 		 */
285 	bool	pass_hash_result;
286 		/**< TRUE to pass the KG hash result to/from the FM User may use
287 		 * fm_port_get_buffer_hash_result() in order to get the
288 		 * parser-result from a buffer.
289 		 */
290 	bool	pass_all_other_pcdinfo;
291 		/**< Add all other Internal-Context information: AD,
292 		 * hash-result, key, etc.
293 		 */
294 	uint16_t	data_align;
295 		/**< 0 to use driver's default alignment [64], other value for
296 		 * selecting a data alignment (must be a power of 2); if write
297 		 * optimization is used, must be >= 16.
298 		 */
299 	uint8_t	manip_ext_space;
300 		/**< Maximum extra size needed (insertion-size minus
301 		 * removal-size);
302 		 * Note that this field impacts the size of the buffer-prefix
303 		 * (i.e. it pushes the data offset);
304 		 */
305 } t_fm_buffer_prefix_content;
306 
307 /*
308  * @Description   A structure of information about each of the external
309  *		  buffer pools used by a port or storage-profile.
310  */
311 typedef struct t_fm_ext_pool_params {
312 	uint8_t		id;	/**< External buffer pool id */
313 	uint16_t	size;	/**< External buffer pool buffer size */
314 } t_fm_ext_pool_params;
315 
316 /*
317  * @Description   A structure for informing the driver about the external
318  *		  buffer pools allocated in the BM and used by a port or a
319  *		  storage-profile.
320  */
321 typedef struct t_fm_ext_pools {
322 	uint8_t		num_of_pools_used;
323 			/**< Number of pools use by this port*/
324 	t_fm_ext_pool_params	ext_buf_pool[FM_PORT_MAX_NUM_OF_EXT_POOLS];
325 			/**< Parameters for each port */
326 } t_fm_ext_pools;
327 
328 /*
329  * @Description   A structure for defining backup BM Pools.
330  */
331 typedef struct t_fm_backup_bm_pools {
332 	uint8_t	num_bkup_pools;
333 			/**< Number of BM backup pools - must be smaller than
334 			 * the total number of pools defined for the specified
335 			 * port.
336 			 */
337 	uint8_t	pool_ids[FM_PORT_MAX_NUM_OF_EXT_POOLS];
338 			/**< num_bkup_pools pool id's, specifying which pools
339 			 * should be used only as backup. Pool id's specified
340 			 * here must be a subset of the pools used by the
341 			 * specified port.
342 			 */
343 } t_fm_backup_bm_pools;
344 
345 /** @} */ /* end of lnx_usr_FM_init_grp group */
346 
347 /*
348  * @Group	lnx_usr_FM_runtime_control_grp FM Runtime Control Unit
349  *
350  * @Description   FM Runtime control unit API functions, definitions and enums.
351  *
352  *		  The FM driver provides a set of control routines.
353  *		  These routines may only be called after the module was fully
354  *		  initialized (both configuration and initialization routines
355  *		  were called). They are typically used to get information from
356  *		  hardware (status, counters/statistics, revision etc.), to
357  *		  modify a current state or to force/enable a required action.
358  *		  Run-time control may be called whenever necessary and as many
359  *		  times as needed.
360  * @{
361  */
362 
363 /*
364  * @Collection   General FM defines.
365  */
366 #define FM_MAX_NUM_OF_VALID_PORTS   (FM_MAX_NUM_OF_OH_PORTS +	\
367 				FM_MAX_NUM_OF_1G_RX_PORTS +	\
368 				FM_MAX_NUM_OF_10G_RX_PORTS +   \
369 				FM_MAX_NUM_OF_1G_TX_PORTS +	\
370 				FM_MAX_NUM_OF_10G_TX_PORTS)
371 				/**< Number of available FM ports */
372 /* @} */
373 
374 /** @} */ /* end of lnx_usr_FM_runtime_control_grp group */
375 /** @} */ /* end of lnx_usr_FM_lib_grp group */
376 /** @} */ /* end of lnx_usr_FM_grp group */
377 
378 /*
379  * @Description   FM Char device ioctls
380  */
381 
382 /*
383  * @Group	lnx_ioctl_FM_grp Frame Manager Linux IOCTL API
384  *
385  * @Description   FM Linux ioctls definitions and enums
386  *
387  * @{
388  */
389 
390 /*
391  * @Collection	FM IOCTL device ('/dev') definitions
392  */
393 #define DEV_FM_NAME		"fm" /**< Name of the FM chardev */
394 
395 #define DEV_FM_MINOR_BASE	0
396 #define DEV_FM_PCD_MINOR_BASE	(DEV_FM_MINOR_BASE + 1)
397 				/*/dev/fmx-pcd */
398 #define DEV_FM_OH_PORTS_MINOR_BASE  (DEV_FM_PCD_MINOR_BASE + 1)
399 				/*/dev/fmx-port-ohy */
400 #define DEV_FM_RX_PORTS_MINOR_BASE \
401 	(DEV_FM_OH_PORTS_MINOR_BASE + FM_MAX_NUM_OF_OH_PORTS)
402 				/*/dev/fmx-port-rxy */
403 #define DEV_FM_TX_PORTS_MINOR_BASE \
404 	(DEV_FM_RX_PORTS_MINOR_BASE + FM_MAX_NUM_OF_RX_PORTS)
405 				/*/dev/fmx-port-txy */
406 #define DEV_FM_MAX_MINORS \
407 	(DEV_FM_TX_PORTS_MINOR_BASE + FM_MAX_NUM_OF_TX_PORTS)
408 
409 #define FM_IOC_NUM(n)	(n)
410 #define FM_PCD_IOC_NUM(n)   ((n) + 20)
411 #define FM_PORT_IOC_NUM(n)  ((n) + 70)
412 /* @} */
413 
414 #define IOC_FM_MAX_NUM_OF_PORTS	64
415 
416 /*
417  * @Description   Enum for defining port types
418  *		  (must match enum e_fm_port_type defined in fm_ext.h)
419  */
420 typedef enum ioc_fm_port_type {
421 	e_IOC_FM_PORT_TYPE_OH_OFFLINE_PARSING = 0,  /**< Offline parsing port */
422 	e_IOC_FM_PORT_TYPE_RX,			/**< 1G Rx port */
423 	e_IOC_FM_PORT_TYPE_RX_10G,		/**< 10G Rx port */
424 	e_IOC_FM_PORT_TYPE_TX,			/**< 1G Tx port */
425 	e_IOC_FM_PORT_TYPE_TX_10G,		/**< 10G Tx port */
426 	e_IOC_FM_PORT_TYPE_DUMMY
427 } ioc_fm_port_type;
428 
429 typedef struct ioc_fm_obj_t {
430 	void	*obj;
431 } ioc_fm_obj_t;
432 
433 typedef union ioc_fm_api_version_t {
434 	struct {
435 	uint8_t major;
436 	uint8_t minor;
437 	uint8_t respin;
438 	uint8_t reserved;
439 	} version;
440 	uint32_t ver;
441 } ioc_fm_api_version_t;
442 
443 /*
444  * @Function	  FM_IOC_GET_API_VERSION
445  *
446  * @Description   Reads the FMD IOCTL API version.
447  *
448  * @Param[in,out] ioc_fm_api_version_t		The requested counter parameters
449  *
450  * @Return	  Version's value.
451  */
452 #define FM_IOC_GET_API_VERSION	\
453 	_IOR(FM_IOC_TYPE_BASE, FM_IOC_NUM(7), ioc_fm_api_version_t)
454 #define FMD_API_VERSION_MAJOR 21
455 #define FMD_API_VERSION_MINOR 1
456 #define FMD_API_VERSION_RESPIN 0
457 
458 uint32_t fm_get_api_version(t_handle h_fm, ioc_fm_api_version_t *p_version);
459 
460 
461 #endif /* __FM_EXT_H */
462