macb.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * Atmel MACB Ethernet Controller driver
  3. *
  4. * Copyright (C) 2004-2006 Atmel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _MACB_H
  11. #define _MACB_H
  12. #define MACB_GREGS_NBR 16
  13. #define MACB_GREGS_VERSION 1
  14. #define MACB_MAX_QUEUES 8
  15. /* MACB register offsets */
  16. #define MACB_NCR 0x0000
  17. #define MACB_NCFGR 0x0004
  18. #define MACB_NSR 0x0008
  19. #define MACB_TAR 0x000c /* AT91RM9200 only */
  20. #define MACB_TCR 0x0010 /* AT91RM9200 only */
  21. #define MACB_TSR 0x0014
  22. #define MACB_RBQP 0x0018
  23. #define MACB_TBQP 0x001c
  24. #define MACB_RSR 0x0020
  25. #define MACB_ISR 0x0024
  26. #define MACB_IER 0x0028
  27. #define MACB_IDR 0x002c
  28. #define MACB_IMR 0x0030
  29. #define MACB_MAN 0x0034
  30. #define MACB_PTR 0x0038
  31. #define MACB_PFR 0x003c
  32. #define MACB_FTO 0x0040
  33. #define MACB_SCF 0x0044
  34. #define MACB_MCF 0x0048
  35. #define MACB_FRO 0x004c
  36. #define MACB_FCSE 0x0050
  37. #define MACB_ALE 0x0054
  38. #define MACB_DTF 0x0058
  39. #define MACB_LCOL 0x005c
  40. #define MACB_EXCOL 0x0060
  41. #define MACB_TUND 0x0064
  42. #define MACB_CSE 0x0068
  43. #define MACB_RRE 0x006c
  44. #define MACB_ROVR 0x0070
  45. #define MACB_RSE 0x0074
  46. #define MACB_ELE 0x0078
  47. #define MACB_RJA 0x007c
  48. #define MACB_USF 0x0080
  49. #define MACB_STE 0x0084
  50. #define MACB_RLE 0x0088
  51. #define MACB_TPF 0x008c
  52. #define MACB_HRB 0x0090
  53. #define MACB_HRT 0x0094
  54. #define MACB_SA1B 0x0098
  55. #define MACB_SA1T 0x009c
  56. #define MACB_SA2B 0x00a0
  57. #define MACB_SA2T 0x00a4
  58. #define MACB_SA3B 0x00a8
  59. #define MACB_SA3T 0x00ac
  60. #define MACB_SA4B 0x00b0
  61. #define MACB_SA4T 0x00b4
  62. #define MACB_TID 0x00b8
  63. #define MACB_TPQ 0x00bc
  64. #define MACB_USRIO 0x00c0
  65. #define MACB_WOL 0x00c4
  66. #define MACB_MID 0x00fc
  67. /* GEM register offsets. */
  68. #define GEM_NCFGR 0x0004
  69. #define GEM_USRIO 0x000c
  70. #define GEM_DMACFG 0x0010
  71. #define GEM_HRB 0x0080
  72. #define GEM_HRT 0x0084
  73. #define GEM_SA1B 0x0088
  74. #define GEM_SA1T 0x008C
  75. #define GEM_SA2B 0x0090
  76. #define GEM_SA2T 0x0094
  77. #define GEM_SA3B 0x0098
  78. #define GEM_SA3T 0x009C
  79. #define GEM_SA4B 0x00A0
  80. #define GEM_SA4T 0x00A4
  81. #define GEM_OTX 0x0100
  82. #define GEM_DCFG1 0x0280
  83. #define GEM_DCFG2 0x0284
  84. #define GEM_DCFG3 0x0288
  85. #define GEM_DCFG4 0x028c
  86. #define GEM_DCFG5 0x0290
  87. #define GEM_DCFG6 0x0294
  88. #define GEM_DCFG7 0x0298
  89. #define GEM_ISR(hw_q) (0x0400 + ((hw_q) << 2))
  90. #define GEM_TBQP(hw_q) (0x0440 + ((hw_q) << 2))
  91. #define GEM_RBQP(hw_q) (0x0480 + ((hw_q) << 2))
  92. #define GEM_IER(hw_q) (0x0600 + ((hw_q) << 2))
  93. #define GEM_IDR(hw_q) (0x0620 + ((hw_q) << 2))
  94. #define GEM_IMR(hw_q) (0x0640 + ((hw_q) << 2))
  95. /* Bitfields in NCR */
  96. #define MACB_LB_OFFSET 0
  97. #define MACB_LB_SIZE 1
  98. #define MACB_LLB_OFFSET 1
  99. #define MACB_LLB_SIZE 1
  100. #define MACB_RE_OFFSET 2
  101. #define MACB_RE_SIZE 1
  102. #define MACB_TE_OFFSET 3
  103. #define MACB_TE_SIZE 1
  104. #define MACB_MPE_OFFSET 4
  105. #define MACB_MPE_SIZE 1
  106. #define MACB_CLRSTAT_OFFSET 5
  107. #define MACB_CLRSTAT_SIZE 1
  108. #define MACB_INCSTAT_OFFSET 6
  109. #define MACB_INCSTAT_SIZE 1
  110. #define MACB_WESTAT_OFFSET 7
  111. #define MACB_WESTAT_SIZE 1
  112. #define MACB_BP_OFFSET 8
  113. #define MACB_BP_SIZE 1
  114. #define MACB_TSTART_OFFSET 9
  115. #define MACB_TSTART_SIZE 1
  116. #define MACB_THALT_OFFSET 10
  117. #define MACB_THALT_SIZE 1
  118. #define MACB_NCR_TPF_OFFSET 11
  119. #define MACB_NCR_TPF_SIZE 1
  120. #define MACB_TZQ_OFFSET 12
  121. #define MACB_TZQ_SIZE 1
  122. /* Bitfields in NCFGR */
  123. #define MACB_SPD_OFFSET 0
  124. #define MACB_SPD_SIZE 1
  125. #define MACB_FD_OFFSET 1
  126. #define MACB_FD_SIZE 1
  127. #define MACB_BIT_RATE_OFFSET 2
  128. #define MACB_BIT_RATE_SIZE 1
  129. #define MACB_JFRAME_OFFSET 3
  130. #define MACB_JFRAME_SIZE 1
  131. #define MACB_CAF_OFFSET 4
  132. #define MACB_CAF_SIZE 1
  133. #define MACB_NBC_OFFSET 5
  134. #define MACB_NBC_SIZE 1
  135. #define MACB_NCFGR_MTI_OFFSET 6
  136. #define MACB_NCFGR_MTI_SIZE 1
  137. #define MACB_UNI_OFFSET 7
  138. #define MACB_UNI_SIZE 1
  139. #define MACB_BIG_OFFSET 8
  140. #define MACB_BIG_SIZE 1
  141. #define MACB_EAE_OFFSET 9
  142. #define MACB_EAE_SIZE 1
  143. #define MACB_CLK_OFFSET 10
  144. #define MACB_CLK_SIZE 2
  145. #define MACB_RTY_OFFSET 12
  146. #define MACB_RTY_SIZE 1
  147. #define MACB_PAE_OFFSET 13
  148. #define MACB_PAE_SIZE 1
  149. #define MACB_RM9200_RMII_OFFSET 13 /* AT91RM9200 only */
  150. #define MACB_RM9200_RMII_SIZE 1 /* AT91RM9200 only */
  151. #define MACB_RBOF_OFFSET 14
  152. #define MACB_RBOF_SIZE 2
  153. #define MACB_RLCE_OFFSET 16
  154. #define MACB_RLCE_SIZE 1
  155. #define MACB_DRFCS_OFFSET 17
  156. #define MACB_DRFCS_SIZE 1
  157. #define MACB_EFRHD_OFFSET 18
  158. #define MACB_EFRHD_SIZE 1
  159. #define MACB_IRXFCS_OFFSET 19
  160. #define MACB_IRXFCS_SIZE 1
  161. /* GEM specific NCFGR bitfields. */
  162. #define GEM_GBE_OFFSET 10
  163. #define GEM_GBE_SIZE 1
  164. #define GEM_CLK_OFFSET 18
  165. #define GEM_CLK_SIZE 3
  166. #define GEM_DBW_OFFSET 21
  167. #define GEM_DBW_SIZE 2
  168. #define GEM_RXCOEN_OFFSET 24
  169. #define GEM_RXCOEN_SIZE 1
  170. /* Constants for data bus width. */
  171. #define GEM_DBW32 0
  172. #define GEM_DBW64 1
  173. #define GEM_DBW128 2
  174. /* Bitfields in DMACFG. */
  175. #define GEM_FBLDO_OFFSET 0
  176. #define GEM_FBLDO_SIZE 5
  177. #define GEM_ENDIA_OFFSET 7
  178. #define GEM_ENDIA_SIZE 1
  179. #define GEM_RXBMS_OFFSET 8
  180. #define GEM_RXBMS_SIZE 2
  181. #define GEM_TXPBMS_OFFSET 10
  182. #define GEM_TXPBMS_SIZE 1
  183. #define GEM_TXCOEN_OFFSET 11
  184. #define GEM_TXCOEN_SIZE 1
  185. #define GEM_RXBS_OFFSET 16
  186. #define GEM_RXBS_SIZE 8
  187. #define GEM_DDRP_OFFSET 24
  188. #define GEM_DDRP_SIZE 1
  189. /* Bitfields in NSR */
  190. #define MACB_NSR_LINK_OFFSET 0
  191. #define MACB_NSR_LINK_SIZE 1
  192. #define MACB_MDIO_OFFSET 1
  193. #define MACB_MDIO_SIZE 1
  194. #define MACB_IDLE_OFFSET 2
  195. #define MACB_IDLE_SIZE 1
  196. /* Bitfields in TSR */
  197. #define MACB_UBR_OFFSET 0
  198. #define MACB_UBR_SIZE 1
  199. #define MACB_COL_OFFSET 1
  200. #define MACB_COL_SIZE 1
  201. #define MACB_TSR_RLE_OFFSET 2
  202. #define MACB_TSR_RLE_SIZE 1
  203. #define MACB_TGO_OFFSET 3
  204. #define MACB_TGO_SIZE 1
  205. #define MACB_BEX_OFFSET 4
  206. #define MACB_BEX_SIZE 1
  207. #define MACB_RM9200_BNQ_OFFSET 4 /* AT91RM9200 only */
  208. #define MACB_RM9200_BNQ_SIZE 1 /* AT91RM9200 only */
  209. #define MACB_COMP_OFFSET 5
  210. #define MACB_COMP_SIZE 1
  211. #define MACB_UND_OFFSET 6
  212. #define MACB_UND_SIZE 1
  213. /* Bitfields in RSR */
  214. #define MACB_BNA_OFFSET 0
  215. #define MACB_BNA_SIZE 1
  216. #define MACB_REC_OFFSET 1
  217. #define MACB_REC_SIZE 1
  218. #define MACB_OVR_OFFSET 2
  219. #define MACB_OVR_SIZE 1
  220. /* Bitfields in ISR/IER/IDR/IMR */
  221. #define MACB_MFD_OFFSET 0
  222. #define MACB_MFD_SIZE 1
  223. #define MACB_RCOMP_OFFSET 1
  224. #define MACB_RCOMP_SIZE 1
  225. #define MACB_RXUBR_OFFSET 2
  226. #define MACB_RXUBR_SIZE 1
  227. #define MACB_TXUBR_OFFSET 3
  228. #define MACB_TXUBR_SIZE 1
  229. #define MACB_ISR_TUND_OFFSET 4
  230. #define MACB_ISR_TUND_SIZE 1
  231. #define MACB_ISR_RLE_OFFSET 5
  232. #define MACB_ISR_RLE_SIZE 1
  233. #define MACB_TXERR_OFFSET 6
  234. #define MACB_TXERR_SIZE 1
  235. #define MACB_TCOMP_OFFSET 7
  236. #define MACB_TCOMP_SIZE 1
  237. #define MACB_ISR_LINK_OFFSET 9
  238. #define MACB_ISR_LINK_SIZE 1
  239. #define MACB_ISR_ROVR_OFFSET 10
  240. #define MACB_ISR_ROVR_SIZE 1
  241. #define MACB_HRESP_OFFSET 11
  242. #define MACB_HRESP_SIZE 1
  243. #define MACB_PFR_OFFSET 12
  244. #define MACB_PFR_SIZE 1
  245. #define MACB_PTZ_OFFSET 13
  246. #define MACB_PTZ_SIZE 1
  247. /* Bitfields in MAN */
  248. #define MACB_DATA_OFFSET 0
  249. #define MACB_DATA_SIZE 16
  250. #define MACB_CODE_OFFSET 16
  251. #define MACB_CODE_SIZE 2
  252. #define MACB_REGA_OFFSET 18
  253. #define MACB_REGA_SIZE 5
  254. #define MACB_PHYA_OFFSET 23
  255. #define MACB_PHYA_SIZE 5
  256. #define MACB_RW_OFFSET 28
  257. #define MACB_RW_SIZE 2
  258. #define MACB_SOF_OFFSET 30
  259. #define MACB_SOF_SIZE 2
  260. /* Bitfields in USRIO (AVR32) */
  261. #define MACB_MII_OFFSET 0
  262. #define MACB_MII_SIZE 1
  263. #define MACB_EAM_OFFSET 1
  264. #define MACB_EAM_SIZE 1
  265. #define MACB_TX_PAUSE_OFFSET 2
  266. #define MACB_TX_PAUSE_SIZE 1
  267. #define MACB_TX_PAUSE_ZERO_OFFSET 3
  268. #define MACB_TX_PAUSE_ZERO_SIZE 1
  269. /* Bitfields in USRIO (AT91) */
  270. #define MACB_RMII_OFFSET 0
  271. #define MACB_RMII_SIZE 1
  272. #define GEM_RGMII_OFFSET 0 /* GEM gigabit mode */
  273. #define GEM_RGMII_SIZE 1
  274. #define MACB_CLKEN_OFFSET 1
  275. #define MACB_CLKEN_SIZE 1
  276. /* Bitfields in WOL */
  277. #define MACB_IP_OFFSET 0
  278. #define MACB_IP_SIZE 16
  279. #define MACB_MAG_OFFSET 16
  280. #define MACB_MAG_SIZE 1
  281. #define MACB_ARP_OFFSET 17
  282. #define MACB_ARP_SIZE 1
  283. #define MACB_SA1_OFFSET 18
  284. #define MACB_SA1_SIZE 1
  285. #define MACB_WOL_MTI_OFFSET 19
  286. #define MACB_WOL_MTI_SIZE 1
  287. /* Bitfields in MID */
  288. #define MACB_IDNUM_OFFSET 16
  289. #define MACB_IDNUM_SIZE 16
  290. #define MACB_REV_OFFSET 0
  291. #define MACB_REV_SIZE 16
  292. /* Bitfields in DCFG1. */
  293. #define GEM_IRQCOR_OFFSET 23
  294. #define GEM_IRQCOR_SIZE 1
  295. #define GEM_DBWDEF_OFFSET 25
  296. #define GEM_DBWDEF_SIZE 3
  297. /* Bitfields in DCFG2. */
  298. #define GEM_RX_PKT_BUFF_OFFSET 20
  299. #define GEM_RX_PKT_BUFF_SIZE 1
  300. #define GEM_TX_PKT_BUFF_OFFSET 21
  301. #define GEM_TX_PKT_BUFF_SIZE 1
  302. /* Constants for CLK */
  303. #define MACB_CLK_DIV8 0
  304. #define MACB_CLK_DIV16 1
  305. #define MACB_CLK_DIV32 2
  306. #define MACB_CLK_DIV64 3
  307. /* GEM specific constants for CLK. */
  308. #define GEM_CLK_DIV8 0
  309. #define GEM_CLK_DIV16 1
  310. #define GEM_CLK_DIV32 2
  311. #define GEM_CLK_DIV48 3
  312. #define GEM_CLK_DIV64 4
  313. #define GEM_CLK_DIV96 5
  314. /* Constants for MAN register */
  315. #define MACB_MAN_SOF 1
  316. #define MACB_MAN_WRITE 1
  317. #define MACB_MAN_READ 2
  318. #define MACB_MAN_CODE 2
  319. /* Capability mask bits */
  320. #define MACB_CAPS_ISR_CLEAR_ON_WRITE 0x00000001
  321. #define MACB_CAPS_FIFO_MODE 0x10000000
  322. #define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000
  323. #define MACB_CAPS_SG_DISABLED 0x40000000
  324. #define MACB_CAPS_MACB_IS_GEM 0x80000000
  325. /* Bit manipulation macros */
  326. #define MACB_BIT(name) \
  327. (1 << MACB_##name##_OFFSET)
  328. #define MACB_BF(name,value) \
  329. (((value) & ((1 << MACB_##name##_SIZE) - 1)) \
  330. << MACB_##name##_OFFSET)
  331. #define MACB_BFEXT(name,value)\
  332. (((value) >> MACB_##name##_OFFSET) \
  333. & ((1 << MACB_##name##_SIZE) - 1))
  334. #define MACB_BFINS(name,value,old) \
  335. (((old) & ~(((1 << MACB_##name##_SIZE) - 1) \
  336. << MACB_##name##_OFFSET)) \
  337. | MACB_BF(name,value))
  338. #define GEM_BIT(name) \
  339. (1 << GEM_##name##_OFFSET)
  340. #define GEM_BF(name, value) \
  341. (((value) & ((1 << GEM_##name##_SIZE) - 1)) \
  342. << GEM_##name##_OFFSET)
  343. #define GEM_BFEXT(name, value)\
  344. (((value) >> GEM_##name##_OFFSET) \
  345. & ((1 << GEM_##name##_SIZE) - 1))
  346. #define GEM_BFINS(name, value, old) \
  347. (((old) & ~(((1 << GEM_##name##_SIZE) - 1) \
  348. << GEM_##name##_OFFSET)) \
  349. | GEM_BF(name, value))
  350. /* Register access macros */
  351. #define macb_readl(port,reg) \
  352. __raw_readl((port)->regs + MACB_##reg)
  353. #define macb_writel(port,reg,value) \
  354. __raw_writel((value), (port)->regs + MACB_##reg)
  355. #define gem_readl(port, reg) \
  356. __raw_readl((port)->regs + GEM_##reg)
  357. #define gem_writel(port, reg, value) \
  358. __raw_writel((value), (port)->regs + GEM_##reg)
  359. #define queue_readl(queue, reg) \
  360. __raw_readl((queue)->bp->regs + (queue)->reg)
  361. #define queue_writel(queue, reg, value) \
  362. __raw_writel((value), (queue)->bp->regs + (queue)->reg)
  363. /*
  364. * Conditional GEM/MACB macros. These perform the operation to the correct
  365. * register dependent on whether the device is a GEM or a MACB. For registers
  366. * and bitfields that are common across both devices, use macb_{read,write}l
  367. * to avoid the cost of the conditional.
  368. */
  369. #define macb_or_gem_writel(__bp, __reg, __value) \
  370. ({ \
  371. if (macb_is_gem((__bp))) \
  372. gem_writel((__bp), __reg, __value); \
  373. else \
  374. macb_writel((__bp), __reg, __value); \
  375. })
  376. #define macb_or_gem_readl(__bp, __reg) \
  377. ({ \
  378. u32 __v; \
  379. if (macb_is_gem((__bp))) \
  380. __v = gem_readl((__bp), __reg); \
  381. else \
  382. __v = macb_readl((__bp), __reg); \
  383. __v; \
  384. })
  385. /**
  386. * struct macb_dma_desc - Hardware DMA descriptor
  387. * @addr: DMA address of data buffer
  388. * @ctrl: Control and status bits
  389. */
  390. struct macb_dma_desc {
  391. u32 addr;
  392. u32 ctrl;
  393. };
  394. /* DMA descriptor bitfields */
  395. #define MACB_RX_USED_OFFSET 0
  396. #define MACB_RX_USED_SIZE 1
  397. #define MACB_RX_WRAP_OFFSET 1
  398. #define MACB_RX_WRAP_SIZE 1
  399. #define MACB_RX_WADDR_OFFSET 2
  400. #define MACB_RX_WADDR_SIZE 30
  401. #define MACB_RX_FRMLEN_OFFSET 0
  402. #define MACB_RX_FRMLEN_SIZE 12
  403. #define MACB_RX_OFFSET_OFFSET 12
  404. #define MACB_RX_OFFSET_SIZE 2
  405. #define MACB_RX_SOF_OFFSET 14
  406. #define MACB_RX_SOF_SIZE 1
  407. #define MACB_RX_EOF_OFFSET 15
  408. #define MACB_RX_EOF_SIZE 1
  409. #define MACB_RX_CFI_OFFSET 16
  410. #define MACB_RX_CFI_SIZE 1
  411. #define MACB_RX_VLAN_PRI_OFFSET 17
  412. #define MACB_RX_VLAN_PRI_SIZE 3
  413. #define MACB_RX_PRI_TAG_OFFSET 20
  414. #define MACB_RX_PRI_TAG_SIZE 1
  415. #define MACB_RX_VLAN_TAG_OFFSET 21
  416. #define MACB_RX_VLAN_TAG_SIZE 1
  417. #define MACB_RX_TYPEID_MATCH_OFFSET 22
  418. #define MACB_RX_TYPEID_MATCH_SIZE 1
  419. #define MACB_RX_SA4_MATCH_OFFSET 23
  420. #define MACB_RX_SA4_MATCH_SIZE 1
  421. #define MACB_RX_SA3_MATCH_OFFSET 24
  422. #define MACB_RX_SA3_MATCH_SIZE 1
  423. #define MACB_RX_SA2_MATCH_OFFSET 25
  424. #define MACB_RX_SA2_MATCH_SIZE 1
  425. #define MACB_RX_SA1_MATCH_OFFSET 26
  426. #define MACB_RX_SA1_MATCH_SIZE 1
  427. #define MACB_RX_EXT_MATCH_OFFSET 28
  428. #define MACB_RX_EXT_MATCH_SIZE 1
  429. #define MACB_RX_UHASH_MATCH_OFFSET 29
  430. #define MACB_RX_UHASH_MATCH_SIZE 1
  431. #define MACB_RX_MHASH_MATCH_OFFSET 30
  432. #define MACB_RX_MHASH_MATCH_SIZE 1
  433. #define MACB_RX_BROADCAST_OFFSET 31
  434. #define MACB_RX_BROADCAST_SIZE 1
  435. /* RX checksum offload disabled: bit 24 clear in NCFGR */
  436. #define GEM_RX_TYPEID_MATCH_OFFSET 22
  437. #define GEM_RX_TYPEID_MATCH_SIZE 2
  438. /* RX checksum offload enabled: bit 24 set in NCFGR */
  439. #define GEM_RX_CSUM_OFFSET 22
  440. #define GEM_RX_CSUM_SIZE 2
  441. #define MACB_TX_FRMLEN_OFFSET 0
  442. #define MACB_TX_FRMLEN_SIZE 11
  443. #define MACB_TX_LAST_OFFSET 15
  444. #define MACB_TX_LAST_SIZE 1
  445. #define MACB_TX_NOCRC_OFFSET 16
  446. #define MACB_TX_NOCRC_SIZE 1
  447. #define MACB_TX_BUF_EXHAUSTED_OFFSET 27
  448. #define MACB_TX_BUF_EXHAUSTED_SIZE 1
  449. #define MACB_TX_UNDERRUN_OFFSET 28
  450. #define MACB_TX_UNDERRUN_SIZE 1
  451. #define MACB_TX_ERROR_OFFSET 29
  452. #define MACB_TX_ERROR_SIZE 1
  453. #define MACB_TX_WRAP_OFFSET 30
  454. #define MACB_TX_WRAP_SIZE 1
  455. #define MACB_TX_USED_OFFSET 31
  456. #define MACB_TX_USED_SIZE 1
  457. #define GEM_TX_FRMLEN_OFFSET 0
  458. #define GEM_TX_FRMLEN_SIZE 14
  459. /* Buffer descriptor constants */
  460. #define GEM_RX_CSUM_NONE 0
  461. #define GEM_RX_CSUM_IP_ONLY 1
  462. #define GEM_RX_CSUM_IP_TCP 2
  463. #define GEM_RX_CSUM_IP_UDP 3
  464. /* limit RX checksum offload to TCP and UDP packets */
  465. #define GEM_RX_CSUM_CHECKED_MASK 2
  466. /**
  467. * struct macb_tx_skb - data about an skb which is being transmitted
  468. * @skb: skb currently being transmitted, only set for the last buffer
  469. * of the frame
  470. * @mapping: DMA address of the skb's fragment buffer
  471. * @size: size of the DMA mapped buffer
  472. * @mapped_as_page: true when buffer was mapped with skb_frag_dma_map(),
  473. * false when buffer was mapped with dma_map_single()
  474. */
  475. struct macb_tx_skb {
  476. struct sk_buff *skb;
  477. dma_addr_t mapping;
  478. size_t size;
  479. bool mapped_as_page;
  480. };
  481. /*
  482. * Hardware-collected statistics. Used when updating the network
  483. * device stats by a periodic timer.
  484. */
  485. struct macb_stats {
  486. u32 rx_pause_frames;
  487. u32 tx_ok;
  488. u32 tx_single_cols;
  489. u32 tx_multiple_cols;
  490. u32 rx_ok;
  491. u32 rx_fcs_errors;
  492. u32 rx_align_errors;
  493. u32 tx_deferred;
  494. u32 tx_late_cols;
  495. u32 tx_excessive_cols;
  496. u32 tx_underruns;
  497. u32 tx_carrier_errors;
  498. u32 rx_resource_errors;
  499. u32 rx_overruns;
  500. u32 rx_symbol_errors;
  501. u32 rx_oversize_pkts;
  502. u32 rx_jabbers;
  503. u32 rx_undersize_pkts;
  504. u32 sqe_test_errors;
  505. u32 rx_length_mismatch;
  506. u32 tx_pause_frames;
  507. };
  508. struct gem_stats {
  509. u32 tx_octets_31_0;
  510. u32 tx_octets_47_32;
  511. u32 tx_frames;
  512. u32 tx_broadcast_frames;
  513. u32 tx_multicast_frames;
  514. u32 tx_pause_frames;
  515. u32 tx_64_byte_frames;
  516. u32 tx_65_127_byte_frames;
  517. u32 tx_128_255_byte_frames;
  518. u32 tx_256_511_byte_frames;
  519. u32 tx_512_1023_byte_frames;
  520. u32 tx_1024_1518_byte_frames;
  521. u32 tx_greater_than_1518_byte_frames;
  522. u32 tx_underrun;
  523. u32 tx_single_collision_frames;
  524. u32 tx_multiple_collision_frames;
  525. u32 tx_excessive_collisions;
  526. u32 tx_late_collisions;
  527. u32 tx_deferred_frames;
  528. u32 tx_carrier_sense_errors;
  529. u32 rx_octets_31_0;
  530. u32 rx_octets_47_32;
  531. u32 rx_frames;
  532. u32 rx_broadcast_frames;
  533. u32 rx_multicast_frames;
  534. u32 rx_pause_frames;
  535. u32 rx_64_byte_frames;
  536. u32 rx_65_127_byte_frames;
  537. u32 rx_128_255_byte_frames;
  538. u32 rx_256_511_byte_frames;
  539. u32 rx_512_1023_byte_frames;
  540. u32 rx_1024_1518_byte_frames;
  541. u32 rx_greater_than_1518_byte_frames;
  542. u32 rx_undersized_frames;
  543. u32 rx_oversize_frames;
  544. u32 rx_jabbers;
  545. u32 rx_frame_check_sequence_errors;
  546. u32 rx_length_field_frame_errors;
  547. u32 rx_symbol_errors;
  548. u32 rx_alignment_errors;
  549. u32 rx_resource_errors;
  550. u32 rx_overruns;
  551. u32 rx_ip_header_checksum_errors;
  552. u32 rx_tcp_checksum_errors;
  553. u32 rx_udp_checksum_errors;
  554. };
  555. struct macb;
  556. struct macb_or_gem_ops {
  557. int (*mog_alloc_rx_buffers)(struct macb *bp);
  558. void (*mog_free_rx_buffers)(struct macb *bp);
  559. void (*mog_init_rings)(struct macb *bp);
  560. int (*mog_rx)(struct macb *bp, int budget);
  561. };
  562. struct macb_config {
  563. u32 caps;
  564. unsigned int dma_burst_length;
  565. };
  566. struct macb_queue {
  567. struct macb *bp;
  568. int irq;
  569. unsigned int ISR;
  570. unsigned int IER;
  571. unsigned int IDR;
  572. unsigned int IMR;
  573. unsigned int TBQP;
  574. unsigned int tx_head, tx_tail;
  575. struct macb_dma_desc *tx_ring;
  576. struct macb_tx_skb *tx_skb;
  577. dma_addr_t tx_ring_dma;
  578. struct work_struct tx_error_task;
  579. };
  580. struct macb {
  581. void __iomem *regs;
  582. unsigned int rx_tail;
  583. unsigned int rx_prepared_head;
  584. struct macb_dma_desc *rx_ring;
  585. struct sk_buff **rx_skbuff;
  586. void *rx_buffers;
  587. size_t rx_buffer_size;
  588. unsigned int num_queues;
  589. struct macb_queue queues[MACB_MAX_QUEUES];
  590. spinlock_t lock;
  591. struct platform_device *pdev;
  592. struct clk *pclk;
  593. struct clk *hclk;
  594. struct clk *tx_clk;
  595. struct net_device *dev;
  596. struct napi_struct napi;
  597. struct net_device_stats stats;
  598. union {
  599. struct macb_stats macb;
  600. struct gem_stats gem;
  601. } hw_stats;
  602. dma_addr_t rx_ring_dma;
  603. dma_addr_t rx_buffers_dma;
  604. struct macb_or_gem_ops macbgem_ops;
  605. struct mii_bus *mii_bus;
  606. struct phy_device *phy_dev;
  607. unsigned int link;
  608. unsigned int speed;
  609. unsigned int duplex;
  610. u32 caps;
  611. unsigned int dma_burst_length;
  612. phy_interface_t phy_interface;
  613. /* AT91RM9200 transmit */
  614. struct sk_buff *skb; /* holds skb until xmit interrupt completes */
  615. dma_addr_t skb_physaddr; /* phys addr from pci_map_single */
  616. int skb_length; /* saved skb length for pci_unmap_single */
  617. unsigned int max_tx_length;
  618. };
  619. extern const struct ethtool_ops macb_ethtool_ops;
  620. int macb_mii_init(struct macb *bp);
  621. int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  622. struct net_device_stats *macb_get_stats(struct net_device *dev);
  623. void macb_set_rx_mode(struct net_device *dev);
  624. void macb_set_hwaddr(struct macb *bp);
  625. void macb_get_hwaddr(struct macb *bp);
  626. static inline bool macb_is_gem(struct macb *bp)
  627. {
  628. return !!(bp->caps & MACB_CAPS_MACB_IS_GEM);
  629. }
  630. #endif /* _MACB_H */