]> Pileus Git - ~andy/linux/blob - drivers/staging/rtl8188eu/include/rtw_io.h
Merge branch 'linus' into perf/urgent
[~andy/linux] / drivers / staging / rtl8188eu / include / rtw_io.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 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  *
19  ******************************************************************************/
20
21 #ifndef _RTW_IO_H_
22 #define _RTW_IO_H_
23
24 #include <osdep_service.h>
25 #include <osdep_intf.h>
26
27 #include <asm/byteorder.h>
28 #include <linux/semaphore.h>
29 #include <linux/list.h>
30 #include <linux/spinlock.h>
31 #include <linux/atomic.h>
32
33 #include <linux/usb.h>
34 #include <linux/usb/ch9.h>
35
36 #define rtw_usb_buffer_alloc(dev, size, dma)                            \
37         usb_alloc_coherent((dev), (size), (in_interrupt() ?             \
38                            GFP_ATOMIC : GFP_KERNEL), (dma))
39 #define rtw_usb_buffer_free(dev, size, addr, dma)                       \
40         usb_free_coherent((dev), (size), (addr), (dma))
41
42 #define NUM_IOREQ               8
43
44 #define MAX_PROT_SZ     (64-16)
45
46 #define _IOREADY                0
47 #define _IO_WAIT_COMPLETE       1
48 #define _IO_WAIT_RSP            2
49
50 /*  IO COMMAND TYPE */
51 #define _IOSZ_MASK_             (0x7F)
52 #define _IO_WRITE_              BIT(7)
53 #define _IO_FIXED_              BIT(8)
54 #define _IO_BURST_              BIT(9)
55 #define _IO_BYTE_               BIT(10)
56 #define _IO_HW_                 BIT(11)
57 #define _IO_WORD_               BIT(12)
58 #define _IO_SYNC_               BIT(13)
59 #define _IO_CMDMASK_            (0x1F80)
60
61 /*
62         For prompt mode accessing, caller shall free io_req
63         Otherwise, io_handler will free io_req
64 */
65
66 /*  IO STATUS TYPE */
67 #define _IO_ERR_                BIT(2)
68 #define _IO_SUCCESS_            BIT(1)
69 #define _IO_DONE_               BIT(0)
70
71 #define IO_RD32                 (_IO_SYNC_ | _IO_WORD_)
72 #define IO_RD16                 (_IO_SYNC_ | _IO_HW_)
73 #define IO_RD8                  (_IO_SYNC_ | _IO_BYTE_)
74
75 #define IO_RD32_ASYNC           (_IO_WORD_)
76 #define IO_RD16_ASYNC           (_IO_HW_)
77 #define IO_RD8_ASYNC            (_IO_BYTE_)
78
79 #define IO_WR32                 (_IO_WRITE_ | _IO_SYNC_ | _IO_WORD_)
80 #define IO_WR16                 (_IO_WRITE_ | _IO_SYNC_ | _IO_HW_)
81 #define IO_WR8                  (_IO_WRITE_ | _IO_SYNC_ | _IO_BYTE_)
82
83 #define IO_WR32_ASYNC           (_IO_WRITE_ | _IO_WORD_)
84 #define IO_WR16_ASYNC           (_IO_WRITE_ | _IO_HW_)
85 #define IO_WR8_ASYNC            (_IO_WRITE_ | _IO_BYTE_)
86
87 /*
88         Only Sync. burst accessing is provided.
89 */
90
91 #define IO_WR_BURST(x)                                          \
92         (_IO_WRITE_ | _IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_))
93 #define IO_RD_BURST(x)                                          \
94         (_IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_))
95
96 /* below is for the intf_option bit defition... */
97
98 #define _INTF_ASYNC_    BIT(0)  /* support async io */
99
100 struct intf_priv;
101 struct intf_hdl;
102 struct io_queue;
103
104 struct _io_ops {
105         u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
106         u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
107         u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
108         int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
109         int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
110         int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
111         int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length,
112                        u8 *pdata);
113         int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
114         int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
115         int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
116         void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
117                           u8 *pmem);
118         void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
119                            u8 *pmem);
120         void (*_sync_irp_protocol_rw)(struct io_queue *pio_q);
121         u32 (*_read_interrupt)(struct intf_hdl *pintfhdl, u32 addr);
122         u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
123                           u8 *pmem);
124         u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
125                            u8 *pmem);
126         u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
127         void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
128         void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
129 };
130
131 struct io_req {
132         struct list_head list;
133         u32     addr;
134         u32     val;
135         u32     command;
136         u32     status;
137         u8      *pbuf;
138         struct semaphore sema;
139
140         void (*_async_io_callback)(struct adapter *padater,
141                                    struct io_req *pio_req, u8 *cnxt);
142         u8 *cnxt;
143 };
144
145 struct  intf_hdl {
146         struct adapter *padapter;
147         struct dvobj_priv *pintf_dev;
148         struct _io_ops  io_ops;
149 };
150
151 struct reg_protocol_rd {
152 #ifdef __LITTLE_ENDIAN
153         /* DW1 */
154         u32             NumOfTrans:4;
155         u32             Reserved1:4;
156         u32             Reserved2:24;
157         /* DW2 */
158         u32             ByteCount:7;
159         u32             WriteEnable:1;          /* 0:read, 1:write */
160         u32             FixOrContinuous:1;      /* 0:continuous, 1: Fix */
161         u32             BurstMode:1;
162         u32             Byte1Access:1;
163         u32             Byte2Access:1;
164         u32             Byte4Access:1;
165         u32             Reserved3:3;
166         u32             Reserved4:16;
167         /* DW3 */
168         u32             BusAddress;
169         /* DW4 */
170         /* u32          Value; */
171 #else
172 /* DW1 */
173         u32 Reserved1:4;
174         u32 NumOfTrans:4;
175         u32 Reserved2:24;
176         /* DW2 */
177         u32 WriteEnable:1;
178         u32 ByteCount:7;
179         u32 Reserved3:3;
180         u32 Byte4Access:1;
181
182         u32 Byte2Access:1;
183         u32 Byte1Access:1;
184         u32 BurstMode:1;
185         u32 FixOrContinuous:1;
186         u32 Reserved4:16;
187         /* DW3 */
188         u32     BusAddress;
189
190         /* DW4 */
191 #endif
192 };
193
194 struct reg_protocol_wt {
195 #ifdef __LITTLE_ENDIAN
196         /* DW1 */
197         u32     NumOfTrans:4;
198         u32     Reserved1:4;
199         u32     Reserved2:24;
200         /* DW2 */
201         u32     ByteCount:7;
202         u32     WriteEnable:1;          /* 0:read, 1:write */
203         u32     FixOrContinuous:1;      /* 0:continuous, 1: Fix */
204         u32     BurstMode:1;
205         u32     Byte1Access:1;
206         u32     Byte2Access:1;
207         u32     Byte4Access:1;
208         u32     Reserved3:3;
209         u32     Reserved4:16;
210         /* DW3 */
211         u32     BusAddress;
212         /* DW4 */
213         u32     Value;
214 #else
215         /* DW1 */
216         u32 Reserved1 :4;
217         u32 NumOfTrans:4;
218         u32 Reserved2:24;
219         /* DW2 */
220         u32 WriteEnable:1;
221         u32 ByteCount:7;
222         u32 Reserved3:3;
223         u32 Byte4Access:1;
224         u32 Byte2Access:1;
225         u32 Byte1Access:1;
226         u32 BurstMode:1;
227         u32 FixOrContinuous:1;
228         u32 Reserved4:16;
229         /* DW3 */
230         u32     BusAddress;
231         /* DW4 */
232         u32     Value;
233 #endif
234 };
235
236 /*
237 Below is the data structure used by _io_handler
238 */
239
240 struct io_queue {
241         spinlock_t lock;
242         struct list_head free_ioreqs;
243         struct list_head pending;       /* The io_req list that will be served
244                                          * in the single protocol read/write.*/
245         struct list_head processing;
246         u8      *free_ioreqs_buf; /*  4-byte aligned */
247         u8      *pallocated_free_ioreqs_buf;
248         struct  intf_hdl        intf;
249 };
250
251 struct io_priv {
252         struct adapter *padapter;
253         struct intf_hdl intf;
254 };
255
256 uint ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
257 void sync_ioreq_enqueue(struct io_req *preq,struct io_queue *ioqueue);
258 uint sync_ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
259 uint free_ioreq(struct io_req *preq, struct io_queue *pio_queue);
260 struct io_req *alloc_ioreq(struct io_queue *pio_q);
261
262 uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl);
263 void unregister_intf_hdl(struct intf_hdl *pintfhdl);
264
265 void _rtw_attrib_read(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
266 void _rtw_attrib_write(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
267
268 u8 _rtw_read8(struct adapter *adapter, u32 addr);
269 u16 _rtw_read16(struct adapter *adapter, u32 addr);
270 u32 _rtw_read32(struct adapter *adapter, u32 addr);
271 void _rtw_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
272 void _rtw_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
273 void _rtw_read_port_cancel(struct adapter *adapter);
274
275 int _rtw_write8(struct adapter *adapter, u32 addr, u8 val);
276 int _rtw_write16(struct adapter *adapter, u32 addr, u16 val);
277 int _rtw_write32(struct adapter *adapter, u32 addr, u32 val);
278 int _rtw_writeN(struct adapter *adapter, u32 addr, u32 length, u8 *pdata);
279
280 int _rtw_write8_async(struct adapter *adapter, u32 addr, u8 val);
281 int _rtw_write16_async(struct adapter *adapter, u32 addr, u16 val);
282 int _rtw_write32_async(struct adapter *adapter, u32 addr, u32 val);
283
284 void _rtw_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
285 u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
286 u32 _rtw_write_port_and_wait(struct adapter *adapter, u32 addr, u32 cnt,
287                              u8 *pmem, int timeout_ms);
288 void _rtw_write_port_cancel(struct adapter *adapter);
289
290 #define rtw_read8(adapter, addr) _rtw_read8((adapter), (addr))
291 #define rtw_read16(adapter, addr) _rtw_read16((adapter), (addr))
292 #define rtw_read32(adapter, addr) _rtw_read32((adapter), (addr))
293 #define rtw_read_mem(adapter, addr, cnt, mem)                           \
294         _rtw_read_mem((adapter), (addr), (cnt), (mem))
295 #define rtw_read_port(adapter, addr, cnt, mem)                          \
296         _rtw_read_port((adapter), (addr), (cnt), (mem))
297 #define rtw_read_port_cancel(adapter) _rtw_read_port_cancel((adapter))
298
299 #define  rtw_write8(adapter, addr, val)                                 \
300         _rtw_write8((adapter), (addr), (val))
301 #define  rtw_write16(adapter, addr, val)                                \
302         _rtw_write16((adapter), (addr), (val))
303 #define  rtw_write32(adapter, addr, val)                                \
304         _rtw_write32((adapter), (addr), (val))
305 #define  rtw_writeN(adapter, addr, length, data)                        \
306         _rtw_writeN((adapter), (addr), (length), (data))
307 #define rtw_write8_async(adapter, addr, val)                            \
308         _rtw_write8_async((adapter), (addr), (val))
309 #define rtw_write16_async(adapter, addr, val)                           \
310         _rtw_write16_async((adapter), (addr), (val))
311 #define rtw_write32_async(adapter, addr, val)                           \
312         _rtw_write32_async((adapter), (addr), (val))
313 #define rtw_write_mem(adapter, addr, cnt, mem)                          \
314         _rtw_write_mem((adapter), (addr), (cnt), (mem))
315 #define rtw_write_port(adapter, addr, cnt, mem)                         \
316         _rtw_write_port((adapter), (addr), (cnt), (mem))
317 #define rtw_write_port_and_wait(adapter, addr, cnt, mem, timeout_ms)    \
318         _rtw_write_port_and_wait((adapter), (addr), (cnt), (mem), (timeout_ms))
319 #define rtw_write_port_cancel(adapter) _rtw_write_port_cancel((adapter))
320
321 void rtw_write_scsi(struct adapter *adapter, u32 cnt, u8 *pmem);
322
323 /* ioreq */
324 void ioreq_read8(struct adapter *adapter, u32 addr, u8 *pval);
325 void ioreq_read16(struct adapter *adapter, u32 addr, u16 *pval);
326 void ioreq_read32(struct adapter *adapter, u32 addr, u32 *pval);
327 void ioreq_write8(struct adapter *adapter, u32 addr, u8 val);
328 void ioreq_write16(struct adapter *adapter, u32 addr, u16 val);
329 void ioreq_write32(struct adapter *adapter, u32 addr, u32 val);
330
331 uint async_read8(struct adapter *adapter, u32 addr, u8 *pbuff,
332                  void (*_async_io_callback)(struct adapter *padater,
333                                             struct io_req *pio_req,
334                                             u8 *cnxt), u8 *cnxt);
335 uint async_read16(struct adapter *adapter, u32 addr,  u8 *pbuff,
336                   void (*_async_io_callback)(struct adapter *padater,
337                                              struct io_req *pio_req,
338                                              u8 *cnxt), u8 *cnxt);
339 uint async_read32(struct adapter *adapter, u32 addr,  u8 *pbuff,
340                   void (*_async_io_callback)(struct adapter *padater,
341                                              struct io_req *pio_req,
342                                              u8 *cnxt), u8 *cnxt);
343
344 void async_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
345 void async_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
346
347 void async_write8(struct adapter *adapter, u32 addr, u8 val,
348                   void (*_async_io_callback)(struct adapter *padater,
349                                              struct io_req *pio_req,
350                                              u8 *cnxt), u8 *cnxt);
351 void async_write16(struct adapter *adapter, u32 addr, u16 val,
352                    void (*_async_io_callback)(struct adapter *padater,
353                                               struct io_req *pio_req,
354                                               u8 *cnxt), u8 *cnxt);
355 void async_write32(struct adapter *adapter, u32 addr, u32 val,
356                    void (*_async_io_callback)(struct adapter *padater,
357                                               struct io_req *pio_req,
358                                               u8 *cnxt), u8 *cnxt);
359
360 void async_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
361 void async_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
362
363 int rtw_init_io_priv(struct adapter *padapter,
364                      void (*set_intf_ops)(struct _io_ops *pops));
365
366 uint alloc_io_queue(struct adapter *adapter);
367 void free_io_queue(struct adapter *adapter);
368 void async_bus_io(struct io_queue *pio_q);
369 void bus_sync_io(struct io_queue *pio_q);
370 u32 _ioreq2rwmem(struct io_queue *pio_q);
371 void dev_power_down(struct adapter * Adapter, u8 bpwrup);
372
373 #define PlatformEFIOWrite1Byte(_a,_b,_c)                \
374         rtw_write8(_a,_b,_c)
375 #define PlatformEFIOWrite2Byte(_a,_b,_c)                \
376         rtw_write16(_a,_b,_c)
377 #define PlatformEFIOWrite4Byte(_a,_b,_c)                \
378         rtw_write32(_a,_b,_c)
379
380 #define PlatformEFIORead1Byte(_a,_b)            \
381                 rtw_read8(_a,_b)
382 #define PlatformEFIORead2Byte(_a,_b)            \
383                 rtw_read16(_a,_b)
384 #define PlatformEFIORead4Byte(_a,_b)            \
385                 rtw_read32(_a,_b)
386
387 #endif  /* _RTL8711_IO_H_ */