dsa_priv.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * net/dsa/dsa_priv.h - Hardware switch handling
  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. #ifndef __DSA_PRIV_H
  11. #define __DSA_PRIV_H
  12. #include <linux/phy.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/netpoll.h>
  15. #include <net/dsa.h>
  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_MDB_ADD,
  23. DSA_NOTIFIER_MDB_DEL,
  24. DSA_NOTIFIER_VLAN_ADD,
  25. DSA_NOTIFIER_VLAN_DEL,
  26. };
  27. /* DSA_NOTIFIER_AGEING_TIME */
  28. struct dsa_notifier_ageing_time_info {
  29. struct switchdev_trans *trans;
  30. unsigned int ageing_time;
  31. };
  32. /* DSA_NOTIFIER_BRIDGE_* */
  33. struct dsa_notifier_bridge_info {
  34. struct net_device *br;
  35. int sw_index;
  36. int port;
  37. };
  38. /* DSA_NOTIFIER_FDB_* */
  39. struct dsa_notifier_fdb_info {
  40. int sw_index;
  41. int port;
  42. const unsigned char *addr;
  43. u16 vid;
  44. };
  45. /* DSA_NOTIFIER_MDB_* */
  46. struct dsa_notifier_mdb_info {
  47. const struct switchdev_obj_port_mdb *mdb;
  48. struct switchdev_trans *trans;
  49. int sw_index;
  50. int port;
  51. };
  52. /* DSA_NOTIFIER_VLAN_* */
  53. struct dsa_notifier_vlan_info {
  54. const struct switchdev_obj_port_vlan *vlan;
  55. struct switchdev_trans *trans;
  56. int sw_index;
  57. int port;
  58. };
  59. struct dsa_slave_priv {
  60. /* Copy of CPU port xmit for faster access in slave transmit hot path */
  61. struct sk_buff * (*xmit)(struct sk_buff *skb,
  62. struct net_device *dev);
  63. struct pcpu_sw_netstats *stats64;
  64. /* DSA port data, such as switch, port index, etc. */
  65. struct dsa_port *dp;
  66. #ifdef CONFIG_NET_POLL_CONTROLLER
  67. struct netpoll *netpoll;
  68. #endif
  69. /* TC context */
  70. struct list_head mall_tc_list;
  71. };
  72. /* dsa.c */
  73. const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
  74. bool dsa_schedule_work(struct work_struct *work);
  75. /* legacy.c */
  76. #if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
  77. int dsa_legacy_register(void);
  78. void dsa_legacy_unregister(void);
  79. #else
  80. static inline int dsa_legacy_register(void)
  81. {
  82. return 0;
  83. }
  84. static inline void dsa_legacy_unregister(void) { }
  85. #endif
  86. int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  87. struct net_device *dev,
  88. const unsigned char *addr, u16 vid,
  89. u16 flags);
  90. int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
  91. struct net_device *dev,
  92. const unsigned char *addr, u16 vid);
  93. /* master.c */
  94. int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
  95. void dsa_master_teardown(struct net_device *dev);
  96. static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
  97. int device, int port)
  98. {
  99. struct dsa_port *cpu_dp = dev->dsa_ptr;
  100. struct dsa_switch_tree *dst = cpu_dp->dst;
  101. struct dsa_switch *ds;
  102. struct dsa_port *slave_port;
  103. if (device < 0 || device >= DSA_MAX_SWITCHES)
  104. return NULL;
  105. ds = dst->ds[device];
  106. if (!ds)
  107. return NULL;
  108. if (port < 0 || port >= ds->num_ports)
  109. return NULL;
  110. slave_port = &ds->ports[port];
  111. if (unlikely(slave_port->type != DSA_PORT_TYPE_USER))
  112. return NULL;
  113. return slave_port->slave;
  114. }
  115. /* port.c */
  116. int dsa_port_set_state(struct dsa_port *dp, u8 state,
  117. struct switchdev_trans *trans);
  118. int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
  119. void dsa_port_disable(struct dsa_port *dp, struct phy_device *phy);
  120. int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br);
  121. void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
  122. int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
  123. struct switchdev_trans *trans);
  124. int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
  125. struct switchdev_trans *trans);
  126. int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
  127. u16 vid);
  128. int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
  129. u16 vid);
  130. int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
  131. int dsa_port_mdb_add(const struct dsa_port *dp,
  132. const struct switchdev_obj_port_mdb *mdb,
  133. struct switchdev_trans *trans);
  134. int dsa_port_mdb_del(const struct dsa_port *dp,
  135. const struct switchdev_obj_port_mdb *mdb);
  136. int dsa_port_vlan_add(struct dsa_port *dp,
  137. const struct switchdev_obj_port_vlan *vlan,
  138. struct switchdev_trans *trans);
  139. int dsa_port_vlan_del(struct dsa_port *dp,
  140. const struct switchdev_obj_port_vlan *vlan);
  141. int dsa_port_link_register_of(struct dsa_port *dp);
  142. void dsa_port_link_unregister_of(struct dsa_port *dp);
  143. /* slave.c */
  144. extern const struct dsa_device_ops notag_netdev_ops;
  145. void dsa_slave_mii_bus_init(struct dsa_switch *ds);
  146. int dsa_slave_create(struct dsa_port *dp);
  147. void dsa_slave_destroy(struct net_device *slave_dev);
  148. int dsa_slave_suspend(struct net_device *slave_dev);
  149. int dsa_slave_resume(struct net_device *slave_dev);
  150. int dsa_slave_register_notifier(void);
  151. void dsa_slave_unregister_notifier(void);
  152. static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
  153. {
  154. struct dsa_slave_priv *p = netdev_priv(dev);
  155. return p->dp;
  156. }
  157. static inline struct net_device *
  158. dsa_slave_to_master(const struct net_device *dev)
  159. {
  160. struct dsa_port *dp = dsa_slave_to_port(dev);
  161. return dp->cpu_dp->master;
  162. }
  163. /* switch.c */
  164. int dsa_switch_register_notifier(struct dsa_switch *ds);
  165. void dsa_switch_unregister_notifier(struct dsa_switch *ds);
  166. /* tag_brcm.c */
  167. extern const struct dsa_device_ops brcm_netdev_ops;
  168. extern const struct dsa_device_ops brcm_prepend_netdev_ops;
  169. /* tag_dsa.c */
  170. extern const struct dsa_device_ops dsa_netdev_ops;
  171. /* tag_edsa.c */
  172. extern const struct dsa_device_ops edsa_netdev_ops;
  173. /* tag_ksz.c */
  174. extern const struct dsa_device_ops ksz_netdev_ops;
  175. /* tag_lan9303.c */
  176. extern const struct dsa_device_ops lan9303_netdev_ops;
  177. /* tag_mtk.c */
  178. extern const struct dsa_device_ops mtk_netdev_ops;
  179. /* tag_qca.c */
  180. extern const struct dsa_device_ops qca_netdev_ops;
  181. /* tag_trailer.c */
  182. extern const struct dsa_device_ops trailer_netdev_ops;
  183. #endif