dwmac1000_dma.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 int dwmac1000_dma_init(void __iomem *ioaddr, int pbl, int fb,
  25. int mb, int burst_len, u32 dma_tx, u32 dma_rx)
  26. {
  27. u32 value = readl(ioaddr + DMA_BUS_MODE);
  28. int limit;
  29. /* DMA SW reset */
  30. value |= DMA_BUS_MODE_SFT_RESET;
  31. writel(value, ioaddr + DMA_BUS_MODE);
  32. limit = 10;
  33. while (limit--) {
  34. if (!(readl(ioaddr + DMA_BUS_MODE) & DMA_BUS_MODE_SFT_RESET))
  35. break;
  36. mdelay(10);
  37. }
  38. if (limit < 0)
  39. return -EBUSY;
  40. /*
  41. * Set the DMA PBL (Programmable Burst Length) mode
  42. * Before stmmac core 3.50 this mode bit was 4xPBL, and
  43. * post 3.5 mode bit acts as 8*PBL.
  44. * For core rev < 3.5, when the core is set for 4xPBL mode, the
  45. * DMA transfers the data in 4, 8, 16, 32, 64 & 128 beats
  46. * depending on pbl value.
  47. * For core rev > 3.5, when the core is set for 8xPBL mode, the
  48. * DMA transfers the data in 8, 16, 32, 64, 128 & 256 beats
  49. * depending on pbl value.
  50. */
  51. value = DMA_BUS_MODE_PBL | ((pbl << DMA_BUS_MODE_PBL_SHIFT) |
  52. (pbl << DMA_BUS_MODE_RPBL_SHIFT));
  53. /* Set the Fixed burst mode */
  54. if (fb)
  55. value |= DMA_BUS_MODE_FB;
  56. /* Mixed Burst has no effect when fb is set */
  57. if (mb)
  58. value |= DMA_BUS_MODE_MB;
  59. #ifdef CONFIG_STMMAC_DA
  60. value |= DMA_BUS_MODE_DA; /* Rx has priority over tx */
  61. #endif
  62. writel(value, ioaddr + DMA_BUS_MODE);
  63. /* In case of GMAC AXI configuration, program the DMA_AXI_BUS_MODE
  64. * for supported bursts.
  65. *
  66. * Note: This is applicable only for revision GMACv3.61a. For
  67. * older version this register is reserved and shall have no
  68. * effect.
  69. *
  70. * Note:
  71. * For Fixed Burst Mode: if we directly write 0xFF to this
  72. * register using the configurations pass from platform code,
  73. * this would ensure that all bursts supported by core are set
  74. * and those which are not supported would remain ineffective.
  75. *
  76. * For Non Fixed Burst Mode: provide the maximum value of the
  77. * burst length. Any burst equal or below the provided burst
  78. * length would be allowed to perform. */
  79. writel(burst_len, ioaddr + DMA_AXI_BUS_MODE);
  80. /* Mask interrupts by writing to CSR7 */
  81. writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
  82. /* The base address of the RX/TX descriptor lists must be written into
  83. * DMA CSR3 and CSR4, respectively. */
  84. writel(dma_tx, ioaddr + DMA_TX_BASE_ADDR);
  85. writel(dma_rx, ioaddr + DMA_RCV_BASE_ADDR);
  86. return 0;
  87. }
  88. static void dwmac1000_dma_operation_mode(void __iomem *ioaddr, int txmode,
  89. int rxmode)
  90. {
  91. u32 csr6 = readl(ioaddr + DMA_CONTROL);
  92. if (txmode == SF_DMA_MODE) {
  93. CHIP_DBG(KERN_DEBUG "GMAC: enable TX store and forward mode\n");
  94. /* Transmit COE type 2 cannot be done in cut-through mode. */
  95. csr6 |= DMA_CONTROL_TSF;
  96. /* Operating on second frame increase the performance
  97. * especially when transmit store-and-forward is used.*/
  98. csr6 |= DMA_CONTROL_OSF;
  99. } else {
  100. CHIP_DBG(KERN_DEBUG "GMAC: disabling TX store and forward mode"
  101. " (threshold = %d)\n", txmode);
  102. csr6 &= ~DMA_CONTROL_TSF;
  103. csr6 &= DMA_CONTROL_TC_TX_MASK;
  104. /* Set the transmit threshold */
  105. if (txmode <= 32)
  106. csr6 |= DMA_CONTROL_TTC_32;
  107. else if (txmode <= 64)
  108. csr6 |= DMA_CONTROL_TTC_64;
  109. else if (txmode <= 128)
  110. csr6 |= DMA_CONTROL_TTC_128;
  111. else if (txmode <= 192)
  112. csr6 |= DMA_CONTROL_TTC_192;
  113. else
  114. csr6 |= DMA_CONTROL_TTC_256;
  115. }
  116. if (rxmode == SF_DMA_MODE) {
  117. CHIP_DBG(KERN_DEBUG "GMAC: enable RX store and forward mode\n");
  118. csr6 |= DMA_CONTROL_RSF;
  119. } else {
  120. CHIP_DBG(KERN_DEBUG "GMAC: disabling RX store and forward mode"
  121. " (threshold = %d)\n", rxmode);
  122. csr6 &= ~DMA_CONTROL_RSF;
  123. csr6 &= DMA_CONTROL_TC_RX_MASK;
  124. if (rxmode <= 32)
  125. csr6 |= DMA_CONTROL_RTC_32;
  126. else if (rxmode <= 64)
  127. csr6 |= DMA_CONTROL_RTC_64;
  128. else if (rxmode <= 96)
  129. csr6 |= DMA_CONTROL_RTC_96;
  130. else
  131. csr6 |= DMA_CONTROL_RTC_128;
  132. }
  133. writel(csr6, ioaddr + DMA_CONTROL);
  134. }
  135. static void dwmac1000_dump_dma_regs(void __iomem *ioaddr)
  136. {
  137. int i;
  138. pr_info(" DMA registers\n");
  139. for (i = 0; i < 22; i++) {
  140. if ((i < 9) || (i > 17)) {
  141. int offset = i * 4;
  142. pr_err("\t Reg No. %d (offset 0x%x): 0x%08x\n", i,
  143. (DMA_BUS_MODE + offset),
  144. readl(ioaddr + DMA_BUS_MODE + offset));
  145. }
  146. }
  147. }
  148. static unsigned int dwmac1000_get_hw_feature(void __iomem *ioaddr)
  149. {
  150. return readl(ioaddr + DMA_HW_FEATURE);
  151. }
  152. static void dwmac1000_rx_watchdog(void __iomem *ioaddr, u32 riwt)
  153. {
  154. writel(riwt, ioaddr + DMA_RX_WATCHDOG);
  155. }
  156. const struct stmmac_dma_ops dwmac1000_dma_ops = {
  157. .init = dwmac1000_dma_init,
  158. .dump_regs = dwmac1000_dump_dma_regs,
  159. .dma_mode = dwmac1000_dma_operation_mode,
  160. .enable_dma_transmission = dwmac_enable_dma_transmission,
  161. .enable_dma_irq = dwmac_enable_dma_irq,
  162. .disable_dma_irq = dwmac_disable_dma_irq,
  163. .start_tx = dwmac_dma_start_tx,
  164. .stop_tx = dwmac_dma_stop_tx,
  165. .start_rx = dwmac_dma_start_rx,
  166. .stop_rx = dwmac_dma_stop_rx,
  167. .dma_interrupt = dwmac_dma_interrupt,
  168. .get_hw_feature = dwmac1000_get_hw_feature,
  169. .rx_watchdog = dwmac1000_rx_watchdog,
  170. };