blob: 6eff4335895d995ea58abd3c4934a29c1269dc18 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips
4 * Copyright (c) 2008-2009 Marvell Semiconductor
5 */
6
7#ifndef __LINUX_NET_DSA_H
8#define __LINUX_NET_DSA_H
9
10#include <linux/if.h>
11#include <linux/if_ether.h>
12#include <linux/list.h>
13#include <linux/notifier.h>
14#include <linux/timer.h>
15#include <linux/workqueue.h>
16#include <linux/of.h>
17#include <linux/ethtool.h>
18#include <linux/net_tstamp.h>
19#include <linux/phy.h>
20#include <linux/platform_data/dsa.h>
21#include <linux/phylink.h>
22#include <net/devlink.h>
23#include <net/switchdev.h>
24
25struct tc_action;
26struct phy_device;
27struct fixed_phy_status;
28struct phylink_link_state;
29
30#define DSA_TAG_PROTO_NONE_VALUE 0
31#define DSA_TAG_PROTO_BRCM_VALUE 1
32#define DSA_TAG_PROTO_BRCM_PREPEND_VALUE 2
33#define DSA_TAG_PROTO_DSA_VALUE 3
34#define DSA_TAG_PROTO_EDSA_VALUE 4
35#define DSA_TAG_PROTO_GSWIP_VALUE 5
36#define DSA_TAG_PROTO_KSZ9477_VALUE 6
37#define DSA_TAG_PROTO_KSZ9893_VALUE 7
38#define DSA_TAG_PROTO_LAN9303_VALUE 8
39#define DSA_TAG_PROTO_MTK_VALUE 9
40#define DSA_TAG_PROTO_QCA_VALUE 10
41#define DSA_TAG_PROTO_TRAILER_VALUE 11
42#define DSA_TAG_PROTO_8021Q_VALUE 12
43#define DSA_TAG_PROTO_SJA1105_VALUE 13
44#define DSA_TAG_PROTO_KSZ8795_VALUE 14
45#define DSA_TAG_PROTO_RTL4_A_VALUE 17
46
47enum dsa_tag_protocol {
48 DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE,
49 DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE,
50 DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE,
51 DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE,
52 DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE,
53 DSA_TAG_PROTO_GSWIP = DSA_TAG_PROTO_GSWIP_VALUE,
54 DSA_TAG_PROTO_KSZ9477 = DSA_TAG_PROTO_KSZ9477_VALUE,
55 DSA_TAG_PROTO_KSZ9893 = DSA_TAG_PROTO_KSZ9893_VALUE,
56 DSA_TAG_PROTO_LAN9303 = DSA_TAG_PROTO_LAN9303_VALUE,
57 DSA_TAG_PROTO_MTK = DSA_TAG_PROTO_MTK_VALUE,
58 DSA_TAG_PROTO_QCA = DSA_TAG_PROTO_QCA_VALUE,
59 DSA_TAG_PROTO_TRAILER = DSA_TAG_PROTO_TRAILER_VALUE,
60 DSA_TAG_PROTO_8021Q = DSA_TAG_PROTO_8021Q_VALUE,
61 DSA_TAG_PROTO_SJA1105 = DSA_TAG_PROTO_SJA1105_VALUE,
62 DSA_TAG_PROTO_KSZ8795 = DSA_TAG_PROTO_KSZ8795_VALUE,
63 DSA_TAG_PROTO_RTL4_A = DSA_TAG_PROTO_RTL4_A_VALUE,
64};
65
66struct packet_type;
67struct dsa_switch;
68
69struct 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
89struct dsa_skb_cb {
90 struct sk_buff *clone;
91 bool deferred_xmit;
92};
93
94struct __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
106struct 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 */
139enum dsa_port_mall_action_type {
140 DSA_PORT_MALL_MIRROR,
141};
142
143/* TC mirroring entry */
144struct dsa_mall_mirror_tc_entry {
145 u8 to_local_port;
146 bool ingress;
147};
148
149/* TC matchall entry */
150struct 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
160struct 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 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
219struct 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 /* Pass .port_vlan_add and .port_vlan_del to drivers even for bridges
276 * that have vlan_filtering=0. All drivers should ideally set this (and
277 * then the option would get removed), but it is unknown whether this
278 * would break things or not.
279 */
280 bool configure_vlan_while_not_filtering;
281
282 /* Let DSA manage the FDB entries towards the CPU, based on the
283 * software bridge database.
284 */
285 bool assisted_learning_on_cpu_port;
286
287 /* In case vlan_filtering_is_global is set, the VLAN awareness state
288 * should be retrieved from here and not from the per-port settings.
289 */
290 bool vlan_filtering;
291
292 /* Dynamically allocated ports, keep last */
293 size_t num_ports;
294 struct dsa_port ports[];
295};
296
297static inline const struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
298{
299 return &ds->ports[p];
300}
301
302static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
303{
304 return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED;
305}
306
307static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
308{
309 return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_CPU;
310}
311
312static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
313{
314 return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_DSA;
315}
316
317static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
318{
319 return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
320}
321
322static inline u32 dsa_user_ports(struct dsa_switch *ds)
323{
324 u32 mask = 0;
325 int p;
326
327 for (p = 0; p < ds->num_ports; p++)
328 if (dsa_is_user_port(ds, p))
329 mask |= BIT(p);
330
331 return mask;
332}
333
334/* Return the local port used to reach an arbitrary switch port */
335static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device,
336 int port)
337{
338 if (device == ds->index)
339 return port;
340 else
341 return ds->rtable[device];
342}
343
344/* Return the local port used to reach the dedicated CPU port */
345static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
346{
347 const struct dsa_port *dp = dsa_to_port(ds, port);
348 const struct dsa_port *cpu_dp = dp->cpu_dp;
349
350 if (!cpu_dp)
351 return port;
352
353 return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
354}
355
356static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
357{
358 const struct dsa_switch *ds = dp->ds;
359
360 if (ds->vlan_filtering_is_global)
361 return ds->vlan_filtering;
362 else
363 return dp->vlan_filtering;
364}
365
366typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
367 bool is_static, void *data);
368struct dsa_switch_ops {
369 enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
370 int port,
371 enum dsa_tag_protocol mprot);
372
373 int (*setup)(struct dsa_switch *ds);
374 void (*teardown)(struct dsa_switch *ds);
375 u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
376
377 /*
378 * Access to the switch's PHY registers.
379 */
380 int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
381 int (*phy_write)(struct dsa_switch *ds, int port,
382 int regnum, u16 val);
383
384 /*
385 * Link state adjustment (called from libphy)
386 */
387 void (*adjust_link)(struct dsa_switch *ds, int port,
388 struct phy_device *phydev);
389 void (*fixed_link_update)(struct dsa_switch *ds, int port,
390 struct fixed_phy_status *st);
391
392 /*
393 * PHYLINK integration
394 */
395 void (*phylink_validate)(struct dsa_switch *ds, int port,
396 unsigned long *supported,
397 struct phylink_link_state *state);
398 int (*phylink_mac_link_state)(struct dsa_switch *ds, int port,
399 struct phylink_link_state *state);
400 void (*phylink_mac_config)(struct dsa_switch *ds, int port,
401 unsigned int mode,
402 const struct phylink_link_state *state);
403 void (*phylink_mac_an_restart)(struct dsa_switch *ds, int port);
404 void (*phylink_mac_link_down)(struct dsa_switch *ds, int port,
405 unsigned int mode,
406 phy_interface_t interface);
407 void (*phylink_mac_link_up)(struct dsa_switch *ds, int port,
408 unsigned int mode,
409 phy_interface_t interface,
410 struct phy_device *phydev);
411 void (*phylink_fixed_state)(struct dsa_switch *ds, int port,
412 struct phylink_link_state *state);
413 /*
414 * ethtool hardware statistics.
415 */
416 void (*get_strings)(struct dsa_switch *ds, int port,
417 u32 stringset, uint8_t *data);
418 void (*get_ethtool_stats)(struct dsa_switch *ds,
419 int port, uint64_t *data);
420 int (*get_sset_count)(struct dsa_switch *ds, int port, int sset);
421 void (*get_ethtool_phy_stats)(struct dsa_switch *ds,
422 int port, uint64_t *data);
423
424 /*
425 * ethtool Wake-on-LAN
426 */
427 void (*get_wol)(struct dsa_switch *ds, int port,
428 struct ethtool_wolinfo *w);
429 int (*set_wol)(struct dsa_switch *ds, int port,
430 struct ethtool_wolinfo *w);
431
432 /*
433 * ethtool timestamp info
434 */
435 int (*get_ts_info)(struct dsa_switch *ds, int port,
436 struct ethtool_ts_info *ts);
437
438 /*
439 * Suspend and resume
440 */
441 int (*suspend)(struct dsa_switch *ds);
442 int (*resume)(struct dsa_switch *ds);
443
444 /*
445 * Port enable/disable
446 */
447 int (*port_enable)(struct dsa_switch *ds, int port,
448 struct phy_device *phy);
449 void (*port_disable)(struct dsa_switch *ds, int port);
450
451 /*
452 * Port's MAC EEE settings
453 */
454 int (*set_mac_eee)(struct dsa_switch *ds, int port,
455 struct ethtool_eee *e);
456 int (*get_mac_eee)(struct dsa_switch *ds, int port,
457 struct ethtool_eee *e);
458
459 /* EEPROM access */
460 int (*get_eeprom_len)(struct dsa_switch *ds);
461 int (*get_eeprom)(struct dsa_switch *ds,
462 struct ethtool_eeprom *eeprom, u8 *data);
463 int (*set_eeprom)(struct dsa_switch *ds,
464 struct ethtool_eeprom *eeprom, u8 *data);
465
466 /*
467 * Register access.
468 */
469 int (*get_regs_len)(struct dsa_switch *ds, int port);
470 void (*get_regs)(struct dsa_switch *ds, int port,
471 struct ethtool_regs *regs, void *p);
472
473 /*
474 * Bridge integration
475 */
476 int (*set_ageing_time)(struct dsa_switch *ds, unsigned int msecs);
477 int (*port_bridge_join)(struct dsa_switch *ds, int port,
478 struct net_device *bridge);
479 void (*port_bridge_leave)(struct dsa_switch *ds, int port,
480 struct net_device *bridge);
481 void (*port_stp_state_set)(struct dsa_switch *ds, int port,
482 u8 state);
483 void (*port_fast_age)(struct dsa_switch *ds, int port);
484 int (*port_egress_floods)(struct dsa_switch *ds, int port,
485 bool unicast, bool multicast);
486
487 /*
488 * VLAN support
489 */
490 int (*port_vlan_filtering)(struct dsa_switch *ds, int port,
491 bool vlan_filtering);
492 int (*port_vlan_prepare)(struct dsa_switch *ds, int port,
493 const struct switchdev_obj_port_vlan *vlan);
494 void (*port_vlan_add)(struct dsa_switch *ds, int port,
495 const struct switchdev_obj_port_vlan *vlan);
496 int (*port_vlan_del)(struct dsa_switch *ds, int port,
497 const struct switchdev_obj_port_vlan *vlan);
498 /*
499 * Forwarding database
500 */
501 int (*port_fdb_add)(struct dsa_switch *ds, int port,
502 const unsigned char *addr, u16 vid);
503 int (*port_fdb_del)(struct dsa_switch *ds, int port,
504 const unsigned char *addr, u16 vid);
505 int (*port_fdb_dump)(struct dsa_switch *ds, int port,
506 dsa_fdb_dump_cb_t *cb, void *data);
507
508 /*
509 * Multicast database
510 */
511 int (*port_mdb_prepare)(struct dsa_switch *ds, int port,
512 const struct switchdev_obj_port_mdb *mdb);
513 void (*port_mdb_add)(struct dsa_switch *ds, int port,
514 const struct switchdev_obj_port_mdb *mdb);
515 int (*port_mdb_del)(struct dsa_switch *ds, int port,
516 const struct switchdev_obj_port_mdb *mdb);
517 /*
518 * RXNFC
519 */
520 int (*get_rxnfc)(struct dsa_switch *ds, int port,
521 struct ethtool_rxnfc *nfc, u32 *rule_locs);
522 int (*set_rxnfc)(struct dsa_switch *ds, int port,
523 struct ethtool_rxnfc *nfc);
524
525 /*
526 * TC integration
527 */
528 int (*port_mirror_add)(struct dsa_switch *ds, int port,
529 struct dsa_mall_mirror_tc_entry *mirror,
530 bool ingress);
531 void (*port_mirror_del)(struct dsa_switch *ds, int port,
532 struct dsa_mall_mirror_tc_entry *mirror);
533 int (*port_setup_tc)(struct dsa_switch *ds, int port,
534 enum tc_setup_type type, void *type_data);
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
563struct dsa_switch_driver {
564 struct list_head list;
565 const struct dsa_switch_ops *ops;
566};
567
568struct net_device *dsa_dev_to_net_device(struct device *dev);
569
570/* Keep inline for faster access in hot path */
571static 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
579static 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
588struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
589void dsa_unregister_switch(struct dsa_switch *ds);
590int dsa_register_switch(struct dsa_switch *ds);
591#ifdef CONFIG_PM_SLEEP
592int dsa_switch_suspend(struct dsa_switch *ds);
593int dsa_switch_resume(struct dsa_switch *ds);
594#else
595static inline int dsa_switch_suspend(struct dsa_switch *ds)
596{
597 return 0;
598}
599static inline int dsa_switch_resume(struct dsa_switch *ds)
600{
601 return 0;
602}
603#endif /* CONFIG_PM_SLEEP */
604
605enum dsa_notifier_type {
606 DSA_PORT_REGISTER,
607 DSA_PORT_UNREGISTER,
608};
609
610struct dsa_notifier_info {
611 struct net_device *dev;
612};
613
614struct 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
621static inline struct net_device *
622dsa_notifier_info_to_dev(const struct dsa_notifier_info *info)
623{
624 return info->dev;
625}
626
627#if IS_ENABLED(CONFIG_NET_DSA)
628int register_dsa_notifier(struct notifier_block *nb);
629int unregister_dsa_notifier(struct notifier_block *nb);
630int call_dsa_notifiers(unsigned long val, struct net_device *dev,
631 struct dsa_notifier_info *info);
632#else
633static inline int register_dsa_notifier(struct notifier_block *nb)
634{
635 return 0;
636}
637
638static inline int unregister_dsa_notifier(struct notifier_block *nb)
639{
640 return 0;
641}
642
643static 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
656netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
657int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
658int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data);
659int dsa_port_get_phy_sset_count(struct dsa_port *dp);
660void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
661
662struct dsa_tag_driver {
663 const struct dsa_device_ops *ops;
664 struct list_head list;
665 struct module *owner;
666};
667
668void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
669 unsigned int count,
670 struct module *owner);
671void 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) \
675static 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} \
681module_init(dsa_tag_driver_module_init); \
682 \
683static void __exit dsa_tag_driver_module_exit(void) \
684{ \
685 dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \
686} \
687module_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) \
699dsa_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) \
707static 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) \
721DSA_TAG_DRIVER(__ops); \
722 \
723static struct dsa_tag_driver *dsa_tag_driver_array[] = { \
724 &DSA_TAG_DRIVER_NAME(__ops) \
725}; \
726module_dsa_tag_drivers(dsa_tag_driver_array)
727#endif
728