xref: /linux/drivers/net/dsa/sja1105/sja1105_static_config.h (revision 02680c23d7b3febe45ea3d4f9818c2b2dc89020a)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2016-2018, NXP Semiconductors
3  * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com>
4  */
5 #ifndef _SJA1105_STATIC_CONFIG_H
6 #define _SJA1105_STATIC_CONFIG_H
7 
8 #include <linux/packing.h>
9 #include <linux/types.h>
10 #include <asm/types.h>
11 
12 #define SJA1105_SIZE_DEVICE_ID				4
13 #define SJA1105_SIZE_TABLE_HEADER			12
14 #define SJA1105_SIZE_SCHEDULE_ENTRY			8
15 #define SJA1105_SIZE_SCHEDULE_ENTRY_POINTS_ENTRY	4
16 #define SJA1105_SIZE_VL_LOOKUP_ENTRY			12
17 #define SJA1105_SIZE_VL_POLICING_ENTRY			8
18 #define SJA1105_SIZE_VL_FORWARDING_ENTRY		4
19 #define SJA1105_SIZE_L2_POLICING_ENTRY			8
20 #define SJA1105_SIZE_VLAN_LOOKUP_ENTRY			8
21 #define SJA1105_SIZE_L2_FORWARDING_ENTRY		8
22 #define SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY		12
23 #define SJA1105_SIZE_RETAGGING_ENTRY			8
24 #define SJA1105_SIZE_XMII_PARAMS_ENTRY			4
25 #define SJA1105_SIZE_SCHEDULE_PARAMS_ENTRY		12
26 #define SJA1105_SIZE_SCHEDULE_ENTRY_POINTS_PARAMS_ENTRY	4
27 #define SJA1105_SIZE_VL_FORWARDING_PARAMS_ENTRY         12
28 #define SJA1105ET_SIZE_L2_LOOKUP_ENTRY			12
29 #define SJA1105ET_SIZE_MAC_CONFIG_ENTRY			28
30 #define SJA1105ET_SIZE_L2_LOOKUP_PARAMS_ENTRY		4
31 #define SJA1105ET_SIZE_GENERAL_PARAMS_ENTRY		40
32 #define SJA1105ET_SIZE_AVB_PARAMS_ENTRY			12
33 #define SJA1105ET_SIZE_CBS_ENTRY			16
34 #define SJA1105PQRS_SIZE_L2_LOOKUP_ENTRY		20
35 #define SJA1105PQRS_SIZE_MAC_CONFIG_ENTRY		32
36 #define SJA1105PQRS_SIZE_L2_LOOKUP_PARAMS_ENTRY		16
37 #define SJA1105PQRS_SIZE_GENERAL_PARAMS_ENTRY		44
38 #define SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY		16
39 #define SJA1105PQRS_SIZE_CBS_ENTRY			20
40 
41 /* UM10944.pdf Page 11, Table 2. Configuration Blocks */
42 enum {
43 	BLKID_SCHEDULE					= 0x00,
44 	BLKID_SCHEDULE_ENTRY_POINTS			= 0x01,
45 	BLKID_VL_LOOKUP					= 0x02,
46 	BLKID_VL_POLICING				= 0x03,
47 	BLKID_VL_FORWARDING				= 0x04,
48 	BLKID_L2_LOOKUP					= 0x05,
49 	BLKID_L2_POLICING				= 0x06,
50 	BLKID_VLAN_LOOKUP				= 0x07,
51 	BLKID_L2_FORWARDING				= 0x08,
52 	BLKID_MAC_CONFIG				= 0x09,
53 	BLKID_SCHEDULE_PARAMS				= 0x0A,
54 	BLKID_SCHEDULE_ENTRY_POINTS_PARAMS		= 0x0B,
55 	BLKID_VL_FORWARDING_PARAMS			= 0x0C,
56 	BLKID_L2_LOOKUP_PARAMS				= 0x0D,
57 	BLKID_L2_FORWARDING_PARAMS			= 0x0E,
58 	BLKID_AVB_PARAMS				= 0x10,
59 	BLKID_GENERAL_PARAMS				= 0x11,
60 	BLKID_RETAGGING					= 0x12,
61 	BLKID_CBS					= 0x13,
62 	BLKID_XMII_PARAMS				= 0x4E,
63 };
64 
65 enum sja1105_blk_idx {
66 	BLK_IDX_SCHEDULE = 0,
67 	BLK_IDX_SCHEDULE_ENTRY_POINTS,
68 	BLK_IDX_VL_LOOKUP,
69 	BLK_IDX_VL_POLICING,
70 	BLK_IDX_VL_FORWARDING,
71 	BLK_IDX_L2_LOOKUP,
72 	BLK_IDX_L2_POLICING,
73 	BLK_IDX_VLAN_LOOKUP,
74 	BLK_IDX_L2_FORWARDING,
75 	BLK_IDX_MAC_CONFIG,
76 	BLK_IDX_SCHEDULE_PARAMS,
77 	BLK_IDX_SCHEDULE_ENTRY_POINTS_PARAMS,
78 	BLK_IDX_VL_FORWARDING_PARAMS,
79 	BLK_IDX_L2_LOOKUP_PARAMS,
80 	BLK_IDX_L2_FORWARDING_PARAMS,
81 	BLK_IDX_AVB_PARAMS,
82 	BLK_IDX_GENERAL_PARAMS,
83 	BLK_IDX_RETAGGING,
84 	BLK_IDX_CBS,
85 	BLK_IDX_XMII_PARAMS,
86 	BLK_IDX_MAX,
87 	/* Fake block indices that are only valid for dynamic access */
88 	BLK_IDX_MGMT_ROUTE,
89 	BLK_IDX_MAX_DYN,
90 	BLK_IDX_INVAL = -1,
91 };
92 
93 #define SJA1105_MAX_SCHEDULE_COUNT			1024
94 #define SJA1105_MAX_SCHEDULE_ENTRY_POINTS_COUNT		2048
95 #define SJA1105_MAX_VL_LOOKUP_COUNT			1024
96 #define SJA1105_MAX_VL_POLICING_COUNT			1024
97 #define SJA1105_MAX_VL_FORWARDING_COUNT			1024
98 #define SJA1105_MAX_L2_LOOKUP_COUNT			1024
99 #define SJA1105_MAX_L2_POLICING_COUNT			45
100 #define SJA1105_MAX_VLAN_LOOKUP_COUNT			4096
101 #define SJA1105_MAX_L2_FORWARDING_COUNT			13
102 #define SJA1105_MAX_MAC_CONFIG_COUNT			5
103 #define SJA1105_MAX_SCHEDULE_PARAMS_COUNT		1
104 #define SJA1105_MAX_SCHEDULE_ENTRY_POINTS_PARAMS_COUNT	1
105 #define SJA1105_MAX_VL_FORWARDING_PARAMS_COUNT		1
106 #define SJA1105_MAX_L2_LOOKUP_PARAMS_COUNT		1
107 #define SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT		1
108 #define SJA1105_MAX_GENERAL_PARAMS_COUNT		1
109 #define SJA1105_MAX_RETAGGING_COUNT			32
110 #define SJA1105_MAX_XMII_PARAMS_COUNT			1
111 #define SJA1105_MAX_AVB_PARAMS_COUNT			1
112 #define SJA1105ET_MAX_CBS_COUNT				10
113 #define SJA1105PQRS_MAX_CBS_COUNT			16
114 
115 #define SJA1105_MAX_FRAME_MEMORY			929
116 #define SJA1105_MAX_FRAME_MEMORY_RETAGGING		910
117 #define SJA1105_VL_FRAME_MEMORY				100
118 
119 #define SJA1105E_DEVICE_ID				0x9C00000Cull
120 #define SJA1105T_DEVICE_ID				0x9E00030Eull
121 #define SJA1105PR_DEVICE_ID				0xAF00030Eull
122 #define SJA1105QS_DEVICE_ID				0xAE00030Eull
123 
124 #define SJA1105ET_PART_NO				0x9A83
125 #define SJA1105P_PART_NO				0x9A84
126 #define SJA1105Q_PART_NO				0x9A85
127 #define SJA1105R_PART_NO				0x9A86
128 #define SJA1105S_PART_NO				0x9A87
129 
130 struct sja1105_schedule_entry {
131 	u64 winstindex;
132 	u64 winend;
133 	u64 winst;
134 	u64 destports;
135 	u64 setvalid;
136 	u64 txen;
137 	u64 resmedia_en;
138 	u64 resmedia;
139 	u64 vlindex;
140 	u64 delta;
141 };
142 
143 struct sja1105_schedule_params_entry {
144 	u64 subscheind[8];
145 };
146 
147 struct sja1105_general_params_entry {
148 	u64 vllupformat;
149 	u64 mirr_ptacu;
150 	u64 switchid;
151 	u64 hostprio;
152 	u64 mac_fltres1;
153 	u64 mac_fltres0;
154 	u64 mac_flt1;
155 	u64 mac_flt0;
156 	u64 incl_srcpt1;
157 	u64 incl_srcpt0;
158 	u64 send_meta1;
159 	u64 send_meta0;
160 	u64 casc_port;
161 	u64 host_port;
162 	u64 mirr_port;
163 	u64 vlmarker;
164 	u64 vlmask;
165 	u64 tpid;
166 	u64 ignore2stf;
167 	u64 tpid2;
168 	/* P/Q/R/S only */
169 	u64 queue_ts;
170 	u64 egrmirrvid;
171 	u64 egrmirrpcp;
172 	u64 egrmirrdei;
173 	u64 replay_port;
174 };
175 
176 struct sja1105_schedule_entry_points_entry {
177 	u64 subschindx;
178 	u64 delta;
179 	u64 address;
180 };
181 
182 struct sja1105_schedule_entry_points_params_entry {
183 	u64 clksrc;
184 	u64 actsubsch;
185 };
186 
187 struct sja1105_vlan_lookup_entry {
188 	u64 ving_mirr;
189 	u64 vegr_mirr;
190 	u64 vmemb_port;
191 	u64 vlan_bc;
192 	u64 tag_port;
193 	u64 vlanid;
194 };
195 
196 struct sja1105_l2_lookup_entry {
197 	u64 vlanid;
198 	u64 macaddr;
199 	u64 destports;
200 	u64 enfport;
201 	u64 index;
202 	/* P/Q/R/S only */
203 	u64 mask_iotag;
204 	u64 mask_vlanid;
205 	u64 mask_macaddr;
206 	u64 iotag;
207 	u64 lockeds;
208 	union {
209 		/* LOCKEDS=1: Static FDB entries */
210 		struct {
211 			u64 tsreg;
212 			u64 mirrvlan;
213 			u64 takets;
214 			u64 mirr;
215 			u64 retag;
216 		};
217 		/* LOCKEDS=0: Dynamically learned FDB entries */
218 		struct {
219 			u64 touched;
220 			u64 age;
221 		};
222 	};
223 };
224 
225 struct sja1105_l2_lookup_params_entry {
226 	u64 maxaddrp[5];     /* P/Q/R/S only */
227 	u64 start_dynspc;    /* P/Q/R/S only */
228 	u64 drpnolearn;      /* P/Q/R/S only */
229 	u64 use_static;      /* P/Q/R/S only */
230 	u64 owr_dyn;         /* P/Q/R/S only */
231 	u64 learn_once;      /* P/Q/R/S only */
232 	u64 maxage;          /* Shared */
233 	u64 dyn_tbsz;        /* E/T only */
234 	u64 poly;            /* E/T only */
235 	u64 shared_learn;    /* Shared */
236 	u64 no_enf_hostprt;  /* Shared */
237 	u64 no_mgmt_learn;   /* Shared */
238 };
239 
240 struct sja1105_l2_forwarding_entry {
241 	u64 bc_domain;
242 	u64 reach_port;
243 	u64 fl_domain;
244 	u64 vlan_pmap[8];
245 };
246 
247 struct sja1105_l2_forwarding_params_entry {
248 	u64 max_dynp;
249 	u64 part_spc[8];
250 };
251 
252 struct sja1105_l2_policing_entry {
253 	u64 sharindx;
254 	u64 smax;
255 	u64 rate;
256 	u64 maxlen;
257 	u64 partition;
258 };
259 
260 struct sja1105_avb_params_entry {
261 	u64 cas_master;
262 	u64 destmeta;
263 	u64 srcmeta;
264 };
265 
266 struct sja1105_mac_config_entry {
267 	u64 top[8];
268 	u64 base[8];
269 	u64 enabled[8];
270 	u64 ifg;
271 	u64 speed;
272 	u64 tp_delin;
273 	u64 tp_delout;
274 	u64 maxage;
275 	u64 vlanprio;
276 	u64 vlanid;
277 	u64 ing_mirr;
278 	u64 egr_mirr;
279 	u64 drpnona664;
280 	u64 drpdtag;
281 	u64 drpuntag;
282 	u64 retag;
283 	u64 dyn_learn;
284 	u64 egress;
285 	u64 ingress;
286 };
287 
288 struct sja1105_retagging_entry {
289 	u64 egr_port;
290 	u64 ing_port;
291 	u64 vlan_ing;
292 	u64 vlan_egr;
293 	u64 do_not_learn;
294 	u64 use_dest_ports;
295 	u64 destports;
296 };
297 
298 struct sja1105_cbs_entry {
299 	u64 port;
300 	u64 prio;
301 	u64 credit_hi;
302 	u64 credit_lo;
303 	u64 send_slope;
304 	u64 idle_slope;
305 };
306 
307 struct sja1105_xmii_params_entry {
308 	u64 phy_mac[5];
309 	u64 xmii_mode[5];
310 };
311 
312 enum {
313 	SJA1105_VL_FORMAT_PSFP		= 0,
314 	SJA1105_VL_FORMAT_ARINC664	= 1,
315 };
316 
317 struct sja1105_vl_lookup_entry {
318 	u64 format;
319 	u64 port;
320 	union {
321 		/* SJA1105_VL_FORMAT_PSFP */
322 		struct {
323 			u64 destports;
324 			u64 iscritical;
325 			u64 macaddr;
326 			u64 vlanid;
327 			u64 vlanprior;
328 		};
329 		/* SJA1105_VL_FORMAT_ARINC664 */
330 		struct {
331 			u64 egrmirr;
332 			u64 ingrmirr;
333 			u64 vlid;
334 		};
335 	};
336 	/* Not part of hardware structure */
337 	unsigned long flow_cookie;
338 };
339 
340 struct sja1105_vl_policing_entry {
341 	u64 type;
342 	u64 maxlen;
343 	u64 sharindx;
344 	u64 bag;
345 	u64 jitter;
346 };
347 
348 struct sja1105_vl_forwarding_entry {
349 	u64 type;
350 	u64 priority;
351 	u64 partition;
352 	u64 destports;
353 };
354 
355 struct sja1105_vl_forwarding_params_entry {
356 	u64 partspc[8];
357 	u64 debugen;
358 };
359 
360 struct sja1105_table_header {
361 	u64 block_id;
362 	u64 len;
363 	u64 crc;
364 };
365 
366 struct sja1105_table_ops {
367 	size_t (*packing)(void *buf, void *entry_ptr, enum packing_op op);
368 	size_t unpacked_entry_size;
369 	size_t packed_entry_size;
370 	size_t max_entry_count;
371 };
372 
373 struct sja1105_table {
374 	const struct sja1105_table_ops *ops;
375 	size_t entry_count;
376 	void *entries;
377 };
378 
379 struct sja1105_static_config {
380 	u64 device_id;
381 	struct sja1105_table tables[BLK_IDX_MAX];
382 };
383 
384 extern const struct sja1105_table_ops sja1105e_table_ops[BLK_IDX_MAX];
385 extern const struct sja1105_table_ops sja1105t_table_ops[BLK_IDX_MAX];
386 extern const struct sja1105_table_ops sja1105p_table_ops[BLK_IDX_MAX];
387 extern const struct sja1105_table_ops sja1105q_table_ops[BLK_IDX_MAX];
388 extern const struct sja1105_table_ops sja1105r_table_ops[BLK_IDX_MAX];
389 extern const struct sja1105_table_ops sja1105s_table_ops[BLK_IDX_MAX];
390 
391 size_t sja1105_table_header_packing(void *buf, void *hdr, enum packing_op op);
392 void
393 sja1105_table_header_pack_with_crc(void *buf, struct sja1105_table_header *hdr);
394 size_t
395 sja1105_static_config_get_length(const struct sja1105_static_config *config);
396 
397 typedef enum {
398 	SJA1105_CONFIG_OK = 0,
399 	SJA1105_TTETHERNET_NOT_SUPPORTED,
400 	SJA1105_INCORRECT_TTETHERNET_CONFIGURATION,
401 	SJA1105_INCORRECT_VIRTUAL_LINK_CONFIGURATION,
402 	SJA1105_MISSING_L2_POLICING_TABLE,
403 	SJA1105_MISSING_L2_FORWARDING_TABLE,
404 	SJA1105_MISSING_L2_FORWARDING_PARAMS_TABLE,
405 	SJA1105_MISSING_GENERAL_PARAMS_TABLE,
406 	SJA1105_MISSING_VLAN_TABLE,
407 	SJA1105_MISSING_XMII_TABLE,
408 	SJA1105_MISSING_MAC_TABLE,
409 	SJA1105_OVERCOMMITTED_FRAME_MEMORY,
410 } sja1105_config_valid_t;
411 
412 extern const char *sja1105_static_config_error_msg[];
413 
414 sja1105_config_valid_t
415 sja1105_static_config_check_valid(const struct sja1105_static_config *config);
416 void
417 sja1105_static_config_pack(void *buf, struct sja1105_static_config *config);
418 int sja1105_static_config_init(struct sja1105_static_config *config,
419 			       const struct sja1105_table_ops *static_ops,
420 			       u64 device_id);
421 void sja1105_static_config_free(struct sja1105_static_config *config);
422 
423 int sja1105_table_delete_entry(struct sja1105_table *table, int i);
424 int sja1105_table_resize(struct sja1105_table *table, size_t new_count);
425 
426 u32 sja1105_crc32(const void *buf, size_t len);
427 
428 void sja1105_pack(void *buf, const u64 *val, int start, int end, size_t len);
429 void sja1105_unpack(const void *buf, u64 *val, int start, int end, size_t len);
430 void sja1105_packing(void *buf, u64 *val, int start, int end,
431 		     size_t len, enum packing_op op);
432 
433 /* Common implementations for the static and dynamic configs */
434 size_t sja1105pqrs_general_params_entry_packing(void *buf, void *entry_ptr,
435 						enum packing_op op);
436 size_t sja1105pqrs_l2_lookup_params_entry_packing(void *buf, void *entry_ptr,
437 						  enum packing_op op);
438 size_t sja1105_l2_forwarding_entry_packing(void *buf, void *entry_ptr,
439 					   enum packing_op op);
440 size_t sja1105pqrs_l2_lookup_entry_packing(void *buf, void *entry_ptr,
441 					   enum packing_op op);
442 size_t sja1105et_l2_lookup_entry_packing(void *buf, void *entry_ptr,
443 					 enum packing_op op);
444 size_t sja1105_vlan_lookup_entry_packing(void *buf, void *entry_ptr,
445 					 enum packing_op op);
446 size_t sja1105_retagging_entry_packing(void *buf, void *entry_ptr,
447 				       enum packing_op op);
448 size_t sja1105pqrs_mac_config_entry_packing(void *buf, void *entry_ptr,
449 					    enum packing_op op);
450 size_t sja1105pqrs_avb_params_entry_packing(void *buf, void *entry_ptr,
451 					    enum packing_op op);
452 size_t sja1105_vl_lookup_entry_packing(void *buf, void *entry_ptr,
453 				       enum packing_op op);
454 
455 #endif
456