dsa.h (2a267e7c41aa88215de2b542de797d03d16ecdfd) dsa.h (87671375108625bb7f8a09f0809a369d460ebe43)
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.

--- 16 unchanged lines hidden (view full) ---

25#include <net/devlink.h>
26#include <net/switchdev.h>
27
28struct tc_action;
29struct phy_device;
30struct fixed_phy_status;
31struct phylink_link_state;
32
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.

--- 16 unchanged lines hidden (view full) ---

25#include <net/devlink.h>
26#include <net/switchdev.h>
27
28struct tc_action;
29struct phy_device;
30struct fixed_phy_status;
31struct 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
33enum dsa_tag_protocol {
48enum dsa_tag_protocol {
34 DSA_TAG_PROTO_NONE = 0,
35 DSA_TAG_PROTO_BRCM,
36 DSA_TAG_PROTO_BRCM_PREPEND,
37 DSA_TAG_PROTO_DSA,
38 DSA_TAG_PROTO_EDSA,
39 DSA_TAG_PROTO_GSWIP,
40 DSA_TAG_PROTO_KSZ9477,
41 DSA_TAG_PROTO_KSZ9893,
42 DSA_TAG_PROTO_LAN9303,
43 DSA_TAG_PROTO_MTK,
44 DSA_TAG_PROTO_QCA,
45 DSA_TAG_PROTO_TRAILER,
46 DSA_TAG_LAST, /* MUST BE LAST */
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,
47};
48
49struct packet_type;
50struct dsa_switch;
51
52struct dsa_device_ops {
53 struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
54 struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
55 struct packet_type *pt);
56 int (*flow_dissect)(const struct sk_buff *skb, __be16 *proto,
57 int *offset);
63};
64
65struct packet_type;
66struct dsa_switch;
67
68struct 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);
58 unsigned int overhead;
79 unsigned int overhead;
80 const char *name;
81 enum dsa_tag_protocol proto;
59};
60
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
88struct dsa_skb_cb {
89 struct sk_buff *clone;
90 bool deferred_xmit;
91};
92
93struct __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_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
61struct dsa_switch_tree {
62 struct list_head list;
63
64 /* Notifier chain for switch-wide events */
65 struct raw_notifier_head nh;
66
67 /* Tree identifier */
68 unsigned int index;

--- 54 unchanged lines hidden (view full) ---

123
124 /* CPU port tagging operations used by master or slave devices */
125 const struct dsa_device_ops *tag_ops;
126
127 /* Copies for faster access in master receive hot path */
128 struct dsa_switch_tree *dst;
129 struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
130 struct packet_type *pt);
117struct 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;

--- 54 unchanged lines hidden (view full) ---

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);
131
132 enum {
133 DSA_PORT_TYPE_UNUSED = 0,
134 DSA_PORT_TYPE_CPU,
135 DSA_PORT_TYPE_DSA,
136 DSA_PORT_TYPE_USER,
137 } type;
138
139 struct dsa_switch *ds;
140 unsigned int index;
141 const char *name;
142 const struct dsa_port *cpu_dp;
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;
143 struct device_node *dn;
144 unsigned int ageing_time;
201 struct device_node *dn;
202 unsigned int ageing_time;
203 bool vlan_filtering;
145 u8 stp_state;
146 struct net_device *bridge_dev;
147 struct devlink_port devlink_port;
148 struct phylink *pl;
204 u8 stp_state;
205 struct net_device *bridge_dev;
206 struct devlink_port devlink_port;
207 struct phylink *pl;
208
209 struct work_struct xmit_work;
210 struct sk_buff_head xmit_queue;
211
149 /*
212 /*
213 * Give the switch driver somewhere to hang its per-port private data
214 * structures (accessible from the tagger).
215 */
216 void *priv;
217
218 /*
150 * Original copy of the master netdev ethtool_ops
151 */
152 const struct ethtool_ops *orig_ethtool_ops;
153
154 /*
155 * Original copy of the master netdev net_device_ops
156 */
157 const struct net_device_ops *orig_ndo_ops;

--- 45 unchanged lines hidden (view full) ---

203 unsigned int ageing_time_max;
204
205 /* devlink used to represent this switch device */
206 struct devlink *devlink;
207
208 /* Number of switch port queues */
209 unsigned int num_tx_queues;
210
219 * Original copy of the master netdev ethtool_ops
220 */
221 const struct ethtool_ops *orig_ethtool_ops;
222
223 /*
224 * Original copy of the master netdev net_device_ops
225 */
226 const struct net_device_ops *orig_ndo_ops;

--- 45 unchanged lines hidden (view full) ---

