ring_mode.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 unsigned 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 = priv->dma_tx + entry;
  28. unsigned int nopaged_len = skb_headlen(skb);
  29. unsigned int bmax, len;
  30. if (priv->plat->enh_desc)
  31. bmax = BUF_SIZE_8KiB;
  32. else
  33. bmax = BUF_SIZE_2KiB;
  34. len = nopaged_len - bmax;
  35. if (nopaged_len > BUF_SIZE_8KiB) {
  36. desc->des2 = dma_map_single(priv->device, skb->data,
  37. bmax, DMA_TO_DEVICE);
  38. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  39. priv->hw->desc->prepare_tx_desc(desc, 1, bmax,
  40. csum);
  41. entry = (++priv->cur_tx) % txsize;
  42. desc = priv->dma_tx + entry;
  43. desc->des2 = dma_map_single(priv->device, skb->data + bmax,
  44. len, DMA_TO_DEVICE);
  45. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  46. priv->hw->desc->prepare_tx_desc(desc, 0, len, csum);
  47. priv->hw->desc->set_tx_owner(desc);
  48. priv->tx_skbuff[entry] = NULL;
  49. } else {
  50. desc->des2 = dma_map_single(priv->device, skb->data,
  51. nopaged_len, DMA_TO_DEVICE);
  52. desc->des3 = desc->des2 + BUF_SIZE_4KiB;
  53. priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, csum);
  54. }
  55. return entry;
  56. }
  57. static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
  58. {
  59. unsigned int ret = 0;
  60. if (len >= BUF_SIZE_4KiB)
  61. ret = 1;
  62. return ret;
  63. }
  64. static void stmmac_refill_desc3(int bfsize, struct dma_desc *p)
  65. {
  66. /* Fill DES3 in case of RING mode */
  67. if (bfsize >= BUF_SIZE_8KiB)
  68. p->des3 = p->des2 + BUF_SIZE_8KiB;
  69. }
  70. /* In ring mode we need to fill the desc3 because it is used
  71. * as buffer */
  72. static void stmmac_init_desc3(int des3_as_data_buf, struct dma_desc *p)
  73. {
  74. if (unlikely(des3_as_data_buf))
  75. p->des3 = p->des2 + BUF_SIZE_8KiB;
  76. }
  77. static void stmmac_init_dma_chain(struct dma_desc *des, dma_addr_t phy_addr,
  78. unsigned int size)
  79. {
  80. }
  81. static void stmmac_clean_desc3(struct dma_desc *p)
  82. {
  83. if (unlikely(p->des3))
  84. p->des3 = 0;
  85. }
  86. static int stmmac_set_16kib_bfsize(int mtu)
  87. {
  88. int ret = 0;
  89. if (unlikely(mtu >= BUF_SIZE_8KiB))
  90. ret = BUF_SIZE_16KiB;
  91. return ret;
  92. }
  93. const struct stmmac_ring_mode_ops ring_mode_ops = {
  94. .is_jumbo_frm = stmmac_is_jumbo_frm,
  95. .jumbo_frm = stmmac_jumbo_frm,
  96. .refill_desc3 = stmmac_refill_desc3,
  97. .init_desc3 = stmmac_init_desc3,
  98. .init_dma_chain = stmmac_init_dma_chain,
  99. .clean_desc3 = stmmac_clean_desc3,
  100. .set_16kib_bfsize = stmmac_set_16kib_bfsize,
  101. };