From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Claudiu Manoil <claudiu.manoil@nxp.com>
Subject: [PATCH net-next 11/12] net: enetc: set up XDP program under enetc_reconfigure()
Date: Wed, 18 Jan 2023 01:02:33 +0200 [thread overview]
Message-ID: <20230117230234.2950873-12-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20230117230234.2950873-1-vladimir.oltean@nxp.com>
Offloading a BPF program to the RX path of the driver suffers from the
same problems as the PTP reconfiguration - improper error checking can
leave the driver in an invalid state, and the link on the PHY is lost.
Reuse the enetc_reconfigure() procedure, but here, we need to run some
code in the middle of the ring reconfiguration procedure - while the
interface is still down. Introduce a callback which makes that possible.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/freescale/enetc/enetc.c | 51 ++++++++++++--------
1 file changed, 32 insertions(+), 19 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index ce3319f55573..eeff69336a80 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -2489,16 +2489,24 @@ int enetc_close(struct net_device *ndev)
return 0;
}
-static int enetc_reconfigure(struct enetc_ndev_priv *priv, bool extended)
+static int enetc_reconfigure(struct enetc_ndev_priv *priv, bool extended,
+ int (*cb)(struct enetc_ndev_priv *priv, void *ctx),
+ void *ctx)
{
struct enetc_bdr_resource *tx_res, *rx_res;
int err;
ASSERT_RTNL();
- /* If the interface is down, do nothing. */
- if (!netif_running(priv->ndev))
+ /* If the interface is down, run the callback right away,
+ * without reconfiguration.
+ */
+ if (!netif_running(priv->ndev)) {
+ if (cb)
+ cb(priv, ctx);
+
return 0;
+ }
tx_res = enetc_alloc_tx_resources(priv);
if (IS_ERR(tx_res)) {
@@ -2516,6 +2524,10 @@ static int enetc_reconfigure(struct enetc_ndev_priv *priv, bool extended)
enetc_clear_bdrs(priv);
enetc_free_rxtx_rings(priv);
+ /* Interface is down, run optional callback now */
+ if (cb)
+ cb(priv, ctx);
+
enetc_assign_tx_resources(priv, tx_res);
enetc_assign_rx_resources(priv, rx_res);
enetc_setup_bdrs(priv, extended);
@@ -2586,21 +2598,11 @@ int enetc_setup_tc_mqprio(struct net_device *ndev, void *type_data)
return 0;
}
-static int enetc_setup_xdp_prog(struct net_device *ndev, struct bpf_prog *prog,
- struct netlink_ext_ack *extack)
+static int enetc_reconfigure_xdp_cb(struct enetc_ndev_priv *priv, void *ctx)
{
- struct enetc_ndev_priv *priv = netdev_priv(ndev);
- struct bpf_prog *old_prog;
- bool is_up;
+ struct bpf_prog *old_prog, *prog = ctx;
int i;
- /* The buffer layout is changing, so we need to drain the old
- * RX buffers and seed new ones.
- */
- is_up = netif_running(ndev);
- if (is_up)
- dev_close(ndev);
-
old_prog = xchg(&priv->xdp_prog, prog);
if (old_prog)
bpf_prog_put(old_prog);
@@ -2616,12 +2618,23 @@ static int enetc_setup_xdp_prog(struct net_device *ndev, struct bpf_prog *prog,
rx_ring->buffer_offset = ENETC_RXB_PAD;
}
- if (is_up)
- return dev_open(ndev, extack);
-
return 0;
}
+static int enetc_setup_xdp_prog(struct net_device *ndev, struct bpf_prog *prog,
+ struct netlink_ext_ack *extack)
+{
+ struct enetc_ndev_priv *priv = netdev_priv(ndev);
+ bool extended;
+
+ extended = !!(priv->active_offloads & ENETC_F_RX_TSTAMP);
+
+ /* The buffer layout is changing, so we need to drain the old
+ * RX buffers and seed new ones.
+ */
+ return enetc_reconfigure(priv, extended, enetc_reconfigure_xdp_cb, prog);
+}
+
int enetc_setup_bpf(struct net_device *ndev, struct netdev_bpf *bpf)
{
switch (bpf->command) {
@@ -2755,7 +2768,7 @@ static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
if ((new_offloads ^ priv->active_offloads) & ENETC_F_RX_TSTAMP) {
bool extended = !!(new_offloads & ENETC_F_RX_TSTAMP);
- err = enetc_reconfigure(priv, extended);
+ err = enetc_reconfigure(priv, extended, NULL, NULL);
if (err)
return err;
}
--
2.34.1
next prev parent reply other threads:[~2023-01-17 23:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-17 23:02 [PATCH net-next 00/12] ENETC BD ring cleanup Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 01/12] net: enetc: set next_to_clean/next_to_use just from enetc_setup_txbdr() Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 02/12] net: enetc: set up RX ring indices from enetc_setup_rxbdr() Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 03/12] net: enetc: create enetc_dma_free_bdr() Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 04/12] net: enetc: rx_swbd and tx_swbd are never NULL in enetc_free_rxtx_rings() Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 05/12] net: enetc: drop redundant enetc_free_tx_frame() call from enetc_free_txbdr() Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 06/12] net: enetc: bring "bool extended" to top-level in enetc_open() Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 07/12] net: enetc: split ring resource allocation from assignment Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 08/12] net: enetc: move phylink_start/stop out of enetc_start/stop Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 09/12] net: enetc: implement ring reconfiguration procedure for PTP RX timestamping Vladimir Oltean
2023-01-18 10:51 ` Vladimir Oltean
2023-01-17 23:02 ` [PATCH net-next 10/12] net: enetc: rename "xdp" and "dev" in enetc_setup_bpf() Vladimir Oltean
2023-01-17 23:02 ` Vladimir Oltean [this message]
2023-01-17 23:02 ` [PATCH net-next 12/12] net: enetc: prioritize ability to go down over packet processing Vladimir Oltean
2023-01-19 5:10 ` [PATCH net-next 00/12] ENETC BD ring cleanup patchwork-bot+netdevbpf
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=20230117230234.2950873-12-vladimir.oltean@nxp.com \
--to=vladimir.oltean@nxp.com \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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