mt7530.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com>
  4. */
  5. #ifndef __MT7530_H
  6. #define __MT7530_H
  7. #define MT7530_NUM_PORTS 7
  8. #define MT7530_NUM_PHYS 5
  9. #define MT7530_NUM_FDB_RECORDS 2048
  10. #define MT7530_ALL_MEMBERS 0xff
  11. #define MTK_HDR_LEN 4
  12. #define MT7530_MAX_MTU (15 * 1024 - ETH_HLEN - ETH_FCS_LEN - MTK_HDR_LEN)
  13. enum mt753x_id {
  14. ID_MT7530 = 0,
  15. ID_MT7621 = 1,
  16. ID_MT7531 = 2,
  17. ID_MT7988 = 3,
  18. ID_EN7581 = 4,
  19. };
  20. #define NUM_TRGMII_CTRL 5
  21. #define TRGMII_BASE(x) (0x10000 + (x))
  22. /* Registers to ethsys access */
  23. #define ETHSYS_CLKCFG0 0x2c
  24. #define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
  25. #define SYSC_REG_RSTCTRL 0x34
  26. #define RESET_MCM BIT(2)
  27. /* Register for ARL global control */
  28. #define MT753X_AGC 0xc
  29. #define LOCAL_EN BIT(7)
  30. /* Register for MAC forward control */
  31. #define MT753X_MFC 0x10
  32. #define BC_FFP_MASK GENMASK(31, 24)
  33. #define BC_FFP(x) FIELD_PREP(BC_FFP_MASK, x)
  34. #define UNM_FFP_MASK GENMASK(23, 16)
  35. #define UNM_FFP(x) FIELD_PREP(UNM_FFP_MASK, x)
  36. #define UNU_FFP_MASK GENMASK(15, 8)
  37. #define UNU_FFP(x) FIELD_PREP(UNU_FFP_MASK, x)
  38. #define MT7530_CPU_EN BIT(7)
  39. #define MT7530_CPU_PORT_MASK GENMASK(6, 4)
  40. #define MT7530_CPU_PORT(x) FIELD_PREP(MT7530_CPU_PORT_MASK, x)
  41. #define MT7530_MIRROR_EN BIT(3)
  42. #define MT7530_MIRROR_PORT_MASK GENMASK(2, 0)
  43. #define MT7530_MIRROR_PORT_GET(x) FIELD_GET(MT7530_MIRROR_PORT_MASK, x)
  44. #define MT7530_MIRROR_PORT_SET(x) FIELD_PREP(MT7530_MIRROR_PORT_MASK, x)
  45. #define MT7531_QRY_FFP_MASK GENMASK(7, 0)
  46. #define MT7531_QRY_FFP(x) FIELD_PREP(MT7531_QRY_FFP_MASK, x)
  47. /* Register for CPU forward control */
  48. #define MT7531_CFC 0x4
  49. #define MT7531_MIRROR_EN BIT(19)
  50. #define MT7531_MIRROR_PORT_MASK GENMASK(18, 16)
  51. #define MT7531_MIRROR_PORT_GET(x) FIELD_GET(MT7531_MIRROR_PORT_MASK, x)
  52. #define MT7531_MIRROR_PORT_SET(x) FIELD_PREP(MT7531_MIRROR_PORT_MASK, x)
  53. #define MT7531_CPU_PMAP_MASK GENMASK(7, 0)
  54. #define MT7531_CPU_PMAP(x) FIELD_PREP(MT7531_CPU_PMAP_MASK, x)
  55. #define MT753X_MIRROR_REG(id) ((id == ID_MT7531 || \
  56. id == ID_MT7988 || \
  57. id == ID_EN7581) ? \
  58. MT7531_CFC : MT753X_MFC)
  59. #define MT753X_MIRROR_EN(id) ((id == ID_MT7531 || \
  60. id == ID_MT7988 || \
  61. id == ID_EN7581) ? \
  62. MT7531_MIRROR_EN : MT7530_MIRROR_EN)
  63. #define MT753X_MIRROR_PORT_MASK(id) ((id == ID_MT7531 || \
  64. id == ID_MT7988 || \
  65. id == ID_EN7581) ? \
  66. MT7531_MIRROR_PORT_MASK : \
  67. MT7530_MIRROR_PORT_MASK)
  68. #define MT753X_MIRROR_PORT_GET(id, val) ((id == ID_MT7531 || \
  69. id == ID_MT7988 || \
  70. id == ID_EN7581) ? \
  71. MT7531_MIRROR_PORT_GET(val) : \
  72. MT7530_MIRROR_PORT_GET(val))
  73. #define MT753X_MIRROR_PORT_SET(id, val) ((id == ID_MT7531 || \
  74. id == ID_MT7988 || \
  75. id == ID_EN7581) ? \
  76. MT7531_MIRROR_PORT_SET(val) : \
  77. MT7530_MIRROR_PORT_SET(val))
  78. /* Register for BPDU and PAE frame control */
  79. #define MT753X_BPC 0x24
  80. #define PAE_BPDU_FR BIT(25)
  81. #define PAE_EG_TAG_MASK GENMASK(24, 22)
  82. #define PAE_EG_TAG(x) FIELD_PREP(PAE_EG_TAG_MASK, x)
  83. #define PAE_PORT_FW_MASK GENMASK(18, 16)
  84. #define PAE_PORT_FW(x) FIELD_PREP(PAE_PORT_FW_MASK, x)
  85. #define BPDU_EG_TAG_MASK GENMASK(8, 6)
  86. #define BPDU_EG_TAG(x) FIELD_PREP(BPDU_EG_TAG_MASK, x)
  87. #define BPDU_PORT_FW_MASK GENMASK(2, 0)
  88. /* Register for 01-80-C2-00-00-[01,02] MAC DA frame control */
  89. #define MT753X_RGAC1 0x28
  90. #define R02_BPDU_FR BIT(25)
  91. #define R02_EG_TAG_MASK GENMASK(24, 22)
  92. #define R02_EG_TAG(x) FIELD_PREP(R02_EG_TAG_MASK, x)
  93. #define R02_PORT_FW_MASK GENMASK(18, 16)
  94. #define R02_PORT_FW(x) FIELD_PREP(R02_PORT_FW_MASK, x)
  95. #define R01_BPDU_FR BIT(9)
  96. #define R01_EG_TAG_MASK GENMASK(8, 6)
  97. #define R01_EG_TAG(x) FIELD_PREP(R01_EG_TAG_MASK, x)
  98. #define R01_PORT_FW_MASK GENMASK(2, 0)
  99. /* Register for 01-80-C2-00-00-[03,0E] MAC DA frame control */
  100. #define MT753X_RGAC2 0x2c
  101. #define R0E_BPDU_FR BIT(25)
  102. #define R0E_EG_TAG_MASK GENMASK(24, 22)
  103. #define R0E_EG_TAG(x) FIELD_PREP(R0E_EG_TAG_MASK, x)
  104. #define R0E_PORT_FW_MASK GENMASK(18, 16)
  105. #define R0E_PORT_FW(x) FIELD_PREP(R0E_PORT_FW_MASK, x)
  106. #define R03_BPDU_FR BIT(9)
  107. #define R03_EG_TAG_MASK GENMASK(8, 6)
  108. #define R03_EG_TAG(x) FIELD_PREP(R03_EG_TAG_MASK, x)
  109. #define R03_PORT_FW_MASK GENMASK(2, 0)
  110. enum mt753x_to_cpu_fw {
  111. TO_CPU_FW_SYSTEM_DEFAULT,
  112. TO_CPU_FW_CPU_EXCLUDE = 4,
  113. TO_CPU_FW_CPU_INCLUDE = 5,
  114. TO_CPU_FW_CPU_ONLY = 6,
  115. TO_CPU_FW_DROP = 7,
  116. };
  117. /* Registers for address table access */
  118. #define MT7530_ATA1 0x74
  119. #define STATIC_EMP 0
  120. #define STATIC_ENT 3
  121. #define MT7530_ATA2 0x78
  122. #define ATA2_IVL BIT(15)
  123. #define ATA2_FID(x) (((x) & 0x7) << 12)
  124. /* Register for address table write data */
  125. #define MT7530_ATWD 0x7c
  126. /* Register for address table control */
  127. #define MT7530_ATC 0x80
  128. #define ATC_HASH (((x) & 0xfff) << 16)
  129. #define ATC_BUSY BIT(15)
  130. #define ATC_SRCH_END BIT(14)
  131. #define ATC_SRCH_HIT BIT(13)
  132. #define ATC_INVALID BIT(12)
  133. #define ATC_MAT(x) (((x) & 0xf) << 8)
  134. #define ATC_MAT_MACTAB ATC_MAT(0)
  135. enum mt7530_fdb_cmd {
  136. MT7530_FDB_READ = 0,
  137. MT7530_FDB_WRITE = 1,
  138. MT7530_FDB_FLUSH = 2,
  139. MT7530_FDB_START = 4,
  140. MT7530_FDB_NEXT = 5,
  141. };
  142. /* Registers for table search read address */
  143. #define MT7530_TSRA1 0x84
  144. #define MAC_BYTE_0 24
  145. #define MAC_BYTE_1 16
  146. #define MAC_BYTE_2 8
  147. #define MAC_BYTE_3 0
  148. #define MAC_BYTE_MASK 0xff
  149. #define MT7530_TSRA2 0x88
  150. #define MAC_BYTE_4 24
  151. #define MAC_BYTE_5 16
  152. #define CVID 0
  153. #define CVID_MASK 0xfff
  154. #define MT7530_ATRD 0x8C
  155. #define AGE_TIMER 24
  156. #define AGE_TIMER_MASK 0xff
  157. #define PORT_MAP 4
  158. #define PORT_MAP_MASK 0xff
  159. #define ENT_STATUS 2
  160. #define ENT_STATUS_MASK 0x3
  161. /* Register for vlan table control */
  162. #define MT7530_VTCR 0x90
  163. #define VTCR_BUSY BIT(31)
  164. #define VTCR_INVALID BIT(16)
  165. #define VTCR_FUNC(x) (((x) & 0xf) << 12)
  166. #define VTCR_VID ((x) & 0xfff)
  167. enum mt7530_vlan_cmd {
  168. /* Read/Write the specified VID entry from VAWD register based
  169. * on VID.
  170. */
  171. MT7530_VTCR_RD_VID = 0,
  172. MT7530_VTCR_WR_VID = 1,
  173. };
  174. /* Register for setup vlan and acl write data */
  175. #define MT7530_VAWD1 0x94
  176. #define PORT_STAG BIT(31)
  177. /* Independent VLAN Learning */
  178. #define IVL_MAC BIT(30)
  179. /* Egress Tag Consistent */
  180. #define EG_CON BIT(29)
  181. /* Per VLAN Egress Tag Control */
  182. #define VTAG_EN BIT(28)
  183. /* VLAN Member Control */
  184. #define PORT_MEM(x) (((x) & 0xff) << 16)
  185. /* Filter ID */
  186. #define FID(x) (((x) & 0x7) << 1)
  187. /* VLAN Entry Valid */
  188. #define VLAN_VALID BIT(0)
  189. #define PORT_MEM_SHFT 16
  190. #define PORT_MEM_MASK 0xff
  191. enum mt7530_fid {
  192. FID_STANDALONE = 0,
  193. FID_BRIDGED = 1,
  194. };
  195. #define MT7530_VAWD2 0x98
  196. /* Egress Tag Control */
  197. #define ETAG_CTRL_P(p, x) (((x) & 0x3) << ((p) << 1))
  198. #define ETAG_CTRL_P_MASK(p) ETAG_CTRL_P(p, 3)
  199. enum mt7530_vlan_egress_attr {
  200. MT7530_VLAN_EGRESS_UNTAG = 0,
  201. MT7530_VLAN_EGRESS_TAG = 2,
  202. MT7530_VLAN_EGRESS_STACK = 3,
  203. };
  204. /* Register for address age control */
  205. #define MT7530_AAC 0xa0
  206. /* Disable ageing */
  207. #define AGE_DIS BIT(20)
  208. /* Age count */
  209. #define AGE_CNT_MASK GENMASK(19, 12)
  210. #define AGE_CNT_MAX 0xff
  211. #define AGE_CNT(x) (AGE_CNT_MASK & ((x) << 12))
  212. /* Age unit */
  213. #define AGE_UNIT_MASK GENMASK(11, 0)
  214. #define AGE_UNIT_MAX 0xfff
  215. #define AGE_UNIT(x) (AGE_UNIT_MASK & (x))
  216. /* Register for port STP state control */
  217. #define MT7530_SSP_P(x) (0x2000 + ((x) * 0x100))
  218. #define FID_PST(fid, state) (((state) & 0x3) << ((fid) * 2))
  219. #define FID_PST_MASK(fid) FID_PST(fid, 0x3)
  220. enum mt7530_stp_state {
  221. MT7530_STP_DISABLED = 0,
  222. MT7530_STP_BLOCKING = 1,
  223. MT7530_STP_LISTENING = 1,
  224. MT7530_STP_LEARNING = 2,
  225. MT7530_STP_FORWARDING = 3
  226. };
  227. /* Register for port control */
  228. #define MT7530_PCR_P(x) (0x2004 + ((x) * 0x100))
  229. #define PORT_TX_MIR BIT(9)
  230. #define PORT_RX_MIR BIT(8)
  231. #define PORT_VLAN(x) ((x) & 0x3)
  232. enum mt7530_port_mode {
  233. /* Port Matrix Mode: Frames are forwarded by the PCR_MATRIX members. */
  234. MT7530_PORT_MATRIX_MODE = PORT_VLAN(0),
  235. /* Fallback Mode: Forward received frames with ingress ports that do
  236. * not belong to the VLAN member. Frames whose VID is not listed on
  237. * the VLAN table are forwarded by the PCR_MATRIX members.
  238. */
  239. MT7530_PORT_FALLBACK_MODE = PORT_VLAN(1),
  240. /* Security Mode: Discard any frame due to ingress membership
  241. * violation or VID missed on the VLAN table.
  242. */
  243. MT7530_PORT_SECURITY_MODE = PORT_VLAN(3),
  244. };
  245. #define PCR_MATRIX(x) (((x) & 0xff) << 16)
  246. #define PORT_PRI(x) (((x) & 0x7) << 24)
  247. #define EG_TAG(x) (((x) & 0x3) << 28)
  248. #define PCR_MATRIX_MASK PCR_MATRIX(0xff)
  249. #define PCR_MATRIX_CLR PCR_MATRIX(0)
  250. #define PCR_PORT_VLAN_MASK PORT_VLAN(3)
  251. /* Register for port security control */
  252. #define MT7530_PSC_P(x) (0x200c + ((x) * 0x100))
  253. #define SA_DIS BIT(4)
  254. /* Register for port vlan control */
  255. #define MT7530_PVC_P(x) (0x2010 + ((x) * 0x100))
  256. #define PORT_SPEC_TAG BIT(5)
  257. #define PVC_EG_TAG(x) (((x) & 0x7) << 8)
  258. #define PVC_EG_TAG_MASK PVC_EG_TAG(7)
  259. #define VLAN_ATTR(x) (((x) & 0x3) << 6)
  260. #define VLAN_ATTR_MASK VLAN_ATTR(3)
  261. #define ACC_FRM_MASK GENMASK(1, 0)
  262. enum mt7530_vlan_port_eg_tag {
  263. MT7530_VLAN_EG_DISABLED = 0,
  264. MT7530_VLAN_EG_CONSISTENT = 1,
  265. MT7530_VLAN_EG_UNTAGGED = 4,
  266. };
  267. enum mt7530_vlan_port_attr {
  268. MT7530_VLAN_USER = 0,
  269. MT7530_VLAN_TRANSPARENT = 3,
  270. };
  271. enum mt7530_vlan_port_acc_frm {
  272. MT7530_VLAN_ACC_ALL = 0,
  273. MT7530_VLAN_ACC_TAGGED = 1,
  274. MT7530_VLAN_ACC_UNTAGGED = 2,
  275. };
  276. #define STAG_VPID (((x) & 0xffff) << 16)
  277. /* Register for port port-and-protocol based vlan 1 control */
  278. #define MT7530_PPBV1_P(x) (0x2014 + ((x) * 0x100))
  279. #define G0_PORT_VID(x) (((x) & 0xfff) << 0)
  280. #define G0_PORT_VID_MASK G0_PORT_VID(0xfff)
  281. #define G0_PORT_VID_DEF G0_PORT_VID(0)
  282. /* Register for port MAC control register */
  283. #define MT753X_PMCR_P(x) (0x3000 + ((x) * 0x100))
  284. #define PMCR_IFG_XMIT_MASK GENMASK(19, 18)
  285. #define PMCR_IFG_XMIT(x) FIELD_PREP(PMCR_IFG_XMIT_MASK, x)
  286. #define PMCR_EXT_PHY BIT(17)
  287. #define PMCR_MAC_MODE BIT(16)
  288. #define MT7530_FORCE_MODE BIT(15)
  289. #define PMCR_MAC_TX_EN BIT(14)
  290. #define PMCR_MAC_RX_EN BIT(13)
  291. #define PMCR_BACKOFF_EN BIT(9)
  292. #define PMCR_BACKPR_EN BIT(8)
  293. #define PMCR_FORCE_EEE1G BIT(7)
  294. #define PMCR_FORCE_EEE100 BIT(6)
  295. #define PMCR_FORCE_RX_FC_EN BIT(5)
  296. #define PMCR_FORCE_TX_FC_EN BIT(4)
  297. #define PMCR_FORCE_SPEED_1000 BIT(3)
  298. #define PMCR_FORCE_SPEED_100 BIT(2)
  299. #define PMCR_FORCE_FDX BIT(1)
  300. #define PMCR_FORCE_LNK BIT(0)
  301. #define MT7531_FORCE_MODE_LNK BIT(31)
  302. #define MT7531_FORCE_MODE_SPD BIT(30)
  303. #define MT7531_FORCE_MODE_DPX BIT(29)
  304. #define MT7531_FORCE_MODE_RX_FC BIT(28)
  305. #define MT7531_FORCE_MODE_TX_FC BIT(27)
  306. #define MT7531_FORCE_MODE_EEE100 BIT(26)
  307. #define MT7531_FORCE_MODE_EEE1G BIT(25)
  308. #define MT7531_FORCE_MODE_MASK (MT7531_FORCE_MODE_LNK | \
  309. MT7531_FORCE_MODE_SPD | \
  310. MT7531_FORCE_MODE_DPX | \
  311. MT7531_FORCE_MODE_RX_FC | \
  312. MT7531_FORCE_MODE_TX_FC | \
  313. MT7531_FORCE_MODE_EEE100 | \
  314. MT7531_FORCE_MODE_EEE1G)
  315. #define MT753X_FORCE_MODE(id) ((id == ID_MT7531 || \
  316. id == ID_MT7988) ? \
  317. MT7531_FORCE_MODE_MASK : \
  318. MT7530_FORCE_MODE)
  319. #define PMCR_LINK_SETTINGS_MASK (PMCR_MAC_TX_EN | PMCR_MAC_RX_EN | \
  320. PMCR_FORCE_EEE1G | \
  321. PMCR_FORCE_EEE100 | \
  322. PMCR_FORCE_RX_FC_EN | \
  323. PMCR_FORCE_TX_FC_EN | \
  324. PMCR_FORCE_SPEED_1000 | \
  325. PMCR_FORCE_SPEED_100 | \
  326. PMCR_FORCE_FDX | PMCR_FORCE_LNK)
  327. #define MT753X_PMEEECR_P(x) (0x3004 + (x) * 0x100)
  328. #define WAKEUP_TIME_1000_MASK GENMASK(31, 24)
  329. #define WAKEUP_TIME_1000(x) FIELD_PREP(WAKEUP_TIME_1000_MASK, x)
  330. #define WAKEUP_TIME_100_MASK GENMASK(23, 16)
  331. #define WAKEUP_TIME_100(x) FIELD_PREP(WAKEUP_TIME_100_MASK, x)
  332. #define LPI_THRESH_MASK GENMASK(15, 4)
  333. #define LPI_THRESH_GET(x) FIELD_GET(LPI_THRESH_MASK, x)
  334. #define LPI_THRESH_SET(x) FIELD_PREP(LPI_THRESH_MASK, x)
  335. #define LPI_MODE_EN BIT(0)
  336. #define MT7530_PMSR_P(x) (0x3008 + (x) * 0x100)
  337. #define PMSR_EEE1G BIT(7)
  338. #define PMSR_EEE100M BIT(6)
  339. #define PMSR_RX_FC BIT(5)
  340. #define PMSR_TX_FC BIT(4)
  341. #define PMSR_SPEED_1000 BIT(3)
  342. #define PMSR_SPEED_100 BIT(2)
  343. #define PMSR_SPEED_10 0x00
  344. #define PMSR_SPEED_MASK (PMSR_SPEED_100 | PMSR_SPEED_1000)
  345. #define PMSR_DPX BIT(1)
  346. #define PMSR_LINK BIT(0)
  347. /* Register for port debug count */
  348. #define MT7531_DBG_CNT(x) (0x3018 + (x) * 0x100)
  349. #define MT7531_DIS_CLR BIT(31)
  350. #define MT7530_GMACCR 0x30e0
  351. #define MAX_RX_JUMBO(x) ((x) << 2)
  352. #define MAX_RX_JUMBO_MASK GENMASK(5, 2)
  353. #define MAX_RX_PKT_LEN_MASK GENMASK(1, 0)
  354. #define MAX_RX_PKT_LEN_1522 0x0
  355. #define MAX_RX_PKT_LEN_1536 0x1
  356. #define MAX_RX_PKT_LEN_1552 0x2
  357. #define MAX_RX_PKT_LEN_JUMBO 0x3
  358. /* Register for MIB */
  359. #define MT7530_PORT_MIB_COUNTER(x) (0x4000 + (x) * 0x100)
  360. #define MT7530_MIB_CCR 0x4fe0
  361. #define CCR_MIB_ENABLE BIT(31)
  362. #define CCR_RX_OCT_CNT_GOOD BIT(7)
  363. #define CCR_RX_OCT_CNT_BAD BIT(6)
  364. #define CCR_TX_OCT_CNT_GOOD BIT(5)
  365. #define CCR_TX_OCT_CNT_BAD BIT(4)
  366. #define CCR_MIB_FLUSH (CCR_RX_OCT_CNT_GOOD | \
  367. CCR_RX_OCT_CNT_BAD | \
  368. CCR_TX_OCT_CNT_GOOD | \
  369. CCR_TX_OCT_CNT_BAD)
  370. #define CCR_MIB_ACTIVATE (CCR_MIB_ENABLE | \
  371. CCR_RX_OCT_CNT_GOOD | \
  372. CCR_RX_OCT_CNT_BAD | \
  373. CCR_TX_OCT_CNT_GOOD | \
  374. CCR_TX_OCT_CNT_BAD)
  375. /* MT7531 SGMII register group */
  376. #define MT7531_SGMII_REG_BASE(p) (0x5000 + ((p) - 5) * 0x1000)
  377. #define MT7531_PHYA_CTRL_SIGNAL3 0x128
  378. /* Register for system reset */
  379. #define MT7530_SYS_CTRL 0x7000
  380. #define SYS_CTRL_PHY_RST BIT(2)
  381. #define SYS_CTRL_SW_RST BIT(1)
  382. #define SYS_CTRL_REG_RST BIT(0)
  383. /* Register for system interrupt */
  384. #define MT7530_SYS_INT_EN 0x7008
  385. /* Register for system interrupt status */
  386. #define MT7530_SYS_INT_STS 0x700c
  387. /* Register for PHY Indirect Access Control */
  388. #define MT7531_PHY_IAC 0x701C
  389. #define MT7531_PHY_ACS_ST BIT(31)
  390. #define MT7531_MDIO_REG_ADDR_MASK (0x1f << 25)
  391. #define MT7531_MDIO_PHY_ADDR_MASK (0x1f << 20)
  392. #define MT7531_MDIO_CMD_MASK (0x3 << 18)
  393. #define MT7531_MDIO_ST_MASK (0x3 << 16)
  394. #define MT7531_MDIO_RW_DATA_MASK (0xffff)
  395. #define MT7531_MDIO_REG_ADDR(x) (((x) & 0x1f) << 25)
  396. #define MT7531_MDIO_DEV_ADDR(x) (((x) & 0x1f) << 25)
  397. #define MT7531_MDIO_PHY_ADDR(x) (((x) & 0x1f) << 20)
  398. #define MT7531_MDIO_CMD(x) (((x) & 0x3) << 18)
  399. #define MT7531_MDIO_ST(x) (((x) & 0x3) << 16)
  400. enum mt7531_phy_iac_cmd {
  401. MT7531_MDIO_ADDR = 0,
  402. MT7531_MDIO_WRITE = 1,
  403. MT7531_MDIO_READ = 2,
  404. MT7531_MDIO_READ_CL45 = 3,
  405. };
  406. /* MDIO_ST: MDIO start field */
  407. enum mt7531_mdio_st {
  408. MT7531_MDIO_ST_CL45 = 0,
  409. MT7531_MDIO_ST_CL22 = 1,
  410. };
  411. #define MT7531_MDIO_CL22_READ (MT7531_MDIO_ST(MT7531_MDIO_ST_CL22) | \
  412. MT7531_MDIO_CMD(MT7531_MDIO_READ))
  413. #define MT7531_MDIO_CL22_WRITE (MT7531_MDIO_ST(MT7531_MDIO_ST_CL22) | \
  414. MT7531_MDIO_CMD(MT7531_MDIO_WRITE))
  415. #define MT7531_MDIO_CL45_ADDR (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
  416. MT7531_MDIO_CMD(MT7531_MDIO_ADDR))
  417. #define MT7531_MDIO_CL45_READ (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
  418. MT7531_MDIO_CMD(MT7531_MDIO_READ))
  419. #define MT7531_MDIO_CL45_WRITE (MT7531_MDIO_ST(MT7531_MDIO_ST_CL45) | \
  420. MT7531_MDIO_CMD(MT7531_MDIO_WRITE))
  421. /* Register for RGMII clock phase */
  422. #define MT7531_CLKGEN_CTRL 0x7500
  423. #define CLK_SKEW_OUT(x) (((x) & 0x3) << 8)
  424. #define CLK_SKEW_OUT_MASK GENMASK(9, 8)
  425. #define CLK_SKEW_IN(x) (((x) & 0x3) << 6)
  426. #define CLK_SKEW_IN_MASK GENMASK(7, 6)
  427. #define RXCLK_NO_DELAY BIT(5)
  428. #define TXCLK_NO_REVERSE BIT(4)
  429. #define GP_MODE(x) (((x) & 0x3) << 1)
  430. #define GP_MODE_MASK GENMASK(2, 1)
  431. #define GP_CLK_EN BIT(0)
  432. enum mt7531_gp_mode {
  433. MT7531_GP_MODE_RGMII = 0,
  434. MT7531_GP_MODE_MII = 1,
  435. MT7531_GP_MODE_REV_MII = 2
  436. };
  437. enum mt7531_clk_skew {
  438. MT7531_CLK_SKEW_NO_CHG = 0,
  439. MT7531_CLK_SKEW_DLY_100PPS = 1,
  440. MT7531_CLK_SKEW_DLY_200PPS = 2,
  441. MT7531_CLK_SKEW_REVERSE = 3,
  442. };
  443. /* Register for trap status */
  444. #define MT753X_TRAP 0x7800
  445. #define MT7530_XTAL_MASK (BIT(10) | BIT(9))
  446. #define MT7530_XTAL_25MHZ (BIT(10) | BIT(9))
  447. #define MT7530_XTAL_40MHZ BIT(10)
  448. #define MT7530_XTAL_20MHZ BIT(9)
  449. #define MT7531_XTAL25 BIT(7)
  450. /* Register for trap modification */
  451. #define MT753X_MTRAP 0x7804
  452. #define MT7530_P5_PHY0_SEL BIT(20)
  453. #define MT7530_CHG_TRAP BIT(16)
  454. #define MT7530_P5_MAC_SEL BIT(13)
  455. #define MT7530_P6_DIS BIT(8)
  456. #define MT7530_P5_RGMII_MODE BIT(7)
  457. #define MT7530_P5_DIS BIT(6)
  458. #define MT7530_PHY_INDIRECT_ACCESS BIT(5)
  459. #define MT7531_CHG_STRAP BIT(8)
  460. #define MT7531_PHY_EN BIT(6)
  461. enum mt7531_xtal_fsel {
  462. MT7531_XTAL_FSEL_25MHZ,
  463. MT7531_XTAL_FSEL_40MHZ,
  464. };
  465. /* Register for TOP signal control */
  466. #define MT7530_TOP_SIG_CTRL 0x7808
  467. #define TOP_SIG_CTRL_NORMAL (BIT(17) | BIT(16))
  468. #define MT7531_TOP_SIG_SR 0x780c
  469. #define PAD_DUAL_SGMII_EN BIT(1)
  470. #define PAD_MCM_SMI_EN BIT(0)
  471. #define MT7530_IO_DRV_CR 0x7810
  472. #define P5_IO_CLK_DRV(x) ((x) & 0x3)
  473. #define P5_IO_DATA_DRV(x) (((x) & 0x3) << 4)
  474. #define MT7531_CHIP_REV 0x781C
  475. #define MT7531_PLLGP_EN 0x7820
  476. #define EN_COREPLL BIT(2)
  477. #define SW_CLKSW BIT(1)
  478. #define SW_PLLGP BIT(0)
  479. #define MT7530_P6ECR 0x7830
  480. #define P6_INTF_MODE_MASK 0x3
  481. #define P6_INTF_MODE(x) ((x) & 0x3)
  482. #define MT7531_PLLGP_CR0 0x78a8
  483. #define RG_COREPLL_EN BIT(22)
  484. #define RG_COREPLL_POSDIV_S 23
  485. #define RG_COREPLL_POSDIV_M 0x3800000
  486. #define RG_COREPLL_SDM_PCW_S 1
  487. #define RG_COREPLL_SDM_PCW_M 0x3ffffe
  488. #define RG_COREPLL_SDM_PCW_CHG BIT(0)
  489. /* Registers for RGMII and SGMII PLL clock */
  490. #define MT7531_ANA_PLLGP_CR2 0x78b0
  491. #define MT7531_ANA_PLLGP_CR5 0x78bc
  492. /* Registers for TRGMII on the both side */
  493. #define MT7530_TRGMII_RCK_CTRL 0x7a00
  494. #define RX_RST BIT(31)
  495. #define RXC_DQSISEL BIT(30)
  496. #define DQSI1_TAP_MASK (0x7f << 8)
  497. #define DQSI0_TAP_MASK 0x7f
  498. #define DQSI1_TAP(x) (((x) & 0x7f) << 8)
  499. #define DQSI0_TAP(x) ((x) & 0x7f)
  500. #define MT7530_TRGMII_RCK_RTT 0x7a04
  501. #define DQS1_GATE BIT(31)
  502. #define DQS0_GATE BIT(30)
  503. #define MT7530_TRGMII_RD(x) (0x7a10 + (x) * 8)
  504. #define BSLIP_EN BIT(31)
  505. #define EDGE_CHK BIT(30)
  506. #define RD_TAP_MASK 0x7f
  507. #define RD_TAP(x) ((x) & 0x7f)
  508. #define MT7530_TRGMII_TXCTRL 0x7a40
  509. #define TRAIN_TXEN BIT(31)
  510. #define TXC_INV BIT(30)
  511. #define TX_RST BIT(28)
  512. #define MT7530_TRGMII_TD_ODT(i) (0x7a54 + 8 * (i))
  513. #define TD_DM_DRVP(x) ((x) & 0xf)
  514. #define TD_DM_DRVN(x) (((x) & 0xf) << 4)
  515. #define MT7530_TRGMII_TCK_CTRL 0x7a78
  516. #define TCK_TAP(x) (((x) & 0xf) << 8)
  517. #define MT7530_P5RGMIIRXCR 0x7b00
  518. #define CSR_RGMII_EDGE_ALIGN BIT(8)
  519. #define CSR_RGMII_RXC_0DEG_CFG(x) ((x) & 0xf)
  520. #define MT7530_P5RGMIITXCR 0x7b04
  521. #define CSR_RGMII_TXC_CFG(x) ((x) & 0x1f)
  522. /* Registers for GPIO mode */
  523. #define MT7531_GPIO_MODE0 0x7c0c
  524. #define MT7531_GPIO0_MASK GENMASK(3, 0)
  525. #define MT7531_GPIO0_INTERRUPT 1
  526. #define MT7531_GPIO_MODE1 0x7c10
  527. #define MT7531_GPIO11_RG_RXD2_MASK GENMASK(15, 12)
  528. #define MT7531_EXT_P_MDC_11 (2 << 12)
  529. #define MT7531_GPIO12_RG_RXD3_MASK GENMASK(19, 16)
  530. #define MT7531_EXT_P_MDIO_12 (2 << 16)
  531. /* Registers for LED GPIO control (MT7530 only)
  532. * All registers follow this pattern:
  533. * [ 2: 0] port 0
  534. * [ 6: 4] port 1
  535. * [10: 8] port 2
  536. * [14:12] port 3
  537. * [18:16] port 4
  538. */
  539. /* LED enable, 0: Disable, 1: Enable (Default) */
  540. #define MT7530_LED_EN 0x7d00
  541. /* LED mode, 0: GPIO mode, 1: PHY mode (Default) */
  542. #define MT7530_LED_IO_MODE 0x7d04
  543. /* GPIO direction, 0: Input, 1: Output */
  544. #define MT7530_LED_GPIO_DIR 0x7d10
  545. /* GPIO output enable, 0: Disable, 1: Enable */
  546. #define MT7530_LED_GPIO_OE 0x7d14
  547. /* GPIO value, 0: Low, 1: High */
  548. #define MT7530_LED_GPIO_DATA 0x7d18
  549. #define MT7530_CREV 0x7ffc
  550. #define CHIP_NAME_SHIFT 16
  551. #define MT7530_ID 0x7530
  552. #define MT7531_CREV 0x781C
  553. #define CHIP_REV_M 0x0f
  554. #define MT7531_ID 0x7531
  555. /* Registers for core PLL access through mmd indirect */
  556. #define CORE_PLL_GROUP2 0x401
  557. #define RG_SYSPLL_EN_NORMAL BIT(15)
  558. #define RG_SYSPLL_VODEN BIT(14)
  559. #define RG_SYSPLL_LF BIT(13)
  560. #define RG_SYSPLL_RST_DLY(x) (((x) & 0x3) << 12)
  561. #define RG_SYSPLL_LVROD_EN BIT(10)
  562. #define RG_SYSPLL_PREDIV(x) (((x) & 0x3) << 8)
  563. #define RG_SYSPLL_POSDIV(x) (((x) & 0x3) << 5)
  564. #define RG_SYSPLL_FBKSEL BIT(4)
  565. #define RT_SYSPLL_EN_AFE_OLT BIT(0)
  566. #define CORE_PLL_GROUP4 0x403
  567. #define RG_SYSPLL_DDSFBK_EN BIT(12)
  568. #define RG_SYSPLL_BIAS_EN BIT(11)
  569. #define RG_SYSPLL_BIAS_LPF_EN BIT(10)
  570. #define MT7531_RG_SYSPLL_DMY2 BIT(6)
  571. #define MT7531_PHY_PLL_OFF BIT(5)
  572. #define MT7531_PHY_PLL_BYPASS_MODE BIT(4)
  573. #define MT753X_CTRL_PHY_ADDR(addr) ((addr + 1) & 0x1f)
  574. #define CORE_PLL_GROUP5 0x404
  575. #define RG_LCDDS_PCW_NCPO1(x) ((x) & 0xffff)
  576. #define CORE_PLL_GROUP6 0x405
  577. #define RG_LCDDS_PCW_NCPO0(x) ((x) & 0xffff)
  578. #define CORE_PLL_GROUP7 0x406
  579. #define RG_LCDDS_PWDB BIT(15)
  580. #define RG_LCDDS_ISO_EN BIT(13)
  581. #define RG_LCCDS_C(x) (((x) & 0x7) << 4)
  582. #define RG_LCDDS_PCW_NCPO_CHG BIT(3)
  583. #define CORE_PLL_GROUP10 0x409
  584. #define RG_LCDDS_SSC_DELTA(x) ((x) & 0xfff)
  585. #define CORE_PLL_GROUP11 0x40a
  586. #define RG_LCDDS_SSC_DELTA1(x) ((x) & 0xfff)
  587. #define CORE_GSWPLL_GRP1 0x40d
  588. #define RG_GSWPLL_PREDIV(x) (((x) & 0x3) << 14)
  589. #define RG_GSWPLL_POSDIV_200M(x) (((x) & 0x3) << 12)
  590. #define RG_GSWPLL_EN_PRE BIT(11)
  591. #define RG_GSWPLL_FBKSEL BIT(10)
  592. #define RG_GSWPLL_BP BIT(9)
  593. #define RG_GSWPLL_BR BIT(8)
  594. #define RG_GSWPLL_FBKDIV_200M(x) ((x) & 0xff)
  595. #define CORE_GSWPLL_GRP2 0x40e
  596. #define RG_GSWPLL_POSDIV_500M(x) (((x) & 0x3) << 8)
  597. #define RG_GSWPLL_FBKDIV_500M(x) ((x) & 0xff)
  598. #define CORE_TRGMII_GSW_CLK_CG 0x410
  599. #define REG_GSWCK_EN BIT(0)
  600. #define REG_TRGMIICK_EN BIT(1)
  601. #define MIB_DESC(_s, _o, _n) \
  602. { \
  603. .size = (_s), \
  604. .offset = (_o), \
  605. .name = (_n), \
  606. }
  607. struct mt7530_mib_desc {
  608. unsigned int size;
  609. unsigned int offset;
  610. const char *name;
  611. };
  612. struct mt7530_fdb {
  613. u16 vid;
  614. u8 port_mask;
  615. u8 aging;
  616. u8 mac[6];
  617. bool noarp;
  618. };
  619. /* struct mt7530_port - This is the main data structure for holding the state
  620. * of the port.
  621. * @enable: The status used for show port is enabled or not.
  622. * @pm: The matrix used to show all connections with the port.
  623. * @pvid: The VLAN specified is to be considered a PVID at ingress. Any
  624. * untagged frames will be assigned to the related VLAN.
  625. * @sgmii_pcs: Pointer to PCS instance for SerDes ports
  626. */
  627. struct mt7530_port {
  628. bool enable;
  629. bool isolated;
  630. u32 pm;
  631. u16 pvid;
  632. struct phylink_pcs *sgmii_pcs;
  633. };
  634. /* Port 5 mode definitions of the MT7530 switch */
  635. enum mt7530_p5_mode {
  636. GMAC5,
  637. MUX_PHY_P0,
  638. MUX_PHY_P4,
  639. };
  640. struct mt7530_priv;
  641. struct mt753x_pcs {
  642. struct phylink_pcs pcs;
  643. struct mt7530_priv *priv;
  644. int port;
  645. };
  646. /* struct mt753x_info - This is the main data structure for holding the specific
  647. * part for each supported device
  648. * @id: Holding the identifier to a switch model
  649. * @pcs_ops: Holding the pointer to the MAC PCS operations structure
  650. * @sw_setup: Holding the handler to a device initialization
  651. * @phy_read_c22: Holding the way reading PHY port using C22
  652. * @phy_write_c22: Holding the way writing PHY port using C22
  653. * @phy_read_c45: Holding the way reading PHY port using C45
  654. * @phy_write_c45: Holding the way writing PHY port using C45
  655. * @mac_port_get_caps: Holding the handler that provides MAC capabilities
  656. * @mac_port_config: Holding the way setting up the PHY attribute to a
  657. * certain MAC port
  658. */
  659. struct mt753x_info {
  660. enum mt753x_id id;
  661. const struct phylink_pcs_ops *pcs_ops;
  662. int (*sw_setup)(struct dsa_switch *ds);
  663. int (*phy_read_c22)(struct mt7530_priv *priv, int port, int regnum);
  664. int (*phy_write_c22)(struct mt7530_priv *priv, int port, int regnum,
  665. u16 val);
  666. int (*phy_read_c45)(struct mt7530_priv *priv, int port, int devad,
  667. int regnum);
  668. int (*phy_write_c45)(struct mt7530_priv *priv, int port, int devad,
  669. int regnum, u16 val);
  670. void (*mac_port_get_caps)(struct dsa_switch *ds, int port,
  671. struct phylink_config *config);
  672. void (*mac_port_config)(struct dsa_switch *ds, int port,
  673. unsigned int mode,
  674. phy_interface_t interface);
  675. };
  676. /* struct mt7530_priv - This is the main data structure for holding the state
  677. * of the driver
  678. * @dev: The device pointer
  679. * @ds: The pointer to the dsa core structure
  680. * @bus: The bus used for the device and built-in PHY
  681. * @regmap: The regmap instance representing all switch registers
  682. * @rstc: The pointer to reset control used by MCM
  683. * @core_pwr: The power supplied into the core
  684. * @io_pwr: The power supplied into the I/O
  685. * @reset: The descriptor for GPIO line tied to its reset pin
  686. * @mcm: Flag for distinguishing if standalone IC or module
  687. * coupling
  688. * @ports: Holding the state among ports
  689. * @reg_mutex: The lock for protecting among process accessing
  690. * registers
  691. * @p5_mode: Holding the current mode of port 5 of the MT7530 switch
  692. * @p5_sgmii: Flag for distinguishing if port 5 of the MT7531 switch
  693. * has got SGMII
  694. * @irq: IRQ number of the switch
  695. * @irq_domain: IRQ domain of the switch irq_chip
  696. * @irq_enable: IRQ enable bits, synced to SYS_INT_EN
  697. * @create_sgmii: Pointer to function creating SGMII PCS instance(s)
  698. * @active_cpu_ports: Holding the active CPU ports
  699. * @mdiodev: The pointer to the MDIO device structure
  700. */
  701. struct mt7530_priv {
  702. struct device *dev;
  703. struct dsa_switch *ds;
  704. struct mii_bus *bus;
  705. struct regmap *regmap;
  706. struct reset_control *rstc;
  707. struct regulator *core_pwr;
  708. struct regulator *io_pwr;
  709. struct gpio_desc *reset;
  710. const struct mt753x_info *info;
  711. unsigned int id;
  712. bool mcm;
  713. enum mt7530_p5_mode p5_mode;
  714. bool p5_sgmii;
  715. u8 mirror_rx;
  716. u8 mirror_tx;
  717. struct mt7530_port ports[MT7530_NUM_PORTS];
  718. struct mt753x_pcs pcs[MT7530_NUM_PORTS];
  719. /* protect among processes for registers access*/
  720. struct mutex reg_mutex;
  721. int irq;
  722. struct irq_domain *irq_domain;
  723. u32 irq_enable;
  724. int (*create_sgmii)(struct mt7530_priv *priv);
  725. u8 active_cpu_ports;
  726. struct mdio_device *mdiodev;
  727. };
  728. struct mt7530_hw_vlan_entry {
  729. int port;
  730. u8 old_members;
  731. bool untagged;
  732. };
  733. static inline void mt7530_hw_vlan_entry_init(struct mt7530_hw_vlan_entry *e,
  734. int port, bool untagged)
  735. {
  736. e->port = port;
  737. e->untagged = untagged;
  738. }
  739. typedef void (*mt7530_vlan_op)(struct mt7530_priv *,
  740. struct mt7530_hw_vlan_entry *);
  741. struct mt7530_hw_stats {
  742. const char *string;
  743. u16 reg;
  744. u8 sizeof_stat;
  745. };
  746. struct mt7530_dummy_poll {
  747. struct mt7530_priv *priv;
  748. u32 reg;
  749. };
  750. static inline void INIT_MT7530_DUMMY_POLL(struct mt7530_dummy_poll *p,
  751. struct mt7530_priv *priv, u32 reg)
  752. {
  753. p->priv = priv;
  754. p->reg = reg;
  755. }
  756. int mt7530_probe_common(struct mt7530_priv *priv);
  757. void mt7530_remove_common(struct mt7530_priv *priv);
  758. extern const struct dsa_switch_ops mt7530_switch_ops;
  759. extern const struct mt753x_info mt753x_table[];
  760. #endif /* __MT7530_H */