From patchwork Mon Mar 15 13:24:57 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: 400951 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.8 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 797E1C43619 for ; Mon, 15 Mar 2021 13:27:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5ECA164F0C for ; Mon, 15 Mar 2021 13:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231479AbhCON1Y (ORCPT ); Mon, 15 Mar 2021 09:27:24 -0400 Received: from mail-co1nam11on2080.outbound.protection.outlook.com ([40.107.220.80]:9473 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231213AbhCON0Z (ORCPT ); Mon, 15 Mar 2021 09:26:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OiwvgeDsS7tYjy/STDuylOBK7zPsB09kIuDBHP15QZuRUcBveL7M7MDgqFcdYpZpxB86b//TegnxVF2g3OB3DQJV08cZxhPocBUBkwP+nZANByBC2EZ2KjBuvS5yXVgvIUOfUOxAe1CPNuHvzqlxp7XF2X1T+8jfZGOu1QP2wH8i7y15/mxmY6sxeLvDGvfTuRqJ4fgi/I+ENZSutRoSLw4aXMZ16tOBY9BuHx5qy7eHjSzNqrFnb0DvnFn+/sfHY1E1ur/bc4NG4UBszNXO8hMBMoGZgiwinHWv/YsgGDRchRGny5kCGppnp8L+OWKUPrYFha5G7P9sjmsPeVnZow== 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-SenderADCheck; bh=XLOlILZHl1+swJSIwchSBtKnDHyJG/1pxSDCPiyVRmU=; b=bno8I/uVsCZxswNxz57VbvmWZdMAnj4qhA5pdeBoN2d2qGm+VX95TKSPN9MC07hqOvyHH+CWxq5/mC7+MGXwO00foYj2fFu6HiIHeiOFs69ZDQmctkBG64bXlUWfwD+SKKu7Hs/7i6xEo2HhaJ1fdqSUCzNnb7pM9eenJXXgwr8+oI+SbfmkuCSR1t5AVVvD9eluLcyRxFU1yu322AZjfarCMA44R2WBPqOn/DMUn/kwDHRU4AGyZE44vFLf82WSSSFqwScYb3fhpTvwYi8F0tXEfhopTinOz5PEDr8mqzFHaIjdKD3wAOEApjQlb2J3mC7vF0cfzXQSXZ/OZQO+jQ== 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=XLOlILZHl1+swJSIwchSBtKnDHyJG/1pxSDCPiyVRmU=; b=QSQm0TiHeDHZspswo5JuxbiLXFv6WE1PuDd3hcYB80IV/XOWfxg06guNJ//jSGlODpHfA+UUU4JXghgYEY96ZpTwz2zb6hvRuT+hIGaFCs4JAeD6VzJ/CzNcvqSfkr7+khGU5FpsQCT9uvd+r8PMbKhA0BsBnNZEOM5C/Aj/csY= 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 SN6PR11MB3216.namprd11.prod.outlook.com (2603:10b6:805:c1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Mon, 15 Mar 2021 13:26:17 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::41bc:5ce:dfa0:9701]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::41bc:5ce:dfa0:9701%7]) with mapi id 15.20.3933.032; Mon, 15 Mar 2021 13:26:17 +0000 From: Jerome Pouiller To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , devicetree@vger.kernel.org, Rob Herring , linux-mmc@vger.kernel.org, =?utf-8?q?Pali_Roh=C3=A1r?= , Ulf Hansson , =?utf-8?b?SsOpcsO0bWUg?= =?utf-8?q?Pouiller?= Subject: [PATCH v5 20/24] wfx: add scan.c/scan.h Date: Mon, 15 Mar 2021 14:24:57 +0100 Message-Id: <20210315132501.441681-21-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315132501.441681-1-Jerome.Pouiller@silabs.com> References: <20210315132501.441681-1-Jerome.Pouiller@silabs.com> X-Originating-IP: [2a01:e35:2435:66a0:544b:f17b:7ae8:fb7] X-ClientProxiedBy: SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pc-42.silabs.com (2a01:e35:2435:66a0:544b:f17b:7ae8:fb7) by SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 13:26:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 523690e2-d3e2-47e3-d14e-08d8e7b5ea12 X-MS-TrafficTypeDiagnostic: SN6PR11MB3216: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rE4sdzf78fiml24FMwRqx2m2sI3oFsYFqp8KNs3r3iuUgrwFJ1Y5Qmdp0ElzrCHLWkE5G6fa1WgiO8v6B2/vr3fS+wzSroXJEYwj4XjPLT4rALMTbgot7yhvFVsju5h+FIAc+CTzjLZ7RzpLAkVHDu2Cex0bVDdFZbLY0s/sQ5DZdJ/3FOsISBTTh/s/ywH+OgXUTWxnZDDMxQQP3SHAaT1y1tUkr7uAhU5qbdeIASfwN7IihR4RIM3iuHmrS0S6omPCyaH0mKTtNXBoeXeNRT0uIZnYWZl/KWILfjnsGZDXUDAaWbyfUDZkY2L7wGlysLE/APVMsTIAn9kbmnjbvMwAMwOvCj3JFBQy2QatbNQU31f2o85DEW2TxdUXWkH5g2kgg00ULWZGq+7USl6UmAmIVKoBrqauaG9c6Qy+sfDb90XnLNGM2MWFiW6puXhH61gDWbekzvfehMrSg6T+SM8Crh4iU19x5SvxjWiFsIC7U4F7cSNN+qvzVAh24fQImiHq3PGdOtAzSpmdXVnZyo5En2zXcza1JOSri7cfKDdhiDc6tl6mau+buwBfd6oN 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:(376002)(346002)(396003)(366004)(39850400004)(136003)(86362001)(107886003)(2616005)(186003)(1076003)(4326008)(316002)(66556008)(478600001)(8676002)(66476007)(6486002)(7696005)(5660300002)(66946007)(2906002)(54906003)(83380400001)(6666004)(8936002)(36756003)(52116002)(7416002)(66574015)(16526019); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?BO0J0omBv9zEnvMfhKOthllR9ik?= =?utf-8?q?hHYrya/BVQXElZZZzDqku5/QL3W7Zm3evnNaN6pGcIRhAhqpZGE5r7qU?= =?utf-8?q?ahF3bVsNY4Atuv6Q3AGRHx7p9gptXVl4/EAgmngTEaJRfotGqhEvEbuR?= =?utf-8?q?kLQFjgSbQ15zIuxKDExFS93rx1rqDIf9mBVT/MK/jXSzAVkmk8TQZKtV?= =?utf-8?q?U4/72Hcts/DmprollrqFLH8MoBEmHMZ+nSnVfTDrXq6ifda5sKygNrFS?= =?utf-8?q?bEMu85c0/QTksGgXCWi6lFTtQAUE2aqFcjSHui+tPPgXtQwiCg9AvZ1m?= =?utf-8?q?ZvNL3/1sDB00zJ3ZXMd1h23vbFPaUX8L2tteMXbB6KqH0FSRTh99idZO?= =?utf-8?q?6vCCyFV5WujRcbhhJl+VTHJAkEbR8FRT13Vpt8FYLrqyA/gL2vgrWwip?= =?utf-8?q?wARww5XXP/nZ3s7daaU1XCiCeOKNjFa+8VJrgX642T8PdVPbzR4pnLNw?= =?utf-8?q?UlCccdFW2V4gysR5pAEz2O30sKxV6LxxtGm5NWFRj4pbFCliNo8Xd3yv?= =?utf-8?q?vm7hScWNjvAP8zTiRe+0cUoQ271KRIjalm5fIb0dz3ljjLIK3ZYV5Ugn?= =?utf-8?q?gkOkgioEEPQP2F9Q7ph8QqN0JUnfQf1xqPjxe02j1dpcq2fsZmJ2Zn+I?= =?utf-8?q?U3Jk2Hzv06MkI3PnsxKcT5IzCtV3MofDLiiQ0PSVg5w18eNxIlc8N06y?= =?utf-8?q?krQsVvOOH6GpwNp1UJ14W0vVraYBcMmGmnwOVnA8MbzkxjjNE/ATUEkq?= =?utf-8?q?REKCs1GO3E9TgH3GDyDQKlBrPmOFO80WDK6UHXwOjizV2LIVflWsSHjZ?= =?utf-8?q?TeGCxZJodr6JAqvCqlyBnHrBODfu/KM2YVJMsCSmU9SwVSa8x6yrjL4c?= =?utf-8?q?84UgdVZ2Ex+ZtxD2OAhkbKrmdaZmQHvmDQKBdoCQaxMVDN2piuanSWGk?= =?utf-8?q?xthJ6cNrfeOhubKbY/ih7A2sf3DGWHonR0lFI1jXFijUPzyFV6C6dDmO?= =?utf-8?q?vIfKsgJnDr7vzQdfnL4x38uwH29112JHFb6e60UI9J+HxwwEdySfQnH6?= =?utf-8?q?kU+ed2pYwleV6WRBfaeoKhtEp0gPlQglWMYkf9fyuP9ycy3UHftMY3xz?= =?utf-8?q?ma0yKgDVd8KD/WHnukWGXl8BuI9+WymwJo/ZKqhQ+ejOLsLJ302LJwwd?= =?utf-8?q?zarS1tCTLXPDi1lEvPc8fjso7c4+ZOCltLtjn7aeNP7fRQOfBLP3VpHD?= =?utf-8?q?Yc3GoKAqYg2SXAlRs8wW9yEAiAV/TAuCWHcGAc5Zny8t6o0+sE6KH8+y?= =?utf-8?q?qgZ+75aKEAN1IekywH7H5wp3F/F4LSGxEd6/3B1Htz4hK9oCuJVYuWnp?= =?utf-8?q?FabAjuksYes4enePxU5axu+UntCYryi9O7WBUrAK5MLJmRNrS4bVo9kt?= =?utf-8?q?wsKO9fMs+Ua+Lx4CH4D4CQdFU5bniHBbPKJop?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 523690e2-d3e2-47e3-d14e-08d8e7b5ea12 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 13:26:17.7592 (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: zjsFirmSkvTAf3wpY6gwBtHfVpN/5KFLRiEmb4wGaIrPvnCQPvGEA4r07aJUSVi3mIE6QljIJCgBjYPoVAtYtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3216 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 | 131 +++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/scan.h | 22 +++++ 2 files changed, 153 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..3d5f13c89bac --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/scan.c @@ -0,0 +1,131 @@ +// 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, timeout; + 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, &timeout); + if (ret) { + wfx_tx_unlock(wvif->wdev); + return -EIO; + } + ret = wait_for_completion_timeout(&wvif->scan_complete, timeout); + 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); + if (!ret) { + dev_notice(wvif->wdev->dev, "scan timeout\n"); + hif_stop_scan(wvif); + return -ETIMEDOUT; + } + if (wvif->scan_abort) { + dev_notice(wvif->wdev->dev, "scan abort\n"); + return -ECONNABORTED; + } + return i - start_idx; +} + +/* 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; + + mutex_lock(&wvif->wdev->conf_mutex); + mutex_lock(&wvif->scan_lock); + if (wvif->join_in_progress) { + dev_info(wvif->wdev->dev, "%s: abort in-progress REQ_JOIN", + __func__); + wfx_reset(wvif); + } + update_probe_tmpl(wvif, &hw_req->req); + chan_cur = 0; + do { + ret = send_scan_req(wvif, &hw_req->req, chan_cur); + if (ret > 0) + chan_cur += ret; + } 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) +{ + 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..6d70717f2bf7 --- /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); + +#endif