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 /* SPMS - Switch Port MSTP/RSTP State Register
161 * -------------------------------------------
162 * Configures the spanning tree state of a physical port.
164 #define MLXSW_REG_SPMS_ID 0x200D
165 #define MLXSW_REG_SPMS_LEN 0x404
167 static const struct mlxsw_reg_info mlxsw_reg_spms = {
168 .id = MLXSW_REG_SPMS_ID,
169 .len = MLXSW_REG_SPMS_LEN,
172 /* reg_spms_local_port
176 MLXSW_ITEM32(reg, spms, local_port, 0x00, 16, 8);
178 enum mlxsw_reg_spms_state {
179 MLXSW_REG_SPMS_STATE_NO_CHANGE,
180 MLXSW_REG_SPMS_STATE_DISCARDING,
181 MLXSW_REG_SPMS_STATE_LEARNING,
182 MLXSW_REG_SPMS_STATE_FORWARDING,
186 * Spanning tree state of each VLAN ID (VID) of the local port.
187 * 0 - Do not change spanning tree state (used only when writing).
188 * 1 - Discarding. No learning or forwarding to/from this port (default).
189 * 2 - Learning. Port is learning, but not forwarding.
190 * 3 - Forwarding. Port is learning and forwarding.
193 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
195 static inline void mlxsw_reg_spms_pack(char *payload, u8 local_port)
197 MLXSW_REG_ZERO(spms, payload);
198 mlxsw_reg_spms_local_port_set(payload, local_port);
201 static inline void mlxsw_reg_spms_vid_pack(char *payload, u16 vid,
202 enum mlxsw_reg_spms_state state)
204 mlxsw_reg_spms_state_set(payload, vid, state);
207 /* SFGC - Switch Flooding Group Configuration
208 * ------------------------------------------
209 * The following register controls the association of flooding tables and MIDs
210 * to packet types used for flooding.
212 #define MLXSW_REG_SFGC_ID 0x2011
213 #define MLXSW_REG_SFGC_LEN 0x10
215 static const struct mlxsw_reg_info mlxsw_reg_sfgc = {
216 .id = MLXSW_REG_SFGC_ID,
217 .len = MLXSW_REG_SFGC_LEN,
220 enum mlxsw_reg_sfgc_type {
221 MLXSW_REG_SFGC_TYPE_BROADCAST,
222 MLXSW_REG_SFGC_TYPE_UNKNOWN_UNICAST,
223 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4,
224 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6,
225 MLXSW_REG_SFGC_TYPE_RESERVED,
226 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP,
227 MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL,
228 MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST,
229 MLXSW_REG_SFGC_TYPE_MAX,
233 * The traffic type to reach the flooding table.
236 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
238 enum mlxsw_reg_sfgc_bridge_type {
239 MLXSW_REG_SFGC_BRIDGE_TYPE_1Q_FID = 0,
240 MLXSW_REG_SFGC_BRIDGE_TYPE_VFID = 1,
243 /* reg_sfgc_bridge_type
246 * Note: SwitchX-2 only supports 802.1Q mode.
248 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
250 enum mlxsw_flood_table_type {
251 MLXSW_REG_SFGC_TABLE_TYPE_VID = 1,
252 MLXSW_REG_SFGC_TABLE_TYPE_SINGLE = 2,
253 MLXSW_REG_SFGC_TABLE_TYPE_ANY = 0,
254 MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFEST = 3,
255 MLXSW_REG_SFGC_TABLE_TYPE_FID = 4,
258 /* reg_sfgc_table_type
259 * See mlxsw_flood_table_type
262 * Note: FID offset and FID types are not supported in SwitchX-2.
264 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
266 /* reg_sfgc_flood_table
267 * Flooding table index to associate with the specific type on the specific
271 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
274 * The multicast ID for the swid. Not supported for Spectrum
277 MLXSW_ITEM32(reg, sfgc, mid, 0x08, 0, 16);
279 /* reg_sfgc_counter_set_type
280 * Counter Set Type for flow counters.
283 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
285 /* reg_sfgc_counter_index
286 * Counter Index for flow counters.
289 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
292 mlxsw_reg_sfgc_pack(char *payload, enum mlxsw_reg_sfgc_type type,
293 enum mlxsw_reg_sfgc_bridge_type bridge_type,
294 enum mlxsw_flood_table_type table_type,
295 unsigned int flood_table)
297 MLXSW_REG_ZERO(sfgc, payload);
298 mlxsw_reg_sfgc_type_set(payload, type);
299 mlxsw_reg_sfgc_bridge_type_set(payload, bridge_type);
300 mlxsw_reg_sfgc_table_type_set(payload, table_type);
301 mlxsw_reg_sfgc_flood_table_set(payload, flood_table);
302 mlxsw_reg_sfgc_mid_set(payload, MLXSW_PORT_MID);
305 /* SFTR - Switch Flooding Table Register
306 * -------------------------------------
307 * The switch flooding table is used for flooding packet replication. The table
308 * defines a bit mask of ports for packet replication.
310 #define MLXSW_REG_SFTR_ID 0x2012
311 #define MLXSW_REG_SFTR_LEN 0x420
313 static const struct mlxsw_reg_info mlxsw_reg_sftr = {
314 .id = MLXSW_REG_SFTR_ID,
315 .len = MLXSW_REG_SFTR_LEN,
319 * Switch partition ID with which to associate the port.
322 MLXSW_ITEM32(reg, sftr, swid, 0x00, 24, 8);
324 /* reg_sftr_flood_table
325 * Flooding table index to associate with the specific type on the specific
329 MLXSW_ITEM32(reg, sftr, flood_table, 0x00, 16, 6);
332 * Index. Used as an index into the Flooding Table in case the table is
333 * configured to use VID / FID or FID Offset.
336 MLXSW_ITEM32(reg, sftr, index, 0x00, 0, 16);
338 /* reg_sftr_table_type
339 * See mlxsw_flood_table_type
342 MLXSW_ITEM32(reg, sftr, table_type, 0x04, 16, 3);
345 * Range of entries to update
348 MLXSW_ITEM32(reg, sftr, range, 0x04, 0, 16);
351 * Local port membership (1 bit per port).
354 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port, 0x20, 0x20, 1);
356 /* reg_sftr_cpu_port_mask
357 * CPU port mask (1 bit per port).
360 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port_mask, 0x220, 0x20, 1);
362 static inline void mlxsw_reg_sftr_pack(char *payload,
363 unsigned int flood_table,
365 enum mlxsw_flood_table_type table_type,
366 unsigned int range, u8 port, bool set)
368 MLXSW_REG_ZERO(sftr, payload);
369 mlxsw_reg_sftr_swid_set(payload, 0);
370 mlxsw_reg_sftr_flood_table_set(payload, flood_table);
371 mlxsw_reg_sftr_index_set(payload, index);
372 mlxsw_reg_sftr_table_type_set(payload, table_type);
373 mlxsw_reg_sftr_range_set(payload, range);
374 mlxsw_reg_sftr_port_set(payload, port, set);
375 mlxsw_reg_sftr_port_mask_set(payload, port, 1);
378 /* SPMLR - Switch Port MAC Learning Register
379 * -----------------------------------------
380 * Controls the Switch MAC learning policy per port.
382 #define MLXSW_REG_SPMLR_ID 0x2018
383 #define MLXSW_REG_SPMLR_LEN 0x8
385 static const struct mlxsw_reg_info mlxsw_reg_spmlr = {
386 .id = MLXSW_REG_SPMLR_ID,
387 .len = MLXSW_REG_SPMLR_LEN,
390 /* reg_spmlr_local_port
394 MLXSW_ITEM32(reg, spmlr, local_port, 0x00, 16, 8);
396 /* reg_spmlr_sub_port
397 * Virtual port within the physical port.
398 * Should be set to 0 when virtual ports are not enabled on the port.
401 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
403 enum mlxsw_reg_spmlr_learn_mode {
404 MLXSW_REG_SPMLR_LEARN_MODE_DISABLE = 0,
405 MLXSW_REG_SPMLR_LEARN_MODE_ENABLE = 2,
406 MLXSW_REG_SPMLR_LEARN_MODE_SEC = 3,
409 /* reg_spmlr_learn_mode
410 * Learning mode on the port.
411 * 0 - Learning disabled.
412 * 2 - Learning enabled.
415 * In security mode the switch does not learn MACs on the port, but uses the
416 * SMAC to see if it exists on another ingress port. If so, the packet is
417 * classified as a bad packet and is discarded unless the software registers
418 * to receive port security error packets usign HPKT.
420 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
422 static inline void mlxsw_reg_spmlr_pack(char *payload, u8 local_port,
423 enum mlxsw_reg_spmlr_learn_mode mode)
425 MLXSW_REG_ZERO(spmlr, payload);
426 mlxsw_reg_spmlr_local_port_set(payload, local_port);
427 mlxsw_reg_spmlr_sub_port_set(payload, 0);
428 mlxsw_reg_spmlr_learn_mode_set(payload, mode);
431 /* PMLP - Ports Module to Local Port Register
432 * ------------------------------------------
433 * Configures the assignment of modules to local ports.
435 #define MLXSW_REG_PMLP_ID 0x5002
436 #define MLXSW_REG_PMLP_LEN 0x40
438 static const struct mlxsw_reg_info mlxsw_reg_pmlp = {
439 .id = MLXSW_REG_PMLP_ID,
440 .len = MLXSW_REG_PMLP_LEN,
444 * 0 - Tx value is used for both Tx and Rx.
445 * 1 - Rx value is taken from a separte field.
448 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
450 /* reg_pmlp_local_port
454 MLXSW_ITEM32(reg, pmlp, local_port, 0x00, 16, 8);
457 * 0 - Unmap local port.
458 * 1 - Lane 0 is used.
459 * 2 - Lanes 0 and 1 are used.
460 * 4 - Lanes 0, 1, 2 and 3 are used.
463 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
469 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0, false);
472 * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
475 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 2, 0x04, 16, false);
478 * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
482 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 2, 0x04, 24, false);
484 static inline void mlxsw_reg_pmlp_pack(char *payload, u8 local_port)
486 MLXSW_REG_ZERO(pmlp, payload);
487 mlxsw_reg_pmlp_local_port_set(payload, local_port);
490 /* PMTU - Port MTU Register
491 * ------------------------
492 * Configures and reports the port MTU.
494 #define MLXSW_REG_PMTU_ID 0x5003
495 #define MLXSW_REG_PMTU_LEN 0x10
497 static const struct mlxsw_reg_info mlxsw_reg_pmtu = {
498 .id = MLXSW_REG_PMTU_ID,
499 .len = MLXSW_REG_PMTU_LEN,
502 /* reg_pmtu_local_port
506 MLXSW_ITEM32(reg, pmtu, local_port, 0x00, 16, 8);
510 * When port type (e.g. Ethernet) is configured, the relevant MTU is
511 * reported, otherwise the minimum between the max_mtu of the different
515 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
517 /* reg_pmtu_admin_mtu
518 * MTU value to set port to. Must be smaller or equal to max_mtu.
519 * Note: If port type is Infiniband, then port must be disabled, when its
523 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
526 * The actual MTU configured on the port. Packets exceeding this size
528 * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
529 * oper_mtu might be smaller than admin_mtu.
532 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
534 static inline void mlxsw_reg_pmtu_pack(char *payload, u8 local_port,
537 MLXSW_REG_ZERO(pmtu, payload);
538 mlxsw_reg_pmtu_local_port_set(payload, local_port);
539 mlxsw_reg_pmtu_max_mtu_set(payload, 0);
540 mlxsw_reg_pmtu_admin_mtu_set(payload, new_mtu);
541 mlxsw_reg_pmtu_oper_mtu_set(payload, 0);
544 /* PTYS - Port Type and Speed Register
545 * -----------------------------------
546 * Configures and reports the port speed type.
548 * Note: When set while the link is up, the changes will not take effect
549 * until the port transitions from down to up state.
551 #define MLXSW_REG_PTYS_ID 0x5004
552 #define MLXSW_REG_PTYS_LEN 0x40
554 static const struct mlxsw_reg_info mlxsw_reg_ptys = {
555 .id = MLXSW_REG_PTYS_ID,
556 .len = MLXSW_REG_PTYS_LEN,
559 /* reg_ptys_local_port
563 MLXSW_ITEM32(reg, ptys, local_port, 0x00, 16, 8);
565 #define MLXSW_REG_PTYS_PROTO_MASK_ETH BIT(2)
567 /* reg_ptys_proto_mask
568 * Protocol mask. Indicates which protocol is used.
574 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
576 #define MLXSW_REG_PTYS_ETH_SPEED_SGMII BIT(0)
577 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX BIT(1)
578 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4 BIT(2)
579 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4 BIT(3)
580 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR BIT(4)
581 #define MLXSW_REG_PTYS_ETH_SPEED_20GBASE_KR2 BIT(5)
582 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4 BIT(6)
583 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4 BIT(7)
584 #define MLXSW_REG_PTYS_ETH_SPEED_56GBASE_R4 BIT(8)
585 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR BIT(12)
586 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR BIT(13)
587 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR BIT(14)
588 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4 BIT(15)
589 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4 BIT(16)
590 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR4 BIT(19)
591 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4 BIT(20)
592 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4 BIT(21)
593 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4 BIT(22)
594 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4 BIT(23)
595 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_TX BIT(24)
596 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_T BIT(25)
597 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_T BIT(26)
598 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR BIT(27)
599 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR BIT(28)
600 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR BIT(29)
601 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2 BIT(30)
602 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2 BIT(31)
604 /* reg_ptys_eth_proto_cap
605 * Ethernet port supported speeds and protocols.
608 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
610 /* reg_ptys_eth_proto_admin
611 * Speed and protocol to set port to.
614 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
616 /* reg_ptys_eth_proto_oper
617 * The current speed and protocol configured for the port.
620 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
622 static inline void mlxsw_reg_ptys_pack(char *payload, u8 local_port,
625 MLXSW_REG_ZERO(ptys, payload);
626 mlxsw_reg_ptys_local_port_set(payload, local_port);
627 mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
628 mlxsw_reg_ptys_eth_proto_admin_set(payload, proto_admin);
631 static inline void mlxsw_reg_ptys_unpack(char *payload, u32 *p_eth_proto_cap,
632 u32 *p_eth_proto_adm,
633 u32 *p_eth_proto_oper)
636 *p_eth_proto_cap = mlxsw_reg_ptys_eth_proto_cap_get(payload);
638 *p_eth_proto_adm = mlxsw_reg_ptys_eth_proto_admin_get(payload);
639 if (p_eth_proto_oper)
640 *p_eth_proto_oper = mlxsw_reg_ptys_eth_proto_oper_get(payload);
643 /* PPAD - Port Physical Address Register
644 * -------------------------------------
645 * The PPAD register configures the per port physical MAC address.
647 #define MLXSW_REG_PPAD_ID 0x5005
648 #define MLXSW_REG_PPAD_LEN 0x10
650 static const struct mlxsw_reg_info mlxsw_reg_ppad = {
651 .id = MLXSW_REG_PPAD_ID,
652 .len = MLXSW_REG_PPAD_LEN,
655 /* reg_ppad_single_base_mac
656 * 0: base_mac, local port should be 0 and mac[7:0] is
657 * reserved. HW will set incremental
658 * 1: single_mac - mac of the local_port
661 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
663 /* reg_ppad_local_port
664 * port number, if single_base_mac = 0 then local_port is reserved
667 MLXSW_ITEM32(reg, ppad, local_port, 0x00, 16, 8);
670 * If single_base_mac = 0 - base MAC address, mac[7:0] is reserved.
671 * If single_base_mac = 1 - the per port MAC address
674 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
676 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
679 MLXSW_REG_ZERO(ppad, payload);
680 mlxsw_reg_ppad_single_base_mac_set(payload, !!single_base_mac);
681 mlxsw_reg_ppad_local_port_set(payload, local_port);
684 /* PAOS - Ports Administrative and Operational Status Register
685 * -----------------------------------------------------------
686 * Configures and retrieves per port administrative and operational status.
688 #define MLXSW_REG_PAOS_ID 0x5006
689 #define MLXSW_REG_PAOS_LEN 0x10
691 static const struct mlxsw_reg_info mlxsw_reg_paos = {
692 .id = MLXSW_REG_PAOS_ID,
693 .len = MLXSW_REG_PAOS_LEN,
697 * Switch partition ID with which to associate the port.
698 * Note: while external ports uses unique local port numbers (and thus swid is
699 * redundant), router ports use the same local port number where swid is the
700 * only indication for the relevant port.
703 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
705 /* reg_paos_local_port
709 MLXSW_ITEM32(reg, paos, local_port, 0x00, 16, 8);
711 /* reg_paos_admin_status
712 * Port administrative state (the desired state of the port):
715 * 3 - Up once. This means that in case of link failure, the port won't go
716 * into polling mode, but will wait to be re-enabled by software.
717 * 4 - Disabled by system. Can only be set by hardware.
720 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
722 /* reg_paos_oper_status
723 * Port operational state (the current state):
726 * 3 - Down by port failure. This means that the device will not let the
727 * port up again until explicitly specified by software.
730 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
733 * Admin state update enabled.
736 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
739 * Event update enable. If this bit is set, event generation will be
740 * updated based on the e field.
743 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
746 * Event generation on operational state change:
747 * 0 - Do not generate event.
748 * 1 - Generate Event.
749 * 2 - Generate Single Event.
752 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
754 static inline void mlxsw_reg_paos_pack(char *payload, u8 local_port,
755 enum mlxsw_port_admin_status status)
757 MLXSW_REG_ZERO(paos, payload);
758 mlxsw_reg_paos_swid_set(payload, 0);
759 mlxsw_reg_paos_local_port_set(payload, local_port);
760 mlxsw_reg_paos_admin_status_set(payload, status);
761 mlxsw_reg_paos_oper_status_set(payload, 0);
762 mlxsw_reg_paos_ase_set(payload, 1);
763 mlxsw_reg_paos_ee_set(payload, 1);
764 mlxsw_reg_paos_e_set(payload, 1);
767 /* PPCNT - Ports Performance Counters Register
768 * -------------------------------------------
769 * The PPCNT register retrieves per port performance counters.
771 #define MLXSW_REG_PPCNT_ID 0x5008
772 #define MLXSW_REG_PPCNT_LEN 0x100
774 static const struct mlxsw_reg_info mlxsw_reg_ppcnt = {
775 .id = MLXSW_REG_PPCNT_ID,
776 .len = MLXSW_REG_PPCNT_LEN,
780 * For HCA: must be always 0.
781 * Switch partition ID to associate port with.
782 * Switch partitions are numbered from 0 to 7 inclusively.
783 * Switch partition 254 indicates stacking ports.
784 * Switch partition 255 indicates all switch partitions.
785 * Only valid on Set() operation with local_port=255.
788 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
790 /* reg_ppcnt_local_port
792 * 255 indicates all ports on the device, and is only allowed
793 * for Set() operation.
796 MLXSW_ITEM32(reg, ppcnt, local_port, 0x00, 16, 8);
799 * Port number access type:
800 * 0 - Local port number
804 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
807 * Performance counter group.
808 * Group 63 indicates all groups. Only valid on Set() operation with
810 * 0x0: IEEE 802.3 Counters
811 * 0x1: RFC 2863 Counters
812 * 0x2: RFC 2819 Counters
813 * 0x3: RFC 3635 Counters
814 * 0x5: Ethernet Extended Counters
815 * 0x8: Link Level Retransmission Counters
816 * 0x10: Per Priority Counters
817 * 0x11: Per Traffic Class Counters
818 * 0x12: Physical Layer Counters
821 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
824 * Clear counters. Setting the clr bit will reset the counter value
825 * for all counters in the counter group. This bit can be set
826 * for both Set() and Get() operation.
829 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
832 * Priority for counter set that support per priority, valid values: 0-7.
833 * Traffic class for counter set that support per traffic class,
834 * valid values: 0- cap_max_tclass-1 .
835 * For HCA: cap_max_tclass is always 8.
836 * Otherwise must be 0.
839 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
841 /* reg_ppcnt_a_frames_transmitted_ok
844 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
847 /* reg_ppcnt_a_frames_received_ok
850 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
853 /* reg_ppcnt_a_frame_check_sequence_errors
856 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
859 /* reg_ppcnt_a_alignment_errors
862 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
865 /* reg_ppcnt_a_octets_transmitted_ok
868 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
871 /* reg_ppcnt_a_octets_received_ok
874 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
877 /* reg_ppcnt_a_multicast_frames_xmitted_ok
880 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
883 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
886 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
889 /* reg_ppcnt_a_multicast_frames_received_ok
892 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
895 /* reg_ppcnt_a_broadcast_frames_received_ok
898 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
901 /* reg_ppcnt_a_in_range_length_errors
904 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
907 /* reg_ppcnt_a_out_of_range_length_field
910 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
913 /* reg_ppcnt_a_frame_too_long_errors
916 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
919 /* reg_ppcnt_a_symbol_error_during_carrier
922 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
925 /* reg_ppcnt_a_mac_control_frames_transmitted
928 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
931 /* reg_ppcnt_a_mac_control_frames_received
934 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
937 /* reg_ppcnt_a_unsupported_opcodes_received
940 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
943 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
946 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
949 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
952 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
955 static inline void mlxsw_reg_ppcnt_pack(char *payload, u8 local_port)
957 MLXSW_REG_ZERO(ppcnt, payload);
958 mlxsw_reg_ppcnt_swid_set(payload, 0);
959 mlxsw_reg_ppcnt_local_port_set(payload, local_port);
960 mlxsw_reg_ppcnt_pnat_set(payload, 0);
961 mlxsw_reg_ppcnt_grp_set(payload, 0);
962 mlxsw_reg_ppcnt_clr_set(payload, 0);
963 mlxsw_reg_ppcnt_prio_tc_set(payload, 0);
966 /* PSPA - Port Switch Partition Allocation
967 * ---------------------------------------
968 * Controls the association of a port with a switch partition and enables
969 * configuring ports as stacking ports.
971 #define MLXSW_REG_PSPA_ID 0x500D
972 #define MLXSW_REG_PSPA_LEN 0x8
974 static const struct mlxsw_reg_info mlxsw_reg_pspa = {
975 .id = MLXSW_REG_PSPA_ID,
976 .len = MLXSW_REG_PSPA_LEN,
980 * Switch partition ID.
983 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
985 /* reg_pspa_local_port
989 MLXSW_ITEM32(reg, pspa, local_port, 0x00, 16, 8);
992 * Virtual port within the local port. Set to 0 when virtual ports are
993 * disabled on the local port.
996 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
998 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
1000 MLXSW_REG_ZERO(pspa, payload);
1001 mlxsw_reg_pspa_swid_set(payload, swid);
1002 mlxsw_reg_pspa_local_port_set(payload, local_port);
1003 mlxsw_reg_pspa_sub_port_set(payload, 0);
1006 /* HTGT - Host Trap Group Table
1007 * ----------------------------
1008 * Configures the properties for forwarding to CPU.
1010 #define MLXSW_REG_HTGT_ID 0x7002
1011 #define MLXSW_REG_HTGT_LEN 0x100
1013 static const struct mlxsw_reg_info mlxsw_reg_htgt = {
1014 .id = MLXSW_REG_HTGT_ID,
1015 .len = MLXSW_REG_HTGT_LEN,
1019 * Switch partition ID.
1022 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
1024 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0 /* For locally attached CPU */
1030 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
1032 enum mlxsw_reg_htgt_trap_group {
1033 MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
1034 MLXSW_REG_HTGT_TRAP_GROUP_RX,
1035 MLXSW_REG_HTGT_TRAP_GROUP_CTRL,
1038 /* reg_htgt_trap_group
1039 * Trap group number. User defined number specifying which trap groups
1040 * should be forwarded to the CPU. The mapping between trap IDs and trap
1041 * groups is configured using HPKT register.
1044 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
1047 MLXSW_REG_HTGT_POLICER_DISABLE,
1048 MLXSW_REG_HTGT_POLICER_ENABLE,
1052 * Enable policer ID specified using 'pid' field.
1055 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
1058 * Policer ID for the trap group.
1061 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
1063 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
1065 /* reg_htgt_mirror_action
1066 * Mirror action to use.
1068 * 1 - Trap to CPU and mirror to a mirroring agent.
1069 * 2 - Mirror to a mirroring agent and do not trap to CPU.
1072 * Note: Mirroring to a mirroring agent is only supported in Spectrum.
1074 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
1076 /* reg_htgt_mirroring_agent
1080 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
1082 /* reg_htgt_priority
1083 * Trap group priority.
1084 * In case a packet matches multiple classification rules, the packet will
1085 * only be trapped once, based on the trap ID associated with the group (via
1086 * register HPKT) with the highest priority.
1087 * Supported values are 0-7, with 7 represnting the highest priority.
1090 * Note: In SwitchX-2 this field is ignored and the priority value is replaced
1091 * by the 'trap_group' field.
1093 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
1095 /* reg_htgt_local_path_cpu_tclass
1096 * CPU ingress traffic class for the trap group.
1099 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
1101 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD 0x15
1102 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX 0x14
1103 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL 0x13
1105 /* reg_htgt_local_path_rdq
1106 * Receive descriptor queue (RDQ) to use for the trap group.
1109 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
1111 static inline void mlxsw_reg_htgt_pack(char *payload,
1112 enum mlxsw_reg_htgt_trap_group group)
1116 MLXSW_REG_ZERO(htgt, payload);
1118 case MLXSW_REG_HTGT_TRAP_GROUP_EMAD:
1119 swid = MLXSW_PORT_SWID_ALL_SWIDS;
1120 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD;
1122 case MLXSW_REG_HTGT_TRAP_GROUP_RX:
1124 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX;
1126 case MLXSW_REG_HTGT_TRAP_GROUP_CTRL:
1128 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL;
1131 mlxsw_reg_htgt_swid_set(payload, swid);
1132 mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
1133 mlxsw_reg_htgt_trap_group_set(payload, group);
1134 mlxsw_reg_htgt_pide_set(payload, MLXSW_REG_HTGT_POLICER_DISABLE);
1135 mlxsw_reg_htgt_pid_set(payload, 0);
1136 mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
1137 mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
1138 mlxsw_reg_htgt_priority_set(payload, 0);
1139 mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, 7);
1140 mlxsw_reg_htgt_local_path_rdq_set(payload, rdq);
1143 /* HPKT - Host Packet Trap
1144 * -----------------------
1145 * Configures trap IDs inside trap groups.
1147 #define MLXSW_REG_HPKT_ID 0x7003
1148 #define MLXSW_REG_HPKT_LEN 0x10
1150 static const struct mlxsw_reg_info mlxsw_reg_hpkt = {
1151 .id = MLXSW_REG_HPKT_ID,
1152 .len = MLXSW_REG_HPKT_LEN,
1156 MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
1157 MLXSW_REG_HPKT_ACK_REQUIRED,
1161 * Require acknowledgements from the host for events.
1162 * If set, then the device will wait for the event it sent to be acknowledged
1163 * by the host. This option is only relevant for event trap IDs.
1166 * Note: Currently not supported by firmware.
1168 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
1170 enum mlxsw_reg_hpkt_action {
1171 MLXSW_REG_HPKT_ACTION_FORWARD,
1172 MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
1173 MLXSW_REG_HPKT_ACTION_MIRROR_TO_CPU,
1174 MLXSW_REG_HPKT_ACTION_DISCARD,
1175 MLXSW_REG_HPKT_ACTION_SOFT_DISCARD,
1176 MLXSW_REG_HPKT_ACTION_TRAP_AND_SOFT_DISCARD,
1180 * Action to perform on packet when trapped.
1181 * 0 - No action. Forward to CPU based on switching rules.
1182 * 1 - Trap to CPU (CPU receives sole copy).
1183 * 2 - Mirror to CPU (CPU receives a replica of the packet).
1185 * 4 - Soft discard (allow other traps to act on the packet).
1186 * 5 - Trap and soft discard (allow other traps to overwrite this trap).
1189 * Note: Must be set to 0 (forward) for event trap IDs, as they are already
1190 * addressed to the CPU.
1192 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
1194 /* reg_hpkt_trap_group
1195 * Trap group to associate the trap with.
1198 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
1204 * Note: A trap ID can only be associated with a single trap group. The device
1205 * will associate the trap ID with the last trap group configured.
1207 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 9);
1210 MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
1211 MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
1212 MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
1216 * Configure dedicated buffer resources for control packets.
1217 * 0 - Keep factory defaults.
1218 * 1 - Do not use control buffer for this trap ID.
1219 * 2 - Use control buffer for this trap ID.
1222 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
1224 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id)
1226 enum mlxsw_reg_htgt_trap_group trap_group;
1228 MLXSW_REG_ZERO(hpkt, payload);
1229 mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
1230 mlxsw_reg_hpkt_action_set(payload, action);
1232 case MLXSW_TRAP_ID_ETHEMAD:
1233 case MLXSW_TRAP_ID_PUDE:
1234 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_EMAD;
1237 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_RX;
1240 mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
1241 mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
1242 mlxsw_reg_hpkt_ctrl_set(payload, MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT);
1245 static inline const char *mlxsw_reg_id_str(u16 reg_id)
1248 case MLXSW_REG_SGCR_ID:
1250 case MLXSW_REG_SPAD_ID:
1252 case MLXSW_REG_SSPR_ID:
1254 case MLXSW_REG_SPMS_ID:
1256 case MLXSW_REG_SFGC_ID:
1258 case MLXSW_REG_SFTR_ID:
1260 case MLXSW_REG_SPMLR_ID:
1262 case MLXSW_REG_PMLP_ID:
1264 case MLXSW_REG_PMTU_ID:
1266 case MLXSW_REG_PTYS_ID:
1268 case MLXSW_REG_PPAD_ID:
1270 case MLXSW_REG_PAOS_ID:
1272 case MLXSW_REG_PPCNT_ID:
1274 case MLXSW_REG_PSPA_ID:
1276 case MLXSW_REG_HTGT_ID:
1278 case MLXSW_REG_HPKT_ID:
1285 /* PUDE - Port Up / Down Event
1286 * ---------------------------
1287 * Reports the operational state change of a port.
1289 #define MLXSW_REG_PUDE_LEN 0x10
1292 * Switch partition ID with which to associate the port.
1295 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
1297 /* reg_pude_local_port
1298 * Local port number.
1301 MLXSW_ITEM32(reg, pude, local_port, 0x00, 16, 8);
1303 /* reg_pude_admin_status
1304 * Port administrative state (the desired state).
1307 * 3 - Up once. This means that in case of link failure, the port won't go
1308 * into polling mode, but will wait to be re-enabled by software.
1309 * 4 - Disabled by system. Can only be set by hardware.
1312 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
1314 /* reg_pude_oper_status
1315 * Port operatioanl state.
1318 * 3 - Down by port failure. This means that the device will not let the
1319 * port up again until explicitly specified by software.
1322 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);