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
drv_start(struct ieee80211_local * local)13 int drv_start(struct ieee80211_local *local)
14 {
15 int ret;
16
17 might_sleep();
18
19 if (WARN_ON(local->started))
20 return -EALREADY;
21
22 trace_drv_start(local);
23 local->started = true;
24 /* allow rx frames */
25 smp_mb();
26 ret = local->ops->start(&local->hw);
27 trace_drv_return_int(local, ret);
28
29 if (ret)
30 local->started = false;
31
32 return ret;
33 }
34
drv_stop(struct ieee80211_local * local)35 void drv_stop(struct ieee80211_local *local)
36 {
37 might_sleep();
38
39 if (WARN_ON(!local->started))
40 return;
41
42 trace_drv_stop(local);
43 local->ops->stop(&local->hw);
44 trace_drv_return_void(local);
45
46 /* sync away all work on the tasklet before clearing started */
47 tasklet_disable(&local->tasklet);
48 tasklet_enable(&local->tasklet);
49
50 barrier();
51
52 local->started = false;
53 }
54
drv_add_interface(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata)55 int drv_add_interface(struct ieee80211_local *local,
56 struct ieee80211_sub_if_data *sdata)
57 {
58 int ret;
59
60 might_sleep();
61
62 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
63 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
64 !ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) &&
65 !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))))
66 return -EINVAL;
67
68 trace_drv_add_interface(local, sdata);
69 ret = local->ops->add_interface(&local->hw, &sdata->vif);
70 trace_drv_return_int(local, ret);
71
72 if (ret == 0)
73 sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
74
75 return ret;
76 }
77
drv_change_interface(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata,enum nl80211_iftype type,bool p2p)78 int drv_change_interface(struct ieee80211_local *local,
79 struct ieee80211_sub_if_data *sdata,
80 enum nl80211_iftype type, bool p2p)
81 {
82 int ret;
83
84 might_sleep();
85
86 if (!check_sdata_in_driver(sdata))
87 return -EIO;
88
89 trace_drv_change_interface(local, sdata, type, p2p);
90 ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
91 trace_drv_return_int(local, ret);
92 return ret;
93 }
94
drv_remove_interface(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata)95 void drv_remove_interface(struct ieee80211_local *local,
96 struct ieee80211_sub_if_data *sdata)
97 {
98 might_sleep();
99
100 if (!check_sdata_in_driver(sdata))
101 return;
102
103 trace_drv_remove_interface(local, sdata);
104 local->ops->remove_interface(&local->hw, &sdata->vif);
105 sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
106 trace_drv_return_void(local);
107 }
108
109 __must_check
drv_sta_state(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata,struct sta_info * sta,enum ieee80211_sta_state old_state,enum ieee80211_sta_state new_state)110 int drv_sta_state(struct ieee80211_local *local,
111 struct ieee80211_sub_if_data *sdata,
112 struct sta_info *sta,
113 enum ieee80211_sta_state old_state,
114 enum ieee80211_sta_state new_state)
115 {
116 int ret = 0;
117
118 might_sleep();
119
120 sdata = get_bss_sdata(sdata);
121 if (!check_sdata_in_driver(sdata))
122 return -EIO;
123
124 trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
125 if (local->ops->sta_state) {
126 ret = local->ops->sta_state(&local->hw, &sdata->vif, &sta->sta,
127 old_state, new_state);
128 } else if (old_state == IEEE80211_STA_AUTH &&
129 new_state == IEEE80211_STA_ASSOC) {
130 ret = drv_sta_add(local, sdata, &sta->sta);
131 if (ret == 0) {
132 sta->uploaded = true;
133 if (rcu_access_pointer(sta->sta.rates))
134 drv_sta_rate_tbl_update(local, sdata, &sta->sta);
135 }
136 } else if (old_state == IEEE80211_STA_ASSOC &&
137 new_state == IEEE80211_STA_AUTH) {
138 drv_sta_remove(local, sdata, &sta->sta);
139 }
140 trace_drv_return_int(local, ret);
141 return ret;
142 }
143
drv_sta_rc_update(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata,struct ieee80211_sta * sta,u32 changed)144 void drv_sta_rc_update(struct ieee80211_local *local,
145 struct ieee80211_sub_if_data *sdata,
146 struct ieee80211_sta *sta, u32 changed)
147 {
148 sdata = get_bss_sdata(sdata);
149 if (!check_sdata_in_driver(sdata))
150 return;
151
152 WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
153 (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
154 sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
155
156 trace_drv_sta_rc_update(local, sdata, sta, changed);
157 if (local->ops->sta_rc_update)
158 local->ops->sta_rc_update(&local->hw, &sdata->vif,
159 sta, changed);
160
161 trace_drv_return_void(local);
162 }
163
drv_conf_tx(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata,u16 ac,const struct ieee80211_tx_queue_params * params)164 int drv_conf_tx(struct ieee80211_local *local,
165 struct ieee80211_sub_if_data *sdata, u16 ac,
166 const struct ieee80211_tx_queue_params *params)
167 {
168 int ret = -EOPNOTSUPP;
169
170 might_sleep();
171
172 if (!check_sdata_in_driver(sdata))
173 return -EIO;
174
175 if (params->cw_min == 0 || params->cw_min > params->cw_max) {
176 /*
177 * If we can't configure hardware anyway, don't warn. We may
178 * never have initialized the CW parameters.
179 */
180 WARN_ONCE(local->ops->conf_tx,
181 "%s: invalid CW_min/CW_max: %d/%d\n",
182 sdata->name, params->cw_min, params->cw_max);
183 return -EINVAL;
184 }
185
186 trace_drv_conf_tx(local, sdata, ac, params);
187 if (local->ops->conf_tx)
188 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
189 ac, params);
190 trace_drv_return_int(local, ret);
191 return ret;
192 }
193
drv_get_tsf(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata)194 u64 drv_get_tsf(struct ieee80211_local *local,
195 struct ieee80211_sub_if_data *sdata)
196 {
197 u64 ret = -1ULL;
198
199 might_sleep();
200
201 if (!check_sdata_in_driver(sdata))
202 return ret;
203
204 trace_drv_get_tsf(local, sdata);
205 if (local->ops->get_tsf)
206 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
207 trace_drv_return_u64(local, ret);
208 return ret;
209 }
210
drv_set_tsf(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata,u64 tsf)211 void drv_set_tsf(struct ieee80211_local *local,
212 struct ieee80211_sub_if_data *sdata,
213 u64 tsf)
214 {
215 might_sleep();
216
217 if (!check_sdata_in_driver(sdata))
218 return;
219
220 trace_drv_set_tsf(local, sdata, tsf);
221 if (local->ops->set_tsf)
222 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
223 trace_drv_return_void(local);
224 }
225
drv_reset_tsf(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata)226 void drv_reset_tsf(struct ieee80211_local *local,
227 struct ieee80211_sub_if_data *sdata)
228 {
229 might_sleep();
230
231 if (!check_sdata_in_driver(sdata))
232 return;
233
234 trace_drv_reset_tsf(local, sdata);
235 if (local->ops->reset_tsf)
236 local->ops->reset_tsf(&local->hw, &sdata->vif);
237 trace_drv_return_void(local);
238 }
239
drv_switch_vif_chanctx(struct ieee80211_local * local,struct ieee80211_vif_chanctx_switch * vifs,int n_vifs,enum ieee80211_chanctx_switch_mode mode)240 int drv_switch_vif_chanctx(struct ieee80211_local *local,
241 struct ieee80211_vif_chanctx_switch *vifs,
242 int n_vifs, enum ieee80211_chanctx_switch_mode mode)
243 {
244 int ret = 0;
245 int i;
246
247 might_sleep();
248
249 if (!local->ops->switch_vif_chanctx)
250 return -EOPNOTSUPP;
251
252 for (i = 0; i < n_vifs; i++) {
253 struct ieee80211_chanctx *new_ctx =
254 container_of(vifs[i].new_ctx,
255 struct ieee80211_chanctx,
256 conf);
257 struct ieee80211_chanctx *old_ctx =
258 container_of(vifs[i].old_ctx,
259 struct ieee80211_chanctx,
260 conf);
261
262 WARN_ON_ONCE(!old_ctx->driver_present);
263 WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
264 new_ctx->driver_present) ||
265 (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
266 !new_ctx->driver_present));
267 }
268
269 trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
270 ret = local->ops->switch_vif_chanctx(&local->hw,
271 vifs, n_vifs, mode);
272 trace_drv_return_int(local, ret);
273
274 if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
275 for (i = 0; i < n_vifs; i++) {
276 struct ieee80211_chanctx *new_ctx =
277 container_of(vifs[i].new_ctx,
278 struct ieee80211_chanctx,
279 conf);
280 struct ieee80211_chanctx *old_ctx =
281 container_of(vifs[i].old_ctx,
282 struct ieee80211_chanctx,
283 conf);
284
285 new_ctx->driver_present = true;
286 old_ctx->driver_present = false;
287 }
288 }
289
290 return ret;
291 }
292
drv_ampdu_action(struct ieee80211_local * local,struct ieee80211_sub_if_data * sdata,struct ieee80211_ampdu_params * params)293 int drv_ampdu_action(struct ieee80211_local *local,
294 struct ieee80211_sub_if_data *sdata,
295 struct ieee80211_ampdu_params *params)
296 {
297 int ret = -EOPNOTSUPP;
298
299 might_sleep();
300
301 sdata = get_bss_sdata(sdata);
302 if (!check_sdata_in_driver(sdata))
303 return -EIO;
304
305 trace_drv_ampdu_action(local, sdata, params);
306
307 if (local->ops->ampdu_action)
308 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, params);
309
310 trace_drv_return_int(local, ret);
311
312 return ret;
313 }
314