accel/qaic: Add AIC200 support
[drm/drm-misc.git] / net / mac80211 / driver-ops.c
blob299d38e9e8630b1c58255c87612ad6c66ed25b33
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright 2015 Intel Deutschland GmbH
4 * Copyright (C) 2022-2024 Intel Corporation
5 */
6 #include <net/mac80211.h>
7 #include "ieee80211_i.h"
8 #include "trace.h"
9 #include "driver-ops.h"
10 #include "debugfs_sta.h"
11 #include "debugfs_netdev.h"
13 int drv_start(struct ieee80211_local *local)
15 int ret;
17 might_sleep();
18 lockdep_assert_wiphy(local->hw.wiphy);
20 if (WARN_ON(local->started))
21 return -EALREADY;
23 trace_drv_start(local);
24 local->started = true;
25 /* allow rx frames */
26 smp_mb();
27 ret = local->ops->start(&local->hw);
28 trace_drv_return_int(local, ret);
30 if (ret)
31 local->started = false;
33 return ret;
36 void drv_stop(struct ieee80211_local *local, bool suspend)
38 might_sleep();
39 lockdep_assert_wiphy(local->hw.wiphy);
41 if (WARN_ON(!local->started))
42 return;
44 trace_drv_stop(local, suspend);
45 local->ops->stop(&local->hw, suspend);
46 trace_drv_return_void(local);
48 /* sync away all work on the tasklet before clearing started */
49 tasklet_disable(&local->tasklet);
50 tasklet_enable(&local->tasklet);
52 barrier();
54 local->started = false;
57 int drv_add_interface(struct ieee80211_local *local,
58 struct ieee80211_sub_if_data *sdata)
60 int ret;
62 might_sleep();
63 lockdep_assert_wiphy(local->hw.wiphy);
65 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
66 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
67 !ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF) &&
68 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR) &&
69 !(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))))
70 return -EINVAL;
72 trace_drv_add_interface(local, sdata);
73 ret = local->ops->add_interface(&local->hw, &sdata->vif);
74 trace_drv_return_int(local, ret);
76 if (ret)
77 return ret;
79 if (!(sdata->flags & IEEE80211_SDATA_IN_DRIVER)) {
80 sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
82 drv_vif_add_debugfs(local, sdata);
83 /* initially vif is not MLD */
84 ieee80211_link_debugfs_drv_add(&sdata->deflink);
87 return 0;
90 int drv_change_interface(struct ieee80211_local *local,
91 struct ieee80211_sub_if_data *sdata,
92 enum nl80211_iftype type, bool p2p)
94 int ret;
96 might_sleep();
97 lockdep_assert_wiphy(local->hw.wiphy);
99 if (!check_sdata_in_driver(sdata))
100 return -EIO;
102 trace_drv_change_interface(local, sdata, type, p2p);
103 ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
104 trace_drv_return_int(local, ret);
105 return ret;
108 void drv_remove_interface(struct ieee80211_local *local,
109 struct ieee80211_sub_if_data *sdata)
111 might_sleep();
112 lockdep_assert_wiphy(local->hw.wiphy);
114 if (!check_sdata_in_driver(sdata))
115 return;
117 sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
119 /* Remove driver debugfs entries */
120 ieee80211_debugfs_recreate_netdev(sdata, sdata->vif.valid_links);
122 trace_drv_remove_interface(local, sdata);
123 local->ops->remove_interface(&local->hw, &sdata->vif);
124 trace_drv_return_void(local);
127 __must_check
128 int drv_sta_state(struct ieee80211_local *local,
129 struct ieee80211_sub_if_data *sdata,
130 struct sta_info *sta,
131 enum ieee80211_sta_state old_state,
132 enum ieee80211_sta_state new_state)
134 int ret = 0;
136 might_sleep();
137 lockdep_assert_wiphy(local->hw.wiphy);
139 sdata = get_bss_sdata(sdata);
140 if (!check_sdata_in_driver(sdata))
141 return -EIO;
143 trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
144 if (local->ops->sta_state) {
145 ret = local->ops->sta_state(&local->hw, &sdata->vif, &sta->sta,
146 old_state, new_state);
147 } else if (old_state == IEEE80211_STA_AUTH &&
148 new_state == IEEE80211_STA_ASSOC) {
149 ret = drv_sta_add(local, sdata, &sta->sta);
150 if (ret == 0) {
151 sta->uploaded = true;
152 if (rcu_access_pointer(sta->sta.rates))
153 drv_sta_rate_tbl_update(local, sdata, &sta->sta);
155 } else if (old_state == IEEE80211_STA_ASSOC &&
156 new_state == IEEE80211_STA_AUTH) {
157 drv_sta_remove(local, sdata, &sta->sta);
159 trace_drv_return_int(local, ret);
160 return ret;
163 __must_check
164 int drv_sta_set_txpwr(struct ieee80211_local *local,
165 struct ieee80211_sub_if_data *sdata,
166 struct sta_info *sta)
168 int ret = -EOPNOTSUPP;
170 might_sleep();
171 lockdep_assert_wiphy(local->hw.wiphy);
173 sdata = get_bss_sdata(sdata);
174 if (!check_sdata_in_driver(sdata))
175 return -EIO;
177 trace_drv_sta_set_txpwr(local, sdata, &sta->sta);
178 if (local->ops->sta_set_txpwr)
179 ret = local->ops->sta_set_txpwr(&local->hw, &sdata->vif,
180 &sta->sta);
181 trace_drv_return_int(local, ret);
182 return ret;
185 void drv_link_sta_rc_update(struct ieee80211_local *local,
186 struct ieee80211_sub_if_data *sdata,
187 struct ieee80211_link_sta *link_sta,
188 u32 changed)
190 sdata = get_bss_sdata(sdata);
191 if (!check_sdata_in_driver(sdata))
192 return;
194 WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
195 (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
196 sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
198 trace_drv_link_sta_rc_update(local, sdata, link_sta, changed);
199 if (local->ops->link_sta_rc_update)
200 local->ops->link_sta_rc_update(&local->hw, &sdata->vif,
201 link_sta, changed);
203 trace_drv_return_void(local);
206 int drv_conf_tx(struct ieee80211_local *local,
207 struct ieee80211_link_data *link, u16 ac,
208 const struct ieee80211_tx_queue_params *params)
210 struct ieee80211_sub_if_data *sdata = link->sdata;
211 int ret = -EOPNOTSUPP;
213 might_sleep();
214 lockdep_assert_wiphy(local->hw.wiphy);
216 if (!check_sdata_in_driver(sdata))
217 return -EIO;
219 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
220 return 0;
222 if (params->cw_min == 0 || params->cw_min > params->cw_max) {
224 * If we can't configure hardware anyway, don't warn. We may
225 * never have initialized the CW parameters.
227 WARN_ONCE(local->ops->conf_tx,
228 "%s: invalid CW_min/CW_max: %d/%d\n",
229 sdata->name, params->cw_min, params->cw_max);
230 return -EINVAL;
233 trace_drv_conf_tx(local, sdata, link->link_id, ac, params);
234 if (local->ops->conf_tx)
235 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
236 link->link_id, ac, params);
237 trace_drv_return_int(local, ret);
238 return ret;
241 u64 drv_get_tsf(struct ieee80211_local *local,
242 struct ieee80211_sub_if_data *sdata)
244 u64 ret = -1ULL;
246 might_sleep();
247 lockdep_assert_wiphy(local->hw.wiphy);
249 if (!check_sdata_in_driver(sdata))
250 return ret;
252 trace_drv_get_tsf(local, sdata);
253 if (local->ops->get_tsf)
254 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
255 trace_drv_return_u64(local, ret);
256 return ret;
259 void drv_set_tsf(struct ieee80211_local *local,
260 struct ieee80211_sub_if_data *sdata,
261 u64 tsf)
263 might_sleep();
264 lockdep_assert_wiphy(local->hw.wiphy);
266 if (!check_sdata_in_driver(sdata))
267 return;
269 trace_drv_set_tsf(local, sdata, tsf);
270 if (local->ops->set_tsf)
271 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
272 trace_drv_return_void(local);
275 void drv_offset_tsf(struct ieee80211_local *local,
276 struct ieee80211_sub_if_data *sdata,
277 s64 offset)
279 might_sleep();
280 lockdep_assert_wiphy(local->hw.wiphy);
282 if (!check_sdata_in_driver(sdata))
283 return;
285 trace_drv_offset_tsf(local, sdata, offset);
286 if (local->ops->offset_tsf)
287 local->ops->offset_tsf(&local->hw, &sdata->vif, offset);
288 trace_drv_return_void(local);
291 void drv_reset_tsf(struct ieee80211_local *local,
292 struct ieee80211_sub_if_data *sdata)
294 might_sleep();
295 lockdep_assert_wiphy(local->hw.wiphy);
297 if (!check_sdata_in_driver(sdata))
298 return;
300 trace_drv_reset_tsf(local, sdata);
301 if (local->ops->reset_tsf)
302 local->ops->reset_tsf(&local->hw, &sdata->vif);
303 trace_drv_return_void(local);
306 int drv_assign_vif_chanctx(struct ieee80211_local *local,
307 struct ieee80211_sub_if_data *sdata,
308 struct ieee80211_bss_conf *link_conf,
309 struct ieee80211_chanctx *ctx)
311 int ret = 0;
313 might_sleep();
314 lockdep_assert_wiphy(local->hw.wiphy);
317 * We should perhaps push emulate chanctx down and only
318 * make it call ->config() when the chanctx is actually
319 * assigned here (and unassigned below), but that's yet
320 * another change to all drivers to add assign/unassign
321 * emulation callbacks. Maybe later.
323 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
324 local->emulate_chanctx &&
325 !ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
326 return 0;
328 if (!check_sdata_in_driver(sdata))
329 return -EIO;
331 if (!ieee80211_vif_link_active(&sdata->vif, link_conf->link_id))
332 return 0;
334 trace_drv_assign_vif_chanctx(local, sdata, link_conf, ctx);
335 if (local->ops->assign_vif_chanctx) {
336 WARN_ON_ONCE(!ctx->driver_present);
337 ret = local->ops->assign_vif_chanctx(&local->hw,
338 &sdata->vif,
339 link_conf,
340 &ctx->conf);
342 trace_drv_return_int(local, ret);
344 return ret;
347 void drv_unassign_vif_chanctx(struct ieee80211_local *local,
348 struct ieee80211_sub_if_data *sdata,
349 struct ieee80211_bss_conf *link_conf,
350 struct ieee80211_chanctx *ctx)
352 might_sleep();
353 lockdep_assert_wiphy(local->hw.wiphy);
355 if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
356 local->emulate_chanctx &&
357 !ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
358 return;
360 if (!check_sdata_in_driver(sdata))
361 return;
363 if (!ieee80211_vif_link_active(&sdata->vif, link_conf->link_id))
364 return;
366 trace_drv_unassign_vif_chanctx(local, sdata, link_conf, ctx);
367 if (local->ops->unassign_vif_chanctx) {
368 WARN_ON_ONCE(!ctx->driver_present);
369 local->ops->unassign_vif_chanctx(&local->hw,
370 &sdata->vif,
371 link_conf,
372 &ctx->conf);
374 trace_drv_return_void(local);
377 int drv_switch_vif_chanctx(struct ieee80211_local *local,
378 struct ieee80211_vif_chanctx_switch *vifs,
379 int n_vifs, enum ieee80211_chanctx_switch_mode mode)
381 int ret = 0;
382 int i;
384 might_sleep();
385 lockdep_assert_wiphy(local->hw.wiphy);
387 if (!local->ops->switch_vif_chanctx)
388 return -EOPNOTSUPP;
390 for (i = 0; i < n_vifs; i++) {
391 struct ieee80211_chanctx *new_ctx =
392 container_of(vifs[i].new_ctx,
393 struct ieee80211_chanctx,
394 conf);
395 struct ieee80211_chanctx *old_ctx =
396 container_of(vifs[i].old_ctx,
397 struct ieee80211_chanctx,
398 conf);
400 WARN_ON_ONCE(!old_ctx->driver_present);
401 WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
402 new_ctx->driver_present) ||
403 (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
404 !new_ctx->driver_present));
407 trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
408 ret = local->ops->switch_vif_chanctx(&local->hw,
409 vifs, n_vifs, mode);
410 trace_drv_return_int(local, ret);
412 if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
413 for (i = 0; i < n_vifs; i++) {
414 struct ieee80211_chanctx *new_ctx =
415 container_of(vifs[i].new_ctx,
416 struct ieee80211_chanctx,
417 conf);
418 struct ieee80211_chanctx *old_ctx =
419 container_of(vifs[i].old_ctx,
420 struct ieee80211_chanctx,
421 conf);
423 new_ctx->driver_present = true;
424 old_ctx->driver_present = false;
428 return ret;
431 int drv_ampdu_action(struct ieee80211_local *local,
432 struct ieee80211_sub_if_data *sdata,
433 struct ieee80211_ampdu_params *params)
435 int ret = -EOPNOTSUPP;
437 might_sleep();
438 lockdep_assert_wiphy(local->hw.wiphy);
440 sdata = get_bss_sdata(sdata);
441 if (!check_sdata_in_driver(sdata))
442 return -EIO;
444 trace_drv_ampdu_action(local, sdata, params);
446 if (local->ops->ampdu_action)
447 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, params);
449 trace_drv_return_int(local, ret);
451 return ret;
454 void drv_link_info_changed(struct ieee80211_local *local,
455 struct ieee80211_sub_if_data *sdata,
456 struct ieee80211_bss_conf *info,
457 int link_id, u64 changed)
459 might_sleep();
460 lockdep_assert_wiphy(local->hw.wiphy);
462 if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
463 BSS_CHANGED_BEACON_ENABLED) &&
464 sdata->vif.type != NL80211_IFTYPE_AP &&
465 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
466 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
467 sdata->vif.type != NL80211_IFTYPE_OCB))
468 return;
470 if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
471 sdata->vif.type == NL80211_IFTYPE_NAN ||
472 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
473 !sdata->vif.bss_conf.mu_mimo_owner &&
474 !(changed & BSS_CHANGED_TXPOWER))))
475 return;
477 if (!check_sdata_in_driver(sdata))
478 return;
480 if (!ieee80211_vif_link_active(&sdata->vif, link_id))
481 return;
483 trace_drv_link_info_changed(local, sdata, info, changed);
484 if (local->ops->link_info_changed)
485 local->ops->link_info_changed(&local->hw, &sdata->vif,
486 info, changed);
487 else if (local->ops->bss_info_changed)
488 local->ops->bss_info_changed(&local->hw, &sdata->vif,
489 info, changed);
490 trace_drv_return_void(local);
493 int drv_set_key(struct ieee80211_local *local,
494 enum set_key_cmd cmd,
495 struct ieee80211_sub_if_data *sdata,
496 struct ieee80211_sta *sta,
497 struct ieee80211_key_conf *key)
499 int ret;
501 might_sleep();
502 lockdep_assert_wiphy(local->hw.wiphy);
504 sdata = get_bss_sdata(sdata);
505 if (!check_sdata_in_driver(sdata))
506 return -EIO;
508 if (WARN_ON(key->link_id >= 0 && sdata->vif.active_links &&
509 !(sdata->vif.active_links & BIT(key->link_id))))
510 return -ENOLINK;
512 trace_drv_set_key(local, cmd, sdata, sta, key);
513 ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
514 trace_drv_return_int(local, ret);
515 return ret;
518 int drv_change_vif_links(struct ieee80211_local *local,
519 struct ieee80211_sub_if_data *sdata,
520 u16 old_links, u16 new_links,
521 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
523 struct ieee80211_link_data *link;
524 unsigned long links_to_add;
525 unsigned long links_to_rem;
526 unsigned int link_id;
527 int ret = -EOPNOTSUPP;
529 might_sleep();
530 lockdep_assert_wiphy(local->hw.wiphy);
532 if (!check_sdata_in_driver(sdata))
533 return -EIO;
535 if (old_links == new_links)
536 return 0;
538 links_to_add = ~old_links & new_links;
539 links_to_rem = old_links & ~new_links;
541 for_each_set_bit(link_id, &links_to_rem, IEEE80211_MLD_MAX_NUM_LINKS) {
542 link = rcu_access_pointer(sdata->link[link_id]);
544 ieee80211_link_debugfs_drv_remove(link);
547 trace_drv_change_vif_links(local, sdata, old_links, new_links);
548 if (local->ops->change_vif_links)
549 ret = local->ops->change_vif_links(&local->hw, &sdata->vif,
550 old_links, new_links, old);
551 trace_drv_return_int(local, ret);
553 if (ret)
554 return ret;
556 if (!local->in_reconfig && !local->resuming) {
557 for_each_set_bit(link_id, &links_to_add,
558 IEEE80211_MLD_MAX_NUM_LINKS) {
559 link = rcu_access_pointer(sdata->link[link_id]);
561 ieee80211_link_debugfs_drv_add(link);
565 return 0;
568 int drv_change_sta_links(struct ieee80211_local *local,
569 struct ieee80211_sub_if_data *sdata,
570 struct ieee80211_sta *sta,
571 u16 old_links, u16 new_links)
573 struct sta_info *info = container_of(sta, struct sta_info, sta);
574 struct link_sta_info *link_sta;
575 unsigned long links_to_add;
576 unsigned long links_to_rem;
577 unsigned int link_id;
578 int ret = -EOPNOTSUPP;
580 might_sleep();
581 lockdep_assert_wiphy(local->hw.wiphy);
583 if (!check_sdata_in_driver(sdata))
584 return -EIO;
586 old_links &= sdata->vif.active_links;
587 new_links &= sdata->vif.active_links;
589 if (old_links == new_links)
590 return 0;
592 links_to_add = ~old_links & new_links;
593 links_to_rem = old_links & ~new_links;
595 for_each_set_bit(link_id, &links_to_rem, IEEE80211_MLD_MAX_NUM_LINKS) {
596 link_sta = rcu_dereference_protected(info->link[link_id],
597 lockdep_is_held(&local->hw.wiphy->mtx));
599 ieee80211_link_sta_debugfs_drv_remove(link_sta);
602 trace_drv_change_sta_links(local, sdata, sta, old_links, new_links);
603 if (local->ops->change_sta_links)
604 ret = local->ops->change_sta_links(&local->hw, &sdata->vif, sta,
605 old_links, new_links);
606 trace_drv_return_int(local, ret);
608 if (ret)
609 return ret;
611 /* during reconfig don't add it to debugfs again */
612 if (local->in_reconfig || local->resuming)
613 return 0;
615 for_each_set_bit(link_id, &links_to_add, IEEE80211_MLD_MAX_NUM_LINKS) {
616 link_sta = rcu_dereference_protected(info->link[link_id],
617 lockdep_is_held(&local->hw.wiphy->mtx));
618 ieee80211_link_sta_debugfs_drv_add(link_sta);
621 return 0;