]> git.karo-electronics.de Git - linux-beck.git/blob - drivers/net/ethernet/mellanox/mlxsw/reg.h
Merge tag 'batman-adv-for-davem' of git://git.open-mesh.org/linux-merge
[linux-beck.git] / drivers / net / ethernet / mellanox / mlxsw / reg.h
1 /*
2  * drivers/net/ethernet/mellanox/mlxsw/reg.h
3  * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4  * Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
5  * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
6  * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the names of the copyright holders nor the names of its
17  *    contributors may be used to endorse or promote products derived from
18  *    this software without specific prior written permission.
19  *
20  * Alternatively, this software may be distributed under the terms of the
21  * GNU General Public License ("GPL") version 2 as published by the Free
22  * Software Foundation.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #ifndef _MLXSW_REG_H
38 #define _MLXSW_REG_H
39
40 #include <linux/string.h>
41 #include <linux/bitops.h>
42 #include <linux/if_vlan.h>
43
44 #include "item.h"
45 #include "port.h"
46
47 struct mlxsw_reg_info {
48         u16 id;
49         u16 len; /* In u8 */
50 };
51
52 #define MLXSW_REG(type) (&mlxsw_reg_##type)
53 #define MLXSW_REG_LEN(type) MLXSW_REG(type)->len
54 #define MLXSW_REG_ZERO(type, payload) memset(payload, 0, MLXSW_REG(type)->len)
55
56 /* SGCR - Switch General Configuration Register
57  * --------------------------------------------
58  * This register is used for configuration of the switch capabilities.
59  */
60 #define MLXSW_REG_SGCR_ID 0x2000
61 #define MLXSW_REG_SGCR_LEN 0x10
62
63 static const struct mlxsw_reg_info mlxsw_reg_sgcr = {
64         .id = MLXSW_REG_SGCR_ID,
65         .len = MLXSW_REG_SGCR_LEN,
66 };
67
68 /* reg_sgcr_llb
69  * Link Local Broadcast (Default=0)
70  * When set, all Link Local packets (224.0.0.X) will be treated as broadcast
71  * packets and ignore the IGMP snooping entries.
72  * Access: RW
73  */
74 MLXSW_ITEM32(reg, sgcr, llb, 0x04, 0, 1);
75
76 static inline void mlxsw_reg_sgcr_pack(char *payload, bool llb)
77 {
78         MLXSW_REG_ZERO(sgcr, payload);
79         mlxsw_reg_sgcr_llb_set(payload, !!llb);
80 }
81
82 /* SPAD - Switch Physical Address Register
83  * ---------------------------------------
84  * The SPAD register configures the switch physical MAC address.
85  */
86 #define MLXSW_REG_SPAD_ID 0x2002
87 #define MLXSW_REG_SPAD_LEN 0x10
88
89 static const struct mlxsw_reg_info mlxsw_reg_spad = {
90         .id = MLXSW_REG_SPAD_ID,
91         .len = MLXSW_REG_SPAD_LEN,
92 };
93
94 /* reg_spad_base_mac
95  * Base MAC address for the switch partitions.
96  * Per switch partition MAC address is equal to:
97  * base_mac + swid
98  * Access: RW
99  */
100 MLXSW_ITEM_BUF(reg, spad, base_mac, 0x02, 6);
101
102 /* SSPR - Switch System Port Record Register
103  * -----------------------------------------
104  * Configures the system port to local port mapping.
105  */
106 #define MLXSW_REG_SSPR_ID 0x2008
107 #define MLXSW_REG_SSPR_LEN 0x8
108
109 static const struct mlxsw_reg_info mlxsw_reg_sspr = {
110         .id = MLXSW_REG_SSPR_ID,
111         .len = MLXSW_REG_SSPR_LEN,
112 };
113
114 /* reg_sspr_m
115  * Master - if set, then the record describes the master system port.
116  * This is needed in case a local port is mapped into several system ports
117  * (for multipathing). That number will be reported as the source system
118  * port when packets are forwarded to the CPU. Only one master port is allowed
119  * per local port.
120  *
121  * Note: Must be set for Spectrum.
122  * Access: RW
123  */
124 MLXSW_ITEM32(reg, sspr, m, 0x00, 31, 1);
125
126 /* reg_sspr_local_port
127  * Local port number.
128  *
129  * Access: RW
130  */
131 MLXSW_ITEM32(reg, sspr, local_port, 0x00, 16, 8);
132
133 /* reg_sspr_sub_port
134  * Virtual port within the physical port.
135  * Should be set to 0 when virtual ports are not enabled on the port.
136  *
137  * Access: RW
138  */
139 MLXSW_ITEM32(reg, sspr, sub_port, 0x00, 8, 8);
140
141 /* reg_sspr_system_port
142  * Unique identifier within the stacking domain that represents all the ports
143  * that are available in the system (external ports).
144  *
145  * Currently, only single-ASIC configurations are supported, so we default to
146  * 1:1 mapping between system ports and local ports.
147  * Access: Index
148  */
149 MLXSW_ITEM32(reg, sspr, system_port, 0x04, 0, 16);
150
151 static inline void mlxsw_reg_sspr_pack(char *payload, u8 local_port)
152 {
153         MLXSW_REG_ZERO(sspr, payload);
154         mlxsw_reg_sspr_m_set(payload, 1);
155         mlxsw_reg_sspr_local_port_set(payload, local_port);
156         mlxsw_reg_sspr_sub_port_set(payload, 0);
157         mlxsw_reg_sspr_system_port_set(payload, local_port);
158 }
159
160 /* SFDAT - Switch Filtering Database Aging Time
161  * --------------------------------------------
162  * Controls the Switch aging time. Aging time is able to be set per Switch
163  * Partition.
164  */
165 #define MLXSW_REG_SFDAT_ID 0x2009
166 #define MLXSW_REG_SFDAT_LEN 0x8
167
168 static const struct mlxsw_reg_info mlxsw_reg_sfdat = {
169         .id = MLXSW_REG_SFDAT_ID,
170         .len = MLXSW_REG_SFDAT_LEN,
171 };
172
173 /* reg_sfdat_swid
174  * Switch partition ID.
175  * Access: Index
176  */
177 MLXSW_ITEM32(reg, sfdat, swid, 0x00, 24, 8);
178
179 /* reg_sfdat_age_time
180  * Aging time in seconds
181  * Min - 10 seconds
182  * Max - 1,000,000 seconds
183  * Default is 300 seconds.
184  * Access: RW
185  */
186 MLXSW_ITEM32(reg, sfdat, age_time, 0x04, 0, 20);
187
188 static inline void mlxsw_reg_sfdat_pack(char *payload, u32 age_time)
189 {
190         MLXSW_REG_ZERO(sfdat, payload);
191         mlxsw_reg_sfdat_swid_set(payload, 0);
192         mlxsw_reg_sfdat_age_time_set(payload, age_time);
193 }
194
195 /* SFD - Switch Filtering Database
196  * -------------------------------
197  * The following register defines the access to the filtering database.
198  * The register supports querying, adding, removing and modifying the database.
199  * The access is optimized for bulk updates in which case more than one
200  * FDB record is present in the same command.
201  */
202 #define MLXSW_REG_SFD_ID 0x200A
203 #define MLXSW_REG_SFD_BASE_LEN 0x10 /* base length, without records */
204 #define MLXSW_REG_SFD_REC_LEN 0x10 /* record length */
205 #define MLXSW_REG_SFD_REC_MAX_COUNT 64
206 #define MLXSW_REG_SFD_LEN (MLXSW_REG_SFD_BASE_LEN +     \
207                            MLXSW_REG_SFD_REC_LEN * MLXSW_REG_SFD_REC_MAX_COUNT)
208
209 static const struct mlxsw_reg_info mlxsw_reg_sfd = {
210         .id = MLXSW_REG_SFD_ID,
211         .len = MLXSW_REG_SFD_LEN,
212 };
213
214 /* reg_sfd_swid
215  * Switch partition ID for queries. Reserved on Write.
216  * Access: Index
217  */
218 MLXSW_ITEM32(reg, sfd, swid, 0x00, 24, 8);
219
220 enum mlxsw_reg_sfd_op {
221         /* Dump entire FDB a (process according to record_locator) */
222         MLXSW_REG_SFD_OP_QUERY_DUMP = 0,
223         /* Query records by {MAC, VID/FID} value */
224         MLXSW_REG_SFD_OP_QUERY_QUERY = 1,
225         /* Query and clear activity. Query records by {MAC, VID/FID} value */
226         MLXSW_REG_SFD_OP_QUERY_QUERY_AND_CLEAR_ACTIVITY = 2,
227         /* Test. Response indicates if each of the records could be
228          * added to the FDB.
229          */
230         MLXSW_REG_SFD_OP_WRITE_TEST = 0,
231         /* Add/modify. Aged-out records cannot be added. This command removes
232          * the learning notification of the {MAC, VID/FID}. Response includes
233          * the entries that were added to the FDB.
234          */
235         MLXSW_REG_SFD_OP_WRITE_EDIT = 1,
236         /* Remove record by {MAC, VID/FID}. This command also removes
237          * the learning notification and aged-out notifications
238          * of the {MAC, VID/FID}. The response provides current (pre-removal)
239          * entries as non-aged-out.
240          */
241         MLXSW_REG_SFD_OP_WRITE_REMOVE = 2,
242         /* Remove learned notification by {MAC, VID/FID}. The response provides
243          * the removed learning notification.
244          */
245         MLXSW_REG_SFD_OP_WRITE_REMOVE_NOTIFICATION = 2,
246 };
247
248 /* reg_sfd_op
249  * Operation.
250  * Access: OP
251  */
252 MLXSW_ITEM32(reg, sfd, op, 0x04, 30, 2);
253
254 /* reg_sfd_record_locator
255  * Used for querying the FDB. Use record_locator=0 to initiate the
256  * query. When a record is returned, a new record_locator is
257  * returned to be used in the subsequent query.
258  * Reserved for database update.
259  * Access: Index
260  */
261 MLXSW_ITEM32(reg, sfd, record_locator, 0x04, 0, 30);
262
263 /* reg_sfd_num_rec
264  * Request: Number of records to read/add/modify/remove
265  * Response: Number of records read/added/replaced/removed
266  * See above description for more details.
267  * Ranges 0..64
268  * Access: RW
269  */
270 MLXSW_ITEM32(reg, sfd, num_rec, 0x08, 0, 8);
271
272 static inline void mlxsw_reg_sfd_pack(char *payload, enum mlxsw_reg_sfd_op op,
273                                       u32 record_locator)
274 {
275         MLXSW_REG_ZERO(sfd, payload);
276         mlxsw_reg_sfd_op_set(payload, op);
277         mlxsw_reg_sfd_record_locator_set(payload, record_locator);
278 }
279
280 /* reg_sfd_rec_swid
281  * Switch partition ID.
282  * Access: Index
283  */
284 MLXSW_ITEM32_INDEXED(reg, sfd, rec_swid, MLXSW_REG_SFD_BASE_LEN, 24, 8,
285                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
286
287 enum mlxsw_reg_sfd_rec_type {
288         MLXSW_REG_SFD_REC_TYPE_UNICAST = 0x0,
289         MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG = 0x1,
290 };
291
292 /* reg_sfd_rec_type
293  * FDB record type.
294  * Access: RW
295  */
296 MLXSW_ITEM32_INDEXED(reg, sfd, rec_type, MLXSW_REG_SFD_BASE_LEN, 20, 4,
297                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
298
299 enum mlxsw_reg_sfd_rec_policy {
300         /* Replacement disabled, aging disabled. */
301         MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY = 0,
302         /* (mlag remote): Replacement enabled, aging disabled,
303          * learning notification enabled on this port.
304          */
305         MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_MLAG = 1,
306         /* (ingress device): Replacement enabled, aging enabled. */
307         MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS = 3,
308 };
309
310 /* reg_sfd_rec_policy
311  * Policy.
312  * Access: RW
313  */
314 MLXSW_ITEM32_INDEXED(reg, sfd, rec_policy, MLXSW_REG_SFD_BASE_LEN, 18, 2,
315                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
316
317 /* reg_sfd_rec_a
318  * Activity. Set for new static entries. Set for static entries if a frame SMAC
319  * lookup hits on the entry.
320  * To clear the a bit, use "query and clear activity" op.
321  * Access: RO
322  */
323 MLXSW_ITEM32_INDEXED(reg, sfd, rec_a, MLXSW_REG_SFD_BASE_LEN, 16, 1,
324                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
325
326 /* reg_sfd_rec_mac
327  * MAC address.
328  * Access: Index
329  */
330 MLXSW_ITEM_BUF_INDEXED(reg, sfd, rec_mac, MLXSW_REG_SFD_BASE_LEN, 6,
331                        MLXSW_REG_SFD_REC_LEN, 0x02);
332
333 enum mlxsw_reg_sfd_rec_action {
334         /* forward */
335         MLXSW_REG_SFD_REC_ACTION_NOP = 0,
336         /* forward and trap, trap_id is FDB_TRAP */
337         MLXSW_REG_SFD_REC_ACTION_MIRROR_TO_CPU = 1,
338         /* trap and do not forward, trap_id is FDB_TRAP */
339         MLXSW_REG_SFD_REC_ACTION_TRAP = 3,
340         MLXSW_REG_SFD_REC_ACTION_DISCARD_ERROR = 15,
341 };
342
343 /* reg_sfd_rec_action
344  * Action to apply on the packet.
345  * Note: Dynamic entries can only be configured with NOP action.
346  * Access: RW
347  */
348 MLXSW_ITEM32_INDEXED(reg, sfd, rec_action, MLXSW_REG_SFD_BASE_LEN, 28, 4,
349                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
350
351 /* reg_sfd_uc_sub_port
352  * VEPA channel on local port.
353  * Valid only if local port is a non-stacking port. Must be 0 if multichannel
354  * VEPA is not enabled.
355  * Access: RW
356  */
357 MLXSW_ITEM32_INDEXED(reg, sfd, uc_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
358                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
359
360 /* reg_sfd_uc_fid_vid
361  * Filtering ID or VLAN ID
362  * For SwitchX and SwitchX-2:
363  * - Dynamic entries (policy 2,3) use FID
364  * - Static entries (policy 0) use VID
365  * - When independent learning is configured, VID=FID
366  * For Spectrum: use FID for both Dynamic and Static entries.
367  * VID should not be used.
368  * Access: Index
369  */
370 MLXSW_ITEM32_INDEXED(reg, sfd, uc_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
371                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
372
373 /* reg_sfd_uc_system_port
374  * Unique port identifier for the final destination of the packet.
375  * Access: RW
376  */
377 MLXSW_ITEM32_INDEXED(reg, sfd, uc_system_port, MLXSW_REG_SFD_BASE_LEN, 0, 16,
378                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
379
380 static inline void mlxsw_reg_sfd_rec_pack(char *payload, int rec_index,
381                                           enum mlxsw_reg_sfd_rec_type rec_type,
382                                           enum mlxsw_reg_sfd_rec_policy policy,
383                                           const char *mac,
384                                           enum mlxsw_reg_sfd_rec_action action)
385 {
386         u8 num_rec = mlxsw_reg_sfd_num_rec_get(payload);
387
388         if (rec_index >= num_rec)
389                 mlxsw_reg_sfd_num_rec_set(payload, rec_index + 1);
390         mlxsw_reg_sfd_rec_swid_set(payload, rec_index, 0);
391         mlxsw_reg_sfd_rec_type_set(payload, rec_index, rec_type);
392         mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
393         mlxsw_reg_sfd_rec_mac_memcpy_to(payload, rec_index, mac);
394         mlxsw_reg_sfd_rec_action_set(payload, rec_index, action);
395 }
396
397 static inline void mlxsw_reg_sfd_uc_pack(char *payload, int rec_index,
398                                          enum mlxsw_reg_sfd_rec_policy policy,
399                                          const char *mac, u16 fid_vid,
400                                          enum mlxsw_reg_sfd_rec_action action,
401                                          u8 local_port)
402 {
403         mlxsw_reg_sfd_rec_pack(payload, rec_index,
404                                MLXSW_REG_SFD_REC_TYPE_UNICAST,
405                                policy, mac, action);
406         mlxsw_reg_sfd_uc_sub_port_set(payload, rec_index, 0);
407         mlxsw_reg_sfd_uc_fid_vid_set(payload, rec_index, fid_vid);
408         mlxsw_reg_sfd_uc_system_port_set(payload, rec_index, local_port);
409 }
410
411 static inline void mlxsw_reg_sfd_uc_unpack(char *payload, int rec_index,
412                                            char *mac, u16 *p_fid_vid,
413                                            u8 *p_local_port)
414 {
415         mlxsw_reg_sfd_rec_mac_memcpy_from(payload, rec_index, mac);
416         *p_fid_vid = mlxsw_reg_sfd_uc_fid_vid_get(payload, rec_index);
417         *p_local_port = mlxsw_reg_sfd_uc_system_port_get(payload, rec_index);
418 }
419
420 /* reg_sfd_uc_lag_sub_port
421  * LAG sub port.
422  * Must be 0 if multichannel VEPA is not enabled.
423  * Access: RW
424  */
425 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
426                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
427
428 /* reg_sfd_uc_lag_fid_vid
429  * Filtering ID or VLAN ID
430  * For SwitchX and SwitchX-2:
431  * - Dynamic entries (policy 2,3) use FID
432  * - Static entries (policy 0) use VID
433  * - When independent learning is configured, VID=FID
434  * For Spectrum: use FID for both Dynamic and Static entries.
435  * VID should not be used.
436  * Access: Index
437  */
438 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
439                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
440
441 /* reg_sfd_uc_lag_lag_vid
442  * Indicates VID in case of vFIDs. Reserved for FIDs.
443  * Access: RW
444  */
445 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_lag_vid, MLXSW_REG_SFD_BASE_LEN, 16, 12,
446                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
447
448 /* reg_sfd_uc_lag_lag_id
449  * LAG Identifier - pointer into the LAG descriptor table.
450  * Access: RW
451  */
452 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_lag_id, MLXSW_REG_SFD_BASE_LEN, 0, 10,
453                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
454
455 static inline void
456 mlxsw_reg_sfd_uc_lag_pack(char *payload, int rec_index,
457                           enum mlxsw_reg_sfd_rec_policy policy,
458                           const char *mac, u16 fid_vid,
459                           enum mlxsw_reg_sfd_rec_action action, u16 lag_vid,
460                           u16 lag_id)
461 {
462         mlxsw_reg_sfd_rec_pack(payload, rec_index,
463                                MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG,
464                                policy, mac, action);
465         mlxsw_reg_sfd_uc_lag_sub_port_set(payload, rec_index, 0);
466         mlxsw_reg_sfd_uc_lag_fid_vid_set(payload, rec_index, fid_vid);
467         mlxsw_reg_sfd_uc_lag_lag_vid_set(payload, rec_index, lag_vid);
468         mlxsw_reg_sfd_uc_lag_lag_id_set(payload, rec_index, lag_id);
469 }
470
471 static inline void mlxsw_reg_sfd_uc_lag_unpack(char *payload, int rec_index,
472                                                char *mac, u16 *p_vid,
473                                                u16 *p_lag_id)
474 {
475         mlxsw_reg_sfd_rec_mac_memcpy_from(payload, rec_index, mac);
476         *p_vid = mlxsw_reg_sfd_uc_lag_fid_vid_get(payload, rec_index);
477         *p_lag_id = mlxsw_reg_sfd_uc_lag_lag_id_get(payload, rec_index);
478 }
479
480 /* SFN - Switch FDB Notification Register
481  * -------------------------------------------
482  * The switch provides notifications on newly learned FDB entries and
483  * aged out entries. The notifications can be polled by software.
484  */
485 #define MLXSW_REG_SFN_ID 0x200B
486 #define MLXSW_REG_SFN_BASE_LEN 0x10 /* base length, without records */
487 #define MLXSW_REG_SFN_REC_LEN 0x10 /* record length */
488 #define MLXSW_REG_SFN_REC_MAX_COUNT 64
489 #define MLXSW_REG_SFN_LEN (MLXSW_REG_SFN_BASE_LEN +     \
490                            MLXSW_REG_SFN_REC_LEN * MLXSW_REG_SFN_REC_MAX_COUNT)
491
492 static const struct mlxsw_reg_info mlxsw_reg_sfn = {
493         .id = MLXSW_REG_SFN_ID,
494         .len = MLXSW_REG_SFN_LEN,
495 };
496
497 /* reg_sfn_swid
498  * Switch partition ID.
499  * Access: Index
500  */
501 MLXSW_ITEM32(reg, sfn, swid, 0x00, 24, 8);
502
503 /* reg_sfn_num_rec
504  * Request: Number of learned notifications and aged-out notification
505  * records requested.
506  * Response: Number of notification records returned (must be smaller
507  * than or equal to the value requested)
508  * Ranges 0..64
509  * Access: OP
510  */
511 MLXSW_ITEM32(reg, sfn, num_rec, 0x04, 0, 8);
512
513 static inline void mlxsw_reg_sfn_pack(char *payload)
514 {
515         MLXSW_REG_ZERO(sfn, payload);
516         mlxsw_reg_sfn_swid_set(payload, 0);
517         mlxsw_reg_sfn_num_rec_set(payload, MLXSW_REG_SFN_REC_MAX_COUNT);
518 }
519
520 /* reg_sfn_rec_swid
521  * Switch partition ID.
522  * Access: RO
523  */
524 MLXSW_ITEM32_INDEXED(reg, sfn, rec_swid, MLXSW_REG_SFN_BASE_LEN, 24, 8,
525                      MLXSW_REG_SFN_REC_LEN, 0x00, false);
526
527 enum mlxsw_reg_sfn_rec_type {
528         /* MAC addresses learned on a regular port. */
529         MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC = 0x5,
530         /* MAC addresses learned on a LAG port. */
531         MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG = 0x6,
532         /* Aged-out MAC address on a regular port. */
533         MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC = 0x7,
534         /* Aged-out MAC address on a LAG port. */
535         MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG = 0x8,
536 };
537
538 /* reg_sfn_rec_type
539  * Notification record type.
540  * Access: RO
541  */
542 MLXSW_ITEM32_INDEXED(reg, sfn, rec_type, MLXSW_REG_SFN_BASE_LEN, 20, 4,
543                      MLXSW_REG_SFN_REC_LEN, 0x00, false);
544
545 /* reg_sfn_rec_mac
546  * MAC address.
547  * Access: RO
548  */
549 MLXSW_ITEM_BUF_INDEXED(reg, sfn, rec_mac, MLXSW_REG_SFN_BASE_LEN, 6,
550                        MLXSW_REG_SFN_REC_LEN, 0x02);
551
552 /* reg_sfn_mac_sub_port
553  * VEPA channel on the local port.
554  * 0 if multichannel VEPA is not enabled.
555  * Access: RO
556  */
557 MLXSW_ITEM32_INDEXED(reg, sfn, mac_sub_port, MLXSW_REG_SFN_BASE_LEN, 16, 8,
558                      MLXSW_REG_SFN_REC_LEN, 0x08, false);
559
560 /* reg_sfn_mac_fid
561  * Filtering identifier.
562  * Access: RO
563  */
564 MLXSW_ITEM32_INDEXED(reg, sfn, mac_fid, MLXSW_REG_SFN_BASE_LEN, 0, 16,
565                      MLXSW_REG_SFN_REC_LEN, 0x08, false);
566
567 /* reg_sfn_mac_system_port
568  * Unique port identifier for the final destination of the packet.
569  * Access: RO
570  */
571 MLXSW_ITEM32_INDEXED(reg, sfn, mac_system_port, MLXSW_REG_SFN_BASE_LEN, 0, 16,
572                      MLXSW_REG_SFN_REC_LEN, 0x0C, false);
573
574 static inline void mlxsw_reg_sfn_mac_unpack(char *payload, int rec_index,
575                                             char *mac, u16 *p_vid,
576                                             u8 *p_local_port)
577 {
578         mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
579         *p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
580         *p_local_port = mlxsw_reg_sfn_mac_system_port_get(payload, rec_index);
581 }
582
583 /* reg_sfn_mac_lag_lag_id
584  * LAG ID (pointer into the LAG descriptor table).
585  * Access: RO
586  */
587 MLXSW_ITEM32_INDEXED(reg, sfn, mac_lag_lag_id, MLXSW_REG_SFN_BASE_LEN, 0, 10,
588                      MLXSW_REG_SFN_REC_LEN, 0x0C, false);
589
590 static inline void mlxsw_reg_sfn_mac_lag_unpack(char *payload, int rec_index,
591                                                 char *mac, u16 *p_vid,
592                                                 u16 *p_lag_id)
593 {
594         mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
595         *p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
596         *p_lag_id = mlxsw_reg_sfn_mac_lag_lag_id_get(payload, rec_index);
597 }
598
599 /* SPMS - Switch Port MSTP/RSTP State Register
600  * -------------------------------------------
601  * Configures the spanning tree state of a physical port.
602  */
603 #define MLXSW_REG_SPMS_ID 0x200D
604 #define MLXSW_REG_SPMS_LEN 0x404
605
606 static const struct mlxsw_reg_info mlxsw_reg_spms = {
607         .id = MLXSW_REG_SPMS_ID,
608         .len = MLXSW_REG_SPMS_LEN,
609 };
610
611 /* reg_spms_local_port
612  * Local port number.
613  * Access: Index
614  */
615 MLXSW_ITEM32(reg, spms, local_port, 0x00, 16, 8);
616
617 enum mlxsw_reg_spms_state {
618         MLXSW_REG_SPMS_STATE_NO_CHANGE,
619         MLXSW_REG_SPMS_STATE_DISCARDING,
620         MLXSW_REG_SPMS_STATE_LEARNING,
621         MLXSW_REG_SPMS_STATE_FORWARDING,
622 };
623
624 /* reg_spms_state
625  * Spanning tree state of each VLAN ID (VID) of the local port.
626  * 0 - Do not change spanning tree state (used only when writing).
627  * 1 - Discarding. No learning or forwarding to/from this port (default).
628  * 2 - Learning. Port is learning, but not forwarding.
629  * 3 - Forwarding. Port is learning and forwarding.
630  * Access: RW
631  */
632 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
633
634 static inline void mlxsw_reg_spms_pack(char *payload, u8 local_port)
635 {
636         MLXSW_REG_ZERO(spms, payload);
637         mlxsw_reg_spms_local_port_set(payload, local_port);
638 }
639
640 static inline void mlxsw_reg_spms_vid_pack(char *payload, u16 vid,
641                                            enum mlxsw_reg_spms_state state)
642 {
643         mlxsw_reg_spms_state_set(payload, vid, state);
644 }
645
646 /* SPVID - Switch Port VID
647  * -----------------------
648  * The switch port VID configures the default VID for a port.
649  */
650 #define MLXSW_REG_SPVID_ID 0x200E
651 #define MLXSW_REG_SPVID_LEN 0x08
652
653 static const struct mlxsw_reg_info mlxsw_reg_spvid = {
654         .id = MLXSW_REG_SPVID_ID,
655         .len = MLXSW_REG_SPVID_LEN,
656 };
657
658 /* reg_spvid_local_port
659  * Local port number.
660  * Access: Index
661  */
662 MLXSW_ITEM32(reg, spvid, local_port, 0x00, 16, 8);
663
664 /* reg_spvid_sub_port
665  * Virtual port within the physical port.
666  * Should be set to 0 when virtual ports are not enabled on the port.
667  * Access: Index
668  */
669 MLXSW_ITEM32(reg, spvid, sub_port, 0x00, 8, 8);
670
671 /* reg_spvid_pvid
672  * Port default VID
673  * Access: RW
674  */
675 MLXSW_ITEM32(reg, spvid, pvid, 0x04, 0, 12);
676
677 static inline void mlxsw_reg_spvid_pack(char *payload, u8 local_port, u16 pvid)
678 {
679         MLXSW_REG_ZERO(spvid, payload);
680         mlxsw_reg_spvid_local_port_set(payload, local_port);
681         mlxsw_reg_spvid_pvid_set(payload, pvid);
682 }
683
684 /* SPVM - Switch Port VLAN Membership
685  * ----------------------------------
686  * The Switch Port VLAN Membership register configures the VLAN membership
687  * of a port in a VLAN denoted by VID. VLAN membership is managed per
688  * virtual port. The register can be used to add and remove VID(s) from a port.
689  */
690 #define MLXSW_REG_SPVM_ID 0x200F
691 #define MLXSW_REG_SPVM_BASE_LEN 0x04 /* base length, without records */
692 #define MLXSW_REG_SPVM_REC_LEN 0x04 /* record length */
693 #define MLXSW_REG_SPVM_REC_MAX_COUNT 256
694 #define MLXSW_REG_SPVM_LEN (MLXSW_REG_SPVM_BASE_LEN +   \
695                     MLXSW_REG_SPVM_REC_LEN * MLXSW_REG_SPVM_REC_MAX_COUNT)
696
697 static const struct mlxsw_reg_info mlxsw_reg_spvm = {
698         .id = MLXSW_REG_SPVM_ID,
699         .len = MLXSW_REG_SPVM_LEN,
700 };
701
702 /* reg_spvm_pt
703  * Priority tagged. If this bit is set, packets forwarded to the port with
704  * untagged VLAN membership (u bit is set) will be tagged with priority tag
705  * (VID=0)
706  * Access: RW
707  */
708 MLXSW_ITEM32(reg, spvm, pt, 0x00, 31, 1);
709
710 /* reg_spvm_pte
711  * Priority Tagged Update Enable. On Write operations, if this bit is cleared,
712  * the pt bit will NOT be updated. To update the pt bit, pte must be set.
713  * Access: WO
714  */
715 MLXSW_ITEM32(reg, spvm, pte, 0x00, 30, 1);
716
717 /* reg_spvm_local_port
718  * Local port number.
719  * Access: Index
720  */
721 MLXSW_ITEM32(reg, spvm, local_port, 0x00, 16, 8);
722
723 /* reg_spvm_sub_port
724  * Virtual port within the physical port.
725  * Should be set to 0 when virtual ports are not enabled on the port.
726  * Access: Index
727  */
728 MLXSW_ITEM32(reg, spvm, sub_port, 0x00, 8, 8);
729
730 /* reg_spvm_num_rec
731  * Number of records to update. Each record contains: i, e, u, vid.
732  * Access: OP
733  */
734 MLXSW_ITEM32(reg, spvm, num_rec, 0x00, 0, 8);
735
736 /* reg_spvm_rec_i
737  * Ingress membership in VLAN ID.
738  * Access: Index
739  */
740 MLXSW_ITEM32_INDEXED(reg, spvm, rec_i,
741                      MLXSW_REG_SPVM_BASE_LEN, 14, 1,
742                      MLXSW_REG_SPVM_REC_LEN, 0, false);
743
744 /* reg_spvm_rec_e
745  * Egress membership in VLAN ID.
746  * Access: Index
747  */
748 MLXSW_ITEM32_INDEXED(reg, spvm, rec_e,
749                      MLXSW_REG_SPVM_BASE_LEN, 13, 1,
750                      MLXSW_REG_SPVM_REC_LEN, 0, false);
751
752 /* reg_spvm_rec_u
753  * Untagged - port is an untagged member - egress transmission uses untagged
754  * frames on VID<n>
755  * Access: Index
756  */
757 MLXSW_ITEM32_INDEXED(reg, spvm, rec_u,
758                      MLXSW_REG_SPVM_BASE_LEN, 12, 1,
759                      MLXSW_REG_SPVM_REC_LEN, 0, false);
760
761 /* reg_spvm_rec_vid
762  * Egress membership in VLAN ID.
763  * Access: Index
764  */
765 MLXSW_ITEM32_INDEXED(reg, spvm, rec_vid,
766                      MLXSW_REG_SPVM_BASE_LEN, 0, 12,
767                      MLXSW_REG_SPVM_REC_LEN, 0, false);
768
769 static inline void mlxsw_reg_spvm_pack(char *payload, u8 local_port,
770                                        u16 vid_begin, u16 vid_end,
771                                        bool is_member, bool untagged)
772 {
773         int size = vid_end - vid_begin + 1;
774         int i;
775
776         MLXSW_REG_ZERO(spvm, payload);
777         mlxsw_reg_spvm_local_port_set(payload, local_port);
778         mlxsw_reg_spvm_num_rec_set(payload, size);
779
780         for (i = 0; i < size; i++) {
781                 mlxsw_reg_spvm_rec_i_set(payload, i, is_member);
782                 mlxsw_reg_spvm_rec_e_set(payload, i, is_member);
783                 mlxsw_reg_spvm_rec_u_set(payload, i, untagged);
784                 mlxsw_reg_spvm_rec_vid_set(payload, i, vid_begin + i);
785         }
786 }
787
788 /* SFGC - Switch Flooding Group Configuration
789  * ------------------------------------------
790  * The following register controls the association of flooding tables and MIDs
791  * to packet types used for flooding.
792  */
793 #define MLXSW_REG_SFGC_ID 0x2011
794 #define MLXSW_REG_SFGC_LEN 0x10
795
796 static const struct mlxsw_reg_info mlxsw_reg_sfgc = {
797         .id = MLXSW_REG_SFGC_ID,
798         .len = MLXSW_REG_SFGC_LEN,
799 };
800
801 enum mlxsw_reg_sfgc_type {
802         MLXSW_REG_SFGC_TYPE_BROADCAST,
803         MLXSW_REG_SFGC_TYPE_UNKNOWN_UNICAST,
804         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4,
805         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6,
806         MLXSW_REG_SFGC_TYPE_RESERVED,
807         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP,
808         MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL,
809         MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST,
810         MLXSW_REG_SFGC_TYPE_MAX,
811 };
812
813 /* reg_sfgc_type
814  * The traffic type to reach the flooding table.
815  * Access: Index
816  */
817 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
818
819 enum mlxsw_reg_sfgc_bridge_type {
820         MLXSW_REG_SFGC_BRIDGE_TYPE_1Q_FID = 0,
821         MLXSW_REG_SFGC_BRIDGE_TYPE_VFID = 1,
822 };
823
824 /* reg_sfgc_bridge_type
825  * Access: Index
826  *
827  * Note: SwitchX-2 only supports 802.1Q mode.
828  */
829 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
830
831 enum mlxsw_flood_table_type {
832         MLXSW_REG_SFGC_TABLE_TYPE_VID = 1,
833         MLXSW_REG_SFGC_TABLE_TYPE_SINGLE = 2,
834         MLXSW_REG_SFGC_TABLE_TYPE_ANY = 0,
835         MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFEST = 3,
836         MLXSW_REG_SFGC_TABLE_TYPE_FID = 4,
837 };
838
839 /* reg_sfgc_table_type
840  * See mlxsw_flood_table_type
841  * Access: RW
842  *
843  * Note: FID offset and FID types are not supported in SwitchX-2.
844  */
845 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
846
847 /* reg_sfgc_flood_table
848  * Flooding table index to associate with the specific type on the specific
849  * switch partition.
850  * Access: RW
851  */
852 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
853
854 /* reg_sfgc_mid
855  * The multicast ID for the swid. Not supported for Spectrum
856  * Access: RW
857  */
858 MLXSW_ITEM32(reg, sfgc, mid, 0x08, 0, 16);
859
860 /* reg_sfgc_counter_set_type
861  * Counter Set Type for flow counters.
862  * Access: RW
863  */
864 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
865
866 /* reg_sfgc_counter_index
867  * Counter Index for flow counters.
868  * Access: RW
869  */
870 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
871
872 static inline void
873 mlxsw_reg_sfgc_pack(char *payload, enum mlxsw_reg_sfgc_type type,
874                     enum mlxsw_reg_sfgc_bridge_type bridge_type,
875                     enum mlxsw_flood_table_type table_type,
876                     unsigned int flood_table)
877 {
878         MLXSW_REG_ZERO(sfgc, payload);
879         mlxsw_reg_sfgc_type_set(payload, type);
880         mlxsw_reg_sfgc_bridge_type_set(payload, bridge_type);
881         mlxsw_reg_sfgc_table_type_set(payload, table_type);
882         mlxsw_reg_sfgc_flood_table_set(payload, flood_table);
883         mlxsw_reg_sfgc_mid_set(payload, MLXSW_PORT_MID);
884 }
885
886 /* SFTR - Switch Flooding Table Register
887  * -------------------------------------
888  * The switch flooding table is used for flooding packet replication. The table
889  * defines a bit mask of ports for packet replication.
890  */
891 #define MLXSW_REG_SFTR_ID 0x2012
892 #define MLXSW_REG_SFTR_LEN 0x420
893
894 static const struct mlxsw_reg_info mlxsw_reg_sftr = {
895         .id = MLXSW_REG_SFTR_ID,
896         .len = MLXSW_REG_SFTR_LEN,
897 };
898
899 /* reg_sftr_swid
900  * Switch partition ID with which to associate the port.
901  * Access: Index
902  */
903 MLXSW_ITEM32(reg, sftr, swid, 0x00, 24, 8);
904
905 /* reg_sftr_flood_table
906  * Flooding table index to associate with the specific type on the specific
907  * switch partition.
908  * Access: Index
909  */
910 MLXSW_ITEM32(reg, sftr, flood_table, 0x00, 16, 6);
911
912 /* reg_sftr_index
913  * Index. Used as an index into the Flooding Table in case the table is
914  * configured to use VID / FID or FID Offset.
915  * Access: Index
916  */
917 MLXSW_ITEM32(reg, sftr, index, 0x00, 0, 16);
918
919 /* reg_sftr_table_type
920  * See mlxsw_flood_table_type
921  * Access: RW
922  */
923 MLXSW_ITEM32(reg, sftr, table_type, 0x04, 16, 3);
924
925 /* reg_sftr_range
926  * Range of entries to update
927  * Access: Index
928  */
929 MLXSW_ITEM32(reg, sftr, range, 0x04, 0, 16);
930
931 /* reg_sftr_port
932  * Local port membership (1 bit per port).
933  * Access: RW
934  */
935 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port, 0x20, 0x20, 1);
936
937 /* reg_sftr_cpu_port_mask
938  * CPU port mask (1 bit per port).
939  * Access: W
940  */
941 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port_mask, 0x220, 0x20, 1);
942
943 static inline void mlxsw_reg_sftr_pack(char *payload,
944                                        unsigned int flood_table,
945                                        unsigned int index,
946                                        enum mlxsw_flood_table_type table_type,
947                                        unsigned int range, u8 port, bool set)
948 {
949         MLXSW_REG_ZERO(sftr, payload);
950         mlxsw_reg_sftr_swid_set(payload, 0);
951         mlxsw_reg_sftr_flood_table_set(payload, flood_table);
952         mlxsw_reg_sftr_index_set(payload, index);
953         mlxsw_reg_sftr_table_type_set(payload, table_type);
954         mlxsw_reg_sftr_range_set(payload, range);
955         mlxsw_reg_sftr_port_set(payload, port, set);
956         mlxsw_reg_sftr_port_mask_set(payload, port, 1);
957 }
958
959 /* SLDR - Switch LAG Descriptor Register
960  * -----------------------------------------
961  * The switch LAG descriptor register is populated by LAG descriptors.
962  * Each LAG descriptor is indexed by lag_id. The LAG ID runs from 0 to
963  * max_lag-1.
964  */
965 #define MLXSW_REG_SLDR_ID 0x2014
966 #define MLXSW_REG_SLDR_LEN 0x0C /* counting in only one port in list */
967
968 static const struct mlxsw_reg_info mlxsw_reg_sldr = {
969         .id = MLXSW_REG_SLDR_ID,
970         .len = MLXSW_REG_SLDR_LEN,
971 };
972
973 enum mlxsw_reg_sldr_op {
974         /* Indicates a creation of a new LAG-ID, lag_id must be valid */
975         MLXSW_REG_SLDR_OP_LAG_CREATE,
976         MLXSW_REG_SLDR_OP_LAG_DESTROY,
977         /* Ports that appear in the list have the Distributor enabled */
978         MLXSW_REG_SLDR_OP_LAG_ADD_PORT_LIST,
979         /* Removes ports from the disributor list */
980         MLXSW_REG_SLDR_OP_LAG_REMOVE_PORT_LIST,
981 };
982
983 /* reg_sldr_op
984  * Operation.
985  * Access: RW
986  */
987 MLXSW_ITEM32(reg, sldr, op, 0x00, 29, 3);
988
989 /* reg_sldr_lag_id
990  * LAG identifier. The lag_id is the index into the LAG descriptor table.
991  * Access: Index
992  */
993 MLXSW_ITEM32(reg, sldr, lag_id, 0x00, 0, 10);
994
995 static inline void mlxsw_reg_sldr_lag_create_pack(char *payload, u8 lag_id)
996 {
997         MLXSW_REG_ZERO(sldr, payload);
998         mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_CREATE);
999         mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1000 }
1001
1002 static inline void mlxsw_reg_sldr_lag_destroy_pack(char *payload, u8 lag_id)
1003 {
1004         MLXSW_REG_ZERO(sldr, payload);
1005         mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_DESTROY);
1006         mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1007 }
1008
1009 /* reg_sldr_num_ports
1010  * The number of member ports of the LAG.
1011  * Reserved for Create / Destroy operations
1012  * For Add / Remove operations - indicates the number of ports in the list.
1013  * Access: RW
1014  */
1015 MLXSW_ITEM32(reg, sldr, num_ports, 0x04, 24, 8);
1016
1017 /* reg_sldr_system_port
1018  * System port.
1019  * Access: RW
1020  */
1021 MLXSW_ITEM32_INDEXED(reg, sldr, system_port, 0x08, 0, 16, 4, 0, false);
1022
1023 static inline void mlxsw_reg_sldr_lag_add_port_pack(char *payload, u8 lag_id,
1024                                                     u8 local_port)
1025 {
1026         MLXSW_REG_ZERO(sldr, payload);
1027         mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_ADD_PORT_LIST);
1028         mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1029         mlxsw_reg_sldr_num_ports_set(payload, 1);
1030         mlxsw_reg_sldr_system_port_set(payload, 0, local_port);
1031 }
1032
1033 static inline void mlxsw_reg_sldr_lag_remove_port_pack(char *payload, u8 lag_id,
1034                                                        u8 local_port)
1035 {
1036         MLXSW_REG_ZERO(sldr, payload);
1037         mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_REMOVE_PORT_LIST);
1038         mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1039         mlxsw_reg_sldr_num_ports_set(payload, 1);
1040         mlxsw_reg_sldr_system_port_set(payload, 0, local_port);
1041 }
1042
1043 /* SLCR - Switch LAG Configuration 2 Register
1044  * -------------------------------------------
1045  * The Switch LAG Configuration register is used for configuring the
1046  * LAG properties of the switch.
1047  */
1048 #define MLXSW_REG_SLCR_ID 0x2015
1049 #define MLXSW_REG_SLCR_LEN 0x10
1050
1051 static const struct mlxsw_reg_info mlxsw_reg_slcr = {
1052         .id = MLXSW_REG_SLCR_ID,
1053         .len = MLXSW_REG_SLCR_LEN,
1054 };
1055
1056 enum mlxsw_reg_slcr_pp {
1057         /* Global Configuration (for all ports) */
1058         MLXSW_REG_SLCR_PP_GLOBAL,
1059         /* Per port configuration, based on local_port field */
1060         MLXSW_REG_SLCR_PP_PER_PORT,
1061 };
1062
1063 /* reg_slcr_pp
1064  * Per Port Configuration
1065  * Note: Reading at Global mode results in reading port 1 configuration.
1066  * Access: Index
1067  */
1068 MLXSW_ITEM32(reg, slcr, pp, 0x00, 24, 1);
1069
1070 /* reg_slcr_local_port
1071  * Local port number
1072  * Supported from CPU port
1073  * Not supported from router port
1074  * Reserved when pp = Global Configuration
1075  * Access: Index
1076  */
1077 MLXSW_ITEM32(reg, slcr, local_port, 0x00, 16, 8);
1078
1079 enum mlxsw_reg_slcr_type {
1080         MLXSW_REG_SLCR_TYPE_CRC, /* default */
1081         MLXSW_REG_SLCR_TYPE_XOR,
1082         MLXSW_REG_SLCR_TYPE_RANDOM,
1083 };
1084
1085 /* reg_slcr_type
1086  * Hash type
1087  * Access: RW
1088  */
1089 MLXSW_ITEM32(reg, slcr, type, 0x00, 0, 4);
1090
1091 /* Ingress port */
1092 #define MLXSW_REG_SLCR_LAG_HASH_IN_PORT         BIT(0)
1093 /* SMAC - for IPv4 and IPv6 packets */
1094 #define MLXSW_REG_SLCR_LAG_HASH_SMAC_IP         BIT(1)
1095 /* SMAC - for non-IP packets */
1096 #define MLXSW_REG_SLCR_LAG_HASH_SMAC_NONIP      BIT(2)
1097 #define MLXSW_REG_SLCR_LAG_HASH_SMAC \
1098         (MLXSW_REG_SLCR_LAG_HASH_SMAC_IP | \
1099          MLXSW_REG_SLCR_LAG_HASH_SMAC_NONIP)
1100 /* DMAC - for IPv4 and IPv6 packets */
1101 #define MLXSW_REG_SLCR_LAG_HASH_DMAC_IP         BIT(3)
1102 /* DMAC - for non-IP packets */
1103 #define MLXSW_REG_SLCR_LAG_HASH_DMAC_NONIP      BIT(4)
1104 #define MLXSW_REG_SLCR_LAG_HASH_DMAC \
1105         (MLXSW_REG_SLCR_LAG_HASH_DMAC_IP | \
1106          MLXSW_REG_SLCR_LAG_HASH_DMAC_NONIP)
1107 /* Ethertype - for IPv4 and IPv6 packets */
1108 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_IP    BIT(5)
1109 /* Ethertype - for non-IP packets */
1110 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_NONIP BIT(6)
1111 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE \
1112         (MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_IP | \
1113          MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_NONIP)
1114 /* VLAN ID - for IPv4 and IPv6 packets */
1115 #define MLXSW_REG_SLCR_LAG_HASH_VLANID_IP       BIT(7)
1116 /* VLAN ID - for non-IP packets */
1117 #define MLXSW_REG_SLCR_LAG_HASH_VLANID_NONIP    BIT(8)
1118 #define MLXSW_REG_SLCR_LAG_HASH_VLANID \
1119         (MLXSW_REG_SLCR_LAG_HASH_VLANID_IP | \
1120          MLXSW_REG_SLCR_LAG_HASH_VLANID_NONIP)
1121 /* Source IP address (can be IPv4 or IPv6) */
1122 #define MLXSW_REG_SLCR_LAG_HASH_SIP             BIT(9)
1123 /* Destination IP address (can be IPv4 or IPv6) */
1124 #define MLXSW_REG_SLCR_LAG_HASH_DIP             BIT(10)
1125 /* TCP/UDP source port */
1126 #define MLXSW_REG_SLCR_LAG_HASH_SPORT           BIT(11)
1127 /* TCP/UDP destination port*/
1128 #define MLXSW_REG_SLCR_LAG_HASH_DPORT           BIT(12)
1129 /* IPv4 Protocol/IPv6 Next Header */
1130 #define MLXSW_REG_SLCR_LAG_HASH_IPPROTO         BIT(13)
1131 /* IPv6 Flow label */
1132 #define MLXSW_REG_SLCR_LAG_HASH_FLOWLABEL       BIT(14)
1133 /* SID - FCoE source ID */
1134 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_SID        BIT(15)
1135 /* DID - FCoE destination ID */
1136 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_DID        BIT(16)
1137 /* OXID - FCoE originator exchange ID */
1138 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_OXID       BIT(17)
1139 /* Destination QP number - for RoCE packets */
1140 #define MLXSW_REG_SLCR_LAG_HASH_ROCE_DQP        BIT(19)
1141
1142 /* reg_slcr_lag_hash
1143  * LAG hashing configuration. This is a bitmask, in which each set
1144  * bit includes the corresponding item in the LAG hash calculation.
1145  * The default lag_hash contains SMAC, DMAC, VLANID and
1146  * Ethertype (for all packet types).
1147  * Access: RW
1148  */
1149 MLXSW_ITEM32(reg, slcr, lag_hash, 0x04, 0, 20);
1150
1151 static inline void mlxsw_reg_slcr_pack(char *payload, u16 lag_hash)
1152 {
1153         MLXSW_REG_ZERO(slcr, payload);
1154         mlxsw_reg_slcr_pp_set(payload, MLXSW_REG_SLCR_PP_GLOBAL);
1155         mlxsw_reg_slcr_type_set(payload, MLXSW_REG_SLCR_TYPE_XOR);
1156         mlxsw_reg_slcr_lag_hash_set(payload, lag_hash);
1157 }
1158
1159 /* SLCOR - Switch LAG Collector Register
1160  * -------------------------------------
1161  * The Switch LAG Collector register controls the Local Port membership
1162  * in a LAG and enablement of the collector.
1163  */
1164 #define MLXSW_REG_SLCOR_ID 0x2016
1165 #define MLXSW_REG_SLCOR_LEN 0x10
1166
1167 static const struct mlxsw_reg_info mlxsw_reg_slcor = {
1168         .id = MLXSW_REG_SLCOR_ID,
1169         .len = MLXSW_REG_SLCOR_LEN,
1170 };
1171
1172 enum mlxsw_reg_slcor_col {
1173         /* Port is added with collector disabled */
1174         MLXSW_REG_SLCOR_COL_LAG_ADD_PORT,
1175         MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED,
1176         MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_DISABLED,
1177         MLXSW_REG_SLCOR_COL_LAG_REMOVE_PORT,
1178 };
1179
1180 /* reg_slcor_col
1181  * Collector configuration
1182  * Access: RW
1183  */
1184 MLXSW_ITEM32(reg, slcor, col, 0x00, 30, 2);
1185
1186 /* reg_slcor_local_port
1187  * Local port number
1188  * Not supported for CPU port
1189  * Access: Index
1190  */
1191 MLXSW_ITEM32(reg, slcor, local_port, 0x00, 16, 8);
1192
1193 /* reg_slcor_lag_id
1194  * LAG Identifier. Index into the LAG descriptor table.
1195  * Access: Index
1196  */
1197 MLXSW_ITEM32(reg, slcor, lag_id, 0x00, 0, 10);
1198
1199 /* reg_slcor_port_index
1200  * Port index in the LAG list. Only valid on Add Port to LAG col.
1201  * Valid range is from 0 to cap_max_lag_members-1
1202  * Access: RW
1203  */
1204 MLXSW_ITEM32(reg, slcor, port_index, 0x04, 0, 10);
1205
1206 static inline void mlxsw_reg_slcor_pack(char *payload,
1207                                         u8 local_port, u16 lag_id,
1208                                         enum mlxsw_reg_slcor_col col)
1209 {
1210         MLXSW_REG_ZERO(slcor, payload);
1211         mlxsw_reg_slcor_col_set(payload, col);
1212         mlxsw_reg_slcor_local_port_set(payload, local_port);
1213         mlxsw_reg_slcor_lag_id_set(payload, lag_id);
1214 }
1215
1216 static inline void mlxsw_reg_slcor_port_add_pack(char *payload,
1217                                                  u8 local_port, u16 lag_id,
1218                                                  u8 port_index)
1219 {
1220         mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1221                              MLXSW_REG_SLCOR_COL_LAG_ADD_PORT);
1222         mlxsw_reg_slcor_port_index_set(payload, port_index);
1223 }
1224
1225 static inline void mlxsw_reg_slcor_port_remove_pack(char *payload,
1226                                                     u8 local_port, u16 lag_id)
1227 {
1228         mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1229                              MLXSW_REG_SLCOR_COL_LAG_REMOVE_PORT);
1230 }
1231
1232 static inline void mlxsw_reg_slcor_col_enable_pack(char *payload,
1233                                                    u8 local_port, u16 lag_id)
1234 {
1235         mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1236                              MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED);
1237 }
1238
1239 static inline void mlxsw_reg_slcor_col_disable_pack(char *payload,
1240                                                     u8 local_port, u16 lag_id)
1241 {
1242         mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1243                              MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED);
1244 }
1245
1246 /* SPMLR - Switch Port MAC Learning Register
1247  * -----------------------------------------
1248  * Controls the Switch MAC learning policy per port.
1249  */
1250 #define MLXSW_REG_SPMLR_ID 0x2018
1251 #define MLXSW_REG_SPMLR_LEN 0x8
1252
1253 static const struct mlxsw_reg_info mlxsw_reg_spmlr = {
1254         .id = MLXSW_REG_SPMLR_ID,
1255         .len = MLXSW_REG_SPMLR_LEN,
1256 };
1257
1258 /* reg_spmlr_local_port
1259  * Local port number.
1260  * Access: Index
1261  */
1262 MLXSW_ITEM32(reg, spmlr, local_port, 0x00, 16, 8);
1263
1264 /* reg_spmlr_sub_port
1265  * Virtual port within the physical port.
1266  * Should be set to 0 when virtual ports are not enabled on the port.
1267  * Access: Index
1268  */
1269 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
1270
1271 enum mlxsw_reg_spmlr_learn_mode {
1272         MLXSW_REG_SPMLR_LEARN_MODE_DISABLE = 0,
1273         MLXSW_REG_SPMLR_LEARN_MODE_ENABLE = 2,
1274         MLXSW_REG_SPMLR_LEARN_MODE_SEC = 3,
1275 };
1276
1277 /* reg_spmlr_learn_mode
1278  * Learning mode on the port.
1279  * 0 - Learning disabled.
1280  * 2 - Learning enabled.
1281  * 3 - Security mode.
1282  *
1283  * In security mode the switch does not learn MACs on the port, but uses the
1284  * SMAC to see if it exists on another ingress port. If so, the packet is
1285  * classified as a bad packet and is discarded unless the software registers
1286  * to receive port security error packets usign HPKT.
1287  */
1288 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
1289
1290 static inline void mlxsw_reg_spmlr_pack(char *payload, u8 local_port,
1291                                         enum mlxsw_reg_spmlr_learn_mode mode)
1292 {
1293         MLXSW_REG_ZERO(spmlr, payload);
1294         mlxsw_reg_spmlr_local_port_set(payload, local_port);
1295         mlxsw_reg_spmlr_sub_port_set(payload, 0);
1296         mlxsw_reg_spmlr_learn_mode_set(payload, mode);
1297 }
1298
1299 /* SVFA - Switch VID to FID Allocation Register
1300  * --------------------------------------------
1301  * Controls the VID to FID mapping and {Port, VID} to FID mapping for
1302  * virtualized ports.
1303  */
1304 #define MLXSW_REG_SVFA_ID 0x201C
1305 #define MLXSW_REG_SVFA_LEN 0x10
1306
1307 static const struct mlxsw_reg_info mlxsw_reg_svfa = {
1308         .id = MLXSW_REG_SVFA_ID,
1309         .len = MLXSW_REG_SVFA_LEN,
1310 };
1311
1312 /* reg_svfa_swid
1313  * Switch partition ID.
1314  * Access: Index
1315  */
1316 MLXSW_ITEM32(reg, svfa, swid, 0x00, 24, 8);
1317
1318 /* reg_svfa_local_port
1319  * Local port number.
1320  * Access: Index
1321  *
1322  * Note: Reserved for 802.1Q FIDs.
1323  */
1324 MLXSW_ITEM32(reg, svfa, local_port, 0x00, 16, 8);
1325
1326 enum mlxsw_reg_svfa_mt {
1327         MLXSW_REG_SVFA_MT_VID_TO_FID,
1328         MLXSW_REG_SVFA_MT_PORT_VID_TO_FID,
1329 };
1330
1331 /* reg_svfa_mapping_table
1332  * Mapping table:
1333  * 0 - VID to FID
1334  * 1 - {Port, VID} to FID
1335  * Access: Index
1336  *
1337  * Note: Reserved for SwitchX-2.
1338  */
1339 MLXSW_ITEM32(reg, svfa, mapping_table, 0x00, 8, 3);
1340
1341 /* reg_svfa_v
1342  * Valid.
1343  * Valid if set.
1344  * Access: RW
1345  *
1346  * Note: Reserved for SwitchX-2.
1347  */
1348 MLXSW_ITEM32(reg, svfa, v, 0x00, 0, 1);
1349
1350 /* reg_svfa_fid
1351  * Filtering ID.
1352  * Access: RW
1353  */
1354 MLXSW_ITEM32(reg, svfa, fid, 0x04, 16, 16);
1355
1356 /* reg_svfa_vid
1357  * VLAN ID.
1358  * Access: Index
1359  */
1360 MLXSW_ITEM32(reg, svfa, vid, 0x04, 0, 12);
1361
1362 /* reg_svfa_counter_set_type
1363  * Counter set type for flow counters.
1364  * Access: RW
1365  *
1366  * Note: Reserved for SwitchX-2.
1367  */
1368 MLXSW_ITEM32(reg, svfa, counter_set_type, 0x08, 24, 8);
1369
1370 /* reg_svfa_counter_index
1371  * Counter index for flow counters.
1372  * Access: RW
1373  *
1374  * Note: Reserved for SwitchX-2.
1375  */
1376 MLXSW_ITEM32(reg, svfa, counter_index, 0x08, 0, 24);
1377
1378 static inline void mlxsw_reg_svfa_pack(char *payload, u8 local_port,
1379                                        enum mlxsw_reg_svfa_mt mt, bool valid,
1380                                        u16 fid, u16 vid)
1381 {
1382         MLXSW_REG_ZERO(svfa, payload);
1383         local_port = mt == MLXSW_REG_SVFA_MT_VID_TO_FID ? 0 : local_port;
1384         mlxsw_reg_svfa_swid_set(payload, 0);
1385         mlxsw_reg_svfa_local_port_set(payload, local_port);
1386         mlxsw_reg_svfa_mapping_table_set(payload, mt);
1387         mlxsw_reg_svfa_v_set(payload, valid);
1388         mlxsw_reg_svfa_fid_set(payload, fid);
1389         mlxsw_reg_svfa_vid_set(payload, vid);
1390 }
1391
1392 /* SVPE - Switch Virtual-Port Enabling Register
1393  * --------------------------------------------
1394  * Enables port virtualization.
1395  */
1396 #define MLXSW_REG_SVPE_ID 0x201E
1397 #define MLXSW_REG_SVPE_LEN 0x4
1398
1399 static const struct mlxsw_reg_info mlxsw_reg_svpe = {
1400         .id = MLXSW_REG_SVPE_ID,
1401         .len = MLXSW_REG_SVPE_LEN,
1402 };
1403
1404 /* reg_svpe_local_port
1405  * Local port number
1406  * Access: Index
1407  *
1408  * Note: CPU port is not supported (uses VLAN mode only).
1409  */
1410 MLXSW_ITEM32(reg, svpe, local_port, 0x00, 16, 8);
1411
1412 /* reg_svpe_vp_en
1413  * Virtual port enable.
1414  * 0 - Disable, VLAN mode (VID to FID).
1415  * 1 - Enable, Virtual port mode ({Port, VID} to FID).
1416  * Access: RW
1417  */
1418 MLXSW_ITEM32(reg, svpe, vp_en, 0x00, 8, 1);
1419
1420 static inline void mlxsw_reg_svpe_pack(char *payload, u8 local_port,
1421                                        bool enable)
1422 {
1423         MLXSW_REG_ZERO(svpe, payload);
1424         mlxsw_reg_svpe_local_port_set(payload, local_port);
1425         mlxsw_reg_svpe_vp_en_set(payload, enable);
1426 }
1427
1428 /* SFMR - Switch FID Management Register
1429  * -------------------------------------
1430  * Creates and configures FIDs.
1431  */
1432 #define MLXSW_REG_SFMR_ID 0x201F
1433 #define MLXSW_REG_SFMR_LEN 0x18
1434
1435 static const struct mlxsw_reg_info mlxsw_reg_sfmr = {
1436         .id = MLXSW_REG_SFMR_ID,
1437         .len = MLXSW_REG_SFMR_LEN,
1438 };
1439
1440 enum mlxsw_reg_sfmr_op {
1441         MLXSW_REG_SFMR_OP_CREATE_FID,
1442         MLXSW_REG_SFMR_OP_DESTROY_FID,
1443 };
1444
1445 /* reg_sfmr_op
1446  * Operation.
1447  * 0 - Create or edit FID.
1448  * 1 - Destroy FID.
1449  * Access: WO
1450  */
1451 MLXSW_ITEM32(reg, sfmr, op, 0x00, 24, 4);
1452
1453 /* reg_sfmr_fid
1454  * Filtering ID.
1455  * Access: Index
1456  */
1457 MLXSW_ITEM32(reg, sfmr, fid, 0x00, 0, 16);
1458
1459 /* reg_sfmr_fid_offset
1460  * FID offset.
1461  * Used to point into the flooding table selected by SFGC register if
1462  * the table is of type FID-Offset. Otherwise, this field is reserved.
1463  * Access: RW
1464  */
1465 MLXSW_ITEM32(reg, sfmr, fid_offset, 0x08, 0, 16);
1466
1467 /* reg_sfmr_vtfp
1468  * Valid Tunnel Flood Pointer.
1469  * If not set, then nve_tunnel_flood_ptr is reserved and considered NULL.
1470  * Access: RW
1471  *
1472  * Note: Reserved for 802.1Q FIDs.
1473  */
1474 MLXSW_ITEM32(reg, sfmr, vtfp, 0x0C, 31, 1);
1475
1476 /* reg_sfmr_nve_tunnel_flood_ptr
1477  * Underlay Flooding and BC Pointer.
1478  * Used as a pointer to the first entry of the group based link lists of
1479  * flooding or BC entries (for NVE tunnels).
1480  * Access: RW
1481  */
1482 MLXSW_ITEM32(reg, sfmr, nve_tunnel_flood_ptr, 0x0C, 0, 24);
1483
1484 /* reg_sfmr_vv
1485  * VNI Valid.
1486  * If not set, then vni is reserved.
1487  * Access: RW
1488  *
1489  * Note: Reserved for 802.1Q FIDs.
1490  */
1491 MLXSW_ITEM32(reg, sfmr, vv, 0x10, 31, 1);
1492
1493 /* reg_sfmr_vni
1494  * Virtual Network Identifier.
1495  * Access: RW
1496  *
1497  * Note: A given VNI can only be assigned to one FID.
1498  */
1499 MLXSW_ITEM32(reg, sfmr, vni, 0x10, 0, 24);
1500
1501 static inline void mlxsw_reg_sfmr_pack(char *payload,
1502                                        enum mlxsw_reg_sfmr_op op, u16 fid,
1503                                        u16 fid_offset)
1504 {
1505         MLXSW_REG_ZERO(sfmr, payload);
1506         mlxsw_reg_sfmr_op_set(payload, op);
1507         mlxsw_reg_sfmr_fid_set(payload, fid);
1508         mlxsw_reg_sfmr_fid_offset_set(payload, fid_offset);
1509         mlxsw_reg_sfmr_vtfp_set(payload, false);
1510         mlxsw_reg_sfmr_vv_set(payload, false);
1511 }
1512
1513 /* SPVMLR - Switch Port VLAN MAC Learning Register
1514  * -----------------------------------------------
1515  * Controls the switch MAC learning policy per {Port, VID}.
1516  */
1517 #define MLXSW_REG_SPVMLR_ID 0x2020
1518 #define MLXSW_REG_SPVMLR_BASE_LEN 0x04 /* base length, without records */
1519 #define MLXSW_REG_SPVMLR_REC_LEN 0x04 /* record length */
1520 #define MLXSW_REG_SPVMLR_REC_MAX_COUNT 256
1521 #define MLXSW_REG_SPVMLR_LEN (MLXSW_REG_SPVMLR_BASE_LEN + \
1522                               MLXSW_REG_SPVMLR_REC_LEN * \
1523                               MLXSW_REG_SPVMLR_REC_MAX_COUNT)
1524
1525 static const struct mlxsw_reg_info mlxsw_reg_spvmlr = {
1526         .id = MLXSW_REG_SPVMLR_ID,
1527         .len = MLXSW_REG_SPVMLR_LEN,
1528 };
1529
1530 /* reg_spvmlr_local_port
1531  * Local ingress port.
1532  * Access: Index
1533  *
1534  * Note: CPU port is not supported.
1535  */
1536 MLXSW_ITEM32(reg, spvmlr, local_port, 0x00, 16, 8);
1537
1538 /* reg_spvmlr_num_rec
1539  * Number of records to update.
1540  * Access: OP
1541  */
1542 MLXSW_ITEM32(reg, spvmlr, num_rec, 0x00, 0, 8);
1543
1544 /* reg_spvmlr_rec_learn_enable
1545  * 0 - Disable learning for {Port, VID}.
1546  * 1 - Enable learning for {Port, VID}.
1547  * Access: RW
1548  */
1549 MLXSW_ITEM32_INDEXED(reg, spvmlr, rec_learn_enable, MLXSW_REG_SPVMLR_BASE_LEN,
1550                      31, 1, MLXSW_REG_SPVMLR_REC_LEN, 0x00, false);
1551
1552 /* reg_spvmlr_rec_vid
1553  * VLAN ID to be added/removed from port or for querying.
1554  * Access: Index
1555  */
1556 MLXSW_ITEM32_INDEXED(reg, spvmlr, rec_vid, MLXSW_REG_SPVMLR_BASE_LEN, 0, 12,
1557                      MLXSW_REG_SPVMLR_REC_LEN, 0x00, false);
1558
1559 static inline void mlxsw_reg_spvmlr_pack(char *payload, u8 local_port,
1560                                          u16 vid_begin, u16 vid_end,
1561                                          bool learn_enable)
1562 {
1563         int num_rec = vid_end - vid_begin + 1;
1564         int i;
1565
1566         WARN_ON(num_rec < 1 || num_rec > MLXSW_REG_SPVMLR_REC_MAX_COUNT);
1567
1568         MLXSW_REG_ZERO(spvmlr, payload);
1569         mlxsw_reg_spvmlr_local_port_set(payload, local_port);
1570         mlxsw_reg_spvmlr_num_rec_set(payload, num_rec);
1571
1572         for (i = 0; i < num_rec; i++) {
1573                 mlxsw_reg_spvmlr_rec_learn_enable_set(payload, i, learn_enable);
1574                 mlxsw_reg_spvmlr_rec_vid_set(payload, i, vid_begin + i);
1575         }
1576 }
1577
1578 /* PMLP - Ports Module to Local Port Register
1579  * ------------------------------------------
1580  * Configures the assignment of modules to local ports.
1581  */
1582 #define MLXSW_REG_PMLP_ID 0x5002
1583 #define MLXSW_REG_PMLP_LEN 0x40
1584
1585 static const struct mlxsw_reg_info mlxsw_reg_pmlp = {
1586         .id = MLXSW_REG_PMLP_ID,
1587         .len = MLXSW_REG_PMLP_LEN,
1588 };
1589
1590 /* reg_pmlp_rxtx
1591  * 0 - Tx value is used for both Tx and Rx.
1592  * 1 - Rx value is taken from a separte field.
1593  * Access: RW
1594  */
1595 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
1596
1597 /* reg_pmlp_local_port
1598  * Local port number.
1599  * Access: Index
1600  */
1601 MLXSW_ITEM32(reg, pmlp, local_port, 0x00, 16, 8);
1602
1603 /* reg_pmlp_width
1604  * 0 - Unmap local port.
1605  * 1 - Lane 0 is used.
1606  * 2 - Lanes 0 and 1 are used.
1607  * 4 - Lanes 0, 1, 2 and 3 are used.
1608  * Access: RW
1609  */
1610 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
1611
1612 /* reg_pmlp_module
1613  * Module number.
1614  * Access: RW
1615  */
1616 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0, false);
1617
1618 /* reg_pmlp_tx_lane
1619  * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
1620  * Access: RW
1621  */
1622 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 2, 0x04, 16, false);
1623
1624 /* reg_pmlp_rx_lane
1625  * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
1626  * equal to Tx lane.
1627  * Access: RW
1628  */
1629 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 2, 0x04, 24, false);
1630
1631 static inline void mlxsw_reg_pmlp_pack(char *payload, u8 local_port)
1632 {
1633         MLXSW_REG_ZERO(pmlp, payload);
1634         mlxsw_reg_pmlp_local_port_set(payload, local_port);
1635 }
1636
1637 /* PMTU - Port MTU Register
1638  * ------------------------
1639  * Configures and reports the port MTU.
1640  */
1641 #define MLXSW_REG_PMTU_ID 0x5003
1642 #define MLXSW_REG_PMTU_LEN 0x10
1643
1644 static const struct mlxsw_reg_info mlxsw_reg_pmtu = {
1645         .id = MLXSW_REG_PMTU_ID,
1646         .len = MLXSW_REG_PMTU_LEN,
1647 };
1648
1649 /* reg_pmtu_local_port
1650  * Local port number.
1651  * Access: Index
1652  */
1653 MLXSW_ITEM32(reg, pmtu, local_port, 0x00, 16, 8);
1654
1655 /* reg_pmtu_max_mtu
1656  * Maximum MTU.
1657  * When port type (e.g. Ethernet) is configured, the relevant MTU is
1658  * reported, otherwise the minimum between the max_mtu of the different
1659  * types is reported.
1660  * Access: RO
1661  */
1662 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
1663
1664 /* reg_pmtu_admin_mtu
1665  * MTU value to set port to. Must be smaller or equal to max_mtu.
1666  * Note: If port type is Infiniband, then port must be disabled, when its
1667  * MTU is set.
1668  * Access: RW
1669  */
1670 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
1671
1672 /* reg_pmtu_oper_mtu
1673  * The actual MTU configured on the port. Packets exceeding this size
1674  * will be dropped.
1675  * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
1676  * oper_mtu might be smaller than admin_mtu.
1677  * Access: RO
1678  */
1679 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
1680
1681 static inline void mlxsw_reg_pmtu_pack(char *payload, u8 local_port,
1682                                        u16 new_mtu)
1683 {
1684         MLXSW_REG_ZERO(pmtu, payload);
1685         mlxsw_reg_pmtu_local_port_set(payload, local_port);
1686         mlxsw_reg_pmtu_max_mtu_set(payload, 0);
1687         mlxsw_reg_pmtu_admin_mtu_set(payload, new_mtu);
1688         mlxsw_reg_pmtu_oper_mtu_set(payload, 0);
1689 }
1690
1691 /* PTYS - Port Type and Speed Register
1692  * -----------------------------------
1693  * Configures and reports the port speed type.
1694  *
1695  * Note: When set while the link is up, the changes will not take effect
1696  * until the port transitions from down to up state.
1697  */
1698 #define MLXSW_REG_PTYS_ID 0x5004
1699 #define MLXSW_REG_PTYS_LEN 0x40
1700
1701 static const struct mlxsw_reg_info mlxsw_reg_ptys = {
1702         .id = MLXSW_REG_PTYS_ID,
1703         .len = MLXSW_REG_PTYS_LEN,
1704 };
1705
1706 /* reg_ptys_local_port
1707  * Local port number.
1708  * Access: Index
1709  */
1710 MLXSW_ITEM32(reg, ptys, local_port, 0x00, 16, 8);
1711
1712 #define MLXSW_REG_PTYS_PROTO_MASK_ETH   BIT(2)
1713
1714 /* reg_ptys_proto_mask
1715  * Protocol mask. Indicates which protocol is used.
1716  * 0 - Infiniband.
1717  * 1 - Fibre Channel.
1718  * 2 - Ethernet.
1719  * Access: Index
1720  */
1721 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
1722
1723 #define MLXSW_REG_PTYS_ETH_SPEED_SGMII                  BIT(0)
1724 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX            BIT(1)
1725 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4            BIT(2)
1726 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4            BIT(3)
1727 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR             BIT(4)
1728 #define MLXSW_REG_PTYS_ETH_SPEED_20GBASE_KR2            BIT(5)
1729 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4            BIT(6)
1730 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4            BIT(7)
1731 #define MLXSW_REG_PTYS_ETH_SPEED_56GBASE_R4             BIT(8)
1732 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR             BIT(12)
1733 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR             BIT(13)
1734 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR          BIT(14)
1735 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4            BIT(15)
1736 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4        BIT(16)
1737 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR4            BIT(19)
1738 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4           BIT(20)
1739 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4           BIT(21)
1740 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4           BIT(22)
1741 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4       BIT(23)
1742 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_TX             BIT(24)
1743 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_T              BIT(25)
1744 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_T              BIT(26)
1745 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR             BIT(27)
1746 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR             BIT(28)
1747 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR             BIT(29)
1748 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2            BIT(30)
1749 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2            BIT(31)
1750
1751 /* reg_ptys_eth_proto_cap
1752  * Ethernet port supported speeds and protocols.
1753  * Access: RO
1754  */
1755 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
1756
1757 /* reg_ptys_eth_proto_admin
1758  * Speed and protocol to set port to.
1759  * Access: RW
1760  */
1761 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
1762
1763 /* reg_ptys_eth_proto_oper
1764  * The current speed and protocol configured for the port.
1765  * Access: RO
1766  */
1767 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
1768
1769 static inline void mlxsw_reg_ptys_pack(char *payload, u8 local_port,
1770                                        u32 proto_admin)
1771 {
1772         MLXSW_REG_ZERO(ptys, payload);
1773         mlxsw_reg_ptys_local_port_set(payload, local_port);
1774         mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
1775         mlxsw_reg_ptys_eth_proto_admin_set(payload, proto_admin);
1776 }
1777
1778 static inline void mlxsw_reg_ptys_unpack(char *payload, u32 *p_eth_proto_cap,
1779                                          u32 *p_eth_proto_adm,
1780                                          u32 *p_eth_proto_oper)
1781 {
1782         if (p_eth_proto_cap)
1783                 *p_eth_proto_cap = mlxsw_reg_ptys_eth_proto_cap_get(payload);
1784         if (p_eth_proto_adm)
1785                 *p_eth_proto_adm = mlxsw_reg_ptys_eth_proto_admin_get(payload);
1786         if (p_eth_proto_oper)
1787                 *p_eth_proto_oper = mlxsw_reg_ptys_eth_proto_oper_get(payload);
1788 }
1789
1790 /* PPAD - Port Physical Address Register
1791  * -------------------------------------
1792  * The PPAD register configures the per port physical MAC address.
1793  */
1794 #define MLXSW_REG_PPAD_ID 0x5005
1795 #define MLXSW_REG_PPAD_LEN 0x10
1796
1797 static const struct mlxsw_reg_info mlxsw_reg_ppad = {
1798         .id = MLXSW_REG_PPAD_ID,
1799         .len = MLXSW_REG_PPAD_LEN,
1800 };
1801
1802 /* reg_ppad_single_base_mac
1803  * 0: base_mac, local port should be 0 and mac[7:0] is
1804  * reserved. HW will set incremental
1805  * 1: single_mac - mac of the local_port
1806  * Access: RW
1807  */
1808 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
1809
1810 /* reg_ppad_local_port
1811  * port number, if single_base_mac = 0 then local_port is reserved
1812  * Access: RW
1813  */
1814 MLXSW_ITEM32(reg, ppad, local_port, 0x00, 16, 8);
1815
1816 /* reg_ppad_mac
1817  * If single_base_mac = 0 - base MAC address, mac[7:0] is reserved.
1818  * If single_base_mac = 1 - the per port MAC address
1819  * Access: RW
1820  */
1821 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
1822
1823 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
1824                                        u8 local_port)
1825 {
1826         MLXSW_REG_ZERO(ppad, payload);
1827         mlxsw_reg_ppad_single_base_mac_set(payload, !!single_base_mac);
1828         mlxsw_reg_ppad_local_port_set(payload, local_port);
1829 }
1830
1831 /* PAOS - Ports Administrative and Operational Status Register
1832  * -----------------------------------------------------------
1833  * Configures and retrieves per port administrative and operational status.
1834  */
1835 #define MLXSW_REG_PAOS_ID 0x5006
1836 #define MLXSW_REG_PAOS_LEN 0x10
1837
1838 static const struct mlxsw_reg_info mlxsw_reg_paos = {
1839         .id = MLXSW_REG_PAOS_ID,
1840         .len = MLXSW_REG_PAOS_LEN,
1841 };
1842
1843 /* reg_paos_swid
1844  * Switch partition ID with which to associate the port.
1845  * Note: while external ports uses unique local port numbers (and thus swid is
1846  * redundant), router ports use the same local port number where swid is the
1847  * only indication for the relevant port.
1848  * Access: Index
1849  */
1850 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
1851
1852 /* reg_paos_local_port
1853  * Local port number.
1854  * Access: Index
1855  */
1856 MLXSW_ITEM32(reg, paos, local_port, 0x00, 16, 8);
1857
1858 /* reg_paos_admin_status
1859  * Port administrative state (the desired state of the port):
1860  * 1 - Up.
1861  * 2 - Down.
1862  * 3 - Up once. This means that in case of link failure, the port won't go
1863  *     into polling mode, but will wait to be re-enabled by software.
1864  * 4 - Disabled by system. Can only be set by hardware.
1865  * Access: RW
1866  */
1867 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
1868
1869 /* reg_paos_oper_status
1870  * Port operational state (the current state):
1871  * 1 - Up.
1872  * 2 - Down.
1873  * 3 - Down by port failure. This means that the device will not let the
1874  *     port up again until explicitly specified by software.
1875  * Access: RO
1876  */
1877 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
1878
1879 /* reg_paos_ase
1880  * Admin state update enabled.
1881  * Access: WO
1882  */
1883 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
1884
1885 /* reg_paos_ee
1886  * Event update enable. If this bit is set, event generation will be
1887  * updated based on the e field.
1888  * Access: WO
1889  */
1890 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
1891
1892 /* reg_paos_e
1893  * Event generation on operational state change:
1894  * 0 - Do not generate event.
1895  * 1 - Generate Event.
1896  * 2 - Generate Single Event.
1897  * Access: RW
1898  */
1899 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
1900
1901 static inline void mlxsw_reg_paos_pack(char *payload, u8 local_port,
1902                                        enum mlxsw_port_admin_status status)
1903 {
1904         MLXSW_REG_ZERO(paos, payload);
1905         mlxsw_reg_paos_swid_set(payload, 0);
1906         mlxsw_reg_paos_local_port_set(payload, local_port);
1907         mlxsw_reg_paos_admin_status_set(payload, status);
1908         mlxsw_reg_paos_oper_status_set(payload, 0);
1909         mlxsw_reg_paos_ase_set(payload, 1);
1910         mlxsw_reg_paos_ee_set(payload, 1);
1911         mlxsw_reg_paos_e_set(payload, 1);
1912 }
1913
1914 /* PPCNT - Ports Performance Counters Register
1915  * -------------------------------------------
1916  * The PPCNT register retrieves per port performance counters.
1917  */
1918 #define MLXSW_REG_PPCNT_ID 0x5008
1919 #define MLXSW_REG_PPCNT_LEN 0x100
1920
1921 static const struct mlxsw_reg_info mlxsw_reg_ppcnt = {
1922         .id = MLXSW_REG_PPCNT_ID,
1923         .len = MLXSW_REG_PPCNT_LEN,
1924 };
1925
1926 /* reg_ppcnt_swid
1927  * For HCA: must be always 0.
1928  * Switch partition ID to associate port with.
1929  * Switch partitions are numbered from 0 to 7 inclusively.
1930  * Switch partition 254 indicates stacking ports.
1931  * Switch partition 255 indicates all switch partitions.
1932  * Only valid on Set() operation with local_port=255.
1933  * Access: Index
1934  */
1935 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
1936
1937 /* reg_ppcnt_local_port
1938  * Local port number.
1939  * 255 indicates all ports on the device, and is only allowed
1940  * for Set() operation.
1941  * Access: Index
1942  */
1943 MLXSW_ITEM32(reg, ppcnt, local_port, 0x00, 16, 8);
1944
1945 /* reg_ppcnt_pnat
1946  * Port number access type:
1947  * 0 - Local port number
1948  * 1 - IB port number
1949  * Access: Index
1950  */
1951 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
1952
1953 /* reg_ppcnt_grp
1954  * Performance counter group.
1955  * Group 63 indicates all groups. Only valid on Set() operation with
1956  * clr bit set.
1957  * 0x0: IEEE 802.3 Counters
1958  * 0x1: RFC 2863 Counters
1959  * 0x2: RFC 2819 Counters
1960  * 0x3: RFC 3635 Counters
1961  * 0x5: Ethernet Extended Counters
1962  * 0x8: Link Level Retransmission Counters
1963  * 0x10: Per Priority Counters
1964  * 0x11: Per Traffic Class Counters
1965  * 0x12: Physical Layer Counters
1966  * Access: Index
1967  */
1968 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
1969
1970 /* reg_ppcnt_clr
1971  * Clear counters. Setting the clr bit will reset the counter value
1972  * for all counters in the counter group. This bit can be set
1973  * for both Set() and Get() operation.
1974  * Access: OP
1975  */
1976 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
1977
1978 /* reg_ppcnt_prio_tc
1979  * Priority for counter set that support per priority, valid values: 0-7.
1980  * Traffic class for counter set that support per traffic class,
1981  * valid values: 0- cap_max_tclass-1 .
1982  * For HCA: cap_max_tclass is always 8.
1983  * Otherwise must be 0.
1984  * Access: Index
1985  */
1986 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
1987
1988 /* reg_ppcnt_a_frames_transmitted_ok
1989  * Access: RO
1990  */
1991 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
1992              0x08 + 0x00, 0, 64);
1993
1994 /* reg_ppcnt_a_frames_received_ok
1995  * Access: RO
1996  */
1997 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
1998              0x08 + 0x08, 0, 64);
1999
2000 /* reg_ppcnt_a_frame_check_sequence_errors
2001  * Access: RO
2002  */
2003 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
2004              0x08 + 0x10, 0, 64);
2005
2006 /* reg_ppcnt_a_alignment_errors
2007  * Access: RO
2008  */
2009 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
2010              0x08 + 0x18, 0, 64);
2011
2012 /* reg_ppcnt_a_octets_transmitted_ok
2013  * Access: RO
2014  */
2015 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
2016              0x08 + 0x20, 0, 64);
2017
2018 /* reg_ppcnt_a_octets_received_ok
2019  * Access: RO
2020  */
2021 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
2022              0x08 + 0x28, 0, 64);
2023
2024 /* reg_ppcnt_a_multicast_frames_xmitted_ok
2025  * Access: RO
2026  */
2027 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
2028              0x08 + 0x30, 0, 64);
2029
2030 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
2031  * Access: RO
2032  */
2033 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
2034              0x08 + 0x38, 0, 64);
2035
2036 /* reg_ppcnt_a_multicast_frames_received_ok
2037  * Access: RO
2038  */
2039 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
2040              0x08 + 0x40, 0, 64);
2041
2042 /* reg_ppcnt_a_broadcast_frames_received_ok
2043  * Access: RO
2044  */
2045 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
2046              0x08 + 0x48, 0, 64);
2047
2048 /* reg_ppcnt_a_in_range_length_errors
2049  * Access: RO
2050  */
2051 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
2052              0x08 + 0x50, 0, 64);
2053
2054 /* reg_ppcnt_a_out_of_range_length_field
2055  * Access: RO
2056  */
2057 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
2058              0x08 + 0x58, 0, 64);
2059
2060 /* reg_ppcnt_a_frame_too_long_errors
2061  * Access: RO
2062  */
2063 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
2064              0x08 + 0x60, 0, 64);
2065
2066 /* reg_ppcnt_a_symbol_error_during_carrier
2067  * Access: RO
2068  */
2069 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
2070              0x08 + 0x68, 0, 64);
2071
2072 /* reg_ppcnt_a_mac_control_frames_transmitted
2073  * Access: RO
2074  */
2075 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
2076              0x08 + 0x70, 0, 64);
2077
2078 /* reg_ppcnt_a_mac_control_frames_received
2079  * Access: RO
2080  */
2081 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
2082              0x08 + 0x78, 0, 64);
2083
2084 /* reg_ppcnt_a_unsupported_opcodes_received
2085  * Access: RO
2086  */
2087 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
2088              0x08 + 0x80, 0, 64);
2089
2090 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
2091  * Access: RO
2092  */
2093 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
2094              0x08 + 0x88, 0, 64);
2095
2096 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
2097  * Access: RO
2098  */
2099 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
2100              0x08 + 0x90, 0, 64);
2101
2102 static inline void mlxsw_reg_ppcnt_pack(char *payload, u8 local_port)
2103 {
2104         MLXSW_REG_ZERO(ppcnt, payload);
2105         mlxsw_reg_ppcnt_swid_set(payload, 0);
2106         mlxsw_reg_ppcnt_local_port_set(payload, local_port);
2107         mlxsw_reg_ppcnt_pnat_set(payload, 0);
2108         mlxsw_reg_ppcnt_grp_set(payload, 0);
2109         mlxsw_reg_ppcnt_clr_set(payload, 0);
2110         mlxsw_reg_ppcnt_prio_tc_set(payload, 0);
2111 }
2112
2113 /* PBMC - Port Buffer Management Control Register
2114  * ----------------------------------------------
2115  * The PBMC register configures and retrieves the port packet buffer
2116  * allocation for different Prios, and the Pause threshold management.
2117  */
2118 #define MLXSW_REG_PBMC_ID 0x500C
2119 #define MLXSW_REG_PBMC_LEN 0x68
2120
2121 static const struct mlxsw_reg_info mlxsw_reg_pbmc = {
2122         .id = MLXSW_REG_PBMC_ID,
2123         .len = MLXSW_REG_PBMC_LEN,
2124 };
2125
2126 /* reg_pbmc_local_port
2127  * Local port number.
2128  * Access: Index
2129  */
2130 MLXSW_ITEM32(reg, pbmc, local_port, 0x00, 16, 8);
2131
2132 /* reg_pbmc_xoff_timer_value
2133  * When device generates a pause frame, it uses this value as the pause
2134  * timer (time for the peer port to pause in quota-512 bit time).
2135  * Access: RW
2136  */
2137 MLXSW_ITEM32(reg, pbmc, xoff_timer_value, 0x04, 16, 16);
2138
2139 /* reg_pbmc_xoff_refresh
2140  * The time before a new pause frame should be sent to refresh the pause RW
2141  * state. Using the same units as xoff_timer_value above (in quota-512 bit
2142  * time).
2143  * Access: RW
2144  */
2145 MLXSW_ITEM32(reg, pbmc, xoff_refresh, 0x04, 0, 16);
2146
2147 /* reg_pbmc_buf_lossy
2148  * The field indicates if the buffer is lossy.
2149  * 0 - Lossless
2150  * 1 - Lossy
2151  * Access: RW
2152  */
2153 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_lossy, 0x0C, 25, 1, 0x08, 0x00, false);
2154
2155 /* reg_pbmc_buf_epsb
2156  * Eligible for Port Shared buffer.
2157  * If epsb is set, packets assigned to buffer are allowed to insert the port
2158  * shared buffer.
2159  * When buf_lossy is MLXSW_REG_PBMC_LOSSY_LOSSY this field is reserved.
2160  * Access: RW
2161  */
2162 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_epsb, 0x0C, 24, 1, 0x08, 0x00, false);
2163
2164 /* reg_pbmc_buf_size
2165  * The part of the packet buffer array is allocated for the specific buffer.
2166  * Units are represented in cells.
2167  * Access: RW
2168  */
2169 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_size, 0x0C, 0, 16, 0x08, 0x00, false);
2170
2171 static inline void mlxsw_reg_pbmc_pack(char *payload, u8 local_port,
2172                                        u16 xoff_timer_value, u16 xoff_refresh)
2173 {
2174         MLXSW_REG_ZERO(pbmc, payload);
2175         mlxsw_reg_pbmc_local_port_set(payload, local_port);
2176         mlxsw_reg_pbmc_xoff_timer_value_set(payload, xoff_timer_value);
2177         mlxsw_reg_pbmc_xoff_refresh_set(payload, xoff_refresh);
2178 }
2179
2180 static inline void mlxsw_reg_pbmc_lossy_buffer_pack(char *payload,
2181                                                     int buf_index,
2182                                                     u16 size)
2183 {
2184         mlxsw_reg_pbmc_buf_lossy_set(payload, buf_index, 1);
2185         mlxsw_reg_pbmc_buf_epsb_set(payload, buf_index, 0);
2186         mlxsw_reg_pbmc_buf_size_set(payload, buf_index, size);
2187 }
2188
2189 /* PSPA - Port Switch Partition Allocation
2190  * ---------------------------------------
2191  * Controls the association of a port with a switch partition and enables
2192  * configuring ports as stacking ports.
2193  */
2194 #define MLXSW_REG_PSPA_ID 0x500D
2195 #define MLXSW_REG_PSPA_LEN 0x8
2196
2197 static const struct mlxsw_reg_info mlxsw_reg_pspa = {
2198         .id = MLXSW_REG_PSPA_ID,
2199         .len = MLXSW_REG_PSPA_LEN,
2200 };
2201
2202 /* reg_pspa_swid
2203  * Switch partition ID.
2204  * Access: RW
2205  */
2206 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
2207
2208 /* reg_pspa_local_port
2209  * Local port number.
2210  * Access: Index
2211  */
2212 MLXSW_ITEM32(reg, pspa, local_port, 0x00, 16, 8);
2213
2214 /* reg_pspa_sub_port
2215  * Virtual port within the local port. Set to 0 when virtual ports are
2216  * disabled on the local port.
2217  * Access: Index
2218  */
2219 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
2220
2221 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
2222 {
2223         MLXSW_REG_ZERO(pspa, payload);
2224         mlxsw_reg_pspa_swid_set(payload, swid);
2225         mlxsw_reg_pspa_local_port_set(payload, local_port);
2226         mlxsw_reg_pspa_sub_port_set(payload, 0);
2227 }
2228
2229 /* HTGT - Host Trap Group Table
2230  * ----------------------------
2231  * Configures the properties for forwarding to CPU.
2232  */
2233 #define MLXSW_REG_HTGT_ID 0x7002
2234 #define MLXSW_REG_HTGT_LEN 0x100
2235
2236 static const struct mlxsw_reg_info mlxsw_reg_htgt = {
2237         .id = MLXSW_REG_HTGT_ID,
2238         .len = MLXSW_REG_HTGT_LEN,
2239 };
2240
2241 /* reg_htgt_swid
2242  * Switch partition ID.
2243  * Access: Index
2244  */
2245 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
2246
2247 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0      /* For locally attached CPU */
2248
2249 /* reg_htgt_type
2250  * CPU path type.
2251  * Access: RW
2252  */
2253 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
2254
2255 enum mlxsw_reg_htgt_trap_group {
2256         MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
2257         MLXSW_REG_HTGT_TRAP_GROUP_RX,
2258         MLXSW_REG_HTGT_TRAP_GROUP_CTRL,
2259 };
2260
2261 /* reg_htgt_trap_group
2262  * Trap group number. User defined number specifying which trap groups
2263  * should be forwarded to the CPU. The mapping between trap IDs and trap
2264  * groups is configured using HPKT register.
2265  * Access: Index
2266  */
2267 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
2268
2269 enum {
2270         MLXSW_REG_HTGT_POLICER_DISABLE,
2271         MLXSW_REG_HTGT_POLICER_ENABLE,
2272 };
2273
2274 /* reg_htgt_pide
2275  * Enable policer ID specified using 'pid' field.
2276  * Access: RW
2277  */
2278 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
2279
2280 /* reg_htgt_pid
2281  * Policer ID for the trap group.
2282  * Access: RW
2283  */
2284 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
2285
2286 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
2287
2288 /* reg_htgt_mirror_action
2289  * Mirror action to use.
2290  * 0 - Trap to CPU.
2291  * 1 - Trap to CPU and mirror to a mirroring agent.
2292  * 2 - Mirror to a mirroring agent and do not trap to CPU.
2293  * Access: RW
2294  *
2295  * Note: Mirroring to a mirroring agent is only supported in Spectrum.
2296  */
2297 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
2298
2299 /* reg_htgt_mirroring_agent
2300  * Mirroring agent.
2301  * Access: RW
2302  */
2303 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
2304
2305 /* reg_htgt_priority
2306  * Trap group priority.
2307  * In case a packet matches multiple classification rules, the packet will
2308  * only be trapped once, based on the trap ID associated with the group (via
2309  * register HPKT) with the highest priority.
2310  * Supported values are 0-7, with 7 represnting the highest priority.
2311  * Access: RW
2312  *
2313  * Note: In SwitchX-2 this field is ignored and the priority value is replaced
2314  * by the 'trap_group' field.
2315  */
2316 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
2317
2318 /* reg_htgt_local_path_cpu_tclass
2319  * CPU ingress traffic class for the trap group.
2320  * Access: RW
2321  */
2322 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
2323
2324 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD      0x15
2325 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX        0x14
2326 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL      0x13
2327
2328 /* reg_htgt_local_path_rdq
2329  * Receive descriptor queue (RDQ) to use for the trap group.
2330  * Access: RW
2331  */
2332 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
2333
2334 static inline void mlxsw_reg_htgt_pack(char *payload,
2335                                        enum mlxsw_reg_htgt_trap_group group)
2336 {
2337         u8 swid, rdq;
2338
2339         MLXSW_REG_ZERO(htgt, payload);
2340         switch (group) {
2341         case MLXSW_REG_HTGT_TRAP_GROUP_EMAD:
2342                 swid = MLXSW_PORT_SWID_ALL_SWIDS;
2343                 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD;
2344                 break;
2345         case MLXSW_REG_HTGT_TRAP_GROUP_RX:
2346                 swid = 0;
2347                 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX;
2348                 break;
2349         case MLXSW_REG_HTGT_TRAP_GROUP_CTRL:
2350                 swid = 0;
2351                 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL;
2352                 break;
2353         }
2354         mlxsw_reg_htgt_swid_set(payload, swid);
2355         mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
2356         mlxsw_reg_htgt_trap_group_set(payload, group);
2357         mlxsw_reg_htgt_pide_set(payload, MLXSW_REG_HTGT_POLICER_DISABLE);
2358         mlxsw_reg_htgt_pid_set(payload, 0);
2359         mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
2360         mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
2361         mlxsw_reg_htgt_priority_set(payload, 0);
2362         mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, 7);
2363         mlxsw_reg_htgt_local_path_rdq_set(payload, rdq);
2364 }
2365
2366 /* HPKT - Host Packet Trap
2367  * -----------------------
2368  * Configures trap IDs inside trap groups.
2369  */
2370 #define MLXSW_REG_HPKT_ID 0x7003
2371 #define MLXSW_REG_HPKT_LEN 0x10
2372
2373 static const struct mlxsw_reg_info mlxsw_reg_hpkt = {
2374         .id = MLXSW_REG_HPKT_ID,
2375         .len = MLXSW_REG_HPKT_LEN,
2376 };
2377
2378 enum {
2379         MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
2380         MLXSW_REG_HPKT_ACK_REQUIRED,
2381 };
2382
2383 /* reg_hpkt_ack
2384  * Require acknowledgements from the host for events.
2385  * If set, then the device will wait for the event it sent to be acknowledged
2386  * by the host. This option is only relevant for event trap IDs.
2387  * Access: RW
2388  *
2389  * Note: Currently not supported by firmware.
2390  */
2391 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
2392
2393 enum mlxsw_reg_hpkt_action {
2394         MLXSW_REG_HPKT_ACTION_FORWARD,
2395         MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
2396         MLXSW_REG_HPKT_ACTION_MIRROR_TO_CPU,
2397         MLXSW_REG_HPKT_ACTION_DISCARD,
2398         MLXSW_REG_HPKT_ACTION_SOFT_DISCARD,
2399         MLXSW_REG_HPKT_ACTION_TRAP_AND_SOFT_DISCARD,
2400 };
2401
2402 /* reg_hpkt_action
2403  * Action to perform on packet when trapped.
2404  * 0 - No action. Forward to CPU based on switching rules.
2405  * 1 - Trap to CPU (CPU receives sole copy).
2406  * 2 - Mirror to CPU (CPU receives a replica of the packet).
2407  * 3 - Discard.
2408  * 4 - Soft discard (allow other traps to act on the packet).
2409  * 5 - Trap and soft discard (allow other traps to overwrite this trap).
2410  * Access: RW
2411  *
2412  * Note: Must be set to 0 (forward) for event trap IDs, as they are already
2413  * addressed to the CPU.
2414  */
2415 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
2416
2417 /* reg_hpkt_trap_group
2418  * Trap group to associate the trap with.
2419  * Access: RW
2420  */
2421 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
2422
2423 /* reg_hpkt_trap_id
2424  * Trap ID.
2425  * Access: Index
2426  *
2427  * Note: A trap ID can only be associated with a single trap group. The device
2428  * will associate the trap ID with the last trap group configured.
2429  */
2430 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 9);
2431
2432 enum {
2433         MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
2434         MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
2435         MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
2436 };
2437
2438 /* reg_hpkt_ctrl
2439  * Configure dedicated buffer resources for control packets.
2440  * 0 - Keep factory defaults.
2441  * 1 - Do not use control buffer for this trap ID.
2442  * 2 - Use control buffer for this trap ID.
2443  * Access: RW
2444  */
2445 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
2446
2447 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id)
2448 {
2449         enum mlxsw_reg_htgt_trap_group trap_group;
2450
2451         MLXSW_REG_ZERO(hpkt, payload);
2452         mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
2453         mlxsw_reg_hpkt_action_set(payload, action);
2454         switch (trap_id) {
2455         case MLXSW_TRAP_ID_ETHEMAD:
2456         case MLXSW_TRAP_ID_PUDE:
2457                 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_EMAD;
2458                 break;
2459         default:
2460                 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_RX;
2461                 break;
2462         }
2463         mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
2464         mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
2465         mlxsw_reg_hpkt_ctrl_set(payload, MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT);
2466 }
2467
2468 /* MFCR - Management Fan Control Register
2469  * --------------------------------------
2470  * This register controls the settings of the Fan Speed PWM mechanism.
2471  */
2472 #define MLXSW_REG_MFCR_ID 0x9001
2473 #define MLXSW_REG_MFCR_LEN 0x08
2474
2475 static const struct mlxsw_reg_info mlxsw_reg_mfcr = {
2476         .id = MLXSW_REG_MFCR_ID,
2477         .len = MLXSW_REG_MFCR_LEN,
2478 };
2479
2480 enum mlxsw_reg_mfcr_pwm_frequency {
2481         MLXSW_REG_MFCR_PWM_FEQ_11HZ = 0x00,
2482         MLXSW_REG_MFCR_PWM_FEQ_14_7HZ = 0x01,
2483         MLXSW_REG_MFCR_PWM_FEQ_22_1HZ = 0x02,
2484         MLXSW_REG_MFCR_PWM_FEQ_1_4KHZ = 0x40,
2485         MLXSW_REG_MFCR_PWM_FEQ_5KHZ = 0x41,
2486         MLXSW_REG_MFCR_PWM_FEQ_20KHZ = 0x42,
2487         MLXSW_REG_MFCR_PWM_FEQ_22_5KHZ = 0x43,
2488         MLXSW_REG_MFCR_PWM_FEQ_25KHZ = 0x44,
2489 };
2490
2491 /* reg_mfcr_pwm_frequency
2492  * Controls the frequency of the PWM signal.
2493  * Access: RW
2494  */
2495 MLXSW_ITEM32(reg, mfcr, pwm_frequency, 0x00, 0, 6);
2496
2497 #define MLXSW_MFCR_TACHOS_MAX 10
2498
2499 /* reg_mfcr_tacho_active
2500  * Indicates which of the tachometer is active (bit per tachometer).
2501  * Access: RO
2502  */
2503 MLXSW_ITEM32(reg, mfcr, tacho_active, 0x04, 16, MLXSW_MFCR_TACHOS_MAX);
2504
2505 #define MLXSW_MFCR_PWMS_MAX 5
2506
2507 /* reg_mfcr_pwm_active
2508  * Indicates which of the PWM control is active (bit per PWM).
2509  * Access: RO
2510  */
2511 MLXSW_ITEM32(reg, mfcr, pwm_active, 0x04, 0, MLXSW_MFCR_PWMS_MAX);
2512
2513 static inline void
2514 mlxsw_reg_mfcr_pack(char *payload,
2515                     enum mlxsw_reg_mfcr_pwm_frequency pwm_frequency)
2516 {
2517         MLXSW_REG_ZERO(mfcr, payload);
2518         mlxsw_reg_mfcr_pwm_frequency_set(payload, pwm_frequency);
2519 }
2520
2521 static inline void
2522 mlxsw_reg_mfcr_unpack(char *payload,
2523                       enum mlxsw_reg_mfcr_pwm_frequency *p_pwm_frequency,
2524                       u16 *p_tacho_active, u8 *p_pwm_active)
2525 {
2526         *p_pwm_frequency = mlxsw_reg_mfcr_pwm_frequency_get(payload);
2527         *p_tacho_active = mlxsw_reg_mfcr_tacho_active_get(payload);
2528         *p_pwm_active = mlxsw_reg_mfcr_pwm_active_get(payload);
2529 }
2530
2531 /* MFSC - Management Fan Speed Control Register
2532  * --------------------------------------------
2533  * This register controls the settings of the Fan Speed PWM mechanism.
2534  */
2535 #define MLXSW_REG_MFSC_ID 0x9002
2536 #define MLXSW_REG_MFSC_LEN 0x08
2537
2538 static const struct mlxsw_reg_info mlxsw_reg_mfsc = {
2539         .id = MLXSW_REG_MFSC_ID,
2540         .len = MLXSW_REG_MFSC_LEN,
2541 };
2542
2543 /* reg_mfsc_pwm
2544  * Fan pwm to control / monitor.
2545  * Access: Index
2546  */
2547 MLXSW_ITEM32(reg, mfsc, pwm, 0x00, 24, 3);
2548
2549 /* reg_mfsc_pwm_duty_cycle
2550  * Controls the duty cycle of the PWM. Value range from 0..255 to
2551  * represent duty cycle of 0%...100%.
2552  * Access: RW
2553  */
2554 MLXSW_ITEM32(reg, mfsc, pwm_duty_cycle, 0x04, 0, 8);
2555
2556 static inline void mlxsw_reg_mfsc_pack(char *payload, u8 pwm,
2557                                        u8 pwm_duty_cycle)
2558 {
2559         MLXSW_REG_ZERO(mfsc, payload);
2560         mlxsw_reg_mfsc_pwm_set(payload, pwm);
2561         mlxsw_reg_mfsc_pwm_duty_cycle_set(payload, pwm_duty_cycle);
2562 }
2563
2564 /* MFSM - Management Fan Speed Measurement
2565  * ---------------------------------------
2566  * This register controls the settings of the Tacho measurements and
2567  * enables reading the Tachometer measurements.
2568  */
2569 #define MLXSW_REG_MFSM_ID 0x9003
2570 #define MLXSW_REG_MFSM_LEN 0x08
2571
2572 static const struct mlxsw_reg_info mlxsw_reg_mfsm = {
2573         .id = MLXSW_REG_MFSM_ID,
2574         .len = MLXSW_REG_MFSM_LEN,
2575 };
2576
2577 /* reg_mfsm_tacho
2578  * Fan tachometer index.
2579  * Access: Index
2580  */
2581 MLXSW_ITEM32(reg, mfsm, tacho, 0x00, 24, 4);
2582
2583 /* reg_mfsm_rpm
2584  * Fan speed (round per minute).
2585  * Access: RO
2586  */
2587 MLXSW_ITEM32(reg, mfsm, rpm, 0x04, 0, 16);
2588
2589 static inline void mlxsw_reg_mfsm_pack(char *payload, u8 tacho)
2590 {
2591         MLXSW_REG_ZERO(mfsm, payload);
2592         mlxsw_reg_mfsm_tacho_set(payload, tacho);
2593 }
2594
2595 /* MTCAP - Management Temperature Capabilities
2596  * -------------------------------------------
2597  * This register exposes the capabilities of the device and
2598  * system temperature sensing.
2599  */
2600 #define MLXSW_REG_MTCAP_ID 0x9009
2601 #define MLXSW_REG_MTCAP_LEN 0x08
2602
2603 static const struct mlxsw_reg_info mlxsw_reg_mtcap = {
2604         .id = MLXSW_REG_MTCAP_ID,
2605         .len = MLXSW_REG_MTCAP_LEN,
2606 };
2607
2608 /* reg_mtcap_sensor_count
2609  * Number of sensors supported by the device.
2610  * This includes the QSFP module sensors (if exists in the QSFP module).
2611  * Access: RO
2612  */
2613 MLXSW_ITEM32(reg, mtcap, sensor_count, 0x00, 0, 7);
2614
2615 /* MTMP - Management Temperature
2616  * -----------------------------
2617  * This register controls the settings of the temperature measurements
2618  * and enables reading the temperature measurements. Note that temperature
2619  * is in 0.125 degrees Celsius.
2620  */
2621 #define MLXSW_REG_MTMP_ID 0x900A
2622 #define MLXSW_REG_MTMP_LEN 0x20
2623
2624 static const struct mlxsw_reg_info mlxsw_reg_mtmp = {
2625         .id = MLXSW_REG_MTMP_ID,
2626         .len = MLXSW_REG_MTMP_LEN,
2627 };
2628
2629 /* reg_mtmp_sensor_index
2630  * Sensors index to access.
2631  * 64-127 of sensor_index are mapped to the SFP+/QSFP modules sequentially
2632  * (module 0 is mapped to sensor_index 64).
2633  * Access: Index
2634  */
2635 MLXSW_ITEM32(reg, mtmp, sensor_index, 0x00, 0, 7);
2636
2637 /* Convert to milli degrees Celsius */
2638 #define MLXSW_REG_MTMP_TEMP_TO_MC(val) (val * 125)
2639
2640 /* reg_mtmp_temperature
2641  * Temperature reading from the sensor. Reading is in 0.125 Celsius
2642  * degrees units.
2643  * Access: RO
2644  */
2645 MLXSW_ITEM32(reg, mtmp, temperature, 0x04, 0, 16);
2646
2647 /* reg_mtmp_mte
2648  * Max Temperature Enable - enables measuring the max temperature on a sensor.
2649  * Access: RW
2650  */
2651 MLXSW_ITEM32(reg, mtmp, mte, 0x08, 31, 1);
2652
2653 /* reg_mtmp_mtr
2654  * Max Temperature Reset - clears the value of the max temperature register.
2655  * Access: WO
2656  */
2657 MLXSW_ITEM32(reg, mtmp, mtr, 0x08, 30, 1);
2658
2659 /* reg_mtmp_max_temperature
2660  * The highest measured temperature from the sensor.
2661  * When the bit mte is cleared, the field max_temperature is reserved.
2662  * Access: RO
2663  */
2664 MLXSW_ITEM32(reg, mtmp, max_temperature, 0x08, 0, 16);
2665
2666 #define MLXSW_REG_MTMP_SENSOR_NAME_SIZE 8
2667
2668 /* reg_mtmp_sensor_name
2669  * Sensor Name
2670  * Access: RO
2671  */
2672 MLXSW_ITEM_BUF(reg, mtmp, sensor_name, 0x18, MLXSW_REG_MTMP_SENSOR_NAME_SIZE);
2673
2674 static inline void mlxsw_reg_mtmp_pack(char *payload, u8 sensor_index,
2675                                        bool max_temp_enable,
2676                                        bool max_temp_reset)
2677 {
2678         MLXSW_REG_ZERO(mtmp, payload);
2679         mlxsw_reg_mtmp_sensor_index_set(payload, sensor_index);
2680         mlxsw_reg_mtmp_mte_set(payload, max_temp_enable);
2681         mlxsw_reg_mtmp_mtr_set(payload, max_temp_reset);
2682 }
2683
2684 static inline void mlxsw_reg_mtmp_unpack(char *payload, unsigned int *p_temp,
2685                                          unsigned int *p_max_temp,
2686                                          char *sensor_name)
2687 {
2688         u16 temp;
2689
2690         if (p_temp) {
2691                 temp = mlxsw_reg_mtmp_temperature_get(payload);
2692                 *p_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
2693         }
2694         if (p_max_temp) {
2695                 temp = mlxsw_reg_mtmp_max_temperature_get(payload);
2696                 *p_max_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
2697         }
2698         if (sensor_name)
2699                 mlxsw_reg_mtmp_sensor_name_memcpy_from(payload, sensor_name);
2700 }
2701
2702 /* MLCR - Management LED Control Register
2703  * --------------------------------------
2704  * Controls the system LEDs.
2705  */
2706 #define MLXSW_REG_MLCR_ID 0x902B
2707 #define MLXSW_REG_MLCR_LEN 0x0C
2708
2709 static const struct mlxsw_reg_info mlxsw_reg_mlcr = {
2710         .id = MLXSW_REG_MLCR_ID,
2711         .len = MLXSW_REG_MLCR_LEN,
2712 };
2713
2714 /* reg_mlcr_local_port
2715  * Local port number.
2716  * Access: RW
2717  */
2718 MLXSW_ITEM32(reg, mlcr, local_port, 0x00, 16, 8);
2719
2720 #define MLXSW_REG_MLCR_DURATION_MAX 0xFFFF
2721
2722 /* reg_mlcr_beacon_duration
2723  * Duration of the beacon to be active, in seconds.
2724  * 0x0 - Will turn off the beacon.
2725  * 0xFFFF - Will turn on the beacon until explicitly turned off.
2726  * Access: RW
2727  */
2728 MLXSW_ITEM32(reg, mlcr, beacon_duration, 0x04, 0, 16);
2729
2730 /* reg_mlcr_beacon_remain
2731  * Remaining duration of the beacon, in seconds.
2732  * 0xFFFF indicates an infinite amount of time.
2733  * Access: RO
2734  */
2735 MLXSW_ITEM32(reg, mlcr, beacon_remain, 0x08, 0, 16);
2736
2737 static inline void mlxsw_reg_mlcr_pack(char *payload, u8 local_port,
2738                                        bool active)
2739 {
2740         MLXSW_REG_ZERO(mlcr, payload);
2741         mlxsw_reg_mlcr_local_port_set(payload, local_port);
2742         mlxsw_reg_mlcr_beacon_duration_set(payload, active ?
2743                                            MLXSW_REG_MLCR_DURATION_MAX : 0);
2744 }
2745
2746 /* SBPR - Shared Buffer Pools Register
2747  * -----------------------------------
2748  * The SBPR configures and retrieves the shared buffer pools and configuration.
2749  */
2750 #define MLXSW_REG_SBPR_ID 0xB001
2751 #define MLXSW_REG_SBPR_LEN 0x14
2752
2753 static const struct mlxsw_reg_info mlxsw_reg_sbpr = {
2754         .id = MLXSW_REG_SBPR_ID,
2755         .len = MLXSW_REG_SBPR_LEN,
2756 };
2757
2758 enum mlxsw_reg_sbpr_dir {
2759         MLXSW_REG_SBPR_DIR_INGRESS,
2760         MLXSW_REG_SBPR_DIR_EGRESS,
2761 };
2762
2763 /* reg_sbpr_dir
2764  * Direction.
2765  * Access: Index
2766  */
2767 MLXSW_ITEM32(reg, sbpr, dir, 0x00, 24, 2);
2768
2769 /* reg_sbpr_pool
2770  * Pool index.
2771  * Access: Index
2772  */
2773 MLXSW_ITEM32(reg, sbpr, pool, 0x00, 0, 4);
2774
2775 /* reg_sbpr_size
2776  * Pool size in buffer cells.
2777  * Access: RW
2778  */
2779 MLXSW_ITEM32(reg, sbpr, size, 0x04, 0, 24);
2780
2781 enum mlxsw_reg_sbpr_mode {
2782         MLXSW_REG_SBPR_MODE_STATIC,
2783         MLXSW_REG_SBPR_MODE_DYNAMIC,
2784 };
2785
2786 /* reg_sbpr_mode
2787  * Pool quota calculation mode.
2788  * Access: RW
2789  */
2790 MLXSW_ITEM32(reg, sbpr, mode, 0x08, 0, 4);
2791
2792 static inline void mlxsw_reg_sbpr_pack(char *payload, u8 pool,
2793                                        enum mlxsw_reg_sbpr_dir dir,
2794                                        enum mlxsw_reg_sbpr_mode mode, u32 size)
2795 {
2796         MLXSW_REG_ZERO(sbpr, payload);
2797         mlxsw_reg_sbpr_pool_set(payload, pool);
2798         mlxsw_reg_sbpr_dir_set(payload, dir);
2799         mlxsw_reg_sbpr_mode_set(payload, mode);
2800         mlxsw_reg_sbpr_size_set(payload, size);
2801 }
2802
2803 /* SBCM - Shared Buffer Class Management Register
2804  * ----------------------------------------------
2805  * The SBCM register configures and retrieves the shared buffer allocation
2806  * and configuration according to Port-PG, including the binding to pool
2807  * and definition of the associated quota.
2808  */
2809 #define MLXSW_REG_SBCM_ID 0xB002
2810 #define MLXSW_REG_SBCM_LEN 0x28
2811
2812 static const struct mlxsw_reg_info mlxsw_reg_sbcm = {
2813         .id = MLXSW_REG_SBCM_ID,
2814         .len = MLXSW_REG_SBCM_LEN,
2815 };
2816
2817 /* reg_sbcm_local_port
2818  * Local port number.
2819  * For Ingress: excludes CPU port and Router port
2820  * For Egress: excludes IP Router
2821  * Access: Index
2822  */
2823 MLXSW_ITEM32(reg, sbcm, local_port, 0x00, 16, 8);
2824
2825 /* reg_sbcm_pg_buff
2826  * PG buffer - Port PG (dir=ingress) / traffic class (dir=egress)
2827  * For PG buffer: range is 0..cap_max_pg_buffers - 1
2828  * For traffic class: range is 0..cap_max_tclass - 1
2829  * Note that when traffic class is in MC aware mode then the traffic
2830  * classes which are MC aware cannot be configured.
2831  * Access: Index
2832  */
2833 MLXSW_ITEM32(reg, sbcm, pg_buff, 0x00, 8, 6);
2834
2835 enum mlxsw_reg_sbcm_dir {
2836         MLXSW_REG_SBCM_DIR_INGRESS,
2837         MLXSW_REG_SBCM_DIR_EGRESS,
2838 };
2839
2840 /* reg_sbcm_dir
2841  * Direction.
2842  * Access: Index
2843  */
2844 MLXSW_ITEM32(reg, sbcm, dir, 0x00, 0, 2);
2845
2846 /* reg_sbcm_min_buff
2847  * Minimum buffer size for the limiter, in cells.
2848  * Access: RW
2849  */
2850 MLXSW_ITEM32(reg, sbcm, min_buff, 0x18, 0, 24);
2851
2852 /* reg_sbcm_max_buff
2853  * When the pool associated to the port-pg/tclass is configured to
2854  * static, Maximum buffer size for the limiter configured in cells.
2855  * When the pool associated to the port-pg/tclass is configured to
2856  * dynamic, the max_buff holds the "alpha" parameter, supporting
2857  * the following values:
2858  * 0: 0
2859  * i: (1/128)*2^(i-1), for i=1..14
2860  * 0xFF: Infinity
2861  * Access: RW
2862  */
2863 MLXSW_ITEM32(reg, sbcm, max_buff, 0x1C, 0, 24);
2864
2865 /* reg_sbcm_pool
2866  * Association of the port-priority to a pool.
2867  * Access: RW
2868  */
2869 MLXSW_ITEM32(reg, sbcm, pool, 0x24, 0, 4);
2870
2871 static inline void mlxsw_reg_sbcm_pack(char *payload, u8 local_port, u8 pg_buff,
2872                                        enum mlxsw_reg_sbcm_dir dir,
2873                                        u32 min_buff, u32 max_buff, u8 pool)
2874 {
2875         MLXSW_REG_ZERO(sbcm, payload);
2876         mlxsw_reg_sbcm_local_port_set(payload, local_port);
2877         mlxsw_reg_sbcm_pg_buff_set(payload, pg_buff);
2878         mlxsw_reg_sbcm_dir_set(payload, dir);
2879         mlxsw_reg_sbcm_min_buff_set(payload, min_buff);
2880         mlxsw_reg_sbcm_max_buff_set(payload, max_buff);
2881         mlxsw_reg_sbcm_pool_set(payload, pool);
2882 }
2883
2884 /* SBPM - Shared Buffer Class Management Register
2885  * ----------------------------------------------
2886  * The SBPM register configures and retrieves the shared buffer allocation
2887  * and configuration according to Port-Pool, including the definition
2888  * of the associated quota.
2889  */
2890 #define MLXSW_REG_SBPM_ID 0xB003
2891 #define MLXSW_REG_SBPM_LEN 0x28
2892
2893 static const struct mlxsw_reg_info mlxsw_reg_sbpm = {
2894         .id = MLXSW_REG_SBPM_ID,
2895         .len = MLXSW_REG_SBPM_LEN,
2896 };
2897
2898 /* reg_sbpm_local_port
2899  * Local port number.
2900  * For Ingress: excludes CPU port and Router port
2901  * For Egress: excludes IP Router
2902  * Access: Index
2903  */
2904 MLXSW_ITEM32(reg, sbpm, local_port, 0x00, 16, 8);
2905
2906 /* reg_sbpm_pool
2907  * The pool associated to quota counting on the local_port.
2908  * Access: Index
2909  */
2910 MLXSW_ITEM32(reg, sbpm, pool, 0x00, 8, 4);
2911
2912 enum mlxsw_reg_sbpm_dir {
2913         MLXSW_REG_SBPM_DIR_INGRESS,
2914         MLXSW_REG_SBPM_DIR_EGRESS,
2915 };
2916
2917 /* reg_sbpm_dir
2918  * Direction.
2919  * Access: Index
2920  */
2921 MLXSW_ITEM32(reg, sbpm, dir, 0x00, 0, 2);
2922
2923 /* reg_sbpm_min_buff
2924  * Minimum buffer size for the limiter, in cells.
2925  * Access: RW
2926  */
2927 MLXSW_ITEM32(reg, sbpm, min_buff, 0x18, 0, 24);
2928
2929 /* reg_sbpm_max_buff
2930  * When the pool associated to the port-pg/tclass is configured to
2931  * static, Maximum buffer size for the limiter configured in cells.
2932  * When the pool associated to the port-pg/tclass is configured to
2933  * dynamic, the max_buff holds the "alpha" parameter, supporting
2934  * the following values:
2935  * 0: 0
2936  * i: (1/128)*2^(i-1), for i=1..14
2937  * 0xFF: Infinity
2938  * Access: RW
2939  */
2940 MLXSW_ITEM32(reg, sbpm, max_buff, 0x1C, 0, 24);
2941
2942 static inline void mlxsw_reg_sbpm_pack(char *payload, u8 local_port, u8 pool,
2943                                        enum mlxsw_reg_sbpm_dir dir,
2944                                        u32 min_buff, u32 max_buff)
2945 {
2946         MLXSW_REG_ZERO(sbpm, payload);
2947         mlxsw_reg_sbpm_local_port_set(payload, local_port);
2948         mlxsw_reg_sbpm_pool_set(payload, pool);
2949         mlxsw_reg_sbpm_dir_set(payload, dir);
2950         mlxsw_reg_sbpm_min_buff_set(payload, min_buff);
2951         mlxsw_reg_sbpm_max_buff_set(payload, max_buff);
2952 }
2953
2954 /* SBMM - Shared Buffer Multicast Management Register
2955  * --------------------------------------------------
2956  * The SBMM register configures and retrieves the shared buffer allocation
2957  * and configuration for MC packets according to Switch-Priority, including
2958  * the binding to pool and definition of the associated quota.
2959  */
2960 #define MLXSW_REG_SBMM_ID 0xB004
2961 #define MLXSW_REG_SBMM_LEN 0x28
2962
2963 static const struct mlxsw_reg_info mlxsw_reg_sbmm = {
2964         .id = MLXSW_REG_SBMM_ID,
2965         .len = MLXSW_REG_SBMM_LEN,
2966 };
2967
2968 /* reg_sbmm_prio
2969  * Switch Priority.
2970  * Access: Index
2971  */
2972 MLXSW_ITEM32(reg, sbmm, prio, 0x00, 8, 4);
2973
2974 /* reg_sbmm_min_buff
2975  * Minimum buffer size for the limiter, in cells.
2976  * Access: RW
2977  */
2978 MLXSW_ITEM32(reg, sbmm, min_buff, 0x18, 0, 24);
2979
2980 /* reg_sbmm_max_buff
2981  * When the pool associated to the port-pg/tclass is configured to
2982  * static, Maximum buffer size for the limiter configured in cells.
2983  * When the pool associated to the port-pg/tclass is configured to
2984  * dynamic, the max_buff holds the "alpha" parameter, supporting
2985  * the following values:
2986  * 0: 0
2987  * i: (1/128)*2^(i-1), for i=1..14
2988  * 0xFF: Infinity
2989  * Access: RW
2990  */
2991 MLXSW_ITEM32(reg, sbmm, max_buff, 0x1C, 0, 24);
2992
2993 /* reg_sbmm_pool
2994  * Association of the port-priority to a pool.
2995  * Access: RW
2996  */
2997 MLXSW_ITEM32(reg, sbmm, pool, 0x24, 0, 4);
2998
2999 static inline void mlxsw_reg_sbmm_pack(char *payload, u8 prio, u32 min_buff,
3000                                        u32 max_buff, u8 pool)
3001 {
3002         MLXSW_REG_ZERO(sbmm, payload);
3003         mlxsw_reg_sbmm_prio_set(payload, prio);
3004         mlxsw_reg_sbmm_min_buff_set(payload, min_buff);
3005         mlxsw_reg_sbmm_max_buff_set(payload, max_buff);
3006         mlxsw_reg_sbmm_pool_set(payload, pool);
3007 }
3008
3009 static inline const char *mlxsw_reg_id_str(u16 reg_id)
3010 {
3011         switch (reg_id) {
3012         case MLXSW_REG_SGCR_ID:
3013                 return "SGCR";
3014         case MLXSW_REG_SPAD_ID:
3015                 return "SPAD";
3016         case MLXSW_REG_SSPR_ID:
3017                 return "SSPR";
3018         case MLXSW_REG_SFDAT_ID:
3019                 return "SFDAT";
3020         case MLXSW_REG_SFD_ID:
3021                 return "SFD";
3022         case MLXSW_REG_SFN_ID:
3023                 return "SFN";
3024         case MLXSW_REG_SPMS_ID:
3025                 return "SPMS";
3026         case MLXSW_REG_SPVID_ID:
3027                 return "SPVID";
3028         case MLXSW_REG_SPVM_ID:
3029                 return "SPVM";
3030         case MLXSW_REG_SFGC_ID:
3031                 return "SFGC";
3032         case MLXSW_REG_SFTR_ID:
3033                 return "SFTR";
3034         case MLXSW_REG_SLDR_ID:
3035                 return "SLDR";
3036         case MLXSW_REG_SLCR_ID:
3037                 return "SLCR";
3038         case MLXSW_REG_SLCOR_ID:
3039                 return "SLCOR";
3040         case MLXSW_REG_SPMLR_ID:
3041                 return "SPMLR";
3042         case MLXSW_REG_SVFA_ID:
3043                 return "SVFA";
3044         case MLXSW_REG_SVPE_ID:
3045                 return "SVPE";
3046         case MLXSW_REG_SFMR_ID:
3047                 return "SFMR";
3048         case MLXSW_REG_SPVMLR_ID:
3049                 return "SPVMLR";
3050         case MLXSW_REG_PMLP_ID:
3051                 return "PMLP";
3052         case MLXSW_REG_PMTU_ID:
3053                 return "PMTU";
3054         case MLXSW_REG_PTYS_ID:
3055                 return "PTYS";
3056         case MLXSW_REG_PPAD_ID:
3057                 return "PPAD";
3058         case MLXSW_REG_PAOS_ID:
3059                 return "PAOS";
3060         case MLXSW_REG_PPCNT_ID:
3061                 return "PPCNT";
3062         case MLXSW_REG_PBMC_ID:
3063                 return "PBMC";
3064         case MLXSW_REG_PSPA_ID:
3065                 return "PSPA";
3066         case MLXSW_REG_HTGT_ID:
3067                 return "HTGT";
3068         case MLXSW_REG_HPKT_ID:
3069                 return "HPKT";
3070         case MLXSW_REG_MFCR_ID:
3071                 return "MFCR";
3072         case MLXSW_REG_MFSC_ID:
3073                 return "MFSC";
3074         case MLXSW_REG_MFSM_ID:
3075                 return "MFSM";
3076         case MLXSW_REG_MTCAP_ID:
3077                 return "MTCAP";
3078         case MLXSW_REG_MTMP_ID:
3079                 return "MTMP";
3080         case MLXSW_REG_MLCR_ID:
3081                 return "MLCR";
3082         case MLXSW_REG_SBPR_ID:
3083                 return "SBPR";
3084         case MLXSW_REG_SBCM_ID:
3085                 return "SBCM";
3086         case MLXSW_REG_SBPM_ID:
3087                 return "SBPM";
3088         case MLXSW_REG_SBMM_ID:
3089                 return "SBMM";
3090         default:
3091                 return "*UNKNOWN*";
3092         }
3093 }
3094
3095 /* PUDE - Port Up / Down Event
3096  * ---------------------------
3097  * Reports the operational state change of a port.
3098  */
3099 #define MLXSW_REG_PUDE_LEN 0x10
3100
3101 /* reg_pude_swid
3102  * Switch partition ID with which to associate the port.
3103  * Access: Index
3104  */
3105 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
3106
3107 /* reg_pude_local_port
3108  * Local port number.
3109  * Access: Index
3110  */
3111 MLXSW_ITEM32(reg, pude, local_port, 0x00, 16, 8);
3112
3113 /* reg_pude_admin_status
3114  * Port administrative state (the desired state).
3115  * 1 - Up.
3116  * 2 - Down.
3117  * 3 - Up once. This means that in case of link failure, the port won't go
3118  *     into polling mode, but will wait to be re-enabled by software.
3119  * 4 - Disabled by system. Can only be set by hardware.
3120  * Access: RO
3121  */
3122 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
3123
3124 /* reg_pude_oper_status
3125  * Port operatioanl state.
3126  * 1 - Up.
3127  * 2 - Down.
3128  * 3 - Down by port failure. This means that the device will not let the
3129  *     port up again until explicitly specified by software.
3130  * Access: RO
3131  */
3132 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);
3133
3134 #endif