mlxsw: Change trap set function
authorNogah Frankel <nogahf@mellanox.com>
Fri, 25 Nov 2016 09:33:38 +0000 (10:33 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sat, 26 Nov 2016 02:22:14 +0000 (21:22 -0500)
Change trap setting function so instead of determining the trap group by
trap id, it gets it as a parameter (so later we can have different trap
groups for Spectrum and Switchx2).
Add "is_ctrl" parameter to the trap setting function. It control whether
the trapped packets wait in a designated control buffer or in their
default one. This parameter is ignored by Switchx2 and Switchib.
Add these parameters to the traps array in Spectrum, Switchx2 and
Switchib.

Signed-off-by: Nogah Frankel <nogahf@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/core.c
drivers/net/ethernet/mellanox/mlxsw/core.h
drivers/net/ethernet/mellanox/mlxsw/reg.h
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/switchx2.c

index a8cff78c7029ee54dc4deea8061ec9cd0debe17b..d3b82d6e35d18e0fd01dfbfc5853a712bac23ca6 100644 (file)
@@ -590,7 +590,8 @@ static int mlxsw_emad_traps_set(struct mlxsw_core *mlxsw_core)
                return err;
 
        mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,
-                           MLXSW_TRAP_ID_ETHEMAD);
+                           MLXSW_TRAP_ID_ETHEMAD,
+                           MLXSW_REG_HTGT_TRAP_GROUP_EMAD, false);
        return mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
 }
 
@@ -643,7 +644,8 @@ static void mlxsw_emad_fini(struct mlxsw_core *mlxsw_core)
 
        mlxsw_core->emad.use_emad = false;
        mlxsw_reg_hpkt_pack(hpkt_pl, MLXSW_REG_HPKT_ACTION_DISCARD,
-                           MLXSW_TRAP_ID_ETHEMAD);
+                           MLXSW_TRAP_ID_ETHEMAD,
+                           MLXSW_REG_HTGT_TRAP_GROUP_EMAD, false);
        mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
 
        mlxsw_core_rx_listener_unregister(mlxsw_core,
@@ -1430,8 +1432,9 @@ int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core,
        if (err)
                return err;
 
-       mlxsw_reg_hpkt_pack(hpkt_pl, listener->action, listener->trap_id);
-       err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
+       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;
 
@@ -1451,7 +1454,8 @@ void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core,
 
        if (!listener->is_event) {
                mlxsw_reg_hpkt_pack(hpkt_pl, listener->unreg_action,
-                                   listener->trap_id);
+                                   listener->trap_id, listener->trap_group,
+                                   listener->is_ctrl);
                mlxsw_reg_write(mlxsw_core, MLXSW_REG(hpkt), hpkt_pl);
        }
 
index 852218e44b23edb456c80a1922b90d335eeb4275..b5b5b367d25c3dbc97ef0f79b5ca6172ece186df 100644 (file)
@@ -98,10 +98,12 @@ struct mlxsw_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, _unreg_action)             \
+#define MLXSW_RXL(_func, _trap_id, _action, _is_ctrl, _unreg_action)   \
        {                                                               \
                .trap_id = MLXSW_TRAP_ID_##_trap_id,                    \
                .u.rx_listener =                                        \
@@ -112,6 +114,8 @@ struct mlxsw_listener {
                },                                                      \
                .action = MLXSW_REG_HPKT_ACTION_##_action,              \
                .unreg_action = MLXSW_REG_HPKT_ACTION_##_unreg_action,  \
+               .trap_group = MLXSW_REG_HTGT_TRAP_GROUP_RX,             \
+               .is_ctrl = _is_ctrl,                                    \
                .is_event = false,                                      \
        }
 
@@ -124,6 +128,8 @@ struct mlxsw_listener {
                        .trap_id = MLXSW_TRAP_ID_##_trap_id,    \
                },                                              \
                .action = MLXSW_REG_HPKT_ACTION_TRAP_TO_CPU,    \
+               .trap_group = MLXSW_REG_HTGT_TRAP_GROUP_EMAD,   \
+               .is_ctrl = false,                               \
                .is_event = true,                               \
        }
 
