GNU Linux-libre 4.14.259-gnu1
[releases.git] / drivers / net / ethernet / mellanox / mlxsw / reg.h
1 /*
2  * drivers/net/ethernet/mellanox/mlxsw/reg.h
3  * Copyright (c) 2015-2017 Mellanox Technologies. All rights reserved.
4  * Copyright (c) 2015-2016 Ido Schimmel <idosch@mellanox.com>
5  * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
6  * Copyright (c) 2015-2017 Jiri Pirko <jiri@mellanox.com>
7  * Copyright (c) 2016 Yotam Gigi <yotamg@mellanox.com>
8  * Copyright (c) 2017 Petr Machata <petrm@mellanox.com>
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the names of the copyright holders nor the names of its
19  *    contributors may be used to endorse or promote products derived from
20  *    this software without specific prior written permission.
21  *
22  * Alternatively, this software may be distributed under the terms of the
23  * GNU General Public License ("GPL") version 2 as published by the Free
24  * Software Foundation.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38
39 #ifndef _MLXSW_REG_H
40 #define _MLXSW_REG_H
41
42 #include <linux/string.h>
43 #include <linux/bitops.h>
44 #include <linux/if_vlan.h>
45
46 #include "item.h"
47 #include "port.h"
48
49 struct mlxsw_reg_info {
50         u16 id;
51         u16 len; /* In u8 */
52         const char *name;
53 };
54
55 #define MLXSW_REG_DEFINE(_name, _id, _len)                              \
56 static const struct mlxsw_reg_info mlxsw_reg_##_name = {                \
57         .id = _id,                                                      \
58         .len = _len,                                                    \
59         .name = #_name,                                                 \
60 }
61
62 #define MLXSW_REG(type) (&mlxsw_reg_##type)
63 #define MLXSW_REG_LEN(type) MLXSW_REG(type)->len
64 #define MLXSW_REG_ZERO(type, payload) memset(payload, 0, MLXSW_REG(type)->len)
65
66 /* SGCR - Switch General Configuration Register
67  * --------------------------------------------
68  * This register is used for configuration of the switch capabilities.
69  */
70 #define MLXSW_REG_SGCR_ID 0x2000
71 #define MLXSW_REG_SGCR_LEN 0x10
72
73 MLXSW_REG_DEFINE(sgcr, MLXSW_REG_SGCR_ID, MLXSW_REG_SGCR_LEN);
74
75 /* reg_sgcr_llb
76  * Link Local Broadcast (Default=0)
77  * When set, all Link Local packets (224.0.0.X) will be treated as broadcast
78  * packets and ignore the IGMP snooping entries.
79  * Access: RW
80  */
81 MLXSW_ITEM32(reg, sgcr, llb, 0x04, 0, 1);
82
83 static inline void mlxsw_reg_sgcr_pack(char *payload, bool llb)
84 {
85         MLXSW_REG_ZERO(sgcr, payload);
86         mlxsw_reg_sgcr_llb_set(payload, !!llb);
87 }
88
89 /* SPAD - Switch Physical Address Register
90  * ---------------------------------------
91  * The SPAD register configures the switch physical MAC address.
92  */
93 #define MLXSW_REG_SPAD_ID 0x2002
94 #define MLXSW_REG_SPAD_LEN 0x10
95
96 MLXSW_REG_DEFINE(spad, MLXSW_REG_SPAD_ID, MLXSW_REG_SPAD_LEN);
97
98 /* reg_spad_base_mac
99  * Base MAC address for the switch partitions.
100  * Per switch partition MAC address is equal to:
101  * base_mac + swid
102  * Access: RW
103  */
104 MLXSW_ITEM_BUF(reg, spad, base_mac, 0x02, 6);
105
106 /* SMID - Switch Multicast ID
107  * --------------------------
108  * The MID record maps from a MID (Multicast ID), which is a unique identifier
109  * of the multicast group within the stacking domain, into a list of local
110  * ports into which the packet is replicated.
111  */
112 #define MLXSW_REG_SMID_ID 0x2007
113 #define MLXSW_REG_SMID_LEN 0x240
114
115 MLXSW_REG_DEFINE(smid, MLXSW_REG_SMID_ID, MLXSW_REG_SMID_LEN);
116
117 /* reg_smid_swid
118  * Switch partition ID.
119  * Access: Index
120  */
121 MLXSW_ITEM32(reg, smid, swid, 0x00, 24, 8);
122
123 /* reg_smid_mid
124  * Multicast identifier - global identifier that represents the multicast group
125  * across all devices.
126  * Access: Index
127  */
128 MLXSW_ITEM32(reg, smid, mid, 0x00, 0, 16);
129
130 /* reg_smid_port
131  * Local port memebership (1 bit per port).
132  * Access: RW
133  */
134 MLXSW_ITEM_BIT_ARRAY(reg, smid, port, 0x20, 0x20, 1);
135
136 /* reg_smid_port_mask
137  * Local port mask (1 bit per port).
138  * Access: W
139  */
140 MLXSW_ITEM_BIT_ARRAY(reg, smid, port_mask, 0x220, 0x20, 1);
141
142 static inline void mlxsw_reg_smid_pack(char *payload, u16 mid,
143                                        u8 port, bool set)
144 {
145         MLXSW_REG_ZERO(smid, payload);
146         mlxsw_reg_smid_swid_set(payload, 0);
147         mlxsw_reg_smid_mid_set(payload, mid);
148         mlxsw_reg_smid_port_set(payload, port, set);
149         mlxsw_reg_smid_port_mask_set(payload, port, 1);
150 }
151
152 /* SSPR - Switch System Port Record Register
153  * -----------------------------------------
154  * Configures the system port to local port mapping.
155  */
156 #define MLXSW_REG_SSPR_ID 0x2008
157 #define MLXSW_REG_SSPR_LEN 0x8
158
159 MLXSW_REG_DEFINE(sspr, MLXSW_REG_SSPR_ID, MLXSW_REG_SSPR_LEN);
160
161 /* reg_sspr_m
162  * Master - if set, then the record describes the master system port.
163  * This is needed in case a local port is mapped into several system ports
164  * (for multipathing). That number will be reported as the source system
165  * port when packets are forwarded to the CPU. Only one master port is allowed
166  * per local port.
167  *
168  * Note: Must be set for Spectrum.
169  * Access: RW
170  */
171 MLXSW_ITEM32(reg, sspr, m, 0x00, 31, 1);
172
173 /* reg_sspr_local_port
174  * Local port number.
175  *
176  * Access: RW
177  */
178 MLXSW_ITEM32(reg, sspr, local_port, 0x00, 16, 8);
179
180 /* reg_sspr_sub_port
181  * Virtual port within the physical port.
182  * Should be set to 0 when virtual ports are not enabled on the port.
183  *
184  * Access: RW
185  */
186 MLXSW_ITEM32(reg, sspr, sub_port, 0x00, 8, 8);
187
188 /* reg_sspr_system_port
189  * Unique identifier within the stacking domain that represents all the ports
190  * that are available in the system (external ports).
191  *
192  * Currently, only single-ASIC configurations are supported, so we default to
193  * 1:1 mapping between system ports and local ports.
194  * Access: Index
195  */
196 MLXSW_ITEM32(reg, sspr, system_port, 0x04, 0, 16);
197
198 static inline void mlxsw_reg_sspr_pack(char *payload, u8 local_port)
199 {
200         MLXSW_REG_ZERO(sspr, payload);
201         mlxsw_reg_sspr_m_set(payload, 1);
202         mlxsw_reg_sspr_local_port_set(payload, local_port);
203         mlxsw_reg_sspr_sub_port_set(payload, 0);
204         mlxsw_reg_sspr_system_port_set(payload, local_port);
205 }
206
207 /* SFDAT - Switch Filtering Database Aging Time
208  * --------------------------------------------
209  * Controls the Switch aging time. Aging time is able to be set per Switch
210  * Partition.
211  */
212 #define MLXSW_REG_SFDAT_ID 0x2009
213 #define MLXSW_REG_SFDAT_LEN 0x8
214
215 MLXSW_REG_DEFINE(sfdat, MLXSW_REG_SFDAT_ID, MLXSW_REG_SFDAT_LEN);
216
217 /* reg_sfdat_swid
218  * Switch partition ID.
219  * Access: Index
220  */
221 MLXSW_ITEM32(reg, sfdat, swid, 0x00, 24, 8);
222
223 /* reg_sfdat_age_time
224  * Aging time in seconds
225  * Min - 10 seconds
226  * Max - 1,000,000 seconds
227  * Default is 300 seconds.
228  * Access: RW
229  */
230 MLXSW_ITEM32(reg, sfdat, age_time, 0x04, 0, 20);
231
232 static inline void mlxsw_reg_sfdat_pack(char *payload, u32 age_time)
233 {
234         MLXSW_REG_ZERO(sfdat, payload);
235         mlxsw_reg_sfdat_swid_set(payload, 0);
236         mlxsw_reg_sfdat_age_time_set(payload, age_time);
237 }
238
239 /* SFD - Switch Filtering Database
240  * -------------------------------
241  * The following register defines the access to the filtering database.
242  * The register supports querying, adding, removing and modifying the database.
243  * The access is optimized for bulk updates in which case more than one
244  * FDB record is present in the same command.
245  */
246 #define MLXSW_REG_SFD_ID 0x200A
247 #define MLXSW_REG_SFD_BASE_LEN 0x10 /* base length, without records */
248 #define MLXSW_REG_SFD_REC_LEN 0x10 /* record length */
249 #define MLXSW_REG_SFD_REC_MAX_COUNT 64
250 #define MLXSW_REG_SFD_LEN (MLXSW_REG_SFD_BASE_LEN +     \
251                            MLXSW_REG_SFD_REC_LEN * MLXSW_REG_SFD_REC_MAX_COUNT)
252
253 MLXSW_REG_DEFINE(sfd, MLXSW_REG_SFD_ID, MLXSW_REG_SFD_LEN);
254
255 /* reg_sfd_swid
256  * Switch partition ID for queries. Reserved on Write.
257  * Access: Index
258  */
259 MLXSW_ITEM32(reg, sfd, swid, 0x00, 24, 8);
260
261 enum mlxsw_reg_sfd_op {
262         /* Dump entire FDB a (process according to record_locator) */
263         MLXSW_REG_SFD_OP_QUERY_DUMP = 0,
264         /* Query records by {MAC, VID/FID} value */
265         MLXSW_REG_SFD_OP_QUERY_QUERY = 1,
266         /* Query and clear activity. Query records by {MAC, VID/FID} value */
267         MLXSW_REG_SFD_OP_QUERY_QUERY_AND_CLEAR_ACTIVITY = 2,
268         /* Test. Response indicates if each of the records could be
269          * added to the FDB.
270          */
271         MLXSW_REG_SFD_OP_WRITE_TEST = 0,
272         /* Add/modify. Aged-out records cannot be added. This command removes
273          * the learning notification of the {MAC, VID/FID}. Response includes
274          * the entries that were added to the FDB.
275          */
276         MLXSW_REG_SFD_OP_WRITE_EDIT = 1,
277         /* Remove record by {MAC, VID/FID}. This command also removes
278          * the learning notification and aged-out notifications
279          * of the {MAC, VID/FID}. The response provides current (pre-removal)
280          * entries as non-aged-out.
281          */
282         MLXSW_REG_SFD_OP_WRITE_REMOVE = 2,
283         /* Remove learned notification by {MAC, VID/FID}. The response provides
284          * the removed learning notification.
285          */
286         MLXSW_REG_SFD_OP_WRITE_REMOVE_NOTIFICATION = 2,
287 };
288
289 /* reg_sfd_op
290  * Operation.
291  * Access: OP
292  */
293 MLXSW_ITEM32(reg, sfd, op, 0x04, 30, 2);
294
295 /* reg_sfd_record_locator
296  * Used for querying the FDB. Use record_locator=0 to initiate the
297  * query. When a record is returned, a new record_locator is
298  * returned to be used in the subsequent query.
299  * Reserved for database update.
300  * Access: Index
301  */
302 MLXSW_ITEM32(reg, sfd, record_locator, 0x04, 0, 30);
303
304 /* reg_sfd_num_rec
305  * Request: Number of records to read/add/modify/remove
306  * Response: Number of records read/added/replaced/removed
307  * See above description for more details.
308  * Ranges 0..64
309  * Access: RW
310  */
311 MLXSW_ITEM32(reg, sfd, num_rec, 0x08, 0, 8);
312
313 static inline void mlxsw_reg_sfd_pack(char *payload, enum mlxsw_reg_sfd_op op,
314                                       u32 record_locator)
315 {
316         MLXSW_REG_ZERO(sfd, payload);
317         mlxsw_reg_sfd_op_set(payload, op);
318         mlxsw_reg_sfd_record_locator_set(payload, record_locator);
319 }
320
321 /* reg_sfd_rec_swid
322  * Switch partition ID.
323  * Access: Index
324  */
325 MLXSW_ITEM32_INDEXED(reg, sfd, rec_swid, MLXSW_REG_SFD_BASE_LEN, 24, 8,
326                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
327
328 enum mlxsw_reg_sfd_rec_type {
329         MLXSW_REG_SFD_REC_TYPE_UNICAST = 0x0,
330         MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG = 0x1,
331         MLXSW_REG_SFD_REC_TYPE_MULTICAST = 0x2,
332 };
333
334 /* reg_sfd_rec_type
335  * FDB record type.
336  * Access: RW
337  */
338 MLXSW_ITEM32_INDEXED(reg, sfd, rec_type, MLXSW_REG_SFD_BASE_LEN, 20, 4,
339                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
340
341 enum mlxsw_reg_sfd_rec_policy {
342         /* Replacement disabled, aging disabled. */
343         MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY = 0,
344         /* (mlag remote): Replacement enabled, aging disabled,
345          * learning notification enabled on this port.
346          */
347         MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_MLAG = 1,
348         /* (ingress device): Replacement enabled, aging enabled. */
349         MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS = 3,
350 };
351
352 /* reg_sfd_rec_policy
353  * Policy.
354  * Access: RW
355  */
356 MLXSW_ITEM32_INDEXED(reg, sfd, rec_policy, MLXSW_REG_SFD_BASE_LEN, 18, 2,
357                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
358
359 /* reg_sfd_rec_a
360  * Activity. Set for new static entries. Set for static entries if a frame SMAC
361  * lookup hits on the entry.
362  * To clear the a bit, use "query and clear activity" op.
363  * Access: RO
364  */
365 MLXSW_ITEM32_INDEXED(reg, sfd, rec_a, MLXSW_REG_SFD_BASE_LEN, 16, 1,
366                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
367
368 /* reg_sfd_rec_mac
369  * MAC address.
370  * Access: Index
371  */
372 MLXSW_ITEM_BUF_INDEXED(reg, sfd, rec_mac, MLXSW_REG_SFD_BASE_LEN, 6,
373                        MLXSW_REG_SFD_REC_LEN, 0x02);
374
375 enum mlxsw_reg_sfd_rec_action {
376         /* forward */
377         MLXSW_REG_SFD_REC_ACTION_NOP = 0,
378         /* forward and trap, trap_id is FDB_TRAP */
379         MLXSW_REG_SFD_REC_ACTION_MIRROR_TO_CPU = 1,
380         /* trap and do not forward, trap_id is FDB_TRAP */
381         MLXSW_REG_SFD_REC_ACTION_TRAP = 2,
382         /* forward to IP router */
383         MLXSW_REG_SFD_REC_ACTION_FORWARD_IP_ROUTER = 3,
384         MLXSW_REG_SFD_REC_ACTION_DISCARD_ERROR = 15,
385 };
386
387 /* reg_sfd_rec_action
388  * Action to apply on the packet.
389  * Note: Dynamic entries can only be configured with NOP action.
390  * Access: RW
391  */
392 MLXSW_ITEM32_INDEXED(reg, sfd, rec_action, MLXSW_REG_SFD_BASE_LEN, 28, 4,
393                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
394
395 /* reg_sfd_uc_sub_port
396  * VEPA channel on local port.
397  * Valid only if local port is a non-stacking port. Must be 0 if multichannel
398  * VEPA is not enabled.
399  * Access: RW
400  */
401 MLXSW_ITEM32_INDEXED(reg, sfd, uc_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
402                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
403
404 /* reg_sfd_uc_fid_vid
405  * Filtering ID or VLAN ID
406  * For SwitchX and SwitchX-2:
407  * - Dynamic entries (policy 2,3) use FID
408  * - Static entries (policy 0) use VID
409  * - When independent learning is configured, VID=FID
410  * For Spectrum: use FID for both Dynamic and Static entries.
411  * VID should not be used.
412  * Access: Index
413  */
414 MLXSW_ITEM32_INDEXED(reg, sfd, uc_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
415                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
416
417 /* reg_sfd_uc_system_port
418  * Unique port identifier for the final destination of the packet.
419  * Access: RW
420  */
421 MLXSW_ITEM32_INDEXED(reg, sfd, uc_system_port, MLXSW_REG_SFD_BASE_LEN, 0, 16,
422                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
423
424 static inline void mlxsw_reg_sfd_rec_pack(char *payload, int rec_index,
425                                           enum mlxsw_reg_sfd_rec_type rec_type,
426                                           const char *mac,
427                                           enum mlxsw_reg_sfd_rec_action action)
428 {
429         u8 num_rec = mlxsw_reg_sfd_num_rec_get(payload);
430
431         if (rec_index >= num_rec)
432                 mlxsw_reg_sfd_num_rec_set(payload, rec_index + 1);
433         mlxsw_reg_sfd_rec_swid_set(payload, rec_index, 0);
434         mlxsw_reg_sfd_rec_type_set(payload, rec_index, rec_type);
435         mlxsw_reg_sfd_rec_mac_memcpy_to(payload, rec_index, mac);
436         mlxsw_reg_sfd_rec_action_set(payload, rec_index, action);
437 }
438
439 static inline void mlxsw_reg_sfd_uc_pack(char *payload, int rec_index,
440                                          enum mlxsw_reg_sfd_rec_policy policy,
441                                          const char *mac, u16 fid_vid,
442                                          enum mlxsw_reg_sfd_rec_action action,
443                                          u8 local_port)
444 {
445         mlxsw_reg_sfd_rec_pack(payload, rec_index,
446                                MLXSW_REG_SFD_REC_TYPE_UNICAST, mac, action);
447         mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
448         mlxsw_reg_sfd_uc_sub_port_set(payload, rec_index, 0);
449         mlxsw_reg_sfd_uc_fid_vid_set(payload, rec_index, fid_vid);
450         mlxsw_reg_sfd_uc_system_port_set(payload, rec_index, local_port);
451 }
452
453 static inline void mlxsw_reg_sfd_uc_unpack(char *payload, int rec_index,
454                                            char *mac, u16 *p_fid_vid,
455                                            u8 *p_local_port)
456 {
457         mlxsw_reg_sfd_rec_mac_memcpy_from(payload, rec_index, mac);
458         *p_fid_vid = mlxsw_reg_sfd_uc_fid_vid_get(payload, rec_index);
459         *p_local_port = mlxsw_reg_sfd_uc_system_port_get(payload, rec_index);
460 }
461
462 /* reg_sfd_uc_lag_sub_port
463  * LAG sub port.
464  * Must be 0 if multichannel VEPA is not enabled.
465  * Access: RW
466  */
467 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
468                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
469
470 /* reg_sfd_uc_lag_fid_vid
471  * Filtering ID or VLAN ID
472  * For SwitchX and SwitchX-2:
473  * - Dynamic entries (policy 2,3) use FID
474  * - Static entries (policy 0) use VID
475  * - When independent learning is configured, VID=FID
476  * For Spectrum: use FID for both Dynamic and Static entries.
477  * VID should not be used.
478  * Access: Index
479  */
480 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
481                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
482
483 /* reg_sfd_uc_lag_lag_vid
484  * Indicates VID in case of vFIDs. Reserved for FIDs.
485  * Access: RW
486  */
487 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_lag_vid, MLXSW_REG_SFD_BASE_LEN, 16, 12,
488                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
489
490 /* reg_sfd_uc_lag_lag_id
491  * LAG Identifier - pointer into the LAG descriptor table.
492  * Access: RW
493  */
494 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_lag_id, MLXSW_REG_SFD_BASE_LEN, 0, 10,
495                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
496
497 static inline void
498 mlxsw_reg_sfd_uc_lag_pack(char *payload, int rec_index,
499                           enum mlxsw_reg_sfd_rec_policy policy,
500                           const char *mac, u16 fid_vid,
501                           enum mlxsw_reg_sfd_rec_action action, u16 lag_vid,
502                           u16 lag_id)
503 {
504         mlxsw_reg_sfd_rec_pack(payload, rec_index,
505                                MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG,
506                                mac, action);
507         mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
508         mlxsw_reg_sfd_uc_lag_sub_port_set(payload, rec_index, 0);
509         mlxsw_reg_sfd_uc_lag_fid_vid_set(payload, rec_index, fid_vid);
510         mlxsw_reg_sfd_uc_lag_lag_vid_set(payload, rec_index, lag_vid);
511         mlxsw_reg_sfd_uc_lag_lag_id_set(payload, rec_index, lag_id);
512 }
513
514 static inline void mlxsw_reg_sfd_uc_lag_unpack(char *payload, int rec_index,
515                                                char *mac, u16 *p_vid,
516                                                u16 *p_lag_id)
517 {
518         mlxsw_reg_sfd_rec_mac_memcpy_from(payload, rec_index, mac);
519         *p_vid = mlxsw_reg_sfd_uc_lag_fid_vid_get(payload, rec_index);
520         *p_lag_id = mlxsw_reg_sfd_uc_lag_lag_id_get(payload, rec_index);
521 }
522
523 /* reg_sfd_mc_pgi
524  *
525  * Multicast port group index - index into the port group table.
526  * Value 0x1FFF indicates the pgi should point to the MID entry.
527  * For Spectrum this value must be set to 0x1FFF
528  * Access: RW
529  */
530 MLXSW_ITEM32_INDEXED(reg, sfd, mc_pgi, MLXSW_REG_SFD_BASE_LEN, 16, 13,
531                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
532
533 /* reg_sfd_mc_fid_vid
534  *
535  * Filtering ID or VLAN ID
536  * Access: Index
537  */
538 MLXSW_ITEM32_INDEXED(reg, sfd, mc_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
539                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
540
541 /* reg_sfd_mc_mid
542  *
543  * Multicast identifier - global identifier that represents the multicast
544  * group across all devices.
545  * Access: RW
546  */
547 MLXSW_ITEM32_INDEXED(reg, sfd, mc_mid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
548                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
549
550 static inline void
551 mlxsw_reg_sfd_mc_pack(char *payload, int rec_index,
552                       const char *mac, u16 fid_vid,
553                       enum mlxsw_reg_sfd_rec_action action, u16 mid)
554 {
555         mlxsw_reg_sfd_rec_pack(payload, rec_index,
556                                MLXSW_REG_SFD_REC_TYPE_MULTICAST, mac, action);
557         mlxsw_reg_sfd_mc_pgi_set(payload, rec_index, 0x1FFF);
558         mlxsw_reg_sfd_mc_fid_vid_set(payload, rec_index, fid_vid);
559         mlxsw_reg_sfd_mc_mid_set(payload, rec_index, mid);
560 }
561
562 /* SFN - Switch FDB Notification Register
563  * -------------------------------------------
564  * The switch provides notifications on newly learned FDB entries and
565  * aged out entries. The notifications can be polled by software.
566  */
567 #define MLXSW_REG_SFN_ID 0x200B
568 #define MLXSW_REG_SFN_BASE_LEN 0x10 /* base length, without records */
569 #define MLXSW_REG_SFN_REC_LEN 0x10 /* record length */
570 #define MLXSW_REG_SFN_REC_MAX_COUNT 64
571 #define MLXSW_REG_SFN_LEN (MLXSW_REG_SFN_BASE_LEN +     \
572                            MLXSW_REG_SFN_REC_LEN * MLXSW_REG_SFN_REC_MAX_COUNT)
573
574 MLXSW_REG_DEFINE(sfn, MLXSW_REG_SFN_ID, MLXSW_REG_SFN_LEN);
575
576 /* reg_sfn_swid
577  * Switch partition ID.
578  * Access: Index
579  */
580 MLXSW_ITEM32(reg, sfn, swid, 0x00, 24, 8);
581
582 /* reg_sfn_end
583  * Forces the current session to end.
584  * Access: OP
585  */
586 MLXSW_ITEM32(reg, sfn, end, 0x04, 20, 1);
587
588 /* reg_sfn_num_rec
589  * Request: Number of learned notifications and aged-out notification
590  * records requested.
591  * Response: Number of notification records returned (must be smaller
592  * than or equal to the value requested)
593  * Ranges 0..64
594  * Access: OP
595  */
596 MLXSW_ITEM32(reg, sfn, num_rec, 0x04, 0, 8);
597
598 static inline void mlxsw_reg_sfn_pack(char *payload)
599 {
600         MLXSW_REG_ZERO(sfn, payload);
601         mlxsw_reg_sfn_swid_set(payload, 0);
602         mlxsw_reg_sfn_end_set(payload, 1);
603         mlxsw_reg_sfn_num_rec_set(payload, MLXSW_REG_SFN_REC_MAX_COUNT);
604 }
605
606 /* reg_sfn_rec_swid
607  * Switch partition ID.
608  * Access: RO
609  */
610 MLXSW_ITEM32_INDEXED(reg, sfn, rec_swid, MLXSW_REG_SFN_BASE_LEN, 24, 8,
611                      MLXSW_REG_SFN_REC_LEN, 0x00, false);
612
613 enum mlxsw_reg_sfn_rec_type {
614         /* MAC addresses learned on a regular port. */
615         MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC = 0x5,
616         /* MAC addresses learned on a LAG port. */
617         MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG = 0x6,
618         /* Aged-out MAC address on a regular port. */
619         MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC = 0x7,
620         /* Aged-out MAC address on a LAG port. */
621         MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG = 0x8,
622 };
623
624 /* reg_sfn_rec_type
625  * Notification record type.
626  * Access: RO
627  */
628 MLXSW_ITEM32_INDEXED(reg, sfn, rec_type, MLXSW_REG_SFN_BASE_LEN, 20, 4,
629                      MLXSW_REG_SFN_REC_LEN, 0x00, false);
630
631 /* reg_sfn_rec_mac
632  * MAC address.
633  * Access: RO
634  */
635 MLXSW_ITEM_BUF_INDEXED(reg, sfn, rec_mac, MLXSW_REG_SFN_BASE_LEN, 6,
636                        MLXSW_REG_SFN_REC_LEN, 0x02);
637
638 /* reg_sfn_mac_sub_port
639  * VEPA channel on the local port.
640  * 0 if multichannel VEPA is not enabled.
641  * Access: RO
642  */
643 MLXSW_ITEM32_INDEXED(reg, sfn, mac_sub_port, MLXSW_REG_SFN_BASE_LEN, 16, 8,
644                      MLXSW_REG_SFN_REC_LEN, 0x08, false);
645
646 /* reg_sfn_mac_fid
647  * Filtering identifier.
648  * Access: RO
649  */
650 MLXSW_ITEM32_INDEXED(reg, sfn, mac_fid, MLXSW_REG_SFN_BASE_LEN, 0, 16,
651                      MLXSW_REG_SFN_REC_LEN, 0x08, false);
652
653 /* reg_sfn_mac_system_port
654  * Unique port identifier for the final destination of the packet.
655  * Access: RO
656  */
657 MLXSW_ITEM32_INDEXED(reg, sfn, mac_system_port, MLXSW_REG_SFN_BASE_LEN, 0, 16,
658                      MLXSW_REG_SFN_REC_LEN, 0x0C, false);
659
660 static inline void mlxsw_reg_sfn_mac_unpack(char *payload, int rec_index,
661                                             char *mac, u16 *p_vid,
662                                             u8 *p_local_port)
663 {
664         mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
665         *p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
666         *p_local_port = mlxsw_reg_sfn_mac_system_port_get(payload, rec_index);
667 }
668
669 /* reg_sfn_mac_lag_lag_id
670  * LAG ID (pointer into the LAG descriptor table).
671  * Access: RO
672  */
673 MLXSW_ITEM32_INDEXED(reg, sfn, mac_lag_lag_id, MLXSW_REG_SFN_BASE_LEN, 0, 10,
674                      MLXSW_REG_SFN_REC_LEN, 0x0C, false);
675
676 static inline void mlxsw_reg_sfn_mac_lag_unpack(char *payload, int rec_index,
677                                                 char *mac, u16 *p_vid,
678                                                 u16 *p_lag_id)
679 {
680         mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
681         *p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
682         *p_lag_id = mlxsw_reg_sfn_mac_lag_lag_id_get(payload, rec_index);
683 }
684
685 /* SPMS - Switch Port MSTP/RSTP State Register
686  * -------------------------------------------
687  * Configures the spanning tree state of a physical port.
688  */
689 #define MLXSW_REG_SPMS_ID 0x200D
690 #define MLXSW_REG_SPMS_LEN 0x404
691
692 MLXSW_REG_DEFINE(spms, MLXSW_REG_SPMS_ID, MLXSW_REG_SPMS_LEN);
693
694 /* reg_spms_local_port
695  * Local port number.
696  * Access: Index
697  */
698 MLXSW_ITEM32(reg, spms, local_port, 0x00, 16, 8);
699
700 enum mlxsw_reg_spms_state {
701         MLXSW_REG_SPMS_STATE_NO_CHANGE,
702         MLXSW_REG_SPMS_STATE_DISCARDING,
703         MLXSW_REG_SPMS_STATE_LEARNING,
704         MLXSW_REG_SPMS_STATE_FORWARDING,
705 };
706
707 /* reg_spms_state
708  * Spanning tree state of each VLAN ID (VID) of the local port.
709  * 0 - Do not change spanning tree state (used only when writing).
710  * 1 - Discarding. No learning or forwarding to/from this port (default).
711  * 2 - Learning. Port is learning, but not forwarding.
712  * 3 - Forwarding. Port is learning and forwarding.
713  * Access: RW
714  */
715 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
716
717 static inline void mlxsw_reg_spms_pack(char *payload, u8 local_port)
718 {
719         MLXSW_REG_ZERO(spms, payload);
720         mlxsw_reg_spms_local_port_set(payload, local_port);
721 }
722
723 static inline void mlxsw_reg_spms_vid_pack(char *payload, u16 vid,
724                                            enum mlxsw_reg_spms_state state)
725 {
726         mlxsw_reg_spms_state_set(payload, vid, state);
727 }
728
729 /* SPVID - Switch Port VID
730  * -----------------------
731  * The switch port VID configures the default VID for a port.
732  */
733 #define MLXSW_REG_SPVID_ID 0x200E
734 #define MLXSW_REG_SPVID_LEN 0x08
735
736 MLXSW_REG_DEFINE(spvid, MLXSW_REG_SPVID_ID, MLXSW_REG_SPVID_LEN);
737
738 /* reg_spvid_local_port
739  * Local port number.
740  * Access: Index
741  */
742 MLXSW_ITEM32(reg, spvid, local_port, 0x00, 16, 8);
743
744 /* reg_spvid_sub_port
745  * Virtual port within the physical port.
746  * Should be set to 0 when virtual ports are not enabled on the port.
747  * Access: Index
748  */
749 MLXSW_ITEM32(reg, spvid, sub_port, 0x00, 8, 8);
750
751 /* reg_spvid_pvid
752  * Port default VID
753  * Access: RW
754  */
755 MLXSW_ITEM32(reg, spvid, pvid, 0x04, 0, 12);
756
757 static inline void mlxsw_reg_spvid_pack(char *payload, u8 local_port, u16 pvid)
758 {
759         MLXSW_REG_ZERO(spvid, payload);
760         mlxsw_reg_spvid_local_port_set(payload, local_port);
761         mlxsw_reg_spvid_pvid_set(payload, pvid);
762 }
763
764 /* SPVM - Switch Port VLAN Membership
765  * ----------------------------------
766  * The Switch Port VLAN Membership register configures the VLAN membership
767  * of a port in a VLAN denoted by VID. VLAN membership is managed per
768  * virtual port. The register can be used to add and remove VID(s) from a port.
769  */
770 #define MLXSW_REG_SPVM_ID 0x200F
771 #define MLXSW_REG_SPVM_BASE_LEN 0x04 /* base length, without records */
772 #define MLXSW_REG_SPVM_REC_LEN 0x04 /* record length */
773 #define MLXSW_REG_SPVM_REC_MAX_COUNT 255
774 #define MLXSW_REG_SPVM_LEN (MLXSW_REG_SPVM_BASE_LEN +   \
775                     MLXSW_REG_SPVM_REC_LEN * MLXSW_REG_SPVM_REC_MAX_COUNT)
776
777 MLXSW_REG_DEFINE(spvm, MLXSW_REG_SPVM_ID, MLXSW_REG_SPVM_LEN);
778
779 /* reg_spvm_pt
780  * Priority tagged. If this bit is set, packets forwarded to the port with
781  * untagged VLAN membership (u bit is set) will be tagged with priority tag
782  * (VID=0)
783  * Access: RW
784  */
785 MLXSW_ITEM32(reg, spvm, pt, 0x00, 31, 1);
786
787 /* reg_spvm_pte
788  * Priority Tagged Update Enable. On Write operations, if this bit is cleared,
789  * the pt bit will NOT be updated. To update the pt bit, pte must be set.
790  * Access: WO
791  */
792 MLXSW_ITEM32(reg, spvm, pte, 0x00, 30, 1);
793
794 /* reg_spvm_local_port
795  * Local port number.
796  * Access: Index
797  */
798 MLXSW_ITEM32(reg, spvm, local_port, 0x00, 16, 8);
799
800 /* reg_spvm_sub_port
801  * Virtual port within the physical port.
802  * Should be set to 0 when virtual ports are not enabled on the port.
803  * Access: Index
804  */
805 MLXSW_ITEM32(reg, spvm, sub_port, 0x00, 8, 8);
806
807 /* reg_spvm_num_rec
808  * Number of records to update. Each record contains: i, e, u, vid.
809  * Access: OP
810  */
811 MLXSW_ITEM32(reg, spvm, num_rec, 0x00, 0, 8);
812
813 /* reg_spvm_rec_i
814  * Ingress membership in VLAN ID.
815  * Access: Index
816  */
817 MLXSW_ITEM32_INDEXED(reg, spvm, rec_i,
818                      MLXSW_REG_SPVM_BASE_LEN, 14, 1,
819                      MLXSW_REG_SPVM_REC_LEN, 0, false);
820
821 /* reg_spvm_rec_e
822  * Egress membership in VLAN ID.
823  * Access: Index
824  */
825 MLXSW_ITEM32_INDEXED(reg, spvm, rec_e,
826                      MLXSW_REG_SPVM_BASE_LEN, 13, 1,
827                      MLXSW_REG_SPVM_REC_LEN, 0, false);
828
829 /* reg_spvm_rec_u
830  * Untagged - port is an untagged member - egress transmission uses untagged
831  * frames on VID<n>
832  * Access: Index
833  */
834 MLXSW_ITEM32_INDEXED(reg, spvm, rec_u,
835                      MLXSW_REG_SPVM_BASE_LEN, 12, 1,
836                      MLXSW_REG_SPVM_REC_LEN, 0, false);
837
838 /* reg_spvm_rec_vid
839  * Egress membership in VLAN ID.
840  * Access: Index
841  */
842 MLXSW_ITEM32_INDEXED(reg, spvm, rec_vid,
843                      MLXSW_REG_SPVM_BASE_LEN, 0, 12,
844                      MLXSW_REG_SPVM_REC_LEN, 0, false);
845
846 static inline void mlxsw_reg_spvm_pack(char *payload, u8 local_port,
847                                        u16 vid_begin, u16 vid_end,
848                                        bool is_member, bool untagged)
849 {
850         int size = vid_end - vid_begin + 1;
851         int i;
852
853         MLXSW_REG_ZERO(spvm, payload);
854         mlxsw_reg_spvm_local_port_set(payload, local_port);
855         mlxsw_reg_spvm_num_rec_set(payload, size);
856
857         for (i = 0; i < size; i++) {
858                 mlxsw_reg_spvm_rec_i_set(payload, i, is_member);
859                 mlxsw_reg_spvm_rec_e_set(payload, i, is_member);
860                 mlxsw_reg_spvm_rec_u_set(payload, i, untagged);
861                 mlxsw_reg_spvm_rec_vid_set(payload, i, vid_begin + i);
862         }
863 }
864
865 /* SPAFT - Switch Port Acceptable Frame Types
866  * ------------------------------------------
867  * The Switch Port Acceptable Frame Types register configures the frame
868  * admittance of the port.
869  */
870 #define MLXSW_REG_SPAFT_ID 0x2010
871 #define MLXSW_REG_SPAFT_LEN 0x08
872
873 MLXSW_REG_DEFINE(spaft, MLXSW_REG_SPAFT_ID, MLXSW_REG_SPAFT_LEN);
874
875 /* reg_spaft_local_port
876  * Local port number.
877  * Access: Index
878  *
879  * Note: CPU port is not supported (all tag types are allowed).
880  */
881 MLXSW_ITEM32(reg, spaft, local_port, 0x00, 16, 8);
882
883 /* reg_spaft_sub_port
884  * Virtual port within the physical port.
885  * Should be set to 0 when virtual ports are not enabled on the port.
886  * Access: RW
887  */
888 MLXSW_ITEM32(reg, spaft, sub_port, 0x00, 8, 8);
889
890 /* reg_spaft_allow_untagged
891  * When set, untagged frames on the ingress are allowed (default).
892  * Access: RW
893  */
894 MLXSW_ITEM32(reg, spaft, allow_untagged, 0x04, 31, 1);
895
896 /* reg_spaft_allow_prio_tagged
897  * When set, priority tagged frames on the ingress are allowed (default).
898  * Access: RW
899  */
900 MLXSW_ITEM32(reg, spaft, allow_prio_tagged, 0x04, 30, 1);
901
902 /* reg_spaft_allow_tagged
903  * When set, tagged frames on the ingress are allowed (default).
904  * Access: RW
905  */
906 MLXSW_ITEM32(reg, spaft, allow_tagged, 0x04, 29, 1);
907
908 static inline void mlxsw_reg_spaft_pack(char *payload, u8 local_port,
909                                         bool allow_untagged)
910 {
911         MLXSW_REG_ZERO(spaft, payload);
912         mlxsw_reg_spaft_local_port_set(payload, local_port);
913         mlxsw_reg_spaft_allow_untagged_set(payload, allow_untagged);
914         mlxsw_reg_spaft_allow_prio_tagged_set(payload, allow_untagged);
915         mlxsw_reg_spaft_allow_tagged_set(payload, true);
916 }
917
918 /* SFGC - Switch Flooding Group Configuration
919  * ------------------------------------------
920  * The following register controls the association of flooding tables and MIDs
921  * to packet types used for flooding.
922  */
923 #define MLXSW_REG_SFGC_ID 0x2011
924 #define MLXSW_REG_SFGC_LEN 0x10
925
926 MLXSW_REG_DEFINE(sfgc, MLXSW_REG_SFGC_ID, MLXSW_REG_SFGC_LEN);
927
928 enum mlxsw_reg_sfgc_type {
929         MLXSW_REG_SFGC_TYPE_BROADCAST,
930         MLXSW_REG_SFGC_TYPE_UNKNOWN_UNICAST,
931         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4,
932         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6,
933         MLXSW_REG_SFGC_TYPE_RESERVED,
934         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP,
935         MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL,
936         MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST,
937         MLXSW_REG_SFGC_TYPE_MAX,
938 };
939
940 /* reg_sfgc_type
941  * The traffic type to reach the flooding table.
942  * Access: Index
943  */
944 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
945
946 enum mlxsw_reg_sfgc_bridge_type {
947         MLXSW_REG_SFGC_BRIDGE_TYPE_1Q_FID = 0,
948         MLXSW_REG_SFGC_BRIDGE_TYPE_VFID = 1,
949 };
950
951 /* reg_sfgc_bridge_type
952  * Access: Index
953  *
954  * Note: SwitchX-2 only supports 802.1Q mode.
955  */
956 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
957
958 enum mlxsw_flood_table_type {
959         MLXSW_REG_SFGC_TABLE_TYPE_VID = 1,
960         MLXSW_REG_SFGC_TABLE_TYPE_SINGLE = 2,
961         MLXSW_REG_SFGC_TABLE_TYPE_ANY = 0,
962         MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFSET = 3,
963         MLXSW_REG_SFGC_TABLE_TYPE_FID = 4,
964 };
965
966 /* reg_sfgc_table_type
967  * See mlxsw_flood_table_type
968  * Access: RW
969  *
970  * Note: FID offset and FID types are not supported in SwitchX-2.
971  */
972 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
973
974 /* reg_sfgc_flood_table
975  * Flooding table index to associate with the specific type on the specific
976  * switch partition.
977  * Access: RW
978  */
979 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
980
981 /* reg_sfgc_mid
982  * The multicast ID for the swid. Not supported for Spectrum
983  * Access: RW
984  */
985 MLXSW_ITEM32(reg, sfgc, mid, 0x08, 0, 16);
986
987 /* reg_sfgc_counter_set_type
988  * Counter Set Type for flow counters.
989  * Access: RW
990  */
991 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
992
993 /* reg_sfgc_counter_index
994  * Counter Index for flow counters.
995  * Access: RW
996  */
997 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
998
999 static inline void
1000 mlxsw_reg_sfgc_pack(char *payload, enum mlxsw_reg_sfgc_type type,
1001                     enum mlxsw_reg_sfgc_bridge_type bridge_type,
1002                     enum mlxsw_flood_table_type table_type,
1003                     unsigned int flood_table)
1004 {
1005         MLXSW_REG_ZERO(sfgc, payload);
1006         mlxsw_reg_sfgc_type_set(payload, type);
1007         mlxsw_reg_sfgc_bridge_type_set(payload, bridge_type);
1008         mlxsw_reg_sfgc_table_type_set(payload, table_type);
1009         mlxsw_reg_sfgc_flood_table_set(payload, flood_table);
1010         mlxsw_reg_sfgc_mid_set(payload, MLXSW_PORT_MID);
1011 }
1012
1013 /* SFTR - Switch Flooding Table Register
1014  * -------------------------------------
1015  * The switch flooding table is used for flooding packet replication. The table
1016  * defines a bit mask of ports for packet replication.
1017  */
1018 #define MLXSW_REG_SFTR_ID 0x2012
1019 #define MLXSW_REG_SFTR_LEN 0x420
1020
1021 MLXSW_REG_DEFINE(sftr, MLXSW_REG_SFTR_ID, MLXSW_REG_SFTR_LEN);
1022
1023 /* reg_sftr_swid
1024  * Switch partition ID with which to associate the port.
1025  * Access: Index
1026  */
1027 MLXSW_ITEM32(reg, sftr, swid, 0x00, 24, 8);
1028
1029 /* reg_sftr_flood_table
1030  * Flooding table index to associate with the specific type on the specific
1031  * switch partition.
1032  * Access: Index
1033  */
1034 MLXSW_ITEM32(reg, sftr, flood_table, 0x00, 16, 6);
1035
1036 /* reg_sftr_index
1037  * Index. Used as an index into the Flooding Table in case the table is
1038  * configured to use VID / FID or FID Offset.
1039  * Access: Index
1040  */
1041 MLXSW_ITEM32(reg, sftr, index, 0x00, 0, 16);
1042
1043 /* reg_sftr_table_type
1044  * See mlxsw_flood_table_type
1045  * Access: RW
1046  */
1047 MLXSW_ITEM32(reg, sftr, table_type, 0x04, 16, 3);
1048
1049 /* reg_sftr_range
1050  * Range of entries to update
1051  * Access: Index
1052  */
1053 MLXSW_ITEM32(reg, sftr, range, 0x04, 0, 16);
1054
1055 /* reg_sftr_port
1056  * Local port membership (1 bit per port).
1057  * Access: RW
1058  */
1059 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port, 0x20, 0x20, 1);
1060
1061 /* reg_sftr_cpu_port_mask
1062  * CPU port mask (1 bit per port).
1063  * Access: W
1064  */
1065 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port_mask, 0x220, 0x20, 1);
1066
1067 static inline void mlxsw_reg_sftr_pack(char *payload,
1068                                        unsigned int flood_table,
1069                                        unsigned int index,
1070                                        enum mlxsw_flood_table_type table_type,
1071                                        unsigned int range, u8 port, bool set)
1072 {
1073         MLXSW_REG_ZERO(sftr, payload);
1074         mlxsw_reg_sftr_swid_set(payload, 0);
1075         mlxsw_reg_sftr_flood_table_set(payload, flood_table);
1076         mlxsw_reg_sftr_index_set(payload, index);
1077         mlxsw_reg_sftr_table_type_set(payload, table_type);
1078         mlxsw_reg_sftr_range_set(payload, range);
1079         mlxsw_reg_sftr_port_set(payload, port, set);
1080         mlxsw_reg_sftr_port_mask_set(payload, port, 1);
1081 }
1082
1083 /* SFDF - Switch Filtering DB Flush
1084  * --------------------------------
1085  * The switch filtering DB flush register is used to flush the FDB.
1086  * Note that FDB notifications are flushed as well.
1087  */
1088 #define MLXSW_REG_SFDF_ID 0x2013
1089 #define MLXSW_REG_SFDF_LEN 0x14
1090
1091 MLXSW_REG_DEFINE(sfdf, MLXSW_REG_SFDF_ID, MLXSW_REG_SFDF_LEN);
1092
1093 /* reg_sfdf_swid
1094  * Switch partition ID.
1095  * Access: Index
1096  */
1097 MLXSW_ITEM32(reg, sfdf, swid, 0x00, 24, 8);
1098
1099 enum mlxsw_reg_sfdf_flush_type {
1100         MLXSW_REG_SFDF_FLUSH_PER_SWID,
1101         MLXSW_REG_SFDF_FLUSH_PER_FID,
1102         MLXSW_REG_SFDF_FLUSH_PER_PORT,
1103         MLXSW_REG_SFDF_FLUSH_PER_PORT_AND_FID,
1104         MLXSW_REG_SFDF_FLUSH_PER_LAG,
1105         MLXSW_REG_SFDF_FLUSH_PER_LAG_AND_FID,
1106 };
1107
1108 /* reg_sfdf_flush_type
1109  * Flush type.
1110  * 0 - All SWID dynamic entries are flushed.
1111  * 1 - All FID dynamic entries are flushed.
1112  * 2 - All dynamic entries pointing to port are flushed.
1113  * 3 - All FID dynamic entries pointing to port are flushed.
1114  * 4 - All dynamic entries pointing to LAG are flushed.
1115  * 5 - All FID dynamic entries pointing to LAG are flushed.
1116  * Access: RW
1117  */
1118 MLXSW_ITEM32(reg, sfdf, flush_type, 0x04, 28, 4);
1119
1120 /* reg_sfdf_flush_static
1121  * Static.
1122  * 0 - Flush only dynamic entries.
1123  * 1 - Flush both dynamic and static entries.
1124  * Access: RW
1125  */
1126 MLXSW_ITEM32(reg, sfdf, flush_static, 0x04, 24, 1);
1127
1128 static inline void mlxsw_reg_sfdf_pack(char *payload,
1129                                        enum mlxsw_reg_sfdf_flush_type type)
1130 {
1131         MLXSW_REG_ZERO(sfdf, payload);
1132         mlxsw_reg_sfdf_flush_type_set(payload, type);
1133         mlxsw_reg_sfdf_flush_static_set(payload, true);
1134 }
1135
1136 /* reg_sfdf_fid
1137  * FID to flush.
1138  * Access: RW
1139  */
1140 MLXSW_ITEM32(reg, sfdf, fid, 0x0C, 0, 16);
1141
1142 /* reg_sfdf_system_port
1143  * Port to flush.
1144  * Access: RW
1145  */
1146 MLXSW_ITEM32(reg, sfdf, system_port, 0x0C, 0, 16);
1147
1148 /* reg_sfdf_port_fid_system_port
1149  * Port to flush, pointed to by FID.
1150  * Access: RW
1151  */
1152 MLXSW_ITEM32(reg, sfdf, port_fid_system_port, 0x08, 0, 16);
1153
1154 /* reg_sfdf_lag_id
1155  * LAG ID to flush.
1156  * Access: RW
1157  */
1158 MLXSW_ITEM32(reg, sfdf, lag_id, 0x0C, 0, 10);
1159
1160 /* reg_sfdf_lag_fid_lag_id
1161  * LAG ID to flush, pointed to by FID.
1162  * Access: RW
1163  */
1164 MLXSW_ITEM32(reg, sfdf, lag_fid_lag_id, 0x08, 0, 10);
1165
1166 /* SLDR - Switch LAG Descriptor Register
1167  * -----------------------------------------
1168  * The switch LAG descriptor register is populated by LAG descriptors.
1169  * Each LAG descriptor is indexed by lag_id. The LAG ID runs from 0 to
1170  * max_lag-1.
1171  */
1172 #define MLXSW_REG_SLDR_ID 0x2014
1173 #define MLXSW_REG_SLDR_LEN 0x0C /* counting in only one port in list */
1174
1175 MLXSW_REG_DEFINE(sldr, MLXSW_REG_SLDR_ID, MLXSW_REG_SLDR_LEN);
1176
1177 enum mlxsw_reg_sldr_op {
1178         /* Indicates a creation of a new LAG-ID, lag_id must be valid */
1179         MLXSW_REG_SLDR_OP_LAG_CREATE,
1180         MLXSW_REG_SLDR_OP_LAG_DESTROY,
1181         /* Ports that appear in the list have the Distributor enabled */
1182         MLXSW_REG_SLDR_OP_LAG_ADD_PORT_LIST,
1183         /* Removes ports from the disributor list */
1184         MLXSW_REG_SLDR_OP_LAG_REMOVE_PORT_LIST,
1185 };
1186
1187 /* reg_sldr_op
1188  * Operation.
1189  * Access: RW
1190  */
1191 MLXSW_ITEM32(reg, sldr, op, 0x00, 29, 3);
1192
1193 /* reg_sldr_lag_id
1194  * LAG identifier. The lag_id is the index into the LAG descriptor table.
1195  * Access: Index
1196  */
1197 MLXSW_ITEM32(reg, sldr, lag_id, 0x00, 0, 10);
1198
1199 static inline void mlxsw_reg_sldr_lag_create_pack(char *payload, u8 lag_id)
1200 {
1201         MLXSW_REG_ZERO(sldr, payload);
1202         mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_CREATE);
1203         mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1204 }
1205
1206 static inline void mlxsw_reg_sldr_lag_destroy_pack(char *payload, u8 lag_id)
1207 {
1208         MLXSW_REG_ZERO(sldr, payload);
1209         mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_DESTROY);
1210         mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1211 }
1212
1213 /* reg_sldr_num_ports
1214  * The number of member ports of the LAG.
1215  * Reserved for Create / Destroy operations
1216  * For Add / Remove operations - indicates the number of ports in the list.
1217  * Access: RW
1218  */
1219 MLXSW_ITEM32(reg, sldr, num_ports, 0x04, 24, 8);
1220
1221 /* reg_sldr_system_port
1222  * System port.
1223  * Access: RW
1224  */
1225 MLXSW_ITEM32_INDEXED(reg, sldr, system_port, 0x08, 0, 16, 4, 0, false);
1226
1227 static inline void mlxsw_reg_sldr_lag_add_port_pack(char *payload, u8 lag_id,
1228                                                     u8 local_port)
1229 {
1230         MLXSW_REG_ZERO(sldr, payload);
1231         mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_ADD_PORT_LIST);
1232         mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1233         mlxsw_reg_sldr_num_ports_set(payload, 1);
1234         mlxsw_reg_sldr_system_port_set(payload, 0, local_port);
1235 }
1236
1237 static inline void mlxsw_reg_sldr_lag_remove_port_pack(char *payload, u8 lag_id,
1238                                                        u8 local_port)
1239 {
1240         MLXSW_REG_ZERO(sldr, payload);
1241         mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_REMOVE_PORT_LIST);
1242         mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1243         mlxsw_reg_sldr_num_ports_set(payload, 1);
1244         mlxsw_reg_sldr_system_port_set(payload, 0, local_port);
1245 }
1246
1247 /* SLCR - Switch LAG Configuration 2 Register
1248  * -------------------------------------------
1249  * The Switch LAG Configuration register is used for configuring the
1250  * LAG properties of the switch.
1251  */
1252 #define MLXSW_REG_SLCR_ID 0x2015
1253 #define MLXSW_REG_SLCR_LEN 0x10
1254
1255 MLXSW_REG_DEFINE(slcr, MLXSW_REG_SLCR_ID, MLXSW_REG_SLCR_LEN);
1256
1257 enum mlxsw_reg_slcr_pp {
1258         /* Global Configuration (for all ports) */
1259         MLXSW_REG_SLCR_PP_GLOBAL,
1260         /* Per port configuration, based on local_port field */
1261         MLXSW_REG_SLCR_PP_PER_PORT,
1262 };
1263
1264 /* reg_slcr_pp
1265  * Per Port Configuration
1266  * Note: Reading at Global mode results in reading port 1 configuration.
1267  * Access: Index
1268  */
1269 MLXSW_ITEM32(reg, slcr, pp, 0x00, 24, 1);
1270
1271 /* reg_slcr_local_port
1272  * Local port number
1273  * Supported from CPU port
1274  * Not supported from router port
1275  * Reserved when pp = Global Configuration
1276  * Access: Index
1277  */
1278 MLXSW_ITEM32(reg, slcr, local_port, 0x00, 16, 8);
1279
1280 enum mlxsw_reg_slcr_type {
1281         MLXSW_REG_SLCR_TYPE_CRC, /* default */
1282         MLXSW_REG_SLCR_TYPE_XOR,
1283         MLXSW_REG_SLCR_TYPE_RANDOM,
1284 };
1285
1286 /* reg_slcr_type
1287  * Hash type
1288  * Access: RW
1289  */
1290 MLXSW_ITEM32(reg, slcr, type, 0x00, 0, 4);
1291
1292 /* Ingress port */
1293 #define MLXSW_REG_SLCR_LAG_HASH_IN_PORT         BIT(0)
1294 /* SMAC - for IPv4 and IPv6 packets */
1295 #define MLXSW_REG_SLCR_LAG_HASH_SMAC_IP         BIT(1)
1296 /* SMAC - for non-IP packets */
1297 #define MLXSW_REG_SLCR_LAG_HASH_SMAC_NONIP      BIT(2)
1298 #define MLXSW_REG_SLCR_LAG_HASH_SMAC \
1299         (MLXSW_REG_SLCR_LAG_HASH_SMAC_IP | \
1300          MLXSW_REG_SLCR_LAG_HASH_SMAC_NONIP)
1301 /* DMAC - for IPv4 and IPv6 packets */
1302 #define MLXSW_REG_SLCR_LAG_HASH_DMAC_IP         BIT(3)
1303 /* DMAC - for non-IP packets */
1304 #define MLXSW_REG_SLCR_LAG_HASH_DMAC_NONIP      BIT(4)
1305 #define MLXSW_REG_SLCR_LAG_HASH_DMAC \
1306         (MLXSW_REG_SLCR_LAG_HASH_DMAC_IP | \
1307          MLXSW_REG_SLCR_LAG_HASH_DMAC_NONIP)
1308 /* Ethertype - for IPv4 and IPv6 packets */
1309 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_IP    BIT(5)
1310 /* Ethertype - for non-IP packets */
1311 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_NONIP BIT(6)
1312 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE \
1313         (MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_IP | \
1314          MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_NONIP)
1315 /* VLAN ID - for IPv4 and IPv6 packets */
1316 #define MLXSW_REG_SLCR_LAG_HASH_VLANID_IP       BIT(7)
1317 /* VLAN ID - for non-IP packets */
1318 #define MLXSW_REG_SLCR_LAG_HASH_VLANID_NONIP    BIT(8)
1319 #define MLXSW_REG_SLCR_LAG_HASH_VLANID \
1320         (MLXSW_REG_SLCR_LAG_HASH_VLANID_IP | \
1321          MLXSW_REG_SLCR_LAG_HASH_VLANID_NONIP)
1322 /* Source IP address (can be IPv4 or IPv6) */
1323 #define MLXSW_REG_SLCR_LAG_HASH_SIP             BIT(9)
1324 /* Destination IP address (can be IPv4 or IPv6) */
1325 #define MLXSW_REG_SLCR_LAG_HASH_DIP             BIT(10)
1326 /* TCP/UDP source port */
1327 #define MLXSW_REG_SLCR_LAG_HASH_SPORT           BIT(11)
1328 /* TCP/UDP destination port*/
1329 #define MLXSW_REG_SLCR_LAG_HASH_DPORT           BIT(12)
1330 /* IPv4 Protocol/IPv6 Next Header */
1331 #define MLXSW_REG_SLCR_LAG_HASH_IPPROTO         BIT(13)
1332 /* IPv6 Flow label */
1333 #define MLXSW_REG_SLCR_LAG_HASH_FLOWLABEL       BIT(14)
1334 /* SID - FCoE source ID */
1335 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_SID        BIT(15)
1336 /* DID - FCoE destination ID */
1337 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_DID        BIT(16)
1338 /* OXID - FCoE originator exchange ID */
1339 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_OXID       BIT(17)
1340 /* Destination QP number - for RoCE packets */
1341 #define MLXSW_REG_SLCR_LAG_HASH_ROCE_DQP        BIT(19)
1342
1343 /* reg_slcr_lag_hash
1344  * LAG hashing configuration. This is a bitmask, in which each set
1345  * bit includes the corresponding item in the LAG hash calculation.
1346  * The default lag_hash contains SMAC, DMAC, VLANID and
1347  * Ethertype (for all packet types).
1348  * Access: RW
1349  */
1350 MLXSW_ITEM32(reg, slcr, lag_hash, 0x04, 0, 20);
1351
1352 static inline void mlxsw_reg_slcr_pack(char *payload, u16 lag_hash)
1353 {
1354         MLXSW_REG_ZERO(slcr, payload);
1355         mlxsw_reg_slcr_pp_set(payload, MLXSW_REG_SLCR_PP_GLOBAL);
1356         mlxsw_reg_slcr_type_set(payload, MLXSW_REG_SLCR_TYPE_CRC);
1357         mlxsw_reg_slcr_lag_hash_set(payload, lag_hash);
1358 }
1359
1360 /* SLCOR - Switch LAG Collector Register
1361  * -------------------------------------
1362  * The Switch LAG Collector register controls the Local Port membership
1363  * in a LAG and enablement of the collector.
1364  */
1365 #define MLXSW_REG_SLCOR_ID 0x2016
1366 #define MLXSW_REG_SLCOR_LEN 0x10
1367
1368 MLXSW_REG_DEFINE(slcor, MLXSW_REG_SLCOR_ID, MLXSW_REG_SLCOR_LEN);
1369
1370 enum mlxsw_reg_slcor_col {
1371         /* Port is added with collector disabled */
1372         MLXSW_REG_SLCOR_COL_LAG_ADD_PORT,
1373         MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED,
1374         MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_DISABLED,
1375         MLXSW_REG_SLCOR_COL_LAG_REMOVE_PORT,
1376 };
1377
1378 /* reg_slcor_col
1379  * Collector configuration
1380  * Access: RW
1381  */
1382 MLXSW_ITEM32(reg, slcor, col, 0x00, 30, 2);
1383
1384 /* reg_slcor_local_port
1385  * Local port number
1386  * Not supported for CPU port
1387  * Access: Index
1388  */
1389 MLXSW_ITEM32(reg, slcor, local_port, 0x00, 16, 8);
1390
1391 /* reg_slcor_lag_id
1392  * LAG Identifier. Index into the LAG descriptor table.
1393  * Access: Index
1394  */
1395 MLXSW_ITEM32(reg, slcor, lag_id, 0x00, 0, 10);
1396
1397 /* reg_slcor_port_index
1398  * Port index in the LAG list. Only valid on Add Port to LAG col.
1399  * Valid range is from 0 to cap_max_lag_members-1
1400  * Access: RW
1401  */
1402 MLXSW_ITEM32(reg, slcor, port_index, 0x04, 0, 10);
1403
1404 static inline void mlxsw_reg_slcor_pack(char *payload,
1405                                         u8 local_port, u16 lag_id,
1406                                         enum mlxsw_reg_slcor_col col)
1407 {
1408         MLXSW_REG_ZERO(slcor, payload);
1409         mlxsw_reg_slcor_col_set(payload, col);
1410         mlxsw_reg_slcor_local_port_set(payload, local_port);
1411         mlxsw_reg_slcor_lag_id_set(payload, lag_id);
1412 }
1413
1414 static inline void mlxsw_reg_slcor_port_add_pack(char *payload,
1415                                                  u8 local_port, u16 lag_id,
1416                                                  u8 port_index)
1417 {
1418         mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1419                              MLXSW_REG_SLCOR_COL_LAG_ADD_PORT);
1420         mlxsw_reg_slcor_port_index_set(payload, port_index);
1421 }
1422
1423 static inline void mlxsw_reg_slcor_port_remove_pack(char *payload,
1424                                                     u8 local_port, u16 lag_id)
1425 {
1426         mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1427                              MLXSW_REG_SLCOR_COL_LAG_REMOVE_PORT);
1428 }
1429
1430 static inline void mlxsw_reg_slcor_col_enable_pack(char *payload,
1431                                                    u8 local_port, u16 lag_id)
1432 {
1433         mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1434                              MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED);
1435 }
1436
1437 static inline void mlxsw_reg_slcor_col_disable_pack(char *payload,
1438                                                     u8 local_port, u16 lag_id)
1439 {
1440         mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1441                              MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED);
1442 }
1443
1444 /* SPMLR - Switch Port MAC Learning Register
1445  * -----------------------------------------
1446  * Controls the Switch MAC learning policy per port.
1447  */
1448 #define MLXSW_REG_SPMLR_ID 0x2018
1449 #define MLXSW_REG_SPMLR_LEN 0x8
1450
1451 MLXSW_REG_DEFINE(spmlr, MLXSW_REG_SPMLR_ID, MLXSW_REG_SPMLR_LEN);
1452
1453 /* reg_spmlr_local_port
1454  * Local port number.
1455  * Access: Index
1456  */
1457 MLXSW_ITEM32(reg, spmlr, local_port, 0x00, 16, 8);
1458
1459 /* reg_spmlr_sub_port
1460  * Virtual port within the physical port.
1461  * Should be set to 0 when virtual ports are not enabled on the port.
1462  * Access: Index
1463  */
1464 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
1465
1466 enum mlxsw_reg_spmlr_learn_mode {
1467         MLXSW_REG_SPMLR_LEARN_MODE_DISABLE = 0,
1468         MLXSW_REG_SPMLR_LEARN_MODE_ENABLE = 2,
1469         MLXSW_REG_SPMLR_LEARN_MODE_SEC = 3,
1470 };
1471
1472 /* reg_spmlr_learn_mode
1473  * Learning mode on the port.
1474  * 0 - Learning disabled.
1475  * 2 - Learning enabled.
1476  * 3 - Security mode.
1477  *
1478  * In security mode the switch does not learn MACs on the port, but uses the
1479  * SMAC to see if it exists on another ingress port. If so, the packet is
1480  * classified as a bad packet and is discarded unless the software registers
1481  * to receive port security error packets usign HPKT.
1482  */
1483 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
1484
1485 static inline void mlxsw_reg_spmlr_pack(char *payload, u8 local_port,
1486                                         enum mlxsw_reg_spmlr_learn_mode mode)
1487 {
1488         MLXSW_REG_ZERO(spmlr, payload);
1489         mlxsw_reg_spmlr_local_port_set(payload, local_port);
1490         mlxsw_reg_spmlr_sub_port_set(payload, 0);
1491         mlxsw_reg_spmlr_learn_mode_set(payload, mode);
1492 }
1493
1494 /* SVFA - Switch VID to FID Allocation Register
1495  * --------------------------------------------
1496  * Controls the VID to FID mapping and {Port, VID} to FID mapping for
1497  * virtualized ports.
1498  */
1499 #define MLXSW_REG_SVFA_ID 0x201C
1500 #define MLXSW_REG_SVFA_LEN 0x10
1501
1502 MLXSW_REG_DEFINE(svfa, MLXSW_REG_SVFA_ID, MLXSW_REG_SVFA_LEN);
1503
1504 /* reg_svfa_swid
1505  * Switch partition ID.
1506  * Access: Index
1507  */
1508 MLXSW_ITEM32(reg, svfa, swid, 0x00, 24, 8);
1509
1510 /* reg_svfa_local_port
1511  * Local port number.
1512  * Access: Index
1513  *
1514  * Note: Reserved for 802.1Q FIDs.
1515  */
1516 MLXSW_ITEM32(reg, svfa, local_port, 0x00, 16, 8);
1517
1518 enum mlxsw_reg_svfa_mt {
1519         MLXSW_REG_SVFA_MT_VID_TO_FID,
1520         MLXSW_REG_SVFA_MT_PORT_VID_TO_FID,
1521 };
1522
1523 /* reg_svfa_mapping_table
1524  * Mapping table:
1525  * 0 - VID to FID
1526  * 1 - {Port, VID} to FID
1527  * Access: Index
1528  *
1529  * Note: Reserved for SwitchX-2.
1530  */
1531 MLXSW_ITEM32(reg, svfa, mapping_table, 0x00, 8, 3);
1532
1533 /* reg_svfa_v
1534  * Valid.
1535  * Valid if set.
1536  * Access: RW
1537  *
1538  * Note: Reserved for SwitchX-2.
1539  */
1540 MLXSW_ITEM32(reg, svfa, v, 0x00, 0, 1);
1541
1542 /* reg_svfa_fid
1543  * Filtering ID.
1544  * Access: RW
1545  */
1546 MLXSW_ITEM32(reg, svfa, fid, 0x04, 16, 16);
1547
1548 /* reg_svfa_vid
1549  * VLAN ID.
1550  * Access: Index
1551  */
1552 MLXSW_ITEM32(reg, svfa, vid, 0x04, 0, 12);
1553
1554 /* reg_svfa_counter_set_type
1555  * Counter set type for flow counters.
1556  * Access: RW
1557  *
1558  * Note: Reserved for SwitchX-2.
1559  */
1560 MLXSW_ITEM32(reg, svfa, counter_set_type, 0x08, 24, 8);
1561
1562 /* reg_svfa_counter_index
1563  * Counter index for flow counters.
1564  * Access: RW
1565  *
1566  * Note: Reserved for SwitchX-2.
1567  */
1568 MLXSW_ITEM32(reg, svfa, counter_index, 0x08, 0, 24);
1569
1570 static inline void mlxsw_reg_svfa_pack(char *payload, u8 local_port,
1571                                        enum mlxsw_reg_svfa_mt mt, bool valid,
1572                                        u16 fid, u16 vid)
1573 {
1574         MLXSW_REG_ZERO(svfa, payload);
1575         local_port = mt == MLXSW_REG_SVFA_MT_VID_TO_FID ? 0 : local_port;
1576         mlxsw_reg_svfa_swid_set(payload, 0);
1577         mlxsw_reg_svfa_local_port_set(payload, local_port);
1578         mlxsw_reg_svfa_mapping_table_set(payload, mt);
1579         mlxsw_reg_svfa_v_set(payload, valid);
1580         mlxsw_reg_svfa_fid_set(payload, fid);
1581         mlxsw_reg_svfa_vid_set(payload, vid);
1582 }
1583
1584 /* SVPE - Switch Virtual-Port Enabling Register
1585  * --------------------------------------------
1586  * Enables port virtualization.
1587  */
1588 #define MLXSW_REG_SVPE_ID 0x201E
1589 #define MLXSW_REG_SVPE_LEN 0x4
1590
1591 MLXSW_REG_DEFINE(svpe, MLXSW_REG_SVPE_ID, MLXSW_REG_SVPE_LEN);
1592
1593 /* reg_svpe_local_port
1594  * Local port number
1595  * Access: Index
1596  *
1597  * Note: CPU port is not supported (uses VLAN mode only).
1598  */
1599 MLXSW_ITEM32(reg, svpe, local_port, 0x00, 16, 8);
1600
1601 /* reg_svpe_vp_en
1602  * Virtual port enable.
1603  * 0 - Disable, VLAN mode (VID to FID).
1604  * 1 - Enable, Virtual port mode ({Port, VID} to FID).
1605  * Access: RW
1606  */
1607 MLXSW_ITEM32(reg, svpe, vp_en, 0x00, 8, 1);
1608
1609 static inline void mlxsw_reg_svpe_pack(char *payload, u8 local_port,
1610                                        bool enable)
1611 {
1612         MLXSW_REG_ZERO(svpe, payload);
1613         mlxsw_reg_svpe_local_port_set(payload, local_port);
1614         mlxsw_reg_svpe_vp_en_set(payload, enable);
1615 }
1616
1617 /* SFMR - Switch FID Management Register
1618  * -------------------------------------
1619  * Creates and configures FIDs.
1620  */
1621 #define MLXSW_REG_SFMR_ID 0x201F
1622 #define MLXSW_REG_SFMR_LEN 0x18
1623
1624 MLXSW_REG_DEFINE(sfmr, MLXSW_REG_SFMR_ID, MLXSW_REG_SFMR_LEN);
1625
1626 enum mlxsw_reg_sfmr_op {
1627         MLXSW_REG_SFMR_OP_CREATE_FID,
1628         MLXSW_REG_SFMR_OP_DESTROY_FID,
1629 };
1630
1631 /* reg_sfmr_op
1632  * Operation.
1633  * 0 - Create or edit FID.
1634  * 1 - Destroy FID.
1635  * Access: WO
1636  */
1637 MLXSW_ITEM32(reg, sfmr, op, 0x00, 24, 4);
1638
1639 /* reg_sfmr_fid
1640  * Filtering ID.
1641  * Access: Index
1642  */
1643 MLXSW_ITEM32(reg, sfmr, fid, 0x00, 0, 16);
1644
1645 /* reg_sfmr_fid_offset
1646  * FID offset.
1647  * Used to point into the flooding table selected by SFGC register if
1648  * the table is of type FID-Offset. Otherwise, this field is reserved.
1649  * Access: RW
1650  */
1651 MLXSW_ITEM32(reg, sfmr, fid_offset, 0x08, 0, 16);
1652
1653 /* reg_sfmr_vtfp
1654  * Valid Tunnel Flood Pointer.
1655  * If not set, then nve_tunnel_flood_ptr is reserved and considered NULL.
1656  * Access: RW
1657  *
1658  * Note: Reserved for 802.1Q FIDs.
1659  */
1660 MLXSW_ITEM32(reg, sfmr, vtfp, 0x0C, 31, 1);
1661
1662 /* reg_sfmr_nve_tunnel_flood_ptr
1663  * Underlay Flooding and BC Pointer.
1664  * Used as a pointer to the first entry of the group based link lists of
1665  * flooding or BC entries (for NVE tunnels).
1666  * Access: RW
1667  */
1668 MLXSW_ITEM32(reg, sfmr, nve_tunnel_flood_ptr, 0x0C, 0, 24);
1669
1670 /* reg_sfmr_vv
1671  * VNI Valid.
1672  * If not set, then vni is reserved.
1673  * Access: RW
1674  *
1675  * Note: Reserved for 802.1Q FIDs.
1676  */
1677 MLXSW_ITEM32(reg, sfmr, vv, 0x10, 31, 1);
1678
1679 /* reg_sfmr_vni
1680  * Virtual Network Identifier.
1681  * Access: RW
1682  *
1683  * Note: A given VNI can only be assigned to one FID.
1684  */
1685 MLXSW_ITEM32(reg, sfmr, vni, 0x10, 0, 24);
1686
1687 static inline void mlxsw_reg_sfmr_pack(char *payload,
1688                                        enum mlxsw_reg_sfmr_op op, u16 fid,
1689                                        u16 fid_offset)
1690 {
1691         MLXSW_REG_ZERO(sfmr, payload);
1692         mlxsw_reg_sfmr_op_set(payload, op);
1693         mlxsw_reg_sfmr_fid_set(payload, fid);
1694         mlxsw_reg_sfmr_fid_offset_set(payload, fid_offset);
1695         mlxsw_reg_sfmr_vtfp_set(payload, false);
1696         mlxsw_reg_sfmr_vv_set(payload, false);
1697 }
1698
1699 /* SPVMLR - Switch Port VLAN MAC Learning Register
1700  * -----------------------------------------------
1701  * Controls the switch MAC learning policy per {Port, VID}.
1702  */
1703 #define MLXSW_REG_SPVMLR_ID 0x2020
1704 #define MLXSW_REG_SPVMLR_BASE_LEN 0x04 /* base length, without records */
1705 #define MLXSW_REG_SPVMLR_REC_LEN 0x04 /* record length */
1706 #define MLXSW_REG_SPVMLR_REC_MAX_COUNT 255
1707 #define MLXSW_REG_SPVMLR_LEN (MLXSW_REG_SPVMLR_BASE_LEN + \
1708                               MLXSW_REG_SPVMLR_REC_LEN * \
1709                               MLXSW_REG_SPVMLR_REC_MAX_COUNT)
1710
1711 MLXSW_REG_DEFINE(spvmlr, MLXSW_REG_SPVMLR_ID, MLXSW_REG_SPVMLR_LEN);
1712
1713 /* reg_spvmlr_local_port
1714  * Local ingress port.
1715  * Access: Index
1716  *
1717  * Note: CPU port is not supported.
1718  */
1719 MLXSW_ITEM32(reg, spvmlr, local_port, 0x00, 16, 8);
1720
1721 /* reg_spvmlr_num_rec
1722  * Number of records to update.
1723  * Access: OP
1724  */
1725 MLXSW_ITEM32(reg, spvmlr, num_rec, 0x00, 0, 8);
1726
1727 /* reg_spvmlr_rec_learn_enable
1728  * 0 - Disable learning for {Port, VID}.
1729  * 1 - Enable learning for {Port, VID}.
1730  * Access: RW
1731  */
1732 MLXSW_ITEM32_INDEXED(reg, spvmlr, rec_learn_enable, MLXSW_REG_SPVMLR_BASE_LEN,
1733                      31, 1, MLXSW_REG_SPVMLR_REC_LEN, 0x00, false);
1734
1735 /* reg_spvmlr_rec_vid
1736  * VLAN ID to be added/removed from port or for querying.
1737  * Access: Index
1738  */
1739 MLXSW_ITEM32_INDEXED(reg, spvmlr, rec_vid, MLXSW_REG_SPVMLR_BASE_LEN, 0, 12,
1740                      MLXSW_REG_SPVMLR_REC_LEN, 0x00, false);
1741
1742 static inline void mlxsw_reg_spvmlr_pack(char *payload, u8 local_port,
1743                                          u16 vid_begin, u16 vid_end,
1744                                          bool learn_enable)
1745 {
1746         int num_rec = vid_end - vid_begin + 1;
1747         int i;
1748
1749         WARN_ON(num_rec < 1 || num_rec > MLXSW_REG_SPVMLR_REC_MAX_COUNT);
1750
1751         MLXSW_REG_ZERO(spvmlr, payload);
1752         mlxsw_reg_spvmlr_local_port_set(payload, local_port);
1753         mlxsw_reg_spvmlr_num_rec_set(payload, num_rec);
1754
1755         for (i = 0; i < num_rec; i++) {
1756                 mlxsw_reg_spvmlr_rec_learn_enable_set(payload, i, learn_enable);
1757                 mlxsw_reg_spvmlr_rec_vid_set(payload, i, vid_begin + i);
1758         }
1759 }
1760
1761 /* PPBT - Policy-Engine Port Binding Table
1762  * ---------------------------------------
1763  * This register is used for configuration of the Port Binding Table.
1764  */
1765 #define MLXSW_REG_PPBT_ID 0x3002
1766 #define MLXSW_REG_PPBT_LEN 0x14
1767
1768 MLXSW_REG_DEFINE(ppbt, MLXSW_REG_PPBT_ID, MLXSW_REG_PPBT_LEN);
1769
1770 enum mlxsw_reg_pxbt_e {
1771         MLXSW_REG_PXBT_E_IACL,
1772         MLXSW_REG_PXBT_E_EACL,
1773 };
1774
1775 /* reg_ppbt_e
1776  * Access: Index
1777  */
1778 MLXSW_ITEM32(reg, ppbt, e, 0x00, 31, 1);
1779
1780 enum mlxsw_reg_pxbt_op {
1781         MLXSW_REG_PXBT_OP_BIND,
1782         MLXSW_REG_PXBT_OP_UNBIND,
1783 };
1784
1785 /* reg_ppbt_op
1786  * Access: RW
1787  */
1788 MLXSW_ITEM32(reg, ppbt, op, 0x00, 28, 3);
1789
1790 /* reg_ppbt_local_port
1791  * Local port. Not including CPU port.
1792  * Access: Index
1793  */
1794 MLXSW_ITEM32(reg, ppbt, local_port, 0x00, 16, 8);
1795
1796 /* reg_ppbt_g
1797  * group - When set, the binding is of an ACL group. When cleared,
1798  * the binding is of an ACL.
1799  * Must be set to 1 for Spectrum.
1800  * Access: RW
1801  */
1802 MLXSW_ITEM32(reg, ppbt, g, 0x10, 31, 1);
1803
1804 /* reg_ppbt_acl_info
1805  * ACL/ACL group identifier. If the g bit is set, this field should hold
1806  * the acl_group_id, else it should hold the acl_id.
1807  * Access: RW
1808  */
1809 MLXSW_ITEM32(reg, ppbt, acl_info, 0x10, 0, 16);
1810
1811 static inline void mlxsw_reg_ppbt_pack(char *payload, enum mlxsw_reg_pxbt_e e,
1812                                        enum mlxsw_reg_pxbt_op op,
1813                                        u8 local_port, u16 acl_info)
1814 {
1815         MLXSW_REG_ZERO(ppbt, payload);
1816         mlxsw_reg_ppbt_e_set(payload, e);
1817         mlxsw_reg_ppbt_op_set(payload, op);
1818         mlxsw_reg_ppbt_local_port_set(payload, local_port);
1819         mlxsw_reg_ppbt_g_set(payload, true);
1820         mlxsw_reg_ppbt_acl_info_set(payload, acl_info);
1821 }
1822
1823 /* PACL - Policy-Engine ACL Register
1824  * ---------------------------------
1825  * This register is used for configuration of the ACL.
1826  */
1827 #define MLXSW_REG_PACL_ID 0x3004
1828 #define MLXSW_REG_PACL_LEN 0x70
1829
1830 MLXSW_REG_DEFINE(pacl, MLXSW_REG_PACL_ID, MLXSW_REG_PACL_LEN);
1831
1832 /* reg_pacl_v
1833  * Valid. Setting the v bit makes the ACL valid. It should not be cleared
1834  * while the ACL is bounded to either a port, VLAN or ACL rule.
1835  * Access: RW
1836  */
1837 MLXSW_ITEM32(reg, pacl, v, 0x00, 24, 1);
1838
1839 /* reg_pacl_acl_id
1840  * An identifier representing the ACL (managed by software)
1841  * Range 0 .. cap_max_acl_regions - 1
1842  * Access: Index
1843  */
1844 MLXSW_ITEM32(reg, pacl, acl_id, 0x08, 0, 16);
1845
1846 #define MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN 16
1847
1848 /* reg_pacl_tcam_region_info
1849  * Opaque object that represents a TCAM region.
1850  * Obtained through PTAR register.
1851  * Access: RW
1852  */
1853 MLXSW_ITEM_BUF(reg, pacl, tcam_region_info, 0x30,
1854                MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
1855
1856 static inline void mlxsw_reg_pacl_pack(char *payload, u16 acl_id,
1857                                        bool valid, const char *tcam_region_info)
1858 {
1859         MLXSW_REG_ZERO(pacl, payload);
1860         mlxsw_reg_pacl_acl_id_set(payload, acl_id);
1861         mlxsw_reg_pacl_v_set(payload, valid);
1862         mlxsw_reg_pacl_tcam_region_info_memcpy_to(payload, tcam_region_info);
1863 }
1864
1865 /* PAGT - Policy-Engine ACL Group Table
1866  * ------------------------------------
1867  * This register is used for configuration of the ACL Group Table.
1868  */
1869 #define MLXSW_REG_PAGT_ID 0x3005
1870 #define MLXSW_REG_PAGT_BASE_LEN 0x30
1871 #define MLXSW_REG_PAGT_ACL_LEN 4
1872 #define MLXSW_REG_PAGT_ACL_MAX_NUM 16
1873 #define MLXSW_REG_PAGT_LEN (MLXSW_REG_PAGT_BASE_LEN + \
1874                 MLXSW_REG_PAGT_ACL_MAX_NUM * MLXSW_REG_PAGT_ACL_LEN)
1875
1876 MLXSW_REG_DEFINE(pagt, MLXSW_REG_PAGT_ID, MLXSW_REG_PAGT_LEN);
1877
1878 /* reg_pagt_size
1879  * Number of ACLs in the group.
1880  * Size 0 invalidates a group.
1881  * Range 0 .. cap_max_acl_group_size (hard coded to 16 for now)
1882  * Total number of ACLs in all groups must be lower or equal
1883  * to cap_max_acl_tot_groups
1884  * Note: a group which is binded must not be invalidated
1885  * Access: Index
1886  */
1887 MLXSW_ITEM32(reg, pagt, size, 0x00, 0, 8);
1888
1889 /* reg_pagt_acl_group_id
1890  * An identifier (numbered from 0..cap_max_acl_groups-1) representing
1891  * the ACL Group identifier (managed by software).
1892  * Access: Index
1893  */
1894 MLXSW_ITEM32(reg, pagt, acl_group_id, 0x08, 0, 16);
1895
1896 /* reg_pagt_acl_id
1897  * ACL identifier
1898  * Access: RW
1899  */
1900 MLXSW_ITEM32_INDEXED(reg, pagt, acl_id, 0x30, 0, 16, 0x04, 0x00, false);
1901
1902 static inline void mlxsw_reg_pagt_pack(char *payload, u16 acl_group_id)
1903 {
1904         MLXSW_REG_ZERO(pagt, payload);
1905         mlxsw_reg_pagt_acl_group_id_set(payload, acl_group_id);
1906 }
1907
1908 static inline void mlxsw_reg_pagt_acl_id_pack(char *payload, int index,
1909                                               u16 acl_id)
1910 {
1911         u8 size = mlxsw_reg_pagt_size_get(payload);
1912
1913         if (index >= size)
1914                 mlxsw_reg_pagt_size_set(payload, index + 1);
1915         mlxsw_reg_pagt_acl_id_set(payload, index, acl_id);
1916 }
1917
1918 /* PTAR - Policy-Engine TCAM Allocation Register
1919  * ---------------------------------------------
1920  * This register is used for allocation of regions in the TCAM.
1921  * Note: Query method is not supported on this register.
1922  */
1923 #define MLXSW_REG_PTAR_ID 0x3006
1924 #define MLXSW_REG_PTAR_BASE_LEN 0x20
1925 #define MLXSW_REG_PTAR_KEY_ID_LEN 1
1926 #define MLXSW_REG_PTAR_KEY_ID_MAX_NUM 16
1927 #define MLXSW_REG_PTAR_LEN (MLXSW_REG_PTAR_BASE_LEN + \
1928                 MLXSW_REG_PTAR_KEY_ID_MAX_NUM * MLXSW_REG_PTAR_KEY_ID_LEN)
1929
1930 MLXSW_REG_DEFINE(ptar, MLXSW_REG_PTAR_ID, MLXSW_REG_PTAR_LEN);
1931
1932 enum mlxsw_reg_ptar_op {
1933         /* allocate a TCAM region */
1934         MLXSW_REG_PTAR_OP_ALLOC,
1935         /* resize a TCAM region */
1936         MLXSW_REG_PTAR_OP_RESIZE,
1937         /* deallocate TCAM region */
1938         MLXSW_REG_PTAR_OP_FREE,
1939         /* test allocation */
1940         MLXSW_REG_PTAR_OP_TEST,
1941 };
1942
1943 /* reg_ptar_op
1944  * Access: OP
1945  */
1946 MLXSW_ITEM32(reg, ptar, op, 0x00, 28, 4);
1947
1948 /* reg_ptar_action_set_type
1949  * Type of action set to be used on this region.
1950  * For Spectrum, this is always type 2 - "flexible"
1951  * Access: WO
1952  */
1953 MLXSW_ITEM32(reg, ptar, action_set_type, 0x00, 16, 8);
1954
1955 /* reg_ptar_key_type
1956  * TCAM key type for the region.
1957  * For Spectrum, this is always type 0x50 - "FLEX_KEY"
1958  * Access: WO
1959  */
1960 MLXSW_ITEM32(reg, ptar, key_type, 0x00, 0, 8);
1961
1962 /* reg_ptar_region_size
1963  * TCAM region size. When allocating/resizing this is the requested size,
1964  * the response is the actual size. Note that actual size may be
1965  * larger than requested.
1966  * Allowed range 1 .. cap_max_rules-1
1967  * Reserved during op deallocate.
1968  * Access: WO
1969  */
1970 MLXSW_ITEM32(reg, ptar, region_size, 0x04, 0, 16);
1971
1972 /* reg_ptar_region_id
1973  * Region identifier
1974  * Range 0 .. cap_max_regions-1
1975  * Access: Index
1976  */
1977 MLXSW_ITEM32(reg, ptar, region_id, 0x08, 0, 16);
1978
1979 /* reg_ptar_tcam_region_info
1980  * Opaque object that represents the TCAM region.
1981  * Returned when allocating a region.
1982  * Provided by software for ACL generation and region deallocation and resize.
1983  * Access: RW
1984  */
1985 MLXSW_ITEM_BUF(reg, ptar, tcam_region_info, 0x10,
1986                MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
1987
1988 /* reg_ptar_flexible_key_id
1989  * Identifier of the Flexible Key.
1990  * Only valid if key_type == "FLEX_KEY"
1991  * The key size will be rounded up to one of the following values:
1992  * 9B, 18B, 36B, 54B.
1993  * This field is reserved for in resize operation.
1994  * Access: WO
1995  */
1996 MLXSW_ITEM8_INDEXED(reg, ptar, flexible_key_id, 0x20, 0, 8,
1997                     MLXSW_REG_PTAR_KEY_ID_LEN, 0x00, false);
1998
1999 static inline void mlxsw_reg_ptar_pack(char *payload, enum mlxsw_reg_ptar_op op,
2000                                        u16 region_size, u16 region_id,
2001                                        const char *tcam_region_info)
2002 {
2003         MLXSW_REG_ZERO(ptar, payload);
2004         mlxsw_reg_ptar_op_set(payload, op);
2005         mlxsw_reg_ptar_action_set_type_set(payload, 2); /* "flexible" */
2006         mlxsw_reg_ptar_key_type_set(payload, 0x50); /* "FLEX_KEY" */
2007         mlxsw_reg_ptar_region_size_set(payload, region_size);
2008         mlxsw_reg_ptar_region_id_set(payload, region_id);
2009         mlxsw_reg_ptar_tcam_region_info_memcpy_to(payload, tcam_region_info);
2010 }
2011
2012 static inline void mlxsw_reg_ptar_key_id_pack(char *payload, int index,
2013                                               u16 key_id)
2014 {
2015         mlxsw_reg_ptar_flexible_key_id_set(payload, index, key_id);
2016 }
2017
2018 static inline void mlxsw_reg_ptar_unpack(char *payload, char *tcam_region_info)
2019 {
2020         mlxsw_reg_ptar_tcam_region_info_memcpy_from(payload, tcam_region_info);
2021 }
2022
2023 /* PPBS - Policy-Engine Policy Based Switching Register
2024  * ----------------------------------------------------
2025  * This register retrieves and sets Policy Based Switching Table entries.
2026  */
2027 #define MLXSW_REG_PPBS_ID 0x300C
2028 #define MLXSW_REG_PPBS_LEN 0x14
2029
2030 MLXSW_REG_DEFINE(ppbs, MLXSW_REG_PPBS_ID, MLXSW_REG_PPBS_LEN);
2031
2032 /* reg_ppbs_pbs_ptr
2033  * Index into the PBS table.
2034  * For Spectrum, the index points to the KVD Linear.
2035  * Access: Index
2036  */
2037 MLXSW_ITEM32(reg, ppbs, pbs_ptr, 0x08, 0, 24);
2038
2039 /* reg_ppbs_system_port
2040  * Unique port identifier for the final destination of the packet.
2041  * Access: RW
2042  */
2043 MLXSW_ITEM32(reg, ppbs, system_port, 0x10, 0, 16);
2044
2045 static inline void mlxsw_reg_ppbs_pack(char *payload, u32 pbs_ptr,
2046                                        u16 system_port)
2047 {
2048         MLXSW_REG_ZERO(ppbs, payload);
2049         mlxsw_reg_ppbs_pbs_ptr_set(payload, pbs_ptr);
2050         mlxsw_reg_ppbs_system_port_set(payload, system_port);
2051 }
2052
2053 /* PRCR - Policy-Engine Rules Copy Register
2054  * ----------------------------------------
2055  * This register is used for accessing rules within a TCAM region.
2056  */
2057 #define MLXSW_REG_PRCR_ID 0x300D
2058 #define MLXSW_REG_PRCR_LEN 0x40
2059
2060 MLXSW_REG_DEFINE(prcr, MLXSW_REG_PRCR_ID, MLXSW_REG_PRCR_LEN);
2061
2062 enum mlxsw_reg_prcr_op {
2063         /* Move rules. Moves the rules from "tcam_region_info" starting
2064          * at offset "offset" to "dest_tcam_region_info"
2065          * at offset "dest_offset."
2066          */
2067         MLXSW_REG_PRCR_OP_MOVE,
2068         /* Copy rules. Copies the rules from "tcam_region_info" starting
2069          * at offset "offset" to "dest_tcam_region_info"
2070          * at offset "dest_offset."
2071          */
2072         MLXSW_REG_PRCR_OP_COPY,
2073 };
2074
2075 /* reg_prcr_op
2076  * Access: OP
2077  */
2078 MLXSW_ITEM32(reg, prcr, op, 0x00, 28, 4);
2079
2080 /* reg_prcr_offset
2081  * Offset within the source region to copy/move from.
2082  * Access: Index
2083  */
2084 MLXSW_ITEM32(reg, prcr, offset, 0x00, 0, 16);
2085
2086 /* reg_prcr_size
2087  * The number of rules to copy/move.
2088  * Access: WO
2089  */
2090 MLXSW_ITEM32(reg, prcr, size, 0x04, 0, 16);
2091
2092 /* reg_prcr_tcam_region_info
2093  * Opaque object that represents the source TCAM region.
2094  * Access: Index
2095  */
2096 MLXSW_ITEM_BUF(reg, prcr, tcam_region_info, 0x10,
2097                MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
2098
2099 /* reg_prcr_dest_offset
2100  * Offset within the source region to copy/move to.
2101  * Access: Index
2102  */
2103 MLXSW_ITEM32(reg, prcr, dest_offset, 0x20, 0, 16);
2104
2105 /* reg_prcr_dest_tcam_region_info
2106  * Opaque object that represents the destination TCAM region.
2107  * Access: Index
2108  */
2109 MLXSW_ITEM_BUF(reg, prcr, dest_tcam_region_info, 0x30,
2110                MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
2111
2112 static inline void mlxsw_reg_prcr_pack(char *payload, enum mlxsw_reg_prcr_op op,
2113                                        const char *src_tcam_region_info,
2114                                        u16 src_offset,
2115                                        const char *dest_tcam_region_info,
2116                                        u16 dest_offset, u16 size)
2117 {
2118         MLXSW_REG_ZERO(prcr, payload);
2119         mlxsw_reg_prcr_op_set(payload, op);
2120         mlxsw_reg_prcr_offset_set(payload, src_offset);
2121         mlxsw_reg_prcr_size_set(payload, size);
2122         mlxsw_reg_prcr_tcam_region_info_memcpy_to(payload,
2123                                                   src_tcam_region_info);
2124         mlxsw_reg_prcr_dest_offset_set(payload, dest_offset);
2125         mlxsw_reg_prcr_dest_tcam_region_info_memcpy_to(payload,
2126                                                        dest_tcam_region_info);
2127 }
2128
2129 /* PEFA - Policy-Engine Extended Flexible Action Register
2130  * ------------------------------------------------------
2131  * This register is used for accessing an extended flexible action entry
2132  * in the central KVD Linear Database.
2133  */
2134 #define MLXSW_REG_PEFA_ID 0x300F
2135 #define MLXSW_REG_PEFA_LEN 0xB0
2136
2137 MLXSW_REG_DEFINE(pefa, MLXSW_REG_PEFA_ID, MLXSW_REG_PEFA_LEN);
2138
2139 /* reg_pefa_index
2140  * Index in the KVD Linear Centralized Database.
2141  * Access: Index
2142  */
2143 MLXSW_ITEM32(reg, pefa, index, 0x00, 0, 24);
2144
2145 #define MLXSW_REG_PXXX_FLEX_ACTION_SET_LEN 0xA8
2146
2147 /* reg_pefa_flex_action_set
2148  * Action-set to perform when rule is matched.
2149  * Must be zero padded if action set is shorter.
2150  * Access: RW
2151  */
2152 MLXSW_ITEM_BUF(reg, pefa, flex_action_set, 0x08,
2153                MLXSW_REG_PXXX_FLEX_ACTION_SET_LEN);
2154
2155 static inline void mlxsw_reg_pefa_pack(char *payload, u32 index,
2156                                        const char *flex_action_set)
2157 {
2158         MLXSW_REG_ZERO(pefa, payload);
2159         mlxsw_reg_pefa_index_set(payload, index);
2160         mlxsw_reg_pefa_flex_action_set_memcpy_to(payload, flex_action_set);
2161 }
2162
2163 /* PTCE-V2 - Policy-Engine TCAM Entry Register Version 2
2164  * -----------------------------------------------------
2165  * This register is used for accessing rules within a TCAM region.
2166  * It is a new version of PTCE in order to support wider key,
2167  * mask and action within a TCAM region. This register is not supported
2168  * by SwitchX and SwitchX-2.
2169  */
2170 #define MLXSW_REG_PTCE2_ID 0x3017
2171 #define MLXSW_REG_PTCE2_LEN 0x1D8
2172
2173 MLXSW_REG_DEFINE(ptce2, MLXSW_REG_PTCE2_ID, MLXSW_REG_PTCE2_LEN);
2174
2175 /* reg_ptce2_v
2176  * Valid.
2177  * Access: RW
2178  */
2179 MLXSW_ITEM32(reg, ptce2, v, 0x00, 31, 1);
2180
2181 /* reg_ptce2_a
2182  * Activity. Set if a packet lookup has hit on the specific entry.
2183  * To clear the "a" bit, use "clear activity" op or "clear on read" op.
2184  * Access: RO
2185  */
2186 MLXSW_ITEM32(reg, ptce2, a, 0x00, 30, 1);
2187
2188 enum mlxsw_reg_ptce2_op {
2189         /* Read operation. */
2190         MLXSW_REG_PTCE2_OP_QUERY_READ = 0,
2191         /* clear on read operation. Used to read entry
2192          * and clear Activity bit.
2193          */
2194         MLXSW_REG_PTCE2_OP_QUERY_CLEAR_ON_READ = 1,
2195         /* Write operation. Used to write a new entry to the table.
2196          * All R/W fields are relevant for new entry. Activity bit is set
2197          * for new entries - Note write with v = 0 will delete the entry.
2198          */
2199         MLXSW_REG_PTCE2_OP_WRITE_WRITE = 0,
2200         /* Update action. Only action set will be updated. */
2201         MLXSW_REG_PTCE2_OP_WRITE_UPDATE = 1,
2202         /* Clear activity. A bit is cleared for the entry. */
2203         MLXSW_REG_PTCE2_OP_WRITE_CLEAR_ACTIVITY = 2,
2204 };
2205
2206 /* reg_ptce2_op
2207  * Access: OP
2208  */
2209 MLXSW_ITEM32(reg, ptce2, op, 0x00, 20, 3);
2210
2211 /* reg_ptce2_offset
2212  * Access: Index
2213  */
2214 MLXSW_ITEM32(reg, ptce2, offset, 0x00, 0, 16);
2215
2216 /* reg_ptce2_tcam_region_info
2217  * Opaque object that represents the TCAM region.
2218  * Access: Index
2219  */
2220 MLXSW_ITEM_BUF(reg, ptce2, tcam_region_info, 0x10,
2221                MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN);
2222
2223 #define MLXSW_REG_PTCE2_FLEX_KEY_BLOCKS_LEN 96
2224
2225 /* reg_ptce2_flex_key_blocks
2226  * ACL Key.
2227  * Access: RW
2228  */
2229 MLXSW_ITEM_BUF(reg, ptce2, flex_key_blocks, 0x20,
2230                MLXSW_REG_PTCE2_FLEX_KEY_BLOCKS_LEN);
2231
2232 /* reg_ptce2_mask
2233  * mask- in the same size as key. A bit that is set directs the TCAM
2234  * to compare the corresponding bit in key. A bit that is clear directs
2235  * the TCAM to ignore the corresponding bit in key.
2236  * Access: RW
2237  */
2238 MLXSW_ITEM_BUF(reg, ptce2, mask, 0x80,
2239                MLXSW_REG_PTCE2_FLEX_KEY_BLOCKS_LEN);
2240
2241 /* reg_ptce2_flex_action_set
2242  * ACL action set.
2243  * Access: RW
2244  */
2245 MLXSW_ITEM_BUF(reg, ptce2, flex_action_set, 0xE0,
2246                MLXSW_REG_PXXX_FLEX_ACTION_SET_LEN);
2247
2248 static inline void mlxsw_reg_ptce2_pack(char *payload, bool valid,
2249                                         enum mlxsw_reg_ptce2_op op,
2250                                         const char *tcam_region_info,
2251                                         u16 offset)
2252 {
2253         MLXSW_REG_ZERO(ptce2, payload);
2254         mlxsw_reg_ptce2_v_set(payload, valid);
2255         mlxsw_reg_ptce2_op_set(payload, op);
2256         mlxsw_reg_ptce2_offset_set(payload, offset);
2257         mlxsw_reg_ptce2_tcam_region_info_memcpy_to(payload, tcam_region_info);
2258 }
2259
2260 /* QPCR - QoS Policer Configuration Register
2261  * -----------------------------------------
2262  * The QPCR register is used to create policers - that limit
2263  * the rate of bytes or packets via some trap group.
2264  */
2265 #define MLXSW_REG_QPCR_ID 0x4004
2266 #define MLXSW_REG_QPCR_LEN 0x28
2267
2268 MLXSW_REG_DEFINE(qpcr, MLXSW_REG_QPCR_ID, MLXSW_REG_QPCR_LEN);
2269
2270 enum mlxsw_reg_qpcr_g {
2271         MLXSW_REG_QPCR_G_GLOBAL = 2,
2272         MLXSW_REG_QPCR_G_STORM_CONTROL = 3,
2273 };
2274
2275 /* reg_qpcr_g
2276  * The policer type.
2277  * Access: Index
2278  */
2279 MLXSW_ITEM32(reg, qpcr, g, 0x00, 14, 2);
2280
2281 /* reg_qpcr_pid
2282  * Policer ID.
2283  * Access: Index
2284  */
2285 MLXSW_ITEM32(reg, qpcr, pid, 0x00, 0, 14);
2286
2287 /* reg_qpcr_color_aware
2288  * Is the policer aware of colors.
2289  * Must be 0 (unaware) for cpu port.
2290  * Access: RW for unbounded policer. RO for bounded policer.
2291  */
2292 MLXSW_ITEM32(reg, qpcr, color_aware, 0x04, 15, 1);
2293
2294 /* reg_qpcr_bytes
2295  * Is policer limit is for bytes per sec or packets per sec.
2296  * 0 - packets
2297  * 1 - bytes
2298  * Access: RW for unbounded policer. RO for bounded policer.
2299  */
2300 MLXSW_ITEM32(reg, qpcr, bytes, 0x04, 14, 1);
2301
2302 enum mlxsw_reg_qpcr_ir_units {
2303         MLXSW_REG_QPCR_IR_UNITS_M,
2304         MLXSW_REG_QPCR_IR_UNITS_K,
2305 };
2306
2307 /* reg_qpcr_ir_units
2308  * Policer's units for cir and eir fields (for bytes limits only)
2309  * 1 - 10^3
2310  * 0 - 10^6
2311  * Access: OP
2312  */
2313 MLXSW_ITEM32(reg, qpcr, ir_units, 0x04, 12, 1);
2314
2315 enum mlxsw_reg_qpcr_rate_type {
2316         MLXSW_REG_QPCR_RATE_TYPE_SINGLE = 1,
2317         MLXSW_REG_QPCR_RATE_TYPE_DOUBLE = 2,
2318 };
2319
2320 /* reg_qpcr_rate_type
2321  * Policer can have one limit (single rate) or 2 limits with specific operation
2322  * for packets that exceed the lower rate but not the upper one.
2323  * (For cpu port must be single rate)
2324  * Access: RW for unbounded policer. RO for bounded policer.
2325  */
2326 MLXSW_ITEM32(reg, qpcr, rate_type, 0x04, 8, 2);
2327
2328 /* reg_qpc_cbs
2329  * Policer's committed burst size.
2330  * The policer is working with time slices of 50 nano sec. By default every
2331  * slice is granted the proportionate share of the committed rate. If we want to
2332  * allow a slice to exceed that share (while still keeping the rate per sec) we
2333  * can allow burst. The burst size is between the default proportionate share
2334  * (and no lower than 8) to 32Gb. (Even though giving a number higher than the
2335  * committed rate will result in exceeding the rate). The burst size must be a
2336  * log of 2 and will be determined by 2^cbs.
2337  * Access: RW
2338  */
2339 MLXSW_ITEM32(reg, qpcr, cbs, 0x08, 24, 6);
2340
2341 /* reg_qpcr_cir
2342  * Policer's committed rate.
2343  * The rate used for sungle rate, the lower rate for double rate.
2344  * For bytes limits, the rate will be this value * the unit from ir_units.
2345  * (Resolution error is up to 1%).
2346  * Access: RW
2347  */
2348 MLXSW_ITEM32(reg, qpcr, cir, 0x0C, 0, 32);
2349
2350 /* reg_qpcr_eir
2351  * Policer's exceed rate.
2352  * The higher rate for double rate, reserved for single rate.
2353  * Lower rate for double rate policer.
2354  * For bytes limits, the rate will be this value * the unit from ir_units.
2355  * (Resolution error is up to 1%).
2356  * Access: RW
2357  */
2358 MLXSW_ITEM32(reg, qpcr, eir, 0x10, 0, 32);
2359
2360 #define MLXSW_REG_QPCR_DOUBLE_RATE_ACTION 2
2361
2362 /* reg_qpcr_exceed_action.
2363  * What to do with packets between the 2 limits for double rate.
2364  * Access: RW for unbounded policer. RO for bounded policer.
2365  */
2366 MLXSW_ITEM32(reg, qpcr, exceed_action, 0x14, 0, 4);
2367
2368 enum mlxsw_reg_qpcr_action {
2369         /* Discard */
2370         MLXSW_REG_QPCR_ACTION_DISCARD = 1,
2371         /* Forward and set color to red.
2372          * If the packet is intended to cpu port, it will be dropped.
2373          */
2374         MLXSW_REG_QPCR_ACTION_FORWARD = 2,
2375 };
2376
2377 /* reg_qpcr_violate_action
2378  * What to do with packets that cross the cir limit (for single rate) or the eir
2379  * limit (for double rate).
2380  * Access: RW for unbounded policer. RO for bounded policer.
2381  */
2382 MLXSW_ITEM32(reg, qpcr, violate_action, 0x18, 0, 4);
2383
2384 static inline void mlxsw_reg_qpcr_pack(char *payload, u16 pid,
2385                                        enum mlxsw_reg_qpcr_ir_units ir_units,
2386                                        bool bytes, u32 cir, u16 cbs)
2387 {
2388         MLXSW_REG_ZERO(qpcr, payload);
2389         mlxsw_reg_qpcr_pid_set(payload, pid);
2390         mlxsw_reg_qpcr_g_set(payload, MLXSW_REG_QPCR_G_GLOBAL);
2391         mlxsw_reg_qpcr_rate_type_set(payload, MLXSW_REG_QPCR_RATE_TYPE_SINGLE);
2392         mlxsw_reg_qpcr_violate_action_set(payload,
2393                                           MLXSW_REG_QPCR_ACTION_DISCARD);
2394         mlxsw_reg_qpcr_cir_set(payload, cir);
2395         mlxsw_reg_qpcr_ir_units_set(payload, ir_units);
2396         mlxsw_reg_qpcr_bytes_set(payload, bytes);
2397         mlxsw_reg_qpcr_cbs_set(payload, cbs);
2398 }
2399
2400 /* QTCT - QoS Switch Traffic Class Table
2401  * -------------------------------------
2402  * Configures the mapping between the packet switch priority and the
2403  * traffic class on the transmit port.
2404  */
2405 #define MLXSW_REG_QTCT_ID 0x400A
2406 #define MLXSW_REG_QTCT_LEN 0x08
2407
2408 MLXSW_REG_DEFINE(qtct, MLXSW_REG_QTCT_ID, MLXSW_REG_QTCT_LEN);
2409
2410 /* reg_qtct_local_port
2411  * Local port number.
2412  * Access: Index
2413  *
2414  * Note: CPU port is not supported.
2415  */
2416 MLXSW_ITEM32(reg, qtct, local_port, 0x00, 16, 8);
2417
2418 /* reg_qtct_sub_port
2419  * Virtual port within the physical port.
2420  * Should be set to 0 when virtual ports are not enabled on the port.
2421  * Access: Index
2422  */
2423 MLXSW_ITEM32(reg, qtct, sub_port, 0x00, 8, 8);
2424
2425 /* reg_qtct_switch_prio
2426  * Switch priority.
2427  * Access: Index
2428  */
2429 MLXSW_ITEM32(reg, qtct, switch_prio, 0x00, 0, 4);
2430
2431 /* reg_qtct_tclass
2432  * Traffic class.
2433  * Default values:
2434  * switch_prio 0 : tclass 1
2435  * switch_prio 1 : tclass 0
2436  * switch_prio i : tclass i, for i > 1
2437  * Access: RW
2438  */
2439 MLXSW_ITEM32(reg, qtct, tclass, 0x04, 0, 4);
2440
2441 static inline void mlxsw_reg_qtct_pack(char *payload, u8 local_port,
2442                                        u8 switch_prio, u8 tclass)
2443 {
2444         MLXSW_REG_ZERO(qtct, payload);
2445         mlxsw_reg_qtct_local_port_set(payload, local_port);
2446         mlxsw_reg_qtct_switch_prio_set(payload, switch_prio);
2447         mlxsw_reg_qtct_tclass_set(payload, tclass);
2448 }
2449
2450 /* QEEC - QoS ETS Element Configuration Register
2451  * ---------------------------------------------
2452  * Configures the ETS elements.
2453  */
2454 #define MLXSW_REG_QEEC_ID 0x400D
2455 #define MLXSW_REG_QEEC_LEN 0x20
2456
2457 MLXSW_REG_DEFINE(qeec, MLXSW_REG_QEEC_ID, MLXSW_REG_QEEC_LEN);
2458
2459 /* reg_qeec_local_port
2460  * Local port number.
2461  * Access: Index
2462  *
2463  * Note: CPU port is supported.
2464  */
2465 MLXSW_ITEM32(reg, qeec, local_port, 0x00, 16, 8);
2466
2467 enum mlxsw_reg_qeec_hr {
2468         MLXSW_REG_QEEC_HIERARCY_PORT,
2469         MLXSW_REG_QEEC_HIERARCY_GROUP,
2470         MLXSW_REG_QEEC_HIERARCY_SUBGROUP,
2471         MLXSW_REG_QEEC_HIERARCY_TC,
2472 };
2473
2474 /* reg_qeec_element_hierarchy
2475  * 0 - Port
2476  * 1 - Group
2477  * 2 - Subgroup
2478  * 3 - Traffic Class
2479  * Access: Index
2480  */
2481 MLXSW_ITEM32(reg, qeec, element_hierarchy, 0x04, 16, 4);
2482
2483 /* reg_qeec_element_index
2484  * The index of the element in the hierarchy.
2485  * Access: Index
2486  */
2487 MLXSW_ITEM32(reg, qeec, element_index, 0x04, 0, 8);
2488
2489 /* reg_qeec_next_element_index
2490  * The index of the next (lower) element in the hierarchy.
2491  * Access: RW
2492  *
2493  * Note: Reserved for element_hierarchy 0.
2494  */
2495 MLXSW_ITEM32(reg, qeec, next_element_index, 0x08, 0, 8);
2496
2497 /* reg_qeec_mise
2498  * Min shaper configuration enable. Enables configuration of the min
2499  * shaper on this ETS element
2500  * 0 - Disable
2501  * 1 - Enable
2502  * Access: RW
2503  */
2504 MLXSW_ITEM32(reg, qeec, mise, 0x0C, 31, 1);
2505
2506 enum {
2507         MLXSW_REG_QEEC_BYTES_MODE,
2508         MLXSW_REG_QEEC_PACKETS_MODE,
2509 };
2510
2511 /* reg_qeec_pb
2512  * Packets or bytes mode.
2513  * 0 - Bytes mode
2514  * 1 - Packets mode
2515  * Access: RW
2516  *
2517  * Note: Used for max shaper configuration. For Spectrum, packets mode
2518  * is supported only for traffic classes of CPU port.
2519  */
2520 MLXSW_ITEM32(reg, qeec, pb, 0x0C, 28, 1);
2521
2522 /* The smallest permitted min shaper rate. */
2523 #define MLXSW_REG_QEEC_MIS_MIN  200000          /* Kbps */
2524
2525 /* reg_qeec_min_shaper_rate
2526  * Min shaper information rate.
2527  * For CPU port, can only be configured for port hierarchy.
2528  * When in bytes mode, value is specified in units of 1000bps.
2529  * Access: RW
2530  */
2531 MLXSW_ITEM32(reg, qeec, min_shaper_rate, 0x0C, 0, 28);
2532
2533 /* reg_qeec_mase
2534  * Max shaper configuration enable. Enables configuration of the max
2535  * shaper on this ETS element.
2536  * 0 - Disable
2537  * 1 - Enable
2538  * Access: RW
2539  */
2540 MLXSW_ITEM32(reg, qeec, mase, 0x10, 31, 1);
2541
2542 /* A large max rate will disable the max shaper. */
2543 #define MLXSW_REG_QEEC_MAS_DIS  200000000       /* Kbps */
2544
2545 /* reg_qeec_max_shaper_rate
2546  * Max shaper information rate.
2547  * For CPU port, can only be configured for port hierarchy.
2548  * When in bytes mode, value is specified in units of 1000bps.
2549  * Access: RW
2550  */
2551 MLXSW_ITEM32(reg, qeec, max_shaper_rate, 0x10, 0, 28);
2552
2553 /* reg_qeec_de
2554  * DWRR configuration enable. Enables configuration of the dwrr and
2555  * dwrr_weight.
2556  * 0 - Disable
2557  * 1 - Enable
2558  * Access: RW
2559  */
2560 MLXSW_ITEM32(reg, qeec, de, 0x18, 31, 1);
2561
2562 /* reg_qeec_dwrr
2563  * Transmission selection algorithm to use on the link going down from
2564  * the ETS element.
2565  * 0 - Strict priority
2566  * 1 - DWRR
2567  * Access: RW
2568  */
2569 MLXSW_ITEM32(reg, qeec, dwrr, 0x18, 15, 1);
2570
2571 /* reg_qeec_dwrr_weight
2572  * DWRR weight on the link going down from the ETS element. The
2573  * percentage of bandwidth guaranteed to an ETS element within
2574  * its hierarchy. The sum of all weights across all ETS elements
2575  * within one hierarchy should be equal to 100. Reserved when
2576  * transmission selection algorithm is strict priority.
2577  * Access: RW
2578  */
2579 MLXSW_ITEM32(reg, qeec, dwrr_weight, 0x18, 0, 8);
2580
2581 static inline void mlxsw_reg_qeec_pack(char *payload, u8 local_port,
2582                                        enum mlxsw_reg_qeec_hr hr, u8 index,
2583                                        u8 next_index)
2584 {
2585         MLXSW_REG_ZERO(qeec, payload);
2586         mlxsw_reg_qeec_local_port_set(payload, local_port);
2587         mlxsw_reg_qeec_element_hierarchy_set(payload, hr);
2588         mlxsw_reg_qeec_element_index_set(payload, index);
2589         mlxsw_reg_qeec_next_element_index_set(payload, next_index);
2590 }
2591
2592 /* PMLP - Ports Module to Local Port Register
2593  * ------------------------------------------
2594  * Configures the assignment of modules to local ports.
2595  */
2596 #define MLXSW_REG_PMLP_ID 0x5002
2597 #define MLXSW_REG_PMLP_LEN 0x40
2598
2599 MLXSW_REG_DEFINE(pmlp, MLXSW_REG_PMLP_ID, MLXSW_REG_PMLP_LEN);
2600
2601 /* reg_pmlp_rxtx
2602  * 0 - Tx value is used for both Tx and Rx.
2603  * 1 - Rx value is taken from a separte field.
2604  * Access: RW
2605  */
2606 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
2607
2608 /* reg_pmlp_local_port
2609  * Local port number.
2610  * Access: Index
2611  */
2612 MLXSW_ITEM32(reg, pmlp, local_port, 0x00, 16, 8);
2613
2614 /* reg_pmlp_width
2615  * 0 - Unmap local port.
2616  * 1 - Lane 0 is used.
2617  * 2 - Lanes 0 and 1 are used.
2618  * 4 - Lanes 0, 1, 2 and 3 are used.
2619  * Access: RW
2620  */
2621 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
2622
2623 /* reg_pmlp_module
2624  * Module number.
2625  * Access: RW
2626  */
2627 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0x00, false);
2628
2629 /* reg_pmlp_tx_lane
2630  * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
2631  * Access: RW
2632  */
2633 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 2, 0x04, 0x00, false);
2634
2635 /* reg_pmlp_rx_lane
2636  * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
2637  * equal to Tx lane.
2638  * Access: RW
2639  */
2640 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 2, 0x04, 0x00, false);
2641
2642 static inline void mlxsw_reg_pmlp_pack(char *payload, u8 local_port)
2643 {
2644         MLXSW_REG_ZERO(pmlp, payload);
2645         mlxsw_reg_pmlp_local_port_set(payload, local_port);
2646 }
2647
2648 /* PMTU - Port MTU Register
2649  * ------------------------
2650  * Configures and reports the port MTU.
2651  */
2652 #define MLXSW_REG_PMTU_ID 0x5003
2653 #define MLXSW_REG_PMTU_LEN 0x10
2654
2655 MLXSW_REG_DEFINE(pmtu, MLXSW_REG_PMTU_ID, MLXSW_REG_PMTU_LEN);
2656
2657 /* reg_pmtu_local_port
2658  * Local port number.
2659  * Access: Index
2660  */
2661 MLXSW_ITEM32(reg, pmtu, local_port, 0x00, 16, 8);
2662
2663 /* reg_pmtu_max_mtu
2664  * Maximum MTU.
2665  * When port type (e.g. Ethernet) is configured, the relevant MTU is
2666  * reported, otherwise the minimum between the max_mtu of the different
2667  * types is reported.
2668  * Access: RO
2669  */
2670 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
2671
2672 /* reg_pmtu_admin_mtu
2673  * MTU value to set port to. Must be smaller or equal to max_mtu.
2674  * Note: If port type is Infiniband, then port must be disabled, when its
2675  * MTU is set.
2676  * Access: RW
2677  */
2678 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
2679
2680 /* reg_pmtu_oper_mtu
2681  * The actual MTU configured on the port. Packets exceeding this size
2682  * will be dropped.
2683  * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
2684  * oper_mtu might be smaller than admin_mtu.
2685  * Access: RO
2686  */
2687 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
2688
2689 static inline void mlxsw_reg_pmtu_pack(char *payload, u8 local_port,
2690                                        u16 new_mtu)
2691 {
2692         MLXSW_REG_ZERO(pmtu, payload);
2693         mlxsw_reg_pmtu_local_port_set(payload, local_port);
2694         mlxsw_reg_pmtu_max_mtu_set(payload, 0);
2695         mlxsw_reg_pmtu_admin_mtu_set(payload, new_mtu);
2696         mlxsw_reg_pmtu_oper_mtu_set(payload, 0);
2697 }
2698
2699 /* PTYS - Port Type and Speed Register
2700  * -----------------------------------
2701  * Configures and reports the port speed type.
2702  *
2703  * Note: When set while the link is up, the changes will not take effect
2704  * until the port transitions from down to up state.
2705  */
2706 #define MLXSW_REG_PTYS_ID 0x5004
2707 #define MLXSW_REG_PTYS_LEN 0x40
2708
2709 MLXSW_REG_DEFINE(ptys, MLXSW_REG_PTYS_ID, MLXSW_REG_PTYS_LEN);
2710
2711 /* reg_ptys_local_port
2712  * Local port number.
2713  * Access: Index
2714  */
2715 MLXSW_ITEM32(reg, ptys, local_port, 0x00, 16, 8);
2716
2717 #define MLXSW_REG_PTYS_PROTO_MASK_IB    BIT(0)
2718 #define MLXSW_REG_PTYS_PROTO_MASK_ETH   BIT(2)
2719
2720 /* reg_ptys_proto_mask
2721  * Protocol mask. Indicates which protocol is used.
2722  * 0 - Infiniband.
2723  * 1 - Fibre Channel.
2724  * 2 - Ethernet.
2725  * Access: Index
2726  */
2727 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
2728
2729 enum {
2730         MLXSW_REG_PTYS_AN_STATUS_NA,
2731         MLXSW_REG_PTYS_AN_STATUS_OK,
2732         MLXSW_REG_PTYS_AN_STATUS_FAIL,
2733 };
2734
2735 /* reg_ptys_an_status
2736  * Autonegotiation status.
2737  * Access: RO
2738  */
2739 MLXSW_ITEM32(reg, ptys, an_status, 0x04, 28, 4);
2740
2741 #define MLXSW_REG_PTYS_ETH_SPEED_SGMII                  BIT(0)
2742 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX            BIT(1)
2743 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4            BIT(2)
2744 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4            BIT(3)
2745 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR             BIT(4)
2746 #define MLXSW_REG_PTYS_ETH_SPEED_20GBASE_KR2            BIT(5)
2747 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4            BIT(6)
2748 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4            BIT(7)
2749 #define MLXSW_REG_PTYS_ETH_SPEED_56GBASE_R4             BIT(8)
2750 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR             BIT(12)
2751 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR             BIT(13)
2752 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR          BIT(14)
2753 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4            BIT(15)
2754 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4        BIT(16)
2755 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_SR2            BIT(18)
2756 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR4            BIT(19)
2757 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4           BIT(20)
2758 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4           BIT(21)
2759 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4           BIT(22)
2760 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4       BIT(23)
2761 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_TX             BIT(24)
2762 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_T              BIT(25)
2763 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_T              BIT(26)
2764 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR             BIT(27)
2765 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR             BIT(28)
2766 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR             BIT(29)
2767 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2            BIT(30)
2768 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2            BIT(31)
2769
2770 /* reg_ptys_eth_proto_cap
2771  * Ethernet port supported speeds and protocols.
2772  * Access: RO
2773  */
2774 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
2775
2776 /* reg_ptys_ib_link_width_cap
2777  * IB port supported widths.
2778  * Access: RO
2779  */
2780 MLXSW_ITEM32(reg, ptys, ib_link_width_cap, 0x10, 16, 16);
2781
2782 #define MLXSW_REG_PTYS_IB_SPEED_SDR     BIT(0)
2783 #define MLXSW_REG_PTYS_IB_SPEED_DDR     BIT(1)
2784 #define MLXSW_REG_PTYS_IB_SPEED_QDR     BIT(2)
2785 #define MLXSW_REG_PTYS_IB_SPEED_FDR10   BIT(3)
2786 #define MLXSW_REG_PTYS_IB_SPEED_FDR     BIT(4)
2787 #define MLXSW_REG_PTYS_IB_SPEED_EDR     BIT(5)
2788
2789 /* reg_ptys_ib_proto_cap
2790  * IB port supported speeds and protocols.
2791  * Access: RO
2792  */
2793 MLXSW_ITEM32(reg, ptys, ib_proto_cap, 0x10, 0, 16);
2794
2795 /* reg_ptys_eth_proto_admin
2796  * Speed and protocol to set port to.
2797  * Access: RW
2798  */
2799 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
2800
2801 /* reg_ptys_ib_link_width_admin
2802  * IB width to set port to.
2803  * Access: RW
2804  */
2805 MLXSW_ITEM32(reg, ptys, ib_link_width_admin, 0x1C, 16, 16);
2806
2807 /* reg_ptys_ib_proto_admin
2808  * IB speeds and protocols to set port to.
2809  * Access: RW
2810  */
2811 MLXSW_ITEM32(reg, ptys, ib_proto_admin, 0x1C, 0, 16);
2812
2813 /* reg_ptys_eth_proto_oper
2814  * The current speed and protocol configured for the port.
2815  * Access: RO
2816  */
2817 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
2818
2819 /* reg_ptys_ib_link_width_oper
2820  * The current IB width to set port to.
2821  * Access: RO
2822  */
2823 MLXSW_ITEM32(reg, ptys, ib_link_width_oper, 0x28, 16, 16);
2824
2825 /* reg_ptys_ib_proto_oper
2826  * The current IB speed and protocol.
2827  * Access: RO
2828  */
2829 MLXSW_ITEM32(reg, ptys, ib_proto_oper, 0x28, 0, 16);
2830
2831 /* reg_ptys_eth_proto_lp_advertise
2832  * The protocols that were advertised by the link partner during
2833  * autonegotiation.
2834  * Access: RO
2835  */
2836 MLXSW_ITEM32(reg, ptys, eth_proto_lp_advertise, 0x30, 0, 32);
2837
2838 static inline void mlxsw_reg_ptys_eth_pack(char *payload, u8 local_port,
2839                                            u32 proto_admin)
2840 {
2841         MLXSW_REG_ZERO(ptys, payload);
2842         mlxsw_reg_ptys_local_port_set(payload, local_port);
2843         mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
2844         mlxsw_reg_ptys_eth_proto_admin_set(payload, proto_admin);
2845 }
2846
2847 static inline void mlxsw_reg_ptys_eth_unpack(char *payload,
2848                                              u32 *p_eth_proto_cap,
2849                                              u32 *p_eth_proto_adm,
2850                                              u32 *p_eth_proto_oper)
2851 {
2852         if (p_eth_proto_cap)
2853                 *p_eth_proto_cap = mlxsw_reg_ptys_eth_proto_cap_get(payload);
2854         if (p_eth_proto_adm)
2855                 *p_eth_proto_adm = mlxsw_reg_ptys_eth_proto_admin_get(payload);
2856         if (p_eth_proto_oper)
2857                 *p_eth_proto_oper = mlxsw_reg_ptys_eth_proto_oper_get(payload);
2858 }
2859
2860 static inline void mlxsw_reg_ptys_ib_pack(char *payload, u8 local_port,
2861                                           u16 proto_admin, u16 link_width)
2862 {
2863         MLXSW_REG_ZERO(ptys, payload);
2864         mlxsw_reg_ptys_local_port_set(payload, local_port);
2865         mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_IB);
2866         mlxsw_reg_ptys_ib_proto_admin_set(payload, proto_admin);
2867         mlxsw_reg_ptys_ib_link_width_admin_set(payload, link_width);
2868 }
2869
2870 static inline void mlxsw_reg_ptys_ib_unpack(char *payload, u16 *p_ib_proto_cap,
2871                                             u16 *p_ib_link_width_cap,
2872                                             u16 *p_ib_proto_oper,
2873                                             u16 *p_ib_link_width_oper)
2874 {
2875         if (p_ib_proto_cap)
2876                 *p_ib_proto_cap = mlxsw_reg_ptys_ib_proto_cap_get(payload);
2877         if (p_ib_link_width_cap)
2878                 *p_ib_link_width_cap =
2879                         mlxsw_reg_ptys_ib_link_width_cap_get(payload);
2880         if (p_ib_proto_oper)
2881                 *p_ib_proto_oper = mlxsw_reg_ptys_ib_proto_oper_get(payload);
2882         if (p_ib_link_width_oper)
2883                 *p_ib_link_width_oper =
2884                         mlxsw_reg_ptys_ib_link_width_oper_get(payload);
2885 }
2886
2887 /* PPAD - Port Physical Address Register
2888  * -------------------------------------
2889  * The PPAD register configures the per port physical MAC address.
2890  */
2891 #define MLXSW_REG_PPAD_ID 0x5005
2892 #define MLXSW_REG_PPAD_LEN 0x10
2893
2894 MLXSW_REG_DEFINE(ppad, MLXSW_REG_PPAD_ID, MLXSW_REG_PPAD_LEN);
2895
2896 /* reg_ppad_single_base_mac
2897  * 0: base_mac, local port should be 0 and mac[7:0] is
2898  * reserved. HW will set incremental
2899  * 1: single_mac - mac of the local_port
2900  * Access: RW
2901  */
2902 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
2903
2904 /* reg_ppad_local_port
2905  * port number, if single_base_mac = 0 then local_port is reserved
2906  * Access: RW
2907  */
2908 MLXSW_ITEM32(reg, ppad, local_port, 0x00, 16, 8);
2909
2910 /* reg_ppad_mac
2911  * If single_base_mac = 0 - base MAC address, mac[7:0] is reserved.
2912  * If single_base_mac = 1 - the per port MAC address
2913  * Access: RW
2914  */
2915 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
2916
2917 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
2918                                        u8 local_port)
2919 {
2920         MLXSW_REG_ZERO(ppad, payload);
2921         mlxsw_reg_ppad_single_base_mac_set(payload, !!single_base_mac);
2922         mlxsw_reg_ppad_local_port_set(payload, local_port);
2923 }
2924
2925 /* PAOS - Ports Administrative and Operational Status Register
2926  * -----------------------------------------------------------
2927  * Configures and retrieves per port administrative and operational status.
2928  */
2929 #define MLXSW_REG_PAOS_ID 0x5006
2930 #define MLXSW_REG_PAOS_LEN 0x10
2931
2932 MLXSW_REG_DEFINE(paos, MLXSW_REG_PAOS_ID, MLXSW_REG_PAOS_LEN);
2933
2934 /* reg_paos_swid
2935  * Switch partition ID with which to associate the port.
2936  * Note: while external ports uses unique local port numbers (and thus swid is
2937  * redundant), router ports use the same local port number where swid is the
2938  * only indication for the relevant port.
2939  * Access: Index
2940  */
2941 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
2942
2943 /* reg_paos_local_port
2944  * Local port number.
2945  * Access: Index
2946  */
2947 MLXSW_ITEM32(reg, paos, local_port, 0x00, 16, 8);
2948
2949 /* reg_paos_admin_status
2950  * Port administrative state (the desired state of the port):
2951  * 1 - Up.
2952  * 2 - Down.
2953  * 3 - Up once. This means that in case of link failure, the port won't go
2954  *     into polling mode, but will wait to be re-enabled by software.
2955  * 4 - Disabled by system. Can only be set by hardware.
2956  * Access: RW
2957  */
2958 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
2959
2960 /* reg_paos_oper_status
2961  * Port operational state (the current state):
2962  * 1 - Up.
2963  * 2 - Down.
2964  * 3 - Down by port failure. This means that the device will not let the
2965  *     port up again until explicitly specified by software.
2966  * Access: RO
2967  */
2968 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
2969
2970 /* reg_paos_ase
2971  * Admin state update enabled.
2972  * Access: WO
2973  */
2974 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
2975
2976 /* reg_paos_ee
2977  * Event update enable. If this bit is set, event generation will be
2978  * updated based on the e field.
2979  * Access: WO
2980  */
2981 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
2982
2983 /* reg_paos_e
2984  * Event generation on operational state change:
2985  * 0 - Do not generate event.
2986  * 1 - Generate Event.
2987  * 2 - Generate Single Event.
2988  * Access: RW
2989  */
2990 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
2991
2992 static inline void mlxsw_reg_paos_pack(char *payload, u8 local_port,
2993                                        enum mlxsw_port_admin_status status)
2994 {
2995         MLXSW_REG_ZERO(paos, payload);
2996         mlxsw_reg_paos_swid_set(payload, 0);
2997         mlxsw_reg_paos_local_port_set(payload, local_port);
2998         mlxsw_reg_paos_admin_status_set(payload, status);
2999         mlxsw_reg_paos_oper_status_set(payload, 0);
3000         mlxsw_reg_paos_ase_set(payload, 1);
3001         mlxsw_reg_paos_ee_set(payload, 1);
3002         mlxsw_reg_paos_e_set(payload, 1);
3003 }
3004
3005 /* PFCC - Ports Flow Control Configuration Register
3006  * ------------------------------------------------
3007  * Configures and retrieves the per port flow control configuration.
3008  */
3009 #define MLXSW_REG_PFCC_ID 0x5007
3010 #define MLXSW_REG_PFCC_LEN 0x20
3011
3012 MLXSW_REG_DEFINE(pfcc, MLXSW_REG_PFCC_ID, MLXSW_REG_PFCC_LEN);
3013
3014 /* reg_pfcc_local_port
3015  * Local port number.
3016  * Access: Index
3017  */
3018 MLXSW_ITEM32(reg, pfcc, local_port, 0x00, 16, 8);
3019
3020 /* reg_pfcc_pnat
3021  * Port number access type. Determines the way local_port is interpreted:
3022  * 0 - Local port number.
3023  * 1 - IB / label port number.
3024  * Access: Index
3025  */
3026 MLXSW_ITEM32(reg, pfcc, pnat, 0x00, 14, 2);
3027
3028 /* reg_pfcc_shl_cap
3029  * Send to higher layers capabilities:
3030  * 0 - No capability of sending Pause and PFC frames to higher layers.
3031  * 1 - Device has capability of sending Pause and PFC frames to higher
3032  *     layers.
3033  * Access: RO
3034  */
3035 MLXSW_ITEM32(reg, pfcc, shl_cap, 0x00, 1, 1);
3036
3037 /* reg_pfcc_shl_opr
3038  * Send to higher layers operation:
3039  * 0 - Pause and PFC frames are handled by the port (default).
3040  * 1 - Pause and PFC frames are handled by the port and also sent to
3041  *     higher layers. Only valid if shl_cap = 1.
3042  * Access: RW
3043  */
3044 MLXSW_ITEM32(reg, pfcc, shl_opr, 0x00, 0, 1);
3045
3046 /* reg_pfcc_ppan
3047  * Pause policy auto negotiation.
3048  * 0 - Disabled. Generate / ignore Pause frames based on pptx / pprtx.
3049  * 1 - Enabled. When auto-negotiation is performed, set the Pause policy
3050  *     based on the auto-negotiation resolution.
3051  * Access: RW
3052  *
3053  * Note: The auto-negotiation advertisement is set according to pptx and
3054  * pprtx. When PFC is set on Tx / Rx, ppan must be set to 0.
3055  */
3056 MLXSW_ITEM32(reg, pfcc, ppan, 0x04, 28, 4);
3057
3058 /* reg_pfcc_prio_mask_tx
3059  * Bit per priority indicating if Tx flow control policy should be
3060  * updated based on bit pfctx.
3061  * Access: WO
3062  */
3063 MLXSW_ITEM32(reg, pfcc, prio_mask_tx, 0x04, 16, 8);
3064
3065 /* reg_pfcc_prio_mask_rx
3066  * Bit per priority indicating if Rx flow control policy should be
3067  * updated based on bit pfcrx.
3068  * Access: WO
3069  */
3070 MLXSW_ITEM32(reg, pfcc, prio_mask_rx, 0x04, 0, 8);
3071
3072 /* reg_pfcc_pptx
3073  * Admin Pause policy on Tx.
3074  * 0 - Never generate Pause frames (default).
3075  * 1 - Generate Pause frames according to Rx buffer threshold.
3076  * Access: RW
3077  */
3078 MLXSW_ITEM32(reg, pfcc, pptx, 0x08, 31, 1);
3079
3080 /* reg_pfcc_aptx
3081  * Active (operational) Pause policy on Tx.
3082  * 0 - Never generate Pause frames.
3083  * 1 - Generate Pause frames according to Rx buffer threshold.
3084  * Access: RO
3085  */
3086 MLXSW_ITEM32(reg, pfcc, aptx, 0x08, 30, 1);
3087
3088 /* reg_pfcc_pfctx
3089  * Priority based flow control policy on Tx[7:0]. Per-priority bit mask:
3090  * 0 - Never generate priority Pause frames on the specified priority
3091  *     (default).
3092  * 1 - Generate priority Pause frames according to Rx buffer threshold on
3093  *     the specified priority.
3094  * Access: RW
3095  *
3096  * Note: pfctx and pptx must be mutually exclusive.
3097  */
3098 MLXSW_ITEM32(reg, pfcc, pfctx, 0x08, 16, 8);
3099
3100 /* reg_pfcc_pprx
3101  * Admin Pause policy on Rx.
3102  * 0 - Ignore received Pause frames (default).
3103  * 1 - Respect received Pause frames.
3104  * Access: RW
3105  */
3106 MLXSW_ITEM32(reg, pfcc, pprx, 0x0C, 31, 1);
3107
3108 /* reg_pfcc_aprx
3109  * Active (operational) Pause policy on Rx.
3110  * 0 - Ignore received Pause frames.
3111  * 1 - Respect received Pause frames.
3112  * Access: RO
3113  */
3114 MLXSW_ITEM32(reg, pfcc, aprx, 0x0C, 30, 1);
3115
3116 /* reg_pfcc_pfcrx
3117  * Priority based flow control policy on Rx[7:0]. Per-priority bit mask:
3118  * 0 - Ignore incoming priority Pause frames on the specified priority
3119  *     (default).
3120  * 1 - Respect incoming priority Pause frames on the specified priority.
3121  * Access: RW
3122  */
3123 MLXSW_ITEM32(reg, pfcc, pfcrx, 0x0C, 16, 8);
3124
3125 #define MLXSW_REG_PFCC_ALL_PRIO 0xFF
3126
3127 static inline void mlxsw_reg_pfcc_prio_pack(char *payload, u8 pfc_en)
3128 {
3129         mlxsw_reg_pfcc_prio_mask_tx_set(payload, MLXSW_REG_PFCC_ALL_PRIO);
3130         mlxsw_reg_pfcc_prio_mask_rx_set(payload, MLXSW_REG_PFCC_ALL_PRIO);
3131         mlxsw_reg_pfcc_pfctx_set(payload, pfc_en);
3132         mlxsw_reg_pfcc_pfcrx_set(payload, pfc_en);
3133 }
3134
3135 static inline void mlxsw_reg_pfcc_pack(char *payload, u8 local_port)
3136 {
3137         MLXSW_REG_ZERO(pfcc, payload);
3138         mlxsw_reg_pfcc_local_port_set(payload, local_port);
3139 }
3140
3141 /* PPCNT - Ports Performance Counters Register
3142  * -------------------------------------------
3143  * The PPCNT register retrieves per port performance counters.
3144  */
3145 #define MLXSW_REG_PPCNT_ID 0x5008
3146 #define MLXSW_REG_PPCNT_LEN 0x100
3147
3148 MLXSW_REG_DEFINE(ppcnt, MLXSW_REG_PPCNT_ID, MLXSW_REG_PPCNT_LEN);
3149
3150 /* reg_ppcnt_swid
3151  * For HCA: must be always 0.
3152  * Switch partition ID to associate port with.
3153  * Switch partitions are numbered from 0 to 7 inclusively.
3154  * Switch partition 254 indicates stacking ports.
3155  * Switch partition 255 indicates all switch partitions.
3156  * Only valid on Set() operation with local_port=255.
3157  * Access: Index
3158  */
3159 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
3160
3161 /* reg_ppcnt_local_port
3162  * Local port number.
3163  * 255 indicates all ports on the device, and is only allowed
3164  * for Set() operation.
3165  * Access: Index
3166  */
3167 MLXSW_ITEM32(reg, ppcnt, local_port, 0x00, 16, 8);
3168
3169 /* reg_ppcnt_pnat
3170  * Port number access type:
3171  * 0 - Local port number
3172  * 1 - IB port number
3173  * Access: Index
3174  */
3175 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
3176
3177 enum mlxsw_reg_ppcnt_grp {
3178         MLXSW_REG_PPCNT_IEEE_8023_CNT = 0x0,
3179         MLXSW_REG_PPCNT_PRIO_CNT = 0x10,
3180         MLXSW_REG_PPCNT_TC_CNT = 0x11,
3181 };
3182
3183 /* reg_ppcnt_grp
3184  * Performance counter group.
3185  * Group 63 indicates all groups. Only valid on Set() operation with
3186  * clr bit set.
3187  * 0x0: IEEE 802.3 Counters
3188  * 0x1: RFC 2863 Counters
3189  * 0x2: RFC 2819 Counters
3190  * 0x3: RFC 3635 Counters
3191  * 0x5: Ethernet Extended Counters
3192  * 0x8: Link Level Retransmission Counters
3193  * 0x10: Per Priority Counters
3194  * 0x11: Per Traffic Class Counters
3195  * 0x12: Physical Layer Counters
3196  * Access: Index
3197  */
3198 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
3199
3200 /* reg_ppcnt_clr
3201  * Clear counters. Setting the clr bit will reset the counter value
3202  * for all counters in the counter group. This bit can be set
3203  * for both Set() and Get() operation.
3204  * Access: OP
3205  */
3206 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
3207
3208 /* reg_ppcnt_prio_tc
3209  * Priority for counter set that support per priority, valid values: 0-7.
3210  * Traffic class for counter set that support per traffic class,
3211  * valid values: 0- cap_max_tclass-1 .
3212  * For HCA: cap_max_tclass is always 8.
3213  * Otherwise must be 0.
3214  * Access: Index
3215  */
3216 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
3217
3218 /* Ethernet IEEE 802.3 Counter Group */
3219
3220 /* reg_ppcnt_a_frames_transmitted_ok
3221  * Access: RO
3222  */
3223 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
3224              0x08 + 0x00, 0, 64);
3225
3226 /* reg_ppcnt_a_frames_received_ok
3227  * Access: RO
3228  */
3229 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
3230              0x08 + 0x08, 0, 64);
3231
3232 /* reg_ppcnt_a_frame_check_sequence_errors
3233  * Access: RO
3234  */
3235 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
3236              0x08 + 0x10, 0, 64);
3237
3238 /* reg_ppcnt_a_alignment_errors
3239  * Access: RO
3240  */
3241 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
3242              0x08 + 0x18, 0, 64);
3243
3244 /* reg_ppcnt_a_octets_transmitted_ok
3245  * Access: RO
3246  */
3247 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
3248              0x08 + 0x20, 0, 64);
3249
3250 /* reg_ppcnt_a_octets_received_ok
3251  * Access: RO
3252  */
3253 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
3254              0x08 + 0x28, 0, 64);
3255
3256 /* reg_ppcnt_a_multicast_frames_xmitted_ok
3257  * Access: RO
3258  */
3259 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
3260              0x08 + 0x30, 0, 64);
3261
3262 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
3263  * Access: RO
3264  */
3265 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
3266              0x08 + 0x38, 0, 64);
3267
3268 /* reg_ppcnt_a_multicast_frames_received_ok
3269  * Access: RO
3270  */
3271 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
3272              0x08 + 0x40, 0, 64);
3273
3274 /* reg_ppcnt_a_broadcast_frames_received_ok
3275  * Access: RO
3276  */
3277 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
3278              0x08 + 0x48, 0, 64);
3279
3280 /* reg_ppcnt_a_in_range_length_errors
3281  * Access: RO
3282  */
3283 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
3284              0x08 + 0x50, 0, 64);
3285
3286 /* reg_ppcnt_a_out_of_range_length_field
3287  * Access: RO
3288  */
3289 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
3290              0x08 + 0x58, 0, 64);
3291
3292 /* reg_ppcnt_a_frame_too_long_errors
3293  * Access: RO
3294  */
3295 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
3296              0x08 + 0x60, 0, 64);
3297
3298 /* reg_ppcnt_a_symbol_error_during_carrier
3299  * Access: RO
3300  */
3301 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
3302              0x08 + 0x68, 0, 64);
3303
3304 /* reg_ppcnt_a_mac_control_frames_transmitted
3305  * Access: RO
3306  */
3307 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
3308              0x08 + 0x70, 0, 64);
3309
3310 /* reg_ppcnt_a_mac_control_frames_received
3311  * Access: RO
3312  */
3313 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
3314              0x08 + 0x78, 0, 64);
3315
3316 /* reg_ppcnt_a_unsupported_opcodes_received
3317  * Access: RO
3318  */
3319 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
3320              0x08 + 0x80, 0, 64);
3321
3322 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
3323  * Access: RO
3324  */
3325 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
3326              0x08 + 0x88, 0, 64);
3327
3328 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
3329  * Access: RO
3330  */
3331 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
3332              0x08 + 0x90, 0, 64);
3333
3334 /* Ethernet Per Priority Group Counters */
3335
3336 /* reg_ppcnt_rx_octets
3337  * Access: RO
3338  */
3339 MLXSW_ITEM64(reg, ppcnt, rx_octets, 0x08 + 0x00, 0, 64);
3340
3341 /* reg_ppcnt_rx_frames
3342  * Access: RO
3343  */
3344 MLXSW_ITEM64(reg, ppcnt, rx_frames, 0x08 + 0x20, 0, 64);
3345
3346 /* reg_ppcnt_tx_octets
3347  * Access: RO
3348  */
3349 MLXSW_ITEM64(reg, ppcnt, tx_octets, 0x08 + 0x28, 0, 64);
3350
3351 /* reg_ppcnt_tx_frames
3352  * Access: RO
3353  */
3354 MLXSW_ITEM64(reg, ppcnt, tx_frames, 0x08 + 0x48, 0, 64);
3355
3356 /* reg_ppcnt_rx_pause
3357  * Access: RO
3358  */
3359 MLXSW_ITEM64(reg, ppcnt, rx_pause, 0x08 + 0x50, 0, 64);
3360
3361 /* reg_ppcnt_rx_pause_duration
3362  * Access: RO
3363  */
3364 MLXSW_ITEM64(reg, ppcnt, rx_pause_duration, 0x08 + 0x58, 0, 64);
3365
3366 /* reg_ppcnt_tx_pause
3367  * Access: RO
3368  */
3369 MLXSW_ITEM64(reg, ppcnt, tx_pause, 0x08 + 0x60, 0, 64);
3370
3371 /* reg_ppcnt_tx_pause_duration
3372  * Access: RO
3373  */
3374 MLXSW_ITEM64(reg, ppcnt, tx_pause_duration, 0x08 + 0x68, 0, 64);
3375
3376 /* reg_ppcnt_rx_pause_transition
3377  * Access: RO
3378  */
3379 MLXSW_ITEM64(reg, ppcnt, tx_pause_transition, 0x08 + 0x70, 0, 64);
3380
3381 /* Ethernet Per Traffic Group Counters */
3382
3383 /* reg_ppcnt_tc_transmit_queue
3384  * Contains the transmit queue depth in cells of traffic class
3385  * selected by prio_tc and the port selected by local_port.
3386  * The field cannot be cleared.
3387  * Access: RO
3388  */
3389 MLXSW_ITEM64(reg, ppcnt, tc_transmit_queue, 0x08 + 0x00, 0, 64);
3390
3391 /* reg_ppcnt_tc_no_buffer_discard_uc
3392  * The number of unicast packets dropped due to lack of shared
3393  * buffer resources.
3394  * Access: RO
3395  */
3396 MLXSW_ITEM64(reg, ppcnt, tc_no_buffer_discard_uc, 0x08 + 0x08, 0, 64);
3397
3398 static inline void mlxsw_reg_ppcnt_pack(char *payload, u8 local_port,
3399                                         enum mlxsw_reg_ppcnt_grp grp,
3400                                         u8 prio_tc)
3401 {
3402         MLXSW_REG_ZERO(ppcnt, payload);
3403         mlxsw_reg_ppcnt_swid_set(payload, 0);
3404         mlxsw_reg_ppcnt_local_port_set(payload, local_port);
3405         mlxsw_reg_ppcnt_pnat_set(payload, 0);
3406         mlxsw_reg_ppcnt_grp_set(payload, grp);
3407         mlxsw_reg_ppcnt_clr_set(payload, 0);
3408         mlxsw_reg_ppcnt_prio_tc_set(payload, prio_tc);
3409 }
3410
3411 /* PLIB - Port Local to InfiniBand Port
3412  * ------------------------------------
3413  * The PLIB register performs mapping from Local Port into InfiniBand Port.
3414  */
3415 #define MLXSW_REG_PLIB_ID 0x500A
3416 #define MLXSW_REG_PLIB_LEN 0x10
3417
3418 MLXSW_REG_DEFINE(plib, MLXSW_REG_PLIB_ID, MLXSW_REG_PLIB_LEN);
3419
3420 /* reg_plib_local_port
3421  * Local port number.
3422  * Access: Index
3423  */
3424 MLXSW_ITEM32(reg, plib, local_port, 0x00, 16, 8);
3425
3426 /* reg_plib_ib_port
3427  * InfiniBand port remapping for local_port.
3428  * Access: RW
3429  */
3430 MLXSW_ITEM32(reg, plib, ib_port, 0x00, 0, 8);
3431
3432 /* PPTB - Port Prio To Buffer Register
3433  * -----------------------------------
3434  * Configures the switch priority to buffer table.
3435  */
3436 #define MLXSW_REG_PPTB_ID 0x500B
3437 #define MLXSW_REG_PPTB_LEN 0x10
3438
3439 MLXSW_REG_DEFINE(pptb, MLXSW_REG_PPTB_ID, MLXSW_REG_PPTB_LEN);
3440
3441 enum {
3442         MLXSW_REG_PPTB_MM_UM,
3443         MLXSW_REG_PPTB_MM_UNICAST,
3444         MLXSW_REG_PPTB_MM_MULTICAST,
3445 };
3446
3447 /* reg_pptb_mm
3448  * Mapping mode.
3449  * 0 - Map both unicast and multicast packets to the same buffer.
3450  * 1 - Map only unicast packets.
3451  * 2 - Map only multicast packets.
3452  * Access: Index
3453  *
3454  * Note: SwitchX-2 only supports the first option.
3455  */
3456 MLXSW_ITEM32(reg, pptb, mm, 0x00, 28, 2);
3457
3458 /* reg_pptb_local_port
3459  * Local port number.
3460  * Access: Index
3461  */
3462 MLXSW_ITEM32(reg, pptb, local_port, 0x00, 16, 8);
3463
3464 /* reg_pptb_um
3465  * Enables the update of the untagged_buf field.
3466  * Access: RW
3467  */
3468 MLXSW_ITEM32(reg, pptb, um, 0x00, 8, 1);
3469
3470 /* reg_pptb_pm
3471  * Enables the update of the prio_to_buff field.
3472  * Bit <i> is a flag for updating the mapping for switch priority <i>.
3473  * Access: RW
3474  */
3475 MLXSW_ITEM32(reg, pptb, pm, 0x00, 0, 8);
3476
3477 /* reg_pptb_prio_to_buff
3478  * Mapping of switch priority <i> to one of the allocated receive port
3479  * buffers.
3480  * Access: RW
3481  */
3482 MLXSW_ITEM_BIT_ARRAY(reg, pptb, prio_to_buff, 0x04, 0x04, 4);
3483
3484 /* reg_pptb_pm_msb
3485  * Enables the update of the prio_to_buff field.
3486  * Bit <i> is a flag for updating the mapping for switch priority <i+8>.
3487  * Access: RW
3488  */
3489 MLXSW_ITEM32(reg, pptb, pm_msb, 0x08, 24, 8);
3490
3491 /* reg_pptb_untagged_buff
3492  * Mapping of untagged frames to one of the allocated receive port buffers.
3493  * Access: RW
3494  *
3495  * Note: In SwitchX-2 this field must be mapped to buffer 8. Reserved for
3496  * Spectrum, as it maps untagged packets based on the default switch priority.
3497  */
3498 MLXSW_ITEM32(reg, pptb, untagged_buff, 0x08, 0, 4);
3499
3500 /* reg_pptb_prio_to_buff_msb
3501  * Mapping of switch priority <i+8> to one of the allocated receive port
3502  * buffers.
3503  * Access: RW
3504  */
3505 MLXSW_ITEM_BIT_ARRAY(reg, pptb, prio_to_buff_msb, 0x0C, 0x04, 4);
3506
3507 #define MLXSW_REG_PPTB_ALL_PRIO 0xFF
3508
3509 static inline void mlxsw_reg_pptb_pack(char *payload, u8 local_port)
3510 {
3511         MLXSW_REG_ZERO(pptb, payload);
3512         mlxsw_reg_pptb_mm_set(payload, MLXSW_REG_PPTB_MM_UM);
3513         mlxsw_reg_pptb_local_port_set(payload, local_port);
3514         mlxsw_reg_pptb_pm_set(payload, MLXSW_REG_PPTB_ALL_PRIO);
3515         mlxsw_reg_pptb_pm_msb_set(payload, MLXSW_REG_PPTB_ALL_PRIO);
3516 }
3517
3518 static inline void mlxsw_reg_pptb_prio_to_buff_pack(char *payload, u8 prio,
3519                                                     u8 buff)
3520 {
3521         mlxsw_reg_pptb_prio_to_buff_set(payload, prio, buff);
3522         mlxsw_reg_pptb_prio_to_buff_msb_set(payload, prio, buff);
3523 }
3524
3525 /* PBMC - Port Buffer Management Control Register
3526  * ----------------------------------------------
3527  * The PBMC register configures and retrieves the port packet buffer
3528  * allocation for different Prios, and the Pause threshold management.
3529  */
3530 #define MLXSW_REG_PBMC_ID 0x500C
3531 #define MLXSW_REG_PBMC_LEN 0x6C
3532
3533 MLXSW_REG_DEFINE(pbmc, MLXSW_REG_PBMC_ID, MLXSW_REG_PBMC_LEN);
3534
3535 /* reg_pbmc_local_port
3536  * Local port number.
3537  * Access: Index
3538  */
3539 MLXSW_ITEM32(reg, pbmc, local_port, 0x00, 16, 8);
3540
3541 /* reg_pbmc_xoff_timer_value
3542  * When device generates a pause frame, it uses this value as the pause
3543  * timer (time for the peer port to pause in quota-512 bit time).
3544  * Access: RW
3545  */
3546 MLXSW_ITEM32(reg, pbmc, xoff_timer_value, 0x04, 16, 16);
3547
3548 /* reg_pbmc_xoff_refresh
3549  * The time before a new pause frame should be sent to refresh the pause RW
3550  * state. Using the same units as xoff_timer_value above (in quota-512 bit
3551  * time).
3552  * Access: RW
3553  */
3554 MLXSW_ITEM32(reg, pbmc, xoff_refresh, 0x04, 0, 16);
3555
3556 #define MLXSW_REG_PBMC_PORT_SHARED_BUF_IDX 11
3557
3558 /* reg_pbmc_buf_lossy
3559  * The field indicates if the buffer is lossy.
3560  * 0 - Lossless
3561  * 1 - Lossy
3562  * Access: RW
3563  */
3564 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_lossy, 0x0C, 25, 1, 0x08, 0x00, false);
3565
3566 /* reg_pbmc_buf_epsb
3567  * Eligible for Port Shared buffer.
3568  * If epsb is set, packets assigned to buffer are allowed to insert the port
3569  * shared buffer.
3570  * When buf_lossy is MLXSW_REG_PBMC_LOSSY_LOSSY this field is reserved.
3571  * Access: RW
3572  */
3573 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_epsb, 0x0C, 24, 1, 0x08, 0x00, false);
3574
3575 /* reg_pbmc_buf_size
3576  * The part of the packet buffer array is allocated for the specific buffer.
3577  * Units are represented in cells.
3578  * Access: RW
3579  */
3580 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_size, 0x0C, 0, 16, 0x08, 0x00, false);
3581
3582 /* reg_pbmc_buf_xoff_threshold
3583  * Once the amount of data in the buffer goes above this value, device
3584  * starts sending PFC frames for all priorities associated with the
3585  * buffer. Units are represented in cells. Reserved in case of lossy
3586  * buffer.
3587  * Access: RW
3588  *
3589  * Note: In Spectrum, reserved for buffer[9].
3590  */
3591 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_xoff_threshold, 0x0C, 16, 16,
3592                      0x08, 0x04, false);
3593
3594 /* reg_pbmc_buf_xon_threshold
3595  * When the amount of data in the buffer goes below this value, device
3596  * stops sending PFC frames for the priorities associated with the
3597  * buffer. Units are represented in cells. Reserved in case of lossy
3598  * buffer.
3599  * Access: RW
3600  *
3601  * Note: In Spectrum, reserved for buffer[9].
3602  */
3603 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_xon_threshold, 0x0C, 0, 16,
3604                      0x08, 0x04, false);
3605
3606 static inline void mlxsw_reg_pbmc_pack(char *payload, u8 local_port,
3607                                        u16 xoff_timer_value, u16 xoff_refresh)
3608 {
3609         MLXSW_REG_ZERO(pbmc, payload);
3610         mlxsw_reg_pbmc_local_port_set(payload, local_port);
3611         mlxsw_reg_pbmc_xoff_timer_value_set(payload, xoff_timer_value);
3612         mlxsw_reg_pbmc_xoff_refresh_set(payload, xoff_refresh);
3613 }
3614
3615 static inline void mlxsw_reg_pbmc_lossy_buffer_pack(char *payload,
3616                                                     int buf_index,
3617                                                     u16 size)
3618 {
3619         mlxsw_reg_pbmc_buf_lossy_set(payload, buf_index, 1);
3620         mlxsw_reg_pbmc_buf_epsb_set(payload, buf_index, 0);
3621         mlxsw_reg_pbmc_buf_size_set(payload, buf_index, size);
3622 }
3623
3624 static inline void mlxsw_reg_pbmc_lossless_buffer_pack(char *payload,
3625                                                        int buf_index, u16 size,
3626                                                        u16 threshold)
3627 {
3628         mlxsw_reg_pbmc_buf_lossy_set(payload, buf_index, 0);
3629         mlxsw_reg_pbmc_buf_epsb_set(payload, buf_index, 0);
3630         mlxsw_reg_pbmc_buf_size_set(payload, buf_index, size);
3631         mlxsw_reg_pbmc_buf_xoff_threshold_set(payload, buf_index, threshold);
3632         mlxsw_reg_pbmc_buf_xon_threshold_set(payload, buf_index, threshold);
3633 }
3634
3635 /* PSPA - Port Switch Partition Allocation
3636  * ---------------------------------------
3637  * Controls the association of a port with a switch partition and enables
3638  * configuring ports as stacking ports.
3639  */
3640 #define MLXSW_REG_PSPA_ID 0x500D
3641 #define MLXSW_REG_PSPA_LEN 0x8
3642
3643 MLXSW_REG_DEFINE(pspa, MLXSW_REG_PSPA_ID, MLXSW_REG_PSPA_LEN);
3644
3645 /* reg_pspa_swid
3646  * Switch partition ID.
3647  * Access: RW
3648  */
3649 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
3650
3651 /* reg_pspa_local_port
3652  * Local port number.
3653  * Access: Index
3654  */
3655 MLXSW_ITEM32(reg, pspa, local_port, 0x00, 16, 8);
3656
3657 /* reg_pspa_sub_port
3658  * Virtual port within the local port. Set to 0 when virtual ports are
3659  * disabled on the local port.
3660  * Access: Index
3661  */
3662 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
3663
3664 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
3665 {
3666         MLXSW_REG_ZERO(pspa, payload);
3667         mlxsw_reg_pspa_swid_set(payload, swid);
3668         mlxsw_reg_pspa_local_port_set(payload, local_port);
3669         mlxsw_reg_pspa_sub_port_set(payload, 0);
3670 }
3671
3672 /* HTGT - Host Trap Group Table
3673  * ----------------------------
3674  * Configures the properties for forwarding to CPU.
3675  */
3676 #define MLXSW_REG_HTGT_ID 0x7002
3677 #define MLXSW_REG_HTGT_LEN 0x20
3678
3679 MLXSW_REG_DEFINE(htgt, MLXSW_REG_HTGT_ID, MLXSW_REG_HTGT_LEN);
3680
3681 /* reg_htgt_swid
3682  * Switch partition ID.
3683  * Access: Index
3684  */
3685 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
3686
3687 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0      /* For locally attached CPU */
3688
3689 /* reg_htgt_type
3690  * CPU path type.
3691  * Access: RW
3692  */
3693 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
3694
3695 enum mlxsw_reg_htgt_trap_group {
3696         MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
3697         MLXSW_REG_HTGT_TRAP_GROUP_SX2_RX,
3698         MLXSW_REG_HTGT_TRAP_GROUP_SX2_CTRL,
3699         MLXSW_REG_HTGT_TRAP_GROUP_SP_STP,
3700         MLXSW_REG_HTGT_TRAP_GROUP_SP_LACP,
3701         MLXSW_REG_HTGT_TRAP_GROUP_SP_LLDP,
3702         MLXSW_REG_HTGT_TRAP_GROUP_SP_IGMP,
3703         MLXSW_REG_HTGT_TRAP_GROUP_SP_BGP,
3704         MLXSW_REG_HTGT_TRAP_GROUP_SP_OSPF,
3705         MLXSW_REG_HTGT_TRAP_GROUP_SP_ARP,
3706         MLXSW_REG_HTGT_TRAP_GROUP_SP_HOST_MISS,
3707         MLXSW_REG_HTGT_TRAP_GROUP_SP_ROUTER_EXP,
3708         MLXSW_REG_HTGT_TRAP_GROUP_SP_REMOTE_ROUTE,
3709         MLXSW_REG_HTGT_TRAP_GROUP_SP_IP2ME,
3710         MLXSW_REG_HTGT_TRAP_GROUP_SP_DHCP,
3711         MLXSW_REG_HTGT_TRAP_GROUP_SP_EVENT,
3712         MLXSW_REG_HTGT_TRAP_GROUP_SP_IPV6_MLD,
3713         MLXSW_REG_HTGT_TRAP_GROUP_SP_IPV6_ND,
3714 };
3715
3716 /* reg_htgt_trap_group
3717  * Trap group number. User defined number specifying which trap groups
3718  * should be forwarded to the CPU. The mapping between trap IDs and trap
3719  * groups is configured using HPKT register.
3720  * Access: Index
3721  */
3722 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
3723
3724 enum {
3725         MLXSW_REG_HTGT_POLICER_DISABLE,
3726         MLXSW_REG_HTGT_POLICER_ENABLE,
3727 };
3728
3729 /* reg_htgt_pide
3730  * Enable policer ID specified using 'pid' field.
3731  * Access: RW
3732  */
3733 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
3734
3735 #define MLXSW_REG_HTGT_INVALID_POLICER 0xff
3736
3737 /* reg_htgt_pid
3738  * Policer ID for the trap group.
3739  * Access: RW
3740  */
3741 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
3742
3743 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
3744
3745 /* reg_htgt_mirror_action
3746  * Mirror action to use.
3747  * 0 - Trap to CPU.
3748  * 1 - Trap to CPU and mirror to a mirroring agent.
3749  * 2 - Mirror to a mirroring agent and do not trap to CPU.
3750  * Access: RW
3751  *
3752  * Note: Mirroring to a mirroring agent is only supported in Spectrum.
3753  */
3754 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
3755
3756 /* reg_htgt_mirroring_agent
3757  * Mirroring agent.
3758  * Access: RW
3759  */
3760 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
3761
3762 #define MLXSW_REG_HTGT_DEFAULT_PRIORITY 0
3763
3764 /* reg_htgt_priority
3765  * Trap group priority.
3766  * In case a packet matches multiple classification rules, the packet will
3767  * only be trapped once, based on the trap ID associated with the group (via
3768  * register HPKT) with the highest priority.
3769  * Supported values are 0-7, with 7 represnting the highest priority.
3770  * Access: RW
3771  *
3772  * Note: In SwitchX-2 this field is ignored and the priority value is replaced
3773  * by the 'trap_group' field.
3774  */
3775 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
3776
3777 #define MLXSW_REG_HTGT_DEFAULT_TC 7
3778
3779 /* reg_htgt_local_path_cpu_tclass
3780  * CPU ingress traffic class for the trap group.
3781  * Access: RW
3782  */
3783 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
3784
3785 enum mlxsw_reg_htgt_local_path_rdq {
3786         MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_CTRL = 0x13,
3787         MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_RX = 0x14,
3788         MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_EMAD = 0x15,
3789         MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SIB_EMAD = 0x15,
3790 };
3791 /* reg_htgt_local_path_rdq
3792  * Receive descriptor queue (RDQ) to use for the trap group.
3793  * Access: RW
3794  */
3795 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
3796
3797 static inline void mlxsw_reg_htgt_pack(char *payload, u8 group, u8 policer_id,
3798                                        u8 priority, u8 tc)
3799 {
3800         MLXSW_REG_ZERO(htgt, payload);
3801
3802         if (policer_id == MLXSW_REG_HTGT_INVALID_POLICER) {
3803                 mlxsw_reg_htgt_pide_set(payload,
3804                                         MLXSW_REG_HTGT_POLICER_DISABLE);
3805         } else {
3806                 mlxsw_reg_htgt_pide_set(payload,
3807                                         MLXSW_REG_HTGT_POLICER_ENABLE);
3808                 mlxsw_reg_htgt_pid_set(payload, policer_id);
3809         }
3810
3811         mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
3812         mlxsw_reg_htgt_trap_group_set(payload, group);
3813         mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
3814         mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
3815         mlxsw_reg_htgt_priority_set(payload, priority);
3816         mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, tc);
3817         mlxsw_reg_htgt_local_path_rdq_set(payload, group);
3818 }
3819
3820 /* HPKT - Host Packet Trap
3821  * -----------------------
3822  * Configures trap IDs inside trap groups.
3823  */
3824 #define MLXSW_REG_HPKT_ID 0x7003
3825 #define MLXSW_REG_HPKT_LEN 0x10
3826
3827 MLXSW_REG_DEFINE(hpkt, MLXSW_REG_HPKT_ID, MLXSW_REG_HPKT_LEN);
3828
3829 enum {
3830         MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
3831         MLXSW_REG_HPKT_ACK_REQUIRED,
3832 };
3833
3834 /* reg_hpkt_ack
3835  * Require acknowledgements from the host for events.
3836  * If set, then the device will wait for the event it sent to be acknowledged
3837  * by the host. This option is only relevant for event trap IDs.
3838  * Access: RW
3839  *
3840  * Note: Currently not supported by firmware.
3841  */
3842 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
3843
3844 enum mlxsw_reg_hpkt_action {
3845         MLXSW_REG_HPKT_ACTION_FORWARD,
3846         MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
3847         MLXSW_REG_HPKT_ACTION_MIRROR_TO_CPU,
3848         MLXSW_REG_HPKT_ACTION_DISCARD,
3849         MLXSW_REG_HPKT_ACTION_SOFT_DISCARD,
3850         MLXSW_REG_HPKT_ACTION_TRAP_AND_SOFT_DISCARD,
3851 };
3852
3853 /* reg_hpkt_action
3854  * Action to perform on packet when trapped.
3855  * 0 - No action. Forward to CPU based on switching rules.
3856  * 1 - Trap to CPU (CPU receives sole copy).
3857  * 2 - Mirror to CPU (CPU receives a replica of the packet).
3858  * 3 - Discard.
3859  * 4 - Soft discard (allow other traps to act on the packet).
3860  * 5 - Trap and soft discard (allow other traps to overwrite this trap).
3861  * Access: RW
3862  *
3863  * Note: Must be set to 0 (forward) for event trap IDs, as they are already
3864  * addressed to the CPU.
3865  */
3866 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
3867
3868 /* reg_hpkt_trap_group
3869  * Trap group to associate the trap with.
3870  * Access: RW
3871  */
3872 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
3873
3874 /* reg_hpkt_trap_id
3875  * Trap ID.
3876  * Access: Index
3877  *
3878  * Note: A trap ID can only be associated with a single trap group. The device
3879  * will associate the trap ID with the last trap group configured.
3880  */
3881 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 9);
3882
3883 enum {
3884         MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
3885         MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
3886         MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
3887 };
3888
3889 /* reg_hpkt_ctrl
3890  * Configure dedicated buffer resources for control packets.
3891  * Ignored by SwitchX-2.
3892  * 0 - Keep factory defaults.
3893  * 1 - Do not use control buffer for this trap ID.
3894  * 2 - Use control buffer for this trap ID.
3895  * Access: RW
3896  */
3897 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
3898
3899 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id,
3900                                        enum mlxsw_reg_htgt_trap_group trap_group,
3901                                        bool is_ctrl)
3902 {
3903         MLXSW_REG_ZERO(hpkt, payload);
3904         mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
3905         mlxsw_reg_hpkt_action_set(payload, action);
3906         mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
3907         mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
3908         mlxsw_reg_hpkt_ctrl_set(payload, is_ctrl ?
3909                                 MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER :
3910                                 MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER);
3911 }
3912
3913 /* RGCR - Router General Configuration Register
3914  * --------------------------------------------
3915  * The register is used for setting up the router configuration.
3916  */
3917 #define MLXSW_REG_RGCR_ID 0x8001
3918 #define MLXSW_REG_RGCR_LEN 0x28
3919
3920 MLXSW_REG_DEFINE(rgcr, MLXSW_REG_RGCR_ID, MLXSW_REG_RGCR_LEN);
3921
3922 /* reg_rgcr_ipv4_en
3923  * IPv4 router enable.
3924  * Access: RW
3925  */
3926 MLXSW_ITEM32(reg, rgcr, ipv4_en, 0x00, 31, 1);
3927
3928 /* reg_rgcr_ipv6_en
3929  * IPv6 router enable.
3930  * Access: RW
3931  */
3932 MLXSW_ITEM32(reg, rgcr, ipv6_en, 0x00, 30, 1);
3933
3934 /* reg_rgcr_max_router_interfaces
3935  * Defines the maximum number of active router interfaces for all virtual
3936  * routers.
3937  * Access: RW
3938  */
3939 MLXSW_ITEM32(reg, rgcr, max_router_interfaces, 0x10, 0, 16);
3940
3941 /* reg_rgcr_usp
3942  * Update switch priority and packet color.
3943  * 0 - Preserve the value of Switch Priority and packet color.
3944  * 1 - Recalculate the value of Switch Priority and packet color.
3945  * Access: RW
3946  *
3947  * Note: Not supported by SwitchX and SwitchX-2.
3948  */
3949 MLXSW_ITEM32(reg, rgcr, usp, 0x18, 20, 1);
3950
3951 /* reg_rgcr_pcp_rw
3952  * Indicates how to handle the pcp_rewrite_en value:
3953  * 0 - Preserve the value of pcp_rewrite_en.
3954  * 2 - Disable PCP rewrite.
3955  * 3 - Enable PCP rewrite.
3956  * Access: RW
3957  *
3958  * Note: Not supported by SwitchX and SwitchX-2.
3959  */
3960 MLXSW_ITEM32(reg, rgcr, pcp_rw, 0x18, 16, 2);
3961
3962 /* reg_rgcr_activity_dis
3963  * Activity disable:
3964  * 0 - Activity will be set when an entry is hit (default).
3965  * 1 - Activity will not be set when an entry is hit.
3966  *
3967  * Bit 0 - Disable activity bit in Router Algorithmic LPM Unicast Entry
3968  * (RALUE).
3969  * Bit 1 - Disable activity bit in Router Algorithmic LPM Unicast Host
3970  * Entry (RAUHT).
3971  * Bits 2:7 are reserved.
3972  * Access: RW
3973  *
3974  * Note: Not supported by SwitchX, SwitchX-2 and Switch-IB.
3975  */
3976 MLXSW_ITEM32(reg, rgcr, activity_dis, 0x20, 0, 8);
3977
3978 static inline void mlxsw_reg_rgcr_pack(char *payload, bool ipv4_en,
3979                                        bool ipv6_en)
3980 {
3981         MLXSW_REG_ZERO(rgcr, payload);
3982         mlxsw_reg_rgcr_ipv4_en_set(payload, ipv4_en);
3983         mlxsw_reg_rgcr_ipv6_en_set(payload, ipv6_en);
3984 }
3985
3986 /* RITR - Router Interface Table Register
3987  * --------------------------------------
3988  * The register is used to configure the router interface table.
3989  */
3990 #define MLXSW_REG_RITR_ID 0x8002
3991 #define MLXSW_REG_RITR_LEN 0x40
3992
3993 MLXSW_REG_DEFINE(ritr, MLXSW_REG_RITR_ID, MLXSW_REG_RITR_LEN);
3994
3995 /* reg_ritr_enable
3996  * Enables routing on the router interface.
3997  * Access: RW
3998  */
3999 MLXSW_ITEM32(reg, ritr, enable, 0x00, 31, 1);
4000
4001 /* reg_ritr_ipv4
4002  * IPv4 routing enable. Enables routing of IPv4 traffic on the router
4003  * interface.
4004  * Access: RW
4005  */
4006 MLXSW_ITEM32(reg, ritr, ipv4, 0x00, 29, 1);
4007
4008 /* reg_ritr_ipv6
4009  * IPv6 routing enable. Enables routing of IPv6 traffic on the router
4010  * interface.
4011  * Access: RW
4012  */
4013 MLXSW_ITEM32(reg, ritr, ipv6, 0x00, 28, 1);
4014
4015 enum mlxsw_reg_ritr_if_type {
4016         /* VLAN interface. */
4017         MLXSW_REG_RITR_VLAN_IF,
4018         /* FID interface. */
4019         MLXSW_REG_RITR_FID_IF,
4020         /* Sub-port interface. */
4021         MLXSW_REG_RITR_SP_IF,
4022         /* Loopback Interface. */
4023         MLXSW_REG_RITR_LOOPBACK_IF,
4024 };
4025
4026 /* reg_ritr_type
4027  * Router interface type as per enum mlxsw_reg_ritr_if_type.
4028  * Access: RW
4029  */
4030 MLXSW_ITEM32(reg, ritr, type, 0x00, 23, 3);
4031
4032 enum {
4033         MLXSW_REG_RITR_RIF_CREATE,
4034         MLXSW_REG_RITR_RIF_DEL,
4035 };
4036
4037 /* reg_ritr_op
4038  * Opcode:
4039  * 0 - Create or edit RIF.
4040  * 1 - Delete RIF.
4041  * Reserved for SwitchX-2. For Spectrum, editing of interface properties
4042  * is not supported. An interface must be deleted and re-created in order
4043  * to update properties.
4044  * Access: WO
4045  */
4046 MLXSW_ITEM32(reg, ritr, op, 0x00, 20, 2);
4047
4048 /* reg_ritr_rif
4049  * Router interface index. A pointer to the Router Interface Table.
4050  * Access: Index
4051  */
4052 MLXSW_ITEM32(reg, ritr, rif, 0x00, 0, 16);
4053
4054 /* reg_ritr_ipv4_fe
4055  * IPv4 Forwarding Enable.
4056  * Enables routing of IPv4 traffic on the router interface. When disabled,
4057  * forwarding is blocked but local traffic (traps and IP2ME) will be enabled.
4058  * Not supported in SwitchX-2.
4059  * Access: RW
4060  */
4061 MLXSW_ITEM32(reg, ritr, ipv4_fe, 0x04, 29, 1);
4062
4063 /* reg_ritr_ipv6_fe
4064  * IPv6 Forwarding Enable.
4065  * Enables routing of IPv6 traffic on the router interface. When disabled,
4066  * forwarding is blocked but local traffic (traps and IP2ME) will be enabled.
4067  * Not supported in SwitchX-2.
4068  * Access: RW
4069  */
4070 MLXSW_ITEM32(reg, ritr, ipv6_fe, 0x04, 28, 1);
4071
4072 /* reg_ritr_lb_en
4073  * Loop-back filter enable for unicast packets.
4074  * If the flag is set then loop-back filter for unicast packets is
4075  * implemented on the RIF. Multicast packets are always subject to
4076  * loop-back filtering.
4077  * Access: RW
4078  */
4079 MLXSW_ITEM32(reg, ritr, lb_en, 0x04, 24, 1);
4080
4081 /* reg_ritr_virtual_router
4082  * Virtual router ID associated with the router interface.
4083  * Access: RW
4084  */
4085 MLXSW_ITEM32(reg, ritr, virtual_router, 0x04, 0, 16);
4086
4087 /* reg_ritr_mtu
4088  * Router interface MTU.
4089  * Access: RW
4090  */
4091 MLXSW_ITEM32(reg, ritr, mtu, 0x34, 0, 16);
4092
4093 /* reg_ritr_if_swid
4094  * Switch partition ID.
4095  * Access: RW
4096  */
4097 MLXSW_ITEM32(reg, ritr, if_swid, 0x08, 24, 8);
4098
4099 /* reg_ritr_if_mac
4100  * Router interface MAC address.
4101  * In Spectrum, all MAC addresses must have the same 38 MSBits.
4102  * Access: RW
4103  */
4104 MLXSW_ITEM_BUF(reg, ritr, if_mac, 0x12, 6);
4105
4106 /* VLAN Interface */
4107
4108 /* reg_ritr_vlan_if_vid
4109  * VLAN ID.
4110  * Access: RW
4111  */
4112 MLXSW_ITEM32(reg, ritr, vlan_if_vid, 0x08, 0, 12);
4113
4114 /* FID Interface */
4115
4116 /* reg_ritr_fid_if_fid
4117  * Filtering ID. Used to connect a bridge to the router. Only FIDs from
4118  * the vFID range are supported.
4119  * Access: RW
4120  */
4121 MLXSW_ITEM32(reg, ritr, fid_if_fid, 0x08, 0, 16);
4122
4123 static inline void mlxsw_reg_ritr_fid_set(char *payload,
4124                                           enum mlxsw_reg_ritr_if_type rif_type,
4125                                           u16 fid)
4126 {
4127         if (rif_type == MLXSW_REG_RITR_FID_IF)
4128                 mlxsw_reg_ritr_fid_if_fid_set(payload, fid);
4129         else
4130                 mlxsw_reg_ritr_vlan_if_vid_set(payload, fid);
4131 }
4132
4133 /* Sub-port Interface */
4134
4135 /* reg_ritr_sp_if_lag
4136  * LAG indication. When this bit is set the system_port field holds the
4137  * LAG identifier.
4138  * Access: RW
4139  */
4140 MLXSW_ITEM32(reg, ritr, sp_if_lag, 0x08, 24, 1);
4141
4142 /* reg_ritr_sp_system_port
4143  * Port unique indentifier. When lag bit is set, this field holds the
4144  * lag_id in bits 0:9.
4145  * Access: RW
4146  */
4147 MLXSW_ITEM32(reg, ritr, sp_if_system_port, 0x08, 0, 16);
4148
4149 /* reg_ritr_sp_if_vid
4150  * VLAN ID.
4151  * Access: RW
4152  */
4153 MLXSW_ITEM32(reg, ritr, sp_if_vid, 0x18, 0, 12);
4154
4155 /* Loopback Interface */
4156
4157 enum mlxsw_reg_ritr_loopback_protocol {
4158         /* IPinIP IPv4 underlay Unicast */
4159         MLXSW_REG_RITR_LOOPBACK_PROTOCOL_IPIP_IPV4,
4160         /* IPinIP IPv6 underlay Unicast */
4161         MLXSW_REG_RITR_LOOPBACK_PROTOCOL_IPIP_IPV6,
4162 };
4163
4164 /* reg_ritr_loopback_protocol
4165  * Access: RW
4166  */
4167 MLXSW_ITEM32(reg, ritr, loopback_protocol, 0x08, 28, 4);
4168
4169 enum mlxsw_reg_ritr_loopback_ipip_type {
4170         /* Tunnel is IPinIP. */
4171         MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_IP,
4172         /* Tunnel is GRE, no key. */
4173         MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_GRE_IN_IP,
4174         /* Tunnel is GRE, with a key. */
4175         MLXSW_REG_RITR_LOOPBACK_IPIP_TYPE_IP_IN_GRE_KEY_IN_IP,
4176 };
4177
4178 /* reg_ritr_loopback_ipip_type
4179  * Encapsulation type.
4180  * Access: RW
4181  */
4182 MLXSW_ITEM32(reg, ritr, loopback_ipip_type, 0x10, 24, 4);
4183
4184 enum mlxsw_reg_ritr_loopback_ipip_options {
4185         /* The key is defined by gre_key. */
4186         MLXSW_REG_RITR_LOOPBACK_IPIP_OPTIONS_GRE_KEY_PRESET,
4187 };
4188
4189 /* reg_ritr_loopback_ipip_options
4190  * Access: RW
4191  */
4192 MLXSW_ITEM32(reg, ritr, loopback_ipip_options, 0x10, 20, 4);
4193
4194 /* reg_ritr_loopback_ipip_uvr
4195  * Underlay Virtual Router ID.
4196  * Range is 0..cap_max_virtual_routers-1.
4197  * Reserved for Spectrum-2.
4198  * Access: RW
4199  */
4200 MLXSW_ITEM32(reg, ritr, loopback_ipip_uvr, 0x10, 0, 16);
4201
4202 /* reg_ritr_loopback_ipip_usip*
4203  * Encapsulation Underlay source IP.
4204  * Access: RW
4205  */
4206 MLXSW_ITEM_BUF(reg, ritr, loopback_ipip_usip6, 0x18, 16);
4207 MLXSW_ITEM32(reg, ritr, loopback_ipip_usip4, 0x24, 0, 32);
4208
4209 /* reg_ritr_loopback_ipip_gre_key
4210  * GRE Key.
4211  * Reserved when ipip_type is not IP_IN_GRE_KEY_IN_IP.
4212  * Access: RW
4213  */
4214 MLXSW_ITEM32(reg, ritr, loopback_ipip_gre_key, 0x28, 0, 32);
4215
4216 /* Shared between ingress/egress */
4217 enum mlxsw_reg_ritr_counter_set_type {
4218         /* No Count. */
4219         MLXSW_REG_RITR_COUNTER_SET_TYPE_NO_COUNT = 0x0,
4220         /* Basic. Used for router interfaces, counting the following:
4221          *      - Error and Discard counters.
4222          *      - Unicast, Multicast and Broadcast counters. Sharing the
4223          *        same set of counters for the different type of traffic
4224          *        (IPv4, IPv6 and mpls).
4225          */
4226         MLXSW_REG_RITR_COUNTER_SET_TYPE_BASIC = 0x9,
4227 };
4228
4229 /* reg_ritr_ingress_counter_index
4230  * Counter Index for flow counter.
4231  * Access: RW
4232  */
4233 MLXSW_ITEM32(reg, ritr, ingress_counter_index, 0x38, 0, 24);
4234
4235 /* reg_ritr_ingress_counter_set_type
4236  * Igress Counter Set Type for router interface counter.
4237  * Access: RW
4238  */
4239 MLXSW_ITEM32(reg, ritr, ingress_counter_set_type, 0x38, 24, 8);
4240
4241 /* reg_ritr_egress_counter_index
4242  * Counter Index for flow counter.
4243  * Access: RW
4244  */
4245 MLXSW_ITEM32(reg, ritr, egress_counter_index, 0x3C, 0, 24);
4246
4247 /* reg_ritr_egress_counter_set_type
4248  * Egress Counter Set Type for router interface counter.
4249  * Access: RW
4250  */
4251 MLXSW_ITEM32(reg, ritr, egress_counter_set_type, 0x3C, 24, 8);
4252
4253 static inline void mlxsw_reg_ritr_counter_pack(char *payload, u32 index,
4254                                                bool enable, bool egress)
4255 {
4256         enum mlxsw_reg_ritr_counter_set_type set_type;
4257
4258         if (enable)
4259                 set_type = MLXSW_REG_RITR_COUNTER_SET_TYPE_BASIC;
4260         else
4261                 set_type = MLXSW_REG_RITR_COUNTER_SET_TYPE_NO_COUNT;
4262         mlxsw_reg_ritr_egress_counter_set_type_set(payload, set_type);
4263
4264         if (egress)
4265                 mlxsw_reg_ritr_egress_counter_index_set(payload, index);
4266         else
4267                 mlxsw_reg_ritr_ingress_counter_index_set(payload, index);
4268 }
4269
4270 static inline void mlxsw_reg_ritr_rif_pack(char *payload, u16 rif)
4271 {
4272         MLXSW_REG_ZERO(ritr, payload);
4273         mlxsw_reg_ritr_rif_set(payload, rif);
4274 }
4275
4276 static inline void mlxsw_reg_ritr_sp_if_pack(char *payload, bool lag,
4277                                              u16 system_port, u16 vid)
4278 {
4279         mlxsw_reg_ritr_sp_if_lag_set(payload, lag);
4280         mlxsw_reg_ritr_sp_if_system_port_set(payload, system_port);
4281         mlxsw_reg_ritr_sp_if_vid_set(payload, vid);
4282 }
4283
4284 static inline void mlxsw_reg_ritr_pack(char *payload, bool enable,
4285                                        enum mlxsw_reg_ritr_if_type type,
4286                                        u16 rif, u16 vr_id, u16 mtu)
4287 {
4288         bool op = enable ? MLXSW_REG_RITR_RIF_CREATE : MLXSW_REG_RITR_RIF_DEL;
4289
4290         MLXSW_REG_ZERO(ritr, payload);
4291         mlxsw_reg_ritr_enable_set(payload, enable);
4292         mlxsw_reg_ritr_ipv4_set(payload, 1);
4293         mlxsw_reg_ritr_ipv6_set(payload, 1);
4294         mlxsw_reg_ritr_type_set(payload, type);
4295         mlxsw_reg_ritr_op_set(payload, op);
4296         mlxsw_reg_ritr_rif_set(payload, rif);
4297         mlxsw_reg_ritr_ipv4_fe_set(payload, 1);
4298         mlxsw_reg_ritr_ipv6_fe_set(payload, 1);
4299         mlxsw_reg_ritr_lb_en_set(payload, 1);
4300         mlxsw_reg_ritr_virtual_router_set(payload, vr_id);
4301         mlxsw_reg_ritr_mtu_set(payload, mtu);
4302 }
4303
4304 static inline void mlxsw_reg_ritr_mac_pack(char *payload, const char *mac)
4305 {
4306         mlxsw_reg_ritr_if_mac_memcpy_to(payload, mac);
4307 }
4308
4309 static inline void
4310 mlxsw_reg_ritr_loopback_ipip_common_pack(char *payload,
4311                             enum mlxsw_reg_ritr_loopback_ipip_type ipip_type,
4312                             enum mlxsw_reg_ritr_loopback_ipip_options options,
4313                             u16 uvr_id, u32 gre_key)
4314 {
4315         mlxsw_reg_ritr_loopback_ipip_type_set(payload, ipip_type);
4316         mlxsw_reg_ritr_loopback_ipip_options_set(payload, options);
4317         mlxsw_reg_ritr_loopback_ipip_uvr_set(payload, uvr_id);
4318         mlxsw_reg_ritr_loopback_ipip_gre_key_set(payload, gre_key);
4319 }
4320
4321 static inline void
4322 mlxsw_reg_ritr_loopback_ipip4_pack(char *payload,
4323                             enum mlxsw_reg_ritr_loopback_ipip_type ipip_type,
4324                             enum mlxsw_reg_ritr_loopback_ipip_options options,
4325                             u16 uvr_id, u32 usip, u32 gre_key)
4326 {
4327         mlxsw_reg_ritr_loopback_protocol_set(payload,
4328                                     MLXSW_REG_RITR_LOOPBACK_PROTOCOL_IPIP_IPV4);
4329         mlxsw_reg_ritr_loopback_ipip_common_pack(payload, ipip_type, options,
4330                                                  uvr_id, gre_key);
4331         mlxsw_reg_ritr_loopback_ipip_usip4_set(payload, usip);
4332 }
4333
4334 /* RATR - Router Adjacency Table Register
4335  * --------------------------------------
4336  * The RATR register is used to configure the Router Adjacency (next-hop)
4337  * Table.
4338  */
4339 #define MLXSW_REG_RATR_ID 0x8008
4340 #define MLXSW_REG_RATR_LEN 0x2C
4341
4342 MLXSW_REG_DEFINE(ratr, MLXSW_REG_RATR_ID, MLXSW_REG_RATR_LEN);
4343
4344 enum mlxsw_reg_ratr_op {
4345         /* Read */
4346         MLXSW_REG_RATR_OP_QUERY_READ = 0,
4347         /* Read and clear activity */
4348         MLXSW_REG_RATR_OP_QUERY_READ_CLEAR = 2,
4349         /* Write Adjacency entry */
4350         MLXSW_REG_RATR_OP_WRITE_WRITE_ENTRY = 1,
4351         /* Write Adjacency entry only if the activity is cleared.
4352          * The write may not succeed if the activity is set. There is not
4353          * direct feedback if the write has succeeded or not, however
4354          * the get will reveal the actual entry (SW can compare the get
4355          * response to the set command).
4356          */
4357         MLXSW_REG_RATR_OP_WRITE_WRITE_ENTRY_ON_ACTIVITY = 3,
4358 };
4359
4360 /* reg_ratr_op
4361  * Note that Write operation may also be used for updating
4362  * counter_set_type and counter_index. In this case all other
4363  * fields must not be updated.
4364  * Access: OP
4365  */
4366 MLXSW_ITEM32(reg, ratr, op, 0x00, 28, 4);
4367
4368 /* reg_ratr_v
4369  * Valid bit. Indicates if the adjacency entry is valid.
4370  * Note: the device may need some time before reusing an invalidated
4371  * entry. During this time the entry can not be reused. It is
4372  * recommended to use another entry before reusing an invalidated
4373  * entry (e.g. software can put it at the end of the list for
4374  * reusing). Trying to access an invalidated entry not yet cleared
4375  * by the device results with failure indicating "Try Again" status.
4376  * When valid is '0' then egress_router_interface,trap_action,
4377  * adjacency_parameters and counters are reserved
4378  * Access: RW
4379  */
4380 MLXSW_ITEM32(reg, ratr, v, 0x00, 24, 1);
4381
4382 /* reg_ratr_a
4383  * Activity. Set for new entries. Set if a packet lookup has hit on
4384  * the specific entry. To clear the a bit, use "clear activity".
4385  * Access: RO
4386  */
4387 MLXSW_ITEM32(reg, ratr, a, 0x00, 16, 1);
4388
4389 enum mlxsw_reg_ratr_type {
4390         /* Ethernet */
4391         MLXSW_REG_RATR_TYPE_ETHERNET,
4392         /* IPoIB Unicast without GRH.
4393          * Reserved for Spectrum.
4394          */
4395         MLXSW_REG_RATR_TYPE_IPOIB_UC,
4396         /* IPoIB Unicast with GRH. Supported only in table 0 (Ethernet unicast
4397          * adjacency).
4398          * Reserved for Spectrum.
4399          */
4400         MLXSW_REG_RATR_TYPE_IPOIB_UC_W_GRH,
4401         /* IPoIB Multicast.
4402          * Reserved for Spectrum.
4403          */
4404         MLXSW_REG_RATR_TYPE_IPOIB_MC,
4405         /* MPLS.
4406          * Reserved for SwitchX/-2.
4407          */
4408         MLXSW_REG_RATR_TYPE_MPLS,
4409         /* IPinIP Encap.
4410          * Reserved for SwitchX/-2.
4411          */
4412         MLXSW_REG_RATR_TYPE_IPIP,
4413 };
4414
4415 /* reg_ratr_type
4416  * Adjacency entry type.
4417  * Access: RW
4418  */
4419 MLXSW_ITEM32(reg, ratr, type, 0x04, 28, 4);
4420
4421 /* reg_ratr_adjacency_index_low
4422  * Bits 15:0 of index into the adjacency table.
4423  * For SwitchX and SwitchX-2, the adjacency table is linear and
4424  * used for adjacency entries only.
4425  * For Spectrum, the index is to the KVD linear.
4426  * Access: Index
4427  */
4428 MLXSW_ITEM32(reg, ratr, adjacency_index_low, 0x04, 0, 16);
4429
4430 /* reg_ratr_egress_router_interface
4431  * Range is 0 .. cap_max_router_interfaces - 1
4432  * Access: RW
4433  */
4434 MLXSW_ITEM32(reg, ratr, egress_router_interface, 0x08, 0, 16);
4435
4436 enum mlxsw_reg_ratr_trap_action {
4437         MLXSW_REG_RATR_TRAP_ACTION_NOP,
4438         MLXSW_REG_RATR_TRAP_ACTION_TRAP,
4439         MLXSW_REG_RATR_TRAP_ACTION_MIRROR_TO_CPU,
4440         MLXSW_REG_RATR_TRAP_ACTION_MIRROR,
4441         MLXSW_REG_RATR_TRAP_ACTION_DISCARD_ERRORS,
4442 };
4443
4444 /* reg_ratr_trap_action
4445  * see mlxsw_reg_ratr_trap_action
4446  * Access: RW
4447  */
4448 MLXSW_ITEM32(reg, ratr, trap_action, 0x0C, 28, 4);
4449
4450 /* reg_ratr_adjacency_index_high
4451  * Bits 23:16 of the adjacency_index.
4452  * Access: Index
4453  */
4454 MLXSW_ITEM32(reg, ratr, adjacency_index_high, 0x0C, 16, 8);
4455
4456 enum mlxsw_reg_ratr_trap_id {
4457         MLXSW_REG_RATR_TRAP_ID_RTR_EGRESS0,
4458         MLXSW_REG_RATR_TRAP_ID_RTR_EGRESS1,
4459 };
4460
4461 /* reg_ratr_trap_id
4462  * Trap ID to be reported to CPU.
4463  * Trap-ID is RTR_EGRESS0 or RTR_EGRESS1.
4464  * For trap_action of NOP, MIRROR and DISCARD_ERROR
4465  * Access: RW
4466  */
4467 MLXSW_ITEM32(reg, ratr, trap_id, 0x0C, 0, 8);
4468
4469 /* reg_ratr_eth_destination_mac
4470  * MAC address of the destination next-hop.
4471  * Access: RW
4472  */
4473 MLXSW_ITEM_BUF(reg, ratr, eth_destination_mac, 0x12, 6);
4474
4475 enum mlxsw_reg_ratr_ipip_type {
4476         /* IPv4, address set by mlxsw_reg_ratr_ipip_ipv4_udip. */
4477         MLXSW_REG_RATR_IPIP_TYPE_IPV4,
4478         /* IPv6, address set by mlxsw_reg_ratr_ipip_ipv6_ptr. */
4479         MLXSW_REG_RATR_IPIP_TYPE_IPV6,
4480 };
4481
4482 /* reg_ratr_ipip_type
4483  * Underlay destination ip type.
4484  * Note: the type field must match the protocol of the router interface.
4485  * Access: RW
4486  */
4487 MLXSW_ITEM32(reg, ratr, ipip_type, 0x10, 16, 4);
4488
4489 /* reg_ratr_ipip_ipv4_udip
4490  * Underlay ipv4 dip.
4491  * Reserved when ipip_type is IPv6.
4492  * Access: RW
4493  */
4494 MLXSW_ITEM32(reg, ratr, ipip_ipv4_udip, 0x18, 0, 32);
4495
4496 /* reg_ratr_ipip_ipv6_ptr
4497  * Pointer to IPv6 underlay destination ip address.
4498  * For Spectrum: Pointer to KVD linear space.
4499  * Access: RW
4500  */
4501 MLXSW_ITEM32(reg, ratr, ipip_ipv6_ptr, 0x1C, 0, 24);
4502
4503 static inline void
4504 mlxsw_reg_ratr_pack(char *payload,
4505                     enum mlxsw_reg_ratr_op op, bool valid,
4506                     enum mlxsw_reg_ratr_type type,
4507                     u32 adjacency_index, u16 egress_rif)
4508 {
4509         MLXSW_REG_ZERO(ratr, payload);
4510         mlxsw_reg_ratr_op_set(payload, op);
4511         mlxsw_reg_ratr_v_set(payload, valid);
4512         mlxsw_reg_ratr_type_set(payload, type);
4513         mlxsw_reg_ratr_adjacency_index_low_set(payload, adjacency_index);
4514         mlxsw_reg_ratr_adjacency_index_high_set(payload, adjacency_index >> 16);
4515         mlxsw_reg_ratr_egress_router_interface_set(payload, egress_rif);
4516 }
4517
4518 static inline void mlxsw_reg_ratr_eth_entry_pack(char *payload,
4519                                                  const char *dest_mac)
4520 {
4521         mlxsw_reg_ratr_eth_destination_mac_memcpy_to(payload, dest_mac);
4522 }
4523
4524 static inline void mlxsw_reg_ratr_ipip4_entry_pack(char *payload, u32 ipv4_udip)
4525 {
4526         mlxsw_reg_ratr_ipip_type_set(payload, MLXSW_REG_RATR_IPIP_TYPE_IPV4);
4527         mlxsw_reg_ratr_ipip_ipv4_udip_set(payload, ipv4_udip);
4528 }
4529
4530 /* RICNT - Router Interface Counter Register
4531  * -----------------------------------------
4532  * The RICNT register retrieves per port performance counters
4533  */
4534 #define MLXSW_REG_RICNT_ID 0x800B
4535 #define MLXSW_REG_RICNT_LEN 0x100
4536
4537 MLXSW_REG_DEFINE(ricnt, MLXSW_REG_RICNT_ID, MLXSW_REG_RICNT_LEN);
4538
4539 /* reg_ricnt_counter_index
4540  * Counter index
4541  * Access: RW
4542  */
4543 MLXSW_ITEM32(reg, ricnt, counter_index, 0x04, 0, 24);
4544
4545 enum mlxsw_reg_ricnt_counter_set_type {
4546         /* No Count. */
4547         MLXSW_REG_RICNT_COUNTER_SET_TYPE_NO_COUNT = 0x00,
4548         /* Basic. Used for router interfaces, counting the following:
4549          *      - Error and Discard counters.
4550          *      - Unicast, Multicast and Broadcast counters. Sharing the
4551          *        same set of counters for the different type of traffic
4552          *        (IPv4, IPv6 and mpls).
4553          */
4554         MLXSW_REG_RICNT_COUNTER_SET_TYPE_BASIC = 0x09,
4555 };
4556
4557 /* reg_ricnt_counter_set_type
4558  * Counter Set Type for router interface counter
4559  * Access: RW
4560  */
4561 MLXSW_ITEM32(reg, ricnt, counter_set_type, 0x04, 24, 8);
4562
4563 enum mlxsw_reg_ricnt_opcode {
4564         /* Nop. Supported only for read access*/
4565         MLXSW_REG_RICNT_OPCODE_NOP = 0x00,
4566         /* Clear. Setting the clr bit will reset the counter value for
4567          * all counters of the specified Router Interface.
4568          */
4569         MLXSW_REG_RICNT_OPCODE_CLEAR = 0x08,
4570 };
4571
4572 /* reg_ricnt_opcode
4573  * Opcode
4574  * Access: RW
4575  */
4576 MLXSW_ITEM32(reg, ricnt, op, 0x00, 28, 4);
4577
4578 /* reg_ricnt_good_unicast_packets
4579  * good unicast packets.
4580  * Access: RW
4581  */
4582 MLXSW_ITEM64(reg, ricnt, good_unicast_packets, 0x08, 0, 64);
4583
4584 /* reg_ricnt_good_multicast_packets
4585  * good multicast packets.
4586  * Access: RW
4587  */
4588 MLXSW_ITEM64(reg, ricnt, good_multicast_packets, 0x10, 0, 64);
4589
4590 /* reg_ricnt_good_broadcast_packets
4591  * good broadcast packets
4592  * Access: RW
4593  */
4594 MLXSW_ITEM64(reg, ricnt, good_broadcast_packets, 0x18, 0, 64);
4595
4596 /* reg_ricnt_good_unicast_bytes
4597  * A count of L3 data and padding octets not including L2 headers
4598  * for good unicast frames.
4599  * Access: RW
4600  */
4601 MLXSW_ITEM64(reg, ricnt, good_unicast_bytes, 0x20, 0, 64);
4602
4603 /* reg_ricnt_good_multicast_bytes
4604  * A count of L3 data and padding octets not including L2 headers
4605  * for good multicast frames.
4606  * Access: RW
4607  */
4608 MLXSW_ITEM64(reg, ricnt, good_multicast_bytes, 0x28, 0, 64);
4609
4610 /* reg_ritr_good_broadcast_bytes
4611  * A count of L3 data and padding octets not including L2 headers
4612  * for good broadcast frames.
4613  * Access: RW
4614  */
4615 MLXSW_ITEM64(reg, ricnt, good_broadcast_bytes, 0x30, 0, 64);
4616
4617 /* reg_ricnt_error_packets
4618  * A count of errored frames that do not pass the router checks.
4619  * Access: RW
4620  */
4621 MLXSW_ITEM64(reg, ricnt, error_packets, 0x38, 0, 64);
4622
4623 /* reg_ricnt_discrad_packets
4624  * A count of non-errored frames that do not pass the router checks.
4625  * Access: RW
4626  */
4627 MLXSW_ITEM64(reg, ricnt, discard_packets, 0x40, 0, 64);
4628
4629 /* reg_ricnt_error_bytes
4630  * A count of L3 data and padding octets not including L2 headers
4631  * for errored frames.
4632  * Access: RW
4633  */
4634 MLXSW_ITEM64(reg, ricnt, error_bytes, 0x48, 0, 64);
4635
4636 /* reg_ricnt_discard_bytes
4637  * A count of L3 data and padding octets not including L2 headers
4638  * for non-errored frames that do not pass the router checks.
4639  * Access: RW
4640  */
4641 MLXSW_ITEM64(reg, ricnt, discard_bytes, 0x50, 0, 64);
4642
4643 static inline void mlxsw_reg_ricnt_pack(char *payload, u32 index,
4644                                         enum mlxsw_reg_ricnt_opcode op)
4645 {
4646         MLXSW_REG_ZERO(ricnt, payload);
4647         mlxsw_reg_ricnt_op_set(payload, op);
4648         mlxsw_reg_ricnt_counter_index_set(payload, index);
4649         mlxsw_reg_ricnt_counter_set_type_set(payload,
4650                                              MLXSW_REG_RICNT_COUNTER_SET_TYPE_BASIC);
4651 }
4652
4653 /* RALTA - Router Algorithmic LPM Tree Allocation Register
4654  * -------------------------------------------------------
4655  * RALTA is used to allocate the LPM trees of the SHSPM method.
4656  */
4657 #define MLXSW_REG_RALTA_ID 0x8010
4658 #define MLXSW_REG_RALTA_LEN 0x04
4659
4660 MLXSW_REG_DEFINE(ralta, MLXSW_REG_RALTA_ID, MLXSW_REG_RALTA_LEN);
4661
4662 /* reg_ralta_op
4663  * opcode (valid for Write, must be 0 on Read)
4664  * 0 - allocate a tree
4665  * 1 - deallocate a tree
4666  * Access: OP
4667  */
4668 MLXSW_ITEM32(reg, ralta, op, 0x00, 28, 2);
4669
4670 enum mlxsw_reg_ralxx_protocol {
4671         MLXSW_REG_RALXX_PROTOCOL_IPV4,
4672         MLXSW_REG_RALXX_PROTOCOL_IPV6,
4673 };
4674
4675 /* reg_ralta_protocol
4676  * Protocol.
4677  * Deallocation opcode: Reserved.
4678  * Access: RW
4679  */
4680 MLXSW_ITEM32(reg, ralta, protocol, 0x00, 24, 4);
4681
4682 /* reg_ralta_tree_id
4683  * An identifier (numbered from 1..cap_shspm_max_trees-1) representing
4684  * the tree identifier (managed by software).
4685  * Note that tree_id 0 is allocated for a default-route tree.
4686  * Access: Index
4687  */
4688 MLXSW_ITEM32(reg, ralta, tree_id, 0x00, 0, 8);
4689
4690 static inline void mlxsw_reg_ralta_pack(char *payload, bool alloc,
4691                                         enum mlxsw_reg_ralxx_protocol protocol,
4692                                         u8 tree_id)
4693 {
4694         MLXSW_REG_ZERO(ralta, payload);
4695         mlxsw_reg_ralta_op_set(payload, !alloc);
4696         mlxsw_reg_ralta_protocol_set(payload, protocol);
4697         mlxsw_reg_ralta_tree_id_set(payload, tree_id);
4698 }
4699
4700 /* RALST - Router Algorithmic LPM Structure Tree Register
4701  * ------------------------------------------------------
4702  * RALST is used to set and query the structure of an LPM tree.
4703  * The structure of the tree must be sorted as a sorted binary tree, while
4704  * each node is a bin that is tagged as the length of the prefixes the lookup
4705  * will refer to. Therefore, bin X refers to a set of entries with prefixes
4706  * of X bits to match with the destination address. The bin 0 indicates
4707  * the default action, when there is no match of any prefix.
4708  */
4709 #define MLXSW_REG_RALST_ID 0x8011
4710 #define MLXSW_REG_RALST_LEN 0x104
4711
4712 MLXSW_REG_DEFINE(ralst, MLXSW_REG_RALST_ID, MLXSW_REG_RALST_LEN);
4713
4714 /* reg_ralst_root_bin
4715  * The bin number of the root bin.
4716  * 0<root_bin=<(length of IP address)
4717  * For a default-route tree configure 0xff
4718  * Access: RW
4719  */
4720 MLXSW_ITEM32(reg, ralst, root_bin, 0x00, 16, 8);
4721
4722 /* reg_ralst_tree_id
4723  * Tree identifier numbered from 1..(cap_shspm_max_trees-1).
4724  * Access: Index
4725  */
4726 MLXSW_ITEM32(reg, ralst, tree_id, 0x00, 0, 8);
4727
4728 #define MLXSW_REG_RALST_BIN_NO_CHILD 0xff
4729 #define MLXSW_REG_RALST_BIN_OFFSET 0x04
4730 #define MLXSW_REG_RALST_BIN_COUNT 128
4731
4732 /* reg_ralst_left_child_bin
4733  * Holding the children of the bin according to the stored tree's structure.
4734  * For trees composed of less than 4 blocks, the bins in excess are reserved.
4735  * Note that tree_id 0 is allocated for a default-route tree, bins are 0xff
4736  * Access: RW
4737  */
4738 MLXSW_ITEM16_INDEXED(reg, ralst, left_child_bin, 0x04, 8, 8, 0x02, 0x00, false);
4739
4740 /* reg_ralst_right_child_bin
4741  * Holding the children of the bin according to the stored tree's structure.
4742  * For trees composed of less than 4 blocks, the bins in excess are reserved.
4743  * Note that tree_id 0 is allocated for a default-route tree, bins are 0xff
4744  * Access: RW
4745  */
4746 MLXSW_ITEM16_INDEXED(reg, ralst, right_child_bin, 0x04, 0, 8, 0x02, 0x00,
4747                      false);
4748
4749 static inline void mlxsw_reg_ralst_pack(char *payload, u8 root_bin, u8 tree_id)
4750 {
4751         MLXSW_REG_ZERO(ralst, payload);
4752
4753         /* Initialize all bins to have no left or right child */
4754         memset(payload + MLXSW_REG_RALST_BIN_OFFSET,
4755                MLXSW_REG_RALST_BIN_NO_CHILD, MLXSW_REG_RALST_BIN_COUNT * 2);
4756
4757         mlxsw_reg_ralst_root_bin_set(payload, root_bin);
4758         mlxsw_reg_ralst_tree_id_set(payload, tree_id);
4759 }
4760
4761 static inline void mlxsw_reg_ralst_bin_pack(char *payload, u8 bin_number,
4762                                             u8 left_child_bin,
4763                                             u8 right_child_bin)
4764 {
4765         int bin_index = bin_number - 1;
4766
4767         mlxsw_reg_ralst_left_child_bin_set(payload, bin_index, left_child_bin);
4768         mlxsw_reg_ralst_right_child_bin_set(payload, bin_index,
4769                                             right_child_bin);
4770 }
4771
4772 /* RALTB - Router Algorithmic LPM Tree Binding Register
4773  * ----------------------------------------------------
4774  * RALTB is used to bind virtual router and protocol to an allocated LPM tree.
4775  */
4776 #define MLXSW_REG_RALTB_ID 0x8012
4777 #define MLXSW_REG_RALTB_LEN 0x04
4778
4779 MLXSW_REG_DEFINE(raltb, MLXSW_REG_RALTB_ID, MLXSW_REG_RALTB_LEN);
4780
4781 /* reg_raltb_virtual_router
4782  * Virtual Router ID
4783  * Range is 0..cap_max_virtual_routers-1
4784  * Access: Index
4785  */
4786 MLXSW_ITEM32(reg, raltb, virtual_router, 0x00, 16, 16);
4787
4788 /* reg_raltb_protocol
4789  * Protocol.
4790  * Access: Index
4791  */
4792 MLXSW_ITEM32(reg, raltb, protocol, 0x00, 12, 4);
4793
4794 /* reg_raltb_tree_id
4795  * Tree to be used for the {virtual_router, protocol}
4796  * Tree identifier numbered from 1..(cap_shspm_max_trees-1).
4797  * By default, all Unicast IPv4 and IPv6 are bound to tree_id 0.
4798  * Access: RW
4799  */
4800 MLXSW_ITEM32(reg, raltb, tree_id, 0x00, 0, 8);
4801
4802 static inline void mlxsw_reg_raltb_pack(char *payload, u16 virtual_router,
4803                                         enum mlxsw_reg_ralxx_protocol protocol,
4804                                         u8 tree_id)
4805 {
4806         MLXSW_REG_ZERO(raltb, payload);
4807         mlxsw_reg_raltb_virtual_router_set(payload, virtual_router);
4808         mlxsw_reg_raltb_protocol_set(payload, protocol);
4809         mlxsw_reg_raltb_tree_id_set(payload, tree_id);
4810 }
4811
4812 /* RALUE - Router Algorithmic LPM Unicast Entry Register
4813  * -----------------------------------------------------
4814  * RALUE is used to configure and query LPM entries that serve
4815  * the Unicast protocols.
4816  */
4817 #define MLXSW_REG_RALUE_ID 0x8013
4818 #define MLXSW_REG_RALUE_LEN 0x38
4819
4820 MLXSW_REG_DEFINE(ralue, MLXSW_REG_RALUE_ID, MLXSW_REG_RALUE_LEN);
4821
4822 /* reg_ralue_protocol
4823  * Protocol.
4824  * Access: Index
4825  */
4826 MLXSW_ITEM32(reg, ralue, protocol, 0x00, 24, 4);
4827
4828 enum mlxsw_reg_ralue_op {
4829         /* Read operation. If entry doesn't exist, the operation fails. */
4830         MLXSW_REG_RALUE_OP_QUERY_READ = 0,
4831         /* Clear on read operation. Used to read entry and
4832          * clear Activity bit.
4833          */
4834         MLXSW_REG_RALUE_OP_QUERY_CLEAR = 1,
4835         /* Write operation. Used to write a new entry to the table. All RW
4836          * fields are written for new entry. Activity bit is set
4837          * for new entries.
4838          */
4839         MLXSW_REG_RALUE_OP_WRITE_WRITE = 0,
4840         /* Update operation. Used to update an existing route entry and
4841          * only update the RW fields that are detailed in the field
4842          * op_u_mask. If entry doesn't exist, the operation fails.
4843          */
4844         MLXSW_REG_RALUE_OP_WRITE_UPDATE = 1,
4845         /* Clear activity. The Activity bit (the field a) is cleared
4846          * for the entry.
4847          */
4848         MLXSW_REG_RALUE_OP_WRITE_CLEAR = 2,
4849         /* Delete operation. Used to delete an existing entry. If entry
4850          * doesn't exist, the operation fails.
4851          */
4852         MLXSW_REG_RALUE_OP_WRITE_DELETE = 3,
4853 };
4854
4855 /* reg_ralue_op
4856  * Operation.
4857  * Access: OP
4858  */
4859 MLXSW_ITEM32(reg, ralue, op, 0x00, 20, 3);
4860
4861 /* reg_ralue_a
4862  * Activity. Set for new entries. Set if a packet lookup has hit on the
4863  * specific entry, only if the entry is a route. To clear the a bit, use
4864  * "clear activity" op.
4865  * Enabled by activity_dis in RGCR
4866  * Access: RO
4867  */
4868 MLXSW_ITEM32(reg, ralue, a, 0x00, 16, 1);
4869
4870 /* reg_ralue_virtual_router
4871  * Virtual Router ID
4872  * Range is 0..cap_max_virtual_routers-1
4873  * Access: Index
4874  */
4875 MLXSW_ITEM32(reg, ralue, virtual_router, 0x04, 16, 16);
4876
4877 #define MLXSW_REG_RALUE_OP_U_MASK_ENTRY_TYPE    BIT(0)
4878 #define MLXSW_REG_RALUE_OP_U_MASK_BMP_LEN       BIT(1)
4879 #define MLXSW_REG_RALUE_OP_U_MASK_ACTION        BIT(2)
4880
4881 /* reg_ralue_op_u_mask
4882  * opcode update mask.
4883  * On read operation, this field is reserved.
4884  * This field is valid for update opcode, otherwise - reserved.
4885  * This field is a bitmask of the fields that should be updated.
4886  * Access: WO
4887  */
4888 MLXSW_ITEM32(reg, ralue, op_u_mask, 0x04, 8, 3);
4889
4890 /* reg_ralue_prefix_len
4891  * Number of bits in the prefix of the LPM route.
4892  * Note that for IPv6 prefixes, if prefix_len>64 the entry consumes
4893  * two entries in the physical HW table.
4894  * Access: Index
4895  */
4896 MLXSW_ITEM32(reg, ralue, prefix_len, 0x08, 0, 8);
4897
4898 /* reg_ralue_dip*
4899  * The prefix of the route or of the marker that the object of the LPM
4900  * is compared with. The most significant bits of the dip are the prefix.
4901  * The least significant bits must be '0' if the prefix_len is smaller
4902  * than 128 for IPv6 or smaller than 32 for IPv4.
4903  * IPv4 address uses bits dip[31:0] and bits dip[127:32] are reserved.
4904  * Access: Index
4905  */
4906 MLXSW_ITEM32(reg, ralue, dip4, 0x18, 0, 32);
4907 MLXSW_ITEM_BUF(reg, ralue, dip6, 0x0C, 16);
4908
4909 enum mlxsw_reg_ralue_entry_type {
4910         MLXSW_REG_RALUE_ENTRY_TYPE_MARKER_ENTRY = 1,
4911         MLXSW_REG_RALUE_ENTRY_TYPE_ROUTE_ENTRY = 2,
4912         MLXSW_REG_RALUE_ENTRY_TYPE_MARKER_AND_ROUTE_ENTRY = 3,
4913 };
4914
4915 /* reg_ralue_entry_type
4916  * Entry type.
4917  * Note - for Marker entries, the action_type and action fields are reserved.
4918  * Access: RW
4919  */
4920 MLXSW_ITEM32(reg, ralue, entry_type, 0x1C, 30, 2);
4921
4922 /* reg_ralue_bmp_len
4923  * The best match prefix length in the case that there is no match for
4924  * longer prefixes.
4925  * If (entry_type != MARKER_ENTRY), bmp_len must be equal to prefix_len
4926  * Note for any update operation with entry_type modification this
4927  * field must be set.
4928  * Access: RW
4929  */
4930 MLXSW_ITEM32(reg, ralue, bmp_len, 0x1C, 16, 8);
4931
4932 enum mlxsw_reg_ralue_action_type {
4933         MLXSW_REG_RALUE_ACTION_TYPE_REMOTE,
4934         MLXSW_REG_RALUE_ACTION_TYPE_LOCAL,
4935         MLXSW_REG_RALUE_ACTION_TYPE_IP2ME,
4936 };
4937
4938 /* reg_ralue_action_type
4939  * Action Type
4940  * Indicates how the IP address is connected.
4941  * It can be connected to a local subnet through local_erif or can be
4942  * on a remote subnet connected through a next-hop router,
4943  * or transmitted to the CPU.
4944  * Reserved when entry_type = MARKER_ENTRY
4945  * Access: RW
4946  */
4947 MLXSW_ITEM32(reg, ralue, action_type, 0x1C, 0, 2);
4948
4949 enum mlxsw_reg_ralue_trap_action {
4950         MLXSW_REG_RALUE_TRAP_ACTION_NOP,
4951         MLXSW_REG_RALUE_TRAP_ACTION_TRAP,
4952         MLXSW_REG_RALUE_TRAP_ACTION_MIRROR_TO_CPU,
4953         MLXSW_REG_RALUE_TRAP_ACTION_MIRROR,
4954         MLXSW_REG_RALUE_TRAP_ACTION_DISCARD_ERROR,
4955 };
4956
4957 /* reg_ralue_trap_action
4958  * Trap action.
4959  * For IP2ME action, only NOP and MIRROR are possible.
4960  * Access: RW
4961  */
4962 MLXSW_ITEM32(reg, ralue, trap_action, 0x20, 28, 4);
4963
4964 /* reg_ralue_trap_id
4965  * Trap ID to be reported to CPU.
4966  * Trap ID is RTR_INGRESS0 or RTR_INGRESS1.
4967  * For trap_action of NOP, MIRROR and DISCARD_ERROR, trap_id is reserved.
4968  * Access: RW
4969  */
4970 MLXSW_ITEM32(reg, ralue, trap_id, 0x20, 0, 9);
4971
4972 /* reg_ralue_adjacency_index
4973  * Points to the first entry of the group-based ECMP.
4974  * Only relevant in case of REMOTE action.
4975  * Access: RW
4976  */
4977 MLXSW_ITEM32(reg, ralue, adjacency_index, 0x24, 0, 24);
4978
4979 /* reg_ralue_ecmp_size
4980  * Amount of sequential entries starting
4981  * from the adjacency_index (the number of ECMPs).
4982  * The valid range is 1-64, 512, 1024, 2048 and 4096.
4983  * Reserved when trap_action is TRAP or DISCARD_ERROR.
4984  * Only relevant in case of REMOTE action.
4985  * Access: RW
4986  */
4987 MLXSW_ITEM32(reg, ralue, ecmp_size, 0x28, 0, 13);
4988
4989 /* reg_ralue_local_erif
4990  * Egress Router Interface.
4991  * Only relevant in case of LOCAL action.
4992  * Access: RW
4993  */
4994 MLXSW_ITEM32(reg, ralue, local_erif, 0x24, 0, 16);
4995
4996 /* reg_ralue_ip2me_v
4997  * Valid bit for the tunnel_ptr field.
4998  * If valid = 0 then trap to CPU as IP2ME trap ID.
4999  * If valid = 1 and the packet format allows NVE or IPinIP tunnel
5000  * decapsulation then tunnel decapsulation is done.
5001  * If valid = 1 and packet format does not allow NVE or IPinIP tunnel
5002  * decapsulation then trap as IP2ME trap ID.
5003  * Only relevant in case of IP2ME action.
5004  * Access: RW
5005  */
5006 MLXSW_ITEM32(reg, ralue, ip2me_v, 0x24, 31, 1);
5007
5008 /* reg_ralue_ip2me_tunnel_ptr
5009  * Tunnel Pointer for NVE or IPinIP tunnel decapsulation.
5010  * For Spectrum, pointer to KVD Linear.
5011  * Only relevant in case of IP2ME action.
5012  * Access: RW
5013  */
5014 MLXSW_ITEM32(reg, ralue, ip2me_tunnel_ptr, 0x24, 0, 24);
5015
5016 static inline void mlxsw_reg_ralue_pack(char *payload,
5017                                         enum mlxsw_reg_ralxx_protocol protocol,
5018                                         enum mlxsw_reg_ralue_op op,
5019                                         u16 virtual_router, u8 prefix_len)
5020 {
5021         MLXSW_REG_ZERO(ralue, payload);
5022         mlxsw_reg_ralue_protocol_set(payload, protocol);
5023         mlxsw_reg_ralue_op_set(payload, op);
5024         mlxsw_reg_ralue_virtual_router_set(payload, virtual_router);
5025         mlxsw_reg_ralue_prefix_len_set(payload, prefix_len);
5026         mlxsw_reg_ralue_entry_type_set(payload,
5027                                        MLXSW_REG_RALUE_ENTRY_TYPE_ROUTE_ENTRY);
5028         mlxsw_reg_ralue_bmp_len_set(payload, prefix_len);
5029 }
5030
5031 static inline void mlxsw_reg_ralue_pack4(char *payload,
5032                                          enum mlxsw_reg_ralxx_protocol protocol,
5033                                          enum mlxsw_reg_ralue_op op,
5034                                          u16 virtual_router, u8 prefix_len,
5035                                          u32 dip)
5036 {
5037         mlxsw_reg_ralue_pack(payload, protocol, op, virtual_router, prefix_len);
5038         mlxsw_reg_ralue_dip4_set(payload, dip);
5039 }
5040
5041 static inline void mlxsw_reg_ralue_pack6(char *payload,
5042                                          enum mlxsw_reg_ralxx_protocol protocol,
5043                                          enum mlxsw_reg_ralue_op op,
5044                                          u16 virtual_router, u8 prefix_len,
5045                                          const void *dip)
5046 {
5047         mlxsw_reg_ralue_pack(payload, protocol, op, virtual_router, prefix_len);
5048         mlxsw_reg_ralue_dip6_memcpy_to(payload, dip);
5049 }
5050
5051 static inline void
5052 mlxsw_reg_ralue_act_remote_pack(char *payload,
5053                                 enum mlxsw_reg_ralue_trap_action trap_action,
5054                                 u16 trap_id, u32 adjacency_index, u16 ecmp_size)
5055 {
5056         mlxsw_reg_ralue_action_type_set(payload,
5057                                         MLXSW_REG_RALUE_ACTION_TYPE_REMOTE);
5058         mlxsw_reg_ralue_trap_action_set(payload, trap_action);
5059         mlxsw_reg_ralue_trap_id_set(payload, trap_id);
5060         mlxsw_reg_ralue_adjacency_index_set(payload, adjacency_index);
5061         mlxsw_reg_ralue_ecmp_size_set(payload, ecmp_size);
5062 }
5063
5064 static inline void
5065 mlxsw_reg_ralue_act_local_pack(char *payload,
5066                                enum mlxsw_reg_ralue_trap_action trap_action,
5067                                u16 trap_id, u16 local_erif)
5068 {
5069         mlxsw_reg_ralue_action_type_set(payload,
5070                                         MLXSW_REG_RALUE_ACTION_TYPE_LOCAL);
5071         mlxsw_reg_ralue_trap_action_set(payload, trap_action);
5072         mlxsw_reg_ralue_trap_id_set(payload, trap_id);
5073         mlxsw_reg_ralue_local_erif_set(payload, local_erif);
5074 }
5075
5076 static inline void
5077 mlxsw_reg_ralue_act_ip2me_pack(char *payload)
5078 {
5079         mlxsw_reg_ralue_action_type_set(payload,
5080                                         MLXSW_REG_RALUE_ACTION_TYPE_IP2ME);
5081 }
5082
5083 static inline void
5084 mlxsw_reg_ralue_act_ip2me_tun_pack(char *payload, u32 tunnel_ptr)
5085 {
5086         mlxsw_reg_ralue_action_type_set(payload,
5087                                         MLXSW_REG_RALUE_ACTION_TYPE_IP2ME);
5088         mlxsw_reg_ralue_ip2me_v_set(payload, 1);
5089         mlxsw_reg_ralue_ip2me_tunnel_ptr_set(payload, tunnel_ptr);
5090 }
5091
5092 /* RAUHT - Router Algorithmic LPM Unicast Host Table Register
5093  * ----------------------------------------------------------
5094  * The RAUHT register is used to configure and query the Unicast Host table in
5095  * devices that implement the Algorithmic LPM.
5096  */
5097 #define MLXSW_REG_RAUHT_ID 0x8014
5098 #define MLXSW_REG_RAUHT_LEN 0x74
5099
5100 MLXSW_REG_DEFINE(rauht, MLXSW_REG_RAUHT_ID, MLXSW_REG_RAUHT_LEN);
5101
5102 enum mlxsw_reg_rauht_type {
5103         MLXSW_REG_RAUHT_TYPE_IPV4,
5104         MLXSW_REG_RAUHT_TYPE_IPV6,
5105 };
5106
5107 /* reg_rauht_type
5108  * Access: Index
5109  */
5110 MLXSW_ITEM32(reg, rauht, type, 0x00, 24, 2);
5111
5112 enum mlxsw_reg_rauht_op {
5113         MLXSW_REG_RAUHT_OP_QUERY_READ = 0,
5114         /* Read operation */
5115         MLXSW_REG_RAUHT_OP_QUERY_CLEAR_ON_READ = 1,
5116         /* Clear on read operation. Used to read entry and clear
5117          * activity bit.
5118          */
5119         MLXSW_REG_RAUHT_OP_WRITE_ADD = 0,
5120         /* Add. Used to write a new entry to the table. All R/W fields are
5121          * relevant for new entry. Activity bit is set for new entries.
5122          */
5123         MLXSW_REG_RAUHT_OP_WRITE_UPDATE = 1,
5124         /* Update action. Used to update an existing route entry and
5125          * only update the following fields:
5126          * trap_action, trap_id, mac, counter_set_type, counter_index
5127          */
5128         MLXSW_REG_RAUHT_OP_WRITE_CLEAR_ACTIVITY = 2,
5129         /* Clear activity. A bit is cleared for the entry. */
5130         MLXSW_REG_RAUHT_OP_WRITE_DELETE = 3,
5131         /* Delete entry */
5132         MLXSW_REG_RAUHT_OP_WRITE_DELETE_ALL = 4,
5133         /* Delete all host entries on a RIF. In this command, dip
5134          * field is reserved.
5135          */
5136 };
5137
5138 /* reg_rauht_op
5139  * Access: OP
5140  */
5141 MLXSW_ITEM32(reg, rauht, op, 0x00, 20, 3);
5142
5143 /* reg_rauht_a
5144  * Activity. Set for new entries. Set if a packet lookup has hit on
5145  * the specific entry.
5146  * To clear the a bit, use "clear activity" op.
5147  * Enabled by activity_dis in RGCR
5148  * Access: RO
5149  */
5150 MLXSW_ITEM32(reg, rauht, a, 0x00, 16, 1);
5151
5152 /* reg_rauht_rif
5153  * Router Interface
5154  * Access: Index
5155  */
5156 MLXSW_ITEM32(reg, rauht, rif, 0x00, 0, 16);
5157
5158 /* reg_rauht_dip*
5159  * Destination address.
5160  * Access: Index
5161  */
5162 MLXSW_ITEM32(reg, rauht, dip4, 0x1C, 0x0, 32);
5163 MLXSW_ITEM_BUF(reg, rauht, dip6, 0x10, 16);
5164
5165 enum mlxsw_reg_rauht_trap_action {
5166         MLXSW_REG_RAUHT_TRAP_ACTION_NOP,
5167         MLXSW_REG_RAUHT_TRAP_ACTION_TRAP,
5168         MLXSW_REG_RAUHT_TRAP_ACTION_MIRROR_TO_CPU,
5169         MLXSW_REG_RAUHT_TRAP_ACTION_MIRROR,
5170         MLXSW_REG_RAUHT_TRAP_ACTION_DISCARD_ERRORS,
5171 };
5172
5173 /* reg_rauht_trap_action
5174  * Access: RW
5175  */
5176 MLXSW_ITEM32(reg, rauht, trap_action, 0x60, 28, 4);
5177
5178 enum mlxsw_reg_rauht_trap_id {
5179         MLXSW_REG_RAUHT_TRAP_ID_RTR_EGRESS0,
5180         MLXSW_REG_RAUHT_TRAP_ID_RTR_EGRESS1,
5181 };
5182
5183 /* reg_rauht_trap_id
5184  * Trap ID to be reported to CPU.
5185  * Trap-ID is RTR_EGRESS0 or RTR_EGRESS1.
5186  * For trap_action of NOP, MIRROR and DISCARD_ERROR,
5187  * trap_id is reserved.
5188  * Access: RW
5189  */
5190 MLXSW_ITEM32(reg, rauht, trap_id, 0x60, 0, 9);
5191
5192 enum mlxsw_reg_flow_counter_set_type {
5193         /* No count */
5194         MLXSW_REG_FLOW_COUNTER_SET_TYPE_NO_COUNT = 0x00,
5195         /* Count packets and bytes */
5196         MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES = 0x03,
5197         /* Count only packets */
5198         MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS = 0x05,
5199 };
5200
5201 /* reg_rauht_counter_set_type
5202  * Counter set type for flow counters
5203  * Access: RW
5204  */
5205 MLXSW_ITEM32(reg, rauht, counter_set_type, 0x68, 24, 8);
5206
5207 /* reg_rauht_counter_index
5208  * Counter index for flow counters
5209  * Access: RW
5210  */
5211 MLXSW_ITEM32(reg, rauht, counter_index, 0x68, 0, 24);
5212
5213 /* reg_rauht_mac
5214  * MAC address.
5215  * Access: RW
5216  */
5217 MLXSW_ITEM_BUF(reg, rauht, mac, 0x6E, 6);
5218
5219 static inline void mlxsw_reg_rauht_pack(char *payload,
5220                                         enum mlxsw_reg_rauht_op op, u16 rif,
5221                                         const char *mac)
5222 {
5223         MLXSW_REG_ZERO(rauht, payload);
5224         mlxsw_reg_rauht_op_set(payload, op);
5225         mlxsw_reg_rauht_rif_set(payload, rif);
5226         mlxsw_reg_rauht_mac_memcpy_to(payload, mac);
5227 }
5228
5229 static inline void mlxsw_reg_rauht_pack4(char *payload,
5230                                          enum mlxsw_reg_rauht_op op, u16 rif,
5231                                          const char *mac, u32 dip)
5232 {
5233         mlxsw_reg_rauht_pack(payload, op, rif, mac);
5234         mlxsw_reg_rauht_dip4_set(payload, dip);
5235 }
5236
5237 static inline void mlxsw_reg_rauht_pack6(char *payload,
5238                                          enum mlxsw_reg_rauht_op op, u16 rif,
5239                                          const char *mac, const char *dip)
5240 {
5241         mlxsw_reg_rauht_pack(payload, op, rif, mac);
5242         mlxsw_reg_rauht_type_set(payload, MLXSW_REG_RAUHT_TYPE_IPV6);
5243         mlxsw_reg_rauht_dip6_memcpy_to(payload, dip);
5244 }
5245
5246 static inline void mlxsw_reg_rauht_pack_counter(char *payload,
5247                                                 u64 counter_index)
5248 {
5249         mlxsw_reg_rauht_counter_index_set(payload, counter_index);
5250         mlxsw_reg_rauht_counter_set_type_set(payload,
5251                                              MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES);
5252 }
5253
5254 /* RALEU - Router Algorithmic LPM ECMP Update Register
5255  * ---------------------------------------------------
5256  * The register enables updating the ECMP section in the action for multiple
5257  * LPM Unicast entries in a single operation. The update is executed to
5258  * all entries of a {virtual router, protocol} tuple using the same ECMP group.
5259  */
5260 #define MLXSW_REG_RALEU_ID 0x8015
5261 #define MLXSW_REG_RALEU_LEN 0x28
5262
5263 MLXSW_REG_DEFINE(raleu, MLXSW_REG_RALEU_ID, MLXSW_REG_RALEU_LEN);
5264
5265 /* reg_raleu_protocol
5266  * Protocol.
5267  * Access: Index
5268  */
5269 MLXSW_ITEM32(reg, raleu, protocol, 0x00, 24, 4);
5270
5271 /* reg_raleu_virtual_router
5272  * Virtual Router ID
5273  * Range is 0..cap_max_virtual_routers-1
5274  * Access: Index
5275  */
5276 MLXSW_ITEM32(reg, raleu, virtual_router, 0x00, 0, 16);
5277
5278 /* reg_raleu_adjacency_index
5279  * Adjacency Index used for matching on the existing entries.
5280  * Access: Index
5281  */
5282 MLXSW_ITEM32(reg, raleu, adjacency_index, 0x10, 0, 24);
5283
5284 /* reg_raleu_ecmp_size
5285  * ECMP Size used for matching on the existing entries.
5286  * Access: Index
5287  */
5288 MLXSW_ITEM32(reg, raleu, ecmp_size, 0x14, 0, 13);
5289
5290 /* reg_raleu_new_adjacency_index
5291  * New Adjacency Index.
5292  * Access: WO
5293  */
5294 MLXSW_ITEM32(reg, raleu, new_adjacency_index, 0x20, 0, 24);
5295
5296 /* reg_raleu_new_ecmp_size
5297  * New ECMP Size.
5298  * Access: WO
5299  */
5300 MLXSW_ITEM32(reg, raleu, new_ecmp_size, 0x24, 0, 13);
5301
5302 static inline void mlxsw_reg_raleu_pack(char *payload,
5303                                         enum mlxsw_reg_ralxx_protocol protocol,
5304                                         u16 virtual_router,
5305                                         u32 adjacency_index, u16 ecmp_size,
5306                                         u32 new_adjacency_index,
5307                                         u16 new_ecmp_size)
5308 {
5309         MLXSW_REG_ZERO(raleu, payload);
5310         mlxsw_reg_raleu_protocol_set(payload, protocol);
5311         mlxsw_reg_raleu_virtual_router_set(payload, virtual_router);
5312         mlxsw_reg_raleu_adjacency_index_set(payload, adjacency_index);
5313         mlxsw_reg_raleu_ecmp_size_set(payload, ecmp_size);
5314         mlxsw_reg_raleu_new_adjacency_index_set(payload, new_adjacency_index);
5315         mlxsw_reg_raleu_new_ecmp_size_set(payload, new_ecmp_size);
5316 }
5317
5318 /* RAUHTD - Router Algorithmic LPM Unicast Host Table Dump Register
5319  * ----------------------------------------------------------------
5320  * The RAUHTD register allows dumping entries from the Router Unicast Host
5321  * Table. For a given session an entry is dumped no more than one time. The
5322  * first RAUHTD access after reset is a new session. A session ends when the
5323  * num_rec response is smaller than num_rec request or for IPv4 when the
5324  * num_entries is smaller than 4. The clear activity affect the current session
5325  * or the last session if a new session has not started.
5326  */
5327 #define MLXSW_REG_RAUHTD_ID 0x8018
5328 #define MLXSW_REG_RAUHTD_BASE_LEN 0x20
5329 #define MLXSW_REG_RAUHTD_REC_LEN 0x20
5330 #define MLXSW_REG_RAUHTD_REC_MAX_NUM 32
5331 #define MLXSW_REG_RAUHTD_LEN (MLXSW_REG_RAUHTD_BASE_LEN + \
5332                 MLXSW_REG_RAUHTD_REC_MAX_NUM * MLXSW_REG_RAUHTD_REC_LEN)
5333 #define MLXSW_REG_RAUHTD_IPV4_ENT_PER_REC 4
5334
5335 MLXSW_REG_DEFINE(rauhtd, MLXSW_REG_RAUHTD_ID, MLXSW_REG_RAUHTD_LEN);
5336
5337 #define MLXSW_REG_RAUHTD_FILTER_A BIT(0)
5338 #define MLXSW_REG_RAUHTD_FILTER_RIF BIT(3)
5339
5340 /* reg_rauhtd_filter_fields
5341  * if a bit is '0' then the relevant field is ignored and dump is done
5342  * regardless of the field value
5343  * Bit0 - filter by activity: entry_a
5344  * Bit3 - filter by entry rip: entry_rif
5345  * Access: Index
5346  */
5347 MLXSW_ITEM32(reg, rauhtd, filter_fields, 0x00, 0, 8);
5348
5349 enum mlxsw_reg_rauhtd_op {
5350         MLXSW_REG_RAUHTD_OP_DUMP,
5351         MLXSW_REG_RAUHTD_OP_DUMP_AND_CLEAR,
5352 };
5353
5354 /* reg_rauhtd_op
5355  * Access: OP
5356  */
5357 MLXSW_ITEM32(reg, rauhtd, op, 0x04, 24, 2);
5358
5359 /* reg_rauhtd_num_rec
5360  * At request: number of records requested
5361  * At response: number of records dumped
5362  * For IPv4, each record has 4 entries at request and up to 4 entries
5363  * at response
5364  * Range is 0..MLXSW_REG_RAUHTD_REC_MAX_NUM
5365  * Access: Index
5366  */
5367 MLXSW_ITEM32(reg, rauhtd, num_rec, 0x04, 0, 8);
5368
5369 /* reg_rauhtd_entry_a
5370  * Dump only if activity has value of entry_a
5371  * Reserved if filter_fields bit0 is '0'
5372  * Access: Index
5373  */
5374 MLXSW_ITEM32(reg, rauhtd, entry_a, 0x08, 16, 1);
5375
5376 enum mlxsw_reg_rauhtd_type {
5377         MLXSW_REG_RAUHTD_TYPE_IPV4,
5378         MLXSW_REG_RAUHTD_TYPE_IPV6,
5379 };
5380
5381 /* reg_rauhtd_type
5382  * Dump only if record type is:
5383  * 0 - IPv4
5384  * 1 - IPv6
5385  * Access: Index
5386  */
5387 MLXSW_ITEM32(reg, rauhtd, type, 0x08, 0, 4);
5388
5389 /* reg_rauhtd_entry_rif
5390  * Dump only if RIF has value of entry_rif
5391  * Reserved if filter_fields bit3 is '0'
5392  * Access: Index
5393  */
5394 MLXSW_ITEM32(reg, rauhtd, entry_rif, 0x0C, 0, 16);
5395
5396 static inline void mlxsw_reg_rauhtd_pack(char *payload,
5397                                          enum mlxsw_reg_rauhtd_type type)
5398 {
5399         MLXSW_REG_ZERO(rauhtd, payload);
5400         mlxsw_reg_rauhtd_filter_fields_set(payload, MLXSW_REG_RAUHTD_FILTER_A);
5401         mlxsw_reg_rauhtd_op_set(payload, MLXSW_REG_RAUHTD_OP_DUMP_AND_CLEAR);
5402         mlxsw_reg_rauhtd_num_rec_set(payload, MLXSW_REG_RAUHTD_REC_MAX_NUM);
5403         mlxsw_reg_rauhtd_entry_a_set(payload, 1);
5404         mlxsw_reg_rauhtd_type_set(payload, type);
5405 }
5406
5407 /* reg_rauhtd_ipv4_rec_num_entries
5408  * Number of valid entries in this record:
5409  * 0 - 1 valid entry
5410  * 1 - 2 valid entries
5411  * 2 - 3 valid entries
5412  * 3 - 4 valid entries
5413  * Access: RO
5414  */
5415 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_rec_num_entries,
5416                      MLXSW_REG_RAUHTD_BASE_LEN, 28, 2,
5417                      MLXSW_REG_RAUHTD_REC_LEN, 0x00, false);
5418
5419 /* reg_rauhtd_rec_type
5420  * Record type.
5421  * 0 - IPv4
5422  * 1 - IPv6
5423  * Access: RO
5424  */
5425 MLXSW_ITEM32_INDEXED(reg, rauhtd, rec_type, MLXSW_REG_RAUHTD_BASE_LEN, 24, 2,
5426                      MLXSW_REG_RAUHTD_REC_LEN, 0x00, false);
5427
5428 #define MLXSW_REG_RAUHTD_IPV4_ENT_LEN 0x8
5429
5430 /* reg_rauhtd_ipv4_ent_a
5431  * Activity. Set for new entries. Set if a packet lookup has hit on the
5432  * specific entry.
5433  * Access: RO
5434  */
5435 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_a, MLXSW_REG_RAUHTD_BASE_LEN, 16, 1,
5436                      MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x00, false);
5437
5438 /* reg_rauhtd_ipv4_ent_rif
5439  * Router interface.
5440  * Access: RO
5441  */
5442 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_rif, MLXSW_REG_RAUHTD_BASE_LEN, 0,
5443                      16, MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x00, false);
5444
5445 /* reg_rauhtd_ipv4_ent_dip
5446  * Destination IPv4 address.
5447  * Access: RO
5448  */
5449 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv4_ent_dip, MLXSW_REG_RAUHTD_BASE_LEN, 0,
5450                      32, MLXSW_REG_RAUHTD_IPV4_ENT_LEN, 0x04, false);
5451
5452 #define MLXSW_REG_RAUHTD_IPV6_ENT_LEN 0x20
5453
5454 /* reg_rauhtd_ipv6_ent_a
5455  * Activity. Set for new entries. Set if a packet lookup has hit on the
5456  * specific entry.
5457  * Access: RO
5458  */
5459 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv6_ent_a, MLXSW_REG_RAUHTD_BASE_LEN, 16, 1,
5460                      MLXSW_REG_RAUHTD_IPV6_ENT_LEN, 0x00, false);
5461
5462 /* reg_rauhtd_ipv6_ent_rif
5463  * Router interface.
5464  * Access: RO
5465  */
5466 MLXSW_ITEM32_INDEXED(reg, rauhtd, ipv6_ent_rif, MLXSW_REG_RAUHTD_BASE_LEN, 0,
5467                      16, MLXSW_REG_RAUHTD_IPV6_ENT_LEN, 0x00, false);
5468
5469 /* reg_rauhtd_ipv6_ent_dip
5470  * Destination IPv6 address.
5471  * Access: RO
5472  */
5473 MLXSW_ITEM_BUF_INDEXED(reg, rauhtd, ipv6_ent_dip, MLXSW_REG_RAUHTD_BASE_LEN,
5474                        16, MLXSW_REG_RAUHTD_IPV6_ENT_LEN, 0x10);
5475
5476 static inline void mlxsw_reg_rauhtd_ent_ipv4_unpack(char *payload,
5477                                                     int ent_index, u16 *p_rif,
5478                                                     u32 *p_dip)
5479 {
5480         *p_rif = mlxsw_reg_rauhtd_ipv4_ent_rif_get(payload, ent_index);
5481         *p_dip = mlxsw_reg_rauhtd_ipv4_ent_dip_get(payload, ent_index);
5482 }
5483
5484 static inline void mlxsw_reg_rauhtd_ent_ipv6_unpack(char *payload,
5485                                                     int rec_index, u16 *p_rif,
5486                                                     char *p_dip)
5487 {
5488         *p_rif = mlxsw_reg_rauhtd_ipv6_ent_rif_get(payload, rec_index);
5489         mlxsw_reg_rauhtd_ipv6_ent_dip_memcpy_from(payload, rec_index, p_dip);
5490 }
5491
5492 /* RTDP - Routing Tunnel Decap Properties Register
5493  * -----------------------------------------------
5494  * The RTDP register is used for configuring the tunnel decap properties of NVE
5495  * and IPinIP.
5496  */
5497 #define MLXSW_REG_RTDP_ID 0x8020
5498 #define MLXSW_REG_RTDP_LEN 0x44
5499
5500 MLXSW_REG_DEFINE(rtdp, MLXSW_REG_RTDP_ID, MLXSW_REG_RTDP_LEN);
5501
5502 enum mlxsw_reg_rtdp_type {
5503         MLXSW_REG_RTDP_TYPE_NVE,
5504         MLXSW_REG_RTDP_TYPE_IPIP,
5505 };
5506
5507 /* reg_rtdp_type
5508  * Type of the RTDP entry as per enum mlxsw_reg_rtdp_type.
5509  * Access: RW
5510  */
5511 MLXSW_ITEM32(reg, rtdp, type, 0x00, 28, 4);
5512
5513 /* reg_rtdp_tunnel_index
5514  * Index to the Decap entry.
5515  * For Spectrum, Index to KVD Linear.
5516  * Access: Index
5517  */
5518 MLXSW_ITEM32(reg, rtdp, tunnel_index, 0x00, 0, 24);
5519
5520 /* IPinIP */
5521
5522 /* reg_rtdp_ipip_irif
5523  * Ingress Router Interface for the overlay router
5524  * Access: RW
5525  */
5526 MLXSW_ITEM32(reg, rtdp, ipip_irif, 0x04, 16, 16);
5527
5528 enum mlxsw_reg_rtdp_ipip_sip_check {
5529         /* No sip checks. */
5530         MLXSW_REG_RTDP_IPIP_SIP_CHECK_NO,
5531         /* Filter packet if underlay is not IPv4 or if underlay SIP does not
5532          * equal ipv4_usip.
5533          */
5534         MLXSW_REG_RTDP_IPIP_SIP_CHECK_FILTER_IPV4,
5535         /* Filter packet if underlay is not IPv6 or if underlay SIP does not
5536          * equal ipv6_usip.
5537          */
5538         MLXSW_REG_RTDP_IPIP_SIP_CHECK_FILTER_IPV6 = 3,
5539 };
5540
5541 /* reg_rtdp_ipip_sip_check
5542  * SIP check to perform. If decapsulation failed due to these configurations
5543  * then trap_id is IPIP_DECAP_ERROR.
5544  * Access: RW
5545  */
5546 MLXSW_ITEM32(reg, rtdp, ipip_sip_check, 0x04, 0, 3);
5547
5548 /* If set, allow decapsulation of IPinIP (without GRE). */
5549 #define MLXSW_REG_RTDP_IPIP_TYPE_CHECK_ALLOW_IPIP       BIT(0)
5550 /* If set, allow decapsulation of IPinGREinIP without a key. */
5551 #define MLXSW_REG_RTDP_IPIP_TYPE_CHECK_ALLOW_GRE        BIT(1)
5552 /* If set, allow decapsulation of IPinGREinIP with a key. */
5553 #define MLXSW_REG_RTDP_IPIP_TYPE_CHECK_ALLOW_GRE_KEY    BIT(2)
5554
5555 /* reg_rtdp_ipip_type_check
5556  * Flags as per MLXSW_REG_RTDP_IPIP_TYPE_CHECK_*. If decapsulation failed due to
5557  * these configurations then trap_id is IPIP_DECAP_ERROR.
5558  * Access: RW
5559  */
5560 MLXSW_ITEM32(reg, rtdp, ipip_type_check, 0x08, 24, 3);
5561
5562 /* reg_rtdp_ipip_gre_key_check
5563  * Whether GRE key should be checked. When check is enabled:
5564  * - A packet received as IPinIP (without GRE) will always pass.
5565  * - A packet received as IPinGREinIP without a key will not pass the check.
5566  * - A packet received as IPinGREinIP with a key will pass the check only if the
5567  *   key in the packet is equal to expected_gre_key.
5568  * If decapsulation failed due to GRE key then trap_id is IPIP_DECAP_ERROR.
5569  * Access: RW
5570  */
5571 MLXSW_ITEM32(reg, rtdp, ipip_gre_key_check, 0x08, 23, 1);
5572
5573 /* reg_rtdp_ipip_ipv4_usip
5574  * Underlay IPv4 address for ipv4 source address check.
5575  * Reserved when sip_check is not '1'.
5576  * Access: RW
5577  */
5578 MLXSW_ITEM32(reg, rtdp, ipip_ipv4_usip, 0x0C, 0, 32);
5579
5580 /* reg_rtdp_ipip_ipv6_usip_ptr
5581  * This field is valid when sip_check is "sipv6 check explicitly". This is a
5582  * pointer to the IPv6 DIP which is configured by RIPS. For Spectrum, the index
5583  * is to the KVD linear.
5584  * Reserved when sip_check is not MLXSW_REG_RTDP_IPIP_SIP_CHECK_FILTER_IPV6.
5585  * Access: RW
5586  */
5587 MLXSW_ITEM32(reg, rtdp, ipip_ipv6_usip_ptr, 0x10, 0, 24);
5588
5589 /* reg_rtdp_ipip_expected_gre_key
5590  * GRE key for checking.
5591  * Reserved when gre_key_check is '0'.
5592  * Access: RW
5593  */
5594 MLXSW_ITEM32(reg, rtdp, ipip_expected_gre_key, 0x14, 0, 32);
5595
5596 static inline void mlxsw_reg_rtdp_pack(char *payload,
5597                                        enum mlxsw_reg_rtdp_type type,
5598                                        u32 tunnel_index)
5599 {
5600         MLXSW_REG_ZERO(rtdp, payload);
5601         mlxsw_reg_rtdp_type_set(payload, type);
5602         mlxsw_reg_rtdp_tunnel_index_set(payload, tunnel_index);
5603 }
5604
5605 static inline void
5606 mlxsw_reg_rtdp_ipip4_pack(char *payload, u16 irif,
5607                           enum mlxsw_reg_rtdp_ipip_sip_check sip_check,
5608                           unsigned int type_check, bool gre_key_check,
5609                           u32 ipv4_usip, u32 expected_gre_key)
5610 {
5611         mlxsw_reg_rtdp_ipip_irif_set(payload, irif);
5612         mlxsw_reg_rtdp_ipip_sip_check_set(payload, sip_check);
5613         mlxsw_reg_rtdp_ipip_type_check_set(payload, type_check);
5614         mlxsw_reg_rtdp_ipip_gre_key_check_set(payload, gre_key_check);
5615         mlxsw_reg_rtdp_ipip_ipv4_usip_set(payload, ipv4_usip);
5616         mlxsw_reg_rtdp_ipip_expected_gre_key_set(payload, expected_gre_key);
5617 }
5618
5619 /* MFCR - Management Fan Control Register
5620  * --------------------------------------
5621  * This register controls the settings of the Fan Speed PWM mechanism.
5622  */
5623 #define MLXSW_REG_MFCR_ID 0x9001
5624 #define MLXSW_REG_MFCR_LEN 0x08
5625
5626 MLXSW_REG_DEFINE(mfcr, MLXSW_REG_MFCR_ID, MLXSW_REG_MFCR_LEN);
5627
5628 enum mlxsw_reg_mfcr_pwm_frequency {
5629         MLXSW_REG_MFCR_PWM_FEQ_11HZ = 0x00,
5630         MLXSW_REG_MFCR_PWM_FEQ_14_7HZ = 0x01,
5631         MLXSW_REG_MFCR_PWM_FEQ_22_1HZ = 0x02,
5632         MLXSW_REG_MFCR_PWM_FEQ_1_4KHZ = 0x40,
5633         MLXSW_REG_MFCR_PWM_FEQ_5KHZ = 0x41,
5634         MLXSW_REG_MFCR_PWM_FEQ_20KHZ = 0x42,
5635         MLXSW_REG_MFCR_PWM_FEQ_22_5KHZ = 0x43,
5636         MLXSW_REG_MFCR_PWM_FEQ_25KHZ = 0x44,
5637 };
5638
5639 /* reg_mfcr_pwm_frequency
5640  * Controls the frequency of the PWM signal.
5641  * Access: RW
5642  */
5643 MLXSW_ITEM32(reg, mfcr, pwm_frequency, 0x00, 0, 7);
5644
5645 #define MLXSW_MFCR_TACHOS_MAX 10
5646
5647 /* reg_mfcr_tacho_active
5648  * Indicates which of the tachometer is active (bit per tachometer).
5649  * Access: RO
5650  */
5651 MLXSW_ITEM32(reg, mfcr, tacho_active, 0x04, 16, MLXSW_MFCR_TACHOS_MAX);
5652
5653 #define MLXSW_MFCR_PWMS_MAX 5
5654
5655 /* reg_mfcr_pwm_active
5656  * Indicates which of the PWM control is active (bit per PWM).
5657  * Access: RO
5658  */
5659 MLXSW_ITEM32(reg, mfcr, pwm_active, 0x04, 0, MLXSW_MFCR_PWMS_MAX);
5660
5661 static inline void
5662 mlxsw_reg_mfcr_pack(char *payload,
5663                     enum mlxsw_reg_mfcr_pwm_frequency pwm_frequency)
5664 {
5665         MLXSW_REG_ZERO(mfcr, payload);
5666         mlxsw_reg_mfcr_pwm_frequency_set(payload, pwm_frequency);
5667 }
5668
5669 static inline void
5670 mlxsw_reg_mfcr_unpack(char *payload,
5671                       enum mlxsw_reg_mfcr_pwm_frequency *p_pwm_frequency,
5672                       u16 *p_tacho_active, u8 *p_pwm_active)
5673 {
5674         *p_pwm_frequency = mlxsw_reg_mfcr_pwm_frequency_get(payload);
5675         *p_tacho_active = mlxsw_reg_mfcr_tacho_active_get(payload);
5676         *p_pwm_active = mlxsw_reg_mfcr_pwm_active_get(payload);
5677 }
5678
5679 /* MFSC - Management Fan Speed Control Register
5680  * --------------------------------------------
5681  * This register controls the settings of the Fan Speed PWM mechanism.
5682  */
5683 #define MLXSW_REG_MFSC_ID 0x9002
5684 #define MLXSW_REG_MFSC_LEN 0x08
5685
5686 MLXSW_REG_DEFINE(mfsc, MLXSW_REG_MFSC_ID, MLXSW_REG_MFSC_LEN);
5687
5688 /* reg_mfsc_pwm
5689  * Fan pwm to control / monitor.
5690  * Access: Index
5691  */
5692 MLXSW_ITEM32(reg, mfsc, pwm, 0x00, 24, 3);
5693
5694 /* reg_mfsc_pwm_duty_cycle
5695  * Controls the duty cycle of the PWM. Value range from 0..255 to
5696  * represent duty cycle of 0%...100%.
5697  * Access: RW
5698  */
5699 MLXSW_ITEM32(reg, mfsc, pwm_duty_cycle, 0x04, 0, 8);
5700
5701 static inline void mlxsw_reg_mfsc_pack(char *payload, u8 pwm,
5702                                        u8 pwm_duty_cycle)
5703 {
5704         MLXSW_REG_ZERO(mfsc, payload);
5705         mlxsw_reg_mfsc_pwm_set(payload, pwm);
5706         mlxsw_reg_mfsc_pwm_duty_cycle_set(payload, pwm_duty_cycle);
5707 }
5708
5709 /* MFSM - Management Fan Speed Measurement
5710  * ---------------------------------------
5711  * This register controls the settings of the Tacho measurements and
5712  * enables reading the Tachometer measurements.
5713  */
5714 #define MLXSW_REG_MFSM_ID 0x9003
5715 #define MLXSW_REG_MFSM_LEN 0x08
5716
5717 MLXSW_REG_DEFINE(mfsm, MLXSW_REG_MFSM_ID, MLXSW_REG_MFSM_LEN);
5718
5719 /* reg_mfsm_tacho
5720  * Fan tachometer index.
5721  * Access: Index
5722  */
5723 MLXSW_ITEM32(reg, mfsm, tacho, 0x00, 24, 4);
5724
5725 /* reg_mfsm_rpm
5726  * Fan speed (round per minute).
5727  * Access: RO
5728  */
5729 MLXSW_ITEM32(reg, mfsm, rpm, 0x04, 0, 16);
5730
5731 static inline void mlxsw_reg_mfsm_pack(char *payload, u8 tacho)
5732 {
5733         MLXSW_REG_ZERO(mfsm, payload);
5734         mlxsw_reg_mfsm_tacho_set(payload, tacho);
5735 }
5736
5737 /* MFSL - Management Fan Speed Limit Register
5738  * ------------------------------------------
5739  * The Fan Speed Limit register is used to configure the fan speed
5740  * event / interrupt notification mechanism. Fan speed threshold are
5741  * defined for both under-speed and over-speed.
5742  */
5743 #define MLXSW_REG_MFSL_ID 0x9004
5744 #define MLXSW_REG_MFSL_LEN 0x0C
5745
5746 MLXSW_REG_DEFINE(mfsl, MLXSW_REG_MFSL_ID, MLXSW_REG_MFSL_LEN);
5747
5748 /* reg_mfsl_tacho
5749  * Fan tachometer index.
5750  * Access: Index
5751  */
5752 MLXSW_ITEM32(reg, mfsl, tacho, 0x00, 24, 4);
5753
5754 /* reg_mfsl_tach_min
5755  * Tachometer minimum value (minimum RPM).
5756  * Access: RW
5757  */
5758 MLXSW_ITEM32(reg, mfsl, tach_min, 0x04, 0, 16);
5759
5760 /* reg_mfsl_tach_max
5761  * Tachometer maximum value (maximum RPM).
5762  * Access: RW
5763  */
5764 MLXSW_ITEM32(reg, mfsl, tach_max, 0x08, 0, 16);
5765
5766 static inline void mlxsw_reg_mfsl_pack(char *payload, u8 tacho,
5767                                        u16 tach_min, u16 tach_max)
5768 {
5769         MLXSW_REG_ZERO(mfsl, payload);
5770         mlxsw_reg_mfsl_tacho_set(payload, tacho);
5771         mlxsw_reg_mfsl_tach_min_set(payload, tach_min);
5772         mlxsw_reg_mfsl_tach_max_set(payload, tach_max);
5773 }
5774
5775 static inline void mlxsw_reg_mfsl_unpack(char *payload, u8 tacho,
5776                                          u16 *p_tach_min, u16 *p_tach_max)
5777 {
5778         if (p_tach_min)
5779                 *p_tach_min = mlxsw_reg_mfsl_tach_min_get(payload);
5780
5781         if (p_tach_max)
5782                 *p_tach_max = mlxsw_reg_mfsl_tach_max_get(payload);
5783 }
5784
5785 /* MTCAP - Management Temperature Capabilities
5786  * -------------------------------------------
5787  * This register exposes the capabilities of the device and
5788  * system temperature sensing.
5789  */
5790 #define MLXSW_REG_MTCAP_ID 0x9009
5791 #define MLXSW_REG_MTCAP_LEN 0x08
5792
5793 MLXSW_REG_DEFINE(mtcap, MLXSW_REG_MTCAP_ID, MLXSW_REG_MTCAP_LEN);
5794
5795 /* reg_mtcap_sensor_count
5796  * Number of sensors supported by the device.
5797  * This includes the QSFP module sensors (if exists in the QSFP module).
5798  * Access: RO
5799  */
5800 MLXSW_ITEM32(reg, mtcap, sensor_count, 0x00, 0, 7);
5801
5802 /* MTMP - Management Temperature
5803  * -----------------------------
5804  * This register controls the settings of the temperature measurements
5805  * and enables reading the temperature measurements. Note that temperature
5806  * is in 0.125 degrees Celsius.
5807  */
5808 #define MLXSW_REG_MTMP_ID 0x900A
5809 #define MLXSW_REG_MTMP_LEN 0x20
5810
5811 MLXSW_REG_DEFINE(mtmp, MLXSW_REG_MTMP_ID, MLXSW_REG_MTMP_LEN);
5812
5813 /* reg_mtmp_sensor_index
5814  * Sensors index to access.
5815  * 64-127 of sensor_index are mapped to the SFP+/QSFP modules sequentially
5816  * (module 0 is mapped to sensor_index 64).
5817  * Access: Index
5818  */
5819 MLXSW_ITEM32(reg, mtmp, sensor_index, 0x00, 0, 7);
5820
5821 /* Convert to milli degrees Celsius */
5822 #define MLXSW_REG_MTMP_TEMP_TO_MC(val) (val * 125)
5823
5824 /* reg_mtmp_temperature
5825  * Temperature reading from the sensor. Reading is in 0.125 Celsius
5826  * degrees units.
5827  * Access: RO
5828  */
5829 MLXSW_ITEM32(reg, mtmp, temperature, 0x04, 0, 16);
5830
5831 /* reg_mtmp_mte
5832  * Max Temperature Enable - enables measuring the max temperature on a sensor.
5833  * Access: RW
5834  */
5835 MLXSW_ITEM32(reg, mtmp, mte, 0x08, 31, 1);
5836
5837 /* reg_mtmp_mtr
5838  * Max Temperature Reset - clears the value of the max temperature register.
5839  * Access: WO
5840  */
5841 MLXSW_ITEM32(reg, mtmp, mtr, 0x08, 30, 1);
5842
5843 /* reg_mtmp_max_temperature
5844  * The highest measured temperature from the sensor.
5845  * When the bit mte is cleared, the field max_temperature is reserved.
5846  * Access: RO
5847  */
5848 MLXSW_ITEM32(reg, mtmp, max_temperature, 0x08, 0, 16);
5849
5850 /* reg_mtmp_tee
5851  * Temperature Event Enable.
5852  * 0 - Do not generate event
5853  * 1 - Generate event
5854  * 2 - Generate single event
5855  * Access: RW
5856  */
5857 MLXSW_ITEM32(reg, mtmp, tee, 0x0C, 30, 2);
5858
5859 #define MLXSW_REG_MTMP_THRESH_HI 0x348  /* 105 Celsius */
5860
5861 /* reg_mtmp_temperature_threshold_hi
5862  * High threshold for Temperature Warning Event. In 0.125 Celsius.
5863  * Access: RW
5864  */
5865 MLXSW_ITEM32(reg, mtmp, temperature_threshold_hi, 0x0C, 0, 16);
5866
5867 /* reg_mtmp_temperature_threshold_lo
5868  * Low threshold for Temperature Warning Event. In 0.125 Celsius.
5869  * Access: RW
5870  */
5871 MLXSW_ITEM32(reg, mtmp, temperature_threshold_lo, 0x10, 0, 16);
5872
5873 #define MLXSW_REG_MTMP_SENSOR_NAME_SIZE 8
5874
5875 /* reg_mtmp_sensor_name
5876  * Sensor Name
5877  * Access: RO
5878  */
5879 MLXSW_ITEM_BUF(reg, mtmp, sensor_name, 0x18, MLXSW_REG_MTMP_SENSOR_NAME_SIZE);
5880
5881 static inline void mlxsw_reg_mtmp_pack(char *payload, u8 sensor_index,
5882                                        bool max_temp_enable,
5883                                        bool max_temp_reset)
5884 {
5885         MLXSW_REG_ZERO(mtmp, payload);
5886         mlxsw_reg_mtmp_sensor_index_set(payload, sensor_index);
5887         mlxsw_reg_mtmp_mte_set(payload, max_temp_enable);
5888         mlxsw_reg_mtmp_mtr_set(payload, max_temp_reset);
5889         mlxsw_reg_mtmp_temperature_threshold_hi_set(payload,
5890                                                     MLXSW_REG_MTMP_THRESH_HI);
5891 }
5892
5893 static inline void mlxsw_reg_mtmp_unpack(char *payload, unsigned int *p_temp,
5894                                          unsigned int *p_max_temp,
5895                                          char *sensor_name)
5896 {
5897         u16 temp;
5898
5899         if (p_temp) {
5900                 temp = mlxsw_reg_mtmp_temperature_get(payload);
5901                 *p_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
5902         }
5903         if (p_max_temp) {
5904                 temp = mlxsw_reg_mtmp_max_temperature_get(payload);
5905                 *p_max_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
5906         }
5907         if (sensor_name)
5908                 mlxsw_reg_mtmp_sensor_name_memcpy_from(payload, sensor_name);
5909 }
5910
5911 /* MCIA - Management Cable Info Access
5912  * -----------------------------------
5913  * MCIA register is used to access the SFP+ and QSFP connector's EPROM.
5914  */
5915
5916 #define MLXSW_REG_MCIA_ID 0x9014
5917 #define MLXSW_REG_MCIA_LEN 0x40
5918
5919 MLXSW_REG_DEFINE(mcia, MLXSW_REG_MCIA_ID, MLXSW_REG_MCIA_LEN);
5920
5921 /* reg_mcia_l
5922  * Lock bit. Setting this bit will lock the access to the specific
5923  * cable. Used for updating a full page in a cable EPROM. Any access
5924  * other then subsequence writes will fail while the port is locked.
5925  * Access: RW
5926  */
5927 MLXSW_ITEM32(reg, mcia, l, 0x00, 31, 1);
5928
5929 /* reg_mcia_module
5930  * Module number.
5931  * Access: Index
5932  */
5933 MLXSW_ITEM32(reg, mcia, module, 0x00, 16, 8);
5934
5935 /* reg_mcia_status
5936  * Module status.
5937  * Access: RO
5938  */
5939 MLXSW_ITEM32(reg, mcia, status, 0x00, 0, 8);
5940
5941 /* reg_mcia_i2c_device_address
5942  * I2C device address.
5943  * Access: RW
5944  */
5945 MLXSW_ITEM32(reg, mcia, i2c_device_address, 0x04, 24, 8);
5946
5947 /* reg_mcia_page_number
5948  * Page number.
5949  * Access: RW
5950  */
5951 MLXSW_ITEM32(reg, mcia, page_number, 0x04, 16, 8);
5952
5953 /* reg_mcia_device_address
5954  * Device address.
5955  * Access: RW
5956  */
5957 MLXSW_ITEM32(reg, mcia, device_address, 0x04, 0, 16);
5958
5959 /* reg_mcia_size
5960  * Number of bytes to read/write (up to 48 bytes).
5961  * Access: RW
5962  */
5963 MLXSW_ITEM32(reg, mcia, size, 0x08, 0, 16);
5964
5965 #define MLXSW_SP_REG_MCIA_EEPROM_SIZE 48
5966
5967 /* reg_mcia_eeprom
5968  * Bytes to read/write.
5969  * Access: RW
5970  */
5971 MLXSW_ITEM_BUF(reg, mcia, eeprom, 0x10, MLXSW_SP_REG_MCIA_EEPROM_SIZE);
5972
5973 static inline void mlxsw_reg_mcia_pack(char *payload, u8 module, u8 lock,
5974                                        u8 page_number, u16 device_addr,
5975                                        u8 size, u8 i2c_device_addr)
5976 {
5977         MLXSW_REG_ZERO(mcia, payload);
5978         mlxsw_reg_mcia_module_set(payload, module);
5979         mlxsw_reg_mcia_l_set(payload, lock);
5980         mlxsw_reg_mcia_page_number_set(payload, page_number);
5981         mlxsw_reg_mcia_device_address_set(payload, device_addr);
5982         mlxsw_reg_mcia_size_set(payload, size);
5983         mlxsw_reg_mcia_i2c_device_address_set(payload, i2c_device_addr);
5984 }
5985
5986 /* MPAT - Monitoring Port Analyzer Table
5987  * -------------------------------------
5988  * MPAT Register is used to query and configure the Switch PortAnalyzer Table.
5989  * For an enabled analyzer, all fields except e (enable) cannot be modified.
5990  */
5991 #define MLXSW_REG_MPAT_ID 0x901A
5992 #define MLXSW_REG_MPAT_LEN 0x78
5993
5994 MLXSW_REG_DEFINE(mpat, MLXSW_REG_MPAT_ID, MLXSW_REG_MPAT_LEN);
5995
5996 /* reg_mpat_pa_id
5997  * Port Analyzer ID.
5998  * Access: Index
5999  */
6000 MLXSW_ITEM32(reg, mpat, pa_id, 0x00, 28, 4);
6001
6002 /* reg_mpat_system_port
6003  * A unique port identifier for the final destination of the packet.
6004  * Access: RW
6005  */
6006 MLXSW_ITEM32(reg, mpat, system_port, 0x00, 0, 16);
6007
6008 /* reg_mpat_e
6009  * Enable. Indicating the Port Analyzer is enabled.
6010  * Access: RW
6011  */
6012 MLXSW_ITEM32(reg, mpat, e, 0x04, 31, 1);
6013
6014 /* reg_mpat_qos
6015  * Quality Of Service Mode.
6016  * 0: CONFIGURED - QoS parameters (Switch Priority, and encapsulation
6017  * PCP, DEI, DSCP or VL) are configured.
6018  * 1: MAINTAIN - QoS parameters (Switch Priority, Color) are the
6019  * same as in the original packet that has triggered the mirroring. For
6020  * SPAN also the pcp,dei are maintained.
6021  * Access: RW
6022  */
6023 MLXSW_ITEM32(reg, mpat, qos, 0x04, 26, 1);
6024
6025 /* reg_mpat_be
6026  * Best effort mode. Indicates mirroring traffic should not cause packet
6027  * drop or back pressure, but will discard the mirrored packets. Mirrored
6028  * packets will be forwarded on a best effort manner.
6029  * 0: Do not discard mirrored packets
6030  * 1: Discard mirrored packets if causing congestion
6031  * Access: RW
6032  */
6033 MLXSW_ITEM32(reg, mpat, be, 0x04, 25, 1);
6034
6035 static inline void mlxsw_reg_mpat_pack(char *payload, u8 pa_id,
6036                                        u16 system_port, bool e)
6037 {
6038         MLXSW_REG_ZERO(mpat, payload);
6039         mlxsw_reg_mpat_pa_id_set(payload, pa_id);
6040         mlxsw_reg_mpat_system_port_set(payload, system_port);
6041         mlxsw_reg_mpat_e_set(payload, e);
6042         mlxsw_reg_mpat_qos_set(payload, 1);
6043         mlxsw_reg_mpat_be_set(payload, 1);
6044 }
6045
6046 /* MPAR - Monitoring Port Analyzer Register
6047  * ----------------------------------------
6048  * MPAR register is used to query and configure the port analyzer port mirroring
6049  * properties.
6050  */
6051 #define MLXSW_REG_MPAR_ID 0x901B
6052 #define MLXSW_REG_MPAR_LEN 0x08
6053
6054 MLXSW_REG_DEFINE(mpar, MLXSW_REG_MPAR_ID, MLXSW_REG_MPAR_LEN);
6055
6056 /* reg_mpar_local_port
6057  * The local port to mirror the packets from.
6058  * Access: Index
6059  */
6060 MLXSW_ITEM32(reg, mpar, local_port, 0x00, 16, 8);
6061
6062 enum mlxsw_reg_mpar_i_e {
6063         MLXSW_REG_MPAR_TYPE_EGRESS,
6064         MLXSW_REG_MPAR_TYPE_INGRESS,
6065 };
6066
6067 /* reg_mpar_i_e
6068  * Ingress/Egress
6069  * Access: Index
6070  */
6071 MLXSW_ITEM32(reg, mpar, i_e, 0x00, 0, 4);
6072
6073 /* reg_mpar_enable
6074  * Enable mirroring
6075  * By default, port mirroring is disabled for all ports.
6076  * Access: RW
6077  */
6078 MLXSW_ITEM32(reg, mpar, enable, 0x04, 31, 1);
6079
6080 /* reg_mpar_pa_id
6081  * Port Analyzer ID.
6082  * Access: RW
6083  */
6084 MLXSW_ITEM32(reg, mpar, pa_id, 0x04, 0, 4);
6085
6086 static inline void mlxsw_reg_mpar_pack(char *payload, u8 local_port,
6087                                        enum mlxsw_reg_mpar_i_e i_e,
6088                                        bool enable, u8 pa_id)
6089 {
6090         MLXSW_REG_ZERO(mpar, payload);
6091         mlxsw_reg_mpar_local_port_set(payload, local_port);
6092         mlxsw_reg_mpar_enable_set(payload, enable);
6093         mlxsw_reg_mpar_i_e_set(payload, i_e);
6094         mlxsw_reg_mpar_pa_id_set(payload, pa_id);
6095 }
6096
6097 /* MLCR - Management LED Control Register
6098  * --------------------------------------
6099  * Controls the system LEDs.
6100  */
6101 #define MLXSW_REG_MLCR_ID 0x902B
6102 #define MLXSW_REG_MLCR_LEN 0x0C
6103
6104 MLXSW_REG_DEFINE(mlcr, MLXSW_REG_MLCR_ID, MLXSW_REG_MLCR_LEN);
6105
6106 /* reg_mlcr_local_port
6107  * Local port number.
6108  * Access: RW
6109  */
6110 MLXSW_ITEM32(reg, mlcr, local_port, 0x00, 16, 8);
6111
6112 #define MLXSW_REG_MLCR_DURATION_MAX 0xFFFF
6113
6114 /* reg_mlcr_beacon_duration
6115  * Duration of the beacon to be active, in seconds.
6116  * 0x0 - Will turn off the beacon.
6117  * 0xFFFF - Will turn on the beacon until explicitly turned off.
6118  * Access: RW
6119  */
6120 MLXSW_ITEM32(reg, mlcr, beacon_duration, 0x04, 0, 16);
6121
6122 /* reg_mlcr_beacon_remain
6123  * Remaining duration of the beacon, in seconds.
6124  * 0xFFFF indicates an infinite amount of time.
6125  * Access: RO
6126  */
6127 MLXSW_ITEM32(reg, mlcr, beacon_remain, 0x08, 0, 16);
6128
6129 static inline void mlxsw_reg_mlcr_pack(char *payload, u8 local_port,
6130                                        bool active)
6131 {
6132         MLXSW_REG_ZERO(mlcr, payload);
6133         mlxsw_reg_mlcr_local_port_set(payload, local_port);
6134         mlxsw_reg_mlcr_beacon_duration_set(payload, active ?
6135                                            MLXSW_REG_MLCR_DURATION_MAX : 0);
6136 }
6137
6138 /* MCQI - Management Component Query Information
6139  * ---------------------------------------------
6140  * This register allows querying information about firmware components.
6141  */
6142 #define MLXSW_REG_MCQI_ID 0x9061
6143 #define MLXSW_REG_MCQI_BASE_LEN 0x18
6144 #define MLXSW_REG_MCQI_CAP_LEN 0x14
6145 #define MLXSW_REG_MCQI_LEN (MLXSW_REG_MCQI_BASE_LEN + MLXSW_REG_MCQI_CAP_LEN)
6146
6147 MLXSW_REG_DEFINE(mcqi, MLXSW_REG_MCQI_ID, MLXSW_REG_MCQI_LEN);
6148
6149 /* reg_mcqi_component_index
6150  * Index of the accessed component.
6151  * Access: Index
6152  */
6153 MLXSW_ITEM32(reg, mcqi, component_index, 0x00, 0, 16);
6154
6155 enum mlxfw_reg_mcqi_info_type {
6156         MLXSW_REG_MCQI_INFO_TYPE_CAPABILITIES,
6157 };
6158
6159 /* reg_mcqi_info_type
6160  * Component properties set.
6161  * Access: RW
6162  */
6163 MLXSW_ITEM32(reg, mcqi, info_type, 0x08, 0, 5);
6164
6165 /* reg_mcqi_offset
6166  * The requested/returned data offset from the section start, given in bytes.
6167  * Must be DWORD aligned.
6168  * Access: RW
6169  */
6170 MLXSW_ITEM32(reg, mcqi, offset, 0x10, 0, 32);
6171
6172 /* reg_mcqi_data_size
6173  * The requested/returned data size, given in bytes. If data_size is not DWORD
6174  * aligned, the last bytes are zero padded.
6175  * Access: RW
6176  */
6177 MLXSW_ITEM32(reg, mcqi, data_size, 0x14, 0, 16);
6178
6179 /* reg_mcqi_cap_max_component_size
6180  * Maximum size for this component, given in bytes.
6181  * Access: RO
6182  */
6183 MLXSW_ITEM32(reg, mcqi, cap_max_component_size, 0x20, 0, 32);
6184
6185 /* reg_mcqi_cap_log_mcda_word_size
6186  * Log 2 of the access word size in bytes. Read and write access must be aligned
6187  * to the word size. Write access must be done for an integer number of words.
6188  * Access: RO
6189  */
6190 MLXSW_ITEM32(reg, mcqi, cap_log_mcda_word_size, 0x24, 28, 4);
6191
6192 /* reg_mcqi_cap_mcda_max_write_size
6193  * Maximal write size for MCDA register
6194  * Access: RO
6195  */
6196 MLXSW_ITEM32(reg, mcqi, cap_mcda_max_write_size, 0x24, 0, 16);
6197
6198 static inline void mlxsw_reg_mcqi_pack(char *payload, u16 component_index)
6199 {
6200         MLXSW_REG_ZERO(mcqi, payload);
6201         mlxsw_reg_mcqi_component_index_set(payload, component_index);
6202         mlxsw_reg_mcqi_info_type_set(payload,
6203                                      MLXSW_REG_MCQI_INFO_TYPE_CAPABILITIES);
6204         mlxsw_reg_mcqi_offset_set(payload, 0);
6205         mlxsw_reg_mcqi_data_size_set(payload, MLXSW_REG_MCQI_CAP_LEN);
6206 }
6207
6208 static inline void mlxsw_reg_mcqi_unpack(char *payload,
6209                                          u32 *p_cap_max_component_size,
6210                                          u8 *p_cap_log_mcda_word_size,
6211                                          u16 *p_cap_mcda_max_write_size)
6212 {
6213         *p_cap_max_component_size =
6214                 mlxsw_reg_mcqi_cap_max_component_size_get(payload);
6215         *p_cap_log_mcda_word_size =
6216                 mlxsw_reg_mcqi_cap_log_mcda_word_size_get(payload);
6217         *p_cap_mcda_max_write_size =
6218                 mlxsw_reg_mcqi_cap_mcda_max_write_size_get(payload);
6219 }
6220
6221 /* MCC - Management Component Control
6222  * ----------------------------------
6223  * Controls the firmware component and updates the FSM.
6224  */
6225 #define MLXSW_REG_MCC_ID 0x9062
6226 #define MLXSW_REG_MCC_LEN 0x1C
6227
6228 MLXSW_REG_DEFINE(mcc, MLXSW_REG_MCC_ID, MLXSW_REG_MCC_LEN);
6229
6230 enum mlxsw_reg_mcc_instruction {
6231         MLXSW_REG_MCC_INSTRUCTION_LOCK_UPDATE_HANDLE = 0x01,
6232         MLXSW_REG_MCC_INSTRUCTION_RELEASE_UPDATE_HANDLE = 0x02,
6233         MLXSW_REG_MCC_INSTRUCTION_UPDATE_COMPONENT = 0x03,
6234         MLXSW_REG_MCC_INSTRUCTION_VERIFY_COMPONENT = 0x04,
6235         MLXSW_REG_MCC_INSTRUCTION_ACTIVATE = 0x06,
6236         MLXSW_REG_MCC_INSTRUCTION_CANCEL = 0x08,
6237 };
6238
6239 /* reg_mcc_instruction
6240  * Command to be executed by the FSM.
6241  * Applicable for write operation only.
6242  * Access: RW
6243  */
6244 MLXSW_ITEM32(reg, mcc, instruction, 0x00, 0, 8);
6245
6246 /* reg_mcc_component_index
6247  * Index of the accessed component. Applicable only for commands that
6248  * refer to components. Otherwise, this field is reserved.
6249  * Access: Index
6250  */
6251 MLXSW_ITEM32(reg, mcc, component_index, 0x04, 0, 16);
6252
6253 /* reg_mcc_update_handle
6254  * Token representing the current flow executed by the FSM.
6255  * Access: WO
6256  */
6257 MLXSW_ITEM32(reg, mcc, update_handle, 0x08, 0, 24);
6258
6259 /* reg_mcc_error_code
6260  * Indicates the successful completion of the instruction, or the reason it
6261  * failed
6262  * Access: RO
6263  */
6264 MLXSW_ITEM32(reg, mcc, error_code, 0x0C, 8, 8);
6265
6266 /* reg_mcc_control_state
6267  * Current FSM state
6268  * Access: RO
6269  */
6270 MLXSW_ITEM32(reg, mcc, control_state, 0x0C, 0, 4);
6271
6272 /* reg_mcc_component_size
6273  * Component size in bytes. Valid for UPDATE_COMPONENT instruction. Specifying
6274  * the size may shorten the update time. Value 0x0 means that size is
6275  * unspecified.
6276  * Access: WO
6277  */
6278 MLXSW_ITEM32(reg, mcc, component_size, 0x10, 0, 32);
6279
6280 static inline void mlxsw_reg_mcc_pack(char *payload,
6281                                       enum mlxsw_reg_mcc_instruction instr,
6282                                       u16 component_index, u32 update_handle,
6283                                       u32 component_size)
6284 {
6285         MLXSW_REG_ZERO(mcc, payload);
6286         mlxsw_reg_mcc_instruction_set(payload, instr);
6287         mlxsw_reg_mcc_component_index_set(payload, component_index);
6288         mlxsw_reg_mcc_update_handle_set(payload, update_handle);
6289         mlxsw_reg_mcc_component_size_set(payload, component_size);
6290 }
6291
6292 static inline void mlxsw_reg_mcc_unpack(char *payload, u32 *p_update_handle,
6293                                         u8 *p_error_code, u8 *p_control_state)
6294 {
6295         if (p_update_handle)
6296                 *p_update_handle = mlxsw_reg_mcc_update_handle_get(payload);
6297         if (p_error_code)
6298                 *p_error_code = mlxsw_reg_mcc_error_code_get(payload);
6299         if (p_control_state)
6300                 *p_control_state = mlxsw_reg_mcc_control_state_get(payload);
6301 }
6302
6303 /* MCDA - Management Component Data Access
6304  * ---------------------------------------
6305  * This register allows reading and writing a firmware component.
6306  */
6307 #define MLXSW_REG_MCDA_ID 0x9063
6308 #define MLXSW_REG_MCDA_BASE_LEN 0x10
6309 #define MLXSW_REG_MCDA_MAX_DATA_LEN 0x80
6310 #define MLXSW_REG_MCDA_LEN \
6311                 (MLXSW_REG_MCDA_BASE_LEN + MLXSW_REG_MCDA_MAX_DATA_LEN)
6312
6313 MLXSW_REG_DEFINE(mcda, MLXSW_REG_MCDA_ID, MLXSW_REG_MCDA_LEN);
6314
6315 /* reg_mcda_update_handle
6316  * Token representing the current flow executed by the FSM.
6317  * Access: RW
6318  */
6319 MLXSW_ITEM32(reg, mcda, update_handle, 0x00, 0, 24);
6320
6321 /* reg_mcda_offset
6322  * Offset of accessed address relative to component start. Accesses must be in
6323  * accordance to log_mcda_word_size in MCQI reg.
6324  * Access: RW
6325  */
6326 MLXSW_ITEM32(reg, mcda, offset, 0x04, 0, 32);
6327
6328 /* reg_mcda_size
6329  * Size of the data accessed, given in bytes.
6330  * Access: RW
6331  */
6332 MLXSW_ITEM32(reg, mcda, size, 0x08, 0, 16);
6333
6334 /* reg_mcda_data
6335  * Data block accessed.
6336  * Access: RW
6337  */
6338 MLXSW_ITEM32_INDEXED(reg, mcda, data, 0x10, 0, 32, 4, 0, false);
6339
6340 static inline void mlxsw_reg_mcda_pack(char *payload, u32 update_handle,
6341                                        u32 offset, u16 size, u8 *data)
6342 {
6343         int i;
6344
6345         MLXSW_REG_ZERO(mcda, payload);
6346         mlxsw_reg_mcda_update_handle_set(payload, update_handle);
6347         mlxsw_reg_mcda_offset_set(payload, offset);
6348         mlxsw_reg_mcda_size_set(payload, size);
6349
6350         for (i = 0; i < size / 4; i++)
6351                 mlxsw_reg_mcda_data_set(payload, i, *(u32 *) &data[i * 4]);
6352 }
6353
6354 /* MPSC - Monitoring Packet Sampling Configuration Register
6355  * --------------------------------------------------------
6356  * MPSC Register is used to configure the Packet Sampling mechanism.
6357  */
6358 #define MLXSW_REG_MPSC_ID 0x9080
6359 #define MLXSW_REG_MPSC_LEN 0x1C
6360
6361 MLXSW_REG_DEFINE(mpsc, MLXSW_REG_MPSC_ID, MLXSW_REG_MPSC_LEN);
6362
6363 /* reg_mpsc_local_port
6364  * Local port number
6365  * Not supported for CPU port
6366  * Access: Index
6367  */
6368 MLXSW_ITEM32(reg, mpsc, local_port, 0x00, 16, 8);
6369
6370 /* reg_mpsc_e
6371  * Enable sampling on port local_port
6372  * Access: RW
6373  */
6374 MLXSW_ITEM32(reg, mpsc, e, 0x04, 30, 1);
6375
6376 #define MLXSW_REG_MPSC_RATE_MAX 3500000000UL
6377
6378 /* reg_mpsc_rate
6379  * Sampling rate = 1 out of rate packets (with randomization around
6380  * the point). Valid values are: 1 to MLXSW_REG_MPSC_RATE_MAX
6381  * Access: RW
6382  */
6383 MLXSW_ITEM32(reg, mpsc, rate, 0x08, 0, 32);
6384
6385 static inline void mlxsw_reg_mpsc_pack(char *payload, u8 local_port, bool e,
6386                                        u32 rate)
6387 {
6388         MLXSW_REG_ZERO(mpsc, payload);
6389         mlxsw_reg_mpsc_local_port_set(payload, local_port);
6390         mlxsw_reg_mpsc_e_set(payload, e);
6391         mlxsw_reg_mpsc_rate_set(payload, rate);
6392 }
6393
6394 /* MGPC - Monitoring General Purpose Counter Set Register
6395  * The MGPC register retrieves and sets the General Purpose Counter Set.
6396  */
6397 #define MLXSW_REG_MGPC_ID 0x9081
6398 #define MLXSW_REG_MGPC_LEN 0x18
6399
6400 MLXSW_REG_DEFINE(mgpc, MLXSW_REG_MGPC_ID, MLXSW_REG_MGPC_LEN);
6401
6402 /* reg_mgpc_counter_set_type
6403  * Counter set type.
6404  * Access: OP
6405  */
6406 MLXSW_ITEM32(reg, mgpc, counter_set_type, 0x00, 24, 8);
6407
6408 /* reg_mgpc_counter_index
6409  * Counter index.
6410  * Access: Index
6411  */
6412 MLXSW_ITEM32(reg, mgpc, counter_index, 0x00, 0, 24);
6413
6414 enum mlxsw_reg_mgpc_opcode {
6415         /* Nop */
6416         MLXSW_REG_MGPC_OPCODE_NOP = 0x00,
6417         /* Clear counters */
6418         MLXSW_REG_MGPC_OPCODE_CLEAR = 0x08,
6419 };
6420
6421 /* reg_mgpc_opcode
6422  * Opcode.
6423  * Access: OP
6424  */
6425 MLXSW_ITEM32(reg, mgpc, opcode, 0x04, 28, 4);
6426
6427 /* reg_mgpc_byte_counter
6428  * Byte counter value.
6429  * Access: RW
6430  */
6431 MLXSW_ITEM64(reg, mgpc, byte_counter, 0x08, 0, 64);
6432
6433 /* reg_mgpc_packet_counter
6434  * Packet counter value.
6435  * Access: RW
6436  */
6437 MLXSW_ITEM64(reg, mgpc, packet_counter, 0x10, 0, 64);
6438
6439 static inline void mlxsw_reg_mgpc_pack(char *payload, u32 counter_index,
6440                                        enum mlxsw_reg_mgpc_opcode opcode,
6441                                        enum mlxsw_reg_flow_counter_set_type set_type)
6442 {
6443         MLXSW_REG_ZERO(mgpc, payload);
6444         mlxsw_reg_mgpc_counter_index_set(payload, counter_index);
6445         mlxsw_reg_mgpc_counter_set_type_set(payload, set_type);
6446         mlxsw_reg_mgpc_opcode_set(payload, opcode);
6447 }
6448
6449 /* TIGCR - Tunneling IPinIP General Configuration Register
6450  * -------------------------------------------------------
6451  * The TIGCR register is used for setting up the IPinIP Tunnel configuration.
6452  */
6453 #define MLXSW_REG_TIGCR_ID 0xA801
6454 #define MLXSW_REG_TIGCR_LEN 0x10
6455
6456 MLXSW_REG_DEFINE(tigcr, MLXSW_REG_TIGCR_ID, MLXSW_REG_TIGCR_LEN);
6457
6458 /* reg_tigcr_ipip_ttlc
6459  * For IPinIP Tunnel encapsulation: whether to copy the ttl from the packet
6460  * header.
6461  * Access: RW
6462  */
6463 MLXSW_ITEM32(reg, tigcr, ttlc, 0x04, 8, 1);
6464
6465 /* reg_tigcr_ipip_ttl_uc
6466  * The TTL for IPinIP Tunnel encapsulation of unicast packets if
6467  * reg_tigcr_ipip_ttlc is unset.
6468  * Access: RW
6469  */
6470 MLXSW_ITEM32(reg, tigcr, ttl_uc, 0x04, 0, 8);
6471
6472 static inline void mlxsw_reg_tigcr_pack(char *payload, bool ttlc, u8 ttl_uc)
6473 {
6474         MLXSW_REG_ZERO(tigcr, payload);
6475         mlxsw_reg_tigcr_ttlc_set(payload, ttlc);
6476         mlxsw_reg_tigcr_ttl_uc_set(payload, ttl_uc);
6477 }
6478
6479 /* SBPR - Shared Buffer Pools Register
6480  * -----------------------------------
6481  * The SBPR configures and retrieves the shared buffer pools and configuration.
6482  */
6483 #define MLXSW_REG_SBPR_ID 0xB001
6484 #define MLXSW_REG_SBPR_LEN 0x14
6485
6486 MLXSW_REG_DEFINE(sbpr, MLXSW_REG_SBPR_ID, MLXSW_REG_SBPR_LEN);
6487
6488 /* shared direstion enum for SBPR, SBCM, SBPM */
6489 enum mlxsw_reg_sbxx_dir {
6490         MLXSW_REG_SBXX_DIR_INGRESS,
6491         MLXSW_REG_SBXX_DIR_EGRESS,
6492 };
6493
6494 /* reg_sbpr_dir
6495  * Direction.
6496  * Access: Index
6497  */
6498 MLXSW_ITEM32(reg, sbpr, dir, 0x00, 24, 2);
6499
6500 /* reg_sbpr_pool
6501  * Pool index.
6502  * Access: Index
6503  */
6504 MLXSW_ITEM32(reg, sbpr, pool, 0x00, 0, 4);
6505
6506 /* reg_sbpr_size
6507  * Pool size in buffer cells.
6508  * Access: RW
6509  */
6510 MLXSW_ITEM32(reg, sbpr, size, 0x04, 0, 24);
6511
6512 enum mlxsw_reg_sbpr_mode {
6513         MLXSW_REG_SBPR_MODE_STATIC,
6514         MLXSW_REG_SBPR_MODE_DYNAMIC,
6515 };
6516
6517 /* reg_sbpr_mode
6518  * Pool quota calculation mode.
6519  * Access: RW
6520  */
6521 MLXSW_ITEM32(reg, sbpr, mode, 0x08, 0, 4);
6522
6523 static inline void mlxsw_reg_sbpr_pack(char *payload, u8 pool,
6524                                        enum mlxsw_reg_sbxx_dir dir,
6525                                        enum mlxsw_reg_sbpr_mode mode, u32 size)
6526 {
6527         MLXSW_REG_ZERO(sbpr, payload);
6528         mlxsw_reg_sbpr_pool_set(payload, pool);
6529         mlxsw_reg_sbpr_dir_set(payload, dir);
6530         mlxsw_reg_sbpr_mode_set(payload, mode);
6531         mlxsw_reg_sbpr_size_set(payload, size);
6532 }
6533
6534 /* SBCM - Shared Buffer Class Management Register
6535  * ----------------------------------------------
6536  * The SBCM register configures and retrieves the shared buffer allocation
6537  * and configuration according to Port-PG, including the binding to pool
6538  * and definition of the associated quota.
6539  */
6540 #define MLXSW_REG_SBCM_ID 0xB002
6541 #define MLXSW_REG_SBCM_LEN 0x28
6542
6543 MLXSW_REG_DEFINE(sbcm, MLXSW_REG_SBCM_ID, MLXSW_REG_SBCM_LEN);
6544
6545 /* reg_sbcm_local_port
6546  * Local port number.
6547  * For Ingress: excludes CPU port and Router port
6548  * For Egress: excludes IP Router
6549  * Access: Index
6550  */
6551 MLXSW_ITEM32(reg, sbcm, local_port, 0x00, 16, 8);
6552
6553 /* reg_sbcm_pg_buff
6554  * PG buffer - Port PG (dir=ingress) / traffic class (dir=egress)
6555  * For PG buffer: range is 0..cap_max_pg_buffers - 1
6556  * For traffic class: range is 0..cap_max_tclass - 1
6557  * Note that when traffic class is in MC aware mode then the traffic
6558  * classes which are MC aware cannot be configured.
6559  * Access: Index
6560  */
6561 MLXSW_ITEM32(reg, sbcm, pg_buff, 0x00, 8, 6);
6562
6563 /* reg_sbcm_dir
6564  * Direction.
6565  * Access: Index
6566  */
6567 MLXSW_ITEM32(reg, sbcm, dir, 0x00, 0, 2);
6568
6569 /* reg_sbcm_min_buff
6570  * Minimum buffer size for the limiter, in cells.
6571  * Access: RW
6572  */
6573 MLXSW_ITEM32(reg, sbcm, min_buff, 0x18, 0, 24);
6574
6575 /* shared max_buff limits for dynamic threshold for SBCM, SBPM */
6576 #define MLXSW_REG_SBXX_DYN_MAX_BUFF_MIN 1
6577 #define MLXSW_REG_SBXX_DYN_MAX_BUFF_MAX 14
6578
6579 /* reg_sbcm_max_buff
6580  * When the pool associated to the port-pg/tclass is configured to
6581  * static, Maximum buffer size for the limiter configured in cells.
6582  * When the pool associated to the port-pg/tclass is configured to
6583  * dynamic, the max_buff holds the "alpha" parameter, supporting
6584  * the following values:
6585  * 0: 0
6586  * i: (1/128)*2^(i-1), for i=1..14
6587  * 0xFF: Infinity
6588  * Access: RW
6589  */
6590 MLXSW_ITEM32(reg, sbcm, max_buff, 0x1C, 0, 24);
6591
6592 /* reg_sbcm_pool
6593  * Association of the port-priority to a pool.
6594  * Access: RW
6595  */
6596 MLXSW_ITEM32(reg, sbcm, pool, 0x24, 0, 4);
6597
6598 static inline void mlxsw_reg_sbcm_pack(char *payload, u8 local_port, u8 pg_buff,
6599                                        enum mlxsw_reg_sbxx_dir dir,
6600                                        u32 min_buff, u32 max_buff, u8 pool)
6601 {
6602         MLXSW_REG_ZERO(sbcm, payload);
6603         mlxsw_reg_sbcm_local_port_set(payload, local_port);
6604         mlxsw_reg_sbcm_pg_buff_set(payload, pg_buff);
6605         mlxsw_reg_sbcm_dir_set(payload, dir);
6606         mlxsw_reg_sbcm_min_buff_set(payload, min_buff);
6607         mlxsw_reg_sbcm_max_buff_set(payload, max_buff);
6608         mlxsw_reg_sbcm_pool_set(payload, pool);
6609 }
6610
6611 /* SBPM - Shared Buffer Port Management Register
6612  * ---------------------------------------------
6613  * The SBPM register configures and retrieves the shared buffer allocation
6614  * and configuration according to Port-Pool, including the definition
6615  * of the associated quota.
6616  */
6617 #define MLXSW_REG_SBPM_ID 0xB003
6618 #define MLXSW_REG_SBPM_LEN 0x28
6619
6620 MLXSW_REG_DEFINE(sbpm, MLXSW_REG_SBPM_ID, MLXSW_REG_SBPM_LEN);
6621
6622 /* reg_sbpm_local_port
6623  * Local port number.
6624  * For Ingress: excludes CPU port and Router port
6625  * For Egress: excludes IP Router
6626  * Access: Index
6627  */
6628 MLXSW_ITEM32(reg, sbpm, local_port, 0x00, 16, 8);
6629
6630 /* reg_sbpm_pool
6631  * The pool associated to quota counting on the local_port.
6632  * Access: Index
6633  */
6634 MLXSW_ITEM32(reg, sbpm, pool, 0x00, 8, 4);
6635
6636 /* reg_sbpm_dir
6637  * Direction.
6638  * Access: Index
6639  */
6640 MLXSW_ITEM32(reg, sbpm, dir, 0x00, 0, 2);
6641
6642 /* reg_sbpm_buff_occupancy
6643  * Current buffer occupancy in cells.
6644  * Access: RO
6645  */
6646 MLXSW_ITEM32(reg, sbpm, buff_occupancy, 0x10, 0, 24);
6647
6648 /* reg_sbpm_clr
6649  * Clear Max Buffer Occupancy
6650  * When this bit is set, max_buff_occupancy field is cleared (and a
6651  * new max value is tracked from the time the clear was performed).
6652  * Access: OP
6653  */
6654 MLXSW_ITEM32(reg, sbpm, clr, 0x14, 31, 1);
6655
6656 /* reg_sbpm_max_buff_occupancy
6657  * Maximum value of buffer occupancy in cells monitored. Cleared by
6658  * writing to the clr field.
6659  * Access: RO
6660  */
6661 MLXSW_ITEM32(reg, sbpm, max_buff_occupancy, 0x14, 0, 24);
6662
6663 /* reg_sbpm_min_buff
6664  * Minimum buffer size for the limiter, in cells.
6665  * Access: RW
6666  */
6667 MLXSW_ITEM32(reg, sbpm, min_buff, 0x18, 0, 24);
6668
6669 /* reg_sbpm_max_buff
6670  * When the pool associated to the port-pg/tclass is configured to
6671  * static, Maximum buffer size for the limiter configured in cells.
6672  * When the pool associated to the port-pg/tclass is configured to
6673  * dynamic, the max_buff holds the "alpha" parameter, supporting
6674  * the following values:
6675  * 0: 0
6676  * i: (1/128)*2^(i-1), for i=1..14
6677  * 0xFF: Infinity
6678  * Access: RW
6679  */
6680 MLXSW_ITEM32(reg, sbpm, max_buff, 0x1C, 0, 24);
6681
6682 static inline void mlxsw_reg_sbpm_pack(char *payload, u8 local_port, u8 pool,
6683                                        enum mlxsw_reg_sbxx_dir dir, bool clr,
6684                                        u32 min_buff, u32 max_buff)
6685 {
6686         MLXSW_REG_ZERO(sbpm, payload);
6687         mlxsw_reg_sbpm_local_port_set(payload, local_port);
6688         mlxsw_reg_sbpm_pool_set(payload, pool);
6689         mlxsw_reg_sbpm_dir_set(payload, dir);
6690         mlxsw_reg_sbpm_clr_set(payload, clr);
6691         mlxsw_reg_sbpm_min_buff_set(payload, min_buff);
6692         mlxsw_reg_sbpm_max_buff_set(payload, max_buff);
6693 }
6694
6695 static inline void mlxsw_reg_sbpm_unpack(char *payload, u32 *p_buff_occupancy,
6696                                          u32 *p_max_buff_occupancy)
6697 {
6698         *p_buff_occupancy = mlxsw_reg_sbpm_buff_occupancy_get(payload);
6699         *p_max_buff_occupancy = mlxsw_reg_sbpm_max_buff_occupancy_get(payload);
6700 }
6701
6702 /* SBMM - Shared Buffer Multicast Management Register
6703  * --------------------------------------------------
6704  * The SBMM register configures and retrieves the shared buffer allocation
6705  * and configuration for MC packets according to Switch-Priority, including
6706  * the binding to pool and definition of the associated quota.
6707  */
6708 #define MLXSW_REG_SBMM_ID 0xB004
6709 #define MLXSW_REG_SBMM_LEN 0x28
6710
6711 MLXSW_REG_DEFINE(sbmm, MLXSW_REG_SBMM_ID, MLXSW_REG_SBMM_LEN);
6712
6713 /* reg_sbmm_prio
6714  * Switch Priority.
6715  * Access: Index
6716  */
6717 MLXSW_ITEM32(reg, sbmm, prio, 0x00, 8, 4);
6718
6719 /* reg_sbmm_min_buff
6720  * Minimum buffer size for the limiter, in cells.
6721  * Access: RW
6722  */
6723 MLXSW_ITEM32(reg, sbmm, min_buff, 0x18, 0, 24);
6724
6725 /* reg_sbmm_max_buff
6726  * When the pool associated to the port-pg/tclass is configured to
6727  * static, Maximum buffer size for the limiter configured in cells.
6728  * When the pool associated to the port-pg/tclass is configured to
6729  * dynamic, the max_buff holds the "alpha" parameter, supporting
6730  * the following values:
6731  * 0: 0
6732  * i: (1/128)*2^(i-1), for i=1..14
6733  * 0xFF: Infinity
6734  * Access: RW
6735  */
6736 MLXSW_ITEM32(reg, sbmm, max_buff, 0x1C, 0, 24);
6737
6738 /* reg_sbmm_pool
6739  * Association of the port-priority to a pool.
6740  * Access: RW
6741  */
6742 MLXSW_ITEM32(reg, sbmm, pool, 0x24, 0, 4);
6743
6744 static inline void mlxsw_reg_sbmm_pack(char *payload, u8 prio, u32 min_buff,
6745                                        u32 max_buff, u8 pool)
6746 {
6747         MLXSW_REG_ZERO(sbmm, payload);
6748         mlxsw_reg_sbmm_prio_set(payload, prio);
6749         mlxsw_reg_sbmm_min_buff_set(payload, min_buff);
6750         mlxsw_reg_sbmm_max_buff_set(payload, max_buff);
6751         mlxsw_reg_sbmm_pool_set(payload, pool);
6752 }
6753
6754 /* SBSR - Shared Buffer Status Register
6755  * ------------------------------------
6756  * The SBSR register retrieves the shared buffer occupancy according to
6757  * Port-Pool. Note that this register enables reading a large amount of data.
6758  * It is the user's responsibility to limit the amount of data to ensure the
6759  * response can match the maximum transfer unit. In case the response exceeds
6760  * the maximum transport unit, it will be truncated with no special notice.
6761  */
6762 #define MLXSW_REG_SBSR_ID 0xB005
6763 #define MLXSW_REG_SBSR_BASE_LEN 0x5C /* base length, without records */
6764 #define MLXSW_REG_SBSR_REC_LEN 0x8 /* record length */
6765 #define MLXSW_REG_SBSR_REC_MAX_COUNT 120
6766 #define MLXSW_REG_SBSR_LEN (MLXSW_REG_SBSR_BASE_LEN +   \
6767                             MLXSW_REG_SBSR_REC_LEN *    \
6768                             MLXSW_REG_SBSR_REC_MAX_COUNT)
6769
6770 MLXSW_REG_DEFINE(sbsr, MLXSW_REG_SBSR_ID, MLXSW_REG_SBSR_LEN);
6771
6772 /* reg_sbsr_clr
6773  * Clear Max Buffer Occupancy. When this bit is set, the max_buff_occupancy
6774  * field is cleared (and a new max value is tracked from the time the clear
6775  * was performed).
6776  * Access: OP
6777  */
6778 MLXSW_ITEM32(reg, sbsr, clr, 0x00, 31, 1);
6779
6780 /* reg_sbsr_ingress_port_mask
6781  * Bit vector for all ingress network ports.
6782  * Indicates which of the ports (for which the relevant bit is set)
6783  * are affected by the set operation. Configuration of any other port
6784  * does not change.
6785  * Access: Index
6786  */
6787 MLXSW_ITEM_BIT_ARRAY(reg, sbsr, ingress_port_mask, 0x10, 0x20, 1);
6788
6789 /* reg_sbsr_pg_buff_mask
6790  * Bit vector for all switch priority groups.
6791  * Indicates which of the priorities (for which the relevant bit is set)
6792  * are affected by the set operation. Configuration of any other priority
6793  * does not change.
6794  * Range is 0..cap_max_pg_buffers - 1
6795  * Access: Index
6796  */
6797 MLXSW_ITEM_BIT_ARRAY(reg, sbsr, pg_buff_mask, 0x30, 0x4, 1);
6798
6799 /* reg_sbsr_egress_port_mask
6800  * Bit vector for all egress network ports.
6801  * Indicates which of the ports (for which the relevant bit is set)
6802  * are affected by the set operation. Configuration of any other port
6803  * does not change.
6804  * Access: Index
6805  */
6806 MLXSW_ITEM_BIT_ARRAY(reg, sbsr, egress_port_mask, 0x34, 0x20, 1);
6807
6808 /* reg_sbsr_tclass_mask
6809  * Bit vector for all traffic classes.
6810  * Indicates which of the traffic classes (for which the relevant bit is
6811  * set) are affected by the set operation. Configuration of any other
6812  * traffic class does not change.
6813  * Range is 0..cap_max_tclass - 1
6814  * Access: Index
6815  */
6816 MLXSW_ITEM_BIT_ARRAY(reg, sbsr, tclass_mask, 0x54, 0x8, 1);
6817
6818 static inline void mlxsw_reg_sbsr_pack(char *payload, bool clr)
6819 {
6820         MLXSW_REG_ZERO(sbsr, payload);
6821         mlxsw_reg_sbsr_clr_set(payload, clr);
6822 }
6823
6824 /* reg_sbsr_rec_buff_occupancy
6825  * Current buffer occupancy in cells.
6826  * Access: RO
6827  */
6828 MLXSW_ITEM32_INDEXED(reg, sbsr, rec_buff_occupancy, MLXSW_REG_SBSR_BASE_LEN,
6829                      0, 24, MLXSW_REG_SBSR_REC_LEN, 0x00, false);
6830
6831 /* reg_sbsr_rec_max_buff_occupancy
6832  * Maximum value of buffer occupancy in cells monitored. Cleared by
6833  * writing to the clr field.
6834  * Access: RO
6835  */
6836 MLXSW_ITEM32_INDEXED(reg, sbsr, rec_max_buff_occupancy, MLXSW_REG_SBSR_BASE_LEN,
6837                      0, 24, MLXSW_REG_SBSR_REC_LEN, 0x04, false);
6838
6839 static inline void mlxsw_reg_sbsr_rec_unpack(char *payload, int rec_index,
6840                                              u32 *p_buff_occupancy,
6841                                              u32 *p_max_buff_occupancy)
6842 {
6843         *p_buff_occupancy =
6844                 mlxsw_reg_sbsr_rec_buff_occupancy_get(payload, rec_index);
6845         *p_max_buff_occupancy =
6846                 mlxsw_reg_sbsr_rec_max_buff_occupancy_get(payload, rec_index);
6847 }
6848
6849 /* SBIB - Shared Buffer Internal Buffer Register
6850  * ---------------------------------------------
6851  * The SBIB register configures per port buffers for internal use. The internal
6852  * buffers consume memory on the port buffers (note that the port buffers are
6853  * used also by PBMC).
6854  *
6855  * For Spectrum this is used for egress mirroring.
6856  */
6857 #define MLXSW_REG_SBIB_ID 0xB006
6858 #define MLXSW_REG_SBIB_LEN 0x10
6859
6860 MLXSW_REG_DEFINE(sbib, MLXSW_REG_SBIB_ID, MLXSW_REG_SBIB_LEN);
6861
6862 /* reg_sbib_local_port
6863  * Local port number
6864  * Not supported for CPU port and router port
6865  * Access: Index
6866  */
6867 MLXSW_ITEM32(reg, sbib, local_port, 0x00, 16, 8);
6868
6869 /* reg_sbib_buff_size
6870  * Units represented in cells
6871  * Allowed range is 0 to (cap_max_headroom_size - 1)
6872  * Default is 0
6873  * Access: RW
6874  */
6875 MLXSW_ITEM32(reg, sbib, buff_size, 0x08, 0, 24);
6876
6877 static inline void mlxsw_reg_sbib_pack(char *payload, u8 local_port,
6878                                        u32 buff_size)
6879 {
6880         MLXSW_REG_ZERO(sbib, payload);
6881         mlxsw_reg_sbib_local_port_set(payload, local_port);
6882         mlxsw_reg_sbib_buff_size_set(payload, buff_size);
6883 }
6884
6885 static const struct mlxsw_reg_info *mlxsw_reg_infos[] = {
6886         MLXSW_REG(sgcr),
6887         MLXSW_REG(spad),
6888         MLXSW_REG(smid),
6889         MLXSW_REG(sspr),
6890         MLXSW_REG(sfdat),
6891         MLXSW_REG(sfd),
6892         MLXSW_REG(sfn),
6893         MLXSW_REG(spms),
6894         MLXSW_REG(spvid),
6895         MLXSW_REG(spvm),
6896         MLXSW_REG(spaft),
6897         MLXSW_REG(sfgc),
6898         MLXSW_REG(sftr),
6899         MLXSW_REG(sfdf),
6900         MLXSW_REG(sldr),
6901         MLXSW_REG(slcr),
6902         MLXSW_REG(slcor),
6903         MLXSW_REG(spmlr),
6904         MLXSW_REG(svfa),
6905         MLXSW_REG(svpe),
6906         MLXSW_REG(sfmr),
6907         MLXSW_REG(spvmlr),
6908         MLXSW_REG(ppbt),
6909         MLXSW_REG(pacl),
6910         MLXSW_REG(pagt),
6911         MLXSW_REG(ptar),
6912         MLXSW_REG(ppbs),
6913         MLXSW_REG(prcr),
6914         MLXSW_REG(pefa),
6915         MLXSW_REG(ptce2),
6916         MLXSW_REG(qpcr),
6917         MLXSW_REG(qtct),
6918         MLXSW_REG(qeec),
6919         MLXSW_REG(pmlp),
6920         MLXSW_REG(pmtu),
6921         MLXSW_REG(ptys),
6922         MLXSW_REG(ppad),
6923         MLXSW_REG(paos),
6924         MLXSW_REG(pfcc),
6925         MLXSW_REG(ppcnt),
6926         MLXSW_REG(plib),
6927         MLXSW_REG(pptb),
6928         MLXSW_REG(pbmc),
6929         MLXSW_REG(pspa),
6930         MLXSW_REG(htgt),
6931         MLXSW_REG(hpkt),
6932         MLXSW_REG(rgcr),
6933         MLXSW_REG(ritr),
6934         MLXSW_REG(ratr),
6935         MLXSW_REG(rtdp),
6936         MLXSW_REG(ricnt),
6937         MLXSW_REG(ralta),
6938         MLXSW_REG(ralst),
6939         MLXSW_REG(raltb),
6940         MLXSW_REG(ralue),
6941         MLXSW_REG(rauht),
6942         MLXSW_REG(raleu),
6943         MLXSW_REG(rauhtd),
6944         MLXSW_REG(mfcr),
6945         MLXSW_REG(mfsc),
6946         MLXSW_REG(mfsm),
6947         MLXSW_REG(mfsl),
6948         MLXSW_REG(mtcap),
6949         MLXSW_REG(mtmp),
6950         MLXSW_REG(mcia),
6951         MLXSW_REG(mpat),
6952         MLXSW_REG(mpar),
6953         MLXSW_REG(mlcr),
6954         MLXSW_REG(mpsc),
6955         MLXSW_REG(mcqi),
6956         MLXSW_REG(mcc),
6957         MLXSW_REG(mcda),
6958         MLXSW_REG(mgpc),
6959         MLXSW_REG(tigcr),
6960         MLXSW_REG(sbpr),
6961         MLXSW_REG(sbcm),
6962         MLXSW_REG(sbpm),
6963         MLXSW_REG(sbmm),
6964         MLXSW_REG(sbsr),
6965         MLXSW_REG(sbib),
6966 };
6967
6968 static inline const char *mlxsw_reg_id_str(u16 reg_id)
6969 {
6970         const struct mlxsw_reg_info *reg_info;
6971         int i;
6972
6973         for (i = 0; i < ARRAY_SIZE(mlxsw_reg_infos); i++) {
6974                 reg_info = mlxsw_reg_infos[i];
6975                 if (reg_info->id == reg_id)
6976                         return reg_info->name;
6977         }
6978         return "*UNKNOWN*";
6979 }
6980
6981 /* PUDE - Port Up / Down Event
6982  * ---------------------------
6983  * Reports the operational state change of a port.
6984  */
6985 #define MLXSW_REG_PUDE_LEN 0x10
6986
6987 /* reg_pude_swid
6988  * Switch partition ID with which to associate the port.
6989  * Access: Index
6990  */
6991 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
6992
6993 /* reg_pude_local_port
6994  * Local port number.
6995  * Access: Index
6996  */
6997 MLXSW_ITEM32(reg, pude, local_port, 0x00, 16, 8);
6998
6999 /* reg_pude_admin_status
7000  * Port administrative state (the desired state).
7001  * 1 - Up.
7002  * 2 - Down.
7003  * 3 - Up once. This means that in case of link failure, the port won't go
7004  *     into polling mode, but will wait to be re-enabled by software.
7005  * 4 - Disabled by system. Can only be set by hardware.
7006  * Access: RO
7007  */
7008 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
7009
7010 /* reg_pude_oper_status
7011  * Port operatioanl state.
7012  * 1 - Up.
7013  * 2 - Down.
7014  * 3 - Down by port failure. This means that the device will not let the
7015  *     port up again until explicitly specified by software.
7016  * Access: RO
7017  */
7018 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);
7019
7020 #endif