dsa.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. /* set to size of eeprom if supported by the switch */
  36. int eeprom_len;
  37. /* Device tree node pointer for this specific switch chip
  38. * used during switch setup in case additional properties
  39. * and resources needs to be used
  40. */
  41. struct device_node *of_node;
  42. /*
  43. * The names of the switch's ports. Use "cpu" to
  44. * designate the switch port that the cpu is connected to,
  45. * "dsa" to indicate that this port is a DSA link to
  46. * another switch, NULL to indicate the port is unused,
  47. * or any other string to indicate this is a physical port.
  48. */
  49. char *port_names[DSA_MAX_PORTS];
  50. struct device_node *port_dn[DSA_MAX_PORTS];
  51. /*
  52. * An array (with nr_chips elements) of which element [a]
  53. * indicates which port on this switch should be used to
  54. * send packets to that are destined for switch a. Can be
  55. * NULL if there is only one switch chip.
  56. */
  57. s8 *rtable;
  58. };
  59. struct dsa_platform_data {
  60. /*
  61. * Reference to a Linux network interface that connects
  62. * to the root switch chip of the tree.
  63. */
  64. struct device *netdev;
  65. struct net_device *of_netdev;
  66. /*
  67. * Info structs describing each of the switch chips
  68. * connected via this network interface.
  69. */
  70. int nr_chips;
  71. struct dsa_chip_data *chip;
  72. };
  73. struct packet_type;
  74. struct dsa_switch_tree {
  75. /*
  76. * Configuration data for the platform device that owns
  77. * this dsa switch tree instance.
  78. */
  79. struct dsa_platform_data *pd;
  80. /*
  81. * Reference to network device to use, and which tagging
  82. * protocol to use.
  83. */
  84. struct net_device *master_netdev;
  85. int (*rcv)(struct sk_buff *skb,
  86. struct net_device *dev,
  87. struct packet_type *pt,
  88. struct net_device *orig_dev);
  89. enum dsa_tag_protocol tag_protocol;
  90. /*
  91. * The switch and port to which the CPU is attached.
  92. */
  93. s8 cpu_switch;
  94. s8 cpu_port;
  95. /*
  96. * Link state polling.
  97. */
  98. int link_poll_needed;
  99. struct work_struct link_poll_work;
  100. struct timer_list link_poll_timer;
  101. /*
  102. * Data for the individual switch chips.
  103. */
  104. struct dsa_switch *ds[DSA_MAX_SWITCHES];
  105. };
  106. struct dsa_switch {
  107. /*
  108. * Parent switch tree, and switch index.
  109. */
  110. struct dsa_switch_tree *dst;
  111. int index;
  112. /*
  113. * Tagging protocol understood by this switch
  114. */
  115. enum dsa_tag_protocol tag_protocol;
  116. /*
  117. * Configuration data for this switch.
  118. */
  119. struct dsa_chip_data *pd;
  120. /*
  121. * The used switch driver.
  122. */
  123. struct dsa_switch_driver *drv;
  124. /*
  125. * Reference to host device to use.
  126. */
  127. struct device *master_dev;
  128. #ifdef CONFIG_NET_DSA_HWMON
  129. /*
  130. * Hardware monitoring information
  131. */
  132. char hwmon_name[IFNAMSIZ + 8];
  133. struct device *hwmon_dev;
  134. #endif
  135. /*
  136. * Slave mii_bus and devices for the individual ports.
  137. */
  138. u32 dsa_port_mask;
  139. u32 phys_port_mask;
  140. u32 phys_mii_mask;
  141. struct mii_bus *slave_mii_bus;
  142. struct net_device *ports[DSA_MAX_PORTS];
  143. };
  144. static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
  145. {
  146. return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
  147. }
  148. static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p)
  149. {
  150. return !!((ds->dsa_port_mask) & (1 << p));
  151. }
  152. static inline bool dsa_is_port_initialized(struct dsa_switch *ds, int p)
  153. {
  154. return ds->phys_port_mask & (1 << p) && ds->ports[p];
  155. }
  156. static inline u8 dsa_upstream_port(struct dsa_switch *ds)
  157. {
  158. struct dsa_switch_tree *dst = ds->dst;
  159. /*
  160. * If this is the root switch (i.e. the switch that connects
  161. * to the CPU), return the cpu port number on this switch.
  162. * Else return the (DSA) port number that connects to the
  163. * switch that is one hop closer to the cpu.
  164. */
  165. if (dst->cpu_switch == ds->index)
  166. return dst->cpu_port;
  167. else
  168. return ds->pd->rtable[dst->cpu_switch];
  169. }
  170. struct switchdev_trans;
  171. struct switchdev_obj_port_fdb;
  172. struct dsa_switch_driver {
  173. struct list_head list;
  174. enum dsa_tag_protocol tag_protocol;
  175. int priv_size;
  176. /*
  177. * Probing and setup.
  178. */
  179. char *(*probe)(struct device *host_dev, int sw_addr);
  180. int (*setup)(struct dsa_switch *ds);
  181. int (*set_addr)(struct dsa_switch *ds, u8 *addr);
  182. u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
  183. /*
  184. * Access to the switch's PHY registers.
  185. */
  186. int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
  187. int (*phy_write)(struct dsa_switch *ds, int port,
  188. int regnum, u16 val);
  189. /*
  190. * Link state polling and IRQ handling.
  191. */
  192. void (*poll_link)(struct dsa_switch *ds);
  193. /*
  194. * Link state adjustment (called from libphy)
  195. */
  196. void (*adjust_link)(struct dsa_switch *ds, int port,
  197. struct phy_device *phydev);
  198. void (*fixed_link_update)(struct dsa_switch *ds, int port,
  199. struct fixed_phy_status *st);
  200. /*
  201. * ethtool hardware statistics.
  202. */
  203. void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
  204. void (*get_ethtool_stats)(struct dsa_switch *ds,
  205. int port, uint64_t *data);
  206. int (*get_sset_count)(struct dsa_switch *ds);
  207. /*
  208. * ethtool Wake-on-LAN
  209. */
  210. void (*get_wol)(struct dsa_switch *ds, int port,
  211. struct ethtool_wolinfo *w);
  212. int (*set_wol)(struct dsa_switch *ds, int port,
  213. struct ethtool_wolinfo *w);
  214. /*
  215. * Suspend and resume
  216. */
  217. int (*suspend)(struct dsa_switch *ds);
  218. int (*resume)(struct dsa_switch *ds);
  219. /*
  220. * Port enable/disable
  221. */
  222. int (*port_enable)(struct dsa_switch *ds, int port,
  223. struct phy_device *phy);
  224. void (*port_disable)(struct dsa_switch *ds, int port,
  225. struct phy_device *phy);
  226. /*
  227. * EEE setttings
  228. */
  229. int (*set_eee)(struct dsa_switch *ds, int port,
  230. struct phy_device *phydev,
  231. struct ethtool_eee *e);
  232. int (*get_eee)(struct dsa_switch *ds, int port,
  233. struct ethtool_eee *e);
  234. #ifdef CONFIG_NET_DSA_HWMON
  235. /* Hardware monitoring */
  236. int (*get_temp)(struct dsa_switch *ds, int *temp);
  237. int (*get_temp_limit)(struct dsa_switch *ds, int *temp);
  238. int (*set_temp_limit)(struct dsa_switch *ds, int temp);
  239. int (*get_temp_alarm)(struct dsa_switch *ds, bool *alarm);
  240. #endif
  241. /* EEPROM access */
  242. int (*get_eeprom_len)(struct dsa_switch *ds);
  243. int (*get_eeprom)(struct dsa_switch *ds,
  244. struct ethtool_eeprom *eeprom, u8 *data);
  245. int (*set_eeprom)(struct dsa_switch *ds,
  246. struct ethtool_eeprom *eeprom, u8 *data);
  247. /*
  248. * Register access.
  249. */
  250. int (*get_regs_len)(struct dsa_switch *ds, int port);
  251. void (*get_regs)(struct dsa_switch *ds, int port,
  252. struct ethtool_regs *regs, void *p);
  253. /*
  254. * Bridge integration
  255. */
  256. int (*port_join_bridge)(struct dsa_switch *ds, int port,
  257. u32 br_port_mask);
  258. int (*port_leave_bridge)(struct dsa_switch *ds, int port,
  259. u32 br_port_mask);
  260. int (*port_stp_update)(struct dsa_switch *ds, int port,
  261. u8 state);
  262. /*
  263. * VLAN support
  264. */
  265. int (*port_pvid_get)(struct dsa_switch *ds, int port, u16 *pvid);
  266. int (*port_pvid_set)(struct dsa_switch *ds, int port, u16 pvid);
  267. int (*port_vlan_add)(struct dsa_switch *ds, int port, u16 vid,
  268. bool untagged);
  269. int (*port_vlan_del)(struct dsa_switch *ds, int port, u16 vid);
  270. int (*vlan_getnext)(struct dsa_switch *ds, u16 *vid,
  271. unsigned long *ports, unsigned long *untagged);
  272. /*
  273. * Forwarding database
  274. */
  275. int (*port_fdb_prepare)(struct dsa_switch *ds, int port,
  276. const struct switchdev_obj_port_fdb *fdb,
  277. struct switchdev_trans *trans);
  278. int (*port_fdb_add)(struct dsa_switch *ds, int port,
  279. const struct switchdev_obj_port_fdb *fdb,
  280. struct switchdev_trans *trans);
  281. int (*port_fdb_del)(struct dsa_switch *ds, int port,
  282. const struct switchdev_obj_port_fdb *fdb);
  283. int (*port_fdb_getnext)(struct dsa_switch *ds, int port,
  284. unsigned char *addr, u16 *vid,
  285. bool *is_static);
  286. };
  287. void register_switch_driver(struct dsa_switch_driver *type);
  288. void unregister_switch_driver(struct dsa_switch_driver *type);
  289. struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
  290. static inline void *ds_to_priv(struct dsa_switch *ds)
  291. {
  292. return (void *)(ds + 1);
  293. }
  294. static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
  295. {
  296. return dst->rcv != NULL;
  297. }
  298. #endif