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