1 /*
2  * This file is part of wl12xx
3  *
4  * Copyright (C) 2012 Texas Instruments. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  */
21 
22 #include "event.h"
23 #include "scan.h"
24 #include "../wlcore/cmd.h"
25 #include "../wlcore/debug.h"
26 
27 int wl12xx_wait_for_event(struct wl1271 *wl, enum wlcore_wait_event event,
28 			  bool *timeout)
29 {
30 	u32 local_event;
31 
32 	switch (event) {
33 	case WLCORE_EVENT_ROLE_STOP_COMPLETE:
34 		local_event = ROLE_STOP_COMPLETE_EVENT_ID;
35 		break;
36 
37 	case WLCORE_EVENT_PEER_REMOVE_COMPLETE:
38 		local_event = PEER_REMOVE_COMPLETE_EVENT_ID;
39 		break;
40 
41 	default:
42 		/* event not implemented */
43 		return 0;
44 	}
45 	return wlcore_cmd_wait_for_event_or_timeout(wl, local_event, timeout);
46 }
47 
48 int wl12xx_process_mailbox_events(struct wl1271 *wl)
49 {
50 	struct wl12xx_event_mailbox *mbox = wl->mbox;
51 	u32 vector;
52 
53 
54 	vector = le32_to_cpu(mbox->events_vector);
55 	vector &= ~(le32_to_cpu(mbox->events_mask));
56 
57 	wl1271_debug(DEBUG_EVENT, "MBOX vector: 0x%x", vector);
58 
59 	if (vector & SCAN_COMPLETE_EVENT_ID) {
60 		wl1271_debug(DEBUG_EVENT, "status: 0x%x",
61 			     mbox->scheduled_scan_status);
62 
63 		if (wl->scan_wlvif)
64 			wl12xx_scan_completed(wl, wl->scan_wlvif);
65 	}
66 
67 	if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
68 		wl1271_debug(DEBUG_EVENT,
69 			     "PERIODIC_SCAN_REPORT_EVENT (status 0x%0x)",
70 			     mbox->scheduled_scan_status);
71 
72 		wlcore_scan_sched_scan_results(wl);
73 	}
74 
75 	if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID)
76 		wlcore_event_sched_scan_completed(wl,
77 						  mbox->scheduled_scan_status);
78 	if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
79 		wlcore_event_soft_gemini_sense(wl,
80 					       mbox->soft_gemini_sense_info);
81 
82 	if (vector & BSS_LOSE_EVENT_ID)
83 		wlcore_event_beacon_loss(wl, 0xff);
84 
85 	if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID)
86 		wlcore_event_rssi_trigger(wl, mbox->rssi_snr_trigger_metric);
87 
88 	if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)
89 		wlcore_event_ba_rx_constraint(wl,
90 					      BIT(mbox->role_id),
91 					      mbox->rx_ba_allowed);
92 
93 	if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID)
94 		wlcore_event_channel_switch(wl, 0xff,
95 					    mbox->channel_switch_status);
96 
97 	if (vector & DUMMY_PACKET_EVENT_ID)
98 		wlcore_event_dummy_packet(wl);
99 
100 	/*
101 	 * "TX retries exceeded" has a different meaning according to mode.
102 	 * In AP mode the offending station is disconnected.
103 	 */
104 	if (vector & MAX_TX_RETRY_EVENT_ID)
105 		wlcore_event_max_tx_failure(wl,
106 				le16_to_cpu(mbox->sta_tx_retry_exceeded));
107 
108 	if (vector & INACTIVE_STA_EVENT_ID)
109 		wlcore_event_inactive_sta(wl,
110 					  le16_to_cpu(mbox->sta_aging_status));
111 
112 	if (vector & REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID)
113 		wlcore_event_roc_complete(wl);
114 
115 	return 0;
116 }
117