From patchwork Tue Jan 11 17:14:15 2022 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: 12710128 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C80B8C433EF for ; Tue, 11 Jan 2022 17:16:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344065AbiAKRQC (ORCPT ); Tue, 11 Jan 2022 12:16:02 -0500 Received: from mail-co1nam11on2074.outbound.protection.outlook.com ([40.107.220.74]:39233 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1344069AbiAKRP1 (ORCPT ); Tue, 11 Jan 2022 12:15:27 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SpOSxtRj+fgSSrIlSC4Im1iEhWyt2MCmbVxhSDTZ7D8Y/zh0Uh8Y+iwkOv8GzcsOx+WnsMV/OS4jeZnfZKzaRaVvBUF7XzQDPNfwM1MUx5o9hKMObpxzJjRoUeXI069pBOEBrNyUUT+AXVkltd9XrQXL/g0MOwZWK1F1rf9IuD+dHyjayuYY9Qt4Y49CxK2uZYUehUpkai/qNKIbuFSY/UCwF5Gl0TGE14RaC/YOprGw71xQcO2YSd2+mRRh9wAVfIE+vebaiumrOa6xCo5fy7uhv9nsGpfZ+UjE/IQ4yWSZj4P1P/fVbvuBvcgC3BjrzFiIkqZCQ1aqnBLa5QxGyg== 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=j9h0zA7BZD91wuRETbxelKSdy5XxdmI3rjzlFKTtFEg=; b=Z0FtIS/1z/PPIlh0lszDq4umFqveFO566K9gVnG6GQzkUC7x01Ur4bGarVTLEEqNcxlNqV9DMxwaOchGmdAYw1p+9K+/sdRfcpmrECqYbfijo1Ez1CKkdqvwnd1jaoZCuiORIb0GpCws7AGqjHGT+OQ+ulR1gE5Pz6fdRN5Z4CYuTx1/gG5suwjT1b/zhJH0pX4TVHLvDbG3GWEBdyXhtsD+ohC8wG4H87e8pIo5sXgLzVI15lfghMlB+NCJXMR6QZkohUFuE7srCtwcOnhZKu7YFlgvn3asTmqCznOmdI09mr2q3CyD/sG4vl91Fy7Aj4s0vM+gnjuZ964Pl8D//A== 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=j9h0zA7BZD91wuRETbxelKSdy5XxdmI3rjzlFKTtFEg=; b=i1Pbzb/inYxUQO2WZo+FS/Uokwu5NdDaD4t1b1Gvs7QY89cJJZU+JlOVyVXqSmVNVeWMskkhUb5IxGukvCu+6K8ZEa7Xi2E6a6EE79/g17EGzBZjYJqF7+u8+E0b5iK8K82OjKLfnH4H9Q7yM+YVgTSFLTsri+IEsozgnfjVmxo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=silabs.com; Received: from PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) by PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.11; Tue, 11 Jan 2022 17:15:25 +0000 Received: from PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::d031:da9e:71a:73e4]) by PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::d031:da9e:71a:73e4%6]) with mapi id 15.20.4867.012; Tue, 11 Jan 2022 17:15:25 +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 v9 15/24] wfx: add hif_rx.c/hif_rx.h Date: Tue, 11 Jan 2022 18:14:15 +0100 Message-Id: <20220111171424.862764-16-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220111171424.862764-1-Jerome.Pouiller@silabs.com> References: <20220111171424.862764-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SN1PR12CA0099.namprd12.prod.outlook.com (2603:10b6:802:21::34) To PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16a027b1-44a8-4084-6d9a-08d9d525f4fb X-MS-TrafficTypeDiagnostic: PH0PR11MB5657:EE_ 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: 1cjyTKj/S0Hd2WLDFkkEE2a1jFNYjYoxjHN2wYAytArayA8lQGrjqLGjXDvEfvj5nS9NEfbUYekniGizAjAY3fI7jbUWvFqVa50LmONacolHU12FTzSXeC2HoSRYsrkM/WVS8vVYgFKrWze2tI39mAbDtjN2m3zWiMNDo+o1DowXy0BjfsWUwrrX2h4Cn43A2x3PQ/jn2rSBvrcBTjoVPzUOIkWta1umD/54xrrxsvQacVCaHLBMxewKFvWeOXWz7sQWCKjxTYck4MqzfH8fQq4fUmxg89q416WOixuejBrmJ4ehQ8ks0QVtQIF7Mg6qur9CZLmndnDfky5DNwqc+2XVEPjuxCJh1o9qdHx6nNuzIgRQwvBeIJqgTJJd4YNMmneTlXS1Xymqi20ZBHrX+Ni1tWo3r5oaCwZa/3VFob/nSFBf1sU0pt21nFr1u2/JeVRPI2o2+e/1A32G3uBfzfeut4ZwQ+ib6PI+0Km/NlppBBx2TNlwb6NuvBGbxkSaD7c7ouzt9W9XI3iVDZGzAT4oQxzoKrahYzQirNjmlv8kZXoo8HqmLTVUe0c7eaImmnfraPzG7E+2lYzi8rBchKI7jzbsibs+EV80TDe5kegsa8cNW7qwRy6kuSGxX5xR99toxiNQ4LLCmZZFXLzmcw== 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)(6506007)(66574015)(86362001)(5660300002)(8936002)(7416002)(6916009)(8676002)(83380400001)(1076003)(6486002)(36756003)(38100700002)(186003)(66946007)(6666004)(2616005)(4326008)(2906002)(316002)(107886003)(66556008)(66476007)(54906003)(6512007)(508600001)(30864003)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?0jFzT7bhhT5XQjj43c5KEAalnPp0?= =?utf-8?q?1lfm2qowAljGBwchYf1Mq9lvudJK/zuGCPVG1VAMCT/zbI1sBAzpsXOlt7PxXLD6N?= =?utf-8?q?OqIc0LK3Ow3PKGUrkHSV7p0wQz0Labp7jZCasfPUAKtUBCJGGpYeXZJDhiN43/cZq?= =?utf-8?q?oDqIYh1CEtXCUkx3m9Uxi6blU1Sd8s/RaY4GzJrPacTB/KfmqLxPHtA/iuYlInbng?= =?utf-8?q?pxZn1akTGcSs/WG5bcPOKyDVLqsRoLnfrjbKOrG3WaEpOokVN/LT7AfKgI3tB8xMc?= =?utf-8?q?j1HeXf8gdLA7Qo2WYiTq0pPDS6q8vVGTswhRU7KeFDr+KgrgwOiLRy+JEYkfbBnOm?= =?utf-8?q?f/r8QUNRrnflUvOK4ziSW4laAoI8j5Xm6898Nl0Xg5TgUQgiWdMA7ywZGA3zTHKoV?= =?utf-8?q?z+w+QHfhY//yBiKq2kDF8l4SyrH+QKOaeVTtjIo2zuIS36dTW9LZbiCpZiI6Q6mWT?= =?utf-8?q?4l/NC0CYu219nkc7JRHFEVHGs/gi30/NIpdrDNG6ynaoSkFhiO9MTEXx8Kr21rs4Q?= =?utf-8?q?s/GYw5bbwvCMC6KRZr8gGLVSMLoVsZY7lmgmRjRBTq0rajfNFfX0RZaKLS9uAqRoT?= =?utf-8?q?fcH64TwlNjfMFe7OqI6jkhm5o3qZr8ps83LWKHv+l+bEbar6Il8hkBIA0ITW2DleN?= =?utf-8?q?CJMnR6XFulq34QqZlWuHYigMj8qvqJXLw2dphQ+3e3ns7IpBvw3bVFpFmQglZODmR?= =?utf-8?q?mjuedSZWUaoVVReuObJBI7usDf4vPYomlI6Ukz+aALLKfjC1694cIw3siEnQiMv7C?= =?utf-8?q?UND7xOoFMKINsA/LOgcYg8g/7jyyhiT/8J/dFZeberUxcihw0xnucOxfFIwHPxnxz?= =?utf-8?q?3NIwPFCThoHHiYf+F1zB6X2widu4rhoK75zk0koZNnawaJs2FEpGtXmDjOu33Dus3?= =?utf-8?q?PWdMqiiYgeDVlazS9cVv1s4CoUN3vakaDkhHGIQ5SOTWtz5pJ68LWinAeB5eyj3JF?= =?utf-8?q?wDMsMwQFfTJjjMz7sUWVuZPmQapvD8yPJVM827S9DXwdRvZ13fPWw2iYTpWIxRSI+?= =?utf-8?q?tcSmK633j3714ESEruL+/quVlEaSl5JiOUdOiHZtbGetheuvEtwnzMAsNd9SVRuGh?= =?utf-8?q?cCftPuvN+1l3iLkS2FPpA2ZPnmIjZN5Z8/9mlWjQu7NwBo53hUk9hhPgRk7b7gByc?= =?utf-8?q?y8T3yFiQgo7kD0ROUuuSksV1oJf0xANkic/jorR+o0zqmaNmSuVwfyNe8VIVH2Ypw?= =?utf-8?q?qz/QyeExqhYdPX0EyVOM3U7S8kr1gtAK/VOzC9ig00Sx6a5z/ZdwR98bJgFTg1CxW?= =?utf-8?q?NiRxA1dKSFQzvhZH5ILQI92yHoKolKnknZLvi74b4i1BF5466a6KLrlDj59z35Qtv?= =?utf-8?q?lk4bjxmb9ADZszZhO7IiyUTVwezICvz1yR+1FNeSz+K9CxWMn6gp/w5qVztpo1ImL?= =?utf-8?q?ltF1+Imkc0mGmmwyRD1MoEy4+cUxxrKHkdV8jAyZ1aw5CA6TM6Pv+udFb2PYn/tVf?= =?utf-8?q?2xRbjnqD+3/+b/djvTIrwW1gybvNgc3WKOVc9OfHqvUIjpTVeI6TM+bCVqKc+35nS?= =?utf-8?q?tErlHVwKQyB2RieRJBEgNT+XZoNz5JlztIPQWnjapfAagIMbmFewgMIp3ylgNWS+w?= =?utf-8?q?ovQSEFFhsMrq5FrqlejJbgQMnvuEDCAMfh3iCQUjhM6ySY5HzPwgfQ=3D?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 16a027b1-44a8-4084-6d9a-08d9d525f4fb X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5657.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2022 17:15:25.2759 (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: UHWHP1XFjVnGtWKRm8cTds1wap02inWqVVRuHBa9HCWsUv2vbX7HlQcpwApXNSRDVrT/WgwrB9pHeUvfUez0Xw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5657 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 | 392 +++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/hif_rx.h | 17 + 2 files changed, 409 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..302bdb2bf036 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/hif_rx.c @@ -0,0 +1,392 @@ +// 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