hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/include/net/switchdev.h
....@@ -1,12 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * include/net/switchdev.h - Switch device API
34 * Copyright (c) 2014-2015 Jiri Pirko <jiri@resnulli.us>
45 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
106 */
117 #ifndef _LINUX_SWITCHDEV_H_
128 #define _LINUX_SWITCHDEV_H_
....@@ -20,14 +16,7 @@
2016 #define SWITCHDEV_F_SKIP_EOPNOTSUPP BIT(1)
2117 #define SWITCHDEV_F_DEFER BIT(2)
2218
23
-struct switchdev_trans_item {
24
- struct list_head list;
25
- void *data;
26
- void (*destructor)(const void *data);
27
-};
28
-
2919 struct switchdev_trans {
30
- struct list_head item_list;
3120 bool ph_prepare;
3221 };
3322
....@@ -43,15 +32,18 @@
4332
4433 enum switchdev_attr_id {
4534 SWITCHDEV_ATTR_ID_UNDEFINED,
46
- SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
4735 SWITCHDEV_ATTR_ID_PORT_STP_STATE,
4836 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
49
- SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS_SUPPORT,
37
+ SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS,
5038 SWITCHDEV_ATTR_ID_PORT_MROUTER,
5139 SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
5240 SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
41
+ SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL,
5342 SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED,
5443 SWITCHDEV_ATTR_ID_BRIDGE_MROUTER,
44
+#if IS_ENABLED(CONFIG_BRIDGE_MRP)
45
+ SWITCHDEV_ATTR_ID_MRP_PORT_ROLE,
46
+#endif
5547 };
5648
5749 struct switchdev_attr {
....@@ -61,14 +53,16 @@
6153 void *complete_priv;
6254 void (*complete)(struct net_device *dev, int err, void *priv);
6355 union {
64
- struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
6556 u8 stp_state; /* PORT_STP_STATE */
66
- unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
67
- unsigned long brport_flags_support; /* PORT_BRIDGE_FLAGS_SUPPORT */
57
+ unsigned long brport_flags; /* PORT_{PRE}_BRIDGE_FLAGS */
6858 bool mrouter; /* PORT_MROUTER */
6959 clock_t ageing_time; /* BRIDGE_AGEING_TIME */
7060 bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */
61
+ u16 vlan_protocol; /* BRIDGE_VLAN_PROTOCOL */
7162 bool mc_disabled; /* MC_DISABLED */
63
+#if IS_ENABLED(CONFIG_BRIDGE_MRP)
64
+ u8 mrp_port_role; /* MRP_PORT_ROLE */
65
+#endif
7266 } u;
7367 };
7468
....@@ -77,6 +71,16 @@
7771 SWITCHDEV_OBJ_ID_PORT_VLAN,
7872 SWITCHDEV_OBJ_ID_PORT_MDB,
7973 SWITCHDEV_OBJ_ID_HOST_MDB,
74
+#if IS_ENABLED(CONFIG_BRIDGE_MRP)
75
+ SWITCHDEV_OBJ_ID_MRP,
76
+ SWITCHDEV_OBJ_ID_RING_TEST_MRP,
77
+ SWITCHDEV_OBJ_ID_RING_ROLE_MRP,
78
+ SWITCHDEV_OBJ_ID_RING_STATE_MRP,
79
+ SWITCHDEV_OBJ_ID_IN_TEST_MRP,
80
+ SWITCHDEV_OBJ_ID_IN_ROLE_MRP,
81
+ SWITCHDEV_OBJ_ID_IN_STATE_MRP,
82
+
83
+#endif
8084 };
8185
8286 struct switchdev_obj {
....@@ -95,8 +99,8 @@
9599 u16 vid_end;
96100 };
97101
98
-#define SWITCHDEV_OBJ_PORT_VLAN(obj) \
99
- container_of(obj, struct switchdev_obj_port_vlan, obj)
102
+#define SWITCHDEV_OBJ_PORT_VLAN(OBJ) \
103
+ container_of((OBJ), struct switchdev_obj_port_vlan, obj)
100104
101105 /* SWITCHDEV_OBJ_ID_PORT_MDB */
102106 struct switchdev_obj_port_mdb {
....@@ -105,39 +109,93 @@
105109 u16 vid;
106110 };
107111
108
-#define SWITCHDEV_OBJ_PORT_MDB(obj) \
109
- container_of(obj, struct switchdev_obj_port_mdb, obj)
112
+#define SWITCHDEV_OBJ_PORT_MDB(OBJ) \
113
+ container_of((OBJ), struct switchdev_obj_port_mdb, obj)
110114
111
-void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
112
- void *data, void (*destructor)(void const *),
113
- struct switchdev_trans_item *tritem);
114
-void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
115
+
116
+#if IS_ENABLED(CONFIG_BRIDGE_MRP)
117
+/* SWITCHDEV_OBJ_ID_MRP */
118
+struct switchdev_obj_mrp {
119
+ struct switchdev_obj obj;
120
+ struct net_device *p_port;
121
+ struct net_device *s_port;
122
+ u32 ring_id;
123
+ u16 prio;
124
+};
125
+
126
+#define SWITCHDEV_OBJ_MRP(OBJ) \
127
+ container_of((OBJ), struct switchdev_obj_mrp, obj)
128
+
129
+/* SWITCHDEV_OBJ_ID_RING_TEST_MRP */
130
+struct switchdev_obj_ring_test_mrp {
131
+ struct switchdev_obj obj;
132
+ /* The value is in us and a value of 0 represents to stop */
133
+ u32 interval;
134
+ u8 max_miss;
135
+ u32 ring_id;
136
+ u32 period;
137
+ bool monitor;
138
+};
139
+
140
+#define SWITCHDEV_OBJ_RING_TEST_MRP(OBJ) \
141
+ container_of((OBJ), struct switchdev_obj_ring_test_mrp, obj)
142
+
143
+/* SWICHDEV_OBJ_ID_RING_ROLE_MRP */
144
+struct switchdev_obj_ring_role_mrp {
145
+ struct switchdev_obj obj;
146
+ u8 ring_role;
147
+ u32 ring_id;
148
+};
149
+
150
+#define SWITCHDEV_OBJ_RING_ROLE_MRP(OBJ) \
151
+ container_of((OBJ), struct switchdev_obj_ring_role_mrp, obj)
152
+
153
+struct switchdev_obj_ring_state_mrp {
154
+ struct switchdev_obj obj;
155
+ u8 ring_state;
156
+ u32 ring_id;
157
+};
158
+
159
+#define SWITCHDEV_OBJ_RING_STATE_MRP(OBJ) \
160
+ container_of((OBJ), struct switchdev_obj_ring_state_mrp, obj)
161
+
162
+/* SWITCHDEV_OBJ_ID_IN_TEST_MRP */
163
+struct switchdev_obj_in_test_mrp {
164
+ struct switchdev_obj obj;
165
+ /* The value is in us and a value of 0 represents to stop */
166
+ u32 interval;
167
+ u32 in_id;
168
+ u32 period;
169
+ u8 max_miss;
170
+};
171
+
172
+#define SWITCHDEV_OBJ_IN_TEST_MRP(OBJ) \
173
+ container_of((OBJ), struct switchdev_obj_in_test_mrp, obj)
174
+
175
+/* SWICHDEV_OBJ_ID_IN_ROLE_MRP */
176
+struct switchdev_obj_in_role_mrp {
177
+ struct switchdev_obj obj;
178
+ struct net_device *i_port;
179
+ u32 ring_id;
180
+ u16 in_id;
181
+ u8 in_role;
182
+};
183
+
184
+#define SWITCHDEV_OBJ_IN_ROLE_MRP(OBJ) \
185
+ container_of((OBJ), struct switchdev_obj_in_role_mrp, obj)
186
+
187
+struct switchdev_obj_in_state_mrp {
188
+ struct switchdev_obj obj;
189
+ u32 in_id;
190
+ u8 in_state;
191
+};
192
+
193
+#define SWITCHDEV_OBJ_IN_STATE_MRP(OBJ) \
194
+ container_of((OBJ), struct switchdev_obj_in_state_mrp, obj)
195
+
196
+#endif
115197
116198 typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj);
117
-
118
-/**
119
- * struct switchdev_ops - switchdev operations
120
- *
121
- * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
122
- *
123
- * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
124
- *
125
- * @switchdev_port_obj_add: Add an object to port (see switchdev_obj_*).
126
- *
127
- * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj_*).
128
- */
129
-struct switchdev_ops {
130
- int (*switchdev_port_attr_get)(struct net_device *dev,
131
- struct switchdev_attr *attr);
132
- int (*switchdev_port_attr_set)(struct net_device *dev,
133
- const struct switchdev_attr *attr,
134
- struct switchdev_trans *trans);
135
- int (*switchdev_port_obj_add)(struct net_device *dev,
136
- const struct switchdev_obj *obj,
137
- struct switchdev_trans *trans);
138
- int (*switchdev_port_obj_del)(struct net_device *dev,
139
- const struct switchdev_obj *obj);
140
-};
141199
142200 enum switchdev_notifier_type {
143201 SWITCHDEV_FDB_ADD_TO_BRIDGE = 1,
....@@ -145,17 +203,44 @@
145203 SWITCHDEV_FDB_ADD_TO_DEVICE,
146204 SWITCHDEV_FDB_DEL_TO_DEVICE,
147205 SWITCHDEV_FDB_OFFLOADED,
206
+ SWITCHDEV_FDB_FLUSH_TO_BRIDGE,
207
+
208
+ SWITCHDEV_PORT_OBJ_ADD, /* Blocking. */
209
+ SWITCHDEV_PORT_OBJ_DEL, /* Blocking. */
210
+ SWITCHDEV_PORT_ATTR_SET, /* May be blocking . */
211
+
212
+ SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE,
213
+ SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE,
214
+ SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE,
215
+ SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE,
216
+ SWITCHDEV_VXLAN_FDB_OFFLOADED,
148217 };
149218
150219 struct switchdev_notifier_info {
151220 struct net_device *dev;
221
+ struct netlink_ext_ack *extack;
152222 };
153223
154224 struct switchdev_notifier_fdb_info {
155225 struct switchdev_notifier_info info; /* must be first */
156226 const unsigned char *addr;
157227 u16 vid;
158
- bool added_by_user;
228
+ u8 added_by_user:1,
229
+ offloaded:1;
230
+};
231
+
232
+struct switchdev_notifier_port_obj_info {
233
+ struct switchdev_notifier_info info; /* must be first */
234
+ const struct switchdev_obj *obj;
235
+ struct switchdev_trans *trans;
236
+ bool handled;
237
+};
238
+
239
+struct switchdev_notifier_port_attr_info {
240
+ struct switchdev_notifier_info info; /* must be first */
241
+ const struct switchdev_attr *attr;
242
+ struct switchdev_trans *trans;
243
+ bool handled;
159244 };
160245
161246 static inline struct net_device *
....@@ -164,39 +249,62 @@
164249 return info->dev;
165250 }
166251
252
+static inline struct netlink_ext_ack *
253
+switchdev_notifier_info_to_extack(const struct switchdev_notifier_info *info)
254
+{
255
+ return info->extack;
256
+}
257
+
167258 #ifdef CONFIG_NET_SWITCHDEV
168259
169260 void switchdev_deferred_process(void);
170
-int switchdev_port_attr_get(struct net_device *dev,
171
- struct switchdev_attr *attr);
172261 int switchdev_port_attr_set(struct net_device *dev,
173262 const struct switchdev_attr *attr);
174263 int switchdev_port_obj_add(struct net_device *dev,
175
- const struct switchdev_obj *obj);
264
+ const struct switchdev_obj *obj,
265
+ struct netlink_ext_ack *extack);
176266 int switchdev_port_obj_del(struct net_device *dev,
177267 const struct switchdev_obj *obj);
268
+
178269 int register_switchdev_notifier(struct notifier_block *nb);
179270 int unregister_switchdev_notifier(struct notifier_block *nb);
180271 int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
181
- struct switchdev_notifier_info *info);
272
+ struct switchdev_notifier_info *info,
273
+ struct netlink_ext_ack *extack);
274
+
275
+int register_switchdev_blocking_notifier(struct notifier_block *nb);
276
+int unregister_switchdev_blocking_notifier(struct notifier_block *nb);
277
+int call_switchdev_blocking_notifiers(unsigned long val, struct net_device *dev,
278
+ struct switchdev_notifier_info *info,
279
+ struct netlink_ext_ack *extack);
280
+
182281 void switchdev_port_fwd_mark_set(struct net_device *dev,
183282 struct net_device *group_dev,
184283 bool joining);
185284
186
-bool switchdev_port_same_parent_id(struct net_device *a,
187
- struct net_device *b);
285
+int switchdev_handle_port_obj_add(struct net_device *dev,
286
+ struct switchdev_notifier_port_obj_info *port_obj_info,
287
+ bool (*check_cb)(const struct net_device *dev),
288
+ int (*add_cb)(struct net_device *dev,
289
+ const struct switchdev_obj *obj,
290
+ struct switchdev_trans *trans,
291
+ struct netlink_ext_ack *extack));
292
+int switchdev_handle_port_obj_del(struct net_device *dev,
293
+ struct switchdev_notifier_port_obj_info *port_obj_info,
294
+ bool (*check_cb)(const struct net_device *dev),
295
+ int (*del_cb)(struct net_device *dev,
296
+ const struct switchdev_obj *obj));
188297
189
-#define SWITCHDEV_SET_OPS(netdev, ops) ((netdev)->switchdev_ops = (ops))
298
+int switchdev_handle_port_attr_set(struct net_device *dev,
299
+ struct switchdev_notifier_port_attr_info *port_attr_info,
300
+ bool (*check_cb)(const struct net_device *dev),
301
+ int (*set_cb)(struct net_device *dev,
302
+ const struct switchdev_attr *attr,
303
+ struct switchdev_trans *trans));
190304 #else
191305
192306 static inline void switchdev_deferred_process(void)
193307 {
194
-}
195
-
196
-static inline int switchdev_port_attr_get(struct net_device *dev,
197
- struct switchdev_attr *attr)
198
-{
199
- return -EOPNOTSUPP;
200308 }
201309
202310 static inline int switchdev_port_attr_set(struct net_device *dev,
....@@ -206,7 +314,8 @@
206314 }
207315
208316 static inline int switchdev_port_obj_add(struct net_device *dev,
209
- const struct switchdev_obj *obj)
317
+ const struct switchdev_obj *obj,
318
+ struct netlink_ext_ack *extack)
210319 {
211320 return -EOPNOTSUPP;
212321 }
....@@ -229,19 +338,65 @@
229338
230339 static inline int call_switchdev_notifiers(unsigned long val,
231340 struct net_device *dev,
232
- struct switchdev_notifier_info *info)
341
+ struct switchdev_notifier_info *info,
342
+ struct netlink_ext_ack *extack)
233343 {
234344 return NOTIFY_DONE;
235345 }
236346
237
-static inline bool switchdev_port_same_parent_id(struct net_device *a,
238
- struct net_device *b)
347
+static inline int
348
+register_switchdev_blocking_notifier(struct notifier_block *nb)
239349 {
240
- return false;
350
+ return 0;
241351 }
242352
243
-#define SWITCHDEV_SET_OPS(netdev, ops) do {} while (0)
353
+static inline int
354
+unregister_switchdev_blocking_notifier(struct notifier_block *nb)
355
+{
356
+ return 0;
357
+}
244358
359
+static inline int
360
+call_switchdev_blocking_notifiers(unsigned long val,
361
+ struct net_device *dev,
362
+ struct switchdev_notifier_info *info,
363
+ struct netlink_ext_ack *extack)
364
+{
365
+ return NOTIFY_DONE;
366
+}
367
+
368
+static inline int
369
+switchdev_handle_port_obj_add(struct net_device *dev,
370
+ struct switchdev_notifier_port_obj_info *port_obj_info,
371
+ bool (*check_cb)(const struct net_device *dev),
372
+ int (*add_cb)(struct net_device *dev,
373
+ const struct switchdev_obj *obj,
374
+ struct switchdev_trans *trans,
375
+ struct netlink_ext_ack *extack))
376
+{
377
+ return 0;
378
+}
379
+
380
+static inline int
381
+switchdev_handle_port_obj_del(struct net_device *dev,
382
+ struct switchdev_notifier_port_obj_info *port_obj_info,
383
+ bool (*check_cb)(const struct net_device *dev),
384
+ int (*del_cb)(struct net_device *dev,
385
+ const struct switchdev_obj *obj))
386
+{
387
+ return 0;
388
+}
389
+
390
+static inline int
391
+switchdev_handle_port_attr_set(struct net_device *dev,
392
+ struct switchdev_notifier_port_attr_info *port_attr_info,
393
+ bool (*check_cb)(const struct net_device *dev),
394
+ int (*set_cb)(struct net_device *dev,
395
+ const struct switchdev_attr *attr,
396
+ struct switchdev_trans *trans))
397
+{
398
+ return 0;
399
+}
245400 #endif
246401
247402 #endif /* _LINUX_SWITCHDEV_H_ */