enh_desc.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*******************************************************************************
  2. This contains the functions to handle the enhanced 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 "common.h"
  19. static int enh_desc_get_tx_status(void *data, struct stmmac_extra_stats *x,
  20. struct dma_desc *p, void __iomem *ioaddr)
  21. {
  22. int ret = 0;
  23. struct net_device_stats *stats = (struct net_device_stats *)data;
  24. if (unlikely(p->des01.etx.error_summary)) {
  25. CHIP_DBG(KERN_ERR "GMAC TX error... 0x%08x\n", p->des01.etx);
  26. if (unlikely(p->des01.etx.jabber_timeout)) {
  27. CHIP_DBG(KERN_ERR "\tjabber_timeout error\n");
  28. x->tx_jabber++;
  29. }
  30. if (unlikely(p->des01.etx.frame_flushed)) {
  31. CHIP_DBG(KERN_ERR "\tframe_flushed error\n");
  32. x->tx_frame_flushed++;
  33. dwmac_dma_flush_tx_fifo(ioaddr);
  34. }
  35. if (unlikely(p->des01.etx.loss_carrier)) {
  36. CHIP_DBG(KERN_ERR "\tloss_carrier error\n");
  37. x->tx_losscarrier++;
  38. stats->tx_carrier_errors++;
  39. }
  40. if (unlikely(p->des01.etx.no_carrier)) {
  41. CHIP_DBG(KERN_ERR "\tno_carrier error\n");
  42. x->tx_carrier++;
  43. stats->tx_carrier_errors++;
  44. }
  45. if (unlikely(p->des01.etx.late_collision)) {
  46. CHIP_DBG(KERN_ERR "\tlate_collision error\n");
  47. stats->collisions += p->des01.etx.collision_count;
  48. }
  49. if (unlikely(p->des01.etx.excessive_collisions)) {
  50. CHIP_DBG(KERN_ERR "\texcessive_collisions\n");
  51. stats->collisions += p->des01.etx.collision_count;
  52. }
  53. if (unlikely(p->des01.etx.excessive_deferral)) {
  54. CHIP_DBG(KERN_INFO "\texcessive tx_deferral\n");
  55. x->tx_deferred++;
  56. }
  57. if (unlikely(p->des01.etx.underflow_error)) {
  58. CHIP_DBG(KERN_ERR "\tunderflow error\n");
  59. dwmac_dma_flush_tx_fifo(ioaddr);
  60. x->tx_underflow++;
  61. }
  62. if (unlikely(p->des01.etx.ip_header_error)) {
  63. CHIP_DBG(KERN_ERR "\tTX IP header csum error\n");
  64. x->tx_ip_header_error++;
  65. }
  66. if (unlikely(p->des01.etx.payload_error)) {
  67. CHIP_DBG(KERN_ERR "\tAddr/Payload csum error\n");
  68. x->tx_payload_error++;
  69. dwmac_dma_flush_tx_fifo(ioaddr);
  70. }
  71. ret = -1;
  72. }
  73. if (unlikely(p->des01.etx.deferred)) {
  74. CHIP_DBG(KERN_INFO "GMAC TX status: tx deferred\n");
  75. x->tx_deferred++;
  76. }
  77. #ifdef STMMAC_VLAN_TAG_USED
  78. if (p->des01.etx.vlan_frame) {
  79. CHIP_DBG(KERN_INFO "GMAC TX status: VLAN frame\n");
  80. x->tx_vlan++;
  81. }
  82. #endif
  83. return ret;
  84. }
  85. static int enh_desc_get_tx_len(struct dma_desc *p)
  86. {
  87. return p->des01.etx.buffer1_size;
  88. }
  89. static int enh_desc_coe_rdes0(int ipc_err, int type, int payload_err)
  90. {
  91. int ret = good_frame;
  92. u32 status = (type << 2 | ipc_err << 1 | payload_err) & 0x7;
  93. /* bits 5 7 0 | Frame status
  94. * ----------------------------------------------------------
  95. * 0 0 0 | IEEE 802.3 Type frame (length < 1536 octects)
  96. * 1 0 0 | IPv4/6 No CSUM errorS.
  97. * 1 0 1 | IPv4/6 CSUM PAYLOAD error
  98. * 1 1 0 | IPv4/6 CSUM IP HR error
  99. * 1 1 1 | IPv4/6 IP PAYLOAD AND HEADER errorS
  100. * 0 0 1 | IPv4/6 unsupported IP PAYLOAD
  101. * 0 1 1 | COE bypassed.. no IPv4/6 frame
  102. * 0 1 0 | Reserved.
  103. */
  104. if (status == 0x0) {
  105. CHIP_DBG(KERN_INFO "RX Des0 status: IEEE 802.3 Type frame.\n");
  106. ret = llc_snap;
  107. } else if (status == 0x4) {
  108. CHIP_DBG(KERN_INFO "RX Des0 status: IPv4/6 No CSUM errorS.\n");
  109. ret = good_frame;
  110. } else if (status == 0x5) {
  111. CHIP_DBG(KERN_ERR "RX Des0 status: IPv4/6 Payload Error.\n");
  112. ret = csum_none;
  113. } else if (status == 0x6) {
  114. CHIP_DBG(KERN_ERR "RX Des0 status: IPv4/6 Header Error.\n");
  115. ret = csum_none;
  116. } else if (status == 0x7) {
  117. CHIP_DBG(KERN_ERR
  118. "RX Des0 status: IPv4/6 Header and Payload Error.\n");
  119. ret = csum_none;
  120. } else if (status == 0x1) {
  121. CHIP_DBG(KERN_ERR
  122. "RX Des0 status: IPv4/6 unsupported IP PAYLOAD.\n");
  123. ret = discard_frame;
  124. } else if (status == 0x3) {
  125. CHIP_DBG(KERN_ERR "RX Des0 status: No IPv4, IPv6 frame.\n");
  126. ret = discard_frame;
  127. }
  128. return ret;
  129. }
  130. static int enh_desc_get_rx_status(void *data, struct stmmac_extra_stats *x,
  131. struct dma_desc *p)
  132. {
  133. int ret = good_frame;
  134. struct net_device_stats *stats = (struct net_device_stats *)data;
  135. if (unlikely(p->des01.erx.error_summary)) {
  136. CHIP_DBG(KERN_ERR "GMAC RX Error Summary 0x%08x\n",
  137. p->des01.erx);
  138. if (unlikely(p->des01.erx.descriptor_error)) {
  139. CHIP_DBG(KERN_ERR "\tdescriptor error\n");
  140. x->rx_desc++;
  141. stats->rx_length_errors++;
  142. }
  143. if (unlikely(p->des01.erx.overflow_error)) {
  144. CHIP_DBG(KERN_ERR "\toverflow error\n");
  145. x->rx_gmac_overflow++;
  146. }
  147. if (unlikely(p->des01.erx.ipc_csum_error))
  148. CHIP_DBG(KERN_ERR "\tIPC Csum Error/Giant frame\n");
  149. if (unlikely(p->des01.erx.late_collision)) {
  150. CHIP_DBG(KERN_ERR "\tlate_collision error\n");
  151. stats->collisions++;
  152. stats->collisions++;
  153. }
  154. if (unlikely(p->des01.erx.receive_watchdog)) {
  155. CHIP_DBG(KERN_ERR "\treceive_watchdog error\n");
  156. x->rx_watchdog++;
  157. }
  158. if (unlikely(p->des01.erx.error_gmii)) {
  159. CHIP_DBG(KERN_ERR "\tReceive Error\n");
  160. x->rx_mii++;
  161. }
  162. if (unlikely(p->des01.erx.crc_error)) {
  163. CHIP_DBG(KERN_ERR "\tCRC error\n");
  164. x->rx_crc++;
  165. stats->rx_crc_errors++;
  166. }
  167. ret = discard_frame;
  168. }
  169. /* After a payload csum error, the ES bit is set.
  170. * It doesn't match with the information reported into the databook.
  171. * At any rate, we need to understand if the CSUM hw computation is ok
  172. * and report this info to the upper layers. */
  173. ret = enh_desc_coe_rdes0(p->des01.erx.ipc_csum_error,
  174. p->des01.erx.frame_type, p->des01.erx.payload_csum_error);
  175. if (unlikely(p->des01.erx.dribbling)) {
  176. CHIP_DBG(KERN_ERR "GMAC RX: dribbling error\n");
  177. ret = discard_frame;
  178. }
  179. if (unlikely(p->des01.erx.sa_filter_fail)) {
  180. CHIP_DBG(KERN_ERR "GMAC RX : Source Address filter fail\n");
  181. x->sa_rx_filter_fail++;
  182. ret = discard_frame;
  183. }
  184. if (unlikely(p->des01.erx.da_filter_fail)) {
  185. CHIP_DBG(KERN_ERR "GMAC RX : Dest Address filter fail\n");
  186. x->da_rx_filter_fail++;
  187. ret = discard_frame;
  188. }
  189. if (unlikely(p->des01.erx.length_error)) {
  190. CHIP_DBG(KERN_ERR "GMAC RX: length_error error\n");
  191. x->rx_length++;
  192. ret = discard_frame;
  193. }
  194. #ifdef STMMAC_VLAN_TAG_USED
  195. if (p->des01.erx.vlan_tag) {
  196. CHIP_DBG(KERN_INFO "GMAC RX: VLAN frame tagged\n");
  197. x->rx_vlan++;
  198. }
  199. #endif
  200. return ret;
  201. }
  202. static void enh_desc_init_rx_desc(struct dma_desc *p, unsigned int ring_size,
  203. int disable_rx_ic)
  204. {
  205. int i;
  206. for (i = 0; i < ring_size; i++) {
  207. p->des01.erx.own = 1;
  208. p->des01.erx.buffer1_size = BUF_SIZE_8KiB - 1;
  209. /* To support jumbo frames */
  210. p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
  211. if (i == ring_size - 1)
  212. p->des01.erx.end_ring = 1;
  213. if (disable_rx_ic)
  214. p->des01.erx.disable_ic = 1;
  215. p++;
  216. }
  217. }
  218. static void enh_desc_init_tx_desc(struct dma_desc *p, unsigned int ring_size)
  219. {
  220. int i;
  221. for (i = 0; i < ring_size; i++) {
  222. p->des01.etx.own = 0;
  223. if (i == ring_size - 1)
  224. p->des01.etx.end_ring = 1;
  225. p++;
  226. }
  227. }
  228. static int enh_desc_get_tx_owner(struct dma_desc *p)
  229. {
  230. return p->des01.etx.own;
  231. }
  232. static int enh_desc_get_rx_owner(struct dma_desc *p)
  233. {
  234. return p->des01.erx.own;
  235. }
  236. static void enh_desc_set_tx_owner(struct dma_desc *p)
  237. {
  238. p->des01.etx.own = 1;
  239. }
  240. static void enh_desc_set_rx_owner(struct dma_desc *p)
  241. {
  242. p->des01.erx.own = 1;
  243. }
  244. static int enh_desc_get_tx_ls(struct dma_desc *p)
  245. {
  246. return p->des01.etx.last_segment;
  247. }
  248. static void enh_desc_release_tx_desc(struct dma_desc *p)
  249. {
  250. int ter = p->des01.etx.end_ring;
  251. memset(p, 0, offsetof(struct dma_desc, des2));
  252. p->des01.etx.end_ring = ter;
  253. }
  254. static void enh_desc_prepare_tx_desc(struct dma_desc *p, int is_fs, int len,
  255. int csum_flag)
  256. {
  257. p->des01.etx.first_segment = is_fs;
  258. if (unlikely(len > BUF_SIZE_4KiB)) {
  259. p->des01.etx.buffer1_size = BUF_SIZE_4KiB;
  260. p->des01.etx.buffer2_size = len - BUF_SIZE_4KiB;
  261. } else {
  262. p->des01.etx.buffer1_size = len;
  263. }
  264. if (likely(csum_flag))
  265. p->des01.etx.checksum_insertion = cic_full;
  266. }
  267. static void enh_desc_clear_tx_ic(struct dma_desc *p)
  268. {
  269. p->des01.etx.interrupt = 0;
  270. }
  271. static void enh_desc_close_tx_desc(struct dma_desc *p)
  272. {
  273. p->des01.etx.last_segment = 1;
  274. p->des01.etx.interrupt = 1;
  275. }
  276. static int enh_desc_get_rx_frame_len(struct dma_desc *p)
  277. {
  278. return p->des01.erx.frame_length;
  279. }
  280. const struct stmmac_desc_ops enh_desc_ops = {
  281. .tx_status = enh_desc_get_tx_status,
  282. .rx_status = enh_desc_get_rx_status,
  283. .get_tx_len = enh_desc_get_tx_len,
  284. .init_rx_desc = enh_desc_init_rx_desc,
  285. .init_tx_desc = enh_desc_init_tx_desc,
  286. .get_tx_owner = enh_desc_get_tx_owner,
  287. .get_rx_owner = enh_desc_get_rx_owner,
  288. .release_tx_desc = enh_desc_release_tx_desc,
  289. .prepare_tx_desc = enh_desc_prepare_tx_desc,
  290. .clear_tx_ic = enh_desc_clear_tx_ic,
  291. .close_tx_desc = enh_desc_close_tx_desc,
  292. .get_tx_ls = enh_desc_get_tx_ls,
  293. .set_tx_owner = enh_desc_set_tx_owner,
  294. .set_rx_owner = enh_desc_set_rx_owner,
  295. .get_rx_frame_len = enh_desc_get_rx_frame_len,
  296. };