Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2413770pxu; Fri, 18 Dec 2020 12:39:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYC3pDJE/XEF5xFeD9R7XIHVw3h9l7EeF0BTWyepuvj1B2jpR5kMuA8m/9UoNg7+FhNyOm X-Received: by 2002:a05:6402:949:: with SMTP id h9mr6159812edz.301.1608323949128; Fri, 18 Dec 2020 12:39:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608323949; cv=none; d=google.com; s=arc-20160816; b=MkxuJBCm3rzWQa8iu1kpLl67h0ba9TOUgqfBSaL+Ix2bxBwZvSAmRCGjqU6+Lqw7ym NIJ3bwDXBjyr5MbSJuMFvUTacJQF3oO2QuSuX9CDMra+2ocfsg7uK8RMXc7sGh3N56+P MpoSg9WZVzsdSTuw/jEqmMo1T70SPypHe4XI1wJZH6nbHPzPr0LejBIYbfhemJYHEIVr T+b7Oz6ftj2pnDbC+sjlqSWoa/5dlqUs29BPE2sOnMQu1xmlElJ35D/j+yTNBjC1sysz 6lgHl23WzUp6lXmzzaxuaDnHRiVFE2lUo2E07gC9G5qKJsklVmHwPwCi42NFa5dRcT1w 6JNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:ironport-sdr:ironport-sdr; bh=f3D/kKQTjUFmDFPGraULj8DDJK8zXsvAb/O79QECtXw=; b=otObzrZGaGciP9w8nsid1RVp5DbtKZzrl/HX3CjwWc2KjM6JY4a8ImBADULSkrU5Xs ozL7kSbn04sgWBey3C3sVYbh14TGRU3ANNvBuA7vIa/ONjRLvjlMv97zz0Mrro+LJ8Pj KX5IrmKv2gdvZ6ROWavTrXxZzCwPuVPBPjjIcU4fCimroyh7haPZoH5TyCh+AIp8Hono 0GMrWbZ4cvXGKF0i7sBfgDERQLeM/BAE5ooVHX11IUZ0KDLd4uNGVaE391LAUumW8TZA mcLy23wYoUuWju7/kwv1ojHEM7//I8n1teosZ59y9PFpTL1DGBC7msYqAF8wQJ9jZvWN WKMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z23si5225264ejn.209.2020.12.18.12.38.46; Fri, 18 Dec 2020 12:39:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727021AbgLRSfv (ORCPT + 99 others); Fri, 18 Dec 2020 13:35:51 -0500 Received: from mga09.intel.com ([134.134.136.24]:62466 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725766AbgLRSfu (ORCPT ); Fri, 18 Dec 2020 13:35:50 -0500 IronPort-SDR: 8RlXYXgCBKofEmr/6j108yxxg7rtYjYetrD3Hztuz+yeAAA2pOIa5kkO18RUb2YMDRhDrHK4O6 X6BbUc6tSCWg== X-IronPort-AV: E=McAfee;i="6000,8403,9839"; a="175624473" X-IronPort-AV: E=Sophos;i="5.78,431,1599548400"; d="scan'208";a="175624473" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2020 10:35:09 -0800 IronPort-SDR: XU3Zi/R5SNHSBXELhDhOLVBZ2Knmc0n32i3ol2glcUtdSKgzlMYOzOorZ5ouL6gJqdArRl8AcJ lse2F/+Mt4aQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,431,1599548400"; d="scan'208";a="414210965" Received: from ahunter-desktop.fi.intel.com (HELO [10.237.72.94]) ([10.237.72.94]) by orsmga001.jf.intel.com with ESMTP; 18 Dec 2020 10:34:59 -0800 Subject: Re: [PATCH V3] scsi: ufs-debugfs: Add error counters To: Bean Huo , "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Alim Akhtar , Avri Altman , Can Guo , Stanley Chu References: <20201218122027.27472-1-adrian.hunter@intel.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Message-ID: <17957d71-d45b-d5f6-8ef2-453402a23268@intel.com> Date: Fri, 18 Dec 2020 20:34:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/12/20 5:17 pm, Bean Huo wrote: > On Fri, 2020-12-18 at 14:20 +0200, Adrian Hunter wrote: >> People testing have a need to know how many errors might be occurring >> over time. Add error counters and expose them via debugfs. >> >> A module initcall is used to create a debugfs root directory for >> ufshcd-related items. In the case that modules are built-in, then >> initialization is done in link order, so move ufshcd-core to the top >> of >> the Makefile. >> >> Signed-off-by: Adrian Hunter >> Reviewed-by: Avri Altman >> --- >> >> >> Changes in V3: >> Fixed link order to ensure correct initcall ordering when >> modules are built-in. >> Amended commit message accordingly. >> >> Changes in V2: >> Add missing '#include "ufs-debugfs.h"' in ufs-debugfs.c >> Reported-by: kernel test robot >> >> >> drivers/scsi/ufs/Makefile | 13 +++++--- >> drivers/scsi/ufs/ufs-debugfs.c | 56 >> ++++++++++++++++++++++++++++++++++ >> drivers/scsi/ufs/ufs-debugfs.h | 22 +++++++++++++ >> drivers/scsi/ufs/ufshcd.c | 19 ++++++++++++ >> drivers/scsi/ufs/ufshcd.h | 5 +++ >> 5 files changed, 111 insertions(+), 4 deletions(-) >> create mode 100644 drivers/scsi/ufs/ufs-debugfs.c >> create mode 100644 drivers/scsi/ufs/ufs-debugfs.h >> >> diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile >> index 4679af1b564e..06f3a3fe4a44 100644 >> --- a/drivers/scsi/ufs/Makefile >> +++ b/drivers/scsi/ufs/Makefile >> @@ -1,5 +1,14 @@ >> # SPDX-License-Identifier: GPL-2.0 >> # UFSHCD makefile >> + >> +# The link order is important here. ufshcd-core must initialize >> +# before vendor drivers. >> +obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o >> +ufshcd-core-y += ufshcd.o ufs-sysfs.o >> +ufshcd-core-$(CONFIG_DEBUG_FS) += ufs-debugfs.o >> +ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o >> +ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o >> + >> obj-$(CONFIG_SCSI_UFS_DWC_TC_PCI) += tc-dwc-g210-pci.o ufshcd-dwc.o >> tc-dwc-g210.o >> obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o >> ufshcd-dwc.o tc-dwc-g210.o >> obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o >> @@ -7,10 +16,6 @@ obj-$(CONFIG_SCSI_UFS_QCOM) += ufs_qcom.o >> ufs_qcom-y += ufs-qcom.o >> ufs_qcom-$(CONFIG_SCSI_UFS_CRYPTO) += ufs-qcom-ice.o >> obj-$(CONFIG_SCSI_UFS_EXYNOS) += ufs-exynos.o >> -obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o >> -ufshcd-core-y += ufshcd.o ufs-sysfs.o >> -ufshcd-core-$(CONFIG_SCSI_UFS_BSG) += ufs_bsg.o >> -ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO) += ufshcd-crypto.o >> obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o >> obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o >> obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o >> diff --git a/drivers/scsi/ufs/ufs-debugfs.c b/drivers/scsi/ufs/ufs- >> debugfs.c >> new file mode 100644 >> index 000000000000..dee98dc72d29 >> --- /dev/null >> +++ b/drivers/scsi/ufs/ufs-debugfs.c >> @@ -0,0 +1,56 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +// Copyright (C) 2020 Intel Corporation >> + >> +#include >> + >> +#include "ufs-debugfs.h" >> +#include "ufshcd.h" >> + >> +static struct dentry *ufs_debugfs_root; >> + >> +void __init ufs_debugfs_init(void) >> +{ >> + ufs_debugfs_root = debugfs_create_dir("ufshcd", NULL); >> +} >> + >> +void __exit ufs_debugfs_exit(void) >> +{ >> + debugfs_remove_recursive(ufs_debugfs_root); >> +} >> + >> +static int ufs_debugfs_stats_show(struct seq_file *s, void *data) >> +{ >> + struct ufs_hba *hba = s->private; >> + struct ufs_event_hist *e = hba->ufs_stats.event; >> + >> +#define PRT(fmt, typ) \ >> + seq_printf(s, fmt, e[UFS_EVT_ ## typ].cnt) >> + >> + PRT("PHY Adapter Layer errors (except LINERESET): %llu\n", >> PA_ERR); >> + PRT("Data Link Layer errors: %llu\n", DL_ERR); >> + PRT("Network Layer errors: %llu\n", NL_ERR); >> + PRT("Transport Layer errors: %llu\n", TL_ERR); >> + PRT("Generic DME errors: %llu\n", DME_ERR); >> + PRT("Auto-hibernate errors: %llu\n", AUTO_HIBERN8_ERR); >> + PRT("IS Fatal errors (CEFES, SBFES, HCFES, DFES): %llu\n", >> FATAL_ERR); >> + PRT("DME Link Startup errors: %llu\n", LINK_STARTUP_FAIL); >> + PRT("PM Resume errors: %llu\n", RESUME_ERR); >> + PRT("PM Suspend errors : %llu\n", SUSPEND_ERR); >> + PRT("Logical Unit Resets: %llu\n", DEV_RESET); >> + PRT("Host Resets: %llu\n", HOST_RESET); >> + PRT("SCSI command aborts: %llu\n", ABORT); >> +#undef PRT >> + return 0; >> +} >> +DEFINE_SHOW_ATTRIBUTE(ufs_debugfs_stats); >> + >> +void ufs_debugfs_hba_init(struct ufs_hba *hba) >> +{ > > I prefer adding: > if (!ufs_debugfs_root) > return; I understand that you want to be careful, but it is not harmful if it is NULL, so are you sure we should do this? > >> + hba->debugfs_root = debugfs_create_dir(dev_name(hba->dev), >> ufs_debugfs_root); It is OK to pass NULL or error codes as parent dentry to debugfs_create_... functions. If ufs_debugfs_root is NULL (which won't happen) then the directory will be created in debugfs root i.e. /sys/kernel/debug, using the device name. If ufs_debugfs_root is an error code, then debugfs_create_dir will return an error code, and following debugfs_create_file() will return an error code. > >> + debugfs_create_file("stats", 0400, hba->debugfs_root, hba, >> &ufs_debugfs_stats_fops); > > if (!debugfs_create_file("stats", 0400, hba->debugfs_root, hba, > &ufs_debugfs_stats_fops)) { > debugfs_remove(hba->debugfs_root); > return -ENOMEM; Being without debugfs files is not a problem, so there is no reason to return an error. It is relatively rare in the kernel that code checks the return value of debugfs_create_file(). We really don't want to fail probing just because of debugfs. However, because debugfs' only real resource is a small amount of memory, it is extremely unlikely it will fail in that sense. Although you can force it to fail by adding the kernel command line parameter debugfs=off