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 
8c50a2825SEliad Peller #include "event.h"
9c50a2825SEliad Peller #include "scan.h"
10c50a2825SEliad Peller #include "../wlcore/cmd.h"
11c50a2825SEliad Peller #include "../wlcore/debug.h"
12c50a2825SEliad Peller 
wl12xx_wait_for_event(struct wl1271 * wl,enum wlcore_wait_event event,bool * timeout)13c50a2825SEliad Peller int wl12xx_wait_for_event(struct wl1271 *wl, enum wlcore_wait_event event,
14c50a2825SEliad Peller 			  bool *timeout)
15c50a2825SEliad Peller {
16c50a2825SEliad Peller 	u32 local_event;
17c50a2825SEliad Peller 
18c50a2825SEliad Peller 	switch (event) {
19c50a2825SEliad Peller 	case WLCORE_EVENT_ROLE_STOP_COMPLETE:
20c50a2825SEliad Peller 		local_event = ROLE_STOP_COMPLETE_EVENT_ID;
21c50a2825SEliad Peller 		break;
22c50a2825SEliad Peller 
23c50a2825SEliad Peller 	case WLCORE_EVENT_PEER_REMOVE_COMPLETE:
24c50a2825SEliad Peller 		local_event = PEER_REMOVE_COMPLETE_EVENT_ID;
25c50a2825SEliad Peller 		break;
26c50a2825SEliad Peller 
27c50a2825SEliad Peller 	default:
28c50a2825SEliad Peller 		/* event not implemented */
29c50a2825SEliad Peller 		return 0;
30c50a2825SEliad Peller 	}
31c50a2825SEliad Peller 	return wlcore_cmd_wait_for_event_or_timeout(wl, local_event, timeout);
32c50a2825SEliad Peller }
33c50a2825SEliad Peller 
wl12xx_process_mailbox_events(struct wl1271 * wl)34c50a2825SEliad Peller int wl12xx_process_mailbox_events(struct wl1271 *wl)
35c50a2825SEliad Peller {
36c50a2825SEliad Peller 	struct wl12xx_event_mailbox *mbox = wl->mbox;
37c50a2825SEliad Peller 	u32 vector;
38c50a2825SEliad Peller 
39c50a2825SEliad Peller 
40c50a2825SEliad Peller 	vector = le32_to_cpu(mbox->events_vector);
41c50a2825SEliad Peller 	vector &= ~(le32_to_cpu(mbox->events_mask));
42c50a2825SEliad Peller 
43c50a2825SEliad Peller 	wl1271_debug(DEBUG_EVENT, "MBOX vector: 0x%x", vector);
44c50a2825SEliad Peller 
45c50a2825SEliad Peller 	if (vector & SCAN_COMPLETE_EVENT_ID) {
46c50a2825SEliad Peller 		wl1271_debug(DEBUG_EVENT, "status: 0x%x",
47c50a2825SEliad Peller 			     mbox->scheduled_scan_status);
48c50a2825SEliad Peller 
49c50a2825SEliad Peller 		if (wl->scan_wlvif)
50c50a2825SEliad Peller 			wl12xx_scan_completed(wl, wl->scan_wlvif);
51c50a2825SEliad Peller 	}
52c50a2825SEliad Peller 
530b70078cSEyal Shapira 	if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
540b70078cSEyal Shapira 		wl1271_debug(DEBUG_EVENT,
550b70078cSEyal Shapira 			     "PERIODIC_SCAN_REPORT_EVENT (status 0x%0x)",
56c50a2825SEliad Peller 			     mbox->scheduled_scan_status);
57c50a2825SEliad Peller 
580b70078cSEyal Shapira 		wlcore_scan_sched_scan_results(wl);
590b70078cSEyal Shapira 	}
600b70078cSEyal Shapira 
61c50a2825SEliad Peller 	if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID)
62c50a2825SEliad Peller 		wlcore_event_sched_scan_completed(wl,
63c50a2825SEliad Peller 						  mbox->scheduled_scan_status);
64c50a2825SEliad Peller 	if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
65c50a2825SEliad Peller 		wlcore_event_soft_gemini_sense(wl,
66c50a2825SEliad Peller 					       mbox->soft_gemini_sense_info);
67c50a2825SEliad Peller 
68c50a2825SEliad Peller 	if (vector & BSS_LOSE_EVENT_ID)
69c50a2825SEliad Peller 		wlcore_event_beacon_loss(wl, 0xff);
70c50a2825SEliad Peller 
71c50a2825SEliad Peller 	if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID)
72c50a2825SEliad Peller 		wlcore_event_rssi_trigger(wl, mbox->rssi_snr_trigger_metric);
73c50a2825SEliad Peller 
74c50a2825SEliad Peller 	if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)
75c50a2825SEliad Peller 		wlcore_event_ba_rx_constraint(wl,
76c50a2825SEliad Peller 					      BIT(mbox->role_id),
77c50a2825SEliad Peller 					      mbox->rx_ba_allowed);
78c50a2825SEliad Peller 
79c50a2825SEliad Peller 	if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID)
80c50a2825SEliad Peller 		wlcore_event_channel_switch(wl, 0xff,
81c50a2825SEliad Peller 					    mbox->channel_switch_status);
82c50a2825SEliad Peller 
83c50a2825SEliad Peller 	if (vector & DUMMY_PACKET_EVENT_ID)
84c50a2825SEliad Peller 		wlcore_event_dummy_packet(wl);
85c50a2825SEliad Peller 
86c50a2825SEliad Peller 	/*
87c50a2825SEliad Peller 	 * "TX retries exceeded" has a different meaning according to mode.
88c50a2825SEliad Peller 	 * In AP mode the offending station is disconnected.
89c50a2825SEliad Peller 	 */
90c50a2825SEliad Peller 	if (vector & MAX_TX_RETRY_EVENT_ID)
91c50a2825SEliad Peller 		wlcore_event_max_tx_failure(wl,
92c50a2825SEliad Peller 				le16_to_cpu(mbox->sta_tx_retry_exceeded));
93c50a2825SEliad Peller 
94c50a2825SEliad Peller 	if (vector & INACTIVE_STA_EVENT_ID)
95c50a2825SEliad Peller 		wlcore_event_inactive_sta(wl,
96c50a2825SEliad Peller 					  le16_to_cpu(mbox->sta_aging_status));
97c50a2825SEliad Peller 
98c50a2825SEliad Peller 	if (vector & REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID)
99c50a2825SEliad Peller 		wlcore_event_roc_complete(wl);
100c50a2825SEliad Peller 
101c50a2825SEliad Peller 	return 0;
102c50a2825SEliad Peller }
103