Merge branch 'work.iov_iter' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[deliverable/linux.git] / drivers / net / wireless / intel / iwlwifi / iwl-io.c
CommitLineData
02a7fa00
JB
1/******************************************************************************
2 *
51368bf7 3 * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
14ef1b43 4 * Copyright(c) 2015 Intel Deutschland GmbH
02a7fa00
JB
5 *
6 * Portions of this file are derived from the ipw3945 project.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
cb2f8277 25 * Intel Linux Wireless <linuxwifi@intel.com>
02a7fa00
JB
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
83ed9015
EG
29#include <linux/delay.h>
30#include <linux/device.h>
cc5f7e39 31#include <linux/export.h>
02a7fa00 32
48e29340 33#include "iwl-drv.h"
02a7fa00 34#include "iwl-io.h"
6ac7d115 35#include "iwl-csr.h"
83ed9015 36#include "iwl-debug.h"
4c9706dc 37#include "iwl-prph.h"
313b0a29 38#include "iwl-fh.h"
02a7fa00 39
a73a2cea
EG
40void iwl_write8(struct iwl_trans *trans, u32 ofs, u8 val)
41{
42 trace_iwlwifi_dev_iowrite8(trans->dev, ofs, val);
43 iwl_trans_write8(trans, ofs, val);
44}
45IWL_EXPORT_SYMBOL(iwl_write8);
46
47void iwl_write32(struct iwl_trans *trans, u32 ofs, u32 val)
48{
49 trace_iwlwifi_dev_iowrite32(trans->dev, ofs, val);
50 iwl_trans_write32(trans, ofs, val);
51}
52IWL_EXPORT_SYMBOL(iwl_write32);
53
54u32 iwl_read32(struct iwl_trans *trans, u32 ofs)
55{
56 u32 val = iwl_trans_read32(trans, ofs);
89ced540 57
a73a2cea
EG
58 trace_iwlwifi_dev_ioread32(trans->dev, ofs, val);
59 return val;
60}
61IWL_EXPORT_SYMBOL(iwl_read32);
62
02a7fa00
JB
63#define IWL_POLL_INTERVAL 10 /* microseconds */
64
1042db2a 65int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
02a7fa00
JB
66 u32 bits, u32 mask, int timeout)
67{
68 int t = 0;
69
70 do {
1042db2a 71 if ((iwl_read32(trans, addr) & mask) == (bits & mask))
02a7fa00
JB
72 return t;
73 udelay(IWL_POLL_INTERVAL);
74 t += IWL_POLL_INTERVAL;
75 } while (t < timeout);
76
77 return -ETIMEDOUT;
78}
48e29340 79IWL_EXPORT_SYMBOL(iwl_poll_bit);
02a7fa00 80
1042db2a 81u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
02a7fa00 82{
abae2386 83 u32 value = 0x5a5a5a5a;
02a7fa00 84 unsigned long flags;
23ba9340 85 if (iwl_trans_grab_nic_access(trans, &flags)) {
abae2386 86 value = iwl_read32(trans, reg);
e56b04ef 87 iwl_trans_release_nic_access(trans, &flags);
abae2386 88 }
02a7fa00
JB
89
90 return value;
91}
48e29340 92IWL_EXPORT_SYMBOL(iwl_read_direct32);
02a7fa00 93
1042db2a 94void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
02a7fa00
JB
95{
96 unsigned long flags;
97
23ba9340 98 if (iwl_trans_grab_nic_access(trans, &flags)) {
1042db2a 99 iwl_write32(trans, reg, value);
e56b04ef 100 iwl_trans_release_nic_access(trans, &flags);
02a7fa00 101 }
02a7fa00 102}
48e29340 103IWL_EXPORT_SYMBOL(iwl_write_direct32);
02a7fa00 104
1042db2a 105int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
02a7fa00
JB
106 int timeout)
107{
108 int t = 0;
109
110 do {
1042db2a 111 if ((iwl_read_direct32(trans, addr) & mask) == mask)
02a7fa00
JB
112 return t;
113 udelay(IWL_POLL_INTERVAL);
114 t += IWL_POLL_INTERVAL;
115 } while (t < timeout);
116
117 return -ETIMEDOUT;
118}
48e29340 119IWL_EXPORT_SYMBOL(iwl_poll_direct_bit);
02a7fa00 120
14ef1b43 121u32 iwl_read_prph_no_grab(struct iwl_trans *trans, u32 ofs)
02a7fa00 122{
6a06b6c1
EG
123 u32 val = iwl_trans_read_prph(trans, ofs);
124 trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
125 return val;
02a7fa00 126}
14ef1b43 127IWL_EXPORT_SYMBOL(iwl_read_prph_no_grab);
02a7fa00 128
14ef1b43 129void iwl_write_prph_no_grab(struct iwl_trans *trans, u32 ofs, u32 val)
02a7fa00 130{
6a06b6c1
EG
131 trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
132 iwl_trans_write_prph(trans, ofs, val);
02a7fa00 133}
14ef1b43 134IWL_EXPORT_SYMBOL(iwl_write_prph_no_grab);
02a7fa00 135
6a06b6c1 136u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
02a7fa00
JB
137{
138 unsigned long flags;
abae2386 139 u32 val = 0x5a5a5a5a;
02a7fa00 140
23ba9340 141 if (iwl_trans_grab_nic_access(trans, &flags)) {
14ef1b43 142 val = iwl_read_prph_no_grab(trans, ofs);
e56b04ef 143 iwl_trans_release_nic_access(trans, &flags);
abae2386 144 }
02a7fa00
JB
145 return val;
146}
48e29340 147IWL_EXPORT_SYMBOL(iwl_read_prph);
02a7fa00 148
6a06b6c1 149void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
02a7fa00
JB
150{
151 unsigned long flags;
152
23ba9340 153 if (iwl_trans_grab_nic_access(trans, &flags)) {
14ef1b43 154 iwl_write_prph_no_grab(trans, ofs, val);
e56b04ef 155 iwl_trans_release_nic_access(trans, &flags);
02a7fa00 156 }
02a7fa00 157}
48e29340 158IWL_EXPORT_SYMBOL(iwl_write_prph);
02a7fa00 159
189fa2fa
EH
160int iwl_poll_prph_bit(struct iwl_trans *trans, u32 addr,
161 u32 bits, u32 mask, int timeout)
162{
163 int t = 0;
164
165 do {
166 if ((iwl_read_prph(trans, addr) & mask) == (bits & mask))
167 return t;
168 udelay(IWL_POLL_INTERVAL);
169 t += IWL_POLL_INTERVAL;
170 } while (t < timeout);
171
172 return -ETIMEDOUT;
173}
174
6a06b6c1 175void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
02a7fa00
JB
176{
177 unsigned long flags;
178
23ba9340 179 if (iwl_trans_grab_nic_access(trans, &flags)) {
14ef1b43
GBA
180 iwl_write_prph_no_grab(trans, ofs,
181 iwl_read_prph_no_grab(trans, ofs) |
182 mask);
e56b04ef 183 iwl_trans_release_nic_access(trans, &flags);
bfe4b80e 184 }
02a7fa00 185}
48e29340 186IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
02a7fa00 187
6a06b6c1 188void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
02a7fa00
JB
189 u32 bits, u32 mask)
190{
191 unsigned long flags;
192
23ba9340 193 if (iwl_trans_grab_nic_access(trans, &flags)) {
14ef1b43
GBA
194 iwl_write_prph_no_grab(trans, ofs,
195 (iwl_read_prph_no_grab(trans, ofs) &
196 mask) | bits);
e56b04ef 197 iwl_trans_release_nic_access(trans, &flags);
bfe4b80e 198 }
02a7fa00 199}
48e29340 200IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
02a7fa00 201
6a06b6c1 202void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
02a7fa00
JB
203{
204 unsigned long flags;
205 u32 val;
206
23ba9340 207 if (iwl_trans_grab_nic_access(trans, &flags)) {
14ef1b43
GBA
208 val = iwl_read_prph_no_grab(trans, ofs);
209 iwl_write_prph_no_grab(trans, ofs, (val & ~mask));
e56b04ef 210 iwl_trans_release_nic_access(trans, &flags);
bfe4b80e 211 }
02a7fa00 212}
48e29340 213IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);
313b0a29 214
4c9706dc
LK
215void iwl_force_nmi(struct iwl_trans *trans)
216{
5dd9c68a 217 if (trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
66396583
EG
218 iwl_write_prph(trans, DEVICE_SET_NMI_REG,
219 DEVICE_SET_NMI_VAL_DRV);
220 iwl_write_prph(trans, DEVICE_SET_NMI_REG,
221 DEVICE_SET_NMI_VAL_HW);
222 } else {
5dd9c68a
EG
223 iwl_write_prph(trans, DEVICE_SET_NMI_8000_REG,
224 DEVICE_SET_NMI_8000_VAL);
9b666db4
EG
225 iwl_write_prph(trans, DEVICE_SET_NMI_REG,
226 DEVICE_SET_NMI_VAL_DRV);
66396583 227 }
4c9706dc
LK
228}
229IWL_EXPORT_SYMBOL(iwl_force_nmi);
230
313b0a29
IH
231static const char *get_fh_string(int cmd)
232{
233#define IWL_CMD(x) case x: return #x
234 switch (cmd) {
235 IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
236 IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
237 IWL_CMD(FH_RSCSR_CHNL0_WPTR);
238 IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
239 IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
240 IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
241 IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
242 IWL_CMD(FH_TSSR_TX_STATUS_REG);
243 IWL_CMD(FH_TSSR_TX_ERROR_REG);
244 default:
245 return "UNKNOWN";
246 }
247#undef IWL_CMD
248}
249
250int iwl_dump_fh(struct iwl_trans *trans, char **buf)
251{
252 int i;
253 static const u32 fh_tbl[] = {
254 FH_RSCSR_CHNL0_STTS_WPTR_REG,
255 FH_RSCSR_CHNL0_RBDCB_BASE_REG,
256 FH_RSCSR_CHNL0_WPTR,
257 FH_MEM_RCSR_CHNL0_CONFIG_REG,
258 FH_MEM_RSSR_SHARED_CTRL_REG,
259 FH_MEM_RSSR_RX_STATUS_REG,
260 FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
261 FH_TSSR_TX_STATUS_REG,
262 FH_TSSR_TX_ERROR_REG
263 };
264
265#ifdef CONFIG_IWLWIFI_DEBUGFS
266 if (buf) {
267 int pos = 0;
268 size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
269
270 *buf = kmalloc(bufsz, GFP_KERNEL);
271 if (!*buf)
272 return -ENOMEM;
273
274 pos += scnprintf(*buf + pos, bufsz - pos,
275 "FH register values:\n");
276
277 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
278 pos += scnprintf(*buf + pos, bufsz - pos,
279 " %34s: 0X%08x\n",
280 get_fh_string(fh_tbl[i]),
281 iwl_read_direct32(trans, fh_tbl[i]));
282
283 return pos;
284 }
285#endif
286
287 IWL_ERR(trans, "FH register values:\n");
288 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
289 IWL_ERR(trans, " %34s: 0X%08x\n",
290 get_fh_string(fh_tbl[i]),
291 iwl_read_direct32(trans, fh_tbl[i]));
292
293 return 0;
294}
This page took 0.452651 seconds and 5 git commands to generate.