From patchwork Fri Sep 17 15:13: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: 12502585 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 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,URIBL_BLOCKED, 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 9B369C433EF for ; Fri, 17 Sep 2021 15:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81F1160FA0 for ; Fri, 17 Sep 2021 15:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235716AbhIQPUm (ORCPT ); Fri, 17 Sep 2021 11:20:42 -0400 Received: from mail-mw2nam12on2053.outbound.protection.outlook.com ([40.107.244.53]:15265 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1344528AbhIQPSJ (ORCPT ); Fri, 17 Sep 2021 11:18:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WmPVCN89W5ivjJPZcKMnXFwG4SnCfD6G+8hze7VyzVNgDP5zfv7TYqbW0eJ9JhltOniGjunVd0vaa1AzIwje/JIAlAK4blaqB1UgIvkTGoKvcc/8AP7+ous/47CnZRHIGqNMDs8PD02R6OP8l+rdLIEdxL9w/XOQu9nqpUk15v1NJQ+YJusKQYa/Mvwlzd13XaxFcw4hNgt4g0kAx6xoA4Ra225iVSTD+y80iyAf+aGb/FTuGp2SR2oXuTt4Xp2NeMKY3oWZ221lttmIPAVhrCn4suTLyEfpI0SuFMjnDfctPYykaIaPPxd9yAxcFnCp7ydr+uU5wfe7KjY8mupRQQ== 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=LeWwOoIu1tS0RuJH93j/BPqJ4WhUdJywqOWdV3DDobvI+UepzBbXZ9M26tTz0ibnb8n/QIhmQn0I9ee2gKjjWW0u68AJHixKYRQDne7g6arPHORYGxHCo5VEliJHRCdBabuwSXJyblJAcIdZA3SQnztDl3n8vKgRxz/Ntk0GICJViIm08yi2BtBGnGVciyvrRii6/LL0DiUkAj8jxHBT3n1ofPxgUGTy7Jv68aZhrp/zRNEXNYJfFH65/d8fcsUVHCI7n1b6uuUF5qGC1vrJ+au9oaOZGg3DAeuN7AY7YJNp7a6z43hdzRy3Iihsyq/U7Aj8s5/5Ax9eMM+933Xmdw== 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=Jm81Uy9mcFeZvpxjMSDNZKNE8prW/OUebXKeJQN3wPX0Rgc19DJis3h87Zb0KX+xXROqI0SMn+AdAVtKIDWgpAxNLNBenitdVWBWf9e8QiCITgn9AMxHbNRH88ANy7884KC20iQX/9fEkLD9QLrVybZrVI9328ANBeh6G5hZ7VQ= 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 SA2PR11MB4876.namprd11.prod.outlook.com (2603:10b6:806:119::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Fri, 17 Sep 2021 15:15:09 +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.4500.017; Fri, 17 Sep 2021 15:15:09 +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 v6 20/24] wfx: add scan.c/scan.h Date: Fri, 17 Sep 2021 17:13:56 +0200 Message-Id: <20210917151401.2274772-21-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210917151401.2274772-1-Jerome.Pouiller@silabs.com> References: <20210917151401.2274772-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SA9PR03CA0029.namprd03.prod.outlook.com (2603:10b6:806:20::34) 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 SA9PR03CA0029.namprd03.prod.outlook.com (2603:10b6:806:20::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 15:15:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab54259c-6abe-4f22-1538-08d979edf041 X-MS-TrafficTypeDiagnostic: SA2PR11MB4876: 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: wEIqF4tA5NKDUgQGC6sw6lJVaY+raPpsizFUw+x+CZEfrPwYRMrW4i/K9at5Fo+lRgt6TBAlmNhoSiIuCDZGtG04RtyjE6EnIjKzg+s/eybwi7vaM40kjOQadBIhXyZ8MYIquwmSRdmIAk3S7dAJCJGgHpKjiQ3jw7VzIQE+lHIl1qhrfk14ulMCmCoFjyak3jryQwrMw8RvDuVjFlYOB+d9sA4lxHRqH+oYLPdkbkmJ+ihwQX7AwwGMvzs8QEiioSo930ihG4uL936jrDdtQ0kjxcjdt03wXlpn/fetRe7N0f4tgEZlYyv+DA1v4Inqj4FQXlN5VPRFom7xL+3dFi//j3RaVzOFfTuJtwaMqNydNwDOTWgQmdy8x8CMRVyI2yVk5cMGZA04L8ZhjUVoLjeq9jJLBgIGOm28ISANzrvIs0eQtfmmvHEJH28w3DCc8fLYg8LUGa7t/knVccgSy7plbHolyJielCkyRTcPi6Msg6MvE3Hi/NGGUOg5qWuWmEci+xGjzejdYUnkj1YKK87QzMi1MiHTTb+y+XM8ZAkDPTGEo/cVlWTgv4MZgLUley8eTXQDDk+fmx6hDcyLx0GWiFvOBwr4UJMrEMt1L/vHFK1oWFV3J8/MbXQzivwasmlSAT9UnoqTrezmgBX4sQ== 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)(83380400001)(1076003)(6486002)(38100700002)(107886003)(66574015)(36756003)(8936002)(2906002)(7416002)(54906003)(5660300002)(186003)(8676002)(508600001)(52116002)(7696005)(6916009)(66476007)(66946007)(66556008)(2616005)(86362001)(316002)(4326008)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?/Hi2amYB4pydBrVxWcDQuKeAVeaa?= =?utf-8?q?lQ8PzN2hlnRFaKJOnX/Q+F2wezREAKGahjfl4sVYm7Xa2GTXsV7VbX1RLj+GCTMjV?= =?utf-8?q?2oI28cFDiY0xEIsw8m1cxYIfW4QU6kBIYgUJiZJReyN7ETSDCXP6NdB/2UnlZN7YT?= =?utf-8?q?9CpsUgvQ2PyIHh/LTfNfZEVY18PpUy9tdzbWPJFrW0AcHhEgtFuHZzifVKvUGBnGu?= =?utf-8?q?n2jkIgNEnGjy92PTLrE8Qh4zdYAF9Im9Q/Ru900awHycL2qzfMJkxMjyQHMu15Bsl?= =?utf-8?q?G/d8m/tovTg42C0jgxBz2N5zG9TiG17YQLvJGZYuCzlN250l4pm7SLt3cBrbDj5W4?= =?utf-8?q?yS9N7w12zSzJbVlERsGxxY6BLqgVsRab7ufpeAqvvA7YSStygLDS6pn3xG3Im50A8?= =?utf-8?q?gWXO+zT+W/k8hAYQRVDAGEhSLgQapqZDdegUlzjgE3mRpiOthVoYt1sf5iATdssUj?= =?utf-8?q?S/mkZCj0apB7vqtlIJZyNJPuAa0CSYTcESRjBkbKM4rZbxMkcWPkOxkXjwYXipEd2?= =?utf-8?q?sXpZjwNYRtvUGSkk2PUA4hTU1DgxDfdZXcg51l035B35XTehEKCzyvx6p+3+Oqhub?= =?utf-8?q?56NEh50yVdZWxu2Tg6L0+Ra9QNd5DbRhdv5Cj5TMl7gXjvjmab9oRmGFDE8NzqXd9?= =?utf-8?q?DkVGF5rW8glt7zd0fQOLptLNjt+uVxO4eA4A/GCXS09RIX6gCGbqwXXmse9JbwLIs?= =?utf-8?q?b8mkAdVr3SwPIkXWeTrGNk8yrQNPk1BZkv/VV0xEiifQCBeve4069CxTz6XaqBUU7?= =?utf-8?q?uhqozitns+faxVTdmf1WTF16hN3aIU/46DKKcZr2rczwmBb+AMx1viWg5bTUB4LOm?= =?utf-8?q?nL2bYL2xlAeAVQwArTxITgsTUUA6Yj38iWp+RqirpFVDXJr6rUiY6FNaLOz3SdvPJ?= =?utf-8?q?OP8ygfxvlJA1pyIaRJO52QfBRJscovdakCN9twwG8v3X4qAnzzVvTWm4lCGuBhlWe?= =?utf-8?q?6PfYO+I9BROjz8e2ZAvJE01x1fBBCqEhWHaDr0DZzrniaUiQlYVWv2ShNMzrGUhmJ?= =?utf-8?q?wocAckgMtz0B1HOxG9jcq2ajp/BrnuM0LKRkKsOVChXA+NbpquQBgRshC5Bn0Ak5x?= =?utf-8?q?ocxZiXuO1OTFbZ7+w3Rwe9aFMDR35f3mk2jOqGvFp6/FItaAIfX29ovl2rcCvoLEO?= =?utf-8?q?c+yDvZQDKJP/qXlN0gG4oRTIr9J3aRhjULJ+aDLd4ZIRRot7Yeq6old5YO5zGR9mk?= =?utf-8?q?dMIoGEND5gqwgnpoeH7KbrtAY5Q6DI/MTSuWusa7ldjJbwGrUnM6+B9lZ/GNSCYbO?= =?utf-8?q?nLWPRsqo4DLnraWqm7K5bj6kuXsrmIn9CS2+uQ45TCq8yDmFZkEJ3VrJi4EEzkMqZ?= =?utf-8?q?jgK2iWxeiToT9ld?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab54259c-6abe-4f22-1538-08d979edf041 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 15:15:09.7511 (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: KZZLzn5jJh9zotCoMGDsHZ5DYjeL0uQ/1Qh4bAid6XAyWT32IgdmGIgLT7x1G8FmW+Fzizdpe6f+YGemM39owA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB4876 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..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