Error Trace

[Home]

Bug # 121

Show/hide error trace
Error trace
Function bodies
Blocks
  • Others...
    Function bodies without model function calls
    Initialization function calls
    Initialization function bodies
    Entry point
    Entry point body
    Function calls
    Skipped function calls
    Formal parameter names
    Declarations
    Assumes
    Assume conditions
    Returns
    Return values
    DEG initialization
    DEG function calls
    Model function calls
    Model function bodies
    Model asserts
    Model state changes
    Model function function calls
    Model function function bodies
    Model returns
    Model others
    Identation
    Line numbers
    Expand signs
/*Is true unsafe:*/
/*Number of usage points:2*/
/*Number of usages :2*/
/*Two examples:*/
/*_____________________*/
/*mutex_lock(char *"_mutex_of_ath9k_htc_priv")[1]*/
-__CPAchecker_initialize()
{
return ;
}
-entry_point
{
323 unsigned int ldvarg104;
324 int *ldvarg105;
325 u16 *ldvarg103;
326 int tmp;
327 int tmp___0;
328 int tmp___1;
329 int tmp___2;
322 ldv_initialize() { /* Function call is skipped due to function is undefined */}
328 ldv_state_variable_6 = 0;
329 ldv_state_variable_11 = 0;
330 ldv_state_variable_3 = 0;
331 ldv_state_variable_7 = 0;
332 ldv_state_variable_9 = 0;
333 ldv_state_variable_12 = 0;
334 ldv_state_variable_2 = 0;
335 ldv_state_variable_14 = 0;
336 ldv_state_variable_8 = 0;
338 -timer_init_1()
{
179 ldv_timer_1_0 = 0;
180 ldv_timer_1_1 = 0;
181 ldv_timer_1_2 = 0;
182 ldv_timer_1_3 = 0;
183 return ;;
}
340 ldv_state_variable_1 = 1;
341 ldv_state_variable_4 = 0;
342 ref_cnt = 0;
343 ldv_state_variable_0 = 1;
344 ldv_state_variable_13 = 0;
345 ldv_state_variable_10 = 0;
346 ldv_state_variable_5 = 0;
347 ldv_57990:;
348 tmp = __VERIFIER_nondet_int() { /* Function call is skipped due to function is undefined */}
348 switch (tmp);
349 assume(!(tmp == 0));
357 assume(!(tmp == 1));
387 assume(!(tmp == 2));
395 assume(!(tmp == 3));
403 assume(!(tmp == 4));
411 assume(tmp == 5);
414 assume(ldv_state_variable_12 != 0);
415 -ldv_main_exported_12()
{
147 struct ieee80211_vif *ldvarg75;
148 struct ieee80211_tx_control *ldvarg52;
149 int ldvarg74;
150 struct ieee80211_vif *ldvarg22;
151 struct ieee80211_vif *ldvarg25;
152 struct ieee80211_bss_conf *ldvarg61;
153 struct ieee80211_vif *ldvarg54;
154 struct ieee80211_sta *ldvarg21;
155 unsigned int ldvarg30;
156 struct ieee80211_vif *ldvarg68;
157 const struct cfg80211_bitrate_mask *ldvarg70;
158 struct ieee80211_vif *ldvarg73;
159 unsigned int ldvarg26;
160 u8 *ldvarg27;
161 unsigned int ldvarg63;
162 unsigned short ldvarg45;
163 enum ieee80211_ampdu_mlme_action ldvarg40;
164 u64 *ldvarg36;
165 struct ieee80211_vif *ldvarg55;
166 struct ieee80211_sta *ldvarg66;
167 struct ieee80211_vif *ldvarg57;
168 enum set_key_cmd ldvarg65;
169 struct ieee80211_vif *ldvarg62;
170 unsigned long long ldvarg49;
171 u32 *ldvarg59;
172 unsigned char ldvarg41;
173 u32 *ldvarg60;
174 struct ieee80211_vif *ldvarg31;
175 struct ieee80211_vif *ldvarg20;
176 u16 *ldvarg39;
177 struct ieee80211_vif *ldvarg47;
178 unsigned int *ldvarg34;
179 struct ieee80211_vif *ldvarg28;
180 unsigned int ldvarg48;
181 unsigned long long ldvarg33;
182 short ldvarg69;
183 struct ieee80211_vif *ldvarg38;
184 unsigned int ldvarg35;
185 struct ieee80211_vif *ldvarg24;
186 struct ieee80211_sta *ldvarg44;
187 u8 *ldvarg29;
188 struct ieee80211_vif *ldvarg64;
189 struct ieee80211_sta *ldvarg53;
190 struct ethtool_stats *ldvarg37;
191 const struct ieee80211_tx_queue_params *ldvarg58;
192 struct ieee80211_sta *ldvarg46;
193 struct ieee80211_vif *ldvarg50;
194 unsigned short ldvarg56;
195 unsigned int ldvarg72;
196 struct ieee80211_vif *ldvarg71;
197 struct ieee80211_vif *ldvarg42;
198 _Bool ldvarg43;
199 struct cfg80211_chan_def *ldvarg23;
200 struct ieee80211_key_conf *ldvarg67;
201 struct ieee80211_low_level_stats *ldvarg32;
202 struct sk_buff *ldvarg51;
203 int tmp;
204 int tmp___0;
205 int tmp___1;
206 int tmp___2;
207 int tmp___3;
208 int tmp___4;
209 int tmp___5;
203 tmp = __VERIFIER_nondet_int() { /* Function call is skipped due to function is undefined */}
203 switch (tmp);
204 assume(!(tmp == 0));
221 assume(!(tmp == 1));
238 assume(!(tmp == 2));
251 assume(tmp == 3);
253 assume(ldv_state_variable_12 == 1);
255 -ath9k_htc_config(ath9k_htc_ops_group0, ldvarg72)
{
1180 struct ath9k_htc_priv *priv;
1181 struct ath_common *common;
1182 struct ath_common *tmp;
1183 struct ieee80211_conf *conf;
1184 _Bool chip_reset;
1185 int ret;
1186 struct ieee80211_channel *curchan;
1187 int pos;
1188 int tmp___0;
1180 struct ath9k_htc_priv *__CPAchecker_TMP_0 = (struct ath9k_htc_priv *)(hw->priv);
1180 priv = __CPAchecker_TMP_0;
1181 -ath9k_hw_common(priv->ah)
{
990 return &(ah->common);;
}
1181 common = tmp;
1182 conf = &(hw->conf);
1183 chip_reset = 0;
1184 ret = 0;
1186 -ldv_mutex_lock_407(&(priv->mutex))
{
/*Change states for locks mutex_lock(char *"_mutex_of_ath9k_htc_priv")*/
1257 ldv_mutex_lock(ldv_func_arg1, (char *)"_mutex_of_ath9k_htc_priv") { /* Function call is skipped due to function is undefined */}
1258 return ;;
}
1187 -ath9k_htc_ps_wakeup(priv)
{
47 -ldv_mutex_lock_379(&(priv->htc_pm_lock))
{
/*Change states for locks mutex_lock(char *"_htc_pm_lock_of_ath9k_htc_priv")*/
1059 ldv_mutex_lock(ldv_func_arg1, (char *)"_htc_pm_lock_of_ath9k_htc_priv") { /* Function call is skipped due to function is undefined */}
1060 return ;;
}
48 priv->ps_usecount = (priv->ps_usecount) + 1UL;
48 assume(!((priv->ps_usecount) != 1UL));
50 ath9k_hw_setpower(priv->ah, 0) { /* Function call is skipped due to function is undefined */}
51 unlock:;
53 -ldv_mutex_unlock_380(&(priv->htc_pm_lock))
{
/*Change states for locks mutex_lock(char *"_htc_pm_lock_of_ath9k_htc_priv")*/
1065 ldv_mutex_unlock(ldv_func_arg1, (char *)"_htc_pm_lock_of_ath9k_htc_priv") { /* Function call is skipped due to function is undefined */}
1066 return ;;
}
54 return ;;
}
1189 assume(!((changed & 256U) != 0U));
1203 assume((changed & 8U) != 0U);
1204 int __CPAchecker_TMP_1 = (int)(conf->flags);
1204 assume(!((__CPAchecker_TMP_1 & 1) == 0));
1204 assume((priv->ah->is_monitoring) == 0);
1206 -ath9k_htc_add_monitor_interface(priv)
{
355 struct ath_common *common;
356 struct ath_common *tmp;
357 struct ath9k_htc_target_vif hvif;
358 struct ath9k_htc_target_sta tsta;
359 int ret;
360 int sta_idx;
361 unsigned char cmd_rsp;
362 unsigned long tmp___0;
363 unsigned long tmp___1;
355 -ath9k_hw_common(priv->ah)
{
990 return &(ah->common);;
}
355 common = tmp;
358 ret = 0;
361 unsigned int __CPAchecker_TMP_0 = (unsigned int)(priv->nvifs);
361 assume(!(__CPAchecker_TMP_0 > 1U));
361 unsigned int __CPAchecker_TMP_1 = (unsigned int)(priv->nstations);
361 assume(!(__CPAchecker_TMP_1 > 7U));
367 unsigned long __CPAchecker_TMP_2 = (unsigned long)(priv->sta_slot);
367 -ffz(__CPAchecker_TMP_2)
{
362 Ignored inline assembler code
365 return word;;
}
367 sta_idx = (int)tmp___0;
368 assume(!(sta_idx < 0));
368 assume(!(sta_idx > 8));
376 __memset((void *)(&hvif), 0, 12UL) { /* Function call is skipped due to function is undefined */}
377 __memcpy((void *)(&(hvif.myaddr)), (const void *)(&(common->macaddr)), 6UL) { /* Function call is skipped due to function is undefined */}
379 hvif.opmode = 8U;
380 unsigned long __CPAchecker_TMP_3 = (unsigned long)(priv->vif_slot);
380 -ffz(__CPAchecker_TMP_3)
{
362 Ignored inline assembler code
365 return word;;
}
380 hvif.index = (u8 )tmp___1;
382 -ath9k_wmi_cmd(priv->wmi, 19, (u8 *)(&hvif), 12U, &cmd_rsp, 1U, 500U)
{
294 struct ath_hw *ah;
295 struct ath_common *common;
296 struct ath_common *tmp;
297 unsigned short headroom;
298 struct sk_buff *skb;
299 u8 *data;
300 unsigned long time_left;
301 int ret;
302 unsigned char *tmp___0;
303 long tmp___1;
304 const char *tmp___2;
305 const char *tmp___3;
296 ah = wmi->drv_priv->ah;
297 -ath9k_hw_common(ah)
{
990 return &(ah->common);;
}
297 common = tmp;
298 headroom = 12U;
303 ret = 0;
305 assume(!(((ah->ah_flags) & 2U) != 0U));
308 -alloc_skb(((u32 )headroom) + cmd_len, 34078752U)
{
894 struct sk_buff *tmp;
895 tmp = __alloc_skb(size, priority, 0, -1) { /* Function call is skipped due to function is undefined */}
895 return tmp;;
}
309 assume(!(((unsigned long)skb) == ((unsigned long)((struct sk_buff *)0))));
312 -skb_reserve(skb, (int)headroom)
{
1984 skb->data = (skb->data) + ((unsigned long)len);
1985 skb->tail = (skb->tail) + ((sk_buff_data_t )len);
1986 return ;;
}
314 assume(cmd_len != 0U);
314 assume(((unsigned long)cmd_buf) != ((unsigned long)((u8 *)0U)));
315 tmp___0 = skb_put(skb, cmd_len) { /* Function call is skipped due to function is undefined */}
315 data = tmp___0;
316 __memcpy((void *)data, (const void *)cmd_buf, (size_t )cmd_len) { /* Function call is skipped due to function is undefined */}
319 -ldv_mutex_lock_217(&(wmi->op_mutex))
{
/*Change states for locks mutex_lock(char *"_op_mutex_of_wmi")*/
610 ldv_mutex_lock(ldv_func_arg1, (char *)"_op_mutex_of_wmi") { /* Function call is skipped due to function is undefined */}
611 return ;;
}
322 long __CPAchecker_TMP_0 = (long)(wmi->stopped);
322 -__builtin_expect(__CPAchecker_TMP_0, 0L)
{
52 return exp;;
}
322 assume(!(tmp___1 != 0L));
328 wmi->cmd_rsp_buf = rsp_buf;
329 wmi->cmd_rsp_len = rsp_len;
331 -ath9k_wmi_cmd_issue(wmi, skb, cmd_id, (int)((u16 )cmd_len))
{
276 struct wmi_cmd_hdr *hdr;
277 unsigned long flags;
278 unsigned char *tmp;
279 unsigned short tmp___0;
280 unsigned short tmp___1;
281 int tmp___2;
280 tmp = skb_push(skb, 4U) { /* Function call is skipped due to function is undefined */}
280 hdr = (struct wmi_cmd_hdr *)tmp;
281 -__fswab16((int)((__u16 )cmd))
{
53 return (__u16 )(((int)((short)(((int)val) << 8))) | ((int)((short)(((int)val) >> 8))));;
}
281 hdr->command_id = tmp___0;
282 int __CPAchecker_TMP_0 = (int)(wmi->tx_seq_id);
282 wmi->tx_seq_id = (u16 )(__CPAchecker_TMP_0 + 1);
282 int __CPAchecker_TMP_1 = (int)(wmi->tx_seq_id);
282 -__fswab16(__CPAchecker_TMP_1)
{
53 return (__u16 )(((int)((short)(((int)val) << 8))) | ((int)((short)(((int)val) >> 8))));;
}
282 hdr->seq_no = tmp___1;
284 -ldv___ldv_spin_lock_215(&(wmi->wmi_lock))
{
/*Change states for locks spin_lock(char *"_wmi_lock_of_wmi")*/
598 ldv_spin_lock(ldv_func_arg1, (char *)"_wmi_lock_of_wmi") { /* Function call is skipped due to function is undefined */}
599 return ;;
}
285 wmi->last_seq_id = wmi->tx_seq_id;
286 -ldv_spin_unlock_irqrestore_203(&(wmi->wmi_lock), flags)
{
/*Change states for locks spin_lock(char *"_wmi_lock_of_wmi")*/
526 ldv_spin_unlock(lock, (char *)"_wmi_lock_of_wmi") { /* Function call is skipped due to function is undefined */}
527 return ;;
}
288 -htc_send_epid(wmi->htc, skb, wmi->ctrl_epid)
{
304 int tmp;
305 u16 __CPAchecker_TMP_0 = (u16 )(skb->len);
305 -htc_issue_send(target, skb, (int)__CPAchecker_TMP_0, 0, (int)((u8 )epid))
{
24 struct htc_frame_hdr *hdr;
25 struct htc_endpoint *endpoint;
26 int status;
27 unsigned char *tmp;
28 unsigned short tmp___0;
26 endpoint = ((struct htc_endpoint *)(&(target->endpoint))) + ((unsigned long)epid);
29 tmp = skb_push(skb, 8U) { /* Function call is skipped due to function is undefined */}
29 hdr = (struct htc_frame_hdr *)tmp;
31 hdr->endpoint_id = epid;
32 hdr->flags = flags;
33 -__fswab16((int)len)
{
53 return (__u16 )(((int)((short)(((int)val) << 8))) | ((int)((short)(((int)val) >> 8))));;
}
33 hdr->payload_len = tmp___0;
35 int __CPAchecker_TMP_0 = (int)(endpoint->ul_pipeid);
35 status = (*(target->hif->send))(target->hif_dev, __CPAchecker_TMP_0, skb);
37 return status;;
}
305 return tmp;;
}
288 return tmp___2;;
}
332 assume(!(ret != 0));
335 time_left = wait_for_completion_timeout(&(wmi->cmd_wait), (unsigned long)timeout) { /* Function call is skipped due to function is undefined */}
336 assume(!(time_left == 0UL));
343 -ldv_mutex_unlock_219(&(wmi->op_mutex))
{
/*Change states for locks mutex_lock(char *"_op_mutex_of_wmi")*/
622 ldv_mutex_unlock(ldv_func_arg1, (char *)"_op_mutex_of_wmi") { /* Function call is skipped due to function is undefined */}
623 return ;;
}
345 return 0;;
}
383 assume(!(ret != 0));
390 priv->mon_vif_idx = hvif.index;
391 signed char __CPAchecker_TMP_4 = (signed char)(priv->vif_slot);
391 priv->vif_slot = (u8 )(((int)__CPAchecker_TMP_4) | ((int)((signed char)(1 << ((int)(hvif.index))))));
397 unsigned int __CPAchecker_TMP_5 = (unsigned int)(priv->nvifs);
397 assume(!(__CPAchecker_TMP_5 == 0U));
400 int __CPAchecker_TMP_6 = (int)(priv->nvifs);
400 priv->nvifs = (u16 )(__CPAchecker_TMP_6 + 1);
405 __memset((void *)(&tsta), 0, 22UL) { /* Function call is skipped due to function is undefined */}
407 __memcpy((void *)(&(tsta.macaddr)), (const void *)(&(common->macaddr)), 6UL) { /* Function call is skipped due to function is undefined */}
409 tsta.is_vif_sta = 1U;
410 tsta.sta_index = (u8 )sta_idx;
411 tsta.vif_index = hvif.index;
412 tsta.maxampdu = 65535U;
414 -ath9k_wmi_cmd(priv->wmi, 16, (u8 *)(&tsta), 22U, &cmd_rsp, 1U, 500U)
{
294 struct ath_hw *ah;
295 struct ath_common *common;
296 struct ath_common *tmp;
297 unsigned short headroom;
298 struct sk_buff *skb;
299 u8 *data;
300 unsigned long time_left;
301 int ret;
302 unsigned char *tmp___0;
303 long tmp___1;
304 const char *tmp___2;
305 const char *tmp___3;
296 ah = wmi->drv_priv->ah;
297 -ath9k_hw_common(ah)
{
990 return &(ah->common);;
}
297 common = tmp;
298 headroom = 12U;
303 ret = 0;
305 assume(!(((ah->ah_flags) & 2U) != 0U));
308 -alloc_skb(((u32 )headroom) + cmd_len, 34078752U)
{
894 struct sk_buff *tmp;
895 tmp = __alloc_skb(size, priority, 0, -1) { /* Function call is skipped due to function is undefined */}
895 return tmp;;
}
309 assume(!(((unsigned long)skb) == ((unsigned long)((struct sk_buff *)0))));
312 -skb_reserve(skb, (int)headroom)
{
1984 skb->data = (skb->data) + ((unsigned long)len);
1985 skb->tail = (skb->tail) + ((sk_buff_data_t )len);
1986 return ;;
}
314 assume(cmd_len != 0U);
314 assume(((unsigned long)cmd_buf) != ((unsigned long)((u8 *)0U)));
315 tmp___0 = skb_put(skb, cmd_len) { /* Function call is skipped due to function is undefined */}
315 data = tmp___0;
316 __memcpy((void *)data, (const void *)cmd_buf, (size_t )cmd_len) { /* Function call is skipped due to function is undefined */}
319 -ldv_mutex_lock_217(&(wmi->op_mutex))
{
/*Change states for locks mutex_lock(char *"_op_mutex_of_wmi")*/
610 ldv_mutex_lock(ldv_func_arg1, (char *)"_op_mutex_of_wmi") { /* Function call is skipped due to function is undefined */}
611 return ;;
}
322 long __CPAchecker_TMP_0 = (long)(wmi->stopped);
322 -__builtin_expect(__CPAchecker_TMP_0, 0L)
{
52 return exp;;
}
322 assume(!(tmp___1 != 0L));
328 wmi->cmd_rsp_buf = rsp_buf;
329 wmi->cmd_rsp_len = rsp_len;
331 -ath9k_wmi_cmd_issue(wmi, skb, cmd_id, (int)((u16 )cmd_len))
{
276 struct wmi_cmd_hdr *hdr;
277 unsigned long flags;
278 unsigned char *tmp;
279 unsigned short tmp___0;
280 unsigned short tmp___1;
281 int tmp___2;
280 tmp = skb_push(skb, 4U) { /* Function call is skipped due to function is undefined */}
280 hdr = (struct wmi_cmd_hdr *)tmp;
281 -__fswab16((int)((__u16 )cmd))
{
53 return (__u16 )(((int)((short)(((int)val) << 8))) | ((int)((short)(((int)val) >> 8))));;
}
281 hdr->command_id = tmp___0;
282 int __CPAchecker_TMP_0 = (int)(wmi->tx_seq_id);
282 wmi->tx_seq_id = (u16 )(__CPAchecker_TMP_0 + 1);
282 int __CPAchecker_TMP_1 = (int)(wmi->tx_seq_id);
282 -__fswab16(__CPAchecker_TMP_1)
{
53 return (__u16 )(((int)((short)(((int)val) << 8))) | ((int)((short)(((int)val) >> 8))));;
}
282 hdr->seq_no = tmp___1;
284 -ldv___ldv_spin_lock_215(&(wmi->wmi_lock))
{
/*Change states for locks spin_lock(char *"_wmi_lock_of_wmi")*/
598 ldv_spin_lock(ldv_func_arg1, (char *)"_wmi_lock_of_wmi") { /* Function call is skipped due to function is undefined */}
599 return ;;
}
285 wmi->last_seq_id = wmi->tx_seq_id;
286 -ldv_spin_unlock_irqrestore_203(&(wmi->wmi_lock), flags)
{
/*Change states for locks spin_lock(char *"_wmi_lock_of_wmi")*/
526 ldv_spin_unlock(lock, (char *)"_wmi_lock_of_wmi") { /* Function call is skipped due to function is undefined */}
527 return ;;
}
288 -htc_send_epid(wmi->htc, skb, wmi->ctrl_epid)
{
304 int tmp;
305 u16 __CPAchecker_TMP_0 = (u16 )(skb->len);
305 -htc_issue_send(target, skb, (int)__CPAchecker_TMP_0, 0, (int)((u8 )epid))
{
24 struct htc_frame_hdr *hdr;
25 struct htc_endpoint *endpoint;
26 int status;
27 unsigned char *tmp;
28 unsigned short tmp___0;
26 endpoint = ((struct htc_endpoint *)(&(target->endpoint))) + ((unsigned long)epid);
29 tmp = skb_push(skb, 8U) { /* Function call is skipped due to function is undefined */}
29 hdr = (struct htc_frame_hdr *)tmp;
31 hdr->endpoint_id = epid;
32 hdr->flags = flags;
33 -__fswab16((int)len)
{
53 return (__u16 )(((int)((short)(((int)val) << 8))) | ((int)((short)(((int)val) >> 8))));;
}
33 hdr->payload_len = tmp___0;
35 int __CPAchecker_TMP_0 = (int)(endpoint->ul_pipeid);
35 status = (*(target->hif->send))(target->hif_dev, __CPAchecker_TMP_0, skb);
37 return status;;
}
305 return tmp;;
}
288 return tmp___2;;
}
332 assume(!(ret != 0));
335 time_left = wait_for_completion_timeout(&(wmi->cmd_wait), (unsigned long)timeout) { /* Function call is skipped due to function is undefined */}
336 assume(!(time_left == 0UL));
343 -ldv_mutex_unlock_219(&(wmi->op_mutex))
{
/*Change states for locks mutex_lock(char *"_op_mutex_of_wmi")*/
622 ldv_mutex_unlock(ldv_func_arg1, (char *)"_op_mutex_of_wmi") { /* Function call is skipped due to function is undefined */}
623 return ;;
}
345 return 0;;
}
415 assume(!(ret != 0));
420 signed char __CPAchecker_TMP_7 = (signed char)(priv->sta_slot);
420 priv->sta_slot = (u8 )(((int)__CPAchecker_TMP_7) | ((int)((signed char)(1 << sta_idx))));
421 int __CPAchecker_TMP_8 = (int)(priv->nstations);
421 priv->nstations = (u16 )(__CPAchecker_TMP_8 + 1);
422 int __CPAchecker_TMP_9 = (int)(priv->mon_vif_idx);
422 (priv->vif_sta_pos)[__CPAchecker_TMP_9] = (u8 )sta_idx;
423 priv->ah->is_monitoring = 1;
425 assume(!(((common->debug_mask) & 512) != 0));
return ;;
}
return ;;
}
return ;;
}
return ;;
}
/*_____________________*/
/*Without locks*/
-__CPAchecker_initialize()
{
return ;
}
-entry_point
{
323 unsigned int ldvarg104;
324 int *ldvarg105;
325 u16 *ldvarg103;
326 int tmp;
327 int tmp___0;
328 int tmp___1;
329 int tmp___2;
322 ldv_initialize() { /* Function call is skipped due to function is undefined */}
328 ldv_state_variable_6 = 0;
329 ldv_state_variable_11 = 0;
330 ldv_state_variable_3 = 0;
331 ldv_state_variable_7 = 0;
332 ldv_state_variable_9 = 0;
333 ldv_state_variable_12 = 0;
334 ldv_state_variable_2 = 0;
335 ldv_state_variable_14 = 0;
336 ldv_state_variable_8 = 0;
338 -timer_init_1()
{
179 ldv_timer_1_0 = 0;
180 ldv_timer_1_1 = 0;
181 ldv_timer_1_2 = 0;
182 ldv_timer_1_3 = 0;
183 return ;;
}
340 ldv_state_variable_1 = 1;
341 ldv_state_variable_4 = 0;
342 ref_cnt = 0;
343 ldv_state_variable_0 = 1;
344 ldv_state_variable_13 = 0;
345 ldv_state_variable_10 = 0;
346 ldv_state_variable_5 = 0;
347 ldv_57990:;
348 tmp = __VERIFIER_nondet_int() { /* Function call is skipped due to function is undefined */}
348 switch (tmp);
349 assume(!(tmp == 0));
357 assume(!(tmp == 1));
387 assume(!(tmp == 2));
395 assume(!(tmp == 3));
403 assume(!(tmp == 4));
411 assume(tmp == 5);
414 assume(ldv_state_variable_12 != 0);
415 -ldv_main_exported_12()
{
147 struct ieee80211_vif *ldvarg75;
148 struct ieee80211_tx_control *ldvarg52;
149 int ldvarg74;
150 struct ieee80211_vif *ldvarg22;
151 struct ieee80211_vif *ldvarg25;
152 struct ieee80211_bss_conf *ldvarg61;
153 struct ieee80211_vif *ldvarg54;
154 struct ieee80211_sta *ldvarg21;
155 unsigned int ldvarg30;
156 struct ieee80211_vif *ldvarg68;
157 const struct cfg80211_bitrate_mask *ldvarg70;
158 struct ieee80211_vif *ldvarg73;
159 unsigned int ldvarg26;
160 u8 *ldvarg27;
161 unsigned int ldvarg63;
162 unsigned short ldvarg45;
163 enum ieee80211_ampdu_mlme_action ldvarg40;
164 u64 *ldvarg36;
165 struct ieee80211_vif *ldvarg55;
166 struct ieee80211_sta *ldvarg66;
167 struct ieee80211_vif *ldvarg57;
168 enum set_key_cmd ldvarg65;
169 struct ieee80211_vif *ldvarg62;
170 unsigned long long ldvarg49;
171 u32 *ldvarg59;
172 unsigned char ldvarg41;
173 u32 *ldvarg60;
174 struct ieee80211_vif *ldvarg31;
175 struct ieee80211_vif *ldvarg20;
176 u16 *ldvarg39;
177 struct ieee80211_vif *ldvarg47;
178 unsigned int *ldvarg34;
179 struct ieee80211_vif *ldvarg28;
180 unsigned int ldvarg48;
181 unsigned long long ldvarg33;
182 short ldvarg69;
183 struct ieee80211_vif *ldvarg38;
184 unsigned int ldvarg35;
185 struct ieee80211_vif *ldvarg24;
186 struct ieee80211_sta *ldvarg44;
187 u8 *ldvarg29;
188 struct ieee80211_vif *ldvarg64;
189 struct ieee80211_sta *ldvarg53;
190 struct ethtool_stats *ldvarg37;
191 const struct ieee80211_tx_queue_params *ldvarg58;
192 struct ieee80211_sta *ldvarg46;
193 struct ieee80211_vif *ldvarg50;
194 unsigned short ldvarg56;
195 unsigned int ldvarg72;
196 struct ieee80211_vif *ldvarg71;
197 struct ieee80211_vif *ldvarg42;
198 _Bool ldvarg43;
199 struct cfg80211_chan_def *ldvarg23;
200 struct ieee80211_key_conf *ldvarg67;
201 struct ieee80211_low_level_stats *ldvarg32;
202 struct sk_buff *ldvarg51;
203 int tmp;
204 int tmp___0;
205 int tmp___1;
206 int tmp___2;
207 int tmp___3;
208 int tmp___4;
209 int tmp___5;
203 tmp = __VERIFIER_nondet_int() { /* Function call is skipped due to function is undefined */}
203 switch (tmp);
204 assume(!(tmp == 0));
221 assume(!(tmp == 1));
238 assume(!(tmp == 2));
251 assume(!(tmp == 3));
268 assume(!(tmp == 4));
285 assume(!(tmp == 5));
302 assume(!(tmp == 6));
319 assume(!(tmp == 7));
329 assume(!(tmp == 8));
346 assume(!(tmp == 9));
363 assume(!(tmp == 10));
380 assume(!(tmp == 11));
397 assume(!(tmp == 12));
409 assume(!(tmp == 13));
426 assume(tmp == 14);
428 assume(ldv_state_variable_12 == 1);
430 -ath9k_htc_tx(ath9k_htc_ops_group0, ldvarg52, ldvarg51)
{
868 struct ieee80211_hdr *hdr;
869 struct ath9k_htc_priv *priv;
870 struct ath_common *common;
871 struct ath_common *tmp;
872 int padpos;
873 int padsize;
874 int ret;
875 int slot;
876 unsigned int tmp___0;
877 unsigned int tmp___1;
870 struct ath9k_htc_priv *__CPAchecker_TMP_0 = (struct ath9k_htc_priv *)(hw->priv);
870 priv = __CPAchecker_TMP_0;
871 -ath9k_hw_common(priv->ah)
{
990 return &(ah->common);;
}
871 common = tmp;
874 struct ieee80211_hdr *__CPAchecker_TMP_1 = (struct ieee80211_hdr *)(skb->data);
874 hdr = __CPAchecker_TMP_1;
877 int __CPAchecker_TMP_2 = (int)(hdr->frame_control);
877 tmp___0 = ieee80211_hdrlen(__CPAchecker_TMP_2) { /* Function call is skipped due to function is undefined */}
877 padpos = (int)tmp___0;
878 padsize = padpos & 3;
879 assume(!(padsize != 0));
888 -ath9k_htc_tx_get_slot(priv)
{
81 int slot;
82 unsigned long tmp;
83 -ldv_spin_lock_bh_207(&(priv->tx.tx_lock))
{
/*Change states for locks spin_lock(char *"_tx_lock_of_ath9k_htc_tx")*/
550 ldv_spin_lock(lock, (char *)"_tx_lock_of_ath9k_htc_tx") { /* Function call is skipped due to function is undefined */}
551 return ;;
}
84 tmp = find_first_zero_bit((const unsigned long *)(&(priv->tx.tx_slot)), 256UL) { /* Function call is skipped due to function is undefined */}
84 slot = (int)tmp;
85 assume(!(slot > 255));
89 -__set_bit((long)slot, (volatile unsigned long *)(&(priv->tx.tx_slot)))
{
96 Ignored inline assembler code
97 return ;;
}
90 -ldv_spin_unlock_bh_208(&(priv->tx.tx_lock))
{
/*Change states for locks spin_lock(char *"_tx_lock_of_ath9k_htc_tx")*/
556 ldv_spin_unlock(lock, (char *)"_tx_lock_of_ath9k_htc_tx") { /* Function call is skipped due to function is undefined */}
557 return ;;
}
92 return slot;;
}
889 assume(!(slot < 0));
894 -ath9k_htc_tx_start(priv, control->sta, skb, (int)((u8 )slot), 0)
{
338 struct ieee80211_hdr *hdr;
339 struct ieee80211_tx_info *tx_info;
340 struct ieee80211_tx_info *tmp;
341 struct ieee80211_vif *vif;
342 struct ath9k_htc_sta *ista;
343 struct ath9k_htc_vif *avp;
344 unsigned char sta_idx;
345 unsigned char vif_idx;
346 struct ath_common *tmp___0;
347 struct ath_common *tmp___1;
348 _Bool tmp___2;
349 int tmp___3;
341 -IEEE80211_SKB_CB(skb)
{
925 return (struct ieee80211_tx_info *)(&(skb->cb));;
}
341 tx_info = tmp;
342 vif = tx_info->__annonCompField107.control.vif;
344 avp = (struct ath9k_htc_vif *)0;
347 struct ieee80211_hdr *__CPAchecker_TMP_0 = (struct ieee80211_hdr *)(skb->data);
347 hdr = __CPAchecker_TMP_0;
353 assume(!(((unsigned long)vif) != ((unsigned long)((struct ieee80211_vif *)0))));
357 assume(!((priv->ah->is_monitoring) == 0));
363 vif_idx = priv->mon_vif_idx;
369 assume(!(((unsigned long)sta) != ((unsigned long)((struct ieee80211_sta *)0))));
373 sta_idx = (priv->vif_sta_pos)[(int)vif_idx];
return ;;
}
return ;;
}
return ;;
}
return ;;
}
Source code
1 /* 2 * Copyright (c) 2010-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include <asm/unaligned.h> 18 #include "htc.h" 19 20 MODULE_FIRMWARE(HTC_7010_MODULE_FW); 21 MODULE_FIRMWARE(HTC_9271_MODULE_FW); 22 23 static struct usb_device_id ath9k_hif_usb_ids[] = { 24 { USB_DEVICE(0x0cf3, 0x9271) }, /* Atheros */ 25 { USB_DEVICE(0x0cf3, 0x1006) }, /* Atheros */ 26 { USB_DEVICE(0x0846, 0x9030) }, /* Netgear N150 */ 27 { USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */ 28 { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */ 29 { USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */ 30 { USB_DEVICE(0x13D3, 0x3346) }, /* IMC Networks */ 31 { USB_DEVICE(0x13D3, 0x3348) }, /* Azurewave */ 32 { USB_DEVICE(0x13D3, 0x3349) }, /* Azurewave */ 33 { USB_DEVICE(0x13D3, 0x3350) }, /* Azurewave */ 34 { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */ 35 { USB_DEVICE(0x040D, 0x3801) }, /* VIA */ 36 { USB_DEVICE(0x0cf3, 0xb003) }, /* Ubiquiti WifiStation Ext */ 37 { USB_DEVICE(0x0cf3, 0xb002) }, /* Ubiquiti WifiStation */ 38 { USB_DEVICE(0x057c, 0x8403) }, /* AVM FRITZ!WLAN 11N v2 USB */ 39 { USB_DEVICE(0x0471, 0x209e) }, /* Philips (or NXP) PTA01 */ 40 41 { USB_DEVICE(0x0cf3, 0x7015), 42 .driver_info = AR9287_USB }, /* Atheros */ 43 { USB_DEVICE(0x1668, 0x1200), 44 .driver_info = AR9287_USB }, /* Verizon */ 45 46 { USB_DEVICE(0x0cf3, 0x7010), 47 .driver_info = AR9280_USB }, /* Atheros */ 48 { USB_DEVICE(0x0846, 0x9018), 49 .driver_info = AR9280_USB }, /* Netgear WNDA3200 */ 50 { USB_DEVICE(0x083A, 0xA704), 51 .driver_info = AR9280_USB }, /* SMC Networks */ 52 { USB_DEVICE(0x0411, 0x017f), 53 .driver_info = AR9280_USB }, /* Sony UWA-BR100 */ 54 { USB_DEVICE(0x0411, 0x0197), 55 .driver_info = AR9280_USB }, /* Buffalo WLI-UV-AG300P */ 56 { USB_DEVICE(0x04da, 0x3904), 57 .driver_info = AR9280_USB }, 58 59 { USB_DEVICE(0x0cf3, 0x20ff), 60 .driver_info = STORAGE_DEVICE }, 61 62 { }, 63 }; 64 65 MODULE_DEVICE_TABLE(usb, ath9k_hif_usb_ids); 66 67 static int __hif_usb_tx(struct hif_device_usb *hif_dev); 68 69 static void hif_usb_regout_cb(struct urb *urb) 70 { 71 struct cmd_buf *cmd = (struct cmd_buf *)urb->context; 72 73 switch (urb->status) { 74 case 0: 75 break; 76 case -ENOENT: 77 case -ECONNRESET: 78 case -ENODEV: 79 case -ESHUTDOWN: 80 goto free; 81 default: 82 break; 83 } 84 85 if (cmd) { 86 ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle, 87 cmd->skb, true); 88 kfree(cmd); 89 } 90 91 return; 92 free: 93 kfree_skb(cmd->skb); 94 kfree(cmd); 95 } 96 97 static int hif_usb_send_regout(struct hif_device_usb *hif_dev, 98 struct sk_buff *skb) 99 { 100 struct urb *urb; 101 struct cmd_buf *cmd; 102 int ret = 0; 103 104 urb = usb_alloc_urb(0, GFP_KERNEL); 105 if (urb == NULL) 106 return -ENOMEM; 107 108 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 109 if (cmd == NULL) { 110 usb_free_urb(urb); 111 return -ENOMEM; 112 } 113 114 cmd->skb = skb; 115 cmd->hif_dev = hif_dev; 116 117 usb_fill_int_urb(urb, hif_dev->udev, 118 usb_sndintpipe(hif_dev->udev, USB_REG_OUT_PIPE), 119 skb->data, skb->len, 120 hif_usb_regout_cb, cmd, 1); 121 122 usb_anchor_urb(urb, &hif_dev->regout_submitted); 123 ret = usb_submit_urb(urb, GFP_KERNEL); 124 if (ret) { 125 usb_unanchor_urb(urb); 126 kfree(cmd); 127 } 128 usb_free_urb(urb); 129 130 return ret; 131 } 132 133 static void hif_usb_mgmt_cb(struct urb *urb) 134 { 135 struct cmd_buf *cmd = (struct cmd_buf *)urb->context; 136 struct hif_device_usb *hif_dev; 137 bool txok = true; 138 139 if (!cmd || !cmd->skb || !cmd->hif_dev) 140 return; 141 142 hif_dev = cmd->hif_dev; 143 144 switch (urb->status) { 145 case 0: 146 break; 147 case -ENOENT: 148 case -ECONNRESET: 149 case -ENODEV: 150 case -ESHUTDOWN: 151 txok = false; 152 153 /* 154 * If the URBs are being flushed, no need to complete 155 * this packet. 156 */ 157 spin_lock(&hif_dev->tx.tx_lock); 158 if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) { 159 spin_unlock(&hif_dev->tx.tx_lock); 160 dev_kfree_skb_any(cmd->skb); 161 kfree(cmd); 162 return; 163 } 164 spin_unlock(&hif_dev->tx.tx_lock); 165 166 break; 167 default: 168 txok = false; 169 break; 170 } 171 172 skb_pull(cmd->skb, 4); 173 ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle, 174 cmd->skb, txok); 175 kfree(cmd); 176 } 177 178 static int hif_usb_send_mgmt(struct hif_device_usb *hif_dev, 179 struct sk_buff *skb) 180 { 181 struct urb *urb; 182 struct cmd_buf *cmd; 183 int ret = 0; 184 __le16 *hdr; 185 186 urb = usb_alloc_urb(0, GFP_ATOMIC); 187 if (urb == NULL) 188 return -ENOMEM; 189 190 cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC); 191 if (cmd == NULL) { 192 usb_free_urb(urb); 193 return -ENOMEM; 194 } 195 196 cmd->skb = skb; 197 cmd->hif_dev = hif_dev; 198 199 hdr = (__le16 *) skb_push(skb, 4); 200 *hdr++ = cpu_to_le16(skb->len - 4); 201 *hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG); 202 203 usb_fill_bulk_urb(urb, hif_dev->udev, 204 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE), 205 skb->data, skb->len, 206 hif_usb_mgmt_cb, cmd); 207 208 usb_anchor_urb(urb, &hif_dev->mgmt_submitted); 209 ret = usb_submit_urb(urb, GFP_ATOMIC); 210 if (ret) { 211 usb_unanchor_urb(urb); 212 kfree(cmd); 213 } 214 usb_free_urb(urb); 215 216 return ret; 217 } 218 219 static inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev, 220 struct sk_buff_head *list) 221 { 222 struct sk_buff *skb; 223 224 while ((skb = __skb_dequeue(list)) != NULL) { 225 dev_kfree_skb_any(skb); 226 } 227 } 228 229 static inline void ath9k_skb_queue_complete(struct hif_device_usb *hif_dev, 230 struct sk_buff_head *queue, 231 bool txok) 232 { 233 struct sk_buff *skb; 234 235 while ((skb = __skb_dequeue(queue)) != NULL) { 236 #ifdef CONFIG_ATH9K_HTC_DEBUGFS 237 int ln = skb->len; 238 #endif 239 ath9k_htc_txcompletion_cb(hif_dev->htc_handle, 240 skb, txok); 241 if (txok) { 242 TX_STAT_INC(skb_success); 243 TX_STAT_ADD(skb_success_bytes, ln); 244 } 245 else 246 TX_STAT_INC(skb_failed); 247 } 248 } 249 250 static void hif_usb_tx_cb(struct urb *urb) 251 { 252 struct tx_buf *tx_buf = (struct tx_buf *) urb->context; 253 struct hif_device_usb *hif_dev; 254 bool txok = true; 255 256 if (!tx_buf || !tx_buf->hif_dev) 257 return; 258 259 hif_dev = tx_buf->hif_dev; 260 261 switch (urb->status) { 262 case 0: 263 break; 264 case -ENOENT: 265 case -ECONNRESET: 266 case -ENODEV: 267 case -ESHUTDOWN: 268 txok = false; 269 270 /* 271 * If the URBs are being flushed, no need to add this 272 * URB to the free list. 273 */ 274 spin_lock(&hif_dev->tx.tx_lock); 275 if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) { 276 spin_unlock(&hif_dev->tx.tx_lock); 277 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue); 278 return; 279 } 280 spin_unlock(&hif_dev->tx.tx_lock); 281 282 break; 283 default: 284 txok = false; 285 break; 286 } 287 288 ath9k_skb_queue_complete(hif_dev, &tx_buf->skb_queue, txok); 289 290 /* Re-initialize the SKB queue */ 291 tx_buf->len = tx_buf->offset = 0; 292 __skb_queue_head_init(&tx_buf->skb_queue); 293 294 /* Add this TX buffer to the free list */ 295 spin_lock(&hif_dev->tx.tx_lock); 296 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf); 297 hif_dev->tx.tx_buf_cnt++; 298 if (!(hif_dev->tx.flags & HIF_USB_TX_STOP)) 299 __hif_usb_tx(hif_dev); /* Check for pending SKBs */ 300 TX_STAT_INC(buf_completed); 301 spin_unlock(&hif_dev->tx.tx_lock); 302 } 303 304 /* TX lock has to be taken */ 305 static int __hif_usb_tx(struct hif_device_usb *hif_dev) 306 { 307 struct tx_buf *tx_buf = NULL; 308 struct sk_buff *nskb = NULL; 309 int ret = 0, i; 310 u16 tx_skb_cnt = 0; 311 u8 *buf; 312 __le16 *hdr; 313 314 if (hif_dev->tx.tx_skb_cnt == 0) 315 return 0; 316 317 /* Check if a free TX buffer is available */ 318 if (list_empty(&hif_dev->tx.tx_buf)) 319 return 0; 320 321 tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list); 322 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_pending); 323 hif_dev->tx.tx_buf_cnt--; 324 325 tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM); 326 327 for (i = 0; i < tx_skb_cnt; i++) { 328 nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue); 329 330 /* Should never be NULL */ 331 BUG_ON(!nskb); 332 333 hif_dev->tx.tx_skb_cnt--; 334 335 buf = tx_buf->buf; 336 buf += tx_buf->offset; 337 hdr = (__le16 *)buf; 338 *hdr++ = cpu_to_le16(nskb->len); 339 *hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG); 340 buf += 4; 341 memcpy(buf, nskb->data, nskb->len); 342 tx_buf->len = nskb->len + 4; 343 344 if (i < (tx_skb_cnt - 1)) 345 tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4; 346 347 if (i == (tx_skb_cnt - 1)) 348 tx_buf->len += tx_buf->offset; 349 350 __skb_queue_tail(&tx_buf->skb_queue, nskb); 351 TX_STAT_INC(skb_queued); 352 } 353 354 usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev, 355 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE), 356 tx_buf->buf, tx_buf->len, 357 hif_usb_tx_cb, tx_buf); 358 359 ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC); 360 if (ret) { 361 tx_buf->len = tx_buf->offset = 0; 362 ath9k_skb_queue_complete(hif_dev, &tx_buf->skb_queue, false); 363 __skb_queue_head_init(&tx_buf->skb_queue); 364 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf); 365 hif_dev->tx.tx_buf_cnt++; 366 } 367 368 if (!ret) 369 TX_STAT_INC(buf_queued); 370 371 return ret; 372 } 373 374 static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb) 375 { 376 struct ath9k_htc_tx_ctl *tx_ctl; 377 unsigned long flags; 378 int ret = 0; 379 380 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 381 382 if (hif_dev->tx.flags & HIF_USB_TX_STOP) { 383 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 384 return -ENODEV; 385 } 386 387 /* Check if the max queue count has been reached */ 388 if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) { 389 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 390 return -ENOMEM; 391 } 392 393 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 394 395 tx_ctl = HTC_SKB_CB(skb); 396 397 /* Mgmt/Beacon frames don't use the TX buffer pool */ 398 if ((tx_ctl->type == ATH9K_HTC_MGMT) || 399 (tx_ctl->type == ATH9K_HTC_BEACON)) { 400 ret = hif_usb_send_mgmt(hif_dev, skb); 401 } 402 403 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 404 405 if ((tx_ctl->type == ATH9K_HTC_NORMAL) || 406 (tx_ctl->type == ATH9K_HTC_AMPDU)) { 407 __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb); 408 hif_dev->tx.tx_skb_cnt++; 409 } 410 411 /* Check if AMPDUs have to be sent immediately */ 412 if ((hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) && 413 (hif_dev->tx.tx_skb_cnt < 2)) { 414 __hif_usb_tx(hif_dev); 415 } 416 417 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 418 419 return ret; 420 } 421 422 static void hif_usb_start(void *hif_handle) 423 { 424 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; 425 unsigned long flags; 426 427 hif_dev->flags |= HIF_USB_START; 428 429 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 430 hif_dev->tx.flags &= ~HIF_USB_TX_STOP; 431 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 432 } 433 434 static void hif_usb_stop(void *hif_handle) 435 { 436 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; 437 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL; 438 unsigned long flags; 439 440 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 441 ath9k_skb_queue_complete(hif_dev, &hif_dev->tx.tx_skb_queue, false); 442 hif_dev->tx.tx_skb_cnt = 0; 443 hif_dev->tx.flags |= HIF_USB_TX_STOP; 444 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 445 446 /* The pending URBs have to be canceled. */ 447 list_for_each_entry_safe(tx_buf, tx_buf_tmp, 448 &hif_dev->tx.tx_pending, list) { 449 usb_kill_urb(tx_buf->urb); 450 } 451 452 usb_kill_anchored_urbs(&hif_dev->mgmt_submitted); 453 } 454 455 static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb) 456 { 457 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; 458 int ret = 0; 459 460 switch (pipe_id) { 461 case USB_WLAN_TX_PIPE: 462 ret = hif_usb_send_tx(hif_dev, skb); 463 break; 464 case USB_REG_OUT_PIPE: 465 ret = hif_usb_send_regout(hif_dev, skb); 466 break; 467 default: 468 dev_err(&hif_dev->udev->dev, 469 "ath9k_htc: Invalid TX pipe: %d\n", pipe_id); 470 ret = -EINVAL; 471 break; 472 } 473 474 return ret; 475 } 476 477 static inline bool check_index(struct sk_buff *skb, u8 idx) 478 { 479 struct ath9k_htc_tx_ctl *tx_ctl; 480 481 tx_ctl = HTC_SKB_CB(skb); 482 483 if ((tx_ctl->type == ATH9K_HTC_AMPDU) && 484 (tx_ctl->sta_idx == idx)) 485 return true; 486 487 return false; 488 } 489 490 static void hif_usb_sta_drain(void *hif_handle, u8 idx) 491 { 492 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; 493 struct sk_buff *skb, *tmp; 494 unsigned long flags; 495 496 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 497 498 skb_queue_walk_safe(&hif_dev->tx.tx_skb_queue, skb, tmp) { 499 if (check_index(skb, idx)) { 500 __skb_unlink(skb, &hif_dev->tx.tx_skb_queue); 501 ath9k_htc_txcompletion_cb(hif_dev->htc_handle, 502 skb, false); 503 hif_dev->tx.tx_skb_cnt--; 504 TX_STAT_INC(skb_failed); 505 } 506 } 507 508 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 509 } 510 511 static struct ath9k_htc_hif hif_usb = { 512 .transport = ATH9K_HIF_USB, 513 .name = "ath9k_hif_usb", 514 515 .control_ul_pipe = USB_REG_OUT_PIPE, 516 .control_dl_pipe = USB_REG_IN_PIPE, 517 518 .start = hif_usb_start, 519 .stop = hif_usb_stop, 520 .sta_drain = hif_usb_sta_drain, 521 .send = hif_usb_send, 522 }; 523 524 static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev, 525 struct sk_buff *skb) 526 { 527 struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER]; 528 int index = 0, i = 0, len = skb->len; 529 int rx_remain_len, rx_pkt_len; 530 u16 pool_index = 0; 531 u8 *ptr; 532 533 spin_lock(&hif_dev->rx_lock); 534 535 rx_remain_len = hif_dev->rx_remain_len; 536 rx_pkt_len = hif_dev->rx_transfer_len; 537 538 if (rx_remain_len != 0) { 539 struct sk_buff *remain_skb = hif_dev->remain_skb; 540 541 if (remain_skb) { 542 ptr = (u8 *) remain_skb->data; 543 544 index = rx_remain_len; 545 rx_remain_len -= hif_dev->rx_pad_len; 546 ptr += rx_pkt_len; 547 548 memcpy(ptr, skb->data, rx_remain_len); 549 550 rx_pkt_len += rx_remain_len; 551 hif_dev->rx_remain_len = 0; 552 skb_put(remain_skb, rx_pkt_len); 553 554 skb_pool[pool_index++] = remain_skb; 555 556 } else { 557 index = rx_remain_len; 558 } 559 } 560 561 spin_unlock(&hif_dev->rx_lock); 562 563 while (index < len) { 564 u16 pkt_len; 565 u16 pkt_tag; 566 u16 pad_len; 567 int chk_idx; 568 569 ptr = (u8 *) skb->data; 570 571 pkt_len = get_unaligned_le16(ptr + index); 572 pkt_tag = get_unaligned_le16(ptr + index + 2); 573 574 if (pkt_tag != ATH_USB_RX_STREAM_MODE_TAG) { 575 RX_STAT_INC(skb_dropped); 576 return; 577 } 578 579 pad_len = 4 - (pkt_len & 0x3); 580 if (pad_len == 4) 581 pad_len = 0; 582 583 chk_idx = index; 584 index = index + 4 + pkt_len + pad_len; 585 586 if (index > MAX_RX_BUF_SIZE) { 587 spin_lock(&hif_dev->rx_lock); 588 hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE; 589 hif_dev->rx_transfer_len = 590 MAX_RX_BUF_SIZE - chk_idx - 4; 591 hif_dev->rx_pad_len = pad_len; 592 593 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC); 594 if (!nskb) { 595 dev_err(&hif_dev->udev->dev, 596 "ath9k_htc: RX memory allocation error\n"); 597 spin_unlock(&hif_dev->rx_lock); 598 goto err; 599 } 600 skb_reserve(nskb, 32); 601 RX_STAT_INC(skb_allocated); 602 603 memcpy(nskb->data, &(skb->data[chk_idx+4]), 604 hif_dev->rx_transfer_len); 605 606 /* Record the buffer pointer */ 607 hif_dev->remain_skb = nskb; 608 spin_unlock(&hif_dev->rx_lock); 609 } else { 610 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC); 611 if (!nskb) { 612 dev_err(&hif_dev->udev->dev, 613 "ath9k_htc: RX memory allocation error\n"); 614 goto err; 615 } 616 skb_reserve(nskb, 32); 617 RX_STAT_INC(skb_allocated); 618 619 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len); 620 skb_put(nskb, pkt_len); 621 skb_pool[pool_index++] = nskb; 622 } 623 } 624 625 err: 626 for (i = 0; i < pool_index; i++) { 627 RX_STAT_ADD(skb_completed_bytes, skb_pool[i]->len); 628 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i], 629 skb_pool[i]->len, USB_WLAN_RX_PIPE); 630 RX_STAT_INC(skb_completed); 631 } 632 } 633 634 static void ath9k_hif_usb_rx_cb(struct urb *urb) 635 { 636 struct sk_buff *skb = (struct sk_buff *) urb->context; 637 struct hif_device_usb *hif_dev = 638 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); 639 int ret; 640 641 if (!skb) 642 return; 643 644 if (!hif_dev) 645 goto free; 646 647 switch (urb->status) { 648 case 0: 649 break; 650 case -ENOENT: 651 case -ECONNRESET: 652 case -ENODEV: 653 case -ESHUTDOWN: 654 goto free; 655 default: 656 goto resubmit; 657 } 658 659 if (likely(urb->actual_length != 0)) { 660 skb_put(skb, urb->actual_length); 661 ath9k_hif_usb_rx_stream(hif_dev, skb); 662 } 663 664 resubmit: 665 skb_reset_tail_pointer(skb); 666 skb_trim(skb, 0); 667 668 usb_anchor_urb(urb, &hif_dev->rx_submitted); 669 ret = usb_submit_urb(urb, GFP_ATOMIC); 670 if (ret) { 671 usb_unanchor_urb(urb); 672 goto free; 673 } 674 675 return; 676 free: 677 kfree_skb(skb); 678 } 679 680 static void ath9k_hif_usb_reg_in_cb(struct urb *urb) 681 { 682 struct sk_buff *skb = (struct sk_buff *) urb->context; 683 struct sk_buff *nskb; 684 struct hif_device_usb *hif_dev = 685 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); 686 int ret; 687 688 if (!skb) 689 return; 690 691 if (!hif_dev) 692 goto free; 693 694 switch (urb->status) { 695 case 0: 696 break; 697 case -ENOENT: 698 case -ECONNRESET: 699 case -ENODEV: 700 case -ESHUTDOWN: 701 goto free; 702 default: 703 skb_reset_tail_pointer(skb); 704 skb_trim(skb, 0); 705 706 goto resubmit; 707 } 708 709 if (likely(urb->actual_length != 0)) { 710 skb_put(skb, urb->actual_length); 711 712 /* Process the command first */ 713 ath9k_htc_rx_msg(hif_dev->htc_handle, skb, 714 skb->len, USB_REG_IN_PIPE); 715 716 717 nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC); 718 if (!nskb) { 719 dev_err(&hif_dev->udev->dev, 720 "ath9k_htc: REG_IN memory allocation failure\n"); 721 urb->context = NULL; 722 return; 723 } 724 725 usb_fill_int_urb(urb, hif_dev->udev, 726 usb_rcvintpipe(hif_dev->udev, 727 USB_REG_IN_PIPE), 728 nskb->data, MAX_REG_IN_BUF_SIZE, 729 ath9k_hif_usb_reg_in_cb, nskb, 1); 730 } 731 732 resubmit: 733 usb_anchor_urb(urb, &hif_dev->reg_in_submitted); 734 ret = usb_submit_urb(urb, GFP_ATOMIC); 735 if (ret) { 736 usb_unanchor_urb(urb); 737 goto free; 738 } 739 740 return; 741 free: 742 kfree_skb(skb); 743 urb->context = NULL; 744 } 745 746 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev) 747 { 748 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL; 749 unsigned long flags; 750 751 list_for_each_entry_safe(tx_buf, tx_buf_tmp, 752 &hif_dev->tx.tx_buf, list) { 753 usb_kill_urb(tx_buf->urb); 754 list_del(&tx_buf->list); 755 usb_free_urb(tx_buf->urb); 756 kfree(tx_buf->buf); 757 kfree(tx_buf); 758 } 759 760 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 761 hif_dev->tx.flags |= HIF_USB_TX_FLUSH; 762 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 763 764 list_for_each_entry_safe(tx_buf, tx_buf_tmp, 765 &hif_dev->tx.tx_pending, list) { 766 usb_kill_urb(tx_buf->urb); 767 list_del(&tx_buf->list); 768 usb_free_urb(tx_buf->urb); 769 kfree(tx_buf->buf); 770 kfree(tx_buf); 771 } 772 773 usb_kill_anchored_urbs(&hif_dev->mgmt_submitted); 774 } 775 776 static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev) 777 { 778 struct tx_buf *tx_buf; 779 int i; 780 781 INIT_LIST_HEAD(&hif_dev->tx.tx_buf); 782 INIT_LIST_HEAD(&hif_dev->tx.tx_pending); 783 spin_lock_init(&hif_dev->tx.tx_lock); 784 __skb_queue_head_init(&hif_dev->tx.tx_skb_queue); 785 init_usb_anchor(&hif_dev->mgmt_submitted); 786 787 for (i = 0; i < MAX_TX_URB_NUM; i++) { 788 tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL); 789 if (!tx_buf) 790 goto err; 791 792 tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL); 793 if (!tx_buf->buf) 794 goto err; 795 796 tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL); 797 if (!tx_buf->urb) 798 goto err; 799 800 tx_buf->hif_dev = hif_dev; 801 __skb_queue_head_init(&tx_buf->skb_queue); 802 803 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf); 804 } 805 806 hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM; 807 808 return 0; 809 err: 810 if (tx_buf) { 811 kfree(tx_buf->buf); 812 kfree(tx_buf); 813 } 814 ath9k_hif_usb_dealloc_tx_urbs(hif_dev); 815 return -ENOMEM; 816 } 817 818 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev) 819 { 820 usb_kill_anchored_urbs(&hif_dev->rx_submitted); 821 } 822 823 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev) 824 { 825 struct urb *urb = NULL; 826 struct sk_buff *skb = NULL; 827 int i, ret; 828 829 init_usb_anchor(&hif_dev->rx_submitted); 830 spin_lock_init(&hif_dev->rx_lock); 831 832 for (i = 0; i < MAX_RX_URB_NUM; i++) { 833 834 /* Allocate URB */ 835 urb = usb_alloc_urb(0, GFP_KERNEL); 836 if (urb == NULL) { 837 ret = -ENOMEM; 838 goto err_urb; 839 } 840 841 /* Allocate buffer */ 842 skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL); 843 if (!skb) { 844 ret = -ENOMEM; 845 goto err_skb; 846 } 847 848 usb_fill_bulk_urb(urb, hif_dev->udev, 849 usb_rcvbulkpipe(hif_dev->udev, 850 USB_WLAN_RX_PIPE), 851 skb->data, MAX_RX_BUF_SIZE, 852 ath9k_hif_usb_rx_cb, skb); 853 854 /* Anchor URB */ 855 usb_anchor_urb(urb, &hif_dev->rx_submitted); 856 857 /* Submit URB */ 858 ret = usb_submit_urb(urb, GFP_KERNEL); 859 if (ret) { 860 usb_unanchor_urb(urb); 861 goto err_submit; 862 } 863 864 /* 865 * Drop reference count. 866 * This ensures that the URB is freed when killing them. 867 */ 868 usb_free_urb(urb); 869 } 870 871 return 0; 872 873 err_submit: 874 kfree_skb(skb); 875 err_skb: 876 usb_free_urb(urb); 877 err_urb: 878 ath9k_hif_usb_dealloc_rx_urbs(hif_dev); 879 return ret; 880 } 881 882 static void ath9k_hif_usb_dealloc_reg_in_urbs(struct hif_device_usb *hif_dev) 883 { 884 usb_kill_anchored_urbs(&hif_dev->reg_in_submitted); 885 } 886 887 static int ath9k_hif_usb_alloc_reg_in_urbs(struct hif_device_usb *hif_dev) 888 { 889 struct urb *urb = NULL; 890 struct sk_buff *skb = NULL; 891 int i, ret; 892 893 init_usb_anchor(&hif_dev->reg_in_submitted); 894 895 for (i = 0; i < MAX_REG_IN_URB_NUM; i++) { 896 897 /* Allocate URB */ 898 urb = usb_alloc_urb(0, GFP_KERNEL); 899 if (urb == NULL) { 900 ret = -ENOMEM; 901 goto err_urb; 902 } 903 904 /* Allocate buffer */ 905 skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL); 906 if (!skb) { 907 ret = -ENOMEM; 908 goto err_skb; 909 } 910 911 usb_fill_int_urb(urb, hif_dev->udev, 912 usb_rcvintpipe(hif_dev->udev, 913 USB_REG_IN_PIPE), 914 skb->data, MAX_REG_IN_BUF_SIZE, 915 ath9k_hif_usb_reg_in_cb, skb, 1); 916 917 /* Anchor URB */ 918 usb_anchor_urb(urb, &hif_dev->reg_in_submitted); 919 920 /* Submit URB */ 921 ret = usb_submit_urb(urb, GFP_KERNEL); 922 if (ret) { 923 usb_unanchor_urb(urb); 924 goto err_submit; 925 } 926 927 /* 928 * Drop reference count. 929 * This ensures that the URB is freed when killing them. 930 */ 931 usb_free_urb(urb); 932 } 933 934 return 0; 935 936 err_submit: 937 kfree_skb(skb); 938 err_skb: 939 usb_free_urb(urb); 940 err_urb: 941 ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev); 942 return ret; 943 } 944 945 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev) 946 { 947 /* Register Write */ 948 init_usb_anchor(&hif_dev->regout_submitted); 949 950 /* TX */ 951 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0) 952 goto err; 953 954 /* RX */ 955 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0) 956 goto err_rx; 957 958 /* Register Read */ 959 if (ath9k_hif_usb_alloc_reg_in_urbs(hif_dev) < 0) 960 goto err_reg; 961 962 return 0; 963 err_reg: 964 ath9k_hif_usb_dealloc_rx_urbs(hif_dev); 965 err_rx: 966 ath9k_hif_usb_dealloc_tx_urbs(hif_dev); 967 err: 968 return -ENOMEM; 969 } 970 971 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev) 972 { 973 usb_kill_anchored_urbs(&hif_dev->regout_submitted); 974 ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev); 975 ath9k_hif_usb_dealloc_tx_urbs(hif_dev); 976 ath9k_hif_usb_dealloc_rx_urbs(hif_dev); 977 } 978 979 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev) 980 { 981 int transfer, err; 982 const void *data = hif_dev->fw_data; 983 size_t len = hif_dev->fw_size; 984 u32 addr = AR9271_FIRMWARE; 985 u8 *buf = kzalloc(4096, GFP_KERNEL); 986 u32 firm_offset; 987 988 if (!buf) 989 return -ENOMEM; 990 991 while (len) { 992 transfer = min_t(size_t, len, 4096); 993 memcpy(buf, data, transfer); 994 995 err = usb_control_msg(hif_dev->udev, 996 usb_sndctrlpipe(hif_dev->udev, 0), 997 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT, 998 addr >> 8, 0, buf, transfer, HZ); 999 if (err < 0) { 1000 kfree(buf); 1001 return err; 1002 } 1003 1004 len -= transfer; 1005 data += transfer; 1006 addr += transfer; 1007 } 1008 kfree(buf); 1009 1010 if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info)) 1011 firm_offset = AR7010_FIRMWARE_TEXT; 1012 else 1013 firm_offset = AR9271_FIRMWARE_TEXT; 1014 1015 /* 1016 * Issue FW download complete command to firmware. 1017 */ 1018 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0), 1019 FIRMWARE_DOWNLOAD_COMP, 1020 0x40 | USB_DIR_OUT, 1021 firm_offset >> 8, 0, NULL, 0, HZ); 1022 if (err) 1023 return -EIO; 1024 1025 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n", 1026 hif_dev->fw_name, (unsigned long) hif_dev->fw_size); 1027 1028 return 0; 1029 } 1030 1031 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev) 1032 { 1033 int ret; 1034 1035 ret = ath9k_hif_usb_download_fw(hif_dev); 1036 if (ret) { 1037 dev_err(&hif_dev->udev->dev, 1038 "ath9k_htc: Firmware - %s download failed\n", 1039 hif_dev->fw_name); 1040 return ret; 1041 } 1042 1043 /* Alloc URBs */ 1044 ret = ath9k_hif_usb_alloc_urbs(hif_dev); 1045 if (ret) { 1046 dev_err(&hif_dev->udev->dev, 1047 "ath9k_htc: Unable to allocate URBs\n"); 1048 return ret; 1049 } 1050 1051 return 0; 1052 } 1053 1054 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev) 1055 { 1056 ath9k_hif_usb_dealloc_urbs(hif_dev); 1057 } 1058 1059 /* 1060 * If initialization fails or the FW cannot be retrieved, 1061 * detach the device. 1062 */ 1063 static void ath9k_hif_usb_firmware_fail(struct hif_device_usb *hif_dev) 1064 { 1065 struct device *dev = &hif_dev->udev->dev; 1066 struct device *parent = dev->parent; 1067 1068 complete_all(&hif_dev->fw_done); 1069 1070 if (parent) 1071 device_lock(parent); 1072 1073 device_release_driver(dev); 1074 1075 if (parent) 1076 device_unlock(parent); 1077 } 1078 1079 static void ath9k_hif_usb_firmware_cb(const struct firmware *fw, void *context); 1080 1081 /* taken from iwlwifi */ 1082 static int ath9k_hif_request_firmware(struct hif_device_usb *hif_dev, 1083 bool first) 1084 { 1085 char index[8], *chip; 1086 int ret; 1087 1088 if (first) { 1089 if (htc_use_dev_fw) { 1090 hif_dev->fw_minor_index = FIRMWARE_MINOR_IDX_MAX + 1; 1091 sprintf(index, "%s", "dev"); 1092 } else { 1093 hif_dev->fw_minor_index = FIRMWARE_MINOR_IDX_MAX; 1094 sprintf(index, "%d", hif_dev->fw_minor_index); 1095 } 1096 } else { 1097 hif_dev->fw_minor_index--; 1098 sprintf(index, "%d", hif_dev->fw_minor_index); 1099 } 1100 1101 /* test for FW 1.3 */ 1102 if (MAJOR_VERSION_REQ == 1 && hif_dev->fw_minor_index == 3) { 1103 const char *filename; 1104 1105 if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info)) 1106 filename = FIRMWARE_AR7010_1_1; 1107 else 1108 filename = FIRMWARE_AR9271; 1109 1110 /* expected fw locations: 1111 * - htc_9271.fw (stable version 1.3, depricated) 1112 */ 1113 snprintf(hif_dev->fw_name, sizeof(hif_dev->fw_name), 1114 "%s", filename); 1115 1116 } else if (hif_dev->fw_minor_index < FIRMWARE_MINOR_IDX_MIN) { 1117 dev_err(&hif_dev->udev->dev, "no suitable firmware found!\n"); 1118 1119 return -ENOENT; 1120 } else { 1121 if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info)) 1122 chip = "7010"; 1123 else 1124 chip = "9271"; 1125 1126 /* expected fw locations: 1127 * - ath9k_htc/htc_9271-1.dev.0.fw (development version) 1128 * - ath9k_htc/htc_9271-1.4.0.fw (stable version) 1129 */ 1130 snprintf(hif_dev->fw_name, sizeof(hif_dev->fw_name), 1131 "%s/htc_%s-%d.%s.0.fw", HTC_FW_PATH, 1132 chip, MAJOR_VERSION_REQ, index); 1133 } 1134 1135 ret = request_firmware_nowait(THIS_MODULE, true, hif_dev->fw_name, 1136 &hif_dev->udev->dev, GFP_KERNEL, 1137 hif_dev, ath9k_hif_usb_firmware_cb); 1138 if (ret) { 1139 dev_err(&hif_dev->udev->dev, 1140 "ath9k_htc: Async request for firmware %s failed\n", 1141 hif_dev->fw_name); 1142 return ret; 1143 } 1144 1145 dev_info(&hif_dev->udev->dev, "ath9k_htc: Firmware %s requested\n", 1146 hif_dev->fw_name); 1147 1148 return ret; 1149 } 1150 1151 static void ath9k_hif_usb_firmware_cb(const struct firmware *fw, void *context) 1152 { 1153 struct hif_device_usb *hif_dev = context; 1154 int ret; 1155 1156 if (!fw) { 1157 ret = ath9k_hif_request_firmware(hif_dev, false); 1158 if (!ret) 1159 return; 1160 1161 dev_err(&hif_dev->udev->dev, 1162 "ath9k_htc: Failed to get firmware %s\n", 1163 hif_dev->fw_name); 1164 goto err_fw; 1165 } 1166 1167 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb, 1168 &hif_dev->udev->dev); 1169 if (hif_dev->htc_handle == NULL) 1170 goto err_dev_alloc; 1171 1172 hif_dev->fw_data = fw->data; 1173 hif_dev->fw_size = fw->size; 1174 1175 /* Proceed with initialization */ 1176 1177 ret = ath9k_hif_usb_dev_init(hif_dev); 1178 if (ret) 1179 goto err_dev_init; 1180 1181 ret = ath9k_htc_hw_init(hif_dev->htc_handle, 1182 &hif_dev->interface->dev, 1183 hif_dev->usb_device_id->idProduct, 1184 hif_dev->udev->product, 1185 hif_dev->usb_device_id->driver_info); 1186 if (ret) { 1187 ret = -EINVAL; 1188 goto err_htc_hw_init; 1189 } 1190 1191 release_firmware(fw); 1192 hif_dev->flags |= HIF_USB_READY; 1193 complete_all(&hif_dev->fw_done); 1194 1195 return; 1196 1197 err_htc_hw_init: 1198 ath9k_hif_usb_dev_deinit(hif_dev); 1199 err_dev_init: 1200 ath9k_htc_hw_free(hif_dev->htc_handle); 1201 err_dev_alloc: 1202 release_firmware(fw); 1203 err_fw: 1204 ath9k_hif_usb_firmware_fail(hif_dev); 1205 } 1206 1207 /* 1208 * An exact copy of the function from zd1211rw. 1209 */ 1210 static int send_eject_command(struct usb_interface *interface) 1211 { 1212 struct usb_device *udev = interface_to_usbdev(interface); 1213 struct usb_host_interface *iface_desc = &interface->altsetting[0]; 1214 struct usb_endpoint_descriptor *endpoint; 1215 unsigned char *cmd; 1216 u8 bulk_out_ep; 1217 int r; 1218 1219 /* Find bulk out endpoint */ 1220 for (r = 1; r >= 0; r--) { 1221 endpoint = &iface_desc->endpoint[r].desc; 1222 if (usb_endpoint_dir_out(endpoint) && 1223 usb_endpoint_xfer_bulk(endpoint)) { 1224 bulk_out_ep = endpoint->bEndpointAddress; 1225 break; 1226 } 1227 } 1228 if (r == -1) { 1229 dev_err(&udev->dev, 1230 "ath9k_htc: Could not find bulk out endpoint\n"); 1231 return -ENODEV; 1232 } 1233 1234 cmd = kzalloc(31, GFP_KERNEL); 1235 if (cmd == NULL) 1236 return -ENODEV; 1237 1238 /* USB bulk command block */ 1239 cmd[0] = 0x55; /* bulk command signature */ 1240 cmd[1] = 0x53; /* bulk command signature */ 1241 cmd[2] = 0x42; /* bulk command signature */ 1242 cmd[3] = 0x43; /* bulk command signature */ 1243 cmd[14] = 6; /* command length */ 1244 1245 cmd[15] = 0x1b; /* SCSI command: START STOP UNIT */ 1246 cmd[19] = 0x2; /* eject disc */ 1247 1248 dev_info(&udev->dev, "Ejecting storage device...\n"); 1249 r = usb_bulk_msg(udev, usb_sndbulkpipe(udev, bulk_out_ep), 1250 cmd, 31, NULL, 2000); 1251 kfree(cmd); 1252 if (r) 1253 return r; 1254 1255 /* At this point, the device disconnects and reconnects with the real 1256 * ID numbers. */ 1257 1258 usb_set_intfdata(interface, NULL); 1259 return 0; 1260 } 1261 1262 static int ath9k_hif_usb_probe(struct usb_interface *interface, 1263 const struct usb_device_id *id) 1264 { 1265 struct usb_device *udev = interface_to_usbdev(interface); 1266 struct hif_device_usb *hif_dev; 1267 int ret = 0; 1268 1269 if (id->driver_info == STORAGE_DEVICE) 1270 return send_eject_command(interface); 1271 1272 hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL); 1273 if (!hif_dev) { 1274 ret = -ENOMEM; 1275 goto err_alloc; 1276 } 1277 1278 usb_get_dev(udev); 1279 1280 hif_dev->udev = udev; 1281 hif_dev->interface = interface; 1282 hif_dev->usb_device_id = id; 1283 #ifdef CONFIG_PM 1284 udev->reset_resume = 1; 1285 #endif 1286 usb_set_intfdata(interface, hif_dev); 1287 1288 init_completion(&hif_dev->fw_done); 1289 1290 ret = ath9k_hif_request_firmware(hif_dev, true); 1291 if (ret) 1292 goto err_fw_req; 1293 1294 return ret; 1295 1296 err_fw_req: 1297 usb_set_intfdata(interface, NULL); 1298 kfree(hif_dev); 1299 usb_put_dev(udev); 1300 err_alloc: 1301 return ret; 1302 } 1303 1304 static void ath9k_hif_usb_reboot(struct usb_device *udev) 1305 { 1306 u32 reboot_cmd = 0xffffffff; 1307 void *buf; 1308 int ret; 1309 1310 buf = kmemdup(&reboot_cmd, 4, GFP_KERNEL); 1311 if (!buf) 1312 return; 1313 1314 ret = usb_interrupt_msg(udev, usb_sndintpipe(udev, USB_REG_OUT_PIPE), 1315 buf, 4, NULL, HZ); 1316 if (ret) 1317 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n"); 1318 1319 kfree(buf); 1320 } 1321 1322 static void ath9k_hif_usb_disconnect(struct usb_interface *interface) 1323 { 1324 struct usb_device *udev = interface_to_usbdev(interface); 1325 struct hif_device_usb *hif_dev = usb_get_intfdata(interface); 1326 bool unplugged = (udev->state == USB_STATE_NOTATTACHED) ? true : false; 1327 1328 if (!hif_dev) 1329 return; 1330 1331 wait_for_completion(&hif_dev->fw_done); 1332 1333 if (hif_dev->flags & HIF_USB_READY) { 1334 ath9k_htc_hw_deinit(hif_dev->htc_handle, unplugged); 1335 ath9k_htc_hw_free(hif_dev->htc_handle); 1336 ath9k_hif_usb_dev_deinit(hif_dev); 1337 } 1338 1339 usb_set_intfdata(interface, NULL); 1340 1341 /* If firmware was loaded we should drop it 1342 * go back to first stage bootloader. */ 1343 if (!unplugged && (hif_dev->flags & HIF_USB_READY)) 1344 ath9k_hif_usb_reboot(udev); 1345 1346 kfree(hif_dev); 1347 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n"); 1348 usb_put_dev(udev); 1349 } 1350 1351 #ifdef CONFIG_PM 1352 static int ath9k_hif_usb_suspend(struct usb_interface *interface, 1353 pm_message_t message) 1354 { 1355 struct hif_device_usb *hif_dev = usb_get_intfdata(interface); 1356 1357 /* 1358 * The device has to be set to FULLSLEEP mode in case no 1359 * interface is up. 1360 */ 1361 if (!(hif_dev->flags & HIF_USB_START)) 1362 ath9k_htc_suspend(hif_dev->htc_handle); 1363 1364 wait_for_completion(&hif_dev->fw_done); 1365 1366 if (hif_dev->flags & HIF_USB_READY) 1367 ath9k_hif_usb_dealloc_urbs(hif_dev); 1368 1369 return 0; 1370 } 1371 1372 static int ath9k_hif_usb_resume(struct usb_interface *interface) 1373 { 1374 struct hif_device_usb *hif_dev = usb_get_intfdata(interface); 1375 struct htc_target *htc_handle = hif_dev->htc_handle; 1376 int ret; 1377 const struct firmware *fw; 1378 1379 ret = ath9k_hif_usb_alloc_urbs(hif_dev); 1380 if (ret) 1381 return ret; 1382 1383 if (hif_dev->flags & HIF_USB_READY) { 1384 /* request cached firmware during suspend/resume cycle */ 1385 ret = request_firmware(&fw, hif_dev->fw_name, 1386 &hif_dev->udev->dev); 1387 if (ret) 1388 goto fail_resume; 1389 1390 hif_dev->fw_data = fw->data; 1391 hif_dev->fw_size = fw->size; 1392 ret = ath9k_hif_usb_download_fw(hif_dev); 1393 release_firmware(fw); 1394 if (ret) 1395 goto fail_resume; 1396 } else { 1397 ath9k_hif_usb_dealloc_urbs(hif_dev); 1398 return -EIO; 1399 } 1400 1401 mdelay(100); 1402 1403 ret = ath9k_htc_resume(htc_handle); 1404 1405 if (ret) 1406 goto fail_resume; 1407 1408 return 0; 1409 1410 fail_resume: 1411 ath9k_hif_usb_dealloc_urbs(hif_dev); 1412 1413 return ret; 1414 } 1415 #endif 1416 1417 static struct usb_driver ath9k_hif_usb_driver = { 1418 .name = KBUILD_MODNAME, 1419 .probe = ath9k_hif_usb_probe, 1420 .disconnect = ath9k_hif_usb_disconnect, 1421 #ifdef CONFIG_PM 1422 .suspend = ath9k_hif_usb_suspend, 1423 .resume = ath9k_hif_usb_resume, 1424 .reset_resume = ath9k_hif_usb_resume, 1425 #endif 1426 .id_table = ath9k_hif_usb_ids, 1427 .soft_unbind = 1, 1428 .disable_hub_initiated_lpm = 1, 1429 }; 1430 1431 int ath9k_hif_usb_init(void) 1432 { 1433 return usb_register(&ath9k_hif_usb_driver); 1434 } 1435 1436 void ath9k_hif_usb_exit(void) 1437 { 1438 usb_deregister(&ath9k_hif_usb_driver); 1439 }
1 2 #include <linux/kernel.h> 3 #include <linux/mutex.h> 4 #include <linux/spinlock.h> 5 #include <linux/errno.h> 6 #include <verifier/rcv.h> 7 #include <linux/list.h> 8 9 /* mutexes */ 10 extern int mutex_lock_interruptible(struct mutex *lock); 11 extern int mutex_lock_killable(struct mutex *lock); 12 extern void mutex_lock(struct mutex *lock); 13 14 /* mutex model functions */ 15 extern void ldv_mutex_lock(struct mutex *lock, char *sign); 16 extern int ldv_mutex_is_locked(struct mutex *lock, char *sign); 17 extern void ldv_mutex_unlock(struct mutex *lock, char *sign); 18 19 20 /* Spin locks */ 21 extern void __ldv_spin_lock(spinlock_t *lock); 22 extern void __ldv_spin_unlock(spinlock_t *lock); 23 extern int __ldv_spin_trylock(spinlock_t *lock); 24 extern void __ldv_spin_unlock_wait(spinlock_t *lock); 25 extern void __ldv_spin_can_lock(spinlock_t *lock); 26 extern int __ldv_atomic_dec_and_lock(spinlock_t *lock); 27 28 /* spin model functions */ 29 extern void ldv_spin_lock(spinlock_t *lock, char *sign); 30 extern void ldv_spin_unlock(spinlock_t *lock, char *sign); 31 extern int ldv_spin_is_locked(spinlock_t *lock, char *sign); 32 33 /* Support for list binder functions */ 34 static inline struct list_head *ldv_list_get_first(struct list_head *head) { 35 return head->next; 36 } 37 38 static inline int ldv_list_is_stop(struct list_head *pos, struct list_head *head) { 39 return pos==head; 40 } 41 42 static inline struct list_head *ldv_list_get_next(struct list_head *pos) { 43 return pos->next; 44 } 45 46 #include <linux/mutex.h> 47 #include <linux/slab.h> 48 #include <verifier/rcv.h> 49 #include <linux/timer.h> 50 #include <linux/rtnetlink.h> 51 #include <linux/gfp.h> 52 extern struct file *fops_xmit_group2; 53 extern int ldv_state_variable_8; 54 extern int ldv_timer_1_3; 55 extern struct ath_common *ath9k_usb_bus_ops_group0; 56 extern struct inode *fops_debug_group1; 57 extern struct inode *fops_queue_group1; 58 extern struct ath_common *ath9k_htc_ps_ops_group0; 59 extern int ldv_state_variable_0; 60 extern int ldv_state_variable_5; 61 extern int ldv_state_variable_13; 62 extern int ldv_state_variable_12; 63 extern struct file *fops_tgt_tx_stats_group2; 64 extern struct file *fops_queue_group2; 65 extern int ldv_state_variable_14; 66 extern int ldv_timer_1_0; 67 extern int ldv_state_variable_9; 68 extern struct inode *fops_tgt_tx_stats_group1; 69 extern struct file *fops_debug_group2; 70 extern int ref_cnt; 71 extern struct mutex key_mtx; 72 extern int ldv_state_variable_1; 73 extern int ldv_state_variable_7; 74 extern struct inode *fops_xmit_group1; 75 extern struct inode *fops_skb_rx_group1; 76 extern struct file *fops_tgt_int_stats_group2; 77 extern struct usb_interface *ath9k_hif_usb_driver_group1; 78 extern struct timer_list * ldv_timer_list_1_3; 79 extern int ldv_state_variable_10; 80 extern struct timer_list * ldv_timer_list_1_1; 81 extern struct timer_list * ldv_timer_list_1_0; 82 extern int ldv_state_variable_6; 83 extern int ldv_timer_1_2; 84 extern int ldv_timer_1_1; 85 extern int ldv_state_variable_2; 86 extern struct timer_list * ldv_timer_list_1_2; 87 extern struct inode *fops_tgt_int_stats_group1; 88 extern struct ieee80211_hw *ath9k_htc_ops_group0; 89 extern int usb_counter; 90 extern int ldv_state_variable_11; 91 extern struct file *fops_slot_group2; 92 extern int LDV_IN_INTERRUPT = 1; 93 extern struct inode *fops_slot_group1; 94 extern struct inode *fops_tgt_rx_stats_group1; 95 extern struct file *fops_tgt_rx_stats_group2; 96 extern struct mutex fs_mutex; 97 extern int ldv_state_variable_3; 98 extern struct mutex ar_mutex; 99 extern struct file *fops_skb_rx_group2; 100 extern int ldv_state_variable_4; 101 extern void ldv_file_operations_7(void); 102 extern void ldv_file_operations_6(void); 103 extern void ldv_file_operations_2(void); 104 extern void activate_pending_timer_1(struct timer_list * timer, unsigned long data, int pending_flag); 105 extern void ldv_initialyze_ath_bus_ops_10(void); 106 extern int evil_hack_12(void); 107 extern void timer_init_1(void); 108 extern void ldv_file_operations_9(void); 109 extern void ldv_usb_driver_13(void); 110 extern void ldv_file_operations_3(void); 111 extern void ldv_file_operations_8(void); 112 extern int reg_timer_1(struct timer_list * timer, void (*function)(unsigned long), unsigned long data); 113 extern void ldv_initialyze_ath_ps_ops_11(void); 114 extern int evil_hack_key_12(void); 115 extern void ldv_initialyze_ieee80211_ops_12(void); 116 extern void disable_suitable_timer_1(struct timer_list * timer); 117 extern void activate_suitable_timer_1(struct timer_list * timer, unsigned long data); 118 extern int evil_hack_fs_lock(void); 119 extern int __VERIFIER_nondet_int(void); 120 extern void ldv_file_operations_5(void); 121 extern void choose_timer_1(void); 122 extern void ldv_timer_1(int state, struct timer_list * timer); 123 extern int evil_hack_ar_lock(void); 124 extern void ldv_file_operations_4(void); 125 #line 1 "/work/ldvuser/andrianov/work/current--X--drivers/net/wireless/ath/ath9k/--X--defaultlinux-4.5-rc7--X--races--X--cpachecker/linux-4.5-rc7/csd_deg_dscv/74/dscv_tempdir/dscv/ri/races/drivers/net/wireless/ath/ath9k/hif_usb.c" 126 /* 127 * Copyright (c) 2010-2011 Atheros Communications Inc. 128 * 129 * Permission to use, copy, modify, and/or distribute this software for any 130 * purpose with or without fee is hereby granted, provided that the above 131 * copyright notice and this permission notice appear in all copies. 132 * 133 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 134 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 135 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 136 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 137 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 139 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 140 */ 141 142 #include <asm/unaligned.h> 143 #include "htc.h" 144 145 MODULE_FIRMWARE(HTC_7010_MODULE_FW); 146 MODULE_FIRMWARE(HTC_9271_MODULE_FW); 147 148 static struct usb_device_id ath9k_hif_usb_ids[] = { 149 { USB_DEVICE(0x0cf3, 0x9271) }, /* Atheros */ 150 { USB_DEVICE(0x0cf3, 0x1006) }, /* Atheros */ 151 { USB_DEVICE(0x0846, 0x9030) }, /* Netgear N150 */ 152 { USB_DEVICE(0x07D1, 0x3A10) }, /* Dlink Wireless 150 */ 153 { USB_DEVICE(0x13D3, 0x3327) }, /* Azurewave */ 154 { USB_DEVICE(0x13D3, 0x3328) }, /* Azurewave */ 155 { USB_DEVICE(0x13D3, 0x3346) }, /* IMC Networks */ 156 { USB_DEVICE(0x13D3, 0x3348) }, /* Azurewave */ 157 { USB_DEVICE(0x13D3, 0x3349) }, /* Azurewave */ 158 { USB_DEVICE(0x13D3, 0x3350) }, /* Azurewave */ 159 { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */ 160 { USB_DEVICE(0x040D, 0x3801) }, /* VIA */ 161 { USB_DEVICE(0x0cf3, 0xb003) }, /* Ubiquiti WifiStation Ext */ 162 { USB_DEVICE(0x0cf3, 0xb002) }, /* Ubiquiti WifiStation */ 163 { USB_DEVICE(0x057c, 0x8403) }, /* AVM FRITZ!WLAN 11N v2 USB */ 164 { USB_DEVICE(0x0471, 0x209e) }, /* Philips (or NXP) PTA01 */ 165 166 { USB_DEVICE(0x0cf3, 0x7015), 167 .driver_info = AR9287_USB }, /* Atheros */ 168 { USB_DEVICE(0x1668, 0x1200), 169 .driver_info = AR9287_USB }, /* Verizon */ 170 171 { USB_DEVICE(0x0cf3, 0x7010), 172 .driver_info = AR9280_USB }, /* Atheros */ 173 { USB_DEVICE(0x0846, 0x9018), 174 .driver_info = AR9280_USB }, /* Netgear WNDA3200 */ 175 { USB_DEVICE(0x083A, 0xA704), 176 .driver_info = AR9280_USB }, /* SMC Networks */ 177 { USB_DEVICE(0x0411, 0x017f), 178 .driver_info = AR9280_USB }, /* Sony UWA-BR100 */ 179 { USB_DEVICE(0x0411, 0x0197), 180 .driver_info = AR9280_USB }, /* Buffalo WLI-UV-AG300P */ 181 { USB_DEVICE(0x04da, 0x3904), 182 .driver_info = AR9280_USB }, 183 184 { USB_DEVICE(0x0cf3, 0x20ff), 185 .driver_info = STORAGE_DEVICE }, 186 187 { }, 188 }; 189 190 MODULE_DEVICE_TABLE(usb, ath9k_hif_usb_ids); 191 192 static int __hif_usb_tx(struct hif_device_usb *hif_dev); 193 194 static void hif_usb_regout_cb(struct urb *urb) 195 { 196 struct cmd_buf *cmd = (struct cmd_buf *)urb->context; 197 198 switch (urb->status) { 199 case 0: 200 break; 201 case -ENOENT: 202 case -ECONNRESET: 203 case -ENODEV: 204 case -ESHUTDOWN: 205 goto free; 206 default: 207 break; 208 } 209 210 if (cmd) { 211 ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle, 212 cmd->skb, true); 213 kfree(cmd); 214 } 215 216 return; 217 free: 218 kfree_skb(cmd->skb); 219 kfree(cmd); 220 } 221 222 static int hif_usb_send_regout(struct hif_device_usb *hif_dev, 223 struct sk_buff *skb) 224 { 225 struct urb *urb; 226 struct cmd_buf *cmd; 227 int ret = 0; 228 229 urb = usb_alloc_urb(0, GFP_KERNEL); 230 if (urb == NULL) 231 return -ENOMEM; 232 233 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 234 if (cmd == NULL) { 235 usb_free_urb(urb); 236 return -ENOMEM; 237 } 238 239 cmd->skb = skb; 240 cmd->hif_dev = hif_dev; 241 242 usb_fill_int_urb(urb, hif_dev->udev, 243 usb_sndintpipe(hif_dev->udev, USB_REG_OUT_PIPE), 244 skb->data, skb->len, 245 hif_usb_regout_cb, cmd, 1); 246 247 usb_anchor_urb(urb, &hif_dev->regout_submitted); 248 ret = usb_submit_urb(urb, GFP_KERNEL); 249 if (ret) { 250 usb_unanchor_urb(urb); 251 kfree(cmd); 252 } 253 usb_free_urb(urb); 254 255 return ret; 256 } 257 258 static void hif_usb_mgmt_cb(struct urb *urb) 259 { 260 struct cmd_buf *cmd = (struct cmd_buf *)urb->context; 261 struct hif_device_usb *hif_dev; 262 bool txok = true; 263 264 if (!cmd || !cmd->skb || !cmd->hif_dev) 265 return; 266 267 hif_dev = cmd->hif_dev; 268 269 switch (urb->status) { 270 case 0: 271 break; 272 case -ENOENT: 273 case -ECONNRESET: 274 case -ENODEV: 275 case -ESHUTDOWN: 276 txok = false; 277 278 /* 279 * If the URBs are being flushed, no need to complete 280 * this packet. 281 */ 282 spin_lock(&hif_dev->tx.tx_lock); 283 if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) { 284 spin_unlock(&hif_dev->tx.tx_lock); 285 dev_kfree_skb_any(cmd->skb); 286 kfree(cmd); 287 return; 288 } 289 spin_unlock(&hif_dev->tx.tx_lock); 290 291 break; 292 default: 293 txok = false; 294 break; 295 } 296 297 skb_pull(cmd->skb, 4); 298 ath9k_htc_txcompletion_cb(cmd->hif_dev->htc_handle, 299 cmd->skb, txok); 300 kfree(cmd); 301 } 302 303 static int hif_usb_send_mgmt(struct hif_device_usb *hif_dev, 304 struct sk_buff *skb) 305 { 306 struct urb *urb; 307 struct cmd_buf *cmd; 308 int ret = 0; 309 __le16 *hdr; 310 311 urb = usb_alloc_urb(0, GFP_ATOMIC); 312 if (urb == NULL) 313 return -ENOMEM; 314 315 cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC); 316 if (cmd == NULL) { 317 usb_free_urb(urb); 318 return -ENOMEM; 319 } 320 321 cmd->skb = skb; 322 cmd->hif_dev = hif_dev; 323 324 hdr = (__le16 *) skb_push(skb, 4); 325 *hdr++ = cpu_to_le16(skb->len - 4); 326 *hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG); 327 328 usb_fill_bulk_urb(urb, hif_dev->udev, 329 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE), 330 skb->data, skb->len, 331 hif_usb_mgmt_cb, cmd); 332 333 usb_anchor_urb(urb, &hif_dev->mgmt_submitted); 334 ret = usb_submit_urb(urb, GFP_ATOMIC); 335 if (ret) { 336 usb_unanchor_urb(urb); 337 kfree(cmd); 338 } 339 usb_free_urb(urb); 340 341 return ret; 342 } 343 344 static inline void ath9k_skb_queue_purge(struct hif_device_usb *hif_dev, 345 struct sk_buff_head *list) 346 { 347 struct sk_buff *skb; 348 349 while ((skb = __skb_dequeue(list)) != NULL) { 350 dev_kfree_skb_any(skb); 351 } 352 } 353 354 static inline void ath9k_skb_queue_complete(struct hif_device_usb *hif_dev, 355 struct sk_buff_head *queue, 356 bool txok) 357 { 358 struct sk_buff *skb; 359 360 while ((skb = __skb_dequeue(queue)) != NULL) { 361 #ifdef CONFIG_ATH9K_HTC_DEBUGFS 362 int ln = skb->len; 363 #endif 364 ath9k_htc_txcompletion_cb(hif_dev->htc_handle, 365 skb, txok); 366 if (txok) { 367 TX_STAT_INC(skb_success); 368 TX_STAT_ADD(skb_success_bytes, ln); 369 } 370 else 371 TX_STAT_INC(skb_failed); 372 } 373 } 374 375 static void hif_usb_tx_cb(struct urb *urb) 376 { 377 struct tx_buf *tx_buf = (struct tx_buf *) urb->context; 378 struct hif_device_usb *hif_dev; 379 bool txok = true; 380 381 if (!tx_buf || !tx_buf->hif_dev) 382 return; 383 384 hif_dev = tx_buf->hif_dev; 385 386 switch (urb->status) { 387 case 0: 388 break; 389 case -ENOENT: 390 case -ECONNRESET: 391 case -ENODEV: 392 case -ESHUTDOWN: 393 txok = false; 394 395 /* 396 * If the URBs are being flushed, no need to add this 397 * URB to the free list. 398 */ 399 spin_lock(&hif_dev->tx.tx_lock); 400 if (hif_dev->tx.flags & HIF_USB_TX_FLUSH) { 401 spin_unlock(&hif_dev->tx.tx_lock); 402 ath9k_skb_queue_purge(hif_dev, &tx_buf->skb_queue); 403 return; 404 } 405 spin_unlock(&hif_dev->tx.tx_lock); 406 407 break; 408 default: 409 txok = false; 410 break; 411 } 412 413 ath9k_skb_queue_complete(hif_dev, &tx_buf->skb_queue, txok); 414 415 /* Re-initialize the SKB queue */ 416 tx_buf->len = tx_buf->offset = 0; 417 __skb_queue_head_init(&tx_buf->skb_queue); 418 419 /* Add this TX buffer to the free list */ 420 spin_lock(&hif_dev->tx.tx_lock); 421 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf); 422 hif_dev->tx.tx_buf_cnt++; 423 if (!(hif_dev->tx.flags & HIF_USB_TX_STOP)) 424 __hif_usb_tx(hif_dev); /* Check for pending SKBs */ 425 TX_STAT_INC(buf_completed); 426 spin_unlock(&hif_dev->tx.tx_lock); 427 } 428 429 /* TX lock has to be taken */ 430 static int __hif_usb_tx(struct hif_device_usb *hif_dev) 431 { 432 struct tx_buf *tx_buf = NULL; 433 struct sk_buff *nskb = NULL; 434 int ret = 0, i; 435 u16 tx_skb_cnt = 0; 436 u8 *buf; 437 __le16 *hdr; 438 439 if (hif_dev->tx.tx_skb_cnt == 0) 440 return 0; 441 442 /* Check if a free TX buffer is available */ 443 if (list_empty(&hif_dev->tx.tx_buf)) 444 return 0; 445 446 tx_buf = list_first_entry(&hif_dev->tx.tx_buf, struct tx_buf, list); 447 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_pending); 448 hif_dev->tx.tx_buf_cnt--; 449 450 tx_skb_cnt = min_t(u16, hif_dev->tx.tx_skb_cnt, MAX_TX_AGGR_NUM); 451 452 for (i = 0; i < tx_skb_cnt; i++) { 453 nskb = __skb_dequeue(&hif_dev->tx.tx_skb_queue); 454 455 /* Should never be NULL */ 456 BUG_ON(!nskb); 457 458 hif_dev->tx.tx_skb_cnt--; 459 460 buf = tx_buf->buf; 461 buf += tx_buf->offset; 462 hdr = (__le16 *)buf; 463 *hdr++ = cpu_to_le16(nskb->len); 464 *hdr++ = cpu_to_le16(ATH_USB_TX_STREAM_MODE_TAG); 465 buf += 4; 466 memcpy(buf, nskb->data, nskb->len); 467 tx_buf->len = nskb->len + 4; 468 469 if (i < (tx_skb_cnt - 1)) 470 tx_buf->offset += (((tx_buf->len - 1) / 4) + 1) * 4; 471 472 if (i == (tx_skb_cnt - 1)) 473 tx_buf->len += tx_buf->offset; 474 475 __skb_queue_tail(&tx_buf->skb_queue, nskb); 476 TX_STAT_INC(skb_queued); 477 } 478 479 usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev, 480 usb_sndbulkpipe(hif_dev->udev, USB_WLAN_TX_PIPE), 481 tx_buf->buf, tx_buf->len, 482 hif_usb_tx_cb, tx_buf); 483 484 ret = usb_submit_urb(tx_buf->urb, GFP_ATOMIC); 485 if (ret) { 486 tx_buf->len = tx_buf->offset = 0; 487 ath9k_skb_queue_complete(hif_dev, &tx_buf->skb_queue, false); 488 __skb_queue_head_init(&tx_buf->skb_queue); 489 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf); 490 hif_dev->tx.tx_buf_cnt++; 491 } 492 493 if (!ret) 494 TX_STAT_INC(buf_queued); 495 496 return ret; 497 } 498 499 static int hif_usb_send_tx(struct hif_device_usb *hif_dev, struct sk_buff *skb) 500 { 501 struct ath9k_htc_tx_ctl *tx_ctl; 502 unsigned long flags; 503 int ret = 0; 504 505 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 506 507 if (hif_dev->tx.flags & HIF_USB_TX_STOP) { 508 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 509 return -ENODEV; 510 } 511 512 /* Check if the max queue count has been reached */ 513 if (hif_dev->tx.tx_skb_cnt > MAX_TX_BUF_NUM) { 514 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 515 return -ENOMEM; 516 } 517 518 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 519 520 tx_ctl = HTC_SKB_CB(skb); 521 522 /* Mgmt/Beacon frames don't use the TX buffer pool */ 523 if ((tx_ctl->type == ATH9K_HTC_MGMT) || 524 (tx_ctl->type == ATH9K_HTC_BEACON)) { 525 ret = hif_usb_send_mgmt(hif_dev, skb); 526 } 527 528 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 529 530 if ((tx_ctl->type == ATH9K_HTC_NORMAL) || 531 (tx_ctl->type == ATH9K_HTC_AMPDU)) { 532 __skb_queue_tail(&hif_dev->tx.tx_skb_queue, skb); 533 hif_dev->tx.tx_skb_cnt++; 534 } 535 536 /* Check if AMPDUs have to be sent immediately */ 537 if ((hif_dev->tx.tx_buf_cnt == MAX_TX_URB_NUM) && 538 (hif_dev->tx.tx_skb_cnt < 2)) { 539 __hif_usb_tx(hif_dev); 540 } 541 542 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 543 544 return ret; 545 } 546 547 static void hif_usb_start(void *hif_handle) 548 { 549 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; 550 unsigned long flags; 551 552 hif_dev->flags |= HIF_USB_START; 553 554 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 555 hif_dev->tx.flags &= ~HIF_USB_TX_STOP; 556 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 557 } 558 559 static void hif_usb_stop(void *hif_handle) 560 { 561 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; 562 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL; 563 unsigned long flags; 564 565 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 566 ath9k_skb_queue_complete(hif_dev, &hif_dev->tx.tx_skb_queue, false); 567 hif_dev->tx.tx_skb_cnt = 0; 568 hif_dev->tx.flags |= HIF_USB_TX_STOP; 569 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 570 571 /* The pending URBs have to be canceled. */ 572 list_for_each_entry_safe(tx_buf, tx_buf_tmp, 573 &hif_dev->tx.tx_pending, list) { 574 usb_kill_urb(tx_buf->urb); 575 } 576 577 usb_kill_anchored_urbs(&hif_dev->mgmt_submitted); 578 } 579 580 static int hif_usb_send(void *hif_handle, u8 pipe_id, struct sk_buff *skb) 581 { 582 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; 583 int ret = 0; 584 585 switch (pipe_id) { 586 case USB_WLAN_TX_PIPE: 587 ret = hif_usb_send_tx(hif_dev, skb); 588 break; 589 case USB_REG_OUT_PIPE: 590 ret = hif_usb_send_regout(hif_dev, skb); 591 break; 592 default: 593 dev_err(&hif_dev->udev->dev, 594 "ath9k_htc: Invalid TX pipe: %d\n", pipe_id); 595 ret = -EINVAL; 596 break; 597 } 598 599 return ret; 600 } 601 602 static inline bool check_index(struct sk_buff *skb, u8 idx) 603 { 604 struct ath9k_htc_tx_ctl *tx_ctl; 605 606 tx_ctl = HTC_SKB_CB(skb); 607 608 if ((tx_ctl->type == ATH9K_HTC_AMPDU) && 609 (tx_ctl->sta_idx == idx)) 610 return true; 611 612 return false; 613 } 614 615 static void hif_usb_sta_drain(void *hif_handle, u8 idx) 616 { 617 struct hif_device_usb *hif_dev = (struct hif_device_usb *)hif_handle; 618 struct sk_buff *skb, *tmp; 619 unsigned long flags; 620 621 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 622 623 skb_queue_walk_safe(&hif_dev->tx.tx_skb_queue, skb, tmp) { 624 if (check_index(skb, idx)) { 625 __skb_unlink(skb, &hif_dev->tx.tx_skb_queue); 626 ath9k_htc_txcompletion_cb(hif_dev->htc_handle, 627 skb, false); 628 hif_dev->tx.tx_skb_cnt--; 629 TX_STAT_INC(skb_failed); 630 } 631 } 632 633 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 634 } 635 636 static struct ath9k_htc_hif hif_usb = { 637 .transport = ATH9K_HIF_USB, 638 .name = "ath9k_hif_usb", 639 640 .control_ul_pipe = USB_REG_OUT_PIPE, 641 .control_dl_pipe = USB_REG_IN_PIPE, 642 643 .start = hif_usb_start, 644 .stop = hif_usb_stop, 645 .sta_drain = hif_usb_sta_drain, 646 .send = hif_usb_send, 647 }; 648 649 static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev, 650 struct sk_buff *skb) 651 { 652 struct sk_buff *nskb, *skb_pool[MAX_PKT_NUM_IN_TRANSFER]; 653 int index = 0, i = 0, len = skb->len; 654 int rx_remain_len, rx_pkt_len; 655 u16 pool_index = 0; 656 u8 *ptr; 657 658 spin_lock(&hif_dev->rx_lock); 659 660 rx_remain_len = hif_dev->rx_remain_len; 661 rx_pkt_len = hif_dev->rx_transfer_len; 662 663 if (rx_remain_len != 0) { 664 struct sk_buff *remain_skb = hif_dev->remain_skb; 665 666 if (remain_skb) { 667 ptr = (u8 *) remain_skb->data; 668 669 index = rx_remain_len; 670 rx_remain_len -= hif_dev->rx_pad_len; 671 ptr += rx_pkt_len; 672 673 memcpy(ptr, skb->data, rx_remain_len); 674 675 rx_pkt_len += rx_remain_len; 676 hif_dev->rx_remain_len = 0; 677 skb_put(remain_skb, rx_pkt_len); 678 679 skb_pool[pool_index++] = remain_skb; 680 681 } else { 682 index = rx_remain_len; 683 } 684 } 685 686 spin_unlock(&hif_dev->rx_lock); 687 688 while (index < len) { 689 u16 pkt_len; 690 u16 pkt_tag; 691 u16 pad_len; 692 int chk_idx; 693 694 ptr = (u8 *) skb->data; 695 696 pkt_len = get_unaligned_le16(ptr + index); 697 pkt_tag = get_unaligned_le16(ptr + index + 2); 698 699 if (pkt_tag != ATH_USB_RX_STREAM_MODE_TAG) { 700 RX_STAT_INC(skb_dropped); 701 return; 702 } 703 704 pad_len = 4 - (pkt_len & 0x3); 705 if (pad_len == 4) 706 pad_len = 0; 707 708 chk_idx = index; 709 index = index + 4 + pkt_len + pad_len; 710 711 if (index > MAX_RX_BUF_SIZE) { 712 spin_lock(&hif_dev->rx_lock); 713 hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE; 714 hif_dev->rx_transfer_len = 715 MAX_RX_BUF_SIZE - chk_idx - 4; 716 hif_dev->rx_pad_len = pad_len; 717 718 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC); 719 if (!nskb) { 720 dev_err(&hif_dev->udev->dev, 721 "ath9k_htc: RX memory allocation error\n"); 722 spin_unlock(&hif_dev->rx_lock); 723 goto err; 724 } 725 skb_reserve(nskb, 32); 726 RX_STAT_INC(skb_allocated); 727 728 memcpy(nskb->data, &(skb->data[chk_idx+4]), 729 hif_dev->rx_transfer_len); 730 731 /* Record the buffer pointer */ 732 hif_dev->remain_skb = nskb; 733 spin_unlock(&hif_dev->rx_lock); 734 } else { 735 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC); 736 if (!nskb) { 737 dev_err(&hif_dev->udev->dev, 738 "ath9k_htc: RX memory allocation error\n"); 739 goto err; 740 } 741 skb_reserve(nskb, 32); 742 RX_STAT_INC(skb_allocated); 743 744 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len); 745 skb_put(nskb, pkt_len); 746 skb_pool[pool_index++] = nskb; 747 } 748 } 749 750 err: 751 for (i = 0; i < pool_index; i++) { 752 RX_STAT_ADD(skb_completed_bytes, skb_pool[i]->len); 753 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i], 754 skb_pool[i]->len, USB_WLAN_RX_PIPE); 755 RX_STAT_INC(skb_completed); 756 } 757 } 758 759 static void ath9k_hif_usb_rx_cb(struct urb *urb) 760 { 761 struct sk_buff *skb = (struct sk_buff *) urb->context; 762 struct hif_device_usb *hif_dev = 763 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); 764 int ret; 765 766 if (!skb) 767 return; 768 769 if (!hif_dev) 770 goto free; 771 772 switch (urb->status) { 773 case 0: 774 break; 775 case -ENOENT: 776 case -ECONNRESET: 777 case -ENODEV: 778 case -ESHUTDOWN: 779 goto free; 780 default: 781 goto resubmit; 782 } 783 784 if (likely(urb->actual_length != 0)) { 785 skb_put(skb, urb->actual_length); 786 ath9k_hif_usb_rx_stream(hif_dev, skb); 787 } 788 789 resubmit: 790 skb_reset_tail_pointer(skb); 791 skb_trim(skb, 0); 792 793 usb_anchor_urb(urb, &hif_dev->rx_submitted); 794 ret = usb_submit_urb(urb, GFP_ATOMIC); 795 if (ret) { 796 usb_unanchor_urb(urb); 797 goto free; 798 } 799 800 return; 801 free: 802 kfree_skb(skb); 803 } 804 805 static void ath9k_hif_usb_reg_in_cb(struct urb *urb) 806 { 807 struct sk_buff *skb = (struct sk_buff *) urb->context; 808 struct sk_buff *nskb; 809 struct hif_device_usb *hif_dev = 810 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); 811 int ret; 812 813 if (!skb) 814 return; 815 816 if (!hif_dev) 817 goto free; 818 819 switch (urb->status) { 820 case 0: 821 break; 822 case -ENOENT: 823 case -ECONNRESET: 824 case -ENODEV: 825 case -ESHUTDOWN: 826 goto free; 827 default: 828 skb_reset_tail_pointer(skb); 829 skb_trim(skb, 0); 830 831 goto resubmit; 832 } 833 834 if (likely(urb->actual_length != 0)) { 835 skb_put(skb, urb->actual_length); 836 837 /* Process the command first */ 838 ath9k_htc_rx_msg(hif_dev->htc_handle, skb, 839 skb->len, USB_REG_IN_PIPE); 840 841 842 nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC); 843 if (!nskb) { 844 dev_err(&hif_dev->udev->dev, 845 "ath9k_htc: REG_IN memory allocation failure\n"); 846 urb->context = NULL; 847 return; 848 } 849 850 usb_fill_int_urb(urb, hif_dev->udev, 851 usb_rcvintpipe(hif_dev->udev, 852 USB_REG_IN_PIPE), 853 nskb->data, MAX_REG_IN_BUF_SIZE, 854 ath9k_hif_usb_reg_in_cb, nskb, 1); 855 } 856 857 resubmit: 858 usb_anchor_urb(urb, &hif_dev->reg_in_submitted); 859 ret = usb_submit_urb(urb, GFP_ATOMIC); 860 if (ret) { 861 usb_unanchor_urb(urb); 862 goto free; 863 } 864 865 return; 866 free: 867 kfree_skb(skb); 868 urb->context = NULL; 869 } 870 871 static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev) 872 { 873 struct tx_buf *tx_buf = NULL, *tx_buf_tmp = NULL; 874 unsigned long flags; 875 876 list_for_each_entry_safe(tx_buf, tx_buf_tmp, 877 &hif_dev->tx.tx_buf, list) { 878 usb_kill_urb(tx_buf->urb); 879 list_del(&tx_buf->list); 880 usb_free_urb(tx_buf->urb); 881 kfree(tx_buf->buf); 882 kfree(tx_buf); 883 } 884 885 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags); 886 hif_dev->tx.flags |= HIF_USB_TX_FLUSH; 887 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags); 888 889 list_for_each_entry_safe(tx_buf, tx_buf_tmp, 890 &hif_dev->tx.tx_pending, list) { 891 usb_kill_urb(tx_buf->urb); 892 list_del(&tx_buf->list); 893 usb_free_urb(tx_buf->urb); 894 kfree(tx_buf->buf); 895 kfree(tx_buf); 896 } 897 898 usb_kill_anchored_urbs(&hif_dev->mgmt_submitted); 899 } 900 901 static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev) 902 { 903 struct tx_buf *tx_buf; 904 int i; 905 906 INIT_LIST_HEAD(&hif_dev->tx.tx_buf); 907 INIT_LIST_HEAD(&hif_dev->tx.tx_pending); 908 spin_lock_init(&hif_dev->tx.tx_lock); 909 __skb_queue_head_init(&hif_dev->tx.tx_skb_queue); 910 init_usb_anchor(&hif_dev->mgmt_submitted); 911 912 for (i = 0; i < MAX_TX_URB_NUM; i++) { 913 tx_buf = kzalloc(sizeof(struct tx_buf), GFP_KERNEL); 914 if (!tx_buf) 915 goto err; 916 917 tx_buf->buf = kzalloc(MAX_TX_BUF_SIZE, GFP_KERNEL); 918 if (!tx_buf->buf) 919 goto err; 920 921 tx_buf->urb = usb_alloc_urb(0, GFP_KERNEL); 922 if (!tx_buf->urb) 923 goto err; 924 925 tx_buf->hif_dev = hif_dev; 926 __skb_queue_head_init(&tx_buf->skb_queue); 927 928 list_add_tail(&tx_buf->list, &hif_dev->tx.tx_buf); 929 } 930 931 hif_dev->tx.tx_buf_cnt = MAX_TX_URB_NUM; 932 933 return 0; 934 err: 935 if (tx_buf) { 936 kfree(tx_buf->buf); 937 kfree(tx_buf); 938 } 939 ath9k_hif_usb_dealloc_tx_urbs(hif_dev); 940 return -ENOMEM; 941 } 942 943 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev) 944 { 945 usb_kill_anchored_urbs(&hif_dev->rx_submitted); 946 } 947 948 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev) 949 { 950 struct urb *urb = NULL; 951 struct sk_buff *skb = NULL; 952 int i, ret; 953 954 init_usb_anchor(&hif_dev->rx_submitted); 955 spin_lock_init(&hif_dev->rx_lock); 956 957 for (i = 0; i < MAX_RX_URB_NUM; i++) { 958 959 /* Allocate URB */ 960 urb = usb_alloc_urb(0, GFP_KERNEL); 961 if (urb == NULL) { 962 ret = -ENOMEM; 963 goto err_urb; 964 } 965 966 /* Allocate buffer */ 967 skb = alloc_skb(MAX_RX_BUF_SIZE, GFP_KERNEL); 968 if (!skb) { 969 ret = -ENOMEM; 970 goto err_skb; 971 } 972 973 usb_fill_bulk_urb(urb, hif_dev->udev, 974 usb_rcvbulkpipe(hif_dev->udev, 975 USB_WLAN_RX_PIPE), 976 skb->data, MAX_RX_BUF_SIZE, 977 ath9k_hif_usb_rx_cb, skb); 978 979 /* Anchor URB */ 980 usb_anchor_urb(urb, &hif_dev->rx_submitted); 981 982 /* Submit URB */ 983 ret = usb_submit_urb(urb, GFP_KERNEL); 984 if (ret) { 985 usb_unanchor_urb(urb); 986 goto err_submit; 987 } 988 989 /* 990 * Drop reference count. 991 * This ensures that the URB is freed when killing them. 992 */ 993 usb_free_urb(urb); 994 } 995 996 return 0; 997 998 err_submit: 999 kfree_skb(skb); 1000 err_skb: 1001 usb_free_urb(urb); 1002 err_urb: 1003 ath9k_hif_usb_dealloc_rx_urbs(hif_dev); 1004 return ret; 1005 } 1006 1007 static void ath9k_hif_usb_dealloc_reg_in_urbs(struct hif_device_usb *hif_dev) 1008 { 1009 usb_kill_anchored_urbs(&hif_dev->reg_in_submitted); 1010 } 1011 1012 static int ath9k_hif_usb_alloc_reg_in_urbs(struct hif_device_usb *hif_dev) 1013 { 1014 struct urb *urb = NULL; 1015 struct sk_buff *skb = NULL; 1016 int i, ret; 1017 1018 init_usb_anchor(&hif_dev->reg_in_submitted); 1019 1020 for (i = 0; i < MAX_REG_IN_URB_NUM; i++) { 1021 1022 /* Allocate URB */ 1023 urb = usb_alloc_urb(0, GFP_KERNEL); 1024 if (urb == NULL) { 1025 ret = -ENOMEM; 1026 goto err_urb; 1027 } 1028 1029 /* Allocate buffer */ 1030 skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_KERNEL); 1031 if (!skb) { 1032 ret = -ENOMEM; 1033 goto err_skb; 1034 } 1035 1036 usb_fill_int_urb(urb, hif_dev->udev, 1037 usb_rcvintpipe(hif_dev->udev, 1038 USB_REG_IN_PIPE), 1039 skb->data, MAX_REG_IN_BUF_SIZE, 1040 ath9k_hif_usb_reg_in_cb, skb, 1); 1041 1042 /* Anchor URB */ 1043 usb_anchor_urb(urb, &hif_dev->reg_in_submitted); 1044 1045 /* Submit URB */ 1046 ret = usb_submit_urb(urb, GFP_KERNEL); 1047 if (ret) { 1048 usb_unanchor_urb(urb); 1049 goto err_submit; 1050 } 1051 1052 /* 1053 * Drop reference count. 1054 * This ensures that the URB is freed when killing them. 1055 */ 1056 usb_free_urb(urb); 1057 } 1058 1059 return 0; 1060 1061 err_submit: 1062 kfree_skb(skb); 1063 err_skb: 1064 usb_free_urb(urb); 1065 err_urb: 1066 ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev); 1067 return ret; 1068 } 1069 1070 static int ath9k_hif_usb_alloc_urbs(struct hif_device_usb *hif_dev) 1071 { 1072 /* Register Write */ 1073 init_usb_anchor(&hif_dev->regout_submitted); 1074 1075 /* TX */ 1076 if (ath9k_hif_usb_alloc_tx_urbs(hif_dev) < 0) 1077 goto err; 1078 1079 /* RX */ 1080 if (ath9k_hif_usb_alloc_rx_urbs(hif_dev) < 0) 1081 goto err_rx; 1082 1083 /* Register Read */ 1084 if (ath9k_hif_usb_alloc_reg_in_urbs(hif_dev) < 0) 1085 goto err_reg; 1086 1087 return 0; 1088 err_reg: 1089 ath9k_hif_usb_dealloc_rx_urbs(hif_dev); 1090 err_rx: 1091 ath9k_hif_usb_dealloc_tx_urbs(hif_dev); 1092 err: 1093 return -ENOMEM; 1094 } 1095 1096 static void ath9k_hif_usb_dealloc_urbs(struct hif_device_usb *hif_dev) 1097 { 1098 usb_kill_anchored_urbs(&hif_dev->regout_submitted); 1099 ath9k_hif_usb_dealloc_reg_in_urbs(hif_dev); 1100 ath9k_hif_usb_dealloc_tx_urbs(hif_dev); 1101 ath9k_hif_usb_dealloc_rx_urbs(hif_dev); 1102 } 1103 1104 static int ath9k_hif_usb_download_fw(struct hif_device_usb *hif_dev) 1105 { 1106 int transfer, err; 1107 const void *data = hif_dev->fw_data; 1108 size_t len = hif_dev->fw_size; 1109 u32 addr = AR9271_FIRMWARE; 1110 u8 *buf = kzalloc(4096, GFP_KERNEL); 1111 u32 firm_offset; 1112 1113 if (!buf) 1114 return -ENOMEM; 1115 1116 while (len) { 1117 transfer = min_t(size_t, len, 4096); 1118 memcpy(buf, data, transfer); 1119 1120 err = usb_control_msg(hif_dev->udev, 1121 usb_sndctrlpipe(hif_dev->udev, 0), 1122 FIRMWARE_DOWNLOAD, 0x40 | USB_DIR_OUT, 1123 addr >> 8, 0, buf, transfer, HZ); 1124 if (err < 0) { 1125 kfree(buf); 1126 return err; 1127 } 1128 1129 len -= transfer; 1130 data += transfer; 1131 addr += transfer; 1132 } 1133 kfree(buf); 1134 1135 if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info)) 1136 firm_offset = AR7010_FIRMWARE_TEXT; 1137 else 1138 firm_offset = AR9271_FIRMWARE_TEXT; 1139 1140 /* 1141 * Issue FW download complete command to firmware. 1142 */ 1143 err = usb_control_msg(hif_dev->udev, usb_sndctrlpipe(hif_dev->udev, 0), 1144 FIRMWARE_DOWNLOAD_COMP, 1145 0x40 | USB_DIR_OUT, 1146 firm_offset >> 8, 0, NULL, 0, HZ); 1147 if (err) 1148 return -EIO; 1149 1150 dev_info(&hif_dev->udev->dev, "ath9k_htc: Transferred FW: %s, size: %ld\n", 1151 hif_dev->fw_name, (unsigned long) hif_dev->fw_size); 1152 1153 return 0; 1154 } 1155 1156 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev) 1157 { 1158 int ret; 1159 1160 ret = ath9k_hif_usb_download_fw(hif_dev); 1161 if (ret) { 1162 dev_err(&hif_dev->udev->dev, 1163 "ath9k_htc: Firmware - %s download failed\n", 1164 hif_dev->fw_name); 1165 return ret; 1166 } 1167 1168 /* Alloc URBs */ 1169 ret = ath9k_hif_usb_alloc_urbs(hif_dev); 1170 if (ret) { 1171 dev_err(&hif_dev->udev->dev, 1172 "ath9k_htc: Unable to allocate URBs\n"); 1173 return ret; 1174 } 1175 1176 return 0; 1177 } 1178 1179 static void ath9k_hif_usb_dev_deinit(struct hif_device_usb *hif_dev) 1180 { 1181 ath9k_hif_usb_dealloc_urbs(hif_dev); 1182 } 1183 1184 /* 1185 * If initialization fails or the FW cannot be retrieved, 1186 * detach the device. 1187 */ 1188 static void ath9k_hif_usb_firmware_fail(struct hif_device_usb *hif_dev) 1189 { 1190 struct device *dev = &hif_dev->udev->dev; 1191 struct device *parent = dev->parent; 1192 1193 complete_all(&hif_dev->fw_done); 1194 1195 if (parent) 1196 device_lock(parent); 1197 1198 device_release_driver(dev); 1199 1200 if (parent) 1201 device_unlock(parent); 1202 } 1203 1204 static void ath9k_hif_usb_firmware_cb(const struct firmware *fw, void *context); 1205 1206 /* taken from iwlwifi */ 1207 static int ath9k_hif_request_firmware(struct hif_device_usb *hif_dev, 1208 bool first) 1209 { 1210 char index[8], *chip; 1211 int ret; 1212 1213 if (first) { 1214 if (htc_use_dev_fw) { 1215 hif_dev->fw_minor_index = FIRMWARE_MINOR_IDX_MAX + 1; 1216 sprintf(index, "%s", "dev"); 1217 } else { 1218 hif_dev->fw_minor_index = FIRMWARE_MINOR_IDX_MAX; 1219 sprintf(index, "%d", hif_dev->fw_minor_index); 1220 } 1221 } else { 1222 hif_dev->fw_minor_index--; 1223 sprintf(index, "%d", hif_dev->fw_minor_index); 1224 } 1225 1226 /* test for FW 1.3 */ 1227 if (MAJOR_VERSION_REQ == 1 && hif_dev->fw_minor_index == 3) { 1228 const char *filename; 1229 1230 if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info)) 1231 filename = FIRMWARE_AR7010_1_1; 1232 else 1233 filename = FIRMWARE_AR9271; 1234 1235 /* expected fw locations: 1236 * - htc_9271.fw (stable version 1.3, depricated) 1237 */ 1238 snprintf(hif_dev->fw_name, sizeof(hif_dev->fw_name), 1239 "%s", filename); 1240 1241 } else if (hif_dev->fw_minor_index < FIRMWARE_MINOR_IDX_MIN) { 1242 dev_err(&hif_dev->udev->dev, "no suitable firmware found!\n"); 1243 1244 return -ENOENT; 1245 } else { 1246 if (IS_AR7010_DEVICE(hif_dev->usb_device_id->driver_info)) 1247 chip = "7010"; 1248 else 1249 chip = "9271"; 1250 1251 /* expected fw locations: 1252 * - ath9k_htc/htc_9271-1.dev.0.fw (development version) 1253 * - ath9k_htc/htc_9271-1.4.0.fw (stable version) 1254 */ 1255 snprintf(hif_dev->fw_name, sizeof(hif_dev->fw_name), 1256 "%s/htc_%s-%d.%s.0.fw", HTC_FW_PATH, 1257 chip, MAJOR_VERSION_REQ, index); 1258 } 1259 1260 ret = request_firmware_nowait(THIS_MODULE, true, hif_dev->fw_name, 1261 &hif_dev->udev->dev, GFP_KERNEL, 1262 hif_dev, ath9k_hif_usb_firmware_cb); 1263 if (ret) { 1264 dev_err(&hif_dev->udev->dev, 1265 "ath9k_htc: Async request for firmware %s failed\n", 1266 hif_dev->fw_name); 1267 return ret; 1268 } 1269 1270 dev_info(&hif_dev->udev->dev, "ath9k_htc: Firmware %s requested\n", 1271 hif_dev->fw_name); 1272 1273 return ret; 1274 } 1275 1276 static void ath9k_hif_usb_firmware_cb(const struct firmware *fw, void *context) 1277 { 1278 struct hif_device_usb *hif_dev = context; 1279 int ret; 1280 1281 if (!fw) { 1282 ret = ath9k_hif_request_firmware(hif_dev, false); 1283 if (!ret) 1284 return; 1285 1286 dev_err(&hif_dev->udev->dev, 1287 "ath9k_htc: Failed to get firmware %s\n", 1288 hif_dev->fw_name); 1289 goto err_fw; 1290 } 1291 1292 hif_dev->htc_handle = ath9k_htc_hw_alloc(hif_dev, &hif_usb, 1293 &hif_dev->udev->dev); 1294 if (hif_dev->htc_handle == NULL) 1295 goto err_dev_alloc; 1296 1297 hif_dev->fw_data = fw->data; 1298 hif_dev->fw_size = fw->size; 1299 1300 /* Proceed with initialization */ 1301 1302 ret = ath9k_hif_usb_dev_init(hif_dev); 1303 if (ret) 1304 goto err_dev_init; 1305 1306 ret = ath9k_htc_hw_init(hif_dev->htc_handle, 1307 &hif_dev->interface->dev, 1308 hif_dev->usb_device_id->idProduct, 1309 hif_dev->udev->product, 1310 hif_dev->usb_device_id->driver_info); 1311 if (ret) { 1312 ret = -EINVAL; 1313 goto err_htc_hw_init; 1314 } 1315 1316 release_firmware(fw); 1317 hif_dev->flags |= HIF_USB_READY; 1318 complete_all(&hif_dev->fw_done); 1319 1320 return; 1321 1322 err_htc_hw_init: 1323 ath9k_hif_usb_dev_deinit(hif_dev); 1324 err_dev_init: 1325 ath9k_htc_hw_free(hif_dev->htc_handle); 1326 err_dev_alloc: 1327 release_firmware(fw); 1328 err_fw: 1329 ath9k_hif_usb_firmware_fail(hif_dev); 1330 } 1331 1332 /* 1333 * An exact copy of the function from zd1211rw. 1334 */ 1335 static int send_eject_command(struct usb_interface *interface) 1336 { 1337 struct usb_device *udev = interface_to_usbdev(interface); 1338 struct usb_host_interface *iface_desc = &interface->altsetting[0]; 1339 struct usb_endpoint_descriptor *endpoint; 1340 unsigned char *cmd; 1341 u8 bulk_out_ep; 1342 int r; 1343 1344 /* Find bulk out endpoint */ 1345 for (r = 1; r >= 0; r--) { 1346 endpoint = &iface_desc->endpoint[r].desc; 1347 if (usb_endpoint_dir_out(endpoint) && 1348 usb_endpoint_xfer_bulk(endpoint)) { 1349 bulk_out_ep = endpoint->bEndpointAddress; 1350 break; 1351 } 1352 } 1353 if (r == -1) { 1354 dev_err(&udev->dev, 1355 "ath9k_htc: Could not find bulk out endpoint\n"); 1356 return -ENODEV; 1357 } 1358 1359 cmd = kzalloc(31, GFP_KERNEL); 1360 if (cmd == NULL) 1361 return -ENODEV; 1362 1363 /* USB bulk command block */ 1364 cmd[0] = 0x55; /* bulk command signature */ 1365 cmd[1] = 0x53; /* bulk command signature */ 1366 cmd[2] = 0x42; /* bulk command signature */ 1367 cmd[3] = 0x43; /* bulk command signature */ 1368 cmd[14] = 6; /* command length */ 1369 1370 cmd[15] = 0x1b; /* SCSI command: START STOP UNIT */ 1371 cmd[19] = 0x2; /* eject disc */ 1372 1373 dev_info(&udev->dev, "Ejecting storage device...\n"); 1374 r = usb_bulk_msg(udev, usb_sndbulkpipe(udev, bulk_out_ep), 1375 cmd, 31, NULL, 2000); 1376 kfree(cmd); 1377 if (r) 1378 return r; 1379 1380 /* At this point, the device disconnects and reconnects with the real 1381 * ID numbers. */ 1382 1383 usb_set_intfdata(interface, NULL); 1384 return 0; 1385 } 1386 1387 static int ath9k_hif_usb_probe(struct usb_interface *interface, 1388 const struct usb_device_id *id) 1389 { 1390 struct usb_device *udev = interface_to_usbdev(interface); 1391 struct hif_device_usb *hif_dev; 1392 int ret = 0; 1393 1394 if (id->driver_info == STORAGE_DEVICE) 1395 return send_eject_command(interface); 1396 1397 hif_dev = kzalloc(sizeof(struct hif_device_usb), GFP_KERNEL); 1398 if (!hif_dev) { 1399 ret = -ENOMEM; 1400 goto err_alloc; 1401 } 1402 1403 usb_get_dev(udev); 1404 1405 hif_dev->udev = udev; 1406 hif_dev->interface = interface; 1407 hif_dev->usb_device_id = id; 1408 #ifdef CONFIG_PM 1409 udev->reset_resume = 1; 1410 #endif 1411 usb_set_intfdata(interface, hif_dev); 1412 1413 init_completion(&hif_dev->fw_done); 1414 1415 ret = ath9k_hif_request_firmware(hif_dev, true); 1416 if (ret) 1417 goto err_fw_req; 1418 1419 return ret; 1420 1421 err_fw_req: 1422 usb_set_intfdata(interface, NULL); 1423 kfree(hif_dev); 1424 usb_put_dev(udev); 1425 err_alloc: 1426 return ret; 1427 } 1428 1429 static void ath9k_hif_usb_reboot(struct usb_device *udev) 1430 { 1431 u32 reboot_cmd = 0xffffffff; 1432 void *buf; 1433 int ret; 1434 1435 buf = kmemdup(&reboot_cmd, 4, GFP_KERNEL); 1436 if (!buf) 1437 return; 1438 1439 ret = usb_interrupt_msg(udev, usb_sndintpipe(udev, USB_REG_OUT_PIPE), 1440 buf, 4, NULL, HZ); 1441 if (ret) 1442 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n"); 1443 1444 kfree(buf); 1445 } 1446 1447 static void ath9k_hif_usb_disconnect(struct usb_interface *interface) 1448 { 1449 struct usb_device *udev = interface_to_usbdev(interface); 1450 struct hif_device_usb *hif_dev = usb_get_intfdata(interface); 1451 bool unplugged = (udev->state == USB_STATE_NOTATTACHED) ? true : false; 1452 1453 if (!hif_dev) 1454 return; 1455 1456 wait_for_completion(&hif_dev->fw_done); 1457 1458 if (hif_dev->flags & HIF_USB_READY) { 1459 ath9k_htc_hw_deinit(hif_dev->htc_handle, unplugged); 1460 ath9k_htc_hw_free(hif_dev->htc_handle); 1461 ath9k_hif_usb_dev_deinit(hif_dev); 1462 } 1463 1464 usb_set_intfdata(interface, NULL); 1465 1466 /* If firmware was loaded we should drop it 1467 * go back to first stage bootloader. */ 1468 if (!unplugged && (hif_dev->flags & HIF_USB_READY)) 1469 ath9k_hif_usb_reboot(udev); 1470 1471 kfree(hif_dev); 1472 dev_info(&udev->dev, "ath9k_htc: USB layer deinitialized\n"); 1473 usb_put_dev(udev); 1474 } 1475 1476 #ifdef CONFIG_PM 1477 static int ath9k_hif_usb_suspend(struct usb_interface *interface, 1478 pm_message_t message) 1479 { 1480 struct hif_device_usb *hif_dev = usb_get_intfdata(interface); 1481 1482 /* 1483 * The device has to be set to FULLSLEEP mode in case no 1484 * interface is up. 1485 */ 1486 if (!(hif_dev->flags & HIF_USB_START)) 1487 ath9k_htc_suspend(hif_dev->htc_handle); 1488 1489 wait_for_completion(&hif_dev->fw_done); 1490 1491 if (hif_dev->flags & HIF_USB_READY) 1492 ath9k_hif_usb_dealloc_urbs(hif_dev); 1493 1494 return 0; 1495 } 1496 1497 static int ath9k_hif_usb_resume(struct usb_interface *interface) 1498 { 1499 struct hif_device_usb *hif_dev = usb_get_intfdata(interface); 1500 struct htc_target *htc_handle = hif_dev->htc_handle; 1501 int ret; 1502 const struct firmware *fw; 1503 1504 ret = ath9k_hif_usb_alloc_urbs(hif_dev); 1505 if (ret) 1506 return ret; 1507 1508 if (hif_dev->flags & HIF_USB_READY) { 1509 /* request cached firmware during suspend/resume cycle */ 1510 ret = request_firmware(&fw, hif_dev->fw_name, 1511 &hif_dev->udev->dev); 1512 if (ret) 1513 goto fail_resume; 1514 1515 hif_dev->fw_data = fw->data; 1516 hif_dev->fw_size = fw->size; 1517 ret = ath9k_hif_usb_download_fw(hif_dev); 1518 release_firmware(fw); 1519 if (ret) 1520 goto fail_resume; 1521 } else { 1522 ath9k_hif_usb_dealloc_urbs(hif_dev); 1523 return -EIO; 1524 } 1525 1526 mdelay(100); 1527 1528 ret = ath9k_htc_resume(htc_handle); 1529 1530 if (ret) 1531 goto fail_resume; 1532 1533 return 0; 1534 1535 fail_resume: 1536 ath9k_hif_usb_dealloc_urbs(hif_dev); 1537 1538 return ret; 1539 } 1540 #endif 1541 1542 static struct usb_driver ath9k_hif_usb_driver = { 1543 .name = KBUILD_MODNAME, 1544 .probe = ath9k_hif_usb_probe, 1545 .disconnect = ath9k_hif_usb_disconnect, 1546 #ifdef CONFIG_PM 1547 .suspend = ath9k_hif_usb_suspend, 1548 .resume = ath9k_hif_usb_resume, 1549 .reset_resume = ath9k_hif_usb_resume, 1550 #endif 1551 .id_table = ath9k_hif_usb_ids, 1552 .soft_unbind = 1, 1553 .disable_hub_initiated_lpm = 1, 1554 }; 1555 1556 int ath9k_hif_usb_init(void) 1557 { 1558 return usb_register(&ath9k_hif_usb_driver); 1559 } 1560 1561 void ath9k_hif_usb_exit(void) 1562 { 1563 usb_deregister(&ath9k_hif_usb_driver); 1564 } 1565 1566 #line 125 "/work/ldvuser/andrianov/work/current--X--drivers/net/wireless/ath/ath9k/--X--defaultlinux-4.5-rc7--X--races--X--cpachecker/linux-4.5-rc7/csd_deg_dscv/74/dscv_tempdir/dscv/ri/races/drivers/net/wireless/ath/ath9k/hif_usb.o.c.prepared" 1567 1568 int ldv_retval_11; 1569 int ldv_retval_10; 1570 int ldv_retval_9; 1571 1572 1573 void ldv_usb_driver_13(void){ 1574 ath9k_hif_usb_driver_group1 = ldv_undef_ptr(); 1575 } 1576 1577 1578 void ldv_main_exported_13(void){ 1579 pm_message_t ldvarg101; 1580 struct usb_device_id const *ldvarg102; 1581 /*DEG-struct: handlers from structure ath9k_hif_usb_driver*/ 1582 switch(__VERIFIER_nondet_int()){ 1583 case 0:{ 1584 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1585 if(ldv_state_variable_13 == 1){ 1586 /*DEG-CALL: handler probe from ath9k_hif_usb_driver*/ 1587 ldv_retval_11=(& ath9k_hif_usb_probe)(ath9k_hif_usb_driver_group1,ldvarg102); 1588 if(ldv_retval_11==0){ 1589 ldv_state_variable_13 = 2; 1590 ref_cnt++; 1591 } 1592 } 1593 } 1594 break; 1595 case 1:{ 1596 /*DEG-state: state 3 (look at corresponding state-chart diagram for details)*/ 1597 if(ldv_state_variable_13 == 3){ 1598 /*DEG-CALL: handler reset_resume from ath9k_hif_usb_driver*/ 1599 ldv_retval_10=(& ath9k_hif_usb_resume)(ath9k_hif_usb_driver_group1); 1600 if(ldv_retval_10==0){ 1601 ldv_state_variable_13 = 2; 1602 } 1603 } 1604 } 1605 break; 1606 case 2:{ 1607 /*DEG-state: state 3 (look at corresponding state-chart diagram for details)*/ 1608 if(ldv_state_variable_13 == 3 && usb_counter==0){ 1609 /*DEG-CALL: handler disconnect from ath9k_hif_usb_driver*/ 1610 (& ath9k_hif_usb_disconnect)(ath9k_hif_usb_driver_group1); 1611 ldv_state_variable_13 = 1; 1612 ref_cnt--; 1613 } 1614 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1615 if(ldv_state_variable_13 == 2 && usb_counter==0){ 1616 /*DEG-CALL: handler disconnect from ath9k_hif_usb_driver*/ 1617 (& ath9k_hif_usb_disconnect)(ath9k_hif_usb_driver_group1); 1618 ldv_state_variable_13 = 1; 1619 ref_cnt--; 1620 } 1621 } 1622 break; 1623 case 3:{ 1624 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1625 if(ldv_state_variable_13 == 2){ 1626 /*DEG-CALL: handler suspend from ath9k_hif_usb_driver*/ 1627 (& ath9k_hif_usb_suspend)(ath9k_hif_usb_driver_group1,ldvarg101); 1628 ldv_state_variable_13 = 3; 1629 } 1630 } 1631 break; 1632 case 4:{ 1633 /*DEG-state: state 3 (look at corresponding state-chart diagram for details)*/ 1634 if(ldv_state_variable_13 == 3){ 1635 /*DEG-CALL: handler resume from ath9k_hif_usb_driver*/ 1636 ldv_retval_9=(& ath9k_hif_usb_resume)(ath9k_hif_usb_driver_group1); 1637 if(ldv_retval_9==0){ 1638 ldv_state_variable_13 = 2; 1639 } 1640 } 1641 } 1642 break; 1643 default: ldv_assume(0); 1644 } 1645 1646 }; 1647 1648 1649 void ldv_main_exported_14(void){ 1650 void *ldvarg86; 1651 struct sk_buff *ldvarg87; 1652 void *ldvarg90; 1653 void *ldvarg89; 1654 u8 ldvarg88; 1655 u8 ldvarg84; 1656 void *ldvarg85; 1657 /*DEG-struct: handlers from structure hif_usb*/ 1658 switch(__VERIFIER_nondet_int()){ 1659 case 0:{ 1660 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1661 if(ldv_state_variable_14 == 1){ 1662 /*DEG-CALL: handler start from hif_usb*/ 1663 (& hif_usb_start)(ldvarg90); 1664 /*DEG-postcall: get module*/ 1665 ldv_state_variable_14 = 2; 1666 ref_cnt++; 1667 } 1668 } 1669 break; 1670 case 1:{ 1671 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1672 if(ldv_state_variable_14 == 1){ 1673 /*DEG-CALL: handler send from hif_usb*/ 1674 (& hif_usb_send)(ldvarg89,ldvarg88,ldvarg87); 1675 /*DEG-postcall: default*/ 1676 ldv_state_variable_14 = 1; 1677 } 1678 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1679 if(ldv_state_variable_14 == 2){ 1680 /*DEG-CALL: handler send from hif_usb*/ 1681 (& hif_usb_send)(ldvarg89,ldvarg88,ldvarg87); 1682 /*DEG-postcall: default*/ 1683 ldv_state_variable_14 = 2; 1684 } 1685 } 1686 break; 1687 case 2:{ 1688 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1689 if(ldv_state_variable_14 == 2){ 1690 /*DEG-CALL: handler stop from hif_usb*/ 1691 (& hif_usb_stop)(ldvarg86); 1692 /*DEG-postcall: module put*/ 1693 ldv_state_variable_14 = 1; 1694 ref_cnt--; 1695 } 1696 } 1697 break; 1698 case 3:{ 1699 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1700 if(ldv_state_variable_14 == 1){ 1701 /*DEG-CALL: handler sta_drain from hif_usb*/ 1702 (& hif_usb_sta_drain)(ldvarg85,ldvarg84); 1703 /*DEG-postcall: default*/ 1704 ldv_state_variable_14 = 1; 1705 } 1706 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1707 if(ldv_state_variable_14 == 2){ 1708 /*DEG-CALL: handler sta_drain from hif_usb*/ 1709 (& hif_usb_sta_drain)(ldvarg85,ldvarg84); 1710 /*DEG-postcall: default*/ 1711 ldv_state_variable_14 = 2; 1712 } 1713 } 1714 break; 1715 default: ldv_assume(0); 1716 } 1717 1718 };
1 /* 2 * Copyright (c) 2010-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include "htc.h" 18 19 #define FUDGE 2 20 21 void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv) 22 { 23 struct ath_hw *ah = priv->ah; 24 struct ath9k_tx_queue_info qi, qi_be; 25 26 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); 27 memset(&qi_be, 0, sizeof(struct ath9k_tx_queue_info)); 28 29 ath9k_hw_get_txq_props(ah, priv->beacon.beaconq, &qi); 30 31 if (priv->ah->opmode == NL80211_IFTYPE_AP || 32 priv->ah->opmode == NL80211_IFTYPE_MESH_POINT) { 33 qi.tqi_aifs = 1; 34 qi.tqi_cwmin = 0; 35 qi.tqi_cwmax = 0; 36 } else if (priv->ah->opmode == NL80211_IFTYPE_ADHOC) { 37 int qnum = priv->hwq_map[IEEE80211_AC_BE]; 38 39 ath9k_hw_get_txq_props(ah, qnum, &qi_be); 40 41 qi.tqi_aifs = qi_be.tqi_aifs; 42 43 /* 44 * For WIFI Beacon Distribution 45 * Long slot time : 2x cwmin 46 * Short slot time : 4x cwmin 47 */ 48 if (ah->slottime == ATH9K_SLOT_TIME_20) 49 qi.tqi_cwmin = 2*qi_be.tqi_cwmin; 50 else 51 qi.tqi_cwmin = 4*qi_be.tqi_cwmin; 52 53 qi.tqi_cwmax = qi_be.tqi_cwmax; 54 55 } 56 57 if (!ath9k_hw_set_txq_props(ah, priv->beacon.beaconq, &qi)) { 58 ath_err(ath9k_hw_common(ah), 59 "Unable to update beacon queue %u!\n", priv->beacon.beaconq); 60 } else { 61 ath9k_hw_resettxqueue(ah, priv->beacon.beaconq); 62 } 63 } 64 65 /* 66 * Both nexttbtt and intval have to be in usecs. 67 */ 68 static void ath9k_htc_beacon_init(struct ath9k_htc_priv *priv, 69 struct ath_beacon_config *conf, 70 bool reset_tsf) 71 { 72 struct ath_hw *ah = priv->ah; 73 int ret __attribute__ ((unused)); 74 __be32 htc_imask = 0; 75 u8 cmd_rsp; 76 77 if (conf->intval >= TU_TO_USEC(DEFAULT_SWBA_RESPONSE)) 78 ah->config.sw_beacon_response_time = DEFAULT_SWBA_RESPONSE; 79 else 80 ah->config.sw_beacon_response_time = MIN_SWBA_RESPONSE; 81 82 WMI_CMD(WMI_DISABLE_INTR_CMDID); 83 if (reset_tsf) 84 ath9k_hw_reset_tsf(ah); 85 ath9k_htc_beaconq_config(priv); 86 ath9k_hw_beaconinit(ah, conf->nexttbtt, conf->intval); 87 priv->beacon.bmisscnt = 0; 88 htc_imask = cpu_to_be32(ah->imask); 89 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask); 90 } 91 92 static void ath9k_htc_beacon_config_sta(struct ath9k_htc_priv *priv, 93 struct ath_beacon_config *bss_conf) 94 { 95 struct ath9k_beacon_state bs; 96 enum ath9k_int imask = 0; 97 __be32 htc_imask = 0; 98 int ret __attribute__ ((unused)); 99 u8 cmd_rsp; 100 101 if (ath9k_cmn_beacon_config_sta(priv->ah, bss_conf, &bs) == -EPERM) 102 return; 103 104 WMI_CMD(WMI_DISABLE_INTR_CMDID); 105 ath9k_hw_set_sta_beacon_timers(priv->ah, &bs); 106 imask |= ATH9K_INT_BMISS; 107 htc_imask = cpu_to_be32(imask); 108 WMI_CMD_BUF(WMI_ENABLE_INTR_CMDID, &htc_imask); 109 } 110 111 static void ath9k_htc_beacon_config_ap(struct ath9k_htc_priv *priv, 112 struct ath_beacon_config *conf) 113 { 114 struct ath_hw *ah = priv->ah; 115 ah->imask = 0; 116 117 ath9k_cmn_beacon_config_ap(ah, conf, ATH9K_HTC_MAX_BCN_VIF); 118 ath9k_htc_beacon_init(priv, conf, false); 119 } 120 121 static void ath9k_htc_beacon_config_adhoc(struct ath9k_htc_priv *priv, 122 struct ath_beacon_config *conf) 123 { 124 struct ath_hw *ah = priv->ah; 125 ah->imask = 0; 126 127 ath9k_cmn_beacon_config_adhoc(ah, conf); 128 ath9k_htc_beacon_init(priv, conf, conf->ibss_creator); 129 } 130 131 void ath9k_htc_beaconep(void *drv_priv, struct sk_buff *skb, 132 enum htc_endpoint_id ep_id, bool txok) 133 { 134 dev_kfree_skb_any(skb); 135 } 136 137 static void ath9k_htc_send_buffered(struct ath9k_htc_priv *priv, 138 int slot) 139 { 140 struct ath_common *common = ath9k_hw_common(priv->ah); 141 struct ieee80211_vif *vif; 142 struct sk_buff *skb; 143 struct ieee80211_hdr *hdr; 144 int padpos, padsize, ret, tx_slot; 145 146 spin_lock_bh(&priv->beacon_lock); 147 148 vif = priv->beacon.bslot[slot]; 149 150 skb = ieee80211_get_buffered_bc(priv->hw, vif); 151 152 while(skb) { 153 hdr = (struct ieee80211_hdr *) skb->data; 154 155 padpos = ieee80211_hdrlen(hdr->frame_control); 156 padsize = padpos & 3; 157 if (padsize && skb->len > padpos) { 158 if (skb_headroom(skb) < padsize) { 159 dev_kfree_skb_any(skb); 160 goto next; 161 } 162 skb_push(skb, padsize); 163 memmove(skb->data, skb->data + padsize, padpos); 164 } 165 166 tx_slot = ath9k_htc_tx_get_slot(priv); 167 if (tx_slot < 0) { 168 ath_dbg(common, XMIT, "No free CAB slot\n"); 169 dev_kfree_skb_any(skb); 170 goto next; 171 } 172 173 ret = ath9k_htc_tx_start(priv, NULL, skb, tx_slot, true); 174 if (ret != 0) { 175 ath9k_htc_tx_clear_slot(priv, tx_slot); 176 dev_kfree_skb_any(skb); 177 178 ath_dbg(common, XMIT, "Failed to send CAB frame\n"); 179 } else { 180 spin_lock_bh(&priv->tx.tx_lock); 181 priv->tx.queued_cnt++; 182 spin_unlock_bh(&priv->tx.tx_lock); 183 } 184 next: 185 skb = ieee80211_get_buffered_bc(priv->hw, vif); 186 } 187 188 spin_unlock_bh(&priv->beacon_lock); 189 } 190 191 static void ath9k_htc_send_beacon(struct ath9k_htc_priv *priv, 192 int slot) 193 { 194 struct ath_common *common = ath9k_hw_common(priv->ah); 195 struct ieee80211_vif *vif; 196 struct ath9k_htc_vif *avp; 197 struct tx_beacon_header beacon_hdr; 198 struct ath9k_htc_tx_ctl *tx_ctl; 199 struct ieee80211_tx_info *info; 200 struct ieee80211_mgmt *mgmt; 201 struct sk_buff *beacon; 202 u8 *tx_fhdr; 203 int ret; 204 205 memset(&beacon_hdr, 0, sizeof(struct tx_beacon_header)); 206 207 spin_lock_bh(&priv->beacon_lock); 208 209 vif = priv->beacon.bslot[slot]; 210 avp = (struct ath9k_htc_vif *)vif->drv_priv; 211 212 if (unlikely(test_bit(ATH_OP_SCANNING, &common->op_flags))) { 213 spin_unlock_bh(&priv->beacon_lock); 214 return; 215 } 216 217 /* Get a new beacon */ 218 beacon = ieee80211_beacon_get(priv->hw, vif); 219 if (!beacon) { 220 spin_unlock_bh(&priv->beacon_lock); 221 return; 222 } 223 224 /* 225 * Update the TSF adjust value here, the HW will 226 * add this value for every beacon. 227 */ 228 mgmt = (struct ieee80211_mgmt *)beacon->data; 229 mgmt->u.beacon.timestamp = avp->tsfadjust; 230 231 info = IEEE80211_SKB_CB(beacon); 232 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { 233 struct ieee80211_hdr *hdr = 234 (struct ieee80211_hdr *) beacon->data; 235 avp->seq_no += 0x10; 236 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); 237 hdr->seq_ctrl |= cpu_to_le16(avp->seq_no); 238 } 239 240 tx_ctl = HTC_SKB_CB(beacon); 241 memset(tx_ctl, 0, sizeof(*tx_ctl)); 242 243 tx_ctl->type = ATH9K_HTC_BEACON; 244 tx_ctl->epid = priv->beacon_ep; 245 246 beacon_hdr.vif_index = avp->index; 247 tx_fhdr = skb_push(beacon, sizeof(beacon_hdr)); 248 memcpy(tx_fhdr, (u8 *) &beacon_hdr, sizeof(beacon_hdr)); 249 250 ret = htc_send(priv->htc, beacon); 251 if (ret != 0) { 252 if (ret == -ENOMEM) { 253 ath_dbg(common, BSTUCK, 254 "Failed to send beacon, no free TX buffer\n"); 255 } 256 dev_kfree_skb_any(beacon); 257 } 258 259 spin_unlock_bh(&priv->beacon_lock); 260 261 ath9k_htc_csa_is_finished(priv); 262 } 263 264 static int ath9k_htc_choose_bslot(struct ath9k_htc_priv *priv, 265 struct wmi_event_swba *swba) 266 { 267 struct ath_common *common = ath9k_hw_common(priv->ah); 268 u64 tsf; 269 u32 tsftu; 270 u16 intval; 271 int slot; 272 273 intval = priv->cur_beacon_conf.beacon_interval; 274 275 tsf = be64_to_cpu(swba->tsf); 276 tsftu = TSF_TO_TU(tsf >> 32, tsf); 277 slot = ((tsftu % intval) * ATH9K_HTC_MAX_BCN_VIF) / intval; 278 slot = ATH9K_HTC_MAX_BCN_VIF - slot - 1; 279 280 ath_dbg(common, BEACON, 281 "Choose slot: %d, tsf: %llu, tsftu: %u, intval: %u\n", 282 slot, tsf, tsftu, intval); 283 284 return slot; 285 } 286 287 void ath9k_htc_swba(struct ath9k_htc_priv *priv, 288 struct wmi_event_swba *swba) 289 { 290 struct ath_common *common = ath9k_hw_common(priv->ah); 291 int slot; 292 293 if (swba->beacon_pending != 0) { 294 priv->beacon.bmisscnt++; 295 if (priv->beacon.bmisscnt > BSTUCK_THRESHOLD) { 296 ath_dbg(common, BSTUCK, "Beacon stuck, HW reset\n"); 297 ieee80211_queue_work(priv->hw, 298 &priv->fatal_work); 299 } 300 return; 301 } 302 303 if (priv->beacon.bmisscnt) { 304 ath_dbg(common, BSTUCK, 305 "Resuming beacon xmit after %u misses\n", 306 priv->beacon.bmisscnt); 307 priv->beacon.bmisscnt = 0; 308 } 309 310 slot = ath9k_htc_choose_bslot(priv, swba); 311 spin_lock_bh(&priv->beacon_lock); 312 if (priv->beacon.bslot[slot] == NULL) { 313 spin_unlock_bh(&priv->beacon_lock); 314 return; 315 } 316 spin_unlock_bh(&priv->beacon_lock); 317 318 ath9k_htc_send_buffered(priv, slot); 319 ath9k_htc_send_beacon(priv, slot); 320 } 321 322 void ath9k_htc_assign_bslot(struct ath9k_htc_priv *priv, 323 struct ieee80211_vif *vif) 324 { 325 struct ath_common *common = ath9k_hw_common(priv->ah); 326 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv; 327 int i = 0; 328 329 spin_lock_bh(&priv->beacon_lock); 330 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) { 331 if (priv->beacon.bslot[i] == NULL) { 332 avp->bslot = i; 333 break; 334 } 335 } 336 337 priv->beacon.bslot[avp->bslot] = vif; 338 spin_unlock_bh(&priv->beacon_lock); 339 340 ath_dbg(common, CONFIG, "Added interface at beacon slot: %d\n", 341 avp->bslot); 342 } 343 344 void ath9k_htc_remove_bslot(struct ath9k_htc_priv *priv, 345 struct ieee80211_vif *vif) 346 { 347 struct ath_common *common = ath9k_hw_common(priv->ah); 348 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv; 349 350 spin_lock_bh(&priv->beacon_lock); 351 priv->beacon.bslot[avp->bslot] = NULL; 352 spin_unlock_bh(&priv->beacon_lock); 353 354 ath_dbg(common, CONFIG, "Removed interface at beacon slot: %d\n", 355 avp->bslot); 356 } 357 358 /* 359 * Calculate the TSF adjustment value for all slots 360 * other than zero. 361 */ 362 void ath9k_htc_set_tsfadjust(struct ath9k_htc_priv *priv, 363 struct ieee80211_vif *vif) 364 { 365 struct ath_common *common = ath9k_hw_common(priv->ah); 366 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *)vif->drv_priv; 367 struct ath_beacon_config *cur_conf = &priv->cur_beacon_conf; 368 u64 tsfadjust; 369 370 if (avp->bslot == 0) 371 return; 372 373 /* 374 * The beacon interval cannot be different for multi-AP mode, 375 * and we reach here only for VIF slots greater than zero, 376 * so beacon_interval is guaranteed to be set in cur_conf. 377 */ 378 tsfadjust = cur_conf->beacon_interval * avp->bslot / ATH9K_HTC_MAX_BCN_VIF; 379 avp->tsfadjust = cpu_to_le64(TU_TO_USEC(tsfadjust)); 380 381 ath_dbg(common, CONFIG, "tsfadjust is: %llu for bslot: %d\n", 382 (unsigned long long)tsfadjust, avp->bslot); 383 } 384 385 static void ath9k_htc_beacon_iter(void *data, u8 *mac, struct ieee80211_vif *vif) 386 { 387 bool *beacon_configured = (bool *)data; 388 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; 389 390 if (vif->type == NL80211_IFTYPE_STATION && 391 avp->beacon_configured) 392 *beacon_configured = true; 393 } 394 395 static bool ath9k_htc_check_beacon_config(struct ath9k_htc_priv *priv, 396 struct ieee80211_vif *vif) 397 { 398 struct ath_common *common = ath9k_hw_common(priv->ah); 399 struct ath_beacon_config *cur_conf = &priv->cur_beacon_conf; 400 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 401 bool beacon_configured; 402 403 /* 404 * Changing the beacon interval when multiple AP interfaces 405 * are configured will affect beacon transmission of all 406 * of them. 407 */ 408 if ((priv->ah->opmode == NL80211_IFTYPE_AP) && 409 (priv->num_ap_vif > 1) && 410 (vif->type == NL80211_IFTYPE_AP) && 411 (cur_conf->beacon_interval != bss_conf->beacon_int)) { 412 ath_dbg(common, CONFIG, 413 "Changing beacon interval of multiple AP interfaces !\n"); 414 return false; 415 } 416 417 /* 418 * If the HW is operating in AP mode, any new station interfaces that 419 * are added cannot change the beacon parameters. 420 */ 421 if (priv->num_ap_vif && 422 (vif->type != NL80211_IFTYPE_AP)) { 423 ath_dbg(common, CONFIG, 424 "HW in AP mode, cannot set STA beacon parameters\n"); 425 return false; 426 } 427 428 /* 429 * The beacon parameters are configured only for the first 430 * station interface. 431 */ 432 if ((priv->ah->opmode == NL80211_IFTYPE_STATION) && 433 (priv->num_sta_vif > 1) && 434 (vif->type == NL80211_IFTYPE_STATION)) { 435 beacon_configured = false; 436 ieee80211_iterate_active_interfaces_atomic( 437 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL, 438 ath9k_htc_beacon_iter, &beacon_configured); 439 440 if (beacon_configured) { 441 ath_dbg(common, CONFIG, 442 "Beacon already configured for a station interface\n"); 443 return false; 444 } 445 } 446 447 return true; 448 } 449 450 void ath9k_htc_beacon_config(struct ath9k_htc_priv *priv, 451 struct ieee80211_vif *vif) 452 { 453 struct ath_common *common = ath9k_hw_common(priv->ah); 454 struct ath_beacon_config *cur_conf = &priv->cur_beacon_conf; 455 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 456 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; 457 458 if (!ath9k_htc_check_beacon_config(priv, vif)) 459 return; 460 461 cur_conf->beacon_interval = bss_conf->beacon_int; 462 if (cur_conf->beacon_interval == 0) 463 cur_conf->beacon_interval = 100; 464 465 cur_conf->dtim_period = bss_conf->dtim_period; 466 cur_conf->bmiss_timeout = 467 ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval; 468 469 switch (vif->type) { 470 case NL80211_IFTYPE_STATION: 471 ath9k_htc_beacon_config_sta(priv, cur_conf); 472 avp->beacon_configured = true; 473 break; 474 case NL80211_IFTYPE_ADHOC: 475 ath9k_htc_beacon_config_adhoc(priv, cur_conf); 476 break; 477 case NL80211_IFTYPE_MESH_POINT: 478 case NL80211_IFTYPE_AP: 479 ath9k_htc_beacon_config_ap(priv, cur_conf); 480 break; 481 default: 482 ath_dbg(common, CONFIG, "Unsupported beaconing mode\n"); 483 return; 484 } 485 } 486 487 void ath9k_htc_beacon_reconfig(struct ath9k_htc_priv *priv) 488 { 489 struct ath_common *common = ath9k_hw_common(priv->ah); 490 struct ath_beacon_config *cur_conf = &priv->cur_beacon_conf; 491 492 switch (priv->ah->opmode) { 493 case NL80211_IFTYPE_STATION: 494 ath9k_htc_beacon_config_sta(priv, cur_conf); 495 break; 496 case NL80211_IFTYPE_ADHOC: 497 ath9k_htc_beacon_config_adhoc(priv, cur_conf); 498 break; 499 case NL80211_IFTYPE_MESH_POINT: 500 case NL80211_IFTYPE_AP: 501 ath9k_htc_beacon_config_ap(priv, cur_conf); 502 break; 503 default: 504 ath_dbg(common, CONFIG, "Unsupported beaconing mode\n"); 505 return; 506 } 507 } 508 509 bool ath9k_htc_csa_is_finished(struct ath9k_htc_priv *priv) 510 { 511 struct ieee80211_vif *vif; 512 513 vif = priv->csa_vif; 514 if (!vif || !vif->csa_active) 515 return false; 516 517 if (!ieee80211_csa_is_complete(vif)) 518 return false; 519 520 ieee80211_csa_finish(vif); 521 522 priv->csa_vif = NULL; 523 return true; 524 }
1 /* 2 * Copyright (c) 2010-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include "htc.h" 18 19 static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf, 20 size_t count, loff_t *ppos) 21 { 22 struct ath9k_htc_priv *priv = file->private_data; 23 struct ath9k_htc_target_int_stats cmd_rsp; 24 char buf[512]; 25 unsigned int len = 0; 26 int ret = 0; 27 28 memset(&cmd_rsp, 0, sizeof(cmd_rsp)); 29 30 ath9k_htc_ps_wakeup(priv); 31 32 WMI_CMD(WMI_INT_STATS_CMDID); 33 if (ret) { 34 ath9k_htc_ps_restore(priv); 35 return -EINVAL; 36 } 37 38 ath9k_htc_ps_restore(priv); 39 40 len += scnprintf(buf + len, sizeof(buf) - len, 41 "%20s : %10u\n", "RX", 42 be32_to_cpu(cmd_rsp.rx)); 43 44 len += scnprintf(buf + len, sizeof(buf) - len, 45 "%20s : %10u\n", "RXORN", 46 be32_to_cpu(cmd_rsp.rxorn)); 47 48 len += scnprintf(buf + len, sizeof(buf) - len, 49 "%20s : %10u\n", "RXEOL", 50 be32_to_cpu(cmd_rsp.rxeol)); 51 52 len += scnprintf(buf + len, sizeof(buf) - len, 53 "%20s : %10u\n", "TXURN", 54 be32_to_cpu(cmd_rsp.txurn)); 55 56 len += scnprintf(buf + len, sizeof(buf) - len, 57 "%20s : %10u\n", "TXTO", 58 be32_to_cpu(cmd_rsp.txto)); 59 60 len += scnprintf(buf + len, sizeof(buf) - len, 61 "%20s : %10u\n", "CST", 62 be32_to_cpu(cmd_rsp.cst)); 63 64 if (len > sizeof(buf)) 65 len = sizeof(buf); 66 67 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 68 } 69 70 static const struct file_operations fops_tgt_int_stats = { 71 .read = read_file_tgt_int_stats, 72 .open = simple_open, 73 .owner = THIS_MODULE, 74 .llseek = default_llseek, 75 }; 76 77 static ssize_t read_file_tgt_tx_stats(struct file *file, char __user *user_buf, 78 size_t count, loff_t *ppos) 79 { 80 struct ath9k_htc_priv *priv = file->private_data; 81 struct ath9k_htc_target_tx_stats cmd_rsp; 82 char buf[512]; 83 unsigned int len = 0; 84 int ret = 0; 85 86 memset(&cmd_rsp, 0, sizeof(cmd_rsp)); 87 88 ath9k_htc_ps_wakeup(priv); 89 90 WMI_CMD(WMI_TX_STATS_CMDID); 91 if (ret) { 92 ath9k_htc_ps_restore(priv); 93 return -EINVAL; 94 } 95 96 ath9k_htc_ps_restore(priv); 97 98 len += scnprintf(buf + len, sizeof(buf) - len, 99 "%20s : %10u\n", "Xretries", 100 be32_to_cpu(cmd_rsp.xretries)); 101 102 len += scnprintf(buf + len, sizeof(buf) - len, 103 "%20s : %10u\n", "FifoErr", 104 be32_to_cpu(cmd_rsp.fifoerr)); 105 106 len += scnprintf(buf + len, sizeof(buf) - len, 107 "%20s : %10u\n", "Filtered", 108 be32_to_cpu(cmd_rsp.filtered)); 109 110 len += scnprintf(buf + len, sizeof(buf) - len, 111 "%20s : %10u\n", "TimerExp", 112 be32_to_cpu(cmd_rsp.timer_exp)); 113 114 len += scnprintf(buf + len, sizeof(buf) - len, 115 "%20s : %10u\n", "ShortRetries", 116 be32_to_cpu(cmd_rsp.shortretries)); 117 118 len += scnprintf(buf + len, sizeof(buf) - len, 119 "%20s : %10u\n", "LongRetries", 120 be32_to_cpu(cmd_rsp.longretries)); 121 122 len += scnprintf(buf + len, sizeof(buf) - len, 123 "%20s : %10u\n", "QueueNull", 124 be32_to_cpu(cmd_rsp.qnull)); 125 126 len += scnprintf(buf + len, sizeof(buf) - len, 127 "%20s : %10u\n", "EncapFail", 128 be32_to_cpu(cmd_rsp.encap_fail)); 129 130 len += scnprintf(buf + len, sizeof(buf) - len, 131 "%20s : %10u\n", "NoBuf", 132 be32_to_cpu(cmd_rsp.nobuf)); 133 134 if (len > sizeof(buf)) 135 len = sizeof(buf); 136 137 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 138 } 139 140 static const struct file_operations fops_tgt_tx_stats = { 141 .read = read_file_tgt_tx_stats, 142 .open = simple_open, 143 .owner = THIS_MODULE, 144 .llseek = default_llseek, 145 }; 146 147 static ssize_t read_file_tgt_rx_stats(struct file *file, char __user *user_buf, 148 size_t count, loff_t *ppos) 149 { 150 struct ath9k_htc_priv *priv = file->private_data; 151 struct ath9k_htc_target_rx_stats cmd_rsp; 152 char buf[512]; 153 unsigned int len = 0; 154 int ret = 0; 155 156 memset(&cmd_rsp, 0, sizeof(cmd_rsp)); 157 158 ath9k_htc_ps_wakeup(priv); 159 160 WMI_CMD(WMI_RX_STATS_CMDID); 161 if (ret) { 162 ath9k_htc_ps_restore(priv); 163 return -EINVAL; 164 } 165 166 ath9k_htc_ps_restore(priv); 167 168 len += scnprintf(buf + len, sizeof(buf) - len, 169 "%20s : %10u\n", "NoBuf", 170 be32_to_cpu(cmd_rsp.nobuf)); 171 172 len += scnprintf(buf + len, sizeof(buf) - len, 173 "%20s : %10u\n", "HostSend", 174 be32_to_cpu(cmd_rsp.host_send)); 175 176 len += scnprintf(buf + len, sizeof(buf) - len, 177 "%20s : %10u\n", "HostDone", 178 be32_to_cpu(cmd_rsp.host_done)); 179 180 if (len > sizeof(buf)) 181 len = sizeof(buf); 182 183 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 184 } 185 186 static const struct file_operations fops_tgt_rx_stats = { 187 .read = read_file_tgt_rx_stats, 188 .open = simple_open, 189 .owner = THIS_MODULE, 190 .llseek = default_llseek, 191 }; 192 193 static ssize_t read_file_xmit(struct file *file, char __user *user_buf, 194 size_t count, loff_t *ppos) 195 { 196 struct ath9k_htc_priv *priv = file->private_data; 197 char buf[512]; 198 unsigned int len = 0; 199 200 len += scnprintf(buf + len, sizeof(buf) - len, 201 "%20s : %10u\n", "Buffers queued", 202 priv->debug.tx_stats.buf_queued); 203 len += scnprintf(buf + len, sizeof(buf) - len, 204 "%20s : %10u\n", "Buffers completed", 205 priv->debug.tx_stats.buf_completed); 206 len += scnprintf(buf + len, sizeof(buf) - len, 207 "%20s : %10u\n", "SKBs queued", 208 priv->debug.tx_stats.skb_queued); 209 len += scnprintf(buf + len, sizeof(buf) - len, 210 "%20s : %10u\n", "SKBs success", 211 priv->debug.tx_stats.skb_success); 212 len += scnprintf(buf + len, sizeof(buf) - len, 213 "%20s : %10u\n", "SKBs failed", 214 priv->debug.tx_stats.skb_failed); 215 len += scnprintf(buf + len, sizeof(buf) - len, 216 "%20s : %10u\n", "CAB queued", 217 priv->debug.tx_stats.cab_queued); 218 219 len += scnprintf(buf + len, sizeof(buf) - len, 220 "%20s : %10u\n", "BE queued", 221 priv->debug.tx_stats.queue_stats[IEEE80211_AC_BE]); 222 len += scnprintf(buf + len, sizeof(buf) - len, 223 "%20s : %10u\n", "BK queued", 224 priv->debug.tx_stats.queue_stats[IEEE80211_AC_BK]); 225 len += scnprintf(buf + len, sizeof(buf) - len, 226 "%20s : %10u\n", "VI queued", 227 priv->debug.tx_stats.queue_stats[IEEE80211_AC_VI]); 228 len += scnprintf(buf + len, sizeof(buf) - len, 229 "%20s : %10u\n", "VO queued", 230 priv->debug.tx_stats.queue_stats[IEEE80211_AC_VO]); 231 232 if (len > sizeof(buf)) 233 len = sizeof(buf); 234 235 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 236 } 237 238 static const struct file_operations fops_xmit = { 239 .read = read_file_xmit, 240 .open = simple_open, 241 .owner = THIS_MODULE, 242 .llseek = default_llseek, 243 }; 244 245 void ath9k_htc_err_stat_rx(struct ath9k_htc_priv *priv, 246 struct ath_rx_status *rs) 247 { 248 ath9k_cmn_debug_stat_rx(&priv->debug.rx_stats, rs); 249 } 250 251 static ssize_t read_file_skb_rx(struct file *file, char __user *user_buf, 252 size_t count, loff_t *ppos) 253 { 254 struct ath9k_htc_priv *priv = file->private_data; 255 char *buf; 256 unsigned int len = 0, size = 1500; 257 ssize_t retval = 0; 258 259 buf = kzalloc(size, GFP_KERNEL); 260 if (buf == NULL) 261 return -ENOMEM; 262 263 len += scnprintf(buf + len, size - len, 264 "%20s : %10u\n", "SKBs allocated", 265 priv->debug.skbrx_stats.skb_allocated); 266 len += scnprintf(buf + len, size - len, 267 "%20s : %10u\n", "SKBs completed", 268 priv->debug.skbrx_stats.skb_completed); 269 len += scnprintf(buf + len, size - len, 270 "%20s : %10u\n", "SKBs Dropped", 271 priv->debug.skbrx_stats.skb_dropped); 272 273 if (len > size) 274 len = size; 275 276 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 277 kfree(buf); 278 279 return retval; 280 } 281 282 static const struct file_operations fops_skb_rx = { 283 .read = read_file_skb_rx, 284 .open = simple_open, 285 .owner = THIS_MODULE, 286 .llseek = default_llseek, 287 }; 288 289 static ssize_t read_file_slot(struct file *file, char __user *user_buf, 290 size_t count, loff_t *ppos) 291 { 292 struct ath9k_htc_priv *priv = file->private_data; 293 char buf[512]; 294 unsigned int len; 295 296 spin_lock_bh(&priv->tx.tx_lock); 297 len = scnprintf(buf, sizeof(buf), 298 "TX slot bitmap : %*pb\n" 299 "Used slots : %d\n", 300 MAX_TX_BUF_NUM, priv->tx.tx_slot, 301 bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM)); 302 spin_unlock_bh(&priv->tx.tx_lock); 303 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 304 } 305 306 static const struct file_operations fops_slot = { 307 .read = read_file_slot, 308 .open = simple_open, 309 .owner = THIS_MODULE, 310 .llseek = default_llseek, 311 }; 312 313 static ssize_t read_file_queue(struct file *file, char __user *user_buf, 314 size_t count, loff_t *ppos) 315 { 316 struct ath9k_htc_priv *priv = file->private_data; 317 char buf[512]; 318 unsigned int len = 0; 319 320 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 321 "Mgmt endpoint", skb_queue_len(&priv->tx.mgmt_ep_queue)); 322 323 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 324 "Cab endpoint", skb_queue_len(&priv->tx.cab_ep_queue)); 325 326 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 327 "Data BE endpoint", skb_queue_len(&priv->tx.data_be_queue)); 328 329 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 330 "Data BK endpoint", skb_queue_len(&priv->tx.data_bk_queue)); 331 332 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 333 "Data VI endpoint", skb_queue_len(&priv->tx.data_vi_queue)); 334 335 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 336 "Data VO endpoint", skb_queue_len(&priv->tx.data_vo_queue)); 337 338 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 339 "Failed queue", skb_queue_len(&priv->tx.tx_failed)); 340 341 spin_lock_bh(&priv->tx.tx_lock); 342 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 343 "Queued count", priv->tx.queued_cnt); 344 spin_unlock_bh(&priv->tx.tx_lock); 345 346 if (len > sizeof(buf)) 347 len = sizeof(buf); 348 349 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 350 351 } 352 353 static const struct file_operations fops_queue = { 354 .read = read_file_queue, 355 .open = simple_open, 356 .owner = THIS_MODULE, 357 .llseek = default_llseek, 358 }; 359 360 static ssize_t read_file_debug(struct file *file, char __user *user_buf, 361 size_t count, loff_t *ppos) 362 { 363 struct ath9k_htc_priv *priv = file->private_data; 364 struct ath_common *common = ath9k_hw_common(priv->ah); 365 char buf[32]; 366 unsigned int len; 367 368 len = sprintf(buf, "0x%08x\n", common->debug_mask); 369 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 370 } 371 372 static ssize_t write_file_debug(struct file *file, const char __user *user_buf, 373 size_t count, loff_t *ppos) 374 { 375 struct ath9k_htc_priv *priv = file->private_data; 376 struct ath_common *common = ath9k_hw_common(priv->ah); 377 unsigned long mask; 378 char buf[32]; 379 ssize_t len; 380 381 len = min(count, sizeof(buf) - 1); 382 if (copy_from_user(buf, user_buf, len)) 383 return -EFAULT; 384 385 buf[len] = '\0'; 386 if (kstrtoul(buf, 0, &mask)) 387 return -EINVAL; 388 389 common->debug_mask = mask; 390 return count; 391 } 392 393 static const struct file_operations fops_debug = { 394 .read = read_file_debug, 395 .write = write_file_debug, 396 .open = simple_open, 397 .owner = THIS_MODULE, 398 .llseek = default_llseek, 399 }; 400 401 /* Ethtool support for get-stats */ 402 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO" 403 static const char ath9k_htc_gstrings_stats[][ETH_GSTRING_LEN] = { 404 "tx_pkts_nic", 405 "tx_bytes_nic", 406 "rx_pkts_nic", 407 "rx_bytes_nic", 408 409 AMKSTR(d_tx_pkts), 410 411 "d_rx_crc_err", 412 "d_rx_decrypt_crc_err", 413 "d_rx_phy_err", 414 "d_rx_mic_err", 415 "d_rx_pre_delim_crc_err", 416 "d_rx_post_delim_crc_err", 417 "d_rx_decrypt_busy_err", 418 419 "d_rx_phyerr_radar", 420 "d_rx_phyerr_ofdm_timing", 421 "d_rx_phyerr_cck_timing", 422 423 }; 424 #define ATH9K_HTC_SSTATS_LEN ARRAY_SIZE(ath9k_htc_gstrings_stats) 425 426 void ath9k_htc_get_et_strings(struct ieee80211_hw *hw, 427 struct ieee80211_vif *vif, 428 u32 sset, u8 *data) 429 { 430 if (sset == ETH_SS_STATS) 431 memcpy(data, *ath9k_htc_gstrings_stats, 432 sizeof(ath9k_htc_gstrings_stats)); 433 } 434 435 int ath9k_htc_get_et_sset_count(struct ieee80211_hw *hw, 436 struct ieee80211_vif *vif, int sset) 437 { 438 if (sset == ETH_SS_STATS) 439 return ATH9K_HTC_SSTATS_LEN; 440 return 0; 441 } 442 443 #define STXBASE priv->debug.tx_stats 444 #define SRXBASE priv->debug.rx_stats 445 #define SKBTXBASE priv->debug.tx_stats 446 #define SKBRXBASE priv->debug.skbrx_stats 447 #define ASTXQ(a) \ 448 data[i++] = STXBASE.a[IEEE80211_AC_BE]; \ 449 data[i++] = STXBASE.a[IEEE80211_AC_BK]; \ 450 data[i++] = STXBASE.a[IEEE80211_AC_VI]; \ 451 data[i++] = STXBASE.a[IEEE80211_AC_VO] 452 453 void ath9k_htc_get_et_stats(struct ieee80211_hw *hw, 454 struct ieee80211_vif *vif, 455 struct ethtool_stats *stats, u64 *data) 456 { 457 struct ath9k_htc_priv *priv = hw->priv; 458 int i = 0; 459 460 data[i++] = SKBTXBASE.skb_success; 461 data[i++] = SKBTXBASE.skb_success_bytes; 462 data[i++] = SKBRXBASE.skb_completed; 463 data[i++] = SKBRXBASE.skb_completed_bytes; 464 465 ASTXQ(queue_stats); 466 467 data[i++] = SRXBASE.crc_err; 468 data[i++] = SRXBASE.decrypt_crc_err; 469 data[i++] = SRXBASE.phy_err; 470 data[i++] = SRXBASE.mic_err; 471 data[i++] = SRXBASE.pre_delim_crc_err; 472 data[i++] = SRXBASE.post_delim_crc_err; 473 data[i++] = SRXBASE.decrypt_busy_err; 474 475 data[i++] = SRXBASE.phy_err_stats[ATH9K_PHYERR_RADAR]; 476 data[i++] = SRXBASE.phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]; 477 data[i++] = SRXBASE.phy_err_stats[ATH9K_PHYERR_CCK_TIMING]; 478 479 WARN_ON(i != ATH9K_HTC_SSTATS_LEN); 480 } 481 482 void ath9k_htc_deinit_debug(struct ath9k_htc_priv *priv) 483 { 484 ath9k_cmn_spectral_deinit_debug(&priv->spec_priv); 485 } 486 487 int ath9k_htc_init_debug(struct ath_hw *ah) 488 { 489 struct ath_common *common = ath9k_hw_common(ah); 490 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 491 492 priv->debug.debugfs_phy = debugfs_create_dir(KBUILD_MODNAME, 493 priv->hw->wiphy->debugfsdir); 494 if (!priv->debug.debugfs_phy) 495 return -ENOMEM; 496 497 ath9k_cmn_spectral_init_debug(&priv->spec_priv, priv->debug.debugfs_phy); 498 499 debugfs_create_file("tgt_int_stats", S_IRUSR, priv->debug.debugfs_phy, 500 priv, &fops_tgt_int_stats); 501 debugfs_create_file("tgt_tx_stats", S_IRUSR, priv->debug.debugfs_phy, 502 priv, &fops_tgt_tx_stats); 503 debugfs_create_file("tgt_rx_stats", S_IRUSR, priv->debug.debugfs_phy, 504 priv, &fops_tgt_rx_stats); 505 debugfs_create_file("xmit", S_IRUSR, priv->debug.debugfs_phy, 506 priv, &fops_xmit); 507 debugfs_create_file("skb_rx", S_IRUSR, priv->debug.debugfs_phy, 508 priv, &fops_skb_rx); 509 510 ath9k_cmn_debug_recv(priv->debug.debugfs_phy, &priv->debug.rx_stats); 511 ath9k_cmn_debug_phy_err(priv->debug.debugfs_phy, &priv->debug.rx_stats); 512 513 debugfs_create_file("slot", S_IRUSR, priv->debug.debugfs_phy, 514 priv, &fops_slot); 515 debugfs_create_file("queue", S_IRUSR, priv->debug.debugfs_phy, 516 priv, &fops_queue); 517 debugfs_create_file("debug", S_IRUSR | S_IWUSR, priv->debug.debugfs_phy, 518 priv, &fops_debug); 519 520 ath9k_cmn_debug_base_eeprom(priv->debug.debugfs_phy, priv->ah); 521 ath9k_cmn_debug_modal_eeprom(priv->debug.debugfs_phy, priv->ah); 522 523 return 0; 524 }
1 2 #include <linux/kernel.h> 3 #include <linux/mutex.h> 4 #include <linux/spinlock.h> 5 #include <linux/errno.h> 6 #include <verifier/rcv.h> 7 #include <linux/list.h> 8 9 /* mutexes */ 10 extern int mutex_lock_interruptible(struct mutex *lock); 11 extern int mutex_lock_killable(struct mutex *lock); 12 extern void mutex_lock(struct mutex *lock); 13 14 /* mutex model functions */ 15 extern void ldv_mutex_lock(struct mutex *lock, char *sign); 16 extern int ldv_mutex_is_locked(struct mutex *lock, char *sign); 17 extern void ldv_mutex_unlock(struct mutex *lock, char *sign); 18 19 20 /* Spin locks */ 21 extern void __ldv_spin_lock(spinlock_t *lock); 22 extern void __ldv_spin_unlock(spinlock_t *lock); 23 extern int __ldv_spin_trylock(spinlock_t *lock); 24 extern void __ldv_spin_unlock_wait(spinlock_t *lock); 25 extern void __ldv_spin_can_lock(spinlock_t *lock); 26 extern int __ldv_atomic_dec_and_lock(spinlock_t *lock); 27 28 /* spin model functions */ 29 extern void ldv_spin_lock(spinlock_t *lock, char *sign); 30 extern void ldv_spin_unlock(spinlock_t *lock, char *sign); 31 extern int ldv_spin_is_locked(spinlock_t *lock, char *sign); 32 33 /* Support for list binder functions */ 34 static inline struct list_head *ldv_list_get_first(struct list_head *head) { 35 return head->next; 36 } 37 38 static inline int ldv_list_is_stop(struct list_head *pos, struct list_head *head) { 39 return pos==head; 40 } 41 42 static inline struct list_head *ldv_list_get_next(struct list_head *pos) { 43 return pos->next; 44 } 45 46 #include <linux/mutex.h> 47 #include <linux/slab.h> 48 #include <verifier/rcv.h> 49 #include <linux/timer.h> 50 #include <linux/rtnetlink.h> 51 #include <linux/gfp.h> 52 extern struct file *fops_xmit_group2; 53 extern int ldv_state_variable_8; 54 extern int ldv_timer_1_3; 55 extern struct ath_common *ath9k_usb_bus_ops_group0; 56 extern struct inode *fops_debug_group1; 57 extern struct inode *fops_queue_group1; 58 extern struct ath_common *ath9k_htc_ps_ops_group0; 59 extern int ldv_state_variable_0; 60 extern int ldv_state_variable_5; 61 extern int ldv_state_variable_13; 62 extern int ldv_state_variable_12; 63 extern struct file *fops_tgt_tx_stats_group2; 64 extern struct file *fops_queue_group2; 65 extern int ldv_state_variable_14; 66 extern int ldv_timer_1_0; 67 extern int ldv_state_variable_9; 68 extern struct inode *fops_tgt_tx_stats_group1; 69 extern struct file *fops_debug_group2; 70 extern int ref_cnt; 71 extern struct mutex key_mtx; 72 extern int ldv_state_variable_1; 73 extern int ldv_state_variable_7; 74 extern struct inode *fops_xmit_group1; 75 extern struct inode *fops_skb_rx_group1; 76 extern struct file *fops_tgt_int_stats_group2; 77 extern struct usb_interface *ath9k_hif_usb_driver_group1; 78 extern struct timer_list * ldv_timer_list_1_3; 79 extern int ldv_state_variable_10; 80 extern struct timer_list * ldv_timer_list_1_1; 81 extern struct timer_list * ldv_timer_list_1_0; 82 extern int ldv_state_variable_6; 83 extern int ldv_timer_1_2; 84 extern int ldv_timer_1_1; 85 extern int ldv_state_variable_2; 86 extern struct timer_list * ldv_timer_list_1_2; 87 extern struct inode *fops_tgt_int_stats_group1; 88 extern struct ieee80211_hw *ath9k_htc_ops_group0; 89 extern int usb_counter; 90 extern int ldv_state_variable_11; 91 extern struct file *fops_slot_group2; 92 extern int LDV_IN_INTERRUPT = 1; 93 extern struct inode *fops_slot_group1; 94 extern struct inode *fops_tgt_rx_stats_group1; 95 extern struct file *fops_tgt_rx_stats_group2; 96 extern struct mutex fs_mutex; 97 extern int ldv_state_variable_3; 98 extern struct mutex ar_mutex; 99 extern struct file *fops_skb_rx_group2; 100 extern int ldv_state_variable_4; 101 extern void ldv_file_operations_7(void); 102 extern void ldv_file_operations_6(void); 103 extern void ldv_file_operations_2(void); 104 extern void activate_pending_timer_1(struct timer_list * timer, unsigned long data, int pending_flag); 105 extern void ldv_initialyze_ath_bus_ops_10(void); 106 extern int evil_hack_12(void); 107 extern void timer_init_1(void); 108 extern void ldv_file_operations_9(void); 109 extern void ldv_usb_driver_13(void); 110 extern void ldv_file_operations_3(void); 111 extern void ldv_file_operations_8(void); 112 extern int reg_timer_1(struct timer_list * timer, void (*function)(unsigned long), unsigned long data); 113 extern void ldv_initialyze_ath_ps_ops_11(void); 114 extern int evil_hack_key_12(void); 115 extern void ldv_initialyze_ieee80211_ops_12(void); 116 extern void disable_suitable_timer_1(struct timer_list * timer); 117 extern void activate_suitable_timer_1(struct timer_list * timer, unsigned long data); 118 extern int evil_hack_fs_lock(void); 119 extern int __VERIFIER_nondet_int(void); 120 extern void ldv_file_operations_5(void); 121 extern void choose_timer_1(void); 122 extern void ldv_timer_1(int state, struct timer_list * timer); 123 extern int evil_hack_ar_lock(void); 124 extern void ldv_file_operations_4(void); 125 #line 1 "/work/ldvuser/andrianov/work/current--X--drivers/net/wireless/ath/ath9k/--X--defaultlinux-4.5-rc7--X--races--X--cpachecker/linux-4.5-rc7/csd_deg_dscv/74/dscv_tempdir/dscv/ri/races/drivers/net/wireless/ath/ath9k/htc_drv_debug.c" 126 /* 127 * Copyright (c) 2010-2011 Atheros Communications Inc. 128 * 129 * Permission to use, copy, modify, and/or distribute this software for any 130 * purpose with or without fee is hereby granted, provided that the above 131 * copyright notice and this permission notice appear in all copies. 132 * 133 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 134 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 135 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 136 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 137 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 139 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 140 */ 141 142 #include "htc.h" 143 144 static ssize_t read_file_tgt_int_stats(struct file *file, char __user *user_buf, 145 size_t count, loff_t *ppos) 146 { 147 struct ath9k_htc_priv *priv = file->private_data; 148 struct ath9k_htc_target_int_stats cmd_rsp; 149 char buf[512]; 150 unsigned int len = 0; 151 int ret = 0; 152 153 memset(&cmd_rsp, 0, sizeof(cmd_rsp)); 154 155 ath9k_htc_ps_wakeup(priv); 156 157 WMI_CMD(WMI_INT_STATS_CMDID); 158 if (ret) { 159 ath9k_htc_ps_restore(priv); 160 return -EINVAL; 161 } 162 163 ath9k_htc_ps_restore(priv); 164 165 len += scnprintf(buf + len, sizeof(buf) - len, 166 "%20s : %10u\n", "RX", 167 be32_to_cpu(cmd_rsp.rx)); 168 169 len += scnprintf(buf + len, sizeof(buf) - len, 170 "%20s : %10u\n", "RXORN", 171 be32_to_cpu(cmd_rsp.rxorn)); 172 173 len += scnprintf(buf + len, sizeof(buf) - len, 174 "%20s : %10u\n", "RXEOL", 175 be32_to_cpu(cmd_rsp.rxeol)); 176 177 len += scnprintf(buf + len, sizeof(buf) - len, 178 "%20s : %10u\n", "TXURN", 179 be32_to_cpu(cmd_rsp.txurn)); 180 181 len += scnprintf(buf + len, sizeof(buf) - len, 182 "%20s : %10u\n", "TXTO", 183 be32_to_cpu(cmd_rsp.txto)); 184 185 len += scnprintf(buf + len, sizeof(buf) - len, 186 "%20s : %10u\n", "CST", 187 be32_to_cpu(cmd_rsp.cst)); 188 189 if (len > sizeof(buf)) 190 len = sizeof(buf); 191 192 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 193 } 194 195 static const struct file_operations fops_tgt_int_stats = { 196 .read = read_file_tgt_int_stats, 197 .open = simple_open, 198 .owner = THIS_MODULE, 199 .llseek = default_llseek, 200 }; 201 202 static ssize_t read_file_tgt_tx_stats(struct file *file, char __user *user_buf, 203 size_t count, loff_t *ppos) 204 { 205 struct ath9k_htc_priv *priv = file->private_data; 206 struct ath9k_htc_target_tx_stats cmd_rsp; 207 char buf[512]; 208 unsigned int len = 0; 209 int ret = 0; 210 211 memset(&cmd_rsp, 0, sizeof(cmd_rsp)); 212 213 ath9k_htc_ps_wakeup(priv); 214 215 WMI_CMD(WMI_TX_STATS_CMDID); 216 if (ret) { 217 ath9k_htc_ps_restore(priv); 218 return -EINVAL; 219 } 220 221 ath9k_htc_ps_restore(priv); 222 223 len += scnprintf(buf + len, sizeof(buf) - len, 224 "%20s : %10u\n", "Xretries", 225 be32_to_cpu(cmd_rsp.xretries)); 226 227 len += scnprintf(buf + len, sizeof(buf) - len, 228 "%20s : %10u\n", "FifoErr", 229 be32_to_cpu(cmd_rsp.fifoerr)); 230 231 len += scnprintf(buf + len, sizeof(buf) - len, 232 "%20s : %10u\n", "Filtered", 233 be32_to_cpu(cmd_rsp.filtered)); 234 235 len += scnprintf(buf + len, sizeof(buf) - len, 236 "%20s : %10u\n", "TimerExp", 237 be32_to_cpu(cmd_rsp.timer_exp)); 238 239 len += scnprintf(buf + len, sizeof(buf) - len, 240 "%20s : %10u\n", "ShortRetries", 241 be32_to_cpu(cmd_rsp.shortretries)); 242 243 len += scnprintf(buf + len, sizeof(buf) - len, 244 "%20s : %10u\n", "LongRetries", 245 be32_to_cpu(cmd_rsp.longretries)); 246 247 len += scnprintf(buf + len, sizeof(buf) - len, 248 "%20s : %10u\n", "QueueNull", 249 be32_to_cpu(cmd_rsp.qnull)); 250 251 len += scnprintf(buf + len, sizeof(buf) - len, 252 "%20s : %10u\n", "EncapFail", 253 be32_to_cpu(cmd_rsp.encap_fail)); 254 255 len += scnprintf(buf + len, sizeof(buf) - len, 256 "%20s : %10u\n", "NoBuf", 257 be32_to_cpu(cmd_rsp.nobuf)); 258 259 if (len > sizeof(buf)) 260 len = sizeof(buf); 261 262 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 263 } 264 265 static const struct file_operations fops_tgt_tx_stats = { 266 .read = read_file_tgt_tx_stats, 267 .open = simple_open, 268 .owner = THIS_MODULE, 269 .llseek = default_llseek, 270 }; 271 272 static ssize_t read_file_tgt_rx_stats(struct file *file, char __user *user_buf, 273 size_t count, loff_t *ppos) 274 { 275 struct ath9k_htc_priv *priv = file->private_data; 276 struct ath9k_htc_target_rx_stats cmd_rsp; 277 char buf[512]; 278 unsigned int len = 0; 279 int ret = 0; 280 281 memset(&cmd_rsp, 0, sizeof(cmd_rsp)); 282 283 ath9k_htc_ps_wakeup(priv); 284 285 WMI_CMD(WMI_RX_STATS_CMDID); 286 if (ret) { 287 ath9k_htc_ps_restore(priv); 288 return -EINVAL; 289 } 290 291 ath9k_htc_ps_restore(priv); 292 293 len += scnprintf(buf + len, sizeof(buf) - len, 294 "%20s : %10u\n", "NoBuf", 295 be32_to_cpu(cmd_rsp.nobuf)); 296 297 len += scnprintf(buf + len, sizeof(buf) - len, 298 "%20s : %10u\n", "HostSend", 299 be32_to_cpu(cmd_rsp.host_send)); 300 301 len += scnprintf(buf + len, sizeof(buf) - len, 302 "%20s : %10u\n", "HostDone", 303 be32_to_cpu(cmd_rsp.host_done)); 304 305 if (len > sizeof(buf)) 306 len = sizeof(buf); 307 308 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 309 } 310 311 static const struct file_operations fops_tgt_rx_stats = { 312 .read = read_file_tgt_rx_stats, 313 .open = simple_open, 314 .owner = THIS_MODULE, 315 .llseek = default_llseek, 316 }; 317 318 static ssize_t read_file_xmit(struct file *file, char __user *user_buf, 319 size_t count, loff_t *ppos) 320 { 321 struct ath9k_htc_priv *priv = file->private_data; 322 char buf[512]; 323 unsigned int len = 0; 324 325 len += scnprintf(buf + len, sizeof(buf) - len, 326 "%20s : %10u\n", "Buffers queued", 327 priv->debug.tx_stats.buf_queued); 328 len += scnprintf(buf + len, sizeof(buf) - len, 329 "%20s : %10u\n", "Buffers completed", 330 priv->debug.tx_stats.buf_completed); 331 len += scnprintf(buf + len, sizeof(buf) - len, 332 "%20s : %10u\n", "SKBs queued", 333 priv->debug.tx_stats.skb_queued); 334 len += scnprintf(buf + len, sizeof(buf) - len, 335 "%20s : %10u\n", "SKBs success", 336 priv->debug.tx_stats.skb_success); 337 len += scnprintf(buf + len, sizeof(buf) - len, 338 "%20s : %10u\n", "SKBs failed", 339 priv->debug.tx_stats.skb_failed); 340 len += scnprintf(buf + len, sizeof(buf) - len, 341 "%20s : %10u\n", "CAB queued", 342 priv->debug.tx_stats.cab_queued); 343 344 len += scnprintf(buf + len, sizeof(buf) - len, 345 "%20s : %10u\n", "BE queued", 346 priv->debug.tx_stats.queue_stats[IEEE80211_AC_BE]); 347 len += scnprintf(buf + len, sizeof(buf) - len, 348 "%20s : %10u\n", "BK queued", 349 priv->debug.tx_stats.queue_stats[IEEE80211_AC_BK]); 350 len += scnprintf(buf + len, sizeof(buf) - len, 351 "%20s : %10u\n", "VI queued", 352 priv->debug.tx_stats.queue_stats[IEEE80211_AC_VI]); 353 len += scnprintf(buf + len, sizeof(buf) - len, 354 "%20s : %10u\n", "VO queued", 355 priv->debug.tx_stats.queue_stats[IEEE80211_AC_VO]); 356 357 if (len > sizeof(buf)) 358 len = sizeof(buf); 359 360 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 361 } 362 363 static const struct file_operations fops_xmit = { 364 .read = read_file_xmit, 365 .open = simple_open, 366 .owner = THIS_MODULE, 367 .llseek = default_llseek, 368 }; 369 370 void ath9k_htc_err_stat_rx(struct ath9k_htc_priv *priv, 371 struct ath_rx_status *rs) 372 { 373 ath9k_cmn_debug_stat_rx(&priv->debug.rx_stats, rs); 374 } 375 376 static ssize_t read_file_skb_rx(struct file *file, char __user *user_buf, 377 size_t count, loff_t *ppos) 378 { 379 struct ath9k_htc_priv *priv = file->private_data; 380 char *buf; 381 unsigned int len = 0, size = 1500; 382 ssize_t retval = 0; 383 384 buf = kzalloc(size, GFP_KERNEL); 385 if (buf == NULL) 386 return -ENOMEM; 387 388 len += scnprintf(buf + len, size - len, 389 "%20s : %10u\n", "SKBs allocated", 390 priv->debug.skbrx_stats.skb_allocated); 391 len += scnprintf(buf + len, size - len, 392 "%20s : %10u\n", "SKBs completed", 393 priv->debug.skbrx_stats.skb_completed); 394 len += scnprintf(buf + len, size - len, 395 "%20s : %10u\n", "SKBs Dropped", 396 priv->debug.skbrx_stats.skb_dropped); 397 398 if (len > size) 399 len = size; 400 401 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 402 kfree(buf); 403 404 return retval; 405 } 406 407 static const struct file_operations fops_skb_rx = { 408 .read = read_file_skb_rx, 409 .open = simple_open, 410 .owner = THIS_MODULE, 411 .llseek = default_llseek, 412 }; 413 414 static ssize_t read_file_slot(struct file *file, char __user *user_buf, 415 size_t count, loff_t *ppos) 416 { 417 struct ath9k_htc_priv *priv = file->private_data; 418 char buf[512]; 419 unsigned int len; 420 421 spin_lock_bh(&priv->tx.tx_lock); 422 len = scnprintf(buf, sizeof(buf), 423 "TX slot bitmap : %*pb\n" 424 "Used slots : %d\n", 425 MAX_TX_BUF_NUM, priv->tx.tx_slot, 426 bitmap_weight(priv->tx.tx_slot, MAX_TX_BUF_NUM)); 427 spin_unlock_bh(&priv->tx.tx_lock); 428 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 429 } 430 431 static const struct file_operations fops_slot = { 432 .read = read_file_slot, 433 .open = simple_open, 434 .owner = THIS_MODULE, 435 .llseek = default_llseek, 436 }; 437 438 static ssize_t read_file_queue(struct file *file, char __user *user_buf, 439 size_t count, loff_t *ppos) 440 { 441 struct ath9k_htc_priv *priv = file->private_data; 442 char buf[512]; 443 unsigned int len = 0; 444 445 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 446 "Mgmt endpoint", skb_queue_len(&priv->tx.mgmt_ep_queue)); 447 448 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 449 "Cab endpoint", skb_queue_len(&priv->tx.cab_ep_queue)); 450 451 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 452 "Data BE endpoint", skb_queue_len(&priv->tx.data_be_queue)); 453 454 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 455 "Data BK endpoint", skb_queue_len(&priv->tx.data_bk_queue)); 456 457 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 458 "Data VI endpoint", skb_queue_len(&priv->tx.data_vi_queue)); 459 460 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 461 "Data VO endpoint", skb_queue_len(&priv->tx.data_vo_queue)); 462 463 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 464 "Failed queue", skb_queue_len(&priv->tx.tx_failed)); 465 466 spin_lock_bh(&priv->tx.tx_lock); 467 len += scnprintf(buf + len, sizeof(buf) - len, "%20s : %10u\n", 468 "Queued count", priv->tx.queued_cnt); 469 spin_unlock_bh(&priv->tx.tx_lock); 470 471 if (len > sizeof(buf)) 472 len = sizeof(buf); 473 474 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 475 476 } 477 478 static const struct file_operations fops_queue = { 479 .read = read_file_queue, 480 .open = simple_open, 481 .owner = THIS_MODULE, 482 .llseek = default_llseek, 483 }; 484 485 static ssize_t read_file_debug(struct file *file, char __user *user_buf, 486 size_t count, loff_t *ppos) 487 { 488 struct ath9k_htc_priv *priv = file->private_data; 489 struct ath_common *common = ath9k_hw_common(priv->ah); 490 char buf[32]; 491 unsigned int len; 492 493 len = sprintf(buf, "0x%08x\n", common->debug_mask); 494 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 495 } 496 497 static ssize_t write_file_debug(struct file *file, const char __user *user_buf, 498 size_t count, loff_t *ppos) 499 { 500 struct ath9k_htc_priv *priv = file->private_data; 501 struct ath_common *common = ath9k_hw_common(priv->ah); 502 unsigned long mask; 503 char buf[32]; 504 ssize_t len; 505 506 len = min(count, sizeof(buf) - 1); 507 if (copy_from_user(buf, user_buf, len)) 508 return -EFAULT; 509 510 buf[len] = '\0'; 511 if (kstrtoul(buf, 0, &mask)) 512 return -EINVAL; 513 514 common->debug_mask = mask; 515 return count; 516 } 517 518 static const struct file_operations fops_debug = { 519 .read = read_file_debug, 520 .write = write_file_debug, 521 .open = simple_open, 522 .owner = THIS_MODULE, 523 .llseek = default_llseek, 524 }; 525 526 /* Ethtool support for get-stats */ 527 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO" 528 static const char ath9k_htc_gstrings_stats[][ETH_GSTRING_LEN] = { 529 "tx_pkts_nic", 530 "tx_bytes_nic", 531 "rx_pkts_nic", 532 "rx_bytes_nic", 533 534 AMKSTR(d_tx_pkts), 535 536 "d_rx_crc_err", 537 "d_rx_decrypt_crc_err", 538 "d_rx_phy_err", 539 "d_rx_mic_err", 540 "d_rx_pre_delim_crc_err", 541 "d_rx_post_delim_crc_err", 542 "d_rx_decrypt_busy_err", 543 544 "d_rx_phyerr_radar", 545 "d_rx_phyerr_ofdm_timing", 546 "d_rx_phyerr_cck_timing", 547 548 }; 549 #define ATH9K_HTC_SSTATS_LEN ARRAY_SIZE(ath9k_htc_gstrings_stats) 550 551 void ath9k_htc_get_et_strings(struct ieee80211_hw *hw, 552 struct ieee80211_vif *vif, 553 u32 sset, u8 *data) 554 { 555 if (sset == ETH_SS_STATS) 556 memcpy(data, *ath9k_htc_gstrings_stats, 557 sizeof(ath9k_htc_gstrings_stats)); 558 } 559 560 int ath9k_htc_get_et_sset_count(struct ieee80211_hw *hw, 561 struct ieee80211_vif *vif, int sset) 562 { 563 if (sset == ETH_SS_STATS) 564 return ATH9K_HTC_SSTATS_LEN; 565 return 0; 566 } 567 568 #define STXBASE priv->debug.tx_stats 569 #define SRXBASE priv->debug.rx_stats 570 #define SKBTXBASE priv->debug.tx_stats 571 #define SKBRXBASE priv->debug.skbrx_stats 572 #define ASTXQ(a) \ 573 data[i++] = STXBASE.a[IEEE80211_AC_BE]; \ 574 data[i++] = STXBASE.a[IEEE80211_AC_BK]; \ 575 data[i++] = STXBASE.a[IEEE80211_AC_VI]; \ 576 data[i++] = STXBASE.a[IEEE80211_AC_VO] 577 578 void ath9k_htc_get_et_stats(struct ieee80211_hw *hw, 579 struct ieee80211_vif *vif, 580 struct ethtool_stats *stats, u64 *data) 581 { 582 struct ath9k_htc_priv *priv = hw->priv; 583 int i = 0; 584 585 data[i++] = SKBTXBASE.skb_success; 586 data[i++] = SKBTXBASE.skb_success_bytes; 587 data[i++] = SKBRXBASE.skb_completed; 588 data[i++] = SKBRXBASE.skb_completed_bytes; 589 590 ASTXQ(queue_stats); 591 592 data[i++] = SRXBASE.crc_err; 593 data[i++] = SRXBASE.decrypt_crc_err; 594 data[i++] = SRXBASE.phy_err; 595 data[i++] = SRXBASE.mic_err; 596 data[i++] = SRXBASE.pre_delim_crc_err; 597 data[i++] = SRXBASE.post_delim_crc_err; 598 data[i++] = SRXBASE.decrypt_busy_err; 599 600 data[i++] = SRXBASE.phy_err_stats[ATH9K_PHYERR_RADAR]; 601 data[i++] = SRXBASE.phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]; 602 data[i++] = SRXBASE.phy_err_stats[ATH9K_PHYERR_CCK_TIMING]; 603 604 WARN_ON(i != ATH9K_HTC_SSTATS_LEN); 605 } 606 607 void ath9k_htc_deinit_debug(struct ath9k_htc_priv *priv) 608 { 609 ath9k_cmn_spectral_deinit_debug(&priv->spec_priv); 610 } 611 612 int ath9k_htc_init_debug(struct ath_hw *ah) 613 { 614 struct ath_common *common = ath9k_hw_common(ah); 615 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 616 617 priv->debug.debugfs_phy = debugfs_create_dir(KBUILD_MODNAME, 618 priv->hw->wiphy->debugfsdir); 619 if (!priv->debug.debugfs_phy) 620 return -ENOMEM; 621 622 ath9k_cmn_spectral_init_debug(&priv->spec_priv, priv->debug.debugfs_phy); 623 624 debugfs_create_file("tgt_int_stats", S_IRUSR, priv->debug.debugfs_phy, 625 priv, &fops_tgt_int_stats); 626 debugfs_create_file("tgt_tx_stats", S_IRUSR, priv->debug.debugfs_phy, 627 priv, &fops_tgt_tx_stats); 628 debugfs_create_file("tgt_rx_stats", S_IRUSR, priv->debug.debugfs_phy, 629 priv, &fops_tgt_rx_stats); 630 debugfs_create_file("xmit", S_IRUSR, priv->debug.debugfs_phy, 631 priv, &fops_xmit); 632 debugfs_create_file("skb_rx", S_IRUSR, priv->debug.debugfs_phy, 633 priv, &fops_skb_rx); 634 635 ath9k_cmn_debug_recv(priv->debug.debugfs_phy, &priv->debug.rx_stats); 636 ath9k_cmn_debug_phy_err(priv->debug.debugfs_phy, &priv->debug.rx_stats); 637 638 debugfs_create_file("slot", S_IRUSR, priv->debug.debugfs_phy, 639 priv, &fops_slot); 640 debugfs_create_file("queue", S_IRUSR, priv->debug.debugfs_phy, 641 priv, &fops_queue); 642 debugfs_create_file("debug", S_IRUSR | S_IWUSR, priv->debug.debugfs_phy, 643 priv, &fops_debug); 644 645 ath9k_cmn_debug_base_eeprom(priv->debug.debugfs_phy, priv->ah); 646 ath9k_cmn_debug_modal_eeprom(priv->debug.debugfs_phy, priv->ah); 647 648 return 0; 649 } 650 651 #line 125 "/work/ldvuser/andrianov/work/current--X--drivers/net/wireless/ath/ath9k/--X--defaultlinux-4.5-rc7--X--races--X--cpachecker/linux-4.5-rc7/csd_deg_dscv/74/dscv_tempdir/dscv/ri/races/drivers/net/wireless/ath/ath9k/htc_drv_debug.o.c.prepared" 652 653 int ldv_release_9(void); 654 int ldv_retval_2; 655 int ldv_release_8(void); 656 int ldv_retval_12; 657 int ldv_retval_5; 658 int ldv_retval_0; 659 int ldv_retval_6; 660 int ldv_retval_1; 661 int ldv_release_4(void); 662 int ldv_release_6(void); 663 int ldv_release_5(void); 664 int ldv_release_2(void); 665 int ldv_release_3(void); 666 int ldv_release_7(void); 667 int ldv_retval_3; 668 int ldv_retval_7; 669 670 671 void ldv_file_operations_7(void){ 672 fops_tgt_rx_stats_group1 = ldv_undef_ptr(); 673 fops_tgt_rx_stats_group2 = ldv_undef_ptr(); 674 } 675 676 677 void ldv_file_operations_6(void){ 678 fops_xmit_group1 = ldv_undef_ptr(); 679 fops_xmit_group2 = ldv_undef_ptr(); 680 } 681 682 683 void ldv_file_operations_2(void){ 684 fops_debug_group1 = ldv_undef_ptr(); 685 fops_debug_group2 = ldv_undef_ptr(); 686 } 687 688 689 void ldv_file_operations_9(void){ 690 fops_tgt_int_stats_group1 = ldv_undef_ptr(); 691 fops_tgt_int_stats_group2 = ldv_undef_ptr(); 692 } 693 694 695 void ldv_file_operations_3(void){ 696 fops_queue_group1 = ldv_undef_ptr(); 697 fops_queue_group2 = ldv_undef_ptr(); 698 } 699 700 701 void ldv_file_operations_8(void){ 702 fops_tgt_tx_stats_group1 = ldv_undef_ptr(); 703 fops_tgt_tx_stats_group2 = ldv_undef_ptr(); 704 } 705 706 707 void ldv_file_operations_5(void){ 708 fops_skb_rx_group1 = ldv_undef_ptr(); 709 fops_skb_rx_group2 = ldv_undef_ptr(); 710 } 711 712 713 void ldv_file_operations_4(void){ 714 fops_slot_group1 = ldv_undef_ptr(); 715 fops_slot_group2 = ldv_undef_ptr(); 716 } 717 718 719 void ldv_main_exported_6(void){ 720 loff_t *ldvarg2; 721 int ldvarg0; 722 size_t ldvarg3; 723 char *ldvarg4; 724 loff_t ldvarg1; 725 /*DEG-struct: handlers from structure fops_xmit*/ 726 switch(__VERIFIER_nondet_int()){ 727 case 0:{ 728 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 729 if(ldv_state_variable_6 == 1){ 730 /*DEG-CALL: handler open from fops_xmit*/ 731 ldv_retval_0=(& simple_open)(fops_xmit_group1,fops_xmit_group2); 732 if(ldv_retval_0==0){ 733 ldv_state_variable_6 = 2; 734 ref_cnt++; 735 } 736 } 737 } 738 break; 739 case 1:{ 740 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 741 if(ldv_state_variable_6 == 2){ 742 /*DEG-CALL: handler read from fops_xmit*/ 743 (& read_file_xmit)(fops_xmit_group2,ldvarg4,ldvarg3,ldvarg2); 744 /*DEG-postcall: default*/ 745 ldv_state_variable_6 = 2; 746 } 747 } 748 break; 749 case 2:{ 750 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 751 if(ldv_state_variable_6 == 2){ 752 /*DEG-CALL: handler llseek from fops_xmit*/ 753 (& default_llseek)(fops_xmit_group2,ldvarg1,ldvarg0); 754 /*DEG-postcall: default*/ 755 ldv_state_variable_6 = 2; 756 } 757 } 758 break; 759 case 3:{ 760 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 761 if(ldv_state_variable_6 == 2){ 762 /*DEG-CALL: handler release from fops_xmit*/ 763 ldv_release_6(); 764 ldv_state_variable_6 = 1; 765 ref_cnt--; 766 } 767 } 768 break; 769 default: ldv_assume(0); 770 } 771 772 }; 773 774 775 void ldv_main_exported_3(void){ 776 loff_t ldvarg6; 777 int ldvarg5; 778 char *ldvarg9; 779 loff_t *ldvarg7; 780 size_t ldvarg8; 781 /*DEG-struct: handlers from structure fops_queue*/ 782 switch(__VERIFIER_nondet_int()){ 783 case 0:{ 784 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 785 if(ldv_state_variable_3 == 1){ 786 /*DEG-CALL: handler open from fops_queue*/ 787 ldv_retval_1=(& simple_open)(fops_queue_group1,fops_queue_group2); 788 if(ldv_retval_1==0){ 789 ldv_state_variable_3 = 2; 790 ref_cnt++; 791 } 792 } 793 } 794 break; 795 case 1:{ 796 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 797 if(ldv_state_variable_3 == 2){ 798 /*DEG-CALL: handler read from fops_queue*/ 799 (& read_file_queue)(fops_queue_group2,ldvarg9,ldvarg8,ldvarg7); 800 /*DEG-postcall: default*/ 801 ldv_state_variable_3 = 2; 802 } 803 } 804 break; 805 case 2:{ 806 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 807 if(ldv_state_variable_3 == 2){ 808 /*DEG-CALL: handler llseek from fops_queue*/ 809 (& default_llseek)(fops_queue_group2,ldvarg6,ldvarg5); 810 /*DEG-postcall: default*/ 811 ldv_state_variable_3 = 2; 812 } 813 } 814 break; 815 case 3:{ 816 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 817 if(ldv_state_variable_3 == 2){ 818 /*DEG-CALL: handler release from fops_queue*/ 819 ldv_release_3(); 820 ldv_state_variable_3 = 1; 821 ref_cnt--; 822 } 823 } 824 break; 825 default: ldv_assume(0); 826 } 827 828 }; 829 830 831 void ldv_main_exported_7(void){ 832 loff_t *ldvarg12; 833 int ldvarg10; 834 size_t ldvarg13; 835 char *ldvarg14; 836 loff_t ldvarg11; 837 /*DEG-struct: handlers from structure fops_tgt_rx_stats*/ 838 switch(__VERIFIER_nondet_int()){ 839 case 0:{ 840 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 841 if(ldv_state_variable_7 == 1){ 842 /*DEG-CALL: handler open from fops_tgt_rx_stats*/ 843 ldv_retval_2=(& simple_open)(fops_tgt_rx_stats_group1,fops_tgt_rx_stats_group2); 844 if(ldv_retval_2==0){ 845 ldv_state_variable_7 = 2; 846 ref_cnt++; 847 } 848 } 849 } 850 break; 851 case 1:{ 852 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 853 if(ldv_state_variable_7 == 2){ 854 /*DEG-CALL: handler read from fops_tgt_rx_stats*/ 855 (& read_file_tgt_rx_stats)(fops_tgt_rx_stats_group2,ldvarg14,ldvarg13,ldvarg12); 856 /*DEG-postcall: default*/ 857 ldv_state_variable_7 = 2; 858 } 859 } 860 break; 861 case 2:{ 862 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 863 if(ldv_state_variable_7 == 2){ 864 /*DEG-CALL: handler llseek from fops_tgt_rx_stats*/ 865 (& default_llseek)(fops_tgt_rx_stats_group2,ldvarg11,ldvarg10); 866 /*DEG-postcall: default*/ 867 ldv_state_variable_7 = 2; 868 } 869 } 870 break; 871 case 3:{ 872 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 873 if(ldv_state_variable_7 == 2){ 874 /*DEG-CALL: handler release from fops_tgt_rx_stats*/ 875 ldv_release_7(); 876 ldv_state_variable_7 = 1; 877 ref_cnt--; 878 } 879 } 880 break; 881 default: ldv_assume(0); 882 } 883 884 }; 885 886 887 void ldv_main_exported_9(void){ 888 int ldvarg15; 889 loff_t ldvarg16; 890 char *ldvarg19; 891 loff_t *ldvarg17; 892 size_t ldvarg18; 893 /*DEG-struct: handlers from structure fops_tgt_int_stats*/ 894 switch(__VERIFIER_nondet_int()){ 895 case 0:{ 896 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 897 if(ldv_state_variable_9 == 1){ 898 /*DEG-CALL: handler open from fops_tgt_int_stats*/ 899 ldv_retval_3=(& simple_open)(fops_tgt_int_stats_group1,fops_tgt_int_stats_group2); 900 if(ldv_retval_3==0){ 901 ldv_state_variable_9 = 2; 902 ref_cnt++; 903 } 904 } 905 } 906 break; 907 case 1:{ 908 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 909 if(ldv_state_variable_9 == 2){ 910 /*DEG-CALL: handler read from fops_tgt_int_stats*/ 911 (& read_file_tgt_int_stats)(fops_tgt_int_stats_group2,ldvarg19,ldvarg18,ldvarg17); 912 /*DEG-postcall: default*/ 913 ldv_state_variable_9 = 2; 914 } 915 } 916 break; 917 case 2:{ 918 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 919 if(ldv_state_variable_9 == 2){ 920 /*DEG-CALL: handler llseek from fops_tgt_int_stats*/ 921 (& default_llseek)(fops_tgt_int_stats_group2,ldvarg16,ldvarg15); 922 /*DEG-postcall: default*/ 923 ldv_state_variable_9 = 2; 924 } 925 } 926 break; 927 case 3:{ 928 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 929 if(ldv_state_variable_9 == 2){ 930 /*DEG-CALL: handler release from fops_tgt_int_stats*/ 931 ldv_release_9(); 932 ldv_state_variable_9 = 1; 933 ref_cnt--; 934 } 935 } 936 break; 937 default: ldv_assume(0); 938 } 939 940 }; 941 942 943 void ldv_main_exported_2(void){ 944 loff_t *ldvarg83; 945 char const *ldvarg82; 946 int ldvarg76; 947 char *ldvarg79; 948 size_t ldvarg78; 949 loff_t *ldvarg80; 950 loff_t ldvarg77; 951 size_t ldvarg81; 952 /*DEG-struct: handlers from structure fops_debug*/ 953 switch(__VERIFIER_nondet_int()){ 954 case 0:{ 955 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 956 if(ldv_state_variable_2 == 1){ 957 /*DEG-CALL: handler open from fops_debug*/ 958 ldv_retval_5=(& simple_open)(fops_debug_group1,fops_debug_group2); 959 if(ldv_retval_5==0){ 960 ldv_state_variable_2 = 2; 961 ref_cnt++; 962 } 963 } 964 } 965 break; 966 case 1:{ 967 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 968 if(ldv_state_variable_2 == 1){ 969 /*DEG-CALL: handler write from fops_debug*/ 970 (& write_file_debug)(fops_debug_group2,ldvarg82,ldvarg81,ldvarg83); 971 /*DEG-postcall: default*/ 972 ldv_state_variable_2 = 1; 973 } 974 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 975 if(ldv_state_variable_2 == 2){ 976 /*DEG-CALL: handler write from fops_debug*/ 977 (& write_file_debug)(fops_debug_group2,ldvarg82,ldvarg81,ldvarg83); 978 /*DEG-postcall: default*/ 979 ldv_state_variable_2 = 2; 980 } 981 } 982 break; 983 case 2:{ 984 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 985 if(ldv_state_variable_2 == 2){ 986 /*DEG-CALL: handler read from fops_debug*/ 987 (& read_file_debug)(fops_debug_group2,ldvarg79,ldvarg78,ldvarg80); 988 /*DEG-postcall: default*/ 989 ldv_state_variable_2 = 2; 990 } 991 } 992 break; 993 case 3:{ 994 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 995 if(ldv_state_variable_2 == 2){ 996 /*DEG-CALL: handler llseek from fops_debug*/ 997 (& default_llseek)(fops_debug_group2,ldvarg77,ldvarg76); 998 /*DEG-postcall: default*/ 999 ldv_state_variable_2 = 2; 1000 } 1001 } 1002 break; 1003 case 4:{ 1004 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1005 if(ldv_state_variable_2 == 2){ 1006 /*DEG-CALL: handler release from fops_debug*/ 1007 ldv_release_2(); 1008 ldv_state_variable_2 = 1; 1009 ref_cnt--; 1010 } 1011 } 1012 break; 1013 default: ldv_assume(0); 1014 } 1015 1016 }; 1017 1018 1019 void ldv_main_exported_8(void){ 1020 loff_t ldvarg92; 1021 int ldvarg91; 1022 char *ldvarg94; 1023 loff_t *ldvarg95; 1024 size_t ldvarg93; 1025 /*DEG-struct: handlers from structure fops_tgt_tx_stats*/ 1026 switch(__VERIFIER_nondet_int()){ 1027 case 0:{ 1028 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1029 if(ldv_state_variable_8 == 1){ 1030 /*DEG-CALL: handler open from fops_tgt_tx_stats*/ 1031 ldv_retval_6=(& simple_open)(fops_tgt_tx_stats_group1,fops_tgt_tx_stats_group2); 1032 if(ldv_retval_6==0){ 1033 ldv_state_variable_8 = 2; 1034 ref_cnt++; 1035 } 1036 } 1037 } 1038 break; 1039 case 1:{ 1040 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1041 if(ldv_state_variable_8 == 2){ 1042 /*DEG-CALL: handler read from fops_tgt_tx_stats*/ 1043 (& read_file_tgt_tx_stats)(fops_tgt_tx_stats_group2,ldvarg94,ldvarg93,ldvarg95); 1044 /*DEG-postcall: default*/ 1045 ldv_state_variable_8 = 2; 1046 } 1047 } 1048 break; 1049 case 2:{ 1050 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1051 if(ldv_state_variable_8 == 2){ 1052 /*DEG-CALL: handler llseek from fops_tgt_tx_stats*/ 1053 (& default_llseek)(fops_tgt_tx_stats_group2,ldvarg92,ldvarg91); 1054 /*DEG-postcall: default*/ 1055 ldv_state_variable_8 = 2; 1056 } 1057 } 1058 break; 1059 case 3:{ 1060 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1061 if(ldv_state_variable_8 == 2){ 1062 /*DEG-CALL: handler release from fops_tgt_tx_stats*/ 1063 ldv_release_8(); 1064 ldv_state_variable_8 = 1; 1065 ref_cnt--; 1066 } 1067 } 1068 break; 1069 default: ldv_assume(0); 1070 } 1071 1072 }; 1073 1074 1075 void ldv_main_exported_4(void){ 1076 char *ldvarg99; 1077 int ldvarg96; 1078 loff_t *ldvarg100; 1079 loff_t ldvarg97; 1080 size_t ldvarg98; 1081 /*DEG-struct: handlers from structure fops_slot*/ 1082 switch(__VERIFIER_nondet_int()){ 1083 case 0:{ 1084 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1085 if(ldv_state_variable_4 == 1){ 1086 /*DEG-CALL: handler open from fops_slot*/ 1087 ldv_retval_7=(& simple_open)(fops_slot_group1,fops_slot_group2); 1088 if(ldv_retval_7==0){ 1089 ldv_state_variable_4 = 2; 1090 ref_cnt++; 1091 } 1092 } 1093 } 1094 break; 1095 case 1:{ 1096 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1097 if(ldv_state_variable_4 == 2){ 1098 /*DEG-CALL: handler read from fops_slot*/ 1099 (& read_file_slot)(fops_slot_group2,ldvarg99,ldvarg98,ldvarg100); 1100 /*DEG-postcall: default*/ 1101 ldv_state_variable_4 = 2; 1102 } 1103 } 1104 break; 1105 case 2:{ 1106 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1107 if(ldv_state_variable_4 == 2){ 1108 /*DEG-CALL: handler llseek from fops_slot*/ 1109 (& default_llseek)(fops_slot_group2,ldvarg97,ldvarg96); 1110 /*DEG-postcall: default*/ 1111 ldv_state_variable_4 = 2; 1112 } 1113 } 1114 break; 1115 case 3:{ 1116 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1117 if(ldv_state_variable_4 == 2){ 1118 /*DEG-CALL: handler release from fops_slot*/ 1119 ldv_release_4(); 1120 ldv_state_variable_4 = 1; 1121 ref_cnt--; 1122 } 1123 } 1124 break; 1125 default: ldv_assume(0); 1126 } 1127 1128 }; 1129 1130 1131 void ldv_main_exported_5(void){ 1132 char *ldvarg109; 1133 loff_t ldvarg107; 1134 int ldvarg106; 1135 size_t ldvarg108; 1136 loff_t *ldvarg110; 1137 /*DEG-struct: handlers from structure fops_skb_rx*/ 1138 switch(__VERIFIER_nondet_int()){ 1139 case 0:{ 1140 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1141 if(ldv_state_variable_5 == 1){ 1142 /*DEG-CALL: handler open from fops_skb_rx*/ 1143 ldv_retval_12=(& simple_open)(fops_skb_rx_group1,fops_skb_rx_group2); 1144 if(ldv_retval_12==0){ 1145 ldv_state_variable_5 = 2; 1146 ref_cnt++; 1147 } 1148 } 1149 } 1150 break; 1151 case 1:{ 1152 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1153 if(ldv_state_variable_5 == 2){ 1154 /*DEG-CALL: handler read from fops_skb_rx*/ 1155 (& read_file_skb_rx)(fops_skb_rx_group2,ldvarg109,ldvarg108,ldvarg110); 1156 /*DEG-postcall: default*/ 1157 ldv_state_variable_5 = 2; 1158 } 1159 } 1160 break; 1161 case 2:{ 1162 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1163 if(ldv_state_variable_5 == 2){ 1164 /*DEG-CALL: handler llseek from fops_skb_rx*/ 1165 (& default_llseek)(fops_skb_rx_group2,ldvarg107,ldvarg106); 1166 /*DEG-postcall: default*/ 1167 ldv_state_variable_5 = 2; 1168 } 1169 } 1170 break; 1171 case 3:{ 1172 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1173 if(ldv_state_variable_5 == 2){ 1174 /*DEG-CALL: handler release from fops_skb_rx*/ 1175 ldv_release_5(); 1176 ldv_state_variable_5 = 1; 1177 ref_cnt--; 1178 } 1179 } 1180 break; 1181 default: ldv_assume(0); 1182 } 1183 1184 };
1 /* 2 * Copyright (c) 2010-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include "htc.h" 18 19 /******************/ 20 /* BTCOEX */ 21 /******************/ 22 23 #define ATH_HTC_BTCOEX_PRODUCT_ID "wb193" 24 25 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT 26 27 /* 28 * Detects if there is any priority bt traffic 29 */ 30 static void ath_detect_bt_priority(struct ath9k_htc_priv *priv) 31 { 32 struct ath_btcoex *btcoex = &priv->btcoex; 33 struct ath_hw *ah = priv->ah; 34 35 if (ath9k_hw_gpio_get(ah, ah->btcoex_hw.btpriority_gpio)) 36 btcoex->bt_priority_cnt++; 37 38 if (time_after(jiffies, btcoex->bt_priority_time + 39 msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) { 40 clear_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags); 41 clear_bit(OP_BT_SCAN, &priv->op_flags); 42 /* Detect if colocated bt started scanning */ 43 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) { 44 ath_dbg(ath9k_hw_common(ah), BTCOEX, 45 "BT scan detected\n"); 46 set_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags); 47 set_bit(OP_BT_SCAN, &priv->op_flags); 48 } else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) { 49 ath_dbg(ath9k_hw_common(ah), BTCOEX, 50 "BT priority traffic detected\n"); 51 set_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags); 52 } 53 54 btcoex->bt_priority_cnt = 0; 55 btcoex->bt_priority_time = jiffies; 56 } 57 } 58 59 /* 60 * This is the master bt coex work which runs for every 61 * 45ms, bt traffic will be given priority during 55% of this 62 * period while wlan gets remaining 45% 63 */ 64 static void ath_btcoex_period_work(struct work_struct *work) 65 { 66 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv, 67 coex_period_work.work); 68 struct ath_btcoex *btcoex = &priv->btcoex; 69 struct ath_common *common = ath9k_hw_common(priv->ah); 70 u32 timer_period; 71 int ret; 72 73 ath_detect_bt_priority(priv); 74 75 ret = ath9k_htc_update_cap_target(priv, 76 test_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags)); 77 if (ret) { 78 ath_err(common, "Unable to set BTCOEX parameters\n"); 79 return; 80 } 81 82 ath9k_hw_btcoex_bt_stomp(priv->ah, test_bit(OP_BT_SCAN, &priv->op_flags) ? 83 ATH_BTCOEX_STOMP_ALL : btcoex->bt_stomp_type); 84 85 ath9k_hw_btcoex_enable(priv->ah); 86 timer_period = test_bit(OP_BT_SCAN, &priv->op_flags) ? 87 btcoex->btscan_no_stomp : btcoex->btcoex_no_stomp; 88 ieee80211_queue_delayed_work(priv->hw, &priv->duty_cycle_work, 89 msecs_to_jiffies(timer_period)); 90 ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work, 91 msecs_to_jiffies(btcoex->btcoex_period)); 92 } 93 94 /* 95 * Work to time slice between wlan and bt traffic and 96 * configure weight registers 97 */ 98 static void ath_btcoex_duty_cycle_work(struct work_struct *work) 99 { 100 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv, 101 duty_cycle_work.work); 102 struct ath_hw *ah = priv->ah; 103 struct ath_btcoex *btcoex = &priv->btcoex; 104 struct ath_common *common = ath9k_hw_common(ah); 105 106 ath_dbg(common, BTCOEX, "time slice work for bt and wlan\n"); 107 108 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || 109 test_bit(OP_BT_SCAN, &priv->op_flags)) 110 ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE); 111 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL) 112 ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW); 113 114 ath9k_hw_btcoex_enable(priv->ah); 115 } 116 117 static void ath_htc_init_btcoex_work(struct ath9k_htc_priv *priv) 118 { 119 struct ath_btcoex *btcoex = &priv->btcoex; 120 121 btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD; 122 btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) * 123 btcoex->btcoex_period / 100; 124 btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) * 125 btcoex->btcoex_period / 100; 126 INIT_DELAYED_WORK(&priv->coex_period_work, ath_btcoex_period_work); 127 INIT_DELAYED_WORK(&priv->duty_cycle_work, ath_btcoex_duty_cycle_work); 128 } 129 130 /* 131 * (Re)start btcoex work 132 */ 133 134 static void ath_htc_resume_btcoex_work(struct ath9k_htc_priv *priv) 135 { 136 struct ath_btcoex *btcoex = &priv->btcoex; 137 struct ath_hw *ah = priv->ah; 138 139 ath_dbg(ath9k_hw_common(ah), BTCOEX, "Starting btcoex work\n"); 140 141 btcoex->bt_priority_cnt = 0; 142 btcoex->bt_priority_time = jiffies; 143 clear_bit(OP_BT_PRIORITY_DETECTED, &priv->op_flags); 144 clear_bit(OP_BT_SCAN, &priv->op_flags); 145 ieee80211_queue_delayed_work(priv->hw, &priv->coex_period_work, 0); 146 } 147 148 149 /* 150 * Cancel btcoex and bt duty cycle work. 151 */ 152 static void ath_htc_cancel_btcoex_work(struct ath9k_htc_priv *priv) 153 { 154 cancel_delayed_work_sync(&priv->coex_period_work); 155 cancel_delayed_work_sync(&priv->duty_cycle_work); 156 } 157 158 void ath9k_htc_start_btcoex(struct ath9k_htc_priv *priv) 159 { 160 struct ath_hw *ah = priv->ah; 161 162 if (ath9k_hw_get_btcoex_scheme(ah) == ATH_BTCOEX_CFG_3WIRE) { 163 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT, 164 AR_STOMP_LOW_WLAN_WGHT, 0); 165 ath9k_hw_btcoex_enable(ah); 166 ath_htc_resume_btcoex_work(priv); 167 } 168 } 169 170 void ath9k_htc_stop_btcoex(struct ath9k_htc_priv *priv) 171 { 172 struct ath_hw *ah = priv->ah; 173 174 if (ah->btcoex_hw.enabled && 175 ath9k_hw_get_btcoex_scheme(ah) != ATH_BTCOEX_CFG_NONE) { 176 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) 177 ath_htc_cancel_btcoex_work(priv); 178 ath9k_hw_btcoex_disable(ah); 179 } 180 } 181 182 void ath9k_htc_init_btcoex(struct ath9k_htc_priv *priv, char *product) 183 { 184 struct ath_hw *ah = priv->ah; 185 struct ath_common *common = ath9k_hw_common(ah); 186 int qnum; 187 188 /* 189 * Check if BTCOEX is globally disabled. 190 */ 191 if (!common->btcoex_enabled) { 192 ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_NONE; 193 return; 194 } 195 196 if (product && strncmp(product, ATH_HTC_BTCOEX_PRODUCT_ID, 5) == 0) { 197 ah->btcoex_hw.scheme = ATH_BTCOEX_CFG_3WIRE; 198 } 199 200 switch (ath9k_hw_get_btcoex_scheme(priv->ah)) { 201 case ATH_BTCOEX_CFG_NONE: 202 break; 203 case ATH_BTCOEX_CFG_3WIRE: 204 priv->ah->btcoex_hw.btactive_gpio = 7; 205 priv->ah->btcoex_hw.btpriority_gpio = 6; 206 priv->ah->btcoex_hw.wlanactive_gpio = 8; 207 priv->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW; 208 ath9k_hw_btcoex_init_3wire(priv->ah); 209 ath_htc_init_btcoex_work(priv); 210 qnum = priv->hwq_map[IEEE80211_AC_BE]; 211 ath9k_hw_init_btcoex_hw(priv->ah, qnum); 212 break; 213 default: 214 WARN_ON(1); 215 break; 216 } 217 } 218 219 #endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */ 220 221 /*******/ 222 /* LED */ 223 /*******/ 224 225 #ifdef CONFIG_MAC80211_LEDS 226 void ath9k_led_work(struct work_struct *work) 227 { 228 struct ath9k_htc_priv *priv = container_of(work, 229 struct ath9k_htc_priv, 230 led_work); 231 232 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 233 (priv->brightness == LED_OFF)); 234 } 235 236 static void ath9k_led_brightness(struct led_classdev *led_cdev, 237 enum led_brightness brightness) 238 { 239 struct ath9k_htc_priv *priv = container_of(led_cdev, 240 struct ath9k_htc_priv, 241 led_cdev); 242 243 /* Not locked, but it's just a tiny green light..*/ 244 priv->brightness = brightness; 245 ieee80211_queue_work(priv->hw, &priv->led_work); 246 } 247 248 void ath9k_deinit_leds(struct ath9k_htc_priv *priv) 249 { 250 if (!priv->led_registered) 251 return; 252 253 ath9k_led_brightness(&priv->led_cdev, LED_OFF); 254 led_classdev_unregister(&priv->led_cdev); 255 cancel_work_sync(&priv->led_work); 256 } 257 258 259 void ath9k_configure_leds(struct ath9k_htc_priv *priv) 260 { 261 /* Configure gpio 1 for output */ 262 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin, 263 AR_GPIO_OUTPUT_MUX_AS_OUTPUT); 264 /* LED off, active low */ 265 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1); 266 267 } 268 269 void ath9k_init_leds(struct ath9k_htc_priv *priv) 270 { 271 int ret; 272 273 if (AR_SREV_9287(priv->ah)) 274 priv->ah->led_pin = ATH_LED_PIN_9287; 275 else if (AR_SREV_9271(priv->ah)) 276 priv->ah->led_pin = ATH_LED_PIN_9271; 277 else if (AR_DEVID_7010(priv->ah)) 278 priv->ah->led_pin = ATH_LED_PIN_7010; 279 else 280 priv->ah->led_pin = ATH_LED_PIN_DEF; 281 282 if (!ath9k_htc_led_blink) 283 priv->led_cdev.default_trigger = 284 ieee80211_get_radio_led_name(priv->hw); 285 286 ath9k_configure_leds(priv); 287 288 snprintf(priv->led_name, sizeof(priv->led_name), 289 "ath9k_htc-%s", wiphy_name(priv->hw->wiphy)); 290 priv->led_cdev.name = priv->led_name; 291 priv->led_cdev.brightness_set = ath9k_led_brightness; 292 293 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &priv->led_cdev); 294 if (ret < 0) 295 return; 296 297 INIT_WORK(&priv->led_work, ath9k_led_work); 298 priv->led_registered = true; 299 300 return; 301 } 302 #endif 303 304 /*******************/ 305 /* Rfkill */ 306 /*******************/ 307 308 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv) 309 { 310 bool is_blocked; 311 312 ath9k_htc_ps_wakeup(priv); 313 is_blocked = ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) == 314 priv->ah->rfkill_polarity; 315 ath9k_htc_ps_restore(priv); 316 317 return is_blocked; 318 } 319 320 void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw) 321 { 322 struct ath9k_htc_priv *priv = hw->priv; 323 bool blocked = !!ath_is_rfkill_set(priv); 324 325 wiphy_rfkill_set_hw_state(hw->wiphy, blocked); 326 } 327 328 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv) 329 { 330 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT) 331 wiphy_rfkill_start_polling(priv->hw->wiphy); 332 }
1 /* 2 * Copyright (c) 2010-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 18 19 #include "htc.h" 20 21 MODULE_AUTHOR("Atheros Communications"); 22 MODULE_LICENSE("Dual BSD/GPL"); 23 MODULE_DESCRIPTION("Atheros driver 802.11n HTC based wireless devices"); 24 25 static unsigned int ath9k_debug = ATH_DBG_DEFAULT; 26 module_param_named(debug, ath9k_debug, uint, 0); 27 MODULE_PARM_DESC(debug, "Debugging mask"); 28 29 int htc_modparam_nohwcrypt; 30 module_param_named(nohwcrypt, htc_modparam_nohwcrypt, int, 0444); 31 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption"); 32 33 static int ath9k_htc_btcoex_enable; 34 module_param_named(btcoex_enable, ath9k_htc_btcoex_enable, int, 0444); 35 MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence"); 36 37 static int ath9k_ps_enable; 38 module_param_named(ps_enable, ath9k_ps_enable, int, 0444); 39 MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave"); 40 41 int htc_use_dev_fw = 0; 42 module_param_named(use_dev_fw, htc_use_dev_fw, int, 0444); 43 MODULE_PARM_DESC(use_dev_fw, "Use development FW version"); 44 45 #ifdef CONFIG_MAC80211_LEDS 46 int ath9k_htc_led_blink = 1; 47 module_param_named(blink, ath9k_htc_led_blink, int, 0444); 48 MODULE_PARM_DESC(blink, "Enable LED blink on activity"); 49 50 static const struct ieee80211_tpt_blink ath9k_htc_tpt_blink[] = { 51 { .throughput = 0 * 1024, .blink_time = 334 }, 52 { .throughput = 1 * 1024, .blink_time = 260 }, 53 { .throughput = 5 * 1024, .blink_time = 220 }, 54 { .throughput = 10 * 1024, .blink_time = 190 }, 55 { .throughput = 20 * 1024, .blink_time = 170 }, 56 { .throughput = 50 * 1024, .blink_time = 150 }, 57 { .throughput = 70 * 1024, .blink_time = 130 }, 58 { .throughput = 100 * 1024, .blink_time = 110 }, 59 { .throughput = 200 * 1024, .blink_time = 80 }, 60 { .throughput = 300 * 1024, .blink_time = 50 }, 61 }; 62 #endif 63 64 static void ath9k_htc_op_ps_wakeup(struct ath_common *common) 65 { 66 ath9k_htc_ps_wakeup((struct ath9k_htc_priv *) common->priv); 67 } 68 69 static void ath9k_htc_op_ps_restore(struct ath_common *common) 70 { 71 ath9k_htc_ps_restore((struct ath9k_htc_priv *) common->priv); 72 } 73 74 static struct ath_ps_ops ath9k_htc_ps_ops = { 75 .wakeup = ath9k_htc_op_ps_wakeup, 76 .restore = ath9k_htc_op_ps_restore, 77 }; 78 79 static int ath9k_htc_wait_for_target(struct ath9k_htc_priv *priv) 80 { 81 unsigned long time_left; 82 83 if (atomic_read(&priv->htc->tgt_ready) > 0) { 84 atomic_dec(&priv->htc->tgt_ready); 85 return 0; 86 } 87 88 /* Firmware can take up to 50ms to get ready, to be safe use 1 second */ 89 time_left = wait_for_completion_timeout(&priv->htc->target_wait, HZ); 90 if (!time_left) { 91 dev_err(priv->dev, "ath9k_htc: Target is unresponsive\n"); 92 return -ETIMEDOUT; 93 } 94 95 atomic_dec(&priv->htc->tgt_ready); 96 97 return 0; 98 } 99 100 static void ath9k_deinit_priv(struct ath9k_htc_priv *priv) 101 { 102 ath9k_hw_deinit(priv->ah); 103 kfree(priv->ah); 104 priv->ah = NULL; 105 } 106 107 static void ath9k_deinit_device(struct ath9k_htc_priv *priv) 108 { 109 struct ieee80211_hw *hw = priv->hw; 110 111 wiphy_rfkill_stop_polling(hw->wiphy); 112 ath9k_deinit_leds(priv); 113 ath9k_htc_deinit_debug(priv); 114 ieee80211_unregister_hw(hw); 115 ath9k_rx_cleanup(priv); 116 ath9k_tx_cleanup(priv); 117 ath9k_deinit_priv(priv); 118 } 119 120 static inline int ath9k_htc_connect_svc(struct ath9k_htc_priv *priv, 121 u16 service_id, 122 void (*tx) (void *, 123 struct sk_buff *, 124 enum htc_endpoint_id, 125 bool txok), 126 enum htc_endpoint_id *ep_id) 127 { 128 struct htc_service_connreq req; 129 130 memset(&req, 0, sizeof(struct htc_service_connreq)); 131 132 req.service_id = service_id; 133 req.ep_callbacks.priv = priv; 134 req.ep_callbacks.rx = ath9k_htc_rxep; 135 req.ep_callbacks.tx = tx; 136 137 return htc_connect_service(priv->htc, &req, ep_id); 138 } 139 140 static int ath9k_init_htc_services(struct ath9k_htc_priv *priv, u16 devid, 141 u32 drv_info) 142 { 143 int ret; 144 145 /* WMI CMD*/ 146 ret = ath9k_wmi_connect(priv->htc, priv->wmi, &priv->wmi_cmd_ep); 147 if (ret) 148 goto err; 149 150 /* Beacon */ 151 ret = ath9k_htc_connect_svc(priv, WMI_BEACON_SVC, ath9k_htc_beaconep, 152 &priv->beacon_ep); 153 if (ret) 154 goto err; 155 156 /* CAB */ 157 ret = ath9k_htc_connect_svc(priv, WMI_CAB_SVC, ath9k_htc_txep, 158 &priv->cab_ep); 159 if (ret) 160 goto err; 161 162 163 /* UAPSD */ 164 ret = ath9k_htc_connect_svc(priv, WMI_UAPSD_SVC, ath9k_htc_txep, 165 &priv->uapsd_ep); 166 if (ret) 167 goto err; 168 169 /* MGMT */ 170 ret = ath9k_htc_connect_svc(priv, WMI_MGMT_SVC, ath9k_htc_txep, 171 &priv->mgmt_ep); 172 if (ret) 173 goto err; 174 175 /* DATA BE */ 176 ret = ath9k_htc_connect_svc(priv, WMI_DATA_BE_SVC, ath9k_htc_txep, 177 &priv->data_be_ep); 178 if (ret) 179 goto err; 180 181 /* DATA BK */ 182 ret = ath9k_htc_connect_svc(priv, WMI_DATA_BK_SVC, ath9k_htc_txep, 183 &priv->data_bk_ep); 184 if (ret) 185 goto err; 186 187 /* DATA VI */ 188 ret = ath9k_htc_connect_svc(priv, WMI_DATA_VI_SVC, ath9k_htc_txep, 189 &priv->data_vi_ep); 190 if (ret) 191 goto err; 192 193 /* DATA VO */ 194 ret = ath9k_htc_connect_svc(priv, WMI_DATA_VO_SVC, ath9k_htc_txep, 195 &priv->data_vo_ep); 196 if (ret) 197 goto err; 198 199 /* 200 * Setup required credits before initializing HTC. 201 * This is a bit hacky, but, since queuing is done in 202 * the HIF layer, shouldn't matter much. 203 */ 204 205 if (IS_AR7010_DEVICE(drv_info)) 206 priv->htc->credits = 45; 207 else 208 priv->htc->credits = 33; 209 210 ret = htc_init(priv->htc); 211 if (ret) 212 goto err; 213 214 dev_info(priv->dev, "ath9k_htc: HTC initialized with %d credits\n", 215 priv->htc->credits); 216 217 return 0; 218 219 err: 220 dev_err(priv->dev, "ath9k_htc: Unable to initialize HTC services\n"); 221 return ret; 222 } 223 224 static void ath9k_reg_notifier(struct wiphy *wiphy, 225 struct regulatory_request *request) 226 { 227 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 228 struct ath9k_htc_priv *priv = hw->priv; 229 230 ath_reg_notifier_apply(wiphy, request, 231 ath9k_hw_regulatory(priv->ah)); 232 } 233 234 static unsigned int ath9k_regread(void *hw_priv, u32 reg_offset) 235 { 236 struct ath_hw *ah = (struct ath_hw *) hw_priv; 237 struct ath_common *common = ath9k_hw_common(ah); 238 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 239 __be32 val, reg = cpu_to_be32(reg_offset); 240 int r; 241 242 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID, 243 (u8 *) &reg, sizeof(reg), 244 (u8 *) &val, sizeof(val), 245 100); 246 if (unlikely(r)) { 247 ath_dbg(common, WMI, "REGISTER READ FAILED: (0x%04x, %d)\n", 248 reg_offset, r); 249 return -EIO; 250 } 251 252 return be32_to_cpu(val); 253 } 254 255 static void ath9k_multi_regread(void *hw_priv, u32 *addr, 256 u32 *val, u16 count) 257 { 258 struct ath_hw *ah = (struct ath_hw *) hw_priv; 259 struct ath_common *common = ath9k_hw_common(ah); 260 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 261 __be32 tmpaddr[8]; 262 __be32 tmpval[8]; 263 int i, ret; 264 265 for (i = 0; i < count; i++) { 266 tmpaddr[i] = cpu_to_be32(addr[i]); 267 } 268 269 ret = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID, 270 (u8 *)tmpaddr , sizeof(u32) * count, 271 (u8 *)tmpval, sizeof(u32) * count, 272 100); 273 if (unlikely(ret)) { 274 ath_dbg(common, WMI, 275 "Multiple REGISTER READ FAILED (count: %d)\n", count); 276 } 277 278 for (i = 0; i < count; i++) { 279 val[i] = be32_to_cpu(tmpval[i]); 280 } 281 } 282 283 static void ath9k_regwrite_multi(struct ath_common *common) 284 { 285 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 286 u32 rsp_status; 287 int r; 288 289 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID, 290 (u8 *) &priv->wmi->multi_write, 291 sizeof(struct register_write) * priv->wmi->multi_write_idx, 292 (u8 *) &rsp_status, sizeof(rsp_status), 293 100); 294 if (unlikely(r)) { 295 ath_dbg(common, WMI, 296 "REGISTER WRITE FAILED, multi len: %d\n", 297 priv->wmi->multi_write_idx); 298 } 299 priv->wmi->multi_write_idx = 0; 300 } 301 302 static void ath9k_regwrite_single(void *hw_priv, u32 val, u32 reg_offset) 303 { 304 struct ath_hw *ah = (struct ath_hw *) hw_priv; 305 struct ath_common *common = ath9k_hw_common(ah); 306 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 307 const __be32 buf[2] = { 308 cpu_to_be32(reg_offset), 309 cpu_to_be32(val), 310 }; 311 int r; 312 313 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID, 314 (u8 *) &buf, sizeof(buf), 315 (u8 *) &val, sizeof(val), 316 100); 317 if (unlikely(r)) { 318 ath_dbg(common, WMI, "REGISTER WRITE FAILED:(0x%04x, %d)\n", 319 reg_offset, r); 320 } 321 } 322 323 static void ath9k_regwrite_buffer(void *hw_priv, u32 val, u32 reg_offset) 324 { 325 struct ath_hw *ah = (struct ath_hw *) hw_priv; 326 struct ath_common *common = ath9k_hw_common(ah); 327 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 328 329 mutex_lock(&priv->wmi->multi_write_mutex); 330 331 /* Store the register/value */ 332 priv->wmi->multi_write[priv->wmi->multi_write_idx].reg = 333 cpu_to_be32(reg_offset); 334 priv->wmi->multi_write[priv->wmi->multi_write_idx].val = 335 cpu_to_be32(val); 336 337 priv->wmi->multi_write_idx++; 338 339 /* If the buffer is full, send it out. */ 340 if (priv->wmi->multi_write_idx == MAX_CMD_NUMBER) 341 ath9k_regwrite_multi(common); 342 343 mutex_unlock(&priv->wmi->multi_write_mutex); 344 } 345 346 static void ath9k_regwrite(void *hw_priv, u32 val, u32 reg_offset) 347 { 348 struct ath_hw *ah = (struct ath_hw *) hw_priv; 349 struct ath_common *common = ath9k_hw_common(ah); 350 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 351 352 if (atomic_read(&priv->wmi->mwrite_cnt)) 353 ath9k_regwrite_buffer(hw_priv, val, reg_offset); 354 else 355 ath9k_regwrite_single(hw_priv, val, reg_offset); 356 } 357 358 static void ath9k_enable_regwrite_buffer(void *hw_priv) 359 { 360 struct ath_hw *ah = (struct ath_hw *) hw_priv; 361 struct ath_common *common = ath9k_hw_common(ah); 362 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 363 364 atomic_inc(&priv->wmi->mwrite_cnt); 365 } 366 367 static void ath9k_regwrite_flush(void *hw_priv) 368 { 369 struct ath_hw *ah = (struct ath_hw *) hw_priv; 370 struct ath_common *common = ath9k_hw_common(ah); 371 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 372 373 atomic_dec(&priv->wmi->mwrite_cnt); 374 375 mutex_lock(&priv->wmi->multi_write_mutex); 376 377 if (priv->wmi->multi_write_idx) 378 ath9k_regwrite_multi(common); 379 380 mutex_unlock(&priv->wmi->multi_write_mutex); 381 } 382 383 static void ath9k_reg_rmw_buffer(void *hw_priv, 384 u32 reg_offset, u32 set, u32 clr) 385 { 386 struct ath_hw *ah = (struct ath_hw *) hw_priv; 387 struct ath_common *common = ath9k_hw_common(ah); 388 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 389 u32 rsp_status; 390 int r; 391 392 mutex_lock(&priv->wmi->multi_rmw_mutex); 393 394 /* Store the register/value */ 395 priv->wmi->multi_rmw[priv->wmi->multi_rmw_idx].reg = 396 cpu_to_be32(reg_offset); 397 priv->wmi->multi_rmw[priv->wmi->multi_rmw_idx].set = 398 cpu_to_be32(set); 399 priv->wmi->multi_rmw[priv->wmi->multi_rmw_idx].clr = 400 cpu_to_be32(clr); 401 402 priv->wmi->multi_rmw_idx++; 403 404 /* If the buffer is full, send it out. */ 405 if (priv->wmi->multi_rmw_idx == MAX_RMW_CMD_NUMBER) { 406 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_RMW_CMDID, 407 (u8 *) &priv->wmi->multi_rmw, 408 sizeof(struct register_write) * priv->wmi->multi_rmw_idx, 409 (u8 *) &rsp_status, sizeof(rsp_status), 410 100); 411 if (unlikely(r)) { 412 ath_dbg(common, WMI, 413 "REGISTER RMW FAILED, multi len: %d\n", 414 priv->wmi->multi_rmw_idx); 415 } 416 priv->wmi->multi_rmw_idx = 0; 417 } 418 419 mutex_unlock(&priv->wmi->multi_rmw_mutex); 420 } 421 422 static void ath9k_reg_rmw_flush(void *hw_priv) 423 { 424 struct ath_hw *ah = (struct ath_hw *) hw_priv; 425 struct ath_common *common = ath9k_hw_common(ah); 426 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 427 u32 rsp_status; 428 int r; 429 430 if (test_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags)) 431 return; 432 433 atomic_dec(&priv->wmi->m_rmw_cnt); 434 435 mutex_lock(&priv->wmi->multi_rmw_mutex); 436 437 if (priv->wmi->multi_rmw_idx) { 438 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_RMW_CMDID, 439 (u8 *) &priv->wmi->multi_rmw, 440 sizeof(struct register_rmw) * priv->wmi->multi_rmw_idx, 441 (u8 *) &rsp_status, sizeof(rsp_status), 442 100); 443 if (unlikely(r)) { 444 ath_dbg(common, WMI, 445 "REGISTER RMW FAILED, multi len: %d\n", 446 priv->wmi->multi_rmw_idx); 447 } 448 priv->wmi->multi_rmw_idx = 0; 449 } 450 451 mutex_unlock(&priv->wmi->multi_rmw_mutex); 452 } 453 454 static void ath9k_enable_rmw_buffer(void *hw_priv) 455 { 456 struct ath_hw *ah = (struct ath_hw *) hw_priv; 457 struct ath_common *common = ath9k_hw_common(ah); 458 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 459 460 if (test_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags)) 461 return; 462 463 atomic_inc(&priv->wmi->m_rmw_cnt); 464 } 465 466 static u32 ath9k_reg_rmw_single(void *hw_priv, 467 u32 reg_offset, u32 set, u32 clr) 468 { 469 struct ath_hw *ah = (struct ath_hw *) hw_priv; 470 struct ath_common *common = ath9k_hw_common(ah); 471 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 472 struct register_rmw buf, buf_ret; 473 int ret; 474 u32 val = 0; 475 476 buf.reg = cpu_to_be32(reg_offset); 477 buf.set = cpu_to_be32(set); 478 buf.clr = cpu_to_be32(clr); 479 480 ret = ath9k_wmi_cmd(priv->wmi, WMI_REG_RMW_CMDID, 481 (u8 *) &buf, sizeof(buf), 482 (u8 *) &buf_ret, sizeof(buf_ret), 483 100); 484 if (unlikely(ret)) { 485 ath_dbg(common, WMI, "REGISTER RMW FAILED:(0x%04x, %d)\n", 486 reg_offset, ret); 487 } 488 return val; 489 } 490 491 static u32 ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr) 492 { 493 struct ath_hw *ah = (struct ath_hw *) hw_priv; 494 struct ath_common *common = ath9k_hw_common(ah); 495 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 496 497 if (test_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags)) { 498 u32 val; 499 500 val = REG_READ(ah, reg_offset); 501 val &= ~clr; 502 val |= set; 503 REG_WRITE(ah, reg_offset, val); 504 505 return 0; 506 } 507 508 if (atomic_read(&priv->wmi->m_rmw_cnt)) 509 ath9k_reg_rmw_buffer(hw_priv, reg_offset, set, clr); 510 else 511 ath9k_reg_rmw_single(hw_priv, reg_offset, set, clr); 512 513 return 0; 514 } 515 516 static void ath_usb_read_cachesize(struct ath_common *common, int *csz) 517 { 518 *csz = L1_CACHE_BYTES >> 2; 519 } 520 521 static bool ath_usb_eeprom_read(struct ath_common *common, u32 off, u16 *data) 522 { 523 struct ath_hw *ah = (struct ath_hw *) common->ah; 524 525 (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S)); 526 527 if (!ath9k_hw_wait(ah, 528 AR_EEPROM_STATUS_DATA, 529 AR_EEPROM_STATUS_DATA_BUSY | 530 AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0, 531 AH_WAIT_TIMEOUT)) 532 return false; 533 534 *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA), 535 AR_EEPROM_STATUS_DATA_VAL); 536 537 return true; 538 } 539 540 static const struct ath_bus_ops ath9k_usb_bus_ops = { 541 .ath_bus_type = ATH_USB, 542 .read_cachesize = ath_usb_read_cachesize, 543 .eeprom_read = ath_usb_eeprom_read, 544 }; 545 546 static int ath9k_init_queues(struct ath9k_htc_priv *priv) 547 { 548 struct ath_common *common = ath9k_hw_common(priv->ah); 549 int i; 550 551 for (i = 0; i < ARRAY_SIZE(priv->hwq_map); i++) 552 priv->hwq_map[i] = -1; 553 554 priv->beacon.beaconq = ath9k_hw_beaconq_setup(priv->ah); 555 if (priv->beacon.beaconq == -1) { 556 ath_err(common, "Unable to setup BEACON xmit queue\n"); 557 goto err; 558 } 559 560 priv->cabq = ath9k_htc_cabq_setup(priv); 561 if (priv->cabq == -1) { 562 ath_err(common, "Unable to setup CAB xmit queue\n"); 563 goto err; 564 } 565 566 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_BE)) { 567 ath_err(common, "Unable to setup xmit queue for BE traffic\n"); 568 goto err; 569 } 570 571 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_BK)) { 572 ath_err(common, "Unable to setup xmit queue for BK traffic\n"); 573 goto err; 574 } 575 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_VI)) { 576 ath_err(common, "Unable to setup xmit queue for VI traffic\n"); 577 goto err; 578 } 579 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_VO)) { 580 ath_err(common, "Unable to setup xmit queue for VO traffic\n"); 581 goto err; 582 } 583 584 return 0; 585 586 err: 587 return -EINVAL; 588 } 589 590 static void ath9k_init_misc(struct ath9k_htc_priv *priv) 591 { 592 struct ath_common *common = ath9k_hw_common(priv->ah); 593 594 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN); 595 596 common->last_rssi = ATH_RSSI_DUMMY_MARKER; 597 priv->ah->opmode = NL80211_IFTYPE_STATION; 598 599 priv->spec_priv.ah = priv->ah; 600 priv->spec_priv.spec_config.enabled = 0; 601 priv->spec_priv.spec_config.short_repeat = true; 602 priv->spec_priv.spec_config.count = 8; 603 priv->spec_priv.spec_config.endless = false; 604 priv->spec_priv.spec_config.period = 0x12; 605 priv->spec_priv.spec_config.fft_period = 0x02; 606 } 607 608 static int ath9k_init_priv(struct ath9k_htc_priv *priv, 609 u16 devid, char *product, 610 u32 drv_info) 611 { 612 struct ath_hw *ah = NULL; 613 struct ath_common *common; 614 int i, ret = 0, csz = 0; 615 616 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL); 617 if (!ah) 618 return -ENOMEM; 619 620 ah->dev = priv->dev; 621 ah->hw = priv->hw; 622 ah->hw_version.devid = devid; 623 ah->hw_version.usbdev = drv_info; 624 ah->ah_flags |= AH_USE_EEPROM; 625 ah->reg_ops.read = ath9k_regread; 626 ah->reg_ops.multi_read = ath9k_multi_regread; 627 ah->reg_ops.write = ath9k_regwrite; 628 ah->reg_ops.enable_write_buffer = ath9k_enable_regwrite_buffer; 629 ah->reg_ops.write_flush = ath9k_regwrite_flush; 630 ah->reg_ops.enable_rmw_buffer = ath9k_enable_rmw_buffer; 631 ah->reg_ops.rmw_flush = ath9k_reg_rmw_flush; 632 ah->reg_ops.rmw = ath9k_reg_rmw; 633 priv->ah = ah; 634 635 common = ath9k_hw_common(ah); 636 common->ops = &ah->reg_ops; 637 common->ps_ops = &ath9k_htc_ps_ops; 638 common->bus_ops = &ath9k_usb_bus_ops; 639 common->ah = ah; 640 common->hw = priv->hw; 641 common->priv = priv; 642 common->debug_mask = ath9k_debug; 643 common->btcoex_enabled = ath9k_htc_btcoex_enable == 1; 644 set_bit(ATH_OP_INVALID, &common->op_flags); 645 646 spin_lock_init(&priv->beacon_lock); 647 spin_lock_init(&priv->tx.tx_lock); 648 mutex_init(&priv->mutex); 649 mutex_init(&priv->htc_pm_lock); 650 tasklet_init(&priv->rx_tasklet, ath9k_rx_tasklet, 651 (unsigned long)priv); 652 tasklet_init(&priv->tx_failed_tasklet, ath9k_tx_failed_tasklet, 653 (unsigned long)priv); 654 INIT_DELAYED_WORK(&priv->ani_work, ath9k_htc_ani_work); 655 INIT_WORK(&priv->ps_work, ath9k_ps_work); 656 INIT_WORK(&priv->fatal_work, ath9k_fatal_work); 657 setup_timer(&priv->tx.cleanup_timer, ath9k_htc_tx_cleanup_timer, 658 (unsigned long)priv); 659 660 /* 661 * Cache line size is used to size and align various 662 * structures used to communicate with the hardware. 663 */ 664 ath_read_cachesize(common, &csz); 665 common->cachelsz = csz << 2; /* convert to bytes */ 666 667 ret = ath9k_hw_init(ah); 668 if (ret) { 669 ath_err(common, 670 "Unable to initialize hardware; initialization status: %d\n", 671 ret); 672 goto err_hw; 673 } 674 675 ret = ath9k_init_queues(priv); 676 if (ret) 677 goto err_queues; 678 679 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) 680 priv->beacon.bslot[i] = NULL; 681 priv->beacon.slottime = ATH9K_SLOT_TIME_9; 682 683 ath9k_cmn_init_channels_rates(common); 684 ath9k_cmn_init_crypto(ah); 685 ath9k_init_misc(priv); 686 ath9k_htc_init_btcoex(priv, product); 687 688 return 0; 689 690 err_queues: 691 ath9k_hw_deinit(ah); 692 err_hw: 693 694 kfree(ah); 695 priv->ah = NULL; 696 697 return ret; 698 } 699 700 static const struct ieee80211_iface_limit if_limits[] = { 701 { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) | 702 BIT(NL80211_IFTYPE_P2P_CLIENT) }, 703 { .max = 2, .types = BIT(NL80211_IFTYPE_AP) | 704 #ifdef CONFIG_MAC80211_MESH 705 BIT(NL80211_IFTYPE_MESH_POINT) | 706 #endif 707 BIT(NL80211_IFTYPE_P2P_GO) }, 708 }; 709 710 static const struct ieee80211_iface_combination if_comb = { 711 .limits = if_limits, 712 .n_limits = ARRAY_SIZE(if_limits), 713 .max_interfaces = 2, 714 .num_different_channels = 1, 715 }; 716 717 static void ath9k_set_hw_capab(struct ath9k_htc_priv *priv, 718 struct ieee80211_hw *hw) 719 { 720 struct ath_hw *ah = priv->ah; 721 struct ath_common *common = ath9k_hw_common(priv->ah); 722 struct base_eep_header *pBase; 723 724 ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING); 725 ieee80211_hw_set(hw, MFP_CAPABLE); 726 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 727 ieee80211_hw_set(hw, PS_NULLFUNC_STACK); 728 ieee80211_hw_set(hw, RX_INCLUDES_FCS); 729 ieee80211_hw_set(hw, HAS_RATE_CONTROL); 730 ieee80211_hw_set(hw, SPECTRUM_MGMT); 731 ieee80211_hw_set(hw, SIGNAL_DBM); 732 ieee80211_hw_set(hw, AMPDU_AGGREGATION); 733 734 if (ath9k_ps_enable) 735 ieee80211_hw_set(hw, SUPPORTS_PS); 736 737 hw->wiphy->interface_modes = 738 BIT(NL80211_IFTYPE_STATION) | 739 BIT(NL80211_IFTYPE_ADHOC) | 740 BIT(NL80211_IFTYPE_AP) | 741 BIT(NL80211_IFTYPE_P2P_GO) | 742 BIT(NL80211_IFTYPE_P2P_CLIENT) | 743 BIT(NL80211_IFTYPE_MESH_POINT) | 744 BIT(NL80211_IFTYPE_OCB); 745 746 hw->wiphy->iface_combinations = &if_comb; 747 hw->wiphy->n_iface_combinations = 1; 748 749 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 750 751 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN | 752 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | 753 WIPHY_FLAG_HAS_CHANNEL_SWITCH; 754 755 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 756 757 hw->queues = 4; 758 hw->max_listen_interval = 1; 759 760 hw->vif_data_size = sizeof(struct ath9k_htc_vif); 761 hw->sta_data_size = sizeof(struct ath9k_htc_sta); 762 763 /* tx_frame_hdr is larger than tx_mgmt_hdr anyway */ 764 hw->extra_tx_headroom = sizeof(struct tx_frame_hdr) + 765 sizeof(struct htc_frame_hdr) + 4; 766 767 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) 768 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = 769 &common->sbands[IEEE80211_BAND_2GHZ]; 770 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) 771 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = 772 &common->sbands[IEEE80211_BAND_5GHZ]; 773 774 ath9k_cmn_reload_chainmask(ah); 775 776 pBase = ath9k_htc_get_eeprom_base(priv); 777 if (pBase) { 778 hw->wiphy->available_antennas_rx = pBase->rxMask; 779 hw->wiphy->available_antennas_tx = pBase->txMask; 780 } 781 782 SET_IEEE80211_PERM_ADDR(hw, common->macaddr); 783 } 784 785 static int ath9k_init_firmware_version(struct ath9k_htc_priv *priv) 786 { 787 struct ieee80211_hw *hw = priv->hw; 788 struct wmi_fw_version cmd_rsp; 789 int ret; 790 791 memset(&cmd_rsp, 0, sizeof(cmd_rsp)); 792 793 WMI_CMD(WMI_GET_FW_VERSION); 794 if (ret) 795 return -EINVAL; 796 797 priv->fw_version_major = be16_to_cpu(cmd_rsp.major); 798 priv->fw_version_minor = be16_to_cpu(cmd_rsp.minor); 799 800 snprintf(hw->wiphy->fw_version, sizeof(hw->wiphy->fw_version), "%d.%d", 801 priv->fw_version_major, 802 priv->fw_version_minor); 803 804 dev_info(priv->dev, "ath9k_htc: FW Version: %d.%d\n", 805 priv->fw_version_major, 806 priv->fw_version_minor); 807 808 /* 809 * Check if the available FW matches the driver's 810 * required version. 811 */ 812 if (priv->fw_version_major != MAJOR_VERSION_REQ || 813 priv->fw_version_minor < MINOR_VERSION_REQ) { 814 dev_err(priv->dev, "ath9k_htc: Please upgrade to FW version %d.%d\n", 815 MAJOR_VERSION_REQ, MINOR_VERSION_REQ); 816 return -EINVAL; 817 } 818 819 if (priv->fw_version_major == 1 && priv->fw_version_minor < 4) 820 set_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags); 821 822 dev_info(priv->dev, "FW RMW support: %s\n", 823 test_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags) ? "Off" : "On"); 824 825 return 0; 826 } 827 828 static int ath9k_init_device(struct ath9k_htc_priv *priv, 829 u16 devid, char *product, u32 drv_info) 830 { 831 struct ieee80211_hw *hw = priv->hw; 832 struct ath_common *common; 833 struct ath_hw *ah; 834 int error = 0; 835 struct ath_regulatory *reg; 836 char hw_name[64]; 837 838 /* Bring up device */ 839 error = ath9k_init_priv(priv, devid, product, drv_info); 840 if (error != 0) 841 goto err_init; 842 843 ah = priv->ah; 844 common = ath9k_hw_common(ah); 845 ath9k_set_hw_capab(priv, hw); 846 847 error = ath9k_init_firmware_version(priv); 848 if (error != 0) 849 goto err_fw; 850 851 /* Initialize regulatory */ 852 error = ath_regd_init(&common->regulatory, priv->hw->wiphy, 853 ath9k_reg_notifier); 854 if (error) 855 goto err_regd; 856 857 reg = &common->regulatory; 858 859 /* Setup TX */ 860 error = ath9k_tx_init(priv); 861 if (error != 0) 862 goto err_tx; 863 864 /* Setup RX */ 865 error = ath9k_rx_init(priv); 866 if (error != 0) 867 goto err_rx; 868 869 ath9k_hw_disable(priv->ah); 870 #ifdef CONFIG_MAC80211_LEDS 871 /* must be initialized before ieee80211_register_hw */ 872 priv->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(priv->hw, 873 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_htc_tpt_blink, 874 ARRAY_SIZE(ath9k_htc_tpt_blink)); 875 #endif 876 877 /* Register with mac80211 */ 878 error = ieee80211_register_hw(hw); 879 if (error) 880 goto err_register; 881 882 /* Handle world regulatory */ 883 if (!ath_is_world_regd(reg)) { 884 error = regulatory_hint(hw->wiphy, reg->alpha2); 885 if (error) 886 goto err_world; 887 } 888 889 error = ath9k_htc_init_debug(priv->ah); 890 if (error) { 891 ath_err(common, "Unable to create debugfs files\n"); 892 goto err_world; 893 } 894 895 ath_dbg(common, CONFIG, 896 "WMI:%d, BCN:%d, CAB:%d, UAPSD:%d, MGMT:%d, BE:%d, BK:%d, VI:%d, VO:%d\n", 897 priv->wmi_cmd_ep, 898 priv->beacon_ep, 899 priv->cab_ep, 900 priv->uapsd_ep, 901 priv->mgmt_ep, 902 priv->data_be_ep, 903 priv->data_bk_ep, 904 priv->data_vi_ep, 905 priv->data_vo_ep); 906 907 ath9k_hw_name(priv->ah, hw_name, sizeof(hw_name)); 908 wiphy_info(hw->wiphy, "%s\n", hw_name); 909 910 ath9k_init_leds(priv); 911 ath9k_start_rfkill_poll(priv); 912 913 return 0; 914 915 err_world: 916 ieee80211_unregister_hw(hw); 917 err_register: 918 ath9k_rx_cleanup(priv); 919 err_rx: 920 ath9k_tx_cleanup(priv); 921 err_tx: 922 /* Nothing */ 923 err_regd: 924 /* Nothing */ 925 err_fw: 926 ath9k_deinit_priv(priv); 927 err_init: 928 return error; 929 } 930 931 int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev, 932 u16 devid, char *product, u32 drv_info) 933 { 934 struct ieee80211_hw *hw; 935 struct ath9k_htc_priv *priv; 936 int ret; 937 938 hw = ieee80211_alloc_hw(sizeof(struct ath9k_htc_priv), &ath9k_htc_ops); 939 if (!hw) 940 return -ENOMEM; 941 942 priv = hw->priv; 943 priv->hw = hw; 944 priv->htc = htc_handle; 945 priv->dev = dev; 946 htc_handle->drv_priv = priv; 947 SET_IEEE80211_DEV(hw, priv->dev); 948 949 ret = ath9k_htc_wait_for_target(priv); 950 if (ret) 951 goto err_free; 952 953 priv->wmi = ath9k_init_wmi(priv); 954 if (!priv->wmi) { 955 ret = -EINVAL; 956 goto err_free; 957 } 958 959 ret = ath9k_init_htc_services(priv, devid, drv_info); 960 if (ret) 961 goto err_init; 962 963 ret = ath9k_init_device(priv, devid, product, drv_info); 964 if (ret) 965 goto err_init; 966 967 return 0; 968 969 err_init: 970 ath9k_deinit_wmi(priv); 971 err_free: 972 ieee80211_free_hw(hw); 973 return ret; 974 } 975 976 void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug) 977 { 978 if (htc_handle->drv_priv) { 979 980 /* Check if the device has been yanked out. */ 981 if (hotunplug) 982 htc_handle->drv_priv->ah->ah_flags |= AH_UNPLUGGED; 983 984 ath9k_deinit_device(htc_handle->drv_priv); 985 ath9k_deinit_wmi(htc_handle->drv_priv); 986 ieee80211_free_hw(htc_handle->drv_priv->hw); 987 } 988 } 989 990 #ifdef CONFIG_PM 991 992 void ath9k_htc_suspend(struct htc_target *htc_handle) 993 { 994 ath9k_htc_setpower(htc_handle->drv_priv, ATH9K_PM_FULL_SLEEP); 995 } 996 997 int ath9k_htc_resume(struct htc_target *htc_handle) 998 { 999 struct ath9k_htc_priv *priv = htc_handle->drv_priv; 1000 int ret; 1001 1002 ret = ath9k_htc_wait_for_target(priv); 1003 if (ret) 1004 return ret; 1005 1006 ret = ath9k_init_htc_services(priv, priv->ah->hw_version.devid, 1007 priv->ah->hw_version.usbdev); 1008 ath9k_configure_leds(priv); 1009 1010 return ret; 1011 } 1012 #endif 1013 1014 static int __init ath9k_htc_init(void) 1015 { 1016 if (ath9k_hif_usb_init() < 0) { 1017 pr_err("No USB devices found, driver not installed\n"); 1018 return -ENODEV; 1019 } 1020 1021 return 0; 1022 } 1023 module_init(ath9k_htc_init); 1024 1025 static void __exit ath9k_htc_exit(void) 1026 { 1027 ath9k_hif_usb_exit(); 1028 pr_info("Driver unloaded\n"); 1029 } 1030 module_exit(ath9k_htc_exit);
1 2 #include <linux/kernel.h> 3 #include <linux/mutex.h> 4 #include <linux/spinlock.h> 5 #include <linux/errno.h> 6 #include <verifier/rcv.h> 7 #include <linux/list.h> 8 9 /* mutexes */ 10 extern int mutex_lock_interruptible(struct mutex *lock); 11 extern int mutex_lock_killable(struct mutex *lock); 12 extern void mutex_lock(struct mutex *lock); 13 14 /* mutex model functions */ 15 extern void ldv_mutex_lock(struct mutex *lock, char *sign); 16 extern int ldv_mutex_is_locked(struct mutex *lock, char *sign); 17 extern void ldv_mutex_unlock(struct mutex *lock, char *sign); 18 19 20 /* Spin locks */ 21 extern void __ldv_spin_lock(spinlock_t *lock); 22 extern void __ldv_spin_unlock(spinlock_t *lock); 23 extern int __ldv_spin_trylock(spinlock_t *lock); 24 extern void __ldv_spin_unlock_wait(spinlock_t *lock); 25 extern void __ldv_spin_can_lock(spinlock_t *lock); 26 extern int __ldv_atomic_dec_and_lock(spinlock_t *lock); 27 28 /* spin model functions */ 29 extern void ldv_spin_lock(spinlock_t *lock, char *sign); 30 extern void ldv_spin_unlock(spinlock_t *lock, char *sign); 31 extern int ldv_spin_is_locked(spinlock_t *lock, char *sign); 32 33 /* Support for list binder functions */ 34 static inline struct list_head *ldv_list_get_first(struct list_head *head) { 35 return head->next; 36 } 37 38 static inline int ldv_list_is_stop(struct list_head *pos, struct list_head *head) { 39 return pos==head; 40 } 41 42 static inline struct list_head *ldv_list_get_next(struct list_head *pos) { 43 return pos->next; 44 } 45 46 #include <linux/mutex.h> 47 #include <linux/slab.h> 48 #include <verifier/rcv.h> 49 #include <linux/timer.h> 50 #include <linux/rtnetlink.h> 51 #include <linux/gfp.h> 52 struct file *fops_xmit_group2; 53 int ldv_state_variable_8; 54 int ldv_timer_1_3; 55 struct ath_common *ath9k_usb_bus_ops_group0; 56 struct inode *fops_debug_group1; 57 struct inode *fops_queue_group1; 58 struct ath_common *ath9k_htc_ps_ops_group0; 59 int ldv_state_variable_0; 60 int ldv_state_variable_5; 61 int ldv_state_variable_13; 62 int ldv_state_variable_12; 63 struct file *fops_tgt_tx_stats_group2; 64 struct file *fops_queue_group2; 65 int ldv_state_variable_14; 66 int ldv_timer_1_0; 67 int ldv_state_variable_9; 68 struct inode *fops_tgt_tx_stats_group1; 69 struct file *fops_debug_group2; 70 int ref_cnt; 71 struct mutex key_mtx; 72 int ldv_state_variable_1; 73 int ldv_state_variable_7; 74 struct inode *fops_xmit_group1; 75 struct inode *fops_skb_rx_group1; 76 struct file *fops_tgt_int_stats_group2; 77 struct usb_interface *ath9k_hif_usb_driver_group1; 78 struct timer_list * ldv_timer_list_1_3; 79 int ldv_state_variable_10; 80 struct timer_list * ldv_timer_list_1_1; 81 struct timer_list * ldv_timer_list_1_0; 82 int ldv_state_variable_6; 83 int ldv_timer_1_2; 84 int ldv_timer_1_1; 85 int ldv_state_variable_2; 86 struct timer_list * ldv_timer_list_1_2; 87 struct inode *fops_tgt_int_stats_group1; 88 struct ieee80211_hw *ath9k_htc_ops_group0; 89 int usb_counter; 90 int ldv_state_variable_11; 91 struct file *fops_slot_group2; 92 int LDV_IN_INTERRUPT = 1; 93 struct inode *fops_slot_group1; 94 struct inode *fops_tgt_rx_stats_group1; 95 int __VERIFIER_nondet_int(void); 96 struct file *fops_tgt_rx_stats_group2; 97 struct mutex fs_mutex; 98 int ldv_state_variable_3; 99 struct mutex ar_mutex; 100 struct file *fops_skb_rx_group2; 101 int ldv_state_variable_4; 102 void ldv_file_operations_7(void); 103 void ldv_file_operations_6(void); 104 void ldv_file_operations_2(void); 105 void activate_pending_timer_1(struct timer_list * timer, unsigned long data, int pending_flag); 106 void ldv_initialyze_ath_bus_ops_10(void); 107 int evil_hack_12(void); 108 void timer_init_1(void); 109 void ldv_file_operations_9(void); 110 void ldv_usb_driver_13(void); 111 void ldv_file_operations_3(void); 112 void ldv_file_operations_8(void); 113 int reg_timer_1(struct timer_list * timer, void (*function)(unsigned long), unsigned long data); 114 void ldv_initialyze_ath_ps_ops_11(void); 115 int evil_hack_key_12(void); 116 void ldv_initialyze_ieee80211_ops_12(void); 117 void disable_suitable_timer_1(struct timer_list * timer); 118 void activate_suitable_timer_1(struct timer_list * timer, unsigned long data); 119 int evil_hack_fs_lock(void); 120 int __VERIFIER_nondet_int(void); 121 void ldv_file_operations_5(void); 122 void choose_timer_1(void); 123 void ldv_timer_1(int state, struct timer_list * timer); 124 int evil_hack_ar_lock(void); 125 void ldv_file_operations_4(void); 126 #line 1 "/work/ldvuser/andrianov/work/current--X--drivers/net/wireless/ath/ath9k/--X--defaultlinux-4.5-rc7--X--races--X--cpachecker/linux-4.5-rc7/csd_deg_dscv/74/dscv_tempdir/dscv/ri/races/drivers/net/wireless/ath/ath9k/htc_drv_init.c" 127 /* 128 * Copyright (c) 2010-2011 Atheros Communications Inc. 129 * 130 * Permission to use, copy, modify, and/or distribute this software for any 131 * purpose with or without fee is hereby granted, provided that the above 132 * copyright notice and this permission notice appear in all copies. 133 * 134 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 135 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 136 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 137 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 138 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 139 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 140 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 141 */ 142 143 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 144 145 #include "htc.h" 146 147 MODULE_AUTHOR("Atheros Communications"); 148 MODULE_LICENSE("Dual BSD/GPL"); 149 MODULE_DESCRIPTION("Atheros driver 802.11n HTC based wireless devices"); 150 151 static unsigned int ath9k_debug = ATH_DBG_DEFAULT; 152 module_param_named(debug, ath9k_debug, uint, 0); 153 MODULE_PARM_DESC(debug, "Debugging mask"); 154 155 int htc_modparam_nohwcrypt; 156 module_param_named(nohwcrypt, htc_modparam_nohwcrypt, int, 0444); 157 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption"); 158 159 static int ath9k_htc_btcoex_enable; 160 module_param_named(btcoex_enable, ath9k_htc_btcoex_enable, int, 0444); 161 MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence"); 162 163 static int ath9k_ps_enable; 164 module_param_named(ps_enable, ath9k_ps_enable, int, 0444); 165 MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave"); 166 167 int htc_use_dev_fw = 0; 168 module_param_named(use_dev_fw, htc_use_dev_fw, int, 0444); 169 MODULE_PARM_DESC(use_dev_fw, "Use development FW version"); 170 171 #ifdef CONFIG_MAC80211_LEDS 172 int ath9k_htc_led_blink = 1; 173 module_param_named(blink, ath9k_htc_led_blink, int, 0444); 174 MODULE_PARM_DESC(blink, "Enable LED blink on activity"); 175 176 static const struct ieee80211_tpt_blink ath9k_htc_tpt_blink[] = { 177 { .throughput = 0 * 1024, .blink_time = 334 }, 178 { .throughput = 1 * 1024, .blink_time = 260 }, 179 { .throughput = 5 * 1024, .blink_time = 220 }, 180 { .throughput = 10 * 1024, .blink_time = 190 }, 181 { .throughput = 20 * 1024, .blink_time = 170 }, 182 { .throughput = 50 * 1024, .blink_time = 150 }, 183 { .throughput = 70 * 1024, .blink_time = 130 }, 184 { .throughput = 100 * 1024, .blink_time = 110 }, 185 { .throughput = 200 * 1024, .blink_time = 80 }, 186 { .throughput = 300 * 1024, .blink_time = 50 }, 187 }; 188 #endif 189 190 static void ath9k_htc_op_ps_wakeup(struct ath_common *common) 191 { 192 ath9k_htc_ps_wakeup((struct ath9k_htc_priv *) common->priv); 193 } 194 195 static void ath9k_htc_op_ps_restore(struct ath_common *common) 196 { 197 ath9k_htc_ps_restore((struct ath9k_htc_priv *) common->priv); 198 } 199 200 static struct ath_ps_ops ath9k_htc_ps_ops = { 201 .wakeup = ath9k_htc_op_ps_wakeup, 202 .restore = ath9k_htc_op_ps_restore, 203 }; 204 205 static int ath9k_htc_wait_for_target(struct ath9k_htc_priv *priv) 206 { 207 unsigned long time_left; 208 209 if (atomic_read(&priv->htc->tgt_ready) > 0) { 210 atomic_dec(&priv->htc->tgt_ready); 211 return 0; 212 } 213 214 /* Firmware can take up to 50ms to get ready, to be safe use 1 second */ 215 time_left = wait_for_completion_timeout(&priv->htc->target_wait, HZ); 216 if (!time_left) { 217 dev_err(priv->dev, "ath9k_htc: Target is unresponsive\n"); 218 return -ETIMEDOUT; 219 } 220 221 atomic_dec(&priv->htc->tgt_ready); 222 223 return 0; 224 } 225 226 static void ath9k_deinit_priv(struct ath9k_htc_priv *priv) 227 { 228 ath9k_hw_deinit(priv->ah); 229 kfree(priv->ah); 230 priv->ah = NULL; 231 } 232 233 static void ath9k_deinit_device(struct ath9k_htc_priv *priv) 234 { 235 struct ieee80211_hw *hw = priv->hw; 236 237 wiphy_rfkill_stop_polling(hw->wiphy); 238 ath9k_deinit_leds(priv); 239 ath9k_htc_deinit_debug(priv); 240 ieee80211_unregister_hw(hw); 241 ath9k_rx_cleanup(priv); 242 ath9k_tx_cleanup(priv); 243 ath9k_deinit_priv(priv); 244 } 245 246 static inline int ath9k_htc_connect_svc(struct ath9k_htc_priv *priv, 247 u16 service_id, 248 void (*tx) (void *, 249 struct sk_buff *, 250 enum htc_endpoint_id, 251 bool txok), 252 enum htc_endpoint_id *ep_id) 253 { 254 struct htc_service_connreq req; 255 256 memset(&req, 0, sizeof(struct htc_service_connreq)); 257 258 req.service_id = service_id; 259 req.ep_callbacks.priv = priv; 260 req.ep_callbacks.rx = ath9k_htc_rxep; 261 req.ep_callbacks.tx = tx; 262 263 return htc_connect_service(priv->htc, &req, ep_id); 264 } 265 266 static int ath9k_init_htc_services(struct ath9k_htc_priv *priv, u16 devid, 267 u32 drv_info) 268 { 269 int ret; 270 271 /* WMI CMD*/ 272 ret = ath9k_wmi_connect(priv->htc, priv->wmi, &priv->wmi_cmd_ep); 273 if (ret) 274 goto err; 275 276 /* Beacon */ 277 ret = ath9k_htc_connect_svc(priv, WMI_BEACON_SVC, ath9k_htc_beaconep, 278 &priv->beacon_ep); 279 if (ret) 280 goto err; 281 282 /* CAB */ 283 ret = ath9k_htc_connect_svc(priv, WMI_CAB_SVC, ath9k_htc_txep, 284 &priv->cab_ep); 285 if (ret) 286 goto err; 287 288 289 /* UAPSD */ 290 ret = ath9k_htc_connect_svc(priv, WMI_UAPSD_SVC, ath9k_htc_txep, 291 &priv->uapsd_ep); 292 if (ret) 293 goto err; 294 295 /* MGMT */ 296 ret = ath9k_htc_connect_svc(priv, WMI_MGMT_SVC, ath9k_htc_txep, 297 &priv->mgmt_ep); 298 if (ret) 299 goto err; 300 301 /* DATA BE */ 302 ret = ath9k_htc_connect_svc(priv, WMI_DATA_BE_SVC, ath9k_htc_txep, 303 &priv->data_be_ep); 304 if (ret) 305 goto err; 306 307 /* DATA BK */ 308 ret = ath9k_htc_connect_svc(priv, WMI_DATA_BK_SVC, ath9k_htc_txep, 309 &priv->data_bk_ep); 310 if (ret) 311 goto err; 312 313 /* DATA VI */ 314 ret = ath9k_htc_connect_svc(priv, WMI_DATA_VI_SVC, ath9k_htc_txep, 315 &priv->data_vi_ep); 316 if (ret) 317 goto err; 318 319 /* DATA VO */ 320 ret = ath9k_htc_connect_svc(priv, WMI_DATA_VO_SVC, ath9k_htc_txep, 321 &priv->data_vo_ep); 322 if (ret) 323 goto err; 324 325 /* 326 * Setup required credits before initializing HTC. 327 * This is a bit hacky, but, since queuing is done in 328 * the HIF layer, shouldn't matter much. 329 */ 330 331 if (IS_AR7010_DEVICE(drv_info)) 332 priv->htc->credits = 45; 333 else 334 priv->htc->credits = 33; 335 336 ret = htc_init(priv->htc); 337 if (ret) 338 goto err; 339 340 dev_info(priv->dev, "ath9k_htc: HTC initialized with %d credits\n", 341 priv->htc->credits); 342 343 return 0; 344 345 err: 346 dev_err(priv->dev, "ath9k_htc: Unable to initialize HTC services\n"); 347 return ret; 348 } 349 350 static void ath9k_reg_notifier(struct wiphy *wiphy, 351 struct regulatory_request *request) 352 { 353 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 354 struct ath9k_htc_priv *priv = hw->priv; 355 356 ath_reg_notifier_apply(wiphy, request, 357 ath9k_hw_regulatory(priv->ah)); 358 } 359 360 static unsigned int ath9k_regread(void *hw_priv, u32 reg_offset) 361 { 362 struct ath_hw *ah = (struct ath_hw *) hw_priv; 363 struct ath_common *common = ath9k_hw_common(ah); 364 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 365 __be32 val, reg = cpu_to_be32(reg_offset); 366 int r; 367 368 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID, 369 (u8 *) &reg, sizeof(reg), 370 (u8 *) &val, sizeof(val), 371 100); 372 if (unlikely(r)) { 373 ath_dbg(common, WMI, "REGISTER READ FAILED: (0x%04x, %d)\n", 374 reg_offset, r); 375 return -EIO; 376 } 377 378 return be32_to_cpu(val); 379 } 380 381 static void ath9k_multi_regread(void *hw_priv, u32 *addr, 382 u32 *val, u16 count) 383 { 384 struct ath_hw *ah = (struct ath_hw *) hw_priv; 385 struct ath_common *common = ath9k_hw_common(ah); 386 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 387 __be32 tmpaddr[8]; 388 __be32 tmpval[8]; 389 int i, ret; 390 391 for (i = 0; i < count; i++) { 392 tmpaddr[i] = cpu_to_be32(addr[i]); 393 } 394 395 ret = ath9k_wmi_cmd(priv->wmi, WMI_REG_READ_CMDID, 396 (u8 *)tmpaddr , sizeof(u32) * count, 397 (u8 *)tmpval, sizeof(u32) * count, 398 100); 399 if (unlikely(ret)) { 400 ath_dbg(common, WMI, 401 "Multiple REGISTER READ FAILED (count: %d)\n", count); 402 } 403 404 for (i = 0; i < count; i++) { 405 val[i] = be32_to_cpu(tmpval[i]); 406 } 407 } 408 409 static void ath9k_regwrite_multi(struct ath_common *common) 410 { 411 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 412 u32 rsp_status; 413 int r; 414 415 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID, 416 (u8 *) &priv->wmi->multi_write, 417 sizeof(struct register_write) * priv->wmi->multi_write_idx, 418 (u8 *) &rsp_status, sizeof(rsp_status), 419 100); 420 if (unlikely(r)) { 421 ath_dbg(common, WMI, 422 "REGISTER WRITE FAILED, multi len: %d\n", 423 priv->wmi->multi_write_idx); 424 } 425 priv->wmi->multi_write_idx = 0; 426 } 427 428 static void ath9k_regwrite_single(void *hw_priv, u32 val, u32 reg_offset) 429 { 430 struct ath_hw *ah = (struct ath_hw *) hw_priv; 431 struct ath_common *common = ath9k_hw_common(ah); 432 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 433 const __be32 buf[2] = { 434 cpu_to_be32(reg_offset), 435 cpu_to_be32(val), 436 }; 437 int r; 438 439 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_WRITE_CMDID, 440 (u8 *) &buf, sizeof(buf), 441 (u8 *) &val, sizeof(val), 442 100); 443 if (unlikely(r)) { 444 ath_dbg(common, WMI, "REGISTER WRITE FAILED:(0x%04x, %d)\n", 445 reg_offset, r); 446 } 447 } 448 449 static void ath9k_regwrite_buffer(void *hw_priv, u32 val, u32 reg_offset) 450 { 451 struct ath_hw *ah = (struct ath_hw *) hw_priv; 452 struct ath_common *common = ath9k_hw_common(ah); 453 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 454 455 mutex_lock(&priv->wmi->multi_write_mutex); 456 457 /* Store the register/value */ 458 priv->wmi->multi_write[priv->wmi->multi_write_idx].reg = 459 cpu_to_be32(reg_offset); 460 priv->wmi->multi_write[priv->wmi->multi_write_idx].val = 461 cpu_to_be32(val); 462 463 priv->wmi->multi_write_idx++; 464 465 /* If the buffer is full, send it out. */ 466 if (priv->wmi->multi_write_idx == MAX_CMD_NUMBER) 467 ath9k_regwrite_multi(common); 468 469 mutex_unlock(&priv->wmi->multi_write_mutex); 470 } 471 472 static void ath9k_regwrite(void *hw_priv, u32 val, u32 reg_offset) 473 { 474 struct ath_hw *ah = (struct ath_hw *) hw_priv; 475 struct ath_common *common = ath9k_hw_common(ah); 476 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 477 478 if (atomic_read(&priv->wmi->mwrite_cnt)) 479 ath9k_regwrite_buffer(hw_priv, val, reg_offset); 480 else 481 ath9k_regwrite_single(hw_priv, val, reg_offset); 482 } 483 484 static void ath9k_enable_regwrite_buffer(void *hw_priv) 485 { 486 struct ath_hw *ah = (struct ath_hw *) hw_priv; 487 struct ath_common *common = ath9k_hw_common(ah); 488 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 489 490 atomic_inc(&priv->wmi->mwrite_cnt); 491 } 492 493 static void ath9k_regwrite_flush(void *hw_priv) 494 { 495 struct ath_hw *ah = (struct ath_hw *) hw_priv; 496 struct ath_common *common = ath9k_hw_common(ah); 497 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 498 499 atomic_dec(&priv->wmi->mwrite_cnt); 500 501 mutex_lock(&priv->wmi->multi_write_mutex); 502 503 if (priv->wmi->multi_write_idx) 504 ath9k_regwrite_multi(common); 505 506 mutex_unlock(&priv->wmi->multi_write_mutex); 507 } 508 509 static void ath9k_reg_rmw_buffer(void *hw_priv, 510 u32 reg_offset, u32 set, u32 clr) 511 { 512 struct ath_hw *ah = (struct ath_hw *) hw_priv; 513 struct ath_common *common = ath9k_hw_common(ah); 514 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 515 u32 rsp_status; 516 int r; 517 518 mutex_lock(&priv->wmi->multi_rmw_mutex); 519 520 /* Store the register/value */ 521 priv->wmi->multi_rmw[priv->wmi->multi_rmw_idx].reg = 522 cpu_to_be32(reg_offset); 523 priv->wmi->multi_rmw[priv->wmi->multi_rmw_idx].set = 524 cpu_to_be32(set); 525 priv->wmi->multi_rmw[priv->wmi->multi_rmw_idx].clr = 526 cpu_to_be32(clr); 527 528 priv->wmi->multi_rmw_idx++; 529 530 /* If the buffer is full, send it out. */ 531 if (priv->wmi->multi_rmw_idx == MAX_RMW_CMD_NUMBER) { 532 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_RMW_CMDID, 533 (u8 *) &priv->wmi->multi_rmw, 534 sizeof(struct register_write) * priv->wmi->multi_rmw_idx, 535 (u8 *) &rsp_status, sizeof(rsp_status), 536 100); 537 if (unlikely(r)) { 538 ath_dbg(common, WMI, 539 "REGISTER RMW FAILED, multi len: %d\n", 540 priv->wmi->multi_rmw_idx); 541 } 542 priv->wmi->multi_rmw_idx = 0; 543 } 544 545 mutex_unlock(&priv->wmi->multi_rmw_mutex); 546 } 547 548 static void ath9k_reg_rmw_flush(void *hw_priv) 549 { 550 struct ath_hw *ah = (struct ath_hw *) hw_priv; 551 struct ath_common *common = ath9k_hw_common(ah); 552 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 553 u32 rsp_status; 554 int r; 555 556 if (test_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags)) 557 return; 558 559 atomic_dec(&priv->wmi->m_rmw_cnt); 560 561 mutex_lock(&priv->wmi->multi_rmw_mutex); 562 563 if (priv->wmi->multi_rmw_idx) { 564 r = ath9k_wmi_cmd(priv->wmi, WMI_REG_RMW_CMDID, 565 (u8 *) &priv->wmi->multi_rmw, 566 sizeof(struct register_rmw) * priv->wmi->multi_rmw_idx, 567 (u8 *) &rsp_status, sizeof(rsp_status), 568 100); 569 if (unlikely(r)) { 570 ath_dbg(common, WMI, 571 "REGISTER RMW FAILED, multi len: %d\n", 572 priv->wmi->multi_rmw_idx); 573 } 574 priv->wmi->multi_rmw_idx = 0; 575 } 576 577 mutex_unlock(&priv->wmi->multi_rmw_mutex); 578 } 579 580 static void ath9k_enable_rmw_buffer(void *hw_priv) 581 { 582 struct ath_hw *ah = (struct ath_hw *) hw_priv; 583 struct ath_common *common = ath9k_hw_common(ah); 584 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 585 586 if (test_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags)) 587 return; 588 589 atomic_inc(&priv->wmi->m_rmw_cnt); 590 } 591 592 static u32 ath9k_reg_rmw_single(void *hw_priv, 593 u32 reg_offset, u32 set, u32 clr) 594 { 595 struct ath_hw *ah = (struct ath_hw *) hw_priv; 596 struct ath_common *common = ath9k_hw_common(ah); 597 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 598 struct register_rmw buf, buf_ret; 599 int ret; 600 u32 val = 0; 601 602 buf.reg = cpu_to_be32(reg_offset); 603 buf.set = cpu_to_be32(set); 604 buf.clr = cpu_to_be32(clr); 605 606 ret = ath9k_wmi_cmd(priv->wmi, WMI_REG_RMW_CMDID, 607 (u8 *) &buf, sizeof(buf), 608 (u8 *) &buf_ret, sizeof(buf_ret), 609 100); 610 if (unlikely(ret)) { 611 ath_dbg(common, WMI, "REGISTER RMW FAILED:(0x%04x, %d)\n", 612 reg_offset, ret); 613 } 614 return val; 615 } 616 617 static u32 ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr) 618 { 619 struct ath_hw *ah = (struct ath_hw *) hw_priv; 620 struct ath_common *common = ath9k_hw_common(ah); 621 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv; 622 623 if (test_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags)) { 624 u32 val; 625 626 val = REG_READ(ah, reg_offset); 627 val &= ~clr; 628 val |= set; 629 REG_WRITE(ah, reg_offset, val); 630 631 return 0; 632 } 633 634 if (atomic_read(&priv->wmi->m_rmw_cnt)) 635 ath9k_reg_rmw_buffer(hw_priv, reg_offset, set, clr); 636 else 637 ath9k_reg_rmw_single(hw_priv, reg_offset, set, clr); 638 639 return 0; 640 } 641 642 static void ath_usb_read_cachesize(struct ath_common *common, int *csz) 643 { 644 *csz = L1_CACHE_BYTES >> 2; 645 } 646 647 static bool ath_usb_eeprom_read(struct ath_common *common, u32 off, u16 *data) 648 { 649 struct ath_hw *ah = (struct ath_hw *) common->ah; 650 651 (void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S)); 652 653 if (!ath9k_hw_wait(ah, 654 AR_EEPROM_STATUS_DATA, 655 AR_EEPROM_STATUS_DATA_BUSY | 656 AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0, 657 AH_WAIT_TIMEOUT)) 658 return false; 659 660 *data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA), 661 AR_EEPROM_STATUS_DATA_VAL); 662 663 return true; 664 } 665 666 static const struct ath_bus_ops ath9k_usb_bus_ops = { 667 .ath_bus_type = ATH_USB, 668 .read_cachesize = ath_usb_read_cachesize, 669 .eeprom_read = ath_usb_eeprom_read, 670 }; 671 672 static int ath9k_init_queues(struct ath9k_htc_priv *priv) 673 { 674 struct ath_common *common = ath9k_hw_common(priv->ah); 675 int i; 676 677 for (i = 0; i < ARRAY_SIZE(priv->hwq_map); i++) 678 priv->hwq_map[i] = -1; 679 680 priv->beacon.beaconq = ath9k_hw_beaconq_setup(priv->ah); 681 if (priv->beacon.beaconq == -1) { 682 ath_err(common, "Unable to setup BEACON xmit queue\n"); 683 goto err; 684 } 685 686 priv->cabq = ath9k_htc_cabq_setup(priv); 687 if (priv->cabq == -1) { 688 ath_err(common, "Unable to setup CAB xmit queue\n"); 689 goto err; 690 } 691 692 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_BE)) { 693 ath_err(common, "Unable to setup xmit queue for BE traffic\n"); 694 goto err; 695 } 696 697 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_BK)) { 698 ath_err(common, "Unable to setup xmit queue for BK traffic\n"); 699 goto err; 700 } 701 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_VI)) { 702 ath_err(common, "Unable to setup xmit queue for VI traffic\n"); 703 goto err; 704 } 705 if (!ath9k_htc_txq_setup(priv, IEEE80211_AC_VO)) { 706 ath_err(common, "Unable to setup xmit queue for VO traffic\n"); 707 goto err; 708 } 709 710 return 0; 711 712 err: 713 return -EINVAL; 714 } 715 716 static void ath9k_init_misc(struct ath9k_htc_priv *priv) 717 { 718 struct ath_common *common = ath9k_hw_common(priv->ah); 719 720 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN); 721 722 common->last_rssi = ATH_RSSI_DUMMY_MARKER; 723 priv->ah->opmode = NL80211_IFTYPE_STATION; 724 725 priv->spec_priv.ah = priv->ah; 726 priv->spec_priv.spec_config.enabled = 0; 727 priv->spec_priv.spec_config.short_repeat = true; 728 priv->spec_priv.spec_config.count = 8; 729 priv->spec_priv.spec_config.endless = false; 730 priv->spec_priv.spec_config.period = 0x12; 731 priv->spec_priv.spec_config.fft_period = 0x02; 732 } 733 734 static int ath9k_init_priv(struct ath9k_htc_priv *priv, 735 u16 devid, char *product, 736 u32 drv_info) 737 { 738 struct ath_hw *ah = NULL; 739 struct ath_common *common; 740 int i, ret = 0, csz = 0; 741 742 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL); 743 if (!ah) 744 return -ENOMEM; 745 746 ah->dev = priv->dev; 747 ah->hw = priv->hw; 748 ah->hw_version.devid = devid; 749 ah->hw_version.usbdev = drv_info; 750 ah->ah_flags |= AH_USE_EEPROM; 751 ah->reg_ops.read = ath9k_regread; 752 ah->reg_ops.multi_read = ath9k_multi_regread; 753 ah->reg_ops.write = ath9k_regwrite; 754 ah->reg_ops.enable_write_buffer = ath9k_enable_regwrite_buffer; 755 ah->reg_ops.write_flush = ath9k_regwrite_flush; 756 ah->reg_ops.enable_rmw_buffer = ath9k_enable_rmw_buffer; 757 ah->reg_ops.rmw_flush = ath9k_reg_rmw_flush; 758 ah->reg_ops.rmw = ath9k_reg_rmw; 759 priv->ah = ah; 760 761 common = ath9k_hw_common(ah); 762 common->ops = &ah->reg_ops; 763 common->ps_ops = &ath9k_htc_ps_ops; 764 common->bus_ops = &ath9k_usb_bus_ops; 765 common->ah = ah; 766 common->hw = priv->hw; 767 common->priv = priv; 768 common->debug_mask = ath9k_debug; 769 common->btcoex_enabled = ath9k_htc_btcoex_enable == 1; 770 set_bit(ATH_OP_INVALID, &common->op_flags); 771 772 spin_lock_init(&priv->beacon_lock); 773 spin_lock_init(&priv->tx.tx_lock); 774 mutex_init(&priv->mutex); 775 mutex_init(&priv->htc_pm_lock); 776 tasklet_init(&priv->rx_tasklet, ath9k_rx_tasklet, 777 (unsigned long)priv); 778 tasklet_init(&priv->tx_failed_tasklet, ath9k_tx_failed_tasklet, 779 (unsigned long)priv); 780 INIT_DELAYED_WORK(&priv->ani_work, ath9k_htc_ani_work); 781 INIT_WORK(&priv->ps_work, ath9k_ps_work); 782 INIT_WORK(&priv->fatal_work, ath9k_fatal_work); 783 setup_timer(&priv->tx.cleanup_timer, ath9k_htc_tx_cleanup_timer, 784 (unsigned long)priv); 785 786 /* 787 * Cache line size is used to size and align various 788 * structures used to communicate with the hardware. 789 */ 790 ath_read_cachesize(common, &csz); 791 common->cachelsz = csz << 2; /* convert to bytes */ 792 793 ret = ath9k_hw_init(ah); 794 if (ret) { 795 ath_err(common, 796 "Unable to initialize hardware; initialization status: %d\n", 797 ret); 798 goto err_hw; 799 } 800 801 ret = ath9k_init_queues(priv); 802 if (ret) 803 goto err_queues; 804 805 for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++) 806 priv->beacon.bslot[i] = NULL; 807 priv->beacon.slottime = ATH9K_SLOT_TIME_9; 808 809 ath9k_cmn_init_channels_rates(common); 810 ath9k_cmn_init_crypto(ah); 811 ath9k_init_misc(priv); 812 ath9k_htc_init_btcoex(priv, product); 813 814 return 0; 815 816 err_queues: 817 ath9k_hw_deinit(ah); 818 err_hw: 819 820 kfree(ah); 821 priv->ah = NULL; 822 823 return ret; 824 } 825 826 static const struct ieee80211_iface_limit if_limits[] = { 827 { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) | 828 BIT(NL80211_IFTYPE_P2P_CLIENT) }, 829 { .max = 2, .types = BIT(NL80211_IFTYPE_AP) | 830 #ifdef CONFIG_MAC80211_MESH 831 BIT(NL80211_IFTYPE_MESH_POINT) | 832 #endif 833 BIT(NL80211_IFTYPE_P2P_GO) }, 834 }; 835 836 static const struct ieee80211_iface_combination if_comb = { 837 .limits = if_limits, 838 .n_limits = ARRAY_SIZE(if_limits), 839 .max_interfaces = 2, 840 .num_different_channels = 1, 841 }; 842 843 static void ath9k_set_hw_capab(struct ath9k_htc_priv *priv, 844 struct ieee80211_hw *hw) 845 { 846 struct ath_hw *ah = priv->ah; 847 struct ath_common *common = ath9k_hw_common(priv->ah); 848 struct base_eep_header *pBase; 849 850 ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING); 851 ieee80211_hw_set(hw, MFP_CAPABLE); 852 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 853 ieee80211_hw_set(hw, PS_NULLFUNC_STACK); 854 ieee80211_hw_set(hw, RX_INCLUDES_FCS); 855 ieee80211_hw_set(hw, HAS_RATE_CONTROL); 856 ieee80211_hw_set(hw, SPECTRUM_MGMT); 857 ieee80211_hw_set(hw, SIGNAL_DBM); 858 ieee80211_hw_set(hw, AMPDU_AGGREGATION); 859 860 if (ath9k_ps_enable) 861 ieee80211_hw_set(hw, SUPPORTS_PS); 862 863 hw->wiphy->interface_modes = 864 BIT(NL80211_IFTYPE_STATION) | 865 BIT(NL80211_IFTYPE_ADHOC) | 866 BIT(NL80211_IFTYPE_AP) | 867 BIT(NL80211_IFTYPE_P2P_GO) | 868 BIT(NL80211_IFTYPE_P2P_CLIENT) | 869 BIT(NL80211_IFTYPE_MESH_POINT) | 870 BIT(NL80211_IFTYPE_OCB); 871 872 hw->wiphy->iface_combinations = &if_comb; 873 hw->wiphy->n_iface_combinations = 1; 874 875 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 876 877 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN | 878 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | 879 WIPHY_FLAG_HAS_CHANNEL_SWITCH; 880 881 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 882 883 hw->queues = 4; 884 hw->max_listen_interval = 1; 885 886 hw->vif_data_size = sizeof(struct ath9k_htc_vif); 887 hw->sta_data_size = sizeof(struct ath9k_htc_sta); 888 889 /* tx_frame_hdr is larger than tx_mgmt_hdr anyway */ 890 hw->extra_tx_headroom = sizeof(struct tx_frame_hdr) + 891 sizeof(struct htc_frame_hdr) + 4; 892 893 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) 894 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = 895 &common->sbands[IEEE80211_BAND_2GHZ]; 896 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) 897 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = 898 &common->sbands[IEEE80211_BAND_5GHZ]; 899 900 ath9k_cmn_reload_chainmask(ah); 901 902 pBase = ath9k_htc_get_eeprom_base(priv); 903 if (pBase) { 904 hw->wiphy->available_antennas_rx = pBase->rxMask; 905 hw->wiphy->available_antennas_tx = pBase->txMask; 906 } 907 908 SET_IEEE80211_PERM_ADDR(hw, common->macaddr); 909 } 910 911 static int ath9k_init_firmware_version(struct ath9k_htc_priv *priv) 912 { 913 struct ieee80211_hw *hw = priv->hw; 914 struct wmi_fw_version cmd_rsp; 915 int ret; 916 917 memset(&cmd_rsp, 0, sizeof(cmd_rsp)); 918 919 WMI_CMD(WMI_GET_FW_VERSION); 920 if (ret) 921 return -EINVAL; 922 923 priv->fw_version_major = be16_to_cpu(cmd_rsp.major); 924 priv->fw_version_minor = be16_to_cpu(cmd_rsp.minor); 925 926 snprintf(hw->wiphy->fw_version, sizeof(hw->wiphy->fw_version), "%d.%d", 927 priv->fw_version_major, 928 priv->fw_version_minor); 929 930 dev_info(priv->dev, "ath9k_htc: FW Version: %d.%d\n", 931 priv->fw_version_major, 932 priv->fw_version_minor); 933 934 /* 935 * Check if the available FW matches the driver's 936 * required version. 937 */ 938 if (priv->fw_version_major != MAJOR_VERSION_REQ || 939 priv->fw_version_minor < MINOR_VERSION_REQ) { 940 dev_err(priv->dev, "ath9k_htc: Please upgrade to FW version %d.%d\n", 941 MAJOR_VERSION_REQ, MINOR_VERSION_REQ); 942 return -EINVAL; 943 } 944 945 if (priv->fw_version_major == 1 && priv->fw_version_minor < 4) 946 set_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags); 947 948 dev_info(priv->dev, "FW RMW support: %s\n", 949 test_bit(HTC_FWFLAG_NO_RMW, &priv->fw_flags) ? "Off" : "On"); 950 951 return 0; 952 } 953 954 static int ath9k_init_device(struct ath9k_htc_priv *priv, 955 u16 devid, char *product, u32 drv_info) 956 { 957 struct ieee80211_hw *hw = priv->hw; 958 struct ath_common *common; 959 struct ath_hw *ah; 960 int error = 0; 961 struct ath_regulatory *reg; 962 char hw_name[64]; 963 964 /* Bring up device */ 965 error = ath9k_init_priv(priv, devid, product, drv_info); 966 if (error != 0) 967 goto err_init; 968 969 ah = priv->ah; 970 common = ath9k_hw_common(ah); 971 ath9k_set_hw_capab(priv, hw); 972 973 error = ath9k_init_firmware_version(priv); 974 if (error != 0) 975 goto err_fw; 976 977 /* Initialize regulatory */ 978 error = ath_regd_init(&common->regulatory, priv->hw->wiphy, 979 ath9k_reg_notifier); 980 if (error) 981 goto err_regd; 982 983 reg = &common->regulatory; 984 985 /* Setup TX */ 986 error = ath9k_tx_init(priv); 987 if (error != 0) 988 goto err_tx; 989 990 /* Setup RX */ 991 error = ath9k_rx_init(priv); 992 if (error != 0) 993 goto err_rx; 994 995 ath9k_hw_disable(priv->ah); 996 #ifdef CONFIG_MAC80211_LEDS 997 /* must be initialized before ieee80211_register_hw */ 998 priv->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(priv->hw, 999 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_htc_tpt_blink, 1000 ARRAY_SIZE(ath9k_htc_tpt_blink)); 1001 #endif 1002 1003 /* Register with mac80211 */ 1004 error = ieee80211_register_hw(hw); 1005 if (error) 1006 goto err_register; 1007 1008 /* Handle world regulatory */ 1009 if (!ath_is_world_regd(reg)) { 1010 error = regulatory_hint(hw->wiphy, reg->alpha2); 1011 if (error) 1012 goto err_world; 1013 } 1014 1015 error = ath9k_htc_init_debug(priv->ah); 1016 if (error) { 1017 ath_err(common, "Unable to create debugfs files\n"); 1018 goto err_world; 1019 } 1020 1021 ath_dbg(common, CONFIG, 1022 "WMI:%d, BCN:%d, CAB:%d, UAPSD:%d, MGMT:%d, BE:%d, BK:%d, VI:%d, VO:%d\n", 1023 priv->wmi_cmd_ep, 1024 priv->beacon_ep, 1025 priv->cab_ep, 1026 priv->uapsd_ep, 1027 priv->mgmt_ep, 1028 priv->data_be_ep, 1029 priv->data_bk_ep, 1030 priv->data_vi_ep, 1031 priv->data_vo_ep); 1032 1033 ath9k_hw_name(priv->ah, hw_name, sizeof(hw_name)); 1034 wiphy_info(hw->wiphy, "%s\n", hw_name); 1035 1036 ath9k_init_leds(priv); 1037 ath9k_start_rfkill_poll(priv); 1038 1039 return 0; 1040 1041 err_world: 1042 ieee80211_unregister_hw(hw); 1043 err_register: 1044 ath9k_rx_cleanup(priv); 1045 err_rx: 1046 ath9k_tx_cleanup(priv); 1047 err_tx: 1048 /* Nothing */ 1049 err_regd: 1050 /* Nothing */ 1051 err_fw: 1052 ath9k_deinit_priv(priv); 1053 err_init: 1054 return error; 1055 } 1056 1057 int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev, 1058 u16 devid, char *product, u32 drv_info) 1059 { 1060 struct ieee80211_hw *hw; 1061 struct ath9k_htc_priv *priv; 1062 int ret; 1063 1064 hw = ieee80211_alloc_hw(sizeof(struct ath9k_htc_priv), &ath9k_htc_ops); 1065 if (!hw) 1066 return -ENOMEM; 1067 1068 priv = hw->priv; 1069 priv->hw = hw; 1070 priv->htc = htc_handle; 1071 priv->dev = dev; 1072 htc_handle->drv_priv = priv; 1073 SET_IEEE80211_DEV(hw, priv->dev); 1074 1075 ret = ath9k_htc_wait_for_target(priv); 1076 if (ret) 1077 goto err_free; 1078 1079 priv->wmi = ath9k_init_wmi(priv); 1080 if (!priv->wmi) { 1081 ret = -EINVAL; 1082 goto err_free; 1083 } 1084 1085 ret = ath9k_init_htc_services(priv, devid, drv_info); 1086 if (ret) 1087 goto err_init; 1088 1089 ret = ath9k_init_device(priv, devid, product, drv_info); 1090 if (ret) 1091 goto err_init; 1092 1093 return 0; 1094 1095 err_init: 1096 ath9k_deinit_wmi(priv); 1097 err_free: 1098 ieee80211_free_hw(hw); 1099 return ret; 1100 } 1101 1102 void ath9k_htc_disconnect_device(struct htc_target *htc_handle, bool hotunplug) 1103 { 1104 if (htc_handle->drv_priv) { 1105 1106 /* Check if the device has been yanked out. */ 1107 if (hotunplug) 1108 htc_handle->drv_priv->ah->ah_flags |= AH_UNPLUGGED; 1109 1110 ath9k_deinit_device(htc_handle->drv_priv); 1111 ath9k_deinit_wmi(htc_handle->drv_priv); 1112 ieee80211_free_hw(htc_handle->drv_priv->hw); 1113 } 1114 } 1115 1116 #ifdef CONFIG_PM 1117 1118 void ath9k_htc_suspend(struct htc_target *htc_handle) 1119 { 1120 ath9k_htc_setpower(htc_handle->drv_priv, ATH9K_PM_FULL_SLEEP); 1121 } 1122 1123 int ath9k_htc_resume(struct htc_target *htc_handle) 1124 { 1125 struct ath9k_htc_priv *priv = htc_handle->drv_priv; 1126 int ret; 1127 1128 ret = ath9k_htc_wait_for_target(priv); 1129 if (ret) 1130 return ret; 1131 1132 ret = ath9k_init_htc_services(priv, priv->ah->hw_version.devid, 1133 priv->ah->hw_version.usbdev); 1134 ath9k_configure_leds(priv); 1135 1136 return ret; 1137 } 1138 #endif 1139 1140 static int __init ath9k_htc_init(void) 1141 { 1142 if (ath9k_hif_usb_init() < 0) { 1143 pr_err("No USB devices found, driver not installed\n"); 1144 return -ENODEV; 1145 } 1146 1147 return 0; 1148 } 1149 module_init(ath9k_htc_init); 1150 1151 static void __exit ath9k_htc_exit(void) 1152 { 1153 ath9k_hif_usb_exit(); 1154 pr_info("Driver unloaded\n"); 1155 } 1156 module_exit(ath9k_htc_exit); 1157 1158 #line 126 "/work/ldvuser/andrianov/work/current--X--drivers/net/wireless/ath/ath9k/--X--defaultlinux-4.5-rc7--X--races--X--cpachecker/linux-4.5-rc7/csd_deg_dscv/74/dscv_tempdir/dscv/ri/races/drivers/net/wireless/ath/ath9k/htc_drv_init.o.c.prepared" 1159 1160 int ldv_probe_10(void); 1161 void ldv_initialize(void); 1162 void ldv_check_final_state(void); 1163 int ldv_retval_8; 1164 int ldv_release_10(void); 1165 1166 1167 void activate_pending_timer_1(struct timer_list * timer, unsigned long data, int pending_flag){ 1168 if(ldv_timer_list_1_0 == timer){ 1169 if(ldv_timer_1_0 == 2 || pending_flag){ 1170 ldv_timer_list_1_0 = timer; 1171 ldv_timer_list_1_0->data = data; 1172 ldv_timer_1_0 = 1; 1173 } 1174 return; 1175 } 1176 1177 if(ldv_timer_list_1_1 == timer){ 1178 if(ldv_timer_1_1 == 2 || pending_flag){ 1179 ldv_timer_list_1_1 = timer; 1180 ldv_timer_list_1_1->data = data; 1181 ldv_timer_1_1 = 1; 1182 } 1183 return; 1184 } 1185 1186 if(ldv_timer_list_1_2 == timer){ 1187 if(ldv_timer_1_2 == 2 || pending_flag){ 1188 ldv_timer_list_1_2 = timer; 1189 ldv_timer_list_1_2->data = data; 1190 ldv_timer_1_2= 1; 1191 } 1192 return; 1193 } 1194 1195 if(ldv_timer_list_1_3 == timer){ 1196 if(ldv_timer_1_3 == 2 || pending_flag){ 1197 ldv_timer_list_1_3 = timer; 1198 ldv_timer_list_1_3->data = data; 1199 ldv_timer_1_3 = 1; 1200 } 1201 return; 1202 } 1203 activate_suitable_timer_1(timer, data); 1204 } 1205 1206 1207 void ldv_initialyze_ath_bus_ops_10(void){ 1208 ath9k_usb_bus_ops_group0 = ldv_undef_ptr(); 1209 } 1210 1211 void timer_init_1(void){ 1212 ldv_timer_1_0 = 0; 1213 ldv_timer_1_1 = 0; 1214 ldv_timer_1_2 = 0; 1215 ldv_timer_1_3 = 0; 1216 } 1217 1218 1219 int reg_timer_1(struct timer_list * timer, void (*function)(unsigned long), unsigned long data){ 1220 if(function == ath9k_htc_tx_cleanup_timer){ 1221 activate_suitable_timer_1(timer, data); 1222 } 1223 } 1224 1225 1226 void ldv_initialyze_ath_ps_ops_11(void){ 1227 ath9k_htc_ps_ops_group0 = ldv_undef_ptr(); 1228 } 1229 1230 void disable_suitable_timer_1(struct timer_list * timer){ 1231 if(ldv_timer_1_0 != 0 && timer == ldv_timer_list_1_0){ 1232 ldv_timer_1_0 = 0; 1233 return; 1234 } 1235 if(ldv_timer_1_1 != 0 && timer == ldv_timer_list_1_1){ 1236 ldv_timer_1_1 = 0; 1237 return; 1238 } 1239 if(ldv_timer_1_2 != 0 && timer == ldv_timer_list_1_2){ 1240 ldv_timer_1_2 = 0; 1241 return; 1242 } 1243 if(ldv_timer_1_3 != 0 && timer == ldv_timer_list_1_3){ 1244 ldv_timer_1_3 = 0; 1245 return; 1246 } 1247 return; 1248 } 1249 1250 1251 void activate_suitable_timer_1(struct timer_list * timer, unsigned long data){ 1252 if(ldv_timer_1_0 == 0 || ldv_timer_1_0 == 2){ 1253 ldv_timer_list_1_0 = timer; 1254 ldv_timer_list_1_0->data = data; 1255 ldv_timer_1_0 = 1; 1256 return; 1257 } 1258 if(ldv_timer_1_1 == 0 || ldv_timer_1_1 == 2){ 1259 ldv_timer_list_1_1 = timer; 1260 ldv_timer_list_1_1->data = data; 1261 ldv_timer_1_1 = 1; 1262 return; 1263 } 1264 if(ldv_timer_1_2 == 0 || ldv_timer_1_2 == 2){ 1265 ldv_timer_list_1_2 = timer; 1266 ldv_timer_list_1_2->data = data; 1267 ldv_timer_1_2 = 1; 1268 return; 1269 } 1270 if(ldv_timer_1_3 == 0 || ldv_timer_1_3 == 2){ 1271 ldv_timer_list_1_3 = timer; 1272 ldv_timer_list_1_3->data = data; 1273 ldv_timer_1_3 = 1; 1274 return; 1275 } 1276 return; 1277 } 1278 1279 1280 int evil_hack_fs_lock(void){ 1281 mutex_lock(&fs_mutex); 1282 return 1; 1283 } 1284 1285 int __VERIFIER_nondet_int(void); 1286 1287 void choose_timer_1(void){ 1288 switch(__VERIFIER_nondet_int()){ 1289 case 0: { 1290 if(ldv_timer_1_0 == 1){ 1291 ldv_timer_1_0 = 2; 1292 ldv_timer_1(ldv_timer_1_0, ldv_timer_list_1_0); 1293 } 1294 } 1295 break; 1296 case 1: { 1297 if(ldv_timer_1_1 == 1){ 1298 ldv_timer_1_1 = 2; 1299 ldv_timer_1(ldv_timer_1_1, ldv_timer_list_1_1); 1300 } 1301 } 1302 break; 1303 case 2: { 1304 if(ldv_timer_1_2 == 1){ 1305 ldv_timer_1_2 = 2; 1306 ldv_timer_1(ldv_timer_1_2, ldv_timer_list_1_2); 1307 } 1308 } 1309 break; 1310 case 3: { 1311 if(ldv_timer_1_3 == 1){ 1312 ldv_timer_1_3 = 2; 1313 ldv_timer_1(ldv_timer_1_3, ldv_timer_list_1_3); 1314 } 1315 } 1316 break; 1317 default: ldv_assume(0); 1318 } 1319 return; 1320 } 1321 1322 1323 void ldv_timer_1(int state, struct timer_list * timer){ 1324 LDV_IN_INTERRUPT=2; 1325 (ath9k_htc_tx_cleanup_timer)(timer->data); 1326 LDV_IN_INTERRUPT=1; 1327 } 1328 1329 1330 int evil_hack_ar_lock(void){ 1331 mutex_lock(&ar_mutex); 1332 return 1; 1333 } 1334 1335 1336 /* DEG-ENVIRONMENT-BEGIN */ 1337 extern void ldv_main_exported_12(void); 1338 extern void ldv_main_exported_11(void); 1339 extern void ldv_main_exported_0(void); 1340 extern void ldv_main_exported_10(void); 1341 extern void ldv_main_exported_13(void); 1342 extern void ldv_main_exported_14(void); 1343 extern void ldv_main_exported_6(void); 1344 extern void ldv_main_exported_3(void); 1345 extern void ldv_main_exported_7(void); 1346 extern void ldv_main_exported_9(void); 1347 extern void ldv_main_exported_2(void); 1348 extern void ldv_main_exported_8(void); 1349 extern void ldv_main_exported_4(void); 1350 extern void ldv_main_exported_5(void); 1351 1352 //********************* LDV MAIN ********************* 1353 //main 1354 void entry_point(void){ 1355 ldv_initialize(); 1356 //args for callbacks 1357 u32 ldvarg104; 1358 int *ldvarg105; 1359 u16 *ldvarg103; 1360 //initialization of machine states 1361 ldv_state_variable_6=0; 1362 ldv_state_variable_11=0; 1363 ldv_state_variable_3=0; 1364 ldv_state_variable_7=0; 1365 ldv_state_variable_9=0; 1366 ldv_state_variable_12=0; 1367 ldv_state_variable_2=0; 1368 ldv_state_variable_14=0; 1369 ldv_state_variable_8=0; 1370 1371 timer_init_1(); 1372 1373 ldv_state_variable_1=1; 1374 ldv_state_variable_4=0; 1375 ref_cnt=0; 1376 ldv_state_variable_0=1; 1377 ldv_state_variable_13=0; 1378 ldv_state_variable_10=0; 1379 ldv_state_variable_5=0; 1380 while(1){ 1381 switch(__VERIFIER_nondet_int()){ 1382 case 0:{ 1383 /*DEG-struct: handlers from structure fops_xmit*/ 1384 /*DEG-CHECK: checking registration of fops_xmit structure*/ 1385 if(ldv_state_variable_6 != 0){ 1386 ldv_main_exported_6(); 1387 } 1388 } 1389 break; 1390 case 1:{ 1391 /*DEG-struct: handlers from structure ath9k_htc_ps_ops*/ 1392 /*DEG-CHECK: checking registration of ath9k_htc_ps_ops structure*/ 1393 if(ldv_state_variable_11 != 0){ 1394 switch(__VERIFIER_nondet_int()){ 1395 case 0:{ 1396 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1397 if(ldv_state_variable_11 == 1){ 1398 /*DEG-CALL: handler restore from ath9k_htc_ps_ops*/ 1399 (& ath9k_htc_op_ps_restore)(ath9k_htc_ps_ops_group0); 1400 /*DEG-postcall: default*/ 1401 ldv_state_variable_11 = 1; 1402 } 1403 } 1404 break; 1405 case 1:{ 1406 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1407 if(ldv_state_variable_11 == 1){ 1408 /*DEG-CALL: handler wakeup from ath9k_htc_ps_ops*/ 1409 (& ath9k_htc_op_ps_wakeup)(ath9k_htc_ps_ops_group0); 1410 /*DEG-postcall: default*/ 1411 ldv_state_variable_11 = 1; 1412 } 1413 } 1414 break; 1415 default: ldv_assume(0); 1416 } 1417 } 1418 } 1419 break; 1420 case 2:{ 1421 /*DEG-struct: handlers from structure fops_queue*/ 1422 /*DEG-CHECK: checking registration of fops_queue structure*/ 1423 if(ldv_state_variable_3 != 0){ 1424 ldv_main_exported_3(); 1425 } 1426 } 1427 break; 1428 case 3:{ 1429 /*DEG-struct: handlers from structure fops_tgt_rx_stats*/ 1430 /*DEG-CHECK: checking registration of fops_tgt_rx_stats structure*/ 1431 if(ldv_state_variable_7 != 0){ 1432 ldv_main_exported_7(); 1433 } 1434 } 1435 break; 1436 case 4:{ 1437 /*DEG-struct: handlers from structure fops_tgt_int_stats*/ 1438 /*DEG-CHECK: checking registration of fops_tgt_int_stats structure*/ 1439 if(ldv_state_variable_9 != 0){ 1440 ldv_main_exported_9(); 1441 } 1442 } 1443 break; 1444 case 5:{ 1445 /*DEG-struct: handlers from structure ath9k_htc_ops*/ 1446 /*DEG-CHECK: checking registration of ath9k_htc_ops structure*/ 1447 if(ldv_state_variable_12 != 0){ 1448 ldv_main_exported_12(); 1449 } 1450 } 1451 break; 1452 case 6:{ 1453 /*DEG-struct: handlers from structure fops_debug*/ 1454 /*DEG-CHECK: checking registration of fops_debug structure*/ 1455 if(ldv_state_variable_2 != 0){ 1456 ldv_main_exported_2(); 1457 } 1458 } 1459 break; 1460 case 7:{ 1461 /*DEG-struct: handlers from structure hif_usb*/ 1462 /*DEG-CHECK: checking registration of hif_usb structure*/ 1463 if(ldv_state_variable_14 != 0){ 1464 ldv_main_exported_14(); 1465 } 1466 } 1467 break; 1468 case 8:{ 1469 /*DEG-struct: handlers from structure fops_tgt_tx_stats*/ 1470 /*DEG-CHECK: checking registration of fops_tgt_tx_stats structure*/ 1471 if(ldv_state_variable_8 != 0){ 1472 ldv_main_exported_8(); 1473 } 1474 } 1475 break; 1476 case 9:{ 1477 /*DEG-struct: handlers from structure ldv_setup_timer_0*/ 1478 /*DEG-CHECK: checking registration of ldv_setup_timer_0 structure*/ 1479 if(ldv_state_variable_1 != 0){ 1480 choose_timer_1(); 1481 } 1482 } 1483 break; 1484 case 10:{ 1485 /*DEG-struct: handlers from structure fops_slot*/ 1486 /*DEG-CHECK: checking registration of fops_slot structure*/ 1487 if(ldv_state_variable_4 != 0){ 1488 ldv_main_exported_4(); 1489 } 1490 } 1491 break; 1492 case 11:{ 1493 /*DEG-struct: handlers from structure module*/ 1494 /*DEG-CHECK: checking registration of module structure*/ 1495 if(ldv_state_variable_0 != 0){ 1496 switch(__VERIFIER_nondet_int()){ 1497 case 0:{ 1498 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1499 if(ldv_state_variable_0 == 2 && ref_cnt==0){ 1500 /*DEG-CALL: handler module_exit from module*/ 1501 ath9k_htc_exit(); 1502 ldv_state_variable_0 = 3; 1503 goto ldv_final; 1504 } 1505 } 1506 break; 1507 case 1:{ 1508 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1509 if(ldv_state_variable_0 == 1){ 1510 /*DEG-CALL: handler module_init from module*/ 1511 ldv_retval_8=ath9k_htc_init(); 1512 if(ldv_retval_8!=0){ 1513 ldv_state_variable_0 = 3; 1514 goto ldv_final; 1515 } 1516 /*DEG-postcall: if success*/ 1517 if(ldv_retval_8==0){ 1518 ldv_state_variable_0 = 2; 1519 ldv_state_variable_5 = 1; 1520 ldv_file_operations_5(); 1521 ldv_state_variable_10 = 1; 1522 ldv_initialyze_ath_bus_ops_10(); 1523 ldv_state_variable_4 = 1; 1524 ldv_file_operations_4(); 1525 ldv_state_variable_8 = 1; 1526 ldv_file_operations_8(); 1527 ldv_state_variable_14 = 1; 1528 ldv_state_variable_2 = 1; 1529 ldv_file_operations_2(); 1530 ldv_state_variable_9 = 1; 1531 ldv_file_operations_9(); 1532 ldv_state_variable_7 = 1; 1533 ldv_file_operations_7(); 1534 ldv_state_variable_3 = 1; 1535 ldv_file_operations_3(); 1536 ldv_state_variable_11 = 1; 1537 ldv_initialyze_ath_ps_ops_11(); 1538 ldv_state_variable_6 = 1; 1539 ldv_file_operations_6(); 1540 } 1541 } 1542 } 1543 break; 1544 default: ldv_assume(0); 1545 } 1546 } 1547 } 1548 break; 1549 case 12:{ 1550 /*DEG-struct: handlers from structure ath9k_hif_usb_driver*/ 1551 /*DEG-CHECK: checking registration of ath9k_hif_usb_driver structure*/ 1552 if(ldv_state_variable_13 != 0){ 1553 ldv_main_exported_13(); 1554 } 1555 } 1556 break; 1557 case 13:{ 1558 /*DEG-struct: handlers from structure ath9k_usb_bus_ops*/ 1559 /*DEG-CHECK: checking registration of ath9k_usb_bus_ops structure*/ 1560 if(ldv_state_variable_10 != 0){ 1561 switch(__VERIFIER_nondet_int()){ 1562 case 0:{ 1563 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1564 if(ldv_state_variable_10 == 2){ 1565 /*DEG-CALL: handler read_cachesize from ath9k_usb_bus_ops*/ 1566 (& ath_usb_read_cachesize)(ath9k_usb_bus_ops_group0,ldvarg105); 1567 /*DEG-postcall: default*/ 1568 ldv_state_variable_10 = 2; 1569 } 1570 } 1571 break; 1572 case 1:{ 1573 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1574 if(ldv_state_variable_10 == 1){ 1575 /*DEG-CALL: handler eeprom_read from ath9k_usb_bus_ops*/ 1576 (& ath_usb_eeprom_read)(ath9k_usb_bus_ops_group0,ldvarg104,ldvarg103); 1577 /*DEG-postcall: default*/ 1578 ldv_state_variable_10 = 1; 1579 } 1580 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1581 if(ldv_state_variable_10 == 2){ 1582 /*DEG-CALL: handler eeprom_read from ath9k_usb_bus_ops*/ 1583 (& ath_usb_eeprom_read)(ath9k_usb_bus_ops_group0,ldvarg104,ldvarg103); 1584 /*DEG-postcall: default*/ 1585 ldv_state_variable_10 = 2; 1586 } 1587 } 1588 break; 1589 case 2:{ 1590 /*DEG-state: state 2 (look at corresponding state-chart diagram for details)*/ 1591 if(ldv_state_variable_10 == 2){ 1592 /*DEG-CALL: handler release from ath9k_usb_bus_ops*/ 1593 ldv_release_10(); 1594 /*DEG-postcall: module put*/ 1595 ldv_state_variable_10 = 1; 1596 ref_cnt--; 1597 } 1598 } 1599 break; 1600 case 3:{ 1601 /*DEG-state: state 1 (look at corresponding state-chart diagram for details)*/ 1602 if(ldv_state_variable_10 == 1){ 1603 /*DEG-CALL: handler probe from ath9k_usb_bus_ops*/ 1604 ldv_probe_10(); 1605 /*DEG-postcall: get module*/ 1606 ldv_state_variable_10 = 2; 1607 ref_cnt++; 1608 } 1609 } 1610 break; 1611 default: ldv_assume(0); 1612 } 1613 } 1614 } 1615 break; 1616 case 14:{ 1617 /*DEG-struct: handlers from structure fops_skb_rx*/ 1618 /*DEG-CHECK: checking registration of fops_skb_rx structure*/ 1619 if(ldv_state_variable_5 != 0){ 1620 ldv_main_exported_5(); 1621 } 1622 } 1623 break; 1624 default: ldv_assume(0); 1625 } 1626 } 1627 ldv_final: 1628 ldv_check_final_state(); 1629 return; 1630 } 1631 /* DEG-ENVIRONMENT-END */
1 /* 2 * Copyright (c) 2010-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include "htc.h" 18 19 /*************/ 20 /* Utilities */ 21 /*************/ 22 23 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */ 24 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv, 25 struct ath9k_channel *ichan) 26 { 27 if (IS_CHAN_5GHZ(ichan)) 28 return HTC_MODE_11NA; 29 30 return HTC_MODE_11NG; 31 } 32 33 bool ath9k_htc_setpower(struct ath9k_htc_priv *priv, 34 enum ath9k_power_mode mode) 35 { 36 bool ret; 37 38 mutex_lock(&priv->htc_pm_lock); 39 ret = ath9k_hw_setpower(priv->ah, mode); 40 mutex_unlock(&priv->htc_pm_lock); 41 42 return ret; 43 } 44 45 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv) 46 { 47 mutex_lock(&priv->htc_pm_lock); 48 if (++priv->ps_usecount != 1) 49 goto unlock; 50 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE); 51 52 unlock: 53 mutex_unlock(&priv->htc_pm_lock); 54 } 55 56 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv) 57 { 58 bool reset; 59 60 mutex_lock(&priv->htc_pm_lock); 61 if (--priv->ps_usecount != 0) 62 goto unlock; 63 64 if (priv->ps_idle) { 65 ath9k_hw_setrxabort(priv->ah, true); 66 ath9k_hw_stopdmarecv(priv->ah, &reset); 67 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP); 68 } else if (priv->ps_enabled) { 69 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP); 70 } 71 72 unlock: 73 mutex_unlock(&priv->htc_pm_lock); 74 } 75 76 void ath9k_ps_work(struct work_struct *work) 77 { 78 struct ath9k_htc_priv *priv = 79 container_of(work, struct ath9k_htc_priv, 80 ps_work); 81 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE); 82 83 /* The chip wakes up after receiving the first beacon 84 while network sleep is enabled. For the driver to 85 be in sync with the hw, set the chip to awake and 86 only then set it to sleep. 87 */ 88 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP); 89 } 90 91 static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) 92 { 93 struct ath9k_htc_priv *priv = data; 94 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 95 96 if ((vif->type == NL80211_IFTYPE_AP || 97 vif->type == NL80211_IFTYPE_MESH_POINT) && 98 bss_conf->enable_beacon) { 99 priv->reconfig_beacon = true; 100 priv->rearm_ani = true; 101 } 102 103 if (bss_conf->assoc) { 104 priv->rearm_ani = true; 105 priv->reconfig_beacon = true; 106 } 107 } 108 109 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv) 110 { 111 priv->rearm_ani = false; 112 priv->reconfig_beacon = false; 113 114 ieee80211_iterate_active_interfaces_atomic( 115 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL, 116 ath9k_htc_vif_iter, priv); 117 if (priv->rearm_ani) 118 ath9k_htc_start_ani(priv); 119 120 if (priv->reconfig_beacon) { 121 ath9k_htc_ps_wakeup(priv); 122 ath9k_htc_beacon_reconfig(priv); 123 ath9k_htc_ps_restore(priv); 124 } 125 } 126 127 static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif) 128 { 129 struct ath9k_vif_iter_data *iter_data = data; 130 int i; 131 132 if (iter_data->hw_macaddr != NULL) { 133 for (i = 0; i < ETH_ALEN; i++) 134 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]); 135 } else { 136 iter_data->hw_macaddr = mac; 137 } 138 } 139 140 static void ath9k_htc_set_mac_bssid_mask(struct ath9k_htc_priv *priv, 141 struct ieee80211_vif *vif) 142 { 143 struct ath_common *common = ath9k_hw_common(priv->ah); 144 struct ath9k_vif_iter_data iter_data; 145 146 /* 147 * Pick the MAC address of the first interface as the new hardware 148 * MAC address. The hardware will use it together with the BSSID mask 149 * when matching addresses. 150 */ 151 iter_data.hw_macaddr = NULL; 152 eth_broadcast_addr(iter_data.mask); 153 154 if (vif) 155 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif); 156 157 /* Get list of all active MAC addresses */ 158 ieee80211_iterate_active_interfaces_atomic( 159 priv->hw, IEEE80211_IFACE_ITER_RESUME_ALL, 160 ath9k_htc_bssid_iter, &iter_data); 161 162 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); 163 164 if (iter_data.hw_macaddr) 165 memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN); 166 167 ath_hw_setbssidmask(common); 168 } 169 170 static void ath9k_htc_set_opmode(struct ath9k_htc_priv *priv) 171 { 172 if (priv->num_ibss_vif) 173 priv->ah->opmode = NL80211_IFTYPE_ADHOC; 174 else if (priv->num_ap_vif) 175 priv->ah->opmode = NL80211_IFTYPE_AP; 176 else if (priv->num_mbss_vif) 177 priv->ah->opmode = NL80211_IFTYPE_MESH_POINT; 178 else 179 priv->ah->opmode = NL80211_IFTYPE_STATION; 180 181 ath9k_hw_setopmode(priv->ah); 182 } 183 184 void ath9k_htc_reset(struct ath9k_htc_priv *priv) 185 { 186 struct ath_hw *ah = priv->ah; 187 struct ath_common *common = ath9k_hw_common(ah); 188 struct ieee80211_channel *channel = priv->hw->conf.chandef.chan; 189 struct ath9k_hw_cal_data *caldata = NULL; 190 enum htc_phymode mode; 191 __be16 htc_mode; 192 u8 cmd_rsp; 193 int ret; 194 195 mutex_lock(&priv->mutex); 196 ath9k_htc_ps_wakeup(priv); 197 198 ath9k_htc_stop_ani(priv); 199 ieee80211_stop_queues(priv->hw); 200 201 del_timer_sync(&priv->tx.cleanup_timer); 202 ath9k_htc_tx_drain(priv); 203 204 WMI_CMD(WMI_DISABLE_INTR_CMDID); 205 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); 206 WMI_CMD(WMI_STOP_RECV_CMDID); 207 208 ath9k_wmi_event_drain(priv); 209 210 caldata = &priv->caldata; 211 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false); 212 if (ret) { 213 ath_err(common, 214 "Unable to reset device (%u Mhz) reset status %d\n", 215 channel->center_freq, ret); 216 } 217 218 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, 219 &priv->curtxpow); 220 221 WMI_CMD(WMI_START_RECV_CMDID); 222 ath9k_host_rx_init(priv); 223 224 mode = ath9k_htc_get_curmode(priv, ah->curchan); 225 htc_mode = cpu_to_be16(mode); 226 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); 227 228 WMI_CMD(WMI_ENABLE_INTR_CMDID); 229 htc_start(priv->htc); 230 ath9k_htc_vif_reconfig(priv); 231 ieee80211_wake_queues(priv->hw); 232 233 mod_timer(&priv->tx.cleanup_timer, 234 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); 235 236 ath9k_htc_ps_restore(priv); 237 mutex_unlock(&priv->mutex); 238 } 239 240 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv, 241 struct ieee80211_hw *hw, 242 struct ath9k_channel *hchan) 243 { 244 struct ath_hw *ah = priv->ah; 245 struct ath_common *common = ath9k_hw_common(ah); 246 struct ieee80211_conf *conf = &common->hw->conf; 247 bool fastcc; 248 struct ieee80211_channel *channel = hw->conf.chandef.chan; 249 struct ath9k_hw_cal_data *caldata = NULL; 250 enum htc_phymode mode; 251 __be16 htc_mode; 252 u8 cmd_rsp; 253 int ret; 254 255 if (test_bit(ATH_OP_INVALID, &common->op_flags)) 256 return -EIO; 257 258 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL); 259 260 ath9k_htc_ps_wakeup(priv); 261 262 ath9k_htc_stop_ani(priv); 263 del_timer_sync(&priv->tx.cleanup_timer); 264 ath9k_htc_tx_drain(priv); 265 266 WMI_CMD(WMI_DISABLE_INTR_CMDID); 267 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID); 268 WMI_CMD(WMI_STOP_RECV_CMDID); 269 270 ath9k_wmi_event_drain(priv); 271 272 ath_dbg(common, CONFIG, 273 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n", 274 priv->ah->curchan->channel, 275 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf), 276 fastcc); 277 278 if (!fastcc) 279 caldata = &priv->caldata; 280 281 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc); 282 if (ret) { 283 ath_err(common, 284 "Unable to reset channel (%u Mhz) reset status %d\n", 285 channel->center_freq, ret); 286 goto err; 287 } 288 289 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit, 290 &priv->curtxpow); 291 292 WMI_CMD(WMI_START_RECV_CMDID); 293 if (ret) 294 goto err; 295 296 ath9k_host_rx_init(priv); 297 298 mode = ath9k_htc_get_curmode(priv, hchan); 299 htc_mode = cpu_to_be16(mode); 300 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode); 301 if (ret) 302 goto err; 303 304 WMI_CMD(WMI_ENABLE_INTR_CMDID); 305 if (ret) 306 goto err; 307 308 htc_start(priv->htc); 309 310 if (!test_bit(ATH_OP_SCANNING, &common->op_flags) && 311 !(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) 312 ath9k_htc_vif_reconfig(priv); 313 314 mod_timer(&priv->tx.cleanup_timer, 315 jiffies + msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL)); 316 317 /* perform spectral scan if requested. */ 318 if (test_bit(ATH_OP_SCANNING, &common->op_flags) && 319 priv->spec_priv.spectral_mode == SPECTRAL_CHANSCAN) 320 ath9k_cmn_spectral_scan_trigger(common, &priv->spec_priv); 321 err: 322 ath9k_htc_ps_restore(priv); 323 return ret; 324 } 325 326 /* 327 * Monitor mode handling is a tad complicated because the firmware requires 328 * an interface to be created exclusively, while mac80211 doesn't associate 329 * an interface with the mode. 330 * 331 * So, for now, only one monitor interface can be configured. 332 */ 333 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) 334 { 335 struct ath_common *common = ath9k_hw_common(priv->ah); 336 struct ath9k_htc_target_vif hvif; 337 int ret = 0; 338 u8 cmd_rsp; 339 340 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); 341 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); 342 hvif.index = priv->mon_vif_idx; 343 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif); 344 if (ret) { 345 ath_err(common, "Unable to remove monitor interface at idx: %d\n", 346 priv->mon_vif_idx); 347 } 348 349 priv->nvifs--; 350 priv->vif_slot &= ~(1 << priv->mon_vif_idx); 351 } 352 353 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv) 354 { 355 struct ath_common *common = ath9k_hw_common(priv->ah); 356 struct ath9k_htc_target_vif hvif; 357 struct ath9k_htc_target_sta tsta; 358 int ret = 0, sta_idx; 359 u8 cmd_rsp; 360 361 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) || 362 (priv->nstations >= ATH9K_HTC_MAX_STA)) { 363 ret = -ENOBUFS; 364 goto err_vif; 365 } 366 367 sta_idx = ffz(priv->sta_slot); 368 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) { 369 ret = -ENOBUFS; 370 goto err_vif; 371 } 372 373 /* 374 * Add an interface. 375 */ 376 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif)); 377 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN); 378 379 hvif.opmode = HTC_M_MONITOR; 380 hvif.index = ffz(priv->vif_slot); 381 382 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif); 383 if (ret) 384 goto err_vif; 385 386 /* 387 * Assign the monitor interface index as a special case here. 388 * This is needed when the interface is brought down. 389 */ 390 priv->mon_vif_idx = hvif.index; 391 priv->vif_slot |= (1 << hvif.index); 392 393 /* 394 * Set the hardware mode to monitor only if there are no 395 * other interfaces. 396 */ 397 if (!priv->nvifs) 398 priv->ah->opmode = NL80211_IFTYPE_MONITOR; 399 400 priv->nvifs++; 401 402 /* 403 * Associate a station with the interface for packet injection. 404 */ 405 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); 406 407 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN); 408 409 tsta.is_vif_sta = 1; 410 tsta.sta_index = sta_idx; 411 tsta.vif_index = hvif.index; 412 tsta.maxampdu = cpu_to_be16(0xffff); 413 414 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); 415 if (ret) { 416 ath_err(common, "Unable to add station entry for monitor mode\n"); 417 goto err_sta; 418 } 419 420 priv->sta_slot |= (1 << sta_idx); 421 priv->nstations++; 422 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx; 423 priv->ah->is_monitoring = true; 424 425 ath_dbg(common, CONFIG, 426 "Attached a monitor interface at idx: %d, sta idx: %d\n", 427 priv->mon_vif_idx, sta_idx); 428 429 return 0; 430 431 err_sta: 432 /* 433 * Remove the interface from the target. 434 */ 435 __ath9k_htc_remove_monitor_interface(priv); 436 err_vif: 437 ath_dbg(common, FATAL, "Unable to attach a monitor interface\n"); 438 439 return ret; 440 } 441 442 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv) 443 { 444 struct ath_common *common = ath9k_hw_common(priv->ah); 445 int ret = 0; 446 u8 cmd_rsp, sta_idx; 447 448 __ath9k_htc_remove_monitor_interface(priv); 449 450 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx]; 451 452 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); 453 if (ret) { 454 ath_err(common, "Unable to remove station entry for monitor mode\n"); 455 return ret; 456 } 457 458 priv->sta_slot &= ~(1 << sta_idx); 459 priv->nstations--; 460 priv->ah->is_monitoring = false; 461 462 ath_dbg(common, CONFIG, 463 "Removed a monitor interface at idx: %d, sta idx: %d\n", 464 priv->mon_vif_idx, sta_idx); 465 466 return 0; 467 } 468 469 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv, 470 struct ieee80211_vif *vif, 471 struct ieee80211_sta *sta) 472 { 473 struct ath_common *common = ath9k_hw_common(priv->ah); 474 struct ath9k_htc_target_sta tsta; 475 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; 476 struct ath9k_htc_sta *ista; 477 int ret, sta_idx; 478 u8 cmd_rsp; 479 u16 maxampdu; 480 481 if (priv->nstations >= ATH9K_HTC_MAX_STA) 482 return -ENOBUFS; 483 484 sta_idx = ffz(priv->sta_slot); 485 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) 486 return -ENOBUFS; 487 488 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta)); 489 490 if (sta) { 491 ista = (struct ath9k_htc_sta *) sta->drv_priv; 492 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN); 493 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN); 494 ista->index = sta_idx; 495 tsta.is_vif_sta = 0; 496 maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + 497 sta->ht_cap.ampdu_factor); 498 tsta.maxampdu = cpu_to_be16(maxampdu); 499 } else { 500 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN); 501 tsta.is_vif_sta = 1; 502 tsta.maxampdu = cpu_to_be16(0xffff); 503 } 504 505 tsta.sta_index = sta_idx; 506 tsta.vif_index = avp->index; 507 508 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta); 509 if (ret) { 510 if (sta) 511 ath_err(common, 512 "Unable to add station entry for: %pM\n", 513 sta->addr); 514 return ret; 515 } 516 517 if (sta) { 518 ath_dbg(common, CONFIG, 519 "Added a station entry for: %pM (idx: %d)\n", 520 sta->addr, tsta.sta_index); 521 } else { 522 ath_dbg(common, CONFIG, 523 "Added a station entry for VIF %d (idx: %d)\n", 524 avp->index, tsta.sta_index); 525 } 526 527 priv->sta_slot |= (1 << sta_idx); 528 priv->nstations++; 529 if (!sta) 530 priv->vif_sta_pos[avp->index] = sta_idx; 531 532 return 0; 533 } 534 535 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv, 536 struct ieee80211_vif *vif, 537 struct ieee80211_sta *sta) 538 { 539 struct ath_common *common = ath9k_hw_common(priv->ah); 540 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv; 541 struct ath9k_htc_sta *ista; 542 int ret; 543 u8 cmd_rsp, sta_idx; 544 545 if (sta) { 546 ista = (struct ath9k_htc_sta *) sta->drv_priv; 547 sta_idx = ista->index; 548 } else { 549 sta_idx = priv->vif_sta_pos[avp->index]; 550 } 551 552 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx); 553 if (ret) { 554 if (sta) 555 ath_err(common, 556 "Unable to remove station entry for: %pM\n", 557 sta->addr); 558 return ret; 559 } 560 561 if (sta) { 562 ath_dbg(common, CONFIG, 563 "Removed a station entry for: %pM (idx: %d)\n", 564 sta->addr, sta_idx); 565 } else { 566 ath_dbg(common, CONFIG, 567 "Removed a station entry for VIF %d (idx: %d)\n", 568 avp->index, sta_idx); 569 } 570 571 priv->sta_slot &= ~(1 << sta_idx); 572 priv->nstations--; 573 574 return 0; 575 } 576 577 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv, 578 u8 enable_coex) 579 { 580 struct ath9k_htc_cap_target tcap; 581 int ret; 582 u8 cmd_rsp; 583 584 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target)); 585 586 tcap.ampdu_limit = cpu_to_be32(0xffff); 587 tcap.ampdu_subframes = 0xff; 588 tcap.enable_coex = enable_coex; 589 tcap.tx_chainmask = priv->ah->caps.tx_chainmask; 590 591 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap); 592 593 return ret; 594 } 595 596 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv, 597 struct ieee80211_sta *sta, 598 struct ath9k_htc_target_rate *trate) 599 { 600 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv; 601 struct ieee80211_supported_band *sband; 602 u32 caps = 0; 603 int i, j; 604 605 sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band]; 606 607 for (i = 0, j = 0; i < sband->n_bitrates; i++) { 608 if (sta->supp_rates[sband->band] & BIT(i)) { 609 trate->rates.legacy_rates.rs_rates[j] 610 = (sband->bitrates[i].bitrate * 2) / 10; 611 j++; 612 } 613 } 614 trate->rates.legacy_rates.rs_nrates = j; 615 616 if (sta->ht_cap.ht_supported) { 617 for (i = 0, j = 0; i < 77; i++) { 618 if (sta->ht_cap.mcs.rx