switch.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * switch.h: Switch configuration API
  3. *
  4. * Copyright (C) 2008 Felix Fietkau <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #ifndef _LINUX_SWITCH_H
  17. #define _LINUX_SWITCH_H
  18. #include <net/genetlink.h>
  19. #include <uapi/linux/switch.h>
  20. struct switch_dev;
  21. struct switch_op;
  22. struct switch_val;
  23. struct switch_attr;
  24. struct switch_attrlist;
  25. struct switch_led_trigger;
  26. int register_switch(struct switch_dev *dev, struct net_device *netdev);
  27. void unregister_switch(struct switch_dev *dev);
  28. /**
  29. * struct switch_attrlist - attribute list
  30. *
  31. * @n_attr: number of attributes
  32. * @attr: pointer to the attributes array
  33. */
  34. struct switch_attrlist {
  35. int n_attr;
  36. const struct switch_attr *attr;
  37. };
  38. enum switch_port_speed {
  39. SWITCH_PORT_SPEED_UNKNOWN = 0,
  40. SWITCH_PORT_SPEED_10 = 10,
  41. SWITCH_PORT_SPEED_100 = 100,
  42. SWITCH_PORT_SPEED_1000 = 1000,
  43. };
  44. struct switch_port_link {
  45. bool link;
  46. bool duplex;
  47. bool aneg;
  48. bool tx_flow;
  49. bool rx_flow;
  50. enum switch_port_speed speed;
  51. };
  52. struct switch_port_stats {
  53. unsigned long tx_bytes;
  54. unsigned long rx_bytes;
  55. };
  56. /**
  57. * struct switch_dev_ops - switch driver operations
  58. *
  59. * @attr_global: global switch attribute list
  60. * @attr_port: port attribute list
  61. * @attr_vlan: vlan attribute list
  62. *
  63. * Callbacks:
  64. *
  65. * @get_vlan_ports: read the port list of a VLAN
  66. * @set_vlan_ports: set the port list of a VLAN
  67. *
  68. * @get_port_pvid: get the primary VLAN ID of a port
  69. * @set_port_pvid: set the primary VLAN ID of a port
  70. *
  71. * @apply_config: apply all changed settings to the switch
  72. * @reset_switch: resetting the switch
  73. */
  74. struct switch_dev_ops {
  75. struct switch_attrlist attr_global, attr_port, attr_vlan;
  76. int (*get_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
  77. int (*set_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
  78. int (*get_port_pvid)(struct switch_dev *dev, int port, int *val);
  79. int (*set_port_pvid)(struct switch_dev *dev, int port, int val);
  80. int (*apply_config)(struct switch_dev *dev);
  81. int (*reset_switch)(struct switch_dev *dev);
  82. int (*get_port_link)(struct switch_dev *dev, int port,
  83. struct switch_port_link *link);
  84. int (*get_port_stats)(struct switch_dev *dev, int port,
  85. struct switch_port_stats *stats);
  86. };
  87. struct switch_dev {
  88. struct device_node *of_node;
  89. const struct switch_dev_ops *ops;
  90. /* will be automatically filled */
  91. char devname[IFNAMSIZ];
  92. const char *name;
  93. /* NB: either alias or netdev must be set */
  94. const char *alias;
  95. struct net_device *netdev;
  96. int ports;
  97. int vlans;
  98. int cpu_port;
  99. /* the following fields are internal for swconfig */
  100. int id;
  101. struct list_head dev_list;
  102. unsigned long def_global, def_port, def_vlan;
  103. struct mutex sw_mutex;
  104. struct switch_port *portbuf;
  105. struct switch_portmap *portmap;
  106. char buf[128];
  107. #ifdef CONFIG_SWCONFIG_LEDS
  108. struct switch_led_trigger *led_trigger;
  109. #endif
  110. };
  111. struct switch_port {
  112. u32 id;
  113. u32 flags;
  114. };
  115. struct switch_portmap {
  116. u32 virt;
  117. const char *s;
  118. };
  119. struct switch_val {
  120. const struct switch_attr *attr;
  121. int port_vlan;
  122. int len;
  123. union {
  124. const char *s;
  125. u32 i;
  126. struct switch_port *ports;
  127. } value;
  128. };
  129. struct switch_attr {
  130. int disabled;
  131. int type;
  132. const char *name;
  133. const char *description;
  134. int (*set)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
  135. int (*get)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
  136. /* for driver internal use */
  137. int id;
  138. int ofs;
  139. int max;
  140. };
  141. #endif /* _LINUX_SWITCH_H */