Netdev List
 help / color / mirror / Atom feed
From: Yevhen Orlov <yevhen.orlov@plvision.eu>
To: netdev@vger.kernel.org
Cc: Volodymyr Mytnyk <volodymyr.mytnyk@plvision.eu>,
	Taras Chornyi <taras.chornyi@plvision.eu>,
	Mickey Rachamim <mickeyr@marvell.com>,
	Serhiy Pshyk <serhiy.pshyk@plvision.eu>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Stephen Hemminger <stephen@networkplumber.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next v1 1/2] net: marvell: prestera: Add router ipv6 ABI
Date: Mon, 19 Dec 2022 00:16:40 +0200	[thread overview]
Message-ID: <Y5+RSF0Had10xizI@yorlov.ow.s> (raw)

There are only lpm add/del for ipv6 needed.
Nexthops indexes shared with ipv4.

Limitations:
- Only "local" and "main" tables supported
- Only generic interfaces supported for router (no bridges or vlans)

Co-developed-by: Taras Chornyi <taras.chornyi@plvision.eu>
Signed-off-by: Taras Chornyi <taras.chornyi@plvision.eu>
Co-developed-by: Elad Nachman <enachman@marvell.com>
Signed-off-by: Elad Nachman <enachman@marvell.com>
Signed-off-by: Yevhen Orlov <yevhen.orlov@plvision.eu>
---
 .../ethernet/marvell/prestera/prestera_hw.c   | 34 +++++++++++++++++++
 .../ethernet/marvell/prestera/prestera_hw.h   |  4 +++
 .../marvell/prestera/prestera_router_hw.c     | 33 ++++++++++++++----
 3 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/marvell/prestera/prestera_hw.c b/drivers/net/ethernet/marvell/prestera/prestera_hw.c
index fc6f7d2746e8..13341056599a 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_hw.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_hw.c
@@ -540,6 +540,11 @@ struct prestera_msg_iface {
 	u8 __pad[3];
 };
 
