[PATCH net-next v5 4/5] net: ipqess: Add out-of-band DSA tagging support

Vladimir Oltean vladimir.oltean at nxp.com
Fri Oct 21 07:12:35 PDT 2022


On Fri, Oct 21, 2022 at 02:45:55PM +0200, Maxime Chevallier wrote:
> +static int ipqess_netdevice_event(struct notifier_block *nb,
> +				  unsigned long event, void *ptr)
> +{
> +	struct ipqess *ess = container_of(nb, struct ipqess, netdev_notifier);
> +	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
> +	struct netdev_notifier_changeupper_info *info;
> +
> +	switch (event) {
> +	case NETDEV_CHANGEUPPER:
> +		info = ptr;
> +
> +		if (dev->netdev_ops != &ipqess_axi_netdev_ops)
> +			return NOTIFY_DONE;
> +
> +		if (!dsa_slave_dev_check(info->upper_dev))
> +			return NOTIFY_DONE;
> +
> +		if (info->linking)
> +			ess->dsa_ports++;
> +		else
> +			ess->dsa_ports--;

How many ipqess devices are there in a system? The netdev notifier
should be a singleton, meaning it should be registered at module_init()
and unregistered at module_exit(). You can then get the "ess" pointer as
netdev_priv(dev), once you ensure that dev->netdev_ops is what you expect.

The code is already wrong: you take *ess from the &ess->netdev_notifier
reference, then you increment ess->dsa_ports based on the sole condition
that "dev" (the interface on which the notification was already emitted)
was an ess netdevice. But the "dev" pointer could be ess1, and the "ess"
pointer could be the netdev_priv(ess0). Your logic would increment the
dsa_ports of ess0 when a DSA switch joined ess1 (because all notifier
handlers see the event).

> +
> +		return NOTIFY_DONE;
> +	}
> +	return NOTIFY_OK;
> +}
> +
> @@ -1201,12 +1255,19 @@ static int ipqess_axi_probe(struct platform_device *pdev)
>  		netif_napi_add(netdev, &ess->rx_ring[i].napi_rx, ipqess_rx_napi);
>  	}
>  
> -	err = register_netdev(netdev);
> +	ess->netdev_notifier.notifier_call = ipqess_netdevice_event;
> +	err = register_netdevice_notifier(&ess->netdev_notifier);
>  	if (err)
>  		goto err_hw_stop;
>  
> +	err = register_netdev(netdev);
> +	if (err)
> +		goto err_notifier_unregister;
> +
>  	return 0;
>  
> +err_notifier_unregister:
> +	unregister_netdevice_notifier(&ess->netdev_notifier);
>  err_hw_stop:
>  	ipqess_hw_stop(ess);
>  
> diff --git a/drivers/net/ethernet/qualcomm/ipqess/ipqess.h b/drivers/net/ethernet/qualcomm/ipqess/ipqess.h
> index 9a4ab6ce282a..33cccaf6f143 100644
> --- a/drivers/net/ethernet/qualcomm/ipqess/ipqess.h
> +++ b/drivers/net/ethernet/qualcomm/ipqess/ipqess.h
> @@ -171,6 +171,10 @@ struct ipqess {
>  	struct platform_device *pdev;
>  	struct phylink *phylink;
>  	struct phylink_config phylink_config;
> +
> +	struct notifier_block netdev_notifier;
> +	int dsa_ports;
> +
>  	struct ipqess_tx_ring tx_ring[IPQESS_NETDEV_QUEUES];
>  
>  	struct ipqess_statistics ipqess_stats;
> -- 
> 2.37.3
>


More information about the linux-arm-kernel mailing list