]>
Commit | Line | Data |
---|---|---|
02a7fa00 JB |
1 | /****************************************************************************** |
2 | * | |
51368bf7 | 3 | * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved. |
02a7fa00 JB |
4 | * |
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 | *****************************************************************************/ | |
83ed9015 EG |
28 | #include <linux/delay.h> |
29 | #include <linux/device.h> | |
cc5f7e39 | 30 | #include <linux/export.h> |
02a7fa00 | 31 | |
48e29340 | 32 | #include "iwl-drv.h" |
02a7fa00 | 33 | #include "iwl-io.h" |
6ac7d115 | 34 | #include "iwl-csr.h" |
83ed9015 | 35 | #include "iwl-debug.h" |
313b0a29 | 36 | #include "iwl-fh.h" |
02a7fa00 JB |
37 | |
38 | #define IWL_POLL_INTERVAL 10 /* microseconds */ | |
39 | ||
1042db2a | 40 | int iwl_poll_bit(struct iwl_trans *trans, u32 addr, |
02a7fa00 JB |
41 | u32 bits, u32 mask, int timeout) |
42 | { | |
43 | int t = 0; | |
44 | ||
45 | do { | |
1042db2a | 46 | if ((iwl_read32(trans, addr) & mask) == (bits & mask)) |
02a7fa00 JB |
47 | return t; |
48 | udelay(IWL_POLL_INTERVAL); | |
49 | t += IWL_POLL_INTERVAL; | |
50 | } while (t < timeout); | |
51 | ||
52 | return -ETIMEDOUT; | |
53 | } | |
48e29340 | 54 | IWL_EXPORT_SYMBOL(iwl_poll_bit); |
02a7fa00 | 55 | |
1042db2a | 56 | u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg) |
02a7fa00 | 57 | { |
abae2386 | 58 | u32 value = 0x5a5a5a5a; |
02a7fa00 | 59 | unsigned long flags; |
e56b04ef | 60 | if (iwl_trans_grab_nic_access(trans, false, &flags)) { |
abae2386 | 61 | value = iwl_read32(trans, reg); |
e56b04ef | 62 | iwl_trans_release_nic_access(trans, &flags); |
abae2386 | 63 | } |
02a7fa00 JB |
64 | |
65 | return value; | |
66 | } | |
48e29340 | 67 | IWL_EXPORT_SYMBOL(iwl_read_direct32); |
02a7fa00 | 68 | |
1042db2a | 69 | void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) |
02a7fa00 JB |
70 | { |
71 | unsigned long flags; | |
72 | ||
e56b04ef | 73 | if (iwl_trans_grab_nic_access(trans, false, &flags)) { |
1042db2a | 74 | iwl_write32(trans, reg, value); |
e56b04ef | 75 | iwl_trans_release_nic_access(trans, &flags); |
02a7fa00 | 76 | } |
02a7fa00 | 77 | } |
48e29340 | 78 | IWL_EXPORT_SYMBOL(iwl_write_direct32); |
02a7fa00 | 79 | |
1042db2a | 80 | int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask, |
02a7fa00 JB |
81 | int timeout) |
82 | { | |
83 | int t = 0; | |
84 | ||
85 | do { | |
1042db2a | 86 | if ((iwl_read_direct32(trans, addr) & mask) == mask) |
02a7fa00 JB |
87 | return t; |
88 | udelay(IWL_POLL_INTERVAL); | |
89 | t += IWL_POLL_INTERVAL; | |
90 | } while (t < timeout); | |
91 | ||
92 | return -ETIMEDOUT; | |
93 | } | |
48e29340 | 94 | IWL_EXPORT_SYMBOL(iwl_poll_direct_bit); |
02a7fa00 | 95 | |
6a06b6c1 | 96 | static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs) |
02a7fa00 | 97 | { |
6a06b6c1 EG |
98 | u32 val = iwl_trans_read_prph(trans, ofs); |
99 | trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val); | |
100 | return val; | |
02a7fa00 JB |
101 | } |
102 | ||
6a06b6c1 | 103 | static inline void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) |
02a7fa00 | 104 | { |
6a06b6c1 EG |
105 | trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val); |
106 | iwl_trans_write_prph(trans, ofs, val); | |
02a7fa00 JB |
107 | } |
108 | ||
6a06b6c1 | 109 | u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs) |
02a7fa00 JB |
110 | { |
111 | unsigned long flags; | |
abae2386 | 112 | u32 val = 0x5a5a5a5a; |
02a7fa00 | 113 | |
e56b04ef | 114 | if (iwl_trans_grab_nic_access(trans, false, &flags)) { |
abae2386 | 115 | val = __iwl_read_prph(trans, ofs); |
e56b04ef | 116 | iwl_trans_release_nic_access(trans, &flags); |
abae2386 | 117 | } |
02a7fa00 JB |
118 | return val; |
119 | } | |
48e29340 | 120 | IWL_EXPORT_SYMBOL(iwl_read_prph); |
02a7fa00 | 121 | |
6a06b6c1 | 122 | void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val) |
02a7fa00 JB |
123 | { |
124 | unsigned long flags; | |
125 | ||
e56b04ef | 126 | if (iwl_trans_grab_nic_access(trans, false, &flags)) { |
6a06b6c1 | 127 | __iwl_write_prph(trans, ofs, val); |
e56b04ef | 128 | iwl_trans_release_nic_access(trans, &flags); |
02a7fa00 | 129 | } |
02a7fa00 | 130 | } |
48e29340 | 131 | IWL_EXPORT_SYMBOL(iwl_write_prph); |
02a7fa00 | 132 | |
6a06b6c1 | 133 | void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) |
02a7fa00 JB |
134 | { |
135 | unsigned long flags; | |
136 | ||
e56b04ef | 137 | if (iwl_trans_grab_nic_access(trans, false, &flags)) { |
6a06b6c1 EG |
138 | __iwl_write_prph(trans, ofs, |
139 | __iwl_read_prph(trans, ofs) | mask); | |
e56b04ef | 140 | iwl_trans_release_nic_access(trans, &flags); |
bfe4b80e | 141 | } |
02a7fa00 | 142 | } |
48e29340 | 143 | IWL_EXPORT_SYMBOL(iwl_set_bits_prph); |
02a7fa00 | 144 | |
6a06b6c1 | 145 | void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs, |
02a7fa00 JB |
146 | u32 bits, u32 mask) |
147 | { | |
148 | unsigned long flags; | |
149 | ||
e56b04ef | 150 | if (iwl_trans_grab_nic_access(trans, false, &flags)) { |
6a06b6c1 EG |
151 | __iwl_write_prph(trans, ofs, |
152 | (__iwl_read_prph(trans, ofs) & mask) | bits); | |
e56b04ef | 153 | iwl_trans_release_nic_access(trans, &flags); |
bfe4b80e | 154 | } |
02a7fa00 | 155 | } |
48e29340 | 156 | IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph); |
02a7fa00 | 157 | |
6a06b6c1 | 158 | void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask) |
02a7fa00 JB |
159 | { |
160 | unsigned long flags; | |
161 | u32 val; | |
162 | ||
e56b04ef | 163 | if (iwl_trans_grab_nic_access(trans, false, &flags)) { |
6a06b6c1 EG |
164 | val = __iwl_read_prph(trans, ofs); |
165 | __iwl_write_prph(trans, ofs, (val & ~mask)); | |
e56b04ef | 166 | iwl_trans_release_nic_access(trans, &flags); |
bfe4b80e | 167 | } |
02a7fa00 | 168 | } |
48e29340 | 169 | IWL_EXPORT_SYMBOL(iwl_clear_bits_prph); |
313b0a29 IH |
170 | |
171 | static const char *get_fh_string(int cmd) | |
172 | { | |
173 | #define IWL_CMD(x) case x: return #x | |
174 | switch (cmd) { | |
175 | IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG); | |
176 | IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG); | |
177 | IWL_CMD(FH_RSCSR_CHNL0_WPTR); | |
178 | IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG); | |
179 | IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG); | |
180 | IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG); | |
181 | IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV); | |
182 | IWL_CMD(FH_TSSR_TX_STATUS_REG); | |
183 | IWL_CMD(FH_TSSR_TX_ERROR_REG); | |
184 | default: | |
185 | return "UNKNOWN"; | |
186 | } | |
187 | #undef IWL_CMD | |
188 | } | |
189 | ||
190 | int iwl_dump_fh(struct iwl_trans *trans, char **buf) | |
191 | { | |
192 | int i; | |
193 | static const u32 fh_tbl[] = { | |
194 | FH_RSCSR_CHNL0_STTS_WPTR_REG, | |
195 | FH_RSCSR_CHNL0_RBDCB_BASE_REG, | |
196 | FH_RSCSR_CHNL0_WPTR, | |
197 | FH_MEM_RCSR_CHNL0_CONFIG_REG, | |
198 | FH_MEM_RSSR_SHARED_CTRL_REG, | |
199 | FH_MEM_RSSR_RX_STATUS_REG, | |
200 | FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV, | |
201 | FH_TSSR_TX_STATUS_REG, | |
202 | FH_TSSR_TX_ERROR_REG | |
203 | }; | |
204 | ||
205 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
206 | if (buf) { | |
207 | int pos = 0; | |
208 | size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40; | |
209 | ||
210 | *buf = kmalloc(bufsz, GFP_KERNEL); | |
211 | if (!*buf) | |
212 | return -ENOMEM; | |
213 | ||
214 | pos += scnprintf(*buf + pos, bufsz - pos, | |
215 | "FH register values:\n"); | |
216 | ||
217 | for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) | |
218 | pos += scnprintf(*buf + pos, bufsz - pos, | |
219 | " %34s: 0X%08x\n", | |
220 | get_fh_string(fh_tbl[i]), | |
221 | iwl_read_direct32(trans, fh_tbl[i])); | |
222 | ||
223 | return pos; | |
224 | } | |
225 | #endif | |
226 | ||
227 | IWL_ERR(trans, "FH register values:\n"); | |
228 | for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) | |
229 | IWL_ERR(trans, " %34s: 0X%08x\n", | |
230 | get_fh_string(fh_tbl[i]), | |
231 | iwl_read_direct32(trans, fh_tbl[i])); | |
232 | ||
233 | return 0; | |
234 | } |