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
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
19 ******************************************************************************/
24 #include <osdep_service.h>
25 #include <osdep_intf.h>
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>
33 #include <linux/usb.h>
34 #include <linux/usb/ch9.h>
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))
44 #define MAX_PROT_SZ (64-16)
47 #define _IO_WAIT_COMPLETE 1
48 #define _IO_WAIT_RSP 2
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)
62 For prompt mode accessing, caller shall free io_req
63 Otherwise, io_handler will free io_req
67 #define _IO_ERR_ BIT(2)
68 #define _IO_SUCCESS_ BIT(1)
69 #define _IO_DONE_ BIT(0)
71 #define IO_RD32 (_IO_SYNC_ | _IO_WORD_)
72 #define IO_RD16 (_IO_SYNC_ | _IO_HW_)
73 #define IO_RD8 (_IO_SYNC_ | _IO_BYTE_)
75 #define IO_RD32_ASYNC (_IO_WORD_)
76 #define IO_RD16_ASYNC (_IO_HW_)
77 #define IO_RD8_ASYNC (_IO_BYTE_)
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_)
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_)
88 Only Sync. burst accessing is provided.
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_))
96 /* below is for the intf_option bit defition... */
98 #define _INTF_ASYNC_ BIT(0) /* support async io */
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
,
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
,
118 void (*_write_mem
)(struct intf_hdl
*pintfhdl
, u32 addr
, u32 cnt
,
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
,
124 u32 (*_write_port
)(struct intf_hdl
*pintfhdl
, u32 addr
, u32 cnt
,
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
);
132 struct list_head list
;
138 struct semaphore sema
;
140 void (*_async_io_callback
)(struct adapter
*padater
,
141 struct io_req
*pio_req
, u8
*cnxt
);
146 struct adapter
*padapter
;
147 struct dvobj_priv
*pintf_dev
;
148 struct _io_ops io_ops
;
151 struct reg_protocol_rd
{
152 #ifdef __LITTLE_ENDIAN
159 u32 WriteEnable
:1; /* 0:read, 1:write */
160 u32 FixOrContinuous
:1; /* 0:continuous, 1: Fix */
185 u32 FixOrContinuous
:1;
194 struct reg_protocol_wt
{
195 #ifdef __LITTLE_ENDIAN
202 u32 WriteEnable
:1; /* 0:read, 1:write */
203 u32 FixOrContinuous
:1; /* 0:continuous, 1: Fix */
227 u32 FixOrContinuous
:1;
237 Below is the data structure used by _io_handler
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
;
252 struct adapter
*padapter
;
253 struct intf_hdl intf
;
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
);
262 uint
register_intf_hdl(u8
*dev
, struct intf_hdl
*pintfhdl
);
263 void unregister_intf_hdl(struct intf_hdl
*pintfhdl
);
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
);
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
);
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
);
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
);
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
);
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))
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))
321 void rtw_write_scsi(struct adapter
*adapter
, u32 cnt
, u8
*pmem
);
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
);
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
);
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
);
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
);
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
);
363 int rtw_init_io_priv(struct adapter
*padapter
,
364 void (*set_intf_ops
)(struct _io_ops
*pops
));
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
);
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)
380 #define PlatformEFIORead1Byte(_a, _b) \
382 #define PlatformEFIORead2Byte(_a, _b) \
384 #define PlatformEFIORead4Byte(_a, _b) \
387 #endif /* _RTL8711_IO_H_ */