Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp448578ybl; Tue, 28 Jan 2020 06:09:45 -0800 (PST) X-Google-Smtp-Source: APXvYqwYiTWxstViWEh4r89SQlF0Owwb+eXBDCXP9dVW4vI+NkOaCHxNUib2r41aT/H3Pfy4eeEX X-Received: by 2002:a9d:21f4:: with SMTP id s107mr17372044otb.102.1580220585112; Tue, 28 Jan 2020 06:09:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580220585; cv=none; d=google.com; s=arc-20160816; b=pXJiJFZVpJ00P/TOpJ3yEPN196Rtg8rfWD4DdylV2qEN70tMH/3Z5KBkNB7zxblVLO b7QQ2/fVudJuVUKjkXQRHc5QqxNuarHZrdvfySrrbE6/orl5y2saF3SiQgzFWzgkKxo7 VXeWwDJWdC6Ia/VGZRETBTTYmsXe6KvGelycRMBF5pF1SVJa5oaXaY0qDXJ/sstlBmp6 ogUe25mKz49/iIkTS+8PeExXiAuHetfn1mHYanWGuH0HF/fGTEETzt2KzDgzSGA8kkYU nBnKr3z+aqP4qrmV4O5uAeDxG32YqbUCrA7l5y/PZTBf2cKr9yjutDudLstbke/VUPL1 XNyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=rHFftXWylFY/sRogGiEmGprTl40S+WrCE7s13k04Ct4=; b=Tn84VVDN5jRhEfYT1hZmRamxKCJFt/FuPFw5NcsOX2QT93CTdeGypGTXYPFzKLZnrz yknLpvimfd2ZNlFRSjMG4L/yrdFwybcDbnlnEmWu84PSCz/2w7+dmu9SE77OX6BSzVeJ rq84YTwk/IJS9otghUUDerFo1bllhvyjawl627gavZWGEZpzYCNT1gdSWM09FPIoHvhL YB6azQeXVsaQs1Z69o6z2gfRNw/rwB2E+cN+AqW52+/yTWpcyWs0aruvz/qpDkGNWCvV h3ENyzxgvI2ZWwwz9KWM7urcTZ7yWQP1H/i73VVNHkgQt7SqHCXWdBJAbCT3Ggmr64aK +8gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2UXpA6vi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id u3si4913671oif.167.2020.01.28.06.09.07; Tue, 28 Jan 2020 06:09:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2UXpA6vi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728102AbgA1OEb (ORCPT + 99 others); Tue, 28 Jan 2020 09:04:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:51638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728070AbgA1OE1 (ORCPT ); Tue, 28 Jan 2020 09:04:27 -0500 Received: from localhost (173-25-83-245.client.mchsi.com [173.25.83.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 212012468F; Tue, 28 Jan 2020 14:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580220266; bh=ub4UwKqrZMgy6+sqrMhH+mrNyxJs1wj0mog/wg3Wxx0=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=2UXpA6vi6H0YSp/fpxanVwcpc42jUmIi3kYBrYYIq/in9lxz55IcxTVto6yR3Qns0 zTf0Qdk2pZcJzQ+ZCjDYagC9ZENOLyQudDxjhQc0n4CwKAJ38zq+TdHLcBE/OuOwMK askCzG5zDppDZuwGYKJ+jhu/ibUp1dTtJS5tGHcA= Date: Tue, 28 Jan 2020 08:04:24 -0600 From: Bjorn Helgaas To: Bharat Kumar Gogada Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, rgummal@xilinx.com Subject: Re: [PATCH v4 2/2] PCI: xilinx-cpm: Add Versal CPM Root Port driver Message-ID: <20200128140424.GA150109@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1580215483-8835-3-git-send-email-bharat.kumar.gogada@xilinx.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 28, 2020 at 06:14:43PM +0530, Bharat Kumar Gogada wrote: > - Add support for Versal CPM as Root Port. > - The Versal ACAP devices include CCIX-PCIe Module (CPM). The integrated > block for CPM along with the integrated bridge can function > as PCIe Root Port. > - CPM Versal uses GICv3 ITS feature for achieving assigning MSI/MSI-X > vectors and handling MSI/MSI-X interrupts. > - Bridge error and legacy interrupts in Versal CPM are handled using > Versal CPM specific MISC interrupt line. > > Changes v4: > - change commit subject. > - Remove unnecessary comments and type cast. > - Added comments for CPM block register access using readl/writel. > > Signed-off-by: Bharat Kumar Gogada > ... > +static bool xilinx_cpm_pcie_valid_device(struct pci_bus *bus, > + unsigned int devfn) > +{ > + struct xilinx_cpm_pcie_port *port = bus->sysdata; > + > + /* Only one device down on each root port */ > + if (bus->number == port->root_busno && devfn > 0) > + return false; This whole *_valid_device() thing is a mess. We shouldn't need it at all. But if we *do* need it, I don't think you should check the entire devfn because that means you can't attach a multifunction device. Several other drivers with similar *_valid_device() implementations check only PCI_SLOT(): dw_pcie_valid_device() advk_pcie_valid_device() pci_dw_valid_device() altera_pcie_valid_device() mobiveil_pcie_valid_device() rockchip_pcie_valid_device() Even checking just PCI_SLOT() is problematic because I think an ARI device with more than 8 functions will not work correctly. What exactly happens if you omit this function, i.e., if we just go ahead and attempt config accesses when the device is not present? We *should* get something like an Unsupported Request completion, and that *should* be a recoverable error. Most hardware turns this error into read data of 0xffffffff. The OS should be able to figure out that there's no device there and continue with no ill effects. > + return true; > +} > + > +/** > + * xilinx_cpm_pcie_map_bus - Get configuration base > + * @bus: PCI Bus structure > + * @devfn: Device/function > + * @where: Offset from base > + * > + * Return: Base address of the configuration space needed to be > + * accessed. > + */ > +static void __iomem *xilinx_cpm_pcie_map_bus(struct pci_bus *bus, > + unsigned int devfn, int where) > +{ > + struct xilinx_cpm_pcie_port *port = bus->sysdata; > + int relbus; > + > + if (!xilinx_cpm_pcie_valid_device(bus, devfn)) > + return NULL; > + > + relbus = (bus->number << ECAM_BUS_NUM_SHIFT) | > + (devfn << ECAM_DEV_NUM_SHIFT); > + > + return port->reg_base + relbus + where; > +} > + > +/* PCIe operations */ > +static struct pci_ops xilinx_cpm_pcie_ops = { > + .map_bus = xilinx_cpm_pcie_map_bus, > + .read = pci_generic_config_read, > + .write = pci_generic_config_write, > +};