From patchwork Wed Feb 15 07:18:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9573445 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 21DF4601D8 for ; Wed, 15 Feb 2017 07:19:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 134632842B for ; Wed, 15 Feb 2017 07:19:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07CBC28442; Wed, 15 Feb 2017 07:19:30 +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=unavailable 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 6AAA22842B for ; Wed, 15 Feb 2017 07:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751925AbdBOHTP (ORCPT ); Wed, 15 Feb 2017 02:19:15 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:45120 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751886AbdBOHTD (ORCPT ); Wed, 15 Feb 2017 02:19:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PCb16SEfE13n+8sQIqwLeW93RZiZvToHW2FnQrUDpRw=; b=SPTVzVDYU2rFODCgXD1w7TwQL iV30B3hJsVZPoZ3cj934997lVtbBT+bSQ2tI4TSq5mIYTcb11+5kAWKp8j05eSjO2307QhpsuxDTL F5KMKVQVWATuavMrrJJzeX4bP6vdQBB4m+lWun7Dyez6gDWtigojT+zdSnUtPOK0nE5Tedosp5gPR A8H2eSwZXnGibY78vRDjs+WGA7EFTeUkx1Gd9UJUAPYfqNYWAd1cVzQUk+ZAu4Od3quGSCqIGO++f ov0AIEvEk1wnKia5vNK2+QaiRIYMCz5nymtY9o6Hjk04TDo0HyWalGBTrBcqY8Ns2e9Lj5f/sGlkD CAthpdiKQ==; Received: from [91.114.64.3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1cdtrb-00041l-DC; Wed, 15 Feb 2017 07:18:55 +0000 From: Christoph Hellwig To: George Cherian Cc: David Daney , Herbert Xu , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] crypto: cavium/cptvf: switch to pci_alloc_irq_vectors Date: Wed, 15 Feb 2017 08:18:43 +0100 Message-Id: <20170215071843.30108-4-hch@lst.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170215071843.30108-1-hch@lst.de> References: <20170215071843.30108-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pci_enable_msix has been long deprecated, but this driver adds a new instance. Convert it to pci_alloc_irq_vectors and greatly simplify the code, and make sure the prope code properly unwinds. Signed-off-by: Christoph Hellwig --- drivers/crypto/cavium/cpt/cptvf.h | 3 - drivers/crypto/cavium/cpt/cptvf_main.c | 203 +++++++++++---------------------- 2 files changed, 65 insertions(+), 141 deletions(-) diff --git a/drivers/crypto/cavium/cpt/cptvf.h b/drivers/crypto/cavium/cpt/cptvf.h index 1cc04aa611e4..0a835a07d4f2 100644 --- a/drivers/crypto/cavium/cpt/cptvf.h +++ b/drivers/crypto/cavium/cpt/cptvf.h @@ -107,9 +107,6 @@ struct cpt_vf { void __iomem *reg_base; /* Register start address */ void *wqe_info; /* BH worker info */ /* MSI-X */ - bool msix_enabled; - struct msix_entry msix_entries[CPT_VF_MSIX_VECTORS]; - bool irq_allocated[CPT_VF_MSIX_VECTORS]; cpumask_var_t affinity_mask[CPT_VF_MSIX_VECTORS]; /* Command and Pending queues */ u32 qsize; diff --git a/drivers/crypto/cavium/cpt/cptvf_main.c b/drivers/crypto/cavium/cpt/cptvf_main.c index 527bdc3c2969..aac2966ff8d9 100644 --- a/drivers/crypto/cavium/cpt/cptvf_main.c +++ b/drivers/crypto/cavium/cpt/cptvf_main.c @@ -357,48 +357,10 @@ static int cptvf_sw_init(struct cpt_vf *cptvf, u32 qlen, u32 nr_queues) return ret; } -static void cptvf_disable_msix(struct cpt_vf *cptvf) +static void cptvf_free_irq_affinity(struct cpt_vf *cptvf, int vec) { - if (cptvf->msix_enabled) { - pci_disable_msix(cptvf->pdev); - cptvf->msix_enabled = 0; - } -} - -static int cptvf_enable_msix(struct cpt_vf *cptvf) -{ - int i, ret; - - for (i = 0; i < CPT_VF_MSIX_VECTORS; i++) - cptvf->msix_entries[i].entry = i; - - ret = pci_enable_msix(cptvf->pdev, cptvf->msix_entries, - CPT_VF_MSIX_VECTORS); - if (ret) { - dev_err(&cptvf->pdev->dev, "Request for #%d msix vectors failed\n", - CPT_VF_MSIX_VECTORS); - return ret; - } - - cptvf->msix_enabled = 1; - /* Mark MSIX enabled */ - cptvf->flags |= CPT_FLAG_MSIX_ENABLED; - - return 0; -} - -static void cptvf_free_all_interrupts(struct cpt_vf *cptvf) -{ - int irq; - - for (irq = 0; irq < CPT_VF_MSIX_VECTORS; irq++) { - if (cptvf->irq_allocated[irq]) - irq_set_affinity_hint(cptvf->msix_entries[irq].vector, - NULL); - free_cpumask_var(cptvf->affinity_mask[irq]); - free_irq(cptvf->msix_entries[irq].vector, cptvf); - cptvf->irq_allocated[irq] = false; - } + irq_set_affinity_hint(pci_irq_vector(cptvf->pdev, vec), NULL); + free_cpumask_var(cptvf->affinity_mask[vec]); } static void cptvf_write_vq_ctl(struct cpt_vf *cptvf, bool val) @@ -650,85 +612,23 @@ static irqreturn_t cptvf_done_intr_handler(int irq, void *cptvf_irq) return IRQ_HANDLED; } -static int cptvf_register_misc_intr(struct cpt_vf *cptvf) -{ - struct pci_dev *pdev = cptvf->pdev; - int ret; - - /* Register misc interrupt handlers */ - ret = request_irq(cptvf->msix_entries[CPT_VF_INT_VEC_E_MISC].vector, - cptvf_misc_intr_handler, 0, "CPT VF misc intr", - cptvf); - if (ret) - goto fail; - - cptvf->irq_allocated[CPT_VF_INT_VEC_E_MISC] = true; - - /* Enable mailbox interrupt */ - cptvf_enable_mbox_interrupts(cptvf); - cptvf_enable_swerr_interrupts(cptvf); - - return 0; - -fail: - dev_err(&pdev->dev, "Request misc irq failed"); - cptvf_free_all_interrupts(cptvf); - return ret; -} - -static int cptvf_register_done_intr(struct cpt_vf *cptvf) -{ - struct pci_dev *pdev = cptvf->pdev; - int ret; - - /* Register DONE interrupt handlers */ - ret = request_irq(cptvf->msix_entries[CPT_VF_INT_VEC_E_DONE].vector, - cptvf_done_intr_handler, 0, "CPT VF done intr", - cptvf); - if (ret) - goto fail; - - cptvf->irq_allocated[CPT_VF_INT_VEC_E_DONE] = true; - - /* Enable mailbox interrupt */ - cptvf_enable_done_interrupts(cptvf); - return 0; - -fail: - dev_err(&pdev->dev, "Request done irq failed\n"); - cptvf_free_all_interrupts(cptvf); - return ret; -} - -static void cptvf_unregister_interrupts(struct cpt_vf *cptvf) -{ - cptvf_free_all_interrupts(cptvf); - cptvf_disable_msix(cptvf); -} - -static void cptvf_set_irq_affinity(struct cpt_vf *cptvf) +static void cptvf_set_irq_affinity(struct cpt_vf *cptvf, int vec) { struct pci_dev *pdev = cptvf->pdev; - int vec, cpu; - int irqnum; - - for (vec = 0; vec < CPT_VF_MSIX_VECTORS; vec++) { - if (!cptvf->irq_allocated[vec]) - continue; - - if (!zalloc_cpumask_var(&cptvf->affinity_mask[vec], - GFP_KERNEL)) { - dev_err(&pdev->dev, "Allocation failed for affinity_mask for VF %d", - cptvf->vfid); - return; - } + int cpu; - cpu = cptvf->vfid % num_online_cpus(); - cpumask_set_cpu(cpumask_local_spread(cpu, cptvf->node), - cptvf->affinity_mask[vec]); - irqnum = cptvf->msix_entries[vec].vector; - irq_set_affinity_hint(irqnum, cptvf->affinity_mask[vec]); + if (!zalloc_cpumask_var(&cptvf->affinity_mask[vec], + GFP_KERNEL)) { + dev_err(&pdev->dev, "Allocation failed for affinity_mask for VF %d", + cptvf->vfid); + return; } + + cpu = cptvf->vfid % num_online_cpus(); + cpumask_set_cpu(cpumask_local_spread(cpu, cptvf->node), + cptvf->affinity_mask[vec]); + irq_set_affinity_hint(pci_irq_vector(pdev, vec), + cptvf->affinity_mask[vec]); } static void cptvf_write_vq_saddr(struct cpt_vf *cptvf, u64 val) @@ -809,22 +709,32 @@ static int cptvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } cptvf->node = dev_to_node(&pdev->dev); - /* Enable MSI-X */ - err = cptvf_enable_msix(cptvf); - if (err) { - dev_err(dev, "cptvf_enable_msix() failed"); + err = pci_alloc_irq_vectors(pdev, CPT_VF_MSIX_VECTORS, + CPT_VF_MSIX_VECTORS, PCI_IRQ_MSIX); + if (err < 0) { + dev_err(dev, "Request for #%d msix vectors failed\n", + CPT_VF_MSIX_VECTORS); goto cptvf_err_release_regions; } - /* Register mailbox interrupts */ - cptvf_register_misc_intr(cptvf); + err = request_irq(pci_irq_vector(pdev, CPT_VF_INT_VEC_E_MISC), + cptvf_misc_intr_handler, 0, "CPT VF misc intr", + cptvf); + if (err) { + dev_err(dev, "Request misc irq failed"); + goto cptvf_free_vectors; + } + + /* Enable mailbox interrupt */ + cptvf_enable_mbox_interrupts(cptvf); + cptvf_enable_swerr_interrupts(cptvf); /* Check ready with PF */ /* Gets chip ID / device Id from PF if ready */ err = cptvf_check_pf_ready(cptvf); if (err) { dev_err(dev, "PF not responding to READY msg"); - goto cptvf_err_release_regions; + goto cptvf_free_misc_irq; } /* CPT VF software resources initialization */ @@ -832,13 +742,13 @@ static int cptvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = cptvf_sw_init(cptvf, CPT_CMD_QLEN, CPT_NUM_QS_PER_VF); if (err) { dev_err(dev, "cptvf_sw_init() failed"); - goto cptvf_err_release_regions; + goto cptvf_free_misc_irq; } /* Convey VQ LEN to PF */ err = cptvf_send_vq_size_msg(cptvf); if (err) { dev_err(dev, "PF not responding to QLEN msg"); - goto cptvf_err_release_regions; + goto cptvf_free_misc_irq; } /* CPT VF device initialization */ @@ -848,37 +758,50 @@ static int cptvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = cptvf_send_vf_to_grp_msg(cptvf); if (err) { dev_err(dev, "PF not responding to VF_GRP msg"); - goto cptvf_err_release_regions; + goto cptvf_free_misc_irq; } cptvf->priority = 1; err = cptvf_send_vf_priority_msg(cptvf); if (err) { dev_err(dev, "PF not responding to VF_PRIO msg"); - goto cptvf_err_release_regions; + goto cptvf_free_misc_irq; + } + + err = request_irq(pci_irq_vector(pdev, CPT_VF_INT_VEC_E_DONE), + cptvf_done_intr_handler, 0, "CPT VF done intr", + cptvf); + if (err) { + dev_err(dev, "Request done irq failed\n"); + goto cptvf_free_misc_irq; } - /* Register DONE interrupts */ - err = cptvf_register_done_intr(cptvf); - if (err) - goto cptvf_err_release_regions; + + /* Enable mailbox interrupt */ + cptvf_enable_done_interrupts(cptvf); /* Set irq affinity masks */ - cptvf_set_irq_affinity(cptvf); - /* Convey UP to PF */ + cptvf_set_irq_affinity(cptvf, CPT_VF_INT_VEC_E_MISC); + cptvf_set_irq_affinity(cptvf, CPT_VF_INT_VEC_E_DONE); + err = cptvf_send_vf_up(cptvf); if (err) { dev_err(dev, "PF not responding to UP msg"); - goto cptvf_up_fail; + goto cptvf_free_irq_affinity; } err = cvm_crypto_init(cptvf); if (err) { dev_err(dev, "Algorithm register failed\n"); - goto cptvf_up_fail; + goto cptvf_free_irq_affinity; } return 0; -cptvf_up_fail: - cptvf_unregister_interrupts(cptvf); +cptvf_free_irq_affinity: + cptvf_free_irq_affinity(cptvf, CPT_VF_INT_VEC_E_DONE); + cptvf_free_irq_affinity(cptvf, CPT_VF_INT_VEC_E_MISC); +cptvf_free_misc_irq: + free_irq(pci_irq_vector(pdev, CPT_VF_INT_VEC_E_MISC), cptvf); +cptvf_free_vectors: + pci_free_irq_vectors(cptvf->pdev); cptvf_err_release_regions: pci_release_regions(pdev); cptvf_err_disable_device: @@ -899,7 +822,11 @@ static void cptvf_remove(struct pci_dev *pdev) if (cptvf_send_vf_down(cptvf)) { dev_err(&pdev->dev, "PF not responding to DOWN msg"); } else { - cptvf_unregister_interrupts(cptvf); + cptvf_free_irq_affinity(cptvf, CPT_VF_INT_VEC_E_DONE); + cptvf_free_irq_affinity(cptvf, CPT_VF_INT_VEC_E_MISC); + free_irq(pci_irq_vector(pdev, CPT_VF_INT_VEC_E_DONE), cptvf); + free_irq(pci_irq_vector(pdev, CPT_VF_INT_VEC_E_MISC), cptvf); + pci_free_irq_vectors(cptvf->pdev); cptvf_sw_cleanup(cptvf); pci_set_drvdata(pdev, NULL); pci_release_regions(pdev);