dsa.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. #define DSA_MAX_SWITCHES 4
  17. #define DSA_MAX_PORTS 12
  18. struct dsa_chip_data {
  19. /*
  20. * How to access the switch configuration registers.
  21. */
  22. struct device *mii_bus;
  23. int sw_addr;
  24. /*
  25. * The names of the switch's ports. Use "cpu" to
  26. * designate the switch port that the cpu is connected to,
  27. * "dsa" to indicate that this port is a DSA link to
  28. * another switch, NULL to indicate the port is unused,
  29. * or any other string to indicate this is a physical port.
  30. */
  31. char *port_names[DSA_MAX_PORTS];
  32. /*
  33. * An array (with nr_chips elements) of which element [a]
  34. * indicates which port on this switch should be used to
  35. * send packets to that are destined for switch a. Can be
  36. * NULL if there is only one switch chip.
  37. */
  38. s8 *rtable;
  39. };
  40. struct dsa_platform_data {
  41. /*
  42. * Reference to a Linux network interface that connects
  43. * to the root switch chip of the tree.
  44. */
  45. struct device *netdev;
  46. /*
  47. * Info structs describing each of the switch chips
  48. * connected via this network interface.
  49. */
  50. int nr_chips;
  51. struct dsa_chip_data *chip;
  52. };
  53. struct dsa_switch_tree {
  54. /*
  55. * Configuration data for the platform device that owns
  56. * this dsa switch tree instance.
  57. */
  58. struct dsa_platform_data *pd;
  59. /*
  60. * Reference to network device to use, and which tagging
  61. * protocol to use.
  62. */
  63. struct net_device *master_netdev;
  64. __be16 tag_protocol;
  65. /*
  66. * The switch and port to which the CPU is attached.
  67. */
  68. s8 cpu_switch;
  69. s8 cpu_port;
  70. /*
  71. * Link state polling.
  72. */
  73. int link_poll_needed;
  74. struct work_struct link_poll_work;
  75. struct timer_list link_poll_timer;
  76. /*
  77. * Data for the individual switch chips.
  78. */
  79. struct dsa_switch *ds[DSA_MAX_SWITCHES];
  80. };
  81. struct dsa_switch {
  82. /*
  83. * Parent switch tree, and switch index.
  84. */
  85. struct dsa_switch_tree *dst;
  86. int index;
  87. /*
  88. * Configuration data for this switch.
  89. */
  90. struct dsa_chip_data *pd;
  91. /*
  92. * The used switch driver.
  93. */
  94. struct dsa_switch_driver *drv;
  95. /*
  96. * Reference to mii bus to use.
  97. */
  98. struct mii_bus *master_mii_bus;
  99. /*
  100. * Slave mii_bus and devices for the individual ports.
  101. */
  102. u32 dsa_port_mask;
  103. u32 phys_port_mask;
  104. struct mii_bus *slave_mii_bus;
  105. struct net_device *ports[DSA_MAX_PORTS];
  106. };
  107. static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
  108. {
  109. return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
  110. }
  111. static inline u8 dsa_upstream_port(struct dsa_switch *ds)
  112. {
  113. struct dsa_switch_tree *dst = ds->dst;
  114. /*
  115. * If this is the root switch (i.e. the switch that connects
  116. * to the CPU), return the cpu port number on this switch.
  117. * Else return the (DSA) port number that connects to the
  118. * switch that is one hop closer to the cpu.
  119. */
  120. if (dst->cpu_switch == ds->index)
  121. return dst->cpu_port;
  122. else
  123. return ds->pd->rtable[dst->cpu_switch];
  124. }
  125. struct dsa_switch_driver {
  126. struct list_head list;
  127. __be16 tag_protocol;
  128. int priv_size;
  129. /*
  130. * Probing and setup.
  131. */
  132. char *(*probe)(struct mii_bus *bus, int sw_addr);
  133. int (*setup)(struct dsa_switch *ds);
  134. int (*set_addr)(struct dsa_switch *ds, u8 *addr);
  135. /*
  136. * Access to the switch's PHY registers.
  137. */
  138. int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
  139. int (*phy_write)(struct dsa_switch *ds, int port,
  140. int regnum, u16 val);
  141. /*
  142. * Link state polling and IRQ handling.
  143. */
  144. void (*poll_link)(struct dsa_switch *ds);
  145. /*
  146. * ethtool hardware statistics.
  147. */
  148. void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
  149. void (*get_ethtool_stats)(struct dsa_switch *ds,
  150. int port, uint64_t *data);
  151. int (*get_sset_count)(struct dsa_switch *ds);
  152. };
  153. void register_switch_driver(struct dsa_switch_driver *type);
  154. void unregister_switch_driver(struct dsa_switch_driver *type);
  155. /*
  156. * The original DSA tag format and some other tag formats have no
  157. * ethertype, which means that we need to add a little hack to the
  158. * networking receive path to make sure that received frames get
  159. * the right ->protocol assigned to them when one of those tag
  160. * formats is in use.
  161. */
  162. static inline bool dsa_uses_dsa_tags(struct dsa_switch_tree *dst)
  163. {
  164. return !!(dst->tag_protocol == htons(ETH_P_DSA));
  165. }
  166. static inline bool dsa_uses_trailer_tags(struct dsa_switch_tree *dst)
  167. {
  168. return !!(dst->tag_protocol == htons(ETH_P_TRAILER));
  169. }
  170. #endif