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
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>
35 #include "iwl-debug.h"
38 #define IWL_POLL_INTERVAL 10 /* microseconds */
40 int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
41 u32 bits, u32 mask, int timeout)
46 if ((iwl_read32(trans, addr) & mask) == (bits & mask))
48 udelay(IWL_POLL_INTERVAL);
49 t += IWL_POLL_INTERVAL;
50 } while (t < timeout);
54 IWL_EXPORT_SYMBOL(iwl_poll_bit);
56 u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
58 u32 value = 0x5a5a5a5a;
60 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
61 value = iwl_read32(trans, reg);
62 iwl_trans_release_nic_access(trans, &flags);
67 IWL_EXPORT_SYMBOL(iwl_read_direct32);
69 void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
73 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
74 iwl_write32(trans, reg, value);
75 iwl_trans_release_nic_access(trans, &flags);
78 IWL_EXPORT_SYMBOL(iwl_write_direct32);
80 int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
86 if ((iwl_read_direct32(trans, addr) & mask) == mask)
88 udelay(IWL_POLL_INTERVAL);
89 t += IWL_POLL_INTERVAL;
90 } while (t < timeout);
94 IWL_EXPORT_SYMBOL(iwl_poll_direct_bit);
96 u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
98 u32 val = iwl_trans_read_prph(trans, ofs);
99 trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
103 void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
105 trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
106 iwl_trans_write_prph(trans, ofs, val);
109 u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
112 u32 val = 0x5a5a5a5a;
114 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
115 val = __iwl_read_prph(trans, ofs);
116 iwl_trans_release_nic_access(trans, &flags);
120 IWL_EXPORT_SYMBOL(iwl_read_prph);
122 void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
126 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
127 __iwl_write_prph(trans, ofs, val);
128 iwl_trans_release_nic_access(trans, &flags);
131 IWL_EXPORT_SYMBOL(iwl_write_prph);
133 int iwl_poll_prph_bit(struct iwl_trans *trans, u32 addr,
134 u32 bits, u32 mask, int timeout)
139 if ((iwl_read_prph(trans, addr) & mask) == (bits & mask))
141 udelay(IWL_POLL_INTERVAL);
142 t += IWL_POLL_INTERVAL;
143 } while (t < timeout);
148 void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
152 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
153 __iwl_write_prph(trans, ofs,
154 __iwl_read_prph(trans, ofs) | mask);
155 iwl_trans_release_nic_access(trans, &flags);
158 IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
160 void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
165 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
166 __iwl_write_prph(trans, ofs,
167 (__iwl_read_prph(trans, ofs) & mask) | bits);
168 iwl_trans_release_nic_access(trans, &flags);
171 IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
173 void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
178 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
179 val = __iwl_read_prph(trans, ofs);
180 __iwl_write_prph(trans, ofs, (val & ~mask));
181 iwl_trans_release_nic_access(trans, &flags);
184 IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);
186 static const char *get_fh_string(int cmd)
188 #define IWL_CMD(x) case x: return #x
190 IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
191 IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
192 IWL_CMD(FH_RSCSR_CHNL0_WPTR);
193 IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
194 IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
195 IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
196 IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
197 IWL_CMD(FH_TSSR_TX_STATUS_REG);
198 IWL_CMD(FH_TSSR_TX_ERROR_REG);
205 int iwl_dump_fh(struct iwl_trans *trans, char **buf)
208 static const u32 fh_tbl[] = {
209 FH_RSCSR_CHNL0_STTS_WPTR_REG,
210 FH_RSCSR_CHNL0_RBDCB_BASE_REG,
212 FH_MEM_RCSR_CHNL0_CONFIG_REG,
213 FH_MEM_RSSR_SHARED_CTRL_REG,
214 FH_MEM_RSSR_RX_STATUS_REG,
215 FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
216 FH_TSSR_TX_STATUS_REG,
220 #ifdef CONFIG_IWLWIFI_DEBUGFS
223 size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
225 *buf = kmalloc(bufsz, GFP_KERNEL);
229 pos += scnprintf(*buf + pos, bufsz - pos,
230 "FH register values:\n");
232 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
233 pos += scnprintf(*buf + pos, bufsz - pos,
235 get_fh_string(fh_tbl[i]),
236 iwl_read_direct32(trans, fh_tbl[i]));
242 IWL_ERR(trans, "FH register values:\n");
243 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
244 IWL_ERR(trans, " %34s: 0X%08x\n",
245 get_fh_string(fh_tbl[i]),
246 iwl_read_direct32(trans, fh_tbl[i]));