wlcore, wl1251: fix spelling: "Couldnt" -> "Couldn't" and remove error on -ENOMEM
[linux-2.6/btrfs-unstable.git] / drivers / staging / rtl8723bs / include / rtw_io.h
blob0341d0d35375c86f3f376f0665ca2819e4937599
1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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.
14 ******************************************************************************/
16 #ifndef _RTW_IO_H_
17 #define _RTW_IO_H_
19 #define NUM_IOREQ 8
21 #define MAX_PROT_SZ (64-16)
23 #define _IOREADY 0
24 #define _IO_WAIT_COMPLETE 1
25 #define _IO_WAIT_RSP 2
27 /* IO COMMAND TYPE */
28 #define _IOSZ_MASK_ (0x7F)
29 #define _IO_WRITE_ BIT(7)
30 #define _IO_FIXED_ BIT(8)
31 #define _IO_BURST_ BIT(9)
32 #define _IO_BYTE_ BIT(10)
33 #define _IO_HW_ BIT(11)
34 #define _IO_WORD_ BIT(12)
35 #define _IO_SYNC_ BIT(13)
36 #define _IO_CMDMASK_ (0x1F80)
40 For prompt mode accessing, caller shall free io_req
41 Otherwise, io_handler will free io_req
46 /* IO STATUS TYPE */
47 #define _IO_ERR_ BIT(2)
48 #define _IO_SUCCESS_ BIT(1)
49 #define _IO_DONE_ BIT(0)
52 #define IO_RD32 (_IO_SYNC_ | _IO_WORD_)
53 #define IO_RD16 (_IO_SYNC_ | _IO_HW_)
54 #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_)
60 #define IO_WR32 (_IO_WRITE_ | _IO_SYNC_ | _IO_WORD_)
61 #define IO_WR16 (_IO_WRITE_ | _IO_SYNC_ | _IO_HW_)
62 #define IO_WR8 (_IO_WRITE_ | _IO_SYNC_ | _IO_BYTE_)
64 #define IO_WR32_ASYNC (_IO_WRITE_ | _IO_WORD_)
65 #define IO_WR16_ASYNC (_IO_WRITE_ | _IO_HW_)
66 #define IO_WR8_ASYNC (_IO_WRITE_ | _IO_BYTE_)
70 Only Sync. burst accessing is provided.
74 #define IO_WR_BURST(x) (_IO_WRITE_ | _IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_))
75 #define IO_RD_BURST(x) (_IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_))
79 /* below is for the intf_option bit defition... */
81 #define _INTF_ASYNC_ BIT(0) /* support async io */
83 struct intf_priv;
84 struct intf_hdl;
85 struct io_queue;
87 struct _io_ops {
88 u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
89 u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
90 u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
92 int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
93 int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
94 int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
95 int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata);
97 int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
98 int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
99 int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
101 void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
102 void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
104 void (*_sync_irp_protocol_rw)(struct io_queue *pio_q);
106 u32 (*_read_interrupt)(struct intf_hdl *pintfhdl, u32 addr);
108 u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
109 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
111 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
113 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
114 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
116 u8 (*_sd_f0_read8)(struct intf_hdl *pintfhdl, u32 addr);
119 struct io_req {
120 struct list_head list;
121 u32 addr;
122 volatile u32 val;
123 u32 command;
124 u32 status;
125 u8 *pbuf;
126 _sema sema;
128 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt);
129 u8 *cnxt;
132 struct intf_hdl {
133 struct adapter *padapter;
134 struct dvobj_priv *pintf_dev;/* pointer to &(padapter->dvobjpriv); */
136 struct _io_ops io_ops;
139 struct reg_protocol_rd {
141 #ifdef __LITTLE_ENDIAN
143 /* DW1 */
144 u32 NumOfTrans:4;
145 u32 Reserved1:4;
146 u32 Reserved2:24;
147 /* DW2 */
148 u32 ByteCount:7;
149 u32 WriteEnable:1; /* 0:read, 1:write */
150 u32 FixOrContinuous:1; /* 0:continuous, 1: Fix */
151 u32 BurstMode:1;
152 u32 Byte1Access:1;
153 u32 Byte2Access:1;
154 u32 Byte4Access:1;
155 u32 Reserved3:3;
156 u32 Reserved4:16;
157 /* DW3 */
158 u32 BusAddress;
159 /* DW4 */
160 /* u32 Value; */
161 #else
164 /* DW1 */
165 u32 Reserved1 :4;
166 u32 NumOfTrans :4;
168 u32 Reserved2 :24;
170 /* DW2 */
171 u32 WriteEnable : 1;
172 u32 ByteCount :7;
175 u32 Reserved3 : 3;
176 u32 Byte4Access : 1;
178 u32 Byte2Access : 1;
179 u32 Byte1Access : 1;
180 u32 BurstMode :1 ;
181 u32 FixOrContinuous : 1;
183 u32 Reserved4 : 16;
185 /* DW3 */
186 u32 BusAddress;
188 /* DW4 */
189 /* u32 Value; */
191 #endif
196 struct reg_protocol_wt {
199 #ifdef __LITTLE_ENDIAN
201 /* DW1 */
202 u32 NumOfTrans:4;
203 u32 Reserved1:4;
204 u32 Reserved2:24;
205 /* DW2 */
206 u32 ByteCount:7;
207 u32 WriteEnable:1; /* 0:read, 1:write */
208 u32 FixOrContinuous:1; /* 0:continuous, 1: Fix */
209 u32 BurstMode:1;
210 u32 Byte1Access:1;
211 u32 Byte2Access:1;
212 u32 Byte4Access:1;
213 u32 Reserved3:3;
214 u32 Reserved4:16;
215 /* DW3 */
216 u32 BusAddress;
217 /* DW4 */
218 u32 Value;
220 #else
221 /* DW1 */
222 u32 Reserved1 :4;
223 u32 NumOfTrans :4;
225 u32 Reserved2 :24;
227 /* DW2 */
228 u32 WriteEnable : 1;
229 u32 ByteCount :7;
231 u32 Reserved3 : 3;
232 u32 Byte4Access : 1;
234 u32 Byte2Access : 1;
235 u32 Byte1Access : 1;
236 u32 BurstMode :1 ;
237 u32 FixOrContinuous : 1;
239 u32 Reserved4 : 16;
241 /* DW3 */
242 u32 BusAddress;
244 /* DW4 */
245 u32 Value;
247 #endif
250 #define SD_IO_TRY_CNT (8)
251 #define MAX_CONTINUAL_IO_ERR SD_IO_TRY_CNT
253 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj);
254 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj);
257 Below is the data structure used by _io_handler
261 struct io_queue {
262 _lock lock;
263 struct list_head free_ioreqs;
264 struct list_head pending; /* The io_req list that will be served in the single protocol read/write. */
265 struct list_head processing;
266 u8 *free_ioreqs_buf; /* 4-byte aligned */
267 u8 *pallocated_free_ioreqs_buf;
268 struct intf_hdl intf;
271 struct io_priv{
273 struct adapter *padapter;
275 struct intf_hdl intf;
279 extern uint ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
280 extern void sync_ioreq_enqueue(struct io_req *preq, struct io_queue *ioqueue);
281 extern uint sync_ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
284 extern uint free_ioreq(struct io_req *preq, struct io_queue *pio_queue);
285 extern struct io_req *alloc_ioreq(struct io_queue *pio_q);
287 extern uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl);
288 extern void unregister_intf_hdl(struct intf_hdl *pintfhdl);
290 extern void _rtw_attrib_read(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
291 extern void _rtw_attrib_write(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
293 extern u8 _rtw_read8(struct adapter *adapter, u32 addr);
294 extern u16 _rtw_read16(struct adapter *adapter, u32 addr);
295 extern u32 _rtw_read32(struct adapter *adapter, u32 addr);
297 extern int _rtw_write8(struct adapter *adapter, u32 addr, u8 val);
298 extern int _rtw_write16(struct adapter *adapter, u32 addr, u16 val);
299 extern int _rtw_write32(struct adapter *adapter, u32 addr, u32 val);
301 extern u8 _rtw_sd_f0_read8(struct adapter *adapter, u32 addr);
303 extern u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
305 #define rtw_read8(adapter, addr) _rtw_read8((adapter), (addr))
306 #define rtw_read16(adapter, addr) _rtw_read16((adapter), (addr))
307 #define rtw_read32(adapter, addr) _rtw_read32((adapter), (addr))
309 #define rtw_write8(adapter, addr, val) _rtw_write8((adapter), (addr), (val))
310 #define rtw_write16(adapter, addr, val) _rtw_write16((adapter), (addr), (val))
311 #define rtw_write32(adapter, addr, val) _rtw_write32((adapter), (addr), (val))
313 #define rtw_write_port(adapter, addr, cnt, mem) _rtw_write_port((adapter), (addr), (cnt), (mem))
315 #define rtw_sd_f0_read8(adapter, addr) _rtw_sd_f0_read8((adapter), (addr))
317 extern void rtw_write_scsi(struct adapter *adapter, u32 cnt, u8 *pmem);
319 /* ioreq */
320 extern void ioreq_read8(struct adapter *adapter, u32 addr, u8 *pval);
321 extern void ioreq_read16(struct adapter *adapter, u32 addr, u16 *pval);
322 extern void ioreq_read32(struct adapter *adapter, u32 addr, u32 *pval);
323 extern void ioreq_write8(struct adapter *adapter, u32 addr, u8 val);
324 extern void ioreq_write16(struct adapter *adapter, u32 addr, u16 val);
325 extern void ioreq_write32(struct adapter *adapter, u32 addr, u32 val);
328 extern uint async_read8(struct adapter *adapter, u32 addr, u8 *pbuff,
329 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
330 extern uint async_read16(struct adapter *adapter, u32 addr, u8 *pbuff,
331 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
332 extern uint async_read32(struct adapter *adapter, u32 addr, u8 *pbuff,
333 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
335 extern void async_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
336 extern void async_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
338 extern void async_write8(struct adapter *adapter, u32 addr, u8 val,
339 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
340 extern void async_write16(struct adapter *adapter, u32 addr, u16 val,
341 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
342 extern void async_write32(struct adapter *adapter, u32 addr, u32 val,
343 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
345 extern void async_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
346 extern void async_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
349 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops));
352 extern uint alloc_io_queue(struct adapter *adapter);
353 extern void free_io_queue(struct adapter *adapter);
354 extern void async_bus_io(struct io_queue *pio_q);
355 extern void bus_sync_io(struct io_queue *pio_q);
356 extern u32 _ioreq2rwmem(struct io_queue *pio_q);
357 extern void dev_power_down(struct adapter * Adapter, u8 bpwrup);
359 #define PlatformEFIOWrite1Byte(_a, _b, _c) \
360 rtw_write8(_a, _b, _c)
361 #define PlatformEFIOWrite2Byte(_a, _b, _c) \
362 rtw_write16(_a, _b, _c)
363 #define PlatformEFIOWrite4Byte(_a, _b, _c) \
364 rtw_write32(_a, _b, _c)
366 #define PlatformEFIORead1Byte(_a, _b) \
367 rtw_read8(_a, _b)
368 #define PlatformEFIORead2Byte(_a, _b) \
369 rtw_read16(_a, _b)
370 #define PlatformEFIORead4Byte(_a, _b) \
371 rtw_read32(_a, _b)
373 #endif /* _RTL8711_IO_H_ */