Skip to content

Commit 4cfab35

Browse files
ffainellidavem330
authored andcommitted
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: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent aad74d8 commit 4cfab35

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

‎include/net/dsa.h‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ struct dsa_device_ops {
8686
enum dsa_tag_protocol proto;
8787
};
8888

89+
/* This structure defines the control interfaces that are overlayed by the
90+
* DSA layer on top of the DSA CPU/management net_device instance. This is
91+
* used by the core net_device layer while calling various net_device_ops
92+
* function pointers.
93+
*/
94+
struct dsa_netdevice_ops {
95+
int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr,
96+
int cmd);
97+
int (*ndo_get_phys_port_name)(struct net_device *dev, char *name,
98+
size_t len);
99+
};
100+
89101
#define DSA_TAG_DRIVER_ALIAS "dsa_tag-"
90102
#define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \
91103
MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE))
@@ -217,6 +229,7 @@ struct dsa_port {
217229
/*
218230
* Original copy of the master netdev net_device_ops
219231
*/
232+
const struct dsa_netdevice_ops *netdev_ops;
220233
const struct net_device_ops *orig_ndo_ops;
221234

222235
bool setup;
@@ -679,6 +692,63 @@ static inline bool dsa_can_decode(const struct sk_buff *skb,
679692
return false;
680693
}
681694

695+
#if IS_ENABLED(CONFIG_NET_DSA)
696+
static inline int __dsa_netdevice_ops_check(struct net_device *dev)
697+
{
698+
int err = -EOPNOTSUPP;
699+
700+
if (!dev->dsa_ptr)
701+
return err;
702+
703+
if (!dev->dsa_ptr->netdev_ops)
704+
return err;
705+
706+
return 0;
707+
}
708+
709+
static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr,
710+
int cmd)
711+
{
712+
const struct dsa_netdevice_ops *ops;
713+
int err;
714+
715+
err = __dsa_netdevice_ops_check(dev);
716+
if (err)
717+
return err;
718+
719+
ops = dev->dsa_ptr->netdev_ops;
720+
721+
return ops->ndo_do_ioctl(dev, ifr, cmd);
722+
}
723+
724+
static inline int dsa_ndo_get_phys_port_name(struct net_device *dev,
725+
char *name, size_t len)
726+
{
727+
const struct dsa_netdevice_ops *ops;
728+
int err;
729+
730+
err = __dsa_netdevice_ops_check(dev);
731+
if (err)
732+
return err;
733+
734+
ops = dev->dsa_ptr->netdev_ops;
735+
736+
return ops->ndo_get_phys_port_name(dev, name, len);
737+
}
738+
#else
739+
static inline int dsa_ndo_do_ioctl(struct net_device *dev, struct ifreq *ifr,
740+
int cmd)
741+
{
742+
return -EOPNOTSUPP;
743+
}
744+
745+
static inline int dsa_ndo_get_phys_port_name(struct net_device *dev,
746+
char *name, size_t len)
747+
{
748+
return -EOPNOTSUPP;
749+
}
750+
#endif
751+
682752
void dsa_unregister_switch(struct dsa_switch *ds);
683753
int dsa_register_switch(struct dsa_switch *ds);
684754
struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);

0 commit comments

Comments
 (0)