dsa.h 9.1 KB

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