From patchwork Mon Mar 15 13:24:58 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: 400952 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 B6947C4361A for ; Mon, 15 Mar 2021 13:27:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 957D364F04 for ; Mon, 15 Mar 2021 13:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231542AbhCON11 (ORCPT ); Mon, 15 Mar 2021 09:27:27 -0400 Received: from mail-co1nam11on2080.outbound.protection.outlook.com ([40.107.220.80]:9473 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231232AbhCON01 (ORCPT ); Mon, 15 Mar 2021 09:26:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mtkiLR+bRuuYj2Ud7G2naT3JD/e40PjDdfIAVyWMQH0tYZY+R2QfpY3WKTdb65EXwUh2V8M7itjsvMfvMQmhCaPfjEMTRi2ytEX9wGCblCgi4JTbpf4Sold2maIxLVVfrqcep9DSiJ0tfaK7NDWK7bYtTs6YHOANyNw16h7+FqQTQLK8Wjw2pIU1kP+1Gpsbm0RLU79Nmj5o2wKm0rtG6Db+SQ2uDh9SMwtZj4NkdeUKbKPxkpLyMscHnZP3/5y9oJsiBm1DQ5lhsxa++iPEybrp36hZ8N+0V3O4sC0tJqZlCdvUP03eJ4oHikK6xzi+v6h8+egra3BQPv/Sgx79sA== 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=SnMF94P1x7EH+JxB3vUGGXW3d2/0oE6/46mwevOlULM=; b=RHOKYf9+rQxVVFL+WxAcIR3V/Lr3ITb464cx374PgmMFaJ4paVBhnklPJDsn8F83a85fgmCVJlFwTbtorx3eKGLWccPV8dwV486yLV0PHyfEH0mWAStW9YoeGv6hxSzJfpXI+bHPgwotD5by8fxi7pGGq8zzQlTmfVeVrIHySRNGJ7yDDQX/aotQhnDOm4aCqjGq6RSkRvzlwQpVgOT8vExvchkXXa74yr1b+GFnNoYW6WTNx8K4id18LL85vOCIoRmKaWM/pA4AwfHwhCTFX6XMde7/MLec5WcvjMrkzLgQRw06pTysENQQI4Fu2orZRNUs6xctMFgWQ31XEzqhOg== 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=SnMF94P1x7EH+JxB3vUGGXW3d2/0oE6/46mwevOlULM=; b=ZE/VRh4hhqflX7uX84fD6pP/F9mGFHj9WWnedpQIy5+6BoTh3jwy1tDLGSPl1YVyJL1QHmQ7ztXBhQ/ElV0x2R4BaaEO9YPQ0kxcPwcBWHLgnoRHs9Y3s/L7qNSV7oecC2wP5aFbNB0UjuzjBjV6tzJCjPURHAqDfCE1DoxoFdM= 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 SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) by SN6PR11MB3216.namprd11.prod.outlook.com (2603:10b6:805:c1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Mon, 15 Mar 2021 13:26:21 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::41bc:5ce:dfa0:9701]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::41bc:5ce:dfa0:9701%7]) with mapi id 15.20.3933.032; Mon, 15 Mar 2021 13:26:20 +0000 From: Jerome Pouiller To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , devicetree@vger.kernel.org, Rob Herring , linux-mmc@vger.kernel.org, =?utf-8?q?Pali_Roh=C3=A1r?= , Ulf Hansson , =?utf-8?b?SsOpcsO0bWUg?= =?utf-8?q?Pouiller?= Subject: [PATCH v5 21/24] wfx: add debug.c/debug.h Date: Mon, 15 Mar 2021 14:24:58 +0100 Message-Id: <20210315132501.441681-22-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315132501.441681-1-Jerome.Pouiller@silabs.com> References: <20210315132501.441681-1-Jerome.Pouiller@silabs.com> X-Originating-IP: [2a01:e35:2435:66a0:544b:f17b:7ae8:fb7] X-ClientProxiedBy: SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pc-42.silabs.com (2a01:e35:2435:66a0:544b:f17b:7ae8:fb7) by SN4PR0801CA0014.namprd08.prod.outlook.com (2603:10b6:803:29::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32 via Frontend Transport; Mon, 15 Mar 2021 13:26:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc043929-7d13-427e-f452-08d8e7b5ebb6 X-MS-TrafficTypeDiagnostic: SN6PR11MB3216: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:989; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0vYzfwUb0N1VcZW5C2z0PRwnShMaWYtF6KeB6y9aXLbtoy3rhtBRGbKTJ0RbowHM3QpSc9RjtNplfJmRQuInC0yrYTc9D0eCS0QKC6YQo6WVme5B3UZGQJEMrtPWT8k8RvFoHLXlxTtRJL6LHYzwYpzeyXmkQJMkO+xkzTBmtiY80T++dkkC2IC9Ga19Z9EA7MCU6IEtlz2i09xKHPKSjXAGji9+YYKOKeCJE5RpqaUwF56GeEQnHaXWWqXK4fJOu5ev65oCPBPhRkCvbGIlP+WFNyG1W90MDEKm+PaSthXAyGSilMy/uRMnxVJaq3KyCF/yGwQr1I1pC9+qM4NCblwqESkVDCifU9PJjVsbkznPwCFbQVPV/tagJtWbeY2B3nNn47rCHdhDtOoPF06putuPuk1N2hCD0CHQsIr7cqs7BNZN3XSB0hTI1MRJbH3Qc+h47vOot6gDMoUjLYGr8QpET6RCxs6143aKFHq5MHSkPHl/3161Vp/5B88R2EpZJMSPlVEniY2FgDz0xzVj4wppIfvn2ERKIFj9fjXmAR7aC486zy3I+mydKgySwbcn X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR11MB2718.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(346002)(396003)(366004)(39850400004)(136003)(86362001)(107886003)(2616005)(186003)(1076003)(4326008)(316002)(30864003)(66556008)(478600001)(8676002)(66476007)(6486002)(7696005)(5660300002)(66946007)(2906002)(54906003)(83380400001)(6666004)(8936002)(36756003)(52116002)(7416002)(66574015)(16526019); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?5DirxddYw3gK4gEco1GUW83eEYd?= =?utf-8?q?rtVmVAiHtasCM6VX7vpMnfQKl/K2hGtpfUrWEtBGVMowsrhC+YZen3LK?= =?utf-8?q?ei4ZSMgc2VtoKS/RaARHkOH1jO4LjIWGLdZGpyk/H86YLiK3ZCM9l21O?= =?utf-8?q?lLG2pdcflwUM9EFjHmyQNAkStE7jK5omKVezw2Co50HpPWM43nh8/O8/?= =?utf-8?q?cn8asr1eV6j2KT9YowV62QEkAvmJDP6mlku2OKzGl9kYws9iYmmE7dx6?= =?utf-8?q?9huFaeHICu+1q8HlvaO4TZi/PGHwYmWisOrb3UzOtnKpBY0Z6snPnHwl?= =?utf-8?q?TWqCL0xM7xdUpgNkQ8iZaFZU/2ll6OOBLRDkIyA2DLw3W52ZPSKc09yG?= =?utf-8?q?TTSY8KBCv2qjV0SuUbSjEZB4+aY6UnJ6A5fvWdMXKHSlFTpWk9cJSc03?= =?utf-8?q?HGXk78kXl9NIIbF9MajHaBNSwnNsyZniMTFRmx440BZG3Wja/JH4sHAm?= =?utf-8?q?TXsGqP2eWtnCSOkG+rhq66wBadYp5waTvmLFrLb/Knbu1b13NvXVk0Yp?= =?utf-8?q?uHci0ETTzPiDHBlORBcLTDicZJQKNcJz8+rcitDbDW3+QESD72XH0VGC?= =?utf-8?q?puFfaCVFEY+dZ0w9zT+QHNd3KNQ9VJNKB03qSztRTvx9/incwQzinJxi?= =?utf-8?q?M5rfDJRz/dNqJdGTAzSuUECSIc4kGLhrap8W+hy9OOlSHpsSPbBNRnVL?= =?utf-8?q?vyObXysNn0jvX8HWIhtW8cFchj34FOfBIK50yQOabMKjKSmyj29OyJxO?= =?utf-8?q?jkZp/h6E04mDwx/lfFneyK2tHQi/eQWrOfaKYIndVlcPEIQ/FWwrb79t?= =?utf-8?q?V6MgCkwh8M5uMsrASeTyxnmj3fwHYwtWtKQU/Vu1N+EjyD5ML8swfyP8?= =?utf-8?q?mFugBTHikMp3qAnlVQYGmpjyyJNIEX52v57y2l+ib2w9up80LvqyeDox?= =?utf-8?q?hBjRf1+Uw38rqCKH7ojgKvdZh0GSHlpePCC1Auy5xrMmLFRIoiAamoHx?= =?utf-8?q?sWYz5Dlyj633Lw5y5XvPzwyZHf3ScUNsM7BJ8lqsSDlgadWzOYnOgI2x?= =?utf-8?q?i0bVbc8Pl6pTcyu4AqM62X/ldTqqkLmIzyVK/ztMQoC7gZoYA6twuB69?= =?utf-8?q?Z0QsrUpRL+r6zpX1Qi8N/P9pw52u/I3nb4rBlanwTYuwO4GOLCgjl2oO?= =?utf-8?q?o4NSztAgf6iRr3IFlrkE+hv1DsifIzboGnV+WS+busjPoD//LbmOwcVG?= =?utf-8?q?NEPgOoEmkThsoFYMOeNW3mxM7yj6Jn64SGVLGrd0bhh8vO3TuHMjBU4s?= =?utf-8?q?opwK3Tnkgilh6IEh23IyDdJkdaHjXd1TjWyPSMc9sPl8WL8DELrBXLsY?= =?utf-8?q?MDSahDnDx0a9O2aLGRSeKJvhk3+qYkG62fvO4nsUEohmsUZro7RsgjXN?= =?utf-8?q?e81W5LlKiKpyptrUj2/XEpf5hTJjue6fvBroO?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc043929-7d13-427e-f452-08d8e7b5ebb6 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2021 13:26:20.5116 (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: xgvw+dXGepfs4JHL0d25VS3mdGgOQ7BocePFX6yWIi1mxSqNC4juqu181V+4cX4krutEyX/NgtZJK3Xnbd6H6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3216 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 | 361 ++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/debug.h | 19 ++ 2 files changed, 380 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..3f7101213df3 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/debug.c @@ -0,0 +1,361 @@ +// 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 *get_hif_name(unsigned long id) +{ + return get_symbol(id, hif_msg_print_map); +} + +const char *get_mib_name(unsigned long id) +{ + return get_symbol(id, hif_mib_print_map); +} + +const char *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 hif_mib_extended_count_table counters[3]; + + for (i = 0; i < ARRAY_SIZE(counters); i++) { + ret = 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_packets); + PUT_COUNTER(tx_multicast_frames); + PUT_COUNTER(tx_frames_success); + PUT_COUNTER(tx_frame_failures); + PUT_COUNTER(tx_frames_retried); + PUT_COUNTER(tx_frames_multi_retried); + + PUT_COUNTER(rts_success); + PUT_COUNTER(rts_failures); + PUT_COUNTER(ack_failures); + + PUT_COUNTER(rx_packets); + PUT_COUNTER(rx_frames_success); + PUT_COUNTER(rx_packet_errors); + PUT_COUNTER(plcp_errors); + PUT_COUNTER(fcs_errors); + PUT_COUNTER(rx_decryption_failures); + PUT_COUNTER(rx_mic_failures); + PUT_COUNTER(rx_no_key_failures); + PUT_COUNTER(rx_frame_duplicates); + PUT_COUNTER(rx_multicast_frames); + PUT_COUNTER(rx_cmacicv_errors); + PUT_COUNTER(rx_cmac_replays); + PUT_COUNTER(rx_mgmt_ccmp_replays); + + PUT_COUNTER(rx_beacon); + PUT_COUNTER(miss_beacon); + +#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 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 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 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 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, +}; + +static int wfx_ps_timeout_set(void *data, u64 val) +{ + struct wfx_dev *wdev = (struct wfx_dev *)data; + struct wfx_vif *wvif; + + wdev->force_ps_timeout = val; + wvif = NULL; + while ((wvif = wvif_iterate(wdev, wvif)) != NULL) + wfx_update_pm(wvif); + return 0; +} + +static int wfx_ps_timeout_get(void *data, u64 *val) +{ + struct wfx_dev *wdev = (struct wfx_dev *)data; + + *val = wdev->force_ps_timeout; + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(wfx_ps_timeout_fops, wfx_ps_timeout_get, wfx_ps_timeout_set, "%lld\n"); + +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); + debugfs_create_file("ps_timeout", 0600, d, wdev, &wfx_ps_timeout_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..4b9c49a9fffb --- /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 *get_hif_name(unsigned long id); +const char *get_mib_name(unsigned long id); +const char *get_reg_name(unsigned long id); + +#endif