dsa.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. #ifndef __LINUX_NET_DSA_H
  11. #define __LINUX_NET_DSA_H
  12. #include <linux/if_ether.h>
  13. #include <linux/list.h>
  14. #include <linux/timer.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/of.h>
  17. #include <linux/phy.h>
  18. #include <linux/phy_fixed.h>
  19. #include <linux/ethtool.h>
  20. enum dsa_tag_protocol {
  21. DSA_TAG_PROTO_NONE = 0,
  22. DSA_TAG_PROTO_DSA,
  23. DSA_TAG_PROTO_TRAILER,
  24. DSA_TAG_PROTO_EDSA,
  25. DSA_TAG_PROTO_BRCM,
  26. };
  27. #define DSA_MAX_SWITCHES 4
  28. #define DSA_MAX_PORTS 12
  29. struct dsa_chip_data {
  30. /*
  31. * How to access the switch configuration registers.
  32. */
  33. struct device *host_dev;
  34. int sw_addr;
  35. /* Device tree node pointer for this specific switch chip
  36. * used during switch setup in case additional properties
  37. * and resources needs to be used
  38. */
  39. struct device_node *of_node;
  40. /*
  41. * The names of the switch's ports. Use "cpu" to
  42. * designate the switch port that the cpu is connected to,
  43. * "dsa" to indicate that this port is a DSA link to
  44. * another switch, NULL to indicate the port is unused,
  45. * or any other string to indicate this is a physical port.
  46. */
  47. char *port_names[DSA_MAX_PORTS];
  48. struct device_node *port_dn[DSA_MAX_PORTS];
  49. /*
  50. * An array (with nr_chips elements) of which element [a]
  51. * indicates which port on this switch should be used to
  52. * send packets to that are destined for switch a. Can be
  53. * NULL if there is only one switch chip.
  54. */
  55. s8 *rtable;
  56. };
  57. struct dsa_platform_data {
  58. /*
  59. * Reference to a Linux network interface that connects
  60. * to the root switch chip of the tree.
  61. */
  62. struct device *netdev;
  63. /*
  64. * Info structs describing each of the switch chips
  65. * connected via this network interface.
  66. */
  67. int nr_chips;
  68. struct dsa_chip_data *chip;
  69. };
  70. struct packet_type;
  71. struct dsa_switch_tree {
  72. /*
  73. * Configuration data for the platform device that owns
  74. * this dsa switch tree instance.
  75. */
  76. struct dsa_platform_data *pd;
  77. /*
  78. * Reference to network device to use, and which tagging
  79. * protocol to use.
  80. */
  81. struct net_device *master_netdev;
  82. int (*rcv)(struct sk_buff *skb,
  83. struct net_device *dev,
  84. struct packet_type *pt,
  85. struct net_device *orig_dev);
  86. enum dsa_tag_protocol tag_protocol;
  87. /*
  88. * The switch and port to which the CPU is attached.
  89. */
  90. s8 cpu_switch;
  91. s8 cpu_port;
  92. /*
  93. * Link state polling.
  94. */
  95. int link_poll_needed;
  96. struct work_struct link_poll_work;
  97. struct timer_list link_poll_timer;
  98. /*
  99. * Data for the individual switch chips.
  100. */
  101. struct dsa_switch *ds[DSA_MAX_SWITCHES];
  102. };
  103. struct dsa_switch {
  104. /*
  105. * Parent switch tree, and switch index.
  106. */
  107. struct dsa_switch_tree *dst;
  108. int index;
  109. /*
  110. * Configuration data for this switch.
  111. */
  112. struct dsa_chip_data *pd;
  113. /*
  114. * The used switch driver.
  115. */
  116. struct dsa_switch_driver *drv;
  117. /*
  118. * Reference to host device to use.
  119. */
  120. struct device *master_dev;
  121. /*
  122. * Slave mii_bus and devices for the individual ports.
  123. */
  124. u32 dsa_port_mask;
  125. u32 phys_port_mask;
  126. u32 phys_mii_mask;
  127. struct mii_bus *slave_mii_bus;
  128. struct net_device *ports[DSA_MAX_PORTS];
  129. };
  130. static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
  131. {
  132. return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
  133. }
  134. static inline u8 dsa_upstream_port(struct dsa_switch *ds)
  135. {
  136. struct dsa_switch_tree *dst = ds->dst;
  137. /*
  138. * If this is the root switch (i.e. the switch that connects
  139. * to the CPU), return the cpu port number on this switch.
  140. * Else return the (DSA) port number that connects to the
  141. * switch that is one hop closer to the cpu.
  142. */
  143. if (dst->cpu_switch == ds->index)
  144. return dst->cpu_port;
  145. else
  146. return ds->pd->rtable[dst->cpu_switch];
  147. }
  148. struct dsa_switch_driver {
  149. struct list_head list;
  150. enum dsa_tag_protocol tag_protocol;
  151. int priv_size;
  152. /*
  153. * Probing and setup.
  154. */
  155. char *(*probe)(struct device *host_dev, int sw_addr);
  156. int (*setup)(struct dsa_switch *ds);
  157. int (*set_addr)(struct dsa_switch *ds, u8 *addr);
  158. u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
  159. /*
  160. * Access to the switch's PHY registers.
  161. */
  162. int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
  163. int (*phy_write)(struct dsa_switch *ds, int port,
  164. int regnum, u16 val);
  165. /*
  166. * Link state polling and IRQ handling.
  167. */
  168. void (*poll_link)(struct dsa_switch *ds);
  169. /*
  170. * Link state adjustment (called from libphy)
  171. */
  172. void (*adjust_link)(struct dsa_switch *ds, int port,
  173. struct phy_device *phydev);
  174. void (*fixed_link_update)(struct dsa_switch *ds, int port,
  175. struct fixed_phy_status *st);
  176. /*
  177. * ethtool hardware statistics.
  178. */
  179. void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
  180. void (*get_ethtool_stats)(struct dsa_switch *ds,
  181. int port, uint64_t *data);
  182. int (*get_sset_count)(struct dsa_switch *ds);
  183. /*
  184. * ethtool Wake-on-LAN
  185. */
  186. void (*get_wol)(struct dsa_switch *ds, int port,
  187. struct ethtool_wolinfo *w);
  188. int (*set_wol)(struct dsa_switch *ds, int port,
  189. struct ethtool_wolinfo *w);
  190. /*
  191. * Suspend and resume
  192. */
  193. int (*suspend)(struct dsa_switch *ds);
  194. int (*resume)(struct dsa_switch *ds);
  195. /*
  196. * Port enable/disable
  197. */
  198. int (*port_enable)(struct dsa_switch *ds, int port,
  199. struct phy_device *phy);
  200. void (*port_disable)(struct dsa_switch *ds, int port,
  201. struct phy_device *phy);
  202. /*
  203. * EEE setttings
  204. */
  205. int (*set_eee)(struct dsa_switch *ds, int port,
  206. struct phy_device *phydev,
  207. struct ethtool_eee *e);
  208. int (*get_eee)(struct dsa_switch *ds, int port,
  209. struct ethtool_eee *e);
  210. };
  211. void register_switch_driver(struct dsa_switch_driver *type);
  212. void unregister_switch_driver(struct dsa_switch_driver *type);
  213. struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
  214. static inline void *ds_to_priv(struct dsa_switch *ds)
  215. {
  216. return (void *)(ds + 1);
  217. }
  218. static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
  219. {
  220. return dst->rcv != NULL;
  221. }
  222. #endif