1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
13 #define MAX_PROT_SZ (64-16)
16 #define _IO_WAIT_COMPLETE 1
17 #define _IO_WAIT_RSP 2
20 #define _IOSZ_MASK_ (0x7F)
21 #define _IO_WRITE_ BIT(7)
22 #define _IO_FIXED_ BIT(8)
23 #define _IO_BURST_ BIT(9)
24 #define _IO_BYTE_ BIT(10)
25 #define _IO_HW_ BIT(11)
26 #define _IO_WORD_ BIT(12)
27 #define _IO_SYNC_ BIT(13)
28 #define _IO_CMDMASK_ (0x1F80)
32 For prompt mode accessing, caller shall free io_req
33 Otherwise, io_handler will free io_req
39 #define _IO_ERR_ BIT(2)
40 #define _IO_SUCCESS_ BIT(1)
41 #define _IO_DONE_ BIT(0)
44 #define IO_RD32 (_IO_SYNC_ | _IO_WORD_)
45 #define IO_RD16 (_IO_SYNC_ | _IO_HW_)
46 #define IO_RD8 (_IO_SYNC_ | _IO_BYTE_)
48 #define IO_RD32_ASYNC (_IO_WORD_)
49 #define IO_RD16_ASYNC (_IO_HW_)
50 #define IO_RD8_ASYNC (_IO_BYTE_)
52 #define IO_WR32 (_IO_WRITE_ | _IO_SYNC_ | _IO_WORD_)
53 #define IO_WR16 (_IO_WRITE_ | _IO_SYNC_ | _IO_HW_)
54 #define IO_WR8 (_IO_WRITE_ | _IO_SYNC_ | _IO_BYTE_)
56 #define IO_WR32_ASYNC (_IO_WRITE_ | _IO_WORD_)
57 #define IO_WR16_ASYNC (_IO_WRITE_ | _IO_HW_)
58 #define IO_WR8_ASYNC (_IO_WRITE_ | _IO_BYTE_)
62 Only Sync. burst accessing is provided.
66 #define IO_WR_BURST(x) (_IO_WRITE_ | _IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_))
67 #define IO_RD_BURST(x) (_IO_SYNC_ | _IO_BURST_ | ((x) & _IOSZ_MASK_))
71 /* below is for the intf_option bit defition... */
73 #define _INTF_ASYNC_ BIT(0) /* support async io */
80 u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
81 u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
82 u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
84 int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
85 int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
86 int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
87 int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata);
89 int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
90 int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
91 int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
93 void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
94 void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
96 void (*_sync_irp_protocol_rw)(struct io_queue *pio_q);
98 u32 (*_read_interrupt)(struct intf_hdl *pintfhdl, u32 addr);
100 u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
101 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
103 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
105 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
106 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
108 u8 (*_sd_f0_read8)(struct intf_hdl *pintfhdl, u32 addr);
112 struct list_head list;
120 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt);
125 struct adapter *padapter;
126 struct dvobj_priv *pintf_dev;/* pointer to &(padapter->dvobjpriv); */
128 struct _io_ops io_ops;
131 struct reg_protocol_rd {
133 #ifdef __LITTLE_ENDIAN
141 u32 WriteEnable:1; /* 0:read, 1:write */
142 u32 FixOrContinuous:1; /* 0:continuous, 1: Fix */
173 u32 FixOrContinuous : 1;
188 struct reg_protocol_wt {
191 #ifdef __LITTLE_ENDIAN
199 u32 WriteEnable:1; /* 0:read, 1:write */
200 u32 FixOrContinuous:1; /* 0:continuous, 1: Fix */
229 u32 FixOrContinuous : 1;
242 #define SD_IO_TRY_CNT (8)
243 #define MAX_CONTINUAL_IO_ERR SD_IO_TRY_CNT
245 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj);
246 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj);
249 Below is the data structure used by _io_handler
255 struct list_head free_ioreqs;
256 struct list_head pending; /* The io_req list that will be served in the single protocol read/write. */
257 struct list_head processing;
258 u8 *free_ioreqs_buf; /* 4-byte aligned */
259 u8 *pallocated_free_ioreqs_buf;
260 struct intf_hdl intf;
265 struct adapter *padapter;
267 struct intf_hdl intf;
271 extern uint ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
272 extern void sync_ioreq_enqueue(struct io_req *preq, struct io_queue *ioqueue);
273 extern uint sync_ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
276 extern uint free_ioreq(struct io_req *preq, struct io_queue *pio_queue);
277 extern struct io_req *alloc_ioreq(struct io_queue *pio_q);
279 extern uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl);
280 extern void unregister_intf_hdl(struct intf_hdl *pintfhdl);
282 extern void _rtw_attrib_read(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
283 extern void _rtw_attrib_write(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
285 extern u8 _rtw_read8(struct adapter *adapter, u32 addr);
286 extern u16 _rtw_read16(struct adapter *adapter, u32 addr);
287 extern u32 _rtw_read32(struct adapter *adapter, u32 addr);
289 extern int _rtw_write8(struct adapter *adapter, u32 addr, u8 val);
290 extern int _rtw_write16(struct adapter *adapter, u32 addr, u16 val);
291 extern int _rtw_write32(struct adapter *adapter, u32 addr, u32 val);
293 extern u8 _rtw_sd_f0_read8(struct adapter *adapter, u32 addr);
295 extern u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
297 #define rtw_read8(adapter, addr) _rtw_read8((adapter), (addr))
298 #define rtw_read16(adapter, addr) _rtw_read16((adapter), (addr))
299 #define rtw_read32(adapter, addr) _rtw_read32((adapter), (addr))
301 #define rtw_write8(adapter, addr, val) _rtw_write8((adapter), (addr), (val))
302 #define rtw_write16(adapter, addr, val) _rtw_write16((adapter), (addr), (val))
303 #define rtw_write32(adapter, addr, val) _rtw_write32((adapter), (addr), (val))
305 #define rtw_write_port(adapter, addr, cnt, mem) _rtw_write_port((adapter), (addr), (cnt), (mem))
307 #define rtw_sd_f0_read8(adapter, addr) _rtw_sd_f0_read8((adapter), (addr))
309 extern void rtw_write_scsi(struct adapter *adapter, u32 cnt, u8 *pmem);
312 extern void ioreq_read8(struct adapter *adapter, u32 addr, u8 *pval);
313 extern void ioreq_read16(struct adapter *adapter, u32 addr, u16 *pval);
314 extern void ioreq_read32(struct adapter *adapter, u32 addr, u32 *pval);
315 extern void ioreq_write8(struct adapter *adapter, u32 addr, u8 val);
316 extern void ioreq_write16(struct adapter *adapter, u32 addr, u16 val);
317 extern void ioreq_write32(struct adapter *adapter, u32 addr, u32 val);
320 extern uint async_read8(struct adapter *adapter, u32 addr, u8 *pbuff,
321 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
322 extern uint async_read16(struct adapter *adapter, u32 addr, u8 *pbuff,
323 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
324 extern uint async_read32(struct adapter *adapter, u32 addr, u8 *pbuff,
325 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
327 extern void async_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
328 extern void async_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
330 extern void async_write8(struct adapter *adapter, u32 addr, u8 val,
331 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
332 extern void async_write16(struct adapter *adapter, u32 addr, u16 val,
333 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
334 extern void async_write32(struct adapter *adapter, u32 addr, u32 val,
335 void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
337 extern void async_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
338 extern void async_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
341 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops));
344 extern uint alloc_io_queue(struct adapter *adapter);
345 extern void free_io_queue(struct adapter *adapter);
346 extern void async_bus_io(struct io_queue *pio_q);
347 extern void bus_sync_io(struct io_queue *pio_q);
348 extern u32 _ioreq2rwmem(struct io_queue *pio_q);
349 extern void dev_power_down(struct adapter * Adapter, u8 bpwrup);
351 #define PlatformEFIOWrite1Byte(_a, _b, _c) \
352 rtw_write8(_a, _b, _c)
353 #define PlatformEFIOWrite2Byte(_a, _b, _c) \
354 rtw_write16(_a, _b, _c)
355 #define PlatformEFIOWrite4Byte(_a, _b, _c) \
356 rtw_write32(_a, _b, _c)
358 #define PlatformEFIORead1Byte(_a, _b) \
360 #define PlatformEFIORead2Byte(_a, _b) \
362 #define PlatformEFIORead4Byte(_a, _b) \
365 #endif /* _RTL8711_IO_H_ */