Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2720564pxj; Mon, 31 May 2021 09:04:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMX2yRDQVvWHwudiH15qolpBLgk3ucebNm+x96xeCVJ3rXjm53D/s0qGfJ53af//2q6/Je X-Received: by 2002:a92:c689:: with SMTP id o9mr9680509ilg.297.1622477060234; Mon, 31 May 2021 09:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622477060; cv=none; d=google.com; s=arc-20160816; b=DoIaXJJF3C4eO6ficyQ6u6uWf+6imgCvEciPJ2LPfpl9XKT+iiL1HdVaXF2yqWgHZ0 Ex9wqTiGwL6qw7Pw0Lr9xDN9PRRX5GLFftsC3oFYf3XgLoqnEvzajKfWRwvWqwURz5TA ucPpk0xgDvkfcVFWyTjWdX74MAz33zC0ge0Rg70swLMpez2NuIV+Wvtd2u2ZyBlVEmLz wT99yh2tf+Q+uEWeDmjTzDGv3CIwcQvrEk+/jd/KEWUANfWjIut2Ct7FxfrWR0DNnIWt eZDR74iBKywzwiQ34bXdLlsWpCHzPMvFfnJolFm/QvxZLlkkmGBA6g0wfc7/WmSzLwh6 2Kbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ysht9L9dYJikdQy/XKTPaZTscJwCE9fGHluRtmO9Ui4=; b=XAh4v9qowwhTPWidKKh+prSbrybEFNqIsyK1+Nd153jZ6ZO8YdOcwHwWqHxFsQhQCb kIU8av0Z0QExCD8qOo9ENdqLCgSTIt5sigd16Nef5Yplmx7LQxv8li8YcZhqGZGg4Gk6 qZoX/XTi3lOmHi0Xjk8N1LdVv0AKUDLoiDFW7Cg+ddslTOZVwL6MP7iWjnf1TxLpRgd+ DkBPZIQoPa5t+gOPgv8L/phd7qfrTp3oTOwQSn+6/zn5YgTCk5jXK5mzYeRELnZ/Oj8P QiBImJLWZZ7cJ0Yq/gmuaFp5JDElM0M7g1Uz5MFRhvElQQ/tdmdiE3P370BHz8a+1ME1 7ioA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EBJSJzAV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z13si7661624ilm.140.2021.05.31.09.04.04; Mon, 31 May 2021 09:04:20 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EBJSJzAV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234608AbhEaQEm (ORCPT + 99 others); Mon, 31 May 2021 12:04:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:60974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233071AbhEaOfK (ORCPT ); Mon, 31 May 2021 10:35:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2EC2361C49; Mon, 31 May 2021 13:50:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622469044; bh=2hB1FM6ZqXS6rP1wgN1/iBHGjsSsIUt5rITLK+PQftg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EBJSJzAVAAqwPHVXZpQxMRb+PDJc5H8rfzRyAamo/3Fb+2jxnnrwMJfviLoCWSsPj nAe1YvlbFeZ/MqcLd5mK5UeWno51r3CNGyFzlAkpJ1F1wo8Wt/2nVeKUU18VzEyl4O bgb+obacin2M8crnRRger0lHvz2NcvQvbEfeZNPU5upgmaN4/QNlQ8+PgULWX+dj8b YTIOrYiXArammEpBto6ouJS8g/4kbO1wxAkSiBFX0tNbGfAWo5xrGfibD/ofYrYl6G pXUwATwqzwEqjmKnJa5yrEV6n+mkGkr0IBha2NM6LGwNvjLm4uj7Roi8GwI1BgSBjz tX/mgynY6SvGw== Received: by pali.im (Postfix) id B7C04B84; Mon, 31 May 2021 15:50:41 +0200 (CEST) Date: Mon, 31 May 2021 15:50:41 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Sergio Paracuellos Cc: "open list:MIPS" , Thomas Bogendoerfer , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Matthias Brugger , John Crispin , Bjorn Helgaas , Rob Herring , linux-staging@lists.linux.dev, Greg KH , NeilBrown , Ilya Lipnitskiy , linux-kernel , linux-pci@vger.kernel.org Subject: Re: [PATCH 2/4] MIPS: pci: Add driver for MT7621 PCIe controller Message-ID: <20210531135041.42ovpmbwuc3yfkaw@pali> References: <20210515124055.22225-1-sergio.paracuellos@gmail.com> <20210515124055.22225-3-sergio.paracuellos@gmail.com> <20210531131431.bzsvmefqdyawmeo2@pali> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday 31 May 2021 15:39:55 Sergio Paracuellos wrote: > Hi Pali, > > Thanks for your comments. > > On Mon, May 31, 2021 at 3:14 PM Pali Rohár wrote: > > > > On Saturday 15 May 2021 14:40:53 Sergio Paracuellos wrote: > > > This patch adds a driver for the PCIe controller of MT7621 SoC. > > > > > > Signed-off-by: Sergio Paracuellos > > > --- > > > arch/mips/pci/Makefile | 1 + > > > arch/mips/pci/pci-mt7621.c | 624 +++++++++++++++++++++++++++++++++++++ > > > arch/mips/ralink/Kconfig | 9 +- > > > 3 files changed, 633 insertions(+), 1 deletion(-) > > > create mode 100644 arch/mips/pci/pci-mt7621.c > > > > > > diff --git a/arch/mips/pci/Makefile b/arch/mips/pci/Makefile > > > index f3eecc065e5c..178c550739c4 100644 > > > --- a/arch/mips/pci/Makefile > > > +++ b/arch/mips/pci/Makefile > > > @@ -24,6 +24,7 @@ obj-$(CONFIG_PCI_AR2315) += pci-ar2315.o > > > obj-$(CONFIG_SOC_AR71XX) += pci-ar71xx.o > > > obj-$(CONFIG_PCI_AR724X) += pci-ar724x.o > > > obj-$(CONFIG_PCI_XTALK_BRIDGE) += pci-xtalk-bridge.o > > > +obj-$(CONFIG_PCI_MT7621) += pci-mt7621.o > > > # > > > # These are still pretty much in the old state, watch, go blind. > > > # > > > diff --git a/arch/mips/pci/pci-mt7621.c b/arch/mips/pci/pci-mt7621.c > > > new file mode 100644 > > > index 000000000000..fe1945819d25 > > > --- /dev/null > > > +++ b/arch/mips/pci/pci-mt7621.c > > ... > > > +static int mt7621_pcie_enable_ports(struct mt7621_pcie *pcie) > > > +{ > > > + struct device *dev = pcie->dev; > > > + struct mt7621_pcie_port *port; > > > + u8 num_slots_enabled = 0; > > > + u32 slot; > > > + u32 val; > > > + int err; > > > + > > > + /* Setup MEMWIN and IOWIN */ > > > + pcie_write(pcie, 0xffffffff, RALINK_PCI_MEMBASE); > > > + pcie_write(pcie, pcie->io.start, RALINK_PCI_IOBASE); > > > + > > > + list_for_each_entry(port, &pcie->ports, list) { > > > + if (port->enabled) { > > > + err = clk_prepare_enable(port->clk); > > > + if (err) { > > > + dev_err(dev, "enabling clk pcie%d\n", slot); > > > + return err; > > > + } > > > + > > > + mt7621_pcie_enable_port(port); > > > + dev_info(dev, "PCIE%d enabled\n", port->slot); > > > + num_slots_enabled++; > > > + } > > > + } > > > + > > > + for (slot = 0; slot < num_slots_enabled; slot++) { > > > + val = read_config(pcie, slot, PCI_COMMAND); > > > + val |= PCI_COMMAND_MASTER; > > > + write_config(pcie, slot, PCI_COMMAND, val); > > > > Hello! Is this part of code correct? Because it looks strange if PCIe > > controller driver automatically enables PCI bus mastering, prior device > > driver initialize itself. > > > > Moreover kernel has already function pci_set_master() for this purpose > > which is used by device drivers. > > > > So I think this code can confuse some device drivers... > > I agree that we have pci_set_master() to be used in pci device driver > code. Original controller driver set this bit for enabled slots. Since > there is no documentation at all for the PCI in this SoC I see... this is really a big problem to do any driver development... > I have > maintained the setting in the driver in a cleaner way. See original > driver code and the setting here [0]. There is no other reason than > that. I am ok with removing this from here and testing with my two > devices that everything is still ok if having this setting in the pci > controller driver is a real problem. You can run lspci -nnvv with and without PCI_COMMAND_MASTER code and then compare outputs. Device drivers for sure enable PCI_COMMAND_MASTER at the time when it is needed, so it is possible that there would be no difference in lspci output. > [0]: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git/tree/drivers/staging/mt7621-pci/pci-mt7621.c?h=v4.18#n676 > > Best regards, > Sergio Paracuellos > > > > > + /* configure RC FTS number to 250 when it leaves L0s */ > > > + val = read_config(pcie, slot, PCIE_FTS_NUM); > > > + val &= ~PCIE_FTS_NUM_MASK; > > > + val |= PCIE_FTS_NUM_L0(0x50); > > > + write_config(pcie, slot, PCIE_FTS_NUM, val); > > > + } > > > + > > > + return 0; > > > +}