ravb.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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 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. GCCR = 0x0390,
  153. GMTT = 0x0394,
  154. GPTC = 0x0398,
  155. GTI = 0x039C,
  156. GTO0 = 0x03A0,
  157. GTO1 = 0x03A4,
  158. GTO2 = 0x03A8,
  159. GIC = 0x03AC,
  160. GIS = 0x03B0,
  161. GCPT = 0x03B4, /* Undocumented? */
  162. GCT0 = 0x03B8,
  163. GCT1 = 0x03BC,
  164. GCT2 = 0x03C0,
  165. /* E-MAC registers */
  166. ECMR = 0x0500,
  167. RFLR = 0x0508,
  168. ECSR = 0x0510,
  169. ECSIPR = 0x0518,
  170. PIR = 0x0520,
  171. PSR = 0x0528,
  172. PIPR = 0x052c,
  173. MPR = 0x0558,
  174. PFTCR = 0x055c,
  175. PFRCR = 0x0560,
  176. GECMR = 0x05b0,
  177. MAHR = 0x05c0,
  178. MALR = 0x05c8,
  179. TROCR = 0x0700, /* Undocumented? */
  180. CDCR = 0x0708, /* Undocumented? */
  181. LCCR = 0x0710, /* Undocumented? */
  182. CEFCR = 0x0740,
  183. FRECR = 0x0748,
  184. TSFRCR = 0x0750,
  185. TLFRCR = 0x0758,
  186. RFCR = 0x0760,
  187. CERCR = 0x0768, /* Undocumented? */
  188. CEECR = 0x0770, /* Undocumented? */
  189. MAFCR = 0x0778,
  190. };
  191. /* Register bits of the Ethernet AVB */
  192. /* CCC */
  193. enum CCC_BIT {
  194. CCC_OPC = 0x00000003,
  195. CCC_OPC_RESET = 0x00000000,
  196. CCC_OPC_CONFIG = 0x00000001,
  197. CCC_OPC_OPERATION = 0x00000002,
  198. CCC_DTSR = 0x00000100,
  199. CCC_CSEL = 0x00030000,
  200. CCC_CSEL_HPB = 0x00010000,
  201. CCC_CSEL_ETH_TX = 0x00020000,
  202. CCC_CSEL_GMII_REF = 0x00030000,
  203. CCC_BOC = 0x00100000, /* Undocumented? */
  204. CCC_LBME = 0x01000000,
  205. };
  206. /* CSR */
  207. enum CSR_BIT {
  208. CSR_OPS = 0x0000000F,
  209. CSR_OPS_RESET = 0x00000001,
  210. CSR_OPS_CONFIG = 0x00000002,
  211. CSR_OPS_OPERATION = 0x00000004,
  212. CSR_OPS_STANDBY = 0x00000008, /* Undocumented? */
  213. CSR_DTS = 0x00000100,
  214. CSR_TPO0 = 0x00010000,
  215. CSR_TPO1 = 0x00020000,
  216. CSR_TPO2 = 0x00040000,
  217. CSR_TPO3 = 0x00080000,
  218. CSR_RPO = 0x00100000,
  219. };
  220. /* ESR */
  221. enum ESR_BIT {
  222. ESR_EQN = 0x0000001F,
  223. ESR_ET = 0x00000F00,
  224. ESR_EIL = 0x00001000,
  225. };
  226. /* RCR */
  227. enum RCR_BIT {
  228. RCR_EFFS = 0x00000001,
  229. RCR_ENCF = 0x00000002,
  230. RCR_ESF = 0x0000000C,
  231. RCR_ETS0 = 0x00000010,
  232. RCR_ETS2 = 0x00000020,
  233. RCR_RFCL = 0x1FFF0000,
  234. };
  235. /* RQC0/1/2/3/4 */
  236. enum RQC_BIT {
  237. RQC_RSM0 = 0x00000003,
  238. RQC_UFCC0 = 0x00000030,
  239. RQC_RSM1 = 0x00000300,
  240. RQC_UFCC1 = 0x00003000,
  241. RQC_RSM2 = 0x00030000,
  242. RQC_UFCC2 = 0x00300000,
  243. RQC_RSM3 = 0x03000000,
  244. RQC_UFCC3 = 0x30000000,
  245. };
  246. /* RPC */
  247. enum RPC_BIT {
  248. RPC_PCNT = 0x00000700,
  249. RPC_DCNT = 0x00FF0000,
  250. };
  251. /* UFCW */
  252. enum UFCW_BIT {
  253. UFCW_WL0 = 0x0000003F,
  254. UFCW_WL1 = 0x00003F00,
  255. UFCW_WL2 = 0x003F0000,
  256. UFCW_WL3 = 0x3F000000,
  257. };
  258. /* UFCS */
  259. enum UFCS_BIT {
  260. UFCS_SL0 = 0x0000003F,
  261. UFCS_SL1 = 0x00003F00,
  262. UFCS_SL2 = 0x003F0000,
  263. UFCS_SL3 = 0x3F000000,
  264. };
  265. /* UFCV0/1/2/3/4 */
  266. enum UFCV_BIT {
  267. UFCV_CV0 = 0x0000003F,
  268. UFCV_CV1 = 0x00003F00,
  269. UFCV_CV2 = 0x003F0000,
  270. UFCV_CV3 = 0x3F000000,
  271. };
  272. /* UFCD0/1/2/3/4 */
  273. enum UFCD_BIT {
  274. UFCD_DV0 = 0x0000003F,
  275. UFCD_DV1 = 0x00003F00,
  276. UFCD_DV2 = 0x003F0000,
  277. UFCD_DV3 = 0x3F000000,
  278. };
  279. /* SFO */
  280. enum SFO_BIT {
  281. SFO_FPB = 0x0000003F,
  282. };
  283. /* RTC */
  284. enum RTC_BIT {
  285. RTC_MFL0 = 0x00000FFF,
  286. RTC_MFL1 = 0x0FFF0000,
  287. };
  288. /* TGC */
  289. enum TGC_BIT {
  290. TGC_TSM0 = 0x00000001,
  291. TGC_TSM1 = 0x00000002,
  292. TGC_TSM2 = 0x00000004,
  293. TGC_TSM3 = 0x00000008,
  294. TGC_TQP = 0x00000030,
  295. TGC_TQP_NONAVB = 0x00000000,
  296. TGC_TQP_AVBMODE1 = 0x00000010,
  297. TGC_TQP_AVBMODE2 = 0x00000030,
  298. TGC_TBD0 = 0x00000300,
  299. TGC_TBD1 = 0x00003000,
  300. TGC_TBD2 = 0x00030000,
  301. TGC_TBD3 = 0x00300000,
  302. };
  303. /* TCCR */
  304. enum TCCR_BIT {
  305. TCCR_TSRQ0 = 0x00000001,
  306. TCCR_TSRQ1 = 0x00000002,
  307. TCCR_TSRQ2 = 0x00000004,
  308. TCCR_TSRQ3 = 0x00000008,
  309. TCCR_TFEN = 0x00000100,
  310. TCCR_TFR = 0x00000200,
  311. };
  312. /* TSR */
  313. enum TSR_BIT {
  314. TSR_CCS0 = 0x00000003,
  315. TSR_CCS1 = 0x0000000C,
  316. TSR_TFFL = 0x00000700,
  317. };
  318. /* TFA2 */
  319. enum TFA2_BIT {
  320. TFA2_TSV = 0x0000FFFF,
  321. TFA2_TST = 0x03FF0000,
  322. };
  323. /* DIC */
  324. enum DIC_BIT {
  325. DIC_DPE1 = 0x00000002,
  326. DIC_DPE2 = 0x00000004,
  327. DIC_DPE3 = 0x00000008,
  328. DIC_DPE4 = 0x00000010,
  329. DIC_DPE5 = 0x00000020,
  330. DIC_DPE6 = 0x00000040,
  331. DIC_DPE7 = 0x00000080,
  332. DIC_DPE8 = 0x00000100,
  333. DIC_DPE9 = 0x00000200,
  334. DIC_DPE10 = 0x00000400,
  335. DIC_DPE11 = 0x00000800,
  336. DIC_DPE12 = 0x00001000,
  337. DIC_DPE13 = 0x00002000,
  338. DIC_DPE14 = 0x00004000,
  339. DIC_DPE15 = 0x00008000,
  340. };
  341. /* DIS */
  342. enum DIS_BIT {
  343. DIS_DPF1 = 0x00000002,
  344. DIS_DPF2 = 0x00000004,
  345. DIS_DPF3 = 0x00000008,
  346. DIS_DPF4 = 0x00000010,
  347. DIS_DPF5 = 0x00000020,
  348. DIS_DPF6 = 0x00000040,
  349. DIS_DPF7 = 0x00000080,
  350. DIS_DPF8 = 0x00000100,
  351. DIS_DPF9 = 0x00000200,
  352. DIS_DPF10 = 0x00000400,
  353. DIS_DPF11 = 0x00000800,
  354. DIS_DPF12 = 0x00001000,
  355. DIS_DPF13 = 0x00002000,
  356. DIS_DPF14 = 0x00004000,
  357. DIS_DPF15 = 0x00008000,
  358. };
  359. /* EIC */
  360. enum EIC_BIT {
  361. EIC_MREE = 0x00000001,
  362. EIC_MTEE = 0x00000002,
  363. EIC_QEE = 0x00000004,
  364. EIC_SEE = 0x00000008,
  365. EIC_CLLE0 = 0x00000010,
  366. EIC_CLLE1 = 0x00000020,
  367. EIC_CULE0 = 0x00000040,
  368. EIC_CULE1 = 0x00000080,
  369. EIC_TFFE = 0x00000100,
  370. };
  371. /* EIS */
  372. enum EIS_BIT {
  373. EIS_MREF = 0x00000001,
  374. EIS_MTEF = 0x00000002,
  375. EIS_QEF = 0x00000004,
  376. EIS_SEF = 0x00000008,
  377. EIS_CLLF0 = 0x00000010,
  378. EIS_CLLF1 = 0x00000020,
  379. EIS_CULF0 = 0x00000040,
  380. EIS_CULF1 = 0x00000080,
  381. EIS_TFFF = 0x00000100,
  382. EIS_QFS = 0x00010000,
  383. };
  384. /* RIC0 */
  385. enum RIC0_BIT {
  386. RIC0_FRE0 = 0x00000001,
  387. RIC0_FRE1 = 0x00000002,
  388. RIC0_FRE2 = 0x00000004,
  389. RIC0_FRE3 = 0x00000008,
  390. RIC0_FRE4 = 0x00000010,
  391. RIC0_FRE5 = 0x00000020,
  392. RIC0_FRE6 = 0x00000040,
  393. RIC0_FRE7 = 0x00000080,
  394. RIC0_FRE8 = 0x00000100,
  395. RIC0_FRE9 = 0x00000200,
  396. RIC0_FRE10 = 0x00000400,
  397. RIC0_FRE11 = 0x00000800,
  398. RIC0_FRE12 = 0x00001000,
  399. RIC0_FRE13 = 0x00002000,
  400. RIC0_FRE14 = 0x00004000,
  401. RIC0_FRE15 = 0x00008000,
  402. RIC0_FRE16 = 0x00010000,
  403. RIC0_FRE17 = 0x00020000,
  404. };
  405. /* RIC0 */
  406. enum RIS0_BIT {
  407. RIS0_FRF0 = 0x00000001,
  408. RIS0_FRF1 = 0x00000002,
  409. RIS0_FRF2 = 0x00000004,
  410. RIS0_FRF3 = 0x00000008,
  411. RIS0_FRF4 = 0x00000010,
  412. RIS0_FRF5 = 0x00000020,
  413. RIS0_FRF6 = 0x00000040,
  414. RIS0_FRF7 = 0x00000080,
  415. RIS0_FRF8 = 0x00000100,
  416. RIS0_FRF9 = 0x00000200,
  417. RIS0_FRF10 = 0x00000400,
  418. RIS0_FRF11 = 0x00000800,
  419. RIS0_FRF12 = 0x00001000,
  420. RIS0_FRF13 = 0x00002000,
  421. RIS0_FRF14 = 0x00004000,
  422. RIS0_FRF15 = 0x00008000,
  423. RIS0_FRF16 = 0x00010000,
  424. RIS0_FRF17 = 0x00020000,
  425. };
  426. /* RIC1 */
  427. enum RIC1_BIT {
  428. RIC1_RFWE = 0x80000000,
  429. };
  430. /* RIS1 */
  431. enum RIS1_BIT {
  432. RIS1_RFWF = 0x80000000,
  433. };
  434. /* RIC2 */
  435. enum RIC2_BIT {
  436. RIC2_QFE0 = 0x00000001,
  437. RIC2_QFE1 = 0x00000002,
  438. RIC2_QFE2 = 0x00000004,
  439. RIC2_QFE3 = 0x00000008,
  440. RIC2_QFE4 = 0x00000010,
  441. RIC2_QFE5 = 0x00000020,
  442. RIC2_QFE6 = 0x00000040,
  443. RIC2_QFE7 = 0x00000080,
  444. RIC2_QFE8 = 0x00000100,
  445. RIC2_QFE9 = 0x00000200,
  446. RIC2_QFE10 = 0x00000400,
  447. RIC2_QFE11 = 0x00000800,
  448. RIC2_QFE12 = 0x00001000,
  449. RIC2_QFE13 = 0x00002000,
  450. RIC2_QFE14 = 0x00004000,
  451. RIC2_QFE15 = 0x00008000,
  452. RIC2_QFE16 = 0x00010000,
  453. RIC2_QFE17 = 0x00020000,
  454. RIC2_RFFE = 0x80000000,
  455. };
  456. /* RIS2 */
  457. enum RIS2_BIT {
  458. RIS2_QFF0 = 0x00000001,
  459. RIS2_QFF1 = 0x00000002,
  460. RIS2_QFF2 = 0x00000004,
  461. RIS2_QFF3 = 0x00000008,
  462. RIS2_QFF4 = 0x00000010,
  463. RIS2_QFF5 = 0x00000020,
  464. RIS2_QFF6 = 0x00000040,
  465. RIS2_QFF7 = 0x00000080,
  466. RIS2_QFF8 = 0x00000100,
  467. RIS2_QFF9 = 0x00000200,
  468. RIS2_QFF10 = 0x00000400,
  469. RIS2_QFF11 = 0x00000800,
  470. RIS2_QFF12 = 0x00001000,
  471. RIS2_QFF13 = 0x00002000,
  472. RIS2_QFF14 = 0x00004000,
  473. RIS2_QFF15 = 0x00008000,
  474. RIS2_QFF16 = 0x00010000,
  475. RIS2_QFF17 = 0x00020000,
  476. RIS2_RFFF = 0x80000000,
  477. };
  478. /* TIC */
  479. enum TIC_BIT {
  480. TIC_FTE0 = 0x00000001, /* Undocumented? */
  481. TIC_FTE1 = 0x00000002, /* Undocumented? */
  482. TIC_TFUE = 0x00000100,
  483. TIC_TFWE = 0x00000200,
  484. };
  485. /* TIS */
  486. enum TIS_BIT {
  487. TIS_FTF0 = 0x00000001, /* Undocumented? */
  488. TIS_FTF1 = 0x00000002, /* Undocumented? */
  489. TIS_TFUF = 0x00000100,
  490. TIS_TFWF = 0x00000200,
  491. };
  492. /* ISS */
  493. enum ISS_BIT {
  494. ISS_FRS = 0x00000001, /* Undocumented? */
  495. ISS_FTS = 0x00000004, /* Undocumented? */
  496. ISS_ES = 0x00000040,
  497. ISS_MS = 0x00000080,
  498. ISS_TFUS = 0x00000100,
  499. ISS_TFWS = 0x00000200,
  500. ISS_RFWS = 0x00001000,
  501. ISS_CGIS = 0x00002000,
  502. ISS_DPS1 = 0x00020000,
  503. ISS_DPS2 = 0x00040000,
  504. ISS_DPS3 = 0x00080000,
  505. ISS_DPS4 = 0x00100000,
  506. ISS_DPS5 = 0x00200000,
  507. ISS_DPS6 = 0x00400000,
  508. ISS_DPS7 = 0x00800000,
  509. ISS_DPS8 = 0x01000000,
  510. ISS_DPS9 = 0x02000000,
  511. ISS_DPS10 = 0x04000000,
  512. ISS_DPS11 = 0x08000000,
  513. ISS_DPS12 = 0x10000000,
  514. ISS_DPS13 = 0x20000000,
  515. ISS_DPS14 = 0x40000000,
  516. ISS_DPS15 = 0x80000000,
  517. };
  518. /* GCCR */
  519. enum GCCR_BIT {
  520. GCCR_TCR = 0x00000003,
  521. GCCR_TCR_NOREQ = 0x00000000, /* No request */
  522. GCCR_TCR_RESET = 0x00000001, /* gPTP/AVTP presentation timer reset */
  523. GCCR_TCR_CAPTURE = 0x00000003, /* Capture value set in GCCR.TCSS */
  524. GCCR_LTO = 0x00000004,
  525. GCCR_LTI = 0x00000008,
  526. GCCR_LPTC = 0x00000010,
  527. GCCR_LMTT = 0x00000020,
  528. GCCR_TCSS = 0x00000300,
  529. GCCR_TCSS_GPTP = 0x00000000, /* gPTP timer value */
  530. GCCR_TCSS_ADJGPTP = 0x00000100, /* Adjusted gPTP timer value */
  531. GCCR_TCSS_AVTP = 0x00000200, /* AVTP presentation time value */
  532. };
  533. /* GTI */
  534. enum GTI_BIT {
  535. GTI_TIV = 0x0FFFFFFF,
  536. };
  537. /* GIC */
  538. enum GIC_BIT {
  539. GIC_PTCE = 0x00000001, /* Undocumented? */
  540. GIC_PTME = 0x00000004,
  541. };
  542. /* GIS */
  543. enum GIS_BIT {
  544. GIS_PTCF = 0x00000001, /* Undocumented? */
  545. GIS_PTMF = 0x00000004,
  546. };
  547. /* ECMR */
  548. enum ECMR_BIT {
  549. ECMR_PRM = 0x00000001,
  550. ECMR_DM = 0x00000002,
  551. ECMR_TE = 0x00000020,
  552. ECMR_RE = 0x00000040,
  553. ECMR_MPDE = 0x00000200,
  554. ECMR_TXF = 0x00010000, /* Undocumented? */
  555. ECMR_RXF = 0x00020000,
  556. ECMR_PFR = 0x00040000,
  557. ECMR_ZPF = 0x00080000, /* Undocumented? */
  558. ECMR_RZPF = 0x00100000,
  559. ECMR_DPAD = 0x00200000,
  560. ECMR_RCSC = 0x00800000,
  561. ECMR_TRCCM = 0x04000000,
  562. };
  563. /* ECSR */
  564. enum ECSR_BIT {
  565. ECSR_ICD = 0x00000001,
  566. ECSR_MPD = 0x00000002,
  567. ECSR_LCHNG = 0x00000004,
  568. ECSR_PHYI = 0x00000008,
  569. };
  570. /* ECSIPR */
  571. enum ECSIPR_BIT {
  572. ECSIPR_ICDIP = 0x00000001,
  573. ECSIPR_MPDIP = 0x00000002,
  574. ECSIPR_LCHNGIP = 0x00000004, /* Undocumented? */
  575. };
  576. /* PIR */
  577. enum PIR_BIT {
  578. PIR_MDC = 0x00000001,
  579. PIR_MMD = 0x00000002,
  580. PIR_MDO = 0x00000004,
  581. PIR_MDI = 0x00000008,
  582. };
  583. /* PSR */
  584. enum PSR_BIT {
  585. PSR_LMON = 0x00000001,
  586. };
  587. /* PIPR */
  588. enum PIPR_BIT {
  589. PIPR_PHYIP = 0x00000001,
  590. };
  591. /* MPR */
  592. enum MPR_BIT {
  593. MPR_MP = 0x0000ffff,
  594. };
  595. /* GECMR */
  596. enum GECMR_BIT {
  597. GECMR_SPEED = 0x00000001,
  598. GECMR_SPEED_100 = 0x00000000,
  599. GECMR_SPEED_1000 = 0x00000001,
  600. };
  601. /* The Ethernet AVB descriptor definitions. */
  602. struct ravb_desc {
  603. __le16 ds; /* Descriptor size */
  604. u8 cc; /* Content control MSBs (reserved) */
  605. u8 die_dt; /* Descriptor interrupt enable and type */
  606. __le32 dptr; /* Descriptor pointer */
  607. };
  608. #define DPTR_ALIGN 4 /* Required descriptor pointer alignment */
  609. enum DIE_DT {
  610. /* Frame data */
  611. DT_FMID = 0x40,
  612. DT_FSTART = 0x50,
  613. DT_FEND = 0x60,
  614. DT_FSINGLE = 0x70,
  615. /* Chain control */
  616. DT_LINK = 0x80,
  617. DT_LINKFIX = 0x90,
  618. DT_EOS = 0xa0,
  619. /* HW/SW arbitration */
  620. DT_FEMPTY = 0xc0,
  621. DT_FEMPTY_IS = 0xd0,
  622. DT_FEMPTY_IC = 0xe0,
  623. DT_FEMPTY_ND = 0xf0,
  624. DT_LEMPTY = 0x20,
  625. DT_EEMPTY = 0x30,
  626. };
  627. struct ravb_rx_desc {
  628. __le16 ds_cc; /* Descriptor size and content control LSBs */
  629. u8 msc; /* MAC status code */
  630. u8 die_dt; /* Descriptor interrupt enable and type */
  631. __le32 dptr; /* Descpriptor pointer */
  632. };
  633. struct ravb_ex_rx_desc {
  634. __le16 ds_cc; /* Descriptor size and content control lower bits */
  635. u8 msc; /* MAC status code */
  636. u8 die_dt; /* Descriptor interrupt enable and type */
  637. __le32 dptr; /* Descpriptor pointer */
  638. __le32 ts_n; /* Timestampe nsec */
  639. __le32 ts_sl; /* Timestamp low */
  640. __le16 ts_sh; /* Timestamp high */
  641. __le16 res; /* Reserved bits */
  642. };
  643. enum RX_DS_CC_BIT {
  644. RX_DS = 0x0fff, /* Data size */
  645. RX_TR = 0x1000, /* Truncation indication */
  646. RX_EI = 0x2000, /* Error indication */
  647. RX_PS = 0xc000, /* Padding selection */
  648. };
  649. /* E-MAC status code */
  650. enum MSC_BIT {
  651. MSC_CRC = 0x01, /* Frame CRC error */
  652. MSC_RFE = 0x02, /* Frame reception error (flagged by PHY) */
  653. MSC_RTSF = 0x04, /* Frame length error (frame too short) */
  654. MSC_RTLF = 0x08, /* Frame length error (frame too long) */
  655. MSC_FRE = 0x10, /* Fraction error (not a multiple of 8 bits) */
  656. MSC_CRL = 0x20, /* Carrier lost */
  657. MSC_CEEF = 0x40, /* Carrier extension error */
  658. MSC_MC = 0x80, /* Multicast frame reception */
  659. };
  660. struct ravb_tx_desc {
  661. __le16 ds_tagl; /* Descriptor size and frame tag LSBs */
  662. u8 tagh_tsr; /* Frame tag MSBs and timestamp storage request bit */
  663. u8 die_dt; /* Descriptor interrupt enable and type */
  664. __le32 dptr; /* Descpriptor pointer */
  665. };
  666. enum TX_DS_TAGL_BIT {
  667. TX_DS = 0x0fff, /* Data size */
  668. TX_TAGL = 0xf000, /* Frame tag LSBs */
  669. };
  670. enum TX_TAGH_TSR_BIT {
  671. TX_TAGH = 0x3f, /* Frame tag MSBs */
  672. TX_TSR = 0x40, /* Timestamp storage request */
  673. };
  674. enum RAVB_QUEUE {
  675. RAVB_BE = 0, /* Best Effort Queue */
  676. RAVB_NC, /* Network Control Queue */
  677. };
  678. #define DBAT_ENTRY_NUM 22
  679. #define RX_QUEUE_OFFSET 4
  680. #define NUM_RX_QUEUE 2
  681. #define NUM_TX_QUEUE 2
  682. #define NUM_TX_DESC 2 /* TX descriptors per packet */
  683. struct ravb_tstamp_skb {
  684. struct list_head list;
  685. struct sk_buff *skb;
  686. u16 tag;
  687. };
  688. struct ravb_ptp_perout {
  689. u32 target;
  690. u32 period;
  691. };
  692. #define N_EXT_TS 1
  693. #define N_PER_OUT 1
  694. struct ravb_ptp {
  695. struct ptp_clock *clock;
  696. struct ptp_clock_info info;
  697. u32 default_addend;
  698. u32 current_addend;
  699. int extts[N_EXT_TS];
  700. struct ravb_ptp_perout perout[N_PER_OUT];
  701. };
  702. enum ravb_chip_id {
  703. RCAR_GEN2,
  704. RCAR_GEN3,
  705. };
  706. struct ravb_private {
  707. struct net_device *ndev;
  708. struct platform_device *pdev;
  709. void __iomem *addr;
  710. struct mdiobb_ctrl mdiobb;
  711. u32 num_rx_ring[NUM_RX_QUEUE];
  712. u32 num_tx_ring[NUM_TX_QUEUE];
  713. u32 desc_bat_size;
  714. dma_addr_t desc_bat_dma;
  715. struct ravb_desc *desc_bat;
  716. dma_addr_t rx_desc_dma[NUM_RX_QUEUE];
  717. dma_addr_t tx_desc_dma[NUM_TX_QUEUE];
  718. struct ravb_ex_rx_desc *rx_ring[NUM_RX_QUEUE];
  719. struct ravb_tx_desc *tx_ring[NUM_TX_QUEUE];
  720. void *tx_align[NUM_TX_QUEUE];
  721. struct sk_buff **rx_skb[NUM_RX_QUEUE];
  722. struct sk_buff **tx_skb[NUM_TX_QUEUE];
  723. u32 rx_over_errors;
  724. u32 rx_fifo_errors;
  725. struct net_device_stats stats[NUM_RX_QUEUE];
  726. u32 tstamp_tx_ctrl;
  727. u32 tstamp_rx_ctrl;
  728. struct list_head ts_skb_list;
  729. u32 ts_skb_tag;
  730. struct ravb_ptp ptp;
  731. spinlock_t lock; /* Register access lock */
  732. u32 cur_rx[NUM_RX_QUEUE]; /* Consumer ring indices */
  733. u32 dirty_rx[NUM_RX_QUEUE]; /* Producer ring indices */
  734. u32 cur_tx[NUM_TX_QUEUE];
  735. u32 dirty_tx[NUM_TX_QUEUE];
  736. struct napi_struct napi[NUM_RX_QUEUE];
  737. struct work_struct work;
  738. /* MII transceiver section. */
  739. struct mii_bus *mii_bus; /* MDIO bus control */
  740. struct phy_device *phydev; /* PHY device control */
  741. int link;
  742. phy_interface_t phy_interface;
  743. int msg_enable;
  744. int speed;
  745. int duplex;
  746. int emac_irq;
  747. enum ravb_chip_id chip_id;
  748. unsigned no_avb_link:1;
  749. unsigned avb_link_active_low:1;
  750. };
  751. static inline u32 ravb_read(struct net_device *ndev, enum ravb_reg reg)
  752. {
  753. struct ravb_private *priv = netdev_priv(ndev);
  754. return ioread32(priv->addr + reg);
  755. }
  756. static inline void ravb_write(struct net_device *ndev, u32 data,
  757. enum ravb_reg reg)
  758. {
  759. struct ravb_private *priv = netdev_priv(ndev);
  760. iowrite32(data, priv->addr + reg);
  761. }
  762. int ravb_wait(struct net_device *ndev, enum ravb_reg reg, u32 mask, u32 value);
  763. irqreturn_t ravb_ptp_interrupt(struct net_device *ndev);
  764. void ravb_ptp_init(struct net_device *ndev, struct platform_device *pdev);
  765. void ravb_ptp_stop(struct net_device *ndev);
  766. #endif /* #ifndef __RAVB_H__ */