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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 The purpose of rtw_io.c
26 b. provides the protocol engine
28 c. provides the software interface between caller and the hardware interface
34 a. USE_ASYNC_IRP: Both sync/async operations are provided.
36 Only sync read/rtw_write_mem operations are provided.
38 jackson@realtek.com.tw
43 #include <osdep_service.h>
44 #include <drv_types.h>
46 #include <osdep_intf.h>
49 #define rtw_le16_to_cpu(val) le16_to_cpu(val)
50 #define rtw_le32_to_cpu(val) le32_to_cpu(val)
51 #define rtw_cpu_to_le16(val) cpu_to_le16(val)
52 #define rtw_cpu_to_le32(val) cpu_to_le32(val)
55 u8 _rtw_read8(struct adapter *adapter, u32 addr)
58 struct io_priv *pio_priv = &adapter->iopriv;
59 struct intf_hdl *pintfhdl = &(pio_priv->intf);
60 u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
63 _read8 = pintfhdl->io_ops._read8;
64 r_val = _read8(pintfhdl, addr);
69 u16 _rtw_read16(struct adapter *adapter, u32 addr)
72 struct io_priv *pio_priv = &adapter->iopriv;
73 struct intf_hdl *pintfhdl = &(pio_priv->intf);
74 u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
76 _read16 = pintfhdl->io_ops._read16;
78 r_val = _read16(pintfhdl, addr);
83 u32 _rtw_read32(struct adapter *adapter, u32 addr)
86 struct io_priv *pio_priv = &adapter->iopriv;
87 struct intf_hdl *pintfhdl = &(pio_priv->intf);
88 u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
90 _read32 = pintfhdl->io_ops._read32;
92 r_val = _read32(pintfhdl, addr);
97 int _rtw_write8(struct adapter *adapter, u32 addr, u8 val)
99 struct io_priv *pio_priv = &adapter->iopriv;
100 struct intf_hdl *pintfhdl = &(pio_priv->intf);
101 int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
104 _write8 = pintfhdl->io_ops._write8;
106 ret = _write8(pintfhdl, addr, val);
109 return RTW_STATUS_CODE(ret);
112 int _rtw_write16(struct adapter *adapter, u32 addr, u16 val)
114 struct io_priv *pio_priv = &adapter->iopriv;
115 struct intf_hdl *pintfhdl = &(pio_priv->intf);
116 int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
119 _write16 = pintfhdl->io_ops._write16;
121 ret = _write16(pintfhdl, addr, val);
124 return RTW_STATUS_CODE(ret);
126 int _rtw_write32(struct adapter *adapter, u32 addr, u32 val)
128 struct io_priv *pio_priv = &adapter->iopriv;
129 struct intf_hdl *pintfhdl = &(pio_priv->intf);
130 int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
133 _write32 = pintfhdl->io_ops._write32;
135 ret = _write32(pintfhdl, addr, val);
138 return RTW_STATUS_CODE(ret);
141 int _rtw_writeN(struct adapter *adapter, u32 addr , u32 length , u8 *pdata)
143 struct io_priv *pio_priv = &adapter->iopriv;
144 struct intf_hdl *pintfhdl = (struct intf_hdl *)(&(pio_priv->intf));
145 int (*_writeN)(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata);
148 _writeN = pintfhdl->io_ops._writeN;
150 ret = _writeN(pintfhdl, addr, length, pdata);
153 return RTW_STATUS_CODE(ret);
155 int _rtw_write8_async(struct adapter *adapter, u32 addr, u8 val)
157 struct io_priv *pio_priv = &adapter->iopriv;
158 struct intf_hdl *pintfhdl = &(pio_priv->intf);
159 int (*_write8_async)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
162 _write8_async = pintfhdl->io_ops._write8_async;
164 ret = _write8_async(pintfhdl, addr, val);
167 return RTW_STATUS_CODE(ret);
170 int _rtw_write16_async(struct adapter *adapter, u32 addr, u16 val)
172 struct io_priv *pio_priv = &adapter->iopriv;
173 struct intf_hdl *pintfhdl = &(pio_priv->intf);
174 int (*_write16_async)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
178 _write16_async = pintfhdl->io_ops._write16_async;
179 ret = _write16_async(pintfhdl, addr, val);
182 return RTW_STATUS_CODE(ret);
185 int _rtw_write32_async(struct adapter *adapter, u32 addr, u32 val)
187 struct io_priv *pio_priv = &adapter->iopriv;
188 struct intf_hdl *pintfhdl = &(pio_priv->intf);
189 int (*_write32_async)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
193 _write32_async = pintfhdl->io_ops._write32_async;
194 ret = _write32_async(pintfhdl, addr, val);
197 return RTW_STATUS_CODE(ret);
200 void _rtw_read_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
202 void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
203 struct io_priv *pio_priv = &adapter->iopriv;
204 struct intf_hdl *pintfhdl = &(pio_priv->intf);
207 if (adapter->bDriverStopped || adapter->bSurpriseRemoved) {
208 RT_TRACE(_module_rtl871x_io_c_, _drv_info_,
209 ("rtw_read_mem:bDriverStopped(%d) OR bSurpriseRemoved(%d)",
210 adapter->bDriverStopped, adapter->bSurpriseRemoved));
213 _read_mem = pintfhdl->io_ops._read_mem;
214 _read_mem(pintfhdl, addr, cnt, pmem);
218 void _rtw_write_mem(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
220 void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
221 struct io_priv *pio_priv = &adapter->iopriv;
222 struct intf_hdl *pintfhdl = &(pio_priv->intf);
226 _write_mem = pintfhdl->io_ops._write_mem;
228 _write_mem(pintfhdl, addr, cnt, pmem);
233 void _rtw_read_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
235 u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
236 struct io_priv *pio_priv = &adapter->iopriv;
237 struct intf_hdl *pintfhdl = &(pio_priv->intf);
241 if (adapter->bDriverStopped || adapter->bSurpriseRemoved) {
242 RT_TRACE(_module_rtl871x_io_c_, _drv_info_,
243 ("rtw_read_port:bDriverStopped(%d) OR bSurpriseRemoved(%d)",
244 adapter->bDriverStopped, adapter->bSurpriseRemoved));
248 _read_port = pintfhdl->io_ops._read_port;
250 _read_port(pintfhdl, addr, cnt, pmem);
255 void _rtw_read_port_cancel(struct adapter *adapter)
257 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
258 struct io_priv *pio_priv = &adapter->iopriv;
259 struct intf_hdl *pintfhdl = &(pio_priv->intf);
261 _read_port_cancel = pintfhdl->io_ops._read_port_cancel;
263 if (_read_port_cancel)
264 _read_port_cancel(pintfhdl);
267 u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
269 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
270 struct io_priv *pio_priv = &adapter->iopriv;
271 struct intf_hdl *pintfhdl = &(pio_priv->intf);
276 _write_port = pintfhdl->io_ops._write_port;
278 ret = _write_port(pintfhdl, addr, cnt, pmem);
285 u32 _rtw_write_port_and_wait(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem, int timeout_ms)
288 struct xmit_buf *pxmitbuf = (struct xmit_buf *)pmem;
289 struct submit_ctx sctx;
291 rtw_sctx_init(&sctx, timeout_ms);
292 pxmitbuf->sctx = &sctx;
294 ret = _rtw_write_port(adapter, addr, cnt, pmem);
297 ret = rtw_sctx_wait(&sctx);
302 void _rtw_write_port_cancel(struct adapter *adapter)
304 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
305 struct io_priv *pio_priv = &adapter->iopriv;
306 struct intf_hdl *pintfhdl = &(pio_priv->intf);
308 _write_port_cancel = pintfhdl->io_ops._write_port_cancel;
310 if (_write_port_cancel)
311 _write_port_cancel(pintfhdl);
314 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct _io_ops *pops))
316 struct io_priv *piopriv = &padapter->iopriv;
317 struct intf_hdl *pintf = &piopriv->intf;
319 if (set_intf_ops == NULL)
322 piopriv->padapter = padapter;
323 pintf->padapter = padapter;
324 pintf->pintf_dev = adapter_to_dvobj(padapter);
326 set_intf_ops(&pintf->io_ops);