2 * drivers/net/ethernet/mellanox/mlxsw/reg.h
3 * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
5 * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
6 * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
40 #include <linux/string.h>
41 #include <linux/bitops.h>
42 #include <linux/if_vlan.h>
47 struct mlxsw_reg_info {
52 #define MLXSW_REG(type) (&mlxsw_reg_##type)
53 #define MLXSW_REG_LEN(type) MLXSW_REG(type)->len
54 #define MLXSW_REG_ZERO(type, payload) memset(payload, 0, MLXSW_REG(type)->len)
56 /* SGCR - Switch General Configuration Register
57 * --------------------------------------------
58 * This register is used for configuration of the switch capabilities.
60 #define MLXSW_REG_SGCR_ID 0x2000
61 #define MLXSW_REG_SGCR_LEN 0x10
63 static const struct mlxsw_reg_info mlxsw_reg_sgcr = {
64 .id = MLXSW_REG_SGCR_ID,
65 .len = MLXSW_REG_SGCR_LEN,
69 * Link Local Broadcast (Default=0)
70 * When set, all Link Local packets (224.0.0.X) will be treated as broadcast
71 * packets and ignore the IGMP snooping entries.
74 MLXSW_ITEM32(reg, sgcr, llb, 0x04, 0, 1);
76 static inline void mlxsw_reg_sgcr_pack(char *payload, bool llb)
78 MLXSW_REG_ZERO(sgcr, payload);
79 mlxsw_reg_sgcr_llb_set(payload, !!llb);
82 /* SPAD - Switch Physical Address Register
83 * ---------------------------------------
84 * The SPAD register configures the switch physical MAC address.
86 #define MLXSW_REG_SPAD_ID 0x2002
87 #define MLXSW_REG_SPAD_LEN 0x10
89 static const struct mlxsw_reg_info mlxsw_reg_spad = {
90 .id = MLXSW_REG_SPAD_ID,
91 .len = MLXSW_REG_SPAD_LEN,
95 * Base MAC address for the switch partitions.
96 * Per switch partition MAC address is equal to:
100 MLXSW_ITEM_BUF(reg, spad, base_mac, 0x02, 6);
102 /* SSPR - Switch System Port Record Register
103 * -----------------------------------------
104 * Configures the system port to local port mapping.
106 #define MLXSW_REG_SSPR_ID 0x2008
107 #define MLXSW_REG_SSPR_LEN 0x8
109 static const struct mlxsw_reg_info mlxsw_reg_sspr = {
110 .id = MLXSW_REG_SSPR_ID,
111 .len = MLXSW_REG_SSPR_LEN,
115 * Master - if set, then the record describes the master system port.
116 * This is needed in case a local port is mapped into several system ports
117 * (for multipathing). That number will be reported as the source system
118 * port when packets are forwarded to the CPU. Only one master port is allowed
121 * Note: Must be set for Spectrum.
124 MLXSW_ITEM32(reg, sspr, m, 0x00, 31, 1);
126 /* reg_sspr_local_port
131 MLXSW_ITEM32(reg, sspr, local_port, 0x00, 16, 8);
134 * Virtual port within the physical port.
135 * Should be set to 0 when virtual ports are not enabled on the port.
139 MLXSW_ITEM32(reg, sspr, sub_port, 0x00, 8, 8);
141 /* reg_sspr_system_port
142 * Unique identifier within the stacking domain that represents all the ports
143 * that are available in the system (external ports).
145 * Currently, only single-ASIC configurations are supported, so we default to
146 * 1:1 mapping between system ports and local ports.
149 MLXSW_ITEM32(reg, sspr, system_port, 0x04, 0, 16);
151 static inline void mlxsw_reg_sspr_pack(char *payload, u8 local_port)
153 MLXSW_REG_ZERO(sspr, payload);
154 mlxsw_reg_sspr_m_set(payload, 1);
155 mlxsw_reg_sspr_local_port_set(payload, local_port);
156 mlxsw_reg_sspr_sub_port_set(payload, 0);
157 mlxsw_reg_sspr_system_port_set(payload, local_port);
160 /* SFDAT - Switch Filtering Database Aging Time
161 * --------------------------------------------
162 * Controls the Switch aging time. Aging time is able to be set per Switch
165 #define MLXSW_REG_SFDAT_ID 0x2009
166 #define MLXSW_REG_SFDAT_LEN 0x8
168 static const struct mlxsw_reg_info mlxsw_reg_sfdat = {
169 .id = MLXSW_REG_SFDAT_ID,
170 .len = MLXSW_REG_SFDAT_LEN,
174 * Switch partition ID.
177 MLXSW_ITEM32(reg, sfdat, swid, 0x00, 24, 8);
179 /* reg_sfdat_age_time
180 * Aging time in seconds
182 * Max - 1,000,000 seconds
183 * Default is 300 seconds.
186 MLXSW_ITEM32(reg, sfdat, age_time, 0x04, 0, 20);
188 static inline void mlxsw_reg_sfdat_pack(char *payload, u32 age_time)
190 MLXSW_REG_ZERO(sfdat, payload);
191 mlxsw_reg_sfdat_swid_set(payload, 0);
192 mlxsw_reg_sfdat_age_time_set(payload, age_time);
195 /* SFD - Switch Filtering Database
196 * -------------------------------
197 * The following register defines the access to the filtering database.
198 * The register supports querying, adding, removing and modifying the database.
199 * The access is optimized for bulk updates in which case more than one
200 * FDB record is present in the same command.
202 #define MLXSW_REG_SFD_ID 0x200A
203 #define MLXSW_REG_SFD_BASE_LEN 0x10 /* base length, without records */
204 #define MLXSW_REG_SFD_REC_LEN 0x10 /* record length */
205 #define MLXSW_REG_SFD_REC_MAX_COUNT 64
206 #define MLXSW_REG_SFD_LEN (MLXSW_REG_SFD_BASE_LEN + \
207 MLXSW_REG_SFD_REC_LEN * MLXSW_REG_SFD_REC_MAX_COUNT)
209 static const struct mlxsw_reg_info mlxsw_reg_sfd = {
210 .id = MLXSW_REG_SFD_ID,
211 .len = MLXSW_REG_SFD_LEN,
215 * Switch partition ID for queries. Reserved on Write.
218 MLXSW_ITEM32(reg, sfd, swid, 0x00, 24, 8);
220 enum mlxsw_reg_sfd_op {
221 /* Dump entire FDB a (process according to record_locator) */
222 MLXSW_REG_SFD_OP_QUERY_DUMP = 0,
223 /* Query records by {MAC, VID/FID} value */
224 MLXSW_REG_SFD_OP_QUERY_QUERY = 1,
225 /* Query and clear activity. Query records by {MAC, VID/FID} value */
226 MLXSW_REG_SFD_OP_QUERY_QUERY_AND_CLEAR_ACTIVITY = 2,
227 /* Test. Response indicates if each of the records could be
230 MLXSW_REG_SFD_OP_WRITE_TEST = 0,
231 /* Add/modify. Aged-out records cannot be added. This command removes
232 * the learning notification of the {MAC, VID/FID}. Response includes
233 * the entries that were added to the FDB.
235 MLXSW_REG_SFD_OP_WRITE_EDIT = 1,
236 /* Remove record by {MAC, VID/FID}. This command also removes
237 * the learning notification and aged-out notifications
238 * of the {MAC, VID/FID}. The response provides current (pre-removal)
239 * entries as non-aged-out.
241 MLXSW_REG_SFD_OP_WRITE_REMOVE = 2,
242 /* Remove learned notification by {MAC, VID/FID}. The response provides
243 * the removed learning notification.
245 MLXSW_REG_SFD_OP_WRITE_REMOVE_NOTIFICATION = 2,
252 MLXSW_ITEM32(reg, sfd, op, 0x04, 30, 2);
254 /* reg_sfd_record_locator
255 * Used for querying the FDB. Use record_locator=0 to initiate the
256 * query. When a record is returned, a new record_locator is
257 * returned to be used in the subsequent query.
258 * Reserved for database update.
261 MLXSW_ITEM32(reg, sfd, record_locator, 0x04, 0, 30);
264 * Request: Number of records to read/add/modify/remove
265 * Response: Number of records read/added/replaced/removed
266 * See above description for more details.
270 MLXSW_ITEM32(reg, sfd, num_rec, 0x08, 0, 8);
272 static inline void mlxsw_reg_sfd_pack(char *payload, enum mlxsw_reg_sfd_op op,
275 MLXSW_REG_ZERO(sfd, payload);
276 mlxsw_reg_sfd_op_set(payload, op);
277 mlxsw_reg_sfd_record_locator_set(payload, record_locator);
281 * Switch partition ID.
284 MLXSW_ITEM32_INDEXED(reg, sfd, rec_swid, MLXSW_REG_SFD_BASE_LEN, 24, 8,
285 MLXSW_REG_SFD_REC_LEN, 0x00, false);
287 enum mlxsw_reg_sfd_rec_type {
288 MLXSW_REG_SFD_REC_TYPE_UNICAST = 0x0,
289 MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG = 0x1,
296 MLXSW_ITEM32_INDEXED(reg, sfd, rec_type, MLXSW_REG_SFD_BASE_LEN, 20, 4,
297 MLXSW_REG_SFD_REC_LEN, 0x00, false);
299 enum mlxsw_reg_sfd_rec_policy {
300 /* Replacement disabled, aging disabled. */
301 MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY = 0,
302 /* (mlag remote): Replacement enabled, aging disabled,
303 * learning notification enabled on this port.
305 MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_MLAG = 1,
306 /* (ingress device): Replacement enabled, aging enabled. */
307 MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS = 3,
310 /* reg_sfd_rec_policy
314 MLXSW_ITEM32_INDEXED(reg, sfd, rec_policy, MLXSW_REG_SFD_BASE_LEN, 18, 2,
315 MLXSW_REG_SFD_REC_LEN, 0x00, false);
318 * Activity. Set for new static entries. Set for static entries if a frame SMAC
319 * lookup hits on the entry.
320 * To clear the a bit, use "query and clear activity" op.
323 MLXSW_ITEM32_INDEXED(reg, sfd, rec_a, MLXSW_REG_SFD_BASE_LEN, 16, 1,
324 MLXSW_REG_SFD_REC_LEN, 0x00, false);
330 MLXSW_ITEM_BUF_INDEXED(reg, sfd, rec_mac, MLXSW_REG_SFD_BASE_LEN, 6,
331 MLXSW_REG_SFD_REC_LEN, 0x02);
333 enum mlxsw_reg_sfd_rec_action {
335 MLXSW_REG_SFD_REC_ACTION_NOP = 0,
336 /* forward and trap, trap_id is FDB_TRAP */
337 MLXSW_REG_SFD_REC_ACTION_MIRROR_TO_CPU = 1,
338 /* trap and do not forward, trap_id is FDB_TRAP */
339 MLXSW_REG_SFD_REC_ACTION_TRAP = 3,
340 MLXSW_REG_SFD_REC_ACTION_DISCARD_ERROR = 15,
343 /* reg_sfd_rec_action
344 * Action to apply on the packet.
345 * Note: Dynamic entries can only be configured with NOP action.
348 MLXSW_ITEM32_INDEXED(reg, sfd, rec_action, MLXSW_REG_SFD_BASE_LEN, 28, 4,
349 MLXSW_REG_SFD_REC_LEN, 0x0C, false);
351 /* reg_sfd_uc_sub_port
352 * VEPA channel on local port.
353 * Valid only if local port is a non-stacking port. Must be 0 if multichannel
354 * VEPA is not enabled.
357 MLXSW_ITEM32_INDEXED(reg, sfd, uc_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
358 MLXSW_REG_SFD_REC_LEN, 0x08, false);
360 /* reg_sfd_uc_fid_vid
361 * Filtering ID or VLAN ID
362 * For SwitchX and SwitchX-2:
363 * - Dynamic entries (policy 2,3) use FID
364 * - Static entries (policy 0) use VID
365 * - When independent learning is configured, VID=FID
366 * For Spectrum: use FID for both Dynamic and Static entries.
367 * VID should not be used.
370 MLXSW_ITEM32_INDEXED(reg, sfd, uc_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
371 MLXSW_REG_SFD_REC_LEN, 0x08, false);
373 /* reg_sfd_uc_system_port
374 * Unique port identifier for the final destination of the packet.
377 MLXSW_ITEM32_INDEXED(reg, sfd, uc_system_port, MLXSW_REG_SFD_BASE_LEN, 0, 16,
378 MLXSW_REG_SFD_REC_LEN, 0x0C, false);
380 static inline void mlxsw_reg_sfd_rec_pack(char *payload, int rec_index,
381 enum mlxsw_reg_sfd_rec_type rec_type,
382 enum mlxsw_reg_sfd_rec_policy policy,
384 enum mlxsw_reg_sfd_rec_action action)
386 u8 num_rec = mlxsw_reg_sfd_num_rec_get(payload);
388 if (rec_index >= num_rec)
389 mlxsw_reg_sfd_num_rec_set(payload, rec_index + 1);
390 mlxsw_reg_sfd_rec_swid_set(payload, rec_index, 0);
391 mlxsw_reg_sfd_rec_type_set(payload, rec_index, rec_type);
392 mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
393 mlxsw_reg_sfd_rec_mac_memcpy_to(payload, rec_index, mac);
394 mlxsw_reg_sfd_rec_action_set(payload, rec_index, action);
397 static inline void mlxsw_reg_sfd_uc_pack(char *payload, int rec_index,
398 enum mlxsw_reg_sfd_rec_policy policy,
399 const char *mac, u16 fid_vid,
400 enum mlxsw_reg_sfd_rec_action action,
403 mlxsw_reg_sfd_rec_pack(payload, rec_index,
404 MLXSW_REG_SFD_REC_TYPE_UNICAST,
405 policy, mac, action);
406 mlxsw_reg_sfd_uc_sub_port_set(payload, rec_index, 0);
407 mlxsw_reg_sfd_uc_fid_vid_set(payload, rec_index, fid_vid);
408 mlxsw_reg_sfd_uc_system_port_set(payload, rec_index, local_port);
411 static inline void mlxsw_reg_sfd_uc_unpack(char *payload, int rec_index,
412 char *mac, u16 *p_fid_vid,
415 mlxsw_reg_sfd_rec_mac_memcpy_from(payload, rec_index, mac);
416 *p_fid_vid = mlxsw_reg_sfd_uc_fid_vid_get(payload, rec_index);
417 *p_local_port = mlxsw_reg_sfd_uc_system_port_get(payload, rec_index);
420 /* reg_sfd_uc_lag_sub_port
422 * Must be 0 if multichannel VEPA is not enabled.
425 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
426 MLXSW_REG_SFD_REC_LEN, 0x08, false);
428 /* reg_sfd_uc_lag_fid_vid
429 * Filtering ID or VLAN ID
430 * For SwitchX and SwitchX-2:
431 * - Dynamic entries (policy 2,3) use FID
432 * - Static entries (policy 0) use VID
433 * - When independent learning is configured, VID=FID
434 * For Spectrum: use FID for both Dynamic and Static entries.
435 * VID should not be used.
438 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
439 MLXSW_REG_SFD_REC_LEN, 0x08, false);
441 /* reg_sfd_uc_lag_lag_vid
442 * Indicates VID in case of vFIDs. Reserved for FIDs.
445 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_lag_vid, MLXSW_REG_SFD_BASE_LEN, 16, 12,
446 MLXSW_REG_SFD_REC_LEN, 0x0C, false);
448 /* reg_sfd_uc_lag_lag_id
449 * LAG Identifier - pointer into the LAG descriptor table.
452 MLXSW_ITEM32_INDEXED(reg, sfd, uc_lag_lag_id, MLXSW_REG_SFD_BASE_LEN, 0, 10,
453 MLXSW_REG_SFD_REC_LEN, 0x0C, false);
456 mlxsw_reg_sfd_uc_lag_pack(char *payload, int rec_index,
457 enum mlxsw_reg_sfd_rec_policy policy,
458 const char *mac, u16 fid_vid,
459 enum mlxsw_reg_sfd_rec_action action, u16 lag_vid,
462 mlxsw_reg_sfd_rec_pack(payload, rec_index,
463 MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG,
464 policy, mac, action);
465 mlxsw_reg_sfd_uc_lag_sub_port_set(payload, rec_index, 0);
466 mlxsw_reg_sfd_uc_lag_fid_vid_set(payload, rec_index, fid_vid);
467 mlxsw_reg_sfd_uc_lag_lag_vid_set(payload, rec_index, lag_vid);
468 mlxsw_reg_sfd_uc_lag_lag_id_set(payload, rec_index, lag_id);
471 static inline void mlxsw_reg_sfd_uc_lag_unpack(char *payload, int rec_index,
472 char *mac, u16 *p_vid,
475 mlxsw_reg_sfd_rec_mac_memcpy_from(payload, rec_index, mac);
476 *p_vid = mlxsw_reg_sfd_uc_lag_fid_vid_get(payload, rec_index);
477 *p_lag_id = mlxsw_reg_sfd_uc_lag_lag_id_get(payload, rec_index);
480 /* SFN - Switch FDB Notification Register
481 * -------------------------------------------
482 * The switch provides notifications on newly learned FDB entries and
483 * aged out entries. The notifications can be polled by software.
485 #define MLXSW_REG_SFN_ID 0x200B
486 #define MLXSW_REG_SFN_BASE_LEN 0x10 /* base length, without records */
487 #define MLXSW_REG_SFN_REC_LEN 0x10 /* record length */
488 #define MLXSW_REG_SFN_REC_MAX_COUNT 64
489 #define MLXSW_REG_SFN_LEN (MLXSW_REG_SFN_BASE_LEN + \
490 MLXSW_REG_SFN_REC_LEN * MLXSW_REG_SFN_REC_MAX_COUNT)
492 static const struct mlxsw_reg_info mlxsw_reg_sfn = {
493 .id = MLXSW_REG_SFN_ID,
494 .len = MLXSW_REG_SFN_LEN,
498 * Switch partition ID.
501 MLXSW_ITEM32(reg, sfn, swid, 0x00, 24, 8);
504 * Request: Number of learned notifications and aged-out notification
506 * Response: Number of notification records returned (must be smaller
507 * than or equal to the value requested)
511 MLXSW_ITEM32(reg, sfn, num_rec, 0x04, 0, 8);
513 static inline void mlxsw_reg_sfn_pack(char *payload)
515 MLXSW_REG_ZERO(sfn, payload);
516 mlxsw_reg_sfn_swid_set(payload, 0);
517 mlxsw_reg_sfn_num_rec_set(payload, MLXSW_REG_SFN_REC_MAX_COUNT);
521 * Switch partition ID.
524 MLXSW_ITEM32_INDEXED(reg, sfn, rec_swid, MLXSW_REG_SFN_BASE_LEN, 24, 8,
525 MLXSW_REG_SFN_REC_LEN, 0x00, false);
527 enum mlxsw_reg_sfn_rec_type {
528 /* MAC addresses learned on a regular port. */
529 MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC = 0x5,
530 /* MAC addresses learned on a LAG port. */
531 MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG = 0x6,
532 /* Aged-out MAC address on a regular port. */
533 MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC = 0x7,
534 /* Aged-out MAC address on a LAG port. */
535 MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG = 0x8,
539 * Notification record type.
542 MLXSW_ITEM32_INDEXED(reg, sfn, rec_type, MLXSW_REG_SFN_BASE_LEN, 20, 4,
543 MLXSW_REG_SFN_REC_LEN, 0x00, false);
549 MLXSW_ITEM_BUF_INDEXED(reg, sfn, rec_mac, MLXSW_REG_SFN_BASE_LEN, 6,
550 MLXSW_REG_SFN_REC_LEN, 0x02);
552 /* reg_sfn_mac_sub_port
553 * VEPA channel on the local port.
554 * 0 if multichannel VEPA is not enabled.
557 MLXSW_ITEM32_INDEXED(reg, sfn, mac_sub_port, MLXSW_REG_SFN_BASE_LEN, 16, 8,
558 MLXSW_REG_SFN_REC_LEN, 0x08, false);
561 * Filtering identifier.
564 MLXSW_ITEM32_INDEXED(reg, sfn, mac_fid, MLXSW_REG_SFN_BASE_LEN, 0, 16,
565 MLXSW_REG_SFN_REC_LEN, 0x08, false);
567 /* reg_sfn_mac_system_port
568 * Unique port identifier for the final destination of the packet.
571 MLXSW_ITEM32_INDEXED(reg, sfn, mac_system_port, MLXSW_REG_SFN_BASE_LEN, 0, 16,
572 MLXSW_REG_SFN_REC_LEN, 0x0C, false);
574 static inline void mlxsw_reg_sfn_mac_unpack(char *payload, int rec_index,
575 char *mac, u16 *p_vid,
578 mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
579 *p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
580 *p_local_port = mlxsw_reg_sfn_mac_system_port_get(payload, rec_index);
583 /* reg_sfn_mac_lag_lag_id
584 * LAG ID (pointer into the LAG descriptor table).
587 MLXSW_ITEM32_INDEXED(reg, sfn, mac_lag_lag_id, MLXSW_REG_SFN_BASE_LEN, 0, 10,
588 MLXSW_REG_SFN_REC_LEN, 0x0C, false);
590 static inline void mlxsw_reg_sfn_mac_lag_unpack(char *payload, int rec_index,
591 char *mac, u16 *p_vid,
594 mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
595 *p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
596 *p_lag_id = mlxsw_reg_sfn_mac_lag_lag_id_get(payload, rec_index);
599 /* SPMS - Switch Port MSTP/RSTP State Register
600 * -------------------------------------------
601 * Configures the spanning tree state of a physical port.
603 #define MLXSW_REG_SPMS_ID 0x200D
604 #define MLXSW_REG_SPMS_LEN 0x404
606 static const struct mlxsw_reg_info mlxsw_reg_spms = {
607 .id = MLXSW_REG_SPMS_ID,
608 .len = MLXSW_REG_SPMS_LEN,
611 /* reg_spms_local_port
615 MLXSW_ITEM32(reg, spms, local_port, 0x00, 16, 8);
617 enum mlxsw_reg_spms_state {
618 MLXSW_REG_SPMS_STATE_NO_CHANGE,
619 MLXSW_REG_SPMS_STATE_DISCARDING,
620 MLXSW_REG_SPMS_STATE_LEARNING,
621 MLXSW_REG_SPMS_STATE_FORWARDING,
625 * Spanning tree state of each VLAN ID (VID) of the local port.
626 * 0 - Do not change spanning tree state (used only when writing).
627 * 1 - Discarding. No learning or forwarding to/from this port (default).
628 * 2 - Learning. Port is learning, but not forwarding.
629 * 3 - Forwarding. Port is learning and forwarding.
632 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
634 static inline void mlxsw_reg_spms_pack(char *payload, u8 local_port)
636 MLXSW_REG_ZERO(spms, payload);
637 mlxsw_reg_spms_local_port_set(payload, local_port);
640 static inline void mlxsw_reg_spms_vid_pack(char *payload, u16 vid,
641 enum mlxsw_reg_spms_state state)
643 mlxsw_reg_spms_state_set(payload, vid, state);
646 /* SPVID - Switch Port VID
647 * -----------------------
648 * The switch port VID configures the default VID for a port.
650 #define MLXSW_REG_SPVID_ID 0x200E
651 #define MLXSW_REG_SPVID_LEN 0x08
653 static const struct mlxsw_reg_info mlxsw_reg_spvid = {
654 .id = MLXSW_REG_SPVID_ID,
655 .len = MLXSW_REG_SPVID_LEN,
658 /* reg_spvid_local_port
662 MLXSW_ITEM32(reg, spvid, local_port, 0x00, 16, 8);
664 /* reg_spvid_sub_port
665 * Virtual port within the physical port.
666 * Should be set to 0 when virtual ports are not enabled on the port.
669 MLXSW_ITEM32(reg, spvid, sub_port, 0x00, 8, 8);
675 MLXSW_ITEM32(reg, spvid, pvid, 0x04, 0, 12);
677 static inline void mlxsw_reg_spvid_pack(char *payload, u8 local_port, u16 pvid)
679 MLXSW_REG_ZERO(spvid, payload);
680 mlxsw_reg_spvid_local_port_set(payload, local_port);
681 mlxsw_reg_spvid_pvid_set(payload, pvid);
684 /* SPVM - Switch Port VLAN Membership
685 * ----------------------------------
686 * The Switch Port VLAN Membership register configures the VLAN membership
687 * of a port in a VLAN denoted by VID. VLAN membership is managed per
688 * virtual port. The register can be used to add and remove VID(s) from a port.
690 #define MLXSW_REG_SPVM_ID 0x200F
691 #define MLXSW_REG_SPVM_BASE_LEN 0x04 /* base length, without records */
692 #define MLXSW_REG_SPVM_REC_LEN 0x04 /* record length */
693 #define MLXSW_REG_SPVM_REC_MAX_COUNT 256
694 #define MLXSW_REG_SPVM_LEN (MLXSW_REG_SPVM_BASE_LEN + \
695 MLXSW_REG_SPVM_REC_LEN * MLXSW_REG_SPVM_REC_MAX_COUNT)
697 static const struct mlxsw_reg_info mlxsw_reg_spvm = {
698 .id = MLXSW_REG_SPVM_ID,
699 .len = MLXSW_REG_SPVM_LEN,
703 * Priority tagged. If this bit is set, packets forwarded to the port with
704 * untagged VLAN membership (u bit is set) will be tagged with priority tag
708 MLXSW_ITEM32(reg, spvm, pt, 0x00, 31, 1);
711 * Priority Tagged Update Enable. On Write operations, if this bit is cleared,
712 * the pt bit will NOT be updated. To update the pt bit, pte must be set.
715 MLXSW_ITEM32(reg, spvm, pte, 0x00, 30, 1);
717 /* reg_spvm_local_port
721 MLXSW_ITEM32(reg, spvm, local_port, 0x00, 16, 8);
724 * Virtual port within the physical port.
725 * Should be set to 0 when virtual ports are not enabled on the port.
728 MLXSW_ITEM32(reg, spvm, sub_port, 0x00, 8, 8);
731 * Number of records to update. Each record contains: i, e, u, vid.
734 MLXSW_ITEM32(reg, spvm, num_rec, 0x00, 0, 8);
737 * Ingress membership in VLAN ID.
740 MLXSW_ITEM32_INDEXED(reg, spvm, rec_i,
741 MLXSW_REG_SPVM_BASE_LEN, 14, 1,
742 MLXSW_REG_SPVM_REC_LEN, 0, false);
745 * Egress membership in VLAN ID.
748 MLXSW_ITEM32_INDEXED(reg, spvm, rec_e,
749 MLXSW_REG_SPVM_BASE_LEN, 13, 1,
750 MLXSW_REG_SPVM_REC_LEN, 0, false);
753 * Untagged - port is an untagged member - egress transmission uses untagged
757 MLXSW_ITEM32_INDEXED(reg, spvm, rec_u,
758 MLXSW_REG_SPVM_BASE_LEN, 12, 1,
759 MLXSW_REG_SPVM_REC_LEN, 0, false);
762 * Egress membership in VLAN ID.
765 MLXSW_ITEM32_INDEXED(reg, spvm, rec_vid,
766 MLXSW_REG_SPVM_BASE_LEN, 0, 12,
767 MLXSW_REG_SPVM_REC_LEN, 0, false);
769 static inline void mlxsw_reg_spvm_pack(char *payload, u8 local_port,
770 u16 vid_begin, u16 vid_end,
771 bool is_member, bool untagged)
773 int size = vid_end - vid_begin + 1;
776 MLXSW_REG_ZERO(spvm, payload);
777 mlxsw_reg_spvm_local_port_set(payload, local_port);
778 mlxsw_reg_spvm_num_rec_set(payload, size);
780 for (i = 0; i < size; i++) {
781 mlxsw_reg_spvm_rec_i_set(payload, i, is_member);
782 mlxsw_reg_spvm_rec_e_set(payload, i, is_member);
783 mlxsw_reg_spvm_rec_u_set(payload, i, untagged);
784 mlxsw_reg_spvm_rec_vid_set(payload, i, vid_begin + i);
788 /* SFGC - Switch Flooding Group Configuration
789 * ------------------------------------------
790 * The following register controls the association of flooding tables and MIDs
791 * to packet types used for flooding.
793 #define MLXSW_REG_SFGC_ID 0x2011
794 #define MLXSW_REG_SFGC_LEN 0x10
796 static const struct mlxsw_reg_info mlxsw_reg_sfgc = {
797 .id = MLXSW_REG_SFGC_ID,
798 .len = MLXSW_REG_SFGC_LEN,
801 enum mlxsw_reg_sfgc_type {
802 MLXSW_REG_SFGC_TYPE_BROADCAST,
803 MLXSW_REG_SFGC_TYPE_UNKNOWN_UNICAST,
804 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4,
805 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6,
806 MLXSW_REG_SFGC_TYPE_RESERVED,
807 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP,
808 MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL,
809 MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST,
810 MLXSW_REG_SFGC_TYPE_MAX,
814 * The traffic type to reach the flooding table.
817 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
819 enum mlxsw_reg_sfgc_bridge_type {
820 MLXSW_REG_SFGC_BRIDGE_TYPE_1Q_FID = 0,
821 MLXSW_REG_SFGC_BRIDGE_TYPE_VFID = 1,
824 /* reg_sfgc_bridge_type
827 * Note: SwitchX-2 only supports 802.1Q mode.
829 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
831 enum mlxsw_flood_table_type {
832 MLXSW_REG_SFGC_TABLE_TYPE_VID = 1,
833 MLXSW_REG_SFGC_TABLE_TYPE_SINGLE = 2,
834 MLXSW_REG_SFGC_TABLE_TYPE_ANY = 0,
835 MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFEST = 3,
836 MLXSW_REG_SFGC_TABLE_TYPE_FID = 4,
839 /* reg_sfgc_table_type
840 * See mlxsw_flood_table_type
843 * Note: FID offset and FID types are not supported in SwitchX-2.
845 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
847 /* reg_sfgc_flood_table
848 * Flooding table index to associate with the specific type on the specific
852 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
855 * The multicast ID for the swid. Not supported for Spectrum
858 MLXSW_ITEM32(reg, sfgc, mid, 0x08, 0, 16);
860 /* reg_sfgc_counter_set_type
861 * Counter Set Type for flow counters.
864 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
866 /* reg_sfgc_counter_index
867 * Counter Index for flow counters.
870 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
873 mlxsw_reg_sfgc_pack(char *payload, enum mlxsw_reg_sfgc_type type,
874 enum mlxsw_reg_sfgc_bridge_type bridge_type,
875 enum mlxsw_flood_table_type table_type,
876 unsigned int flood_table)
878 MLXSW_REG_ZERO(sfgc, payload);
879 mlxsw_reg_sfgc_type_set(payload, type);
880 mlxsw_reg_sfgc_bridge_type_set(payload, bridge_type);
881 mlxsw_reg_sfgc_table_type_set(payload, table_type);
882 mlxsw_reg_sfgc_flood_table_set(payload, flood_table);
883 mlxsw_reg_sfgc_mid_set(payload, MLXSW_PORT_MID);
886 /* SFTR - Switch Flooding Table Register
887 * -------------------------------------
888 * The switch flooding table is used for flooding packet replication. The table
889 * defines a bit mask of ports for packet replication.
891 #define MLXSW_REG_SFTR_ID 0x2012
892 #define MLXSW_REG_SFTR_LEN 0x420
894 static const struct mlxsw_reg_info mlxsw_reg_sftr = {
895 .id = MLXSW_REG_SFTR_ID,
896 .len = MLXSW_REG_SFTR_LEN,
900 * Switch partition ID with which to associate the port.
903 MLXSW_ITEM32(reg, sftr, swid, 0x00, 24, 8);
905 /* reg_sftr_flood_table
906 * Flooding table index to associate with the specific type on the specific
910 MLXSW_ITEM32(reg, sftr, flood_table, 0x00, 16, 6);
913 * Index. Used as an index into the Flooding Table in case the table is
914 * configured to use VID / FID or FID Offset.
917 MLXSW_ITEM32(reg, sftr, index, 0x00, 0, 16);
919 /* reg_sftr_table_type
920 * See mlxsw_flood_table_type
923 MLXSW_ITEM32(reg, sftr, table_type, 0x04, 16, 3);
926 * Range of entries to update
929 MLXSW_ITEM32(reg, sftr, range, 0x04, 0, 16);
932 * Local port membership (1 bit per port).
935 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port, 0x20, 0x20, 1);
937 /* reg_sftr_cpu_port_mask
938 * CPU port mask (1 bit per port).
941 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port_mask, 0x220, 0x20, 1);
943 static inline void mlxsw_reg_sftr_pack(char *payload,
944 unsigned int flood_table,
946 enum mlxsw_flood_table_type table_type,
947 unsigned int range, u8 port, bool set)
949 MLXSW_REG_ZERO(sftr, payload);
950 mlxsw_reg_sftr_swid_set(payload, 0);
951 mlxsw_reg_sftr_flood_table_set(payload, flood_table);
952 mlxsw_reg_sftr_index_set(payload, index);
953 mlxsw_reg_sftr_table_type_set(payload, table_type);
954 mlxsw_reg_sftr_range_set(payload, range);
955 mlxsw_reg_sftr_port_set(payload, port, set);
956 mlxsw_reg_sftr_port_mask_set(payload, port, 1);
959 /* SLDR - Switch LAG Descriptor Register
960 * -----------------------------------------
961 * The switch LAG descriptor register is populated by LAG descriptors.
962 * Each LAG descriptor is indexed by lag_id. The LAG ID runs from 0 to
965 #define MLXSW_REG_SLDR_ID 0x2014
966 #define MLXSW_REG_SLDR_LEN 0x0C /* counting in only one port in list */
968 static const struct mlxsw_reg_info mlxsw_reg_sldr = {
969 .id = MLXSW_REG_SLDR_ID,
970 .len = MLXSW_REG_SLDR_LEN,
973 enum mlxsw_reg_sldr_op {
974 /* Indicates a creation of a new LAG-ID, lag_id must be valid */
975 MLXSW_REG_SLDR_OP_LAG_CREATE,
976 MLXSW_REG_SLDR_OP_LAG_DESTROY,
977 /* Ports that appear in the list have the Distributor enabled */
978 MLXSW_REG_SLDR_OP_LAG_ADD_PORT_LIST,
979 /* Removes ports from the disributor list */
980 MLXSW_REG_SLDR_OP_LAG_REMOVE_PORT_LIST,
987 MLXSW_ITEM32(reg, sldr, op, 0x00, 29, 3);
990 * LAG identifier. The lag_id is the index into the LAG descriptor table.
993 MLXSW_ITEM32(reg, sldr, lag_id, 0x00, 0, 10);
995 static inline void mlxsw_reg_sldr_lag_create_pack(char *payload, u8 lag_id)
997 MLXSW_REG_ZERO(sldr, payload);
998 mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_CREATE);
999 mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1002 static inline void mlxsw_reg_sldr_lag_destroy_pack(char *payload, u8 lag_id)
1004 MLXSW_REG_ZERO(sldr, payload);
1005 mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_DESTROY);
1006 mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1009 /* reg_sldr_num_ports
1010 * The number of member ports of the LAG.
1011 * Reserved for Create / Destroy operations
1012 * For Add / Remove operations - indicates the number of ports in the list.
1015 MLXSW_ITEM32(reg, sldr, num_ports, 0x04, 24, 8);
1017 /* reg_sldr_system_port
1021 MLXSW_ITEM32_INDEXED(reg, sldr, system_port, 0x08, 0, 16, 4, 0, false);
1023 static inline void mlxsw_reg_sldr_lag_add_port_pack(char *payload, u8 lag_id,
1026 MLXSW_REG_ZERO(sldr, payload);
1027 mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_ADD_PORT_LIST);
1028 mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1029 mlxsw_reg_sldr_num_ports_set(payload, 1);
1030 mlxsw_reg_sldr_system_port_set(payload, 0, local_port);
1033 static inline void mlxsw_reg_sldr_lag_remove_port_pack(char *payload, u8 lag_id,
1036 MLXSW_REG_ZERO(sldr, payload);
1037 mlxsw_reg_sldr_op_set(payload, MLXSW_REG_SLDR_OP_LAG_REMOVE_PORT_LIST);
1038 mlxsw_reg_sldr_lag_id_set(payload, lag_id);
1039 mlxsw_reg_sldr_num_ports_set(payload, 1);
1040 mlxsw_reg_sldr_system_port_set(payload, 0, local_port);
1043 /* SLCR - Switch LAG Configuration 2 Register
1044 * -------------------------------------------
1045 * The Switch LAG Configuration register is used for configuring the
1046 * LAG properties of the switch.
1048 #define MLXSW_REG_SLCR_ID 0x2015
1049 #define MLXSW_REG_SLCR_LEN 0x10
1051 static const struct mlxsw_reg_info mlxsw_reg_slcr = {
1052 .id = MLXSW_REG_SLCR_ID,
1053 .len = MLXSW_REG_SLCR_LEN,
1056 enum mlxsw_reg_slcr_pp {
1057 /* Global Configuration (for all ports) */
1058 MLXSW_REG_SLCR_PP_GLOBAL,
1059 /* Per port configuration, based on local_port field */
1060 MLXSW_REG_SLCR_PP_PER_PORT,
1064 * Per Port Configuration
1065 * Note: Reading at Global mode results in reading port 1 configuration.
1068 MLXSW_ITEM32(reg, slcr, pp, 0x00, 24, 1);
1070 /* reg_slcr_local_port
1072 * Supported from CPU port
1073 * Not supported from router port
1074 * Reserved when pp = Global Configuration
1077 MLXSW_ITEM32(reg, slcr, local_port, 0x00, 16, 8);
1079 enum mlxsw_reg_slcr_type {
1080 MLXSW_REG_SLCR_TYPE_CRC, /* default */
1081 MLXSW_REG_SLCR_TYPE_XOR,
1082 MLXSW_REG_SLCR_TYPE_RANDOM,
1089 MLXSW_ITEM32(reg, slcr, type, 0x00, 0, 4);
1092 #define MLXSW_REG_SLCR_LAG_HASH_IN_PORT BIT(0)
1093 /* SMAC - for IPv4 and IPv6 packets */
1094 #define MLXSW_REG_SLCR_LAG_HASH_SMAC_IP BIT(1)
1095 /* SMAC - for non-IP packets */
1096 #define MLXSW_REG_SLCR_LAG_HASH_SMAC_NONIP BIT(2)
1097 #define MLXSW_REG_SLCR_LAG_HASH_SMAC \
1098 (MLXSW_REG_SLCR_LAG_HASH_SMAC_IP | \
1099 MLXSW_REG_SLCR_LAG_HASH_SMAC_NONIP)
1100 /* DMAC - for IPv4 and IPv6 packets */
1101 #define MLXSW_REG_SLCR_LAG_HASH_DMAC_IP BIT(3)
1102 /* DMAC - for non-IP packets */
1103 #define MLXSW_REG_SLCR_LAG_HASH_DMAC_NONIP BIT(4)
1104 #define MLXSW_REG_SLCR_LAG_HASH_DMAC \
1105 (MLXSW_REG_SLCR_LAG_HASH_DMAC_IP | \
1106 MLXSW_REG_SLCR_LAG_HASH_DMAC_NONIP)
1107 /* Ethertype - for IPv4 and IPv6 packets */
1108 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_IP BIT(5)
1109 /* Ethertype - for non-IP packets */
1110 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_NONIP BIT(6)
1111 #define MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE \
1112 (MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_IP | \
1113 MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE_NONIP)
1114 /* VLAN ID - for IPv4 and IPv6 packets */
1115 #define MLXSW_REG_SLCR_LAG_HASH_VLANID_IP BIT(7)
1116 /* VLAN ID - for non-IP packets */
1117 #define MLXSW_REG_SLCR_LAG_HASH_VLANID_NONIP BIT(8)
1118 #define MLXSW_REG_SLCR_LAG_HASH_VLANID \
1119 (MLXSW_REG_SLCR_LAG_HASH_VLANID_IP | \
1120 MLXSW_REG_SLCR_LAG_HASH_VLANID_NONIP)
1121 /* Source IP address (can be IPv4 or IPv6) */
1122 #define MLXSW_REG_SLCR_LAG_HASH_SIP BIT(9)
1123 /* Destination IP address (can be IPv4 or IPv6) */
1124 #define MLXSW_REG_SLCR_LAG_HASH_DIP BIT(10)
1125 /* TCP/UDP source port */
1126 #define MLXSW_REG_SLCR_LAG_HASH_SPORT BIT(11)
1127 /* TCP/UDP destination port*/
1128 #define MLXSW_REG_SLCR_LAG_HASH_DPORT BIT(12)
1129 /* IPv4 Protocol/IPv6 Next Header */
1130 #define MLXSW_REG_SLCR_LAG_HASH_IPPROTO BIT(13)
1131 /* IPv6 Flow label */
1132 #define MLXSW_REG_SLCR_LAG_HASH_FLOWLABEL BIT(14)
1133 /* SID - FCoE source ID */
1134 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_SID BIT(15)
1135 /* DID - FCoE destination ID */
1136 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_DID BIT(16)
1137 /* OXID - FCoE originator exchange ID */
1138 #define MLXSW_REG_SLCR_LAG_HASH_FCOE_OXID BIT(17)
1139 /* Destination QP number - for RoCE packets */
1140 #define MLXSW_REG_SLCR_LAG_HASH_ROCE_DQP BIT(19)
1142 /* reg_slcr_lag_hash
1143 * LAG hashing configuration. This is a bitmask, in which each set
1144 * bit includes the corresponding item in the LAG hash calculation.
1145 * The default lag_hash contains SMAC, DMAC, VLANID and
1146 * Ethertype (for all packet types).
1149 MLXSW_ITEM32(reg, slcr, lag_hash, 0x04, 0, 20);
1151 static inline void mlxsw_reg_slcr_pack(char *payload, u16 lag_hash)
1153 MLXSW_REG_ZERO(slcr, payload);
1154 mlxsw_reg_slcr_pp_set(payload, MLXSW_REG_SLCR_PP_GLOBAL);
1155 mlxsw_reg_slcr_type_set(payload, MLXSW_REG_SLCR_TYPE_XOR);
1156 mlxsw_reg_slcr_lag_hash_set(payload, lag_hash);
1159 /* SLCOR - Switch LAG Collector Register
1160 * -------------------------------------
1161 * The Switch LAG Collector register controls the Local Port membership
1162 * in a LAG and enablement of the collector.
1164 #define MLXSW_REG_SLCOR_ID 0x2016
1165 #define MLXSW_REG_SLCOR_LEN 0x10
1167 static const struct mlxsw_reg_info mlxsw_reg_slcor = {
1168 .id = MLXSW_REG_SLCOR_ID,
1169 .len = MLXSW_REG_SLCOR_LEN,
1172 enum mlxsw_reg_slcor_col {
1173 /* Port is added with collector disabled */
1174 MLXSW_REG_SLCOR_COL_LAG_ADD_PORT,
1175 MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED,
1176 MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_DISABLED,
1177 MLXSW_REG_SLCOR_COL_LAG_REMOVE_PORT,
1181 * Collector configuration
1184 MLXSW_ITEM32(reg, slcor, col, 0x00, 30, 2);
1186 /* reg_slcor_local_port
1188 * Not supported for CPU port
1191 MLXSW_ITEM32(reg, slcor, local_port, 0x00, 16, 8);
1194 * LAG Identifier. Index into the LAG descriptor table.
1197 MLXSW_ITEM32(reg, slcor, lag_id, 0x00, 0, 10);
1199 /* reg_slcor_port_index
1200 * Port index in the LAG list. Only valid on Add Port to LAG col.
1201 * Valid range is from 0 to cap_max_lag_members-1
1204 MLXSW_ITEM32(reg, slcor, port_index, 0x04, 0, 10);
1206 static inline void mlxsw_reg_slcor_pack(char *payload,
1207 u8 local_port, u16 lag_id,
1208 enum mlxsw_reg_slcor_col col)
1210 MLXSW_REG_ZERO(slcor, payload);
1211 mlxsw_reg_slcor_col_set(payload, col);
1212 mlxsw_reg_slcor_local_port_set(payload, local_port);
1213 mlxsw_reg_slcor_lag_id_set(payload, lag_id);
1216 static inline void mlxsw_reg_slcor_port_add_pack(char *payload,
1217 u8 local_port, u16 lag_id,
1220 mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1221 MLXSW_REG_SLCOR_COL_LAG_ADD_PORT);
1222 mlxsw_reg_slcor_port_index_set(payload, port_index);
1225 static inline void mlxsw_reg_slcor_port_remove_pack(char *payload,
1226 u8 local_port, u16 lag_id)
1228 mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1229 MLXSW_REG_SLCOR_COL_LAG_REMOVE_PORT);
1232 static inline void mlxsw_reg_slcor_col_enable_pack(char *payload,
1233 u8 local_port, u16 lag_id)
1235 mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1236 MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED);
1239 static inline void mlxsw_reg_slcor_col_disable_pack(char *payload,
1240 u8 local_port, u16 lag_id)
1242 mlxsw_reg_slcor_pack(payload, local_port, lag_id,
1243 MLXSW_REG_SLCOR_COL_LAG_COLLECTOR_ENABLED);
1246 /* SPMLR - Switch Port MAC Learning Register
1247 * -----------------------------------------
1248 * Controls the Switch MAC learning policy per port.
1250 #define MLXSW_REG_SPMLR_ID 0x2018
1251 #define MLXSW_REG_SPMLR_LEN 0x8
1253 static const struct mlxsw_reg_info mlxsw_reg_spmlr = {
1254 .id = MLXSW_REG_SPMLR_ID,
1255 .len = MLXSW_REG_SPMLR_LEN,
1258 /* reg_spmlr_local_port
1259 * Local port number.
1262 MLXSW_ITEM32(reg, spmlr, local_port, 0x00, 16, 8);
1264 /* reg_spmlr_sub_port
1265 * Virtual port within the physical port.
1266 * Should be set to 0 when virtual ports are not enabled on the port.
1269 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
1271 enum mlxsw_reg_spmlr_learn_mode {
1272 MLXSW_REG_SPMLR_LEARN_MODE_DISABLE = 0,
1273 MLXSW_REG_SPMLR_LEARN_MODE_ENABLE = 2,
1274 MLXSW_REG_SPMLR_LEARN_MODE_SEC = 3,
1277 /* reg_spmlr_learn_mode
1278 * Learning mode on the port.
1279 * 0 - Learning disabled.
1280 * 2 - Learning enabled.
1281 * 3 - Security mode.
1283 * In security mode the switch does not learn MACs on the port, but uses the
1284 * SMAC to see if it exists on another ingress port. If so, the packet is
1285 * classified as a bad packet and is discarded unless the software registers
1286 * to receive port security error packets usign HPKT.
1288 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
1290 static inline void mlxsw_reg_spmlr_pack(char *payload, u8 local_port,
1291 enum mlxsw_reg_spmlr_learn_mode mode)
1293 MLXSW_REG_ZERO(spmlr, payload);
1294 mlxsw_reg_spmlr_local_port_set(payload, local_port);
1295 mlxsw_reg_spmlr_sub_port_set(payload, 0);
1296 mlxsw_reg_spmlr_learn_mode_set(payload, mode);
1299 /* SVFA - Switch VID to FID Allocation Register
1300 * --------------------------------------------
1301 * Controls the VID to FID mapping and {Port, VID} to FID mapping for
1302 * virtualized ports.
1304 #define MLXSW_REG_SVFA_ID 0x201C
1305 #define MLXSW_REG_SVFA_LEN 0x10
1307 static const struct mlxsw_reg_info mlxsw_reg_svfa = {
1308 .id = MLXSW_REG_SVFA_ID,
1309 .len = MLXSW_REG_SVFA_LEN,
1313 * Switch partition ID.
1316 MLXSW_ITEM32(reg, svfa, swid, 0x00, 24, 8);
1318 /* reg_svfa_local_port
1319 * Local port number.
1322 * Note: Reserved for 802.1Q FIDs.
1324 MLXSW_ITEM32(reg, svfa, local_port, 0x00, 16, 8);
1326 enum mlxsw_reg_svfa_mt {
1327 MLXSW_REG_SVFA_MT_VID_TO_FID,
1328 MLXSW_REG_SVFA_MT_PORT_VID_TO_FID,
1331 /* reg_svfa_mapping_table
1334 * 1 - {Port, VID} to FID
1337 * Note: Reserved for SwitchX-2.
1339 MLXSW_ITEM32(reg, svfa, mapping_table, 0x00, 8, 3);
1346 * Note: Reserved for SwitchX-2.
1348 MLXSW_ITEM32(reg, svfa, v, 0x00, 0, 1);
1354 MLXSW_ITEM32(reg, svfa, fid, 0x04, 16, 16);
1360 MLXSW_ITEM32(reg, svfa, vid, 0x04, 0, 12);
1362 /* reg_svfa_counter_set_type
1363 * Counter set type for flow counters.
1366 * Note: Reserved for SwitchX-2.
1368 MLXSW_ITEM32(reg, svfa, counter_set_type, 0x08, 24, 8);
1370 /* reg_svfa_counter_index
1371 * Counter index for flow counters.
1374 * Note: Reserved for SwitchX-2.
1376 MLXSW_ITEM32(reg, svfa, counter_index, 0x08, 0, 24);
1378 static inline void mlxsw_reg_svfa_pack(char *payload, u8 local_port,
1379 enum mlxsw_reg_svfa_mt mt, bool valid,
1382 MLXSW_REG_ZERO(svfa, payload);
1383 local_port = mt == MLXSW_REG_SVFA_MT_VID_TO_FID ? 0 : local_port;
1384 mlxsw_reg_svfa_swid_set(payload, 0);
1385 mlxsw_reg_svfa_local_port_set(payload, local_port);
1386 mlxsw_reg_svfa_mapping_table_set(payload, mt);
1387 mlxsw_reg_svfa_v_set(payload, valid);
1388 mlxsw_reg_svfa_fid_set(payload, fid);
1389 mlxsw_reg_svfa_vid_set(payload, vid);
1392 /* SVPE - Switch Virtual-Port Enabling Register
1393 * --------------------------------------------
1394 * Enables port virtualization.
1396 #define MLXSW_REG_SVPE_ID 0x201E
1397 #define MLXSW_REG_SVPE_LEN 0x4
1399 static const struct mlxsw_reg_info mlxsw_reg_svpe = {
1400 .id = MLXSW_REG_SVPE_ID,
1401 .len = MLXSW_REG_SVPE_LEN,
1404 /* reg_svpe_local_port
1408 * Note: CPU port is not supported (uses VLAN mode only).
1410 MLXSW_ITEM32(reg, svpe, local_port, 0x00, 16, 8);
1413 * Virtual port enable.
1414 * 0 - Disable, VLAN mode (VID to FID).
1415 * 1 - Enable, Virtual port mode ({Port, VID} to FID).
1418 MLXSW_ITEM32(reg, svpe, vp_en, 0x00, 8, 1);
1420 static inline void mlxsw_reg_svpe_pack(char *payload, u8 local_port,
1423 MLXSW_REG_ZERO(svpe, payload);
1424 mlxsw_reg_svpe_local_port_set(payload, local_port);
1425 mlxsw_reg_svpe_vp_en_set(payload, enable);
1428 /* SFMR - Switch FID Management Register
1429 * -------------------------------------
1430 * Creates and configures FIDs.
1432 #define MLXSW_REG_SFMR_ID 0x201F
1433 #define MLXSW_REG_SFMR_LEN 0x18
1435 static const struct mlxsw_reg_info mlxsw_reg_sfmr = {
1436 .id = MLXSW_REG_SFMR_ID,
1437 .len = MLXSW_REG_SFMR_LEN,
1440 enum mlxsw_reg_sfmr_op {
1441 MLXSW_REG_SFMR_OP_CREATE_FID,
1442 MLXSW_REG_SFMR_OP_DESTROY_FID,
1447 * 0 - Create or edit FID.
1451 MLXSW_ITEM32(reg, sfmr, op, 0x00, 24, 4);
1457 MLXSW_ITEM32(reg, sfmr, fid, 0x00, 0, 16);
1459 /* reg_sfmr_fid_offset
1461 * Used to point into the flooding table selected by SFGC register if
1462 * the table is of type FID-Offset. Otherwise, this field is reserved.
1465 MLXSW_ITEM32(reg, sfmr, fid_offset, 0x08, 0, 16);
1468 * Valid Tunnel Flood Pointer.
1469 * If not set, then nve_tunnel_flood_ptr is reserved and considered NULL.
1472 * Note: Reserved for 802.1Q FIDs.
1474 MLXSW_ITEM32(reg, sfmr, vtfp, 0x0C, 31, 1);
1476 /* reg_sfmr_nve_tunnel_flood_ptr
1477 * Underlay Flooding and BC Pointer.
1478 * Used as a pointer to the first entry of the group based link lists of
1479 * flooding or BC entries (for NVE tunnels).
1482 MLXSW_ITEM32(reg, sfmr, nve_tunnel_flood_ptr, 0x0C, 0, 24);
1486 * If not set, then vni is reserved.
1489 * Note: Reserved for 802.1Q FIDs.
1491 MLXSW_ITEM32(reg, sfmr, vv, 0x10, 31, 1);
1494 * Virtual Network Identifier.
1497 * Note: A given VNI can only be assigned to one FID.
1499 MLXSW_ITEM32(reg, sfmr, vni, 0x10, 0, 24);
1501 static inline void mlxsw_reg_sfmr_pack(char *payload,
1502 enum mlxsw_reg_sfmr_op op, u16 fid,
1505 MLXSW_REG_ZERO(sfmr, payload);
1506 mlxsw_reg_sfmr_op_set(payload, op);
1507 mlxsw_reg_sfmr_fid_set(payload, fid);
1508 mlxsw_reg_sfmr_fid_offset_set(payload, fid_offset);
1509 mlxsw_reg_sfmr_vtfp_set(payload, false);
1510 mlxsw_reg_sfmr_vv_set(payload, false);
1513 /* SPVMLR - Switch Port VLAN MAC Learning Register
1514 * -----------------------------------------------
1515 * Controls the switch MAC learning policy per {Port, VID}.
1517 #define MLXSW_REG_SPVMLR_ID 0x2020
1518 #define MLXSW_REG_SPVMLR_BASE_LEN 0x04 /* base length, without records */
1519 #define MLXSW_REG_SPVMLR_REC_LEN 0x04 /* record length */
1520 #define MLXSW_REG_SPVMLR_REC_MAX_COUNT 256
1521 #define MLXSW_REG_SPVMLR_LEN (MLXSW_REG_SPVMLR_BASE_LEN + \
1522 MLXSW_REG_SPVMLR_REC_LEN * \
1523 MLXSW_REG_SPVMLR_REC_MAX_COUNT)
1525 static const struct mlxsw_reg_info mlxsw_reg_spvmlr = {
1526 .id = MLXSW_REG_SPVMLR_ID,
1527 .len = MLXSW_REG_SPVMLR_LEN,
1530 /* reg_spvmlr_local_port
1531 * Local ingress port.
1534 * Note: CPU port is not supported.
1536 MLXSW_ITEM32(reg, spvmlr, local_port, 0x00, 16, 8);
1538 /* reg_spvmlr_num_rec
1539 * Number of records to update.
1542 MLXSW_ITEM32(reg, spvmlr, num_rec, 0x00, 0, 8);
1544 /* reg_spvmlr_rec_learn_enable
1545 * 0 - Disable learning for {Port, VID}.
1546 * 1 - Enable learning for {Port, VID}.
1549 MLXSW_ITEM32_INDEXED(reg, spvmlr, rec_learn_enable, MLXSW_REG_SPVMLR_BASE_LEN,
1550 31, 1, MLXSW_REG_SPVMLR_REC_LEN, 0x00, false);
1552 /* reg_spvmlr_rec_vid
1553 * VLAN ID to be added/removed from port or for querying.
1556 MLXSW_ITEM32_INDEXED(reg, spvmlr, rec_vid, MLXSW_REG_SPVMLR_BASE_LEN, 0, 12,
1557 MLXSW_REG_SPVMLR_REC_LEN, 0x00, false);
1559 static inline void mlxsw_reg_spvmlr_pack(char *payload, u8 local_port,
1560 u16 vid_begin, u16 vid_end,
1563 int num_rec = vid_end - vid_begin + 1;
1566 WARN_ON(num_rec < 1 || num_rec > MLXSW_REG_SPVMLR_REC_MAX_COUNT);
1568 MLXSW_REG_ZERO(spvmlr, payload);
1569 mlxsw_reg_spvmlr_local_port_set(payload, local_port);
1570 mlxsw_reg_spvmlr_num_rec_set(payload, num_rec);
1572 for (i = 0; i < num_rec; i++) {
1573 mlxsw_reg_spvmlr_rec_learn_enable_set(payload, i, learn_enable);
1574 mlxsw_reg_spvmlr_rec_vid_set(payload, i, vid_begin + i);
1578 /* PMLP - Ports Module to Local Port Register
1579 * ------------------------------------------
1580 * Configures the assignment of modules to local ports.
1582 #define MLXSW_REG_PMLP_ID 0x5002
1583 #define MLXSW_REG_PMLP_LEN 0x40
1585 static const struct mlxsw_reg_info mlxsw_reg_pmlp = {
1586 .id = MLXSW_REG_PMLP_ID,
1587 .len = MLXSW_REG_PMLP_LEN,
1591 * 0 - Tx value is used for both Tx and Rx.
1592 * 1 - Rx value is taken from a separte field.
1595 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
1597 /* reg_pmlp_local_port
1598 * Local port number.
1601 MLXSW_ITEM32(reg, pmlp, local_port, 0x00, 16, 8);
1604 * 0 - Unmap local port.
1605 * 1 - Lane 0 is used.
1606 * 2 - Lanes 0 and 1 are used.
1607 * 4 - Lanes 0, 1, 2 and 3 are used.
1610 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
1616 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0, false);
1619 * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
1622 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 2, 0x04, 16, false);
1625 * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
1629 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 2, 0x04, 24, false);
1631 static inline void mlxsw_reg_pmlp_pack(char *payload, u8 local_port)
1633 MLXSW_REG_ZERO(pmlp, payload);
1634 mlxsw_reg_pmlp_local_port_set(payload, local_port);
1637 /* PMTU - Port MTU Register
1638 * ------------------------
1639 * Configures and reports the port MTU.
1641 #define MLXSW_REG_PMTU_ID 0x5003
1642 #define MLXSW_REG_PMTU_LEN 0x10
1644 static const struct mlxsw_reg_info mlxsw_reg_pmtu = {
1645 .id = MLXSW_REG_PMTU_ID,
1646 .len = MLXSW_REG_PMTU_LEN,
1649 /* reg_pmtu_local_port
1650 * Local port number.
1653 MLXSW_ITEM32(reg, pmtu, local_port, 0x00, 16, 8);
1657 * When port type (e.g. Ethernet) is configured, the relevant MTU is
1658 * reported, otherwise the minimum between the max_mtu of the different
1659 * types is reported.
1662 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
1664 /* reg_pmtu_admin_mtu
1665 * MTU value to set port to. Must be smaller or equal to max_mtu.
1666 * Note: If port type is Infiniband, then port must be disabled, when its
1670 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
1672 /* reg_pmtu_oper_mtu
1673 * The actual MTU configured on the port. Packets exceeding this size
1675 * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
1676 * oper_mtu might be smaller than admin_mtu.
1679 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
1681 static inline void mlxsw_reg_pmtu_pack(char *payload, u8 local_port,
1684 MLXSW_REG_ZERO(pmtu, payload);
1685 mlxsw_reg_pmtu_local_port_set(payload, local_port);
1686 mlxsw_reg_pmtu_max_mtu_set(payload, 0);
1687 mlxsw_reg_pmtu_admin_mtu_set(payload, new_mtu);
1688 mlxsw_reg_pmtu_oper_mtu_set(payload, 0);
1691 /* PTYS - Port Type and Speed Register
1692 * -----------------------------------
1693 * Configures and reports the port speed type.
1695 * Note: When set while the link is up, the changes will not take effect
1696 * until the port transitions from down to up state.
1698 #define MLXSW_REG_PTYS_ID 0x5004
1699 #define MLXSW_REG_PTYS_LEN 0x40
1701 static const struct mlxsw_reg_info mlxsw_reg_ptys = {
1702 .id = MLXSW_REG_PTYS_ID,
1703 .len = MLXSW_REG_PTYS_LEN,
1706 /* reg_ptys_local_port
1707 * Local port number.
1710 MLXSW_ITEM32(reg, ptys, local_port, 0x00, 16, 8);
1712 #define MLXSW_REG_PTYS_PROTO_MASK_ETH BIT(2)
1714 /* reg_ptys_proto_mask
1715 * Protocol mask. Indicates which protocol is used.
1717 * 1 - Fibre Channel.
1721 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
1723 #define MLXSW_REG_PTYS_ETH_SPEED_SGMII BIT(0)
1724 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX BIT(1)
1725 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4 BIT(2)
1726 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4 BIT(3)
1727 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR BIT(4)
1728 #define MLXSW_REG_PTYS_ETH_SPEED_20GBASE_KR2 BIT(5)
1729 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4 BIT(6)
1730 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4 BIT(7)
1731 #define MLXSW_REG_PTYS_ETH_SPEED_56GBASE_R4 BIT(8)
1732 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR BIT(12)
1733 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR BIT(13)
1734 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR BIT(14)
1735 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4 BIT(15)
1736 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4 BIT(16)
1737 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR4 BIT(19)
1738 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4 BIT(20)
1739 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4 BIT(21)
1740 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4 BIT(22)
1741 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4 BIT(23)
1742 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_TX BIT(24)
1743 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_T BIT(25)
1744 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_T BIT(26)
1745 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR BIT(27)
1746 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR BIT(28)
1747 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR BIT(29)
1748 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2 BIT(30)
1749 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2 BIT(31)
1751 /* reg_ptys_eth_proto_cap
1752 * Ethernet port supported speeds and protocols.
1755 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
1757 /* reg_ptys_eth_proto_admin
1758 * Speed and protocol to set port to.
1761 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
1763 /* reg_ptys_eth_proto_oper
1764 * The current speed and protocol configured for the port.
1767 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
1769 static inline void mlxsw_reg_ptys_pack(char *payload, u8 local_port,
1772 MLXSW_REG_ZERO(ptys, payload);
1773 mlxsw_reg_ptys_local_port_set(payload, local_port);
1774 mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
1775 mlxsw_reg_ptys_eth_proto_admin_set(payload, proto_admin);
1778 static inline void mlxsw_reg_ptys_unpack(char *payload, u32 *p_eth_proto_cap,
1779 u32 *p_eth_proto_adm,
1780 u32 *p_eth_proto_oper)
1782 if (p_eth_proto_cap)
1783 *p_eth_proto_cap = mlxsw_reg_ptys_eth_proto_cap_get(payload);
1784 if (p_eth_proto_adm)
1785 *p_eth_proto_adm = mlxsw_reg_ptys_eth_proto_admin_get(payload);
1786 if (p_eth_proto_oper)
1787 *p_eth_proto_oper = mlxsw_reg_ptys_eth_proto_oper_get(payload);
1790 /* PPAD - Port Physical Address Register
1791 * -------------------------------------
1792 * The PPAD register configures the per port physical MAC address.
1794 #define MLXSW_REG_PPAD_ID 0x5005
1795 #define MLXSW_REG_PPAD_LEN 0x10
1797 static const struct mlxsw_reg_info mlxsw_reg_ppad = {
1798 .id = MLXSW_REG_PPAD_ID,
1799 .len = MLXSW_REG_PPAD_LEN,
1802 /* reg_ppad_single_base_mac
1803 * 0: base_mac, local port should be 0 and mac[7:0] is
1804 * reserved. HW will set incremental
1805 * 1: single_mac - mac of the local_port
1808 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
1810 /* reg_ppad_local_port
1811 * port number, if single_base_mac = 0 then local_port is reserved
1814 MLXSW_ITEM32(reg, ppad, local_port, 0x00, 16, 8);
1817 * If single_base_mac = 0 - base MAC address, mac[7:0] is reserved.
1818 * If single_base_mac = 1 - the per port MAC address
1821 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
1823 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
1826 MLXSW_REG_ZERO(ppad, payload);
1827 mlxsw_reg_ppad_single_base_mac_set(payload, !!single_base_mac);
1828 mlxsw_reg_ppad_local_port_set(payload, local_port);
1831 /* PAOS - Ports Administrative and Operational Status Register
1832 * -----------------------------------------------------------
1833 * Configures and retrieves per port administrative and operational status.
1835 #define MLXSW_REG_PAOS_ID 0x5006
1836 #define MLXSW_REG_PAOS_LEN 0x10
1838 static const struct mlxsw_reg_info mlxsw_reg_paos = {
1839 .id = MLXSW_REG_PAOS_ID,
1840 .len = MLXSW_REG_PAOS_LEN,
1844 * Switch partition ID with which to associate the port.
1845 * Note: while external ports uses unique local port numbers (and thus swid is
1846 * redundant), router ports use the same local port number where swid is the
1847 * only indication for the relevant port.
1850 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
1852 /* reg_paos_local_port
1853 * Local port number.
1856 MLXSW_ITEM32(reg, paos, local_port, 0x00, 16, 8);
1858 /* reg_paos_admin_status
1859 * Port administrative state (the desired state of the port):
1862 * 3 - Up once. This means that in case of link failure, the port won't go
1863 * into polling mode, but will wait to be re-enabled by software.
1864 * 4 - Disabled by system. Can only be set by hardware.
1867 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
1869 /* reg_paos_oper_status
1870 * Port operational state (the current state):
1873 * 3 - Down by port failure. This means that the device will not let the
1874 * port up again until explicitly specified by software.
1877 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
1880 * Admin state update enabled.
1883 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
1886 * Event update enable. If this bit is set, event generation will be
1887 * updated based on the e field.
1890 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
1893 * Event generation on operational state change:
1894 * 0 - Do not generate event.
1895 * 1 - Generate Event.
1896 * 2 - Generate Single Event.
1899 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
1901 static inline void mlxsw_reg_paos_pack(char *payload, u8 local_port,
1902 enum mlxsw_port_admin_status status)
1904 MLXSW_REG_ZERO(paos, payload);
1905 mlxsw_reg_paos_swid_set(payload, 0);
1906 mlxsw_reg_paos_local_port_set(payload, local_port);
1907 mlxsw_reg_paos_admin_status_set(payload, status);
1908 mlxsw_reg_paos_oper_status_set(payload, 0);
1909 mlxsw_reg_paos_ase_set(payload, 1);
1910 mlxsw_reg_paos_ee_set(payload, 1);
1911 mlxsw_reg_paos_e_set(payload, 1);
1914 /* PPCNT - Ports Performance Counters Register
1915 * -------------------------------------------
1916 * The PPCNT register retrieves per port performance counters.
1918 #define MLXSW_REG_PPCNT_ID 0x5008
1919 #define MLXSW_REG_PPCNT_LEN 0x100
1921 static const struct mlxsw_reg_info mlxsw_reg_ppcnt = {
1922 .id = MLXSW_REG_PPCNT_ID,
1923 .len = MLXSW_REG_PPCNT_LEN,
1927 * For HCA: must be always 0.
1928 * Switch partition ID to associate port with.
1929 * Switch partitions are numbered from 0 to 7 inclusively.
1930 * Switch partition 254 indicates stacking ports.
1931 * Switch partition 255 indicates all switch partitions.
1932 * Only valid on Set() operation with local_port=255.
1935 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
1937 /* reg_ppcnt_local_port
1938 * Local port number.
1939 * 255 indicates all ports on the device, and is only allowed
1940 * for Set() operation.
1943 MLXSW_ITEM32(reg, ppcnt, local_port, 0x00, 16, 8);
1946 * Port number access type:
1947 * 0 - Local port number
1948 * 1 - IB port number
1951 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
1954 * Performance counter group.
1955 * Group 63 indicates all groups. Only valid on Set() operation with
1957 * 0x0: IEEE 802.3 Counters
1958 * 0x1: RFC 2863 Counters
1959 * 0x2: RFC 2819 Counters
1960 * 0x3: RFC 3635 Counters
1961 * 0x5: Ethernet Extended Counters
1962 * 0x8: Link Level Retransmission Counters
1963 * 0x10: Per Priority Counters
1964 * 0x11: Per Traffic Class Counters
1965 * 0x12: Physical Layer Counters
1968 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
1971 * Clear counters. Setting the clr bit will reset the counter value
1972 * for all counters in the counter group. This bit can be set
1973 * for both Set() and Get() operation.
1976 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
1978 /* reg_ppcnt_prio_tc
1979 * Priority for counter set that support per priority, valid values: 0-7.
1980 * Traffic class for counter set that support per traffic class,
1981 * valid values: 0- cap_max_tclass-1 .
1982 * For HCA: cap_max_tclass is always 8.
1983 * Otherwise must be 0.
1986 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
1988 /* reg_ppcnt_a_frames_transmitted_ok
1991 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
1992 0x08 + 0x00, 0, 64);
1994 /* reg_ppcnt_a_frames_received_ok
1997 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
1998 0x08 + 0x08, 0, 64);
2000 /* reg_ppcnt_a_frame_check_sequence_errors
2003 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
2004 0x08 + 0x10, 0, 64);
2006 /* reg_ppcnt_a_alignment_errors
2009 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
2010 0x08 + 0x18, 0, 64);
2012 /* reg_ppcnt_a_octets_transmitted_ok
2015 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
2016 0x08 + 0x20, 0, 64);
2018 /* reg_ppcnt_a_octets_received_ok
2021 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
2022 0x08 + 0x28, 0, 64);
2024 /* reg_ppcnt_a_multicast_frames_xmitted_ok
2027 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
2028 0x08 + 0x30, 0, 64);
2030 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
2033 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
2034 0x08 + 0x38, 0, 64);
2036 /* reg_ppcnt_a_multicast_frames_received_ok
2039 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
2040 0x08 + 0x40, 0, 64);
2042 /* reg_ppcnt_a_broadcast_frames_received_ok
2045 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
2046 0x08 + 0x48, 0, 64);
2048 /* reg_ppcnt_a_in_range_length_errors
2051 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
2052 0x08 + 0x50, 0, 64);
2054 /* reg_ppcnt_a_out_of_range_length_field
2057 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
2058 0x08 + 0x58, 0, 64);
2060 /* reg_ppcnt_a_frame_too_long_errors
2063 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
2064 0x08 + 0x60, 0, 64);
2066 /* reg_ppcnt_a_symbol_error_during_carrier
2069 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
2070 0x08 + 0x68, 0, 64);
2072 /* reg_ppcnt_a_mac_control_frames_transmitted
2075 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
2076 0x08 + 0x70, 0, 64);
2078 /* reg_ppcnt_a_mac_control_frames_received
2081 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
2082 0x08 + 0x78, 0, 64);
2084 /* reg_ppcnt_a_unsupported_opcodes_received
2087 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
2088 0x08 + 0x80, 0, 64);
2090 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
2093 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
2094 0x08 + 0x88, 0, 64);
2096 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
2099 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
2100 0x08 + 0x90, 0, 64);
2102 static inline void mlxsw_reg_ppcnt_pack(char *payload, u8 local_port)
2104 MLXSW_REG_ZERO(ppcnt, payload);
2105 mlxsw_reg_ppcnt_swid_set(payload, 0);
2106 mlxsw_reg_ppcnt_local_port_set(payload, local_port);
2107 mlxsw_reg_ppcnt_pnat_set(payload, 0);
2108 mlxsw_reg_ppcnt_grp_set(payload, 0);
2109 mlxsw_reg_ppcnt_clr_set(payload, 0);
2110 mlxsw_reg_ppcnt_prio_tc_set(payload, 0);
2113 /* PBMC - Port Buffer Management Control Register
2114 * ----------------------------------------------
2115 * The PBMC register configures and retrieves the port packet buffer
2116 * allocation for different Prios, and the Pause threshold management.
2118 #define MLXSW_REG_PBMC_ID 0x500C
2119 #define MLXSW_REG_PBMC_LEN 0x68
2121 static const struct mlxsw_reg_info mlxsw_reg_pbmc = {
2122 .id = MLXSW_REG_PBMC_ID,
2123 .len = MLXSW_REG_PBMC_LEN,
2126 /* reg_pbmc_local_port
2127 * Local port number.
2130 MLXSW_ITEM32(reg, pbmc, local_port, 0x00, 16, 8);
2132 /* reg_pbmc_xoff_timer_value
2133 * When device generates a pause frame, it uses this value as the pause
2134 * timer (time for the peer port to pause in quota-512 bit time).
2137 MLXSW_ITEM32(reg, pbmc, xoff_timer_value, 0x04, 16, 16);
2139 /* reg_pbmc_xoff_refresh
2140 * The time before a new pause frame should be sent to refresh the pause RW
2141 * state. Using the same units as xoff_timer_value above (in quota-512 bit
2145 MLXSW_ITEM32(reg, pbmc, xoff_refresh, 0x04, 0, 16);
2147 /* reg_pbmc_buf_lossy
2148 * The field indicates if the buffer is lossy.
2153 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_lossy, 0x0C, 25, 1, 0x08, 0x00, false);
2155 /* reg_pbmc_buf_epsb
2156 * Eligible for Port Shared buffer.
2157 * If epsb is set, packets assigned to buffer are allowed to insert the port
2159 * When buf_lossy is MLXSW_REG_PBMC_LOSSY_LOSSY this field is reserved.
2162 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_epsb, 0x0C, 24, 1, 0x08, 0x00, false);
2164 /* reg_pbmc_buf_size
2165 * The part of the packet buffer array is allocated for the specific buffer.
2166 * Units are represented in cells.
2169 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_size, 0x0C, 0, 16, 0x08, 0x00, false);
2171 static inline void mlxsw_reg_pbmc_pack(char *payload, u8 local_port,
2172 u16 xoff_timer_value, u16 xoff_refresh)
2174 MLXSW_REG_ZERO(pbmc, payload);
2175 mlxsw_reg_pbmc_local_port_set(payload, local_port);
2176 mlxsw_reg_pbmc_xoff_timer_value_set(payload, xoff_timer_value);
2177 mlxsw_reg_pbmc_xoff_refresh_set(payload, xoff_refresh);
2180 static inline void mlxsw_reg_pbmc_lossy_buffer_pack(char *payload,
2184 mlxsw_reg_pbmc_buf_lossy_set(payload, buf_index, 1);
2185 mlxsw_reg_pbmc_buf_epsb_set(payload, buf_index, 0);
2186 mlxsw_reg_pbmc_buf_size_set(payload, buf_index, size);
2189 /* PSPA - Port Switch Partition Allocation
2190 * ---------------------------------------
2191 * Controls the association of a port with a switch partition and enables
2192 * configuring ports as stacking ports.
2194 #define MLXSW_REG_PSPA_ID 0x500D
2195 #define MLXSW_REG_PSPA_LEN 0x8
2197 static const struct mlxsw_reg_info mlxsw_reg_pspa = {
2198 .id = MLXSW_REG_PSPA_ID,
2199 .len = MLXSW_REG_PSPA_LEN,
2203 * Switch partition ID.
2206 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
2208 /* reg_pspa_local_port
2209 * Local port number.
2212 MLXSW_ITEM32(reg, pspa, local_port, 0x00, 16, 8);
2214 /* reg_pspa_sub_port
2215 * Virtual port within the local port. Set to 0 when virtual ports are
2216 * disabled on the local port.
2219 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
2221 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
2223 MLXSW_REG_ZERO(pspa, payload);
2224 mlxsw_reg_pspa_swid_set(payload, swid);
2225 mlxsw_reg_pspa_local_port_set(payload, local_port);
2226 mlxsw_reg_pspa_sub_port_set(payload, 0);
2229 /* HTGT - Host Trap Group Table
2230 * ----------------------------
2231 * Configures the properties for forwarding to CPU.
2233 #define MLXSW_REG_HTGT_ID 0x7002
2234 #define MLXSW_REG_HTGT_LEN 0x100
2236 static const struct mlxsw_reg_info mlxsw_reg_htgt = {
2237 .id = MLXSW_REG_HTGT_ID,
2238 .len = MLXSW_REG_HTGT_LEN,
2242 * Switch partition ID.
2245 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
2247 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0 /* For locally attached CPU */
2253 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
2255 enum mlxsw_reg_htgt_trap_group {
2256 MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
2257 MLXSW_REG_HTGT_TRAP_GROUP_RX,
2258 MLXSW_REG_HTGT_TRAP_GROUP_CTRL,
2261 /* reg_htgt_trap_group
2262 * Trap group number. User defined number specifying which trap groups
2263 * should be forwarded to the CPU. The mapping between trap IDs and trap
2264 * groups is configured using HPKT register.
2267 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
2270 MLXSW_REG_HTGT_POLICER_DISABLE,
2271 MLXSW_REG_HTGT_POLICER_ENABLE,
2275 * Enable policer ID specified using 'pid' field.
2278 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
2281 * Policer ID for the trap group.
2284 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
2286 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
2288 /* reg_htgt_mirror_action
2289 * Mirror action to use.
2291 * 1 - Trap to CPU and mirror to a mirroring agent.
2292 * 2 - Mirror to a mirroring agent and do not trap to CPU.
2295 * Note: Mirroring to a mirroring agent is only supported in Spectrum.
2297 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
2299 /* reg_htgt_mirroring_agent
2303 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
2305 /* reg_htgt_priority
2306 * Trap group priority.
2307 * In case a packet matches multiple classification rules, the packet will
2308 * only be trapped once, based on the trap ID associated with the group (via
2309 * register HPKT) with the highest priority.
2310 * Supported values are 0-7, with 7 represnting the highest priority.
2313 * Note: In SwitchX-2 this field is ignored and the priority value is replaced
2314 * by the 'trap_group' field.
2316 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
2318 /* reg_htgt_local_path_cpu_tclass
2319 * CPU ingress traffic class for the trap group.
2322 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
2324 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD 0x15
2325 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX 0x14
2326 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL 0x13
2328 /* reg_htgt_local_path_rdq
2329 * Receive descriptor queue (RDQ) to use for the trap group.
2332 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
2334 static inline void mlxsw_reg_htgt_pack(char *payload,
2335 enum mlxsw_reg_htgt_trap_group group)
2339 MLXSW_REG_ZERO(htgt, payload);
2341 case MLXSW_REG_HTGT_TRAP_GROUP_EMAD:
2342 swid = MLXSW_PORT_SWID_ALL_SWIDS;
2343 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD;
2345 case MLXSW_REG_HTGT_TRAP_GROUP_RX:
2347 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX;
2349 case MLXSW_REG_HTGT_TRAP_GROUP_CTRL:
2351 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL;
2354 mlxsw_reg_htgt_swid_set(payload, swid);
2355 mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
2356 mlxsw_reg_htgt_trap_group_set(payload, group);
2357 mlxsw_reg_htgt_pide_set(payload, MLXSW_REG_HTGT_POLICER_DISABLE);
2358 mlxsw_reg_htgt_pid_set(payload, 0);
2359 mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
2360 mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
2361 mlxsw_reg_htgt_priority_set(payload, 0);
2362 mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, 7);
2363 mlxsw_reg_htgt_local_path_rdq_set(payload, rdq);
2366 /* HPKT - Host Packet Trap
2367 * -----------------------
2368 * Configures trap IDs inside trap groups.
2370 #define MLXSW_REG_HPKT_ID 0x7003
2371 #define MLXSW_REG_HPKT_LEN 0x10
2373 static const struct mlxsw_reg_info mlxsw_reg_hpkt = {
2374 .id = MLXSW_REG_HPKT_ID,
2375 .len = MLXSW_REG_HPKT_LEN,
2379 MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
2380 MLXSW_REG_HPKT_ACK_REQUIRED,
2384 * Require acknowledgements from the host for events.
2385 * If set, then the device will wait for the event it sent to be acknowledged
2386 * by the host. This option is only relevant for event trap IDs.
2389 * Note: Currently not supported by firmware.
2391 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
2393 enum mlxsw_reg_hpkt_action {
2394 MLXSW_REG_HPKT_ACTION_FORWARD,
2395 MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
2396 MLXSW_REG_HPKT_ACTION_MIRROR_TO_CPU,
2397 MLXSW_REG_HPKT_ACTION_DISCARD,
2398 MLXSW_REG_HPKT_ACTION_SOFT_DISCARD,
2399 MLXSW_REG_HPKT_ACTION_TRAP_AND_SOFT_DISCARD,
2403 * Action to perform on packet when trapped.
2404 * 0 - No action. Forward to CPU based on switching rules.
2405 * 1 - Trap to CPU (CPU receives sole copy).
2406 * 2 - Mirror to CPU (CPU receives a replica of the packet).
2408 * 4 - Soft discard (allow other traps to act on the packet).
2409 * 5 - Trap and soft discard (allow other traps to overwrite this trap).
2412 * Note: Must be set to 0 (forward) for event trap IDs, as they are already
2413 * addressed to the CPU.
2415 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
2417 /* reg_hpkt_trap_group
2418 * Trap group to associate the trap with.
2421 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
2427 * Note: A trap ID can only be associated with a single trap group. The device
2428 * will associate the trap ID with the last trap group configured.
2430 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 9);
2433 MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
2434 MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
2435 MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
2439 * Configure dedicated buffer resources for control packets.
2440 * 0 - Keep factory defaults.
2441 * 1 - Do not use control buffer for this trap ID.
2442 * 2 - Use control buffer for this trap ID.
2445 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
2447 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id)
2449 enum mlxsw_reg_htgt_trap_group trap_group;
2451 MLXSW_REG_ZERO(hpkt, payload);
2452 mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
2453 mlxsw_reg_hpkt_action_set(payload, action);
2455 case MLXSW_TRAP_ID_ETHEMAD:
2456 case MLXSW_TRAP_ID_PUDE:
2457 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_EMAD;
2460 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_RX;
2463 mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
2464 mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
2465 mlxsw_reg_hpkt_ctrl_set(payload, MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT);
2468 /* MFCR - Management Fan Control Register
2469 * --------------------------------------
2470 * This register controls the settings of the Fan Speed PWM mechanism.
2472 #define MLXSW_REG_MFCR_ID 0x9001
2473 #define MLXSW_REG_MFCR_LEN 0x08
2475 static const struct mlxsw_reg_info mlxsw_reg_mfcr = {
2476 .id = MLXSW_REG_MFCR_ID,
2477 .len = MLXSW_REG_MFCR_LEN,
2480 enum mlxsw_reg_mfcr_pwm_frequency {
2481 MLXSW_REG_MFCR_PWM_FEQ_11HZ = 0x00,
2482 MLXSW_REG_MFCR_PWM_FEQ_14_7HZ = 0x01,
2483 MLXSW_REG_MFCR_PWM_FEQ_22_1HZ = 0x02,
2484 MLXSW_REG_MFCR_PWM_FEQ_1_4KHZ = 0x40,
2485 MLXSW_REG_MFCR_PWM_FEQ_5KHZ = 0x41,
2486 MLXSW_REG_MFCR_PWM_FEQ_20KHZ = 0x42,
2487 MLXSW_REG_MFCR_PWM_FEQ_22_5KHZ = 0x43,
2488 MLXSW_REG_MFCR_PWM_FEQ_25KHZ = 0x44,
2491 /* reg_mfcr_pwm_frequency
2492 * Controls the frequency of the PWM signal.
2495 MLXSW_ITEM32(reg, mfcr, pwm_frequency, 0x00, 0, 6);
2497 #define MLXSW_MFCR_TACHOS_MAX 10
2499 /* reg_mfcr_tacho_active
2500 * Indicates which of the tachometer is active (bit per tachometer).
2503 MLXSW_ITEM32(reg, mfcr, tacho_active, 0x04, 16, MLXSW_MFCR_TACHOS_MAX);
2505 #define MLXSW_MFCR_PWMS_MAX 5
2507 /* reg_mfcr_pwm_active
2508 * Indicates which of the PWM control is active (bit per PWM).
2511 MLXSW_ITEM32(reg, mfcr, pwm_active, 0x04, 0, MLXSW_MFCR_PWMS_MAX);
2514 mlxsw_reg_mfcr_pack(char *payload,
2515 enum mlxsw_reg_mfcr_pwm_frequency pwm_frequency)
2517 MLXSW_REG_ZERO(mfcr, payload);
2518 mlxsw_reg_mfcr_pwm_frequency_set(payload, pwm_frequency);
2522 mlxsw_reg_mfcr_unpack(char *payload,
2523 enum mlxsw_reg_mfcr_pwm_frequency *p_pwm_frequency,
2524 u16 *p_tacho_active, u8 *p_pwm_active)
2526 *p_pwm_frequency = mlxsw_reg_mfcr_pwm_frequency_get(payload);
2527 *p_tacho_active = mlxsw_reg_mfcr_tacho_active_get(payload);
2528 *p_pwm_active = mlxsw_reg_mfcr_pwm_active_get(payload);
2531 /* MFSC - Management Fan Speed Control Register
2532 * --------------------------------------------
2533 * This register controls the settings of the Fan Speed PWM mechanism.
2535 #define MLXSW_REG_MFSC_ID 0x9002
2536 #define MLXSW_REG_MFSC_LEN 0x08
2538 static const struct mlxsw_reg_info mlxsw_reg_mfsc = {
2539 .id = MLXSW_REG_MFSC_ID,
2540 .len = MLXSW_REG_MFSC_LEN,
2544 * Fan pwm to control / monitor.
2547 MLXSW_ITEM32(reg, mfsc, pwm, 0x00, 24, 3);
2549 /* reg_mfsc_pwm_duty_cycle
2550 * Controls the duty cycle of the PWM. Value range from 0..255 to
2551 * represent duty cycle of 0%...100%.
2554 MLXSW_ITEM32(reg, mfsc, pwm_duty_cycle, 0x04, 0, 8);
2556 static inline void mlxsw_reg_mfsc_pack(char *payload, u8 pwm,
2559 MLXSW_REG_ZERO(mfsc, payload);
2560 mlxsw_reg_mfsc_pwm_set(payload, pwm);
2561 mlxsw_reg_mfsc_pwm_duty_cycle_set(payload, pwm_duty_cycle);
2564 /* MFSM - Management Fan Speed Measurement
2565 * ---------------------------------------
2566 * This register controls the settings of the Tacho measurements and
2567 * enables reading the Tachometer measurements.
2569 #define MLXSW_REG_MFSM_ID 0x9003
2570 #define MLXSW_REG_MFSM_LEN 0x08
2572 static const struct mlxsw_reg_info mlxsw_reg_mfsm = {
2573 .id = MLXSW_REG_MFSM_ID,
2574 .len = MLXSW_REG_MFSM_LEN,
2578 * Fan tachometer index.
2581 MLXSW_ITEM32(reg, mfsm, tacho, 0x00, 24, 4);
2584 * Fan speed (round per minute).
2587 MLXSW_ITEM32(reg, mfsm, rpm, 0x04, 0, 16);
2589 static inline void mlxsw_reg_mfsm_pack(char *payload, u8 tacho)
2591 MLXSW_REG_ZERO(mfsm, payload);
2592 mlxsw_reg_mfsm_tacho_set(payload, tacho);
2595 /* MTCAP - Management Temperature Capabilities
2596 * -------------------------------------------
2597 * This register exposes the capabilities of the device and
2598 * system temperature sensing.
2600 #define MLXSW_REG_MTCAP_ID 0x9009
2601 #define MLXSW_REG_MTCAP_LEN 0x08
2603 static const struct mlxsw_reg_info mlxsw_reg_mtcap = {
2604 .id = MLXSW_REG_MTCAP_ID,
2605 .len = MLXSW_REG_MTCAP_LEN,
2608 /* reg_mtcap_sensor_count
2609 * Number of sensors supported by the device.
2610 * This includes the QSFP module sensors (if exists in the QSFP module).
2613 MLXSW_ITEM32(reg, mtcap, sensor_count, 0x00, 0, 7);
2615 /* MTMP - Management Temperature
2616 * -----------------------------
2617 * This register controls the settings of the temperature measurements
2618 * and enables reading the temperature measurements. Note that temperature
2619 * is in 0.125 degrees Celsius.
2621 #define MLXSW_REG_MTMP_ID 0x900A
2622 #define MLXSW_REG_MTMP_LEN 0x20
2624 static const struct mlxsw_reg_info mlxsw_reg_mtmp = {
2625 .id = MLXSW_REG_MTMP_ID,
2626 .len = MLXSW_REG_MTMP_LEN,
2629 /* reg_mtmp_sensor_index
2630 * Sensors index to access.
2631 * 64-127 of sensor_index are mapped to the SFP+/QSFP modules sequentially
2632 * (module 0 is mapped to sensor_index 64).
2635 MLXSW_ITEM32(reg, mtmp, sensor_index, 0x00, 0, 7);
2637 /* Convert to milli degrees Celsius */
2638 #define MLXSW_REG_MTMP_TEMP_TO_MC(val) (val * 125)
2640 /* reg_mtmp_temperature
2641 * Temperature reading from the sensor. Reading is in 0.125 Celsius
2645 MLXSW_ITEM32(reg, mtmp, temperature, 0x04, 0, 16);
2648 * Max Temperature Enable - enables measuring the max temperature on a sensor.
2651 MLXSW_ITEM32(reg, mtmp, mte, 0x08, 31, 1);
2654 * Max Temperature Reset - clears the value of the max temperature register.
2657 MLXSW_ITEM32(reg, mtmp, mtr, 0x08, 30, 1);
2659 /* reg_mtmp_max_temperature
2660 * The highest measured temperature from the sensor.
2661 * When the bit mte is cleared, the field max_temperature is reserved.
2664 MLXSW_ITEM32(reg, mtmp, max_temperature, 0x08, 0, 16);
2666 #define MLXSW_REG_MTMP_SENSOR_NAME_SIZE 8
2668 /* reg_mtmp_sensor_name
2672 MLXSW_ITEM_BUF(reg, mtmp, sensor_name, 0x18, MLXSW_REG_MTMP_SENSOR_NAME_SIZE);
2674 static inline void mlxsw_reg_mtmp_pack(char *payload, u8 sensor_index,
2675 bool max_temp_enable,
2676 bool max_temp_reset)
2678 MLXSW_REG_ZERO(mtmp, payload);
2679 mlxsw_reg_mtmp_sensor_index_set(payload, sensor_index);
2680 mlxsw_reg_mtmp_mte_set(payload, max_temp_enable);
2681 mlxsw_reg_mtmp_mtr_set(payload, max_temp_reset);
2684 static inline void mlxsw_reg_mtmp_unpack(char *payload, unsigned int *p_temp,
2685 unsigned int *p_max_temp,
2691 temp = mlxsw_reg_mtmp_temperature_get(payload);
2692 *p_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
2695 temp = mlxsw_reg_mtmp_max_temperature_get(payload);
2696 *p_max_temp = MLXSW_REG_MTMP_TEMP_TO_MC(temp);
2699 mlxsw_reg_mtmp_sensor_name_memcpy_from(payload, sensor_name);
2702 /* MLCR - Management LED Control Register
2703 * --------------------------------------
2704 * Controls the system LEDs.
2706 #define MLXSW_REG_MLCR_ID 0x902B
2707 #define MLXSW_REG_MLCR_LEN 0x0C
2709 static const struct mlxsw_reg_info mlxsw_reg_mlcr = {
2710 .id = MLXSW_REG_MLCR_ID,
2711 .len = MLXSW_REG_MLCR_LEN,
2714 /* reg_mlcr_local_port
2715 * Local port number.
2718 MLXSW_ITEM32(reg, mlcr, local_port, 0x00, 16, 8);
2720 #define MLXSW_REG_MLCR_DURATION_MAX 0xFFFF
2722 /* reg_mlcr_beacon_duration
2723 * Duration of the beacon to be active, in seconds.
2724 * 0x0 - Will turn off the beacon.
2725 * 0xFFFF - Will turn on the beacon until explicitly turned off.
2728 MLXSW_ITEM32(reg, mlcr, beacon_duration, 0x04, 0, 16);
2730 /* reg_mlcr_beacon_remain
2731 * Remaining duration of the beacon, in seconds.
2732 * 0xFFFF indicates an infinite amount of time.
2735 MLXSW_ITEM32(reg, mlcr, beacon_remain, 0x08, 0, 16);
2737 static inline void mlxsw_reg_mlcr_pack(char *payload, u8 local_port,
2740 MLXSW_REG_ZERO(mlcr, payload);
2741 mlxsw_reg_mlcr_local_port_set(payload, local_port);
2742 mlxsw_reg_mlcr_beacon_duration_set(payload, active ?
2743 MLXSW_REG_MLCR_DURATION_MAX : 0);
2746 /* SBPR - Shared Buffer Pools Register
2747 * -----------------------------------
2748 * The SBPR configures and retrieves the shared buffer pools and configuration.
2750 #define MLXSW_REG_SBPR_ID 0xB001
2751 #define MLXSW_REG_SBPR_LEN 0x14
2753 static const struct mlxsw_reg_info mlxsw_reg_sbpr = {
2754 .id = MLXSW_REG_SBPR_ID,
2755 .len = MLXSW_REG_SBPR_LEN,
2758 enum mlxsw_reg_sbpr_dir {
2759 MLXSW_REG_SBPR_DIR_INGRESS,
2760 MLXSW_REG_SBPR_DIR_EGRESS,
2767 MLXSW_ITEM32(reg, sbpr, dir, 0x00, 24, 2);
2773 MLXSW_ITEM32(reg, sbpr, pool, 0x00, 0, 4);
2776 * Pool size in buffer cells.
2779 MLXSW_ITEM32(reg, sbpr, size, 0x04, 0, 24);
2781 enum mlxsw_reg_sbpr_mode {
2782 MLXSW_REG_SBPR_MODE_STATIC,
2783 MLXSW_REG_SBPR_MODE_DYNAMIC,
2787 * Pool quota calculation mode.
2790 MLXSW_ITEM32(reg, sbpr, mode, 0x08, 0, 4);
2792 static inline void mlxsw_reg_sbpr_pack(char *payload, u8 pool,
2793 enum mlxsw_reg_sbpr_dir dir,
2794 enum mlxsw_reg_sbpr_mode mode, u32 size)
2796 MLXSW_REG_ZERO(sbpr, payload);
2797 mlxsw_reg_sbpr_pool_set(payload, pool);
2798 mlxsw_reg_sbpr_dir_set(payload, dir);
2799 mlxsw_reg_sbpr_mode_set(payload, mode);
2800 mlxsw_reg_sbpr_size_set(payload, size);
2803 /* SBCM - Shared Buffer Class Management Register
2804 * ----------------------------------------------
2805 * The SBCM register configures and retrieves the shared buffer allocation
2806 * and configuration according to Port-PG, including the binding to pool
2807 * and definition of the associated quota.
2809 #define MLXSW_REG_SBCM_ID 0xB002
2810 #define MLXSW_REG_SBCM_LEN 0x28
2812 static const struct mlxsw_reg_info mlxsw_reg_sbcm = {
2813 .id = MLXSW_REG_SBCM_ID,
2814 .len = MLXSW_REG_SBCM_LEN,
2817 /* reg_sbcm_local_port
2818 * Local port number.
2819 * For Ingress: excludes CPU port and Router port
2820 * For Egress: excludes IP Router
2823 MLXSW_ITEM32(reg, sbcm, local_port, 0x00, 16, 8);
2826 * PG buffer - Port PG (dir=ingress) / traffic class (dir=egress)
2827 * For PG buffer: range is 0..cap_max_pg_buffers - 1
2828 * For traffic class: range is 0..cap_max_tclass - 1
2829 * Note that when traffic class is in MC aware mode then the traffic
2830 * classes which are MC aware cannot be configured.
2833 MLXSW_ITEM32(reg, sbcm, pg_buff, 0x00, 8, 6);
2835 enum mlxsw_reg_sbcm_dir {
2836 MLXSW_REG_SBCM_DIR_INGRESS,
2837 MLXSW_REG_SBCM_DIR_EGRESS,
2844 MLXSW_ITEM32(reg, sbcm, dir, 0x00, 0, 2);
2846 /* reg_sbcm_min_buff
2847 * Minimum buffer size for the limiter, in cells.
2850 MLXSW_ITEM32(reg, sbcm, min_buff, 0x18, 0, 24);
2852 /* reg_sbcm_max_buff
2853 * When the pool associated to the port-pg/tclass is configured to
2854 * static, Maximum buffer size for the limiter configured in cells.
2855 * When the pool associated to the port-pg/tclass is configured to
2856 * dynamic, the max_buff holds the "alpha" parameter, supporting
2857 * the following values:
2859 * i: (1/128)*2^(i-1), for i=1..14
2863 MLXSW_ITEM32(reg, sbcm, max_buff, 0x1C, 0, 24);
2866 * Association of the port-priority to a pool.
2869 MLXSW_ITEM32(reg, sbcm, pool, 0x24, 0, 4);
2871 static inline void mlxsw_reg_sbcm_pack(char *payload, u8 local_port, u8 pg_buff,
2872 enum mlxsw_reg_sbcm_dir dir,
2873 u32 min_buff, u32 max_buff, u8 pool)
2875 MLXSW_REG_ZERO(sbcm, payload);
2876 mlxsw_reg_sbcm_local_port_set(payload, local_port);
2877 mlxsw_reg_sbcm_pg_buff_set(payload, pg_buff);
2878 mlxsw_reg_sbcm_dir_set(payload, dir);
2879 mlxsw_reg_sbcm_min_buff_set(payload, min_buff);
2880 mlxsw_reg_sbcm_max_buff_set(payload, max_buff);
2881 mlxsw_reg_sbcm_pool_set(payload, pool);
2884 /* SBPM - Shared Buffer Class Management Register
2885 * ----------------------------------------------
2886 * The SBPM register configures and retrieves the shared buffer allocation
2887 * and configuration according to Port-Pool, including the definition
2888 * of the associated quota.
2890 #define MLXSW_REG_SBPM_ID 0xB003
2891 #define MLXSW_REG_SBPM_LEN 0x28
2893 static const struct mlxsw_reg_info mlxsw_reg_sbpm = {
2894 .id = MLXSW_REG_SBPM_ID,
2895 .len = MLXSW_REG_SBPM_LEN,
2898 /* reg_sbpm_local_port
2899 * Local port number.
2900 * For Ingress: excludes CPU port and Router port
2901 * For Egress: excludes IP Router
2904 MLXSW_ITEM32(reg, sbpm, local_port, 0x00, 16, 8);
2907 * The pool associated to quota counting on the local_port.
2910 MLXSW_ITEM32(reg, sbpm, pool, 0x00, 8, 4);
2912 enum mlxsw_reg_sbpm_dir {
2913 MLXSW_REG_SBPM_DIR_INGRESS,
2914 MLXSW_REG_SBPM_DIR_EGRESS,
2921 MLXSW_ITEM32(reg, sbpm, dir, 0x00, 0, 2);
2923 /* reg_sbpm_min_buff
2924 * Minimum buffer size for the limiter, in cells.
2927 MLXSW_ITEM32(reg, sbpm, min_buff, 0x18, 0, 24);
2929 /* reg_sbpm_max_buff
2930 * When the pool associated to the port-pg/tclass is configured to
2931 * static, Maximum buffer size for the limiter configured in cells.
2932 * When the pool associated to the port-pg/tclass is configured to
2933 * dynamic, the max_buff holds the "alpha" parameter, supporting
2934 * the following values:
2936 * i: (1/128)*2^(i-1), for i=1..14
2940 MLXSW_ITEM32(reg, sbpm, max_buff, 0x1C, 0, 24);
2942 static inline void mlxsw_reg_sbpm_pack(char *payload, u8 local_port, u8 pool,
2943 enum mlxsw_reg_sbpm_dir dir,
2944 u32 min_buff, u32 max_buff)
2946 MLXSW_REG_ZERO(sbpm, payload);
2947 mlxsw_reg_sbpm_local_port_set(payload, local_port);
2948 mlxsw_reg_sbpm_pool_set(payload, pool);
2949 mlxsw_reg_sbpm_dir_set(payload, dir);
2950 mlxsw_reg_sbpm_min_buff_set(payload, min_buff);
2951 mlxsw_reg_sbpm_max_buff_set(payload, max_buff);
2954 /* SBMM - Shared Buffer Multicast Management Register
2955 * --------------------------------------------------
2956 * The SBMM register configures and retrieves the shared buffer allocation
2957 * and configuration for MC packets according to Switch-Priority, including
2958 * the binding to pool and definition of the associated quota.
2960 #define MLXSW_REG_SBMM_ID 0xB004
2961 #define MLXSW_REG_SBMM_LEN 0x28
2963 static const struct mlxsw_reg_info mlxsw_reg_sbmm = {
2964 .id = MLXSW_REG_SBMM_ID,
2965 .len = MLXSW_REG_SBMM_LEN,
2972 MLXSW_ITEM32(reg, sbmm, prio, 0x00, 8, 4);
2974 /* reg_sbmm_min_buff
2975 * Minimum buffer size for the limiter, in cells.
2978 MLXSW_ITEM32(reg, sbmm, min_buff, 0x18, 0, 24);
2980 /* reg_sbmm_max_buff
2981 * When the pool associated to the port-pg/tclass is configured to
2982 * static, Maximum buffer size for the limiter configured in cells.
2983 * When the pool associated to the port-pg/tclass is configured to
2984 * dynamic, the max_buff holds the "alpha" parameter, supporting
2985 * the following values:
2987 * i: (1/128)*2^(i-1), for i=1..14
2991 MLXSW_ITEM32(reg, sbmm, max_buff, 0x1C, 0, 24);
2994 * Association of the port-priority to a pool.
2997 MLXSW_ITEM32(reg, sbmm, pool, 0x24, 0, 4);
2999 static inline void mlxsw_reg_sbmm_pack(char *payload, u8 prio, u32 min_buff,
3000 u32 max_buff, u8 pool)
3002 MLXSW_REG_ZERO(sbmm, payload);
3003 mlxsw_reg_sbmm_prio_set(payload, prio);
3004 mlxsw_reg_sbmm_min_buff_set(payload, min_buff);
3005 mlxsw_reg_sbmm_max_buff_set(payload, max_buff);
3006 mlxsw_reg_sbmm_pool_set(payload, pool);
3009 static inline const char *mlxsw_reg_id_str(u16 reg_id)
3012 case MLXSW_REG_SGCR_ID:
3014 case MLXSW_REG_SPAD_ID:
3016 case MLXSW_REG_SSPR_ID:
3018 case MLXSW_REG_SFDAT_ID:
3020 case MLXSW_REG_SFD_ID:
3022 case MLXSW_REG_SFN_ID:
3024 case MLXSW_REG_SPMS_ID:
3026 case MLXSW_REG_SPVID_ID:
3028 case MLXSW_REG_SPVM_ID:
3030 case MLXSW_REG_SFGC_ID:
3032 case MLXSW_REG_SFTR_ID:
3034 case MLXSW_REG_SLDR_ID:
3036 case MLXSW_REG_SLCR_ID:
3038 case MLXSW_REG_SLCOR_ID:
3040 case MLXSW_REG_SPMLR_ID:
3042 case MLXSW_REG_SVFA_ID:
3044 case MLXSW_REG_SVPE_ID:
3046 case MLXSW_REG_SFMR_ID:
3048 case MLXSW_REG_SPVMLR_ID:
3050 case MLXSW_REG_PMLP_ID:
3052 case MLXSW_REG_PMTU_ID:
3054 case MLXSW_REG_PTYS_ID:
3056 case MLXSW_REG_PPAD_ID:
3058 case MLXSW_REG_PAOS_ID:
3060 case MLXSW_REG_PPCNT_ID:
3062 case MLXSW_REG_PBMC_ID:
3064 case MLXSW_REG_PSPA_ID:
3066 case MLXSW_REG_HTGT_ID:
3068 case MLXSW_REG_HPKT_ID:
3070 case MLXSW_REG_MFCR_ID:
3072 case MLXSW_REG_MFSC_ID:
3074 case MLXSW_REG_MFSM_ID:
3076 case MLXSW_REG_MTCAP_ID:
3078 case MLXSW_REG_MTMP_ID:
3080 case MLXSW_REG_MLCR_ID:
3082 case MLXSW_REG_SBPR_ID:
3084 case MLXSW_REG_SBCM_ID:
3086 case MLXSW_REG_SBPM_ID:
3088 case MLXSW_REG_SBMM_ID:
3095 /* PUDE - Port Up / Down Event
3096 * ---------------------------
3097 * Reports the operational state change of a port.
3099 #define MLXSW_REG_PUDE_LEN 0x10
3102 * Switch partition ID with which to associate the port.
3105 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
3107 /* reg_pude_local_port
3108 * Local port number.
3111 MLXSW_ITEM32(reg, pude, local_port, 0x00, 16, 8);
3113 /* reg_pude_admin_status
3114 * Port administrative state (the desired state).
3117 * 3 - Up once. This means that in case of link failure, the port won't go
3118 * into polling mode, but will wait to be re-enabled by software.
3119 * 4 - Disabled by system. Can only be set by hardware.
3122 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
3124 /* reg_pude_oper_status
3125 * Port operatioanl state.
3128 * 3 - Down by port failure. This means that the device will not let the
3129 * port up again until explicitly specified by software.
3132 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);