xref: /openbmc/linux/net/mac80211/driver-ops.h (revision a8182929)
124487981SJohannes Berg #ifndef __MAC80211_DRIVER_OPS
224487981SJohannes Berg #define __MAC80211_DRIVER_OPS
324487981SJohannes Berg 
424487981SJohannes Berg #include <net/mac80211.h>
524487981SJohannes Berg #include "ieee80211_i.h"
6011ad0e9SJohannes Berg #include "trace.h"
724487981SJohannes Berg 
8f6837ba8SJohannes Berg static inline bool check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
97b7eab6fSJohannes Berg {
10f6837ba8SJohannes Berg 	return !WARN(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER),
11d17087e7SBen Greear 		     "%s:  Failed check-sdata-in-driver check, flags: 0x%x\n",
12f142c6b9SJohannes Berg 		     sdata->dev ? sdata->dev->name : sdata->name, sdata->flags);
137b7eab6fSJohannes Berg }
147b7eab6fSJohannes Berg 
15bc192f89SFelix Fietkau static inline struct ieee80211_sub_if_data *
16bc192f89SFelix Fietkau get_bss_sdata(struct ieee80211_sub_if_data *sdata)
17bc192f89SFelix Fietkau {
18bc192f89SFelix Fietkau 	if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
19bc192f89SFelix Fietkau 		sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
20bc192f89SFelix Fietkau 				     u.ap);
21bc192f89SFelix Fietkau 
22bc192f89SFelix Fietkau 	return sdata;
23bc192f89SFelix Fietkau }
24bc192f89SFelix Fietkau 
2536323f81SThomas Huehn static inline void drv_tx(struct ieee80211_local *local,
2636323f81SThomas Huehn 			  struct ieee80211_tx_control *control,
2736323f81SThomas Huehn 			  struct sk_buff *skb)
2824487981SJohannes Berg {
2936323f81SThomas Huehn 	local->ops->tx(&local->hw, control, skb);
3024487981SJohannes Berg }
3124487981SJohannes Berg 
32e352114fSBen Greear static inline void drv_get_et_strings(struct ieee80211_sub_if_data *sdata,
33e352114fSBen Greear 				      u32 sset, u8 *data)
34e352114fSBen Greear {
35e352114fSBen Greear 	struct ieee80211_local *local = sdata->local;
36e352114fSBen Greear 	if (local->ops->get_et_strings) {
37e352114fSBen Greear 		trace_drv_get_et_strings(local, sset);
38e352114fSBen Greear 		local->ops->get_et_strings(&local->hw, &sdata->vif, sset, data);
39e352114fSBen Greear 		trace_drv_return_void(local);
40e352114fSBen Greear 	}
41e352114fSBen Greear }
42e352114fSBen Greear 
43e352114fSBen Greear static inline void drv_get_et_stats(struct ieee80211_sub_if_data *sdata,
44e352114fSBen Greear 				    struct ethtool_stats *stats,
45e352114fSBen Greear 				    u64 *data)
46e352114fSBen Greear {
47e352114fSBen Greear 	struct ieee80211_local *local = sdata->local;
48e352114fSBen Greear 	if (local->ops->get_et_stats) {
49e352114fSBen Greear 		trace_drv_get_et_stats(local);
50e352114fSBen Greear 		local->ops->get_et_stats(&local->hw, &sdata->vif, stats, data);
51e352114fSBen Greear 		trace_drv_return_void(local);
52e352114fSBen Greear 	}
53e352114fSBen Greear }
54e352114fSBen Greear 
55e352114fSBen Greear static inline int drv_get_et_sset_count(struct ieee80211_sub_if_data *sdata,
56e352114fSBen Greear 					int sset)
57e352114fSBen Greear {
58e352114fSBen Greear 	struct ieee80211_local *local = sdata->local;
59e352114fSBen Greear 	int rv = 0;
60e352114fSBen Greear 	if (local->ops->get_et_sset_count) {
61e352114fSBen Greear 		trace_drv_get_et_sset_count(local, sset);
62e352114fSBen Greear 		rv = local->ops->get_et_sset_count(&local->hw, &sdata->vif,
63e352114fSBen Greear 						   sset);
64e352114fSBen Greear 		trace_drv_return_int(local, rv);
65e352114fSBen Greear 	}
66e352114fSBen Greear 	return rv;
67e352114fSBen Greear }
68e352114fSBen Greear 
6924487981SJohannes Berg static inline int drv_start(struct ieee80211_local *local)
7024487981SJohannes Berg {
71ea77f12fSJohannes Berg 	int ret;
72ea77f12fSJohannes Berg 
73e1781ed3SKalle Valo 	might_sleep();
74e1781ed3SKalle Valo 
754efc76bdSJohannes Berg 	trace_drv_start(local);
76ea77f12fSJohannes Berg 	local->started = true;
77ea77f12fSJohannes Berg 	smp_mb();
78ea77f12fSJohannes Berg 	ret = local->ops->start(&local->hw);
794efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
800a2b8bb2SJohannes Berg 	return ret;
8124487981SJohannes Berg }
8224487981SJohannes Berg 
8324487981SJohannes Berg static inline void drv_stop(struct ieee80211_local *local)
8424487981SJohannes Berg {
85e1781ed3SKalle Valo 	might_sleep();
86e1781ed3SKalle Valo 
870a2b8bb2SJohannes Berg 	trace_drv_stop(local);
884efc76bdSJohannes Berg 	local->ops->stop(&local->hw);
894efc76bdSJohannes Berg 	trace_drv_return_void(local);
90ea77f12fSJohannes Berg 
91ea77f12fSJohannes Berg 	/* sync away all work on the tasklet before clearing started */
92ea77f12fSJohannes Berg 	tasklet_disable(&local->tasklet);
93ea77f12fSJohannes Berg 	tasklet_enable(&local->tasklet);
94ea77f12fSJohannes Berg 
95ea77f12fSJohannes Berg 	barrier();
96ea77f12fSJohannes Berg 
97ea77f12fSJohannes Berg 	local->started = false;
9824487981SJohannes Berg }
9924487981SJohannes Berg 
100eecc4800SJohannes Berg #ifdef CONFIG_PM
101eecc4800SJohannes Berg static inline int drv_suspend(struct ieee80211_local *local,
102eecc4800SJohannes Berg 			      struct cfg80211_wowlan *wowlan)
103eecc4800SJohannes Berg {
104eecc4800SJohannes Berg 	int ret;
105eecc4800SJohannes Berg 
106eecc4800SJohannes Berg 	might_sleep();
107eecc4800SJohannes Berg 
108eecc4800SJohannes Berg 	trace_drv_suspend(local);
109eecc4800SJohannes Berg 	ret = local->ops->suspend(&local->hw, wowlan);
110eecc4800SJohannes Berg 	trace_drv_return_int(local, ret);
111eecc4800SJohannes Berg 	return ret;
112eecc4800SJohannes Berg }
113eecc4800SJohannes Berg 
114eecc4800SJohannes Berg static inline int drv_resume(struct ieee80211_local *local)
115eecc4800SJohannes Berg {
116eecc4800SJohannes Berg 	int ret;
117eecc4800SJohannes Berg 
118eecc4800SJohannes Berg 	might_sleep();
119eecc4800SJohannes Berg 
120eecc4800SJohannes Berg 	trace_drv_resume(local);
121eecc4800SJohannes Berg 	ret = local->ops->resume(&local->hw);
122eecc4800SJohannes Berg 	trace_drv_return_int(local, ret);
123eecc4800SJohannes Berg 	return ret;
124eecc4800SJohannes Berg }
1256d52563fSJohannes Berg 
1266d52563fSJohannes Berg static inline void drv_set_wakeup(struct ieee80211_local *local,
1276d52563fSJohannes Berg 				  bool enabled)
1286d52563fSJohannes Berg {
1296d52563fSJohannes Berg 	might_sleep();
1306d52563fSJohannes Berg 
1316d52563fSJohannes Berg 	if (!local->ops->set_wakeup)
1326d52563fSJohannes Berg 		return;
1336d52563fSJohannes Berg 
1346d52563fSJohannes Berg 	trace_drv_set_wakeup(local, enabled);
1356d52563fSJohannes Berg 	local->ops->set_wakeup(&local->hw, enabled);
1366d52563fSJohannes Berg 	trace_drv_return_void(local);
1376d52563fSJohannes Berg }
138eecc4800SJohannes Berg #endif
139eecc4800SJohannes Berg 
14024487981SJohannes Berg static inline int drv_add_interface(struct ieee80211_local *local,
1417b7eab6fSJohannes Berg 				    struct ieee80211_sub_if_data *sdata)
14224487981SJohannes Berg {
143e1781ed3SKalle Valo 	int ret;
144e1781ed3SKalle Valo 
145e1781ed3SKalle Valo 	might_sleep();
146e1781ed3SKalle Valo 
1477b7eab6fSJohannes Berg 	if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1484b6f1dd6SJohannes Berg 		    (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
14931eba5bcSFelix Fietkau 		     !(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF) &&
15031eba5bcSFelix Fietkau 		     !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))))
1517b7eab6fSJohannes Berg 		return -EINVAL;
1527b7eab6fSJohannes Berg 
1537b7eab6fSJohannes Berg 	trace_drv_add_interface(local, sdata);
1547b7eab6fSJohannes Berg 	ret = local->ops->add_interface(&local->hw, &sdata->vif);
1554efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
1567b7eab6fSJohannes Berg 
1577b7eab6fSJohannes Berg 	if (ret == 0)
1587b7eab6fSJohannes Berg 		sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
1597b7eab6fSJohannes Berg 
1600a2b8bb2SJohannes Berg 	return ret;
16124487981SJohannes Berg }
16224487981SJohannes Berg 
16334d4bc4dSJohannes Berg static inline int drv_change_interface(struct ieee80211_local *local,
16434d4bc4dSJohannes Berg 				       struct ieee80211_sub_if_data *sdata,
1652ca27bcfSJohannes Berg 				       enum nl80211_iftype type, bool p2p)
16634d4bc4dSJohannes Berg {
16734d4bc4dSJohannes Berg 	int ret;
16834d4bc4dSJohannes Berg 
16934d4bc4dSJohannes Berg 	might_sleep();
17034d4bc4dSJohannes Berg 
171f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
172f6837ba8SJohannes Berg 		return -EIO;
1737b7eab6fSJohannes Berg 
1742ca27bcfSJohannes Berg 	trace_drv_change_interface(local, sdata, type, p2p);
1752ca27bcfSJohannes Berg 	ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
17634d4bc4dSJohannes Berg 	trace_drv_return_int(local, ret);
17734d4bc4dSJohannes Berg 	return ret;
17834d4bc4dSJohannes Berg }
17934d4bc4dSJohannes Berg 
18024487981SJohannes Berg static inline void drv_remove_interface(struct ieee80211_local *local,
1817b7eab6fSJohannes Berg 					struct ieee80211_sub_if_data *sdata)
18224487981SJohannes Berg {
183e1781ed3SKalle Valo 	might_sleep();
184e1781ed3SKalle Valo 
185f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
186f6837ba8SJohannes Berg 		return;
1877b7eab6fSJohannes Berg 
1887b7eab6fSJohannes Berg 	trace_drv_remove_interface(local, sdata);
1897b7eab6fSJohannes Berg 	local->ops->remove_interface(&local->hw, &sdata->vif);
1907b7eab6fSJohannes Berg 	sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
1914efc76bdSJohannes Berg 	trace_drv_return_void(local);
19224487981SJohannes Berg }
19324487981SJohannes Berg 
19424487981SJohannes Berg static inline int drv_config(struct ieee80211_local *local, u32 changed)
19524487981SJohannes Berg {
196e1781ed3SKalle Valo 	int ret;
197e1781ed3SKalle Valo 
198e1781ed3SKalle Valo 	might_sleep();
199e1781ed3SKalle Valo 
2004efc76bdSJohannes Berg 	trace_drv_config(local, changed);
201e1781ed3SKalle Valo 	ret = local->ops->config(&local->hw, changed);
2024efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
2030a2b8bb2SJohannes Berg 	return ret;
20424487981SJohannes Berg }
20524487981SJohannes Berg 
20624487981SJohannes Berg static inline void drv_bss_info_changed(struct ieee80211_local *local,
20712375ef9SJohannes Berg 					struct ieee80211_sub_if_data *sdata,
20824487981SJohannes Berg 					struct ieee80211_bss_conf *info,
20924487981SJohannes Berg 					u32 changed)
21024487981SJohannes Berg {
211e1781ed3SKalle Valo 	might_sleep();
212e1781ed3SKalle Valo 
2135bbe754dSJohannes Berg 	if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
214b8dc1a35SJohannes Berg 				    BSS_CHANGED_BEACON_ENABLED) &&
215b8dc1a35SJohannes Berg 			 sdata->vif.type != NL80211_IFTYPE_AP &&
216b8dc1a35SJohannes Berg 			 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
217239281f8SRostislav Lisovy 			 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
218239281f8SRostislav Lisovy 			 sdata->vif.type != NL80211_IFTYPE_OCB))
2195bbe754dSJohannes Berg 		return;
2205bbe754dSJohannes Berg 
2215bbe754dSJohannes Berg 	if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
2225bbe754dSJohannes Berg 			 sdata->vif.type == NL80211_IFTYPE_MONITOR))
2235bbe754dSJohannes Berg 		return;
224b8dc1a35SJohannes Berg 
225f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
226f6837ba8SJohannes Berg 		return;
2277b7eab6fSJohannes Berg 
2284efc76bdSJohannes Berg 	trace_drv_bss_info_changed(local, sdata, info, changed);
22924487981SJohannes Berg 	if (local->ops->bss_info_changed)
23012375ef9SJohannes Berg 		local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
2314efc76bdSJohannes Berg 	trace_drv_return_void(local);
23224487981SJohannes Berg }
23324487981SJohannes Berg 
2343ac64beeSJohannes Berg static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
23522bedad3SJiri Pirko 					struct netdev_hw_addr_list *mc_list)
23624487981SJohannes Berg {
2373ac64beeSJohannes Berg 	u64 ret = 0;
2383ac64beeSJohannes Berg 
2394efc76bdSJohannes Berg 	trace_drv_prepare_multicast(local, mc_list->count);
2404efc76bdSJohannes Berg 
2413ac64beeSJohannes Berg 	if (local->ops->prepare_multicast)
24222bedad3SJiri Pirko 		ret = local->ops->prepare_multicast(&local->hw, mc_list);
2433ac64beeSJohannes Berg 
2444efc76bdSJohannes Berg 	trace_drv_return_u64(local, ret);
2453ac64beeSJohannes Berg 
2463ac64beeSJohannes Berg 	return ret;
2473ac64beeSJohannes Berg }
2483ac64beeSJohannes Berg 
2493ac64beeSJohannes Berg static inline void drv_configure_filter(struct ieee80211_local *local,
2503ac64beeSJohannes Berg 					unsigned int changed_flags,
2513ac64beeSJohannes Berg 					unsigned int *total_flags,
2523ac64beeSJohannes Berg 					u64 multicast)
2533ac64beeSJohannes Berg {
2543ac64beeSJohannes Berg 	might_sleep();
2553ac64beeSJohannes Berg 
2560a2b8bb2SJohannes Berg 	trace_drv_configure_filter(local, changed_flags, total_flags,
2573ac64beeSJohannes Berg 				   multicast);
2584efc76bdSJohannes Berg 	local->ops->configure_filter(&local->hw, changed_flags, total_flags,
2594efc76bdSJohannes Berg 				     multicast);
2604efc76bdSJohannes Berg 	trace_drv_return_void(local);
26124487981SJohannes Berg }
26224487981SJohannes Berg 
26324487981SJohannes Berg static inline int drv_set_tim(struct ieee80211_local *local,
26424487981SJohannes Berg 			      struct ieee80211_sta *sta, bool set)
26524487981SJohannes Berg {
2660a2b8bb2SJohannes Berg 	int ret = 0;
2674efc76bdSJohannes Berg 	trace_drv_set_tim(local, sta, set);
26824487981SJohannes Berg 	if (local->ops->set_tim)
2690a2b8bb2SJohannes Berg 		ret = local->ops->set_tim(&local->hw, sta, set);
2704efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
2710a2b8bb2SJohannes Berg 	return ret;
27224487981SJohannes Berg }
27324487981SJohannes Berg 
27424487981SJohannes Berg static inline int drv_set_key(struct ieee80211_local *local,
27512375ef9SJohannes Berg 			      enum set_key_cmd cmd,
27612375ef9SJohannes Berg 			      struct ieee80211_sub_if_data *sdata,
27724487981SJohannes Berg 			      struct ieee80211_sta *sta,
27824487981SJohannes Berg 			      struct ieee80211_key_conf *key)
27924487981SJohannes Berg {
280e1781ed3SKalle Valo 	int ret;
281e1781ed3SKalle Valo 
282e1781ed3SKalle Valo 	might_sleep();
283e1781ed3SKalle Valo 
284077f4939SJohannes Berg 	sdata = get_bss_sdata(sdata);
285f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
286f6837ba8SJohannes Berg 		return -EIO;
2877b7eab6fSJohannes Berg 
2884efc76bdSJohannes Berg 	trace_drv_set_key(local, cmd, sdata, sta, key);
289e1781ed3SKalle Valo 	ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
2904efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
2910a2b8bb2SJohannes Berg 	return ret;
29224487981SJohannes Berg }
29324487981SJohannes Berg 
29424487981SJohannes Berg static inline void drv_update_tkip_key(struct ieee80211_local *local,
295b3fbdcf4SJohannes Berg 				       struct ieee80211_sub_if_data *sdata,
29624487981SJohannes Berg 				       struct ieee80211_key_conf *conf,
297b3fbdcf4SJohannes Berg 				       struct sta_info *sta, u32 iv32,
29824487981SJohannes Berg 				       u16 *phase1key)
29924487981SJohannes Berg {
300b3fbdcf4SJohannes Berg 	struct ieee80211_sta *ista = NULL;
301b3fbdcf4SJohannes Berg 
302b3fbdcf4SJohannes Berg 	if (sta)
303b3fbdcf4SJohannes Berg 		ista = &sta->sta;
304b3fbdcf4SJohannes Berg 
305077f4939SJohannes Berg 	sdata = get_bss_sdata(sdata);
306f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
307f6837ba8SJohannes Berg 		return;
3087b7eab6fSJohannes Berg 
3094efc76bdSJohannes Berg 	trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
31024487981SJohannes Berg 	if (local->ops->update_tkip_key)
311b3fbdcf4SJohannes Berg 		local->ops->update_tkip_key(&local->hw, &sdata->vif, conf,
312b3fbdcf4SJohannes Berg 					    ista, iv32, phase1key);
3134efc76bdSJohannes Berg 	trace_drv_return_void(local);
31424487981SJohannes Berg }
31524487981SJohannes Berg 
31624487981SJohannes Berg static inline int drv_hw_scan(struct ieee80211_local *local,
317a060bbfeSJohannes Berg 			      struct ieee80211_sub_if_data *sdata,
318c56ef672SDavid Spinadel 			      struct ieee80211_scan_request *req)
31924487981SJohannes Berg {
320e1781ed3SKalle Valo 	int ret;
321e1781ed3SKalle Valo 
322e1781ed3SKalle Valo 	might_sleep();
323e1781ed3SKalle Valo 
324f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
325f6837ba8SJohannes Berg 		return -EIO;
3267b7eab6fSJohannes Berg 
32779f460caSLuciano Coelho 	trace_drv_hw_scan(local, sdata);
328a060bbfeSJohannes Berg 	ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
3294efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
3300a2b8bb2SJohannes Berg 	return ret;
33124487981SJohannes Berg }
33224487981SJohannes Berg 
333b856439bSEliad Peller static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
334b856439bSEliad Peller 				      struct ieee80211_sub_if_data *sdata)
335b856439bSEliad Peller {
336b856439bSEliad Peller 	might_sleep();
337b856439bSEliad Peller 
338f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
339f6837ba8SJohannes Berg 		return;
3407b7eab6fSJohannes Berg 
341b856439bSEliad Peller 	trace_drv_cancel_hw_scan(local, sdata);
342b856439bSEliad Peller 	local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
343b856439bSEliad Peller 	trace_drv_return_void(local);
344b856439bSEliad Peller }
345b856439bSEliad Peller 
34679f460caSLuciano Coelho static inline int
34779f460caSLuciano Coelho drv_sched_scan_start(struct ieee80211_local *local,
34879f460caSLuciano Coelho 		     struct ieee80211_sub_if_data *sdata,
34979f460caSLuciano Coelho 		     struct cfg80211_sched_scan_request *req,
350633e2713SDavid Spinadel 		     struct ieee80211_scan_ies *ies)
35179f460caSLuciano Coelho {
35279f460caSLuciano Coelho 	int ret;
35379f460caSLuciano Coelho 
35479f460caSLuciano Coelho 	might_sleep();
35579f460caSLuciano Coelho 
356f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
357f6837ba8SJohannes Berg 		return -EIO;
3587b7eab6fSJohannes Berg 
35979f460caSLuciano Coelho 	trace_drv_sched_scan_start(local, sdata);
36079f460caSLuciano Coelho 	ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
36179f460caSLuciano Coelho 					      req, ies);
36279f460caSLuciano Coelho 	trace_drv_return_int(local, ret);
36379f460caSLuciano Coelho 	return ret;
36479f460caSLuciano Coelho }
36579f460caSLuciano Coelho 
36637e3308cSJohannes Berg static inline int drv_sched_scan_stop(struct ieee80211_local *local,
36779f460caSLuciano Coelho 				      struct ieee80211_sub_if_data *sdata)
36879f460caSLuciano Coelho {
36937e3308cSJohannes Berg 	int ret;
37037e3308cSJohannes Berg 
37179f460caSLuciano Coelho 	might_sleep();
37279f460caSLuciano Coelho 
373f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
374f6837ba8SJohannes Berg 		return -EIO;
3757b7eab6fSJohannes Berg 
37679f460caSLuciano Coelho 	trace_drv_sched_scan_stop(local, sdata);
37737e3308cSJohannes Berg 	ret = local->ops->sched_scan_stop(&local->hw, &sdata->vif);
37837e3308cSJohannes Berg 	trace_drv_return_int(local, ret);
37937e3308cSJohannes Berg 
38037e3308cSJohannes Berg 	return ret;
38179f460caSLuciano Coelho }
38279f460caSLuciano Coelho 
383a344d677SJohannes Berg static inline void drv_sw_scan_start(struct ieee80211_local *local,
384a344d677SJohannes Berg 				     struct ieee80211_sub_if_data *sdata,
385a344d677SJohannes Berg 				     const u8 *mac_addr)
38624487981SJohannes Berg {
387e1781ed3SKalle Valo 	might_sleep();
388e1781ed3SKalle Valo 
389a344d677SJohannes Berg 	trace_drv_sw_scan_start(local, sdata, mac_addr);
39024487981SJohannes Berg 	if (local->ops->sw_scan_start)
391a344d677SJohannes Berg 		local->ops->sw_scan_start(&local->hw, &sdata->vif, mac_addr);
3924efc76bdSJohannes Berg 	trace_drv_return_void(local);
39324487981SJohannes Berg }
39424487981SJohannes Berg 
395a344d677SJohannes Berg static inline void drv_sw_scan_complete(struct ieee80211_local *local,
396a344d677SJohannes Berg 					struct ieee80211_sub_if_data *sdata)
39724487981SJohannes Berg {
398e1781ed3SKalle Valo 	might_sleep();
399e1781ed3SKalle Valo 
400a344d677SJohannes Berg 	trace_drv_sw_scan_complete(local, sdata);
40124487981SJohannes Berg 	if (local->ops->sw_scan_complete)
402a344d677SJohannes Berg 		local->ops->sw_scan_complete(&local->hw, &sdata->vif);
4034efc76bdSJohannes Berg 	trace_drv_return_void(local);
40424487981SJohannes Berg }
40524487981SJohannes Berg 
40624487981SJohannes Berg static inline int drv_get_stats(struct ieee80211_local *local,
40724487981SJohannes Berg 				struct ieee80211_low_level_stats *stats)
40824487981SJohannes Berg {
4090a2b8bb2SJohannes Berg 	int ret = -EOPNOTSUPP;
4100a2b8bb2SJohannes Berg 
411e1781ed3SKalle Valo 	might_sleep();
412e1781ed3SKalle Valo 
4130a2b8bb2SJohannes Berg 	if (local->ops->get_stats)
4140a2b8bb2SJohannes Berg 		ret = local->ops->get_stats(&local->hw, stats);
4150a2b8bb2SJohannes Berg 	trace_drv_get_stats(local, stats, ret);
4160a2b8bb2SJohannes Berg 
4170a2b8bb2SJohannes Berg 	return ret;
41824487981SJohannes Berg }
41924487981SJohannes Berg 
42024487981SJohannes Berg static inline void drv_get_tkip_seq(struct ieee80211_local *local,
42124487981SJohannes Berg 				    u8 hw_key_idx, u32 *iv32, u16 *iv16)
42224487981SJohannes Berg {
42324487981SJohannes Berg 	if (local->ops->get_tkip_seq)
42424487981SJohannes Berg 		local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16);
4250a2b8bb2SJohannes Berg 	trace_drv_get_tkip_seq(local, hw_key_idx, iv32, iv16);
42624487981SJohannes Berg }
42724487981SJohannes Berg 
428f23a4780SArik Nemtsov static inline int drv_set_frag_threshold(struct ieee80211_local *local,
429f23a4780SArik Nemtsov 					u32 value)
430f23a4780SArik Nemtsov {
431f23a4780SArik Nemtsov 	int ret = 0;
432f23a4780SArik Nemtsov 
433f23a4780SArik Nemtsov 	might_sleep();
434f23a4780SArik Nemtsov 
435f23a4780SArik Nemtsov 	trace_drv_set_frag_threshold(local, value);
436f23a4780SArik Nemtsov 	if (local->ops->set_frag_threshold)
437f23a4780SArik Nemtsov 		ret = local->ops->set_frag_threshold(&local->hw, value);
438f23a4780SArik Nemtsov 	trace_drv_return_int(local, ret);
439f23a4780SArik Nemtsov 	return ret;
440f23a4780SArik Nemtsov }
441f23a4780SArik Nemtsov 
44224487981SJohannes Berg static inline int drv_set_rts_threshold(struct ieee80211_local *local,
44324487981SJohannes Berg 					u32 value)
44424487981SJohannes Berg {
4450a2b8bb2SJohannes Berg 	int ret = 0;
446e1781ed3SKalle Valo 
447e1781ed3SKalle Valo 	might_sleep();
448e1781ed3SKalle Valo 
4494efc76bdSJohannes Berg 	trace_drv_set_rts_threshold(local, value);
45024487981SJohannes Berg 	if (local->ops->set_rts_threshold)
4510a2b8bb2SJohannes Berg 		ret = local->ops->set_rts_threshold(&local->hw, value);
4524efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
4530a2b8bb2SJohannes Berg 	return ret;
45424487981SJohannes Berg }
45524487981SJohannes Berg 
456310bc676SLukáš Turek static inline int drv_set_coverage_class(struct ieee80211_local *local,
457a4bcaf55SLorenzo Bianconi 					 s16 value)
458310bc676SLukáš Turek {
459310bc676SLukáš Turek 	int ret = 0;
460310bc676SLukáš Turek 	might_sleep();
461310bc676SLukáš Turek 
4624efc76bdSJohannes Berg 	trace_drv_set_coverage_class(local, value);
463310bc676SLukáš Turek 	if (local->ops->set_coverage_class)
464310bc676SLukáš Turek 		local->ops->set_coverage_class(&local->hw, value);
465310bc676SLukáš Turek 	else
466310bc676SLukáš Turek 		ret = -EOPNOTSUPP;
467310bc676SLukáš Turek 
4684efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
469310bc676SLukáš Turek 	return ret;
470310bc676SLukáš Turek }
471310bc676SLukáš Turek 
47224487981SJohannes Berg static inline void drv_sta_notify(struct ieee80211_local *local,
47312375ef9SJohannes Berg 				  struct ieee80211_sub_if_data *sdata,
47424487981SJohannes Berg 				  enum sta_notify_cmd cmd,
47524487981SJohannes Berg 				  struct ieee80211_sta *sta)
47624487981SJohannes Berg {
477bc192f89SFelix Fietkau 	sdata = get_bss_sdata(sdata);
478f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
479f6837ba8SJohannes Berg 		return;
4807b7eab6fSJohannes Berg 
4814efc76bdSJohannes Berg 	trace_drv_sta_notify(local, sdata, cmd, sta);
48224487981SJohannes Berg 	if (local->ops->sta_notify)
48312375ef9SJohannes Berg 		local->ops->sta_notify(&local->hw, &sdata->vif, cmd, sta);
4844efc76bdSJohannes Berg 	trace_drv_return_void(local);
48524487981SJohannes Berg }
48624487981SJohannes Berg 
48734e89507SJohannes Berg static inline int drv_sta_add(struct ieee80211_local *local,
48834e89507SJohannes Berg 			      struct ieee80211_sub_if_data *sdata,
48934e89507SJohannes Berg 			      struct ieee80211_sta *sta)
49034e89507SJohannes Berg {
49134e89507SJohannes Berg 	int ret = 0;
49234e89507SJohannes Berg 
49334e89507SJohannes Berg 	might_sleep();
49434e89507SJohannes Berg 
495bc192f89SFelix Fietkau 	sdata = get_bss_sdata(sdata);
496f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
497f6837ba8SJohannes Berg 		return -EIO;
4987b7eab6fSJohannes Berg 
4994efc76bdSJohannes Berg 	trace_drv_sta_add(local, sdata, sta);
50034e89507SJohannes Berg 	if (local->ops->sta_add)
50134e89507SJohannes Berg 		ret = local->ops->sta_add(&local->hw, &sdata->vif, sta);
50234e89507SJohannes Berg 
5034efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
50434e89507SJohannes Berg 
50534e89507SJohannes Berg 	return ret;
50634e89507SJohannes Berg }
50734e89507SJohannes Berg 
50834e89507SJohannes Berg static inline void drv_sta_remove(struct ieee80211_local *local,
50934e89507SJohannes Berg 				  struct ieee80211_sub_if_data *sdata,
51034e89507SJohannes Berg 				  struct ieee80211_sta *sta)
51134e89507SJohannes Berg {
51234e89507SJohannes Berg 	might_sleep();
51334e89507SJohannes Berg 
514bc192f89SFelix Fietkau 	sdata = get_bss_sdata(sdata);
515f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
516f6837ba8SJohannes Berg 		return;
5177b7eab6fSJohannes Berg 
5184efc76bdSJohannes Berg 	trace_drv_sta_remove(local, sdata, sta);
51934e89507SJohannes Berg 	if (local->ops->sta_remove)
52034e89507SJohannes Berg 		local->ops->sta_remove(&local->hw, &sdata->vif, sta);
52134e89507SJohannes Berg 
5224efc76bdSJohannes Berg 	trace_drv_return_void(local);
52334e89507SJohannes Berg }
52434e89507SJohannes Berg 
52577d2ece6SSujith Manoharan #ifdef CONFIG_MAC80211_DEBUGFS
52677d2ece6SSujith Manoharan static inline void drv_sta_add_debugfs(struct ieee80211_local *local,
52777d2ece6SSujith Manoharan 				       struct ieee80211_sub_if_data *sdata,
52877d2ece6SSujith Manoharan 				       struct ieee80211_sta *sta,
52977d2ece6SSujith Manoharan 				       struct dentry *dir)
53077d2ece6SSujith Manoharan {
53177d2ece6SSujith Manoharan 	might_sleep();
53277d2ece6SSujith Manoharan 
53377d2ece6SSujith Manoharan 	sdata = get_bss_sdata(sdata);
534f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
535f6837ba8SJohannes Berg 		return;
53677d2ece6SSujith Manoharan 
53777d2ece6SSujith Manoharan 	if (local->ops->sta_add_debugfs)
53877d2ece6SSujith Manoharan 		local->ops->sta_add_debugfs(&local->hw, &sdata->vif,
53977d2ece6SSujith Manoharan 					    sta, dir);
54077d2ece6SSujith Manoharan }
54177d2ece6SSujith Manoharan 
54277d2ece6SSujith Manoharan static inline void drv_sta_remove_debugfs(struct ieee80211_local *local,
54377d2ece6SSujith Manoharan 					  struct ieee80211_sub_if_data *sdata,
54477d2ece6SSujith Manoharan 					  struct ieee80211_sta *sta,
54577d2ece6SSujith Manoharan 					  struct dentry *dir)
54677d2ece6SSujith Manoharan {
54777d2ece6SSujith Manoharan 	might_sleep();
54877d2ece6SSujith Manoharan 
54977d2ece6SSujith Manoharan 	sdata = get_bss_sdata(sdata);
55077d2ece6SSujith Manoharan 	check_sdata_in_driver(sdata);
55177d2ece6SSujith Manoharan 
55277d2ece6SSujith Manoharan 	if (local->ops->sta_remove_debugfs)
55377d2ece6SSujith Manoharan 		local->ops->sta_remove_debugfs(&local->hw, &sdata->vif,
55477d2ece6SSujith Manoharan 					       sta, dir);
55577d2ece6SSujith Manoharan }
55677d2ece6SSujith Manoharan #endif
55777d2ece6SSujith Manoharan 
5586a9d1b91SJohannes Berg static inline void drv_sta_pre_rcu_remove(struct ieee80211_local *local,
5596a9d1b91SJohannes Berg 					  struct ieee80211_sub_if_data *sdata,
5606a9d1b91SJohannes Berg 					  struct sta_info *sta)
5616a9d1b91SJohannes Berg {
5626a9d1b91SJohannes Berg 	might_sleep();
5636a9d1b91SJohannes Berg 
5646a9d1b91SJohannes Berg 	sdata = get_bss_sdata(sdata);
565f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
566f6837ba8SJohannes Berg 		return;
5676a9d1b91SJohannes Berg 
5686a9d1b91SJohannes Berg 	trace_drv_sta_pre_rcu_remove(local, sdata, &sta->sta);
5696a9d1b91SJohannes Berg 	if (local->ops->sta_pre_rcu_remove)
5706a9d1b91SJohannes Berg 		local->ops->sta_pre_rcu_remove(&local->hw, &sdata->vif,
5716a9d1b91SJohannes Berg 					       &sta->sta);
5726a9d1b91SJohannes Berg 	trace_drv_return_void(local);
5736a9d1b91SJohannes Berg }
5746a9d1b91SJohannes Berg 
575f09603a2SJohannes Berg static inline __must_check
576f09603a2SJohannes Berg int drv_sta_state(struct ieee80211_local *local,
577f09603a2SJohannes Berg 		  struct ieee80211_sub_if_data *sdata,
578f09603a2SJohannes Berg 		  struct sta_info *sta,
579f09603a2SJohannes Berg 		  enum ieee80211_sta_state old_state,
580f09603a2SJohannes Berg 		  enum ieee80211_sta_state new_state)
581f09603a2SJohannes Berg {
582f09603a2SJohannes Berg 	int ret = 0;
583f09603a2SJohannes Berg 
584f09603a2SJohannes Berg 	might_sleep();
585f09603a2SJohannes Berg 
586f09603a2SJohannes Berg 	sdata = get_bss_sdata(sdata);
587f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
588f6837ba8SJohannes Berg 		return -EIO;
589f09603a2SJohannes Berg 
590f09603a2SJohannes Berg 	trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
591a4ec45a4SJohannes Berg 	if (local->ops->sta_state) {
592f09603a2SJohannes Berg 		ret = local->ops->sta_state(&local->hw, &sdata->vif, &sta->sta,
593f09603a2SJohannes Berg 					    old_state, new_state);
594a4ec45a4SJohannes Berg 	} else if (old_state == IEEE80211_STA_AUTH &&
595a4ec45a4SJohannes Berg 		   new_state == IEEE80211_STA_ASSOC) {
596a4ec45a4SJohannes Berg 		ret = drv_sta_add(local, sdata, &sta->sta);
597a4ec45a4SJohannes Berg 		if (ret == 0)
598a4ec45a4SJohannes Berg 			sta->uploaded = true;
599a4ec45a4SJohannes Berg 	} else if (old_state == IEEE80211_STA_ASSOC &&
600a4ec45a4SJohannes Berg 		   new_state == IEEE80211_STA_AUTH) {
601a4ec45a4SJohannes Berg 		drv_sta_remove(local, sdata, &sta->sta);
602a4ec45a4SJohannes Berg 	}
603f09603a2SJohannes Berg 	trace_drv_return_int(local, ret);
604f09603a2SJohannes Berg 	return ret;
605f09603a2SJohannes Berg }
606f09603a2SJohannes Berg 
6078f727ef3SJohannes Berg static inline void drv_sta_rc_update(struct ieee80211_local *local,
6088f727ef3SJohannes Berg 				     struct ieee80211_sub_if_data *sdata,
6098f727ef3SJohannes Berg 				     struct ieee80211_sta *sta, u32 changed)
6108f727ef3SJohannes Berg {
6118f727ef3SJohannes Berg 	sdata = get_bss_sdata(sdata);
612f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
613f6837ba8SJohannes Berg 		return;
6148f727ef3SJohannes Berg 
615e687f61eSAntonio Quartulli 	WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
616f68d776aSThomas Pedersen 		(sdata->vif.type != NL80211_IFTYPE_ADHOC &&
617f68d776aSThomas Pedersen 		 sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
618e687f61eSAntonio Quartulli 
6198f727ef3SJohannes Berg 	trace_drv_sta_rc_update(local, sdata, sta, changed);
6208f727ef3SJohannes Berg 	if (local->ops->sta_rc_update)
6218f727ef3SJohannes Berg 		local->ops->sta_rc_update(&local->hw, &sdata->vif,
6228f727ef3SJohannes Berg 					  sta, changed);
6238f727ef3SJohannes Berg 
6248f727ef3SJohannes Berg 	trace_drv_return_void(local);
6258f727ef3SJohannes Berg }
6268f727ef3SJohannes Berg 
627f815e2b3SJohannes Berg static inline void drv_sta_rate_tbl_update(struct ieee80211_local *local,
628f815e2b3SJohannes Berg 					   struct ieee80211_sub_if_data *sdata,
629f815e2b3SJohannes Berg 					   struct ieee80211_sta *sta)
630f815e2b3SJohannes Berg {
631f815e2b3SJohannes Berg 	sdata = get_bss_sdata(sdata);
632f815e2b3SJohannes Berg 	if (!check_sdata_in_driver(sdata))
633f815e2b3SJohannes Berg 		return;
634f815e2b3SJohannes Berg 
635f815e2b3SJohannes Berg 	trace_drv_sta_rate_tbl_update(local, sdata, sta);
636f815e2b3SJohannes Berg 	if (local->ops->sta_rate_tbl_update)
637f815e2b3SJohannes Berg 		local->ops->sta_rate_tbl_update(&local->hw, &sdata->vif, sta);
638f815e2b3SJohannes Berg 
639f815e2b3SJohannes Berg 	trace_drv_return_void(local);
640f815e2b3SJohannes Berg }
641f815e2b3SJohannes Berg 
6422b9a7e1bSJohannes Berg static inline void drv_sta_statistics(struct ieee80211_local *local,
6432b9a7e1bSJohannes Berg 				      struct ieee80211_sub_if_data *sdata,
6442b9a7e1bSJohannes Berg 				      struct ieee80211_sta *sta,
6452b9a7e1bSJohannes Berg 				      struct station_info *sinfo)
6462b9a7e1bSJohannes Berg {
6472b9a7e1bSJohannes Berg 	sdata = get_bss_sdata(sdata);
6482b9a7e1bSJohannes Berg 	if (!check_sdata_in_driver(sdata))
6492b9a7e1bSJohannes Berg 		return;
6502b9a7e1bSJohannes Berg 
6512b9a7e1bSJohannes Berg 	trace_drv_sta_statistics(local, sdata, sta);
6522b9a7e1bSJohannes Berg 	if (local->ops->sta_statistics)
6532b9a7e1bSJohannes Berg 		local->ops->sta_statistics(&local->hw, &sdata->vif, sta, sinfo);
6542b9a7e1bSJohannes Berg 	trace_drv_return_void(local);
6552b9a7e1bSJohannes Berg }
6562b9a7e1bSJohannes Berg 
657f6f3def3SEliad Peller static inline int drv_conf_tx(struct ieee80211_local *local,
658a3304b0aSJohannes Berg 			      struct ieee80211_sub_if_data *sdata, u16 ac,
65924487981SJohannes Berg 			      const struct ieee80211_tx_queue_params *params)
66024487981SJohannes Berg {
6610a2b8bb2SJohannes Berg 	int ret = -EOPNOTSUPP;
662e1781ed3SKalle Valo 
663e1781ed3SKalle Valo 	might_sleep();
664e1781ed3SKalle Valo 
665f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
666f6837ba8SJohannes Berg 		return -EIO;
6677b7eab6fSJohannes Berg 
668f409079bSJohannes Berg 	if (WARN_ONCE(params->cw_min == 0 ||
669f409079bSJohannes Berg 		      params->cw_min > params->cw_max,
670f409079bSJohannes Berg 		      "%s: invalid CW_min/CW_max: %d/%d\n",
671f409079bSJohannes Berg 		      sdata->name, params->cw_min, params->cw_max))
672f409079bSJohannes Berg 		return -EINVAL;
673f409079bSJohannes Berg 
674a3304b0aSJohannes Berg 	trace_drv_conf_tx(local, sdata, ac, params);
67524487981SJohannes Berg 	if (local->ops->conf_tx)
6768a3a3c85SEliad Peller 		ret = local->ops->conf_tx(&local->hw, &sdata->vif,
677a3304b0aSJohannes Berg 					  ac, params);
6784efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
6790a2b8bb2SJohannes Berg 	return ret;
68024487981SJohannes Berg }
68124487981SJohannes Berg 
68237a41b4aSEliad Peller static inline u64 drv_get_tsf(struct ieee80211_local *local,
68337a41b4aSEliad Peller 			      struct ieee80211_sub_if_data *sdata)
68424487981SJohannes Berg {
6850a2b8bb2SJohannes Berg 	u64 ret = -1ULL;
686e1781ed3SKalle Valo 
687e1781ed3SKalle Valo 	might_sleep();
688e1781ed3SKalle Valo 
689f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
690f6837ba8SJohannes Berg 		return ret;
6917b7eab6fSJohannes Berg 
69237a41b4aSEliad Peller 	trace_drv_get_tsf(local, sdata);
69324487981SJohannes Berg 	if (local->ops->get_tsf)
69437a41b4aSEliad Peller 		ret = local->ops->get_tsf(&local->hw, &sdata->vif);
6954efc76bdSJohannes Berg 	trace_drv_return_u64(local, ret);
6960a2b8bb2SJohannes Berg 	return ret;
69724487981SJohannes Berg }
69824487981SJohannes Berg 
69937a41b4aSEliad Peller static inline void drv_set_tsf(struct ieee80211_local *local,
70037a41b4aSEliad Peller 			       struct ieee80211_sub_if_data *sdata,
70137a41b4aSEliad Peller 			       u64 tsf)
70224487981SJohannes Berg {
703e1781ed3SKalle Valo 	might_sleep();
704e1781ed3SKalle Valo 
705f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
706f6837ba8SJohannes Berg 		return;
7077b7eab6fSJohannes Berg 
70837a41b4aSEliad Peller 	trace_drv_set_tsf(local, sdata, tsf);
70924487981SJohannes Berg 	if (local->ops->set_tsf)
71037a41b4aSEliad Peller 		local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
7114efc76bdSJohannes Berg 	trace_drv_return_void(local);
71224487981SJohannes Berg }
71324487981SJohannes Berg 
71437a41b4aSEliad Peller static inline void drv_reset_tsf(struct ieee80211_local *local,
71537a41b4aSEliad Peller 				 struct ieee80211_sub_if_data *sdata)
71624487981SJohannes Berg {
717e1781ed3SKalle Valo 	might_sleep();
718e1781ed3SKalle Valo 
719f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
720f6837ba8SJohannes Berg 		return;
7217b7eab6fSJohannes Berg 
72237a41b4aSEliad Peller 	trace_drv_reset_tsf(local, sdata);
72324487981SJohannes Berg 	if (local->ops->reset_tsf)
72437a41b4aSEliad Peller 		local->ops->reset_tsf(&local->hw, &sdata->vif);
7254efc76bdSJohannes Berg 	trace_drv_return_void(local);
72624487981SJohannes Berg }
72724487981SJohannes Berg 
72824487981SJohannes Berg static inline int drv_tx_last_beacon(struct ieee80211_local *local)
72924487981SJohannes Berg {
73002582e9bSMasanari Iida 	int ret = 0; /* default unsupported op for less congestion */
731e1781ed3SKalle Valo 
732e1781ed3SKalle Valo 	might_sleep();
733e1781ed3SKalle Valo 
7344efc76bdSJohannes Berg 	trace_drv_tx_last_beacon(local);
73524487981SJohannes Berg 	if (local->ops->tx_last_beacon)
7360a2b8bb2SJohannes Berg 		ret = local->ops->tx_last_beacon(&local->hw);
7374efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
7380a2b8bb2SJohannes Berg 	return ret;
73924487981SJohannes Berg }
74024487981SJohannes Berg 
74124487981SJohannes Berg static inline int drv_ampdu_action(struct ieee80211_local *local,
74212375ef9SJohannes Berg 				   struct ieee80211_sub_if_data *sdata,
74324487981SJohannes Berg 				   enum ieee80211_ampdu_mlme_action action,
74424487981SJohannes Berg 				   struct ieee80211_sta *sta, u16 tid,
7450b01f030SJohannes Berg 				   u16 *ssn, u8 buf_size)
74624487981SJohannes Berg {
7470a2b8bb2SJohannes Berg 	int ret = -EOPNOTSUPP;
748cfcdbde3SJohannes Berg 
749cfcdbde3SJohannes Berg 	might_sleep();
750cfcdbde3SJohannes Berg 
751bc192f89SFelix Fietkau 	sdata = get_bss_sdata(sdata);
752f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
753f6837ba8SJohannes Berg 		return -EIO;
7547b7eab6fSJohannes Berg 
7550b01f030SJohannes Berg 	trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size);
7564efc76bdSJohannes Berg 
75724487981SJohannes Berg 	if (local->ops->ampdu_action)
75812375ef9SJohannes Berg 		ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
7590b01f030SJohannes Berg 					       sta, tid, ssn, buf_size);
76085ad181eSJohannes Berg 
7614efc76bdSJohannes Berg 	trace_drv_return_int(local, ret);
7624efc76bdSJohannes Berg 
7630a2b8bb2SJohannes Berg 	return ret;
76424487981SJohannes Berg }
7651f87f7d3SJohannes Berg 
7661289723eSHolger Schurig static inline int drv_get_survey(struct ieee80211_local *local, int idx,
7671289723eSHolger Schurig 				struct survey_info *survey)
7681289723eSHolger Schurig {
7691289723eSHolger Schurig 	int ret = -EOPNOTSUPP;
770c466d4efSJohn W. Linville 
771c466d4efSJohn W. Linville 	trace_drv_get_survey(local, idx, survey);
772c466d4efSJohn W. Linville 
77335dd0509SHolger Schurig 	if (local->ops->get_survey)
7741289723eSHolger Schurig 		ret = local->ops->get_survey(&local->hw, idx, survey);
775c466d4efSJohn W. Linville 
776c466d4efSJohn W. Linville 	trace_drv_return_int(local, ret);
777c466d4efSJohn W. Linville 
7781289723eSHolger Schurig 	return ret;
7791289723eSHolger Schurig }
7801f87f7d3SJohannes Berg 
7811f87f7d3SJohannes Berg static inline void drv_rfkill_poll(struct ieee80211_local *local)
7821f87f7d3SJohannes Berg {
783e1781ed3SKalle Valo 	might_sleep();
784e1781ed3SKalle Valo 
7851f87f7d3SJohannes Berg 	if (local->ops->rfkill_poll)
7861f87f7d3SJohannes Berg 		local->ops->rfkill_poll(&local->hw);
7871f87f7d3SJohannes Berg }
788a80f7c0bSJohannes Berg 
78939ecc01dSJohannes Berg static inline void drv_flush(struct ieee80211_local *local,
79077be2c54SEmmanuel Grumbach 			     struct ieee80211_sub_if_data *sdata,
79139ecc01dSJohannes Berg 			     u32 queues, bool drop)
792a80f7c0bSJohannes Berg {
79377be2c54SEmmanuel Grumbach 	struct ieee80211_vif *vif = sdata ? &sdata->vif : NULL;
79477be2c54SEmmanuel Grumbach 
795e1781ed3SKalle Valo 	might_sleep();
796e1781ed3SKalle Valo 
797f6837ba8SJohannes Berg 	if (sdata && !check_sdata_in_driver(sdata))
798f6837ba8SJohannes Berg 		return;
79977be2c54SEmmanuel Grumbach 
80039ecc01dSJohannes Berg 	trace_drv_flush(local, queues, drop);
801a80f7c0bSJohannes Berg 	if (local->ops->flush)
80277be2c54SEmmanuel Grumbach 		local->ops->flush(&local->hw, vif, queues, drop);
8034efc76bdSJohannes Berg 	trace_drv_return_void(local);
804a80f7c0bSJohannes Berg }
8055ce6e438SJohannes Berg 
8065ce6e438SJohannes Berg static inline void drv_channel_switch(struct ieee80211_local *local,
8070f791eb4SLuciano Coelho 				      struct ieee80211_sub_if_data *sdata,
8085ce6e438SJohannes Berg 				      struct ieee80211_channel_switch *ch_switch)
8095ce6e438SJohannes Berg {
8105ce6e438SJohannes Berg 	might_sleep();
8115ce6e438SJohannes Berg 
8120f791eb4SLuciano Coelho 	trace_drv_channel_switch(local, sdata, ch_switch);
8130f791eb4SLuciano Coelho 	local->ops->channel_switch(&local->hw, &sdata->vif, ch_switch);
8144efc76bdSJohannes Berg 	trace_drv_return_void(local);
8155ce6e438SJohannes Berg }
8165ce6e438SJohannes Berg 
81715d96753SBruno Randolf 
81815d96753SBruno Randolf static inline int drv_set_antenna(struct ieee80211_local *local,
81915d96753SBruno Randolf 				  u32 tx_ant, u32 rx_ant)
82015d96753SBruno Randolf {
82115d96753SBruno Randolf 	int ret = -EOPNOTSUPP;
82215d96753SBruno Randolf 	might_sleep();
82315d96753SBruno Randolf 	if (local->ops->set_antenna)
82415d96753SBruno Randolf 		ret = local->ops->set_antenna(&local->hw, tx_ant, rx_ant);
82515d96753SBruno Randolf 	trace_drv_set_antenna(local, tx_ant, rx_ant, ret);
82615d96753SBruno Randolf 	return ret;
82715d96753SBruno Randolf }
82815d96753SBruno Randolf 
82915d96753SBruno Randolf static inline int drv_get_antenna(struct ieee80211_local *local,
83015d96753SBruno Randolf 				  u32 *tx_ant, u32 *rx_ant)
83115d96753SBruno Randolf {
83215d96753SBruno Randolf 	int ret = -EOPNOTSUPP;
83315d96753SBruno Randolf 	might_sleep();
83415d96753SBruno Randolf 	if (local->ops->get_antenna)
83515d96753SBruno Randolf 		ret = local->ops->get_antenna(&local->hw, tx_ant, rx_ant);
83615d96753SBruno Randolf 	trace_drv_get_antenna(local, *tx_ant, *rx_ant, ret);
83715d96753SBruno Randolf 	return ret;
83815d96753SBruno Randolf }
83915d96753SBruno Randolf 
84021f83589SJohannes Berg static inline int drv_remain_on_channel(struct ieee80211_local *local,
84149884568SEliad Peller 					struct ieee80211_sub_if_data *sdata,
84221f83589SJohannes Berg 					struct ieee80211_channel *chan,
843d339d5caSIlan Peer 					unsigned int duration,
844d339d5caSIlan Peer 					enum ieee80211_roc_type type)
84521f83589SJohannes Berg {
84621f83589SJohannes Berg 	int ret;
84721f83589SJohannes Berg 
84821f83589SJohannes Berg 	might_sleep();
84921f83589SJohannes Berg 
850d339d5caSIlan Peer 	trace_drv_remain_on_channel(local, sdata, chan, duration, type);
85149884568SEliad Peller 	ret = local->ops->remain_on_channel(&local->hw, &sdata->vif,
852d339d5caSIlan Peer 					    chan, duration, type);
85321f83589SJohannes Berg 	trace_drv_return_int(local, ret);
85421f83589SJohannes Berg 
85521f83589SJohannes Berg 	return ret;
85621f83589SJohannes Berg }
85721f83589SJohannes Berg 
85821f83589SJohannes Berg static inline int drv_cancel_remain_on_channel(struct ieee80211_local *local)
85921f83589SJohannes Berg {
86021f83589SJohannes Berg 	int ret;
86121f83589SJohannes Berg 
86221f83589SJohannes Berg 	might_sleep();
86321f83589SJohannes Berg 
86421f83589SJohannes Berg 	trace_drv_cancel_remain_on_channel(local);
86521f83589SJohannes Berg 	ret = local->ops->cancel_remain_on_channel(&local->hw);
86621f83589SJohannes Berg 	trace_drv_return_int(local, ret);
86721f83589SJohannes Berg 
86821f83589SJohannes Berg 	return ret;
86921f83589SJohannes Berg }
87021f83589SJohannes Berg 
87138c09159SJohn W. Linville static inline int drv_set_ringparam(struct ieee80211_local *local,
87238c09159SJohn W. Linville 				    u32 tx, u32 rx)
87338c09159SJohn W. Linville {
87438c09159SJohn W. Linville 	int ret = -ENOTSUPP;
87538c09159SJohn W. Linville 
87638c09159SJohn W. Linville 	might_sleep();
87738c09159SJohn W. Linville 
87838c09159SJohn W. Linville 	trace_drv_set_ringparam(local, tx, rx);
87938c09159SJohn W. Linville 	if (local->ops->set_ringparam)
88038c09159SJohn W. Linville 		ret = local->ops->set_ringparam(&local->hw, tx, rx);
88138c09159SJohn W. Linville 	trace_drv_return_int(local, ret);
88238c09159SJohn W. Linville 
88338c09159SJohn W. Linville 	return ret;
88438c09159SJohn W. Linville }
88538c09159SJohn W. Linville 
88638c09159SJohn W. Linville static inline void drv_get_ringparam(struct ieee80211_local *local,
88738c09159SJohn W. Linville 				     u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
88838c09159SJohn W. Linville {
88938c09159SJohn W. Linville 	might_sleep();
89038c09159SJohn W. Linville 
89138c09159SJohn W. Linville 	trace_drv_get_ringparam(local, tx, tx_max, rx, rx_max);
89238c09159SJohn W. Linville 	if (local->ops->get_ringparam)
89338c09159SJohn W. Linville 		local->ops->get_ringparam(&local->hw, tx, tx_max, rx, rx_max);
89438c09159SJohn W. Linville 	trace_drv_return_void(local);
89538c09159SJohn W. Linville }
89638c09159SJohn W. Linville 
897e8306f98SVivek Natarajan static inline bool drv_tx_frames_pending(struct ieee80211_local *local)
898e8306f98SVivek Natarajan {
899e8306f98SVivek Natarajan 	bool ret = false;
900e8306f98SVivek Natarajan 
901e8306f98SVivek Natarajan 	might_sleep();
902e8306f98SVivek Natarajan 
903e8306f98SVivek Natarajan 	trace_drv_tx_frames_pending(local);
904e8306f98SVivek Natarajan 	if (local->ops->tx_frames_pending)
905e8306f98SVivek Natarajan 		ret = local->ops->tx_frames_pending(&local->hw);
906e8306f98SVivek Natarajan 	trace_drv_return_bool(local, ret);
907e8306f98SVivek Natarajan 
908e8306f98SVivek Natarajan 	return ret;
909e8306f98SVivek Natarajan }
910bdbfd6b5SSujith Manoharan 
911bdbfd6b5SSujith Manoharan static inline int drv_set_bitrate_mask(struct ieee80211_local *local,
912bdbfd6b5SSujith Manoharan 				       struct ieee80211_sub_if_data *sdata,
913bdbfd6b5SSujith Manoharan 				       const struct cfg80211_bitrate_mask *mask)
914bdbfd6b5SSujith Manoharan {
915bdbfd6b5SSujith Manoharan 	int ret = -EOPNOTSUPP;
916bdbfd6b5SSujith Manoharan 
917bdbfd6b5SSujith Manoharan 	might_sleep();
918bdbfd6b5SSujith Manoharan 
919f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
920f6837ba8SJohannes Berg 		return -EIO;
9217b7eab6fSJohannes Berg 
922bdbfd6b5SSujith Manoharan 	trace_drv_set_bitrate_mask(local, sdata, mask);
923bdbfd6b5SSujith Manoharan 	if (local->ops->set_bitrate_mask)
924bdbfd6b5SSujith Manoharan 		ret = local->ops->set_bitrate_mask(&local->hw,
925bdbfd6b5SSujith Manoharan 						   &sdata->vif, mask);
926bdbfd6b5SSujith Manoharan 	trace_drv_return_int(local, ret);
927bdbfd6b5SSujith Manoharan 
928bdbfd6b5SSujith Manoharan 	return ret;
929bdbfd6b5SSujith Manoharan }
930bdbfd6b5SSujith Manoharan 
931c68f4b89SJohannes Berg static inline void drv_set_rekey_data(struct ieee80211_local *local,
932c68f4b89SJohannes Berg 				      struct ieee80211_sub_if_data *sdata,
933c68f4b89SJohannes Berg 				      struct cfg80211_gtk_rekey_data *data)
934c68f4b89SJohannes Berg {
935f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
936f6837ba8SJohannes Berg 		return;
9377b7eab6fSJohannes Berg 
938c68f4b89SJohannes Berg 	trace_drv_set_rekey_data(local, sdata, data);
939c68f4b89SJohannes Berg 	if (local->ops->set_rekey_data)
940c68f4b89SJohannes Berg 		local->ops->set_rekey_data(&local->hw, &sdata->vif, data);
941c68f4b89SJohannes Berg 	trace_drv_return_void(local);
942c68f4b89SJohannes Berg }
943c68f4b89SJohannes Berg 
944a8182929SEmmanuel Grumbach static inline void drv_event_callback(struct ieee80211_local *local,
945887da917SEmmanuel Grumbach 				      struct ieee80211_sub_if_data *sdata,
946a8182929SEmmanuel Grumbach 				      const struct ieee80211_event *event)
947615f7b9bSMeenakshi Venkataraman {
948a8182929SEmmanuel Grumbach 	trace_drv_event_callback(local, sdata, event);
949a8182929SEmmanuel Grumbach 	if (local->ops->event_callback)
950a8182929SEmmanuel Grumbach 		local->ops->event_callback(&local->hw, &sdata->vif, event);
951615f7b9bSMeenakshi Venkataraman 	trace_drv_return_void(local);
952615f7b9bSMeenakshi Venkataraman }
9534049e09aSJohannes Berg 
9544049e09aSJohannes Berg static inline void
9554049e09aSJohannes Berg drv_release_buffered_frames(struct ieee80211_local *local,
9564049e09aSJohannes Berg 			    struct sta_info *sta, u16 tids, int num_frames,
9574049e09aSJohannes Berg 			    enum ieee80211_frame_release_type reason,
9584049e09aSJohannes Berg 			    bool more_data)
9594049e09aSJohannes Berg {
9604049e09aSJohannes Berg 	trace_drv_release_buffered_frames(local, &sta->sta, tids, num_frames,
9614049e09aSJohannes Berg 					  reason, more_data);
9624049e09aSJohannes Berg 	if (local->ops->release_buffered_frames)
9634049e09aSJohannes Berg 		local->ops->release_buffered_frames(&local->hw, &sta->sta, tids,
9644049e09aSJohannes Berg 						    num_frames, reason,
9654049e09aSJohannes Berg 						    more_data);
9664049e09aSJohannes Berg 	trace_drv_return_void(local);
9674049e09aSJohannes Berg }
96840b96408SJohannes Berg 
96940b96408SJohannes Berg static inline void
97040b96408SJohannes Berg drv_allow_buffered_frames(struct ieee80211_local *local,
97140b96408SJohannes Berg 			  struct sta_info *sta, u16 tids, int num_frames,
97240b96408SJohannes Berg 			  enum ieee80211_frame_release_type reason,
97340b96408SJohannes Berg 			  bool more_data)
97440b96408SJohannes Berg {
97540b96408SJohannes Berg 	trace_drv_allow_buffered_frames(local, &sta->sta, tids, num_frames,
97640b96408SJohannes Berg 					reason, more_data);
97740b96408SJohannes Berg 	if (local->ops->allow_buffered_frames)
97840b96408SJohannes Berg 		local->ops->allow_buffered_frames(&local->hw, &sta->sta,
97940b96408SJohannes Berg 						  tids, num_frames, reason,
98040b96408SJohannes Berg 						  more_data);
98140b96408SJohannes Berg 	trace_drv_return_void(local);
98240b96408SJohannes Berg }
98366572cfcSVictor Goldenshtein 
984a1845fc7SJohannes Berg static inline void drv_mgd_prepare_tx(struct ieee80211_local *local,
985a1845fc7SJohannes Berg 				      struct ieee80211_sub_if_data *sdata)
986a1845fc7SJohannes Berg {
987a1845fc7SJohannes Berg 	might_sleep();
988a1845fc7SJohannes Berg 
989f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
990f6837ba8SJohannes Berg 		return;
991a1845fc7SJohannes Berg 	WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
992a1845fc7SJohannes Berg 
993a1845fc7SJohannes Berg 	trace_drv_mgd_prepare_tx(local, sdata);
994a1845fc7SJohannes Berg 	if (local->ops->mgd_prepare_tx)
995a1845fc7SJohannes Berg 		local->ops->mgd_prepare_tx(&local->hw, &sdata->vif);
996a1845fc7SJohannes Berg 	trace_drv_return_void(local);
997a1845fc7SJohannes Berg }
998c3645eacSMichal Kazior 
999ee10f2c7SArik Nemtsov static inline void
1000ee10f2c7SArik Nemtsov drv_mgd_protect_tdls_discover(struct ieee80211_local *local,
1001ee10f2c7SArik Nemtsov 			      struct ieee80211_sub_if_data *sdata)
1002ee10f2c7SArik Nemtsov {
1003ee10f2c7SArik Nemtsov 	might_sleep();
1004ee10f2c7SArik Nemtsov 
1005ee10f2c7SArik Nemtsov 	if (!check_sdata_in_driver(sdata))
1006ee10f2c7SArik Nemtsov 		return;
1007ee10f2c7SArik Nemtsov 	WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
1008ee10f2c7SArik Nemtsov 
1009ee10f2c7SArik Nemtsov 	trace_drv_mgd_protect_tdls_discover(local, sdata);
1010ee10f2c7SArik Nemtsov 	if (local->ops->mgd_protect_tdls_discover)
1011ee10f2c7SArik Nemtsov 		local->ops->mgd_protect_tdls_discover(&local->hw, &sdata->vif);
1012ee10f2c7SArik Nemtsov 	trace_drv_return_void(local);
1013ee10f2c7SArik Nemtsov }
1014ee10f2c7SArik Nemtsov 
1015c3645eacSMichal Kazior static inline int drv_add_chanctx(struct ieee80211_local *local,
1016c3645eacSMichal Kazior 				  struct ieee80211_chanctx *ctx)
1017c3645eacSMichal Kazior {
1018c3645eacSMichal Kazior 	int ret = -EOPNOTSUPP;
1019c3645eacSMichal Kazior 
1020c3645eacSMichal Kazior 	trace_drv_add_chanctx(local, ctx);
1021c3645eacSMichal Kazior 	if (local->ops->add_chanctx)
1022c3645eacSMichal Kazior 		ret = local->ops->add_chanctx(&local->hw, &ctx->conf);
1023c3645eacSMichal Kazior 	trace_drv_return_int(local, ret);
10248a61af65SJohannes Berg 	if (!ret)
10258a61af65SJohannes Berg 		ctx->driver_present = true;
1026c3645eacSMichal Kazior 
1027c3645eacSMichal Kazior 	return ret;
1028c3645eacSMichal Kazior }
1029c3645eacSMichal Kazior 
1030c3645eacSMichal Kazior static inline void drv_remove_chanctx(struct ieee80211_local *local,
1031c3645eacSMichal Kazior 				      struct ieee80211_chanctx *ctx)
1032c3645eacSMichal Kazior {
1033f6837ba8SJohannes Berg 	if (WARN_ON(!ctx->driver_present))
1034f6837ba8SJohannes Berg 		return;
1035f6837ba8SJohannes Berg 
1036c3645eacSMichal Kazior 	trace_drv_remove_chanctx(local, ctx);
1037c3645eacSMichal Kazior 	if (local->ops->remove_chanctx)
1038c3645eacSMichal Kazior 		local->ops->remove_chanctx(&local->hw, &ctx->conf);
1039c3645eacSMichal Kazior 	trace_drv_return_void(local);
10408a61af65SJohannes Berg 	ctx->driver_present = false;
1041c3645eacSMichal Kazior }
1042c3645eacSMichal Kazior 
1043c3645eacSMichal Kazior static inline void drv_change_chanctx(struct ieee80211_local *local,
1044c3645eacSMichal Kazior 				      struct ieee80211_chanctx *ctx,
1045c3645eacSMichal Kazior 				      u32 changed)
1046c3645eacSMichal Kazior {
1047c3645eacSMichal Kazior 	trace_drv_change_chanctx(local, ctx, changed);
10488a61af65SJohannes Berg 	if (local->ops->change_chanctx) {
10498a61af65SJohannes Berg 		WARN_ON_ONCE(!ctx->driver_present);
1050c3645eacSMichal Kazior 		local->ops->change_chanctx(&local->hw, &ctx->conf, changed);
10518a61af65SJohannes Berg 	}
1052c3645eacSMichal Kazior 	trace_drv_return_void(local);
1053c3645eacSMichal Kazior }
1054c3645eacSMichal Kazior 
1055c3645eacSMichal Kazior static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
1056c3645eacSMichal Kazior 					 struct ieee80211_sub_if_data *sdata,
1057c3645eacSMichal Kazior 					 struct ieee80211_chanctx *ctx)
1058c3645eacSMichal Kazior {
1059c3645eacSMichal Kazior 	int ret = 0;
1060c3645eacSMichal Kazior 
1061f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
1062f6837ba8SJohannes Berg 		return -EIO;
1063c3645eacSMichal Kazior 
1064c3645eacSMichal Kazior 	trace_drv_assign_vif_chanctx(local, sdata, ctx);
10658a61af65SJohannes Berg 	if (local->ops->assign_vif_chanctx) {
10668a61af65SJohannes Berg 		WARN_ON_ONCE(!ctx->driver_present);
1067c3645eacSMichal Kazior 		ret = local->ops->assign_vif_chanctx(&local->hw,
1068c3645eacSMichal Kazior 						     &sdata->vif,
1069c3645eacSMichal Kazior 						     &ctx->conf);
10708a61af65SJohannes Berg 	}
1071c3645eacSMichal Kazior 	trace_drv_return_int(local, ret);
1072c3645eacSMichal Kazior 
1073c3645eacSMichal Kazior 	return ret;
1074c3645eacSMichal Kazior }
1075c3645eacSMichal Kazior 
1076c3645eacSMichal Kazior static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
1077c3645eacSMichal Kazior 					    struct ieee80211_sub_if_data *sdata,
1078c3645eacSMichal Kazior 					    struct ieee80211_chanctx *ctx)
1079c3645eacSMichal Kazior {
1080f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
1081f6837ba8SJohannes Berg 		return;
1082c3645eacSMichal Kazior 
1083c3645eacSMichal Kazior 	trace_drv_unassign_vif_chanctx(local, sdata, ctx);
10848a61af65SJohannes Berg 	if (local->ops->unassign_vif_chanctx) {
10858a61af65SJohannes Berg 		WARN_ON_ONCE(!ctx->driver_present);
1086c3645eacSMichal Kazior 		local->ops->unassign_vif_chanctx(&local->hw,
1087c3645eacSMichal Kazior 						 &sdata->vif,
1088c3645eacSMichal Kazior 						 &ctx->conf);
10898a61af65SJohannes Berg 	}
1090c3645eacSMichal Kazior 	trace_drv_return_void(local);
1091c3645eacSMichal Kazior }
1092c3645eacSMichal Kazior 
10931a5f0c13SLuciano Coelho static inline int
10941a5f0c13SLuciano Coelho drv_switch_vif_chanctx(struct ieee80211_local *local,
10951a5f0c13SLuciano Coelho 		       struct ieee80211_vif_chanctx_switch *vifs,
10961a5f0c13SLuciano Coelho 		       int n_vifs,
10971a5f0c13SLuciano Coelho 		       enum ieee80211_chanctx_switch_mode mode)
10981a5f0c13SLuciano Coelho {
10991a5f0c13SLuciano Coelho 	int ret = 0;
11001a5f0c13SLuciano Coelho 	int i;
11011a5f0c13SLuciano Coelho 
11021a5f0c13SLuciano Coelho 	if (!local->ops->switch_vif_chanctx)
11031a5f0c13SLuciano Coelho 		return -EOPNOTSUPP;
11041a5f0c13SLuciano Coelho 
11051a5f0c13SLuciano Coelho 	for (i = 0; i < n_vifs; i++) {
11061a5f0c13SLuciano Coelho 		struct ieee80211_chanctx *new_ctx =
11071a5f0c13SLuciano Coelho 			container_of(vifs[i].new_ctx,
11081a5f0c13SLuciano Coelho 				     struct ieee80211_chanctx,
11091a5f0c13SLuciano Coelho 				     conf);
11101a5f0c13SLuciano Coelho 		struct ieee80211_chanctx *old_ctx =
11111a5f0c13SLuciano Coelho 			container_of(vifs[i].old_ctx,
11121a5f0c13SLuciano Coelho 				     struct ieee80211_chanctx,
11131a5f0c13SLuciano Coelho 				     conf);
11141a5f0c13SLuciano Coelho 
11151a5f0c13SLuciano Coelho 		WARN_ON_ONCE(!old_ctx->driver_present);
11161a5f0c13SLuciano Coelho 		WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
11171a5f0c13SLuciano Coelho 			      new_ctx->driver_present) ||
11181a5f0c13SLuciano Coelho 			     (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
11191a5f0c13SLuciano Coelho 			      !new_ctx->driver_present));
11201a5f0c13SLuciano Coelho 	}
11211a5f0c13SLuciano Coelho 
11221a5f0c13SLuciano Coelho 	trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
11231a5f0c13SLuciano Coelho 	ret = local->ops->switch_vif_chanctx(&local->hw,
11241a5f0c13SLuciano Coelho 					     vifs, n_vifs, mode);
11251a5f0c13SLuciano Coelho 	trace_drv_return_int(local, ret);
11261a5f0c13SLuciano Coelho 
11271a5f0c13SLuciano Coelho 	if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
11281a5f0c13SLuciano Coelho 		for (i = 0; i < n_vifs; i++) {
11291a5f0c13SLuciano Coelho 			struct ieee80211_chanctx *new_ctx =
11301a5f0c13SLuciano Coelho 				container_of(vifs[i].new_ctx,
11311a5f0c13SLuciano Coelho 					     struct ieee80211_chanctx,
11321a5f0c13SLuciano Coelho 					     conf);
11331a5f0c13SLuciano Coelho 			struct ieee80211_chanctx *old_ctx =
11341a5f0c13SLuciano Coelho 				container_of(vifs[i].old_ctx,
11351a5f0c13SLuciano Coelho 					     struct ieee80211_chanctx,
11361a5f0c13SLuciano Coelho 					     conf);
11371a5f0c13SLuciano Coelho 
11381a5f0c13SLuciano Coelho 			new_ctx->driver_present = true;
11391a5f0c13SLuciano Coelho 			old_ctx->driver_present = false;
11401a5f0c13SLuciano Coelho 		}
11411a5f0c13SLuciano Coelho 	}
11421a5f0c13SLuciano Coelho 
11431a5f0c13SLuciano Coelho 	return ret;
11441a5f0c13SLuciano Coelho }
11451a5f0c13SLuciano Coelho 
11461041638fSJohannes Berg static inline int drv_start_ap(struct ieee80211_local *local,
11471041638fSJohannes Berg 			       struct ieee80211_sub_if_data *sdata)
11481041638fSJohannes Berg {
11491041638fSJohannes Berg 	int ret = 0;
11501041638fSJohannes Berg 
1151f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
1152f6837ba8SJohannes Berg 		return -EIO;
11531041638fSJohannes Berg 
11541041638fSJohannes Berg 	trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
11551041638fSJohannes Berg 	if (local->ops->start_ap)
11561041638fSJohannes Berg 		ret = local->ops->start_ap(&local->hw, &sdata->vif);
11571041638fSJohannes Berg 	trace_drv_return_int(local, ret);
11581041638fSJohannes Berg 	return ret;
11591041638fSJohannes Berg }
11601041638fSJohannes Berg 
11611041638fSJohannes Berg static inline void drv_stop_ap(struct ieee80211_local *local,
11621041638fSJohannes Berg 			       struct ieee80211_sub_if_data *sdata)
11631041638fSJohannes Berg {
1164f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
1165f6837ba8SJohannes Berg 		return;
11661041638fSJohannes Berg 
11671041638fSJohannes Berg 	trace_drv_stop_ap(local, sdata);
11681041638fSJohannes Berg 	if (local->ops->stop_ap)
11691041638fSJohannes Berg 		local->ops->stop_ap(&local->hw, &sdata->vif);
11701041638fSJohannes Berg 	trace_drv_return_void(local);
11711041638fSJohannes Berg }
11721041638fSJohannes Berg 
1173cf2c92d8SEliad Peller static inline void
1174cf2c92d8SEliad Peller drv_reconfig_complete(struct ieee80211_local *local,
1175cf2c92d8SEliad Peller 		      enum ieee80211_reconfig_type reconfig_type)
11769214ad7fSJohannes Berg {
11779214ad7fSJohannes Berg 	might_sleep();
11789214ad7fSJohannes Berg 
1179cf2c92d8SEliad Peller 	trace_drv_reconfig_complete(local, reconfig_type);
1180cf2c92d8SEliad Peller 	if (local->ops->reconfig_complete)
1181cf2c92d8SEliad Peller 		local->ops->reconfig_complete(&local->hw, reconfig_type);
11829214ad7fSJohannes Berg 	trace_drv_return_void(local);
11839214ad7fSJohannes Berg }
11849214ad7fSJohannes Berg 
1185de5fad81SYoni Divinsky static inline void
1186de5fad81SYoni Divinsky drv_set_default_unicast_key(struct ieee80211_local *local,
1187de5fad81SYoni Divinsky 			    struct ieee80211_sub_if_data *sdata,
1188de5fad81SYoni Divinsky 			    int key_idx)
1189de5fad81SYoni Divinsky {
1190f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
1191f6837ba8SJohannes Berg 		return;
1192de5fad81SYoni Divinsky 
1193de5fad81SYoni Divinsky 	WARN_ON_ONCE(key_idx < -1 || key_idx > 3);
1194de5fad81SYoni Divinsky 
1195de5fad81SYoni Divinsky 	trace_drv_set_default_unicast_key(local, sdata, key_idx);
1196de5fad81SYoni Divinsky 	if (local->ops->set_default_unicast_key)
1197de5fad81SYoni Divinsky 		local->ops->set_default_unicast_key(&local->hw, &sdata->vif,
1198de5fad81SYoni Divinsky 						    key_idx);
1199de5fad81SYoni Divinsky 	trace_drv_return_void(local);
1200de5fad81SYoni Divinsky }
1201de5fad81SYoni Divinsky 
1202a65240c1SJohannes Berg #if IS_ENABLED(CONFIG_IPV6)
1203a65240c1SJohannes Berg static inline void drv_ipv6_addr_change(struct ieee80211_local *local,
1204a65240c1SJohannes Berg 					struct ieee80211_sub_if_data *sdata,
1205a65240c1SJohannes Berg 					struct inet6_dev *idev)
1206a65240c1SJohannes Berg {
1207a65240c1SJohannes Berg 	trace_drv_ipv6_addr_change(local, sdata);
1208a65240c1SJohannes Berg 	if (local->ops->ipv6_addr_change)
1209a65240c1SJohannes Berg 		local->ops->ipv6_addr_change(&local->hw, &sdata->vif, idev);
1210a65240c1SJohannes Berg 	trace_drv_return_void(local);
1211a65240c1SJohannes Berg }
1212a65240c1SJohannes Berg #endif
1213a65240c1SJohannes Berg 
121473da7d5bSSimon Wunderlich static inline void
121573da7d5bSSimon Wunderlich drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
121673da7d5bSSimon Wunderlich 			  struct cfg80211_chan_def *chandef)
121773da7d5bSSimon Wunderlich {
121873da7d5bSSimon Wunderlich 	struct ieee80211_local *local = sdata->local;
121973da7d5bSSimon Wunderlich 
122073da7d5bSSimon Wunderlich 	if (local->ops->channel_switch_beacon) {
122173da7d5bSSimon Wunderlich 		trace_drv_channel_switch_beacon(local, sdata, chandef);
122273da7d5bSSimon Wunderlich 		local->ops->channel_switch_beacon(&local->hw, &sdata->vif,
122373da7d5bSSimon Wunderlich 						  chandef);
122473da7d5bSSimon Wunderlich 	}
122573da7d5bSSimon Wunderlich }
122673da7d5bSSimon Wunderlich 
12276d027bccSLuciano Coelho static inline int
12286d027bccSLuciano Coelho drv_pre_channel_switch(struct ieee80211_sub_if_data *sdata,
12296d027bccSLuciano Coelho 		       struct ieee80211_channel_switch *ch_switch)
12306d027bccSLuciano Coelho {
12316d027bccSLuciano Coelho 	struct ieee80211_local *local = sdata->local;
12326d027bccSLuciano Coelho 	int ret = 0;
12336d027bccSLuciano Coelho 
12346d027bccSLuciano Coelho 	if (!check_sdata_in_driver(sdata))
12356d027bccSLuciano Coelho 		return -EIO;
12366d027bccSLuciano Coelho 
12376d027bccSLuciano Coelho 	trace_drv_pre_channel_switch(local, sdata, ch_switch);
12386d027bccSLuciano Coelho 	if (local->ops->pre_channel_switch)
12396d027bccSLuciano Coelho 		ret = local->ops->pre_channel_switch(&local->hw, &sdata->vif,
12406d027bccSLuciano Coelho 						     ch_switch);
12416d027bccSLuciano Coelho 	trace_drv_return_int(local, ret);
12426d027bccSLuciano Coelho 	return ret;
12436d027bccSLuciano Coelho }
12446d027bccSLuciano Coelho 
1245f1d65583SLuciano Coelho static inline int
1246f1d65583SLuciano Coelho drv_post_channel_switch(struct ieee80211_sub_if_data *sdata)
1247f1d65583SLuciano Coelho {
1248f1d65583SLuciano Coelho 	struct ieee80211_local *local = sdata->local;
1249f1d65583SLuciano Coelho 	int ret = 0;
1250f1d65583SLuciano Coelho 
1251f1d65583SLuciano Coelho 	if (!check_sdata_in_driver(sdata))
1252f1d65583SLuciano Coelho 		return -EIO;
1253f1d65583SLuciano Coelho 
1254f1d65583SLuciano Coelho 	trace_drv_post_channel_switch(local, sdata);
1255f1d65583SLuciano Coelho 	if (local->ops->post_channel_switch)
1256f1d65583SLuciano Coelho 		ret = local->ops->post_channel_switch(&local->hw, &sdata->vif);
1257f1d65583SLuciano Coelho 	trace_drv_return_int(local, ret);
1258f1d65583SLuciano Coelho 	return ret;
1259f1d65583SLuciano Coelho }
1260f1d65583SLuciano Coelho 
126155fff501SJohannes Berg static inline int drv_join_ibss(struct ieee80211_local *local,
126255fff501SJohannes Berg 				struct ieee80211_sub_if_data *sdata)
126355fff501SJohannes Berg {
126455fff501SJohannes Berg 	int ret = 0;
126555fff501SJohannes Berg 
126655fff501SJohannes Berg 	might_sleep();
1267f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
1268f6837ba8SJohannes Berg 		return -EIO;
126955fff501SJohannes Berg 
127055fff501SJohannes Berg 	trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf);
127155fff501SJohannes Berg 	if (local->ops->join_ibss)
127255fff501SJohannes Berg 		ret = local->ops->join_ibss(&local->hw, &sdata->vif);
127355fff501SJohannes Berg 	trace_drv_return_int(local, ret);
127455fff501SJohannes Berg 	return ret;
127555fff501SJohannes Berg }
127655fff501SJohannes Berg 
127755fff501SJohannes Berg static inline void drv_leave_ibss(struct ieee80211_local *local,
127855fff501SJohannes Berg 				  struct ieee80211_sub_if_data *sdata)
127955fff501SJohannes Berg {
128055fff501SJohannes Berg 	might_sleep();
1281f6837ba8SJohannes Berg 	if (!check_sdata_in_driver(sdata))
1282f6837ba8SJohannes Berg 		return;
128355fff501SJohannes Berg 
128455fff501SJohannes Berg 	trace_drv_leave_ibss(local, sdata);
128555fff501SJohannes Berg 	if (local->ops->leave_ibss)
128655fff501SJohannes Berg 		local->ops->leave_ibss(&local->hw, &sdata->vif);
128755fff501SJohannes Berg 	trace_drv_return_void(local);
128855fff501SJohannes Berg }
128955fff501SJohannes Berg 
1290cca674d4SAntonio Quartulli static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
1291cca674d4SAntonio Quartulli 					      struct ieee80211_sta *sta)
1292cca674d4SAntonio Quartulli {
1293cca674d4SAntonio Quartulli 	u32 ret = 0;
1294cca674d4SAntonio Quartulli 
1295cca674d4SAntonio Quartulli 	trace_drv_get_expected_throughput(sta);
1296cca674d4SAntonio Quartulli 	if (local->ops->get_expected_throughput)
1297cca674d4SAntonio Quartulli 		ret = local->ops->get_expected_throughput(sta);
1298cca674d4SAntonio Quartulli 	trace_drv_return_u32(local, ret);
1299cca674d4SAntonio Quartulli 
1300cca674d4SAntonio Quartulli 	return ret;
1301cca674d4SAntonio Quartulli }
1302cca674d4SAntonio Quartulli 
13035b3dc42bSFelix Fietkau static inline int drv_get_txpower(struct ieee80211_local *local,
13045b3dc42bSFelix Fietkau 				  struct ieee80211_sub_if_data *sdata, int *dbm)
13055b3dc42bSFelix Fietkau {
13065b3dc42bSFelix Fietkau 	int ret;
13075b3dc42bSFelix Fietkau 
13085b3dc42bSFelix Fietkau 	if (!local->ops->get_txpower)
13095b3dc42bSFelix Fietkau 		return -EOPNOTSUPP;
13105b3dc42bSFelix Fietkau 
13115b3dc42bSFelix Fietkau 	ret = local->ops->get_txpower(&local->hw, &sdata->vif, dbm);
13125b3dc42bSFelix Fietkau 	trace_drv_get_txpower(local, sdata, *dbm, ret);
13135b3dc42bSFelix Fietkau 
13145b3dc42bSFelix Fietkau 	return ret;
13155b3dc42bSFelix Fietkau }
13165b3dc42bSFelix Fietkau 
1317a7a6bdd0SArik Nemtsov static inline int
1318a7a6bdd0SArik Nemtsov drv_tdls_channel_switch(struct ieee80211_local *local,
1319a7a6bdd0SArik Nemtsov 			struct ieee80211_sub_if_data *sdata,
1320a7a6bdd0SArik Nemtsov 			struct ieee80211_sta *sta, u8 oper_class,
1321a7a6bdd0SArik Nemtsov 			struct cfg80211_chan_def *chandef,
1322a7a6bdd0SArik Nemtsov 			struct sk_buff *tmpl_skb, u32 ch_sw_tm_ie)
1323a7a6bdd0SArik Nemtsov {
1324a7a6bdd0SArik Nemtsov 	int ret;
1325a7a6bdd0SArik Nemtsov 
1326a7a6bdd0SArik Nemtsov 	might_sleep();
1327a7a6bdd0SArik Nemtsov 	if (!check_sdata_in_driver(sdata))
1328a7a6bdd0SArik Nemtsov 		return -EIO;
1329a7a6bdd0SArik Nemtsov 
1330a7a6bdd0SArik Nemtsov 	if (!local->ops->tdls_channel_switch)
1331a7a6bdd0SArik Nemtsov 		return -EOPNOTSUPP;
1332a7a6bdd0SArik Nemtsov 
1333a7a6bdd0SArik Nemtsov 	trace_drv_tdls_channel_switch(local, sdata, sta, oper_class, chandef);
1334a7a6bdd0SArik Nemtsov 	ret = local->ops->tdls_channel_switch(&local->hw, &sdata->vif, sta,
1335a7a6bdd0SArik Nemtsov 					      oper_class, chandef, tmpl_skb,
1336a7a6bdd0SArik Nemtsov 					      ch_sw_tm_ie);
1337a7a6bdd0SArik Nemtsov 	trace_drv_return_int(local, ret);
1338a7a6bdd0SArik Nemtsov 	return ret;
1339a7a6bdd0SArik Nemtsov }
1340a7a6bdd0SArik Nemtsov 
1341a7a6bdd0SArik Nemtsov static inline void
1342a7a6bdd0SArik Nemtsov drv_tdls_cancel_channel_switch(struct ieee80211_local *local,
1343a7a6bdd0SArik Nemtsov 			       struct ieee80211_sub_if_data *sdata,
1344a7a6bdd0SArik Nemtsov 			       struct ieee80211_sta *sta)
1345a7a6bdd0SArik Nemtsov {
1346a7a6bdd0SArik Nemtsov 	might_sleep();
1347a7a6bdd0SArik Nemtsov 	if (!check_sdata_in_driver(sdata))
1348a7a6bdd0SArik Nemtsov 		return;
1349a7a6bdd0SArik Nemtsov 
1350a7a6bdd0SArik Nemtsov 	if (!local->ops->tdls_cancel_channel_switch)
1351a7a6bdd0SArik Nemtsov 		return;
1352a7a6bdd0SArik Nemtsov 
1353a7a6bdd0SArik Nemtsov 	trace_drv_tdls_cancel_channel_switch(local, sdata, sta);
1354a7a6bdd0SArik Nemtsov 	local->ops->tdls_cancel_channel_switch(&local->hw, &sdata->vif, sta);
1355a7a6bdd0SArik Nemtsov 	trace_drv_return_void(local);
1356a7a6bdd0SArik Nemtsov }
1357a7a6bdd0SArik Nemtsov 
13588a4d32f3SArik Nemtsov static inline void
13598a4d32f3SArik Nemtsov drv_tdls_recv_channel_switch(struct ieee80211_local *local,
13608a4d32f3SArik Nemtsov 			     struct ieee80211_sub_if_data *sdata,
13618a4d32f3SArik Nemtsov 			     struct ieee80211_tdls_ch_sw_params *params)
13628a4d32f3SArik Nemtsov {
13638a4d32f3SArik Nemtsov 	trace_drv_tdls_recv_channel_switch(local, sdata, params);
13648a4d32f3SArik Nemtsov 	if (local->ops->tdls_recv_channel_switch)
13658a4d32f3SArik Nemtsov 		local->ops->tdls_recv_channel_switch(&local->hw, &sdata->vif,
13668a4d32f3SArik Nemtsov 						     params);
13678a4d32f3SArik Nemtsov 	trace_drv_return_void(local);
13688a4d32f3SArik Nemtsov }
13698a4d32f3SArik Nemtsov 
137024487981SJohannes Berg #endif /* __MAC80211_DRIVER_OPS */
1371