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_SYNC_IRP: Only sync operations are provided.
35 b. USE_ASYNC_IRP:Both sync/async operations are provided.
37 jackson@realtek.com.tw
43 #include <drv_types.h>
45 #define rtw_le16_to_cpu(val) val
46 #define rtw_le32_to_cpu(val) val
47 #define rtw_cpu_to_le16(val) val
48 #define rtw_cpu_to_le32(val) val
50 u8 _rtw_read8(_adapter *adapter, u32 addr)
53 //struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
54 struct io_priv *pio_priv = &adapter->iopriv;
55 struct intf_hdl *pintfhdl = &(pio_priv->intf);
56 u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
58 _read8 = pintfhdl->io_ops._read8;
60 r_val = _read8(pintfhdl, addr);
65 u16 _rtw_read16(_adapter *adapter, u32 addr)
68 //struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
69 struct io_priv *pio_priv = &adapter->iopriv;
70 struct intf_hdl *pintfhdl = &(pio_priv->intf);
71 u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
73 _read16 = pintfhdl->io_ops._read16;
75 r_val = _read16(pintfhdl, addr);
77 return rtw_le16_to_cpu(r_val);
80 u32 _rtw_read32(_adapter *adapter, u32 addr)
83 //struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
84 struct io_priv *pio_priv = &adapter->iopriv;
85 struct intf_hdl *pintfhdl = &(pio_priv->intf);
86 u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
88 _read32 = pintfhdl->io_ops._read32;
90 r_val = _read32(pintfhdl, addr);
92 return rtw_le32_to_cpu(r_val);
96 int _rtw_write8(_adapter *adapter, u32 addr, u8 val)
98 //struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
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);
111 int _rtw_write16(_adapter *adapter, u32 addr, u16 val)
113 //struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
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 val = rtw_cpu_to_le16(val);
122 ret = _write16(pintfhdl, addr, val);
125 return RTW_STATUS_CODE(ret);
127 int _rtw_write32(_adapter *adapter, u32 addr, u32 val)
129 //struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
130 struct io_priv *pio_priv = &adapter->iopriv;
131 struct intf_hdl *pintfhdl = &(pio_priv->intf);
132 int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
135 _write32 = pintfhdl->io_ops._write32;
137 val = rtw_cpu_to_le32(val);
138 ret = _write32(pintfhdl, addr, val);
141 return RTW_STATUS_CODE(ret);
144 u8 _rtw_sd_f0_read8(_adapter *adapter, u32 addr)
147 struct io_priv *pio_priv = &adapter->iopriv;
148 struct intf_hdl *pintfhdl = &(pio_priv->intf);
149 u8 (*_sd_f0_read8)(struct intf_hdl *pintfhdl, u32 addr);
152 _sd_f0_read8 = pintfhdl->io_ops._sd_f0_read8;
155 r_val = _sd_f0_read8(pintfhdl, addr);
157 DBG_871X_LEVEL(_drv_warning_, FUNC_ADPT_FMT" _sd_f0_read8 callback is NULL\n", FUNC_ADPT_ARG(adapter));
163 u32 _rtw_write_port(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
165 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
166 //struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
167 struct io_priv *pio_priv = &adapter->iopriv;
168 struct intf_hdl *pintfhdl = &(pio_priv->intf);
173 _write_port = pintfhdl->io_ops._write_port;
175 ret = _write_port(pintfhdl, addr, cnt, pmem);
182 int rtw_init_io_priv(_adapter *padapter, void (*set_intf_ops)(_adapter *padapter,struct _io_ops *pops))
184 struct io_priv *piopriv = &padapter->iopriv;
185 struct intf_hdl *pintf = &piopriv->intf;
187 if (set_intf_ops == NULL)
190 piopriv->padapter = padapter;
191 pintf->padapter = padapter;
192 pintf->pintf_dev = adapter_to_dvobj(padapter);
194 set_intf_ops(padapter,&pintf->io_ops);
200 * Increase and check if the continual_io_error of this @param dvobjprive is larger than MAX_CONTINUAL_IO_ERR
204 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj)
208 if( (value=atomic_inc_return(&dvobj->continual_io_error)) > MAX_CONTINUAL_IO_ERR) {
209 DBG_871X("[dvobj:%p][ERROR] continual_io_error:%d > %d\n", dvobj, value, MAX_CONTINUAL_IO_ERR);
212 //DBG_871X("[dvobj:%p] continual_io_error:%d\n", dvobj, value);
218 * Set the continual_io_error of this @param dvobjprive to 0
220 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj)
222 atomic_set(&dvobj->continual_io_error, 0);