dsa.h 4.7 KB

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