diff options
author | Tim Harvey | 2022-11-30 09:42:46 -0800 |
---|---|---|
committer | Tom Rini | 2023-02-02 14:22:08 -0500 |
commit | 43c2a00a14a7e4567b156a2345870d008485da3c (patch) | |
tree | 7d4746490ea7ba6eb2db8157917eafae122898db /net/dsa-uclass.c | |
parent | c5868fcd25c670f5c4e37afca2c5eaddadd218b4 (diff) |
net: dsa: ensure dsa driver has proper ops
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>
Reviewed-by: Fabio Estevam <festevam@denx.de>
Diffstat (limited to 'net/dsa-uclass.c')
-rw-r--r-- | net/dsa-uclass.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/net/dsa-uclass.c b/net/dsa-uclass.c index 5759cedcbec..211a991cdd0 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"); |