From patchwork Tue Jan 11 17:14:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 12710139 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4FABC433EF for ; Tue, 11 Jan 2022 17:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344568AbiAKRR4 (ORCPT ); Tue, 11 Jan 2022 12:17:56 -0500 Received: from mail-co1nam11on2055.outbound.protection.outlook.com ([40.107.220.55]:7776 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1344274AbiAKRQ0 (ORCPT ); Tue, 11 Jan 2022 12:16:26 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DXjrXIz6J4iagDqWJQx0iH+LaP7xC6YJQHNw/mH3zwk2Yd4hpoWNyJ7dGUcmYk8ERgYabvkeBjErR9MZpNppjdx3ALRYZrvoegMzL8zm8lgJNd0oVb9DHutMMCKW9InuTYqZFJvwq8xCVxQwiCDXbGz8bHfSHtA+FhaOgBlZLz1IEjMBQhaMox+GFPhaULdOEoxC6T7YFT7pkhabNvvFYT7ARCi6BCGbof6+wuxS0kwJ4qOU+MixNC5YoVXnRXBrfsqJcTEixi8yqlRsaycIehCya+hsI6F3hPHRKloQRlw3oVOw2jq++PC4LIXYbrrmEp0VLz6DXIf6K18vFSUDwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SUV4Qx2xAHfWPtLqC0k6XS5ZsZqHukeuq3nR01y+l7Q=; b=W9zR//A6FsCWqSvURGMOyoWbK8+q2ofyTpmLx6oVxTzKUUmY1+4XAsQkDDxB6oUmpfAkqRu+a/IOUiAGZVD7mk+QaEEuPqnAPKRObxbAwvj8kgYFCOPB0UlzDAornj+bpc6KXdpEx7iqEO2esDbTIRWDs7YOEB/NX0ji9vivERF6nz+qA35dNUPYGRw+3/9OTSV2jOjaOJ4WPPbZOiqyn/KUyeiYwdIPM4icibYkMIeOuavi/7G5gcMlaBcl/aNizgSdc6fpdZOAut7yh0YSeZNrXE+6tDlN6mAtE8cZPaQy2771L0KrW4YZ1fa0U9NzXk57FrNNVhTX1i68GF4yaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SUV4Qx2xAHfWPtLqC0k6XS5ZsZqHukeuq3nR01y+l7Q=; b=A1tRelJK5CgqwqgCy4VhH/YJfyBGnDK/nLIIQ92ODh7jvk7G3SDAin8CwUKPxr/Wd71s3fkHrIEzqJYiCigzEy4Xz06WY66rEhgqNhcLbJ/vNpgtqJOL6CnOGx8hwmMwPVThBUQyqo8Fqm0ksD40ZQm/M1E3/5qJLQHka3AujeU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=silabs.com; Received: from PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) by PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.11; Tue, 11 Jan 2022 17:15:39 +0000 Received: from PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::d031:da9e:71a:73e4]) by PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::d031:da9e:71a:73e4%6]) with mapi id 15.20.4867.012; Tue, 11 Jan 2022 17:15:39 +0000 From: Jerome Pouiller To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Kalle Valo Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "David S . Miller" , devicetree@vger.kernel.org, Rob Herring , linux-mmc@vger.kernel.org, =?utf-8?q?Pali?= =?utf-8?q?_Roh=C3=A1r?= , Ulf Hansson , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v9 20/24] wfx: add scan.c/scan.h Date: Tue, 11 Jan 2022 18:14:20 +0100 Message-Id: <20220111171424.862764-21-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220111171424.862764-1-Jerome.Pouiller@silabs.com> References: <20220111171424.862764-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SN1PR12CA0099.namprd12.prod.outlook.com (2603:10b6:802:21::34) To PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 147edad4-c244-4975-4107-08d9d525fd2c X-MS-TrafficTypeDiagnostic: PH0PR11MB5657:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YKj/+/2fLJtkYGc0hR+nOz8EDTiwaJp61czX9lF70o5Y7fthxPHLA/wripFoA1k45pHip7jHPy5tnfoQMR+wwOq/mpkryhIgriiY9WkN5wMEosL90+a90JPR5XgamrfTCz8VvEIwfFGHIzoprw+rIRPocnlCHmxRS8SgVfkkxPHPeIdOLIQX3hpN2s8TtlxKfrm01mD/rQQNwLOg5uuSodtI13SYF0D0ftSTB7pI/T1AXsfpemup0x/AqCahRq3ArCZ7yWEiKf7cweeym6rmeUzz1mJ1naT+U/0s5fRV/1V8crgN/x5dPsXJBSjXj3h4SO8UIsdhUgBX89CCAywLCYdb2zbnphltGVKoUU+IxMHBsb61WNPahdGkVeHCPTnYuDH8IDf+i/GFY9vanP1C7dHKlQWMhg8YiKSh5u7pajt4zm6kQX3TDD2UqBkI9JZ4jiHja+w5B/w41xv64/FcMq1KZ+cFA59A1LwTLmUjTcDmLvhQ9dSYQ1wNCu4H8yyiXU7unc94m8jvw0k/A/yMWAsJHRV43Ssw5SuY1BQKkR3MpTBCsFw2XmElha24ndxMWzpH8rVTvh2cNUzfFbK+hw/t2mQJel7axGaQHVFty2IJZ6q5CTTWPWXSD/OmpHwwSOrPLozDbq7CMnPJO9ZD+A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR11MB5657.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(6506007)(66574015)(86362001)(5660300002)(8936002)(7416002)(6916009)(8676002)(83380400001)(1076003)(6486002)(36756003)(38100700002)(186003)(66946007)(6666004)(2616005)(4326008)(2906002)(316002)(107886003)(66556008)(66476007)(54906003)(6512007)(508600001)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hbtECpn54psS+u0ZlQQ5449iQhB5?= =?utf-8?q?03FrgocGaP6Y/9Pd3UNRsA0Fu7BGPi5pmKayWzO2cUzA17qYaiDmG+6KfM2xQZvly?= =?utf-8?q?9WJveW79VdDDQIBGVgAwhfSkjzYZ0mkQTK/fGhNBt+PgcQrD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IyJhBfTTciWPGIsg?= =?utf-8?q?xfFrKGQVrUmUl8penN8zM+1/DDtN5zVh+/anF+8454FWktVoidggchPRZasMzHTqK?= =?utf-8?q?DBwGYWdaZzEzvl73E6nfNRmZwWPbhZtxBxBJnVw/TOOedtlr++NrQYrFZHUvo9Xr9?= =?utf-8?q?/XLLN8LnqWKSxSqj4dfixf9riteDftNmNxDg34D9cqyfTMA7UfoIaj4cm3BJSarOW?= =?utf-8?q?cLUh22HVMAxBX2jiOp98H/Dmux4RMRzhupyVTNLQNCQJ7LW3NU7Q8BKrv6f7uSwbC?= =?utf-8?q?QMNyfGFBgnTGNKF9baNwYB3KtasfkBvlFUMC1UpcVsS0xVr2JheWPtg508UlQpVWK?= =?utf-8?q?HrpHOhQt1jgk2GV5IOXVu+Capccmt040U2qsMb+NtLw0Ba87iC/jWsfmnco4ZcFM8?= =?utf-8?q?tfIxwsEgwduXJr7FxmnF5s/ErVQvrlTozJQWbuvigvoLRpmXpN0vflMedKAIcN2ph?= =?utf-8?q?yOwPoFJX/L2nsd6t2ILw/FJRPTDda3rV80MJbRzEOVBxZDWU4dOu+gI7hlHb5B5TC?= =?utf-8?q?f2NgtD7v5OxIgdRUpE2dnEwsqUnjUiiiK1IZN5jxNA+oU9tUvRcMa1c/Dy60Iqspa?= =?utf-8?q?taU+MFKeqNusbVhFkQqvet9JZQUv/CJlCy/rizpc88FKhkbFndzCRQ=3D?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 147edad4-c244-4975-4107-08d9d525fd2c X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5657.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2022 17:15:38.9708 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Q3nftuR3nQLjWM/MVsJBzRNFa6cvqz26YvfMOS7WMd43iVs+olJ6lfVw2NeB01j1vraalPl1XyuUfH8SFbK6ZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5657 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller Signed-off-by: Jérôme Pouiller --- drivers/net/wireless/silabs/wfx/scan.c | 144 +++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/scan.h | 22 ++++ 2 files changed, 166 insertions(+) create mode 100644 drivers/net/wireless/silabs/wfx/scan.c create mode 100644 drivers/net/wireless/silabs/wfx/scan.h diff --git a/drivers/net/wireless/silabs/wfx/scan.c b/drivers/net/wireless/silabs/wfx/scan.c new file mode 100644 index 000000000000..7f34f0d322f9 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/scan.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Scan related functions. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#include + +#include "scan.h" +#include "wfx.h" +#include "sta.h" +#include "hif_tx_mib.h" + +static void wfx_ieee80211_scan_completed_compat(struct ieee80211_hw *hw, bool aborted) +{ + struct cfg80211_scan_info info = { + .aborted = aborted, + }; + + ieee80211_scan_completed(hw, &info); +} + +static int update_probe_tmpl(struct wfx_vif *wvif, struct cfg80211_scan_request *req) +{ + struct sk_buff *skb; + + skb = ieee80211_probereq_get(wvif->wdev->hw, wvif->vif->addr, NULL, 0, req->ie_len); + if (!skb) + return -ENOMEM; + + skb_put_data(skb, req->ie, req->ie_len); + wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_PRBREQ, 0); + dev_kfree_skb(skb); + return 0; +} + +static int send_scan_req(struct wfx_vif *wvif, struct cfg80211_scan_request *req, int start_idx) +{ + int i, ret; + struct ieee80211_channel *ch_start, *ch_cur; + + for (i = start_idx; i < req->n_channels; i++) { + ch_start = req->channels[start_idx]; + ch_cur = req->channels[i]; + WARN(ch_cur->band != NL80211_BAND_2GHZ, "band not supported"); + if (ch_cur->max_power != ch_start->max_power) + break; + if ((ch_cur->flags ^ ch_start->flags) & IEEE80211_CHAN_NO_IR) + break; + } + wfx_tx_lock_flush(wvif->wdev); + wvif->scan_abort = false; + reinit_completion(&wvif->scan_complete); + ret = wfx_hif_scan(wvif, req, start_idx, i - start_idx); + if (ret) { + wfx_tx_unlock(wvif->wdev); + return -EIO; + } + ret = wait_for_completion_timeout(&wvif->scan_complete, 1 * HZ); + if (!ret) { + wfx_hif_stop_scan(wvif); + ret = wait_for_completion_timeout(&wvif->scan_complete, 1 * HZ); + dev_dbg(wvif->wdev->dev, "scan timeout (%d channels done)\n", + wvif->scan_nb_chan_done); + } + if (!ret) { + dev_err(wvif->wdev->dev, "scan didn't stop\n"); + ret = -ETIMEDOUT; + } else if (wvif->scan_abort) { + dev_notice(wvif->wdev->dev, "scan abort\n"); + ret = -ECONNABORTED; + } else if (wvif->scan_nb_chan_done > i - start_idx) { + ret = -EIO; + } else { + ret = wvif->scan_nb_chan_done; + } + if (req->channels[start_idx]->max_power != wvif->vif->bss_conf.txpower) + wfx_hif_set_output_power(wvif, wvif->vif->bss_conf.txpower); + wfx_tx_unlock(wvif->wdev); + return ret; +} + +/* It is not really necessary to run scan request asynchronously. However, + * there is a bug in "iw scan" when ieee80211_scan_completed() is called before + * wfx_hw_scan() return + */ +void wfx_hw_scan_work(struct work_struct *work) +{ + struct wfx_vif *wvif = container_of(work, struct wfx_vif, scan_work); + struct ieee80211_scan_request *hw_req = wvif->scan_req; + int chan_cur, ret, err; + + mutex_lock(&wvif->wdev->conf_mutex); + mutex_lock(&wvif->scan_lock); + if (wvif->join_in_progress) { + dev_info(wvif->wdev->dev, "abort in-progress REQ_JOIN"); + wfx_reset(wvif); + } + update_probe_tmpl(wvif, &hw_req->req); + chan_cur = 0; + err = 0; + do { + ret = send_scan_req(wvif, &hw_req->req, chan_cur); + if (ret > 0) { + chan_cur += ret; + err = 0; + } + if (!ret) + err++; + if (err > 2) { + dev_err(wvif->wdev->dev, "scan has not been able to start\n"); + ret = -ETIMEDOUT; + } + } while (ret >= 0 && chan_cur < hw_req->req.n_channels); + mutex_unlock(&wvif->scan_lock); + mutex_unlock(&wvif->wdev->conf_mutex); + wfx_ieee80211_scan_completed_compat(wvif->wdev->hw, ret < 0); +} + +int wfx_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + struct ieee80211_scan_request *hw_req) +{ + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; + + WARN_ON(hw_req->req.n_channels > HIF_API_MAX_NB_CHANNELS); + wvif->scan_req = hw_req; + schedule_work(&wvif->scan_work); + return 0; +} + +void wfx_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) +{ + struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv; + + wvif->scan_abort = true; + wfx_hif_stop_scan(wvif); +} + +void wfx_scan_complete(struct wfx_vif *wvif, int nb_chan_done) +{ + wvif->scan_nb_chan_done = nb_chan_done; + complete(&wvif->scan_complete); +} diff --git a/drivers/net/wireless/silabs/wfx/scan.h b/drivers/net/wireless/silabs/wfx/scan.h new file mode 100644 index 000000000000..78e3b984f375 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/scan.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Scan related functions. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#ifndef WFX_SCAN_H +#define WFX_SCAN_H + +#include + +struct wfx_dev; +struct wfx_vif; + +void wfx_hw_scan_work(struct work_struct *work); +int wfx_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + struct ieee80211_scan_request *req); +void wfx_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif); +void wfx_scan_complete(struct wfx_vif *wvif, int nb_chan_done); + +#endif