From patchwork Fri Sep 17 15:13: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: 12502497 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 X-Spam-Level: X-Spam-Status: No, score=-16.7 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,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 48DDBC433FE for ; Fri, 17 Sep 2021 15:15:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3325161244 for ; Fri, 17 Sep 2021 15:15:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344045AbhIQPRJ (ORCPT ); Fri, 17 Sep 2021 11:17:09 -0400 Received: from mail-dm6nam10on2053.outbound.protection.outlook.com ([40.107.93.53]:28225 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244665AbhIQPQg (ORCPT ); Fri, 17 Sep 2021 11:16:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EhQYOUWEeiudWC74ZcHq3zvZ3APxCUKv/RerpZIvfCKjxnpYTykmZdm0k6kbQKXqP59c7u3Ji5ANTP/lx92JADHZ8BPqbmAmG+AG08ulFGENvzObVvoMV2tLIcWqr+UgOeqiVGI84e+d4il8m/SkKU2dc3QP6JQAe/hEJOW73XUUaDfBrVaMRcuhGT1oq8u25MNDoegfLDtUEwTpkoL7WA6TqsHcAJ9NnqkQimfGIDS/ySdXaC0KQoMwL8eHphW35HhK1DMomlE2GhdJDmD8C+QViw3I+nEVArssAGyATIYc89Z/0A7X2kdl5Fl4nMl0BOoe5N60dSVXMzVzBZXm+w== 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; bh=fZ2JaKzYlrdGaX+6E4MBhFuNexc43HZ2kCx0dbW2tZY=; b=TxmQ56zzcd0uljkMEwEJSz0j9fZ6F48SZf/CZrC8YbqCrlxbZu4VsHhHqbg9hLWF/yF1+EeLE4QJkz9Zp/hRRaZYIQROPcQZjBfoppnlJDB9gZaONftrkhJ/O/1KchqUkshGII48vX7H2qgY8CHbDvtWjD2o75kgdYkGIQL1VowxsIutkC7n0gtoFNfCIiqtdp9fKJeP1Mdsljc1HLULoYRjmM5ROuz4X5XDGzaPFnqqqxDRWnRyH3FU5zRtZLpesAYnDcnPw+Px2K/WM5Qi7htxWf1jAH+uSCFecTlngfuel4UvVkuYK1s5AJvyxyzUfomu3L3pxEG6Rut/PPv/Lg== 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=fZ2JaKzYlrdGaX+6E4MBhFuNexc43HZ2kCx0dbW2tZY=; b=M56BWzcczpAGedrtmj8csBw1YOfakAbzR9AqXCvDcVTzmRCDuVb+A6eWpsir0JetHj4VONv6aPShUk78C8+U+Okkp+F6cGWEXgBhWgO6476Wzk3XTu/kX/Rg5269XBxRtgLp2rVJ0lJ5gUtdFVRIK92J4M3JudmSG+TUtQ7OGUc= 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 SN6PR11MB3360.namprd11.prod.outlook.com (2603:10b6:805:c8::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Fri, 17 Sep 2021 15:15:12 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::7050:a0a:415:2ccd%7]) with mapi id 15.20.4500.017; Fri, 17 Sep 2021 15:15:12 +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 v6 21/24] wfx: add debug.c/debug.h Date: Fri, 17 Sep 2021 17:13:57 +0200 Message-Id: <20210917151401.2274772-22-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210917151401.2274772-1-Jerome.Pouiller@silabs.com> References: <20210917151401.2274772-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SA9PR03CA0029.namprd03.prod.outlook.com (2603:10b6:806:20::34) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 Received: from pc-42.silabs.com (2a01:e34:ecb5:66a0:9876:e1d7:65be:d294) by SA9PR03CA0029.namprd03.prod.outlook.com (2603:10b6:806:20::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 15:15:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8c81efe7-0e41-4881-dec1-08d979edf1cf X-MS-TrafficTypeDiagnostic: SN6PR11MB3360: 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: JpttOG38sdhpFVpITCutIb6/8/h5tMHqNsSY/mcKlraa7cb2qUiNRQE+1TUOkX4uci6+4e1GA7u7GBC5r31WFQ0+DrU7ySwGyGGeXZIfn4zesv9KWmGueBpVVIf9DGib2jR/k9/rNGdSjWA0rSMGQdtwrBUo9BzM1AU+JNMAJI76iuaAzFnX8N2h8lJkNOaSrpWhTFmE5Cp/qwU7PBNcU2wqv05OQdRBINMAsqbejjoFyLFIbGImZbckuAv+MQlwQdoBspb2LNObuJctahDnyV7EH+ZWsIuUQQH3StkZLPyzsLwho8HHqBKtxvZ9y6lZb7P3ToaocuuGn7xeYZAHbGrLEPDMqEN4uRYpWJMQvXnKd9bbShC89e65MSr5M2c4yBNx1nTp5uCiiXzW6R89S4Jh7VuHKrt284yEELmr7YN/XQxanEoMdMZoqMmHa2PXlWJfquuL8jiTRPP2e17OiU6uG8NzBfEXLrz+uyP2dzZEGVguifV5T8yoINv0t29MUkPjwVhKVMjKaaks8KuAaCtuHRej9BSUPoVQpN/IRIsjTf8I5ATOXCsbnwDmnt84nzs/FO9djd2OOVpvmnfonXnLRTSbvJsFfRGfi5HtLL4tIxTVLnZd2gw7Y7TUj5/XwoPG+N34FRScfGgf0jcU4g== 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:(366004)(39850400004)(376002)(346002)(396003)(136003)(8936002)(5660300002)(36756003)(7696005)(86362001)(83380400001)(52116002)(54906003)(66476007)(107886003)(66556008)(30864003)(8676002)(66946007)(316002)(2616005)(7416002)(6916009)(4326008)(38100700002)(66574015)(6666004)(186003)(478600001)(6486002)(2906002)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?aoeSg9M4UYEijep9ASxD00aBebXT?= =?utf-8?q?8yD72Cn7q+QrEfKvbA6CFsHdSxWrX2ndTJ/OejvMEjwt14lIxCzPA0onNPuEg7oXX?= =?utf-8?q?DW6w6pnl64CREbs2Ig7UDG3AMlHdphkIalj3BwJcwfHwap7+l+rAeyV9i62beRU9R?= =?utf-8?q?whHONqLvqqvYnXHlGBW1JZo8O+J4o+h5xdFq/tnhzxDpFr+OL7nda7W1ezt1GtqQ8?= =?utf-8?q?np/GMEFQwA18dwRlFKmhjeIaCWq/o2RKMbX9f+cq4A1JI/cvO733NOoUtCdV8Qdtm?= =?utf-8?q?XPC8kmRfXkcTnOyoYD24pCOaqoxng1mAaltRbl6Fr915oU10Hq00l7AKzxOwh6QKJ?= =?utf-8?q?F4hUlRxE1QANfsEtKiFgwacCBjYzRAJPdLJkAnUzM0wM/ClWjklAcOB3ACkhdKWXu?= =?utf-8?q?GT8d6pxJilIUG/PaU1wWAvdwTFKDR15iZe8IK4WwnpeqtL3M1o52m6gbHHqLb8Edi?= =?utf-8?q?OXbb+SFWWAqJ0G9+UNJWT73ZBPkUIzr6od/9BDZ+PGr0s6l+kN1tsPbJJMyBX/icF?= =?utf-8?q?nrspRO63e+1SdsVk1XSd7PnHKvoPLqHTr3xfhNMyzUIOZxPh4ibVK+YuXHiaRiXYP?= =?utf-8?q?MTwiA/0udXj8+ExORQp1l53zmHxoiGcRP/5aPqWIKqNwTVJX/z/yOR4BCKQHK7/g+?= =?utf-8?q?lDmEbNyAJhjfEx885SuieenfwZWFeXpRoCyAKxxfC3eDaa9GcBmFSpnRMkVL1GfAY?= =?utf-8?q?yrEg98wQnPYuHVrBBYVJpDmnks9i0k6MJps4LckUgZjNsUTjWb9VHkWu9Pkwh8qEd?= =?utf-8?q?WCc3ZrRG0CvPhQLxkfNYgNjDfBdz8/bZiyb5bU3SXLk/v3kcy3e9Mzmb8MUC+sddt?= =?utf-8?q?PfGE3BVM5kQiI7IhqCkrfU/X3yGY6Q0xNLzeiODGc4cF7qyc9dv1VohoIwFsC3zvm?= =?utf-8?q?uad/tEF63Es/UhqfXQutvQIZbEVo/2dbbtUDthteSx/rz5zO4JDh648YrJ3dPlwIl?= =?utf-8?q?GsOc0uWpRv4/qN6/Db4V1jXMX8vPLMcenbl0RivsVWPGLYSzYFAnNky/TUhweWuuW?= =?utf-8?q?LrMKOCUaTXi3jmLMPpv4zStplGfcGYiYdoAuRpGL0lkWpb1e1TU/snEVXzr6+RLOQ?= =?utf-8?q?E0VqHjs6yasjOw8A8Sr04pqLJsY5KpzStrOcC6IL2IRxGzzqHiqoTKAKWxupkNGQH?= =?utf-8?q?7T1ZtxpG/VUIoxWXQyLMsctclXL6HsiPElhfkSjsj9Jjm2Po0CmNzSHpJwpDotpuM?= =?utf-8?q?mep4SaDiDZ6i+yBkmgPXRkvBnmwvHEQGp8FFGasJWfmRpqFSTdS4clmWQofJP1SCk?= =?utf-8?q?36dXJaCNeK4PFLT9YHO8mtcaOVJB8e9JZBrT8yqbL7uLSo4naaNqNV5jM4wVHBM6G?= =?utf-8?q?9lRqVG5DGj+Qv86?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c81efe7-0e41-4881-dec1-08d979edf1cf X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 15:15:12.3006 (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: tQdg/Z4lxVdyNnA3b8QuQqL8HTglT+VD2ZUhLn0RLjQ72H6qxWgfPG3WKY5e72q8Ch17fxu/jDkZnSD3uFew3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3360 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 | 365 ++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/debug.h | 19 ++ 2 files changed, 384 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..9f93268a3202 --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/debug.c @@ -0,0 +1,365 @@ +// 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_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 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