blob: 03250a45272eba7185851d74bc90d6a6863d664d [file] [log] [blame]
Johannes Berg02a7fa02011-04-05 09:42:12 -07001/******************************************************************************
2 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02003 * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
Johannes Berg02a7fa02011-04-05 09:42:12 -07004 *
5 * Portions of this file are derived from the ipw3945 project.
6 *
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.
10 *
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.
15 *
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
19 *
20 * The full GNU General Public License is included in this distribution in the
21 * file called LICENSE.
22 *
23 * Contact Information:
24 * Intel Linux Wireless <ilw@linux.intel.com>
25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *
27 *****************************************************************************/
Emmanuel Grumbach83ed9012011-08-25 23:11:14 -070028#include <linux/delay.h>
29#include <linux/device.h>
Don Frycc5f7e32012-05-16 22:54:27 +020030#include <linux/export.h>
Johannes Berg02a7fa02011-04-05 09:42:12 -070031
Johannes Berg48e29342013-03-01 00:13:33 +010032#include "iwl-drv.h"
Johannes Berg02a7fa02011-04-05 09:42:12 -070033#include "iwl-io.h"
Paul Bolle6ac7d112012-06-06 14:17:46 +020034#include "iwl-csr.h"
Emmanuel Grumbach83ed9012011-08-25 23:11:14 -070035#include "iwl-debug.h"
Liad Kaufman4c9706d2014-04-27 16:46:09 +030036#include "iwl-prph.h"
Inbal Hacohen313b0a22013-06-24 10:35:53 +030037#include "iwl-fh.h"
Johannes Berg02a7fa02011-04-05 09:42:12 -070038
39#define IWL_POLL_INTERVAL 10 /* microseconds */
40
Emmanuel Grumbach1042db22012-01-03 16:56:15 +020041int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
Johannes Berg02a7fa02011-04-05 09:42:12 -070042 u32 bits, u32 mask, int timeout)
43{
44 int t = 0;
45
46 do {
Emmanuel Grumbach1042db22012-01-03 16:56:15 +020047 if ((iwl_read32(trans, addr) & mask) == (bits & mask))
Johannes Berg02a7fa02011-04-05 09:42:12 -070048 return t;
49 udelay(IWL_POLL_INTERVAL);
50 t += IWL_POLL_INTERVAL;
51 } while (t < timeout);
52
53 return -ETIMEDOUT;
54}
Johannes Berg48e29342013-03-01 00:13:33 +010055IWL_EXPORT_SYMBOL(iwl_poll_bit);
Johannes Berg02a7fa02011-04-05 09:42:12 -070056
Emmanuel Grumbach1042db22012-01-03 16:56:15 +020057u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
Johannes Berg02a7fa02011-04-05 09:42:12 -070058{
Emmanuel Grumbachabae2382012-12-31 13:46:42 +020059 u32 value = 0x5a5a5a5a;
Johannes Berg02a7fa02011-04-05 09:42:12 -070060 unsigned long flags;
Lilach Edelsteine56b04e2013-01-16 11:34:49 +020061 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
Emmanuel Grumbachabae2382012-12-31 13:46:42 +020062 value = iwl_read32(trans, reg);
Lilach Edelsteine56b04e2013-01-16 11:34:49 +020063 iwl_trans_release_nic_access(trans, &flags);
Emmanuel Grumbachabae2382012-12-31 13:46:42 +020064 }
Johannes Berg02a7fa02011-04-05 09:42:12 -070065
66 return value;
67}
Johannes Berg48e29342013-03-01 00:13:33 +010068IWL_EXPORT_SYMBOL(iwl_read_direct32);
Johannes Berg02a7fa02011-04-05 09:42:12 -070069
Emmanuel Grumbach1042db22012-01-03 16:56:15 +020070void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
Johannes Berg02a7fa02011-04-05 09:42:12 -070071{
72 unsigned long flags;
73
Lilach Edelsteine56b04e2013-01-16 11:34:49 +020074 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
Emmanuel Grumbach1042db22012-01-03 16:56:15 +020075 iwl_write32(trans, reg, value);
Lilach Edelsteine56b04e2013-01-16 11:34:49 +020076 iwl_trans_release_nic_access(trans, &flags);
Johannes Berg02a7fa02011-04-05 09:42:12 -070077 }
Johannes Berg02a7fa02011-04-05 09:42:12 -070078}
Johannes Berg48e29342013-03-01 00:13:33 +010079IWL_EXPORT_SYMBOL(iwl_write_direct32);
Johannes Berg02a7fa02011-04-05 09:42:12 -070080
Emmanuel Grumbach1042db22012-01-03 16:56:15 +020081int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
Johannes Berg02a7fa02011-04-05 09:42:12 -070082 int timeout)
83{
84 int t = 0;
85
86 do {
Emmanuel Grumbach1042db22012-01-03 16:56:15 +020087 if ((iwl_read_direct32(trans, addr) & mask) == mask)
Johannes Berg02a7fa02011-04-05 09:42:12 -070088 return t;
89 udelay(IWL_POLL_INTERVAL);
90 t += IWL_POLL_INTERVAL;
91 } while (t < timeout);
92
93 return -ETIMEDOUT;
94}
Johannes Berg48e29342013-03-01 00:13:33 +010095IWL_EXPORT_SYMBOL(iwl_poll_direct_bit);
Johannes Berg02a7fa02011-04-05 09:42:12 -070096
Alexander Bondara812cba2014-02-18 16:45:00 +010097u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
Johannes Berg02a7fa02011-04-05 09:42:12 -070098{
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +020099 u32 val = iwl_trans_read_prph(trans, ofs);
100 trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
101 return val;
Johannes Berg02a7fa02011-04-05 09:42:12 -0700102}
103
Alexander Bondara812cba2014-02-18 16:45:00 +0100104void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
Johannes Berg02a7fa02011-04-05 09:42:12 -0700105{
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200106 trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
107 iwl_trans_write_prph(trans, ofs, val);
Johannes Berg02a7fa02011-04-05 09:42:12 -0700108}
109
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200110u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
Johannes Berg02a7fa02011-04-05 09:42:12 -0700111{
112 unsigned long flags;
Emmanuel Grumbachabae2382012-12-31 13:46:42 +0200113 u32 val = 0x5a5a5a5a;
Johannes Berg02a7fa02011-04-05 09:42:12 -0700114
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200115 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
Emmanuel Grumbachabae2382012-12-31 13:46:42 +0200116 val = __iwl_read_prph(trans, ofs);
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200117 iwl_trans_release_nic_access(trans, &flags);
Emmanuel Grumbachabae2382012-12-31 13:46:42 +0200118 }
Johannes Berg02a7fa02011-04-05 09:42:12 -0700119 return val;
120}
Johannes Berg48e29342013-03-01 00:13:33 +0100121IWL_EXPORT_SYMBOL(iwl_read_prph);
Johannes Berg02a7fa02011-04-05 09:42:12 -0700122
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200123void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
Johannes Berg02a7fa02011-04-05 09:42:12 -0700124{
125 unsigned long flags;
126
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200127 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200128 __iwl_write_prph(trans, ofs, val);
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200129 iwl_trans_release_nic_access(trans, &flags);
Johannes Berg02a7fa02011-04-05 09:42:12 -0700130 }
Johannes Berg02a7fa02011-04-05 09:42:12 -0700131}
Johannes Berg48e29342013-03-01 00:13:33 +0100132IWL_EXPORT_SYMBOL(iwl_write_prph);
Johannes Berg02a7fa02011-04-05 09:42:12 -0700133
Eran Harary189fa2f2014-01-23 16:26:32 +0200134int iwl_poll_prph_bit(struct iwl_trans *trans, u32 addr,
135 u32 bits, u32 mask, int timeout)
136{
137 int t = 0;
138
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);
145
146 return -ETIMEDOUT;
147}
148
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200149void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
Johannes Berg02a7fa02011-04-05 09:42:12 -0700150{
151 unsigned long flags;
152
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200153 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200154 __iwl_write_prph(trans, ofs,
155 __iwl_read_prph(trans, ofs) | mask);
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200156 iwl_trans_release_nic_access(trans, &flags);
Stanislaw Gruszkabfe4b802012-03-07 09:52:24 -0800157 }
Johannes Berg02a7fa02011-04-05 09:42:12 -0700158}
Johannes Berg48e29342013-03-01 00:13:33 +0100159IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
Johannes Berg02a7fa02011-04-05 09:42:12 -0700160
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200161void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
Johannes Berg02a7fa02011-04-05 09:42:12 -0700162 u32 bits, u32 mask)
163{
164 unsigned long flags;
165
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200166 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200167 __iwl_write_prph(trans, ofs,
168 (__iwl_read_prph(trans, ofs) & mask) | bits);
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200169 iwl_trans_release_nic_access(trans, &flags);
Stanislaw Gruszkabfe4b802012-03-07 09:52:24 -0800170 }
Johannes Berg02a7fa02011-04-05 09:42:12 -0700171}
Johannes Berg48e29342013-03-01 00:13:33 +0100172IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
Johannes Berg02a7fa02011-04-05 09:42:12 -0700173
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200174void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
Johannes Berg02a7fa02011-04-05 09:42:12 -0700175{
176 unsigned long flags;
177 u32 val;
178
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200179 if (iwl_trans_grab_nic_access(trans, false, &flags)) {
Emmanuel Grumbach6a06b6c2012-12-02 13:07:30 +0200180 val = __iwl_read_prph(trans, ofs);
181 __iwl_write_prph(trans, ofs, (val & ~mask));
Lilach Edelsteine56b04e2013-01-16 11:34:49 +0200182 iwl_trans_release_nic_access(trans, &flags);
Stanislaw Gruszkabfe4b802012-03-07 09:52:24 -0800183 }
Johannes Berg02a7fa02011-04-05 09:42:12 -0700184}
Johannes Berg48e29342013-03-01 00:13:33 +0100185IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);
Inbal Hacohen313b0a22013-06-24 10:35:53 +0300186
Liad Kaufman4c9706d2014-04-27 16:46:09 +0300187void iwl_force_nmi(struct iwl_trans *trans)
188{
189 /*
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.
194 */
195 if ((trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) ||
Emmanuel Grumbach66396582015-01-07 16:44:06 +0200196 (CSR_HW_REV_STEP(trans->hw_rev) == SILICON_A_STEP)) {
197 iwl_write_prph(trans, DEVICE_SET_NMI_REG,
198 DEVICE_SET_NMI_VAL_DRV);
199 iwl_write_prph(trans, DEVICE_SET_NMI_REG,
200 DEVICE_SET_NMI_VAL_HW);
201 } else {
Liad Kaufman4c9706d2014-04-27 16:46:09 +0300202 iwl_write_prph(trans, DEVICE_SET_NMI_8000B_REG,
203 DEVICE_SET_NMI_8000B_VAL);
Emmanuel Grumbach66396582015-01-07 16:44:06 +0200204 }
Liad Kaufman4c9706d2014-04-27 16:46:09 +0300205}
206IWL_EXPORT_SYMBOL(iwl_force_nmi);
207
Inbal Hacohen313b0a22013-06-24 10:35:53 +0300208static const char *get_fh_string(int cmd)
209{
210#define IWL_CMD(x) case x: return #x
211 switch (cmd) {
212 IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
213 IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
214 IWL_CMD(FH_RSCSR_CHNL0_WPTR);
215 IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
216 IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
217 IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
218 IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
219 IWL_CMD(FH_TSSR_TX_STATUS_REG);
220 IWL_CMD(FH_TSSR_TX_ERROR_REG);
221 default:
222 return "UNKNOWN";
223 }
224#undef IWL_CMD
225}
226
227int iwl_dump_fh(struct iwl_trans *trans, char **buf)
228{
229 int i;
230 static const u32 fh_tbl[] = {
231 FH_RSCSR_CHNL0_STTS_WPTR_REG,
232 FH_RSCSR_CHNL0_RBDCB_BASE_REG,
233 FH_RSCSR_CHNL0_WPTR,
234 FH_MEM_RCSR_CHNL0_CONFIG_REG,
235 FH_MEM_RSSR_SHARED_CTRL_REG,
236 FH_MEM_RSSR_RX_STATUS_REG,
237 FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
238 FH_TSSR_TX_STATUS_REG,
239 FH_TSSR_TX_ERROR_REG
240 };
241
242#ifdef CONFIG_IWLWIFI_DEBUGFS
243 if (buf) {
244 int pos = 0;
245 size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
246
247 *buf = kmalloc(bufsz, GFP_KERNEL);
248 if (!*buf)
249 return -ENOMEM;
250
251 pos += scnprintf(*buf + pos, bufsz - pos,
252 "FH register values:\n");
253
254 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
255 pos += scnprintf(*buf + pos, bufsz - pos,
256 " %34s: 0X%08x\n",
257 get_fh_string(fh_tbl[i]),
258 iwl_read_direct32(trans, fh_tbl[i]));
259
260 return pos;
261 }
262#endif
263
264 IWL_ERR(trans, "FH register values:\n");
265 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
266 IWL_ERR(trans, " %34s: 0X%08x\n",
267 get_fh_string(fh_tbl[i]),
268 iwl_read_direct32(trans, fh_tbl[i]));
269
270 return 0;
271}