dsa.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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_device_ops;
  54. struct dsa_switch_tree {
  55. /*
  56. * Configuration data for the platform device that owns
  57. * this dsa switch tree instance.
  58. */
  59. struct dsa_platform_data *pd;
  60. /*
  61. * Reference to network device to use, and which tagging
  62. * protocol to use.
  63. */
  64. struct net_device *master_netdev;
  65. const struct dsa_device_ops *ops;
  66. __be16 tag_protocol;
  67. /*
  68. * The switch and port to which the CPU is attached.
  69. */
  70. s8 cpu_switch;
  71. s8 cpu_port;
  72. /*
  73. * Link state polling.
  74. */
  75. int link_poll_needed;
  76. struct work_struct link_poll_work;
  77. struct timer_list link_poll_timer;
  78. /*
  79. * Data for the individual switch chips.
  80. */
  81. struct dsa_switch *ds[DSA_MAX_SWITCHES];
  82. };
  83. struct dsa_switch {
  84. /*
  85. * Parent switch tree, and switch index.
  86. */
  87. struct dsa_switch_tree *dst;
  88. int index;
  89. /*
  90. * Configuration data for this switch.
  91. */
  92. struct dsa_chip_data *pd;
  93. /*
  94. * The used switch driver.
  95. */
  96. struct dsa_switch_driver *drv;
  97. /*
  98. * Reference to mii bus to use.
  99. */
  100. struct mii_bus *master_mii_bus;
  101. /*
  102. * Slave mii_bus and devices for the individual ports.
  103. */
  104. u32 dsa_port_mask;
  105. u32 phys_port_mask;
  106. struct mii_bus *slave_mii_bus;
  107. struct net_device *ports[DSA_MAX_PORTS];
  108. };
  109. static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
  110. {
  111. return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
  112. }
  113. static inline u8 dsa_upstream_port(struct dsa_switch *ds)
  114. {
  115. struct dsa_switch_tree *dst = ds->dst;
  116. /*
  117. * If this is the root switch (i.e. the switch that connects
  118. * to the CPU), return the cpu port number on this switch.
  119. * Else return the (DSA) port number that connects to the
  120. * switch that is one hop closer to the cpu.
  121. */
  122. if (dst->cpu_switch == ds->index)
  123. return dst->cpu_port;
  124. else
  125. return ds->pd->rtable[dst->cpu_switch];
  126. }
  127. struct dsa_switch_driver {
  128. struct list_head list;
  129. __be16 tag_protocol;
  130. int priv_size;
  131. /*
  132. * Probing and setup.
  133. */
  134. char *(*probe)(struct mii_bus *bus, int sw_addr);
  135. int (*setup)(struct dsa_switch *ds);
  136. int (*set_addr)(struct dsa_switch *ds, u8 *addr);
  137. /*
  138. * Access to the switch's PHY registers.
  139. */
  140. int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
  141. int (*phy_write)(struct dsa_switch *ds, int port,
  142. int regnum, u16 val);
  143. /*
  144. * Link state polling and IRQ handling.
  145. */
  146. void (*poll_link)(struct dsa_switch *ds);
  147. /*
  148. * ethtool hardware statistics.
  149. */
  150. void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
  151. void (*get_ethtool_stats)(struct dsa_switch *ds,
  152. int port, uint64_t *data);
  153. int (*get_sset_count)(struct dsa_switch *ds);
  154. };
  155. void register_switch_driver(struct dsa_switch_driver *type);
  156. void unregister_switch_driver(struct dsa_switch_driver *type);
  157. static inline void *ds_to_priv(struct dsa_switch *ds)
  158. {
  159. return (void *)(ds + 1);
  160. }
  161. #endif