slave.c (a3a4de056ed5cfb22085173d8f0f13b0ca6b6d60) slave.c (f50f212749e8a28803af3628acbeb85ee0458ed5)
1/*
2 * net/dsa/slave.c - Slave device handling
3 * Copyright (c) 2008-2009 Marvell Semiconductor
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
11#include <linux/list.h>
12#include <linux/etherdevice.h>
13#include <linux/netdevice.h>
14#include <linux/phy.h>
15#include <linux/phy_fixed.h>
16#include <linux/of_net.h>
17#include <linux/of_mdio.h>
18#include <linux/mdio.h>
1/*
2 * net/dsa/slave.c - Slave device handling
3 * Copyright (c) 2008-2009 Marvell Semiconductor
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
11#include <linux/list.h>
12#include <linux/etherdevice.h>
13#include <linux/netdevice.h>
14#include <linux/phy.h>
15#include <linux/phy_fixed.h>
16#include <linux/of_net.h>
17#include <linux/of_mdio.h>
18#include <linux/mdio.h>
19#include <linux/list.h>
19#include <net/rtnetlink.h>
20#include <net/switchdev.h>
20#include <net/rtnetlink.h>
21#include <net/switchdev.h>
22#include <net/pkt_cls.h>
23#include <net/tc_act/tc_mirred.h>
21#include <linux/if_bridge.h>
22#include <linux/netpoll.h>
23#include "dsa_priv.h"
24
24#include <linux/if_bridge.h>
25#include <linux/netpoll.h>
26#include "dsa_priv.h"
27
28static bool dsa_slave_dev_check(struct net_device *dev);
29
25/* slave mii_bus handling ***************************************************/
26static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg)
27{
28 struct dsa_switch *ds = bus->priv;
29
30 if (ds->phys_mii_mask & (1 << addr))
31 return ds->ops->phy_read(ds, addr, reg);
32

--- 957 unchanged lines hidden (view full) ---

990 struct dsa_slave_priv *p = netdev_priv(dev);
991
992 if (snprintf(name, len, "p%d", p->dp->index) >= len)
993 return -EINVAL;
994
995 return 0;
996}
997
30/* slave mii_bus handling ***************************************************/
31static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg)
32{
33 struct dsa_switch *ds = bus->priv;
34
35 if (ds->phys_mii_mask & (1 << addr))
36 return ds->ops->phy_read(ds, addr, reg);
37

--- 957 unchanged lines hidden (view full) ---

995 struct dsa_slave_priv *p = netdev_priv(dev);
996
997 if (snprintf(name, len, "p%d", p->dp->index) >= len)
998 return -EINVAL;
999
1000 return 0;
1001}
1002
1003static struct dsa_mall_tc_entry *
1004dsa_slave_mall_tc_entry_find(struct dsa_slave_priv *p,
1005 unsigned long cookie)
1006{
1007 struct dsa_mall_tc_entry *mall_tc_entry;
1008
1009 list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list)
1010 if (mall_tc_entry->cookie == cookie)
1011 return mall_tc_entry;
1012
1013 return NULL;
1014}
1015
1016static int dsa_slave_add_cls_matchall(struct net_device *dev,
1017 __be16 protocol,
1018 struct tc_cls_matchall_offload *cls,
1019 bool ingress)
1020{
1021 struct dsa_slave_priv *p = netdev_priv(dev);
1022 struct dsa_mall_tc_entry *mall_tc_entry;
1023 struct dsa_switch *ds = p->dp->ds;
1024 struct net *net = dev_net(dev);
1025 struct dsa_slave_priv *to_p;
1026 struct net_device *to_dev;
1027 const struct tc_action *a;
1028 int err = -EOPNOTSUPP;
1029 LIST_HEAD(actions);
1030 int ifindex;
1031
1032 if (!ds->ops->port_mirror_add)
1033 return err;
1034
1035 if (!tc_single_action(cls->exts))
1036 return err;
1037
1038 tcf_exts_to_list(cls->exts, &actions);
1039 a = list_first_entry(&actions, struct tc_action, list);
1040
1041 if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) {
1042 struct dsa_mall_mirror_tc_entry *mirror;
1043
1044 ifindex = tcf_mirred_ifindex(a);
1045 to_dev = __dev_get_by_index(net, ifindex);
1046 if (!to_dev)
1047 return -EINVAL;
1048
1049 if (!dsa_slave_dev_check(to_dev))
1050 return -EOPNOTSUPP;
1051
1052 mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
1053 if (!mall_tc_entry)
1054 return -ENOMEM;
1055
1056 mall_tc_entry->cookie = cls->cookie;
1057 mall_tc_entry->type = DSA_PORT_MALL_MIRROR;
1058 mirror = &mall_tc_entry->mirror;
1059
1060 to_p = netdev_priv(to_dev);
1061
1062 mirror->to_local_port = to_p->dp->index;
1063 mirror->ingress = ingress;
1064
1065 err = ds->ops->port_mirror_add(ds, p->dp->index, mirror,
1066 ingress);
1067 if (err) {
1068 kfree(mall_tc_entry);
1069 return err;
1070 }
1071
1072 list_add_tail(&mall_tc_entry->list, &p->mall_tc_list);
1073 }
1074
1075 return 0;
1076}
1077
1078static void dsa_slave_del_cls_matchall(struct net_device *dev,
1079 struct tc_cls_matchall_offload *cls)
1080{
1081 struct dsa_slave_priv *p = netdev_priv(dev);
1082 struct dsa_mall_tc_entry *mall_tc_entry;
1083 struct dsa_switch *ds = p->dp->ds;
1084
1085 if (!ds->ops->port_mirror_del)
1086 return;
1087
1088 mall_tc_entry = dsa_slave_mall_tc_entry_find(p, cls->cookie);
1089 if (!mall_tc_entry)
1090 return;
1091
1092 list_del(&mall_tc_entry->list);
1093
1094 switch (mall_tc_entry->type) {
1095 case DSA_PORT_MALL_MIRROR:
1096 ds->ops->port_mirror_del(ds, p->dp->index,
1097 &mall_tc_entry->mirror);
1098 break;
1099 default:
1100 WARN_ON(1);
1101 }
1102
1103 kfree(mall_tc_entry);
1104}
1105
1106static int dsa_slave_setup_tc(struct net_device *dev, u32 handle,
1107 __be16 protocol, struct tc_to_netdev *tc)
1108{
1109 bool ingress = TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS);
1110 int ret = -EOPNOTSUPP;
1111
1112 switch (tc->type) {
1113 case TC_SETUP_MATCHALL:
1114 switch (tc->cls_mall->command) {
1115 case TC_CLSMATCHALL_REPLACE:
1116 return dsa_slave_add_cls_matchall(dev, protocol,
1117 tc->cls_mall,
1118 ingress);
1119 case TC_CLSMATCHALL_DESTROY:
1120 dsa_slave_del_cls_matchall(dev, tc->cls_mall);
1121 return 0;
1122 }
1123 default:
1124 break;
1125 }
1126
1127 return ret;
1128}
1129
998void dsa_cpu_port_ethtool_init(struct ethtool_ops *ops)
999{
1000 ops->get_sset_count = dsa_cpu_port_get_sset_count;
1001 ops->get_ethtool_stats = dsa_cpu_port_get_ethtool_stats;
1002 ops->get_strings = dsa_cpu_port_get_strings;
1003}
1004
1005static int dsa_slave_get_rxnfc(struct net_device *dev,

--- 58 unchanged lines hidden (view full) ---

1064 .ndo_netpoll_setup = dsa_slave_netpoll_setup,
1065 .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,
1066 .ndo_poll_controller = dsa_slave_poll_controller,
1067#endif
1068 .ndo_bridge_getlink = switchdev_port_bridge_getlink,
1069 .ndo_bridge_setlink = switchdev_port_bridge_setlink,
1070 .ndo_bridge_dellink = switchdev_port_bridge_dellink,
1071 .ndo_get_phys_port_name = dsa_slave_get_phys_port_name,
1130void dsa_cpu_port_ethtool_init(struct ethtool_ops *ops)
1131{
1132 ops->get_sset_count = dsa_cpu_port_get_sset_count;
1133 ops->get_ethtool_stats = dsa_cpu_port_get_ethtool_stats;
1134 ops->get_strings = dsa_cpu_port_get_strings;
1135}
1136
1137static int dsa_slave_get_rxnfc(struct net_device *dev,

--- 58 unchanged lines hidden (view full) ---

1196 .ndo_netpoll_setup = dsa_slave_netpoll_setup,
1197 .ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,
1198 .ndo_poll_controller = dsa_slave_poll_controller,
1199#endif
1200 .ndo_bridge_getlink = switchdev_port_bridge_getlink,
1201 .ndo_bridge_setlink = switchdev_port_bridge_setlink,
1202 .ndo_bridge_dellink = switchdev_port_bridge_dellink,
1203 .ndo_get_phys_port_name = dsa_slave_get_phys_port_name,
1204 .ndo_setup_tc = dsa_slave_setup_tc,
1072};
1073
1074static const struct switchdev_ops dsa_slave_switchdev_ops = {
1075 .switchdev_port_attr_get = dsa_slave_port_attr_get,
1076 .switchdev_port_attr_set = dsa_slave_port_attr_set,
1077 .switchdev_port_obj_add = dsa_slave_port_obj_add,
1078 .switchdev_port_obj_del = dsa_slave_port_obj_del,
1079 .switchdev_port_obj_dump = dsa_slave_port_obj_dump,

--- 200 unchanged lines hidden (view full) ---

1280 if (ds->master_netdev)
1281 master = ds->master_netdev;
1282
1283 slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name,
1284 NET_NAME_UNKNOWN, ether_setup);
1285 if (slave_dev == NULL)
1286 return -ENOMEM;
1287
1205};
1206
1207static const struct switchdev_ops dsa_slave_switchdev_ops = {
1208 .switchdev_port_attr_get = dsa_slave_port_attr_get,
1209 .switchdev_port_attr_set = dsa_slave_port_attr_set,
1210 .switchdev_port_obj_add = dsa_slave_port_obj_add,
1211 .switchdev_port_obj_del = dsa_slave_port_obj_del,
1212 .switchdev_port_obj_dump = dsa_slave_port_obj_dump,

--- 200 unchanged lines hidden (view full) ---

1413 if (ds->master_netdev)
1414 master = ds->master_netdev;
1415
1416 slave_dev = alloc_netdev(sizeof(struct dsa_slave_priv), name,
1417 NET_NAME_UNKNOWN, ether_setup);
1418 if (slave_dev == NULL)
1419 return -ENOMEM;
1420
1288 slave_dev->features = master->vlan_features;
1421 slave_dev->features = master->vlan_features | NETIF_F_HW_TC;
1422 slave_dev->hw_features |= NETIF_F_HW_TC;
1289 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
1290 eth_hw_addr_inherit(slave_dev, master);
1291 slave_dev->priv_flags |= IFF_NO_QUEUE;
1292 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
1293 slave_dev->switchdev_ops = &dsa_slave_switchdev_ops;
1294 slave_dev->min_mtu = 0;
1295 slave_dev->max_mtu = ETH_MAX_MTU;
1296 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type);
1297
1298 netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
1299 NULL);
1300
1301 SET_NETDEV_DEV(slave_dev, parent);
1302 slave_dev->dev.of_node = ds->ports[port].dn;
1303 slave_dev->vlan_features = master->vlan_features;
1304
1305 p = netdev_priv(slave_dev);
1306 p->dp = &ds->ports[port];
1423 slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
1424 eth_hw_addr_inherit(slave_dev, master);
1425 slave_dev->priv_flags |= IFF_NO_QUEUE;
1426 slave_dev->netdev_ops = &dsa_slave_netdev_ops;
1427 slave_dev->switchdev_ops = &dsa_slave_switchdev_ops;
1428 slave_dev->min_mtu = 0;
1429 slave_dev->max_mtu = ETH_MAX_MTU;
1430 SET_NETDEV_DEVTYPE(slave_dev, &dsa_type);
1431
1432 netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one,
1433 NULL);
1434
1435 SET_NETDEV_DEV(slave_dev, parent);
1436 slave_dev->dev.of_node = ds->ports[port].dn;
1437 slave_dev->vlan_features = master->vlan_features;
1438
1439 p = netdev_priv(slave_dev);
1440 p->dp = &ds->ports[port];
1441 INIT_LIST_HEAD(&p->mall_tc_list);
1307 p->xmit = dst->tag_ops->xmit;
1308
1309 p->old_pause = -1;
1310 p->old_link = -1;
1311 p->old_duplex = -1;
1312
1313 ds->ports[port].netdev = slave_dev;
1314 ret = register_netdev(slave_dev);

--- 87 unchanged lines hidden ---
1442 p->xmit = dst->tag_ops->xmit;
1443
1444 p->old_pause = -1;
1445 p->old_link = -1;
1446 p->old_duplex = -1;
1447
1448 ds->ports[port].netdev = slave_dev;
1449 ret = register_netdev(slave_dev);

--- 87 unchanged lines hidden ---