1 /******************************************************************************
3 * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
4 * Copyright(c) 2015 Intel Deutschland GmbH
6 * Portions of this file are derived from the ipw3945 project.
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.
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
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
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <linuxwifi@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
29 #include <linux/delay.h>
30 #include <linux/device.h>
31 #include <linux/export.h>
36 #include "iwl-debug.h"
40 void iwl_write8(struct iwl_trans
*trans
, u32 ofs
, u8 val
)
42 trace_iwlwifi_dev_iowrite8(trans
->dev
, ofs
, val
);
43 iwl_trans_write8(trans
, ofs
, val
);
45 IWL_EXPORT_SYMBOL(iwl_write8
);
47 void iwl_write32(struct iwl_trans
*trans
, u32 ofs
, u32 val
)
49 trace_iwlwifi_dev_iowrite32(trans
->dev
, ofs
, val
);
50 iwl_trans_write32(trans
, ofs
, val
);
52 IWL_EXPORT_SYMBOL(iwl_write32
);
54 u32
iwl_read32(struct iwl_trans
*trans
, u32 ofs
)
56 u32 val
= iwl_trans_read32(trans
, ofs
);
58 trace_iwlwifi_dev_ioread32(trans
->dev
, ofs
, val
);
61 IWL_EXPORT_SYMBOL(iwl_read32
);
63 #define IWL_POLL_INTERVAL 10 /* microseconds */
65 int iwl_poll_bit(struct iwl_trans
*trans
, u32 addr
,
66 u32 bits
, u32 mask
, int timeout
)
71 if ((iwl_read32(trans
, addr
) & mask
) == (bits
& mask
))
73 udelay(IWL_POLL_INTERVAL
);
74 t
+= IWL_POLL_INTERVAL
;
75 } while (t
< timeout
);
79 IWL_EXPORT_SYMBOL(iwl_poll_bit
);
81 u32
iwl_read_direct32(struct iwl_trans
*trans
, u32 reg
)
83 u32 value
= 0x5a5a5a5a;
85 if (iwl_trans_grab_nic_access(trans
, &flags
)) {
86 value
= iwl_read32(trans
, reg
);
87 iwl_trans_release_nic_access(trans
, &flags
);
92 IWL_EXPORT_SYMBOL(iwl_read_direct32
);
94 void iwl_write_direct32(struct iwl_trans
*trans
, u32 reg
, u32 value
)
98 if (iwl_trans_grab_nic_access(trans
, &flags
)) {
99 iwl_write32(trans
, reg
, value
);
100 iwl_trans_release_nic_access(trans
, &flags
);
103 IWL_EXPORT_SYMBOL(iwl_write_direct32
);
105 int iwl_poll_direct_bit(struct iwl_trans
*trans
, u32 addr
, u32 mask
,
111 if ((iwl_read_direct32(trans
, addr
) & mask
) == mask
)
113 udelay(IWL_POLL_INTERVAL
);
114 t
+= IWL_POLL_INTERVAL
;
115 } while (t
< timeout
);
119 IWL_EXPORT_SYMBOL(iwl_poll_direct_bit
);
121 u32
iwl_read_prph_no_grab(struct iwl_trans
*trans
, u32 ofs
)
123 u32 val
= iwl_trans_read_prph(trans
, ofs
);
124 trace_iwlwifi_dev_ioread_prph32(trans
->dev
, ofs
, val
);
127 IWL_EXPORT_SYMBOL(iwl_read_prph_no_grab
);
129 void iwl_write_prph_no_grab(struct iwl_trans
*trans
, u32 ofs
, u32 val
)
131 trace_iwlwifi_dev_iowrite_prph32(trans
->dev
, ofs
, val
);
132 iwl_trans_write_prph(trans
, ofs
, val
);
134 IWL_EXPORT_SYMBOL(iwl_write_prph_no_grab
);
136 u32
iwl_read_prph(struct iwl_trans
*trans
, u32 ofs
)
139 u32 val
= 0x5a5a5a5a;
141 if (iwl_trans_grab_nic_access(trans
, &flags
)) {
142 val
= iwl_read_prph_no_grab(trans
, ofs
);
143 iwl_trans_release_nic_access(trans
, &flags
);
147 IWL_EXPORT_SYMBOL(iwl_read_prph
);
149 void iwl_write_prph(struct iwl_trans
*trans
, u32 ofs
, u32 val
)
153 if (iwl_trans_grab_nic_access(trans
, &flags
)) {
154 iwl_write_prph_no_grab(trans
, ofs
, val
);
155 iwl_trans_release_nic_access(trans
, &flags
);
158 IWL_EXPORT_SYMBOL(iwl_write_prph
);
160 int iwl_poll_prph_bit(struct iwl_trans
*trans
, u32 addr
,
161 u32 bits
, u32 mask
, int timeout
)
166 if ((iwl_read_prph(trans
, addr
) & mask
) == (bits
& mask
))
168 udelay(IWL_POLL_INTERVAL
);
169 t
+= IWL_POLL_INTERVAL
;
170 } while (t
< timeout
);
175 void iwl_set_bits_prph(struct iwl_trans
*trans
, u32 ofs
, u32 mask
)
179 if (iwl_trans_grab_nic_access(trans
, &flags
)) {
180 iwl_write_prph_no_grab(trans
, ofs
,
181 iwl_read_prph_no_grab(trans
, ofs
) |
183 iwl_trans_release_nic_access(trans
, &flags
);
186 IWL_EXPORT_SYMBOL(iwl_set_bits_prph
);
188 void iwl_set_bits_mask_prph(struct iwl_trans
*trans
, u32 ofs
,
193 if (iwl_trans_grab_nic_access(trans
, &flags
)) {
194 iwl_write_prph_no_grab(trans
, ofs
,
195 (iwl_read_prph_no_grab(trans
, ofs
) &
197 iwl_trans_release_nic_access(trans
, &flags
);
200 IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph
);
202 void iwl_clear_bits_prph(struct iwl_trans
*trans
, u32 ofs
, u32 mask
)
207 if (iwl_trans_grab_nic_access(trans
, &flags
)) {
208 val
= iwl_read_prph_no_grab(trans
, ofs
);
209 iwl_write_prph_no_grab(trans
, ofs
, (val
& ~mask
));
210 iwl_trans_release_nic_access(trans
, &flags
);
213 IWL_EXPORT_SYMBOL(iwl_clear_bits_prph
);
215 void iwl_force_nmi(struct iwl_trans
*trans
)
217 if (trans
->cfg
->device_family
!= IWL_DEVICE_FAMILY_8000
) {
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
);
223 iwl_write_prph(trans
, DEVICE_SET_NMI_8000_REG
,
224 DEVICE_SET_NMI_8000_VAL
);
225 iwl_write_prph(trans
, DEVICE_SET_NMI_REG
,
226 DEVICE_SET_NMI_VAL_DRV
);
229 IWL_EXPORT_SYMBOL(iwl_force_nmi
);
231 static const char *get_fh_string(int cmd
)
233 #define IWL_CMD(x) case x: return #x
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
);
250 int iwl_dump_fh(struct iwl_trans
*trans
, char **buf
)
253 static const u32 fh_tbl
[] = {
254 FH_RSCSR_CHNL0_STTS_WPTR_REG
,
255 FH_RSCSR_CHNL0_RBDCB_BASE_REG
,
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
,
265 #ifdef CONFIG_IWLWIFI_DEBUGFS
268 size_t bufsz
= ARRAY_SIZE(fh_tbl
) * 48 + 40;
270 *buf
= kmalloc(bufsz
, GFP_KERNEL
);
274 pos
+= scnprintf(*buf
+ pos
, bufsz
- pos
,
275 "FH register values:\n");
277 for (i
= 0; i
< ARRAY_SIZE(fh_tbl
); i
++)
278 pos
+= scnprintf(*buf
+ pos
, bufsz
- pos
,
280 get_fh_string(fh_tbl
[i
]),
281 iwl_read_direct32(trans
, fh_tbl
[i
]));
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
]));