Commit 4cfab356 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

net: dsa: Add wrappers for overloaded ndo_ops

Add definitions for the dsa_netdevice_ops structure which is a subset of
the net_device_ops structure for the specific operations that we care
about overlaying on top of the DSA CPU port net_device and provide
inline stubs that take core managing whether DSA code is reachable.
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent aad74d84
...@@ -86,6 +86,18 @@ struct dsa_device_ops { ...@@ -86,6 +86,18 @@ struct dsa_device_ops {
enum dsa_tag_protocol proto; enum dsa_tag_protocol proto;
}; };
/* This structure defines the control interfaces that are overlayed by the
* DSA layer on top of the DSA CPU/management net_device instance. This is
* used by the core net_device layer while calling various net_device_ops
* function pointers.
*/
struct dsa_netdevice_ops {
int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr,
int cmd);
int (*ndo_get_phys_port_name)(struct net_device *dev, char *name,
size_t len);
};
#define DSA_TAG_DRIVER_ALIAS "dsa_tag-" #define DSA_TAG_DRIVER_ALIAS "dsa_tag-"
#define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \ #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \
MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE)) MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE))
...@@ -217,6 +229,7 @@ struct dsa_port { ...@@ -217,6 +229,7 @@ struct dsa_port {
/* /*
* Original copy of the master netdev net_device_ops * Original copy of the master netdev net_device_ops
*/ */
const struct dsa_netdevice_ops *netdev_ops;
const struct net_device_ops *orig_ndo_ops; const struct net_device_ops *orig_ndo_ops;
bool setup; bool setup;
...@@ -679,6 +692,63 @@ static inline bool dsa_can_decode(const struct sk_buff *skb, ...@@ -679,6 +692,63 @@ static inline bool dsa_can_decode(const struct sk_buff *skb,
return false; return false;
} }
#if IS_ENABLED(CONFIG_NET_DSA)
static inline int __dsa_netdevice_ops_check(struct net_device *dev)
{
int err = -EOPNOTSUPP;
if (!dev->dsa_ptr)
return err;
if (!dev->dsa_ptr->netdev_ops)
return err;
return 0;
}
static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr,
int cmd)
{
const struct dsa_netdevice_ops *ops;
int err;
err = __dsa_netdevice_ops_check(dev);
if (err)
return err;
ops = dev->dsa_ptr->netdev_ops;
return ops->ndo_do_ioctl(dev, ifr, cmd);
}
static inline int dsa_ndo_get_phys_port_name(struct net_device *dev,
char *name, size_t len)
{
const struct dsa_netdevice_ops *ops;
int err;
err = __dsa_netdevice_ops_check(dev);
if (err)
return err;
ops = dev->dsa_ptr->netdev_ops;
return ops->ndo_get_phys_port_name(dev, name, len);
}
#else
static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr,
int cmd)
{
return -EOPNOTSUPP;
}
static inline int dsa_ndo_get_phys_port_name(struct net_device *dev,
char *name, size_t len)
{
return -EOPNOTSUPP;
}
#endif
void dsa_unregister_switch(struct dsa_switch *ds); void dsa_unregister_switch(struct dsa_switch *ds);
int dsa_register_switch(struct dsa_switch *ds); int dsa_register_switch(struct dsa_switch *ds);
struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment