From patchwork Sat Sep 24 23:21:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9349355 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 2851A601C2 for ; Sat, 24 Sep 2016 23:23:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AA55290C6 for ; Sat, 24 Sep 2016 23:23:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F9EF290CF; Sat, 24 Sep 2016 23:23:23 +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 3007B290CE for ; Sat, 24 Sep 2016 23:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934472AbcIXXXG (ORCPT ); Sat, 24 Sep 2016 19:23:06 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:3081 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030406AbcIXXWc (ORCPT ); Sat, 24 Sep 2016 19:22:32 -0400 Received: from sc9-mailhost1.vmware.com (10.113.161.71) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Sat, 24 Sep 2016 16:22:05 -0700 Received: from EX13-CAS-002.vmware.com (ex13-cas-002.vmware.com [10.113.191.52]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id CA47818445; Sat, 24 Sep 2016 16:22:28 -0700 (PDT) Received: from EX13-CAS-003.vmware.com (10.113.191.53) by EX13-MBX-030.vmware.com (10.113.191.50) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Sat, 24 Sep 2016 16:22:28 -0700 Received: from NAM03-CO1-obe.outbound.protection.outlook.com (10.113.170.11) by EX13-CAS-003.vmware.com (10.113.191.53) with Microsoft SMTP Server (TLS) id 15.0.1156.6 via Frontend Transport; Sat, 24 Sep 2016 16:22:28 -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=etloepOC9mdpZ7y2nGCmpeR4jwRyOCvKJqITj1YO37ndw6dRwbw80upnNYC0Sal9PoPPsjbHYuPmurMM7fC8YNs3hSEDCGgM4yvXMNgemnbnyE8H5C0PMktCcTXXkmoh5gtTRU5DWrH/yU9mQ2Eixa+vKXhXCpkPXYjt2AqzCoE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aditr@vmware.com; Received: from promb-2s-dhcp95-136.eng.vmware.com (208.91.1.34) by CO2PR0501MB837.namprd05.prod.outlook.com (10.141.244.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.639.2; Sat, 24 Sep 2016 23:22:23 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , , , Subject: [PATCH v5 10/16] IB/pvrdma: Add UAR support Date: Sat, 24 Sep 2016 16:21:34 -0700 Message-ID: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [208.91.1.34] X-ClientProxiedBy: CY1PR18CA0027.namprd18.prod.outlook.com (10.163.31.37) To CO2PR0501MB837.namprd05.prod.outlook.com (10.141.244.147) X-MS-Office365-Filtering-Correlation-Id: 9865d43f-fa87-405b-8dc9-08d3e4d1a439 X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 2:17qMlLVIA1txYwFH1KtGurYO8nvi2r7Zx8sC9e3FI0LGCDwoESP8Vyxf42zizaIoYhkrcKyAttohAPw7QTHSw4A9vRW7MLUF8i8kgSrJu1P1c524EUP5xUY2vtEpqNsMT4eKHbnQGsPBx/dYFa3JsuL0yEyGL9C+YiFJmLWTmBuIrpY748tGcXLMWBFVSUT4; 3:FM8Q4wdG3YAeZ3SjTcGRlpqHeQmpCGjOXDLTElgvTFC+Bg+nqq9sAkQ9ZGt8H2HKFUjksw20qK3lSkhiE0e934vRQQSZH3OqtE1c2uyMUM/27Fn3eXLgRFNDyDswo8th X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR0501MB837; X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 25:m6ftCmatHv1ii5QhI76cgu3ljwmOYmO/vc/qXysIZkoRSIAN/TFtALSd7SvUoHdNywh/GyYY59eRgPdI1SY/JEJkmaXivdZCxctjd7lcipGHRHN49UmoT0ExnyDYSrIbGPKCFQ38eb3NkcY3vl/SICqxl5XxRLtv2Zwo6c/wW18msC0Mxndv/VZieI/WNrT1flVVZEnQUsvWyz7hhgkcDQzwuEEV/jFLm8lyjQZMqS9wdQ7tO1ngBzQe9Bro7Hn+Wod7t+gjLmtJOc00TfNtuwQANDn+1jfx1ABnXaxaJzOC++fgh/8MdpVsSFxdde1byhNC8C4EPHvHux4wX5dsSpDvFP8Vn4xdKFUMUnqIzUv7ilEStTnuiB+ZjtMJCF0dYH+4chxxdMrJf2UaIl4m/jS5xu4wpfs3MJKAmUQJIakzuHD9fIklAgKb1QqOn4hyY8WorqUkgeu+nG35+zw/aqUL1US9TCdhA6JSPcckgAPziFyekbNdU4j3dxeVxK24hMlMKK6RAN3G+ZionJWDPfsRCg+HBj0x/n2LFWyO7PgnRfyBL7d4CrvdOxqzEbdmwlrEhucc9h3KVu8jDTejSy+UXoCPkS0XIcXcaY+IoqCNF2heCpBMp/r+/AEqTf/DB0Suo7NQSaqEGS2U1fLbwuYV5Ublcx62LcMI+qriLi8ovLluWi/nGUtXtrWwz20ZhvuLvZKTb8IWBt7/3f53czvOWkfCKcgfkbGQRuZxFHmLhxU9apPllVlGMksFgsPN0/0rBPTN1oJz+iPvkRY5ad7ikAlOdqPL7zYaQrNG8AQsIj193RH/vSlHRF1RwmYW X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 31:7os27euH9qEHNb/r116Vzym3JsBFqUKTrQtyyheEFAmsV6pbhWh7wUnLCLQWSUGvjpHva3eY+C0oLCLMlVxgVlQVl211N1FmQz3x03vIfYCM0mD0s/cNScmg7+ilO3hZCoklnSAJeNLLAX4DJ4y2AVpaAmnBclFxTqY0zkra5JzBJoQfILdHoIv59l4U+w2cc8oYEAK4aq75jODaGNR1th3k2apYq0yzOpKC0HkJDAE=; 20:miQ3VaUVRV1pKAE8bnsv6XrRRB4J6u3qlmt6MVnTuYQMat7q6m98Ah6B9EoLWPs4YY7rsxdhfFOrKUylrad8YkGuXH/+Jdm2yKpa535fTvdOdy5eGrXeh7ebI6aPISQGb2cQW6Z8bZTT1EQZ9eOlpjO98vXbjo+VRlkq3wKIWbXFjtEeY/xAm7V4GC+WETUyKPasZEQcB8tP+WNdY3orZjwhszcU0pBAgaX/uBB19r6ZG72cT+5BzFUkUZfsA7uDtsZoeExShK0NIc7lmHl34KyIqvDvm5XaMOfi1q47l3NlF0Kh3IarJQGt9HrYbYI+U9L8Y32lJvBY7cfGiVXV9OEDoPkA8QQMxcPc9g3R3HmDkQWH7IiOWqDhgM/AHbGzZ7hy8TkP574KekXa7nsJN1vlJiI+V0VJ6EYnSE0AH4L/1TaL/NKCy/ADjXtGDKMqMNtn8y9pbyMaGd3dcwJaP8ReXWXo+GIJMmfcumNa+MQHYfOhjUz+ZLl7Ep3zS+xX 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)(8121501046)(5005006)(3002001)(10201501046); SRVR:CO2PR0501MB837; BCL:0; PCL:0; RULEID:; SRVR:CO2PR0501MB837; X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 4:osO5Rj+ZI3BRP5tDyQMaWuBY1ytA7kglSD4FPIUyp5XBv0QzJpwudBJ24V3EZA7vQ7JKsLLtgwiXMp6oHQTFVIVPLjga8XKVvMT6AbZecVu56uqgRwdI8da1QrzeSx2zdS5dJ/6Ldh2MrsikS3uV0EL+tcs3jBLkL1c5guLQgndIpUhhvH8YggFQvA5svs3nIFQhys6PhQeKdsdzE81ECmNCHjO4CqaFz0UyvxjPxBlCkr7Hwzxfywgkt6GAFsoD3mF3LoeoX3zyQVmQ0GbT4kRlnYsJIjojSUbpV+9WpV5qYKiBE5ErVQ5aqgXXRSr+rGMpFuyEphHwoxAbzkLE1OAe4/JPtsomilUBpscC8GhSwk6CXHKV/w+LPn2FRxcg6VWy+w59TPWQ707aosl/CT3Xl7bNXy/1pg0UVQ3M/Wo/1qUNDVR6khaa959pYzJuE7mLXAZ0zMaxh+IHCiWUNfXBDav7Wkio9TRwCnePosGkTu+5RNXgrmUL2Sju0QoCE8KnwANiwX+I78ldvM8gPYV9BZDjRw5V4GWQNStfYVc= X-Forefront-PRVS: 0075CB064E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(107886002)(77096005)(97736004)(4326007)(106356001)(105586002)(15975445007)(76176999)(586003)(6862003)(118296001)(50986999)(2950100002)(33646002)(6116002)(5001770100001)(19580395003)(5660300001)(19580405001)(92566002)(2906002)(3846002)(47776003)(189998001)(50466002)(86362001)(48376002)(2201001)(81156014)(81166006)(101416001)(8676002)(50226002)(5003940100001)(36756003)(7736002)(7846002)(305945005)(229853001)(42186005)(68736007)(66066001)(4001430100002)(7099028)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR0501MB837; H:promb-2s-dhcp95-136.eng.vmware.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (EX13-EDG-OU-002.vmware.com: aditr@vmware.com does not designate permitted sender hosts) Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR0501MB837; 23:LGY338l0xTEoMRjY1QCGwaGElkgoVheWZgoppjZp?= =?us-ascii?Q?v/xXuoiI7UbKiol1Q7CrlV/mIfmLnMg6IOpdI7iaLPkqPBTadcqFfgeI4zwR?= =?us-ascii?Q?D38PzjAGWvlsD1ZnUGUfal4pLQri+W85YfHzp5JEhMHsh2/S2S/AuOGLCr/6?= =?us-ascii?Q?TtJJuEAZ2D4oUTVeP6cxvF4p13Sjyi91jUHPhHM/rYuYrlg723M7sv3mlL/C?= =?us-ascii?Q?vi5fpDMLbYesdkWyFOLsN+djlWIN+GHToBPFl1X2xOfFsrCBNPIzxwbbHUhP?= =?us-ascii?Q?mpBP3oEK73WAmtyj0sbMmuQLfG+mIjgDYo0BZCT+b4mEpCqncPrbQELvsbO/?= =?us-ascii?Q?FHacwdtR1KxzHkS6hDkb4rfaoniNFQL5I1qyvqstrd5MqVMgazdoHth+5+om?= =?us-ascii?Q?1F6hB7wMpw5HRGe5Wk6AkT0ZSfvKCTU0320YXpZ6SThh3NqQ6j6oInaC+Na1?= =?us-ascii?Q?Xs5b+wGwEP4+IBhEPqckWUlV1Wh8hxfZopZ0kPIPAE9uaBzUf2HgDEB8uyQL?= =?us-ascii?Q?Cneryd2pxCy4F3xAyWjykFQnYLljOBW9nf6dHZTipz7aqvXU/MOKz+qF5bYF?= =?us-ascii?Q?fZvAtYBmkhjDrjLjjMUZLjsdrDrC8oVm04bjQZqas4aF9/qjPDcmEAPpG6MA?= =?us-ascii?Q?WST5FCanz/BnYuhkbzv4j3C/8kIol6ptAgbzqwz4CtpcCWUp8xeuPTRcJ8p4?= =?us-ascii?Q?QwJLMggQBJs5w2hNG5IQy1iDorbKKJpOYiypBzw9c6Wv41pFiv0jyLtXX419?= =?us-ascii?Q?BfG++QbHvczrNv3ytFbBY6YPsEIhM/a6QmR1OMbgHYMyJfSL3qszqsKshGkJ?= =?us-ascii?Q?urKbc3iUb+KZY1O5foCikGtXNQ2xScKuSOl1S6QPXuNKQsgvHq0Di1NofN46?= =?us-ascii?Q?f0un+oNXpyC0Mwp+tinvnotTZz+nVlqqTywypuN8vPLYsFJduEAPSdQn0Dy8?= =?us-ascii?Q?zkdWoWiv5kMZJz2RgK7g14i2rburARyuFPVjP+NCsOuAvRtqHY5EFA/h2bEN?= =?us-ascii?Q?Z6BF9Hxpn7OqLPFspBZeaKhuw43lHTG4iESIBQ0HiiVBn7UHQGHIg/PE2NBe?= =?us-ascii?Q?qUYguxr0fQkYxfGqqxZBMSUj96DWepghrXhbx5ny7zPxxAP7+JqIYvS1TACp?= =?us-ascii?Q?p21jyA/EX2dJa663y2XtNak9m+Xfwp6nIkYnezEmon9S/bhTP84H9xsd6NhG?= =?us-ascii?Q?7fM+2v+ifYl5hjY7ecCLkIaYoinVigKLZhNYONwCPlTkbLarKGZAOAfYyQ?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 6:TMkPyTfKsmn3T5rV37N0OCFqEYRviYHTeaXjandR6/iPrVn45we1E/ZavGHK9hwbkN8QVbkHXyfgLoUBsGSqP4YI+Akd/uspFx7AevDsv4p9m1w1Swb4Omhg1kNfXDyENKHF2HvialyJYwUXSPLNAtwJp/bc4Cp1s4BYZakW54Yy3wouOE/sa4bphLOeWxiwY6RC2ZKWH2YJXRYYjeHRyA0x/NKKK8w7Od/GeIBMIpae36qZA9p7eM7fmrir6Ag8M8aJYAcHhB6AgkaE9yPuX9ZxCuvPlRdzQHmQEC4B0To=; 5:qGctJn/2RwPAvKSy7WE7Kf43dGwhUr3HhhuF3toTchSqyowPgPlFUmvjV+D2g83WiJxFO3YvRsvS7R4s1dOW//HgMwYsxiYAcToSPI73YfkzokXdInFjnDAVYJQFo/TQEI1ZyJsuevgYBTiQHStMqg==; 24:4ryUUTARnL+MFBJ3IX2R/akeNbVmECiOwjoSo69kkmfQPLT2kV+MQISKK/o9QzDwMnWdT2JjlVDyWgTsIR1AloJ7asIVaJmsPTnwPnuR78w=; 7:DzwUrn+oq+o7B4r7DGV9yDIZA+ElrHDgK+cL43nvs0xd2hos3N9LZ301Zp6YYYBZTlPytsvaOBx3Cin7cOtN5/5YmAQrBdEYvE2aVzdeHSm6SnGn39nuFqrxQjl6GJwLk4dYwfxSc/ebG8s2g1E+VWZ/CGpM8l4TRIPlGUAR5DQaOGpu2bvtAmGgLT/9WM5c8xqsSAN8uINaj/oJfMA2vAInoBdN6/IfVt2PsgZVSHNqiNKIODfoEvIHP0lHeaU7OwsljCG4wBtctqJyCvtXgcJEQd4mhg1yEoLgbC0PndOO5pvrvxm6DgXqj0wcIh/5 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 20:3aDVMWs/QUhMbkJ/bJsk9Q+nv5c0iEByncCYdwhMrPP803rRYIkNAXassMlJTtIVUhAH1SIp5vJ5shRZX0VtTDn0+0Ec+zoi2pH8+PBcKmqWay80VzZUOqLlNTz2OG0PAoPCayBhJvc2VPEySI1ZaOdwHUXkHIBX86YFyr9X9KQ= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2016 23:22:23.1585 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR0501MB837 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); +}