+enum prestera_msg_ip_addr_v {
+	PRESTERA_MSG_IPV4 = 0,
+	PRESTERA_MSG_IPV6
+};
+
 struct prestera_msg_ip_addr {
 	union {
 		__be32 ipv4;
@@ -2088,6 +2093,35 @@ int prestera_hw_lpm_del(struct prestera_switch *sw, u16 vr_id,
 			    sizeof(req));
 }
 
+int prestera_hw_lpm6_add(struct prestera_switch *sw, u16 vr_id,
+			 __u8 *dst, u32 dst_len, u32 grp_id)
+{
+	struct prestera_msg_lpm_req req;
+
+	req.dst.v = PRESTERA_MSG_IPV6;
+	memcpy(&req.dst.u.ipv6, dst, 16);
+	req.dst_len = __cpu_to_le32(dst_len);
+	req.vr_id = __cpu_to_le16(vr_id);
+	req.grp_id = __cpu_to_le32(grp_id);
+
+	return prestera_cmd(sw, PRESTERA_CMD_TYPE_ROUTER_LPM_ADD, &req.cmd,
+			    sizeof(req));
+}
+
+int prestera_hw_lpm6_del(struct prestera_switch *sw, u16 vr_id,
+			 __u8 *dst, u32 dst_len)
+{
+	struct prestera_msg_lpm_req req;
+
+	req.dst.v = PRESTERA_MSG_IPV6;
+	memcpy(&req.dst.u.ipv6, dst, 16);
+	req.dst_len = __cpu_to_le32(dst_len);
+	req.vr_id = __cpu_to_le16(vr_id);
+
+	return prestera_cmd(sw, PRESTERA_CMD_TYPE_ROUTER_LPM_DELETE, &req.cmd,
+			    sizeof(req));
+}
+
 int prestera_hw_nh_entries_set(struct prestera_switch *sw, int count,
 			       struct prestera_neigh_info *nhs, u32 grp_id)
 {
diff --git a/drivers/net/ethernet/marvell/prestera/prestera_hw.h b/drivers/net/ethernet/marvell/prestera/prestera_hw.h
index 0a929279e1ce..8769be6752bc 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_hw.h
+++ b/drivers/net/ethernet/marvell/prestera/prestera_hw.h
@@ -266,6 +266,10 @@ 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);
+int prestera_hw_lpm6_add(struct prestera_switch *sw, u16 vr_id,
+			 __u8 *dst, u32 dst_len, u32 grp_id);
+int prestera_hw_lpm6_del(struct prestera_switch *sw, u16 vr_id,
+			 __u8 *dst, u32 dst_len);
 
 /* NH API */
 int prestera_hw_nh_entries_set(struct prestera_switch *sw, int count,
diff --git a/drivers/net/ethernet/marvell/prestera/prestera_router_hw.c b/drivers/net/ethernet/marvell/prestera/prestera_router_hw.c
index 02faaea2aefa..1c6d0cdbdfdf 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_router_hw.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_router_hw.c
@@ -581,8 +581,16 @@ static void __prestera_fib_node_destruct(struct prestera_switch *sw,
 	struct prestera_vr *vr;
 
 	vr = fib_node->info.vr;
-	prestera_hw_lpm_del(sw, vr->hw_vr_id, fib_node->key.addr.u.ipv4,
-			    fib_node->key.prefix_len);
+	if (fib_node->key.addr.v == PRESTERA_IPV4)
+		prestera_hw_lpm_del(sw, vr->hw_vr_id, fib_node->key.addr.u.ipv4,
+				    fib_node->key.prefix_len);
+	else if (fib_node->key.addr.v == PRESTERA_IPV6)
+		prestera_hw_lpm6_del(sw, vr->hw_vr_id,
+				     (u8 *)&fib_node->key.addr.u.ipv6.s6_addr,
+				     fib_node->key.prefix_len);
+	else
+		WARN(1, "Invalid address version. Memory corrupted?");
+
 	switch (fib_node->info.type) {
 	case PRESTERA_FIB_TYPE_UC_NH:
 		prestera_nexthop_group_put(sw, fib_node->info.nh_grp);
@@ -661,8 +669,16 @@ prestera_fib_node_create(struct prestera_switch *sw,
 		goto err_nh_grp_get;
 	}
 
-	err = prestera_hw_lpm_add(sw, vr->hw_vr_id, key->addr.u.ipv4,
-				  key->prefix_len, grp_id);
+	if (key->addr.v == PRESTERA_IPV4)
+		err = prestera_hw_lpm_add(sw, vr->hw_vr_id, key->addr.u.ipv4,
+					  key->prefix_len, grp_id);
+	else if (key->addr.v == PRESTERA_IPV6)
+		err = prestera_hw_lpm6_add(sw, vr->hw_vr_id,
+					   (u8 *)&key->addr.u.ipv6.s6_addr,
+					   key->prefix_len, grp_id);
+	else
+		WARN(1, "Invalid address version. Memory corrupted?");
+
 	if (err)
 		goto err_lpm_add;
 
@@ -674,8 +690,13 @@ prestera_fib_node_create(struct prestera_switch *sw,
 	return fib_node;
 
 err_ht_insert:
-	prestera_hw_lpm_del(sw, vr->hw_vr_id, key->addr.u.ipv4,
-			    key->prefix_len);
+	if (key->addr.v == PRESTERA_IPV4)
+		prestera_hw_lpm_del(sw, vr->hw_vr_id, key->addr.u.ipv4,
+				    key->prefix_len);
+	else if (key->addr.v == PRESTERA_IPV6)
+		prestera_hw_lpm6_del(sw, vr->hw_vr_id,
+				     (u8 *)&key->addr.u.ipv6.s6_addr,
+				     key->prefix_len);
 err_lpm_add:
 	if (fib_type == PRESTERA_FIB_TYPE_UC_NH)
 		prestera_nexthop_group_put(sw, fib_node->info.nh_grp);
-- 
2.17.1


             reply	other threads:[~2022-12-18 22:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-18 22:16 Yevhen Orlov [this message]
2022-12-20 10:39 ` [PATCH net-next v1 1/2] net: marvell: prestera: Add router ipv6 ABI kernel test robot
2022-12-20 12:21 ` Piotr Raczynski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y5+RSF0Had10xizI@yorlov.ow.s \
    --to=yevhen.orlov@plvision.eu \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mickeyr@marvell.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=serhiy.pshyk@plvision.eu \
    --cc=stephen@networkplumber.org \
    --cc=taras.chornyi@plvision.eu \
    --cc=volodymyr.mytnyk@plvision.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox