dsa.h 4.6 KB

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