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