dsa.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. /* Not an official ethertype value, used only internally for DSA
  20. * demultiplexing
  21. */
  22. #define ETH_P_BRCMTAG (ETH_P_XDSA + 1)
  23. #define DSA_MAX_SWITCHES 4
  24. #define DSA_MAX_PORTS 12
  25. struct dsa_chip_data {
  26. /*
  27. * How to access the switch configuration registers.
  28. */
  29. struct device *mii_bus;
  30. int sw_addr;
  31. /* Device tree node pointer for this specific switch chip
  32. * used during switch setup in case additional properties
  33. * and resources needs to be used
  34. */
  35. struct device_node *of_node;
  36. /*
  37. * The names of the switch's ports. Use "cpu" to
  38. * designate the switch port that the cpu is connected to,
  39. * "dsa" to indicate that this port is a DSA link to
  40. * another switch, NULL to indicate the port is unused,
  41. * or any other string to indicate this is a physical port.
  42. */
  43. char *port_names[DSA_MAX_PORTS];
  44. struct device_node *port_dn[DSA_MAX_PORTS];
  45. /*
  46. * An array (with nr_chips elements) of which element [a]
  47. * indicates which port on this switch should be used to
  48. * send packets to that are destined for switch a. Can be
  49. * NULL if there is only one switch chip.
  50. */
  51. s8 *rtable;
  52. };
  53. struct dsa_platform_data {
  54. /*
  55. * Reference to a Linux network interface that connects
  56. * to the root switch chip of the tree.
  57. */
  58. struct device *netdev;
  59. /*
  60. * Info structs describing each of the switch chips
  61. * connected via this network interface.
  62. */
  63. int nr_chips;
  64. struct dsa_chip_data *chip;
  65. };
  66. struct dsa_device_ops;
  67. struct dsa_switch_tree {
  68. /*
  69. * Configuration data for the platform device that owns
  70. * this dsa switch tree instance.
  71. */
  72. struct dsa_platform_data *pd;
  73. /*
  74. * Reference to network device to use, and which tagging
  75. * protocol to use.
  76. */
  77. struct net_device *master_netdev;
  78. const struct dsa_device_ops *ops;
  79. __be16 tag_protocol;
  80. /*
  81. * The switch and port to which the CPU is attached.
  82. */
  83. s8 cpu_switch;
  84. s8 cpu_port;
  85. /*
  86. * Link state polling.
  87. */
  88. int link_poll_needed;
  89. struct work_struct link_poll_work;
  90. struct timer_list link_poll_timer;
  91. /*
  92. * Data for the individual switch chips.
  93. */
  94. struct dsa_switch *ds[DSA_MAX_SWITCHES];
  95. };
  96. struct dsa_switch {
  97. /*
  98. * Parent switch tree, and switch index.
  99. */
  100. struct dsa_switch_tree *dst;
  101. int index;
  102. /*
  103. * Configuration data for this switch.
  104. */
  105. struct dsa_chip_data *pd;
  106. /*
  107. * The used switch driver.
  108. */
  109. struct dsa_switch_driver *drv;
  110. /*
  111. * Reference to mii bus to use.
  112. */
  113. struct mii_bus *master_mii_bus;
  114. /*
  115. * Slave mii_bus and devices for the individual ports.
  116. */
  117. u32 dsa_port_mask;
  118. u32 phys_port_mask;
  119. u32 phys_mii_mask;
  120. struct mii_bus *slave_mii_bus;
  121. struct net_device *ports[DSA_MAX_PORTS];
  122. };
  123. static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
  124. {
  125. return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
  126. }
  127. static inline u8 dsa_upstream_port(struct dsa_switch *ds)
  128. {
  129. struct dsa_switch_tree *dst = ds->dst;
  130. /*
  131. * If this is the root switch (i.e. the switch that connects
  132. * to the CPU), return the cpu port number on this switch.
  133. * Else return the (DSA) port number that connects to the
  134. * switch that is one hop closer to the cpu.
  135. */
  136. if (dst->cpu_switch == ds->index)
  137. return dst->cpu_port;
  138. else
  139. return ds->pd->rtable[dst->cpu_switch];
  140. }
  141. struct dsa_switch_driver {
  142. struct list_head list;
  143. __be16 tag_protocol;
  144. int priv_size;
  145. /*
  146. * Probing and setup.
  147. */
  148. char *(*probe)(struct mii_bus *bus, int sw_addr);
  149. int (*setup)(struct dsa_switch *ds);
  150. int (*set_addr)(struct dsa_switch *ds, u8 *addr);
  151. /*
  152. * Access to the switch's PHY registers.
  153. */
  154. int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
  155. int (*phy_write)(struct dsa_switch *ds, int port,
  156. int regnum, u16 val);
  157. /*
  158. * Link state polling and IRQ handling.
  159. */
  160. void (*poll_link)(struct dsa_switch *ds);
  161. /*
  162. * Link state adjustment (called from libphy)
  163. */
  164. void (*adjust_link)(struct dsa_switch *ds, int port,
  165. struct phy_device *phydev);
  166. void (*fixed_link_update)(struct dsa_switch *ds, int port,
  167. struct fixed_phy_status *st);
  168. /*
  169. * ethtool hardware statistics.
  170. */
  171. void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
  172. void (*get_ethtool_stats)(struct dsa_switch *ds,
  173. int port, uint64_t *data);
  174. int (*get_sset_count)(struct dsa_switch *ds);
  175. };
  176. void register_switch_driver(struct dsa_switch_driver *type);
  177. void unregister_switch_driver(struct dsa_switch_driver *type);
  178. static inline void *ds_to_priv(struct dsa_switch *ds)
  179. {
  180. return (void *)(ds + 1);
  181. }
  182. static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
  183. {
  184. return dst->tag_protocol != 0;
  185. }
  186. #endif