wlcore, wl1251: fix spelling: "Couldnt" -> "Couldn't" and remove error on -ENOMEM
[linux-2.6/btrfs-unstable.git] / drivers / staging / rtl8723bs / core / rtw_io.c
blob6bd5a4741e79826890cfa5a3bd55512e6b3f36af
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
12 * more details.
14 ******************************************************************************/
17 The purpose of rtw_io.c
19 a. provides the API
21 b. provides the protocol engine
23 c. provides the software interface between caller and the hardware interface
26 Compiler Flag Option:
28 1. CONFIG_SDIO_HCI:
29 a. USE_SYNC_IRP: Only sync operations are provided.
30 b. USE_ASYNC_IRP:Both sync/async operations are provided.
32 jackson@realtek.com.tw
36 #define _RTW_IO_C_
38 #include <drv_types.h>
39 #include <rtw_debug.h>
41 #define rtw_le16_to_cpu(val) val
42 #define rtw_le32_to_cpu(val) val
43 #define rtw_cpu_to_le16(val) val
44 #define rtw_cpu_to_le32(val) val
46 u8 _rtw_read8(struct adapter *adapter, u32 addr)
48 u8 r_val;
49 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
50 struct io_priv *pio_priv = &adapter->iopriv;
51 struct intf_hdl *pintfhdl = &(pio_priv->intf);
52 u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
54 _read8 = pintfhdl->io_ops._read8;
56 r_val = _read8(pintfhdl, addr);
57 return r_val;
60 u16 _rtw_read16(struct adapter *adapter, u32 addr)
62 u16 r_val;
63 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
64 struct io_priv *pio_priv = &adapter->iopriv;
65 struct intf_hdl *pintfhdl = &(pio_priv->intf);
66 u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
68 _read16 = pintfhdl->io_ops._read16;
70 r_val = _read16(pintfhdl, addr);
71 return rtw_le16_to_cpu(r_val);
74 u32 _rtw_read32(struct adapter *adapter, u32 addr)
76 u32 r_val;
77 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
78 struct io_priv *pio_priv = &adapter->iopriv;
79 struct intf_hdl *pintfhdl = &(pio_priv->intf);
80 u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
82 _read32 = pintfhdl->io_ops._read32;
84 r_val = _read32(pintfhdl, addr);
85 return rtw_le32_to_cpu(r_val);
89 int _rtw_write8(struct adapter *adapter, u32 addr, u8 val)
91 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
92 struct io_priv *pio_priv = &adapter->iopriv;
93 struct intf_hdl *pintfhdl = &(pio_priv->intf);
94 int (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
95 int ret;
97 _write8 = pintfhdl->io_ops._write8;
99 ret = _write8(pintfhdl, addr, val);
101 return RTW_STATUS_CODE(ret);
103 int _rtw_write16(struct adapter *adapter, u32 addr, u16 val)
105 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
106 struct io_priv *pio_priv = &adapter->iopriv;
107 struct intf_hdl *pintfhdl = &(pio_priv->intf);
108 int (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
109 int ret;
111 _write16 = pintfhdl->io_ops._write16;
113 ret = _write16(pintfhdl, addr, val);
114 return RTW_STATUS_CODE(ret);
116 int _rtw_write32(struct adapter *adapter, u32 addr, u32 val)
118 /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */
119 struct io_priv *pio_priv = &adapter->iopriv;
120 struct intf_hdl *pintfhdl = &(pio_priv->intf);
121 int (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
122 int ret;
124 _write32 = pintfhdl->io_ops._write32;
126 ret = _write32(pintfhdl, addr, val);
128 return RTW_STATUS_CODE(ret);
131 u8 _rtw_sd_f0_read8(struct adapter *adapter, u32 addr)
133 u8 r_val = 0x00;
134 struct io_priv *pio_priv = &adapter->iopriv;
135 struct intf_hdl *pintfhdl = &(pio_priv->intf);
136 u8 (*_sd_f0_read8)(struct intf_hdl *pintfhdl, u32 addr);
138 _sd_f0_read8 = pintfhdl->io_ops._sd_f0_read8;
140 if (_sd_f0_read8)
141 r_val = _sd_f0_read8(pintfhdl, addr);
142 else
143 DBG_871X_LEVEL(_drv_warning_, FUNC_ADPT_FMT" _sd_f0_read8 callback is NULL\n", FUNC_ADPT_ARG(adapter));
145 return r_val;
148 u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
150 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem);
151 struct io_priv *pio_priv = &adapter->iopriv;
152 struct intf_hdl *pintfhdl = &(pio_priv->intf);
153 u32 ret = _SUCCESS;
155 _write_port = pintfhdl->io_ops._write_port;
157 ret = _write_port(pintfhdl, addr, cnt, pmem);
159 return ret;
162 int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops))
164 struct io_priv *piopriv = &padapter->iopriv;
165 struct intf_hdl *pintf = &piopriv->intf;
167 if (set_intf_ops == NULL)
168 return _FAIL;
170 piopriv->padapter = padapter;
171 pintf->padapter = padapter;
172 pintf->pintf_dev = adapter_to_dvobj(padapter);
174 set_intf_ops(padapter, &pintf->io_ops);
176 return _SUCCESS;
180 * Increase and check if the continual_io_error of this @param dvobjprive is larger than MAX_CONTINUAL_IO_ERR
181 * @return true:
182 * @return false:
184 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj)
186 int ret = false;
187 int value = atomic_inc_return(&dvobj->continual_io_error);
188 if (value > MAX_CONTINUAL_IO_ERR) {
189 DBG_871X("[dvobj:%p][ERROR] continual_io_error:%d > %d\n", dvobj, value, MAX_CONTINUAL_IO_ERR);
190 ret = true;
191 } else {
192 /* DBG_871X("[dvobj:%p] continual_io_error:%d\n", dvobj, value); */
194 return ret;
198 * Set the continual_io_error of this @param dvobjprive to 0
200 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj)
202 atomic_set(&dvobj->continual_io_error, 0);