From patchwork Mon Dec 16 17:03:59 2019 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: 11294769 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E594930 for ; Mon, 16 Dec 2019 17:08:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC8122072D for ; Mon, 16 Dec 2019 17:08:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=silabs.onmicrosoft.com header.i=@silabs.onmicrosoft.com header.b="BnTYjfbg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727884AbfLPRG6 (ORCPT ); Mon, 16 Dec 2019 12:06:58 -0500 Received: from mail-dm6nam11on2044.outbound.protection.outlook.com ([40.107.223.44]:54496 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727795AbfLPRG4 (ORCPT ); Mon, 16 Dec 2019 12:06:56 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N4MRK/p+vggI0XSBfcbZ6R2bSeyiDW63j2E9hlH/Gc1JhJFD3HXh5lXtM+FjEPxkMxdgs4+ItTzN2Tk2Bn6UdG3XXxoxGQLmJgnP8qBBR4/B4wJugqEhHminu3WqxmZ1Hu61TdLnAHGvNimGx2+HHkOBRnUDk+VkVVu1bwoKXkxH/VagMvMm9JH4AbMlbFAIn9kXNexOQy57XDe7cn8jobESEZ7y7sWe+9FlZ+w0MYGWMrtn24mnDdrfBcPcNun67cvnd08R4MIc+j0s3L1DHseQyWv0KR4BqGFsmxsuLlHqUjd0SWzzZwrptd5VTCtkQEpYjreiGoBlhQuvlimOXw== 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=XBmTF54IXQismnM9J8cO9ubA617V2LGtGi2MGRDTsno=; b=fTAdnH806nKRP4//9K7VTAKPXHk95JSEK4UOIWKfuiYn7BtP/JOS9ePdI5Rq4Cxylsxk+YTiVZRwFC+A2J/e2CPzzTHYY9fsoYsDRxqce9fEqC/yC8xjRtFyVabeaURUuzGCJr9lo03aIWtxaAsS1ejmknmtc1ucKxFTcsYpu6cUABV2I8iuJo3i386iMlHaiDhJ6xiWE5kWS/jFaZMc8Y+maVf6zcqIZNVeaE3icOZgigbOTyDaNpiYwTwMDgrIjn8+coQfqQZxDl8QeyMfUfUZO8GdtcbXlNYtLe/4uYi14kfiuRPxnqDpcK/1SeBxV90gYPADBSN9P0MfpU8dwg== 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=XBmTF54IXQismnM9J8cO9ubA617V2LGtGi2MGRDTsno=; b=BnTYjfbgOhPJhiASZ5UDBswKV/ItZbvLrq+UB5lafXk4dGDVmpgOP9eCBl1s1VhukmLZ8OdGoGSUNwuq/f6hNXwtGt1GOEJkQQpz1zxkn8RORRVy8owRPxO+3DPwodROlqRIuCXkER8y/Ry/K/9yLnURKtpopoVPUFV32nx+ehM= Received: from MN2PR11MB4063.namprd11.prod.outlook.com (10.255.180.22) by MN2PR11MB4445.namprd11.prod.outlook.com (52.135.37.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2538.18; Mon, 16 Dec 2019 17:06:49 +0000 Received: from MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::f46c:e5b4:2a85:f0bf]) by MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::f46c:e5b4:2a85:f0bf%4]) with mapi id 15.20.2538.019; Mon, 16 Dec 2019 17:06:49 +0000 From: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= To: "devel@driverdev.osuosl.org" , "linux-wireless@vger.kernel.org" CC: "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH 51/55] staging: wfx: workaround bug with "iw scan" Thread-Topic: [PATCH 51/55] staging: wfx: workaround bug with "iw scan" Thread-Index: AQHVtDLPeVDVbzcyeU22pDnDrXDn9A== Date: Mon, 16 Dec 2019 17:03:59 +0000 Message-ID: <20191216170302.29543-52-Jerome.Pouiller@silabs.com> References: <20191216170302.29543-1-Jerome.Pouiller@silabs.com> In-Reply-To: <20191216170302.29543-1-Jerome.Pouiller@silabs.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jerome.Pouiller@silabs.com; x-originating-ip: [37.71.187.125] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 18e2aae6-1ef3-45ed-2313-08d7824a571e x-ms-traffictypediagnostic: MN2PR11MB4445: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-forefront-prvs: 02530BD3AA x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(346002)(366004)(39850400004)(396003)(136003)(189003)(199004)(110136005)(6486002)(107886003)(36756003)(186003)(316002)(66946007)(54906003)(5660300002)(66574012)(66446008)(66556008)(85182001)(66476007)(76116006)(91956017)(64756008)(2616005)(6506007)(85202003)(2906002)(26005)(71200400001)(6512007)(4326008)(8936002)(81166006)(1076003)(478600001)(86362001)(81156014)(6666004)(8676002);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR11MB4445;H:MN2PR11MB4063.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: silabs.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: z0xeBTeg+Rz5B2T5TuONgJKpiu/sljm/mS0jKnc8/Uhqo7jr200RL+68WyDHik025SmBeV2o3YWDEuVkPejHeLsPDRk36RlaHNV3tEqTR34XTxLunczw5J7WPagpyjkKUn6sv3CuJFREpZzE2jtRUFQO8ocW4dtgPndhhKmvtyNMMD+YrEC7450dpotggMIUmYSFSk4Qv0c4/eLN0aofgViysZ7y5SSykefKQihxMR7lGCZrIQNFpQcdVcBT4jv9JLXpmreLO9vieiFOBlwlMeFju9e/m8PgQfgjbdUF5VUO6t2IxalEcB3CyxevVfzGG6Uq03viUxudfFg35nQDpfx7pVBOMgi7EEdMo5rVHb9Wwjo1bYB6w0si2i/+GnZ3lhjf8ByWhG5S6cT6p0Nplwn+WNG0MKk70bhBlt+v6gdroNbhjdMLYfqDs1X2pNdF Content-ID: <45C1EA37BD8C434482D2028C9998FC5B@namprd11.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18e2aae6-1ef3-45ed-2313-08d7824a571e X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Dec 2019 17:03:59.4502 (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: Un5D3uwThHU9cGtznZaQqt0jYxcpSglNbq1Sz78NgFrVxVmf+tZQDriLB/c6Efn+PY1wGJrgSrumQeezYFE5Cg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4445 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller mac80211 specification does not forbid hw_scan() to call ieee80211_scan_completed(). However, from userspace point of view, not all applications support this behavior. In particular, the code of iw contains a big fat warning: /* * This code has a bug, which requires creating a separate * nl80211 socket to fix: * It is possible for a NL80211_CMD_NEW_SCAN_RESULTS or * NL80211_CMD_SCAN_ABORTED message to be sent by the kernel * before (!) we listen to it, because we only start listening * after we send our scan request. [...] * Alas, the kernel doesn't do that (yet). */ So, we have to avoid to call ieee80211_scan_completed() from hw_scan() (it's a kind of unwritten rule). This patch relocates the hw_scan() process to a work_struct to fix the problem. Signed-off-by: Jérôme Pouiller --- drivers/staging/wfx/scan.c | 47 ++++++++++++++++++++++++-------------- drivers/staging/wfx/scan.h | 1 + drivers/staging/wfx/sta.c | 1 + drivers/staging/wfx/wfx.h | 2 ++ 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/drivers/staging/wfx/scan.c b/drivers/staging/wfx/scan.c index b73e61e8da46..540009b72240 100644 --- a/drivers/staging/wfx/scan.c +++ b/drivers/staging/wfx/scan.c @@ -71,23 +71,19 @@ static int send_scan_req(struct wfx_vif *wvif, return i - start_idx; } -int wfx_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, - struct ieee80211_scan_request *hw_req) +/* + * 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_dev *wdev = hw->priv; - struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv; + 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; - WARN_ON(hw_req->req.n_channels > HIF_API_MAX_NB_CHANNELS); - - if (vif->type == NL80211_IFTYPE_AP) - return -EOPNOTSUPP; - - if (wvif->state == WFX_STATE_PRE_STA) - return -EBUSY; - mutex_lock(&wvif->scan_lock); - mutex_lock(&wdev->conf_mutex); + mutex_lock(&wvif->wdev->conf_mutex); update_probe_tmpl(wvif, &hw_req->req); wfx_fwd_probe_req(wvif, true); chan_cur = 0; @@ -96,18 +92,35 @@ int wfx_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, if (ret > 0) chan_cur += ret; } while (ret > 0 && chan_cur < hw_req->req.n_channels); - __ieee80211_scan_completed_compat(hw, ret < 0); - mutex_unlock(&wdev->conf_mutex); + mutex_unlock(&wvif->wdev->conf_mutex); mutex_unlock(&wvif->scan_lock); + __ieee80211_scan_completed_compat(wvif->wdev->hw, ret < 0); if (wvif->delayed_unjoin) { wvif->delayed_unjoin = false; - wfx_tx_lock(wdev); + wfx_tx_lock(wvif->wdev); if (!schedule_work(&wvif->unjoin_work)) - wfx_tx_unlock(wdev); + wfx_tx_unlock(wvif->wdev); } else if (wvif->delayed_link_loss) { wvif->delayed_link_loss = false; wfx_cqm_bssloss_sm(wvif, 1, 0, 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); + + if (vif->type == NL80211_IFTYPE_AP) + return -EOPNOTSUPP; + + if (wvif->state == WFX_STATE_PRE_STA) + return -EBUSY; + + wvif->scan_req = hw_req; + schedule_work(&wvif->scan_work); return 0; } diff --git a/drivers/staging/wfx/scan.h b/drivers/staging/wfx/scan.h index 03bc6c7e562d..b547f1927d72 100644 --- a/drivers/staging/wfx/scan.h +++ b/drivers/staging/wfx/scan.h @@ -15,6 +15,7 @@ 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_scan_complete(struct wfx_vif *wvif, diff --git a/drivers/staging/wfx/sta.c b/drivers/staging/wfx/sta.c index 16f5db873275..4354bb8081c5 100644 --- a/drivers/staging/wfx/sta.c +++ b/drivers/staging/wfx/sta.c @@ -1427,6 +1427,7 @@ int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) mutex_init(&wvif->scan_lock); init_completion(&wvif->scan_complete); + INIT_WORK(&wvif->scan_work, wfx_hw_scan_work); mutex_unlock(&wdev->conf_mutex); diff --git a/drivers/staging/wfx/wfx.h b/drivers/staging/wfx/wfx.h index 3356d0cbf7af..b5f763c3fac7 100644 --- a/drivers/staging/wfx/wfx.h +++ b/drivers/staging/wfx/wfx.h @@ -127,7 +127,9 @@ struct wfx_vif { /* avoid some operations in parallel with scan */ struct mutex scan_lock; + struct work_struct scan_work; struct completion scan_complete; + struct ieee80211_scan_request *scan_req; struct completion set_pm_mode_complete;