From patchwork Tue Oct 5 13:53:51 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: 12536813 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F4F4C433FE for ; Tue, 5 Oct 2021 13:57:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7827361074 for ; Tue, 5 Oct 2021 13:57:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235919AbhJEN7l (ORCPT ); Tue, 5 Oct 2021 09:59:41 -0400 Received: from mail-bn8nam11on2074.outbound.protection.outlook.com ([40.107.236.74]:33504 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235206AbhJEN6D (ORCPT ); Tue, 5 Oct 2021 09:58:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eS/YArxg7trWnsa2eX6ItVJ7qQcqUblw4pZFnol5I83oOr8Ws0LcqHSDscFdypw3oIqz32pO0d57+WWuoOSKCez3NEqXe/IvQx0mBvsRZYdVCDHT9l5durOPSm0NeaAmneiSz4lvJve4LDkBQ1fsDO+WbdcokWuuGehC4lSVJ5BgMupCy6VRHv0fmuM5OxEE0J/v9P3P1V9LnWBTopiFizmy6AnfnTVOjk5zfneRx1/PMvges5KHYnJ9lnDE6Qe8xLr7RDELY2po8jurv7/0Sq1UMXhdUTpQStk78BOWTwKfxxDh7/qaIT/HM1K861ZfhtRAfDq1kZj5lTldR0PR1g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ynxNsreBxLM4dS2VSzDZK68/1/ZmGATe/2kh9kCID0Y=; b=evTgax/ySfFSv4PMKZSl2ZF5uBSksC2i4spbHM1SHSYv+WT7KjspWZW8pNz6A0TKqbQ7QgyUPKBeF0ttlP+4EuDBHcGMzlaTIk44aFVuxqyYSrs7JR4gubeZpnwSqKbq1a8fUjtusXPG8vNfvoTRblEWtQWCFG+fGipwDJRxnYfOzPpOcJT7VqGz/hg9FhmTTZjc1/UrEX6SM3uET9azdGLaF5sLVqudkOSR2NlcgU+/uhzxPOX6Qnvv2Kctfxe0EDLpX54bG3FL8g4gjljgFqIKlm6lX0VwwSI4wJhcozZTUJM5PP66MPYo2Cu5n7630Ss+msXthpARDzqf1hycIA== 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=ynxNsreBxLM4dS2VSzDZK68/1/ZmGATe/2kh9kCID0Y=; b=ObV3FuAois3jNUo4/NUJO4sPpRD6E2v2uMpbxSUEsHYqutUpFVq+blU0epO/QF/vRtHXqvNBM3M3/TxbMBiUm8DrznGNOkEbDZOvnXIBuLwavO/vx5w6OnCrddDF9QEljkFbPffOYmhUBjxm+GyMdWwX48WV+KreWJFoOpwLVTw= 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 PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) by PH0PR11MB5644.namprd11.prod.outlook.com (2603:10b6:510:ef::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Tue, 5 Oct 2021 13:55:04 +0000 Received: from PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::31cb:3b13:b0e8:d8f4]) by PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::31cb:3b13:b0e8:d8f4%9]) with mapi id 15.20.4566.022; Tue, 5 Oct 2021 13:55:04 +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 v8 15/24] wfx: add hif_rx.c/hif_rx.h Date: Tue, 5 Oct 2021 15:53:51 +0200 Message-Id: <20211005135400.788058-16-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005135400.788058-1-Jerome.Pouiller@silabs.com> References: <20211005135400.788058-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PR3P189CA0084.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::29) To PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) MIME-Version: 1.0 Received: from pc-42.silabs.com (37.71.187.125) by PR3P189CA0084.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Tue, 5 Oct 2021 13:55:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eed64e26-deef-49a8-68e7-08d98807bba5 X-MS-TrafficTypeDiagnostic: PH0PR11MB5644: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1332; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y24HO+zm5j5Kn+M7SMzF7A+HvlHJtERlDyZtMQs/NQMA/beUsCV561dxi7+HD+0UjmUn2upVGHJBFMlTfKFrlp9xu5xkj2yh9sX0YIEcTWrpPoT1Sf5ThPI8DhyNxHnoaXJRvilvJHZOj99JhHz0SrE5TDkOSODrsZavT6lUkAmKwHQWblPPuGQSCPdEIydclYWxkzgmMkIwadu+/7kIqA9vbcl2ux/rzPUjEvfWh3Z5kpLZoeqizEpgMm9iPsqWkJ/jyXPYUaa3qTKBmn+sOat3r9qZ7N5iNHquzYsgp1kNbGPrBlhRmSPRrqFxIsY0k0llYVQRx8uKzLzok/V8q+7YzdZbDhbkRzJsAmePt7VAbCKykAOcFiaC3xz7jCpftTsEexR0luU74wuMw72bxhoIqBnFQ3mj1BQLDsC9f2GDi+aHd1byP+APhMJRK0+aFTVXeS7X2I2bCF8FMdDbSI5LX75BlEGLWowcPylcjP+7uz0h/9OeKMsJHaGn3dayk7KYEKMv36gJBr3IMih+hXihgkHaPh1OCoWPB3H7+CSJi9QcuaULvQOEv45v8x8YPmhZscZVG5xKTCDIvDZ1FiZxeKZesgnrvLyNk/O0N0NySh+bjZDZBOxD8k5IOjjkBc+BGjRD56tNBZNS9l7TgxOQklEGLapN8TdwH9XAVm0sCuKBjEZFrMIWQlCtq6qNnNRi2MVfqHNWbF8aeh+g1A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR11MB5657.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(66946007)(66556008)(8936002)(6916009)(83380400001)(956004)(508600001)(2616005)(66476007)(26005)(186003)(7416002)(2906002)(36756003)(4326008)(30864003)(8676002)(107886003)(66574015)(7696005)(52116002)(38100700002)(316002)(1076003)(5660300002)(86362001)(6666004)(54906003)(38350700002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?xqQfp/KTx3GMMVMfKUw2pmNZiW/S?= =?utf-8?q?pLmUEpQAn82tAJUJOu/rlFPL7Di0dC22L76WkbpgMM+0xT/E+1ymzbUyQUyUAIRjM?= =?utf-8?q?LJR41Heo5puKS/D2FzMT7loxtFIkPwtSo9qXgAQebpGBUO5NIarmuYtSrbcSM8lOS?= =?utf-8?q?GjyO6wFnw7mhDDFcCFF0Rugv1IireK6mmFBUQsPDQUx3YcukFjh5KnMRT65mHc/FS?= =?utf-8?q?6J2/bR5ZtogaL15gVEsRENA+Bc3IJh+jXo5NJBhfnbYEgqGPQT2KUE5TLwD68vFzr?= =?utf-8?q?qCoBX2ghYII98cdwSgjautMT5rIDqXo+lEdmcouoP/4r738JLOOh5NkoqbUpVyL0h?= =?utf-8?q?foSvyj3294/ouTw1/tn5azYI2gMiBgKceTyqw0x0XHO2nmqLa2Ma/a703Qrf/YKzJ?= =?utf-8?q?/Y2KXlbHdjAFBJsTytLJZCe/YZbZ7T2vsTivm3jUwwPKxvEyhqWcBo+EDuRqR9ZqD?= =?utf-8?q?4ZWvK4YmUiS62DPMgfccdyJu3W32OhMoPmfAygZROwJGqYrIOpykHyfuM0umjN8u+?= =?utf-8?q?Tv3XUmVwFnxtXfe8Wi5HkSCcx35CglkBqq1Cg78g3ZMSkckumQjPKQL//Xv2w4zOI?= =?utf-8?q?NwFMPleqJDk2K5SxWjMYfLwui5b5i6qTHi8HNL2H5NMF+19m7nOJCg+r8j6k5bat9?= =?utf-8?q?5IzaY9UkjhlpWtIxqoLY7xeC5cRa7yvIm/ebAdpo5K7wRazh2Jr3e4RSm7BcpOQkq?= =?utf-8?q?N2AMmo2Yb0FlMIwZlv2aUE+l43TJEL3RmwkqnMJyKz/qyvcRyZ57UgbZjNgZ/OAn4?= =?utf-8?q?yn2xXr0AlwapoKm54mZYzl/D8W4tYScfB9Ew4eH+J8tdrogBIbkWZR65SzwjwlqUA?= =?utf-8?q?wKlzfDdCzBqSpmqBkoteGZBHAQai2pZJy1ZosQlagfITFnqXABXyV6xYQnVM0AgzO?= =?utf-8?q?W+3nM1Wp0qcf5B/SyNKMgyqgRRzAM8nr4hv7SzbxZE+uHF4H9gbrzjxj/uxbHkDyq?= =?utf-8?q?VYULl7l1lmSS5+81BAyEBIyI/Z2Stu9GNtCfDkFzmwhXAl2lXtEPZ9e/2riU4+xMP?= =?utf-8?q?SwYTU6K9naBxH6VeY3Jf6isFTUlGVmCjHwGz0dUvCPx2l1lGUNVESG5tZVFtorrdD?= =?utf-8?q?K/YVVpO+F1Fjx+OWmYNEQov0J/TYWu/Y29qhYBG+DcqKdq9mTMYqLTdnwEUpwAm6g?= =?utf-8?q?he2OT7Jyv1ds9bwutNP/+2i2I926AEG5o4/IMWI4Snbf8Cvt2Q5AlYBTlaMYdZijk?= =?utf-8?q?IRN3EBI9hK+7g0+yei88UzChQCDIfzY8apfu5Yi1q9nDGbK0zyS2//DQNvF3Xo/eh?= =?utf-8?q?c/80FvDqp5nBZqm6?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: eed64e26-deef-49a8-68e7-08d98807bba5 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5657.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Oct 2021 13:55:04.6662 (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: 7pH1p7ul28wYtq778fggiMNfybkZNtePHFoMpHdPGq2H2Kfl76gsFuwbkgbYVCLOEwlY2DvBQzQQo1bequTpEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5644 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/hif_rx.c | 414 +++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/hif_rx.h | 17 + 2 files changed, 431 insertions(+) create mode 100644 drivers/net/wireless/silabs/wfx/hif_rx.c create mode 100644 drivers/net/wireless/silabs/wfx/hif_rx.h diff --git a/drivers/net/wireless/silabs/wfx/hif_rx.c b/drivers/net/wireless/silabs/wfx/hif_rx.c new file mode 100644 index 000000000000..13abe3ed481a --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/hif_rx.c @@ -0,0 +1,414 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Handling of the chip-to-host events (aka indications) of the hardware API. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#include +#include + +#include "hif_rx.h" +#include "wfx.h" +#include "scan.h" +#include "bh.h" +#include "sta.h" +#include "data_rx.h" +#include "hif_api_cmd.h" + +static int wfx_hif_generic_confirm(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, const void *buf) +{ + /* All confirm messages start with status */ + int status = le32_to_cpup((__le32 *)buf); + int cmd = hif->id; + int len = le16_to_cpu(hif->len) - 4; /* drop header */ + + WARN(!mutex_is_locked(&wdev->hif_cmd.lock), "data locking error"); + + if (!wdev->hif_cmd.buf_send) { + dev_warn(wdev->dev, "unexpected confirmation: 0x%.2x\n", cmd); + return -EINVAL; + } + + if (cmd != wdev->hif_cmd.buf_send->id) { + dev_warn(wdev->dev, + "chip response mismatch request: 0x%.2x vs 0x%.2x\n", + cmd, wdev->hif_cmd.buf_send->id); + return -EINVAL; + } + + if (wdev->hif_cmd.buf_recv) { + if (wdev->hif_cmd.len_recv >= len && len > 0) + memcpy(wdev->hif_cmd.buf_recv, buf, len); + else + status = -EIO; + } + wdev->hif_cmd.ret = status; + + complete(&wdev->hif_cmd.done); + return status; +} + +static int wfx_hif_tx_confirm(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, const void *buf) +{ + const struct wfx_hif_cnf_tx *body = buf; + + wfx_tx_confirm_cb(wdev, body); + return 0; +} + +static int wfx_hif_multi_tx_confirm(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, const void *buf) +{ + const struct wfx_hif_cnf_multi_transmit *body = buf; + int i; + + WARN(body->num_tx_confs <= 0, "corrupted message"); + for (i = 0; i < body->num_tx_confs; i++) + wfx_tx_confirm_cb(wdev, &body->tx_conf_payload[i]); + return 0; +} + +static int wfx_hif_startup_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf) +{ + const struct wfx_hif_ind_startup *body = buf; + + if (body->status || body->firmware_type > 4) { + dev_err(wdev->dev, "received invalid startup indication"); + return -EINVAL; + } + memcpy(&wdev->hw_caps, body, sizeof(struct wfx_hif_ind_startup)); + complete(&wdev->firmware_ready); + return 0; +} + +static int wfx_hif_wakeup_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf) +{ + if (!wdev->pdata.gpio_wakeup || + gpiod_get_value(wdev->pdata.gpio_wakeup) == 0) { + dev_warn(wdev->dev, "unexpected wake-up indication\n"); + return -EIO; + } + return 0; +} + +static int wfx_hif_receive_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf, struct sk_buff *skb) +{ + struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); + const struct wfx_hif_ind_rx *body = buf; + + if (!wvif) { + dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__); + return -EIO; + } + skb_pull(skb, sizeof(struct wfx_hif_msg) + sizeof(struct wfx_hif_ind_rx)); + wfx_rx_cb(wvif, body, skb); + + return 0; +} + +static int wfx_hif_event_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, const void *buf) +{ + struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); + const struct wfx_hif_ind_event *body = buf; + int type = le32_to_cpu(body->event_id); + + if (!wvif) { + dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__); + return -EIO; + } + + switch (type) { + case HIF_EVENT_IND_RCPI_RSSI: + wfx_event_report_rssi(wvif, body->event_data.rcpi_rssi); + break; + case HIF_EVENT_IND_BSSLOST: + schedule_delayed_work(&wvif->beacon_loss_work, 0); + break; + case HIF_EVENT_IND_BSSREGAINED: + cancel_delayed_work(&wvif->beacon_loss_work); + dev_dbg(wdev->dev, "ignore BSSREGAINED indication\n"); + break; + case HIF_EVENT_IND_PS_MODE_ERROR: + dev_warn(wdev->dev, "error while processing power save request: %d\n", + le32_to_cpu(body->event_data.ps_mode_error)); + break; + default: + dev_warn(wdev->dev, "unhandled event indication: %.2x\n", + type); + break; + } + return 0; +} + +static int wfx_hif_pm_mode_complete_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf) +{ + struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); + + if (!wvif) { + dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__); + return -EIO; + } + complete(&wvif->set_pm_mode_complete); + + return 0; +} + +static int wfx_hif_scan_complete_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf) +{ + struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); + const struct wfx_hif_ind_scan_cmpl *body = buf; + + if (!wvif) { + dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__); + return -EIO; + } + + wfx_scan_complete(wvif, body->num_channels_completed); + + return 0; +} + +static int wfx_hif_join_complete_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf) +{ + struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface); + + if (!wvif) { + dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__); + return -EIO; + } + dev_warn(wdev->dev, "unattended JoinCompleteInd\n"); + + return 0; +} + +static int wfx_hif_suspend_resume_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf) +{ + const struct wfx_hif_ind_suspend_resume_tx *body = buf; + struct wfx_vif *wvif; + + if (body->bc_mc_only) { + wvif = wdev_to_wvif(wdev, hif->interface); + if (!wvif) { + dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__); + return -EIO; + } + if (body->resume) + wfx_suspend_resume_mc(wvif, STA_NOTIFY_AWAKE); + else + wfx_suspend_resume_mc(wvif, STA_NOTIFY_SLEEP); + } else { + WARN(body->peer_sta_set, "misunderstood indication"); + WARN(hif->interface != 2, "misunderstood indication"); + if (body->resume) + wfx_suspend_hot_dev(wdev, STA_NOTIFY_AWAKE); + else + wfx_suspend_hot_dev(wdev, STA_NOTIFY_SLEEP); + } + + return 0; +} + +static int wfx_hif_generic_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf) +{ + const struct wfx_hif_ind_generic *body = buf; + int type = le32_to_cpu(body->type); + + switch (type) { + case HIF_GENERIC_INDICATION_TYPE_RAW: + return 0; + case HIF_GENERIC_INDICATION_TYPE_STRING: + dev_info(wdev->dev, "firmware says: %s\n", (char *)&body->data); + return 0; + case HIF_GENERIC_INDICATION_TYPE_RX_STATS: + mutex_lock(&wdev->rx_stats_lock); + /* Older firmware send a generic indication beside RxStats */ + if (!wfx_api_older_than(wdev, 1, 4)) + dev_info(wdev->dev, "Rx test ongoing. Temperature: %d degrees C\n", + body->data.rx_stats.current_temp); + memcpy(&wdev->rx_stats, &body->data.rx_stats, + sizeof(wdev->rx_stats)); + mutex_unlock(&wdev->rx_stats_lock); + return 0; + case HIF_GENERIC_INDICATION_TYPE_TX_POWER_LOOP_INFO: + mutex_lock(&wdev->tx_power_loop_info_lock); + memcpy(&wdev->tx_power_loop_info, + &body->data.tx_power_loop_info, + sizeof(wdev->tx_power_loop_info)); + mutex_unlock(&wdev->tx_power_loop_info_lock); + return 0; + default: + dev_err(wdev->dev, "generic_indication: unknown indication type: %#.8x\n", + type); + return -EIO; + } +} + +static const struct { + int val; + const char *str; + bool has_param; +} hif_errors[] = { + { HIF_ERROR_FIRMWARE_ROLLBACK, + "rollback status" }, + { HIF_ERROR_FIRMWARE_DEBUG_ENABLED, + "debug feature enabled" }, + { HIF_ERROR_PDS_PAYLOAD, + "PDS version is not supported" }, + { HIF_ERROR_PDS_TESTFEATURE, + "PDS ask for an unknown test mode" }, + { HIF_ERROR_OOR_VOLTAGE, + "out-of-range power supply voltage", true }, + { HIF_ERROR_OOR_TEMPERATURE, + "out-of-range temperature", true }, + { HIF_ERROR_SLK_REQ_DURING_KEY_EXCHANGE, + "secure link does not expect request during key exchange" }, + { HIF_ERROR_SLK_SESSION_KEY, + "secure link session key is invalid" }, + { HIF_ERROR_SLK_OVERFLOW, + "secure link overflow" }, + { HIF_ERROR_SLK_WRONG_ENCRYPTION_STATE, + "secure link messages list does not match message encryption" }, + { HIF_ERROR_SLK_UNCONFIGURED, + "secure link not yet configured" }, + { HIF_ERROR_HIF_BUS_FREQUENCY_TOO_LOW, + "bus clock is too slow (<1kHz)" }, + { HIF_ERROR_HIF_RX_DATA_TOO_LARGE, + "HIF message too large" }, + /* Following errors only exists in old firmware versions: */ + { HIF_ERROR_HIF_TX_QUEUE_FULL, + "HIF messages queue is full" }, + { HIF_ERROR_HIF_BUS, + "HIF bus" }, + { HIF_ERROR_SLK_MULTI_TX_UNSUPPORTED, + "secure link does not support multi-tx confirmations" }, + { HIF_ERROR_SLK_OUTDATED_SESSION_KEY, + "secure link session key is outdated" }, + { HIF_ERROR_SLK_DECRYPTION, + "secure link params (nonce or tag) mismatch" }, +}; + +static int wfx_hif_error_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, const void *buf) +{ + const struct wfx_hif_ind_error *body = buf; + int type = le32_to_cpu(body->type); + int param = (s8)body->data[0]; + int i; + + for (i = 0; i < ARRAY_SIZE(hif_errors); i++) + if (type == hif_errors[i].val) + break; + if (i < ARRAY_SIZE(hif_errors)) + if (hif_errors[i].has_param) + dev_err(wdev->dev, "asynchronous error: %s: %d\n", + hif_errors[i].str, param); + else + dev_err(wdev->dev, "asynchronous error: %s\n", + hif_errors[i].str); + else + dev_err(wdev->dev, "asynchronous error: unknown: %08x\n", type); + print_hex_dump(KERN_INFO, "hif: ", DUMP_PREFIX_OFFSET, + 16, 1, hif, le16_to_cpu(hif->len), false); + wdev->chip_frozen = true; + + return 0; +}; + +static int wfx_hif_exception_indication(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, + const void *buf) +{ + const struct wfx_hif_ind_exception *body = buf; + int type = le32_to_cpu(body->type); + + if (type == 4) + dev_err(wdev->dev, "firmware assert %d\n", + le32_to_cpup((__le32 *)body->data)); + else + dev_err(wdev->dev, "firmware exception\n"); + print_hex_dump(KERN_INFO, "hif: ", DUMP_PREFIX_OFFSET, + 16, 1, hif, le16_to_cpu(hif->len), false); + wdev->chip_frozen = true; + + return -1; +} + +static const struct { + int msg_id; + int (*handler)(struct wfx_dev *wdev, + const struct wfx_hif_msg *hif, const void *buf); +} hif_handlers[] = { + /* Confirmations */ + { HIF_CNF_ID_TX, wfx_hif_tx_confirm }, + { HIF_CNF_ID_MULTI_TRANSMIT, wfx_hif_multi_tx_confirm }, + /* Indications */ + { HIF_IND_ID_STARTUP, wfx_hif_startup_indication }, + { HIF_IND_ID_WAKEUP, wfx_hif_wakeup_indication }, + { HIF_IND_ID_JOIN_COMPLETE, wfx_hif_join_complete_indication }, + { HIF_IND_ID_SET_PM_MODE_CMPL, wfx_hif_pm_mode_complete_indication }, + { HIF_IND_ID_SCAN_CMPL, wfx_hif_scan_complete_indication }, + { HIF_IND_ID_SUSPEND_RESUME_TX, wfx_hif_suspend_resume_indication }, + { HIF_IND_ID_EVENT, wfx_hif_event_indication }, + { HIF_IND_ID_GENERIC, wfx_hif_generic_indication }, + { HIF_IND_ID_ERROR, wfx_hif_error_indication }, + { HIF_IND_ID_EXCEPTION, wfx_hif_exception_indication }, + /* FIXME: allocate skb_p from wfx_hif_receive_indication and make it generic */ + //{ HIF_IND_ID_RX, wfx_hif_receive_indication }, +}; + +void wfx_handle_rx(struct wfx_dev *wdev, struct sk_buff *skb) +{ + int i; + const struct wfx_hif_msg *hif = (const struct wfx_hif_msg *)skb->data; + int hif_id = hif->id; + + if (hif_id == HIF_IND_ID_RX) { + /* wfx_hif_receive_indication take care of skb lifetime */ + wfx_hif_receive_indication(wdev, hif, hif->body, skb); + return; + } + /* Note: mutex_is_lock cause an implicit memory barrier that protect + * buf_send + */ + if (mutex_is_locked(&wdev->hif_cmd.lock) && + wdev->hif_cmd.buf_send && + wdev->hif_cmd.buf_send->id == hif_id) { + wfx_hif_generic_confirm(wdev, hif, hif->body); + goto free; + } + for (i = 0; i < ARRAY_SIZE(hif_handlers); i++) { + if (hif_handlers[i].msg_id == hif_id) { + if (hif_handlers[i].handler) + hif_handlers[i].handler(wdev, hif, hif->body); + goto free; + } + } + if (hif_id & HIF_ID_IS_INDICATION) + dev_err(wdev->dev, "unsupported HIF indication: ID %02x\n", + hif_id); + else + dev_err(wdev->dev, "unexpected HIF confirmation: ID %02x\n", + hif_id); +free: + dev_kfree_skb(skb); +} diff --git a/drivers/net/wireless/silabs/wfx/hif_rx.h b/drivers/net/wireless/silabs/wfx/hif_rx.h new file mode 100644 index 000000000000..96543b81fa77 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/hif_rx.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Handling of the chip-to-host events (aka indications) of the hardware API. + * + * Copyright (c) 2017-2019, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + * Copyright (C) 2010, ST-Ericsson SA + */ +#ifndef WFX_HIF_RX_H +#define WFX_HIF_RX_H + +struct wfx_dev; +struct sk_buff; + +void wfx_handle_rx(struct wfx_dev *wdev, struct sk_buff *skb); + +#endif