From: Andrew Lunn <andrew@lunn.ch>
To: Michael Dege <michael.dege@renesas.com>
Cc: "Yoshihiro Shimoda" <yoshihiro.shimoda.uh@renesas.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Richard Cochran" <richardcochran@gmail.com>,
"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
"Paul Barker" <paul@pbarker.dev>, "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Magnus Damm" <magnus.damm@gmail.com>,
netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
"Nikita Yushchenko" <nikita.yoush@cogentembedded.com>,
"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>
Subject: Re: [PATCH net-next 09/10] net: renesas: rswitch: add simple l3 routing
Date: Fri, 7 Nov 2025 03:32:16 +0100 [thread overview]
Message-ID: <06213fb1-12dc-4045-803e-d2a65c7e9fc6@lunn.ch> (raw)
In-Reply-To: <20251106-add_l3_routing-v1-9-dcbb8368ca54@renesas.com>
> +void rswitch_update_l3_offload(struct rswitch_private *priv)
> +{
> + u32 all_ports_mask = GENMASK(RSWITCH_NUM_AGENTS - 1, 0);
> + struct rswitch_device *rdev;
> + bool l3_offload_enable_cond;
> + u32 l3_rdev_count;
> + u32 l3_ports_mask;
> +
> + l3_ports_mask = all_ports_mask;
> +
> + l3_rdev_count = 0;
> + rswitch_for_all_ports(priv, rdev) {
> + if (rdev_for_l3_offload(rdev)) {
> + l3_rdev_count++;
> + l3_ports_mask &= ~BIT(rdev->port);
> + }
> + }
> +
> + l3_offload_enable_cond = (l3_rdev_count >= 2);
> +
> +#define FWPC0_L3_MASK (FWPC0_LTHTA | FWPC0_IP4UE | FWPC0_IP4TE | FWPC0_IP4OE)
> + rswitch_for_all_ports(priv, rdev) {
> + if (rdev_for_l3_offload(rdev) && l3_offload_enable_cond) {
> + /* Update allowed offload destinations even for ports
> + * with l3 offload enabled earlier.
> + *
> + * Allow offload routing to self for hw port.
> + */
> + rswitch_modify(priv->addr, FWPC1(rdev->port),
> + FWPC1_LTHFW_MASK,
> + FIELD_PREP(FWPC1_LTHFW_MASK, l3_ports_mask));
> + if (!rdev->l3_offload_enabled) {
> + rswitch_modify(priv->addr, FWPC0(rdev->port),
> + 0,
> + FWPC0_L3_MASK);
> + rdev->l3_offload_enabled = 1;
> + netdev_info(rdev->ndev, "starting l3 offload\n");
This, and the other netdev_info calls should probably be debug.
> +static bool rswitch_l23update_hw_op(struct rswitch_private *priv,
> + struct rswitch_l23update *update,
> + bool install)
> +{
> + u8 *dst_mac = update->spec.dst_mac;
> + u32 val;
> + int ret;
> +
> + val = FIELD_PREP(FWL23URL0_RN, update->index) |
> + FIELD_PREP(FWL23URL0_PV,
> + install ? GENMASK(RSWITCH_NUM_AGENTS - 1, 0) : 0);
> + iowrite32(val, priv->addr + FWL23URL0);
> +
> + val = FWL23URL1_TTLU |
> + FWL23URL1_MSAU |
> + FWL23URL1_MDAU |
> + (dst_mac[0] << 8) | (dst_mac[1] << 0);
> + iowrite32(val, priv->addr + FWL23URL1);
> +
> + val = (dst_mac[2] << 24) | (dst_mac[3] << 16) |
> + (dst_mac[4] << 8) | (dst_mac[5] << 0);
> + iowrite32(val, priv->addr + FWL23URL2);
> +
> + iowrite32(0, priv->addr + FWL23URL3);
> +
> + /* Rule write starts after writing to FWL23URL3 */
> +
> + ret = rswitch_reg_wait(priv->addr, FWL23URLR, FWL23URLR_L, 0);
> + if (ret) {
> + dev_err(&priv->pdev->dev, "timeout writing l23_update\n");
> + return false;
Why not make this an int function and return -ETIMEDOUT?
> +static bool rmon_ipv4_dst_offload_hw_op(struct rswitch_route_monitor *rmon,
> + struct rmon_ipv4_dst_offload *offload,
> + u8 frame_type, bool install)
Why all this bool functions? Especially when you have calls returning
error codes you are throwing away.
> +static struct rswitch_l23update *rswitch_get_l23update(struct rswitch_private *priv,
> + struct rswitch_l23update_spec *spec)
> +{
> + struct rswitch_l23update *update;
> +
> + spin_lock(&priv->l3_lock);
> +
> + list_for_each_entry(update, &priv->l23_update_list, list) {
> + if (rswitch_l23update_matches_spec(update, spec)) {
> + update->use_count++;
> + goto out;
> + }
> + }
> +
> + update = kzalloc(sizeof(*update), GFP_ATOMIC);
> + if (!update)
> + goto out;
> +
> + update->use_count = 1;
> + update->spec = *spec;
> + update->index = find_first_zero_bit(priv->l23_update_bitmap,
> + RSWITCH_MAX_NUM_RRULE);
> + if (update->index == RSWITCH_MAX_NUM_RRULE) {
> + dev_err_ratelimited(&priv->pdev->dev,
> + "out of l23_update entries\n");
> + /* FIXME: trigger expire? */
> + goto no_free_bit;
> + }
> + set_bit(update->index, priv->l23_update_bitmap);
> +
> + if (!rswitch_l23update_hw_op(priv, update, true))
> + goto hw_op_failed;
> +
> + list_add(&update->list, &priv->l23_update_list);
> +out:
> + spin_unlock(&priv->l3_lock);
> +
> + return update;
> +
> +hw_op_failed:
> + clear_bit(update->index, priv->l23_update_bitmap);
> +no_free_bit:
> + kfree(update);
> + update = NULL;
> + goto out;
It is pretty unusual to have a backwards goto, especially in error
handling. This is one case where a scoped_guard() might make sense.
Andrew
next prev parent reply other threads:[~2025-11-07 2:32 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 12:55 [PATCH net-next 00/10] net: renesas: rswitch: R-Car S4 add HW offloading for layer 3 routing Michael Dege
2025-11-06 12:55 ` [PATCH net-next 01/10] net: renesas: rswitch: cleanup MII settings Michael Dege
2025-11-06 12:55 ` [PATCH net-next 02/10] net: renesas: rswitch: enable Phy link status pin Michael Dege
2025-11-07 1:16 ` Andrew Lunn
2025-11-07 13:37 ` Michael Dege
2025-11-06 12:55 ` [PATCH net-next 03/10] dt-bindings: net: renesas,r8a779f0-ether-switch.yaml: add optional property link-pin Michael Dege
2025-11-06 13:41 ` Geert Uytterhoeven
2025-11-06 14:19 ` Rob Herring (Arm)
2025-11-06 17:16 ` Conor Dooley
2025-11-06 12:55 ` [PATCH net-next 04/10] arm64: dts: renesas: r8a779f4-s4sk.dts add link-pin property Michael Dege
2025-11-06 12:55 ` [PATCH net-next 05/10] arm64: dts: renesas: r8a779f0-spider-ethernet.dtsi " Michael Dege
2025-11-06 12:55 ` [PATCH net-next 06/10] net: renesas: rswitch: add MAC address filtering Michael Dege
2025-11-07 1:18 ` Andrew Lunn
2025-11-06 12:55 ` [PATCH net-next 07/10] net: renesas: rswitch: fix FWPCx register names Michael Dege
2025-11-06 12:55 ` [PATCH net-next 08/10] net: renesas: rswitch: add bit access macros for forwarding engine Michael Dege
2025-11-06 12:55 ` [PATCH net-next 09/10] net: renesas: rswitch: add simple l3 routing Michael Dege
2025-11-07 2:32 ` Andrew Lunn [this message]
2025-11-07 10:02 ` Nikita Yushchenko
2025-11-07 13:29 ` Michael Dege
2025-11-07 13:46 ` Andrew Lunn
2025-11-17 10:46 ` Michael Dege
2025-11-07 13:35 ` Michael Dege
2025-11-06 12:55 ` [PATCH net-next 10/10] net: renesas: rswitch: update error handling of probe Michael Dege
2025-11-07 2:32 ` Andrew Lunn
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=06213fb1-12dc-4045-803e-d2a65c7e9fc6@lunn.ch \
--to=andrew@lunn.ch \
--cc=andrew+netdev@lunn.ch \
--cc=christophe.jaillet@wanadoo.fr \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=geert+renesas@glider.be \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=michael.dege@renesas.com \
--cc=netdev@vger.kernel.org \
--cc=nikita.yoush@cogentembedded.com \
--cc=niklas.soderlund@ragnatech.se \
--cc=pabeni@redhat.com \
--cc=paul@pbarker.dev \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=yoshihiro.shimoda.uh@renesas.com \
/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
all inboxes | Powered by JetHome®