net: dsa: Keep private info in the skb->cb
[sfrench/cifs-2.6.git] / include / net / dsa.h
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
47 enum 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 };
62
63 struct packet_type;
64 struct dsa_switch;
65
66 struct dsa_device_ops {
67         struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
68         struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
69                                struct packet_type *pt);
70         int (*flow_dissect)(const struct sk_buff *skb, __be16 *proto,
71                             int *offset);
72         /* Used to determine which traffic should match the DSA filter in
73          * eth_type_trans, and which, if any, should bypass it and be processed
74          * as regular on the master net device.
75          */
76         bool (*filter)(const struct sk_buff *skb, struct net_device *dev);
77         unsigned int overhead;
78         const char *name;
79         enum dsa_tag_protocol proto;
80 };
81
82 #define DSA_TAG_DRIVER_ALIAS "dsa_tag-"
83 #define MODULE_ALIAS_DSA_TAG_DRIVER(__proto)                            \
84         MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE))
85
86 struct dsa_skb_cb {
87         struct sk_buff *clone;
88 };
89
90 struct __dsa_skb_cb {
91         struct dsa_skb_cb cb;
92         u8 priv[48 - sizeof(struct dsa_skb_cb)];
93 };
94
95 #define __DSA_SKB_CB(skb) ((struct __dsa_skb_cb *)((skb)->cb))
96
97 #define DSA_SKB_CB(skb) ((struct dsa_skb_cb *)((skb)->cb))
98
99 #define DSA_SKB_CB_COPY(nskb, skb)              \
100         { *__DSA_SKB_CB(nskb) = *__DSA_SKB_CB(skb); }
101
102 #define DSA_SKB_CB_ZERO(skb)                    \
103         { *__DSA_SKB_CB(skb) = (struct __dsa_skb_cb) {0}; }
104
105 #define DSA_SKB_CB_PRIV(skb)                    \
106         ((void *)(skb)->cb + offsetof(struct __dsa_skb_cb, priv))
107
108 #define DSA_SKB_CB_CLONE(_clone, _skb)          \
109         {                                       \
110                 struct sk_buff *clone = _clone; \
111                 struct sk_buff *skb = _skb;     \
112                                                 \
113                 DSA_SKB_CB_COPY(clone, skb);    \
114                 DSA_SKB_CB(skb)->clone = clone; \
115         }
116
117 struct dsa_switch_tree {
118         struct list_head        list;
119
120         /* Notifier chain for switch-wide events */
121         struct raw_notifier_head        nh;
122
123         /* Tree identifier */
124         unsigned int index;
125
126         /* Number of switches attached to this tree */
127         struct kref refcount;
128
129         /* Has this tree been applied to the hardware? */
130         bool setup;
131
132         /*
133          * Configuration data for the platform device that owns
134          * this dsa switch tree instance.
135          */
136         struct dsa_platform_data        *pd;
137
138         /*
139          * The switch port to which the CPU is attached.
140          */
141         struct dsa_port         *cpu_dp;
142
143         /*
144          * Data for the individual switch chips.
145          */
146         struct dsa_switch       *ds[DSA_MAX_SWITCHES];
147 };
148
149 /* TC matchall action types, only mirroring for now */
150 enum dsa_port_mall_action_type {
151         DSA_PORT_MALL_MIRROR,
152 };
153
154 /* TC mirroring entry */
155 struct dsa_mall_mirror_tc_entry {
156         u8 to_local_port;
157         bool ingress;
158 };
159
160 /* TC matchall entry */
161 struct dsa_mall_tc_entry {
162         struct list_head list;
163         unsigned long cookie;
164         enum dsa_port_mall_action_type type;
165         union {
166                 struct dsa_mall_mirror_tc_entry mirror;
167         };
168 };
169
170
171 struct dsa_port {
172         /* A CPU port is physically connected to a master device.
173          * A user port exposed to userspace has a slave device.
174          */
175         union {
176                 struct net_device *master;
177                 struct net_device *slave;
178         };
179
180         /* CPU port tagging operations used by master or slave devices */
181         const struct dsa_device_ops *tag_ops;
182
183         /* Copies for faster access in master receive hot path */
184         struct dsa_switch_tree *dst;
185         struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
186                                struct packet_type *pt);
187         bool (*filter)(const struct sk_buff *skb, struct net_device *dev);
188
189         enum {
190                 DSA_PORT_TYPE_UNUSED = 0,
191                 DSA_PORT_TYPE_CPU,
192                 DSA_PORT_TYPE_DSA,
193                 DSA_PORT_TYPE_USER,
194         } type;
195
196         struct dsa_switch       *ds;
197         unsigned int            index;
198         const char              *name;
199         const struct dsa_port   *cpu_dp;
200         const char              *mac;
201         struct device_node      *dn;
202         unsigned int            ageing_time;
203         bool                    vlan_filtering;
204         u8                      stp_state;
205         struct net_device       *bridge_dev;
206         struct devlink_port     devlink_port;
207         struct phylink          *pl;
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 struct dsa_switch_driver {
545         struct list_head        list;
546         const struct dsa_switch_ops *ops;
547 };
548
549 struct net_device *dsa_dev_to_net_device(struct device *dev);
550
551 /* Keep inline for faster access in hot path */
552 static inline bool netdev_uses_dsa(struct net_device *dev)
553 {
554 #if IS_ENABLED(CONFIG_NET_DSA)
555         return dev->dsa_ptr && dev->dsa_ptr->rcv;
556 #endif
557         return false;
558 }
559
560 static inline bool dsa_can_decode(const struct sk_buff *skb,
561                                   struct net_device *dev)
562 {
563 #if IS_ENABLED(CONFIG_NET_DSA)
564         return !dev->dsa_ptr->filter || dev->dsa_ptr->filter(skb, dev);
565 #endif
566         return false;
567 }
568
569 struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
570 void dsa_unregister_switch(struct dsa_switch *ds);
571 int dsa_register_switch(struct dsa_switch *ds);
572 #ifdef CONFIG_PM_SLEEP
573 int dsa_switch_suspend(struct dsa_switch *ds);
574 int dsa_switch_resume(struct dsa_switch *ds);
575 #else
576 static inline int dsa_switch_suspend(struct dsa_switch *ds)
577 {
578         return 0;
579 }
580 static inline int dsa_switch_resume(struct dsa_switch *ds)
581 {
582         return 0;
583 }
584 #endif /* CONFIG_PM_SLEEP */
585
586 enum dsa_notifier_type {
587         DSA_PORT_REGISTER,
588         DSA_PORT_UNREGISTER,
589 };
590
591 struct dsa_notifier_info {
592         struct net_device *dev;
593 };
594
595 struct dsa_notifier_register_info {
596         struct dsa_notifier_info info;  /* must be first */
597         struct net_device *master;
598         unsigned int port_number;
599         unsigned int switch_number;
600 };
601
602 static inline struct net_device *
603 dsa_notifier_info_to_dev(const struct dsa_notifier_info *info)
604 {
605         return info->dev;
606 }
607
608 #if IS_ENABLED(CONFIG_NET_DSA)
609 int register_dsa_notifier(struct notifier_block *nb);
610 int unregister_dsa_notifier(struct notifier_block *nb);
611 int call_dsa_notifiers(unsigned long val, struct net_device *dev,
612                        struct dsa_notifier_info *info);
613 #else
614 static inline int register_dsa_notifier(struct notifier_block *nb)
615 {
616         return 0;
617 }
618
619 static inline int unregister_dsa_notifier(struct notifier_block *nb)
620 {
621         return 0;
622 }
623
624 static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,
625                                      struct dsa_notifier_info *info)
626 {
627         return NOTIFY_DONE;
628 }
629 #endif
630
631 /* Broadcom tag specific helpers to insert and extract queue/port number */
632 #define BRCM_TAG_SET_PORT_QUEUE(p, q)   ((p) << 8 | q)
633 #define BRCM_TAG_GET_PORT(v)            ((v) >> 8)
634 #define BRCM_TAG_GET_QUEUE(v)           ((v) & 0xff)
635
636
637 int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
638 int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data);
639 int dsa_port_get_phy_sset_count(struct dsa_port *dp);
640 void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
641
642 struct dsa_tag_driver {
643         const struct dsa_device_ops *ops;
644         struct list_head list;
645         struct module *owner;
646 };
647
648 void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
649                               unsigned int count,
650                               struct module *owner);
651 void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
652                                 unsigned int count);
653
654 #define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \
655 static int __init dsa_tag_driver_module_init(void)                      \
656 {                                                                       \
657         dsa_tag_drivers_register(__dsa_tag_drivers_array, __count,      \
658                                  THIS_MODULE);                          \
659         return 0;                                                       \
660 }                                                                       \
661 module_init(dsa_tag_driver_module_init);                                \
662                                                                         \
663 static void __exit dsa_tag_driver_module_exit(void)                     \
664 {                                                                       \
665         dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count);   \
666 }                                                                       \
667 module_exit(dsa_tag_driver_module_exit)
668
669 /**
670  * module_dsa_tag_drivers() - Helper macro for registering DSA tag
671  * drivers
672  * @__ops_array: Array of tag driver strucutres
673  *
674  * Helper macro for DSA tag drivers which do not do anything special
675  * in module init/exit. Each module may only use this macro once, and
676  * calling it replaces module_init() and module_exit().
677  */
678 #define module_dsa_tag_drivers(__ops_array)                             \
679 dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
680
681 #define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops
682
683 /* Create a static structure we can build a linked list of dsa_tag
684  * drivers
685  */
686 #define DSA_TAG_DRIVER(__ops)                                           \
687 static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = {             \
688         .ops = &__ops,                                                  \
689 }
690
691 /**
692  * module_dsa_tag_driver() - Helper macro for registering a single DSA tag
693  * driver
694  * @__ops: Single tag driver structures
695  *
696  * Helper macro for DSA tag drivers which do not do anything special
697  * in module init/exit. Each module may only use this macro once, and
698  * calling it replaces module_init() and module_exit().
699  */
700 #define module_dsa_tag_driver(__ops)                                    \
701 DSA_TAG_DRIVER(__ops);                                                  \
702                                                                         \
703 static struct dsa_tag_driver *dsa_tag_driver_array[] =  {               \
704         &DSA_TAG_DRIVER_NAME(__ops)                                     \
705 };                                                                      \
706 module_dsa_tag_drivers(dsa_tag_driver_array)
707 #endif
708