ravb.h 22 KB

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