1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2015 Intel Deutschland GmbH
4 * Copyright (C) 2022 Intel Corporation
6 #include <net/mac80211.h>
7 #include "ieee80211_i.h"
9 #include "driver-ops.h"
11 int drv_start(struct ieee80211_local *local)
17 if (WARN_ON(local->started))
20 trace_drv_start(local);
21 local->started = true;
24 ret = local->ops->start(&local->hw);
25 trace_drv_return_int(local, ret);
28 local->started = false;
33 void drv_stop(struct ieee80211_local *local)
37 if (WARN_ON(!local->started))
40 trace_drv_stop(local);
41 local->ops->stop(&local->hw);
42 trace_drv_return_void(local);
44 /* sync away all work on the tasklet before clearing started */
45 tasklet_disable(&local->tasklet);
46 tasklet_enable(&local->tasklet);
50 local->started = false;
53 int drv_add_interface(struct ieee80211_local *local,
54 struct ieee80211_sub_if_data *sdata)
60 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
61 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
62 !ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) &&
63 !(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))))
66 trace_drv_add_interface(local, sdata);
67 ret = local->ops->add_interface(&local->hw, &sdata->vif);
68 trace_drv_return_int(local, ret);
71 sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
76 int drv_change_interface(struct ieee80211_local *local,
77 struct ieee80211_sub_if_data *sdata,
78 enum nl80211_iftype type, bool p2p)
84 if (!check_sdata_in_driver(sdata))
87 trace_drv_change_interface(local, sdata, type, p2p);
88 ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
89 trace_drv_return_int(local, ret);
93 void drv_remove_interface(struct ieee80211_local *local,
94 struct ieee80211_sub_if_data *sdata)
98 if (!check_sdata_in_driver(sdata))
101 trace_drv_remove_interface(local, sdata);
102 local->ops->remove_interface(&local->hw, &sdata->vif);
103 sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
104 trace_drv_return_void(local);
108 int drv_sta_state(struct ieee80211_local *local,
109 struct ieee80211_sub_if_data *sdata,
110 struct sta_info *sta,
111 enum ieee80211_sta_state old_state,
112 enum ieee80211_sta_state new_state)
118 sdata = get_bss_sdata(sdata);
119 if (!check_sdata_in_driver(sdata))
122 trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
123 if (local->ops->sta_state) {
124 ret = local->ops->sta_state(&local->hw, &sdata->vif, &sta->sta,
125 old_state, new_state);
126 } else if (old_state == IEEE80211_STA_AUTH &&
127 new_state == IEEE80211_STA_ASSOC) {
128 ret = drv_sta_add(local, sdata, &sta->sta);
130 sta->uploaded = true;
131 if (rcu_access_pointer(sta->sta.rates))
132 drv_sta_rate_tbl_update(local, sdata, &sta->sta);
134 } else if (old_state == IEEE80211_STA_ASSOC &&
135 new_state == IEEE80211_STA_AUTH) {
136 drv_sta_remove(local, sdata, &sta->sta);
138 trace_drv_return_int(local, ret);
143 int drv_sta_set_txpwr(struct ieee80211_local *local,
144 struct ieee80211_sub_if_data *sdata,
145 struct sta_info *sta)
147 int ret = -EOPNOTSUPP;
151 sdata = get_bss_sdata(sdata);
152 if (!check_sdata_in_driver(sdata))
155 trace_drv_sta_set_txpwr(local, sdata, &sta->sta);
156 if (local->ops->sta_set_txpwr)
157 ret = local->ops->sta_set_txpwr(&local->hw, &sdata->vif,
159 trace_drv_return_int(local, ret);
163 void drv_sta_rc_update(struct ieee80211_local *local,
164 struct ieee80211_sub_if_data *sdata,
165 struct ieee80211_sta *sta, u32 changed)
167 sdata = get_bss_sdata(sdata);
168 if (!check_sdata_in_driver(sdata))
171 WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
172 (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
173 sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
175 trace_drv_sta_rc_update(local, sdata, sta, changed);
176 if (local->ops->sta_rc_update)
177 local->ops->sta_rc_update(&local->hw, &sdata->vif,
180 trace_drv_return_void(local);
183 int drv_conf_tx(struct ieee80211_local *local,
184 struct ieee80211_link_data *link, u16 ac,
185 const struct ieee80211_tx_queue_params *params)
187 struct ieee80211_sub_if_data *sdata = link->sdata;
188 int ret = -EOPNOTSUPP;
192 if (!check_sdata_in_driver(sdata))
195 if (sdata->vif.active_links &&
196 !(sdata->vif.active_links & BIT(link->link_id)))
199 if (params->cw_min == 0 || params->cw_min > params->cw_max) {
201 * If we can't configure hardware anyway, don't warn. We may
202 * never have initialized the CW parameters.
204 WARN_ONCE(local->ops->conf_tx,
205 "%s: invalid CW_min/CW_max: %d/%d\n",
206 sdata->name, params->cw_min, params->cw_max);
210 trace_drv_conf_tx(local, sdata, link->link_id, ac, params);
211 if (local->ops->conf_tx)
212 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
213 link->link_id, ac, params);
214 trace_drv_return_int(local, ret);
218 u64 drv_get_tsf(struct ieee80211_local *local,
219 struct ieee80211_sub_if_data *sdata)
225 if (!check_sdata_in_driver(sdata))
228 trace_drv_get_tsf(local, sdata);
229 if (local->ops->get_tsf)
230 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
231 trace_drv_return_u64(local, ret);
235 void drv_set_tsf(struct ieee80211_local *local,
236 struct ieee80211_sub_if_data *sdata,
241 if (!check_sdata_in_driver(sdata))
244 trace_drv_set_tsf(local, sdata, tsf);
245 if (local->ops->set_tsf)
246 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
247 trace_drv_return_void(local);
250 void drv_offset_tsf(struct ieee80211_local *local,
251 struct ieee80211_sub_if_data *sdata,
256 if (!check_sdata_in_driver(sdata))
259 trace_drv_offset_tsf(local, sdata, offset);
260 if (local->ops->offset_tsf)
261 local->ops->offset_tsf(&local->hw, &sdata->vif, offset);
262 trace_drv_return_void(local);
265 void drv_reset_tsf(struct ieee80211_local *local,
266 struct ieee80211_sub_if_data *sdata)
270 if (!check_sdata_in_driver(sdata))
273 trace_drv_reset_tsf(local, sdata);
274 if (local->ops->reset_tsf)
275 local->ops->reset_tsf(&local->hw, &sdata->vif);
276 trace_drv_return_void(local);
279 int drv_assign_vif_chanctx(struct ieee80211_local *local,
280 struct ieee80211_sub_if_data *sdata,
281 struct ieee80211_bss_conf *link_conf,
282 struct ieee80211_chanctx *ctx)
286 drv_verify_link_exists(sdata, link_conf);
287 if (!check_sdata_in_driver(sdata))
290 if (sdata->vif.active_links &&
291 !(sdata->vif.active_links & BIT(link_conf->link_id)))
294 trace_drv_assign_vif_chanctx(local, sdata, link_conf, ctx);
295 if (local->ops->assign_vif_chanctx) {
296 WARN_ON_ONCE(!ctx->driver_present);
297 ret = local->ops->assign_vif_chanctx(&local->hw,
302 trace_drv_return_int(local, ret);
307 void drv_unassign_vif_chanctx(struct ieee80211_local *local,
308 struct ieee80211_sub_if_data *sdata,
309 struct ieee80211_bss_conf *link_conf,
310 struct ieee80211_chanctx *ctx)
314 drv_verify_link_exists(sdata, link_conf);
315 if (!check_sdata_in_driver(sdata))
318 if (sdata->vif.active_links &&
319 !(sdata->vif.active_links & BIT(link_conf->link_id)))
322 trace_drv_unassign_vif_chanctx(local, sdata, link_conf, ctx);
323 if (local->ops->unassign_vif_chanctx) {
324 WARN_ON_ONCE(!ctx->driver_present);
325 local->ops->unassign_vif_chanctx(&local->hw,
330 trace_drv_return_void(local);
333 int drv_switch_vif_chanctx(struct ieee80211_local *local,
334 struct ieee80211_vif_chanctx_switch *vifs,
335 int n_vifs, enum ieee80211_chanctx_switch_mode mode)
342 if (!local->ops->switch_vif_chanctx)
345 for (i = 0; i < n_vifs; i++) {
346 struct ieee80211_chanctx *new_ctx =
347 container_of(vifs[i].new_ctx,
348 struct ieee80211_chanctx,
350 struct ieee80211_chanctx *old_ctx =
351 container_of(vifs[i].old_ctx,
352 struct ieee80211_chanctx,
355 WARN_ON_ONCE(!old_ctx->driver_present);
356 WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
357 new_ctx->driver_present) ||
358 (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
359 !new_ctx->driver_present));
362 trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
363 ret = local->ops->switch_vif_chanctx(&local->hw,
365 trace_drv_return_int(local, ret);
367 if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
368 for (i = 0; i < n_vifs; i++) {
369 struct ieee80211_chanctx *new_ctx =
370 container_of(vifs[i].new_ctx,
371 struct ieee80211_chanctx,
373 struct ieee80211_chanctx *old_ctx =
374 container_of(vifs[i].old_ctx,
375 struct ieee80211_chanctx,
378 new_ctx->driver_present = true;
379 old_ctx->driver_present = false;
386 int drv_ampdu_action(struct ieee80211_local *local,
387 struct ieee80211_sub_if_data *sdata,
388 struct ieee80211_ampdu_params *params)
390 int ret = -EOPNOTSUPP;
394 sdata = get_bss_sdata(sdata);
395 if (!check_sdata_in_driver(sdata))
398 trace_drv_ampdu_action(local, sdata, params);
400 if (local->ops->ampdu_action)
401 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, params);
403 trace_drv_return_int(local, ret);
408 void drv_link_info_changed(struct ieee80211_local *local,
409 struct ieee80211_sub_if_data *sdata,
410 struct ieee80211_bss_conf *info,
411 int link_id, u64 changed)
415 if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
416 BSS_CHANGED_BEACON_ENABLED) &&
417 sdata->vif.type != NL80211_IFTYPE_AP &&
418 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
419 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
420 sdata->vif.type != NL80211_IFTYPE_OCB))
423 if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
424 sdata->vif.type == NL80211_IFTYPE_NAN ||
425 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
426 !sdata->vif.bss_conf.mu_mimo_owner &&
427 !(changed & BSS_CHANGED_TXPOWER))))
430 if (!check_sdata_in_driver(sdata))
433 if (sdata->vif.active_links &&
434 !(sdata->vif.active_links & BIT(link_id)))
437 trace_drv_link_info_changed(local, sdata, info, changed);
438 if (local->ops->link_info_changed)
439 local->ops->link_info_changed(&local->hw, &sdata->vif,
441 else if (local->ops->bss_info_changed)
442 local->ops->bss_info_changed(&local->hw, &sdata->vif,
444 trace_drv_return_void(local);
447 int drv_set_key(struct ieee80211_local *local,
448 enum set_key_cmd cmd,
449 struct ieee80211_sub_if_data *sdata,
450 struct ieee80211_sta *sta,
451 struct ieee80211_key_conf *key)
457 sdata = get_bss_sdata(sdata);
458 if (!check_sdata_in_driver(sdata))
461 if (WARN_ON(key->link_id >= 0 && sdata->vif.active_links &&
462 !(sdata->vif.active_links & BIT(key->link_id))))
465 trace_drv_set_key(local, cmd, sdata, sta, key);
466 ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
467 trace_drv_return_int(local, ret);
471 int drv_change_vif_links(struct ieee80211_local *local,
472 struct ieee80211_sub_if_data *sdata,
473 u16 old_links, u16 new_links,
474 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
476 int ret = -EOPNOTSUPP;
480 if (!check_sdata_in_driver(sdata))
483 if (old_links == new_links)
486 trace_drv_change_vif_links(local, sdata, old_links, new_links);
487 if (local->ops->change_vif_links)
488 ret = local->ops->change_vif_links(&local->hw, &sdata->vif,
489 old_links, new_links, old);
490 trace_drv_return_int(local, ret);
495 int drv_change_sta_links(struct ieee80211_local *local,
496 struct ieee80211_sub_if_data *sdata,
497 struct ieee80211_sta *sta,
498 u16 old_links, u16 new_links)
500 int ret = -EOPNOTSUPP;
504 if (!check_sdata_in_driver(sdata))
507 old_links &= sdata->vif.active_links;
508 new_links &= sdata->vif.active_links;
510 if (old_links == new_links)
513 trace_drv_change_sta_links(local, sdata, sta, old_links, new_links);
514 if (local->ops->change_sta_links)
515 ret = local->ops->change_sta_links(&local->hw, &sdata->vif, sta,
516 old_links, new_links);
517 trace_drv_return_int(local, ret);