dsa_priv.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
  44. {
  45. return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
  46. }
  47. static inline u8 dsa_upstream_port(struct dsa_switch *ds)
  48. {
  49. struct dsa_switch_tree *dst = ds->dst;
  50. /*
  51. * If this is the root switch (i.e. the switch that connects
  52. * to the CPU), return the cpu port number on this switch.
  53. * Else return the (DSA) port number that connects to the
  54. * switch that is one hop closer to the cpu.
  55. */
  56. if (dst->cpu_switch == ds->index)
  57. return dst->cpu_port;
  58. else
  59. return ds->pd->rtable[dst->cpu_switch];
  60. }
  61. struct dsa_slave_priv {
  62. /*
  63. * The linux network interface corresponding to this
  64. * switch port.
  65. */
  66. struct net_device *dev;
  67. /*
  68. * Which switch this port is a part of, and the port index
  69. * for this port.
  70. */
  71. struct dsa_switch *parent;
  72. u8 port;
  73. /*
  74. * The phylib phy_device pointer for the PHY connected
  75. * to this port.
  76. */
  77. struct phy_device *phy;
  78. };
  79. struct dsa_switch_driver {
  80. struct list_head list;
  81. __be16 tag_protocol;
  82. int priv_size;
  83. /*
  84. * Probing and setup.
  85. */
  86. char *(*probe)(struct mii_bus *bus, int sw_addr);
  87. int (*setup)(struct dsa_switch *ds);
  88. int (*set_addr)(struct dsa_switch *ds, u8 *addr);
  89. /*
  90. * Access to the switch's PHY registers.
  91. */
  92. int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
  93. int (*phy_write)(struct dsa_switch *ds, int port,
  94. int regnum, u16 val);
  95. /*
  96. * Link state polling and IRQ handling.
  97. */
  98. void (*poll_link)(struct dsa_switch *ds);
  99. /*
  100. * ethtool hardware statistics.
  101. */
  102. void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
  103. void (*get_ethtool_stats)(struct dsa_switch *ds,
  104. int port, uint64_t *data);
  105. int (*get_sset_count)(struct dsa_switch *ds);
  106. };
  107. /* dsa.c */
  108. extern char dsa_driver_version[];
  109. void register_switch_driver(struct dsa_switch_driver *type);
  110. void unregister_switch_driver(struct dsa_switch_driver *type);
  111. /* slave.c */
  112. void dsa_slave_mii_bus_init(struct dsa_switch *ds);
  113. struct net_device *dsa_slave_create(struct dsa_switch *ds,
  114. struct device *parent,
  115. int port, char *name);
  116. /* tag_dsa.c */
  117. netdev_tx_t dsa_xmit(struct sk_buff *skb, struct net_device *dev);
  118. extern struct packet_type dsa_packet_type;
  119. /* tag_edsa.c */
  120. netdev_tx_t edsa_xmit(struct sk_buff *skb, struct net_device *dev);
  121. extern struct packet_type edsa_packet_type;
  122. /* tag_trailer.c */
  123. netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev);
  124. extern struct packet_type trailer_packet_type;
  125. #endif