ring_mode.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*******************************************************************************
  2. Specialised functions for managing Ring mode
  3. Copyright(C) 2011 STMicroelectronics Ltd
  4. It defines all the functions used to handle the normal/enhanced
  5. descriptors in case of the DMA is configured to work in chained or
  6. in ring mode.
  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 "stmmac.h"
  22. static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
  23. {
  24. struct stmmac_priv *priv = (struct stmmac_priv *)p;
  25. unsigned int txsize = priv->dma_tx_size;
  26. unsigned int entry = priv->cur_tx % txsize;
  27. struct dma_desc *desc;
  28. unsigned int nopaged_len = skb_headlen(skb);
  29. unsigned int bmax, len;
  30. if (priv->extend_desc)
  31. desc = (struct dma_desc *)(priv->dma_etx + entry);
  32. else
  33. desc = priv->dma_tx + entry;
  34. if (priv->plat->enh_desc)
  35. bmax = BUF_SIZE_8KiB;
  36. else
  37. bmax = BUF_SIZE_2KiB;
  38. len = nopaged_len - bmax;
  39. if (nopaged_len > BUF_SIZE_8KiB) {
  40. desc->des2 = dma_map_single(priv->device, skb->data,
  41. bmax, DMA_TO_DEVICE);
  42. if (dma_mapping_error(priv->device, desc->des2))
  43. return -1;
  44. priv->tx_skbuff_dma[entry].buf = desc->des2;
  45. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  46. priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum,
  47. STMMAC_RING_MODE);
  48. wmb();
  49. priv->tx_skbuff[entry] = NULL;
  50. entry = (++priv->cur_tx) % txsize;
  51. if (priv->extend_desc)
  52. desc = (struct dma_desc *)(priv->dma_etx + entry);
  53. else
  54. desc = priv->dma_tx + entry;
  55. desc->des2 = dma_map_single(priv->device, skb->data + bmax,
  56. len, DMA_TO_DEVICE);
  57. if (dma_mapping_error(priv->device, desc->des2))
  58. return -1;
  59. priv->tx_skbuff_dma[entry].buf = desc->des2;
  60. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  61. priv->hw->desc->prepare_tx_desc(desc, 0, len, csum,
  62. STMMAC_RING_MODE);
  63. wmb();
  64. priv->hw->desc->set_tx_owner(desc);
  65. } else {
  66. desc->des2 = dma_map_single(priv->device, skb->data,
  67. nopaged_len, DMA_TO_DEVICE);
  68. if (dma_mapping_error(priv->device, desc->des2))
  69. return -1;
  70. priv->tx_skbuff_dma[entry].buf = desc->des2;
  71. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  72. priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, csum,
  73. STMMAC_RING_MODE);
  74. }
  75. return entry;
  76. }
  77. static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
  78. {
  79. unsigned int ret = 0;
  80. if (len >= BUF_SIZE_4KiB)
  81. ret = 1;
  82. return ret;
  83. }
  84. static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
  85. {
  86. struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
  87. /* Fill DES3 in case of RING mode */
  88. if (priv->dma_buf_sz >= BUF_SIZE_8KiB)
  89. p->des3 = p->des2 + BUF_SIZE_8KiB;
  90. }
  91. /* In ring mode we need to fill the desc3 because it is used as buffer */
  92. static void stmmac_init_desc3(struct dma_desc *p)
  93. {
  94. p->des3 = p->des2 + BUF_SIZE_8KiB;
  95. }
  96. static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
  97. {
  98. if (unlikely(p->des3))
  99. p->des3 = 0;
  100. }
  101. static int stmmac_set_16kib_bfsize(int mtu)
  102. {
  103. int ret = 0;
  104. if (unlikely(mtu >= BUF_SIZE_8KiB))
  105. ret = BUF_SIZE_16KiB;
  106. return ret;
  107. }
  108. const struct stmmac_mode_ops ring_mode_ops = {
  109. .is_jumbo_frm = stmmac_is_jumbo_frm,
  110. .jumbo_frm = stmmac_jumbo_frm,
  111. .refill_desc3 = stmmac_refill_desc3,
  112. .init_desc3 = stmmac_init_desc3,
  113. .clean_desc3 = stmmac_clean_desc3,
  114. .set_16kib_bfsize = stmmac_set_16kib_bfsize,
  115. };