From nobody Mon Oct 6 15:09:56 2025 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010048.outbound.protection.outlook.com [52.101.69.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9998F285CA8; Mon, 21 Jul 2025 06:31:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753079520; cv=fail; b=HBQqRfGArUiYu7UlBEPjsH8ZmYveJ9FZkJekEuSEVL8dP9pY68CPkc+2JSWktETIn7Vlbd0DOX99aqer336/D9tevhvtcwAQ2CveH6Z9FsBnlxWOAC0Gtfr/+eEs4WjwOeabYzC0a9KeJiqLAHyGF6McfvE8b9pde1Zwb7Jx5+Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753079520; c=relaxed/simple; bh=/IBL8kmGcInVioabeGIS/UfCQL9DEurAeVKUOK24lrY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=PMJhIGiDr/WeFattTZtQXXGXnLquVm8Teobn6MNjEkxzM0cCtS3HZh2uJ01hchiB+YDVn1ycdMKtyaT/skMua2ixQemW+4e3ce/S2OyiqteJX++Lrrg/+SD3t4LMP2bnF0OfR1+spwP7WQ4kuZYOahpw3U9rDdlb0iuQgNeeizs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Jc4pPUXu; arc=fail smtp.client-ip=52.101.69.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Jc4pPUXu" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b8wensNaUrJWuUFHPlVY5IsKdXTlGdKoAL40vV9tAy6U5d6bKCQ5plA3f0TA6fKGg/kdmZnbqOLVc6MOIGfjYCKSRSGcp9m5HFsWXnIy78dGbgYxUdsgDoFixEwYJjZL59PVX3HI2pNJUso543RlIS6bgvavJRHTXesTp3+Q6dc+ifnRp7Z0KKl1av0n/AN056EGabE74sUkJQSivMu6jrIAPtzLZ8efVGVgBbRu93qIXz9qUkWcW8AQN9unrUuZ3je4IqWxPgv8PX74XC7B+DP/AKcOuNPWJjNI100oV55Deme5QfBuVFzHzBeZ/DTL/tn0DklbLxJpcL+sb52ojg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=+SR2cgDuftJiC5tEjz+Fsa6B3U7F8W3LjPrqEdm0ZGo=; b=UvQ31tevq56iULyPuAuOCYMgU8QKqc2XPtZYSqa6OvtPR4AzmbsceoW+L0ihU0gBU31uwnasDA/dtNyYTU0HIFO0s2DBIqhdOGnEio6PotJNcqAjjb58eCjV70rT4DoxsMrtkZKQx8oAVLngiUhXMDBDLrLOCmE8WWGthSFb7XrNWjpzvGWMiIVWwym0d2A6F/QV30dBtX4/pOiuzcmiFdOF8f3L8HcagmBsrzHRkdTuDY5Me8Xprgejelyo5YhUJvQ+QO30ZI24iX2dP8jm4me6KUrQhSnnXOJbOlRt2TkJNo2LQGxRYDYaK0sZip/vq4L55zUJ2nA/h/JrTW9kpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+SR2cgDuftJiC5tEjz+Fsa6B3U7F8W3LjPrqEdm0ZGo=; b=Jc4pPUXuwFPeltQjMthuyR0cOCjT3bC+ws5nWycOaDZyrnJ7MGTXhe77nRkavqDpWonFHQ5smeYkNqy3e9ACJHaxFWAkJLOKhthqHR1ryrRR/vuHlukOO78DJPlQDPl6OsnpcVDyc+8h4HIgJJAKylohmBlaEDe+ey84i3TDJ85y00E03Q3/20an1Z0ljV0JsD8YcXFHQiX7Itk+oIE+lAk1HVQU2z3c4YlhRS49ixVZC3XcKwj2v1ZWPCtKEpL6WFgvXEsgfyXBzE9eQJc5uorEmz8WfhcSh040QghXvtkm1iWRGoB3hqHlnV5qtChJiaYcHSeLwktIjMixc7pPoA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DBBPR04MB7740.eurprd04.prod.outlook.com (2603:10a6:10:1ee::23) by AM8PR04MB7780.eurprd04.prod.outlook.com (2603:10a6:20b:24c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8943.30; Mon, 21 Jul 2025 06:31:51 +0000 Received: from DBBPR04MB7740.eurprd04.prod.outlook.com ([fe80::7a71:369b:fb82:59d7]) by DBBPR04MB7740.eurprd04.prod.outlook.com ([fe80::7a71:369b:fb82:59d7%5]) with mapi id 15.20.8943.029; Mon, 21 Jul 2025 06:31:51 +0000 From: Jeff Chen To: linux-wireless@vger.kernel.org, johannes@sipsolutions.net Cc: linux-kernel@vger.kernel.org, briannorris@chromium.org, francesco@dolcini.it, s.hauer@pengutronix.de, tsung-hsien.hsieh@nxp.com, jeff.chen_1@nxp.com, brian.hsu@nxp.com Subject: [PATCH v4 14/22] wifi: nxpwifi: add debugfs file Date: Mon, 21 Jul 2025 14:26:33 +0800 Message-Id: <20250721062641.2001796-15-jeff.chen_1@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250721062641.2001796-1-jeff.chen_1@nxp.com> References: <20250721062641.2001796-1-jeff.chen_1@nxp.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FR4P281CA0440.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c6::19) To DBBPR04MB7740.eurprd04.prod.outlook.com (2603:10a6:10:1ee::23) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DBBPR04MB7740:EE_|AM8PR04MB7780:EE_ X-MS-Office365-Filtering-Correlation-Id: d640fad2-207b-4068-247f-08ddc82046c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|366016|1800799024|19092799006|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9ttGvK+urzIrSLak7IzdQvBT3EmeFci9F/rEZFzId/hb3GcFw40srZ6cXzcJ?= =?us-ascii?Q?61wwbcjGD+1slByOqRkwiChKcMAWiEYKchtr+qEch2lTjWMq61AmaQYmkbTN?= =?us-ascii?Q?N2HHGcH6ewJIGd8j7QPG0cnakYbCycbL+aa9RvqVGFUZ8S84BuTUoLt3scRs?= =?us-ascii?Q?tGiup4dYbvvoTtgaHuLKFM0uN1hhh1t9VCDP0bFEQgMf6LLRnqROxENxLfps?= =?us-ascii?Q?8xrJfQAl4bHhdLmXQsnUG6Fo6wp77K2xdVXfWBx+kajs6uWJlbZ2BBi3SHHE?= =?us-ascii?Q?Msi5LmWf3GDSrAH5+ka9rESyMyZKYWcJsB+ZQ3+xwfCZXUXzM9t5LWYzJpk0?= =?us-ascii?Q?wu1n1rDdkpPUkAsZunKtGvOo46ZLF9bCLit51zum3ufo6jiTsTadN8EqX6zl?= =?us-ascii?Q?sOR7UgiYnwLx4KqA1dBYPI5UphSPRdGybxu2d19xuauLUAerZO1x6Jr3LZ++?= =?us-ascii?Q?5FVz12EYuuI38+N8Fo+tUcmBrK3xTv6EGcskHV3cqrj9lja0O50HGqprRWuF?= =?us-ascii?Q?w7EUSFLk0ohfCfU1REGZW7/fqabhqrFP2O3Qk0ANMuWceHOUVhr2VcxjJIgb?= =?us-ascii?Q?GJ0QxuN99Xu2h/b72yp2bNLfT74YcDd8+NLmgRFZaRaDPNyXItDCR+NyqskB?= =?us-ascii?Q?xDSa7Y7Tu1F+c5iuakcjFmwXN1IHNrLUicDGOfvUUTNuqQCGXXwho++1CfqW?= =?us-ascii?Q?KyyARBP0rdn8cN+UJN8oBZAF6+cmZbx99DMVx8K16fevEblTEUGO/6WBGsnL?= =?us-ascii?Q?Xw6K6ioNAjKSggAkxggYAHB5uMJBbERYWQVjRtcIREiUKGRWlVGBneDynRBd?= =?us-ascii?Q?Jc16D5XMjrkc6nUVpirLJ1C9ZW5CqmPgYN3zbK55SfaUZ6l5BvmJBL6z1NHR?= =?us-ascii?Q?kjRmsagSvXb/a3aTHl6w12m88jZM2YH/wm5pYofmRMUXBLYM9jL+EOt5d5Vl?= =?us-ascii?Q?FVcpbxx63GSI58jKB748SvyICTAdDQ/6L75+8w0DKpufHHe7G5DgLPJhq0zD?= =?us-ascii?Q?POWYaYtNyajCExxyj0uHySraZ483ADkdxONkW8u4j2uVmj55HbHBW4BtkA+6?= =?us-ascii?Q?ra9sOiFGl9w51fMid/ZJYt1STS1TTxiEAPw8V5tU2xmFjecBOXyV50YTTwqc?= =?us-ascii?Q?fmGqFwIHp/DGO3mjEIjODYX7v9VkF2I9MQhuXVIHGQnP61Gaulswal++U78G?= =?us-ascii?Q?GERNAVVE4xzAANbkq7RinHlI4grCN+e4o6+gBcvKPSrcmYA5xCes/SOLhvjn?= =?us-ascii?Q?IQCeKubASBXGxmvlV6HW/h2utR1xKN//d4Q+aXuT3YFbj7RBG3fHCkeE/jGy?= =?us-ascii?Q?gOxSJllReBbGSQjS8lrYswEDsW7hwvriROA6ckuHnBauTO23ReKoC1xvKns+?= =?us-ascii?Q?aWdA7E4SiVDjhhulYGw542fcRc9tywuNn2g8m/6PwhNZaiEaVA89OrCy4VuW?= =?us-ascii?Q?x6F7dPI0FFih7buCvGVKFlnJrfzZzll5EXB8oLcNWW9/NZquZiHjsA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DBBPR04MB7740.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(366016)(1800799024)(19092799006)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?WoS50HJGTJF3z8kpLC/Hc35EPX9pCBjlIisEU+t3SkBCoec0MIswF/+GcYfz?= =?us-ascii?Q?kcAITqV+RE5KI6epvQF8b5JXQu2cWNnq6kXlwLCfpllpFXL0fwKETV/xLSGZ?= =?us-ascii?Q?UwM23/XGw0u9/LH71H9bfZC+XCxxh15HwZ+FNF2R/4cfXe3wk3oYQsZXD4u6?= =?us-ascii?Q?OVkU/DocsjWjGeSCpd/c5v+Ma5Ndzo3vczXRQoJ6wUzbVb5F3oOLoRcG+UGF?= =?us-ascii?Q?F+sSoMg+X0RI28XYuWGEFROW5d64kerM/otd4THNSd6dqSvnSWSMqNQRaDDD?= =?us-ascii?Q?BlEiZGqUqw3MGotI52726Sgz9RkIcGax75+dpm8ZfMb9/ZCof4TDTkCEA7cZ?= =?us-ascii?Q?73LFMKfL7tYDdRiOgOYCfAUGQftSaRqI0dXZ36xurdikzO+m7wloitlOxZaC?= =?us-ascii?Q?/Dxtq6/9RMi2NpboPy4tWChYBurkXghdOO79iaGHqRF40qP9K6ThQraBEKF3?= =?us-ascii?Q?4AmRxeHXb3NrsXg5L/PqYH9L541PHO6cCy/cO5ef8GAoCKVy55x5SNGBwF8x?= =?us-ascii?Q?UFkWA42wgMryGtplgnnv/G3mvMlJJwVbF/yXTaR2sTJDk3/xz4NjoGOnLrzp?= =?us-ascii?Q?TispKsuJQJhWhvWbGu5gXayvP4Dkxc7CRxziFx+V1FTk7YUgc0w76ODIiv66?= =?us-ascii?Q?DYug90rhXxU81CTnZZBpWj7E3VMqCa0ibXNjd5MXoVZCGYvnJ4FNxlEVFkzy?= =?us-ascii?Q?nXUNRE6q7Qpf/oZMxdmP8FwNanCb7i3Qhdzgauqdo7WCduVT/CmGHWjHXpt7?= =?us-ascii?Q?Ifrv7kvfSR10/hc4nabmCsIQimNQD7xMsLzsW3xLrQqvOgrOS27a5CiHWVn+?= =?us-ascii?Q?HYsnyEbuMxKLiXhZ62qgS7G+rN3tMM70qAuuXqFptLKZ15whNLCJJG4TaSKd?= =?us-ascii?Q?S3PjqAY73HXEWbolfXgkJyIzUYHPZ84dxxJD58mxCmT+/Gbh9OXK6B9AbQ3M?= =?us-ascii?Q?FpUs4CzyWvp0E15clFVWcgbMGXLvCysvIpOo36f48HiJLGrrAH2mSuMH9oN8?= =?us-ascii?Q?ieL4SAL06dTK1ycbItGbClkD2UZnVpjZGTtDTa7fureZrdSEsUpECILBj9h8?= =?us-ascii?Q?ZieGI6uBuvt5l73ItkgF8NjT5YQ/DWWoDdcm1CQ4qBfUQWJ0vMKTY+ahfInf?= =?us-ascii?Q?9tQ+kBW4GXXhfhBQP4aKmzWOavTZtJyFRN1j4/ucbVD6tQtmFg3nJ3oYZIR6?= =?us-ascii?Q?tRFVF5EdN0L6E1IOU2qjE9ksU3T9um9JRMT9LK0OmB1n0by1b/nVsgB5eIc9?= =?us-ascii?Q?QqFTd1ARNacdkzPgvfqYOdVWTfuCmUQ9/YhIZen3WOAJqfRntYMmwMEdlFxl?= =?us-ascii?Q?NLicKdd8y6WvC5jF1eoZaHSgxbw4fGGQhhac7E7dF9ExwCf8qmkNkvKp6IED?= =?us-ascii?Q?fVjUiI6Cv3V43yeLKCvaTvEhl7HaOnUNHS+BaLZkEWauXXlg2vRW922dNVUb?= =?us-ascii?Q?DXlSLdo8MlEyJFugDgDuwlXvzdooL1YjWlLOKYAOr3NSmh8DE5tv5FYEwoqv?= =?us-ascii?Q?R99KYbuYpz1GjIdtlYUFfJDpg8MUkqUPHVSidhjNzFyCUW9TAwmzxjKy23/k?= =?us-ascii?Q?5pZspx1cUmAJJRHDkNbZMS43SMa2Puqx2b2m0cYs?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d640fad2-207b-4068-247f-08ddc82046c0 X-MS-Exchange-CrossTenant-AuthSource: DBBPR04MB7740.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2025 06:31:51.1540 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kYXi44szRgmL08IgimfME5iRxF9e3YdK0SCW5tvpPn6MdER5Mhw1sGV0U4Yatv4RhMw5iMsIwcYDvR1KitKexw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7780 Content-Type: text/plain; charset="utf-8" Implement useful functions to help debug and test nxpwifi. For example, file "fake_radar_detect" can generate fake radar detection which can be used to test AP DFS mode of nxpwifi without real radar detection triggerred by FW. Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/debugfs.c | 1230 ++++++++++++++++++++ 1 file changed, 1230 insertions(+) create mode 100644 drivers/net/wireless/nxp/nxpwifi/debugfs.c diff --git a/drivers/net/wireless/nxp/nxpwifi/debugfs.c b/drivers/net/wirel= ess/nxp/nxpwifi/debugfs.c new file mode 100644 index 000000000000..3a2a8f6d363f --- /dev/null +++ b/drivers/net/wireless/nxp/nxpwifi/debugfs.c @@ -0,0 +1,1230 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * NXP Wireless LAN device driver: debugfs + * + * Copyright 2011-2024 NXP + */ + +#include + +#include "main.h" +#include "cmdevt.h" +#include "11n.h" + +static struct dentry *nxpwifi_dfs_dir; + +static char *bss_modes[] =3D { + "UNSPECIFIED", + "ADHOC", + "STATION", + "AP", + "AP_VLAN", + "WDS", + "MONITOR", + "MESH_POINT", + "P2P_CLIENT", + "P2P_GO", + "P2P_DEVICE", +}; + +/* Proc info file read handler. + * + * This function is called when the 'info' file is opened for reading. + * It prints the following driver related information - + * - Driver name + * - Driver version + * - Driver extended version + * - Interface name + * - BSS mode + * - Media state (connected or disconnected) + * - MAC address + * - Total number of Tx bytes + * - Total number of Rx bytes + * - Total number of Tx packets + * - Total number of Rx packets + * - Total number of dropped Tx packets + * - Total number of dropped Rx packets + * - Total number of corrupted Tx packets + * - Total number of corrupted Rx packets + * - Carrier status (on or off) + * - Tx queue status (started or stopped) + * + * For STA mode drivers, it also prints the following extra - + * - ESSID + * - BSSID + * - Channel + * - Region code + * - Multicast count + * - Multicast addresses + */ +static ssize_t +nxpwifi_info_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + struct net_device *netdev =3D priv->netdev; + struct netdev_hw_addr *ha; + struct netdev_queue *txq; + unsigned long page =3D get_zeroed_page(GFP_KERNEL); + char *p =3D (char *)page, fmt[64]; + struct nxpwifi_bss_info info; + ssize_t ret; + int i =3D 0; + + if (!p) + return -ENOMEM; + + memset(&info, 0, sizeof(info)); + ret =3D nxpwifi_get_bss_info(priv, &info); + if (ret) + goto free_and_exit; + + nxpwifi_drv_get_driver_version(priv->adapter, fmt, sizeof(fmt) - 1); + + nxpwifi_get_ver_ext(priv, 0); + + p +=3D sprintf(p, "driver_name =3D "); + p +=3D sprintf(p, "\"nxpwifi\"\n"); + p +=3D sprintf(p, "driver_version =3D %s", fmt); + p +=3D sprintf(p, "\nverext =3D %s", priv->version_str); + p +=3D sprintf(p, "\ninterface_name=3D\"%s\"\n", netdev->name); + + if (info.bss_mode >=3D ARRAY_SIZE(bss_modes)) + p +=3D sprintf(p, "bss_mode=3D\"%d\"\n", info.bss_mode); + else + p +=3D sprintf(p, "bss_mode=3D\"%s\"\n", bss_modes[info.bss_mode]); + + p +=3D sprintf(p, "media_state=3D\"%s\"\n", + (!priv->media_connected ? "Disconnected" : "Connected")); + p +=3D sprintf(p, "mac_address=3D\"%pM\"\n", netdev->dev_addr); + + if (GET_BSS_ROLE(priv) =3D=3D NXPWIFI_BSS_ROLE_STA) { + p +=3D sprintf(p, "multicast_count=3D\"%d\"\n", + netdev_mc_count(netdev)); + p +=3D sprintf(p, "essid=3D\"%.*s\"\n", info.ssid.ssid_len, + info.ssid.ssid); + p +=3D sprintf(p, "bssid=3D\"%pM\"\n", info.bssid); + p +=3D sprintf(p, "channel=3D\"%d\"\n", (int)info.bss_chan); + p +=3D sprintf(p, "country_code =3D \"%s\"\n", info.country_code); + p +=3D sprintf(p, "region_code=3D\"0x%x\"\n", + priv->adapter->region_code); + + netdev_for_each_mc_addr(ha, netdev) + p +=3D sprintf(p, "multicast_address[%d]=3D\"%pM\"\n", + i++, ha->addr); + } + + p +=3D sprintf(p, "num_tx_bytes =3D %lu\n", priv->stats.tx_bytes); + p +=3D sprintf(p, "num_rx_bytes =3D %lu\n", priv->stats.rx_bytes); + p +=3D sprintf(p, "num_tx_pkts =3D %lu\n", priv->stats.tx_packets); + p +=3D sprintf(p, "num_rx_pkts =3D %lu\n", priv->stats.rx_packets); + p +=3D sprintf(p, "num_tx_pkts_dropped =3D %lu\n", priv->stats.tx_dropped= ); + p +=3D sprintf(p, "num_rx_pkts_dropped =3D %lu\n", priv->stats.rx_dropped= ); + p +=3D sprintf(p, "num_tx_pkts_err =3D %lu\n", priv->stats.tx_errors); + p +=3D sprintf(p, "num_rx_pkts_err =3D %lu\n", priv->stats.rx_errors); + p +=3D sprintf(p, "carrier %s\n", ((netif_carrier_ok(priv->netdev)) + ? "on" : "off")); + p +=3D sprintf(p, "tx queue"); + for (i =3D 0; i < netdev->num_tx_queues; i++) { + txq =3D netdev_get_tx_queue(netdev, i); + p +=3D sprintf(p, " %d:%s", i, netif_tx_queue_stopped(txq) ? + "stopped" : "started"); + } + p +=3D sprintf(p, "\n"); + + ret =3D simple_read_from_buffer(ubuf, count, ppos, (char *)page, + (unsigned long)p - page); + +free_and_exit: + free_page(page); + return ret; +} + +/* Proc getlog file read handler. + * + * This function is called when the 'getlog' file is opened for reading + * It prints the following log information - + * - Number of multicast Tx frames + * - Number of failed packets + * - Number of Tx retries + * - Number of multicast Tx retries + * - Number of duplicate frames + * - Number of RTS successes + * - Number of RTS failures + * - Number of ACK failures + * - Number of fragmented Rx frames + * - Number of multicast Rx frames + * - Number of FCS errors + * - Number of Tx frames + * - WEP ICV error counts + * - Number of received beacons + * - Number of missed beacons + */ +static ssize_t +nxpwifi_getlog_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + unsigned long page =3D get_zeroed_page(GFP_KERNEL); + char *p =3D (char *)page; + ssize_t ret; + struct nxpwifi_ds_get_stats stats; + + if (!p) + return -ENOMEM; + + memset(&stats, 0, sizeof(stats)); + ret =3D nxpwifi_get_stats_info(priv, &stats); + if (ret) + goto free_and_exit; + + p +=3D sprintf(p, "\n" + "mcasttxframe %u\n" + "failed %u\n" + "retry %u\n" + "multiretry %u\n" + "framedup %u\n" + "rtssuccess %u\n" + "rtsfailure %u\n" + "ackfailure %u\n" + "rxfrag %u\n" + "mcastrxframe %u\n" + "fcserror %u\n" + "txframe %u\n" + "wepicverrcnt-1 %u\n" + "wepicverrcnt-2 %u\n" + "wepicverrcnt-3 %u\n" + "wepicverrcnt-4 %u\n" + "bcn_rcv_cnt %u\n" + "bcn_miss_cnt %u\n", + stats.mcast_tx_frame, + stats.failed, + stats.retry, + stats.multi_retry, + stats.frame_dup, + stats.rts_success, + stats.rts_failure, + stats.ack_failure, + stats.rx_frag, + stats.mcast_rx_frame, + stats.fcs_error, + stats.tx_frame, + stats.wep_icv_error[0], + stats.wep_icv_error[1], + stats.wep_icv_error[2], + stats.wep_icv_error[3], + stats.bcn_rcv_cnt, + stats.bcn_miss_cnt); + + ret =3D simple_read_from_buffer(ubuf, count, ppos, (char *)page, + (unsigned long)p - page); + +free_and_exit: + free_page(page); + return ret; +} + +/* Sysfs histogram file read handler. + * + * This function is called when the 'histogram' file is opened for reading + * It prints the following histogram information - + * - Number of histogram samples + * - Receive packet number of each rx_rate + * - Receive packet number of each snr + * - Receive packet number of each nosie_flr + * - Receive packet number of each signal streath + */ +static ssize_t +nxpwifi_histogram_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + ssize_t ret; + struct nxpwifi_histogram_data *phist_data; + int i, value; + unsigned long page =3D get_zeroed_page(GFP_KERNEL); + char *p =3D (char *)page; + + if (!p) + return -ENOMEM; + + if (!priv || !priv->hist_data) { + ret =3D -EFAULT; + goto free_and_exit; + } + + phist_data =3D priv->hist_data; + + p +=3D sprintf(p, "\n" + "total samples =3D %d\n", + atomic_read(&phist_data->num_samples)); + + p +=3D sprintf(p, + "rx rates (in Mbps): 0=3D1M 1=3D2M 2=3D5.5M 3=3D11M 4=3D6M 5= =3D9M 6=3D12M\n" + "7=3D18M 8=3D24M 9=3D36M 10=3D48M 11=3D54M 12-27=3DMCS0-15(BW20= ) 28-43=3DMCS0-15(BW40)\n"); + + if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) { + p +=3D sprintf(p, + "44-53=3DMCS0-9(VHT:BW20) 54-63=3DMCS0-9(VHT:BW40) 64-73=3DMCS0-9(= VHT:BW80)\n\n"); + } else { + p +=3D sprintf(p, "\n"); + } + + for (i =3D 0; i < NXPWIFI_MAX_RX_RATES; i++) { + value =3D atomic_read(&phist_data->rx_rate[i]); + if (value) + p +=3D sprintf(p, "rx_rate[%02d] =3D %d\n", i, value); + } + + if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info)) { + for (i =3D NXPWIFI_MAX_RX_RATES; i < NXPWIFI_MAX_AC_RX_RATES; + i++) { + value =3D atomic_read(&phist_data->rx_rate[i]); + if (value) + p +=3D sprintf(p, "rx_rate[%02d] =3D %d\n", + i, value); + } + } + + for (i =3D 0; i < NXPWIFI_MAX_SNR; i++) { + value =3D atomic_read(&phist_data->snr[i]); + if (value) + p +=3D sprintf(p, "snr[%02ddB] =3D %d\n", i, value); + } + for (i =3D 0; i < NXPWIFI_MAX_NOISE_FLR; i++) { + value =3D atomic_read(&phist_data->noise_flr[i]); + if (value) + p +=3D sprintf(p, "noise_flr[%02ddBm] =3D %d\n", + (int)(i - 128), value); + } + for (i =3D 0; i < NXPWIFI_MAX_SIG_STRENGTH; i++) { + value =3D atomic_read(&phist_data->sig_str[i]); + if (value) + p +=3D sprintf(p, "sig_strength[-%02ddBm] =3D %d\n", + i, value); + } + + ret =3D simple_read_from_buffer(ubuf, count, ppos, (char *)page, + (unsigned long)p - page); + +free_and_exit: + free_page(page); + return ret; +} + +static ssize_t +nxpwifi_histogram_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D (void *)file->private_data; + + if (priv && priv->hist_data) + nxpwifi_hist_data_reset(priv); + return 0; +} + +static struct nxpwifi_debug_info info; + +/* Proc debug file read handler. + * + * This function is called when the 'debug' file is opened for reading + * It prints the following log information - + * - Interrupt count + * - WMM AC VO packets count + * - WMM AC VI packets count + * - WMM AC BE packets count + * - WMM AC BK packets count + * - Maximum Tx buffer size + * - Tx buffer size + * - Current Tx buffer size + * - Power Save mode + * - Power Save state + * - Deep Sleep status + * - Device wakeup required status + * - Number of wakeup tries + * - Host Sleep configured status + * - Host Sleep activated status + * - Number of Tx timeouts + * - Number of command timeouts + * - Last timed out command ID + * - Last timed out command action + * - Last command ID + * - Last command action + * - Last command index + * - Last command response ID + * - Last command response index + * - Last event + * - Last event index + * - Number of host to card command failures + * - Number of sleep confirm command failures + * - Number of host to card data failure + * - Number of deauthentication events + * - Number of disassociation events + * - Number of link lost events + * - Number of deauthentication commands + * - Number of association success commands + * - Number of association failure commands + * - Number of commands sent + * - Number of data packets sent + * - Number of command responses received + * - Number of events received + * - Tx BA stream table (TID, RA) + * - Rx reorder table (TID, TA, Start window, Window size, Buffer) + */ +static ssize_t +nxpwifi_debug_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + unsigned long page =3D get_zeroed_page(GFP_KERNEL); + char *p =3D (char *)page; + ssize_t ret; + + if (!p) + return -ENOMEM; + + ret =3D nxpwifi_get_debug_info(priv, &info); + if (ret) + goto free_and_exit; + + p +=3D nxpwifi_debug_info_to_buffer(priv, p, &info); + + ret =3D simple_read_from_buffer(ubuf, count, ppos, (char *)page, + (unsigned long)p - page); + +free_and_exit: + free_page(page); + return ret; +} + +static u32 saved_reg_type, saved_reg_offset, saved_reg_value; + +/* Proc regrdwr file write handler. + * + * This function is called when the 'regrdwr' file is opened for writing + * + * This function can be used to write to a register. + */ +static ssize_t +nxpwifi_regrdwr_write(struct file *file, + const char __user *ubuf, size_t count, loff_t *ppos) +{ + char *buf; + int ret; + u32 reg_type =3D 0, reg_offset =3D 0, reg_value =3D UINT_MAX; + int rv; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + rv =3D sscanf(buf, "%u %x %x", ®_type, ®_offset, ®_value); + + if (rv !=3D 3) { + ret =3D -EINVAL; + goto done; + } + + if (reg_type =3D=3D 0 || reg_offset =3D=3D 0) { + ret =3D -EINVAL; + goto done; + } else { + saved_reg_type =3D reg_type; + saved_reg_offset =3D reg_offset; + saved_reg_value =3D reg_value; + ret =3D count; + } +done: + kfree(buf); + return ret; +} + +/* Proc regrdwr file read handler. + * + * This function is called when the 'regrdwr' file is opened for reading + * + * This function can be used to read from a register. + */ +static ssize_t +nxpwifi_regrdwr_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + unsigned long addr =3D get_zeroed_page(GFP_KERNEL); + char *buf =3D (char *)addr; + int pos =3D 0, ret =3D 0; + u32 reg_value; + + if (!buf) + return -ENOMEM; + + if (!saved_reg_type) { + /* No command has been given */ + pos +=3D snprintf(buf, PAGE_SIZE, "0"); + goto done; + } + /* Set command has been given */ + if (saved_reg_value !=3D UINT_MAX) { + ret =3D nxpwifi_reg_write(priv, saved_reg_type, saved_reg_offset, + saved_reg_value); + + pos +=3D snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", + saved_reg_type, saved_reg_offset, + saved_reg_value); + + ret =3D simple_read_from_buffer(ubuf, count, ppos, buf, pos); + + goto done; + } + /* Get command has been given */ + ret =3D nxpwifi_reg_read(priv, saved_reg_type, + saved_reg_offset, ®_value); + if (ret) { + ret =3D -EINVAL; + goto done; + } + + pos +=3D snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", saved_reg_type, + saved_reg_offset, reg_value); + + ret =3D simple_read_from_buffer(ubuf, count, ppos, buf, pos); + +done: + free_page(addr); + return ret; +} + +/* Proc debug_mask file read handler. + * This function is called when the 'debug_mask' file is opened for reading + * This function can be used read driver debugging mask value. + */ +static ssize_t +nxpwifi_debug_mask_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + unsigned long page =3D get_zeroed_page(GFP_KERNEL); + char *buf =3D (char *)page; + size_t ret =3D 0; + int pos =3D 0; + + if (!buf) + return -ENOMEM; + + pos +=3D snprintf(buf, PAGE_SIZE, "debug mask=3D0x%08x\n", + priv->adapter->debug_mask); + ret =3D simple_read_from_buffer(ubuf, count, ppos, buf, pos); + + free_page(page); + return ret; +} + +/* Proc debug_mask file read handler. + * This function is called when the 'debug_mask' file is opened for reading + * This function can be used read driver debugging mask value. + */ +static ssize_t +nxpwifi_debug_mask_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + int ret; + unsigned long debug_mask; + struct nxpwifi_private *priv =3D (void *)file->private_data; + char *buf; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + if (kstrtoul(buf, 0, &debug_mask)) { + ret =3D -EINVAL; + goto done; + } + + priv->adapter->debug_mask =3D debug_mask; + ret =3D count; +done: + kfree(buf); + return ret; +} + +/* debugfs verext file write handler. + * This function is called when the 'verext' file is opened for write + */ +static ssize_t +nxpwifi_verext_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + int ret; + u32 versionstrsel; + struct nxpwifi_private *priv =3D (void *)file->private_data; + + ret =3D kstrtou32_from_user(ubuf, count, 10, &versionstrsel); + if (ret) + return ret; + + priv->versionstrsel =3D versionstrsel; + + return count; +} + +/* Proc verext file read handler. + * This function is called when the 'verext' file is opened for reading + * This function can be used read driver exteneed verion string. + */ +static ssize_t +nxpwifi_verext_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + char buf[256]; + int ret; + + nxpwifi_get_ver_ext(priv, priv->versionstrsel); + ret =3D snprintf(buf, sizeof(buf), "version string: %s\n", + priv->version_str); + + return simple_read_from_buffer(ubuf, count, ppos, buf, ret); +} + +/* Proc memrw file write handler. + * This function is called when the 'memrw' file is opened for writing + * This function can be used to write to a memory location. + */ +static ssize_t +nxpwifi_memrw_write(struct file *file, const char __user *ubuf, size_t cou= nt, + loff_t *ppos) +{ + int ret; + char cmd; + struct nxpwifi_ds_mem_rw mem_rw; + u16 cmd_action; + struct nxpwifi_private *priv =3D (void *)file->private_data; + char *buf; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + ret =3D sscanf(buf, "%c %x %x", &cmd, &mem_rw.addr, &mem_rw.value); + if (ret !=3D 3) { + ret =3D -EINVAL; + goto done; + } + + if ((cmd =3D=3D 'r') || (cmd =3D=3D 'R')) { + cmd_action =3D HOST_ACT_GEN_GET; + mem_rw.value =3D 0; + } else if ((cmd =3D=3D 'w') || (cmd =3D=3D 'W')) { + cmd_action =3D HOST_ACT_GEN_SET; + } else { + ret =3D -EINVAL; + goto done; + } + + memcpy(&priv->mem_rw, &mem_rw, sizeof(mem_rw)); + ret =3D nxpwifi_send_cmd(priv, HOST_CMD_MEM_ACCESS, cmd_action, 0, + &mem_rw, true); + if (!ret) + ret =3D count; + +done: + kfree(buf); + return ret; +} + +/* Proc memrw file read handler. + * This function is called when the 'memrw' file is opened for reading + * This function can be used to read from a memory location. + */ +static ssize_t +nxpwifi_memrw_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D (void *)file->private_data; + unsigned long addr =3D get_zeroed_page(GFP_KERNEL); + char *buf =3D (char *)addr; + int ret, pos =3D 0; + + if (!buf) + return -ENOMEM; + + pos +=3D snprintf(buf, PAGE_SIZE, "0x%x 0x%x\n", priv->mem_rw.addr, + priv->mem_rw.value); + ret =3D simple_read_from_buffer(ubuf, count, ppos, buf, pos); + + free_page(addr); + return ret; +} + +static u32 saved_offset =3D -1, saved_bytes =3D -1; + +/* Proc rdeeprom file write handler. + * + * This function is called when the 'rdeeprom' file is opened for writing + * + * This function can be used to write to a RDEEPROM location. + */ +static ssize_t +nxpwifi_rdeeprom_write(struct file *file, + const char __user *ubuf, size_t count, loff_t *ppos) +{ + char *buf; + int ret =3D 0; + int offset =3D -1, bytes =3D -1; + int rv; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + rv =3D sscanf(buf, "%d %d", &offset, &bytes); + + if (rv !=3D 2) { + ret =3D -EINVAL; + goto done; + } + + if (offset =3D=3D -1 || bytes =3D=3D -1) { + ret =3D -EINVAL; + goto done; + } else { + saved_offset =3D offset; + saved_bytes =3D bytes; + ret =3D count; + } +done: + kfree(buf); + return ret; +} + +/* Proc rdeeprom read write handler. + * + * This function is called when the 'rdeeprom' file is opened for reading + * + * This function can be used to read from a RDEEPROM location. + */ +static ssize_t +nxpwifi_rdeeprom_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + unsigned long addr =3D get_zeroed_page(GFP_KERNEL); + char *buf =3D (char *)addr; + int pos, ret, i; + u8 value[MAX_EEPROM_DATA]; + + if (!buf) + return -ENOMEM; + + if (saved_offset =3D=3D -1) { + /* No command has been given */ + pos =3D snprintf(buf, PAGE_SIZE, "0"); + goto done; + } + + /* Get command has been given */ + ret =3D nxpwifi_eeprom_read(priv, (u16)saved_offset, + (u16)saved_bytes, value); + if (ret) { + ret =3D -EINVAL; + goto out_free; + } + + pos =3D snprintf(buf, PAGE_SIZE, "%d %d ", saved_offset, saved_bytes); + + for (i =3D 0; i < saved_bytes; i++) + pos +=3D scnprintf(buf + pos, PAGE_SIZE - pos, "%d ", value[i]); + +done: + ret =3D simple_read_from_buffer(ubuf, count, ppos, buf, pos); +out_free: + free_page(addr); + return ret; +} + +/* Proc hscfg file write handler + * This function can be used to configure the host sleep parameters. + */ +static ssize_t +nxpwifi_hscfg_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D (void *)file->private_data; + char *buf; + int ret, arg_num; + struct nxpwifi_ds_hs_cfg hscfg; + int conditions =3D HS_CFG_COND_DEF; + u32 gpio =3D HS_CFG_GPIO_DEF, gap =3D HS_CFG_GAP_DEF; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + arg_num =3D sscanf(buf, "%d %x %x", &conditions, &gpio, &gap); + + memset(&hscfg, 0, sizeof(struct nxpwifi_ds_hs_cfg)); + + if (arg_num > 3) { + nxpwifi_dbg(priv->adapter, ERROR, + "Too many arguments\n"); + ret =3D -EINVAL; + goto done; + } + + if (arg_num >=3D 1 && arg_num < 3) + nxpwifi_set_hs_params(priv, HOST_ACT_GEN_GET, + NXPWIFI_SYNC_CMD, &hscfg); + + if (arg_num) { + if (conditions =3D=3D HS_CFG_CANCEL) { + nxpwifi_cancel_hs(priv, NXPWIFI_ASYNC_CMD); + ret =3D count; + goto done; + } + hscfg.conditions =3D conditions; + } + if (arg_num >=3D 2) + hscfg.gpio =3D gpio; + if (arg_num =3D=3D 3) + hscfg.gap =3D gap; + + hscfg.is_invoke_hostcmd =3D false; + nxpwifi_set_hs_params(priv, HOST_ACT_GEN_SET, + NXPWIFI_SYNC_CMD, &hscfg); + + nxpwifi_enable_hs(priv->adapter); + clear_bit(NXPWIFI_IS_HS_ENABLING, &priv->adapter->work_flags); + ret =3D count; +done: + kfree(buf); + return ret; +} + +/* Proc hscfg file read handler + * This function can be used to read host sleep configuration + * parameters from driver. + */ +static ssize_t +nxpwifi_hscfg_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D (void *)file->private_data; + unsigned long addr =3D get_zeroed_page(GFP_KERNEL); + char *buf =3D (char *)addr; + int pos, ret; + struct nxpwifi_ds_hs_cfg hscfg; + + if (!buf) + return -ENOMEM; + + nxpwifi_set_hs_params(priv, HOST_ACT_GEN_GET, + NXPWIFI_SYNC_CMD, &hscfg); + + pos =3D snprintf(buf, PAGE_SIZE, "%u 0x%x 0x%x\n", hscfg.conditions, + hscfg.gpio, hscfg.gap); + + ret =3D simple_read_from_buffer(ubuf, count, ppos, buf, pos); + + free_page(addr); + return ret; +} + +static ssize_t +nxpwifi_timeshare_coex_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D file->private_data; + char buf[3]; + bool timeshare_coex; + int ret; + unsigned int len; + + if (priv->adapter->fw_api_ver !=3D NXPWIFI_FW_V15) + return -EOPNOTSUPP; + + ret =3D nxpwifi_send_cmd(priv, HOST_CMD_ROBUST_COEX, + HOST_ACT_GEN_GET, 0, ×hare_coex, true); + if (ret) + return ret; + + len =3D sprintf(buf, "%d\n", timeshare_coex); + return simple_read_from_buffer(ubuf, count, ppos, buf, len); +} + +static ssize_t +nxpwifi_timeshare_coex_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + bool timeshare_coex; + struct nxpwifi_private *priv =3D file->private_data; + int ret; + + if (priv->adapter->fw_api_ver !=3D NXPWIFI_FW_V15) + return -EOPNOTSUPP; + + ret =3D kstrtobool_from_user(ubuf, count, ×hare_coex); + if (ret) + return ret; + + ret =3D nxpwifi_send_cmd(priv, HOST_CMD_ROBUST_COEX, + HOST_ACT_GEN_SET, 0, ×hare_coex, true); + if (ret) + return ret; + else + return count; +} + +static ssize_t +nxpwifi_reset_write(struct file *file, + const char __user *ubuf, size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D file->private_data; + struct nxpwifi_adapter *adapter =3D priv->adapter; + bool result; + int rc; + + rc =3D kstrtobool_from_user(ubuf, count, &result); + if (rc) + return rc; + + if (!result) + return -EINVAL; + + if (adapter->if_ops.card_reset) { + dev_info(adapter->dev, "Resetting per request\n"); + adapter->if_ops.card_reset(adapter); + } + + return count; +} + +static ssize_t +nxpwifi_fake_radar_detect_write(struct file *file, + const char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D file->private_data; + struct nxpwifi_adapter *adapter =3D priv->adapter; + bool result; + int rc; + + rc =3D kstrtobool_from_user(ubuf, count, &result); + if (rc) + return rc; + + if (!result) + return -EINVAL; + + if (priv->wdev.cac_started) { + nxpwifi_dbg(adapter, MSG, + "Generate fake radar detected during CAC\n"); + if (nxpwifi_stop_radar_detection(priv, &priv->dfs_chandef)) + nxpwifi_dbg(adapter, ERROR, + "Failed to stop CAC in FW\n"); + wiphy_delayed_work_cancel(priv->adapter->wiphy, &priv->dfs_cac_work); + cfg80211_cac_event(priv->netdev, &priv->dfs_chandef, + NL80211_RADAR_CAC_ABORTED, GFP_KERNEL); + cfg80211_radar_event(adapter->wiphy, &priv->dfs_chandef, + GFP_KERNEL); + } else { + if (priv->bss_chandef.chan->dfs_cac_ms) { + nxpwifi_dbg(adapter, MSG, + "Generate fake radar detected\n"); + cfg80211_radar_event(adapter->wiphy, + &priv->dfs_chandef, + GFP_KERNEL); + } + } + + return count; +} + +static ssize_t +nxpwifi_netmon_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + int ret; + struct nxpwifi_802_11_net_monitor netmon_cfg; + struct nxpwifi_private *priv =3D (void *)file->private_data; + char *buf; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + memset(&netmon_cfg, 0, sizeof(struct nxpwifi_802_11_net_monitor)); + ret =3D sscanf(buf, "%u %u %u %u %u", + &netmon_cfg.enable_net_mon, + &netmon_cfg.filter_flag, + &netmon_cfg.band, + &netmon_cfg.channel, + &netmon_cfg.chan_bandwidth); + + ret =3D nxpwifi_send_cmd(priv, HOST_CMD_802_11_NET_MONITOR, + HOST_ACT_GEN_SET, 0, &netmon_cfg, true); + + if (!ret) + ret =3D count; + + kfree(buf); + return ret; +} + +static ssize_t +nxpwifi_twt_setup_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + int ret; + struct nxpwifi_twt_cfg twt_cfg; + struct nxpwifi_private *priv =3D (void *)file->private_data; + char *buf; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + ret =3D sscanf(buf, "%hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hu %hh= u %hu", + &twt_cfg.param.twt_setup.implicit, + &twt_cfg.param.twt_setup.announced, + &twt_cfg.param.twt_setup.trigger_enabled, + &twt_cfg.param.twt_setup.twt_info_disabled, + &twt_cfg.param.twt_setup.negotiation_type, + &twt_cfg.param.twt_setup.twt_wakeup_duration, + &twt_cfg.param.twt_setup.flow_identifier, + &twt_cfg.param.twt_setup.hard_constraint, + &twt_cfg.param.twt_setup.twt_exponent, + &twt_cfg.param.twt_setup.twt_mantissa, + &twt_cfg.param.twt_setup.twt_request, + &twt_cfg.param.twt_setup.bcn_miss_threshold); + if (ret !=3D 12) { + ret =3D -EINVAL; + goto done; + } + twt_cfg.sub_id =3D NXPWIFI_11AX_TWT_SETUP_SUBID; + ret =3D nxpwifi_send_cmd(priv, HOST_CMD_TWT_CFG, HOST_ACT_GEN_SET, 0, + &twt_cfg, true); + if (!ret) + ret =3D count; +done: + kfree(buf); + return ret; +} + +static ssize_t +nxpwifi_twt_teardown_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + int ret; + struct nxpwifi_twt_cfg twt_cfg; + struct nxpwifi_private *priv =3D (void *)file->private_data; + char *buf; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + ret =3D sscanf(buf, "%hhu %hhu %hhu", + &twt_cfg.param.twt_teardown.flow_identifier, + &twt_cfg.param.twt_teardown.negotiation_type, + &twt_cfg.param.twt_teardown.teardown_all_twt); + if (ret !=3D 3) { + ret =3D -EINVAL; + goto done; + } + + twt_cfg.sub_id =3D NXPWIFI_11AX_TWT_TEARDOWN_SUBID; + ret =3D nxpwifi_send_cmd(priv, HOST_CMD_TWT_CFG, HOST_ACT_GEN_SET, 0, + &twt_cfg, true); + + if (!ret) + ret =3D count; + +done: + kfree(buf); + return ret; +} + +static ssize_t +nxpwifi_twt_report_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct nxpwifi_private *priv =3D + (struct nxpwifi_private *)file->private_data; + unsigned long page =3D get_zeroed_page(GFP_KERNEL); + char *p =3D (char *)page; + ssize_t ret; + struct nxpwifi_twt_cfg twt_cfg; + u8 num, i, j; + + if (!p) + return -ENOMEM; + + twt_cfg.sub_id =3D NXPWIFI_11AX_TWT_REPORT_SUBID; + ret =3D nxpwifi_send_cmd(priv, HOST_CMD_TWT_CFG, HOST_ACT_GEN_GET, 0, + &twt_cfg, true); + if (ret) + goto done; + num =3D twt_cfg.param.twt_report.length / NXPWIFI_BTWT_REPORT_LEN; + num =3D num <=3D NXPWIFI_BTWT_REPORT_MAX_NUM ? num : NXPWIFI_BTWT_REPORT_= MAX_NUM; + p +=3D sprintf(p, "\ntwt_report len %hhu, num %hhu, twt_report_info:\n", + twt_cfg.param.twt_report.length, num); + for (i =3D 0; i < num; i++) { + p +=3D sprintf(p, "id[%hu]:\r\n", i); + for (j =3D 0; j < NXPWIFI_BTWT_REPORT_LEN; j++) { + p +=3D sprintf(p, + " 0x%02x", + twt_cfg.param.twt_report.data[i * NXPWIFI_BTWT_REPORT_LEN + j]); + } + p +=3D sprintf(p, "\r\n"); + } + + ret =3D simple_read_from_buffer(ubuf, count, ppos, (char *)page, + (unsigned long)p - page); + +done: + free_page(page); + return ret; +} + +static ssize_t +nxpwifi_twt_information_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + int ret; + struct nxpwifi_twt_cfg twt_cfg; + struct nxpwifi_private *priv =3D (void *)file->private_data; + char *buf; + + buf =3D memdup_user_nul(ubuf, min(count, (size_t)(PAGE_SIZE - 1))); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + ret =3D sscanf(buf, "%hhu %u", + &twt_cfg.param.twt_information.flow_identifier, + &twt_cfg.param.twt_information.suspend_duration); + if (ret !=3D 2) { + ret =3D -EINVAL; + goto done; + } + + twt_cfg.sub_id =3D NXPWIFI_11AX_TWT_INFORMATION_SUBID; + ret =3D nxpwifi_send_cmd(priv, HOST_CMD_TWT_CFG, HOST_ACT_GEN_SET, 0, + &twt_cfg, true); + + if (!ret) + ret =3D count; + +done: + kfree(buf); + return ret; +} + +#define NXPWIFI_DFS_ADD_FILE(name) debugfs_create_file(#name, 0644, \ + priv->dfs_dev_dir, priv, \ + &nxpwifi_dfs_##name##_fops) + +#define NXPWIFI_DFS_FILE_OPS(name) \ +static const struct file_operations nxpwifi_dfs_##name##_fops =3D { \ + .read =3D nxpwifi_##name##_read, \ + .write =3D nxpwifi_##name##_write, \ + .open =3D simple_open, \ +} + +#define NXPWIFI_DFS_FILE_READ_OPS(name) \ +static const struct file_operations nxpwifi_dfs_##name##_fops =3D { \ + .read =3D nxpwifi_##name##_read, \ + .open =3D simple_open, \ +} + +#define NXPWIFI_DFS_FILE_WRITE_OPS(name) \ +static const struct file_operations nxpwifi_dfs_##name##_fops =3D { \ + .write =3D nxpwifi_##name##_write, \ + .open =3D simple_open, \ +} + +NXPWIFI_DFS_FILE_READ_OPS(info); +NXPWIFI_DFS_FILE_READ_OPS(debug); +NXPWIFI_DFS_FILE_READ_OPS(getlog); +NXPWIFI_DFS_FILE_OPS(regrdwr); +NXPWIFI_DFS_FILE_OPS(rdeeprom); +NXPWIFI_DFS_FILE_OPS(memrw); +NXPWIFI_DFS_FILE_OPS(hscfg); +NXPWIFI_DFS_FILE_OPS(histogram); +NXPWIFI_DFS_FILE_OPS(debug_mask); +NXPWIFI_DFS_FILE_OPS(timeshare_coex); +NXPWIFI_DFS_FILE_WRITE_OPS(reset); +NXPWIFI_DFS_FILE_WRITE_OPS(fake_radar_detect); +NXPWIFI_DFS_FILE_OPS(verext); +NXPWIFI_DFS_FILE_WRITE_OPS(netmon); +NXPWIFI_DFS_FILE_WRITE_OPS(twt_setup); +NXPWIFI_DFS_FILE_WRITE_OPS(twt_teardown); +NXPWIFI_DFS_FILE_READ_OPS(twt_report); +NXPWIFI_DFS_FILE_WRITE_OPS(twt_information); + +/* This function creates the debug FS directory structure and the files. + */ +void +nxpwifi_dev_debugfs_init(struct nxpwifi_private *priv) +{ + if (!nxpwifi_dfs_dir || !priv) + return; + + priv->dfs_dev_dir =3D debugfs_create_dir(priv->netdev->name, + nxpwifi_dfs_dir); + + NXPWIFI_DFS_ADD_FILE(info); + NXPWIFI_DFS_ADD_FILE(debug); + NXPWIFI_DFS_ADD_FILE(getlog); + NXPWIFI_DFS_ADD_FILE(regrdwr); + NXPWIFI_DFS_ADD_FILE(rdeeprom); + + NXPWIFI_DFS_ADD_FILE(memrw); + NXPWIFI_DFS_ADD_FILE(hscfg); + NXPWIFI_DFS_ADD_FILE(histogram); + NXPWIFI_DFS_ADD_FILE(debug_mask); + NXPWIFI_DFS_ADD_FILE(timeshare_coex); + NXPWIFI_DFS_ADD_FILE(reset); + NXPWIFI_DFS_ADD_FILE(fake_radar_detect); + NXPWIFI_DFS_ADD_FILE(verext); + NXPWIFI_DFS_ADD_FILE(netmon); + NXPWIFI_DFS_ADD_FILE(twt_setup); + NXPWIFI_DFS_ADD_FILE(twt_teardown); + NXPWIFI_DFS_ADD_FILE(twt_report); + NXPWIFI_DFS_ADD_FILE(twt_information); +} + +/* This function removes the debug FS directory structure and the files. + */ +void +nxpwifi_dev_debugfs_remove(struct nxpwifi_private *priv) +{ + if (!priv) + return; + + debugfs_remove_recursive(priv->dfs_dev_dir); +} + +/* This function creates the top level proc directory. + */ +void +nxpwifi_debugfs_init(void) +{ + if (!nxpwifi_dfs_dir) + nxpwifi_dfs_dir =3D debugfs_create_dir("nxpwifi", NULL); +} + +/* This function removes the top level proc directory. + */ +void +nxpwifi_debugfs_remove(void) +{ + debugfs_remove(nxpwifi_dfs_dir); +} --=20 2.34.1