dsa_priv.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * net/dsa/dsa_priv.h - Hardware switch handling
  4. * Copyright (c) 2008-2009 Marvell Semiconductor
  5. */
  6. #ifndef __DSA_PRIV_H
  7. #define __DSA_PRIV_H
  8. #include <linux/if_bridge.h>
  9. #include <linux/if_vlan.h>
  10. #include <linux/phy.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/netpoll.h>
  13. #include <net/dsa.h>
  14. #include <net/gro_cells.h>
  15. #define DSA_MAX_NUM_OFFLOADING_BRIDGES BITS_PER_LONG
  16. enum {
  17. DSA_NOTIFIER_AGEING_TIME,
  18. DSA_NOTIFIER_BRIDGE_JOIN,
  19. DSA_NOTIFIER_BRIDGE_LEAVE,
  20. DSA_NOTIFIER_FDB_ADD,
  21. DSA_NOTIFIER_FDB_DEL,
  22. DSA_NOTIFIER_HOST_FDB_ADD,
  23. DSA_NOTIFIER_HOST_FDB_DEL,
  24. DSA_NOTIFIER_LAG_FDB_ADD,
  25. DSA_NOTIFIER_LAG_FDB_DEL,
  26. DSA_NOTIFIER_LAG_CHANGE,
  27. DSA_NOTIFIER_LAG_JOIN,
  28. DSA_NOTIFIER_LAG_LEAVE,
  29. DSA_NOTIFIER_MDB_ADD,
  30. DSA_NOTIFIER_MDB_DEL,
  31. DSA_NOTIFIER_HOST_MDB_ADD,
  32. DSA_NOTIFIER_HOST_MDB_DEL,
  33. DSA_NOTIFIER_VLAN_ADD,
  34. DSA_NOTIFIER_VLAN_DEL,
  35. DSA_NOTIFIER_HOST_VLAN_ADD,
  36. DSA_NOTIFIER_HOST_VLAN_DEL,
  37. DSA_NOTIFIER_MTU,
  38. DSA_NOTIFIER_TAG_PROTO,
  39. DSA_NOTIFIER_TAG_PROTO_CONNECT,
  40. DSA_NOTIFIER_TAG_PROTO_DISCONNECT,
  41. DSA_NOTIFIER_TAG_8021Q_VLAN_ADD,
  42. DSA_NOTIFIER_TAG_8021Q_VLAN_DEL,
  43. DSA_NOTIFIER_MASTER_STATE_CHANGE,
  44. };
  45. /* DSA_NOTIFIER_AGEING_TIME */
  46. struct dsa_notifier_ageing_time_info {
  47. unsigned int ageing_time;
  48. };
  49. /* DSA_NOTIFIER_BRIDGE_* */
  50. struct dsa_notifier_bridge_info {
  51. const struct dsa_port *dp;
  52. struct dsa_bridge bridge;
  53. bool tx_fwd_offload;
  54. struct netlink_ext_ack *extack;
  55. };
  56. /* DSA_NOTIFIER_FDB_* */
  57. struct dsa_notifier_fdb_info {
  58. const struct dsa_port *dp;
  59. const unsigned char *addr;
  60. u16 vid;
  61. struct dsa_db db;
  62. };
  63. /* DSA_NOTIFIER_LAG_FDB_* */
  64. struct dsa_notifier_lag_fdb_info {
  65. struct dsa_lag *lag;
  66. const unsigned char *addr;
  67. u16 vid;
  68. struct dsa_db db;
  69. };
  70. /* DSA_NOTIFIER_MDB_* */
  71. struct dsa_notifier_mdb_info {
  72. const struct dsa_port *dp;
  73. const struct switchdev_obj_port_mdb *mdb;
  74. struct dsa_db db;
  75. };
  76. /* DSA_NOTIFIER_LAG_* */
  77. struct dsa_notifier_lag_info {
  78. const struct dsa_port *dp;
  79. struct dsa_lag lag;
  80. struct netdev_lag_upper_info *info;
  81. struct netlink_ext_ack *extack;
  82. };
  83. /* DSA_NOTIFIER_VLAN_* */
  84. struct dsa_notifier_vlan_info {
  85. const struct dsa_port *dp;
  86. const struct switchdev_obj_port_vlan *vlan;
  87. struct netlink_ext_ack *extack;
  88. };
  89. /* DSA_NOTIFIER_MTU */
  90. struct dsa_notifier_mtu_info {
  91. const struct dsa_port *dp;
  92. int mtu;
  93. };
  94. /* DSA_NOTIFIER_TAG_PROTO_* */
  95. struct dsa_notifier_tag_proto_info {
  96. const struct dsa_device_ops *tag_ops;
  97. };
  98. /* DSA_NOTIFIER_TAG_8021Q_VLAN_* */
  99. struct dsa_notifier_tag_8021q_vlan_info {
  100. const struct dsa_port *dp;
  101. u16 vid;
  102. };
  103. /* DSA_NOTIFIER_MASTER_STATE_CHANGE */
  104. struct dsa_notifier_master_state_info {
  105. const struct net_device *master;
  106. bool operational;
  107. };
  108. struct dsa_switchdev_event_work {
  109. struct net_device *dev;
  110. struct net_device *orig_dev;
  111. struct work_struct work;
  112. unsigned long event;
  113. /* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and
  114. * SWITCHDEV_FDB_DEL_TO_DEVICE
  115. */
  116. unsigned char addr[ETH_ALEN];
  117. u16 vid;
  118. bool host_addr;
  119. };
  120. enum dsa_standalone_event {
  121. DSA_UC_ADD,
  122. DSA_UC_DEL,
  123. DSA_MC_ADD,
  124. DSA_MC_DEL,
  125. };
  126. struct dsa_standalone_event_work {
  127. struct work_struct work;
  128. struct net_device *dev;
  129. enum dsa_standalone_event event;
  130. unsigned char addr[ETH_ALEN];
  131. u16 vid;
  132. };
  133. struct dsa_slave_priv {
  134. /* Copy of CPU port xmit for faster access in slave transmit hot path */
  135. struct sk_buff * (*xmit)(struct sk_buff *skb,
  136. struct net_device *dev);
  137. struct gro_cells gcells;
  138. /* DSA port data, such as switch, port index, etc. */
  139. struct dsa_port *dp;
  140. #ifdef CONFIG_NET_POLL_CONTROLLER
  141. struct netpoll *netpoll;
  142. #endif
  143. /* TC context */
  144. struct list_head mall_tc_list;
  145. };
  146. /* dsa.c */
  147. const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol);
  148. void dsa_tag_driver_put(const struct dsa_device_ops *ops);
  149. const struct dsa_device_ops *dsa_find_tagger_by_name(const char *buf);
  150. bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
  151. bool dsa_schedule_work(struct work_struct *work);
  152. const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
  153. static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops)
  154. {
  155. return ops->needed_headroom + ops->needed_tailroom;
  156. }
  157. /* master.c */
  158. int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
  159. void dsa_master_teardown(struct net_device *dev);
  160. int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp,
  161. struct netdev_lag_upper_info *uinfo,
  162. struct netlink_ext_ack *extack);
  163. void dsa_master_lag_teardown(struct net_device *lag_dev,
  164. struct dsa_port *cpu_dp);
  165. static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
  166. int device, int port)
  167. {
  168. struct dsa_port *cpu_dp = dev->dsa_ptr;
  169. struct dsa_switch_tree *dst = cpu_dp->dst;
  170. struct dsa_port *dp;
  171. list_for_each_entry(dp, &dst->ports, list)
  172. if (dp->ds->index == device && dp->index == port &&
  173. dp->type == DSA_PORT_TYPE_USER)
  174. return dp->slave;
  175. return NULL;
  176. }
  177. /* netlink.c */
  178. extern struct rtnl_link_ops dsa_link_ops __read_mostly;
  179. /* port.c */
  180. bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr);
  181. void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp,
  182. const struct dsa_device_ops *tag_ops);
  183. int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age);
  184. int dsa_port_set_mst_state(struct dsa_port *dp,
  185. const struct switchdev_mst_state *state,
  186. struct netlink_ext_ack *extack);
  187. int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy);
  188. int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
  189. void dsa_port_disable_rt(struct dsa_port *dp);
  190. void dsa_port_disable(struct dsa_port *dp);
  191. int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
  192. struct netlink_ext_ack *extack);
  193. void dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br);
  194. void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
  195. int dsa_port_lag_change(struct dsa_port *dp,
  196. struct netdev_lag_lower_state_info *linfo);
  197. int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev,
  198. struct netdev_lag_upper_info *uinfo,
  199. struct netlink_ext_ack *extack);
  200. void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag_dev);
  201. void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag_dev);
  202. int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
  203. struct netlink_ext_ack *extack);
  204. bool dsa_port_skip_vlan_configuration(struct dsa_port *dp);
  205. int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock);
  206. int dsa_port_mst_enable(struct dsa_port *dp, bool on,
  207. struct netlink_ext_ack *extack);
  208. int dsa_port_vlan_msti(struct dsa_port *dp,
  209. const struct switchdev_vlan_msti *msti);
  210. int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu);
  211. int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
  212. u16 vid);
  213. int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
  214. u16 vid);
  215. int dsa_port_standalone_host_fdb_add(struct dsa_port *dp,
  216. const unsigned char *addr, u16 vid);
  217. int dsa_port_standalone_host_fdb_del(struct dsa_port *dp,
  218. const unsigned char *addr, u16 vid);
  219. int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr,
  220. u16 vid);
  221. int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr,
  222. u16 vid);
  223. int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
  224. u16 vid);
  225. int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr,
  226. u16 vid);
  227. int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
  228. int dsa_port_mdb_add(const struct dsa_port *dp,
  229. const struct switchdev_obj_port_mdb *mdb);
  230. int dsa_port_mdb_del(const struct dsa_port *dp,
  231. const struct switchdev_obj_port_mdb *mdb);
  232. int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp,
  233. const struct switchdev_obj_port_mdb *mdb);
  234. int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp,
  235. const struct switchdev_obj_port_mdb *mdb);
  236. int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp,
  237. const struct switchdev_obj_port_mdb *mdb);
  238. int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp,
  239. const struct switchdev_obj_port_mdb *mdb);
  240. int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
  241. struct switchdev_brport_flags flags,
  242. struct netlink_ext_ack *extack);
  243. int dsa_port_bridge_flags(struct dsa_port *dp,
  244. struct switchdev_brport_flags flags,
  245. struct netlink_ext_ack *extack);
  246. int dsa_port_vlan_add(struct dsa_port *dp,
  247. const struct switchdev_obj_port_vlan *vlan,
  248. struct netlink_ext_ack *extack);
  249. int dsa_port_vlan_del(struct dsa_port *dp,
  250. const struct switchdev_obj_port_vlan *vlan);
  251. int dsa_port_host_vlan_add(struct dsa_port *dp,
  252. const struct switchdev_obj_port_vlan *vlan,
  253. struct netlink_ext_ack *extack);
  254. int dsa_port_host_vlan_del(struct dsa_port *dp,
  255. const struct switchdev_obj_port_vlan *vlan);
  256. int dsa_port_mrp_add(const struct dsa_port *dp,
  257. const struct switchdev_obj_mrp *mrp);
  258. int dsa_port_mrp_del(const struct dsa_port *dp,
  259. const struct switchdev_obj_mrp *mrp);
  260. int dsa_port_mrp_add_ring_role(const struct dsa_port *dp,
  261. const struct switchdev_obj_ring_role_mrp *mrp);
  262. int dsa_port_mrp_del_ring_role(const struct dsa_port *dp,
  263. const struct switchdev_obj_ring_role_mrp *mrp);
  264. int dsa_port_phylink_create(struct dsa_port *dp);
  265. void dsa_port_phylink_destroy(struct dsa_port *dp);
  266. int dsa_shared_port_link_register_of(struct dsa_port *dp);
  267. void dsa_shared_port_link_unregister_of(struct dsa_port *dp);
  268. int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr);
  269. void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr);
  270. int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast);
  271. void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast);
  272. void dsa_port_set_host_flood(struct dsa_port *dp, bool uc, bool mc);
  273. int dsa_port_change_master(struct dsa_port *dp, struct net_device *master,
  274. struct netlink_ext_ack *extack);
  275. /* slave.c */
  276. extern const struct dsa_device_ops notag_netdev_ops;
  277. extern struct notifier_block dsa_slave_switchdev_notifier;
  278. extern struct notifier_block dsa_slave_switchdev_blocking_notifier;
  279. void dsa_slave_mii_bus_init(struct dsa_switch *ds);
  280. int dsa_slave_create(struct dsa_port *dp);
  281. void dsa_slave_destroy(struct net_device *slave_dev);
  282. int dsa_slave_suspend(struct net_device *slave_dev);
  283. int dsa_slave_resume(struct net_device *slave_dev);
  284. int dsa_slave_register_notifier(void);
  285. void dsa_slave_unregister_notifier(void);
  286. void dsa_slave_sync_ha(struct net_device *dev);
  287. void dsa_slave_unsync_ha(struct net_device *dev);
  288. void dsa_slave_setup_tagger(struct net_device *slave);
  289. int dsa_slave_change_mtu(struct net_device *dev, int new_mtu);
  290. int dsa_slave_change_master(struct net_device *dev, struct net_device *master,
  291. struct netlink_ext_ack *extack);
  292. int dsa_slave_manage_vlan_filtering(struct net_device *dev,
  293. bool vlan_filtering);
  294. static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
  295. {
  296. struct dsa_slave_priv *p = netdev_priv(dev);
  297. return p->dp;
  298. }
  299. static inline struct net_device *
  300. dsa_slave_to_master(const struct net_device *dev)
  301. {
  302. struct dsa_port *dp = dsa_slave_to_port(dev);
  303. return dsa_port_to_master(dp);
  304. }
  305. /* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged
  306. * frames as untagged, since the bridge will not untag them.
  307. */
  308. static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
  309. {
  310. struct dsa_port *dp = dsa_slave_to_port(skb->dev);
  311. struct net_device *br = dsa_port_bridge_dev_get(dp);
  312. struct net_device *dev = skb->dev;
  313. struct net_device *upper_dev;
  314. u16 vid, pvid, proto;
  315. int err;
  316. if (!br || br_vlan_enabled(br))
  317. return skb;
  318. err = br_vlan_get_proto(br, &proto);
  319. if (err)
  320. return skb;
  321. /* Move VLAN tag from data to hwaccel */
  322. if (!skb_vlan_tag_present(skb) && skb->protocol == htons(proto)) {
  323. skb = skb_vlan_untag(skb);
  324. if (!skb)
  325. return NULL;
  326. }
  327. if (!skb_vlan_tag_present(skb))
  328. return skb;
  329. vid = skb_vlan_tag_get_id(skb);
  330. /* We already run under an RCU read-side critical section since
  331. * we are called from netif_receive_skb_list_internal().
  332. */
  333. err = br_vlan_get_pvid_rcu(dev, &pvid);
  334. if (err)
  335. return skb;
  336. if (vid != pvid)
  337. return skb;
  338. /* The sad part about attempting to untag from DSA is that we
  339. * don't know, unless we check, if the skb will end up in
  340. * the bridge's data path - br_allowed_ingress() - or not.
  341. * For example, there might be an 8021q upper for the
  342. * default_pvid of the bridge, which will steal VLAN-tagged traffic
  343. * from the bridge's data path. This is a configuration that DSA
  344. * supports because vlan_filtering is 0. In that case, we should
  345. * definitely keep the tag, to make sure it keeps working.
  346. */
  347. upper_dev = __vlan_find_dev_deep_rcu(br, htons(proto), vid);
  348. if (upper_dev)
  349. return skb;
  350. __vlan_hwaccel_clear_tag(skb);
  351. return skb;
  352. }
  353. /* For switches without hardware support for DSA tagging to be able
  354. * to support termination through the bridge.
  355. */
  356. static inline struct net_device *
  357. dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid)
  358. {
  359. struct dsa_port *cpu_dp = master->dsa_ptr;
  360. struct dsa_switch_tree *dst = cpu_dp->dst;
  361. struct bridge_vlan_info vinfo;
  362. struct net_device *slave;
  363. struct dsa_port *dp;
  364. int err;
  365. list_for_each_entry(dp, &dst->ports, list) {
  366. if (dp->type != DSA_PORT_TYPE_USER)
  367. continue;
  368. if (!dp->bridge)
  369. continue;
  370. if (dp->stp_state != BR_STATE_LEARNING &&
  371. dp->stp_state != BR_STATE_FORWARDING)
  372. continue;
  373. /* Since the bridge might learn this packet, keep the CPU port
  374. * affinity with the port that will be used for the reply on
  375. * xmit.
  376. */
  377. if (dp->cpu_dp != cpu_dp)
  378. continue;
  379. slave = dp->slave;
  380. err = br_vlan_get_info_rcu(slave, vid, &vinfo);
  381. if (err)
  382. continue;
  383. return slave;
  384. }
  385. return NULL;
  386. }
  387. /* If the ingress port offloads the bridge, we mark the frame as autonomously
  388. * forwarded by hardware, so the software bridge doesn't forward in twice, back
  389. * to us, because we already did. However, if we're in fallback mode and we do
  390. * software bridging, we are not offloading it, therefore the dp->bridge
  391. * pointer is not populated, and flooding needs to be done by software (we are
  392. * effectively operating in standalone ports mode).
  393. */
  394. static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
  395. {
  396. struct dsa_port *dp = dsa_slave_to_port(skb->dev);
  397. skb->offload_fwd_mark = !!(dp->bridge);
  398. }
  399. /* Helper for removing DSA header tags from packets in the RX path.
  400. * Must not be called before skb_pull(len).
  401. * skb->data
  402. * |
  403. * v
  404. * | | | | | | | | | | | | | | | | | | |
  405. * +-----------------------+-----------------------+---------------+-------+
  406. * | Destination MAC | Source MAC | DSA header | EType |
  407. * +-----------------------+-----------------------+---------------+-------+
  408. * | |
  409. * <----- len -----> <----- len ----->
  410. * |
  411. * >>>>>>> v
  412. * >>>>>>> | | | | | | | | | | | | | | |
  413. * >>>>>>> +-----------------------+-----------------------+-------+
  414. * >>>>>>> | Destination MAC | Source MAC | EType |
  415. * +-----------------------+-----------------------+-------+
  416. * ^
  417. * |
  418. * skb->data
  419. */
  420. static inline void dsa_strip_etype_header(struct sk_buff *skb, int len)
  421. {
  422. memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - len, 2 * ETH_ALEN);
  423. }
  424. /* Helper for creating space for DSA header tags in TX path packets.
  425. * Must not be called before skb_push(len).
  426. *
  427. * Before:
  428. *
  429. * <<<<<<< | | | | | | | | | | | | | | |
  430. * ^ <<<<<<< +-----------------------+-----------------------+-------+
  431. * | <<<<<<< | Destination MAC | Source MAC | EType |
  432. * | +-----------------------+-----------------------+-------+
  433. * <----- len ----->
  434. * |
  435. * |
  436. * skb->data
  437. *
  438. * After:
  439. *
  440. * | | | | | | | | | | | | | | | | | | |
  441. * +-----------------------+-----------------------+---------------+-------+
  442. * | Destination MAC | Source MAC | DSA header | EType |
  443. * +-----------------------+-----------------------+---------------+-------+
  444. * ^ | |
  445. * | <----- len ----->
  446. * skb->data
  447. */
  448. static inline void dsa_alloc_etype_header(struct sk_buff *skb, int len)
  449. {
  450. memmove(skb->data, skb->data + len, 2 * ETH_ALEN);
  451. }
  452. /* On RX, eth_type_trans() on the DSA master pulls ETH_HLEN bytes starting from
  453. * skb_mac_header(skb), which leaves skb->data pointing at the first byte after
  454. * what the DSA master perceives as the EtherType (the beginning of the L3
  455. * protocol). Since DSA EtherType header taggers treat the EtherType as part of
  456. * the DSA tag itself, and the EtherType is 2 bytes in length, the DSA header
  457. * is located 2 bytes behind skb->data. Note that EtherType in this context
  458. * means the first 2 bytes of the DSA header, not the encapsulated EtherType
  459. * that will become visible after the DSA header is stripped.
  460. */
  461. static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
  462. {
  463. return skb->data - 2;
  464. }
  465. /* On TX, skb->data points to skb_mac_header(skb), which means that EtherType
  466. * header taggers start exactly where the EtherType is (the EtherType is
  467. * treated as part of the DSA header).
  468. */
  469. static inline void *dsa_etype_header_pos_tx(struct sk_buff *skb)
  470. {
  471. return skb->data + 2 * ETH_ALEN;
  472. }
  473. /* switch.c */
  474. int dsa_switch_register_notifier(struct dsa_switch *ds);
  475. void dsa_switch_unregister_notifier(struct dsa_switch *ds);
  476. static inline bool dsa_switch_supports_uc_filtering(struct dsa_switch *ds)
  477. {
  478. return ds->ops->port_fdb_add && ds->ops->port_fdb_del &&
  479. ds->fdb_isolation && !ds->vlan_filtering_is_global &&
  480. !ds->needs_standalone_vlan_filtering;
  481. }
  482. static inline bool dsa_switch_supports_mc_filtering(struct dsa_switch *ds)
  483. {
  484. return ds->ops->port_mdb_add && ds->ops->port_mdb_del &&
  485. ds->fdb_isolation && !ds->vlan_filtering_is_global &&
  486. !ds->needs_standalone_vlan_filtering;
  487. }
  488. /* dsa2.c */
  489. void dsa_lag_map(struct dsa_switch_tree *dst, struct dsa_lag *lag);
  490. void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag);
  491. struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst,
  492. const struct net_device *lag_dev);
  493. struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst);
  494. int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v);
  495. int dsa_broadcast(unsigned long e, void *v);
  496. int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
  497. const struct dsa_device_ops *tag_ops,
  498. const struct dsa_device_ops *old_tag_ops);
  499. void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst,
  500. struct net_device *master,
  501. bool up);
  502. void dsa_tree_master_oper_state_change(struct dsa_switch_tree *dst,
  503. struct net_device *master,
  504. bool up);
  505. unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max);
  506. void dsa_bridge_num_put(const struct net_device *bridge_dev,
  507. unsigned int bridge_num);
  508. struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst,
  509. const struct net_device *br);
  510. /* tag_8021q.c */
  511. int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
  512. struct dsa_notifier_tag_8021q_vlan_info *info);
  513. int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,
  514. struct dsa_notifier_tag_8021q_vlan_info *info);
  515. extern struct list_head dsa_tree_list;
  516. #endif