]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/mellanox/mlxsw/reg.h
mlxsw: reg: Add shared buffer configuration registers definitions
[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 /* SSPR - Switch System Port Record Register
103  * -----------------------------------------
104  * Configures the system port to local port mapping.
105  */
106 #define MLXSW_REG_SSPR_ID 0x2008
107 #define MLXSW_REG_SSPR_LEN 0x8
108
109 static const struct mlxsw_reg_info mlxsw_reg_sspr = {
110         .id = MLXSW_REG_SSPR_ID,
111         .len = MLXSW_REG_SSPR_LEN,
112 };
113
114 /* reg_sspr_m
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
119  * per local port.
120  *
121  * Note: Must be set for Spectrum.
122  * Access: RW
123  */
124 MLXSW_ITEM32(reg, sspr, m, 0x00, 31, 1);
125
126 /* reg_sspr_local_port
127  * Local port number.
128  *
129  * Access: RW
130  */
131 MLXSW_ITEM32(reg, sspr, local_port, 0x00, 16, 8);
132
133 /* reg_sspr_sub_port
134  * Virtual port within the physical port.
135  * Should be set to 0 when virtual ports are not enabled on the port.
136  *
137  * Access: RW
138  */
139 MLXSW_ITEM32(reg, sspr, sub_port, 0x00, 8, 8);
140
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).
144  *
145  * Currently, only single-ASIC configurations are supported, so we default to
146  * 1:1 mapping between system ports and local ports.
147  * Access: Index
148  */
149 MLXSW_ITEM32(reg, sspr, system_port, 0x04, 0, 16);
150
151 static inline void mlxsw_reg_sspr_pack(char *payload, u8 local_port)
152 {
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);
158 }
159
160 /* SFD - Switch Filtering Database
161  * -------------------------------
162  * The following register defines the access to the filtering database.
163  * The register supports querying, adding, removing and modifying the database.
164  * The access is optimized for bulk updates in which case more than one
165  * FDB record is present in the same command.
166  */
167 #define MLXSW_REG_SFD_ID 0x200A
168 #define MLXSW_REG_SFD_BASE_LEN 0x10 /* base length, without records */
169 #define MLXSW_REG_SFD_REC_LEN 0x10 /* record length */
170 #define MLXSW_REG_SFD_REC_MAX_COUNT 64
171 #define MLXSW_REG_SFD_LEN (MLXSW_REG_SFD_BASE_LEN +     \
172                            MLXSW_REG_SFD_REC_LEN * MLXSW_REG_SFD_REC_MAX_COUNT)
173
174 static const struct mlxsw_reg_info mlxsw_reg_sfd = {
175         .id = MLXSW_REG_SFD_ID,
176         .len = MLXSW_REG_SFD_LEN,
177 };
178
179 /* reg_sfd_swid
180  * Switch partition ID for queries. Reserved on Write.
181  * Access: Index
182  */
183 MLXSW_ITEM32(reg, sfd, swid, 0x00, 24, 8);
184
185 enum mlxsw_reg_sfd_op {
186         /* Dump entire FDB a (process according to record_locator) */
187         MLXSW_REG_SFD_OP_QUERY_DUMP = 0,
188         /* Query records by {MAC, VID/FID} value */
189         MLXSW_REG_SFD_OP_QUERY_QUERY = 1,
190         /* Query and clear activity. Query records by {MAC, VID/FID} value */
191         MLXSW_REG_SFD_OP_QUERY_QUERY_AND_CLEAR_ACTIVITY = 2,
192         /* Test. Response indicates if each of the records could be
193          * added to the FDB.
194          */
195         MLXSW_REG_SFD_OP_WRITE_TEST = 0,
196         /* Add/modify. Aged-out records cannot be added. This command removes
197          * the learning notification of the {MAC, VID/FID}. Response includes
198          * the entries that were added to the FDB.
199          */
200         MLXSW_REG_SFD_OP_WRITE_EDIT = 1,
201         /* Remove record by {MAC, VID/FID}. This command also removes
202          * the learning notification and aged-out notifications
203          * of the {MAC, VID/FID}. The response provides current (pre-removal)
204          * entries as non-aged-out.
205          */
206         MLXSW_REG_SFD_OP_WRITE_REMOVE = 2,
207         /* Remove learned notification by {MAC, VID/FID}. The response provides
208          * the removed learning notification.
209          */
210         MLXSW_REG_SFD_OP_WRITE_REMOVE_NOTIFICATION = 2,
211 };
212
213 /* reg_sfd_op
214  * Operation.
215  * Access: OP
216  */
217 MLXSW_ITEM32(reg, sfd, op, 0x04, 30, 2);
218
219 /* reg_sfd_record_locator
220  * Used for querying the FDB. Use record_locator=0 to initiate the
221  * query. When a record is returned, a new record_locator is
222  * returned to be used in the subsequent query.
223  * Reserved for database update.
224  * Access: Index
225  */
226 MLXSW_ITEM32(reg, sfd, record_locator, 0x04, 0, 30);
227
228 /* reg_sfd_num_rec
229  * Request: Number of records to read/add/modify/remove
230  * Response: Number of records read/added/replaced/removed
231  * See above description for more details.
232  * Ranges 0..64
233  * Access: RW
234  */
235 MLXSW_ITEM32(reg, sfd, num_rec, 0x08, 0, 8);
236
237 static inline void mlxsw_reg_sfd_pack(char *payload, enum mlxsw_reg_sfd_op op,
238                                       u32 record_locator)
239 {
240         MLXSW_REG_ZERO(sfd, payload);
241         mlxsw_reg_sfd_op_set(payload, op);
242         mlxsw_reg_sfd_record_locator_set(payload, record_locator);
243 }
244
245 /* reg_sfd_rec_swid
246  * Switch partition ID.
247  * Access: Index
248  */
249 MLXSW_ITEM32_INDEXED(reg, sfd, rec_swid, MLXSW_REG_SFD_BASE_LEN, 24, 8,
250                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
251
252 enum mlxsw_reg_sfd_rec_type {
253         MLXSW_REG_SFD_REC_TYPE_UNICAST = 0x0,
254 };
255
256 /* reg_sfd_rec_type
257  * FDB record type.
258  * Access: RW
259  */
260 MLXSW_ITEM32_INDEXED(reg, sfd, rec_type, MLXSW_REG_SFD_BASE_LEN, 20, 4,
261                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
262
263 enum mlxsw_reg_sfd_rec_policy {
264         /* Replacement disabled, aging disabled. */
265         MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY = 0,
266         /* (mlag remote): Replacement enabled, aging disabled,
267          * learning notification enabled on this port.
268          */
269         MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_MLAG = 1,
270         /* (ingress device): Replacement enabled, aging enabled. */
271         MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS = 3,
272 };
273
274 /* reg_sfd_rec_policy
275  * Policy.
276  * Access: RW
277  */
278 MLXSW_ITEM32_INDEXED(reg, sfd, rec_policy, MLXSW_REG_SFD_BASE_LEN, 18, 2,
279                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
280
281 /* reg_sfd_rec_a
282  * Activity. Set for new static entries. Set for static entries if a frame SMAC
283  * lookup hits on the entry.
284  * To clear the a bit, use "query and clear activity" op.
285  * Access: RO
286  */
287 MLXSW_ITEM32_INDEXED(reg, sfd, rec_a, MLXSW_REG_SFD_BASE_LEN, 16, 1,
288                      MLXSW_REG_SFD_REC_LEN, 0x00, false);
289
290 /* reg_sfd_rec_mac
291  * MAC address.
292  * Access: Index
293  */
294 MLXSW_ITEM_BUF_INDEXED(reg, sfd, rec_mac, MLXSW_REG_SFD_BASE_LEN, 6,
295                        MLXSW_REG_SFD_REC_LEN, 0x02);
296
297 enum mlxsw_reg_sfd_rec_action {
298         /* forward */
299         MLXSW_REG_SFD_REC_ACTION_NOP = 0,
300         /* forward and trap, trap_id is FDB_TRAP */
301         MLXSW_REG_SFD_REC_ACTION_MIRROR_TO_CPU = 1,
302         /* trap and do not forward, trap_id is FDB_TRAP */
303         MLXSW_REG_SFD_REC_ACTION_TRAP = 3,
304         MLXSW_REG_SFD_REC_ACTION_DISCARD_ERROR = 15,
305 };
306
307 /* reg_sfd_rec_action
308  * Action to apply on the packet.
309  * Note: Dynamic entries can only be configured with NOP action.
310  * Access: RW
311  */
312 MLXSW_ITEM32_INDEXED(reg, sfd, rec_action, MLXSW_REG_SFD_BASE_LEN, 28, 4,
313                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
314
315 /* reg_sfd_uc_sub_port
316  * LAG sub port.
317  * Must be 0 if multichannel VEPA is not enabled.
318  * Access: RW
319  */
320 MLXSW_ITEM32_INDEXED(reg, sfd, uc_sub_port, MLXSW_REG_SFD_BASE_LEN, 16, 8,
321                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
322
323 /* reg_sfd_uc_fid_vid
324  * Filtering ID or VLAN ID
325  * For SwitchX and SwitchX-2:
326  * - Dynamic entries (policy 2,3) use FID
327  * - Static entries (policy 0) use VID
328  * - When independent learning is configured, VID=FID
329  * For Spectrum: use FID for both Dynamic and Static entries.
330  * VID should not be used.
331  * Access: Index
332  */
333 MLXSW_ITEM32_INDEXED(reg, sfd, uc_fid_vid, MLXSW_REG_SFD_BASE_LEN, 0, 16,
334                      MLXSW_REG_SFD_REC_LEN, 0x08, false);
335
336 /* reg_sfd_uc_system_port
337  * Unique port identifier for the final destination of the packet.
338  * Access: RW
339  */
340 MLXSW_ITEM32_INDEXED(reg, sfd, uc_system_port, MLXSW_REG_SFD_BASE_LEN, 0, 16,
341                      MLXSW_REG_SFD_REC_LEN, 0x0C, false);
342
343 static inline void mlxsw_reg_sfd_uc_pack(char *payload, int rec_index,
344                                          enum mlxsw_reg_sfd_rec_policy policy,
345                                          const char *mac, u16 vid,
346                                          enum mlxsw_reg_sfd_rec_action action,
347                                          u8 local_port)
348 {
349         u8 num_rec = mlxsw_reg_sfd_num_rec_get(payload);
350
351         if (rec_index >= num_rec)
352                 mlxsw_reg_sfd_num_rec_set(payload, rec_index + 1);
353         mlxsw_reg_sfd_rec_swid_set(payload, rec_index, 0);
354         mlxsw_reg_sfd_rec_type_set(payload, rec_index,
355                                    MLXSW_REG_SFD_REC_TYPE_UNICAST);
356         mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
357         mlxsw_reg_sfd_rec_mac_memcpy_to(payload, rec_index, mac);
358         mlxsw_reg_sfd_uc_sub_port_set(payload, rec_index, 0);
359         mlxsw_reg_sfd_uc_fid_vid_set(payload, rec_index, vid);
360         mlxsw_reg_sfd_rec_action_set(payload, rec_index, action);
361         mlxsw_reg_sfd_uc_system_port_set(payload, rec_index, local_port);
362 }
363
364 static inline void
365 mlxsw_reg_sfd_uc_unpack(char *payload, int rec_index,
366                         char *mac, u16 *p_vid,
367                         u8 *p_local_port)
368 {
369         mlxsw_reg_sfd_rec_mac_memcpy_from(payload, rec_index, mac);
370         *p_vid = mlxsw_reg_sfd_uc_fid_vid_get(payload, rec_index);
371         *p_local_port = mlxsw_reg_sfd_uc_system_port_get(payload, rec_index);
372 }
373
374 /* SFN - Switch FDB Notification Register
375  * -------------------------------------------
376  * The switch provides notifications on newly learned FDB entries and
377  * aged out entries. The notifications can be polled by software.
378  */
379 #define MLXSW_REG_SFN_ID 0x200B
380 #define MLXSW_REG_SFN_BASE_LEN 0x10 /* base length, without records */
381 #define MLXSW_REG_SFN_REC_LEN 0x10 /* record length */
382 #define MLXSW_REG_SFN_REC_MAX_COUNT 64
383 #define MLXSW_REG_SFN_LEN (MLXSW_REG_SFN_BASE_LEN +     \
384                            MLXSW_REG_SFN_REC_LEN * MLXSW_REG_SFN_REC_MAX_COUNT)
385
386 static const struct mlxsw_reg_info mlxsw_reg_sfn = {
387         .id = MLXSW_REG_SFN_ID,
388         .len = MLXSW_REG_SFN_LEN,
389 };
390
391 /* reg_sfn_swid
392  * Switch partition ID.
393  * Access: Index
394  */
395 MLXSW_ITEM32(reg, sfn, swid, 0x00, 24, 8);
396
397 /* reg_sfn_num_rec
398  * Request: Number of learned notifications and aged-out notification
399  * records requested.
400  * Response: Number of notification records returned (must be smaller
401  * than or equal to the value requested)
402  * Ranges 0..64
403  * Access: OP
404  */
405 MLXSW_ITEM32(reg, sfn, num_rec, 0x04, 0, 8);
406
407 static inline void mlxsw_reg_sfn_pack(char *payload)
408 {
409         MLXSW_REG_ZERO(sfn, payload);
410         mlxsw_reg_sfn_swid_set(payload, 0);
411         mlxsw_reg_sfn_num_rec_set(payload, MLXSW_REG_SFN_REC_MAX_COUNT);
412 }
413
414 /* reg_sfn_rec_swid
415  * Switch partition ID.
416  * Access: RO
417  */
418 MLXSW_ITEM32_INDEXED(reg, sfn, rec_swid, MLXSW_REG_SFN_BASE_LEN, 24, 8,
419                      MLXSW_REG_SFN_REC_LEN, 0x00, false);
420
421 enum mlxsw_reg_sfn_rec_type {
422         /* MAC addresses learned on a regular port. */
423         MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC = 0x5,
424         /* Aged-out MAC address on a regular port */
425         MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC = 0x7,
426 };
427
428 /* reg_sfn_rec_type
429  * Notification record type.
430  * Access: RO
431  */
432 MLXSW_ITEM32_INDEXED(reg, sfn, rec_type, MLXSW_REG_SFN_BASE_LEN, 20, 4,
433                      MLXSW_REG_SFN_REC_LEN, 0x00, false);
434
435 /* reg_sfn_rec_mac
436  * MAC address.
437  * Access: RO
438  */
439 MLXSW_ITEM_BUF_INDEXED(reg, sfn, rec_mac, MLXSW_REG_SFN_BASE_LEN, 6,
440                        MLXSW_REG_SFN_REC_LEN, 0x02);
441
442 /* reg_sfd_mac_sub_port
443  * VEPA channel on the local port.
444  * 0 if multichannel VEPA is not enabled.
445  * Access: RO
446  */
447 MLXSW_ITEM32_INDEXED(reg, sfn, mac_sub_port, MLXSW_REG_SFN_BASE_LEN, 16, 8,
448                      MLXSW_REG_SFN_REC_LEN, 0x08, false);
449
450 /* reg_sfd_mac_fid
451  * Filtering identifier.
452  * Access: RO
453  */
454 MLXSW_ITEM32_INDEXED(reg, sfn, mac_fid, MLXSW_REG_SFN_BASE_LEN, 0, 16,
455                      MLXSW_REG_SFN_REC_LEN, 0x08, false);
456
457 /* reg_sfd_mac_system_port
458  * Unique port identifier for the final destination of the packet.
459  * Access: RO
460  */
461 MLXSW_ITEM32_INDEXED(reg, sfn, mac_system_port, MLXSW_REG_SFN_BASE_LEN, 0, 16,
462                      MLXSW_REG_SFN_REC_LEN, 0x0C, false);
463
464 static inline void mlxsw_reg_sfn_mac_unpack(char *payload, int rec_index,
465                                             char *mac, u16 *p_vid,
466                                             u8 *p_local_port)
467 {
468         mlxsw_reg_sfn_rec_mac_memcpy_from(payload, rec_index, mac);
469         *p_vid = mlxsw_reg_sfn_mac_fid_get(payload, rec_index);
470         *p_local_port = mlxsw_reg_sfn_mac_system_port_get(payload, rec_index);
471 }
472
473 /* SPMS - Switch Port MSTP/RSTP State Register
474  * -------------------------------------------
475  * Configures the spanning tree state of a physical port.
476  */
477 #define MLXSW_REG_SPMS_ID 0x200D
478 #define MLXSW_REG_SPMS_LEN 0x404
479
480 static const struct mlxsw_reg_info mlxsw_reg_spms = {
481         .id = MLXSW_REG_SPMS_ID,
482         .len = MLXSW_REG_SPMS_LEN,
483 };
484
485 /* reg_spms_local_port
486  * Local port number.
487  * Access: Index
488  */
489 MLXSW_ITEM32(reg, spms, local_port, 0x00, 16, 8);
490
491 enum mlxsw_reg_spms_state {
492         MLXSW_REG_SPMS_STATE_NO_CHANGE,
493         MLXSW_REG_SPMS_STATE_DISCARDING,
494         MLXSW_REG_SPMS_STATE_LEARNING,
495         MLXSW_REG_SPMS_STATE_FORWARDING,
496 };
497
498 /* reg_spms_state
499  * Spanning tree state of each VLAN ID (VID) of the local port.
500  * 0 - Do not change spanning tree state (used only when writing).
501  * 1 - Discarding. No learning or forwarding to/from this port (default).
502  * 2 - Learning. Port is learning, but not forwarding.
503  * 3 - Forwarding. Port is learning and forwarding.
504  * Access: RW
505  */
506 MLXSW_ITEM_BIT_ARRAY(reg, spms, state, 0x04, 0x400, 2);
507
508 static inline void mlxsw_reg_spms_pack(char *payload, u8 local_port)
509 {
510         MLXSW_REG_ZERO(spms, payload);
511         mlxsw_reg_spms_local_port_set(payload, local_port);
512 }
513
514 static inline void mlxsw_reg_spms_vid_pack(char *payload, u16 vid,
515                                            enum mlxsw_reg_spms_state state)
516 {
517         mlxsw_reg_spms_state_set(payload, vid, state);
518 }
519
520 /* SPVID - Switch Port VID
521  * -----------------------
522  * The switch port VID configures the default VID for a port.
523  */
524 #define MLXSW_REG_SPVID_ID 0x200E
525 #define MLXSW_REG_SPVID_LEN 0x08
526
527 static const struct mlxsw_reg_info mlxsw_reg_spvid = {
528         .id = MLXSW_REG_SPVID_ID,
529         .len = MLXSW_REG_SPVID_LEN,
530 };
531
532 /* reg_spvid_local_port
533  * Local port number.
534  * Access: Index
535  */
536 MLXSW_ITEM32(reg, spvid, local_port, 0x00, 16, 8);
537
538 /* reg_spvid_sub_port
539  * Virtual port within the physical port.
540  * Should be set to 0 when virtual ports are not enabled on the port.
541  * Access: Index
542  */
543 MLXSW_ITEM32(reg, spvid, sub_port, 0x00, 8, 8);
544
545 /* reg_spvid_pvid
546  * Port default VID
547  * Access: RW
548  */
549 MLXSW_ITEM32(reg, spvid, pvid, 0x04, 0, 12);
550
551 static inline void mlxsw_reg_spvid_pack(char *payload, u8 local_port, u16 pvid)
552 {
553         MLXSW_REG_ZERO(spvid, payload);
554         mlxsw_reg_spvid_local_port_set(payload, local_port);
555         mlxsw_reg_spvid_pvid_set(payload, pvid);
556 }
557
558 /* SPVM - Switch Port VLAN Membership
559  * ----------------------------------
560  * The Switch Port VLAN Membership register configures the VLAN membership
561  * of a port in a VLAN denoted by VID. VLAN membership is managed per
562  * virtual port. The register can be used to add and remove VID(s) from a port.
563  */
564 #define MLXSW_REG_SPVM_ID 0x200F
565 #define MLXSW_REG_SPVM_BASE_LEN 0x04 /* base length, without records */
566 #define MLXSW_REG_SPVM_REC_LEN 0x04 /* record length */
567 #define MLXSW_REG_SPVM_REC_MAX_COUNT 256
568 #define MLXSW_REG_SPVM_LEN (MLXSW_REG_SPVM_BASE_LEN +   \
569                     MLXSW_REG_SPVM_REC_LEN * MLXSW_REG_SPVM_REC_MAX_COUNT)
570
571 static const struct mlxsw_reg_info mlxsw_reg_spvm = {
572         .id = MLXSW_REG_SPVM_ID,
573         .len = MLXSW_REG_SPVM_LEN,
574 };
575
576 /* reg_spvm_pt
577  * Priority tagged. If this bit is set, packets forwarded to the port with
578  * untagged VLAN membership (u bit is set) will be tagged with priority tag
579  * (VID=0)
580  * Access: RW
581  */
582 MLXSW_ITEM32(reg, spvm, pt, 0x00, 31, 1);
583
584 /* reg_spvm_pte
585  * Priority Tagged Update Enable. On Write operations, if this bit is cleared,
586  * the pt bit will NOT be updated. To update the pt bit, pte must be set.
587  * Access: WO
588  */
589 MLXSW_ITEM32(reg, spvm, pte, 0x00, 30, 1);
590
591 /* reg_spvm_local_port
592  * Local port number.
593  * Access: Index
594  */
595 MLXSW_ITEM32(reg, spvm, local_port, 0x00, 16, 8);
596
597 /* reg_spvm_sub_port
598  * Virtual port within the physical port.
599  * Should be set to 0 when virtual ports are not enabled on the port.
600  * Access: Index
601  */
602 MLXSW_ITEM32(reg, spvm, sub_port, 0x00, 8, 8);
603
604 /* reg_spvm_num_rec
605  * Number of records to update. Each record contains: i, e, u, vid.
606  * Access: OP
607  */
608 MLXSW_ITEM32(reg, spvm, num_rec, 0x00, 0, 8);
609
610 /* reg_spvm_rec_i
611  * Ingress membership in VLAN ID.
612  * Access: Index
613  */
614 MLXSW_ITEM32_INDEXED(reg, spvm, rec_i,
615                      MLXSW_REG_SPVM_BASE_LEN, 14, 1,
616                      MLXSW_REG_SPVM_REC_LEN, 0, false);
617
618 /* reg_spvm_rec_e
619  * Egress membership in VLAN ID.
620  * Access: Index
621  */
622 MLXSW_ITEM32_INDEXED(reg, spvm, rec_e,
623                      MLXSW_REG_SPVM_BASE_LEN, 13, 1,
624                      MLXSW_REG_SPVM_REC_LEN, 0, false);
625
626 /* reg_spvm_rec_u
627  * Untagged - port is an untagged member - egress transmission uses untagged
628  * frames on VID<n>
629  * Access: Index
630  */
631 MLXSW_ITEM32_INDEXED(reg, spvm, rec_u,
632                      MLXSW_REG_SPVM_BASE_LEN, 12, 1,
633                      MLXSW_REG_SPVM_REC_LEN, 0, false);
634
635 /* reg_spvm_rec_vid
636  * Egress membership in VLAN ID.
637  * Access: Index
638  */
639 MLXSW_ITEM32_INDEXED(reg, spvm, rec_vid,
640                      MLXSW_REG_SPVM_BASE_LEN, 0, 12,
641                      MLXSW_REG_SPVM_REC_LEN, 0, false);
642
643 static inline void mlxsw_reg_spvm_pack(char *payload, u8 local_port,
644                                        u16 vid_begin, u16 vid_end,
645                                        bool is_member, bool untagged)
646 {
647         int size = vid_end - vid_begin + 1;
648         int i;
649
650         MLXSW_REG_ZERO(spvm, payload);
651         mlxsw_reg_spvm_local_port_set(payload, local_port);
652         mlxsw_reg_spvm_num_rec_set(payload, size);
653
654         for (i = 0; i < size; i++) {
655                 mlxsw_reg_spvm_rec_i_set(payload, i, is_member);
656                 mlxsw_reg_spvm_rec_e_set(payload, i, is_member);
657                 mlxsw_reg_spvm_rec_u_set(payload, i, untagged);
658                 mlxsw_reg_spvm_rec_vid_set(payload, i, vid_begin + i);
659         }
660 }
661
662 /* SFGC - Switch Flooding Group Configuration
663  * ------------------------------------------
664  * The following register controls the association of flooding tables and MIDs
665  * to packet types used for flooding.
666  */
667 #define MLXSW_REG_SFGC_ID 0x2011
668 #define MLXSW_REG_SFGC_LEN 0x10
669
670 static const struct mlxsw_reg_info mlxsw_reg_sfgc = {
671         .id = MLXSW_REG_SFGC_ID,
672         .len = MLXSW_REG_SFGC_LEN,
673 };
674
675 enum mlxsw_reg_sfgc_type {
676         MLXSW_REG_SFGC_TYPE_BROADCAST,
677         MLXSW_REG_SFGC_TYPE_UNKNOWN_UNICAST,
678         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV4,
679         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_IPV6,
680         MLXSW_REG_SFGC_TYPE_RESERVED,
681         MLXSW_REG_SFGC_TYPE_UNREGISTERED_MULTICAST_NON_IP,
682         MLXSW_REG_SFGC_TYPE_IPV4_LINK_LOCAL,
683         MLXSW_REG_SFGC_TYPE_IPV6_ALL_HOST,
684         MLXSW_REG_SFGC_TYPE_MAX,
685 };
686
687 /* reg_sfgc_type
688  * The traffic type to reach the flooding table.
689  * Access: Index
690  */
691 MLXSW_ITEM32(reg, sfgc, type, 0x00, 0, 4);
692
693 enum mlxsw_reg_sfgc_bridge_type {
694         MLXSW_REG_SFGC_BRIDGE_TYPE_1Q_FID = 0,
695         MLXSW_REG_SFGC_BRIDGE_TYPE_VFID = 1,
696 };
697
698 /* reg_sfgc_bridge_type
699  * Access: Index
700  *
701  * Note: SwitchX-2 only supports 802.1Q mode.
702  */
703 MLXSW_ITEM32(reg, sfgc, bridge_type, 0x04, 24, 3);
704
705 enum mlxsw_flood_table_type {
706         MLXSW_REG_SFGC_TABLE_TYPE_VID = 1,
707         MLXSW_REG_SFGC_TABLE_TYPE_SINGLE = 2,
708         MLXSW_REG_SFGC_TABLE_TYPE_ANY = 0,
709         MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFEST = 3,
710         MLXSW_REG_SFGC_TABLE_TYPE_FID = 4,
711 };
712
713 /* reg_sfgc_table_type
714  * See mlxsw_flood_table_type
715  * Access: RW
716  *
717  * Note: FID offset and FID types are not supported in SwitchX-2.
718  */
719 MLXSW_ITEM32(reg, sfgc, table_type, 0x04, 16, 3);
720
721 /* reg_sfgc_flood_table
722  * Flooding table index to associate with the specific type on the specific
723  * switch partition.
724  * Access: RW
725  */
726 MLXSW_ITEM32(reg, sfgc, flood_table, 0x04, 0, 6);
727
728 /* reg_sfgc_mid
729  * The multicast ID for the swid. Not supported for Spectrum
730  * Access: RW
731  */
732 MLXSW_ITEM32(reg, sfgc, mid, 0x08, 0, 16);
733
734 /* reg_sfgc_counter_set_type
735  * Counter Set Type for flow counters.
736  * Access: RW
737  */
738 MLXSW_ITEM32(reg, sfgc, counter_set_type, 0x0C, 24, 8);
739
740 /* reg_sfgc_counter_index
741  * Counter Index for flow counters.
742  * Access: RW
743  */
744 MLXSW_ITEM32(reg, sfgc, counter_index, 0x0C, 0, 24);
745
746 static inline void
747 mlxsw_reg_sfgc_pack(char *payload, enum mlxsw_reg_sfgc_type type,
748                     enum mlxsw_reg_sfgc_bridge_type bridge_type,
749                     enum mlxsw_flood_table_type table_type,
750                     unsigned int flood_table)
751 {
752         MLXSW_REG_ZERO(sfgc, payload);
753         mlxsw_reg_sfgc_type_set(payload, type);
754         mlxsw_reg_sfgc_bridge_type_set(payload, bridge_type);
755         mlxsw_reg_sfgc_table_type_set(payload, table_type);
756         mlxsw_reg_sfgc_flood_table_set(payload, flood_table);
757         mlxsw_reg_sfgc_mid_set(payload, MLXSW_PORT_MID);
758 }
759
760 /* SFTR - Switch Flooding Table Register
761  * -------------------------------------
762  * The switch flooding table is used for flooding packet replication. The table
763  * defines a bit mask of ports for packet replication.
764  */
765 #define MLXSW_REG_SFTR_ID 0x2012
766 #define MLXSW_REG_SFTR_LEN 0x420
767
768 static const struct mlxsw_reg_info mlxsw_reg_sftr = {
769         .id = MLXSW_REG_SFTR_ID,
770         .len = MLXSW_REG_SFTR_LEN,
771 };
772
773 /* reg_sftr_swid
774  * Switch partition ID with which to associate the port.
775  * Access: Index
776  */
777 MLXSW_ITEM32(reg, sftr, swid, 0x00, 24, 8);
778
779 /* reg_sftr_flood_table
780  * Flooding table index to associate with the specific type on the specific
781  * switch partition.
782  * Access: Index
783  */
784 MLXSW_ITEM32(reg, sftr, flood_table, 0x00, 16, 6);
785
786 /* reg_sftr_index
787  * Index. Used as an index into the Flooding Table in case the table is
788  * configured to use VID / FID or FID Offset.
789  * Access: Index
790  */
791 MLXSW_ITEM32(reg, sftr, index, 0x00, 0, 16);
792
793 /* reg_sftr_table_type
794  * See mlxsw_flood_table_type
795  * Access: RW
796  */
797 MLXSW_ITEM32(reg, sftr, table_type, 0x04, 16, 3);
798
799 /* reg_sftr_range
800  * Range of entries to update
801  * Access: Index
802  */
803 MLXSW_ITEM32(reg, sftr, range, 0x04, 0, 16);
804
805 /* reg_sftr_port
806  * Local port membership (1 bit per port).
807  * Access: RW
808  */
809 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port, 0x20, 0x20, 1);
810
811 /* reg_sftr_cpu_port_mask
812  * CPU port mask (1 bit per port).
813  * Access: W
814  */
815 MLXSW_ITEM_BIT_ARRAY(reg, sftr, port_mask, 0x220, 0x20, 1);
816
817 static inline void mlxsw_reg_sftr_pack(char *payload,
818                                        unsigned int flood_table,
819                                        unsigned int index,
820                                        enum mlxsw_flood_table_type table_type,
821                                        unsigned int range, u8 port, bool set)
822 {
823         MLXSW_REG_ZERO(sftr, payload);
824         mlxsw_reg_sftr_swid_set(payload, 0);
825         mlxsw_reg_sftr_flood_table_set(payload, flood_table);
826         mlxsw_reg_sftr_index_set(payload, index);
827         mlxsw_reg_sftr_table_type_set(payload, table_type);
828         mlxsw_reg_sftr_range_set(payload, range);
829         mlxsw_reg_sftr_port_set(payload, port, set);
830         mlxsw_reg_sftr_port_mask_set(payload, port, 1);
831 }
832
833 /* SPMLR - Switch Port MAC Learning Register
834  * -----------------------------------------
835  * Controls the Switch MAC learning policy per port.
836  */
837 #define MLXSW_REG_SPMLR_ID 0x2018
838 #define MLXSW_REG_SPMLR_LEN 0x8
839
840 static const struct mlxsw_reg_info mlxsw_reg_spmlr = {
841         .id = MLXSW_REG_SPMLR_ID,
842         .len = MLXSW_REG_SPMLR_LEN,
843 };
844
845 /* reg_spmlr_local_port
846  * Local port number.
847  * Access: Index
848  */
849 MLXSW_ITEM32(reg, spmlr, local_port, 0x00, 16, 8);
850
851 /* reg_spmlr_sub_port
852  * Virtual port within the physical port.
853  * Should be set to 0 when virtual ports are not enabled on the port.
854  * Access: Index
855  */
856 MLXSW_ITEM32(reg, spmlr, sub_port, 0x00, 8, 8);
857
858 enum mlxsw_reg_spmlr_learn_mode {
859         MLXSW_REG_SPMLR_LEARN_MODE_DISABLE = 0,
860         MLXSW_REG_SPMLR_LEARN_MODE_ENABLE = 2,
861         MLXSW_REG_SPMLR_LEARN_MODE_SEC = 3,
862 };
863
864 /* reg_spmlr_learn_mode
865  * Learning mode on the port.
866  * 0 - Learning disabled.
867  * 2 - Learning enabled.
868  * 3 - Security mode.
869  *
870  * In security mode the switch does not learn MACs on the port, but uses the
871  * SMAC to see if it exists on another ingress port. If so, the packet is
872  * classified as a bad packet and is discarded unless the software registers
873  * to receive port security error packets usign HPKT.
874  */
875 MLXSW_ITEM32(reg, spmlr, learn_mode, 0x04, 30, 2);
876
877 static inline void mlxsw_reg_spmlr_pack(char *payload, u8 local_port,
878                                         enum mlxsw_reg_spmlr_learn_mode mode)
879 {
880         MLXSW_REG_ZERO(spmlr, payload);
881         mlxsw_reg_spmlr_local_port_set(payload, local_port);
882         mlxsw_reg_spmlr_sub_port_set(payload, 0);
883         mlxsw_reg_spmlr_learn_mode_set(payload, mode);
884 }
885
886 /* PMLP - Ports Module to Local Port Register
887  * ------------------------------------------
888  * Configures the assignment of modules to local ports.
889  */
890 #define MLXSW_REG_PMLP_ID 0x5002
891 #define MLXSW_REG_PMLP_LEN 0x40
892
893 static const struct mlxsw_reg_info mlxsw_reg_pmlp = {
894         .id = MLXSW_REG_PMLP_ID,
895         .len = MLXSW_REG_PMLP_LEN,
896 };
897
898 /* reg_pmlp_rxtx
899  * 0 - Tx value is used for both Tx and Rx.
900  * 1 - Rx value is taken from a separte field.
901  * Access: RW
902  */
903 MLXSW_ITEM32(reg, pmlp, rxtx, 0x00, 31, 1);
904
905 /* reg_pmlp_local_port
906  * Local port number.
907  * Access: Index
908  */
909 MLXSW_ITEM32(reg, pmlp, local_port, 0x00, 16, 8);
910
911 /* reg_pmlp_width
912  * 0 - Unmap local port.
913  * 1 - Lane 0 is used.
914  * 2 - Lanes 0 and 1 are used.
915  * 4 - Lanes 0, 1, 2 and 3 are used.
916  * Access: RW
917  */
918 MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8);
919
920 /* reg_pmlp_module
921  * Module number.
922  * Access: RW
923  */
924 MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0, false);
925
926 /* reg_pmlp_tx_lane
927  * Tx Lane. When rxtx field is cleared, this field is used for Rx as well.
928  * Access: RW
929  */
930 MLXSW_ITEM32_INDEXED(reg, pmlp, tx_lane, 0x04, 16, 2, 0x04, 16, false);
931
932 /* reg_pmlp_rx_lane
933  * Rx Lane. When rxtx field is cleared, this field is ignored and Rx lane is
934  * equal to Tx lane.
935  * Access: RW
936  */
937 MLXSW_ITEM32_INDEXED(reg, pmlp, rx_lane, 0x04, 24, 2, 0x04, 24, false);
938
939 static inline void mlxsw_reg_pmlp_pack(char *payload, u8 local_port)
940 {
941         MLXSW_REG_ZERO(pmlp, payload);
942         mlxsw_reg_pmlp_local_port_set(payload, local_port);
943 }
944
945 /* PMTU - Port MTU Register
946  * ------------------------
947  * Configures and reports the port MTU.
948  */
949 #define MLXSW_REG_PMTU_ID 0x5003
950 #define MLXSW_REG_PMTU_LEN 0x10
951
952 static const struct mlxsw_reg_info mlxsw_reg_pmtu = {
953         .id = MLXSW_REG_PMTU_ID,
954         .len = MLXSW_REG_PMTU_LEN,
955 };
956
957 /* reg_pmtu_local_port
958  * Local port number.
959  * Access: Index
960  */
961 MLXSW_ITEM32(reg, pmtu, local_port, 0x00, 16, 8);
962
963 /* reg_pmtu_max_mtu
964  * Maximum MTU.
965  * When port type (e.g. Ethernet) is configured, the relevant MTU is
966  * reported, otherwise the minimum between the max_mtu of the different
967  * types is reported.
968  * Access: RO
969  */
970 MLXSW_ITEM32(reg, pmtu, max_mtu, 0x04, 16, 16);
971
972 /* reg_pmtu_admin_mtu
973  * MTU value to set port to. Must be smaller or equal to max_mtu.
974  * Note: If port type is Infiniband, then port must be disabled, when its
975  * MTU is set.
976  * Access: RW
977  */
978 MLXSW_ITEM32(reg, pmtu, admin_mtu, 0x08, 16, 16);
979
980 /* reg_pmtu_oper_mtu
981  * The actual MTU configured on the port. Packets exceeding this size
982  * will be dropped.
983  * Note: In Ethernet and FC oper_mtu == admin_mtu, however, in Infiniband
984  * oper_mtu might be smaller than admin_mtu.
985  * Access: RO
986  */
987 MLXSW_ITEM32(reg, pmtu, oper_mtu, 0x0C, 16, 16);
988
989 static inline void mlxsw_reg_pmtu_pack(char *payload, u8 local_port,
990                                        u16 new_mtu)
991 {
992         MLXSW_REG_ZERO(pmtu, payload);
993         mlxsw_reg_pmtu_local_port_set(payload, local_port);
994         mlxsw_reg_pmtu_max_mtu_set(payload, 0);
995         mlxsw_reg_pmtu_admin_mtu_set(payload, new_mtu);
996         mlxsw_reg_pmtu_oper_mtu_set(payload, 0);
997 }
998
999 /* PTYS - Port Type and Speed Register
1000  * -----------------------------------
1001  * Configures and reports the port speed type.
1002  *
1003  * Note: When set while the link is up, the changes will not take effect
1004  * until the port transitions from down to up state.
1005  */
1006 #define MLXSW_REG_PTYS_ID 0x5004
1007 #define MLXSW_REG_PTYS_LEN 0x40
1008
1009 static const struct mlxsw_reg_info mlxsw_reg_ptys = {
1010         .id = MLXSW_REG_PTYS_ID,
1011         .len = MLXSW_REG_PTYS_LEN,
1012 };
1013
1014 /* reg_ptys_local_port
1015  * Local port number.
1016  * Access: Index
1017  */
1018 MLXSW_ITEM32(reg, ptys, local_port, 0x00, 16, 8);
1019
1020 #define MLXSW_REG_PTYS_PROTO_MASK_ETH   BIT(2)
1021
1022 /* reg_ptys_proto_mask
1023  * Protocol mask. Indicates which protocol is used.
1024  * 0 - Infiniband.
1025  * 1 - Fibre Channel.
1026  * 2 - Ethernet.
1027  * Access: Index
1028  */
1029 MLXSW_ITEM32(reg, ptys, proto_mask, 0x00, 0, 3);
1030
1031 #define MLXSW_REG_PTYS_ETH_SPEED_SGMII                  BIT(0)
1032 #define MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX            BIT(1)
1033 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4            BIT(2)
1034 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4            BIT(3)
1035 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR             BIT(4)
1036 #define MLXSW_REG_PTYS_ETH_SPEED_20GBASE_KR2            BIT(5)
1037 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4            BIT(6)
1038 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4            BIT(7)
1039 #define MLXSW_REG_PTYS_ETH_SPEED_56GBASE_R4             BIT(8)
1040 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR             BIT(12)
1041 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR             BIT(13)
1042 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR          BIT(14)
1043 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4            BIT(15)
1044 #define MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4        BIT(16)
1045 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR4            BIT(19)
1046 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4           BIT(20)
1047 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4           BIT(21)
1048 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4           BIT(22)
1049 #define MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4       BIT(23)
1050 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_TX             BIT(24)
1051 #define MLXSW_REG_PTYS_ETH_SPEED_100BASE_T              BIT(25)
1052 #define MLXSW_REG_PTYS_ETH_SPEED_10GBASE_T              BIT(26)
1053 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR             BIT(27)
1054 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR             BIT(28)
1055 #define MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR             BIT(29)
1056 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2            BIT(30)
1057 #define MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2            BIT(31)
1058
1059 /* reg_ptys_eth_proto_cap
1060  * Ethernet port supported speeds and protocols.
1061  * Access: RO
1062  */
1063 MLXSW_ITEM32(reg, ptys, eth_proto_cap, 0x0C, 0, 32);
1064
1065 /* reg_ptys_eth_proto_admin
1066  * Speed and protocol to set port to.
1067  * Access: RW
1068  */
1069 MLXSW_ITEM32(reg, ptys, eth_proto_admin, 0x18, 0, 32);
1070
1071 /* reg_ptys_eth_proto_oper
1072  * The current speed and protocol configured for the port.
1073  * Access: RO
1074  */
1075 MLXSW_ITEM32(reg, ptys, eth_proto_oper, 0x24, 0, 32);
1076
1077 static inline void mlxsw_reg_ptys_pack(char *payload, u8 local_port,
1078                                        u32 proto_admin)
1079 {
1080         MLXSW_REG_ZERO(ptys, payload);
1081         mlxsw_reg_ptys_local_port_set(payload, local_port);
1082         mlxsw_reg_ptys_proto_mask_set(payload, MLXSW_REG_PTYS_PROTO_MASK_ETH);
1083         mlxsw_reg_ptys_eth_proto_admin_set(payload, proto_admin);
1084 }
1085
1086 static inline void mlxsw_reg_ptys_unpack(char *payload, u32 *p_eth_proto_cap,
1087                                          u32 *p_eth_proto_adm,
1088                                          u32 *p_eth_proto_oper)
1089 {
1090         if (p_eth_proto_cap)
1091                 *p_eth_proto_cap = mlxsw_reg_ptys_eth_proto_cap_get(payload);
1092         if (p_eth_proto_adm)
1093                 *p_eth_proto_adm = mlxsw_reg_ptys_eth_proto_admin_get(payload);
1094         if (p_eth_proto_oper)
1095                 *p_eth_proto_oper = mlxsw_reg_ptys_eth_proto_oper_get(payload);
1096 }
1097
1098 /* PPAD - Port Physical Address Register
1099  * -------------------------------------
1100  * The PPAD register configures the per port physical MAC address.
1101  */
1102 #define MLXSW_REG_PPAD_ID 0x5005
1103 #define MLXSW_REG_PPAD_LEN 0x10
1104
1105 static const struct mlxsw_reg_info mlxsw_reg_ppad = {
1106         .id = MLXSW_REG_PPAD_ID,
1107         .len = MLXSW_REG_PPAD_LEN,
1108 };
1109
1110 /* reg_ppad_single_base_mac
1111  * 0: base_mac, local port should be 0 and mac[7:0] is
1112  * reserved. HW will set incremental
1113  * 1: single_mac - mac of the local_port
1114  * Access: RW
1115  */
1116 MLXSW_ITEM32(reg, ppad, single_base_mac, 0x00, 28, 1);
1117
1118 /* reg_ppad_local_port
1119  * port number, if single_base_mac = 0 then local_port is reserved
1120  * Access: RW
1121  */
1122 MLXSW_ITEM32(reg, ppad, local_port, 0x00, 16, 8);
1123
1124 /* reg_ppad_mac
1125  * If single_base_mac = 0 - base MAC address, mac[7:0] is reserved.
1126  * If single_base_mac = 1 - the per port MAC address
1127  * Access: RW
1128  */
1129 MLXSW_ITEM_BUF(reg, ppad, mac, 0x02, 6);
1130
1131 static inline void mlxsw_reg_ppad_pack(char *payload, bool single_base_mac,
1132                                        u8 local_port)
1133 {
1134         MLXSW_REG_ZERO(ppad, payload);
1135         mlxsw_reg_ppad_single_base_mac_set(payload, !!single_base_mac);
1136         mlxsw_reg_ppad_local_port_set(payload, local_port);
1137 }
1138
1139 /* PAOS - Ports Administrative and Operational Status Register
1140  * -----------------------------------------------------------
1141  * Configures and retrieves per port administrative and operational status.
1142  */
1143 #define MLXSW_REG_PAOS_ID 0x5006
1144 #define MLXSW_REG_PAOS_LEN 0x10
1145
1146 static const struct mlxsw_reg_info mlxsw_reg_paos = {
1147         .id = MLXSW_REG_PAOS_ID,
1148         .len = MLXSW_REG_PAOS_LEN,
1149 };
1150
1151 /* reg_paos_swid
1152  * Switch partition ID with which to associate the port.
1153  * Note: while external ports uses unique local port numbers (and thus swid is
1154  * redundant), router ports use the same local port number where swid is the
1155  * only indication for the relevant port.
1156  * Access: Index
1157  */
1158 MLXSW_ITEM32(reg, paos, swid, 0x00, 24, 8);
1159
1160 /* reg_paos_local_port
1161  * Local port number.
1162  * Access: Index
1163  */
1164 MLXSW_ITEM32(reg, paos, local_port, 0x00, 16, 8);
1165
1166 /* reg_paos_admin_status
1167  * Port administrative state (the desired state of the port):
1168  * 1 - Up.
1169  * 2 - Down.
1170  * 3 - Up once. This means that in case of link failure, the port won't go
1171  *     into polling mode, but will wait to be re-enabled by software.
1172  * 4 - Disabled by system. Can only be set by hardware.
1173  * Access: RW
1174  */
1175 MLXSW_ITEM32(reg, paos, admin_status, 0x00, 8, 4);
1176
1177 /* reg_paos_oper_status
1178  * Port operational state (the current state):
1179  * 1 - Up.
1180  * 2 - Down.
1181  * 3 - Down by port failure. This means that the device will not let the
1182  *     port up again until explicitly specified by software.
1183  * Access: RO
1184  */
1185 MLXSW_ITEM32(reg, paos, oper_status, 0x00, 0, 4);
1186
1187 /* reg_paos_ase
1188  * Admin state update enabled.
1189  * Access: WO
1190  */
1191 MLXSW_ITEM32(reg, paos, ase, 0x04, 31, 1);
1192
1193 /* reg_paos_ee
1194  * Event update enable. If this bit is set, event generation will be
1195  * updated based on the e field.
1196  * Access: WO
1197  */
1198 MLXSW_ITEM32(reg, paos, ee, 0x04, 30, 1);
1199
1200 /* reg_paos_e
1201  * Event generation on operational state change:
1202  * 0 - Do not generate event.
1203  * 1 - Generate Event.
1204  * 2 - Generate Single Event.
1205  * Access: RW
1206  */
1207 MLXSW_ITEM32(reg, paos, e, 0x04, 0, 2);
1208
1209 static inline void mlxsw_reg_paos_pack(char *payload, u8 local_port,
1210                                        enum mlxsw_port_admin_status status)
1211 {
1212         MLXSW_REG_ZERO(paos, payload);
1213         mlxsw_reg_paos_swid_set(payload, 0);
1214         mlxsw_reg_paos_local_port_set(payload, local_port);
1215         mlxsw_reg_paos_admin_status_set(payload, status);
1216         mlxsw_reg_paos_oper_status_set(payload, 0);
1217         mlxsw_reg_paos_ase_set(payload, 1);
1218         mlxsw_reg_paos_ee_set(payload, 1);
1219         mlxsw_reg_paos_e_set(payload, 1);
1220 }
1221
1222 /* PPCNT - Ports Performance Counters Register
1223  * -------------------------------------------
1224  * The PPCNT register retrieves per port performance counters.
1225  */
1226 #define MLXSW_REG_PPCNT_ID 0x5008
1227 #define MLXSW_REG_PPCNT_LEN 0x100
1228
1229 static const struct mlxsw_reg_info mlxsw_reg_ppcnt = {
1230         .id = MLXSW_REG_PPCNT_ID,
1231         .len = MLXSW_REG_PPCNT_LEN,
1232 };
1233
1234 /* reg_ppcnt_swid
1235  * For HCA: must be always 0.
1236  * Switch partition ID to associate port with.
1237  * Switch partitions are numbered from 0 to 7 inclusively.
1238  * Switch partition 254 indicates stacking ports.
1239  * Switch partition 255 indicates all switch partitions.
1240  * Only valid on Set() operation with local_port=255.
1241  * Access: Index
1242  */
1243 MLXSW_ITEM32(reg, ppcnt, swid, 0x00, 24, 8);
1244
1245 /* reg_ppcnt_local_port
1246  * Local port number.
1247  * 255 indicates all ports on the device, and is only allowed
1248  * for Set() operation.
1249  * Access: Index
1250  */
1251 MLXSW_ITEM32(reg, ppcnt, local_port, 0x00, 16, 8);
1252
1253 /* reg_ppcnt_pnat
1254  * Port number access type:
1255  * 0 - Local port number
1256  * 1 - IB port number
1257  * Access: Index
1258  */
1259 MLXSW_ITEM32(reg, ppcnt, pnat, 0x00, 14, 2);
1260
1261 /* reg_ppcnt_grp
1262  * Performance counter group.
1263  * Group 63 indicates all groups. Only valid on Set() operation with
1264  * clr bit set.
1265  * 0x0: IEEE 802.3 Counters
1266  * 0x1: RFC 2863 Counters
1267  * 0x2: RFC 2819 Counters
1268  * 0x3: RFC 3635 Counters
1269  * 0x5: Ethernet Extended Counters
1270  * 0x8: Link Level Retransmission Counters
1271  * 0x10: Per Priority Counters
1272  * 0x11: Per Traffic Class Counters
1273  * 0x12: Physical Layer Counters
1274  * Access: Index
1275  */
1276 MLXSW_ITEM32(reg, ppcnt, grp, 0x00, 0, 6);
1277
1278 /* reg_ppcnt_clr
1279  * Clear counters. Setting the clr bit will reset the counter value
1280  * for all counters in the counter group. This bit can be set
1281  * for both Set() and Get() operation.
1282  * Access: OP
1283  */
1284 MLXSW_ITEM32(reg, ppcnt, clr, 0x04, 31, 1);
1285
1286 /* reg_ppcnt_prio_tc
1287  * Priority for counter set that support per priority, valid values: 0-7.
1288  * Traffic class for counter set that support per traffic class,
1289  * valid values: 0- cap_max_tclass-1 .
1290  * For HCA: cap_max_tclass is always 8.
1291  * Otherwise must be 0.
1292  * Access: Index
1293  */
1294 MLXSW_ITEM32(reg, ppcnt, prio_tc, 0x04, 0, 5);
1295
1296 /* reg_ppcnt_a_frames_transmitted_ok
1297  * Access: RO
1298  */
1299 MLXSW_ITEM64(reg, ppcnt, a_frames_transmitted_ok,
1300              0x08 + 0x00, 0, 64);
1301
1302 /* reg_ppcnt_a_frames_received_ok
1303  * Access: RO
1304  */
1305 MLXSW_ITEM64(reg, ppcnt, a_frames_received_ok,
1306              0x08 + 0x08, 0, 64);
1307
1308 /* reg_ppcnt_a_frame_check_sequence_errors
1309  * Access: RO
1310  */
1311 MLXSW_ITEM64(reg, ppcnt, a_frame_check_sequence_errors,
1312              0x08 + 0x10, 0, 64);
1313
1314 /* reg_ppcnt_a_alignment_errors
1315  * Access: RO
1316  */
1317 MLXSW_ITEM64(reg, ppcnt, a_alignment_errors,
1318              0x08 + 0x18, 0, 64);
1319
1320 /* reg_ppcnt_a_octets_transmitted_ok
1321  * Access: RO
1322  */
1323 MLXSW_ITEM64(reg, ppcnt, a_octets_transmitted_ok,
1324              0x08 + 0x20, 0, 64);
1325
1326 /* reg_ppcnt_a_octets_received_ok
1327  * Access: RO
1328  */
1329 MLXSW_ITEM64(reg, ppcnt, a_octets_received_ok,
1330              0x08 + 0x28, 0, 64);
1331
1332 /* reg_ppcnt_a_multicast_frames_xmitted_ok
1333  * Access: RO
1334  */
1335 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_xmitted_ok,
1336              0x08 + 0x30, 0, 64);
1337
1338 /* reg_ppcnt_a_broadcast_frames_xmitted_ok
1339  * Access: RO
1340  */
1341 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_xmitted_ok,
1342              0x08 + 0x38, 0, 64);
1343
1344 /* reg_ppcnt_a_multicast_frames_received_ok
1345  * Access: RO
1346  */
1347 MLXSW_ITEM64(reg, ppcnt, a_multicast_frames_received_ok,
1348              0x08 + 0x40, 0, 64);
1349
1350 /* reg_ppcnt_a_broadcast_frames_received_ok
1351  * Access: RO
1352  */
1353 MLXSW_ITEM64(reg, ppcnt, a_broadcast_frames_received_ok,
1354              0x08 + 0x48, 0, 64);
1355
1356 /* reg_ppcnt_a_in_range_length_errors
1357  * Access: RO
1358  */
1359 MLXSW_ITEM64(reg, ppcnt, a_in_range_length_errors,
1360              0x08 + 0x50, 0, 64);
1361
1362 /* reg_ppcnt_a_out_of_range_length_field
1363  * Access: RO
1364  */
1365 MLXSW_ITEM64(reg, ppcnt, a_out_of_range_length_field,
1366              0x08 + 0x58, 0, 64);
1367
1368 /* reg_ppcnt_a_frame_too_long_errors
1369  * Access: RO
1370  */
1371 MLXSW_ITEM64(reg, ppcnt, a_frame_too_long_errors,
1372              0x08 + 0x60, 0, 64);
1373
1374 /* reg_ppcnt_a_symbol_error_during_carrier
1375  * Access: RO
1376  */
1377 MLXSW_ITEM64(reg, ppcnt, a_symbol_error_during_carrier,
1378              0x08 + 0x68, 0, 64);
1379
1380 /* reg_ppcnt_a_mac_control_frames_transmitted
1381  * Access: RO
1382  */
1383 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_transmitted,
1384              0x08 + 0x70, 0, 64);
1385
1386 /* reg_ppcnt_a_mac_control_frames_received
1387  * Access: RO
1388  */
1389 MLXSW_ITEM64(reg, ppcnt, a_mac_control_frames_received,
1390              0x08 + 0x78, 0, 64);
1391
1392 /* reg_ppcnt_a_unsupported_opcodes_received
1393  * Access: RO
1394  */
1395 MLXSW_ITEM64(reg, ppcnt, a_unsupported_opcodes_received,
1396              0x08 + 0x80, 0, 64);
1397
1398 /* reg_ppcnt_a_pause_mac_ctrl_frames_received
1399  * Access: RO
1400  */
1401 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_received,
1402              0x08 + 0x88, 0, 64);
1403
1404 /* reg_ppcnt_a_pause_mac_ctrl_frames_transmitted
1405  * Access: RO
1406  */
1407 MLXSW_ITEM64(reg, ppcnt, a_pause_mac_ctrl_frames_transmitted,
1408              0x08 + 0x90, 0, 64);
1409
1410 static inline void mlxsw_reg_ppcnt_pack(char *payload, u8 local_port)
1411 {
1412         MLXSW_REG_ZERO(ppcnt, payload);
1413         mlxsw_reg_ppcnt_swid_set(payload, 0);
1414         mlxsw_reg_ppcnt_local_port_set(payload, local_port);
1415         mlxsw_reg_ppcnt_pnat_set(payload, 0);
1416         mlxsw_reg_ppcnt_grp_set(payload, 0);
1417         mlxsw_reg_ppcnt_clr_set(payload, 0);
1418         mlxsw_reg_ppcnt_prio_tc_set(payload, 0);
1419 }
1420
1421 /* PBMC - Port Buffer Management Control Register
1422  * ----------------------------------------------
1423  * The PBMC register configures and retrieves the port packet buffer
1424  * allocation for different Prios, and the Pause threshold management.
1425  */
1426 #define MLXSW_REG_PBMC_ID 0x500C
1427 #define MLXSW_REG_PBMC_LEN 0x68
1428
1429 static const struct mlxsw_reg_info mlxsw_reg_pbmc = {
1430         .id = MLXSW_REG_PBMC_ID,
1431         .len = MLXSW_REG_PBMC_LEN,
1432 };
1433
1434 /* reg_pbmc_local_port
1435  * Local port number.
1436  * Access: Index
1437  */
1438 MLXSW_ITEM32(reg, pbmc, local_port, 0x00, 16, 8);
1439
1440 /* reg_pbmc_xoff_timer_value
1441  * When device generates a pause frame, it uses this value as the pause
1442  * timer (time for the peer port to pause in quota-512 bit time).
1443  * Access: RW
1444  */
1445 MLXSW_ITEM32(reg, pbmc, xoff_timer_value, 0x04, 16, 16);
1446
1447 /* reg_pbmc_xoff_refresh
1448  * The time before a new pause frame should be sent to refresh the pause RW
1449  * state. Using the same units as xoff_timer_value above (in quota-512 bit
1450  * time).
1451  * Access: RW
1452  */
1453 MLXSW_ITEM32(reg, pbmc, xoff_refresh, 0x04, 0, 16);
1454
1455 /* reg_pbmc_buf_lossy
1456  * The field indicates if the buffer is lossy.
1457  * 0 - Lossless
1458  * 1 - Lossy
1459  * Access: RW
1460  */
1461 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_lossy, 0x0C, 25, 1, 0x08, 0x00, false);
1462
1463 /* reg_pbmc_buf_epsb
1464  * Eligible for Port Shared buffer.
1465  * If epsb is set, packets assigned to buffer are allowed to insert the port
1466  * shared buffer.
1467  * When buf_lossy is MLXSW_REG_PBMC_LOSSY_LOSSY this field is reserved.
1468  * Access: RW
1469  */
1470 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_epsb, 0x0C, 24, 1, 0x08, 0x00, false);
1471
1472 /* reg_pbmc_buf_size
1473  * The part of the packet buffer array is allocated for the specific buffer.
1474  * Units are represented in cells.
1475  * Access: RW
1476  */
1477 MLXSW_ITEM32_INDEXED(reg, pbmc, buf_size, 0x0C, 0, 16, 0x08, 0x00, false);
1478
1479 static inline void mlxsw_reg_pbmc_pack(char *payload, u8 local_port,
1480                                        u16 xoff_timer_value, u16 xoff_refresh)
1481 {
1482         MLXSW_REG_ZERO(pbmc, payload);
1483         mlxsw_reg_pbmc_local_port_set(payload, local_port);
1484         mlxsw_reg_pbmc_xoff_timer_value_set(payload, xoff_timer_value);
1485         mlxsw_reg_pbmc_xoff_refresh_set(payload, xoff_refresh);
1486 }
1487
1488 static inline void mlxsw_reg_pbmc_lossy_buffer_pack(char *payload,
1489                                                     int buf_index,
1490                                                     u16 size)
1491 {
1492         mlxsw_reg_pbmc_buf_lossy_set(payload, buf_index, 1);
1493         mlxsw_reg_pbmc_buf_epsb_set(payload, buf_index, 0);
1494         mlxsw_reg_pbmc_buf_size_set(payload, buf_index, size);
1495 }
1496
1497 /* PSPA - Port Switch Partition Allocation
1498  * ---------------------------------------
1499  * Controls the association of a port with a switch partition and enables
1500  * configuring ports as stacking ports.
1501  */
1502 #define MLXSW_REG_PSPA_ID 0x500D
1503 #define MLXSW_REG_PSPA_LEN 0x8
1504
1505 static const struct mlxsw_reg_info mlxsw_reg_pspa = {
1506         .id = MLXSW_REG_PSPA_ID,
1507         .len = MLXSW_REG_PSPA_LEN,
1508 };
1509
1510 /* reg_pspa_swid
1511  * Switch partition ID.
1512  * Access: RW
1513  */
1514 MLXSW_ITEM32(reg, pspa, swid, 0x00, 24, 8);
1515
1516 /* reg_pspa_local_port
1517  * Local port number.
1518  * Access: Index
1519  */
1520 MLXSW_ITEM32(reg, pspa, local_port, 0x00, 16, 8);
1521
1522 /* reg_pspa_sub_port
1523  * Virtual port within the local port. Set to 0 when virtual ports are
1524  * disabled on the local port.
1525  * Access: Index
1526  */
1527 MLXSW_ITEM32(reg, pspa, sub_port, 0x00, 8, 8);
1528
1529 static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
1530 {
1531         MLXSW_REG_ZERO(pspa, payload);
1532         mlxsw_reg_pspa_swid_set(payload, swid);
1533         mlxsw_reg_pspa_local_port_set(payload, local_port);
1534         mlxsw_reg_pspa_sub_port_set(payload, 0);
1535 }
1536
1537 /* HTGT - Host Trap Group Table
1538  * ----------------------------
1539  * Configures the properties for forwarding to CPU.
1540  */
1541 #define MLXSW_REG_HTGT_ID 0x7002
1542 #define MLXSW_REG_HTGT_LEN 0x100
1543
1544 static const struct mlxsw_reg_info mlxsw_reg_htgt = {
1545         .id = MLXSW_REG_HTGT_ID,
1546         .len = MLXSW_REG_HTGT_LEN,
1547 };
1548
1549 /* reg_htgt_swid
1550  * Switch partition ID.
1551  * Access: Index
1552  */
1553 MLXSW_ITEM32(reg, htgt, swid, 0x00, 24, 8);
1554
1555 #define MLXSW_REG_HTGT_PATH_TYPE_LOCAL 0x0      /* For locally attached CPU */
1556
1557 /* reg_htgt_type
1558  * CPU path type.
1559  * Access: RW
1560  */
1561 MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
1562
1563 enum mlxsw_reg_htgt_trap_group {
1564         MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
1565         MLXSW_REG_HTGT_TRAP_GROUP_RX,
1566         MLXSW_REG_HTGT_TRAP_GROUP_CTRL,
1567 };
1568
1569 /* reg_htgt_trap_group
1570  * Trap group number. User defined number specifying which trap groups
1571  * should be forwarded to the CPU. The mapping between trap IDs and trap
1572  * groups is configured using HPKT register.
1573  * Access: Index
1574  */
1575 MLXSW_ITEM32(reg, htgt, trap_group, 0x00, 0, 8);
1576
1577 enum {
1578         MLXSW_REG_HTGT_POLICER_DISABLE,
1579         MLXSW_REG_HTGT_POLICER_ENABLE,
1580 };
1581
1582 /* reg_htgt_pide
1583  * Enable policer ID specified using 'pid' field.
1584  * Access: RW
1585  */
1586 MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
1587
1588 /* reg_htgt_pid
1589  * Policer ID for the trap group.
1590  * Access: RW
1591  */
1592 MLXSW_ITEM32(reg, htgt, pid, 0x04, 0, 8);
1593
1594 #define MLXSW_REG_HTGT_TRAP_TO_CPU 0x0
1595
1596 /* reg_htgt_mirror_action
1597  * Mirror action to use.
1598  * 0 - Trap to CPU.
1599  * 1 - Trap to CPU and mirror to a mirroring agent.
1600  * 2 - Mirror to a mirroring agent and do not trap to CPU.
1601  * Access: RW
1602  *
1603  * Note: Mirroring to a mirroring agent is only supported in Spectrum.
1604  */
1605 MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
1606
1607 /* reg_htgt_mirroring_agent
1608  * Mirroring agent.
1609  * Access: RW
1610  */
1611 MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
1612
1613 /* reg_htgt_priority
1614  * Trap group priority.
1615  * In case a packet matches multiple classification rules, the packet will
1616  * only be trapped once, based on the trap ID associated with the group (via
1617  * register HPKT) with the highest priority.
1618  * Supported values are 0-7, with 7 represnting the highest priority.
1619  * Access: RW
1620  *
1621  * Note: In SwitchX-2 this field is ignored and the priority value is replaced
1622  * by the 'trap_group' field.
1623  */
1624 MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
1625
1626 /* reg_htgt_local_path_cpu_tclass
1627  * CPU ingress traffic class for the trap group.
1628  * Access: RW
1629  */
1630 MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
1631
1632 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD      0x15
1633 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX        0x14
1634 #define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL      0x13
1635
1636 /* reg_htgt_local_path_rdq
1637  * Receive descriptor queue (RDQ) to use for the trap group.
1638  * Access: RW
1639  */
1640 MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
1641
1642 static inline void mlxsw_reg_htgt_pack(char *payload,
1643                                        enum mlxsw_reg_htgt_trap_group group)
1644 {
1645         u8 swid, rdq;
1646
1647         MLXSW_REG_ZERO(htgt, payload);
1648         switch (group) {
1649         case MLXSW_REG_HTGT_TRAP_GROUP_EMAD:
1650                 swid = MLXSW_PORT_SWID_ALL_SWIDS;
1651                 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD;
1652                 break;
1653         case MLXSW_REG_HTGT_TRAP_GROUP_RX:
1654                 swid = 0;
1655                 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX;
1656                 break;
1657         case MLXSW_REG_HTGT_TRAP_GROUP_CTRL:
1658                 swid = 0;
1659                 rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL;
1660                 break;
1661         }
1662         mlxsw_reg_htgt_swid_set(payload, swid);
1663         mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
1664         mlxsw_reg_htgt_trap_group_set(payload, group);
1665         mlxsw_reg_htgt_pide_set(payload, MLXSW_REG_HTGT_POLICER_DISABLE);
1666         mlxsw_reg_htgt_pid_set(payload, 0);
1667         mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
1668         mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
1669         mlxsw_reg_htgt_priority_set(payload, 0);
1670         mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, 7);
1671         mlxsw_reg_htgt_local_path_rdq_set(payload, rdq);
1672 }
1673
1674 /* HPKT - Host Packet Trap
1675  * -----------------------
1676  * Configures trap IDs inside trap groups.
1677  */
1678 #define MLXSW_REG_HPKT_ID 0x7003
1679 #define MLXSW_REG_HPKT_LEN 0x10
1680
1681 static const struct mlxsw_reg_info mlxsw_reg_hpkt = {
1682         .id = MLXSW_REG_HPKT_ID,
1683         .len = MLXSW_REG_HPKT_LEN,
1684 };
1685
1686 enum {
1687         MLXSW_REG_HPKT_ACK_NOT_REQUIRED,
1688         MLXSW_REG_HPKT_ACK_REQUIRED,
1689 };
1690
1691 /* reg_hpkt_ack
1692  * Require acknowledgements from the host for events.
1693  * If set, then the device will wait for the event it sent to be acknowledged
1694  * by the host. This option is only relevant for event trap IDs.
1695  * Access: RW
1696  *
1697  * Note: Currently not supported by firmware.
1698  */
1699 MLXSW_ITEM32(reg, hpkt, ack, 0x00, 24, 1);
1700
1701 enum mlxsw_reg_hpkt_action {
1702         MLXSW_REG_HPKT_ACTION_FORWARD,
1703         MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
1704         MLXSW_REG_HPKT_ACTION_MIRROR_TO_CPU,
1705         MLXSW_REG_HPKT_ACTION_DISCARD,
1706         MLXSW_REG_HPKT_ACTION_SOFT_DISCARD,
1707         MLXSW_REG_HPKT_ACTION_TRAP_AND_SOFT_DISCARD,
1708 };
1709
1710 /* reg_hpkt_action
1711  * Action to perform on packet when trapped.
1712  * 0 - No action. Forward to CPU based on switching rules.
1713  * 1 - Trap to CPU (CPU receives sole copy).
1714  * 2 - Mirror to CPU (CPU receives a replica of the packet).
1715  * 3 - Discard.
1716  * 4 - Soft discard (allow other traps to act on the packet).
1717  * 5 - Trap and soft discard (allow other traps to overwrite this trap).
1718  * Access: RW
1719  *
1720  * Note: Must be set to 0 (forward) for event trap IDs, as they are already
1721  * addressed to the CPU.
1722  */
1723 MLXSW_ITEM32(reg, hpkt, action, 0x00, 20, 3);
1724
1725 /* reg_hpkt_trap_group
1726  * Trap group to associate the trap with.
1727  * Access: RW
1728  */
1729 MLXSW_ITEM32(reg, hpkt, trap_group, 0x00, 12, 6);
1730
1731 /* reg_hpkt_trap_id
1732  * Trap ID.
1733  * Access: Index
1734  *
1735  * Note: A trap ID can only be associated with a single trap group. The device
1736  * will associate the trap ID with the last trap group configured.
1737  */
1738 MLXSW_ITEM32(reg, hpkt, trap_id, 0x00, 0, 9);
1739
1740 enum {
1741         MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT,
1742         MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER,
1743         MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER,
1744 };
1745
1746 /* reg_hpkt_ctrl
1747  * Configure dedicated buffer resources for control packets.
1748  * 0 - Keep factory defaults.
1749  * 1 - Do not use control buffer for this trap ID.
1750  * 2 - Use control buffer for this trap ID.
1751  * Access: RW
1752  */
1753 MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
1754
1755 static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id)
1756 {
1757         enum mlxsw_reg_htgt_trap_group trap_group;
1758
1759         MLXSW_REG_ZERO(hpkt, payload);
1760         mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
1761         mlxsw_reg_hpkt_action_set(payload, action);
1762         switch (trap_id) {
1763         case MLXSW_TRAP_ID_ETHEMAD:
1764         case MLXSW_TRAP_ID_PUDE:
1765                 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_EMAD;
1766                 break;
1767         default:
1768                 trap_group = MLXSW_REG_HTGT_TRAP_GROUP_RX;
1769                 break;
1770         }
1771         mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
1772         mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
1773         mlxsw_reg_hpkt_ctrl_set(payload, MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT);
1774 }
1775
1776 /* SBPR - Shared Buffer Pools Register
1777  * -----------------------------------
1778  * The SBPR configures and retrieves the shared buffer pools and configuration.
1779  */
1780 #define MLXSW_REG_SBPR_ID 0xB001
1781 #define MLXSW_REG_SBPR_LEN 0x14
1782
1783 static const struct mlxsw_reg_info mlxsw_reg_sbpr = {
1784         .id = MLXSW_REG_SBPR_ID,
1785         .len = MLXSW_REG_SBPR_LEN,
1786 };
1787
1788 enum mlxsw_reg_sbpr_dir {
1789         MLXSW_REG_SBPR_DIR_INGRESS,
1790         MLXSW_REG_SBPR_DIR_EGRESS,
1791 };
1792
1793 /* reg_sbpr_dir
1794  * Direction.
1795  * Access: Index
1796  */
1797 MLXSW_ITEM32(reg, sbpr, dir, 0x00, 24, 2);
1798
1799 /* reg_sbpr_pool
1800  * Pool index.
1801  * Access: Index
1802  */
1803 MLXSW_ITEM32(reg, sbpr, pool, 0x00, 0, 4);
1804
1805 /* reg_sbpr_size
1806  * Pool size in buffer cells.
1807  * Access: RW
1808  */
1809 MLXSW_ITEM32(reg, sbpr, size, 0x04, 0, 24);
1810
1811 enum mlxsw_reg_sbpr_mode {
1812         MLXSW_REG_SBPR_MODE_STATIC,
1813         MLXSW_REG_SBPR_MODE_DYNAMIC,
1814 };
1815
1816 /* reg_sbpr_mode
1817  * Pool quota calculation mode.
1818  * Access: RW
1819  */
1820 MLXSW_ITEM32(reg, sbpr, mode, 0x08, 0, 4);
1821
1822 static inline void mlxsw_reg_sbpr_pack(char *payload, u8 pool,
1823                                        enum mlxsw_reg_sbpr_dir dir,
1824                                        enum mlxsw_reg_sbpr_mode mode, u32 size)
1825 {
1826         MLXSW_REG_ZERO(sbpr, payload);
1827         mlxsw_reg_sbpr_pool_set(payload, pool);
1828         mlxsw_reg_sbpr_dir_set(payload, dir);
1829         mlxsw_reg_sbpr_mode_set(payload, mode);
1830         mlxsw_reg_sbpr_size_set(payload, size);
1831 }
1832
1833 /* SBCM - Shared Buffer Class Management Register
1834  * ----------------------------------------------
1835  * The SBCM register configures and retrieves the shared buffer allocation
1836  * and configuration according to Port-PG, including the binding to pool
1837  * and definition of the associated quota.
1838  */
1839 #define MLXSW_REG_SBCM_ID 0xB002
1840 #define MLXSW_REG_SBCM_LEN 0x28
1841
1842 static const struct mlxsw_reg_info mlxsw_reg_sbcm = {
1843         .id = MLXSW_REG_SBCM_ID,
1844         .len = MLXSW_REG_SBCM_LEN,
1845 };
1846
1847 /* reg_sbcm_local_port
1848  * Local port number.
1849  * For Ingress: excludes CPU port and Router port
1850  * For Egress: excludes IP Router
1851  * Access: Index
1852  */
1853 MLXSW_ITEM32(reg, sbcm, local_port, 0x00, 16, 8);
1854
1855 /* reg_sbcm_pg_buff
1856  * PG buffer - Port PG (dir=ingress) / traffic class (dir=egress)
1857  * For PG buffer: range is 0..cap_max_pg_buffers - 1
1858  * For traffic class: range is 0..cap_max_tclass - 1
1859  * Note that when traffic class is in MC aware mode then the traffic
1860  * classes which are MC aware cannot be configured.
1861  * Access: Index
1862  */
1863 MLXSW_ITEM32(reg, sbcm, pg_buff, 0x00, 8, 6);
1864
1865 enum mlxsw_reg_sbcm_dir {
1866         MLXSW_REG_SBCM_DIR_INGRESS,
1867         MLXSW_REG_SBCM_DIR_EGRESS,
1868 };
1869
1870 /* reg_sbcm_dir
1871  * Direction.
1872  * Access: Index
1873  */
1874 MLXSW_ITEM32(reg, sbcm, dir, 0x00, 0, 2);
1875
1876 /* reg_sbcm_min_buff
1877  * Minimum buffer size for the limiter, in cells.
1878  * Access: RW
1879  */
1880 MLXSW_ITEM32(reg, sbcm, min_buff, 0x18, 0, 24);
1881
1882 /* reg_sbcm_max_buff
1883  * When the pool associated to the port-pg/tclass is configured to
1884  * static, Maximum buffer size for the limiter configured in cells.
1885  * When the pool associated to the port-pg/tclass is configured to
1886  * dynamic, the max_buff holds the "alpha" parameter, supporting
1887  * the following values:
1888  * 0: 0
1889  * i: (1/128)*2^(i-1), for i=1..14
1890  * 0xFF: Infinity
1891  * Access: RW
1892  */
1893 MLXSW_ITEM32(reg, sbcm, max_buff, 0x1C, 0, 24);
1894
1895 /* reg_sbcm_pool
1896  * Association of the port-priority to a pool.
1897  * Access: RW
1898  */
1899 MLXSW_ITEM32(reg, sbcm, pool, 0x24, 0, 4);
1900
1901 static inline void mlxsw_reg_sbcm_pack(char *payload, u8 local_port, u8 pg_buff,
1902                                        enum mlxsw_reg_sbcm_dir dir,
1903                                        u32 min_buff, u32 max_buff, u8 pool)
1904 {
1905         MLXSW_REG_ZERO(sbcm, payload);
1906         mlxsw_reg_sbcm_local_port_set(payload, local_port);
1907         mlxsw_reg_sbcm_pg_buff_set(payload, pg_buff);
1908         mlxsw_reg_sbcm_dir_set(payload, dir);
1909         mlxsw_reg_sbcm_min_buff_set(payload, min_buff);
1910         mlxsw_reg_sbcm_max_buff_set(payload, max_buff);
1911         mlxsw_reg_sbcm_pool_set(payload, pool);
1912 }
1913
1914 /* SBPM - Shared Buffer Class Management Register
1915  * ----------------------------------------------
1916  * The SBPM register configures and retrieves the shared buffer allocation
1917  * and configuration according to Port-Pool, including the definition
1918  * of the associated quota.
1919  */
1920 #define MLXSW_REG_SBPM_ID 0xB003
1921 #define MLXSW_REG_SBPM_LEN 0x28
1922
1923 static const struct mlxsw_reg_info mlxsw_reg_sbpm = {
1924         .id = MLXSW_REG_SBPM_ID,
1925         .len = MLXSW_REG_SBPM_LEN,
1926 };
1927
1928 /* reg_sbpm_local_port
1929  * Local port number.
1930  * For Ingress: excludes CPU port and Router port
1931  * For Egress: excludes IP Router
1932  * Access: Index
1933  */
1934 MLXSW_ITEM32(reg, sbpm, local_port, 0x00, 16, 8);
1935
1936 /* reg_sbpm_pool
1937  * The pool associated to quota counting on the local_port.
1938  * Access: Index
1939  */
1940 MLXSW_ITEM32(reg, sbpm, pool, 0x00, 8, 4);
1941
1942 enum mlxsw_reg_sbpm_dir {
1943         MLXSW_REG_SBPM_DIR_INGRESS,
1944         MLXSW_REG_SBPM_DIR_EGRESS,
1945 };
1946
1947 /* reg_sbpm_dir
1948  * Direction.
1949  * Access: Index
1950  */
1951 MLXSW_ITEM32(reg, sbpm, dir, 0x00, 0, 2);
1952
1953 /* reg_sbpm_min_buff
1954  * Minimum buffer size for the limiter, in cells.
1955  * Access: RW
1956  */
1957 MLXSW_ITEM32(reg, sbpm, min_buff, 0x18, 0, 24);
1958
1959 /* reg_sbpm_max_buff
1960  * When the pool associated to the port-pg/tclass is configured to
1961  * static, Maximum buffer size for the limiter configured in cells.
1962  * When the pool associated to the port-pg/tclass is configured to
1963  * dynamic, the max_buff holds the "alpha" parameter, supporting
1964  * the following values:
1965  * 0: 0
1966  * i: (1/128)*2^(i-1), for i=1..14
1967  * 0xFF: Infinity
1968  * Access: RW
1969  */
1970 MLXSW_ITEM32(reg, sbpm, max_buff, 0x1C, 0, 24);
1971
1972 static inline void mlxsw_reg_sbpm_pack(char *payload, u8 local_port, u8 pool,
1973                                        enum mlxsw_reg_sbpm_dir dir,
1974                                        u32 min_buff, u32 max_buff)
1975 {
1976         MLXSW_REG_ZERO(sbpm, payload);
1977         mlxsw_reg_sbpm_local_port_set(payload, local_port);
1978         mlxsw_reg_sbpm_pool_set(payload, pool);
1979         mlxsw_reg_sbpm_dir_set(payload, dir);
1980         mlxsw_reg_sbpm_min_buff_set(payload, min_buff);
1981         mlxsw_reg_sbpm_max_buff_set(payload, max_buff);
1982 }
1983
1984 /* SBMM - Shared Buffer Multicast Management Register
1985  * --------------------------------------------------
1986  * The SBMM register configures and retrieves the shared buffer allocation
1987  * and configuration for MC packets according to Switch-Priority, including
1988  * the binding to pool and definition of the associated quota.
1989  */
1990 #define MLXSW_REG_SBMM_ID 0xB004
1991 #define MLXSW_REG_SBMM_LEN 0x28
1992
1993 static const struct mlxsw_reg_info mlxsw_reg_sbmm = {
1994         .id = MLXSW_REG_SBMM_ID,
1995         .len = MLXSW_REG_SBMM_LEN,
1996 };
1997
1998 /* reg_sbmm_prio
1999  * Switch Priority.
2000  * Access: Index
2001  */
2002 MLXSW_ITEM32(reg, sbmm, prio, 0x00, 8, 4);
2003
2004 /* reg_sbmm_min_buff
2005  * Minimum buffer size for the limiter, in cells.
2006  * Access: RW
2007  */
2008 MLXSW_ITEM32(reg, sbmm, min_buff, 0x18, 0, 24);
2009
2010 /* reg_sbmm_max_buff
2011  * When the pool associated to the port-pg/tclass is configured to
2012  * static, Maximum buffer size for the limiter configured in cells.
2013  * When the pool associated to the port-pg/tclass is configured to
2014  * dynamic, the max_buff holds the "alpha" parameter, supporting
2015  * the following values:
2016  * 0: 0
2017  * i: (1/128)*2^(i-1), for i=1..14
2018  * 0xFF: Infinity
2019  * Access: RW
2020  */
2021 MLXSW_ITEM32(reg, sbmm, max_buff, 0x1C, 0, 24);
2022
2023 /* reg_sbmm_pool
2024  * Association of the port-priority to a pool.
2025  * Access: RW
2026  */
2027 MLXSW_ITEM32(reg, sbmm, pool, 0x24, 0, 4);
2028
2029 static inline void mlxsw_reg_sbmm_pack(char *payload, u8 prio, u32 min_buff,
2030                                        u32 max_buff, u8 pool)
2031 {
2032         MLXSW_REG_ZERO(sbmm, payload);
2033         mlxsw_reg_sbmm_prio_set(payload, prio);
2034         mlxsw_reg_sbmm_min_buff_set(payload, min_buff);
2035         mlxsw_reg_sbmm_max_buff_set(payload, max_buff);
2036         mlxsw_reg_sbmm_pool_set(payload, pool);
2037 }
2038
2039 static inline const char *mlxsw_reg_id_str(u16 reg_id)
2040 {
2041         switch (reg_id) {
2042         case MLXSW_REG_SGCR_ID:
2043                 return "SGCR";
2044         case MLXSW_REG_SPAD_ID:
2045                 return "SPAD";
2046         case MLXSW_REG_SSPR_ID:
2047                 return "SSPR";
2048         case MLXSW_REG_SFD_ID:
2049                 return "SFD";
2050         case MLXSW_REG_SFN_ID:
2051                 return "SFN";
2052         case MLXSW_REG_SPMS_ID:
2053                 return "SPMS";
2054         case MLXSW_REG_SPVID_ID:
2055                 return "SPVID";
2056         case MLXSW_REG_SPVM_ID:
2057                 return "SPVM";
2058         case MLXSW_REG_SFGC_ID:
2059                 return "SFGC";
2060         case MLXSW_REG_SFTR_ID:
2061                 return "SFTR";
2062         case MLXSW_REG_SPMLR_ID:
2063                 return "SPMLR";
2064         case MLXSW_REG_PMLP_ID:
2065                 return "PMLP";
2066         case MLXSW_REG_PMTU_ID:
2067                 return "PMTU";
2068         case MLXSW_REG_PTYS_ID:
2069                 return "PTYS";
2070         case MLXSW_REG_PPAD_ID:
2071                 return "PPAD";
2072         case MLXSW_REG_PAOS_ID:
2073                 return "PAOS";
2074         case MLXSW_REG_PPCNT_ID:
2075                 return "PPCNT";
2076         case MLXSW_REG_PBMC_ID:
2077                 return "PBMC";
2078         case MLXSW_REG_PSPA_ID:
2079                 return "PSPA";
2080         case MLXSW_REG_HTGT_ID:
2081                 return "HTGT";
2082         case MLXSW_REG_HPKT_ID:
2083                 return "HPKT";
2084         case MLXSW_REG_SBPR_ID:
2085                 return "SBPR";
2086         case MLXSW_REG_SBCM_ID:
2087                 return "SBCM";
2088         case MLXSW_REG_SBPM_ID:
2089                 return "SBPM";
2090         case MLXSW_REG_SBMM_ID:
2091                 return "SBMM";
2092         default:
2093                 return "*UNKNOWN*";
2094         }
2095 }
2096
2097 /* PUDE - Port Up / Down Event
2098  * ---------------------------
2099  * Reports the operational state change of a port.
2100  */
2101 #define MLXSW_REG_PUDE_LEN 0x10
2102
2103 /* reg_pude_swid
2104  * Switch partition ID with which to associate the port.
2105  * Access: Index
2106  */
2107 MLXSW_ITEM32(reg, pude, swid, 0x00, 24, 8);
2108
2109 /* reg_pude_local_port
2110  * Local port number.
2111  * Access: Index
2112  */
2113 MLXSW_ITEM32(reg, pude, local_port, 0x00, 16, 8);
2114
2115 /* reg_pude_admin_status
2116  * Port administrative state (the desired state).
2117  * 1 - Up.
2118  * 2 - Down.
2119  * 3 - Up once. This means that in case of link failure, the port won't go
2120  *     into polling mode, but will wait to be re-enabled by software.
2121  * 4 - Disabled by system. Can only be set by hardware.
2122  * Access: RO
2123  */
2124 MLXSW_ITEM32(reg, pude, admin_status, 0x00, 8, 4);
2125
2126 /* reg_pude_oper_status
2127  * Port operatioanl state.
2128  * 1 - Up.
2129  * 2 - Down.
2130  * 3 - Down by port failure. This means that the device will not let the
2131  *     port up again until explicitly specified by software.
2132  * Access: RO
2133  */
2134 MLXSW_ITEM32(reg, pude, oper_status, 0x00, 0, 4);
2135
2136 #endif