diff mbox series

[3/8] net: dsa: ensure dsa driver has proper ops

Message ID 20220512002003.16886-4-tharvey@gateworks.com
State Superseded, archived
Delegated to: Ramon Fried
Headers show
Series Add MV88E61xx DSA driver and use on gwventana | expand

Commit Message

Tim Harvey May 12, 2022, 12:19 a.m. UTC
Add a function to sanity check a dsa driver having proper ops.

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

Comments

Vladimir Oltean May 18, 2022, 2:31 p.m. UTC | #1
On Wed, May 11, 2022 at 05:19:58PM -0700, Tim Harvey wrote:
> Add a function to sanity check a dsa driver having proper ops.
> 
> Suggested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> Signed-off-by: Tim Harvey <tharvey@gateworks.com>
> ---

Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
diff mbox series

Patch

diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c
index 07edc584daf3..b3033c97aa63 100644
--- a/net/dsa-uclass.c
+++ b/net/dsa-uclass.c
@@ -342,6 +342,19 @@  U_BOOT_DRIVER(dsa_port) = {
 	.plat_auto = sizeof(struct eth_pdata),
 };
 
+static int dsa_sanitize_ops(struct udevice *dev)
+{
+	struct dsa_ops *ops = dsa_get_ops(dev);
+
+	if ((!ops->xmit || !ops->rcv) &&
+	    (!ops->port_enable && !ops->port_disable)) {
+		dev_err(dev, "Packets cannot be steered to ports\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 /*
  * This function mostly deals with pulling information out of the device tree
  * into the pdata structure.
@@ -358,6 +371,10 @@  static int dsa_post_bind(struct udevice *dev)
 	if (!ofnode_valid(node))
 		return -ENODEV;
 
+	err = dsa_sanitize_ops(dev);
+	if (err)
+		return err;
+
 	pdata->master_node = ofnode_null();
 
 	node = ofnode_find_subnode(node, "ports");