From patchwork Mon Sep 20 16:11:32 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: 12505935 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80860C433FE for ; Mon, 20 Sep 2021 16:15:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 686EE61175 for ; Mon, 20 Sep 2021 16:15:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243786AbhITQQr (ORCPT ); Mon, 20 Sep 2021 12:16:47 -0400 Received: from mail-bn7nam10on2058.outbound.protection.outlook.com ([40.107.92.58]:43040 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S243177AbhITQO4 (ORCPT ); Mon, 20 Sep 2021 12:14:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OcNpPUasR156CwNhHb92+ZV5i+WO5bFIWzlbpZ4mLT+kuPbGMboQSlPT4AblMfSqahTtXlGmvCAXkuPZE4HEWOwjHVEBVMrHV7TKNkLH2+MdXrapt+pLZ3wvi/SEY9gkClPtg3R62/O3Q9xxFBmQMMxcTrtgBnwI+9ldhruKkmBX3hs8sc2cQuWdI5NWG0gVJq2jivty4Vb1vgWyzc3pTPyjMMvbSBboZmq8qmjtrXb4YhLxQCWT+3hkL/aPc2WexcyxxKmo4TqmFaIEj2MmIA2R+zTiiLjuvYNq9MHY+Sb7r03d0/io1gJnE67ojWap7J32KLFY2qyCJVK+1vB7GA== 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; bh=dEk3+qj4e1ksJvrrPFbprdR/znDZKjI5IcYfuaq0J5c=; b=dzrV5Zm7UVVLVlDa+iGcf/unJ+JX7BsixASfmHs26dvVWRjqCCxWAZ3RdGkwmcJQia9uHg3Nrn2a68xGg0HETVMtvPfibQKPGwxrYKNgmanSLgklAUo/vvsdaRuNz5LM8Jn8AjUOPOTdlNCCZz8grTrDczqV8jZuKalh1A5h4HZ3L/MQjwtk32/8SAQjIkDXAgFURq3sMJtuq8Bv5X7jMTgYLxddZn/EWNpGsVZE5PTxo6L4Iy5GwasT2S78iZLg+82HstgMvZrCWOr3nj3NK/0Gu4qiPB8jZBu/0Y4Poe0u+WSlP72zYZ6N3E9SLifzn2l9H6S2nHq7RsdRaqswgw== 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=dEk3+qj4e1ksJvrrPFbprdR/znDZKjI5IcYfuaq0J5c=; b=BO294GIqUn4AgVhyp54eq9tcV3+a+Vaonv+yhiDZTnC92uI+FCvXL0XjurehuiMpUxfRcxfhgqMyc/Vlw8FDO0XZ5agd0YUczedBELarwOA6FCt81yDcMkoBQqeGSA5pHmpzMxjgNjJrJ9xvKp1HQi1WuYLyukR/YDWeRMOftqs= 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 SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) by SN6PR11MB3168.namprd11.prod.outlook.com (2603:10b6:805:c4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.18; Mon, 20 Sep 2021 16:12:43 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd%7]) with mapi id 15.20.4523.018; Mon, 20 Sep 2021 16:12:43 +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 v7 20/24] wfx: add scan.c/scan.h Date: Mon, 20 Sep 2021 18:11:32 +0200 Message-Id: <20210920161136.2398632-21-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920161136.2398632-1-Jerome.Pouiller@silabs.com> References: <20210920161136.2398632-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SA0PR11CA0064.namprd11.prod.outlook.com (2603:10b6:806:d2::9) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 Received: from pc-42.silabs.com (2a01:e34:ecb5:66a0:9876:e1d7:65be:d294) by SA0PR11CA0064.namprd11.prod.outlook.com (2603:10b6:806:d2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 16:12:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a3306306-46db-43cd-580b-08d97c517a02 X-MS-TrafficTypeDiagnostic: SN6PR11MB3168: 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: edrMjC4vnRzxV1bWX7pWWyZimy6A7FTVqdiUD5rVAmw/utAnaqYNSnUiu1532Kh/6sk9eQ40dPDya+VN3e1ebQ4/tHs+2mO/cT7jfNrRWexl1TotTaowglbD+HoasvtQoxStOaKUnVlEscGKnIdy3Z2rsSs7YOQptOY2q/d9mvxrt7D1k8zxvu2Ge8RrK9UkgPLgIZmWMMBZmOEJfeoB4urL4sJn5/lKIEvUemjF8les9ae/gCrvsAgfN1pT7IgnGvs55PfYPxT3hSn8JZ3NDsBVaS5ffY+O4AYt8656K5sR/DzH3NdG2rIuAEPOJ9cjBOcY1zP18ete+BEqIDhOGUKHrdak0nAF+Ob8mU+pMZt3SihGvY60h7Z7kYAY4iHgZLKD+rhjmXLzal2jV2qHBBSUUgW3bgiyA5I6pDi+bceA8Sa3GpUI0i7Xwuy6zuOxtv0pC255Lo0H7Tqpv7+V/G4GEVbZO78d53XdggKVW2HmjbQJM0+e3aquNq4V3U74tNDHOKUo/6AJVKjkpX40ejUh1YNRpDeKvViThvZJLgfoYiNGKIXVabnmWCy2y24THp3GvQ/8w/3LvhvQgRi2QJmVQxmwwnbD2bPx9Ytri74Qt0I7+bh+zxIfWsVDWxDEPVkQmJJZhxgoa6yR90+izw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR11MB2718.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(86362001)(1076003)(6666004)(54906003)(5660300002)(8676002)(6916009)(2906002)(38100700002)(8936002)(107886003)(52116002)(186003)(66946007)(66574015)(6486002)(66476007)(4326008)(36756003)(2616005)(508600001)(7416002)(66556008)(7696005)(316002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U+hvs9mVjQ1Ay4MEv+Io3REZh3h36j1kTagj5HdrLpfn+p+GRoYSgeT66Htflx6RzxJydYbgscb7njaLjHo6B25RreRLk6ao61m2axo8xgPiCz0mz0TTXDRdOBG3WiwsL0be260KUlIVJPKGsyyldpPeNMAk14i5+N+KGT0ylOzO28g3ppeFrgNT3yQBDrYQ9ayfEhkZBPm0bLoZBtdnJeOLQX4AyCOz6+z6q1N19GkLgru14IE51rrSj7286pM6A5wtfrUiYKQST5lEebUXcgA0sEVvSDhYhNIGdN+gEl1z85DOcpTRVyeAsKWKf1DaOuWjlBrf/8A/9eiqCBlM+sGdcrIlZ2+VV27rgfXtzAWYd/0Hl+iRvZd72IvTlvKu6uOphQ0NdhYEXXgU6Ji5B7yqidXk4nxDXBaM4ezpkEzywu3M8BtwA1MRcprNR5StlSa4WK61Klxpc1e4KZXbcZS3xJ8azBVn3RW/SPO7oHd7GOAc+QZyP2ptAlSNkfxs1kaDj7+f0rnbey97+P+yIi0pkWdPf9/RPXgkKoZCB3QoEKG2VSp89flcqRLudZ+UpOVqNt0GF9SR5PxRAaRpv6LhyNtDDXJTlD865ytNh/UBQzyoC+9YRhyL8SjDGVZBHkLwpzkEhZ6ivJ8kAwcBlxHLTrZYRRDTteA0OzHqEvEzD0phGxvviEMiKBkJgi6U704z6KU5iW2886xYnverrf5xdC3JLPUp8cPlyYAHgNJimm+NX4jWwIyp9S/l7F+1yuN7ZiJPgMGbiFO27B1DaB+zNQKthm5fubzJoX8q4QOEt7LQz0bzVsmGJLTzh6tQ X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3306306-46db-43cd-580b-08d97c517a02 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 16:12:43.2963 (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: CmLEXrQVDVvu/ldAC/d+3RAhaIL1CBTNn2p6kUejebhb+zipCs+R9GuXPLfRuy+hVbouuGYrefyEzHiGJXzUMw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3168 Precedence: bulk List-ID: X-Mailing-List: netdev@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..0cc97dfac526 --- /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 __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); + 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 = 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) { + 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) + 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); + __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; + 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