From patchwork Fri Jul 22 10:41:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Koehrer Mathias (ETAS/ESW5)" X-Patchwork-Id: 651629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rwnJv163Mz9t0P for ; Fri, 22 Jul 2016 20:42:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753333AbcGVKmF (ORCPT ); Fri, 22 Jul 2016 06:42:05 -0400 Received: from smtp6-v.fe.bosch.de ([139.15.237.11]:11271 "EHLO smtp6-v.fe.bosch.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752452AbcGVKmE convert rfc822-to-8bit (ORCPT ); Fri, 22 Jul 2016 06:42:04 -0400 Received: from vsmta12.fe.internet.bosch.com (unknown [10.4.98.52]) by imta23.fe.bosch.de (Postfix) with ESMTP id 545F21580002; Fri, 22 Jul 2016 12:42:01 +0200 (CEST) Received: from SI-MBX1012.de.bosch.com (vsgw24.fe.internet.bosch.com [10.4.98.24]) by vsmta12.fe.internet.bosch.com (Postfix) with ESMTP id 2AB5C1B802AA; Fri, 22 Jul 2016 12:42:01 +0200 (CEST) Received: from FE-MBX1012.de.bosch.com (10.3.230.70) by SI-MBX1012.de.bosch.com (10.3.230.45) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Fri, 22 Jul 2016 12:42:00 +0200 Received: from FE-MBX1012.de.bosch.com ([fe80::310c:6b49:1d6e:47a]) by FE-MBX1012.de.bosch.com ([fe80::310c:6b49:1d6e:47a%16]) with mapi id 15.00.1178.000; Fri, 22 Jul 2016 12:42:00 +0200 From: "Koehrer Mathias (ETAS/ESW5)" To: Bjorn Helgaas CC: "gregkh@linuxfoundation.org" , "linux-pci@vger.kernel.org" , "bhelgaas@google.com" Subject: [PATCH resend v2] Extending kernel option pci=resource_alignment to be able to specify PCI device/vendor IDs Thread-Topic: [PATCH resend v2] Extending kernel option pci=resource_alignment to be able to specify PCI device/vendor IDs Thread-Index: AdHkBaYAyyxdNkNfRs65mmKKLw0MNg== Date: Fri, 22 Jul 2016 10:41:59 +0000 Message-ID: <14535ddd929448b4b8a9f8f2f58439a6@FE-MBX1012.de.bosch.com> Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.4.162.35] MIME-Version: 1.0 X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-22466.006 X-TMASE-MatchedRID: ZKUaM899N8xFsw2Lp+kSuFu4M/xm4KZeO1IfDKON40lBL//DKiVcziLW R2TcjmIxv2B1Wiv+bnvem5jmylDk/deV00rMo+W98YGKGucXIE+BHKTJ+sfXGUENV4Lwnu7BFAx 8b8GXiy3ERx+bb7v/+cGfVvC1EFC2DXVj0zMhpTYVglQa/gMvfPZfafJjZZIJd71AOvz4tNyby3 1RR+vPLS8vrA3c3A0HcpY/M8utm1/HQuauwt+FXISvKOGqLLPK0pVrZbbfikhXU/N8EvfsRCzyb VqWyY2NQ01NIl0EPx8ROooL/2LdYg+/n/431GMSbCMnhMV5TW7wq1JQ5xF4kgqiCYa6w8tvtTPr O7QRu3ji8zVgXoAltjrm2CwlZwVRIAcCikR3vq8Wr2+0Tw0SvWEvqAFEfpUvYvCxmBx/dwOdPmo 7D5pFgh9YOV9Mxun7 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Some uio based PCI drivers (e.g. uio_cif) do not work if the assigned PCI memory resources are not page aligned. By using the kernel option "pci=resource_alignment" it is possible to force single PCI boards to use page alignment for their memory resources. However, this is fairly cumbersome if multiple of these boards are in use as the specification of the cards has to be done via PCI bus/slot/function number which might change e.g. by adding another board. This patch extends the kernel option "pci=resource_alignment" to allow to specify the relevant boards via PCI device/vendor (and subdevice/subvendor) ids. The specification of the devices via device/vendor is indicated by a leading string "pci:" as argument to "pci=resource_alignment". The format of the specification is pci::[::] Examples: pci=resource_alignment=4096@pci:1234:abcd:1234:bcde pci=resource_alignment=pci:1234:abcd Signed-off-by: Mathias Koehrer --- Documentation/kernel-parameters.txt | 2 + drivers/pci/pci.c | 66 +++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 19 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-4.7-rc1/Documentation/kernel-parameters.txt =================================================================== --- linux-4.7-rc1.orig/Documentation/kernel-parameters.txt +++ linux-4.7-rc1/Documentation/kernel-parameters.txt @@ -2998,12 +2998,17 @@ bytes respectively. Such letter suffixes resource_alignment= Format: [@][:]:.[; ...] + [@]pci::\ + [::][; ...] Specifies alignment and device to reassign aligned memory resources. If is not specified, PAGE_SIZE is used as alignment. PCI-PCI bridge can be specified, if resource windows need to be expanded. + To specify the alignment for certain types of devices, the + PCI vendor/device (and subvendor/subdevice) may be + specified. E.g. 4096@pci:1234:abcd:1234:bcde ecrc= Enable/disable PCIe ECRC (transaction layer end-to-end CRC checking). bios: Use BIOS/firmware settings. This is the Index: linux-4.7-rc1/drivers/pci/pci.c =================================================================== --- linux-4.7-rc1.orig/drivers/pci/pci.c +++ linux-4.7-rc1/drivers/pci/pci.c @@ -4755,6 +4755,7 @@ static DEFINE_SPINLOCK(resource_alignmen static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev) { int seg, bus, slot, func, align_order, count; + unsigned short vendor, device, subsystem_vendor, subsystem_device; resource_size_t align = 0; char *p; @@ -4768,28 +4769,55 @@ static resource_size_t pci_specified_res } else { align_order = -1; } - if (sscanf(p, "%x:%x:%x.%x%n", - &seg, &bus, &slot, &func, &count) != 4) { - seg = 0; - if (sscanf(p, "%x:%x.%x%n", - &bus, &slot, &func, &count) != 3) { - /* Invalid format */ - printk(KERN_ERR "PCI: Can't parse resource_alignment parameter: %s\n", - p); + if (strncmp(p, "pci:", 4) == 0) { + /* PCI vendor/device (subvendor/subdevice) ids are specified */ + p += 4; + if (sscanf(p, "%hx:%hx:%hx:%hx%n", + &vendor, &device, &subsystem_vendor, &subsystem_device, &count) != 4) { + if (sscanf(p, "%hx:%hx%n", &vendor, &device, &count) != 2) { + printk(KERN_ERR "PCI: Can't parse resource_alignment parameter: pci:%s\n", + p); + break; + } + subsystem_vendor = subsystem_device = 0; + } + p += count; + if ((!vendor || (vendor == dev->vendor)) && + (!device || (device == dev->device)) && + (!subsystem_vendor || (subsystem_vendor == dev->subsystem_vendor)) && + (!subsystem_device || (subsystem_device == dev->subsystem_device))) { + if (align_order == -1) + align = PAGE_SIZE; + else + align = 1 << align_order; + /* Found */ break; } } - p += count; - if (seg == pci_domain_nr(dev->bus) && - bus == dev->bus->number && - slot == PCI_SLOT(dev->devfn) && - func == PCI_FUNC(dev->devfn)) { - if (align_order == -1) - align = PAGE_SIZE; - else - align = 1 << align_order; - /* Found */ - break; + else { + if (sscanf(p, "%x:%x:%x.%x%n", + &seg, &bus, &slot, &func, &count) != 4) { + seg = 0; + if (sscanf(p, "%x:%x.%x%n", + &bus, &slot, &func, &count) != 3) { + /* Invalid format */ + printk(KERN_ERR "PCI: Can't parse resource_alignment parameter: %s\n", + p); + break; + } + } + p += count; + if (seg == pci_domain_nr(dev->bus) && + bus == dev->bus->number && + slot == PCI_SLOT(dev->devfn) && + func == PCI_FUNC(dev->devfn)) { + if (align_order == -1) + align = PAGE_SIZE; + else + align = 1 << align_order; + /* Found */ + break; + } } if (*p != ';' && *p != ',') { /* End of param or invalid format */