xref: /linux/drivers/staging/rtl8723bs/include/rtw_io.h (revision b83deaa741558babf4b8d51d34f6637ccfff1b26)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 
8 #ifndef _RTW_IO_H_
9 #define _RTW_IO_H_
10 
11 #define NUM_IOREQ		8
12 
13 #define MAX_PROT_SZ	(64-16)
14 
15 #define _IOREADY			0
16 #define _IO_WAIT_COMPLETE   1
17 #define _IO_WAIT_RSP        2
18 
19 /*  IO COMMAND TYPE */
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)
29 
30 
31 /*
32 	For prompt mode accessing, caller shall free io_req
33 	Otherwise, io_handler will free io_req
34 */
35 
36 
37 
38 /*  IO STATUS TYPE */
39 #define _IO_ERR_		BIT(2)
40 #define _IO_SUCCESS_	BIT(1)
41 #define _IO_DONE_		BIT(0)
42 
43 
44 #define IO_RD32			(_IO_SYNC_ | _IO_WORD_)
45 #define IO_RD16			(_IO_SYNC_ | _IO_HW_)
46 #define IO_RD8			(_IO_SYNC_ | _IO_BYTE_)
47 
48 #define IO_RD32_ASYNC	(_IO_WORD_)
49 #define IO_RD16_ASYNC	(_IO_HW_)
50 #define IO_RD8_ASYNC	(_IO_BYTE_)
51 
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_)
55 
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_)
59 
60 /*
61 
62 	Only Sync. burst accessing is provided.
63 
64 */
65 
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_))
68 
69 
70 
71 /* below is for the intf_option bit defition... */
72 
73 #define _INTF_ASYNC_	BIT(0)	/* support async io */
74 
75 struct intf_priv;
76 struct intf_hdl;
77 struct io_queue;
78 
79 struct _io_ops {
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);
83 
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);
88 
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);
92 
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);
95 
96 		void (*_sync_irp_protocol_rw)(struct io_queue *pio_q);
97 
98 		u32 (*_read_interrupt)(struct intf_hdl *pintfhdl, u32 addr);
99 
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);
102 
103 		u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
104 
105 		void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
106 		void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
107 };
108 
109 struct io_req {
110 	struct list_head	list;
111 	u32 addr;
112 	volatile u32 val;
113 	u32 command;
114 	u32 status;
115 	u8 *pbuf;
116 
117 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt);
118 	u8 *cnxt;
119 };
120 
121 struct	intf_hdl {
122 	struct adapter *padapter;
123 	struct dvobj_priv *pintf_dev;/* 	pointer to &(padapter->dvobjpriv); */
124 
125 	struct _io_ops	io_ops;
126 };
127 
128 #define SD_IO_TRY_CNT (8)
129 #define MAX_CONTINUAL_IO_ERR SD_IO_TRY_CNT
130 
131 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj);
132 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj);
133 
134 /*
135 Below is the data structure used by _io_handler
136 
137 */
138 
139 struct io_queue {
140 	spinlock_t	lock;
141 	struct list_head	free_ioreqs;
142 	struct list_head		pending;		/* The io_req list that will be served in the single protocol read/write. */
143 	struct list_head		processing;
144 	u8 *free_ioreqs_buf; /*  4-byte aligned */
145 	u8 *pallocated_free_ioreqs_buf;
146 	struct	intf_hdl	intf;
147 };
148 
149 struct io_priv {
150 
151 	struct adapter *padapter;
152 
153 	struct intf_hdl intf;
154 
155 };
156 
157 extern uint ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
158 extern void sync_ioreq_enqueue(struct io_req *preq, struct io_queue *ioqueue);
159 extern uint sync_ioreq_flush(struct adapter *adapter, struct io_queue *ioqueue);
160 
161 
162 extern uint free_ioreq(struct io_req *preq, struct io_queue *pio_queue);
163 extern struct io_req *alloc_ioreq(struct io_queue *pio_q);
164 
165 extern uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl);
166 extern void unregister_intf_hdl(struct intf_hdl *pintfhdl);
167 
168 extern void _rtw_attrib_read(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
169 extern void _rtw_attrib_write(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
170 
171 extern u8 rtw_read8(struct adapter *adapter, u32 addr);
172 extern u16 rtw_read16(struct adapter *adapter, u32 addr);
173 extern u32 rtw_read32(struct adapter *adapter, u32 addr);
174 
175 extern int rtw_write8(struct adapter *adapter, u32 addr, u8 val);
176 extern int rtw_write16(struct adapter *adapter, u32 addr, u16 val);
177 extern int rtw_write32(struct adapter *adapter, u32 addr, u32 val);
178 
179 extern u32 rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
180 
181 extern void rtw_write_scsi(struct adapter *adapter, u32 cnt, u8 *pmem);
182 
183 /* ioreq */
184 extern void ioreq_read8(struct adapter *adapter, u32 addr, u8 *pval);
185 extern void ioreq_read16(struct adapter *adapter, u32 addr, u16 *pval);
186 extern void ioreq_read32(struct adapter *adapter, u32 addr, u32 *pval);
187 extern void ioreq_write8(struct adapter *adapter, u32 addr, u8 val);
188 extern void ioreq_write16(struct adapter *adapter, u32 addr, u16 val);
189 extern void ioreq_write32(struct adapter *adapter, u32 addr, u32 val);
190 
191 
192 extern uint async_read8(struct adapter *adapter, u32 addr, u8 *pbuff,
193 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
194 extern uint async_read16(struct adapter *adapter, u32 addr,  u8 *pbuff,
195 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
196 extern uint async_read32(struct adapter *adapter, u32 addr,  u8 *pbuff,
197 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
198 
199 extern void async_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
200 extern void async_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
201 
202 extern void async_write8(struct adapter *adapter, u32 addr, u8 val,
203 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
204 extern void async_write16(struct adapter *adapter, u32 addr, u16 val,
205 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
206 extern void async_write32(struct adapter *adapter, u32 addr, u32 val,
207 	void (*_async_io_callback)(struct adapter *padater, struct io_req *pio_req, u8 *cnxt), u8 *cnxt);
208 
209 extern void async_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
210 extern void async_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem);
211 
212 
213 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops));
214 
215 
216 extern uint alloc_io_queue(struct adapter *adapter);
217 extern void free_io_queue(struct adapter *adapter);
218 extern void async_bus_io(struct io_queue *pio_q);
219 extern void bus_sync_io(struct io_queue *pio_q);
220 extern u32 _ioreq2rwmem(struct io_queue *pio_q);
221 extern void dev_power_down(struct adapter *Adapter, u8 bpwrup);
222 
223 #endif	/* _RTL8711_IO_H_ */
224