mm/zsmalloc: allocate exactly size of struct zs_pool
[linux/fpc-iii.git] / drivers / net / wireless / iwlwifi / iwl-io.c
blob7a2cbf6f90dbf39185c4a2e0ff52eddfb1b9d951
1 /******************************************************************************
3 * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 * The full GNU General Public License is included in this distribution in the
21 * file called LICENSE.
23 * Contact Information:
24 * Intel Linux Wireless <ilw@linux.intel.com>
25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28 #include <linux/delay.h>
29 #include <linux/device.h>
30 #include <linux/export.h>
32 #include "iwl-drv.h"
33 #include "iwl-io.h"
34 #include "iwl-csr.h"
35 #include "iwl-debug.h"
36 #include "iwl-prph.h"
37 #include "iwl-fh.h"
39 #define IWL_POLL_INTERVAL 10 /* microseconds */
41 int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
42 u32 bits, u32 mask, int timeout)
44 int t = 0;
46 do {
47 if ((iwl_read32(trans, addr) & mask) == (bits & mask))
48 return t;
49 udelay(IWL_POLL_INTERVAL);
50 t += IWL_POLL_INTERVAL;
51 } while (t < timeout);
53 return -ETIMEDOUT;
55 IWL_EXPORT_SYMBOL(iwl_poll_bit);
57 u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
59 u32 value = 0x5a5a5a5a;
60 unsigned long flags;
61 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
62 value = iwl_read32(trans, reg);
63 iwl_trans_release_nic_access(trans, &flags);
66 return value;
68 IWL_EXPORT_SYMBOL(iwl_read_direct32);
70 void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
72 unsigned long flags;
74 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
75 iwl_write32(trans, reg, value);
76 iwl_trans_release_nic_access(trans, &flags);
79 IWL_EXPORT_SYMBOL(iwl_write_direct32);
81 int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
82 int timeout)
84 int t = 0;
86 do {
87 if ((iwl_read_direct32(trans, addr) & mask) == mask)
88 return t;
89 udelay(IWL_POLL_INTERVAL);
90 t += IWL_POLL_INTERVAL;
91 } while (t < timeout);
93 return -ETIMEDOUT;
95 IWL_EXPORT_SYMBOL(iwl_poll_direct_bit);
97 u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
99 u32 val = iwl_trans_read_prph(trans, ofs);
100 trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
101 return val;
104 void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
106 trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
107 iwl_trans_write_prph(trans, ofs, val);
110 u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
112 unsigned long flags;
113 u32 val = 0x5a5a5a5a;
115 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
116 val = __iwl_read_prph(trans, ofs);
117 iwl_trans_release_nic_access(trans, &flags);
119 return val;
121 IWL_EXPORT_SYMBOL(iwl_read_prph);
123 void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
125 unsigned long flags;
127 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
128 __iwl_write_prph(trans, ofs, val);
129 iwl_trans_release_nic_access(trans, &flags);
132 IWL_EXPORT_SYMBOL(iwl_write_prph);
134 int iwl_poll_prph_bit(struct iwl_trans *trans, u32 addr,
135 u32 bits, u32 mask, int timeout)
137 int t = 0;
139 do {
140 if ((iwl_read_prph(trans, addr) & mask) == (bits & mask))
141 return t;
142 udelay(IWL_POLL_INTERVAL);
143 t += IWL_POLL_INTERVAL;
144 } while (t < timeout);
146 return -ETIMEDOUT;
149 void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
151 unsigned long flags;
153 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
154 __iwl_write_prph(trans, ofs,
155 __iwl_read_prph(trans, ofs) | mask);
156 iwl_trans_release_nic_access(trans, &flags);
159 IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
161 void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
162 u32 bits, u32 mask)
164 unsigned long flags;
166 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
167 __iwl_write_prph(trans, ofs,
168 (__iwl_read_prph(trans, ofs) & mask) | bits);
169 iwl_trans_release_nic_access(trans, &flags);
172 IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
174 void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
176 unsigned long flags;
177 u32 val;
179 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
180 val = __iwl_read_prph(trans, ofs);
181 __iwl_write_prph(trans, ofs, (val & ~mask));
182 iwl_trans_release_nic_access(trans, &flags);
185 IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);
187 void iwl_force_nmi(struct iwl_trans *trans)
190 * In HW previous to the 8000 HW family, and in the 8000 HW family
191 * itself when the revision step==0, the DEVICE_SET_NMI_REG is used
192 * to force an NMI. Otherwise, a different register -
193 * DEVICE_SET_NMI_8000B_REG - is used.
195 if ((trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) ||
196 (CSR_HW_REV_STEP(trans->hw_rev) == SILICON_A_STEP))
197 iwl_write_prph(trans, DEVICE_SET_NMI_REG, DEVICE_SET_NMI_VAL);
198 else
199 iwl_write_prph(trans, DEVICE_SET_NMI_8000B_REG,
200 DEVICE_SET_NMI_8000B_VAL);
202 IWL_EXPORT_SYMBOL(iwl_force_nmi);
204 static const char *get_fh_string(int cmd)
206 #define IWL_CMD(x) case x: return #x
207 switch (cmd) {
208 IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
209 IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
210 IWL_CMD(FH_RSCSR_CHNL0_WPTR);
211 IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
212 IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
213 IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
214 IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
215 IWL_CMD(FH_TSSR_TX_STATUS_REG);
216 IWL_CMD(FH_TSSR_TX_ERROR_REG);
217 default:
218 return "UNKNOWN";
220 #undef IWL_CMD
223 int iwl_dump_fh(struct iwl_trans *trans, char **buf)
225 int i;
226 static const u32 fh_tbl[] = {
227 FH_RSCSR_CHNL0_STTS_WPTR_REG,
228 FH_RSCSR_CHNL0_RBDCB_BASE_REG,
229 FH_RSCSR_CHNL0_WPTR,
230 FH_MEM_RCSR_CHNL0_CONFIG_REG,
231 FH_MEM_RSSR_SHARED_CTRL_REG,
232 FH_MEM_RSSR_RX_STATUS_REG,
233 FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
234 FH_TSSR_TX_STATUS_REG,
235 FH_TSSR_TX_ERROR_REG
238 #ifdef CONFIG_IWLWIFI_DEBUGFS
239 if (buf) {
240 int pos = 0;
241 size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
243 *buf = kmalloc(bufsz, GFP_KERNEL);
244 if (!*buf)
245 return -ENOMEM;
247 pos += scnprintf(*buf + pos, bufsz - pos,
248 "FH register values:\n");
250 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
251 pos += scnprintf(*buf + pos, bufsz - pos,
252 " %34s: 0X%08x\n",
253 get_fh_string(fh_tbl[i]),
254 iwl_read_direct32(trans, fh_tbl[i]));
256 return pos;
258 #endif
260 IWL_ERR(trans, "FH register values:\n");
261 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
262 IWL_ERR(trans, " %34s: 0X%08x\n",
263 get_fh_string(fh_tbl[i]),
264 iwl_read_direct32(trans, fh_tbl[i]));
266 return 0;