From patchwork Tue Oct 5 13:53:56 2021 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: 12536805 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 121C2C43217 for ; Tue, 5 Oct 2021 13:57:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3295610EA for ; Tue, 5 Oct 2021 13:57:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236198AbhJEN7B (ORCPT ); Tue, 5 Oct 2021 09:59:01 -0400 Received: from mail-co1nam11on2088.outbound.protection.outlook.com ([40.107.220.88]:52640 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236088AbhJEN5x (ORCPT ); Tue, 5 Oct 2021 09:57:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PvOUwf24J+S4w6HECq3OKr9/dMJSx7CLjdUd7y8jkoiN7P3n7yI8Uzk19xMo72sUYKjuKmV5zb1gFBntWHGqYJ/81n9uF+eMW6dcB5WhoJnCVuqtohYQxJb33Y8nE36nne0wkmDEDM7gYV1nqb1BK00tchlMVcW4g8Am+7P/9hjRs5gNUnx8DWEQQU0G9DIrwftjlrqw91i2JSneVL3K+Fl8vyAqywUbDi7PjV2iQlhjrZOpV6Ph38tYsUTg5w+YI9B8mtJfSkIay2jD8FbC/mwZ93Y9ARROEMXZx9Ohuu9PqOMSd3eMARh6sYBZz8I8KSCekwhT8+qJWzle887JuA== 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=hU0n7knVPWJ6nLLzMJmEZuM53P6meleovWN/Ag+kRQw=; b=kGyP+8xNouxIfHf8qGoBhr4eF55RlxgpHVeJPV3TXrYZdnHCwHGswOIU/+UHYUELbWJr9rZXx01dOsLVAGOfny3FceZ7BUZVTW5OAl9PCplUwgBbxIMwAEvCv5zCFaSXvkLU2uv3PD6njSLSiN3YrdNCFuUi1SXD6gAitbRTPJdv29G5yyFfx38kDKdava1d+mfHz7hEUPJhNrYJBnO/mlAqGIWK/shVlwchuvFrvHC2Z5QozWy/d//f+LCkmEpdmDSNCEMrpSyKNwuOdZhsDp5J8WCtaMwBxV5aX462Ip/NU5/P2kYFN8nY1T4/t8kEvzONjNDoZCpR7TS9AuxRZA== 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=hU0n7knVPWJ6nLLzMJmEZuM53P6meleovWN/Ag+kRQw=; b=Uq5UdN+2V+Y6jtueZMllk5Ze3eGWwg1GJfxvIBym7tBmzqknTQo5OkNcmA5y/TkPFjvcrSXEzWltz94Ai6cj2mQal+5JJ/qfk/p8NRglGCoJCXZT1Ahmtgb4RgT6rao1pxVzRs2Me6+e53sYpgrtOuj3gqopvhPtnEWNw+6nuuI= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=silabs.com; Received: from PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) by PH0PR11MB5642.namprd11.prod.outlook.com (2603:10b6:510:e5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Tue, 5 Oct 2021 13:55:19 +0000 Received: from PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::31cb:3b13:b0e8:d8f4]) by PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::31cb:3b13:b0e8:d8f4%9]) with mapi id 15.20.4566.022; Tue, 5 Oct 2021 13:55:19 +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 v8 20/24] wfx: add scan.c/scan.h Date: Tue, 5 Oct 2021 15:53:56 +0200 Message-Id: <20211005135400.788058-21-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005135400.788058-1-Jerome.Pouiller@silabs.com> References: <20211005135400.788058-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PR3P189CA0084.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::29) To PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) MIME-Version: 1.0 Received: from pc-42.silabs.com (37.71.187.125) by PR3P189CA0084.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Tue, 5 Oct 2021 13:55:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 380c1646-b1cd-4818-0c9b-08d98807c4a6 X-MS-TrafficTypeDiagnostic: PH0PR11MB5642: X-MS-Exchange-Transport-Forked: True 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: ZMRbtdvsHSOJRudeUhsNgUnxrOeJLPZ5xQ5M+biVQFJidLma3/4ULDLuTb5GfLG1+whDWA+AUHCDz5DqEeZ3av44mjTlQTbMsm+7EJ1FSeVgO9261s9JpHURfzZ65vxJxipSL4nrFC4w1UONfgBf/u4rJx8v4HZlmXWPlxVBjwHr88ENt7KR8zI+0twlCqxGnNIMkmMkQIZNb0lNOpMr8nCHMcRavCIMPu5VhQRsJKEevD8aLvKV3ajnxmM9hubjdrHbVnsJkZv/ItoUPVRaT0p2cxWG0VglxQSIRFVb8LX2ZMjQ2Z/BL9f6ot6luE92xwsGR9DasOtVJKloEuHF0jM1tyVt8j49YxIA9GKU+JHlV5STJEq7ig5wDq1ohiocxr64coZT4iXgdnkWcn4p6GqfQ6VNwtde+zW8PXlj2q8OAkUbTOaHAWt33AMUabWH4Eye2TsV2DeKhOTwd4ssSTIplRHqcZyInY0WGdpwna5pW9xDgDmbGMyeTcq5U5jselRCLkk344xTC81nzHf6SclsTAZ7bQueqyhaJnOzvlxfwQ+XV52KFiDOJY06wp6nAShk8FGO4/WPLhSPF/h5FG3wzYhVavtoX6mlRuA+B45Ufs4vwLRyAYnY9qEE/bOd3CvHpbxsv3s9zjVPYYgyiLkm9+793D49TdZRQHTOj4Q3I5UsSwGfrBRLDYKVjiNeAyQi8nYBavje74n65pUxgQ== 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)(86362001)(5660300002)(26005)(52116002)(7696005)(956004)(8676002)(2616005)(38100700002)(8936002)(38350700002)(4326008)(6666004)(186003)(7416002)(6916009)(66574015)(107886003)(83380400001)(36756003)(66476007)(66556008)(508600001)(2906002)(316002)(6486002)(1076003)(66946007)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SBM1Lb00+P96eViDlmRz3V1sNBXW?= =?utf-8?q?Gp26x4t5iG0YTHIAi97qLXyvcyEWek6ro8r/KvfMLXr+CrZuRu1+MmVP1cIISaqCH?= =?utf-8?q?u8nALNTDW4OC3OyM2B8EHBGHwNPlE6NdjWiokze0925dzSIj0HWQaS56ax4NTTCLv?= =?utf-8?q?m3HnBRqxp/2fN3r64el80wBc09FV9PWm1s2UsIQHhc3mLBssdMc+U5Wb7H7lfwhEk?= =?utf-8?q?g6i8JgWuVE8+G7vOgABled0z/vT22G4madu0nFRMs6VhRXox7yvYBw/cniUf6U3UN?= =?utf-8?q?/pH4y1F6dYXax/uTLCWjdPhzbqD1169w4NQFFdz9X+GXX5ZeuGjmOkSdB1RBx+W+n?= =?utf-8?q?+PlR5LVSlKtAgIyk40e58CaBu5dMfke88u6Rn1SoXPf6VZ28RYtE06e9vbUaA/hLx?= =?utf-8?q?W5cyaDlStssrnoJBANh/0zPaw0UrdvjwI3bJGLwuYazzewFrM6p23ePLQD81aRfLf?= =?utf-8?q?19+E9F/SKzHpSVy+OVR39fiKl28hEo2xxPQMiV8pxztd34075VGMTO0yBXCQdBO0Z?= =?utf-8?q?Hyw0uIdg5Yn9QlB1PgPG+9Pxe291Z6Ebfzx7Ict6e4QIBMRQm0vXG0fcZTCAgvy1D?= =?utf-8?q?AbvTXwXvZxDu7td1QvoZUHICQrtVb/rbLAedSMtOLX9nfNX7QfzcmmwZXc+0BDcy4?= =?utf-8?q?CJEsyXhNVwp6HCiuOfrM1hhzpZ65IWl2nazO1UfAFCdEwaKjAZaME1Du5nLtYN3ux?= =?utf-8?q?1zVbsBQ/zwd78NA6wgf4jIUUdDE5atOeZ8lcLfYYMsxbtEg7Thma1jM03OilZ9BBg?= =?utf-8?q?smYJrmFTo0exiMrepR4MvQ+fqnQRCLVfNPGNZ4laPPNzhKrfhgyAOEliCC7hgkdeC?= =?utf-8?q?wzInoBwfQ14tOp3PqW1jtUlrCTFN8HCLttLoBsfnFiJ1CdWlDuOh+CuvVamvUtAp3?= =?utf-8?q?yRAb/RGP8R0pOCEKwCEtIMpSn5MDZLgGYAsBSWi5gvMrcjw0H6PRf0MnxCvjNCGcT?= =?utf-8?q?KEfGzUWrVpNucr+QXN0/Ru0mkkzVlAiVPw0HhmrCFnp/wPqQ4jC4cBJJxHYIKbr8d?= =?utf-8?q?KTwI+YXhGkBbmRO4RCm6n+cJnpJ99djhOcCNRV1xG51+m9dExiIZsI+Pi229Ftarx?= =?utf-8?q?dAv8vsNRGKn2oujgAAo1k7cOp7G8CUWhanlPyPt/f7gkjFxqWHWjGONUFJM0qwBGo?= =?utf-8?q?DJYIXalDaRxULngnO0h9T/QuoMThAu64P6Gdri9QkZmnGKbqSyhXCo2ypERooDgYj?= =?utf-8?q?BBrBD9fWXtu5jZ486ojkI8EBC6cG4dGjsVIPRXgk5/5Wz+jhFqFJdXIIMBgmEpP8f?= =?utf-8?q?QFXkAMA04uic/4Ej?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 380c1646-b1cd-4818-0c9b-08d98807c4a6 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5657.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2021 13:55:19.6554 (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: mFXpHzzkUyOsK0gC0J9WsbaOcra562KJCHfVj672npix13Vwi7GgV63nAv1haxT74X8xvrYLIZprGIUo0I1dag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5642 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 | 148 +++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/scan.h | 22 ++++ 2 files changed, 170 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..a77638e9a294 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/scan.c @@ -0,0 +1,148 @@ +// 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