Skip to contentSkip to conversation

wcn36xx: Add hardware scan offload support

PATCH In review Loic Poulain 4 participants 6 messages Dec 8, 2017 – Dec 14, 2017 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/net/wireless/ath/wcn36xx/hal.h  | 107 ++++++++++++++++++++++++++--
 drivers/net/wireless/ath/wcn36xx/main.c |  16 ++++-
 drivers/net/wireless/ath/wcn36xx/smd.c  | 120 ++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath/wcn36xx/smd.h  |   3 +
 4 files changed, 238 insertions(+), 8 deletions(-)
drivers/net/wireless/ath/wcn36xx/hal.h +102 -5
index b765c64..1829635 100644
@@ -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 {
drivers/net/wireless/ath/wcn36xx/main.c +13 -3
index b83f01d..6dd4d57 100644
@@ -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,11 +637,16 @@ static int wcn36xx_hw_scan(struct ieee80211_hw *hw,
 
 	wcn->scan_aborted = false;
 	wcn->scan_req = &hw_req->req;
+
 	mutex_unlock(&wcn->scan_lock);
 
-	schedule_work(&wcn->scan_work);
+	if (!get_feat_caps(wcn->fw_feat_caps, SCAN_OFFLOAD)) {
+		/* legacy manual/sw scan */
+		schedule_work(&wcn->scan_work);
+		return 0;
+	}
 
-	return 0;
+	return wcn36xx_smd_start_hw_scan(wcn, vif, &hw_req->req);
 }
 
 static void wcn36xx_cancel_hw_scan(struct ieee80211_hw *hw,
@@ -650,6 +654,12 @@ static void wcn36xx_cancel_hw_scan(struct ieee80211_hw *hw,
 {
 	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);
drivers/net/wireless/ath/wcn36xx/smd.c +120 -0

150 lines not on this page · raw message

drivers/net/wireless/ath/wcn36xx/smd.h +3 -0
index 013fc95..8076edf 100644
@@ -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);
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Loic Poulain

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.

Quoted 5 lines

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).

I'm puzzled to why I didn't see this when I dumped the control channel that lead up to the initial hw_scan patch. But this looks good and with a related locking issue fixed this seems to work well.

Quoted 1 line
drivers/net/wireless/ath/wcn36xx/smd.c +0 -0

[..]

Quoted 7 lines
drivers/net/wireless/ath/wcn36xx/smd.c +7 -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");

drivers/net/wireless/ath/wcn36xx/smd.c static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len) · line 2137

Quoted 10 lines
drivers/net/wireless/ath/wcn36xx/smd.c +10 -0
+		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);

Grabbing this mutex with DEBUG_ATOMIC_SLEEP causes issues, but that's because the locking in ind_smd_work() is to excessive. Will reply with a fix for this.

drivers/net/wireless/ath/wcn36xx/smd.c static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len) · line 2141

Quoted 4 lines
drivers/net/wireless/ath/wcn36xx/smd.c +4 -0
+		wcn->scan_req = NULL;
+		mutex_unlock(&wcn->scan_lock);
+		ieee80211_scan_completed(wcn->hw, &scan_info);
+		break;

Regards,
Bjorn

#2 lore raw

Hi Bjorn,

Quoted 16 lines · Bjorn Andersson
Quoted 2 lines
drivers/net/wireless/ath/wcn36xx/smd.c +0 -0

[..]

Quoted 13 lines
drivers/net/wireless/ath/wcn36xx/smd.c +13 -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) {
Quoted 8 lines

drivers/net/wireless/ath/wcn36xx/smd.c static int wcn36xx_smd_tx_compl_ind(struct wcn36xx *wcn, void *buf, size_t len) · line 2137

Quoted 4 lines
drivers/net/wireless/ath/wcn36xx/smd.c +4 -0
+     case WCN36XX_HAL_SCAN_IND_FAILED:
+             scan_info.aborted = true;
+     case WCN36XX_HAL_SCAN_IND_COMPLETED:
+             mutex_lock(&wcn->scan_lock);

Grabbing this mutex with DEBUG_ATOMIC_SLEEP causes issues, but that's because the locking in ind_smd_work() is to excessive. Will reply with a fix for this.

Oops you're right, thanks for the patch.

Regards,
Loic

#3 lore raw

PATCH 1/1 wcn36xx: Reduce spinlock in indication handler

In reply to Loic Poulain

The purpose of pushing indication on a list and handle these in a separate worker is to allow the handlers to sleep. It does therefor not make much sense to hold the queue spinlock through the entire indication worker function.

By removing items from the queue early we don't need to hold the lock throughout the indication worker, allowing the individual handlers to sleep.

---
 drivers/net/wireless/ath/wcn36xx/smd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/wcn36xx/smd.c +2 -2
index fa88a2a460aa..52daae863aed 100644
@@ -2414,6 +2414,8 @@ static void wcn36xx_ind_smd_work(struct work_struct *work)
 	hal_ind_msg = list_first_entry(&wcn->hal_ind_queue,
 				       struct wcn36xx_hal_ind_msg,
 				       list);
+	list_del(wcn->hal_ind_queue.next);
+	spin_unlock_irqrestore(&wcn->hal_ind_lock, flags);
 
 	msg_header = (struct wcn36xx_hal_msg_header *)hal_ind_msg->msg;
 
@@ -2450,8 +2452,6 @@ static void wcn36xx_ind_smd_work(struct work_struct *work)
 		wcn36xx_err("SMD_EVENT (%d) not supported\n",
 			      msg_header->msg_type);
 	}
-	list_del(wcn->hal_ind_queue.next);
-	spin_unlock_irqrestore(&wcn->hal_ind_lock, flags);
 	kfree(hal_ind_msg);
 }
 int wcn36xx_smd_open(struct wcn36xx *wcn)
Signature · 1 line
2.15.0
#4 lore raw

Re: wcn36xx: Reduce spinlock in indication handler

Quoted 11 lines · Bjorn Andersson

The purpose of pushing indication on a list and handle these in a separate worker is to allow the handlers to sleep. It does therefor not make much sense to hold the queue spinlock through the entire indication worker function.

By removing items from the queue early we don't need to hold the lock throughout the indication worker, allowing the individual handlers to sleep.

Patch applied to ath-next branch of ath.git, thanks.

6d1f37323f5b wcn36xx: Reduce spinlock in indication handler

Signature · 3 lines
https://patchwork.kernel.org/patch/10103469/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

A message that is not in the archive (sent off-list or not yet received): 1512725730-19188-1-git-send-email-loic.poulain-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org

#6 lore raw
Quoted 16 lines · Loic Poulain

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).

Quoted 5 lines

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

Patch applied to ath-next branch of ath.git, thanks.

2f3bef4b247e wcn36xx: Add hardware scan offload support

Signature · 3 lines
https://patchwork.kernel.org/patch/10101937/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches