[PATCH v3 02/12] net: add of_find_eth_device_by_node() function

Sascha Hauer sha at pengutronix.de
Thu Apr 7 06:36:11 PDT 2022


On Thu, Apr 07, 2022 at 11:15:54AM +0200, Oleksij Rempel wrote:
> For DSA support we need to find MAC node by phandle from the switch port
> node. So, provide of_find_eth_device_by_node() to solve this task.
> 
> Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
> ---
>  include/net.h |  1 +
>  net/eth.c     | 16 ++++++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/include/net.h b/include/net.h
> index ca9b6cd61e..8013f79c2e 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -97,6 +97,7 @@ int eth_open(struct eth_device *edev);
>  void eth_close(struct eth_device *edev);
>  int eth_send(struct eth_device *edev, void *packet, int length);	   /* Send a packet		*/
>  int eth_rx(void);			/* Check for received packets	*/
> +struct eth_device *of_find_eth_device_by_node(struct device_node *np);
>  
>  /* associate a MAC address to a ethernet device. Should be called by
>   * board code for boards which store their MAC address at some unusual
> diff --git a/net/eth.c b/net/eth.c
> index 762c5dfb8a..06bf5fbe65 100644
> --- a/net/eth.c
> +++ b/net/eth.c
> @@ -506,6 +506,22 @@ void led_trigger_network(enum led_trigger trigger)
>  	led_trigger(LED_TRIGGER_NET_TXRX, TRIGGER_FLASH);
>  }
>  
> +struct eth_device *of_find_eth_device_by_node(struct device_node *np)
> +{
> +	struct eth_device *edev;
> +	int ret;
> +
> +	ret = of_device_ensure_probed(np);
> +	if (ret)
> +		return NULL;
> +
> +	list_for_each_entry(edev, &netdev_list, list)
> +		if (edev->parent->device_node == np)
> +			return edev;
> +	return NULL;
> +}
> +EXPORT_SYMBOL(of_find_device_by_node);

Should be of_find_eth_device_by_node

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list