Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2054354rda; Tue, 24 Oct 2023 10:53:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyCaZ2YtOxGFr8XTxBK1WXrk0TKEt1QfOu06wkBs5kINeioSEuGyp28IIG4LzAg70tLJaQ X-Received: by 2002:a17:903:1cb:b0:1ca:2ec4:7f38 with SMTP id e11-20020a17090301cb00b001ca2ec47f38mr11746524plh.17.1698170002623; Tue, 24 Oct 2023 10:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698170002; cv=none; d=google.com; s=arc-20160816; b=VNqQBth4+Q6a4tDzH2o2XFznMPtc6HeYdHlAsvDbzi41Y122eHZ7aYa5iYctEfsdY2 HzmQPFyJ1SJ4NRakXfSFH06OMOhkcfdmzbbvZBbBX81jh+qrfuVmS17TGOFZ1Hey2FPB cRVXD3gDpCeokhCGVcXB6NkhLYxYAI+a5BAr/WS4lL8cu3GEr0IAqFj2Ym2IbEMcoR7C PXgoab1UCYBW/LKKlPRu2LuED4xPF6nOpmBxfMF1R+CkPKHFH3FMgfUlC5KBgAwu3ZrM wDCCklQ0BBa/svUXzF3pbJVkoRdC1id2yKohQR1KEUxUaiQwmKsSzUbztUhg7LqQmvi6 Kacg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=9PIE5feH5zszsUjw0NVuxx5Sem1RsriqdguV/hjyLgA=; fh=edLK6CrLZnoyngH4Z0tRvVYoYKorJO0VIuKCSDp0nUE=; b=Wk/06rH0HtieJBieVi0wMJVdqK6U5r60GxUWGMZ5PAX4LcvtI5DBGCOH8FMqqqDu5G 5Z0bXQZNsNwL8wCDKkGoIyhfG/2j5T9aremA5/JdZc4ylYihwD8ZQXeGx3InEzbCIQUh abmHa35B/9rYUz2V+7XGbiro3xomFiyr9KKbDCESFGpfi4893qkrSz56LwFpWEC0I8ef UVI1YpX3j56uEsw2kXCo+WtWrVg0KcgqSa7WKCFBORZmuzZk3Mbf25XZGVqgMEm02RuS +N0sPuRVhqCt6m52+xdiY3TDOlx4UR51U00vnhEIqykKs6USO9MFiL+ex7vwiafPmD/M ni6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=szEiV2H2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id b13-20020a170902d30d00b001c78345f376si8508887plc.241.2023.10.24.10.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 10:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=szEiV2H2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DB16680301E3; Tue, 24 Oct 2023 10:53:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343823AbjJXRw7 (ORCPT + 99 others); Tue, 24 Oct 2023 13:52:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234315AbjJXRw6 (ORCPT ); Tue, 24 Oct 2023 13:52:58 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8192810D3; Tue, 24 Oct 2023 10:52:56 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEBD1C433C7; Tue, 24 Oct 2023 17:52:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698169976; bh=KUF7e+OQ3Cmah38SMoodhEwyDPQhM9qKHEvTf9JRMLA=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=szEiV2H2y6V69DSMmIjRsYCrp7HLNV/OYuRJb36ATW03CYFhw7JwfTZ7CE3WiiunT IoMGGD+iW3gjfdM5coQnjSmuYY57kaitDfZG+vVWYuEmpF/W/TrEudTZP5J3hDKRpz nTzMTiUHC3esNZ+ZqhB+LxOwRpxcbNgCohlcUegpEXuT3LncyOCpGY3CCJUvOThe/h hyN+7Dv1qPOApEdX2Xif3Rbb72hl53NwpT/I2Bf0OHRQZaNG0VYw8ZDsqi4wy2zq2P ixonxQTg+4Y7pKbQo8XdnBSzp/FiAHOgGLpH/jRqE2WRPdazUQFCecbe7oiv5iB+zU xqeGovmWrEOTg== Date: Tue, 24 Oct 2023 12:52:53 -0500 From: Bjorn Helgaas To: Minda Chen Cc: Conor Dooley , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Lorenzo Pieralisi , Daire McNamara , Emil Renner Berthing , Krzysztof Kozlowski , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-pci@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Philipp Zabel , Mason Huo , Leyfoon Tan , Kevin Xie Subject: Re: [PATCH v9 19/20] PCI: starfive: Add JH7110 PCIe controller Message-ID: <20231024175253.GA1662387@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231020104341.63157-20-minda.chen@starfivetech.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 10:53:20 -0700 (PDT) On Fri, Oct 20, 2023 at 06:43:40PM +0800, Minda Chen wrote: > Add StarFive JH7110 SoC PCIe controller platform > driver codes, JH7110 with PLDA host PCIe core. Wrap all your commit logs to fill about 75 columns (as suggested before). "git log" adds a few spaces, so if you fill to 75 columns, the result will still fit in a default 80 column window. > +config PCIE_STARFIVE_HOST > + tristate "StarFive PCIe host controller" > + depends on OF && PCI_MSI > + select PCIE_PLDA_HOST > + help > + Say Y here if you want to support the StarFive PCIe controller > + in host mode. StarFive PCIe controller uses PLDA PCIe > + core. Add blank line between paragraphs. Wrap to fill 75-78 columns. > + If you choose to build this driver as module it will > + be dynamically linked and module will be called > + pcie-starfive.ko > +++ b/drivers/pci/controller/plda/pcie-plda.h > @@ -6,14 +6,26 @@ > #ifndef _PCIE_PLDA_H > #define _PCIE_PLDA_H > > +#include I don't think you need to #include this. In this file you only use a pointer to struct phy, so declaring the struct should be enough, e.g., struct phy; You will have to #include it in pcie-starfive.c where you actually *use* phy, of course. > +#define CONFIG_SPACE_ADDR 0x1000u This looks like an *offset* that you add to ->bridge_addr. Adding two addresses together doesn't really make sense. > +static int starfive_pcie_config_write(struct pci_bus *bus, unsigned int devfn, > + int where, int size, u32 value) > +{ > + if (starfive_pcie_hide_rc_bar(bus, devfn, where)) > + return PCIBIOS_BAD_REGISTER_NUMBER; I think this should probably return PCIBIOS_SUCCESSFUL. There's nothing wrong with the register number; you just want to pretend that it's hardwired to zero. That means ignore writes and always return 0 for reads. > + return pci_generic_config_write(bus, devfn, where, size, value); > +} > + > +static int starfive_pcie_config_read(struct pci_bus *bus, unsigned int devfn, > + int where, int size, u32 *value) > +{ > + if (starfive_pcie_hide_rc_bar(bus, devfn, where)) > + return PCIBIOS_BAD_REGISTER_NUMBER; Set *value to zero and return PCIBIOS_SUCCESSFUL. > + return pci_generic_config_read(bus, devfn, where, size, value); > +} > + > +static int starfive_pcie_parse_dt(struct starfive_jh7110_pcie *pcie, struct device *dev) 95% of this driver (and the rest of drivers/pci) is wrapped to fit in 80 columns, e.g., static int starfive_pcie_parse_dt(struct starfive_jh7110_pcie *pcie, struct device *dev) > + domain_nr = of_get_pci_domain_nr(dev->of_node); > + > + if (domain_nr < 0 || domain_nr > 1) > + return dev_err_probe(dev, -ENODEV, > + "failed to get valid pcie id\n"); "id" is too generic and doesn't hint about where the problem is. Update the message ("pcie id") to mention "domain" so it corresponds with the source ("linux,pci-domain" from DT). > + ret = reset_control_deassert(pcie->resets); > + if (ret) { > + clk_bulk_disable_unprepare(pcie->num_clks, pcie->clks); > + dev_err_probe(dev, ret, "failed to resets\n"); "failed to ... resets" is missing a word. "Failed to deassert resets", I guess? > + /* Ensure that PERST has been asserted for at least 100 ms, > + * the sleep value is T_PVPERL from PCIe CEM spec r2.0 (Table 2-4) > + */ Use multiline comment formatting (also below): /* * Ensure ... */ > + msleep(100); > + if (pcie->reset_gpio) > + gpiod_set_value_cansleep(pcie->reset_gpio, 0); > + > + /* As the requirement in PCIe base spec r6.0, system (<=5GT/s) must > + * wait a minimum of 100 ms following exit from a conventional reset > + * before sending a configuration request to the device. Mention sec 6.6.1, where (I think) this value comes from. Eventually we should make a #define for this because it's not specific to any one PCIe controller. > + msleep(100); > + > + if (starfive_pcie_host_wait_for_link(pcie)) > + dev_info(dev, "port link down\n"); > + > + return ret; We know the value here, so return it explicitly: return 0; > +static int starfive_pcie_suspend_noirq(struct device *dev) > +{ > + struct starfive_jh7110_pcie *pcie = dev_get_drvdata(dev); > + > + if (!pcie) > + return 0; How could it happen that "pcie" is zero? I think it could only happen if there were a driver bug or a memory corruption. Either way, we should remove the check so we take a NULL pointer fault and find out about the problem. > +static int starfive_pcie_resume_noirq(struct device *dev) > +{ > + struct starfive_jh7110_pcie *pcie = dev_get_drvdata(dev); > + int ret; > + > + ret = starfive_pcie_enable_phy(dev, &pcie->plda); > + if (ret) > + return ret; > + > + ret = clk_bulk_prepare_enable(pcie->num_clks, pcie->clks); > + if (ret) { > + dev_err(dev, "failed to enable clocks\n"); > + starfive_pcie_disable_phy(&pcie->plda); > + return ret; > + } > + > + return ret; return 0; Bjorn