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 (params->cw_min == 0 || params->cw_min > params->cw_max) {
197 * If we can't configure hardware anyway, don't warn. We may
198 * never have initialized the CW parameters.
200 WARN_ONCE(local->ops->conf_tx,
201 "%s: invalid CW_min/CW_max: %d/%d\n",
202 sdata->name, params->cw_min, params->cw_max);
206 trace_drv_conf_tx(local, sdata, link->link_id, ac, params);
207 if (local->ops->conf_tx)
208 ret = local->ops->conf_tx(&local->hw, &sdata->vif,
209 link->link_id, ac, params);
210 trace_drv_return_int(local, ret);
214 u64 drv_get_tsf(struct ieee80211_local *local,
215 struct ieee80211_sub_if_data *sdata)
221 if (!check_sdata_in_driver(sdata))
224 trace_drv_get_tsf(local, sdata);
225 if (local->ops->get_tsf)
226 ret = local->ops->get_tsf(&local->hw, &sdata->vif);
227 trace_drv_return_u64(local, ret);
231 void drv_set_tsf(struct ieee80211_local *local,
232 struct ieee80211_sub_if_data *sdata,
237 if (!check_sdata_in_driver(sdata))
240 trace_drv_set_tsf(local, sdata, tsf);
241 if (local->ops->set_tsf)
242 local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
243 trace_drv_return_void(local);
246 void drv_offset_tsf(struct ieee80211_local *local,
247 struct ieee80211_sub_if_data *sdata,
252 if (!check_sdata_in_driver(sdata))
255 trace_drv_offset_tsf(local, sdata, offset);
256 if (local->ops->offset_tsf)
257 local->ops->offset_tsf(&local->hw, &sdata->vif, offset);
258 trace_drv_return_void(local);
261 void drv_reset_tsf(struct ieee80211_local *local,
262 struct ieee80211_sub_if_data *sdata)
266 if (!check_sdata_in_driver(sdata))
269 trace_drv_reset_tsf(local, sdata);
270 if (local->ops->reset_tsf)
271 local->ops->reset_tsf(&local->hw, &sdata->vif);
272 trace_drv_return_void(local);
275 int drv_switch_vif_chanctx(struct ieee80211_local *local,
276 struct ieee80211_vif_chanctx_switch *vifs,
277 int n_vifs, enum ieee80211_chanctx_switch_mode mode)
284 if (!local->ops->switch_vif_chanctx)
287 for (i = 0; i < n_vifs; i++) {
288 struct ieee80211_chanctx *new_ctx =
289 container_of(vifs[i].new_ctx,
290 struct ieee80211_chanctx,
292 struct ieee80211_chanctx *old_ctx =
293 container_of(vifs[i].old_ctx,
294 struct ieee80211_chanctx,
297 WARN_ON_ONCE(!old_ctx->driver_present);
298 WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
299 new_ctx->driver_present) ||
300 (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
301 !new_ctx->driver_present));
304 trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
305 ret = local->ops->switch_vif_chanctx(&local->hw,
307 trace_drv_return_int(local, ret);
309 if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
310 for (i = 0; i < n_vifs; i++) {
311 struct ieee80211_chanctx *new_ctx =
312 container_of(vifs[i].new_ctx,
313 struct ieee80211_chanctx,
315 struct ieee80211_chanctx *old_ctx =
316 container_of(vifs[i].old_ctx,
317 struct ieee80211_chanctx,
320 new_ctx->driver_present = true;
321 old_ctx->driver_present = false;
328 int drv_ampdu_action(struct ieee80211_local *local,
329 struct ieee80211_sub_if_data *sdata,
330 struct ieee80211_ampdu_params *params)
332 int ret = -EOPNOTSUPP;
336 sdata = get_bss_sdata(sdata);
337 if (!check_sdata_in_driver(sdata))
340 trace_drv_ampdu_action(local, sdata, params);
342 if (local->ops->ampdu_action)
343 ret = local->ops->ampdu_action(&local->hw, &sdata->vif, params);
345 trace_drv_return_int(local, ret);