driver-ops.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 (params->cw_min == 0 || params->cw_min > params->cw_max) {
  136. /*
  137. * If we can't configure hardware anyway, don't warn. We may
  138. * never have initialized the CW parameters.
  139. */
  140. WARN_ONCE(local->ops->conf_tx,
  141. "%s: invalid CW_min/CW_max: %d/%d\n",
  142. sdata->name, params->cw_min, params->cw_max);
  143. return -EINVAL;
  144. }
  145. trace_drv_conf_tx(local, sdata, ac, params);
  146. if (local->ops->conf_tx)
  147. ret = local->ops->conf_tx(&local->hw, &sdata->vif,
  148. ac, params);
  149. trace_drv_return_int(local, ret);
  150. return ret;
  151. }
  152. u64 drv_get_tsf(struct ieee80211_local *local,
  153. struct ieee80211_sub_if_data *sdata)
  154. {
  155. u64 ret = -1ULL;
  156. might_sleep();
  157. if (!check_sdata_in_driver(sdata))
  158. return ret;
  159. trace_drv_get_tsf(local, sdata);
  160. if (local->ops->get_tsf)
  161. ret = local->ops->get_tsf(&local->hw, &sdata->vif);
  162. trace_drv_return_u64(local, ret);
  163. return ret;
  164. }
  165. void drv_set_tsf(struct ieee80211_local *local,
  166. struct ieee80211_sub_if_data *sdata,
  167. u64 tsf)
  168. {
  169. might_sleep();
  170. if (!check_sdata_in_driver(sdata))
  171. return;
  172. trace_drv_set_tsf(local, sdata, tsf);
  173. if (local->ops->set_tsf)
  174. local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
  175. trace_drv_return_void(local);
  176. }
  177. void drv_offset_tsf(struct ieee80211_local *local,
  178. struct ieee80211_sub_if_data *sdata,
  179. s64 offset)
  180. {
  181. might_sleep();
  182. if (!check_sdata_in_driver(sdata))
  183. return;
  184. trace_drv_offset_tsf(local, sdata, offset);
  185. if (local->ops->offset_tsf)
  186. local->ops->offset_tsf(&local->hw, &sdata->vif, offset);
  187. trace_drv_return_void(local);
  188. }
  189. void drv_reset_tsf(struct ieee80211_local *local,
  190. struct ieee80211_sub_if_data *sdata)
  191. {
  192. might_sleep();
  193. if (!check_sdata_in_driver(sdata))
  194. return;
  195. trace_drv_reset_tsf(local, sdata);
  196. if (local->ops->reset_tsf)
  197. local->ops->reset_tsf(&local->hw, &sdata->vif);
  198. trace_drv_return_void(local);
  199. }
  200. int drv_switch_vif_chanctx(struct ieee80211_local *local,
  201. struct ieee80211_vif_chanctx_switch *vifs,
  202. int n_vifs, enum ieee80211_chanctx_switch_mode mode)
  203. {
  204. int ret = 0;
  205. int i;
  206. might_sleep();
  207. if (!local->ops->switch_vif_chanctx)
  208. return -EOPNOTSUPP;
  209. for (i = 0; i < n_vifs; i++) {
  210. struct ieee80211_chanctx *new_ctx =
  211. container_of(vifs[i].new_ctx,
  212. struct ieee80211_chanctx,
  213. conf);
  214. struct ieee80211_chanctx *old_ctx =
  215. container_of(vifs[i].old_ctx,
  216. struct ieee80211_chanctx,
  217. conf);
  218. WARN_ON_ONCE(!old_ctx->driver_present);
  219. WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
  220. new_ctx->driver_present) ||
  221. (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
  222. !new_ctx->driver_present));
  223. }
  224. trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
  225. ret = local->ops->switch_vif_chanctx(&local->hw,
  226. vifs, n_vifs, mode);
  227. trace_drv_return_int(local, ret);
  228. if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
  229. for (i = 0; i < n_vifs; i++) {
  230. struct ieee80211_chanctx *new_ctx =
  231. container_of(vifs[i].new_ctx,
  232. struct ieee80211_chanctx,
  233. conf);
  234. struct ieee80211_chanctx *old_ctx =
  235. container_of(vifs[i].old_ctx,
  236. struct ieee80211_chanctx,
  237. conf);
  238. new_ctx->driver_present = true;
  239. old_ctx->driver_present = false;
  240. }
  241. }
  242. return ret;
  243. }
  244. int drv_ampdu_action(struct ieee80211_local *local,
  245. struct ieee80211_sub_if_data *sdata,
  246. struct ieee80211_ampdu_params *params)
  247. {
  248. int ret = -EOPNOTSUPP;
  249. might_sleep();
  250. sdata = get_bss_sdata(sdata);
  251. if (!check_sdata_in_driver(sdata))
  252. return -EIO;
  253. trace_drv_ampdu_action(local, sdata, params);
  254. if (local->ops->ampdu_action)
  255. ret = local->ops->ampdu_action(&local->hw, &sdata->vif, params);
  256. trace_drv_return_int(local, ret);
  257. return ret;
  258. }