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