dsa.h 5.3 KB

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