sh_eth.h 19 KB

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