aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-io.c
diff options
context:
space:
mode:
authorStanislaw Gruszka <sgruszka@redhat.com>2012-03-07 12:52:24 -0500
committerJohn W. Linville <linville@tuxdriver.com>2012-03-08 13:59:50 -0500
commitbfe4b80e9f7385f34986736cdc094be56782109a (patch)
tree29b1335d3045834bcbb5d23d53a4b212ef9355e0 /drivers/net/wireless/iwlwifi/iwl-io.c
parentaa5affbacb24cb5d8fd6f7c66e57d62164ed6d34 (diff)
iwlwifi: always check if got h/w access before write
Before we write to the device registers always check if iwl_grap_nic_access() was successful. On the way change return type of grab_nic_access() to bool, and add likely()/unlikely() statement. Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-io.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-io.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-io.c b/drivers/net/wireless/iwlwifi/iwl-io.c
index fc365350a3e7..fa69845954cf 100644
--- a/drivers/net/wireless/iwlwifi/iwl-io.c
+++ b/drivers/net/wireless/iwlwifi/iwl-io.c
@@ -118,16 +118,17 @@ int iwl_grab_nic_access_silent(struct iwl_trans *trans)
118 return 0; 118 return 0;
119} 119}
120 120
121int iwl_grab_nic_access(struct iwl_trans *trans) 121bool iwl_grab_nic_access(struct iwl_trans *trans)
122{ 122{
123 int ret = iwl_grab_nic_access_silent(trans); 123 int ret = iwl_grab_nic_access_silent(trans);
124 if (unlikely(ret)) { 124 if (unlikely(ret)) {
125 u32 val = iwl_read32(trans, CSR_GP_CNTRL); 125 u32 val = iwl_read32(trans, CSR_GP_CNTRL);
126 WARN_ONCE(1, "Timeout waiting for hardware access " 126 WARN_ONCE(1, "Timeout waiting for hardware access "
127 "(CSR_GP_CNTRL 0x%08x)\n", val); 127 "(CSR_GP_CNTRL 0x%08x)\n", val);
128 return false;
128 } 129 }
129 130
130 return ret; 131 return true;
131} 132}
132 133
133void iwl_release_nic_access(struct iwl_trans *trans) 134void iwl_release_nic_access(struct iwl_trans *trans)
@@ -156,7 +157,7 @@ void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
156 unsigned long flags; 157 unsigned long flags;
157 158
158 spin_lock_irqsave(&trans->reg_lock, flags); 159 spin_lock_irqsave(&trans->reg_lock, flags);
159 if (!iwl_grab_nic_access(trans)) { 160 if (likely(iwl_grab_nic_access(trans))) {
160 iwl_write32(trans, reg, value); 161 iwl_write32(trans, reg, value);
161 iwl_release_nic_access(trans); 162 iwl_release_nic_access(trans);
162 } 163 }
@@ -211,7 +212,7 @@ void iwl_write_prph(struct iwl_trans *trans, u32 addr, u32 val)
211 unsigned long flags; 212 unsigned long flags;
212 213
213 spin_lock_irqsave(&trans->reg_lock, flags); 214 spin_lock_irqsave(&trans->reg_lock, flags);
214 if (!iwl_grab_nic_access(trans)) { 215 if (likely(iwl_grab_nic_access(trans))) {
215 __iwl_write_prph(trans, addr, val); 216 __iwl_write_prph(trans, addr, val);
216 iwl_release_nic_access(trans); 217 iwl_release_nic_access(trans);
217 } 218 }
@@ -223,9 +224,11 @@ void iwl_set_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask)
223 unsigned long flags; 224 unsigned long flags;
224 225
225 spin_lock_irqsave(&trans->reg_lock, flags); 226 spin_lock_irqsave(&trans->reg_lock, flags);
226 iwl_grab_nic_access(trans); 227 if (likely(iwl_grab_nic_access(trans))) {
227 __iwl_write_prph(trans, reg, __iwl_read_prph(trans, reg) | mask); 228 __iwl_write_prph(trans, reg,
228 iwl_release_nic_access(trans); 229 __iwl_read_prph(trans, reg) | mask);
230 iwl_release_nic_access(trans);
231 }
229 spin_unlock_irqrestore(&trans->reg_lock, flags); 232 spin_unlock_irqrestore(&trans->reg_lock, flags);
230} 233}
231 234
@@ -235,10 +238,11 @@ void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 reg,
235 unsigned long flags; 238 unsigned long flags;
236 239
237 spin_lock_irqsave(&trans->reg_lock, flags); 240 spin_lock_irqsave(&trans->reg_lock, flags);
238 iwl_grab_nic_access(trans); 241 if (likely(iwl_grab_nic_access(trans))) {
239 __iwl_write_prph(trans, reg, 242 __iwl_write_prph(trans, reg,
240 (__iwl_read_prph(trans, reg) & mask) | bits); 243 (__iwl_read_prph(trans, reg) & mask) | bits);
241 iwl_release_nic_access(trans); 244 iwl_release_nic_access(trans);
245 }
242 spin_unlock_irqrestore(&trans->reg_lock, flags); 246 spin_unlock_irqrestore(&trans->reg_lock, flags);
243} 247}
244 248
@@ -248,10 +252,11 @@ void iwl_clear_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask)
248 u32 val; 252 u32 val;
249 253
250 spin_lock_irqsave(&trans->reg_lock, flags); 254 spin_lock_irqsave(&trans->reg_lock, flags);
251 iwl_grab_nic_access(trans); 255 if (likely(iwl_grab_nic_access(trans))) {
252 val = __iwl_read_prph(trans, reg); 256 val = __iwl_read_prph(trans, reg);
253 __iwl_write_prph(trans, reg, (val & ~mask)); 257 __iwl_write_prph(trans, reg, (val & ~mask));
254 iwl_release_nic_access(trans); 258 iwl_release_nic_access(trans);
259 }
255 spin_unlock_irqrestore(&trans->reg_lock, flags); 260 spin_unlock_irqrestore(&trans->reg_lock, flags);
256} 261}
257 262
@@ -263,15 +268,13 @@ void _iwl_read_targ_mem_words(struct iwl_trans *trans, u32 addr,
263 u32 *vals = buf; 268 u32 *vals = buf;
264 269
265 spin_lock_irqsave(&trans->reg_lock, flags); 270 spin_lock_irqsave(&trans->reg_lock, flags);
266 iwl_grab_nic_access(trans); 271 if (likely(iwl_grab_nic_access(trans))) {
267 272 iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr);
268 iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr); 273 rmb();
269 rmb(); 274 for (offs = 0; offs < words; offs++)
270 275 vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
271 for (offs = 0; offs < words; offs++) 276 iwl_release_nic_access(trans);
272 vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT); 277 }
273
274 iwl_release_nic_access(trans);
275 spin_unlock_irqrestore(&trans->reg_lock, flags); 278 spin_unlock_irqrestore(&trans->reg_lock, flags);
276} 279}
277 280
@@ -292,7 +295,7 @@ int _iwl_write_targ_mem_words(struct iwl_trans *trans, u32 addr,
292 u32 *vals = buf; 295 u32 *vals = buf;
293 296
294 spin_lock_irqsave(&trans->reg_lock, flags); 297 spin_lock_irqsave(&trans->reg_lock, flags);
295 if (!iwl_grab_nic_access(trans)) { 298 if (likely(iwl_grab_nic_access(trans))) {
296 iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr); 299 iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr);
297 wmb(); 300 wmb();
298 301