From patchwork Wed Aug 3 23:27: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: 9262409 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 7135B6048B for ; Wed, 3 Aug 2016 23:48:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6092E27FB6 for ; Wed, 3 Aug 2016 23:48:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 552AD28068; Wed, 3 Aug 2016 23:48:52 +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 23F2327FB6 for ; Wed, 3 Aug 2016 23:48:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933192AbcHCXsu (ORCPT ); Wed, 3 Aug 2016 19:48:50 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:33503 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758472AbcHCXrg (ORCPT ); Wed, 3 Aug 2016 19:47:36 -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; Wed, 3 Aug 2016 16:27:30 -0700 Received: from EX13-CAS-001.vmware.com (smtp-inbound.vmware.com [10.113.191.51]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 96CBEB06CE; Wed, 3 Aug 2016 16:28:20 -0700 (PDT) Received: from EX13-MBX-TERM.vmware.com (10.113.191.143) by EX13-MBX-014.vmware.com (10.113.191.34) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Wed, 3 Aug 2016 16:28:20 -0700 Received: from EX13-CAS-002.vmware.com (10.113.191.52) by EX13-MBX-TERM.vmware.com (10.113.191.143) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Wed, 3 Aug 2016 16:28:20 -0700 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (10.113.170.11) by EX13-CAS-002.vmware.com (10.113.191.52) with Microsoft SMTP Server (TLS) id 15.0.1156.6 via Frontend Transport; Wed, 3 Aug 2016 16:28:20 -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=qsPjhOMhdo1b+ex/NMCLxNY3Hg8VpMaZZ5wjbfeKht4=; b=RPq8BMXieUBLAXwAUEsDDTrFVHuRPronQBe+MIr33Fb6cQ7hDOsh5+QH/xq8vw4FAjzpsGt8IQjttByymGNxYobl/v86vAAx2cBS4k4wCcQPsfJtrrZXaE5Sc0g/ITq8voV7/V0jtXKR7jfv+W9xXR1luAaFg3TyP/jie8b9oyI= 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 SN2PR0501MB847.namprd05.prod.outlook.com (10.160.14.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15; Wed, 3 Aug 2016 23:28:15 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , Subject: [PATCH v3 05/15] IB/pvrdma: Add paravirtual rdma device Date: Wed, 3 Aug 2016 16:27:34 -0700 Message-ID: <1470266864-16888-6-git-send-email-aditr@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470266864-16888-1-git-send-email-aditr@vmware.com> References: <1470266864-16888-1-git-send-email-aditr@vmware.com> MIME-Version: 1.0 X-Originating-IP: [208.91.1.34] X-ClientProxiedBy: CY1PR12CA0084.namprd12.prod.outlook.com (10.163.230.52) To SN2PR0501MB847.namprd05.prod.outlook.com (10.160.14.145) X-MS-Office365-Filtering-Correlation-Id: 608a732f-1547-4814-d46c-08d3bbf5d895 X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB847; 2:DTVtrzOTyBjliCGeXXk3WXeIVKjMrjEphr/u+jjVbHQcQagUtc4OIzS329cr0ycOQElULH048iqBErz/RUg8j00G1X8u8hcEi5jHQNk4WqYMRGbhPV3QZuEba4DcDxivuhOe09QLUuWKJPEpdE1zo6tpb0uvJpvWBuPCSoOtys/YjtZVEo9rQjmsXyaJVQdB; 3:u9z1AQkSa4kOjWWHIrP7/1l5tyndweTdFv+hQrmn722V81NcN5FHVoI/giUuP9k2KKhPqMGndCZ8lBg+TcMO04RgMguAK6HTYGT1NPn3R6bfI5zP0ZTwsvuzMSR9J5ZA X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR0501MB847; X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB847; 25:QV0e/4Rn1RCWGOIjR2JR3DEmby9/hzYd9We1xeke0GaiTL5Amh3pZx9Qv/aKiDatrns/yLMXnc/KBRwJ4bjOUHs5qWV5rAEB//KonrmHRZ2IZ3epDJ8faWUB5rn+5EXhr49pN33C1A+UkD//FQE7gpfHoZV1XBWSnaIMNFDTzVdwXQf+lN9y0EDt/nkqgOnKGe7wRzW1ap9KVVc6ukg+xZ240TExotIVUeyAGr9qZXc8dR5oWbzqhsNVO7L9vW6yxitn+IZfESuyIsNWosgEmN23mubEhE6K8SA6bmH3++afG6Zas76hUeoFyJlrJNJPyfwkdurFFHj8EXIBx5TEDE0lKHUmhjTMoCtxonb1sosHT9RLPfpw4KjWGn1FDcuqwyxzr+s4OHK0giUt1mTrQzLSSPPsvbGEBcs/WKCD3rK7GhOZ9ObmUlDATyiLmAibI45cJy9t+q7o7LdAnYE3VpiWuUFNE5rdTZ8GvT1qw0nFKrwXTgHg7SEYQWthw/EvlDnklndgCgw27BvQWot8m2sJ8Ci/BGoKtuXfTk/MT2vlI+Q8d6IpUQk2X5mF4DlvGUV/z+EO1XN+FX1Zs7H8/l5Q4RKyOxqFw3VtCpniJH0sRhY/BQhrNlQqDaIvfgTIBYRdhJcnHFEdhvGU8x8Q6FoXPoPS+dq/paQ9MpBXymJetnZ8YPKgFZOH15eTHO4IYkJhwaXI1cFrnLdlpeT8mlD6TK97ULjnJnPniZ5+jDYJJBAQLbnDvVYnViLDwViSYsx067BOqDUHNbAl6EH8x89qFVgJmBb2ZJ2r1fRoBTqV3zOllD2wpUFsDrbGktb4 X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB847; 31:M/1JiiPEMfyle02GS/46OlfkfTjofyaGltLy7gYkhWZ7sbt4PKNlFjcopBGJ2jErEPqGmhJCy7GJ5mzdVODaAEQ1LwbO+FHdLrjb3J/mTIF2BUhoK1SjPzmLVrwRHQh2fAXl5DxpFW4MCgtzHwTJ+wQ2LdH1r1kRIire6tX04BbyBZZ5clfC3QElUMiA00e9ZOvU/LW40QcjM9eEgsT5tihnOm7n+3Towm++5b69ulg=; 20:qipF7JaytkRZdU6XyO01viJYPW7iFJ0l0abl2BWQUWDW1uuQkpWOX2xPjby8HkQqsRjI72l/DwubSgEV+IaQr/0IF88LciVZiU8Hf92L5vZqII3razCgHTfzh+ZOZjAnEhe9/a3lJK3swzJjpGiPkdrB7kECx1O5JkEuBO6SuQKzHzEaIZkF7ApI/YzKUQRjsA7WB2seqJ0Uc/LrMx6L99vfh/FHi6KsIvcx8yTY++1q50xU/j85iZfLELkxoHhR X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(61668805478150)(22074186197030); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:SN2PR0501MB847; BCL:0; PCL:0; RULEID:; SRVR:SN2PR0501MB847; X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB847; 4:U2kZ7vcHdhpDKM4U/3kiBa1V/h2q9am9ehRVfhBA4qxNUJpAsun24aMXexs2bTGmUJ516ZqMMXfhBccI9RuZVbMGLYEQcRf/7ru1KoJYZXWrDLGefEkdtmXeV78V4C+U/bjGFrqL1Ok5C8oqzDZ5e6VSSaMZkJ39UhaWCanr5ae6jwh4XsKkBCqILZ4EvkZOg39xW1/9HNnusJtZxZHjqq6Fyd1fmnfQNHILSGWnhtuGwl8XNTOeCT/7aknjxtBKmA2G9+lF+LcudXwfS5oYU5cPQshitZR7L2bEFKAWBNV9Ejwyjgki/iaC4jo5Vg74R6yfilFjpdktoPojML+6mAHGwZVMP86+Ry0NMkRcrL+G/atbdjx3ijOihHgQYRcsT+ZR2Yr9LITHaEXaAzg3U1c78ym7lWqgG3zqLeBifpbbOdBU+2QUMASJrt5J1SNXXEZwzy4inFVGwsNtUzoMdH2oL56n3ny8F74By4HIOHk= X-Forefront-PRVS: 00235A1EEF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(199003)(189002)(4001450100002)(66066001)(106356001)(189998001)(33646002)(92566002)(107886002)(5001770100001)(77096005)(15975445007)(229853001)(48376002)(50466002)(101416001)(97736004)(2950100001)(42186005)(586003)(47776003)(68736007)(76176999)(50986999)(4001430100002)(2906002)(105586002)(7846002)(7736002)(305945005)(81156014)(50226002)(86362001)(81166006)(8676002)(6116002)(36756003)(3846002)(5003940100001)(19580405001)(19580395003)(2201001)(4326007)(7099028)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR0501MB847; H:promb-2s-dhcp95-136.eng.vmware.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (EX13-EDG-OU-001.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; SN2PR0501MB847; 23:Fhr12yKDUZF/sS1xxVF6vzxfhYnesZMzfLNU6QX8?= =?us-ascii?Q?YaB4eAgODS2iaR9fIBEIZoeA9UFXkSHIXAVcrqiKYgtfLUHw/RcKCx4ATtd4?= =?us-ascii?Q?CS02KEab8xqBWC7iBliIzjA6d0G5R+OprzvSJlqDZ28FdlyiMyTIAf3KvtsM?= =?us-ascii?Q?wSUcIxMjRu8zxVFn1FhRJ1Y22a+BdGfJoMYhDVFO9wDbBZasdwq4buqmqGL9?= =?us-ascii?Q?ROc/9tc1Y4LUgx6kSD/bDre6DWzXkSf9w2N4z24b/NZpSHMOsAX8pBToH6UY?= =?us-ascii?Q?BUAQpngPOPtuINRCiors2+CjsflOKx6k3pox1LH8wVwBCHIQg2xamIM+V+MM?= =?us-ascii?Q?Dk6mqCFib2yxZdpUvwsH9/FAqZw0Z85iKsKaFkG3pghBE02YlijqBWNNbi70?= =?us-ascii?Q?eTdEw/YIxvjyqy00WxWkLnQah5DQNHpY4y4XHP8FNL2Gm1nkoaj/g11zmpDc?= =?us-ascii?Q?P3RAsfXxr0fN/H0Wl0GxuWNjlbHJY1I1RwUDvG9bu7DuoJQqrPjLn85+OZ8p?= =?us-ascii?Q?jhRbPZ28joCQAVM1RB9ldTpvBMbY7z3/FvIcGF2JTfN6OXSBczNmfCxYmpBe?= =?us-ascii?Q?idaSkES+zfiQ6J9qKnaZKEKqegqJEurJN96Tmm7q8oE9WoI1ypRdE4BxkdvB?= =?us-ascii?Q?NdXRRsVX4ws8Bn9srRKraxuJQYGhv2WIchIMUcr4KD8e88D8GDFuRVHxdCcb?= =?us-ascii?Q?M0OydP6Ep8rrTzkXroBvBBhYGb31yMg9eVfbNTc4l6VaOpwcTl/H3YuB283e?= =?us-ascii?Q?KTrLHs2dz4yo8Sdu9pcn2CBQt6+uuoXg16kHk1Sr97P6JV7JeylQT9YQra9U?= =?us-ascii?Q?x1BPNygyBVskpqvAOvGNqVGseiJDs1q/djcWDmbUbSl6jpPRPHdjnAkXn//C?= =?us-ascii?Q?ApqmccJ+TnS+pkRHnQa1Vk85khm39I0nApRwvPdoFTRjL4PQm48T6vC6hL3d?= =?us-ascii?Q?LHsclb4NsPaMVo/1rNHCThTL7+jQJxlS5biJVMzTazHciX3zbPCgXDoyjtF9?= =?us-ascii?Q?msEoBEV4tRXlEW9rnBZFdt+QW8yvVv8yMr+lclw1m90Eq0CnQKMI4xsvpWOx?= =?us-ascii?Q?junEOkC8bRD+5eem/xzjGk+Lb069N5eE/KmiptxbrxuHDvCwfTtbMvmaJazl?= =?us-ascii?Q?rEdD2yAwi6VXjwTzS+2zNZgfS0HTAsoxuBdpcjyfvq/xWfGO9SLyAvfs0btY?= =?us-ascii?Q?hBgKzHGMVXmuuMP/6ejrI0N+dxHaRZgdDPlsUtv9imL3hTxFSyPTsdFt4w?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB847; 6:GMe0Vil83nniTex4PFej2l6khl9QO+YEVu+IjQNtw5CG6T4IUDKLhMZrii1ws1yT9lQ3zBqT8mDqbsLXJ0WdxL3DZGeL4DtoKdcvdZwKMGVkHP5bctHRFxVmdJdJiDjpF4U4PZZA3YWet5AH5ZWxvNpLty+WKxcJpMReLcfroSNQ+jAMHhb4rl5hhT04ZfsX1ZHa/SfF2m4rJw66GSDwYOinZCY77N7BAwJMmvLTGpJdi2uPkA3q8JD4syUsNvvQZpnqDUJlf5k4HrhI0Orsp2Jo295PxH/MxbB+bBkN9Ik=; 5:YhEVq+5v+5gSqA69L44XSOpADuSG3O2NUcY0sy84/vu2RgDPISAQDTqMHYdcc/gu7FrLiwO4bvCFcmtG8e+LovmWevzpuRx3ktrgqeaE2O4RWNwKP1mmYlqocz2QFqsxC6VM0GtmqcTp4aziI6ZXHA==; 24:SsICu7mCoP0zVZAwC9y3SMeVvdqwPEDq+B0euL+r9wcaoC0zWEKgN2oWyKGLm/arBMFvS5f0huCMt5NjGdBQKgQrQAGwGsdXPGG4WMuPUF8=; 7:wKwY6iHWuM4dCXlooiCY6roqX63XDE9HrObky0JDcbWtYcP8cZ85vS260admY6IUdWE4pTY427XvSu842GI7pFQ7Xl7xYMgT2bG4qLHH3jBA2TZXya10Wfik2sS00cTDWvxXNfC2CUIG/6cjb8wHf5Ly28kxvHhb2Y/vmYuRKxIkkZ4oeqwk/c0hBdv4hi0+TVOkMgO6bPQUDF8LG/ATNl1YbMtBupeycyhqUm9nUyXJ/rw7XDJLHIoFQVVdQQZ+ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB847; 20:A3PRVKCRCsZLBG1UlEsSL7EfS+8tCfaxM6sH3H+0NE6VHFPY2b7BXoUS8REhIPDmnnCKus9TVNIOVLWynLrrKcXwMW/Z9vVIh3lccuJdbm7ZOgyFv2wDRTq/KqWuYC+le6EMouzqhhF/2SDmUVhRql93kYfwOXQ7sGGkyMYowbk= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2016 23:28:15.3513 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR0501MB847 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 main device-level structures and functions to be used to provide RDMA functionality. Also, we define conversion functions from the IB core stack structures to the device-specific ones. Changes v2->v3: - Removed VMware vendor id redefinition. - Removed the boolean in pvrdma_cmd_post. Reviewed-by: Jorgen Hansen Reviewed-by: George Zhang Reviewed-by: Aditya Sarwade Reviewed-by: Bryan Tan Signed-off-by: Adit Ranadive --- drivers/infiniband/hw/pvrdma/pvrdma.h | 456 ++++++++++++++++++++++++++++++++++ 1 file changed, 456 insertions(+) create mode 100644 drivers/infiniband/hw/pvrdma/pvrdma.h diff --git a/drivers/infiniband/hw/pvrdma/pvrdma.h b/drivers/infiniband/hw/pvrdma/pvrdma.h new file mode 100644 index 0000000..8a45fcc --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma.h @@ -0,0 +1,456 @@ +/* + * 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. + */ + +#ifndef __PVRDMA_H__ +#define __PVRDMA_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pvrdma_defs.h" +#include "pvrdma_dev_api.h" +#include "pvrdma_verbs.h" + +/* NOT the same as BIT_MASK(). */ +#define PVRDMA_MASK(n) ((n << 1) - 1) + +/* + * VMware PVRDMA PCI device id. + */ +#define PCI_DEVICE_ID_VMWARE_PVRDMA 0x0820 + +struct pvrdma_dev; + +struct pvrdma_page_dir { + dma_addr_t dir_dma; + u64 *dir; + int ntables; + u64 **tables; + u64 npages; + void **pages; +}; + +struct pvrdma_cq { + struct ib_cq ibcq; + int offset; + spinlock_t cq_lock; /* Poll lock. */ + struct pvrdma_uar_map *uar; + struct ib_umem *umem; + struct pvrdma_ring_state *ring_state; + struct pvrdma_page_dir pdir; + u32 cq_handle; + bool is_kernel; + atomic_t refcnt; + wait_queue_head_t wait; +}; + +struct pvrdma_id_table { + u32 last; + u32 top; + u32 max; + u32 mask; + spinlock_t lock; /* Table lock. */ + unsigned long *table; +}; + +struct pvrdma_uar_map { + unsigned long pfn; + void __iomem *map; + int index; +}; + +struct pvrdma_uar_table { + struct pvrdma_id_table tbl; + int size; +}; + +struct pvrdma_ucontext { + struct ib_ucontext ibucontext; + struct pvrdma_dev *dev; + struct pvrdma_uar_map uar; + u64 ctx_handle; +}; + +struct pvrdma_pd { + struct ib_pd ibpd; + u32 pdn; + u32 pd_handle; + int priviledged; +}; + +struct pvrdma_mr { + u32 mr_handle; + u64 iova; + u64 size; +}; + +struct pvrdma_user_mr { + struct ib_mr ibmr; + struct ib_umem *umem; + struct pvrdma_mr mmr; + struct pvrdma_page_dir pdir; + u64 *pages; + u32 npages; + u32 max_pages; + u32 page_shift; +}; + +struct pvrdma_wq { + struct pvrdma_ring *ring; + spinlock_t lock; /* Work queue lock. */ + int wqe_cnt; + int wqe_size; + int max_gs; + int offset; +}; + +struct pvrdma_ah { + struct ib_ah ibah; + struct pvrdma_av av; +}; + +struct pvrdma_qp { + struct ib_qp ibqp; + u32 qp_handle; + u32 qkey; + struct pvrdma_wq sq; + struct pvrdma_wq rq; + struct ib_umem *rumem; + struct ib_umem *sumem; + struct pvrdma_page_dir pdir; + int npages; + int npages_send; + int npages_recv; + u32 flags; + u8 port; + u8 state; + bool is_kernel; + struct mutex mutex; /* QP state mutex. */ + atomic_t refcnt; + wait_queue_head_t wait; +}; + +struct pvrdma_dev { + /* PCI device-related information. */ + struct ib_device ib_dev; + struct pci_dev *pdev; + void __iomem *regs; + struct pvrdma_device_shared_region *dsr; /* Shared region pointer */ + dma_addr_t dsrbase; /* Shared region base address */ + void *cmd_slot; + void *resp_slot; + unsigned long flags; + struct list_head device_link; + + /* Locking and interrupt information. */ + spinlock_t cmd_lock; /* Command lock. */ + struct semaphore cmd_sema; + struct completion cmd_done; + struct { + enum pvrdma_intr_type type; /* Intr type */ + struct msix_entry msix_entry[PVRDMA_MAX_INTERRUPTS]; + irq_handler_t handler[PVRDMA_MAX_INTERRUPTS]; + u8 enabled[PVRDMA_MAX_INTERRUPTS]; + u8 size; + } intr; + + /* RDMA-related device information. */ + union ib_gid *sgid_tbl; + struct pvrdma_ring_state *async_ring_state; + struct pvrdma_page_dir async_pdir; + struct pvrdma_ring_state *cq_ring_state; + struct pvrdma_page_dir cq_pdir; + struct pvrdma_cq **cq_tbl; + spinlock_t cq_tbl_lock; + struct pvrdma_qp **qp_tbl; + spinlock_t qp_tbl_lock; + struct pvrdma_uar_table uar_table; + struct pvrdma_uar_map driver_uar; + __be64 sys_image_guid; + spinlock_t desc_lock; /* Device modification lock. */ + u32 port_cap_mask; + struct mutex port_mutex; /* Port modification mutex. */ + bool ib_active; + atomic_t num_qps; + atomic_t num_cqs; + atomic_t num_pds; + atomic_t num_ahs; + + /* Network device information. */ + struct net_device *netdev; + struct notifier_block nb_netdev; +}; + +static inline struct pvrdma_dev *to_vdev(struct ib_device *ibdev) +{ + return container_of(ibdev, struct pvrdma_dev, ib_dev); +} + +static inline struct +pvrdma_ucontext *to_vucontext(struct ib_ucontext *ibucontext) +{ + return container_of(ibucontext, struct pvrdma_ucontext, ibucontext); +} + +static inline struct pvrdma_pd *to_vpd(struct ib_pd *ibpd) +{ + return container_of(ibpd, struct pvrdma_pd, ibpd); +} + +static inline struct pvrdma_cq *to_vcq(struct ib_cq *ibcq) +{ + return container_of(ibcq, struct pvrdma_cq, ibcq); +} + +static inline struct pvrdma_user_mr *to_vmr(struct ib_mr *ibmr) +{ + return container_of(ibmr, struct pvrdma_user_mr, ibmr); +} + +static inline struct pvrdma_qp *to_vqp(struct ib_qp *ibqp) +{ + return container_of(ibqp, struct pvrdma_qp, ibqp); +} + +static inline struct pvrdma_ah *to_vah(struct ib_ah *ibah) +{ + return container_of(ibah, struct pvrdma_ah, ibah); +} + +static inline void pvrdma_write_reg(struct pvrdma_dev *dev, u32 reg, u32 val) +{ + writel(cpu_to_le32(val), dev->regs + reg); +} + +static inline u32 pvrdma_read_reg(struct pvrdma_dev *dev, u32 reg) +{ + return le32_to_cpu(readl(dev->regs + reg)); +} + +static inline void *pvrdma_page_dir_get_ptr(struct pvrdma_page_dir *pdir, + u64 offset) +{ + return pdir->pages[offset / PAGE_SIZE] + (offset % PAGE_SIZE); +} + +static inline enum pvrdma_mtu ib_mtu_to_pvrdma(enum ib_mtu mtu) +{ + return (enum pvrdma_mtu)mtu; +} + +static inline enum ib_mtu pvrdma_mtu_to_ib(enum pvrdma_mtu mtu) +{ + return (enum ib_mtu)mtu; +} + +static inline enum pvrdma_port_state ib_port_state_to_pvrdma( + enum ib_port_state state) +{ + return (enum pvrdma_port_state)state; +} + +static inline enum ib_port_state pvrdma_port_state_to_ib( + enum pvrdma_port_state state) +{ + return (enum ib_port_state)state; +} + +static inline int ib_port_cap_flags_to_pvrdma(int flags) +{ + return flags & PVRDMA_MASK(PVRDMA_PORT_CAP_FLAGS_MAX); +} + +static inline int pvrdma_port_cap_flags_to_ib(int flags) +{ + return flags; +} + +static inline enum pvrdma_port_width ib_port_width_to_pvrdma( + enum ib_port_width width) +{ + return (enum pvrdma_port_width)width; +} + +static inline enum ib_port_width pvrdma_port_width_to_ib( + enum pvrdma_port_width width) +{ + return (enum ib_port_width)width; +} + +static inline enum pvrdma_port_speed ib_port_speed_to_pvrdma( + enum ib_port_speed speed) +{ + return (enum pvrdma_port_speed)speed; +} + +static inline enum ib_port_speed pvrdma_port_speed_to_ib( + enum pvrdma_port_speed speed) +{ + return (enum ib_port_speed)speed; +} + +static inline int pvrdma_qp_attr_mask_to_ib(int attr_mask) +{ + return attr_mask; +} + +static inline int ib_qp_attr_mask_to_pvrdma(int attr_mask) +{ + return attr_mask & PVRDMA_MASK(PVRDMA_QP_ATTR_MASK_MAX); +} + +static inline enum pvrdma_mig_state ib_mig_state_to_pvrdma( + enum ib_mig_state state) +{ + return (enum pvrdma_mig_state)state; +} + +static inline enum ib_mig_state pvrdma_mig_state_to_ib( + enum pvrdma_mig_state state) +{ + return (enum ib_mig_state)state; +} + +static inline int ib_access_flags_to_pvrdma(int flags) +{ + return flags; +} + +static inline int pvrdma_access_flags_to_ib(int flags) +{ + return flags & PVRDMA_MASK(PVRDMA_ACCESS_FLAGS_MAX); +} + +static inline enum pvrdma_qp_type ib_qp_type_to_pvrdma(enum ib_qp_type type) +{ + return (enum pvrdma_qp_type)type; +} + +static inline enum ib_qp_type pvrdma_qp_type_to_ib(enum pvrdma_qp_type type) +{ + return (enum ib_qp_type)type; +} + +static inline enum pvrdma_qp_state ib_qp_state_to_pvrdma(enum ib_qp_state state) +{ + return (enum pvrdma_qp_state)state; +} + +static inline enum ib_qp_state pvrdma_qp_state_to_ib(enum pvrdma_qp_state state) +{ + return (enum ib_qp_state)state; +} + +static inline enum pvrdma_wr_opcode ib_wr_opcode_to_pvrdma(enum ib_wr_opcode op) +{ + return (enum pvrdma_wr_opcode)op; +} + +static inline enum ib_wc_status pvrdma_wc_status_to_ib( + enum pvrdma_wc_status status) +{ + return (enum ib_wc_status)status; +} + +static inline int pvrdma_wc_opcode_to_ib(int opcode) +{ + return opcode; +} + +static inline int pvrdma_wc_flags_to_ib(int flags) +{ + return flags; +} + +static inline int ib_send_flags_to_pvrdma(int flags) +{ + return flags & PVRDMA_MASK(PVRDMA_SEND_FLAGS_MAX); +} + +void pvrdma_qp_cap_to_ib(const struct pvrdma_qp_cap *src, + struct ib_qp_cap *dst); +void ib_qp_cap_to_pvrdma(const struct ib_qp_cap *src, + struct pvrdma_qp_cap *dst); +void pvrdma_gid_to_ib(const union pvrdma_gid *src, union ib_gid *dst); +void ib_gid_to_pvrdma(const union ib_gid *src, union pvrdma_gid *dst); +void pvrdma_global_route_to_ib(const struct pvrdma_global_route *src, + struct ib_global_route *dst); +void ib_global_route_to_pvrdma(const struct ib_global_route *src, + struct pvrdma_global_route *dst); +void pvrdma_ah_attr_to_ib(const struct pvrdma_ah_attr *src, + struct ib_ah_attr *dst); +void ib_ah_attr_to_pvrdma(const struct ib_ah_attr *src, + struct pvrdma_ah_attr *dst); + +int pvrdma_uar_table_init(struct pvrdma_dev *dev); +void pvrdma_uar_table_cleanup(struct pvrdma_dev *dev); + +int pvrdma_uar_alloc(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar); +void pvrdma_uar_free(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar); + +void pvrdma_flush_cqe(struct pvrdma_qp *qp, struct pvrdma_cq *cq); + +int pvrdma_page_dir_init(struct pvrdma_dev *dev, struct pvrdma_page_dir *pdir, + u64 npages, bool alloc_pages); +void pvrdma_page_dir_cleanup(struct pvrdma_dev *dev, + struct pvrdma_page_dir *pdir); +int pvrdma_page_dir_insert_dma(struct pvrdma_page_dir *pdir, u64 idx, + dma_addr_t daddr); +int pvrdma_page_dir_insert_umem(struct pvrdma_page_dir *pdir, + struct ib_umem *umem, u64 offset); +dma_addr_t pvrdma_page_dir_get_dma(struct pvrdma_page_dir *pdir, u64 idx); +int pvrdma_page_dir_insert_page_list(struct pvrdma_page_dir *pdir, + u64 *page_list, int num_pages); + +int pvrdma_cmd_post(struct pvrdma_dev *dev, union pvrdma_cmd_req *req, + union pvrdma_cmd_resp *rsp); + +#endif /* __PVRDMA_H__ */