fec.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Bestcomm FEC tasks driver
  3. *
  4. *
  5. * Copyright (C) 2006-2007 Sylvain Munaut <tnt@246tNt.com>
  6. * Copyright (C) 2003-2004 MontaVista, Software, Inc.
  7. * ( by Dale Farnsworth <dfarnsworth@mvista.com> )
  8. *
  9. * This file is licensed under the terms of the GNU General Public License
  10. * version 2. This program is licensed "as is" without any warranty of any
  11. * kind, whether express or implied.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <asm/io.h>
  17. #include <linux/fsl/bestcomm/bestcomm.h>
  18. #include <linux/fsl/bestcomm/bestcomm_priv.h>
  19. #include <linux/fsl/bestcomm/fec.h>
  20. /* ======================================================================== */
  21. /* Task image/var/inc */
  22. /* ======================================================================== */
  23. /* fec tasks images */
  24. extern u32 bcom_fec_rx_task[];
  25. extern u32 bcom_fec_tx_task[];
  26. /* rx task vars that need to be set before enabling the task */
  27. struct bcom_fec_rx_var {
  28. u32 enable; /* (u16*) address of task's control register */
  29. u32 fifo; /* (u32*) address of fec's fifo */
  30. u32 bd_base; /* (struct bcom_bd*) beginning of ring buffer */
  31. u32 bd_last; /* (struct bcom_bd*) end of ring buffer */
  32. u32 bd_start; /* (struct bcom_bd*) current bd */
  33. u32 buffer_size; /* size of receive buffer */
  34. };
  35. /* rx task incs that need to be set before enabling the task */
  36. struct bcom_fec_rx_inc {
  37. u16 pad0;
  38. s16 incr_bytes;
  39. u16 pad1;
  40. s16 incr_dst;
  41. u16 pad2;
  42. s16 incr_dst_ma;
  43. };
  44. /* tx task vars that need to be set before enabling the task */
  45. struct bcom_fec_tx_var {
  46. u32 DRD; /* (u32*) address of self-modified DRD */
  47. u32 fifo; /* (u32*) address of fec's fifo */
  48. u32 enable; /* (u16*) address of task's control register */
  49. u32 bd_base; /* (struct bcom_bd*) beginning of ring buffer */
  50. u32 bd_last; /* (struct bcom_bd*) end of ring buffer */
  51. u32 bd_start; /* (struct bcom_bd*) current bd */
  52. u32 buffer_size; /* set by uCode for each packet */
  53. };
  54. /* tx task incs that need to be set before enabling the task */
  55. struct bcom_fec_tx_inc {
  56. u16 pad0;
  57. s16 incr_bytes;
  58. u16 pad1;
  59. s16 incr_src;
  60. u16 pad2;
  61. s16 incr_src_ma;
  62. };
  63. /* private structure in the task */
  64. struct bcom_fec_priv {
  65. phys_addr_t fifo;
  66. int maxbufsize;
  67. };
  68. /* ======================================================================== */
  69. /* Task support code */
  70. /* ======================================================================== */
  71. struct bcom_task *
  72. bcom_fec_rx_init(int queue_len, phys_addr_t fifo, int maxbufsize)
  73. {
  74. struct bcom_task *tsk;
  75. struct bcom_fec_priv *priv;
  76. tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_fec_bd),
  77. sizeof(struct bcom_fec_priv));
  78. if (!tsk)
  79. return NULL;
  80. tsk->flags = BCOM_FLAGS_NONE;
  81. priv = tsk->priv;
  82. priv->fifo = fifo;
  83. priv->maxbufsize = maxbufsize;
  84. if (bcom_fec_rx_reset(tsk)) {
  85. bcom_task_free(tsk);
  86. return NULL;
  87. }
  88. return tsk;
  89. }
  90. EXPORT_SYMBOL_GPL(bcom_fec_rx_init);
  91. int
  92. bcom_fec_rx_reset(struct bcom_task *tsk)
  93. {
  94. struct bcom_fec_priv *priv = tsk->priv;
  95. struct bcom_fec_rx_var *var;
  96. struct bcom_fec_rx_inc *inc;
  97. /* Shutdown the task */
  98. bcom_disable_task(tsk->tasknum);
  99. /* Reset the microcode */
  100. var = (struct bcom_fec_rx_var *) bcom_task_var(tsk->tasknum);
  101. inc = (struct bcom_fec_rx_inc *) bcom_task_inc(tsk->tasknum);
  102. if (bcom_load_image(tsk->tasknum, bcom_fec_rx_task))
  103. return -1;
  104. var->enable = bcom_eng->regs_base +
  105. offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
  106. var->fifo = (u32) priv->fifo;
  107. var->bd_base = tsk->bd_pa;
  108. var->bd_last = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
  109. var->bd_start = tsk->bd_pa;
  110. var->buffer_size = priv->maxbufsize;
  111. inc->incr_bytes = -(s16)sizeof(u32); /* These should be in the */
  112. inc->incr_dst = sizeof(u32); /* task image, but we stick */
  113. inc->incr_dst_ma= sizeof(u8); /* to the official ones */
  114. /* Reset the BDs */
  115. tsk->index = 0;
  116. tsk->outdex = 0;
  117. memset(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
  118. /* Configure some stuff */
  119. bcom_set_task_pragma(tsk->tasknum, BCOM_FEC_RX_BD_PRAGMA);
  120. bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
  121. out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_FEC_RX], BCOM_IPR_FEC_RX);
  122. out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum); /* Clear ints */
  123. return 0;
  124. }
  125. EXPORT_SYMBOL_GPL(bcom_fec_rx_reset);
  126. void
  127. bcom_fec_rx_release(struct bcom_task *tsk)
  128. {
  129. /* Nothing special for the FEC tasks */
  130. bcom_task_free(tsk);
  131. }
  132. EXPORT_SYMBOL_GPL(bcom_fec_rx_release);
  133. /* Return 2nd to last DRD */
  134. /* This is an ugly hack, but at least it's only done
  135. once at initialization */
  136. static u32 *self_modified_drd(int tasknum)
  137. {
  138. u32 *desc;
  139. int num_descs;
  140. int drd_count;
  141. int i;
  142. num_descs = bcom_task_num_descs(tasknum);
  143. desc = bcom_task_desc(tasknum) + num_descs - 1;
  144. drd_count = 0;
  145. for (i=0; i<num_descs; i++, desc--)
  146. if (bcom_desc_is_drd(*desc) && ++drd_count == 3)
  147. break;
  148. return desc;
  149. }
  150. struct bcom_task *
  151. bcom_fec_tx_init(int queue_len, phys_addr_t fifo)
  152. {
  153. struct bcom_task *tsk;
  154. struct bcom_fec_priv *priv;
  155. tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_fec_bd),
  156. sizeof(struct bcom_fec_priv));
  157. if (!tsk)
  158. return NULL;
  159. tsk->flags = BCOM_FLAGS_ENABLE_TASK;
  160. priv = tsk->priv;
  161. priv->fifo = fifo;
  162. if (bcom_fec_tx_reset(tsk)) {
  163. bcom_task_free(tsk);
  164. return NULL;
  165. }
  166. return tsk;
  167. }
  168. EXPORT_SYMBOL_GPL(bcom_fec_tx_init);
  169. int
  170. bcom_fec_tx_reset(struct bcom_task *tsk)
  171. {
  172. struct bcom_fec_priv *priv = tsk->priv;
  173. struct bcom_fec_tx_var *var;
  174. struct bcom_fec_tx_inc *inc;
  175. /* Shutdown the task */
  176. bcom_disable_task(tsk->tasknum);
  177. /* Reset the microcode */
  178. var = (struct bcom_fec_tx_var *) bcom_task_var(tsk->tasknum);
  179. inc = (struct bcom_fec_tx_inc *) bcom_task_inc(tsk->tasknum);
  180. if (bcom_load_image(tsk->tasknum, bcom_fec_tx_task))
  181. return -1;
  182. var->enable = bcom_eng->regs_base +
  183. offsetof(struct mpc52xx_sdma, tcr[tsk->tasknum]);
  184. var->fifo = (u32) priv->fifo;
  185. var->DRD = bcom_sram_va2pa(self_modified_drd(tsk->tasknum));
  186. var->bd_base = tsk->bd_pa;
  187. var->bd_last = tsk->bd_pa + ((tsk->num_bd-1) * tsk->bd_size);
  188. var->bd_start = tsk->bd_pa;
  189. inc->incr_bytes = -(s16)sizeof(u32); /* These should be in the */
  190. inc->incr_src = sizeof(u32); /* task image, but we stick */
  191. inc->incr_src_ma= sizeof(u8); /* to the official ones */
  192. /* Reset the BDs */
  193. tsk->index = 0;
  194. tsk->outdex = 0;
  195. memset(tsk->bd, 0x00, tsk->num_bd * tsk->bd_size);
  196. /* Configure some stuff */
  197. bcom_set_task_pragma(tsk->tasknum, BCOM_FEC_TX_BD_PRAGMA);
  198. bcom_set_task_auto_start(tsk->tasknum, tsk->tasknum);
  199. out_8(&bcom_eng->regs->ipr[BCOM_INITIATOR_FEC_TX], BCOM_IPR_FEC_TX);
  200. out_be32(&bcom_eng->regs->IntPend, 1<<tsk->tasknum); /* Clear ints */
  201. return 0;
  202. }
  203. EXPORT_SYMBOL_GPL(bcom_fec_tx_reset);
  204. void
  205. bcom_fec_tx_release(struct bcom_task *tsk)
  206. {
  207. /* Nothing special for the FEC tasks */
  208. bcom_task_free(tsk);
  209. }
  210. EXPORT_SYMBOL_GPL(bcom_fec_tx_release);
  211. MODULE_DESCRIPTION("BestComm FEC tasks driver");
  212. MODULE_AUTHOR("Dale Farnsworth <dfarnsworth@mvista.com>");
  213. MODULE_LICENSE("GPL v2");