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 /* SFD - Switch Filtering Database
161 * -------------------------------
162 * The following register defines the access to the filtering database.
163 * The register supports querying, adding, removing and modifying the database.
164 * The access is optimized for bulk updates in which case more than one
165 * FDB record is present in the same command.
167 #define MLXSW_REG_SFD_ID 0x200A
168 #define MLXSW_REG_SFD_BASE_LEN 0x10 /* base length, without records */
169 #define MLXSW_REG_SFD_REC_LEN 0x10 /* record length */
170 #define MLXSW_REG_SFD_REC_MAX_COUNT 64
171 #define MLXSW_REG_SFD_LEN (MLXSW_REG_SFD_BASE_LEN + \
172 MLXSW_REG_SFD_REC_LEN * MLXSW_REG_SFD_REC_MAX_COUNT)
174 static const struct mlxsw_reg_info mlxsw_reg_sfd = {
175 .id = MLXSW_REG_SFD_ID,
176 .len = MLXSW_REG_SFD_LEN,
180 * Switch partition ID for queries. Reserved on Write.
183 MLXSW_ITEM32(reg, sfd, swid, 0x00, 24, 8);
185 enum mlxsw_reg_sfd_op {
186 /* Dump entire FDB a (process according to record_locator) */
187 MLXSW_REG_SFD_OP_QUERY_DUMP = 0,
188 /* Query records by {MAC, VID/FID} value */
189 MLXSW_REG_SFD_OP_QUERY_QUERY = 1,
190 /* Query and clear activity. Query records by {MAC, VID/FID} value */
191 MLXSW_REG_SFD_OP_QUERY_QUERY_AND_CLEAR_ACTIVITY = 2,
192 /* Test. Response indicates if each of the records could be
195 MLXSW_REG_SFD_OP_WRITE_TEST = 0,
196 /* Add/modify. Aged-out records cannot be added. This command removes
197 * the learning notification of the {MAC, VID/FID}. Response includes
198 * the entries that were added to the FDB.
200 MLXSW_REG_SFD_OP_WRITE_EDIT = 1,
201 /* Remove record by {MAC, VID/FID}. This command also removes
202 * the learning notification and aged-out notifications
203 * of the {MAC, VID/FID}. The response provides current (pre-removal)
204 * entries as non-aged-out.
206 MLXSW_REG_SFD_OP_WRITE_REMOVE = 2,
207 /* Remove learned notification by {MAC, VID/FID}. The response provides
208 * the removed learning notification.
210 MLXSW_REG_SFD_OP_WRITE_REMOVE_NOTIFICATION = 2,
217 MLXSW_ITEM32(reg, sfd, op, 0x04, 30, 2);
219 /* reg_sfd_record_locator
220 * Used for querying the FDB. Use record_locator=0 to initiate the
221 * query. When a record is returned, a new record_locator is
222 * returned to be used in the subsequent query.
223 * Reserved for database update.
226 MLXSW_ITEM32(reg, sfd, record_locator, 0x04, 0, 30);
229 * Request: Number of records to read/add/modify/remove
230 * Response: Number of records read/added/replaced/removed
231 * See above description for more details.
235 MLXSW_ITEM32(reg, sfd, num_rec, 0x08, 0, 8);
237 static inline void mlxsw_reg_sfd_pack(char *payload, enum mlxsw_reg_sfd_op op,
240 MLXSW_REG_ZERO(sfd, payload);
241 mlxsw_reg_sfd_op_set(payload, op);
242 mlxsw_reg_sfd_record_locator_set(payload, record_locator);
246 * Switch partition ID.
249 MLXSW_ITEM32_INDEXED(reg, sfd, rec_swid, MLXSW_REG_SFD_BASE_LEN, 24, 8,
250 MLXSW_REG_SFD_REC_LEN, 0x00, false);
252 enum mlxsw_reg_sfd_rec_type {
253 MLXSW_REG_SFD_REC_TYPE_UNICAST = 0x0,
260 MLXSW_ITEM32_INDEXED(reg, sfd, rec_type, MLXSW_REG_SFD_BASE_LEN, 20, 4,
261 MLXSW_REG_SFD_REC_LEN, 0x00, false);
263 enum mlxsw_reg_sfd_rec_policy {
264 /* Replacement disabled, aging disabled. */
265 MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY = 0,
266 /* (mlag remote): Replacement enabled, aging disabled,
267 * learning notification enabled on this port.
269 MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_MLAG = 1,
270 /* (ingress device): Replacement enabled, aging enabled. */
271 MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS = 3,
274 /* reg_sfd_rec_policy
278 MLXSW_ITEM32_INDEXED(reg, sfd, rec_policy, MLXSW_REG_SFD_BASE_LEN, 18, 2,
279 MLXSW_REG_SFD_REC_LEN, 0x00, false);
282 * Activity. Set for new static entries. Set for static entries if a frame SMAC
283 * lookup hits on the entry.
284 * To clear the a bit, use "query and clear activity" op.
287 MLXSW_ITEM32_INDEXED(reg, sfd, rec_a, MLXSW_REG_SFD_BASE_LEN, 16, 1,
288 MLXSW_REG_SFD_REC_LEN, 0x00, false);
294 MLXSW_ITEM_BUF_INDEXED(reg, sfd, rec_mac, MLXSW_REG_SFD_BASE_LEN, 6,
295 MLXSW_REG_SFD_REC_LEN, 0x02);
297 enum mlxsw_reg_sfd_rec_action {
299 MLXSW_REG_SFD_REC_ACTION_NOP = 0,
300 /* forward and trap, trap_id is FDB_TRAP */
301 MLXSW_REG_SFD_REC_ACTION_MIRROR_TO_CPU = 1,
302 /* trap and do not forward, trap_id is FDB_TRAP */
303 MLXSW_REG_SFD_REC_ACTION_TRAP = 3,
304 MLXSW_REG_SFD_REC_ACTION_DISCARD_ERROR = 15,
307 /* reg_sfd_rec_action
308 * Action to apply on the packet.
309 * Note: Dynamic entries can only be configured with NOP action.
312 MLXSW_ITEM32_INDEXED(reg, sfd, rec_action, MLXSW_REG_SFD_BASE_LEN, 28, 4,
313 MLXSW_REG_SFD_REC_LEN, 0x0C, false);
315 /* reg_sfd_uc_sub_port
317 * Must be 0 if multichannel VEPA is not enabled.
320 MLXSW_ITEM32_INDEXED(reg, sfd, uc_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
321 MLXSW_REG_SFD_REC_LEN, 0x08, false);
323 /* reg_sfd_uc_fid_vid
324 * Filtering ID or VLAN ID
325 * For SwitchX and SwitchX-2:
326 * - Dynamic entries (policy 2,3) use FID
327 * - Static entries (policy 0) use VID
328 * - When independent learning is configured, VID=FID
329 * For Spectrum: use FID for both Dynamic and Static entries.
330 * VID should not be used.
333 MLXSW_ITEM32_INDEXED(reg, sfd, uc_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
334 MLXSW_REG_SFD_REC_LEN, 0x08, false);
336 /* reg_sfd_uc_system_port
337 * Unique port identifier for the final destination of the packet.
340 MLXSW_ITEM32_INDEXED(reg, sfd, uc_system_port, MLXSW_REG_SFD_BASE_LEN, 0, 16,
341 MLXSW_REG_SFD_REC_LEN, 0x0C, false);
343 static inline void mlxsw_reg_sfd_uc_pack(char *payload, int rec_index,
344 enum mlxsw_reg_sfd_rec_policy policy,
345 const char *mac, u16 vid,
346 enum mlxsw_reg_sfd_rec_action action,
349 u8 num_rec = mlxsw_reg_sfd_num_rec_get(payload);
351 if (rec_index >= num_rec)
352 mlxsw_reg_sfd_num_rec_set(payload, rec_index + 1);
353 mlxsw_reg_sfd_rec_swid_set(payload, rec_index, 0);
354 mlxsw_reg_sfd_rec_type_set(payload, rec_index,
355 MLXSW_REG_SFD_REC_TYPE_UNICAST);
356 mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
357 mlxsw_reg_sfd_rec_mac_memcpy_to(payload, rec_index, mac);
358 mlxsw_reg_sfd_uc_sub_port_set(payload, rec_index, 0);
359 mlxsw_reg_sfd_uc_fid_vid_set(payload, rec_index, vid);
360 mlxsw_reg_sfd_rec_action_set(payload, rec_index, action);
361 mlxsw_reg_sfd_uc_system_port_set(payload, rec_index, local_port);
365 mlxsw_reg_sfd_uc_unpack(char *payload, int rec_index,
366 char *mac, u16 *p_vid,
369 mlxsw_reg_sfd_rec_mac_memcpy_from(payload, rec_index, mac);
370 *p_vid = mlxsw_reg_sfd_uc_fid_vid_get(payload, rec_index);
371 *p_local_port = mlxsw_reg_sfd_uc_system_port_get(payload, rec_index);
374 /* SPMS - Switch Port MSTP/RSTP State Register
375 * -------------------------------------------
376 * Configures the spanning tree state of a physical port.
378 #define MLXSW_REG_SPMS_ID 0x200D
379 #define MLXSW_REG_SPMS_LEN 0x404
381 static const struct mlxsw_reg_info mlxsw_reg_spms = {
382 .id = MLXSW_REG_SPMS_ID,
383 .len = MLXSW_REG_SPMS_LEN,
386 /* reg_spms_local_port
390 MLXSW_ITEM32(reg, spms, local_port, 0x00, 16, 8);
392 enum mlxsw_reg_spms_state {
393 MLXSW_REG_SPMS_STATE_NO_CHANGE,
394 MLXSW_REG_SPMS_STATE_DISCARDING,
395 MLXSW_REG_SPMS_STATE_LEARNING,
396 MLXSW_REG_SPMS_STATE_FORWARDING,
400 * Spanning tree state of each VLAN ID (VID) of the local port.
401 * 0 - Do not change spanning tree state (used only when writing).
402 * 1 - Discarding. No learning or forwarding to/from this port (default).
403 * 2 - Learning. Port is learning, but not forwarding.
404 * 3 - Forwarding. Port is learning and forwarding.
407 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
409 static inline void mlxsw_reg_spms_pack(char *payload, u8 local_port)
411 MLXSW_REG_ZERO(spms, payload);
412 mlxsw_reg_spms_local_port_set(payload, local_port);
415 static inline void mlxsw_reg_spms_vid_pack(char *payload, u16 vid,
416 enum mlxsw_reg_spms_state state)
418 mlxsw_reg_spms_state_set(payload, vid, state);
421 /* SFGC - Switch Flooding Group Configuration
422 * ------------------------------------------
423 * The following register controls the association of flooding tables and MIDs
424 * to packet types used for flooding.
426 #define MLXSW_REG_SFGC_ID 0x2011
427 #define MLXSW_REG_SFGC_LEN 0x10
429 static const struct mlxsw_reg_info mlxsw_reg_sfgc = {
430 .id = MLXSW_REG_SFGC_ID,
431 .len = MLXSW_REG_SFGC_LEN,
434 enum mlxsw_reg_sfgc_type {
435 MLXSW_REG_SFGC_TYPE_BROADCAST,
436 MLXSW_REG_SFGC_TYPE_UNKNOWN_UNICAST,
437 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4,
438 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6,
439 MLXSW_REG_SFGC_TYPE_RESERVED,
440 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP,
441 MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL,
442 MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST,
443 MLXSW_REG_SFGC_TYPE_MAX,
447 * The traffic type to reach the flooding table.
450 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
452 enum mlxsw_reg_sfgc_bridge_type {
453 MLXSW_REG_SFGC_BRIDGE_TYPE_1Q_FID = 0,
454 MLXSW_REG_SFGC_BRIDGE_TYPE_VFID = 1,
457 /* reg_sfgc_bridge_type
460 * Note: SwitchX-2 only supports 802.1Q mode.
462 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
464 enum mlxsw_flood_table_type {
465 MLXSW_REG_SFGC_TABLE_TYPE_VID = 1,
466 MLXSW_REG_SFGC_TABLE_TYPE_SINGLE = 2,
467 MLXSW_REG_SFGC_TABLE_TYPE_ANY = 0,
468 MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFEST = 3,
469 MLXSW_REG_SFGC_TABLE_TYPE_FID = 4,
472 /* reg_sfgc_table_type
473 * See mlxsw_flood_table_type
476 * Note: FID offset and FID types are not supported in SwitchX-2.
478 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
480 /* reg_sfgc_flood_table
481 * Flooding table index to associate with the specific type on the specific
485 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
488 * The multicast ID for the swid. Not supported for Spectrum
491 MLXSW_ITEM32(reg, sfgc, mid, 0x08, 0, 16);
493 /* reg_sfgc_counter_set_type
494 * Counter Set Type for flow counters.
497 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
499 /* reg_sfgc_counter_index
500 * Counter Index for flow counters.
503 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
506 mlxsw_reg_sfgc_pack(char *payload, enum mlxsw_reg_sfgc_type type,
507 enum mlxsw_reg_sfgc_bridge_type bridge_type,
508 enum mlxsw_flood_table_type table_type,
509 unsigned int flood_table)
511 MLXSW_REG_ZERO(sfgc, payload);
512 mlxsw_reg_sfgc_type_set(payload, type);
513 mlxsw_reg_sfgc_bridge_type_set(payload, bridge_type);
514 mlxsw_reg_sfgc_table_type_set(payload, table_type);
515 mlxsw_reg_sfgc_flood_table_set(payload, flood_table);
516 mlxsw_reg_sfgc_mid_set(payload, MLXSW_PORT_MID);
519 /* SFTR - Switch Flooding Table Register
520 * -------------------------------------
521 * The switch flooding table is used for flooding packet replication. The table
522 * defines a bit mask of ports for packet replication.
524 #define MLXSW_REG_SFTR_ID 0x2012
525 #define MLXSW_REG_SFTR_LEN 0x420
527 static const struct mlxsw_reg_info mlxsw_reg_sftr = {
528 .id = MLXSW_REG_SFTR_ID,
529 .len = MLXSW_REG_SFTR_LEN,
533 * Switch partition ID with which to associate the port.
536 MLXSW_ITEM32(reg, sftr, swid, 0x00, 24, 8);
538 /* reg_sftr_flood_table
539 * Flooding table index to associate with the specific type on the specific
543 MLXSW_ITEM32(reg, sftr, flood_table, 0x00, 16, 6);
546 * Index. Used as an index into the Flooding Table in case the table is
547 * configured to use VID / FID or FID Offset.
550 MLXSW_ITEM32(reg, sftr, index, 0x00, 0, 16);
552 /* reg_sftr_table_type
553 * See mlxsw_flood_table_type
556 MLXSW_ITEM32(reg, sftr, table_type, 0x04, 16, 3);
559 * Range of entries to update
562 MLXSW_ITEM32(reg, sftr, range, 0x04, 0, 16);
565 * Local port membership (1 bit per port).
568 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port, 0x20, 0x20, 1);
570 /* reg_sftr_cpu_port_mask
571 * CPU port mask (1 bit per port).
574 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port_mask, 0x220, 0x20, 1);
576 static inline void mlxsw_reg_sftr_pack(char *payload,
577 unsigned int flood_table,
579 enum mlxsw_flood_table_type table_type,
580 unsigned int range, u8 port, bool set)
582 MLXSW_REG_ZERO(sftr, payload);
583 mlxsw_reg_sftr_swid_set(payload, 0);
584 mlxsw_reg_sftr_flood_table_set(payload, flood_table);
585 mlxsw_reg_sftr_index_set(payload, index);
586 mlxsw_reg_sftr_table_type_set(payload, table_type);
587 mlxsw_reg_sftr_range_set(payload, range);
588 mlxsw_reg_sftr_port_set(payload, port, set);
589 mlxsw_reg_sftr_port_mask_set(payload, port, 1);
592 /* SPMLR - Switch Port MAC Learning Register
593 * -----------------------------------------
594 * Controls the Switch MAC learning policy per port.
596 #define MLXSW_REG_SPMLR_ID 0x2018
597 #define MLXSW_REG_SPMLR_LEN 0x8
599 static const struct mlxsw_reg_info mlxsw_reg_spmlr = {
600 .id = MLXSW_REG_SPMLR_ID,
601 .len = MLXSW_REG_SPMLR_LEN,
604 /* reg_spmlr_local_port
608 MLXSW_ITEM32(reg, spmlr, local_port, 0x00, 16, 8);
610 /* reg_spmlr_sub_port
611 * Virtual port within the physical port.
612 * Should be set to 0 when virtual ports are not enabled on the port.
615 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
617 enum mlxsw_reg_spmlr_learn_mode {
618 MLXSW_REG_SPMLR_LEARN_MODE_DISABLE = 0,
619 MLXSW_REG_SPMLR_LEARN_MODE_ENABLE = 2,
620 MLXSW_REG_SPMLR_LEARN_MODE_SEC = 3,
623 /* reg_spmlr_learn_mode
624 * Learning mode on the port.
625 * 0 - Learning disabled.
626 * 2 - Learning enabled.
629 * In security mode the switch does not learn MACs on the port, but uses the
630 * SMAC to see if it exists on another ingress port. If so, the packet is
631 * classified as a bad packet and is discarded unless the software registers
632 * to receive port security error packets usign HPKT.
634 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
636 static inline void mlxsw_reg_spmlr_pack(char *payload, u8 local_port,
637 enum mlxsw_reg_spmlr_learn_mode mode)
639 MLXSW_REG_ZERO(spmlr, payload);
640 mlxsw_reg_spmlr_local_port_set(payload, local_port);
641 mlxsw_reg_spmlr_sub_port_set(payload, 0);
642 mlxsw_reg_spmlr_learn_mode_set(payload, mode);
645 /* PMLP - Ports Module to Local Port Register
646 * ------------------------------------------
647 * Configures the assignment of modules to local ports.
649 #define MLXSW_REG_PMLP_ID 0x5002
650 #define MLXSW_REG_PMLP_LEN 0x40
652 static const struct mlxsw_reg_info mlxsw_reg_pmlp = {
653 .id = MLXSW_REG_PMLP_ID,
654 .len = MLXSW_REG_PMLP_LEN,
658 * 0 - Tx value is used for both Tx and Rx.
659 * 1 - Rx value is taken from a separte field.
662 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
664 /* reg_pmlp_local_port
668 MLXSW_ITEM32(reg, pmlp, local_port, 0x00, 16, 8);
671 * 0 - Unmap local port.
672 * 1 - Lane 0 is used.
673 * 2 - Lanes 0 and 1 are used.
674 * 4 - Lanes 0, 1, 2 and 3 are used.
677 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
683 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0, false);
686 * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
689 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 2, 0x04, 16, false);
692 * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
696 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 2, 0x04, 24, false);
698 static inline void mlxsw_reg_pmlp_pack(char *payload, u8 local_port)
700 MLXSW_REG_ZERO(pmlp, payload);
701 mlxsw_reg_pmlp_local_port_set(payload, local_port);
704 /* PMTU - Port MTU Register
705 * ------------------------
706 * Configures and reports the port MTU.
708 #define MLXSW_REG_PMTU_ID 0x5003
709 #define MLXSW_REG_PMTU_LEN 0x10
711 static const struct mlxsw_reg_info mlxsw_reg_pmtu = {
712 .id = MLXSW_REG_PMTU_ID,
713 .len = MLXSW_REG_PMTU_LEN,
716 /* reg_pmtu_local_port
720 MLXSW_ITEM32(reg, pmtu, local_port, 0x00, 16, 8);
724 * When port type (e.g. Ethernet) is configured, the relevant MTU is
725 * reported, otherwise the minimum between the max_mtu of the different
729 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
731 /* reg_pmtu_admin_mtu
732 * MTU value to set port to. Must be smaller or equal to max_mtu.
733 * Note: If port type is Infiniband, then port must be disabled, when its
737 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
740 * The actual MTU configured on the port. Packets exceeding this size
742 * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
743 * oper_mtu might be smaller than admin_mtu.
746 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
748 static inline void mlxsw_reg_pmtu_pack(char *payload, u8 local_port,
751 MLXSW_REG_ZERO(pmtu, payload);
752 mlxsw_reg_pmtu_local_port_set(payload, local_port);
753 mlxsw_reg_pmtu_max_mtu_set(payload, 0);
754 mlxsw_reg_pmtu_admin_mtu_set(payload, new_mtu);
755 mlxsw_reg_pmtu_oper_mtu_set(payload, 0);
758 /* PTYS - Port Type and Speed Register
759 * -----------------------------------
760 * Configures and reports the port speed type.
762 * Note: When set while the link is up, the changes will not take effect
763 * until the port transitions from down to up state.
765 #define MLXSW_REG_PTYS_ID 0x5004
766 #define MLXSW_REG_PTYS_LEN 0x40
768 static const struct mlxsw_reg_info mlxsw_reg_ptys = {
769 .id = MLXSW_REG_PTYS_ID,
770 .len = MLXSW_REG_PTYS_LEN,
773 /* reg_ptys_local_port
777 MLXSW_ITEM32(reg, ptys, local_port, 0x00, 16, 8);
779 #define MLXSW_REG_PTYS_PROTO_MASK_ETH BIT(2)
781 /* reg_ptys_proto_mask
782 * Protocol mask. Indicates which protocol is used.
788 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
790 #define MLXSW_REG_PTYS_ETH_SPEED_SGMII BIT(0)
791 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX BIT(1)
792 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4 BIT(2)
793 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4 BIT(3)
794 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR BIT(4)
795 #define MLXSW_REG_PTYS_ETH_SPEED_20GBASE_KR2 BIT(5)
796 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4 BIT(6)
797 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4 BIT(7)
798 #define MLXSW_REG_PTYS_ETH_SPEED_56GBASE_R4 BIT(8)
799 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR BIT(12)
800 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR BIT(13)
801 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR BIT(14)
802 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4 BIT(15)
803 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4 BIT(16)
804 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR4 BIT(19)
805 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4 BIT(20)
806 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4 BIT(21)
807 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4 BIT(22)
808 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4 BIT(23)
809 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_TX BIT(24)
810 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_T BIT(25)
811 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_T BIT(26)
812 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR BIT(27)
813 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR BIT(28)
814 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR BIT(29)
815 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2 BIT(30)
816 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2 BIT(31)
818 /* reg_ptys_eth_proto_cap
819 * Ethernet port supported speeds and protocols.
822 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
824 /* reg_ptys_eth_proto_admin
825 * Speed and protocol to set port to.
828 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
830 /* reg_ptys_eth_proto_oper
831 * The current speed and protocol configured for the port.
834 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
836 static inline void mlxsw_reg_ptys_pack(char *payload, u8 local_port,
839 MLXSW_REG_ZERO(ptys, payload);
840 mlxsw_reg_ptys_local_port_set(payload, local_port);
841 mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
842 mlxsw_reg_ptys_eth_proto_admin_set(payload, proto_admin);
845 static inline void mlxsw_reg_ptys_unpack(char *payload, u32 *p_eth_proto_cap,
846 u32 *p_eth_proto_adm,
847 u32 *p_eth_proto_oper)
850 *p_eth_proto_cap = mlxsw_reg_ptys_eth_proto_cap_get(payload);
852 *p_eth_proto_adm = mlxsw_reg_ptys_eth_proto_admin_get(payload);
853 if (p_eth_proto_oper)
854 *p_eth_proto_oper = mlxsw_reg_ptys_eth_proto_oper_get(payload);
857 /* PPAD - Port Physical Address Register
858 * -------------------------------------
859 * The PPAD register configures the per port physical MAC address.
861 #define MLXSW_REG_PPAD_ID 0x5005
862 #define MLXSW_REG_PPAD_LEN 0x10
864 static const struct mlxsw_reg_info mlxsw_reg_ppad = {
865 .id = MLXSW_REG_PPAD_ID,
866 .len = MLXSW_REG_PPAD_LEN,
869 /* reg_ppad_single_base_mac
870 * 0: base_mac, local port should be 0 and mac[7:0] is
871 * reserved. HW will set incremental
872 * 1: single_mac - mac of the local_port
875 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
877 /* reg_ppad_local_port
878 * port number, if single_base_mac = 0 then local_port is reserved
881 MLXSW_ITEM32(reg, ppad, local_port, 0x00, 16, 8);
884 * If single_base_mac = 0 - base MAC address, mac[7:0] is reserved.
885 * If single_base_mac = 1 - the per port MAC address
888 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
890 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
893 MLXSW_REG_ZERO(ppad, payload);
894 mlxsw_reg_ppad_single_base_mac_set(payload, !!single_base_mac);
895 mlxsw_reg_ppad_local_port_set(payload, local_port);
898 /* PAOS - Ports Administrative and Operational Status Register
899 * -----------------------------------------------------------
900 * Configures and retrieves per port administrative and operational status.
902 #define MLXSW_REG_PAOS_ID 0x5006
903 #define MLXSW_REG_PAOS_LEN 0x10
905 static const struct mlxsw_reg_info mlxsw_reg_paos = {
906 .id = MLXSW_REG_PAOS_ID,
907 .len = MLXSW_REG_PAOS_LEN,
911 * Switch partition ID with which to associate the port.
912 * Note: while external ports uses unique local port numbers (and thus swid is
913 * redundant), router ports use the same local port number where swid is the
914 * only indication for the relevant port.
917 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
919 /* reg_paos_local_port
923 MLXSW_ITEM32(reg, paos, local_port, 0x00, 16, 8);
925 /* reg_paos_admin_status
926 * Port administrative state (the desired state of the port):
929 * 3 - Up once. This means that in case of link failure, the port won't go
930 * into polling mode, but will wait to be re-enabled by software.
931 * 4 - Disabled by system. Can only be set by hardware.
934 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
936 /* reg_paos_oper_status
937 * Port operational state (the current state):
940 * 3 - Down by port failure. This means that the device will not let the
941 * port up again until explicitly specified by software.
944 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
947 * Admin state update enabled.
950 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
953 * Event update enable. If this bit is set, event generation will be
954 * updated based on the e field.
957 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
960 * Event generation on operational state change:
961 * 0 - Do not generate event.
962 * 1 - Generate Event.
963 * 2 - Generate Single Event.
966 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
968 static inline void mlxsw_reg_paos_pack(char *payload, u8 local_port,
969 enum mlxsw_port_admin_status status)
971 MLXSW_REG_ZERO(paos, payload);
972 mlxsw_reg_paos_swid_set(payload, 0);
973 mlxsw_reg_paos_local_port_set(payload, local_port);
974 mlxsw_reg_paos_admin_status_set(payload, status);
975 mlxsw_reg_paos_oper_status_set(payload, 0);
976 mlxsw_reg_paos_ase_set(payload, 1);
977 mlxsw_reg_paos_ee_set(payload, 1);
978 mlxsw_reg_paos_e_set(payload, 1);
981 /* PPCNT - Ports Performance Counters Register
982 * -------------------------------------------
983 * The PPCNT register retrieves per port performance counters.
985 #define MLXSW_REG_PPCNT_ID 0x5008
986 #define MLXSW_REG_PPCNT_LEN 0x100
988 static const struct mlxsw_reg_info mlxsw_reg_ppcnt = {
989 .id = MLXSW_REG_PPCNT_ID,
990 .len = MLXSW_REG_PPCNT_LEN,
994 * For HCA: must be always 0.
995 * Switch partition ID to associate port with.
996 * Switch partitions are numbered from 0 to 7 inclusively.
997 * Switch partition 254 indicates stacking ports.
998 * Switch partition 255 indicates all switch partitions.
999 * Only valid on Set() operation with local_port=255.
1002 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
1004 /* reg_ppcnt_local_port
1005 * Local port number.
1006 * 255 indicates all ports on the device, and is only allowed
1007 * for Set() operation.
1010 MLXSW_ITEM32(reg, ppcnt, local_port, 0x00, 16, 8);
1013 * Port number access type:
1014 * 0 - Local port number
1015 * 1 - IB port number
1018 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
1021 * Performance counter group.
1022 * Group 63 indicates all groups. Only valid on Set() operation with
1024 * 0x0: IEEE 802.3 Counters
1025 * 0x1: RFC 2863 Counters
1026 * 0x2: RFC 2819 Counters
1027 * 0x3: RFC 3635 Counters
1028 * 0x5: Ethernet Extended Counters
1029 * 0x8: Link Level Retransmission Counters
1030 * 0x10: Per Priority Counters
1031 * 0x11: Per Traffic Class Counters
1032 * 0x12: Physical Layer Counters
1035 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
1038 * Clear counters. Setting the clr bit will reset the counter value
1039 * for all counters in the counter group. This bit can be set
1040 * for both Set() and Get() operation.
1043 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
1045 /* reg_ppcnt_prio_tc
1046 * Priority for counter set that support per priority, valid values: 0-7.
1047 * Traffic class for counter set that support per traffic class,
1048 * valid values: 0- cap_max_tclass-1 .
1049 * For HCA: cap_max_tclass is always 8.
1050 * Otherwise must be 0.
1053 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
1055 /* reg_ppcnt_a_frames_transmitted_ok
1058 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
1059 0x08 + 0x00, 0, 64);
1061 /* reg_ppcnt_a_frames_received_ok
1064 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
1065 0x08 + 0x08, 0, 64);
1067 /* reg_ppcnt_a_frame_check_sequence_errors
1070 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
1071 0x08 + 0x10, 0, 64);
1073 /* reg_ppcnt_a_alignment_errors
1076 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
1077 0x08 + 0x18, 0, 64);
1079 /* reg_ppcnt_a_octets_transmitted_ok
1082 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
1083 0x08 + 0x20, 0, 64);
1085 /* reg_ppcnt_a_octets_received_ok
1088 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
1089 0x08 + 0x28, 0, 64);
1091 /* reg_ppcnt_a_multicast_frames_xmitted_ok
1094 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
1095 0x08 + 0x30, 0, 64);
1097 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
1100 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
1101 0x08 + 0x38, 0, 64);
1103 /* reg_ppcnt_a_multicast_frames_received_ok
1106 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
1107 0x08 + 0x40, 0, 64);
1109 /* reg_ppcnt_a_broadcast_frames_received_ok
1112 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
1113 0x08 + 0x48, 0, 64);
1115 /* reg_ppcnt_a_in_range_length_errors
1118 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
1119 0x08 + 0x50, 0, 64);
1121 /* reg_ppcnt_a_out_of_range_length_field
1124 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
1125 0x08 + 0x58, 0, 64);
1127 /* reg_ppcnt_a_frame_too_long_errors
1130 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
1131 0x08 + 0x60, 0, 64);
1133 /* reg_ppcnt_a_symbol_error_during_carrier
1136 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
1137 0x08 + 0x68, 0, 64);
1139 /* reg_ppcnt_a_mac_control_frames_transmitted
1142 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
1143 0x08 + 0x70, 0, 64);
1145 /* reg_ppcnt_a_mac_control_frames_received
1148 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
1149 0x08 + 0x78, 0, 64);
1151 /* reg_ppcnt_a_unsupported_opcodes_received
1154 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
1155 0x08 + 0x80, 0, 64);
1157 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
1160 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
1161 0x08 + 0x88, 0, 64);
1163 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
1166 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
1167 0x08 + 0x90, 0, 64);
1169 static inline void mlxsw_reg_ppcnt_pack(char *payload, u8 local_port)
1171 MLXSW_REG_ZERO(ppcnt, payload);
1172 mlxsw_reg_ppcnt_swid_set(payload, 0);
1173 mlxsw_reg_ppcnt_local_port_set(payload, local_port);
1174 mlxsw_reg_ppcnt_pnat_set(payload, 0);
1175 mlxsw_reg_ppcnt_grp_set(payload, 0);
1176 mlxsw_reg_ppcnt_clr_set(payload, 0);
1177 mlxsw_reg_ppcnt_prio_tc_set(payload, 0);
1180 /* PSPA - Port Switch Partition Allocation
1181 * ---------------------------------------
1182 * Controls the association of a port with a switch partition and enables
1183 * configuring ports as stacking ports.
1185 #define MLXSW_REG_PSPA_ID 0x500D
1186 #define MLXSW_REG_PSPA_LEN 0x8
1188 static const struct mlxsw_reg_info mlxsw_reg_pspa = {
1189 .id = MLXSW_REG_PSPA_ID,
1190 .len = MLXSW_REG_PSPA_LEN,
1194 * Switch partition ID.
1197 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
1199 /* reg_pspa_local_port
1200 * Local port number.
1203 MLXSW_ITEM32(reg, pspa, local_port, 0x00, 16, 8);
1205 /* reg_pspa_sub_port
1206 * Virtual port within the local port. Set to 0 when virtual ports are
1207 * disabled on the local port.
1210 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
1212 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
1214 MLXSW_REG_ZERO(pspa, payload);
1215 mlxsw_reg_pspa_swid_set(payload, swid);
1216 mlxsw_reg_pspa_local_port_set(payload, local_port);
1217 mlxsw_reg_pspa_sub_port_set(payload, 0);
1220 /* HTGT - Host Trap Group Table
1221 * ----------------------------
1222 * Configures the properties for forwarding to CPU.
1224 #define MLXSW_REG_HTGT_ID 0x7002
1225 #define MLXSW_REG_HTGT_LEN 0x100
1227 static const struct mlxsw_reg_info mlxsw_reg_htgt = {
1228 .id = MLXSW_REG_HTGT_ID,
1229 .len = MLXSW_REG_HTGT_LEN,
1233 * Switch partition ID.
1236 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
1238 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0 /* For locally attached CPU */
1244 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
1246 enum mlxsw_reg_htgt_trap_group {
1247 MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
1248 MLXSW_REG_HTGT_TRAP_GROUP_RX,
1249 MLXSW_REG_HTGT_TRAP_GROUP_CTRL,
1252 /* reg_htgt_trap_group
1253 * Trap group number. User defined number specifying which trap groups
1254 * should be forwarded to the CPU. The mapping between trap IDs and trap
1255 * groups is configured using HPKT register.
1258 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
1261 MLXSW_REG_HTGT_POLICER_DISABLE,
1262 MLXSW_REG_HTGT_POLICER_ENABLE,
1266 * Enable policer ID specified using 'pid' field.
1269 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
1272 * Policer ID for the trap group.
1275 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
1277 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
1279 /* reg_htgt_mirror_action
1280 * Mirror action to use.
1282 * 1 - Trap to CPU and mirror to a mirroring agent.
1283 * 2 - Mirror to a mirroring agent and do not trap to CPU.
1286 * Note: Mirroring to a mirroring agent is only supported in Spectrum.
1288 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
1290 /* reg_htgt_mirroring_agent
1294 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
1296 /* reg_htgt_priority
1297 * Trap group priority.
1298 * In case a packet matches multiple classification rules, the packet will
1299 * only be trapped once, based on the trap ID associated with the group (via
1300 * register HPKT) with the highest priority.
1301 * Supported values are 0-7, with 7 represnting the highest priority.
1304 * Note: In SwitchX-2 this field is ignored and the priority value is replaced
1305 * by the 'trap_group' field.
1307 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
1309 /* reg_htgt_local_path_cpu_tclass
1310 * CPU ingress traffic class for the trap group.
1313 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
1315 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD 0x15
1316 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX 0x14
1317 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL 0x13
1319 /* reg_htgt_local_path_rdq
1320 * Receive descriptor queue (RDQ) to use for the trap group.
1323 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
1325 static inline void mlxsw_reg_htgt_pack(char *payload,
1326 enum mlxsw_reg_htgt_trap_group group)
1330 MLXSW_REG_ZERO(htgt, payload);
1332 case MLXSW_REG_HTGT_TRAP_GROUP_EMAD:
1333 swid = MLXSW_PORT_SWID_ALL_SWIDS;
1334 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD;
1336 case MLXSW_REG_HTGT_TRAP_GROUP_RX:
1338 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX;
1340 case MLXSW_REG_HTGT_TRAP_GROUP_CTRL:
1342 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL;
1345 mlxsw_reg_htgt_swid_set(payload, swid);
1346 mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
1347 mlxsw_reg_htgt_trap_group_set(payload, group);
1348 mlxsw_reg_htgt_pide_set(payload, MLXSW_REG_HTGT_POLICER_DISABLE);
1349 mlxsw_reg_htgt_pid_set(payload, 0);
1350 mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
1351 mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
1352 mlxsw_reg_htgt_priority_set(payload, 0);
1353 mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, 7);
1354 mlxsw_reg_htgt_local_path_rdq_set(payload, rdq);
1357 /* HPKT - Host Packet Trap
1358 * -----------------------
1359 * Configures trap IDs inside trap groups.
1361 #define MLXSW_REG_HPKT_ID 0x7003
1362 #define MLXSW_REG_HPKT_LEN 0x10
1364 static const struct mlxsw_reg_info mlxsw_reg_hpkt = {
1365 .id = MLXSW_REG_HPKT_ID,
1366 .len = MLXSW_REG_HPKT_LEN,
1370 MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
1371 MLXSW_REG_HPKT_ACK_REQUIRED,
1375 * Require acknowledgements from the host for events.
1376 * If set, then the device will wait for the event it sent to be acknowledged
1377 * by the host. This option is only relevant for event trap IDs.
1380 * Note: Currently not supported by firmware.
1382 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
1384 enum mlxsw_reg_hpkt_action {
1385 MLXSW_REG_HPKT_ACTION_FORWARD,
1386 MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
1387 MLXSW_REG_HPKT_ACTION_MIRROR_TO_CPU,
1388 MLXSW_REG_HPKT_ACTION_DISCARD,
1389 MLXSW_REG_HPKT_ACTION_SOFT_DISCARD,
1390 MLXSW_REG_HPKT_ACTION_TRAP_AND_SOFT_DISCARD,
1394 * Action to perform on packet when trapped.
1395 * 0 - No action. Forward to CPU based on switching rules.
1396 * 1 - Trap to CPU (CPU receives sole copy).
1397 * 2 - Mirror to CPU (CPU receives a replica of the packet).
1399 * 4 - Soft discard (allow other traps to act on the packet).
1400 * 5 - Trap and soft discard (allow other traps to overwrite this trap).
1403 * Note: Must be set to 0 (forward) for event trap IDs, as they are already
1404 * addressed to the CPU.
1406 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
1408 /* reg_hpkt_trap_group
1409 * Trap group to associate the trap with.
1412 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
1418 * Note: A trap ID can only be associated with a single trap group. The device
1419 * will associate the trap ID with the last trap group configured.
1421 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 9);
1424 MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
1425 MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
1426 MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
1430 * Configure dedicated buffer resources for control packets.
1431 * 0 - Keep factory defaults.
1432 * 1 - Do not use control buffer for this trap ID.
1433 * 2 - Use control buffer for this trap ID.
1436 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
1438 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id)
1440 enum mlxsw_reg_htgt_trap_group trap_group;
1442 MLXSW_REG_ZERO(hpkt, payload);
1443 mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
1444 mlxsw_reg_hpkt_action_set(payload, action);
1446 case MLXSW_TRAP_ID_ETHEMAD:
1447 case MLXSW_TRAP_ID_PUDE:
1448 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_EMAD;
1451 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_RX;
1454 mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
1455 mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
1456 mlxsw_reg_hpkt_ctrl_set(payload, MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT);
1459 static inline const char *mlxsw_reg_id_str(u16 reg_id)
1462 case MLXSW_REG_SGCR_ID:
1464 case MLXSW_REG_SPAD_ID:
1466 case MLXSW_REG_SSPR_ID:
1468 case MLXSW_REG_SFD_ID:
1470 case MLXSW_REG_SPMS_ID:
1472 case MLXSW_REG_SFGC_ID:
1474 case MLXSW_REG_SFTR_ID:
1476 case MLXSW_REG_SPMLR_ID:
1478 case MLXSW_REG_PMLP_ID:
1480 case MLXSW_REG_PMTU_ID:
1482 case MLXSW_REG_PTYS_ID:
1484 case MLXSW_REG_PPAD_ID:
1486 case MLXSW_REG_PAOS_ID:
1488 case MLXSW_REG_PPCNT_ID:
1490 case MLXSW_REG_PSPA_ID:
1492 case MLXSW_REG_HTGT_ID:
1494 case MLXSW_REG_HPKT_ID:
1501 /* PUDE - Port Up / Down Event
1502 * ---------------------------
1503 * Reports the operational state change of a port.
1505 #define MLXSW_REG_PUDE_LEN 0x10
1508 * Switch partition ID with which to associate the port.
1511 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
1513 /* reg_pude_local_port
1514 * Local port number.
1517 MLXSW_ITEM32(reg, pude, local_port, 0x00, 16, 8);
1519 /* reg_pude_admin_status
1520 * Port administrative state (the desired state).
1523 * 3 - Up once. This means that in case of link failure, the port won't go
1524 * into polling mode, but will wait to be re-enabled by software.
1525 * 4 - Disabled by system. Can only be set by hardware.
1528 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
1530 /* reg_pude_oper_status
1531 * Port operatioanl state.
1534 * 3 - Down by port failure. This means that the device will not let the
1535 * port up again until explicitly specified by software.
1538 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);