diff options
author | Stanislaw Gruszka <sgruszka@redhat.com> | 2012-03-07 12:52:24 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2012-03-08 13:59:50 -0500 |
commit | bfe4b80e9f7385f34986736cdc094be56782109a (patch) | |
tree | 29b1335d3045834bcbb5d23d53a4b212ef9355e0 /drivers/net/wireless | |
parent | aa5affbacb24cb5d8fd6f7c66e57d62164ed6d34 (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')
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn-tt.c | 2 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn.c | 2 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-io.c | 53 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-io.h | 2 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-mac80211.c | 2 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c | 4 |
6 files changed, 35 insertions, 30 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tt.c b/drivers/net/wireless/iwlwifi/iwl-agn-tt.c index 7712c5537370..9a12b70c7d4f 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn-tt.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn-tt.c | |||
@@ -189,7 +189,7 @@ static void iwl_tt_check_exit_ct_kill(unsigned long data) | |||
189 | } | 189 | } |
190 | iwl_read32(trans(priv), CSR_UCODE_DRV_GP1); | 190 | iwl_read32(trans(priv), CSR_UCODE_DRV_GP1); |
191 | spin_lock_irqsave(&trans(priv)->reg_lock, flags); | 191 | spin_lock_irqsave(&trans(priv)->reg_lock, flags); |
192 | if (!iwl_grab_nic_access(trans(priv))) | 192 | if (likely(iwl_grab_nic_access(trans(priv)))) |
193 | iwl_release_nic_access(trans(priv)); | 193 | iwl_release_nic_access(trans(priv)); |
194 | spin_unlock_irqrestore(&trans(priv)->reg_lock, flags); | 194 | spin_unlock_irqrestore(&trans(priv)->reg_lock, flags); |
195 | 195 | ||
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c index 5f390f8d3b8b..ce9ebeb89e4c 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn.c | |||
@@ -327,7 +327,7 @@ static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base, | |||
327 | 327 | ||
328 | /* Make sure device is powered up for SRAM reads */ | 328 | /* Make sure device is powered up for SRAM reads */ |
329 | spin_lock_irqsave(&trans(priv)->reg_lock, reg_flags); | 329 | spin_lock_irqsave(&trans(priv)->reg_lock, reg_flags); |
330 | if (iwl_grab_nic_access(trans(priv))) { | 330 | if (unlikely(!iwl_grab_nic_access(trans(priv)))) { |
331 | spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags); | 331 | spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags); |
332 | return; | 332 | return; |
333 | } | 333 | } |
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 | ||
121 | int iwl_grab_nic_access(struct iwl_trans *trans) | 121 | bool 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 | ||
133 | void iwl_release_nic_access(struct iwl_trans *trans) | 134 | void 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 | ||
diff --git a/drivers/net/wireless/iwlwifi/iwl-io.h b/drivers/net/wireless/iwlwifi/iwl-io.h index 1136dc19936a..09b856768f62 100644 --- a/drivers/net/wireless/iwlwifi/iwl-io.h +++ b/drivers/net/wireless/iwlwifi/iwl-io.h | |||
@@ -61,7 +61,7 @@ int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask, | |||
61 | int timeout); | 61 | int timeout); |
62 | 62 | ||
63 | int iwl_grab_nic_access_silent(struct iwl_trans *trans); | 63 | int iwl_grab_nic_access_silent(struct iwl_trans *trans); |
64 | int iwl_grab_nic_access(struct iwl_trans *trans); | 64 | bool iwl_grab_nic_access(struct iwl_trans *trans); |
65 | void iwl_release_nic_access(struct iwl_trans *trans); | 65 | void iwl_release_nic_access(struct iwl_trans *trans); |
66 | 66 | ||
67 | u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg); | 67 | u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg); |
diff --git a/drivers/net/wireless/iwlwifi/iwl-mac80211.c b/drivers/net/wireless/iwlwifi/iwl-mac80211.c index bdcbbd0d3467..91a42c3261aa 100644 --- a/drivers/net/wireless/iwlwifi/iwl-mac80211.c +++ b/drivers/net/wireless/iwlwifi/iwl-mac80211.c | |||
@@ -445,7 +445,7 @@ static int iwlagn_mac_resume(struct ieee80211_hw *hw) | |||
445 | if (iwlagn_hw_valid_rtc_data_addr(base)) { | 445 | if (iwlagn_hw_valid_rtc_data_addr(base)) { |
446 | spin_lock_irqsave(&trans(priv)->reg_lock, flags); | 446 | spin_lock_irqsave(&trans(priv)->reg_lock, flags); |
447 | ret = iwl_grab_nic_access_silent(trans(priv)); | 447 | ret = iwl_grab_nic_access_silent(trans(priv)); |
448 | if (ret == 0) { | 448 | if (likely(ret == 0)) { |
449 | iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, base); | 449 | iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, base); |
450 | status = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT); | 450 | status = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT); |
451 | iwl_release_nic_access(trans(priv)); | 451 | iwl_release_nic_access(trans(priv)); |
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c index 83cc60e8f607..5d1fc7b1b0a3 100644 --- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c +++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c | |||
@@ -745,7 +745,8 @@ static int iwl_print_event_log(struct iwl_trans *trans, u32 start_idx, | |||
745 | 745 | ||
746 | /* Make sure device is powered up for SRAM reads */ | 746 | /* Make sure device is powered up for SRAM reads */ |
747 | spin_lock_irqsave(&trans->reg_lock, reg_flags); | 747 | spin_lock_irqsave(&trans->reg_lock, reg_flags); |
748 | iwl_grab_nic_access(trans); | 748 | if (unlikely(!iwl_grab_nic_access(trans))) |
749 | goto out_unlock; | ||
749 | 750 | ||
750 | /* Set starting address; reads will auto-increment */ | 751 | /* Set starting address; reads will auto-increment */ |
751 | iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr); | 752 | iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr); |
@@ -785,6 +786,7 @@ static int iwl_print_event_log(struct iwl_trans *trans, u32 start_idx, | |||
785 | 786 | ||
786 | /* Allow device to power down */ | 787 | /* Allow device to power down */ |
787 | iwl_release_nic_access(trans); | 788 | iwl_release_nic_access(trans); |
789 | out_unlock: | ||
788 | spin_unlock_irqrestore(&trans->reg_lock, reg_flags); | 790 | spin_unlock_irqrestore(&trans->reg_lock, reg_flags); |
789 | return pos; | 791 | return pos; |
790 | } | 792 | } |