Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f3bef4b authored by Loic Poulain's avatar Loic Poulain Committed by Kalle Valo
Browse files

wcn36xx: Add hardware scan offload support



Current hw_scan implementation does not trigger offloaded
hardware scan and seems to only put the device in a kind of
listening mode (beacon/probe-response) for software scan.
Since no probe request are generated by the software, current
scanning method is similar to a passive scan.

This patch introduces support for 'true' hardware offloaded scan.
Hardware scan is configured and started via the start-scan-offload
firmware message. Once scan has been completed a scan indicator
message is received from firmware.

Moreover, this patch includes support for directed probe-request,
allowing connection with hidden APs. It also fixes scan issues with
band-steering AP which are not 'visible' with passive scan (due to
hidden ssid in beacons).

Let's keep the 'legacy' scanning method in case scan-offload is not
supported.

Signed-off-by: default avatarLoic Poulain <loic.poulain@linaro.org>
Signed-off-by: default avatarKalle Valo <kvalo@qca.qualcomm.com>
parent d06f26c5
Loading
Loading
Loading
Loading
+102 −5
Original line number Diff line number Diff line
@@ -348,6 +348,13 @@ enum wcn36xx_hal_host_msg_type {
	WCN36XX_HAL_DHCP_START_IND = 189,
	WCN36XX_HAL_DHCP_STOP_IND = 190,

	/* Scan Offload(hw) APIs */
	WCN36XX_HAL_START_SCAN_OFFLOAD_REQ = 204,
	WCN36XX_HAL_START_SCAN_OFFLOAD_RSP = 205,
	WCN36XX_HAL_STOP_SCAN_OFFLOAD_REQ = 206,
	WCN36XX_HAL_STOP_SCAN_OFFLOAD_RSP = 207,
	WCN36XX_HAL_SCAN_OFFLOAD_IND = 210,

	WCN36XX_HAL_AVOID_FREQ_RANGE_IND = 233,

	WCN36XX_HAL_PRINT_REG_INFO_IND = 259,
@@ -1115,6 +1122,101 @@ struct wcn36xx_hal_finish_scan_rsp_msg {

} __packed;

enum wcn36xx_hal_scan_type {
	WCN36XX_HAL_SCAN_TYPE_PASSIVE = 0x00,
	WCN36XX_HAL_SCAN_TYPE_ACTIVE = WCN36XX_HAL_MAX_ENUM_SIZE
};

struct wcn36xx_hal_mac_ssid {
	u8 length;
	u8 ssid[32];
} __packed;

struct wcn36xx_hal_start_scan_offload_req_msg {
	struct wcn36xx_hal_msg_header header;

	/* BSSIDs hot list */
	u8 num_bssid;
	u8 bssids[4][ETH_ALEN];

	/* Directed probe-requests will be sent for listed SSIDs (max 10)*/
	u8 num_ssid;
	struct wcn36xx_hal_mac_ssid ssids[10];

	/* Report AP with hidden ssid */
	u8 scan_hidden;

	/* Self MAC address */
	u8 mac[ETH_ALEN];

	/* BSS type */
	enum wcn36xx_hal_bss_type bss_type;

	/* Scan type */
	enum wcn36xx_hal_scan_type scan_type;

	/* Minimum scanning time on each channel (ms) */
	u32 min_ch_time;

	/* Maximum scanning time on each channel */
	u32 max_ch_time;

	/* Is a p2p search */
	u8 p2p_search;

	/* Channels to scan */
	u8 num_channel;
	u8 channels[80];

	/* IE field */
	u16 ie_len;
	u8 ie[0];
} __packed;

struct wcn36xx_hal_start_scan_offload_rsp_msg {
	struct wcn36xx_hal_msg_header header;

	/* success or failure */
	u32 status;
} __packed;

enum wcn36xx_hal_scan_offload_ind_type {
	/* Scan has been started */
	WCN36XX_HAL_SCAN_IND_STARTED = 0x01,
	/* Scan has been completed */
	WCN36XX_HAL_SCAN_IND_COMPLETED = 0x02,
	/* Moved to foreign channel */
	WCN36XX_HAL_SCAN_IND_FOREIGN_CHANNEL = 0x08,
	/* scan request has been dequeued */
	WCN36XX_HAL_SCAN_IND_DEQUEUED = 0x10,
	/* preempted by other high priority scan */
	WCN36XX_HAL_SCAN_IND_PREEMPTED = 0x20,
	/* scan start failed */
	WCN36XX_HAL_SCAN_IND_FAILED = 0x40,
	 /*scan restarted */
	WCN36XX_HAL_SCAN_IND_RESTARTED = 0x80,
	WCN36XX_HAL_SCAN_IND_MAX = WCN36XX_HAL_MAX_ENUM_SIZE
};

struct wcn36xx_hal_scan_offload_ind {
	struct wcn36xx_hal_msg_header header;

	u32 type;
	u32 channel_mhz;
	u32 scan_id;
} __packed;

struct wcn36xx_hal_stop_scan_offload_req_msg {
	struct wcn36xx_hal_msg_header header;
} __packed;

struct wcn36xx_hal_stop_scan_offload_rsp_msg {
	struct wcn36xx_hal_msg_header header;

	/* success or failure */
	u32 status;
} __packed;

enum wcn36xx_hal_rate_index {
	HW_RATE_INDEX_1MBPS	= 0x82,
	HW_RATE_INDEX_2MBPS	= 0x84,
@@ -1507,11 +1609,6 @@ struct wcn36xx_hal_edca_param_record {
	u16 txop_limit;
} __packed;

struct wcn36xx_hal_mac_ssid {
	u8 length;
	u8 ssid[32];
} __packed;

/* Concurrency role. These are generic IDs that identify the various roles
 *  in the software system. */
enum wcn36xx_hal_con_mode {
+13 −3
Original line number Diff line number Diff line
@@ -629,7 +629,6 @@ static int wcn36xx_hw_scan(struct ieee80211_hw *hw,
			   struct ieee80211_scan_request *hw_req)
{
	struct wcn36xx *wcn = hw->priv;

	mutex_lock(&wcn->scan_lock);
	if (wcn->scan_req) {
		mutex_unlock(&wcn->scan_lock);
@@ -638,18 +637,29 @@ static int wcn36xx_hw_scan(struct ieee80211_hw *hw,

	wcn->scan_aborted = false;
	wcn->scan_req = &hw_req->req;

	mutex_unlock(&wcn->scan_lock);

	if (!get_feat_caps(wcn->fw_feat_caps, SCAN_OFFLOAD)) {
		/* legacy manual/sw scan */
		schedule_work(&wcn->scan_work);

		return 0;
	}

	return wcn36xx_smd_start_hw_scan(wcn, vif, &hw_req->req);
}

static void wcn36xx_cancel_hw_scan(struct ieee80211_hw *hw,
				   struct ieee80211_vif *vif)
{
	struct wcn36xx *wcn = hw->priv;

	if (!wcn36xx_smd_stop_hw_scan(wcn)) {
		struct cfg80211_scan_info scan_info = { .aborted = true };

		ieee80211_scan_completed(wcn->hw, &scan_info);
	}

	mutex_lock(&wcn->scan_lock);
	wcn->scan_aborted = true;
	mutex_unlock(&wcn->scan_lock);
+120 −0
Original line number Diff line number Diff line
@@ -615,6 +615,85 @@ int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
	return ret;
}

int wcn36xx_smd_start_hw_scan(struct wcn36xx *wcn, struct ieee80211_vif *vif,
			      struct cfg80211_scan_request *req)
{
	struct wcn36xx_hal_start_scan_offload_req_msg msg_body;
	int ret, i;

	mutex_lock(&wcn->hal_mutex);
	INIT_HAL_MSG(msg_body, WCN36XX_HAL_START_SCAN_OFFLOAD_REQ);

	msg_body.scan_type = WCN36XX_HAL_SCAN_TYPE_ACTIVE;
	msg_body.min_ch_time = 30;
	msg_body.min_ch_time = 100;
	msg_body.scan_hidden = 1;
	memcpy(msg_body.mac, vif->addr, ETH_ALEN);
	msg_body.p2p_search = vif->p2p;

	msg_body.num_ssid = min_t(u8, req->n_ssids, ARRAY_SIZE(msg_body.ssids));
	for (i = 0; i < msg_body.num_ssid; i++) {
		msg_body.ssids[i].length = min_t(u8, req->ssids[i].ssid_len,
						sizeof(msg_body.ssids[i].ssid));
		memcpy(msg_body.ssids[i].ssid, req->ssids[i].ssid,
		       msg_body.ssids[i].length);
	}

	msg_body.num_channel = min_t(u8, req->n_channels,
				     sizeof(msg_body.channels));
	for (i = 0; i < msg_body.num_channel; i++)
		msg_body.channels[i] = req->channels[i]->hw_value;

	PREPARE_HAL_BUF(wcn->hal_buf, msg_body);

	wcn36xx_dbg(WCN36XX_DBG_HAL,
		    "hal start hw-scan (channels: %u; ssids: %u; p2p: %s)\n",
		    msg_body.num_channel, msg_body.num_ssid,
		    msg_body.p2p_search ? "yes" : "no");

	ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
	if (ret) {
		wcn36xx_err("Sending hal_start_scan_offload failed\n");
		goto out;
	}
	ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
	if (ret) {
		wcn36xx_err("hal_start_scan_offload response failed err=%d\n",
			    ret);
		goto out;
	}
out:
	mutex_unlock(&wcn->hal_mutex);
	return ret;
}

int wcn36xx_smd_stop_hw_scan(struct wcn36xx *wcn)
{
	struct wcn36xx_hal_stop_scan_offload_req_msg msg_body;
	int ret;

	mutex_lock(&wcn->hal_mutex);
	INIT_HAL_MSG(msg_body, WCN36XX_HAL_STOP_SCAN_OFFLOAD_REQ);
	PREPARE_HAL_BUF(wcn->hal_buf, msg_body);

	wcn36xx_dbg(WCN36XX_DBG_HAL, "hal stop hw-scan\n");

	ret = wcn36xx_smd_send_and_wait(wcn, msg_body.header.len);
	if (ret) {
		wcn36xx_err("Sending hal_stop_scan_offload failed\n");
		goto out;
	}
	ret = wcn36xx_smd_rsp_status_check(wcn->hal_buf, wcn->hal_rsp_len);
	if (ret) {
		wcn36xx_err("hal_stop_scan_offload response failed err=%d\n",
			    ret);
		goto out;
	}
out:
	mutex_unlock(&wcn->hal_mutex);
	return ret;
}

static int wcn36xx_smd_switch_channel_rsp(void *buf, size_t len)
{
	struct wcn36xx_hal_switch_channel_rsp_msg *rsp;
@@ -2041,6 +2120,40 @@ static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len)
	return 0;
}

static int wcn36xx_smd_hw_scan_ind(struct wcn36xx *wcn, void *buf, size_t len)
{
	struct wcn36xx_hal_scan_offload_ind *rsp = buf;
	struct cfg80211_scan_info scan_info = {};

	if (len != sizeof(*rsp)) {
		wcn36xx_warn("Corrupted delete scan indication\n");
		return -EIO;
	}

	wcn36xx_dbg(WCN36XX_DBG_HAL, "scan indication (type %x)", rsp->type);

	switch (rsp->type) {
	case WCN36XX_HAL_SCAN_IND_FAILED:
		scan_info.aborted = true;
	case WCN36XX_HAL_SCAN_IND_COMPLETED:
		mutex_lock(&wcn->scan_lock);
		wcn->scan_req = NULL;
		mutex_unlock(&wcn->scan_lock);
		ieee80211_scan_completed(wcn->hw, &scan_info);
		break;
	case WCN36XX_HAL_SCAN_IND_STARTED:
	case WCN36XX_HAL_SCAN_IND_FOREIGN_CHANNEL:
	case WCN36XX_HAL_SCAN_IND_DEQUEUED:
	case WCN36XX_HAL_SCAN_IND_PREEMPTED:
	case WCN36XX_HAL_SCAN_IND_RESTARTED:
		break;
	default:
		wcn36xx_warn("Unknown scan indication type %x\n", rsp->type);
	}

	return 0;
}

static int wcn36xx_smd_missed_beacon_ind(struct wcn36xx *wcn,
					 void *buf,
					 size_t len)
@@ -2252,6 +2365,8 @@ int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
	case WCN36XX_HAL_CH_SWITCH_RSP:
	case WCN36XX_HAL_FEATURE_CAPS_EXCHANGE_RSP:
	case WCN36XX_HAL_8023_MULTICAST_LIST_RSP:
	case WCN36XX_HAL_START_SCAN_OFFLOAD_RSP:
	case WCN36XX_HAL_STOP_SCAN_OFFLOAD_RSP:
		memcpy(wcn->hal_buf, buf, len);
		wcn->hal_rsp_len = len;
		complete(&wcn->hal_rsp_compl);
@@ -2264,6 +2379,7 @@ int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
	case WCN36XX_HAL_MISSED_BEACON_IND:
	case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
	case WCN36XX_HAL_PRINT_REG_INFO_IND:
	case WCN36XX_HAL_SCAN_OFFLOAD_IND:
		msg_ind = kmalloc(sizeof(*msg_ind) + len, GFP_ATOMIC);
		if (!msg_ind) {
			wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
@@ -2328,6 +2444,10 @@ static void wcn36xx_ind_smd_work(struct work_struct *work)
					       hal_ind_msg->msg,
					       hal_ind_msg->msg_len);
		break;
	case WCN36XX_HAL_SCAN_OFFLOAD_IND:
		wcn36xx_smd_hw_scan_ind(wcn, hal_ind_msg->msg,
					hal_ind_msg->msg_len);
		break;
	default:
		wcn36xx_err("SMD_EVENT (%d) not supported\n",
			      msg_header->msg_type);
+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ int wcn36xx_smd_end_scan(struct wcn36xx *wcn, u8 scan_channel);
int wcn36xx_smd_finish_scan(struct wcn36xx *wcn,
			    enum wcn36xx_hal_sys_mode mode);
int wcn36xx_smd_update_scan_params(struct wcn36xx *wcn, u8 *channels, size_t channel_count);
int wcn36xx_smd_start_hw_scan(struct wcn36xx *wcn, struct ieee80211_vif *vif,
			      struct cfg80211_scan_request *req);
int wcn36xx_smd_stop_hw_scan(struct wcn36xx *wcn);
int wcn36xx_smd_add_sta_self(struct wcn36xx *wcn, struct ieee80211_vif *vif);
int wcn36xx_smd_delete_sta_self(struct wcn36xx *wcn, u8 *addr);
int wcn36xx_smd_delete_sta(struct wcn36xx *wcn, u8 sta_index);