OSDN Git Service

18db67160a488ae3a25a9cc9108d1d9b2a4b68de
[android-x86/kernel.git] / drivers / staging / rtl8723bs / 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  * 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
17  *
18  *
19  ******************************************************************************/
20 /*
21
22 The purpose of rtw_io.c
23
24 a. provides the API
25
26 b. provides the protocol engine
27
28 c. provides the software interface between caller and the hardware interface
29
30
31 Compiler Flag Option:
32
33 1. CONFIG_SDIO_HCI:
34     a. USE_SYNC_IRP:  Only sync operations are provided.
35     b. USE_ASYNC_IRP:Both sync/async operations are provided.
36
37 jackson@realtek.com.tw
38
39 */
40
41 #define _RTW_IO_C_
42
43 #include <drv_types.h>
44
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
49
50 u8 _rtw_read8(_adapter *adapter, u32 addr)
51 {
52         u8 r_val;
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);
57         _func_enter_;
58         _read8 = pintfhdl->io_ops._read8;
59
60         r_val = _read8(pintfhdl, addr);
61         _func_exit_;
62         return r_val;
63 }
64
65 u16 _rtw_read16(_adapter *adapter, u32 addr)
66 {
67         u16 r_val;
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);
72         _func_enter_;
73         _read16 = pintfhdl->io_ops._read16;
74
75         r_val = _read16(pintfhdl, addr);
76         _func_exit_;
77         return rtw_le16_to_cpu(r_val);
78 }
79
80 u32 _rtw_read32(_adapter *adapter, u32 addr)
81 {
82         u32 r_val;
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);
87         _func_enter_;
88         _read32 = pintfhdl->io_ops._read32;
89
90         r_val = _read32(pintfhdl, addr);
91         _func_exit_;
92         return rtw_le32_to_cpu(r_val);
93
94 }
95
96 int _rtw_write8(_adapter *adapter, u32 addr, u8 val)
97 {
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);
102         int ret;
103         _func_enter_;
104         _write8 = pintfhdl->io_ops._write8;
105
106         ret = _write8(pintfhdl, addr, val);
107         _func_exit_;
108
109         return RTW_STATUS_CODE(ret);
110 }
111 int _rtw_write16(_adapter *adapter, u32 addr, u16 val)
112 {
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);
117         int ret;
118         _func_enter_;
119         _write16 = pintfhdl->io_ops._write16;
120
121         val = rtw_cpu_to_le16(val);
122         ret = _write16(pintfhdl, addr, val);
123         _func_exit_;
124
125         return RTW_STATUS_CODE(ret);
126 }
127 int _rtw_write32(_adapter *adapter, u32 addr, u32 val)
128 {
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);
133         int ret;
134         _func_enter_;
135         _write32 = pintfhdl->io_ops._write32;
136
137         val = rtw_cpu_to_le32(val);
138         ret = _write32(pintfhdl, addr, val);
139         _func_exit_;
140
141         return RTW_STATUS_CODE(ret);
142 }
143
144 u8 _rtw_sd_f0_read8(_adapter *adapter, u32 addr)
145 {
146         u8 r_val = 0x00;
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);
150
151         _func_enter_;
152         _sd_f0_read8 = pintfhdl->io_ops._sd_f0_read8;
153
154         if (_sd_f0_read8)
155                 r_val = _sd_f0_read8(pintfhdl, addr);
156         else
157                 DBG_871X_LEVEL(_drv_warning_, FUNC_ADPT_FMT" _sd_f0_read8 callback is NULL\n", FUNC_ADPT_ARG(adapter));
158
159         _func_exit_;
160         return r_val;
161 }
162
163 u32 _rtw_write_port(_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
164 {
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);
169         u32 ret = _SUCCESS;
170
171         _func_enter_;
172
173         _write_port = pintfhdl->io_ops._write_port;
174
175         ret = _write_port(pintfhdl, addr, cnt, pmem);
176
177          _func_exit_;
178
179         return ret;
180 }
181
182 int rtw_init_io_priv(_adapter *padapter, void (*set_intf_ops)(_adapter *padapter,struct _io_ops *pops))
183 {
184         struct io_priv  *piopriv = &padapter->iopriv;
185         struct intf_hdl *pintf = &piopriv->intf;
186
187         if (set_intf_ops == NULL)
188                 return _FAIL;
189
190         piopriv->padapter = padapter;
191         pintf->padapter = padapter;
192         pintf->pintf_dev = adapter_to_dvobj(padapter);
193
194         set_intf_ops(padapter,&pintf->io_ops);
195
196         return _SUCCESS;
197 }
198
199 /*
200 * Increase and check if the continual_io_error of this @param dvobjprive is larger than MAX_CONTINUAL_IO_ERR
201 * @return true:
202 * @return false:
203 */
204 int rtw_inc_and_chk_continual_io_error(struct dvobj_priv *dvobj)
205 {
206         int ret = false;
207         int value;
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);
210                 ret = true;
211         } else {
212                 //DBG_871X("[dvobj:%p] continual_io_error:%d\n", dvobj, value);
213         }
214         return ret;
215 }
216
217 /*
218 * Set the continual_io_error of this @param dvobjprive to 0
219 */
220 void rtw_reset_continual_io_error(struct dvobj_priv *dvobj)
221 {
222         atomic_set(&dvobj->continual_io_error, 0);
223 }