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 ******************************************************************************/
21 #define MAX_PROT_SZ (64-16)
24 #define _IO_WAIT_COMPLETE 1
25 #define _IO_WAIT_RSP 2
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
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 */
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
);
120 struct list_head list
;
128 void (*_async_io_callback
)(struct adapter
*padater
, struct io_req
*pio_req
, u8
*cnxt
);
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
149 u32 WriteEnable
:1; /* 0:read, 1:write */
150 u32 FixOrContinuous
:1; /* 0:continuous, 1: Fix */
181 u32 FixOrContinuous
: 1;
196 struct reg_protocol_wt
{
199 #ifdef __LITTLE_ENDIAN
207 u32 WriteEnable
:1; /* 0:read, 1:write */
208 u32 FixOrContinuous
:1; /* 0:continuous, 1: Fix */
237 u32 FixOrContinuous
: 1;
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
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
;
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
);
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) \
368 #define PlatformEFIORead2Byte(_a, _b) \
370 #define PlatformEFIORead4Byte(_a, _b) \
373 #endif /* _RTL8711_IO_H_ */