index 2618e9cf3aab1d2b7a2c425678109efe87f49f2a..68a0e63954b6c52d3244ae2cb28adc6b20196477 100644 (file)
@@ -3214,6 +3214,7 @@ enum {
 
 /* reg_hpkt_ctrl
  * Configure dedicated buffer resources for control packets.
+ * Ignored by SwitchX-2.
  * 0 - Keep factory defaults.
  * 1 - Do not use control buffer for this trap ID.
  * 2 - Use control buffer for this trap ID.
@@ -3221,25 +3222,18 @@ enum {
  */
 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_hpkt_ack_set(payload, MLXSW_REG_HPKT_ACK_NOT_REQUIRED);
        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_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
index d758ce6228f4b3e88b51fea502b916dab78ccfac..3582e3f2901bfdbdff03c947d11bf7eb249a00ae 100644 (file)
@@ -2730,37 +2730,37 @@ static void mlxsw_sp_rx_listener_mark_func(struct sk_buff *skb, u8 local_port,
        return mlxsw_sp_rx_listener_no_mark_func(skb, local_port, priv);
 }
 
-#define MLXSW_SP_RXL_NO_MARK(_trap_id, _action)                                \
-       MLXSW_RXL(mlxsw_sp_rx_listener_no_mark_func, _trap_id, _action, \
-                 DISCARD)
+#define MLXSW_SP_RXL_NO_MARK(_trap_id, _action, _is_ctrl)              \
+       MLXSW_RXL(mlxsw_sp_rx_listener_no_mark_func, _trap_id, _action, \
+                 _is_ctrl, DISCARD)
 
-#define MLXSW_SP_RXL_MARK(_trap_id, _action)                           \
+#define MLXSW_SP_RXL_MARK(_trap_id, _action, _is_ctrl)                 \
        MLXSW_RXL(mlxsw_sp_rx_listener_mark_func, _trap_id, _action,    \
-                 DISCARD)
+                 _is_ctrl, DISCARD)
 
 static const struct mlxsw_listener mlxsw_sp_listener[] = {
        /* Events */
        MLXSW_EVENTL(mlxsw_sp_pude_event_func, PUDE),
        /* L2 traps */
-       MLXSW_SP_RXL_NO_MARK(STP, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(LACP, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(LLDP, TRAP_TO_CPU),
-       MLXSW_SP_RXL_MARK(DHCP, MIRROR_TO_CPU),
-       MLXSW_SP_RXL_MARK(IGMP_QUERY, MIRROR_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(IGMP_V1_REPORT, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(IGMP_V2_REPORT, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(IGMP_V2_LEAVE, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(IGMP_V3_REPORT, TRAP_TO_CPU),
-       MLXSW_SP_RXL_MARK(ARPBC, MIRROR_TO_CPU),
-       MLXSW_SP_RXL_MARK(ARPUC, MIRROR_TO_CPU),
+       MLXSW_SP_RXL_NO_MARK(STP, TRAP_TO_CPU, true),
+       MLXSW_SP_RXL_NO_MARK(LACP, TRAP_TO_CPU, true),
+       MLXSW_SP_RXL_NO_MARK(LLDP, TRAP_TO_CPU, true),
+       MLXSW_SP_RXL_MARK(DHCP, MIRROR_TO_CPU, false),
+       MLXSW_SP_RXL_MARK(IGMP_QUERY, MIRROR_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(IGMP_V1_REPORT, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(IGMP_V2_REPORT, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(IGMP_V2_LEAVE, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(IGMP_V3_REPORT, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_MARK(ARPBC, MIRROR_TO_CPU, false),
+       MLXSW_SP_RXL_MARK(ARPUC, MIRROR_TO_CPU, false),
        /* L3 traps */
-       MLXSW_SP_RXL_NO_MARK(MTUERROR, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(TTLERROR, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(LBERROR, TRAP_TO_CPU),
-       MLXSW_SP_RXL_MARK(OSPF, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(IP2ME, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(RTR_INGRESS0, TRAP_TO_CPU),
-       MLXSW_SP_RXL_NO_MARK(HOST_MISS_IPV4, TRAP_TO_CPU),
+       MLXSW_SP_RXL_NO_MARK(MTUERROR, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(TTLERROR, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(LBERROR, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_MARK(OSPF, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(IP2ME, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(RTR_INGRESS0, TRAP_TO_CPU, false),
+       MLXSW_SP_RXL_NO_MARK(HOST_MISS_IPV4, TRAP_TO_CPU, false),
 };
 
 static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
index 675ce122768bd355ff37288b7eaf15b4ea0faced..a15875675c48263b45bf32128fc5b80aff83ea44 100644 (file)
@@ -1448,8 +1448,9 @@ err_port_module_info_get:
        return err;
 }
 
-#define MLXSW_SX_RXL(_trap_id) \
-       MLXSW_RXL(mlxsw_sx_rx_listener_func, _trap_id, TRAP_TO_CPU, FORWARD)
+#define MLXSW_SX_RXL(_trap_id)                                         \
+       MLXSW_RXL(mlxsw_sx_rx_listener_func, _trap_id, TRAP_TO_CPU,     \
+                 false, FORWARD)
 
 static const struct mlxsw_listener mlxsw_sx_listener[] = {
        MLXSW_EVENTL(mlxsw_sx_pude_event_func, PUDE),