From patchwork Mon Jan 20 00:49:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aryan Srivastava X-Patchwork-Id: 13944628 X-Patchwork-Delegate: kuba@kernel.org Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F5F4946C for ; Mon, 20 Jan 2025 00:49:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.36.163.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737334185; cv=none; b=JRqQgpQuX/CaecBQY+Y9Vb35evZp4jLPI8hN5hkfWox/Met4qto4EDcUD40VdSwU7oqHQT/3IISLmc116s2u2MncfX1+t9cOZQVlI0JcYDG4kkHuaj30Yute/+IOkiuRK/mdq5r2gxWi/fEjGegiY6l/1Ja9ipw+XWiqwxMNNMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737334185; c=relaxed/simple; bh=9b8xxzzOm+EYemXfgQ+At2NaK2nYAc/3bZtR8hLjDOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mEXfItDfZuQLZYHp2Q7Lv6mJuRdw7CH8J2Oc9I1r7SJYgwaZZ6XV76cZX9VrG+Mtop+5bpSgYTQR0ZVDkXwLFGg5XL3leCmzZws4vXzLLoO/Bm9aCBIdnS06XTv1SO3fnXbs9iQTs6DZDSio8X49Rb4cu5/HmoVWrQ6Hq1e9GWY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz; spf=pass smtp.mailfrom=alliedtelesis.co.nz; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b=LgBee2ve; arc=none smtp.client-ip=202.36.163.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="LgBee2ve" Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 50A2E2C0505; Mon, 20 Jan 2025 13:49:42 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1737334182; bh=jFP1PQGXEnG4TROU5CynpdTaGvi/F/6HOejN2BzslmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LgBee2veXXWS0RDDBZmsIIltjB/DcJj/PntZJfhROUPgOYxQkBJ9Sxyu8XbZemiIT bEuzVDmz0jHqesBe/1Cb0dbNj6P2+tNbGlwyzmL+plCu9/GqszzivBueKcb2MJoAyf zOFannHVEa0+EWH9RZVrICbcP7wooyLw0GQ32fuzUun4c28JsdT/VUb3gZrIU8fEHk 3I5va/qdjSVmo3nGCW/gYYl4D3KNldXeeCrq/LTdc1DlVmIlGQaZr7MoISmxQ1W9H1 4lH0SQsfSImT+SaXZW/pDZfke/RyxmI3XpWyWFl2jaYlDCNjEaYqiOyhZb0eI/6Ydc skSBXhl14N5fw== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Mon, 20 Jan 2025 13:49:40 +1300 Received: from aryans-dl.ws.atlnz.lc (aryans-dl.ws.atlnz.lc [10.33.22.38]) by pat.atlnz.lc (Postfix) with ESMTP id 80DC713ED5A; Mon, 20 Jan 2025 13:49:40 +1300 (NZDT) Received: by aryans-dl.ws.atlnz.lc (Postfix, from userid 1844) id 7E9062A1696; Mon, 20 Jan 2025 13:49:40 +1300 (NZDT) From: Aryan Srivastava To: Jiri Pirko , Andrew Lunn Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Aryan Srivastava , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Subject: [RFC net-next v1 1/2] net: devlink: Add port function for bridge offload Date: Mon, 20 Jan 2025 13:49:11 +1300 Message-ID: <20250120004913.2154398-2-aryan.srivastava@alliedtelesis.co.nz> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120004913.2154398-1-aryan.srivastava@alliedtelesis.co.nz> References: <20250120004913.2154398-1-aryan.srivastava@alliedtelesis.co.nz> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SEG-SpamProfiler-Analysis: v=2.4 cv=BNQQr0QG c=1 sm=1 tr=0 ts=678d9da4 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=VdSt8ZQiCzkA:10 a=Rn-rybJDi6Mx2ZrNRmMA:9 a=3ZKOabzyN94A:10 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add configurable devlink port attr for HW offloading. Most drivers (and DSA framework) will offload a bridge port to HW if there is mechanism available to do so. Adding a configurable devlink attr allows users to change this default setting, in cases where HW offload of a bridge port is not desired. Signed-off-by: Aryan Srivastava --- include/net/devlink.h | 13 ++++++++++++ include/uapi/linux/devlink.h | 2 ++ net/devlink/port.c | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index b8783126c1ed..79211b3cdc1a 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1627,6 +1627,15 @@ void devlink_free(struct devlink *devlink); * of event queues. Should be used by device drivers to * configure maximum number of event queues * of a function managed by the devlink port. + * @port_fn_bridge_offload_get: Callback used to get port function's bridge + * offload capability. Should be used by device drivers + * to report the current state of offload + * capability of a function managed by the devlink + * port. + * @port_fn_bridge_offload_get: Callback used to set port function's bridge + * offload capability. Should be used by device drivers to + * enable/disable offload capability of a + * function managed by the devlink port. * * Note: Driver should return -EOPNOTSUPP if it doesn't support * port function (@port_fn_*) handling for a particular port. @@ -1682,6 +1691,10 @@ struct devlink_port_ops { int (*port_fn_max_io_eqs_set)(struct devlink_port *devlink_port, u32 max_eqs, struct netlink_ext_ack *extack); + void (*port_fn_bridge_offload_get)(struct devlink_port *devlink_port, + bool *is_enable); + void (*port_fn_bridge_offload_set)(struct devlink_port *devlink_port, + bool enable); }; void devlink_port_init(struct devlink *devlink, diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 9401aa343673..e2682bc9ecb1 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -668,6 +668,7 @@ enum devlink_port_fn_attr_cap { DEVLINK_PORT_FN_ATTR_CAP_MIGRATABLE_BIT, DEVLINK_PORT_FN_ATTR_CAP_IPSEC_CRYPTO_BIT, DEVLINK_PORT_FN_ATTR_CAP_IPSEC_PACKET_BIT, + DEVLINK_PORT_FN_ATTR_CAP_BRIDGE_OFFLOAD_BIT, /* Add new caps above */ __DEVLINK_PORT_FN_ATTR_CAPS_MAX, @@ -678,6 +679,7 @@ enum devlink_port_fn_attr_cap { _BITUL(DEVLINK_PORT_FN_ATTR_CAP_MIGRATABLE_BIT) #define DEVLINK_PORT_FN_CAP_IPSEC_CRYPTO _BITUL(DEVLINK_PORT_FN_ATTR_CAP_IPSEC_CRYPTO_BIT) #define DEVLINK_PORT_FN_CAP_IPSEC_PACKET _BITUL(DEVLINK_PORT_FN_ATTR_CAP_IPSEC_PACKET_BIT) +#define DEVLINK_PORT_FN_CAP_BRIDGE_OFFLOAD _BITUL(DEVLINK_PORT_FN_ATTR_CAP_BRIDGE_OFFLOAD_BIT) enum devlink_port_function_attr { DEVLINK_PORT_FUNCTION_ATTR_UNSPEC, diff --git a/net/devlink/port.c b/net/devlink/port.c index 939081a0e615..8009c94e06e5 100644 --- a/net/devlink/port.c +++ b/net/devlink/port.c @@ -148,6 +148,21 @@ static int devlink_port_fn_ipsec_packet_fill(struct devlink_port *devlink_port, return 0; } +static int devlink_port_bridge_offload_fill(struct devlink_port *devlink_port, + struct nla_bitfield32 *caps) +{ + bool is_enable; + + if (!devlink_port->ops->port_fn_bridge_offload_get || + devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL) + return 0; + + devlink_port->ops->port_fn_bridge_offload_get(devlink_port, &is_enable); + + devlink_port_fn_cap_fill(caps, DEVLINK_PORT_FN_CAP_BRIDGE_OFFLOAD, is_enable); + return 0; +} + static int devlink_port_fn_caps_fill(struct devlink_port *devlink_port, struct sk_buff *msg, struct netlink_ext_ack *extack, @@ -172,6 +187,10 @@ static int devlink_port_fn_caps_fill(struct devlink_port *devlink_port, if (err) return err; + err = devlink_port_bridge_offload_fill(devlink_port, &caps); + if (err) + return err; + if (!caps.selector) return 0; err = nla_put_bitfield32(msg, DEVLINK_PORT_FN_ATTR_CAPS, caps.value, @@ -393,6 +412,12 @@ devlink_port_fn_ipsec_packet_set(struct devlink_port *devlink_port, bool enable, return devlink_port->ops->port_fn_ipsec_packet_set(devlink_port, enable, extack); } +static void +devlink_port_fn_bridge_offload_set(struct devlink_port *devlink_port, bool enable) +{ + return devlink_port->ops->port_fn_bridge_offload_set(devlink_port, enable); +} + static int devlink_port_fn_caps_set(struct devlink_port *devlink_port, const struct nlattr *attr, struct netlink_ext_ack *extack) @@ -431,6 +456,10 @@ static int devlink_port_fn_caps_set(struct devlink_port *devlink_port, if (err) return err; } + if (caps.selector & DEVLINK_PORT_FN_CAP_BRIDGE_OFFLOAD) { + devlink_port_fn_bridge_offload_set(devlink_port, caps_value & + DEVLINK_PORT_FN_CAP_BRIDGE_OFFLOAD); + } return 0; } @@ -765,6 +794,18 @@ static int devlink_port_function_validate(struct devlink_port *devlink_port, return -EOPNOTSUPP; } } + if (caps.selector & DEVLINK_PORT_FN_CAP_BRIDGE_OFFLOAD) { + if (!ops->port_fn_bridge_offload_set) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "Port doesn't support bridge offload function attribute"); + return -EOPNOTSUPP; + } + if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL) { + NL_SET_ERR_MSG_ATTR(extack, attr, + "bridge offload function attribute supported for physical ports only"); + return -EOPNOTSUPP; + } + } } if (tb[DEVLINK_PORT_FN_ATTR_MAX_IO_EQS] && !ops->port_fn_max_io_eqs_set) { From patchwork Mon Jan 20 00:49:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aryan Srivastava X-Patchwork-Id: 13944627 X-Patchwork-Delegate: kuba@kernel.org Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F62BAD51 for ; Mon, 20 Jan 2025 00:49:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.36.163.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737334185; cv=none; b=Lqxrgh/DkQTrxI3fh4qIDeC3PjjWVsOw7CyjUJzJ2sMYZJi/0itFAwT9zcytEWSgTin2Ptv3VGR+LvR9R3ILlG429raSuyDo6cRszmHeCnJfcli+venpZdclxdv6zPezosgX/lNz28Pew4EkFyNxX87rTmC+8AeaTxnWmiq2EXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737334185; c=relaxed/simple; bh=61ItVcu3Z+mpVJ0kWGkVbw2XvWGB49Gd+pqvECLY8r4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pGAUpOZGGMb6Jwn/Lwl9Agb2OY7rT9rvJB1BYuWvyhbnD4lg/Hb7dr4dchRJk/NY4VNCkuXK2dngQqf1iuMQJ9mPvh+CTow3xGpIaRqy+ExEpJpydzVBTviQPUMxFJkS+sOa78ofMdWbJOMEHE5HlHfXkMSPMJAdie0tn/5eyXc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz; spf=pass smtp.mailfrom=alliedtelesis.co.nz; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b=KwV88P+C; arc=none smtp.client-ip=202.36.163.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="KwV88P+C" Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 9AADD2C0692; Mon, 20 Jan 2025 13:49:42 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1737334182; bh=mo4Lr0O9DdbDCn6eylNMbQRpNiyEtj/zPpgjr7LMFkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KwV88P+Ck1rWKT7RP4kYJGiAIubPjUq9LbjCOdj7SBdM/JdRy51VPByHpT1zHGlDT tu6S0X0PBtSCX3QbgxhVFday/868Yz/fqr+0TVPxasc7XdPwZWHD2H18RYcOjkcYpR WmloKANoBeUNHZ7N+QOm3wv2raJdF9Z2O5Mm3Mn85gohwAW17/GeqE4HzV1TeSMTuL HQ6QQvWLJUHK4LSWaJw0Oype3ZDrCDvrtGDT3N+pZPjFQ6SHXpAlFruUsmvUq3sJ1z 9s0vMb3NnBZjFu92g5iEUDPTNlBlyDxr0ANt4bCOKHd4gSrvaXtxJQq7l5Erd0zyFw BYAInrS5xxe+w== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Mon, 20 Jan 2025 13:49:41 +1300 Received: from aryans-dl.ws.atlnz.lc (aryans-dl.ws.atlnz.lc [10.33.22.38]) by pat.atlnz.lc (Postfix) with ESMTP id D123D13ED5A; Mon, 20 Jan 2025 13:49:41 +1300 (NZDT) Received: by aryans-dl.ws.atlnz.lc (Postfix, from userid 1844) id CEDA62A1696; Mon, 20 Jan 2025 13:49:41 +1300 (NZDT) From: Aryan Srivastava To: Jiri Pirko , Andrew Lunn Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Aryan Srivastava , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Subject: [RFC net-next v1 2/2] net: dsa: add option for bridge port HW offload Date: Mon, 20 Jan 2025 13:49:12 +1300 Message-ID: <20250120004913.2154398-3-aryan.srivastava@alliedtelesis.co.nz> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250120004913.2154398-1-aryan.srivastava@alliedtelesis.co.nz> References: <20250120004913.2154398-1-aryan.srivastava@alliedtelesis.co.nz> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SEG-SpamProfiler-Analysis: v=2.4 cv=BNQQr0QG c=1 sm=1 tr=0 ts=678d9da6 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=VdSt8ZQiCzkA:10 a=sVghOlvp1KO_yCYPZfwA:9 a=3ZKOabzyN94A:10 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Currently the DSA framework will HW offload any bridge port if there is a driver available to support HW offloading. This may not always be the preferred case. In cases where it is preferred that all traffic still hit the CPU, do software bridging instead. To prevent HW bridging (and potential CPU bypass), make the DSA framework aware of the devlink port function attr, bridge_offload, and add a matching field to the port struct. Add get/set functions to configure the field, and use this field to condition HW config for offloading a bridge port. Signed-off-by: Aryan Srivastava --- include/net/dsa.h | 1 + net/dsa/devlink.c | 27 ++++++++++++++++++++++++++- net/dsa/dsa.c | 1 + net/dsa/port.c | 3 ++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index a0a9481c52c2..9ee2d7ccfff8 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -291,6 +291,7 @@ struct dsa_port { struct device_node *dn; unsigned int ageing_time; + bool bridge_offloading; struct dsa_bridge *bridge; struct devlink_port devlink_port; diff --git a/net/dsa/devlink.c b/net/dsa/devlink.c index f41f9fc2194e..dc98e5311921 100644 --- a/net/dsa/devlink.c +++ b/net/dsa/devlink.c @@ -298,6 +298,31 @@ void dsa_devlink_region_destroy(struct devlink_region *region) } EXPORT_SYMBOL_GPL(dsa_devlink_region_destroy); +static void +dsa_devlink_port_bridge_offload_get(struct devlink_port *dlp, + bool *is_enable) +{ + struct dsa_port *dp = dsa_to_port(dsa_devlink_port_to_ds(dlp), + dsa_devlink_port_to_port(dlp)); + + *is_enable = dp->bridge_offloading; +} + +static void +dsa_devlink_port_bridge_offload_set(struct devlink_port *dlp, + bool enable) +{ + struct dsa_port *dp = dsa_to_port(dsa_devlink_port_to_ds(dlp), + dsa_devlink_port_to_port(dlp)); + + dp->bridge_offloading = enable; +} + +static const struct devlink_port_ops dsa_devlink_port_ops = { + .port_fn_bridge_offload_get = dsa_devlink_port_bridge_offload_get, + .port_fn_bridge_offload_set = dsa_devlink_port_bridge_offload_set, +}; + int dsa_port_devlink_setup(struct dsa_port *dp) { struct devlink_port *dlp = &dp->devlink_port; @@ -341,7 +366,7 @@ int dsa_port_devlink_setup(struct dsa_port *dp) } devlink_port_attrs_set(dlp, &attrs); - err = devlink_port_register(dl, dlp, dp->index); + err = devlink_port_register_with_ops(dl, dlp, dp->index, &dsa_devlink_port_ops); if (err) { if (ds->ops->port_teardown) ds->ops->port_teardown(ds, dp->index); diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 5a7c0e565a89..20cf55bd42db 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -529,6 +529,7 @@ static int dsa_port_setup(struct dsa_port *dp) return err; } + dp->bridge_offloading = true; dp->setup = true; return 0; diff --git a/net/dsa/port.c b/net/dsa/port.c index 5c9d1798e830..de176f7993d0 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -493,7 +493,8 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, struct net_device *brport_dev; int err; - if (br_mst_enabled(br) && !dsa_port_supports_mst(dp)) + if ((br_mst_enabled(br) && !dsa_port_supports_mst(dp)) || + !dp->bridge_offloading) return -EOPNOTSUPP; /* Here the interface is already bridged. Reflect the current