272 unsigned int ageing_time_max;
273
274 /* devlink used to represent this switch device */
275 struct devlink *devlink;
276
277 /* Number of switch port queues */
278 unsigned int num_tx_queues;
279
280 /* Disallow bridge core from requesting different VLAN awareness
281 * settings on ports if not hardware-supported
282 */
283 bool vlan_filtering_is_global;
284
285 /* In case vlan_filtering_is_global is set, the VLAN awareness state
286 * should be retrieved from here and not from the per-port settings.
287 */
288 bool vlan_filtering;
289
211 unsigned long *bitmap;
212 unsigned long _bitmap;
213
214 /* Dynamically allocated ports, keep last */
215 size_t num_ports;
216 struct dsa_port ports[];
217};
218

--- 51 unchanged lines hidden (view full) ---

270 const struct dsa_port *cpu_dp = dp->cpu_dp;
271
272 if (!cpu_dp)
273 return port;
274
275 return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
276}
277
290 unsigned long *bitmap;
291 unsigned long _bitmap;
292
293 /* Dynamically allocated ports, keep last */
294 size_t num_ports;
295 struct dsa_port ports[];
296};
297

--- 51 unchanged lines hidden (view full) ---

349 const struct dsa_port *cpu_dp = dp->cpu_dp;
350
351 if (!cpu_dp)
352 return port;
353
354 return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
355}
356
357static inline bool dsa_port_is_vlan_filtering(const struct dsa_port *dp)
358{
359 const struct dsa_switch *ds = dp->ds;
360
361 if (ds->vlan_filtering_is_global)
362 return ds->vlan_filtering;
363 else
364 return dp->vlan_filtering;
365}
366
278typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
279 bool is_static, void *data);
280struct dsa_switch_ops {
367typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
368 bool is_static, void *data);
369struct dsa_switch_ops {
281#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
282 /*
283 * Legacy probing.
284 */
285 const char *(*probe)(struct device *dsa_dev,
286 struct device *host_dev, int sw_addr,
287 void **priv);
288#endif
289
290 enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
291 int port);
292
293 int (*setup)(struct dsa_switch *ds);
294 u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
295
296 /*
297 * Access to the switch's PHY registers.

--- 166 unchanged lines hidden (view full) ---

464 int (*port_hwtstamp_get)(struct dsa_switch *ds, int port,
465 struct ifreq *ifr);
466 int (*port_hwtstamp_set)(struct dsa_switch *ds, int port,
467 struct ifreq *ifr);
468 bool (*port_txtstamp)(struct dsa_switch *ds, int port,
469 struct sk_buff *clone, unsigned int type);
470 bool (*port_rxtstamp)(struct dsa_switch *ds, int port,
471 struct sk_buff *skb, unsigned int type);
370 enum dsa_tag_protocol (*get_tag_protocol)(struct dsa_switch *ds,
371 int port);
372
373 int (*setup)(struct dsa_switch *ds);
374 u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
375
376 /*
377 * Access to the switch's PHY registers.

--- 166 unchanged lines hidden (view full) ---

544 int (*port_hwtstamp_get)(struct dsa_switch *ds, int port,
545 struct ifreq *ifr);
546 int (*port_hwtstamp_set)(struct dsa_switch *ds, int port,
547 struct ifreq *ifr);
548 bool (*port_txtstamp)(struct dsa_switch *ds, int port,
549 struct sk_buff *clone, unsigned int type);
550 bool (*port_rxtstamp)(struct dsa_switch *ds, int port,
551 struct sk_buff *skb, unsigned int type);
552
553 /*
554 * Deferred frame Tx
555 */
556 netdev_tx_t (*port_deferred_xmit)(struct dsa_switch *ds, int port,
557 struct sk_buff *skb);
472};
473
474struct dsa_switch_driver {
475 struct list_head list;
476 const struct dsa_switch_ops *ops;
477};
478
558};
559
560struct dsa_switch_driver {
561 struct list_head list;
562 const struct dsa_switch_ops *ops;
563};
564
479#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
480/* Legacy driver registration */
481void register_switch_driver(struct dsa_switch_driver *type);
482void unregister_switch_driver(struct dsa_switch_driver *type);
483struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
484
485#else
486static inline void register_switch_driver(struct dsa_switch_driver *type) { }
487static inline void unregister_switch_driver(struct dsa_switch_driver *type) { }
488static inline struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev)
489{
490 return NULL;
491}
492#endif
493struct net_device *dsa_dev_to_net_device(struct device *dev);
494
495/* Keep inline for faster access in hot path */
496static inline bool netdev_uses_dsa(struct net_device *dev)
497{
498#if IS_ENABLED(CONFIG_NET_DSA)
499 return dev->dsa_ptr && dev->dsa_ptr->rcv;
500#endif
501 return false;
502}
503
565struct net_device *dsa_dev_to_net_device(struct device *dev);
566
567/* Keep inline for faster access in hot path */
568static inline bool netdev_uses_dsa(struct net_device *dev)
569{
570#if IS_ENABLED(CONFIG_NET_DSA)
571 return dev->dsa_ptr && dev->dsa_ptr->rcv;
572#endif
573 return false;
574}
575
576static inline bool dsa_can_decode(const struct sk_buff *skb,
577 struct net_device *dev)
578{
579#if IS_ENABLED(CONFIG_NET_DSA)
580 return !dev->dsa_ptr->filter || dev->dsa_ptr->filter(skb, dev);
581#endif
582 return false;
583}
584
504struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
505void dsa_unregister_switch(struct dsa_switch *ds);
506int dsa_register_switch(struct dsa_switch *ds);
507#ifdef CONFIG_PM_SLEEP
508int dsa_switch_suspend(struct dsa_switch *ds);
509int dsa_switch_resume(struct dsa_switch *ds);
510#else
511static inline int dsa_switch_suspend(struct dsa_switch *ds)

