dwmac1000_dma.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*******************************************************************************
  2. This is the driver for the GMAC on-chip Ethernet controller for ST SoCs.
  3. DWC Ether MAC 10/100/1000 Universal version 3.41a has been used for
  4. developing this code.
  5. This contains the functions to handle the dma.
  6. Copyright (C) 2007-2009 STMicroelectronics Ltd
  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. This program is distributed in the hope it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. more details.
  14. You should have received a copy of the GNU General Public License along with
  15. this program; if not, write to the Free Software Foundation, Inc.,
  16. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. The full GNU General Public License is included in this distribution in
  18. the file called "COPYING".
  19. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  20. *******************************************************************************/
  21. #include <asm/io.h>
  22. #include "dwmac1000.h"
  23. #include "dwmac_dma.h"
  24. static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
  25. {
  26. u32 value = readl(ioaddr + DMA_AXI_BUS_MODE);
  27. int i;
  28. pr_info("dwmac1000: Master AXI performs %s burst length\n",
  29. !(value & DMA_AXI_UNDEF) ? "fixed" : "any");
  30. if (axi->axi_lpi_en)
  31. value |= DMA_AXI_EN_LPI;
  32. if (axi->axi_xit_frm)
  33. value |= DMA_AXI_LPI_XIT_FRM;
  34. value &= ~DMA_AXI_WR_OSR_LMT;
  35. value |= (axi->axi_wr_osr_lmt & DMA_AXI_WR_OSR_LMT_MASK) <<
  36. DMA_AXI_WR_OSR_LMT_SHIFT;
  37. value &= ~DMA_AXI_RD_OSR_LMT;
  38. value |= (axi->axi_rd_osr_lmt & DMA_AXI_RD_OSR_LMT_MASK) <<
  39. DMA_AXI_RD_OSR_LMT_SHIFT;
  40. /* Depending on the UNDEF bit the Master AXI will perform any burst
  41. * length according to the BLEN programmed (by default all BLEN are
  42. * set).
  43. */
  44. for (i = 0; i < AXI_BLEN; i++) {
  45. switch (axi->axi_blen[i]) {
  46. case 256:
  47. value |= DMA_AXI_BLEN256;
  48. break;
  49. case 128:
  50. value |= DMA_AXI_BLEN128;
  51. break;
  52. case 64:
  53. value |= DMA_AXI_BLEN64;
  54. break;
  55. case 32:
  56. value |= DMA_AXI_BLEN32;
  57. break;
  58. case 16:
  59. value |= DMA_AXI_BLEN16;
  60. break;
  61. case 8:
  62. value |= DMA_AXI_BLEN8;
  63. break;
  64. case 4:
  65. value |= DMA_AXI_BLEN4;
  66. break;
  67. }
  68. }
  69. writel(value, ioaddr + DMA_AXI_BUS_MODE);
  70. }
  71. static void dwmac1000_dma_init(void __iomem *ioaddr, int pbl, int fb, int mb,
  72. int aal, u32 dma_tx, u32 dma_rx, int atds)
  73. {
  74. u32 value = readl(ioaddr + DMA_BUS_MODE);
  75. /*
  76. * Set the DMA PBL (Programmable Burst Length) mode.
  77. *
  78. * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
  79. * post 3.5 mode bit acts as 8*PBL.
  80. *
  81. * This configuration doesn't take care about the Separate PBL
  82. * so only the bits: 13-8 are programmed with the PBL passed from the
  83. * platform.
  84. */
  85. value |= DMA_BUS_MODE_MAXPBL;
  86. value &= ~DMA_BUS_MODE_PBL_MASK;
  87. value |= (pbl << DMA_BUS_MODE_PBL_SHIFT);
  88. /* Set the Fixed burst mode */
  89. if (fb)
  90. value |= DMA_BUS_MODE_FB;
  91. /* Mixed Burst has no effect when fb is set */
  92. if (mb)
  93. value |= DMA_BUS_MODE_MB;
  94. if (atds)
  95. value |= DMA_BUS_MODE_ATDS;
  96. if (aal)
  97. value |= DMA_BUS_MODE_AAL;
  98. writel(value, ioaddr + DMA_BUS_MODE);
  99. /* Mask interrupts by writing to CSR7 */
  100. writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
  101. /* RX/TX descriptor base address lists must be written into
  102. * DMA CSR3 and CSR4, respectively
  103. */
  104. writel(dma_tx, ioaddr + DMA_TX_BASE_ADDR);
  105. writel(dma_rx, ioaddr + DMA_RCV_BASE_ADDR);
  106. }
  107. static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
  108. {
  109. csr6 &= ~DMA_CONTROL_RFA_MASK;
  110. csr6 &= ~DMA_CONTROL_RFD_MASK;
  111. /* Leave flow control disabled if receive fifo size is less than
  112. * 4K or 0. Otherwise, send XOFF when fifo is 1K less than full,
  113. * and send XON when 2K less than full.
  114. */
  115. if (rxfifosz < 4096) {
  116. csr6 &= ~DMA_CONTROL_EFC;
  117. pr_debug("GMAC: disabling flow control, rxfifo too small(%d)\n",
  118. rxfifosz);
  119. } else {
  120. csr6 |= DMA_CONTROL_EFC;
  121. csr6 |= RFA_FULL_MINUS_1K;
  122. csr6 |= RFD_FULL_MINUS_2K;
  123. }
  124. return csr6;
  125. }
  126. static void dwmac1000_dma_operation_mode(void __iomem *ioaddr, int txmode,
  127. int rxmode, int rxfifosz)
  128. {
  129. u32 csr6 = readl(ioaddr + DMA_CONTROL);
  130. if (txmode == SF_DMA_MODE) {
  131. pr_debug("GMAC: enable TX store and forward mode\n");
  132. /* Transmit COE type 2 cannot be done in cut-through mode. */
  133. csr6 |= DMA_CONTROL_TSF;
  134. /* Operating on second frame increase the performance
  135. * especially when transmit store-and-forward is used.
  136. */
  137. csr6 |= DMA_CONTROL_OSF;
  138. } else {
  139. pr_debug("GMAC: disabling TX SF (threshold %d)\n", txmode);
  140. csr6 &= ~DMA_CONTROL_TSF;
  141. csr6 &= DMA_CONTROL_TC_TX_MASK;
  142. /* Set the transmit threshold */
  143. if (txmode <= 32)
  144. csr6 |= DMA_CONTROL_TTC_32;
  145. else if (txmode <= 64)
  146. csr6 |= DMA_CONTROL_TTC_64;
  147. else if (txmode <= 128)
  148. csr6 |= DMA_CONTROL_TTC_128;
  149. else if (txmode <= 192)
  150. csr6 |= DMA_CONTROL_TTC_192;
  151. else
  152. csr6 |= DMA_CONTROL_TTC_256;
  153. }
  154. if (rxmode == SF_DMA_MODE) {
  155. pr_debug("GMAC: enable RX store and forward mode\n");
  156. csr6 |= DMA_CONTROL_RSF;
  157. } else {
  158. pr_debug("GMAC: disable RX SF mode (threshold %d)\n", rxmode);
  159. csr6 &= ~DMA_CONTROL_RSF;
  160. csr6 &= DMA_CONTROL_TC_RX_MASK;
  161. if (rxmode <= 32)
  162. csr6 |= DMA_CONTROL_RTC_32;
  163. else if (rxmode <= 64)
  164. csr6 |= DMA_CONTROL_RTC_64;
  165. else if (rxmode <= 96)
  166. csr6 |= DMA_CONTROL_RTC_96;
  167. else
  168. csr6 |= DMA_CONTROL_RTC_128;
  169. }
  170. /* Configure flow control based on rx fifo size */
  171. csr6 = dwmac1000_configure_fc(csr6, rxfifosz);
  172. writel(csr6, ioaddr + DMA_CONTROL);
  173. }
  174. static void dwmac1000_dump_dma_regs(void __iomem *ioaddr)
  175. {
  176. int i;
  177. pr_info(" DMA registers\n");
  178. for (i = 0; i < 22; i++) {
  179. if ((i < 9) || (i > 17)) {
  180. int offset = i * 4;
  181. pr_err("\t Reg No. %d (offset 0x%x): 0x%08x\n", i,
  182. (DMA_BUS_MODE + offset),
  183. readl(ioaddr + DMA_BUS_MODE + offset));
  184. }
  185. }
  186. }
  187. static void dwmac1000_get_hw_feature(void __iomem *ioaddr,
  188. struct dma_features *dma_cap)
  189. {
  190. u32 hw_cap = readl(ioaddr + DMA_HW_FEATURE);
  191. dma_cap->mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
  192. dma_cap->mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
  193. dma_cap->half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
  194. dma_cap->hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
  195. dma_cap->multi_addr = (hw_cap & DMA_HW_FEAT_ADDMAC) >> 5;
  196. dma_cap->pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
  197. dma_cap->sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
  198. dma_cap->pmt_remote_wake_up = (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
  199. dma_cap->pmt_magic_frame = (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
  200. /* MMC */
  201. dma_cap->rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
  202. /* IEEE 1588-2002 */
  203. dma_cap->time_stamp =
  204. (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
  205. /* IEEE 1588-2008 */
  206. dma_cap->atime_stamp = (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
  207. /* 802.3az - Energy-Efficient Ethernet (EEE) */
  208. dma_cap->eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
  209. dma_cap->av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
  210. /* TX and RX csum */
  211. dma_cap->tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
  212. dma_cap->rx_coe_type1 = (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
  213. dma_cap->rx_coe_type2 = (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
  214. dma_cap->rxfifo_over_2048 = (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
  215. /* TX and RX number of channels */
  216. dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
  217. dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
  218. /* Alternate (enhanced) DESC mode */
  219. dma_cap->enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
  220. }
  221. static void dwmac1000_rx_watchdog(void __iomem *ioaddr, u32 riwt)
  222. {
  223. writel(riwt, ioaddr + DMA_RX_WATCHDOG);
  224. }
  225. const struct stmmac_dma_ops dwmac1000_dma_ops = {
  226. .reset = dwmac_dma_reset,
  227. .init = dwmac1000_dma_init,
  228. .axi = dwmac1000_dma_axi,
  229. .dump_regs = dwmac1000_dump_dma_regs,
  230. .dma_mode = dwmac1000_dma_operation_mode,
  231. .enable_dma_transmission = dwmac_enable_dma_transmission,
  232. .enable_dma_irq = dwmac_enable_dma_irq,
  233. .disable_dma_irq = dwmac_disable_dma_irq,
  234. .start_tx = dwmac_dma_start_tx,
  235. .stop_tx = dwmac_dma_stop_tx,
  236. .start_rx = dwmac_dma_start_rx,
  237. .stop_rx = dwmac_dma_stop_rx,
  238. .dma_interrupt = dwmac_dma_interrupt,
  239. .get_hw_feature = dwmac1000_get_hw_feature,
  240. .rx_watchdog = dwmac1000_rx_watchdog,
  241. };