xref: /openbmc/linux/drivers/net/wireless/ti/wl18xx/event.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
12b27bdccSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2c50a2825SEliad Peller /*
3c50a2825SEliad Peller  * This file is part of wl12xx
4c50a2825SEliad Peller  *
5c50a2825SEliad Peller  * Copyright (C) 2012 Texas Instruments. All rights reserved.
6c50a2825SEliad Peller  */
7c50a2825SEliad Peller 
8e93e15fbSEliad Peller #include <net/genetlink.h>
9c50a2825SEliad Peller #include "event.h"
10c50a2825SEliad Peller #include "scan.h"
11c5aa9541SGuy Mishol #include "conf.h"
12c50a2825SEliad Peller #include "../wlcore/cmd.h"
13c50a2825SEliad Peller #include "../wlcore/debug.h"
14e93e15fbSEliad Peller #include "../wlcore/vendor_cmd.h"
15c50a2825SEliad Peller 
wl18xx_wait_for_event(struct wl1271 * wl,enum wlcore_wait_event event,bool * timeout)16c50a2825SEliad Peller int wl18xx_wait_for_event(struct wl1271 *wl, enum wlcore_wait_event event,
17c50a2825SEliad Peller 			  bool *timeout)
18c50a2825SEliad Peller {
19c50a2825SEliad Peller 	u32 local_event;
20c50a2825SEliad Peller 
21c50a2825SEliad Peller 	switch (event) {
22c50a2825SEliad Peller 	case WLCORE_EVENT_PEER_REMOVE_COMPLETE:
23c50a2825SEliad Peller 		local_event = PEER_REMOVE_COMPLETE_EVENT_ID;
24c50a2825SEliad Peller 		break;
25c50a2825SEliad Peller 
266b70e7ebSVictor Goldenshtein 	case WLCORE_EVENT_DFS_CONFIG_COMPLETE:
276b70e7ebSVictor Goldenshtein 		local_event = DFS_CHANNELS_CONFIG_COMPLETE_EVENT;
286b70e7ebSVictor Goldenshtein 		break;
296b70e7ebSVictor Goldenshtein 
30c50a2825SEliad Peller 	default:
31c50a2825SEliad Peller 		/* event not implemented */
32c50a2825SEliad Peller 		return 0;
33c50a2825SEliad Peller 	}
34c50a2825SEliad Peller 	return wlcore_cmd_wait_for_event_or_timeout(wl, local_event, timeout);
35c50a2825SEliad Peller }
36c50a2825SEliad Peller 
wl18xx_radar_type_decode(u8 radar_type)37750e9d15SEliad Peller static const char *wl18xx_radar_type_decode(u8 radar_type)
38750e9d15SEliad Peller {
39750e9d15SEliad Peller 	switch (radar_type) {
40750e9d15SEliad Peller 	case RADAR_TYPE_REGULAR:
41750e9d15SEliad Peller 		return "REGULAR";
42750e9d15SEliad Peller 	case RADAR_TYPE_CHIRP:
43750e9d15SEliad Peller 		return "CHIRP";
44750e9d15SEliad Peller 	case RADAR_TYPE_NONE:
45750e9d15SEliad Peller 	default:
46750e9d15SEliad Peller 		return "N/A";
47750e9d15SEliad Peller 	}
48750e9d15SEliad Peller }
49750e9d15SEliad Peller 
wlcore_smart_config_sync_event(struct wl1271 * wl,u8 sync_channel,u8 sync_band)50e93e15fbSEliad Peller static int wlcore_smart_config_sync_event(struct wl1271 *wl, u8 sync_channel,
51e93e15fbSEliad Peller 					  u8 sync_band)
52e93e15fbSEliad Peller {
53e93e15fbSEliad Peller 	struct sk_buff *skb;
5457fbcce3SJohannes Berg 	enum nl80211_band band;
55e93e15fbSEliad Peller 	int freq;
56e93e15fbSEliad Peller 
57e93e15fbSEliad Peller 	if (sync_band == WLCORE_BAND_5GHZ)
5857fbcce3SJohannes Berg 		band = NL80211_BAND_5GHZ;
59e93e15fbSEliad Peller 	else
6057fbcce3SJohannes Berg 		band = NL80211_BAND_2GHZ;
61e93e15fbSEliad Peller 
62e93e15fbSEliad Peller 	freq = ieee80211_channel_to_frequency(sync_channel, band);
63e93e15fbSEliad Peller 
64e93e15fbSEliad Peller 	wl1271_debug(DEBUG_EVENT,
65e93e15fbSEliad Peller 		     "SMART_CONFIG_SYNC_EVENT_ID, freq: %d (chan: %d band %d)",
66e93e15fbSEliad Peller 		     freq, sync_channel, sync_band);
676c09e791SAhmad Kholaif 	skb = cfg80211_vendor_event_alloc(wl->hw->wiphy, NULL, 20,
68e93e15fbSEliad Peller 					  WLCORE_VENDOR_EVENT_SC_SYNC,
69e93e15fbSEliad Peller 					  GFP_KERNEL);
70e93e15fbSEliad Peller 
71e93e15fbSEliad Peller 	if (nla_put_u32(skb, WLCORE_VENDOR_ATTR_FREQ, freq)) {
72e93e15fbSEliad Peller 		kfree_skb(skb);
73e93e15fbSEliad Peller 		return -EMSGSIZE;
74e93e15fbSEliad Peller 	}
75e93e15fbSEliad Peller 	cfg80211_vendor_event(skb, GFP_KERNEL);
76e93e15fbSEliad Peller 	return 0;
77e93e15fbSEliad Peller }
78e93e15fbSEliad Peller 
wlcore_smart_config_decode_event(struct wl1271 * wl,u8 ssid_len,u8 * ssid,u8 pwd_len,u8 * pwd)79e93e15fbSEliad Peller static int wlcore_smart_config_decode_event(struct wl1271 *wl,
80e93e15fbSEliad Peller 					    u8 ssid_len, u8 *ssid,
81e93e15fbSEliad Peller 					    u8 pwd_len, u8 *pwd)
82e93e15fbSEliad Peller {
83e93e15fbSEliad Peller 	struct sk_buff *skb;
84e93e15fbSEliad Peller 
85e93e15fbSEliad Peller 	wl1271_debug(DEBUG_EVENT, "SMART_CONFIG_DECODE_EVENT_ID");
86e93e15fbSEliad Peller 	wl1271_dump_ascii(DEBUG_EVENT, "SSID:", ssid, ssid_len);
87e93e15fbSEliad Peller 
886c09e791SAhmad Kholaif 	skb = cfg80211_vendor_event_alloc(wl->hw->wiphy, NULL,
89e93e15fbSEliad Peller 					  ssid_len + pwd_len + 20,
90e93e15fbSEliad Peller 					  WLCORE_VENDOR_EVENT_SC_DECODE,
91e93e15fbSEliad Peller 					  GFP_KERNEL);
92e93e15fbSEliad Peller 
93e93e15fbSEliad Peller 	if (nla_put(skb, WLCORE_VENDOR_ATTR_SSID, ssid_len, ssid) ||
94e93e15fbSEliad Peller 	    nla_put(skb, WLCORE_VENDOR_ATTR_PSK, pwd_len, pwd)) {
95e93e15fbSEliad Peller 		kfree_skb(skb);
96e93e15fbSEliad Peller 		return -EMSGSIZE;
97e93e15fbSEliad Peller 	}
98e93e15fbSEliad Peller 	cfg80211_vendor_event(skb, GFP_KERNEL);
99e93e15fbSEliad Peller 	return 0;
100e93e15fbSEliad Peller }
101e93e15fbSEliad Peller 
wlcore_event_time_sync(struct wl1271 * wl,u16 tsf_high_msb,u16 tsf_high_lsb,u16 tsf_low_msb,u16 tsf_low_lsb)102585dfe81SMachani, Yaniv static void wlcore_event_time_sync(struct wl1271 *wl,
103585dfe81SMachani, Yaniv 				   u16 tsf_high_msb, u16 tsf_high_lsb,
104585dfe81SMachani, Yaniv 				   u16 tsf_low_msb, u16 tsf_low_lsb)
1056d5c8987SMachani, Yaniv {
106585dfe81SMachani, Yaniv 	u32 clock_low;
107585dfe81SMachani, Yaniv 	u32 clock_high;
108585dfe81SMachani, Yaniv 
109585dfe81SMachani, Yaniv 	clock_high = (tsf_high_msb << 16) | tsf_high_lsb;
110585dfe81SMachani, Yaniv 	clock_low = (tsf_low_msb << 16) | tsf_low_lsb;
111585dfe81SMachani, Yaniv 
112585dfe81SMachani, Yaniv 	wl1271_info("TIME_SYNC_EVENT_ID: clock_high %u, clock low %u",
113585dfe81SMachani, Yaniv 		    clock_high, clock_low);
1146d5c8987SMachani, Yaniv }
1156d5c8987SMachani, Yaniv 
wl18xx_process_mailbox_events(struct wl1271 * wl)116c50a2825SEliad Peller int wl18xx_process_mailbox_events(struct wl1271 *wl)
117c50a2825SEliad Peller {
118c50a2825SEliad Peller 	struct wl18xx_event_mailbox *mbox = wl->mbox;
119c50a2825SEliad Peller 	u32 vector;
120c50a2825SEliad Peller 
121c50a2825SEliad Peller 	vector = le32_to_cpu(mbox->events_vector);
122c50a2825SEliad Peller 	wl1271_debug(DEBUG_EVENT, "MBOX vector: 0x%x", vector);
123c50a2825SEliad Peller 
124c50a2825SEliad Peller 	if (vector & SCAN_COMPLETE_EVENT_ID) {
125c50a2825SEliad Peller 		wl1271_debug(DEBUG_EVENT, "scan results: %d",
126c50a2825SEliad Peller 			     mbox->number_of_scan_results);
127c50a2825SEliad Peller 
128c50a2825SEliad Peller 		if (wl->scan_wlvif)
129c50a2825SEliad Peller 			wl18xx_scan_completed(wl, wl->scan_wlvif);
130c50a2825SEliad Peller 	}
131c50a2825SEliad Peller 
1326d5c8987SMachani, Yaniv 	if (vector & TIME_SYNC_EVENT_ID)
1336d5c8987SMachani, Yaniv 		wlcore_event_time_sync(wl,
134*9d5b6657SJohannes Berg 			le16_to_cpu(mbox->time_sync_tsf_high_msb),
135*9d5b6657SJohannes Berg 			le16_to_cpu(mbox->time_sync_tsf_high_lsb),
136*9d5b6657SJohannes Berg 			le16_to_cpu(mbox->time_sync_tsf_low_msb),
137*9d5b6657SJohannes Berg 			le16_to_cpu(mbox->time_sync_tsf_low_lsb));
1386d5c8987SMachani, Yaniv 
139750e9d15SEliad Peller 	if (vector & RADAR_DETECTED_EVENT_ID) {
140750e9d15SEliad Peller 		wl1271_info("radar event: channel %d type %s",
141750e9d15SEliad Peller 			    mbox->radar_channel,
142750e9d15SEliad Peller 			    wl18xx_radar_type_decode(mbox->radar_type));
143750e9d15SEliad Peller 
1448cf77e17SEliad Peller 		if (!wl->radar_debug_mode)
145750e9d15SEliad Peller 			ieee80211_radar_detected(wl->hw);
146750e9d15SEliad Peller 	}
147750e9d15SEliad Peller 
1480b70078cSEyal Shapira 	if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
1490b70078cSEyal Shapira 		wl1271_debug(DEBUG_EVENT,
1500b70078cSEyal Shapira 			     "PERIODIC_SCAN_REPORT_EVENT (results %d)",
1510b70078cSEyal Shapira 			     mbox->number_of_sched_scan_results);
1520b70078cSEyal Shapira 
1530b70078cSEyal Shapira 		wlcore_scan_sched_scan_results(wl);
1540b70078cSEyal Shapira 	}
1550b70078cSEyal Shapira 
156c50a2825SEliad Peller 	if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID)
157c50a2825SEliad Peller 		wlcore_event_sched_scan_completed(wl, 1);
158c50a2825SEliad Peller 
159c50a2825SEliad Peller 	if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID)
160c50a2825SEliad Peller 		wlcore_event_rssi_trigger(wl, mbox->rssi_snr_trigger_metric);
161c50a2825SEliad Peller 
162c50a2825SEliad Peller 	if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)
163c50a2825SEliad Peller 		wlcore_event_ba_rx_constraint(wl,
164c50a2825SEliad Peller 				le16_to_cpu(mbox->rx_ba_role_id_bitmap),
165c50a2825SEliad Peller 				le16_to_cpu(mbox->rx_ba_allowed_bitmap));
166c50a2825SEliad Peller 
167c50a2825SEliad Peller 	if (vector & BSS_LOSS_EVENT_ID)
168c50a2825SEliad Peller 		wlcore_event_beacon_loss(wl,
169c50a2825SEliad Peller 					 le16_to_cpu(mbox->bss_loss_bitmap));
170c50a2825SEliad Peller 
171c50a2825SEliad Peller 	if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID)
172c50a2825SEliad Peller 		wlcore_event_channel_switch(wl,
173c50a2825SEliad Peller 			le16_to_cpu(mbox->channel_switch_role_id_bitmap),
174c50a2825SEliad Peller 			true);
175c50a2825SEliad Peller 
176c50a2825SEliad Peller 	if (vector & DUMMY_PACKET_EVENT_ID)
177c50a2825SEliad Peller 		wlcore_event_dummy_packet(wl);
178c50a2825SEliad Peller 
179c50a2825SEliad Peller 	/*
180c50a2825SEliad Peller 	 * "TX retries exceeded" has a different meaning according to mode.
181c50a2825SEliad Peller 	 * In AP mode the offending station is disconnected.
182c50a2825SEliad Peller 	 */
183c50a2825SEliad Peller 	if (vector & MAX_TX_FAILURE_EVENT_ID)
184c50a2825SEliad Peller 		wlcore_event_max_tx_failure(wl,
185585dfe81SMachani, Yaniv 				le16_to_cpu(mbox->tx_retry_exceeded_bitmap));
186c50a2825SEliad Peller 
187c50a2825SEliad Peller 	if (vector & INACTIVE_STA_EVENT_ID)
188c50a2825SEliad Peller 		wlcore_event_inactive_sta(wl,
189585dfe81SMachani, Yaniv 				le16_to_cpu(mbox->inactive_sta_bitmap));
190c50a2825SEliad Peller 
191c50a2825SEliad Peller 	if (vector & REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID)
192c50a2825SEliad Peller 		wlcore_event_roc_complete(wl);
193c50a2825SEliad Peller 
194e93e15fbSEliad Peller 	if (vector & SMART_CONFIG_SYNC_EVENT_ID)
195e93e15fbSEliad Peller 		wlcore_smart_config_sync_event(wl, mbox->sc_sync_channel,
196e93e15fbSEliad Peller 					       mbox->sc_sync_band);
197e93e15fbSEliad Peller 
198e93e15fbSEliad Peller 	if (vector & SMART_CONFIG_DECODE_EVENT_ID)
199e93e15fbSEliad Peller 		wlcore_smart_config_decode_event(wl,
200e93e15fbSEliad Peller 						 mbox->sc_ssid_len,
201e93e15fbSEliad Peller 						 mbox->sc_ssid,
202e93e15fbSEliad Peller 						 mbox->sc_pwd_len,
203e93e15fbSEliad Peller 						 mbox->sc_pwd);
2043719c17eSShahar Patury 	if (vector & FW_LOGGER_INDICATION)
2053719c17eSShahar Patury 		wlcore_event_fw_logger(wl);
206e93e15fbSEliad Peller 
207e7ee74b5SMaxim Altshul 	if (vector & RX_BA_WIN_SIZE_CHANGE_EVENT_ID) {
208e7ee74b5SMaxim Altshul 		struct wl12xx_vif *wlvif;
209e7ee74b5SMaxim Altshul 		struct ieee80211_vif *vif;
210e7ee74b5SMaxim Altshul 		struct ieee80211_sta *sta;
211e7ee74b5SMaxim Altshul 		u8 link_id = mbox->rx_ba_link_id;
212e7ee74b5SMaxim Altshul 		u8 win_size = mbox->rx_ba_win_size;
213e7ee74b5SMaxim Altshul 		const u8 *addr;
214e7ee74b5SMaxim Altshul 
215e7ee74b5SMaxim Altshul 		wlvif = wl->links[link_id].wlvif;
216e7ee74b5SMaxim Altshul 		vif = wl12xx_wlvif_to_vif(wlvif);
217e7ee74b5SMaxim Altshul 
218e7ee74b5SMaxim Altshul 		/* Update RX aggregation window size and call
219e7ee74b5SMaxim Altshul 		 * MAC routine to stop active RX aggregations for this link
220e7ee74b5SMaxim Altshul 		 */
221e7ee74b5SMaxim Altshul 		if (wlvif->bss_type != BSS_TYPE_AP_BSS)
222e7ee74b5SMaxim Altshul 			addr = vif->bss_conf.bssid;
223e7ee74b5SMaxim Altshul 		else
224e7ee74b5SMaxim Altshul 			addr = wl->links[link_id].addr;
225e7ee74b5SMaxim Altshul 
226e7ee74b5SMaxim Altshul 		sta = ieee80211_find_sta(vif, addr);
227e7ee74b5SMaxim Altshul 		if (sta) {
228e7ee74b5SMaxim Altshul 			sta->max_rx_aggregation_subframes = win_size;
229e7ee74b5SMaxim Altshul 			ieee80211_stop_rx_ba_session(vif,
230e7ee74b5SMaxim Altshul 						wl->links[link_id].ba_bitmap,
231e7ee74b5SMaxim Altshul 						addr);
232e7ee74b5SMaxim Altshul 		}
233e7ee74b5SMaxim Altshul 	}
234e7ee74b5SMaxim Altshul 
235c50a2825SEliad Peller 	return 0;
236c50a2825SEliad Peller }
237