aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harvey2022-11-30 09:42:47 -0800
committerTom Rini2023-02-02 14:22:08 -0500
commit54d11e2019b73758070632d695cf47f3d5fbf108 (patch)
tree6f39e3521f10319db8f029132b357798a2d906a6
parent43c2a00a14a7e4567b156a2345870d008485da3c (diff)
net: dsa: allow rcv() and xmit() to be optional
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> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Fabio Estevam <festevam@denx.de> Signed-off-by: Tim Harvey <tharvey@gateworks.com>
-rw-r--r--net/dsa-uclass.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c
index 211a991cdd0..dd78e5744d5 100644
--- a/net/dsa-uclass.c
+++ b/net/dsa-uclass.c
@@ -142,20 +142,22 @@ static int dsa_port_send(struct udevice *pdev, void *packet, int length)
struct dsa_port_pdata *port_pdata;
int err;
- if (length + head + tail > PKTSIZE_ALIGN)
- return -EINVAL;
+ if (ops->xmit) {
+ if (length + head + tail > PKTSIZE_ALIGN)
+ return -EINVAL;
- memset(dsa_packet_tmp, 0, head);
- memset(dsa_packet_tmp + head + length, 0, tail);
- memcpy(dsa_packet_tmp + head, packet, length);
- length += head + tail;
- /* copy back to preserve original buffer alignment */
- memcpy(packet, dsa_packet_tmp, length);
+ memset(dsa_packet_tmp, 0, head);
+ memset(dsa_packet_tmp + head + length, 0, tail);
+ memcpy(dsa_packet_tmp + head, packet, length);
+ length += head + tail;
+ /* 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;
+ port_pdata = dev_get_parent_plat(pdev);
+ err = ops->xmit(dev, port_pdata->index, packet, length);
+ if (err)
+ return err;
+ }
return eth_get_ops(master)->send(master, packet, length);
}
@@ -172,7 +174,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;
/*