1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
3 
4 #ifndef _MLXSW_REG_H
5 #define _MLXSW_REG_H
6 
7 #include <linux/kernel.h>
8 #include <linux/string.h>
9 #include <linux/bitops.h>
10 #include <linux/if_vlan.h>
11 
12 #include "item.h"
13 #include "port.h"
14 
15 struct mlxsw_reg_info {
16 	u16 id;
17 	u16 len; /* In u8 */
18 	const char *name;
19 };
20 
21 #define MLXSW_REG_DEFINE(_name, _id, _len)				\
22 static const struct mlxsw_reg_info mlxsw_reg_##_name = {		\
23 	.id = _id,							\
24 	.len = _len,							\
25 	.name = #_name,							\
26 }
27 
28 #define MLXSW_REG(type) (&mlxsw_reg_##type)
29 #define MLXSW_REG_LEN(type) MLXSW_REG(type)->len
30 #define MLXSW_REG_ZERO(type, payload) memset(payload, 0, MLXSW_REG(type)->len)
31 
32 /* SGCR - Switch General Configuration Register
33  * --------------------------------------------
34  * This register is used for configuration of the switch capabilities.
35  */
36 #define MLXSW_REG_SGCR_ID 0x2000
37 #define MLXSW_REG_SGCR_LEN 0x10
38 
39 MLXSW_REG_DEFINE(sgcr, MLXSW_REG_SGCR_ID, MLXSW_REG_SGCR_LEN);
40 
41 /* reg_sgcr_llb
42  * Link Local Broadcast (Default=0)
43  * When set, all Link Local packets (224.0.0.X) will be treated as broadcast
44  * packets and ignore the IGMP snooping entries.
45  * Access: RW
46  */
47 MLXSW_ITEM32(reg, sgcr, llb, 0x04, 0, 1);
48 
49 static inline void mlxsw_reg_sgcr_pack(char *payload, bool llb)
50 {
51 	MLXSW_REG_ZERO(sgcr, payload);
52 	mlxsw_reg_sgcr_llb_set(payload, !!llb);
53 }
54 
55 /* SPAD - Switch Physical Address Register
56  * ---------------------------------------
57  * The SPAD register configures the switch physical MAC address.
58  */
59 #define MLXSW_REG_SPAD_ID 0x2002
60 #define MLXSW_REG_SPAD_LEN 0x10
61 
62 MLXSW_REG_DEFINE(spad, MLXSW_REG_SPAD_ID, MLXSW_REG_SPAD_LEN);
63 
64 /* reg_spad_base_mac
65  * Base MAC address for the switch partitions.
66  * Per switch partition MAC address is equal to:
67  * base_mac + swid
68  * Access: RW
69  */
70 MLXSW_ITEM_BUF(reg, spad, base_mac, 0x02, 6);
71 
72 /* SSPR - Switch System Port Record Register
73  * -----------------------------------------
74  * Configures the system port to local port mapping.
75  */
76 #define MLXSW_REG_SSPR_ID 0x2008
77 #define MLXSW_REG_SSPR_LEN 0x8
78 
79 MLXSW_REG_DEFINE(sspr, MLXSW_REG_SSPR_ID, MLXSW_REG_SSPR_LEN);
80 
81 /* reg_sspr_m
82  * Master - if set, then the record describes the master system port.
83  * This is needed in case a local port is mapped into several system ports
84  * (for multipathing). That number will be reported as the source system
85  * port when packets are forwarded to the CPU. Only one master port is allowed
86  * per local port.
87  *
88  * Note: Must be set for Spectrum.
89  * Access: RW
90  */
91 MLXSW_ITEM32(reg, sspr, m, 0x00, 31, 1);
92 
93 /* reg_sspr_local_port
94  * Local port number.
95  *
96  * Access: RW
97  */
98 MLXSW_ITEM32_LP(reg, sspr, 0x00, 16, 0x00, 12);
99 
100 /* reg_sspr_sub_port
101  * Virtual port within the physical port.
102  * Should be set to 0 when virtual ports are not enabled on the port.
103  *
104  * Access: RW
105  */
106 MLXSW_ITEM32(reg, sspr, sub_port, 0x00, 8, 8);
107 
108 /* reg_sspr_system_port
109  * Unique identifier within the stacking domain that represents all the ports
110  * that are available in the system (external ports).
111  *
112  * Currently, only single-ASIC configurations are supported, so we default to
113  * 1:1 mapping between system ports and local ports.
114  * Access: Index
115  */
116 MLXSW_ITEM32(reg, sspr, system_port, 0x04, 0, 16);
117 
118 static inline void mlxsw_reg_sspr_pack(char *payload, u16 local_port)
119 {
120 	MLXSW_REG_ZERO(sspr, payload);
121 	mlxsw_reg_sspr_m_set(payload, 1);
122 	mlxsw_reg_sspr_local_port_set(payload, local_port);
123 	mlxsw_reg_sspr_sub_port_set(payload, 0);
124 	mlxsw_reg_sspr_system_port_set(payload, local_port);
125 }
126 
127 /* SFDAT - Switch Filtering Database Aging Time
128  * --------------------------------------------
129  * Controls the Switch aging time. Aging time is able to be set per Switch
130  * Partition.
131  */
132 #define MLXSW_REG_SFDAT_ID 0x2009
133 #define MLXSW_REG_SFDAT_LEN 0x8
134 
135 MLXSW_REG_DEFINE(sfdat, MLXSW_REG_SFDAT_ID, MLXSW_REG_SFDAT_LEN);
136 
137 /* reg_sfdat_swid
138  * Switch partition ID.
139  * Access: Index
140  */
141 MLXSW_ITEM32(reg, sfdat, swid, 0x00, 24, 8);
142 
143 /* reg_sfdat_age_time
144  * Aging time in seconds
145  * Min - 10 seconds
146  * Max - 1,000,000 seconds
147  * Default is 300 seconds.
148  * Access: RW
149  */
150 MLXSW_ITEM32(reg, sfdat, age_time, 0x04, 0, 20);
151 
152 static inline void mlxsw_reg_sfdat_pack(char *payload, u32 age_time)
153 {
154 	MLXSW_REG_ZERO(sfdat, payload);
155 	mlxsw_reg_sfdat_swid_set(payload, 0);
156 	mlxsw_reg_sfdat_age_time_set(payload, age_time);
157 }
158 
159 /* SFD - Switch Filtering Database
160  * -------------------------------
161  * The following register defines the access to the filtering database.
162  * The register supports querying, adding, removing and modifying the database.
163  * The access is optimized for bulk updates in which case more than one
164  * FDB record is present in the same command.
165  */
166 #define MLXSW_REG_SFD_ID 0x200A
167 #define MLXSW_REG_SFD_BASE_LEN 0x10 /* base length, without records */
168 #define MLXSW_REG_SFD_REC_LEN 0x10 /* record length */
169 #define MLXSW_REG_SFD_REC_MAX_COUNT 64
170 #define MLXSW_REG_SFD_LEN (MLXSW_REG_SFD_BASE_LEN +	\
171 			   MLXSW_REG_SFD_REC_LEN * MLXSW_REG_SFD_REC_MAX_COUNT)
172 
173 MLXSW_REG_DEFINE(sfd, MLXSW_REG_SFD_ID, MLXSW_REG_SFD_LEN);
174 
175 /* reg_sfd_swid
176  * Switch partition ID for queries. Reserved on Write.
177  * Access: Index
178  */
179 MLXSW_ITEM32(reg, sfd, swid, 0x00, 24, 8);
180 
181 enum mlxsw_reg_sfd_op {
182 	/* Dump entire FDB a (process according to record_locator) */
183 	MLXSW_REG_SFD_OP_QUERY_DUMP = 0,
184 	/* Query records by {MAC, VID/FID} value */
185 	MLXSW_REG_SFD_OP_QUERY_QUERY = 1,
186 	/* Query and clear activity. Query records by {MAC, VID/FID} value */
187 	MLXSW_REG_SFD_OP_QUERY_QUERY_AND_CLEAR_ACTIVITY = 2,
188 	/* Test. Response indicates if each of the records could be
189 	 * added to the FDB.
190 	 */
191 	MLXSW_REG_SFD_OP_WRITE_TEST = 0,
192 	/* Add/modify. Aged-out records cannot be added. This command removes
193 	 * the learning notification of the {MAC, VID/FID}. Response includes
194 	 * the entries that were added to the FDB.
195 	 */
196 	MLXSW_REG_SFD_OP_WRITE_EDIT = 1,
197 	/* Remove record by {MAC, VID/FID}. This command also removes
198 	 * the learning notification and aged-out notifications
199 	 * of the {MAC, VID/FID}. The response provides current (pre-removal)
200 	 * entries as non-aged-out.
201 	 */
202 	MLXSW_REG_SFD_OP_WRITE_REMOVE = 2,
203 	/* Remove learned notification by {MAC, VID/FID}. The response provides
204 	 * the removed learning notification.
205 	 */
206 	MLXSW_REG_SFD_OP_WRITE_REMOVE_NOTIFICATION = 2,
207 };
208 
209 /* reg_sfd_op
210  * Operation.
211  * Access: OP
212  */
213 MLXSW_ITEM32(reg, sfd, op, 0x04, 30, 2);
214 
215 /* reg_sfd_record_locator
216  * Used for querying the FDB. Use record_locator=0 to initiate the
217  * query. When a record is returned, a new record_locator is
218  * returned to be used in the subsequent query.
219  * Reserved for database update.
220  * Access: Index
221  */
222 MLXSW_ITEM32(reg, sfd, record_locator, 0x04, 0, 30);
223 
224 /* reg_sfd_num_rec
225  * Request: Number of records to read/add/modify/remove
226  * Response: Number of records read/added/replaced/removed
227  * See above description for more details.
228  * Ranges 0..64
229  * Access: RW
230  */
231 MLXSW_ITEM32(reg, sfd, num_rec, 0x08, 0, 8);
232 
233 static inline void mlxsw_reg_sfd_pack(char *payload, enum mlxsw_reg_sfd_op op,
234 				      u32 record_locator)
235 {
236 	MLXSW_REG_ZERO(sfd, payload);
237 	mlxsw_reg_sfd_op_set(payload, op);
238 	mlxsw_reg_sfd_record_locator_set(payload, record_locator);
239 }
240 
241 /* reg_sfd_rec_swid
242  * Switch partition ID.
243  * Access: Index
244  */
245 MLXSW_ITEM32_INDEXED(reg, sfd, rec_swid, MLXSW_REG_SFD_BASE_LEN, 24, 8,
246 		     MLXSW_REG_SFD_REC_LEN, 0x00, false);
247 
248 enum mlxsw_reg_sfd_rec_type {
249 	MLXSW_REG_SFD_REC_TYPE_UNICAST = 0x0,
250 	MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG = 0x1,
251 	MLXSW_REG_SFD_REC_TYPE_MULTICAST = 0x2,
252 	MLXSW_REG_SFD_REC_TYPE_UNICAST_TUNNEL = 0xC,
253 };
254 
255 /* reg_sfd_rec_type
256  * FDB record type.
257  * Access: RW
258  */
259 MLXSW_ITEM32_INDEXED(reg, sfd, rec_type, MLXSW_REG_SFD_BASE_LEN, 20, 4,
260 		     MLXSW_REG_SFD_REC_LEN, 0x00, false);
261 
262 enum mlxsw_reg_sfd_rec_policy {
263 	/* Replacement disabled, aging disabled. */
264 	MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY = 0,
265 	/* (mlag remote): Replacement enabled, aging disabled,
266 	 * learning notification enabled on this port.
267 	 */
268 	MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_MLAG = 1,
269 	/* (ingress device): Replacement enabled, aging enabled. */
270 	MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS = 3,
271 };
272 
273 /* reg_sfd_rec_policy
274  * Policy.
275  * Access: RW
276  */
277 MLXSW_ITEM32_INDEXED(reg, sfd, rec_policy, MLXSW_REG_SFD_BASE_LEN, 18, 2,
278 		     MLXSW_REG_SFD_REC_LEN, 0x00, false);
279 
280 /* reg_sfd_rec_a
281  * Activity. Set for new static entries. Set for static entries if a frame SMAC
282  * lookup hits on the entry.
283  * To clear the a bit, use "query and clear activity" op.
284  * Access: RO
285  */
286 MLXSW_ITEM32_INDEXED(reg, sfd, rec_a, MLXSW_REG_SFD_BASE_LEN, 16, 1,
287 		     MLXSW_REG_SFD_REC_LEN, 0x00, false);
288 
289 /* reg_sfd_rec_mac
290  * MAC address.
291  * Access: Index
292  */
293 MLXSW_ITEM_BUF_INDEXED(reg, sfd, rec_mac, MLXSW_REG_SFD_BASE_LEN, 6,
294 		       MLXSW_REG_SFD_REC_LEN, 0x02);
295 
296 enum mlxsw_reg_sfd_rec_action {
297 	/* forward */
298 	MLXSW_REG_SFD_REC_ACTION_NOP = 0,
299 	/* forward and trap, trap_id is FDB_TRAP */
300 	MLXSW_REG_SFD_REC_ACTION_MIRROR_TO_CPU = 1,
301 	/* trap and do not forward, trap_id is FDB_TRAP */
302 	MLXSW_REG_SFD_REC_ACTION_TRAP = 2,
303 	/* forward to IP router */
304 	MLXSW_REG_SFD_REC_ACTION_FORWARD_IP_ROUTER = 3,
305 	MLXSW_REG_SFD_REC_ACTION_DISCARD_ERROR = 15,
306 };
307 
308 /* reg_sfd_rec_action
309  * Action to apply on the packet.
310  * Note: Dynamic entries can only be configured with NOP action.
311  * Access: RW
312  */
313 MLXSW_ITEM32_INDEXED(reg, sfd, rec_action, MLXSW_REG_SFD_BASE_LEN, 28, 4,
314 		     MLXSW_REG_SFD_REC_LEN, 0x0C, false);
315 
316 /* reg_sfd_uc_sub_port
317  * VEPA channel on local port.
318  * Valid only if local port is a non-stacking port. Must be 0 if multichannel
319  * VEPA is not enabled.
320  * Access: RW
321  */
322 MLXSW_ITEM32_INDEXED(reg, sfd, uc_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
323 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
324 
325 /* reg_sfd_uc_set_vid
326  * Set VID.
327  * 0 - Do not update VID.
328  * 1 - Set VID.
329  * For Spectrum-2 when set_vid=0 and smpe_valid=1, the smpe will modify the vid.
330  * Access: RW
331  *
332  * Note: Reserved when legacy bridge model is used.
333  */
334 MLXSW_ITEM32_INDEXED(reg, sfd, uc_set_vid, MLXSW_REG_SFD_BASE_LEN, 31, 1,
335 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
336 
337 /* reg_sfd_uc_fid_vid
338  * Filtering ID or VLAN ID
339  * For SwitchX and SwitchX-2:
340  * - Dynamic entries (policy 2,3) use FID
341  * - Static entries (policy 0) use VID
342  * - When independent learning is configured, VID=FID
343  * For Spectrum: use FID for both Dynamic and Static entries.
344  * VID should not be used.
345  * Access: Index
346  */
347 MLXSW_ITEM32_INDEXED(reg, sfd, uc_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
348 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
349 
350 /* reg_sfd_uc_vid
351  * New VID when set_vid=1.
352  * Access: RW
353  *
354  * Note: Reserved when legacy bridge model is used and when set_vid=0.
355  */
356 MLXSW_ITEM32_INDEXED(reg, sfd, uc_vid, MLXSW_REG_SFD_BASE_LEN, 16, 12,
357 		     MLXSW_REG_SFD_REC_LEN, 0x0C, false);
358 
359 /* reg_sfd_uc_system_port
360  * Unique port identifier for the final destination of the packet.
361  * Access: RW
362  */
363 MLXSW_ITEM32_INDEXED(reg, sfd, uc_system_port, MLXSW_REG_SFD_BASE_LEN, 0, 16,
364 		     MLXSW_REG_SFD_REC_LEN, 0x0C, false);
365 
366 static inline void mlxsw_reg_sfd_rec_pack(char *payload, int rec_index,
367 					  enum mlxsw_reg_sfd_rec_type rec_type,
368 					  const char *mac,
369 					  enum mlxsw_reg_sfd_rec_action action)
370 {
371 	u8 num_rec = mlxsw_reg_sfd_num_rec_get(payload);
372 
373 	if (rec_index >= num_rec)
374 		mlxsw_reg_sfd_num_rec_set(payload, rec_index + 1);
375 	mlxsw_reg_sfd_rec_swid_set(payload, rec_index, 0);
376 	mlxsw_reg_sfd_rec_type_set(payload, rec_index, rec_type);
377 	mlxsw_reg_sfd_rec_mac_memcpy_to(payload, rec_index, mac);
378 	mlxsw_reg_sfd_rec_action_set(payload, rec_index, action);
379 }
380 
381 static inline void mlxsw_reg_sfd_uc_pack(char *payload, int rec_index,
382 					 enum mlxsw_reg_sfd_rec_policy policy,
383 					 const char *mac, u16 fid_vid, u16 vid,
384 					 enum mlxsw_reg_sfd_rec_action action,
385 					 u16 local_port)
386 {
387 	mlxsw_reg_sfd_rec_pack(payload, rec_index,
388 			       MLXSW_REG_SFD_REC_TYPE_UNICAST, mac, action);
389 	mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
390 	mlxsw_reg_sfd_uc_sub_port_set(payload, rec_index, 0);
391 	mlxsw_reg_sfd_uc_fid_vid_set(payload, rec_index, fid_vid);
392 	mlxsw_reg_sfd_uc_set_vid_set(payload, rec_index, vid ? true : false);
393 	mlxsw_reg_sfd_uc_vid_set(payload, rec_index, vid);
394 	mlxsw_reg_sfd_uc_system_port_set(payload, rec_index, local_port);
395 }
396 
397 /* reg_sfd_uc_lag_sub_port
398  * LAG sub port.
399  * Must be 0 if multichannel VEPA is not enabled.
400  * Access: RW
401  */
402 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
403 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
404 
405 /* reg_sfd_uc_lag_set_vid
406  * Set VID.
407  * 0 - Do not update VID.
408  * 1 - Set VID.
409  * For Spectrum-2 when set_vid=0 and smpe_valid=1, the smpe will modify the vid.
410  * Access: RW
411  *
412  * Note: Reserved when legacy bridge model is used.
413  */
414 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_set_vid, MLXSW_REG_SFD_BASE_LEN, 31, 1,
415 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
416 
417 /* reg_sfd_uc_lag_fid_vid
418  * Filtering ID or VLAN ID
419  * For SwitchX and SwitchX-2:
420  * - Dynamic entries (policy 2,3) use FID
421  * - Static entries (policy 0) use VID
422  * - When independent learning is configured, VID=FID
423  * For Spectrum: use FID for both Dynamic and Static entries.
424  * VID should not be used.
425  * Access: Index
426  */
427 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
428 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
429 
430 /* reg_sfd_uc_lag_lag_vid
431  * New vlan ID.
432  * Access: RW
433  *
434  * Note: Reserved when legacy bridge model is used and set_vid=0.
435  */
436 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_lag_vid, MLXSW_REG_SFD_BASE_LEN, 16, 12,
437 		     MLXSW_REG_SFD_REC_LEN, 0x0C, false);
438 
439 /* reg_sfd_uc_lag_lag_id
440  * LAG Identifier - pointer into the LAG descriptor table.
441  * Access: RW
442  */
443 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_lag_id, MLXSW_REG_SFD_BASE_LEN, 0, 10,
444 		     MLXSW_REG_SFD_REC_LEN, 0x0C, false);
445 
446 static inline void
447 mlxsw_reg_sfd_uc_lag_pack(char *payload, int rec_index,
448 			  enum mlxsw_reg_sfd_rec_policy policy,
449 			  const char *mac, u16 fid_vid,
450 			  enum mlxsw_reg_sfd_rec_action action, u16 lag_vid,
451 			  u16 lag_id)
452 {
453 	mlxsw_reg_sfd_rec_pack(payload, rec_index,
454 			       MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG,
455 			       mac, action);
456 	mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
457 	mlxsw_reg_sfd_uc_lag_sub_port_set(payload, rec_index, 0);
458 	mlxsw_reg_sfd_uc_lag_fid_vid_set(payload, rec_index, fid_vid);
459 	mlxsw_reg_sfd_uc_lag_set_vid_set(payload, rec_index, true);
460 	mlxsw_reg_sfd_uc_lag_lag_vid_set(payload, rec_index, lag_vid);
461 	mlxsw_reg_sfd_uc_lag_lag_id_set(payload, rec_index, lag_id);
462 }
463 
464 /* reg_sfd_mc_pgi
465  *
466  * Multicast port group index - index into the port group table.
467  * Value 0x1FFF indicates the pgi should point to the MID entry.
468  * For Spectrum this value must be set to 0x1FFF
469  * Access: RW
470  */
471 MLXSW_ITEM32_INDEXED(reg, sfd, mc_pgi, MLXSW_REG_SFD_BASE_LEN, 16, 13,
472 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
473 
474 /* reg_sfd_mc_fid_vid
475  *
476  * Filtering ID or VLAN ID
477  * Access: Index
478  */
479 MLXSW_ITEM32_INDEXED(reg, sfd, mc_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
480 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
481 
482 /* reg_sfd_mc_mid
483  *
484  * Multicast identifier - global identifier that represents the multicast
485  * group across all devices.
486  * Access: RW
487  */
488 MLXSW_ITEM32_INDEXED(reg, sfd, mc_mid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
489 		     MLXSW_REG_SFD_REC_LEN, 0x0C, false);
490 
491 static inline void
492 mlxsw_reg_sfd_mc_pack(char *payload, int rec_index,
493 		      const char *mac, u16 fid_vid,
494 		      enum mlxsw_reg_sfd_rec_action action, u16 mid)
495 {
496 	mlxsw_reg_sfd_rec_pack(payload, rec_index,
497 			       MLXSW_REG_SFD_REC_TYPE_MULTICAST, mac, action);
498 	mlxsw_reg_sfd_mc_pgi_set(payload, rec_index, 0x1FFF);
499 	mlxsw_reg_sfd_mc_fid_vid_set(payload, rec_index, fid_vid);
500 	mlxsw_reg_sfd_mc_mid_set(payload, rec_index, mid);
501 }
502 
503 /* reg_sfd_uc_tunnel_uip_msb
504  * When protocol is IPv4, the most significant byte of the underlay IPv4
505  * destination IP.
506  * When protocol is IPv6, reserved.
507  * Access: RW
508  */
509 MLXSW_ITEM32_INDEXED(reg, sfd, uc_tunnel_uip_msb, MLXSW_REG_SFD_BASE_LEN, 24,
510 		     8, MLXSW_REG_SFD_REC_LEN, 0x08, false);
511 
512 /* reg_sfd_uc_tunnel_fid
513  * Filtering ID.
514  * Access: Index
515  */
516 MLXSW_ITEM32_INDEXED(reg, sfd, uc_tunnel_fid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
517 		     MLXSW_REG_SFD_REC_LEN, 0x08, false);
518 
519 enum mlxsw_reg_sfd_uc_tunnel_protocol {
520 	MLXSW_REG_SFD_UC_TUNNEL_PROTOCOL_IPV4,
521 	MLXSW_REG_SFD_UC_TUNNEL_PROTOCOL_IPV6,
522 };
523 
524 /* reg_sfd_uc_tunnel_protocol
525  * IP protocol.
526  * Access: RW
527  */
528 MLXSW_ITEM32_INDEXED(reg, sfd, uc_tunnel_protocol, MLXSW_REG_SFD_BASE_LEN, 27,
529 		     1, MLXSW_REG_SFD_REC_LEN, 0x0C, false);
530 
531 /* reg_sfd_uc_tunnel_uip_lsb
532  * When protocol is IPv4, the least significant bytes of the underlay
533  * IPv4 destination IP.
534  * When protocol is IPv6, pointer to the underlay IPv6 destination IP
535  * which is configured by RIPS.
536  * Access: RW
537  */
538 MLXSW_ITEM32_INDEXED(reg, sfd, uc_tunnel_uip_lsb, MLXSW_REG_SFD_BASE_LEN, 0,
539 		     24, MLXSW_REG_SFD_REC_LEN, 0x0C, false);
540 
541 static inline void
542 mlxsw_reg_sfd_uc_tunnel_pack(char *payload, int rec_index,
543 			     enum mlxsw_reg_sfd_rec_policy policy,
544 			     const char *mac, u16 fid,
545 			     enum mlxsw_reg_sfd_rec_action action,
546 			     enum mlxsw_reg_sfd_uc_tunnel_protocol proto)
547 {
548 	mlxsw_reg_sfd_rec_pack(payload, rec_index,
549 			       MLXSW_REG_SFD_REC_TYPE_UNICAST_TUNNEL, mac,
550 			       action);
551 	mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
552 	mlxsw_reg_sfd_uc_tunnel_fid_set(payload, rec_index, fid);
553 	mlxsw_reg_sfd_uc_tunnel_protocol_set(payload, rec_index, proto);
554 }
555 
556 static inline void
557 mlxsw_reg_sfd_uc_tunnel_pack4(char *payload, int rec_index,
558 			      enum mlxsw_reg_sfd_rec_policy policy,
559 			      const char *mac, u16 fid,
560 			      enum mlxsw_reg_sfd_rec_action action, u32 uip)
561 {
562 	mlxsw_reg_sfd_uc_tunnel_uip_msb_set(payload, rec_index, uip >> 24);
563 	mlxsw_reg_sfd_uc_tunnel_uip_lsb_set(payload, rec_index, uip);
564 	mlxsw_reg_sfd_uc_tunnel_pack(payload, rec_index, policy, mac, fid,
565 				     action,
566 				     MLXSW_REG_SFD_UC_TUNNEL_PROTOCOL_IPV4);
567 }
568 
569 static inline void
570 mlxsw_reg_sfd_uc_tunnel_pack6(char *payload, int rec_index, const char *mac,
571 			      u16 fid, enum mlxsw_reg_sfd_rec_action action,
572 			      u32 uip_ptr)
573 {
574 	mlxsw_reg_sfd_uc_tunnel_uip_lsb_set(payload, rec_index, uip_ptr);
575 	/* Only static policy is supported for IPv6 unicast tunnel entry. */
576 	mlxsw_reg_sfd_uc_tunnel_pack(payload, rec_index,
577 				     MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY,
578 				     mac, fid, action,
579 				     MLXSW_REG_SFD_UC_TUNNEL_PROTOCOL_IPV6);
580 }
581 
582 enum mlxsw_reg_tunnel_port {
583 	MLXSW_REG_TUNNEL_PORT_NVE,
584 	MLXSW_REG_TUNNEL_PORT_VPLS,
585 	MLXSW_REG_TUNNEL_PORT_FLEX_TUNNEL0,
586 	MLXSW_REG_TUNNEL_PORT_FLEX_TUNNEL1,
587 };
588 
589 /* SFN - Switch FDB Notification Register
590  * -------------------------------------------
591  * The switch provides notifications on newly learned FDB entries and
592  * aged out entries. The notifications can be polled by software.
593  */
594 #define MLXSW_REG_SFN_ID 0x200B
595 #define MLXSW_REG_SFN_BASE_LEN 0x10 /* base length, without records */
596 #define MLXSW_REG_SFN_REC_LEN 0x10 /* record length */
597 #define MLXSW_REG_SFN_REC_MAX_COUNT 64
598 #define MLXSW_REG_SFN_LEN (MLXSW_REG_SFN_BASE_LEN +	\
599 			   MLXSW_REG_SFN_REC_LEN * MLXSW_REG_SFN_REC_MAX_COUNT)
600 
601 MLXSW_REG_DEFINE(sfn, MLXSW_REG_SFN_ID, MLXSW_REG_SFN_LEN);
602 
603 /* reg_sfn_swid
604  * Switch partition ID.
605  * Access: Index
606  */
607 MLXSW_ITEM32(reg, sfn, swid, 0x00, 24, 8);
608 
609 /* reg_sfn_end
610  * Forces the current session to end.
611  * Access: OP
612  */
613 MLXSW_ITEM32(reg, sfn, end, 0x04, 20, 1);
614 
615 /* reg_sfn_num_rec
616  * Request: Number of learned notifications and aged-out notification
617  * records requested.
618  * Response: Number of notification records returned (must be smaller
619  * than or equal to the value requested)
620  * Ranges 0..64
621  * Access: OP
622  */
623 MLXSW_ITEM32(reg, sfn, num_rec, 0x04, 0, 8);
624 
625 static inline void mlxsw_reg_sfn_pack(char *payload)
626 {
627 	MLXSW_REG_ZERO(sfn, payload);
628 	mlxsw_reg_sfn_swid_set(payload, 0);
629 	mlxsw_reg_sfn_end_set(payload, 0);
630 	mlxsw_reg_sfn_num_rec_set(payload, MLXSW_REG_SFN_REC_MAX_COUNT);
631 }
632 
633 /* reg_sfn_rec_swid
634  * Switch partition ID.
635  * Access: RO
636  */
637 MLXSW_ITEM32_INDEXED(reg, sfn, rec_swid, MLXSW_REG_SFN_BASE_LEN, 24, 8,
638 		     MLXSW_REG_SFN_REC_LEN, 0x00, false);
639 
640 enum mlxsw_reg_sfn_rec_type {
641 	/* MAC addresses learned on a regular port. */
642 	MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC = 0x5,
643 	/* MAC addresses learned on a LAG port. */
644 	MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG = 0x6,
645 	/* Aged-out MAC address on a regular port. */
646 	MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC = 0x7,
647 	/* Aged-out MAC address on a LAG port. */
648 	MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG = 0x8,
649 	/* Learned unicast tunnel record. */
650 	MLXSW_REG_SFN_REC_TYPE_LEARNED_UNICAST_TUNNEL = 0xD,
651 	/* Aged-out unicast tunnel record. */
652 	MLXSW_REG_SFN_REC_TYPE_AGED_OUT_UNICAST_TUNNEL = 0xE,
653 };
654 
655 /* reg_sfn_rec_type
656  * Notification record type.
657  * Access: RO
658  */
659 MLXSW_ITEM32_INDEXED(reg, sfn, rec_type, MLXSW_REG_SFN_BASE_LEN, 20, 4,
660 		     MLXSW_REG_SFN_REC_LEN, 0x00, false);
661 
662 /* reg_sfn_rec_mac
663  * MAC address.
664  * Access: RO
665  */
666 MLXSW_ITEM_BUF_INDEXED(reg, sfn, rec_mac, MLXSW_REG_SFN_BASE_LEN, 6,
667 		       MLXSW_REG_SFN_REC_LEN, 0x02);
668 
669 /* reg_sfn_mac_sub_port
670  * VEPA channel on the local port.
671  * 0 if multichannel VEPA is not enabled.
672  * Access: RO
673  */
674 MLXSW_ITEM32_INDEXED(reg, sfn, mac_sub_port, MLXSW_REG_SFN_BASE_LEN, 16, 8,
675 		     MLXSW_REG_SFN_REC_LEN, 0x08, false);
676 
677 /* reg_sfn_mac_fid
678  * Filtering identifier.
679  * Access: RO
680  */
681 MLXSW_ITEM32_INDEXED(reg, sfn, mac_fid, MLXSW_REG_SFN_BASE_LEN, 0, 16,
682 		     MLXSW_REG_SFN_REC_LEN, 0x08, false);
683 
684 /* reg_sfn_mac_system_port
685  * Unique port identifier for the final destination of the packet.
686  * Access: RO
687  */
688 MLXSW_ITEM32_INDEXED(reg, sfn, mac_system_port, MLXSW_REG_SFN_BASE_LEN, 0, 16,
689 		     MLXSW_REG_SFN_REC_LEN, 0x0C, false);
690 
691 static inline void mlxsw_reg_sfn_mac_unpack(char *payload, int rec_index,
692 					    char *mac, u16 *p_vid,
693 					    u16 *p_local_port)
694 {
695 	mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
696 	*p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
697 	*p_local_port = mlxsw_reg_sfn_mac_system_port_get(payload, rec_index);
698 }
699 
700 /* reg_sfn_mac_lag_lag_id
701  * LAG ID (pointer into the LAG descriptor table).
702  * Access: RO
703  */
704 MLXSW_ITEM32_INDEXED(reg, sfn, mac_lag_lag_id, MLXSW_REG_SFN_BASE_LEN, 0, 10,
705 		     MLXSW_REG_SFN_REC_LEN, 0x0C, false);
706 
707 static inline void mlxsw_reg_sfn_mac_lag_unpack(char *payload, int rec_index,
708 						char *mac, u16 *p_vid,
709 						u16 *p_lag_id)
710 {
711 	mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
712 	*p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
713 	*p_lag_id = mlxsw_reg_sfn_mac_lag_lag_id_get(payload, rec_index);
714 }
715 
716 /* reg_sfn_uc_tunnel_uip_msb
717  * When protocol is IPv4, the most significant byte of the underlay IPv4
718  * address of the remote VTEP.
719  * When protocol is IPv6, reserved.
720  * Access: RO
721  */
722 MLXSW_ITEM32_INDEXED(reg, sfn, uc_tunnel_uip_msb, MLXSW_REG_SFN_BASE_LEN, 24,
723 		     8, MLXSW_REG_SFN_REC_LEN, 0x08, false);
724 
725 enum mlxsw_reg_sfn_uc_tunnel_protocol {
726 	MLXSW_REG_SFN_UC_TUNNEL_PROTOCOL_IPV4,
727 	MLXSW_REG_SFN_UC_TUNNEL_PROTOCOL_IPV6,
728 };
729 
730 /* reg_sfn_uc_tunnel_protocol
731  * IP protocol.
732  * Access: RO
733  */
734 MLXSW_ITEM32_INDEXED(reg, sfn, uc_tunnel_protocol, MLXSW_REG_SFN_BASE_LEN, 27,
735 		     1, MLXSW_REG_SFN_REC_LEN, 0x0C, false);
736 
737 /* reg_sfn_uc_tunnel_uip_lsb
738  * When protocol is IPv4, the least significant bytes of the underlay
739  * IPv4 address of the remote VTEP.
740  * When protocol is IPv6, ipv6_id to be queried from TNIPSD.
741  * Access: RO
742  */
743 MLXSW_ITEM32_INDEXED(reg, sfn, uc_tunnel_uip_lsb, MLXSW_REG_SFN_BASE_LEN, 0,
744 		     24, MLXSW_REG_SFN_REC_LEN, 0x0C, false);
745 
746 /* reg_sfn_uc_tunnel_port
747  * Tunnel port.
748  * Reserved on Spectrum.
749  * Access: RO
750  */
751 MLXSW_ITEM32_INDEXED(reg, sfn, tunnel_port, MLXSW_REG_SFN_BASE_LEN, 0, 4,
752 		     MLXSW_REG_SFN_REC_LEN, 0x10, false);
753 
754 static inline void
755 mlxsw_reg_sfn_uc_tunnel_unpack(char *payload, int rec_index, char *mac,
756 			       u16 *p_fid, u32 *p_uip,
757 			       enum mlxsw_reg_sfn_uc_tunnel_protocol *p_proto)
758 {
759 	u32 uip_msb, uip_lsb;
760 
761 	mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
762 	*p_fid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
763 	uip_msb = mlxsw_reg_sfn_uc_tunnel_uip_msb_get(payload, rec_index);
764 	uip_lsb = mlxsw_reg_sfn_uc_tunnel_uip_lsb_get(payload, rec_index);
765 	*p_uip = uip_msb << 24 | uip_lsb;
766 	*p_proto = mlxsw_reg_sfn_uc_tunnel_protocol_get(payload, rec_index);
767 }
768 
769 /* SPMS - Switch Port MSTP/RSTP State Register
770  * -------------------------------------------
771  * Configures the spanning tree state of a physical port.
772  */
773 #define MLXSW_REG_SPMS_ID 0x200D
774 #define MLXSW_REG_SPMS_LEN 0x404
775 
776 MLXSW_REG_DEFINE(spms, MLXSW_REG_SPMS_ID, MLXSW_REG_SPMS_LEN);
777 
778 /* reg_spms_local_port
779  * Local port number.
780  * Access: Index
781  */
782 MLXSW_ITEM32_LP(reg, spms, 0x00, 16, 0x00, 12);
783 
784 enum mlxsw_reg_spms_state {
785 	MLXSW_REG_SPMS_STATE_NO_CHANGE,
786 	MLXSW_REG_SPMS_STATE_DISCARDING,
787 	MLXSW_REG_SPMS_STATE_LEARNING,
788 	MLXSW_REG_SPMS_STATE_FORWARDING,
789 };
790 
791 /* reg_spms_state
792  * Spanning tree state of each VLAN ID (VID) of the local port.
793  * 0 - Do not change spanning tree state (used only when writing).
794  * 1 - Discarding. No learning or forwarding to/from this port (default).
795  * 2 - Learning. Port is learning, but not forwarding.
796  * 3 - Forwarding. Port is learning and forwarding.
797  * Access: RW
798  */
799 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
800 
801 static inline void mlxsw_reg_spms_pack(char *payload, u16 local_port)
802 {
803 	MLXSW_REG_ZERO(spms, payload);
804 	mlxsw_reg_spms_local_port_set(payload, local_port);
805 }
806 
807 static inline void mlxsw_reg_spms_vid_pack(char *payload, u16 vid,
808 					   enum mlxsw_reg_spms_state state)
809 {
810 	mlxsw_reg_spms_state_set(payload, vid, state);
811 }
812 
813 /* SPVID - Switch Port VID
814  * -----------------------
815  * The switch port VID configures the default VID for a port.
816  */
817 #define MLXSW_REG_SPVID_ID 0x200E
818 #define MLXSW_REG_SPVID_LEN 0x08
819 
820 MLXSW_REG_DEFINE(spvid, MLXSW_REG_SPVID_ID, MLXSW_REG_SPVID_LEN);
821 
822 /* reg_spvid_tport
823  * Port is tunnel port.
824  * Reserved when SwitchX/-2 or Spectrum-1.
825  * Access: Index
826  */
827 MLXSW_ITEM32(reg, spvid, tport, 0x00, 24, 1);
828 
829 /* reg_spvid_local_port
830  * When tport = 0: Local port number. Not supported for CPU port.
831  * When tport = 1: Tunnel port.
832  * Access: Index
833  */
834 MLXSW_ITEM32_LP(reg, spvid, 0x00, 16, 0x00, 12);
835 
836 /* reg_spvid_sub_port
837  * Virtual port within the physical port.
838  * Should be set to 0 when virtual ports are not enabled on the port.
839  * Access: Index
840  */
841 MLXSW_ITEM32(reg, spvid, sub_port, 0x00, 8, 8);
842 
843 /* reg_spvid_egr_et_set
844  * When VLAN is pushed at ingress (for untagged packets or for
845  * QinQ push mode) then the EtherType is decided at the egress port.
846  * Reserved when Spectrum-1.
847  * Access: RW
848  */
849 MLXSW_ITEM32(reg, spvid, egr_et_set, 0x04, 24, 1);
850 
851 /* reg_spvid_et_vlan
852  * EtherType used for when VLAN is pushed at ingress (for untagged
853  * packets or for QinQ push mode).
854  * 0: ether_type0 - (default)
855  * 1: ether_type1
856  * 2: ether_type2 - Reserved when Spectrum-1, supported by Spectrum-2
857  * Ethertype IDs are configured by SVER.
858  * Reserved when egr_et_set = 1.
859  * Access: RW
860  */
861 MLXSW_ITEM32(reg, spvid, et_vlan, 0x04, 16, 2);
862 
863 /* reg_spvid_pvid
864  * Port default VID
865  * Access: RW
866  */
867 MLXSW_ITEM32(reg, spvid, pvid, 0x04, 0, 12);
868 
869 static inline void mlxsw_reg_spvid_pack(char *payload, u16 local_port, u16 pvid,
870 					u8 et_vlan)
871 {
872 	MLXSW_REG_ZERO(spvid, payload);
873 	mlxsw_reg_spvid_local_port_set(payload, local_port);
874 	mlxsw_reg_spvid_pvid_set(payload, pvid);
875 	mlxsw_reg_spvid_et_vlan_set(payload, et_vlan);
876 }
877 
878 /* SPVM - Switch Port VLAN Membership
879  * ----------------------------------
880  * The Switch Port VLAN Membership register configures the VLAN membership
881  * of a port in a VLAN denoted by VID. VLAN membership is managed per
882  * virtual port. The register can be used to add and remove VID(s) from a port.
883  */
884 #define MLXSW_REG_SPVM_ID 0x200F
885 #define MLXSW_REG_SPVM_BASE_LEN 0x04 /* base length, without records */
886 #define MLXSW_REG_SPVM_REC_LEN 0x04 /* record length */
887 #define MLXSW_REG_SPVM_REC_MAX_COUNT 255
888 #define MLXSW_REG_SPVM_LEN (MLXSW_REG_SPVM_BASE_LEN +	\
889 		    MLXSW_REG_SPVM_REC_LEN * MLXSW_REG_SPVM_REC_MAX_COUNT)
890 
891 MLXSW_REG_DEFINE(spvm, MLXSW_REG_SPVM_ID, MLXSW_REG_SPVM_LEN);
892 
893 /* reg_spvm_pt
894  * Priority tagged. If this bit is set, packets forwarded to the port with
895  * untagged VLAN membership (u bit is set) will be tagged with priority tag
896  * (VID=0)
897  * Access: RW
898  */
899 MLXSW_ITEM32(reg, spvm, pt, 0x00, 31, 1);
900 
901 /* reg_spvm_pte
902  * Priority Tagged Update Enable. On Write operations, if this bit is cleared,
903  * the pt bit will NOT be updated. To update the pt bit, pte must be set.
904  * Access: WO
905  */
906 MLXSW_ITEM32(reg, spvm, pte, 0x00, 30, 1);
907 
908 /* reg_spvm_local_port
909  * Local port number.
910  * Access: Index
911  */
912 MLXSW_ITEM32_LP(reg, spvm, 0x00, 16, 0x00, 12);
913 
914 /* reg_spvm_sub_port
915  * Virtual port within the physical port.
916  * Should be set to 0 when virtual ports are not enabled on the port.
917  * Access: Index
918  */
919 MLXSW_ITEM32(reg, spvm, sub_port, 0x00, 8, 8);
920 
921 /* reg_spvm_num_rec
922  * Number of records to update. Each record contains: i, e, u, vid.
923  * Access: OP
924  */
925 MLXSW_ITEM32(reg, spvm, num_rec, 0x00, 0, 8);
926 
927 /* reg_spvm_rec_i
928  * Ingress membership in VLAN ID.
929  * Access: Index
930  */
931 MLXSW_ITEM32_INDEXED(reg, spvm, rec_i,
932 		     MLXSW_REG_SPVM_BASE_LEN, 14, 1,
933 		     MLXSW_REG_SPVM_REC_LEN, 0, false);
934 
935 /* reg_spvm_rec_e
936  * Egress membership in VLAN ID.
937  * Access: Index
938  */
939 MLXSW_ITEM32_INDEXED(reg, spvm, rec_e,
940 		     MLXSW_REG_SPVM_BASE_LEN, 13, 1,
941 		     MLXSW_REG_SPVM_REC_LEN, 0, false);
942 
943 /* reg_spvm_rec_u
944  * Untagged - port is an untagged member - egress transmission uses untagged
945  * frames on VID<n>
946  * Access: Index
947  */
948 MLXSW_ITEM32_INDEXED(reg, spvm, rec_u,
949 		     MLXSW_REG_SPVM_BASE_LEN, 12, 1,
950 		     MLXSW_REG_SPVM_REC_LEN, 0, false);
951 
952 /* reg_spvm_rec_vid
953  * Egress membership in VLAN ID.
954  * Access: Index
955  */
956 MLXSW_ITEM32_INDEXED(reg, spvm, rec_vid,
957 		     MLXSW_REG_SPVM_BASE_LEN, 0, 12,
958 		     MLXSW_REG_SPVM_REC_LEN, 0, false);
959 
960 static inline void mlxsw_reg_spvm_pack(char *payload, u16 local_port,
961 				       u16 vid_begin, u16 vid_end,
962 				       bool is_member, bool untagged)
963 {
964 	int size = vid_end - vid_begin + 1;
965 	int i;
966 
967 	MLXSW_REG_ZERO(spvm, payload);
968 	mlxsw_reg_spvm_local_port_set(payload, local_port);
969 	mlxsw_reg_spvm_num_rec_set(payload, size);
970 
971 	for (i = 0; i < size; i++) {
972 		mlxsw_reg_spvm_rec_i_set(payload, i, is_member);
973 		mlxsw_reg_spvm_rec_e_set(payload, i, is_member);
974 		mlxsw_reg_spvm_rec_u_set(payload, i, untagged);
975 		mlxsw_reg_spvm_rec_vid_set(payload, i, vid_begin + i);
976 	}
977 }
978 
979 /* SPAFT - Switch Port Acceptable Frame Types
980  * ------------------------------------------
981  * The Switch Port Acceptable Frame Types register configures the frame
982  * admittance of the port.
983  */
984 #define MLXSW_REG_SPAFT_ID 0x2010
985 #define MLXSW_REG_SPAFT_LEN 0x08
986 
987 MLXSW_REG_DEFINE(spaft, MLXSW_REG_SPAFT_ID, MLXSW_REG_SPAFT_LEN);
988 
989 /* reg_spaft_local_port
990  * Local port number.
991  * Access: Index
992  *
993  * Note: CPU port is not supported (all tag types are allowed).
994  */
995 MLXSW_ITEM32_LP(reg, spaft, 0x00, 16, 0x00, 12);
996 
997 /* reg_spaft_sub_port
998  * Virtual port within the physical port.
999  * Should be set to 0 when virtual ports are not enabled on the port.
1000  * Access: RW
1001  */
1002 MLXSW_ITEM32(reg, spaft, sub_port, 0x00, 8, 8);
1003 
1004 /* reg_spaft_allow_untagged
1005  * When set, untagged frames on the ingress are allowed (default).
1006  * Access: RW
1007  */
1008 MLXSW_ITEM32(reg, spaft, allow_untagged, 0x04, 31, 1);
1009 
1010 /* reg_spaft_allow_prio_tagged
1011  * When set, priority tagged frames on the ingress are allowed (default).
1012  * Access: RW
1013  */
1014 MLXSW_ITEM32(reg, spaft, allow_prio_tagged, 0x04, 30, 1);
1015 
1016 /* reg_spaft_allow_tagged
1017  * When set, tagged frames on the ingress are allowed (default).
1018  * Access: RW
1019  */
1020 MLXSW_ITEM32(reg, spaft, allow_tagged, 0x04, 29, 1);
1021 
1022 static inline void mlxsw_reg_spaft_pack(char *payload, u16 local_port,
1023 					bool allow_untagged)
1024 {
1025 	MLXSW_REG_ZERO(spaft, payload);
1026 	mlxsw_reg_spaft_local_port_set(payload, local_port);
1027 	mlxsw_reg_spaft_allow_untagged_set(payload, allow_untagged);
1028 	mlxsw_reg_spaft_allow_prio_tagged_set(payload, allow_untagged);
1029 	mlxsw_reg_spaft_allow_tagged_set(payload, true);
1030 }
1031 
1032 /* SFGC - Switch Flooding Group Configuration
1033  * ------------------------------------------
1034  * The following register controls the association of flooding tables and MIDs
1035  * to packet types used for flooding.
1036  */
1037 #define MLXSW_REG_SFGC_ID 0x2011
1038 #define MLXSW_REG_SFGC_LEN 0x14
1039 
1040 MLXSW_REG_DEFINE(sfgc, MLXSW_REG_SFGC_ID, MLXSW_REG_SFGC_LEN);
1041 
1042 enum mlxsw_reg_sfgc_type {
1043 	MLXSW_REG_SFGC_TYPE_BROADCAST,
1044 	MLXSW_REG_SFGC_TYPE_UNKNOWN_UNICAST,
1045 	MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4,
1046 	MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6,
1047 	MLXSW_REG_SFGC_TYPE_RESERVED,
1048 	MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP,
1049 	MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL,
1050 	MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST,
1051 	MLXSW_REG_SFGC_TYPE_MAX,
1052 };
1053 
1054 /* reg_sfgc_type
1055  * The traffic type to reach the flooding table.
1056  * Access: Index
1057  */
1058 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
1059 
1060 /* bridge_type is used in SFGC and SFMR. */
1061 enum mlxsw_reg_bridge_type {
1062 	MLXSW_REG_BRIDGE_TYPE_0 = 0, /* Used for .1q FIDs. */
1063 	MLXSW_REG_BRIDGE_TYPE_1 = 1, /* Used for .1d FIDs. */
1064 };
1065 
1066 /* reg_sfgc_bridge_type
1067  * Access: Index
1068  *
1069  * Note: SwitchX-2 only supports 802.1Q mode.
1070  */
1071 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
1072 
1073 enum mlxsw_flood_table_type {
1074 	MLXSW_REG_SFGC_TABLE_TYPE_VID = 1,
1075 	MLXSW_REG_SFGC_TABLE_TYPE_SINGLE = 2,
1076 	MLXSW_REG_SFGC_TABLE_TYPE_ANY = 0,
1077 	MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFSET = 3,
1078 	MLXSW_REG_SFGC_TABLE_TYPE_FID = 4,
1079 };
1080 
1081 /* reg_sfgc_table_type
1082  * See mlxsw_flood_table_type
1083  * Access: RW
1084  *
1085  * Note: FID offset and FID types are not supported in SwitchX-2.
1086  */
1087 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
1088 
1089 /* reg_sfgc_flood_table
1090  * Flooding table index to associate with the specific type on the specific
1091  * switch partition.
1092  * Access: RW
1093  */
1094 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
1095 
1096 /* reg_sfgc_counter_set_type
1097  * Counter Set Type for flow counters.
1098  * Access: RW
1099  */
1100 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
1101 
1102 /* reg_sfgc_counter_index
1103  * Counter Index for flow counters.
1104  * Access: RW
1105  */
1106 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
1107 
1108 /* reg_sfgc_mid_base
1109  * MID Base.
1110  * Access: RW
1111  *
1112  * Note: Reserved when legacy bridge model is used.
1113  */
1114 MLXSW_ITEM32(reg, sfgc, mid_base, 0x10, 0, 16);
1115 
1116 static inline void
1117 mlxsw_reg_sfgc_pack(char *payload, enum mlxsw_reg_sfgc_type type,
1118 		    enum mlxsw_reg_bridge_type bridge_type,
1119 		    enum mlxsw_flood_table_type table_type,
1120 		    unsigned int flood_table, u16 mid_base)
1121 {
1122 	MLXSW_REG_ZERO(sfgc, payload);
1123 	mlxsw_reg_sfgc_type_set(payload, type);
1124 	mlxsw_reg_sfgc_bridge_type_set(payload, bridge_type);
1125 	mlxsw_reg_sfgc_table_type_set(payload, table_type);
1126 	mlxsw_reg_sfgc_flood_table_set(payload, flood_table);
1127 	mlxsw_reg_sfgc_mid_base_set(payload, mid_base);
1128 }
1129 
1130 /* SFDF - Switch Filtering DB Flush
1131  * --------------------------------
1132  * The switch filtering DB flush register is used to flush the FDB.
1133  * Note that FDB notifications are flushed as well.
1134  */
1135 #define MLXSW_REG_SFDF_ID 0x2013
1136 #define MLXSW_REG_SFDF_LEN 0x14
1137 
1138 MLXSW_REG_DEFINE(sfdf, MLXSW_REG_SFDF_ID, MLXSW_REG_SFDF_LEN);
1139 
1140 /* reg_sfdf_swid
1141  * Switch partition ID.
1142  * Access: Index
1143  */
1144 MLXSW_ITEM32(reg, sfdf, swid, 0x00, 24, 8);
1145 
1146 enum mlxsw_reg_sfdf_flush_type {
1147 	MLXSW_REG_SFDF_FLUSH_PER_SWID,
1148 	MLXSW_REG_SFDF_FLUSH_PER_FID,
1149 	MLXSW_REG_SFDF_FLUSH_PER_PORT,
1150 	MLXSW_REG_SFDF_FLUSH_PER_PORT_AND_FID,
1151 	MLXSW_REG_SFDF_FLUSH_PER_LAG,
1152 	MLXSW_REG_SFDF_FLUSH_PER_LAG_AND_FID,
1153 	MLXSW_REG_SFDF_FLUSH_PER_NVE,
1154 	MLXSW_REG_SFDF_FLUSH_PER_NVE_AND_FID,
1155 };
1156 
1157 /* reg_sfdf_flush_type
1158  * Flush type.
1159  * 0 - All SWID dynamic entries are flushed.
1160  * 1 - All FID dynamic entries are flushed.
1161  * 2 - All dynamic entries pointing to port are flushed.
1162  * 3 - All FID dynamic entries pointing to port are flushed.
1163  * 4 - All dynamic entries pointing to LAG are flushed.
1164  * 5 - All FID dynamic entries pointing to LAG are flushed.
1165  * 6 - All entries of type "Unicast Tunnel" or "Multicast Tunnel" are
1166  *     flushed.
1167  * 7 - All entries of type "Unicast Tunnel" or "Multicast Tunnel" are
1168  *     flushed, per FID.
1169  * Access: RW
1170  */
1171 MLXSW_ITEM32(reg, sfdf, flush_type, 0x04, 28, 4);
1172 
1173 /* reg_sfdf_flush_static
1174  * Static.
1175  * 0 - Flush only dynamic entries.
1176  * 1 - Flush both dynamic and static entries.
1177  * Access: RW
1178  */
1179 MLXSW_ITEM32(reg, sfdf, flush_static, 0x04, 24, 1);
1180 
1181 static inline void mlxsw_reg_sfdf_pack(char *payload,
1182 				       enum mlxsw_reg_sfdf_flush_type type)
1183 {
1184 	MLXSW_REG_ZERO(sfdf, payload);
1185 	mlxsw_reg_sfdf_flush_type_set(payload, type);
1186 	mlxsw_reg_sfdf_flush_static_set(payload, true);
1187 }
1188 
1189 /* reg_sfdf_fid
1190  * FID to flush.
1191  * Access: RW
1192  */
1193 MLXSW_ITEM32(reg, sfdf, fid, 0x0C, 0, 16);
1194 
1195 /* reg_sfdf_system_port
1196  * Port to flush.
1197  * Access: RW
1198  */
1199 MLXSW_ITEM32(reg, sfdf, system_port, 0x0C, 0, 16);
1200 
1201 /* reg_sfdf_port_fid_system_port
1202  * Port to flush, pointed to by FID.
1203  * Access: RW
1204  */
1205 MLXSW_ITEM32(reg, sfdf, port_fid_system_port, 0x08, 0, 16);
1206 
1207 /* reg_sfdf_lag_id
1208  * LAG ID to flush.
1209  * Access: RW
1210  */
1211 MLXSW_ITEM32(reg, sfdf, lag_id, 0x0C, 0, 10);
1212 
1213 /* reg_sfdf_lag_fid_lag_id
1214  * LAG ID to flush, pointed to by FID.
1215  * Access: RW
1216  */
1217 MLXSW_ITEM32(reg, sfdf, lag_fid_lag_id, 0x08, 0, 10);
1218 
1219 /* SLDR - Switch LAG Descriptor Register
1220  * -----------------------------------------
1221  * The switch LAG descriptor register is populated by LAG descriptors.
1222  * Each LAG descriptor is indexed by lag_id. The LAG ID runs from 0 to
1223  * max_lag-1.
1224  */
1225 #define MLXSW_REG_SLDR_ID 0x2014
1226 #define MLXSW_REG_SLDR_LEN 0x0C /* counting in only one port in list */
1227 
1228 MLXSW_REG_DEFINE(sldr, MLXSW_REG_SLDR_ID, MLXSW_REG_SLDR_LEN);
1229 
1230 enum mlxsw_reg_sldr_op {
1231 	/* Indicates a creation of a new LAG-ID, lag_id must be valid */
1232 	MLXSW_REG_SLDR_OP_LAG_CREATE,
1233 	MLXSW_REG_SLDR_OP_LAG_DESTROY,
1234 	/* Ports that appear in the list have the Distributor enabled */
1235 	MLXSW_REG_SLDR_OP_LAG_ADD_PORT_LIST,
1236 	/* Removes ports from the disributor list */
1237 	MLXSW_REG_SLDR_OP_LAG_REMOVE_PORT_LIST,
1238 };
1239 
1240 /* reg_sldr_op
1241  * Operation.
1242  * Access: RW
1243  */
1244 MLXSW_ITEM32(reg, sldr, op, 0x00, 29, 3);
1245 
1246 /* reg_sldr_lag_id
1247  * LAG identifier. The lag_id is the index into the LAG descriptor table.
1248  * Access: Index
1249  */
1250 MLXSW_ITEM32(reg, sldr, lag_id, 0x00, 0, 10);
1251 
1252 static inline void mlxsw_reg_sldr_lag_create_pack(char *payload, u8 lag_id)
1253 {
1254 	MLXSW_REG_ZERO(sldr, payload);
1255 	mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_CREATE);
1256 	mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1257 }
1258 
1259 static inline void mlxsw_reg_sldr_lag_destroy_pack(char *payload, u8 lag_id)
1260 {
1261 	MLXSW_REG_ZERO(sldr, payload);
1262 	mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_DESTROY);
1263 	mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1264 }
1265 
1266 /* reg_sldr_num_ports
1267  * The number of member ports of the LAG.
1268  * Reserved for Create / Destroy operations
1269  * For Add / Remove operations - indicates the number of ports in the list.
1270  * Access: RW
1271  */
1272 MLXSW_ITEM32(reg, sldr, num_ports, 0x04, 24, 8);
1273 
1274 /* reg_sldr_system_port
1275  * System port.
1276  * Access: RW
1277  */
1278 MLXSW_ITEM32_INDEXED(reg, sldr, system_port, 0x08, 0, 16, 4, 0, false);
1279 
1280 static inline void mlxsw_reg_sldr_lag_add_port_pack(char *payload, u8 lag_id,
1281 						    u16 local_port)
1282 {
1283 	MLXSW_REG_ZERO(sldr, payload);
1284 	mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_ADD_PORT_LIST);
1285 	mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1286 	mlxsw_reg_sldr_num_ports_set(payload, 1);
1287 	mlxsw_reg_sldr_system_port_set(payload, 0, local_port);
1288 }
1289 
1290 static inline void mlxsw_reg_sldr_lag_remove_port_pack(char *payload, u8 lag_id,
1291 						       u16 local_port)
1292 {
1293 	MLXSW_REG_ZERO(sldr, payload);
1294 	mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_REMOVE_PORT_LIST);
1295 	mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1296 	mlxsw_reg_sldr_num_ports_set(payload, 1);
1297 	mlxsw_reg_sldr_system_port_set(payload, 0, local_port);
1298 }
1299 
1300 /* SLCR - Switch LAG Configuration 2 Register
1301  * -------------------------------------------
1302  * The Switch LAG Configuration register is used for configuring the
1303  * LAG properties of the switch.
1304  */
1305 #define MLXSW_REG_SLCR_ID 0x2015
1306 #define MLXSW_REG_SLCR_LEN 0x10
1307 
1308 MLXSW_REG_DEFINE(slcr, MLXSW_REG_SLCR_ID, MLXSW_REG_SLCR_LEN);
1309 
1310 enum mlxsw_reg_slcr_pp {
1311 	/* Global Configuration (for all ports) */
1312 	MLXSW_REG_SLCR_PP_GLOBAL,
1313 	/* Per port configuration, based on local_port field */
1314 	MLXSW_REG_SLCR_PP_PER_PORT,
1315 };
1316 
1317 /* reg_slcr_pp
1318  * Per Port Configuration
1319  * Note: Reading at Global mode results in reading port 1 configuration.
1320  * Access: Index
1321  */
1322 MLXSW_ITEM32(reg, slcr, pp, 0x00, 24, 1);
1323 
1324 /* reg_slcr_local_port
1325  * Local port number
1326  * Supported from CPU port
1327  * Not supported from router port
1328  * Reserved when pp = Global Configuration
1329  * Access: Index
1330  */
1331 MLXSW_ITEM32_LP(reg, slcr, 0x00, 16, 0x00, 12);
1332 
1333 enum mlxsw_reg_slcr_type {
1334 	MLXSW_REG_SLCR_TYPE_CRC, /* default */
1335 	MLXSW_REG_SLCR_TYPE_XOR,
1336 	MLXSW_REG_SLCR_TYPE_RANDOM,
1337 };
1338 
1339 /* reg_slcr_type
1340  * Hash type
1341  * Access: RW
1342  */
1343 MLXSW_ITEM32(reg, slcr, type, 0x00, 0, 4);
1344 
1345 /* Ingress port */
1346 #define MLXSW_REG_SLCR_LAG_HASH_IN_PORT		BIT(0)
1347 /* SMAC - for IPv4 and IPv6 packets */
1348 #define MLXSW_REG_SLCR_LAG_HASH_SMAC_IP		BIT(1)
1349 /* SMAC - for non-IP packets */
1350 #define MLXSW_REG_SLCR_LAG_HASH_SMAC_NONIP	BIT(2)
1351 #define MLXSW_REG_SLCR_LAG_HASH_SMAC \
1352 	(MLXSW_REG_SLCR_LAG_HASH_SMAC_IP | \
1353 	 MLXSW_REG_SLCR_LAG_HASH_SMAC_NONIP)
1354 /* DMAC - for IPv4 and IPv6 packets */
1355 #define MLXSW_REG_SLCR_LAG_HASH_DMAC_IP		BIT(3)
1356 /* DMAC - for non-IP packets */
1357 #define MLXSW_REG_SLCR_LAG_HASH_DMAC_NONIP	BIT(4)
1358 #define MLXSW_REG_SLCR_LAG_HASH_DMAC \
1359 	(MLXSW_REG_SLCR_LAG_HASH_DMAC_IP | \
1360 	 MLXSW_REG_SLCR_LAG_HASH_DMAC_NONIP)
1361 /* Ethertype - for IPv4 and IPv6 packets */
1362 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_IP	BIT(5)
1363 /* Ethertype - for non-IP packets */
1364 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_NONIP	BIT(6)
1365 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE \
1366 	(MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_IP | \
1367 	 MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_NONIP)
1368 /* VLAN ID - for IPv4 and IPv6 packets */
1369 #define MLXSW_REG_SLCR_LAG_HASH_VLANID_IP	BIT(7)
1370 /* VLAN ID - for non-IP packets */
1371 #define MLXSW_REG_SLCR_LAG_HASH_VLANID_NONIP	BIT(8)
1372 #define MLXSW_REG_SLCR_LAG_HASH_VLANID \
1373 	(MLXSW_REG_SLCR_LAG_HASH_VLANID_IP | \
1374 	 MLXSW_REG_SLCR_LAG_HASH_VLANID_NONIP)
1375 /* Source IP address (can be IPv4 or IPv6) */
1376 #define MLXSW_REG_SLCR_LAG_HASH_SIP		BIT(9)
1377 /* Destination IP address (can be IPv4 or IPv6) */
1378 #define MLXSW_REG_SLCR_LAG_HASH_DIP		BIT(10)
1379 /* TCP/UDP source port */
1380 #define MLXSW_REG_SLCR_LAG_HASH_SPORT		BIT(11)
1381 /* TCP/UDP destination port*/
1382 #define MLXSW_REG_SLCR_LAG_HASH_DPORT		BIT(12)
1383 /* IPv4 Protocol/IPv6 Next Header */
1384 #define MLXSW_REG_SLCR_LAG_HASH_IPPROTO		BIT(13)
1385 /* IPv6 Flow label */
1386 #define MLXSW_REG_SLCR_LAG_HASH_FLOWLABEL	BIT(14)
1387 /* SID - FCoE source ID */
1388 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_SID	BIT(15)
1389 /* DID - FCoE destination ID */
1390 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_DID	BIT(16)
1391 /* OXID - FCoE originator exchange ID */
1392 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_OXID	BIT(17)
1393 /* Destination QP number - for RoCE packets */
1394 #define MLXSW_REG_SLCR_LAG_HASH_ROCE_DQP	BIT(19)
1395 
1396 /* reg_slcr_lag_hash
1397  * LAG hashing configuration. This is a bitmask, in which each set
1398  * bit includes the corresponding item in the LAG hash calculation.
1399  * The default lag_hash contains SMAC, DMAC, VLANID and
1400  * Ethertype (for all packet types).
1401  * Access: RW
1402  */
1403 MLXSW_ITEM32(reg, slcr, lag_hash, 0x04, 0, 20);
1404 
1405 /* reg_slcr_seed
1406  * LAG seed value. The seed is the same for all ports.
1407  * Access: RW
1408  */
1409 MLXSW_ITEM32(reg, slcr, seed, 0x08, 0, 32);
1410 
1411 static inline void mlxsw_reg_slcr_pack(char *payload, u16 lag_hash, u32 seed)
1412 {
1413 	MLXSW_REG_ZERO(slcr, payload);
1414 	mlxsw_reg_slcr_pp_set(payload, MLXSW_REG_SLCR_PP_GLOBAL);
1415 	mlxsw_reg_slcr_type_set(payload, MLXSW_REG_SLCR_TYPE_CRC);
1416 	mlxsw_reg_slcr_lag_hash_set(payload, lag_hash);
1417 	mlxsw_reg_slcr_seed_set(payload, seed);
1418 }
1419 
1420 /* SLCOR - Switch LAG Collector Register
1421  * -------------------------------------
1422  * The Switch LAG Collector register controls the Local Port membership
1423  * in a LAG and enablement of the collector.
1424  */
1425 #define MLXSW_REG_SLCOR_ID 0x2016
1426 #define MLXSW_REG_SLCOR_LEN 0x10
1427 
1428 MLXSW_REG_DEFINE(slcor, MLXSW_REG_SLCOR_ID, MLXSW_REG_SLCOR_LEN);
1429 
1430 enum mlxsw_reg_slcor_col {
1431 	/* Port is added with collector disabled */
1432 	MLXSW_REG_SLCOR_COL_LAG_ADD_PORT,
1433 	MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED,
1434 	MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_DISABLED,
1435 	MLXSW_REG_SLCOR_COL_LAG_REMOVE_PORT,
1436 };
1437 
1438 /* reg_slcor_col
1439  * Collector configuration
1440  * Access: RW
1441  */
1442 MLXSW_ITEM32(reg, slcor, col, 0x00, 30, 2);
1443 
1444 /* reg_slcor_local_port
1445  * Local port number
1446  * Not supported for CPU port
1447  * Access: Index
1448  */
1449 MLXSW_ITEM32_LP(reg, slcor, 0x00, 16, 0x00, 12);
1450 
1451 /* reg_slcor_lag_id
1452  * LAG Identifier. Index into the LAG descriptor table.
1453  * Access: Index
1454  */
1455 MLXSW_ITEM32(reg, slcor, lag_id, 0x00, 0, 10);
1456 
1457 /* reg_slcor_port_index
1458  * Port index in the LAG list. Only valid on Add Port to LAG col.
1459  * Valid range is from 0 to cap_max_lag_members-1
1460  * Access: RW
1461  */
1462 MLXSW_ITEM32(reg, slcor, port_index, 0x04, 0, 10);
1463 
1464 static inline void mlxsw_reg_slcor_pack(char *payload,
1465 					u16 local_port, u16 lag_id,
1466 					enum mlxsw_reg_slcor_col col)
1467 {
1468 	MLXSW_REG_ZERO(slcor, payload);
1469 	mlxsw_reg_slcor_col_set(payload, col);
1470 	mlxsw_reg_slcor_local_port_set(payload, local_port);
1471 	mlxsw_reg_slcor_lag_id_set(payload, lag_id);
1472 }
1473 
1474 static inline void mlxsw_reg_slcor_port_add_pack(char *payload,
1475 						 u16 local_port, u16 lag_id,
1476 						 u8 port_index)
1477 {
1478 	mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1479 			     MLXSW_REG_SLCOR_COL_LAG_ADD_PORT);
1480 	mlxsw_reg_slcor_port_index_set(payload, port_index);
1481 }
1482 
1483 static inline void mlxsw_reg_slcor_port_remove_pack(char *payload,
1484 						    u16 local_port, u16 lag_id)
1485 {
1486 	mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1487 			     MLXSW_REG_SLCOR_COL_LAG_REMOVE_PORT);
1488 }
1489 
1490 static inline void mlxsw_reg_slcor_col_enable_pack(char *payload,
1491 						   u16 local_port, u16 lag_id)
1492 {
1493 	mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1494 			     MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED);
1495 }
1496 
1497 static inline void mlxsw_reg_slcor_col_disable_pack(char *payload,
1498 						    u16 local_port, u16 lag_id)
1499 {
1500 	mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1501 			     MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED);
1502 }
1503 
1504 /* SPMLR - Switch Port MAC Learning Register
1505  * -----------------------------------------
1506  * Controls the Switch MAC learning policy per port.
1507  */
1508 #define MLXSW_REG_SPMLR_ID 0x2018
1509 #define MLXSW_REG_SPMLR_LEN 0x8
1510 
1511 MLXSW_REG_DEFINE(spmlr, MLXSW_REG_SPMLR_ID, MLXSW_REG_SPMLR_LEN);
1512 
1513 /* reg_spmlr_local_port
1514  * Local port number.
1515  * Access: Index
1516  */
1517 MLXSW_ITEM32_LP(reg, spmlr, 0x00, 16, 0x00, 12);
1518 
1519 /* reg_spmlr_sub_port
1520  * Virtual port within the physical port.
1521  * Should be set to 0 when virtual ports are not enabled on the port.
1522  * Access: Index
1523  */
1524 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
1525 
1526 enum mlxsw_reg_spmlr_learn_mode {
1527 	MLXSW_REG_SPMLR_LEARN_MODE_DISABLE = 0,
1528 	MLXSW_REG_SPMLR_LEARN_MODE_ENABLE = 2,
1529 	MLXSW_REG_SPMLR_LEARN_MODE_SEC = 3,
1530 };
1531 
1532 /* reg_spmlr_learn_mode
1533  * Learning mode on the port.
1534  * 0 - Learning disabled.
1535  * 2 - Learning enabled.
1536  * 3 - Security mode.
1537  *
1538  * In security mode the switch does not learn MACs on the port, but uses the
1539  * SMAC to see if it exists on another ingress port. If so, the packet is
1540  * classified as a bad packet and is discarded unless the software registers
1541  * to receive port security error packets usign HPKT.
1542  */
1543 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
1544 
1545 static inline void mlxsw_reg_spmlr_pack(char *payload, u16 local_port,
1546 					enum mlxsw_reg_spmlr_learn_mode mode)
1547 {
1548 	MLXSW_REG_ZERO(spmlr, payload);
1549 	mlxsw_reg_spmlr_local_port_set(payload, local_port);
1550 	mlxsw_reg_spmlr_sub_port_set(payload, 0);
1551 	mlxsw_reg_spmlr_learn_mode_set(payload, mode);
1552 }
1553 
1554 /* SVFA - Switch VID to FID Allocation Register
1555  * --------------------------------------------
1556  * Controls the VID to FID mapping and {Port, VID} to FID mapping for
1557  * virtualized ports.
1558  */
1559 #define MLXSW_REG_SVFA_ID 0x201C
1560 #define MLXSW_REG_SVFA_LEN 0x18
1561 
1562 MLXSW_REG_DEFINE(svfa, MLXSW_REG_SVFA_ID, MLXSW_REG_SVFA_LEN);
1563 
1564 /* reg_svfa_swid
1565  * Switch partition ID.
1566  * Access: Index
1567  */
1568 MLXSW_ITEM32(reg, svfa, swid, 0x00, 24, 8);
1569 
1570 /* reg_svfa_local_port
1571  * Local port number.
1572  * Access: Index
1573  *
1574  * Note: Reserved for 802.1Q FIDs.
1575  */
1576 MLXSW_ITEM32_LP(reg, svfa, 0x00, 16, 0x00, 12);
1577 
1578 enum mlxsw_reg_svfa_mt {
1579 	MLXSW_REG_SVFA_MT_VID_TO_FID,
1580 	MLXSW_REG_SVFA_MT_PORT_VID_TO_FID,
1581 	MLXSW_REG_SVFA_MT_VNI_TO_FID,
1582 };
1583 
1584 /* reg_svfa_mapping_table
1585  * Mapping table:
1586  * 0 - VID to FID
1587  * 1 - {Port, VID} to FID
1588  * Access: Index
1589  *
1590  * Note: Reserved for SwitchX-2.
1591  */
1592 MLXSW_ITEM32(reg, svfa, mapping_table, 0x00, 8, 3);
1593 
1594 /* reg_svfa_v
1595  * Valid.
1596  * Valid if set.
1597  * Access: RW
1598  *
1599  * Note: Reserved for SwitchX-2.
1600  */
1601 MLXSW_ITEM32(reg, svfa, v, 0x00, 0, 1);
1602 
1603 /* reg_svfa_fid
1604  * Filtering ID.
1605  * Access: RW
1606  */
1607 MLXSW_ITEM32(reg, svfa, fid, 0x04, 16, 16);
1608 
1609 /* reg_svfa_vid
1610  * VLAN ID.
1611  * Access: Index
1612  */
1613 MLXSW_ITEM32(reg, svfa, vid, 0x04, 0, 12);
1614 
1615 /* reg_svfa_counter_set_type
1616  * Counter set type for flow counters.
1617  * Access: RW
1618  *
1619  * Note: Reserved for SwitchX-2.
1620  */
1621 MLXSW_ITEM32(reg, svfa, counter_set_type, 0x08, 24, 8);
1622 
1623 /* reg_svfa_counter_index
1624  * Counter index for flow counters.
1625  * Access: RW
1626  *
1627  * Note: Reserved for SwitchX-2.
1628  */
1629 MLXSW_ITEM32(reg, svfa, counter_index, 0x08, 0, 24);
1630 
1631 /* reg_svfa_vni
1632  * Virtual Network Identifier.
1633  * Access: Index
1634  *
1635  * Note: Reserved when mapping_table is not 2 (VNI mapping table).
1636  */
1637 MLXSW_ITEM32(reg, svfa, vni, 0x10, 0, 24);
1638 
1639 /* reg_svfa_irif_v
1640  * Ingress RIF valid.
1641  * 0 - Ingress RIF is not valid, no ingress RIF assigned.
1642  * 1 - Ingress RIF valid.
1643  * Must not be set for a non enabled RIF.
1644  * Access: RW
1645  *
1646  * Note: Reserved when legacy bridge model is used.
1647  */
1648 MLXSW_ITEM32(reg, svfa, irif_v, 0x14, 24, 1);
1649 
1650 /* reg_svfa_irif
1651  * Ingress RIF (Router Interface).
1652  * Range is 0..cap_max_router_interfaces-1.
1653  * Access: RW
1654  *
1655  * Note: Reserved when legacy bridge model is used and when irif_v=0.
1656  */
1657 MLXSW_ITEM32(reg, svfa, irif, 0x14, 0, 16);
1658 
1659 static inline void __mlxsw_reg_svfa_pack(char *payload,
1660 					 enum mlxsw_reg_svfa_mt mt, bool valid,
1661 					 u16 fid, bool irif_v, u16 irif)
1662 {
1663 	MLXSW_REG_ZERO(svfa, payload);
1664 	mlxsw_reg_svfa_swid_set(payload, 0);
1665 	mlxsw_reg_svfa_mapping_table_set(payload, mt);
1666 	mlxsw_reg_svfa_v_set(payload, valid);
1667 	mlxsw_reg_svfa_fid_set(payload, fid);
1668 	mlxsw_reg_svfa_irif_v_set(payload, irif_v);
1669 	mlxsw_reg_svfa_irif_set(payload, irif_v ? irif : 0);
1670 }
1671 
1672 static inline void mlxsw_reg_svfa_port_vid_pack(char *payload, u16 local_port,
1673 						bool valid, u16 fid, u16 vid,
1674 						bool irif_v, u16 irif)
1675 {
1676 	enum mlxsw_reg_svfa_mt mt = MLXSW_REG_SVFA_MT_PORT_VID_TO_FID;
1677 
1678 	__mlxsw_reg_svfa_pack(payload, mt, valid, fid, irif_v, irif);
1679 	mlxsw_reg_svfa_local_port_set(payload, local_port);
1680 	mlxsw_reg_svfa_vid_set(payload, vid);
1681 }
1682 
1683 static inline void mlxsw_reg_svfa_vid_pack(char *payload, bool valid, u16 fid,
1684 					   u16 vid, bool irif_v, u16 irif)
1685 {
1686 	enum mlxsw_reg_svfa_mt mt = MLXSW_REG_SVFA_MT_VID_TO_FID;
1687 
1688 	__mlxsw_reg_svfa_pack(payload, mt, valid, fid, irif_v, irif);
1689 	mlxsw_reg_svfa_vid_set(payload, vid);
1690 }
1691 
1692 static inline void mlxsw_reg_svfa_vni_pack(char *payload, bool valid, u16 fid,
1693 					   u32 vni, bool irif_v, u16 irif)
1694 {
1695 	enum mlxsw_reg_svfa_mt mt = MLXSW_REG_SVFA_MT_VNI_TO_FID;
1696 
1697 	__mlxsw_reg_svfa_pack(payload, mt, valid, fid, irif_v, irif);
1698 	mlxsw_reg_svfa_vni_set(payload, vni);
1699 }
1700 
1701 /*  SPVTR - Switch Port VLAN Stacking Register
1702  *  ------------------------------------------
1703  *  The Switch Port VLAN Stacking register configures the VLAN mode of the port
1704  *  to enable VLAN stacking.
1705  */
1706 #define MLXSW_REG_SPVTR_ID 0x201D
1707 #define MLXSW_REG_SPVTR_LEN 0x10
1708 
1709 MLXSW_REG_DEFINE(spvtr, MLXSW_REG_SPVTR_ID, MLXSW_REG_SPVTR_LEN);
1710 
1711 /* reg_spvtr_tport
1712  * Port is tunnel port.
1713  * Access: Index
1714  *
1715  * Note: Reserved when SwitchX/-2 or Spectrum-1.
1716  */
1717 MLXSW_ITEM32(reg, spvtr, tport, 0x00, 24, 1);
1718 
1719 /* reg_spvtr_local_port
1720  * When tport = 0: local port number (Not supported from/to CPU).
1721  * When tport = 1: tunnel port.
1722  * Access: Index
1723  */
1724 MLXSW_ITEM32_LP(reg, spvtr, 0x00, 16, 0x00, 12);
1725 
1726 /* reg_spvtr_ippe
1727  * Ingress Port Prio Mode Update Enable.
1728  * When set, the Port Prio Mode is updated with the provided ipprio_mode field.
1729  * Reserved on Get operations.
1730  * Access: OP
1731  */
1732 MLXSW_ITEM32(reg, spvtr, ippe, 0x04, 31, 1);
1733 
1734 /* reg_spvtr_ipve
1735  * Ingress Port VID Mode Update Enable.
1736  * When set, the Ingress Port VID Mode is updated with the provided ipvid_mode
1737  * field.
1738  * Reserved on Get operations.
1739  * Access: OP
1740  */
1741 MLXSW_ITEM32(reg, spvtr, ipve, 0x04, 30, 1);
1742 
1743 /* reg_spvtr_epve
1744  * Egress Port VID Mode Update Enable.
1745  * When set, the Egress Port VID Mode is updated with the provided epvid_mode
1746  * field.
1747  * Access: OP
1748  */
1749 MLXSW_ITEM32(reg, spvtr, epve, 0x04, 29, 1);
1750 
1751 /* reg_spvtr_ipprio_mode
1752  * Ingress Port Priority Mode.
1753  * This controls the PCP and DEI of the new outer VLAN
1754  * Note: for SwitchX/-2 the DEI is not affected.
1755  * 0: use port default PCP and DEI (configured by QPDPC).
1756  * 1: use C-VLAN PCP and DEI.
1757  * Has no effect when ipvid_mode = 0.
1758  * Reserved when tport = 1.
1759  * Access: RW
1760  */
1761 MLXSW_ITEM32(reg, spvtr, ipprio_mode, 0x04, 20, 4);
1762 
1763 enum mlxsw_reg_spvtr_ipvid_mode {
1764 	/* IEEE Compliant PVID (default) */
1765 	MLXSW_REG_SPVTR_IPVID_MODE_IEEE_COMPLIANT_PVID,
1766 	/* Push VLAN (for VLAN stacking, except prio tagged packets) */
1767 	MLXSW_REG_SPVTR_IPVID_MODE_PUSH_VLAN_FOR_UNTAGGED_PACKET,
1768 	/* Always push VLAN (also for prio tagged packets) */
1769 	MLXSW_REG_SPVTR_IPVID_MODE_ALWAYS_PUSH_VLAN,
1770 };
1771 
1772 /* reg_spvtr_ipvid_mode
1773  * Ingress Port VLAN-ID Mode.
1774  * For Spectrum family, this affects the values of SPVM.i
1775  * Access: RW
1776  */
1777 MLXSW_ITEM32(reg, spvtr, ipvid_mode, 0x04, 16, 4);
1778 
1779 enum mlxsw_reg_spvtr_epvid_mode {
1780 	/* IEEE Compliant VLAN membership */
1781 	MLXSW_REG_SPVTR_EPVID_MODE_IEEE_COMPLIANT_VLAN_MEMBERSHIP,
1782 	/* Pop VLAN (for VLAN stacking) */
1783 	MLXSW_REG_SPVTR_EPVID_MODE_POP_VLAN,
1784 };
1785 
1786 /* reg_spvtr_epvid_mode
1787  * Egress Port VLAN-ID Mode.
1788  * For Spectrum family, this affects the values of SPVM.e,u,pt.
1789  * Access: WO
1790  */
1791 MLXSW_ITEM32(reg, spvtr, epvid_mode, 0x04, 0, 4);
1792 
1793 static inline void mlxsw_reg_spvtr_pack(char *payload, bool tport,
1794 					u16 local_port,
1795 					enum mlxsw_reg_spvtr_ipvid_mode ipvid_mode)
1796 {
1797 	MLXSW_REG_ZERO(spvtr, payload);
1798 	mlxsw_reg_spvtr_tport_set(payload, tport);
1799 	mlxsw_reg_spvtr_local_port_set(payload, local_port);
1800 	mlxsw_reg_spvtr_ipvid_mode_set(payload, ipvid_mode);
1801 	mlxsw_reg_spvtr_ipve_set(payload, true);
1802 }
1803 
1804 /* SVPE - Switch Virtual-Port Enabling Register
1805  * --------------------------------------------
1806  * Enables port virtualization.
1807  */
1808 #define MLXSW_REG_SVPE_ID 0x201E
1809 #define MLXSW_REG_SVPE_LEN 0x4
1810 
1811 MLXSW_REG_DEFINE(svpe, MLXSW_REG_SVPE_ID, MLXSW_REG_SVPE_LEN);
1812 
1813 /* reg_svpe_local_port
1814  * Local port number
1815  * Access: Index
1816  *
1817  * Note: CPU port is not supported (uses VLAN mode only).
1818  */
1819 MLXSW_ITEM32_LP(reg, svpe, 0x00, 16, 0x00, 12);
1820 
1821 /* reg_svpe_vp_en
1822  * Virtual port enable.
1823  * 0 - Disable, VLAN mode (VID to FID).
1824  * 1 - Enable, Virtual port mode ({Port, VID} to FID).
1825  * Access: RW
1826  */
1827 MLXSW_ITEM32(reg, svpe, vp_en, 0x00, 8, 1);
1828 
1829 static inline void mlxsw_reg_svpe_pack(char *payload, u16 local_port,
1830 				       bool enable)
1831 {
1832 	MLXSW_REG_ZERO(svpe, payload);
1833 	mlxsw_reg_svpe_local_port_set(payload, local_port);
1834 	mlxsw_reg_svpe_vp_en_set(payload, enable);
1835 }
1836 
1837 /* SFMR - Switch FID Management Register
1838  * -------------------------------------
1839  * Creates and configures FIDs.
1840  */
1841 #define MLXSW_REG_SFMR_ID 0x201F
1842 #define MLXSW_REG_SFMR_LEN 0x30
1843 
1844 MLXSW_REG_DEFINE(sfmr, MLXSW_REG_SFMR_ID, MLXSW_REG_SFMR_LEN);
1845 
1846 enum mlxsw_reg_sfmr_op {
1847 	MLXSW_REG_SFMR_OP_CREATE_FID,
1848 	MLXSW_REG_SFMR_OP_DESTROY_FID,
1849 };
1850 
1851 /* reg_sfmr_op
1852  * Operation.
1853  * 0 - Create or edit FID.
1854  * 1 - Destroy FID.
1855  * Access: WO
1856  */
1857 MLXSW_ITEM32(reg, sfmr, op, 0x00, 24, 4);
1858 
1859 /* reg_sfmr_fid
1860  * Filtering ID.
1861  * Access: Index
1862  */
1863 MLXSW_ITEM32(reg, sfmr, fid, 0x00, 0, 16);
1864 
1865 /* reg_sfmr_flood_rsp
1866  * Router sub-port flooding table.
1867  * 0 - Regular flooding table.
1868  * 1 - Router sub-port flooding table. For this FID the flooding is per
1869  * router-sub-port local_port. Must not be set for a FID which is not a
1870  * router-sub-port and must be set prior to enabling the relevant RIF.
1871  * Access: RW
1872  *
1873  * Note: Reserved when legacy bridge model is used.
1874  */
1875 MLXSW_ITEM32(reg, sfmr, flood_rsp, 0x08, 31, 1);
1876 
1877 /* reg_sfmr_flood_bridge_type
1878  * Flood bridge type (see SFGC.bridge_type).
1879  * 0 - type_0.
1880  * 1 - type_1.
1881  * Access: RW
1882  *
1883  * Note: Reserved when legacy bridge model is used and when flood_rsp=1.
1884  */
1885 MLXSW_ITEM32(reg, sfmr, flood_bridge_type, 0x08, 28, 1);
1886 
1887 /* reg_sfmr_fid_offset
1888  * FID offset.
1889  * Used to point into the flooding table selected by SFGC register if
1890  * the table is of type FID-Offset. Otherwise, this field is reserved.
1891  * Access: RW
1892  */
1893 MLXSW_ITEM32(reg, sfmr, fid_offset, 0x08, 0, 16);
1894 
1895 /* reg_sfmr_vtfp
1896  * Valid Tunnel Flood Pointer.
1897  * If not set, then nve_tunnel_flood_ptr is reserved and considered NULL.
1898  * Access: RW
1899  *
1900  * Note: Reserved for 802.1Q FIDs.
1901  */
1902 MLXSW_ITEM32(reg, sfmr, vtfp, 0x0C, 31, 1);
1903 
1904 /* reg_sfmr_nve_tunnel_flood_ptr
1905  * Underlay Flooding and BC Pointer.
1906  * Used as a pointer to the first entry of the group based link lists of
1907  * flooding or BC entries (for NVE tunnels).
1908  * Access: RW
1909  */
1910 MLXSW_ITEM32(reg, sfmr, nve_tunnel_flood_ptr, 0x0C, 0, 24);
1911 
1912 /* reg_sfmr_vv
1913  * VNI Valid.
1914  * If not set, then vni is reserved.
1915  * Access: RW
1916  *
1917  * Note: Reserved for 802.1Q FIDs.
1918  */
1919 MLXSW_ITEM32(reg, sfmr, vv, 0x10, 31, 1);
1920 
1921 /* reg_sfmr_vni
1922  * Virtual Network Identifier.
1923  * When legacy bridge model is used, a given VNI can only be assigned to one
1924  * FID. When unified bridge model is used, it configures only the FID->VNI,
1925  * the VNI->FID is done by SVFA.
1926  * Access: RW
1927  */
1928 MLXSW_ITEM32(reg, sfmr, vni, 0x10, 0, 24);
1929 
1930 /* reg_sfmr_irif_v
1931  * Ingress RIF valid.
1932  * 0 - Ingress RIF is not valid, no ingress RIF assigned.
1933  * 1 - Ingress RIF valid.
1934  * Must not be set for a non valid RIF.
1935  * Access: RW
1936  *
1937  * Note: Reserved when legacy bridge model is used.
1938  */
1939 MLXSW_ITEM32(reg, sfmr, irif_v, 0x14, 24, 1);
1940 
1941 /* reg_sfmr_irif
1942  * Ingress RIF (Router Interface).
1943  * Range is 0..cap_max_router_interfaces-1.
1944  * Access: RW
1945  *
1946  * Note: Reserved when legacy bridge model is used and when irif_v=0.
1947  */
1948 MLXSW_ITEM32(reg, sfmr, irif, 0x14, 0, 16);
1949 
1950 /* reg_sfmr_smpe_valid
1951  * SMPE is valid.
1952  * Access: RW
1953  *
1954  * Note: Reserved when legacy bridge model is used, when flood_rsp=1 and on
1955  * Spectrum-1.
1956  */
1957 MLXSW_ITEM32(reg, sfmr, smpe_valid, 0x28, 20, 1);
1958 
1959 /* reg_sfmr_smpe
1960  * Switch multicast port to egress VID.
1961  * Range is 0..cap_max_rmpe-1
1962  * Access: RW
1963  *
1964  * Note: Reserved when legacy bridge model is used, when flood_rsp=1 and on
1965  * Spectrum-1.
1966  */
1967 MLXSW_ITEM32(reg, sfmr, smpe, 0x28, 0, 16);
1968 
1969 static inline void mlxsw_reg_sfmr_pack(char *payload,
1970 				       enum mlxsw_reg_sfmr_op op, u16 fid,
1971 				       u16 fid_offset, bool flood_rsp,
1972 				       enum mlxsw_reg_bridge_type bridge_type,
1973 				       bool smpe_valid, u16 smpe)
1974 {
1975 	MLXSW_REG_ZERO(sfmr, payload);
1976 	mlxsw_reg_sfmr_op_set(payload, op);
1977 	mlxsw_reg_sfmr_fid_set(payload, fid);
1978 	mlxsw_reg_sfmr_fid_offset_set(payload, fid_offset);
1979 	mlxsw_reg_sfmr_vtfp_set(payload, false);
1980 	mlxsw_reg_sfmr_vv_set(payload, false);
1981 	mlxsw_reg_sfmr_flood_rsp_set(payload, flood_rsp);
1982 	mlxsw_reg_sfmr_flood_bridge_type_set(payload, bridge_type);
1983 	mlxsw_reg_sfmr_smpe_valid_set(payload, smpe_valid);
1984 	mlxsw_reg_sfmr_smpe_set(payload, smpe);
1985 }
1986 
1987 /* SPVMLR - Switch Port VLAN MAC Learning Register
1988  * -----------------------------------------------
1989  * Controls the switch MAC learning policy per {Port, VID}.
1990  */
1991 #define MLXSW_REG_SPVMLR_ID 0x2020
1992 #define MLXSW_REG_SPVMLR_BASE_LEN 0x04 /* base length, without records */
1993 #define MLXSW_REG_SPVMLR_REC_LEN 0x04 /* record length */
1994 #define MLXSW_REG_SPVMLR_REC_MAX_COUNT 255
1995 #define MLXSW_REG_SPVMLR_LEN (MLXSW_REG_SPVMLR_BASE_LEN + \
1996 			      MLXSW_REG_SPVMLR_REC_LEN * \
1997 			      MLXSW_REG_SPVMLR_REC_MAX_COUNT)
1998 
1999 MLXSW_REG_DEFINE(spvmlr, MLXSW_REG_SPVMLR_ID, MLXSW_REG_SPVMLR_LEN);
2000 
2001 /* reg_spvmlr_local_port
2002  * Local ingress port.
2003  * Access: Index
2004  *
2005  * Note: CPU port is not supported.
2006  */
2007 MLXSW_ITEM32_LP(reg, spvmlr, 0x00, 16, 0x00, 12);
2008 
2009 /* reg_spvmlr_num_rec
2010  * Number of records to update.
2011  * Access: OP
2012  */
2013 MLXSW_ITEM32(reg, spvmlr, num_rec, 0x00, 0, 8);
2014 
2015 /* reg_spvmlr_rec_learn_enable
2016  * 0 - Disable learning for {Port, VID}.
2017  * 1 - Enable learning for {Port, VID}.
2018  * Access: RW
2019  */
2020 MLXSW_ITEM32_INDEXED(reg, spvmlr, rec_learn_enable, MLXSW_REG_SPVMLR_BASE_LEN,
2021 		     31, 1, MLXSW_REG_SPVMLR_REC_LEN, 0x00, false);
2022 
2023 /* reg_spvmlr_rec_vid
2024  * VLAN ID to be added/removed from port or for querying.
2025  * Access: Index
2026  */
2027 MLXSW_ITEM32_INDEXED(reg, spvmlr, rec_vid, MLXSW_REG_SPVMLR_BASE_LEN, 0, 12,
2028 		     MLXSW_REG_SPVMLR_REC_LEN, 0x00, false);
2029 
2030 static inline void mlxsw_reg_spvmlr_pack(char *payload, u16 local_port,
2031 					 u16 vid_begin, u16 vid_end,
2032 					 bool learn_enable)
2033 {
2034 	int num_rec = vid_end - vid_begin + 1;
2035 	int i;
2036 
2037 	WARN_ON(num_rec < 1 || num_rec > MLXSW_REG_SPVMLR_REC_MAX_COUNT);
2038 
2039 	MLXSW_REG_ZERO(spvmlr, payload);
2040 	mlxsw_reg_spvmlr_local_port_set(payload, local_port);
2041 	mlxsw_reg_spvmlr_num_rec_set(payload, num_rec);
2042 
2043 	for (i = 0; i < num_rec; i++) {
2044 		mlxsw_reg_spvmlr_rec_learn_enable_set(payload, i, learn_enable);
2045 		mlxsw_reg_spvmlr_rec_vid_set(payload, i, vid_begin + i);
2046 	}
2047 }
2048 
2049 /* SPVC - Switch Port VLAN Classification Register
2050  * -----------------------------------------------
2051  * Configures the port to identify packets as untagged / single tagged /
2052  * double packets based on the packet EtherTypes.
2053  * Ethertype IDs are configured by SVER.
2054  */
2055 #define MLXSW_REG_SPVC_ID 0x2026
2056 #define MLXSW_REG_SPVC_LEN 0x0C
2057 
2058 MLXSW_REG_DEFINE(spvc, MLXSW_REG_SPVC_ID, MLXSW_REG_SPVC_LEN);
2059 
2060 /* reg_spvc_local_port
2061  * Local port.
2062  * Access: Index
2063  *
2064  * Note: applies both to Rx port and Tx port, so if a packet traverses
2065  * through Rx port i and a Tx port j then port i and port j must have the
2066  * same configuration.
2067  */
2068 MLXSW_ITEM32_LP(reg, spvc, 0x00, 16, 0x00, 12);
2069 
2070 /* reg_spvc_inner_et2
2071  * Vlan Tag1 EtherType2 enable.
2072  * Packet is initially classified as double VLAN Tag if in addition to
2073  * being classified with a tag0 VLAN Tag its tag1 EtherType value is
2074  * equal to ether_type2.
2075  * 0: disable (default)
2076  * 1: enable
2077  * Access: RW
2078  */
2079 MLXSW_ITEM32(reg, spvc, inner_et2, 0x08, 17, 1);
2080 
2081 /* reg_spvc_et2
2082  * Vlan Tag0 EtherType2 enable.
2083  * Packet is initially classified as VLAN Tag if its tag0 EtherType is
2084  * equal to ether_type2.
2085  * 0: disable (default)
2086  * 1: enable
2087  * Access: RW
2088  */
2089 MLXSW_ITEM32(reg, spvc, et2, 0x08, 16, 1);
2090 
2091 /* reg_spvc_inner_et1
2092  * Vlan Tag1 EtherType1 enable.
2093  * Packet is initially classified as double VLAN Tag if in addition to
2094  * being classified with a tag0 VLAN Tag its tag1 EtherType value is
2095  * equal to ether_type1.
2096  * 0: disable
2097  * 1: enable (default)
2098  * Access: RW
2099  */
2100 MLXSW_ITEM32(reg, spvc, inner_et1, 0x08, 9, 1);
2101 
2102 /* reg_spvc_et1
2103  * Vlan Tag0 EtherType1 enable.
2104  * Packet is initially classified as VLAN Tag if its tag0 EtherType is
2105  * equal to ether_type1.
2106  * 0: disable
2107  * 1: enable (default)
2108  * Access: RW
2109  */
2110 MLXSW_ITEM32(reg, spvc, et1, 0x08, 8, 1);
2111 
2112 /* reg_inner_et0
2113  * Vlan Tag1 EtherType0 enable.
2114  * Packet is initially classified as double VLAN Tag if in addition to
2115  * being classified with a tag0 VLAN Tag its tag1 EtherType value is
2116  * equal to ether_type0.
2117  * 0: disable
2118  * 1: enable (default)
2119  * Access: RW
2120  */
2121 MLXSW_ITEM32(reg, spvc, inner_et0, 0x08, 1, 1);
2122 
2123 /* reg_et0
2124  * Vlan Tag0 EtherType0 enable.
2125  * Packet is initially classified as VLAN Tag if its tag0 EtherType is
2126  * equal to ether_type0.
2127  * 0: disable
2128  * 1: enable (default)
2129  * Access: RW
2130  */
2131 MLXSW_ITEM32(reg, spvc, et0, 0x08, 0, 1);
2132 
2133 static inline void mlxsw_reg_spvc_pack(char *payload, u16 local_port, bool et1,
2134 				       bool et0)
2135 {
2136 	MLXSW_REG_ZERO(spvc, payload);
2137 	mlxsw_reg_spvc_local_port_set(payload, local_port);
2138 	/* Enable inner_et1 and inner_et0 to enable identification of double
2139 	 * tagged packets.
2140 	 */
2141 	mlxsw_reg_spvc_inner_et1_set(payload, 1);
2142 	mlxsw_reg_spvc_inner_et0_set(payload, 1);
2143 	mlxsw_reg_spvc_et1_set(payload, et1);
2144 	mlxsw_reg_spvc_et0_set(payload, et0);
2145 }
2146 
2147 /* SPEVET - Switch Port Egress VLAN EtherType
2148  * ------------------------------------------
2149  * The switch port egress VLAN EtherType configures which EtherType to push at
2150  * egress for packets incoming through a local port for which 'SPVID.egr_et_set'
2151  * is set.
2152  */
2153 #define MLXSW_REG_SPEVET_ID 0x202A
2154 #define MLXSW_REG_SPEVET_LEN 0x08
2155 
2156 MLXSW_REG_DEFINE(spevet, MLXSW_REG_SPEVET_ID, MLXSW_REG_SPEVET_LEN);
2157 
2158 /* reg_spevet_local_port
2159  * Egress Local port number.
2160  * Not supported to CPU port.
2161  * Access: Index
2162  */
2163 MLXSW_ITEM32_LP(reg, spevet, 0x00, 16, 0x00, 12);
2164 
2165 /* reg_spevet_et_vlan
2166  * Egress EtherType VLAN to push when SPVID.egr_et_set field set for the packet:
2167  * 0: ether_type0 - (default)
2168  * 1: ether_type1
2169  * 2: ether_type2
2170  * Access: RW
2171  */
2172 MLXSW_ITEM32(reg, spevet, et_vlan, 0x04, 16, 2);
2173 
2174 static inline void mlxsw_reg_spevet_pack(char *payload, u16 local_port,
2175 					 u8 et_vlan)
2176 {
2177 	MLXSW_REG_ZERO(spevet, payload);
2178 	mlxsw_reg_spevet_local_port_set(payload, local_port);
2179 	mlxsw_reg_spevet_et_vlan_set(payload, et_vlan);
2180 }
2181 
2182 /* SMPE - Switch Multicast Port to Egress VID
2183  * ------------------------------------------
2184  * The switch multicast port to egress VID maps
2185  * {egress_port, SMPE index} -> {VID}.
2186  */
2187 #define MLXSW_REG_SMPE_ID 0x202B
2188 #define MLXSW_REG_SMPE_LEN 0x0C
2189 
2190 MLXSW_REG_DEFINE(smpe, MLXSW_REG_SMPE_ID, MLXSW_REG_SMPE_LEN);
2191 
2192 /* reg_smpe_local_port
2193  * Local port number.
2194  * CPU port is not supported.
2195  * Access: Index
2196  */
2197 MLXSW_ITEM32_LP(reg, smpe, 0x00, 16, 0x00, 12);
2198 
2199 /* reg_smpe_smpe_index
2200  * Switch multicast port to egress VID.
2201  * Range is 0..cap_max_rmpe-1.
2202  * Access: Index
2203  */
2204 MLXSW_ITEM32(reg, smpe, smpe_index, 0x04, 0, 16);
2205 
2206 /* reg_smpe_evid
2207  * Egress VID.
2208  * Access: RW
2209  */
2210 MLXSW_ITEM32(reg, smpe, evid, 0x08, 0, 12);
2211 
2212 static inline void mlxsw_reg_smpe_pack(char *payload, u16 local_port,
2213 				       u16 smpe_index, u16 evid)
2214 {
2215 	MLXSW_REG_ZERO(smpe, payload);
2216 	mlxsw_reg_smpe_local_port_set(payload, local_port);
2217 	mlxsw_reg_smpe_smpe_index_set(payload, smpe_index);
2218 	mlxsw_reg_smpe_evid_set(payload, evid);
2219 }
2220 
2221 /* SFTR-V2 - Switch Flooding Table Version 2 Register
2222  * --------------------------------------------------
2223  * The switch flooding table is used for flooding packet replication. The table
2224  * defines a bit mask of ports for packet replication.
2225  */
2226 #define MLXSW_REG_SFTR2_ID 0x202F
2227 #define MLXSW_REG_SFTR2_LEN 0x120
2228 
2229 MLXSW_REG_DEFINE(sftr2, MLXSW_REG_SFTR2_ID, MLXSW_REG_SFTR2_LEN);
2230 
2231 /* reg_sftr2_swid
2232  * Switch partition ID with which to associate the port.
2233  * Access: Index
2234  */
2235 MLXSW_ITEM32(reg, sftr2, swid, 0x00, 24, 8);
2236 
2237 /* reg_sftr2_flood_table
2238  * Flooding table index to associate with the specific type on the specific
2239  * switch partition.
2240  * Access: Index
2241  */
2242 MLXSW_ITEM32(reg, sftr2, flood_table, 0x00, 16, 6);
2243 
2244 /* reg_sftr2_index
2245  * Index. Used as an index into the Flooding Table in case the table is
2246  * configured to use VID / FID or FID Offset.
2247  * Access: Index
2248  */
2249 MLXSW_ITEM32(reg, sftr2, index, 0x00, 0, 16);
2250 
2251 /* reg_sftr2_table_type
2252  * See mlxsw_flood_table_type
2253  * Access: RW
2254  */
2255 MLXSW_ITEM32(reg, sftr2, table_type, 0x04, 16, 3);
2256 
2257 /* reg_sftr2_range
2258  * Range of entries to update
2259  * Access: Index
2260  */
2261 MLXSW_ITEM32(reg, sftr2, range, 0x04, 0, 16);
2262 
2263 /* reg_sftr2_port
2264  * Local port membership (1 bit per port).
2265  * Access: RW
2266  */
2267 MLXSW_ITEM_BIT_ARRAY(reg, sftr2, port, 0x20, 0x80, 1);
2268 
2269 /* reg_sftr2_port_mask
2270  * Local port mask (1 bit per port).
2271  * Access: WO
2272  */
2273 MLXSW_ITEM_BIT_ARRAY(reg, sftr2, port_mask, 0xA0, 0x80, 1);
2274 
2275 static inline void mlxsw_reg_sftr2_pack(char *payload,
2276 					unsigned int flood_table,
2277 					unsigned int index,
2278 					enum mlxsw_flood_table_type table_type,
2279 					unsigned int range, u16 port, bool set)
2280 {
2281 	MLXSW_REG_ZERO(sftr2, payload);
2282 	mlxsw_reg_sftr2_swid_set(payload, 0);
2283 	mlxsw_reg_sftr2_flood_table_set(payload, flood_table);
2284 	mlxsw_reg_sftr2_index_set(payload, index);
2285 	mlxsw_reg_sftr2_table_type_set(payload, table_type);
2286 	mlxsw_reg_sftr2_range_set(payload, range);
2287 	mlxsw_reg_sftr2_port_set(payload, port, set);
2288 	mlxsw_reg_sftr2_port_mask_set(payload, port, 1);
2289 }
2290 
2291 /* SMID-V2 - Switch Multicast ID Version 2 Register
2292  * ------------------------------------------------
2293  * The MID record maps from a MID (Multicast ID), which is a unique identifier
2294  * of the multicast group within the stacking domain, into a list of local
2295  * ports into which the packet is replicated.
2296  */
2297 #define MLXSW_REG_SMID2_ID 0x2034
2298 #define MLXSW_REG_SMID2_LEN 0x120
2299 
2300 MLXSW_REG_DEFINE(smid2, MLXSW_REG_SMID2_ID, MLXSW_REG_SMID2_LEN);
2301 
2302 /* reg_smid2_swid
2303  * Switch partition ID.
2304  * Access: Index
2305  */
2306 MLXSW_ITEM32(reg, smid2, swid, 0x00, 24, 8);
2307 
2308 /* reg_smid2_mid
2309  * Multicast identifier - global identifier that represents the multicast group
2310  * across all devices.
2311  * Access: Index
2312  */
2313 MLXSW_ITEM32(reg, smid2, mid, 0x00, 0, 16);
2314 
2315 /* reg_smid2_smpe_valid
2316  * SMPE is valid.
2317  * When not valid, the egress VID will not be modified by the SMPE table.
2318  * Access: RW
2319  *
2320  * Note: Reserved when legacy bridge model is used and on Spectrum-2.
2321  */
2322 MLXSW_ITEM32(reg, smid2, smpe_valid, 0x08, 20, 1);
2323 
2324 /* reg_smid2_smpe
2325  * Switch multicast port to egress VID.
2326  * Access: RW
2327  *
2328  * Note: Reserved when legacy bridge model is used and on Spectrum-2.
2329  */
2330 MLXSW_ITEM32(reg, smid2, smpe, 0x08, 0, 16);
2331 
2332 /* reg_smid2_port
2333  * Local port memebership (1 bit per port).
2334  * Access: RW
2335  */
2336 MLXSW_ITEM_BIT_ARRAY(reg, smid2, port, 0x20, 0x80, 1);
2337 
2338 /* reg_smid2_port_mask
2339  * Local port mask (1 bit per port).
2340  * Access: WO
2341  */
2342 MLXSW_ITEM_BIT_ARRAY(reg, smid2, port_mask, 0xA0, 0x80, 1);
2343 
2344 static inline void mlxsw_reg_smid2_pack(char *payload, u16 mid, u16 port,
2345 					bool set, bool smpe_valid, u16 smpe)
2346 {
2347 	MLXSW_REG_ZERO(smid2, payload);
2348 	mlxsw_reg_smid2_swid_set(payload, 0);
2349 	mlxsw_reg_smid2_mid_set(payload, mid);
2350 	mlxsw_reg_smid2_port_set(payload, port, set);
2351 	mlxsw_reg_smid2_port_mask_set(payload, port, 1);
2352 	mlxsw_reg_smid2_smpe_valid_set(payload, smpe_valid);
2353 	mlxsw_reg_smid2_smpe_set(payload, smpe_valid ? smpe : 0);
2354 }
2355 
2356 /* CWTP - Congetion WRED ECN TClass Profile
2357  * ----------------------------------------
2358  * Configures the profiles for queues of egress port and traffic class
2359  */
2360 #define MLXSW_REG_CWTP_ID 0x2802
2361 #define MLXSW_REG_CWTP_BASE_LEN 0x28
2362 #define MLXSW_REG_CWTP_PROFILE_DATA_REC_LEN 0x08
2363 #define MLXSW_REG_CWTP_LEN 0x40
2364 
2365 MLXSW_REG_DEFINE(cwtp, MLXSW_REG_CWTP_ID, MLXSW_REG_CWTP_LEN);
2366 
2367 /* reg_cwtp_local_port
2368  * Local port number
2369  * Not supported for CPU port
2370  * Access: Index
2371  */
2372 MLXSW_ITEM32_LP(reg, cwtp, 0x00, 16, 0x00, 12);
2373 
2374 /* reg_cwtp_traffic_class
2375  * Traffic Class to configure
2376  * Access: Index
2377  */
2378 MLXSW_ITEM32(reg, cwtp, traffic_class, 32, 0, 8);
2379 
2380 /* reg_cwtp_profile_min
2381  * Minimum Average Queue Size of the profile in cells.
2382  * Access: RW
2383  */
2384 MLXSW_ITEM32_INDEXED(reg, cwtp, profile_min, MLXSW_REG_CWTP_BASE_LEN,
2385 		     0, 20, MLXSW_REG_CWTP_PROFILE_DATA_REC_LEN, 0, false);
2386 
2387 /* reg_cwtp_profile_percent
2388  * Percentage of WRED and ECN marking for maximum Average Queue size
2389  * Range is 0 to 100, units of integer percentage
2390  * Access: RW
2391  */
2392 MLXSW_ITEM32_INDEXED(reg, cwtp, profile_percent, MLXSW_REG_CWTP_BASE_LEN,
2393 		     24, 7, MLXSW_REG_CWTP_PROFILE_DATA_REC_LEN, 4, false);
2394 
2395 /* reg_cwtp_profile_max
2396  * Maximum Average Queue size of the profile in cells
2397  * Access: RW
2398  */
2399 MLXSW_ITEM32_INDEXED(reg, cwtp, profile_max, MLXSW_REG_CWTP_BASE_LEN,
2400 		     0, 20, MLXSW_REG_CWTP_PROFILE_DATA_REC_LEN, 4, false);
2401 
2402 #define MLXSW_REG_CWTP_MIN_VALUE 64
2403 #define MLXSW_REG_CWTP_MAX_PROFILE 2
2404 #define MLXSW_REG_CWTP_DEFAULT_PROFILE 1
2405 
2406 static inline void mlxsw_reg_cwtp_pack(char *payload, u16 local_port,
2407 				       u8 traffic_class)
2408 {
2409 	int i;
2410 
2411 	MLXSW_REG_ZERO(cwtp, payload);
2412 	mlxsw_reg_cwtp_local_port_set(payload, local_port);
2413 	mlxsw_reg_cwtp_traffic_class_set(payload, traffic_class);
2414 
2415 	for (i = 0; i <= MLXSW_REG_CWTP_MAX_PROFILE; i++) {
2416 		mlxsw_reg_cwtp_profile_min_set(payload, i,
2417 					       MLXSW_REG_CWTP_MIN_VALUE);
2418 		mlxsw_reg_cwtp_profile_max_set(payload, i,
2419 					       MLXSW_REG_CWTP_MIN_VALUE);
2420 	}
2421 }
2422 
2423 #define MLXSW_REG_CWTP_PROFILE_TO_INDEX(profile) (profile - 1)
2424 
2425 static inline void
2426 mlxsw_reg_cwtp_profile_pack(char *payload, u8 profile, u32 min, u32 max,
2427 			    u32 probability)
2428 {
2429 	u8 index = MLXSW_REG_CWTP_PROFILE_TO_INDEX(profile);
2430 
2431 	mlxsw_reg_cwtp_profile_min_set(payload, index, min);
2432 	mlxsw_reg_cwtp_profile_max_set(payload, index, max);
2433 	mlxsw_reg_cwtp_profile_percent_set(payload, index, probability);
2434 }
2435 
2436 /* CWTPM - Congestion WRED ECN TClass and Pool Mapping
2437  * ---------------------------------------------------
2438  * The CWTPM register maps each egress port and traffic class to profile num.
2439  */
2440 #define MLXSW_REG_CWTPM_ID 0x2803
2441 #define MLXSW_REG_CWTPM_LEN 0x44
2442 
2443 MLXSW_REG_DEFINE(cwtpm, MLXSW_REG_CWTPM_ID, MLXSW_REG_CWTPM_LEN);
2444 
2445 /* reg_cwtpm_local_port
2446  * Local port number
2447  * Not supported for CPU port
2448  * Access: Index
2449  */
2450 MLXSW_ITEM32_LP(reg, cwtpm, 0x00, 16, 0x00, 12);
2451 
2452 /* reg_cwtpm_traffic_class
2453  * Traffic Class to configure
2454  * Access: Index
2455  */
2456 MLXSW_ITEM32(reg, cwtpm, traffic_class, 32, 0, 8);
2457 
2458 /* reg_cwtpm_ew
2459  * Control enablement of WRED for traffic class:
2460  * 0 - Disable
2461  * 1 - Enable
2462  * Access: RW
2463  */
2464 MLXSW_ITEM32(reg, cwtpm, ew, 36, 1, 1);
2465 
2466 /* reg_cwtpm_ee
2467  * Control enablement of ECN for traffic class:
2468  * 0 - Disable
2469  * 1 - Enable
2470  * Access: RW
2471  */
2472 MLXSW_ITEM32(reg, cwtpm, ee, 36, 0, 1);
2473 
2474 /* reg_cwtpm_tcp_g
2475  * TCP Green Profile.
2476  * Index of the profile within {port, traffic class} to use.
2477  * 0 for disabling both WRED and ECN for this type of traffic.
2478  * Access: RW
2479  */
2480 MLXSW_ITEM32(reg, cwtpm, tcp_g, 52, 0, 2);
2481 
2482 /* reg_cwtpm_tcp_y
2483  * TCP Yellow Profile.
2484  * Index of the profile within {port, traffic class} to use.
2485  * 0 for disabling both WRED and ECN for this type of traffic.
2486  * Access: RW
2487  */
2488 MLXSW_ITEM32(reg, cwtpm, tcp_y, 56, 16, 2);
2489 
2490 /* reg_cwtpm_tcp_r
2491  * TCP Red Profile.
2492  * Index of the profile within {port, traffic class} to use.
2493  * 0 for disabling both WRED and ECN for this type of traffic.
2494  * Access: RW
2495  */
2496 MLXSW_ITEM32(reg, cwtpm, tcp_r, 56, 0, 2);
2497 
2498 /* reg_cwtpm_ntcp_g
2499  * Non-TCP Green Profile.
2500  * Index of the profile within {port, traffic class} to use.
2501  * 0 for disabling both WRED and ECN for this type of traffic.
2502  * Access: RW
2503  */
2504 MLXSW_ITEM32(reg, cwtpm, ntcp_g, 60, 0, 2);
2505 
2506 /* reg_cwtpm_ntcp_y
2507  * Non-TCP Yellow Profile.
2508  * Index of the profile within {port, traffic class} to use.
2509  * 0 for disabling both WRED and ECN for this type of traffic.
2510  * Access: RW
2511  */
2512 MLXSW_ITEM32(reg, cwtpm, ntcp_y, 64, 16, 2);
2513 
2514 /* reg_cwtpm_ntcp_r
2515  * Non-TCP Red Profile.
2516  * Index of the profile within {port, traffic class} to use.
2517  * 0 for disabling both WRED and ECN for this type of traffic.
2518  * Access: RW
2519  */
2520 MLXSW_ITEM32(reg, cwtpm, ntcp_r, 64, 0, 2);
2521 
2522 #define MLXSW_REG_CWTPM_RESET_PROFILE 0
2523 
2524 static inline void mlxsw_reg_cwtpm_pack(char *payload, u16 local_port,
2525 					u8 traffic_class, u8 profile,
2526 					bool wred, bool ecn)
2527 {
2528 	MLXSW_REG_ZERO(cwtpm, payload);
2529 	mlxsw_reg_cwtpm_local_port_set(payload, local_port);
2530 	mlxsw_reg_cwtpm_traffic_class_set(payload, traffic_class);
2531 	mlxsw_reg_cwtpm_ew_set(payload, wred);
2532 	mlxsw_reg_cwtpm_ee_set(payload, ecn);
2533 	mlxsw_reg_cwtpm_tcp_g_set(payload, profile);
2534 	mlxsw_reg_cwtpm_tcp_y_set(payload, profile);
2535 	mlxsw_reg_cwtpm_tcp_r_set(payload, profile);
2536 	mlxsw_reg_cwtpm_ntcp_g_set(payload, profile);
2537 	mlxsw_reg_cwtpm_ntcp_y_set(payload, profile);
2538 	mlxsw_reg_cwtpm_ntcp_r_set(payload, profile);
2539 }
2540 
2541 /* PGCR - Policy-Engine General Configuration Register
2542  * ---------------------------------------------------
2543  * This register configures general Policy-Engine settings.
2544  */
2545 #define MLXSW_REG_PGCR_ID 0x3001
2546 #define MLXSW_REG_PGCR_LEN 0x20
2547 
2548 MLXSW_REG_DEFINE(pgcr, MLXSW_REG_PGCR_ID, MLXSW_REG_PGCR_LEN);
2549 
2550 /* reg_pgcr_default_action_pointer_base
2551  * Default action pointer base. Each region has a default action pointer
2552  * which is equal to default_action_pointer_base + region_id.
2553  * Access: RW
2554  */
2555 MLXSW_ITEM32(reg, pgcr, default_action_pointer_base, 0x1C, 0, 24);
2556 
2557 static inline void mlxsw_reg_pgcr_pack(char *payload, u32 pointer_base)
2558 {
2559 	MLXSW_REG_ZERO(pgcr, payload);
2560 	mlxsw_reg_pgcr_default_action_pointer_base_set(payload, pointer_base);
2561 }
2562 
2563 /* PPBT - Policy-Engine Port Binding Table
2564  * ---------------------------------------
2565  * This register is used for configuration of the Port Binding Table.
2566  */
2567 #define MLXSW_REG_PPBT_ID 0x3002
2568 #define MLXSW_REG_PPBT_LEN 0x14
2569 
2570 MLXSW_REG_DEFINE(ppbt, MLXSW_REG_PPBT_ID, MLXSW_REG_PPBT_LEN);
2571 
2572 enum mlxsw_reg_pxbt_e {
2573 	MLXSW_REG_PXBT_E_IACL,
2574 	MLXSW_REG_PXBT_E_EACL,
2575 };
2576 
2577 /* reg_ppbt_e
2578  * Access: Index
2579  */
2580 MLXSW_ITEM32(reg, ppbt, e, 0x00, 31, 1);
2581 
2582 enum mlxsw_reg_pxbt_op {
2583 	MLXSW_REG_PXBT_OP_BIND,
2584 	MLXSW_REG_PXBT_OP_UNBIND,
2585 };
2586 
2587 /* reg_ppbt_op
2588  * Access: RW
2589  */
2590 MLXSW_ITEM32(reg, ppbt, op, 0x00, 28, 3);
2591 
2592 /* reg_ppbt_local_port
2593  * Local port. Not including CPU port.
2594  * Access: Index
2595  */
2596 MLXSW_ITEM32_LP(reg, ppbt, 0x00, 16, 0x00, 12);
2597 
2598 /* reg_ppbt_g
2599  * group - When set, the binding is of an ACL group. When cleared,
2600  * the binding is of an ACL.
2601  * Must be set to 1 for Spectrum.
2602  * Access: RW
2603  */
2604 MLXSW_ITEM32(reg, ppbt, g, 0x10, 31, 1);
2605 
2606 /* reg_ppbt_acl_info
2607  * ACL/ACL group identifier. If the g bit is set, this field should hold
2608  * the acl_group_id, else it should hold the acl_id.
2609  * Access: RW
2610  */
2611 MLXSW_ITEM32(reg, ppbt, acl_info, 0x10, 0, 16);
2612 
2613 static inline void mlxsw_reg_ppbt_pack(char *payload, enum mlxsw_reg_pxbt_e e,
2614 				       enum mlxsw_reg_pxbt_op op,
2615 				       u16 local_port, u16 acl_info)
2616 {
2617 	MLXSW_REG_ZERO(ppbt, payload);
2618 	mlxsw_reg_ppbt_e_set(payload, e);
2619 	mlxsw_reg_ppbt_op_set(payload, op);
2620 	mlxsw_reg_ppbt_local_port_set(payload, local_port);
2621 	mlxsw_reg_ppbt_g_set(payload, true);
2622 	mlxsw_reg_ppbt_acl_info_set(payload, acl_info);
2623 }
2624 
2625 /* PACL - Policy-Engine ACL Register
2626  * ---------------------------------
2627  * This register is used for configuration of the ACL.
2628  */
2629 #define MLXSW_REG_PACL_ID 0x3004
2630 #define MLXSW_REG_PACL_LEN 0x70
2631 
2632 MLXSW_REG_DEFINE(pacl, MLXSW_REG_PACL_ID, MLXSW_REG_PACL_LEN);
2633 
2634 /* reg_pacl_v
2635  * Valid. Setting the v bit makes the ACL valid. It should not be cleared
2636  * while the ACL is bounded to either a port, VLAN or ACL rule.
2637  * Access: RW
2638  */
2639 MLXSW_ITEM32(reg, pacl, v, 0x00, 24, 1);
2640 
2641 /* reg_pacl_acl_id
2642  * An identifier representing the ACL (managed by software)
2643  * Range 0 .. cap_max_acl_regions - 1
2644  * Access: Index
2645  */
2646 MLXSW_ITEM32(reg, pacl, acl_id, 0x08, 0, 16);
2647 
2648 #define MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN 16
2649 
2650 /* reg_pacl_tcam_region_info
2651  * Opaque object that represents a TCAM region.
2652  * Obtained through PTAR register.
2653  * Access: RW
2654  */
2655 MLXSW_ITEM_BUF(reg, pacl, tcam_region_info, 0x30,
2656 	       MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
2657 
2658 static inline void mlxsw_reg_pacl_pack(char *payload, u16 acl_id,
2659 				       bool valid, const char *tcam_region_info)
2660 {
2661 	MLXSW_REG_ZERO(pacl, payload);
2662 	mlxsw_reg_pacl_acl_id_set(payload, acl_id);
2663 	mlxsw_reg_pacl_v_set(payload, valid);
2664 	mlxsw_reg_pacl_tcam_region_info_memcpy_to(payload, tcam_region_info);
2665 }
2666 
2667 /* PAGT - Policy-Engine ACL Group Table
2668  * ------------------------------------
2669  * This register is used for configuration of the ACL Group Table.
2670  */
2671 #define MLXSW_REG_PAGT_ID 0x3005
2672 #define MLXSW_REG_PAGT_BASE_LEN 0x30
2673 #define MLXSW_REG_PAGT_ACL_LEN 4
2674 #define MLXSW_REG_PAGT_ACL_MAX_NUM 16
2675 #define MLXSW_REG_PAGT_LEN (MLXSW_REG_PAGT_BASE_LEN + \
2676 		MLXSW_REG_PAGT_ACL_MAX_NUM * MLXSW_REG_PAGT_ACL_LEN)
2677 
2678 MLXSW_REG_DEFINE(pagt, MLXSW_REG_PAGT_ID, MLXSW_REG_PAGT_LEN);
2679 
2680 /* reg_pagt_size
2681  * Number of ACLs in the group.
2682  * Size 0 invalidates a group.
2683  * Range 0 .. cap_max_acl_group_size (hard coded to 16 for now)
2684  * Total number of ACLs in all groups must be lower or equal
2685  * to cap_max_acl_tot_groups
2686  * Note: a group which is binded must not be invalidated
2687  * Access: Index
2688  */
2689 MLXSW_ITEM32(reg, pagt, size, 0x00, 0, 8);
2690 
2691 /* reg_pagt_acl_group_id
2692  * An identifier (numbered from 0..cap_max_acl_groups-1) representing
2693  * the ACL Group identifier (managed by software).
2694  * Access: Index
2695  */
2696 MLXSW_ITEM32(reg, pagt, acl_group_id, 0x08, 0, 16);
2697 
2698 /* reg_pagt_multi
2699  * Multi-ACL
2700  * 0 - This ACL is the last ACL in the multi-ACL
2701  * 1 - This ACL is part of a multi-ACL
2702  * Access: RW
2703  */
2704 MLXSW_ITEM32_INDEXED(reg, pagt, multi, 0x30, 31, 1, 0x04, 0x00, false);
2705 
2706 /* reg_pagt_acl_id
2707  * ACL identifier
2708  * Access: RW
2709  */
2710 MLXSW_ITEM32_INDEXED(reg, pagt, acl_id, 0x30, 0, 16, 0x04, 0x00, false);
2711 
2712 static inline void mlxsw_reg_pagt_pack(char *payload, u16 acl_group_id)
2713 {
2714 	MLXSW_REG_ZERO(pagt, payload);
2715 	mlxsw_reg_pagt_acl_group_id_set(payload, acl_group_id);
2716 }
2717 
2718 static inline void mlxsw_reg_pagt_acl_id_pack(char *payload, int index,
2719 					      u16 acl_id, bool multi)
2720 {
2721 	u8 size = mlxsw_reg_pagt_size_get(payload);
2722 
2723 	if (index >= size)
2724 		mlxsw_reg_pagt_size_set(payload, index + 1);
2725 	mlxsw_reg_pagt_multi_set(payload, index, multi);
2726 	mlxsw_reg_pagt_acl_id_set(payload, index, acl_id);
2727 }
2728 
2729 /* PTAR - Policy-Engine TCAM Allocation Register
2730  * ---------------------------------------------
2731  * This register is used for allocation of regions in the TCAM.
2732  * Note: Query method is not supported on this register.
2733  */
2734 #define MLXSW_REG_PTAR_ID 0x3006
2735 #define MLXSW_REG_PTAR_BASE_LEN 0x20
2736 #define MLXSW_REG_PTAR_KEY_ID_LEN 1
2737 #define MLXSW_REG_PTAR_KEY_ID_MAX_NUM 16
2738 #define MLXSW_REG_PTAR_LEN (MLXSW_REG_PTAR_BASE_LEN + \
2739 		MLXSW_REG_PTAR_KEY_ID_MAX_NUM * MLXSW_REG_PTAR_KEY_ID_LEN)
2740 
2741 MLXSW_REG_DEFINE(ptar, MLXSW_REG_PTAR_ID, MLXSW_REG_PTAR_LEN);
2742 
2743 enum mlxsw_reg_ptar_op {
2744 	/* allocate a TCAM region */
2745 	MLXSW_REG_PTAR_OP_ALLOC,
2746 	/* resize a TCAM region */
2747 	MLXSW_REG_PTAR_OP_RESIZE,
2748 	/* deallocate TCAM region */
2749 	MLXSW_REG_PTAR_OP_FREE,
2750 	/* test allocation */
2751 	MLXSW_REG_PTAR_OP_TEST,
2752 };
2753 
2754 /* reg_ptar_op
2755  * Access: OP
2756  */
2757 MLXSW_ITEM32(reg, ptar, op, 0x00, 28, 4);
2758 
2759 /* reg_ptar_action_set_type
2760  * Type of action set to be used on this region.
2761  * For Spectrum and Spectrum-2, this is always type 2 - "flexible"
2762  * Access: WO
2763  */
2764 MLXSW_ITEM32(reg, ptar, action_set_type, 0x00, 16, 8);
2765 
2766 enum mlxsw_reg_ptar_key_type {
2767 	MLXSW_REG_PTAR_KEY_TYPE_FLEX = 0x50, /* Spetrum */
2768 	MLXSW_REG_PTAR_KEY_TYPE_FLEX2 = 0x51, /* Spectrum-2 */
2769 };
2770 
2771 /* reg_ptar_key_type
2772  * TCAM key type for the region.
2773  * Access: WO
2774  */
2775 MLXSW_ITEM32(reg, ptar, key_type, 0x00, 0, 8);
2776 
2777 /* reg_ptar_region_size
2778  * TCAM region size. When allocating/resizing this is the requested size,
2779  * the response is the actual size. Note that actual size may be
2780  * larger than requested.
2781  * Allowed range 1 .. cap_max_rules-1
2782  * Reserved during op deallocate.
2783  * Access: WO
2784  */
2785 MLXSW_ITEM32(reg, ptar, region_size, 0x04, 0, 16);
2786 
2787 /* reg_ptar_region_id
2788  * Region identifier
2789  * Range 0 .. cap_max_regions-1
2790  * Access: Index
2791  */
2792 MLXSW_ITEM32(reg, ptar, region_id, 0x08, 0, 16);
2793 
2794 /* reg_ptar_tcam_region_info
2795  * Opaque object that represents the TCAM region.
2796  * Returned when allocating a region.
2797  * Provided by software for ACL generation and region deallocation and resize.
2798  * Access: RW
2799  */
2800 MLXSW_ITEM_BUF(reg, ptar, tcam_region_info, 0x10,
2801 	       MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
2802 
2803 /* reg_ptar_flexible_key_id
2804  * Identifier of the Flexible Key.
2805  * Only valid if key_type == "FLEX_KEY"
2806  * The key size will be rounded up to one of the following values:
2807  * 9B, 18B, 36B, 54B.
2808  * This field is reserved for in resize operation.
2809  * Access: WO
2810  */
2811 MLXSW_ITEM8_INDEXED(reg, ptar, flexible_key_id, 0x20, 0, 8,
2812 		    MLXSW_REG_PTAR_KEY_ID_LEN, 0x00, false);
2813 
2814 static inline void mlxsw_reg_ptar_pack(char *payload, enum mlxsw_reg_ptar_op op,
2815 				       enum mlxsw_reg_ptar_key_type key_type,
2816 				       u16 region_size, u16 region_id,
2817 				       const char *tcam_region_info)
2818 {
2819 	MLXSW_REG_ZERO(ptar, payload);
2820 	mlxsw_reg_ptar_op_set(payload, op);
2821 	mlxsw_reg_ptar_action_set_type_set(payload, 2); /* "flexible" */
2822 	mlxsw_reg_ptar_key_type_set(payload, key_type);
2823 	mlxsw_reg_ptar_region_size_set(payload, region_size);
2824 	mlxsw_reg_ptar_region_id_set(payload, region_id);
2825 	mlxsw_reg_ptar_tcam_region_info_memcpy_to(payload, tcam_region_info);
2826 }
2827 
2828 static inline void mlxsw_reg_ptar_key_id_pack(char *payload, int index,
2829 					      u16 key_id)
2830 {
2831 	mlxsw_reg_ptar_flexible_key_id_set(payload, index, key_id);
2832 }
2833 
2834 static inline void mlxsw_reg_ptar_unpack(char *payload, char *tcam_region_info)
2835 {
2836 	mlxsw_reg_ptar_tcam_region_info_memcpy_from(payload, tcam_region_info);
2837 }
2838 
2839 /* PPBS - Policy-Engine Policy Based Switching Register
2840  * ----------------------------------------------------
2841  * This register retrieves and sets Policy Based Switching Table entries.
2842  */
2843 #define MLXSW_REG_PPBS_ID 0x300C
2844 #define MLXSW_REG_PPBS_LEN 0x14
2845 
2846 MLXSW_REG_DEFINE(ppbs, MLXSW_REG_PPBS_ID, MLXSW_REG_PPBS_LEN);
2847 
2848 /* reg_ppbs_pbs_ptr
2849  * Index into the PBS table.
2850  * For Spectrum, the index points to the KVD Linear.
2851  * Access: Index
2852  */
2853 MLXSW_ITEM32(reg, ppbs, pbs_ptr, 0x08, 0, 24);
2854 
2855 /* reg_ppbs_system_port
2856  * Unique port identifier for the final destination of the packet.
2857  * Access: RW
2858  */
2859 MLXSW_ITEM32(reg, ppbs, system_port, 0x10, 0, 16);
2860 
2861 static inline void mlxsw_reg_ppbs_pack(char *payload, u32 pbs_ptr,
2862 				       u16 system_port)
2863 {
2864 	MLXSW_REG_ZERO(ppbs, payload);
2865 	mlxsw_reg_ppbs_pbs_ptr_set(payload, pbs_ptr);
2866 	mlxsw_reg_ppbs_system_port_set(payload, system_port);
2867 }
2868 
2869 /* PRCR - Policy-Engine Rules Copy Register
2870  * ----------------------------------------
2871  * This register is used for accessing rules within a TCAM region.
2872  */
2873 #define MLXSW_REG_PRCR_ID 0x300D
2874 #define MLXSW_REG_PRCR_LEN 0x40
2875 
2876 MLXSW_REG_DEFINE(prcr, MLXSW_REG_PRCR_ID, MLXSW_REG_PRCR_LEN);
2877 
2878 enum mlxsw_reg_prcr_op {
2879 	/* Move rules. Moves the rules from "tcam_region_info" starting
2880 	 * at offset "offset" to "dest_tcam_region_info"
2881 	 * at offset "dest_offset."
2882 	 */
2883 	MLXSW_REG_PRCR_OP_MOVE,
2884 	/* Copy rules. Copies the rules from "tcam_region_info" starting
2885 	 * at offset "offset" to "dest_tcam_region_info"
2886 	 * at offset "dest_offset."
2887 	 */
2888 	MLXSW_REG_PRCR_OP_COPY,
2889 };
2890 
2891 /* reg_prcr_op
2892  * Access: OP
2893  */
2894 MLXSW_ITEM32(reg, prcr, op, 0x00, 28, 4);
2895 
2896 /* reg_prcr_offset
2897  * Offset within the source region to copy/move from.
2898  * Access: Index
2899  */
2900 MLXSW_ITEM32(reg, prcr, offset, 0x00, 0, 16);
2901 
2902 /* reg_prcr_size
2903  * The number of rules to copy/move.
2904  * Access: WO
2905  */
2906 MLXSW_ITEM32(reg, prcr, size, 0x04, 0, 16);
2907 
2908 /* reg_prcr_tcam_region_info
2909  * Opaque object that represents the source TCAM region.
2910  * Access: Index
2911  */
2912 MLXSW_ITEM_BUF(reg, prcr, tcam_region_info, 0x10,
2913 	       MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
2914 
2915 /* reg_prcr_dest_offset
2916  * Offset within the source region to copy/move to.
2917  * Access: Index
2918  */
2919 MLXSW_ITEM32(reg, prcr, dest_offset, 0x20, 0, 16);
2920 
2921 /* reg_prcr_dest_tcam_region_info
2922  * Opaque object that represents the destination TCAM region.
2923  * Access: Index
2924  */
2925 MLXSW_ITEM_BUF(reg, prcr, dest_tcam_region_info, 0x30,
2926 	       MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
2927 
2928 static inline void mlxsw_reg_prcr_pack(char *payload, enum mlxsw_reg_prcr_op op,
2929 				       const char *src_tcam_region_info,
2930 				       u16 src_offset,
2931 				       const char *dest_tcam_region_info,
2932 				       u16 dest_offset, u16 size)
2933 {
2934 	MLXSW_REG_ZERO(prcr, payload);
2935 	mlxsw_reg_prcr_op_set(payload, op);
2936 	mlxsw_reg_prcr_offset_set(payload, src_offset);
2937 	mlxsw_reg_prcr_size_set(payload, size);
2938 	mlxsw_reg_prcr_tcam_region_info_memcpy_to(payload,
2939 						  src_tcam_region_info);
2940 	mlxsw_reg_prcr_dest_offset_set(payload, dest_offset);
2941 	mlxsw_reg_prcr_dest_tcam_region_info_memcpy_to(payload,
2942 						       dest_tcam_region_info);
2943 }
2944 
2945 /* PEFA - Policy-Engine Extended Flexible Action Register
2946  * ------------------------------------------------------
2947  * This register is used for accessing an extended flexible action entry
2948  * in the central KVD Linear Database.
2949  */
2950 #define MLXSW_REG_PEFA_ID 0x300F
2951 #define MLXSW_REG_PEFA_LEN 0xB0
2952 
2953 MLXSW_REG_DEFINE(pefa, MLXSW_REG_PEFA_ID, MLXSW_REG_PEFA_LEN);
2954 
2955 /* reg_pefa_index
2956  * Index in the KVD Linear Centralized Database.
2957  * Access: Index
2958  */
2959 MLXSW_ITEM32(reg, pefa, index, 0x00, 0, 24);
2960 
2961 /* reg_pefa_a
2962  * Index in the KVD Linear Centralized Database.
2963  * Activity
2964  * For a new entry: set if ca=0, clear if ca=1
2965  * Set if a packet lookup has hit on the specific entry
2966  * Access: RO
2967  */
2968 MLXSW_ITEM32(reg, pefa, a, 0x04, 29, 1);
2969 
2970 /* reg_pefa_ca
2971  * Clear activity
2972  * When write: activity is according to this field
2973  * When read: after reading the activity is cleared according to ca
2974  * Access: OP
2975  */
2976 MLXSW_ITEM32(reg, pefa, ca, 0x04, 24, 1);
2977 
2978 #define MLXSW_REG_FLEX_ACTION_SET_LEN 0xA8
2979 
2980 /* reg_pefa_flex_action_set
2981  * Action-set to perform when rule is matched.
2982  * Must be zero padded if action set is shorter.
2983  * Access: RW
2984  */
2985 MLXSW_ITEM_BUF(reg, pefa, flex_action_set, 0x08, MLXSW_REG_FLEX_ACTION_SET_LEN);
2986 
2987 static inline void mlxsw_reg_pefa_pack(char *payload, u32 index, bool ca,
2988 				       const char *flex_action_set)
2989 {
2990 	MLXSW_REG_ZERO(pefa, payload);
2991 	mlxsw_reg_pefa_index_set(payload, index);
2992 	mlxsw_reg_pefa_ca_set(payload, ca);
2993 	if (flex_action_set)
2994 		mlxsw_reg_pefa_flex_action_set_memcpy_to(payload,
2995 							 flex_action_set);
2996 }
2997 
2998 static inline void mlxsw_reg_pefa_unpack(char *payload, bool *p_a)
2999 {
3000 	*p_a = mlxsw_reg_pefa_a_get(payload);
3001 }
3002 
3003 /* PEMRBT - Policy-Engine Multicast Router Binding Table Register
3004  * --------------------------------------------------------------
3005  * This register is used for binding Multicast router to an ACL group
3006  * that serves the MC router.
3007  * This register is not supported by SwitchX/-2 and Spectrum.
3008  */
3009 #define MLXSW_REG_PEMRBT_ID 0x3014
3010 #define MLXSW_REG_PEMRBT_LEN 0x14
3011 
3012 MLXSW_REG_DEFINE(pemrbt, MLXSW_REG_PEMRBT_ID, MLXSW_REG_PEMRBT_LEN);
3013 
3014 enum mlxsw_reg_pemrbt_protocol {
3015 	MLXSW_REG_PEMRBT_PROTO_IPV4,
3016 	MLXSW_REG_PEMRBT_PROTO_IPV6,
3017 };
3018 
3019 /* reg_pemrbt_protocol
3020  * Access: Index
3021  */
3022 MLXSW_ITEM32(reg, pemrbt, protocol, 0x00, 0, 1);
3023 
3024 /* reg_pemrbt_group_id
3025  * ACL group identifier.
3026  * Range 0..cap_max_acl_groups-1
3027  * Access: RW
3028  */
3029 MLXSW_ITEM32(reg, pemrbt, group_id, 0x10, 0, 16);
3030 
3031 static inline void
3032 mlxsw_reg_pemrbt_pack(char *payload, enum mlxsw_reg_pemrbt_protocol protocol,
3033 		      u16 group_id)
3034 {
3035 	MLXSW_REG_ZERO(pemrbt, payload);
3036 	mlxsw_reg_pemrbt_protocol_set(payload, protocol);
3037 	mlxsw_reg_pemrbt_group_id_set(payload, group_id);
3038 }
3039 
3040 /* PTCE-V2 - Policy-Engine TCAM Entry Register Version 2
3041  * -----------------------------------------------------
3042  * This register is used for accessing rules within a TCAM region.
3043  * It is a new version of PTCE in order to support wider key,
3044  * mask and action within a TCAM region. This register is not supported
3045  * by SwitchX and SwitchX-2.
3046  */
3047 #define MLXSW_REG_PTCE2_ID 0x3017
3048 #define MLXSW_REG_PTCE2_LEN 0x1D8
3049 
3050 MLXSW_REG_DEFINE(ptce2, MLXSW_REG_PTCE2_ID, MLXSW_REG_PTCE2_LEN);
3051 
3052 /* reg_ptce2_v
3053  * Valid.
3054  * Access: RW
3055  */
3056 MLXSW_ITEM32(reg, ptce2, v, 0x00, 31, 1);
3057 
3058 /* reg_ptce2_a
3059  * Activity. Set if a packet lookup has hit on the specific entry.
3060  * To clear the "a" bit, use "clear activity" op or "clear on read" op.
3061  * Access: RO
3062  */
3063 MLXSW_ITEM32(reg, ptce2, a, 0x00, 30, 1);
3064 
3065 enum mlxsw_reg_ptce2_op {
3066 	/* Read operation. */
3067 	MLXSW_REG_PTCE2_OP_QUERY_READ = 0,
3068 	/* clear on read operation. Used to read entry
3069 	 * and clear Activity bit.
3070 	 */
3071 	MLXSW_REG_PTCE2_OP_QUERY_CLEAR_ON_READ = 1,
3072 	/* Write operation. Used to write a new entry to the table.
3073 	 * All R/W fields are relevant for new entry. Activity bit is set
3074 	 * for new entries - Note write with v = 0 will delete the entry.
3075 	 */
3076 	MLXSW_REG_PTCE2_OP_WRITE_WRITE = 0,
3077 	/* Update action. Only action set will be updated. */
3078 	MLXSW_REG_PTCE2_OP_WRITE_UPDATE = 1,
3079 	/* Clear activity. A bit is cleared for the entry. */
3080 	MLXSW_REG_PTCE2_OP_WRITE_CLEAR_ACTIVITY = 2,
3081 };
3082 
3083 /* reg_ptce2_op
3084  * Access: OP
3085  */
3086 MLXSW_ITEM32(reg, ptce2, op, 0x00, 20, 3);
3087 
3088 /* reg_ptce2_offset
3089  * Access: Index
3090  */
3091 MLXSW_ITEM32(reg, ptce2, offset, 0x00, 0, 16);
3092 
3093 /* reg_ptce2_priority
3094  * Priority of the rule, higher values win. The range is 1..cap_kvd_size-1.
3095  * Note: priority does not have to be unique per rule.
3096  * Within a region, higher priority should have lower offset (no limitation
3097  * between regions in a multi-region).
3098  * Access: RW
3099  */
3100 MLXSW_ITEM32(reg, ptce2, priority, 0x04, 0, 24);
3101 
3102 /* reg_ptce2_tcam_region_info
3103  * Opaque object that represents the TCAM region.
3104  * Access: Index
3105  */
3106 MLXSW_ITEM_BUF(reg, ptce2, tcam_region_info, 0x10,
3107 	       MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
3108 
3109 #define MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN 96
3110 
3111 /* reg_ptce2_flex_key_blocks
3112  * ACL Key.
3113  * Access: RW
3114  */
3115 MLXSW_ITEM_BUF(reg, ptce2, flex_key_blocks, 0x20,
3116 	       MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN);
3117 
3118 /* reg_ptce2_mask
3119  * mask- in the same size as key. A bit that is set directs the TCAM
3120  * to compare the corresponding bit in key. A bit that is clear directs
3121  * the TCAM to ignore the corresponding bit in key.
3122  * Access: RW
3123  */
3124 MLXSW_ITEM_BUF(reg, ptce2, mask, 0x80,
3125 	       MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN);
3126 
3127 /* reg_ptce2_flex_action_set
3128  * ACL action set.
3129  * Access: RW
3130  */
3131 MLXSW_ITEM_BUF(reg, ptce2, flex_action_set, 0xE0,
3132 	       MLXSW_REG_FLEX_ACTION_SET_LEN);
3133 
3134 static inline void mlxsw_reg_ptce2_pack(char *payload, bool valid,
3135 					enum mlxsw_reg_ptce2_op op,
3136 					const char *tcam_region_info,
3137 					u16 offset, u32 priority)
3138 {
3139 	MLXSW_REG_ZERO(ptce2, payload);
3140 	mlxsw_reg_ptce2_v_set(payload, valid);
3141 	mlxsw_reg_ptce2_op_set(payload, op);
3142 	mlxsw_reg_ptce2_offset_set(payload, offset);
3143 	mlxsw_reg_ptce2_priority_set(payload, priority);
3144 	mlxsw_reg_ptce2_tcam_region_info_memcpy_to(payload, tcam_region_info);
3145 }
3146 
3147 /* PERPT - Policy-Engine ERP Table Register
3148  * ----------------------------------------
3149  * This register adds and removes eRPs from the eRP table.
3150  */
3151 #define MLXSW_REG_PERPT_ID 0x3021
3152 #define MLXSW_REG_PERPT_LEN 0x80
3153 
3154 MLXSW_REG_DEFINE(perpt, MLXSW_REG_PERPT_ID, MLXSW_REG_PERPT_LEN);
3155 
3156 /* reg_perpt_erpt_bank
3157  * eRP table bank.
3158  * Range 0 .. cap_max_erp_table_banks - 1
3159  * Access: Index
3160  */
3161 MLXSW_ITEM32(reg, perpt, erpt_bank, 0x00, 16, 4);
3162 
3163 /* reg_perpt_erpt_index
3164  * Index to eRP table within the eRP bank.
3165  * Range is 0 .. cap_max_erp_table_bank_size - 1
3166  * Access: Index
3167  */
3168 MLXSW_ITEM32(reg, perpt, erpt_index, 0x00, 0, 8);
3169 
3170 enum mlxsw_reg_perpt_key_size {
3171 	MLXSW_REG_PERPT_KEY_SIZE_2KB,
3172 	MLXSW_REG_PERPT_KEY_SIZE_4KB,
3173 	MLXSW_REG_PERPT_KEY_SIZE_8KB,
3174 	MLXSW_REG_PERPT_KEY_SIZE_12KB,
3175 };
3176 
3177 /* reg_perpt_key_size
3178  * Access: OP
3179  */
3180 MLXSW_ITEM32(reg, perpt, key_size, 0x04, 0, 4);
3181 
3182 /* reg_perpt_bf_bypass
3183  * 0 - The eRP is used only if bloom filter state is set for the given
3184  * rule.
3185  * 1 - The eRP is used regardless of bloom filter state.
3186  * The bypass is an OR condition of region_id or eRP. See PERCR.bf_bypass
3187  * Access: RW
3188  */
3189 MLXSW_ITEM32(reg, perpt, bf_bypass, 0x08, 8, 1);
3190 
3191 /* reg_perpt_erp_id
3192  * eRP ID for use by the rules.
3193  * Access: RW
3194  */
3195 MLXSW_ITEM32(reg, perpt, erp_id, 0x08, 0, 4);
3196 
3197 /* reg_perpt_erpt_base_bank
3198  * Base eRP table bank, points to head of erp_vector
3199  * Range is 0 .. cap_max_erp_table_banks - 1
3200  * Access: OP
3201  */
3202 MLXSW_ITEM32(reg, perpt, erpt_base_bank, 0x0C, 16, 4);
3203 
3204 /* reg_perpt_erpt_base_index
3205  * Base index to eRP table within the eRP bank
3206  * Range is 0 .. cap_max_erp_table_bank_size - 1
3207  * Access: OP
3208  */
3209 MLXSW_ITEM32(reg, perpt, erpt_base_index, 0x0C, 0, 8);
3210 
3211 /* reg_perpt_erp_index_in_vector
3212  * eRP index in the vector.
3213  * Access: OP
3214  */
3215 MLXSW_ITEM32(reg, perpt, erp_index_in_vector, 0x10, 0, 4);
3216 
3217 /* reg_perpt_erp_vector
3218  * eRP vector.
3219  * Access: OP
3220  */
3221 MLXSW_ITEM_BIT_ARRAY(reg, perpt, erp_vector, 0x14, 4, 1);
3222 
3223 /* reg_perpt_mask
3224  * Mask
3225  * 0 - A-TCAM will ignore the bit in key
3226  * 1 - A-TCAM will compare the bit in key
3227  * Access: RW
3228  */
3229 MLXSW_ITEM_BUF(reg, perpt, mask, 0x20, MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN);
3230 
3231 static inline void mlxsw_reg_perpt_erp_vector_pack(char *payload,
3232 						   unsigned long *erp_vector,
3233 						   unsigned long size)
3234 {
3235 	unsigned long bit;
3236 
3237 	for_each_set_bit(bit, erp_vector, size)
3238 		mlxsw_reg_perpt_erp_vector_set(payload, bit, true);
3239 }
3240 
3241 static inline void
3242 mlxsw_reg_perpt_pack(char *payload, u8 erpt_bank, u8 erpt_index,
3243 		     enum mlxsw_reg_perpt_key_size key_size, u8 erp_id,
3244 		     u8 erpt_base_bank, u8 erpt_base_index, u8 erp_index,
3245 		     char *mask)
3246 {
3247 	MLXSW_REG_ZERO(perpt, payload);
3248 	mlxsw_reg_perpt_erpt_bank_set(payload, erpt_bank);
3249 	mlxsw_reg_perpt_erpt_index_set(payload, erpt_index);
3250 	mlxsw_reg_perpt_key_size_set(payload, key_size);
3251 	mlxsw_reg_perpt_bf_bypass_set(payload, false);
3252 	mlxsw_reg_perpt_erp_id_set(payload, erp_id);
3253 	mlxsw_reg_perpt_erpt_base_bank_set(payload, erpt_base_bank);
3254 	mlxsw_reg_perpt_erpt_base_index_set(payload, erpt_base_index);
3255 	mlxsw_reg_perpt_erp_index_in_vector_set(payload, erp_index);
3256 	mlxsw_reg_perpt_mask_memcpy_to(payload, mask);
3257 }
3258 
3259 /* PERAR - Policy-Engine Region Association Register
3260  * -------------------------------------------------
3261  * This register associates a hw region for region_id's. Changing on the fly
3262  * is supported by the device.
3263  */
3264 #define MLXSW_REG_PERAR_ID 0x3026
3265 #define MLXSW_REG_PERAR_LEN 0x08
3266 
3267 MLXSW_REG_DEFINE(perar, MLXSW_REG_PERAR_ID, MLXSW_REG_PERAR_LEN);
3268 
3269 /* reg_perar_region_id
3270  * Region identifier
3271  * Range 0 .. cap_max_regions-1
3272  * Access: Index
3273  */
3274 MLXSW_ITEM32(reg, perar, region_id, 0x00, 0, 16);
3275 
3276 static inline unsigned int
3277 mlxsw_reg_perar_hw_regions_needed(unsigned int block_num)
3278 {
3279 	return DIV_ROUND_UP(block_num, 4);
3280 }
3281 
3282 /* reg_perar_hw_region
3283  * HW Region
3284  * Range 0 .. cap_max_regions-1
3285  * Default: hw_region = region_id
3286  * For a 8 key block region, 2 consecutive regions are used
3287  * For a 12 key block region, 3 consecutive regions are used
3288  * Access: RW
3289  */
3290 MLXSW_ITEM32(reg, perar, hw_region, 0x04, 0, 16);
3291 
3292 static inline void mlxsw_reg_perar_pack(char *payload, u16 region_id,
3293 					u16 hw_region)
3294 {
3295 	MLXSW_REG_ZERO(perar, payload);
3296 	mlxsw_reg_perar_region_id_set(payload, region_id);
3297 	mlxsw_reg_perar_hw_region_set(payload, hw_region);
3298 }
3299 
3300 /* PTCE-V3 - Policy-Engine TCAM Entry Register Version 3
3301  * -----------------------------------------------------
3302  * This register is a new version of PTCE-V2 in order to support the
3303  * A-TCAM. This register is not supported by SwitchX/-2 and Spectrum.
3304  */
3305 #define MLXSW_REG_PTCE3_ID 0x3027
3306 #define MLXSW_REG_PTCE3_LEN 0xF0
3307 
3308 MLXSW_REG_DEFINE(ptce3, MLXSW_REG_PTCE3_ID, MLXSW_REG_PTCE3_LEN);
3309 
3310 /* reg_ptce3_v
3311  * Valid.
3312  * Access: RW
3313  */
3314 MLXSW_ITEM32(reg, ptce3, v, 0x00, 31, 1);
3315 
3316 enum mlxsw_reg_ptce3_op {
3317 	/* Write operation. Used to write a new entry to the table.
3318 	 * All R/W fields are relevant for new entry. Activity bit is set
3319 	 * for new entries. Write with v = 0 will delete the entry. Must
3320 	 * not be used if an entry exists.
3321 	 */
3322 	 MLXSW_REG_PTCE3_OP_WRITE_WRITE = 0,
3323 	 /* Update operation */
3324 	 MLXSW_REG_PTCE3_OP_WRITE_UPDATE = 1,
3325 	 /* Read operation */
3326 	 MLXSW_REG_PTCE3_OP_QUERY_READ = 0,
3327 };
3328 
3329 /* reg_ptce3_op
3330  * Access: OP
3331  */
3332 MLXSW_ITEM32(reg, ptce3, op, 0x00, 20, 3);
3333 
3334 /* reg_ptce3_priority
3335  * Priority of the rule. Higher values win.
3336  * For Spectrum-2 range is 1..cap_kvd_size - 1
3337  * Note: Priority does not have to be unique per rule.
3338  * Access: RW
3339  */
3340 MLXSW_ITEM32(reg, ptce3, priority, 0x04, 0, 24);
3341 
3342 /* reg_ptce3_tcam_region_info
3343  * Opaque object that represents the TCAM region.
3344  * Access: Index
3345  */
3346 MLXSW_ITEM_BUF(reg, ptce3, tcam_region_info, 0x10,
3347 	       MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
3348 
3349 /* reg_ptce3_flex2_key_blocks
3350  * ACL key. The key must be masked according to eRP (if exists) or
3351  * according to master mask.
3352  * Access: Index
3353  */
3354 MLXSW_ITEM_BUF(reg, ptce3, flex2_key_blocks, 0x20,
3355 	       MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN);
3356 
3357 /* reg_ptce3_erp_id
3358  * eRP ID.
3359  * Access: Index
3360  */
3361 MLXSW_ITEM32(reg, ptce3, erp_id, 0x80, 0, 4);
3362 
3363 /* reg_ptce3_delta_start
3364  * Start point of delta_value and delta_mask, in bits. Must not exceed
3365  * num_key_blocks * 36 - 8. Reserved when delta_mask = 0.
3366  * Access: Index
3367  */
3368 MLXSW_ITEM32(reg, ptce3, delta_start, 0x84, 0, 10);
3369 
3370 /* reg_ptce3_delta_mask
3371  * Delta mask.
3372  * 0 - Ignore relevant bit in delta_value
3373  * 1 - Compare relevant bit in delta_value
3374  * Delta mask must not be set for reserved fields in the key blocks.
3375  * Note: No delta when no eRPs. Thus, for regions with
3376  * PERERP.erpt_pointer_valid = 0 the delta mask must be 0.
3377  * Access: Index
3378  */
3379 MLXSW_ITEM32(reg, ptce3, delta_mask, 0x88, 16, 8);
3380 
3381 /* reg_ptce3_delta_value
3382  * Delta value.
3383  * Bits which are masked by delta_mask must be 0.
3384  * Access: Index
3385  */
3386 MLXSW_ITEM32(reg, ptce3, delta_value, 0x88, 0, 8);
3387 
3388 /* reg_ptce3_prune_vector
3389  * Pruning vector relative to the PERPT.erp_id.
3390  * Used for reducing lookups.
3391  * 0 - NEED: Do a lookup using the eRP.
3392  * 1 - PRUNE: Do not perform a lookup using the eRP.
3393  * Maybe be modified by PEAPBL and PEAPBM.
3394  * Note: In Spectrum-2, a region of 8 key blocks must be set to either
3395  * all 1's or all 0's.
3396  * Access: RW
3397  */
3398 MLXSW_ITEM_BIT_ARRAY(reg, ptce3, prune_vector, 0x90, 4, 1);
3399 
3400 /* reg_ptce3_prune_ctcam
3401  * Pruning on C-TCAM. Used for reducing lookups.
3402  * 0 - NEED: Do a lookup in the C-TCAM.
3403  * 1 - PRUNE: Do not perform a lookup in the C-TCAM.
3404  * Access: RW
3405  */
3406 MLXSW_ITEM32(reg, ptce3, prune_ctcam, 0x94, 31, 1);
3407 
3408 /* reg_ptce3_large_exists
3409  * Large entry key ID exists.
3410  * Within the region:
3411  * 0 - SINGLE: The large_entry_key_id is not currently in use.
3412  * For rule insert: The MSB of the key (blocks 6..11) will be added.
3413  * For rule delete: The MSB of the key will be removed.
3414  * 1 - NON_SINGLE: The large_entry_key_id is currently in use.
3415  * For rule insert: The MSB of the key (blocks 6..11) will not be added.
3416  * For rule delete: The MSB of the key will not be removed.
3417  * Access: WO
3418  */
3419 MLXSW_ITEM32(reg, ptce3, large_exists, 0x98, 31, 1);
3420 
3421 /* reg_ptce3_large_entry_key_id
3422  * Large entry key ID.
3423  * A key for 12 key blocks rules. Reserved when region has less than 12 key
3424  * blocks. Must be different for different keys which have the same common
3425  * 6 key blocks (MSB, blocks 6..11) key within a region.
3426  * Range is 0..cap_max_pe_large_key_id - 1
3427  * Access: RW
3428  */
3429 MLXSW_ITEM32(reg, ptce3, large_entry_key_id, 0x98, 0, 24);
3430 
3431 /* reg_ptce3_action_pointer
3432  * Pointer to action.
3433  * Range is 0..cap_max_kvd_action_sets - 1
3434  * Access: RW
3435  */
3436 MLXSW_ITEM32(reg, ptce3, action_pointer, 0xA0, 0, 24);
3437 
3438 static inline void mlxsw_reg_ptce3_pack(char *payload, bool valid,
3439 					enum mlxsw_reg_ptce3_op op,
3440 					u32 priority,
3441 					const char *tcam_region_info,
3442 					const char *key, u8 erp_id,
3443 					u16 delta_start, u8 delta_mask,
3444 					u8 delta_value, bool large_exists,
3445 					u32 lkey_id, u32 action_pointer)
3446 {
3447 	MLXSW_REG_ZERO(ptce3, payload);
3448 	mlxsw_reg_ptce3_v_set(payload, valid);
3449 	mlxsw_reg_ptce3_op_set(payload, op);
3450 	mlxsw_reg_ptce3_priority_set(payload, priority);
3451 	mlxsw_reg_ptce3_tcam_region_info_memcpy_to(payload, tcam_region_info);
3452 	mlxsw_reg_ptce3_flex2_key_blocks_memcpy_to(payload, key);
3453 	mlxsw_reg_ptce3_erp_id_set(payload, erp_id);
3454 	mlxsw_reg_ptce3_delta_start_set(payload, delta_start);
3455 	mlxsw_reg_ptce3_delta_mask_set(payload, delta_mask);
3456 	mlxsw_reg_ptce3_delta_value_set(payload, delta_value);
3457 	mlxsw_reg_ptce3_large_exists_set(payload, large_exists);
3458 	mlxsw_reg_ptce3_large_entry_key_id_set(payload, lkey_id);
3459 	mlxsw_reg_ptce3_action_pointer_set(payload, action_pointer);
3460 }
3461 
3462 /* PERCR - Policy-Engine Region Configuration Register
3463  * ---------------------------------------------------
3464  * This register configures the region parameters. The region_id must be
3465  * allocated.
3466  */
3467 #define MLXSW_REG_PERCR_ID 0x302A
3468 #define MLXSW_REG_PERCR_LEN 0x80
3469 
3470 MLXSW_REG_DEFINE(percr, MLXSW_REG_PERCR_ID, MLXSW_REG_PERCR_LEN);
3471 
3472 /* reg_percr_region_id
3473  * Region identifier.
3474  * Range 0..cap_max_regions-1
3475  * Access: Index
3476  */
3477 MLXSW_ITEM32(reg, percr, region_id, 0x00, 0, 16);
3478 
3479 /* reg_percr_atcam_ignore_prune
3480  * Ignore prune_vector by other A-TCAM rules. Used e.g., for a new rule.
3481  * Access: RW
3482  */
3483 MLXSW_ITEM32(reg, percr, atcam_ignore_prune, 0x04, 25, 1);
3484 
3485 /* reg_percr_ctcam_ignore_prune
3486  * Ignore prune_ctcam by other A-TCAM rules. Used e.g., for a new rule.
3487  * Access: RW
3488  */
3489 MLXSW_ITEM32(reg, percr, ctcam_ignore_prune, 0x04, 24, 1);
3490 
3491 /* reg_percr_bf_bypass
3492  * Bloom filter bypass.
3493  * 0 - Bloom filter is used (default)
3494  * 1 - Bloom filter is bypassed. The bypass is an OR condition of
3495  * region_id or eRP. See PERPT.bf_bypass
3496  * Access: RW
3497  */
3498 MLXSW_ITEM32(reg, percr, bf_bypass, 0x04, 16, 1);
3499 
3500 /* reg_percr_master_mask
3501  * Master mask. Logical OR mask of all masks of all rules of a region
3502  * (both A-TCAM and C-TCAM). When there are no eRPs
3503  * (erpt_pointer_valid = 0), then this provides the mask.
3504  * Access: RW
3505  */
3506 MLXSW_ITEM_BUF(reg, percr, master_mask, 0x20, 96);
3507 
3508 static inline void mlxsw_reg_percr_pack(char *payload, u16 region_id)
3509 {
3510 	MLXSW_REG_ZERO(percr, payload);
3511 	mlxsw_reg_percr_region_id_set(payload, region_id);
3512 	mlxsw_reg_percr_atcam_ignore_prune_set(payload, false);
3513 	mlxsw_reg_percr_ctcam_ignore_prune_set(payload, false);
3514 	mlxsw_reg_percr_bf_bypass_set(payload, false);
3515 }
3516 
3517 /* PERERP - Policy-Engine Region eRP Register
3518  * ------------------------------------------
3519  * This register configures the region eRP. The region_id must be
3520  * allocated.
3521  */
3522 #define MLXSW_REG_PERERP_ID 0x302B
3523 #define MLXSW_REG_PERERP_LEN 0x1C
3524 
3525 MLXSW_REG_DEFINE(pererp, MLXSW_REG_PERERP_ID, MLXSW_REG_PERERP_LEN);
3526 
3527 /* reg_pererp_region_id
3528  * Region identifier.
3529  * Range 0..cap_max_regions-1
3530  * Access: Index
3531  */
3532 MLXSW_ITEM32(reg, pererp, region_id, 0x00, 0, 16);
3533 
3534 /* reg_pererp_ctcam_le
3535  * C-TCAM lookup enable. Reserved when erpt_pointer_valid = 0.
3536  * Access: RW
3537  */
3538 MLXSW_ITEM32(reg, pererp, ctcam_le, 0x04, 28, 1);
3539 
3540 /* reg_pererp_erpt_pointer_valid
3541  * erpt_pointer is valid.
3542  * Access: RW
3543  */
3544 MLXSW_ITEM32(reg, pererp, erpt_pointer_valid, 0x10, 31, 1);
3545 
3546 /* reg_pererp_erpt_bank_pointer
3547  * Pointer to eRP table bank. May be modified at any time.
3548  * Range 0..cap_max_erp_table_banks-1
3549  * Reserved when erpt_pointer_valid = 0
3550  */
3551 MLXSW_ITEM32(reg, pererp, erpt_bank_pointer, 0x10, 16, 4);
3552 
3553 /* reg_pererp_erpt_pointer
3554  * Pointer to eRP table within the eRP bank. Can be changed for an
3555  * existing region.
3556  * Range 0..cap_max_erp_table_size-1
3557  * Reserved when erpt_pointer_valid = 0
3558  * Access: RW
3559  */
3560 MLXSW_ITEM32(reg, pererp, erpt_pointer, 0x10, 0, 8);
3561 
3562 /* reg_pererp_erpt_vector
3563  * Vector of allowed eRP indexes starting from erpt_pointer within the
3564  * erpt_bank_pointer. Next entries will be in next bank.
3565  * Note that eRP index is used and not eRP ID.
3566  * Reserved when erpt_pointer_valid = 0
3567  * Access: RW
3568  */
3569 MLXSW_ITEM_BIT_ARRAY(reg, pererp, erpt_vector, 0x14, 4, 1);
3570 
3571 /* reg_pererp_master_rp_id
3572  * Master RP ID. When there are no eRPs, then this provides the eRP ID
3573  * for the lookup. Can be changed for an existing region.
3574  * Reserved when erpt_pointer_valid = 1
3575  * Access: RW
3576  */
3577 MLXSW_ITEM32(reg, pererp, master_rp_id, 0x18, 0, 4);
3578 
3579 static inline void mlxsw_reg_pererp_erp_vector_pack(char *payload,
3580 						    unsigned long *erp_vector,
3581 						    unsigned long size)
3582 {
3583 	unsigned long bit;
3584 
3585 	for_each_set_bit(bit, erp_vector, size)
3586 		mlxsw_reg_pererp_erpt_vector_set(payload, bit, true);
3587 }
3588 
3589 static inline void mlxsw_reg_pererp_pack(char *payload, u16 region_id,
3590 					 bool ctcam_le, bool erpt_pointer_valid,
3591 					 u8 erpt_bank_pointer, u8 erpt_pointer,
3592 					 u8 master_rp_id)
3593 {
3594 	MLXSW_REG_ZERO(pererp, payload);
3595 	mlxsw_reg_pererp_region_id_set(payload, region_id);
3596 	mlxsw_reg_pererp_ctcam_le_set(payload, ctcam_le);
3597 	mlxsw_reg_pererp_erpt_pointer_valid_set(payload, erpt_pointer_valid);
3598 	mlxsw_reg_pererp_erpt_bank_pointer_set(payload, erpt_bank_pointer);
3599 	mlxsw_reg_pererp_erpt_pointer_set(payload, erpt_pointer);
3600 	mlxsw_reg_pererp_master_rp_id_set(payload, master_rp_id);
3601 }
3602 
3603 /* PEABFE - Policy-Engine Algorithmic Bloom Filter Entries Register
3604  * ----------------------------------------------------------------
3605  * This register configures the Bloom filter entries.
3606  */
3607 #define MLXSW_REG_PEABFE_ID 0x3022
3608 #define MLXSW_REG_PEABFE_BASE_LEN 0x10
3609 #define MLXSW_REG_PEABFE_BF_REC_LEN 0x4
3610 #define MLXSW_REG_PEABFE_BF_REC_MAX_COUNT 256
3611 #define MLXSW_REG_PEABFE_LEN (MLXSW_REG_PEABFE_BASE_LEN + \
3612 			      MLXSW_REG_PEABFE_BF_REC_LEN * \
3613 			      MLXSW_REG_PEABFE_BF_REC_MAX_COUNT)
3614 
3615 MLXSW_REG_DEFINE(peabfe, MLXSW_REG_PEABFE_ID, MLXSW_REG_PEABFE_LEN);
3616 
3617 /* reg_peabfe_size
3618  * Number of BF entries to be updated.
3619  * Range 1..256
3620  * Access: Op
3621  */
3622 MLXSW_ITEM32(reg, peabfe, size, 0x00, 0, 9);
3623 
3624 /* reg_peabfe_bf_entry_state
3625  * Bloom filter state
3626  * 0 - Clear
3627  * 1 - Set
3628  * Access: RW
3629  */
3630 MLXSW_ITEM32_INDEXED(reg, peabfe, bf_entry_state,
3631 		     MLXSW_REG_PEABFE_BASE_LEN,	31, 1,
3632 		     MLXSW_REG_PEABFE_BF_REC_LEN, 0x00, false);
3633 
3634 /* reg_peabfe_bf_entry_bank
3635  * Bloom filter bank ID
3636  * Range 0..cap_max_erp_table_banks-1
3637  * Access: Index
3638  */
3639 MLXSW_ITEM32_INDEXED(reg, peabfe, bf_entry_bank,
3640 		     MLXSW_REG_PEABFE_BASE_LEN,	24, 4,
3641 		     MLXSW_REG_PEABFE_BF_REC_LEN, 0x00, false);
3642 
3643 /* reg_peabfe_bf_entry_index
3644  * Bloom filter entry index
3645  * Range 0..2^cap_max_bf_log-1
3646  * Access: Index
3647  */
3648 MLXSW_ITEM32_INDEXED(reg, peabfe, bf_entry_index,
3649 		     MLXSW_REG_PEABFE_BASE_LEN,	0, 24,
3650 		     MLXSW_REG_PEABFE_BF_REC_LEN, 0x00, false);
3651 
3652 static inline void mlxsw_reg_peabfe_pack(char *payload)
3653 {
3654 	MLXSW_REG_ZERO(peabfe, payload);
3655 }
3656 
3657 static inline void mlxsw_reg_peabfe_rec_pack(char *payload, int rec_index,
3658 					     u8 state, u8 bank, u32 bf_index)
3659 {
3660 	u8 num_rec = mlxsw_reg_peabfe_size_get(payload);
3661 
3662 	if (rec_index >= num_rec)
3663 		mlxsw_reg_peabfe_size_set(payload, rec_index + 1);
3664 	mlxsw_reg_peabfe_bf_entry_state_set(payload, rec_index, state);
3665 	mlxsw_reg_peabfe_bf_entry_bank_set(payload, rec_index, bank);
3666 	mlxsw_reg_peabfe_bf_entry_index_set(payload, rec_index, bf_index);
3667 }
3668 
3669 /* IEDR - Infrastructure Entry Delete Register
3670  * ----------------------------------------------------
3671  * This register is used for deleting entries from the entry tables.
3672  * It is legitimate to attempt to delete a nonexisting entry (the device will
3673  * respond as a good flow).
3674  */
3675 #define MLXSW_REG_IEDR_ID 0x3804
3676 #define MLXSW_REG_IEDR_BASE_LEN 0x10 /* base length, without records */
3677 #define MLXSW_REG_IEDR_REC_LEN 0x8 /* record length */
3678 #define MLXSW_REG_IEDR_REC_MAX_COUNT 64
3679 #define MLXSW_REG_IEDR_LEN (MLXSW_REG_IEDR_BASE_LEN +	\
3680 			    MLXSW_REG_IEDR_REC_LEN *	\
3681 			    MLXSW_REG_IEDR_REC_MAX_COUNT)
3682 
3683 MLXSW_REG_DEFINE(iedr, MLXSW_REG_IEDR_ID, MLXSW_REG_IEDR_LEN);
3684 
3685 /* reg_iedr_num_rec
3686  * Number of records.
3687  * Access: OP
3688  */
3689 MLXSW_ITEM32(reg, iedr, num_rec, 0x00, 0, 8);
3690 
3691 /* reg_iedr_rec_type
3692  * Resource type.
3693  * Access: OP
3694  */
3695 MLXSW_ITEM32_INDEXED(reg, iedr, rec_type, MLXSW_REG_IEDR_BASE_LEN, 24, 8,
3696 		     MLXSW_REG_IEDR_REC_LEN, 0x00, false);
3697 
3698 /* reg_iedr_rec_size
3699  * Size of entries do be deleted. The unit is 1 entry, regardless of entry type.
3700  * Access: OP
3701  */
3702 MLXSW_ITEM32_INDEXED(reg, iedr, rec_size, MLXSW_REG_IEDR_BASE_LEN, 0, 13,
3703 		     MLXSW_REG_IEDR_REC_LEN, 0x00, false);
3704 
3705 /* reg_iedr_rec_index_start
3706  * Resource index start.
3707  * Access: OP
3708  */
3709 MLXSW_ITEM32_INDEXED(reg, iedr, rec_index_start, MLXSW_REG_IEDR_BASE_LEN, 0, 24,
3710 		     MLXSW_REG_IEDR_REC_LEN, 0x04, false);
3711 
3712 static inline void mlxsw_reg_iedr_pack(char *payload)
3713 {
3714 	MLXSW_REG_ZERO(iedr, payload);
3715 }
3716 
3717 static inline void mlxsw_reg_iedr_rec_pack(char *payload, int rec_index,
3718 					   u8 rec_type, u16 rec_size,
3719 					   u32 rec_index_start)
3720 {
3721 	u8 num_rec = mlxsw_reg_iedr_num_rec_get(payload);
3722 
3723 	if (rec_index >= num_rec)
3724 		mlxsw_reg_iedr_num_rec_set(payload, rec_index + 1);
3725 	mlxsw_reg_iedr_rec_type_set(payload, rec_index, rec_type);
3726 	mlxsw_reg_iedr_rec_size_set(payload, rec_index, rec_size);
3727 	mlxsw_reg_iedr_rec_index_start_set(payload, rec_index, rec_index_start);
3728 }
3729 
3730 /* QPTS - QoS Priority Trust State Register
3731  * ----------------------------------------
3732  * This register controls the port policy to calculate the switch priority and
3733  * packet color based on incoming packet fields.
3734  */
3735 #define MLXSW_REG_QPTS_ID 0x4002
3736 #define MLXSW_REG_QPTS_LEN 0x8
3737 
3738 MLXSW_REG_DEFINE(qpts, MLXSW_REG_QPTS_ID, MLXSW_REG_QPTS_LEN);
3739 
3740 /* reg_qpts_local_port
3741  * Local port number.
3742  * Access: Index
3743  *
3744  * Note: CPU port is supported.
3745  */
3746 MLXSW_ITEM32_LP(reg, qpts, 0x00, 16, 0x00, 12);
3747 
3748 enum mlxsw_reg_qpts_trust_state {
3749 	MLXSW_REG_QPTS_TRUST_STATE_PCP = 1,
3750 	MLXSW_REG_QPTS_TRUST_STATE_DSCP = 2, /* For MPLS, trust EXP. */
3751 };
3752 
3753 /* reg_qpts_trust_state
3754  * Trust state for a given port.
3755  * Access: RW
3756  */
3757 MLXSW_ITEM32(reg, qpts, trust_state, 0x04, 0, 3);
3758 
3759 static inline void mlxsw_reg_qpts_pack(char *payload, u16 local_port,
3760 				       enum mlxsw_reg_qpts_trust_state ts)
3761 {
3762 	MLXSW_REG_ZERO(qpts, payload);
3763 
3764 	mlxsw_reg_qpts_local_port_set(payload, local_port);
3765 	mlxsw_reg_qpts_trust_state_set(payload, ts);
3766 }
3767 
3768 /* QPCR - QoS Policer Configuration Register
3769  * -----------------------------------------
3770  * The QPCR register is used to create policers - that limit
3771  * the rate of bytes or packets via some trap group.
3772  */
3773 #define MLXSW_REG_QPCR_ID 0x4004
3774 #define MLXSW_REG_QPCR_LEN 0x28
3775 
3776 MLXSW_REG_DEFINE(qpcr, MLXSW_REG_QPCR_ID, MLXSW_REG_QPCR_LEN);
3777 
3778 enum mlxsw_reg_qpcr_g {
3779 	MLXSW_REG_QPCR_G_GLOBAL = 2,
3780 	MLXSW_REG_QPCR_G_STORM_CONTROL = 3,
3781 };
3782 
3783 /* reg_qpcr_g
3784  * The policer type.
3785  * Access: Index
3786  */
3787 MLXSW_ITEM32(reg, qpcr, g, 0x00, 14, 2);
3788 
3789 /* reg_qpcr_pid
3790  * Policer ID.
3791  * Access: Index
3792  */
3793 MLXSW_ITEM32(reg, qpcr, pid, 0x00, 0, 14);
3794 
3795 /* reg_qpcr_clear_counter
3796  * Clear counters.
3797  * Access: OP
3798  */
3799 MLXSW_ITEM32(reg, qpcr, clear_counter, 0x04, 31, 1);
3800 
3801 /* reg_qpcr_color_aware
3802  * Is the policer aware of colors.
3803  * Must be 0 (unaware) for cpu port.
3804  * Access: RW for unbounded policer. RO for bounded policer.
3805  */
3806 MLXSW_ITEM32(reg, qpcr, color_aware, 0x04, 15, 1);
3807 
3808 /* reg_qpcr_bytes
3809  * Is policer limit is for bytes per sec or packets per sec.
3810  * 0 - packets
3811  * 1 - bytes
3812  * Access: RW for unbounded policer. RO for bounded policer.
3813  */
3814 MLXSW_ITEM32(reg, qpcr, bytes, 0x04, 14, 1);
3815 
3816 enum mlxsw_reg_qpcr_ir_units {
3817 	MLXSW_REG_QPCR_IR_UNITS_M,
3818 	MLXSW_REG_QPCR_IR_UNITS_K,
3819 };
3820 
3821 /* reg_qpcr_ir_units
3822  * Policer's units for cir and eir fields (for bytes limits only)
3823  * 1 - 10^3
3824  * 0 - 10^6
3825  * Access: OP
3826  */
3827 MLXSW_ITEM32(reg, qpcr, ir_units, 0x04, 12, 1);
3828 
3829 enum mlxsw_reg_qpcr_rate_type {
3830 	MLXSW_REG_QPCR_RATE_TYPE_SINGLE = 1,
3831 	MLXSW_REG_QPCR_RATE_TYPE_DOUBLE = 2,
3832 };
3833 
3834 /* reg_qpcr_rate_type
3835  * Policer can have one limit (single rate) or 2 limits with specific operation
3836  * for packets that exceed the lower rate but not the upper one.
3837  * (For cpu port must be single rate)
3838  * Access: RW for unbounded policer. RO for bounded policer.
3839  */
3840 MLXSW_ITEM32(reg, qpcr, rate_type, 0x04, 8, 2);
3841 
3842 /* reg_qpc_cbs
3843  * Policer's committed burst size.
3844  * The policer is working with time slices of 50 nano sec. By default every
3845  * slice is granted the proportionate share of the committed rate. If we want to
3846  * allow a slice to exceed that share (while still keeping the rate per sec) we
3847  * can allow burst. The burst size is between the default proportionate share
3848  * (and no lower than 8) to 32Gb. (Even though giving a number higher than the
3849  * committed rate will result in exceeding the rate). The burst size must be a
3850  * log of 2 and will be determined by 2^cbs.
3851  * Access: RW
3852  */
3853 MLXSW_ITEM32(reg, qpcr, cbs, 0x08, 24, 6);
3854 
3855 /* reg_qpcr_cir
3856  * Policer's committed rate.
3857  * The rate used for sungle rate, the lower rate for double rate.
3858  * For bytes limits, the rate will be this value * the unit from ir_units.
3859  * (Resolution error is up to 1%).
3860  * Access: RW
3861  */
3862 MLXSW_ITEM32(reg, qpcr, cir, 0x0C, 0, 32);
3863 
3864 /* reg_qpcr_eir
3865  * Policer's exceed rate.
3866  * The higher rate for double rate, reserved for single rate.
3867  * Lower rate for double rate policer.
3868  * For bytes limits, the rate will be this value * the unit from ir_units.
3869  * (Resolution error is up to 1%).
3870  * Access: RW
3871  */
3872 MLXSW_ITEM32(reg, qpcr, eir, 0x10, 0, 32);
3873 
3874 #define MLXSW_REG_QPCR_DOUBLE_RATE_ACTION 2
3875 
3876 /* reg_qpcr_exceed_action.
3877  * What to do with packets between the 2 limits for double rate.
3878  * Access: RW for unbounded policer. RO for bounded policer.
3879  */
3880 MLXSW_ITEM32(reg, qpcr, exceed_action, 0x14, 0, 4);
3881 
3882 enum mlxsw_reg_qpcr_action {
3883 	/* Discard */
3884 	MLXSW_REG_QPCR_ACTION_DISCARD = 1,
3885 	/* Forward and set color to red.
3886 	 * If the packet is intended to cpu port, it will be dropped.
3887 	 */
3888 	MLXSW_REG_QPCR_ACTION_FORWARD = 2,
3889 };
3890 
3891 /* reg_qpcr_violate_action
3892  * What to do with packets that cross the cir limit (for single rate) or the eir
3893  * limit (for double rate).
3894  * Access: RW for unbounded policer. RO for bounded policer.
3895  */
3896 MLXSW_ITEM32(reg, qpcr, violate_action, 0x18, 0, 4);
3897 
3898 /* reg_qpcr_violate_count
3899  * Counts the number of times violate_action happened on this PID.
3900  * Access: RW
3901  */
3902 MLXSW_ITEM64(reg, qpcr, violate_count, 0x20, 0, 64);
3903 
3904 /* Packets */
3905 #define MLXSW_REG_QPCR_LOWEST_CIR	1
3906 #define MLXSW_REG_QPCR_HIGHEST_CIR	(2 * 1000 * 1000 * 1000) /* 2Gpps */
3907 #define MLXSW_REG_QPCR_LOWEST_CBS	4
3908 #define MLXSW_REG_QPCR_HIGHEST_CBS	24
3909 
3910 /* Bandwidth */
3911 #define MLXSW_REG_QPCR_LOWEST_CIR_BITS		1024 /* bps */
3912 #define MLXSW_REG_QPCR_HIGHEST_CIR_BITS		2000000000000ULL /* 2Tbps */
3913 #define MLXSW_REG_QPCR_LOWEST_CBS_BITS_SP1	4
3914 #define MLXSW_REG_QPCR_LOWEST_CBS_BITS_SP2	4
3915 #define MLXSW_REG_QPCR_HIGHEST_CBS_BITS_SP1	25
3916 #define MLXSW_REG_QPCR_HIGHEST_CBS_BITS_SP2	31
3917 
3918 static inline void mlxsw_reg_qpcr_pack(char *payload, u16 pid,
3919 				       enum mlxsw_reg_qpcr_ir_units ir_units,
3920 				       bool bytes, u32 cir, u16 cbs)
3921 {
3922 	MLXSW_REG_ZERO(qpcr, payload);
3923 	mlxsw_reg_qpcr_pid_set(payload, pid);
3924 	mlxsw_reg_qpcr_g_set(payload, MLXSW_REG_QPCR_G_GLOBAL);
3925 	mlxsw_reg_qpcr_rate_type_set(payload, MLXSW_REG_QPCR_RATE_TYPE_SINGLE);
3926 	mlxsw_reg_qpcr_violate_action_set(payload,
3927 					  MLXSW_REG_QPCR_ACTION_DISCARD);
3928 	mlxsw_reg_qpcr_cir_set(payload, cir);
3929 	mlxsw_reg_qpcr_ir_units_set(payload, ir_units);
3930 	mlxsw_reg_qpcr_bytes_set(payload, bytes);
3931 	mlxsw_reg_qpcr_cbs_set(payload, cbs);
3932 }
3933 
3934 /* QTCT - QoS Switch Traffic Class Table
3935  * -------------------------------------
3936  * Configures the mapping between the packet switch priority and the
3937  * traffic class on the transmit port.
3938  */
3939 #define MLXSW_REG_QTCT_ID 0x400A
3940 #define MLXSW_REG_QTCT_LEN 0x08
3941 
3942 MLXSW_REG_DEFINE(qtct, MLXSW_REG_QTCT_ID, MLXSW_REG_QTCT_LEN);
3943 
3944 /* reg_qtct_local_port
3945  * Local port number.
3946  * Access: Index
3947  *
3948  * Note: CPU port is not supported.
3949  */
3950 MLXSW_ITEM32_LP(reg, qtct, 0x00, 16, 0x00, 12);
3951 
3952 /* reg_qtct_sub_port
3953  * Virtual port within the physical port.
3954  * Should be set to 0 when virtual ports are not enabled on the port.
3955  * Access: Index
3956  */
3957 MLXSW_ITEM32(reg, qtct, sub_port, 0x00, 8, 8);
3958 
3959 /* reg_qtct_switch_prio
3960  * Switch priority.
3961  * Access: Index
3962  */
3963 MLXSW_ITEM32(reg, qtct, switch_prio, 0x00, 0, 4);
3964 
3965 /* reg_qtct_tclass
3966  * Traffic class.
3967  * Default values:
3968  * switch_prio 0 : tclass 1
3969  * switch_prio 1 : tclass 0
3970  * switch_prio i : tclass i, for i > 1
3971  * Access: RW
3972  */
3973 MLXSW_ITEM32(reg, qtct, tclass, 0x04, 0, 4);
3974 
3975 static inline void mlxsw_reg_qtct_pack(char *payload, u16 local_port,
3976 				       u8 switch_prio, u8 tclass)
3977 {
3978 	MLXSW_REG_ZERO(qtct, payload);
3979 	mlxsw_reg_qtct_local_port_set(payload, local_port);
3980 	mlxsw_reg_qtct_switch_prio_set(payload, switch_prio);
3981 	mlxsw_reg_qtct_tclass_set(payload, tclass);
3982 }
3983 
3984 /* QEEC - QoS ETS Element Configuration Register
3985  * ---------------------------------------------
3986  * Configures the ETS elements.
3987  */
3988 #define MLXSW_REG_QEEC_ID 0x400D
3989 #define MLXSW_REG_QEEC_LEN 0x20
3990 
3991 MLXSW_REG_DEFINE(qeec, MLXSW_REG_QEEC_ID, MLXSW_REG_QEEC_LEN);
3992 
3993 /* reg_qeec_local_port
3994  * Local port number.
3995  * Access: Index
3996  *
3997  * Note: CPU port is supported.
3998  */
3999 MLXSW_ITEM32_LP(reg, qeec, 0x00, 16, 0x00, 12);
4000 
4001 enum mlxsw_reg_qeec_hr {
4002 	MLXSW_REG_QEEC_HR_PORT,
4003 	MLXSW_REG_QEEC_HR_GROUP,
4004 	MLXSW_REG_QEEC_HR_SUBGROUP,
4005 	MLXSW_REG_QEEC_HR_TC,
4006 };
4007 
4008 /* reg_qeec_element_hierarchy
4009  * 0 - Port
4010  * 1 - Group
4011  * 2 - Subgroup
4012  * 3 - Traffic Class
4013  * Access: Index
4014  */
4015 MLXSW_ITEM32(reg, qeec, element_hierarchy, 0x04, 16, 4);
4016 
4017 /* reg_qeec_element_index
4018  * The index of the element in the hierarchy.
4019  * Access: Index
4020  */
4021 MLXSW_ITEM32(reg, qeec, element_index, 0x04, 0, 8);
4022 
4023 /* reg_qeec_next_element_index
4024  * The index of the next (lower) element in the hierarchy.
4025  * Access: RW
4026  *
4027  * Note: Reserved for element_hierarchy 0.
4028  */
4029 MLXSW_ITEM32(reg, qeec, next_element_index, 0x08, 0, 8);
4030 
4031 /* reg_qeec_mise
4032  * Min shaper configuration enable. Enables configuration of the min
4033  * shaper on this ETS element
4034  * 0 - Disable
4035  * 1 - Enable
4036  * Access: RW
4037  */
4038 MLXSW_ITEM32(reg, qeec, mise, 0x0C, 31, 1);
4039 
4040 /* reg_qeec_ptps
4041  * PTP shaper
4042  * 0: regular shaper mode
4043  * 1: PTP oriented shaper
4044  * Allowed only for hierarchy 0
4045  * Not supported for CPU port
4046  * Note that ptps mode may affect the shaper rates of all hierarchies
4047  * Supported only on Spectrum-1
4048  * Access: RW
4049  */
4050 MLXSW_ITEM32(reg, qeec, ptps, 0x0C, 29, 1);
4051 
4052 enum {
4053 	MLXSW_REG_QEEC_BYTES_MODE,
4054 	MLXSW_REG_QEEC_PACKETS_MODE,
4055 };
4056 
4057 /* reg_qeec_pb
4058  * Packets or bytes mode.
4059  * 0 - Bytes mode
4060  * 1 - Packets mode
4061  * Access: RW
4062  *
4063  * Note: Used for max shaper configuration. For Spectrum, packets mode
4064  * is supported only for traffic classes of CPU port.
4065  */
4066 MLXSW_ITEM32(reg, qeec, pb, 0x0C, 28, 1);
4067 
4068 /* The smallest permitted min shaper rate. */
4069 #define MLXSW_REG_QEEC_MIS_MIN	200000		/* Kbps */
4070 
4071 /* reg_qeec_min_shaper_rate
4072  * Min shaper information rate.
4073  * For CPU port, can only be configured for port hierarchy.
4074  * When in bytes mode, value is specified in units of 1000bps.
4075  * Access: RW
4076  */
4077 MLXSW_ITEM32(reg, qeec, min_shaper_rate, 0x0C, 0, 28);
4078 
4079 /* reg_qeec_mase
4080  * Max shaper configuration enable. Enables configuration of the max
4081  * shaper on this ETS element.
4082  * 0 - Disable
4083  * 1 - Enable
4084  * Access: RW
4085  */
4086 MLXSW_ITEM32(reg, qeec, mase, 0x10, 31, 1);
4087 
4088 /* The largest max shaper value possible to disable the shaper. */
4089 #define MLXSW_REG_QEEC_MAS_DIS	((1u << 31) - 1)	/* Kbps */
4090 
4091 /* reg_qeec_max_shaper_rate
4092  * Max shaper information rate.
4093  * For CPU port, can only be configured for port hierarchy.
4094  * When in bytes mode, value is specified in units of 1000bps.
4095  * Access: RW
4096  */
4097 MLXSW_ITEM32(reg, qeec, max_shaper_rate, 0x10, 0, 31);
4098 
4099 /* reg_qeec_de
4100  * DWRR configuration enable. Enables configuration of the dwrr and
4101  * dwrr_weight.
4102  * 0 - Disable
4103  * 1 - Enable
4104  * Access: RW
4105  */
4106 MLXSW_ITEM32(reg, qeec, de, 0x18, 31, 1);
4107 
4108 /* reg_qeec_dwrr
4109  * Transmission selection algorithm to use on the link going down from
4110  * the ETS element.
4111  * 0 - Strict priority
4112  * 1 - DWRR
4113  * Access: RW
4114  */
4115 MLXSW_ITEM32(reg, qeec, dwrr, 0x18, 15, 1);
4116 
4117 /* reg_qeec_dwrr_weight
4118  * DWRR weight on the link going down from the ETS element. The
4119  * percentage of bandwidth guaranteed to an ETS element within
4120  * its hierarchy. The sum of all weights across all ETS elements
4121  * within one hierarchy should be equal to 100. Reserved when
4122  * transmission selection algorithm is strict priority.
4123  * Access: RW
4124  */
4125 MLXSW_ITEM32(reg, qeec, dwrr_weight, 0x18, 0, 8);
4126 
4127 /* reg_qeec_max_shaper_bs
4128  * Max shaper burst size
4129  * Burst size is 2^max_shaper_bs * 512 bits
4130  * For Spectrum-1: Range is: 5..25
4131  * For Spectrum-2: Range is: 11..25
4132  * Reserved when ptps = 1
4133  * Access: RW
4134  */
4135 MLXSW_ITEM32(reg, qeec, max_shaper_bs, 0x1C, 0, 6);
4136 
4137 #define MLXSW_REG_QEEC_HIGHEST_SHAPER_BS	25
4138 #define MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP1	5
4139 #define MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP2	11
4140 #define MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP3	11
4141 #define MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP4	11
4142 
4143 static inline void mlxsw_reg_qeec_pack(char *payload, u16 local_port,
4144 				       enum mlxsw_reg_qeec_hr hr, u8 index,
4145 				       u8 next_index)
4146 {
4147 	MLXSW_REG_ZERO(qeec, payload);
4148 	mlxsw_reg_qeec_local_port_set(payload, local_port);
4149 	mlxsw_reg_qeec_element_hierarchy_set(payload, hr);
4150 	mlxsw_reg_qeec_element_index_set(payload, index);
4151 	mlxsw_reg_qeec_next_element_index_set(payload, next_index);
4152 }
4153 
4154 static inline void mlxsw_reg_qeec_ptps_pack(char *payload, u16 local_port,
4155 					    bool ptps)
4156 {
4157 	MLXSW_REG_ZERO(qeec, payload);
4158 	mlxsw_reg_qeec_local_port_set(payload, local_port);
4159 	mlxsw_reg_qeec_element_hierarchy_set(payload, MLXSW_REG_QEEC_HR_PORT);
4160 	mlxsw_reg_qeec_ptps_set(payload, ptps);
4161 }
4162 
4163 /* QRWE - QoS ReWrite Enable
4164  * -------------------------
4165  * This register configures the rewrite enable per receive port.
4166  */
4167 #define MLXSW_REG_QRWE_ID 0x400F
4168 #define MLXSW_REG_QRWE_LEN 0x08
4169 
4170 MLXSW_REG_DEFINE(qrwe, MLXSW_REG_QRWE_ID, MLXSW_REG_QRWE_LEN);
4171 
4172 /* reg_qrwe_local_port
4173  * Local port number.
4174  * Access: Index
4175  *
4176  * Note: CPU port is supported. No support for router port.
4177  */
4178 MLXSW_ITEM32_LP(reg, qrwe, 0x00, 16, 0x00, 12);
4179 
4180 /* reg_qrwe_dscp
4181  * Whether to enable DSCP rewrite (default is 0, don't rewrite).
4182  * Access: RW
4183  */
4184 MLXSW_ITEM32(reg, qrwe, dscp, 0x04, 1, 1);
4185 
4186 /* reg_qrwe_pcp
4187  * Whether to enable PCP and DEI rewrite (default is 0, don't rewrite).
4188  * Access: RW
4189  */
4190 MLXSW_ITEM32(reg, qrwe, pcp, 0x04, 0, 1);
4191 
4192 static inline void mlxsw_reg_qrwe_pack(char *payload, u16 local_port,
4193 				       bool rewrite_pcp, bool rewrite_dscp)
4194 {
4195 	MLXSW_REG_ZERO(qrwe, payload);
4196 	mlxsw_reg_qrwe_local_port_set(payload, local_port);
4197 	mlxsw_reg_qrwe_pcp_set(payload, rewrite_pcp);
4198 	mlxsw_reg_qrwe_dscp_set(payload, rewrite_dscp);
4199 }
4200 
4201 /* QPDSM - QoS Priority to DSCP Mapping
4202  * ------------------------------------
4203  * QoS Priority to DSCP Mapping Register
4204  */
4205 #define MLXSW_REG_QPDSM_ID 0x4011
4206 #define MLXSW_REG_QPDSM_BASE_LEN 0x04 /* base length, without records */
4207 #define MLXSW_REG_QPDSM_PRIO_ENTRY_REC_LEN 0x4 /* record length */
4208 #define MLXSW_REG_QPDSM_PRIO_ENTRY_REC_MAX_COUNT 16
4209 #define MLXSW_REG_QPDSM_LEN (MLXSW_REG_QPDSM_BASE_LEN +			\
4210 			     MLXSW_REG_QPDSM_PRIO_ENTRY_REC_LEN *	\
4211 			     MLXSW_REG_QPDSM_PRIO_ENTRY_REC_MAX_COUNT)
4212 
4213 MLXSW_REG_DEFINE(qpdsm, MLXSW_REG_QPDSM_ID, MLXSW_REG_QPDSM_LEN);
4214 
4215 /* reg_qpdsm_local_port
4216  * Local Port. Supported for data packets from CPU port.
4217  * Access: Index
4218  */
4219 MLXSW_ITEM32_LP(reg, qpdsm, 0x00, 16, 0x00, 12);
4220 
4221 /* reg_qpdsm_prio_entry_color0_e
4222  * Enable update of the entry for color 0 and a given port.
4223  * Access: WO
4224  */
4225 MLXSW_ITEM32_INDEXED(reg, qpdsm, prio_entry_color0_e,
4226 		     MLXSW_REG_QPDSM_BASE_LEN, 31, 1,
4227 		     MLXSW_REG_QPDSM_PRIO_ENTRY_REC_LEN, 0x00, false);
4228 
4229 /* reg_qpdsm_prio_entry_color0_dscp
4230  * DSCP field in the outer label of the packet for color 0 and a given port.
4231  * Reserved when e=0.
4232  * Access: RW
4233  */
4234 MLXSW_ITEM32_INDEXED(reg, qpdsm, prio_entry_color0_dscp,
4235 		     MLXSW_REG_QPDSM_BASE_LEN, 24, 6,
4236 		     MLXSW_REG_QPDSM_PRIO_ENTRY_REC_LEN, 0x00, false);
4237 
4238 /* reg_qpdsm_prio_entry_color1_e
4239  * Enable update of the entry for color 1 and a given port.
4240  * Access: WO
4241  */
4242 MLXSW_ITEM32_INDEXED(reg, qpdsm, prio_entry_color1_e,
4243 		     MLXSW_REG_QPDSM_BASE_LEN, 23, 1,
4244 		     MLXSW_REG_QPDSM_PRIO_ENTRY_REC_LEN, 0x00, false);
4245 
4246 /* reg_qpdsm_prio_entry_color1_dscp
4247  * DSCP field in the outer label of the packet for color 1 and a given port.
4248  * Reserved when e=0.
4249  * Access: RW
4250  */
4251 MLXSW_ITEM32_INDEXED(reg, qpdsm, prio_entry_color1_dscp,
4252 		     MLXSW_REG_QPDSM_BASE_LEN, 16, 6,
4253 		     MLXSW_REG_QPDSM_PRIO_ENTRY_REC_LEN, 0x00, false);
4254 
4255 /* reg_qpdsm_prio_entry_color2_e
4256  * Enable update of the entry for color 2 and a given port.
4257  * Access: WO
4258  */
4259 MLXSW_ITEM32_INDEXED(reg, qpdsm, prio_entry_color2_e,
4260 		     MLXSW_REG_QPDSM_BASE_LEN, 15, 1,
4261 		     MLXSW_REG_QPDSM_PRIO_ENTRY_REC_LEN, 0x00, false);
4262 
4263 /* reg_qpdsm_prio_entry_color2_dscp
4264  * DSCP field in the outer label of the packet for color 2 and a given port.
4265  * Reserved when e=0.
4266  * Access: RW
4267  */
4268 MLXSW_ITEM32_INDEXED(reg, qpdsm, prio_entry_color2_dscp,
4269 		     MLXSW_REG_QPDSM_BASE_LEN, 8, 6,
4270 		     MLXSW_REG_QPDSM_PRIO_ENTRY_REC_LEN, 0x00, false);
4271 
4272 static inline void mlxsw_reg_qpdsm_pack(char *payload, u16 local_port)
4273 {
4274 	MLXSW_REG_ZERO(qpdsm, payload);
4275 	mlxsw_reg_qpdsm_local_port_set(payload, local_port);
4276 }
4277 
4278 static inline void
4279 mlxsw_reg_qpdsm_prio_pack(char *payload, unsigned short prio, u8 dscp)
4280 {
4281 	mlxsw_reg_qpdsm_prio_entry_color0_e_set(payload, prio, 1);
4282 	mlxsw_reg_qpdsm_prio_entry_color0_dscp_set(payload, prio, dscp);
4283 	mlxsw_reg_qpdsm_prio_entry_color1_e_set(payload, prio, 1);
4284 	mlxsw_reg_qpdsm_prio_entry_color1_dscp_set(payload, prio, dscp);
4285 	mlxsw_reg_qpdsm_prio_entry_color2_e_set(payload, prio, 1);
4286 	mlxsw_reg_qpdsm_prio_entry_color2_dscp_set(payload, prio, dscp);
4287 }
4288 
4289 /* QPDP - QoS Port DSCP to Priority Mapping Register
4290  * -------------------------------------------------
4291  * This register controls the port default Switch Priority and Color. The
4292  * default Switch Priority and Color are used for frames where the trust state
4293  * uses default values. All member ports of a LAG should be configured with the
4294  * same default values.
4295  */
4296 #define MLXSW_REG_QPDP_ID 0x4007
4297 #define MLXSW_REG_QPDP_LEN 0x8
4298 
4299 MLXSW_REG_DEFINE(qpdp, MLXSW_REG_QPDP_ID, MLXSW_REG_QPDP_LEN);
4300 
4301 /* reg_qpdp_local_port
4302  * Local Port. Supported for data packets from CPU port.
4303  * Access: Index
4304  */
4305 MLXSW_ITEM32_LP(reg, qpdp, 0x00, 16, 0x00, 12);
4306 
4307 /* reg_qpdp_switch_prio
4308  * Default port Switch Priority (default 0)
4309  * Access: RW
4310  */
4311 MLXSW_ITEM32(reg, qpdp, switch_prio, 0x04, 0, 4);
4312 
4313 static inline void mlxsw_reg_qpdp_pack(char *payload, u16 local_port,
4314 				       u8 switch_prio)
4315 {
4316 	MLXSW_REG_ZERO(qpdp, payload);
4317 	mlxsw_reg_qpdp_local_port_set(payload, local_port);
4318 	mlxsw_reg_qpdp_switch_prio_set(payload, switch_prio);
4319 }
4320 
4321 /* QPDPM - QoS Port DSCP to Priority Mapping Register
4322  * --------------------------------------------------
4323  * This register controls the mapping from DSCP field to
4324  * Switch Priority for IP packets.
4325  */
4326 #define MLXSW_REG_QPDPM_ID 0x4013
4327 #define MLXSW_REG_QPDPM_BASE_LEN 0x4 /* base length, without records */
4328 #define MLXSW_REG_QPDPM_DSCP_ENTRY_REC_LEN 0x2 /* record length */
4329 #define MLXSW_REG_QPDPM_DSCP_ENTRY_REC_MAX_COUNT 64
4330 #define MLXSW_REG_QPDPM_LEN (MLXSW_REG_QPDPM_BASE_LEN +			\
4331 			     MLXSW_REG_QPDPM_DSCP_ENTRY_REC_LEN *	\
4332 			     MLXSW_REG_QPDPM_DSCP_ENTRY_REC_MAX_COUNT)
4333 
4334 MLXSW_REG_DEFINE(qpdpm, MLXSW_REG_QPDPM_ID, MLXSW_REG_QPDPM_LEN);
4335 
4336 /* reg_qpdpm_local_port
4337  * Local Port. Supported for data packets from CPU port.
4338  * Access: Index
4339  */
4340 MLXSW_ITEM32_LP(reg, qpdpm, 0x00, 16, 0x00, 12);
4341 
4342 /* reg_qpdpm_dscp_e
4343  * Enable update of the specific entry. When cleared, the switch_prio and color
4344  * fields are ignored and the previous switch_prio and color values are
4345  * preserved.
4346  * Access: WO
4347  */
4348 MLXSW_ITEM16_INDEXED(reg, qpdpm, dscp_entry_e, MLXSW_REG_QPDPM_BASE_LEN, 15, 1,
4349 		     MLXSW_REG_QPDPM_DSCP_ENTRY_REC_LEN, 0x00, false);
4350 
4351 /* reg_qpdpm_dscp_prio
4352  * The new Switch Priority value for the relevant DSCP value.
4353  * Access: RW
4354  */
4355 MLXSW_ITEM16_INDEXED(reg, qpdpm, dscp_entry_prio,
4356 		     MLXSW_REG_QPDPM_BASE_LEN, 0, 4,
4357 		     MLXSW_REG_QPDPM_DSCP_ENTRY_REC_LEN, 0x00, false);
4358 
4359 static inline void mlxsw_reg_qpdpm_pack(char *payload, u16 local_port)
4360 {
4361 	MLXSW_REG_ZERO(qpdpm, payload);
4362 	mlxsw_reg_qpdpm_local_port_set(payload, local_port);
4363 }
4364 
4365 static inline void
4366 mlxsw_reg_qpdpm_dscp_pack(char *payload, unsigned short dscp, u8 prio)
4367 {
4368 	mlxsw_reg_qpdpm_dscp_entry_e_set(payload, dscp, 1);
4369 	mlxsw_reg_qpdpm_dscp_entry_prio_set(payload, dscp, prio);
4370 }
4371 
4372 /* QTCTM - QoS Switch Traffic Class Table is Multicast-Aware Register
4373  * ------------------------------------------------------------------
4374  * This register configures if the Switch Priority to Traffic Class mapping is
4375  * based on Multicast packet indication. If so, then multicast packets will get
4376  * a Traffic Class that is plus (cap_max_tclass_data/2) the value configured by
4377  * QTCT.
4378  * By default, Switch Priority to Traffic Class mapping is not based on
4379  * Multicast packet indication.
4380  */
4381 #define MLXSW_REG_QTCTM_ID 0x401A
4382 #define MLXSW_REG_QTCTM_LEN 0x08
4383 
4384 MLXSW_REG_DEFINE(qtctm, MLXSW_REG_QTCTM_ID, MLXSW_REG_QTCTM_LEN);
4385 
4386 /* reg_qtctm_local_port
4387  * Local port number.
4388  * No support for CPU port.
4389  * Access: Index
4390  */
4391 MLXSW_ITEM32_LP(reg, qtctm, 0x00, 16, 0x00, 12);
4392 
4393 /* reg_qtctm_mc
4394  * Multicast Mode
4395  * Whether Switch Priority to Traffic Class mapping is based on Multicast packet
4396  * indication (default is 0, not based on Multicast packet indication).
4397  */
4398 MLXSW_ITEM32(reg, qtctm, mc, 0x04, 0, 1);
4399 
4400 static inline void
4401 mlxsw_reg_qtctm_pack(char *payload, u16 local_port, bool mc)
4402 {
4403 	MLXSW_REG_ZERO(qtctm, payload);
4404 	mlxsw_reg_qtctm_local_port_set(payload, local_port);
4405 	mlxsw_reg_qtctm_mc_set(payload, mc);
4406 }
4407 
4408 /* QPSC - QoS PTP Shaper Configuration Register
4409  * --------------------------------------------
4410  * The QPSC allows advanced configuration of the shapers when QEEC.ptps=1.
4411  * Supported only on Spectrum-1.
4412  */
4413 #define MLXSW_REG_QPSC_ID 0x401B
4414 #define MLXSW_REG_QPSC_LEN 0x28
4415 
4416 MLXSW_REG_DEFINE(qpsc, MLXSW_REG_QPSC_ID, MLXSW_REG_QPSC_LEN);
4417 
4418 enum mlxsw_reg_qpsc_port_speed {
4419 	MLXSW_REG_QPSC_PORT_SPEED_100M,
4420 	MLXSW_REG_QPSC_PORT_SPEED_1G,
4421 	MLXSW_REG_QPSC_PORT_SPEED_10G,
4422 	MLXSW_REG_QPSC_PORT_SPEED_25G,
4423 };
4424 
4425 /* reg_qpsc_port_speed
4426  * Port speed.
4427  * Access: Index
4428  */
4429 MLXSW_ITEM32(reg, qpsc, port_speed, 0x00, 0, 4);
4430 
4431 /* reg_qpsc_shaper_time_exp
4432  * The base-time-interval for updating the shapers tokens (for all hierarchies).
4433  * shaper_update_rate = 2 ^ shaper_time_exp * (1 + shaper_time_mantissa) * 32nSec
4434  * shaper_rate = 64bit * shaper_inc / shaper_update_rate
4435  * Access: RW
4436  */
4437 MLXSW_ITEM32(reg, qpsc, shaper_time_exp, 0x04, 16, 4);
4438 
4439 /* reg_qpsc_shaper_time_mantissa
4440  * The base-time-interval for updating the shapers tokens (for all hierarchies).
4441  * shaper_update_rate = 2 ^ shaper_time_exp * (1 + shaper_time_mantissa) * 32nSec
4442  * shaper_rate = 64bit * shaper_inc / shaper_update_rate
4443  * Access: RW
4444  */
4445 MLXSW_ITEM32(reg, qpsc, shaper_time_mantissa, 0x04, 0, 5);
4446 
4447 /* reg_qpsc_shaper_inc
4448  * Number of tokens added to shaper on each update.
4449  * Units of 8B.
4450  * Access: RW
4451  */
4452 MLXSW_ITEM32(reg, qpsc, shaper_inc, 0x08, 0, 5);
4453 
4454 /* reg_qpsc_shaper_bs
4455  * Max shaper Burst size.
4456  * Burst size is 2 ^ max_shaper_bs * 512 [bits]
4457  * Range is: 5..25 (from 2KB..2GB)
4458  * Access: RW
4459  */
4460 MLXSW_ITEM32(reg, qpsc, shaper_bs, 0x0C, 0, 6);
4461 
4462 /* reg_qpsc_ptsc_we
4463  * Write enable to port_to_shaper_credits.
4464  * Access: WO
4465  */
4466 MLXSW_ITEM32(reg, qpsc, ptsc_we, 0x10, 31, 1);
4467 
4468 /* reg_qpsc_port_to_shaper_credits
4469  * For split ports: range 1..57
4470  * For non-split ports: range 1..112
4471  * Written only when ptsc_we is set.
4472  * Access: RW
4473  */
4474 MLXSW_ITEM32(reg, qpsc, port_to_shaper_credits, 0x10, 0, 8);
4475 
4476 /* reg_qpsc_ing_timestamp_inc
4477  * Ingress timestamp increment.
4478  * 2's complement.
4479  * The timestamp of MTPPTR at ingress will be incremented by this value. Global
4480  * value for all ports.
4481  * Same units as used by MTPPTR.
4482  * Access: RW
4483  */
4484 MLXSW_ITEM32(reg, qpsc, ing_timestamp_inc, 0x20, 0, 32);
4485 
4486 /* reg_qpsc_egr_timestamp_inc
4487  * Egress timestamp increment.
4488  * 2's complement.
4489  * The timestamp of MTPPTR at egress will be incremented by this value. Global
4490  * value for all ports.
4491  * Same units as used by MTPPTR.
4492  * Access: RW
4493  */
4494 MLXSW_ITEM32(reg, qpsc, egr_timestamp_inc, 0x24, 0, 32);
4495 
4496 static inline void
4497 mlxsw_reg_qpsc_pack(char *payload, enum mlxsw_reg_qpsc_port_speed port_speed,
4498 		    u8 shaper_time_exp, u8 shaper_time_mantissa, u8 shaper_inc,
4499 		    u8 shaper_bs, u8 port_to_shaper_credits,
4500 		    int ing_timestamp_inc, int egr_timestamp_inc)
4501 {
4502 	MLXSW_REG_ZERO(qpsc, payload);
4503 	mlxsw_reg_qpsc_port_speed_set(payload, port_speed);
4504 	mlxsw_reg_qpsc_shaper_time_exp_set(payload, shaper_time_exp);
4505 	mlxsw_reg_qpsc_shaper_time_mantissa_set(payload, shaper_time_mantissa);
4506 	mlxsw_reg_qpsc_shaper_inc_set(payload, shaper_inc);
4507 	mlxsw_reg_qpsc_shaper_bs_set(payload, shaper_bs);
4508 	mlxsw_reg_qpsc_ptsc_we_set(payload, true);
4509 	mlxsw_reg_qpsc_port_to_shaper_credits_set(payload, port_to_shaper_credits);
4510 	mlxsw_reg_qpsc_ing_timestamp_inc_set(payload, ing_timestamp_inc);
4511 	mlxsw_reg_qpsc_egr_timestamp_inc_set(payload, egr_timestamp_inc);
4512 }
4513 
4514 /* PMLP - Ports Module to Local Port Register
4515  * ------------------------------------------
4516  * Configures the assignment of modules to local ports.
4517  */
4518 #define MLXSW_REG_PMLP_ID 0x5002
4519 #define MLXSW_REG_PMLP_LEN 0x40
4520 
4521 MLXSW_REG_DEFINE(pmlp, MLXSW_REG_PMLP_ID, MLXSW_REG_PMLP_LEN);
4522 
4523 /* reg_pmlp_rxtx
4524  * 0 - Tx value is used for both Tx and Rx.
4525  * 1 - Rx value is taken from a separte field.
4526  * Access: RW
4527  */
4528 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
4529 
4530 /* reg_pmlp_local_port
4531  * Local port number.
4532  * Access: Index
4533  */
4534 MLXSW_ITEM32_LP(reg, pmlp, 0x00, 16, 0x00, 12);
4535 
4536 /* reg_pmlp_width
4537  * 0 - Unmap local port.
4538  * 1 - Lane 0 is used.
4539  * 2 - Lanes 0 and 1 are used.
4540  * 4 - Lanes 0, 1, 2 and 3 are used.
4541  * 8 - Lanes 0-7 are used.
4542  * Access: RW
4543  */
4544 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
4545 
4546 /* reg_pmlp_module
4547  * Module number.
4548  * Access: RW
4549  */
4550 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0x00, false);
4551 
4552 /* reg_pmlp_slot_index
4553  * Module number.
4554  * Slot_index
4555  * Slot_index = 0 represent the onboard (motherboard).
4556  * In case of non-modular system only slot_index = 0 is available.
4557  * Access: RW
4558  */
4559 MLXSW_ITEM32_INDEXED(reg, pmlp, slot_index, 0x04, 8, 4, 0x04, 0x00, false);
4560 
4561 /* reg_pmlp_tx_lane
4562  * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
4563  * Access: RW
4564  */
4565 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 4, 0x04, 0x00, false);
4566 
4567 /* reg_pmlp_rx_lane
4568  * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
4569  * equal to Tx lane.
4570  * Access: RW
4571  */
4572 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 4, 0x04, 0x00, false);
4573 
4574 static inline void mlxsw_reg_pmlp_pack(char *payload, u16 local_port)
4575 {
4576 	MLXSW_REG_ZERO(pmlp, payload);
4577 	mlxsw_reg_pmlp_local_port_set(payload, local_port);
4578 }
4579 
4580 /* PMTU - Port MTU Register
4581  * ------------------------
4582  * Configures and reports the port MTU.
4583  */
4584 #define MLXSW_REG_PMTU_ID 0x5003
4585 #define MLXSW_REG_PMTU_LEN 0x10
4586 
4587 MLXSW_REG_DEFINE(pmtu, MLXSW_REG_PMTU_ID, MLXSW_REG_PMTU_LEN);
4588 
4589 /* reg_pmtu_local_port
4590  * Local port number.
4591  * Access: Index
4592  */
4593 MLXSW_ITEM32_LP(reg, pmtu, 0x00, 16, 0x00, 12);
4594 
4595 /* reg_pmtu_max_mtu
4596  * Maximum MTU.
4597  * When port type (e.g. Ethernet) is configured, the relevant MTU is
4598  * reported, otherwise the minimum between the max_mtu of the different
4599  * types is reported.
4600  * Access: RO
4601  */
4602 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
4603 
4604 /* reg_pmtu_admin_mtu
4605  * MTU value to set port to. Must be smaller or equal to max_mtu.
4606  * Note: If port type is Infiniband, then port must be disabled, when its
4607  * MTU is set.
4608  * Access: RW
4609  */
4610 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
4611 
4612 /* reg_pmtu_oper_mtu
4613  * The actual MTU configured on the port. Packets exceeding this size
4614  * will be dropped.
4615  * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
4616  * oper_mtu might be smaller than admin_mtu.
4617  * Access: RO
4618  */
4619 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
4620 
4621 static inline void mlxsw_reg_pmtu_pack(char *payload, u16 local_port,
4622 				       u16 new_mtu)
4623 {
4624 	MLXSW_REG_ZERO(pmtu, payload);
4625 	mlxsw_reg_pmtu_local_port_set(payload, local_port);
4626 	mlxsw_reg_pmtu_max_mtu_set(payload, 0);
4627 	mlxsw_reg_pmtu_admin_mtu_set(payload, new_mtu);
4628 	mlxsw_reg_pmtu_oper_mtu_set(payload, 0);
4629 }
4630 
4631 /* PTYS - Port Type and Speed Register
4632  * -----------------------------------
4633  * Configures and reports the port speed type.
4634  *
4635  * Note: When set while the link is up, the changes will not take effect
4636  * until the port transitions from down to up state.
4637  */
4638 #define MLXSW_REG_PTYS_ID 0x5004
4639 #define MLXSW_REG_PTYS_LEN 0x40
4640 
4641 MLXSW_REG_DEFINE(ptys, MLXSW_REG_PTYS_ID, MLXSW_REG_PTYS_LEN);
4642 
4643 /* an_disable_admin
4644  * Auto negotiation disable administrative configuration
4645  * 0 - Device doesn't support AN disable.
4646  * 1 - Device supports AN disable.
4647  * Access: RW
4648  */
4649 MLXSW_ITEM32(reg, ptys, an_disable_admin, 0x00, 30, 1);
4650 
4651 /* reg_ptys_local_port
4652  * Local port number.
4653  * Access: Index
4654  */
4655 MLXSW_ITEM32_LP(reg, ptys, 0x00, 16, 0x00, 12);
4656 
4657 #define MLXSW_REG_PTYS_PROTO_MASK_IB	BIT(0)
4658 #define MLXSW_REG_PTYS_PROTO_MASK_ETH	BIT(2)
4659 
4660 /* reg_ptys_proto_mask
4661  * Protocol mask. Indicates which protocol is used.
4662  * 0 - Infiniband.
4663  * 1 - Fibre Channel.
4664  * 2 - Ethernet.
4665  * Access: Index
4666  */
4667 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
4668 
4669 enum {
4670 	MLXSW_REG_PTYS_AN_STATUS_NA,
4671 	MLXSW_REG_PTYS_AN_STATUS_OK,
4672 	MLXSW_REG_PTYS_AN_STATUS_FAIL,
4673 };
4674 
4675 /* reg_ptys_an_status
4676  * Autonegotiation status.
4677  * Access: RO
4678  */
4679 MLXSW_ITEM32(reg, ptys, an_status, 0x04, 28, 4);
4680 
4681 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_SGMII_100M				BIT(0)
4682 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_1000BASE_X_SGMII			BIT(1)
4683 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_5GBASE_R				BIT(3)
4684 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_XFI_XAUI_1_10G			BIT(4)
4685 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_XLAUI_4_XLPPI_4_40G		BIT(5)
4686 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_25GAUI_1_25GBASE_CR_KR		BIT(6)
4687 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_50GAUI_2_LAUI_2_50GBASE_CR2_KR2	BIT(7)
4688 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_50GAUI_1_LAUI_1_50GBASE_CR_KR	BIT(8)
4689 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_CAUI_4_100GBASE_CR4_KR4		BIT(9)
4690 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_100GAUI_2_100GBASE_CR2_KR2		BIT(10)
4691 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_200GAUI_4_200GBASE_CR4_KR4		BIT(12)
4692 #define MLXSW_REG_PTYS_EXT_ETH_SPEED_400GAUI_8				BIT(15)
4693 
4694 /* reg_ptys_ext_eth_proto_cap
4695  * Extended Ethernet port supported speeds and protocols.
4696  * Access: RO
4697  */
4698 MLXSW_ITEM32(reg, ptys, ext_eth_proto_cap, 0x08, 0, 32);
4699 
4700 #define MLXSW_REG_PTYS_ETH_SPEED_SGMII			BIT(0)
4701 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX		BIT(1)
4702 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4		BIT(2)
4703 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4		BIT(3)
4704 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR		BIT(4)
4705 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4		BIT(6)
4706 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4		BIT(7)
4707 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR		BIT(12)
4708 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR		BIT(13)
4709 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR		BIT(14)
4710 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4		BIT(15)
4711 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4	BIT(16)
4712 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_SR2		BIT(18)
4713 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR4		BIT(19)
4714 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4		BIT(20)
4715 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4		BIT(21)
4716 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4		BIT(22)
4717 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4	BIT(23)
4718 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_T		BIT(24)
4719 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_T		BIT(25)
4720 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR		BIT(27)
4721 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR		BIT(28)
4722 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR		BIT(29)
4723 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2		BIT(30)
4724 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2		BIT(31)
4725 
4726 /* reg_ptys_eth_proto_cap
4727  * Ethernet port supported speeds and protocols.
4728  * Access: RO
4729  */
4730 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
4731 
4732 /* reg_ptys_ext_eth_proto_admin
4733  * Extended speed and protocol to set port to.
4734  * Access: RW
4735  */
4736 MLXSW_ITEM32(reg, ptys, ext_eth_proto_admin, 0x14, 0, 32);
4737 
4738 /* reg_ptys_eth_proto_admin
4739  * Speed and protocol to set port to.
4740  * Access: RW
4741  */
4742 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
4743 
4744 /* reg_ptys_ext_eth_proto_oper
4745  * The extended current speed and protocol configured for the port.
4746  * Access: RO
4747  */
4748 MLXSW_ITEM32(reg, ptys, ext_eth_proto_oper, 0x20, 0, 32);
4749 
4750 /* reg_ptys_eth_proto_oper
4751  * The current speed and protocol configured for the port.
4752  * Access: RO
4753  */
4754 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
4755 
4756 enum mlxsw_reg_ptys_connector_type {
4757 	MLXSW_REG_PTYS_CONNECTOR_TYPE_UNKNOWN_OR_NO_CONNECTOR,
4758 	MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_NONE,
4759 	MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_TP,
4760 	MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_AUI,
4761 	MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_BNC,
4762 	MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_MII,
4763 	MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_FIBRE,
4764 	MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_DA,
4765 	MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_OTHER,
4766 };
4767 
4768 /* reg_ptys_connector_type
4769  * Connector type indication.
4770  * Access: RO
4771  */
4772 MLXSW_ITEM32(reg, ptys, connector_type, 0x2C, 0, 4);
4773 
4774 static inline void mlxsw_reg_ptys_eth_pack(char *payload, u16 local_port,
4775 					   u32 proto_admin, bool autoneg)
4776 {
4777 	MLXSW_REG_ZERO(ptys, payload);
4778 	mlxsw_reg_ptys_local_port_set(payload, local_port);
4779 	mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
4780 	mlxsw_reg_ptys_eth_proto_admin_set(payload, proto_admin);
4781 	mlxsw_reg_ptys_an_disable_admin_set(payload, !autoneg);
4782 }
4783 
4784 static inline void mlxsw_reg_ptys_ext_eth_pack(char *payload, u16 local_port,
4785 					       u32 proto_admin, bool autoneg)
4786 {
4787 	MLXSW_REG_ZERO(ptys, payload);
4788 	mlxsw_reg_ptys_local_port_set(payload, local_port);
4789 	mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
4790 	mlxsw_reg_ptys_ext_eth_proto_admin_set(payload, proto_admin);
4791 	mlxsw_reg_ptys_an_disable_admin_set(payload, !autoneg);
4792 }
4793 
4794 static inline void mlxsw_reg_ptys_eth_unpack(char *payload,
4795 					     u32 *p_eth_proto_cap,
4796 					     u32 *p_eth_proto_admin,
4797 					     u32 *p_eth_proto_oper)
4798 {
4799 	if (p_eth_proto_cap)
4800 		*p_eth_proto_cap =
4801 			mlxsw_reg_ptys_eth_proto_cap_get(payload);
4802 	if (p_eth_proto_admin)
4803 		*p_eth_proto_admin =
4804 			mlxsw_reg_ptys_eth_proto_admin_get(payload);
4805 	if (p_eth_proto_oper)
4806 		*p_eth_proto_oper =
4807 			mlxsw_reg_ptys_eth_proto_oper_get(payload);
4808 }
4809 
4810 static inline void mlxsw_reg_ptys_ext_eth_unpack(char *payload,
4811 						 u32 *p_eth_proto_cap,
4812 						 u32 *p_eth_proto_admin,
4813 						 u32 *p_eth_proto_oper)
4814 {
4815 	if (p_eth_proto_cap)
4816 		*p_eth_proto_cap =
4817 			mlxsw_reg_ptys_ext_eth_proto_cap_get(payload);
4818 	if (p_eth_proto_admin)
4819 		*p_eth_proto_admin =
4820 			mlxsw_reg_ptys_ext_eth_proto_admin_get(payload);
4821 	if (p_eth_proto_oper)
4822 		*p_eth_proto_oper =
4823 			mlxsw_reg_ptys_ext_eth_proto_oper_get(payload);
4824 }
4825 
4826 /* PPAD - Port Physical Address Register
4827  * -------------------------------------
4828  * The PPAD register configures the per port physical MAC address.
4829  */
4830 #define MLXSW_REG_PPAD_ID 0x5005
4831 #define MLXSW_REG_PPAD_LEN 0x10
4832 
4833 MLXSW_REG_DEFINE(ppad, MLXSW_REG_PPAD_ID, MLXSW_REG_PPAD_LEN);
4834 
4835 /* reg_ppad_single_base_mac
4836  * 0: base_mac, local port should be 0 and mac[7:0] is
4837  * reserved. HW will set incremental
4838  * 1: single_mac - mac of the local_port
4839  * Access: RW
4840  */
4841 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
4842 
4843 /* reg_ppad_local_port
4844  * port number, if single_base_mac = 0 then local_port is reserved
4845  * Access: RW
4846  */
4847 MLXSW_ITEM32_LP(reg, ppad, 0x00, 16, 0x00, 24);
4848 
4849 /* reg_ppad_mac
4850  * If single_base_mac = 0 - base MAC address, mac[7:0] is reserved.
4851  * If single_base_mac = 1 - the per port MAC address
4852  * Access: RW
4853  */
4854 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
4855 
4856 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
4857 				       u16 local_port)
4858 {
4859 	MLXSW_REG_ZERO(ppad, payload);
4860 	mlxsw_reg_ppad_single_base_mac_set(payload, !!single_base_mac);
4861 	mlxsw_reg_ppad_local_port_set(payload, local_port);
4862 }
4863 
4864 /* PAOS - Ports Administrative and Operational Status Register
4865  * -----------------------------------------------------------
4866  * Configures and retrieves per port administrative and operational status.
4867  */
4868 #define MLXSW_REG_PAOS_ID 0x5006
4869 #define MLXSW_REG_PAOS_LEN 0x10
4870 
4871 MLXSW_REG_DEFINE(paos, MLXSW_REG_PAOS_ID, MLXSW_REG_PAOS_LEN);
4872 
4873 /* reg_paos_swid
4874  * Switch partition ID with which to associate the port.
4875  * Note: while external ports uses unique local port numbers (and thus swid is
4876  * redundant), router ports use the same local port number where swid is the
4877  * only indication for the relevant port.
4878  * Access: Index
4879  */
4880 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
4881 
4882 /* reg_paos_local_port
4883  * Local port number.
4884  * Access: Index
4885  */
4886 MLXSW_ITEM32_LP(reg, paos, 0x00, 16, 0x00, 12);
4887 
4888 /* reg_paos_admin_status
4889  * Port administrative state (the desired state of the port):
4890  * 1 - Up.
4891  * 2 - Down.
4892  * 3 - Up once. This means that in case of link failure, the port won't go
4893  *     into polling mode, but will wait to be re-enabled by software.
4894  * 4 - Disabled by system. Can only be set by hardware.
4895  * Access: RW
4896  */
4897 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
4898 
4899 /* reg_paos_oper_status
4900  * Port operational state (the current state):
4901  * 1 - Up.
4902  * 2 - Down.
4903  * 3 - Down by port failure. This means that the device will not let the
4904  *     port up again until explicitly specified by software.
4905  * Access: RO
4906  */
4907 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
4908 
4909 /* reg_paos_ase
4910  * Admin state update enabled.
4911  * Access: WO
4912  */
4913 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
4914 
4915 /* reg_paos_ee
4916  * Event update enable. If this bit is set, event generation will be
4917  * updated based on the e field.
4918  * Access: WO
4919  */
4920 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
4921 
4922 /* reg_paos_e
4923  * Event generation on operational state change:
4924  * 0 - Do not generate event.
4925  * 1 - Generate Event.
4926  * 2 - Generate Single Event.
4927  * Access: RW
4928  */
4929 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
4930 
4931 static inline void mlxsw_reg_paos_pack(char *payload, u16 local_port,
4932 				       enum mlxsw_port_admin_status status)
4933 {
4934 	MLXSW_REG_ZERO(paos, payload);
4935 	mlxsw_reg_paos_swid_set(payload, 0);
4936 	mlxsw_reg_paos_local_port_set(payload, local_port);
4937 	mlxsw_reg_paos_admin_status_set(payload, status);
4938 	mlxsw_reg_paos_oper_status_set(payload, 0);
4939 	mlxsw_reg_paos_ase_set(payload, 1);
4940 	mlxsw_reg_paos_ee_set(payload, 1);
4941 	mlxsw_reg_paos_e_set(payload, 1);
4942 }
4943 
4944 /* PFCC - Ports Flow Control Configuration Register
4945  * ------------------------------------------------
4946  * Configures and retrieves the per port flow control configuration.
4947  */
4948 #define MLXSW_REG_PFCC_ID 0x5007
4949 #define MLXSW_REG_PFCC_LEN 0x20
4950 
4951 MLXSW_REG_DEFINE(pfcc, MLXSW_REG_PFCC_ID, MLXSW_REG_PFCC_LEN);
4952 
4953 /* reg_pfcc_local_port
4954  * Local port number.
4955  * Access: Index
4956  */
4957 MLXSW_ITEM32_LP(reg, pfcc, 0x00, 16, 0x00, 12);
4958 
4959 /* reg_pfcc_pnat
4960  * Port number access type. Determines the way local_port is interpreted:
4961  * 0 - Local port number.
4962  * 1 - IB / label port number.
4963  * Access: Index
4964  */
4965 MLXSW_ITEM32(reg, pfcc, pnat, 0x00, 14, 2);
4966 
4967 /* reg_pfcc_shl_cap
4968  * Send to higher layers capabilities:
4969  * 0 - No capability of sending Pause and PFC frames to higher layers.
4970  * 1 - Device has capability of sending Pause and PFC frames to higher
4971  *     layers.
4972  * Access: RO
4973  */
4974 MLXSW_ITEM32(reg, pfcc, shl_cap, 0x00, 1, 1);
4975 
4976 /* reg_pfcc_shl_opr
4977  * Send to higher layers operation:
4978  * 0 - Pause and PFC frames are handled by the port (default).
4979  * 1 - Pause and PFC frames are handled by the port and also sent to
4980  *     higher layers. Only valid if shl_cap = 1.
4981  * Access: RW
4982  */
4983 MLXSW_ITEM32(reg, pfcc, shl_opr, 0x00, 0, 1);
4984 
4985 /* reg_pfcc_ppan
4986  * Pause policy auto negotiation.
4987  * 0 - Disabled. Generate / ignore Pause frames based on pptx / pprtx.
4988  * 1 - Enabled. When auto-negotiation is performed, set the Pause policy
4989  *     based on the auto-negotiation resolution.
4990  * Access: RW
4991  *
4992  * Note: The auto-negotiation advertisement is set according to pptx and
4993  * pprtx. When PFC is set on Tx / Rx, ppan must be set to 0.
4994  */
4995 MLXSW_ITEM32(reg, pfcc, ppan, 0x04, 28, 4);
4996 
4997 /* reg_pfcc_prio_mask_tx
4998  * Bit per priority indicating if Tx flow control policy should be
4999  * updated based on bit pfctx.
5000  * Access: WO
5001  */
5002 MLXSW_ITEM32(reg, pfcc, prio_mask_tx, 0x04, 16, 8);
5003 
5004 /* reg_pfcc_prio_mask_rx
5005  * Bit per priority indicating if Rx flow control policy should be
5006  * updated based on bit pfcrx.
5007  * Access: WO
5008  */
5009 MLXSW_ITEM32(reg, pfcc, prio_mask_rx, 0x04, 0, 8);
5010 
5011 /* reg_pfcc_pptx
5012  * Admin Pause policy on Tx.
5013  * 0 - Never generate Pause frames (default).
5014  * 1 - Generate Pause frames according to Rx buffer threshold.
5015  * Access: RW
5016  */
5017 MLXSW_ITEM32(reg, pfcc, pptx, 0x08, 31, 1);
5018 
5019 /* reg_pfcc_aptx
5020  * Active (operational) Pause policy on Tx.
5021  * 0 - Never generate Pause frames.
5022  * 1 - Generate Pause frames according to Rx buffer threshold.
5023  * Access: RO
5024  */
5025 MLXSW_ITEM32(reg, pfcc, aptx, 0x08, 30, 1);
5026 
5027 /* reg_pfcc_pfctx
5028  * Priority based flow control policy on Tx[7:0]. Per-priority bit mask:
5029  * 0 - Never generate priority Pause frames on the specified priority
5030  *     (default).
5031  * 1 - Generate priority Pause frames according to Rx buffer threshold on
5032  *     the specified priority.
5033  * Access: RW
5034  *
5035  * Note: pfctx and pptx must be mutually exclusive.
5036  */
5037 MLXSW_ITEM32(reg, pfcc, pfctx, 0x08, 16, 8);
5038 
5039 /* reg_pfcc_pprx
5040  * Admin Pause policy on Rx.
5041  * 0 - Ignore received Pause frames (default).
5042  * 1 - Respect received Pause frames.
5043  * Access: RW
5044  */
5045 MLXSW_ITEM32(reg, pfcc, pprx, 0x0C, 31, 1);
5046 
5047 /* reg_pfcc_aprx
5048  * Active (operational) Pause policy on Rx.
5049  * 0 - Ignore received Pause frames.
5050  * 1 - Respect received Pause frames.
5051  * Access: RO
5052  */
5053 MLXSW_ITEM32(reg, pfcc, aprx, 0x0C, 30, 1);
5054 
5055 /* reg_pfcc_pfcrx
5056  * Priority based flow control policy on Rx[7:0]. Per-priority bit mask:
5057  * 0 - Ignore incoming priority Pause frames on the specified priority
5058  *     (default).
5059  * 1 - Respect incoming priority Pause frames on the specified priority.
5060  * Access: RW
5061  */
5062 MLXSW_ITEM32(reg, pfcc, pfcrx, 0x0C, 16, 8);
5063 
5064 #define MLXSW_REG_PFCC_ALL_PRIO 0xFF
5065 
5066 static inline void mlxsw_reg_pfcc_prio_pack(char *payload, u8 pfc_en)
5067 {
5068 	mlxsw_reg_pfcc_prio_mask_tx_set(payload, MLXSW_REG_PFCC_ALL_PRIO);
5069 	mlxsw_reg_pfcc_prio_mask_rx_set(payload, MLXSW_REG_PFCC_ALL_PRIO);
5070 	mlxsw_reg_pfcc_pfctx_set(payload, pfc_en);
5071 	mlxsw_reg_pfcc_pfcrx_set(payload, pfc_en);
5072 }
5073 
5074 static inline void mlxsw_reg_pfcc_pack(char *payload, u16 local_port)
5075 {
5076 	MLXSW_REG_ZERO(pfcc, payload);
5077 	mlxsw_reg_pfcc_local_port_set(payload, local_port);
5078 }
5079 
5080 /* PPCNT - Ports Performance Counters Register
5081  * -------------------------------------------
5082  * The PPCNT register retrieves per port performance counters.
5083  */
5084 #define MLXSW_REG_PPCNT_ID 0x5008
5085 #define MLXSW_REG_PPCNT_LEN 0x100
5086 #define MLXSW_REG_PPCNT_COUNTERS_OFFSET 0x08
5087 
5088 MLXSW_REG_DEFINE(ppcnt, MLXSW_REG_PPCNT_ID, MLXSW_REG_PPCNT_LEN);
5089 
5090 /* reg_ppcnt_swid
5091  * For HCA: must be always 0.
5092  * Switch partition ID to associate port with.
5093  * Switch partitions are numbered from 0 to 7 inclusively.
5094  * Switch partition 254 indicates stacking ports.
5095  * Switch partition 255 indicates all switch partitions.
5096  * Only valid on Set() operation with local_port=255.
5097  * Access: Index
5098  */
5099 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
5100 
5101 /* reg_ppcnt_local_port
5102  * Local port number.
5103  * Access: Index
5104  */
5105 MLXSW_ITEM32_LP(reg, ppcnt, 0x00, 16, 0x00, 12);
5106 
5107 /* reg_ppcnt_pnat
5108  * Port number access type:
5109  * 0 - Local port number
5110  * 1 - IB port number
5111  * Access: Index
5112  */
5113 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
5114 
5115 enum mlxsw_reg_ppcnt_grp {
5116 	MLXSW_REG_PPCNT_IEEE_8023_CNT = 0x0,
5117 	MLXSW_REG_PPCNT_RFC_2863_CNT = 0x1,
5118 	MLXSW_REG_PPCNT_RFC_2819_CNT = 0x2,
5119 	MLXSW_REG_PPCNT_RFC_3635_CNT = 0x3,
5120 	MLXSW_REG_PPCNT_EXT_CNT = 0x5,
5121 	MLXSW_REG_PPCNT_DISCARD_CNT = 0x6,
5122 	MLXSW_REG_PPCNT_PRIO_CNT = 0x10,
5123 	MLXSW_REG_PPCNT_TC_CNT = 0x11,
5124 	MLXSW_REG_PPCNT_TC_CONG_CNT = 0x13,
5125 };
5126 
5127 /* reg_ppcnt_grp
5128  * Performance counter group.
5129  * Group 63 indicates all groups. Only valid on Set() operation with
5130  * clr bit set.
5131  * 0x0: IEEE 802.3 Counters
5132  * 0x1: RFC 2863 Counters
5133  * 0x2: RFC 2819 Counters
5134  * 0x3: RFC 3635 Counters
5135  * 0x5: Ethernet Extended Counters
5136  * 0x6: Ethernet Discard Counters
5137  * 0x8: Link Level Retransmission Counters
5138  * 0x10: Per Priority Counters
5139  * 0x11: Per Traffic Class Counters
5140  * 0x12: Physical Layer Counters
5141  * 0x13: Per Traffic Class Congestion Counters
5142  * Access: Index
5143  */
5144 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
5145 
5146 /* reg_ppcnt_clr
5147  * Clear counters. Setting the clr bit will reset the counter value
5148  * for all counters in the counter group. This bit can be set
5149  * for both Set() and Get() operation.
5150  * Access: OP
5151  */
5152 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
5153 
5154 /* reg_ppcnt_lp_gl
5155  * Local port global variable.
5156  * 0: local_port 255 = all ports of the device.
5157  * 1: local_port indicates local port number for all ports.
5158  * Access: OP
5159  */
5160 MLXSW_ITEM32(reg, ppcnt, lp_gl, 0x04, 30, 1);
5161 
5162 /* reg_ppcnt_prio_tc
5163  * Priority for counter set that support per priority, valid values: 0-7.
5164  * Traffic class for counter set that support per traffic class,
5165  * valid values: 0- cap_max_tclass-1 .
5166  * For HCA: cap_max_tclass is always 8.
5167  * Otherwise must be 0.
5168  * Access: Index
5169  */
5170 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
5171 
5172 /* Ethernet IEEE 802.3 Counter Group */
5173 
5174 /* reg_ppcnt_a_frames_transmitted_ok
5175  * Access: RO
5176  */
5177 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
5178 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x00, 0, 64);
5179 
5180 /* reg_ppcnt_a_frames_received_ok
5181  * Access: RO
5182  */
5183 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
5184 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x08, 0, 64);
5185 
5186 /* reg_ppcnt_a_frame_check_sequence_errors
5187  * Access: RO
5188  */
5189 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
5190 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x10, 0, 64);
5191 
5192 /* reg_ppcnt_a_alignment_errors
5193  * Access: RO
5194  */
5195 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
5196 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x18, 0, 64);
5197 
5198 /* reg_ppcnt_a_octets_transmitted_ok
5199  * Access: RO
5200  */
5201 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
5202 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x20, 0, 64);
5203 
5204 /* reg_ppcnt_a_octets_received_ok
5205  * Access: RO
5206  */
5207 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
5208 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x28, 0, 64);
5209 
5210 /* reg_ppcnt_a_multicast_frames_xmitted_ok
5211  * Access: RO
5212  */
5213 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
5214 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x30, 0, 64);
5215 
5216 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
5217  * Access: RO
5218  */
5219 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
5220 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x38, 0, 64);
5221 
5222 /* reg_ppcnt_a_multicast_frames_received_ok
5223  * Access: RO
5224  */
5225 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
5226 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x40, 0, 64);
5227 
5228 /* reg_ppcnt_a_broadcast_frames_received_ok
5229  * Access: RO
5230  */
5231 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
5232 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x48, 0, 64);
5233 
5234 /* reg_ppcnt_a_in_range_length_errors
5235  * Access: RO
5236  */
5237 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
5238 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x50, 0, 64);
5239 
5240 /* reg_ppcnt_a_out_of_range_length_field
5241  * Access: RO
5242  */
5243 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
5244 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x58, 0, 64);
5245 
5246 /* reg_ppcnt_a_frame_too_long_errors
5247  * Access: RO
5248  */
5249 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
5250 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x60, 0, 64);
5251 
5252 /* reg_ppcnt_a_symbol_error_during_carrier
5253  * Access: RO
5254  */
5255 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
5256 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x68, 0, 64);
5257 
5258 /* reg_ppcnt_a_mac_control_frames_transmitted
5259  * Access: RO
5260  */
5261 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
5262 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x70, 0, 64);
5263 
5264 /* reg_ppcnt_a_mac_control_frames_received
5265  * Access: RO
5266  */
5267 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
5268 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x78, 0, 64);
5269 
5270 /* reg_ppcnt_a_unsupported_opcodes_received
5271  * Access: RO
5272  */
5273 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
5274 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x80, 0, 64);
5275 
5276 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
5277  * Access: RO
5278  */
5279 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
5280 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x88, 0, 64);
5281 
5282 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
5283  * Access: RO
5284  */
5285 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
5286 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x90, 0, 64);
5287 
5288 /* Ethernet RFC 2863 Counter Group */
5289 
5290 /* reg_ppcnt_if_in_discards
5291  * Access: RO
5292  */
5293 MLXSW_ITEM64(reg, ppcnt, if_in_discards,
5294 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x10, 0, 64);
5295 
5296 /* reg_ppcnt_if_out_discards
5297  * Access: RO
5298  */
5299 MLXSW_ITEM64(reg, ppcnt, if_out_discards,
5300 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x38, 0, 64);
5301 
5302 /* reg_ppcnt_if_out_errors
5303  * Access: RO
5304  */
5305 MLXSW_ITEM64(reg, ppcnt, if_out_errors,
5306 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x40, 0, 64);
5307 
5308 /* Ethernet RFC 2819 Counter Group */
5309 
5310 /* reg_ppcnt_ether_stats_undersize_pkts
5311  * Access: RO
5312  */
5313 MLXSW_ITEM64(reg, ppcnt, ether_stats_undersize_pkts,
5314 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x30, 0, 64);
5315 
5316 /* reg_ppcnt_ether_stats_oversize_pkts
5317  * Access: RO
5318  */
5319 MLXSW_ITEM64(reg, ppcnt, ether_stats_oversize_pkts,
5320 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x38, 0, 64);
5321 
5322 /* reg_ppcnt_ether_stats_fragments
5323  * Access: RO
5324  */
5325 MLXSW_ITEM64(reg, ppcnt, ether_stats_fragments,
5326 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x40, 0, 64);
5327 
5328 /* reg_ppcnt_ether_stats_pkts64octets
5329  * Access: RO
5330  */
5331 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts64octets,
5332 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x58, 0, 64);
5333 
5334 /* reg_ppcnt_ether_stats_pkts65to127octets
5335  * Access: RO
5336  */
5337 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts65to127octets,
5338 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x60, 0, 64);
5339 
5340 /* reg_ppcnt_ether_stats_pkts128to255octets
5341  * Access: RO
5342  */
5343 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts128to255octets,
5344 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x68, 0, 64);
5345 
5346 /* reg_ppcnt_ether_stats_pkts256to511octets
5347  * Access: RO
5348  */
5349 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts256to511octets,
5350 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x70, 0, 64);
5351 
5352 /* reg_ppcnt_ether_stats_pkts512to1023octets
5353  * Access: RO
5354  */
5355 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts512to1023octets,
5356 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x78, 0, 64);
5357 
5358 /* reg_ppcnt_ether_stats_pkts1024to1518octets
5359  * Access: RO
5360  */
5361 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts1024to1518octets,
5362 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x80, 0, 64);
5363 
5364 /* reg_ppcnt_ether_stats_pkts1519to2047octets
5365  * Access: RO
5366  */
5367 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts1519to2047octets,
5368 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x88, 0, 64);
5369 
5370 /* reg_ppcnt_ether_stats_pkts2048to4095octets
5371  * Access: RO
5372  */
5373 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts2048to4095octets,
5374 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x90, 0, 64);
5375 
5376 /* reg_ppcnt_ether_stats_pkts4096to8191octets
5377  * Access: RO
5378  */
5379 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts4096to8191octets,
5380 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x98, 0, 64);
5381 
5382 /* reg_ppcnt_ether_stats_pkts8192to10239octets
5383  * Access: RO
5384  */
5385 MLXSW_ITEM64(reg, ppcnt, ether_stats_pkts8192to10239octets,
5386 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0xA0, 0, 64);
5387 
5388 /* Ethernet RFC 3635 Counter Group */
5389 
5390 /* reg_ppcnt_dot3stats_fcs_errors
5391  * Access: RO
5392  */
5393 MLXSW_ITEM64(reg, ppcnt, dot3stats_fcs_errors,
5394 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x08, 0, 64);
5395 
5396 /* reg_ppcnt_dot3stats_symbol_errors
5397  * Access: RO
5398  */
5399 MLXSW_ITEM64(reg, ppcnt, dot3stats_symbol_errors,
5400 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x60, 0, 64);
5401 
5402 /* reg_ppcnt_dot3control_in_unknown_opcodes
5403  * Access: RO
5404  */
5405 MLXSW_ITEM64(reg, ppcnt, dot3control_in_unknown_opcodes,
5406 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x68, 0, 64);
5407 
5408 /* reg_ppcnt_dot3in_pause_frames
5409  * Access: RO
5410  */
5411 MLXSW_ITEM64(reg, ppcnt, dot3in_pause_frames,
5412 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x70, 0, 64);
5413 
5414 /* Ethernet Extended Counter Group Counters */
5415 
5416 /* reg_ppcnt_ecn_marked
5417  * Access: RO
5418  */
5419 MLXSW_ITEM64(reg, ppcnt, ecn_marked,
5420 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x08, 0, 64);
5421 
5422 /* Ethernet Discard Counter Group Counters */
5423 
5424 /* reg_ppcnt_ingress_general
5425  * Access: RO
5426  */
5427 MLXSW_ITEM64(reg, ppcnt, ingress_general,
5428 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x00, 0, 64);
5429 
5430 /* reg_ppcnt_ingress_policy_engine
5431  * Access: RO
5432  */
5433 MLXSW_ITEM64(reg, ppcnt, ingress_policy_engine,
5434 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x08, 0, 64);
5435 
5436 /* reg_ppcnt_ingress_vlan_membership
5437  * Access: RO
5438  */
5439 MLXSW_ITEM64(reg, ppcnt, ingress_vlan_membership,
5440 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x10, 0, 64);
5441 
5442 /* reg_ppcnt_ingress_tag_frame_type
5443  * Access: RO
5444  */
5445 MLXSW_ITEM64(reg, ppcnt, ingress_tag_frame_type,
5446 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x18, 0, 64);
5447 
5448 /* reg_ppcnt_egress_vlan_membership
5449  * Access: RO
5450  */
5451 MLXSW_ITEM64(reg, ppcnt, egress_vlan_membership,
5452 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x20, 0, 64);
5453 
5454 /* reg_ppcnt_loopback_filter
5455  * Access: RO
5456  */
5457 MLXSW_ITEM64(reg, ppcnt, loopback_filter,
5458 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x28, 0, 64);
5459 
5460 /* reg_ppcnt_egress_general
5461  * Access: RO
5462  */
5463 MLXSW_ITEM64(reg, ppcnt, egress_general,
5464 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x30, 0, 64);
5465 
5466 /* reg_ppcnt_egress_hoq
5467  * Access: RO
5468  */
5469 MLXSW_ITEM64(reg, ppcnt, egress_hoq,
5470 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x40, 0, 64);
5471 
5472 /* reg_ppcnt_egress_policy_engine
5473  * Access: RO
5474  */
5475 MLXSW_ITEM64(reg, ppcnt, egress_policy_engine,
5476 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x50, 0, 64);
5477 
5478 /* reg_ppcnt_ingress_tx_link_down
5479  * Access: RO
5480  */
5481 MLXSW_ITEM64(reg, ppcnt, ingress_tx_link_down,
5482 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x58, 0, 64);
5483 
5484 /* reg_ppcnt_egress_stp_filter
5485  * Access: RO
5486  */
5487 MLXSW_ITEM64(reg, ppcnt, egress_stp_filter,
5488 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x60, 0, 64);
5489 
5490 /* reg_ppcnt_egress_sll
5491  * Access: RO
5492  */
5493 MLXSW_ITEM64(reg, ppcnt, egress_sll,
5494 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x70, 0, 64);
5495 
5496 /* Ethernet Per Priority Group Counters */
5497 
5498 /* reg_ppcnt_rx_octets
5499  * Access: RO
5500  */
5501 MLXSW_ITEM64(reg, ppcnt, rx_octets,
5502 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x00, 0, 64);
5503 
5504 /* reg_ppcnt_rx_frames
5505  * Access: RO
5506  */
5507 MLXSW_ITEM64(reg, ppcnt, rx_frames,
5508 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x20, 0, 64);
5509 
5510 /* reg_ppcnt_tx_octets
5511  * Access: RO
5512  */
5513 MLXSW_ITEM64(reg, ppcnt, tx_octets,
5514 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x28, 0, 64);
5515 
5516 /* reg_ppcnt_tx_frames
5517  * Access: RO
5518  */
5519 MLXSW_ITEM64(reg, ppcnt, tx_frames,
5520 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x48, 0, 64);
5521 
5522 /* reg_ppcnt_rx_pause
5523  * Access: RO
5524  */
5525 MLXSW_ITEM64(reg, ppcnt, rx_pause,
5526 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x50, 0, 64);
5527 
5528 /* reg_ppcnt_rx_pause_duration
5529  * Access: RO
5530  */
5531 MLXSW_ITEM64(reg, ppcnt, rx_pause_duration,
5532 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x58, 0, 64);
5533 
5534 /* reg_ppcnt_tx_pause
5535  * Access: RO
5536  */
5537 MLXSW_ITEM64(reg, ppcnt, tx_pause,
5538 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x60, 0, 64);
5539 
5540 /* reg_ppcnt_tx_pause_duration
5541  * Access: RO
5542  */
5543 MLXSW_ITEM64(reg, ppcnt, tx_pause_duration,
5544 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x68, 0, 64);
5545 
5546 /* reg_ppcnt_rx_pause_transition
5547  * Access: RO
5548  */
5549 MLXSW_ITEM64(reg, ppcnt, tx_pause_transition,
5550 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x70, 0, 64);
5551 
5552 /* Ethernet Per Traffic Class Counters */
5553 
5554 /* reg_ppcnt_tc_transmit_queue
5555  * Contains the transmit queue depth in cells of traffic class
5556  * selected by prio_tc and the port selected by local_port.
5557  * The field cannot be cleared.
5558  * Access: RO
5559  */
5560 MLXSW_ITEM64(reg, ppcnt, tc_transmit_queue,
5561 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x00, 0, 64);
5562 
5563 /* reg_ppcnt_tc_no_buffer_discard_uc
5564  * The number of unicast packets dropped due to lack of shared
5565  * buffer resources.
5566  * Access: RO
5567  */
5568 MLXSW_ITEM64(reg, ppcnt, tc_no_buffer_discard_uc,
5569 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x08, 0, 64);
5570 
5571 /* Ethernet Per Traffic Class Congestion Group Counters */
5572 
5573 /* reg_ppcnt_wred_discard
5574  * Access: RO
5575  */
5576 MLXSW_ITEM64(reg, ppcnt, wred_discard,
5577 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x00, 0, 64);
5578 
5579 /* reg_ppcnt_ecn_marked_tc
5580  * Access: RO
5581  */
5582 MLXSW_ITEM64(reg, ppcnt, ecn_marked_tc,
5583 	     MLXSW_REG_PPCNT_COUNTERS_OFFSET + 0x08, 0, 64);
5584 
5585 static inline void mlxsw_reg_ppcnt_pack(char *payload, u16 local_port,
5586 					enum mlxsw_reg_ppcnt_grp grp,
5587 					u8 prio_tc)
5588 {
5589 	MLXSW_REG_ZERO(ppcnt, payload);
5590 	mlxsw_reg_ppcnt_swid_set(payload, 0);
5591 	mlxsw_reg_ppcnt_local_port_set(payload, local_port);
5592 	mlxsw_reg_ppcnt_pnat_set(payload, 0);
5593 	mlxsw_reg_ppcnt_grp_set(payload, grp);
5594 	mlxsw_reg_ppcnt_clr_set(payload, 0);
5595 	mlxsw_reg_ppcnt_lp_gl_set(payload, 1);
5596 	mlxsw_reg_ppcnt_prio_tc_set(payload, prio_tc);
5597 }
5598 
5599 /* PPTB - Port Prio To Buffer Register
5600  * -----------------------------------
5601  * Configures the switch priority to buffer table.
5602  */
5603 #define MLXSW_REG_PPTB_ID 0x500B
5604 #define MLXSW_REG_PPTB_LEN 0x10
5605 
5606 MLXSW_REG_DEFINE(pptb, MLXSW_REG_PPTB_ID, MLXSW_REG_PPTB_LEN);
5607 
5608 enum {
5609 	MLXSW_REG_PPTB_MM_UM,
5610 	MLXSW_REG_PPTB_MM_UNICAST,
5611 	MLXSW_REG_PPTB_MM_MULTICAST,
5612 };
5613 
5614 /* reg_pptb_mm
5615  * Mapping mode.
5616  * 0 - Map both unicast and multicast packets to the same buffer.
5617  * 1 - Map only unicast packets.
5618  * 2 - Map only multicast packets.
5619  * Access: Index
5620  *
5621  * Note: SwitchX-2 only supports the first option.
5622  */
5623 MLXSW_ITEM32(reg, pptb, mm, 0x00, 28, 2);
5624 
5625 /* reg_pptb_local_port
5626  * Local port number.
5627  * Access: Index
5628  */
5629 MLXSW_ITEM32_LP(reg, pptb, 0x00, 16, 0x00, 12);
5630 
5631 /* reg_pptb_um
5632  * Enables the update of the untagged_buf field.
5633  * Access: RW
5634  */
5635 MLXSW_ITEM32(reg, pptb, um, 0x00, 8, 1);
5636 
5637 /* reg_pptb_pm
5638  * Enables the update of the prio_to_buff field.
5639  * Bit <i> is a flag for updating the mapping for switch priority <i>.
5640  * Access: RW
5641  */
5642 MLXSW_ITEM32(reg, pptb, pm, 0x00, 0, 8);
5643 
5644 /* reg_pptb_prio_to_buff
5645  * Mapping of switch priority <i> to one of the allocated receive port
5646  * buffers.
5647  * Access: RW
5648  */
5649 MLXSW_ITEM_BIT_ARRAY(reg, pptb, prio_to_buff, 0x04, 0x04, 4);
5650 
5651 /* reg_pptb_pm_msb
5652  * Enables the update of the prio_to_buff field.
5653  * Bit <i> is a flag for updating the mapping for switch priority <i+8>.
5654  * Access: RW
5655  */
5656 MLXSW_ITEM32(reg, pptb, pm_msb, 0x08, 24, 8);
5657 
5658 /* reg_pptb_untagged_buff
5659  * Mapping of untagged frames to one of the allocated receive port buffers.
5660  * Access: RW
5661  *
5662  * Note: In SwitchX-2 this field must be mapped to buffer 8. Reserved for
5663  * Spectrum, as it maps untagged packets based on the default switch priority.
5664  */
5665 MLXSW_ITEM32(reg, pptb, untagged_buff, 0x08, 0, 4);
5666 
5667 /* reg_pptb_prio_to_buff_msb
5668  * Mapping of switch priority <i+8> to one of the allocated receive port
5669  * buffers.
5670  * Access: RW
5671  */
5672 MLXSW_ITEM_BIT_ARRAY(reg, pptb, prio_to_buff_msb, 0x0C, 0x04, 4);
5673 
5674 #define MLXSW_REG_PPTB_ALL_PRIO 0xFF
5675 
5676 static inline void mlxsw_reg_pptb_pack(char *payload, u16 local_port)
5677 {
5678 	MLXSW_REG_ZERO(pptb, payload);
5679 	mlxsw_reg_pptb_mm_set(payload, MLXSW_REG_PPTB_MM_UM);
5680 	mlxsw_reg_pptb_local_port_set(payload, local_port);
5681 	mlxsw_reg_pptb_pm_set(payload, MLXSW_REG_PPTB_ALL_PRIO);
5682 	mlxsw_reg_pptb_pm_msb_set(payload, MLXSW_REG_PPTB_ALL_PRIO);
5683 }
5684 
5685 static inline void mlxsw_reg_pptb_prio_to_buff_pack(char *payload, u8 prio,
5686 						    u8 buff)
5687 {
5688 	mlxsw_reg_pptb_prio_to_buff_set(payload, prio, buff);
5689 	mlxsw_reg_pptb_prio_to_buff_msb_set(payload, prio, buff);
5690 }
5691 
5692 /* PBMC - Port Buffer Management Control Register
5693  * ----------------------------------------------
5694  * The PBMC register configures and retrieves the port packet buffer
5695  * allocation for different Prios, and the Pause threshold management.
5696  */
5697 #define MLXSW_REG_PBMC_ID 0x500C
5698 #define MLXSW_REG_PBMC_LEN 0x6C
5699 
5700 MLXSW_REG_DEFINE(pbmc, MLXSW_REG_PBMC_ID, MLXSW_REG_PBMC_LEN);
5701 
5702 /* reg_pbmc_local_port
5703  * Local port number.
5704  * Access: Index
5705  */
5706 MLXSW_ITEM32_LP(reg, pbmc, 0x00, 16, 0x00, 12);
5707 
5708 /* reg_pbmc_xoff_timer_value
5709  * When device generates a pause frame, it uses this value as the pause
5710  * timer (time for the peer port to pause in quota-512 bit time).
5711  * Access: RW
5712  */
5713 MLXSW_ITEM32(reg, pbmc, xoff_timer_value, 0x04, 16, 16);
5714 
5715 /* reg_pbmc_xoff_refresh
5716  * The time before a new pause frame should be sent to refresh the pause RW
5717  * state. Using the same units as xoff_timer_value above (in quota-512 bit
5718  * time).
5719  * Access: RW
5720  */
5721 MLXSW_ITEM32(reg, pbmc, xoff_refresh, 0x04, 0, 16);
5722 
5723 #define MLXSW_REG_PBMC_PORT_SHARED_BUF_IDX 11
5724 
5725 /* reg_pbmc_buf_lossy
5726  * The field indicates if the buffer is lossy.
5727  * 0 - Lossless
5728  * 1 - Lossy
5729  * Access: RW
5730  */
5731 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_lossy, 0x0C, 25, 1, 0x08, 0x00, false);
5732 
5733 /* reg_pbmc_buf_epsb
5734  * Eligible for Port Shared buffer.
5735  * If epsb is set, packets assigned to buffer are allowed to insert the port
5736  * shared buffer.
5737  * When buf_lossy is MLXSW_REG_PBMC_LOSSY_LOSSY this field is reserved.
5738  * Access: RW
5739  */
5740 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_epsb, 0x0C, 24, 1, 0x08, 0x00, false);
5741 
5742 /* reg_pbmc_buf_size
5743  * The part of the packet buffer array is allocated for the specific buffer.
5744  * Units are represented in cells.
5745  * Access: RW
5746  */
5747 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_size, 0x0C, 0, 16, 0x08, 0x00, false);
5748 
5749 /* reg_pbmc_buf_xoff_threshold
5750  * Once the amount of data in the buffer goes above this value, device
5751  * starts sending PFC frames for all priorities associated with the
5752  * buffer. Units are represented in cells. Reserved in case of lossy
5753  * buffer.
5754  * Access: RW
5755  *
5756  * Note: In Spectrum, reserved for buffer[9].
5757  */
5758 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_xoff_threshold, 0x0C, 16, 16,
5759 		     0x08, 0x04, false);
5760 
5761 /* reg_pbmc_buf_xon_threshold
5762  * When the amount of data in the buffer goes below this value, device
5763  * stops sending PFC frames for the priorities associated with the
5764  * buffer. Units are represented in cells. Reserved in case of lossy
5765  * buffer.
5766  * Access: RW
5767  *
5768  * Note: In Spectrum, reserved for buffer[9].
5769  */
5770 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_xon_threshold, 0x0C, 0, 16,
5771 		     0x08, 0x04, false);
5772 
5773 static inline void mlxsw_reg_pbmc_pack(char *payload, u16 local_port,
5774 				       u16 xoff_timer_value, u16 xoff_refresh)
5775 {
5776 	MLXSW_REG_ZERO(pbmc, payload);
5777 	mlxsw_reg_pbmc_local_port_set(payload, local_port);
5778 	mlxsw_reg_pbmc_xoff_timer_value_set(payload, xoff_timer_value);
5779 	mlxsw_reg_pbmc_xoff_refresh_set(payload, xoff_refresh);
5780 }
5781 
5782 static inline void mlxsw_reg_pbmc_lossy_buffer_pack(char *payload,
5783 						    int buf_index,
5784 						    u16 size)
5785 {
5786 	mlxsw_reg_pbmc_buf_lossy_set(payload, buf_index, 1);
5787 	mlxsw_reg_pbmc_buf_epsb_set(payload, buf_index, 0);
5788 	mlxsw_reg_pbmc_buf_size_set(payload, buf_index, size);
5789 }
5790 
5791 static inline void mlxsw_reg_pbmc_lossless_buffer_pack(char *payload,
5792 						       int buf_index, u16 size,
5793 						       u16 threshold)
5794 {
5795 	mlxsw_reg_pbmc_buf_lossy_set(payload, buf_index, 0);
5796 	mlxsw_reg_pbmc_buf_epsb_set(payload, buf_index, 0);
5797 	mlxsw_reg_pbmc_buf_size_set(payload, buf_index, size);
5798 	mlxsw_reg_pbmc_buf_xoff_threshold_set(payload, buf_index, threshold);
5799 	mlxsw_reg_pbmc_buf_xon_threshold_set(payload, buf_index, threshold);
5800 }
5801 
5802 /* PSPA - Port Switch Partition Allocation
5803  * ---------------------------------------
5804  * Controls the association of a port with a switch partition and enables
5805  * configuring ports as stacking ports.
5806  */
5807 #define MLXSW_REG_PSPA_ID 0x500D
5808 #define MLXSW_REG_PSPA_LEN 0x8
5809 
5810 MLXSW_REG_DEFINE(pspa, MLXSW_REG_PSPA_ID, MLXSW_REG_PSPA_LEN);
5811 
5812 /* reg_pspa_swid
5813  * Switch partition ID.
5814  * Access: RW
5815  */
5816 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
5817 
5818 /* reg_pspa_local_port
5819  * Local port number.
5820  * Access: Index
5821  */
5822 MLXSW_ITEM32_LP(reg, pspa, 0x00, 16, 0x00, 0);
5823 
5824 /* reg_pspa_sub_port
5825  * Virtual port within the local port. Set to 0 when virtual ports are
5826  * disabled on the local port.
5827  * Access: Index
5828  */
5829 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
5830 
5831 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u16 local_port)
5832 {
5833 	MLXSW_REG_ZERO(pspa, payload);
5834 	mlxsw_reg_pspa_swid_set(payload, swid);
5835 	mlxsw_reg_pspa_local_port_set(payload, local_port);
5836 	mlxsw_reg_pspa_sub_port_set(payload, 0);
5837 }
5838 
5839 /* PMAOS - Ports Module Administrative and Operational Status
5840  * ----------------------------------------------------------
5841  * This register configures and retrieves the per module status.
5842  */
5843 #define MLXSW_REG_PMAOS_ID 0x5012
5844 #define MLXSW_REG_PMAOS_LEN 0x10
5845 
5846 MLXSW_REG_DEFINE(pmaos, MLXSW_REG_PMAOS_ID, MLXSW_REG_PMAOS_LEN);
5847 
5848 /* reg_pmaos_rst
5849  * Module reset toggle.
5850  * Note: Setting reset while module is plugged-in will result in transition to
5851  * "initializing" operational state.
5852  * Access: OP
5853  */
5854 MLXSW_ITEM32(reg, pmaos, rst, 0x00, 31, 1);
5855 
5856 /* reg_pmaos_slot_index
5857  * Slot index.
5858  * Access: Index
5859  */
5860 MLXSW_ITEM32(reg, pmaos, slot_index, 0x00, 24, 4);
5861 
5862 /* reg_pmaos_module
5863  * Module number.
5864  * Access: Index
5865  */
5866 MLXSW_ITEM32(reg, pmaos, module, 0x00, 16, 8);
5867 
5868 enum mlxsw_reg_pmaos_admin_status {
5869 	MLXSW_REG_PMAOS_ADMIN_STATUS_ENABLED = 1,
5870 	MLXSW_REG_PMAOS_ADMIN_STATUS_DISABLED = 2,
5871 	/* If the module is active and then unplugged, or experienced an error
5872 	 * event, the operational status should go to "disabled" and can only
5873 	 * be enabled upon explicit enable command.
5874 	 */
5875 	MLXSW_REG_PMAOS_ADMIN_STATUS_ENABLED_ONCE = 3,
5876 };
5877 
5878 /* reg_pmaos_admin_status
5879  * Module administrative state (the desired state of the module).
5880  * Note: To disable a module, all ports associated with the port must be
5881  * administatively down first.
5882  * Access: RW
5883  */
5884 MLXSW_ITEM32(reg, pmaos, admin_status, 0x00, 8, 4);
5885 
5886 /* reg_pmaos_ase
5887  * Admin state update enable.
5888  * If this bit is set, admin state will be updated based on admin_state field.
5889  * Only relevant on Set() operations.
5890  * Access: WO
5891  */
5892 MLXSW_ITEM32(reg, pmaos, ase, 0x04, 31, 1);
5893 
5894 /* reg_pmaos_ee
5895  * Event update enable.
5896  * If this bit is set, event generation will be updated based on the e field.
5897  * Only relevant on Set operations.
5898  * Access: WO
5899  */
5900 MLXSW_ITEM32(reg, pmaos, ee, 0x04, 30, 1);
5901 
5902 enum mlxsw_reg_pmaos_e {
5903 	MLXSW_REG_PMAOS_E_DO_NOT_GENERATE_EVENT,
5904 	MLXSW_REG_PMAOS_E_GENERATE_EVENT,
5905 	MLXSW_REG_PMAOS_E_GENERATE_SINGLE_EVENT,
5906 };
5907 
5908 /* reg_pmaos_e
5909  * Event Generation on operational state change.
5910  * Access: RW
5911  */
5912 MLXSW_ITEM32(reg, pmaos, e, 0x04, 0, 2);
5913 
5914 static inline void mlxsw_reg_pmaos_pack(char *payload, u8 slot_index, u8 module)
5915 {
5916 	MLXSW_REG_ZERO(pmaos, payload);
5917 	mlxsw_reg_pmaos_slot_index_set(payload, slot_index);
5918 	mlxsw_reg_pmaos_module_set(payload, module);
5919 }
5920 
5921 /* PPLR - Port Physical Loopback Register
5922  * --------------------------------------
5923  * This register allows configuration of the port's loopback mode.
5924  */
5925 #define MLXSW_REG_PPLR_ID 0x5018
5926 #define MLXSW_REG_PPLR_LEN 0x8
5927 
5928 MLXSW_REG_DEFINE(pplr, MLXSW_REG_PPLR_ID, MLXSW_REG_PPLR_LEN);
5929 
5930 /* reg_pplr_local_port
5931  * Local port number.
5932  * Access: Index
5933  */
5934 MLXSW_ITEM32_LP(reg, pplr, 0x00, 16, 0x00, 12);
5935 
5936 /* Phy local loopback. When set the port's egress traffic is looped back
5937  * to the receiver and the port transmitter is disabled.
5938  */
5939 #define MLXSW_REG_PPLR_LB_TYPE_BIT_PHY_LOCAL BIT(1)
5940 
5941 /* reg_pplr_lb_en
5942  * Loopback enable.
5943  * Access: RW
5944  */
5945 MLXSW_ITEM32(reg, pplr, lb_en, 0x04, 0, 8);
5946 
5947 static inline void mlxsw_reg_pplr_pack(char *payload, u16 local_port,
5948 				       bool phy_local)
5949 {
5950 	MLXSW_REG_ZERO(pplr, payload);
5951 	mlxsw_reg_pplr_local_port_set(payload, local_port);
5952 	mlxsw_reg_pplr_lb_en_set(payload,
5953 				 phy_local ?
5954 				 MLXSW_REG_PPLR_LB_TYPE_BIT_PHY_LOCAL : 0);
5955 }
5956 
5957 /* PMTDB - Port Module To local DataBase Register
5958  * ----------------------------------------------
5959  * The PMTDB register allows to query the possible module<->local port
5960  * mapping than can be used in PMLP. It does not represent the actual/current
5961  * mapping of the local to module. Actual mapping is only defined by PMLP.
5962  */
5963 #define MLXSW_REG_PMTDB_ID 0x501A
5964 #define MLXSW_REG_PMTDB_LEN 0x40
5965 
5966 MLXSW_REG_DEFINE(pmtdb, MLXSW_REG_PMTDB_ID, MLXSW_REG_PMTDB_LEN);
5967 
5968 /* reg_pmtdb_slot_index
5969  * Slot index (0: Main board).
5970  * Access: Index
5971  */
5972 MLXSW_ITEM32(reg, pmtdb, slot_index, 0x00, 24, 4);
5973 
5974 /* reg_pmtdb_module
5975  * Module number.
5976  * Access: Index
5977  */
5978 MLXSW_ITEM32(reg, pmtdb, module, 0x00, 16, 8);
5979 
5980 /* reg_pmtdb_ports_width
5981  * Port's width
5982  * Access: Index
5983  */
5984 MLXSW_ITEM32(reg, pmtdb, ports_width, 0x00, 12, 4);
5985 
5986 /* reg_pmtdb_num_ports
5987  * Number of ports in a single module (split/breakout)
5988  * Access: Index
5989  */
5990 MLXSW_ITEM32(reg, pmtdb, num_ports, 0x00, 8, 4);
5991 
5992 enum mlxsw_reg_pmtdb_status {
5993 	MLXSW_REG_PMTDB_STATUS_SUCCESS,
5994 };
5995 
5996 /* reg_pmtdb_status
5997  * Status
5998  * Access: RO
5999  */
6000 MLXSW_ITEM32(reg, pmtdb, status, 0x00, 0, 4);
6001 
6002 /* reg_pmtdb_port_num
6003  * The local_port value which can be assigned to the module.
6004  * In case of more than one port, port<x> represent the /<x> port of
6005  * the module.
6006  * Access: RO
6007  */
6008 MLXSW_ITEM16_INDEXED(reg, pmtdb, port_num, 0x04, 0, 10, 0x02, 0x00, false);
6009 
6010 static inline void mlxsw_reg_pmtdb_pack(char *payload, u8 slot_index, u8 module,
6011 					u8 ports_width, u8 num_ports)
6012 {
6013 	MLXSW_REG_ZERO(pmtdb, payload);
6014 	mlxsw_reg_pmtdb_slot_index_set(payload, slot_index);
6015 	mlxsw_reg_pmtdb_module_set(payload, module);
6016 	mlxsw_reg_pmtdb_ports_width_set(payload, ports_width);
6017 	mlxsw_reg_pmtdb_num_ports_set(payload, num_ports);
6018 }
6019 
6020 /* PMECR - Ports Mapping Event Configuration Register
6021  * --------------------------------------------------
6022  * The PMECR register is used to enable/disable event triggering
6023  * in case of local port mapping change.
6024  */
6025 #define MLXSW_REG_PMECR_ID 0x501B
6026 #define MLXSW_REG_PMECR_LEN 0x20
6027 
6028 MLXSW_REG_DEFINE(pmecr, MLXSW_REG_PMECR_ID, MLXSW_REG_PMECR_LEN);
6029 
6030 /* reg_pmecr_local_port
6031  * Local port number.
6032  * Access: Index
6033  */
6034 MLXSW_ITEM32_LP(reg, pmecr, 0x00, 16, 0x00, 12);
6035 
6036 /* reg_pmecr_ee
6037  * Event update enable. If this bit is set, event generation will be updated
6038  * based on the e field. Only relevant on Set operations.
6039  * Access: WO
6040  */
6041 MLXSW_ITEM32(reg, pmecr, ee, 0x04, 30, 1);
6042 
6043 /* reg_pmecr_eswi
6044  * Software ignore enable bit. If this bit is set, the value of swi is used.
6045  * If this bit is clear, the value of swi is ignored.
6046  * Only relevant on Set operations.
6047  * Access: WO
6048  */
6049 MLXSW_ITEM32(reg, pmecr, eswi, 0x04, 24, 1);
6050 
6051 /* reg_pmecr_swi
6052  * Software ignore. If this bit is set, the device shouldn't generate events
6053  * in case of PMLP SET operation but only upon self local port mapping change
6054  * (if applicable according to e configuration). This is supplementary
6055  * configuration on top of e value.
6056  * Access: RW
6057  */
6058 MLXSW_ITEM32(reg, pmecr, swi, 0x04, 8, 1);
6059 
6060 enum mlxsw_reg_pmecr_e {
6061 	MLXSW_REG_PMECR_E_DO_NOT_GENERATE_EVENT,
6062 	MLXSW_REG_PMECR_E_GENERATE_EVENT,
6063 	MLXSW_REG_PMECR_E_GENERATE_SINGLE_EVENT,
6064 };
6065 
6066 /* reg_pmecr_e
6067  * Event generation on local port mapping change.
6068  * Access: RW
6069  */
6070 MLXSW_ITEM32(reg, pmecr, e, 0x04, 0, 2);
6071 
6072 static inline void mlxsw_reg_pmecr_pack(char *payload, u16 local_port,
6073 					enum mlxsw_reg_pmecr_e e)
6074 {
6075 	MLXSW_REG_ZERO(pmecr, payload);
6076 	mlxsw_reg_pmecr_local_port_set(payload, local_port);
6077 	mlxsw_reg_pmecr_e_set(payload, e);
6078 	mlxsw_reg_pmecr_ee_set(payload, true);
6079 	mlxsw_reg_pmecr_swi_set(payload, true);
6080 	mlxsw_reg_pmecr_eswi_set(payload, true);
6081 }
6082 
6083 /* PMPE - Port Module Plug/Unplug Event Register
6084  * ---------------------------------------------
6085  * This register reports any operational status change of a module.
6086  * A change in the module’s state will generate an event only if the change
6087  * happens after arming the event mechanism. Any changes to the module state
6088  * while the event mechanism is not armed will not be reported. Software can
6089  * query the PMPE register for module status.
6090  */
6091 #define MLXSW_REG_PMPE_ID 0x5024
6092 #define MLXSW_REG_PMPE_LEN 0x10
6093 
6094 MLXSW_REG_DEFINE(pmpe, MLXSW_REG_PMPE_ID, MLXSW_REG_PMPE_LEN);
6095 
6096 /* reg_pmpe_slot_index
6097  * Slot index.
6098  * Access: Index
6099  */
6100 MLXSW_ITEM32(reg, pmpe, slot_index, 0x00, 24, 4);
6101 
6102 /* reg_pmpe_module
6103  * Module number.
6104  * Access: Index
6105  */
6106 MLXSW_ITEM32(reg, pmpe, module, 0x00, 16, 8);
6107 
6108 enum mlxsw_reg_pmpe_module_status {
6109 	MLXSW_REG_PMPE_MODULE_STATUS_PLUGGED_ENABLED = 1,
6110 	MLXSW_REG_PMPE_MODULE_STATUS_UNPLUGGED,
6111 	MLXSW_REG_PMPE_MODULE_STATUS_PLUGGED_ERROR,
6112 	MLXSW_REG_PMPE_MODULE_STATUS_PLUGGED_DISABLED,
6113 };
6114 
6115 /* reg_pmpe_module_status
6116  * Module status.
6117  * Access: RO
6118  */
6119 MLXSW_ITEM32(reg, pmpe, module_status, 0x00, 0, 4);
6120 
6121 /* reg_pmpe_error_type
6122  * Module error details.
6123  * Access: RO
6124  */
6125 MLXSW_ITEM32(reg, pmpe, error_type, 0x04, 8, 4);
6126 
6127 /* PDDR - Port Diagnostics Database Register
6128  * -----------------------------------------
6129  * The PDDR enables to read the Phy debug database
6130  */
6131 #define MLXSW_REG_PDDR_ID 0x5031
6132 #define MLXSW_REG_PDDR_LEN 0x100
6133 
6134 MLXSW_REG_DEFINE(pddr, MLXSW_REG_PDDR_ID, MLXSW_REG_PDDR_LEN);
6135 
6136 /* reg_pddr_local_port
6137  * Local port number.
6138  * Access: Index
6139  */
6140 MLXSW_ITEM32_LP(reg, pddr, 0x00, 16, 0x00, 12);
6141 
6142 enum mlxsw_reg_pddr_page_select {
6143 	MLXSW_REG_PDDR_PAGE_SELECT_TROUBLESHOOTING_INFO = 1,
6144 };
6145 
6146 /* reg_pddr_page_select
6147  * Page select index.
6148  * Access: Index
6149  */
6150 MLXSW_ITEM32(reg, pddr, page_select, 0x04, 0, 8);
6151 
6152 enum mlxsw_reg_pddr_trblsh_group_opcode {
6153 	/* Monitor opcodes */
6154 	MLXSW_REG_PDDR_TRBLSH_GROUP_OPCODE_MONITOR,
6155 };
6156 
6157 /* reg_pddr_group_opcode
6158  * Group selector.
6159  * Access: Index
6160  */
6161 MLXSW_ITEM32(reg, pddr, trblsh_group_opcode, 0x08, 0, 16);
6162 
6163 /* reg_pddr_status_opcode
6164  * Group selector.
6165  * Access: RO
6166  */
6167 MLXSW_ITEM32(reg, pddr, trblsh_status_opcode, 0x0C, 0, 16);
6168 
6169 static inline void mlxsw_reg_pddr_pack(char *payload, u16 local_port,
6170 				       u8 page_select)
6171 {
6172 	MLXSW_REG_ZERO(pddr, payload);
6173 	mlxsw_reg_pddr_local_port_set(payload, local_port);
6174 	mlxsw_reg_pddr_page_select_set(payload, page_select);
6175 }
6176 
6177 /* PMMP - Port Module Memory Map Properties Register
6178  * -------------------------------------------------
6179  * The PMMP register allows to override the module memory map advertisement.
6180  * The register can only be set when the module is disabled by PMAOS register.
6181  */
6182 #define MLXSW_REG_PMMP_ID 0x5044
6183 #define MLXSW_REG_PMMP_LEN 0x2C
6184 
6185 MLXSW_REG_DEFINE(pmmp, MLXSW_REG_PMMP_ID, MLXSW_REG_PMMP_LEN);
6186 
6187 /* reg_pmmp_module
6188  * Module number.
6189  * Access: Index
6190  */
6191 MLXSW_ITEM32(reg, pmmp, module, 0x00, 16, 8);
6192 
6193 /* reg_pmmp_slot_index
6194  * Slot index.
6195  * Access: Index
6196  */
6197 MLXSW_ITEM32(reg, pmmp, slot_index, 0x00, 24, 4);
6198 
6199 /* reg_pmmp_sticky
6200  * When set, will keep eeprom_override values after plug-out event.
6201  * Access: OP
6202  */
6203 MLXSW_ITEM32(reg, pmmp, sticky, 0x00, 0, 1);
6204 
6205 /* reg_pmmp_eeprom_override_mask
6206  * Write mask bit (negative polarity).
6207  * 0 - Allow write
6208  * 1 - Ignore write
6209  * On write, indicates which of the bits from eeprom_override field are
6210  * updated.
6211  * Access: WO
6212  */
6213 MLXSW_ITEM32(reg, pmmp, eeprom_override_mask, 0x04, 16, 16);
6214 
6215 enum {
6216 	/* Set module to low power mode */
6217 	MLXSW_REG_PMMP_EEPROM_OVERRIDE_LOW_POWER_MASK = BIT(8),
6218 };
6219 
6220 /* reg_pmmp_eeprom_override
6221  * Override / ignore EEPROM advertisement properties bitmask
6222  * Access: RW
6223  */
6224 MLXSW_ITEM32(reg, pmmp, eeprom_override, 0x04, 0, 16);
6225 
6226 static inline void mlxsw_reg_pmmp_pack(char *payload, u8 slot_index, u8 module)
6227 {
6228 	MLXSW_REG_ZERO(pmmp, payload);
6229 	mlxsw_reg_pmmp_slot_index_set(payload, slot_index);
6230 	mlxsw_reg_pmmp_module_set(payload, module);
6231 }
6232 
6233 /* PLLP - Port Local port to Label Port mapping Register
6234  * -----------------------------------------------------
6235  * The PLLP register returns the mapping from Local Port into Label Port.
6236  */
6237 #define MLXSW_REG_PLLP_ID 0x504A
6238 #define MLXSW_REG_PLLP_LEN 0x10
6239 
6240 MLXSW_REG_DEFINE(pllp, MLXSW_REG_PLLP_ID, MLXSW_REG_PLLP_LEN);
6241 
6242 /* reg_pllp_local_port
6243  * Local port number.
6244  * Access: Index
6245  */
6246 MLXSW_ITEM32_LP(reg, pllp, 0x00, 16, 0x00, 12);
6247 
6248 /* reg_pllp_label_port
6249  * Front panel label of the port.
6250  * Access: RO
6251  */
6252 MLXSW_ITEM32(reg, pllp, label_port, 0x00, 0, 8);
6253 
6254 /* reg_pllp_split_num
6255  * Label split mapping for local_port.
6256  * Access: RO
6257  */
6258 MLXSW_ITEM32(reg, pllp, split_num, 0x04, 0, 4);
6259 
6260 /* reg_pllp_slot_index
6261  * Slot index (0: Main board).
6262  * Access: RO
6263  */
6264 MLXSW_ITEM32(reg, pllp, slot_index, 0x08, 0, 4);
6265 
6266 static inline void mlxsw_reg_pllp_pack(char *payload, u16 local_port)
6267 {
6268 	MLXSW_REG_ZERO(pllp, payload);
6269 	mlxsw_reg_pllp_local_port_set(payload, local_port);
6270 }
6271 
6272 static inline void mlxsw_reg_pllp_unpack(char *payload, u8 *label_port,
6273 					 u8 *split_num, u8 *slot_index)
6274 {
6275 	*label_port = mlxsw_reg_pllp_label_port_get(payload);
6276 	*split_num = mlxsw_reg_pllp_split_num_get(payload);
6277 	*slot_index = mlxsw_reg_pllp_slot_index_get(payload);
6278 }
6279 
6280 /* PMTM - Port Module Type Mapping Register
6281  * ----------------------------------------
6282  * The PMTM register allows query or configuration of module types.
6283  * The register can only be set when the module is disabled by PMAOS register
6284  */
6285 #define MLXSW_REG_PMTM_ID 0x5067
6286 #define MLXSW_REG_PMTM_LEN 0x10
6287 
6288 MLXSW_REG_DEFINE(pmtm, MLXSW_REG_PMTM_ID, MLXSW_REG_PMTM_LEN);
6289 
6290 /* reg_pmtm_slot_index
6291  * Slot index.
6292  * Access: Index
6293  */
6294 MLXSW_ITEM32(reg, pmtm, slot_index, 0x00, 24, 4);
6295 
6296 /* reg_pmtm_module
6297  * Module number.
6298  * Access: Index
6299  */
6300 MLXSW_ITEM32(reg, pmtm, module, 0x00, 16, 8);
6301 
6302 enum mlxsw_reg_pmtm_module_type {
6303 	MLXSW_REG_PMTM_MODULE_TYPE_BACKPLANE_4_LANES = 0,
6304 	MLXSW_REG_PMTM_MODULE_TYPE_QSFP = 1,
6305 	MLXSW_REG_PMTM_MODULE_TYPE_SFP = 2,
6306 	MLXSW_REG_PMTM_MODULE_TYPE_BACKPLANE_SINGLE_LANE = 4,
6307 	MLXSW_REG_PMTM_MODULE_TYPE_BACKPLANE_2_LANES = 8,
6308 	MLXSW_REG_PMTM_MODULE_TYPE_CHIP2CHIP4X = 10,
6309 	MLXSW_REG_PMTM_MODULE_TYPE_CHIP2CHIP2X = 11,
6310 	MLXSW_REG_PMTM_MODULE_TYPE_CHIP2CHIP1X = 12,
6311 	MLXSW_REG_PMTM_MODULE_TYPE_QSFP_DD = 14,
6312 	MLXSW_REG_PMTM_MODULE_TYPE_OSFP = 15,
6313 	MLXSW_REG_PMTM_MODULE_TYPE_SFP_DD = 16,
6314 	MLXSW_REG_PMTM_MODULE_TYPE_DSFP = 17,
6315 	MLXSW_REG_PMTM_MODULE_TYPE_CHIP2CHIP8X = 18,
6316 	MLXSW_REG_PMTM_MODULE_TYPE_TWISTED_PAIR = 19,
6317 };
6318 
6319 /* reg_pmtm_module_type
6320  * Module type.
6321  * Access: RW
6322  */
6323 MLXSW_ITEM32(reg, pmtm, module_type, 0x04, 0, 5);
6324 
6325 static inline void mlxsw_reg_pmtm_pack(char *payload, u8 slot_index, u8 module)
6326 {
6327 	MLXSW_REG_ZERO(pmtm, payload);
6328 	mlxsw_reg_pmtm_slot_index_set(payload, slot_index);
6329 	mlxsw_reg_pmtm_module_set(payload, module);
6330 }
6331 
6332 /* HTGT - Host Trap Group Table
6333  * ----------------------------
6334  * Configures the properties for forwarding to CPU.
6335  */
6336 #define MLXSW_REG_HTGT_ID 0x7002
6337 #define MLXSW_REG_HTGT_LEN 0x20
6338 
6339 MLXSW_REG_DEFINE(htgt, MLXSW_REG_HTGT_ID, MLXSW_REG_HTGT_LEN);
6340 
6341 /* reg_htgt_swid
6342  * Switch partition ID.
6343  * Access: Index
6344  */
6345 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
6346 
6347 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0	/* For locally attached CPU */
6348 
6349 /* reg_htgt_type
6350  * CPU path type.
6351  * Access: RW
6352  */
6353 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
6354 
6355 enum mlxsw_reg_htgt_trap_group {
6356 	MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
6357 	MLXSW_REG_HTGT_TRAP_GROUP_CORE_EVENT,
6358 	MLXSW_REG_HTGT_TRAP_GROUP_SP_STP,
6359 	MLXSW_REG_HTGT_TRAP_GROUP_SP_LACP,
6360 	MLXSW_REG_HTGT_TRAP_GROUP_SP_LLDP,
6361 	MLXSW_REG_HTGT_TRAP_GROUP_SP_MC_SNOOPING,
6362 	MLXSW_REG_HTGT_TRAP_GROUP_SP_BGP,
6363 	MLXSW_REG_HTGT_TRAP_GROUP_SP_OSPF,
6364 	MLXSW_REG_HTGT_TRAP_GROUP_SP_PIM,
6365 	MLXSW_REG_HTGT_TRAP_GROUP_SP_MULTICAST,
6366 	MLXSW_REG_HTGT_TRAP_GROUP_SP_NEIGH_DISCOVERY,
6367 	MLXSW_REG_HTGT_TRAP_GROUP_SP_ROUTER_EXP,
6368 	MLXSW_REG_HTGT_TRAP_GROUP_SP_EXTERNAL_ROUTE,
6369 	MLXSW_REG_HTGT_TRAP_GROUP_SP_IP2ME,
6370 	MLXSW_REG_HTGT_TRAP_GROUP_SP_DHCP,
6371 	MLXSW_REG_HTGT_TRAP_GROUP_SP_EVENT,
6372 	MLXSW_REG_HTGT_TRAP_GROUP_SP_IPV6,
6373 	MLXSW_REG_HTGT_TRAP_GROUP_SP_LBERROR,
6374 	MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP0,
6375 	MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP1,
6376 	MLXSW_REG_HTGT_TRAP_GROUP_SP_VRRP,
6377 	MLXSW_REG_HTGT_TRAP_GROUP_SP_PKT_SAMPLE,
6378 	MLXSW_REG_HTGT_TRAP_GROUP_SP_FLOW_LOGGING,
6379 	MLXSW_REG_HTGT_TRAP_GROUP_SP_FID_MISS,
6380 	MLXSW_REG_HTGT_TRAP_GROUP_SP_BFD,
6381 	MLXSW_REG_HTGT_TRAP_GROUP_SP_DUMMY,
6382 	MLXSW_REG_HTGT_TRAP_GROUP_SP_L2_DISCARDS,
6383 	MLXSW_REG_HTGT_TRAP_GROUP_SP_L3_DISCARDS,
6384 	MLXSW_REG_HTGT_TRAP_GROUP_SP_L3_EXCEPTIONS,
6385 	MLXSW_REG_HTGT_TRAP_GROUP_SP_TUNNEL_DISCARDS,
6386 	MLXSW_REG_HTGT_TRAP_GROUP_SP_ACL_DISCARDS,
6387 	MLXSW_REG_HTGT_TRAP_GROUP_SP_BUFFER_DISCARDS,
6388 
6389 	__MLXSW_REG_HTGT_TRAP_GROUP_MAX,
6390 	MLXSW_REG_HTGT_TRAP_GROUP_MAX = __MLXSW_REG_HTGT_TRAP_GROUP_MAX - 1
6391 };
6392 
6393 /* reg_htgt_trap_group
6394  * Trap group number. User defined number specifying which trap groups
6395  * should be forwarded to the CPU. The mapping between trap IDs and trap
6396  * groups is configured using HPKT register.
6397  * Access: Index
6398  */
6399 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
6400 
6401 enum {
6402 	MLXSW_REG_HTGT_POLICER_DISABLE,
6403 	MLXSW_REG_HTGT_POLICER_ENABLE,
6404 };
6405 
6406 /* reg_htgt_pide
6407  * Enable policer ID specified using 'pid' field.
6408  * Access: RW
6409  */
6410 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
6411 
6412 #define MLXSW_REG_HTGT_INVALID_POLICER 0xff
6413 
6414 /* reg_htgt_pid
6415  * Policer ID for the trap group.
6416  * Access: RW
6417  */
6418 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
6419 
6420 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
6421 
6422 /* reg_htgt_mirror_action
6423  * Mirror action to use.
6424  * 0 - Trap to CPU.
6425  * 1 - Trap to CPU and mirror to a mirroring agent.
6426  * 2 - Mirror to a mirroring agent and do not trap to CPU.
6427  * Access: RW
6428  *
6429  * Note: Mirroring to a mirroring agent is only supported in Spectrum.
6430  */
6431 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
6432 
6433 /* reg_htgt_mirroring_agent
6434  * Mirroring agent.
6435  * Access: RW
6436  */
6437 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
6438 
6439 #define MLXSW_REG_HTGT_DEFAULT_PRIORITY 0
6440 
6441 /* reg_htgt_priority
6442  * Trap group priority.
6443  * In case a packet matches multiple classification rules, the packet will
6444  * only be trapped once, based on the trap ID associated with the group (via
6445  * register HPKT) with the highest priority.
6446  * Supported values are 0-7, with 7 represnting the highest priority.
6447  * Access: RW
6448  *
6449  * Note: In SwitchX-2 this field is ignored and the priority value is replaced
6450  * by the 'trap_group' field.
6451  */
6452 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
6453 
6454 #define MLXSW_REG_HTGT_DEFAULT_TC 7
6455 
6456 /* reg_htgt_local_path_cpu_tclass
6457  * CPU ingress traffic class for the trap group.
6458  * Access: RW
6459  */
6460 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
6461 
6462 enum mlxsw_reg_htgt_local_path_rdq {
6463 	MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_CTRL = 0x13,
6464 	MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_RX = 0x14,
6465 	MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_EMAD = 0x15,
6466 	MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SIB_EMAD = 0x15,
6467 };
6468 /* reg_htgt_local_path_rdq
6469  * Receive descriptor queue (RDQ) to use for the trap group.
6470  * Access: RW
6471  */
6472 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
6473 
6474 static inline void mlxsw_reg_htgt_pack(char *payload, u8 group, u8 policer_id,
6475 				       u8 priority, u8 tc)
6476 {
6477 	MLXSW_REG_ZERO(htgt, payload);
6478 
6479 	if (policer_id == MLXSW_REG_HTGT_INVALID_POLICER) {
6480 		mlxsw_reg_htgt_pide_set(payload,
6481 					MLXSW_REG_HTGT_POLICER_DISABLE);
6482 	} else {
6483 		mlxsw_reg_htgt_pide_set(payload,
6484 					MLXSW_REG_HTGT_POLICER_ENABLE);
6485 		mlxsw_reg_htgt_pid_set(payload, policer_id);
6486 	}
6487 
6488 	mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
6489 	mlxsw_reg_htgt_trap_group_set(payload, group);
6490 	mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
6491 	mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
6492 	mlxsw_reg_htgt_priority_set(payload, priority);
6493 	mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, tc);
6494 	mlxsw_reg_htgt_local_path_rdq_set(payload, group);
6495 }
6496 
6497 /* HPKT - Host Packet Trap
6498  * -----------------------
6499  * Configures trap IDs inside trap groups.
6500  */
6501 #define MLXSW_REG_HPKT_ID 0x7003
6502 #define MLXSW_REG_HPKT_LEN 0x10
6503 
6504 MLXSW_REG_DEFINE(hpkt, MLXSW_REG_HPKT_ID, MLXSW_REG_HPKT_LEN);
6505 
6506 enum {
6507 	MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
6508 	MLXSW_REG_HPKT_ACK_REQUIRED,
6509 };
6510 
6511 /* reg_hpkt_ack
6512  * Require acknowledgements from the host for events.
6513  * If set, then the device will wait for the event it sent to be acknowledged
6514  * by the host. This option is only relevant for event trap IDs.
6515  * Access: RW
6516  *
6517  * Note: Currently not supported by firmware.
6518  */
6519 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
6520 
6521 enum mlxsw_reg_hpkt_action {
6522 	MLXSW_REG_HPKT_ACTION_FORWARD,
6523 	MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
6524 	MLXSW_REG_HPKT_ACTION_MIRROR_TO_CPU,
6525 	MLXSW_REG_HPKT_ACTION_DISCARD,
6526 	MLXSW_REG_HPKT_ACTION_SOFT_DISCARD,
6527 	MLXSW_REG_HPKT_ACTION_TRAP_AND_SOFT_DISCARD,
6528 	MLXSW_REG_HPKT_ACTION_TRAP_EXCEPTION_TO_CPU,
6529 	MLXSW_REG_HPKT_ACTION_SET_FW_DEFAULT = 15,
6530 };
6531 
6532 /* reg_hpkt_action
6533  * Action to perform on packet when trapped.
6534  * 0 - No action. Forward to CPU based on switching rules.
6535  * 1 - Trap to CPU (CPU receives sole copy).
6536  * 2 - Mirror to CPU (CPU receives a replica of the packet).
6537  * 3 - Discard.
6538  * 4 - Soft discard (allow other traps to act on the packet).
6539  * 5 - Trap and soft discard (allow other traps to overwrite this trap).
6540  * 6 - Trap to CPU (CPU receives sole copy) and count it as error.
6541  * 15 - Restore the firmware's default action.
6542  * Access: RW
6543  *
6544  * Note: Must be set to 0 (forward) for event trap IDs, as they are already
6545  * addressed to the CPU.
6546  */
6547 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
6548 
6549 /* reg_hpkt_trap_group
6550  * Trap group to associate the trap with.
6551  * Access: RW
6552  */
6553 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
6554 
6555 /* reg_hpkt_trap_id
6556  * Trap ID.
6557  * Access: Index
6558  *
6559  * Note: A trap ID can only be associated with a single trap group. The device
6560  * will associate the trap ID with the last trap group configured.
6561  */
6562 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 10);
6563 
6564 enum {
6565 	MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
6566 	MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
6567 	MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
6568 };
6569 
6570 /* reg_hpkt_ctrl
6571  * Configure dedicated buffer resources for control packets.
6572  * Ignored by SwitchX-2.
6573  * 0 - Keep factory defaults.
6574  * 1 - Do not use control buffer for this trap ID.
6575  * 2 - Use control buffer for this trap ID.
6576  * Access: RW
6577  */
6578 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
6579 
6580 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id,
6581 				       enum mlxsw_reg_htgt_trap_group trap_group,
6582 				       bool is_ctrl)
6583 {
6584 	MLXSW_REG_ZERO(hpkt, payload);
6585 	mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
6586 	mlxsw_reg_hpkt_action_set(payload, action);
6587 	mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
6588 	mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
6589 	mlxsw_reg_hpkt_ctrl_set(payload, is_ctrl ?
6590 				MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER :
6591 				MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER);
6592 }
6593 
6594 /* RGCR - Router General Configuration Register
6595  * --------------------------------------------
6596  * The register is used for setting up the router configuration.
6597  */
6598 #define MLXSW_REG_RGCR_ID 0x8001
6599 #define MLXSW_REG_RGCR_LEN 0x28
6600 
6601 MLXSW_REG_DEFINE(rgcr, MLXSW_REG_RGCR_ID, MLXSW_REG_RGCR_LEN);
6602 
6603 /* reg_rgcr_ipv4_en
6604  * IPv4 router enable.
6605  * Access: RW
6606  */
6607 MLXSW_ITEM32(reg, rgcr, ipv4_en, 0x00, 31, 1);
6608 
6609 /* reg_rgcr_ipv6_en
6610  * IPv6 router enable.
6611  * Access: RW
6612  */
6613 MLXSW_ITEM32(reg, rgcr, ipv6_en, 0x00, 30, 1);
6614 
6615 /* reg_rgcr_max_router_interfaces
6616  * Defines the maximum number of active router interfaces for all virtual
6617  * routers.
6618  * Access: RW
6619  */
6620 MLXSW_ITEM32(reg, rgcr, max_router_interfaces, 0x10, 0, 16);
6621 
6622 /* reg_rgcr_usp
6623  * Update switch priority and packet color.
6624  * 0 - Preserve the value of Switch Priority and packet color.
6625  * 1 - Recalculate the value of Switch Priority and packet color.
6626  * Access: RW
6627  *
6628  * Note: Not supported by SwitchX and SwitchX-2.
6629  */
6630 MLXSW_ITEM32(reg, rgcr, usp, 0x18, 20, 1);
6631 
6632 /* reg_rgcr_pcp_rw
6633  * Indicates how to handle the pcp_rewrite_en value:
6634  * 0 - Preserve the value of pcp_rewrite_en.
6635  * 2 - Disable PCP rewrite.
6636  * 3 - Enable PCP rewrite.
6637  * Access: RW
6638  *
6639  * Note: Not supported by SwitchX and SwitchX-2.
6640  */
6641 MLXSW_ITEM32(reg, rgcr, pcp_rw, 0x18, 16, 2);
6642 
6643 /* reg_rgcr_activity_dis
6644  * Activity disable:
6645  * 0 - Activity will be set when an entry is hit (default).
6646  * 1 - Activity will not be set when an entry is hit.
6647  *
6648  * Bit 0 - Disable activity bit in Router Algorithmic LPM Unicast Entry
6649  * (RALUE).
6650  * Bit 1 - Disable activity bit in Router Algorithmic LPM Unicast Host
6651  * Entry (RAUHT).
6652  * Bits 2:7 are reserved.
6653  * Access: RW
6654  *
6655  * Note: Not supported by SwitchX, SwitchX-2 and Switch-IB.
6656  */
6657 MLXSW_ITEM32(reg, rgcr, activity_dis, 0x20, 0, 8);
6658 
6659 static inline void mlxsw_reg_rgcr_pack(char *payload, bool ipv4_en,
6660 				       bool ipv6_en)
6661 {
6662 	MLXSW_REG_ZERO(rgcr, payload);
6663 	mlxsw_reg_rgcr_ipv4_en_set(payload, ipv4_en);
6664 	mlxsw_reg_rgcr_ipv6_en_set(payload, ipv6_en);
6665 }
6666 
6667 /* RITR - Router Interface Table Register
6668  * --------------------------------------
6669  * The register is used to configure the router interface table.
6670  */
6671 #define MLXSW_REG_RITR_ID 0x8002
6672 #define MLXSW_REG_RITR_LEN 0x40
6673 
6674 MLXSW_REG_DEFINE(ritr, MLXSW_REG_RITR_ID, MLXSW_REG_RITR_LEN);
6675 
6676 /* reg_ritr_enable
6677  * Enables routing on the router interface.
6678  * Access: RW
6679  */
6680 MLXSW_ITEM32(reg, ritr, enable, 0x00, 31, 1);
6681 
6682 /* reg_ritr_ipv4
6683  * IPv4 routing enable. Enables routing of IPv4 traffic on the router
6684  * interface.
6685  * Access: RW
6686  */
6687 MLXSW_ITEM32(reg, ritr, ipv4, 0x00, 29, 1);
6688 
6689 /* reg_ritr_ipv6
6690  * IPv6 routing enable. Enables routing of IPv6 traffic on the router
6691  * interface.
6692  * Access: RW
6693  */
6694 MLXSW_ITEM32(reg, ritr, ipv6, 0x00, 28, 1);
6695 
6696 /* reg_ritr_ipv4_mc
6697  * IPv4 multicast routing enable.
6698  * Access: RW
6699  */
6700 MLXSW_ITEM32(reg, ritr, ipv4_mc, 0x00, 27, 1);
6701 
6702 /* reg_ritr_ipv6_mc
6703  * IPv6 multicast routing enable.
6704  * Access: RW
6705  */
6706 MLXSW_ITEM32(reg, ritr, ipv6_mc, 0x00, 26, 1);
6707 
6708 enum mlxsw_reg_ritr_if_type {
6709 	/* VLAN interface. */
6710 	MLXSW_REG_RITR_VLAN_IF,
6711 	/* FID interface. */
6712 	MLXSW_REG_RITR_FID_IF,
6713 	/* Sub-port interface. */
6714 	MLXSW_REG_RITR_SP_IF,
6715 	/* Loopback Interface. */
6716 	MLXSW_REG_RITR_LOOPBACK_IF,
6717 };
6718 
6719 /* reg_ritr_type
6720  * Router interface type as per enum mlxsw_reg_ritr_if_type.
6721  * Access: RW
6722  */
6723 MLXSW_ITEM32(reg, ritr, type, 0x00, 23, 3);
6724 
6725 enum {
6726 	MLXSW_REG_RITR_RIF_CREATE,
6727 	MLXSW_REG_RITR_RIF_DEL,
6728 };
6729 
6730 /* reg_ritr_op
6731  * Opcode:
6732  * 0 - Create or edit RIF.
6733  * 1 - Delete RIF.
6734  * Reserved for SwitchX-2. For Spectrum, editing of interface properties
6735  * is not supported. An interface must be deleted and re-created in order
6736  * to update properties.
6737  * Access: WO
6738  */
6739 MLXSW_ITEM32(reg, ritr, op, 0x00, 20, 2);
6740 
6741 /* reg_ritr_rif
6742  * Router interface index. A pointer to the Router Interface Table.
6743  * Access: Index
6744  */
6745 MLXSW_ITEM32(reg, ritr, rif, 0x00, 0, 16);
6746 
6747 /* reg_ritr_ipv4_fe
6748  * IPv4 Forwarding Enable.
6749  * Enables routing of IPv4 traffic on the router interface. When disabled,
6750  * forwarding is blocked but local traffic (traps and IP2ME) will be enabled.
6751  * Not supported in SwitchX-2.
6752  * Access: RW
6753  */
6754 MLXSW_ITEM32(reg, ritr, ipv4_fe, 0x04, 29, 1);
6755 
6756 /* reg_ritr_ipv6_fe
6757  * IPv6 Forwarding Enable.
6758  * Enables routing of IPv6 traffic on the router interface. When disabled,
6759  * forwarding is blocked but local traffic (traps and IP2ME) will be enabled.
6760  * Not supported in SwitchX-2.
6761  * Access: RW
6762  */
6763 MLXSW_ITEM32(reg, ritr, ipv6_fe, 0x04, 28, 1);
6764 
6765 /* reg_ritr_ipv4_mc_fe
6766  * IPv4 Multicast Forwarding Enable.
6767  * When disabled, forwarding is blocked but local traffic (traps and IP to me)
6768  * will be enabled.
6769  * Access: RW
6770  */
6771 MLXSW_ITEM32(reg, ritr, ipv4_mc_fe, 0x04, 27, 1);
6772 
6773 /* reg_ritr_ipv6_mc_fe
6774  * IPv6 Multicast Forwarding Enable.
6775  * When disabled, forwarding is blocked but local traffic (traps and IP to me)
6776  * will be enabled.
6777  * Access: RW
6778  */
6779 MLXSW_ITEM32(reg, ritr, ipv6_mc_fe, 0x04, 26, 1);
6780 
6781 /* reg_ritr_lb_en
6782  * Loop-back filter enable for unicast packets.
6783  * If the flag is set then loop-back filter for unicast packets is
6784  * implemented on the RIF. Multicast packets are always subject to
6785  * loop-back filtering.
6786  * Access: RW
6787  */
6788 MLXSW_ITEM32(reg, ritr, lb_en, 0x04, 24, 1);
6789 
6790 /* reg_ritr_virtual_router
6791  * Virtual router ID associated with the router interface.
6792  * Access: RW
6793  */
6794 MLXSW_ITEM32(reg, ritr, virtual_router, 0x04, 0, 16);
6795 
6796 /* reg_ritr_mtu
6797  * Router interface MTU.
6798  * Access: RW
6799  */
6800 MLXSW_ITEM32(reg, ritr, mtu, 0x34, 0, 16);
6801 
6802 /* reg_ritr_if_swid
6803  * Switch partition ID.
6804  * Access: RW
6805  */
6806 MLXSW_ITEM32(reg, ritr, if_swid, 0x08, 24, 8);
6807 
6808 /* reg_ritr_if_mac_profile_id
6809  * MAC msb profile ID.
6810  * Access: RW
6811  */
6812 MLXSW_ITEM32(reg, ritr, if_mac_profile_id, 0x10, 16, 4);
6813 
6814 /* reg_ritr_if_mac
6815  * Router interface MAC address.
6816  * In Spectrum, all MAC addresses must have the same 38 MSBits.
6817  * Access: RW
6818  */
6819 MLXSW_ITEM_BUF(reg, ritr, if_mac, 0x12, 6);
6820 
6821 /* reg_ritr_if_vrrp_id_ipv6
6822  * VRRP ID for IPv6
6823  * Note: Reserved for RIF types other than VLAN, FID and Sub-port.
6824  * Access: RW
6825  */
6826 MLXSW_ITEM32(reg, ritr, if_vrrp_id_ipv6, 0x1C, 8, 8);
6827 
6828 /* reg_ritr_if_vrrp_id_ipv4
6829  * VRRP ID for IPv4
6830  * Note: Reserved for RIF types other than VLAN, FID and Sub-port.
6831  * Access: RW
6832  */
6833 MLXSW_ITEM32(reg, ritr, if_vrrp_id_ipv4, 0x1C, 0, 8);
6834 
6835 /* VLAN Interface */
6836 
6837 /* reg_ritr_vlan_if_vlan_id
6838  * VLAN ID.
6839  * Access: RW
6840  */
6841 MLXSW_ITEM32(reg, ritr, vlan_if_vlan_id, 0x08, 0, 12);
6842 
6843 /* reg_ritr_vlan_if_efid
6844  * Egress FID.
6845  * Used to connect the RIF to a bridge.
6846  * Access: RW
6847  *
6848  * Note: Reserved when legacy bridge model is used and on Spectrum-1.
6849  */
6850 MLXSW_ITEM32(reg, ritr, vlan_if_efid, 0x0C, 0, 16);
6851 
6852 /* FID Interface */
6853 
6854 /* reg_ritr_fid_if_fid
6855  * Filtering ID. Used to connect a bridge to the router.
6856  * When legacy bridge model is used, only FIDs from the vFID range are
6857  * supported. When unified bridge model is used, this is the egress FID for
6858  * router to bridge.
6859  * Access: RW
6860  */
6861 MLXSW_ITEM32(reg, ritr, fid_if_fid, 0x08, 0, 16);
6862 
6863 /* Sub-port Interface */
6864 
6865 /* reg_ritr_sp_if_lag
6866  * LAG indication. When this bit is set the system_port field holds the
6867  * LAG identifier.
6868  * Access: RW
6869  */
6870 MLXSW_ITEM32(reg, ritr, sp_if_lag, 0x08, 24, 1);
6871 
6872 /* reg_ritr_sp_system_port
6873  * Port unique indentifier. When lag bit is set, this field holds the
6874  * lag_id in bits 0:9.
6875  * Access: RW
6876  */
6877 MLXSW_ITEM32(reg, ritr, sp_if_system_port, 0x08, 0, 16);
6878 
6879 /* reg_ritr_sp_if_efid
6880  * Egress filtering ID.
6881  * Used to connect the eRIF to a bridge if eRIF-ACL has modified the DMAC or
6882  * the VID.
6883  * Access: RW
6884  *
6885  * Note: Reserved when legacy bridge model is used.
6886  */
6887 MLXSW_ITEM32(reg, ritr, sp_if_efid, 0x0C, 0, 16);
6888 
6889 /* reg_ritr_sp_if_vid
6890  * VLAN ID.
6891  * Access: RW
6892  */
6893 MLXSW_ITEM32(reg, ritr, sp_if_vid, 0x18, 0, 12);
6894 
6895 /* Loopback Interface */
6896 
6897 enum mlxsw_reg_ritr_loopback_protocol {
6898 	/* IPinIP IPv4 underlay Unicast */
6899 	MLXSW_REG_RITR_LOOPBACK_PROTOCOL_IPIP_IPV4,
6900 	/* IPinIP IPv6 underlay Unicast */
6901 	MLXSW_REG_RITR_LOOPBACK_PROTOCOL_IPIP_IPV6,
6902 	/* IPinIP generic - used for Spectrum-2 underlay RIF */
6903 	MLXSW_REG_RITR_LOOPBACK_GENERIC,
6904 };
6905 
6906 /* reg_ritr_loopback_protocol
6907  * Access: RW
6908  */
6909 MLXSW_ITEM32(reg, ritr, loopback_protocol, 0x08, 28, 4);
6910 
6911 enum mlxsw_reg_ritr_loopback_ipip_type {
6912 	/* Tunnel is IPinIP. */
6913 	MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_IP,
6914 	/* Tunnel is GRE, no key. */
6915 	MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_GRE_IN_IP,
6916 	/* Tunnel is GRE, with a key. */
6917 	MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_GRE_KEY_IN_IP,
6918 };
6919 
6920 /* reg_ritr_loopback_ipip_type
6921  * Encapsulation type.
6922  * Access: RW
6923  */
6924 MLXSW_ITEM32(reg, ritr, loopback_ipip_type, 0x10, 24, 4);
6925 
6926 enum mlxsw_reg_ritr_loopback_ipip_options {
6927 	/* The key is defined by gre_key. */
6928 	MLXSW_REG_RITR_LOOPBACK_IPIP_OPTIONS_GRE_KEY_PRESET,
6929 };
6930 
6931 /* reg_ritr_loopback_ipip_options
6932  * Access: RW
6933  */
6934 MLXSW_ITEM32(reg, ritr, loopback_ipip_options, 0x10, 20, 4);
6935 
6936 /* reg_ritr_loopback_ipip_uvr
6937  * Underlay Virtual Router ID.
6938  * Range is 0..cap_max_virtual_routers-1.
6939  * Reserved for Spectrum-2.
6940  * Access: RW
6941  */
6942 MLXSW_ITEM32(reg, ritr, loopback_ipip_uvr, 0x10, 0, 16);
6943 
6944 /* reg_ritr_loopback_ipip_underlay_rif
6945  * Underlay ingress router interface.
6946  * Reserved for Spectrum.
6947  * Access: RW
6948  */
6949 MLXSW_ITEM32(reg, ritr, loopback_ipip_underlay_rif, 0x14, 0, 16);
6950 
6951 /* reg_ritr_loopback_ipip_usip*
6952  * Encapsulation Underlay source IP.
6953  * Access: RW
6954  */
6955 MLXSW_ITEM_BUF(reg, ritr, loopback_ipip_usip6, 0x18, 16);
6956 MLXSW_ITEM32(reg, ritr, loopback_ipip_usip4, 0x24, 0, 32);
6957 
6958 /* reg_ritr_loopback_ipip_gre_key
6959  * GRE Key.
6960  * Reserved when ipip_type is not IP_IN_GRE_KEY_IN_IP.
6961  * Access: RW
6962  */
6963 MLXSW_ITEM32(reg, ritr, loopback_ipip_gre_key, 0x28, 0, 32);
6964 
6965 /* Shared between ingress/egress */
6966 enum mlxsw_reg_ritr_counter_set_type {
6967 	/* No Count. */
6968 	MLXSW_REG_RITR_COUNTER_SET_TYPE_NO_COUNT = 0x0,
6969 	/* Basic. Used for router interfaces, counting the following:
6970 	 *	- Error and Discard counters.
6971 	 *	- Unicast, Multicast and Broadcast counters. Sharing the
6972 	 *	  same set of counters for the different type of traffic
6973 	 *	  (IPv4, IPv6 and mpls).
6974 	 */
6975 	MLXSW_REG_RITR_COUNTER_SET_TYPE_BASIC = 0x9,
6976 };
6977 
6978 /* reg_ritr_ingress_counter_index
6979  * Counter Index for flow counter.
6980  * Access: RW
6981  */
6982 MLXSW_ITEM32(reg, ritr, ingress_counter_index, 0x38, 0, 24);
6983 
6984 /* reg_ritr_ingress_counter_set_type
6985  * Igress Counter Set Type for router interface counter.
6986  * Access: RW
6987  */
6988 MLXSW_ITEM32(reg, ritr, ingress_counter_set_type, 0x38, 24, 8);
6989 
6990 /* reg_ritr_egress_counter_index
6991  * Counter Index for flow counter.
6992  * Access: RW
6993  */
6994 MLXSW_ITEM32(reg, ritr, egress_counter_index, 0x3C, 0, 24);
6995 
6996 /* reg_ritr_egress_counter_set_type
6997  * Egress Counter Set Type for router interface counter.
6998  * Access: RW
6999  */
7000 MLXSW_ITEM32(reg, ritr, egress_counter_set_type, 0x3C, 24, 8);
7001 
7002 static inline void mlxsw_reg_ritr_counter_pack(char *payload, u32 index,
7003 					       bool enable, bool egress)
7004 {
7005 	enum mlxsw_reg_ritr_counter_set_type set_type;
7006 
7007 	if (enable)
7008 		set_type = MLXSW_REG_RITR_COUNTER_SET_TYPE_BASIC;
7009 	else
7010 		set_type = MLXSW_REG_RITR_COUNTER_SET_TYPE_NO_COUNT;
7011 
7012 	if (egress) {
7013 		mlxsw_reg_ritr_egress_counter_set_type_set(payload, set_type);
7014 		mlxsw_reg_ritr_egress_counter_index_set(payload, index);
7015 	} else {
7016 		mlxsw_reg_ritr_ingress_counter_set_type_set(payload, set_type);
7017 		mlxsw_reg_ritr_ingress_counter_index_set(payload, index);
7018 	}
7019 }
7020 
7021 static inline void mlxsw_reg_ritr_rif_pack(char *payload, u16 rif)
7022 {
7023 	MLXSW_REG_ZERO(ritr, payload);
7024 	mlxsw_reg_ritr_rif_set(payload, rif);
7025 }
7026 
7027 static inline void mlxsw_reg_ritr_sp_if_pack(char *payload, bool lag,
7028 					     u16 system_port, u16 efid, u16 vid)
7029 {
7030 	mlxsw_reg_ritr_sp_if_lag_set(payload, lag);
7031 	mlxsw_reg_ritr_sp_if_system_port_set(payload, system_port);
7032 	mlxsw_reg_ritr_sp_if_efid_set(payload, efid);
7033 	mlxsw_reg_ritr_sp_if_vid_set(payload, vid);
7034 }
7035 
7036 static inline void mlxsw_reg_ritr_pack(char *payload, bool enable,
7037 				       enum mlxsw_reg_ritr_if_type type,
7038 				       u16 rif, u16 vr_id, u16 mtu)
7039 {
7040 	bool op = enable ? MLXSW_REG_RITR_RIF_CREATE : MLXSW_REG_RITR_RIF_DEL;
7041 
7042 	MLXSW_REG_ZERO(ritr, payload);
7043 	mlxsw_reg_ritr_enable_set(payload, enable);
7044 	mlxsw_reg_ritr_ipv4_set(payload, 1);
7045 	mlxsw_reg_ritr_ipv6_set(payload, 1);
7046 	mlxsw_reg_ritr_ipv4_mc_set(payload, 1);
7047 	mlxsw_reg_ritr_ipv6_mc_set(payload, 1);
7048 	mlxsw_reg_ritr_type_set(payload, type);
7049 	mlxsw_reg_ritr_op_set(payload, op);
7050 	mlxsw_reg_ritr_rif_set(payload, rif);
7051 	mlxsw_reg_ritr_ipv4_fe_set(payload, 1);
7052 	mlxsw_reg_ritr_ipv6_fe_set(payload, 1);
7053 	mlxsw_reg_ritr_ipv4_mc_fe_set(payload, 1);
7054 	mlxsw_reg_ritr_ipv6_mc_fe_set(payload, 1);
7055 	mlxsw_reg_ritr_lb_en_set(payload, 1);
7056 	mlxsw_reg_ritr_virtual_router_set(payload, vr_id);
7057 	mlxsw_reg_ritr_mtu_set(payload, mtu);
7058 }
7059 
7060 static inline void mlxsw_reg_ritr_mac_pack(char *payload, const char *mac)
7061 {
7062 	mlxsw_reg_ritr_if_mac_memcpy_to(payload, mac);
7063 }
7064 
7065 static inline void
7066 mlxsw_reg_ritr_vlan_if_pack(char *payload, bool enable, u16 rif, u16 vr_id,
7067 			    u16 mtu, const char *mac, u8 mac_profile_id,
7068 			    u16 vlan_id, u16 efid)
7069 {
7070 	enum mlxsw_reg_ritr_if_type type = MLXSW_REG_RITR_VLAN_IF;
7071 
7072 	mlxsw_reg_ritr_pack(payload, enable, type, rif, vr_id, mtu);
7073 	mlxsw_reg_ritr_if_mac_memcpy_to(payload, mac);
7074 	mlxsw_reg_ritr_if_mac_profile_id_set(payload, mac_profile_id);
7075 	mlxsw_reg_ritr_vlan_if_vlan_id_set(payload, vlan_id);
7076 	mlxsw_reg_ritr_vlan_if_efid_set(payload, efid);
7077 }
7078 
7079 static inline void
7080 mlxsw_reg_ritr_loopback_ipip_common_pack(char *payload,
7081 			    enum mlxsw_reg_ritr_loopback_ipip_type ipip_type,
7082 			    enum mlxsw_reg_ritr_loopback_ipip_options options,
7083 			    u16 uvr_id, u16 underlay_rif, u32 gre_key)
7084 {
7085 	mlxsw_reg_ritr_loopback_ipip_type_set(payload, ipip_type);
7086 	mlxsw_reg_ritr_loopback_ipip_options_set(payload, options);
7087 	mlxsw_reg_ritr_loopback_ipip_uvr_set(payload, uvr_id);
7088 	mlxsw_reg_ritr_loopback_ipip_underlay_rif_set(payload, underlay_rif);
7089 	mlxsw_reg_ritr_loopback_ipip_gre_key_set(payload, gre_key);
7090 }
7091 
7092 static inline void
7093 mlxsw_reg_ritr_loopback_ipip4_pack(char *payload,
7094 			    enum mlxsw_reg_ritr_loopback_ipip_type ipip_type,
7095 			    enum mlxsw_reg_ritr_loopback_ipip_options options,
7096 			    u16 uvr_id, u16 underlay_rif, u32 usip, u32 gre_key)
7097 {
7098 	mlxsw_reg_ritr_loopback_protocol_set(payload,
7099 				    MLXSW_REG_RITR_LOOPBACK_PROTOCOL_IPIP_IPV4);
7100 	mlxsw_reg_ritr_loopback_ipip_common_pack(payload, ipip_type, options,
7101 						 uvr_id, underlay_rif, gre_key);
7102 	mlxsw_reg_ritr_loopback_ipip_usip4_set(payload, usip);
7103 }
7104 
7105 static inline void
7106 mlxsw_reg_ritr_loopback_ipip6_pack(char *payload,
7107 				   enum mlxsw_reg_ritr_loopback_ipip_type ipip_type,
7108 				   enum mlxsw_reg_ritr_loopback_ipip_options options,
7109 				   u16 uvr_id, u16 underlay_rif,
7110 				   const struct in6_addr *usip, u32 gre_key)
7111 {
7112 	enum mlxsw_reg_ritr_loopback_protocol protocol =
7113 		MLXSW_REG_RITR_LOOPBACK_PROTOCOL_IPIP_IPV6;
7114 
7115 	mlxsw_reg_ritr_loopback_protocol_set(payload, protocol);
7116 	mlxsw_reg_ritr_loopback_ipip_common_pack(payload, ipip_type, options,
7117 						 uvr_id, underlay_rif, gre_key);
7118 	mlxsw_reg_ritr_loopback_ipip_usip6_memcpy_to(payload,
7119 						     (const char *)usip);
7120 }
7121 
7122 /* RTAR - Router TCAM Allocation Register
7123  * --------------------------------------
7124  * This register is used for allocation of regions in the TCAM table.
7125  */
7126 #define MLXSW_REG_RTAR_ID 0x8004
7127 #define MLXSW_REG_RTAR_LEN 0x20
7128 
7129 MLXSW_REG_DEFINE(rtar, MLXSW_REG_RTAR_ID, MLXSW_REG_RTAR_LEN);
7130 
7131 enum mlxsw_reg_rtar_op {
7132 	MLXSW_REG_RTAR_OP_ALLOCATE,
7133 	MLXSW_REG_RTAR_OP_RESIZE,
7134 	MLXSW_REG_RTAR_OP_DEALLOCATE,
7135 };
7136 
7137 /* reg_rtar_op
7138  * Access: WO
7139  */
7140 MLXSW_ITEM32(reg, rtar, op, 0x00, 28, 4);
7141 
7142 enum mlxsw_reg_rtar_key_type {
7143 	MLXSW_REG_RTAR_KEY_TYPE_IPV4_MULTICAST = 1,
7144 	MLXSW_REG_RTAR_KEY_TYPE_IPV6_MULTICAST = 3
7145 };
7146 
7147 /* reg_rtar_key_type
7148  * TCAM key type for the region.
7149  * Access: WO
7150  */
7151 MLXSW_ITEM32(reg, rtar, key_type, 0x00, 0, 8);
7152 
7153 /* reg_rtar_region_size
7154  * TCAM region size. When allocating/resizing this is the requested
7155  * size, the response is the actual size.
7156  * Note: Actual size may be larger than requested.
7157  * Reserved for op = Deallocate
7158  * Access: WO
7159  */
7160 MLXSW_ITEM32(reg, rtar, region_size, 0x04, 0, 16);
7161 
7162 static inline void mlxsw_reg_rtar_pack(char *payload,
7163 				       enum mlxsw_reg_rtar_op op,
7164 				       enum mlxsw_reg_rtar_key_type key_type,
7165 				       u16 region_size)
7166 {
7167 	MLXSW_REG_ZERO(rtar, payload);
7168 	mlxsw_reg_rtar_op_set(payload, op);
7169 	mlxsw_reg_rtar_key_type_set(payload, key_type);
7170 	mlxsw_reg_rtar_region_size_set(payload, region_size);
7171 }
7172 
7173 /* RATR - Router Adjacency Table Register
7174  * --------------------------------------
7175  * The RATR register is used to configure the Router Adjacency (next-hop)
7176  * Table.
7177  */
7178 #define MLXSW_REG_RATR_ID 0x8008
7179 #define MLXSW_REG_RATR_LEN 0x2C
7180 
7181 MLXSW_REG_DEFINE(ratr, MLXSW_REG_RATR_ID, MLXSW_REG_RATR_LEN);
7182 
7183 enum mlxsw_reg_ratr_op {
7184 	/* Read */
7185 	MLXSW_REG_RATR_OP_QUERY_READ = 0,
7186 	/* Read and clear activity */
7187 	MLXSW_REG_RATR_OP_QUERY_READ_CLEAR = 2,
7188 	/* Write Adjacency entry */
7189 	MLXSW_REG_RATR_OP_WRITE_WRITE_ENTRY = 1,
7190 	/* Write Adjacency entry only if the activity is cleared.
7191 	 * The write may not succeed if the activity is set. There is not
7192 	 * direct feedback if the write has succeeded or not, however
7193 	 * the get will reveal the actual entry (SW can compare the get
7194 	 * response to the set command).
7195 	 */
7196 	MLXSW_REG_RATR_OP_WRITE_WRITE_ENTRY_ON_ACTIVITY = 3,
7197 };
7198 
7199 /* reg_ratr_op
7200  * Note that Write operation may also be used for updating
7201  * counter_set_type and counter_index. In this case all other
7202  * fields must not be updated.
7203  * Access: OP
7204  */
7205 MLXSW_ITEM32(reg, ratr, op, 0x00, 28, 4);
7206 
7207 /* reg_ratr_v
7208  * Valid bit. Indicates if the adjacency entry is valid.
7209  * Note: the device may need some time before reusing an invalidated
7210  * entry. During this time the entry can not be reused. It is
7211  * recommended to use another entry before reusing an invalidated
7212  * entry (e.g. software can put it at the end of the list for
7213  * reusing). Trying to access an invalidated entry not yet cleared
7214  * by the device results with failure indicating "Try Again" status.
7215  * When valid is '0' then egress_router_interface,trap_action,
7216  * adjacency_parameters and counters are reserved
7217  * Access: RW
7218  */
7219 MLXSW_ITEM32(reg, ratr, v, 0x00, 24, 1);
7220 
7221 /* reg_ratr_a
7222  * Activity. Set for new entries. Set if a packet lookup has hit on
7223  * the specific entry. To clear the a bit, use "clear activity".
7224  * Access: RO
7225  */
7226 MLXSW_ITEM32(reg, ratr, a, 0x00, 16, 1);
7227 
7228 enum mlxsw_reg_ratr_type {
7229 	/* Ethernet */
7230 	MLXSW_REG_RATR_TYPE_ETHERNET,
7231 	/* IPoIB Unicast without GRH.
7232 	 * Reserved for Spectrum.
7233 	 */
7234 	MLXSW_REG_RATR_TYPE_IPOIB_UC,
7235 	/* IPoIB Unicast with GRH. Supported only in table 0 (Ethernet unicast
7236 	 * adjacency).
7237 	 * Reserved for Spectrum.
7238 	 */
7239 	MLXSW_REG_RATR_TYPE_IPOIB_UC_W_GRH,
7240 	/* IPoIB Multicast.
7241 	 * Reserved for Spectrum.
7242 	 */
7243 	MLXSW_REG_RATR_TYPE_IPOIB_MC,
7244 	/* MPLS.
7245 	 * Reserved for SwitchX/-2.
7246 	 */
7247 	MLXSW_REG_RATR_TYPE_MPLS,
7248 	/* IPinIP Encap.
7249 	 * Reserved for SwitchX/-2.
7250 	 */
7251 	MLXSW_REG_RATR_TYPE_IPIP,
7252 };
7253 
7254 /* reg_ratr_type
7255  * Adjacency entry type.
7256  * Access: RW
7257  */
7258 MLXSW_ITEM32(reg, ratr, type, 0x04, 28, 4);
7259 
7260 /* reg_ratr_adjacency_index_low
7261  * Bits 15:0 of index into the adjacency table.
7262  * For SwitchX and SwitchX-2, the adjacency table is linear and
7263  * used for adjacency entries only.
7264  * For Spectrum, the index is to the KVD linear.
7265  * Access: Index
7266  */
7267 MLXSW_ITEM32(reg, ratr, adjacency_index_low, 0x04, 0, 16);
7268 
7269 /* reg_ratr_egress_router_interface
7270  * Range is 0 .. cap_max_router_interfaces - 1
7271  * Access: RW
7272  */
7273 MLXSW_ITEM32(reg, ratr, egress_router_interface, 0x08, 0, 16);
7274 
7275 enum mlxsw_reg_ratr_trap_action {
7276 	MLXSW_REG_RATR_TRAP_ACTION_NOP,
7277 	MLXSW_REG_RATR_TRAP_ACTION_TRAP,
7278 	MLXSW_REG_RATR_TRAP_ACTION_MIRROR_TO_CPU,
7279 	MLXSW_REG_RATR_TRAP_ACTION_MIRROR,
7280 	MLXSW_REG_RATR_TRAP_ACTION_DISCARD_ERRORS,
7281 };
7282 
7283 /* reg_ratr_trap_action
7284  * see mlxsw_reg_ratr_trap_action
7285  * Access: RW
7286  */
7287 MLXSW_ITEM32(reg, ratr, trap_action, 0x0C, 28, 4);
7288 
7289 /* reg_ratr_adjacency_index_high
7290  * Bits 23:16 of the adjacency_index.
7291  * Access: Index
7292  */
7293 MLXSW_ITEM32(reg, ratr, adjacency_index_high, 0x0C, 16, 8);
7294 
7295 enum mlxsw_reg_ratr_trap_id {
7296 	MLXSW_REG_RATR_TRAP_ID_RTR_EGRESS0,
7297 	MLXSW_REG_RATR_TRAP_ID_RTR_EGRESS1,
7298 };
7299 
7300 /* reg_ratr_trap_id
7301  * Trap ID to be reported to CPU.
7302  * Trap-ID is RTR_EGRESS0 or RTR_EGRESS1.
7303  * For trap_action of NOP, MIRROR and DISCARD_ERROR
7304  * Access: RW
7305  */
7306 MLXSW_ITEM32(reg, ratr, trap_id, 0x0C, 0, 8);
7307 
7308 /* reg_ratr_eth_destination_mac
7309  * MAC address of the destination next-hop.
7310  * Access: RW
7311  */
7312 MLXSW_ITEM_BUF(reg, ratr, eth_destination_mac, 0x12, 6);
7313 
7314 enum mlxsw_reg_ratr_ipip_type {
7315 	/* IPv4, address set by mlxsw_reg_ratr_ipip_ipv4_udip. */
7316 	MLXSW_REG_RATR_IPIP_TYPE_IPV4,
7317 	/* IPv6, address set by mlxsw_reg_ratr_ipip_ipv6_ptr. */
7318 	MLXSW_REG_RATR_IPIP_TYPE_IPV6,
7319 };
7320 
7321 /* reg_ratr_ipip_type
7322  * Underlay destination ip type.
7323  * Note: the type field must match the protocol of the router interface.
7324  * Access: RW
7325  */
7326 MLXSW_ITEM32(reg, ratr, ipip_type, 0x10, 16, 4);
7327 
7328 /* reg_ratr_ipip_ipv4_udip
7329  * Underlay ipv4 dip.
7330  * Reserved when ipip_type is IPv6.
7331  * Access: RW
7332  */
7333 MLXSW_ITEM32(reg, ratr, ipip_ipv4_udip, 0x18, 0, 32);
7334 
7335 /* reg_ratr_ipip_ipv6_ptr
7336  * Pointer to IPv6 underlay destination ip address.
7337  * For Spectrum: Pointer to KVD linear space.
7338  * Access: RW
7339  */
7340 MLXSW_ITEM32(reg, ratr, ipip_ipv6_ptr, 0x1C, 0, 24);
7341 
7342 enum mlxsw_reg_flow_counter_set_type {
7343 	/* No count */
7344 	MLXSW_REG_FLOW_COUNTER_SET_TYPE_NO_COUNT = 0x00,
7345 	/* Count packets and bytes */
7346 	MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES = 0x03,
7347 	/* Count only packets */
7348 	MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS = 0x05,
7349 };
7350 
7351 /* reg_ratr_counter_set_type
7352  * Counter set type for flow counters
7353  * Access: RW
7354  */
7355 MLXSW_ITEM32(reg, ratr, counter_set_type, 0x28, 24, 8);
7356 
7357 /* reg_ratr_counter_index
7358  * Counter index for flow counters
7359  * Access: RW
7360  */
7361 MLXSW_ITEM32(reg, ratr, counter_index, 0x28, 0, 24);
7362 
7363 static inline void
7364 mlxsw_reg_ratr_pack(char *payload,
7365 		    enum mlxsw_reg_ratr_op op, bool valid,
7366 		    enum mlxsw_reg_ratr_type type,
7367 		    u32 adjacency_index, u16 egress_rif)
7368 {
7369 	MLXSW_REG_ZERO(ratr, payload);
7370 	mlxsw_reg_ratr_op_set(payload, op);
7371 	mlxsw_reg_ratr_v_set(payload, valid);
7372 	mlxsw_reg_ratr_type_set(payload, type);
7373 	mlxsw_reg_ratr_adjacency_index_low_set(payload, adjacency_index);
7374 	mlxsw_reg_ratr_adjacency_index_high_set(payload, adjacency_index >> 16);
7375 	mlxsw_reg_ratr_egress_router_interface_set(payload, egress_rif);
7376 }
7377 
7378 static inline void mlxsw_reg_ratr_eth_entry_pack(char *payload,
7379 						 const char *dest_mac)
7380 {
7381 	mlxsw_reg_ratr_eth_destination_mac_memcpy_to(payload, dest_mac);
7382 }
7383 
7384 static inline void mlxsw_reg_ratr_ipip4_entry_pack(char *payload, u32 ipv4_udip)
7385 {
7386 	mlxsw_reg_ratr_ipip_type_set(payload, MLXSW_REG_RATR_IPIP_TYPE_IPV4);
7387 	mlxsw_reg_ratr_ipip_ipv4_udip_set(payload, ipv4_udip);
7388 }
7389 
7390 static inline void mlxsw_reg_ratr_ipip6_entry_pack(char *payload, u32 ipv6_ptr)
7391 {
7392 	mlxsw_reg_ratr_ipip_type_set(payload, MLXSW_REG_RATR_IPIP_TYPE_IPV6);
7393 	mlxsw_reg_ratr_ipip_ipv6_ptr_set(payload, ipv6_ptr);
7394 }
7395 
7396 static inline void mlxsw_reg_ratr_counter_pack(char *payload, u64 counter_index,
7397 					       bool counter_enable)
7398 {
7399 	enum mlxsw_reg_flow_counter_set_type set_type;
7400 
7401 	if (counter_enable)
7402 		set_type = MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES;
7403 	else
7404 		set_type = MLXSW_REG_FLOW_COUNTER_SET_TYPE_NO_COUNT;
7405 
7406 	mlxsw_reg_ratr_counter_index_set(payload, counter_index);
7407 	mlxsw_reg_ratr_counter_set_type_set(payload, set_type);
7408 }
7409 
7410 /* RDPM - Router DSCP to Priority Mapping
7411  * --------------------------------------
7412  * Controls the mapping from DSCP field to switch priority on routed packets
7413  */
7414 #define MLXSW_REG_RDPM_ID 0x8009
7415 #define MLXSW_REG_RDPM_BASE_LEN 0x00
7416 #define MLXSW_REG_RDPM_DSCP_ENTRY_REC_LEN 0x01
7417 #define MLXSW_REG_RDPM_DSCP_ENTRY_REC_MAX_COUNT 64
7418 #define MLXSW_REG_RDPM_LEN 0x40
7419 #define MLXSW_REG_RDPM_LAST_ENTRY (MLXSW_REG_RDPM_BASE_LEN + \
7420 				   MLXSW_REG_RDPM_LEN - \
7421 				   MLXSW_REG_RDPM_DSCP_ENTRY_REC_LEN)
7422 
7423 MLXSW_REG_DEFINE(rdpm, MLXSW_REG_RDPM_ID, MLXSW_REG_RDPM_LEN);
7424 
7425 /* reg_dscp_entry_e
7426  * Enable update of the specific entry
7427  * Access: Index
7428  */
7429 MLXSW_ITEM8_INDEXED(reg, rdpm, dscp_entry_e, MLXSW_REG_RDPM_LAST_ENTRY, 7, 1,
7430 		    -MLXSW_REG_RDPM_DSCP_ENTRY_REC_LEN, 0x00, false);
7431 
7432 /* reg_dscp_entry_prio
7433  * Switch Priority
7434  * Access: RW
7435  */
7436 MLXSW_ITEM8_INDEXED(reg, rdpm, dscp_entry_prio, MLXSW_REG_RDPM_LAST_ENTRY, 0, 4,
7437 		    -MLXSW_REG_RDPM_DSCP_ENTRY_REC_LEN, 0x00, false);
7438 
7439 static inline void mlxsw_reg_rdpm_pack(char *payload, unsigned short index,
7440 				       u8 prio)
7441 {
7442 	mlxsw_reg_rdpm_dscp_entry_e_set(payload, index, 1);
7443 	mlxsw_reg_rdpm_dscp_entry_prio_set(payload, index, prio);
7444 }
7445 
7446 /* RICNT - Router Interface Counter Register
7447  * -----------------------------------------
7448  * The RICNT register retrieves per port performance counters
7449  */
7450 #define MLXSW_REG_RICNT_ID 0x800B
7451 #define MLXSW_REG_RICNT_LEN 0x100
7452 
7453 MLXSW_REG_DEFINE(ricnt, MLXSW_REG_RICNT_ID, MLXSW_REG_RICNT_LEN);
7454 
7455 /* reg_ricnt_counter_index
7456  * Counter index
7457  * Access: RW
7458  */
7459 MLXSW_ITEM32(reg, ricnt, counter_index, 0x04, 0, 24);
7460 
7461 enum mlxsw_reg_ricnt_counter_set_type {
7462 	/* No Count. */
7463 	MLXSW_REG_RICNT_COUNTER_SET_TYPE_NO_COUNT = 0x00,
7464 	/* Basic. Used for router interfaces, counting the following:
7465 	 *	- Error and Discard counters.
7466 	 *	- Unicast, Multicast and Broadcast counters. Sharing the
7467 	 *	  same set of counters for the different type of traffic
7468 	 *	  (IPv4, IPv6 and mpls).
7469 	 */
7470 	MLXSW_REG_RICNT_COUNTER_SET_TYPE_BASIC = 0x09,
7471 };
7472 
7473 /* reg_ricnt_counter_set_type
7474  * Counter Set Type for router interface counter
7475  * Access: RW
7476  */
7477 MLXSW_ITEM32(reg, ricnt, counter_set_type, 0x04, 24, 8);
7478 
7479 enum mlxsw_reg_ricnt_opcode {
7480 	/* Nop. Supported only for read access*/
7481 	MLXSW_REG_RICNT_OPCODE_NOP = 0x00,
7482 	/* Clear. Setting the clr bit will reset the counter value for
7483 	 * all counters of the specified Router Interface.
7484 	 */
7485 	MLXSW_REG_RICNT_OPCODE_CLEAR = 0x08,
7486 };
7487 
7488 /* reg_ricnt_opcode
7489  * Opcode
7490  * Access: RW
7491  */
7492 MLXSW_ITEM32(reg, ricnt, op, 0x00, 28, 4);
7493 
7494 /* reg_ricnt_good_unicast_packets
7495  * good unicast packets.
7496  * Access: RW
7497  */
7498 MLXSW_ITEM64(reg, ricnt, good_unicast_packets, 0x08, 0, 64);
7499 
7500 /* reg_ricnt_good_multicast_packets
7501  * good multicast packets.
7502  * Access: RW
7503  */
7504 MLXSW_ITEM64(reg, ricnt, good_multicast_packets, 0x10, 0, 64);
7505 
7506 /* reg_ricnt_good_broadcast_packets
7507  * good broadcast packets
7508  * Access: RW
7509  */
7510 MLXSW_ITEM64(reg, ricnt, good_broadcast_packets, 0x18, 0, 64);
7511 
7512 /* reg_ricnt_good_unicast_bytes
7513  * A count of L3 data and padding octets not including L2 headers
7514  * for good unicast frames.
7515  * Access: RW
7516  */
7517 MLXSW_ITEM64(reg, ricnt, good_unicast_bytes, 0x20, 0, 64);
7518 
7519 /* reg_ricnt_good_multicast_bytes
7520  * A count of L3 data and padding octets not including L2 headers
7521  * for good multicast frames.
7522  * Access: RW
7523  */
7524 MLXSW_ITEM64(reg, ricnt, good_multicast_bytes, 0x28, 0, 64);
7525 
7526 /* reg_ritr_good_broadcast_bytes
7527  * A count of L3 data and padding octets not including L2 headers
7528  * for good broadcast frames.
7529  * Access: RW
7530  */
7531 MLXSW_ITEM64(reg, ricnt, good_broadcast_bytes, 0x30, 0, 64);
7532 
7533 /* reg_ricnt_error_packets
7534  * A count of errored frames that do not pass the router checks.
7535  * Access: RW
7536  */
7537 MLXSW_ITEM64(reg, ricnt, error_packets, 0x38, 0, 64);
7538 
7539 /* reg_ricnt_discrad_packets
7540  * A count of non-errored frames that do not pass the router checks.
7541  * Access: RW
7542  */
7543 MLXSW_ITEM64(reg, ricnt, discard_packets, 0x40, 0, 64);
7544 
7545 /* reg_ricnt_error_bytes
7546  * A count of L3 data and padding octets not including L2 headers
7547  * for errored frames.
7548  * Access: RW
7549  */
7550 MLXSW_ITEM64(reg, ricnt, error_bytes, 0x48, 0, 64);
7551 
7552 /* reg_ricnt_discard_bytes
7553  * A count of L3 data and padding octets not including L2 headers
7554  * for non-errored frames that do not pass the router checks.
7555  * Access: RW
7556  */
7557 MLXSW_ITEM64(reg, ricnt, discard_bytes, 0x50, 0, 64);
7558 
7559 static inline void mlxsw_reg_ricnt_pack(char *payload, u32 index,
7560 					enum mlxsw_reg_ricnt_opcode op)
7561 {
7562 	MLXSW_REG_ZERO(ricnt, payload);
7563 	mlxsw_reg_ricnt_op_set(payload, op);
7564 	mlxsw_reg_ricnt_counter_index_set(payload, index);
7565 	mlxsw_reg_ricnt_counter_set_type_set(payload,
7566 					     MLXSW_REG_RICNT_COUNTER_SET_TYPE_BASIC);
7567 }
7568 
7569 /* RRCR - Router Rules Copy Register Layout
7570  * ----------------------------------------
7571  * This register is used for moving and copying route entry rules.
7572  */
7573 #define MLXSW_REG_RRCR_ID 0x800F
7574 #define MLXSW_REG_RRCR_LEN 0x24
7575 
7576 MLXSW_REG_DEFINE(rrcr, MLXSW_REG_RRCR_ID, MLXSW_REG_RRCR_LEN);
7577 
7578 enum mlxsw_reg_rrcr_op {
7579 	/* Move rules */
7580 	MLXSW_REG_RRCR_OP_MOVE,
7581 	/* Copy rules */
7582 	MLXSW_REG_RRCR_OP_COPY,
7583 };
7584 
7585 /* reg_rrcr_op
7586  * Access: WO
7587  */
7588 MLXSW_ITEM32(reg, rrcr, op, 0x00, 28, 4);
7589 
7590 /* reg_rrcr_offset
7591  * Offset within the region from which to copy/move.
7592  * Access: Index
7593  */
7594 MLXSW_ITEM32(reg, rrcr, offset, 0x00, 0, 16);
7595 
7596 /* reg_rrcr_size
7597  * The number of rules to copy/move.
7598  * Access: WO
7599  */
7600 MLXSW_ITEM32(reg, rrcr, size, 0x04, 0, 16);
7601 
7602 /* reg_rrcr_table_id
7603  * Identifier of the table on which to perform the operation. Encoding is the
7604  * same as in RTAR.key_type
7605  * Access: Index
7606  */
7607 MLXSW_ITEM32(reg, rrcr, table_id, 0x10, 0, 4);
7608 
7609 /* reg_rrcr_dest_offset
7610  * Offset within the region to which to copy/move
7611  * Access: Index
7612  */
7613 MLXSW_ITEM32(reg, rrcr, dest_offset, 0x20, 0, 16);
7614 
7615 static inline void mlxsw_reg_rrcr_pack(char *payload, enum mlxsw_reg_rrcr_op op,
7616 				       u16 offset, u16 size,
7617 				       enum mlxsw_reg_rtar_key_type table_id,
7618 				       u16 dest_offset)
7619 {
7620 	MLXSW_REG_ZERO(rrcr, payload);
7621 	mlxsw_reg_rrcr_op_set(payload, op);
7622 	mlxsw_reg_rrcr_offset_set(payload, offset);
7623 	mlxsw_reg_rrcr_size_set(payload, size);
7624 	mlxsw_reg_rrcr_table_id_set(payload, table_id);
7625 	mlxsw_reg_rrcr_dest_offset_set(payload, dest_offset);
7626 }
7627 
7628 /* RALTA - Router Algorithmic LPM Tree Allocation Register
7629  * -------------------------------------------------------
7630  * RALTA is used to allocate the LPM trees of the SHSPM method.
7631  */
7632 #define MLXSW_REG_RALTA_ID 0x8010
7633 #define MLXSW_REG_RALTA_LEN 0x04
7634 
7635 MLXSW_REG_DEFINE(ralta, MLXSW_REG_RALTA_ID, MLXSW_REG_RALTA_LEN);
7636 
7637 /* reg_ralta_op
7638  * opcode (valid for Write, must be 0 on Read)
7639  * 0 - allocate a tree
7640  * 1 - deallocate a tree
7641  * Access: OP
7642  */
7643 MLXSW_ITEM32(reg, ralta, op, 0x00, 28, 2);
7644 
7645 enum mlxsw_reg_ralxx_protocol {
7646 	MLXSW_REG_RALXX_PROTOCOL_IPV4,
7647 	MLXSW_REG_RALXX_PROTOCOL_IPV6,
7648 };
7649 
7650 /* reg_ralta_protocol
7651  * Protocol.
7652  * Deallocation opcode: Reserved.
7653  * Access: RW
7654  */
7655 MLXSW_ITEM32(reg, ralta, protocol, 0x00, 24, 4);
7656 
7657 /* reg_ralta_tree_id
7658  * An identifier (numbered from 1..cap_shspm_max_trees-1) representing
7659  * the tree identifier (managed by software).
7660  * Note that tree_id 0 is allocated for a default-route tree.
7661  * Access: Index
7662  */
7663 MLXSW_ITEM32(reg, ralta, tree_id, 0x00, 0, 8);
7664 
7665 static inline void mlxsw_reg_ralta_pack(char *payload, bool alloc,
7666 					enum mlxsw_reg_ralxx_protocol protocol,
7667 					u8 tree_id)
7668 {
7669 	MLXSW_REG_ZERO(ralta, payload);
7670 	mlxsw_reg_ralta_op_set(payload, !alloc);
7671 	mlxsw_reg_ralta_protocol_set(payload, protocol);
7672 	mlxsw_reg_ralta_tree_id_set(payload, tree_id);
7673 }
7674 
7675 /* RALST - Router Algorithmic LPM Structure Tree Register
7676  * ------------------------------------------------------
7677  * RALST is used to set and query the structure of an LPM tree.
7678  * The structure of the tree must be sorted as a sorted binary tree, while
7679  * each node is a bin that is tagged as the length of the prefixes the lookup
7680  * will refer to. Therefore, bin X refers to a set of entries with prefixes
7681  * of X bits to match with the destination address. The bin 0 indicates
7682  * the default action, when there is no match of any prefix.
7683  */
7684 #define MLXSW_REG_RALST_ID 0x8011
7685 #define MLXSW_REG_RALST_LEN 0x104
7686 
7687 MLXSW_REG_DEFINE(ralst, MLXSW_REG_RALST_ID, MLXSW_REG_RALST_LEN);
7688 
7689 /* reg_ralst_root_bin
7690  * The bin number of the root bin.
7691  * 0<root_bin=<(length of IP address)
7692  * For a default-route tree configure 0xff
7693  * Access: RW
7694  */
7695 MLXSW_ITEM32(reg, ralst, root_bin, 0x00, 16, 8);
7696 
7697 /* reg_ralst_tree_id
7698  * Tree identifier numbered from 1..(cap_shspm_max_trees-1).
7699  * Access: Index
7700  */
7701 MLXSW_ITEM32(reg, ralst, tree_id, 0x00, 0, 8);
7702 
7703 #define MLXSW_REG_RALST_BIN_NO_CHILD 0xff
7704 #define MLXSW_REG_RALST_BIN_OFFSET 0x04
7705 #define MLXSW_REG_RALST_BIN_COUNT 128
7706 
7707 /* reg_ralst_left_child_bin
7708  * Holding the children of the bin according to the stored tree's structure.
7709  * For trees composed of less than 4 blocks, the bins in excess are reserved.
7710  * Note that tree_id 0 is allocated for a default-route tree, bins are 0xff
7711  * Access: RW
7712  */
7713 MLXSW_ITEM16_INDEXED(reg, ralst, left_child_bin, 0x04, 8, 8, 0x02, 0x00, false);
7714 
7715 /* reg_ralst_right_child_bin
7716  * Holding the children of the bin according to the stored tree's structure.
7717  * For trees composed of less than 4 blocks, the bins in excess are reserved.
7718  * Note that tree_id 0 is allocated for a default-route tree, bins are 0xff
7719  * Access: RW
7720  */
7721 MLXSW_ITEM16_INDEXED(reg, ralst, right_child_bin, 0x04, 0, 8, 0x02, 0x00,
7722 		     false);
7723 
7724 static inline void mlxsw_reg_ralst_pack(char *payload, u8 root_bin, u8 tree_id)
7725 {
7726 	MLXSW_REG_ZERO(ralst, payload);
7727 
7728 	/* Initialize all bins to have no left or right child */
7729 	memset(payload + MLXSW_REG_RALST_BIN_OFFSET,
7730 	       MLXSW_REG_RALST_BIN_NO_CHILD, MLXSW_REG_RALST_BIN_COUNT * 2);
7731 
7732 	mlxsw_reg_ralst_root_bin_set(payload, root_bin);
7733 	mlxsw_reg_ralst_tree_id_set(payload, tree_id);
7734 }
7735 
7736 static inline void mlxsw_reg_ralst_bin_pack(char *payload, u8 bin_number,
7737 					    u8 left_child_bin,
7738 					    u8 right_child_bin)
7739 {
7740 	int bin_index = bin_number - 1;
7741 
7742 	mlxsw_reg_ralst_left_child_bin_set(payload, bin_index, left_child_bin);
7743 	mlxsw_reg_ralst_right_child_bin_set(payload, bin_index,
7744 					    right_child_bin);
7745 }
7746 
7747 /* RALTB - Router Algorithmic LPM Tree Binding Register
7748  * ----------------------------------------------------
7749  * RALTB is used to bind virtual router and protocol to an allocated LPM tree.
7750  */
7751 #define MLXSW_REG_RALTB_ID 0x8012
7752 #define MLXSW_REG_RALTB_LEN 0x04
7753 
7754 MLXSW_REG_DEFINE(raltb, MLXSW_REG_RALTB_ID, MLXSW_REG_RALTB_LEN);
7755 
7756 /* reg_raltb_virtual_router
7757  * Virtual Router ID
7758  * Range is 0..cap_max_virtual_routers-1
7759  * Access: Index
7760  */
7761 MLXSW_ITEM32(reg, raltb, virtual_router, 0x00, 16, 16);
7762 
7763 /* reg_raltb_protocol
7764  * Protocol.
7765  * Access: Index
7766  */
7767 MLXSW_ITEM32(reg, raltb, protocol, 0x00, 12, 4);
7768 
7769 /* reg_raltb_tree_id
7770  * Tree to be used for the {virtual_router, protocol}
7771  * Tree identifier numbered from 1..(cap_shspm_max_trees-1).
7772  * By default, all Unicast IPv4 and IPv6 are bound to tree_id 0.
7773  * Access: RW
7774  */
7775 MLXSW_ITEM32(reg, raltb, tree_id, 0x00, 0, 8);
7776 
7777 static inline void mlxsw_reg_raltb_pack(char *payload, u16 virtual_router,
7778 					enum mlxsw_reg_ralxx_protocol protocol,
7779 					u8 tree_id)
7780 {
7781 	MLXSW_REG_ZERO(raltb, payload);
7782 	mlxsw_reg_raltb_virtual_router_set(payload, virtual_router);
7783 	mlxsw_reg_raltb_protocol_set(payload, protocol);
7784 	mlxsw_reg_raltb_tree_id_set(payload, tree_id);
7785 }
7786 
7787 /* RALUE - Router Algorithmic LPM Unicast Entry Register
7788  * -----------------------------------------------------
7789  * RALUE is used to configure and query LPM entries that serve
7790  * the Unicast protocols.
7791  */
7792 #define MLXSW_REG_RALUE_ID 0x8013
7793 #define MLXSW_REG_RALUE_LEN 0x38
7794 
7795 MLXSW_REG_DEFINE(ralue, MLXSW_REG_RALUE_ID, MLXSW_REG_RALUE_LEN);
7796 
7797 /* reg_ralue_protocol
7798  * Protocol.
7799  * Access: Index
7800  */
7801 MLXSW_ITEM32(reg, ralue, protocol, 0x00, 24, 4);
7802 
7803 enum mlxsw_reg_ralue_op {
7804 	/* Read operation. If entry doesn't exist, the operation fails. */
7805 	MLXSW_REG_RALUE_OP_QUERY_READ = 0,
7806 	/* Clear on read operation. Used to read entry and
7807 	 * clear Activity bit.
7808 	 */
7809 	MLXSW_REG_RALUE_OP_QUERY_CLEAR = 1,
7810 	/* Write operation. Used to write a new entry to the table. All RW
7811 	 * fields are written for new entry. Activity bit is set
7812 	 * for new entries.
7813 	 */
7814 	MLXSW_REG_RALUE_OP_WRITE_WRITE = 0,
7815 	/* Update operation. Used to update an existing route entry and
7816 	 * only update the RW fields that are detailed in the field
7817 	 * op_u_mask. If entry doesn't exist, the operation fails.
7818 	 */
7819 	MLXSW_REG_RALUE_OP_WRITE_UPDATE = 1,
7820 	/* Clear activity. The Activity bit (the field a) is cleared
7821 	 * for the entry.
7822 	 */
7823 	MLXSW_REG_RALUE_OP_WRITE_CLEAR = 2,
7824 	/* Delete operation. Used to delete an existing entry. If entry
7825 	 * doesn't exist, the operation fails.
7826 	 */
7827 	MLXSW_REG_RALUE_OP_WRITE_DELETE = 3,
7828 };
7829 
7830 /* reg_ralue_op
7831  * Operation.
7832  * Access: OP
7833  */
7834 MLXSW_ITEM32(reg, ralue, op, 0x00, 20, 3);
7835 
7836 /* reg_ralue_a
7837  * Activity. Set for new entries. Set if a packet lookup has hit on the
7838  * specific entry, only if the entry is a route. To clear the a bit, use
7839  * "clear activity" op.
7840  * Enabled by activity_dis in RGCR
7841  * Access: RO
7842  */
7843 MLXSW_ITEM32(reg, ralue, a, 0x00, 16, 1);
7844 
7845 /* reg_ralue_virtual_router
7846  * Virtual Router ID
7847  * Range is 0..cap_max_virtual_routers-1
7848  * Access: Index
7849  */
7850 MLXSW_ITEM32(reg, ralue, virtual_router, 0x04, 16, 16);
7851 
7852 #define MLXSW_REG_RALUE_OP_U_MASK_ENTRY_TYPE	BIT(0)
7853 #define MLXSW_REG_RALUE_OP_U_MASK_BMP_LEN	BIT(1)
7854 #define MLXSW_REG_RALUE_OP_U_MASK_ACTION	BIT(2)
7855 
7856 /* reg_ralue_op_u_mask
7857  * opcode update mask.
7858  * On read operation, this field is reserved.
7859  * This field is valid for update opcode, otherwise - reserved.
7860  * This field is a bitmask of the fields that should be updated.
7861  * Access: WO
7862  */
7863 MLXSW_ITEM32(reg, ralue, op_u_mask, 0x04, 8, 3);
7864 
7865 /* reg_ralue_prefix_len
7866  * Number of bits in the prefix of the LPM route.
7867  * Note that for IPv6 prefixes, if prefix_len>64 the entry consumes
7868  * two entries in the physical HW table.
7869  * Access: Index
7870  */
7871 MLXSW_ITEM32(reg, ralue, prefix_len, 0x08, 0, 8);
7872 
7873 /* reg_ralue_dip*
7874  * The prefix of the route or of the marker that the object of the LPM
7875  * is compared with. The most significant bits of the dip are the prefix.
7876  * The least significant bits must be '0' if the prefix_len is smaller
7877  * than 128 for IPv6 or smaller than 32 for IPv4.
7878  * IPv4 address uses bits dip[31:0] and bits dip[127:32] are reserved.
7879  * Access: Index
7880  */
7881 MLXSW_ITEM32(reg, ralue, dip4, 0x18, 0, 32);
7882 MLXSW_ITEM_BUF(reg, ralue, dip6, 0x0C, 16);
7883 
7884 enum mlxsw_reg_ralue_entry_type {
7885 	MLXSW_REG_RALUE_ENTRY_TYPE_MARKER_ENTRY = 1,
7886 	MLXSW_REG_RALUE_ENTRY_TYPE_ROUTE_ENTRY = 2,
7887 	MLXSW_REG_RALUE_ENTRY_TYPE_MARKER_AND_ROUTE_ENTRY = 3,
7888 };
7889 
7890 /* reg_ralue_entry_type
7891  * Entry type.
7892  * Note - for Marker entries, the action_type and action fields are reserved.
7893  * Access: RW
7894  */
7895 MLXSW_ITEM32(reg, ralue, entry_type, 0x1C, 30, 2);
7896 
7897 /* reg_ralue_bmp_len
7898  * The best match prefix length in the case that there is no match for
7899  * longer prefixes.
7900  * If (entry_type != MARKER_ENTRY), bmp_len must be equal to prefix_len
7901  * Note for any update operation with entry_type modification this
7902  * field must be set.
7903  * Access: RW
7904  */
7905 MLXSW_ITEM32(reg, ralue, bmp_len, 0x1C, 16, 8);
7906 
7907 enum mlxsw_reg_ralue_action_type {
7908 	MLXSW_REG_RALUE_ACTION_TYPE_REMOTE,
7909 	MLXSW_REG_RALUE_ACTION_TYPE_LOCAL,
7910 	MLXSW_REG_RALUE_ACTION_TYPE_IP2ME,
7911 };
7912 
7913 /* reg_ralue_action_type
7914  * Action Type
7915  * Indicates how the IP address is connected.
7916  * It can be connected to a local subnet through local_erif or can be
7917  * on a remote subnet connected through a next-hop router,
7918  * or transmitted to the CPU.
7919  * Reserved when entry_type = MARKER_ENTRY
7920  * Access: RW
7921  */
7922 MLXSW_ITEM32(reg, ralue, action_type, 0x1C, 0, 2);
7923 
7924 enum mlxsw_reg_ralue_trap_action {
7925 	MLXSW_REG_RALUE_TRAP_ACTION_NOP,
7926 	MLXSW_REG_RALUE_TRAP_ACTION_TRAP,
7927 	MLXSW_REG_RALUE_TRAP_ACTION_MIRROR_TO_CPU,
7928 	MLXSW_REG_RALUE_TRAP_ACTION_MIRROR,
7929 	MLXSW_REG_RALUE_TRAP_ACTION_DISCARD_ERROR,
7930 };
7931 
7932 /* reg_ralue_trap_action
7933  * Trap action.
7934  * For IP2ME action, only NOP and MIRROR are possible.
7935  * Access: RW
7936  */
7937 MLXSW_ITEM32(reg, ralue, trap_action, 0x20, 28, 4);
7938 
7939 /* reg_ralue_trap_id
7940  * Trap ID to be reported to CPU.
7941  * Trap ID is RTR_INGRESS0 or RTR_INGRESS1.
7942  * For trap_action of NOP, MIRROR and DISCARD_ERROR, trap_id is reserved.
7943  * Access: RW
7944  */
7945 MLXSW_ITEM32(reg, ralue, trap_id, 0x20, 0, 9);
7946 
7947 /* reg_ralue_adjacency_index
7948  * Points to the first entry of the group-based ECMP.
7949  * Only relevant in case of REMOTE action.
7950  * Access: RW
7951  */
7952 MLXSW_ITEM32(reg, ralue, adjacency_index, 0x24, 0, 24);
7953 
7954 /* reg_ralue_ecmp_size
7955  * Amount of sequential entries starting
7956  * from the adjacency_index (the number of ECMPs).
7957  * The valid range is 1-64, 512, 1024, 2048 and 4096.
7958  * Reserved when trap_action is TRAP or DISCARD_ERROR.
7959  * Only relevant in case of REMOTE action.
7960  * Access: RW
7961  */
7962 MLXSW_ITEM32(reg, ralue, ecmp_size, 0x28, 0, 13);
7963 
7964 /* reg_ralue_local_erif
7965  * Egress Router Interface.
7966  * Only relevant in case of LOCAL action.
7967  * Access: RW
7968  */
7969 MLXSW_ITEM32(reg, ralue, local_erif, 0x24, 0, 16);
7970 
7971 /* reg_ralue_ip2me_v
7972  * Valid bit for the tunnel_ptr field.
7973  * If valid = 0 then trap to CPU as IP2ME trap ID.
7974  * If valid = 1 and the packet format allows NVE or IPinIP tunnel
7975  * decapsulation then tunnel decapsulation is done.
7976  * If valid = 1 and packet format does not allow NVE or IPinIP tunnel
7977  * decapsulation then trap as IP2ME trap ID.
7978  * Only relevant in case of IP2ME action.
7979  * Access: RW
7980  */
7981 MLXSW_ITEM32(reg, ralue, ip2me_v, 0x24, 31, 1);
7982 
7983 /* reg_ralue_ip2me_tunnel_ptr
7984  * Tunnel Pointer for NVE or IPinIP tunnel decapsulation.
7985  * For Spectrum, pointer to KVD Linear.
7986  * Only relevant in case of IP2ME action.
7987  * Access: RW
7988  */
7989 MLXSW_ITEM32(reg, ralue, ip2me_tunnel_ptr, 0x24, 0, 24);
7990 
7991 static inline void mlxsw_reg_ralue_pack(char *payload,
7992 					enum mlxsw_reg_ralxx_protocol protocol,
7993 					enum mlxsw_reg_ralue_op op,
7994 					u16 virtual_router, u8 prefix_len)
7995 {
7996 	MLXSW_REG_ZERO(ralue, payload);
7997 	mlxsw_reg_ralue_protocol_set(payload, protocol);
7998 	mlxsw_reg_ralue_op_set(payload, op);
7999 	mlxsw_reg_ralue_virtual_router_set(payload, virtual_router);
8000 	mlxsw_reg_ralue_prefix_len_set(payload, prefix_len);
8001 	mlxsw_reg_ralue_entry_type_set(payload,
8002 				       MLXSW_REG_RALUE_ENTRY_TYPE_ROUTE_ENTRY);
8003 	mlxsw_reg_ralue_bmp_len_set(payload, prefix_len);
8004 }
8005 
8006 static inline void mlxsw_reg_ralue_pack4(char *payload,
8007 					 enum mlxsw_reg_ralxx_protocol protocol,
8008 					 enum mlxsw_reg_ralue_op op,
8009 					 u16 virtual_router, u8 prefix_len,
8010 					 u32 dip)
8011 {
8012 	mlxsw_reg_ralue_pack(payload, protocol, op, virtual_router, prefix_len);
8013 	mlxsw_reg_ralue_dip4_set(payload, dip);
8014 }
8015 
8016 static inline void mlxsw_reg_ralue_pack6(char *payload,
8017 					 enum mlxsw_reg_ralxx_protocol protocol,
8018 					 enum mlxsw_reg_ralue_op op,
8019 					 u16 virtual_router, u8 prefix_len,
8020 					 const void *dip)
8021 {
8022 	mlxsw_reg_ralue_pack(payload, protocol, op, virtual_router, prefix_len);
8023 	mlxsw_reg_ralue_dip6_memcpy_to(payload, dip);
8024 }
8025 
8026 static inline void
8027 mlxsw_reg_ralue_act_remote_pack(char *payload,
8028 				enum mlxsw_reg_ralue_trap_action trap_action,
8029 				u16 trap_id, u32 adjacency_index, u16 ecmp_size)
8030 {
8031 	mlxsw_reg_ralue_action_type_set(payload,
8032 					MLXSW_REG_RALUE_ACTION_TYPE_REMOTE);
8033 	mlxsw_reg_ralue_trap_action_set(payload, trap_action);
8034 	mlxsw_reg_ralue_trap_id_set(payload, trap_id);
8035 	mlxsw_reg_ralue_adjacency_index_set(payload, adjacency_index);
8036 	mlxsw_reg_ralue_ecmp_size_set(payload, ecmp_size);
8037 }
8038 
8039 static inline void
8040 mlxsw_reg_ralue_act_local_pack(char *payload,
8041 			       enum mlxsw_reg_ralue_trap_action trap_action,
8042 			       u16 trap_id, u16 local_erif)
8043 {
8044 	mlxsw_reg_ralue_action_type_set(payload,
8045 					MLXSW_REG_RALUE_ACTION_TYPE_LOCAL);
8046 	mlxsw_reg_ralue_trap_action_set(payload, trap_action);
8047 	mlxsw_reg_ralue_trap_id_set(payload, trap_id);
8048 	mlxsw_reg_ralue_local_erif_set(payload, local_erif);
8049 }
8050 
8051 static inline void
8052 mlxsw_reg_ralue_act_ip2me_pack(char *payload)
8053 {
8054 	mlxsw_reg_ralue_action_type_set(payload,
8055 					MLXSW_REG_RALUE_ACTION_TYPE_IP2ME);
8056 }
8057 
8058 static inline void
8059 mlxsw_reg_ralue_act_ip2me_tun_pack(char *payload, u32 tunnel_ptr)
8060 {
8061 	mlxsw_reg_ralue_action_type_set(payload,
8062 					MLXSW_REG_RALUE_ACTION_TYPE_IP2ME);
8063 	mlxsw_reg_ralue_ip2me_v_set(payload, 1);
8064 	mlxsw_reg_ralue_ip2me_tunnel_ptr_set(payload, tunnel_ptr);
8065 }
8066 
8067 /* RAUHT - Router Algorithmic LPM Unicast Host Table Register
8068  * ----------------------------------------------------------
8069  * The RAUHT register is used to configure and query the Unicast Host table in
8070  * devices that implement the Algorithmic LPM.
8071  */
8072 #define MLXSW_REG_RAUHT_ID 0x8014
8073 #define MLXSW_REG_RAUHT_LEN 0x74
8074 
8075 MLXSW_REG_DEFINE(rauht, MLXSW_REG_RAUHT_ID, MLXSW_REG_RAUHT_LEN);
8076 
8077 enum mlxsw_reg_rauht_type {
8078 	MLXSW_REG_RAUHT_TYPE_IPV4,
8079 	MLXSW_REG_RAUHT_TYPE_IPV6,
8080 };
8081 
8082 /* reg_rauht_type
8083  * Access: Index
8084  */
8085 MLXSW_ITEM32(reg, rauht, type, 0x00, 24, 2);
8086 
8087 enum mlxsw_reg_rauht_op {
8088 	MLXSW_REG_RAUHT_OP_QUERY_READ = 0,
8089 	/* Read operation */
8090 	MLXSW_REG_RAUHT_OP_QUERY_CLEAR_ON_READ = 1,
8091 	/* Clear on read operation. Used to read entry and clear
8092 	 * activity bit.
8093 	 */
8094 	MLXSW_REG_RAUHT_OP_WRITE_ADD = 0,
8095 	/* Add. Used to write a new entry to the table. All R/W fields are
8096 	 * relevant for new entry. Activity bit is set for new entries.
8097 	 */
8098 	MLXSW_REG_RAUHT_OP_WRITE_UPDATE = 1,
8099 	/* Update action. Used to update an existing route entry and
8100 	 * only update the following fields:
8101 	 * trap_action, trap_id, mac, counter_set_type, counter_index
8102 	 */
8103 	MLXSW_REG_RAUHT_OP_WRITE_CLEAR_ACTIVITY = 2,
8104 	/* Clear activity. A bit is cleared for the entry. */
8105 	MLXSW_REG_RAUHT_OP_WRITE_DELETE = 3,
8106 	/* Delete entry */
8107 	MLXSW_REG_RAUHT_OP_WRITE_DELETE_ALL = 4,
8108 	/* Delete all host entries on a RIF. In this command, dip
8109 	 * field is reserved.
8110 	 */
8111 };
8112 
8113 /* reg_rauht_op
8114  * Access: OP
8115  */
8116 MLXSW_ITEM32(reg, rauht, op, 0x00, 20, 3);
8117 
8118 /* reg_rauht_a
8119  * Activity. Set for new entries. Set if a packet lookup has hit on
8120  * the specific entry.
8121  * To clear the a bit, use "clear activity" op.
8122  * Enabled by activity_dis in RGCR
8123  * Access: RO
8124  */
8125 MLXSW_ITEM32(reg, rauht, a, 0x00, 16, 1);
8126 
8127 /* reg_rauht_rif
8128  * Router Interface
8129  * Access: Index
8130  */
8131 MLXSW_ITEM32(reg, rauht, rif, 0x00, 0, 16);
8132 
8133 /* reg_rauht_dip*
8134  * Destination address.
8135  * Access: Index
8136  */
8137 MLXSW_ITEM32(reg, rauht, dip4, 0x1C, 0x0, 32);
8138 MLXSW_ITEM_BUF(reg, rauht, dip6, 0x10, 16);
8139 
8140 enum mlxsw_reg_rauht_trap_action {
8141 	MLXSW_REG_RAUHT_TRAP_ACTION_NOP,
8142 	MLXSW_REG_RAUHT_TRAP_ACTION_TRAP,
8143 	MLXSW_REG_RAUHT_TRAP_ACTION_MIRROR_TO_CPU,
8144 	MLXSW_REG_RAUHT_TRAP_ACTION_MIRROR,
8145 	MLXSW_REG_RAUHT_TRAP_ACTION_DISCARD_ERRORS,
8146 };
8147 
8148 /* reg_rauht_trap_action
8149  * Access: RW
8150  */
8151 MLXSW_ITEM32(reg, rauht, trap_action, 0x60, 28, 4);
8152 
8153 enum mlxsw_reg_rauht_trap_id {
8154 	MLXSW_REG_RAUHT_TRAP_ID_RTR_EGRESS0,
8155 	MLXSW_REG_RAUHT_TRAP_ID_RTR_EGRESS1,
8156 };
8157 
8158 /* reg_rauht_trap_id
8159  * Trap ID to be reported to CPU.
8160  * Trap-ID is RTR_EGRESS0 or RTR_EGRESS1.
8161  * For trap_action of NOP, MIRROR and DISCARD_ERROR,
8162  * trap_id is reserved.
8163  * Access: RW
8164  */
8165 MLXSW_ITEM32(reg, rauht, trap_id, 0x60, 0, 9);
8166 
8167 /* reg_rauht_counter_set_type
8168  * Counter set type for flow counters
8169  * Access: RW
8170  */
8171 MLXSW_ITEM32(reg, rauht, counter_set_type, 0x68, 24, 8);
8172 
8173 /* reg_rauht_counter_index
8174  * Counter index for flow counters
8175  * Access: RW
8176  */
8177 MLXSW_ITEM32(reg, rauht, counter_index, 0x68, 0, 24);
8178 
8179 /* reg_rauht_mac
8180  * MAC address.
8181  * Access: RW
8182  */
8183 MLXSW_ITEM_BUF(reg, rauht, mac, 0x6E, 6);
8184 
8185 static inline void mlxsw_reg_rauht_pack(char *payload,
8186 					enum mlxsw_reg_rauht_op op, u16 rif,
8187 					const char *mac)
8188 {
8189 	MLXSW_REG_ZERO(rauht, payload);
8190 	mlxsw_reg_rauht_op_set(payload, op);
8191 	mlxsw_reg_rauht_rif_set(payload, rif);
8192 	mlxsw_reg_rauht_mac_memcpy_to(payload, mac);
8193 }
8194 
8195 static inline void mlxsw_reg_rauht_pack4(char *payload,
8196 					 enum mlxsw_reg_rauht_op op, u16 rif,
8197 					 const char *mac, u32 dip)
8198 {
8199 	mlxsw_reg_rauht_pack(payload, op, rif, mac);
8200 	mlxsw_reg_rauht_dip4_set(payload, dip);
8201 }
8202 
8203 static inline void mlxsw_reg_rauht_pack6(char *payload,
8204 					 enum mlxsw_reg_rauht_op op, u16 rif,
8205 					 const char *mac, const char *dip)
8206 {
8207 	mlxsw_reg_rauht_pack(payload, op, rif, mac);
8208 	mlxsw_reg_rauht_type_set(payload, MLXSW_REG_RAUHT_TYPE_IPV6);
8209 	mlxsw_reg_rauht_dip6_memcpy_to(payload, dip);
8210 }
8211 
8212 static inline void mlxsw_reg_rauht_pack_counter(char *payload,
8213 						u64 counter_index)
8214 {
8215 	mlxsw_reg_rauht_counter_index_set(payload, counter_index);
8216 	mlxsw_reg_rauht_counter_set_type_set(payload,
8217 					     MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES);
8218 }
8219 
8220 /* RALEU - Router Algorithmic LPM ECMP Update Register
8221  * ---------------------------------------------------
8222  * The register enables updating the ECMP section in the action for multiple
8223  * LPM Unicast entries in a single operation. The update is executed to
8224  * all entries of a {virtual router, protocol} tuple using the same ECMP group.
8225  */
8226 #define MLXSW_REG_RALEU_ID 0x8015
8227 #define MLXSW_REG_RALEU_LEN 0x28
8228 
8229 MLXSW_REG_DEFINE(raleu, MLXSW_REG_RALEU_ID, MLXSW_REG_RALEU_LEN);
8230 
8231 /* reg_raleu_protocol
8232  * Protocol.
8233  * Access: Index
8234  */
8235 MLXSW_ITEM32(reg, raleu, protocol, 0x00, 24, 4);
8236 
8237 /* reg_raleu_virtual_router
8238  * Virtual Router ID
8239  * Range is 0..cap_max_virtual_routers-1
8240  * Access: Index
8241  */
8242 MLXSW_ITEM32(reg, raleu, virtual_router, 0x00, 0, 16);
8243 
8244 /* reg_raleu_adjacency_index
8245  * Adjacency Index used for matching on the existing entries.
8246  * Access: Index
8247  */
8248 MLXSW_ITEM32(reg, raleu, adjacency_index, 0x10, 0, 24);
8249 
8250 /* reg_raleu_ecmp_size
8251  * ECMP Size used for matching on the existing entries.
8252  * Access: Index
8253  */
8254 MLXSW_ITEM32(reg, raleu, ecmp_size, 0x14, 0, 13);
8255 
8256 /* reg_raleu_new_adjacency_index
8257  * New Adjacency Index.
8258  * Access: WO
8259  */
8260 MLXSW_ITEM32(reg, raleu, new_adjacency_index, 0x20, 0, 24);
8261 
8262 /* reg_raleu_new_ecmp_size
8263  * New ECMP Size.
8264  * Access: WO
8265  */
8266 MLXSW_ITEM32(reg, raleu, new_ecmp_size, 0x24, 0, 13);
8267 
8268 static inline void mlxsw_reg_raleu_pack(char *payload,
8269 					enum mlxsw_reg_ralxx_protocol protocol,
8270 					u16 virtual_router,
8271 					u32 adjacency_index, u16 ecmp_size,
8272 					u32 new_adjacency_index,
8273 					u16 new_ecmp_size)
8274 {
8275 	MLXSW_REG_ZERO(raleu, payload);
8276 	mlxsw_reg_raleu_protocol_set(payload, protocol);
8277 	mlxsw_reg_raleu_virtual_router_set(payload, virtual_router);
8278 	mlxsw_reg_raleu_adjacency_index_set(payload, adjacency_index);
8279 	mlxsw_reg_raleu_ecmp_size_set(payload, ecmp_size);
8280 	mlxsw_reg_raleu_new_adjacency_index_set(payload, new_adjacency_index);
8281 	mlxsw_reg_raleu_new_ecmp_size_set(payload, new_ecmp_size);
8282 }
8283 
8284 /* RAUHTD - Router Algorithmic LPM Unicast Host Table Dump Register
8285  * ----------------------------------------------------------------
8286  * The RAUHTD register allows dumping entries from the Router Unicast Host
8287  * Table. For a given session an entry is dumped no more than one time. The
8288  * first RAUHTD access after reset is a new session. A session ends when the
8289  * num_rec response is smaller than num_rec request or for IPv4 when the
8290  * num_entries is smaller than 4. The clear activity affect the current session
8291  * or the last session if a new session has not started.
8292  */
8293 #define MLXSW_REG_RAUHTD_ID 0x8018
8294 #define MLXSW_REG_RAUHTD_BASE_LEN 0x20
8295 #define MLXSW_REG_RAUHTD_REC_LEN 0x20
8296 #define MLXSW_REG_RAUHTD_REC_MAX_NUM 32
8297 #define MLXSW_REG_RAUHTD_LEN (MLXSW_REG_RAUHTD_BASE_LEN + \
8298 		MLXSW_REG_RAUHTD_REC_MAX_NUM * MLXSW_REG_RAUHTD_REC_LEN)
8299 #define MLXSW_REG_RAUHTD_IPV4_ENT_PER_REC 4
8300 
8301 MLXSW_REG_DEFINE(rauhtd, MLXSW_REG_RAUHTD_ID, MLXSW_REG_RAUHTD_LEN);
8302 
8303 #define MLXSW_REG_RAUHTD_FILTER_A BIT(0)
8304 #define MLXSW_REG_RAUHTD_FILTER_RIF BIT(3)
8305 
8306 /* reg_rauhtd_filter_fields
8307  * if a bit is '0' then the relevant field is ignored and dump is done
8308  * regardless of the field value
8309  * Bit0 - filter by activity: entry_a
8310  * Bit3 - filter by entry rip: entry_rif
8311  * Access: Index
8312  */
8313 MLXSW_ITEM32(reg, rauhtd, filter_fields, 0x00, 0, 8);
8314 
8315 enum mlxsw_reg_rauhtd_op {
8316 	MLXSW_REG_RAUHTD_OP_DUMP,
8317 	MLXSW_REG_RAUHTD_OP_DUMP_AND_CLEAR,
8318 };
8319 
8320 /* reg_rauhtd_op
8321  * Access: OP
8322  */
8323 MLXSW_ITEM32(reg, rauhtd, op, 0x04, 24, 2);
8324 
8325 /* reg_rauhtd_num_rec
8326  * At request: number of records requested
8327  * At response: number of records dumped
8328  * For IPv4, each record has 4 entries at request and up to 4 entries
8329  * at response
8330  * Range is 0..MLXSW_REG_RAUHTD_REC_MAX_NUM
8331  * Access: Index
8332  */
8333 MLXSW_ITEM32(reg, rauhtd, num_rec, 0x04, 0, 8);
8334 
8335 /* reg_rauhtd_entry_a
8336  * Dump only if activity has value of entry_a
8337  * Reserved if filter_fields bit0 is '0'
8338  * Access: Index
8339  */
8340 MLXSW_ITEM32(reg, rauhtd, entry_a, 0x08, 16, 1);
8341 
8342 enum mlxsw_reg_rauhtd_type {
8343 	MLXSW_REG_RAUHTD_TYPE_IPV4,
8344 	MLXSW_REG_RAUHTD_TYPE_IPV6,
8345 };
8346 
8347 /* reg_rauhtd_type
8348  * Dump only if record type is:
8349  * 0 - IPv4
8350  * 1 - IPv6
8351  * Access: Index
8352  */
8353 MLXSW_ITEM32(reg, rauhtd, type, 0x08, 0, 4);
8354 
8355 /* reg_rauhtd_entry_rif
8356  * Dump only if RIF has value of entry_rif
8357  * Reserved if filter_fields bit3 is '0'
8358  * Access: Index
8359  */
8360 MLXSW_ITEM32(reg, rauhtd, entry_rif, 0x0C, 0, 16);
8361 
8362 static inline void mlxsw_reg_rauhtd_pack(char *payload,
8363 					 enum mlxsw_reg_rauhtd_type type)
8364 {
8365 	MLXSW_REG_ZERO(rauhtd, payload);
8366 	mlxsw_reg_rauhtd_filter_fields_set(payload, MLXSW_REG_RAUHTD_FILTER_A);
8367 	mlxsw_reg_rauhtd_op_set(payload, MLXSW_REG_RAUHTD_OP_DUMP_AND_CLEAR);
8368 	mlxsw_reg_rauhtd_num_rec_set(payload, MLXSW_REG_RAUHTD_REC_MAX_NUM);
8369 	mlxsw_reg_rauhtd_entry_a_set(payload, 1);
8370 	mlxsw_reg_rauhtd_type_set(payload, type);
8371 }
8372 
8373 /* reg_rauhtd_ipv4_rec_num_entries
8374  * Number of valid entries in this record:
8375  * 0 - 1 valid entry
8376  * 1 - 2 valid entries
8377  * 2 - 3 valid entries
8378  * 3 - 4 valid entries
8379  * Access: RO
8380  */
8381 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_rec_num_entries,
8382 		     MLXSW_REG_RAUHTD_BASE_LEN, 28, 2,
8383 		     MLXSW_REG_RAUHTD_REC_LEN, 0x00, false);
8384 
8385 /* reg_rauhtd_rec_type
8386  * Record type.
8387  * 0 - IPv4
8388  * 1 - IPv6
8389  * Access: RO
8390  */
8391 MLXSW_ITEM32_INDEXED(reg, rauhtd, rec_type, MLXSW_REG_RAUHTD_BASE_LEN, 24, 2,
8392 		     MLXSW_REG_RAUHTD_REC_LEN, 0x00, false);
8393 
8394 #define MLXSW_REG_RAUHTD_IPV4_ENT_LEN 0x8
8395 
8396 /* reg_rauhtd_ipv4_ent_a
8397  * Activity. Set for new entries. Set if a packet lookup has hit on the
8398  * specific entry.
8399  * Access: RO
8400  */
8401 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_a, MLXSW_REG_RAUHTD_BASE_LEN, 16, 1,
8402 		     MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x00, false);
8403 
8404 /* reg_rauhtd_ipv4_ent_rif
8405  * Router interface.
8406  * Access: RO
8407  */
8408 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_rif, MLXSW_REG_RAUHTD_BASE_LEN, 0,
8409 		     16, MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x00, false);
8410 
8411 /* reg_rauhtd_ipv4_ent_dip
8412  * Destination IPv4 address.
8413  * Access: RO
8414  */
8415 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_dip, MLXSW_REG_RAUHTD_BASE_LEN, 0,
8416 		     32, MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x04, false);
8417 
8418 #define MLXSW_REG_RAUHTD_IPV6_ENT_LEN 0x20
8419 
8420 /* reg_rauhtd_ipv6_ent_a
8421  * Activity. Set for new entries. Set if a packet lookup has hit on the
8422  * specific entry.
8423  * Access: RO
8424  */
8425 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv6_ent_a, MLXSW_REG_RAUHTD_BASE_LEN, 16, 1,
8426 		     MLXSW_REG_RAUHTD_IPV6_ENT_LEN, 0x00, false);
8427 
8428 /* reg_rauhtd_ipv6_ent_rif
8429  * Router interface.
8430  * Access: RO
8431  */
8432 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv6_ent_rif, MLXSW_REG_RAUHTD_BASE_LEN, 0,
8433 		     16, MLXSW_REG_RAUHTD_IPV6_ENT_LEN, 0x00, false);
8434 
8435 /* reg_rauhtd_ipv6_ent_dip
8436  * Destination IPv6 address.
8437  * Access: RO
8438  */
8439 MLXSW_ITEM_BUF_INDEXED(reg, rauhtd, ipv6_ent_dip, MLXSW_REG_RAUHTD_BASE_LEN,
8440 		       16, MLXSW_REG_RAUHTD_IPV6_ENT_LEN, 0x10);
8441 
8442 static inline void mlxsw_reg_rauhtd_ent_ipv4_unpack(char *payload,
8443 						    int ent_index, u16 *p_rif,
8444 						    u32 *p_dip)
8445 {
8446 	*p_rif = mlxsw_reg_rauhtd_ipv4_ent_rif_get(payload, ent_index);
8447 	*p_dip = mlxsw_reg_rauhtd_ipv4_ent_dip_get(payload, ent_index);
8448 }
8449 
8450 static inline void mlxsw_reg_rauhtd_ent_ipv6_unpack(char *payload,
8451 						    int rec_index, u16 *p_rif,
8452 						    char *p_dip)
8453 {
8454 	*p_rif = mlxsw_reg_rauhtd_ipv6_ent_rif_get(payload, rec_index);
8455 	mlxsw_reg_rauhtd_ipv6_ent_dip_memcpy_from(payload, rec_index, p_dip);
8456 }
8457 
8458 /* RTDP - Routing Tunnel Decap Properties Register
8459  * -----------------------------------------------
8460  * The RTDP register is used for configuring the tunnel decap properties of NVE
8461  * and IPinIP.
8462  */
8463 #define MLXSW_REG_RTDP_ID 0x8020
8464 #define MLXSW_REG_RTDP_LEN 0x44
8465 
8466 MLXSW_REG_DEFINE(rtdp, MLXSW_REG_RTDP_ID, MLXSW_REG_RTDP_LEN);
8467 
8468 enum mlxsw_reg_rtdp_type {
8469 	MLXSW_REG_RTDP_TYPE_NVE,
8470 	MLXSW_REG_RTDP_TYPE_IPIP,
8471 };
8472 
8473 /* reg_rtdp_type
8474  * Type of the RTDP entry as per enum mlxsw_reg_rtdp_type.
8475  * Access: RW
8476  */
8477 MLXSW_ITEM32(reg, rtdp, type, 0x00, 28, 4);
8478 
8479 /* reg_rtdp_tunnel_index
8480  * Index to the Decap entry.
8481  * For Spectrum, Index to KVD Linear.
8482  * Access: Index
8483  */
8484 MLXSW_ITEM32(reg, rtdp, tunnel_index, 0x00, 0, 24);
8485 
8486 /* reg_rtdp_egress_router_interface
8487  * Underlay egress router interface.
8488  * Valid range is from 0 to cap_max_router_interfaces - 1
8489  * Access: RW
8490  */
8491 MLXSW_ITEM32(reg, rtdp, egress_router_interface, 0x40, 0, 16);
8492 
8493 /* IPinIP */
8494 
8495 /* reg_rtdp_ipip_irif
8496  * Ingress Router Interface for the overlay router
8497  * Access: RW
8498  */
8499 MLXSW_ITEM32(reg, rtdp, ipip_irif, 0x04, 16, 16);
8500 
8501 enum mlxsw_reg_rtdp_ipip_sip_check {
8502 	/* No sip checks. */
8503 	MLXSW_REG_RTDP_IPIP_SIP_CHECK_NO,
8504 	/* Filter packet if underlay is not IPv4 or if underlay SIP does not
8505 	 * equal ipv4_usip.
8506 	 */
8507 	MLXSW_REG_RTDP_IPIP_SIP_CHECK_FILTER_IPV4,
8508 	/* Filter packet if underlay is not IPv6 or if underlay SIP does not
8509 	 * equal ipv6_usip.
8510 	 */
8511 	MLXSW_REG_RTDP_IPIP_SIP_CHECK_FILTER_IPV6 = 3,
8512 };
8513 
8514 /* reg_rtdp_ipip_sip_check
8515  * SIP check to perform. If decapsulation failed due to these configurations
8516  * then trap_id is IPIP_DECAP_ERROR.
8517  * Access: RW
8518  */
8519 MLXSW_ITEM32(reg, rtdp, ipip_sip_check, 0x04, 0, 3);
8520 
8521 /* If set, allow decapsulation of IPinIP (without GRE). */
8522 #define MLXSW_REG_RTDP_IPIP_TYPE_CHECK_ALLOW_IPIP	BIT(0)
8523 /* If set, allow decapsulation of IPinGREinIP without a key. */
8524 #define MLXSW_REG_RTDP_IPIP_TYPE_CHECK_ALLOW_GRE	BIT(1)
8525 /* If set, allow decapsulation of IPinGREinIP with a key. */
8526 #define MLXSW_REG_RTDP_IPIP_TYPE_CHECK_ALLOW_GRE_KEY	BIT(2)
8527 
8528 /* reg_rtdp_ipip_type_check
8529  * Flags as per MLXSW_REG_RTDP_IPIP_TYPE_CHECK_*. If decapsulation failed due to
8530  * these configurations then trap_id is IPIP_DECAP_ERROR.
8531  * Access: RW
8532  */
8533 MLXSW_ITEM32(reg, rtdp, ipip_type_check, 0x08, 24, 3);
8534 
8535 /* reg_rtdp_ipip_gre_key_check
8536  * Whether GRE key should be checked. When check is enabled:
8537  * - A packet received as IPinIP (without GRE) will always pass.
8538  * - A packet received as IPinGREinIP without a key will not pass the check.
8539  * - A packet received as IPinGREinIP with a key will pass the check only if the
8540  *   key in the packet is equal to expected_gre_key.
8541  * If decapsulation failed due to GRE key then trap_id is IPIP_DECAP_ERROR.
8542  * Access: RW
8543  */
8544 MLXSW_ITEM32(reg, rtdp, ipip_gre_key_check, 0x08, 23, 1);
8545 
8546 /* reg_rtdp_ipip_ipv4_usip
8547  * Underlay IPv4 address for ipv4 source address check.
8548  * Reserved when sip_check is not '1'.
8549  * Access: RW
8550  */
8551 MLXSW_ITEM32(reg, rtdp, ipip_ipv4_usip, 0x0C, 0, 32);
8552 
8553 /* reg_rtdp_ipip_ipv6_usip_ptr
8554  * This field is valid when sip_check is "sipv6 check explicitly". This is a
8555  * pointer to the IPv6 DIP which is configured by RIPS. For Spectrum, the index
8556  * is to the KVD linear.
8557  * Reserved when sip_check is not MLXSW_REG_RTDP_IPIP_SIP_CHECK_FILTER_IPV6.
8558  * Access: RW
8559  */
8560 MLXSW_ITEM32(reg, rtdp, ipip_ipv6_usip_ptr, 0x10, 0, 24);
8561 
8562 /* reg_rtdp_ipip_expected_gre_key
8563  * GRE key for checking.
8564  * Reserved when gre_key_check is '0'.
8565  * Access: RW
8566  */
8567 MLXSW_ITEM32(reg, rtdp, ipip_expected_gre_key, 0x14, 0, 32);
8568 
8569 static inline void mlxsw_reg_rtdp_pack(char *payload,
8570 				       enum mlxsw_reg_rtdp_type type,
8571 				       u32 tunnel_index)
8572 {
8573 	MLXSW_REG_ZERO(rtdp, payload);
8574 	mlxsw_reg_rtdp_type_set(payload, type);
8575 	mlxsw_reg_rtdp_tunnel_index_set(payload, tunnel_index);
8576 }
8577 
8578 static inline void
8579 mlxsw_reg_rtdp_ipip_pack(char *payload, u16 irif,
8580 			 enum mlxsw_reg_rtdp_ipip_sip_check sip_check,
8581 			 unsigned int type_check, bool gre_key_check,
8582 			 u32 expected_gre_key)
8583 {
8584 	mlxsw_reg_rtdp_ipip_irif_set(payload, irif);
8585 	mlxsw_reg_rtdp_ipip_sip_check_set(payload, sip_check);
8586 	mlxsw_reg_rtdp_ipip_type_check_set(payload, type_check);
8587 	mlxsw_reg_rtdp_ipip_gre_key_check_set(payload, gre_key_check);
8588 	mlxsw_reg_rtdp_ipip_expected_gre_key_set(payload, expected_gre_key);
8589 }
8590 
8591 static inline void
8592 mlxsw_reg_rtdp_ipip4_pack(char *payload, u16 irif,
8593 			  enum mlxsw_reg_rtdp_ipip_sip_check sip_check,
8594 			  unsigned int type_check, bool gre_key_check,
8595 			  u32 ipv4_usip, u32 expected_gre_key)
8596 {
8597 	mlxsw_reg_rtdp_ipip_pack(payload, irif, sip_check, type_check,
8598 				 gre_key_check, expected_gre_key);
8599 	mlxsw_reg_rtdp_ipip_ipv4_usip_set(payload, ipv4_usip);
8600 }
8601 
8602 static inline void
8603 mlxsw_reg_rtdp_ipip6_pack(char *payload, u16 irif,
8604 			  enum mlxsw_reg_rtdp_ipip_sip_check sip_check,
8605 			  unsigned int type_check, bool gre_key_check,
8606 			  u32 ipv6_usip_ptr, u32 expected_gre_key)
8607 {
8608 	mlxsw_reg_rtdp_ipip_pack(payload, irif, sip_check, type_check,
8609 				 gre_key_check, expected_gre_key);
8610 	mlxsw_reg_rtdp_ipip_ipv6_usip_ptr_set(payload, ipv6_usip_ptr);
8611 }
8612 
8613 /* RIPS - Router IP version Six Register
8614  * -------------------------------------
8615  * The RIPS register is used to store IPv6 addresses for use by the NVE and
8616  * IPinIP
8617  */
8618 #define MLXSW_REG_RIPS_ID 0x8021
8619 #define MLXSW_REG_RIPS_LEN 0x14
8620 
8621 MLXSW_REG_DEFINE(rips, MLXSW_REG_RIPS_ID, MLXSW_REG_RIPS_LEN);
8622 
8623 /* reg_rips_index
8624  * Index to IPv6 address.
8625  * For Spectrum, the index is to the KVD linear.
8626  * Access: Index
8627  */
8628 MLXSW_ITEM32(reg, rips, index, 0x00, 0, 24);
8629 
8630 /* reg_rips_ipv6
8631  * IPv6 address
8632  * Access: RW
8633  */
8634 MLXSW_ITEM_BUF(reg, rips, ipv6, 0x04, 16);
8635 
8636 static inline void mlxsw_reg_rips_pack(char *payload, u32 index,
8637 				       const struct in6_addr *ipv6)
8638 {
8639 	MLXSW_REG_ZERO(rips, payload);
8640 	mlxsw_reg_rips_index_set(payload, index);
8641 	mlxsw_reg_rips_ipv6_memcpy_to(payload, (const char *)ipv6);
8642 }
8643 
8644 /* RATRAD - Router Adjacency Table Activity Dump Register
8645  * ------------------------------------------------------
8646  * The RATRAD register is used to dump and optionally clear activity bits of
8647  * router adjacency table entries.
8648  */
8649 #define MLXSW_REG_RATRAD_ID 0x8022
8650 #define MLXSW_REG_RATRAD_LEN 0x210
8651 
8652 MLXSW_REG_DEFINE(ratrad, MLXSW_REG_RATRAD_ID, MLXSW_REG_RATRAD_LEN);
8653 
8654 enum {
8655 	/* Read activity */
8656 	MLXSW_REG_RATRAD_OP_READ_ACTIVITY,
8657 	/* Read and clear activity */
8658 	MLXSW_REG_RATRAD_OP_READ_CLEAR_ACTIVITY,
8659 };
8660 
8661 /* reg_ratrad_op
8662  * Access: Operation
8663  */
8664 MLXSW_ITEM32(reg, ratrad, op, 0x00, 30, 2);
8665 
8666 /* reg_ratrad_ecmp_size
8667  * ecmp_size is the amount of sequential entries from adjacency_index. Valid
8668  * ranges:
8669  * Spectrum-1: 32-64, 512, 1024, 2048, 4096
8670  * Spectrum-2/3: 32-128, 256, 512, 1024, 2048, 4096
8671  * Access: Index
8672  */
8673 MLXSW_ITEM32(reg, ratrad, ecmp_size, 0x00, 0, 13);
8674 
8675 /* reg_ratrad_adjacency_index
8676  * Index into the adjacency table.
8677  * Access: Index
8678  */
8679 MLXSW_ITEM32(reg, ratrad, adjacency_index, 0x04, 0, 24);
8680 
8681 /* reg_ratrad_activity_vector
8682  * Activity bit per adjacency index.
8683  * Bits higher than ecmp_size are reserved.
8684  * Access: RO
8685  */
8686 MLXSW_ITEM_BIT_ARRAY(reg, ratrad, activity_vector, 0x10, 0x200, 1);
8687 
8688 static inline void mlxsw_reg_ratrad_pack(char *payload, u32 adjacency_index,
8689 					 u16 ecmp_size)
8690 {
8691 	MLXSW_REG_ZERO(ratrad, payload);
8692 	mlxsw_reg_ratrad_op_set(payload,
8693 				MLXSW_REG_RATRAD_OP_READ_CLEAR_ACTIVITY);
8694 	mlxsw_reg_ratrad_ecmp_size_set(payload, ecmp_size);
8695 	mlxsw_reg_ratrad_adjacency_index_set(payload, adjacency_index);
8696 }
8697 
8698 /* RIGR-V2 - Router Interface Group Register Version 2
8699  * ---------------------------------------------------
8700  * The RIGR_V2 register is used to add, remove and query egress interface list
8701  * of a multicast forwarding entry.
8702  */
8703 #define MLXSW_REG_RIGR2_ID 0x8023
8704 #define MLXSW_REG_RIGR2_LEN 0xB0
8705 
8706 #define MLXSW_REG_RIGR2_MAX_ERIFS 32
8707 
8708 MLXSW_REG_DEFINE(rigr2, MLXSW_REG_RIGR2_ID, MLXSW_REG_RIGR2_LEN);
8709 
8710 /* reg_rigr2_rigr_index
8711  * KVD Linear index.
8712  * Access: Index
8713  */
8714 MLXSW_ITEM32(reg, rigr2, rigr_index, 0x04, 0, 24);
8715 
8716 /* reg_rigr2_vnext
8717  * Next RIGR Index is valid.
8718  * Access: RW
8719  */
8720 MLXSW_ITEM32(reg, rigr2, vnext, 0x08, 31, 1);
8721 
8722 /* reg_rigr2_next_rigr_index
8723  * Next RIGR Index. The index is to the KVD linear.
8724  * Reserved when vnxet = '0'.
8725  * Access: RW
8726  */
8727 MLXSW_ITEM32(reg, rigr2, next_rigr_index, 0x08, 0, 24);
8728 
8729 /* reg_rigr2_vrmid
8730  * RMID Index is valid.
8731  * Access: RW
8732  */
8733 MLXSW_ITEM32(reg, rigr2, vrmid, 0x20, 31, 1);
8734 
8735 /* reg_rigr2_rmid_index
8736  * RMID Index.
8737  * Range 0 .. max_mid - 1
8738  * Reserved when vrmid = '0'.
8739  * The index is to the Port Group Table (PGT)
8740  * Access: RW
8741  */
8742 MLXSW_ITEM32(reg, rigr2, rmid_index, 0x20, 0, 16);
8743 
8744 /* reg_rigr2_erif_entry_v
8745  * Egress Router Interface is valid.
8746  * Note that low-entries must be set if high-entries are set. For
8747  * example: if erif_entry[2].v is set then erif_entry[1].v and
8748  * erif_entry[0].v must be set.
8749  * Index can be from 0 to cap_mc_erif_list_entries-1
8750  * Access: RW
8751  */
8752 MLXSW_ITEM32_INDEXED(reg, rigr2, erif_entry_v, 0x24, 31, 1, 4, 0, false);
8753 
8754 /* reg_rigr2_erif_entry_erif
8755  * Egress Router Interface.
8756  * Valid range is from 0 to cap_max_router_interfaces - 1
8757  * Index can be from 0 to MLXSW_REG_RIGR2_MAX_ERIFS - 1
8758  * Access: RW
8759  */
8760 MLXSW_ITEM32_INDEXED(reg, rigr2, erif_entry_erif, 0x24, 0, 16, 4, 0, false);
8761 
8762 static inline void mlxsw_reg_rigr2_pack(char *payload, u32 rigr_index,
8763 					bool vnext, u32 next_rigr_index)
8764 {
8765 	MLXSW_REG_ZERO(rigr2, payload);
8766 	mlxsw_reg_rigr2_rigr_index_set(payload, rigr_index);
8767 	mlxsw_reg_rigr2_vnext_set(payload, vnext);
8768 	mlxsw_reg_rigr2_next_rigr_index_set(payload, next_rigr_index);
8769 	mlxsw_reg_rigr2_vrmid_set(payload, 0);
8770 	mlxsw_reg_rigr2_rmid_index_set(payload, 0);
8771 }
8772 
8773 static inline void mlxsw_reg_rigr2_erif_entry_pack(char *payload, int index,
8774 						   bool v, u16 erif)
8775 {
8776 	mlxsw_reg_rigr2_erif_entry_v_set(payload, index, v);
8777 	mlxsw_reg_rigr2_erif_entry_erif_set(payload, index, erif);
8778 }
8779 
8780 /* RECR-V2 - Router ECMP Configuration Version 2 Register
8781  * ------------------------------------------------------
8782  */
8783 #define MLXSW_REG_RECR2_ID 0x8025
8784 #define MLXSW_REG_RECR2_LEN 0x38
8785 
8786 MLXSW_REG_DEFINE(recr2, MLXSW_REG_RECR2_ID, MLXSW_REG_RECR2_LEN);
8787 
8788 /* reg_recr2_pp
8789  * Per-port configuration
8790  * Access: Index
8791  */
8792 MLXSW_ITEM32(reg, recr2, pp, 0x00, 24, 1);
8793 
8794 /* reg_recr2_sh
8795  * Symmetric hash
8796  * Access: RW
8797  */
8798 MLXSW_ITEM32(reg, recr2, sh, 0x00, 8, 1);
8799 
8800 /* reg_recr2_seed
8801  * Seed
8802  * Access: RW
8803  */
8804 MLXSW_ITEM32(reg, recr2, seed, 0x08, 0, 32);
8805 
8806 enum {
8807 	/* Enable IPv4 fields if packet is not TCP and not UDP */
8808 	MLXSW_REG_RECR2_IPV4_EN_NOT_TCP_NOT_UDP	= 3,
8809 	/* Enable IPv4 fields if packet is TCP or UDP */
8810 	MLXSW_REG_RECR2_IPV4_EN_TCP_UDP		= 4,
8811 	/* Enable IPv6 fields if packet is not TCP and not UDP */
8812 	MLXSW_REG_RECR2_IPV6_EN_NOT_TCP_NOT_UDP	= 5,
8813 	/* Enable IPv6 fields if packet is TCP or UDP */
8814 	MLXSW_REG_RECR2_IPV6_EN_TCP_UDP		= 6,
8815 	/* Enable TCP/UDP header fields if packet is IPv4 */
8816 	MLXSW_REG_RECR2_TCP_UDP_EN_IPV4		= 7,
8817 	/* Enable TCP/UDP header fields if packet is IPv6 */
8818 	MLXSW_REG_RECR2_TCP_UDP_EN_IPV6		= 8,
8819 
8820 	__MLXSW_REG_RECR2_HEADER_CNT,
8821 };
8822 
8823 /* reg_recr2_outer_header_enables
8824  * Bit mask where each bit enables a specific layer to be included in
8825  * the hash calculation.
8826  * Access: RW
8827  */
8828 MLXSW_ITEM_BIT_ARRAY(reg, recr2, outer_header_enables, 0x10, 0x04, 1);
8829 
8830 enum {
8831 	/* IPv4 Source IP */
8832 	MLXSW_REG_RECR2_IPV4_SIP0			= 9,
8833 	MLXSW_REG_RECR2_IPV4_SIP3			= 12,
8834 	/* IPv4 Destination IP */
8835 	MLXSW_REG_RECR2_IPV4_DIP0			= 13,
8836 	MLXSW_REG_RECR2_IPV4_DIP3			= 16,
8837 	/* IP Protocol */
8838 	MLXSW_REG_RECR2_IPV4_PROTOCOL			= 17,
8839 	/* IPv6 Source IP */
8840 	MLXSW_REG_RECR2_IPV6_SIP0_7			= 21,
8841 	MLXSW_REG_RECR2_IPV6_SIP8			= 29,
8842 	MLXSW_REG_RECR2_IPV6_SIP15			= 36,
8843 	/* IPv6 Destination IP */
8844 	MLXSW_REG_RECR2_IPV6_DIP0_7			= 37,
8845 	MLXSW_REG_RECR2_IPV6_DIP8			= 45,
8846 	MLXSW_REG_RECR2_IPV6_DIP15			= 52,
8847 	/* IPv6 Next Header */
8848 	MLXSW_REG_RECR2_IPV6_NEXT_HEADER		= 53,
8849 	/* IPv6 Flow Label */
8850 	MLXSW_REG_RECR2_IPV6_FLOW_LABEL			= 57,
8851 	/* TCP/UDP Source Port */
8852 	MLXSW_REG_RECR2_TCP_UDP_SPORT			= 74,
8853 	/* TCP/UDP Destination Port */
8854 	MLXSW_REG_RECR2_TCP_UDP_DPORT			= 75,
8855 
8856 	__MLXSW_REG_RECR2_FIELD_CNT,
8857 };
8858 
8859 /* reg_recr2_outer_header_fields_enable
8860  * Packet fields to enable for ECMP hash subject to outer_header_enable.
8861  * Access: RW
8862  */
8863 MLXSW_ITEM_BIT_ARRAY(reg, recr2, outer_header_fields_enable, 0x14, 0x14, 1);
8864 
8865 /* reg_recr2_inner_header_enables
8866  * Bit mask where each bit enables a specific inner layer to be included in the
8867  * hash calculation. Same values as reg_recr2_outer_header_enables.
8868  * Access: RW
8869  */
8870 MLXSW_ITEM_BIT_ARRAY(reg, recr2, inner_header_enables, 0x2C, 0x04, 1);
8871 
8872 enum {
8873 	/* Inner IPv4 Source IP */
8874 	MLXSW_REG_RECR2_INNER_IPV4_SIP0			= 3,
8875 	MLXSW_REG_RECR2_INNER_IPV4_SIP3			= 6,
8876 	/* Inner IPv4 Destination IP */
8877 	MLXSW_REG_RECR2_INNER_IPV4_DIP0			= 7,
8878 	MLXSW_REG_RECR2_INNER_IPV4_DIP3			= 10,
8879 	/* Inner IP Protocol */
8880 	MLXSW_REG_RECR2_INNER_IPV4_PROTOCOL		= 11,
8881 	/* Inner IPv6 Source IP */
8882 	MLXSW_REG_RECR2_INNER_IPV6_SIP0_7		= 12,
8883 	MLXSW_REG_RECR2_INNER_IPV6_SIP8			= 20,
8884 	MLXSW_REG_RECR2_INNER_IPV6_SIP15		= 27,
8885 	/* Inner IPv6 Destination IP */
8886 	MLXSW_REG_RECR2_INNER_IPV6_DIP0_7		= 28,
8887 	MLXSW_REG_RECR2_INNER_IPV6_DIP8			= 36,
8888 	MLXSW_REG_RECR2_INNER_IPV6_DIP15		= 43,
8889 	/* Inner IPv6 Next Header */
8890 	MLXSW_REG_RECR2_INNER_IPV6_NEXT_HEADER		= 44,
8891 	/* Inner IPv6 Flow Label */
8892 	MLXSW_REG_RECR2_INNER_IPV6_FLOW_LABEL		= 45,
8893 	/* Inner TCP/UDP Source Port */
8894 	MLXSW_REG_RECR2_INNER_TCP_UDP_SPORT		= 46,
8895 	/* Inner TCP/UDP Destination Port */
8896 	MLXSW_REG_RECR2_INNER_TCP_UDP_DPORT		= 47,
8897 
8898 	__MLXSW_REG_RECR2_INNER_FIELD_CNT,
8899 };
8900 
8901 /* reg_recr2_inner_header_fields_enable
8902  * Inner packet fields to enable for ECMP hash subject to inner_header_enables.
8903  * Access: RW
8904  */
8905 MLXSW_ITEM_BIT_ARRAY(reg, recr2, inner_header_fields_enable, 0x30, 0x08, 1);
8906 
8907 static inline void mlxsw_reg_recr2_pack(char *payload, u32 seed)
8908 {
8909 	MLXSW_REG_ZERO(recr2, payload);
8910 	mlxsw_reg_recr2_pp_set(payload, false);
8911 	mlxsw_reg_recr2_sh_set(payload, true);
8912 	mlxsw_reg_recr2_seed_set(payload, seed);
8913 }
8914 
8915 /* RMFT-V2 - Router Multicast Forwarding Table Version 2 Register
8916  * --------------------------------------------------------------
8917  * The RMFT_V2 register is used to configure and query the multicast table.
8918  */
8919 #define MLXSW_REG_RMFT2_ID 0x8027
8920 #define MLXSW_REG_RMFT2_LEN 0x174
8921 
8922 MLXSW_REG_DEFINE(rmft2, MLXSW_REG_RMFT2_ID, MLXSW_REG_RMFT2_LEN);
8923 
8924 /* reg_rmft2_v
8925  * Valid
8926  * Access: RW
8927  */
8928 MLXSW_ITEM32(reg, rmft2, v, 0x00, 31, 1);
8929 
8930 enum mlxsw_reg_rmft2_type {
8931 	MLXSW_REG_RMFT2_TYPE_IPV4,
8932 	MLXSW_REG_RMFT2_TYPE_IPV6
8933 };
8934 
8935 /* reg_rmft2_type
8936  * Access: Index
8937  */
8938 MLXSW_ITEM32(reg, rmft2, type, 0x00, 28, 2);
8939 
8940 enum mlxsw_sp_reg_rmft2_op {
8941 	/* For Write:
8942 	 * Write operation. Used to write a new entry to the table. All RW
8943 	 * fields are relevant for new entry. Activity bit is set for new
8944 	 * entries - Note write with v (Valid) 0 will delete the entry.
8945 	 * For Query:
8946 	 * Read operation
8947 	 */
8948 	MLXSW_REG_RMFT2_OP_READ_WRITE,
8949 };
8950 
8951 /* reg_rmft2_op
8952  * Operation.
8953  * Access: OP
8954  */
8955 MLXSW_ITEM32(reg, rmft2, op, 0x00, 20, 2);
8956 
8957 /* reg_rmft2_a
8958  * Activity. Set for new entries. Set if a packet lookup has hit on the specific
8959  * entry.
8960  * Access: RO
8961  */
8962 MLXSW_ITEM32(reg, rmft2, a, 0x00, 16, 1);
8963 
8964 /* reg_rmft2_offset
8965  * Offset within the multicast forwarding table to write to.
8966  * Access: Index
8967  */
8968 MLXSW_ITEM32(reg, rmft2, offset, 0x00, 0, 16);
8969 
8970 /* reg_rmft2_virtual_router
8971  * Virtual Router ID. Range from 0..cap_max_virtual_routers-1
8972  * Access: RW
8973  */
8974 MLXSW_ITEM32(reg, rmft2, virtual_router, 0x04, 0, 16);
8975 
8976 enum mlxsw_reg_rmft2_irif_mask {
8977 	MLXSW_REG_RMFT2_IRIF_MASK_IGNORE,
8978 	MLXSW_REG_RMFT2_IRIF_MASK_COMPARE
8979 };
8980 
8981 /* reg_rmft2_irif_mask
8982  * Ingress RIF mask.
8983  * Access: RW
8984  */
8985 MLXSW_ITEM32(reg, rmft2, irif_mask, 0x08, 24, 1);
8986 
8987 /* reg_rmft2_irif
8988  * Ingress RIF index.
8989  * Access: RW
8990  */
8991 MLXSW_ITEM32(reg, rmft2, irif, 0x08, 0, 16);
8992 
8993 /* reg_rmft2_dip{4,6}
8994  * Destination IPv4/6 address
8995  * Access: RW
8996  */
8997 MLXSW_ITEM_BUF(reg, rmft2, dip6, 0x10, 16);
8998 MLXSW_ITEM32(reg, rmft2, dip4, 0x1C, 0, 32);
8999 
9000 /* reg_rmft2_dip{4,6}_mask
9001  * A bit that is set directs the TCAM to compare the corresponding bit in key. A
9002  * bit that is clear directs the TCAM to ignore the corresponding bit in key.
9003  * Access: RW
9004  */
9005 MLXSW_ITEM_BUF(reg, rmft2, dip6_mask, 0x20, 16);
9006 MLXSW_ITEM32(reg, rmft2, dip4_mask, 0x2C, 0, 32);
9007 
9008 /* reg_rmft2_sip{4,6}
9009  * Source IPv4/6 address
9010  * Access: RW
9011  */
9012 MLXSW_ITEM_BUF(reg, rmft2, sip6, 0x30, 16);
9013 MLXSW_ITEM32(reg, rmft2, sip4, 0x3C, 0, 32);
9014 
9015 /* reg_rmft2_sip{4,6}_mask
9016  * A bit that is set directs the TCAM to compare the corresponding bit in key. A
9017  * bit that is clear directs the TCAM to ignore the corresponding bit in key.
9018  * Access: RW
9019  */
9020 MLXSW_ITEM_BUF(reg, rmft2, sip6_mask, 0x40, 16);
9021 MLXSW_ITEM32(reg, rmft2, sip4_mask, 0x4C, 0, 32);
9022 
9023 /* reg_rmft2_flexible_action_set
9024  * ACL action set. The only supported action types in this field and in any
9025  * action-set pointed from here are as follows:
9026  * 00h: ACTION_NULL
9027  * 01h: ACTION_MAC_TTL, only TTL configuration is supported.
9028  * 03h: ACTION_TRAP
9029  * 06h: ACTION_QOS
9030  * 08h: ACTION_POLICING_MONITORING
9031  * 10h: ACTION_ROUTER_MC
9032  * Access: RW
9033  */
9034 MLXSW_ITEM_BUF(reg, rmft2, flexible_action_set, 0x80,
9035 	       MLXSW_REG_FLEX_ACTION_SET_LEN);
9036 
9037 static inline void
9038 mlxsw_reg_rmft2_common_pack(char *payload, bool v, u16 offset,
9039 			    u16 virtual_router,
9040 			    enum mlxsw_reg_rmft2_irif_mask irif_mask, u16 irif,
9041 			    const char *flex_action_set)
9042 {
9043 	MLXSW_REG_ZERO(rmft2, payload);
9044 	mlxsw_reg_rmft2_v_set(payload, v);
9045 	mlxsw_reg_rmft2_op_set(payload, MLXSW_REG_RMFT2_OP_READ_WRITE);
9046 	mlxsw_reg_rmft2_offset_set(payload, offset);
9047 	mlxsw_reg_rmft2_virtual_router_set(payload, virtual_router);
9048 	mlxsw_reg_rmft2_irif_mask_set(payload, irif_mask);
9049 	mlxsw_reg_rmft2_irif_set(payload, irif);
9050 	if (flex_action_set)
9051 		mlxsw_reg_rmft2_flexible_action_set_memcpy_to(payload,
9052 							      flex_action_set);
9053 }
9054 
9055 static inline void
9056 mlxsw_reg_rmft2_ipv4_pack(char *payload, bool v, u16 offset, u16 virtual_router,
9057 			  enum mlxsw_reg_rmft2_irif_mask irif_mask, u16 irif,
9058 			  u32 dip4, u32 dip4_mask, u32 sip4, u32 sip4_mask,
9059 			  const char *flexible_action_set)
9060 {
9061 	mlxsw_reg_rmft2_common_pack(payload, v, offset, virtual_router,
9062 				    irif_mask, irif, flexible_action_set);
9063 	mlxsw_reg_rmft2_type_set(payload, MLXSW_REG_RMFT2_TYPE_IPV4);
9064 	mlxsw_reg_rmft2_dip4_set(payload, dip4);
9065 	mlxsw_reg_rmft2_dip4_mask_set(payload, dip4_mask);
9066 	mlxsw_reg_rmft2_sip4_set(payload, sip4);
9067 	mlxsw_reg_rmft2_sip4_mask_set(payload, sip4_mask);
9068 }
9069 
9070 static inline void
9071 mlxsw_reg_rmft2_ipv6_pack(char *payload, bool v, u16 offset, u16 virtual_router,
9072 			  enum mlxsw_reg_rmft2_irif_mask irif_mask, u16 irif,
9073 			  struct in6_addr dip6, struct in6_addr dip6_mask,
9074 			  struct in6_addr sip6, struct in6_addr sip6_mask,
9075 			  const char *flexible_action_set)
9076 {
9077 	mlxsw_reg_rmft2_common_pack(payload, v, offset, virtual_router,
9078 				    irif_mask, irif, flexible_action_set);
9079 	mlxsw_reg_rmft2_type_set(payload, MLXSW_REG_RMFT2_TYPE_IPV6);
9080 	mlxsw_reg_rmft2_dip6_memcpy_to(payload, (void *)&dip6);
9081 	mlxsw_reg_rmft2_dip6_mask_memcpy_to(payload, (void *)&dip6_mask);
9082 	mlxsw_reg_rmft2_sip6_memcpy_to(payload, (void *)&sip6);
9083 	mlxsw_reg_rmft2_sip6_mask_memcpy_to(payload, (void *)&sip6_mask);
9084 }
9085 
9086 /* REIV - Router Egress Interface to VID Register
9087  * ----------------------------------------------
9088  * The REIV register maps {eRIF, egress_port} -> VID.
9089  * This mapping is done at the egress, after the ACLs.
9090  * This mapping always takes effect after router, regardless of cast
9091  * (for unicast/multicast/port-base multicast), regardless of eRIF type and
9092  * regardless of bridge decisions (e.g. SFD for unicast or SMPE).
9093  * Reserved when the RIF is a loopback RIF.
9094  *
9095  * Note: Reserved when legacy bridge model is used.
9096  */
9097 #define MLXSW_REG_REIV_ID 0x8034
9098 #define MLXSW_REG_REIV_BASE_LEN 0x20 /* base length, without records */
9099 #define MLXSW_REG_REIV_REC_LEN 0x04 /* record length */
9100 #define MLXSW_REG_REIV_REC_MAX_COUNT 256 /* firmware limitation */
9101 #define MLXSW_REG_REIV_LEN (MLXSW_REG_REIV_BASE_LEN +	\
9102 			    MLXSW_REG_REIV_REC_LEN *	\
9103 			    MLXSW_REG_REIV_REC_MAX_COUNT)
9104 
9105 MLXSW_REG_DEFINE(reiv, MLXSW_REG_REIV_ID, MLXSW_REG_REIV_LEN);
9106 
9107 /* reg_reiv_port_page
9108  * Port page - elport_record[0] is 256*port_page.
9109  * Access: Index
9110  */
9111 MLXSW_ITEM32(reg, reiv, port_page, 0x00, 0, 4);
9112 
9113 /* reg_reiv_erif
9114  * Egress RIF.
9115  * Range is 0..cap_max_router_interfaces-1.
9116  * Access: Index
9117  */
9118 MLXSW_ITEM32(reg, reiv, erif, 0x04, 0, 16);
9119 
9120 /* reg_reiv_rec_update
9121  * Update enable (when write):
9122  * 0 - Do not update the entry.
9123  * 1 - Update the entry.
9124  * Access: OP
9125  */
9126 MLXSW_ITEM32_INDEXED(reg, reiv, rec_update, MLXSW_REG_REIV_BASE_LEN, 31, 1,
9127 		     MLXSW_REG_REIV_REC_LEN, 0x00, false);
9128 
9129 /* reg_reiv_rec_evid
9130  * Egress VID.
9131  * Range is 0..4095.
9132  * Access: RW
9133  */
9134 MLXSW_ITEM32_INDEXED(reg, reiv, rec_evid, MLXSW_REG_REIV_BASE_LEN, 0, 12,
9135 		     MLXSW_REG_REIV_REC_LEN, 0x00, false);
9136 
9137 static inline void mlxsw_reg_reiv_pack(char *payload, u8 port_page, u16 erif)
9138 {
9139 	MLXSW_REG_ZERO(reiv, payload);
9140 	mlxsw_reg_reiv_port_page_set(payload, port_page);
9141 	mlxsw_reg_reiv_erif_set(payload, erif);
9142 }
9143 
9144 /* MFCR - Management Fan Control Register
9145  * --------------------------------------
9146  * This register controls the settings of the Fan Speed PWM mechanism.
9147  */
9148 #define MLXSW_REG_MFCR_ID 0x9001
9149 #define MLXSW_REG_MFCR_LEN 0x08
9150 
9151 MLXSW_REG_DEFINE(mfcr, MLXSW_REG_MFCR_ID, MLXSW_REG_MFCR_LEN);
9152 
9153 enum mlxsw_reg_mfcr_pwm_frequency {
9154 	MLXSW_REG_MFCR_PWM_FEQ_11HZ = 0x00,
9155 	MLXSW_REG_MFCR_PWM_FEQ_14_7HZ = 0x01,
9156 	MLXSW_REG_MFCR_PWM_FEQ_22_1HZ = 0x02,
9157 	MLXSW_REG_MFCR_PWM_FEQ_1_4KHZ = 0x40,
9158 	MLXSW_REG_MFCR_PWM_FEQ_5KHZ = 0x41,
9159 	MLXSW_REG_MFCR_PWM_FEQ_20KHZ = 0x42,
9160 	MLXSW_REG_MFCR_PWM_FEQ_22_5KHZ = 0x43,
9161 	MLXSW_REG_MFCR_PWM_FEQ_25KHZ = 0x44,
9162 };
9163 
9164 /* reg_mfcr_pwm_frequency
9165  * Controls the frequency of the PWM signal.
9166  * Access: RW
9167  */
9168 MLXSW_ITEM32(reg, mfcr, pwm_frequency, 0x00, 0, 7);
9169 
9170 #define MLXSW_MFCR_TACHOS_MAX 10
9171 
9172 /* reg_mfcr_tacho_active
9173  * Indicates which of the tachometer is active (bit per tachometer).
9174  * Access: RO
9175  */
9176 MLXSW_ITEM32(reg, mfcr, tacho_active, 0x04, 16, MLXSW_MFCR_TACHOS_MAX);
9177 
9178 #define MLXSW_MFCR_PWMS_MAX 5
9179 
9180 /* reg_mfcr_pwm_active
9181  * Indicates which of the PWM control is active (bit per PWM).
9182  * Access: RO
9183  */
9184 MLXSW_ITEM32(reg, mfcr, pwm_active, 0x04, 0, MLXSW_MFCR_PWMS_MAX);
9185 
9186 static inline void
9187 mlxsw_reg_mfcr_pack(char *payload,
9188 		    enum mlxsw_reg_mfcr_pwm_frequency pwm_frequency)
9189 {
9190 	MLXSW_REG_ZERO(mfcr, payload);
9191 	mlxsw_reg_mfcr_pwm_frequency_set(payload, pwm_frequency);
9192 }
9193 
9194 static inline void
9195 mlxsw_reg_mfcr_unpack(char *payload,
9196 		      enum mlxsw_reg_mfcr_pwm_frequency *p_pwm_frequency,
9197 		      u16 *p_tacho_active, u8 *p_pwm_active)
9198 {
9199 	*p_pwm_frequency = mlxsw_reg_mfcr_pwm_frequency_get(payload);
9200 	*p_tacho_active = mlxsw_reg_mfcr_tacho_active_get(payload);
9201 	*p_pwm_active = mlxsw_reg_mfcr_pwm_active_get(payload);
9202 }
9203 
9204 /* MFSC - Management Fan Speed Control Register
9205  * --------------------------------------------
9206  * This register controls the settings of the Fan Speed PWM mechanism.
9207  */
9208 #define MLXSW_REG_MFSC_ID 0x9002
9209 #define MLXSW_REG_MFSC_LEN 0x08
9210 
9211 MLXSW_REG_DEFINE(mfsc, MLXSW_REG_MFSC_ID, MLXSW_REG_MFSC_LEN);
9212 
9213 /* reg_mfsc_pwm
9214  * Fan pwm to control / monitor.
9215  * Access: Index
9216  */
9217 MLXSW_ITEM32(reg, mfsc, pwm, 0x00, 24, 3);
9218 
9219 /* reg_mfsc_pwm_duty_cycle
9220  * Controls the duty cycle of the PWM. Value range from 0..255 to
9221  * represent duty cycle of 0%...100%.
9222  * Access: RW
9223  */
9224 MLXSW_ITEM32(reg, mfsc, pwm_duty_cycle, 0x04, 0, 8);
9225 
9226 static inline void mlxsw_reg_mfsc_pack(char *payload, u8 pwm,
9227 				       u8 pwm_duty_cycle)
9228 {
9229 	MLXSW_REG_ZERO(mfsc, payload);
9230 	mlxsw_reg_mfsc_pwm_set(payload, pwm);
9231 	mlxsw_reg_mfsc_pwm_duty_cycle_set(payload, pwm_duty_cycle);
9232 }
9233 
9234 /* MFSM - Management Fan Speed Measurement
9235  * ---------------------------------------
9236  * This register controls the settings of the Tacho measurements and
9237  * enables reading the Tachometer measurements.
9238  */
9239 #define MLXSW_REG_MFSM_ID 0x9003
9240 #define MLXSW_REG_MFSM_LEN 0x08
9241 
9242 MLXSW_REG_DEFINE(mfsm, MLXSW_REG_MFSM_ID, MLXSW_REG_MFSM_LEN);
9243 
9244 /* reg_mfsm_tacho
9245  * Fan tachometer index.
9246  * Access: Index
9247  */
9248 MLXSW_ITEM32(reg, mfsm, tacho, 0x00, 24, 4);
9249 
9250 /* reg_mfsm_rpm
9251  * Fan speed (round per minute).
9252  * Access: RO
9253  */
9254 MLXSW_ITEM32(reg, mfsm, rpm, 0x04, 0, 16);
9255 
9256 static inline void mlxsw_reg_mfsm_pack(char *payload, u8 tacho)
9257 {
9258 	MLXSW_REG_ZERO(mfsm, payload);
9259 	mlxsw_reg_mfsm_tacho_set(payload, tacho);
9260 }
9261 
9262 /* MFSL - Management Fan Speed Limit Register
9263  * ------------------------------------------
9264  * The Fan Speed Limit register is used to configure the fan speed
9265  * event / interrupt notification mechanism. Fan speed threshold are
9266  * defined for both under-speed and over-speed.
9267  */
9268 #define MLXSW_REG_MFSL_ID 0x9004
9269 #define MLXSW_REG_MFSL_LEN 0x0C
9270 
9271 MLXSW_REG_DEFINE(mfsl, MLXSW_REG_MFSL_ID, MLXSW_REG_MFSL_LEN);
9272 
9273 /* reg_mfsl_tacho
9274  * Fan tachometer index.
9275  * Access: Index
9276  */
9277 MLXSW_ITEM32(reg, mfsl, tacho, 0x00, 24, 4);
9278 
9279 /* reg_mfsl_tach_min
9280  * Tachometer minimum value (minimum RPM).
9281  * Access: RW
9282  */
9283 MLXSW_ITEM32(reg, mfsl, tach_min, 0x04, 0, 16);
9284 
9285 /* reg_mfsl_tach_max
9286  * Tachometer maximum value (maximum RPM).
9287  * Access: RW
9288  */
9289 MLXSW_ITEM32(reg, mfsl, tach_max, 0x08, 0, 16);
9290 
9291 static inline void mlxsw_reg_mfsl_pack(char *payload, u8 tacho,
9292 				       u16 tach_min, u16 tach_max)
9293 {
9294 	MLXSW_REG_ZERO(mfsl, payload);
9295 	mlxsw_reg_mfsl_tacho_set(payload, tacho);
9296 	mlxsw_reg_mfsl_tach_min_set(payload, tach_min);
9297 	mlxsw_reg_mfsl_tach_max_set(payload, tach_max);
9298 }
9299 
9300 static inline void mlxsw_reg_mfsl_unpack(char *payload, u8 tacho,
9301 					 u16 *p_tach_min, u16 *p_tach_max)
9302 {
9303 	if (p_tach_min)
9304 		*p_tach_min = mlxsw_reg_mfsl_tach_min_get(payload);
9305 
9306 	if (p_tach_max)
9307 		*p_tach_max = mlxsw_reg_mfsl_tach_max_get(payload);
9308 }
9309 
9310 /* FORE - Fan Out of Range Event Register
9311  * --------------------------------------
9312  * This register reports the status of the controlled fans compared to the
9313  * range defined by the MFSL register.
9314  */
9315 #define MLXSW_REG_FORE_ID 0x9007
9316 #define MLXSW_REG_FORE_LEN 0x0C
9317 
9318 MLXSW_REG_DEFINE(fore, MLXSW_REG_FORE_ID, MLXSW_REG_FORE_LEN);
9319 
9320 /* fan_under_limit
9321  * Fan speed is below the low limit defined in MFSL register. Each bit relates
9322  * to a single tachometer and indicates the specific tachometer reading is
9323  * below the threshold.
9324  * Access: RO
9325  */
9326 MLXSW_ITEM32(reg, fore, fan_under_limit, 0x00, 16, 10);
9327 
9328 static inline void mlxsw_reg_fore_unpack(char *payload, u8 tacho,
9329 					 bool *fault)
9330 {
9331 	u16 limit;
9332 
9333 	if (fault) {
9334 		limit = mlxsw_reg_fore_fan_under_limit_get(payload);
9335 		*fault = limit & BIT(tacho);
9336 	}
9337 }
9338 
9339 /* MTCAP - Management Temperature Capabilities
9340  * -------------------------------------------
9341  * This register exposes the capabilities of the device and
9342  * system temperature sensing.
9343  */
9344 #define MLXSW_REG_MTCAP_ID 0x9009
9345 #define MLXSW_REG_MTCAP_LEN 0x08
9346 
9347 MLXSW_REG_DEFINE(mtcap, MLXSW_REG_MTCAP_ID, MLXSW_REG_MTCAP_LEN);
9348 
9349 /* reg_mtcap_sensor_count
9350  * Number of sensors supported by the device.
9351  * This includes the QSFP module sensors (if exists in the QSFP module).
9352  * Access: RO
9353  */
9354 MLXSW_ITEM32(reg, mtcap, sensor_count, 0x00, 0, 7);
9355 
9356 /* MTMP - Management Temperature
9357  * -----------------------------
9358  * This register controls the settings of the temperature measurements
9359  * and enables reading the temperature measurements. Note that temperature
9360  * is in 0.125 degrees Celsius.
9361  */
9362 #define MLXSW_REG_MTMP_ID 0x900A
9363 #define MLXSW_REG_MTMP_LEN 0x20
9364 
9365 MLXSW_REG_DEFINE(mtmp, MLXSW_REG_MTMP_ID, MLXSW_REG_MTMP_LEN);
9366 
9367 /* reg_mtmp_slot_index
9368  * Slot index (0: Main board).
9369  * Access: Index
9370  */
9371 MLXSW_ITEM32(reg, mtmp, slot_index, 0x00, 16, 4);
9372 
9373 #define MLXSW_REG_MTMP_MODULE_INDEX_MIN 64
9374 #define MLXSW_REG_MTMP_GBOX_INDEX_MIN 256
9375 /* reg_mtmp_sensor_index
9376  * Sensors index to access.
9377  * 64-127 of sensor_index are mapped to the SFP+/QSFP modules sequentially
9378  * (module 0 is mapped to sensor_index 64).
9379  * Access: Index
9380  */
9381 MLXSW_ITEM32(reg, mtmp, sensor_index, 0x00, 0, 12);
9382 
9383 /* Convert to milli degrees Celsius */
9384 #define MLXSW_REG_MTMP_TEMP_TO_MC(val) ({ typeof(val) v_ = (val); \
9385 					  ((v_) >= 0) ? ((v_) * 125) : \
9386 					  ((s16)((GENMASK(15, 0) + (v_) + 1) \
9387 					   * 125)); })
9388 
9389 /* reg_mtmp_max_operational_temperature
9390  * The highest temperature in the nominal operational range. Reading is in
9391  * 0.125 Celsius degrees units.
9392  * In case of module this is SFF critical temperature threshold.
9393  * Access: RO
9394  */
9395 MLXSW_ITEM32(reg, mtmp, max_operational_temperature, 0x04, 16, 16);
9396 
9397 /* reg_mtmp_temperature
9398  * Temperature reading from the sensor. Reading is in 0.125 Celsius
9399  * degrees units.
9400  * Access: RO
9401  */
9402 MLXSW_ITEM32(reg, mtmp, temperature, 0x04, 0, 16);
9403 
9404 /* reg_mtmp_mte
9405  * Max Temperature Enable - enables measuring the max temperature on a sensor.
9406  * Access: RW
9407  */
9408 MLXSW_ITEM32(reg, mtmp, mte, 0x08, 31, 1);
9409 
9410 /* reg_mtmp_mtr
9411  * Max Temperature Reset - clears the value of the max temperature register.
9412  * Access: WO
9413  */
9414 MLXSW_ITEM32(reg, mtmp, mtr, 0x08, 30, 1);
9415 
9416 /* reg_mtmp_max_temperature
9417  * The highest measured temperature from the sensor.
9418  * When the bit mte is cleared, the field max_temperature is reserved.
9419  * Access: RO
9420  */
9421 MLXSW_ITEM32(reg, mtmp, max_temperature, 0x08, 0, 16);
9422 
9423 /* reg_mtmp_tee
9424  * Temperature Event Enable.
9425  * 0 - Do not generate event
9426  * 1 - Generate event
9427  * 2 - Generate single event
9428  * Access: RW
9429  */
9430 
9431 enum mlxsw_reg_mtmp_tee {
9432 	MLXSW_REG_MTMP_TEE_NO_EVENT,
9433 	MLXSW_REG_MTMP_TEE_GENERATE_EVENT,
9434 	MLXSW_REG_MTMP_TEE_GENERATE_SINGLE_EVENT,
9435 };
9436 
9437 MLXSW_ITEM32(reg, mtmp, tee, 0x0C, 30, 2);
9438 
9439 #define MLXSW_REG_MTMP_THRESH_HI 0x348	/* 105 Celsius */
9440 
9441 /* reg_mtmp_temperature_threshold_hi
9442  * High threshold for Temperature Warning Event. In 0.125 Celsius.
9443  * Access: RW
9444  */
9445 MLXSW_ITEM32(reg, mtmp, temperature_threshold_hi, 0x0C, 0, 16);
9446 
9447 #define MLXSW_REG_MTMP_HYSTERESIS_TEMP 0x28 /* 5 Celsius */
9448 /* reg_mtmp_temperature_threshold_lo
9449  * Low threshold for Temperature Warning Event. In 0.125 Celsius.
9450  * Access: RW
9451  */
9452 MLXSW_ITEM32(reg, mtmp, temperature_threshold_lo, 0x10, 0, 16);
9453 
9454 #define MLXSW_REG_MTMP_SENSOR_NAME_SIZE 8
9455 
9456 /* reg_mtmp_sensor_name
9457  * Sensor Name
9458  * Access: RO
9459  */
9460 MLXSW_ITEM_BUF(reg, mtmp, sensor_name, 0x18, MLXSW_REG_MTMP_SENSOR_NAME_SIZE);
9461 
9462 static inline void mlxsw_reg_mtmp_pack(char *payload, u8 slot_index,
9463 				       u16 sensor_index, bool max_temp_enable,
9464 				       bool max_temp_reset)
9465 {
9466 	MLXSW_REG_ZERO(mtmp, payload);
9467 	mlxsw_reg_mtmp_slot_index_set(payload, slot_index);
9468 	mlxsw_reg_mtmp_sensor_index_set(payload, sensor_index);
9469 	mlxsw_reg_mtmp_mte_set(payload, max_temp_enable);
9470 	mlxsw_reg_mtmp_mtr_set(payload, max_temp_reset);
9471 	mlxsw_reg_mtmp_temperature_threshold_hi_set(payload,
9472 						    MLXSW_REG_MTMP_THRESH_HI);
9473 }
9474 
9475 static inline void mlxsw_reg_mtmp_unpack(char *payload, int *p_temp,
9476 					 int *p_max_temp, int *p_temp_hi,
9477 					 int *p_max_oper_temp,
9478 					 char *sensor_name)
9479 {
9480 	s16 temp;
9481 
9482 	if (p_temp) {
9483 		temp = mlxsw_reg_mtmp_temperature_get(payload);
9484 		*p_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
9485 	}
9486 	if (p_max_temp) {
9487 		temp = mlxsw_reg_mtmp_max_temperature_get(payload);
9488 		*p_max_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
9489 	}
9490 	if (p_temp_hi) {
9491 		temp = mlxsw_reg_mtmp_temperature_threshold_hi_get(payload);
9492 		*p_temp_hi = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
9493 	}
9494 	if (p_max_oper_temp) {
9495 		temp = mlxsw_reg_mtmp_max_operational_temperature_get(payload);
9496 		*p_max_oper_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
9497 	}
9498 	if (sensor_name)
9499 		mlxsw_reg_mtmp_sensor_name_memcpy_from(payload, sensor_name);
9500 }
9501 
9502 /* MTWE - Management Temperature Warning Event
9503  * -------------------------------------------
9504  * This register is used for over temperature warning.
9505  */
9506 #define MLXSW_REG_MTWE_ID 0x900B
9507 #define MLXSW_REG_MTWE_LEN 0x10
9508 
9509 MLXSW_REG_DEFINE(mtwe, MLXSW_REG_MTWE_ID, MLXSW_REG_MTWE_LEN);
9510 
9511 /* reg_mtwe_sensor_warning
9512  * Bit vector indicating which of the sensor reading is above threshold.
9513  * Address 00h bit31 is sensor_warning[127].
9514  * Address 0Ch bit0 is sensor_warning[0].
9515  * Access: RO
9516  */
9517 MLXSW_ITEM_BIT_ARRAY(reg, mtwe, sensor_warning, 0x0, 0x10, 1);
9518 
9519 /* MTBR - Management Temperature Bulk Register
9520  * -------------------------------------------
9521  * This register is used for bulk temperature reading.
9522  */
9523 #define MLXSW_REG_MTBR_ID 0x900F
9524 #define MLXSW_REG_MTBR_BASE_LEN 0x10 /* base length, without records */
9525 #define MLXSW_REG_MTBR_REC_LEN 0x04 /* record length */
9526 #define MLXSW_REG_MTBR_REC_MAX_COUNT 47 /* firmware limitation */
9527 #define MLXSW_REG_MTBR_LEN (MLXSW_REG_MTBR_BASE_LEN +	\
9528 			    MLXSW_REG_MTBR_REC_LEN *	\
9529 			    MLXSW_REG_MTBR_REC_MAX_COUNT)
9530 
9531 MLXSW_REG_DEFINE(mtbr, MLXSW_REG_MTBR_ID, MLXSW_REG_MTBR_LEN);
9532 
9533 /* reg_mtbr_slot_index
9534  * Slot index (0: Main board).
9535  * Access: Index
9536  */
9537 MLXSW_ITEM32(reg, mtbr, slot_index, 0x00, 16, 4);
9538 
9539 /* reg_mtbr_base_sensor_index
9540  * Base sensors index to access (0 - ASIC sensor, 1-63 - ambient sensors,
9541  * 64-127 are mapped to the SFP+/QSFP modules sequentially).
9542  * Access: Index
9543  */
9544 MLXSW_ITEM32(reg, mtbr, base_sensor_index, 0x00, 0, 12);
9545 
9546 /* reg_mtbr_num_rec
9547  * Request: Number of records to read
9548  * Response: Number of records read
9549  * See above description for more details.
9550  * Range 1..255
9551  * Access: RW
9552  */
9553 MLXSW_ITEM32(reg, mtbr, num_rec, 0x04, 0, 8);
9554 
9555 /* reg_mtbr_rec_max_temp
9556  * The highest measured temperature from the sensor.
9557  * When the bit mte is cleared, the field max_temperature is reserved.
9558  * Access: RO
9559  */
9560 MLXSW_ITEM32_INDEXED(reg, mtbr, rec_max_temp, MLXSW_REG_MTBR_BASE_LEN, 16,
9561 		     16, MLXSW_REG_MTBR_REC_LEN, 0x00, false);
9562 
9563 /* reg_mtbr_rec_temp
9564  * Temperature reading from the sensor. Reading is in 0..125 Celsius
9565  * degrees units.
9566  * Access: RO
9567  */
9568 MLXSW_ITEM32_INDEXED(reg, mtbr, rec_temp, MLXSW_REG_MTBR_BASE_LEN, 0, 16,
9569 		     MLXSW_REG_MTBR_REC_LEN, 0x00, false);
9570 
9571 static inline void mlxsw_reg_mtbr_pack(char *payload, u8 slot_index,
9572 				       u16 base_sensor_index, u8 num_rec)
9573 {
9574 	MLXSW_REG_ZERO(mtbr, payload);
9575 	mlxsw_reg_mtbr_slot_index_set(payload, slot_index);
9576 	mlxsw_reg_mtbr_base_sensor_index_set(payload, base_sensor_index);
9577 	mlxsw_reg_mtbr_num_rec_set(payload, num_rec);
9578 }
9579 
9580 /* Error codes from temperatute reading */
9581 enum mlxsw_reg_mtbr_temp_status {
9582 	MLXSW_REG_MTBR_NO_CONN		= 0x8000,
9583 	MLXSW_REG_MTBR_NO_TEMP_SENS	= 0x8001,
9584 	MLXSW_REG_MTBR_INDEX_NA		= 0x8002,
9585 	MLXSW_REG_MTBR_BAD_SENS_INFO	= 0x8003,
9586 };
9587 
9588 /* Base index for reading modules temperature */
9589 #define MLXSW_REG_MTBR_BASE_MODULE_INDEX 64
9590 
9591 static inline void mlxsw_reg_mtbr_temp_unpack(char *payload, int rec_ind,
9592 					      u16 *p_temp, u16 *p_max_temp)
9593 {
9594 	if (p_temp)
9595 		*p_temp = mlxsw_reg_mtbr_rec_temp_get(payload, rec_ind);
9596 	if (p_max_temp)
9597 		*p_max_temp = mlxsw_reg_mtbr_rec_max_temp_get(payload, rec_ind);
9598 }
9599 
9600 /* MCIA - Management Cable Info Access
9601  * -----------------------------------
9602  * MCIA register is used to access the SFP+ and QSFP connector's EPROM.
9603  */
9604 
9605 #define MLXSW_REG_MCIA_ID 0x9014
9606 #define MLXSW_REG_MCIA_LEN 0x40
9607 
9608 MLXSW_REG_DEFINE(mcia, MLXSW_REG_MCIA_ID, MLXSW_REG_MCIA_LEN);
9609 
9610 /* reg_mcia_l
9611  * Lock bit. Setting this bit will lock the access to the specific
9612  * cable. Used for updating a full page in a cable EPROM. Any access
9613  * other then subsequence writes will fail while the port is locked.
9614  * Access: RW
9615  */
9616 MLXSW_ITEM32(reg, mcia, l, 0x00, 31, 1);
9617 
9618 /* reg_mcia_module
9619  * Module number.
9620  * Access: Index
9621  */
9622 MLXSW_ITEM32(reg, mcia, module, 0x00, 16, 8);
9623 
9624 /* reg_mcia_slot_index
9625  * Slot index (0: Main board)
9626  * Access: Index
9627  */
9628 MLXSW_ITEM32(reg, mcia, slot, 0x00, 12, 4);
9629 
9630 enum {
9631 	MLXSW_REG_MCIA_STATUS_GOOD = 0,
9632 	/* No response from module's EEPROM. */
9633 	MLXSW_REG_MCIA_STATUS_NO_EEPROM_MODULE = 1,
9634 	/* Module type not supported by the device. */
9635 	MLXSW_REG_MCIA_STATUS_MODULE_NOT_SUPPORTED = 2,
9636 	/* No module present indication. */
9637 	MLXSW_REG_MCIA_STATUS_MODULE_NOT_CONNECTED = 3,
9638 	/* Error occurred while trying to access module's EEPROM using I2C. */
9639 	MLXSW_REG_MCIA_STATUS_I2C_ERROR = 9,
9640 	/* Module is disabled. */
9641 	MLXSW_REG_MCIA_STATUS_MODULE_DISABLED = 16,
9642 };
9643 
9644 /* reg_mcia_status
9645  * Module status.
9646  * Access: RO
9647  */
9648 MLXSW_ITEM32(reg, mcia, status, 0x00, 0, 8);
9649 
9650 /* reg_mcia_i2c_device_address
9651  * I2C device address.
9652  * Access: RW
9653  */
9654 MLXSW_ITEM32(reg, mcia, i2c_device_address, 0x04, 24, 8);
9655 
9656 /* reg_mcia_page_number
9657  * Page number.
9658  * Access: RW
9659  */
9660 MLXSW_ITEM32(reg, mcia, page_number, 0x04, 16, 8);
9661 
9662 /* reg_mcia_device_address
9663  * Device address.
9664  * Access: RW
9665  */
9666 MLXSW_ITEM32(reg, mcia, device_address, 0x04, 0, 16);
9667 
9668 /* reg_mcia_bank_number
9669  * Bank number.
9670  * Access: Index
9671  */
9672 MLXSW_ITEM32(reg, mcia, bank_number, 0x08, 16, 8);
9673 
9674 /* reg_mcia_size
9675  * Number of bytes to read/write (up to 48 bytes).
9676  * Access: RW
9677  */
9678 MLXSW_ITEM32(reg, mcia, size, 0x08, 0, 16);
9679 
9680 #define MLXSW_REG_MCIA_EEPROM_PAGE_LENGTH	256
9681 #define MLXSW_REG_MCIA_EEPROM_UP_PAGE_LENGTH	128
9682 #define MLXSW_REG_MCIA_EEPROM_SIZE		48
9683 #define MLXSW_REG_MCIA_I2C_ADDR_LOW		0x50
9684 #define MLXSW_REG_MCIA_I2C_ADDR_HIGH		0x51
9685 #define MLXSW_REG_MCIA_PAGE0_LO_OFF		0xa0
9686 #define MLXSW_REG_MCIA_TH_ITEM_SIZE		2
9687 #define MLXSW_REG_MCIA_TH_PAGE_NUM		3
9688 #define MLXSW_REG_MCIA_TH_PAGE_CMIS_NUM		2
9689 #define MLXSW_REG_MCIA_PAGE0_LO			0
9690 #define MLXSW_REG_MCIA_TH_PAGE_OFF		0x80
9691 #define MLXSW_REG_MCIA_EEPROM_CMIS_FLAT_MEMORY	BIT(7)
9692 
9693 enum mlxsw_reg_mcia_eeprom_module_info_rev_id {
9694 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_REV_ID_UNSPC	= 0x00,
9695 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_REV_ID_8436	= 0x01,
9696 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_REV_ID_8636	= 0x03,
9697 };
9698 
9699 enum mlxsw_reg_mcia_eeprom_module_info_id {
9700 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_SFP	= 0x03,
9701 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP	= 0x0C,
9702 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP_PLUS	= 0x0D,
9703 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP28	= 0x11,
9704 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP_DD	= 0x18,
9705 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_OSFP	= 0x19,
9706 };
9707 
9708 enum mlxsw_reg_mcia_eeprom_module_info {
9709 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID,
9710 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_REV_ID,
9711 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_TYPE_ID,
9712 	MLXSW_REG_MCIA_EEPROM_MODULE_INFO_SIZE,
9713 };
9714 
9715 /* reg_mcia_eeprom
9716  * Bytes to read/write.
9717  * Access: RW
9718  */
9719 MLXSW_ITEM_BUF(reg, mcia, eeprom, 0x10, MLXSW_REG_MCIA_EEPROM_SIZE);
9720 
9721 /* This is used to access the optional upper pages (1-3) in the QSFP+
9722  * memory map. Page 1 is available on offset 256 through 383, page 2 -
9723  * on offset 384 through 511, page 3 - on offset 512 through 639.
9724  */
9725 #define MLXSW_REG_MCIA_PAGE_GET(off) (((off) - \
9726 				MLXSW_REG_MCIA_EEPROM_PAGE_LENGTH) / \
9727 				MLXSW_REG_MCIA_EEPROM_UP_PAGE_LENGTH + 1)
9728 
9729 static inline void mlxsw_reg_mcia_pack(char *payload, u8 slot_index, u8 module,
9730 				       u8 lock, u8 page_number,
9731 				       u16 device_addr, u8 size,
9732 				       u8 i2c_device_addr)
9733 {
9734 	MLXSW_REG_ZERO(mcia, payload);
9735 	mlxsw_reg_mcia_slot_set(payload, slot_index);
9736 	mlxsw_reg_mcia_module_set(payload, module);
9737 	mlxsw_reg_mcia_l_set(payload, lock);
9738 	mlxsw_reg_mcia_page_number_set(payload, page_number);
9739 	mlxsw_reg_mcia_device_address_set(payload, device_addr);
9740 	mlxsw_reg_mcia_size_set(payload, size);
9741 	mlxsw_reg_mcia_i2c_device_address_set(payload, i2c_device_addr);
9742 }
9743 
9744 /* MPAT - Monitoring Port Analyzer Table
9745  * -------------------------------------
9746  * MPAT Register is used to query and configure the Switch PortAnalyzer Table.
9747  * For an enabled analyzer, all fields except e (enable) cannot be modified.
9748  */
9749 #define MLXSW_REG_MPAT_ID 0x901A
9750 #define MLXSW_REG_MPAT_LEN 0x78
9751 
9752 MLXSW_REG_DEFINE(mpat, MLXSW_REG_MPAT_ID, MLXSW_REG_MPAT_LEN);
9753 
9754 /* reg_mpat_pa_id
9755  * Port Analyzer ID.
9756  * Access: Index
9757  */
9758 MLXSW_ITEM32(reg, mpat, pa_id, 0x00, 28, 4);
9759 
9760 /* reg_mpat_session_id
9761  * Mirror Session ID.
9762  * Used for MIRROR_SESSION<i> trap.
9763  * Access: RW
9764  */
9765 MLXSW_ITEM32(reg, mpat, session_id, 0x00, 24, 4);
9766 
9767 /* reg_mpat_system_port
9768  * A unique port identifier for the final destination of the packet.
9769  * Access: RW
9770  */
9771 MLXSW_ITEM32(reg, mpat, system_port, 0x00, 0, 16);
9772 
9773 /* reg_mpat_e
9774  * Enable. Indicating the Port Analyzer is enabled.
9775  * Access: RW
9776  */
9777 MLXSW_ITEM32(reg, mpat, e, 0x04, 31, 1);
9778 
9779 /* reg_mpat_qos
9780  * Quality Of Service Mode.
9781  * 0: CONFIGURED - QoS parameters (Switch Priority, and encapsulation
9782  * PCP, DEI, DSCP or VL) are configured.
9783  * 1: MAINTAIN - QoS parameters (Switch Priority, Color) are the
9784  * same as in the original packet that has triggered the mirroring. For
9785  * SPAN also the pcp,dei are maintained.
9786  * Access: RW
9787  */
9788 MLXSW_ITEM32(reg, mpat, qos, 0x04, 26, 1);
9789 
9790 /* reg_mpat_be
9791  * Best effort mode. Indicates mirroring traffic should not cause packet
9792  * drop or back pressure, but will discard the mirrored packets. Mirrored
9793  * packets will be forwarded on a best effort manner.
9794  * 0: Do not discard mirrored packets
9795  * 1: Discard mirrored packets if causing congestion
9796  * Access: RW
9797  */
9798 MLXSW_ITEM32(reg, mpat, be, 0x04, 25, 1);
9799 
9800 enum mlxsw_reg_mpat_span_type {
9801 	/* Local SPAN Ethernet.
9802 	 * The original packet is not encapsulated.
9803 	 */
9804 	MLXSW_REG_MPAT_SPAN_TYPE_LOCAL_ETH = 0x0,
9805 
9806 	/* Remote SPAN Ethernet VLAN.
9807 	 * The packet is forwarded to the monitoring port on the monitoring
9808 	 * VLAN.
9809 	 */
9810 	MLXSW_REG_MPAT_SPAN_TYPE_REMOTE_ETH = 0x1,
9811 
9812 	/* Encapsulated Remote SPAN Ethernet L3 GRE.
9813 	 * The packet is encapsulated with GRE header.
9814 	 */
9815 	MLXSW_REG_MPAT_SPAN_TYPE_REMOTE_ETH_L3 = 0x3,
9816 };
9817 
9818 /* reg_mpat_span_type
9819  * SPAN type.
9820  * Access: RW
9821  */
9822 MLXSW_ITEM32(reg, mpat, span_type, 0x04, 0, 4);
9823 
9824 /* reg_mpat_pide
9825  * Policer enable.
9826  * Access: RW
9827  */
9828 MLXSW_ITEM32(reg, mpat, pide, 0x0C, 15, 1);
9829 
9830 /* reg_mpat_pid
9831  * Policer ID.
9832  * Access: RW
9833  */
9834 MLXSW_ITEM32(reg, mpat, pid, 0x0C, 0, 14);
9835 
9836 /* Remote SPAN - Ethernet VLAN
9837  * - - - - - - - - - - - - - -
9838  */
9839 
9840 /* reg_mpat_eth_rspan_vid
9841  * Encapsulation header VLAN ID.
9842  * Access: RW
9843  */
9844 MLXSW_ITEM32(reg, mpat, eth_rspan_vid, 0x18, 0, 12);
9845 
9846 /* Encapsulated Remote SPAN - Ethernet L2
9847  * - - - - - - - - - - - - - - - - - - -
9848  */
9849 
9850 enum mlxsw_reg_mpat_eth_rspan_version {
9851 	MLXSW_REG_MPAT_ETH_RSPAN_VERSION_NO_HEADER = 15,
9852 };
9853 
9854 /* reg_mpat_eth_rspan_version
9855  * RSPAN mirror header version.
9856  * Access: RW
9857  */
9858 MLXSW_ITEM32(reg, mpat, eth_rspan_version, 0x10, 18, 4);
9859 
9860 /* reg_mpat_eth_rspan_mac
9861  * Destination MAC address.
9862  * Access: RW
9863  */
9864 MLXSW_ITEM_BUF(reg, mpat, eth_rspan_mac, 0x12, 6);
9865 
9866 /* reg_mpat_eth_rspan_tp
9867  * Tag Packet. Indicates whether the mirroring header should be VLAN tagged.
9868  * Access: RW
9869  */
9870 MLXSW_ITEM32(reg, mpat, eth_rspan_tp, 0x18, 16, 1);
9871 
9872 /* Encapsulated Remote SPAN - Ethernet L3
9873  * - - - - - - - - - - - - - - - - - - -
9874  */
9875 
9876 enum mlxsw_reg_mpat_eth_rspan_protocol {
9877 	MLXSW_REG_MPAT_ETH_RSPAN_PROTOCOL_IPV4,
9878 	MLXSW_REG_MPAT_ETH_RSPAN_PROTOCOL_IPV6,
9879 };
9880 
9881 /* reg_mpat_eth_rspan_protocol
9882  * SPAN encapsulation protocol.
9883  * Access: RW
9884  */
9885 MLXSW_ITEM32(reg, mpat, eth_rspan_protocol, 0x18, 24, 4);
9886 
9887 /* reg_mpat_eth_rspan_ttl
9888  * Encapsulation header Time-to-Live/HopLimit.
9889  * Access: RW
9890  */
9891 MLXSW_ITEM32(reg, mpat, eth_rspan_ttl, 0x1C, 4, 8);
9892 
9893 /* reg_mpat_eth_rspan_smac
9894  * Source MAC address
9895  * Access: RW
9896  */
9897 MLXSW_ITEM_BUF(reg, mpat, eth_rspan_smac, 0x22, 6);
9898 
9899 /* reg_mpat_eth_rspan_dip*
9900  * Destination IP address. The IP version is configured by protocol.
9901  * Access: RW
9902  */
9903 MLXSW_ITEM32(reg, mpat, eth_rspan_dip4, 0x4C, 0, 32);
9904 MLXSW_ITEM_BUF(reg, mpat, eth_rspan_dip6, 0x40, 16);
9905 
9906 /* reg_mpat_eth_rspan_sip*
9907  * Source IP address. The IP version is configured by protocol.
9908  * Access: RW
9909  */
9910 MLXSW_ITEM32(reg, mpat, eth_rspan_sip4, 0x5C, 0, 32);
9911 MLXSW_ITEM_BUF(reg, mpat, eth_rspan_sip6, 0x50, 16);
9912 
9913 static inline void mlxsw_reg_mpat_pack(char *payload, u8 pa_id,
9914 				       u16 system_port, bool e,
9915 				       enum mlxsw_reg_mpat_span_type span_type)
9916 {
9917 	MLXSW_REG_ZERO(mpat, payload);
9918 	mlxsw_reg_mpat_pa_id_set(payload, pa_id);
9919 	mlxsw_reg_mpat_system_port_set(payload, system_port);
9920 	mlxsw_reg_mpat_e_set(payload, e);
9921 	mlxsw_reg_mpat_qos_set(payload, 1);
9922 	mlxsw_reg_mpat_be_set(payload, 1);
9923 	mlxsw_reg_mpat_span_type_set(payload, span_type);
9924 }
9925 
9926 static inline void mlxsw_reg_mpat_eth_rspan_pack(char *payload, u16 vid)
9927 {
9928 	mlxsw_reg_mpat_eth_rspan_vid_set(payload, vid);
9929 }
9930 
9931 static inline void
9932 mlxsw_reg_mpat_eth_rspan_l2_pack(char *payload,
9933 				 enum mlxsw_reg_mpat_eth_rspan_version version,
9934 				 const char *mac,
9935 				 bool tp)
9936 {
9937 	mlxsw_reg_mpat_eth_rspan_version_set(payload, version);
9938 	mlxsw_reg_mpat_eth_rspan_mac_memcpy_to(payload, mac);
9939 	mlxsw_reg_mpat_eth_rspan_tp_set(payload, tp);
9940 }
9941 
9942 static inline void
9943 mlxsw_reg_mpat_eth_rspan_l3_ipv4_pack(char *payload, u8 ttl,
9944 				      const char *smac,
9945 				      u32 sip, u32 dip)
9946 {
9947 	mlxsw_reg_mpat_eth_rspan_ttl_set(payload, ttl);
9948 	mlxsw_reg_mpat_eth_rspan_smac_memcpy_to(payload, smac);
9949 	mlxsw_reg_mpat_eth_rspan_protocol_set(payload,
9950 				    MLXSW_REG_MPAT_ETH_RSPAN_PROTOCOL_IPV4);
9951 	mlxsw_reg_mpat_eth_rspan_sip4_set(payload, sip);
9952 	mlxsw_reg_mpat_eth_rspan_dip4_set(payload, dip);
9953 }
9954 
9955 static inline void
9956 mlxsw_reg_mpat_eth_rspan_l3_ipv6_pack(char *payload, u8 ttl,
9957 				      const char *smac,
9958 				      struct in6_addr sip, struct in6_addr dip)
9959 {
9960 	mlxsw_reg_mpat_eth_rspan_ttl_set(payload, ttl);
9961 	mlxsw_reg_mpat_eth_rspan_smac_memcpy_to(payload, smac);
9962 	mlxsw_reg_mpat_eth_rspan_protocol_set(payload,
9963 				    MLXSW_REG_MPAT_ETH_RSPAN_PROTOCOL_IPV6);
9964 	mlxsw_reg_mpat_eth_rspan_sip6_memcpy_to(payload, (void *)&sip);
9965 	mlxsw_reg_mpat_eth_rspan_dip6_memcpy_to(payload, (void *)&dip);
9966 }
9967 
9968 /* MPAR - Monitoring Port Analyzer Register
9969  * ----------------------------------------
9970  * MPAR register is used to query and configure the port analyzer port mirroring
9971  * properties.
9972  */
9973 #define MLXSW_REG_MPAR_ID 0x901B
9974 #define MLXSW_REG_MPAR_LEN 0x0C
9975 
9976 MLXSW_REG_DEFINE(mpar, MLXSW_REG_MPAR_ID, MLXSW_REG_MPAR_LEN);
9977 
9978 /* reg_mpar_local_port
9979  * The local port to mirror the packets from.
9980  * Access: Index
9981  */
9982 MLXSW_ITEM32_LP(reg, mpar, 0x00, 16, 0x00, 4);
9983 
9984 enum mlxsw_reg_mpar_i_e {
9985 	MLXSW_REG_MPAR_TYPE_EGRESS,
9986 	MLXSW_REG_MPAR_TYPE_INGRESS,
9987 };
9988 
9989 /* reg_mpar_i_e
9990  * Ingress/Egress
9991  * Access: Index
9992  */
9993 MLXSW_ITEM32(reg, mpar, i_e, 0x00, 0, 4);
9994 
9995 /* reg_mpar_enable
9996  * Enable mirroring
9997  * By default, port mirroring is disabled for all ports.
9998  * Access: RW
9999  */
10000 MLXSW_ITEM32(reg, mpar, enable, 0x04, 31, 1);
10001 
10002 /* reg_mpar_pa_id
10003  * Port Analyzer ID.
10004  * Access: RW
10005  */
10006 MLXSW_ITEM32(reg, mpar, pa_id, 0x04, 0, 4);
10007 
10008 #define MLXSW_REG_MPAR_RATE_MAX 3500000000UL
10009 
10010 /* reg_mpar_probability_rate
10011  * Sampling rate.
10012  * Valid values are: 1 to 3.5*10^9
10013  * Value of 1 means "sample all". Default is 1.
10014  * Reserved when Spectrum-1.
10015  * Access: RW
10016  */
10017 MLXSW_ITEM32(reg, mpar, probability_rate, 0x08, 0, 32);
10018 
10019 static inline void mlxsw_reg_mpar_pack(char *payload, u16 local_port,
10020 				       enum mlxsw_reg_mpar_i_e i_e,
10021 				       bool enable, u8 pa_id,
10022 				       u32 probability_rate)
10023 {
10024 	MLXSW_REG_ZERO(mpar, payload);
10025 	mlxsw_reg_mpar_local_port_set(payload, local_port);
10026 	mlxsw_reg_mpar_enable_set(payload, enable);
10027 	mlxsw_reg_mpar_i_e_set(payload, i_e);
10028 	mlxsw_reg_mpar_pa_id_set(payload, pa_id);
10029 	mlxsw_reg_mpar_probability_rate_set(payload, probability_rate);
10030 }
10031 
10032 /* MGIR - Management General Information Register
10033  * ----------------------------------------------
10034  * MGIR register allows software to query the hardware and firmware general
10035  * information.
10036  */
10037 #define MLXSW_REG_MGIR_ID 0x9020
10038 #define MLXSW_REG_MGIR_LEN 0x9C
10039 
10040 MLXSW_REG_DEFINE(mgir, MLXSW_REG_MGIR_ID, MLXSW_REG_MGIR_LEN);
10041 
10042 /* reg_mgir_hw_info_device_hw_revision
10043  * Access: RO
10044  */
10045 MLXSW_ITEM32(reg, mgir, hw_info_device_hw_revision, 0x0, 16, 16);
10046 
10047 #define MLXSW_REG_MGIR_FW_INFO_PSID_SIZE 16
10048 
10049 /* reg_mgir_fw_info_psid
10050  * PSID (ASCII string).
10051  * Access: RO
10052  */
10053 MLXSW_ITEM_BUF(reg, mgir, fw_info_psid, 0x30, MLXSW_REG_MGIR_FW_INFO_PSID_SIZE);
10054 
10055 /* reg_mgir_fw_info_extended_major
10056  * Access: RO
10057  */
10058 MLXSW_ITEM32(reg, mgir, fw_info_extended_major, 0x44, 0, 32);
10059 
10060 /* reg_mgir_fw_info_extended_minor
10061  * Access: RO
10062  */
10063 MLXSW_ITEM32(reg, mgir, fw_info_extended_minor, 0x48, 0, 32);
10064 
10065 /* reg_mgir_fw_info_extended_sub_minor
10066  * Access: RO
10067  */
10068 MLXSW_ITEM32(reg, mgir, fw_info_extended_sub_minor, 0x4C, 0, 32);
10069 
10070 static inline void mlxsw_reg_mgir_pack(char *payload)
10071 {
10072 	MLXSW_REG_ZERO(mgir, payload);
10073 }
10074 
10075 static inline void
10076 mlxsw_reg_mgir_unpack(char *payload, u32 *hw_rev, char *fw_info_psid,
10077 		      u32 *fw_major, u32 *fw_minor, u32 *fw_sub_minor)
10078 {
10079 	*hw_rev = mlxsw_reg_mgir_hw_info_device_hw_revision_get(payload);
10080 	mlxsw_reg_mgir_fw_info_psid_memcpy_from(payload, fw_info_psid);
10081 	*fw_major = mlxsw_reg_mgir_fw_info_extended_major_get(payload);
10082 	*fw_minor = mlxsw_reg_mgir_fw_info_extended_minor_get(payload);
10083 	*fw_sub_minor = mlxsw_reg_mgir_fw_info_extended_sub_minor_get(payload);
10084 }
10085 
10086 /* MRSR - Management Reset and Shutdown Register
10087  * ---------------------------------------------
10088  * MRSR register is used to reset or shutdown the switch or
10089  * the entire system (when applicable).
10090  */
10091 #define MLXSW_REG_MRSR_ID 0x9023
10092 #define MLXSW_REG_MRSR_LEN 0x08
10093 
10094 MLXSW_REG_DEFINE(mrsr, MLXSW_REG_MRSR_ID, MLXSW_REG_MRSR_LEN);
10095 
10096 /* reg_mrsr_command
10097  * Reset/shutdown command
10098  * 0 - do nothing
10099  * 1 - software reset
10100  * Access: WO
10101  */
10102 MLXSW_ITEM32(reg, mrsr, command, 0x00, 0, 4);
10103 
10104 static inline void mlxsw_reg_mrsr_pack(char *payload)
10105 {
10106 	MLXSW_REG_ZERO(mrsr, payload);
10107 	mlxsw_reg_mrsr_command_set(payload, 1);
10108 }
10109 
10110 /* MLCR - Management LED Control Register
10111  * --------------------------------------
10112  * Controls the system LEDs.
10113  */
10114 #define MLXSW_REG_MLCR_ID 0x902B
10115 #define MLXSW_REG_MLCR_LEN 0x0C
10116 
10117 MLXSW_REG_DEFINE(mlcr, MLXSW_REG_MLCR_ID, MLXSW_REG_MLCR_LEN);
10118 
10119 /* reg_mlcr_local_port
10120  * Local port number.
10121  * Access: RW
10122  */
10123 MLXSW_ITEM32_LP(reg, mlcr, 0x00, 16, 0x00, 24);
10124 
10125 #define MLXSW_REG_MLCR_DURATION_MAX 0xFFFF
10126 
10127 /* reg_mlcr_beacon_duration
10128  * Duration of the beacon to be active, in seconds.
10129  * 0x0 - Will turn off the beacon.
10130  * 0xFFFF - Will turn on the beacon until explicitly turned off.
10131  * Access: RW
10132  */
10133 MLXSW_ITEM32(reg, mlcr, beacon_duration, 0x04, 0, 16);
10134 
10135 /* reg_mlcr_beacon_remain
10136  * Remaining duration of the beacon, in seconds.
10137  * 0xFFFF indicates an infinite amount of time.
10138  * Access: RO
10139  */
10140 MLXSW_ITEM32(reg, mlcr, beacon_remain, 0x08, 0, 16);
10141 
10142 static inline void mlxsw_reg_mlcr_pack(char *payload, u16 local_port,
10143 				       bool active)
10144 {
10145 	MLXSW_REG_ZERO(mlcr, payload);
10146 	mlxsw_reg_mlcr_local_port_set(payload, local_port);
10147 	mlxsw_reg_mlcr_beacon_duration_set(payload, active ?
10148 					   MLXSW_REG_MLCR_DURATION_MAX : 0);
10149 }
10150 
10151 /* MCION - Management Cable IO and Notifications Register
10152  * ------------------------------------------------------
10153  * The MCION register is used to query transceiver modules' IO pins and other
10154  * notifications.
10155  */
10156 #define MLXSW_REG_MCION_ID 0x9052
10157 #define MLXSW_REG_MCION_LEN 0x18
10158 
10159 MLXSW_REG_DEFINE(mcion, MLXSW_REG_MCION_ID, MLXSW_REG_MCION_LEN);
10160 
10161 /* reg_mcion_module
10162  * Module number.
10163  * Access: Index
10164  */
10165 MLXSW_ITEM32(reg, mcion, module, 0x00, 16, 8);
10166 
10167 /* reg_mcion_slot_index
10168  * Slot index.
10169  * Access: Index
10170  */
10171 MLXSW_ITEM32(reg, mcion, slot_index, 0x00, 12, 4);
10172 
10173 enum {
10174 	MLXSW_REG_MCION_MODULE_STATUS_BITS_PRESENT_MASK = BIT(0),
10175 	MLXSW_REG_MCION_MODULE_STATUS_BITS_LOW_POWER_MASK = BIT(8),
10176 };
10177 
10178 /* reg_mcion_module_status_bits
10179  * Module IO status as defined by SFF.
10180  * Access: RO
10181  */
10182 MLXSW_ITEM32(reg, mcion, module_status_bits, 0x04, 0, 16);
10183 
10184 static inline void mlxsw_reg_mcion_pack(char *payload, u8 slot_index, u8 module)
10185 {
10186 	MLXSW_REG_ZERO(mcion, payload);
10187 	mlxsw_reg_mcion_slot_index_set(payload, slot_index);
10188 	mlxsw_reg_mcion_module_set(payload, module);
10189 }
10190 
10191 /* MTPPS - Management Pulse Per Second Register
10192  * --------------------------------------------
10193  * This register provides the device PPS capabilities, configure the PPS in and
10194  * out modules and holds the PPS in time stamp.
10195  */
10196 #define MLXSW_REG_MTPPS_ID 0x9053
10197 #define MLXSW_REG_MTPPS_LEN 0x3C
10198 
10199 MLXSW_REG_DEFINE(mtpps, MLXSW_REG_MTPPS_ID, MLXSW_REG_MTPPS_LEN);
10200 
10201 /* reg_mtpps_enable
10202  * Enables the PPS functionality the specific pin.
10203  * A boolean variable.
10204  * Access: RW
10205  */
10206 MLXSW_ITEM32(reg, mtpps, enable, 0x20, 31, 1);
10207 
10208 enum mlxsw_reg_mtpps_pin_mode {
10209 	MLXSW_REG_MTPPS_PIN_MODE_VIRTUAL_PIN = 0x2,
10210 };
10211 
10212 /* reg_mtpps_pin_mode
10213  * Pin mode to be used. The mode must comply with the supported modes of the
10214  * requested pin.
10215  * Access: RW
10216  */
10217 MLXSW_ITEM32(reg, mtpps, pin_mode, 0x20, 8, 4);
10218 
10219 #define MLXSW_REG_MTPPS_PIN_SP_VIRTUAL_PIN	7
10220 
10221 /* reg_mtpps_pin
10222  * Pin to be configured or queried out of the supported pins.
10223  * Access: Index
10224  */
10225 MLXSW_ITEM32(reg, mtpps, pin, 0x20, 0, 8);
10226 
10227 /* reg_mtpps_time_stamp
10228  * When pin_mode = pps_in, the latched device time when it was triggered from
10229  * the external GPIO pin.
10230  * When pin_mode = pps_out or virtual_pin or pps_out_and_virtual_pin, the target
10231  * time to generate next output signal.
10232  * Time is in units of device clock.
10233  * Access: RW
10234  */
10235 MLXSW_ITEM64(reg, mtpps, time_stamp, 0x28, 0, 64);
10236 
10237 static inline void
10238 mlxsw_reg_mtpps_vpin_pack(char *payload, u64 time_stamp)
10239 {
10240 	MLXSW_REG_ZERO(mtpps, payload);
10241 	mlxsw_reg_mtpps_pin_set(payload, MLXSW_REG_MTPPS_PIN_SP_VIRTUAL_PIN);
10242 	mlxsw_reg_mtpps_pin_mode_set(payload,
10243 				     MLXSW_REG_MTPPS_PIN_MODE_VIRTUAL_PIN);
10244 	mlxsw_reg_mtpps_enable_set(payload, true);
10245 	mlxsw_reg_mtpps_time_stamp_set(payload, time_stamp);
10246 }
10247 
10248 /* MTUTC - Management UTC Register
10249  * -------------------------------
10250  * Configures the HW UTC counter.
10251  */
10252 #define MLXSW_REG_MTUTC_ID 0x9055
10253 #define MLXSW_REG_MTUTC_LEN 0x1C
10254 
10255 MLXSW_REG_DEFINE(mtutc, MLXSW_REG_MTUTC_ID, MLXSW_REG_MTUTC_LEN);
10256 
10257 enum mlxsw_reg_mtutc_operation {
10258 	MLXSW_REG_MTUTC_OPERATION_SET_TIME_AT_NEXT_SEC = 0,
10259 	MLXSW_REG_MTUTC_OPERATION_SET_TIME_IMMEDIATE = 1,
10260 	MLXSW_REG_MTUTC_OPERATION_ADJUST_TIME = 2,
10261 	MLXSW_REG_MTUTC_OPERATION_ADJUST_FREQ = 3,
10262 };
10263 
10264 /* reg_mtutc_operation
10265  * Operation.
10266  * Access: OP
10267  */
10268 MLXSW_ITEM32(reg, mtutc, operation, 0x00, 0, 4);
10269 
10270 /* reg_mtutc_freq_adjustment
10271  * Frequency adjustment: Every PPS the HW frequency will be
10272  * adjusted by this value. Units of HW clock, where HW counts
10273  * 10^9 HW clocks for 1 HW second. Range is from -50,000,000 to +50,000,000.
10274  * In Spectrum-2, the field is reversed, positive values mean to decrease the
10275  * frequency.
10276  * Access: RW
10277  */
10278 MLXSW_ITEM32(reg, mtutc, freq_adjustment, 0x04, 0, 32);
10279 
10280 #define MLXSW_REG_MTUTC_MAX_FREQ_ADJ (50 * 1000 * 1000)
10281 
10282 /* reg_mtutc_utc_sec
10283  * UTC seconds.
10284  * Access: WO
10285  */
10286 MLXSW_ITEM32(reg, mtutc, utc_sec, 0x10, 0, 32);
10287 
10288 /* reg_mtutc_utc_nsec
10289  * UTC nSecs.
10290  * Range 0..(10^9-1)
10291  * Updated when operation is SET_TIME_IMMEDIATE.
10292  * Reserved on Spectrum-1.
10293  * Access: WO
10294  */
10295 MLXSW_ITEM32(reg, mtutc, utc_nsec, 0x14, 0, 30);
10296 
10297 /* reg_mtutc_time_adjustment
10298  * Time adjustment.
10299  * Units of nSec.
10300  * Range is from -32768 to +32767.
10301  * Updated when operation is ADJUST_TIME.
10302  * Reserved on Spectrum-1.
10303  * Access: WO
10304  */
10305 MLXSW_ITEM32(reg, mtutc, time_adjustment, 0x18, 0, 32);
10306 
10307 static inline void
10308 mlxsw_reg_mtutc_pack(char *payload, enum mlxsw_reg_mtutc_operation oper,
10309 		     u32 freq_adj, u32 utc_sec, u32 utc_nsec, u32 time_adj)
10310 {
10311 	MLXSW_REG_ZERO(mtutc, payload);
10312 	mlxsw_reg_mtutc_operation_set(payload, oper);
10313 	mlxsw_reg_mtutc_freq_adjustment_set(payload, freq_adj);
10314 	mlxsw_reg_mtutc_utc_sec_set(payload, utc_sec);
10315 	mlxsw_reg_mtutc_utc_nsec_set(payload, utc_nsec);
10316 	mlxsw_reg_mtutc_time_adjustment_set(payload, time_adj);
10317 }
10318 
10319 /* MCQI - Management Component Query Information
10320  * ---------------------------------------------
10321  * This register allows querying information about firmware components.
10322  */
10323 #define MLXSW_REG_MCQI_ID 0x9061
10324 #define MLXSW_REG_MCQI_BASE_LEN 0x18
10325 #define MLXSW_REG_MCQI_CAP_LEN 0x14
10326 #define MLXSW_REG_MCQI_LEN (MLXSW_REG_MCQI_BASE_LEN + MLXSW_REG_MCQI_CAP_LEN)
10327 
10328 MLXSW_REG_DEFINE(mcqi, MLXSW_REG_MCQI_ID, MLXSW_REG_MCQI_LEN);
10329 
10330 /* reg_mcqi_component_index
10331  * Index of the accessed component.
10332  * Access: Index
10333  */
10334 MLXSW_ITEM32(reg, mcqi, component_index, 0x00, 0, 16);
10335 
10336 enum mlxfw_reg_mcqi_info_type {
10337 	MLXSW_REG_MCQI_INFO_TYPE_CAPABILITIES,
10338 };
10339 
10340 /* reg_mcqi_info_type
10341  * Component properties set.
10342  * Access: RW
10343  */
10344 MLXSW_ITEM32(reg, mcqi, info_type, 0x08, 0, 5);
10345 
10346 /* reg_mcqi_offset
10347  * The requested/returned data offset from the section start, given in bytes.
10348  * Must be DWORD aligned.
10349  * Access: RW
10350  */
10351 MLXSW_ITEM32(reg, mcqi, offset, 0x10, 0, 32);
10352 
10353 /* reg_mcqi_data_size
10354  * The requested/returned data size, given in bytes. If data_size is not DWORD
10355  * aligned, the last bytes are zero padded.
10356  * Access: RW
10357  */
10358 MLXSW_ITEM32(reg, mcqi, data_size, 0x14, 0, 16);
10359 
10360 /* reg_mcqi_cap_max_component_size
10361  * Maximum size for this component, given in bytes.
10362  * Access: RO
10363  */
10364 MLXSW_ITEM32(reg, mcqi, cap_max_component_size, 0x20, 0, 32);
10365 
10366 /* reg_mcqi_cap_log_mcda_word_size
10367  * Log 2 of the access word size in bytes. Read and write access must be aligned
10368  * to the word size. Write access must be done for an integer number of words.
10369  * Access: RO
10370  */
10371 MLXSW_ITEM32(reg, mcqi, cap_log_mcda_word_size, 0x24, 28, 4);
10372 
10373 /* reg_mcqi_cap_mcda_max_write_size
10374  * Maximal write size for MCDA register
10375  * Access: RO
10376  */
10377 MLXSW_ITEM32(reg, mcqi, cap_mcda_max_write_size, 0x24, 0, 16);
10378 
10379 static inline void mlxsw_reg_mcqi_pack(char *payload, u16 component_index)
10380 {
10381 	MLXSW_REG_ZERO(mcqi, payload);
10382 	mlxsw_reg_mcqi_component_index_set(payload, component_index);
10383 	mlxsw_reg_mcqi_info_type_set(payload,
10384 				     MLXSW_REG_MCQI_INFO_TYPE_CAPABILITIES);
10385 	mlxsw_reg_mcqi_offset_set(payload, 0);
10386 	mlxsw_reg_mcqi_data_size_set(payload, MLXSW_REG_MCQI_CAP_LEN);
10387 }
10388 
10389 static inline void mlxsw_reg_mcqi_unpack(char *payload,
10390 					 u32 *p_cap_max_component_size,
10391 					 u8 *p_cap_log_mcda_word_size,
10392 					 u16 *p_cap_mcda_max_write_size)
10393 {
10394 	*p_cap_max_component_size =
10395 		mlxsw_reg_mcqi_cap_max_component_size_get(payload);
10396 	*p_cap_log_mcda_word_size =
10397 		mlxsw_reg_mcqi_cap_log_mcda_word_size_get(payload);
10398 	*p_cap_mcda_max_write_size =
10399 		mlxsw_reg_mcqi_cap_mcda_max_write_size_get(payload);
10400 }
10401 
10402 /* MCC - Management Component Control
10403  * ----------------------------------
10404  * Controls the firmware component and updates the FSM.
10405  */
10406 #define MLXSW_REG_MCC_ID 0x9062
10407 #define MLXSW_REG_MCC_LEN 0x1C
10408 
10409 MLXSW_REG_DEFINE(mcc, MLXSW_REG_MCC_ID, MLXSW_REG_MCC_LEN);
10410 
10411 enum mlxsw_reg_mcc_instruction {
10412 	MLXSW_REG_MCC_INSTRUCTION_LOCK_UPDATE_HANDLE = 0x01,
10413 	MLXSW_REG_MCC_INSTRUCTION_RELEASE_UPDATE_HANDLE = 0x02,
10414 	MLXSW_REG_MCC_INSTRUCTION_UPDATE_COMPONENT = 0x03,
10415 	MLXSW_REG_MCC_INSTRUCTION_VERIFY_COMPONENT = 0x04,
10416 	MLXSW_REG_MCC_INSTRUCTION_ACTIVATE = 0x06,
10417 	MLXSW_REG_MCC_INSTRUCTION_CANCEL = 0x08,
10418 };
10419 
10420 /* reg_mcc_instruction
10421  * Command to be executed by the FSM.
10422  * Applicable for write operation only.
10423  * Access: RW
10424  */
10425 MLXSW_ITEM32(reg, mcc, instruction, 0x00, 0, 8);
10426 
10427 /* reg_mcc_component_index
10428  * Index of the accessed component. Applicable only for commands that
10429  * refer to components. Otherwise, this field is reserved.
10430  * Access: Index
10431  */
10432 MLXSW_ITEM32(reg, mcc, component_index, 0x04, 0, 16);
10433 
10434 /* reg_mcc_update_handle
10435  * Token representing the current flow executed by the FSM.
10436  * Access: WO
10437  */
10438 MLXSW_ITEM32(reg, mcc, update_handle, 0x08, 0, 24);
10439 
10440 /* reg_mcc_error_code
10441  * Indicates the successful completion of the instruction, or the reason it
10442  * failed
10443  * Access: RO
10444  */
10445 MLXSW_ITEM32(reg, mcc, error_code, 0x0C, 8, 8);
10446 
10447 /* reg_mcc_control_state
10448  * Current FSM state
10449  * Access: RO
10450  */
10451 MLXSW_ITEM32(reg, mcc, control_state, 0x0C, 0, 4);
10452 
10453 /* reg_mcc_component_size
10454  * Component size in bytes. Valid for UPDATE_COMPONENT instruction. Specifying
10455  * the size may shorten the update time. Value 0x0 means that size is
10456  * unspecified.
10457  * Access: WO
10458  */
10459 MLXSW_ITEM32(reg, mcc, component_size, 0x10, 0, 32);
10460 
10461 static inline void mlxsw_reg_mcc_pack(char *payload,
10462 				      enum mlxsw_reg_mcc_instruction instr,
10463 				      u16 component_index, u32 update_handle,
10464 				      u32 component_size)
10465 {
10466 	MLXSW_REG_ZERO(mcc, payload);
10467 	mlxsw_reg_mcc_instruction_set(payload, instr);
10468 	mlxsw_reg_mcc_component_index_set(payload, component_index);
10469 	mlxsw_reg_mcc_update_handle_set(payload, update_handle);
10470 	mlxsw_reg_mcc_component_size_set(payload, component_size);
10471 }
10472 
10473 static inline void mlxsw_reg_mcc_unpack(char *payload, u32 *p_update_handle,
10474 					u8 *p_error_code, u8 *p_control_state)
10475 {
10476 	if (p_update_handle)
10477 		*p_update_handle = mlxsw_reg_mcc_update_handle_get(payload);
10478 	if (p_error_code)
10479 		*p_error_code = mlxsw_reg_mcc_error_code_get(payload);
10480 	if (p_control_state)
10481 		*p_control_state = mlxsw_reg_mcc_control_state_get(payload);
10482 }
10483 
10484 /* MCDA - Management Component Data Access
10485  * ---------------------------------------
10486  * This register allows reading and writing a firmware component.
10487  */
10488 #define MLXSW_REG_MCDA_ID 0x9063
10489 #define MLXSW_REG_MCDA_BASE_LEN 0x10
10490 #define MLXSW_REG_MCDA_MAX_DATA_LEN 0x80
10491 #define MLXSW_REG_MCDA_LEN \
10492 		(MLXSW_REG_MCDA_BASE_LEN + MLXSW_REG_MCDA_MAX_DATA_LEN)
10493 
10494 MLXSW_REG_DEFINE(mcda, MLXSW_REG_MCDA_ID, MLXSW_REG_MCDA_LEN);
10495 
10496 /* reg_mcda_update_handle
10497  * Token representing the current flow executed by the FSM.
10498  * Access: RW
10499  */
10500 MLXSW_ITEM32(reg, mcda, update_handle, 0x00, 0, 24);
10501 
10502 /* reg_mcda_offset
10503  * Offset of accessed address relative to component start. Accesses must be in
10504  * accordance to log_mcda_word_size in MCQI reg.
10505  * Access: RW
10506  */
10507 MLXSW_ITEM32(reg, mcda, offset, 0x04, 0, 32);
10508 
10509 /* reg_mcda_size
10510  * Size of the data accessed, given in bytes.
10511  * Access: RW
10512  */
10513 MLXSW_ITEM32(reg, mcda, size, 0x08, 0, 16);
10514 
10515 /* reg_mcda_data
10516  * Data block accessed.
10517  * Access: RW
10518  */
10519 MLXSW_ITEM32_INDEXED(reg, mcda, data, 0x10, 0, 32, 4, 0, false);
10520 
10521 static inline void mlxsw_reg_mcda_pack(char *payload, u32 update_handle,
10522 				       u32 offset, u16 size, u8 *data)
10523 {
10524 	int i;
10525 
10526 	MLXSW_REG_ZERO(mcda, payload);
10527 	mlxsw_reg_mcda_update_handle_set(payload, update_handle);
10528 	mlxsw_reg_mcda_offset_set(payload, offset);
10529 	mlxsw_reg_mcda_size_set(payload, size);
10530 
10531 	for (i = 0; i < size / 4; i++)
10532 		mlxsw_reg_mcda_data_set(payload, i, *(u32 *) &data[i * 4]);
10533 }
10534 
10535 /* MPSC - Monitoring Packet Sampling Configuration Register
10536  * --------------------------------------------------------
10537  * MPSC Register is used to configure the Packet Sampling mechanism.
10538  */
10539 #define MLXSW_REG_MPSC_ID 0x9080
10540 #define MLXSW_REG_MPSC_LEN 0x1C
10541 
10542 MLXSW_REG_DEFINE(mpsc, MLXSW_REG_MPSC_ID, MLXSW_REG_MPSC_LEN);
10543 
10544 /* reg_mpsc_local_port
10545  * Local port number
10546  * Not supported for CPU port
10547  * Access: Index
10548  */
10549 MLXSW_ITEM32_LP(reg, mpsc, 0x00, 16, 0x00, 12);
10550 
10551 /* reg_mpsc_e
10552  * Enable sampling on port local_port
10553  * Access: RW
10554  */
10555 MLXSW_ITEM32(reg, mpsc, e, 0x04, 30, 1);
10556 
10557 #define MLXSW_REG_MPSC_RATE_MAX 3500000000UL
10558 
10559 /* reg_mpsc_rate
10560  * Sampling rate = 1 out of rate packets (with randomization around
10561  * the point). Valid values are: 1 to MLXSW_REG_MPSC_RATE_MAX
10562  * Access: RW
10563  */
10564 MLXSW_ITEM32(reg, mpsc, rate, 0x08, 0, 32);
10565 
10566 static inline void mlxsw_reg_mpsc_pack(char *payload, u16 local_port, bool e,
10567 				       u32 rate)
10568 {
10569 	MLXSW_REG_ZERO(mpsc, payload);
10570 	mlxsw_reg_mpsc_local_port_set(payload, local_port);
10571 	mlxsw_reg_mpsc_e_set(payload, e);
10572 	mlxsw_reg_mpsc_rate_set(payload, rate);
10573 }
10574 
10575 /* MGPC - Monitoring General Purpose Counter Set Register
10576  * The MGPC register retrieves and sets the General Purpose Counter Set.
10577  */
10578 #define MLXSW_REG_MGPC_ID 0x9081
10579 #define MLXSW_REG_MGPC_LEN 0x18
10580 
10581 MLXSW_REG_DEFINE(mgpc, MLXSW_REG_MGPC_ID, MLXSW_REG_MGPC_LEN);
10582 
10583 /* reg_mgpc_counter_set_type
10584  * Counter set type.
10585  * Access: OP
10586  */
10587 MLXSW_ITEM32(reg, mgpc, counter_set_type, 0x00, 24, 8);
10588 
10589 /* reg_mgpc_counter_index
10590  * Counter index.
10591  * Access: Index
10592  */
10593 MLXSW_ITEM32(reg, mgpc, counter_index, 0x00, 0, 24);
10594 
10595 enum mlxsw_reg_mgpc_opcode {
10596 	/* Nop */
10597 	MLXSW_REG_MGPC_OPCODE_NOP = 0x00,
10598 	/* Clear counters */
10599 	MLXSW_REG_MGPC_OPCODE_CLEAR = 0x08,
10600 };
10601 
10602 /* reg_mgpc_opcode
10603  * Opcode.
10604  * Access: OP
10605  */
10606 MLXSW_ITEM32(reg, mgpc, opcode, 0x04, 28, 4);
10607 
10608 /* reg_mgpc_byte_counter
10609  * Byte counter value.
10610  * Access: RW
10611  */
10612 MLXSW_ITEM64(reg, mgpc, byte_counter, 0x08, 0, 64);
10613 
10614 /* reg_mgpc_packet_counter
10615  * Packet counter value.
10616  * Access: RW
10617  */
10618 MLXSW_ITEM64(reg, mgpc, packet_counter, 0x10, 0, 64);
10619 
10620 static inline void mlxsw_reg_mgpc_pack(char *payload, u32 counter_index,
10621 				       enum mlxsw_reg_mgpc_opcode opcode,
10622 				       enum mlxsw_reg_flow_counter_set_type set_type)
10623 {
10624 	MLXSW_REG_ZERO(mgpc, payload);
10625 	mlxsw_reg_mgpc_counter_index_set(payload, counter_index);
10626 	mlxsw_reg_mgpc_counter_set_type_set(payload, set_type);
10627 	mlxsw_reg_mgpc_opcode_set(payload, opcode);
10628 }
10629 
10630 /* MPRS - Monitoring Parsing State Register
10631  * ----------------------------------------
10632  * The MPRS register is used for setting up the parsing for hash,
10633  * policy-engine and routing.
10634  */
10635 #define MLXSW_REG_MPRS_ID 0x9083
10636 #define MLXSW_REG_MPRS_LEN 0x14
10637 
10638 MLXSW_REG_DEFINE(mprs, MLXSW_REG_MPRS_ID, MLXSW_REG_MPRS_LEN);
10639 
10640 /* reg_mprs_parsing_depth
10641  * Minimum parsing depth.
10642  * Need to enlarge parsing depth according to L3, MPLS, tunnels, ACL
10643  * rules, traps, hash, etc. Default is 96 bytes. Reserved when SwitchX-2.
10644  * Access: RW
10645  */
10646 MLXSW_ITEM32(reg, mprs, parsing_depth, 0x00, 0, 16);
10647 
10648 /* reg_mprs_parsing_en
10649  * Parsing enable.
10650  * Bit 0 - Enable parsing of NVE of types VxLAN, VxLAN-GPE, GENEVE and
10651  * NVGRE. Default is enabled. Reserved when SwitchX-2.
10652  * Access: RW
10653  */
10654 MLXSW_ITEM32(reg, mprs, parsing_en, 0x04, 0, 16);
10655 
10656 /* reg_mprs_vxlan_udp_dport
10657  * VxLAN UDP destination port.
10658  * Used for identifying VxLAN packets and for dport field in
10659  * encapsulation. Default is 4789.
10660  * Access: RW
10661  */
10662 MLXSW_ITEM32(reg, mprs, vxlan_udp_dport, 0x10, 0, 16);
10663 
10664 static inline void mlxsw_reg_mprs_pack(char *payload, u16 parsing_depth,
10665 				       u16 vxlan_udp_dport)
10666 {
10667 	MLXSW_REG_ZERO(mprs, payload);
10668 	mlxsw_reg_mprs_parsing_depth_set(payload, parsing_depth);
10669 	mlxsw_reg_mprs_parsing_en_set(payload, true);
10670 	mlxsw_reg_mprs_vxlan_udp_dport_set(payload, vxlan_udp_dport);
10671 }
10672 
10673 /* MOGCR - Monitoring Global Configuration Register
10674  * ------------------------------------------------
10675  */
10676 #define MLXSW_REG_MOGCR_ID 0x9086
10677 #define MLXSW_REG_MOGCR_LEN 0x20
10678 
10679 MLXSW_REG_DEFINE(mogcr, MLXSW_REG_MOGCR_ID, MLXSW_REG_MOGCR_LEN);
10680 
10681 /* reg_mogcr_ptp_iftc
10682  * PTP Ingress FIFO Trap Clear
10683  * The PTP_ING_FIFO trap provides MTPPTR with clr according
10684  * to this value. Default 0.
10685  * Reserved when IB switches and when SwitchX/-2, Spectrum-2
10686  * Access: RW
10687  */
10688 MLXSW_ITEM32(reg, mogcr, ptp_iftc, 0x00, 1, 1);
10689 
10690 /* reg_mogcr_ptp_eftc
10691  * PTP Egress FIFO Trap Clear
10692  * The PTP_EGR_FIFO trap provides MTPPTR with clr according
10693  * to this value. Default 0.
10694  * Reserved when IB switches and when SwitchX/-2, Spectrum-2
10695  * Access: RW
10696  */
10697 MLXSW_ITEM32(reg, mogcr, ptp_eftc, 0x00, 0, 1);
10698 
10699 /* reg_mogcr_mirroring_pid_base
10700  * Base policer id for mirroring policers.
10701  * Must have an even value (e.g. 1000, not 1001).
10702  * Reserved when SwitchX/-2, Switch-IB/2, Spectrum-1 and Quantum.
10703  * Access: RW
10704  */
10705 MLXSW_ITEM32(reg, mogcr, mirroring_pid_base, 0x0C, 0, 14);
10706 
10707 /* MPAGR - Monitoring Port Analyzer Global Register
10708  * ------------------------------------------------
10709  * This register is used for global port analyzer configurations.
10710  * Note: This register is not supported by current FW versions for Spectrum-1.
10711  */
10712 #define MLXSW_REG_MPAGR_ID 0x9089
10713 #define MLXSW_REG_MPAGR_LEN 0x0C
10714 
10715 MLXSW_REG_DEFINE(mpagr, MLXSW_REG_MPAGR_ID, MLXSW_REG_MPAGR_LEN);
10716 
10717 enum mlxsw_reg_mpagr_trigger {
10718 	MLXSW_REG_MPAGR_TRIGGER_EGRESS,
10719 	MLXSW_REG_MPAGR_TRIGGER_INGRESS,
10720 	MLXSW_REG_MPAGR_TRIGGER_INGRESS_WRED,
10721 	MLXSW_REG_MPAGR_TRIGGER_INGRESS_SHARED_BUFFER,
10722 	MLXSW_REG_MPAGR_TRIGGER_INGRESS_ING_CONG,
10723 	MLXSW_REG_MPAGR_TRIGGER_INGRESS_EGR_CONG,
10724 	MLXSW_REG_MPAGR_TRIGGER_EGRESS_ECN,
10725 	MLXSW_REG_MPAGR_TRIGGER_EGRESS_HIGH_LATENCY,
10726 };
10727 
10728 /* reg_mpagr_trigger
10729  * Mirror trigger.
10730  * Access: Index
10731  */
10732 MLXSW_ITEM32(reg, mpagr, trigger, 0x00, 0, 4);
10733 
10734 /* reg_mpagr_pa_id
10735  * Port analyzer ID.
10736  * Access: RW
10737  */
10738 MLXSW_ITEM32(reg, mpagr, pa_id, 0x04, 0, 4);
10739 
10740 #define MLXSW_REG_MPAGR_RATE_MAX 3500000000UL
10741 
10742 /* reg_mpagr_probability_rate
10743  * Sampling rate.
10744  * Valid values are: 1 to 3.5*10^9
10745  * Value of 1 means "sample all". Default is 1.
10746  * Access: RW
10747  */
10748 MLXSW_ITEM32(reg, mpagr, probability_rate, 0x08, 0, 32);
10749 
10750 static inline void mlxsw_reg_mpagr_pack(char *payload,
10751 					enum mlxsw_reg_mpagr_trigger trigger,
10752 					u8 pa_id, u32 probability_rate)
10753 {
10754 	MLXSW_REG_ZERO(mpagr, payload);
10755 	mlxsw_reg_mpagr_trigger_set(payload, trigger);
10756 	mlxsw_reg_mpagr_pa_id_set(payload, pa_id);
10757 	mlxsw_reg_mpagr_probability_rate_set(payload, probability_rate);
10758 }
10759 
10760 /* MOMTE - Monitoring Mirror Trigger Enable Register
10761  * -------------------------------------------------
10762  * This register is used to configure the mirror enable for different mirror
10763  * reasons.
10764  */
10765 #define MLXSW_REG_MOMTE_ID 0x908D
10766 #define MLXSW_REG_MOMTE_LEN 0x10
10767 
10768 MLXSW_REG_DEFINE(momte, MLXSW_REG_MOMTE_ID, MLXSW_REG_MOMTE_LEN);
10769 
10770 /* reg_momte_local_port
10771  * Local port number.
10772  * Access: Index
10773  */
10774 MLXSW_ITEM32_LP(reg, momte, 0x00, 16, 0x00, 12);
10775 
10776 enum mlxsw_reg_momte_type {
10777 	MLXSW_REG_MOMTE_TYPE_WRED = 0x20,
10778 	MLXSW_REG_MOMTE_TYPE_SHARED_BUFFER_TCLASS = 0x31,
10779 	MLXSW_REG_MOMTE_TYPE_SHARED_BUFFER_TCLASS_DESCRIPTORS = 0x32,
10780 	MLXSW_REG_MOMTE_TYPE_SHARED_BUFFER_EGRESS_PORT = 0x33,
10781 	MLXSW_REG_MOMTE_TYPE_ING_CONG = 0x40,
10782 	MLXSW_REG_MOMTE_TYPE_EGR_CONG = 0x50,
10783 	MLXSW_REG_MOMTE_TYPE_ECN = 0x60,
10784 	MLXSW_REG_MOMTE_TYPE_HIGH_LATENCY = 0x70,
10785 };
10786 
10787 /* reg_momte_type
10788  * Type of mirroring.
10789  * Access: Index
10790  */
10791 MLXSW_ITEM32(reg, momte, type, 0x04, 0, 8);
10792 
10793 /* reg_momte_tclass_en
10794  * TClass/PG mirror enable. Each bit represents corresponding tclass.
10795  * 0: disable (default)
10796  * 1: enable
10797  * Access: RW
10798  */
10799 MLXSW_ITEM_BIT_ARRAY(reg, momte, tclass_en, 0x08, 0x08, 1);
10800 
10801 static inline void mlxsw_reg_momte_pack(char *payload, u16 local_port,
10802 					enum mlxsw_reg_momte_type type)
10803 {
10804 	MLXSW_REG_ZERO(momte, payload);
10805 	mlxsw_reg_momte_local_port_set(payload, local_port);
10806 	mlxsw_reg_momte_type_set(payload, type);
10807 }
10808 
10809 /* MTPPPC - Time Precision Packet Port Configuration
10810  * -------------------------------------------------
10811  * This register serves for configuration of which PTP messages should be
10812  * timestamped. This is a global configuration, despite the register name.
10813  *
10814  * Reserved when Spectrum-2.
10815  */
10816 #define MLXSW_REG_MTPPPC_ID 0x9090
10817 #define MLXSW_REG_MTPPPC_LEN 0x28
10818 
10819 MLXSW_REG_DEFINE(mtpppc, MLXSW_REG_MTPPPC_ID, MLXSW_REG_MTPPPC_LEN);
10820 
10821 /* reg_mtpppc_ing_timestamp_message_type
10822  * Bitwise vector of PTP message types to timestamp at ingress.
10823  * MessageType field as defined by IEEE 1588
10824  * Each bit corresponds to a value (e.g. Bit0: Sync, Bit1: Delay_Req)
10825  * Default all 0
10826  * Access: RW
10827  */
10828 MLXSW_ITEM32(reg, mtpppc, ing_timestamp_message_type, 0x08, 0, 16);
10829 
10830 /* reg_mtpppc_egr_timestamp_message_type
10831  * Bitwise vector of PTP message types to timestamp at egress.
10832  * MessageType field as defined by IEEE 1588
10833  * Each bit corresponds to a value (e.g. Bit0: Sync, Bit1: Delay_Req)
10834  * Default all 0
10835  * Access: RW
10836  */
10837 MLXSW_ITEM32(reg, mtpppc, egr_timestamp_message_type, 0x0C, 0, 16);
10838 
10839 static inline void mlxsw_reg_mtpppc_pack(char *payload, u16 ing, u16 egr)
10840 {
10841 	MLXSW_REG_ZERO(mtpppc, payload);
10842 	mlxsw_reg_mtpppc_ing_timestamp_message_type_set(payload, ing);
10843 	mlxsw_reg_mtpppc_egr_timestamp_message_type_set(payload, egr);
10844 }
10845 
10846 /* MTPPTR - Time Precision Packet Timestamping Reading
10847  * ---------------------------------------------------
10848  * The MTPPTR is used for reading the per port PTP timestamp FIFO.
10849  * There is a trap for packets which are latched to the timestamp FIFO, thus the
10850  * SW knows which FIFO to read. Note that packets enter the FIFO before been
10851  * trapped. The sequence number is used to synchronize the timestamp FIFO
10852  * entries and the trapped packets.
10853  * Reserved when Spectrum-2.
10854  */
10855 
10856 #define MLXSW_REG_MTPPTR_ID 0x9091
10857 #define MLXSW_REG_MTPPTR_BASE_LEN 0x10 /* base length, without records */
10858 #define MLXSW_REG_MTPPTR_REC_LEN 0x10 /* record length */
10859 #define MLXSW_REG_MTPPTR_REC_MAX_COUNT 4
10860 #define MLXSW_REG_MTPPTR_LEN (MLXSW_REG_MTPPTR_BASE_LEN +		\
10861 		    MLXSW_REG_MTPPTR_REC_LEN * MLXSW_REG_MTPPTR_REC_MAX_COUNT)
10862 
10863 MLXSW_REG_DEFINE(mtpptr, MLXSW_REG_MTPPTR_ID, MLXSW_REG_MTPPTR_LEN);
10864 
10865 /* reg_mtpptr_local_port
10866  * Not supported for CPU port.
10867  * Access: Index
10868  */
10869 MLXSW_ITEM32_LP(reg, mtpptr, 0x00, 16, 0x00, 12);
10870 
10871 enum mlxsw_reg_mtpptr_dir {
10872 	MLXSW_REG_MTPPTR_DIR_INGRESS,
10873 	MLXSW_REG_MTPPTR_DIR_EGRESS,
10874 };
10875 
10876 /* reg_mtpptr_dir
10877  * Direction.
10878  * Access: Index
10879  */
10880 MLXSW_ITEM32(reg, mtpptr, dir, 0x00, 0, 1);
10881 
10882 /* reg_mtpptr_clr
10883  * Clear the records.
10884  * Access: OP
10885  */
10886 MLXSW_ITEM32(reg, mtpptr, clr, 0x04, 31, 1);
10887 
10888 /* reg_mtpptr_num_rec
10889  * Number of valid records in the response
10890  * Range 0.. cap_ptp_timestamp_fifo
10891  * Access: RO
10892  */
10893 MLXSW_ITEM32(reg, mtpptr, num_rec, 0x08, 0, 4);
10894 
10895 /* reg_mtpptr_rec_message_type
10896  * MessageType field as defined by IEEE 1588 Each bit corresponds to a value
10897  * (e.g. Bit0: Sync, Bit1: Delay_Req)
10898  * Access: RO
10899  */
10900 MLXSW_ITEM32_INDEXED(reg, mtpptr, rec_message_type,
10901 		     MLXSW_REG_MTPPTR_BASE_LEN, 8, 4,
10902 		     MLXSW_REG_MTPPTR_REC_LEN, 0, false);
10903 
10904 /* reg_mtpptr_rec_domain_number
10905  * DomainNumber field as defined by IEEE 1588
10906  * Access: RO
10907  */
10908 MLXSW_ITEM32_INDEXED(reg, mtpptr, rec_domain_number,
10909 		     MLXSW_REG_MTPPTR_BASE_LEN, 0, 8,
10910 		     MLXSW_REG_MTPPTR_REC_LEN, 0, false);
10911 
10912 /* reg_mtpptr_rec_sequence_id
10913  * SequenceId field as defined by IEEE 1588
10914  * Access: RO
10915  */
10916 MLXSW_ITEM32_INDEXED(reg, mtpptr, rec_sequence_id,
10917 		     MLXSW_REG_MTPPTR_BASE_LEN, 0, 16,
10918 		     MLXSW_REG_MTPPTR_REC_LEN, 0x4, false);
10919 
10920 /* reg_mtpptr_rec_timestamp_high
10921  * Timestamp of when the PTP packet has passed through the port Units of PLL
10922  * clock time.
10923  * For Spectrum-1 the PLL clock is 156.25Mhz and PLL clock time is 6.4nSec.
10924  * Access: RO
10925  */
10926 MLXSW_ITEM32_INDEXED(reg, mtpptr, rec_timestamp_high,
10927 		     MLXSW_REG_MTPPTR_BASE_LEN, 0, 32,
10928 		     MLXSW_REG_MTPPTR_REC_LEN, 0x8, false);
10929 
10930 /* reg_mtpptr_rec_timestamp_low
10931  * See rec_timestamp_high.
10932  * Access: RO
10933  */
10934 MLXSW_ITEM32_INDEXED(reg, mtpptr, rec_timestamp_low,
10935 		     MLXSW_REG_MTPPTR_BASE_LEN, 0, 32,
10936 		     MLXSW_REG_MTPPTR_REC_LEN, 0xC, false);
10937 
10938 static inline void mlxsw_reg_mtpptr_unpack(const char *payload,
10939 					   unsigned int rec,
10940 					   u8 *p_message_type,
10941 					   u8 *p_domain_number,
10942 					   u16 *p_sequence_id,
10943 					   u64 *p_timestamp)
10944 {
10945 	u32 timestamp_high, timestamp_low;
10946 
10947 	*p_message_type = mlxsw_reg_mtpptr_rec_message_type_get(payload, rec);
10948 	*p_domain_number = mlxsw_reg_mtpptr_rec_domain_number_get(payload, rec);
10949 	*p_sequence_id = mlxsw_reg_mtpptr_rec_sequence_id_get(payload, rec);
10950 	timestamp_high = mlxsw_reg_mtpptr_rec_timestamp_high_get(payload, rec);
10951 	timestamp_low = mlxsw_reg_mtpptr_rec_timestamp_low_get(payload, rec);
10952 	*p_timestamp = (u64)timestamp_high << 32 | timestamp_low;
10953 }
10954 
10955 /* MTPTPT - Monitoring Precision Time Protocol Trap Register
10956  * ---------------------------------------------------------
10957  * This register is used for configuring under which trap to deliver PTP
10958  * packets depending on type of the packet.
10959  */
10960 #define MLXSW_REG_MTPTPT_ID 0x9092
10961 #define MLXSW_REG_MTPTPT_LEN 0x08
10962 
10963 MLXSW_REG_DEFINE(mtptpt, MLXSW_REG_MTPTPT_ID, MLXSW_REG_MTPTPT_LEN);
10964 
10965 enum mlxsw_reg_mtptpt_trap_id {
10966 	MLXSW_REG_MTPTPT_TRAP_ID_PTP0,
10967 	MLXSW_REG_MTPTPT_TRAP_ID_PTP1,
10968 };
10969 
10970 /* reg_mtptpt_trap_id
10971  * Trap id.
10972  * Access: Index
10973  */
10974 MLXSW_ITEM32(reg, mtptpt, trap_id, 0x00, 0, 4);
10975 
10976 /* reg_mtptpt_message_type
10977  * Bitwise vector of PTP message types to trap. This is a necessary but
10978  * non-sufficient condition since need to enable also per port. See MTPPPC.
10979  * Message types are defined by IEEE 1588 Each bit corresponds to a value (e.g.
10980  * Bit0: Sync, Bit1: Delay_Req)
10981  */
10982 MLXSW_ITEM32(reg, mtptpt, message_type, 0x04, 0, 16);
10983 
10984 static inline void mlxsw_reg_mtptpt_pack(char *payload,
10985 					 enum mlxsw_reg_mtptpt_trap_id trap_id,
10986 					 u16 message_type)
10987 {
10988 	MLXSW_REG_ZERO(mtptpt, payload);
10989 	mlxsw_reg_mtptpt_trap_id_set(payload, trap_id);
10990 	mlxsw_reg_mtptpt_message_type_set(payload, message_type);
10991 }
10992 
10993 /* MTPCPC - Monitoring Time Precision Correction Port Configuration Register
10994  * -------------------------------------------------------------------------
10995  */
10996 #define MLXSW_REG_MTPCPC_ID 0x9093
10997 #define MLXSW_REG_MTPCPC_LEN 0x2C
10998 
10999 MLXSW_REG_DEFINE(mtpcpc, MLXSW_REG_MTPCPC_ID, MLXSW_REG_MTPCPC_LEN);
11000 
11001 /* reg_mtpcpc_pport
11002  * Per port:
11003  * 0: config is global. When reading - the local_port is 1.
11004  * 1: config is per port.
11005  * Access: Index
11006  */
11007 MLXSW_ITEM32(reg, mtpcpc, pport, 0x00, 31, 1);
11008 
11009 /* reg_mtpcpc_local_port
11010  * Local port number.
11011  * Supported to/from CPU port.
11012  * Reserved when pport = 0.
11013  * Access: Index
11014  */
11015 MLXSW_ITEM32_LP(reg, mtpcpc, 0x00, 16, 0x00, 12);
11016 
11017 /* reg_mtpcpc_ptp_trap_en
11018  * Enable PTP traps.
11019  * The trap_id is configured by MTPTPT.
11020  * Access: RW
11021  */
11022 MLXSW_ITEM32(reg, mtpcpc, ptp_trap_en, 0x04, 0, 1);
11023 
11024 /* reg_mtpcpc_ing_correction_message_type
11025  * Bitwise vector of PTP message types to update correction-field at ingress.
11026  * MessageType field as defined by IEEE 1588 Each bit corresponds to a value
11027  * (e.g. Bit0: Sync, Bit1: Delay_Req). Supported also from CPU port.
11028  * Default all 0
11029  * Access: RW
11030  */
11031 MLXSW_ITEM32(reg, mtpcpc, ing_correction_message_type, 0x10, 0, 16);
11032 
11033 /* reg_mtpcpc_egr_correction_message_type
11034  * Bitwise vector of PTP message types to update correction-field at egress.
11035  * MessageType field as defined by IEEE 1588 Each bit corresponds to a value
11036  * (e.g. Bit0: Sync, Bit1: Delay_Req). Supported also from CPU port.
11037  * Default all 0
11038  * Access: RW
11039  */
11040 MLXSW_ITEM32(reg, mtpcpc, egr_correction_message_type, 0x14, 0, 16);
11041 
11042 static inline void mlxsw_reg_mtpcpc_pack(char *payload, bool pport,
11043 					 u16 local_port, bool ptp_trap_en,
11044 					 u16 ing, u16 egr)
11045 {
11046 	MLXSW_REG_ZERO(mtpcpc, payload);
11047 	mlxsw_reg_mtpcpc_pport_set(payload, pport);
11048 	mlxsw_reg_mtpcpc_local_port_set(payload, pport ? local_port : 0);
11049 	mlxsw_reg_mtpcpc_ptp_trap_en_set(payload, ptp_trap_en);
11050 	mlxsw_reg_mtpcpc_ing_correction_message_type_set(payload, ing);
11051 	mlxsw_reg_mtpcpc_egr_correction_message_type_set(payload, egr);
11052 }
11053 
11054 /* MFGD - Monitoring FW General Debug Register
11055  * -------------------------------------------
11056  */
11057 #define MLXSW_REG_MFGD_ID 0x90F0
11058 #define MLXSW_REG_MFGD_LEN 0x0C
11059 
11060 MLXSW_REG_DEFINE(mfgd, MLXSW_REG_MFGD_ID, MLXSW_REG_MFGD_LEN);
11061 
11062 /* reg_mfgd_fw_fatal_event_mode
11063  * 0 - don't check FW fatal (default)
11064  * 1 - check FW fatal - enable MFDE trap
11065  * Access: RW
11066  */
11067 MLXSW_ITEM32(reg, mfgd, fatal_event_mode, 0x00, 9, 2);
11068 
11069 /* reg_mfgd_trigger_test
11070  * Access: WO
11071  */
11072 MLXSW_ITEM32(reg, mfgd, trigger_test, 0x00, 11, 1);
11073 
11074 /* MGPIR - Management General Peripheral Information Register
11075  * ----------------------------------------------------------
11076  * MGPIR register allows software to query the hardware and
11077  * firmware general information of peripheral entities.
11078  */
11079 #define MLXSW_REG_MGPIR_ID 0x9100
11080 #define MLXSW_REG_MGPIR_LEN 0xA0
11081 
11082 MLXSW_REG_DEFINE(mgpir, MLXSW_REG_MGPIR_ID, MLXSW_REG_MGPIR_LEN);
11083 
11084 enum mlxsw_reg_mgpir_device_type {
11085 	MLXSW_REG_MGPIR_DEVICE_TYPE_NONE,
11086 	MLXSW_REG_MGPIR_DEVICE_TYPE_GEARBOX_DIE,
11087 };
11088 
11089 /* mgpir_slot_index
11090  * Slot index (0: Main board).
11091  * Access: Index
11092  */
11093 MLXSW_ITEM32(reg, mgpir, slot_index, 0x00, 28, 4);
11094 
11095 /* mgpir_device_type
11096  * Access: RO
11097  */
11098 MLXSW_ITEM32(reg, mgpir, device_type, 0x00, 24, 4);
11099 
11100 /* mgpir_devices_per_flash
11101  * Number of devices of device_type per flash (can be shared by few devices).
11102  * Access: RO
11103  */
11104 MLXSW_ITEM32(reg, mgpir, devices_per_flash, 0x00, 16, 8);
11105 
11106 /* mgpir_num_of_devices
11107  * Number of devices of device_type.
11108  * Access: RO
11109  */
11110 MLXSW_ITEM32(reg, mgpir, num_of_devices, 0x00, 0, 8);
11111 
11112 /* max_modules_per_slot
11113  * Maximum number of modules that can be connected per slot.
11114  * Access: RO
11115  */
11116 MLXSW_ITEM32(reg, mgpir, max_modules_per_slot, 0x04, 16, 8);
11117 
11118 /* mgpir_num_of_slots
11119  * Number of slots in the system.
11120  * Access: RO
11121  */
11122 MLXSW_ITEM32(reg, mgpir, num_of_slots, 0x04, 8, 8);
11123 
11124 /* mgpir_num_of_modules
11125  * Number of modules.
11126  * Access: RO
11127  */
11128 MLXSW_ITEM32(reg, mgpir, num_of_modules, 0x04, 0, 8);
11129 
11130 static inline void mlxsw_reg_mgpir_pack(char *payload, u8 slot_index)
11131 {
11132 	MLXSW_REG_ZERO(mgpir, payload);
11133 	mlxsw_reg_mgpir_slot_index_set(payload, slot_index);
11134 }
11135 
11136 static inline void
11137 mlxsw_reg_mgpir_unpack(char *payload, u8 *num_of_devices,
11138 		       enum mlxsw_reg_mgpir_device_type *device_type,
11139 		       u8 *devices_per_flash, u8 *num_of_modules,
11140 		       u8 *num_of_slots)
11141 {
11142 	if (num_of_devices)
11143 		*num_of_devices = mlxsw_reg_mgpir_num_of_devices_get(payload);
11144 	if (device_type)
11145 		*device_type = mlxsw_reg_mgpir_device_type_get(payload);
11146 	if (devices_per_flash)
11147 		*devices_per_flash =
11148 				mlxsw_reg_mgpir_devices_per_flash_get(payload);
11149 	if (num_of_modules)
11150 		*num_of_modules = mlxsw_reg_mgpir_num_of_modules_get(payload);
11151 	if (num_of_slots)
11152 		*num_of_slots = mlxsw_reg_mgpir_num_of_slots_get(payload);
11153 }
11154 
11155 /* MBCT - Management Binary Code Transfer Register
11156  * -----------------------------------------------
11157  * This register allows to transfer binary codes from the host to
11158  * the management FW by transferring it by chunks of maximum 1KB.
11159  */
11160 #define MLXSW_REG_MBCT_ID 0x9120
11161 #define MLXSW_REG_MBCT_LEN 0x420
11162 
11163 MLXSW_REG_DEFINE(mbct, MLXSW_REG_MBCT_ID, MLXSW_REG_MBCT_LEN);
11164 
11165 /* reg_mbct_slot_index
11166  * Slot index. 0 is reserved.
11167  * Access: Index
11168  */
11169 MLXSW_ITEM32(reg, mbct, slot_index, 0x00, 0, 4);
11170 
11171 /* reg_mbct_data_size
11172  * Actual data field size in bytes for the current data transfer.
11173  * Access: WO
11174  */
11175 MLXSW_ITEM32(reg, mbct, data_size, 0x04, 0, 11);
11176 
11177 enum mlxsw_reg_mbct_op {
11178 	MLXSW_REG_MBCT_OP_ERASE_INI_IMAGE = 1,
11179 	MLXSW_REG_MBCT_OP_DATA_TRANSFER, /* Download */
11180 	MLXSW_REG_MBCT_OP_ACTIVATE,
11181 	MLXSW_REG_MBCT_OP_CLEAR_ERRORS = 6,
11182 	MLXSW_REG_MBCT_OP_QUERY_STATUS,
11183 };
11184 
11185 /* reg_mbct_op
11186  * Access: WO
11187  */
11188 MLXSW_ITEM32(reg, mbct, op, 0x08, 28, 4);
11189 
11190 /* reg_mbct_last
11191  * Indicates that the current data field is the last chunk of the INI.
11192  * Access: WO
11193  */
11194 MLXSW_ITEM32(reg, mbct, last, 0x08, 26, 1);
11195 
11196 /* reg_mbct_oee
11197  * Opcode Event Enable. When set a BCTOE event will be sent once the opcode
11198  * was executed and the fsm_state has changed.
11199  * Access: WO
11200  */
11201 MLXSW_ITEM32(reg, mbct, oee, 0x08, 25, 1);
11202 
11203 enum mlxsw_reg_mbct_status {
11204 	/* Partial data transfer completed successfully and ready for next
11205 	 * data transfer.
11206 	 */
11207 	MLXSW_REG_MBCT_STATUS_PART_DATA = 2,
11208 	MLXSW_REG_MBCT_STATUS_LAST_DATA,
11209 	MLXSW_REG_MBCT_STATUS_ERASE_COMPLETE,
11210 	/* Error - trying to erase INI while it being used. */
11211 	MLXSW_REG_MBCT_STATUS_ERROR_INI_IN_USE,
11212 	/* Last data transfer completed, applying magic pattern. */
11213 	MLXSW_REG_MBCT_STATUS_ERASE_FAILED = 7,
11214 	MLXSW_REG_MBCT_STATUS_INI_ERROR,
11215 	MLXSW_REG_MBCT_STATUS_ACTIVATION_FAILED,
11216 	MLXSW_REG_MBCT_STATUS_ILLEGAL_OPERATION = 11,
11217 };
11218 
11219 /* reg_mbct_status
11220  * Status.
11221  * Access: RO
11222  */
11223 MLXSW_ITEM32(reg, mbct, status, 0x0C, 24, 5);
11224 
11225 enum mlxsw_reg_mbct_fsm_state {
11226 	MLXSW_REG_MBCT_FSM_STATE_INI_IN_USE = 5,
11227 	MLXSW_REG_MBCT_FSM_STATE_ERROR,
11228 };
11229 
11230 /* reg_mbct_fsm_state
11231  * FSM state.
11232  * Access: RO
11233  */
11234 MLXSW_ITEM32(reg, mbct, fsm_state,  0x0C, 16, 4);
11235 
11236 #define MLXSW_REG_MBCT_DATA_LEN 1024
11237 
11238 /* reg_mbct_data
11239  * Up to 1KB of data.
11240  * Access: WO
11241  */
11242 MLXSW_ITEM_BUF(reg, mbct, data, 0x20, MLXSW_REG_MBCT_DATA_LEN);
11243 
11244 static inline void mlxsw_reg_mbct_pack(char *payload, u8 slot_index,
11245 				       enum mlxsw_reg_mbct_op op, bool oee)
11246 {
11247 	MLXSW_REG_ZERO(mbct, payload);
11248 	mlxsw_reg_mbct_slot_index_set(payload, slot_index);
11249 	mlxsw_reg_mbct_op_set(payload, op);
11250 	mlxsw_reg_mbct_oee_set(payload, oee);
11251 }
11252 
11253 static inline void mlxsw_reg_mbct_dt_pack(char *payload,
11254 					  u16 data_size, bool last,
11255 					  const char *data)
11256 {
11257 	if (WARN_ON(data_size > MLXSW_REG_MBCT_DATA_LEN))
11258 		return;
11259 	mlxsw_reg_mbct_data_size_set(payload, data_size);
11260 	mlxsw_reg_mbct_last_set(payload, last);
11261 	mlxsw_reg_mbct_data_memcpy_to(payload, data);
11262 }
11263 
11264 static inline void
11265 mlxsw_reg_mbct_unpack(const char *payload, u8 *p_slot_index,
11266 		      enum mlxsw_reg_mbct_status *p_status,
11267 		      enum mlxsw_reg_mbct_fsm_state *p_fsm_state)
11268 {
11269 	if (p_slot_index)
11270 		*p_slot_index = mlxsw_reg_mbct_slot_index_get(payload);
11271 	*p_status = mlxsw_reg_mbct_status_get(payload);
11272 	if (p_fsm_state)
11273 		*p_fsm_state = mlxsw_reg_mbct_fsm_state_get(payload);
11274 }
11275 
11276 /* MDDT - Management DownStream Device Tunneling Register
11277  * ------------------------------------------------------
11278  * This register allows to deliver query and request messages (PRM registers,
11279  * commands) to a DownStream device.
11280  */
11281 #define MLXSW_REG_MDDT_ID 0x9160
11282 #define MLXSW_REG_MDDT_LEN 0x110
11283 
11284 MLXSW_REG_DEFINE(mddt, MLXSW_REG_MDDT_ID, MLXSW_REG_MDDT_LEN);
11285 
11286 /* reg_mddt_slot_index
11287  * Slot index.
11288  * Access: Index
11289  */
11290 MLXSW_ITEM32(reg, mddt, slot_index, 0x00, 8, 4);
11291 
11292 /* reg_mddt_device_index
11293  * Device index.
11294  * Access: Index
11295  */
11296 MLXSW_ITEM32(reg, mddt, device_index, 0x00, 0, 8);
11297 
11298 /* reg_mddt_read_size
11299  * Read size in D-Words.
11300  * Access: OP
11301  */
11302 MLXSW_ITEM32(reg, mddt, read_size, 0x04, 24, 8);
11303 
11304 /* reg_mddt_write_size
11305  * Write size in D-Words.
11306  * Access: OP
11307  */
11308 MLXSW_ITEM32(reg, mddt, write_size, 0x04, 16, 8);
11309 
11310 enum mlxsw_reg_mddt_status {
11311 	MLXSW_REG_MDDT_STATUS_OK,
11312 };
11313 
11314 /* reg_mddt_status
11315  * Return code of the Downstream Device to the register that was sent.
11316  * Access: RO
11317  */
11318 MLXSW_ITEM32(reg, mddt, status, 0x0C, 24, 8);
11319 
11320 enum mlxsw_reg_mddt_method {
11321 	MLXSW_REG_MDDT_METHOD_QUERY,
11322 	MLXSW_REG_MDDT_METHOD_WRITE,
11323 };
11324 
11325 /* reg_mddt_method
11326  * Access: OP
11327  */
11328 MLXSW_ITEM32(reg, mddt, method, 0x0C, 22, 2);
11329 
11330 /* reg_mddt_register_id
11331  * Access: Index
11332  */
11333 MLXSW_ITEM32(reg, mddt, register_id, 0x0C, 0, 16);
11334 
11335 #define MLXSW_REG_MDDT_PAYLOAD_OFFSET 0x0C
11336 #define MLXSW_REG_MDDT_PRM_REGISTER_HEADER_LEN 4
11337 
11338 static inline char *mlxsw_reg_mddt_inner_payload(char *payload)
11339 {
11340 	return payload + MLXSW_REG_MDDT_PAYLOAD_OFFSET +
11341 	       MLXSW_REG_MDDT_PRM_REGISTER_HEADER_LEN;
11342 }
11343 
11344 static inline void mlxsw_reg_mddt_pack(char *payload, u8 slot_index,
11345 				       u8 device_index,
11346 				       enum mlxsw_reg_mddt_method method,
11347 				       const struct mlxsw_reg_info *reg,
11348 				       char **inner_payload)
11349 {
11350 	int len = reg->len + MLXSW_REG_MDDT_PRM_REGISTER_HEADER_LEN;
11351 
11352 	if (WARN_ON(len + MLXSW_REG_MDDT_PAYLOAD_OFFSET > MLXSW_REG_MDDT_LEN))
11353 		len = MLXSW_REG_MDDT_LEN - MLXSW_REG_MDDT_PAYLOAD_OFFSET;
11354 
11355 	MLXSW_REG_ZERO(mddt, payload);
11356 	mlxsw_reg_mddt_slot_index_set(payload, slot_index);
11357 	mlxsw_reg_mddt_device_index_set(payload, device_index);
11358 	mlxsw_reg_mddt_method_set(payload, method);
11359 	mlxsw_reg_mddt_register_id_set(payload, reg->id);
11360 	mlxsw_reg_mddt_read_size_set(payload, len / 4);
11361 	mlxsw_reg_mddt_write_size_set(payload, len / 4);
11362 	*inner_payload = mlxsw_reg_mddt_inner_payload(payload);
11363 }
11364 
11365 /* MDDQ - Management DownStream Device Query Register
11366  * --------------------------------------------------
11367  * This register allows to query the DownStream device properties. The desired
11368  * information is chosen upon the query_type field and is delivered by 32B
11369  * of data blocks.
11370  */
11371 #define MLXSW_REG_MDDQ_ID 0x9161
11372 #define MLXSW_REG_MDDQ_LEN 0x30
11373 
11374 MLXSW_REG_DEFINE(mddq, MLXSW_REG_MDDQ_ID, MLXSW_REG_MDDQ_LEN);
11375 
11376 /* reg_mddq_sie
11377  * Slot info event enable.
11378  * When set to '1', each change in the slot_info.provisioned / sr_valid /
11379  * active / ready will generate a DSDSC event.
11380  * Access: RW
11381  */
11382 MLXSW_ITEM32(reg, mddq, sie, 0x00, 31, 1);
11383 
11384 enum mlxsw_reg_mddq_query_type {
11385 	MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_INFO = 1,
11386 	MLXSW_REG_MDDQ_QUERY_TYPE_DEVICE_INFO, /* If there are no devices
11387 						* on the slot, data_valid
11388 						* will be '0'.
11389 						*/
11390 	MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_NAME,
11391 };
11392 
11393 /* reg_mddq_query_type
11394  * Access: Index
11395  */
11396 MLXSW_ITEM32(reg, mddq, query_type, 0x00, 16, 8);
11397 
11398 /* reg_mddq_slot_index
11399  * Slot index. 0 is reserved.
11400  * Access: Index
11401  */
11402 MLXSW_ITEM32(reg, mddq, slot_index, 0x00, 0, 4);
11403 
11404 /* reg_mddq_response_msg_seq
11405  * Response message sequential number. For a specific request, the response
11406  * message sequential number is the following one. In addition, the last
11407  * message should be 0.
11408  * Access: RO
11409  */
11410 MLXSW_ITEM32(reg, mddq, response_msg_seq, 0x04, 16, 8);
11411 
11412 /* reg_mddq_request_msg_seq
11413  * Request message sequential number.
11414  * The first message number should be 0.
11415  * Access: Index
11416  */
11417 MLXSW_ITEM32(reg, mddq, request_msg_seq, 0x04, 0, 8);
11418 
11419 /* reg_mddq_data_valid
11420  * If set, the data in the data field is valid and contain the information
11421  * for the queried index.
11422  * Access: RO
11423  */
11424 MLXSW_ITEM32(reg, mddq, data_valid, 0x08, 31, 1);
11425 
11426 /* reg_mddq_slot_info_provisioned
11427  * If set, the INI file is applied and the card is provisioned.
11428  * Access: RO
11429  */
11430 MLXSW_ITEM32(reg, mddq, slot_info_provisioned, 0x10, 31, 1);
11431 
11432 /* reg_mddq_slot_info_sr_valid
11433  * If set, Shift Register is valid (after being provisioned) and data
11434  * can be sent from the switch ASIC to the line-card CPLD over Shift-Register.
11435  * Access: RO
11436  */
11437 MLXSW_ITEM32(reg, mddq, slot_info_sr_valid, 0x10, 30, 1);
11438 
11439 enum mlxsw_reg_mddq_slot_info_ready {
11440 	MLXSW_REG_MDDQ_SLOT_INFO_READY_NOT_READY,
11441 	MLXSW_REG_MDDQ_SLOT_INFO_READY_READY,
11442 	MLXSW_REG_MDDQ_SLOT_INFO_READY_ERROR,
11443 };
11444 
11445 /* reg_mddq_slot_info_lc_ready
11446  * If set, the LC is powered on, matching the INI version and a new FW
11447  * version can be burnt (if necessary).
11448  * Access: RO
11449  */
11450 MLXSW_ITEM32(reg, mddq, slot_info_lc_ready, 0x10, 28, 2);
11451 
11452 /* reg_mddq_slot_info_active
11453  * If set, the FW has completed the MDDC.device_enable command.
11454  * Access: RO
11455  */
11456 MLXSW_ITEM32(reg, mddq, slot_info_active, 0x10, 27, 1);
11457 
11458 /* reg_mddq_slot_info_hw_revision
11459  * Major user-configured version number of the current INI file.
11460  * Valid only when active or ready are '1'.
11461  * Access: RO
11462  */
11463 MLXSW_ITEM32(reg, mddq, slot_info_hw_revision, 0x14, 16, 16);
11464 
11465 /* reg_mddq_slot_info_ini_file_version
11466  * User-configured version number of the current INI file.
11467  * Valid only when active or lc_ready are '1'.
11468  * Access: RO
11469  */
11470 MLXSW_ITEM32(reg, mddq, slot_info_ini_file_version, 0x14, 0, 16);
11471 
11472 /* reg_mddq_slot_info_card_type
11473  * Access: RO
11474  */
11475 MLXSW_ITEM32(reg, mddq, slot_info_card_type, 0x18, 0, 8);
11476 
11477 static inline void
11478 __mlxsw_reg_mddq_pack(char *payload, u8 slot_index,
11479 		      enum mlxsw_reg_mddq_query_type query_type)
11480 {
11481 	MLXSW_REG_ZERO(mddq, payload);
11482 	mlxsw_reg_mddq_slot_index_set(payload, slot_index);
11483 	mlxsw_reg_mddq_query_type_set(payload, query_type);
11484 }
11485 
11486 static inline void
11487 mlxsw_reg_mddq_slot_info_pack(char *payload, u8 slot_index, bool sie)
11488 {
11489 	__mlxsw_reg_mddq_pack(payload, slot_index,
11490 			      MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_INFO);
11491 	mlxsw_reg_mddq_sie_set(payload, sie);
11492 }
11493 
11494 static inline void
11495 mlxsw_reg_mddq_slot_info_unpack(const char *payload, u8 *p_slot_index,
11496 				bool *p_provisioned, bool *p_sr_valid,
11497 				enum mlxsw_reg_mddq_slot_info_ready *p_lc_ready,
11498 				bool *p_active, u16 *p_hw_revision,
11499 				u16 *p_ini_file_version,
11500 				u8 *p_card_type)
11501 {
11502 	*p_slot_index = mlxsw_reg_mddq_slot_index_get(payload);
11503 	*p_provisioned = mlxsw_reg_mddq_slot_info_provisioned_get(payload);
11504 	*p_sr_valid = mlxsw_reg_mddq_slot_info_sr_valid_get(payload);
11505 	*p_lc_ready = mlxsw_reg_mddq_slot_info_lc_ready_get(payload);
11506 	*p_active = mlxsw_reg_mddq_slot_info_active_get(payload);
11507 	*p_hw_revision = mlxsw_reg_mddq_slot_info_hw_revision_get(payload);
11508 	*p_ini_file_version = mlxsw_reg_mddq_slot_info_ini_file_version_get(payload);
11509 	*p_card_type = mlxsw_reg_mddq_slot_info_card_type_get(payload);
11510 }
11511 
11512 /* reg_mddq_device_info_flash_owner
11513  * If set, the device is the flash owner. Otherwise, a shared flash
11514  * is used by this device (another device is the flash owner).
11515  * Access: RO
11516  */
11517 MLXSW_ITEM32(reg, mddq, device_info_flash_owner, 0x10, 30, 1);
11518 
11519 /* reg_mddq_device_info_device_index
11520  * Device index. The first device should number 0.
11521  * Access: RO
11522  */
11523 MLXSW_ITEM32(reg, mddq, device_info_device_index, 0x10, 0, 8);
11524 
11525 /* reg_mddq_device_info_fw_major
11526  * Major FW version number.
11527  * Access: RO
11528  */
11529 MLXSW_ITEM32(reg, mddq, device_info_fw_major, 0x14, 16, 16);
11530 
11531 /* reg_mddq_device_info_fw_minor
11532  * Minor FW version number.
11533  * Access: RO
11534  */
11535 MLXSW_ITEM32(reg, mddq, device_info_fw_minor, 0x18, 16, 16);
11536 
11537 /* reg_mddq_device_info_fw_sub_minor
11538  * Sub-minor FW version number.
11539  * Access: RO
11540  */
11541 MLXSW_ITEM32(reg, mddq, device_info_fw_sub_minor, 0x18, 0, 16);
11542 
11543 static inline void
11544 mlxsw_reg_mddq_device_info_pack(char *payload, u8 slot_index,
11545 				u8 request_msg_seq)
11546 {
11547 	__mlxsw_reg_mddq_pack(payload, slot_index,
11548 			      MLXSW_REG_MDDQ_QUERY_TYPE_DEVICE_INFO);
11549 	mlxsw_reg_mddq_request_msg_seq_set(payload, request_msg_seq);
11550 }
11551 
11552 static inline void
11553 mlxsw_reg_mddq_device_info_unpack(const char *payload, u8 *p_response_msg_seq,
11554 				  bool *p_data_valid, bool *p_flash_owner,
11555 				  u8 *p_device_index, u16 *p_fw_major,
11556 				  u16 *p_fw_minor, u16 *p_fw_sub_minor)
11557 {
11558 	*p_response_msg_seq = mlxsw_reg_mddq_response_msg_seq_get(payload);
11559 	*p_data_valid = mlxsw_reg_mddq_data_valid_get(payload);
11560 	*p_flash_owner = mlxsw_reg_mddq_device_info_flash_owner_get(payload);
11561 	*p_device_index = mlxsw_reg_mddq_device_info_device_index_get(payload);
11562 	*p_fw_major = mlxsw_reg_mddq_device_info_fw_major_get(payload);
11563 	*p_fw_minor = mlxsw_reg_mddq_device_info_fw_minor_get(payload);
11564 	*p_fw_sub_minor = mlxsw_reg_mddq_device_info_fw_sub_minor_get(payload);
11565 }
11566 
11567 #define MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN 20
11568 
11569 /* reg_mddq_slot_ascii_name
11570  * Slot's ASCII name.
11571  * Access: RO
11572  */
11573 MLXSW_ITEM_BUF(reg, mddq, slot_ascii_name, 0x10,
11574 	       MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN);
11575 
11576 static inline void
11577 mlxsw_reg_mddq_slot_name_pack(char *payload, u8 slot_index)
11578 {
11579 	__mlxsw_reg_mddq_pack(payload, slot_index,
11580 			      MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_NAME);
11581 }
11582 
11583 static inline void
11584 mlxsw_reg_mddq_slot_name_unpack(const char *payload, char *slot_ascii_name)
11585 {
11586 	mlxsw_reg_mddq_slot_ascii_name_memcpy_from(payload, slot_ascii_name);
11587 }
11588 
11589 /* MDDC - Management DownStream Device Control Register
11590  * ----------------------------------------------------
11591  * This register allows to control downstream devices and line cards.
11592  */
11593 #define MLXSW_REG_MDDC_ID 0x9163
11594 #define MLXSW_REG_MDDC_LEN 0x30
11595 
11596 MLXSW_REG_DEFINE(mddc, MLXSW_REG_MDDC_ID, MLXSW_REG_MDDC_LEN);
11597 
11598 /* reg_mddc_slot_index
11599  * Slot index. 0 is reserved.
11600  * Access: Index
11601  */
11602 MLXSW_ITEM32(reg, mddc, slot_index, 0x00, 0, 4);
11603 
11604 /* reg_mddc_rst
11605  * Reset request.
11606  * Access: OP
11607  */
11608 MLXSW_ITEM32(reg, mddc, rst, 0x04, 29, 1);
11609 
11610 /* reg_mddc_device_enable
11611  * When set, FW is the manager and allowed to program the downstream device.
11612  * Access: RW
11613  */
11614 MLXSW_ITEM32(reg, mddc, device_enable, 0x04, 28, 1);
11615 
11616 static inline void mlxsw_reg_mddc_pack(char *payload, u8 slot_index, bool rst,
11617 				       bool device_enable)
11618 {
11619 	MLXSW_REG_ZERO(mddc, payload);
11620 	mlxsw_reg_mddc_slot_index_set(payload, slot_index);
11621 	mlxsw_reg_mddc_rst_set(payload, rst);
11622 	mlxsw_reg_mddc_device_enable_set(payload, device_enable);
11623 }
11624 
11625 /* MFDE - Monitoring FW Debug Register
11626  * -----------------------------------
11627  */
11628 #define MLXSW_REG_MFDE_ID 0x9200
11629 #define MLXSW_REG_MFDE_LEN 0x30
11630 
11631 MLXSW_REG_DEFINE(mfde, MLXSW_REG_MFDE_ID, MLXSW_REG_MFDE_LEN);
11632 
11633 /* reg_mfde_irisc_id
11634  * Which irisc triggered the event
11635  * Access: RO
11636  */
11637 MLXSW_ITEM32(reg, mfde, irisc_id, 0x00, 24, 8);
11638 
11639 enum mlxsw_reg_mfde_severity {
11640 	/* Unrecoverable switch behavior */
11641 	MLXSW_REG_MFDE_SEVERITY_FATL = 2,
11642 	/* Unexpected state with possible systemic failure */
11643 	MLXSW_REG_MFDE_SEVERITY_NRML = 3,
11644 	/* Unexpected state without systemic failure */
11645 	MLXSW_REG_MFDE_SEVERITY_INTR = 5,
11646 };
11647 
11648 /* reg_mfde_severity
11649  * The severity of the event.
11650  * Access: RO
11651  */
11652 MLXSW_ITEM32(reg, mfde, severity, 0x00, 16, 8);
11653 
11654 enum mlxsw_reg_mfde_event_id {
11655 	/* CRspace timeout */
11656 	MLXSW_REG_MFDE_EVENT_ID_CRSPACE_TO = 1,
11657 	/* KVD insertion machine stopped */
11658 	MLXSW_REG_MFDE_EVENT_ID_KVD_IM_STOP,
11659 	/* Triggered by MFGD.trigger_test */
11660 	MLXSW_REG_MFDE_EVENT_ID_TEST,
11661 	/* Triggered when firmware hits an assert */
11662 	MLXSW_REG_MFDE_EVENT_ID_FW_ASSERT,
11663 	/* Fatal error interrupt from hardware */
11664 	MLXSW_REG_MFDE_EVENT_ID_FATAL_CAUSE,
11665 };
11666 
11667 /* reg_mfde_event_id
11668  * Access: RO
11669  */
11670 MLXSW_ITEM32(reg, mfde, event_id, 0x00, 0, 16);
11671 
11672 enum mlxsw_reg_mfde_method {
11673 	MLXSW_REG_MFDE_METHOD_QUERY,
11674 	MLXSW_REG_MFDE_METHOD_WRITE,
11675 };
11676 
11677 /* reg_mfde_method
11678  * Access: RO
11679  */
11680 MLXSW_ITEM32(reg, mfde, method, 0x04, 29, 1);
11681 
11682 /* reg_mfde_long_process
11683  * Indicates if the command is in long_process mode.
11684  * Access: RO
11685  */
11686 MLXSW_ITEM32(reg, mfde, long_process, 0x04, 28, 1);
11687 
11688 enum mlxsw_reg_mfde_command_type {
11689 	MLXSW_REG_MFDE_COMMAND_TYPE_MAD,
11690 	MLXSW_REG_MFDE_COMMAND_TYPE_EMAD,
11691 	MLXSW_REG_MFDE_COMMAND_TYPE_CMDIF,
11692 };
11693 
11694 /* reg_mfde_command_type
11695  * Access: RO
11696  */
11697 MLXSW_ITEM32(reg, mfde, command_type, 0x04, 24, 2);
11698 
11699 /* reg_mfde_reg_attr_id
11700  * EMAD - register id, MAD - attibute id
11701  * Access: RO
11702  */
11703 MLXSW_ITEM32(reg, mfde, reg_attr_id, 0x04, 0, 16);
11704 
11705 /* reg_mfde_crspace_to_log_address
11706  * crspace address accessed, which resulted in timeout.
11707  * Access: RO
11708  */
11709 MLXSW_ITEM32(reg, mfde, crspace_to_log_address, 0x10, 0, 32);
11710 
11711 /* reg_mfde_crspace_to_oe
11712  * 0 - New event
11713  * 1 - Old event, occurred before MFGD activation.
11714  * Access: RO
11715  */
11716 MLXSW_ITEM32(reg, mfde, crspace_to_oe, 0x14, 24, 1);
11717 
11718 /* reg_mfde_crspace_to_log_id
11719  * Which irisc triggered the timeout.
11720  * Access: RO
11721  */
11722 MLXSW_ITEM32(reg, mfde, crspace_to_log_id, 0x14, 0, 4);
11723 
11724 /* reg_mfde_crspace_to_log_ip
11725  * IP (instruction pointer) that triggered the timeout.
11726  * Access: RO
11727  */
11728 MLXSW_ITEM64(reg, mfde, crspace_to_log_ip, 0x18, 0, 64);
11729 
11730 /* reg_mfde_kvd_im_stop_oe
11731  * 0 - New event
11732  * 1 - Old event, occurred before MFGD activation.
11733  * Access: RO
11734  */
11735 MLXSW_ITEM32(reg, mfde, kvd_im_stop_oe, 0x10, 24, 1);
11736 
11737 /* reg_mfde_kvd_im_stop_pipes_mask
11738  * Bit per kvh pipe.
11739  * Access: RO
11740  */
11741 MLXSW_ITEM32(reg, mfde, kvd_im_stop_pipes_mask, 0x10, 0, 16);
11742 
11743 /* reg_mfde_fw_assert_var0-4
11744  * Variables passed to assert.
11745  * Access: RO
11746  */
11747 MLXSW_ITEM32(reg, mfde, fw_assert_var0, 0x10, 0, 32);
11748 MLXSW_ITEM32(reg, mfde, fw_assert_var1, 0x14, 0, 32);
11749 MLXSW_ITEM32(reg, mfde, fw_assert_var2, 0x18, 0, 32);
11750 MLXSW_ITEM32(reg, mfde, fw_assert_var3, 0x1C, 0, 32);
11751 MLXSW_ITEM32(reg, mfde, fw_assert_var4, 0x20, 0, 32);
11752 
11753 /* reg_mfde_fw_assert_existptr
11754  * The instruction pointer when assert was triggered.
11755  * Access: RO
11756  */
11757 MLXSW_ITEM32(reg, mfde, fw_assert_existptr, 0x24, 0, 32);
11758 
11759 /* reg_mfde_fw_assert_callra
11760  * The return address after triggering assert.
11761  * Access: RO
11762  */
11763 MLXSW_ITEM32(reg, mfde, fw_assert_callra, 0x28, 0, 32);
11764 
11765 /* reg_mfde_fw_assert_oe
11766  * 0 - New event
11767  * 1 - Old event, occurred before MFGD activation.
11768  * Access: RO
11769  */
11770 MLXSW_ITEM32(reg, mfde, fw_assert_oe, 0x2C, 24, 1);
11771 
11772 /* reg_mfde_fw_assert_tile_v
11773  * 0: The assert was from main
11774  * 1: The assert was from a tile
11775  * Access: RO
11776  */
11777 MLXSW_ITEM32(reg, mfde, fw_assert_tile_v, 0x2C, 23, 1);
11778 
11779 /* reg_mfde_fw_assert_tile_index
11780  * When tile_v=1, the tile_index that caused the assert.
11781  * Access: RO
11782  */
11783 MLXSW_ITEM32(reg, mfde, fw_assert_tile_index, 0x2C, 16, 6);
11784 
11785 /* reg_mfde_fw_assert_ext_synd
11786  * A generated one-to-one identifier which is specific per-assert.
11787  * Access: RO
11788  */
11789 MLXSW_ITEM32(reg, mfde, fw_assert_ext_synd, 0x2C, 0, 16);
11790 
11791 /* reg_mfde_fatal_cause_id
11792  * HW interrupt cause id.
11793  * Access: RO
11794  */
11795 MLXSW_ITEM32(reg, mfde, fatal_cause_id, 0x10, 0, 18);
11796 
11797 /* reg_mfde_fatal_cause_tile_v
11798  * 0: The assert was from main
11799  * 1: The assert was from a tile
11800  * Access: RO
11801  */
11802 MLXSW_ITEM32(reg, mfde, fatal_cause_tile_v, 0x14, 23, 1);
11803 
11804 /* reg_mfde_fatal_cause_tile_index
11805  * When tile_v=1, the tile_index that caused the assert.
11806  * Access: RO
11807  */
11808 MLXSW_ITEM32(reg, mfde, fatal_cause_tile_index, 0x14, 16, 6);
11809 
11810 /* TNGCR - Tunneling NVE General Configuration Register
11811  * ----------------------------------------------------
11812  * The TNGCR register is used for setting up the NVE Tunneling configuration.
11813  */
11814 #define MLXSW_REG_TNGCR_ID 0xA001
11815 #define MLXSW_REG_TNGCR_LEN 0x44
11816 
11817 MLXSW_REG_DEFINE(tngcr, MLXSW_REG_TNGCR_ID, MLXSW_REG_TNGCR_LEN);
11818 
11819 enum mlxsw_reg_tngcr_type {
11820 	MLXSW_REG_TNGCR_TYPE_VXLAN,
11821 	MLXSW_REG_TNGCR_TYPE_VXLAN_GPE,
11822 	MLXSW_REG_TNGCR_TYPE_GENEVE,
11823 	MLXSW_REG_TNGCR_TYPE_NVGRE,
11824 };
11825 
11826 /* reg_tngcr_type
11827  * Tunnel type for encapsulation and decapsulation. The types are mutually
11828  * exclusive.
11829  * Note: For Spectrum the NVE parsing must be enabled in MPRS.
11830  * Access: RW
11831  */
11832 MLXSW_ITEM32(reg, tngcr, type, 0x00, 0, 4);
11833 
11834 /* reg_tngcr_nve_valid
11835  * The VTEP is valid. Allows adding FDB entries for tunnel encapsulation.
11836  * Access: RW
11837  */
11838 MLXSW_ITEM32(reg, tngcr, nve_valid, 0x04, 31, 1);
11839 
11840 /* reg_tngcr_nve_ttl_uc
11841  * The TTL for NVE tunnel encapsulation underlay unicast packets.
11842  * Access: RW
11843  */
11844 MLXSW_ITEM32(reg, tngcr, nve_ttl_uc, 0x04, 0, 8);
11845 
11846 /* reg_tngcr_nve_ttl_mc
11847  * The TTL for NVE tunnel encapsulation underlay multicast packets.
11848  * Access: RW
11849  */
11850 MLXSW_ITEM32(reg, tngcr, nve_ttl_mc, 0x08, 0, 8);
11851 
11852 enum {
11853 	/* Do not copy flow label. Calculate flow label using nve_flh. */
11854 	MLXSW_REG_TNGCR_FL_NO_COPY,
11855 	/* Copy flow label from inner packet if packet is IPv6 and
11856 	 * encapsulation is by IPv6. Otherwise, calculate flow label using
11857 	 * nve_flh.
11858 	 */
11859 	MLXSW_REG_TNGCR_FL_COPY,
11860 };
11861 
11862 /* reg_tngcr_nve_flc
11863  * For NVE tunnel encapsulation: Flow label copy from inner packet.
11864  * Access: RW
11865  */
11866 MLXSW_ITEM32(reg, tngcr, nve_flc, 0x0C, 25, 1);
11867 
11868 enum {
11869 	/* Flow label is static. In Spectrum this means '0'. Spectrum-2
11870 	 * uses {nve_fl_prefix, nve_fl_suffix}.
11871 	 */
11872 	MLXSW_REG_TNGCR_FL_NO_HASH,
11873 	/* 8 LSBs of the flow label are calculated from ECMP hash of the
11874 	 * inner packet. 12 MSBs are configured by nve_fl_prefix.
11875 	 */
11876 	MLXSW_REG_TNGCR_FL_HASH,
11877 };
11878 
11879 /* reg_tngcr_nve_flh
11880  * NVE flow label hash.
11881  * Access: RW
11882  */
11883 MLXSW_ITEM32(reg, tngcr, nve_flh, 0x0C, 24, 1);
11884 
11885 /* reg_tngcr_nve_fl_prefix
11886  * NVE flow label prefix. Constant 12 MSBs of the flow label.
11887  * Access: RW
11888  */
11889 MLXSW_ITEM32(reg, tngcr, nve_fl_prefix, 0x0C, 8, 12);
11890 
11891 /* reg_tngcr_nve_fl_suffix
11892  * NVE flow label suffix. Constant 8 LSBs of the flow label.
11893  * Reserved when nve_flh=1 and for Spectrum.
11894  * Access: RW
11895  */
11896 MLXSW_ITEM32(reg, tngcr, nve_fl_suffix, 0x0C, 0, 8);
11897 
11898 enum {
11899 	/* Source UDP port is fixed (default '0') */
11900 	MLXSW_REG_TNGCR_UDP_SPORT_NO_HASH,
11901 	/* Source UDP port is calculated based on hash */
11902 	MLXSW_REG_TNGCR_UDP_SPORT_HASH,
11903 };
11904 
11905 /* reg_tngcr_nve_udp_sport_type
11906  * NVE UDP source port type.
11907  * Spectrum uses LAG hash (SLCRv2). Spectrum-2 uses ECMP hash (RECRv2).
11908  * When the source UDP port is calculated based on hash, then the 8 LSBs
11909  * are calculated from hash the 8 MSBs are configured by
11910  * nve_udp_sport_prefix.
11911  * Access: RW
11912  */
11913 MLXSW_ITEM32(reg, tngcr, nve_udp_sport_type, 0x10, 24, 1);
11914 
11915 /* reg_tngcr_nve_udp_sport_prefix
11916  * NVE UDP source port prefix. Constant 8 MSBs of the UDP source port.
11917  * Reserved when NVE type is NVGRE.
11918  * Access: RW
11919  */
11920 MLXSW_ITEM32(reg, tngcr, nve_udp_sport_prefix, 0x10, 8, 8);
11921 
11922 /* reg_tngcr_nve_group_size_mc
11923  * The amount of sequential linked lists of MC entries. The first linked
11924  * list is configured by SFD.underlay_mc_ptr.
11925  * Valid values: 1, 2, 4, 8, 16, 32, 64
11926  * The linked list are configured by TNUMT.
11927  * The hash is set by LAG hash.
11928  * Access: RW
11929  */
11930 MLXSW_ITEM32(reg, tngcr, nve_group_size_mc, 0x18, 0, 8);
11931 
11932 /* reg_tngcr_nve_group_size_flood
11933  * The amount of sequential linked lists of flooding entries. The first
11934  * linked list is configured by SFMR.nve_tunnel_flood_ptr
11935  * Valid values: 1, 2, 4, 8, 16, 32, 64
11936  * The linked list are configured by TNUMT.
11937  * The hash is set by LAG hash.
11938  * Access: RW
11939  */
11940 MLXSW_ITEM32(reg, tngcr, nve_group_size_flood, 0x1C, 0, 8);
11941 
11942 /* reg_tngcr_learn_enable
11943  * During decapsulation, whether to learn from NVE port.
11944  * Reserved when Spectrum-2. See TNPC.
11945  * Access: RW
11946  */
11947 MLXSW_ITEM32(reg, tngcr, learn_enable, 0x20, 31, 1);
11948 
11949 /* reg_tngcr_underlay_virtual_router
11950  * Underlay virtual router.
11951  * Reserved when Spectrum-2.
11952  * Access: RW
11953  */
11954 MLXSW_ITEM32(reg, tngcr, underlay_virtual_router, 0x20, 0, 16);
11955 
11956 /* reg_tngcr_underlay_rif
11957  * Underlay ingress router interface. RIF type should be loopback generic.
11958  * Reserved when Spectrum.
11959  * Access: RW
11960  */
11961 MLXSW_ITEM32(reg, tngcr, underlay_rif, 0x24, 0, 16);
11962 
11963 /* reg_tngcr_usipv4
11964  * Underlay source IPv4 address of the NVE.
11965  * Access: RW
11966  */
11967 MLXSW_ITEM32(reg, tngcr, usipv4, 0x28, 0, 32);
11968 
11969 /* reg_tngcr_usipv6
11970  * Underlay source IPv6 address of the NVE. For Spectrum, must not be
11971  * modified under traffic of NVE tunneling encapsulation.
11972  * Access: RW
11973  */
11974 MLXSW_ITEM_BUF(reg, tngcr, usipv6, 0x30, 16);
11975 
11976 static inline void mlxsw_reg_tngcr_pack(char *payload,
11977 					enum mlxsw_reg_tngcr_type type,
11978 					bool valid, u8 ttl)
11979 {
11980 	MLXSW_REG_ZERO(tngcr, payload);
11981 	mlxsw_reg_tngcr_type_set(payload, type);
11982 	mlxsw_reg_tngcr_nve_valid_set(payload, valid);
11983 	mlxsw_reg_tngcr_nve_ttl_uc_set(payload, ttl);
11984 	mlxsw_reg_tngcr_nve_ttl_mc_set(payload, ttl);
11985 	mlxsw_reg_tngcr_nve_flc_set(payload, MLXSW_REG_TNGCR_FL_NO_COPY);
11986 	mlxsw_reg_tngcr_nve_flh_set(payload, 0);
11987 	mlxsw_reg_tngcr_nve_udp_sport_type_set(payload,
11988 					       MLXSW_REG_TNGCR_UDP_SPORT_HASH);
11989 	mlxsw_reg_tngcr_nve_udp_sport_prefix_set(payload, 0);
11990 	mlxsw_reg_tngcr_nve_group_size_mc_set(payload, 1);
11991 	mlxsw_reg_tngcr_nve_group_size_flood_set(payload, 1);
11992 }
11993 
11994 /* TNUMT - Tunneling NVE Underlay Multicast Table Register
11995  * -------------------------------------------------------
11996  * The TNUMT register is for building the underlay MC table. It is used
11997  * for MC, flooding and BC traffic into the NVE tunnel.
11998  */
11999 #define MLXSW_REG_TNUMT_ID 0xA003
12000 #define MLXSW_REG_TNUMT_LEN 0x20
12001 
12002 MLXSW_REG_DEFINE(tnumt, MLXSW_REG_TNUMT_ID, MLXSW_REG_TNUMT_LEN);
12003 
12004 enum mlxsw_reg_tnumt_record_type {
12005 	MLXSW_REG_TNUMT_RECORD_TYPE_IPV4,
12006 	MLXSW_REG_TNUMT_RECORD_TYPE_IPV6,
12007 	MLXSW_REG_TNUMT_RECORD_TYPE_LABEL,
12008 };
12009 
12010 /* reg_tnumt_record_type
12011  * Record type.
12012  * Access: RW
12013  */
12014 MLXSW_ITEM32(reg, tnumt, record_type, 0x00, 28, 4);
12015 
12016 /* reg_tnumt_tunnel_port
12017  * Tunnel port.
12018  * Access: RW
12019  */
12020 MLXSW_ITEM32(reg, tnumt, tunnel_port, 0x00, 24, 4);
12021 
12022 /* reg_tnumt_underlay_mc_ptr
12023  * Index to the underlay multicast table.
12024  * For Spectrum the index is to the KVD linear.
12025  * Access: Index
12026  */
12027 MLXSW_ITEM32(reg, tnumt, underlay_mc_ptr, 0x00, 0, 24);
12028 
12029 /* reg_tnumt_vnext
12030  * The next_underlay_mc_ptr is valid.
12031  * Access: RW
12032  */
12033 MLXSW_ITEM32(reg, tnumt, vnext, 0x04, 31, 1);
12034 
12035 /* reg_tnumt_next_underlay_mc_ptr
12036  * The next index to the underlay multicast table.
12037  * Access: RW
12038  */
12039 MLXSW_ITEM32(reg, tnumt, next_underlay_mc_ptr, 0x04, 0, 24);
12040 
12041 /* reg_tnumt_record_size
12042  * Number of IP addresses in the record.
12043  * Range is 1..cap_max_nve_mc_entries_ipv{4,6}
12044  * Access: RW
12045  */
12046 MLXSW_ITEM32(reg, tnumt, record_size, 0x08, 0, 3);
12047 
12048 /* reg_tnumt_udip
12049  * The underlay IPv4 addresses. udip[i] is reserved if i >= size
12050  * Access: RW
12051  */
12052 MLXSW_ITEM32_INDEXED(reg, tnumt, udip, 0x0C, 0, 32, 0x04, 0x00, false);
12053 
12054 /* reg_tnumt_udip_ptr
12055  * The pointer to the underlay IPv6 addresses. udip_ptr[i] is reserved if
12056  * i >= size. The IPv6 addresses are configured by RIPS.
12057  * Access: RW
12058  */
12059 MLXSW_ITEM32_INDEXED(reg, tnumt, udip_ptr, 0x0C, 0, 24, 0x04, 0x00, false);
12060 
12061 static inline void mlxsw_reg_tnumt_pack(char *payload,
12062 					enum mlxsw_reg_tnumt_record_type type,
12063 					enum mlxsw_reg_tunnel_port tport,
12064 					u32 underlay_mc_ptr, bool vnext,
12065 					u32 next_underlay_mc_ptr,
12066 					u8 record_size)
12067 {
12068 	MLXSW_REG_ZERO(tnumt, payload);
12069 	mlxsw_reg_tnumt_record_type_set(payload, type);
12070 	mlxsw_reg_tnumt_tunnel_port_set(payload, tport);
12071 	mlxsw_reg_tnumt_underlay_mc_ptr_set(payload, underlay_mc_ptr);
12072 	mlxsw_reg_tnumt_vnext_set(payload, vnext);
12073 	mlxsw_reg_tnumt_next_underlay_mc_ptr_set(payload, next_underlay_mc_ptr);
12074 	mlxsw_reg_tnumt_record_size_set(payload, record_size);
12075 }
12076 
12077 /* TNQCR - Tunneling NVE QoS Configuration Register
12078  * ------------------------------------------------
12079  * The TNQCR register configures how QoS is set in encapsulation into the
12080  * underlay network.
12081  */
12082 #define MLXSW_REG_TNQCR_ID 0xA010
12083 #define MLXSW_REG_TNQCR_LEN 0x0C
12084 
12085 MLXSW_REG_DEFINE(tnqcr, MLXSW_REG_TNQCR_ID, MLXSW_REG_TNQCR_LEN);
12086 
12087 /* reg_tnqcr_enc_set_dscp
12088  * For encapsulation: How to set DSCP field:
12089  * 0 - Copy the DSCP from the overlay (inner) IP header to the underlay
12090  * (outer) IP header. If there is no IP header, use TNQDR.dscp
12091  * 1 - Set the DSCP field as TNQDR.dscp
12092  * Access: RW
12093  */
12094 MLXSW_ITEM32(reg, tnqcr, enc_set_dscp, 0x04, 28, 1);
12095 
12096 static inline void mlxsw_reg_tnqcr_pack(char *payload)
12097 {
12098 	MLXSW_REG_ZERO(tnqcr, payload);
12099 	mlxsw_reg_tnqcr_enc_set_dscp_set(payload, 0);
12100 }
12101 
12102 /* TNQDR - Tunneling NVE QoS Default Register
12103  * ------------------------------------------
12104  * The TNQDR register configures the default QoS settings for NVE
12105  * encapsulation.
12106  */
12107 #define MLXSW_REG_TNQDR_ID 0xA011
12108 #define MLXSW_REG_TNQDR_LEN 0x08
12109 
12110 MLXSW_REG_DEFINE(tnqdr, MLXSW_REG_TNQDR_ID, MLXSW_REG_TNQDR_LEN);
12111 
12112 /* reg_tnqdr_local_port
12113  * Local port number (receive port). CPU port is supported.
12114  * Access: Index
12115  */
12116 MLXSW_ITEM32_LP(reg, tnqdr, 0x00, 16, 0x00, 12);
12117 
12118 /* reg_tnqdr_dscp
12119  * For encapsulation, the default DSCP.
12120  * Access: RW
12121  */
12122 MLXSW_ITEM32(reg, tnqdr, dscp, 0x04, 0, 6);
12123 
12124 static inline void mlxsw_reg_tnqdr_pack(char *payload, u16 local_port)
12125 {
12126 	MLXSW_REG_ZERO(tnqdr, payload);
12127 	mlxsw_reg_tnqdr_local_port_set(payload, local_port);
12128 	mlxsw_reg_tnqdr_dscp_set(payload, 0);
12129 }
12130 
12131 /* TNEEM - Tunneling NVE Encapsulation ECN Mapping Register
12132  * --------------------------------------------------------
12133  * The TNEEM register maps ECN of the IP header at the ingress to the
12134  * encapsulation to the ECN of the underlay network.
12135  */
12136 #define MLXSW_REG_TNEEM_ID 0xA012
12137 #define MLXSW_REG_TNEEM_LEN 0x0C
12138 
12139 MLXSW_REG_DEFINE(tneem, MLXSW_REG_TNEEM_ID, MLXSW_REG_TNEEM_LEN);
12140 
12141 /* reg_tneem_overlay_ecn
12142  * ECN of the IP header in the overlay network.
12143  * Access: Index
12144  */
12145 MLXSW_ITEM32(reg, tneem, overlay_ecn, 0x04, 24, 2);
12146 
12147 /* reg_tneem_underlay_ecn
12148  * ECN of the IP header in the underlay network.
12149  * Access: RW
12150  */
12151 MLXSW_ITEM32(reg, tneem, underlay_ecn, 0x04, 16, 2);
12152 
12153 static inline void mlxsw_reg_tneem_pack(char *payload, u8 overlay_ecn,
12154 					u8 underlay_ecn)
12155 {
12156 	MLXSW_REG_ZERO(tneem, payload);
12157 	mlxsw_reg_tneem_overlay_ecn_set(payload, overlay_ecn);
12158 	mlxsw_reg_tneem_underlay_ecn_set(payload, underlay_ecn);
12159 }
12160 
12161 /* TNDEM - Tunneling NVE Decapsulation ECN Mapping Register
12162  * --------------------------------------------------------
12163  * The TNDEM register configures the actions that are done in the
12164  * decapsulation.
12165  */
12166 #define MLXSW_REG_TNDEM_ID 0xA013
12167 #define MLXSW_REG_TNDEM_LEN 0x0C
12168 
12169 MLXSW_REG_DEFINE(tndem, MLXSW_REG_TNDEM_ID, MLXSW_REG_TNDEM_LEN);
12170 
12171 /* reg_tndem_underlay_ecn
12172  * ECN field of the IP header in the underlay network.
12173  * Access: Index
12174  */
12175 MLXSW_ITEM32(reg, tndem, underlay_ecn, 0x04, 24, 2);
12176 
12177 /* reg_tndem_overlay_ecn
12178  * ECN field of the IP header in the overlay network.
12179  * Access: Index
12180  */
12181 MLXSW_ITEM32(reg, tndem, overlay_ecn, 0x04, 16, 2);
12182 
12183 /* reg_tndem_eip_ecn
12184  * Egress IP ECN. ECN field of the IP header of the packet which goes out
12185  * from the decapsulation.
12186  * Access: RW
12187  */
12188 MLXSW_ITEM32(reg, tndem, eip_ecn, 0x04, 8, 2);
12189 
12190 /* reg_tndem_trap_en
12191  * Trap enable:
12192  * 0 - No trap due to decap ECN
12193  * 1 - Trap enable with trap_id
12194  * Access: RW
12195  */
12196 MLXSW_ITEM32(reg, tndem, trap_en, 0x08, 28, 4);
12197 
12198 /* reg_tndem_trap_id
12199  * Trap ID. Either DECAP_ECN0 or DECAP_ECN1.
12200  * Reserved when trap_en is '0'.
12201  * Access: RW
12202  */
12203 MLXSW_ITEM32(reg, tndem, trap_id, 0x08, 0, 9);
12204 
12205 static inline void mlxsw_reg_tndem_pack(char *payload, u8 underlay_ecn,
12206 					u8 overlay_ecn, u8 ecn, bool trap_en,
12207 					u16 trap_id)
12208 {
12209 	MLXSW_REG_ZERO(tndem, payload);
12210 	mlxsw_reg_tndem_underlay_ecn_set(payload, underlay_ecn);
12211 	mlxsw_reg_tndem_overlay_ecn_set(payload, overlay_ecn);
12212 	mlxsw_reg_tndem_eip_ecn_set(payload, ecn);
12213 	mlxsw_reg_tndem_trap_en_set(payload, trap_en);
12214 	mlxsw_reg_tndem_trap_id_set(payload, trap_id);
12215 }
12216 
12217 /* TNPC - Tunnel Port Configuration Register
12218  * -----------------------------------------
12219  * The TNPC register is used for tunnel port configuration.
12220  * Reserved when Spectrum.
12221  */
12222 #define MLXSW_REG_TNPC_ID 0xA020
12223 #define MLXSW_REG_TNPC_LEN 0x18
12224 
12225 MLXSW_REG_DEFINE(tnpc, MLXSW_REG_TNPC_ID, MLXSW_REG_TNPC_LEN);
12226 
12227 /* reg_tnpc_tunnel_port
12228  * Tunnel port.
12229  * Access: Index
12230  */
12231 MLXSW_ITEM32(reg, tnpc, tunnel_port, 0x00, 0, 4);
12232 
12233 /* reg_tnpc_learn_enable_v6
12234  * During IPv6 underlay decapsulation, whether to learn from tunnel port.
12235  * Access: RW
12236  */
12237 MLXSW_ITEM32(reg, tnpc, learn_enable_v6, 0x04, 1, 1);
12238 
12239 /* reg_tnpc_learn_enable_v4
12240  * During IPv4 underlay decapsulation, whether to learn from tunnel port.
12241  * Access: RW
12242  */
12243 MLXSW_ITEM32(reg, tnpc, learn_enable_v4, 0x04, 0, 1);
12244 
12245 static inline void mlxsw_reg_tnpc_pack(char *payload,
12246 				       enum mlxsw_reg_tunnel_port tport,
12247 				       bool learn_enable)
12248 {
12249 	MLXSW_REG_ZERO(tnpc, payload);
12250 	mlxsw_reg_tnpc_tunnel_port_set(payload, tport);
12251 	mlxsw_reg_tnpc_learn_enable_v4_set(payload, learn_enable);
12252 	mlxsw_reg_tnpc_learn_enable_v6_set(payload, learn_enable);
12253 }
12254 
12255 /* TIGCR - Tunneling IPinIP General Configuration Register
12256  * -------------------------------------------------------
12257  * The TIGCR register is used for setting up the IPinIP Tunnel configuration.
12258  */
12259 #define MLXSW_REG_TIGCR_ID 0xA801
12260 #define MLXSW_REG_TIGCR_LEN 0x10
12261 
12262 MLXSW_REG_DEFINE(tigcr, MLXSW_REG_TIGCR_ID, MLXSW_REG_TIGCR_LEN);
12263 
12264 /* reg_tigcr_ipip_ttlc
12265  * For IPinIP Tunnel encapsulation: whether to copy the ttl from the packet
12266  * header.
12267  * Access: RW
12268  */
12269 MLXSW_ITEM32(reg, tigcr, ttlc, 0x04, 8, 1);
12270 
12271 /* reg_tigcr_ipip_ttl_uc
12272  * The TTL for IPinIP Tunnel encapsulation of unicast packets if
12273  * reg_tigcr_ipip_ttlc is unset.
12274  * Access: RW
12275  */
12276 MLXSW_ITEM32(reg, tigcr, ttl_uc, 0x04, 0, 8);
12277 
12278 static inline void mlxsw_reg_tigcr_pack(char *payload, bool ttlc, u8 ttl_uc)
12279 {
12280 	MLXSW_REG_ZERO(tigcr, payload);
12281 	mlxsw_reg_tigcr_ttlc_set(payload, ttlc);
12282 	mlxsw_reg_tigcr_ttl_uc_set(payload, ttl_uc);
12283 }
12284 
12285 /* TIEEM - Tunneling IPinIP Encapsulation ECN Mapping Register
12286  * -----------------------------------------------------------
12287  * The TIEEM register maps ECN of the IP header at the ingress to the
12288  * encapsulation to the ECN of the underlay network.
12289  */
12290 #define MLXSW_REG_TIEEM_ID 0xA812
12291 #define MLXSW_REG_TIEEM_LEN 0x0C
12292 
12293 MLXSW_REG_DEFINE(tieem, MLXSW_REG_TIEEM_ID, MLXSW_REG_TIEEM_LEN);
12294 
12295 /* reg_tieem_overlay_ecn
12296  * ECN of the IP header in the overlay network.
12297  * Access: Index
12298  */
12299 MLXSW_ITEM32(reg, tieem, overlay_ecn, 0x04, 24, 2);
12300 
12301 /* reg_tineem_underlay_ecn
12302  * ECN of the IP header in the underlay network.
12303  * Access: RW
12304  */
12305 MLXSW_ITEM32(reg, tieem, underlay_ecn, 0x04, 16, 2);
12306 
12307 static inline void mlxsw_reg_tieem_pack(char *payload, u8 overlay_ecn,
12308 					u8 underlay_ecn)
12309 {
12310 	MLXSW_REG_ZERO(tieem, payload);
12311 	mlxsw_reg_tieem_overlay_ecn_set(payload, overlay_ecn);
12312 	mlxsw_reg_tieem_underlay_ecn_set(payload, underlay_ecn);
12313 }
12314 
12315 /* TIDEM - Tunneling IPinIP Decapsulation ECN Mapping Register
12316  * -----------------------------------------------------------
12317  * The TIDEM register configures the actions that are done in the
12318  * decapsulation.
12319  */
12320 #define MLXSW_REG_TIDEM_ID 0xA813
12321 #define MLXSW_REG_TIDEM_LEN 0x0C
12322 
12323 MLXSW_REG_DEFINE(tidem, MLXSW_REG_TIDEM_ID, MLXSW_REG_TIDEM_LEN);
12324 
12325 /* reg_tidem_underlay_ecn
12326  * ECN field of the IP header in the underlay network.
12327  * Access: Index
12328  */
12329 MLXSW_ITEM32(reg, tidem, underlay_ecn, 0x04, 24, 2);
12330 
12331 /* reg_tidem_overlay_ecn
12332  * ECN field of the IP header in the overlay network.
12333  * Access: Index
12334  */
12335 MLXSW_ITEM32(reg, tidem, overlay_ecn, 0x04, 16, 2);
12336 
12337 /* reg_tidem_eip_ecn
12338  * Egress IP ECN. ECN field of the IP header of the packet which goes out
12339  * from the decapsulation.
12340  * Access: RW
12341  */
12342 MLXSW_ITEM32(reg, tidem, eip_ecn, 0x04, 8, 2);
12343 
12344 /* reg_tidem_trap_en
12345  * Trap enable:
12346  * 0 - No trap due to decap ECN
12347  * 1 - Trap enable with trap_id
12348  * Access: RW
12349  */
12350 MLXSW_ITEM32(reg, tidem, trap_en, 0x08, 28, 4);
12351 
12352 /* reg_tidem_trap_id
12353  * Trap ID. Either DECAP_ECN0 or DECAP_ECN1.
12354  * Reserved when trap_en is '0'.
12355  * Access: RW
12356  */
12357 MLXSW_ITEM32(reg, tidem, trap_id, 0x08, 0, 9);
12358 
12359 static inline void mlxsw_reg_tidem_pack(char *payload, u8 underlay_ecn,
12360 					u8 overlay_ecn, u8 eip_ecn,
12361 					bool trap_en, u16 trap_id)
12362 {
12363 	MLXSW_REG_ZERO(tidem, payload);
12364 	mlxsw_reg_tidem_underlay_ecn_set(payload, underlay_ecn);
12365 	mlxsw_reg_tidem_overlay_ecn_set(payload, overlay_ecn);
12366 	mlxsw_reg_tidem_eip_ecn_set(payload, eip_ecn);
12367 	mlxsw_reg_tidem_trap_en_set(payload, trap_en);
12368 	mlxsw_reg_tidem_trap_id_set(payload, trap_id);
12369 }
12370 
12371 /* SBPR - Shared Buffer Pools Register
12372  * -----------------------------------
12373  * The SBPR configures and retrieves the shared buffer pools and configuration.
12374  */
12375 #define MLXSW_REG_SBPR_ID 0xB001
12376 #define MLXSW_REG_SBPR_LEN 0x14
12377 
12378 MLXSW_REG_DEFINE(sbpr, MLXSW_REG_SBPR_ID, MLXSW_REG_SBPR_LEN);
12379 
12380 /* reg_sbpr_desc
12381  * When set, configures descriptor buffer.
12382  * Access: Index
12383  */
12384 MLXSW_ITEM32(reg, sbpr, desc, 0x00, 31, 1);
12385 
12386 /* shared direstion enum for SBPR, SBCM, SBPM */
12387 enum mlxsw_reg_sbxx_dir {
12388 	MLXSW_REG_SBXX_DIR_INGRESS,
12389 	MLXSW_REG_SBXX_DIR_EGRESS,
12390 };
12391 
12392 /* reg_sbpr_dir
12393  * Direction.
12394  * Access: Index
12395  */
12396 MLXSW_ITEM32(reg, sbpr, dir, 0x00, 24, 2);
12397 
12398 /* reg_sbpr_pool
12399  * Pool index.
12400  * Access: Index
12401  */
12402 MLXSW_ITEM32(reg, sbpr, pool, 0x00, 0, 4);
12403 
12404 /* reg_sbpr_infi_size
12405  * Size is infinite.
12406  * Access: RW
12407  */
12408 MLXSW_ITEM32(reg, sbpr, infi_size, 0x04, 31, 1);
12409 
12410 /* reg_sbpr_size
12411  * Pool size in buffer cells.
12412  * Reserved when infi_size = 1.
12413  * Access: RW
12414  */
12415 MLXSW_ITEM32(reg, sbpr, size, 0x04, 0, 24);
12416 
12417 enum mlxsw_reg_sbpr_mode {
12418 	MLXSW_REG_SBPR_MODE_STATIC,
12419 	MLXSW_REG_SBPR_MODE_DYNAMIC,
12420 };
12421 
12422 /* reg_sbpr_mode
12423  * Pool quota calculation mode.
12424  * Access: RW
12425  */
12426 MLXSW_ITEM32(reg, sbpr, mode, 0x08, 0, 4);
12427 
12428 static inline void mlxsw_reg_sbpr_pack(char *payload, u8 pool,
12429 				       enum mlxsw_reg_sbxx_dir dir,
12430 				       enum mlxsw_reg_sbpr_mode mode, u32 size,
12431 				       bool infi_size)
12432 {
12433 	MLXSW_REG_ZERO(sbpr, payload);
12434 	mlxsw_reg_sbpr_pool_set(payload, pool);
12435 	mlxsw_reg_sbpr_dir_set(payload, dir);
12436 	mlxsw_reg_sbpr_mode_set(payload, mode);
12437 	mlxsw_reg_sbpr_size_set(payload, size);
12438 	mlxsw_reg_sbpr_infi_size_set(payload, infi_size);
12439 }
12440 
12441 /* SBCM - Shared Buffer Class Management Register
12442  * ----------------------------------------------
12443  * The SBCM register configures and retrieves the shared buffer allocation
12444  * and configuration according to Port-PG, including the binding to pool
12445  * and definition of the associated quota.
12446  */
12447 #define MLXSW_REG_SBCM_ID 0xB002
12448 #define MLXSW_REG_SBCM_LEN 0x28
12449 
12450 MLXSW_REG_DEFINE(sbcm, MLXSW_REG_SBCM_ID, MLXSW_REG_SBCM_LEN);
12451 
12452 /* reg_sbcm_local_port
12453  * Local port number.
12454  * For Ingress: excludes CPU port and Router port
12455  * For Egress: excludes IP Router
12456  * Access: Index
12457  */
12458 MLXSW_ITEM32_LP(reg, sbcm, 0x00, 16, 0x00, 4);
12459 
12460 /* reg_sbcm_pg_buff
12461  * PG buffer - Port PG (dir=ingress) / traffic class (dir=egress)
12462  * For PG buffer: range is 0..cap_max_pg_buffers - 1
12463  * For traffic class: range is 0..cap_max_tclass - 1
12464  * Note that when traffic class is in MC aware mode then the traffic
12465  * classes which are MC aware cannot be configured.
12466  * Access: Index
12467  */
12468 MLXSW_ITEM32(reg, sbcm, pg_buff, 0x00, 8, 6);
12469 
12470 /* reg_sbcm_dir
12471  * Direction.
12472  * Access: Index
12473  */
12474 MLXSW_ITEM32(reg, sbcm, dir, 0x00, 0, 2);
12475 
12476 /* reg_sbcm_min_buff
12477  * Minimum buffer size for the limiter, in cells.
12478  * Access: RW
12479  */
12480 MLXSW_ITEM32(reg, sbcm, min_buff, 0x18, 0, 24);
12481 
12482 /* shared max_buff limits for dynamic threshold for SBCM, SBPM */
12483 #define MLXSW_REG_SBXX_DYN_MAX_BUFF_MIN 1
12484 #define MLXSW_REG_SBXX_DYN_MAX_BUFF_MAX 14
12485 
12486 /* reg_sbcm_infi_max
12487  * Max buffer is infinite.
12488  * Access: RW
12489  */
12490 MLXSW_ITEM32(reg, sbcm, infi_max, 0x1C, 31, 1);
12491 
12492 /* reg_sbcm_max_buff
12493  * When the pool associated to the port-pg/tclass is configured to
12494  * static, Maximum buffer size for the limiter configured in cells.
12495  * When the pool associated to the port-pg/tclass is configured to
12496  * dynamic, the max_buff holds the "alpha" parameter, supporting
12497  * the following values:
12498  * 0: 0
12499  * i: (1/128)*2^(i-1), for i=1..14
12500  * 0xFF: Infinity
12501  * Reserved when infi_max = 1.
12502  * Access: RW
12503  */
12504 MLXSW_ITEM32(reg, sbcm, max_buff, 0x1C, 0, 24);
12505 
12506 /* reg_sbcm_pool
12507  * Association of the port-priority to a pool.
12508  * Access: RW
12509  */
12510 MLXSW_ITEM32(reg, sbcm, pool, 0x24, 0, 4);
12511 
12512 static inline void mlxsw_reg_sbcm_pack(char *payload, u16 local_port, u8 pg_buff,
12513 				       enum mlxsw_reg_sbxx_dir dir,
12514 				       u32 min_buff, u32 max_buff,
12515 				       bool infi_max, u8 pool)
12516 {
12517 	MLXSW_REG_ZERO(sbcm, payload);
12518 	mlxsw_reg_sbcm_local_port_set(payload, local_port);
12519 	mlxsw_reg_sbcm_pg_buff_set(payload, pg_buff);
12520 	mlxsw_reg_sbcm_dir_set(payload, dir);
12521 	mlxsw_reg_sbcm_min_buff_set(payload, min_buff);
12522 	mlxsw_reg_sbcm_max_buff_set(payload, max_buff);
12523 	mlxsw_reg_sbcm_infi_max_set(payload, infi_max);
12524 	mlxsw_reg_sbcm_pool_set(payload, pool);
12525 }
12526 
12527 /* SBPM - Shared Buffer Port Management Register
12528  * ---------------------------------------------
12529  * The SBPM register configures and retrieves the shared buffer allocation
12530  * and configuration according to Port-Pool, including the definition
12531  * of the associated quota.
12532  */
12533 #define MLXSW_REG_SBPM_ID 0xB003
12534 #define MLXSW_REG_SBPM_LEN 0x28
12535 
12536 MLXSW_REG_DEFINE(sbpm, MLXSW_REG_SBPM_ID, MLXSW_REG_SBPM_LEN);
12537 
12538 /* reg_sbpm_local_port
12539  * Local port number.
12540  * For Ingress: excludes CPU port and Router port
12541  * For Egress: excludes IP Router
12542  * Access: Index
12543  */
12544 MLXSW_ITEM32_LP(reg, sbpm, 0x00, 16, 0x00, 12);
12545 
12546 /* reg_sbpm_pool
12547  * The pool associated to quota counting on the local_port.
12548  * Access: Index
12549  */
12550 MLXSW_ITEM32(reg, sbpm, pool, 0x00, 8, 4);
12551 
12552 /* reg_sbpm_dir
12553  * Direction.
12554  * Access: Index
12555  */
12556 MLXSW_ITEM32(reg, sbpm, dir, 0x00, 0, 2);
12557 
12558 /* reg_sbpm_buff_occupancy
12559  * Current buffer occupancy in cells.
12560  * Access: RO
12561  */
12562 MLXSW_ITEM32(reg, sbpm, buff_occupancy, 0x10, 0, 24);
12563 
12564 /* reg_sbpm_clr
12565  * Clear Max Buffer Occupancy
12566  * When this bit is set, max_buff_occupancy field is cleared (and a
12567  * new max value is tracked from the time the clear was performed).
12568  * Access: OP
12569  */
12570 MLXSW_ITEM32(reg, sbpm, clr, 0x14, 31, 1);
12571 
12572 /* reg_sbpm_max_buff_occupancy
12573  * Maximum value of buffer occupancy in cells monitored. Cleared by
12574  * writing to the clr field.
12575  * Access: RO
12576  */
12577 MLXSW_ITEM32(reg, sbpm, max_buff_occupancy, 0x14, 0, 24);
12578 
12579 /* reg_sbpm_min_buff
12580  * Minimum buffer size for the limiter, in cells.
12581  * Access: RW
12582  */
12583 MLXSW_ITEM32(reg, sbpm, min_buff, 0x18, 0, 24);
12584 
12585 /* reg_sbpm_max_buff
12586  * When the pool associated to the port-pg/tclass is configured to
12587  * static, Maximum buffer size for the limiter configured in cells.
12588  * When the pool associated to the port-pg/tclass is configured to
12589  * dynamic, the max_buff holds the "alpha" parameter, supporting
12590  * the following values:
12591  * 0: 0
12592  * i: (1/128)*2^(i-1), for i=1..14
12593  * 0xFF: Infinity
12594  * Access: RW
12595  */
12596 MLXSW_ITEM32(reg, sbpm, max_buff, 0x1C, 0, 24);
12597 
12598 static inline void mlxsw_reg_sbpm_pack(char *payload, u16 local_port, u8 pool,
12599 				       enum mlxsw_reg_sbxx_dir dir, bool clr,
12600 				       u32 min_buff, u32 max_buff)
12601 {
12602 	MLXSW_REG_ZERO(sbpm, payload);
12603 	mlxsw_reg_sbpm_local_port_set(payload, local_port);
12604 	mlxsw_reg_sbpm_pool_set(payload, pool);
12605 	mlxsw_reg_sbpm_dir_set(payload, dir);
12606 	mlxsw_reg_sbpm_clr_set(payload, clr);
12607 	mlxsw_reg_sbpm_min_buff_set(payload, min_buff);
12608 	mlxsw_reg_sbpm_max_buff_set(payload, max_buff);
12609 }
12610 
12611 static inline void mlxsw_reg_sbpm_unpack(char *payload, u32 *p_buff_occupancy,
12612 					 u32 *p_max_buff_occupancy)
12613 {
12614 	*p_buff_occupancy = mlxsw_reg_sbpm_buff_occupancy_get(payload);
12615 	*p_max_buff_occupancy = mlxsw_reg_sbpm_max_buff_occupancy_get(payload);
12616 }
12617 
12618 /* SBMM - Shared Buffer Multicast Management Register
12619  * --------------------------------------------------
12620  * The SBMM register configures and retrieves the shared buffer allocation
12621  * and configuration for MC packets according to Switch-Priority, including
12622  * the binding to pool and definition of the associated quota.
12623  */
12624 #define MLXSW_REG_SBMM_ID 0xB004
12625 #define MLXSW_REG_SBMM_LEN 0x28
12626 
12627 MLXSW_REG_DEFINE(sbmm, MLXSW_REG_SBMM_ID, MLXSW_REG_SBMM_LEN);
12628 
12629 /* reg_sbmm_prio
12630  * Switch Priority.
12631  * Access: Index
12632  */
12633 MLXSW_ITEM32(reg, sbmm, prio, 0x00, 8, 4);
12634 
12635 /* reg_sbmm_min_buff
12636  * Minimum buffer size for the limiter, in cells.
12637  * Access: RW
12638  */
12639 MLXSW_ITEM32(reg, sbmm, min_buff, 0x18, 0, 24);
12640 
12641 /* reg_sbmm_max_buff
12642  * When the pool associated to the port-pg/tclass is configured to
12643  * static, Maximum buffer size for the limiter configured in cells.
12644  * When the pool associated to the port-pg/tclass is configured to
12645  * dynamic, the max_buff holds the "alpha" parameter, supporting
12646  * the following values:
12647  * 0: 0
12648  * i: (1/128)*2^(i-1), for i=1..14
12649  * 0xFF: Infinity
12650  * Access: RW
12651  */
12652 MLXSW_ITEM32(reg, sbmm, max_buff, 0x1C, 0, 24);
12653 
12654 /* reg_sbmm_pool
12655  * Association of the port-priority to a pool.
12656  * Access: RW
12657  */
12658 MLXSW_ITEM32(reg, sbmm, pool, 0x24, 0, 4);
12659 
12660 static inline void mlxsw_reg_sbmm_pack(char *payload, u8 prio, u32 min_buff,
12661 				       u32 max_buff, u8 pool)
12662 {
12663 	MLXSW_REG_ZERO(sbmm, payload);
12664 	mlxsw_reg_sbmm_prio_set(payload, prio);
12665 	mlxsw_reg_sbmm_min_buff_set(payload, min_buff);
12666 	mlxsw_reg_sbmm_max_buff_set(payload, max_buff);
12667 	mlxsw_reg_sbmm_pool_set(payload, pool);
12668 }
12669 
12670 /* SBSR - Shared Buffer Status Register
12671  * ------------------------------------
12672  * The SBSR register retrieves the shared buffer occupancy according to
12673  * Port-Pool. Note that this register enables reading a large amount of data.
12674  * It is the user's responsibility to limit the amount of data to ensure the
12675  * response can match the maximum transfer unit. In case the response exceeds
12676  * the maximum transport unit, it will be truncated with no special notice.
12677  */
12678 #define MLXSW_REG_SBSR_ID 0xB005
12679 #define MLXSW_REG_SBSR_BASE_LEN 0x5C /* base length, without records */
12680 #define MLXSW_REG_SBSR_REC_LEN 0x8 /* record length */
12681 #define MLXSW_REG_SBSR_REC_MAX_COUNT 120
12682 #define MLXSW_REG_SBSR_LEN (MLXSW_REG_SBSR_BASE_LEN +	\
12683 			    MLXSW_REG_SBSR_REC_LEN *	\
12684 			    MLXSW_REG_SBSR_REC_MAX_COUNT)
12685 
12686 MLXSW_REG_DEFINE(sbsr, MLXSW_REG_SBSR_ID, MLXSW_REG_SBSR_LEN);
12687 
12688 /* reg_sbsr_clr
12689  * Clear Max Buffer Occupancy. When this bit is set, the max_buff_occupancy
12690  * field is cleared (and a new max value is tracked from the time the clear
12691  * was performed).
12692  * Access: OP
12693  */
12694 MLXSW_ITEM32(reg, sbsr, clr, 0x00, 31, 1);
12695 
12696 #define MLXSW_REG_SBSR_NUM_PORTS_IN_PAGE 256
12697 
12698 /* reg_sbsr_port_page
12699  * Determines the range of the ports specified in the 'ingress_port_mask'
12700  * and 'egress_port_mask' bit masks.
12701  * {ingress,egress}_port_mask[x] is (256 * port_page) + x
12702  * Access: Index
12703  */
12704 MLXSW_ITEM32(reg, sbsr, port_page, 0x04, 0, 4);
12705 
12706 /* reg_sbsr_ingress_port_mask
12707  * Bit vector for all ingress network ports.
12708  * Indicates which of the ports (for which the relevant bit is set)
12709  * are affected by the set operation. Configuration of any other port
12710  * does not change.
12711  * Access: Index
12712  */
12713 MLXSW_ITEM_BIT_ARRAY(reg, sbsr, ingress_port_mask, 0x10, 0x20, 1);
12714 
12715 /* reg_sbsr_pg_buff_mask
12716  * Bit vector for all switch priority groups.
12717  * Indicates which of the priorities (for which the relevant bit is set)
12718  * are affected by the set operation. Configuration of any other priority
12719  * does not change.
12720  * Range is 0..cap_max_pg_buffers - 1
12721  * Access: Index
12722  */
12723 MLXSW_ITEM_BIT_ARRAY(reg, sbsr, pg_buff_mask, 0x30, 0x4, 1);
12724 
12725 /* reg_sbsr_egress_port_mask
12726  * Bit vector for all egress network ports.
12727  * Indicates which of the ports (for which the relevant bit is set)
12728  * are affected by the set operation. Configuration of any other port
12729  * does not change.
12730  * Access: Index
12731  */
12732 MLXSW_ITEM_BIT_ARRAY(reg, sbsr, egress_port_mask, 0x34, 0x20, 1);
12733 
12734 /* reg_sbsr_tclass_mask
12735  * Bit vector for all traffic classes.
12736  * Indicates which of the traffic classes (for which the relevant bit is
12737  * set) are affected by the set operation. Configuration of any other
12738  * traffic class does not change.
12739  * Range is 0..cap_max_tclass - 1
12740  * Access: Index
12741  */
12742 MLXSW_ITEM_BIT_ARRAY(reg, sbsr, tclass_mask, 0x54, 0x8, 1);
12743 
12744 static inline void mlxsw_reg_sbsr_pack(char *payload, bool clr)
12745 {
12746 	MLXSW_REG_ZERO(sbsr, payload);
12747 	mlxsw_reg_sbsr_clr_set(payload, clr);
12748 }
12749 
12750 /* reg_sbsr_rec_buff_occupancy
12751  * Current buffer occupancy in cells.
12752  * Access: RO
12753  */
12754 MLXSW_ITEM32_INDEXED(reg, sbsr, rec_buff_occupancy, MLXSW_REG_SBSR_BASE_LEN,
12755 		     0, 24, MLXSW_REG_SBSR_REC_LEN, 0x00, false);
12756 
12757 /* reg_sbsr_rec_max_buff_occupancy
12758  * Maximum value of buffer occupancy in cells monitored. Cleared by
12759  * writing to the clr field.
12760  * Access: RO
12761  */
12762 MLXSW_ITEM32_INDEXED(reg, sbsr, rec_max_buff_occupancy, MLXSW_REG_SBSR_BASE_LEN,
12763 		     0, 24, MLXSW_REG_SBSR_REC_LEN, 0x04, false);
12764 
12765 static inline void mlxsw_reg_sbsr_rec_unpack(char *payload, int rec_index,
12766 					     u32 *p_buff_occupancy,
12767 					     u32 *p_max_buff_occupancy)
12768 {
12769 	*p_buff_occupancy =
12770 		mlxsw_reg_sbsr_rec_buff_occupancy_get(payload, rec_index);
12771 	*p_max_buff_occupancy =
12772 		mlxsw_reg_sbsr_rec_max_buff_occupancy_get(payload, rec_index);
12773 }
12774 
12775 /* SBIB - Shared Buffer Internal Buffer Register
12776  * ---------------------------------------------
12777  * The SBIB register configures per port buffers for internal use. The internal
12778  * buffers consume memory on the port buffers (note that the port buffers are
12779  * used also by PBMC).
12780  *
12781  * For Spectrum this is used for egress mirroring.
12782  */
12783 #define MLXSW_REG_SBIB_ID 0xB006
12784 #define MLXSW_REG_SBIB_LEN 0x10
12785 
12786 MLXSW_REG_DEFINE(sbib, MLXSW_REG_SBIB_ID, MLXSW_REG_SBIB_LEN);
12787 
12788 /* reg_sbib_local_port
12789  * Local port number
12790  * Not supported for CPU port and router port
12791  * Access: Index
12792  */
12793 MLXSW_ITEM32_LP(reg, sbib, 0x00, 16, 0x00, 12);
12794 
12795 /* reg_sbib_buff_size
12796  * Units represented in cells
12797  * Allowed range is 0 to (cap_max_headroom_size - 1)
12798  * Default is 0
12799  * Access: RW
12800  */
12801 MLXSW_ITEM32(reg, sbib, buff_size, 0x08, 0, 24);
12802 
12803 static inline void mlxsw_reg_sbib_pack(char *payload, u16 local_port,
12804 				       u32 buff_size)
12805 {
12806 	MLXSW_REG_ZERO(sbib, payload);
12807 	mlxsw_reg_sbib_local_port_set(payload, local_port);
12808 	mlxsw_reg_sbib_buff_size_set(payload, buff_size);
12809 }
12810 
12811 static const struct mlxsw_reg_info *mlxsw_reg_infos[] = {
12812 	MLXSW_REG(sgcr),
12813 	MLXSW_REG(spad),
12814 	MLXSW_REG(sspr),
12815 	MLXSW_REG(sfdat),
12816 	MLXSW_REG(sfd),
12817 	MLXSW_REG(sfn),
12818 	MLXSW_REG(spms),
12819 	MLXSW_REG(spvid),
12820 	MLXSW_REG(spvm),
12821 	MLXSW_REG(spaft),
12822 	MLXSW_REG(sfgc),
12823 	MLXSW_REG(sfdf),
12824 	MLXSW_REG(sldr),
12825 	MLXSW_REG(slcr),
12826 	MLXSW_REG(slcor),
12827 	MLXSW_REG(spmlr),
12828 	MLXSW_REG(svfa),
12829 	MLXSW_REG(spvtr),
12830 	MLXSW_REG(svpe),
12831 	MLXSW_REG(sfmr),
12832 	MLXSW_REG(spvmlr),
12833 	MLXSW_REG(spvc),
12834 	MLXSW_REG(spevet),
12835 	MLXSW_REG(smpe),
12836 	MLXSW_REG(sftr2),
12837 	MLXSW_REG(smid2),
12838 	MLXSW_REG(cwtp),
12839 	MLXSW_REG(cwtpm),
12840 	MLXSW_REG(pgcr),
12841 	MLXSW_REG(ppbt),
12842 	MLXSW_REG(pacl),
12843 	MLXSW_REG(pagt),
12844 	MLXSW_REG(ptar),
12845 	MLXSW_REG(ppbs),
12846 	MLXSW_REG(prcr),
12847 	MLXSW_REG(pefa),
12848 	MLXSW_REG(pemrbt),
12849 	MLXSW_REG(ptce2),
12850 	MLXSW_REG(perpt),
12851 	MLXSW_REG(peabfe),
12852 	MLXSW_REG(perar),
12853 	MLXSW_REG(ptce3),
12854 	MLXSW_REG(percr),
12855 	MLXSW_REG(pererp),
12856 	MLXSW_REG(iedr),
12857 	MLXSW_REG(qpts),
12858 	MLXSW_REG(qpcr),
12859 	MLXSW_REG(qtct),
12860 	MLXSW_REG(qeec),
12861 	MLXSW_REG(qrwe),
12862 	MLXSW_REG(qpdsm),
12863 	MLXSW_REG(qpdp),
12864 	MLXSW_REG(qpdpm),
12865 	MLXSW_REG(qtctm),
12866 	MLXSW_REG(qpsc),
12867 	MLXSW_REG(pmlp),
12868 	MLXSW_REG(pmtu),
12869 	MLXSW_REG(ptys),
12870 	MLXSW_REG(ppad),
12871 	MLXSW_REG(paos),
12872 	MLXSW_REG(pfcc),
12873 	MLXSW_REG(ppcnt),
12874 	MLXSW_REG(pptb),
12875 	MLXSW_REG(pbmc),
12876 	MLXSW_REG(pspa),
12877 	MLXSW_REG(pmaos),
12878 	MLXSW_REG(pplr),
12879 	MLXSW_REG(pmtdb),
12880 	MLXSW_REG(pmecr),
12881 	MLXSW_REG(pmpe),
12882 	MLXSW_REG(pddr),
12883 	MLXSW_REG(pmmp),
12884 	MLXSW_REG(pllp),
12885 	MLXSW_REG(pmtm),
12886 	MLXSW_REG(htgt),
12887 	MLXSW_REG(hpkt),
12888 	MLXSW_REG(rgcr),
12889 	MLXSW_REG(ritr),
12890 	MLXSW_REG(rtar),
12891 	MLXSW_REG(ratr),
12892 	MLXSW_REG(rtdp),
12893 	MLXSW_REG(rips),
12894 	MLXSW_REG(ratrad),
12895 	MLXSW_REG(rdpm),
12896 	MLXSW_REG(ricnt),
12897 	MLXSW_REG(rrcr),
12898 	MLXSW_REG(ralta),
12899 	MLXSW_REG(ralst),
12900 	MLXSW_REG(raltb),
12901 	MLXSW_REG(ralue),
12902 	MLXSW_REG(rauht),
12903 	MLXSW_REG(raleu),
12904 	MLXSW_REG(rauhtd),
12905 	MLXSW_REG(rigr2),
12906 	MLXSW_REG(recr2),
12907 	MLXSW_REG(rmft2),
12908 	MLXSW_REG(reiv),
12909 	MLXSW_REG(mfcr),
12910 	MLXSW_REG(mfsc),
12911 	MLXSW_REG(mfsm),
12912 	MLXSW_REG(mfsl),
12913 	MLXSW_REG(fore),
12914 	MLXSW_REG(mtcap),
12915 	MLXSW_REG(mtmp),
12916 	MLXSW_REG(mtwe),
12917 	MLXSW_REG(mtbr),
12918 	MLXSW_REG(mcia),
12919 	MLXSW_REG(mpat),
12920 	MLXSW_REG(mpar),
12921 	MLXSW_REG(mgir),
12922 	MLXSW_REG(mrsr),
12923 	MLXSW_REG(mlcr),
12924 	MLXSW_REG(mcion),
12925 	MLXSW_REG(mtpps),
12926 	MLXSW_REG(mtutc),
12927 	MLXSW_REG(mpsc),
12928 	MLXSW_REG(mcqi),
12929 	MLXSW_REG(mcc),
12930 	MLXSW_REG(mcda),
12931 	MLXSW_REG(mgpc),
12932 	MLXSW_REG(mprs),
12933 	MLXSW_REG(mogcr),
12934 	MLXSW_REG(mpagr),
12935 	MLXSW_REG(momte),
12936 	MLXSW_REG(mtpppc),
12937 	MLXSW_REG(mtpptr),
12938 	MLXSW_REG(mtptpt),
12939 	MLXSW_REG(mtpcpc),
12940 	MLXSW_REG(mfgd),
12941 	MLXSW_REG(mgpir),
12942 	MLXSW_REG(mbct),
12943 	MLXSW_REG(mddt),
12944 	MLXSW_REG(mddq),
12945 	MLXSW_REG(mddc),
12946 	MLXSW_REG(mfde),
12947 	MLXSW_REG(tngcr),
12948 	MLXSW_REG(tnumt),
12949 	MLXSW_REG(tnqcr),
12950 	MLXSW_REG(tnqdr),
12951 	MLXSW_REG(tneem),
12952 	MLXSW_REG(tndem),
12953 	MLXSW_REG(tnpc),
12954 	MLXSW_REG(tigcr),
12955 	MLXSW_REG(tieem),
12956 	MLXSW_REG(tidem),
12957 	MLXSW_REG(sbpr),
12958 	MLXSW_REG(sbcm),
12959 	MLXSW_REG(sbpm),
12960 	MLXSW_REG(sbmm),
12961 	MLXSW_REG(sbsr),
12962 	MLXSW_REG(sbib),
12963 };
12964 
12965 static inline const char *mlxsw_reg_id_str(u16 reg_id)
12966 {
12967 	const struct mlxsw_reg_info *reg_info;
12968 	int i;
12969 
12970 	for (i = 0; i < ARRAY_SIZE(mlxsw_reg_infos); i++) {
12971 		reg_info = mlxsw_reg_infos[i];
12972 		if (reg_info->id == reg_id)
12973 			return reg_info->name;
12974 	}
12975 	return "*UNKNOWN*";
12976 }
12977 
12978 /* PUDE - Port Up / Down Event
12979  * ---------------------------
12980  * Reports the operational state change of a port.
12981  */
12982 #define MLXSW_REG_PUDE_LEN 0x10
12983 
12984 /* reg_pude_swid
12985  * Switch partition ID with which to associate the port.
12986  * Access: Index
12987  */
12988 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
12989 
12990 /* reg_pude_local_port
12991  * Local port number.
12992  * Access: Index
12993  */
12994 MLXSW_ITEM32_LP(reg, pude, 0x00, 16, 0x00, 12);
12995 
12996 /* reg_pude_admin_status
12997  * Port administrative state (the desired state).
12998  * 1 - Up.
12999  * 2 - Down.
13000  * 3 - Up once. This means that in case of link failure, the port won't go
13001  *     into polling mode, but will wait to be re-enabled by software.
13002  * 4 - Disabled by system. Can only be set by hardware.
13003  * Access: RO
13004  */
13005 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
13006 
13007 /* reg_pude_oper_status
13008  * Port operatioanl state.
13009  * 1 - Up.
13010  * 2 - Down.
13011  * 3 - Down by port failure. This means that the device will not let the
13012  *     port up again until explicitly specified by software.
13013  * Access: RO
13014  */
13015 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);
13016 
13017 #endif
13018