1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2015 Intel Deutschland GmbH
4 * Copyright (C) 2022-2023 Intel Corporation
6 #include <net/mac80211.h>
7 #include "ieee80211_i.h"
9 #include "driver-ops.h"
10 #include "debugfs_sta.h"
11 #include "debugfs_netdev.h"
13 int drv_start(struct ieee80211_local *local)
19 if (WARN_ON(local->started))
22 trace_drv_start(local);
23 local->started = true;
26 ret = local->ops->start(&local->hw);
27 trace_drv_return_int(local, ret);
30 local->started = false;
35 void drv_stop(struct ieee80211_local *local)
39 if (WARN_ON(!local->started))
42 trace_drv_stop(local);
43 local->ops->stop(&local->hw);
44 trace_drv_return_void(local);
46 /* sync away all work on the tasklet before clearing started */
47 tasklet_disable(&local->tasklet);
48 tasklet_enable(&local->tasklet);
52 local->started = false;
55 int drv_add_interface(struct ieee80211_local *local,
56 struct ieee80211_sub_if_data *sdata)
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))))
68 trace_drv_add_interface(local, sdata);
69 ret = local->ops->add_interface(&local->hw, &sdata->vif);
70 trace_drv_return_int(local, ret);
73 sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
78 int drv_change_interface(struct ieee80211_local *local,
79 struct ieee80211_sub_if_data *sdata,
80 enum nl80211_iftype type, bool p2p)
86 if (!check_sdata_in_driver(sdata))
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);
95 void drv_remove_interface(struct ieee80211_local *local,
96 struct ieee80211_sub_if_data *sdata)
100 if (!check_sdata_in_driver(sdata))
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);
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)
120 sdata = get_bss_sdata(sdata);
121 if (!check_sdata_in_driver(sdata))
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);
132 sta->uploaded = true;
133 if (rcu_access_pointer(sta->sta.rates))
134 drv_sta_rate_tbl_update(local, sdata, &sta->sta);
136 } else if (old_state == IEEE80211_STA_ASSOC &&
137 new_state == IEEE80211_STA_AUTH) {
138 drv_sta_remove(local, sdata, &sta->sta);
140 trace_drv_return_int(local, ret);
145 int drv_sta_set_txpwr(struct ieee80211_local *local,
146 struct ieee80211_sub_if_data *sdata,
147 struct sta_info *sta)
149 int ret = -EOPNOTSUPP;
153 sdata = get_bss_sdata(sdata);
154 if (!check_sdata_in_driver(sdata))
157 trace_drv_sta_set_txpwr(local, sdata, &sta->sta);
158 if (local->ops->sta_set_txpwr)
159 ret = local->ops->sta_set_txpwr(&local->hw, &sdata->vif,
161 trace_drv_return_int(local, ret);
165 void drv_sta_rc_update(struct ieee80211_local *local,
166 struct ieee80211_sub_if_data *sdata,
167 struct ieee80211_sta *sta, u32 changed)
169 sdata = get_bss_sdata(sdata);
170 if (!check_sdata_in_driver(sdata))
173 WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
174 (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
175 sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
177 trace_drv_sta_rc_update(local, sdata, sta, changed);
178 if (local->ops->sta_rc_update)
179 local->ops->sta_rc_update(&local->hw, &sdata->vif,
182 trace_drv_return_void(local);
185 int drv_conf_tx(struct ieee80211_local *local,
186 struct ieee80211_link_data *link, u16 ac,
187 const struct ieee80211_tx_queue_params *params)
189 struct ieee80211_sub_if_data *sdata = link->sdata;
190 int ret = -EOPNOTSUPP;
194 if (!check_sdata_in_driver(sdata))
197 if (sdata->vif.active_links &&
198 !(sdata->vif.active_links & BIT(link->link_id)))
201 if (params->cw_min == 0 || params->cw_min > params->cw_max) {
203 * If we can't configure hardware anyway, don't warn. We may
204 * never have initialized the CW parameters.
206 WARN_ONCE(local->ops->conf_tx,
207 "%s: invalid CW_min/CW_max: %d/%d\n",
208 sdata->name, params->cw_min, params->cw_max);
212 trace_drv_conf_tx(local, sdata, link->link_id, ac, params);
213 if (local->ops->conf_tx)
214 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
215 link->link_id, ac, params);
216 trace_drv_return_int(local, ret);
220 u64 drv_get_tsf(struct ieee80211_local *local,
221 struct ieee80211_sub_if_data *sdata)
227 if (!check_sdata_in_driver(sdata))
230 trace_drv_get_tsf(local, sdata);
231 if (local->ops->get_tsf)
232 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
233 trace_drv_return_u64(local, ret);
237 void drv_set_tsf(struct ieee80211_local *local,
238 struct ieee80211_sub_if_data *sdata,
243 if (!check_sdata_in_driver(sdata))
246 trace_drv_set_tsf(local, sdata, tsf);
247 if (local->ops->set_tsf)
248 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
249 trace_drv_return_void(local);
252 void drv_offset_tsf(struct ieee80211_local *local,
253 struct ieee80211_sub_if_data *sdata,
258 if (!check_sdata_in_driver(sdata))
261 trace_drv_offset_tsf(local, sdata, offset);
262 if (local->ops->offset_tsf)
263 local->ops->offset_tsf(&local->hw, &sdata->vif, offset);
264 trace_drv_return_void(local);
267 void drv_reset_tsf(struct ieee80211_local *local,
268 struct ieee80211_sub_if_data *sdata)
272 if (!check_sdata_in_driver(sdata))
275 trace_drv_reset_tsf(local, sdata);
276 if (local->ops->reset_tsf)
277 local->ops->reset_tsf(&local->hw, &sdata->vif);
278 trace_drv_return_void(local);
281 int drv_assign_vif_chanctx(struct ieee80211_local *local,
282 struct ieee80211_sub_if_data *sdata,
283 struct ieee80211_bss_conf *link_conf,
284 struct ieee80211_chanctx *ctx)
288 drv_verify_link_exists(sdata, link_conf);
289 if (!check_sdata_in_driver(sdata))
292 if (sdata->vif.active_links &&
293 !(sdata->vif.active_links & BIT(link_conf->link_id)))
296 trace_drv_assign_vif_chanctx(local, sdata, link_conf, ctx);
297 if (local->ops->assign_vif_chanctx) {
298 WARN_ON_ONCE(!ctx->driver_present);
299 ret = local->ops->assign_vif_chanctx(&local->hw,
304 trace_drv_return_int(local, ret);
309 void drv_unassign_vif_chanctx(struct ieee80211_local *local,
310 struct ieee80211_sub_if_data *sdata,
311 struct ieee80211_bss_conf *link_conf,
312 struct ieee80211_chanctx *ctx)
316 drv_verify_link_exists(sdata, link_conf);
317 if (!check_sdata_in_driver(sdata))
320 if (sdata->vif.active_links &&
321 !(sdata->vif.active_links & BIT(link_conf->link_id)))
324 trace_drv_unassign_vif_chanctx(local, sdata, link_conf, ctx);
325 if (local->ops->unassign_vif_chanctx) {
326 WARN_ON_ONCE(!ctx->driver_present);
327 local->ops->unassign_vif_chanctx(&local->hw,
332 trace_drv_return_void(local);
335 int drv_switch_vif_chanctx(struct ieee80211_local *local,
336 struct ieee80211_vif_chanctx_switch *vifs,
337 int n_vifs, enum ieee80211_chanctx_switch_mode mode)
344 if (!local->ops->switch_vif_chanctx)
347 for (i = 0; i < n_vifs; i++) {
348 struct ieee80211_chanctx *new_ctx =
349 container_of(vifs[i].new_ctx,
350 struct ieee80211_chanctx,
352 struct ieee80211_chanctx *old_ctx =
353 container_of(vifs[i].old_ctx,
354 struct ieee80211_chanctx,
357 WARN_ON_ONCE(!old_ctx->driver_present);
358 WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
359 new_ctx->driver_present) ||
360 (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
361 !new_ctx->driver_present));
364 trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
365 ret = local->ops->switch_vif_chanctx(&local->hw,
367 trace_drv_return_int(local, ret);
369 if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
370 for (i = 0; i < n_vifs; i++) {
371 struct ieee80211_chanctx *new_ctx =
372 container_of(vifs[i].new_ctx,
373 struct ieee80211_chanctx,
375 struct ieee80211_chanctx *old_ctx =
376 container_of(vifs[i].old_ctx,
377 struct ieee80211_chanctx,
380 new_ctx->driver_present = true;
381 old_ctx->driver_present = false;
388 int drv_ampdu_action(struct ieee80211_local *local,
389 struct ieee80211_sub_if_data *sdata,
390 struct ieee80211_ampdu_params *params)
392 int ret = -EOPNOTSUPP;
399 sdata = get_bss_sdata(sdata);
400 if (!check_sdata_in_driver(sdata))
403 trace_drv_ampdu_action(local, sdata, params);
405 if (local->ops->ampdu_action)
406 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, params);
408 trace_drv_return_int(local, ret);
413 void drv_link_info_changed(struct ieee80211_local *local,
414 struct ieee80211_sub_if_data *sdata,
415 struct ieee80211_bss_conf *info,
416 int link_id, u64 changed)
420 if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
421 BSS_CHANGED_BEACON_ENABLED) &&
422 sdata->vif.type != NL80211_IFTYPE_AP &&
423 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
424 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
425 sdata->vif.type != NL80211_IFTYPE_OCB))
428 if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
429 sdata->vif.type == NL80211_IFTYPE_NAN ||
430 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
431 !sdata->vif.bss_conf.mu_mimo_owner &&
432 !(changed & BSS_CHANGED_TXPOWER))))
435 if (!check_sdata_in_driver(sdata))
438 if (sdata->vif.active_links &&
439 !(sdata->vif.active_links & BIT(link_id)))
442 trace_drv_link_info_changed(local, sdata, info, changed);
443 if (local->ops->link_info_changed)
444 local->ops->link_info_changed(&local->hw, &sdata->vif,
446 else if (local->ops->bss_info_changed)
447 local->ops->bss_info_changed(&local->hw, &sdata->vif,
449 trace_drv_return_void(local);
452 int drv_set_key(struct ieee80211_local *local,
453 enum set_key_cmd cmd,
454 struct ieee80211_sub_if_data *sdata,
455 struct ieee80211_sta *sta,
456 struct ieee80211_key_conf *key)
462 sdata = get_bss_sdata(sdata);
463 if (!check_sdata_in_driver(sdata))
466 if (WARN_ON(key->link_id >= 0 && sdata->vif.active_links &&
467 !(sdata->vif.active_links & BIT(key->link_id))))
470 trace_drv_set_key(local, cmd, sdata, sta, key);
471 ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
472 trace_drv_return_int(local, ret);
476 int drv_change_vif_links(struct ieee80211_local *local,
477 struct ieee80211_sub_if_data *sdata,
478 u16 old_links, u16 new_links,
479 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
481 struct ieee80211_link_data *link;
482 unsigned long links_to_add;
483 unsigned long links_to_rem;
484 unsigned int link_id;
485 int ret = -EOPNOTSUPP;
489 if (!check_sdata_in_driver(sdata))
492 if (old_links == new_links)
495 links_to_add = ~old_links & new_links;
496 links_to_rem = old_links & ~new_links;
498 for_each_set_bit(link_id, &links_to_rem, IEEE80211_MLD_MAX_NUM_LINKS) {
499 link = rcu_access_pointer(sdata->link[link_id]);
501 ieee80211_link_debugfs_drv_remove(link);
504 trace_drv_change_vif_links(local, sdata, old_links, new_links);
505 if (local->ops->change_vif_links)
506 ret = local->ops->change_vif_links(&local->hw, &sdata->vif,
507 old_links, new_links, old);
508 trace_drv_return_int(local, ret);
513 if (!local->in_reconfig) {
514 for_each_set_bit(link_id, &links_to_add,
515 IEEE80211_MLD_MAX_NUM_LINKS) {
516 link = rcu_access_pointer(sdata->link[link_id]);
518 ieee80211_link_debugfs_drv_add(link);
525 int drv_change_sta_links(struct ieee80211_local *local,
526 struct ieee80211_sub_if_data *sdata,
527 struct ieee80211_sta *sta,
528 u16 old_links, u16 new_links)
530 struct sta_info *info = container_of(sta, struct sta_info, sta);
531 struct link_sta_info *link_sta;
532 unsigned long links_to_add;
533 unsigned long links_to_rem;
534 unsigned int link_id;
535 int ret = -EOPNOTSUPP;
539 if (!check_sdata_in_driver(sdata))
542 old_links &= sdata->vif.active_links;
543 new_links &= sdata->vif.active_links;
545 if (old_links == new_links)
548 links_to_add = ~old_links & new_links;
549 links_to_rem = old_links & ~new_links;
551 for_each_set_bit(link_id, &links_to_rem, IEEE80211_MLD_MAX_NUM_LINKS) {
552 link_sta = rcu_dereference_protected(info->link[link_id],
553 lockdep_is_held(&local->sta_mtx));
555 ieee80211_link_sta_debugfs_drv_remove(link_sta);
558 trace_drv_change_sta_links(local, sdata, sta, old_links, new_links);
559 if (local->ops->change_sta_links)
560 ret = local->ops->change_sta_links(&local->hw, &sdata->vif, sta,
561 old_links, new_links);
562 trace_drv_return_int(local, ret);
567 /* during reconfig don't add it to debugfs again */
568 if (local->in_reconfig)
571 for_each_set_bit(link_id, &links_to_add, IEEE80211_MLD_MAX_NUM_LINKS) {
572 link_sta = rcu_dereference_protected(info->link[link_id],
573 lockdep_is_held(&local->sta_mtx));
574 ieee80211_link_sta_debugfs_drv_add(link_sta);