1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2015-2018 Mellanox Technologies. All rights reserved */
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/types.h>
8 #include <linux/netdevice.h>
9 #include <linux/etherdevice.h>
10 #include <linux/ethtool.h>
11 #include <linux/slab.h>
12 #include <linux/device.h>
13 #include <linux/skbuff.h>
14 #include <linux/if_vlan.h>
15 #include <linux/if_bridge.h>
16 #include <linux/workqueue.h>
17 #include <linux/jiffies.h>
18 #include <linux/bitops.h>
19 #include <linux/list.h>
20 #include <linux/notifier.h>
21 #include <linux/dcbnl.h>
22 #include <linux/inetdevice.h>
23 #include <linux/netlink.h>
24 #include <linux/jhash.h>
25 #include <net/switchdev.h>
26 #include <net/pkt_cls.h>
27 #include <net/tc_act/tc_mirred.h>
28 #include <net/netevent.h>
29 #include <net/tc_act/tc_sample.h>
30 #include <net/addrconf.h>
40 #include "spectrum_cnt.h"
41 #include "spectrum_dpipe.h"
42 #include "spectrum_acl_flex_actions.h"
43 #include "spectrum_span.h"
44 #include "spectrum_ptp.h"
45 #include "../mlxfw/mlxfw.h"
47 #define MLXSW_SP_FWREV_MINOR_TO_BRANCH(minor) ((minor) / 100)
49 #define MLXSW_SP1_FWREV_MAJOR 13
50 #define MLXSW_SP1_FWREV_MINOR 2000
51 #define MLXSW_SP1_FWREV_SUBMINOR 1886
52 #define MLXSW_SP1_FWREV_CAN_RESET_MINOR 1702
54 static const struct mlxsw_fw_rev mlxsw_sp1_fw_rev = {
55 .major = MLXSW_SP1_FWREV_MAJOR,
56 .minor = MLXSW_SP1_FWREV_MINOR,
57 .subminor = MLXSW_SP1_FWREV_SUBMINOR,
58 .can_reset_minor = MLXSW_SP1_FWREV_CAN_RESET_MINOR,
61 #define MLXSW_SP1_FW_FILENAME \
64 static const char mlxsw_sp1_driver_name[] = "mlxsw_spectrum";
65 static const char mlxsw_sp2_driver_name[] = "mlxsw_spectrum2";
66 static const char mlxsw_sp3_driver_name[] = "mlxsw_spectrum3";
67 static const char mlxsw_sp_driver_version[] = "1.0";
69 static const unsigned char mlxsw_sp1_mac_mask[ETH_ALEN] = {
70 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00
72 static const unsigned char mlxsw_sp2_mac_mask[ETH_ALEN] = {
73 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00
80 MLXSW_ITEM32(tx, hdr, version, 0x00, 28, 4);
83 * Packet control type.
84 * 0 - Ethernet control (e.g. EMADs, LACP)
87 MLXSW_ITEM32(tx, hdr, ctl, 0x00, 26, 2);
90 * Packet protocol type. Must be set to 1 (Ethernet).
92 MLXSW_ITEM32(tx, hdr, proto, 0x00, 21, 3);
94 /* tx_hdr_rx_is_router
95 * Packet is sent from the router. Valid for data packets only.
97 MLXSW_ITEM32(tx, hdr, rx_is_router, 0x00, 19, 1);
100 * Indicates if the 'fid' field is valid and should be used for
101 * forwarding lookup. Valid for data packets only.
103 MLXSW_ITEM32(tx, hdr, fid_valid, 0x00, 16, 1);
106 * Switch partition ID. Must be set to 0.
108 MLXSW_ITEM32(tx, hdr, swid, 0x00, 12, 3);
110 /* tx_hdr_control_tclass
111 * Indicates if the packet should use the control TClass and not one
112 * of the data TClasses.
114 MLXSW_ITEM32(tx, hdr, control_tclass, 0x00, 6, 1);
117 * Egress TClass to be used on the egress device on the egress port.
119 MLXSW_ITEM32(tx, hdr, etclass, 0x00, 0, 4);
122 * Destination local port for unicast packets.
123 * Destination multicast ID for multicast packets.
125 * Control packets are directed to a specific egress port, while data
126 * packets are transmitted through the CPU port (0) into the switch partition,
127 * where forwarding rules are applied.
129 MLXSW_ITEM32(tx, hdr, port_mid, 0x04, 16, 16);
132 * Forwarding ID used for L2 forwarding lookup. Valid only if 'fid_valid' is
133 * set, otherwise calculated based on the packet's VID using VID to FID mapping.
134 * Valid for data packets only.
136 MLXSW_ITEM32(tx, hdr, fid, 0x08, 0, 16);
140 * 6 - Control packets
142 MLXSW_ITEM32(tx, hdr, type, 0x0C, 0, 4);
144 struct mlxsw_sp_mlxfw_dev {
145 struct mlxfw_dev mlxfw_dev;
146 struct mlxsw_sp *mlxsw_sp;
149 struct mlxsw_sp_ptp_ops {
150 struct mlxsw_sp_ptp_clock *
151 (*clock_init)(struct mlxsw_sp *mlxsw_sp, struct device *dev);
152 void (*clock_fini)(struct mlxsw_sp_ptp_clock *clock);
154 struct mlxsw_sp_ptp_state *(*init)(struct mlxsw_sp *mlxsw_sp);
155 void (*fini)(struct mlxsw_sp_ptp_state *ptp_state);
157 /* Notify a driver that a packet that might be PTP was received. Driver
158 * is responsible for freeing the passed-in SKB.
160 void (*receive)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
163 /* Notify a driver that a timestamped packet was transmitted. Driver
164 * is responsible for freeing the passed-in SKB.
166 void (*transmitted)(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
169 int (*hwtstamp_get)(struct mlxsw_sp_port *mlxsw_sp_port,
170 struct hwtstamp_config *config);
171 int (*hwtstamp_set)(struct mlxsw_sp_port *mlxsw_sp_port,
172 struct hwtstamp_config *config);
173 void (*shaper_work)(struct work_struct *work);
174 int (*get_ts_info)(struct mlxsw_sp *mlxsw_sp,
175 struct ethtool_ts_info *info);
176 int (*get_stats_count)(void);
177 void (*get_stats_strings)(u8 **p);
178 void (*get_stats)(struct mlxsw_sp_port *mlxsw_sp_port,
179 u64 *data, int data_index);
182 static int mlxsw_sp_component_query(struct mlxfw_dev *mlxfw_dev,
183 u16 component_index, u32 *p_max_size,
184 u8 *p_align_bits, u16 *p_max_write_size)
186 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
187 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
188 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
189 char mcqi_pl[MLXSW_REG_MCQI_LEN];
192 mlxsw_reg_mcqi_pack(mcqi_pl, component_index);
193 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mcqi), mcqi_pl);
196 mlxsw_reg_mcqi_unpack(mcqi_pl, p_max_size, p_align_bits,
199 *p_align_bits = max_t(u8, *p_align_bits, 2);
200 *p_max_write_size = min_t(u16, *p_max_write_size,
201 MLXSW_REG_MCDA_MAX_DATA_LEN);
205 static int mlxsw_sp_fsm_lock(struct mlxfw_dev *mlxfw_dev, u32 *fwhandle)
207 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
208 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
209 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
210 char mcc_pl[MLXSW_REG_MCC_LEN];
214 mlxsw_reg_mcc_pack(mcc_pl, 0, 0, 0, 0);
215 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mcc), mcc_pl);
219 mlxsw_reg_mcc_unpack(mcc_pl, fwhandle, NULL, &control_state);
220 if (control_state != MLXFW_FSM_STATE_IDLE)
223 mlxsw_reg_mcc_pack(mcc_pl,
224 MLXSW_REG_MCC_INSTRUCTION_LOCK_UPDATE_HANDLE,
226 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mcc), mcc_pl);
229 static int mlxsw_sp_fsm_component_update(struct mlxfw_dev *mlxfw_dev,
230 u32 fwhandle, u16 component_index,
233 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
234 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
235 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
236 char mcc_pl[MLXSW_REG_MCC_LEN];
238 mlxsw_reg_mcc_pack(mcc_pl, MLXSW_REG_MCC_INSTRUCTION_UPDATE_COMPONENT,
239 component_index, fwhandle, component_size);
240 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mcc), mcc_pl);
243 static int mlxsw_sp_fsm_block_download(struct mlxfw_dev *mlxfw_dev,
244 u32 fwhandle, u8 *data, u16 size,
247 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
248 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
249 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
250 char mcda_pl[MLXSW_REG_MCDA_LEN];
252 mlxsw_reg_mcda_pack(mcda_pl, fwhandle, offset, size, data);
253 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mcda), mcda_pl);
256 static int mlxsw_sp_fsm_component_verify(struct mlxfw_dev *mlxfw_dev,
257 u32 fwhandle, u16 component_index)
259 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
260 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
261 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
262 char mcc_pl[MLXSW_REG_MCC_LEN];
264 mlxsw_reg_mcc_pack(mcc_pl, MLXSW_REG_MCC_INSTRUCTION_VERIFY_COMPONENT,
265 component_index, fwhandle, 0);
266 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mcc), mcc_pl);
269 static int mlxsw_sp_fsm_activate(struct mlxfw_dev *mlxfw_dev, u32 fwhandle)
271 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
272 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
273 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
274 char mcc_pl[MLXSW_REG_MCC_LEN];
276 mlxsw_reg_mcc_pack(mcc_pl, MLXSW_REG_MCC_INSTRUCTION_ACTIVATE, 0,
278 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mcc), mcc_pl);
281 static int mlxsw_sp_fsm_query_state(struct mlxfw_dev *mlxfw_dev, u32 fwhandle,
282 enum mlxfw_fsm_state *fsm_state,
283 enum mlxfw_fsm_state_err *fsm_state_err)
285 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
286 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
287 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
288 char mcc_pl[MLXSW_REG_MCC_LEN];
293 mlxsw_reg_mcc_pack(mcc_pl, 0, 0, fwhandle, 0);
294 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mcc), mcc_pl);
298 mlxsw_reg_mcc_unpack(mcc_pl, NULL, &error_code, &control_state);
299 *fsm_state = control_state;
300 *fsm_state_err = min_t(enum mlxfw_fsm_state_err, error_code,
301 MLXFW_FSM_STATE_ERR_MAX);
305 static void mlxsw_sp_fsm_cancel(struct mlxfw_dev *mlxfw_dev, u32 fwhandle)
307 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
308 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
309 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
310 char mcc_pl[MLXSW_REG_MCC_LEN];
312 mlxsw_reg_mcc_pack(mcc_pl, MLXSW_REG_MCC_INSTRUCTION_CANCEL, 0,
314 mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mcc), mcc_pl);
317 static void mlxsw_sp_fsm_release(struct mlxfw_dev *mlxfw_dev, u32 fwhandle)
319 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
320 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
321 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
322 char mcc_pl[MLXSW_REG_MCC_LEN];
324 mlxsw_reg_mcc_pack(mcc_pl,
325 MLXSW_REG_MCC_INSTRUCTION_RELEASE_UPDATE_HANDLE, 0,
327 mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mcc), mcc_pl);
330 static void mlxsw_sp_status_notify(struct mlxfw_dev *mlxfw_dev,
331 const char *msg, const char *comp_name,
332 u32 done_bytes, u32 total_bytes)
334 struct mlxsw_sp_mlxfw_dev *mlxsw_sp_mlxfw_dev =
335 container_of(mlxfw_dev, struct mlxsw_sp_mlxfw_dev, mlxfw_dev);
336 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_mlxfw_dev->mlxsw_sp;
338 devlink_flash_update_status_notify(priv_to_devlink(mlxsw_sp->core),
340 done_bytes, total_bytes);
343 static const struct mlxfw_dev_ops mlxsw_sp_mlxfw_dev_ops = {
344 .component_query = mlxsw_sp_component_query,
345 .fsm_lock = mlxsw_sp_fsm_lock,
346 .fsm_component_update = mlxsw_sp_fsm_component_update,
347 .fsm_block_download = mlxsw_sp_fsm_block_download,
348 .fsm_component_verify = mlxsw_sp_fsm_component_verify,
349 .fsm_activate = mlxsw_sp_fsm_activate,
350 .fsm_query_state = mlxsw_sp_fsm_query_state,
351 .fsm_cancel = mlxsw_sp_fsm_cancel,
352 .fsm_release = mlxsw_sp_fsm_release,
353 .status_notify = mlxsw_sp_status_notify,
356 static int mlxsw_sp_firmware_flash(struct mlxsw_sp *mlxsw_sp,
357 const struct firmware *firmware,
358 struct netlink_ext_ack *extack)
360 struct mlxsw_sp_mlxfw_dev mlxsw_sp_mlxfw_dev = {
362 .ops = &mlxsw_sp_mlxfw_dev_ops,
363 .psid = mlxsw_sp->bus_info->psid,
364 .psid_size = strlen(mlxsw_sp->bus_info->psid),
370 mlxsw_core_fw_flash_start(mlxsw_sp->core);
371 devlink_flash_update_begin_notify(priv_to_devlink(mlxsw_sp->core));
372 err = mlxfw_firmware_flash(&mlxsw_sp_mlxfw_dev.mlxfw_dev,
374 devlink_flash_update_end_notify(priv_to_devlink(mlxsw_sp->core));
375 mlxsw_core_fw_flash_end(mlxsw_sp->core);
380 static int mlxsw_sp_fw_rev_validate(struct mlxsw_sp *mlxsw_sp)
382 const struct mlxsw_fw_rev *rev = &mlxsw_sp->bus_info->fw_rev;
383 const struct mlxsw_fw_rev *req_rev = mlxsw_sp->req_rev;
384 const char *fw_filename = mlxsw_sp->fw_filename;
385 union devlink_param_value value;
386 const struct firmware *firmware;
389 /* Don't check if driver does not require it */
390 if (!req_rev || !fw_filename)
393 /* Don't check if devlink 'fw_load_policy' param is 'flash' */
394 err = devlink_param_driverinit_value_get(priv_to_devlink(mlxsw_sp->core),
395 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
399 if (value.vu8 == DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_FLASH)
402 /* Validate driver & FW are compatible */
403 if (rev->major != req_rev->major) {
404 WARN(1, "Mismatch in major FW version [%d:%d] is never expected; Please contact support\n",
405 rev->major, req_rev->major);
408 if (MLXSW_SP_FWREV_MINOR_TO_BRANCH(rev->minor) ==
409 MLXSW_SP_FWREV_MINOR_TO_BRANCH(req_rev->minor) &&
410 (rev->minor > req_rev->minor ||
411 (rev->minor == req_rev->minor &&
412 rev->subminor >= req_rev->subminor)))
415 dev_info(mlxsw_sp->bus_info->dev, "The firmware version %d.%d.%d is incompatible with the driver\n",
416 rev->major, rev->minor, rev->subminor);
417 dev_info(mlxsw_sp->bus_info->dev, "Flashing firmware using file %s\n",
420 err = reject_firmware_direct(&firmware, fw_filename,
421 mlxsw_sp->bus_info->dev);
423 dev_err(mlxsw_sp->bus_info->dev, "Could not request firmware file %s\n",
428 err = mlxsw_sp_firmware_flash(mlxsw_sp, firmware, NULL);
429 release_firmware(firmware);
431 dev_err(mlxsw_sp->bus_info->dev, "Could not upgrade firmware\n");
433 /* On FW flash success, tell the caller FW reset is needed
434 * if current FW supports it.
436 if (rev->minor >= req_rev->can_reset_minor)
437 return err ? err : -EAGAIN;
442 static int mlxsw_sp_flash_update(struct mlxsw_core *mlxsw_core,
443 const char *file_name, const char *component,
444 struct netlink_ext_ack *extack)
446 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
447 const struct firmware *firmware;
453 err = request_firmware_direct(&firmware, file_name,
454 mlxsw_sp->bus_info->dev);
457 err = mlxsw_sp_firmware_flash(mlxsw_sp, firmware, extack);
458 release_firmware(firmware);
463 int mlxsw_sp_flow_counter_get(struct mlxsw_sp *mlxsw_sp,
464 unsigned int counter_index, u64 *packets,
467 char mgpc_pl[MLXSW_REG_MGPC_LEN];
470 mlxsw_reg_mgpc_pack(mgpc_pl, counter_index, MLXSW_REG_MGPC_OPCODE_NOP,
471 MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES);
472 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(mgpc), mgpc_pl);
476 *packets = mlxsw_reg_mgpc_packet_counter_get(mgpc_pl);
478 *bytes = mlxsw_reg_mgpc_byte_counter_get(mgpc_pl);
482 static int mlxsw_sp_flow_counter_clear(struct mlxsw_sp *mlxsw_sp,
483 unsigned int counter_index)
485 char mgpc_pl[MLXSW_REG_MGPC_LEN];
487 mlxsw_reg_mgpc_pack(mgpc_pl, counter_index, MLXSW_REG_MGPC_OPCODE_CLEAR,
488 MLXSW_REG_FLOW_COUNTER_SET_TYPE_PACKETS_BYTES);
489 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mgpc), mgpc_pl);
492 int mlxsw_sp_flow_counter_alloc(struct mlxsw_sp *mlxsw_sp,
493 unsigned int *p_counter_index)
497 err = mlxsw_sp_counter_alloc(mlxsw_sp, MLXSW_SP_COUNTER_SUB_POOL_FLOW,
501 err = mlxsw_sp_flow_counter_clear(mlxsw_sp, *p_counter_index);
503 goto err_counter_clear;
507 mlxsw_sp_counter_free(mlxsw_sp, MLXSW_SP_COUNTER_SUB_POOL_FLOW,
512 void mlxsw_sp_flow_counter_free(struct mlxsw_sp *mlxsw_sp,
513 unsigned int counter_index)
515 mlxsw_sp_counter_free(mlxsw_sp, MLXSW_SP_COUNTER_SUB_POOL_FLOW,
519 static void mlxsw_sp_txhdr_construct(struct sk_buff *skb,
520 const struct mlxsw_tx_info *tx_info)
522 char *txhdr = skb_push(skb, MLXSW_TXHDR_LEN);
524 memset(txhdr, 0, MLXSW_TXHDR_LEN);
526 mlxsw_tx_hdr_version_set(txhdr, MLXSW_TXHDR_VERSION_1);
527 mlxsw_tx_hdr_ctl_set(txhdr, MLXSW_TXHDR_ETH_CTL);
528 mlxsw_tx_hdr_proto_set(txhdr, MLXSW_TXHDR_PROTO_ETH);
529 mlxsw_tx_hdr_swid_set(txhdr, 0);
530 mlxsw_tx_hdr_control_tclass_set(txhdr, 1);
531 mlxsw_tx_hdr_port_mid_set(txhdr, tx_info->local_port);
532 mlxsw_tx_hdr_type_set(txhdr, MLXSW_TXHDR_TYPE_CONTROL);
535 enum mlxsw_reg_spms_state mlxsw_sp_stp_spms_state(u8 state)
538 case BR_STATE_FORWARDING:
539 return MLXSW_REG_SPMS_STATE_FORWARDING;
540 case BR_STATE_LEARNING:
541 return MLXSW_REG_SPMS_STATE_LEARNING;
542 case BR_STATE_LISTENING: /* fall-through */
543 case BR_STATE_DISABLED: /* fall-through */
544 case BR_STATE_BLOCKING:
545 return MLXSW_REG_SPMS_STATE_DISCARDING;
551 int mlxsw_sp_port_vid_stp_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
554 enum mlxsw_reg_spms_state spms_state = mlxsw_sp_stp_spms_state(state);
555 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
559 spms_pl = kmalloc(MLXSW_REG_SPMS_LEN, GFP_KERNEL);
562 mlxsw_reg_spms_pack(spms_pl, mlxsw_sp_port->local_port);
563 mlxsw_reg_spms_vid_pack(spms_pl, vid, spms_state);
565 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spms), spms_pl);
570 static int mlxsw_sp_base_mac_get(struct mlxsw_sp *mlxsw_sp)
572 char spad_pl[MLXSW_REG_SPAD_LEN] = {0};
575 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(spad), spad_pl);
578 mlxsw_reg_spad_base_mac_memcpy_from(spad_pl, mlxsw_sp->base_mac);
582 static int mlxsw_sp_port_sample_set(struct mlxsw_sp_port *mlxsw_sp_port,
583 bool enable, u32 rate)
585 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
586 char mpsc_pl[MLXSW_REG_MPSC_LEN];
588 mlxsw_reg_mpsc_pack(mpsc_pl, mlxsw_sp_port->local_port, enable, rate);
589 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mpsc), mpsc_pl);
592 static int mlxsw_sp_port_admin_status_set(struct mlxsw_sp_port *mlxsw_sp_port,
595 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
596 char paos_pl[MLXSW_REG_PAOS_LEN];
598 mlxsw_reg_paos_pack(paos_pl, mlxsw_sp_port->local_port,
599 is_up ? MLXSW_PORT_ADMIN_STATUS_UP :
600 MLXSW_PORT_ADMIN_STATUS_DOWN);
601 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(paos), paos_pl);
604 static int mlxsw_sp_port_dev_addr_set(struct mlxsw_sp_port *mlxsw_sp_port,
607 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
608 char ppad_pl[MLXSW_REG_PPAD_LEN];
610 mlxsw_reg_ppad_pack(ppad_pl, true, mlxsw_sp_port->local_port);
611 mlxsw_reg_ppad_mac_memcpy_to(ppad_pl, addr);
612 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ppad), ppad_pl);
615 static int mlxsw_sp_port_dev_addr_init(struct mlxsw_sp_port *mlxsw_sp_port)
617 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
618 unsigned char *addr = mlxsw_sp_port->dev->dev_addr;
620 ether_addr_copy(addr, mlxsw_sp->base_mac);
621 addr[ETH_ALEN - 1] += mlxsw_sp_port->local_port;
622 return mlxsw_sp_port_dev_addr_set(mlxsw_sp_port, addr);
625 static int mlxsw_sp_port_mtu_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 mtu)
627 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
628 char pmtu_pl[MLXSW_REG_PMTU_LEN];
632 mtu += MLXSW_TXHDR_LEN + ETH_HLEN;
633 mlxsw_reg_pmtu_pack(pmtu_pl, mlxsw_sp_port->local_port, 0);
634 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pmtu), pmtu_pl);
637 max_mtu = mlxsw_reg_pmtu_max_mtu_get(pmtu_pl);
642 mlxsw_reg_pmtu_pack(pmtu_pl, mlxsw_sp_port->local_port, mtu);
643 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmtu), pmtu_pl);
646 static int mlxsw_sp_port_swid_set(struct mlxsw_sp_port *mlxsw_sp_port, u8 swid)
648 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
649 char pspa_pl[MLXSW_REG_PSPA_LEN];
651 mlxsw_reg_pspa_pack(pspa_pl, swid, mlxsw_sp_port->local_port);
652 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pspa), pspa_pl);
655 int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, bool enable)
657 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
658 char svpe_pl[MLXSW_REG_SVPE_LEN];
660 mlxsw_reg_svpe_pack(svpe_pl, mlxsw_sp_port->local_port, enable);
661 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(svpe), svpe_pl);
664 int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid,
667 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
671 spvmlr_pl = kmalloc(MLXSW_REG_SPVMLR_LEN, GFP_KERNEL);
674 mlxsw_reg_spvmlr_pack(spvmlr_pl, mlxsw_sp_port->local_port, vid, vid,
676 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spvmlr), spvmlr_pl);
681 static int __mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port,
684 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
685 char spvid_pl[MLXSW_REG_SPVID_LEN];
687 mlxsw_reg_spvid_pack(spvid_pl, mlxsw_sp_port->local_port, vid);
688 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spvid), spvid_pl);
691 static int mlxsw_sp_port_allow_untagged_set(struct mlxsw_sp_port *mlxsw_sp_port,
694 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
695 char spaft_pl[MLXSW_REG_SPAFT_LEN];
697 mlxsw_reg_spaft_pack(spaft_pl, mlxsw_sp_port->local_port, allow);
698 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spaft), spaft_pl);
701 int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid)
706 err = mlxsw_sp_port_allow_untagged_set(mlxsw_sp_port, false);
710 err = __mlxsw_sp_port_pvid_set(mlxsw_sp_port, vid);
713 err = mlxsw_sp_port_allow_untagged_set(mlxsw_sp_port, true);
715 goto err_port_allow_untagged_set;
718 mlxsw_sp_port->pvid = vid;
721 err_port_allow_untagged_set:
722 __mlxsw_sp_port_pvid_set(mlxsw_sp_port, mlxsw_sp_port->pvid);
727 mlxsw_sp_port_system_port_mapping_set(struct mlxsw_sp_port *mlxsw_sp_port)
729 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
730 char sspr_pl[MLXSW_REG_SSPR_LEN];
732 mlxsw_reg_sspr_pack(sspr_pl, mlxsw_sp_port->local_port);
733 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sspr), sspr_pl);
736 static int mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
737 u8 local_port, u8 *p_module,
738 u8 *p_width, u8 *p_lane)
740 char pmlp_pl[MLXSW_REG_PMLP_LEN];
743 mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
744 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl);
747 *p_module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0);
748 *p_width = mlxsw_reg_pmlp_width_get(pmlp_pl);
749 *p_lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0);
753 static int mlxsw_sp_port_module_map(struct mlxsw_sp_port *mlxsw_sp_port,
754 u8 module, u8 width, u8 lane)
756 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
757 char pmlp_pl[MLXSW_REG_PMLP_LEN];
760 mlxsw_reg_pmlp_pack(pmlp_pl, mlxsw_sp_port->local_port);
761 mlxsw_reg_pmlp_width_set(pmlp_pl, width);
762 for (i = 0; i < width; i++) {
763 mlxsw_reg_pmlp_module_set(pmlp_pl, i, module);
764 mlxsw_reg_pmlp_tx_lane_set(pmlp_pl, i, lane + i); /* Rx & Tx */
767 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl);
770 static int mlxsw_sp_port_module_unmap(struct mlxsw_sp_port *mlxsw_sp_port)
772 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
773 char pmlp_pl[MLXSW_REG_PMLP_LEN];
775 mlxsw_reg_pmlp_pack(pmlp_pl, mlxsw_sp_port->local_port);
776 mlxsw_reg_pmlp_width_set(pmlp_pl, 0);
777 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl);
780 static int mlxsw_sp_port_open(struct net_device *dev)
782 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
785 err = mlxsw_sp_port_admin_status_set(mlxsw_sp_port, true);
788 netif_start_queue(dev);
792 static int mlxsw_sp_port_stop(struct net_device *dev)
794 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
796 netif_stop_queue(dev);
797 return mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false);
800 static netdev_tx_t mlxsw_sp_port_xmit(struct sk_buff *skb,
801 struct net_device *dev)
803 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
804 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
805 struct mlxsw_sp_port_pcpu_stats *pcpu_stats;
806 const struct mlxsw_tx_info tx_info = {
807 .local_port = mlxsw_sp_port->local_port,
813 if (skb_cow_head(skb, MLXSW_TXHDR_LEN)) {
814 this_cpu_inc(mlxsw_sp_port->pcpu_stats->tx_dropped);
815 dev_kfree_skb_any(skb);
819 memset(skb->cb, 0, sizeof(struct mlxsw_skb_cb));
821 if (mlxsw_core_skb_transmit_busy(mlxsw_sp->core, &tx_info))
822 return NETDEV_TX_BUSY;
824 if (eth_skb_pad(skb)) {
825 this_cpu_inc(mlxsw_sp_port->pcpu_stats->tx_dropped);
829 mlxsw_sp_txhdr_construct(skb, &tx_info);
830 /* TX header is consumed by HW on the way so we shouldn't count its
831 * bytes as being sent.
833 len = skb->len - MLXSW_TXHDR_LEN;
835 /* Due to a race we might fail here because of a full queue. In that
836 * unlikely case we simply drop the packet.
838 err = mlxsw_core_skb_transmit(mlxsw_sp->core, skb, &tx_info);
841 pcpu_stats = this_cpu_ptr(mlxsw_sp_port->pcpu_stats);
842 u64_stats_update_begin(&pcpu_stats->syncp);
843 pcpu_stats->tx_packets++;
844 pcpu_stats->tx_bytes += len;
845 u64_stats_update_end(&pcpu_stats->syncp);
847 this_cpu_inc(mlxsw_sp_port->pcpu_stats->tx_dropped);
848 dev_kfree_skb_any(skb);
853 static void mlxsw_sp_set_rx_mode(struct net_device *dev)
857 static int mlxsw_sp_port_set_mac_address(struct net_device *dev, void *p)
859 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
860 struct sockaddr *addr = p;
863 if (!is_valid_ether_addr(addr->sa_data))
864 return -EADDRNOTAVAIL;
866 err = mlxsw_sp_port_dev_addr_set(mlxsw_sp_port, addr->sa_data);
869 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
873 static u16 mlxsw_sp_pg_buf_threshold_get(const struct mlxsw_sp *mlxsw_sp,
876 return 2 * mlxsw_sp_bytes_cells(mlxsw_sp, mtu);
879 #define MLXSW_SP_CELL_FACTOR 2 /* 2 * cell_size / (IPG + cell_size + 1) */
881 static u16 mlxsw_sp_pfc_delay_get(const struct mlxsw_sp *mlxsw_sp, int mtu,
884 delay = mlxsw_sp_bytes_cells(mlxsw_sp, DIV_ROUND_UP(delay,
886 return MLXSW_SP_CELL_FACTOR * delay + mlxsw_sp_bytes_cells(mlxsw_sp,
890 /* Maximum delay buffer needed in case of PAUSE frames, in bytes.
891 * Assumes 100m cable and maximum MTU.
893 #define MLXSW_SP_PAUSE_DELAY 58752
895 static u16 mlxsw_sp_pg_buf_delay_get(const struct mlxsw_sp *mlxsw_sp, int mtu,
896 u16 delay, bool pfc, bool pause)
899 return mlxsw_sp_pfc_delay_get(mlxsw_sp, mtu, delay);
901 return mlxsw_sp_bytes_cells(mlxsw_sp, MLXSW_SP_PAUSE_DELAY);
906 static void mlxsw_sp_pg_buf_pack(char *pbmc_pl, int index, u16 size, u16 thres,
910 mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl, index, size);
912 mlxsw_reg_pbmc_lossless_buffer_pack(pbmc_pl, index, size,
916 int __mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port, int mtu,
917 u8 *prio_tc, bool pause_en,
918 struct ieee_pfc *my_pfc)
920 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
921 u8 pfc_en = !!my_pfc ? my_pfc->pfc_en : 0;
922 u16 delay = !!my_pfc ? my_pfc->delay : 0;
923 char pbmc_pl[MLXSW_REG_PBMC_LEN];
924 u32 taken_headroom_cells = 0;
925 u32 max_headroom_cells;
928 max_headroom_cells = mlxsw_sp_sb_max_headroom_cells(mlxsw_sp);
930 mlxsw_reg_pbmc_pack(pbmc_pl, mlxsw_sp_port->local_port, 0, 0);
931 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl);
935 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
936 bool configure = false;
943 for (j = 0; j < IEEE_8021QAZ_MAX_TCS; j++) {
944 if (prio_tc[j] == i) {
945 pfc = pfc_en & BIT(j);
954 lossy = !(pfc || pause_en);
955 thres_cells = mlxsw_sp_pg_buf_threshold_get(mlxsw_sp, mtu);
956 delay_cells = mlxsw_sp_pg_buf_delay_get(mlxsw_sp, mtu, delay,
958 total_cells = thres_cells + delay_cells;
960 taken_headroom_cells += total_cells;
961 if (taken_headroom_cells > max_headroom_cells)
964 mlxsw_sp_pg_buf_pack(pbmc_pl, i, total_cells,
968 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl);
971 static int mlxsw_sp_port_headroom_set(struct mlxsw_sp_port *mlxsw_sp_port,
972 int mtu, bool pause_en)
974 u8 def_prio_tc[IEEE_8021QAZ_MAX_TCS] = {0};
975 bool dcb_en = !!mlxsw_sp_port->dcb.ets;
976 struct ieee_pfc *my_pfc;
979 prio_tc = dcb_en ? mlxsw_sp_port->dcb.ets->prio_tc : def_prio_tc;
980 my_pfc = dcb_en ? mlxsw_sp_port->dcb.pfc : NULL;
982 return __mlxsw_sp_port_headroom_set(mlxsw_sp_port, mtu, prio_tc,
986 static int mlxsw_sp_port_change_mtu(struct net_device *dev, int mtu)
988 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
989 bool pause_en = mlxsw_sp_port_is_pause_en(mlxsw_sp_port);
992 err = mlxsw_sp_port_headroom_set(mlxsw_sp_port, mtu, pause_en);
995 err = mlxsw_sp_span_port_mtu_update(mlxsw_sp_port, mtu);
997 goto err_span_port_mtu_update;
998 err = mlxsw_sp_port_mtu_set(mlxsw_sp_port, mtu);
1000 goto err_port_mtu_set;
1005 mlxsw_sp_span_port_mtu_update(mlxsw_sp_port, dev->mtu);
1006 err_span_port_mtu_update:
1007 mlxsw_sp_port_headroom_set(mlxsw_sp_port, dev->mtu, pause_en);
1012 mlxsw_sp_port_get_sw_stats64(const struct net_device *dev,
1013 struct rtnl_link_stats64 *stats)
1015 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1016 struct mlxsw_sp_port_pcpu_stats *p;
1017 u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
1022 for_each_possible_cpu(i) {
1023 p = per_cpu_ptr(mlxsw_sp_port->pcpu_stats, i);
1025 start = u64_stats_fetch_begin_irq(&p->syncp);
1026 rx_packets = p->rx_packets;
1027 rx_bytes = p->rx_bytes;
1028 tx_packets = p->tx_packets;
1029 tx_bytes = p->tx_bytes;
1030 } while (u64_stats_fetch_retry_irq(&p->syncp, start));
1032 stats->rx_packets += rx_packets;
1033 stats->rx_bytes += rx_bytes;
1034 stats->tx_packets += tx_packets;
1035 stats->tx_bytes += tx_bytes;
1036 /* tx_dropped is u32, updated without syncp protection. */
1037 tx_dropped += p->tx_dropped;
1039 stats->tx_dropped = tx_dropped;
1043 static bool mlxsw_sp_port_has_offload_stats(const struct net_device *dev, int attr_id)
1046 case IFLA_OFFLOAD_XSTATS_CPU_HIT:
1053 static int mlxsw_sp_port_get_offload_stats(int attr_id, const struct net_device *dev,
1057 case IFLA_OFFLOAD_XSTATS_CPU_HIT:
1058 return mlxsw_sp_port_get_sw_stats64(dev, sp);
1064 static int mlxsw_sp_port_get_stats_raw(struct net_device *dev, int grp,
1065 int prio, char *ppcnt_pl)
1067 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1068 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1070 mlxsw_reg_ppcnt_pack(ppcnt_pl, mlxsw_sp_port->local_port, grp, prio);
1071 return mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(ppcnt), ppcnt_pl);
1074 static int mlxsw_sp_port_get_hw_stats(struct net_device *dev,
1075 struct rtnl_link_stats64 *stats)
1077 char ppcnt_pl[MLXSW_REG_PPCNT_LEN];
1080 err = mlxsw_sp_port_get_stats_raw(dev, MLXSW_REG_PPCNT_IEEE_8023_CNT,
1086 mlxsw_reg_ppcnt_a_frames_transmitted_ok_get(ppcnt_pl);
1088 mlxsw_reg_ppcnt_a_frames_received_ok_get(ppcnt_pl);
1090 mlxsw_reg_ppcnt_a_octets_transmitted_ok_get(ppcnt_pl);
1092 mlxsw_reg_ppcnt_a_octets_received_ok_get(ppcnt_pl);
1094 mlxsw_reg_ppcnt_a_multicast_frames_received_ok_get(ppcnt_pl);
1096 stats->rx_crc_errors =
1097 mlxsw_reg_ppcnt_a_frame_check_sequence_errors_get(ppcnt_pl);
1098 stats->rx_frame_errors =
1099 mlxsw_reg_ppcnt_a_alignment_errors_get(ppcnt_pl);
1101 stats->rx_length_errors = (
1102 mlxsw_reg_ppcnt_a_in_range_length_errors_get(ppcnt_pl) +
1103 mlxsw_reg_ppcnt_a_out_of_range_length_field_get(ppcnt_pl) +
1104 mlxsw_reg_ppcnt_a_frame_too_long_errors_get(ppcnt_pl));
1106 stats->rx_errors = (stats->rx_crc_errors +
1107 stats->rx_frame_errors + stats->rx_length_errors);
1114 mlxsw_sp_port_get_hw_xstats(struct net_device *dev,
1115 struct mlxsw_sp_port_xstats *xstats)
1117 char ppcnt_pl[MLXSW_REG_PPCNT_LEN];
1120 err = mlxsw_sp_port_get_stats_raw(dev, MLXSW_REG_PPCNT_EXT_CNT, 0,
1123 xstats->ecn = mlxsw_reg_ppcnt_ecn_marked_get(ppcnt_pl);
1125 for (i = 0; i < TC_MAX_QUEUE; i++) {
1126 err = mlxsw_sp_port_get_stats_raw(dev,
1127 MLXSW_REG_PPCNT_TC_CONG_TC,
1130 xstats->wred_drop[i] =
1131 mlxsw_reg_ppcnt_wred_discard_get(ppcnt_pl);
1133 err = mlxsw_sp_port_get_stats_raw(dev, MLXSW_REG_PPCNT_TC_CNT,
1138 xstats->backlog[i] =
1139 mlxsw_reg_ppcnt_tc_transmit_queue_get(ppcnt_pl);
1140 xstats->tail_drop[i] =
1141 mlxsw_reg_ppcnt_tc_no_buffer_discard_uc_get(ppcnt_pl);
1144 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
1145 err = mlxsw_sp_port_get_stats_raw(dev, MLXSW_REG_PPCNT_PRIO_CNT,
1150 xstats->tx_packets[i] = mlxsw_reg_ppcnt_tx_frames_get(ppcnt_pl);
1151 xstats->tx_bytes[i] = mlxsw_reg_ppcnt_tx_octets_get(ppcnt_pl);
1155 static void update_stats_cache(struct work_struct *work)
1157 struct mlxsw_sp_port *mlxsw_sp_port =
1158 container_of(work, struct mlxsw_sp_port,
1159 periodic_hw_stats.update_dw.work);
1161 if (!netif_carrier_ok(mlxsw_sp_port->dev))
1162 /* Note: mlxsw_sp_port_down_wipe_counters() clears the cache as
1163 * necessary when port goes down.
1167 mlxsw_sp_port_get_hw_stats(mlxsw_sp_port->dev,
1168 &mlxsw_sp_port->periodic_hw_stats.stats);
1169 mlxsw_sp_port_get_hw_xstats(mlxsw_sp_port->dev,
1170 &mlxsw_sp_port->periodic_hw_stats.xstats);
1173 mlxsw_core_schedule_dw(&mlxsw_sp_port->periodic_hw_stats.update_dw,
1174 MLXSW_HW_STATS_UPDATE_TIME);
1177 /* Return the stats from a cache that is updated periodically,
1178 * as this function might get called in an atomic context.
1181 mlxsw_sp_port_get_stats64(struct net_device *dev,
1182 struct rtnl_link_stats64 *stats)
1184 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1186 memcpy(stats, &mlxsw_sp_port->periodic_hw_stats.stats, sizeof(*stats));
1189 static int __mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port,
1190 u16 vid_begin, u16 vid_end,
1191 bool is_member, bool untagged)
1193 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1197 spvm_pl = kmalloc(MLXSW_REG_SPVM_LEN, GFP_KERNEL);
1201 mlxsw_reg_spvm_pack(spvm_pl, mlxsw_sp_port->local_port, vid_begin,
1202 vid_end, is_member, untagged);
1203 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spvm), spvm_pl);
1208 int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
1209 u16 vid_end, bool is_member, bool untagged)
1214 for (vid = vid_begin; vid <= vid_end;
1215 vid += MLXSW_REG_SPVM_REC_MAX_COUNT) {
1216 vid_e = min((u16) (vid + MLXSW_REG_SPVM_REC_MAX_COUNT - 1),
1219 err = __mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid_e,
1220 is_member, untagged);
1228 static void mlxsw_sp_port_vlan_flush(struct mlxsw_sp_port *mlxsw_sp_port,
1231 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan, *tmp;
1233 list_for_each_entry_safe(mlxsw_sp_port_vlan, tmp,
1234 &mlxsw_sp_port->vlans_list, list) {
1235 if (!flush_default &&
1236 mlxsw_sp_port_vlan->vid == MLXSW_SP_DEFAULT_VID)
1238 mlxsw_sp_port_vlan_destroy(mlxsw_sp_port_vlan);
1243 mlxsw_sp_port_vlan_cleanup(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan)
1245 if (mlxsw_sp_port_vlan->bridge_port)
1246 mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan);
1247 else if (mlxsw_sp_port_vlan->fid)
1248 mlxsw_sp_port_vlan_router_leave(mlxsw_sp_port_vlan);
1251 struct mlxsw_sp_port_vlan *
1252 mlxsw_sp_port_vlan_create(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid)
1254 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1255 bool untagged = vid == MLXSW_SP_DEFAULT_VID;
1258 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
1259 if (mlxsw_sp_port_vlan)
1260 return ERR_PTR(-EEXIST);
1262 err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, true, untagged);
1264 return ERR_PTR(err);
1266 mlxsw_sp_port_vlan = kzalloc(sizeof(*mlxsw_sp_port_vlan), GFP_KERNEL);
1267 if (!mlxsw_sp_port_vlan) {
1269 goto err_port_vlan_alloc;
1272 mlxsw_sp_port_vlan->mlxsw_sp_port = mlxsw_sp_port;
1273 mlxsw_sp_port_vlan->vid = vid;
1274 list_add(&mlxsw_sp_port_vlan->list, &mlxsw_sp_port->vlans_list);
1276 return mlxsw_sp_port_vlan;
1278 err_port_vlan_alloc:
1279 mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, false, false);
1280 return ERR_PTR(err);
1283 void mlxsw_sp_port_vlan_destroy(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan)
1285 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp_port_vlan->mlxsw_sp_port;
1286 u16 vid = mlxsw_sp_port_vlan->vid;
1288 mlxsw_sp_port_vlan_cleanup(mlxsw_sp_port_vlan);
1289 list_del(&mlxsw_sp_port_vlan->list);
1290 kfree(mlxsw_sp_port_vlan);
1291 mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid, false, false);
1294 static int mlxsw_sp_port_add_vid(struct net_device *dev,
1295 __be16 __always_unused proto, u16 vid)
1297 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1299 /* VLAN 0 is added to HW filter when device goes up, but it is
1300 * reserved in our case, so simply return.
1305 return PTR_ERR_OR_ZERO(mlxsw_sp_port_vlan_create(mlxsw_sp_port, vid));
1308 static int mlxsw_sp_port_kill_vid(struct net_device *dev,
1309 __be16 __always_unused proto, u16 vid)
1311 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1312 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
1314 /* VLAN 0 is removed from HW filter when device goes down, but
1315 * it is reserved in our case, so simply return.
1320 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid);
1321 if (!mlxsw_sp_port_vlan)
1323 mlxsw_sp_port_vlan_destroy(mlxsw_sp_port_vlan);
1328 static struct mlxsw_sp_port_mall_tc_entry *
1329 mlxsw_sp_port_mall_tc_entry_find(struct mlxsw_sp_port *port,
1330 unsigned long cookie) {
1331 struct mlxsw_sp_port_mall_tc_entry *mall_tc_entry;
1333 list_for_each_entry(mall_tc_entry, &port->mall_tc_list, list)
1334 if (mall_tc_entry->cookie == cookie)
1335 return mall_tc_entry;
1341 mlxsw_sp_port_add_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port,
1342 struct mlxsw_sp_port_mall_mirror_tc_entry *mirror,
1343 const struct flow_action_entry *act,
1346 enum mlxsw_sp_span_type span_type;
1349 netdev_err(mlxsw_sp_port->dev, "Could not find requested device\n");
1353 mirror->ingress = ingress;
1354 span_type = ingress ? MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS;
1355 return mlxsw_sp_span_mirror_add(mlxsw_sp_port, act->dev, span_type,
1356 true, &mirror->span_id);
1360 mlxsw_sp_port_del_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port,
1361 struct mlxsw_sp_port_mall_mirror_tc_entry *mirror)
1363 enum mlxsw_sp_span_type span_type;
1365 span_type = mirror->ingress ?
1366 MLXSW_SP_SPAN_INGRESS : MLXSW_SP_SPAN_EGRESS;
1367 mlxsw_sp_span_mirror_del(mlxsw_sp_port, mirror->span_id,
1372 mlxsw_sp_port_add_cls_matchall_sample(struct mlxsw_sp_port *mlxsw_sp_port,
1373 struct tc_cls_matchall_offload *cls,
1374 const struct flow_action_entry *act,
1379 if (!mlxsw_sp_port->sample)
1381 if (rtnl_dereference(mlxsw_sp_port->sample->psample_group)) {
1382 netdev_err(mlxsw_sp_port->dev, "sample already active\n");
1385 if (act->sample.rate > MLXSW_REG_MPSC_RATE_MAX) {
1386 netdev_err(mlxsw_sp_port->dev, "sample rate not supported\n");
1390 rcu_assign_pointer(mlxsw_sp_port->sample->psample_group,
1391 act->sample.psample_group);
1392 mlxsw_sp_port->sample->truncate = act->sample.truncate;
1393 mlxsw_sp_port->sample->trunc_size = act->sample.trunc_size;
1394 mlxsw_sp_port->sample->rate = act->sample.rate;
1396 err = mlxsw_sp_port_sample_set(mlxsw_sp_port, true, act->sample.rate);
1398 goto err_port_sample_set;
1401 err_port_sample_set:
1402 RCU_INIT_POINTER(mlxsw_sp_port->sample->psample_group, NULL);
1407 mlxsw_sp_port_del_cls_matchall_sample(struct mlxsw_sp_port *mlxsw_sp_port)
1409 if (!mlxsw_sp_port->sample)
1412 mlxsw_sp_port_sample_set(mlxsw_sp_port, false, 1);
1413 RCU_INIT_POINTER(mlxsw_sp_port->sample->psample_group, NULL);
1416 static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
1417 struct tc_cls_matchall_offload *f,
1420 struct mlxsw_sp_port_mall_tc_entry *mall_tc_entry;
1421 __be16 protocol = f->common.protocol;
1422 struct flow_action_entry *act;
1425 if (!flow_offload_has_one_action(&f->rule->action)) {
1426 netdev_err(mlxsw_sp_port->dev, "only singular actions are supported\n");
1430 mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
1433 mall_tc_entry->cookie = f->cookie;
1435 act = &f->rule->action.entries[0];
1437 if (act->id == FLOW_ACTION_MIRRED && protocol == htons(ETH_P_ALL)) {
1438 struct mlxsw_sp_port_mall_mirror_tc_entry *mirror;
1440 mall_tc_entry->type = MLXSW_SP_PORT_MALL_MIRROR;
1441 mirror = &mall_tc_entry->mirror;
1442 err = mlxsw_sp_port_add_cls_matchall_mirror(mlxsw_sp_port,
1445 } else if (act->id == FLOW_ACTION_SAMPLE &&
1446 protocol == htons(ETH_P_ALL)) {
1447 mall_tc_entry->type = MLXSW_SP_PORT_MALL_SAMPLE;
1448 err = mlxsw_sp_port_add_cls_matchall_sample(mlxsw_sp_port, f,
1455 goto err_add_action;
1457 list_add_tail(&mall_tc_entry->list, &mlxsw_sp_port->mall_tc_list);
1461 kfree(mall_tc_entry);
1465 static void mlxsw_sp_port_del_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
1466 struct tc_cls_matchall_offload *f)
1468 struct mlxsw_sp_port_mall_tc_entry *mall_tc_entry;
1470 mall_tc_entry = mlxsw_sp_port_mall_tc_entry_find(mlxsw_sp_port,
1472 if (!mall_tc_entry) {
1473 netdev_dbg(mlxsw_sp_port->dev, "tc entry not found on port\n");
1476 list_del(&mall_tc_entry->list);
1478 switch (mall_tc_entry->type) {
1479 case MLXSW_SP_PORT_MALL_MIRROR:
1480 mlxsw_sp_port_del_cls_matchall_mirror(mlxsw_sp_port,
1481 &mall_tc_entry->mirror);
1483 case MLXSW_SP_PORT_MALL_SAMPLE:
1484 mlxsw_sp_port_del_cls_matchall_sample(mlxsw_sp_port);
1490 kfree(mall_tc_entry);
1493 static int mlxsw_sp_setup_tc_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
1494 struct tc_cls_matchall_offload *f,
1497 switch (f->command) {
1498 case TC_CLSMATCHALL_REPLACE:
1499 return mlxsw_sp_port_add_cls_matchall(mlxsw_sp_port, f,
1501 case TC_CLSMATCHALL_DESTROY:
1502 mlxsw_sp_port_del_cls_matchall(mlxsw_sp_port, f);
1510 mlxsw_sp_setup_tc_cls_flower(struct mlxsw_sp_acl_block *acl_block,
1511 struct flow_cls_offload *f)
1513 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_acl_block_mlxsw_sp(acl_block);
1515 switch (f->command) {
1516 case FLOW_CLS_REPLACE:
1517 return mlxsw_sp_flower_replace(mlxsw_sp, acl_block, f);
1518 case FLOW_CLS_DESTROY:
1519 mlxsw_sp_flower_destroy(mlxsw_sp, acl_block, f);
1521 case FLOW_CLS_STATS:
1522 return mlxsw_sp_flower_stats(mlxsw_sp, acl_block, f);
1523 case FLOW_CLS_TMPLT_CREATE:
1524 return mlxsw_sp_flower_tmplt_create(mlxsw_sp, acl_block, f);
1525 case FLOW_CLS_TMPLT_DESTROY:
1526 mlxsw_sp_flower_tmplt_destroy(mlxsw_sp, acl_block, f);
1533 static int mlxsw_sp_setup_tc_block_cb_matchall(enum tc_setup_type type,
1535 void *cb_priv, bool ingress)
1537 struct mlxsw_sp_port *mlxsw_sp_port = cb_priv;
1540 case TC_SETUP_CLSMATCHALL:
1541 if (!tc_cls_can_offload_and_chain0(mlxsw_sp_port->dev,
1545 return mlxsw_sp_setup_tc_cls_matchall(mlxsw_sp_port, type_data,
1547 case TC_SETUP_CLSFLOWER:
1554 static int mlxsw_sp_setup_tc_block_cb_matchall_ig(enum tc_setup_type type,
1558 return mlxsw_sp_setup_tc_block_cb_matchall(type, type_data,
1562 static int mlxsw_sp_setup_tc_block_cb_matchall_eg(enum tc_setup_type type,
1566 return mlxsw_sp_setup_tc_block_cb_matchall(type, type_data,
1570 static int mlxsw_sp_setup_tc_block_cb_flower(enum tc_setup_type type,
1571 void *type_data, void *cb_priv)
1573 struct mlxsw_sp_acl_block *acl_block = cb_priv;
1576 case TC_SETUP_CLSMATCHALL:
1578 case TC_SETUP_CLSFLOWER:
1579 if (mlxsw_sp_acl_block_disabled(acl_block))
1582 return mlxsw_sp_setup_tc_cls_flower(acl_block, type_data);
1588 static void mlxsw_sp_tc_block_flower_release(void *cb_priv)
1590 struct mlxsw_sp_acl_block *acl_block = cb_priv;
1592 mlxsw_sp_acl_block_destroy(acl_block);
1595 static LIST_HEAD(mlxsw_sp_block_cb_list);
1598 mlxsw_sp_setup_tc_block_flower_bind(struct mlxsw_sp_port *mlxsw_sp_port,
1599 struct flow_block_offload *f, bool ingress)
1601 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1602 struct mlxsw_sp_acl_block *acl_block;
1603 struct flow_block_cb *block_cb;
1604 bool register_block = false;
1607 block_cb = flow_block_cb_lookup(f->block,
1608 mlxsw_sp_setup_tc_block_cb_flower,
1611 acl_block = mlxsw_sp_acl_block_create(mlxsw_sp, f->net);
1614 block_cb = flow_block_cb_alloc(mlxsw_sp_setup_tc_block_cb_flower,
1615 mlxsw_sp, acl_block,
1616 mlxsw_sp_tc_block_flower_release);
1617 if (IS_ERR(block_cb)) {
1618 mlxsw_sp_acl_block_destroy(acl_block);
1619 err = PTR_ERR(block_cb);
1620 goto err_cb_register;
1622 register_block = true;
1624 acl_block = flow_block_cb_priv(block_cb);
1626 flow_block_cb_incref(block_cb);
1627 err = mlxsw_sp_acl_block_bind(mlxsw_sp, acl_block,
1628 mlxsw_sp_port, ingress, f->extack);
1630 goto err_block_bind;
1633 mlxsw_sp_port->ing_acl_block = acl_block;
1635 mlxsw_sp_port->eg_acl_block = acl_block;
1637 if (register_block) {
1638 flow_block_cb_add(block_cb, f);
1639 list_add_tail(&block_cb->driver_list, &mlxsw_sp_block_cb_list);
1645 if (!flow_block_cb_decref(block_cb))
1646 flow_block_cb_free(block_cb);
1652 mlxsw_sp_setup_tc_block_flower_unbind(struct mlxsw_sp_port *mlxsw_sp_port,
1653 struct flow_block_offload *f, bool ingress)
1655 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1656 struct mlxsw_sp_acl_block *acl_block;
1657 struct flow_block_cb *block_cb;
1660 block_cb = flow_block_cb_lookup(f->block,
1661 mlxsw_sp_setup_tc_block_cb_flower,
1667 mlxsw_sp_port->ing_acl_block = NULL;
1669 mlxsw_sp_port->eg_acl_block = NULL;
1671 acl_block = flow_block_cb_priv(block_cb);
1672 err = mlxsw_sp_acl_block_unbind(mlxsw_sp, acl_block,
1673 mlxsw_sp_port, ingress);
1674 if (!err && !flow_block_cb_decref(block_cb)) {
1675 flow_block_cb_remove(block_cb, f);
1676 list_del(&block_cb->driver_list);
1680 static int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port,
1681 struct flow_block_offload *f)
1683 struct flow_block_cb *block_cb;
1684 flow_setup_cb_t *cb;
1688 if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS) {
1689 cb = mlxsw_sp_setup_tc_block_cb_matchall_ig;
1691 } else if (f->binder_type == FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS) {
1692 cb = mlxsw_sp_setup_tc_block_cb_matchall_eg;
1698 f->driver_block_list = &mlxsw_sp_block_cb_list;
1700 switch (f->command) {
1701 case FLOW_BLOCK_BIND:
1702 if (flow_block_cb_is_busy(cb, mlxsw_sp_port,
1703 &mlxsw_sp_block_cb_list))
1706 block_cb = flow_block_cb_alloc(cb, mlxsw_sp_port,
1707 mlxsw_sp_port, NULL);
1708 if (IS_ERR(block_cb))
1709 return PTR_ERR(block_cb);
1710 err = mlxsw_sp_setup_tc_block_flower_bind(mlxsw_sp_port, f,
1713 flow_block_cb_free(block_cb);
1716 flow_block_cb_add(block_cb, f);
1717 list_add_tail(&block_cb->driver_list, &mlxsw_sp_block_cb_list);
1719 case FLOW_BLOCK_UNBIND:
1720 mlxsw_sp_setup_tc_block_flower_unbind(mlxsw_sp_port,
1722 block_cb = flow_block_cb_lookup(f->block, cb, mlxsw_sp_port);
1726 flow_block_cb_remove(block_cb, f);
1727 list_del(&block_cb->driver_list);
1734 static int mlxsw_sp_setup_tc(struct net_device *dev, enum tc_setup_type type,
1737 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1740 case TC_SETUP_BLOCK:
1741 return mlxsw_sp_setup_tc_block(mlxsw_sp_port, type_data);
1742 case TC_SETUP_QDISC_RED:
1743 return mlxsw_sp_setup_tc_red(mlxsw_sp_port, type_data);
1744 case TC_SETUP_QDISC_PRIO:
1745 return mlxsw_sp_setup_tc_prio(mlxsw_sp_port, type_data);
1752 static int mlxsw_sp_feature_hw_tc(struct net_device *dev, bool enable)
1754 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1757 if (mlxsw_sp_acl_block_rule_count(mlxsw_sp_port->ing_acl_block) ||
1758 mlxsw_sp_acl_block_rule_count(mlxsw_sp_port->eg_acl_block) ||
1759 !list_empty(&mlxsw_sp_port->mall_tc_list)) {
1760 netdev_err(dev, "Active offloaded tc filters, can't turn hw_tc_offload off\n");
1763 mlxsw_sp_acl_block_disable_inc(mlxsw_sp_port->ing_acl_block);
1764 mlxsw_sp_acl_block_disable_inc(mlxsw_sp_port->eg_acl_block);
1766 mlxsw_sp_acl_block_disable_dec(mlxsw_sp_port->ing_acl_block);
1767 mlxsw_sp_acl_block_disable_dec(mlxsw_sp_port->eg_acl_block);
1772 static int mlxsw_sp_feature_loopback(struct net_device *dev, bool enable)
1774 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1775 char pplr_pl[MLXSW_REG_PPLR_LEN];
1778 if (netif_running(dev))
1779 mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false);
1781 mlxsw_reg_pplr_pack(pplr_pl, mlxsw_sp_port->local_port, enable);
1782 err = mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pplr),
1785 if (netif_running(dev))
1786 mlxsw_sp_port_admin_status_set(mlxsw_sp_port, true);
1791 typedef int (*mlxsw_sp_feature_handler)(struct net_device *dev, bool enable);
1793 static int mlxsw_sp_handle_feature(struct net_device *dev,
1794 netdev_features_t wanted_features,
1795 netdev_features_t feature,
1796 mlxsw_sp_feature_handler feature_handler)
1798 netdev_features_t changes = wanted_features ^ dev->features;
1799 bool enable = !!(wanted_features & feature);
1802 if (!(changes & feature))
1805 err = feature_handler(dev, enable);
1807 netdev_err(dev, "%s feature %pNF failed, err %d\n",
1808 enable ? "Enable" : "Disable", &feature, err);
1813 dev->features |= feature;
1815 dev->features &= ~feature;
1819 static int mlxsw_sp_set_features(struct net_device *dev,
1820 netdev_features_t features)
1822 netdev_features_t oper_features = dev->features;
1825 err |= mlxsw_sp_handle_feature(dev, features, NETIF_F_HW_TC,
1826 mlxsw_sp_feature_hw_tc);
1827 err |= mlxsw_sp_handle_feature(dev, features, NETIF_F_LOOPBACK,
1828 mlxsw_sp_feature_loopback);
1831 dev->features = oper_features;
1838 static struct devlink_port *
1839 mlxsw_sp_port_get_devlink_port(struct net_device *dev)
1841 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1842 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1844 return mlxsw_core_port_devlink_port_get(mlxsw_sp->core,
1845 mlxsw_sp_port->local_port);
1848 static int mlxsw_sp_port_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
1851 struct hwtstamp_config config;
1854 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
1857 err = mlxsw_sp_port->mlxsw_sp->ptp_ops->hwtstamp_set(mlxsw_sp_port,
1862 if (copy_to_user(ifr->ifr_data, &config, sizeof(config)))
1868 static int mlxsw_sp_port_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
1871 struct hwtstamp_config config;
1874 err = mlxsw_sp_port->mlxsw_sp->ptp_ops->hwtstamp_get(mlxsw_sp_port,
1879 if (copy_to_user(ifr->ifr_data, &config, sizeof(config)))
1885 static inline void mlxsw_sp_port_ptp_clear(struct mlxsw_sp_port *mlxsw_sp_port)
1887 struct hwtstamp_config config = {0};
1889 mlxsw_sp_port->mlxsw_sp->ptp_ops->hwtstamp_set(mlxsw_sp_port, &config);
1893 mlxsw_sp_port_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1895 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1899 return mlxsw_sp_port_hwtstamp_set(mlxsw_sp_port, ifr);
1901 return mlxsw_sp_port_hwtstamp_get(mlxsw_sp_port, ifr);
1907 static const struct net_device_ops mlxsw_sp_port_netdev_ops = {
1908 .ndo_open = mlxsw_sp_port_open,
1909 .ndo_stop = mlxsw_sp_port_stop,
1910 .ndo_start_xmit = mlxsw_sp_port_xmit,
1911 .ndo_setup_tc = mlxsw_sp_setup_tc,
1912 .ndo_set_rx_mode = mlxsw_sp_set_rx_mode,
1913 .ndo_set_mac_address = mlxsw_sp_port_set_mac_address,
1914 .ndo_change_mtu = mlxsw_sp_port_change_mtu,
1915 .ndo_get_stats64 = mlxsw_sp_port_get_stats64,
1916 .ndo_has_offload_stats = mlxsw_sp_port_has_offload_stats,
1917 .ndo_get_offload_stats = mlxsw_sp_port_get_offload_stats,
1918 .ndo_vlan_rx_add_vid = mlxsw_sp_port_add_vid,
1919 .ndo_vlan_rx_kill_vid = mlxsw_sp_port_kill_vid,
1920 .ndo_set_features = mlxsw_sp_set_features,
1921 .ndo_get_devlink_port = mlxsw_sp_port_get_devlink_port,
1922 .ndo_do_ioctl = mlxsw_sp_port_ioctl,
1925 static void mlxsw_sp_port_get_drvinfo(struct net_device *dev,
1926 struct ethtool_drvinfo *drvinfo)
1928 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1929 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1931 strlcpy(drvinfo->driver, mlxsw_sp->bus_info->device_kind,
1932 sizeof(drvinfo->driver));
1933 strlcpy(drvinfo->version, mlxsw_sp_driver_version,
1934 sizeof(drvinfo->version));
1935 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
1937 mlxsw_sp->bus_info->fw_rev.major,
1938 mlxsw_sp->bus_info->fw_rev.minor,
1939 mlxsw_sp->bus_info->fw_rev.subminor);
1940 strlcpy(drvinfo->bus_info, mlxsw_sp->bus_info->device_name,
1941 sizeof(drvinfo->bus_info));
1944 static void mlxsw_sp_port_get_pauseparam(struct net_device *dev,
1945 struct ethtool_pauseparam *pause)
1947 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1949 pause->rx_pause = mlxsw_sp_port->link.rx_pause;
1950 pause->tx_pause = mlxsw_sp_port->link.tx_pause;
1953 static int mlxsw_sp_port_pause_set(struct mlxsw_sp_port *mlxsw_sp_port,
1954 struct ethtool_pauseparam *pause)
1956 char pfcc_pl[MLXSW_REG_PFCC_LEN];
1958 mlxsw_reg_pfcc_pack(pfcc_pl, mlxsw_sp_port->local_port);
1959 mlxsw_reg_pfcc_pprx_set(pfcc_pl, pause->rx_pause);
1960 mlxsw_reg_pfcc_pptx_set(pfcc_pl, pause->tx_pause);
1962 return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pfcc),
1966 static int mlxsw_sp_port_set_pauseparam(struct net_device *dev,
1967 struct ethtool_pauseparam *pause)
1969 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
1970 bool pause_en = pause->tx_pause || pause->rx_pause;
1973 if (mlxsw_sp_port->dcb.pfc && mlxsw_sp_port->dcb.pfc->pfc_en) {
1974 netdev_err(dev, "PFC already enabled on port\n");
1978 if (pause->autoneg) {
1979 netdev_err(dev, "PAUSE frames autonegotiation isn't supported\n");
1983 err = mlxsw_sp_port_headroom_set(mlxsw_sp_port, dev->mtu, pause_en);
1985 netdev_err(dev, "Failed to configure port's headroom\n");
1989 err = mlxsw_sp_port_pause_set(mlxsw_sp_port, pause);
1991 netdev_err(dev, "Failed to set PAUSE parameters\n");
1992 goto err_port_pause_configure;
1995 mlxsw_sp_port->link.rx_pause = pause->rx_pause;
1996 mlxsw_sp_port->link.tx_pause = pause->tx_pause;
2000 err_port_pause_configure:
2001 pause_en = mlxsw_sp_port_is_pause_en(mlxsw_sp_port);
2002 mlxsw_sp_port_headroom_set(mlxsw_sp_port, dev->mtu, pause_en);
2006 struct mlxsw_sp_port_hw_stats {
2007 char str[ETH_GSTRING_LEN];
2008 u64 (*getter)(const char *payload);
2012 static struct mlxsw_sp_port_hw_stats mlxsw_sp_port_hw_stats[] = {
2014 .str = "a_frames_transmitted_ok",
2015 .getter = mlxsw_reg_ppcnt_a_frames_transmitted_ok_get,
2018 .str = "a_frames_received_ok",
2019 .getter = mlxsw_reg_ppcnt_a_frames_received_ok_get,
2022 .str = "a_frame_check_sequence_errors",
2023 .getter = mlxsw_reg_ppcnt_a_frame_check_sequence_errors_get,
2026 .str = "a_alignment_errors",
2027 .getter = mlxsw_reg_ppcnt_a_alignment_errors_get,
2030 .str = "a_octets_transmitted_ok",
2031 .getter = mlxsw_reg_ppcnt_a_octets_transmitted_ok_get,
2034 .str = "a_octets_received_ok",
2035 .getter = mlxsw_reg_ppcnt_a_octets_received_ok_get,
2038 .str = "a_multicast_frames_xmitted_ok",
2039 .getter = mlxsw_reg_ppcnt_a_multicast_frames_xmitted_ok_get,
2042 .str = "a_broadcast_frames_xmitted_ok",
2043 .getter = mlxsw_reg_ppcnt_a_broadcast_frames_xmitted_ok_get,
2046 .str = "a_multicast_frames_received_ok",
2047 .getter = mlxsw_reg_ppcnt_a_multicast_frames_received_ok_get,
2050 .str = "a_broadcast_frames_received_ok",
2051 .getter = mlxsw_reg_ppcnt_a_broadcast_frames_received_ok_get,
2054 .str = "a_in_range_length_errors",
2055 .getter = mlxsw_reg_ppcnt_a_in_range_length_errors_get,
2058 .str = "a_out_of_range_length_field",
2059 .getter = mlxsw_reg_ppcnt_a_out_of_range_length_field_get,
2062 .str = "a_frame_too_long_errors",
2063 .getter = mlxsw_reg_ppcnt_a_frame_too_long_errors_get,
2066 .str = "a_symbol_error_during_carrier",
2067 .getter = mlxsw_reg_ppcnt_a_symbol_error_during_carrier_get,
2070 .str = "a_mac_control_frames_transmitted",
2071 .getter = mlxsw_reg_ppcnt_a_mac_control_frames_transmitted_get,
2074 .str = "a_mac_control_frames_received",
2075 .getter = mlxsw_reg_ppcnt_a_mac_control_frames_received_get,
2078 .str = "a_unsupported_opcodes_received",
2079 .getter = mlxsw_reg_ppcnt_a_unsupported_opcodes_received_get,
2082 .str = "a_pause_mac_ctrl_frames_received",
2083 .getter = mlxsw_reg_ppcnt_a_pause_mac_ctrl_frames_received_get,
2086 .str = "a_pause_mac_ctrl_frames_xmitted",
2087 .getter = mlxsw_reg_ppcnt_a_pause_mac_ctrl_frames_transmitted_get,
2091 #define MLXSW_SP_PORT_HW_STATS_LEN ARRAY_SIZE(mlxsw_sp_port_hw_stats)
2093 static struct mlxsw_sp_port_hw_stats mlxsw_sp_port_hw_rfc_2863_stats[] = {
2095 .str = "if_in_discards",
2096 .getter = mlxsw_reg_ppcnt_if_in_discards_get,
2099 .str = "if_out_discards",
2100 .getter = mlxsw_reg_ppcnt_if_out_discards_get,
2103 .str = "if_out_errors",
2104 .getter = mlxsw_reg_ppcnt_if_out_errors_get,
2108 #define MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN \
2109 ARRAY_SIZE(mlxsw_sp_port_hw_rfc_2863_stats)
2111 static struct mlxsw_sp_port_hw_stats mlxsw_sp_port_hw_rfc_2819_stats[] = {
2113 .str = "ether_stats_undersize_pkts",
2114 .getter = mlxsw_reg_ppcnt_ether_stats_undersize_pkts_get,
2117 .str = "ether_stats_oversize_pkts",
2118 .getter = mlxsw_reg_ppcnt_ether_stats_oversize_pkts_get,
2121 .str = "ether_stats_fragments",
2122 .getter = mlxsw_reg_ppcnt_ether_stats_fragments_get,
2125 .str = "ether_pkts64octets",
2126 .getter = mlxsw_reg_ppcnt_ether_stats_pkts64octets_get,
2129 .str = "ether_pkts65to127octets",
2130 .getter = mlxsw_reg_ppcnt_ether_stats_pkts65to127octets_get,
2133 .str = "ether_pkts128to255octets",
2134 .getter = mlxsw_reg_ppcnt_ether_stats_pkts128to255octets_get,
2137 .str = "ether_pkts256to511octets",
2138 .getter = mlxsw_reg_ppcnt_ether_stats_pkts256to511octets_get,
2141 .str = "ether_pkts512to1023octets",
2142 .getter = mlxsw_reg_ppcnt_ether_stats_pkts512to1023octets_get,
2145 .str = "ether_pkts1024to1518octets",
2146 .getter = mlxsw_reg_ppcnt_ether_stats_pkts1024to1518octets_get,
2149 .str = "ether_pkts1519to2047octets",
2150 .getter = mlxsw_reg_ppcnt_ether_stats_pkts1519to2047octets_get,
2153 .str = "ether_pkts2048to4095octets",
2154 .getter = mlxsw_reg_ppcnt_ether_stats_pkts2048to4095octets_get,
2157 .str = "ether_pkts4096to8191octets",
2158 .getter = mlxsw_reg_ppcnt_ether_stats_pkts4096to8191octets_get,
2161 .str = "ether_pkts8192to10239octets",
2162 .getter = mlxsw_reg_ppcnt_ether_stats_pkts8192to10239octets_get,
2166 #define MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN \
2167 ARRAY_SIZE(mlxsw_sp_port_hw_rfc_2819_stats)
2169 static struct mlxsw_sp_port_hw_stats mlxsw_sp_port_hw_rfc_3635_stats[] = {
2171 .str = "dot3stats_fcs_errors",
2172 .getter = mlxsw_reg_ppcnt_dot3stats_fcs_errors_get,
2175 .str = "dot3stats_symbol_errors",
2176 .getter = mlxsw_reg_ppcnt_dot3stats_symbol_errors_get,
2179 .str = "dot3control_in_unknown_opcodes",
2180 .getter = mlxsw_reg_ppcnt_dot3control_in_unknown_opcodes_get,
2183 .str = "dot3in_pause_frames",
2184 .getter = mlxsw_reg_ppcnt_dot3in_pause_frames_get,
2188 #define MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN \
2189 ARRAY_SIZE(mlxsw_sp_port_hw_rfc_3635_stats)
2191 static struct mlxsw_sp_port_hw_stats mlxsw_sp_port_hw_discard_stats[] = {
2193 .str = "discard_ingress_general",
2194 .getter = mlxsw_reg_ppcnt_ingress_general_get,
2197 .str = "discard_ingress_policy_engine",
2198 .getter = mlxsw_reg_ppcnt_ingress_policy_engine_get,
2201 .str = "discard_ingress_vlan_membership",
2202 .getter = mlxsw_reg_ppcnt_ingress_vlan_membership_get,
2205 .str = "discard_ingress_tag_frame_type",
2206 .getter = mlxsw_reg_ppcnt_ingress_tag_frame_type_get,
2209 .str = "discard_egress_vlan_membership",
2210 .getter = mlxsw_reg_ppcnt_egress_vlan_membership_get,
2213 .str = "discard_loopback_filter",
2214 .getter = mlxsw_reg_ppcnt_loopback_filter_get,
2217 .str = "discard_egress_general",
2218 .getter = mlxsw_reg_ppcnt_egress_general_get,
2221 .str = "discard_egress_hoq",
2222 .getter = mlxsw_reg_ppcnt_egress_hoq_get,
2225 .str = "discard_egress_policy_engine",
2226 .getter = mlxsw_reg_ppcnt_egress_policy_engine_get,
2229 .str = "discard_ingress_tx_link_down",
2230 .getter = mlxsw_reg_ppcnt_ingress_tx_link_down_get,
2233 .str = "discard_egress_stp_filter",
2234 .getter = mlxsw_reg_ppcnt_egress_stp_filter_get,
2237 .str = "discard_egress_sll",
2238 .getter = mlxsw_reg_ppcnt_egress_sll_get,
2242 #define MLXSW_SP_PORT_HW_DISCARD_STATS_LEN \
2243 ARRAY_SIZE(mlxsw_sp_port_hw_discard_stats)
2245 static struct mlxsw_sp_port_hw_stats mlxsw_sp_port_hw_prio_stats[] = {
2247 .str = "rx_octets_prio",
2248 .getter = mlxsw_reg_ppcnt_rx_octets_get,
2251 .str = "rx_frames_prio",
2252 .getter = mlxsw_reg_ppcnt_rx_frames_get,
2255 .str = "tx_octets_prio",
2256 .getter = mlxsw_reg_ppcnt_tx_octets_get,
2259 .str = "tx_frames_prio",
2260 .getter = mlxsw_reg_ppcnt_tx_frames_get,
2263 .str = "rx_pause_prio",
2264 .getter = mlxsw_reg_ppcnt_rx_pause_get,
2267 .str = "rx_pause_duration_prio",
2268 .getter = mlxsw_reg_ppcnt_rx_pause_duration_get,
2271 .str = "tx_pause_prio",
2272 .getter = mlxsw_reg_ppcnt_tx_pause_get,
2275 .str = "tx_pause_duration_prio",
2276 .getter = mlxsw_reg_ppcnt_tx_pause_duration_get,
2280 #define MLXSW_SP_PORT_HW_PRIO_STATS_LEN ARRAY_SIZE(mlxsw_sp_port_hw_prio_stats)
2282 static struct mlxsw_sp_port_hw_stats mlxsw_sp_port_hw_tc_stats[] = {
2284 .str = "tc_transmit_queue_tc",
2285 .getter = mlxsw_reg_ppcnt_tc_transmit_queue_get,
2286 .cells_bytes = true,
2289 .str = "tc_no_buffer_discard_uc_tc",
2290 .getter = mlxsw_reg_ppcnt_tc_no_buffer_discard_uc_get,
2294 #define MLXSW_SP_PORT_HW_TC_STATS_LEN ARRAY_SIZE(mlxsw_sp_port_hw_tc_stats)
2296 #define MLXSW_SP_PORT_ETHTOOL_STATS_LEN (MLXSW_SP_PORT_HW_STATS_LEN + \
2297 MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN + \
2298 MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN + \
2299 MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN + \
2300 MLXSW_SP_PORT_HW_DISCARD_STATS_LEN + \
2301 (MLXSW_SP_PORT_HW_PRIO_STATS_LEN * \
2302 IEEE_8021QAZ_MAX_TCS) + \
2303 (MLXSW_SP_PORT_HW_TC_STATS_LEN * \
2306 static void mlxsw_sp_port_get_prio_strings(u8 **p, int prio)
2310 for (i = 0; i < MLXSW_SP_PORT_HW_PRIO_STATS_LEN; i++) {
2311 snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
2312 mlxsw_sp_port_hw_prio_stats[i].str, prio);
2313 *p += ETH_GSTRING_LEN;
2317 static void mlxsw_sp_port_get_tc_strings(u8 **p, int tc)
2321 for (i = 0; i < MLXSW_SP_PORT_HW_TC_STATS_LEN; i++) {
2322 snprintf(*p, ETH_GSTRING_LEN, "%.29s_%.1d",
2323 mlxsw_sp_port_hw_tc_stats[i].str, tc);
2324 *p += ETH_GSTRING_LEN;
2328 static void mlxsw_sp_port_get_strings(struct net_device *dev,
2329 u32 stringset, u8 *data)
2331 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
2335 switch (stringset) {
2337 for (i = 0; i < MLXSW_SP_PORT_HW_STATS_LEN; i++) {
2338 memcpy(p, mlxsw_sp_port_hw_stats[i].str,
2340 p += ETH_GSTRING_LEN;
2343 for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN; i++) {
2344 memcpy(p, mlxsw_sp_port_hw_rfc_2863_stats[i].str,
2346 p += ETH_GSTRING_LEN;
2349 for (i = 0; i < MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN; i++) {
2350 memcpy(p, mlxsw_sp_port_hw_rfc_2819_stats[i].str,
2352 p += ETH_GSTRING_LEN;
2355 for (i = 0; i < MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN; i++) {
2356 memcpy(p, mlxsw_sp_port_hw_rfc_3635_stats[i].str,
2358 p += ETH_GSTRING_LEN;
2361 for (i = 0; i < MLXSW_SP_PORT_HW_DISCARD_STATS_LEN; i++) {
2362 memcpy(p, mlxsw_sp_port_hw_discard_stats[i].str,
2364 p += ETH_GSTRING_LEN;
2367 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
2368 mlxsw_sp_port_get_prio_strings(&p, i);
2370 for (i = 0; i < TC_MAX_QUEUE; i++)
2371 mlxsw_sp_port_get_tc_strings(&p, i);
2373 mlxsw_sp_port->mlxsw_sp->ptp_ops->get_stats_strings(&p);
2378 static int mlxsw_sp_port_set_phys_id(struct net_device *dev,
2379 enum ethtool_phys_id_state state)
2381 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
2382 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
2383 char mlcr_pl[MLXSW_REG_MLCR_LEN];
2387 case ETHTOOL_ID_ACTIVE:
2390 case ETHTOOL_ID_INACTIVE:
2397 mlxsw_reg_mlcr_pack(mlcr_pl, mlxsw_sp_port->local_port, active);
2398 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(mlcr), mlcr_pl);
2402 mlxsw_sp_get_hw_stats_by_group(struct mlxsw_sp_port_hw_stats **p_hw_stats,
2403 int *p_len, enum mlxsw_reg_ppcnt_grp grp)
2406 case MLXSW_REG_PPCNT_IEEE_8023_CNT:
2407 *p_hw_stats = mlxsw_sp_port_hw_stats;
2408 *p_len = MLXSW_SP_PORT_HW_STATS_LEN;
2410 case MLXSW_REG_PPCNT_RFC_2863_CNT:
2411 *p_hw_stats = mlxsw_sp_port_hw_rfc_2863_stats;
2412 *p_len = MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN;
2414 case MLXSW_REG_PPCNT_RFC_2819_CNT:
2415 *p_hw_stats = mlxsw_sp_port_hw_rfc_2819_stats;
2416 *p_len = MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN;
2418 case MLXSW_REG_PPCNT_RFC_3635_CNT:
2419 *p_hw_stats = mlxsw_sp_port_hw_rfc_3635_stats;
2420 *p_len = MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN;
2422 case MLXSW_REG_PPCNT_DISCARD_CNT:
2423 *p_hw_stats = mlxsw_sp_port_hw_discard_stats;
2424 *p_len = MLXSW_SP_PORT_HW_DISCARD_STATS_LEN;
2426 case MLXSW_REG_PPCNT_PRIO_CNT:
2427 *p_hw_stats = mlxsw_sp_port_hw_prio_stats;
2428 *p_len = MLXSW_SP_PORT_HW_PRIO_STATS_LEN;
2430 case MLXSW_REG_PPCNT_TC_CNT:
2431 *p_hw_stats = mlxsw_sp_port_hw_tc_stats;
2432 *p_len = MLXSW_SP_PORT_HW_TC_STATS_LEN;
2441 static void __mlxsw_sp_port_get_stats(struct net_device *dev,
2442 enum mlxsw_reg_ppcnt_grp grp, int prio,
2443 u64 *data, int data_index)
2445 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
2446 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
2447 struct mlxsw_sp_port_hw_stats *hw_stats;
2448 char ppcnt_pl[MLXSW_REG_PPCNT_LEN];
2452 err = mlxsw_sp_get_hw_stats_by_group(&hw_stats, &len, grp);
2455 mlxsw_sp_port_get_stats_raw(dev, grp, prio, ppcnt_pl);
2456 for (i = 0; i < len; i++) {
2457 data[data_index + i] = hw_stats[i].getter(ppcnt_pl);
2458 if (!hw_stats[i].cells_bytes)
2460 data[data_index + i] = mlxsw_sp_cells_bytes(mlxsw_sp,
2461 data[data_index + i]);
2465 static void mlxsw_sp_port_get_stats(struct net_device *dev,
2466 struct ethtool_stats *stats, u64 *data)
2468 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
2469 int i, data_index = 0;
2471 /* IEEE 802.3 Counters */
2472 __mlxsw_sp_port_get_stats(dev, MLXSW_REG_PPCNT_IEEE_8023_CNT, 0,
2474 data_index = MLXSW_SP_PORT_HW_STATS_LEN;
2476 /* RFC 2863 Counters */
2477 __mlxsw_sp_port_get_stats(dev, MLXSW_REG_PPCNT_RFC_2863_CNT, 0,
2479 data_index += MLXSW_SP_PORT_HW_RFC_2863_STATS_LEN;
2481 /* RFC 2819 Counters */
2482 __mlxsw_sp_port_get_stats(dev, MLXSW_REG_PPCNT_RFC_2819_CNT, 0,
2484 data_index += MLXSW_SP_PORT_HW_RFC_2819_STATS_LEN;
2486 /* RFC 3635 Counters */
2487 __mlxsw_sp_port_get_stats(dev, MLXSW_REG_PPCNT_RFC_3635_CNT, 0,
2489 data_index += MLXSW_SP_PORT_HW_RFC_3635_STATS_LEN;
2491 /* Discard Counters */
2492 __mlxsw_sp_port_get_stats(dev, MLXSW_REG_PPCNT_DISCARD_CNT, 0,
2494 data_index += MLXSW_SP_PORT_HW_DISCARD_STATS_LEN;
2496 /* Per-Priority Counters */
2497 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
2498 __mlxsw_sp_port_get_stats(dev, MLXSW_REG_PPCNT_PRIO_CNT, i,
2500 data_index += MLXSW_SP_PORT_HW_PRIO_STATS_LEN;
2503 /* Per-TC Counters */
2504 for (i = 0; i < TC_MAX_QUEUE; i++) {
2505 __mlxsw_sp_port_get_stats(dev, MLXSW_REG_PPCNT_TC_CNT, i,
2507 data_index += MLXSW_SP_PORT_HW_TC_STATS_LEN;
2511 mlxsw_sp_port->mlxsw_sp->ptp_ops->get_stats(mlxsw_sp_port,
2513 data_index += mlxsw_sp_port->mlxsw_sp->ptp_ops->get_stats_count();
2516 static int mlxsw_sp_port_get_sset_count(struct net_device *dev, int sset)
2518 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
2522 return MLXSW_SP_PORT_ETHTOOL_STATS_LEN +
2523 mlxsw_sp_port->mlxsw_sp->ptp_ops->get_stats_count();
2529 struct mlxsw_sp1_port_link_mode {
2530 enum ethtool_link_mode_bit_indices mask_ethtool;
2535 static const struct mlxsw_sp1_port_link_mode mlxsw_sp1_port_link_mode[] = {
2537 .mask = MLXSW_REG_PTYS_ETH_SPEED_100BASE_T,
2538 .mask_ethtool = ETHTOOL_LINK_MODE_100baseT_Full_BIT,
2542 .mask = MLXSW_REG_PTYS_ETH_SPEED_SGMII |
2543 MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX,
2544 .mask_ethtool = ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
2545 .speed = SPEED_1000,
2548 .mask = MLXSW_REG_PTYS_ETH_SPEED_10GBASE_T,
2549 .mask_ethtool = ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
2550 .speed = SPEED_10000,
2553 .mask = MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CX4 |
2554 MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4,
2555 .mask_ethtool = ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
2556 .speed = SPEED_10000,
2559 .mask = MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR |
2560 MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR |
2561 MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR |
2562 MLXSW_REG_PTYS_ETH_SPEED_10GBASE_ER_LR,
2563 .mask_ethtool = ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
2564 .speed = SPEED_10000,
2567 .mask = MLXSW_REG_PTYS_ETH_SPEED_20GBASE_KR2,
2568 .mask_ethtool = ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
2569 .speed = SPEED_20000,
2572 .mask = MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4,
2573 .mask_ethtool = ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
2574 .speed = SPEED_40000,
2577 .mask = MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4,
2578 .mask_ethtool = ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
2579 .speed = SPEED_40000,
2582 .mask = MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4,
2583 .mask_ethtool = ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
2584 .speed = SPEED_40000,
2587 .mask = MLXSW_REG_PTYS_ETH_SPEED_40GBASE_LR4_ER4,
2588 .mask_ethtool = ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
2589 .speed = SPEED_40000,
2592 .mask = MLXSW_REG_PTYS_ETH_SPEED_25GBASE_CR,
2593 .mask_ethtool = ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
2594 .speed = SPEED_25000,
2597 .mask = MLXSW_REG_PTYS_ETH_SPEED_25GBASE_KR,
2598 .mask_ethtool = ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
2599 .speed = SPEED_25000,
2602 .mask = MLXSW_REG_PTYS_ETH_SPEED_25GBASE_SR,
2603 .mask_ethtool = ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
2604 .speed = SPEED_25000,
2607 .mask = MLXSW_REG_PTYS_ETH_SPEED_50GBASE_CR2,
2608 .mask_ethtool = ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
2609 .speed = SPEED_50000,
2612 .mask = MLXSW_REG_PTYS_ETH_SPEED_50GBASE_KR2,
2613 .mask_ethtool = ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
2614 .speed = SPEED_50000,
2617 .mask = MLXSW_REG_PTYS_ETH_SPEED_50GBASE_SR2,
2618 .mask_ethtool = ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
2619 .speed = SPEED_50000,
2622 .mask = MLXSW_REG_PTYS_ETH_SPEED_100GBASE_CR4,
2623 .mask_ethtool = ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
2624 .speed = SPEED_100000,
2627 .mask = MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4,
2628 .mask_ethtool = ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
2629 .speed = SPEED_100000,
2632 .mask = MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4,
2633 .mask_ethtool = ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
2634 .speed = SPEED_100000,
2637 .mask = MLXSW_REG_PTYS_ETH_SPEED_100GBASE_LR4_ER4,
2638 .mask_ethtool = ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
2639 .speed = SPEED_100000,
2643 #define MLXSW_SP1_PORT_LINK_MODE_LEN ARRAY_SIZE(mlxsw_sp1_port_link_mode)
2646 mlxsw_sp1_from_ptys_supported_port(struct mlxsw_sp *mlxsw_sp,
2648 struct ethtool_link_ksettings *cmd)
2650 if (ptys_eth_proto & (MLXSW_REG_PTYS_ETH_SPEED_10GBASE_CR |
2651 MLXSW_REG_PTYS_ETH_SPEED_10GBASE_SR |
2652 MLXSW_REG_PTYS_ETH_SPEED_40GBASE_CR4 |
2653 MLXSW_REG_PTYS_ETH_SPEED_40GBASE_SR4 |
2654 MLXSW_REG_PTYS_ETH_SPEED_100GBASE_SR4 |
2655 MLXSW_REG_PTYS_ETH_SPEED_SGMII))
2656 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
2658 if (ptys_eth_proto & (MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KR |
2659 MLXSW_REG_PTYS_ETH_SPEED_10GBASE_KX4 |
2660 MLXSW_REG_PTYS_ETH_SPEED_40GBASE_KR4 |
2661 MLXSW_REG_PTYS_ETH_SPEED_100GBASE_KR4 |
2662 MLXSW_REG_PTYS_ETH_SPEED_1000BASE_KX))
2663 ethtool_link_ksettings_add_link_mode(cmd, supported, Backplane);
2667 mlxsw_sp1_from_ptys_link(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
2668 u8 width, unsigned long *mode)
2672 for (i = 0; i < MLXSW_SP1_PORT_LINK_MODE_LEN; i++) {
2673 if (ptys_eth_proto & mlxsw_sp1_port_link_mode[i].mask)
2674 __set_bit(mlxsw_sp1_port_link_mode[i].mask_ethtool,
2680 mlxsw_sp1_from_ptys_speed(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto)
2684 for (i = 0; i < MLXSW_SP1_PORT_LINK_MODE_LEN; i++) {
2685 if (ptys_eth_proto & mlxsw_sp1_port_link_mode[i].mask)
2686 return mlxsw_sp1_port_link_mode[i].speed;
2689 return SPEED_UNKNOWN;
2693 mlxsw_sp1_from_ptys_speed_duplex(struct mlxsw_sp *mlxsw_sp, bool carrier_ok,
2695 struct ethtool_link_ksettings *cmd)
2697 cmd->base.speed = SPEED_UNKNOWN;
2698 cmd->base.duplex = DUPLEX_UNKNOWN;
2703 cmd->base.speed = mlxsw_sp1_from_ptys_speed(mlxsw_sp, ptys_eth_proto);
2704 if (cmd->base.speed != SPEED_UNKNOWN)
2705 cmd->base.duplex = DUPLEX_FULL;
2709 mlxsw_sp1_to_ptys_advert_link(struct mlxsw_sp *mlxsw_sp, u8 width,
2710 const struct ethtool_link_ksettings *cmd)
2715 for (i = 0; i < MLXSW_SP1_PORT_LINK_MODE_LEN; i++) {
2716 if (test_bit(mlxsw_sp1_port_link_mode[i].mask_ethtool,
2717 cmd->link_modes.advertising))
2718 ptys_proto |= mlxsw_sp1_port_link_mode[i].mask;
2723 static u32 mlxsw_sp1_to_ptys_speed(struct mlxsw_sp *mlxsw_sp, u8 width,
2729 for (i = 0; i < MLXSW_SP1_PORT_LINK_MODE_LEN; i++) {
2730 if (speed == mlxsw_sp1_port_link_mode[i].speed)
2731 ptys_proto |= mlxsw_sp1_port_link_mode[i].mask;
2737 mlxsw_sp1_to_ptys_upper_speed(struct mlxsw_sp *mlxsw_sp, u32 upper_speed)
2742 for (i = 0; i < MLXSW_SP1_PORT_LINK_MODE_LEN; i++) {
2743 if (mlxsw_sp1_port_link_mode[i].speed <= upper_speed)
2744 ptys_proto |= mlxsw_sp1_port_link_mode[i].mask;
2750 mlxsw_sp1_port_speed_base(struct mlxsw_sp *mlxsw_sp, u8 local_port,
2753 *base_speed = MLXSW_SP_PORT_BASE_SPEED_25G;
2758 mlxsw_sp1_reg_ptys_eth_pack(struct mlxsw_sp *mlxsw_sp, char *payload,
2759 u8 local_port, u32 proto_admin, bool autoneg)
2761 mlxsw_reg_ptys_eth_pack(payload, local_port, proto_admin, autoneg);
2765 mlxsw_sp1_reg_ptys_eth_unpack(struct mlxsw_sp *mlxsw_sp, char *payload,
2766 u32 *p_eth_proto_cap, u32 *p_eth_proto_admin,
2767 u32 *p_eth_proto_oper)
2769 mlxsw_reg_ptys_eth_unpack(payload, p_eth_proto_cap, p_eth_proto_admin,
2773 static const struct mlxsw_sp_port_type_speed_ops
2774 mlxsw_sp1_port_type_speed_ops = {
2775 .from_ptys_supported_port = mlxsw_sp1_from_ptys_supported_port,
2776 .from_ptys_link = mlxsw_sp1_from_ptys_link,
2777 .from_ptys_speed = mlxsw_sp1_from_ptys_speed,
2778 .from_ptys_speed_duplex = mlxsw_sp1_from_ptys_speed_duplex,
2779 .to_ptys_advert_link = mlxsw_sp1_to_ptys_advert_link,
2780 .to_ptys_speed = mlxsw_sp1_to_ptys_speed,
2781 .to_ptys_upper_speed = mlxsw_sp1_to_ptys_upper_speed,
2782 .port_speed_base = mlxsw_sp1_port_speed_base,
2783 .reg_ptys_eth_pack = mlxsw_sp1_reg_ptys_eth_pack,
2784 .reg_ptys_eth_unpack = mlxsw_sp1_reg_ptys_eth_unpack,
2787 static const enum ethtool_link_mode_bit_indices
2788 mlxsw_sp2_mask_ethtool_sgmii_100m[] = {
2789 ETHTOOL_LINK_MODE_100baseT_Full_BIT,
2792 #define MLXSW_SP2_MASK_ETHTOOL_SGMII_100M_LEN \
2793 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_sgmii_100m)
2795 static const enum ethtool_link_mode_bit_indices
2796 mlxsw_sp2_mask_ethtool_1000base_x_sgmii[] = {
2797 ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
2798 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
2801 #define MLXSW_SP2_MASK_ETHTOOL_1000BASE_X_SGMII_LEN \
2802 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_1000base_x_sgmii)
2804 static const enum ethtool_link_mode_bit_indices
2805 mlxsw_sp2_mask_ethtool_2_5gbase_x_2_5gmii[] = {
2806 ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
2809 #define MLXSW_SP2_MASK_ETHTOOL_2_5GBASE_X_2_5GMII_LEN \
2810 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_2_5gbase_x_2_5gmii)
2812 static const enum ethtool_link_mode_bit_indices
2813 mlxsw_sp2_mask_ethtool_5gbase_r[] = {
2814 ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
2817 #define MLXSW_SP2_MASK_ETHTOOL_5GBASE_R_LEN \
2818 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_5gbase_r)
2820 static const enum ethtool_link_mode_bit_indices
2821 mlxsw_sp2_mask_ethtool_xfi_xaui_1_10g[] = {
2822 ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
2823 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
2824 ETHTOOL_LINK_MODE_10000baseR_FEC_BIT,
2825 ETHTOOL_LINK_MODE_10000baseCR_Full_BIT,
2826 ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
2827 ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
2828 ETHTOOL_LINK_MODE_10000baseER_Full_BIT,
2831 #define MLXSW_SP2_MASK_ETHTOOL_XFI_XAUI_1_10G_LEN \
2832 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_xfi_xaui_1_10g)
2834 static const enum ethtool_link_mode_bit_indices
2835 mlxsw_sp2_mask_ethtool_xlaui_4_xlppi_4_40g[] = {
2836 ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
2837 ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
2838 ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
2839 ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
2842 #define MLXSW_SP2_MASK_ETHTOOL_XLAUI_4_XLPPI_4_40G_LEN \
2843 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_xlaui_4_xlppi_4_40g)
2845 static const enum ethtool_link_mode_bit_indices
2846 mlxsw_sp2_mask_ethtool_25gaui_1_25gbase_cr_kr[] = {
2847 ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
2848 ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
2849 ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
2852 #define MLXSW_SP2_MASK_ETHTOOL_25GAUI_1_25GBASE_CR_KR_LEN \
2853 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_25gaui_1_25gbase_cr_kr)
2855 static const enum ethtool_link_mode_bit_indices
2856 mlxsw_sp2_mask_ethtool_50gaui_2_laui_2_50gbase_cr2_kr2[] = {
2857 ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
2858 ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
2859 ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
2862 #define MLXSW_SP2_MASK_ETHTOOL_50GAUI_2_LAUI_2_50GBASE_CR2_KR2_LEN \
2863 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_50gaui_2_laui_2_50gbase_cr2_kr2)
2865 static const enum ethtool_link_mode_bit_indices
2866 mlxsw_sp2_mask_ethtool_50gaui_1_laui_1_50gbase_cr_kr[] = {
2867 ETHTOOL_LINK_MODE_50000baseKR_Full_BIT,
2868 ETHTOOL_LINK_MODE_50000baseSR_Full_BIT,
2869 ETHTOOL_LINK_MODE_50000baseCR_Full_BIT,
2870 ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT,
2871 ETHTOOL_LINK_MODE_50000baseDR_Full_BIT,
2874 #define MLXSW_SP2_MASK_ETHTOOL_50GAUI_1_LAUI_1_50GBASE_CR_KR_LEN \
2875 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_50gaui_1_laui_1_50gbase_cr_kr)
2877 static const enum ethtool_link_mode_bit_indices
2878 mlxsw_sp2_mask_ethtool_caui_4_100gbase_cr4_kr4[] = {
2879 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
2880 ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
2881 ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
2882 ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
2885 #define MLXSW_SP2_MASK_ETHTOOL_CAUI_4_100GBASE_CR4_KR4_LEN \
2886 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_caui_4_100gbase_cr4_kr4)
2888 static const enum ethtool_link_mode_bit_indices
2889 mlxsw_sp2_mask_ethtool_100gaui_2_100gbase_cr2_kr2[] = {
2890 ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT,
2891 ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT,
2892 ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT,
2893 ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT,
2894 ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT,
2897 #define MLXSW_SP2_MASK_ETHTOOL_100GAUI_2_100GBASE_CR2_KR2_LEN \
2898 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_100gaui_2_100gbase_cr2_kr2)
2900 static const enum ethtool_link_mode_bit_indices
2901 mlxsw_sp2_mask_ethtool_200gaui_4_200gbase_cr4_kr4[] = {
2902 ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT,
2903 ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT,
2904 ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT,
2905 ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT,
2906 ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT,
2909 #define MLXSW_SP2_MASK_ETHTOOL_200GAUI_4_200GBASE_CR4_KR4_LEN \
2910 ARRAY_SIZE(mlxsw_sp2_mask_ethtool_200gaui_4_200gbase_cr4_kr4)
2912 #define MLXSW_SP_PORT_MASK_WIDTH_1X BIT(0)
2913 #define MLXSW_SP_PORT_MASK_WIDTH_2X BIT(1)
2914 #define MLXSW_SP_PORT_MASK_WIDTH_4X BIT(2)
2916 static u8 mlxsw_sp_port_mask_width_get(u8 width)
2920 return MLXSW_SP_PORT_MASK_WIDTH_1X;
2922 return MLXSW_SP_PORT_MASK_WIDTH_2X;
2924 return MLXSW_SP_PORT_MASK_WIDTH_4X;
2931 struct mlxsw_sp2_port_link_mode {
2932 const enum ethtool_link_mode_bit_indices *mask_ethtool;
2939 static const struct mlxsw_sp2_port_link_mode mlxsw_sp2_port_link_mode[] = {
2941 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_SGMII_100M,
2942 .mask_ethtool = mlxsw_sp2_mask_ethtool_sgmii_100m,
2943 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_SGMII_100M_LEN,
2944 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_1X |
2945 MLXSW_SP_PORT_MASK_WIDTH_2X |
2946 MLXSW_SP_PORT_MASK_WIDTH_4X,
2950 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_1000BASE_X_SGMII,
2951 .mask_ethtool = mlxsw_sp2_mask_ethtool_1000base_x_sgmii,
2952 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_1000BASE_X_SGMII_LEN,
2953 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_1X |
2954 MLXSW_SP_PORT_MASK_WIDTH_2X |
2955 MLXSW_SP_PORT_MASK_WIDTH_4X,
2956 .speed = SPEED_1000,
2959 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_2_5GBASE_X_2_5GMII,
2960 .mask_ethtool = mlxsw_sp2_mask_ethtool_2_5gbase_x_2_5gmii,
2961 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_2_5GBASE_X_2_5GMII_LEN,
2962 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_1X |
2963 MLXSW_SP_PORT_MASK_WIDTH_2X |
2964 MLXSW_SP_PORT_MASK_WIDTH_4X,
2965 .speed = SPEED_2500,
2968 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_5GBASE_R,
2969 .mask_ethtool = mlxsw_sp2_mask_ethtool_5gbase_r,
2970 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_5GBASE_R_LEN,
2971 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_1X |
2972 MLXSW_SP_PORT_MASK_WIDTH_2X |
2973 MLXSW_SP_PORT_MASK_WIDTH_4X,
2974 .speed = SPEED_5000,
2977 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_XFI_XAUI_1_10G,
2978 .mask_ethtool = mlxsw_sp2_mask_ethtool_xfi_xaui_1_10g,
2979 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_XFI_XAUI_1_10G_LEN,
2980 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_1X |
2981 MLXSW_SP_PORT_MASK_WIDTH_2X |
2982 MLXSW_SP_PORT_MASK_WIDTH_4X,
2983 .speed = SPEED_10000,
2986 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_XLAUI_4_XLPPI_4_40G,
2987 .mask_ethtool = mlxsw_sp2_mask_ethtool_xlaui_4_xlppi_4_40g,
2988 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_XLAUI_4_XLPPI_4_40G_LEN,
2989 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_4X,
2990 .speed = SPEED_40000,
2993 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_25GAUI_1_25GBASE_CR_KR,
2994 .mask_ethtool = mlxsw_sp2_mask_ethtool_25gaui_1_25gbase_cr_kr,
2995 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_25GAUI_1_25GBASE_CR_KR_LEN,
2996 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_1X |
2997 MLXSW_SP_PORT_MASK_WIDTH_2X |
2998 MLXSW_SP_PORT_MASK_WIDTH_4X,
2999 .speed = SPEED_25000,
3002 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_50GAUI_2_LAUI_2_50GBASE_CR2_KR2,
3003 .mask_ethtool = mlxsw_sp2_mask_ethtool_50gaui_2_laui_2_50gbase_cr2_kr2,
3004 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_50GAUI_2_LAUI_2_50GBASE_CR2_KR2_LEN,
3005 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_2X |
3006 MLXSW_SP_PORT_MASK_WIDTH_4X,
3007 .speed = SPEED_50000,
3010 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_50GAUI_1_LAUI_1_50GBASE_CR_KR,
3011 .mask_ethtool = mlxsw_sp2_mask_ethtool_50gaui_1_laui_1_50gbase_cr_kr,
3012 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_50GAUI_1_LAUI_1_50GBASE_CR_KR_LEN,
3013 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_1X,
3014 .speed = SPEED_50000,
3017 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_CAUI_4_100GBASE_CR4_KR4,
3018 .mask_ethtool = mlxsw_sp2_mask_ethtool_caui_4_100gbase_cr4_kr4,
3019 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_CAUI_4_100GBASE_CR4_KR4_LEN,
3020 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_4X,
3021 .speed = SPEED_100000,
3024 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_100GAUI_2_100GBASE_CR2_KR2,
3025 .mask_ethtool = mlxsw_sp2_mask_ethtool_100gaui_2_100gbase_cr2_kr2,
3026 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_100GAUI_2_100GBASE_CR2_KR2_LEN,
3027 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_2X,
3028 .speed = SPEED_100000,
3031 .mask = MLXSW_REG_PTYS_EXT_ETH_SPEED_200GAUI_4_200GBASE_CR4_KR4,
3032 .mask_ethtool = mlxsw_sp2_mask_ethtool_200gaui_4_200gbase_cr4_kr4,
3033 .m_ethtool_len = MLXSW_SP2_MASK_ETHTOOL_200GAUI_4_200GBASE_CR4_KR4_LEN,
3034 .mask_width = MLXSW_SP_PORT_MASK_WIDTH_4X,
3035 .speed = SPEED_200000,
3039 #define MLXSW_SP2_PORT_LINK_MODE_LEN ARRAY_SIZE(mlxsw_sp2_port_link_mode)
3042 mlxsw_sp2_from_ptys_supported_port(struct mlxsw_sp *mlxsw_sp,
3044 struct ethtool_link_ksettings *cmd)
3046 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
3047 ethtool_link_ksettings_add_link_mode(cmd, supported, Backplane);
3051 mlxsw_sp2_set_bit_ethtool(const struct mlxsw_sp2_port_link_mode *link_mode,
3052 unsigned long *mode)
3056 for (i = 0; i < link_mode->m_ethtool_len; i++)
3057 __set_bit(link_mode->mask_ethtool[i], mode);
3061 mlxsw_sp2_from_ptys_link(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto,
3062 u8 width, unsigned long *mode)
3064 u8 mask_width = mlxsw_sp_port_mask_width_get(width);
3067 for (i = 0; i < MLXSW_SP2_PORT_LINK_MODE_LEN; i++) {
3068 if ((ptys_eth_proto & mlxsw_sp2_port_link_mode[i].mask) &&
3069 (mask_width & mlxsw_sp2_port_link_mode[i].mask_width))
3070 mlxsw_sp2_set_bit_ethtool(&mlxsw_sp2_port_link_mode[i],
3076 mlxsw_sp2_from_ptys_speed(struct mlxsw_sp *mlxsw_sp, u32 ptys_eth_proto)
3080 for (i = 0; i < MLXSW_SP2_PORT_LINK_MODE_LEN; i++) {
3081 if (ptys_eth_proto & mlxsw_sp2_port_link_mode[i].mask)
3082 return mlxsw_sp2_port_link_mode[i].speed;
3085 return SPEED_UNKNOWN;
3089 mlxsw_sp2_from_ptys_speed_duplex(struct mlxsw_sp *mlxsw_sp, bool carrier_ok,
3091 struct ethtool_link_ksettings *cmd)
3093 cmd->base.speed = SPEED_UNKNOWN;
3094 cmd->base.duplex = DUPLEX_UNKNOWN;
3099 cmd->base.speed = mlxsw_sp2_from_ptys_speed(mlxsw_sp, ptys_eth_proto);
3100 if (cmd->base.speed != SPEED_UNKNOWN)
3101 cmd->base.duplex = DUPLEX_FULL;
3105 mlxsw_sp2_test_bit_ethtool(const struct mlxsw_sp2_port_link_mode *link_mode,
3106 const unsigned long *mode)
3111 for (i = 0; i < link_mode->m_ethtool_len; i++) {
3112 if (test_bit(link_mode->mask_ethtool[i], mode))
3116 return cnt == link_mode->m_ethtool_len;
3120 mlxsw_sp2_to_ptys_advert_link(struct mlxsw_sp *mlxsw_sp, u8 width,
3121 const struct ethtool_link_ksettings *cmd)
3123 u8 mask_width = mlxsw_sp_port_mask_width_get(width);
3127 for (i = 0; i < MLXSW_SP2_PORT_LINK_MODE_LEN; i++) {
3128 if ((mask_width & mlxsw_sp2_port_link_mode[i].mask_width) &&
3129 mlxsw_sp2_test_bit_ethtool(&mlxsw_sp2_port_link_mode[i],
3130 cmd->link_modes.advertising))
3131 ptys_proto |= mlxsw_sp2_port_link_mode[i].mask;
3136 static u32 mlxsw_sp2_to_ptys_speed(struct mlxsw_sp *mlxsw_sp,
3137 u8 width, u32 speed)
3139 u8 mask_width = mlxsw_sp_port_mask_width_get(width);
3143 for (i = 0; i < MLXSW_SP2_PORT_LINK_MODE_LEN; i++) {
3144 if ((speed == mlxsw_sp2_port_link_mode[i].speed) &&
3145 (mask_width & mlxsw_sp2_port_link_mode[i].mask_width))
3146 ptys_proto |= mlxsw_sp2_port_link_mode[i].mask;
3152 mlxsw_sp2_to_ptys_upper_speed(struct mlxsw_sp *mlxsw_sp, u32 upper_speed)
3157 for (i = 0; i < MLXSW_SP2_PORT_LINK_MODE_LEN; i++) {
3158 if (mlxsw_sp2_port_link_mode[i].speed <= upper_speed)
3159 ptys_proto |= mlxsw_sp2_port_link_mode[i].mask;
3165 mlxsw_sp2_port_speed_base(struct mlxsw_sp *mlxsw_sp, u8 local_port,
3168 char ptys_pl[MLXSW_REG_PTYS_LEN];
3172 /* In Spectrum-2, the speed of 1x can change from port to port, so query
3175 mlxsw_reg_ptys_ext_eth_pack(ptys_pl, local_port, 0, false);
3176 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(ptys), ptys_pl);
3179 mlxsw_reg_ptys_ext_eth_unpack(ptys_pl, ð_proto_cap, NULL, NULL);
3182 MLXSW_REG_PTYS_EXT_ETH_SPEED_50GAUI_1_LAUI_1_50GBASE_CR_KR) {
3183 *base_speed = MLXSW_SP_PORT_BASE_SPEED_50G;
3188 MLXSW_REG_PTYS_EXT_ETH_SPEED_25GAUI_1_25GBASE_CR_KR) {
3189 *base_speed = MLXSW_SP_PORT_BASE_SPEED_25G;
3197 mlxsw_sp2_reg_ptys_eth_pack(struct mlxsw_sp *mlxsw_sp, char *payload,
3198 u8 local_port, u32 proto_admin,
3201 mlxsw_reg_ptys_ext_eth_pack(payload, local_port, proto_admin, autoneg);
3205 mlxsw_sp2_reg_ptys_eth_unpack(struct mlxsw_sp *mlxsw_sp, char *payload,
3206 u32 *p_eth_proto_cap, u32 *p_eth_proto_admin,
3207 u32 *p_eth_proto_oper)
3209 mlxsw_reg_ptys_ext_eth_unpack(payload, p_eth_proto_cap,
3210 p_eth_proto_admin, p_eth_proto_oper);
3213 static const struct mlxsw_sp_port_type_speed_ops
3214 mlxsw_sp2_port_type_speed_ops = {
3215 .from_ptys_supported_port = mlxsw_sp2_from_ptys_supported_port,
3216 .from_ptys_link = mlxsw_sp2_from_ptys_link,
3217 .from_ptys_speed = mlxsw_sp2_from_ptys_speed,
3218 .from_ptys_speed_duplex = mlxsw_sp2_from_ptys_speed_duplex,
3219 .to_ptys_advert_link = mlxsw_sp2_to_ptys_advert_link,
3220 .to_ptys_speed = mlxsw_sp2_to_ptys_speed,
3221 .to_ptys_upper_speed = mlxsw_sp2_to_ptys_upper_speed,
3222 .port_speed_base = mlxsw_sp2_port_speed_base,
3223 .reg_ptys_eth_pack = mlxsw_sp2_reg_ptys_eth_pack,
3224 .reg_ptys_eth_unpack = mlxsw_sp2_reg_ptys_eth_unpack,
3228 mlxsw_sp_port_get_link_supported(struct mlxsw_sp *mlxsw_sp, u32 eth_proto_cap,
3229 u8 width, struct ethtool_link_ksettings *cmd)
3231 const struct mlxsw_sp_port_type_speed_ops *ops;
3233 ops = mlxsw_sp->port_type_speed_ops;
3235 ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
3236 ethtool_link_ksettings_add_link_mode(cmd, supported, Autoneg);
3237 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
3239 ops->from_ptys_supported_port(mlxsw_sp, eth_proto_cap, cmd);
3240 ops->from_ptys_link(mlxsw_sp, eth_proto_cap, width,
3241 cmd->link_modes.supported);
3245 mlxsw_sp_port_get_link_advertise(struct mlxsw_sp *mlxsw_sp,
3246 u32 eth_proto_admin, bool autoneg, u8 width,
3247 struct ethtool_link_ksettings *cmd)
3249 const struct mlxsw_sp_port_type_speed_ops *ops;
3251 ops = mlxsw_sp->port_type_speed_ops;
3256 ethtool_link_ksettings_add_link_mode(cmd, advertising, Autoneg);
3257 ops->from_ptys_link(mlxsw_sp, eth_proto_admin, width,
3258 cmd->link_modes.advertising);
3262 mlxsw_sp_port_connector_port(enum mlxsw_reg_ptys_connector_type connector_type)
3264 switch (connector_type) {
3265 case MLXSW_REG_PTYS_CONNECTOR_TYPE_UNKNOWN_OR_NO_CONNECTOR:
3267 case MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_NONE:
3269 case MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_TP:
3271 case MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_AUI:
3273 case MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_BNC:
3275 case MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_MII:
3277 case MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_FIBRE:
3279 case MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_DA:
3281 case MLXSW_REG_PTYS_CONNECTOR_TYPE_PORT_OTHER:
3289 static int mlxsw_sp_port_get_link_ksettings(struct net_device *dev,
3290 struct ethtool_link_ksettings *cmd)
3292 u32 eth_proto_cap, eth_proto_admin, eth_proto_oper;
3293 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
3294 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3295 const struct mlxsw_sp_port_type_speed_ops *ops;
3296 char ptys_pl[MLXSW_REG_PTYS_LEN];
3301 ops = mlxsw_sp->port_type_speed_ops;
3303 autoneg = mlxsw_sp_port->link.autoneg;
3304 ops->reg_ptys_eth_pack(mlxsw_sp, ptys_pl, mlxsw_sp_port->local_port,
3306 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(ptys), ptys_pl);
3309 ops->reg_ptys_eth_unpack(mlxsw_sp, ptys_pl, ð_proto_cap,
3310 ð_proto_admin, ð_proto_oper);
3312 mlxsw_sp_port_get_link_supported(mlxsw_sp, eth_proto_cap,
3313 mlxsw_sp_port->mapping.width, cmd);
3315 mlxsw_sp_port_get_link_advertise(mlxsw_sp, eth_proto_admin, autoneg,
3316 mlxsw_sp_port->mapping.width, cmd);
3318 cmd->base.autoneg = autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;
3319 connector_type = mlxsw_reg_ptys_connector_type_get(ptys_pl);
3320 cmd->base.port = mlxsw_sp_port_connector_port(connector_type);
3321 ops->from_ptys_speed_duplex(mlxsw_sp, netif_carrier_ok(dev),
3322 eth_proto_oper, cmd);
3328 mlxsw_sp_port_set_link_ksettings(struct net_device *dev,
3329 const struct ethtool_link_ksettings *cmd)
3331 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
3332 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3333 const struct mlxsw_sp_port_type_speed_ops *ops;
3334 char ptys_pl[MLXSW_REG_PTYS_LEN];
3335 u32 eth_proto_cap, eth_proto_new;
3339 ops = mlxsw_sp->port_type_speed_ops;
3341 ops->reg_ptys_eth_pack(mlxsw_sp, ptys_pl, mlxsw_sp_port->local_port,
3343 err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(ptys), ptys_pl);
3346 ops->reg_ptys_eth_unpack(mlxsw_sp, ptys_pl, ð_proto_cap, NULL, NULL);
3348 autoneg = cmd->base.autoneg == AUTONEG_ENABLE;
3349 eth_proto_new = autoneg ?
3350 ops->to_ptys_advert_link(mlxsw_sp, mlxsw_sp_port->mapping.width,
3352 ops->to_ptys_speed(mlxsw_sp, mlxsw_sp_port->mapping.width,
3355 eth_proto_new = eth_proto_new & eth_proto_cap;
3356 if (!eth_proto_new) {
3357 netdev_err(dev, "No supported speed requested\n");
3361 ops->reg_ptys_eth_pack(mlxsw_sp, ptys_pl, mlxsw_sp_port->local_port,
3362 eth_proto_new, autoneg);
3363 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ptys), ptys_pl);
3367 mlxsw_sp_port->link.autoneg = autoneg;
3369 if (!netif_running(dev))
3372 mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false);
3373 mlxsw_sp_port_admin_status_set(mlxsw_sp_port, true);
3378 static int mlxsw_sp_get_module_info(struct net_device *netdev,
3379 struct ethtool_modinfo *modinfo)
3381 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev);
3382 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3385 err = mlxsw_env_get_module_info(mlxsw_sp->core,
3386 mlxsw_sp_port->mapping.module,
3392 static int mlxsw_sp_get_module_eeprom(struct net_device *netdev,
3393 struct ethtool_eeprom *ee,
3396 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev);
3397 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3400 err = mlxsw_env_get_module_eeprom(netdev, mlxsw_sp->core,
3401 mlxsw_sp_port->mapping.module, ee,
3408 mlxsw_sp_get_ts_info(struct net_device *netdev, struct ethtool_ts_info *info)
3410 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev);
3411 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3413 return mlxsw_sp->ptp_ops->get_ts_info(mlxsw_sp, info);
3416 static const struct ethtool_ops mlxsw_sp_port_ethtool_ops = {
3417 .get_drvinfo = mlxsw_sp_port_get_drvinfo,
3418 .get_link = ethtool_op_get_link,
3419 .get_pauseparam = mlxsw_sp_port_get_pauseparam,
3420 .set_pauseparam = mlxsw_sp_port_set_pauseparam,
3421 .get_strings = mlxsw_sp_port_get_strings,
3422 .set_phys_id = mlxsw_sp_port_set_phys_id,
3423 .get_ethtool_stats = mlxsw_sp_port_get_stats,
3424 .get_sset_count = mlxsw_sp_port_get_sset_count,
3425 .get_link_ksettings = mlxsw_sp_port_get_link_ksettings,
3426 .set_link_ksettings = mlxsw_sp_port_set_link_ksettings,
3427 .get_module_info = mlxsw_sp_get_module_info,
3428 .get_module_eeprom = mlxsw_sp_get_module_eeprom,
3429 .get_ts_info = mlxsw_sp_get_ts_info,
3433 mlxsw_sp_port_speed_by_width_set(struct mlxsw_sp_port *mlxsw_sp_port, u8 width)
3435 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3436 const struct mlxsw_sp_port_type_speed_ops *ops;
3437 char ptys_pl[MLXSW_REG_PTYS_LEN];
3438 u32 eth_proto_admin;
3443 ops = mlxsw_sp->port_type_speed_ops;
3445 err = ops->port_speed_base(mlxsw_sp, mlxsw_sp_port->local_port,
3449 upper_speed = base_speed * width;
3451 eth_proto_admin = ops->to_ptys_upper_speed(mlxsw_sp, upper_speed);
3452 ops->reg_ptys_eth_pack(mlxsw_sp, ptys_pl, mlxsw_sp_port->local_port,
3453 eth_proto_admin, mlxsw_sp_port->link.autoneg);
3454 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ptys), ptys_pl);
3457 int mlxsw_sp_port_ets_set(struct mlxsw_sp_port *mlxsw_sp_port,
3458 enum mlxsw_reg_qeec_hr hr, u8 index, u8 next_index,
3459 bool dwrr, u8 dwrr_weight)
3461 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3462 char qeec_pl[MLXSW_REG_QEEC_LEN];
3464 mlxsw_reg_qeec_pack(qeec_pl, mlxsw_sp_port->local_port, hr, index,
3466 mlxsw_reg_qeec_de_set(qeec_pl, true);
3467 mlxsw_reg_qeec_dwrr_set(qeec_pl, dwrr);
3468 mlxsw_reg_qeec_dwrr_weight_set(qeec_pl, dwrr_weight);
3469 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(qeec), qeec_pl);
3472 int mlxsw_sp_port_ets_maxrate_set(struct mlxsw_sp_port *mlxsw_sp_port,
3473 enum mlxsw_reg_qeec_hr hr, u8 index,
3474 u8 next_index, u32 maxrate)
3476 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3477 char qeec_pl[MLXSW_REG_QEEC_LEN];
3479 mlxsw_reg_qeec_pack(qeec_pl, mlxsw_sp_port->local_port, hr, index,
3481 mlxsw_reg_qeec_mase_set(qeec_pl, true);
3482 mlxsw_reg_qeec_max_shaper_rate_set(qeec_pl, maxrate);
3483 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(qeec), qeec_pl);
3486 static int mlxsw_sp_port_min_bw_set(struct mlxsw_sp_port *mlxsw_sp_port,
3487 enum mlxsw_reg_qeec_hr hr, u8 index,
3488 u8 next_index, u32 minrate)
3490 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3491 char qeec_pl[MLXSW_REG_QEEC_LEN];
3493 mlxsw_reg_qeec_pack(qeec_pl, mlxsw_sp_port->local_port, hr, index,
3495 mlxsw_reg_qeec_mise_set(qeec_pl, true);
3496 mlxsw_reg_qeec_min_shaper_rate_set(qeec_pl, minrate);
3498 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(qeec), qeec_pl);
3501 int mlxsw_sp_port_prio_tc_set(struct mlxsw_sp_port *mlxsw_sp_port,
3502 u8 switch_prio, u8 tclass)
3504 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3505 char qtct_pl[MLXSW_REG_QTCT_LEN];
3507 mlxsw_reg_qtct_pack(qtct_pl, mlxsw_sp_port->local_port, switch_prio,
3509 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(qtct), qtct_pl);
3512 static int mlxsw_sp_port_ets_init(struct mlxsw_sp_port *mlxsw_sp_port)
3516 /* Setup the elements hierarcy, so that each TC is linked to
3517 * one subgroup, which are all member in the same group.
3519 err = mlxsw_sp_port_ets_set(mlxsw_sp_port,
3520 MLXSW_REG_QEEC_HIERARCY_GROUP, 0, 0, false,
3524 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
3525 err = mlxsw_sp_port_ets_set(mlxsw_sp_port,
3526 MLXSW_REG_QEEC_HIERARCY_SUBGROUP, i,
3531 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
3532 err = mlxsw_sp_port_ets_set(mlxsw_sp_port,
3533 MLXSW_REG_QEEC_HIERARCY_TC, i, i,
3538 err = mlxsw_sp_port_ets_set(mlxsw_sp_port,
3539 MLXSW_REG_QEEC_HIERARCY_TC,
3546 /* Make sure the max shaper is disabled in all hierarchies that support
3547 * it. Note that this disables ptps (PTP shaper), but that is intended
3548 * for the initial configuration.
3550 err = mlxsw_sp_port_ets_maxrate_set(mlxsw_sp_port,
3551 MLXSW_REG_QEEC_HIERARCY_PORT, 0, 0,
3552 MLXSW_REG_QEEC_MAS_DIS);
3555 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
3556 err = mlxsw_sp_port_ets_maxrate_set(mlxsw_sp_port,
3557 MLXSW_REG_QEEC_HIERARCY_SUBGROUP,
3559 MLXSW_REG_QEEC_MAS_DIS);
3563 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
3564 err = mlxsw_sp_port_ets_maxrate_set(mlxsw_sp_port,
3565 MLXSW_REG_QEEC_HIERARCY_TC,
3567 MLXSW_REG_QEEC_MAS_DIS);
3571 err = mlxsw_sp_port_ets_maxrate_set(mlxsw_sp_port,
3572 MLXSW_REG_QEEC_HIERARCY_TC,
3574 MLXSW_REG_QEEC_MAS_DIS);
3579 /* Configure the min shaper for multicast TCs. */
3580 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
3581 err = mlxsw_sp_port_min_bw_set(mlxsw_sp_port,
3582 MLXSW_REG_QEEC_HIERARCY_TC,
3584 MLXSW_REG_QEEC_MIS_MIN);
3589 /* Map all priorities to traffic class 0. */
3590 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
3591 err = mlxsw_sp_port_prio_tc_set(mlxsw_sp_port, i, 0);
3599 static int mlxsw_sp_port_tc_mc_mode_set(struct mlxsw_sp_port *mlxsw_sp_port,
3602 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
3603 char qtctm_pl[MLXSW_REG_QTCTM_LEN];
3605 mlxsw_reg_qtctm_pack(qtctm_pl, mlxsw_sp_port->local_port, enable);
3606 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(qtctm), qtctm_pl);
3609 static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
3610 bool split, u8 module, u8 width, u8 lane)
3612 struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;
3613 struct mlxsw_sp_port *mlxsw_sp_port;
3614 struct net_device *dev;
3617 err = mlxsw_core_port_init(mlxsw_sp->core, local_port,
3618 module + 1, split, lane / width,
3620 sizeof(mlxsw_sp->base_mac));
3622 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to init core port\n",
3627 dev = alloc_etherdev(sizeof(struct mlxsw_sp_port));
3630 goto err_alloc_etherdev;
3632 SET_NETDEV_DEV(dev, mlxsw_sp->bus_info->dev);
3633 mlxsw_sp_port = netdev_priv(dev);
3634 mlxsw_sp_port->dev = dev;
3635 mlxsw_sp_port->mlxsw_sp = mlxsw_sp;
3636 mlxsw_sp_port->local_port = local_port;
3637 mlxsw_sp_port->pvid = MLXSW_SP_DEFAULT_VID;
3638 mlxsw_sp_port->split = split;
3639 mlxsw_sp_port->mapping.module = module;
3640 mlxsw_sp_port->mapping.width = width;
3641 mlxsw_sp_port->mapping.lane = lane;
3642 mlxsw_sp_port->link.autoneg = 1;
3643 INIT_LIST_HEAD(&mlxsw_sp_port->vlans_list);
3644 INIT_LIST_HEAD(&mlxsw_sp_port->mall_tc_list);
3646 mlxsw_sp_port->pcpu_stats =
3647 netdev_alloc_pcpu_stats(struct mlxsw_sp_port_pcpu_stats);
3648 if (!mlxsw_sp_port->pcpu_stats) {
3650 goto err_alloc_stats;
3653 mlxsw_sp_port->sample = kzalloc(sizeof(*mlxsw_sp_port->sample),
3655 if (!mlxsw_sp_port->sample) {
3657 goto err_alloc_sample;
3660 INIT_DELAYED_WORK(&mlxsw_sp_port->periodic_hw_stats.update_dw,
3661 &update_stats_cache);
3663 dev->netdev_ops = &mlxsw_sp_port_netdev_ops;
3664 dev->ethtool_ops = &mlxsw_sp_port_ethtool_ops;
3666 err = mlxsw_sp_port_module_map(mlxsw_sp_port, module, width, lane);
3668 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to map module\n",
3669 mlxsw_sp_port->local_port);
3670 goto err_port_module_map;
3673 err = mlxsw_sp_port_swid_set(mlxsw_sp_port, 0);
3675 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to set SWID\n",
3676 mlxsw_sp_port->local_port);
3677 goto err_port_swid_set;
3680 err = mlxsw_sp_port_dev_addr_init(mlxsw_sp_port);
3682 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Unable to init port mac address\n",
3683 mlxsw_sp_port->local_port);
3684 goto err_dev_addr_init;
3687 netif_carrier_off(dev);
3689 dev->features |= NETIF_F_NETNS_LOCAL | NETIF_F_LLTX | NETIF_F_SG |
3690 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_TC;
3691 dev->hw_features |= NETIF_F_HW_TC | NETIF_F_LOOPBACK;
3694 dev->max_mtu = ETH_MAX_MTU;
3696 /* Each packet needs to have a Tx header (metadata) on top all other
3699 dev->needed_headroom = MLXSW_TXHDR_LEN;
3701 err = mlxsw_sp_port_system_port_mapping_set(mlxsw_sp_port);
3703 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to set system port mapping\n",
3704 mlxsw_sp_port->local_port);
3705 goto err_port_system_port_mapping_set;
3708 err = mlxsw_sp_port_speed_by_width_set(mlxsw_sp_port, width);
3710 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to enable speeds\n",
3711 mlxsw_sp_port->local_port);
3712 goto err_port_speed_by_width_set;
3715 err = mlxsw_sp_port_mtu_set(mlxsw_sp_port, ETH_DATA_LEN);
3717 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to set MTU\n",
3718 mlxsw_sp_port->local_port);
3719 goto err_port_mtu_set;
3722 err = mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false);
3724 goto err_port_admin_status_set;
3726 err = mlxsw_sp_port_buffers_init(mlxsw_sp_port);
3728 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to initialize buffers\n",
3729 mlxsw_sp_port->local_port);
3730 goto err_port_buffers_init;
3733 err = mlxsw_sp_port_ets_init(mlxsw_sp_port);
3735 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to initialize ETS\n",
3736 mlxsw_sp_port->local_port);
3737 goto err_port_ets_init;
3740 err = mlxsw_sp_port_tc_mc_mode_set(mlxsw_sp_port, true);
3742 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to initialize TC MC mode\n",
3743 mlxsw_sp_port->local_port);
3744 goto err_port_tc_mc_mode;
3747 /* ETS and buffers must be initialized before DCB. */
3748 err = mlxsw_sp_port_dcb_init(mlxsw_sp_port);
3750 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to initialize DCB\n",
3751 mlxsw_sp_port->local_port);
3752 goto err_port_dcb_init;
3755 err = mlxsw_sp_port_fids_init(mlxsw_sp_port);
3757 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to initialize FIDs\n",
3758 mlxsw_sp_port->local_port);
3759 goto err_port_fids_init;
3762 err = mlxsw_sp_tc_qdisc_init(mlxsw_sp_port);
3764 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to initialize TC qdiscs\n",
3765 mlxsw_sp_port->local_port);
3766 goto err_port_qdiscs_init;
3769 err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, 0, VLAN_N_VID - 1, false,
3772 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to clear VLAN filter\n",
3773 mlxsw_sp_port->local_port);
3774 goto err_port_vlan_clear;
3777 err = mlxsw_sp_port_nve_init(mlxsw_sp_port);
3779 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to initialize NVE\n",
3780 mlxsw_sp_port->local_port);
3781 goto err_port_nve_init;
3784 err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, MLXSW_SP_DEFAULT_VID);
3786 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to set PVID\n",
3787 mlxsw_sp_port->local_port);
3788 goto err_port_pvid_set;
3791 mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_create(mlxsw_sp_port,
3792 MLXSW_SP_DEFAULT_VID);
3793 if (IS_ERR(mlxsw_sp_port_vlan)) {
3794 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to create VID 1\n",
3795 mlxsw_sp_port->local_port);
3796 err = PTR_ERR(mlxsw_sp_port_vlan);
3797 goto err_port_vlan_create;
3799 mlxsw_sp_port->default_vlan = mlxsw_sp_port_vlan;
3801 INIT_DELAYED_WORK(&mlxsw_sp_port->ptp.shaper_dw,
3802 mlxsw_sp->ptp_ops->shaper_work);
3804 mlxsw_sp->ports[local_port] = mlxsw_sp_port;
3805 err = register_netdev(dev);
3807 dev_err(mlxsw_sp->bus_info->dev, "Port %d: Failed to register netdev\n",
3808 mlxsw_sp_port->local_port);
3809 goto err_register_netdev;
3812 mlxsw_core_port_eth_set(mlxsw_sp->core, mlxsw_sp_port->local_port,
3813 mlxsw_sp_port, dev);
3814 mlxsw_core_schedule_dw(&mlxsw_sp_port->periodic_hw_stats.update_dw, 0);
3817 err_register_netdev:
3818 mlxsw_sp->ports[local_port] = NULL;
3819 mlxsw_sp_port_vlan_destroy(mlxsw_sp_port_vlan);
3820 err_port_vlan_create:
3822 mlxsw_sp_port_nve_fini(mlxsw_sp_port);
3824 err_port_vlan_clear:
3825 mlxsw_sp_tc_qdisc_fini(mlxsw_sp_port);
3826 err_port_qdiscs_init:
3827 mlxsw_sp_port_fids_fini(mlxsw_sp_port);
3829 mlxsw_sp_port_dcb_fini(mlxsw_sp_port);
3831 mlxsw_sp_port_tc_mc_mode_set(mlxsw_sp_port, false);
3832 err_port_tc_mc_mode:
3834 err_port_buffers_init:
3835 err_port_admin_status_set:
3837 err_port_speed_by_width_set:
3838 err_port_system_port_mapping_set:
3840 mlxsw_sp_port_swid_set(mlxsw_sp_port, MLXSW_PORT_SWID_DISABLED_PORT);
3842 mlxsw_sp_port_module_unmap(mlxsw_sp_port);
3843 err_port_module_map:
3844 kfree(mlxsw_sp_port->sample);
3846 free_percpu(mlxsw_sp_port->pcpu_stats);
3850 mlxsw_core_port_fini(mlxsw_sp->core, local_port);
3854 static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u8 local_port)
3856 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
3858 cancel_delayed_work_sync(&mlxsw_sp_port->periodic_hw_stats.update_dw);
3859 cancel_delayed_work_sync(&mlxsw_sp_port->ptp.shaper_dw);
3860 mlxsw_sp_port_ptp_clear(mlxsw_sp_port);
3861 mlxsw_core_port_clear(mlxsw_sp->core, local_port, mlxsw_sp);
3862 unregister_netdev(mlxsw_sp_port->dev); /* This calls ndo_stop */
3863 mlxsw_sp->ports[local_port] = NULL;
3864 mlxsw_sp_port_vlan_flush(mlxsw_sp_port, true);
3865 mlxsw_sp_port_nve_fini(mlxsw_sp_port);
3866 mlxsw_sp_tc_qdisc_fini(mlxsw_sp_port);
3867 mlxsw_sp_port_fids_fini(mlxsw_sp_port);
3868 mlxsw_sp_port_dcb_fini(mlxsw_sp_port);
3869 mlxsw_sp_port_tc_mc_mode_set(mlxsw_sp_port, false);
3870 mlxsw_sp_port_swid_set(mlxsw_sp_port, MLXSW_PORT_SWID_DISABLED_PORT);
3871 mlxsw_sp_port_module_unmap(mlxsw_sp_port);
3872 kfree(mlxsw_sp_port->sample);
3873 free_percpu(mlxsw_sp_port->pcpu_stats);
3874 WARN_ON_ONCE(!list_empty(&mlxsw_sp_port->vlans_list));
3875 free_netdev(mlxsw_sp_port->dev);
3876 mlxsw_core_port_fini(mlxsw_sp->core, local_port);
3879 static int mlxsw_sp_cpu_port_create(struct mlxsw_sp *mlxsw_sp)
3881 struct mlxsw_sp_port *mlxsw_sp_port;
3884 mlxsw_sp_port = kzalloc(sizeof(*mlxsw_sp_port), GFP_KERNEL);
3888 mlxsw_sp_port->mlxsw_sp = mlxsw_sp;
3889 mlxsw_sp_port->local_port = MLXSW_PORT_CPU_PORT;
3891 err = mlxsw_core_cpu_port_init(mlxsw_sp->core,
3894 sizeof(mlxsw_sp->base_mac));
3896 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize core CPU port\n");
3897 goto err_core_cpu_port_init;
3900 mlxsw_sp->ports[MLXSW_PORT_CPU_PORT] = mlxsw_sp_port;
3903 err_core_cpu_port_init:
3904 kfree(mlxsw_sp_port);
3908 static void mlxsw_sp_cpu_port_remove(struct mlxsw_sp *mlxsw_sp)
3910 struct mlxsw_sp_port *mlxsw_sp_port =
3911 mlxsw_sp->ports[MLXSW_PORT_CPU_PORT];
3913 mlxsw_core_cpu_port_fini(mlxsw_sp->core);
3914 mlxsw_sp->ports[MLXSW_PORT_CPU_PORT] = NULL;
3915 kfree(mlxsw_sp_port);
3918 static bool mlxsw_sp_port_created(struct mlxsw_sp *mlxsw_sp, u8 local_port)
3920 return mlxsw_sp->ports[local_port] != NULL;
3923 static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
3927 for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++)
3928 if (mlxsw_sp_port_created(mlxsw_sp, i))
3929 mlxsw_sp_port_remove(mlxsw_sp, i);
3930 mlxsw_sp_cpu_port_remove(mlxsw_sp);
3931 kfree(mlxsw_sp->port_to_module);
3932 kfree(mlxsw_sp->ports);
3933 mlxsw_sp->ports = NULL;
3936 static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
3938 unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
3939 u8 module, width, lane;
3944 alloc_size = sizeof(struct mlxsw_sp_port *) * max_ports;
3945 mlxsw_sp->ports = kzalloc(alloc_size, GFP_KERNEL);
3946 if (!mlxsw_sp->ports)
3949 mlxsw_sp->port_to_module = kmalloc_array(max_ports, sizeof(int),
3951 if (!mlxsw_sp->port_to_module) {
3953 goto err_port_to_module_alloc;
3956 err = mlxsw_sp_cpu_port_create(mlxsw_sp);
3958 goto err_cpu_port_create;
3960 for (i = 1; i < max_ports; i++) {
3961 /* Mark as invalid */
3962 mlxsw_sp->port_to_module[i] = -1;
3964 err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, &module,
3967 goto err_port_module_info_get;
3970 mlxsw_sp->port_to_module[i] = module;
3971 err = mlxsw_sp_port_create(mlxsw_sp, i, false,
3972 module, width, lane);
3974 goto err_port_create;
3979 err_port_module_info_get:
3980 for (i--; i >= 1; i--)
3981 if (mlxsw_sp_port_created(mlxsw_sp, i))
3982 mlxsw_sp_port_remove(mlxsw_sp, i);
3983 mlxsw_sp_cpu_port_remove(mlxsw_sp);
3984 err_cpu_port_create:
3985 kfree(mlxsw_sp->port_to_module);
3986 err_port_to_module_alloc:
3987 kfree(mlxsw_sp->ports);
3988 mlxsw_sp->ports = NULL;
3992 static u8 mlxsw_sp_cluster_base_port_get(u8 local_port)
3994 u8 offset = (local_port - 1) % MLXSW_SP_PORTS_PER_CLUSTER_MAX;
3996 return local_port - offset;
3999 static int mlxsw_sp_port_split_create(struct mlxsw_sp *mlxsw_sp, u8 base_port,
4000 u8 module, unsigned int count, u8 offset)
4002 u8 width = MLXSW_PORT_MODULE_MAX_WIDTH / count;
4005 for (i = 0; i < count; i++) {
4006 err = mlxsw_sp_port_create(mlxsw_sp, base_port + i * offset,
4007 true, module, width, i * width);
4009 goto err_port_create;
4015 for (i--; i >= 0; i--)
4016 if (mlxsw_sp_port_created(mlxsw_sp, base_port + i * offset))
4017 mlxsw_sp_port_remove(mlxsw_sp, base_port + i * offset);
4021 static void mlxsw_sp_port_unsplit_create(struct mlxsw_sp *mlxsw_sp,
4022 u8 base_port, unsigned int count)
4024 u8 local_port, module, width = MLXSW_PORT_MODULE_MAX_WIDTH;
4027 /* Split by four means we need to re-create two ports, otherwise
4032 for (i = 0; i < count; i++) {
4033 local_port = base_port + i * 2;
4034 if (mlxsw_sp->port_to_module[local_port] < 0)
4036 module = mlxsw_sp->port_to_module[local_port];
4038 mlxsw_sp_port_create(mlxsw_sp, local_port, false, module,
4043 static struct mlxsw_sp_port *
4044 mlxsw_sp_port_get_by_local_port(struct mlxsw_sp *mlxsw_sp, u8 local_port)
4046 if (mlxsw_sp->ports && mlxsw_sp->ports[local_port])
4047 return mlxsw_sp->ports[local_port];
4051 static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
4053 struct netlink_ext_ack *extack)
4055 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
4056 u8 local_ports_in_1x, local_ports_in_2x, offset;
4057 struct mlxsw_sp_port *mlxsw_sp_port;
4058 u8 module, cur_width, base_port;
4062 if (!MLXSW_CORE_RES_VALID(mlxsw_core, LOCAL_PORTS_IN_1X) ||
4063 !MLXSW_CORE_RES_VALID(mlxsw_core, LOCAL_PORTS_IN_2X))
4066 local_ports_in_1x = MLXSW_CORE_RES_GET(mlxsw_core, LOCAL_PORTS_IN_1X);
4067 local_ports_in_2x = MLXSW_CORE_RES_GET(mlxsw_core, LOCAL_PORTS_IN_2X);
4069 mlxsw_sp_port = mlxsw_sp_port_get_by_local_port(mlxsw_sp, local_port);
4070 if (!mlxsw_sp_port) {
4071 dev_err(mlxsw_sp->bus_info->dev, "Port number \"%d\" does not exist\n",
4073 NL_SET_ERR_MSG_MOD(extack, "Port number does not exist");
4077 module = mlxsw_sp_port->mapping.module;
4078 cur_width = mlxsw_sp_port->mapping.width;
4080 if (count != 2 && count != 4) {
4081 netdev_err(mlxsw_sp_port->dev, "Port can only be split into 2 or 4 ports\n");
4082 NL_SET_ERR_MSG_MOD(extack, "Port can only be split into 2 or 4 ports");
4086 if (cur_width != MLXSW_PORT_MODULE_MAX_WIDTH) {
4087 netdev_err(mlxsw_sp_port->dev, "Port cannot be split further\n");
4088 NL_SET_ERR_MSG_MOD(extack, "Port cannot be split further");
4092 /* Make sure we have enough slave (even) ports for the split. */
4094 offset = local_ports_in_2x;
4095 base_port = local_port;
4096 if (mlxsw_sp->ports[base_port + local_ports_in_2x]) {
4097 netdev_err(mlxsw_sp_port->dev, "Invalid split configuration\n");
4098 NL_SET_ERR_MSG_MOD(extack, "Invalid split configuration");
4102 offset = local_ports_in_1x;
4103 base_port = mlxsw_sp_cluster_base_port_get(local_port);
4104 if (mlxsw_sp->ports[base_port + 1] ||
4105 mlxsw_sp->ports[base_port + 3]) {
4106 netdev_err(mlxsw_sp_port->dev, "Invalid split configuration\n");
4107 NL_SET_ERR_MSG_MOD(extack, "Invalid split configuration");
4112 for (i = 0; i < count; i++)
4113 if (mlxsw_sp_port_created(mlxsw_sp, base_port + i * offset))
4114 mlxsw_sp_port_remove(mlxsw_sp, base_port + i * offset);
4116 err = mlxsw_sp_port_split_create(mlxsw_sp, base_port, module, count,
4119 dev_err(mlxsw_sp->bus_info->dev, "Failed to create split ports\n");
4120 goto err_port_split_create;
4125 err_port_split_create:
4126 mlxsw_sp_port_unsplit_create(mlxsw_sp, base_port, count);
4130 static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port,
4131 struct netlink_ext_ack *extack)
4133 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
4134 u8 local_ports_in_1x, local_ports_in_2x, offset;
4135 struct mlxsw_sp_port *mlxsw_sp_port;
4136 u8 cur_width, base_port;
4140 if (!MLXSW_CORE_RES_VALID(mlxsw_core, LOCAL_PORTS_IN_1X) ||
4141 !MLXSW_CORE_RES_VALID(mlxsw_core, LOCAL_PORTS_IN_2X))
4144 local_ports_in_1x = MLXSW_CORE_RES_GET(mlxsw_core, LOCAL_PORTS_IN_1X);
4145 local_ports_in_2x = MLXSW_CORE_RES_GET(mlxsw_core, LOCAL_PORTS_IN_2X);
4147 mlxsw_sp_port = mlxsw_sp_port_get_by_local_port(mlxsw_sp, local_port);
4148 if (!mlxsw_sp_port) {
4149 dev_err(mlxsw_sp->bus_info->dev, "Port number \"%d\" does not exist\n",
4151 NL_SET_ERR_MSG_MOD(extack, "Port number does not exist");
4155 if (!mlxsw_sp_port->split) {
4156 netdev_err(mlxsw_sp_port->dev, "Port was not split\n");
4157 NL_SET_ERR_MSG_MOD(extack, "Port was not split");
4161 cur_width = mlxsw_sp_port->mapping.width;
4162 count = cur_width == 1 ? 4 : 2;
4165 offset = local_ports_in_2x;
4167 offset = local_ports_in_1x;
4169 base_port = mlxsw_sp_cluster_base_port_get(local_port);
4171 /* Determine which ports to remove. */
4172 if (count == 2 && local_port >= base_port + 2)
4173 base_port = base_port + 2;
4175 for (i = 0; i < count; i++)
4176 if (mlxsw_sp_port_created(mlxsw_sp, base_port + i * offset))
4177 mlxsw_sp_port_remove(mlxsw_sp, base_port + i * offset);
4179 mlxsw_sp_port_unsplit_create(mlxsw_sp, base_port, count);
4185 mlxsw_sp_port_down_wipe_counters(struct mlxsw_sp_port *mlxsw_sp_port)
4189 for (i = 0; i < TC_MAX_QUEUE; i++)
4190 mlxsw_sp_port->periodic_hw_stats.xstats.backlog[i] = 0;
4193 static void mlxsw_sp_pude_event_func(const struct mlxsw_reg_info *reg,
4194 char *pude_pl, void *priv)
4196 struct mlxsw_sp *mlxsw_sp = priv;
4197 struct mlxsw_sp_port *mlxsw_sp_port;
4198 enum mlxsw_reg_pude_oper_status status;
4201 local_port = mlxsw_reg_pude_local_port_get(pude_pl);
4202 mlxsw_sp_port = mlxsw_sp->ports[local_port];
4206 status = mlxsw_reg_pude_oper_status_get(pude_pl);
4207 if (status == MLXSW_PORT_OPER_STATUS_UP) {
4208 netdev_info(mlxsw_sp_port->dev, "link up\n");
4209 netif_carrier_on(mlxsw_sp_port->dev);
4210 mlxsw_core_schedule_dw(&mlxsw_sp_port->ptp.shaper_dw, 0);
4212 netdev_info(mlxsw_sp_port->dev, "link down\n");
4213 netif_carrier_off(mlxsw_sp_port->dev);
4214 mlxsw_sp_port_down_wipe_counters(mlxsw_sp_port);
4218 static void mlxsw_sp1_ptp_fifo_event_func(struct mlxsw_sp *mlxsw_sp,
4219 char *mtpptr_pl, bool ingress)
4225 local_port = mlxsw_reg_mtpptr_local_port_get(mtpptr_pl);
4226 num_rec = mlxsw_reg_mtpptr_num_rec_get(mtpptr_pl);
4227 for (i = 0; i < num_rec; i++) {
4233 mlxsw_reg_mtpptr_unpack(mtpptr_pl, i, &message_type,
4234 &domain_number, &sequence_id,
4236 mlxsw_sp1_ptp_got_timestamp(mlxsw_sp, ingress, local_port,
4237 message_type, domain_number,
4238 sequence_id, timestamp);
4242 static void mlxsw_sp1_ptp_ing_fifo_event_func(const struct mlxsw_reg_info *reg,
4243 char *mtpptr_pl, void *priv)
4245 struct mlxsw_sp *mlxsw_sp = priv;
4247 mlxsw_sp1_ptp_fifo_event_func(mlxsw_sp, mtpptr_pl, true);
4250 static void mlxsw_sp1_ptp_egr_fifo_event_func(const struct mlxsw_reg_info *reg,
4251 char *mtpptr_pl, void *priv)
4253 struct mlxsw_sp *mlxsw_sp = priv;
4255 mlxsw_sp1_ptp_fifo_event_func(mlxsw_sp, mtpptr_pl, false);
4258 void mlxsw_sp_rx_listener_no_mark_func(struct sk_buff *skb,
4259 u8 local_port, void *priv)
4261 struct mlxsw_sp *mlxsw_sp = priv;
4262 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
4263 struct mlxsw_sp_port_pcpu_stats *pcpu_stats;
4265 if (unlikely(!mlxsw_sp_port)) {
4266 dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: skb received for non-existent port\n",
4271 skb->dev = mlxsw_sp_port->dev;
4273 pcpu_stats = this_cpu_ptr(mlxsw_sp_port->pcpu_stats);
4274 u64_stats_update_begin(&pcpu_stats->syncp);
4275 pcpu_stats->rx_packets++;
4276 pcpu_stats->rx_bytes += skb->len;
4277 u64_stats_update_end(&pcpu_stats->syncp);
4279 skb->protocol = eth_type_trans(skb, skb->dev);
4280 netif_receive_skb(skb);
4283 static void mlxsw_sp_rx_listener_mark_func(struct sk_buff *skb, u8 local_port,
4286 skb->offload_fwd_mark = 1;
4287 return mlxsw_sp_rx_listener_no_mark_func(skb, local_port, priv);
4290 static void mlxsw_sp_rx_listener_l3_mark_func(struct sk_buff *skb,
4291 u8 local_port, void *priv)
4293 skb->offload_l3_fwd_mark = 1;
4294 skb->offload_fwd_mark = 1;
4295 return mlxsw_sp_rx_listener_no_mark_func(skb, local_port, priv);
4298 static void mlxsw_sp_rx_listener_sample_func(struct sk_buff *skb, u8 local_port,
4301 struct mlxsw_sp *mlxsw_sp = priv;
4302 struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port];
4303 struct psample_group *psample_group;
4306 if (unlikely(!mlxsw_sp_port)) {
4307 dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: sample skb received for non-existent port\n",
4311 if (unlikely(!mlxsw_sp_port->sample)) {
4312 dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: sample skb received on unsupported port\n",
4317 size = mlxsw_sp_port->sample->truncate ?
4318 mlxsw_sp_port->sample->trunc_size : skb->len;
4321 psample_group = rcu_dereference(mlxsw_sp_port->sample->psample_group);
4324 psample_sample_packet(psample_group, skb, size,
4325 mlxsw_sp_port->dev->ifindex, 0,
4326 mlxsw_sp_port->sample->rate);
4333 static void mlxsw_sp_rx_listener_ptp(struct sk_buff *skb, u8 local_port,
4336 struct mlxsw_sp *mlxsw_sp = priv;
4338 mlxsw_sp->ptp_ops->receive(mlxsw_sp, skb, local_port);
4341 #define MLXSW_SP_RXL_NO_MARK(_trap_id, _action, _trap_group, _is_ctrl) \
4342 MLXSW_RXL(mlxsw_sp_rx_listener_no_mark_func, _trap_id, _action, \
4343 _is_ctrl, SP_##_trap_group, DISCARD)
4345 #define MLXSW_SP_RXL_MARK(_trap_id, _action, _trap_group, _is_ctrl) \
4346 MLXSW_RXL(mlxsw_sp_rx_listener_mark_func, _trap_id, _action, \
4347 _is_ctrl, SP_##_trap_group, DISCARD)
4349 #define MLXSW_SP_RXL_L3_MARK(_trap_id, _action, _trap_group, _is_ctrl) \
4350 MLXSW_RXL(mlxsw_sp_rx_listener_l3_mark_func, _trap_id, _action, \
4351 _is_ctrl, SP_##_trap_group, DISCARD)
4353 #define MLXSW_SP_EVENTL(_func, _trap_id) \
4354 MLXSW_EVENTL(_func, _trap_id, SP_EVENT)
4356 static const struct mlxsw_listener mlxsw_sp_listener[] = {
4358 MLXSW_SP_EVENTL(mlxsw_sp_pude_event_func, PUDE),
4360 MLXSW_SP_RXL_NO_MARK(STP, TRAP_TO_CPU, STP, true),
4361 MLXSW_SP_RXL_NO_MARK(LACP, TRAP_TO_CPU, LACP, true),
4362 MLXSW_RXL(mlxsw_sp_rx_listener_ptp, LLDP, TRAP_TO_CPU,
4363 false, SP_LLDP, DISCARD),
4364 MLXSW_SP_RXL_MARK(DHCP, MIRROR_TO_CPU, DHCP, false),
4365 MLXSW_SP_RXL_MARK(IGMP_QUERY, MIRROR_TO_CPU, IGMP, false),
4366 MLXSW_SP_RXL_NO_MARK(IGMP_V1_REPORT, TRAP_TO_CPU, IGMP, false),
4367 MLXSW_SP_RXL_NO_MARK(IGMP_V2_REPORT, TRAP_TO_CPU, IGMP, false),
4368 MLXSW_SP_RXL_NO_MARK(IGMP_V2_LEAVE, TRAP_TO_CPU, IGMP, false),
4369 MLXSW_SP_RXL_NO_MARK(IGMP_V3_REPORT, TRAP_TO_CPU, IGMP, false),
4370 MLXSW_SP_RXL_MARK(ARPBC, MIRROR_TO_CPU, ARP, false),
4371 MLXSW_SP_RXL_MARK(ARPUC, MIRROR_TO_CPU, ARP, false),
4372 MLXSW_SP_RXL_NO_MARK(FID_MISS, TRAP_TO_CPU, IP2ME, false),
4373 MLXSW_SP_RXL_MARK(IPV6_MLDV12_LISTENER_QUERY, MIRROR_TO_CPU, IPV6_MLD,
4375 MLXSW_SP_RXL_NO_MARK(IPV6_MLDV1_LISTENER_REPORT, TRAP_TO_CPU, IPV6_MLD,
4377 MLXSW_SP_RXL_NO_MARK(IPV6_MLDV1_LISTENER_DONE, TRAP_TO_CPU, IPV6_MLD,
4379 MLXSW_SP_RXL_NO_MARK(IPV6_MLDV2_LISTENER_REPORT, TRAP_TO_CPU, IPV6_MLD,
4382 MLXSW_SP_RXL_MARK(MTUERROR, TRAP_TO_CPU, ROUTER_EXP, false),
4383 MLXSW_SP_RXL_MARK(TTLERROR, TRAP_TO_CPU, ROUTER_EXP, false),
4384 MLXSW_SP_RXL_L3_MARK(LBERROR, MIRROR_TO_CPU, LBERROR, false),
4385 MLXSW_SP_RXL_MARK(IP2ME, TRAP_TO_CPU, IP2ME, false),
4386 MLXSW_SP_RXL_MARK(IPV6_UNSPECIFIED_ADDRESS, TRAP_TO_CPU, ROUTER_EXP,
4388 MLXSW_SP_RXL_MARK(IPV6_LINK_LOCAL_DEST, TRAP_TO_CPU, ROUTER_EXP, false),
4389 MLXSW_SP_RXL_MARK(IPV6_LINK_LOCAL_SRC, TRAP_TO_CPU, ROUTER_EXP, false),
4390 MLXSW_SP_RXL_MARK(IPV6_ALL_NODES_LINK, TRAP_TO_CPU, ROUTER_EXP, false),
4391 MLXSW_SP_RXL_MARK(IPV6_ALL_ROUTERS_LINK, TRAP_TO_CPU, ROUTER_EXP,
4393 MLXSW_SP_RXL_MARK(IPV4_OSPF, TRAP_TO_CPU, OSPF, false),
4394 MLXSW_SP_RXL_MARK(IPV6_OSPF, TRAP_TO_CPU, OSPF, false),
4395 MLXSW_SP_RXL_MARK(IPV6_DHCP, TRAP_TO_CPU, DHCP, false),
4396 MLXSW_SP_RXL_MARK(RTR_INGRESS0, TRAP_TO_CPU, REMOTE_ROUTE, false),
4397 MLXSW_SP_RXL_MARK(IPV4_BGP, TRAP_TO_CPU, BGP, false),
4398 MLXSW_SP_RXL_MARK(IPV6_BGP, TRAP_TO_CPU, BGP, false),
4399 MLXSW_SP_RXL_MARK(L3_IPV6_ROUTER_SOLICITATION, TRAP_TO_CPU, IPV6_ND,
4401 MLXSW_SP_RXL_MARK(L3_IPV6_ROUTER_ADVERTISMENT, TRAP_TO_CPU, IPV6_ND,
4403 MLXSW_SP_RXL_MARK(L3_IPV6_NEIGHBOR_SOLICITATION, TRAP_TO_CPU, IPV6_ND,
4405 MLXSW_SP_RXL_MARK(L3_IPV6_NEIGHBOR_ADVERTISMENT, TRAP_TO_CPU, IPV6_ND,
4407 MLXSW_SP_RXL_MARK(L3_IPV6_REDIRECTION, TRAP_TO_CPU, IPV6_ND, false),
4408 MLXSW_SP_RXL_MARK(IPV6_MC_LINK_LOCAL_DEST, TRAP_TO_CPU, ROUTER_EXP,
4410 MLXSW_SP_RXL_MARK(HOST_MISS_IPV4, TRAP_TO_CPU, HOST_MISS, false),
4411 MLXSW_SP_RXL_MARK(HOST_MISS_IPV6, TRAP_TO_CPU, HOST_MISS, false),
4412 MLXSW_SP_RXL_MARK(ROUTER_ALERT_IPV4, TRAP_TO_CPU, ROUTER_EXP, false),
4413 MLXSW_SP_RXL_MARK(ROUTER_ALERT_IPV6, TRAP_TO_CPU, ROUTER_EXP, false),
4414 MLXSW_SP_RXL_MARK(IPIP_DECAP_ERROR, TRAP_TO_CPU, ROUTER_EXP, false),
4415 MLXSW_SP_RXL_MARK(DECAP_ECN0, TRAP_TO_CPU, ROUTER_EXP, false),
4416 MLXSW_SP_RXL_MARK(IPV4_VRRP, TRAP_TO_CPU, VRRP, false),
4417 MLXSW_SP_RXL_MARK(IPV6_VRRP, TRAP_TO_CPU, VRRP, false),
4418 /* PKT Sample trap */
4419 MLXSW_RXL(mlxsw_sp_rx_listener_sample_func, PKT_SAMPLE, MIRROR_TO_CPU,
4420 false, SP_IP2ME, DISCARD),
4422 MLXSW_SP_RXL_NO_MARK(ACL0, TRAP_TO_CPU, IP2ME, false),
4423 /* Multicast Router Traps */
4424 MLXSW_SP_RXL_MARK(IPV4_PIM, TRAP_TO_CPU, PIM, false),
4425 MLXSW_SP_RXL_MARK(IPV6_PIM, TRAP_TO_CPU, PIM, false),
4426 MLXSW_SP_RXL_MARK(RPF, TRAP_TO_CPU, RPF, false),
4427 MLXSW_SP_RXL_MARK(ACL1, TRAP_TO_CPU, MULTICAST, false),
4428 MLXSW_SP_RXL_L3_MARK(ACL2, TRAP_TO_CPU, MULTICAST, false),
4430 MLXSW_SP_RXL_MARK(NVE_ENCAP_ARP, TRAP_TO_CPU, ARP, false),
4431 MLXSW_SP_RXL_NO_MARK(NVE_DECAP_ARP, TRAP_TO_CPU, ARP, false),
4433 MLXSW_RXL(mlxsw_sp_rx_listener_ptp, PTP0, TRAP_TO_CPU,
4434 false, SP_PTP0, DISCARD),
4435 MLXSW_SP_RXL_NO_MARK(PTP1, TRAP_TO_CPU, PTP1, false),
4438 static const struct mlxsw_listener mlxsw_sp1_listener[] = {
4440 MLXSW_EVENTL(mlxsw_sp1_ptp_egr_fifo_event_func, PTP_EGR_FIFO, SP_PTP0),
4441 MLXSW_EVENTL(mlxsw_sp1_ptp_ing_fifo_event_func, PTP_ING_FIFO, SP_PTP0),
4444 static int mlxsw_sp_cpu_policers_set(struct mlxsw_core *mlxsw_core)
4446 char qpcr_pl[MLXSW_REG_QPCR_LEN];
4447 enum mlxsw_reg_qpcr_ir_units ir_units;
4448 int max_cpu_policers;
4454 if (!MLXSW_CORE_RES_VALID(mlxsw_core, MAX_CPU_POLICERS))
4457 max_cpu_policers = MLXSW_CORE_RES_GET(mlxsw_core, MAX_CPU_POLICERS);
4459 ir_units = MLXSW_REG_QPCR_IR_UNITS_M;
4460 for (i = 0; i < max_cpu_policers; i++) {
4463 case MLXSW_REG_HTGT_TRAP_GROUP_SP_STP:
4464 case MLXSW_REG_HTGT_TRAP_GROUP_SP_LACP:
4465 case MLXSW_REG_HTGT_TRAP_GROUP_SP_LLDP:
4466 case MLXSW_REG_HTGT_TRAP_GROUP_SP_OSPF:
4467 case MLXSW_REG_HTGT_TRAP_GROUP_SP_PIM:
4468 case MLXSW_REG_HTGT_TRAP_GROUP_SP_RPF:
4469 case MLXSW_REG_HTGT_TRAP_GROUP_SP_LBERROR:
4473 case MLXSW_REG_HTGT_TRAP_GROUP_SP_IGMP:
4474 case MLXSW_REG_HTGT_TRAP_GROUP_SP_IPV6_MLD:
4478 case MLXSW_REG_HTGT_TRAP_GROUP_SP_BGP:
4479 case MLXSW_REG_HTGT_TRAP_GROUP_SP_ARP:
4480 case MLXSW_REG_HTGT_TRAP_GROUP_SP_DHCP:
4481 case MLXSW_REG_HTGT_TRAP_GROUP_SP_HOST_MISS:
4482 case MLXSW_REG_HTGT_TRAP_GROUP_SP_ROUTER_EXP:
4483 case MLXSW_REG_HTGT_TRAP_GROUP_SP_REMOTE_ROUTE:
4484 case MLXSW_REG_HTGT_TRAP_GROUP_SP_IPV6_ND:
4485 case MLXSW_REG_HTGT_TRAP_GROUP_SP_MULTICAST:
4489 case MLXSW_REG_HTGT_TRAP_GROUP_SP_IP2ME:
4493 case MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP0:
4497 case MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP1:
4501 case MLXSW_REG_HTGT_TRAP_GROUP_SP_VRRP:
4509 mlxsw_reg_qpcr_pack(qpcr_pl, i, ir_units, is_bytes, rate,
4511 err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(qpcr), qpcr_pl);
4519 static int mlxsw_sp_trap_groups_set(struct mlxsw_core *mlxsw_core)
4521 char htgt_pl[MLXSW_REG_HTGT_LEN];
4522 enum mlxsw_reg_htgt_trap_group i;
4523 int max_cpu_policers;
4524 int max_trap_groups;
4529 if (!MLXSW_CORE_RES_VALID(mlxsw_core, MAX_TRAP_GROUPS))
4532 max_trap_groups = MLXSW_CORE_RES_GET(mlxsw_core, MAX_TRAP_GROUPS);
4533 max_cpu_policers = MLXSW_CORE_RES_GET(mlxsw_core, MAX_CPU_POLICERS);
4535 for (i = 0; i < max_trap_groups; i++) {
4538 case MLXSW_REG_HTGT_TRAP_GROUP_SP_STP:
4539 case MLXSW_REG_HTGT_TRAP_GROUP_SP_LACP:
4540 case MLXSW_REG_HTGT_TRAP_GROUP_SP_LLDP:
4541 case MLXSW_REG_HTGT_TRAP_GROUP_SP_OSPF:
4542 case MLXSW_REG_HTGT_TRAP_GROUP_SP_PIM:
4543 case MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP0:
4544 case MLXSW_REG_HTGT_TRAP_GROUP_SP_VRRP:
4548 case MLXSW_REG_HTGT_TRAP_GROUP_SP_BGP:
4549 case MLXSW_REG_HTGT_TRAP_GROUP_SP_DHCP:
4553 case MLXSW_REG_HTGT_TRAP_GROUP_SP_IGMP:
4554 case MLXSW_REG_HTGT_TRAP_GROUP_SP_IP2ME:
4555 case MLXSW_REG_HTGT_TRAP_GROUP_SP_IPV6_MLD:
4559 case MLXSW_REG_HTGT_TRAP_GROUP_SP_ARP:
4560 case MLXSW_REG_HTGT_TRAP_GROUP_SP_IPV6_ND:
4561 case MLXSW_REG_HTGT_TRAP_GROUP_SP_RPF:
4562 case MLXSW_REG_HTGT_TRAP_GROUP_SP_PTP1:
4566 case MLXSW_REG_HTGT_TRAP_GROUP_SP_HOST_MISS:
4567 case MLXSW_REG_HTGT_TRAP_GROUP_SP_ROUTER_EXP:
4568 case MLXSW_REG_HTGT_TRAP_GROUP_SP_REMOTE_ROUTE:
4569 case MLXSW_REG_HTGT_TRAP_GROUP_SP_MULTICAST:
4570 case MLXSW_REG_HTGT_TRAP_GROUP_SP_LBERROR:
4574 case MLXSW_REG_HTGT_TRAP_GROUP_SP_EVENT:
4575 priority = MLXSW_REG_HTGT_DEFAULT_PRIORITY;
4576 tc = MLXSW_REG_HTGT_DEFAULT_TC;
4577 policer_id = MLXSW_REG_HTGT_INVALID_POLICER;
4583 if (max_cpu_policers <= policer_id &&
4584 policer_id != MLXSW_REG_HTGT_INVALID_POLICER)
4587 mlxsw_reg_htgt_pack(htgt_pl, i, policer_id, priority, tc);
4588 err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
4596 static int mlxsw_sp_traps_register(struct mlxsw_sp *mlxsw_sp,
4597 const struct mlxsw_listener listeners[],
4598 size_t listeners_count)
4603 for (i = 0; i < listeners_count; i++) {
4604 err = mlxsw_core_trap_register(mlxsw_sp->core,
4608 goto err_listener_register;
4613 err_listener_register:
4614 for (i--; i >= 0; i--) {
4615 mlxsw_core_trap_unregister(mlxsw_sp->core,
4622 static void mlxsw_sp_traps_unregister(struct mlxsw_sp *mlxsw_sp,
4623 const struct mlxsw_listener listeners[],
4624 size_t listeners_count)
4628 for (i = 0; i < listeners_count; i++) {
4629 mlxsw_core_trap_unregister(mlxsw_sp->core,
4635 static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
4639 err = mlxsw_sp_cpu_policers_set(mlxsw_sp->core);
4643 err = mlxsw_sp_trap_groups_set(mlxsw_sp->core);
4647 err = mlxsw_sp_traps_register(mlxsw_sp, mlxsw_sp_listener,
4648 ARRAY_SIZE(mlxsw_sp_listener));
4652 err = mlxsw_sp_traps_register(mlxsw_sp, mlxsw_sp->listeners,
4653 mlxsw_sp->listeners_count);
4655 goto err_extra_traps_init;
4659 err_extra_traps_init:
4660 mlxsw_sp_traps_unregister(mlxsw_sp, mlxsw_sp_listener,
4661 ARRAY_SIZE(mlxsw_sp_listener));
4665 static void mlxsw_sp_traps_fini(struct mlxsw_sp *mlxsw_sp)
4667 mlxsw_sp_traps_unregister(mlxsw_sp, mlxsw_sp->listeners,
4668 mlxsw_sp->listeners_count);
4669 mlxsw_sp_traps_unregister(mlxsw_sp, mlxsw_sp_listener,
4670 ARRAY_SIZE(mlxsw_sp_listener));
4673 #define MLXSW_SP_LAG_SEED_INIT 0xcafecafe
4675 static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp)
4677 char slcr_pl[MLXSW_REG_SLCR_LEN];
4681 seed = jhash(mlxsw_sp->base_mac, sizeof(mlxsw_sp->base_mac),
4682 MLXSW_SP_LAG_SEED_INIT);
4683 mlxsw_reg_slcr_pack(slcr_pl, MLXSW_REG_SLCR_LAG_HASH_SMAC |
4684 MLXSW_REG_SLCR_LAG_HASH_DMAC |
4685 MLXSW_REG_SLCR_LAG_HASH_ETHERTYPE |
4686 MLXSW_REG_SLCR_LAG_HASH_VLANID |
4687 MLXSW_REG_SLCR_LAG_HASH_SIP |
4688 MLXSW_REG_SLCR_LAG_HASH_DIP |
4689 MLXSW_REG_SLCR_LAG_HASH_SPORT |
4690 MLXSW_REG_SLCR_LAG_HASH_DPORT |
4691 MLXSW_REG_SLCR_LAG_HASH_IPPROTO, seed);
4692 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(slcr), slcr_pl);
4696 if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_LAG) ||
4697 !MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_LAG_MEMBERS))
4700 mlxsw_sp->lags = kcalloc(MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_LAG),
4701 sizeof(struct mlxsw_sp_upper),
4703 if (!mlxsw_sp->lags)
4709 static void mlxsw_sp_lag_fini(struct mlxsw_sp *mlxsw_sp)
4711 kfree(mlxsw_sp->lags);
4714 static int mlxsw_sp_basic_trap_groups_set(struct mlxsw_core *mlxsw_core)
4716 char htgt_pl[MLXSW_REG_HTGT_LEN];
4718 mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
4719 MLXSW_REG_HTGT_INVALID_POLICER,
4720 MLXSW_REG_HTGT_DEFAULT_PRIORITY,
4721 MLXSW_REG_HTGT_DEFAULT_TC);
4722 return mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
4725 static const struct mlxsw_sp_ptp_ops mlxsw_sp1_ptp_ops = {
4726 .clock_init = mlxsw_sp1_ptp_clock_init,
4727 .clock_fini = mlxsw_sp1_ptp_clock_fini,
4728 .init = mlxsw_sp1_ptp_init,
4729 .fini = mlxsw_sp1_ptp_fini,
4730 .receive = mlxsw_sp1_ptp_receive,
4731 .transmitted = mlxsw_sp1_ptp_transmitted,
4732 .hwtstamp_get = mlxsw_sp1_ptp_hwtstamp_get,
4733 .hwtstamp_set = mlxsw_sp1_ptp_hwtstamp_set,
4734 .shaper_work = mlxsw_sp1_ptp_shaper_work,
4735 .get_ts_info = mlxsw_sp1_ptp_get_ts_info,
4736 .get_stats_count = mlxsw_sp1_get_stats_count,
4737 .get_stats_strings = mlxsw_sp1_get_stats_strings,
4738 .get_stats = mlxsw_sp1_get_stats,
4741 static const struct mlxsw_sp_ptp_ops mlxsw_sp2_ptp_ops = {
4742 .clock_init = mlxsw_sp2_ptp_clock_init,
4743 .clock_fini = mlxsw_sp2_ptp_clock_fini,
4744 .init = mlxsw_sp2_ptp_init,
4745 .fini = mlxsw_sp2_ptp_fini,
4746 .receive = mlxsw_sp2_ptp_receive,
4747 .transmitted = mlxsw_sp2_ptp_transmitted,
4748 .hwtstamp_get = mlxsw_sp2_ptp_hwtstamp_get,
4749 .hwtstamp_set = mlxsw_sp2_ptp_hwtstamp_set,
4750 .shaper_work = mlxsw_sp2_ptp_shaper_work,
4751 .get_ts_info = mlxsw_sp2_ptp_get_ts_info,
4752 .get_stats_count = mlxsw_sp2_get_stats_count,
4753 .get_stats_strings = mlxsw_sp2_get_stats_strings,
4754 .get_stats = mlxsw_sp2_get_stats,
4757 static int mlxsw_sp_netdevice_event(struct notifier_block *unused,
4758 unsigned long event, void *ptr);
4760 static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
4761 const struct mlxsw_bus_info *mlxsw_bus_info)
4763 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
4766 mlxsw_sp->core = mlxsw_core;
4767 mlxsw_sp->bus_info = mlxsw_bus_info;
4769 err = mlxsw_sp_fw_rev_validate(mlxsw_sp);
4773 err = mlxsw_sp_base_mac_get(mlxsw_sp);
4775 dev_err(mlxsw_sp->bus_info->dev, "Failed to get base mac\n");
4779 err = mlxsw_sp_kvdl_init(mlxsw_sp);
4781 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize KVDL\n");
4785 err = mlxsw_sp_fids_init(mlxsw_sp);
4787 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize FIDs\n");
4791 err = mlxsw_sp_traps_init(mlxsw_sp);
4793 dev_err(mlxsw_sp->bus_info->dev, "Failed to set traps\n");
4794 goto err_traps_init;
4797 err = mlxsw_sp_devlink_traps_init(mlxsw_sp);
4799 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize devlink traps\n");
4800 goto err_devlink_traps_init;
4803 err = mlxsw_sp_buffers_init(mlxsw_sp);
4805 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize buffers\n");
4806 goto err_buffers_init;
4809 err = mlxsw_sp_lag_init(mlxsw_sp);
4811 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize LAG\n");
4815 /* Initialize SPAN before router and switchdev, so that those components
4816 * can call mlxsw_sp_span_respin().
4818 err = mlxsw_sp_span_init(mlxsw_sp);
4820 dev_err(mlxsw_sp->bus_info->dev, "Failed to init span system\n");
4824 err = mlxsw_sp_switchdev_init(mlxsw_sp);
4826 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize switchdev\n");
4827 goto err_switchdev_init;
4830 err = mlxsw_sp_counter_pool_init(mlxsw_sp);
4832 dev_err(mlxsw_sp->bus_info->dev, "Failed to init counter pool\n");
4833 goto err_counter_pool_init;
4836 err = mlxsw_sp_afa_init(mlxsw_sp);
4838 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize ACL actions\n");
4842 err = mlxsw_sp_nve_init(mlxsw_sp);
4844 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize NVE\n");
4848 err = mlxsw_sp_acl_init(mlxsw_sp);
4850 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize ACL\n");
4854 err = mlxsw_sp_router_init(mlxsw_sp);
4856 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize router\n");
4857 goto err_router_init;
4860 if (mlxsw_sp->bus_info->read_frc_capable) {
4861 /* NULL is a valid return value from clock_init */
4863 mlxsw_sp->ptp_ops->clock_init(mlxsw_sp,
4864 mlxsw_sp->bus_info->dev);
4865 if (IS_ERR(mlxsw_sp->clock)) {
4866 err = PTR_ERR(mlxsw_sp->clock);
4867 dev_err(mlxsw_sp->bus_info->dev, "Failed to init ptp clock\n");
4868 goto err_ptp_clock_init;
4872 if (mlxsw_sp->clock) {
4873 /* NULL is a valid return value from ptp_ops->init */
4874 mlxsw_sp->ptp_state = mlxsw_sp->ptp_ops->init(mlxsw_sp);
4875 if (IS_ERR(mlxsw_sp->ptp_state)) {
4876 err = PTR_ERR(mlxsw_sp->ptp_state);
4877 dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize PTP\n");
4882 /* Initialize netdevice notifier after router and SPAN is initialized,
4883 * so that the event handler can use router structures and call SPAN
4886 mlxsw_sp->netdevice_nb.notifier_call = mlxsw_sp_netdevice_event;
4887 err = register_netdevice_notifier(&mlxsw_sp->netdevice_nb);
4889 dev_err(mlxsw_sp->bus_info->dev, "Failed to register netdev notifier\n");
4890 goto err_netdev_notifier;
4893 err = mlxsw_sp_dpipe_init(mlxsw_sp);
4895 dev_err(mlxsw_sp->bus_info->dev, "Failed to init pipeline debug\n");
4896 goto err_dpipe_init;
4899 err = mlxsw_sp_ports_create(mlxsw_sp);
4901 dev_err(mlxsw_sp->bus_info->dev, "Failed to create ports\n");
4902 goto err_ports_create;
4908 mlxsw_sp_dpipe_fini(mlxsw_sp);
4910 unregister_netdevice_notifier(&mlxsw_sp->netdevice_nb);
4911 err_netdev_notifier:
4912 if (mlxsw_sp->clock)
4913 mlxsw_sp->ptp_ops->fini(mlxsw_sp->ptp_state);
4915 if (mlxsw_sp->clock)
4916 mlxsw_sp->ptp_ops->clock_fini(mlxsw_sp->clock);
4918 mlxsw_sp_router_fini(mlxsw_sp);
4920 mlxsw_sp_acl_fini(mlxsw_sp);
4922 mlxsw_sp_nve_fini(mlxsw_sp);
4924 mlxsw_sp_afa_fini(mlxsw_sp);
4926 mlxsw_sp_counter_pool_fini(mlxsw_sp);
4927 err_counter_pool_init:
4928 mlxsw_sp_switchdev_fini(mlxsw_sp);
4930 mlxsw_sp_span_fini(mlxsw_sp);
4932 mlxsw_sp_lag_fini(mlxsw_sp);
4934 mlxsw_sp_buffers_fini(mlxsw_sp);
4936 mlxsw_sp_devlink_traps_fini(mlxsw_sp);
4937 err_devlink_traps_init:
4938 mlxsw_sp_traps_fini(mlxsw_sp);
4940 mlxsw_sp_fids_fini(mlxsw_sp);
4942 mlxsw_sp_kvdl_fini(mlxsw_sp);
4946 static int mlxsw_sp1_init(struct mlxsw_core *mlxsw_core,
4947 const struct mlxsw_bus_info *mlxsw_bus_info)
4949 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
4951 mlxsw_sp->req_rev = &mlxsw_sp1_fw_rev;
4952 mlxsw_sp->fw_filename = MLXSW_SP1_FW_FILENAME;
4953 mlxsw_sp->kvdl_ops = &mlxsw_sp1_kvdl_ops;
4954 mlxsw_sp->afa_ops = &mlxsw_sp1_act_afa_ops;
4955 mlxsw_sp->afk_ops = &mlxsw_sp1_afk_ops;
4956 mlxsw_sp->mr_tcam_ops = &mlxsw_sp1_mr_tcam_ops;
4957 mlxsw_sp->acl_tcam_ops = &mlxsw_sp1_acl_tcam_ops;
4958 mlxsw_sp->nve_ops_arr = mlxsw_sp1_nve_ops_arr;
4959 mlxsw_sp->mac_mask = mlxsw_sp1_mac_mask;
4960 mlxsw_sp->rif_ops_arr = mlxsw_sp1_rif_ops_arr;
4961 mlxsw_sp->sb_vals = &mlxsw_sp1_sb_vals;
4962 mlxsw_sp->port_type_speed_ops = &mlxsw_sp1_port_type_speed_ops;
4963 mlxsw_sp->ptp_ops = &mlxsw_sp1_ptp_ops;
4964 mlxsw_sp->listeners = mlxsw_sp1_listener;
4965 mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp1_listener);
4967 return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info);
4970 static int mlxsw_sp2_init(struct mlxsw_core *mlxsw_core,
4971 const struct mlxsw_bus_info *mlxsw_bus_info)
4973 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
4975 mlxsw_sp->kvdl_ops = &mlxsw_sp2_kvdl_ops;
4976 mlxsw_sp->afa_ops = &mlxsw_sp2_act_afa_ops;
4977 mlxsw_sp->afk_ops = &mlxsw_sp2_afk_ops;
4978 mlxsw_sp->mr_tcam_ops = &mlxsw_sp2_mr_tcam_ops;
4979 mlxsw_sp->acl_tcam_ops = &mlxsw_sp2_acl_tcam_ops;
4980 mlxsw_sp->nve_ops_arr = mlxsw_sp2_nve_ops_arr;
4981 mlxsw_sp->mac_mask = mlxsw_sp2_mac_mask;
4982 mlxsw_sp->rif_ops_arr = mlxsw_sp2_rif_ops_arr;
4983 mlxsw_sp->sb_vals = &mlxsw_sp2_sb_vals;
4984 mlxsw_sp->port_type_speed_ops = &mlxsw_sp2_port_type_speed_ops;
4985 mlxsw_sp->ptp_ops = &mlxsw_sp2_ptp_ops;
4987 return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info);
4990 static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core)
4992 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
4994 mlxsw_sp_ports_remove(mlxsw_sp);
4995 mlxsw_sp_dpipe_fini(mlxsw_sp);
4996 unregister_netdevice_notifier(&mlxsw_sp->netdevice_nb);
4997 if (mlxsw_sp->clock) {
4998 mlxsw_sp->ptp_ops->fini(mlxsw_sp->ptp_state);
4999 mlxsw_sp->ptp_ops->clock_fini(mlxsw_sp->clock);
5001 mlxsw_sp_router_fini(mlxsw_sp);
5002 mlxsw_sp_acl_fini(mlxsw_sp);
5003 mlxsw_sp_nve_fini(mlxsw_sp);
5004 mlxsw_sp_afa_fini(mlxsw_sp);
5005 mlxsw_sp_counter_pool_fini(mlxsw_sp);
5006 mlxsw_sp_switchdev_fini(mlxsw_sp);
5007 mlxsw_sp_span_fini(mlxsw_sp);
5008 mlxsw_sp_lag_fini(mlxsw_sp);
5009 mlxsw_sp_buffers_fini(mlxsw_sp);
5010 mlxsw_sp_devlink_traps_fini(mlxsw_sp);
5011 mlxsw_sp_traps_fini(mlxsw_sp);
5012 mlxsw_sp_fids_fini(mlxsw_sp);
5013 mlxsw_sp_kvdl_fini(mlxsw_sp);
5016 /* Per-FID flood tables are used for both "true" 802.1D FIDs and emulated
5019 #define MLXSW_SP_FID_FLOOD_TABLE_SIZE (MLXSW_SP_FID_8021D_MAX + \
5022 static const struct mlxsw_config_profile mlxsw_sp1_config_profile = {
5024 .max_mid = MLXSW_SP_MID_MAX,
5025 .used_flood_tables = 1,
5026 .used_flood_mode = 1,
5028 .max_fid_flood_tables = 3,
5029 .fid_flood_table_size = MLXSW_SP_FID_FLOOD_TABLE_SIZE,
5030 .used_max_ib_mc = 1,
5034 .used_kvd_sizes = 1,
5035 .kvd_hash_single_parts = 59,
5036 .kvd_hash_double_parts = 41,
5037 .kvd_linear_size = MLXSW_SP_KVD_LINEAR_SIZE,
5041 .type = MLXSW_PORT_SWID_TYPE_ETH,
5046 static const struct mlxsw_config_profile mlxsw_sp2_config_profile = {
5048 .max_mid = MLXSW_SP_MID_MAX,
5049 .used_flood_tables = 1,
5050 .used_flood_mode = 1,
5052 .max_fid_flood_tables = 3,
5053 .fid_flood_table_size = MLXSW_SP_FID_FLOOD_TABLE_SIZE,
5054 .used_max_ib_mc = 1,
5061 .type = MLXSW_PORT_SWID_TYPE_ETH,
5067 mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core,
5068 struct devlink_resource_size_params *kvd_size_params,
5069 struct devlink_resource_size_params *linear_size_params,
5070 struct devlink_resource_size_params *hash_double_size_params,
5071 struct devlink_resource_size_params *hash_single_size_params)
5073 u32 single_size_min = MLXSW_CORE_RES_GET(mlxsw_core,
5074 KVD_SINGLE_MIN_SIZE);
5075 u32 double_size_min = MLXSW_CORE_RES_GET(mlxsw_core,
5076 KVD_DOUBLE_MIN_SIZE);
5077 u32 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
5078 u32 linear_size_min = 0;
5080 devlink_resource_size_params_init(kvd_size_params, kvd_size, kvd_size,
5081 MLXSW_SP_KVD_GRANULARITY,
5082 DEVLINK_RESOURCE_UNIT_ENTRY);
5083 devlink_resource_size_params_init(linear_size_params, linear_size_min,
5084 kvd_size - single_size_min -
5086 MLXSW_SP_KVD_GRANULARITY,
5087 DEVLINK_RESOURCE_UNIT_ENTRY);
5088 devlink_resource_size_params_init(hash_double_size_params,
5090 kvd_size - single_size_min -
5092 MLXSW_SP_KVD_GRANULARITY,
5093 DEVLINK_RESOURCE_UNIT_ENTRY);
5094 devlink_resource_size_params_init(hash_single_size_params,
5096 kvd_size - double_size_min -
5098 MLXSW_SP_KVD_GRANULARITY,
5099 DEVLINK_RESOURCE_UNIT_ENTRY);
5102 static int mlxsw_sp1_resources_kvd_register(struct mlxsw_core *mlxsw_core)
5104 struct devlink *devlink = priv_to_devlink(mlxsw_core);
5105 struct devlink_resource_size_params hash_single_size_params;
5106 struct devlink_resource_size_params hash_double_size_params;
5107 struct devlink_resource_size_params linear_size_params;
5108 struct devlink_resource_size_params kvd_size_params;
5109 u32 kvd_size, single_size, double_size, linear_size;
5110 const struct mlxsw_config_profile *profile;
5113 profile = &mlxsw_sp1_config_profile;
5114 if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SIZE))
5117 mlxsw_sp_resource_size_params_prepare(mlxsw_core, &kvd_size_params,
5118 &linear_size_params,
5119 &hash_double_size_params,
5120 &hash_single_size_params);
5122 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
5123 err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD,
5124 kvd_size, MLXSW_SP_RESOURCE_KVD,
5125 DEVLINK_RESOURCE_ID_PARENT_TOP,
5130 linear_size = profile->kvd_linear_size;
5131 err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_LINEAR,
5133 MLXSW_SP_RESOURCE_KVD_LINEAR,
5134 MLXSW_SP_RESOURCE_KVD,
5135 &linear_size_params);
5139 err = mlxsw_sp1_kvdl_resources_register(mlxsw_core);
5143 double_size = kvd_size - linear_size;
5144 double_size *= profile->kvd_hash_double_parts;
5145 double_size /= profile->kvd_hash_double_parts +
5146 profile->kvd_hash_single_parts;
5147 double_size = rounddown(double_size, MLXSW_SP_KVD_GRANULARITY);
5148 err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE,
5150 MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
5151 MLXSW_SP_RESOURCE_KVD,
5152 &hash_double_size_params);
5156 single_size = kvd_size - double_size - linear_size;
5157 err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE,
5159 MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
5160 MLXSW_SP_RESOURCE_KVD,
5161 &hash_single_size_params);
5168 static int mlxsw_sp2_resources_kvd_register(struct mlxsw_core *mlxsw_core)
5170 struct devlink *devlink = priv_to_devlink(mlxsw_core);
5171 struct devlink_resource_size_params kvd_size_params;
5174 if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SIZE))
5177 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
5178 devlink_resource_size_params_init(&kvd_size_params, kvd_size, kvd_size,
5179 MLXSW_SP_KVD_GRANULARITY,
5180 DEVLINK_RESOURCE_UNIT_ENTRY);
5182 return devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD,
5183 kvd_size, MLXSW_SP_RESOURCE_KVD,
5184 DEVLINK_RESOURCE_ID_PARENT_TOP,
5188 static int mlxsw_sp1_resources_register(struct mlxsw_core *mlxsw_core)
5190 return mlxsw_sp1_resources_kvd_register(mlxsw_core);
5193 static int mlxsw_sp2_resources_register(struct mlxsw_core *mlxsw_core)
5195 return mlxsw_sp2_resources_kvd_register(mlxsw_core);
5198 static int mlxsw_sp_kvd_sizes_get(struct mlxsw_core *mlxsw_core,
5199 const struct mlxsw_config_profile *profile,
5200 u64 *p_single_size, u64 *p_double_size,
5203 struct devlink *devlink = priv_to_devlink(mlxsw_core);
5207 if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SINGLE_MIN_SIZE) ||
5208 !MLXSW_CORE_RES_VALID(mlxsw_core, KVD_DOUBLE_MIN_SIZE))
5211 /* The hash part is what left of the kvd without the
5212 * linear part. It is split to the single size and
5213 * double size by the parts ratio from the profile.
5214 * Both sizes must be a multiplications of the
5215 * granularity from the profile. In case the user
5216 * provided the sizes they are obtained via devlink.
5218 err = devlink_resource_size_get(devlink,
5219 MLXSW_SP_RESOURCE_KVD_LINEAR,
5222 *p_linear_size = profile->kvd_linear_size;
5224 err = devlink_resource_size_get(devlink,
5225 MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
5228 double_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE) -
5230 double_size *= profile->kvd_hash_double_parts;
5231 double_size /= profile->kvd_hash_double_parts +
5232 profile->kvd_hash_single_parts;
5233 *p_double_size = rounddown(double_size,
5234 MLXSW_SP_KVD_GRANULARITY);
5237 err = devlink_resource_size_get(devlink,
5238 MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
5241 *p_single_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE) -
5242 *p_double_size - *p_linear_size;
5244 /* Check results are legal. */
5245 if (*p_single_size < MLXSW_CORE_RES_GET(mlxsw_core, KVD_SINGLE_MIN_SIZE) ||
5246 *p_double_size < MLXSW_CORE_RES_GET(mlxsw_core, KVD_DOUBLE_MIN_SIZE) ||
5247 MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE) < *p_linear_size)
5254 mlxsw_sp_devlink_param_fw_load_policy_validate(struct devlink *devlink, u32 id,
5255 union devlink_param_value val,
5256 struct netlink_ext_ack *extack)
5258 if ((val.vu8 != DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_DRIVER) &&
5259 (val.vu8 != DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_FLASH)) {
5260 NL_SET_ERR_MSG_MOD(extack, "'fw_load_policy' must be 'driver' or 'flash'");
5267 static const struct devlink_param mlxsw_sp_devlink_params[] = {
5268 DEVLINK_PARAM_GENERIC(FW_LOAD_POLICY,
5269 BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
5271 mlxsw_sp_devlink_param_fw_load_policy_validate),
5274 static int mlxsw_sp_params_register(struct mlxsw_core *mlxsw_core)
5276 struct devlink *devlink = priv_to_devlink(mlxsw_core);
5277 union devlink_param_value value;
5280 err = devlink_params_register(devlink, mlxsw_sp_devlink_params,
5281 ARRAY_SIZE(mlxsw_sp_devlink_params));
5285 value.vu8 = DEVLINK_PARAM_FW_LOAD_POLICY_VALUE_DRIVER;
5286 devlink_param_driverinit_value_set(devlink,
5287 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
5292 static void mlxsw_sp_params_unregister(struct mlxsw_core *mlxsw_core)
5294 devlink_params_unregister(priv_to_devlink(mlxsw_core),
5295 mlxsw_sp_devlink_params,
5296 ARRAY_SIZE(mlxsw_sp_devlink_params));
5300 mlxsw_sp_params_acl_region_rehash_intrvl_get(struct devlink *devlink, u32 id,
5301 struct devlink_param_gset_ctx *ctx)
5303 struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
5304 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
5306 ctx->val.vu32 = mlxsw_sp_acl_region_rehash_intrvl_get(mlxsw_sp);
5311 mlxsw_sp_params_acl_region_rehash_intrvl_set(struct devlink *devlink, u32 id,
5312 struct devlink_param_gset_ctx *ctx)
5314 struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
5315 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
5317 return mlxsw_sp_acl_region_rehash_intrvl_set(mlxsw_sp, ctx->val.vu32);
5320 static const struct devlink_param mlxsw_sp2_devlink_params[] = {
5321 DEVLINK_PARAM_DRIVER(MLXSW_DEVLINK_PARAM_ID_ACL_REGION_REHASH_INTERVAL,
5322 "acl_region_rehash_interval",
5323 DEVLINK_PARAM_TYPE_U32,
5324 BIT(DEVLINK_PARAM_CMODE_RUNTIME),
5325 mlxsw_sp_params_acl_region_rehash_intrvl_get,
5326 mlxsw_sp_params_acl_region_rehash_intrvl_set,
5330 static int mlxsw_sp2_params_register(struct mlxsw_core *mlxsw_core)
5332 struct devlink *devlink = priv_to_devlink(mlxsw_core);
5333 union devlink_param_value value;
5336 err = mlxsw_sp_params_register(mlxsw_core);
5340 err = devlink_params_register(devlink, mlxsw_sp2_devlink_params,
5341 ARRAY_SIZE(mlxsw_sp2_devlink_params));
5343 goto err_devlink_params_register;
5346 devlink_param_driverinit_value_set(devlink,
5347 MLXSW_DEVLINK_PARAM_ID_ACL_REGION_REHASH_INTERVAL,
5351 err_devlink_params_register:
5352 mlxsw_sp_params_unregister(mlxsw_core);
5356 static void mlxsw_sp2_params_unregister(struct mlxsw_core *mlxsw_core)
5358 devlink_params_unregister(priv_to_devlink(mlxsw_core),
5359 mlxsw_sp2_devlink_params,
5360 ARRAY_SIZE(mlxsw_sp2_devlink_params));
5361 mlxsw_sp_params_unregister(mlxsw_core);
5364 static void mlxsw_sp_ptp_transmitted(struct mlxsw_core *mlxsw_core,
5365 struct sk_buff *skb, u8 local_port)
5367 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
5369 skb_pull(skb, MLXSW_TXHDR_LEN);
5370 mlxsw_sp->ptp_ops->transmitted(mlxsw_sp, skb, local_port);
5373 static struct mlxsw_driver mlxsw_sp1_driver = {
5374 .kind = mlxsw_sp1_driver_name,
5375 .priv_size = sizeof(struct mlxsw_sp),
5376 .init = mlxsw_sp1_init,
5377 .fini = mlxsw_sp_fini,
5378 .basic_trap_groups_set = mlxsw_sp_basic_trap_groups_set,
5379 .port_split = mlxsw_sp_port_split,
5380 .port_unsplit = mlxsw_sp_port_unsplit,
5381 .sb_pool_get = mlxsw_sp_sb_pool_get,
5382 .sb_pool_set = mlxsw_sp_sb_pool_set,
5383 .sb_port_pool_get = mlxsw_sp_sb_port_pool_get,
5384 .sb_port_pool_set = mlxsw_sp_sb_port_pool_set,
5385 .sb_tc_pool_bind_get = mlxsw_sp_sb_tc_pool_bind_get,
5386 .sb_tc_pool_bind_set = mlxsw_sp_sb_tc_pool_bind_set,
5387 .sb_occ_snapshot = mlxsw_sp_sb_occ_snapshot,
5388 .sb_occ_max_clear = mlxsw_sp_sb_occ_max_clear,
5389 .sb_occ_port_pool_get = mlxsw_sp_sb_occ_port_pool_get,
5390 .sb_occ_tc_port_bind_get = mlxsw_sp_sb_occ_tc_port_bind_get,
5391 .flash_update = mlxsw_sp_flash_update,
5392 .trap_init = mlxsw_sp_trap_init,
5393 .trap_fini = mlxsw_sp_trap_fini,
5394 .trap_action_set = mlxsw_sp_trap_action_set,
5395 .trap_group_init = mlxsw_sp_trap_group_init,
5396 .txhdr_construct = mlxsw_sp_txhdr_construct,
5397 .resources_register = mlxsw_sp1_resources_register,
5398 .kvd_sizes_get = mlxsw_sp_kvd_sizes_get,
5399 .params_register = mlxsw_sp_params_register,
5400 .params_unregister = mlxsw_sp_params_unregister,
5401 .ptp_transmitted = mlxsw_sp_ptp_transmitted,
5402 .txhdr_len = MLXSW_TXHDR_LEN,
5403 .profile = &mlxsw_sp1_config_profile,
5404 .res_query_enabled = true,
5407 static struct mlxsw_driver mlxsw_sp2_driver = {
5408 .kind = mlxsw_sp2_driver_name,
5409 .priv_size = sizeof(struct mlxsw_sp),
5410 .init = mlxsw_sp2_init,
5411 .fini = mlxsw_sp_fini,
5412 .basic_trap_groups_set = mlxsw_sp_basic_trap_groups_set,
5413 .port_split = mlxsw_sp_port_split,
5414 .port_unsplit = mlxsw_sp_port_unsplit,
5415 .sb_pool_get = mlxsw_sp_sb_pool_get,
5416 .sb_pool_set = mlxsw_sp_sb_pool_set,
5417 .sb_port_pool_get = mlxsw_sp_sb_port_pool_get,
5418 .sb_port_pool_set = mlxsw_sp_sb_port_pool_set,
5419 .sb_tc_pool_bind_get = mlxsw_sp_sb_tc_pool_bind_get,
5420 .sb_tc_pool_bind_set = mlxsw_sp_sb_tc_pool_bind_set,
5421 .sb_occ_snapshot = mlxsw_sp_sb_occ_snapshot,
5422 .sb_occ_max_clear = mlxsw_sp_sb_occ_max_clear,
5423 .sb_occ_port_pool_get = mlxsw_sp_sb_occ_port_pool_get,
5424 .sb_occ_tc_port_bind_get = mlxsw_sp_sb_occ_tc_port_bind_get,
5425 .flash_update = mlxsw_sp_flash_update,
5426 .trap_init = mlxsw_sp_trap_init,
5427 .trap_fini = mlxsw_sp_trap_fini,
5428 .trap_action_set = mlxsw_sp_trap_action_set,
5429 .trap_group_init = mlxsw_sp_trap_group_init,
5430 .txhdr_construct = mlxsw_sp_txhdr_construct,
5431 .resources_register = mlxsw_sp2_resources_register,
5432 .params_register = mlxsw_sp2_params_register,
5433 .params_unregister = mlxsw_sp2_params_unregister,
5434 .ptp_transmitted = mlxsw_sp_ptp_transmitted,
5435 .txhdr_len = MLXSW_TXHDR_LEN,
5436 .profile = &mlxsw_sp2_config_profile,
5437 .res_query_enabled = true,
5440 static struct mlxsw_driver mlxsw_sp3_driver = {
5441 .kind = mlxsw_sp3_driver_name,
5442 .priv_size = sizeof(struct mlxsw_sp),
5443 .init = mlxsw_sp2_init,
5444 .fini = mlxsw_sp_fini,
5445 .basic_trap_groups_set = mlxsw_sp_basic_trap_groups_set,
5446 .port_split = mlxsw_sp_port_split,
5447 .port_unsplit = mlxsw_sp_port_unsplit,
5448 .sb_pool_get = mlxsw_sp_sb_pool_get,
5449 .sb_pool_set = mlxsw_sp_sb_pool_set,
5450 .sb_port_pool_get = mlxsw_sp_sb_port_pool_get,
5451 .sb_port_pool_set = mlxsw_sp_sb_port_pool_set,
5452 .sb_tc_pool_bind_get = mlxsw_sp_sb_tc_pool_bind_get,
5453 .sb_tc_pool_bind_set = mlxsw_sp_sb_tc_pool_bind_set,
5454 .sb_occ_snapshot = mlxsw_sp_sb_occ_snapshot,
5455 .sb_occ_max_clear = mlxsw_sp_sb_occ_max_clear,
5456 .sb_occ_port_pool_get = mlxsw_sp_sb_occ_port_pool_get,
5457 .sb_occ_tc_port_bind_get = mlxsw_sp_sb_occ_tc_port_bind_get,
5458 .flash_update = mlxsw_sp_flash_update,
5459 .trap_init = mlxsw_sp_trap_init,
5460 .trap_fini = mlxsw_sp_trap_fini,
5461 .trap_action_set = mlxsw_sp_trap_action_set,
5462 .trap_group_init = mlxsw_sp_trap_group_init,
5463 .txhdr_construct = mlxsw_sp_txhdr_construct,
5464 .resources_register = mlxsw_sp2_resources_register,
5465 .params_register = mlxsw_sp2_params_register,
5466 .params_unregister = mlxsw_sp2_params_unregister,
5467 .ptp_transmitted = mlxsw_sp_ptp_transmitted,
5468 .txhdr_len = MLXSW_TXHDR_LEN,
5469 .profile = &mlxsw_sp2_config_profile,
5470 .res_query_enabled = true,
5473 bool mlxsw_sp_port_dev_check(const struct net_device *dev)
5475 return dev->netdev_ops == &mlxsw_sp_port_netdev_ops;
5478 static int mlxsw_sp_lower_dev_walk(struct net_device *lower_dev, void *data)
5480 struct mlxsw_sp_port **p_mlxsw_sp_port = data;
5483 if (mlxsw_sp_port_dev_check(lower_dev)) {
5484 *p_mlxsw_sp_port = netdev_priv(lower_dev);
5491 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find(struct net_device *dev)
5493 struct mlxsw_sp_port *mlxsw_sp_port;
5495 if (mlxsw_sp_port_dev_check(dev))
5496 return netdev_priv(dev);
5498 mlxsw_sp_port = NULL;
5499 netdev_walk_all_lower_dev(dev, mlxsw_sp_lower_dev_walk, &mlxsw_sp_port);
5501 return mlxsw_sp_port;
5504 struct mlxsw_sp *mlxsw_sp_lower_get(struct net_device *dev)
5506 struct mlxsw_sp_port *mlxsw_sp_port;
5508 mlxsw_sp_port = mlxsw_sp_port_dev_lower_find(dev);
5509 return mlxsw_sp_port ? mlxsw_sp_port->mlxsw_sp : NULL;
5512 struct mlxsw_sp_port *mlxsw_sp_port_dev_lower_find_rcu(struct net_device *dev)
5514 struct mlxsw_sp_port *mlxsw_sp_port;
5516 if (mlxsw_sp_port_dev_check(dev))
5517 return netdev_priv(dev);
5519 mlxsw_sp_port = NULL;
5520 netdev_walk_all_lower_dev_rcu(dev, mlxsw_sp_lower_dev_walk,
5523 return mlxsw_sp_port;
5526 struct mlxsw_sp_port *mlxsw_sp_port_lower_dev_hold(struct net_device *dev)
5528 struct mlxsw_sp_port *mlxsw_sp_port;
5531 mlxsw_sp_port = mlxsw_sp_port_dev_lower_find_rcu(dev);
5533 dev_hold(mlxsw_sp_port->dev);
5535 return mlxsw_sp_port;
5538 void mlxsw_sp_port_dev_put(struct mlxsw_sp_port *mlxsw_sp_port)
5540 dev_put(mlxsw_sp_port->dev);
5544 mlxsw_sp_port_lag_uppers_cleanup(struct mlxsw_sp_port *mlxsw_sp_port,
5545 struct net_device *lag_dev)
5547 struct net_device *br_dev = netdev_master_upper_dev_get(lag_dev);
5548 struct net_device *upper_dev;
5549 struct list_head *iter;
5551 if (netif_is_bridge_port(lag_dev))
5552 mlxsw_sp_port_bridge_leave(mlxsw_sp_port, lag_dev, br_dev);
5554 netdev_for_each_upper_dev_rcu(lag_dev, upper_dev, iter) {
5555 if (!netif_is_bridge_port(upper_dev))
5557 br_dev = netdev_master_upper_dev_get(upper_dev);
5558 mlxsw_sp_port_bridge_leave(mlxsw_sp_port, upper_dev, br_dev);
5562 static int mlxsw_sp_lag_create(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
5564 char sldr_pl[MLXSW_REG_SLDR_LEN];
5566 mlxsw_reg_sldr_lag_create_pack(sldr_pl, lag_id);
5567 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sldr), sldr_pl);
5570 static int mlxsw_sp_lag_destroy(struct mlxsw_sp *mlxsw_sp, u16 lag_id)
5572 char sldr_pl[MLXSW_REG_SLDR_LEN];
5574 mlxsw_reg_sldr_lag_destroy_pack(sldr_pl, lag_id);
5575 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sldr), sldr_pl);
5578 static int mlxsw_sp_lag_col_port_add(struct mlxsw_sp_port *mlxsw_sp_port,
5579 u16 lag_id, u8 port_index)
5581 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5582 char slcor_pl[MLXSW_REG_SLCOR_LEN];
5584 mlxsw_reg_slcor_port_add_pack(slcor_pl, mlxsw_sp_port->local_port,
5585 lag_id, port_index);
5586 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(slcor), slcor_pl);
5589 static int mlxsw_sp_lag_col_port_remove(struct mlxsw_sp_port *mlxsw_sp_port,
5592 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5593 char slcor_pl[MLXSW_REG_SLCOR_LEN];
5595 mlxsw_reg_slcor_port_remove_pack(slcor_pl, mlxsw_sp_port->local_port,
5597 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(slcor), slcor_pl);
5600 static int mlxsw_sp_lag_col_port_enable(struct mlxsw_sp_port *mlxsw_sp_port,
5603 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5604 char slcor_pl[MLXSW_REG_SLCOR_LEN];
5606 mlxsw_reg_slcor_col_enable_pack(slcor_pl, mlxsw_sp_port->local_port,
5608 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(slcor), slcor_pl);
5611 static int mlxsw_sp_lag_col_port_disable(struct mlxsw_sp_port *mlxsw_sp_port,
5614 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5615 char slcor_pl[MLXSW_REG_SLCOR_LEN];
5617 mlxsw_reg_slcor_col_disable_pack(slcor_pl, mlxsw_sp_port->local_port,
5619 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(slcor), slcor_pl);
5622 static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp,
5623 struct net_device *lag_dev,
5626 struct mlxsw_sp_upper *lag;
5627 int free_lag_id = -1;
5631 max_lag = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_LAG);
5632 for (i = 0; i < max_lag; i++) {
5633 lag = mlxsw_sp_lag_get(mlxsw_sp, i);
5634 if (lag->ref_count) {
5635 if (lag->dev == lag_dev) {
5639 } else if (free_lag_id < 0) {
5643 if (free_lag_id < 0)
5645 *p_lag_id = free_lag_id;
5650 mlxsw_sp_master_lag_check(struct mlxsw_sp *mlxsw_sp,
5651 struct net_device *lag_dev,
5652 struct netdev_lag_upper_info *lag_upper_info,
5653 struct netlink_ext_ack *extack)
5657 if (mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id) != 0) {
5658 NL_SET_ERR_MSG_MOD(extack, "Exceeded number of supported LAG devices");
5661 if (lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
5662 NL_SET_ERR_MSG_MOD(extack, "LAG device using unsupported Tx type");
5668 static int mlxsw_sp_port_lag_index_get(struct mlxsw_sp *mlxsw_sp,
5669 u16 lag_id, u8 *p_port_index)
5671 u64 max_lag_members;
5674 max_lag_members = MLXSW_CORE_RES_GET(mlxsw_sp->core,
5676 for (i = 0; i < max_lag_members; i++) {
5677 if (!mlxsw_sp_port_lagged_get(mlxsw_sp, lag_id, i)) {
5685 static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port,
5686 struct net_device *lag_dev)
5688 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5689 struct mlxsw_sp_upper *lag;
5694 err = mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id);
5697 lag = mlxsw_sp_lag_get(mlxsw_sp, lag_id);
5698 if (!lag->ref_count) {
5699 err = mlxsw_sp_lag_create(mlxsw_sp, lag_id);
5705 err = mlxsw_sp_port_lag_index_get(mlxsw_sp, lag_id, &port_index);
5708 err = mlxsw_sp_lag_col_port_add(mlxsw_sp_port, lag_id, port_index);
5710 goto err_col_port_add;
5712 mlxsw_core_lag_mapping_set(mlxsw_sp->core, lag_id, port_index,
5713 mlxsw_sp_port->local_port);
5714 mlxsw_sp_port->lag_id = lag_id;
5715 mlxsw_sp_port->lagged = 1;
5718 /* Port is no longer usable as a router interface */
5719 if (mlxsw_sp_port->default_vlan->fid)
5720 mlxsw_sp_port_vlan_router_leave(mlxsw_sp_port->default_vlan);
5725 if (!lag->ref_count)
5726 mlxsw_sp_lag_destroy(mlxsw_sp, lag_id);
5730 static void mlxsw_sp_port_lag_leave(struct mlxsw_sp_port *mlxsw_sp_port,
5731 struct net_device *lag_dev)
5733 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5734 u16 lag_id = mlxsw_sp_port->lag_id;
5735 struct mlxsw_sp_upper *lag;
5737 if (!mlxsw_sp_port->lagged)
5739 lag = mlxsw_sp_lag_get(mlxsw_sp, lag_id);
5740 WARN_ON(lag->ref_count == 0);
5742 mlxsw_sp_lag_col_port_remove(mlxsw_sp_port, lag_id);
5744 /* Any VLANs configured on the port are no longer valid */
5745 mlxsw_sp_port_vlan_flush(mlxsw_sp_port, false);
5746 mlxsw_sp_port_vlan_cleanup(mlxsw_sp_port->default_vlan);
5747 /* Make the LAG and its directly linked uppers leave bridges they
5750 mlxsw_sp_port_lag_uppers_cleanup(mlxsw_sp_port, lag_dev);
5752 if (lag->ref_count == 1)
5753 mlxsw_sp_lag_destroy(mlxsw_sp, lag_id);
5755 mlxsw_core_lag_mapping_clear(mlxsw_sp->core, lag_id,
5756 mlxsw_sp_port->local_port);
5757 mlxsw_sp_port->lagged = 0;
5760 /* Make sure untagged frames are allowed to ingress */
5761 mlxsw_sp_port_pvid_set(mlxsw_sp_port, MLXSW_SP_DEFAULT_VID);
5764 static int mlxsw_sp_lag_dist_port_add(struct mlxsw_sp_port *mlxsw_sp_port,
5767 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5768 char sldr_pl[MLXSW_REG_SLDR_LEN];
5770 mlxsw_reg_sldr_lag_add_port_pack(sldr_pl, lag_id,
5771 mlxsw_sp_port->local_port);
5772 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sldr), sldr_pl);
5775 static int mlxsw_sp_lag_dist_port_remove(struct mlxsw_sp_port *mlxsw_sp_port,
5778 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5779 char sldr_pl[MLXSW_REG_SLDR_LEN];
5781 mlxsw_reg_sldr_lag_remove_port_pack(sldr_pl, lag_id,
5782 mlxsw_sp_port->local_port);
5783 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sldr), sldr_pl);
5787 mlxsw_sp_port_lag_col_dist_enable(struct mlxsw_sp_port *mlxsw_sp_port)
5791 err = mlxsw_sp_lag_col_port_enable(mlxsw_sp_port,
5792 mlxsw_sp_port->lag_id);
5796 err = mlxsw_sp_lag_dist_port_add(mlxsw_sp_port, mlxsw_sp_port->lag_id);
5798 goto err_dist_port_add;
5803 mlxsw_sp_lag_col_port_disable(mlxsw_sp_port, mlxsw_sp_port->lag_id);
5808 mlxsw_sp_port_lag_col_dist_disable(struct mlxsw_sp_port *mlxsw_sp_port)
5812 err = mlxsw_sp_lag_dist_port_remove(mlxsw_sp_port,
5813 mlxsw_sp_port->lag_id);
5817 err = mlxsw_sp_lag_col_port_disable(mlxsw_sp_port,
5818 mlxsw_sp_port->lag_id);
5820 goto err_col_port_disable;
5824 err_col_port_disable:
5825 mlxsw_sp_lag_dist_port_add(mlxsw_sp_port, mlxsw_sp_port->lag_id);
5829 static int mlxsw_sp_port_lag_changed(struct mlxsw_sp_port *mlxsw_sp_port,
5830 struct netdev_lag_lower_state_info *info)
5832 if (info->tx_enabled)
5833 return mlxsw_sp_port_lag_col_dist_enable(mlxsw_sp_port);
5835 return mlxsw_sp_port_lag_col_dist_disable(mlxsw_sp_port);
5838 static int mlxsw_sp_port_stp_set(struct mlxsw_sp_port *mlxsw_sp_port,
5841 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5842 enum mlxsw_reg_spms_state spms_state;
5847 spms_state = enable ? MLXSW_REG_SPMS_STATE_FORWARDING :
5848 MLXSW_REG_SPMS_STATE_DISCARDING;
5850 spms_pl = kmalloc(MLXSW_REG_SPMS_LEN, GFP_KERNEL);
5853 mlxsw_reg_spms_pack(spms_pl, mlxsw_sp_port->local_port);
5855 for (vid = 0; vid < VLAN_N_VID; vid++)
5856 mlxsw_reg_spms_vid_pack(spms_pl, vid, spms_state);
5858 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spms), spms_pl);
5863 static int mlxsw_sp_port_ovs_join(struct mlxsw_sp_port *mlxsw_sp_port)
5868 err = mlxsw_sp_port_vp_mode_set(mlxsw_sp_port, true);
5871 err = mlxsw_sp_port_stp_set(mlxsw_sp_port, true);
5873 goto err_port_stp_set;
5874 err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, 1, VLAN_N_VID - 2,
5877 goto err_port_vlan_set;
5879 for (; vid <= VLAN_N_VID - 1; vid++) {
5880 err = mlxsw_sp_port_vid_learning_set(mlxsw_sp_port,
5883 goto err_vid_learning_set;
5888 err_vid_learning_set:
5889 for (vid--; vid >= 1; vid--)
5890 mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, true);
5892 mlxsw_sp_port_stp_set(mlxsw_sp_port, false);
5894 mlxsw_sp_port_vp_mode_set(mlxsw_sp_port, false);
5898 static void mlxsw_sp_port_ovs_leave(struct mlxsw_sp_port *mlxsw_sp_port)
5902 for (vid = VLAN_N_VID - 1; vid >= 1; vid--)
5903 mlxsw_sp_port_vid_learning_set(mlxsw_sp_port,
5906 mlxsw_sp_port_vlan_set(mlxsw_sp_port, 1, VLAN_N_VID - 2,
5908 mlxsw_sp_port_stp_set(mlxsw_sp_port, false);
5909 mlxsw_sp_port_vp_mode_set(mlxsw_sp_port, false);
5912 static bool mlxsw_sp_bridge_has_multiple_vxlans(struct net_device *br_dev)
5914 unsigned int num_vxlans = 0;
5915 struct net_device *dev;
5916 struct list_head *iter;
5918 netdev_for_each_lower_dev(br_dev, dev, iter) {
5919 if (netif_is_vxlan(dev))
5923 return num_vxlans > 1;
5926 static bool mlxsw_sp_bridge_vxlan_vlan_is_valid(struct net_device *br_dev)
5928 DECLARE_BITMAP(vlans, VLAN_N_VID) = {0};
5929 struct net_device *dev;
5930 struct list_head *iter;
5932 netdev_for_each_lower_dev(br_dev, dev, iter) {
5936 if (!netif_is_vxlan(dev))
5939 err = mlxsw_sp_vxlan_mapped_vid(dev, &pvid);
5943 if (test_and_set_bit(pvid, vlans))
5950 static bool mlxsw_sp_bridge_vxlan_is_valid(struct net_device *br_dev,
5951 struct netlink_ext_ack *extack)
5953 if (br_multicast_enabled(br_dev)) {
5954 NL_SET_ERR_MSG_MOD(extack, "Multicast can not be enabled on a bridge with a VxLAN device");
5958 if (!br_vlan_enabled(br_dev) &&
5959 mlxsw_sp_bridge_has_multiple_vxlans(br_dev)) {
5960 NL_SET_ERR_MSG_MOD(extack, "Multiple VxLAN devices are not supported in a VLAN-unaware bridge");
5964 if (br_vlan_enabled(br_dev) &&
5965 !mlxsw_sp_bridge_vxlan_vlan_is_valid(br_dev)) {
5966 NL_SET_ERR_MSG_MOD(extack, "Multiple VxLAN devices cannot have the same VLAN as PVID and egress untagged");
5973 static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev,
5974 struct net_device *dev,
5975 unsigned long event, void *ptr)
5977 struct netdev_notifier_changeupper_info *info;
5978 struct mlxsw_sp_port *mlxsw_sp_port;
5979 struct netlink_ext_ack *extack;
5980 struct net_device *upper_dev;
5981 struct mlxsw_sp *mlxsw_sp;
5984 mlxsw_sp_port = netdev_priv(dev);
5985 mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
5987 extack = netdev_notifier_info_to_extack(&info->info);
5990 case NETDEV_PRECHANGEUPPER:
5991 upper_dev = info->upper_dev;
5992 if (!is_vlan_dev(upper_dev) &&
5993 !netif_is_lag_master(upper_dev) &&
5994 !netif_is_bridge_master(upper_dev) &&
5995 !netif_is_ovs_master(upper_dev) &&
5996 !netif_is_macvlan(upper_dev)) {
5997 NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
6002 if (netif_is_bridge_master(upper_dev) &&
6003 !mlxsw_sp_bridge_device_is_offloaded(mlxsw_sp, upper_dev) &&
6004 mlxsw_sp_bridge_has_vxlan(upper_dev) &&
6005 !mlxsw_sp_bridge_vxlan_is_valid(upper_dev, extack))
6007 if (netdev_has_any_upper_dev(upper_dev) &&
6008 (!netif_is_bridge_master(upper_dev) ||
6009 !mlxsw_sp_bridge_device_is_offloaded(mlxsw_sp,
6011 NL_SET_ERR_MSG_MOD(extack, "Enslaving a port to a device that already has an upper device is not supported");
6014 if (netif_is_lag_master(upper_dev) &&
6015 !mlxsw_sp_master_lag_check(mlxsw_sp, upper_dev,
6016 info->upper_info, extack))
6018 if (netif_is_lag_master(upper_dev) && vlan_uses_dev(dev)) {
6019 NL_SET_ERR_MSG_MOD(extack, "Master device is a LAG master and this device has a VLAN");
6022 if (netif_is_lag_port(dev) && is_vlan_dev(upper_dev) &&
6023 !netif_is_lag_master(vlan_dev_real_dev(upper_dev))) {
6024 NL_SET_ERR_MSG_MOD(extack, "Can not put a VLAN on a LAG port");
6027 if (netif_is_macvlan(upper_dev) &&
6028 !mlxsw_sp_rif_find_by_dev(mlxsw_sp, lower_dev)) {
6029 NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
6032 if (netif_is_ovs_master(upper_dev) && vlan_uses_dev(dev)) {
6033 NL_SET_ERR_MSG_MOD(extack, "Master device is an OVS master and this device has a VLAN");
6036 if (netif_is_ovs_port(dev) && is_vlan_dev(upper_dev)) {
6037 NL_SET_ERR_MSG_MOD(extack, "Can not put a VLAN on an OVS port");
6041 case NETDEV_CHANGEUPPER:
6042 upper_dev = info->upper_dev;
6043 if (netif_is_bridge_master(upper_dev)) {
6045 err = mlxsw_sp_port_bridge_join(mlxsw_sp_port,
6050 mlxsw_sp_port_bridge_leave(mlxsw_sp_port,
6053 } else if (netif_is_lag_master(upper_dev)) {
6054 if (info->linking) {
6055 err = mlxsw_sp_port_lag_join(mlxsw_sp_port,
6058 mlxsw_sp_port_lag_col_dist_disable(mlxsw_sp_port);
6059 mlxsw_sp_port_lag_leave(mlxsw_sp_port,
6062 } else if (netif_is_ovs_master(upper_dev)) {
6064 err = mlxsw_sp_port_ovs_join(mlxsw_sp_port);
6066 mlxsw_sp_port_ovs_leave(mlxsw_sp_port);
6067 } else if (netif_is_macvlan(upper_dev)) {
6069 mlxsw_sp_rif_macvlan_del(mlxsw_sp, upper_dev);
6070 } else if (is_vlan_dev(upper_dev)) {
6071 struct net_device *br_dev;
6073 if (!netif_is_bridge_port(upper_dev))
6077 br_dev = netdev_master_upper_dev_get(upper_dev);
6078 mlxsw_sp_port_bridge_leave(mlxsw_sp_port, upper_dev,
6087 static int mlxsw_sp_netdevice_port_lower_event(struct net_device *dev,
6088 unsigned long event, void *ptr)
6090 struct netdev_notifier_changelowerstate_info *info;
6091 struct mlxsw_sp_port *mlxsw_sp_port;
6094 mlxsw_sp_port = netdev_priv(dev);
6098 case NETDEV_CHANGELOWERSTATE:
6099 if (netif_is_lag_port(dev) && mlxsw_sp_port->lagged) {
6100 err = mlxsw_sp_port_lag_changed(mlxsw_sp_port,
6101 info->lower_state_info);
6103 netdev_err(dev, "Failed to reflect link aggregation lower state change\n");
6111 static int mlxsw_sp_netdevice_port_event(struct net_device *lower_dev,
6112 struct net_device *port_dev,
6113 unsigned long event, void *ptr)
6116 case NETDEV_PRECHANGEUPPER:
6117 case NETDEV_CHANGEUPPER:
6118 return mlxsw_sp_netdevice_port_upper_event(lower_dev, port_dev,
6120 case NETDEV_CHANGELOWERSTATE:
6121 return mlxsw_sp_netdevice_port_lower_event(port_dev, event,
6128 static int mlxsw_sp_netdevice_lag_event(struct net_device *lag_dev,
6129 unsigned long event, void *ptr)
6131 struct net_device *dev;
6132 struct list_head *iter;
6135 netdev_for_each_lower_dev(lag_dev, dev, iter) {
6136 if (mlxsw_sp_port_dev_check(dev)) {
6137 ret = mlxsw_sp_netdevice_port_event(lag_dev, dev, event,
6147 static int mlxsw_sp_netdevice_port_vlan_event(struct net_device *vlan_dev,
6148 struct net_device *dev,
6149 unsigned long event, void *ptr,
6152 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
6153 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
6154 struct netdev_notifier_changeupper_info *info = ptr;
6155 struct netlink_ext_ack *extack;
6156 struct net_device *upper_dev;
6159 extack = netdev_notifier_info_to_extack(&info->info);
6162 case NETDEV_PRECHANGEUPPER:
6163 upper_dev = info->upper_dev;
6164 if (!netif_is_bridge_master(upper_dev) &&
6165 !netif_is_macvlan(upper_dev)) {
6166 NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
6171 if (netif_is_bridge_master(upper_dev) &&
6172 !mlxsw_sp_bridge_device_is_offloaded(mlxsw_sp, upper_dev) &&
6173 mlxsw_sp_bridge_has_vxlan(upper_dev) &&
6174 !mlxsw_sp_bridge_vxlan_is_valid(upper_dev, extack))
6176 if (netdev_has_any_upper_dev(upper_dev) &&
6177 (!netif_is_bridge_master(upper_dev) ||
6178 !mlxsw_sp_bridge_device_is_offloaded(mlxsw_sp,
6180 NL_SET_ERR_MSG_MOD(extack, "Enslaving a port to a device that already has an upper device is not supported");
6183 if (netif_is_macvlan(upper_dev) &&
6184 !mlxsw_sp_rif_find_by_dev(mlxsw_sp, vlan_dev)) {
6185 NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
6189 case NETDEV_CHANGEUPPER:
6190 upper_dev = info->upper_dev;
6191 if (netif_is_bridge_master(upper_dev)) {
6193 err = mlxsw_sp_port_bridge_join(mlxsw_sp_port,
6198 mlxsw_sp_port_bridge_leave(mlxsw_sp_port,
6201 } else if (netif_is_macvlan(upper_dev)) {
6203 mlxsw_sp_rif_macvlan_del(mlxsw_sp, upper_dev);
6214 static int mlxsw_sp_netdevice_lag_port_vlan_event(struct net_device *vlan_dev,
6215 struct net_device *lag_dev,
6216 unsigned long event,
6219 struct net_device *dev;
6220 struct list_head *iter;
6223 netdev_for_each_lower_dev(lag_dev, dev, iter) {
6224 if (mlxsw_sp_port_dev_check(dev)) {
6225 ret = mlxsw_sp_netdevice_port_vlan_event(vlan_dev, dev,
6236 static int mlxsw_sp_netdevice_bridge_vlan_event(struct net_device *vlan_dev,
6237 struct net_device *br_dev,
6238 unsigned long event, void *ptr,
6241 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(vlan_dev);
6242 struct netdev_notifier_changeupper_info *info = ptr;
6243 struct netlink_ext_ack *extack;
6244 struct net_device *upper_dev;
6249 extack = netdev_notifier_info_to_extack(&info->info);
6252 case NETDEV_PRECHANGEUPPER:
6253 upper_dev = info->upper_dev;
6254 if (!netif_is_macvlan(upper_dev)) {
6255 NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
6260 if (netif_is_macvlan(upper_dev) &&
6261 !mlxsw_sp_rif_find_by_dev(mlxsw_sp, vlan_dev)) {
6262 NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
6266 case NETDEV_CHANGEUPPER:
6267 upper_dev = info->upper_dev;
6270 if (netif_is_macvlan(upper_dev))
6271 mlxsw_sp_rif_macvlan_del(mlxsw_sp, upper_dev);
6278 static int mlxsw_sp_netdevice_vlan_event(struct net_device *vlan_dev,
6279 unsigned long event, void *ptr)
6281 struct net_device *real_dev = vlan_dev_real_dev(vlan_dev);
6282 u16 vid = vlan_dev_vlan_id(vlan_dev);
6284 if (mlxsw_sp_port_dev_check(real_dev))
6285 return mlxsw_sp_netdevice_port_vlan_event(vlan_dev, real_dev,
6287 else if (netif_is_lag_master(real_dev))
6288 return mlxsw_sp_netdevice_lag_port_vlan_event(vlan_dev,
6291 else if (netif_is_bridge_master(real_dev))
6292 return mlxsw_sp_netdevice_bridge_vlan_event(vlan_dev, real_dev,
6298 static int mlxsw_sp_netdevice_bridge_event(struct net_device *br_dev,
6299 unsigned long event, void *ptr)
6301 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(br_dev);
6302 struct netdev_notifier_changeupper_info *info = ptr;
6303 struct netlink_ext_ack *extack;
6304 struct net_device *upper_dev;
6309 extack = netdev_notifier_info_to_extack(&info->info);
6312 case NETDEV_PRECHANGEUPPER:
6313 upper_dev = info->upper_dev;
6314 if (!is_vlan_dev(upper_dev) && !netif_is_macvlan(upper_dev)) {
6315 NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
6320 if (netif_is_macvlan(upper_dev) &&
6321 !mlxsw_sp_rif_find_by_dev(mlxsw_sp, br_dev)) {
6322 NL_SET_ERR_MSG_MOD(extack, "macvlan is only supported on top of router interfaces");
6326 case NETDEV_CHANGEUPPER:
6327 upper_dev = info->upper_dev;
6330 if (is_vlan_dev(upper_dev))
6331 mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, upper_dev);
6332 if (netif_is_macvlan(upper_dev))
6333 mlxsw_sp_rif_macvlan_del(mlxsw_sp, upper_dev);
6340 static int mlxsw_sp_netdevice_macvlan_event(struct net_device *macvlan_dev,
6341 unsigned long event, void *ptr)
6343 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_lower_get(macvlan_dev);
6344 struct netdev_notifier_changeupper_info *info = ptr;
6345 struct netlink_ext_ack *extack;
6347 if (!mlxsw_sp || event != NETDEV_PRECHANGEUPPER)
6350 extack = netdev_notifier_info_to_extack(&info->info);
6352 /* VRF enslavement is handled in mlxsw_sp_netdevice_vrf_event() */
6353 NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type");
6358 static bool mlxsw_sp_is_vrf_event(unsigned long event, void *ptr)
6360 struct netdev_notifier_changeupper_info *info = ptr;
6362 if (event != NETDEV_PRECHANGEUPPER && event != NETDEV_CHANGEUPPER)
6364 return netif_is_l3_master(info->upper_dev);
6367 static int mlxsw_sp_netdevice_vxlan_event(struct mlxsw_sp *mlxsw_sp,
6368 struct net_device *dev,
6369 unsigned long event, void *ptr)
6371 struct netdev_notifier_changeupper_info *cu_info;
6372 struct netdev_notifier_info *info = ptr;
6373 struct netlink_ext_ack *extack;
6374 struct net_device *upper_dev;
6376 extack = netdev_notifier_info_to_extack(info);
6379 case NETDEV_CHANGEUPPER:
6380 cu_info = container_of(info,
6381 struct netdev_notifier_changeupper_info,
6383 upper_dev = cu_info->upper_dev;
6384 if (!netif_is_bridge_master(upper_dev))
6386 if (!mlxsw_sp_lower_get(upper_dev))
6388 if (!mlxsw_sp_bridge_vxlan_is_valid(upper_dev, extack))
6390 if (cu_info->linking) {
6391 if (!netif_running(dev))
6393 /* When the bridge is VLAN-aware, the VNI of the VxLAN
6394 * device needs to be mapped to a VLAN, but at this
6395 * point no VLANs are configured on the VxLAN device
6397 if (br_vlan_enabled(upper_dev))
6399 return mlxsw_sp_bridge_vxlan_join(mlxsw_sp, upper_dev,
6402 /* VLANs were already flushed, which triggered the
6405 if (br_vlan_enabled(upper_dev))
6407 mlxsw_sp_bridge_vxlan_leave(mlxsw_sp, dev);
6411 upper_dev = netdev_master_upper_dev_get(dev);
6414 if (!netif_is_bridge_master(upper_dev))
6416 if (!mlxsw_sp_lower_get(upper_dev))
6418 return mlxsw_sp_bridge_vxlan_join(mlxsw_sp, upper_dev, dev, 0,
6421 upper_dev = netdev_master_upper_dev_get(dev);
6424 if (!netif_is_bridge_master(upper_dev))
6426 if (!mlxsw_sp_lower_get(upper_dev))
6428 mlxsw_sp_bridge_vxlan_leave(mlxsw_sp, dev);
6435 static int mlxsw_sp_netdevice_event(struct notifier_block *nb,
6436 unsigned long event, void *ptr)
6438 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
6439 struct mlxsw_sp_span_entry *span_entry;
6440 struct mlxsw_sp *mlxsw_sp;
6443 mlxsw_sp = container_of(nb, struct mlxsw_sp, netdevice_nb);
6444 if (event == NETDEV_UNREGISTER) {
6445 span_entry = mlxsw_sp_span_entry_find_by_port(mlxsw_sp, dev);
6447 mlxsw_sp_span_entry_invalidate(mlxsw_sp, span_entry);
6449 mlxsw_sp_span_respin(mlxsw_sp);
6451 if (netif_is_vxlan(dev))
6452 err = mlxsw_sp_netdevice_vxlan_event(mlxsw_sp, dev, event, ptr);
6453 if (mlxsw_sp_netdev_is_ipip_ol(mlxsw_sp, dev))
6454 err = mlxsw_sp_netdevice_ipip_ol_event(mlxsw_sp, dev,
6456 else if (mlxsw_sp_netdev_is_ipip_ul(mlxsw_sp, dev))
6457 err = mlxsw_sp_netdevice_ipip_ul_event(mlxsw_sp, dev,
6459 else if (event == NETDEV_PRE_CHANGEADDR ||
6460 event == NETDEV_CHANGEADDR ||
6461 event == NETDEV_CHANGEMTU)
6462 err = mlxsw_sp_netdevice_router_port_event(dev, event, ptr);
6463 else if (mlxsw_sp_is_vrf_event(event, ptr))
6464 err = mlxsw_sp_netdevice_vrf_event(dev, event, ptr);
6465 else if (mlxsw_sp_port_dev_check(dev))
6466 err = mlxsw_sp_netdevice_port_event(dev, dev, event, ptr);
6467 else if (netif_is_lag_master(dev))
6468 err = mlxsw_sp_netdevice_lag_event(dev, event, ptr);
6469 else if (is_vlan_dev(dev))
6470 err = mlxsw_sp_netdevice_vlan_event(dev, event, ptr);
6471 else if (netif_is_bridge_master(dev))
6472 err = mlxsw_sp_netdevice_bridge_event(dev, event, ptr);
6473 else if (netif_is_macvlan(dev))
6474 err = mlxsw_sp_netdevice_macvlan_event(dev, event, ptr);
6476 return notifier_from_errno(err);
6479 static struct notifier_block mlxsw_sp_inetaddr_valid_nb __read_mostly = {
6480 .notifier_call = mlxsw_sp_inetaddr_valid_event,
6483 static struct notifier_block mlxsw_sp_inet6addr_valid_nb __read_mostly = {
6484 .notifier_call = mlxsw_sp_inet6addr_valid_event,
6487 static const struct pci_device_id mlxsw_sp1_pci_id_table[] = {
6488 {PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_SPECTRUM), 0},
6492 static struct pci_driver mlxsw_sp1_pci_driver = {
6493 .name = mlxsw_sp1_driver_name,
6494 .id_table = mlxsw_sp1_pci_id_table,
6497 static const struct pci_device_id mlxsw_sp2_pci_id_table[] = {
6498 {PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_SPECTRUM2), 0},
6502 static struct pci_driver mlxsw_sp2_pci_driver = {
6503 .name = mlxsw_sp2_driver_name,
6504 .id_table = mlxsw_sp2_pci_id_table,
6507 static const struct pci_device_id mlxsw_sp3_pci_id_table[] = {
6508 {PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_SPECTRUM3), 0},
6512 static struct pci_driver mlxsw_sp3_pci_driver = {
6513 .name = mlxsw_sp3_driver_name,
6514 .id_table = mlxsw_sp3_pci_id_table,
6517 static int __init mlxsw_sp_module_init(void)
6521 register_inetaddr_validator_notifier(&mlxsw_sp_inetaddr_valid_nb);
6522 register_inet6addr_validator_notifier(&mlxsw_sp_inet6addr_valid_nb);
6524 err = mlxsw_core_driver_register(&mlxsw_sp1_driver);
6526 goto err_sp1_core_driver_register;
6528 err = mlxsw_core_driver_register(&mlxsw_sp2_driver);
6530 goto err_sp2_core_driver_register;
6532 err = mlxsw_core_driver_register(&mlxsw_sp3_driver);
6534 goto err_sp3_core_driver_register;
6536 err = mlxsw_pci_driver_register(&mlxsw_sp1_pci_driver);
6538 goto err_sp1_pci_driver_register;
6540 err = mlxsw_pci_driver_register(&mlxsw_sp2_pci_driver);
6542 goto err_sp2_pci_driver_register;
6544 err = mlxsw_pci_driver_register(&mlxsw_sp3_pci_driver);
6546 goto err_sp3_pci_driver_register;
6550 err_sp3_pci_driver_register:
6551 mlxsw_pci_driver_unregister(&mlxsw_sp2_pci_driver);
6552 err_sp2_pci_driver_register:
6553 mlxsw_pci_driver_unregister(&mlxsw_sp1_pci_driver);
6554 err_sp1_pci_driver_register:
6555 mlxsw_core_driver_unregister(&mlxsw_sp3_driver);
6556 err_sp3_core_driver_register:
6557 mlxsw_core_driver_unregister(&mlxsw_sp2_driver);
6558 err_sp2_core_driver_register:
6559 mlxsw_core_driver_unregister(&mlxsw_sp1_driver);
6560 err_sp1_core_driver_register:
6561 unregister_inet6addr_validator_notifier(&mlxsw_sp_inet6addr_valid_nb);
6562 unregister_inetaddr_validator_notifier(&mlxsw_sp_inetaddr_valid_nb);
6566 static void __exit mlxsw_sp_module_exit(void)
6568 mlxsw_pci_driver_unregister(&mlxsw_sp3_pci_driver);
6569 mlxsw_pci_driver_unregister(&mlxsw_sp2_pci_driver);
6570 mlxsw_pci_driver_unregister(&mlxsw_sp1_pci_driver);
6571 mlxsw_core_driver_unregister(&mlxsw_sp3_driver);
6572 mlxsw_core_driver_unregister(&mlxsw_sp2_driver);
6573 mlxsw_core_driver_unregister(&mlxsw_sp1_driver);
6574 unregister_inet6addr_validator_notifier(&mlxsw_sp_inet6addr_valid_nb);
6575 unregister_inetaddr_validator_notifier(&mlxsw_sp_inetaddr_valid_nb);
6578 module_init(mlxsw_sp_module_init);
6579 module_exit(mlxsw_sp_module_exit);
6581 MODULE_LICENSE("Dual BSD/GPL");
6582 MODULE_AUTHOR("Jiri Pirko <jiri@mellanox.com>");
6583 MODULE_DESCRIPTION("Mellanox Spectrum driver");
6584 MODULE_DEVICE_TABLE(pci, mlxsw_sp1_pci_id_table);
6585 MODULE_DEVICE_TABLE(pci, mlxsw_sp2_pci_id_table);
6586 MODULE_DEVICE_TABLE(pci, mlxsw_sp3_pci_id_table);