]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/staging/rtl8723au/core/rtw_io.c
Merge tag 'pm+acpi-3.15-rc1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafae...
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / rtl8723au / core / rtw_io.c
1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
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.
8 *
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.
13 *
14 ******************************************************************************/
15 /*
16
17 The purpose of rtw_io.c
18
19 a. provides the API
20
21 b. provides the protocol engine
22
23 c. provides the software interface between caller and the hardware interface
24
25 Compiler Flag Option:
26
27 1. For USB:
28 a. USE_ASYNC_IRP: Both sync/async operations are provided.
29
30 Only sync read/rtw_write_mem operations are provided.
31
32 jackson@realtek.com.tw
33
34 */
35
36 #define _RTW_IO_C_
37 #include <osdep_service.h>
38 #include <drv_types.h>
39 #include <rtw_io.h>
40 #include <osdep_intf.h>
41
42 #include <usb_ops.h>
43
44 u8 _rtw_read823a(struct rtw_adapter *adapter, u32 addr)
45 {
46 u8 r_val;
47 struct io_priv *pio_priv = &adapter->iopriv;
48 struct intf_hdl *pintfhdl = &pio_priv->intf;
49
50 r_val = pintfhdl->io_ops._read8(pintfhdl, addr);
51
52 return r_val;
53 }
54
55 u16 _rtw_read1623a(struct rtw_adapter *adapter, u32 addr)
56 {
57 u16 r_val;
58 struct io_priv *pio_priv = &adapter->iopriv;
59 struct intf_hdl *pintfhdl = &pio_priv->intf;
60
61 r_val = pintfhdl->io_ops._read16(pintfhdl, addr);
62
63 return le16_to_cpu(r_val);
64 }
65
66 u32 _rtw_read3223a(struct rtw_adapter *adapter, u32 addr)
67 {
68 u32 r_val;
69 struct io_priv *pio_priv = &adapter->iopriv;
70 struct intf_hdl *pintfhdl = &pio_priv->intf;
71
72 r_val = pintfhdl->io_ops._read32(pintfhdl, addr);
73
74 return le32_to_cpu(r_val);
75 }
76
77 int _rtw_write823a(struct rtw_adapter *adapter, u32 addr, u8 val)
78 {
79 struct io_priv *pio_priv = &adapter->iopriv;
80 struct intf_hdl *pintfhdl = &pio_priv->intf;
81 int ret;
82
83 ret = pintfhdl->io_ops._write8(pintfhdl, addr, val);
84
85 return RTW_STATUS_CODE23a(ret);
86 }
87
88 int _rtw_write1623a(struct rtw_adapter *adapter, u32 addr, u16 val)
89 {
90 struct io_priv *pio_priv = &adapter->iopriv;
91 struct intf_hdl *pintfhdl = &pio_priv->intf;
92 int ret;
93
94 val = cpu_to_le16(val);
95 ret = pintfhdl->io_ops._write16(pintfhdl, addr, val);
96
97 return RTW_STATUS_CODE23a(ret);
98 }
99 int _rtw_write3223a(struct rtw_adapter *adapter, u32 addr, u32 val)
100 {
101 struct io_priv *pio_priv = &adapter->iopriv;
102 struct intf_hdl *pintfhdl = &pio_priv->intf;
103 int ret;
104
105 val = cpu_to_le32(val);
106 ret = pintfhdl->io_ops._write32(pintfhdl, addr, val);
107
108 return RTW_STATUS_CODE23a(ret);
109 }
110
111 int _rtw_writeN23a(struct rtw_adapter *adapter, u32 addr , u32 length , u8 *pdata)
112 {
113 struct io_priv *pio_priv = &adapter->iopriv;
114 struct intf_hdl *pintfhdl = (struct intf_hdl*)&pio_priv->intf;
115 int ret;
116
117 ret = pintfhdl->io_ops._writeN(pintfhdl, addr, length, pdata);
118
119 return RTW_STATUS_CODE23a(ret);
120 }
121 int _rtw_write823a_async23a(struct rtw_adapter *adapter, u32 addr, u8 val)
122 {
123 struct io_priv *pio_priv = &adapter->iopriv;
124 struct intf_hdl *pintfhdl = &pio_priv->intf;
125 int ret;
126
127 ret = pintfhdl->io_ops._write8_async(pintfhdl, addr, val);
128
129 return RTW_STATUS_CODE23a(ret);
130 }
131 int _rtw_write1623a_async(struct rtw_adapter *adapter, u32 addr, u16 val)
132 {
133 struct io_priv *pio_priv = &adapter->iopriv;
134 struct intf_hdl *pintfhdl = &pio_priv->intf;
135 int ret;
136
137 val = cpu_to_le16(val);
138 ret = pintfhdl->io_ops._write16_async(pintfhdl, addr, val);
139
140 return RTW_STATUS_CODE23a(ret);
141 }
142 int _rtw_write3223a_async23a(struct rtw_adapter *adapter, u32 addr, u32 val)
143 {
144 struct io_priv *pio_priv = &adapter->iopriv;
145 struct intf_hdl *pintfhdl = &pio_priv->intf;
146 int ret;
147
148 val = cpu_to_le32(val);
149 ret = pintfhdl->io_ops._write32_async(pintfhdl, addr, val);
150
151 return RTW_STATUS_CODE23a(ret);
152 }
153
154 void _rtw_read_mem23a(struct rtw_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
155 {
156 struct io_priv *pio_priv = &adapter->iopriv;
157 struct intf_hdl *pintfhdl = &pio_priv->intf;
158
159 if ((adapter->bDriverStopped == true) ||
160 (adapter->bSurpriseRemoved == true)) {
161 RT_TRACE(_module_rtl871x_io_c_, _drv_info_,
162 ("rtw_read_mem:bDriverStopped(%d) OR "
163 "bSurpriseRemoved(%d)", adapter->bDriverStopped,
164 adapter->bSurpriseRemoved));
165 return;
166 }
167
168 pintfhdl->io_ops._read_mem(pintfhdl, addr, cnt, pmem);
169 }
170
171 void _rtw_write_mem23a(struct rtw_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
172 {
173 struct io_priv *pio_priv = &adapter->iopriv;
174 struct intf_hdl *pintfhdl = &pio_priv->intf;
175
176 pintfhdl->io_ops._write_mem(pintfhdl, addr, cnt, pmem);
177 }
178
179 void _rtw_read_port23a(struct rtw_adapter *adapter, u32 addr, u32 cnt,
180 struct recv_buf *rbuf)
181 {
182 struct io_priv *pio_priv = &adapter->iopriv;
183 struct intf_hdl *pintfhdl = &pio_priv->intf;
184
185 if ((adapter->bDriverStopped == true) ||
186 (adapter->bSurpriseRemoved == true)) {
187 RT_TRACE(_module_rtl871x_io_c_, _drv_info_,
188 ("rtw_read_port:bDriverStopped(%d) OR "
189 "bSurpriseRemoved(%d)", adapter->bDriverStopped,
190 adapter->bSurpriseRemoved));
191 return;
192 }
193
194 pintfhdl->io_ops._read_port(pintfhdl, addr, cnt, rbuf);
195 }
196
197 void _rtw_read_port23a_cancel(struct rtw_adapter *adapter)
198 {
199 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
200 struct io_priv *pio_priv = &adapter->iopriv;
201 struct intf_hdl *pintfhdl = &pio_priv->intf;
202
203 _read_port_cancel = pintfhdl->io_ops._read_port_cancel;
204
205 if (_read_port_cancel)
206 _read_port_cancel(pintfhdl);
207 }
208
209 u32 _rtw_write_port23a(struct rtw_adapter *adapter, u32 addr, u32 cnt,
210 struct xmit_buf *xbuf)
211 {
212 struct io_priv *pio_priv = &adapter->iopriv;
213 struct intf_hdl *pintfhdl = &pio_priv->intf;
214 u32 ret = _SUCCESS;
215
216 ret = pintfhdl->io_ops._write_port(pintfhdl, addr, cnt, xbuf);
217
218 return ret;
219 }
220
221 u32 _rtw_write_port23a_and_wait23a(struct rtw_adapter *adapter, u32 addr, u32 cnt,
222 struct xmit_buf *pxmitbuf, int timeout_ms)
223 {
224 int ret = _SUCCESS;
225 struct submit_ctx sctx;
226
227 rtw_sctx_init23a(&sctx, timeout_ms);
228 pxmitbuf->sctx = &sctx;
229
230 ret = _rtw_write_port23a(adapter, addr, cnt, pxmitbuf);
231
232 if (ret == _SUCCESS)
233 ret = rtw_sctx_wait23a(&sctx);
234
235 return ret;
236 }
237
238 void _rtw_write_port23a_cancel(struct rtw_adapter *adapter)
239 {
240 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
241 struct io_priv *pio_priv = &adapter->iopriv;
242 struct intf_hdl *pintfhdl = &pio_priv->intf;
243
244 _write_port_cancel = pintfhdl->io_ops._write_port_cancel;
245
246 if (_write_port_cancel)
247 _write_port_cancel(pintfhdl);
248 }
249
250 int rtw_init_io_priv23a(struct rtw_adapter *padapter,
251 void (*set_intf_ops)(struct _io_ops *pops))
252 {
253 struct io_priv *piopriv = &padapter->iopriv;
254 struct intf_hdl *pintf = &piopriv->intf;
255
256 if (set_intf_ops == NULL)
257 return _FAIL;
258
259 piopriv->padapter = padapter;
260 pintf->padapter = padapter;
261 pintf->pintf_dev = adapter_to_dvobj(padapter);
262
263 set_intf_ops(&pintf->io_ops);
264
265 return _SUCCESS;
266 }