From patchwork Mon Feb 8 12:58:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alvin_=C5=A0ipraga?= X-Patchwork-Id: 379007 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 2AB85C433E0 for ; Mon, 8 Feb 2021 12:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC60664E82 for ; Mon, 8 Feb 2021 12:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230292AbhBHM71 (ORCPT ); Mon, 8 Feb 2021 07:59:27 -0500 Received: from mail-eopbgr150094.outbound.protection.outlook.com ([40.107.15.94]:62848 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229756AbhBHM7P (ORCPT ); Mon, 8 Feb 2021 07:59:15 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KxANQHdTyWNFD0ce/NYC+I07pgCgndsF+HFWLrZfdnL/fPm3LLksqKOf9vNZtum9TG/Haqv77srDwo+qwCw1fwuUWatChnxxNB87SiOs349mPZW4ZBQUaUq7D7qvq/rePAk0RXi73lX7G6puUI3PHwUimQdNRKpPYtj9IT46mV6tQw7wVlvPGl0GFoOsdZ6wMtNS76ZElLE8Z8Zg6+LNZwrPVHubihYg37xbC4MjJ1tlmAwEn9IDtDjs8Ah71UaJLnAQmOrTH8P2uMQpSEGHGq6AU6y/fktvAMtEdA51vE838vM6xGF/OAtFAOy2DqaTlAXf+EiKcghnfqcEZwWijw== 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=XMRhIc3B7FYG9zERVi6T+9L9lk5bJv+oKlz9lE7QZrw=; b=EkWzgXG/ENXuNL5bNYpyDbp4hlide/hWeAIlPBj9UHIC9kZumhAygfaXXziDJyCwiywpBPsCRmtUs0jDjrattpH+UNUIcFlQZ+y4IAFy4IaXKMU6z8L5esSCD7MZKCkoSEPnkqRhcnYxiPbfFcgkoP4KzLNsNRfMsPmxqRKpNq4k0qqhW9jJyMDt+BHJMKCC4LPyNMwr/bMVj9/flAvTb02N4fFqJzMytcuTzcCB/1v8F275uwiNLlls1NYhNAnUFBNIIeqSO3DKNhrRqwTWgYEsmPtJnMrQchAFUNMawGd+PHTxe5apIP6cjWeJmAxk0P4QPdFb3TaXb5WfPxXZ3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bang-olufsen.dk; dmarc=pass action=none header.from=bang-olufsen.dk; dkim=pass header.d=bang-olufsen.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bang-olufsen.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XMRhIc3B7FYG9zERVi6T+9L9lk5bJv+oKlz9lE7QZrw=; b=Vhyg93U+gU4vrBs3cdoB22gurqQ9vck/qBTKcYP34BM2BN+tpEjXrfAWzckJII4cdjguGoeBZ8r6OvTdYR8E/o0dBEx8XenrIQq26TadaT5IN3zp3Bo/91Ge/v3lO2QJP60pkciVEK+rxO/XhOJMGMeaIdvIPk8Qin7K2+RRC/k= Received: from VI1PR03MB3166.eurprd03.prod.outlook.com (2603:10a6:802:32::30) by VE1PR03MB5406.eurprd03.prod.outlook.com (2603:10a6:802:a7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17; Mon, 8 Feb 2021 12:58:20 +0000 Received: from VI1PR03MB3166.eurprd03.prod.outlook.com ([fe80::41f1:9e49:1cd0:55c8]) by VI1PR03MB3166.eurprd03.prod.outlook.com ([fe80::41f1:9e49:1cd0:55c8%6]) with mapi id 15.20.3805.028; Mon, 8 Feb 2021 12:58:20 +0000 From: =?utf-8?q?Alvin_=C5=A0ipraga?= To: Arend van Spriel , Franky Lin , Hante Meuleman , Chi-hsien Lin , Wright Feng , Chung-hsien Hsu , Kalle Valo , "David S. Miller" , Jakub Kicinski CC: =?utf-8?q?Alvin_=C5=A0ipraga?= , Arend van Spriel , "linux-wireless@vger.kernel.org" , "brcm80211-dev-list.pdl@broadcom.com" , "SHA-cyfmac-dev-list@infineon.com" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH v3] brcmfmac: add support for CQM RSSI notifications Thread-Topic: [PATCH v3] brcmfmac: add support for CQM RSSI notifications Thread-Index: AQHW/hoTKnWk3ZrF40mhCMCEIq+8KQ== Date: Mon, 8 Feb 2021 12:58:20 +0000 Message-ID: <20210208125738.3546557-1-alsi@bang-olufsen.dk> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.29.2 authentication-results: gmail.com; dkim=none (message not signed) header.d=none; gmail.com; dmarc=none action=none header.from=bang-olufsen.dk; x-originating-ip: [193.89.194.27] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0ff4dc60-afa0-4b88-6fff-08d8cc3135f7 x-ms-traffictypediagnostic: VE1PR03MB5406: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vc8jledqO/IxCOs+tTtHYa0amT6tlqEKY3eQ9pdIvaDDtsgPQAGEWUGomp5H/dVifj1pgvOc4rwl/kfC7kKZgMz4e2JUqQuaouACkBkGkbk4lZZ2ItSPvZqEY+FiZmXERNt3PUeCOHtX9GuXDWK47sIz9O5cxzrjpTcWgleN33XTQXKiemahd4f/pXd86350nAnFzDjfBjSXWLdqbFmpA7SKsrKzAqlvdwl6dIJNvjeLou+0EsT+GF0ola20TquLB+v7zCGkWDMtMp8iT/VoFpGvQqJBMRUcEhBMxib0ngynsgwN7iKIlNXXp0nFv4aYm8xaL4mMdU7FTEO6XHkyBemLPNfXEK6p5wkDYITXS7FEkJb7tKlW4XP+OcHIeORC9JI2LjE716Ix1CpyrzLD5yQYENkdL2FpJw3Axwr33aFVaDCMRdt0UuAeGja6ZVxUp41lbmMMvg1E0WlKrTqqUue+GiKbpG092x32R3Y/jv4+Jnp7NrUoRhtvzID+M60LuF+ttRjDrZPzROF8izkLbQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR03MB3166.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(366004)(39850400004)(346002)(396003)(26005)(66946007)(110136005)(91956017)(76116006)(66556008)(5660300002)(66446008)(7416002)(66476007)(64756008)(186003)(6506007)(85202003)(71200400001)(478600001)(85182001)(54906003)(6486002)(86362001)(36756003)(66574015)(83380400001)(8976002)(6512007)(1076003)(2616005)(2906002)(4326008)(8936002)(8676002)(15650500001)(316002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: =?utf-8?q?cUpRFELk0fLYs9ucwgkMa0KHf2z?= =?utf-8?q?yC6g01igdJ8NJLzdd7z4uk63FVopXzSp9zR4sp4gsxNkxmX+nz0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fCTONaT5AvJRtZHOSL1mK8uXt/?= =?utf-8?q?deBWAIf4wDvrMqEEZlZk6Q3NVuvMzzQdaiGUxz2g2hwFTWrhtxKTRxzF?= =?utf-8?q?aTaSNV77ftPvjr+ZEZrf0phPdK7HBtNXW8svCTr9Yx4dr/TM3z3XygL/?= =?utf-8?q?dTZp1jr7yxYh/ZGK9Vt5hgZbJL5LR6gk8Xcp2fpikAef94L4FyOyIFGt?= =?utf-8?q?el2zbfOMptp762SgcsNX4OxkcXdg1zhBcn1p+F4i6+ynOvTIoDPuoXDO?= =?utf-8?q?HScaZY1VPb6dUY5c+pBwP3iMAHNUxX1xiU1D3RCYWPmRtusHYaXajW8j?= =?utf-8?q?CUMUEvn4AO3wB0XdUS6fgKZER1QZuYdgKEmlKisqZEKaEbXuu2ugK8/S?= =?utf-8?q?IZYkvPN5ZuX+B8RH+ckKuiwtTOTgk?= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: bang-olufsen.dk X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3166.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ff4dc60-afa0-4b88-6fff-08d8cc3135f7 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Feb 2021 12:58:20.3027 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 210d08b8-83f7-470a-bc96-381193ca14a1 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: f6CjZJY0P1fv89lHQ3cvZhFcOjQrWQvPauNYw0HXcY2lw1Ogj1FqoklIDRb5aISNlHpjX7f7xl89Tn3aTZECtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5406 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add support for CQM RSSI measurement reporting and advertise the NL80211_EXT_FEATURE_CQM_RSSI_LIST feature. This enables a userspace supplicant such as iwd to be notified of changes in the RSSI for roaming and signal monitoring purposes. Signed-off-by: Alvin Šipraga Reviewed-by: Arend van Spriel --- v2 -> v3: - add Reviewed-by tag from Arend - no other changes v1 -> v2: - clarify firmware behaviour in a comment - fix detection of upper bound RSSI transition - improve clamping of min/max RSSI values - remove unnecessary check on last RSSI value --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 87 +++++++++++++++++++ .../broadcom/brcm80211/brcmfmac/cfg80211.h | 6 ++ .../broadcom/brcm80211/brcmfmac/fwil_types.h | 28 ++++++ 3 files changed, 121 insertions(+) -- 2.29.2 diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 0ee421f30aa2..605aa3f4ddc7 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -5196,6 +5196,48 @@ brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, return err; } +static int brcmf_cfg80211_set_cqm_rssi_range_config(struct wiphy *wiphy, + struct net_device *ndev, + s32 rssi_low, s32 rssi_high) +{ + struct brcmf_cfg80211_vif *vif; + struct brcmf_if *ifp; + int err = 0; + + brcmf_dbg(TRACE, "low=%d high=%d", rssi_low, rssi_high); + + ifp = netdev_priv(ndev); + vif = ifp->vif; + + if (rssi_low != vif->cqm_rssi_low || rssi_high != vif->cqm_rssi_high) { + /* The firmware will send an event when the RSSI is less than or + * equal to a configured level and the previous RSSI event was + * less than or equal to a different level. Set a third level + * so that we also detect the transition from rssi <= rssi_high + * to rssi > rssi_high. + */ + struct brcmf_rssi_event_le config = { + .rate_limit_msec = cpu_to_le32(0), + .rssi_level_num = 3, + .rssi_levels = { + clamp_val(rssi_low, S8_MIN, S8_MAX - 2), + clamp_val(rssi_high, S8_MIN + 1, S8_MAX - 1), + S8_MAX, + }, + }; + + err = brcmf_fil_iovar_data_set(ifp, "rssi_event", &config, + sizeof(config)); + if (err) { + err = -EINVAL; + } else { + vif->cqm_rssi_low = rssi_low; + vif->cqm_rssi_high = rssi_high; + } + } + + return err; +} static int brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, @@ -5502,6 +5544,7 @@ static struct cfg80211_ops brcmf_cfg80211_ops = { .update_mgmt_frame_registrations = brcmf_cfg80211_update_mgmt_frame_registrations, .mgmt_tx = brcmf_cfg80211_mgmt_tx, + .set_cqm_rssi_range_config = brcmf_cfg80211_set_cqm_rssi_range_config, .remain_on_channel = brcmf_p2p_remain_on_channel, .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel, .get_channel = brcmf_cfg80211_get_channel, @@ -6137,6 +6180,47 @@ brcmf_notify_mic_status(struct brcmf_if *ifp, return 0; } +static s32 brcmf_notify_rssi(struct brcmf_if *ifp, + const struct brcmf_event_msg *e, void *data) +{ + struct brcmf_cfg80211_vif *vif = ifp->vif; + struct brcmf_rssi_be *info = data; + s32 rssi, snr, noise; + s32 low, high, last; + + if (e->datalen < sizeof(*info)) { + brcmf_err("insufficient RSSI event data\n"); + return 0; + } + + rssi = be32_to_cpu(info->rssi); + snr = be32_to_cpu(info->snr); + noise = be32_to_cpu(info->noise); + + low = vif->cqm_rssi_low; + high = vif->cqm_rssi_high; + last = vif->cqm_rssi_last; + + brcmf_dbg(TRACE, "rssi=%d snr=%d noise=%d low=%d high=%d last=%d\n", + rssi, snr, noise, low, high, last); + + vif->cqm_rssi_last = rssi; + + if (rssi <= low || rssi == 0) { + brcmf_dbg(INFO, "LOW rssi=%d\n", rssi); + cfg80211_cqm_rssi_notify(ifp->ndev, + NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, + rssi, GFP_KERNEL); + } else if (rssi > high) { + brcmf_dbg(INFO, "HIGH rssi=%d\n", rssi); + cfg80211_cqm_rssi_notify(ifp->ndev, + NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, + rssi, GFP_KERNEL); + } + + return 0; +} + static s32 brcmf_notify_vif_event(struct brcmf_if *ifp, const struct brcmf_event_msg *e, void *data) { @@ -6235,6 +6319,7 @@ static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg) brcmf_p2p_notify_action_tx_complete); brcmf_fweh_register(cfg->pub, BRCMF_E_PSK_SUP, brcmf_notify_connect_status); + brcmf_fweh_register(cfg->pub, BRCMF_E_RSSI, brcmf_notify_rssi); } static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg) @@ -7169,6 +7254,8 @@ static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp) wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD); + wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); + wiphy_read_of_freq_limits(wiphy); return 0; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h index 17817cdb5de2..e90a30808c22 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h @@ -213,6 +213,9 @@ struct vif_saved_ie { * @list: linked list. * @mgmt_rx_reg: registered rx mgmt frame types. * @mbss: Multiple BSS type, set if not first AP (not relevant for P2P). + * @cqm_rssi_low: Lower RSSI limit for CQM monitoring + * @cqm_rssi_high: Upper RSSI limit for CQM monitoring + * @cqm_rssi_last: Last RSSI reading for CQM monitoring */ struct brcmf_cfg80211_vif { struct brcmf_if *ifp; @@ -224,6 +227,9 @@ struct brcmf_cfg80211_vif { u16 mgmt_rx_reg; bool mbss; int is_11d; + s32 cqm_rssi_low; + s32 cqm_rssi_high; + s32 cqm_rssi_last; }; /* association inform */ diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h index 2e31cc10c195..ff2ef557f0ea 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h @@ -752,6 +752,34 @@ struct brcmf_assoclist_le { u8 mac[BRCMF_MAX_ASSOCLIST][ETH_ALEN]; }; +/** + * struct brcmf_rssi_be - RSSI threshold event format + * + * @rssi: receive signal strength (in dBm) + * @snr: signal-noise ratio + * @noise: noise (in dBm) + */ +struct brcmf_rssi_be { + __be32 rssi; + __be32 snr; + __be32 noise; +}; + +#define BRCMF_MAX_RSSI_LEVELS 8 + +/** + * struct brcm_rssi_event_le - rssi_event IOVAR format + * + * @rate_limit_msec: RSSI event rate limit + * @rssi_level_num: number of supplied RSSI levels + * @rssi_levels: RSSI levels in ascending order + */ +struct brcmf_rssi_event_le { + __le32 rate_limit_msec; + s8 rssi_level_num; + s8 rssi_levels[BRCMF_MAX_RSSI_LEVELS]; +}; + /** * struct brcmf_wowl_wakeind_le - Wakeup indicators * Note: note both fields contain same information.