On Thu, Feb 06, 2025 at 11:13:43PM +0800, Hans Zhang wrote: > Add the debugfs property to provide a view of the current link's LTSSM > status from the root port device. > > /sys/kernel/debug/dwc_pcie_<dev>/ltssm_status > > Signed-off-by: Hans Zhang <18255117159@xxxxxxx> > --- > Changes since v1: > https://lore.kernel.org/linux-pci/20250123071326.1810751-1-18255117159@xxxxxxx/ > > - Do not place into sysfs node as recommended by maintainer. Shradha-based patch > is put into debugfs. > - Submissions based on the following patches: > https://patchwork.kernel.org/project/linux-pci/patch/20250121111421.35437-2-shradha.t@xxxxxxxxxxx/ > https://patchwork.kernel.org/project/linux-pci/patch/20250121111421.35437-3-shradha.t@xxxxxxxxxxx/ > https://patchwork.kernel.org/project/linux-pci/patch/20250121111421.35437-4-shradha.t@xxxxxxxxxxx/ > https://patchwork.kernel.org/project/linux-pci/patch/20250121111421.35437-5-shradha.t@xxxxxxxxxxx/ > --- > Documentation/ABI/testing/debugfs-dwc-pcie | 6 ++ > .../controller/dwc/pcie-designware-debugfs.c | 70 ++++++++++++++++--- > .../pci/controller/dwc/pcie-designware-ep.c | 4 +- > .../pci/controller/dwc/pcie-designware-host.c | 54 +++++++++++++- > drivers/pci/controller/dwc/pcie-designware.h | 43 ++++++++++-- > 5 files changed, 159 insertions(+), 18 deletions(-) > > diff --git a/Documentation/ABI/testing/debugfs-dwc-pcie b/Documentation/ABI/testing/debugfs-dwc-pcie > index d3f84f46b400..bf0116012175 100644 > --- a/Documentation/ABI/testing/debugfs-dwc-pcie > +++ b/Documentation/ABI/testing/debugfs-dwc-pcie > @@ -142,3 +142,9 @@ Description: (RW) Some lanes in the event list are lane specific events. These i > events 1) - 11) and 34) - 35). > Write lane number for which counter needs to be enabled/disabled/dumped. > Read will return the current selected lane number. Lane0 is selected by default. > + > +What: /sys/kernel/debug/dwc_pcie_<dev>/ltssm_status > +Date: February 2025 > +Contact: Hans Zhang <18255117159@xxxxxxx> > +Description: (RO) Read will return the current value of the PCIe link status raw value and > + string status. > diff --git a/drivers/pci/controller/dwc/pcie-designware-debugfs.c b/drivers/pci/controller/dwc/pcie-designware-debugfs.c > index 5d883b13be84..ddfb854aa684 100644 > --- a/drivers/pci/controller/dwc/pcie-designware-debugfs.c > +++ b/drivers/pci/controller/dwc/pcie-designware-debugfs.c > @@ -465,7 +465,7 @@ static const struct file_operations dwc_pcie_counter_value_ops = { > .read = counter_value_read, > }; > > -void dwc_pcie_rasdes_debugfs_deinit(struct dw_pcie *pci) > +static void dwc_pcie_rasdes_debugfs_deinit(struct dw_pcie *pci) > { > struct dwc_pcie_rasdes_info *rinfo = pci->rasdes_info; > > @@ -473,13 +473,12 @@ void dwc_pcie_rasdes_debugfs_deinit(struct dw_pcie *pci) > mutex_destroy(&rinfo->reg_lock); > } > > -int dwc_pcie_rasdes_debugfs_init(struct dw_pcie *pci) > +static int dwc_pcie_rasdes_debugfs_init(struct dw_pcie *pci, struct dentry *dir) > { > - struct dentry *dir, *rasdes_debug, *rasdes_err_inj, *rasdes_event_counter, *rasdes_events; > + struct dentry *rasdes_debug, *rasdes_err_inj, *rasdes_event_counter, *rasdes_events; > struct dwc_pcie_rasdes_info *rasdes_info; > struct dwc_pcie_rasdes_priv *priv_tmp; > const struct dwc_pcie_vendor_id *vid; > - char dirname[DWC_DEBUGFS_BUF_MAX]; > struct device *dev = pci->dev; > int ras_cap, i, ret; > > @@ -498,12 +497,6 @@ int dwc_pcie_rasdes_debugfs_init(struct dw_pcie *pci) > if (!rasdes_info) > return -ENOMEM; > > - /* Create main directory for each platform driver */ > - snprintf(dirname, DWC_DEBUGFS_BUF_MAX, "dwc_pcie_%s", dev_name(dev)); > - dir = debugfs_create_dir(dirname, NULL); > - if (IS_ERR(dir)) > - return PTR_ERR(dir); > - > /* Create subdirectories for Debug, Error injection, Statistics */ > rasdes_debug = debugfs_create_dir("rasdes_debug", dir); > rasdes_err_inj = debugfs_create_dir("rasdes_err_inj", dir); > @@ -559,3 +552,60 @@ int dwc_pcie_rasdes_debugfs_init(struct dw_pcie *pci) > dwc_pcie_rasdes_debugfs_deinit(pci); > return ret; > } > + > +static int dwc_pcie_ltssm_status_show(struct seq_file *s, void *v) > +{ > + struct dw_pcie *pci = s->private; > + enum dw_pcie_ltssm val; > + > + val = dw_pcie_get_ltssm(pci); > + seq_printf(s, "%s (0x%02x)\n", dw_ltssm_sts_string(val), val); > + > + return 0; > +} > + > +static int dwc_pcie_ltssm_status_open(struct inode *inode, struct file *file) > +{ > + return single_open(file, dwc_pcie_ltssm_status_show, inode->i_private); > +} > + > +static const struct file_operations dwc_pcie_ltssm_status_ops = { > + .open = dwc_pcie_ltssm_status_open, > + .read = seq_read, > +}; > + > +static void dwc_pcie_ltssm_debugfs_init(struct dw_pcie *pci, struct dentry *dir) > +{ > + debugfs_create_file("ltssm_status", 0444, dir, pci, > + &dwc_pcie_ltssm_status_ops); > +} > + > +void dwc_pcie_debugfs_deinit(struct dw_pcie *pci) > +{ > + dwc_pcie_rasdes_debugfs_deinit(pci); > + debugfs_remove_recursive(pci->debugfs); > +} > + > +int dwc_pcie_debugfs_init(struct dw_pcie *pci) > +{ > + char dirname[DWC_DEBUGFS_BUF_MAX]; > + struct device *dev = pci->dev; > + struct dentry *dir; > + int ret; > + > + /* Create main directory for each platform driver */ > + snprintf(dirname, DWC_DEBUGFS_BUF_MAX, "dwc_pcie_%s", dev_name(dev)); > + dir = debugfs_create_dir(dirname, NULL); > + if (IS_ERR(dir)) > + return PTR_ERR(dir); > + > + pci->debugfs = dir; > + ret = dwc_pcie_rasdes_debugfs_init(pci, dir); > + if (ret) > + dev_dbg(dev, "rasdes debugfs init failed\n"); > + > + dwc_pcie_ltssm_debugfs_init(pci, dir); > + > + return 0; > +} > + Stray newline here. This causes: /home/nks/src/linux/.git/worktrees/linux-scratch/rebase-apply/patch:136: new blank line at EOF. + warning: 1 line adds whitespace errors. when doing git am. Also, this patch does not apply anymore, because of a conflict introduce by: 112aba9a7934 ("PCI: dwc: Remove LTSSM state test in dw_pcie_suspend_noirq()") Which added: + DW_PCIE_LTSSM_DETECT_WAIT = 0x6, to drivers/pci/controller/dwc/pcie-designware.h Kind regards, Niklas