norm_desc.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*******************************************************************************
  2. This contains the functions to handle the normal descriptors.
  3. Copyright (C) 2007-2009 STMicroelectronics Ltd
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  17. *******************************************************************************/
  18. #include <linux/stmmac.h>
  19. #include "common.h"
  20. #include "descs_com.h"
  21. static int ndesc_get_tx_status(void *data, struct stmmac_extra_stats *x,
  22. struct dma_desc *p, void __iomem *ioaddr)
  23. {
  24. int ret = 0;
  25. struct net_device_stats *stats = (struct net_device_stats *)data;
  26. if (unlikely(p->des01.tx.error_summary)) {
  27. if (unlikely(p->des01.tx.underflow_error)) {
  28. x->tx_underflow++;
  29. stats->tx_fifo_errors++;
  30. }
  31. if (unlikely(p->des01.tx.no_carrier)) {
  32. x->tx_carrier++;
  33. stats->tx_carrier_errors++;
  34. }
  35. if (unlikely(p->des01.tx.loss_carrier)) {
  36. x->tx_losscarrier++;
  37. stats->tx_carrier_errors++;
  38. }
  39. if (unlikely((p->des01.tx.excessive_deferral) ||
  40. (p->des01.tx.excessive_collisions) ||
  41. (p->des01.tx.late_collision)))
  42. stats->collisions += p->des01.tx.collision_count;
  43. ret = -1;
  44. }
  45. if (p->des01.etx.vlan_frame)
  46. x->tx_vlan++;
  47. if (unlikely(p->des01.tx.deferred))
  48. x->tx_deferred++;
  49. return ret;
  50. }
  51. static int ndesc_get_tx_len(struct dma_desc *p)
  52. {
  53. return p->des01.tx.buffer1_size;
  54. }
  55. /* This function verifies if each incoming frame has some errors
  56. * and, if required, updates the multicast statistics.
  57. * In case of success, it returns good_frame because the GMAC device
  58. * is supposed to be able to compute the csum in HW. */
  59. static int ndesc_get_rx_status(void *data, struct stmmac_extra_stats *x,
  60. struct dma_desc *p)
  61. {
  62. int ret = good_frame;
  63. struct net_device_stats *stats = (struct net_device_stats *)data;
  64. if (unlikely(p->des01.rx.last_descriptor == 0)) {
  65. pr_warn("%s: Oversized frame spanned multiple buffers\n",
  66. __func__);
  67. stats->rx_length_errors++;
  68. return discard_frame;
  69. }
  70. if (unlikely(p->des01.rx.error_summary)) {
  71. if (unlikely(p->des01.rx.descriptor_error))
  72. x->rx_desc++;
  73. if (unlikely(p->des01.rx.sa_filter_fail))
  74. x->sa_filter_fail++;
  75. if (unlikely(p->des01.rx.overflow_error))
  76. x->overflow_error++;
  77. if (unlikely(p->des01.rx.ipc_csum_error))
  78. x->ipc_csum_error++;
  79. if (unlikely(p->des01.rx.collision)) {
  80. x->rx_collision++;
  81. stats->collisions++;
  82. }
  83. if (unlikely(p->des01.rx.crc_error)) {
  84. x->rx_crc++;
  85. stats->rx_crc_errors++;
  86. }
  87. ret = discard_frame;
  88. }
  89. if (unlikely(p->des01.rx.dribbling))
  90. x->dribbling_bit++;
  91. if (unlikely(p->des01.rx.length_error)) {
  92. x->rx_length++;
  93. ret = discard_frame;
  94. }
  95. if (unlikely(p->des01.rx.mii_error)) {
  96. x->rx_mii++;
  97. ret = discard_frame;
  98. }
  99. #ifdef STMMAC_VLAN_TAG_USED
  100. if (p->des01.rx.vlan_tag)
  101. x->vlan_tag++;
  102. #endif
  103. return ret;
  104. }
  105. static void ndesc_init_rx_desc(struct dma_desc *p, int disable_rx_ic, int mode,
  106. int end)
  107. {
  108. p->des01.all_flags = 0;
  109. p->des01.rx.own = 1;
  110. p->des01.rx.buffer1_size = BUF_SIZE_2KiB - 1;
  111. if (mode == STMMAC_CHAIN_MODE)
  112. ndesc_rx_set_on_chain(p, end);
  113. else
  114. ndesc_rx_set_on_ring(p, end);
  115. if (disable_rx_ic)
  116. p->des01.rx.disable_ic = 1;
  117. }
  118. static void ndesc_init_tx_desc(struct dma_desc *p, int mode, int end)
  119. {
  120. p->des01.all_flags = 0;
  121. if (mode == STMMAC_CHAIN_MODE)
  122. ndesc_tx_set_on_chain(p, end);
  123. else
  124. ndesc_tx_set_on_ring(p, end);
  125. }
  126. static int ndesc_get_tx_owner(struct dma_desc *p)
  127. {
  128. return p->des01.tx.own;
  129. }
  130. static int ndesc_get_rx_owner(struct dma_desc *p)
  131. {
  132. return p->des01.rx.own;
  133. }
  134. static void ndesc_set_tx_owner(struct dma_desc *p)
  135. {
  136. p->des01.tx.own = 1;
  137. }
  138. static void ndesc_set_rx_owner(struct dma_desc *p)
  139. {
  140. p->des01.rx.own = 1;
  141. }
  142. static int ndesc_get_tx_ls(struct dma_desc *p)
  143. {
  144. return p->des01.tx.last_segment;
  145. }
  146. static void ndesc_release_tx_desc(struct dma_desc *p, int mode)
  147. {
  148. int ter = p->des01.tx.end_ring;
  149. memset(p, 0, offsetof(struct dma_desc, des2));
  150. if (mode == STMMAC_CHAIN_MODE)
  151. ndesc_end_tx_desc_on_chain(p, ter);
  152. else
  153. ndesc_end_tx_desc_on_ring(p, ter);
  154. }
  155. static void ndesc_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,
  156. int csum_flag, int mode)
  157. {
  158. p->des01.tx.first_segment = is_fs;
  159. if (mode == STMMAC_CHAIN_MODE)
  160. norm_set_tx_desc_len_on_chain(p, len);
  161. else
  162. norm_set_tx_desc_len_on_ring(p, len);
  163. if (likely(csum_flag))
  164. p->des01.tx.checksum_insertion = cic_full;
  165. }
  166. static void ndesc_clear_tx_ic(struct dma_desc *p)
  167. {
  168. p->des01.tx.interrupt = 0;
  169. }
  170. static void ndesc_close_tx_desc(struct dma_desc *p)
  171. {
  172. p->des01.tx.last_segment = 1;
  173. p->des01.tx.interrupt = 1;
  174. }
  175. static int ndesc_get_rx_frame_len(struct dma_desc *p, int rx_coe_type)
  176. {
  177. /* The type-1 checksum offload engines append the checksum at
  178. * the end of frame and the two bytes of checksum are added in
  179. * the length.
  180. * Adjust for that in the framelen for type-1 checksum offload
  181. * engines. */
  182. if (rx_coe_type == STMMAC_RX_COE_TYPE1)
  183. return p->des01.rx.frame_length - 2;
  184. else
  185. return p->des01.rx.frame_length;
  186. }
  187. static void ndesc_enable_tx_timestamp(struct dma_desc *p)
  188. {
  189. p->des01.tx.time_stamp_enable = 1;
  190. }
  191. static int ndesc_get_tx_timestamp_status(struct dma_desc *p)
  192. {
  193. return p->des01.tx.time_stamp_status;
  194. }
  195. static u64 ndesc_get_timestamp(void *desc, u32 ats)
  196. {
  197. struct dma_desc *p = (struct dma_desc *)desc;
  198. u64 ns;
  199. ns = p->des2;
  200. /* convert high/sec time stamp value to nanosecond */
  201. ns += p->des3 * 1000000000ULL;
  202. return ns;
  203. }
  204. static int ndesc_get_rx_timestamp_status(void *desc, u32 ats)
  205. {
  206. struct dma_desc *p = (struct dma_desc *)desc;
  207. if ((p->des2 == 0xffffffff) && (p->des3 == 0xffffffff))
  208. /* timestamp is corrupted, hence don't store it */
  209. return 0;
  210. else
  211. return 1;
  212. }
  213. const struct stmmac_desc_ops ndesc_ops = {
  214. .tx_status = ndesc_get_tx_status,
  215. .rx_status = ndesc_get_rx_status,
  216. .get_tx_len = ndesc_get_tx_len,
  217. .init_rx_desc = ndesc_init_rx_desc,
  218. .init_tx_desc = ndesc_init_tx_desc,
  219. .get_tx_owner = ndesc_get_tx_owner,
  220. .get_rx_owner = ndesc_get_rx_owner,
  221. .release_tx_desc = ndesc_release_tx_desc,
  222. .prepare_tx_desc = ndesc_prepare_tx_desc,
  223. .clear_tx_ic = ndesc_clear_tx_ic,
  224. .close_tx_desc = ndesc_close_tx_desc,
  225. .get_tx_ls = ndesc_get_tx_ls,
  226. .set_tx_owner = ndesc_set_tx_owner,
  227. .set_rx_owner = ndesc_set_rx_owner,
  228. .get_rx_frame_len = ndesc_get_rx_frame_len,
  229. .enable_tx_timestamp = ndesc_enable_tx_timestamp,
  230. .get_tx_timestamp_status = ndesc_get_tx_timestamp_status,
  231. .get_timestamp = ndesc_get_timestamp,
  232. .get_rx_timestamp_status = ndesc_get_rx_timestamp_status,
  233. };