driver-ops.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. } else if (old_state == IEEE80211_STA_ASSOC &&
  105. new_state == IEEE80211_STA_AUTH) {
  106. drv_sta_remove(local, sdata, &sta->sta);
  107. }
  108. trace_drv_return_int(local, ret);
  109. return ret;
  110. }
  111. void drv_sta_rc_update(struct ieee80211_local *local,
  112. struct ieee80211_sub_if_data *sdata,
  113. struct ieee80211_sta *sta, u32 changed)
  114. {
  115. sdata = get_bss_sdata(sdata);
  116. if (!check_sdata_in_driver(sdata))
  117. return;
  118. WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
  119. (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  120. sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
  121. trace_drv_sta_rc_update(local, sdata, sta, changed);
  122. if (local->ops->sta_rc_update)
  123. local->ops->sta_rc_update(&local->hw, &sdata->vif,
  124. sta, changed);
  125. trace_drv_return_void(local);
  126. }
  127. int drv_conf_tx(struct ieee80211_local *local,
  128. struct ieee80211_sub_if_data *sdata, u16 ac,
  129. const struct ieee80211_tx_queue_params *params)
  130. {
  131. int ret = -EOPNOTSUPP;
  132. might_sleep();
  133. if (!check_sdata_in_driver(sdata))
  134. return -EIO;
  135. if (WARN_ONCE(params->cw_min == 0 ||
  136. params->cw_min > params->cw_max,
  137. "%s: invalid CW_min/CW_max: %d/%d\n",
  138. sdata->name, params->cw_min, params->cw_max))
  139. return -EINVAL;
  140. trace_drv_conf_tx(local, sdata, ac, params);
  141. if (local->ops->conf_tx)
  142. ret = local->ops->conf_tx(&local->hw, &sdata->vif,
  143. ac, params);
  144. trace_drv_return_int(local, ret);
  145. return ret;
  146. }
  147. u64 drv_get_tsf(struct ieee80211_local *local,
  148. struct ieee80211_sub_if_data *sdata)
  149. {
  150. u64 ret = -1ULL;
  151. might_sleep();
  152. if (!check_sdata_in_driver(sdata))
  153. return ret;
  154. trace_drv_get_tsf(local, sdata);
  155. if (local->ops->get_tsf)
  156. ret = local->ops->get_tsf(&local->hw, &sdata->vif);
  157. trace_drv_return_u64(local, ret);
  158. return ret;
  159. }
  160. void drv_set_tsf(struct ieee80211_local *local,
  161. struct ieee80211_sub_if_data *sdata,
  162. u64 tsf)
  163. {
  164. might_sleep();
  165. if (!check_sdata_in_driver(sdata))
  166. return;
  167. trace_drv_set_tsf(local, sdata, tsf);
  168. if (local->ops->set_tsf)
  169. local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
  170. trace_drv_return_void(local);
  171. }
  172. void drv_offset_tsf(struct ieee80211_local *local,
  173. struct ieee80211_sub_if_data *sdata,
  174. s64 offset)
  175. {
  176. might_sleep();
  177. if (!check_sdata_in_driver(sdata))
  178. return;
  179. trace_drv_offset_tsf(local, sdata, offset);
  180. if (local->ops->offset_tsf)
  181. local->ops->offset_tsf(&local->hw, &sdata->vif, offset);
  182. trace_drv_return_void(local);
  183. }
  184. void drv_reset_tsf(struct ieee80211_local *local,
  185. struct ieee80211_sub_if_data *sdata)
  186. {
  187. might_sleep();
  188. if (!check_sdata_in_driver(sdata))
  189. return;
  190. trace_drv_reset_tsf(local, sdata);
  191. if (local->ops->reset_tsf)
  192. local->ops->reset_tsf(&local->hw, &sdata->vif);
  193. trace_drv_return_void(local);
  194. }
  195. int drv_switch_vif_chanctx(struct ieee80211_local *local,
  196. struct ieee80211_vif_chanctx_switch *vifs,
  197. int n_vifs, enum ieee80211_chanctx_switch_mode mode)
  198. {
  199. int ret = 0;
  200. int i;
  201. might_sleep();
  202. if (!local->ops->switch_vif_chanctx)
  203. return -EOPNOTSUPP;
  204. for (i = 0; i < n_vifs; i++) {
  205. struct ieee80211_chanctx *new_ctx =
  206. container_of(vifs[i].new_ctx,
  207. struct ieee80211_chanctx,
  208. conf);
  209. struct ieee80211_chanctx *old_ctx =
  210. container_of(vifs[i].old_ctx,
  211. struct ieee80211_chanctx,
  212. conf);
  213. WARN_ON_ONCE(!old_ctx->driver_present);
  214. WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
  215. new_ctx->driver_present) ||
  216. (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
  217. !new_ctx->driver_present));
  218. }
  219. trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
  220. ret = local->ops->switch_vif_chanctx(&local->hw,
  221. vifs, n_vifs, mode);
  222. trace_drv_return_int(local, ret);
  223. if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
  224. for (i = 0; i < n_vifs; i++) {
  225. struct ieee80211_chanctx *new_ctx =
  226. container_of(vifs[i].new_ctx,
  227. struct ieee80211_chanctx,
  228. conf);
  229. struct ieee80211_chanctx *old_ctx =
  230. container_of(vifs[i].old_ctx,
  231. struct ieee80211_chanctx,
  232. conf);
  233. new_ctx->driver_present = true;
  234. old_ctx->driver_present = false;
  235. }
  236. }
  237. return ret;
  238. }
  239. int drv_ampdu_action(struct ieee80211_local *local,
  240. struct ieee80211_sub_if_data *sdata,
  241. struct ieee80211_ampdu_params *params)
  242. {
  243. int ret = -EOPNOTSUPP;
  244. might_sleep();
  245. sdata = get_bss_sdata(sdata);
  246. if (!check_sdata_in_driver(sdata))
  247. return -EIO;
  248. trace_drv_ampdu_action(local, sdata, params);
  249. if (local->ops->ampdu_action)
  250. ret = local->ops->ampdu_action(&local->hw, &sdata->vif, params);
  251. trace_drv_return_int(local, ret);
  252. return ret;
  253. }