From patchwork Tue Oct 5 13:53:57 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: 12536807 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 143B8C433EF for ; Tue, 5 Oct 2021 13:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EED72610EA for ; Tue, 5 Oct 2021 13:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236236AbhJEN7E (ORCPT ); Tue, 5 Oct 2021 09:59:04 -0400 Received: from mail-co1nam11on2041.outbound.protection.outlook.com ([40.107.220.41]:59136 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236188AbhJEN56 (ORCPT ); Tue, 5 Oct 2021 09:57:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mZdfIyRhdCJEg+53PnmUIhE/6jia4PAJqj7ynfepdnvLlJ4Dl1yk5KcWT9it6leqUv5rFZznE2Nx4eaOOFRwjB6xnGiUmXw12+nyb1wNMOgk6YpdsAT1mjwvnneowObslXfO6cgMHpWAY3AeG9XivKa/e+/RkuWrFGu6KHzsNsQpSNi30wXtYMskkiINbbJqA+hu2oMot6eozUQzyF9ZWvrAlZuKWwNj+gdH0O1WJq/EqoT9AVPydaeFwalzxwUrNFaa5sFUoDVK8cIls4bH9eF7LbOytB9+HlMjMO9iOq84sQQo/BEXzzo5yg+fGYzg+dNywRhCYBKyZtg6sgZ8Ig== 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=E278tkYB81u38EUwqGEDgq28Gn2rJRzCfkaK8J/UlNo=; b=OUmi9Av+jZ0/SymxcvreWuMP8A+3O4fLmIAmjbzju9PUkzsrWxE5XaKeVMZAqpiWpTsKr+VjjF/JT7hsjj5Lvs/F8QbXPqBdIBIDx6QqTYI5uFErgZZMlZoHp2l4qqSS1fiRC5w47h/zaUJZ6ndXtgnLtCbu6RCuyI5ttdjl8K0caWbbaQQrEo9vSllh9I9GZ7Xp4oKjq4tLcFhOnYXfhws6Su0olo4zgkvm82WPNvpJeStWSo+U0p38m/nRICKmC2FdjVz6N73dc9BP2lEvvtZTT4T3Mr/9Xo6PFvoahDzF41Hf8/KE7B5X48oiSpg3rq8ONKDEAb6feJ7FkTolLw== 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=E278tkYB81u38EUwqGEDgq28Gn2rJRzCfkaK8J/UlNo=; b=a7gcfaoKI12nOUT4V+VYpt1wPD2mVIy3XHKUKzS3qHCLCNCrmBVp/cuxWcL0spv103cBILG4PdEimyddE6AZQWRMHQF2JR15Wokm83Zr+X11UX9XC2GVk8ofWPjB6auUHTEa86f9tHBqwqu+d95I6Ll37Mf4+C/7W1hHw1pVHfg= 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 PH0PR11MB5642.namprd11.prod.outlook.com (2603:10b6:510:e5::13) 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:22 +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:22 +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 21/24] wfx: add debug.c/debug.h Date: Tue, 5 Oct 2021 15:53:57 +0200 Message-Id: <20211005135400.788058-22-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:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b040a1b-1409-4601-ab02-08d98807c64e X-MS-TrafficTypeDiagnostic: PH0PR11MB5642: X-MS-Exchange-Transport-Forked: True 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: 2oaJqxp0LNBmoF1XL8oNs9GUskc94MaerG8SA9YxBdjPeaHY8OKPtJARHYnd0LB8Egq+J+BYczD0Z2ajkGrxXb/uooYsy2EpUmlkwv4ftxcEeaxvi3KYmGZjgP2raOzqWvZxuaw7Vqw3ovtZJsfQapcmo4GFxLt78k05mM7OCUlLqzMApv5Si5TyaEMfZ1zr9jm7dW+Gv9jTVZHLtRwZBCZheP9xw5uBY5phll8GJFeOYYv6tDKECtYT/PMHfTL0ox9vHyt1ptzdzxDRyUFrqc4D8cKc6tYZetp+YeJ+5c+xCgyzsAEsmx6vJGeHB0CKiyxtV68SJauBQ/PufCAMalFDyeH2ApidrwTCQCLwVWwxAa5lMw3G4dFtQF3lt+2OJtNLJzGa25s2g9Pq+gO1yDkyIfgcBCMMtOrHgfxK1VYJwGMEfxOXc5QgTnKRsDHvl5dBA3dFVVAkmhFnS2Y5zqAMMyA+tNP/WmAmuZn5VWchfErYyiGMlEtNI1BouGViUcK/gCEXDZFSDCPTXmo51KzusfQgo7Mv5tWUHrPD8J3ai5E1weoch2jdaoi0VmvnEVFj0Yt7AMc5UN5XikmTpkB7AhvcdV+WeUsDVGLSpCwBXyenj5n52F+PRpO8QTPiz/0H4x+00eVdEq2NLHp1ATE8PhJdCA33ui4ITfcFfDAQRSY2Iq4CQW//QMCzxw4hcZ0XiV//teKafSh1vs+yuA== 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)(86362001)(5660300002)(26005)(30864003)(52116002)(7696005)(956004)(8676002)(2616005)(38100700002)(8936002)(38350700002)(4326008)(6666004)(186003)(7416002)(6916009)(66574015)(107886003)(83380400001)(36756003)(66476007)(66556008)(508600001)(2906002)(316002)(6486002)(1076003)(66946007)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?dJBsqXyAZQy7w6mU3EKh9KQN689Z?= =?utf-8?q?YEY5Zzz4k8YoQI+bnWQOUyXJOCX0e89f+fi7xGHuLJYk/DuQSoZALxJ/flIL0Cx0o?= =?utf-8?q?HTPuYfEEZFG4dYAi09PVYMulU7hbKm+Hfi0PbqL0HtCv3CJfVELx955RCiPHCJSum?= =?utf-8?q?00YN4ThhqBbftVVMP3Z/komU1Ru42K+K/MXzkRQdq1ZrikkxJQ3pkhJB9+3to7Pmg?= =?utf-8?q?VMo7nFyIpDEkDoJpzaK1k9c8DygVUC86f+QitQai8UDKbNUd6in+MlSXfEEhYQwjk?= =?utf-8?q?vwdi4WWcESf3+uS8EeKDUAAuaUgnnlO69Mm+2JGSdjFpoOBuZRaXG5Y+I/oWREHUM?= =?utf-8?q?bWOAH7C3HifxpuUH1sFNgeMR8FYRF4P5CTaWNSmgHeHMqOqMwDW2yz0n6UDaHje5i?= =?utf-8?q?j1/ID26+f52uVsS8AMAsmC+xOeltOk4BqiELbqalfs8kq3FWM7cGSQAFhMY0NbeyU?= =?utf-8?q?GIU3G3wa9LmViOXVOBoOt/Yx0jXyZIPsJTo0uxDpn781z/JA6CUx9Tz7QcM6osBWY?= =?utf-8?q?r6t4IyADjoHveBdFYt4q7PptRjflIVCn9MNzFAtvpjQ9C1bUmNON6FMG5XgVwzpm7?= =?utf-8?q?171CzBCJsOsW9QypzVVB5EEaLUXHfLlksP6vE109MrYX2JNDX/n+TZFP4rXZclkvR?= =?utf-8?q?vpCHt5nfYaO26pYFSQMnp9Z8f1e/+Z+h61shF9YCVtuLxa2C52QB+HDihjDPZIjHG?= =?utf-8?q?axwfKV+AY5i25POYJCVh/i4wPirsy1FzhCDaboMFOZWVAj/2xlA41KJgt5sINLNkn?= =?utf-8?q?fmpzxxcUpkxZ4H2dxN9ecj9blqb6f9mze5BXwtIBRZifSBBoTrtz7UGTsimRp35WH?= =?utf-8?q?KzQi82S/+x5EnghfaPu02Ba6mO+aEz++VnAEJ8Om5qD6NQJcbZS/EO4npyeI0vuzy?= =?utf-8?q?A2aDyh8B9JQVklik0TX+F75RUy43iIU4gWLhPWcnpdhTbmVoLfoWsVFHfqn11M0ZR?= =?utf-8?q?UhUpgjxhvrO3A2ndsRrWKjj0LbVr5F1q+ON2M+p37/M2itxVWSLrOerir/TrpPjIN?= =?utf-8?q?tbnlrwrojR/e5u3o97VuC4bFZ1iUOMVXZR6oap4MUBt8NEYeVyBBZ0nsZTjzHTd/m?= =?utf-8?q?/qp1mYHYQpqRa98bCID0YmjIfHj/5VPELTrbsmVCmpjCOVK9U+veltAJAD480fPdf?= =?utf-8?q?lyvLkR4rgbxmWwfWQIu7ydBGDKvY4Kpyf1QHLv58nnsGHoT0RVeqGIZaKq1xTWeYq?= =?utf-8?q?v1907ccrDicg16SGB1Sflfs/8MdeFn02QpN8Tf1vX29Uk/vGqYUbqJeJawpcjcKQ4?= =?utf-8?q?X41+R3OHVTbJf/Od?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b040a1b-1409-4601-ab02-08d98807c64e 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:22.5457 (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: XfB0hY7qiqXwifhzEClewLfl+M5ktl2HGrpxXDI6qdelNveJk09xiDIyGdr0aB41wc8sRJa/fJ1nw4o2tQw4xQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5642 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 | 342 ++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/debug.h | 19 ++ 2 files changed, 361 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..a4bc7e566c23 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/debug.c @@ -0,0 +1,342 @@ +// 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