net: marvell: prestera: Add router LPM ABI
authorYevhen Orlov <yevhen.orlov@plvision.eu>
Wed, 16 Feb 2022 01:05:55 +0000 (03:05 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 17 Feb 2022 20:45:01 +0000 (20:45 +0000)
Add functions to create/delete lpm entry in hw.
prestera_hw_lpm_add() take index of allocated virtual router.
Also it takes grp_id, which is index of allocated nexthop group.
ABI to create nexthop group will be added soon.

Co-developed-by: Taras Chornyi <tchornyi@marvell.com>
Signed-off-by: Taras Chornyi <tchornyi@marvell.com>
Co-developed-by: Oleksandr Mazur <oleksandr.mazur@plvision.eu>
Signed-off-by: Oleksandr Mazur <oleksandr.mazur@plvision.eu>
Signed-off-by: Yevhen Orlov <yevhen.orlov@plvision.eu>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/prestera/prestera_hw.c
drivers/net/ethernet/marvell/prestera/prestera_hw.h

index d4c0f0577b265e7e8f88c4fa46f133c8f078052d..c66cc929c820a0293a1dc35073598f30eea77fca 100644 (file)
@@ -55,6 +55,8 @@ enum prestera_cmd_type_t {
 
        PRESTERA_CMD_TYPE_ROUTER_RIF_CREATE = 0x600,
        PRESTERA_CMD_TYPE_ROUTER_RIF_DELETE = 0x601,
+       PRESTERA_CMD_TYPE_ROUTER_LPM_ADD = 0x610,
+       PRESTERA_CMD_TYPE_ROUTER_LPM_DELETE = 0x611,
        PRESTERA_CMD_TYPE_ROUTER_VR_CREATE = 0x630,
        PRESTERA_CMD_TYPE_ROUTER_VR_DELETE = 0x631,
 
@@ -502,6 +504,15 @@ struct prestera_msg_iface {
        u8 __pad[3];
 };
 
+struct prestera_msg_ip_addr {
+       union {
+               __be32 ipv4;
+               __be32 ipv6[4];
+       } u;
+       u8 v; /* e.g. PRESTERA_IPV4 */
+       u8 __pad[3];
+};
+
 struct prestera_msg_rif_req {
        struct prestera_msg_cmd cmd;
        struct prestera_msg_iface iif;
@@ -518,6 +529,15 @@ struct prestera_msg_rif_resp {
        u8 __pad[2];
 };
 
+struct prestera_msg_lpm_req {
+       struct prestera_msg_cmd cmd;
+       struct prestera_msg_ip_addr dst;
+       __le32 grp_id;
+       __le32 dst_len;
+       __le16 vr_id;
+       u8 __pad[2];
+};
+
 struct prestera_msg_vr_req {
        struct prestera_msg_cmd cmd;
        __le16 vr_id;
@@ -601,9 +621,11 @@ static void prestera_hw_build_tests(void)
        BUILD_BUG_ON(sizeof(struct prestera_msg_counter_stats) != 16);
        BUILD_BUG_ON(sizeof(struct prestera_msg_rif_req) != 36);
        BUILD_BUG_ON(sizeof(struct prestera_msg_vr_req) != 8);
+       BUILD_BUG_ON(sizeof(struct prestera_msg_lpm_req) != 36);
 
        /*  structure that are part of req/resp fw messages */
        BUILD_BUG_ON(sizeof(struct prestera_msg_iface) != 16);
+       BUILD_BUG_ON(sizeof(struct prestera_msg_ip_addr) != 20);
 
        /* check responses */
        BUILD_BUG_ON(sizeof(struct prestera_msg_common_resp) != 8);
@@ -1897,6 +1919,33 @@ int prestera_hw_vr_delete(struct prestera_switch *sw, u16 vr_id)
                            sizeof(req));
 }
 
+int prestera_hw_lpm_add(struct prestera_switch *sw, u16 vr_id,
+                       __be32 dst, u32 dst_len, u32 grp_id)
+{
+       struct prestera_msg_lpm_req req = {
+               .dst_len = __cpu_to_le32(dst_len),
+               .vr_id = __cpu_to_le16(vr_id),
+               .grp_id = __cpu_to_le32(grp_id),
+               .dst.u.ipv4 = dst
+       };
+
+       return prestera_cmd(sw, PRESTERA_CMD_TYPE_ROUTER_LPM_ADD, &req.cmd,
+                           sizeof(req));
+}
+
+int prestera_hw_lpm_del(struct prestera_switch *sw, u16 vr_id,
+                       __be32 dst, u32 dst_len)
+{
+       struct prestera_msg_lpm_req req = {
+               .dst_len = __cpu_to_le32(dst_len),
+               .vr_id = __cpu_to_le16(vr_id),
+               .dst.u.ipv4 = dst
+       };
+
+       return prestera_cmd(sw, PRESTERA_CMD_TYPE_ROUTER_LPM_DELETE, &req.cmd,
+                           sizeof(req));
+}
+
 int prestera_hw_rxtx_init(struct prestera_switch *sw,
                          struct prestera_rxtx_params *params)
 {
index 3ff12bae5909c53cabbaf3d5d02d7ebfd4dcf7a8..fd896a8838bb472518be2c5a318e5e2c4833bdf4 100644 (file)
@@ -249,6 +249,12 @@ int prestera_hw_rif_delete(struct prestera_switch *sw, u16 rif_id,
 int prestera_hw_vr_create(struct prestera_switch *sw, u16 *vr_id);
 int prestera_hw_vr_delete(struct prestera_switch *sw, u16 vr_id);
 
+/* LPM PI */
+int prestera_hw_lpm_add(struct prestera_switch *sw, u16 vr_id,
+                       __be32 dst, u32 dst_len, u32 grp_id);
+int prestera_hw_lpm_del(struct prestera_switch *sw, u16 vr_id,
+                       __be32 dst, u32 dst_len);
+
 /* Event handlers */
 int prestera_hw_event_handler_register(struct prestera_switch *sw,
                                       enum prestera_event_type type,