1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2015 Intel Deutschland GmbH
4 * Copyright (C) 2022-2024 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
)
18 lockdep_assert_wiphy(local
->hw
.wiphy
);
20 if (WARN_ON(local
->started
))
23 trace_drv_start(local
);
24 local
->started
= true;
27 ret
= local
->ops
->start(&local
->hw
);
28 trace_drv_return_int(local
, ret
);
31 local
->started
= false;
36 void drv_stop(struct ieee80211_local
*local
, bool suspend
)
39 lockdep_assert_wiphy(local
->hw
.wiphy
);
41 if (WARN_ON(!local
->started
))
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
);
54 local
->started
= false;
57 int drv_add_interface(struct ieee80211_local
*local
,
58 struct ieee80211_sub_if_data
*sdata
)
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
))))
72 trace_drv_add_interface(local
, sdata
);
73 ret
= local
->ops
->add_interface(&local
->hw
, &sdata
->vif
);
74 trace_drv_return_int(local
, 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
);
90 int drv_change_interface(struct ieee80211_local
*local
,
91 struct ieee80211_sub_if_data
*sdata
,
92 enum nl80211_iftype type
, bool p2p
)
97 lockdep_assert_wiphy(local
->hw
.wiphy
);
99 if (!check_sdata_in_driver(sdata
))
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
);
108 void drv_remove_interface(struct ieee80211_local
*local
,
109 struct ieee80211_sub_if_data
*sdata
)
112 lockdep_assert_wiphy(local
->hw
.wiphy
);
114 if (!check_sdata_in_driver(sdata
))
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
);
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
)
137 lockdep_assert_wiphy(local
->hw
.wiphy
);
139 sdata
= get_bss_sdata(sdata
);
140 if (!check_sdata_in_driver(sdata
))
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
);
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
);
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
;
171 lockdep_assert_wiphy(local
->hw
.wiphy
);
173 sdata
= get_bss_sdata(sdata
);
174 if (!check_sdata_in_driver(sdata
))
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
,
181 trace_drv_return_int(local
, 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
,
190 sdata
= get_bss_sdata(sdata
);
191 if (!check_sdata_in_driver(sdata
))
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
,
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
;
214 lockdep_assert_wiphy(local
->hw
.wiphy
);
216 if (!check_sdata_in_driver(sdata
))
219 if (!ieee80211_vif_link_active(&sdata
->vif
, link
->link_id
))
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
);
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
);
241 u64
drv_get_tsf(struct ieee80211_local
*local
,
242 struct ieee80211_sub_if_data
*sdata
)
247 lockdep_assert_wiphy(local
->hw
.wiphy
);
249 if (!check_sdata_in_driver(sdata
))
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
);
259 void drv_set_tsf(struct ieee80211_local
*local
,
260 struct ieee80211_sub_if_data
*sdata
,
264 lockdep_assert_wiphy(local
->hw
.wiphy
);
266 if (!check_sdata_in_driver(sdata
))
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
,
280 lockdep_assert_wiphy(local
->hw
.wiphy
);
282 if (!check_sdata_in_driver(sdata
))
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
)
295 lockdep_assert_wiphy(local
->hw
.wiphy
);
297 if (!check_sdata_in_driver(sdata
))
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
)
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
))
328 if (!check_sdata_in_driver(sdata
))
331 if (!ieee80211_vif_link_active(&sdata
->vif
, link_conf
->link_id
))
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
,
342 trace_drv_return_int(local
, 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
)
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
))
360 if (!check_sdata_in_driver(sdata
))
363 if (!ieee80211_vif_link_active(&sdata
->vif
, link_conf
->link_id
))
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
,
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
)
385 lockdep_assert_wiphy(local
->hw
.wiphy
);
387 if (!local
->ops
->switch_vif_chanctx
)
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
,
395 struct ieee80211_chanctx
*old_ctx
=
396 container_of(vifs
[i
].old_ctx
,
397 struct ieee80211_chanctx
,
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
,
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
,
418 struct ieee80211_chanctx
*old_ctx
=
419 container_of(vifs
[i
].old_ctx
,
420 struct ieee80211_chanctx
,
423 new_ctx
->driver_present
= true;
424 old_ctx
->driver_present
= false;
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
;
438 lockdep_assert_wiphy(local
->hw
.wiphy
);
440 sdata
= get_bss_sdata(sdata
);
441 if (!check_sdata_in_driver(sdata
))
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
);
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
)
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
))
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
))))
477 if (!check_sdata_in_driver(sdata
))
480 if (!ieee80211_vif_link_active(&sdata
->vif
, link_id
))
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
,
487 else if (local
->ops
->bss_info_changed
)
488 local
->ops
->bss_info_changed(&local
->hw
, &sdata
->vif
,
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
)
502 lockdep_assert_wiphy(local
->hw
.wiphy
);
504 sdata
= get_bss_sdata(sdata
);
505 if (!check_sdata_in_driver(sdata
))
508 if (WARN_ON(key
->link_id
>= 0 && sdata
->vif
.active_links
&&
509 !(sdata
->vif
.active_links
& BIT(key
->link_id
))))
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
);
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
;
530 lockdep_assert_wiphy(local
->hw
.wiphy
);
532 if (!check_sdata_in_driver(sdata
))
535 if (old_links
== new_links
)
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
);
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
);
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
;
581 lockdep_assert_wiphy(local
->hw
.wiphy
);
583 if (!check_sdata_in_driver(sdata
))
586 old_links
&= sdata
->vif
.active_links
;
587 new_links
&= sdata
->vif
.active_links
;
589 if (old_links
== new_links
)
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
);
611 /* during reconfig don't add it to debugfs again */
612 if (local
->in_reconfig
|| local
->resuming
)
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
);