18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * This file is part of wl12xx
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2012 Texas Instruments. All rights reserved.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "event.h"
98c2ecf20Sopenharmony_ci#include "scan.h"
108c2ecf20Sopenharmony_ci#include "../wlcore/cmd.h"
118c2ecf20Sopenharmony_ci#include "../wlcore/debug.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciint wl12xx_wait_for_event(struct wl1271 *wl, enum wlcore_wait_event event,
148c2ecf20Sopenharmony_ci			  bool *timeout)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	u32 local_event;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	switch (event) {
198c2ecf20Sopenharmony_ci	case WLCORE_EVENT_ROLE_STOP_COMPLETE:
208c2ecf20Sopenharmony_ci		local_event = ROLE_STOP_COMPLETE_EVENT_ID;
218c2ecf20Sopenharmony_ci		break;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	case WLCORE_EVENT_PEER_REMOVE_COMPLETE:
248c2ecf20Sopenharmony_ci		local_event = PEER_REMOVE_COMPLETE_EVENT_ID;
258c2ecf20Sopenharmony_ci		break;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	default:
288c2ecf20Sopenharmony_ci		/* event not implemented */
298c2ecf20Sopenharmony_ci		return 0;
308c2ecf20Sopenharmony_ci	}
318c2ecf20Sopenharmony_ci	return wlcore_cmd_wait_for_event_or_timeout(wl, local_event, timeout);
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciint wl12xx_process_mailbox_events(struct wl1271 *wl)
358c2ecf20Sopenharmony_ci{
368c2ecf20Sopenharmony_ci	struct wl12xx_event_mailbox *mbox = wl->mbox;
378c2ecf20Sopenharmony_ci	u32 vector;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	vector = le32_to_cpu(mbox->events_vector);
418c2ecf20Sopenharmony_ci	vector &= ~(le32_to_cpu(mbox->events_mask));
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	wl1271_debug(DEBUG_EVENT, "MBOX vector: 0x%x", vector);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	if (vector & SCAN_COMPLETE_EVENT_ID) {
468c2ecf20Sopenharmony_ci		wl1271_debug(DEBUG_EVENT, "status: 0x%x",
478c2ecf20Sopenharmony_ci			     mbox->scheduled_scan_status);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci		if (wl->scan_wlvif)
508c2ecf20Sopenharmony_ci			wl12xx_scan_completed(wl, wl->scan_wlvif);
518c2ecf20Sopenharmony_ci	}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
548c2ecf20Sopenharmony_ci		wl1271_debug(DEBUG_EVENT,
558c2ecf20Sopenharmony_ci			     "PERIODIC_SCAN_REPORT_EVENT (status 0x%0x)",
568c2ecf20Sopenharmony_ci			     mbox->scheduled_scan_status);
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci		wlcore_scan_sched_scan_results(wl);
598c2ecf20Sopenharmony_ci	}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID)
628c2ecf20Sopenharmony_ci		wlcore_event_sched_scan_completed(wl,
638c2ecf20Sopenharmony_ci						  mbox->scheduled_scan_status);
648c2ecf20Sopenharmony_ci	if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
658c2ecf20Sopenharmony_ci		wlcore_event_soft_gemini_sense(wl,
668c2ecf20Sopenharmony_ci					       mbox->soft_gemini_sense_info);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	if (vector & BSS_LOSE_EVENT_ID)
698c2ecf20Sopenharmony_ci		wlcore_event_beacon_loss(wl, 0xff);
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID)
728c2ecf20Sopenharmony_ci		wlcore_event_rssi_trigger(wl, mbox->rssi_snr_trigger_metric);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)
758c2ecf20Sopenharmony_ci		wlcore_event_ba_rx_constraint(wl,
768c2ecf20Sopenharmony_ci					      BIT(mbox->role_id),
778c2ecf20Sopenharmony_ci					      mbox->rx_ba_allowed);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID)
808c2ecf20Sopenharmony_ci		wlcore_event_channel_switch(wl, 0xff,
818c2ecf20Sopenharmony_ci					    mbox->channel_switch_status);
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	if (vector & DUMMY_PACKET_EVENT_ID)
848c2ecf20Sopenharmony_ci		wlcore_event_dummy_packet(wl);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	/*
878c2ecf20Sopenharmony_ci	 * "TX retries exceeded" has a different meaning according to mode.
888c2ecf20Sopenharmony_ci	 * In AP mode the offending station is disconnected.
898c2ecf20Sopenharmony_ci	 */
908c2ecf20Sopenharmony_ci	if (vector & MAX_TX_RETRY_EVENT_ID)
918c2ecf20Sopenharmony_ci		wlcore_event_max_tx_failure(wl,
928c2ecf20Sopenharmony_ci				le16_to_cpu(mbox->sta_tx_retry_exceeded));
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	if (vector & INACTIVE_STA_EVENT_ID)
958c2ecf20Sopenharmony_ci		wlcore_event_inactive_sta(wl,
968c2ecf20Sopenharmony_ci					  le16_to_cpu(mbox->sta_aging_status));
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	if (vector & REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID)
998c2ecf20Sopenharmony_ci		wlcore_event_roc_complete(wl);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	return 0;
1028c2ecf20Sopenharmony_ci}
103