From patchwork Wed Jan 11 23:55:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jim Gill X-Patchwork-Id: 9511633 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3AB8E60476 for ; Wed, 11 Jan 2017 23:55:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2032528655 for ; Wed, 11 Jan 2017 23:55:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1207D286A8; Wed, 11 Jan 2017 23:55:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C58B28655 for ; Wed, 11 Jan 2017 23:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934012AbdAKXzF (ORCPT ); Wed, 11 Jan 2017 18:55:05 -0500 Received: from mail-cys01nam02on0066.outbound.protection.outlook.com ([104.47.37.66]:25600 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932692AbdAKXzE (ORCPT ); Wed, 11 Jan 2017 18:55:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onevmw.onmicrosoft.com; s=selector1-vmware-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=vkIwvYsNd6W9dMuy3oejtTCDAWEatsl+Pl2wRtmrjqE=; b=eskB3j5ToBmNTZFxmw0ISJeEVlH+SaFi+d5xUzGnLDiduh48pomf3Q4BWh49eI5ZPAXl0dAFR1MKjT/+IWTw7eVvD75guVgWJXm5S47KMSKAFWP/La5kOC6uYS0KPvlFYxULZMGGfYnxdug1ZfSKO+a2/bOzjBM6xrEcclejF+0= Received: from DM2PR0501MB1536.namprd05.prod.outlook.com (10.160.133.139) by DM2PR0501MB1536.namprd05.prod.outlook.com (10.160.133.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.860.6; Wed, 11 Jan 2017 23:55:01 +0000 Received: from DM2PR0501MB1536.namprd05.prod.outlook.com ([10.160.133.139]) by DM2PR0501MB1536.namprd05.prod.outlook.com ([10.160.133.139]) with mapi id 15.01.0860.004; Wed, 11 Jan 2017 23:55:01 +0000 From: Jim Gill To: Christoph Hellwig , "Martin K. Petersen" CC: pv-drivers , "linux-scsi@vger.kernel.org" Subject: Re: [PATCH] vmw_pvscsi: switch to pci_alloc_irq_vectors Thread-Topic: [PATCH] vmw_pvscsi: switch to pci_alloc_irq_vectors Thread-Index: AQHSQWFpfApskdgJNEq6YsD8cu+so6DwO09EgD7D44CABUdFjA== Date: Wed, 11 Jan 2017 23:55:01 +0000 Message-ID: References: <1479448958-6653-1-git-send-email-hch@lst.de> , <20170108150751.GA10308@infradead.org> In-Reply-To: <20170108150751.GA10308@infradead.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=jgill@vmware.com; x-originating-ip: [132.245.40.5] x-ld-processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr x-ms-office365-filtering-correlation-id: 450883e4-21e4-4616-eb09-08d43a7d41d4 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM2PR0501MB1536; x-microsoft-exchange-diagnostics: 1; DM2PR0501MB1536; 7:Gt9mMmojcl6pwM0J0JwJm3VGQCa1AjeQdTqQkWmOBzB8ZUSGUVKM3JY8ATnv2B02ucF6dUVnUuY8KqNh58BEUsAFizkhmJ+COAYwYPmy0yz4rVE8N7QftdlaojrfruoIeHL2WffKDmqcXb55eM3HnRq7UXqX+/FtRsQ/MlTbZ2lvbOPusk9G3puGSYm5ko5LON+bZDwWO1jXgu5F8oaCCvtlZ/EnBY2eBjzbPdLyR3F7o1aZbD00CRE2JBCg7wd4PW3VFZE/F1lkb9JrHofBkldEKIo83eBXXKU1rh9AQ/P/OyY4yx84VGGs9p7WF5WmeIOBh8SgDlUABufkd9Mwr4Yi1nuFqfekI3OuIuREsNgNxbTfubNZggP+Vb6ezOQtzIv4S6FKz66lbpNPMtWenjufpdk7/ploAFLIY2lRLBPFBM2hLWR5zpsH5DyvsAd0d5zzJUXlsmQmzhcHjGHZPw==; 20:xekigyx/DYDmYmIBPGM16RzBtou+5qBjwPoASeateVGiRZPuOwFMiFDb+lSsyDs29iM5+RbPe6hQc/RBYGfOwNE1aULjmM3b9GC/HF4EkJxUHCfrf1udmzMQHrkip5UNL1mEyLsBWkgqbqENgulDDfOFWFArk+iLj2RpQwGkYRI= x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(61668805478150)(9452136761055); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123558021)(20161123560025)(20161123564025)(20161123562025)(20161123555025)(6072148); SRVR:DM2PR0501MB1536; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0501MB1536; x-forefront-prvs: 01842C458A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(6009001)(7916002)(39450400003)(24454002)(377454003)(189002)(199003)(33656002)(5660300001)(101416001)(4326007)(3280700002)(6116002)(68736007)(86362001)(2906002)(575784001)(3900700001)(5001770100001)(74316002)(189998001)(97736004)(305945005)(7736002)(105586002)(106116001)(76176999)(54356999)(50986999)(106356001)(3846002)(9686003)(3660700001)(102836003)(92566002)(25786008)(55016002)(8676002)(99286003)(81156014)(54906002)(81166006)(38730400001)(122556002)(229853002)(6436002)(6506006)(2900100001)(66066001)(2950100002)(77096006)(7696004)(8936002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0501MB1536; H:DM2PR0501MB1536.namprd05.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jan 2017 23:55:01.3976 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0501MB1536 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP acked by Jim Gill (jgill@vmware.com) looks good to me. Signed-off-by: Christoph Hellwig --- drivers/scsi/vmw_pvscsi.c | 104 +++++++++++++++++----------------------------- drivers/scsi/vmw_pvscsi.h |   5 --- 2 files changed, 38 insertions(+), 71 deletions(-) diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c index 4a0d3cd..642dd4e 100644 --- a/drivers/scsi/vmw_pvscsi.c +++ b/drivers/scsi/vmw_pvscsi.c @@ -68,10 +68,7 @@ struct pvscsi_ctx { struct pvscsi_adapter {          char                            *mmioBase; -       unsigned int                    irq;          u8                              rev; -       bool                            use_msi; -       bool                            use_msix;          bool                            use_msg;          bool                            use_req_threshold; @@ -1160,30 +1157,26 @@ static bool pvscsi_setup_req_threshold(struct pvscsi_adapter *adapter, static irqreturn_t pvscsi_isr(int irq, void *devp) {          struct pvscsi_adapter *adapter = devp; -       int handled; - -       if (adapter->use_msi || adapter->use_msix) -               handled = true; -       else { -               u32 val = pvscsi_read_intr_status(adapter); -               handled = (val & PVSCSI_INTR_ALL_SUPPORTED) != 0; -               if (handled) -                       pvscsi_write_intr_status(devp, val); -       } - -       if (handled) { -               unsigned long flags; +       unsigned long flags; -               spin_lock_irqsave(&adapter->hw_lock, flags); +       spin_lock_irqsave(&adapter->hw_lock, flags); +       pvscsi_process_completion_ring(adapter); +       if (adapter->use_msg && pvscsi_msg_pending(adapter)) +               queue_work(adapter->workqueue, &adapter->work); +       spin_unlock_irqrestore(&adapter->hw_lock, flags); -               pvscsi_process_completion_ring(adapter); -               if (adapter->use_msg && pvscsi_msg_pending(adapter)) -                       queue_work(adapter->workqueue, &adapter->work); +       return IRQ_HANDLED; +} -               spin_unlock_irqrestore(&adapter->hw_lock, flags); -       } +static irqreturn_t pvscsi_shared_isr(int irq, void *devp) +{ +       struct pvscsi_adapter *adapter = devp; +       u32 val = pvscsi_read_intr_status(adapter); -       return IRQ_RETVAL(handled); +       if (!(val & PVSCSI_INTR_ALL_SUPPORTED)) +               return IRQ_NONE; +       pvscsi_write_intr_status(devp, val); +       return pvscsi_isr(irq, devp); } static void pvscsi_free_sgls(const struct pvscsi_adapter *adapter) @@ -1195,34 +1188,10 @@ static void pvscsi_free_sgls(const struct pvscsi_adapter *adapter)                  free_pages((unsigned long)ctx->sgl, get_order(SGL_SIZE)); } -static int pvscsi_setup_msix(const struct pvscsi_adapter *adapter, -                            unsigned int *irq) -{ -       struct msix_entry entry = { 0, PVSCSI_VECTOR_COMPLETION }; -       int ret; - -       ret = pci_enable_msix_exact(adapter->dev, &entry, 1); -       if (ret) -               return ret; - -       *irq = entry.vector; - -       return 0; -} - static void pvscsi_shutdown_intr(struct pvscsi_adapter *adapter) { -       if (adapter->irq) { -               free_irq(adapter->irq, adapter); -               adapter->irq = 0; -       } -       if (adapter->use_msi) { -               pci_disable_msi(adapter->dev); -               adapter->use_msi = 0; -       } else if (adapter->use_msix) { -               pci_disable_msix(adapter->dev); -               adapter->use_msix = 0; -       } +       free_irq(pci_irq_vector(adapter->dev, 0), adapter); +       pci_free_irq_vectors(adapter->dev); } static void pvscsi_release_resources(struct pvscsi_adapter *adapter) @@ -1358,11 +1327,11 @@ static u32 pvscsi_get_max_targets(struct pvscsi_adapter *adapter) static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id) { +       unsigned int irq_flag = PCI_IRQ_MSIX | PCI_IRQ_MSI | PCI_IRQ_LEGACY;          struct pvscsi_adapter *adapter;          struct pvscsi_adapter adapter_temp;          struct Scsi_Host *host = NULL;          unsigned int i; -       unsigned long flags = 0;          int error;          u32 max_id; @@ -1511,30 +1480,33 @@ static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)                  goto out_reset_adapter;          } -       if (!pvscsi_disable_msix && -           pvscsi_setup_msix(adapter, &adapter->irq) == 0) { -               printk(KERN_INFO "vmw_pvscsi: using MSI-X\n"); -               adapter->use_msix = 1; -       } else if (!pvscsi_disable_msi && pci_enable_msi(pdev) == 0) { -               printk(KERN_INFO "vmw_pvscsi: using MSI\n"); -               adapter->use_msi = 1; -               adapter->irq = pdev->irq; -       } else { -               printk(KERN_INFO "vmw_pvscsi: using INTx\n"); -               adapter->irq = pdev->irq; -               flags = IRQF_SHARED; -       } +       if (pvscsi_disable_msix) +               irq_flag &= ~PCI_IRQ_MSIX; +       if (pvscsi_disable_msi) +               irq_flag &= ~PCI_IRQ_MSI; + +       error = pci_alloc_irq_vectors(adapter->dev, 1, 1, irq_flag); +       if (error) +               goto out_reset_adapter;          adapter->use_req_threshold = pvscsi_setup_req_threshold(adapter, true);          printk(KERN_DEBUG "vmw_pvscsi: driver-based request coalescing %sabled\n",                 adapter->use_req_threshold ? "en" : "dis"); -       error = request_irq(adapter->irq, pvscsi_isr, flags, -                           "vmw_pvscsi", adapter); +       if (adapter->dev->msix_enabled || adapter->dev->msi_enabled) { +               printk(KERN_INFO "vmw_pvscsi: using MSI%s\n", +                       adapter->dev->msix_enabled ? "-X" : ""); +               error = request_irq(pci_irq_vector(pdev, 0), pvscsi_isr, +                               0, "vmw_pvscsi", adapter); +       } else { +               printk(KERN_INFO "vmw_pvscsi: using INTx\n"); +               error = request_irq(pci_irq_vector(pdev, 0), pvscsi_shared_isr, +                               IRQF_SHARED, "vmw_pvscsi", adapter); +       } +          if (error) {                  printk(KERN_ERR                         "vmw_pvscsi: unable to request IRQ: %d\n", error); -               adapter->irq = 0;                  goto out_reset_adapter;          } diff --git a/drivers/scsi/vmw_pvscsi.h b/drivers/scsi/vmw_pvscsi.h index c097d2c..b3060fe 100644 --- a/drivers/scsi/vmw_pvscsi.h +++ b/drivers/scsi/vmw_pvscsi.h @@ -423,11 +423,6 @@ struct PVSCSIConfigPageController { #define PVSCSI_MAX_INTRS        24 /* - * Enumeration of supported MSI-X vectors - */ -#define PVSCSI_VECTOR_COMPLETION   0 - -/*   * Misc constants for the rings.   */