ravb.h 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Renesas Ethernet AVB device driver
  3. *
  4. * Copyright (C) 2014-2015 Renesas Electronics Corporation
  5. * Copyright (C) 2015 Renesas Solutions Corp.
  6. * Copyright (C) 2015-2016 Cogent Embedded, Inc. <source@cogentembedded.com>
  7. *
  8. * Based on the SuperH Ethernet driver
  9. */
  10. #ifndef __RAVB_H__
  11. #define __RAVB_H__
  12. #include <linux/interrupt.h>
  13. #include <linux/io.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mdio-bitbang.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/phy.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/ptp_clock_kernel.h>
  20. #define BE_TX_RING_SIZE 64 /* TX ring size for Best Effort */
  21. #define BE_RX_RING_SIZE 1024 /* RX ring size for Best Effort */
  22. #define NC_TX_RING_SIZE 64 /* TX ring size for Network Control */
  23. #define NC_RX_RING_SIZE 64 /* RX ring size for Network Control */
  24. #define BE_TX_RING_MIN 64
  25. #define BE_RX_RING_MIN 64
  26. #define BE_TX_RING_MAX 1024
  27. #define BE_RX_RING_MAX 2048
  28. #define PKT_BUF_SZ 1538
  29. /* Driver's parameters */
  30. #define RAVB_ALIGN 128
  31. /* Hardware time stamp */
  32. #define RAVB_TXTSTAMP_VALID 0x00000001 /* TX timestamp valid */
  33. #define RAVB_TXTSTAMP_ENABLED 0x00000010 /* Enable TX timestamping */
  34. #define RAVB_RXTSTAMP_VALID 0x00000001 /* RX timestamp valid */
  35. #define RAVB_RXTSTAMP_TYPE 0x00000006 /* RX type mask */
  36. #define RAVB_RXTSTAMP_TYPE_V2_L2_EVENT 0x00000002
  37. #define RAVB_RXTSTAMP_TYPE_ALL 0x00000006
  38. #define RAVB_RXTSTAMP_ENABLED 0x00000010 /* Enable RX timestamping */
  39. enum ravb_reg {
  40. /* AVB-DMAC registers */
  41. CCC = 0x0000,
  42. DBAT = 0x0004,
  43. DLR = 0x0008,
  44. CSR = 0x000C,
  45. CDAR0 = 0x0010,
  46. CDAR1 = 0x0014,
  47. CDAR2 = 0x0018,
  48. CDAR3 = 0x001C,
  49. CDAR4 = 0x0020,
  50. CDAR5 = 0x0024,
  51. CDAR6 = 0x0028,
  52. CDAR7 = 0x002C,
  53. CDAR8 = 0x0030,
  54. CDAR9 = 0x0034,
  55. CDAR10 = 0x0038,
  56. CDAR11 = 0x003C,
  57. CDAR12 = 0x0040,
  58. CDAR13 = 0x0044,
  59. CDAR14 = 0x0048,
  60. CDAR15 = 0x004C,
  61. CDAR16 = 0x0050,
  62. CDAR17 = 0x0054,
  63. CDAR18 = 0x0058,
  64. CDAR19 = 0x005C,
  65. CDAR20 = 0x0060,
  66. CDAR21 = 0x0064,
  67. ESR = 0x0088,
  68. APSR = 0x008C, /* R-Car Gen3 only */
  69. RCR = 0x0090,
  70. RQC0 = 0x0094,
  71. RQC1 = 0x0098,
  72. RQC2 = 0x009C,
  73. RQC3 = 0x00A0,
  74. RQC4 = 0x00A4,
  75. RPC = 0x00B0,
  76. UFCW = 0x00BC,
  77. UFCS = 0x00C0,
  78. UFCV0 = 0x00C4,
  79. UFCV1 = 0x00C8,
  80. UFCV2 = 0x00CC,
  81. UFCV3 = 0x00D0,
  82. UFCV4 = 0x00D4,
  83. UFCD0 = 0x00E0,
  84. UFCD1 = 0x00E4,
  85. UFCD2 = 0x00E8,
  86. UFCD3 = 0x00EC,
  87. UFCD4 = 0x00F0,
  88. SFO = 0x00FC,
  89. SFP0 = 0x0100,
  90. SFP1 = 0x0104,
  91. SFP2 = 0x0108,
  92. SFP3 = 0x010C,
  93. SFP4 = 0x0110,
  94. SFP5 = 0x0114,
  95. SFP6 = 0x0118,
  96. SFP7 = 0x011C,
  97. SFP8 = 0x0120,
  98. SFP9 = 0x0124,
  99. SFP10 = 0x0128,
  100. SFP11 = 0x012C,
  101. SFP12 = 0x0130,
  102. SFP13 = 0x0134,
  103. SFP14 = 0x0138,
  104. SFP15 = 0x013C,
  105. SFP16 = 0x0140,
  106. SFP17 = 0x0144,
  107. SFP18 = 0x0148,
  108. SFP19 = 0x014C,
  109. SFP20 = 0x0150,
  110. SFP21 = 0x0154,
  111. SFP22 = 0x0158,
  112. SFP23 = 0x015C,
  113. SFP24 = 0x0160,
  114. SFP25 = 0x0164,
  115. SFP26 = 0x0168,
  116. SFP27 = 0x016C,
  117. SFP28 = 0x0170,
  118. SFP29 = 0x0174,
  119. SFP30 = 0x0178,
  120. SFP31 = 0x017C,
  121. SFM0 = 0x01C0,
  122. SFM1 = 0x01C4,
  123. TGC = 0x0300,
  124. TCCR = 0x0304,
  125. TSR = 0x0308,
  126. TFA0 = 0x0310,
  127. TFA1 = 0x0314,
  128. TFA2 = 0x0318,
  129. CIVR0 = 0x0320,
  130. CIVR1 = 0x0324,
  131. CDVR0 = 0x0328,
  132. CDVR1 = 0x032C,
  133. CUL0 = 0x0330,
  134. CUL1 = 0x0334,
  135. CLL0 = 0x0338,
  136. CLL1 = 0x033C,
  137. DIC = 0x0350,
  138. DIS = 0x0354,
  139. EIC = 0x0358,
  140. EIS = 0x035C,
  141. RIC0 = 0x0360,
  142. RIS0 = 0x0364,
  143. RIC1 = 0x0368,
  144. RIS1 = 0x036C,
  145. RIC2 = 0x0370,
  146. RIS2 = 0x0374,
  147. TIC = 0x0378,
  148. TIS = 0x037C,
  149. ISS = 0x0380,
  150. CIE = 0x0384, /* R-Car Gen3 only */
  151. GCCR = 0x0390,
  152. GMTT = 0x0394,
  153. GPTC = 0x0398,
  154. GTI = 0x039C,
  155. GTO0 = 0x03A0,
  156. GTO1 = 0x03A4,
  157. GTO2 = 0x03A8,
  158. GIC = 0x03AC,
  159. GIS = 0x03B0,
  160. GCPT = 0x03B4, /* Undocumented? */
  161. GCT0 = 0x03B8,
  162. GCT1 = 0x03BC,
  163. GCT2 = 0x03C0,
  164. GIE = 0x03CC, /* R-Car Gen3 only */
  165. GID = 0x03D0, /* R-Car Gen3 only */
  166. DIL = 0x0440, /* R-Car Gen3 only */
  167. RIE0 = 0x0460, /* R-Car Gen3 only */
  168. RID0 = 0x0464, /* R-Car Gen3 only */
  169. RIE2 = 0x0470, /* R-Car Gen3 only */
  170. RID2 = 0x0474, /* R-Car Gen3 only */
  171. TIE = 0x0478, /* R-Car Gen3 only */
  172. TID = 0x047c, /* R-Car Gen3 only */
  173. /* E-MAC registers */
  174. ECMR = 0x0500,
  175. RFLR = 0x0508,
  176. ECSR = 0x0510,
  177. ECSIPR = 0x0518,
  178. PIR = 0x0520,
  179. PSR = 0x0528,
  180. PIPR = 0x052c,
  181. MPR = 0x0558,
  182. PFTCR = 0x055c,
  183. PFRCR = 0x0560,
  184. GECMR = 0x05b0,
  185. MAHR = 0x05c0,
  186. MALR = 0x05c8,
  187. TROCR = 0x0700, /* Undocumented? */
  188. CDCR = 0x0708, /* Undocumented? */
  189. LCCR = 0x0710, /* Undocumented? */
  190. CEFCR = 0x0740,
  191. FRECR = 0x0748,
  192. TSFRCR = 0x0750,
  193. TLFRCR = 0x0758,
  194. RFCR = 0x0760,
  195. CERCR = 0x0768, /* Undocumented? */
  196. CEECR = 0x0770, /* Undocumented? */
  197. MAFCR = 0x0778,
  198. };
  199. /* Register bits of the Ethernet AVB */
  200. /* CCC */
  201. enum CCC_BIT {
  202. CCC_OPC = 0x00000003,
  203. CCC_OPC_RESET = 0x00000000,
  204. CCC_OPC_CONFIG = 0x00000001,
  205. CCC_OPC_OPERATION = 0x00000002,
  206. CCC_GAC = 0x00000080,
  207. CCC_DTSR = 0x00000100,
  208. CCC_CSEL = 0x00030000,
  209. CCC_CSEL_HPB = 0x00010000,
  210. CCC_CSEL_ETH_TX = 0x00020000,
  211. CCC_CSEL_GMII_REF = 0x00030000,
  212. CCC_BOC = 0x00100000, /* Undocumented? */
  213. CCC_LBME = 0x01000000,
  214. };
  215. /* CSR */
  216. enum CSR_BIT {
  217. CSR_OPS = 0x0000000F,
  218. CSR_OPS_RESET = 0x00000001,
  219. CSR_OPS_CONFIG = 0x00000002,
  220. CSR_OPS_OPERATION = 0x00000004,
  221. CSR_OPS_STANDBY = 0x00000008, /* Undocumented? */
  222. CSR_DTS = 0x00000100,
  223. CSR_TPO0 = 0x00010000,
  224. CSR_TPO1 = 0x00020000,
  225. CSR_TPO2 = 0x00040000,
  226. CSR_TPO3 = 0x00080000,
  227. CSR_RPO = 0x00100000,
  228. };
  229. /* ESR */
  230. enum ESR_BIT {
  231. ESR_EQN = 0x0000001F,
  232. ESR_ET = 0x00000F00,
  233. ESR_EIL = 0x00001000,
  234. };
  235. /* APSR */
  236. enum APSR_BIT {
  237. APSR_MEMS = 0x00000002,
  238. APSR_CMSW = 0x00000010,
  239. APSR_DM = 0x00006000, /* Undocumented? */
  240. APSR_DM_RDM = 0x00002000,
  241. APSR_DM_TDM = 0x00004000,
  242. };
  243. /* RCR */
  244. enum RCR_BIT {
  245. RCR_EFFS = 0x00000001,
  246. RCR_ENCF = 0x00000002,
  247. RCR_ESF = 0x0000000C,
  248. RCR_ETS0 = 0x00000010,
  249. RCR_ETS2 = 0x00000020,
  250. RCR_RFCL = 0x1FFF0000,
  251. };
  252. /* RQC0/1/2/3/4 */
  253. enum RQC_BIT {
  254. RQC_RSM0 = 0x00000003,
  255. RQC_UFCC0 = 0x00000030,
  256. RQC_RSM1 = 0x00000300,
  257. RQC_UFCC1 = 0x00003000,
  258. RQC_RSM2 = 0x00030000,
  259. RQC_UFCC2 = 0x00300000,
  260. RQC_RSM3 = 0x03000000,
  261. RQC_UFCC3 = 0x30000000,
  262. };
  263. /* RPC */
  264. enum RPC_BIT {
  265. RPC_PCNT = 0x00000700,
  266. RPC_DCNT = 0x00FF0000,
  267. };
  268. /* UFCW */
  269. enum UFCW_BIT {
  270. UFCW_WL0 = 0x0000003F,
  271. UFCW_WL1 = 0x00003F00,
  272. UFCW_WL2 = 0x003F0000,
  273. UFCW_WL3 = 0x3F000000,
  274. };
  275. /* UFCS */
  276. enum UFCS_BIT {
  277. UFCS_SL0 = 0x0000003F,
  278. UFCS_SL1 = 0x00003F00,
  279. UFCS_SL2 = 0x003F0000,
  280. UFCS_SL3 = 0x3F000000,
  281. };
  282. /* UFCV0/1/2/3/4 */
  283. enum UFCV_BIT {
  284. UFCV_CV0 = 0x0000003F,
  285. UFCV_CV1 = 0x00003F00,
  286. UFCV_CV2 = 0x003F0000,
  287. UFCV_CV3 = 0x3F000000,
  288. };
  289. /* UFCD0/1/2/3/4 */
  290. enum UFCD_BIT {
  291. UFCD_DV0 = 0x0000003F,
  292. UFCD_DV1 = 0x00003F00,
  293. UFCD_DV2 = 0x003F0000,
  294. UFCD_DV3 = 0x3F000000,
  295. };
  296. /* SFO */
  297. enum SFO_BIT {
  298. SFO_FPB = 0x0000003F,
  299. };
  300. /* RTC */
  301. enum RTC_BIT {
  302. RTC_MFL0 = 0x00000FFF,
  303. RTC_MFL1 = 0x0FFF0000,
  304. };
  305. /* TGC */
  306. enum TGC_BIT {
  307. TGC_TSM0 = 0x00000001,
  308. TGC_TSM1 = 0x00000002,
  309. TGC_TSM2 = 0x00000004,
  310. TGC_TSM3 = 0x00000008,
  311. TGC_TQP = 0x00000030,
  312. TGC_TQP_NONAVB = 0x00000000,
  313. TGC_TQP_AVBMODE1 = 0x00000010,
  314. TGC_TQP_AVBMODE2 = 0x00000030,
  315. TGC_TBD0 = 0x00000300,
  316. TGC_TBD1 = 0x00003000,
  317. TGC_TBD2 = 0x00030000,
  318. TGC_TBD3 = 0x00300000,
  319. };
  320. /* TCCR */
  321. enum TCCR_BIT {
  322. TCCR_TSRQ0 = 0x00000001,
  323. TCCR_TSRQ1 = 0x00000002,
  324. TCCR_TSRQ2 = 0x00000004,
  325. TCCR_TSRQ3 = 0x00000008,
  326. TCCR_TFEN = 0x00000100,
  327. TCCR_TFR = 0x00000200,
  328. };
  329. /* TSR */
  330. enum TSR_BIT {
  331. TSR_CCS0 = 0x00000003,
  332. TSR_CCS1 = 0x0000000C,
  333. TSR_TFFL = 0x00000700,
  334. };
  335. /* TFA2 */
  336. enum TFA2_BIT {
  337. TFA2_TSV = 0x0000FFFF,
  338. TFA2_TST = 0x03FF0000,
  339. };
  340. /* DIC */
  341. enum DIC_BIT {
  342. DIC_DPE1 = 0x00000002,
  343. DIC_DPE2 = 0x00000004,
  344. DIC_DPE3 = 0x00000008,
  345. DIC_DPE4 = 0x00000010,
  346. DIC_DPE5 = 0x00000020,
  347. DIC_DPE6 = 0x00000040,
  348. DIC_DPE7 = 0x00000080,
  349. DIC_DPE8 = 0x00000100,
  350. DIC_DPE9 = 0x00000200,
  351. DIC_DPE10 = 0x00000400,
  352. DIC_DPE11 = 0x00000800,
  353. DIC_DPE12 = 0x00001000,
  354. DIC_DPE13 = 0x00002000,
  355. DIC_DPE14 = 0x00004000,
  356. DIC_DPE15 = 0x00008000,
  357. };
  358. /* DIS */
  359. enum DIS_BIT {
  360. DIS_DPF1 = 0x00000002,
  361. DIS_DPF2 = 0x00000004,
  362. DIS_DPF3 = 0x00000008,
  363. DIS_DPF4 = 0x00000010,
  364. DIS_DPF5 = 0x00000020,
  365. DIS_DPF6 = 0x00000040,
  366. DIS_DPF7 = 0x00000080,
  367. DIS_DPF8 = 0x00000100,
  368. DIS_DPF9 = 0x00000200,
  369. DIS_DPF10 = 0x00000400,
  370. DIS_DPF11 = 0x00000800,
  371. DIS_DPF12 = 0x00001000,
  372. DIS_DPF13 = 0x00002000,
  373. DIS_DPF14 = 0x00004000,
  374. DIS_DPF15 = 0x00008000,
  375. };
  376. /* EIC */
  377. enum EIC_BIT {
  378. EIC_MREE = 0x00000001,
  379. EIC_MTEE = 0x00000002,
  380. EIC_QEE = 0x00000004,
  381. EIC_SEE = 0x00000008,
  382. EIC_CLLE0 = 0x00000010,
  383. EIC_CLLE1 = 0x00000020,
  384. EIC_CULE0 = 0x00000040,
  385. EIC_CULE1 = 0x00000080,
  386. EIC_TFFE = 0x00000100,
  387. };
  388. /* EIS */
  389. enum EIS_BIT {
  390. EIS_MREF = 0x00000001,
  391. EIS_MTEF = 0x00000002,
  392. EIS_QEF = 0x00000004,
  393. EIS_SEF = 0x00000008,
  394. EIS_CLLF0 = 0x00000010,
  395. EIS_CLLF1 = 0x00000020,
  396. EIS_CULF0 = 0x00000040,
  397. EIS_CULF1 = 0x00000080,
  398. EIS_TFFF = 0x00000100,
  399. EIS_QFS = 0x00010000,
  400. EIS_RESERVED = (GENMASK(31, 17) | GENMASK(15, 11)),
  401. };
  402. /* RIC0 */
  403. enum RIC0_BIT {
  404. RIC0_FRE0 = 0x00000001,
  405. RIC0_FRE1 = 0x00000002,
  406. RIC0_FRE2 = 0x00000004,
  407. RIC0_FRE3 = 0x00000008,
  408. RIC0_FRE4 = 0x00000010,
  409. RIC0_FRE5 = 0x00000020,
  410. RIC0_FRE6 = 0x00000040,
  411. RIC0_FRE7 = 0x00000080,
  412. RIC0_FRE8 = 0x00000100,
  413. RIC0_FRE9 = 0x00000200,
  414. RIC0_FRE10 = 0x00000400,
  415. RIC0_FRE11 = 0x00000800,
  416. RIC0_FRE12 = 0x00001000,
  417. RIC0_FRE13 = 0x00002000,
  418. RIC0_FRE14 = 0x00004000,
  419. RIC0_FRE15 = 0x00008000,
  420. RIC0_FRE16 = 0x00010000,
  421. RIC0_FRE17 = 0x00020000,
  422. };
  423. /* RIC0 */
  424. enum RIS0_BIT {
  425. RIS0_FRF0 = 0x00000001,
  426. RIS0_FRF1 = 0x00000002,
  427. RIS0_FRF2 = 0x00000004,
  428. RIS0_FRF3 = 0x00000008,
  429. RIS0_FRF4 = 0x00000010,
  430. RIS0_FRF5 = 0x00000020,
  431. RIS0_FRF6 = 0x00000040,
  432. RIS0_FRF7 = 0x00000080,
  433. RIS0_FRF8 = 0x00000100,
  434. RIS0_FRF9 = 0x00000200,
  435. RIS0_FRF10 = 0x00000400,
  436. RIS0_FRF11 = 0x00000800,
  437. RIS0_FRF12 = 0x00001000,
  438. RIS0_FRF13 = 0x00002000,
  439. RIS0_FRF14 = 0x00004000,
  440. RIS0_FRF15 = 0x00008000,
  441. RIS0_FRF16 = 0x00010000,
  442. RIS0_FRF17 = 0x00020000,
  443. RIS0_RESERVED = GENMASK(31, 18),
  444. };
  445. /* RIC1 */
  446. enum RIC1_BIT {
  447. RIC1_RFWE = 0x80000000,
  448. };
  449. /* RIS1 */
  450. enum RIS1_BIT {
  451. RIS1_RFWF = 0x80000000,
  452. };
  453. /* RIC2 */
  454. enum RIC2_BIT {
  455. RIC2_QFE0 = 0x00000001,
  456. RIC2_QFE1 = 0x00000002,
  457. RIC2_QFE2 = 0x00000004,
  458. RIC2_QFE3 = 0x00000008,
  459. RIC2_QFE4 = 0x00000010,
  460. RIC2_QFE5 = 0x00000020,
  461. RIC2_QFE6 = 0x00000040,
  462. RIC2_QFE7 = 0x00000080,
  463. RIC2_QFE8 = 0x00000100,
  464. RIC2_QFE9 = 0x00000200,
  465. RIC2_QFE10 = 0x00000400,
  466. RIC2_QFE11 = 0x00000800,
  467. RIC2_QFE12 = 0x00001000,
  468. RIC2_QFE13 = 0x00002000,
  469. RIC2_QFE14 = 0x00004000,
  470. RIC2_QFE15 = 0x00008000,
  471. RIC2_QFE16 = 0x00010000,
  472. RIC2_QFE17 = 0x00020000,
  473. RIC2_RFFE = 0x80000000,
  474. };
  475. /* RIS2 */
  476. enum RIS2_BIT {
  477. RIS2_QFF0 = 0x00000001,
  478. RIS2_QFF1 = 0x00000002,
  479. RIS2_QFF2 = 0x00000004,
  480. RIS2_QFF3 = 0x00000008,
  481. RIS2_QFF4 = 0x00000010,
  482. RIS2_QFF5 = 0x00000020,
  483. RIS2_QFF6 = 0x00000040,
  484. RIS2_QFF7 = 0x00000080,
  485. RIS2_QFF8 = 0x00000100,
  486. RIS2_QFF9 = 0x00000200,
  487. RIS2_QFF10 = 0x00000400,
  488. RIS2_QFF11 = 0x00000800,
  489. RIS2_QFF12 = 0x00001000,
  490. RIS2_QFF13 = 0x00002000,
  491. RIS2_QFF14 = 0x00004000,
  492. RIS2_QFF15 = 0x00008000,
  493. RIS2_QFF16 = 0x00010000,
  494. RIS2_QFF17 = 0x00020000,
  495. RIS2_RFFF = 0x80000000,
  496. RIS2_RESERVED = GENMASK(30, 18),
  497. };
  498. /* TIC */
  499. enum TIC_BIT {
  500. TIC_FTE0 = 0x00000001, /* Undocumented? */
  501. TIC_FTE1 = 0x00000002, /* Undocumented? */
  502. TIC_TFUE = 0x00000100,
  503. TIC_TFWE = 0x00000200,
  504. };
  505. /* TIS */
  506. enum TIS_BIT {
  507. TIS_FTF0 = 0x00000001, /* Undocumented? */
  508. TIS_FTF1 = 0x00000002, /* Undocumented? */
  509. TIS_TFUF = 0x00000100,
  510. TIS_TFWF = 0x00000200,
  511. TIS_RESERVED = (GENMASK(31, 20) | GENMASK(15, 12) | GENMASK(7, 4))
  512. };
  513. /* ISS */
  514. enum ISS_BIT {
  515. ISS_FRS = 0x00000001, /* Undocumented? */
  516. ISS_FTS = 0x00000004, /* Undocumented? */
  517. ISS_ES = 0x00000040,
  518. ISS_MS = 0x00000080,
  519. ISS_TFUS = 0x00000100,
  520. ISS_TFWS = 0x00000200,
  521. ISS_RFWS = 0x00001000,
  522. ISS_CGIS = 0x00002000,
  523. ISS_DPS1 = 0x00020000,
  524. ISS_DPS2 = 0x00040000,
  525. ISS_DPS3 = 0x00080000,
  526. ISS_DPS4 = 0x00100000,
  527. ISS_DPS5 = 0x00200000,
  528. ISS_DPS6 = 0x00400000,
  529. ISS_DPS7 = 0x00800000,
  530. ISS_DPS8 = 0x01000000,
  531. ISS_DPS9 = 0x02000000,
  532. ISS_DPS10 = 0x04000000,
  533. ISS_DPS11 = 0x08000000,
  534. ISS_DPS12 = 0x10000000,
  535. ISS_DPS13 = 0x20000000,
  536. ISS_DPS14 = 0x40000000,
  537. ISS_DPS15 = 0x80000000,
  538. };
  539. /* CIE (R-Car Gen3 only) */
  540. enum CIE_BIT {
  541. CIE_CRIE = 0x00000001,
  542. CIE_CTIE = 0x00000100,
  543. CIE_RQFM = 0x00010000,
  544. CIE_CL0M = 0x00020000,
  545. CIE_RFWL = 0x00040000,
  546. CIE_RFFL = 0x00080000,
  547. };
  548. /* GCCR */
  549. enum GCCR_BIT {
  550. GCCR_TCR = 0x00000003,
  551. GCCR_TCR_NOREQ = 0x00000000, /* No request */
  552. GCCR_TCR_RESET = 0x00000001, /* gPTP/AVTP presentation timer reset */
  553. GCCR_TCR_CAPTURE = 0x00000003, /* Capture value set in GCCR.TCSS */
  554. GCCR_LTO = 0x00000004,
  555. GCCR_LTI = 0x00000008,
  556. GCCR_LPTC = 0x00000010,
  557. GCCR_LMTT = 0x00000020,
  558. GCCR_TCSS = 0x00000300,
  559. GCCR_TCSS_GPTP = 0x00000000, /* gPTP timer value */
  560. GCCR_TCSS_ADJGPTP = 0x00000100, /* Adjusted gPTP timer value */
  561. GCCR_TCSS_AVTP = 0x00000200, /* AVTP presentation time value */
  562. };
  563. /* GTI */
  564. enum GTI_BIT {
  565. GTI_TIV = 0x0FFFFFFF,
  566. };
  567. #define GTI_TIV_MAX GTI_TIV
  568. #define GTI_TIV_MIN 0x20
  569. /* GIC */
  570. enum GIC_BIT {
  571. GIC_PTCE = 0x00000001, /* Undocumented? */
  572. GIC_PTME = 0x00000004,
  573. };
  574. /* GIS */
  575. enum GIS_BIT {
  576. GIS_PTCF = 0x00000001, /* Undocumented? */
  577. GIS_PTMF = 0x00000004,
  578. GIS_RESERVED = GENMASK(15, 10),
  579. };
  580. /* GIE (R-Car Gen3 only) */
  581. enum GIE_BIT {
  582. GIE_PTCS = 0x00000001,
  583. GIE_PTOS = 0x00000002,
  584. GIE_PTMS0 = 0x00000004,
  585. GIE_PTMS1 = 0x00000008,
  586. GIE_PTMS2 = 0x00000010,
  587. GIE_PTMS3 = 0x00000020,
  588. GIE_PTMS4 = 0x00000040,
  589. GIE_PTMS5 = 0x00000080,
  590. GIE_PTMS6 = 0x00000100,
  591. GIE_PTMS7 = 0x00000200,
  592. GIE_ATCS0 = 0x00010000,
  593. GIE_ATCS1 = 0x00020000,
  594. GIE_ATCS2 = 0x00040000,
  595. GIE_ATCS3 = 0x00080000,
  596. GIE_ATCS4 = 0x00100000,
  597. GIE_ATCS5 = 0x00200000,
  598. GIE_ATCS6 = 0x00400000,
  599. GIE_ATCS7 = 0x00800000,
  600. GIE_ATCS8 = 0x01000000,
  601. GIE_ATCS9 = 0x02000000,
  602. GIE_ATCS10 = 0x04000000,
  603. GIE_ATCS11 = 0x08000000,
  604. GIE_ATCS12 = 0x10000000,
  605. GIE_ATCS13 = 0x20000000,
  606. GIE_ATCS14 = 0x40000000,
  607. GIE_ATCS15 = 0x80000000,
  608. };
  609. /* GID (R-Car Gen3 only) */
  610. enum GID_BIT {
  611. GID_PTCD = 0x00000001,
  612. GID_PTOD = 0x00000002,
  613. GID_PTMD0 = 0x00000004,
  614. GID_PTMD1 = 0x00000008,
  615. GID_PTMD2 = 0x00000010,
  616. GID_PTMD3 = 0x00000020,
  617. GID_PTMD4 = 0x00000040,
  618. GID_PTMD5 = 0x00000080,
  619. GID_PTMD6 = 0x00000100,
  620. GID_PTMD7 = 0x00000200,
  621. GID_ATCD0 = 0x00010000,
  622. GID_ATCD1 = 0x00020000,
  623. GID_ATCD2 = 0x00040000,
  624. GID_ATCD3 = 0x00080000,
  625. GID_ATCD4 = 0x00100000,
  626. GID_ATCD5 = 0x00200000,
  627. GID_ATCD6 = 0x00400000,
  628. GID_ATCD7 = 0x00800000,
  629. GID_ATCD8 = 0x01000000,
  630. GID_ATCD9 = 0x02000000,
  631. GID_ATCD10 = 0x04000000,
  632. GID_ATCD11 = 0x08000000,
  633. GID_ATCD12 = 0x10000000,
  634. GID_ATCD13 = 0x20000000,
  635. GID_ATCD14 = 0x40000000,
  636. GID_ATCD15 = 0x80000000,
  637. };
  638. /* RIE0 (R-Car Gen3 only) */
  639. enum RIE0_BIT {
  640. RIE0_FRS0 = 0x00000001,
  641. RIE0_FRS1 = 0x00000002,
  642. RIE0_FRS2 = 0x00000004,
  643. RIE0_FRS3 = 0x00000008,
  644. RIE0_FRS4 = 0x00000010,
  645. RIE0_FRS5 = 0x00000020,
  646. RIE0_FRS6 = 0x00000040,
  647. RIE0_FRS7 = 0x00000080,
  648. RIE0_FRS8 = 0x00000100,
  649. RIE0_FRS9 = 0x00000200,
  650. RIE0_FRS10 = 0x00000400,
  651. RIE0_FRS11 = 0x00000800,
  652. RIE0_FRS12 = 0x00001000,
  653. RIE0_FRS13 = 0x00002000,
  654. RIE0_FRS14 = 0x00004000,
  655. RIE0_FRS15 = 0x00008000,
  656. RIE0_FRS16 = 0x00010000,
  657. RIE0_FRS17 = 0x00020000,
  658. };
  659. /* RID0 (R-Car Gen3 only) */
  660. enum RID0_BIT {
  661. RID0_FRD0 = 0x00000001,
  662. RID0_FRD1 = 0x00000002,
  663. RID0_FRD2 = 0x00000004,
  664. RID0_FRD3 = 0x00000008,
  665. RID0_FRD4 = 0x00000010,
  666. RID0_FRD5 = 0x00000020,
  667. RID0_FRD6 = 0x00000040,
  668. RID0_FRD7 = 0x00000080,
  669. RID0_FRD8 = 0x00000100,
  670. RID0_FRD9 = 0x00000200,
  671. RID0_FRD10 = 0x00000400,
  672. RID0_FRD11 = 0x00000800,
  673. RID0_FRD12 = 0x00001000,
  674. RID0_FRD13 = 0x00002000,
  675. RID0_FRD14 = 0x00004000,
  676. RID0_FRD15 = 0x00008000,
  677. RID0_FRD16 = 0x00010000,
  678. RID0_FRD17 = 0x00020000,
  679. };
  680. /* RIE2 (R-Car Gen3 only) */
  681. enum RIE2_BIT {
  682. RIE2_QFS0 = 0x00000001,
  683. RIE2_QFS1 = 0x00000002,
  684. RIE2_QFS2 = 0x00000004,
  685. RIE2_QFS3 = 0x00000008,
  686. RIE2_QFS4 = 0x00000010,
  687. RIE2_QFS5 = 0x00000020,
  688. RIE2_QFS6 = 0x00000040,
  689. RIE2_QFS7 = 0x00000080,
  690. RIE2_QFS8 = 0x00000100,
  691. RIE2_QFS9 = 0x00000200,
  692. RIE2_QFS10 = 0x00000400,
  693. RIE2_QFS11 = 0x00000800,
  694. RIE2_QFS12 = 0x00001000,
  695. RIE2_QFS13 = 0x00002000,
  696. RIE2_QFS14 = 0x00004000,
  697. RIE2_QFS15 = 0x00008000,
  698. RIE2_QFS16 = 0x00010000,
  699. RIE2_QFS17 = 0x00020000,
  700. RIE2_RFFS = 0x80000000,
  701. };
  702. /* RID2 (R-Car Gen3 only) */
  703. enum RID2_BIT {
  704. RID2_QFD0 = 0x00000001,
  705. RID2_QFD1 = 0x00000002,
  706. RID2_QFD2 = 0x00000004,
  707. RID2_QFD3 = 0x00000008,
  708. RID2_QFD4 = 0x00000010,
  709. RID2_QFD5 = 0x00000020,
  710. RID2_QFD6 = 0x00000040,
  711. RID2_QFD7 = 0x00000080,
  712. RID2_QFD8 = 0x00000100,
  713. RID2_QFD9 = 0x00000200,
  714. RID2_QFD10 = 0x00000400,
  715. RID2_QFD11 = 0x00000800,
  716. RID2_QFD12 = 0x00001000,
  717. RID2_QFD13 = 0x00002000,
  718. RID2_QFD14 = 0x00004000,
  719. RID2_QFD15 = 0x00008000,
  720. RID2_QFD16 = 0x00010000,
  721. RID2_QFD17 = 0x00020000,
  722. RID2_RFFD = 0x80000000,
  723. };
  724. /* TIE (R-Car Gen3 only) */
  725. enum TIE_BIT {
  726. TIE_FTS0 = 0x00000001,
  727. TIE_FTS1 = 0x00000002,
  728. TIE_FTS2 = 0x00000004,
  729. TIE_FTS3 = 0x00000008,
  730. TIE_TFUS = 0x00000100,
  731. TIE_TFWS = 0x00000200,
  732. TIE_MFUS = 0x00000400,
  733. TIE_MFWS = 0x00000800,
  734. TIE_TDPS0 = 0x00010000,
  735. TIE_TDPS1 = 0x00020000,
  736. TIE_TDPS2 = 0x00040000,
  737. TIE_TDPS3 = 0x00080000,
  738. };
  739. /* TID (R-Car Gen3 only) */
  740. enum TID_BIT {
  741. TID_FTD0 = 0x00000001,
  742. TID_FTD1 = 0x00000002,
  743. TID_FTD2 = 0x00000004,
  744. TID_FTD3 = 0x00000008,
  745. TID_TFUD = 0x00000100,
  746. TID_TFWD = 0x00000200,
  747. TID_MFUD = 0x00000400,
  748. TID_MFWD = 0x00000800,
  749. TID_TDPD0 = 0x00010000,
  750. TID_TDPD1 = 0x00020000,
  751. TID_TDPD2 = 0x00040000,
  752. TID_TDPD3 = 0x00080000,
  753. };
  754. /* ECMR */
  755. enum ECMR_BIT {
  756. ECMR_PRM = 0x00000001,
  757. ECMR_DM = 0x00000002,
  758. ECMR_TE = 0x00000020,
  759. ECMR_RE = 0x00000040,
  760. ECMR_MPDE = 0x00000200,
  761. ECMR_TXF = 0x00010000, /* Undocumented? */
  762. ECMR_RXF = 0x00020000,
  763. ECMR_PFR = 0x00040000,
  764. ECMR_ZPF = 0x00080000, /* Undocumented? */
  765. ECMR_RZPF = 0x00100000,
  766. ECMR_DPAD = 0x00200000,
  767. ECMR_RCSC = 0x00800000,
  768. ECMR_TRCCM = 0x04000000,
  769. };
  770. /* ECSR */
  771. enum ECSR_BIT {
  772. ECSR_ICD = 0x00000001,
  773. ECSR_MPD = 0x00000002,
  774. ECSR_LCHNG = 0x00000004,
  775. ECSR_PHYI = 0x00000008,
  776. };
  777. /* ECSIPR */
  778. enum ECSIPR_BIT {
  779. ECSIPR_ICDIP = 0x00000001,
  780. ECSIPR_MPDIP = 0x00000002,
  781. ECSIPR_LCHNGIP = 0x00000004, /* Undocumented? */
  782. };
  783. /* PIR */
  784. enum PIR_BIT {
  785. PIR_MDC = 0x00000001,
  786. PIR_MMD = 0x00000002,
  787. PIR_MDO = 0x00000004,
  788. PIR_MDI = 0x00000008,
  789. };
  790. /* PSR */
  791. enum PSR_BIT {
  792. PSR_LMON = 0x00000001,
  793. };
  794. /* PIPR */
  795. enum PIPR_BIT {
  796. PIPR_PHYIP = 0x00000001,
  797. };
  798. /* MPR */
  799. enum MPR_BIT {
  800. MPR_MP = 0x0000ffff,
  801. };
  802. /* GECMR */
  803. enum GECMR_BIT {
  804. GECMR_SPEED = 0x00000001,
  805. GECMR_SPEED_100 = 0x00000000,
  806. GECMR_SPEED_1000 = 0x00000001,
  807. };
  808. /* The Ethernet AVB descriptor definitions. */
  809. struct ravb_desc {
  810. __le16 ds; /* Descriptor size */
  811. u8 cc; /* Content control MSBs (reserved) */
  812. u8 die_dt; /* Descriptor interrupt enable and type */
  813. __le32 dptr; /* Descriptor pointer */
  814. };
  815. #define DPTR_ALIGN 4 /* Required descriptor pointer alignment */
  816. enum DIE_DT {
  817. /* Frame data */
  818. DT_FMID = 0x40,
  819. DT_FSTART = 0x50,
  820. DT_FEND = 0x60,
  821. DT_FSINGLE = 0x70,
  822. /* Chain control */
  823. DT_LINK = 0x80,
  824. DT_LINKFIX = 0x90,
  825. DT_EOS = 0xa0,
  826. /* HW/SW arbitration */
  827. DT_FEMPTY = 0xc0,
  828. DT_FEMPTY_IS = 0xd0,
  829. DT_FEMPTY_IC = 0xe0,
  830. DT_FEMPTY_ND = 0xf0,
  831. DT_LEMPTY = 0x20,
  832. DT_EEMPTY = 0x30,
  833. };
  834. struct ravb_rx_desc {
  835. __le16 ds_cc; /* Descriptor size and content control LSBs */
  836. u8 msc; /* MAC status code */
  837. u8 die_dt; /* Descriptor interrupt enable and type */
  838. __le32 dptr; /* Descpriptor pointer */
  839. };
  840. struct ravb_ex_rx_desc {
  841. __le16 ds_cc; /* Descriptor size and content control lower bits */
  842. u8 msc; /* MAC status code */
  843. u8 die_dt; /* Descriptor interrupt enable and type */
  844. __le32 dptr; /* Descpriptor pointer */
  845. __le32 ts_n; /* Timestampe nsec */
  846. __le32 ts_sl; /* Timestamp low */
  847. __le16 ts_sh; /* Timestamp high */
  848. __le16 res; /* Reserved bits */
  849. };
  850. enum RX_DS_CC_BIT {
  851. RX_DS = 0x0fff, /* Data size */
  852. RX_TR = 0x1000, /* Truncation indication */
  853. RX_EI = 0x2000, /* Error indication */
  854. RX_PS = 0xc000, /* Padding selection */
  855. };
  856. /* E-MAC status code */
  857. enum MSC_BIT {
  858. MSC_CRC = 0x01, /* Frame CRC error */
  859. MSC_RFE = 0x02, /* Frame reception error (flagged by PHY) */
  860. MSC_RTSF = 0x04, /* Frame length error (frame too short) */
  861. MSC_RTLF = 0x08, /* Frame length error (frame too long) */
  862. MSC_FRE = 0x10, /* Fraction error (not a multiple of 8 bits) */
  863. MSC_CRL = 0x20, /* Carrier lost */
  864. MSC_CEEF = 0x40, /* Carrier extension error */
  865. MSC_MC = 0x80, /* Multicast frame reception */
  866. };
  867. struct ravb_tx_desc {
  868. __le16 ds_tagl; /* Descriptor size and frame tag LSBs */
  869. u8 tagh_tsr; /* Frame tag MSBs and timestamp storage request bit */
  870. u8 die_dt; /* Descriptor interrupt enable and type */
  871. __le32 dptr; /* Descpriptor pointer */
  872. };
  873. enum TX_DS_TAGL_BIT {
  874. TX_DS = 0x0fff, /* Data size */
  875. TX_TAGL = 0xf000, /* Frame tag LSBs */
  876. };
  877. enum TX_TAGH_TSR_BIT {
  878. TX_TAGH = 0x3f, /* Frame tag MSBs */
  879. TX_TSR = 0x40, /* Timestamp storage request */
  880. };
  881. enum RAVB_QUEUE {
  882. RAVB_BE = 0, /* Best Effort Queue */
  883. RAVB_NC, /* Network Control Queue */
  884. };
  885. #define DBAT_ENTRY_NUM 22
  886. #define RX_QUEUE_OFFSET 4
  887. #define NUM_RX_QUEUE 2
  888. #define NUM_TX_QUEUE 2
  889. #define NUM_TX_DESC 2 /* TX descriptors per packet */
  890. struct ravb_tstamp_skb {
  891. struct list_head list;
  892. struct sk_buff *skb;
  893. u16 tag;
  894. };
  895. struct ravb_ptp_perout {
  896. u32 target;
  897. u32 period;
  898. };
  899. #define N_EXT_TS 1
  900. #define N_PER_OUT 1
  901. struct ravb_ptp {
  902. struct ptp_clock *clock;
  903. struct ptp_clock_info info;
  904. u32 default_addend;
  905. u32 current_addend;
  906. int extts[N_EXT_TS];
  907. struct ravb_ptp_perout perout[N_PER_OUT];
  908. };
  909. enum ravb_chip_id {
  910. RCAR_GEN2,
  911. RCAR_GEN3,
  912. };
  913. struct ravb_private {
  914. struct net_device *ndev;
  915. struct platform_device *pdev;
  916. void __iomem *addr;
  917. struct clk *clk;
  918. struct mdiobb_ctrl mdiobb;
  919. u32 num_rx_ring[NUM_RX_QUEUE];
  920. u32 num_tx_ring[NUM_TX_QUEUE];
  921. u32 desc_bat_size;
  922. dma_addr_t desc_bat_dma;
  923. struct ravb_desc *desc_bat;
  924. dma_addr_t rx_desc_dma[NUM_RX_QUEUE];
  925. dma_addr_t tx_desc_dma[NUM_TX_QUEUE];
  926. struct ravb_ex_rx_desc *rx_ring[NUM_RX_QUEUE];
  927. struct ravb_tx_desc *tx_ring[NUM_TX_QUEUE];
  928. void *tx_align[NUM_TX_QUEUE];
  929. struct sk_buff **rx_skb[NUM_RX_QUEUE];
  930. struct sk_buff **tx_skb[NUM_TX_QUEUE];
  931. u32 rx_over_errors;
  932. u32 rx_fifo_errors;
  933. struct net_device_stats stats[NUM_RX_QUEUE];
  934. u32 tstamp_tx_ctrl;
  935. u32 tstamp_rx_ctrl;
  936. struct list_head ts_skb_list;
  937. u32 ts_skb_tag;
  938. struct ravb_ptp ptp;
  939. spinlock_t lock; /* Register access lock */
  940. u32 cur_rx[NUM_RX_QUEUE]; /* Consumer ring indices */
  941. u32 dirty_rx[NUM_RX_QUEUE]; /* Producer ring indices */
  942. u32 cur_tx[NUM_TX_QUEUE];
  943. u32 dirty_tx[NUM_TX_QUEUE];
  944. u32 rx_buf_sz; /* Based on MTU+slack. */
  945. struct napi_struct napi[NUM_RX_QUEUE];
  946. struct work_struct work;
  947. /* MII transceiver section. */
  948. struct mii_bus *mii_bus; /* MDIO bus control */
  949. int link;
  950. phy_interface_t phy_interface;
  951. int msg_enable;
  952. int speed;
  953. int emac_irq;
  954. enum ravb_chip_id chip_id;
  955. int rx_irqs[NUM_RX_QUEUE];
  956. int tx_irqs[NUM_TX_QUEUE];
  957. unsigned no_avb_link:1;
  958. unsigned avb_link_active_low:1;
  959. unsigned wol_enabled:1;
  960. };
  961. static inline u32 ravb_read(struct net_device *ndev, enum ravb_reg reg)
  962. {
  963. struct ravb_private *priv = netdev_priv(ndev);
  964. return ioread32(priv->addr + reg);
  965. }
  966. static inline void ravb_write(struct net_device *ndev, u32 data,
  967. enum ravb_reg reg)
  968. {
  969. struct ravb_private *priv = netdev_priv(ndev);
  970. iowrite32(data, priv->addr + reg);
  971. }
  972. void ravb_modify(struct net_device *ndev, enum ravb_reg reg, u32 clear,
  973. u32 set);
  974. int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value);
  975. void ravb_ptp_interrupt(struct net_device *ndev);
  976. void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev);
  977. void ravb_ptp_stop(struct net_device *ndev);
  978. #endif /* #ifndef __RAVB_H__ */