sh_eth.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. /*
  2. * SuperH Ethernet device driver
  3. *
  4. * Copyright (C) 2006-2012 Nobuhiro Iwamatsu
  5. * Copyright (C) 2008-2012 Renesas Solutions Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. */
  22. #ifndef __SH_ETH_H__
  23. #define __SH_ETH_H__
  24. #define CARDNAME "sh-eth"
  25. #define TX_TIMEOUT (5*HZ)
  26. #define TX_RING_SIZE 64 /* Tx ring size */
  27. #define RX_RING_SIZE 64 /* Rx ring size */
  28. #define ETHERSMALL 60
  29. #define PKT_BUF_SZ 1538
  30. #define SH_ETH_TSU_TIMEOUT_MS 500
  31. #define SH_ETH_TSU_CAM_ENTRIES 32
  32. enum {
  33. /* E-DMAC registers */
  34. EDSR = 0,
  35. EDMR,
  36. EDTRR,
  37. EDRRR,
  38. EESR,
  39. EESIPR,
  40. TDLAR,
  41. TDFAR,
  42. TDFXR,
  43. TDFFR,
  44. RDLAR,
  45. RDFAR,
  46. RDFXR,
  47. RDFFR,
  48. TRSCER,
  49. RMFCR,
  50. TFTR,
  51. FDR,
  52. RMCR,
  53. EDOCR,
  54. TFUCR,
  55. RFOCR,
  56. FCFTR,
  57. RPADIR,
  58. TRIMD,
  59. RBWAR,
  60. TBRAR,
  61. /* Ether registers */
  62. ECMR,
  63. ECSR,
  64. ECSIPR,
  65. PIR,
  66. PSR,
  67. RDMLR,
  68. PIPR,
  69. RFLR,
  70. IPGR,
  71. APR,
  72. MPR,
  73. PFTCR,
  74. PFRCR,
  75. RFCR,
  76. RFCF,
  77. TPAUSER,
  78. TPAUSECR,
  79. BCFR,
  80. BCFRR,
  81. GECMR,
  82. BCULR,
  83. MAHR,
  84. MALR,
  85. TROCR,
  86. CDCR,
  87. LCCR,
  88. CNDCR,
  89. CEFCR,
  90. FRECR,
  91. TSFRCR,
  92. TLFRCR,
  93. CERCR,
  94. CEECR,
  95. MAFCR,
  96. RTRATE,
  97. CSMR,
  98. RMII_MII,
  99. /* TSU Absolute address */
  100. ARSTR,
  101. TSU_CTRST,
  102. TSU_FWEN0,
  103. TSU_FWEN1,
  104. TSU_FCM,
  105. TSU_BSYSL0,
  106. TSU_BSYSL1,
  107. TSU_PRISL0,
  108. TSU_PRISL1,
  109. TSU_FWSL0,
  110. TSU_FWSL1,
  111. TSU_FWSLC,
  112. TSU_QTAG0,
  113. TSU_QTAG1,
  114. TSU_QTAGM0,
  115. TSU_QTAGM1,
  116. TSU_FWSR,
  117. TSU_FWINMK,
  118. TSU_ADQT0,
  119. TSU_ADQT1,
  120. TSU_VTAG0,
  121. TSU_VTAG1,
  122. TSU_ADSBSY,
  123. TSU_TEN,
  124. TSU_POST1,
  125. TSU_POST2,
  126. TSU_POST3,
  127. TSU_POST4,
  128. TSU_ADRH0,
  129. TSU_ADRL0,
  130. TSU_ADRH31,
  131. TSU_ADRL31,
  132. TXNLCR0,
  133. TXALCR0,
  134. RXNLCR0,
  135. RXALCR0,
  136. FWNLCR0,
  137. FWALCR0,
  138. TXNLCR1,
  139. TXALCR1,
  140. RXNLCR1,
  141. RXALCR1,
  142. FWNLCR1,
  143. FWALCR1,
  144. /* This value must be written at last. */
  145. SH_ETH_MAX_REGISTER_OFFSET,
  146. };
  147. static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = {
  148. [EDSR] = 0x0000,
  149. [EDMR] = 0x0400,
  150. [EDTRR] = 0x0408,
  151. [EDRRR] = 0x0410,
  152. [EESR] = 0x0428,
  153. [EESIPR] = 0x0430,
  154. [TDLAR] = 0x0010,
  155. [TDFAR] = 0x0014,
  156. [TDFXR] = 0x0018,
  157. [TDFFR] = 0x001c,
  158. [RDLAR] = 0x0030,
  159. [RDFAR] = 0x0034,
  160. [RDFXR] = 0x0038,
  161. [RDFFR] = 0x003c,
  162. [TRSCER] = 0x0438,
  163. [RMFCR] = 0x0440,
  164. [TFTR] = 0x0448,
  165. [FDR] = 0x0450,
  166. [RMCR] = 0x0458,
  167. [RPADIR] = 0x0460,
  168. [FCFTR] = 0x0468,
  169. [CSMR] = 0x04E4,
  170. [ECMR] = 0x0500,
  171. [ECSR] = 0x0510,
  172. [ECSIPR] = 0x0518,
  173. [PIR] = 0x0520,
  174. [PSR] = 0x0528,
  175. [PIPR] = 0x052c,
  176. [RFLR] = 0x0508,
  177. [APR] = 0x0554,
  178. [MPR] = 0x0558,
  179. [PFTCR] = 0x055c,
  180. [PFRCR] = 0x0560,
  181. [TPAUSER] = 0x0564,
  182. [GECMR] = 0x05b0,
  183. [BCULR] = 0x05b4,
  184. [MAHR] = 0x05c0,
  185. [MALR] = 0x05c8,
  186. [TROCR] = 0x0700,
  187. [CDCR] = 0x0708,
  188. [LCCR] = 0x0710,
  189. [CEFCR] = 0x0740,
  190. [FRECR] = 0x0748,
  191. [TSFRCR] = 0x0750,
  192. [TLFRCR] = 0x0758,
  193. [RFCR] = 0x0760,
  194. [CERCR] = 0x0768,
  195. [CEECR] = 0x0770,
  196. [MAFCR] = 0x0778,
  197. [RMII_MII] = 0x0790,
  198. [ARSTR] = 0x0000,
  199. [TSU_CTRST] = 0x0004,
  200. [TSU_FWEN0] = 0x0010,
  201. [TSU_FWEN1] = 0x0014,
  202. [TSU_FCM] = 0x0018,
  203. [TSU_BSYSL0] = 0x0020,
  204. [TSU_BSYSL1] = 0x0024,
  205. [TSU_PRISL0] = 0x0028,
  206. [TSU_PRISL1] = 0x002c,
  207. [TSU_FWSL0] = 0x0030,
  208. [TSU_FWSL1] = 0x0034,
  209. [TSU_FWSLC] = 0x0038,
  210. [TSU_QTAG0] = 0x0040,
  211. [TSU_QTAG1] = 0x0044,
  212. [TSU_FWSR] = 0x0050,
  213. [TSU_FWINMK] = 0x0054,
  214. [TSU_ADQT0] = 0x0048,
  215. [TSU_ADQT1] = 0x004c,
  216. [TSU_VTAG0] = 0x0058,
  217. [TSU_VTAG1] = 0x005c,
  218. [TSU_ADSBSY] = 0x0060,
  219. [TSU_TEN] = 0x0064,
  220. [TSU_POST1] = 0x0070,
  221. [TSU_POST2] = 0x0074,
  222. [TSU_POST3] = 0x0078,
  223. [TSU_POST4] = 0x007c,
  224. [TSU_ADRH0] = 0x0100,
  225. [TSU_ADRL0] = 0x0104,
  226. [TSU_ADRH31] = 0x01f8,
  227. [TSU_ADRL31] = 0x01fc,
  228. [TXNLCR0] = 0x0080,
  229. [TXALCR0] = 0x0084,
  230. [RXNLCR0] = 0x0088,
  231. [RXALCR0] = 0x008c,
  232. [FWNLCR0] = 0x0090,
  233. [FWALCR0] = 0x0094,
  234. [TXNLCR1] = 0x00a0,
  235. [TXALCR1] = 0x00a0,
  236. [RXNLCR1] = 0x00a8,
  237. [RXALCR1] = 0x00ac,
  238. [FWNLCR1] = 0x00b0,
  239. [FWALCR1] = 0x00b4,
  240. };
  241. static const u16 sh_eth_offset_fast_sh4[SH_ETH_MAX_REGISTER_OFFSET] = {
  242. [ECMR] = 0x0100,
  243. [RFLR] = 0x0108,
  244. [ECSR] = 0x0110,
  245. [ECSIPR] = 0x0118,
  246. [PIR] = 0x0120,
  247. [PSR] = 0x0128,
  248. [RDMLR] = 0x0140,
  249. [IPGR] = 0x0150,
  250. [APR] = 0x0154,
  251. [MPR] = 0x0158,
  252. [TPAUSER] = 0x0164,
  253. [RFCF] = 0x0160,
  254. [TPAUSECR] = 0x0168,
  255. [BCFRR] = 0x016c,
  256. [MAHR] = 0x01c0,
  257. [MALR] = 0x01c8,
  258. [TROCR] = 0x01d0,
  259. [CDCR] = 0x01d4,
  260. [LCCR] = 0x01d8,
  261. [CNDCR] = 0x01dc,
  262. [CEFCR] = 0x01e4,
  263. [FRECR] = 0x01e8,
  264. [TSFRCR] = 0x01ec,
  265. [TLFRCR] = 0x01f0,
  266. [RFCR] = 0x01f4,
  267. [MAFCR] = 0x01f8,
  268. [RTRATE] = 0x01fc,
  269. [EDMR] = 0x0000,
  270. [EDTRR] = 0x0008,
  271. [EDRRR] = 0x0010,
  272. [TDLAR] = 0x0018,
  273. [RDLAR] = 0x0020,
  274. [EESR] = 0x0028,
  275. [EESIPR] = 0x0030,
  276. [TRSCER] = 0x0038,
  277. [RMFCR] = 0x0040,
  278. [TFTR] = 0x0048,
  279. [FDR] = 0x0050,
  280. [RMCR] = 0x0058,
  281. [TFUCR] = 0x0064,
  282. [RFOCR] = 0x0068,
  283. [FCFTR] = 0x0070,
  284. [RPADIR] = 0x0078,
  285. [TRIMD] = 0x007c,
  286. [RBWAR] = 0x00c8,
  287. [RDFAR] = 0x00cc,
  288. [TBRAR] = 0x00d4,
  289. [TDFAR] = 0x00d8,
  290. };
  291. static const u16 sh_eth_offset_fast_sh3_sh2[SH_ETH_MAX_REGISTER_OFFSET] = {
  292. [ECMR] = 0x0160,
  293. [ECSR] = 0x0164,
  294. [ECSIPR] = 0x0168,
  295. [PIR] = 0x016c,
  296. [MAHR] = 0x0170,
  297. [MALR] = 0x0174,
  298. [RFLR] = 0x0178,
  299. [PSR] = 0x017c,
  300. [TROCR] = 0x0180,
  301. [CDCR] = 0x0184,
  302. [LCCR] = 0x0188,
  303. [CNDCR] = 0x018c,
  304. [CEFCR] = 0x0194,
  305. [FRECR] = 0x0198,
  306. [TSFRCR] = 0x019c,
  307. [TLFRCR] = 0x01a0,
  308. [RFCR] = 0x01a4,
  309. [MAFCR] = 0x01a8,
  310. [IPGR] = 0x01b4,
  311. [APR] = 0x01b8,
  312. [MPR] = 0x01bc,
  313. [TPAUSER] = 0x01c4,
  314. [BCFR] = 0x01cc,
  315. [ARSTR] = 0x0000,
  316. [TSU_CTRST] = 0x0004,
  317. [TSU_FWEN0] = 0x0010,
  318. [TSU_FWEN1] = 0x0014,
  319. [TSU_FCM] = 0x0018,
  320. [TSU_BSYSL0] = 0x0020,
  321. [TSU_BSYSL1] = 0x0024,
  322. [TSU_PRISL0] = 0x0028,
  323. [TSU_PRISL1] = 0x002c,
  324. [TSU_FWSL0] = 0x0030,
  325. [TSU_FWSL1] = 0x0034,
  326. [TSU_FWSLC] = 0x0038,
  327. [TSU_QTAGM0] = 0x0040,
  328. [TSU_QTAGM1] = 0x0044,
  329. [TSU_ADQT0] = 0x0048,
  330. [TSU_ADQT1] = 0x004c,
  331. [TSU_FWSR] = 0x0050,
  332. [TSU_FWINMK] = 0x0054,
  333. [TSU_ADSBSY] = 0x0060,
  334. [TSU_TEN] = 0x0064,
  335. [TSU_POST1] = 0x0070,
  336. [TSU_POST2] = 0x0074,
  337. [TSU_POST3] = 0x0078,
  338. [TSU_POST4] = 0x007c,
  339. [TXNLCR0] = 0x0080,
  340. [TXALCR0] = 0x0084,
  341. [RXNLCR0] = 0x0088,
  342. [RXALCR0] = 0x008c,
  343. [FWNLCR0] = 0x0090,
  344. [FWALCR0] = 0x0094,
  345. [TXNLCR1] = 0x00a0,
  346. [TXALCR1] = 0x00a0,
  347. [RXNLCR1] = 0x00a8,
  348. [RXALCR1] = 0x00ac,
  349. [FWNLCR1] = 0x00b0,
  350. [FWALCR1] = 0x00b4,
  351. [TSU_ADRH0] = 0x0100,
  352. [TSU_ADRL0] = 0x0104,
  353. [TSU_ADRL31] = 0x01fc,
  354. };
  355. /* Driver's parameters */
  356. #if defined(CONFIG_CPU_SH4)
  357. #define SH4_SKB_RX_ALIGN 32
  358. #else
  359. #define SH2_SH3_SKB_RX_ALIGN 2
  360. #endif
  361. /*
  362. * Register's bits
  363. */
  364. #if defined(CONFIG_CPU_SUBTYPE_SH7734) || defined(CONFIG_CPU_SUBTYPE_SH7763)
  365. /* EDSR */
  366. enum EDSR_BIT {
  367. EDSR_ENT = 0x01, EDSR_ENR = 0x02,
  368. };
  369. #define EDSR_ENALL (EDSR_ENT|EDSR_ENR)
  370. /* GECMR */
  371. enum GECMR_BIT {
  372. GECMR_10 = 0x0, GECMR_100 = 0x04, GECMR_1000 = 0x01,
  373. };
  374. #endif
  375. /* EDMR */
  376. enum DMAC_M_BIT {
  377. EDMR_EL = 0x40, /* Litte endian */
  378. EDMR_DL1 = 0x20, EDMR_DL0 = 0x10,
  379. EDMR_SRST_GETHER = 0x03,
  380. EDMR_SRST_ETHER = 0x01,
  381. };
  382. /* EDTRR */
  383. enum DMAC_T_BIT {
  384. EDTRR_TRNS_GETHER = 0x03,
  385. EDTRR_TRNS_ETHER = 0x01,
  386. };
  387. /* EDRRR*/
  388. enum EDRRR_R_BIT {
  389. EDRRR_R = 0x01,
  390. };
  391. /* TPAUSER */
  392. enum TPAUSER_BIT {
  393. TPAUSER_TPAUSE = 0x0000ffff,
  394. TPAUSER_UNLIMITED = 0,
  395. };
  396. /* BCFR */
  397. enum BCFR_BIT {
  398. BCFR_RPAUSE = 0x0000ffff,
  399. BCFR_UNLIMITED = 0,
  400. };
  401. /* PIR */
  402. enum PIR_BIT {
  403. PIR_MDI = 0x08, PIR_MDO = 0x04, PIR_MMD = 0x02, PIR_MDC = 0x01,
  404. };
  405. /* PSR */
  406. enum PHY_STATUS_BIT { PHY_ST_LINK = 0x01, };
  407. /* EESR */
  408. enum EESR_BIT {
  409. EESR_TWB1 = 0x80000000,
  410. EESR_TWB = 0x40000000, /* same as TWB0 */
  411. EESR_TC1 = 0x20000000,
  412. EESR_TUC = 0x10000000,
  413. EESR_ROC = 0x08000000,
  414. EESR_TABT = 0x04000000,
  415. EESR_RABT = 0x02000000,
  416. EESR_RFRMER = 0x01000000, /* same as RFCOF */
  417. EESR_ADE = 0x00800000,
  418. EESR_ECI = 0x00400000,
  419. EESR_FTC = 0x00200000, /* same as TC or TC0 */
  420. EESR_TDE = 0x00100000,
  421. EESR_TFE = 0x00080000, /* same as TFUF */
  422. EESR_FRC = 0x00040000, /* same as FR */
  423. EESR_RDE = 0x00020000,
  424. EESR_RFE = 0x00010000,
  425. EESR_CND = 0x00000800,
  426. EESR_DLC = 0x00000400,
  427. EESR_CD = 0x00000200,
  428. EESR_RTO = 0x00000100,
  429. EESR_RMAF = 0x00000080,
  430. EESR_CEEF = 0x00000040,
  431. EESR_CELF = 0x00000020,
  432. EESR_RRF = 0x00000010,
  433. EESR_RTLF = 0x00000008,
  434. EESR_RTSF = 0x00000004,
  435. EESR_PRE = 0x00000002,
  436. EESR_CERF = 0x00000001,
  437. };
  438. #define DEFAULT_TX_CHECK (EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | \
  439. EESR_RTO)
  440. #define DEFAULT_EESR_ERR_CHECK (EESR_TWB | EESR_TABT | EESR_RABT | EESR_RFE | \
  441. EESR_RDE | EESR_RFRMER | EESR_ADE | \
  442. EESR_TFE | EESR_TDE | EESR_ECI)
  443. #define DEFAULT_TX_ERROR_CHECK (EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | \
  444. EESR_TFE)
  445. /* EESIPR */
  446. enum DMAC_IM_BIT {
  447. DMAC_M_TWB = 0x40000000, DMAC_M_TABT = 0x04000000,
  448. DMAC_M_RABT = 0x02000000,
  449. DMAC_M_RFRMER = 0x01000000, DMAC_M_ADF = 0x00800000,
  450. DMAC_M_ECI = 0x00400000, DMAC_M_FTC = 0x00200000,
  451. DMAC_M_TDE = 0x00100000, DMAC_M_TFE = 0x00080000,
  452. DMAC_M_FRC = 0x00040000, DMAC_M_RDE = 0x00020000,
  453. DMAC_M_RFE = 0x00010000, DMAC_M_TINT4 = 0x00000800,
  454. DMAC_M_TINT3 = 0x00000400, DMAC_M_TINT2 = 0x00000200,
  455. DMAC_M_TINT1 = 0x00000100, DMAC_M_RINT8 = 0x00000080,
  456. DMAC_M_RINT5 = 0x00000010, DMAC_M_RINT4 = 0x00000008,
  457. DMAC_M_RINT3 = 0x00000004, DMAC_M_RINT2 = 0x00000002,
  458. DMAC_M_RINT1 = 0x00000001,
  459. };
  460. /* Receive descriptor bit */
  461. enum RD_STS_BIT {
  462. RD_RACT = 0x80000000, RD_RDEL = 0x40000000,
  463. RD_RFP1 = 0x20000000, RD_RFP0 = 0x10000000,
  464. RD_RFE = 0x08000000, RD_RFS10 = 0x00000200,
  465. RD_RFS9 = 0x00000100, RD_RFS8 = 0x00000080,
  466. RD_RFS7 = 0x00000040, RD_RFS6 = 0x00000020,
  467. RD_RFS5 = 0x00000010, RD_RFS4 = 0x00000008,
  468. RD_RFS3 = 0x00000004, RD_RFS2 = 0x00000002,
  469. RD_RFS1 = 0x00000001,
  470. };
  471. #define RDF1ST RD_RFP1
  472. #define RDFEND RD_RFP0
  473. #define RD_RFP (RD_RFP1|RD_RFP0)
  474. /* FCFTR */
  475. enum FCFTR_BIT {
  476. FCFTR_RFF2 = 0x00040000, FCFTR_RFF1 = 0x00020000,
  477. FCFTR_RFF0 = 0x00010000, FCFTR_RFD2 = 0x00000004,
  478. FCFTR_RFD1 = 0x00000002, FCFTR_RFD0 = 0x00000001,
  479. };
  480. #define DEFAULT_FIFO_F_D_RFF (FCFTR_RFF2 | FCFTR_RFF1 | FCFTR_RFF0)
  481. #define DEFAULT_FIFO_F_D_RFD (FCFTR_RFD2 | FCFTR_RFD1 | FCFTR_RFD0)
  482. /* Transfer descriptor bit */
  483. enum TD_STS_BIT {
  484. TD_TACT = 0x80000000,
  485. TD_TDLE = 0x40000000, TD_TFP1 = 0x20000000,
  486. TD_TFP0 = 0x10000000,
  487. };
  488. #define TDF1ST TD_TFP1
  489. #define TDFEND TD_TFP0
  490. #define TD_TFP (TD_TFP1|TD_TFP0)
  491. /* RMCR */
  492. #define DEFAULT_RMCR_VALUE 0x00000000
  493. /* ECMR */
  494. enum FELIC_MODE_BIT {
  495. ECMR_TRCCM = 0x04000000, ECMR_RCSC = 0x00800000,
  496. ECMR_DPAD = 0x00200000, ECMR_RZPF = 0x00100000,
  497. ECMR_ZPF = 0x00080000, ECMR_PFR = 0x00040000, ECMR_RXF = 0x00020000,
  498. ECMR_TXF = 0x00010000, ECMR_MCT = 0x00002000, ECMR_PRCEF = 0x00001000,
  499. ECMR_PMDE = 0x00000200, ECMR_RE = 0x00000040, ECMR_TE = 0x00000020,
  500. ECMR_RTM = 0x00000010, ECMR_ILB = 0x00000008, ECMR_ELB = 0x00000004,
  501. ECMR_DM = 0x00000002, ECMR_PRM = 0x00000001,
  502. };
  503. /* ECSR */
  504. enum ECSR_STATUS_BIT {
  505. ECSR_BRCRX = 0x20, ECSR_PSRTO = 0x10,
  506. ECSR_LCHNG = 0x04,
  507. ECSR_MPD = 0x02, ECSR_ICD = 0x01,
  508. };
  509. #define DEFAULT_ECSR_INIT (ECSR_BRCRX | ECSR_PSRTO | ECSR_LCHNG | \
  510. ECSR_ICD | ECSIPR_MPDIP)
  511. /* ECSIPR */
  512. enum ECSIPR_STATUS_MASK_BIT {
  513. ECSIPR_BRCRXIP = 0x20, ECSIPR_PSRTOIP = 0x10,
  514. ECSIPR_LCHNGIP = 0x04,
  515. ECSIPR_MPDIP = 0x02, ECSIPR_ICDIP = 0x01,
  516. };
  517. #define DEFAULT_ECSIPR_INIT (ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | \
  518. ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP)
  519. /* APR */
  520. enum APR_BIT {
  521. APR_AP = 0x00000001,
  522. };
  523. /* MPR */
  524. enum MPR_BIT {
  525. MPR_MP = 0x00000001,
  526. };
  527. /* TRSCER */
  528. enum DESC_I_BIT {
  529. DESC_I_TINT4 = 0x0800, DESC_I_TINT3 = 0x0400, DESC_I_TINT2 = 0x0200,
  530. DESC_I_TINT1 = 0x0100, DESC_I_RINT8 = 0x0080, DESC_I_RINT5 = 0x0010,
  531. DESC_I_RINT4 = 0x0008, DESC_I_RINT3 = 0x0004, DESC_I_RINT2 = 0x0002,
  532. DESC_I_RINT1 = 0x0001,
  533. };
  534. /* RPADIR */
  535. enum RPADIR_BIT {
  536. RPADIR_PADS1 = 0x20000, RPADIR_PADS0 = 0x10000,
  537. RPADIR_PADR = 0x0003f,
  538. };
  539. /* FDR */
  540. #define DEFAULT_FDR_INIT 0x00000707
  541. enum phy_offsets {
  542. PHY_CTRL = 0, PHY_STAT = 1, PHY_IDT1 = 2, PHY_IDT2 = 3,
  543. PHY_ANA = 4, PHY_ANL = 5, PHY_ANE = 6,
  544. PHY_16 = 16,
  545. };
  546. /* PHY_CTRL */
  547. enum PHY_CTRL_BIT {
  548. PHY_C_RESET = 0x8000, PHY_C_LOOPBK = 0x4000, PHY_C_SPEEDSL = 0x2000,
  549. PHY_C_ANEGEN = 0x1000, PHY_C_PWRDN = 0x0800, PHY_C_ISO = 0x0400,
  550. PHY_C_RANEG = 0x0200, PHY_C_DUPLEX = 0x0100, PHY_C_COLT = 0x0080,
  551. };
  552. #define DM9161_PHY_C_ANEGEN 0 /* auto nego special */
  553. /* PHY_STAT */
  554. enum PHY_STAT_BIT {
  555. PHY_S_100T4 = 0x8000, PHY_S_100X_F = 0x4000, PHY_S_100X_H = 0x2000,
  556. PHY_S_10T_F = 0x1000, PHY_S_10T_H = 0x0800, PHY_S_ANEGC = 0x0020,
  557. PHY_S_RFAULT = 0x0010, PHY_S_ANEGA = 0x0008, PHY_S_LINK = 0x0004,
  558. PHY_S_JAB = 0x0002, PHY_S_EXTD = 0x0001,
  559. };
  560. /* PHY_ANA */
  561. enum PHY_ANA_BIT {
  562. PHY_A_NP = 0x8000, PHY_A_ACK = 0x4000, PHY_A_RF = 0x2000,
  563. PHY_A_FCS = 0x0400, PHY_A_T4 = 0x0200, PHY_A_FDX = 0x0100,
  564. PHY_A_HDX = 0x0080, PHY_A_10FDX = 0x0040, PHY_A_10HDX = 0x0020,
  565. PHY_A_SEL = 0x001e,
  566. };
  567. /* PHY_ANL */
  568. enum PHY_ANL_BIT {
  569. PHY_L_NP = 0x8000, PHY_L_ACK = 0x4000, PHY_L_RF = 0x2000,
  570. PHY_L_FCS = 0x0400, PHY_L_T4 = 0x0200, PHY_L_FDX = 0x0100,
  571. PHY_L_HDX = 0x0080, PHY_L_10FDX = 0x0040, PHY_L_10HDX = 0x0020,
  572. PHY_L_SEL = 0x001f,
  573. };
  574. /* PHY_ANE */
  575. enum PHY_ANE_BIT {
  576. PHY_E_PDF = 0x0010, PHY_E_LPNPA = 0x0008, PHY_E_NPA = 0x0004,
  577. PHY_E_PRX = 0x0002, PHY_E_LPANEGA = 0x0001,
  578. };
  579. /* DM9161 */
  580. enum PHY_16_BIT {
  581. PHY_16_BP4B45 = 0x8000, PHY_16_BPSCR = 0x4000, PHY_16_BPALIGN = 0x2000,
  582. PHY_16_BP_ADPOK = 0x1000, PHY_16_Repeatmode = 0x0800,
  583. PHY_16_TXselect = 0x0400,
  584. PHY_16_Rsvd = 0x0200, PHY_16_RMIIEnable = 0x0100,
  585. PHY_16_Force100LNK = 0x0080,
  586. PHY_16_APDLED_CTL = 0x0040, PHY_16_COLLED_CTL = 0x0020,
  587. PHY_16_RPDCTR_EN = 0x0010,
  588. PHY_16_ResetStMch = 0x0008, PHY_16_PreamSupr = 0x0004,
  589. PHY_16_Sleepmode = 0x0002,
  590. PHY_16_RemoteLoopOut = 0x0001,
  591. };
  592. #define POST_RX 0x08
  593. #define POST_FW 0x04
  594. #define POST0_RX (POST_RX)
  595. #define POST0_FW (POST_FW)
  596. #define POST1_RX (POST_RX >> 2)
  597. #define POST1_FW (POST_FW >> 2)
  598. #define POST_ALL (POST0_RX | POST0_FW | POST1_RX | POST1_FW)
  599. /* ARSTR */
  600. enum ARSTR_BIT { ARSTR_ARSTR = 0x00000001, };
  601. /* TSU_FWEN0 */
  602. enum TSU_FWEN0_BIT {
  603. TSU_FWEN0_0 = 0x00000001,
  604. };
  605. /* TSU_ADSBSY */
  606. enum TSU_ADSBSY_BIT {
  607. TSU_ADSBSY_0 = 0x00000001,
  608. };
  609. /* TSU_TEN */
  610. enum TSU_TEN_BIT {
  611. TSU_TEN_0 = 0x80000000,
  612. };
  613. /* TSU_FWSL0 */
  614. enum TSU_FWSL0_BIT {
  615. TSU_FWSL0_FW50 = 0x1000, TSU_FWSL0_FW40 = 0x0800,
  616. TSU_FWSL0_FW30 = 0x0400, TSU_FWSL0_FW20 = 0x0200,
  617. TSU_FWSL0_FW10 = 0x0100, TSU_FWSL0_RMSA0 = 0x0010,
  618. };
  619. /* TSU_FWSLC */
  620. enum TSU_FWSLC_BIT {
  621. TSU_FWSLC_POSTENU = 0x2000, TSU_FWSLC_POSTENL = 0x1000,
  622. TSU_FWSLC_CAMSEL03 = 0x0080, TSU_FWSLC_CAMSEL02 = 0x0040,
  623. TSU_FWSLC_CAMSEL01 = 0x0020, TSU_FWSLC_CAMSEL00 = 0x0010,
  624. TSU_FWSLC_CAMSEL13 = 0x0008, TSU_FWSLC_CAMSEL12 = 0x0004,
  625. TSU_FWSLC_CAMSEL11 = 0x0002, TSU_FWSLC_CAMSEL10 = 0x0001,
  626. };
  627. /* TSU_VTAGn */
  628. #define TSU_VTAG_ENABLE 0x80000000
  629. #define TSU_VTAG_VID_MASK 0x00000fff
  630. /*
  631. * The sh ether Tx buffer descriptors.
  632. * This structure should be 20 bytes.
  633. */
  634. struct sh_eth_txdesc {
  635. u32 status; /* TD0 */
  636. #if defined(__LITTLE_ENDIAN)
  637. u16 pad0; /* TD1 */
  638. u16 buffer_length; /* TD1 */
  639. #else
  640. u16 buffer_length; /* TD1 */
  641. u16 pad0; /* TD1 */
  642. #endif
  643. u32 addr; /* TD2 */
  644. u32 pad1; /* padding data */
  645. } __attribute__((aligned(2), packed));
  646. /*
  647. * The sh ether Rx buffer descriptors.
  648. * This structure should be 20 bytes.
  649. */
  650. struct sh_eth_rxdesc {
  651. u32 status; /* RD0 */
  652. #if defined(__LITTLE_ENDIAN)
  653. u16 frame_length; /* RD1 */
  654. u16 buffer_length; /* RD1 */
  655. #else
  656. u16 buffer_length; /* RD1 */
  657. u16 frame_length; /* RD1 */
  658. #endif
  659. u32 addr; /* RD2 */
  660. u32 pad0; /* padding data */
  661. } __attribute__((aligned(2), packed));
  662. /* This structure is used by each CPU dependency handling. */
  663. struct sh_eth_cpu_data {
  664. /* optional functions */
  665. void (*chip_reset)(struct net_device *ndev);
  666. void (*set_duplex)(struct net_device *ndev);
  667. void (*set_rate)(struct net_device *ndev);
  668. /* mandatory initialize value */
  669. unsigned long eesipr_value;
  670. /* optional initialize value */
  671. unsigned long ecsr_value;
  672. unsigned long ecsipr_value;
  673. unsigned long fdr_value;
  674. unsigned long fcftr_value;
  675. unsigned long rpadir_value;
  676. unsigned long rmcr_value;
  677. /* interrupt checking mask */
  678. unsigned long tx_check;
  679. unsigned long eesr_err_check;
  680. unsigned long tx_error_check;
  681. /* hardware features */
  682. unsigned no_psr:1; /* EtherC DO NOT have PSR */
  683. unsigned apr:1; /* EtherC have APR */
  684. unsigned mpr:1; /* EtherC have MPR */
  685. unsigned tpauser:1; /* EtherC have TPAUSER */
  686. unsigned bculr:1; /* EtherC have BCULR */
  687. unsigned tsu:1; /* EtherC have TSU */
  688. unsigned hw_swap:1; /* E-DMAC have DE bit in EDMR */
  689. unsigned rpadir:1; /* E-DMAC have RPADIR */
  690. unsigned no_trimd:1; /* E-DMAC DO NOT have TRIMD */
  691. unsigned no_ade:1; /* E-DMAC DO NOT have ADE bit in EESR */
  692. unsigned hw_crc:1; /* E-DMAC have CSMR */
  693. };
  694. struct sh_eth_private {
  695. struct platform_device *pdev;
  696. struct sh_eth_cpu_data *cd;
  697. const u16 *reg_offset;
  698. void __iomem *addr;
  699. void __iomem *tsu_addr;
  700. dma_addr_t rx_desc_dma;
  701. dma_addr_t tx_desc_dma;
  702. struct sh_eth_rxdesc *rx_ring;
  703. struct sh_eth_txdesc *tx_ring;
  704. struct sk_buff **rx_skbuff;
  705. struct sk_buff **tx_skbuff;
  706. struct timer_list timer;
  707. spinlock_t lock;
  708. u32 cur_rx, dirty_rx; /* Producer/consumer ring indices */
  709. u32 cur_tx, dirty_tx;
  710. u32 rx_buf_sz; /* Based on MTU+slack. */
  711. int edmac_endian;
  712. /* MII transceiver section. */
  713. u32 phy_id; /* PHY ID */
  714. struct mii_bus *mii_bus; /* MDIO bus control */
  715. struct phy_device *phydev; /* PHY device control */
  716. enum phy_state link;
  717. phy_interface_t phy_interface;
  718. int msg_enable;
  719. int speed;
  720. int duplex;
  721. u32 rx_int_var, tx_int_var; /* interrupt control variables */
  722. char post_rx; /* POST receive */
  723. char post_fw; /* POST forward */
  724. struct net_device_stats tsu_stats; /* TSU forward status */
  725. int port; /* for TSU */
  726. int vlan_num_ids; /* for VLAN tag filter */
  727. unsigned no_ether_link:1;
  728. unsigned ether_link_active_low:1;
  729. };
  730. static inline void sh_eth_soft_swap(char *src, int len)
  731. {
  732. #ifdef __LITTLE_ENDIAN__
  733. u32 *p = (u32 *)src;
  734. u32 *maxp;
  735. maxp = p + ((len + sizeof(u32) - 1) / sizeof(u32));
  736. for (; p < maxp; p++)
  737. *p = swab32(*p);
  738. #endif
  739. }
  740. static inline void sh_eth_write(struct net_device *ndev, unsigned long data,
  741. int enum_index)
  742. {
  743. struct sh_eth_private *mdp = netdev_priv(ndev);
  744. iowrite32(data, mdp->addr + mdp->reg_offset[enum_index]);
  745. }
  746. static inline unsigned long sh_eth_read(struct net_device *ndev,
  747. int enum_index)
  748. {
  749. struct sh_eth_private *mdp = netdev_priv(ndev);
  750. return ioread32(mdp->addr + mdp->reg_offset[enum_index]);
  751. }
  752. static inline void *sh_eth_tsu_get_offset(struct sh_eth_private *mdp,
  753. int enum_index)
  754. {
  755. return mdp->tsu_addr + mdp->reg_offset[enum_index];
  756. }
  757. static inline void sh_eth_tsu_write(struct sh_eth_private *mdp,
  758. unsigned long data, int enum_index)
  759. {
  760. iowrite32(data, mdp->tsu_addr + mdp->reg_offset[enum_index]);
  761. }
  762. static inline unsigned long sh_eth_tsu_read(struct sh_eth_private *mdp,
  763. int enum_index)
  764. {
  765. return ioread32(mdp->tsu_addr + mdp->reg_offset[enum_index]);
  766. }
  767. #endif /* #ifndef __SH_ETH_H__ */