dsa.h 8.9 KB

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