History

net: Get rid of SWITCHDEV_ATTR_ID_PORT_PARENT_ID

Now that we have a dedicated NDO for getting a port's parent ID, get rid of SWITCHDEV_ATTR_ID_PORT_PARENT_ID and convert all callers to use the NDO exclusively. This is a preliminary change to getting rid of switchdev_ops eventually.

Florian Fainelli committed 7 years ago

Commit bccb3021 parent 929d6c16 files · +15 −84Browse files

Unified · Split

6 files
  1. include/net/switchdev.h +0 −11
  2. net/bridge/br_switchdev.c +3 −11
  3. net/core/net-sysfs.c +4 −15
  4. net/core/rtnetlink.c +3 −13
  5. net/ipv4/ipmr.c +5 −14
  6. net/switchdev/switchdev.c +0 −20
include/net/switchdev.h+0−11
@@ -43,7 +43,6 @@ static inline bool switchdev_trans_ph_commit(struct switchdev_trans *trans) · 42 unmodified lines
43 43
44enum switchdev_attr_id {44enum switchdev_attr_id {
45 SWITCHDEV_ATTR_ID_UNDEFINED,45 SWITCHDEV_ATTR_ID_UNDEFINED,
46 SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
47 SWITCHDEV_ATTR_ID_PORT_STP_STATE,46 SWITCHDEV_ATTR_ID_PORT_STP_STATE,
48 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,47 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
49 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS_SUPPORT,48 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS_SUPPORT,
@@ -61,7 +60,6 @@ struct switchdev_attr { · 11 unmodified lines
61 void *complete_priv;60 void *complete_priv;
62 void (*complete)(struct net_device *dev, int err, void *priv);61 void (*complete)(struct net_device *dev, int err, void *priv);
63 union {62 union {
64 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
65 u8 stp_state; /* PORT_STP_STATE */63 u8 stp_state; /* PORT_STP_STATE */
66 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */64 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
67 unsigned long brport_flags_support; /* PORT_BRIDGE_FLAGS_SUPPORT */65 unsigned long brport_flags_support; /* PORT_BRIDGE_FLAGS_SUPPORT */
@@ -208,9 +206,6 @@ void switchdev_port_fwd_mark_set(struct net_device *dev, · 140 unmodified lines
208 struct net_device *group_dev,206 struct net_device *group_dev,
209 bool joining);207 bool joining);
210 208
211bool switchdev_port_same_parent_id(struct net_device *a,
212 struct net_device *b);
213
214int switchdev_handle_port_obj_add(struct net_device *dev,209int switchdev_handle_port_obj_add(struct net_device *dev,
215 struct switchdev_notifier_port_obj_info *port_obj_info,210 struct switchdev_notifier_port_obj_info *port_obj_info,
216 bool (*check_cb)(const struct net_device *dev),211 bool (*check_cb)(const struct net_device *dev),
@@ -295,12 +290,6 @@ call_switchdev_blocking_notifiers(unsigned long val, · 78 unmodified lines
295 return NOTIFY_DONE;290 return NOTIFY_DONE;
296}291}
297 292
298static inline bool switchdev_port_same_parent_id(struct net_device *a,
299 struct net_device *b)
300{
301 return false;
302}
303
304static inline int293static inline int
305switchdev_handle_port_obj_add(struct net_device *dev,294switchdev_handle_port_obj_add(struct net_device *dev,
306 struct switchdev_notifier_port_obj_info *port_obj_info,295 struct switchdev_notifier_port_obj_info *port_obj_info,
net/bridge/br_switchdev.c+3−11
@@ -14,8 +14,7 @@ static int br_switchdev_mark_get(struct net_bridge *br, struct net_device *dev) · 13 unmodified lines
14 14
15 /* dev is yet to be added to the port list. */15 /* dev is yet to be added to the port list. */
16 list_for_each_entry(p, &br->port_list, list) {16 list_for_each_entry(p, &br->port_list, list) {
17 if (netdev_port_same_parent_id(dev, p->dev) ||17 if (netdev_port_same_parent_id(dev, p->dev))
18 switchdev_port_same_parent_id(dev, p->dev))
19 return p->offload_fwd_mark;18 return p->offload_fwd_mark;
20 }19 }
21 20
@@ -24,19 +23,12 @@ static int br_switchdev_mark_get(struct net_bridge *br, struct net_device *dev) · 2 unmodified lines
24 23
25int nbp_switchdev_mark_set(struct net_bridge_port *p)24int nbp_switchdev_mark_set(struct net_bridge_port *p)
26{25{
27 const struct net_device_ops *ops = p->dev->netdev_ops;26 struct netdev_phys_item_id ppid = { };
28 struct switchdev_attr attr = {
29 .orig_dev = p->dev,
30 .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
31 };
32 int err;27 int err;
33 28
34 ASSERT_RTNL();29 ASSERT_RTNL();
35 30
36 if (ops->ndo_get_port_parent_id)31 err = dev_get_port_parent_id(p->dev, &ppid, true);
37 err = dev_get_port_parent_id(p->dev, &attr.u.ppid, true);
38 else
39 err = switchdev_port_attr_get(p->dev, &attr);
40 if (err) {32 if (err) {
41 if (err == -EOPNOTSUPP)33 if (err == -EOPNOTSUPP)
42 return 0;34 return 0;
net/core/net-sysfs.c+4−15
@@ -12,7 +12,6 @@ · 11 unmodified lines
12#include <linux/capability.h>12#include <linux/capability.h>
13#include <linux/kernel.h>13#include <linux/kernel.h>
14#include <linux/netdevice.h>14#include <linux/netdevice.h>
15#include <net/switchdev.h>
16#include <linux/if_arp.h>15#include <linux/if_arp.h>
17#include <linux/slab.h>16#include <linux/slab.h>
18#include <linux/sched/signal.h>17#include <linux/sched/signal.h>
@@ -495,27 +494,17 @@ static ssize_t phys_switch_id_show(struct device *dev, · 476 unmodified lines
495 struct device_attribute *attr, char *buf)494 struct device_attribute *attr, char *buf)
496{495{
497 struct net_device *netdev = to_net_dev(dev);496 struct net_device *netdev = to_net_dev(dev);
498 const struct net_device_ops *ops = netdev->netdev_ops;
499 ssize_t ret = -EINVAL;497 ssize_t ret = -EINVAL;
500 498
501 if (!rtnl_trylock())499 if (!rtnl_trylock())
502 return restart_syscall();500 return restart_syscall();
503 501
504 if (dev_isalive(netdev)) {502 if (dev_isalive(netdev)) {
505 struct switchdev_attr attr = {503 struct netdev_phys_item_id ppid = { };
506 .orig_dev = netdev,504
507 .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,505 ret = dev_get_port_parent_id(netdev, &ppid, false);
508 .flags = SWITCHDEV_F_NO_RECURSE,
509 };
510
511 if (ops->ndo_get_port_parent_id)
512 ret = dev_get_port_parent_id(netdev, &attr.u.ppid,
513 false);
514 else
515 ret = switchdev_port_attr_get(netdev, &attr);
516 if (!ret)506 if (!ret)
517 ret = sprintf(buf, "%*phN\n", attr.u.ppid.id_len,507 ret = sprintf(buf, "%*phN\n", ppid.id_len, ppid.id);
518 attr.u.ppid.id);
519 }508 }
520 rtnl_unlock();509 rtnl_unlock();
521 510
net/core/rtnetlink.c+3−13
@@ -46,7 +46,6 @@ · 45 unmodified lines
46 46
47#include <linux/inet.h>47#include <linux/inet.h>
48#include <linux/netdevice.h>48#include <linux/netdevice.h>
49#include <net/switchdev.h>
50#include <net/ip.h>49#include <net/ip.h>
51#include <net/protocol.h>50#include <net/protocol.h>
52#include <net/arp.h>51#include <net/arp.h>
@@ -1146,26 +1145,17 @@ static int rtnl_phys_port_name_fill(struct sk_buff *skb, struct net_device *dev) · 1093 unmodified lines
1146 1145
1147static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)1146static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
1148{1147{
1149 const struct net_device_ops *ops = dev->netdev_ops;1148 struct netdev_phys_item_id ppid = { };
1150 int err;1149 int err;
1151 struct switchdev_attr attr = {
1152 .orig_dev = dev,
1153 .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
1154 .flags = SWITCHDEV_F_NO_RECURSE,
1155 };
1156 1150
1157 if (ops->ndo_get_port_parent_id)1151 err = dev_get_port_parent_id(dev, &ppid, false);
1158 err = dev_get_port_parent_id(dev, &attr.u.ppid, false);
1159 else
1160 err = switchdev_port_attr_get(dev, &attr);
1161 if (err) {1152 if (err) {
1162 if (err == -EOPNOTSUPP)1153 if (err == -EOPNOTSUPP)
1163 return 0;1154 return 0;
1164 return err;1155 return err;
1165 }1156 }
1166 1157
1167 if (nla_put(skb, IFLA_PHYS_SWITCH_ID, attr.u.ppid.id_len,1158 if (nla_put(skb, IFLA_PHYS_SWITCH_ID, ppid.id_len, ppid.id))
1168 attr.u.ppid.id))
1169 return -EMSGSIZE;1159 return -EMSGSIZE;
1170 1160
1171 return 0;1161 return 0;
net/ipv4/ipmr.c+5−14
@@ -67,7 +67,6 @@ · 66 unmodified lines
67#include <net/fib_rules.h>67#include <net/fib_rules.h>
68#include <linux/netconf.h>68#include <linux/netconf.h>
69#include <net/nexthop.h>69#include <net/nexthop.h>
70#include <net/switchdev.h>
71 70
72#include <linux/nospec.h>71#include <linux/nospec.h>
73 72
@@ -837,11 +836,8 @@ static void ipmr_update_thresholds(struct mr_table *mrt, struct mr_mfc *cache, · 763 unmodified lines
837static int vif_add(struct net *net, struct mr_table *mrt,836static int vif_add(struct net *net, struct mr_table *mrt,
838 struct vifctl *vifc, int mrtsock)837 struct vifctl *vifc, int mrtsock)
839{838{
840 const struct net_device_ops *ops;839 struct netdev_phys_item_id ppid = { };
841 int vifi = vifc->vifc_vifi;840 int vifi = vifc->vifc_vifi;
842 struct switchdev_attr attr = {
843 .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
844 };
845 struct vif_device *v = &mrt->vif_table[vifi];841 struct vif_device *v = &mrt->vif_table[vifi];
846 struct net_device *dev;842 struct net_device *dev;
847 struct in_device *in_dev;843 struct in_device *in_dev;
@@ -920,15 +916,10 @@ static int vif_add(struct net *net, struct mr_table *mrt, · 72 unmodified lines
920 vifc->vifc_flags | (!mrtsock ? VIFF_STATIC : 0),916 vifc->vifc_flags | (!mrtsock ? VIFF_STATIC : 0),
921 (VIFF_TUNNEL | VIFF_REGISTER));917 (VIFF_TUNNEL | VIFF_REGISTER));
922 918
923 attr.orig_dev = dev;919 err = dev_get_port_parent_id(dev, &ppid, true);
924 ops = dev->netdev_ops;920 if (err == 0) {
925 if (ops->ndo_get_port_parent_id &&921 memcpy(v->dev_parent_id.id, ppid.id, ppid.id_len);
926 !dev_get_port_parent_id(dev, &attr.u.ppid, true)) {922 v->dev_parent_id.id_len = ppid.id_len;
927 memcpy(v->dev_parent_id.id, attr.u.ppid.id, attr.u.ppid.id_len);
928 v->dev_parent_id.id_len = attr.u.ppid.id_len;
929 } else if (!switchdev_port_attr_get(dev, &attr)) {
930 memcpy(v->dev_parent_id.id, attr.u.ppid.id, attr.u.ppid.id_len);
931 v->dev_parent_id.id_len = attr.u.ppid.id_len;
932 } else {923 } else {
933 v->dev_parent_id.id_len = 0;924 v->dev_parent_id.id_len = 0;
934 }925 }
net/switchdev/switchdev.c+0−20
@@ -592,26 +592,6 @@ int call_switchdev_blocking_notifiers(unsigned long val, struct net_device *dev, · 591 unmodified lines
592}592}
593EXPORT_SYMBOL_GPL(call_switchdev_blocking_notifiers);593EXPORT_SYMBOL_GPL(call_switchdev_blocking_notifiers);
594 594
595bool switchdev_port_same_parent_id(struct net_device *a,
596 struct net_device *b)
597{
598 struct switchdev_attr a_attr = {
599 .orig_dev = a,
600 .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
601 };
602 struct switchdev_attr b_attr = {
603 .orig_dev = b,
604 .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
605 };
606
607 if (switchdev_port_attr_get(a, &a_attr) ||
608 switchdev_port_attr_get(b, &b_attr))
609 return false;
610
611 return netdev_phys_item_id_same(&a_attr.u.ppid, &b_attr.u.ppid);
612}
613EXPORT_SYMBOL_GPL(switchdev_port_same_parent_id);
614
615static int __switchdev_handle_port_obj_add(struct net_device *dev,595static int __switchdev_handle_port_obj_add(struct net_device *dev,
616 struct switchdev_notifier_port_obj_info *port_obj_info,596 struct switchdev_notifier_port_obj_info *port_obj_info,
617 bool (*check_cb)(const struct net_device *dev),597 bool (*check_cb)(const struct net_device *dev),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t