]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/staging/rtl8723au/core/rtw_io.c
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 ******************************************************************************/
17 The purpose of rtw_io.c
21 b. provides the protocol engine
23 c. provides the software interface between caller and the hardware interface
28 a. USE_ASYNC_IRP: Both sync/async operations are provided.
30 Only sync read/rtw_write_mem operations are provided.
32 jackson@realtek.com.tw
37 #include <osdep_service.h>
38 #include <drv_types.h>
40 #include <osdep_intf.h>
44 u8
_rtw_read823a(struct rtw_adapter
*adapter
, u32 addr
)
47 struct io_priv
*pio_priv
= &adapter
->iopriv
;
48 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
50 r_val
= pintfhdl
->io_ops
._read8(pintfhdl
, addr
);
55 u16
_rtw_read1623a(struct rtw_adapter
*adapter
, u32 addr
)
58 struct io_priv
*pio_priv
= &adapter
->iopriv
;
59 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
61 r_val
= pintfhdl
->io_ops
._read16(pintfhdl
, addr
);
63 return le16_to_cpu(r_val
);
66 u32
_rtw_read3223a(struct rtw_adapter
*adapter
, u32 addr
)
69 struct io_priv
*pio_priv
= &adapter
->iopriv
;
70 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
72 r_val
= pintfhdl
->io_ops
._read32(pintfhdl
, addr
);
74 return le32_to_cpu(r_val
);
77 int _rtw_write823a(struct rtw_adapter
*adapter
, u32 addr
, u8 val
)
79 struct io_priv
*pio_priv
= &adapter
->iopriv
;
80 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
83 ret
= pintfhdl
->io_ops
._write8(pintfhdl
, addr
, val
);
85 return RTW_STATUS_CODE23a(ret
);
88 int _rtw_write1623a(struct rtw_adapter
*adapter
, u32 addr
, u16 val
)
90 struct io_priv
*pio_priv
= &adapter
->iopriv
;
91 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
94 val
= cpu_to_le16(val
);
95 ret
= pintfhdl
->io_ops
._write16(pintfhdl
, addr
, val
);
97 return RTW_STATUS_CODE23a(ret
);
99 int _rtw_write3223a(struct rtw_adapter
*adapter
, u32 addr
, u32 val
)
101 struct io_priv
*pio_priv
= &adapter
->iopriv
;
102 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
105 val
= cpu_to_le32(val
);
106 ret
= pintfhdl
->io_ops
._write32(pintfhdl
, addr
, val
);
108 return RTW_STATUS_CODE23a(ret
);
111 int _rtw_writeN23a(struct rtw_adapter
*adapter
, u32 addr
, u32 length
, u8
*pdata
)
113 struct io_priv
*pio_priv
= &adapter
->iopriv
;
114 struct intf_hdl
*pintfhdl
= (struct intf_hdl
*)&pio_priv
->intf
;
117 ret
= pintfhdl
->io_ops
._writeN(pintfhdl
, addr
, length
, pdata
);
119 return RTW_STATUS_CODE23a(ret
);
121 int _rtw_write823a_async23a(struct rtw_adapter
*adapter
, u32 addr
, u8 val
)
123 struct io_priv
*pio_priv
= &adapter
->iopriv
;
124 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
127 ret
= pintfhdl
->io_ops
._write8_async(pintfhdl
, addr
, val
);
129 return RTW_STATUS_CODE23a(ret
);
131 int _rtw_write1623a_async(struct rtw_adapter
*adapter
, u32 addr
, u16 val
)
133 struct io_priv
*pio_priv
= &adapter
->iopriv
;
134 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
137 val
= cpu_to_le16(val
);
138 ret
= pintfhdl
->io_ops
._write16_async(pintfhdl
, addr
, val
);
140 return RTW_STATUS_CODE23a(ret
);
142 int _rtw_write3223a_async23a(struct rtw_adapter
*adapter
, u32 addr
, u32 val
)
144 struct io_priv
*pio_priv
= &adapter
->iopriv
;
145 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
148 val
= cpu_to_le32(val
);
149 ret
= pintfhdl
->io_ops
._write32_async(pintfhdl
, addr
, val
);
151 return RTW_STATUS_CODE23a(ret
);
154 void _rtw_read_mem23a(struct rtw_adapter
*adapter
, u32 addr
, u32 cnt
, u8
*pmem
)
156 struct io_priv
*pio_priv
= &adapter
->iopriv
;
157 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
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
));
168 pintfhdl
->io_ops
._read_mem(pintfhdl
, addr
, cnt
, pmem
);
171 void _rtw_write_mem23a(struct rtw_adapter
*adapter
, u32 addr
, u32 cnt
, u8
*pmem
)
173 struct io_priv
*pio_priv
= &adapter
->iopriv
;
174 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
176 pintfhdl
->io_ops
._write_mem(pintfhdl
, addr
, cnt
, pmem
);
179 void _rtw_read_port23a(struct rtw_adapter
*adapter
, u32 addr
, u32 cnt
,
180 struct recv_buf
*rbuf
)
182 struct io_priv
*pio_priv
= &adapter
->iopriv
;
183 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
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
));
194 pintfhdl
->io_ops
._read_port(pintfhdl
, addr
, cnt
, rbuf
);
197 void _rtw_read_port23a_cancel(struct rtw_adapter
*adapter
)
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
;
203 _read_port_cancel
= pintfhdl
->io_ops
._read_port_cancel
;
205 if (_read_port_cancel
)
206 _read_port_cancel(pintfhdl
);
209 u32
_rtw_write_port23a(struct rtw_adapter
*adapter
, u32 addr
, u32 cnt
,
210 struct xmit_buf
*xbuf
)
212 struct io_priv
*pio_priv
= &adapter
->iopriv
;
213 struct intf_hdl
*pintfhdl
= &pio_priv
->intf
;
216 ret
= pintfhdl
->io_ops
._write_port(pintfhdl
, addr
, cnt
, xbuf
);
221 u32
_rtw_write_port23a_and_wait23a(struct rtw_adapter
*adapter
, u32 addr
, u32 cnt
,
222 struct xmit_buf
*pxmitbuf
, int timeout_ms
)
225 struct submit_ctx sctx
;
227 rtw_sctx_init23a(&sctx
, timeout_ms
);
228 pxmitbuf
->sctx
= &sctx
;
230 ret
= _rtw_write_port23a(adapter
, addr
, cnt
, pxmitbuf
);
233 ret
= rtw_sctx_wait23a(&sctx
);
238 void _rtw_write_port23a_cancel(struct rtw_adapter
*adapter
)
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
;
244 _write_port_cancel
= pintfhdl
->io_ops
._write_port_cancel
;
246 if (_write_port_cancel
)
247 _write_port_cancel(pintfhdl
);
250 int rtw_init_io_priv23a(struct rtw_adapter
*padapter
,
251 void (*set_intf_ops
)(struct _io_ops
*pops
))
253 struct io_priv
*piopriv
= &padapter
->iopriv
;
254 struct intf_hdl
*pintf
= &piopriv
->intf
;
256 if (set_intf_ops
== NULL
)
259 piopriv
->padapter
= padapter
;
260 pintf
->padapter
= padapter
;
261 pintf
->pintf_dev
= adapter_to_dvobj(padapter
);
263 set_intf_ops(&pintf
->io_ops
);