From patchwork Mon Sep 12 04:49:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9325681 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 B8E4D6048B for ; Mon, 12 Sep 2016 04:51:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEF3728ACC for ; Mon, 12 Sep 2016 04:51:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A349C28B06; Mon, 12 Sep 2016 04:51:02 +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 773E828ACC for ; Mon, 12 Sep 2016 04:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932625AbcILEu5 (ORCPT ); Mon, 12 Sep 2016 00:50:57 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:38056 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932341AbcILEuu (ORCPT ); Mon, 12 Sep 2016 00:50:50 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Sun, 11 Sep 2016 21:50:33 -0700 Received: from EX13-CAS-002.vmware.com (smtp-inbound.vmware.com [10.113.191.52]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 432FAB04DB; Sun, 11 Sep 2016 21:50:44 -0700 (PDT) Received: from EX13-CAS-004.vmware.com (10.113.191.54) by EX13-MBX-010.vmware.com (10.113.191.30) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Sun, 11 Sep 2016 21:50:43 -0700 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (10.113.170.11) by EX13-CAS-004.vmware.com (10.113.191.54) with Microsoft SMTP Server (TLS) id 15.0.1156.6 via Frontend Transport; Sun, 11 Sep 2016 21:50:43 -0700 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=7TnpzFr6+cYL35FViD4+kmPs51y1+mYz+mgDKiTDL+o=; b=nJ4VtQRSyjUstFgf4pnme89mquqj52YrREMlZZKW+LJveqjqkyk1HPfW0sBvz+JiiTEfyrFCyBXAg3svib4sSlsM46RqYJPyVbZLHJX109gdU41ZHGEDZTpFM99hOyw4hy40yB4YwE9WlE7TZOkB+ScSoPtSY9ZDXvSDJeWm83g= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=vmware.com; Received: from promb-2s-dhcp95-136.eng.vmware.com (208.91.1.34) by BLUPR0501MB836.namprd05.prod.outlook.com (10.141.251.150) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.619.3; Mon, 12 Sep 2016 04:50:33 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , , , Subject: [PATCH v4 10/16] IB/pvrdma: Add UAR support Date: Sun, 11 Sep 2016 21:49:20 -0700 Message-ID: <1473655766-31628-11-git-send-email-aditr@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473655766-31628-1-git-send-email-aditr@vmware.com> References: <1473655766-31628-1-git-send-email-aditr@vmware.com> MIME-Version: 1.0 X-Originating-IP: [208.91.1.34] X-ClientProxiedBy: BY2PR04CA052.namprd04.prod.outlook.com (10.141.249.170) To BLUPR0501MB836.namprd05.prod.outlook.com (10.141.251.150) X-MS-Office365-Filtering-Correlation-Id: 795fc575-3946-4f95-68a6-08d3dac85559 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB836; 2:HwXCHZsYijqu/Br6lZuXEV2y0kkdPc40OQkMaN6TWw4CZ+knXURn/4+djernwLxHONkcHgfqLz7lYc2+ca0SZfqbLLP47sz6tEPZCz8147CjTdxMb161QGvP9d5oKouii0pxU119yCsO81KOOq4l5M9araiJlww2U4Yeeqb01tEiKStzmhGnDw8evaDcr5DY; 3:XJRNxlwsegR3+JIzwNpLYQPA+Vsts/DbXDATo951FCUi2Vu5JEX+bnIBJwiYfGSJWXNo7wtQbwCnyJH+QyScGc/EfQ3TQDihOHmSQXUd7EmGtMJY3/Ng8jJTr01xxH16; 25:J2IdP/skNX1JuVksOdarB9DxVFzqbpzV77RQq9z0qcTgpSRPIFppwwDbCmjtsfT/V2w6yCnDMF/IUXSNdPks/uQZQwLQUtCKXZdwHXSRfXRhKw0uBLNiFquR08grsRenMpRb+4pI0NAWkkBCswe+SMtpueH4i37IgtjAqnB3r3CrPKngLnRnRb1d2Gn2tPXai7EYmWyr+hZky7xPk8k7g4hmpkLI+0Vjs1cytlHueLyoREAbg7opWRACX6iIz5AslA8TARr5YUPEdmKqiCvU4BElsPNFIv8xTKa+rBY8aKIcr2JWvIOA+TB1PVfdg3moKv2PtZTWE3FVxO1u8ucOj3BadVH6CUlMxP95pWbfA2Voef00AFhb8aNUSW1cL58p70Pw/zuzYBVnEbU6ijdno1UhHTXKwcvZot6noZeyNoI= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0501MB836; X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB836; 31:ch/pOV1Fzub3IvobCrm3ug4c5xNjhHeGyOI5UhwcBtgdpWIxQ/wMjnvWKkmGR9TmE5JnZsRrErG55kX6bc0L9lopyi2rrkJVwkbVL20mBcFmtk6ztDBPtuMNT9ZizxT7q/6fRgcppw7LRHcZKcibd9SPribvRPCfuboobs7+6kRYSqrVpdB0/LVF+b5XcO4XrK+hI+PA2NjPL0o0SrgN5QI57BUbZI922KBSwVB0q3I=; 20:9bSVXUbEaj1bCk8u5pD8t9eN8Ulo9lZJOy0mlex8i37V+BZBPIwMOZkwabKgMNZqAqVnZch0bW/wdUOQXkaVoOLkrxgYGgYGEwsilanj2VfmtKl9OaUa7/P7XHLW+leRRmpFn3D8CuNmxMh6uE8ZCc7DJvpvMeSQrxLgKURbI7YeH/8mhzkcx1UtXYOeY7e62kotZPpuW0/Jf0T+huekWyY/nlo1HC6q6WLOdN4tRxu83o1B+mIglsd7XW1eQ6LTuRjtkpYR9Ktn3gYD4UF0d5cavbv8yPx0TB0Mt8uQTDctbHNa0he/22UFuYvGqZ+vJ87HrP//185npEsJfyOWaUyPRpINAwboQ68Ier0UDxpik0PMxuqII9Jpl2BahLV9fV8zMvmbr7V99LsGDi67IjvAb+fTz2iqnNDD1d8Z7o6C19oJR+je3XxIKP8WXoSGoSmaZibOhpkuPfYQGQzSYRp2Mc69iazO0d6hX0BYvEoxf6vvw0Kz6yx0XMpmlFX/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(61668805478150)(22074186197030)(146099531331640); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BLUPR0501MB836; BCL:0; PCL:0; RULEID:; SRVR:BLUPR0501MB836; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB836; 4:5PFAhfKzHajNuivi42k67s6tYNZIHTvigbKRvbWsQsAggOut+3aVSdlEcm/EUpKx/LY4Os5WNuoVNm5tDHvc5TPhOnAOw3zt4jjI8MB+dZE0dtfBQrdl4SxSglfCo+6FkhDRnfemjESP3blhwQw+AfM/S0VaIh2Rhp+S8hq0XWb5Heql1IHCrbKKRp6Y/xg/PM2eYONAPR41nuCwhkrFrT8QDfYSCI+QXpmfcTVP1sECwmGPlEa7qIAw8ofSQWzJWITTQ3qmZw15Jy6G+kSdfdiVMQC+brgE2lATtZ9cqt+AU/4pdPCUPwbiPbaRSftNZueVDgqrMjMH0STIPOgY06iQjvY2I8L41eF3InP/UXCUKt9W4CXkOtoSn9mMcqRApmfAXW35BL6OPclby+82z11LWemVpvdIbYGeJKNryLYq4pjvlomAWAbgzjUloKUXXUNj0Jqdtr/aiv77dCw3f2IgZtTYj9PzHHjbWQBiEkWunlG3/tRwSWIFjViFshymqiX0Sk7vbcPnB9Af6x1eI8UNaLNB0Y44xAFntvoPPpY= X-Forefront-PRVS: 006339698F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(66066001)(107886002)(4001430100002)(5003940100001)(36756003)(47776003)(189998001)(4001450100002)(87386001)(86362001)(48376002)(2201001)(50466002)(2906002)(50226002)(8676002)(81166006)(586003)(4326007)(7846002)(5660300001)(305945005)(42186005)(76176999)(7736002)(50986999)(6116002)(3846002)(15975445007)(4001520100001)(5001770100001)(19580405001)(33646002)(92566002)(19580395003)(2950100001)(77096005)(229853001)(7099028)(5001760100003)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0501MB836; H:promb-2s-dhcp95-136.eng.vmware.com; FPR:; SPF:None; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0501MB836; 23:7WE3x5RfHJ4t8xA4I+Wqlz/oOD0jwVBvkxDFl6oe?= =?us-ascii?Q?aarg3zyIJOTDMGQ+fhX1jr+9wE7bpDvULLChCZxdAWZ2C2NNEx2l8lP+rhS8?= =?us-ascii?Q?UFkuThuL0T6ZC+2USkoRKBz3Dk+trAuJ+FsCQxFIltrJedydWnh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5mpEofuOBi+si5MKE0lcEY43VOQPCVa+O?= =?us-ascii?Q?FyQoaXf3KTff6pnRBVq1Y19R1b0QL6bRei0r7ryE8rqKdF6tXnfNkZUuldI3?= =?us-ascii?Q?OGnjEwwyQBRGycVeYhR46rWpud1XJzqR?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB836; 6:vKtN3oGj350HLs5sR0XW9yqjdskFsrU8DAqHKsDjjBvEDvJr5eo8vDwa+YJh1G+hOzUMRYWBZy86Isa+aeNyf6aXxt3cqDJ9IZPAN75/HlrVRw0Uw+n45EIeNL6Eofx9ldL2x4U6UOPAX7EMaMKM+3HRnAqIap/3ymiCphR/db8l3xazSmk2fHoLvisl4YYVfykYdYy7kCOXi5TZW0a5q97V4K4B03FqGZznaOT/vMUSjAQF1ovbmCQY8z4A+B5fpMZ6Ji3dQRplMeRg99e4iJEODtjWD/RWUoj0yZAYCbU=; 5:lNc0fP5vZDs1Vije7Aop6qlMWJzbOZLzSD7wzSqylkNT1QkZorNEfCMi3ZZU1BDejVxFLBmtsMQla8V1x1m8E8UH6GRcu75BZ4ni27k7wm1u1SZvRubdXwc1JlK86Gx1UyNjdnRZsyFEnF9itsLolw==; 24:BKA/Ax5rVgBScFmizVbjUc/QMAOE95OG22/PkzWZuhbWHChHkGcuGhgISfST/xVOkBxkERJrqQ5mBnYj4Uxm7/i/yGVRE7DcTA0cD4/ShOA=; 7:kCI3w6iR64AWl28hc6n7hJZwnjQXgR2RSnUgfhOFvRsRfhYMraCvMsfdnAQPrx9S5sOSSM1H8GDAl+X9ZMbS6Ewyl9xJVCHpmhVVnYghIHRgQKOK8Cf33Df6prF95RdDPgc70+aUivzMHbfTglBAstG2uqCJiB4BRKOC9cXhuL8QTdDR0mNCcLiP4RT3Zwf8OpweC3pJf+gmP3UvKJ37tILybcxWLxJKjdEmpw1p4984E6La3beRS/9H98ARxqoW SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB836; 20:65EZQ+zXS3W8tjfJ3Lh4A/Vb8C3MdIhHN99w3Pp+cQKqRoMjL3/uABl6/Y0p1Kbd8WOfVLFswkhyjMwDkFktqQaGVZluWu3DVNdDQNy10iWCik/OJS3fmRkLbFamqAW8CQcJzf11Sw5AJgD3mjGKr3gZPbdMKlhfkWfROYKz9iU= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2016 04:50:33.7529 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0501MB836 Received-SPF: None (EX13-EDG-OU-001.vmware.com: aditr@vmware.com does not designate permitted sender hosts) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the UAR support for the paravirtual RDMA device. The UAR pages are MMIO pages from the virtual PCI space. We define offsets within this page to provide the fast data-path operations. Reviewed-by: Yuval Shaia Reviewed-by: Jorgen Hansen Reviewed-by: George Zhang Reviewed-by: Aditya Sarwade Reviewed-by: Bryan Tan Signed-off-by: Adit Ranadive --- Changes v3->v4: - Removed an unnecessary comment. Changes v2->v3: - Used is_power_of_2 function. - Simplify pvrdma_uar_alloc function. --- drivers/infiniband/hw/pvrdma/pvrdma_doorbell.c | 127 +++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 drivers/infiniband/hw/pvrdma/pvrdma_doorbell.c diff --git a/drivers/infiniband/hw/pvrdma/pvrdma_doorbell.c b/drivers/infiniband/hw/pvrdma/pvrdma_doorbell.c new file mode 100644 index 0000000..bf51357 --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma_doorbell.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2012-2016 VMware, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of EITHER the GNU General Public License + * version 2 as published by the Free Software Foundation or the BSD + * 2-Clause License. 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 version 2 for more details at + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html. + * + * You should have received a copy of the GNU General Public License + * along with this program available in the file COPYING in the main + * directory of this source tree. + * + * The BSD 2-Clause License + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "pvrdma.h" + +int pvrdma_uar_table_init(struct pvrdma_dev *dev) +{ + u32 num = dev->dsr->caps.max_uar; + u32 mask = num - 1; + struct pvrdma_id_table *tbl = &dev->uar_table.tbl; + + if (!is_power_of_2(num)) + return -EINVAL; + + tbl->last = 0; + tbl->top = 0; + tbl->max = num; + tbl->mask = mask; + spin_lock_init(&tbl->lock); + tbl->table = kcalloc(BITS_TO_LONGS(num), sizeof(long), GFP_KERNEL); + if (!tbl->table) + return -ENOMEM; + + /* 0th UAR is taken by the device. */ + set_bit(0, tbl->table); + + return 0; +} + +void pvrdma_uar_table_cleanup(struct pvrdma_dev *dev) +{ + struct pvrdma_id_table *tbl = &dev->uar_table.tbl; + + kfree(tbl->table); +} + +int pvrdma_uar_alloc(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar) +{ + struct pvrdma_id_table *tbl; + unsigned long flags; + u32 obj; + + tbl = &dev->uar_table.tbl; + + spin_lock_irqsave(&tbl->lock, flags); + obj = find_next_zero_bit(tbl->table, tbl->max, tbl->last); + if (obj >= tbl->max) { + tbl->top = (tbl->top + tbl->max) & tbl->mask; + obj = find_first_zero_bit(tbl->table, tbl->max); + } + + if (obj >= tbl->max) { + spin_unlock_irqrestore(&tbl->lock, flags); + return -ENOMEM; + } + + set_bit(obj, tbl->table); + obj |= tbl->top; + + spin_unlock_irqrestore(&tbl->lock, flags); + + uar->index = obj; + uar->pfn = (pci_resource_start(dev->pdev, PVRDMA_PCI_RESOURCE_UAR) >> + PAGE_SHIFT) + uar->index; + + return 0; +} + +void pvrdma_uar_free(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar) +{ + struct pvrdma_id_table *tbl = &dev->uar_table.tbl; + unsigned long flags; + u32 obj; + + obj = uar->index & (tbl->max - 1); + spin_lock_irqsave(&tbl->lock, flags); + clear_bit(obj, tbl->table); + tbl->last = min(tbl->last, obj); + tbl->top = (tbl->top + tbl->max) & tbl->mask; + spin_unlock_irqrestore(&tbl->lock, flags); +}