]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/mellanox/mlxsw/reg.h
Merge tag 'mac80211-next-for-davem-2015-08-14' mac80211-next.git
[karo-tx-linux.git] / drivers / net / ethernet / mellanox / mlxsw / reg.h
1 /*
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>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
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.
19  *
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.
23  *
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.
35  */
36
37 #ifndef _MLXSW_REG_H
38 #define _MLXSW_REG_H
39
40 #include <linux/string.h>
41 #include <linux/bitops.h>
42 #include <linux/if_vlan.h>
43
44 #include "item.h"
45 #include "port.h"
46
47 struct mlxsw_reg_info {
48         u16 id;
49         u16 len; /* In u8 */
50 };
51
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)
55
56 /* SGCR - Switch General Configuration Register
57  * --------------------------------------------
58  * This register is used for configuration of the switch capabilities.
59  */
60 #define MLXSW_REG_SGCR_ID 0x2000
61 #define MLXSW_REG_SGCR_LEN 0x10
62
63 static const struct mlxsw_reg_info mlxsw_reg_sgcr = {
64         .id = MLXSW_REG_SGCR_ID,
65         .len = MLXSW_REG_SGCR_LEN,
66 };
67
68 /* reg_sgcr_llb
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.
72  * Access: RW
73  */
74 MLXSW_ITEM32(reg, sgcr, llb, 0x04, 0, 1);
75
76 static inline void mlxsw_reg_sgcr_pack(char *payload, bool llb)
77 {
78         MLXSW_REG_ZERO(sgcr, payload);
79         mlxsw_reg_sgcr_llb_set(payload, !!llb);
80 }
81
82 /* SPAD - Switch Physical Address Register
83  * ---------------------------------------
84  * The SPAD register configures the switch physical MAC address.
85  */
86 #define MLXSW_REG_SPAD_ID 0x2002
87 #define MLXSW_REG_SPAD_LEN 0x10
88
89 static const struct mlxsw_reg_info mlxsw_reg_spad = {
90         .id = MLXSW_REG_SPAD_ID,
91         .len = MLXSW_REG_SPAD_LEN,
92 };
93
94 /* reg_spad_base_mac
95  * Base MAC address for the switch partitions.
96  * Per switch partition MAC address is equal to:
97  * base_mac + swid
98  * Access: RW
99  */
100 MLXSW_ITEM_BUF(reg, spad, base_mac, 0x02, 6);
101
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.
110  */
111 #define MLXSW_REG_SMID_ID 0x2007
112 #define MLXSW_REG_SMID_LEN 0x420
113
114 static const struct mlxsw_reg_info mlxsw_reg_smid = {
115         .id = MLXSW_REG_SMID_ID,
116         .len = MLXSW_REG_SMID_LEN,
117 };
118
119 /* reg_smid_swid
120  * Switch partition ID.
121  * Access: Index
122  */
123 MLXSW_ITEM32(reg, smid, swid, 0x00, 24, 8);
124
125 /* reg_smid_mid
126  * Multicast identifier - global identifier that represents the multicast group
127  * across all devices
128  * Access: Index
129  */
130 MLXSW_ITEM32(reg, smid, mid, 0x00, 0, 16);
131
132 /* reg_smid_port
133  * Local port memebership (1 bit per port).
134  * Access: RW
135  */
136 MLXSW_ITEM_BIT_ARRAY(reg, smid, port, 0x20, 0x20, 1);
137
138 /* reg_smid_port_mask
139  * Local port mask (1 bit per port).
140  * Access: W
141  */
142 MLXSW_ITEM_BIT_ARRAY(reg, smid, port_mask, 0x220, 0x20, 1);
143
144 static inline void mlxsw_reg_smid_pack(char *payload, u16 mid)
145 {
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);
151 }
152
153 /* SPMS - Switch Port MSTP/RSTP State Register
154  * -------------------------------------------
155  * Configures the spanning tree state of a physical port.
156  */
157 #define MLXSW_REG_SPMS_ID 0x200d
158 #define MLXSW_REG_SPMS_LEN 0x404
159
160 static const struct mlxsw_reg_info mlxsw_reg_spms = {
161         .id = MLXSW_REG_SPMS_ID,
162         .len = MLXSW_REG_SPMS_LEN,
163 };
164
165 /* reg_spms_local_port
166  * Local port number.
167  * Access: Index
168  */
169 MLXSW_ITEM32(reg, spms, local_port, 0x00, 16, 8);
170
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,
176 };
177
178 /* reg_spms_state
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.
184  * Access: RW
185  */
186 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
187
188 static inline void mlxsw_reg_spms_pack(char *payload, u8 local_port, u16 vid,
189                                        enum mlxsw_reg_spms_state state)
190 {
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);
194 }
195
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.
200  */
201 #define MLXSW_REG_SFGC_ID  0x2011
202 #define MLXSW_REG_SFGC_LEN 0x10
203
204 static const struct mlxsw_reg_info mlxsw_reg_sfgc = {
205         .id = MLXSW_REG_SFGC_ID,
206         .len = MLXSW_REG_SFGC_LEN,
207 };
208
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,
217 };
218
219 /* reg_sfgc_type
220  * The traffic type to reach the flooding table.
221  * Access: Index
222  */
223 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
224
225 enum mlxsw_reg_sfgc_bridge_type {
226         MLXSW_REG_SFGC_BRIDGE_TYPE_1Q_FID = 0,
227         MLXSW_REG_SFGC_BRIDGE_TYPE_VFID = 1,
228 };
229
230 /* reg_sfgc_bridge_type
231  * Access: Index
232  *
233  * Note: SwitchX-2 only supports 802.1Q mode.
234  */
235 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
236
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,
243 };
244
245 /* reg_sfgc_table_type
246  * See mlxsw_flood_table_type
247  * Access: RW
248  *
249  * Note: FID offset and FID types are not supported in SwitchX-2.
250  */
251 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
252
253 /* reg_sfgc_flood_table
254  * Flooding table index to associate with the specific type on the specific
255  * switch partition.
256  * Access: RW
257  */
258 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
259
260 /* reg_sfgc_mid
261  * The multicast ID for the swid. Not supported for Spectrum
262  * Access: RW
263  */
264 MLXSW_ITEM32(reg, sfgc, mid, 0x08, 0, 16);
265
266 /* reg_sfgc_counter_set_type
267  * Counter Set Type for flow counters.
268  * Access: RW
269  */
270 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
271
272 /* reg_sfgc_counter_index
273  * Counter Index for flow counters.
274  * Access: RW
275  */
276 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
277
278 static inline void
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)
283 {
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);
290 }
291
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.
296  */
297 #define MLXSW_REG_SFTR_ID 0x2012
298 #define MLXSW_REG_SFTR_LEN 0x420
299
300 static const struct mlxsw_reg_info mlxsw_reg_sftr = {
301         .id = MLXSW_REG_SFTR_ID,
302         .len = MLXSW_REG_SFTR_LEN,
303 };
304
305 /* reg_sftr_swid
306  * Switch partition ID with which to associate the port.
307  * Access: Index
308  */
309 MLXSW_ITEM32(reg, sftr, swid, 0x00, 24, 8);
310
311 /* reg_sftr_flood_table
312  * Flooding table index to associate with the specific type on the specific
313  * switch partition.
314  * Access: Index
315  */
316 MLXSW_ITEM32(reg, sftr, flood_table, 0x00, 16, 6);
317
318 /* reg_sftr_index
319  * Index. Used as an index into the Flooding Table in case the table is
320  * configured to use VID / FID or FID Offset.
321  * Access: Index
322  */
323 MLXSW_ITEM32(reg, sftr, index, 0x00, 0, 16);
324
325 /* reg_sftr_table_type
326  * See mlxsw_flood_table_type
327  * Access: RW
328  */
329 MLXSW_ITEM32(reg, sftr, table_type, 0x04, 16, 3);
330
331 /* reg_sftr_range
332  * Range of entries to update
333  * Access: Index
334  */
335 MLXSW_ITEM32(reg, sftr, range, 0x04, 0, 16);
336
337 /* reg_sftr_port
338  * Local port membership (1 bit per port).
339  * Access: RW
340  */
341 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port, 0x20, 0x20, 1);
342
343 /* reg_sftr_cpu_port_mask
344  * CPU port mask (1 bit per port).
345  * Access: W
346  */
347 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port_mask, 0x220, 0x20, 1);
348
349 static inline void mlxsw_reg_sftr_pack(char *payload,
350                                        unsigned int flood_table,
351                                        unsigned int index,
352                                        enum mlxsw_flood_table_type table_type,
353                                        unsigned int range)
354 {
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);
363 }
364
365 /* SPMLR - Switch Port MAC Learning Register
366  * -----------------------------------------
367  * Controls the Switch MAC learning policy per port.
368  */
369 #define MLXSW_REG_SPMLR_ID 0x2018
370 #define MLXSW_REG_SPMLR_LEN 0x8
371
372 static const struct mlxsw_reg_info mlxsw_reg_spmlr = {
373         .id = MLXSW_REG_SPMLR_ID,
374         .len = MLXSW_REG_SPMLR_LEN,
375 };
376
377 /* reg_spmlr_local_port
378  * Local port number.
379  * Access: Index
380  */
381 MLXSW_ITEM32(reg, spmlr, local_port, 0x00, 16, 8);
382
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.
386  * Access: Index
387  */
388 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
389
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,
394 };
395
396 /* reg_spmlr_learn_mode
397  * Learning mode on the port.
398  * 0 - Learning disabled.
399  * 2 - Learning enabled.
400  * 3 - Security mode.
401  *
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.
406  */
407 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
408
409 static inline void mlxsw_reg_spmlr_pack(char *payload, u8 local_port,
410                                         enum mlxsw_reg_spmlr_learn_mode mode)
411 {
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);
416 }
417
418 /* PMLP - Ports Module to Local Port Register
419  * ------------------------------------------
420  * Configures the assignment of modules to local ports.
421  */
422 #define MLXSW_REG_PMLP_ID 0x5002
423 #define MLXSW_REG_PMLP_LEN 0x40
424
425 static const struct mlxsw_reg_info mlxsw_reg_pmlp = {
426         .id = MLXSW_REG_PMLP_ID,
427         .len = MLXSW_REG_PMLP_LEN,
428 };
429
430 /* reg_pmlp_rxtx
431  * 0 - Tx value is used for both Tx and Rx.
432  * 1 - Rx value is taken from a separte field.
433  * Access: RW
434  */
435 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
436
437 /* reg_pmlp_local_port
438  * Local port number.
439  * Access: Index
440  */
441 MLXSW_ITEM32(reg, pmlp, local_port, 0x00, 16, 8);
442
443 /* reg_pmlp_width
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.
448  * Access: RW
449  */
450 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
451
452 /* reg_pmlp_module
453  * Module number.
454  * Access: RW
455  */
456 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0, false);
457
458 /* reg_pmlp_tx_lane
459  * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
460  * Access: RW
461  */
462 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 2, 0x04, 16, false);
463
464 /* reg_pmlp_rx_lane
465  * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
466  * equal to Tx lane.
467  * Access: RW
468  */
469 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 2, 0x04, 24, false);
470
471 static inline void mlxsw_reg_pmlp_pack(char *payload, u8 local_port)
472 {
473         MLXSW_REG_ZERO(pmlp, payload);
474         mlxsw_reg_pmlp_local_port_set(payload, local_port);
475 }
476
477 /* PMTU - Port MTU Register
478  * ------------------------
479  * Configures and reports the port MTU.
480  */
481 #define MLXSW_REG_PMTU_ID 0x5003
482 #define MLXSW_REG_PMTU_LEN 0x10
483
484 static const struct mlxsw_reg_info mlxsw_reg_pmtu = {
485         .id = MLXSW_REG_PMTU_ID,
486         .len = MLXSW_REG_PMTU_LEN,
487 };
488
489 /* reg_pmtu_local_port
490  * Local port number.
491  * Access: Index
492  */
493 MLXSW_ITEM32(reg, pmtu, local_port, 0x00, 16, 8);
494
495 /* reg_pmtu_max_mtu
496  * Maximum MTU.
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
499  * types is reported.
500  * Access: RO
501  */
502 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
503
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
507  * MTU is set.
508  * Access: RW
509  */
510 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
511
512 /* reg_pmtu_oper_mtu
513  * The actual MTU configured on the port. Packets exceeding this size
514  * will be dropped.
515  * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
516  * oper_mtu might be smaller than admin_mtu.
517  * Access: RO
518  */
519 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
520
521 static inline void mlxsw_reg_pmtu_pack(char *payload, u8 local_port,
522                                        u16 new_mtu)
523 {
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);
529 }
530
531 /* PTYS - Port Type and Speed Register
532  * -----------------------------------
533  * Configures and reports the port speed type.
534  *
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.
537  */
538 #define MLXSW_REG_PTYS_ID 0x5004
539 #define MLXSW_REG_PTYS_LEN 0x40
540
541 static const struct mlxsw_reg_info mlxsw_reg_ptys = {
542         .id = MLXSW_REG_PTYS_ID,
543         .len = MLXSW_REG_PTYS_LEN,
544 };
545
546 /* reg_ptys_local_port
547  * Local port number.
548  * Access: Index
549  */
550 MLXSW_ITEM32(reg, ptys, local_port, 0x00, 16, 8);
551
552 #define MLXSW_REG_PTYS_PROTO_MASK_ETH   BIT(2)
553
554 /* reg_ptys_proto_mask
555  * Protocol mask. Indicates which protocol is used.
556  * 0 - Infiniband.
557  * 1 - Fibre Channel.
558  * 2 - Ethernet.
559  * Access: Index
560  */
561 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
562
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)
590
591 /* reg_ptys_eth_proto_cap
592  * Ethernet port supported speeds and protocols.
593  * Access: RO
594  */
595 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
596
597 /* reg_ptys_eth_proto_admin
598  * Speed and protocol to set port to.
599  * Access: RW
600  */
601 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
602
603 /* reg_ptys_eth_proto_oper
604  * The current speed and protocol configured for the port.
605  * Access: RO
606  */
607 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
608
609 static inline void mlxsw_reg_ptys_pack(char *payload, u8 local_port,
610                                        u32 proto_admin)
611 {
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);
616 }
617
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)
621 {
622         if (p_eth_proto_cap)
623                 *p_eth_proto_cap = mlxsw_reg_ptys_eth_proto_cap_get(payload);
624         if (p_eth_proto_adm)
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);
628 }
629
630 /* PPAD - Port Physical Address Register
631  * -------------------------------------
632  * The PPAD register configures the per port physical MAC address.
633  */
634 #define MLXSW_REG_PPAD_ID 0x5005
635 #define MLXSW_REG_PPAD_LEN 0x10
636
637 static const struct mlxsw_reg_info mlxsw_reg_ppad = {
638         .id = MLXSW_REG_PPAD_ID,
639         .len = MLXSW_REG_PPAD_LEN,
640 };
641
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
646  * Access: RW
647  */
648 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
649
650 /* reg_ppad_local_port
651  * port number, if single_base_mac = 0 then local_port is reserved
652  * Access: RW
653  */
654 MLXSW_ITEM32(reg, ppad, local_port, 0x00, 16, 8);
655
656 /* reg_ppad_mac
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
659  * Access: RW
660  */
661 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
662
663 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
664                                        u8 local_port)
665 {
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);
669 }
670
671 /* PAOS - Ports Administrative and Operational Status Register
672  * -----------------------------------------------------------
673  * Configures and retrieves per port administrative and operational status.
674  */
675 #define MLXSW_REG_PAOS_ID 0x5006
676 #define MLXSW_REG_PAOS_LEN 0x10
677
678 static const struct mlxsw_reg_info mlxsw_reg_paos = {
679         .id = MLXSW_REG_PAOS_ID,
680         .len = MLXSW_REG_PAOS_LEN,
681 };
682
683 /* reg_paos_swid
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.
688  * Access: Index
689  */
690 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
691
692 /* reg_paos_local_port
693  * Local port number.
694  * Access: Index
695  */
696 MLXSW_ITEM32(reg, paos, local_port, 0x00, 16, 8);
697
698 /* reg_paos_admin_status
699  * Port administrative state (the desired state of the port):
700  * 1 - Up.
701  * 2 - Down.
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.
705  * Access: RW
706  */
707 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
708
709 /* reg_paos_oper_status
710  * Port operational state (the current state):
711  * 1 - Up.
712  * 2 - Down.
713  * 3 - Down by port failure. This means that the device will not let the
714  *     port up again until explicitly specified by software.
715  * Access: RO
716  */
717 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
718
719 /* reg_paos_ase
720  * Admin state update enabled.
721  * Access: WO
722  */
723 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
724
725 /* reg_paos_ee
726  * Event update enable. If this bit is set, event generation will be
727  * updated based on the e field.
728  * Access: WO
729  */
730 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
731
732 /* reg_paos_e
733  * Event generation on operational state change:
734  * 0 - Do not generate event.
735  * 1 - Generate Event.
736  * 2 - Generate Single Event.
737  * Access: RW
738  */
739 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
740
741 static inline void mlxsw_reg_paos_pack(char *payload, u8 local_port,
742                                        enum mlxsw_port_admin_status status)
743 {
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);
752 }
753
754 /* PPCNT - Ports Performance Counters Register
755  * -------------------------------------------
756  * The PPCNT register retrieves per port performance counters.
757  */
758 #define MLXSW_REG_PPCNT_ID 0x5008
759 #define MLXSW_REG_PPCNT_LEN 0x100
760
761 static const struct mlxsw_reg_info mlxsw_reg_ppcnt = {
762         .id = MLXSW_REG_PPCNT_ID,
763         .len = MLXSW_REG_PPCNT_LEN,
764 };
765
766 /* reg_ppcnt_swid
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.
773  * Access: Index
774  */
775 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
776
777 /* reg_ppcnt_local_port
778  * Local port number.
779  * 255 indicates all ports on the device, and is only allowed
780  * for Set() operation.
781  * Access: Index
782  */
783 MLXSW_ITEM32(reg, ppcnt, local_port, 0x00, 16, 8);
784
785 /* reg_ppcnt_pnat
786  * Port number access type:
787  * 0 - Local port number
788  * 1 - IB port number
789  * Access: Index
790  */
791 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
792
793 /* reg_ppcnt_grp
794  * Performance counter group.
795  * Group 63 indicates all groups. Only valid on Set() operation with
796  * clr bit set.
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
806  * Access: Index
807  */
808 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
809
810 /* reg_ppcnt_clr
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.
814  * Access: OP
815  */
816 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
817
818 /* reg_ppcnt_prio_tc
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.
824  * Access: Index
825  */
826 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
827
828 /* reg_ppcnt_a_frames_transmitted_ok
829  * Access: RO
830  */
831 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
832              0x08 + 0x00, 0, 64);
833
834 /* reg_ppcnt_a_frames_received_ok
835  * Access: RO
836  */
837 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
838              0x08 + 0x08, 0, 64);
839
840 /* reg_ppcnt_a_frame_check_sequence_errors
841  * Access: RO
842  */
843 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
844              0x08 + 0x10, 0, 64);
845
846 /* reg_ppcnt_a_alignment_errors
847  * Access: RO
848  */
849 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
850              0x08 + 0x18, 0, 64);
851
852 /* reg_ppcnt_a_octets_transmitted_ok
853  * Access: RO
854  */
855 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
856              0x08 + 0x20, 0, 64);
857
858 /* reg_ppcnt_a_octets_received_ok
859  * Access: RO
860  */
861 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
862              0x08 + 0x28, 0, 64);
863
864 /* reg_ppcnt_a_multicast_frames_xmitted_ok
865  * Access: RO
866  */
867 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
868              0x08 + 0x30, 0, 64);
869
870 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
871  * Access: RO
872  */
873 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
874              0x08 + 0x38, 0, 64);
875
876 /* reg_ppcnt_a_multicast_frames_received_ok
877  * Access: RO
878  */
879 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
880              0x08 + 0x40, 0, 64);
881
882 /* reg_ppcnt_a_broadcast_frames_received_ok
883  * Access: RO
884  */
885 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
886              0x08 + 0x48, 0, 64);
887
888 /* reg_ppcnt_a_in_range_length_errors
889  * Access: RO
890  */
891 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
892              0x08 + 0x50, 0, 64);
893
894 /* reg_ppcnt_a_out_of_range_length_field
895  * Access: RO
896  */
897 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
898              0x08 + 0x58, 0, 64);
899
900 /* reg_ppcnt_a_frame_too_long_errors
901  * Access: RO
902  */
903 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
904              0x08 + 0x60, 0, 64);
905
906 /* reg_ppcnt_a_symbol_error_during_carrier
907  * Access: RO
908  */
909 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
910              0x08 + 0x68, 0, 64);
911
912 /* reg_ppcnt_a_mac_control_frames_transmitted
913  * Access: RO
914  */
915 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
916              0x08 + 0x70, 0, 64);
917
918 /* reg_ppcnt_a_mac_control_frames_received
919  * Access: RO
920  */
921 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
922              0x08 + 0x78, 0, 64);
923
924 /* reg_ppcnt_a_unsupported_opcodes_received
925  * Access: RO
926  */
927 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
928              0x08 + 0x80, 0, 64);
929
930 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
931  * Access: RO
932  */
933 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
934              0x08 + 0x88, 0, 64);
935
936 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
937  * Access: RO
938  */
939 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
940              0x08 + 0x90, 0, 64);
941
942 static inline void mlxsw_reg_ppcnt_pack(char *payload, u8 local_port)
943 {
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);
951 }
952
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.
957  */
958 #define MLXSW_REG_PSPA_ID 0x500d
959 #define MLXSW_REG_PSPA_LEN 0x8
960
961 static const struct mlxsw_reg_info mlxsw_reg_pspa = {
962         .id = MLXSW_REG_PSPA_ID,
963         .len = MLXSW_REG_PSPA_LEN,
964 };
965
966 /* reg_pspa_swid
967  * Switch partition ID.
968  * Access: RW
969  */
970 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
971
972 /* reg_pspa_local_port
973  * Local port number.
974  * Access: Index
975  */
976 MLXSW_ITEM32(reg, pspa, local_port, 0x00, 16, 8);
977
978 /* reg_pspa_sub_port
979  * Virtual port within the local port. Set to 0 when virtual ports are
980  * disabled on the local port.
981  * Access: Index
982  */
983 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
984
985 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
986 {
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);
991 }
992
993 /* HTGT - Host Trap Group Table
994  * ----------------------------
995  * Configures the properties for forwarding to CPU.
996  */
997 #define MLXSW_REG_HTGT_ID 0x7002
998 #define MLXSW_REG_HTGT_LEN 0x100
999
1000 static const struct mlxsw_reg_info mlxsw_reg_htgt = {
1001         .id = MLXSW_REG_HTGT_ID,
1002         .len = MLXSW_REG_HTGT_LEN,
1003 };
1004
1005 /* reg_htgt_swid
1006  * Switch partition ID.
1007  * Access: Index
1008  */
1009 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
1010
1011 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0      /* For locally attached CPU */
1012
1013 /* reg_htgt_type
1014  * CPU path type.
1015  * Access: RW
1016  */
1017 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
1018
1019 #define MLXSW_REG_HTGT_TRAP_GROUP_EMAD  0x0
1020 #define MLXSW_REG_HTGT_TRAP_GROUP_RX    0x1
1021
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.
1026  * Access: Index
1027  */
1028 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
1029
1030 enum {
1031         MLXSW_REG_HTGT_POLICER_DISABLE,
1032         MLXSW_REG_HTGT_POLICER_ENABLE,
1033 };
1034
1035 /* reg_htgt_pide
1036  * Enable policer ID specified using 'pid' field.
1037  * Access: RW
1038  */
1039 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
1040
1041 /* reg_htgt_pid
1042  * Policer ID for the trap group.
1043  * Access: RW
1044  */
1045 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
1046
1047 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
1048
1049 /* reg_htgt_mirror_action
1050  * Mirror action to use.
1051  * 0 - Trap to CPU.
1052  * 1 - Trap to CPU and mirror to a mirroring agent.
1053  * 2 - Mirror to a mirroring agent and do not trap to CPU.
1054  * Access: RW
1055  *
1056  * Note: Mirroring to a mirroring agent is only supported in Spectrum.
1057  */
1058 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
1059
1060 /* reg_htgt_mirroring_agent
1061  * Mirroring agent.
1062  * Access: RW
1063  */
1064 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
1065
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.
1072  * Access: RW
1073  *
1074  * Note: In SwitchX-2 this field is ignored and the priority value is replaced
1075  * by the 'trap_group' field.
1076  */
1077 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
1078
1079 /* reg_htgt_local_path_cpu_tclass
1080  * CPU ingress traffic class for the trap group.
1081  * Access: RW
1082  */
1083 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
1084
1085 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD      0x15
1086 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX        0x14
1087
1088 /* reg_htgt_local_path_rdq
1089  * Receive descriptor queue (RDQ) to use for the trap group.
1090  * Access: RW
1091  */
1092 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
1093
1094 static inline void mlxsw_reg_htgt_pack(char *payload, u8 trap_group)
1095 {
1096         u8 swid, rdq;
1097
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;
1102         } else {
1103                 swid = 0;
1104                 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX;
1105         }
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);
1116 }
1117
1118 /* HPKT - Host Packet Trap
1119  * -----------------------
1120  * Configures trap IDs inside trap groups.
1121  */
1122 #define MLXSW_REG_HPKT_ID 0x7003
1123 #define MLXSW_REG_HPKT_LEN 0x10
1124
1125 static const struct mlxsw_reg_info mlxsw_reg_hpkt = {
1126         .id = MLXSW_REG_HPKT_ID,
1127         .len = MLXSW_REG_HPKT_LEN,
1128 };
1129
1130 enum {
1131         MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
1132         MLXSW_REG_HPKT_ACK_REQUIRED,
1133 };
1134
1135 /* reg_hpkt_ack
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.
1139  * Access: RW
1140  *
1141  * Note: Currently not supported by firmware.
1142  */
1143 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
1144
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,
1152 };
1153
1154 /* reg_hpkt_action
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).
1159  * 3 - Discard.
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).
1162  * Access: RW
1163  *
1164  * Note: Must be set to 0 (forward) for event trap IDs, as they are already
1165  * addressed to the CPU.
1166  */
1167 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
1168
1169 /* reg_hpkt_trap_group
1170  * Trap group to associate the trap with.
1171  * Access: RW
1172  */
1173 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
1174
1175 /* reg_hpkt_trap_id
1176  * Trap ID.
1177  * Access: Index
1178  *
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.
1181  */
1182 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 9);
1183
1184 enum {
1185         MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
1186         MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
1187         MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
1188 };
1189
1190 /* reg_hpkt_ctrl
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.
1195  * Access: RW
1196  */
1197 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
1198
1199 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action,
1200                                        u8 trap_group, u16 trap_id)
1201 {
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);
1208 }
1209
1210 static inline const char *mlxsw_reg_id_str(u16 reg_id)
1211 {
1212         switch (reg_id) {
1213         case MLXSW_REG_SGCR_ID:
1214                 return "SGCR";
1215         case MLXSW_REG_SPAD_ID:
1216                 return "SPAD";
1217         case MLXSW_REG_SMID_ID:
1218                 return "SMID";
1219         case MLXSW_REG_SPMS_ID:
1220                 return "SPMS";
1221         case MLXSW_REG_SFGC_ID:
1222                 return "SFGC";
1223         case MLXSW_REG_SFTR_ID:
1224                 return "SFTR";
1225         case MLXSW_REG_SPMLR_ID:
1226                 return "SPMLR";
1227         case MLXSW_REG_PMLP_ID:
1228                 return "PMLP";
1229         case MLXSW_REG_PMTU_ID:
1230                 return "PMTU";
1231         case MLXSW_REG_PTYS_ID:
1232                 return "PTYS";
1233         case MLXSW_REG_PPAD_ID:
1234                 return "PPAD";
1235         case MLXSW_REG_PAOS_ID:
1236                 return "PAOS";
1237         case MLXSW_REG_PPCNT_ID:
1238                 return "PPCNT";
1239         case MLXSW_REG_PSPA_ID:
1240                 return "PSPA";
1241         case MLXSW_REG_HTGT_ID:
1242                 return "HTGT";
1243         case MLXSW_REG_HPKT_ID:
1244                 return "HPKT";
1245         default:
1246                 return "*UNKNOWN*";
1247         }
1248 }
1249
1250 /* PUDE - Port Up / Down Event
1251  * ---------------------------
1252  * Reports the operational state change of a port.
1253  */
1254 #define MLXSW_REG_PUDE_LEN 0x10
1255
1256 /* reg_pude_swid
1257  * Switch partition ID with which to associate the port.
1258  * Access: Index
1259  */
1260 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
1261
1262 /* reg_pude_local_port
1263  * Local port number.
1264  * Access: Index
1265  */
1266 MLXSW_ITEM32(reg, pude, local_port, 0x00, 16, 8);
1267
1268 /* reg_pude_admin_status
1269  * Port administrative state (the desired state).
1270  * 1 - Up.
1271  * 2 - Down.
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.
1275  * Access: RO
1276  */
1277 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
1278
1279 /* reg_pude_oper_status
1280  * Port operatioanl state.
1281  * 1 - Up.
1282  * 2 - Down.
1283  * 3 - Down by port failure. This means that the device will not let the
1284  *     port up again until explicitly specified by software.
1285  * Access: RO
1286  */
1287 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);
1288
1289 #endif