--- 52 unchanged lines hidden (view full) ---

564#endif
565
566/* Broadcom tag specific helpers to insert and extract queue/port number */
567#define BRCM_TAG_SET_PORT_QUEUE(p, q) ((p) << 8 | q)
568#define BRCM_TAG_GET_PORT(v) ((v) >> 8)
569#define BRCM_TAG_GET_QUEUE(v) ((v) & 0xff)
570
571
585struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n);
586void dsa_unregister_switch(struct dsa_switch *ds);
587int dsa_register_switch(struct dsa_switch *ds);
588#ifdef CONFIG_PM_SLEEP
589int dsa_switch_suspend(struct dsa_switch *ds);
590int dsa_switch_resume(struct dsa_switch *ds);
591#else
592static inline int dsa_switch_suspend(struct dsa_switch *ds)

--- 52 unchanged lines hidden (view full) ---

645#endif
646
647/* Broadcom tag specific helpers to insert and extract queue/port number */
648#define BRCM_TAG_SET_PORT_QUEUE(p, q) ((p) << 8 | q)
649#define BRCM_TAG_GET_PORT(v) ((v) >> 8)
650#define BRCM_TAG_GET_QUEUE(v) ((v) & 0xff)
651
652
653netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
572int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
573int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data);
574int dsa_port_get_phy_sset_count(struct dsa_port *dp);
575void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
576
654int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
655int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data);
656int dsa_port_get_phy_sset_count(struct dsa_port *dp);
657void dsa_port_phylink_mac_change(struct dsa_switch *ds, int port, bool up);
658
659struct dsa_tag_driver {
660 const struct dsa_device_ops *ops;
661 struct list_head list;
662 struct module *owner;
663};
664
665void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
666 unsigned int count,
667 struct module *owner);
668void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
669 unsigned int count);
670
671#define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \
672static int __init dsa_tag_driver_module_init(void) \
673{ \
674 dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \
675 THIS_MODULE); \
676 return 0; \
677} \
678module_init(dsa_tag_driver_module_init); \
679 \
680static void __exit dsa_tag_driver_module_exit(void) \
681{ \
682 dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \
683} \
684module_exit(dsa_tag_driver_module_exit)
685
686/**
687 * module_dsa_tag_drivers() - Helper macro for registering DSA tag
688 * drivers
689 * @__ops_array: Array of tag driver strucutres
690 *
691 * Helper macro for DSA tag drivers which do not do anything special
692 * in module init/exit. Each module may only use this macro once, and
693 * calling it replaces module_init() and module_exit().
694 */
695#define module_dsa_tag_drivers(__ops_array) \
696dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
697
698#define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops
699
700/* Create a static structure we can build a linked list of dsa_tag
701 * drivers
702 */
703#define DSA_TAG_DRIVER(__ops) \
704static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \
705 .ops = &__ops, \
706}
707
708/**
709 * module_dsa_tag_driver() - Helper macro for registering a single DSA tag
710 * driver
711 * @__ops: Single tag driver structures
712 *
713 * Helper macro for DSA tag drivers which do not do anything special
714 * in module init/exit. Each module may only use this macro once, and
715 * calling it replaces module_init() and module_exit().
716 */
717#define module_dsa_tag_driver(__ops) \
718DSA_TAG_DRIVER(__ops); \
719 \
720static struct dsa_tag_driver *dsa_tag_driver_array[] = { \
721 &DSA_TAG_DRIVER_NAME(__ops) \
722}; \
723module_dsa_tag_drivers(dsa_tag_driver_array)
577#endif
724#endif
725