net: dsa: Expose tagging protocol to user-space

There is no way for user-space to know what a given DSA network device's
tagging protocol is. Expose this information through a dsa/tagging
attribute which reflects the tagging protocol currently in use.

This is helpful for configuration (e.g: none behaves dramatically
different wrt. bridges) as well as for packet capture tools when there
is not a proper Ethernet type available.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Florian Fainelli 2018-09-07 11:09:02 -07:00 коммит произвёл David S. Miller
Родитель 0fdc0d675b
Коммит 98cdb48071
4 изменённых файлов: 79 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,7 @@
What: /sys/class/net/<iface>/tagging
Date: August 2018
KernelVersion: 4.20
Contact: netdev@vger.kernel.org
Description:
String indicating the type of tagging protocol used by the
DSA slave network device.

Просмотреть файл

@ -70,6 +70,49 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
[DSA_TAG_PROTO_NONE] = &none_ops,
};
const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
{
const char *protocol_name[DSA_TAG_LAST] = {
#ifdef CONFIG_NET_DSA_TAG_BRCM
[DSA_TAG_PROTO_BRCM] = "brcm",
#endif
#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
[DSA_TAG_PROTO_BRCM_PREPEND] = "brcm-prepend",
#endif
#ifdef CONFIG_NET_DSA_TAG_DSA
[DSA_TAG_PROTO_DSA] = "dsa",
#endif
#ifdef CONFIG_NET_DSA_TAG_EDSA
[DSA_TAG_PROTO_EDSA] = "edsa",
#endif
#ifdef CONFIG_NET_DSA_TAG_KSZ
[DSA_TAG_PROTO_KSZ] = "ksz",
#endif
#ifdef CONFIG_NET_DSA_TAG_LAN9303
[DSA_TAG_PROTO_LAN9303] = "lan9303",
#endif
#ifdef CONFIG_NET_DSA_TAG_MTK
[DSA_TAG_PROTO_MTK] = "mtk",
#endif
#ifdef CONFIG_NET_DSA_TAG_QCA
[DSA_TAG_PROTO_QCA] = "qca",
#endif
#ifdef CONFIG_NET_DSA_TAG_TRAILER
[DSA_TAG_PROTO_TRAILER] = "trailer",
#endif
[DSA_TAG_PROTO_NONE] = "none",
};
unsigned int i;
BUILD_BUG_ON(ARRAY_SIZE(protocol_name) != DSA_TAG_LAST);
for (i = 0; i < ARRAY_SIZE(dsa_device_ops); i++)
if (ops == dsa_device_ops[i])
return protocol_name[i];
return protocol_name[DSA_TAG_PROTO_NONE];
};
const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol)
{
const struct dsa_device_ops *ops;

Просмотреть файл

@ -86,6 +86,7 @@ struct dsa_slave_priv {
/* dsa.c */
const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
bool dsa_schedule_work(struct work_struct *work);
const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
/* legacy.c */
#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)

Просмотреть файл

@ -1058,6 +1058,27 @@ static struct device_type dsa_type = {
.name = "dsa",
};
static ssize_t tagging_show(struct device *d, struct device_attribute *attr,
char *buf)
{
struct net_device *dev = to_net_dev(d);
struct dsa_port *dp = dsa_slave_to_port(dev);
return sprintf(buf, "%s\n",
dsa_tag_protocol_to_str(dp->cpu_dp->tag_ops));
}
static DEVICE_ATTR_RO(tagging);
static struct attribute *dsa_slave_attrs[] = {
&dev_attr_tagging.attr,
NULL
};
static const struct attribute_group dsa_group = {
.name = "dsa",
.attrs = dsa_slave_attrs,
};
static void dsa_slave_phylink_validate(struct net_device *dev,
unsigned long *supported,
struct phylink_link_state *state)
@ -1353,8 +1374,14 @@ int dsa_slave_create(struct dsa_port *port)
goto out_phy;
}
ret = sysfs_create_group(&slave_dev->dev.kobj, &dsa_group);
if (ret)
goto out_unreg;
return 0;
out_unreg:
unregister_netdev(slave_dev);
out_phy:
rtnl_lock();
phylink_disconnect_phy(p->dp->pl);
@ -1378,6 +1405,7 @@ void dsa_slave_destroy(struct net_device *slave_dev)
rtnl_unlock();
dsa_slave_notify(slave_dev, DSA_PORT_UNREGISTER);
sysfs_remove_group(&slave_dev->dev.kobj, &dsa_group);
unregister_netdev(slave_dev);
phylink_destroy(dp->pl);
free_percpu(p->stats64);