Commit e5f12b3f authored by David S. Miller's avatar David S. Miller

Merge branch 'mlxsw-trap-groups-and-policers'

Jiri Pirko says:

====================
mlxsw: traps, trap groups and policers

Nogah says:

For a packet to be sent from the HW to the cpu, it needs to be trapped.
For a trap to be activate it should be assigned to a trap group.
Those trap groups can have policers, to limit the packet rate (the max
number of packets that can be sent to the cpu in a time slot, the rest
will be discarded) or the data rate (the same, but the count is not by the
number of packets but by their total length in bytes).

This patchset rearrange the trap setting API, re-write the traps and the
trap groups list in spectrum and assign them policers.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents eafa6abd 9148e7cf
...@@ -572,27 +572,9 @@ static void mlxsw_emad_rx_listener_func(struct sk_buff *skb, u8 local_port, ...@@ -572,27 +572,9 @@ static void mlxsw_emad_rx_listener_func(struct sk_buff *skb, u8 local_port,
dev_kfree_skb(skb); dev_kfree_skb(skb);
} }
static const struct mlxsw_rx_listener mlxsw_emad_rx_listener = { static const struct mlxsw_listener mlxsw_emad_rx_listener =
.func = mlxsw_emad_rx_listener_func, MLXSW_RXL(mlxsw_emad_rx_listener_func, ETHEMAD, TRAP_TO_CPU, false,
.local_port = MLXSW_PORT_DONT_CARE, EMAD, DISCARD);
.trap_id = MLXSW_TRAP_ID_ETHEMAD,
};
static int mlxsw_emad_traps_set(struct mlxsw_core *mlxsw_core)
{
char htgt_pl[MLXSW_REG_HTGT_LEN];
char hpkt_pl[MLXSW_REG_HPKT_LEN];
int err;
mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_EMAD);
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
if (err)
return err;
mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
MLXSW_TRAP_ID_ETHEMAD);
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
}
static int mlxsw_emad_init(struct mlxsw_core *mlxsw_core) static int mlxsw_emad_init(struct mlxsw_core *mlxsw_core)
{ {
...@@ -613,42 +595,33 @@ static int mlxsw_emad_init(struct mlxsw_core *mlxsw_core) ...@@ -613,42 +595,33 @@ static int mlxsw_emad_init(struct mlxsw_core *mlxsw_core)
INIT_LIST_HEAD(&mlxsw_core->emad.trans_list); INIT_LIST_HEAD(&mlxsw_core->emad.trans_list);
spin_lock_init(&mlxsw_core->emad.trans_list_lock); spin_lock_init(&mlxsw_core->emad.trans_list_lock);
err = mlxsw_core_rx_listener_register(mlxsw_core, err = mlxsw_core_trap_register(mlxsw_core, &mlxsw_emad_rx_listener,
&mlxsw_emad_rx_listener, mlxsw_core);
mlxsw_core);
if (err) if (err)
return err; return err;
err = mlxsw_emad_traps_set(mlxsw_core); err = mlxsw_core->driver->basic_trap_groups_set(mlxsw_core);
if (err) if (err)
goto err_emad_trap_set; goto err_emad_trap_set;
mlxsw_core->emad.use_emad = true; mlxsw_core->emad.use_emad = true;
return 0; return 0;
err_emad_trap_set: err_emad_trap_set:
mlxsw_core_rx_listener_unregister(mlxsw_core, mlxsw_core_trap_unregister(mlxsw_core, &mlxsw_emad_rx_listener,
&mlxsw_emad_rx_listener, mlxsw_core);
mlxsw_core);
return err; return err;
} }
static void mlxsw_emad_fini(struct mlxsw_core *mlxsw_core) static void mlxsw_emad_fini(struct mlxsw_core *mlxsw_core)
{ {
char hpkt_pl[MLXSW_REG_HPKT_LEN];
if (!(mlxsw_core->bus->features & MLXSW_BUS_F_TXRX)) if (!(mlxsw_core->bus->features & MLXSW_BUS_F_TXRX))
return; return;
mlxsw_core->emad.use_emad = false; mlxsw_core->emad.use_emad = false;
mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_DISCARD, mlxsw_core_trap_unregister(mlxsw_core, &mlxsw_emad_rx_listener,
MLXSW_TRAP_ID_ETHEMAD); mlxsw_core);
mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
mlxsw_core_rx_listener_unregister(mlxsw_core,
&mlxsw_emad_rx_listener,
mlxsw_core);
} }
static struct sk_buff *mlxsw_emad_alloc(const struct mlxsw_core *mlxsw_core, static struct sk_buff *mlxsw_emad_alloc(const struct mlxsw_core *mlxsw_core,
...@@ -1392,6 +1365,75 @@ void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core, ...@@ -1392,6 +1365,75 @@ void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core,
} }
EXPORT_SYMBOL(mlxsw_core_event_listener_unregister); EXPORT_SYMBOL(mlxsw_core_event_listener_unregister);
static int mlxsw_core_listener_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener,
void *priv)
{
if (listener->is_event)
return mlxsw_core_event_listener_register(mlxsw_core,
&listener->u.event_listener,
priv);
else
return mlxsw_core_rx_listener_register(mlxsw_core,
&listener->u.rx_listener,
priv);
}
static void mlxsw_core_listener_unregister(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener,
void *priv)
{
if (listener->is_event)
mlxsw_core_event_listener_unregister(mlxsw_core,
&listener->u.event_listener,
priv);
else
mlxsw_core_rx_listener_unregister(mlxsw_core,
&listener->u.rx_listener,
priv);
}
int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener, void *priv)
{
char hpkt_pl[MLXSW_REG_HPKT_LEN];
int err;
err = mlxsw_core_listener_register(mlxsw_core, listener, priv);
if (err)
return err;
mlxsw_reg_hpkt_pack(hpkt_pl, listener->action, listener->trap_id,
listener->trap_group, listener->is_ctrl);
err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
if (err)
goto err_trap_set;
return 0;
err_trap_set:
mlxsw_core_listener_unregister(mlxsw_core, listener, priv);
return err;
}
EXPORT_SYMBOL(mlxsw_core_trap_register);
void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener,
void *priv)
{
char hpkt_pl[MLXSW_REG_HPKT_LEN];
if (!listener->is_event) {
mlxsw_reg_hpkt_pack(hpkt_pl, listener->unreg_action,
listener->trap_id, listener->trap_group,
listener->is_ctrl);
mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
}
mlxsw_core_listener_unregister(mlxsw_core, listener, priv);
}
EXPORT_SYMBOL(mlxsw_core_trap_unregister);
static u64 mlxsw_core_tid_get(struct mlxsw_core *mlxsw_core) static u64 mlxsw_core_tid_get(struct mlxsw_core *mlxsw_core)
{ {
return atomic64_inc_return(&mlxsw_core->emad.tid); return atomic64_inc_return(&mlxsw_core->emad.tid);
......
...@@ -90,6 +90,50 @@ struct mlxsw_event_listener { ...@@ -90,6 +90,50 @@ struct mlxsw_event_listener {
enum mlxsw_event_trap_id trap_id; enum mlxsw_event_trap_id trap_id;
}; };
struct mlxsw_listener {
u16 trap_id;
union {
struct mlxsw_rx_listener rx_listener;
struct mlxsw_event_listener event_listener;
} u;
enum mlxsw_reg_hpkt_action action;
enum mlxsw_reg_hpkt_action unreg_action;
u8 trap_group;
bool is_ctrl; /* should go via control buffer or not */
bool is_event;
};
#define MLXSW_RXL(_func, _trap_id, _action, _is_ctrl, _trap_group, \
_unreg_action) \
{ \
.trap_id = MLXSW_TRAP_ID_##_trap_id, \
.u.rx_listener = \
{ \
.func = _func, \
.local_port = MLXSW_PORT_DONT_CARE, \
.trap_id = MLXSW_TRAP_ID_##_trap_id, \
}, \
.action = MLXSW_REG_HPKT_ACTION_##_action, \
.unreg_action = MLXSW_REG_HPKT_ACTION_##_unreg_action, \
.trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_trap_group, \
.is_ctrl = _is_ctrl, \
.is_event = false, \
}
#define MLXSW_EVENTL(_func, _trap_id, _trap_group) \
{ \
.trap_id = MLXSW_TRAP_ID_##_trap_id, \
.u.event_listener = \
{ \
.func = _func, \
.trap_id = MLXSW_TRAP_ID_##_trap_id, \
}, \
.action = MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU, \
.trap_group = MLXSW_REG_HTGT_TRAP_GROUP_##_trap_group, \
.is_ctrl = false, \
.is_event = true, \
}
int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core, int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_rx_listener *rxl, const struct mlxsw_rx_listener *rxl,
void *priv); void *priv);
...@@ -104,6 +148,13 @@ void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core, ...@@ -104,6 +148,13 @@ void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core,
const struct mlxsw_event_listener *el, const struct mlxsw_event_listener *el,
void *priv); void *priv);
int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener,
void *priv);
void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener,
void *priv);
typedef void mlxsw_reg_trans_cb_t(struct mlxsw_core *mlxsw_core, char *payload, typedef void mlxsw_reg_trans_cb_t(struct mlxsw_core *mlxsw_core, char *payload,
size_t payload_len, unsigned long cb_priv); size_t payload_len, unsigned long cb_priv);
...@@ -214,6 +265,7 @@ struct mlxsw_driver { ...@@ -214,6 +265,7 @@ struct mlxsw_driver {
int (*init)(struct mlxsw_core *mlxsw_core, int (*init)(struct mlxsw_core *mlxsw_core,
const struct mlxsw_bus_info *mlxsw_bus_info); const struct mlxsw_bus_info *mlxsw_bus_info);
void (*fini)(struct mlxsw_core *mlxsw_core); void (*fini)(struct mlxsw_core *mlxsw_core);
int (*basic_trap_groups_set)(struct mlxsw_core *mlxsw_core);
int (*port_type_set)(struct mlxsw_core *mlxsw_core, u8 local_port, int (*port_type_set)(struct mlxsw_core *mlxsw_core, u8 local_port,
enum devlink_port_type new_type); enum devlink_port_type new_type);
int (*port_split)(struct mlxsw_core *mlxsw_core, u8 local_port, int (*port_split)(struct mlxsw_core *mlxsw_core, u8 local_port,
......
...@@ -1757,6 +1757,146 @@ static inline void mlxsw_reg_spvmlr_pack(char *payload, u8 local_port, ...@@ -1757,6 +1757,146 @@ static inline void mlxsw_reg_spvmlr_pack(char *payload, u8 local_port,
} }
} }
/* QPCR - QoS Policer Configuration Register
* -----------------------------------------
* The QPCR register is used to create policers - that limit
* the rate of bytes or packets via some trap group.
*/
#define MLXSW_REG_QPCR_ID 0x4004
#define MLXSW_REG_QPCR_LEN 0x28
MLXSW_REG_DEFINE(qpcr, MLXSW_REG_QPCR_ID, MLXSW_REG_QPCR_LEN);
enum mlxsw_reg_qpcr_g {
MLXSW_REG_QPCR_G_GLOBAL = 2,
MLXSW_REG_QPCR_G_STORM_CONTROL = 3,
};
/* reg_qpcr_g
* The policer type.
* Access: Index
*/
MLXSW_ITEM32(reg, qpcr, g, 0x00, 14, 2);
/* reg_qpcr_pid
* Policer ID.
* Access: Index
*/
MLXSW_ITEM32(reg, qpcr, pid, 0x00, 0, 14);
/* reg_qpcr_color_aware
* Is the policer aware of colors.
* Must be 0 (unaware) for cpu port.
* Access: RW for unbounded policer. RO for bounded policer.
*/
MLXSW_ITEM32(reg, qpcr, color_aware, 0x04, 15, 1);
/* reg_qpcr_bytes
* Is policer limit is for bytes per sec or packets per sec.
* 0 - packets
* 1 - bytes
* Access: RW for unbounded policer. RO for bounded policer.
*/
MLXSW_ITEM32(reg, qpcr, bytes, 0x04, 14, 1);
enum mlxsw_reg_qpcr_ir_units {
MLXSW_REG_QPCR_IR_UNITS_M,
MLXSW_REG_QPCR_IR_UNITS_K,
};
/* reg_qpcr_ir_units
* Policer's units for cir and eir fields (for bytes limits only)
* 1 - 10^3
* 0 - 10^6
* Access: OP
*/
MLXSW_ITEM32(reg, qpcr, ir_units, 0x04, 12, 1);
enum mlxsw_reg_qpcr_rate_type {
MLXSW_REG_QPCR_RATE_TYPE_SINGLE = 1,
MLXSW_REG_QPCR_RATE_TYPE_DOUBLE = 2,
};
/* reg_qpcr_rate_type
* Policer can have one limit (single rate) or 2 limits with specific operation
* for packets that exceed the lower rate but not the upper one.
* (For cpu port must be single rate)
* Access: RW for unbounded policer. RO for bounded policer.
*/
MLXSW_ITEM32(reg, qpcr, rate_type, 0x04, 8, 2);
/* reg_qpc_cbs
* Policer's committed burst size.
* The policer is working with time slices of 50 nano sec. By default every
* slice is granted the proportionate share of the committed rate. If we want to
* allow a slice to exceed that share (while still keeping the rate per sec) we
* can allow burst. The burst size is between the default proportionate share
* (and no lower than 8) to 32Gb. (Even though giving a number higher than the
* committed rate will result in exceeding the rate). The burst size must be a
* log of 2 and will be determined by 2^cbs.
* Access: RW
*/
MLXSW_ITEM32(reg, qpcr, cbs, 0x08, 24, 6);
/* reg_qpcr_cir
* Policer's committed rate.
* The rate used for sungle rate, the lower rate for double rate.
* For bytes limits, the rate will be this value * the unit from ir_units.
* (Resolution error is up to 1%).
* Access: RW
*/
MLXSW_ITEM32(reg, qpcr, cir, 0x0C, 0, 32);
/* reg_qpcr_eir
* Policer's exceed rate.
* The higher rate for double rate, reserved for single rate.
* Lower rate for double rate policer.
* For bytes limits, the rate will be this value * the unit from ir_units.
* (Resolution error is up to 1%).
* Access: RW
*/
MLXSW_ITEM32(reg, qpcr, eir, 0x10, 0, 32);
#define MLXSW_REG_QPCR_DOUBLE_RATE_ACTION 2
/* reg_qpcr_exceed_action.
* What to do with packets between the 2 limits for double rate.
* Access: RW for unbounded policer. RO for bounded policer.
*/
MLXSW_ITEM32(reg, qpcr, exceed_action, 0x14, 0, 4);
enum mlxsw_reg_qpcr_action {
/* Discard */
MLXSW_REG_QPCR_ACTION_DISCARD = 1,
/* Forward and set color to red.
* If the packet is intended to cpu port, it will be dropped.
*/
MLXSW_REG_QPCR_ACTION_FORWARD = 2,
};
/* reg_qpcr_violate_action
* What to do with packets that cross the cir limit (for single rate) or the eir
* limit (for double rate).
* Access: RW for unbounded policer. RO for bounded policer.
*/
MLXSW_ITEM32(reg, qpcr, violate_action, 0x18, 0, 4);
static inline void mlxsw_reg_qpcr_pack(char *payload, u16 pid,
enum mlxsw_reg_qpcr_ir_units ir_units,
bool bytes, u32 cir, u16 cbs)
{
MLXSW_REG_ZERO(qpcr, payload);
mlxsw_reg_qpcr_pid_set(payload, pid);
mlxsw_reg_qpcr_g_set(payload, MLXSW_REG_QPCR_G_GLOBAL);
mlxsw_reg_qpcr_rate_type_set(payload, MLXSW_REG_QPCR_RATE_TYPE_SINGLE);
mlxsw_reg_qpcr_violate_action_set(payload,
MLXSW_REG_QPCR_ACTION_DISCARD);
mlxsw_reg_qpcr_cir_set(payload, cir);
mlxsw_reg_qpcr_ir_units_set(payload, ir_units);
mlxsw_reg_qpcr_bytes_set(payload, bytes);
mlxsw_reg_qpcr_cbs_set(payload, cbs);
}
/* QTCT - QoS Switch Traffic Class Table /* QTCT - QoS Switch Traffic Class Table
* ------------------------------------- * -------------------------------------
* Configures the mapping between the packet switch priority and the * Configures the mapping between the packet switch priority and the
...@@ -3034,8 +3174,21 @@ MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4); ...@@ -3034,8 +3174,21 @@ MLXSW_ITEM32(reg, htgt, type, 0x00, 8, 4);
enum mlxsw_reg_htgt_trap_group { enum mlxsw_reg_htgt_trap_group {
MLXSW_REG_HTGT_TRAP_GROUP_EMAD, MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
MLXSW_REG_HTGT_TRAP_GROUP_RX, MLXSW_REG_HTGT_TRAP_GROUP_SX2_RX,
MLXSW_REG_HTGT_TRAP_GROUP_CTRL, MLXSW_REG_HTGT_TRAP_GROUP_SX2_CTRL,
MLXSW_REG_HTGT_TRAP_GROUP_SP_STP,
MLXSW_REG_HTGT_TRAP_GROUP_SP_LACP,
MLXSW_REG_HTGT_TRAP_GROUP_SP_LLDP,
MLXSW_REG_HTGT_TRAP_GROUP_SP_IGMP,
MLXSW_REG_HTGT_TRAP_GROUP_SP_BGP_IPV4,
MLXSW_REG_HTGT_TRAP_GROUP_SP_OSPF,
MLXSW_REG_HTGT_TRAP_GROUP_SP_ARP,
MLXSW_REG_HTGT_TRAP_GROUP_SP_ARP_MISS,
MLXSW_REG_HTGT_TRAP_GROUP_SP_ROUTER_EXP,
MLXSW_REG_HTGT_TRAP_GROUP_SP_REMOTE_ROUTE,
MLXSW_REG_HTGT_TRAP_GROUP_SP_IP2ME,
MLXSW_REG_HTGT_TRAP_GROUP_SP_DHCP,
MLXSW_REG_HTGT_TRAP_GROUP_SP_EVENT,
}; };
/* reg_htgt_trap_group /* reg_htgt_trap_group
...@@ -3057,6 +3210,8 @@ enum { ...@@ -3057,6 +3210,8 @@ enum {
*/ */
MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1); MLXSW_ITEM32(reg, htgt, pide, 0x04, 15, 1);
#define MLXSW_REG_HTGT_INVALID_POLICER 0xff
/* reg_htgt_pid /* reg_htgt_pid
* Policer ID for the trap group. * Policer ID for the trap group.
* Access: RW * Access: RW
...@@ -3082,6 +3237,8 @@ MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2); ...@@ -3082,6 +3237,8 @@ MLXSW_ITEM32(reg, htgt, mirror_action, 0x08, 8, 2);
*/ */
MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3); MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
#define MLXSW_REG_HTGT_DEFAULT_PRIORITY 0
/* reg_htgt_priority /* reg_htgt_priority
* Trap group priority. * Trap group priority.
* In case a packet matches multiple classification rules, the packet will * In case a packet matches multiple classification rules, the packet will
...@@ -3095,52 +3252,47 @@ MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3); ...@@ -3095,52 +3252,47 @@ MLXSW_ITEM32(reg, htgt, mirroring_agent, 0x08, 0, 3);
*/ */
MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4); MLXSW_ITEM32(reg, htgt, priority, 0x0C, 0, 4);
#define MLXSW_REG_HTGT_DEFAULT_TC 7
/* reg_htgt_local_path_cpu_tclass /* reg_htgt_local_path_cpu_tclass
* CPU ingress traffic class for the trap group. * CPU ingress traffic class for the trap group.
* Access: RW * Access: RW
*/ */
MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6); MLXSW_ITEM32(reg, htgt, local_path_cpu_tclass, 0x10, 16, 6);
#define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD 0x15 enum mlxsw_reg_htgt_local_path_rdq {
#define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX 0x14 MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_CTRL = 0x13,
#define MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL 0x13 MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_RX = 0x14,
MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_EMAD = 0x15,
MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SIB_EMAD = 0x15,
};
/* reg_htgt_local_path_rdq /* reg_htgt_local_path_rdq
* Receive descriptor queue (RDQ) to use for the trap group. * Receive descriptor queue (RDQ) to use for the trap group.
* Access: RW * Access: RW
*/ */
MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6); MLXSW_ITEM32(reg, htgt, local_path_rdq, 0x10, 0, 6);
static inline void mlxsw_reg_htgt_pack(char *payload, static inline void mlxsw_reg_htgt_pack(char *payload, u8 group, u8 policer_id,
enum mlxsw_reg_htgt_trap_group group) u8 priority, u8 tc)
{ {
u8 swid, rdq;
MLXSW_REG_ZERO(htgt, payload); MLXSW_REG_ZERO(htgt, payload);
switch (group) {
case MLXSW_REG_HTGT_TRAP_GROUP_EMAD: if (policer_id == MLXSW_REG_HTGT_INVALID_POLICER) {
swid = MLXSW_PORT_SWID_ALL_SWIDS; mlxsw_reg_htgt_pide_set(payload,
rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_EMAD; MLXSW_REG_HTGT_POLICER_DISABLE);
break; } else {
case MLXSW_REG_HTGT_TRAP_GROUP_RX: mlxsw_reg_htgt_pide_set(payload,
swid = 0; MLXSW_REG_HTGT_POLICER_ENABLE);
rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_RX; mlxsw_reg_htgt_pid_set(payload, policer_id);
break;
case MLXSW_REG_HTGT_TRAP_GROUP_CTRL:
swid = 0;
rdq = MLXSW_REG_HTGT_LOCAL_PATH_RDQ_CTRL;
break;
} }
mlxsw_reg_htgt_swid_set(payload, swid);
mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL); mlxsw_reg_htgt_type_set(payload, MLXSW_REG_HTGT_PATH_TYPE_LOCAL);
mlxsw_reg_htgt_trap_group_set(payload, group); mlxsw_reg_htgt_trap_group_set(payload, group);
mlxsw_reg_htgt_pide_set(payload, MLXSW_REG_HTGT_POLICER_DISABLE);
mlxsw_reg_htgt_pid_set(payload, 0);
mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU); mlxsw_reg_htgt_mirror_action_set(payload, MLXSW_REG_HTGT_TRAP_TO_CPU);
mlxsw_reg_htgt_mirroring_agent_set(payload, 0); mlxsw_reg_htgt_mirroring_agent_set(payload, 0);
mlxsw_reg_htgt_priority_set(payload, 0); mlxsw_reg_htgt_priority_set(payload, priority);
mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, 7); mlxsw_reg_htgt_local_path_cpu_tclass_set(payload, tc);
mlxsw_reg_htgt_local_path_rdq_set(payload, rdq); mlxsw_reg_htgt_local_path_rdq_set(payload, group);
} }
/* HPKT - Host Packet Trap /* HPKT - Host Packet Trap
...@@ -3214,6 +3366,7 @@ enum { ...@@ -3214,6 +3366,7 @@ enum {
/* reg_hpkt_ctrl /* reg_hpkt_ctrl
* Configure dedicated buffer resources for control packets. * Configure dedicated buffer resources for control packets.
* Ignored by SwitchX-2.
* 0 - Keep factory defaults. * 0 - Keep factory defaults.
* 1 - Do not use control buffer for this trap ID. * 1 - Do not use control buffer for this trap ID.
* 2 - Use control buffer for this trap ID. * 2 - Use control buffer for this trap ID.
...@@ -3221,25 +3374,18 @@ enum { ...@@ -3221,25 +3374,18 @@ enum {
*/ */
MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2); MLXSW_ITEM32(reg, hpkt, ctrl, 0x04, 16, 2);
static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id) static inline void mlxsw_reg_hpkt_pack(char *payload, u8 action, u16 trap_id,
enum mlxsw_reg_htgt_trap_group trap_group,
bool is_ctrl)
{ {
enum mlxsw_reg_htgt_trap_group trap_group;
MLXSW_REG_ZERO(hpkt, payload); MLXSW_REG_ZERO(hpkt, payload);
mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED); mlxsw_reg_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
mlxsw_reg_hpkt_action_set(payload, action); mlxsw_reg_hpkt_action_set(payload, action);
switch (trap_id) {
case MLXSW_TRAP_ID_ETHEMAD:
case MLXSW_TRAP_ID_PUDE:
trap_group = MLXSW_REG_HTGT_TRAP_GROUP_EMAD;
break;
default:
trap_group = MLXSW_REG_HTGT_TRAP_GROUP_RX;
break;
}
mlxsw_reg_hpkt_trap_group_set(payload, trap_group); mlxsw_reg_hpkt_trap_group_set(payload, trap_group);
mlxsw_reg_hpkt_trap_id_set(payload, trap_id); mlxsw_reg_hpkt_trap_id_set(payload, trap_id);
mlxsw_reg_hpkt_ctrl_set(payload, MLXSW_REG_HPKT_CTRL_PACKET_DEFAULT); mlxsw_reg_hpkt_ctrl_set(payload, is_ctrl ?
MLXSW_REG_HPKT_CTRL_PACKET_USE_BUFFER :
MLXSW_REG_HPKT_CTRL_PACKET_NO_BUFFER);
} }
/* RGCR - Router General Configuration Register /* RGCR - Router General Configuration Register
...@@ -5248,6 +5394,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = { ...@@ -5248,6 +5394,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = {
MLXSW_REG(svpe), MLXSW_REG(svpe),
MLXSW_REG(sfmr), MLXSW_REG(sfmr),
MLXSW_REG(spvmlr), MLXSW_REG(spvmlr),
MLXSW_REG(qpcr),
MLXSW_REG(qtct), MLXSW_REG(qtct),
MLXSW_REG(qeec), MLXSW_REG(qeec),
MLXSW_REG(pmlp), MLXSW_REG(pmlp),
......
...@@ -42,10 +42,12 @@ enum mlxsw_res_id { ...@@ -42,10 +42,12 @@ enum mlxsw_res_id {
MLXSW_RES_ID_KVD_SIZE, MLXSW_RES_ID_KVD_SIZE,
MLXSW_RES_ID_KVD_SINGLE_MIN_SIZE, MLXSW_RES_ID_KVD_SINGLE_MIN_SIZE,
MLXSW_RES_ID_KVD_DOUBLE_MIN_SIZE, MLXSW_RES_ID_KVD_DOUBLE_MIN_SIZE,
MLXSW_RES_ID_MAX_TRAP_GROUPS,
MLXSW_RES_ID_MAX_SPAN, MLXSW_RES_ID_MAX_SPAN,
MLXSW_RES_ID_MAX_SYSTEM_PORT, MLXSW_RES_ID_MAX_SYSTEM_PORT,
MLXSW_RES_ID_MAX_LAG, MLXSW_RES_ID_MAX_LAG,
MLXSW_RES_ID_MAX_LAG_MEMBERS, MLXSW_RES_ID_MAX_LAG_MEMBERS,
MLXSW_RES_ID_MAX_CPU_POLICERS,
MLXSW_RES_ID_MAX_VRS, MLXSW_RES_ID_MAX_VRS,
MLXSW_RES_ID_MAX_RIFS, MLXSW_RES_ID_MAX_RIFS,
...@@ -63,10 +65,12 @@ static u16 mlxsw_res_ids[] = { ...@@ -63,10 +65,12 @@ static u16 mlxsw_res_ids[] = {
[MLXSW_RES_ID_KVD_SIZE] = 0x1001, [MLXSW_RES_ID_KVD_SIZE] = 0x1001,
[MLXSW_RES_ID_KVD_SINGLE_MIN_SIZE] = 0x1002, [MLXSW_RES_ID_KVD_SINGLE_MIN_SIZE] = 0x1002,
[MLXSW_RES_ID_KVD_DOUBLE_MIN_SIZE] = 0x1003, [MLXSW_RES_ID_KVD_DOUBLE_MIN_SIZE] = 0x1003,
[MLXSW_RES_ID_MAX_TRAP_GROUPS] = 0x2201,
[MLXSW_RES_ID_MAX_SPAN] = 0x2420, [MLXSW_RES_ID_MAX_SPAN] = 0x2420,
[MLXSW_RES_ID_MAX_SYSTEM_PORT] = 0x2502, [MLXSW_RES_ID_MAX_SYSTEM_PORT] = 0x2502,
[MLXSW_RES_ID_MAX_LAG] = 0x2520, [MLXSW_RES_ID_MAX_LAG] = 0x2520,
[MLXSW_RES_ID_MAX_LAG_MEMBERS] = 0x2521, [MLXSW_RES_ID_MAX_LAG_MEMBERS] = 0x2521,
[MLXSW_RES_ID_MAX_CPU_POLICERS] = 0x2A13,
[MLXSW_RES_ID_MAX_VRS] = 0x2C01, [MLXSW_RES_ID_MAX_VRS] = 0x2C01,
[MLXSW_RES_ID_MAX_RIFS] = 0x2C02, [MLXSW_RES_ID_MAX_RIFS] = 0x2C02,
}; };
......
...@@ -408,51 +408,57 @@ static void mlxsw_sib_pude_event_func(const struct mlxsw_reg_info *reg, ...@@ -408,51 +408,57 @@ static void mlxsw_sib_pude_event_func(const struct mlxsw_reg_info *reg,
mlxsw_sib_pude_ib_event_func(mlxsw_sib_port, status); mlxsw_sib_pude_ib_event_func(mlxsw_sib_port, status);
} }
static struct mlxsw_event_listener mlxsw_sib_pude_event = { static const struct mlxsw_listener mlxsw_sib_listener[] = {
.func = mlxsw_sib_pude_event_func, MLXSW_EVENTL(mlxsw_sib_pude_event_func, PUDE, EMAD),
.trap_id = MLXSW_TRAP_ID_PUDE,
}; };
static int mlxsw_sib_event_register(struct mlxsw_sib *mlxsw_sib, static int mlxsw_sib_taps_init(struct mlxsw_sib *mlxsw_sib)
enum mlxsw_event_trap_id trap_id)
{ {
struct mlxsw_event_listener *el; int i;
char hpkt_pl[MLXSW_REG_HPKT_LEN];
int err; int err;
switch (trap_id) { for (i = 0; i < ARRAY_SIZE(mlxsw_sib_listener); i++) {
case MLXSW_TRAP_ID_PUDE: err = mlxsw_core_trap_register(mlxsw_sib->core,
el = &mlxsw_sib_pude_event; &mlxsw_sib_listener[i],
break; mlxsw_sib);
if (err)
goto err_rx_listener_register;
} }
err = mlxsw_core_event_listener_register(mlxsw_sib->core, el,
mlxsw_sib);
if (err)
return err;
mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_FORWARD, trap_id);
err = mlxsw_reg_write(mlxsw_sib->core, MLXSW_REG(hpkt), hpkt_pl);
if (err)
goto err_event_trap_set;
return 0; return 0;
err_event_trap_set: err_rx_listener_register:
mlxsw_core_event_listener_unregister(mlxsw_sib->core, el, mlxsw_sib); for (i--; i >= 0; i--) {
mlxsw_core_trap_unregister(mlxsw_sib->core,
&mlxsw_sib_listener[i],
mlxsw_sib);
}
return err; return err;
} }
static void mlxsw_sib_event_unregister(struct mlxsw_sib *mlxsw_sib, static void mlxsw_sib_traps_fini(struct mlxsw_sib *mlxsw_sib)
enum mlxsw_event_trap_id trap_id)
{ {
struct mlxsw_event_listener *el; int i;
switch (trap_id) { for (i = 0; i < ARRAY_SIZE(mlxsw_sib_listener); i++) {
case MLXSW_TRAP_ID_PUDE: mlxsw_core_trap_unregister(mlxsw_sib->core,
el = &mlxsw_sib_pude_event; &mlxsw_sib_listener[i], mlxsw_sib);
break;
} }
mlxsw_core_event_listener_unregister(mlxsw_sib->core, el, mlxsw_sib); }
static int mlxsw_sib_basic_trap_groups_set(struct mlxsw_core *mlxsw_core)
{
char htgt_pl[MLXSW_REG_HTGT_LEN];
mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
MLXSW_REG_HTGT_INVALID_POLICER,
MLXSW_REG_HTGT_DEFAULT_PRIORITY,
MLXSW_REG_HTGT_DEFAULT_TC);
mlxsw_reg_htgt_swid_set(htgt_pl, MLXSW_PORT_SWID_ALL_SWIDS);
mlxsw_reg_htgt_local_path_rdq_set(htgt_pl,
MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SIB_EMAD);
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
} }
static int mlxsw_sib_init(struct mlxsw_core *mlxsw_core, static int mlxsw_sib_init(struct mlxsw_core *mlxsw_core,
...@@ -470,15 +476,15 @@ static int mlxsw_sib_init(struct mlxsw_core *mlxsw_core, ...@@ -470,15 +476,15 @@ static int mlxsw_sib_init(struct mlxsw_core *mlxsw_core,
return err; return err;
} }
err = mlxsw_sib_event_register(mlxsw_sib, MLXSW_TRAP_ID_PUDE); err = mlxsw_sib_taps_init(mlxsw_sib);
if (err) { if (err) {
dev_err(mlxsw_sib->bus_info->dev, "Failed to register for PUDE events\n"); dev_err(mlxsw_sib->bus_info->dev, "Failed to set traps\n");
goto err_event_register; goto err_traps_init_err;
} }
return 0; return 0;
err_event_register: err_traps_init_err:
mlxsw_sib_ports_remove(mlxsw_sib); mlxsw_sib_ports_remove(mlxsw_sib);
return err; return err;
} }
...@@ -487,7 +493,7 @@ static void mlxsw_sib_fini(struct mlxsw_core *mlxsw_core) ...@@ -487,7 +493,7 @@ static void mlxsw_sib_fini(struct mlxsw_core *mlxsw_core)
{ {
struct mlxsw_sib *mlxsw_sib = mlxsw_core_driver_priv(mlxsw_core); struct mlxsw_sib *mlxsw_sib = mlxsw_core_driver_priv(mlxsw_core);
mlxsw_sib_event_unregister(mlxsw_sib, MLXSW_TRAP_ID_PUDE); mlxsw_sib_traps_fini(mlxsw_sib);
mlxsw_sib_ports_remove(mlxsw_sib); mlxsw_sib_ports_remove(mlxsw_sib);
} }
...@@ -512,6 +518,7 @@ static struct mlxsw_driver mlxsw_sib_driver = { ...@@ -512,6 +518,7 @@ static struct mlxsw_driver mlxsw_sib_driver = {
.priv_size = sizeof(struct mlxsw_sib), .priv_size = sizeof(struct mlxsw_sib),
.init = mlxsw_sib_init, .init = mlxsw_sib_init,
.fini = mlxsw_sib_fini, .fini = mlxsw_sib_fini,
.basic_trap_groups_set = mlxsw_sib_basic_trap_groups_set,
.txhdr_construct = mlxsw_sib_tx_v1_hdr_construct, .txhdr_construct = mlxsw_sib_tx_v1_hdr_construct,
.txhdr_len = MLXSW_TXHDR_LEN, .txhdr_len = MLXSW_TXHDR_LEN,
.profile = &mlxsw_sib_config_profile, .profile = &mlxsw_sib_config_profile,
...@@ -522,6 +529,7 @@ static struct mlxsw_driver mlxsw_sib2_driver = { ...@@ -522,6 +529,7 @@ static struct mlxsw_driver mlxsw_sib2_driver = {
.priv_size = sizeof(struct mlxsw_sib), .priv_size = sizeof(struct mlxsw_sib),
.init = mlxsw_sib_init, .init = mlxsw_sib_init,
.fini = mlxsw_sib_fini, .fini = mlxsw_sib_fini,
.basic_trap_groups_set = mlxsw_sib_basic_trap_groups_set,
.txhdr_construct = mlxsw_sib_tx_v1_hdr_construct, .txhdr_construct = mlxsw_sib_tx_v1_hdr_construct,
.txhdr_len = MLXSW_TXHDR_LEN, .txhdr_len = MLXSW_TXHDR_LEN,
.profile = &mlxsw_sib_config_profile, .profile = &mlxsw_sib_config_profile,
......
...@@ -1396,52 +1396,6 @@ static void mlxsw_sx_pude_event_func(const struct mlxsw_reg_info *reg, ...@@ -1396,52 +1396,6 @@ static void mlxsw_sx_pude_event_func(const struct mlxsw_reg_info *reg,
mlxsw_sx_pude_ib_event_func(mlxsw_sx_port, status); mlxsw_sx_pude_ib_event_func(mlxsw_sx_port, status);
} }
static struct mlxsw_event_listener mlxsw_sx_pude_event = {
.func = mlxsw_sx_pude_event_func,
.trap_id = MLXSW_TRAP_ID_PUDE,
};
static int mlxsw_sx_event_register(struct mlxsw_sx *mlxsw_sx,
enum mlxsw_event_trap_id trap_id)
{
struct mlxsw_event_listener *el;
char hpkt_pl[MLXSW_REG_HPKT_LEN];
int err;
switch (trap_id) {
case MLXSW_TRAP_ID_PUDE:
el = &mlxsw_sx_pude_event;
break;
}
err = mlxsw_core_event_listener_register(mlxsw_sx->core, el, mlxsw_sx);
if (err)
return err;
mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_FORWARD, trap_id);
err = mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(hpkt), hpkt_pl);
if (err)
goto err_event_trap_set;
return 0;
err_event_trap_set:
mlxsw_core_event_listener_unregister(mlxsw_sx->core, el, mlxsw_sx);
return err;
}
static void mlxsw_sx_event_unregister(struct mlxsw_sx *mlxsw_sx,
enum mlxsw_event_trap_id trap_id)
{
struct mlxsw_event_listener *el;
switch (trap_id) {
case MLXSW_TRAP_ID_PUDE:
el = &mlxsw_sx_pude_event;
break;
}
mlxsw_core_event_listener_unregister(mlxsw_sx->core, el, mlxsw_sx);
}
static void mlxsw_sx_rx_listener_func(struct sk_buff *skb, u8 local_port, static void mlxsw_sx_rx_listener_func(struct sk_buff *skb, u8 local_port,
void *priv) void *priv)
{ {
...@@ -1494,142 +1448,83 @@ static int mlxsw_sx_port_type_set(struct mlxsw_core *mlxsw_core, u8 local_port, ...@@ -1494,142 +1448,83 @@ static int mlxsw_sx_port_type_set(struct mlxsw_core *mlxsw_core, u8 local_port,
return err; return err;
} }
static const struct mlxsw_rx_listener mlxsw_sx_rx_listener[] = { #define MLXSW_SX_RXL(_trap_id) \
{ MLXSW_RXL(mlxsw_sx_rx_listener_func, _trap_id, TRAP_TO_CPU, \
.func = mlxsw_sx_rx_listener_func, false, SX2_RX, FORWARD)
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_FDB_MC, static const struct mlxsw_listener mlxsw_sx_listener[] = {
}, MLXSW_EVENTL(mlxsw_sx_pude_event_func, PUDE, EMAD),
/* Traps for specific L2 packet types, not trapped as FDB MC */ MLXSW_SX_RXL(FDB_MC),
{ MLXSW_SX_RXL(STP),
.func = mlxsw_sx_rx_listener_func, MLXSW_SX_RXL(LACP),
.local_port = MLXSW_PORT_DONT_CARE, MLXSW_SX_RXL(EAPOL),
.trap_id = MLXSW_TRAP_ID_STP, MLXSW_SX_RXL(LLDP),
}, MLXSW_SX_RXL(MMRP),
{ MLXSW_SX_RXL(MVRP),
.func = mlxsw_sx_rx_listener_func, MLXSW_SX_RXL(RPVST),
.local_port = MLXSW_PORT_DONT_CARE, MLXSW_SX_RXL(DHCP),
.trap_id = MLXSW_TRAP_ID_LACP, MLXSW_SX_RXL(IGMP_QUERY),
}, MLXSW_SX_RXL(IGMP_V1_REPORT),
{ MLXSW_SX_RXL(IGMP_V2_REPORT),
.func = mlxsw_sx_rx_listener_func, MLXSW_SX_RXL(IGMP_V2_LEAVE),
.local_port = MLXSW_PORT_DONT_CARE, MLXSW_SX_RXL(IGMP_V3_REPORT),
.trap_id = MLXSW_TRAP_ID_EAPOL,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_LLDP,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_MMRP,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_MVRP,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_RPVST,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_DHCP,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_IGMP_QUERY,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_IGMP_V1_REPORT,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_IGMP_V2_REPORT,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_IGMP_V2_LEAVE,
},
{
.func = mlxsw_sx_rx_listener_func,
.local_port = MLXSW_PORT_DONT_CARE,
.trap_id = MLXSW_TRAP_ID_IGMP_V3_REPORT,
},
}; };
static int mlxsw_sx_traps_init(struct mlxsw_sx *mlxsw_sx) static int mlxsw_sx_traps_init(struct mlxsw_sx *mlxsw_sx)
{ {
char htgt_pl[MLXSW_REG_HTGT_LEN]; char htgt_pl[MLXSW_REG_HTGT_LEN];
char hpkt_pl[MLXSW_REG_HPKT_LEN];
int i; int i;
int err; int err;
mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_RX); mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_SX2_RX,
MLXSW_REG_HTGT_INVALID_POLICER,
MLXSW_REG_HTGT_DEFAULT_PRIORITY,
MLXSW_REG_HTGT_DEFAULT_TC);
mlxsw_reg_htgt_local_path_rdq_set(htgt_pl,
MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_RX);
err = mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(htgt), htgt_pl); err = mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(htgt), htgt_pl);
if (err) if (err)
return err; return err;
mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_CTRL); mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_SX2_CTRL,
MLXSW_REG_HTGT_INVALID_POLICER,
MLXSW_REG_HTGT_DEFAULT_PRIORITY,
MLXSW_REG_HTGT_DEFAULT_TC);
mlxsw_reg_htgt_local_path_rdq_set(htgt_pl,
MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_CTRL);
err = mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(htgt), htgt_pl); err = mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(htgt), htgt_pl);
if (err) if (err)
return err; return err;
for (i = 0; i < ARRAY_SIZE(mlxsw_sx_rx_listener); i++) { for (i = 0; i < ARRAY_SIZE(mlxsw_sx_listener); i++) {
err = mlxsw_core_rx_listener_register(mlxsw_sx->core, err = mlxsw_core_trap_register(mlxsw_sx->core,
&mlxsw_sx_rx_listener[i], &mlxsw_sx_listener[i],
mlxsw_sx); mlxsw_sx);
if (err) if (err)
goto err_rx_listener_register; goto err_listener_register;
mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
mlxsw_sx_rx_listener[i].trap_id);
err = mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(hpkt), hpkt_pl);
if (err)
goto err_rx_trap_set;
} }
return 0; return 0;
err_rx_trap_set: err_listener_register:
mlxsw_core_rx_listener_unregister(mlxsw_sx->core,
&mlxsw_sx_rx_listener[i],
mlxsw_sx);
err_rx_listener_register:
for (i--; i >= 0; i--) { for (i--; i >= 0; i--) {
mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_FORWARD, mlxsw_core_trap_unregister(mlxsw_sx->core,
mlxsw_sx_rx_listener[i].trap_id); &mlxsw_sx_listener[i],
mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(hpkt), hpkt_pl); mlxsw_sx);
mlxsw_core_rx_listener_unregister(mlxsw_sx->core,
&mlxsw_sx_rx_listener[i],
mlxsw_sx);
} }
return err; return err;
} }
static void mlxsw_sx_traps_fini(struct mlxsw_sx *mlxsw_sx) static void mlxsw_sx_traps_fini(struct mlxsw_sx *mlxsw_sx)
{ {
char hpkt_pl[MLXSW_REG_HPKT_LEN];
int i; int i;
for (i = 0; i < ARRAY_SIZE(mlxsw_sx_rx_listener); i++) { for (i = 0; i < ARRAY_SIZE(mlxsw_sx_listener); i++) {
mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_FORWARD, mlxsw_core_trap_unregister(mlxsw_sx->core,
mlxsw_sx_rx_listener[i].trap_id); &mlxsw_sx_listener[i],
mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(hpkt), hpkt_pl); mlxsw_sx);
mlxsw_core_rx_listener_unregister(mlxsw_sx->core,
&mlxsw_sx_rx_listener[i],
mlxsw_sx);
} }
} }
...@@ -1701,6 +1596,20 @@ static int mlxsw_sx_flood_init(struct mlxsw_sx *mlxsw_sx) ...@@ -1701,6 +1596,20 @@ static int mlxsw_sx_flood_init(struct mlxsw_sx *mlxsw_sx)
return mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(sgcr), sgcr_pl); return mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(sgcr), sgcr_pl);
} }
static int mlxsw_sx_basic_trap_groups_set(struct mlxsw_core *mlxsw_core)
{
char htgt_pl[MLXSW_REG_HTGT_LEN];
mlxsw_reg_htgt_pack(htgt_pl, MLXSW_REG_HTGT_TRAP_GROUP_EMAD,
MLXSW_REG_HTGT_INVALID_POLICER,
MLXSW_REG_HTGT_DEFAULT_PRIORITY,
MLXSW_REG_HTGT_DEFAULT_TC);
mlxsw_reg_htgt_swid_set(htgt_pl, MLXSW_PORT_SWID_ALL_SWIDS);
mlxsw_reg_htgt_local_path_rdq_set(htgt_pl,
MLXSW_REG_HTGT_LOCAL_PATH_RDQ_SX2_EMAD);
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(htgt), htgt_pl);
}
static int mlxsw_sx_init(struct mlxsw_core *mlxsw_core, static int mlxsw_sx_init(struct mlxsw_core *mlxsw_core,
const struct mlxsw_bus_info *mlxsw_bus_info) const struct mlxsw_bus_info *mlxsw_bus_info)
{ {
...@@ -1722,16 +1631,10 @@ static int mlxsw_sx_init(struct mlxsw_core *mlxsw_core, ...@@ -1722,16 +1631,10 @@ static int mlxsw_sx_init(struct mlxsw_core *mlxsw_core,
return err; return err;
} }
err = mlxsw_sx_event_register(mlxsw_sx, MLXSW_TRAP_ID_PUDE);
if (err) {
dev_err(mlxsw_sx->bus_info->dev, "Failed to register for PUDE events\n");
goto err_event_register;
}
err = mlxsw_sx_traps_init(mlxsw_sx); err = mlxsw_sx_traps_init(mlxsw_sx);
if (err) { if (err) {
dev_err(mlxsw_sx->bus_info->dev, "Failed to set traps for RX\n"); dev_err(mlxsw_sx->bus_info->dev, "Failed to set traps\n");
goto err_rx_listener_register; goto err_listener_register;
} }
err = mlxsw_sx_flood_init(mlxsw_sx); err = mlxsw_sx_flood_init(mlxsw_sx);
...@@ -1744,9 +1647,7 @@ static int mlxsw_sx_init(struct mlxsw_core *mlxsw_core, ...@@ -1744,9 +1647,7 @@ static int mlxsw_sx_init(struct mlxsw_core *mlxsw_core,
err_flood_init: err_flood_init:
mlxsw_sx_traps_fini(mlxsw_sx); mlxsw_sx_traps_fini(mlxsw_sx);
err_rx_listener_register: err_listener_register:
mlxsw_sx_event_unregister(mlxsw_sx, MLXSW_TRAP_ID_PUDE);
err_event_register:
mlxsw_sx_ports_remove(mlxsw_sx); mlxsw_sx_ports_remove(mlxsw_sx);
return err; return err;
} }
...@@ -1756,7 +1657,6 @@ static void mlxsw_sx_fini(struct mlxsw_core *mlxsw_core) ...@@ -1756,7 +1657,6 @@ static void mlxsw_sx_fini(struct mlxsw_core *mlxsw_core)
struct mlxsw_sx *mlxsw_sx = mlxsw_core_driver_priv(mlxsw_core); struct mlxsw_sx *mlxsw_sx = mlxsw_core_driver_priv(mlxsw_core);
mlxsw_sx_traps_fini(mlxsw_sx); mlxsw_sx_traps_fini(mlxsw_sx);
mlxsw_sx_event_unregister(mlxsw_sx, MLXSW_TRAP_ID_PUDE);
mlxsw_sx_ports_remove(mlxsw_sx); mlxsw_sx_ports_remove(mlxsw_sx);
} }
...@@ -1800,6 +1700,7 @@ static struct mlxsw_driver mlxsw_sx_driver = { ...@@ -1800,6 +1700,7 @@ static struct mlxsw_driver mlxsw_sx_driver = {
.priv_size = sizeof(struct mlxsw_sx), .priv_size = sizeof(struct mlxsw_sx),
.init = mlxsw_sx_init, .init = mlxsw_sx_init,
.fini = mlxsw_sx_fini, .fini = mlxsw_sx_fini,
.basic_trap_groups_set = mlxsw_sx_basic_trap_groups_set,
.txhdr_construct = mlxsw_sx_txhdr_construct, .txhdr_construct = mlxsw_sx_txhdr_construct,
.txhdr_len = MLXSW_TXHDR_LEN, .txhdr_len = MLXSW_TXHDR_LEN,
.profile = &mlxsw_sx_config_profile, .profile = &mlxsw_sx_config_profile,
......
...@@ -62,6 +62,7 @@ enum { ...@@ -62,6 +62,7 @@ enum {
MLXSW_TRAP_ID_OSPF = 0x55, MLXSW_TRAP_ID_OSPF = 0x55,
MLXSW_TRAP_ID_IP2ME = 0x5F, MLXSW_TRAP_ID_IP2ME = 0x5F,
MLXSW_TRAP_ID_RTR_INGRESS0 = 0x70, MLXSW_TRAP_ID_RTR_INGRESS0 = 0x70,
MLXSW_TRAP_ID_BGP_IPV4 = 0x88,
MLXSW_TRAP_ID_HOST_MISS_IPV4 = 0x90, MLXSW_TRAP_ID_HOST_MISS_IPV4 = 0x90,
MLXSW_TRAP_ID_MAX = 0x1FF MLXSW_TRAP_ID_MAX = 0x1FF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment