designware.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * (C) Copyright 2010
  3. * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef _DW_ETH_H
  24. #define _DW_ETH_H
  25. #define CONFIG_TX_DESCR_NUM 16
  26. #define CONFIG_RX_DESCR_NUM 16
  27. #define CONFIG_ETH_BUFSIZE 2048
  28. #define TX_TOTAL_BUFSIZE (CONFIG_ETH_BUFSIZE * CONFIG_TX_DESCR_NUM)
  29. #define RX_TOTAL_BUFSIZE (CONFIG_ETH_BUFSIZE * CONFIG_RX_DESCR_NUM)
  30. #define CONFIG_MACRESET_TIMEOUT (3 * CONFIG_SYS_HZ)
  31. #define CONFIG_MDIO_TIMEOUT (3 * CONFIG_SYS_HZ)
  32. #define CONFIG_PHYRESET_TIMEOUT (3 * CONFIG_SYS_HZ)
  33. #define CONFIG_AUTONEG_TIMEOUT (5 * CONFIG_SYS_HZ)
  34. struct eth_mac_regs {
  35. u32 conf; /* 0x00 */
  36. u32 framefilt; /* 0x04 */
  37. u32 hashtablehigh; /* 0x08 */
  38. u32 hashtablelow; /* 0x0c */
  39. u32 miiaddr; /* 0x10 */
  40. u32 miidata; /* 0x14 */
  41. u32 flowcontrol; /* 0x18 */
  42. u32 vlantag; /* 0x1c */
  43. u32 version; /* 0x20 */
  44. u8 reserved_1[20];
  45. u32 intreg; /* 0x38 */
  46. u32 intmask; /* 0x3c */
  47. u32 macaddr0hi; /* 0x40 */
  48. u32 macaddr0lo; /* 0x44 */
  49. };
  50. /* MAC configuration register definitions */
  51. #define FRAMEBURSTENABLE (1 << 21)
  52. #define MII_PORTSELECT (1 << 15)
  53. #define FES_100 (1 << 14)
  54. #define DISABLERXOWN (1 << 13)
  55. #define FULLDPLXMODE (1 << 11)
  56. #define RXENABLE (1 << 2)
  57. #define TXENABLE (1 << 3)
  58. /* MII address register definitions */
  59. #define MII_BUSY (1 << 0)
  60. #define MII_WRITE (1 << 1)
  61. #define MII_CLKRANGE_60_100M (0)
  62. #define MII_CLKRANGE_100_150M (0x4)
  63. #define MII_CLKRANGE_20_35M (0x8)
  64. #define MII_CLKRANGE_35_60M (0xC)
  65. #define MII_CLKRANGE_150_250M (0x10)
  66. #define MII_CLKRANGE_250_300M (0x14)
  67. #define MIIADDRSHIFT (11)
  68. #define MIIREGSHIFT (6)
  69. #define MII_REGMSK (0x1F << 6)
  70. #define MII_ADDRMSK (0x1F << 11)
  71. struct eth_dma_regs {
  72. u32 busmode; /* 0x00 */
  73. u32 txpolldemand; /* 0x04 */
  74. u32 rxpolldemand; /* 0x08 */
  75. u32 rxdesclistaddr; /* 0x0c */
  76. u32 txdesclistaddr; /* 0x10 */
  77. u32 status; /* 0x14 */
  78. u32 opmode; /* 0x18 */
  79. u32 intenable; /* 0x1c */
  80. u8 reserved[40];
  81. u32 currhosttxdesc; /* 0x48 */
  82. u32 currhostrxdesc; /* 0x4c */
  83. u32 currhosttxbuffaddr; /* 0x50 */
  84. u32 currhostrxbuffaddr; /* 0x54 */
  85. };
  86. #define DW_DMA_BASE_OFFSET (0x1000)
  87. /* Bus mode register definitions */
  88. #define FIXEDBURST (1 << 16)
  89. #define PRIORXTX_41 (3 << 14)
  90. #define PRIORXTX_31 (2 << 14)
  91. #define PRIORXTX_21 (1 << 14)
  92. #define PRIORXTX_11 (0 << 14)
  93. #define BURST_1 (1 << 8)
  94. #define BURST_2 (2 << 8)
  95. #define BURST_4 (4 << 8)
  96. #define BURST_8 (8 << 8)
  97. #define BURST_16 (16 << 8)
  98. #define BURST_32 (32 << 8)
  99. #define RXHIGHPRIO (1 << 1)
  100. #define DMAMAC_SRST (1 << 0)
  101. /* Poll demand definitions */
  102. #define POLL_DATA (0xFFFFFFFF)
  103. /* Operation mode definitions */
  104. #define STOREFORWARD (1 << 21)
  105. #define FLUSHTXFIFO (1 << 20)
  106. #define TXSTART (1 << 13)
  107. #define TXSECONDFRAME (1 << 2)
  108. #define RXSTART (1 << 1)
  109. /* Descriptior related definitions */
  110. #define MAC_MAX_FRAME_SZ (1600)
  111. struct dmamacdescr {
  112. u32 txrx_status;
  113. u32 dmamac_cntl;
  114. void *dmamac_addr;
  115. struct dmamacdescr *dmamac_next;
  116. };
  117. /*
  118. * txrx_status definitions
  119. */
  120. /* tx status bits definitions */
  121. #if defined(CONFIG_DW_ALTDESCRIPTOR)
  122. #define DESC_TXSTS_OWNBYDMA (1 << 31)
  123. #define DESC_TXSTS_TXINT (1 << 30)
  124. #define DESC_TXSTS_TXLAST (1 << 29)
  125. #define DESC_TXSTS_TXFIRST (1 << 28)
  126. #define DESC_TXSTS_TXCRCDIS (1 << 27)
  127. #define DESC_TXSTS_TXPADDIS (1 << 26)
  128. #define DESC_TXSTS_TXCHECKINSCTRL (3 << 22)
  129. #define DESC_TXSTS_TXRINGEND (1 << 21)
  130. #define DESC_TXSTS_TXCHAIN (1 << 20)
  131. #define DESC_TXSTS_MSK (0x1FFFF << 0)
  132. #else
  133. #define DESC_TXSTS_OWNBYDMA (1 << 31)
  134. #define DESC_TXSTS_MSK (0x1FFFF << 0)
  135. #endif
  136. /* rx status bits definitions */
  137. #define DESC_RXSTS_OWNBYDMA (1 << 31)
  138. #define DESC_RXSTS_DAFILTERFAIL (1 << 30)
  139. #define DESC_RXSTS_FRMLENMSK (0x3FFF << 16)
  140. #define DESC_RXSTS_FRMLENSHFT (16)
  141. #define DESC_RXSTS_ERROR (1 << 15)
  142. #define DESC_RXSTS_RXTRUNCATED (1 << 14)
  143. #define DESC_RXSTS_SAFILTERFAIL (1 << 13)
  144. #define DESC_RXSTS_RXIPC_GIANTFRAME (1 << 12)
  145. #define DESC_RXSTS_RXDAMAGED (1 << 11)
  146. #define DESC_RXSTS_RXVLANTAG (1 << 10)
  147. #define DESC_RXSTS_RXFIRST (1 << 9)
  148. #define DESC_RXSTS_RXLAST (1 << 8)
  149. #define DESC_RXSTS_RXIPC_GIANT (1 << 7)
  150. #define DESC_RXSTS_RXCOLLISION (1 << 6)
  151. #define DESC_RXSTS_RXFRAMEETHER (1 << 5)
  152. #define DESC_RXSTS_RXWATCHDOG (1 << 4)
  153. #define DESC_RXSTS_RXMIIERROR (1 << 3)
  154. #define DESC_RXSTS_RXDRIBBLING (1 << 2)
  155. #define DESC_RXSTS_RXCRC (1 << 1)
  156. /*
  157. * dmamac_cntl definitions
  158. */
  159. /* tx control bits definitions */
  160. #if defined(CONFIG_DW_ALTDESCRIPTOR)
  161. #define DESC_TXCTRL_SIZE1MASK (0x1FFF << 0)
  162. #define DESC_TXCTRL_SIZE1SHFT (0)
  163. #define DESC_TXCTRL_SIZE2MASK (0x1FFF << 16)
  164. #define DESC_TXCTRL_SIZE2SHFT (16)
  165. #else
  166. #define DESC_TXCTRL_TXINT (1 << 31)
  167. #define DESC_TXCTRL_TXLAST (1 << 30)
  168. #define DESC_TXCTRL_TXFIRST (1 << 29)
  169. #define DESC_TXCTRL_TXCHECKINSCTRL (3 << 27)
  170. #define DESC_TXCTRL_TXCRCDIS (1 << 26)
  171. #define DESC_TXCTRL_TXRINGEND (1 << 25)
  172. #define DESC_TXCTRL_TXCHAIN (1 << 24)
  173. #define DESC_TXCTRL_SIZE1MASK (0x7FF << 0)
  174. #define DESC_TXCTRL_SIZE1SHFT (0)
  175. #define DESC_TXCTRL_SIZE2MASK (0x7FF << 11)
  176. #define DESC_TXCTRL_SIZE2SHFT (11)
  177. #endif
  178. /* rx control bits definitions */
  179. #if defined(CONFIG_DW_ALTDESCRIPTOR)
  180. #define DESC_RXCTRL_RXINTDIS (1 << 31)
  181. #define DESC_RXCTRL_RXRINGEND (1 << 15)
  182. #define DESC_RXCTRL_RXCHAIN (1 << 14)
  183. #define DESC_RXCTRL_SIZE1MASK (0x1FFF << 0)
  184. #define DESC_RXCTRL_SIZE1SHFT (0)
  185. #define DESC_RXCTRL_SIZE2MASK (0x1FFF << 16)
  186. #define DESC_RXCTRL_SIZE2SHFT (16)
  187. #else
  188. #define DESC_RXCTRL_RXINTDIS (1 << 31)
  189. #define DESC_RXCTRL_RXRINGEND (1 << 25)
  190. #define DESC_RXCTRL_RXCHAIN (1 << 24)
  191. #define DESC_RXCTRL_SIZE1MASK (0x7FF << 0)
  192. #define DESC_RXCTRL_SIZE1SHFT (0)
  193. #define DESC_RXCTRL_SIZE2MASK (0x7FF << 11)
  194. #define DESC_RXCTRL_SIZE2SHFT (11)
  195. #endif
  196. struct dw_eth_dev {
  197. u32 address;
  198. u32 speed;
  199. u32 duplex;
  200. u32 tx_currdescnum;
  201. u32 rx_currdescnum;
  202. u32 phy_configured;
  203. u32 padding;
  204. struct dmamacdescr tx_mac_descrtable[CONFIG_TX_DESCR_NUM];
  205. struct dmamacdescr rx_mac_descrtable[CONFIG_RX_DESCR_NUM];
  206. char txbuffs[TX_TOTAL_BUFSIZE];
  207. char rxbuffs[RX_TOTAL_BUFSIZE];
  208. struct eth_mac_regs *mac_regs_p;
  209. struct eth_dma_regs *dma_regs_p;
  210. struct eth_device *dev;
  211. } __attribute__ ((aligned(8)));
  212. /* Speed specific definitions */
  213. #define SPEED_10M 1
  214. #define SPEED_100M 2
  215. #define SPEED_1000M 3
  216. /* Duplex mode specific definitions */
  217. #define HALF_DUPLEX 1
  218. #define FULL_DUPLEX 2
  219. #endif