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 /* SMID - Switch Multicast ID
103 * --------------------------
104 * In multi-chip configuration, each device should maintain mapping between
105 * Multicast ID (MID) into a list of local ports. This mapping is used in all
106 * the devices other than the ingress device, and is implemented as part of the
107 * FDB. The MID record maps from a MID, which is a unique identi- fier of the
108 * multicast group within the stacking domain, into a list of local ports into
109 * which the packet is replicated.
111 #define MLXSW_REG_SMID_ID 0x2007
112 #define MLXSW_REG_SMID_LEN 0x420
114 static const struct mlxsw_reg_info mlxsw_reg_smid = {
115 .id = MLXSW_REG_SMID_ID,
116 .len = MLXSW_REG_SMID_LEN,
120 * Switch partition ID.
123 MLXSW_ITEM32(reg, smid, swid, 0x00, 24, 8);
126 * Multicast identifier - global identifier that represents the multicast group
130 MLXSW_ITEM32(reg, smid, mid, 0x00, 0, 16);
133 * Local port memebership (1 bit per port).
136 MLXSW_ITEM_BIT_ARRAY(reg, smid, port, 0x20, 0x20, 1);
138 /* reg_smid_port_mask
139 * Local port mask (1 bit per port).
142 MLXSW_ITEM_BIT_ARRAY(reg, smid, port_mask, 0x220, 0x20, 1);
144 static inline void mlxsw_reg_smid_pack(char *payload, u16 mid)
146 MLXSW_REG_ZERO(smid, payload);
147 mlxsw_reg_smid_swid_set(payload, 0);
148 mlxsw_reg_smid_mid_set(payload, mid);
149 mlxsw_reg_smid_port_set(payload, MLXSW_PORT_CPU_PORT, 1);
150 mlxsw_reg_smid_port_mask_set(payload, MLXSW_PORT_CPU_PORT, 1);
153 /* SPMS - Switch Port MSTP/RSTP State Register
154 * -------------------------------------------
155 * Configures the spanning tree state of a physical port.
157 #define MLXSW_REG_SPMS_ID 0x200d
158 #define MLXSW_REG_SPMS_LEN 0x404
160 static const struct mlxsw_reg_info mlxsw_reg_spms = {
161 .id = MLXSW_REG_SPMS_ID,
162 .len = MLXSW_REG_SPMS_LEN,
165 /* reg_spms_local_port
169 MLXSW_ITEM32(reg, spms, local_port, 0x00, 16, 8);
171 enum mlxsw_reg_spms_state {
172 MLXSW_REG_SPMS_STATE_NO_CHANGE,
173 MLXSW_REG_SPMS_STATE_DISCARDING,
174 MLXSW_REG_SPMS_STATE_LEARNING,
175 MLXSW_REG_SPMS_STATE_FORWARDING,
179 * Spanning tree state of each VLAN ID (VID) of the local port.
180 * 0 - Do not change spanning tree state (used only when writing).
181 * 1 - Discarding. No learning or forwarding to/from this port (default).
182 * 2 - Learning. Port is learning, but not forwarding.
183 * 3 - Forwarding. Port is learning and forwarding.
186 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
188 static inline void mlxsw_reg_spms_pack(char *payload, u8 local_port, u16 vid,
189 enum mlxsw_reg_spms_state state)
191 MLXSW_REG_ZERO(spms, payload);
192 mlxsw_reg_spms_local_port_set(payload, local_port);
193 mlxsw_reg_spms_state_set(payload, vid, state);
196 /* SFGC - Switch Flooding Group Configuration
197 * ------------------------------------------
198 * The following register controls the association of flooding tables and MIDs
199 * to packet types used for flooding.
201 #define MLXSW_REG_SFGC_ID 0x2011
202 #define MLXSW_REG_SFGC_LEN 0x10
204 static const struct mlxsw_reg_info mlxsw_reg_sfgc = {
205 .id = MLXSW_REG_SFGC_ID,
206 .len = MLXSW_REG_SFGC_LEN,
209 enum mlxsw_reg_sfgc_type {
210 MLXSW_REG_SFGC_TYPE_BROADCAST = 0,
211 MLXSW_REG_SFGC_TYPE_UNKNOWN_UNICAST = 1,
212 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4 = 2,
213 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6 = 3,
214 MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP = 5,
215 MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL = 6,
216 MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST = 7,
220 * The traffic type to reach the flooding table.
223 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
225 enum mlxsw_reg_sfgc_bridge_type {
226 MLXSW_REG_SFGC_BRIDGE_TYPE_1Q_FID = 0,
227 MLXSW_REG_SFGC_BRIDGE_TYPE_VFID = 1,
230 /* reg_sfgc_bridge_type
233 * Note: SwitchX-2 only supports 802.1Q mode.
235 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
237 enum mlxsw_flood_table_type {
238 MLXSW_REG_SFGC_TABLE_TYPE_VID = 1,
239 MLXSW_REG_SFGC_TABLE_TYPE_SINGLE = 2,
240 MLXSW_REG_SFGC_TABLE_TYPE_ANY = 0,
241 MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFEST = 3,
242 MLXSW_REG_SFGC_TABLE_TYPE_FID = 4,
245 /* reg_sfgc_table_type
246 * See mlxsw_flood_table_type
249 * Note: FID offset and FID types are not supported in SwitchX-2.
251 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
253 /* reg_sfgc_flood_table
254 * Flooding table index to associate with the specific type on the specific
258 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
261 * The multicast ID for the swid. Not supported for Spectrum
264 MLXSW_ITEM32(reg, sfgc, mid, 0x08, 0, 16);
266 /* reg_sfgc_counter_set_type
267 * Counter Set Type for flow counters.
270 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
272 /* reg_sfgc_counter_index
273 * Counter Index for flow counters.
276 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
279 mlxsw_reg_sfgc_pack(char *payload, enum mlxsw_reg_sfgc_type type,
280 enum mlxsw_reg_sfgc_bridge_type bridge_type,
281 enum mlxsw_flood_table_type table_type,
282 unsigned int flood_table)
284 MLXSW_REG_ZERO(sfgc, payload);
285 mlxsw_reg_sfgc_type_set(payload, type);
286 mlxsw_reg_sfgc_bridge_type_set(payload, bridge_type);
287 mlxsw_reg_sfgc_table_type_set(payload, table_type);
288 mlxsw_reg_sfgc_flood_table_set(payload, flood_table);
289 mlxsw_reg_sfgc_mid_set(payload, MLXSW_PORT_MID);
292 /* SFTR - Switch Flooding Table Register
293 * -------------------------------------
294 * The switch flooding table is used for flooding packet replication. The table
295 * defines a bit mask of ports for packet replication.
297 #define MLXSW_REG_SFTR_ID 0x2012
298 #define MLXSW_REG_SFTR_LEN 0x420
300 static const struct mlxsw_reg_info mlxsw_reg_sftr = {
301 .id = MLXSW_REG_SFTR_ID,
302 .len = MLXSW_REG_SFTR_LEN,
306 * Switch partition ID with which to associate the port.
309 MLXSW_ITEM32(reg, sftr, swid, 0x00, 24, 8);
311 /* reg_sftr_flood_table
312 * Flooding table index to associate with the specific type on the specific
316 MLXSW_ITEM32(reg, sftr, flood_table, 0x00, 16, 6);
319 * Index. Used as an index into the Flooding Table in case the table is
320 * configured to use VID / FID or FID Offset.
323 MLXSW_ITEM32(reg, sftr, index, 0x00, 0, 16);
325 /* reg_sftr_table_type
326 * See mlxsw_flood_table_type
329 MLXSW_ITEM32(reg, sftr, table_type, 0x04, 16, 3);
332 * Range of entries to update
335 MLXSW_ITEM32(reg, sftr, range, 0x04, 0, 16);
338 * Local port membership (1 bit per port).
341 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port, 0x20, 0x20, 1);
343 /* reg_sftr_cpu_port_mask
344 * CPU port mask (1 bit per port).
347 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port_mask, 0x220, 0x20, 1);
349 static inline void mlxsw_reg_sftr_pack(char *payload,
350 unsigned int flood_table,
352 enum mlxsw_flood_table_type table_type,
355 MLXSW_REG_ZERO(sftr, payload);
356 mlxsw_reg_sftr_swid_set(payload, 0);
357 mlxsw_reg_sftr_flood_table_set(payload, flood_table);
358 mlxsw_reg_sftr_index_set(payload, index);
359 mlxsw_reg_sftr_table_type_set(payload, table_type);
360 mlxsw_reg_sftr_range_set(payload, range);
361 mlxsw_reg_sftr_port_set(payload, MLXSW_PORT_CPU_PORT, 1);
362 mlxsw_reg_sftr_port_mask_set(payload, MLXSW_PORT_CPU_PORT, 1);
365 /* SPMLR - Switch Port MAC Learning Register
366 * -----------------------------------------
367 * Controls the Switch MAC learning policy per port.
369 #define MLXSW_REG_SPMLR_ID 0x2018
370 #define MLXSW_REG_SPMLR_LEN 0x8
372 static const struct mlxsw_reg_info mlxsw_reg_spmlr = {
373 .id = MLXSW_REG_SPMLR_ID,
374 .len = MLXSW_REG_SPMLR_LEN,
377 /* reg_spmlr_local_port
381 MLXSW_ITEM32(reg, spmlr, local_port, 0x00, 16, 8);
383 /* reg_spmlr_sub_port
384 * Virtual port within the physical port.
385 * Should be set to 0 when virtual ports are not enabled on the port.
388 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
390 enum mlxsw_reg_spmlr_learn_mode {
391 MLXSW_REG_SPMLR_LEARN_MODE_DISABLE = 0,
392 MLXSW_REG_SPMLR_LEARN_MODE_ENABLE = 2,
393 MLXSW_REG_SPMLR_LEARN_MODE_SEC = 3,
396 /* reg_spmlr_learn_mode
397 * Learning mode on the port.
398 * 0 - Learning disabled.
399 * 2 - Learning enabled.
402 * In security mode the switch does not learn MACs on the port, but uses the
403 * SMAC to see if it exists on another ingress port. If so, the packet is
404 * classified as a bad packet and is discarded unless the software registers
405 * to receive port security error packets usign HPKT.
407 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
409 static inline void mlxsw_reg_spmlr_pack(char *payload, u8 local_port,
410 enum mlxsw_reg_spmlr_learn_mode mode)
412 MLXSW_REG_ZERO(spmlr, payload);
413 mlxsw_reg_spmlr_local_port_set(payload, local_port);
414 mlxsw_reg_spmlr_sub_port_set(payload, 0);
415 mlxsw_reg_spmlr_learn_mode_set(payload, mode);
418 /* PMLP - Ports Module to Local Port Register
419 * ------------------------------------------
420 * Configures the assignment of modules to local ports.
422 #define MLXSW_REG_PMLP_ID 0x5002
423 #define MLXSW_REG_PMLP_LEN 0x40
425 static const struct mlxsw_reg_info mlxsw_reg_pmlp = {
426 .id = MLXSW_REG_PMLP_ID,
427 .len = MLXSW_REG_PMLP_LEN,
431 * 0 - Tx value is used for both Tx and Rx.
432 * 1 - Rx value is taken from a separte field.
435 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
437 /* reg_pmlp_local_port
441 MLXSW_ITEM32(reg, pmlp, local_port, 0x00, 16, 8);
444 * 0 - Unmap local port.
445 * 1 - Lane 0 is used.
446 * 2 - Lanes 0 and 1 are used.
447 * 4 - Lanes 0, 1, 2 and 3 are used.
450 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
456 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0, false);
459 * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
462 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 2, 0x04, 16, false);
465 * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
469 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 2, 0x04, 24, false);
471 static inline void mlxsw_reg_pmlp_pack(char *payload, u8 local_port)
473 MLXSW_REG_ZERO(pmlp, payload);
474 mlxsw_reg_pmlp_local_port_set(payload, local_port);
477 /* PMTU - Port MTU Register
478 * ------------------------
479 * Configures and reports the port MTU.
481 #define MLXSW_REG_PMTU_ID 0x5003
482 #define MLXSW_REG_PMTU_LEN 0x10
484 static const struct mlxsw_reg_info mlxsw_reg_pmtu = {
485 .id = MLXSW_REG_PMTU_ID,
486 .len = MLXSW_REG_PMTU_LEN,
489 /* reg_pmtu_local_port
493 MLXSW_ITEM32(reg, pmtu, local_port, 0x00, 16, 8);
497 * When port type (e.g. Ethernet) is configured, the relevant MTU is
498 * reported, otherwise the minimum between the max_mtu of the different
502 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
504 /* reg_pmtu_admin_mtu
505 * MTU value to set port to. Must be smaller or equal to max_mtu.
506 * Note: If port type is Infiniband, then port must be disabled, when its
510 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
513 * The actual MTU configured on the port. Packets exceeding this size
515 * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
516 * oper_mtu might be smaller than admin_mtu.
519 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
521 static inline void mlxsw_reg_pmtu_pack(char *payload, u8 local_port,
524 MLXSW_REG_ZERO(pmtu, payload);
525 mlxsw_reg_pmtu_local_port_set(payload, local_port);
526 mlxsw_reg_pmtu_max_mtu_set(payload, 0);
527 mlxsw_reg_pmtu_admin_mtu_set(payload, new_mtu);
528 mlxsw_reg_pmtu_oper_mtu_set(payload, 0);
531 /* PTYS - Port Type and Speed Register
532 * -----------------------------------
533 * Configures and reports the port speed type.
535 * Note: When set while the link is up, the changes will not take effect
536 * until the port transitions from down to up state.
538 #define MLXSW_REG_PTYS_ID 0x5004
539 #define MLXSW_REG_PTYS_LEN 0x40
541 static const struct mlxsw_reg_info mlxsw_reg_ptys = {
542 .id = MLXSW_REG_PTYS_ID,
543 .len = MLXSW_REG_PTYS_LEN,
546 /* reg_ptys_local_port
550 MLXSW_ITEM32(reg, ptys, local_port, 0x00, 16, 8);
552 #define MLXSW_REG_PTYS_PROTO_MASK_ETH BIT(2)
554 /* reg_ptys_proto_mask
555 * Protocol mask. Indicates which protocol is used.
561 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
563 #define MLXSW_REG_PTYS_ETH_SPEED_SGMII BIT(0)
564 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX BIT(1)
565 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4 BIT(2)
566 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4 BIT(3)
567 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR BIT(4)
568 #define MLXSW_REG_PTYS_ETH_SPEED_20GBASE_KR2 BIT(5)
569 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4 BIT(6)
570 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4 BIT(7)
571 #define MLXSW_REG_PTYS_ETH_SPEED_56GBASE_R4 BIT(8)
572 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR BIT(12)
573 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR BIT(13)
574 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR BIT(14)
575 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4 BIT(15)
576 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4 BIT(16)
577 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR4 BIT(19)
578 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4 BIT(20)
579 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4 BIT(21)
580 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4 BIT(22)
581 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4 BIT(23)
582 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_TX BIT(24)
583 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_T BIT(25)
584 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_T BIT(26)
585 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR BIT(27)
586 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR BIT(28)
587 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR BIT(29)
588 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2 BIT(30)
589 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2 BIT(31)
591 /* reg_ptys_eth_proto_cap
592 * Ethernet port supported speeds and protocols.
595 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
597 /* reg_ptys_eth_proto_admin
598 * Speed and protocol to set port to.
601 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
603 /* reg_ptys_eth_proto_oper
604 * The current speed and protocol configured for the port.
607 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
609 static inline void mlxsw_reg_ptys_pack(char *payload, u8 local_port,
612 MLXSW_REG_ZERO(ptys, payload);
613 mlxsw_reg_ptys_local_port_set(payload, local_port);
614 mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
615 mlxsw_reg_ptys_eth_proto_admin_set(payload, proto_admin);
618 static inline void mlxsw_reg_ptys_unpack(char *payload, u32 *p_eth_proto_cap,
619 u32 *p_eth_proto_adm,
620 u32 *p_eth_proto_oper)
623 *p_eth_proto_cap = mlxsw_reg_ptys_eth_proto_cap_get(payload);
625 *p_eth_proto_adm = mlxsw_reg_ptys_eth_proto_admin_get(payload);
626 if (p_eth_proto_oper)
627 *p_eth_proto_oper = mlxsw_reg_ptys_eth_proto_oper_get(payload);
630 /* PPAD - Port Physical Address Register
631 * -------------------------------------
632 * The PPAD register configures the per port physical MAC address.
634 #define MLXSW_REG_PPAD_ID 0x5005
635 #define MLXSW_REG_PPAD_LEN 0x10
637 static const struct mlxsw_reg_info mlxsw_reg_ppad = {
638 .id = MLXSW_REG_PPAD_ID,
639 .len = MLXSW_REG_PPAD_LEN,
642 /* reg_ppad_single_base_mac
643 * 0: base_mac, local port should be 0 and mac[7:0] is
644 * reserved. HW will set incremental
645 * 1: single_mac - mac of the local_port
648 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
650 /* reg_ppad_local_port
651 * port number, if single_base_mac = 0 then local_port is reserved
654 MLXSW_ITEM32(reg, ppad, local_port, 0x00, 16, 8);
657 * If single_base_mac = 0 - base MAC address, mac[7:0] is reserved.
658 * If single_base_mac = 1 - the per port MAC address
661 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
663 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
666 MLXSW_REG_ZERO(ppad, payload);
667 mlxsw_reg_ppad_single_base_mac_set(payload, !!single_base_mac);
668 mlxsw_reg_ppad_local_port_set(payload, local_port);
671 /* PAOS - Ports Administrative and Operational Status Register
672 * -----------------------------------------------------------
673 * Configures and retrieves per port administrative and operational status.
675 #define MLXSW_REG_PAOS_ID 0x5006
676 #define MLXSW_REG_PAOS_LEN 0x10
678 static const struct mlxsw_reg_info mlxsw_reg_paos = {
679 .id = MLXSW_REG_PAOS_ID,
680 .len = MLXSW_REG_PAOS_LEN,
684 * Switch partition ID with which to associate the port.
685 * Note: while external ports uses unique local port numbers (and thus swid is
686 * redundant), router ports use the same local port number where swid is the
687 * only indication for the relevant port.
690 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
692 /* reg_paos_local_port
696 MLXSW_ITEM32(reg, paos, local_port, 0x00, 16, 8);
698 /* reg_paos_admin_status
699 * Port administrative state (the desired state of the port):
702 * 3 - Up once. This means that in case of link failure, the port won't go
703 * into polling mode, but will wait to be re-enabled by software.
704 * 4 - Disabled by system. Can only be set by hardware.
707 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
709 /* reg_paos_oper_status
710 * Port operational state (the current state):
713 * 3 - Down by port failure. This means that the device will not let the
714 * port up again until explicitly specified by software.
717 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
720 * Admin state update enabled.
723 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
726 * Event update enable. If this bit is set, event generation will be
727 * updated based on the e field.
730 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
733 * Event generation on operational state change:
734 * 0 - Do not generate event.
735 * 1 - Generate Event.
736 * 2 - Generate Single Event.
739 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
741 static inline void mlxsw_reg_paos_pack(char *payload, u8 local_port,
742 enum mlxsw_port_admin_status status)
744 MLXSW_REG_ZERO(paos, payload);
745 mlxsw_reg_paos_swid_set(payload, 0);
746 mlxsw_reg_paos_local_port_set(payload, local_port);
747 mlxsw_reg_paos_admin_status_set(payload, status);
748 mlxsw_reg_paos_oper_status_set(payload, 0);
749 mlxsw_reg_paos_ase_set(payload, 1);
750 mlxsw_reg_paos_ee_set(payload, 1);
751 mlxsw_reg_paos_e_set(payload, 1);
754 /* PPCNT - Ports Performance Counters Register
755 * -------------------------------------------
756 * The PPCNT register retrieves per port performance counters.
758 #define MLXSW_REG_PPCNT_ID 0x5008
759 #define MLXSW_REG_PPCNT_LEN 0x100
761 static const struct mlxsw_reg_info mlxsw_reg_ppcnt = {
762 .id = MLXSW_REG_PPCNT_ID,
763 .len = MLXSW_REG_PPCNT_LEN,
767 * For HCA: must be always 0.
768 * Switch partition ID to associate port with.
769 * Switch partitions are numbered from 0 to 7 inclusively.
770 * Switch partition 254 indicates stacking ports.
771 * Switch partition 255 indicates all switch partitions.
772 * Only valid on Set() operation with local_port=255.
775 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
777 /* reg_ppcnt_local_port
779 * 255 indicates all ports on the device, and is only allowed
780 * for Set() operation.
783 MLXSW_ITEM32(reg, ppcnt, local_port, 0x00, 16, 8);
786 * Port number access type:
787 * 0 - Local port number
791 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
794 * Performance counter group.
795 * Group 63 indicates all groups. Only valid on Set() operation with
797 * 0x0: IEEE 802.3 Counters
798 * 0x1: RFC 2863 Counters
799 * 0x2: RFC 2819 Counters
800 * 0x3: RFC 3635 Counters
801 * 0x5: Ethernet Extended Counters
802 * 0x8: Link Level Retransmission Counters
803 * 0x10: Per Priority Counters
804 * 0x11: Per Traffic Class Counters
805 * 0x12: Physical Layer Counters
808 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
811 * Clear counters. Setting the clr bit will reset the counter value
812 * for all counters in the counter group. This bit can be set
813 * for both Set() and Get() operation.
816 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
819 * Priority for counter set that support per priority, valid values: 0-7.
820 * Traffic class for counter set that support per traffic class,
821 * valid values: 0- cap_max_tclass-1 .
822 * For HCA: cap_max_tclass is always 8.
823 * Otherwise must be 0.
826 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
828 /* reg_ppcnt_a_frames_transmitted_ok
831 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
834 /* reg_ppcnt_a_frames_received_ok
837 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
840 /* reg_ppcnt_a_frame_check_sequence_errors
843 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
846 /* reg_ppcnt_a_alignment_errors
849 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
852 /* reg_ppcnt_a_octets_transmitted_ok
855 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
858 /* reg_ppcnt_a_octets_received_ok
861 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
864 /* reg_ppcnt_a_multicast_frames_xmitted_ok
867 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
870 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
873 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
876 /* reg_ppcnt_a_multicast_frames_received_ok
879 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
882 /* reg_ppcnt_a_broadcast_frames_received_ok
885 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
888 /* reg_ppcnt_a_in_range_length_errors
891 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
894 /* reg_ppcnt_a_out_of_range_length_field
897 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
900 /* reg_ppcnt_a_frame_too_long_errors
903 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
906 /* reg_ppcnt_a_symbol_error_during_carrier
909 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
912 /* reg_ppcnt_a_mac_control_frames_transmitted
915 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
918 /* reg_ppcnt_a_mac_control_frames_received
921 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
924 /* reg_ppcnt_a_unsupported_opcodes_received
927 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
930 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
933 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
936 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
939 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
942 static inline void mlxsw_reg_ppcnt_pack(char *payload, u8 local_port)
944 MLXSW_REG_ZERO(ppcnt, payload);
945 mlxsw_reg_ppcnt_swid_set(payload, 0);
946 mlxsw_reg_ppcnt_local_port_set(payload, local_port);
947 mlxsw_reg_ppcnt_pnat_set(payload, 0);
948 mlxsw_reg_ppcnt_grp_set(payload, 0);
949 mlxsw_reg_ppcnt_clr_set(payload, 0);
950 mlxsw_reg_ppcnt_prio_tc_set(payload, 0);
953 /* PSPA - Port Switch Partition Allocation
954 * ---------------------------------------
955 * Controls the association of a port with a switch partition and enables
956 * configuring ports as stacking ports.
958 #define MLXSW_REG_PSPA_ID 0x500d
959 #define MLXSW_REG_PSPA_LEN 0x8
961 static const struct mlxsw_reg_info mlxsw_reg_pspa = {
962 .id = MLXSW_REG_PSPA_ID,
963 .len = MLXSW_REG_PSPA_LEN,
967 * Switch partition ID.
970 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
972 /* reg_pspa_local_port
976 MLXSW_ITEM32(reg, pspa, local_port, 0x00, 16, 8);
979 * Virtual port within the local port. Set to 0 when virtual ports are
980 * disabled on the local port.
983 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
985 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
987 MLXSW_REG_ZERO(pspa, payload);
988 mlxsw_reg_pspa_swid_set(payload, swid);
989 mlxsw_reg_pspa_local_port_set(payload, local_port);
990 mlxsw_reg_pspa_sub_port_set(payload, 0);
993 /* HTGT - Host Trap Group Table
994 * ----------------------------
995 * Configures the properties for forwarding to CPU.
997 #define MLXSW_REG_HTGT_ID 0x7002
998 #define MLXSW_REG_HTGT_LEN 0x100
1000 static const struct mlxsw_reg_info mlxsw_reg_htgt = {
1001 .id = MLXSW_REG_HTGT_ID,
1002 .len = MLXSW_REG_HTGT_LEN,
1006 * Switch partition ID.
1009 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
1011 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0 /* For locally attached CPU */
1017 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
1019 #define MLXSW_REG_HTGT_TRAP_GROUP_EMAD 0x0
1020 #define MLXSW_REG_HTGT_TRAP_GROUP_RX 0x1
1022 /* reg_htgt_trap_group
1023 * Trap group number. User defined number specifying which trap groups
1024 * should be forwarded to the CPU. The mapping between trap IDs and trap
1025 * groups is configured using HPKT register.
1028 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
1031 MLXSW_REG_HTGT_POLICER_DISABLE,
1032 MLXSW_REG_HTGT_POLICER_ENABLE,
1036 * Enable policer ID specified using 'pid' field.
1039 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
1042 * Policer ID for the trap group.
1045 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
1047 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
1049 /* reg_htgt_mirror_action
1050 * Mirror action to use.
1052 * 1 - Trap to CPU and mirror to a mirroring agent.
1053 * 2 - Mirror to a mirroring agent and do not trap to CPU.
1056 * Note: Mirroring to a mirroring agent is only supported in Spectrum.
1058 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
1060 /* reg_htgt_mirroring_agent
1064 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
1066 /* reg_htgt_priority
1067 * Trap group priority.
1068 * In case a packet matches multiple classification rules, the packet will
1069 * only be trapped once, based on the trap ID associated with the group (via
1070 * register HPKT) with the highest priority.
1071 * Supported values are 0-7, with 7 represnting the highest priority.
1074 * Note: In SwitchX-2 this field is ignored and the priority value is replaced
1075 * by the 'trap_group' field.
1077 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
1079 /* reg_htgt_local_path_cpu_tclass
1080 * CPU ingress traffic class for the trap group.
1083 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
1085 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD 0x15
1086 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX 0x14
1088 /* reg_htgt_local_path_rdq
1089 * Receive descriptor queue (RDQ) to use for the trap group.
1092 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
1094 static inline void mlxsw_reg_htgt_pack(char *payload, u8 trap_group)
1098 MLXSW_REG_ZERO(htgt, payload);
1099 if (MLXSW_REG_HTGT_TRAP_GROUP_EMAD == trap_group) {
1100 swid = MLXSW_PORT_SWID_ALL_SWIDS;
1101 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD;
1104 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX;
1106 mlxsw_reg_htgt_swid_set(payload, swid);
1107 mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
1108 mlxsw_reg_htgt_trap_group_set(payload, trap_group);
1109 mlxsw_reg_htgt_pide_set(payload, MLXSW_REG_HTGT_POLICER_DISABLE);
1110 mlxsw_reg_htgt_pid_set(payload, 0);
1111 mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
1112 mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
1113 mlxsw_reg_htgt_priority_set(payload, 0);
1114 mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, 7);
1115 mlxsw_reg_htgt_local_path_rdq_set(payload, rdq);
1118 /* HPKT - Host Packet Trap
1119 * -----------------------
1120 * Configures trap IDs inside trap groups.
1122 #define MLXSW_REG_HPKT_ID 0x7003
1123 #define MLXSW_REG_HPKT_LEN 0x10
1125 static const struct mlxsw_reg_info mlxsw_reg_hpkt = {
1126 .id = MLXSW_REG_HPKT_ID,
1127 .len = MLXSW_REG_HPKT_LEN,
1131 MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
1132 MLXSW_REG_HPKT_ACK_REQUIRED,
1136 * Require acknowledgements from the host for events.
1137 * If set, then the device will wait for the event it sent to be acknowledged
1138 * by the host. This option is only relevant for event trap IDs.
1141 * Note: Currently not supported by firmware.
1143 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
1145 enum mlxsw_reg_hpkt_action {
1146 MLXSW_REG_HPKT_ACTION_FORWARD,
1147 MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
1148 MLXSW_REG_HPKT_ACTION_MIRROR_TO_CPU,
1149 MLXSW_REG_HPKT_ACTION_DISCARD,
1150 MLXSW_REG_HPKT_ACTION_SOFT_DISCARD,
1151 MLXSW_REG_HPKT_ACTION_TRAP_AND_SOFT_DISCARD,
1155 * Action to perform on packet when trapped.
1156 * 0 - No action. Forward to CPU based on switching rules.
1157 * 1 - Trap to CPU (CPU receives sole copy).
1158 * 2 - Mirror to CPU (CPU receives a replica of the packet).
1160 * 4 - Soft discard (allow other traps to act on the packet).
1161 * 5 - Trap and soft discard (allow other traps to overwrite this trap).
1164 * Note: Must be set to 0 (forward) for event trap IDs, as they are already
1165 * addressed to the CPU.
1167 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
1169 /* reg_hpkt_trap_group
1170 * Trap group to associate the trap with.
1173 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
1179 * Note: A trap ID can only be associated with a single trap group. The device
1180 * will associate the trap ID with the last trap group configured.
1182 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 9);
1185 MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
1186 MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
1187 MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
1191 * Configure dedicated buffer resources for control packets.
1192 * 0 - Keep factory defaults.
1193 * 1 - Do not use control buffer for this trap ID.
1194 * 2 - Use control buffer for this trap ID.
1197 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
1199 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action,
1200 u8 trap_group, u16 trap_id)
1202 MLXSW_REG_ZERO(hpkt, payload);
1203 mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
1204 mlxsw_reg_hpkt_action_set(payload, action);
1205 mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
1206 mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
1207 mlxsw_reg_hpkt_ctrl_set(payload, MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT);
1210 static inline const char *mlxsw_reg_id_str(u16 reg_id)
1213 case MLXSW_REG_SGCR_ID:
1215 case MLXSW_REG_SPAD_ID:
1217 case MLXSW_REG_SMID_ID:
1219 case MLXSW_REG_SPMS_ID:
1221 case MLXSW_REG_SFGC_ID:
1223 case MLXSW_REG_SFTR_ID:
1225 case MLXSW_REG_SPMLR_ID:
1227 case MLXSW_REG_PMLP_ID:
1229 case MLXSW_REG_PMTU_ID:
1231 case MLXSW_REG_PTYS_ID:
1233 case MLXSW_REG_PPAD_ID:
1235 case MLXSW_REG_PAOS_ID:
1237 case MLXSW_REG_PPCNT_ID:
1239 case MLXSW_REG_PSPA_ID:
1241 case MLXSW_REG_HTGT_ID:
1243 case MLXSW_REG_HPKT_ID:
1250 /* PUDE - Port Up / Down Event
1251 * ---------------------------
1252 * Reports the operational state change of a port.
1254 #define MLXSW_REG_PUDE_LEN 0x10
1257 * Switch partition ID with which to associate the port.
1260 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
1262 /* reg_pude_local_port
1263 * Local port number.
1266 MLXSW_ITEM32(reg, pude, local_port, 0x00, 16, 8);
1268 /* reg_pude_admin_status
1269 * Port administrative state (the desired state).
1272 * 3 - Up once. This means that in case of link failure, the port won't go
1273 * into polling mode, but will wait to be re-enabled by software.
1274 * 4 - Disabled by system. Can only be set by hardware.
1277 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
1279 /* reg_pude_oper_status
1280 * Port operatioanl state.
1283 * 3 - Down by port failure. This means that the device will not let the
1284 * port up again until explicitly specified by software.
1287 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);