ucc_fast.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Internal header file for UCC FAST unit routines.
  4. *
  5. * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
  6. *
  7. * Authors: Shlomi Gridish <[email protected]>
  8. * Li Yang <[email protected]>
  9. */
  10. #ifndef __UCC_FAST_H__
  11. #define __UCC_FAST_H__
  12. #include <linux/types.h>
  13. #include <soc/fsl/qe/immap_qe.h>
  14. #include <soc/fsl/qe/qe.h>
  15. #include <soc/fsl/qe/ucc.h>
  16. /* Receive BD's status and length*/
  17. #define R_E 0x80000000 /* buffer empty */
  18. #define R_W 0x20000000 /* wrap bit */
  19. #define R_I 0x10000000 /* interrupt on reception */
  20. #define R_L 0x08000000 /* last */
  21. #define R_F 0x04000000 /* first */
  22. /* transmit BD's status and length*/
  23. #define T_R 0x80000000 /* ready bit */
  24. #define T_W 0x20000000 /* wrap bit */
  25. #define T_I 0x10000000 /* interrupt on completion */
  26. #define T_L 0x08000000 /* last */
  27. /* Receive BD's status */
  28. #define R_E_S 0x8000 /* buffer empty */
  29. #define R_W_S 0x2000 /* wrap bit */
  30. #define R_I_S 0x1000 /* interrupt on reception */
  31. #define R_L_S 0x0800 /* last */
  32. #define R_F_S 0x0400 /* first */
  33. #define R_CM_S 0x0200 /* continuous mode */
  34. #define R_LG_S 0x0020 /* frame length */
  35. #define R_NO_S 0x0010 /* nonoctet */
  36. #define R_AB_S 0x0008 /* abort */
  37. #define R_CR_S 0x0004 /* crc */
  38. #define R_OV_S 0x0002 /* overrun */
  39. #define R_CD_S 0x0001 /* carrier detect */
  40. /* transmit BD's status */
  41. #define T_R_S 0x8000 /* ready bit */
  42. #define T_W_S 0x2000 /* wrap bit */
  43. #define T_I_S 0x1000 /* interrupt on completion */
  44. #define T_L_S 0x0800 /* last */
  45. #define T_TC_S 0x0400 /* crc */
  46. #define T_TM_S 0x0200 /* continuous mode */
  47. #define T_UN_S 0x0002 /* hdlc underrun */
  48. #define T_CT_S 0x0001 /* hdlc carrier lost */
  49. /* Rx Data buffer must be 4 bytes aligned in most cases */
  50. #define UCC_FAST_RX_ALIGN 4
  51. #define UCC_FAST_MRBLR_ALIGNMENT 4
  52. #define UCC_FAST_VIRT_FIFO_REGS_ALIGNMENT 8
  53. /* Sizes */
  54. #define UCC_FAST_URFS_MIN_VAL 0x88
  55. #define UCC_FAST_RECEIVE_VIRTUAL_FIFO_SIZE_FUDGE_FACTOR 8
  56. /* ucc_fast_channel_protocol_mode - UCC FAST mode */
  57. enum ucc_fast_channel_protocol_mode {
  58. UCC_FAST_PROTOCOL_MODE_HDLC = 0x00000000,
  59. UCC_FAST_PROTOCOL_MODE_RESERVED01 = 0x00000001,
  60. UCC_FAST_PROTOCOL_MODE_RESERVED_QMC = 0x00000002,
  61. UCC_FAST_PROTOCOL_MODE_RESERVED02 = 0x00000003,
  62. UCC_FAST_PROTOCOL_MODE_RESERVED_UART = 0x00000004,
  63. UCC_FAST_PROTOCOL_MODE_RESERVED03 = 0x00000005,
  64. UCC_FAST_PROTOCOL_MODE_RESERVED_EX_MAC_1 = 0x00000006,
  65. UCC_FAST_PROTOCOL_MODE_RESERVED_EX_MAC_2 = 0x00000007,
  66. UCC_FAST_PROTOCOL_MODE_RESERVED_BISYNC = 0x00000008,
  67. UCC_FAST_PROTOCOL_MODE_RESERVED04 = 0x00000009,
  68. UCC_FAST_PROTOCOL_MODE_ATM = 0x0000000A,
  69. UCC_FAST_PROTOCOL_MODE_RESERVED05 = 0x0000000B,
  70. UCC_FAST_PROTOCOL_MODE_ETHERNET = 0x0000000C,
  71. UCC_FAST_PROTOCOL_MODE_RESERVED06 = 0x0000000D,
  72. UCC_FAST_PROTOCOL_MODE_POS = 0x0000000E,
  73. UCC_FAST_PROTOCOL_MODE_RESERVED07 = 0x0000000F
  74. };
  75. /* ucc_fast_transparent_txrx - UCC Fast Transparent TX & RX */
  76. enum ucc_fast_transparent_txrx {
  77. UCC_FAST_GUMR_TRANSPARENT_TTX_TRX_NORMAL = 0x00000000,
  78. UCC_FAST_GUMR_TRANSPARENT_TTX_TRX_TRANSPARENT = 0x18000000
  79. };
  80. /* UCC fast diagnostic mode */
  81. enum ucc_fast_diag_mode {
  82. UCC_FAST_DIAGNOSTIC_NORMAL = 0x0,
  83. UCC_FAST_DIAGNOSTIC_LOCAL_LOOP_BACK = 0x40000000,
  84. UCC_FAST_DIAGNOSTIC_AUTO_ECHO = 0x80000000,
  85. UCC_FAST_DIAGNOSTIC_LOOP_BACK_AND_ECHO = 0xC0000000
  86. };
  87. /* UCC fast Sync length (transparent mode only) */
  88. enum ucc_fast_sync_len {
  89. UCC_FAST_SYNC_LEN_NOT_USED = 0x0,
  90. UCC_FAST_SYNC_LEN_AUTOMATIC = 0x00004000,
  91. UCC_FAST_SYNC_LEN_8_BIT = 0x00008000,
  92. UCC_FAST_SYNC_LEN_16_BIT = 0x0000C000
  93. };
  94. /* UCC fast RTS mode */
  95. enum ucc_fast_ready_to_send {
  96. UCC_FAST_SEND_IDLES_BETWEEN_FRAMES = 0x00000000,
  97. UCC_FAST_SEND_FLAGS_BETWEEN_FRAMES = 0x00002000
  98. };
  99. /* UCC fast receiver decoding mode */
  100. enum ucc_fast_rx_decoding_method {
  101. UCC_FAST_RX_ENCODING_NRZ = 0x00000000,
  102. UCC_FAST_RX_ENCODING_NRZI = 0x00000800,
  103. UCC_FAST_RX_ENCODING_RESERVED0 = 0x00001000,
  104. UCC_FAST_RX_ENCODING_RESERVED1 = 0x00001800
  105. };
  106. /* UCC fast transmitter encoding mode */
  107. enum ucc_fast_tx_encoding_method {
  108. UCC_FAST_TX_ENCODING_NRZ = 0x00000000,
  109. UCC_FAST_TX_ENCODING_NRZI = 0x00000100,
  110. UCC_FAST_TX_ENCODING_RESERVED0 = 0x00000200,
  111. UCC_FAST_TX_ENCODING_RESERVED1 = 0x00000300
  112. };
  113. /* UCC fast CRC length */
  114. enum ucc_fast_transparent_tcrc {
  115. UCC_FAST_16_BIT_CRC = 0x00000000,
  116. UCC_FAST_CRC_RESERVED0 = 0x00000040,
  117. UCC_FAST_32_BIT_CRC = 0x00000080,
  118. UCC_FAST_CRC_RESERVED1 = 0x000000C0
  119. };
  120. /* Fast UCC initialization structure */
  121. struct ucc_fast_info {
  122. int ucc_num;
  123. int tdm_num;
  124. enum qe_clock rx_clock;
  125. enum qe_clock tx_clock;
  126. enum qe_clock rx_sync;
  127. enum qe_clock tx_sync;
  128. resource_size_t regs;
  129. int irq;
  130. u32 uccm_mask;
  131. int brkpt_support;
  132. int grant_support;
  133. int tsa;
  134. int cdp;
  135. int cds;
  136. int ctsp;
  137. int ctss;
  138. int tci;
  139. int txsy;
  140. int rtsm;
  141. int revd;
  142. int rsyn;
  143. u16 max_rx_buf_length;
  144. u16 urfs;
  145. u16 urfet;
  146. u16 urfset;
  147. u16 utfs;
  148. u16 utfet;
  149. u16 utftt;
  150. u16 ufpt;
  151. enum ucc_fast_channel_protocol_mode mode;
  152. enum ucc_fast_transparent_txrx ttx_trx;
  153. enum ucc_fast_tx_encoding_method tenc;
  154. enum ucc_fast_rx_decoding_method renc;
  155. enum ucc_fast_transparent_tcrc tcrc;
  156. enum ucc_fast_sync_len synl;
  157. };
  158. struct ucc_fast_private {
  159. struct ucc_fast_info *uf_info;
  160. struct ucc_fast __iomem *uf_regs; /* a pointer to the UCC regs. */
  161. __be32 __iomem *p_ucce; /* a pointer to the event register in memory. */
  162. __be32 __iomem *p_uccm; /* a pointer to the mask register in memory. */
  163. #ifdef CONFIG_UGETH_TX_ON_DEMAND
  164. __be16 __iomem *p_utodr;/* pointer to the transmit on demand register */
  165. #endif
  166. int enabled_tx; /* Whether channel is enabled for Tx (ENT) */
  167. int enabled_rx; /* Whether channel is enabled for Rx (ENR) */
  168. int stopped_tx; /* Whether channel has been stopped for Tx
  169. (STOP_TX, etc.) */
  170. int stopped_rx; /* Whether channel has been stopped for Rx */
  171. s32 ucc_fast_tx_virtual_fifo_base_offset;/* pointer to base of Tx
  172. virtual fifo */
  173. s32 ucc_fast_rx_virtual_fifo_base_offset;/* pointer to base of Rx
  174. virtual fifo */
  175. #ifdef STATISTICS
  176. u32 tx_frames; /* Transmitted frames counter. */
  177. u32 rx_frames; /* Received frames counter (only frames
  178. passed to application). */
  179. u32 tx_discarded; /* Discarded tx frames counter (frames that
  180. were discarded by the driver due to errors).
  181. */
  182. u32 rx_discarded; /* Discarded rx frames counter (frames that
  183. were discarded by the driver due to errors).
  184. */
  185. #endif /* STATISTICS */
  186. u16 mrblr; /* maximum receive buffer length */
  187. };
  188. /* ucc_fast_init
  189. * Initializes Fast UCC according to user provided parameters.
  190. *
  191. * uf_info - (In) pointer to the fast UCC info structure.
  192. * uccf_ret - (Out) pointer to the fast UCC structure.
  193. */
  194. int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** uccf_ret);
  195. /* ucc_fast_free
  196. * Frees all resources for fast UCC.
  197. *
  198. * uccf - (In) pointer to the fast UCC structure.
  199. */
  200. void ucc_fast_free(struct ucc_fast_private * uccf);
  201. /* ucc_fast_enable
  202. * Enables a fast UCC port.
  203. * This routine enables Tx and/or Rx through the General UCC Mode Register.
  204. *
  205. * uccf - (In) pointer to the fast UCC structure.
  206. * mode - (In) TX, RX, or both.
  207. */
  208. void ucc_fast_enable(struct ucc_fast_private * uccf, enum comm_dir mode);
  209. /* ucc_fast_disable
  210. * Disables a fast UCC port.
  211. * This routine disables Tx and/or Rx through the General UCC Mode Register.
  212. *
  213. * uccf - (In) pointer to the fast UCC structure.
  214. * mode - (In) TX, RX, or both.
  215. */
  216. void ucc_fast_disable(struct ucc_fast_private * uccf, enum comm_dir mode);
  217. /* ucc_fast_irq
  218. * Handles interrupts on fast UCC.
  219. * Called from the general interrupt routine to handle interrupts on fast UCC.
  220. *
  221. * uccf - (In) pointer to the fast UCC structure.
  222. */
  223. void ucc_fast_irq(struct ucc_fast_private * uccf);
  224. /* ucc_fast_transmit_on_demand
  225. * Immediately forces a poll of the transmitter for data to be sent.
  226. * Typically, the hardware performs a periodic poll for data that the
  227. * transmit routine has set up to be transmitted. In cases where
  228. * this polling cycle is not soon enough, this optional routine can
  229. * be invoked to force a poll right away, instead. Proper use for
  230. * each transmission for which this functionality is desired is to
  231. * call the transmit routine and then this routine right after.
  232. *
  233. * uccf - (In) pointer to the fast UCC structure.
  234. */
  235. void ucc_fast_transmit_on_demand(struct ucc_fast_private * uccf);
  236. u32 ucc_fast_get_qe_cr_subblock(int uccf_num);
  237. void ucc_fast_dump_regs(struct ucc_fast_private * uccf);
  238. #endif /* __UCC_FAST_H__ */