From patchwork Mon Oct 3 02:10:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9359941 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 CFDB160459 for ; Mon, 3 Oct 2016 02:13:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C015228904 for ; Mon, 3 Oct 2016 02:13:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2A1628986; Mon, 3 Oct 2016 02:13:26 +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 7D3E128904 for ; Mon, 3 Oct 2016 02:13:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752156AbcJCCNY (ORCPT ); Sun, 2 Oct 2016 22:13:24 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:46370 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752139AbcJCCNX (ORCPT ); Sun, 2 Oct 2016 22:13:23 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Sun, 2 Oct 2016 19:12:50 -0700 Received: from EX13-CAS-008.vmware.com (smtp-inbound.vmware.com [10.113.191.58]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id DF931B05CC; Sun, 2 Oct 2016 19:13:22 -0700 (PDT) Received: from EX13-CAS-002.vmware.com (10.113.191.52) by EX13-MBX-012.vmware.com (10.113.191.32) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Sun, 2 Oct 2016 19:11:10 -0700 Received: from NAM01-SN1-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; Sun, 2 Oct 2016 19:11:11 -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=czJQzAsvAz4vv2IgZ3R8pu8W/PDlvFbgEzD1ZuM/aBA=; b=sLULPK360XZllrRvuR7n/92sv48BXDGbxvXyKd52WfJsmKd0yoQSA16ryTtgpVW2GDVXtKuZjDZ0r3R8eRMz/f/GI4JiNs0kUULcWvRHkVMutj08TSJQR1cXywRWTCWUg6uI4XkHX9VrufBYr9ehZvskNV5bKOKyjniyMYm2Hpo= 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 DM2PR0501MB841.namprd05.prod.outlook.com (10.242.115.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.649.6; Mon, 3 Oct 2016 02:11:00 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , Subject: [PATCH v6 06/16] IB/pvrdma: Add paravirtual rdma device Date: Sun, 2 Oct 2016 19:10:26 -0700 Message-ID: <767949584f10ff45085b08e60fc31954562eda6a.1475458407.git.aditr@vmware.com> 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: CY1PR1101CA0039.namprd11.prod.outlook.com (10.169.17.49) To DM2PR0501MB841.namprd05.prod.outlook.com (10.242.115.147) X-MS-Office365-Filtering-Correlation-Id: cb4e46ba-6a3b-4e92-5fd4-08d3eb3285be X-Microsoft-Exchange-Diagnostics: 1; DM2PR0501MB841; 2:RhNrDE9JpYz/4NbaG9yGluV9j+FJF1i4Kl07Yz75mQGTPmdB1WnVN21C1YuyJSh5LLzOXWWlxshN+2AJEPcIwQXo9ApCNbBeQchmw3h1RrJhLomDx9RSU0LWq/phdyLaeWXw7BUa2G3GsfZ7aA79Nn/CbWNEGsXOpvTCkirBmebWwM9H/luWN5BpvERI1rlfQo4PnD8t3FqxE5lUpuO9Xw==; 3:EZojgjEXp/7qNwmak736ZP5bzP4w6cmm320voSjTHE657/lyzxqanO6WsBhh7ofYDQl4ChFwztC4yHv6YXp4B/2R2V8bT3k2roLklESZ/NRQzsy3j/WLY3QE24zahqXSxCgKz7mPr7UtqNW5BC+tNA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0501MB841; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0501MB841; 25:QGreKP9K2nxL3lsjo6QSJ/VACQLPiyHRFdVsMBd2n62+FUzk9XXJODNieL3Y2DZO5Yy/89FdfsR9YimFRDJQM2QImn7WeIYawzxwED2CwLUkDu9tJOqd8P+5l9g751Qn1KI1htOhKs2ho4//77aTAEOlMCpiyTUSTPDMJ524mth1bZ9A1+YxrtMXijRqL8PauSdKT0DNNJEwj1mhZn/SPc9o+ZR8tp/7dAv9fev51rQlFfgzrA9CDzsLWqJqhEzIaSFOp8a54fGN+D4CKo7WjadfxErF1DKTTkPHhVfIILDUsbSEyk3BdP+rxQa/it1IrLYzxyNzX9+HNSF7q8mVoTZfQptITCu1JTTgdQGsaQNlvsWn+IqGsHU9i4avq8TlfuHBRWn08l/8LZnFXptp/5sIduCo4ZuZNvv4zsGunlcFJze7sV/4+WO93hJdxD1ip9l40M2KJ9tS2VW40ceGdSh7VuSyod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1oEleRExFifCcRjICnbJAI6251TUn2mDJXTLUNGQkBCbHe0i15rrcBU7uzWTlXi1Rkw2tORhzuqD8xVWsP0cQgkwOSkDM9IQHuA8qb5ARzjWezTr5Ga6FIYi9++OqR7MNnh1v3PEAra5rGvat 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)(10201501046)(3002001); SRVR:DM2PR0501MB841; BCL:0; PCL:0; RULEID:; SRVR:DM2PR0501MB841; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0501MB841; 4:ix6gKMf3A5FYA0Tk/+hsiRfXVu6nrsJWn1S39Qa1FxGk7Ym7Ysawsdgtg85oPpRo9qXLL1IxfGiRbENlk3ZhWPcYuuT4Tuyxnfk6CgfcNcPzPzbUljgBvL86yFLCJPjn2Lo7jPX79bqFm2Dz0TOJn24xM0MKsje3V+Epr9514+8oG2aG0VxipYJFaz/Uuanu34iuhxszDi189291TWuS2D9SNEJGeSPSxatWGWGZND9SA4N0hotM0wcJdqFeXy2HVrEYvW/WqGgbNz4ePF73k5MYZ4iYzY/u0qz2Agqh4UyAg1TN0LkxTYzowutjq0JX7kUaiBWcyr6SKhTGphqACoa2sXoM81z4qevXpKa7bBuQndMJxwIPB8eDjVI+m6gP2CsqDQ+nzBYDIQqWlfgxO/le6cyqAbs1/XsUwL0+ejClkyhJBabAGiK5FiqVU7DNGEaUHGMgwEHv/+ZqyT5GgwLl8eoTwOyM30SVhb3mfODvZQmnnyujTJx6eOXaIuu+v6XK6ac1zKE0BF+3B+I7jkLLX6vBpFJivqu3xv74XOE= X-Forefront-PRVS: 008421A8FF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(97736004)(189998001)(42186005)(19580405001)(47776003)(8676002)(5001770100001)(33646002)(2906002)(19580395003)(15975445007)(77096005)(6862003)(50986999)(76176999)(106356001)(2950100002)(101416001)(5003940100001)(4326007)(5660300001)(107886002)(105586002)(92566002)(7846002)(7736002)(586003)(118296001)(229853001)(68736007)(4001430100002)(305945005)(2201001)(48376002)(6636002)(50466002)(66066001)(86362001)(50226002)(6116002)(3846002)(81156014)(6666003)(36756003)(81166006)(7099028)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0501MB841; 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; DM2PR0501MB841; 23:7tOp7aAa7B17akYulCs9ufUCvlh5vWNOnJgu9iSR?= =?us-ascii?Q?xli2zaS37HBWzGnYozY23XLrn6wpjJrgEisZ0oizRZ33dN58hz708Dyvh2uI?= =?us-ascii?Q?7zWKou6/cdhv+OI/02xk2aW2Er4dGX/axgw2ArnSTQl2M5nUL0pwJ282uB4r?= =?us-ascii?Q?o18u2C+mc6CJmeiHSBU7DpPEN48sozCBhQ7meuQ0XJzEkWLkLP/sCmNhl3cJ?= =?us-ascii?Q?PTxElFDyMOdXzsWLmOL+n8qme+koepAyqLyaJoeVPx3geapQ1JtO1fSZLM7g?= =?us-ascii?Q?DFKOIJDCc8dcGSJBisUu7hHBQhqYFg8y5LYceiJ/AY1BILHh4jKo+qYVOnmm?= =?us-ascii?Q?tB+pyOd+sZJaVFu+KIWX/WV0VceogyNSopp/CgLBg97LfR5oQvHwYhfF3zOE?= =?us-ascii?Q?4huDui0X+nKj9EQAxudSixR+tj1snSpZeogb/oMUTqfDQnRX3w169yPWzGcj?= =?us-ascii?Q?cZPLg7Ll73jdYQjBDg4PB/YKC50ZIOJGMu/iG93gS9n0rMgynCxAjzbPhc4c?= =?us-ascii?Q?mOC9Tj6dKVF5gvj1EobWaXiFEqTtFnVCcLGPJgMEfXCOk9bS71I6X+6ubFq0?= =?us-ascii?Q?mexUUHLjuc/P1b4uQSHnlhglryZViDq9HQs1yX+YtgPcVGKm+iZstgLhyRaY?= =?us-ascii?Q?zT2vqYIYieTs9VCE8lrpLt7SwtPPDw+8GnPuWs7SXv11dyKqMtiBKWsgvale?= =?us-ascii?Q?XgQOteKmy0y6im8sbx3K0KhaHld6dgkvBkZJ2XqhARThpjfhDWN/97FAepsi?= =?us-ascii?Q?ZoX5uVIdRS5nXfd9cZGVNh7k1VjMhc2Cf+BQMorwbuzM4iFEUbOpfZAejhKU?= =?us-ascii?Q?vTHpJQWEqhWdmF5jiiKILu2O3tfrlPtLcjIV0zDEkUn8RGrJlTgpPZAajy0d?= =?us-ascii?Q?3BRo5WXCGs+ykm4p33VUWMXsOXX/d1i+zG7JkhpEpzPuEW+uPvMdbtJZL/r1?= =?us-ascii?Q?1mK8loilWCCgTjBLiy+CezRg1ikG58qPl9HiDgsSS3fhtn21167oZrGfymIy?= =?us-ascii?Q?gAAaz6ihmvf+M/VU7uWoHei6RthUr5y79j8gqVKVCTNKtGwk1fmBPuD1981d?= =?us-ascii?Q?sTtOULt5DUqSH0vmxwVk7Os0SXekkRBbyQGb5stgx3PzGRadh0PcPd4MdOCC?= =?us-ascii?Q?x7dcyk5nrS/rXNlpv2ZK1Hzs0WfafBp6fFPVocrTr532Xrej70g3hMxjI+PO?= =?us-ascii?Q?fQY0+WAC1ApR9duUKumnsUNC98PnHg3mK+gpu+oU3RMt803HOuGGGl+NwyCR?= =?us-ascii?Q?Zuf/1VG5BPgVl9NEZveKDdNvj112yZ1BnX/Hz33c?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0501MB841; 6:pyq6cUkAIrm6yUCGWri+fryHXPQncksJNa+JBnKV/R0t1aQvOzxKVCtDQOp2eTdaTc8SEcGifwneCd4BQ5OKy0wOTCGkeat+L8oJZg1WcbQKZaHmJzy4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1JGQrefAjMafsCSlEAsweD6Gg= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2016 02:11:00.4892 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0501MB841 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: Yuval Shaia Reviewed-by: Jorgen Hansen Reviewed-by: George Zhang Reviewed-by: Aditya Sarwade Reviewed-by: Bryan Tan Signed-off-by: Adit Ranadive --- Changes v5->v6: - Update the header includes for abi and ring headers. Changes v4->v5: - pvrdma_cmd_post takes the response code. Changes v3->v4: - Renamed pvrdma_flush_cqe to _pvrdma_flush_cqe since we hold a lock to call it. - Added wrapper functions for writing to UARs for CQ/QP. - The conversion functions are updated as func_name(dst, src) format. - Renamed max_gs to max_sg. - Added work struct for net device events. - priviledged -> privileged. Changes v2->v3: - Removed VMware vendor id redefinition. - Removed the boolean in pvrdma_cmd_post. --- drivers/infiniband/hw/pvrdma/pvrdma.h | 474 ++++++++++++++++++++++++++++++++++ 1 file changed, 474 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..deb6792 --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma.h @@ -0,0 +1,474 @@ +/* + * 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 +#include + +#include "pvrdma_ring.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 privileged; +}; + +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_sg; + 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; +}; + +struct pvrdma_netdevice_work { + struct work_struct work; + struct net_device *event_netdev; + unsigned long event; +}; + +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_write_uar_cq(struct pvrdma_dev *dev, u32 val) +{ + writel(cpu_to_le32(val), dev->driver_uar.map + PVRDMA_UAR_CQ_OFFSET); +} + +static inline void pvrdma_write_uar_qp(struct pvrdma_dev *dev, u32 val) +{ + writel(cpu_to_le32(val), dev->driver_uar.map + PVRDMA_UAR_QP_OFFSET); +} + +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(struct ib_qp_cap *dst, + const struct pvrdma_qp_cap *src); +void ib_qp_cap_to_pvrdma(struct pvrdma_qp_cap *dst, + const struct ib_qp_cap *src); +void pvrdma_gid_to_ib(union ib_gid *dst, const union pvrdma_gid *src); +void ib_gid_to_pvrdma(union pvrdma_gid *dst, const union ib_gid *src); +void pvrdma_global_route_to_ib(struct ib_global_route *dst, + const struct pvrdma_global_route *src); +void ib_global_route_to_pvrdma(struct pvrdma_global_route *dst, + const struct ib_global_route *src); +void pvrdma_ah_attr_to_ib(struct ib_ah_attr *dst, + const struct pvrdma_ah_attr *src); +void ib_ah_attr_to_pvrdma(struct pvrdma_ah_attr *dst, + const struct ib_ah_attr *src); + +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, unsigned resp_code); + +#endif /* __PVRDMA_H__ */