From patchwork Tue Jul 12 19:36:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9226059 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 ABA7760871 for ; Tue, 12 Jul 2016 19:37:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95D222756B for ; Tue, 12 Jul 2016 19:37:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A68E27F94; Tue, 12 Jul 2016 19:37:43 +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 2A58327D85 for ; Tue, 12 Jul 2016 19:37:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751640AbcGLThg (ORCPT ); Tue, 12 Jul 2016 15:37:36 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:29971 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751617AbcGLThc (ORCPT ); Tue, 12 Jul 2016 15:37:32 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Tue, 12 Jul 2016 12:37:10 -0700 Received: from EX13-CAS-006.vmware.com (ex13-cas-006.vmware.com [10.113.191.56]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 661F040718; Tue, 12 Jul 2016 12:37:31 -0700 (PDT) Received: from EX13-CAS-003.vmware.com (10.113.191.53) by EX13-MBX-005.vmware.com (10.113.191.25) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 12 Jul 2016 12:37:31 -0700 Received: from NAM02-CY1-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; Tue, 12 Jul 2016 12:37:30 -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=ApyLQQXYzoVRPHjfzXTgAU0R1BUTv4i24X4p4iIfiQg=; b=O+id7JRQfAUVtx8WdS0/k/m0fTKMTJV0ifrvutd1rUFXSsu8OeGABR+kzRUJLkVUw+q9XKHEDBBry4mb5R3HhLQOBg2WluhiAg2n4eEGbGZ+bOIRfC+xWAsGzmeCQOhtPPKw3wNbQC+H3uDW8Envdh/8hYV+3c9JAKNsCtO46Ow= 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 BLUPR0501MB834.namprd05.prod.outlook.com (10.141.251.148) with Microsoft SMTP Server (TLS) id 15.1.539.14; Tue, 12 Jul 2016 19:37:26 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , Subject: [PATCH v2 01/15] IB/pvrdma: Add paravirtual rdma device Date: Tue, 12 Jul 2016 12:36:31 -0700 Message-ID: <1468352205-9137-2-git-send-email-aditr@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468352205-9137-1-git-send-email-aditr@vmware.com> References: <1468352205-9137-1-git-send-email-aditr@vmware.com> MIME-Version: 1.0 X-Originating-IP: [208.91.1.34] X-ClientProxiedBy: SN1PR10CA0055.namprd10.prod.outlook.com (10.164.10.151) To BLUPR0501MB834.namprd05.prod.outlook.com (10.141.251.148) X-MS-Office365-Filtering-Correlation-Id: d3722e17-292e-47bb-4162-08d3aa8bf4f7 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB834; 2:Sw2KaBUk36o7DF+RzDXQozlpCOEfgxvXyRnpoBiP5NM7uXtf32LWhwzp7LSBGKOtnkS7KzH7x7NI82F/mx+5XGQ5T6fUXM8htXqKuPisD5sXlGZ1PkXgFD+C3qH7QJeiy7rgYjV4VsNiiDUVfWp75RgnVB7ij8rNwi01Pzz2ZjB4ByvigkfzayXd3bfAlqwf; 3:qu3cQUB9kjOyTqmAs6Gv4RGPUonLVhgewPp4477Fcsxz318Et4G7qz0Zd8hAU/YsyeZ882gzeSoNUjld65A2TsdLdiUJEK/Xz85pvcmvhUXhZJEy4NM+5ryNaiawiOEx; 25:Anm4XDzXBAvfjSrtHKN9vIgOs6mkF+7hInV9HR5smD4WhVatXemr56d58XAVx4vtafttGm8svetkce4VWQXeuUsd8U1ROpohbZvpr5Mg9Sb52snSYDc8a4lJDPTL65RCfHWevAJl0txLVIbBMEtDtKLV8t9ap475Njf3KuwvEBlnSX5ODVmdwW9nqIxxJwPmFK3+GKH/VqzgKpcsWDAdQMVI1RzWG+a8Z5qechhtRH7AAuZn/8L+y8BYaM2YcRhk1/KPRH52+66x4MXobxCaxXoEEsJm7HYUZ8/DosHxjss2+zNL1NDdBM5i0FBYZ2nrflez3sm8IJjIAPQLwpimKI3DLe1KHE1lCPvSsWS889UD41LOdIPUYm6eUDgZnxYw8LU6zuE76td4gmD8+lF4vGQ9fjZz7HVBmewagewD8Vc= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0501MB834; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB834; 31:CPhQr0FTPU03e3rO6PFhTX0Ep8EKkuOOuw3uhOdXCinxcyyRzsW5q6W6ED7+CWA+kD7aC97UmacPKC4N8kIpJWvF9XSoh6/4KoNhuopfqF+2BzS1ZfgZN3t7fSxzjPdgd5sKvkgBwyUKAJJpmXDvvMe9NpOsnYOPMnjrPUJQDRIqjnMfv9jnpwNNO2P6OT2JDUmGyE6bJh3ivsU03yDfmw==; 20:DJdtLvdBawt5oVP6HqaroImCumEbu+CyTB5WnB/3QFcy0VuNVt1xTWaPih4hAVmsu5j7MMmTz79Voj8cvwCJZdhKhmf+meKbPNpGhxY9IDZb88VPJILVbwgawAwSw7rno0+SNWelrOMruitzDSmPM8I2aGV4pmeINPd1oaksdn/x4Ft12goF3oS2ArqF5fqOLMUYAcARZU+xZQsvI1RNIuRX2/65dcQHDSo7hu75rILeHEyVvOHjoLa3AcFeaSrt; 4:8vmlzWa95jbd4NH/Bc5OcCcrl2Pmp71nshRXQqkRgnv2wv28h4nr8jaNsPr19pAzxVAEgO0OgJUhpUVDzYdV12eCBGzzR7ez5mzkSaRfupdsI1QnBNXjsv7A8NdiuTT6yOT/w4gsK1AUtbIba5HJKP4xPkbcoeslqcOgNktz8KCJq0MLJRkxPELiUs1jyRL/hmzQj822CIHoy4PWJUq9xr0PDr4Z59XPIfeVG+GvX6ALaoql3gy3JupDtHUv8KtmxPdTgLwuwJvt+CYE4cOVPx+ldpKG/DsTQ0DIAaewqznKz0wnvKUSPBGlkP6pAzpCtVUsM63zAiJomBRcpB0RHwNdmnvQ73zqOheM66q7sywejtwfN2YSEl/C5gfzkCQfi4ue69fsm+4ay36TZDcdI1nPh0GxUlOCqWamqGG8srR0vI8zuahj5mW7CKELg7XmAEjR36VqY TuMlHZ1OSBpRHx4G37IgoGZfHh3L36enHw= 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)(5005006)(8121501046)(10201501046)(3002001); SRVR:BLUPR0501MB834; BCL:0; PCL:0; RULEID:; SRVR:BLUPR0501MB834; X-Forefront-PRVS: 0001227049 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(979002)(6009001)(7916002)(199003)(189002)(305945005)(7736002)(50226002)(86362001)(4326007)(2906002)(42186005)(7846002)(68736007)(33646002)(229853001)(106356001)(50986999)(586003)(3846002)(2201001)(6116002)(15975445007)(97736004)(81166006)(81156014)(48376002)(36756003)(5003940100001)(19580395003)(19580405001)(47776003)(2950100001)(77096005)(66066001)(50466002)(4001450100002)(4001430100002)(101416001)(92566002)(189998001)(76176999)(105586002)(8676002)(107886002)(5001770100001)(7099028)(2004002)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0501MB834; 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-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; BLUPR0501MB834; 23:FAyG1U2nE8KOYbozFRGLcoXC8heMuIJle13d6ox1?= =?us-ascii?Q?URYQhSdkNBoeSw1f6S3UjUFW7jziZj6EERzov1v0xVFup/0BJ+3FMPwFPLJi?= =?us-ascii?Q?93abUcdQ8BrQMvCxmJTOkFiT47yOXaHZmkj/n7znyIaDdZMKXwWJtjcRawdd?= =?us-ascii?Q?dX6HkJlOewbzEDDhRYRf3mjlSibBn57cjOlmmlRzZ0kxqsMILO0+8VKu4qnW?= =?us-ascii?Q?32cl0miTcp+BJkk53GaM824ENr5RVJ6/p0crqYEyQvT1V9veGv7vDKh6SzPS?= =?us-ascii?Q?HqCJZnqyKPNlwqj9QKyZWZmG+CosdydEn1lDwu3RQV87/HJkk9zKdVfDRsjK?= =?us-ascii?Q?LR3wileWJXTXaQIQjPWhkqyxtnrzcjKTTnC04FVDZv6rrPZ6kRcbOioOdYlH?= =?us-ascii?Q?Bq+iPcLBt9xqrv5ovMSPx1qm41of64DlEwA56Q4koXyKIUCktdq+Cg1eWZKH?= =?us-ascii?Q?+8o24833iK9Wod9HHMxSv9+KOYIMtjLBpkgTF87iyGMIHx06up55N6ccUcy/?= =?us-ascii?Q?89NDo2Nnfl6L+MGMWLyz4/jZzYiFdyqkAWY+ChL6h+tPACYTTrcf6ir1z7Vx?= =?us-ascii?Q?dVShvQkZ0EnW4d+uH2BR8/0qIM9ngjWzXNnU9x12Kt3VJ2pplGClKaUxQYHs?= =?us-ascii?Q?P4toRdCgt8dxatLIiR8AmULXRvNYEgWDiQ9tZF07uphlYpwxzt5kGfAzrnmt?= =?us-ascii?Q?qx/g3aRGvb47+RE0BP6TS+km/7yxn/785sH2J2c2tDEtZbe31lD73S7k770d?= =?us-ascii?Q?/T+MwkRehHsx9KQpT3Wr661WndKB+V0lFb+i2mGH2YxaUzeZCkaTs/0NLk2V?= =?us-ascii?Q?izqYP2X/KcGAX/d7poXSPIFIslQc4d5HN1v9NSUS18bFw3/GKFqIoxR5iXRA?= =?us-ascii?Q?gOkJ5IKnvxv6jyeNkN7JKL9RH1mpnGh3bpZnx7ZocMciSsKNTgpKellPrmr/?= =?us-ascii?Q?6DGnPjuPN3++fTCUSN3vBN+gmhIp+AkDNS7CDaLm9dj5CSMaoLVBrPW8im8y?= =?us-ascii?Q?nuV9ixanf92efbusR/7yhrvrrmfgs0SO516CjJcLYz/MfDYbt9fg0rDZiJg7?= =?us-ascii?Q?CGpl2vL5uxxtRTfWnwMY+7NlT3O30Sp2mludKKrvbCYBZN2Ol8GB+4wR9AaY?= =?us-ascii?Q?L4NHrHjacc/6uWLtNb184fLCi9hTbZj488mtHuAs1rxVQlUbl28KWt/zxbAj?= =?us-ascii?Q?eXedbnN1n0rSDq8/YR0hzgpjqeh6bxpjEpcFeL/phaHGJaUp2tKI7OZUCB4N?= =?us-ascii?Q?mwPNJUkcc1Fh7rqWEvwH4BJvnjy6Vq7Rc/X/lJM4tWQABJn7WSCfP7xljjix?= =?us-ascii?Q?lW2qkwbHG/6fTqtvfkb8LBUINWHFWirIlEkfT6vM6X1a?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB834; 6:CAIgHNTTI8knQGGs23RxqGSO4/BvTD/HyoduNYmrdE7DYu6+Zbo3fwx08XDPemyhGtBvxSG1HzhapnT9hC0IuGA2VE1EqZM6xV+PzC0hqGw0uEQaF23RJ0VzawdeUJDoAWlJwhskPxF1a0oaS/ZFTzDUTpVNQPSOSjsSuOB+TQQaKtgUtOr0vB0KAeC1R7/qr43dBAzyznbot8CkhhCkcDK5lpTdidcnZVAPEHWfOLJUkq13+uS6bb6q+03I3hRt0ZeXJJZqv9qyexbdHdtkw8nho53sQcjJTGX7WQz2KRI=; 5:tW8/CC5WXcGw9Am6hJ814Bp+lBaI7cEKTlvhHvVdU5ELzg41lD6MvOk/sHTg2Iif6A0hVurjeoEqadjbfBFrM55KvT+l2Y+a1ERmhJT6Dru6SuP8GxsWpDvsVzgk3Esdk1LjTCsAjEi7GSEyFhAnpg==; 24:7C70twxRyi0rqk/AHBAfCRZjzPtSctlDATfNg+5P4gYznXaBSQlMlOxZ/5442OuNSjzH3vdjVlwkwpSbNAOG0VCK71rSplz0knfv7mnkAms=; 7:I8BLL3nahcUJRUITbDRGGfQAYLQai4bnhc+emr7cu8QjxUaz9+8z3AGo1bjPcGpusaQ9zgkd/AXdH4PXjiJe+EwFTyRU6ld/wipb26AyCd2yz9jR9273vFIH3/9HZwdT3AbO94ArUIrAJrFCK5T41tN8ZeWN1lGiJrXu4zkr8RzDoM+c1yxBY2zeSaxOLBLAC5EFBCdykN1Q/Vu9IZ+tqGwTgEsnz62uCKft+T/4o+WdElQYlpY4UcwH6sM3G2yE SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB834; 20:RY697SwCyOQ597adwWkstjWr+T2g397Th7234rG4wpckBBytGSIJu7rrIL2o/U93fPVCTyGkT5Zknt0I6z8eRYlz6Q1lzm9ntlnLzSb3nFp9cnfdnenG2awHo2GdkbBvFIHTFFnxetB8kquomBnJHCX3zc/GFI9xidVlkenG2Jc= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2016 19:37:26.5964 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0501MB834 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. 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 | 459 ++++++++++++++++++++++++++++++++++ 1 file changed, 459 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..0dc5bd2 --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma.h @@ -0,0 +1,459 @@ +/* + * 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 vendor id and PCI device id. + */ +#ifndef PCI_VENDOR_ID_VMWARE +#define PCI_VENDOR_ID_VMWARE 0x15AD +#endif +#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, + bool expect, union pvrdma_cmd_resp *rsp); + +#endif /* __PVRDMA_H__ */