rtl871x_io.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  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 Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * Modifications for inclusion into the Linux staging tree are
  19. * Copyright(c) 2010 Larry Finger. All rights reserved.
  20. *
  21. * Contact information:
  22. * WLAN FAE <wlanfae@realtek.com>
  23. * Larry Finger <Larry.Finger@lwfinger.net>
  24. *
  25. ******************************************************************************/
  26. #ifndef _IO_H_
  27. #define _IO_H_
  28. #include "osdep_service.h"
  29. #include "osdep_intf.h"
  30. #define NUM_IOREQ 8
  31. #define MAX_PROT_SZ (64-16)
  32. #define _IOREADY 0
  33. #define _IO_WAIT_COMPLETE 1
  34. #define _IO_WAIT_RSP 2
  35. /* IO COMMAND TYPE */
  36. #define _IOSZ_MASK_ (0x7F)
  37. #define _IO_WRITE_ BIT(7)
  38. #define _IO_FIXED_ BIT(8)
  39. #define _IO_BURST_ BIT(9)
  40. #define _IO_BYTE_ BIT(10)
  41. #define _IO_HW_ BIT(11)
  42. #define _IO_WORD_ BIT(12)
  43. #define _IO_SYNC_ BIT(13)
  44. #define _IO_CMDMASK_ (0x1F80)
  45. /*
  46. For prompt mode accessing, caller shall free io_req
  47. Otherwise, io_handler will free io_req
  48. */
  49. /* IO STATUS TYPE */
  50. #define _IO_ERR_ BIT(2)
  51. #define _IO_SUCCESS_ BIT(1)
  52. #define _IO_DONE_ BIT(0)
  53. #define IO_RD32 (_IO_SYNC_ | _IO_WORD_)
  54. #define IO_RD16 (_IO_SYNC_ | _IO_HW_)
  55. #define IO_RD8 (_IO_SYNC_ | _IO_BYTE_)
  56. #define IO_RD32_ASYNC (_IO_WORD_)
  57. #define IO_RD16_ASYNC (_IO_HW_)
  58. #define IO_RD8_ASYNC (_IO_BYTE_)
  59. #define IO_WR32 (_IO_WRITE_ | _IO_SYNC_ | _IO_WORD_)
  60. #define IO_WR16 (_IO_WRITE_ | _IO_SYNC_ | _IO_HW_)
  61. #define IO_WR8 (_IO_WRITE_ | _IO_SYNC_ | _IO_BYTE_)
  62. #define IO_WR32_ASYNC (_IO_WRITE_ | _IO_WORD_)
  63. #define IO_WR16_ASYNC (_IO_WRITE_ | _IO_HW_)
  64. #define IO_WR8_ASYNC (_IO_WRITE_ | _IO_BYTE_)
  65. /*
  66. Only Sync. burst accessing is provided.
  67. */
  68. #define IO_WR_BURST(x) (IO_WRITE_ | _IO_SYNC_ | _IO_BURST_ | \
  69. ((x) & _IOSZ_MASK_))
  70. #define IO_RD_BURST(x) (_IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_))
  71. /*below is for the intf_option bit defition...*/
  72. #define _INTF_ASYNC_ BIT(0) /*support async io*/
  73. struct intf_priv;
  74. struct intf_hdl;
  75. struct io_queue;
  76. struct _io_ops {
  77. uint (*_sdbus_read_bytes_to_membuf)(struct intf_priv *pintfpriv,
  78. u32 addr, u32 cnt, u8 *pbuf);
  79. uint (*_sdbus_read_blocks_to_membuf)(struct intf_priv *pintfpriv,
  80. u32 addr, u32 cnt, u8 *pbuf);
  81. u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
  82. u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
  83. u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
  84. uint (*_sdbus_write_blocks_from_membuf)(struct intf_priv *pintfpriv,
  85. u32 addr, u32 cnt, u8 *pbuf,
  86. u8 async);
  87. uint (*_sdbus_write_bytes_from_membuf)(struct intf_priv *pintfpriv,
  88. u32 addr, u32 cnt, u8 *pbuf);
  89. u8 (*_cmd52r)(struct intf_priv *pintfpriv, u32 addr);
  90. void (*_cmd52w)(struct intf_priv *pintfpriv, u32 addr, u8 val8);
  91. u8 (*_cmdfunc152r)(struct intf_priv *pintfpriv, u32 addr);
  92. void (*_cmdfunc152w)(struct intf_priv *pintfpriv, u32 addr, u8 val8);
  93. void (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
  94. void (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
  95. void (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
  96. void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
  97. u8 *pmem);
  98. void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
  99. u8 *pmem);
  100. void (*_sync_irp_protocol_rw)(struct io_queue *pio_q);
  101. u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
  102. u8 *pmem);
  103. u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
  104. u8 *pmem);
  105. };
  106. struct io_req {
  107. struct list_head list;
  108. u32 addr;
  109. /*volatile*/ u32 val;
  110. u32 command;
  111. u32 status;
  112. u8 *pbuf;
  113. void (*_async_io_callback)(struct _adapter *padapter,
  114. struct io_req *pio_req, u8 *cnxt);
  115. u8 *cnxt;
  116. };
  117. struct intf_hdl {
  118. u32 intf_option;
  119. u8 *adapter;
  120. u8 *intf_dev;
  121. struct intf_priv *pintfpriv;
  122. void (*intf_hdl_init)(u8 *priv);
  123. void (*intf_hdl_unload)(u8 *priv);
  124. void (*intf_hdl_open)(u8 *priv);
  125. void (*intf_hdl_close)(u8 *priv);
  126. struct _io_ops io_ops;
  127. };
  128. struct reg_protocol_rd {
  129. #ifdef __LITTLE_ENDIAN
  130. /* DW1 */
  131. u32 NumOfTrans:4;
  132. u32 Reserved1:4;
  133. u32 Reserved2:24;
  134. /* DW2 */
  135. u32 ByteCount:7;
  136. u32 WriteEnable:1; /*0:read, 1:write*/
  137. u32 FixOrContinuous:1; /*0:continuous, 1: Fix*/
  138. u32 BurstMode:1;
  139. u32 Byte1Access:1;
  140. u32 Byte2Access:1;
  141. u32 Byte4Access:1;
  142. u32 Reserved3:3;
  143. u32 Reserved4:16;
  144. /*DW3*/
  145. u32 BusAddress;
  146. /*DW4*/
  147. #else
  148. /*DW1*/
  149. u32 Reserved1:4;
  150. u32 NumOfTrans:4;
  151. u32 Reserved2:24;
  152. /*DW2*/
  153. u32 WriteEnable:1;
  154. u32 ByteCount:7;
  155. u32 Reserved3:3;
  156. u32 Byte4Access:1;
  157. u32 Byte2Access:1;
  158. u32 Byte1Access:1;
  159. u32 BurstMode:1;
  160. u32 FixOrContinuous:1;
  161. u32 Reserved4:16;
  162. /*DW3*/
  163. u32 BusAddress;
  164. /*DW4*/
  165. #endif
  166. };
  167. struct reg_protocol_wt {
  168. #ifdef __LITTLE_ENDIAN
  169. /*DW1*/
  170. u32 NumOfTrans:4;
  171. u32 Reserved1:4;
  172. u32 Reserved2:24;
  173. /*DW2*/
  174. u32 ByteCount:7;
  175. u32 WriteEnable:1; /*0:read, 1:write*/
  176. u32 FixOrContinuous:1; /*0:continuous, 1: Fix*/
  177. u32 BurstMode:1;
  178. u32 Byte1Access:1;
  179. u32 Byte2Access:1;
  180. u32 Byte4Access:1;
  181. u32 Reserved3:3;
  182. u32 Reserved4:16;
  183. /*DW3*/
  184. u32 BusAddress;
  185. /*DW4*/
  186. u32 Value;
  187. #else
  188. /*DW1*/
  189. u32 Reserved1:4;
  190. u32 NumOfTrans:4;
  191. u32 Reserved2:24;
  192. /*DW2*/
  193. u32 WriteEnable:1;
  194. u32 ByteCount:7;
  195. u32 Reserved3:3;
  196. u32 Byte4Access:1;
  197. u32 Byte2Access:1;
  198. u32 Byte1Access:1;
  199. u32 BurstMode:1;
  200. u32 FixOrContinuous:1;
  201. u32 Reserved4:16;
  202. /*DW3*/
  203. u32 BusAddress;
  204. /*DW4*/
  205. u32 Value;
  206. #endif
  207. };
  208. /*
  209. Below is the data structure used by _io_handler
  210. */
  211. struct io_queue {
  212. spinlock_t lock;
  213. struct list_head free_ioreqs;
  214. /*The io_req list that will be served in the single protocol r/w.*/
  215. struct list_head pending;
  216. struct list_head processing;
  217. u8 *free_ioreqs_buf; /* 4-byte aligned */
  218. u8 *pallocated_free_ioreqs_buf;
  219. struct intf_hdl intf;
  220. };
  221. u8 r8712_read8(struct _adapter *adapter, u32 addr);
  222. u16 r8712_read16(struct _adapter *adapter, u32 addr);
  223. u32 r8712_read32(struct _adapter *adapter, u32 addr);
  224. void r8712_read_mem(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
  225. void r8712_read_port(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
  226. void r8712_write8(struct _adapter *adapter, u32 addr, u8 val);
  227. void r8712_write16(struct _adapter *adapter, u32 addr, u16 val);
  228. void r8712_write32(struct _adapter *adapter, u32 addr, u32 val);
  229. void r8712_write_mem(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
  230. void r8712_write_port(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
  231. /*ioreq */
  232. uint r8712_alloc_io_queue(struct _adapter *adapter);
  233. void r8712_free_io_queue(struct _adapter *adapter);
  234. #endif /*_RTL8711_IO_H_*/