driver-ops.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Copyright 2015 Intel Deutschland GmbH
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <net/mac80211.h>
  9. #include "ieee80211_i.h"
  10. #include "trace.h"
  11. #include "driver-ops.h"
  12. int drv_start(struct ieee80211_local *local)
  13. {
  14. int ret;
  15. might_sleep();
  16. if (WARN_ON(local->started))
  17. return -EALREADY;
  18. trace_drv_start(local);
  19. local->started = true;
  20. /* allow rx frames */
  21. smp_mb();
  22. ret = local->ops->start(&local->hw);
  23. trace_drv_return_int(local, ret);
  24. if (ret)
  25. local->started = false;
  26. return ret;
  27. }
  28. void drv_stop(struct ieee80211_local *local)
  29. {
  30. might_sleep();
  31. if (WARN_ON(!local->started))
  32. return;
  33. trace_drv_stop(local);
  34. local->ops->stop(&local->hw);
  35. trace_drv_return_void(local);
  36. /* sync away all work on the tasklet before clearing started */
  37. tasklet_disable(&local->tasklet);
  38. tasklet_enable(&local->tasklet);
  39. barrier();
  40. local->started = false;
  41. }
  42. int drv_add_interface(struct ieee80211_local *local,
  43. struct ieee80211_sub_if_data *sdata)
  44. {
  45. int ret;
  46. might_sleep();
  47. if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  48. (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
  49. !ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) &&
  50. !(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))))
  51. return -EINVAL;
  52. trace_drv_add_interface(local, sdata);
  53. ret = local->ops->add_interface(&local->hw, &sdata->vif);
  54. trace_drv_return_int(local, ret);
  55. if (ret == 0)
  56. sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
  57. return ret;
  58. }
  59. int drv_change_interface(struct ieee80211_local *local,
  60. struct ieee80211_sub_if_data *sdata,
  61. enum nl80211_iftype type, bool p2p)
  62. {
  63. int ret;
  64. might_sleep();
  65. if (!check_sdata_in_driver(sdata))
  66. return -EIO;
  67. trace_drv_change_interface(local, sdata, type, p2p);
  68. ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
  69. trace_drv_return_int(local, ret);
  70. return ret;
  71. }
  72. void drv_remove_interface(struct ieee80211_local *local,
  73. struct ieee80211_sub_if_data *sdata)
  74. {
  75. might_sleep();
  76. if (!check_sdata_in_driver(sdata))
  77. return;
  78. trace_drv_remove_interface(local, sdata);
  79. local->ops->remove_interface(&local->hw, &sdata->vif);
  80. sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
  81. trace_drv_return_void(local);
  82. }
  83. __must_check
  84. int drv_sta_state(struct ieee80211_local *local,
  85. struct ieee80211_sub_if_data *sdata,
  86. struct sta_info *sta,
  87. enum ieee80211_sta_state old_state,
  88. enum ieee80211_sta_state new_state)
  89. {
  90. int ret = 0;
  91. might_sleep();
  92. sdata = get_bss_sdata(sdata);
  93. if (!check_sdata_in_driver(sdata))
  94. return -EIO;
  95. trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
  96. if (local->ops->sta_state) {
  97. ret = local->ops->sta_state(&local->hw, &sdata->vif, &sta->sta,
  98. old_state, new_state);
  99. } else if (old_state == IEEE80211_STA_AUTH &&
  100. new_state == IEEE80211_STA_ASSOC) {
  101. ret = drv_sta_add(local, sdata, &sta->sta);
  102. if (ret == 0) {
  103. sta->uploaded = true;
  104. if (rcu_access_pointer(sta->sta.rates))
  105. drv_sta_rate_tbl_update(local, sdata, &sta->sta);
  106. }
  107. } else if (old_state == IEEE80211_STA_ASSOC &&
  108. new_state == IEEE80211_STA_AUTH) {
  109. drv_sta_remove(local, sdata, &sta->sta);
  110. }
  111. trace_drv_return_int(local, ret);
  112. return ret;
  113. }
  114. void drv_sta_rc_update(struct ieee80211_local *local,
  115. struct ieee80211_sub_if_data *sdata,
  116. struct ieee80211_sta *sta, u32 changed)
  117. {
  118. sdata = get_bss_sdata(sdata);
  119. if (!check_sdata_in_driver(sdata))
  120. return;
  121. WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
  122. (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  123. sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
  124. trace_drv_sta_rc_update(local, sdata, sta, changed);
  125. if (local->ops->sta_rc_update)
  126. local->ops->sta_rc_update(&local->hw, &sdata->vif,
  127. sta, changed);
  128. trace_drv_return_void(local);
  129. }
  130. int drv_conf_tx(struct ieee80211_local *local,
  131. struct ieee80211_sub_if_data *sdata, u16 ac,
  132. const struct ieee80211_tx_queue_params *params)
  133. {
  134. int ret = -EOPNOTSUPP;
  135. might_sleep();
  136. if (!check_sdata_in_driver(sdata))
  137. return -EIO;
  138. if (params->cw_min == 0 || params->cw_min > params->cw_max) {
  139. /*
  140. * If we can't configure hardware anyway, don't warn. We may
  141. * never have initialized the CW parameters.
  142. */
  143. WARN_ONCE(local->ops->conf_tx,
  144. "%s: invalid CW_min/CW_max: %d/%d\n",
  145. sdata->name, params->cw_min, params->cw_max);
  146. return -EINVAL;
  147. }
  148. trace_drv_conf_tx(local, sdata, ac, params);
  149. if (local->ops->conf_tx)
  150. ret = local->ops->conf_tx(&local->hw, &sdata->vif,
  151. ac, params);
  152. trace_drv_return_int(local, ret);
  153. return ret;
  154. }
  155. u64 drv_get_tsf(struct ieee80211_local *local,
  156. struct ieee80211_sub_if_data *sdata)
  157. {
  158. u64 ret = -1ULL;
  159. might_sleep();
  160. if (!check_sdata_in_driver(sdata))
  161. return ret;
  162. trace_drv_get_tsf(local, sdata);
  163. if (local->ops->get_tsf)
  164. ret = local->ops->get_tsf(&local->hw, &sdata->vif);
  165. trace_drv_return_u64(local, ret);
  166. return ret;
  167. }
  168. void drv_set_tsf(struct ieee80211_local *local,
  169. struct ieee80211_sub_if_data *sdata,
  170. u64 tsf)
  171. {
  172. might_sleep();
  173. if (!check_sdata_in_driver(sdata))
  174. return;
  175. trace_drv_set_tsf(local, sdata, tsf);
  176. if (local->ops->set_tsf)
  177. local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
  178. trace_drv_return_void(local);
  179. }
  180. void drv_offset_tsf(struct ieee80211_local *local,
  181. struct ieee80211_sub_if_data *sdata,
  182. s64 offset)
  183. {
  184. might_sleep();
  185. if (!check_sdata_in_driver(sdata))
  186. return;
  187. trace_drv_offset_tsf(local, sdata, offset);
  188. if (local->ops->offset_tsf)
  189. local->ops->offset_tsf(&local->hw, &sdata->vif, offset);
  190. trace_drv_return_void(local);
  191. }
  192. void drv_reset_tsf(struct ieee80211_local *local,
  193. struct ieee80211_sub_if_data *sdata)
  194. {
  195. might_sleep();
  196. if (!check_sdata_in_driver(sdata))
  197. return;
  198. trace_drv_reset_tsf(local, sdata);
  199. if (local->ops->reset_tsf)
  200. local->ops->reset_tsf(&local->hw, &sdata->vif);
  201. trace_drv_return_void(local);
  202. }
  203. int drv_switch_vif_chanctx(struct ieee80211_local *local,
  204. struct ieee80211_vif_chanctx_switch *vifs,
  205. int n_vifs, enum ieee80211_chanctx_switch_mode mode)
  206. {
  207. int ret = 0;
  208. int i;
  209. might_sleep();
  210. if (!local->ops->switch_vif_chanctx)
  211. return -EOPNOTSUPP;
  212. for (i = 0; i < n_vifs; i++) {
  213. struct ieee80211_chanctx *new_ctx =
  214. container_of(vifs[i].new_ctx,
  215. struct ieee80211_chanctx,
  216. conf);
  217. struct ieee80211_chanctx *old_ctx =
  218. container_of(vifs[i].old_ctx,
  219. struct ieee80211_chanctx,
  220. conf);
  221. WARN_ON_ONCE(!old_ctx->driver_present);
  222. WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
  223. new_ctx->driver_present) ||
  224. (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
  225. !new_ctx->driver_present));
  226. }
  227. trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
  228. ret = local->ops->switch_vif_chanctx(&local->hw,
  229. vifs, n_vifs, mode);
  230. trace_drv_return_int(local, ret);
  231. if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
  232. for (i = 0; i < n_vifs; i++) {
  233. struct ieee80211_chanctx *new_ctx =
  234. container_of(vifs[i].new_ctx,
  235. struct ieee80211_chanctx,
  236. conf);
  237. struct ieee80211_chanctx *old_ctx =
  238. container_of(vifs[i].old_ctx,
  239. struct ieee80211_chanctx,
  240. conf);
  241. new_ctx->driver_present = true;
  242. old_ctx->driver_present = false;
  243. }
  244. }
  245. return ret;
  246. }
  247. int drv_ampdu_action(struct ieee80211_local *local,
  248. struct ieee80211_sub_if_data *sdata,
  249. struct ieee80211_ampdu_params *params)
  250. {
  251. int ret = -EOPNOTSUPP;
  252. might_sleep();
  253. sdata = get_bss_sdata(sdata);
  254. if (!check_sdata_in_driver(sdata))
  255. return -EIO;
  256. trace_drv_ampdu_action(local, sdata, params);
  257. if (local->ops->ampdu_action)
  258. ret = local->ops->ampdu_action(&local->hw, &sdata->vif, params);
  259. trace_drv_return_int(local, ret);
  260. return ret;
  261. }