public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tim Harvey <tharvey@gateworks.com>
To: "Joe Hershberger" <joe.hershberger@ni.com>,
	"Ramon Fried" <rfried.dev@gmail.com>,
	"Vladimir Oltean" <vladimir.oltean@nxp.com>,
	u-boot@lists.denx.de, "Stefano Babic" <sbabic@denx.de>,
	"Fabio Estevam" <festevam@gmail.com>,
	"NXP i . MX U-Boot Team" <uboot-imx@nxp.com>,
	"Marek Behún" <marek.behun@nic.cz>
Cc: Chris Packham <Chris.Packham@alliedtelesis.co.nz>,
	Anatolij Gustschin <agust@denx.de>,
	Tim Harvey <tharvey@gateworks.com>
Subject: [PATCH 4/8] net: dsa: allow rcv() and xmit() to be optional
Date: Wed, 11 May 2022 17:19:59 -0700	[thread overview]
Message-ID: <20220512002003.16886-5-tharvey@gateworks.com> (raw)
In-Reply-To: <20220512002003.16886-1-tharvey@gateworks.com>

Allow rcv() and xmit() dsa driver ops to be optional in case a driver
does not care to mangle a packet as in U-Boot only one network port is
enabled at a time and thus no packet mangling is necessary.

Suggested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
v2: new patch
---
 net/dsa-uclass.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c
index b3033c97aa63..f82217e0d7a7 100644
--- a/net/dsa-uclass.c
+++ b/net/dsa-uclass.c
@@ -131,16 +131,14 @@ static void dsa_port_stop(struct udevice *pdev)
  * We copy the frame to a stack buffer where we have reserved headroom and
  * tailroom space.  Headroom and tailroom are set to 0.
  */
-static int dsa_port_send(struct udevice *pdev, void *packet, int length)
+static int dsa_port_mangle_packet(struct udevice *pdev, void *packet, int length)
 {
+	struct dsa_port_pdata *port_pdata = dev_get_parent_plat(pdev);
 	struct udevice *dev = dev_get_parent(pdev);
 	struct dsa_priv *priv = dev_get_uclass_priv(dev);
 	int head = priv->headroom, tail = priv->tailroom;
-	struct udevice *master = dsa_get_master(dev);
 	struct dsa_ops *ops = dsa_get_ops(dev);
 	uchar dsa_packet_tmp[PKTSIZE_ALIGN];
-	struct dsa_port_pdata *port_pdata;
-	int err;
 
 	if (length + head + tail > PKTSIZE_ALIGN)
 		return -EINVAL;
@@ -152,10 +150,21 @@ static int dsa_port_send(struct udevice *pdev, void *packet, int length)
 	/* copy back to preserve original buffer alignment */
 	memcpy(packet, dsa_packet_tmp, length);
 
-	port_pdata = dev_get_parent_plat(pdev);
-	err = ops->xmit(dev, port_pdata->index, packet, length);
-	if (err)
-		return err;
+	return ops->xmit(dev, port_pdata->index, packet, length);
+}
+
+static int dsa_port_send(struct udevice *pdev, void *packet, int length)
+{
+	struct udevice *dev = dev_get_parent(pdev);
+	struct udevice *master = dsa_get_master(dev);
+	struct dsa_ops *ops = dsa_get_ops(dev);
+	int err;
+
+	if (ops->xmit) {
+		err = dsa_port_mangle_packet(pdev, packet, length);
+		if (err)
+			return err;
+	}
 
 	return eth_get_ops(master)->send(master, packet, length);
 }
@@ -172,7 +181,7 @@ static int dsa_port_recv(struct udevice *pdev, int flags, uchar **packetp)
 	int length, port_index, err;
 
 	length = eth_get_ops(master)->recv(master, flags, packetp);
-	if (length <= 0)
+	if (length <= 0 || !ops->rcv)
 		return length;
 
 	/*
-- 
2.17.1


  parent reply	other threads:[~2022-05-12  0:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12  0:19 [PATCH v2 0/8] Add MV88E61xx DSA driver and use on gwventana Tim Harvey
2022-05-12  0:19 ` [PATCH 1/8] net: mdio-uclass: scan for dm mdio children on post-bind Tim Harvey
2022-05-12  0:19 ` [PATCH 2/8] net: dsa: move cpu port probe to dsa_post_probe Tim Harvey
2022-05-18 14:30   ` Vladimir Oltean
2022-05-12  0:19 ` [PATCH 3/8] net: dsa: ensure dsa driver has proper ops Tim Harvey
2022-05-18 14:31   ` Vladimir Oltean
2022-05-12  0:19 ` Tim Harvey [this message]
2022-05-18 14:31   ` [PATCH 4/8] net: dsa: allow rcv() and xmit() to be optional Vladimir Oltean
2022-05-12  0:20 ` [PATCH 5/8] net: ksz9477: remove unnecessary xmit and recv functions Tim Harvey
2022-05-18 14:30   ` Vladimir Oltean
2022-05-12  0:20 ` [PATCH 6/8] net: fec: add support for DM_MDIO Tim Harvey
2022-05-12  0:20 ` [PATCH 7/8] net: add MV88E61xx DSA driver Tim Harvey
2022-05-18 14:33   ` Vladimir Oltean
2022-05-12  0:20 ` [PATCH 8/8] board: gw_ventana: enable MV88E61XX DSA support Tim Harvey
2022-05-18 14:41   ` Vladimir Oltean
2022-05-18 16:15     ` Tim Harvey
2022-05-19 13:15       ` Vladimir Oltean

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=20220512002003.16886-5-tharvey@gateworks.com \
    --to=tharvey@gateworks.com \
    --cc=Chris.Packham@alliedtelesis.co.nz \
    --cc=agust@denx.de \
    --cc=festevam@gmail.com \
    --cc=joe.hershberger@ni.com \
    --cc=marek.behun@nic.cz \
    --cc=rfried.dev@gmail.com \
    --cc=sbabic@denx.de \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.com \
    --cc=vladimir.oltean@nxp.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