From patchwork Tue Jan 11 17:14:21 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: 12710141 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 32916C433FE for ; Tue, 11 Jan 2022 17:18:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344043AbiAKRSI (ORCPT ); Tue, 11 Jan 2022 12:18:08 -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 S241871AbiAKRQp (ORCPT ); Tue, 11 Jan 2022 12:16:45 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iLXtbwYlZJidTQJuOCHlq4uujgXKcuRIGphVthcLPZM7reKUSZGQTqKe8lEYY2/bmXBNqmog2c68HOGjtJFDDstP6mQLJC7LLJOFZPbcdVklbfTtoG3uylvM78sWdmgYn0fGqtZutxtgLrfUhrRAKSHC4Qm97vXpUnI55o/MM2if7j4xz8GkM7FRRD2Q7w4S8UNNMs6HEE0aXfrBn5aQyDEt0fYbx016J1qPhnxy3ETSMRCb215gPCFcCpfSvHD7PdD667K9Ixnndp+fbA5IReOlUzKWvXjZKEUT1P3+dJ9zTJkb0N3UbzUdmipzydSEAVZnSBJEr9eal5Aq6frVcg== 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=qoysj/mtAVSNUXQ7KwO2eNZhDpLMvPi23Qvt5OyTevw=; b=nW4OlQQkNN3rWroSCVKqpzFFrvxXmbrQVTHolxW3fhMDDJLxWtyXLxSwWyyzR1b9/fiboCruVHU31EPwUZnqHbHcdwoE20h5wQtd70RB7VQ2Qi3Tp41X+JK/gh1+E+BKcmXKzuyIH8poDLbnjiR+l17KM3OLUkn/GFIoAgNOWGaekY+YVSZhXRp2yNStKE5JyUuiJhOtsgsndVjyW0Yjd/YTkuOVX62n0U+BWwNBntYRu4MaaYPdw2fMZUFgQ6ZmRJnDH0XNEnzk1sx46h2UbU3oJj3ng8BNKHC43tHyst+2fCqYJU+XACvANs4TCjw8Q3JZCrn4b9eKAlQ1eJcG9Q== 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=qoysj/mtAVSNUXQ7KwO2eNZhDpLMvPi23Qvt5OyTevw=; b=mynXS9lbEoX7vhmP7HjxPdjSqYooGhAgMt3OLnnpgPUzoagCZFJUqNCruuA1nGc9NwvaqfuNVgPFYPRzNEozEo2PUznCVfPpyHga8s/voRQ8Y+L10tNGAFf9uF01jgYdwQYEEtos6b+ahcpzrMh5rmoGiw/4K/XmICOLGziFcQU= 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:41 +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:41 +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 21/24] wfx: add debug.c/debug.h Date: Tue, 11 Jan 2022 18:14:21 +0100 Message-Id: <20220111171424.862764-22-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: ffb89243-dda4-431e-fb08-08d9d525feac X-MS-TrafficTypeDiagnostic: PH0PR11MB5657:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:989; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p8nqKxg1ecEICMrFWgl14/ieSQff4aAIioeY4uknQWar3dtV0MmVubBOiKW3qCLjlm6Zn86aTh8BhK8JbXJuQlKUc8bmmdfXHUIQkkNbyyEYdGJ2SlqG+0Q0A5SMOGIhU+MZEFiVzcS2Ax2g6esHcEFPqrLp8araD+XtFkejFBLDXLkH9myd8dseVfiujcgG6bCmYNkcNyGGWuyqt00s3+q1Nbnhfl8gDENQp/LV7RXHy+O/BVcTVeHmUQXOAmDFcjvgu8+JANL4oVRW76j1Gz6nLSHFuEpXCIaFT4nSDqDRwY6QiXe59wYL0dxIGDh3nJb/s8eA1dBUDnxpD4jJ0UGp0YkX9DPwehZ7jPLGqguXDnIldGPBblc334oWPFHIfwHbmB/SGg0leQPDJixVqyiqZ8emg5n0XdLZshKUzyViNtLzNED6Hik7mTfdiWuqoXzro48/gIQaKYsNYIGzrXbjhlNoA8beMwqKEetlWe/95QNchvAZNpavqWTCGGKFw6kR3Uy0h+ThCP3LIX7ftsW8XSDa4/vhRWheD20WTInKUGRZVug5080sN+b/J0lGsxbSiL6T5Pur7U7IGLVzrJwdEUS0jCWOMEQI/jdUsqNYRuIwSVGpBR142PnnTMI4fPbXoBERU6amJObRMDWd/Q== 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?pg2izubilGalGVRxGoPA1yj3wt47?= =?utf-8?q?OfZax7UpbyJaaBIaHHFnw/CqehQbCDAxJ1QKF7E84UKKg8TI5xi9qX3Dx3PJuxVj1?= =?utf-8?q?zYfwjrQZhVFyF13qMAeVaEkKG/T7tzI92+pwXbjFq+lFeoKSck7f3qt8oxKNBB/uW?= =?utf-8?q?3uAZAhRjjAU/bdwq0zgJNWbrg/Q1y3yF0zYjtUSDEZXc+VN4vFHJEtunNtwqBHnry?= =?utf-8?q?9ntLLuSETlczPz3cnb3EaUjdhJFjxQ3pp8MaO+0OF7R+0wooXzYa6DES8CjDb38GN?= =?utf-8?q?PbvbyEkR47OC4bUyrLjFG/CS++heY7tL0xWGwBGYdNxsLbG/URascIw0APjhAlk+c?= =?utf-8?q?ItBf6PkRXdO4Su/SXeLT93KMMG34KxXzobv3cAIBrdtXGXU2ZuoHw2dCwpBveBuV6?= =?utf-8?q?bbRuTuSJJdd5K6rsWsAj0wA08sKVLSFZ9Seajf2Tjk7mgBgt39D6L7rrnRyg7LlWz?= =?utf-8?q?jS+pulxiX9gtuUDTUdKzvyt+a+8pkeQm5qeWWOpDwP8HuFehE6LKhLKu+IpAhxkBQ?= =?utf-8?q?Ap6nsdSca2YzYPonuONkFg5KG/ZEdorVKdAfV7DIowAoINn6n21Qe54W8hNKnlgEl?= =?utf-8?q?TslTOodrOq0WL9oiCyDThuu9J7az1w2tzhwzjlhYNJb8M3wivHx84xqw24PWrICwg?= =?utf-8?q?ruayIJlnLp8adM15Ky1BJVcxkMt4/jLDXwoazKdrMnyudhsurZ8W8kKVfUlYGsakK?= =?utf-8?q?wACo2MAWSQNnP8YEHxoIi7LRqi0DjMDXC49FSE+WB9KPk7CL3JX8Rk2TVAjlVqCFU?= =?utf-8?q?oa26qHOESODhD26I+rr4IiboETqiRiIZ1dv/to9eVEalgOfj4xr7bj9x8fEh11AO8?= =?utf-8?q?gcTNOD0nctPvHihJUfqIk+pNtk5TwhOStDle7x+2EvoWBKHfejjhWvGAA8vKf5myR?= =?utf-8?q?anUe754Glnk5zYYCY+JqPrbMTAB0VSy77vcaQMFJJNaWTAy1SVBkulyJIPNDSWSF7?= =?utf-8?q?5Pl7F+dNbxlNkbAs1Rvk1aJENwmHLVeZRtGsqy7Dh+Kyr9AluBH8gNWvR+ULkcEGW?= =?utf-8?q?8eHeLL1XWBbC3imWZlt3bmqV5pBkrWZjB747l/9oG0fT3yIgYoaXyT1mv0ODMr215?= =?utf-8?q?AVgGq+8uHMywcg1kPFpmvbadXc1ysvOjTNVgm6R2oT4XOX5HTNUw+DajOaUPq6cDM?= =?utf-8?q?D7vOI3QFQKhiNeZ0IKZ+NfDDMsC7+L+03r2cLW3bwbnJL7SgRr5yl6ASbI075Mdol?= =?utf-8?q?5GBCUcmhgo+wgeOms7ft7VZjanuQi9fgSccLIZCndQqsfIJHinJFTi6sT2+jdxUO8?= =?utf-8?q?IihnaEnAdRUu8CxBUsQiXyc2jIVw/nDLYzw9tCsXMMfkecaxJxySWfAyrYquhlj6r?= =?utf-8?q?yRbtTAfSoJNOMWoftjBNDl5ZpvnVdNimWYnilpWBKh+OH3aKfEsoCMLKaIdDAGVaK?= =?utf-8?q?sgLsRRseO0c5r0+HylJ2IgtoTZoACdMQhomIePqtzGY+6rEFap/W3O7cE0SYbSlY5?= =?utf-8?q?PtJrBz4Gxc7kF0IAYYrr+hvOJeyvoRwitSuFWjLz1FtDuy4VMBuo6Bigsr4Gk6xZW?= =?utf-8?q?47Oyrc3vVCf+HE0N3Ua+v93FQ7ZiKb4WQLHW+ZAwHA23Icg5wN4CHyFc2aOAOtlSK?= =?utf-8?q?2mmC04pw6zIDnR7TDBHU3mjSLaDjnAekN8FUJcry72PDmEflxmkSA8=3D?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: ffb89243-dda4-431e-fb08-08d9d525feac 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:41.5547 (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: XPRIGg5W4WpNYNs5PlNhlKid+2BNKZGiHBjQWrN/4+PuPvOxIdAsJtOB3aypZxq5j1o5H6QZnNWj1Iw/xEUt7A== 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/debug.c | 331 ++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/debug.h | 19 ++ 2 files changed, 350 insertions(+) create mode 100644 drivers/net/wireless/silabs/wfx/debug.c create mode 100644 drivers/net/wireless/silabs/wfx/debug.h diff --git a/drivers/net/wireless/silabs/wfx/debug.c b/drivers/net/wireless/silabs/wfx/debug.c new file mode 100644 index 000000000000..e8265208f9a5 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/debug.c @@ -0,0 +1,331 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Debugfs interface. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#include +#include +#include + +#include "debug.h" +#include "wfx.h" +#include "sta.h" +#include "main.h" +#include "hif_tx.h" +#include "hif_tx_mib.h" + +#define CREATE_TRACE_POINTS +#include "traces.h" + +static const struct trace_print_flags hif_msg_print_map[] = { + hif_msg_list, +}; + +static const struct trace_print_flags hif_mib_print_map[] = { + hif_mib_list, +}; + +static const struct trace_print_flags wfx_reg_print_map[] = { + wfx_reg_list, +}; + +static const char *get_symbol(unsigned long val, const struct trace_print_flags *symbol_array) +{ + int i; + + for (i = 0; symbol_array[i].mask != -1; i++) { + if (val == symbol_array[i].mask) + return symbol_array[i].name; + } + + return "unknown"; +} + +const char *wfx_get_hif_name(unsigned long id) +{ + return get_symbol(id, hif_msg_print_map); +} + +const char *wfx_get_mib_name(unsigned long id) +{ + return get_symbol(id, hif_mib_print_map); +} + +const char *wfx_get_reg_name(unsigned long id) +{ + return get_symbol(id, wfx_reg_print_map); +} + +static int wfx_counters_show(struct seq_file *seq, void *v) +{ + int ret, i; + struct wfx_dev *wdev = seq->private; + struct wfx_hif_mib_extended_count_table counters[3]; + + for (i = 0; i < ARRAY_SIZE(counters); i++) { + ret = wfx_hif_get_counters_table(wdev, i, counters + i); + if (ret < 0) + return ret; + if (ret > 0) + return -EIO; + } + + seq_printf(seq, "%-24s %12s %12s %12s\n", "", "global", "iface 0", "iface 1"); + +#define PUT_COUNTER(name) \ + seq_printf(seq, "%-24s %12d %12d %12d\n", #name, \ + le32_to_cpu(counters[2].count_##name), \ + le32_to_cpu(counters[0].count_##name), \ + le32_to_cpu(counters[1].count_##name)) + + PUT_COUNTER(tx_frames); + PUT_COUNTER(tx_frames_multicast); + PUT_COUNTER(tx_frames_success); + PUT_COUNTER(tx_frames_retried); + PUT_COUNTER(tx_frames_multi_retried); + PUT_COUNTER(tx_frames_failed); + + PUT_COUNTER(ack_failed); + PUT_COUNTER(rts_success); + PUT_COUNTER(rts_failed); + + PUT_COUNTER(rx_frames); + PUT_COUNTER(rx_frames_multicast); + PUT_COUNTER(rx_frames_success); + PUT_COUNTER(rx_frames_failed); + PUT_COUNTER(drop_plcp); + PUT_COUNTER(drop_fcs); + PUT_COUNTER(drop_no_key); + PUT_COUNTER(drop_decryption); + PUT_COUNTER(drop_tkip_mic); + PUT_COUNTER(drop_bip_mic); + PUT_COUNTER(drop_cmac_icv); + PUT_COUNTER(drop_cmac_replay); + PUT_COUNTER(drop_ccmp_replay); + PUT_COUNTER(drop_duplicate); + + PUT_COUNTER(rx_bcn_miss); + PUT_COUNTER(rx_bcn_success); + PUT_COUNTER(rx_bcn_dtim); + PUT_COUNTER(rx_bcn_dtim_aid0_clr); + PUT_COUNTER(rx_bcn_dtim_aid0_set); + +#undef PUT_COUNTER + + for (i = 0; i < ARRAY_SIZE(counters[0].reserved); i++) + seq_printf(seq, "reserved[%02d]%12s %12d %12d %12d\n", i, "", + le32_to_cpu(counters[2].reserved[i]), + le32_to_cpu(counters[0].reserved[i]), + le32_to_cpu(counters[1].reserved[i])); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(wfx_counters); + +static const char * const channel_names[] = { + [0] = "1M", + [1] = "2M", + [2] = "5.5M", + [3] = "11M", + /* Entries 4 and 5 does not exist */ + [6] = "6M", + [7] = "9M", + [8] = "12M", + [9] = "18M", + [10] = "24M", + [11] = "36M", + [12] = "48M", + [13] = "54M", + [14] = "MCS0", + [15] = "MCS1", + [16] = "MCS2", + [17] = "MCS3", + [18] = "MCS4", + [19] = "MCS5", + [20] = "MCS6", + [21] = "MCS7", +}; + +static int wfx_rx_stats_show(struct seq_file *seq, void *v) +{ + struct wfx_dev *wdev = seq->private; + struct wfx_hif_rx_stats *st = &wdev->rx_stats; + int i; + + mutex_lock(&wdev->rx_stats_lock); + seq_printf(seq, "Timestamp: %dus\n", st->date); + seq_printf(seq, "Low power clock: frequency %uHz, external %s\n", + le32_to_cpu(st->pwr_clk_freq), st->is_ext_pwr_clk ? "yes" : "no"); + seq_printf(seq, "Num. of frames: %d, PER (x10e4): %d, Throughput: %dKbps/s\n", + st->nb_rx_frame, st->per_total, st->throughput); + seq_puts(seq, " Num. of PER RSSI SNR CFO\n"); + seq_puts(seq, " frames (x10e4) (dBm) (dB) (kHz)\n"); + for (i = 0; i < ARRAY_SIZE(channel_names); i++) { + if (channel_names[i]) + seq_printf(seq, "%5s %8d %8d %8d %8d %8d\n", + channel_names[i], + le32_to_cpu(st->nb_rx_by_rate[i]), + le16_to_cpu(st->per[i]), + (s16)le16_to_cpu(st->rssi[i]) / 100, + (s16)le16_to_cpu(st->snr[i]) / 100, + (s16)le16_to_cpu(st->cfo[i])); + } + mutex_unlock(&wdev->rx_stats_lock); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(wfx_rx_stats); + +static int wfx_tx_power_loop_show(struct seq_file *seq, void *v) +{ + struct wfx_dev *wdev = seq->private; + struct wfx_hif_tx_power_loop_info *st = &wdev->tx_power_loop_info; + int tmp; + + mutex_lock(&wdev->tx_power_loop_info_lock); + tmp = le16_to_cpu(st->tx_gain_dig); + seq_printf(seq, "Tx gain digital: %d\n", tmp); + tmp = le16_to_cpu(st->tx_gain_pa); + seq_printf(seq, "Tx gain PA: %d\n", tmp); + tmp = (s16)le16_to_cpu(st->target_pout); + seq_printf(seq, "Target Pout: %d.%02d dBm\n", tmp / 4, (tmp % 4) * 25); + tmp = (s16)le16_to_cpu(st->p_estimation); + seq_printf(seq, "FEM Pout: %d.%02d dBm\n", tmp / 4, (tmp % 4) * 25); + tmp = le16_to_cpu(st->vpdet); + seq_printf(seq, "Vpdet: %d mV\n", tmp); + seq_printf(seq, "Measure index: %d\n", st->measurement_index); + mutex_unlock(&wdev->tx_power_loop_info_lock); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(wfx_tx_power_loop); + +static ssize_t wfx_send_pds_write(struct file *file, const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct wfx_dev *wdev = file->private_data; + char *buf; + int ret; + + if (*ppos != 0) { + dev_dbg(wdev->dev, "PDS data must be written in one transaction"); + return -EBUSY; + } + buf = memdup_user(user_buf, count); + if (IS_ERR(buf)) + return PTR_ERR(buf); + *ppos = *ppos + count; + ret = wfx_send_pds(wdev, buf, count); + kfree(buf); + if (ret < 0) + return ret; + return count; +} + +static const struct file_operations wfx_send_pds_fops = { + .open = simple_open, + .write = wfx_send_pds_write, +}; + +struct dbgfs_hif_msg { + struct wfx_dev *wdev; + struct completion complete; + u8 reply[1024]; + int ret; +}; + +static ssize_t wfx_send_hif_msg_write(struct file *file, const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct dbgfs_hif_msg *context = file->private_data; + struct wfx_dev *wdev = context->wdev; + struct wfx_hif_msg *request; + + if (completion_done(&context->complete)) { + dev_dbg(wdev->dev, "read previous result before start a new one\n"); + return -EBUSY; + } + if (count < sizeof(struct wfx_hif_msg)) + return -EINVAL; + + /* wfx_cmd_send() checks that reply buffer is wide enough, but does not return precise + * length read. User have to know how many bytes should be read. Filling reply buffer with a + * memory pattern may help user. + */ + memset(context->reply, 0xFF, sizeof(context->reply)); + request = memdup_user(user_buf, count); + if (IS_ERR(request)) + return PTR_ERR(request); + if (le16_to_cpu(request->len) != count) { + kfree(request); + return -EINVAL; + } + context->ret = wfx_cmd_send(wdev, request, context->reply, sizeof(context->reply), false); + + kfree(request); + complete(&context->complete); + return count; +} + +static ssize_t wfx_send_hif_msg_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct dbgfs_hif_msg *context = file->private_data; + int ret; + + if (count > sizeof(context->reply)) + return -EINVAL; + ret = wait_for_completion_interruptible(&context->complete); + if (ret) + return ret; + if (context->ret < 0) + return context->ret; + /* Be careful, write() is waiting for a full message while read() only returns a payload */ + if (copy_to_user(user_buf, context->reply, count)) + return -EFAULT; + + return count; +} + +static int wfx_send_hif_msg_open(struct inode *inode, struct file *file) +{ + struct dbgfs_hif_msg *context = kzalloc(sizeof(*context), GFP_KERNEL); + + if (!context) + return -ENOMEM; + context->wdev = inode->i_private; + init_completion(&context->complete); + file->private_data = context; + return 0; +} + +static int wfx_send_hif_msg_release(struct inode *inode, struct file *file) +{ + struct dbgfs_hif_msg *context = file->private_data; + + kfree(context); + return 0; +} + +static const struct file_operations wfx_send_hif_msg_fops = { + .open = wfx_send_hif_msg_open, + .release = wfx_send_hif_msg_release, + .write = wfx_send_hif_msg_write, + .read = wfx_send_hif_msg_read, +}; + +int wfx_debug_init(struct wfx_dev *wdev) +{ + struct dentry *d; + + d = debugfs_create_dir("wfx", wdev->hw->wiphy->debugfsdir); + debugfs_create_file("counters", 0444, d, wdev, &wfx_counters_fops); + debugfs_create_file("rx_stats", 0444, d, wdev, &wfx_rx_stats_fops); + debugfs_create_file("tx_power_loop", 0444, d, wdev, &wfx_tx_power_loop_fops); + debugfs_create_file("send_pds", 0200, d, wdev, &wfx_send_pds_fops); + debugfs_create_file("send_hif_msg", 0600, d, wdev, &wfx_send_hif_msg_fops); + + return 0; +} diff --git a/drivers/net/wireless/silabs/wfx/debug.h b/drivers/net/wireless/silabs/wfx/debug.h new file mode 100644 index 000000000000..3840575e5e28 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/debug.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Debugfs interface. + * + * Copyright (c) 2017-2019, Silicon Laboratories, Inc. + * Copyright (c) 2011, ST-Ericsson + */ +#ifndef WFX_DEBUG_H +#define WFX_DEBUG_H + +struct wfx_dev; + +int wfx_debug_init(struct wfx_dev *wdev); + +const char *wfx_get_hif_name(unsigned long id); +const char *wfx_get_mib_name(unsigned long id); +const char *wfx_get_reg_name(unsigned long id); + +#endif