mvsw61xx.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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@nbd.name>
  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_CMODE_100BASE_X = 0x8,
  45. MV_PORT_STATUS_CMODE_1000BASE_X = 0x9,
  46. MV_PORT_STATUS_CMODE_SGMII = 0xa,
  47. };
  48. #define MV_PORT_STATUS_CMODE_MASK 0xf
  49. enum {
  50. MV_PORT_STATUS_SPEED_10 = 0x00,
  51. MV_PORT_STATUS_SPEED_100 = 0x01,
  52. MV_PORT_STATUS_SPEED_1000 = 0x02,
  53. };
  54. #define MV_PORT_STATUS_SPEED_SHIFT 8
  55. #define MV_PORT_STATUS_SPEED_MASK (3 << 8)
  56. enum {
  57. MV_PORTCTRL_DISABLED = (0 << 0),
  58. MV_PORTCTRL_BLOCKING = (1 << 0),
  59. MV_PORTCTRL_LEARNING = (2 << 0),
  60. MV_PORTCTRL_FORWARDING = (3 << 0),
  61. MV_PORTCTRL_VLANTUN = (1 << 7),
  62. MV_PORTCTRL_EGRESS = (1 << 12),
  63. };
  64. #define MV_PHYCTL_FC_MASK (3 << 6)
  65. enum {
  66. MV_PHYCTL_FC_ENABLE = (3 << 6),
  67. MV_PHYCTL_FC_DISABLE = (1 << 6),
  68. };
  69. enum {
  70. MV_8021Q_EGRESS_UNMODIFIED = 0x00,
  71. MV_8021Q_EGRESS_UNTAGGED = 0x01,
  72. MV_8021Q_EGRESS_TAGGED = 0x02,
  73. MV_8021Q_EGRESS_ADDTAG = 0x03,
  74. };
  75. #define MV_8021Q_MODE_SHIFT 10
  76. #define MV_8021Q_MODE_MASK (0x3 << MV_8021Q_MODE_SHIFT)
  77. enum {
  78. MV_8021Q_MODE_DISABLE = 0x00,
  79. MV_8021Q_MODE_FALLBACK = 0x01,
  80. MV_8021Q_MODE_CHECK = 0x02,
  81. MV_8021Q_MODE_SECURE = 0x03,
  82. };
  83. enum {
  84. MV_8021Q_VLAN_ONLY = (1 << 15),
  85. };
  86. #define MV_PORTASSOC_MONITOR (1 << 15)
  87. enum {
  88. MV_SWITCH_ATU_FID0 = 0x01,
  89. MV_SWITCH_ATU_FID1 = 0x02,
  90. MV_SWITCH_ATU_SID = 0x03,
  91. MV_SWITCH_CTRL = 0x04,
  92. MV_SWITCH_ATU_CTRL = 0x0a,
  93. MV_SWITCH_ATU_OP = 0x0b,
  94. MV_SWITCH_ATU_DATA = 0x0c,
  95. MV_SWITCH_ATU_MAC0 = 0x0d,
  96. MV_SWITCH_ATU_MAC1 = 0x0e,
  97. MV_SWITCH_ATU_MAC2 = 0x0f,
  98. MV_SWITCH_GLOBAL = 0x1b,
  99. MV_SWITCH_GLOBAL2 = 0x1c,
  100. };
  101. #define MV_SWITCHREG(_type) MV_SWITCHREGS, MV_SWITCH_##_type
  102. enum {
  103. MV_SWITCHCTL_EEIE = (1 << 0),
  104. MV_SWITCHCTL_PHYIE = (1 << 1),
  105. MV_SWITCHCTL_ATUDONE = (1 << 2),
  106. MV_SWITCHCTL_ATUIE = (1 << 3),
  107. MV_SWITCHCTL_CTRMODE = (1 << 8),
  108. MV_SWITCHCTL_RELOAD = (1 << 9),
  109. MV_SWITCHCTL_MSIZE = (1 << 10),
  110. MV_SWITCHCTL_DROP = (1 << 13),
  111. };
  112. enum {
  113. #define MV_ATUCTL_AGETIME_MIN 16
  114. #define MV_ATUCTL_AGETIME_MAX 4080
  115. #define MV_ATUCTL_AGETIME(_n) ((((_n) / 16) & 0xff) << 4)
  116. MV_ATUCTL_ATU_256 = (0 << 12),
  117. MV_ATUCTL_ATU_512 = (1 << 12),
  118. MV_ATUCTL_ATU_1K = (2 << 12),
  119. MV_ATUCTL_ATUMASK = (3 << 12),
  120. MV_ATUCTL_NO_LEARN = (1 << 14),
  121. MV_ATUCTL_RESET = (1 << 15),
  122. };
  123. enum {
  124. #define MV_ATUOP_DBNUM(_n) ((_n) & 0x0f)
  125. MV_ATUOP_NOOP = (0 << 12),
  126. MV_ATUOP_FLUSH_ALL = (1 << 12),
  127. MV_ATUOP_FLUSH_U = (2 << 12),
  128. MV_ATUOP_LOAD_DB = (3 << 12),
  129. MV_ATUOP_GET_NEXT = (4 << 12),
  130. MV_ATUOP_FLUSH_DB = (5 << 12),
  131. MV_ATUOP_FLUSH_DB_UU = (6 << 12),
  132. MV_ATUOP_INPROGRESS = (1 << 15),
  133. };
  134. enum {
  135. MV_GLOBAL_STATUS = 0x00,
  136. MV_GLOBAL_ATU_FID = 0x01,
  137. MV_GLOBAL_VTU_FID = 0x02,
  138. MV_GLOBAL_VTU_SID = 0x03,
  139. MV_GLOBAL_CONTROL = 0x04,
  140. MV_GLOBAL_VTU_OP = 0x05,
  141. MV_GLOBAL_VTU_VID = 0x06,
  142. MV_GLOBAL_VTU_DATA1 = 0x07,
  143. MV_GLOBAL_VTU_DATA2 = 0x08,
  144. MV_GLOBAL_VTU_DATA3 = 0x09,
  145. MV_GLOBAL_CONTROL2 = 0x1c,
  146. };
  147. #define MV_GLOBALREG(_type) MV_SWITCH_GLOBAL, MV_GLOBAL_##_type
  148. enum {
  149. MV_GLOBAL2_SMI_OP = 0x18,
  150. MV_GLOBAL2_SMI_DATA = 0x19,
  151. MV_GLOBAL2_SDET_POLARITY = 0x1d,
  152. };
  153. #define MV_GLOBAL2REG(_type) MV_SWITCH_GLOBAL2, MV_GLOBAL2_##_type
  154. enum {
  155. MV_VTU_VID_VALID = (1 << 12),
  156. };
  157. enum {
  158. MV_VTUOP_PURGE = (1 << 12),
  159. MV_VTUOP_LOAD = (3 << 12),
  160. MV_VTUOP_INPROGRESS = (1 << 15),
  161. MV_VTUOP_STULOAD = (5 << 12),
  162. MV_VTUOP_VTU_GET_NEXT = (4 << 12),
  163. MV_VTUOP_STU_GET_NEXT = (6 << 12),
  164. MV_VTUOP_GET_VIOLATION = (7 << 12),
  165. };
  166. enum {
  167. MV_CONTROL_RESET = (1 << 15),
  168. MV_CONTROL_PPU_ENABLE = (1 << 14),
  169. };
  170. enum {
  171. MV_VTUCTL_EGRESS_UNMODIFIED = (0 << 0),
  172. MV_VTUCTL_EGRESS_UNTAGGED = (1 << 0),
  173. MV_VTUCTL_EGRESS_TAGGED = (2 << 0),
  174. MV_VTUCTL_DISCARD = (3 << 0),
  175. };
  176. enum {
  177. MV_STUCTL_STATE_DISABLED = (0 << 0),
  178. MV_STUCTL_STATE_BLOCKING = (1 << 0),
  179. MV_STUCTL_STATE_LEARNING = (2 << 0),
  180. MV_STUCTL_STATE_FORWARDING = (3 << 0),
  181. };
  182. enum {
  183. MV_INDIRECT_REG_CMD = 0,
  184. MV_INDIRECT_REG_DATA = 1,
  185. };
  186. enum {
  187. MV_INDIRECT_INPROGRESS = 0x8000,
  188. MV_INDIRECT_WRITE = 0x9400,
  189. MV_INDIRECT_READ = 0x9800,
  190. };
  191. #define MV_INDIRECT_ADDR_S 5
  192. #define MV_IDENT_MASK 0xfff0
  193. #define MV_IDENT_VALUE_6171 0x1710
  194. #define MV_IDENT_STR_6171 "MV88E6171"
  195. #define MV_IDENT_VALUE_6172 0x1720
  196. #define MV_IDENT_STR_6172 "MV88E6172"
  197. #define MV_IDENT_VALUE_6176 0x1760
  198. #define MV_IDENT_STR_6176 "MV88E6176"
  199. #define MV_IDENT_VALUE_6352 0x3520
  200. #define MV_IDENT_STR_6352 "MV88E6352"
  201. #define MV_PVID_MASK 0x0fff
  202. #define MV_FDB_HI_MASK 0x00ff
  203. #define MV_FDB_LO_MASK 0xf000
  204. #define MV_FDB_HI_SHIFT 4
  205. #define MV_FDB_LO_SHIFT 12
  206. /* Marvell Specific PHY register */
  207. #define MII_MV_SPEC_CTRL 16
  208. enum {
  209. MV_SPEC_MDI_CROSS_AUTO = (0x6 << 4),
  210. MV_SPEC_ENERGY_DETECT = (0x3 << 8),
  211. MV_SPEC_DOWNSHIFT_COUNTER = (0x3 << 12),
  212. };
  213. #define MII_MV_PAGE 22
  214. #define MV_REG_FIBER_SERDES 0xf
  215. #define MV_PAGE_FIBER_SERDES 0x1
  216. struct mvsw61xx_state {
  217. struct switch_dev dev;
  218. struct mii_bus *bus;
  219. int base_addr;
  220. u16 model;
  221. bool registered;
  222. bool is_indirect;
  223. int cpu_port0;
  224. int cpu_port1;
  225. int vlan_enabled;
  226. struct port_state {
  227. u16 fdb;
  228. u16 pvid;
  229. u16 mask;
  230. u8 qmode;
  231. } ports[MV_PORTS];
  232. struct vlan_state {
  233. bool port_based;
  234. u16 mask;
  235. u16 vid;
  236. u32 port_mode;
  237. u32 port_sstate;
  238. } vlans[MV_VLANS];
  239. char buf[128];
  240. };
  241. #define get_state(_dev) container_of((_dev), struct mvsw61xx_state, dev)
  242. #endif