mvsw61xx.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Marvell 88E61xx switch driver
  3. *
  4. * Copyright (c) 2014 Claudio Leite <leitec@staticky.com>
  5. * Copyright (c) 2014 Nikita Nazarenko <nnazarenko@radiofid.com>
  6. *
  7. * Based on code (c) 2008 Felix Fietkau <nbd@openwrt.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License v2 as published by the
  11. * Free Software Foundation
  12. */
  13. #ifndef __MVSW61XX_H
  14. #define __MVSW61XX_H
  15. #define MV_PORTS 7
  16. #define MV_PORTS_MASK ((1 << MV_PORTS) - 1)
  17. #define MV_BASE 0x10
  18. #define MV_SWITCHPORT_BASE 0x10
  19. #define MV_SWITCHPORT(_n) (MV_SWITCHPORT_BASE + (_n))
  20. #define MV_SWITCHREGS (MV_BASE + 0xb)
  21. #define MV_VLANS 64
  22. enum {
  23. MV_PORT_STATUS = 0x00,
  24. MV_PORT_PHYCTL = 0x01,
  25. MV_PORT_JAMCTL = 0x02,
  26. MV_PORT_IDENT = 0x03,
  27. MV_PORT_CONTROL = 0x04,
  28. MV_PORT_CONTROL1 = 0x05,
  29. MV_PORT_VLANMAP = 0x06,
  30. MV_PORT_VLANID = 0x07,
  31. MV_PORT_CONTROL2 = 0x08,
  32. MV_PORT_ASSOC = 0x0b,
  33. MV_PORT_RX_DISCARD_LOW = 0x10,
  34. MV_PORT_RX_DISCARD_HIGH = 0x11,
  35. MV_PORT_IN_FILTERED = 0x12,
  36. MV_PORT_OUT_ACCEPTED = 0x13,
  37. };
  38. #define MV_PORTREG(_type, _port) MV_SWITCHPORT(_port), MV_PORT_##_type
  39. enum {
  40. MV_PORT_STATUS_FDX = (1 << 10),
  41. MV_PORT_STATUS_LINK = (1 << 11),
  42. };
  43. enum {
  44. MV_PORT_STATUS_SPEED_10 = 0x00,
  45. MV_PORT_STATUS_SPEED_100 = 0x01,
  46. MV_PORT_STATUS_SPEED_1000 = 0x02,
  47. };
  48. #define MV_PORT_STATUS_SPEED_SHIFT 8
  49. #define MV_PORT_STATUS_SPEED_MASK (3 << 8)
  50. enum {
  51. MV_PORTCTRL_DISABLED = (0 << 0),
  52. MV_PORTCTRL_BLOCKING = (1 << 0),
  53. MV_PORTCTRL_LEARNING = (2 << 0),
  54. MV_PORTCTRL_FORWARDING = (3 << 0),
  55. MV_PORTCTRL_VLANTUN = (1 << 7),
  56. MV_PORTCTRL_EGRESS = (1 << 12),
  57. };
  58. #define MV_PHYCTL_FC_MASK (3 << 6)
  59. enum {
  60. MV_PHYCTL_FC_ENABLE = (3 << 6),
  61. MV_PHYCTL_FC_DISABLE = (1 << 6),
  62. };
  63. enum {
  64. MV_8021Q_EGRESS_UNMODIFIED = 0x00,
  65. MV_8021Q_EGRESS_UNTAGGED = 0x01,
  66. MV_8021Q_EGRESS_TAGGED = 0x02,
  67. MV_8021Q_EGRESS_ADDTAG = 0x03,
  68. };
  69. #define MV_8021Q_MODE_SHIFT 10
  70. #define MV_8021Q_MODE_MASK (0x3 << MV_8021Q_MODE_SHIFT)
  71. enum {
  72. MV_8021Q_MODE_DISABLE = 0x00,
  73. MV_8021Q_MODE_FALLBACK = 0x01,
  74. MV_8021Q_MODE_CHECK = 0x02,
  75. MV_8021Q_MODE_SECURE = 0x03,
  76. };
  77. enum {
  78. MV_8021Q_VLAN_ONLY = (1 << 15),
  79. };
  80. #define MV_PORTASSOC_MONITOR (1 << 15)
  81. enum {
  82. MV_SWITCH_ATU_FID0 = 0x01,
  83. MV_SWITCH_ATU_FID1 = 0x02,
  84. MV_SWITCH_ATU_SID = 0x03,
  85. MV_SWITCH_CTRL = 0x04,
  86. MV_SWITCH_ATU_CTRL = 0x0a,
  87. MV_SWITCH_ATU_OP = 0x0b,
  88. MV_SWITCH_ATU_DATA = 0x0c,
  89. MV_SWITCH_ATU_MAC0 = 0x0d,
  90. MV_SWITCH_ATU_MAC1 = 0x0e,
  91. MV_SWITCH_ATU_MAC2 = 0x0f,
  92. MV_SWITCH_GLOBAL = 0x1b,
  93. MV_SWITCH_GLOBAL2 = 0x1c,
  94. };
  95. #define MV_SWITCHREG(_type) MV_SWITCHREGS, MV_SWITCH_##_type
  96. enum {
  97. MV_SWITCHCTL_EEIE = (1 << 0),
  98. MV_SWITCHCTL_PHYIE = (1 << 1),
  99. MV_SWITCHCTL_ATUDONE = (1 << 2),
  100. MV_SWITCHCTL_ATUIE = (1 << 3),
  101. MV_SWITCHCTL_CTRMODE = (1 << 8),
  102. MV_SWITCHCTL_RELOAD = (1 << 9),
  103. MV_SWITCHCTL_MSIZE = (1 << 10),
  104. MV_SWITCHCTL_DROP = (1 << 13),
  105. };
  106. enum {
  107. #define MV_ATUCTL_AGETIME_MIN 16
  108. #define MV_ATUCTL_AGETIME_MAX 4080
  109. #define MV_ATUCTL_AGETIME(_n) ((((_n) / 16) & 0xff) << 4)
  110. MV_ATUCTL_ATU_256 = (0 << 12),
  111. MV_ATUCTL_ATU_512 = (1 << 12),
  112. MV_ATUCTL_ATU_1K = (2 << 12),
  113. MV_ATUCTL_ATUMASK = (3 << 12),
  114. MV_ATUCTL_NO_LEARN = (1 << 14),
  115. MV_ATUCTL_RESET = (1 << 15),
  116. };
  117. enum {
  118. #define MV_ATUOP_DBNUM(_n) ((_n) & 0x0f)
  119. MV_ATUOP_NOOP = (0 << 12),
  120. MV_ATUOP_FLUSH_ALL = (1 << 12),
  121. MV_ATUOP_FLUSH_U = (2 << 12),
  122. MV_ATUOP_LOAD_DB = (3 << 12),
  123. MV_ATUOP_GET_NEXT = (4 << 12),
  124. MV_ATUOP_FLUSH_DB = (5 << 12),
  125. MV_ATUOP_FLUSH_DB_UU = (6 << 12),
  126. MV_ATUOP_INPROGRESS = (1 << 15),
  127. };
  128. enum {
  129. MV_GLOBAL_STATUS = 0x00,
  130. MV_GLOBAL_ATU_FID = 0x01,
  131. MV_GLOBAL_VTU_FID = 0x02,
  132. MV_GLOBAL_VTU_SID = 0x03,
  133. MV_GLOBAL_CONTROL = 0x04,
  134. MV_GLOBAL_VTU_OP = 0x05,
  135. MV_GLOBAL_VTU_VID = 0x06,
  136. MV_GLOBAL_VTU_DATA1 = 0x07,
  137. MV_GLOBAL_VTU_DATA2 = 0x08,
  138. MV_GLOBAL_VTU_DATA3 = 0x09,
  139. MV_GLOBAL_CONTROL2 = 0x1c,
  140. };
  141. #define MV_GLOBALREG(_type) MV_SWITCH_GLOBAL, MV_GLOBAL_##_type
  142. enum {
  143. MV_GLOBAL2_SDET_POLARITY = 0x1d,
  144. };
  145. #define MV_GLOBAL2REG(_type) MV_SWITCH_GLOBAL2, MV_GLOBAL2_##_type
  146. enum {
  147. MV_VTU_VID_VALID = (1 << 12),
  148. };
  149. enum {
  150. MV_VTUOP_PURGE = (1 << 12),
  151. MV_VTUOP_LOAD = (3 << 12),
  152. MV_VTUOP_INPROGRESS = (1 << 15),
  153. MV_VTUOP_STULOAD = (5 << 12),
  154. MV_VTUOP_VTU_GET_NEXT = (4 << 12),
  155. MV_VTUOP_STU_GET_NEXT = (6 << 12),
  156. MV_VTUOP_GET_VIOLATION = (7 << 12),
  157. };
  158. enum {
  159. MV_CONTROL_RESET = (1 << 15),
  160. MV_CONTROL_PPU_ENABLE = (1 << 14),
  161. };
  162. enum {
  163. MV_VTUCTL_EGRESS_UNMODIFIED = (0 << 0),
  164. MV_VTUCTL_EGRESS_UNTAGGED = (1 << 0),
  165. MV_VTUCTL_EGRESS_TAGGED = (2 << 0),
  166. MV_VTUCTL_DISCARD = (3 << 0),
  167. };
  168. enum {
  169. MV_STUCTL_STATE_DISABLED = (0 << 0),
  170. MV_STUCTL_STATE_BLOCKING = (1 << 0),
  171. MV_STUCTL_STATE_LEARNING = (2 << 0),
  172. MV_STUCTL_STATE_FORWARDING = (3 << 0),
  173. };
  174. enum {
  175. MV_INDIRECT_REG_CMD = 0,
  176. MV_INDIRECT_REG_DATA = 1,
  177. };
  178. enum {
  179. MV_INDIRECT_INPROGRESS = 0x8000,
  180. MV_INDIRECT_WRITE = 0x9400,
  181. MV_INDIRECT_READ = 0x9800,
  182. };
  183. #define MV_INDIRECT_ADDR_S 5
  184. #define MV_IDENT_MASK 0xfff0
  185. #define MV_IDENT_VALUE_6171 0x1710
  186. #define MV_IDENT_STR_6171 "MV88E6171"
  187. #define MV_IDENT_VALUE_6172 0x1720
  188. #define MV_IDENT_STR_6172 "MV88E6172"
  189. #define MV_IDENT_VALUE_6176 0x1760
  190. #define MV_IDENT_STR_6176 "MV88E6176"
  191. #define MV_PVID_MASK 0x0fff
  192. struct mvsw61xx_state {
  193. struct switch_dev dev;
  194. struct mii_bus *bus;
  195. int base_addr;
  196. u16 model;
  197. bool registered;
  198. bool is_indirect;
  199. int cpu_port0;
  200. int cpu_port1;
  201. int vlan_enabled;
  202. struct port_state {
  203. u16 pvid;
  204. u16 mask;
  205. u8 qmode;
  206. } ports[MV_PORTS];
  207. struct vlan_state {
  208. bool port_based;
  209. u16 mask;
  210. u16 vid;
  211. u32 port_mode;
  212. u32 port_sstate;
  213. } vlans[MV_VLANS];
  214. char buf[128];
  215. };
  216. #define get_state(_dev) container_of((_dev), struct mvsw61xx_state, dev)
  217. #endif