ring_mode.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 entry = priv->cur_tx;
  26. struct dma_desc *desc;
  27. unsigned int nopaged_len = skb_headlen(skb);
  28. unsigned int bmax, len;
  29. if (priv->extend_desc)
  30. desc = (struct dma_desc *)(priv->dma_etx + entry);
  31. else
  32. desc = priv->dma_tx + entry;
  33. if (priv->plat->enh_desc)
  34. bmax = BUF_SIZE_8KiB;
  35. else
  36. bmax = BUF_SIZE_2KiB;
  37. len = nopaged_len - bmax;
  38. if (nopaged_len > BUF_SIZE_8KiB) {
  39. desc->des2 = dma_map_single(priv->device, skb->data,
  40. bmax, DMA_TO_DEVICE);
  41. if (dma_mapping_error(priv->device, desc->des2))
  42. return -1;
  43. priv->tx_skbuff_dma[entry].buf = desc->des2;
  44. priv->tx_skbuff_dma[entry].len = bmax;
  45. priv->tx_skbuff_dma[entry].is_jumbo = true;
  46. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  47. priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum,
  48. STMMAC_RING_MODE, 0, false);
  49. priv->tx_skbuff[entry] = NULL;
  50. entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
  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. priv->tx_skbuff_dma[entry].len = len;
  61. priv->tx_skbuff_dma[entry].is_jumbo = true;
  62. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  63. priv->hw->desc->prepare_tx_desc(desc, 0, len, csum,
  64. STMMAC_RING_MODE, 1, true);
  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. priv->tx_skbuff_dma[entry].len = nopaged_len;
  72. priv->tx_skbuff_dma[entry].is_jumbo = true;
  73. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  74. priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, csum,
  75. STMMAC_RING_MODE, 0, true);
  76. }
  77. priv->cur_tx = entry;
  78. return entry;
  79. }
  80. static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
  81. {
  82. unsigned int ret = 0;
  83. if (len >= BUF_SIZE_4KiB)
  84. ret = 1;
  85. return ret;
  86. }
  87. static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
  88. {
  89. struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
  90. /* Fill DES3 in case of RING mode */
  91. if (priv->dma_buf_sz >= BUF_SIZE_8KiB)
  92. p->des3 = p->des2 + BUF_SIZE_8KiB;
  93. }
  94. /* In ring mode we need to fill the desc3 because it is used as buffer */
  95. static void stmmac_init_desc3(struct dma_desc *p)
  96. {
  97. p->des3 = p->des2 + BUF_SIZE_8KiB;
  98. }
  99. static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
  100. {
  101. struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
  102. unsigned int entry = priv->dirty_tx;
  103. /* des3 is only used for jumbo frames tx or time stamping */
  104. if (unlikely(priv->tx_skbuff_dma[entry].is_jumbo ||
  105. (priv->tx_skbuff_dma[entry].last_segment &&
  106. !priv->extend_desc && priv->hwts_tx_en)))
  107. p->des3 = 0;
  108. }
  109. static int stmmac_set_16kib_bfsize(int mtu)
  110. {
  111. int ret = 0;
  112. if (unlikely(mtu >= BUF_SIZE_8KiB))
  113. ret = BUF_SIZE_16KiB;
  114. return ret;
  115. }
  116. const struct stmmac_mode_ops ring_mode_ops = {
  117. .is_jumbo_frm = stmmac_is_jumbo_frm,
  118. .jumbo_frm = stmmac_jumbo_frm,
  119. .refill_desc3 = stmmac_refill_desc3,
  120. .init_desc3 = stmmac_init_desc3,
  121. .clean_desc3 = stmmac_clean_desc3,
  122. .set_16kib_bfsize = stmmac_set_16kib_bfsize,
  123. };