xref: /linux/include/net/dsa.h (revision 73b0140bf0fe9df90fb267c00673c4b9bf285430)
1 /*
2  * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips
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 #ifndef __LINUX_NET_DSA_H
12 #define __LINUX_NET_DSA_H
13 
14 #include <linux/if.h>
15 #include <linux/if_ether.h>
16 #include <linux/list.h>
17 #include <linux/notifier.h>
18 #include <linux/timer.h>
19 #include <linux/workqueue.h>
20 #include <linux/of.h>
21 #include <linux/ethtool.h>
22 #include <linux/net_tstamp.h>
23 #include <linux/phy.h>
24 #include <linux/platform_data/dsa.h>
25 #include <net/devlink.h>
26 #include <net/switchdev.h>
27 
28 struct tc_action;
29 struct phy_device;
30 struct fixed_phy_status;
31 struct phylink_link_state;
32 
33 #define DSA_TAG_PROTO_NONE_VALUE		0
34 #define DSA_TAG_PROTO_BRCM_VALUE		1
35 #define DSA_TAG_PROTO_BRCM_PREPEND_VALUE	2
36 #define DSA_TAG_PROTO_DSA_VALUE			3
37 #define DSA_TAG_PROTO_EDSA_VALUE		4
38 #define DSA_TAG_PROTO_GSWIP_VALUE		5
39 #define DSA_TAG_PROTO_KSZ9477_VALUE		6
40 #define DSA_TAG_PROTO_KSZ9893_VALUE		7
41 #define DSA_TAG_PROTO_LAN9303_VALUE		8
42 #define DSA_TAG_PROTO_MTK_VALUE			9
43 #define DSA_TAG_PROTO_QCA_VALUE			10
44 #define DSA_TAG_PROTO_TRAILER_VALUE		11
45 #define DSA_TAG_PROTO_8021Q_VALUE		12
46 #define DSA_TAG_PROTO_SJA1105_VALUE		13
47 
48 enum dsa_tag_protocol {
49 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
50 	DSA_TAG_PROTO_BRCM		= DSA_TAG_PROTO_BRCM_VALUE,
51 	DSA_TAG_PROTO_BRCM_PREPEND	= DSA_TAG_PROTO_BRCM_PREPEND_VALUE,
52 	DSA_TAG_PROTO_DSA		= DSA_TAG_PROTO_DSA_VALUE,
53 	DSA_TAG_PROTO_EDSA		= DSA_TAG_PROTO_EDSA_VALUE,
54 	DSA_TAG_PROTO_GSWIP		= DSA_TAG_PROTO_GSWIP_VALUE,
55 	DSA_TAG_PROTO_KSZ9477		= DSA_TAG_PROTO_KSZ9477_VALUE,
56 	DSA_TAG_PROTO_KSZ9893		= DSA_TAG_PROTO_KSZ9893_VALUE,
57 	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
58 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
59 	DSA_TAG_PROTO_QCA		= DSA_TAG_PROTO_QCA_VALUE,
60 	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
61 	DSA_TAG_PROTO_8021Q		= DSA_TAG_PROTO_8021Q_VALUE,
62 	DSA_TAG_PROTO_SJA1105		= DSA_TAG_PROTO_SJA1105_VALUE,
63 };
64 
65 struct packet_type;
66 struct dsa_switch;
67 
68 struct dsa_device_ops {
69 	struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
70 	struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
71 			       struct packet_type *pt);
72 	int (*flow_dissect)(const struct sk_buff *skb, __be16 *proto,
73 			    int *offset);
74 	/* Used to determine which traffic should match the DSA filter in
75 	 * eth_type_trans, and which, if any, should bypass it and be processed
76 	 * as regular on the master net device.
77 	 */
78 	bool (*filter)(const struct sk_buff *skb, struct net_device *dev);
79 	unsigned int overhead;
80 	const char *name;
81 	enum dsa_tag_protocol proto;
82 };
83 
84 #define DSA_TAG_DRIVER_ALIAS "dsa_tag-"
85 #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto)				\
86 	MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE))
87 
88 struct dsa_skb_cb {
89 	struct sk_buff *clone;
90 	bool deferred_xmit;
91 };
92 
93 struct __dsa_skb_cb {
94 	struct dsa_skb_cb cb;
95 	u8 priv[48 - sizeof(struct dsa_skb_cb)];
96 };
97 
98 #define __DSA_SKB_CB(skb) ((struct __dsa_skb_cb *)((skb)->cb))
99 
100 #define DSA_SKB_CB(skb) ((struct dsa_skb_cb *)((skb)->cb))
101 
102 #define DSA_SKB_CB_COPY(nskb, skb)		\
103 	{ *__DSA_SKB_CB(nskb) = *__DSA_SKB_CB(skb); }
104 
105 #define DSA_SKB_CB_ZERO(skb)			\
106 	{ *__DSA_SKB_CB(skb) = (struct __dsa_skb_cb) {0}; }
107 
108 #define DSA_SKB_CB_PRIV(skb)			\
109 	((void *)(skb)->cb + offsetof(struct __dsa_skb_cb, priv))
110 
111 #define DSA_SKB_CB_CLONE(_clone, _skb)		\
112 	{					\
113 		struct sk_buff *clone = _clone;	\
114 		struct sk_buff *skb = _skb;	\
115 						\
116 		DSA_SKB_CB_COPY(clone, skb);	\
117 		DSA_SKB_CB(skb)->clone = clone; \
118 	}
119 
120 struct dsa_switch_tree {
121 	struct list_head	list;
122 
123 	/* Notifier chain for switch-wide events */
124 	struct raw_notifier_head	nh;
125 
126 	/* Tree identifier */
127 	unsigned int index;
128 
129 	/* Number of switches attached to this tree */
130 	struct kref refcount;
131 
132 	/* Has this tree been applied to the hardware? */
133 	bool setup;
134 
135 	/*
136 	 * Configuration data for the platform device that owns
137 	 * this dsa switch tree instance.
138 	 */
139 	struct dsa_platform_data	*pd;
140 
141 	/*
142 	 * The switch port to which the CPU is attached.
143 	 */
144 	struct dsa_port		*cpu_dp;
145 
146 	/*
147 	 * Data for the individual switch chips.
148 	 */
149 	struct dsa_switch	*ds[DSA_MAX_SWITCHES];
150 };
151 
152 /* TC matchall action types, only mirroring for now */
153 enum dsa_port_mall_action_type {
154 	DSA_PORT_MALL_MIRROR,
155 };
156 
157 /* TC mirroring entry */
158 struct dsa_mall_mirror_tc_entry {
159 	u8 to_local_port;
160 	bool ingress;
161 };
162 
163 /* TC matchall entry */
164 struct dsa_mall_tc_entry {
165 	struct list_head list;
166 	unsigned long cookie;
167 	enum dsa_port_mall_action_type type;
168 	union {
169 		struct dsa_mall_mirror_tc_entry mirror;
170 	};
171 };
172 
173 
174 struct dsa_port {
175 	/* A CPU port is physically connected to a master device.
176 	 * A user port exposed to userspace has a slave device.
177 	 */
178 	union {
179 		struct net_device *master;
180 		struct net_device *slave;
181 	};
182 
183 	/* CPU port tagging operations used by master or slave devices */
184 	const struct dsa_device_ops *tag_ops;
185 
186 	/* Copies for faster access in master receive hot path */
187 	struct dsa_switch_tree *dst;
188 	struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
189 			       struct packet_type *pt);
190 	bool (*filter)(const struct sk_buff *skb, struct net_device *dev);
191 
192 	enum {
193 		DSA_PORT_TYPE_UNUSED = 0,
194 		DSA_PORT_TYPE_CPU,
195 		DSA_PORT_TYPE_DSA,
196 		DSA_PORT_TYPE_USER,
197 	} type;
198 
199 	struct dsa_switch	*ds;
200 	unsigned int		index;
201 	const char		*name;
202 	const struct dsa_port	*cpu_dp;
203 	const char		*mac;
204 	struct device_node	*dn;
205 	unsigned int		ageing_time;
206 	bool			vlan_filtering;
207 	u8			stp_state;
208 	struct net_device	*bridge_dev;
209 	struct devlink_port	devlink_port;
210 	struct phylink		*pl;
211 
212 	struct work_struct	xmit_work;
213 	struct sk_buff_head	xmit_queue;
214 
215 	/*
216 	 * Give the switch driver somewhere to hang its per-port private data
217 	 * structures (accessible from the tagger).
218 	 */
219 	void *priv;
220 
221 	/*
222 	 * Original copy of the master netdev ethtool_ops
223 	 */
224 	const struct ethtool_ops *orig_ethtool_ops;
225 
226 	/*
227 	 * Original copy of the master netdev net_device_ops
228 	 */
229 	const struct net_device_ops *orig_ndo_ops;
230 };
231 
232 struct dsa_switch {
233 	struct device *dev;
234 
235 	/*
236 	 * Parent switch tree, and switch index.
237 	 */
238 	struct dsa_switch_tree	*dst;
239 	unsigned int		index;
240 
241 	/* Listener for switch fabric events */
242 	struct notifier_block	nb;
243 
244 	/*
245 	 * Give the switch driver somewhere to hang its private data
246 	 * structure.
247 	 */
248 	void *priv;
249 
250 	/*
251 	 * Configuration data for this switch.
252 	 */
253 	struct dsa_chip_data	*cd;
254 
255 	/*
256 	 * The switch operations.
257 	 */
258 	const struct dsa_switch_ops	*ops;
259 
260 	/*
261 	 * An array of which element [a] indicates which port on this
262 	 * switch should be used to send packets to that are destined
263 	 * for switch a. Can be NULL if there is only one switch chip.
264 	 */
265 	s8		rtable[DSA_MAX_SWITCHES];
266 
267 	/*
268 	 * Slave mii_bus and devices for the individual ports.
269 	 */
270 	u32			phys_mii_mask;
271 	struct mii_bus		*slave_mii_bus;
272 
273 	/* Ageing Time limits in msecs */
274 	unsigned int ageing_time_min;
275 	unsigned int ageing_time_max;
276 
277 	/* devlink used to represent this switch device */
278 	struct devlink		*devlink;
279 
280 	/* Number of switch port queues */
281 	unsigned int		num_tx_queues;
282 
283 	/* Disallow bridge core from requesting different VLAN awareness
284 	 * settings on ports if not hardware-supported
285 	 */
286 	bool			vlan_filtering_is_global;
287 
288 	/* In case vlan_filtering_is_global is set, the VLAN awareness state
289 	 * should be retrieved from here and not from the per-port settings.
290 	 */
291 	bool			vlan_filtering;
292 
293 	unsigned long		*bitmap;
294 	unsigned long		_bitmap;
295 
296 	/* Dynamically allocated ports, keep last */
297 	size_t num_ports;
298 	struct dsa_port ports[];
299 };
300 
301 static inline const struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
302 {
303 	return &ds->ports[p];
304 }
305 
306 static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
307 {
308 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED;
309 }
310 
311 static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
312 {
313 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU;
314 }
315 
316 static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
317 {
318 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA;
319 }
320 
321 static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
322 {
323 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
324 }
325 
326 static inline u32 dsa_user_ports(struct dsa_switch *ds)
327 {
328 	u32 mask = 0;
329 	int p;
330 
331 	for (p = 0; p < ds->num_ports; p++)
332 		if (dsa_is_user_port(ds, p))
333 			mask |= BIT(p);
334 
335 	return mask;
336 }
337 
338 /* Return the local port used to reach an arbitrary switch port */
339 static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device,
340 					    int port)
341 {
342 	if (device == ds->index)
343 		return port;
344 	else
345 		return ds->rtable[device];
346 }
347 
348 /* Return the local port used to reach the dedicated CPU port */
349 static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
350 {
351 	const struct dsa_port *dp = dsa_to_port(ds, port);
352 	const struct dsa_port *cpu_dp = dp->cpu_dp;
353 
354 	if (!cpu_dp)
355 		return port;
356 
357 	return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
358 }
359 
360 static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
361 {
362 	const struct dsa_switch *ds = dp->ds;
363 
364 	if (ds->vlan_filtering_is_global)
365 		return ds->vlan_filtering;
366 	else
367 		return dp->vlan_filtering;
368 }
369 
370 typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
371 			      bool is_static, void *data);
372 struct dsa_switch_ops {
373 	enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
374 						  int port);
375 
376 	int	(*setup)(struct dsa_switch *ds);
377 	u32	(*get_phy_flags)(struct dsa_switch *ds, int port);
378 
379 	/*
380 	 * Access to the switch's PHY registers.
381 	 */
382 	int	(*phy_read)(struct dsa_switch *ds, int port, int regnum);
383 	int	(*phy_write)(struct dsa_switch *ds, int port,
384 			     int regnum, u16 val);
385 
386 	/*
387 	 * Link state adjustment (called from libphy)
388 	 */
389 	void	(*adjust_link)(struct dsa_switch *ds, int port,
390 				struct phy_device *phydev);
391 	void	(*fixed_link_update)(struct dsa_switch *ds, int port,
392 				struct fixed_phy_status *st);
393 
394 	/*
395 	 * PHYLINK integration
396 	 */
397 	void	(*phylink_validate)(struct dsa_switch *ds, int port,
398 				    unsigned long *supported,
399 				    struct phylink_link_state *state);
400 	int	(*phylink_mac_link_state)(struct dsa_switch *ds, int port,
401 					  struct phylink_link_state *state);
402 	void	(*phylink_mac_config)(struct dsa_switch *ds, int port,
403 				      unsigned int mode,
404 				      const struct phylink_link_state *state);
405 	void	(*phylink_mac_an_restart)(struct dsa_switch *ds, int port);
406 	void	(*phylink_mac_link_down)(struct dsa_switch *ds, int port,
407 					 unsigned int mode,
408 					 phy_interface_t interface);
409 	void	(*phylink_mac_link_up)(struct dsa_switch *ds, int port,
410 				       unsigned int mode,
411 				       phy_interface_t interface,
412 				       struct phy_device *phydev);
413 	void	(*phylink_fixed_state)(struct dsa_switch *ds, int port,
414 				       struct phylink_link_state *state);
415 	/*
416 	 * ethtool hardware statistics.
417 	 */
418 	void	(*get_strings)(struct dsa_switch *ds, int port,
419 			       u32 stringset, uint8_t *data);
420 	void	(*get_ethtool_stats)(struct dsa_switch *ds,
421 				     int port, uint64_t *data);
422 	int	(*get_sset_count)(struct dsa_switch *ds, int port, int sset);
423 	void	(*get_ethtool_phy_stats)(struct dsa_switch *ds,
424 					 int port, uint64_t *data);
425 
426 	/*
427 	 * ethtool Wake-on-LAN
428 	 */
429 	void	(*get_wol)(struct dsa_switch *ds, int port,
430 			   struct ethtool_wolinfo *w);
431 	int	(*set_wol)(struct dsa_switch *ds, int port,
432 			   struct ethtool_wolinfo *w);
433 
434 	/*
435 	 * ethtool timestamp info
436 	 */
437 	int	(*get_ts_info)(struct dsa_switch *ds, int port,
438 			       struct ethtool_ts_info *ts);
439 
440 	/*
441 	 * Suspend and resume
442 	 */
443 	int	(*suspend)(struct dsa_switch *ds);
444 	int	(*resume)(struct dsa_switch *ds);
445 
446 	/*
447 	 * Port enable/disable
448 	 */
449 	int	(*port_enable)(struct dsa_switch *ds, int port,
450 			       struct phy_device *phy);
451 	void	(*port_disable)(struct dsa_switch *ds, int port);
452 
453 	/*
454 	 * Port's MAC EEE settings
455 	 */
456 	int	(*set_mac_eee)(struct dsa_switch *ds, int port,
457 			       struct ethtool_eee *e);
458 	int	(*get_mac_eee)(struct dsa_switch *ds, int port,
459 			       struct ethtool_eee *e);
460 
461 	/* EEPROM access */
462 	int	(*get_eeprom_len)(struct dsa_switch *ds);
463 	int	(*get_eeprom)(struct dsa_switch *ds,
464 			      struct ethtool_eeprom *eeprom, u8 *data);
465 	int	(*set_eeprom)(struct dsa_switch *ds,
466 			      struct ethtool_eeprom *eeprom, u8 *data);
467 
468 	/*
469 	 * Register access.
470 	 */
471 	int	(*get_regs_len)(struct dsa_switch *ds, int port);
472 	void	(*get_regs)(struct dsa_switch *ds, int port,
473 			    struct ethtool_regs *regs, void *p);
474 
475 	/*
476 	 * Bridge integration
477 	 */
478 	int	(*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
479 	int	(*port_bridge_join)(struct dsa_switch *ds, int port,
480 				    struct net_device *bridge);
481 	void	(*port_bridge_leave)(struct dsa_switch *ds, int port,
482 				     struct net_device *bridge);
483 	void	(*port_stp_state_set)(struct dsa_switch *ds, int port,
484 				      u8 state);
485 	void	(*port_fast_age)(struct dsa_switch *ds, int port);
486 	int	(*port_egress_floods)(struct dsa_switch *ds, int port,
487 				      bool unicast, bool multicast);
488 
489 	/*
490 	 * VLAN support
491 	 */
492 	int	(*port_vlan_filtering)(struct dsa_switch *ds, int port,
493 				       bool vlan_filtering);
494 	int (*port_vlan_prepare)(struct dsa_switch *ds, int port,
495 				 const struct switchdev_obj_port_vlan *vlan);
496 	void (*port_vlan_add)(struct dsa_switch *ds, int port,
497 			      const struct switchdev_obj_port_vlan *vlan);
498 	int	(*port_vlan_del)(struct dsa_switch *ds, int port,
499 				 const struct switchdev_obj_port_vlan *vlan);
500 	/*
501 	 * Forwarding database
502 	 */
503 	int	(*port_fdb_add)(struct dsa_switch *ds, int port,
504 				const unsigned char *addr, u16 vid);
505 	int	(*port_fdb_del)(struct dsa_switch *ds, int port,
506 				const unsigned char *addr, u16 vid);
507 	int	(*port_fdb_dump)(struct dsa_switch *ds, int port,
508 				 dsa_fdb_dump_cb_t *cb, void *data);
509 
510 	/*
511 	 * Multicast database
512 	 */
513 	int (*port_mdb_prepare)(struct dsa_switch *ds, int port,
514 				const struct switchdev_obj_port_mdb *mdb);
515 	void (*port_mdb_add)(struct dsa_switch *ds, int port,
516 			     const struct switchdev_obj_port_mdb *mdb);
517 	int	(*port_mdb_del)(struct dsa_switch *ds, int port,
518 				const struct switchdev_obj_port_mdb *mdb);
519 	/*
520 	 * RXNFC
521 	 */
522 	int	(*get_rxnfc)(struct dsa_switch *ds, int port,
523 			     struct ethtool_rxnfc *nfc, u32 *rule_locs);
524 	int	(*set_rxnfc)(struct dsa_switch *ds, int port,
525 			     struct ethtool_rxnfc *nfc);
526 
527 	/*
528 	 * TC integration
529 	 */
530 	int	(*port_mirror_add)(struct dsa_switch *ds, int port,
531 				   struct dsa_mall_mirror_tc_entry *mirror,
532 				   bool ingress);
533 	void	(*port_mirror_del)(struct dsa_switch *ds, int port,
534 				   struct dsa_mall_mirror_tc_entry *mirror);
535 
536 	/*
537 	 * Cross-chip operations
538 	 */
539 	int	(*crosschip_bridge_join)(struct dsa_switch *ds, int sw_index,
540 					 int port, struct net_device *br);
541 	void	(*crosschip_bridge_leave)(struct dsa_switch *ds, int sw_index,
542 					  int port, struct net_device *br);
543 
544 	/*
545 	 * PTP functionality
546 	 */
547 	int	(*port_hwtstamp_get)(struct dsa_switch *ds, int port,
548 				     struct ifreq *ifr);
549 	int	(*port_hwtstamp_set)(struct dsa_switch *ds, int port,
550 				     struct ifreq *ifr);
551 	bool	(*port_txtstamp)(struct dsa_switch *ds, int port,
552 				 struct sk_buff *clone, unsigned int type);
553 	bool	(*port_rxtstamp)(struct dsa_switch *ds, int port,
554 				 struct sk_buff *skb, unsigned int type);
555 
556 	/*
557 	 * Deferred frame Tx
558 	 */
559 	netdev_tx_t (*port_deferred_xmit)(struct dsa_switch *ds, int port,
560 					  struct sk_buff *skb);
561 };
562 
563 struct dsa_switch_driver {
564 	struct list_head	list;
565 	const struct dsa_switch_ops *ops;
566 };
567 
568 struct net_device *dsa_dev_to_net_device(struct device *dev);
569 
570 /* Keep inline for faster access in hot path */
571 static inline bool netdev_uses_dsa(struct net_device *dev)
572 {
573 #if IS_ENABLED(CONFIG_NET_DSA)
574 	return dev->dsa_ptr && dev->dsa_ptr->rcv;
575 #endif
576 	return false;
577 }
578 
579 static inline bool dsa_can_decode(const struct sk_buff *skb,
580 				  struct net_device *dev)
581 {
582 #if IS_ENABLED(CONFIG_NET_DSA)
583 	return !dev->dsa_ptr->filter || dev->dsa_ptr->filter(skb, dev);
584 #endif
585 	return false;
586 }
587 
588 struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
589 void dsa_unregister_switch(struct dsa_switch *ds);
590 int dsa_register_switch(struct dsa_switch *ds);
591 #ifdef CONFIG_PM_SLEEP
592 int dsa_switch_suspend(struct dsa_switch *ds);
593 int dsa_switch_resume(struct dsa_switch *ds);
594 #else
595 static inline int dsa_switch_suspend(struct dsa_switch *ds)
596 {
597 	return 0;
598 }
599 static inline int dsa_switch_resume(struct dsa_switch *ds)
600 {
601 	return 0;
602 }
603 #endif /* CONFIG_PM_SLEEP */
604 
605 enum dsa_notifier_type {
606 	DSA_PORT_REGISTER,
607 	DSA_PORT_UNREGISTER,
608 };
609 
610 struct dsa_notifier_info {
611 	struct net_device *dev;
612 };
613 
614 struct dsa_notifier_register_info {
615 	struct dsa_notifier_info info;	/* must be first */
616 	struct net_device *master;
617 	unsigned int port_number;
618 	unsigned int switch_number;
619 };
620 
621 static inline struct net_device *
622 dsa_notifier_info_to_dev(const struct dsa_notifier_info *info)
623 {
624 	return info->dev;
625 }
626 
627 #if IS_ENABLED(CONFIG_NET_DSA)
628 int register_dsa_notifier(struct notifier_block *nb);
629 int unregister_dsa_notifier(struct notifier_block *nb);
630 int call_dsa_notifiers(unsigned long val, struct net_device *dev,
631 		       struct dsa_notifier_info *info);
632 #else
633 static inline int register_dsa_notifier(struct notifier_block *nb)
634 {
635 	return 0;
636 }
637 
638 static inline int unregister_dsa_notifier(struct notifier_block *nb)
639 {
640 	return 0;
641 }
642 
643 static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,
644 				     struct dsa_notifier_info *info)
645 {
646 	return NOTIFY_DONE;
647 }
648 #endif
649 
650 /* Broadcom tag specific helpers to insert and extract queue/port number */
651 #define BRCM_TAG_SET_PORT_QUEUE(p, q)	((p) << 8 | q)
652 #define BRCM_TAG_GET_PORT(v)		((v) >> 8)
653 #define BRCM_TAG_GET_QUEUE(v)		((v) & 0xff)
654 
655 
656 netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
657 int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
658 int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data);
659 int dsa_port_get_phy_sset_count(struct dsa_port *dp);
660 void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
661 
662 struct dsa_tag_driver {
663 	const struct dsa_device_ops *ops;
664 	struct list_head list;
665 	struct module *owner;
666 };
667 
668 void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
669 			      unsigned int count,
670 			      struct module *owner);
671 void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
672 				unsigned int count);
673 
674 #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count)	\
675 static int __init dsa_tag_driver_module_init(void)			\
676 {									\
677 	dsa_tag_drivers_register(__dsa_tag_drivers_array, __count,	\
678 				 THIS_MODULE);				\
679 	return 0;							\
680 }									\
681 module_init(dsa_tag_driver_module_init);				\
682 									\
683 static void __exit dsa_tag_driver_module_exit(void)			\
684 {									\
685 	dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count);	\
686 }									\
687 module_exit(dsa_tag_driver_module_exit)
688 
689 /**
690  * module_dsa_tag_drivers() - Helper macro for registering DSA tag
691  * drivers
692  * @__ops_array: Array of tag driver strucutres
693  *
694  * Helper macro for DSA tag drivers which do not do anything special
695  * in module init/exit. Each module may only use this macro once, and
696  * calling it replaces module_init() and module_exit().
697  */
698 #define module_dsa_tag_drivers(__ops_array)				\
699 dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
700 
701 #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops
702 
703 /* Create a static structure we can build a linked list of dsa_tag
704  * drivers
705  */
706 #define DSA_TAG_DRIVER(__ops)						\
707 static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = {		\
708 	.ops = &__ops,							\
709 }
710 
711 /**
712  * module_dsa_tag_driver() - Helper macro for registering a single DSA tag
713  * driver
714  * @__ops: Single tag driver structures
715  *
716  * Helper macro for DSA tag drivers which do not do anything special
717  * in module init/exit. Each module may only use this macro once, and
718  * calling it replaces module_init() and module_exit().
719  */
720 #define module_dsa_tag_driver(__ops)					\
721 DSA_TAG_DRIVER(__ops);							\
722 									\
723 static struct dsa_tag_driver *dsa_tag_driver_array[] =	{		\
724 	&DSA_TAG_DRIVER_NAME(__ops)					\
725 };									\
726 module_dsa_tag_drivers(dsa_tag_driver_array)
727 #endif
728 
729