Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754398AbcCEPy5 (ORCPT ); Sat, 5 Mar 2016 10:54:57 -0500 Received: from mail-by2on0059.outbound.protection.outlook.com ([207.46.100.59]:54784 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752592AbcCEPyu (ORCPT ); Sat, 5 Mar 2016 10:54:50 -0500 Authentication-Results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=caviumnetworks.com; Date: Sat, 5 Mar 2016 18:54:09 +0300 From: Yury Norov To: David Daney CC: , , Bjorn Helgaas , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Will Deacon , , , Dann Frazier , David Daney Subject: Re: [PATCH v7 2/3] pci, pci-thunder-pem: Add PCIe host driver for ThunderX processors. Message-ID: <20160305155409.GA2532@yury-N73SV> References: <1457130708-3231-1-git-send-email-ddaney.cavm@gmail.com> <1457130708-3231-3-git-send-email-ddaney.cavm@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <1457130708-3231-3-git-send-email-ddaney.cavm@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: DB4PR07CA018.eurprd07.prod.outlook.com (10.242.229.28) To DM2PR07MB624.namprd07.prod.outlook.com (10.141.177.154) X-Microsoft-Exchange-Diagnostics: 1;DM2PR07MB624;2:ajmMHa4hS8OAECwqMgHZebdcS7Xfo+VeK7gELOeY8oUZwTGcEAIIAJkpj10AYAhcFdHpJN3lapgpJz0dhEioTVDk+0gWhdKhcVNdNHhUO9n1PS/JyRRIAAsPD8xuNiD6keICJczRx1+tpB2R0ZIN/Q==;3:t21JrH2y7gNXO7MCdjr0EdIckQQ+HZAIQ8oCfDG2zwtlHPMBgM+3nnmrguFYRSHufbsXW1Zdmfe/R1SzmFzWlPYm7068aYORWh7ItbNIumrBi4UN+pjzI3CNBN6bZyB7ZB19OVXzQghqzFnjXFzDsDnKdjmA6RIami1mr5y/hNM=;25:MVWLZ7iODq/ViaPaz80P8Lj9mmuTYa2Y0l3fOu2GgeJgAJMJ5JCbeXYdqZdvRqNa6NE6fXF/OpApvTw4D6LbOWAOU1bKVOiUK4y45c575RDVZeuUaia/yYg4gXoMSiT+p8SQAkoWZzdmbS8v3XH2F3+8cJ6d0/90cIsGnewSYfKRlr4nUNi5fRcf8CdWx2M8o4nsQnmJd3ZyUsvZpAkzEGLIEEf5qaHtlgV4i5i1l7Czwf3KExtmFo965PdJwKVH+GQf+iubRfFUq3YKO6Sikvb9d1Xjy6JUmLGG1luajXtoBP53L0Mx7bdiWk4N5hEkoen0SwycbJD2wvI5LZNTNw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(42139001);SRVR:DM2PR07MB624; X-MS-Office365-Filtering-Correlation-Id: 8004b00e-4e66-4358-fcbe-08d3450e79d5 X-Microsoft-Exchange-Diagnostics: 1;DM2PR07MB624;20:cMFmo+VMmhvy46mkglR469K+gp9da4W1Iw5IcPS2SgA4pk4bZP7JX5R5vychA20AdZvFmZ9ON2aUo6CwyqPpRw8xynwCCjHl4eFnlLVQVAbdPSSvPubxtpyk61KKn4QmsAPg3+xiTWMVcCuuEhCc0bCNJBh2ldLjiqvUv5LOGqKRcGZNNrCPLJ6Oc5a8EM1qVt+GnrnR8rMhzLUX3voapK9q7ODadClByHNidJhF+XIsZfHvmCRmYpUTE9OpHCQgUw6Op6rv0vzYzBUYYYGM6KXelWl1A30H5PsqMjbH6qh+Yi8uzvyQeTL0H3ACjxd9Ywg+vjfzJAGa3QyumyiBltJzG0WYeVD6biK9NQ1gGDu79PAZu+sAwL9DvMGVZjPE553i7kwJtWemPoqgABh/tFApi0WLkP+yyY4DiZ9rNyBGnDBehjHRI1cMrywzl28L3llQNIAMsIirTxhf2NsLyNgOUdSpVdxDyNaGcTKjlTc2lAgUjVkpLkYuKVl4G4a9ERVkSAb3orN8nUC8IqvxsHz67xsy4QkhOWROqiLTuWIeS3eLG0k42q7RDp9UKh6UpXj8LA24dQ4mh4p7Y7cStOSLgAKEsUnLIHL9EnN8QtA= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046);SRVR:DM2PR07MB624;BCL:0;PCL:0;RULEID:;SRVR:DM2PR07MB624; X-Microsoft-Exchange-Diagnostics: 1;DM2PR07MB624;4:0HcXNvG3uXCk8VIoQoyEvYCzElgkaNbtuws56DiikMGUrRyUqPA1E6aO0P5RThObooX/J/iJDAGzZDslHJhvST5euJtqAFIHyle4iHs7uRWmJ9aUZc+4/IECz2YKh4ZO6eMUfMn5rNNrLzBDCk7EiDSNdiu7nr7MSit5du9a7gz/PKeYkWcU5faKCJi5bJOi9Y4qZDOFUpkGrrsellBbwdUXebQF9qDTzZ543xOwv7nIs3pao9xDxtlJfqeDmiou+DpXJy75ZVRMKYmQCoT23MUxABLmGSNELtT4aONuWadkQPJNjG5AsMhN9PJnxudMvznFhWo6NmVflditBdb2JpgspIY+ff7eaxen5mpEVV4Jm20zKGtGYCg+aO1C/TRO X-Forefront-PRVS: 087223B4DA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6069001)(6009001)(24454002)(19580395003)(575784001)(46406003)(15975445007)(47776003)(1720100001)(5008740100001)(586003)(5004730100002)(3846002)(87976001)(50466002)(230783001)(2950100001)(1096002)(1076002)(83506001)(54356999)(6116002)(76176999)(76506005)(122386002)(23726003)(77096005)(4326007)(40100003)(4001350100001)(92566002)(189998001)(33716001)(33656002)(97756001)(2906002)(110136002)(42186005)(50986999)(81166005)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR07MB624;H:localhost;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR07MB624;23:8zG6QZl914IaGw9Eo0KuqZXBwL1ZmotjkYFvsEPucA?= =?us-ascii?Q?KKo3u+PAo3GvVrThwWutfZzQszghHomd6CaZSxlv1bXfISLG29oLT/aAa83K?= =?us-ascii?Q?R+xOlpoFmVPXt4WgDaMCAXmhjtDpqf6FjVSVObemm3il0l4FrXP+J7wdq363?= =?us-ascii?Q?PtrwoNckq8UZNwRyyAQIwJqMs4pSKrLabHyT7ftFlp2Q/uEoGc4zrLlTXKW4?= =?us-ascii?Q?EOkgJ31DGxCm6QD7wOCUMe4tRI+Hv9db37hmQ6CTd3/qroUBCCzKfF1C/Idz?= =?us-ascii?Q?qoxn/ASep9Nq/oOLd/P+JVJnDQbPbE8dMfhJk4BpueJhuk+t4s+A9SGLrvfF?= =?us-ascii?Q?X66xxfcKcXfKb4mpCOiQNCpP2tW1rImwmRGWAJMpArUkqmd89sXx/9xQRA60?= =?us-ascii?Q?EvSgFxn6l8wO/zO0HhMGtGFHIWwBX+9vIBqVfOyCrvevhev7Mkk2n8/T6XRR?= =?us-ascii?Q?fmZS5cOkLZVn7tUAuZXsg/WB1NcVUg5KiRhuiFk0RWSSyE/O6y+jjku/QKBQ?= =?us-ascii?Q?qS26ydmKcxPy2sb8MVWKCce2SN7L+1CIMMrq18z/WXayxEkKeeEBYuu3wMUP?= =?us-ascii?Q?xZEePylZwcRjp0MVNLSJwbf66TLIPUdG7+/pO0UfnNvWvqHm031WFZzTlELg?= =?us-ascii?Q?WjkET9j1VswlKwge0YBjB808tQlIcyww2XAd0XbkgrjfXVxF9rwDEwSCzCK3?= =?us-ascii?Q?4Hzn2LrU2ZTQ8f5nWNYgLkXYdcrq/yTnXt/98K9RhFgcZ8gVYr0vvlfSyEC4?= =?us-ascii?Q?meih3YSuBlslNmPZPmAVguAXxHU4Pz3s6EiiEdLBIFQhf0S7FdGJQoGwtOBy?= =?us-ascii?Q?A1twPyjPQAnqHyweXA1sPraF/Yp18939oRnDHDPc76mLKmhSXpZcA/A59Ugi?= =?us-ascii?Q?qZH5rsjocM6tlWd5PE2Ziub67Pr61KarFBRRYy9BBij4d8Ou5bXtxz1BlR18?= =?us-ascii?Q?uB1W6o1WbESwkTS53zy+Hr8jhV7axbNUbkwyKoB6BjdDKVfHyFPdVUDZeEPM?= =?us-ascii?Q?ppf0IjNDFK91Pt2tWvho5aOMveuTGdwvh0Wlu90DqFX0GXpcyRQMT3z6AHBw?= =?us-ascii?Q?7IUS26CkyPOZWhaKoTxKb+1CwJXTbGoXsLKIlgZKPiTUflAQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR07MB624;5:LS1OaeihO6aa8cU9asYLZrGxocLIkolvpHNIKqOQhYJwccC61HAEoZ0kcgtUld+NfhjdsT/r/GTf9fwrtCFIvh9L9ljvvvzP4GAoMzdFNqfkgT7zqekJCofbR6eUvWN83Be2VQigLkwCQD4TumxyEA==;24:2s6tafYqAaPdBj31EpaZzNRHHTGjEjK7w8LxLMyIRogRQeLIob1SX3JLFs2DqjbrjsqvpyJRzDBfkejWNPW3rUIASR4xS+zVenOkwT5r1rw= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Mar 2016 15:54:46.1391 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR07MB624 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 15977 Lines: 497 Hi David, On Fri, Mar 04, 2016 at 02:31:47PM -0800, David Daney wrote: > From: David Daney > > The root complexes used to access off-chip PCIe devices (called PEM > units in the hardware manuals) on some Cavium ThunderX processors > require quirky access methods for the config space of the PCIe bridge. > Add a driver to provide these config space accessor functions. The > pci-host-common code is used to configure the PCI machinery. > > Signed-off-by: David Daney > Acked-by: Rob Herring > Acked-by: Arnd Bergmann > --- > .../devicetree/bindings/pci/pci-thunder-pem.txt | 43 +++ > MAINTAINERS | 8 + > drivers/pci/host/Kconfig | 7 + > drivers/pci/host/Makefile | 1 + > drivers/pci/host/pci-thunder-pem.c | 347 +++++++++++++++++++++ > 5 files changed, 406 insertions(+) > create mode 100644 Documentation/devicetree/bindings/pci/pci-thunder-pem.txt > create mode 100644 drivers/pci/host/pci-thunder-pem.c > > diff --git a/Documentation/devicetree/bindings/pci/pci-thunder-pem.txt b/Documentation/devicetree/bindings/pci/pci-thunder-pem.txt > new file mode 100644 > index 0000000..f131fae > --- /dev/null > +++ b/Documentation/devicetree/bindings/pci/pci-thunder-pem.txt > @@ -0,0 +1,43 @@ > +* ThunderX PEM PCIe host controller > + > +Firmware-initialized PCI host controller found on some Cavium > +ThunderX processors. > + > +The properties and their meanings are identical to those described in > +host-generic-pci.txt except as listed below. > + > +Properties of the host controller node that differ from > +host-generic-pci.txt: > + > +- compatible : Must be "cavium,pci-host-thunder-pem" > + > +- reg : Two entries: First the configuration space for down > + stream devices base address and size, as accessed > + from the parent bus. Second, the register bank of > + the PEM device PCIe bridge. > + > +Example: > + > + pci@87e0,c2000000 { > + compatible = "cavium,pci-host-thunder-pem"; > + device_type = "pci"; > + msi-parent = <&its>; > + msi-map = <0 &its 0x10000 0x10000>; > + bus-range = <0x8f 0xc7>; > + #size-cells = <2>; > + #address-cells = <3>; > + > + reg = <0x8880 0x8f000000 0x0 0x39000000>, /* Configuration space */ > + <0x87e0 0xc2000000 0x0 0x00010000>; /* PEM space */ > + ranges = <0x01000000 0x00 0x00020000 0x88b0 0x00020000 0x00 0x00010000>, /* I/O */ > + <0x03000000 0x00 0x10000000 0x8890 0x10000000 0x0f 0xf0000000>, /* mem64 */ > + <0x43000000 0x10 0x00000000 0x88a0 0x00000000 0x10 0x00000000>, /* mem64-pref */ > + <0x03000000 0x87e0 0xc2f00000 0x87e0 0xc2000000 0x00 0x00100000>; /* mem64 PEM BAR4 */ > + > + #interrupt-cells = <1>; > + interrupt-map-mask = <0 0 0 7>; > + interrupt-map = <0 0 0 1 &gic0 0 0 0 24 4>, /* INTA */ > + <0 0 0 2 &gic0 0 0 0 25 4>, /* INTB */ > + <0 0 0 3 &gic0 0 0 0 26 4>, /* INTC */ > + <0 0 0 4 &gic0 0 0 0 27 4>; /* INTD */ > + }; > diff --git a/MAINTAINERS b/MAINTAINERS > index 370b3cb..cef8dda 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -8407,6 +8407,14 @@ L: linux-arm-msm@vger.kernel.org > S: Maintained > F: drivers/pci/host/*qcom* > > +PCIE DRIVER FOR CAVIUM THUNDERX > +M: David Daney > +L: linux-pci@vger.kernel.org > +L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) > +S: Supported > +F: Documentation/devicetree/bindings/pci/pci-thunder-* > +F: drivers/pci/host/pci-thunder-* > + > PCMCIA SUBSYSTEM > P: Linux PCMCIA Team > L: linux-pcmcia@lists.infradead.org > diff --git a/drivers/pci/host/Kconfig b/drivers/pci/host/Kconfig > index cd5dfbb..c642797 100644 > --- a/drivers/pci/host/Kconfig > +++ b/drivers/pci/host/Kconfig > @@ -196,4 +196,11 @@ config PCIE_QCOM > PCIe controller uses the Designware core plus Qualcomm-specific > hardware wrappers. > > +config PCI_HOST_THUNDER_PEM > + bool "Cavium Thunder PCIe controller to off-chip devices" > + depends on OF && ARM64 > + select PCI_HOST_COMMON > + help > + Say Y here if you want PCIe support for CN88XX Cavium Thunder SoCs. > + > endmenu > diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile > index 3b24af8..8903172 100644 > --- a/drivers/pci/host/Makefile > +++ b/drivers/pci/host/Makefile > @@ -23,3 +23,4 @@ obj-$(CONFIG_PCIE_ALTERA) += pcie-altera.o > obj-$(CONFIG_PCIE_ALTERA_MSI) += pcie-altera-msi.o > obj-$(CONFIG_PCI_HISI) += pcie-hisi.o > obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o > +obj-$(CONFIG_PCI_HOST_THUNDER_PEM) += pci-thunder-pem.o > diff --git a/drivers/pci/host/pci-thunder-pem.c b/drivers/pci/host/pci-thunder-pem.c > new file mode 100644 > index 0000000..4b939c7 > --- /dev/null > +++ b/drivers/pci/host/pci-thunder-pem.c > @@ -0,0 +1,347 @@ > +/* > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program. If not, see . > + * > + * Copyright (C) 2015 - 2016 Cavium, Inc. > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#include "pci-host-common.h" > + > +#define PEM_CFG_WR 0x28 > +#define PEM_CFG_RD 0x30 > + > +struct thunder_pem_pci { > + struct gen_pci gen_pci; > + u32 ea_entry[3]; > + void __iomem *pem_reg_base; > +}; > + > +static void __iomem *thunder_pem_map_bus(struct pci_bus *bus, > + unsigned int devfn, int where) > +{ > + struct gen_pci *pci = bus->sysdata; > + resource_size_t idx = bus->number - pci->cfg.bus_range->start; > + > + return pci->cfg.win[idx] + ((devfn << 16) | where); > +} > + > +static int thunder_pem_bridge_read(struct pci_bus *bus, unsigned int devfn, > + int where, int size, u32 *val) > +{ > + u64 read_val; > + struct thunder_pem_pci *pem_pci; > + struct gen_pci *pci = bus->sysdata; > + > + pem_pci = container_of(pci, struct thunder_pem_pci, gen_pci); > + > + if (devfn != 0 || where >= 2048) { > + *val = ~0; > + return PCIBIOS_DEVICE_NOT_FOUND; > + } > + > + /* > + * 32-bit accesses only. Write the address to the low order > + * bits of PEM_CFG_RD, then trigger the read by reading back. > + * The config data lands in the upper 32-bits of PEM_CFG_RD. > + */ > + read_val = where & ~3ull; > + writeq(read_val, pem_pci->pem_reg_base + PEM_CFG_RD); > + read_val = readq(pem_pci->pem_reg_base + PEM_CFG_RD); > + read_val >>= 32; > + > + /* > + * The config space contains some garbage, fix it up. Also > + * synthesize an EA capability for the BAR used by MSI-X. > + */ > + switch (where & ~3) { > + case 0x40: > + read_val &= 0xffff00ff; > + read_val |= 0x00007000; /* Skip MSI CAP */ > + break; > + case 0x70: /* Express Cap */ > + /* PME interrupt on vector 2*/ > + read_val |= (2u << 25); > + break; > + case 0xb0: /* MSI-X Cap */ > + /* TableSize=4, Next Cap is EA */ > + read_val &= 0xc00000ff; > + read_val |= 0x0003bc00; > + break; > + case 0xb4: > + /* Table offset=0, BIR=0 */ > + read_val = 0x00000000; > + break; > + case 0xb8: > + /* BPA offset=0xf0000, BIR=0 */ > + read_val = 0x000f0000; > + break; > + case 0xbc: > + /* EA, 1 entry, no next Cap */ > + read_val = 0x00010014; > + break; > + case 0xc0: > + /* DW2 for type-1 */ > + read_val = 0x00000000; > + break; > + case 0xc4: > + /* Entry BEI=0, PP=0x00, SP=0xff, ES=3 */ > + read_val = 0x80ff0003; > + break; > + case 0xc8: > + read_val = pem_pci->ea_entry[0]; > + break; > + case 0xcc: > + read_val = pem_pci->ea_entry[1]; > + break; > + case 0xd0: > + read_val = pem_pci->ea_entry[2]; > + break; > + default: > + break; > + } > + read_val >>= (8 * (where & 3)); > + switch (size) { > + case 1: > + read_val &= 0xff; > + break; > + case 2: > + read_val &= 0xffff; > + break; > + default: > + break; > + } > + *val = read_val; > + return PCIBIOS_SUCCESSFUL; > +} > + > +static int thunder_pem_config_read(struct pci_bus *bus, unsigned int devfn, > + int where, int size, u32 *val) > +{ > + struct gen_pci *pci = bus->sysdata; > + > + if (bus->number < pci->cfg.bus_range->start || > + bus->number > pci->cfg.bus_range->end) > + return PCIBIOS_DEVICE_NOT_FOUND; > + > + /* > + * The first device on the bus is the PEM PCIe bridge. > + * Special case its config access. > + */ > + if (bus->number == pci->cfg.bus_range->start) > + return thunder_pem_bridge_read(bus, devfn, where, size, val); > + > + return pci_generic_config_read(bus, devfn, where, size, val); > +} > + > +/* > + * Some of the w1c_bits below also include read-only or non-writable > + * reserved bits, this makes the code simpler and is OK as the bits > + * are not affected by writing zeros to them. > + */ > +static u32 thunder_pem_bridge_w1c_bits(int where) > +{ > + u32 w1c_bits = 0; > + > + switch (where & ~3) { > + case 0x04: /* Command/Status */ > + case 0x1c: /* Base and I/O Limit/Secondary Status */ > + w1c_bits = 0xff000000; > + break; > + case 0x44: /* Power Management Control and Status */ > + w1c_bits = 0xfffffe00; > + break; > + case 0x78: /* Device Control/Device Status */ > + case 0x80: /* Link Control/Link Status */ > + case 0x88: /* Slot Control/Slot Status */ > + case 0x90: /* Root Status */ > + case 0xa0: /* Link Control 2 Registers/Link Status 2 */ > + w1c_bits = 0xffff0000; > + break; > + case 0x104: /* Uncorrectable Error Status */ > + case 0x110: /* Correctable Error Status */ > + case 0x130: /* Error Status */ > + case 0x160: /* Link Control 4 */ This patchset is full of magic numbers. For better readability and portability, it's better to declare all that as macro: #define LINK_CONTROL_4 0x160 If there's some specific reason to use numbers, I think, it should be explained. > + w1c_bits = 0xffffffff; > + break; > + default: > + break; > + } > + return w1c_bits; > +} > + > +static int thunder_pem_bridge_write(struct pci_bus *bus, unsigned int devfn, > + int where, int size, u32 val) > +{ > + struct gen_pci *pci = bus->sysdata; > + struct thunder_pem_pci *pem_pci; > + u64 write_val, read_val; > + u32 mask = 0; > + > + pem_pci = container_of(pci, struct thunder_pem_pci, gen_pci); > + > + if (devfn != 0 || where >= 2048) > + return PCIBIOS_DEVICE_NOT_FOUND; > + > + /* > + * 32-bit accesses only. If the write is for a size smaller > + * than 32-bits, we must first read the 32-bit value and merge > + * in the desired bits and then write the whole 32-bits back > + * out. > + */ > + switch (size) { > + case 1: > + read_val = where & ~3ull; > + writeq(read_val, pem_pci->pem_reg_base + PEM_CFG_RD); > + read_val = readq(pem_pci->pem_reg_base + PEM_CFG_RD); > + read_val >>= 32; > + mask = ~(0xff << (8 * (where & 3))); I'm pretty sure, there's no any rocket science, but it's hard to understand what happens here. What is 8? Bits in byte? Bytes in word? Anything PCI-specific? Moreover, you repeat this line several times here (though little modified). Maybe it deserves to be wrapped by some explaining macro? > + read_val &= mask; > + val = (val & 0xff) << (8 * (where & 3)); > + val |= (u32)read_val; > + break; > + case 2: Case 1 and 2 are looking very similar. Is it possible to wrap them? For now it looks like code duplication. > + read_val = where & ~3ull; > + writeq(read_val, pem_pci->pem_reg_base + PEM_CFG_RD); > + read_val = readq(pem_pci->pem_reg_base + PEM_CFG_RD); > + read_val >>= 32; > + mask = ~(0xffff << (8 * (where & 3))); > + read_val &= mask; > + val = (val & 0xffff) << (8 * (where & 3)); > + val |= (u32)read_val; > + break; > + default: > + break; > + } > + > + /* > + * By expanding the write width to 32 bits, we may > + * inadvertently hit some W1C bits that were not intended to > + * be written. Calculate the mask that must be applied to the > + * data to be written to avoid these cases. > + */ > + if (mask) { > + u32 w1c_bits = thunder_pem_bridge_w1c_bits(where); > + > + if (w1c_bits) { > + mask &= w1c_bits; > + val &= ~mask; > + } > + } > + > + /* > + * Low order bits are the config address, the high order 32 > + * bits are the data to be written. > + */ > + write_val = where & ~3ull; > + write_val |= (((u64)val) << 32); > + writeq(write_val, pem_pci->pem_reg_base + PEM_CFG_WR); > + return PCIBIOS_SUCCESSFUL; > +} > + > +static int thunder_pem_config_write(struct pci_bus *bus, unsigned int devfn, > + int where, int size, u32 val) > +{ > + struct gen_pci *pci = bus->sysdata; > + > + if (bus->number < pci->cfg.bus_range->start || > + bus->number > pci->cfg.bus_range->end) > + return PCIBIOS_DEVICE_NOT_FOUND; > + /* > + * The first device on the bus is the PEM PCIe bridge. > + * Special case its config access. > + */ > + if (bus->number == pci->cfg.bus_range->start) > + return thunder_pem_bridge_write(bus, devfn, where, size, val); > + > + > + return pci_generic_config_write(bus, devfn, where, size, val); > +} > + > +static struct gen_pci_cfg_bus_ops thunder_pem_bus_ops = { > + .bus_shift = 24, > + .ops = { > + .map_bus = thunder_pem_map_bus, > + .read = thunder_pem_config_read, > + .write = thunder_pem_config_write, > + } > +}; > + > +static const struct of_device_id thunder_pem_of_match[] = { > + { .compatible = "cavium,pci-host-thunder-pem", > + .data = &thunder_pem_bus_ops }, > + > + { }, > +}; > +MODULE_DEVICE_TABLE(of, thunder_pem_of_match); > + > +static int thunder_pem_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + const struct of_device_id *of_id; > + resource_size_t bar4_start; > + struct resource *res_pem; > + struct thunder_pem_pci *pem_pci; > + > + pem_pci = devm_kzalloc(dev, sizeof(*pem_pci), GFP_KERNEL); > + if (!pem_pci) > + return -ENOMEM; > + > + of_id = of_match_node(thunder_pem_of_match, dev->of_node); > + pem_pci->gen_pci.cfg.ops = (struct gen_pci_cfg_bus_ops *)of_id->data; > + > + /* > + * The second register range is the PEM bridge to the PCIe > + * bus. It has a different config access method than those > + * devices behind the bridge. > + */ > + res_pem = platform_get_resource(pdev, IORESOURCE_MEM, 1); > + if (!res_pem) { > + dev_err(dev, "missing \"reg[1]\"property\n"); > + return -EINVAL; > + } > + > + pem_pci->pem_reg_base = devm_ioremap(dev, res_pem->start, 0x10000); > + if (!pem_pci->pem_reg_base) > + return -ENOMEM; > + > + /* > + * The MSI-X BAR for the PEM and AER interrupts is located at > + * a fixed offset from the PEM register base. Generate a > + * fragment of the synthesized Enhanced Allocation capability > + * structure here for the BAR. > + */ > + bar4_start = res_pem->start + 0xf00000; > + pem_pci->ea_entry[0] = (u32)bar4_start | 2; > + pem_pci->ea_entry[1] = (u32)(res_pem->end - bar4_start) & ~3u; > + pem_pci->ea_entry[2] = (u32)(bar4_start >> 32); > + > + return pci_host_common_probe(pdev, &pem_pci->gen_pci); > +} > + > +static struct platform_driver thunder_pem_driver = { > + .driver = { > + .name = KBUILD_MODNAME, > + .of_match_table = thunder_pem_of_match, > + }, > + .probe = thunder_pem_probe, > +}; > +module_platform_driver(thunder_pem_driver); > + > +MODULE_DESCRIPTION("Thunder PEM PCIe host driver"); > +MODULE_LICENSE("GPL v2"); > -- > 1.8.3.1 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel