dsa_priv.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * net/dsa/dsa_priv.h - Hardware switch handling
  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 __DSA_PRIV_H
  11. #define __DSA_PRIV_H
  12. #include <linux/list.h>
  13. #include <linux/phy.h>
  14. #include <linux/timer.h>
  15. #include <linux/workqueue.h>
  16. #include <net/dsa.h>
  17. struct dsa_switch {
  18. /*
  19. * Parent switch tree, and switch index.
  20. */
  21. struct dsa_switch_tree *dst;
  22. int index;
  23. /*
  24. * Configuration data for this switch.
  25. */
  26. struct dsa_chip_data *pd;
  27. /*
  28. * The used switch driver.
  29. */
  30. struct dsa_switch_driver *drv;
  31. /*
  32. * Reference to mii bus to use.
  33. */
  34. struct mii_bus *master_mii_bus;
  35. /*
  36. * Slave mii_bus and devices for the individual ports.
  37. */
  38. u32 dsa_port_mask;
  39. u32 phys_port_mask;
  40. struct mii_bus *slave_mii_bus;
  41. struct net_device *ports[DSA_MAX_PORTS];
  42. };
  43. struct dsa_switch_tree {
  44. /*
  45. * Configuration data for the platform device that owns
  46. * this dsa switch tree instance.
  47. */
  48. struct dsa_platform_data *pd;
  49. /*
  50. * Reference to network device to use, and which tagging
  51. * protocol to use.
  52. */
  53. struct net_device *master_netdev;
  54. __be16 tag_protocol;
  55. /*
  56. * The switch and port to which the CPU is attached.
  57. */
  58. s8 cpu_switch;
  59. s8 cpu_port;
  60. /*
  61. * Link state polling.
  62. */
  63. int link_poll_needed;
  64. struct work_struct link_poll_work;
  65. struct timer_list link_poll_timer;
  66. /*
  67. * Data for the individual switch chips.
  68. */
  69. struct dsa_switch *ds[DSA_MAX_SWITCHES];
  70. };
  71. static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
  72. {
  73. return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
  74. }
  75. static inline u8 dsa_upstream_port(struct dsa_switch *ds)
  76. {
  77. struct dsa_switch_tree *dst = ds->dst;
  78. /*
  79. * If this is the root switch (i.e. the switch that connects
  80. * to the CPU), return the cpu port number on this switch.
  81. * Else return the (DSA) port number that connects to the
  82. * switch that is one hop closer to the cpu.
  83. */
  84. if (dst->cpu_switch == ds->index)
  85. return dst->cpu_port;
  86. else
  87. return ds->pd->rtable[dst->cpu_switch];
  88. }
  89. struct dsa_slave_priv {
  90. /*
  91. * The linux network interface corresponding to this
  92. * switch port.
  93. */
  94. struct net_device *dev;
  95. /*
  96. * Which switch this port is a part of, and the port index
  97. * for this port.
  98. */
  99. struct dsa_switch *parent;
  100. u8 port;
  101. /*
  102. * The phylib phy_device pointer for the PHY connected
  103. * to this port.
  104. */
  105. struct phy_device *phy;
  106. };
  107. struct dsa_switch_driver {
  108. struct list_head list;
  109. __be16 tag_protocol;
  110. int priv_size;
  111. /*
  112. * Probing and setup.
  113. */
  114. char *(*probe)(struct mii_bus *bus, int sw_addr);
  115. int (*setup)(struct dsa_switch *ds);
  116. int (*set_addr)(struct dsa_switch *ds, u8 *addr);
  117. /*
  118. * Access to the switch's PHY registers.
  119. */
  120. int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
  121. int (*phy_write)(struct dsa_switch *ds, int port,
  122. int regnum, u16 val);
  123. /*
  124. * Link state polling and IRQ handling.
  125. */
  126. void (*poll_link)(struct dsa_switch *ds);
  127. /*
  128. * ethtool hardware statistics.
  129. */
  130. void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
  131. void (*get_ethtool_stats)(struct dsa_switch *ds,
  132. int port, uint64_t *data);
  133. int (*get_sset_count)(struct dsa_switch *ds);
  134. };
  135. /* dsa.c */
  136. extern char dsa_driver_version[];
  137. void register_switch_driver(struct dsa_switch_driver *type);
  138. void unregister_switch_driver(struct dsa_switch_driver *type);
  139. /* slave.c */
  140. void dsa_slave_mii_bus_init(struct dsa_switch *ds);
  141. struct net_device *dsa_slave_create(struct dsa_switch *ds,
  142. struct device *parent,
  143. int port, char *name);
  144. /* tag_dsa.c */
  145. netdev_tx_t dsa_xmit(struct sk_buff *skb, struct net_device *dev);
  146. /* tag_edsa.c */
  147. netdev_tx_t edsa_xmit(struct sk_buff *skb, struct net_device *dev);
  148. /* tag_trailer.c */
  149. netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev);
  150. #endif