mlxsw: Split handling of FDB tunnel entries between address families
authorAmit Cohen <amcohen@nvidia.com>
Tue, 14 Dec 2021 14:25:47 +0000 (16:25 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 15 Dec 2021 15:05:44 +0000 (15:05 +0000)
Currently, the function which adds/removes unicast tunnel FDB entries is
shared between IPv4 and IPv6, while for IPv6 it warns because there is
no support for it.

The code for IPv6 will be more complicated because it needs to
allocate/release a KVDL pointer for the underlay IPv6 address.

As a preparation for IPv6 underlay support, split the code according to
address family.

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/reg.h
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c

index 5eaba2a..50226da 100644 (file)
@@ -504,19 +504,30 @@ static inline void
 mlxsw_reg_sfd_uc_tunnel_pack(char *payload, int rec_index,
                             enum mlxsw_reg_sfd_rec_policy policy,
                             const char *mac, u16 fid,
-                            enum mlxsw_reg_sfd_rec_action action, u32 uip,
+                            enum mlxsw_reg_sfd_rec_action action,
                             enum mlxsw_reg_sfd_uc_tunnel_protocol proto)
 {
        mlxsw_reg_sfd_rec_pack(payload, rec_index,
                               MLXSW_REG_SFD_REC_TYPE_UNICAST_TUNNEL, mac,
                               action);
        mlxsw_reg_sfd_rec_policy_set(payload, rec_index, policy);
-       mlxsw_reg_sfd_uc_tunnel_uip_msb_set(payload, rec_index, uip >> 24);
-       mlxsw_reg_sfd_uc_tunnel_uip_lsb_set(payload, rec_index, uip);
        mlxsw_reg_sfd_uc_tunnel_fid_set(payload, rec_index, fid);
        mlxsw_reg_sfd_uc_tunnel_protocol_set(payload, rec_index, proto);
 }
 
+static inline void
+mlxsw_reg_sfd_uc_tunnel_pack4(char *payload, int rec_index,
+                             enum mlxsw_reg_sfd_rec_policy policy,
+                             const char *mac, u16 fid,
+                             enum mlxsw_reg_sfd_rec_action action, u32 uip)
+{
+       mlxsw_reg_sfd_uc_tunnel_uip_msb_set(payload, rec_index, uip >> 24);
+       mlxsw_reg_sfd_uc_tunnel_uip_lsb_set(payload, rec_index, uip);
+       mlxsw_reg_sfd_uc_tunnel_pack(payload, rec_index, policy, mac, fid,
+                                    action,
+                                    MLXSW_REG_SFD_UC_TUNNEL_PROTOCOL_IPV4);
+}
+
 enum mlxsw_reg_tunnel_port {
        MLXSW_REG_TUNNEL_PORT_NVE,
        MLXSW_REG_TUNNEL_PORT_VPLS,
index c5fd69a..5347364 100644 (file)
@@ -1290,38 +1290,24 @@ static enum mlxsw_reg_sfd_op mlxsw_sp_sfd_op(bool adding)
                        MLXSW_REG_SFD_OP_WRITE_REMOVE;
 }
 
-static int mlxsw_sp_port_fdb_tunnel_uc_op(struct mlxsw_sp *mlxsw_sp,
-                                         const char *mac, u16 fid,
-                                         enum mlxsw_sp_l3proto proto,
-                                         const union mlxsw_sp_l3addr *addr,
-                                         bool adding, bool dynamic)
+static int
+mlxsw_sp_port_fdb_tun_uc_op4(struct mlxsw_sp *mlxsw_sp, bool dynamic,
+                            const char *mac, u16 fid, __be32 addr, bool adding)
 {
-       enum mlxsw_reg_sfd_uc_tunnel_protocol sfd_proto;
        char *sfd_pl;
        u8 num_rec;
        u32 uip;
        int err;
 
-       switch (proto) {
-       case MLXSW_SP_L3_PROTO_IPV4:
-               uip = be32_to_cpu(addr->addr4);
-               sfd_proto = MLXSW_REG_SFD_UC_TUNNEL_PROTOCOL_IPV4;
-               break;
-       case MLXSW_SP_L3_PROTO_IPV6:
-       default:
-               WARN_ON(1);
-               return -EOPNOTSUPP;
-       }
-
        sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
        if (!sfd_pl)
                return -ENOMEM;
 
+       uip = be32_to_cpu(addr);
        mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
-       mlxsw_reg_sfd_uc_tunnel_pack(sfd_pl, 0,
-                                    mlxsw_sp_sfd_rec_policy(dynamic), mac, fid,
-                                    MLXSW_REG_SFD_REC_ACTION_NOP, uip,
-                                    sfd_proto);
+       mlxsw_reg_sfd_uc_tunnel_pack4(sfd_pl, 0,
+                                     mlxsw_sp_sfd_rec_policy(dynamic), mac,
+                                     fid, MLXSW_REG_SFD_REC_ACTION_NOP, uip);
        num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
        err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
        if (err)
@@ -1335,6 +1321,23 @@ out:
        return err;
 }
 
+static int mlxsw_sp_port_fdb_tunnel_uc_op(struct mlxsw_sp *mlxsw_sp,
+                                         const char *mac, u16 fid,
+                                         enum mlxsw_sp_l3proto proto,
+                                         const union mlxsw_sp_l3addr *addr,
+                                         bool adding, bool dynamic)
+{
+       switch (proto) {
+       case MLXSW_SP_L3_PROTO_IPV4:
+               return mlxsw_sp_port_fdb_tun_uc_op4(mlxsw_sp, dynamic, mac, fid,
+                                                   addr->addr4, adding);
+       case MLXSW_SP_L3_PROTO_IPV6:
+       default:
+               WARN_ON(1);
+               return -EOPNOTSUPP;
+       }
+}
+
 static int __mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u16 local_port,
                                     const char *mac, u16 fid, bool adding,
                                     enum mlxsw_reg_sfd_rec_action action,