From patchwork Mon Sep 12 04:49:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9325671 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 9F3726089F for ; Mon, 12 Sep 2016 04:50:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 931F728ACC for ; Mon, 12 Sep 2016 04:50:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7843D28B19; Mon, 12 Sep 2016 04:50:46 +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 92FF428AD7 for ; Mon, 12 Sep 2016 04:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932422AbcILEul (ORCPT ); Mon, 12 Sep 2016 00:50:41 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:38044 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932258AbcILEug (ORCPT ); Mon, 12 Sep 2016 00:50: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; Sun, 11 Sep 2016 21:50:22 -0700 Received: from EX13-CAS-010.vmware.com (ex13-cas-010.vmware.com [10.113.191.62]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 9D4A1B04DB; Sun, 11 Sep 2016 21:50:33 -0700 (PDT) Received: from EX13-CAS-003.vmware.com (10.113.191.53) by EX13-MBX-018.vmware.com (10.113.191.38) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Sun, 11 Sep 2016 21:50:33 -0700 Received: from NAM01-SN1-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; Sun, 11 Sep 2016 21:50:32 -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=NxuUau+oLDMyLAOVIjNs27+c84hFQ/EVNwV+FaAB0lY=; b=DoiVLiYEwpkW6ja+tLsZ0QF3nkeaIViHou1I0NwI/v2n+yqUUwMTnu0UDdAGbuqeufoVjZBTdhusn6QfApYrVZMfgljqKdsGl6zMPkBx6sqUm9b/g+Vts97W65pZKbDy6CfA39K78a0pZQS4WuG7AjB1LWytKXODovsiaWoIhyU= 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:27 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , , , Subject: [PATCH v4 06/16] IB/pvrdma: Add paravirtual rdma device Date: Sun, 11 Sep 2016 21:49:16 -0700 Message-ID: <1473655766-31628-7-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: b58436f4-229d-4533-63f8-08d3dac8515c X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB836; 2:ZxdqyLeyLzX4prSjr0XxQVYV5GwRVNwzsgzXWTpFhe7J8DSKB7HzTgmnkuxrwzXuFECbzRKcG85vfxXmFis2QO8XPF7MXj7bYM5FkZ467ir9tm/R//G0U1xsy48O9C5NWJ2qE37hr9BCl5j1xrueVCZKhQ4gq7RgjHPOQrGutH4ATaCuI2j01uuR3FM8T7lk; 3:QmT6f7CoZMCchBABIRriVYDmoiu7ekFQCWqJx6Ex0CzsCLwZwRdYiXLnCPp1Cq4OBSenJp+nmgule0iroQiUebrtV5k/IGe74IFGfqbp5aq320AzJBSDeQe8/HrIqvm4; 25:DSZBTalq924skqFrBGTubOlyzzLyShesmkjO9hxn1vigeuahbFbv+v03kOSMvKls/DdpYb7s5T4FHRbluec9QKoQeWuCeAdVf6kT+LmhUMnJACSQnmxie5+W/BIkhM0LMis2eYYtVKx8F4fUEQf0mrRD9IzcVr59HWW3up5iMAfChjQ5E0f/UtqD3h+4nnXQn6alGROrwsnq1k5urmHtfm6DHUb/+9opJy370qcuCsUy69qxdP5LGzgDnZcPs4juPBiC/C2YZUrHGXlejO/TzRwFhCwiAgAkjXZPF8jQTAo3bCk9aqrie07U+G+2wJJLgOQZscNZi9VPsJCIdH5SsqU4bjwDm7jorssh/El9QEWx3Yi+cQh7RLVdZzMkd0HxwAG/kYCUHUTzQ6zRW0stQ7wIcS1b9WsyYMjqL/60RVs= 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:bubxDdt2dCq5+eE5i2d/EjeoefkBvDSikYXoueEq99wskX+4GL4rDIqD1MDtYsCqkVqYFxgpFw/L/XWa4KVxp8OtAyI/z0e7JHkBU/+DvM9ZTX2KoUeoiO6jZIJ3ib93o/u9j0R1zZTBlH71ybKZnoAhHBfV4FdAtJyBxOs2hF+ciUPiwp3cNOkZH8J5NNPWmKbUVOjlvVYRVE1jc2LWAUNTBey5I/lD7V6C7SsMJ98=; 20:Aq18BBwAzRNrMXQOEWXx+smC+1zxiY+9Xvdd4RMefwaf4Qwv8/yTWk0JwiAt48+QrOz6tzmN9nShAvmmPll6zidMYDxqhHpoUTSQnNmdXcaFtQFz3p3l2vI6okV3cAHjIBED8/Op3eKpoXxW0yxxpYBermFIGE81EjySrMQfgvG45j0whRInWyRe0+tqufVD9cj3sZ+cpSjrt0+i4H9FmMvNmkVT+UZrI9/qDuoGvpEWlm1VEX3JG60jXfLuWkBM42UeXCwuvZxKb4U7MX4DAw+tTrKVLLES+BPicjKC0STJN4ovOzP+Eq/ngpBmFwGgHuVkhUHAm2GVCbxzQPvcBdLLwIXGfpCpnc8w1/qyXRx+o8bPhrJJgx5FopKuRczrlNyu0b9OzuvdlesZxr6oTwELnA01O2UczHicI8yy9HOFw8iVYtdt2s6QehU2S3vlGMMddtF58+giR/wfvt/qF86t3uKboL5Wp2j6eL7jjZDrEH6SZ7IT0ktv3U5B6wIk X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(61668805478150)(22074186197030); 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:bJYP3ULlCnZZgS9etCt3ZbpSewrZrAbiwQoGoaKlCIrlIsRbFEXwafQZejSDmtrIE8QxKl3MRsUD2eceNQYqr1RoXHq08ginsv7BiDmATem1P9NOMLZ3+OuagqUJepCTU9q52Cm7ADyD9LLG4qat2WQRDQxLeHkXBVFrEo4g4rXkbYU9Cyxv3Ig/ffgvQxigmklZF1h/1Ixf0fmT51ixnny6jHFt6py1XxSWikRkmwOjhOss4vQAWozkQ+gu4NLqp25j7ONDjLrvhFeHR9INKzD0UuAqe7NMquzqIvE17tDyBZigwB8TBpCeVdcR6+do5rxDIaKO9EzDhBCV3YnraptEYUTeWu5130uMpC3+nkTAySLxZs2IqW9ZGmBTmqGM8PJMwJ5VTHAO5mYiW9XlrZ4D4C5G5ZJM8nCpxEhIqLl5d4LTf9X7Er62cmgalBgUfFXEhdkwULDlGnfVOyDkhqj33DA78o3orCF7BCZi5o2lreZzqvAzZR7ZIUn6GF+N 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:/XsoSMDrnp+z4r4uZXAXyEsSgWbpy070i0U9jb9J?= =?us-ascii?Q?7ZANOdVNCxrZ13zETNS8a3Bu6zbKh0G+yTKbCjKuaalJzB/h1y0e3+OrsDpf?= =?us-ascii?Q?msOPpTBoLt3Sl12h18mB/heMPUmzH7BfeEfAcANra/bIUlxrD7fw36RsoaEy?= =?us-ascii?Q?KZlZCyaptua2qDJGVi4ikugImnLdICiKhD7HDEOnk/Xpckkkfr1cDvbL4tKi?= =?us-ascii?Q?90XGxHWTl0m62qx3jH+04rJMJ1QyGh/6+LH9fExx7hmY4Z8Qi7q6WE9jADxo?= =?us-ascii?Q?OlAZCzj5gJuAyDYKIBh4hL39FWRuMIBwf9EPrhD3xb+ocqfW0/A4toeObSOi?= =?us-ascii?Q?CVn0joDB9RIlqhCp5aukiAASDCD0qumDykP8MexgT6e4UYOqg2xzvnplC9f5?= =?us-ascii?Q?G5Uaaulfcuk3BrjIO9id5trXvVz/BaK4/k+oZ052bbPBJ0eLValDpM7QBGxW?= =?us-ascii?Q?D8/Fd8slfHcpUUNRBv5vySuiIzHR+e993NI916tBmowfjTqKooZK4Pej4U1D?= =?us-ascii?Q?kNB8NVlxBJqV8T0qYaDSBJW46G18l6ktpPGoQJQ7lO0juiFGLkneNsQdR9PY?= =?us-ascii?Q?yxm4639IMIWmYeRd5jtC1KxzPp3t8sSSwg+9WKQF+nrzx7L6bO9oZB94aIGZ?= =?us-ascii?Q?fDKa/pc4PzoqdYS3pzPOtnx7adJtDtY7vYra22sg91p5grh0GNoKkaAHQ2p5?= =?us-ascii?Q?+8t/vM73+hzvYbbSkB4HAFABYO6VrLIKER5vSXFYCjKU3HMIyJ8t/VoWFBNP?= =?us-ascii?Q?9iS+mVInupIj6tUmWa2VJSRCimD1f4MWKJ705vggx9S3yFA57AiCuwnbJwDT?= =?us-ascii?Q?vxoCpteIf84BlWCdPuTSbYDERJHPdMqBZOi+kGCf4J0p7s251i58hWfWcXNS?= =?us-ascii?Q?cR9pnV3rw6hxJdoh3ZPv4ChfK+wLzskMDj97DxQUOJr7BgMWi49Kiq8PzIGa?= =?us-ascii?Q?g5G67dic+iT1CGhsiQp1Egs3NwcT6hoFYjsFKMoPGHL4qVx9Tm1my0gNQuzp?= =?us-ascii?Q?NHQlJHaJOPQdF9O6n0Sm5YFT4wvgzpJUK5YbZdklQu74NalNSb1kbHd/D+su?= =?us-ascii?Q?vNdyZxBb3WWeLzYzWOCAaaGiGtkPiSxZtnRbH7NpEBmqyhRov6znItDLC3sM?= =?us-ascii?Q?O3M4qABrmnoafMvgu1TwmCbXv0RsFUWY?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB836; 6:w5LdpkdzWQxOvKDW57Un6dr/+9VaJk7Hax5SSI+PRsNUuN1H10pw/66xBOdfnFXpHdkSc+afSSS2Gns0oFgQWtVGCOsVmOlAC5J3YzpRm3s60W9fYWhj3vHAbDMzekK0boKL8CazCpBTclkniIuUsQHYV5y6FODd+GTgxDJN77nIkQaQZ44GRHBVmkgP/fd7et0MYMCcmCXlKE1t1d6nUmIMGXIPSIBum/hNabbHw+jvtvRsq0B0co/IMGeS+eI+cWKlwwBBarWceD7XEl+TzpPT0XyT57W4XstRp/suOEg=; 5:PYDg3WYcCPl2UrCWt/3es6P3t71CqImjPAmFsOkBIUR7FG7CpZHyRKSyzLHCHdWskdJTE1zMsIKMY8nVf6ghWyOE/X7tNtQeQVjBnGJkUpoTZKMRJuvDNd6qoSYp5NqTCfTvRvRa7rY/yNalJ5Ylog==; 24:ZAJoMjrMZdaL+UTOa+bmzH3x9C963+X4jT0nXe8vMuC15rI+CIJgRm02BUGFIMOhLTZ9kL33ExkEjGcLpTg8lS6yoMBdbKBJeRXWLxWGkyQ=; 7:JFLf1Lfrwq2QI6eY2gJ61wio4pKQCHaD5rt/PwOo/zuJR27qBAM0X7NcMMoJ6Wa23TVcwy4CZ1SgFbPWtUhYYSaJHmOffP8b55kwHKAUjyukTC/uchK7N/cIaPybSm5wXzzL3DHO0nsoiqHIugEloZ3nGf0M9F1UQkKL6w8InXmIGh3PPx62bdpi0YrAF/98xFySzKdSmhrBwU5BLvsjgn4h1FyN7levvp+2RKR/TJJrN7RBPG2AoJtRPXOAppIV SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR0501MB836; 20:okrRoZSmePOW+ZNdw98tOvy3mVJJvI6IbmGd4F17RHYBNlABXJ1bBzPtgFFlR8P9Dez6kPj0Aj0TiQ8NsKg8S4YitPxqFHtmub4C4+7mst9B8exiTz6zw5Yi8dfSWUiEm4sROKJ+BEA564B2RdGqQ6rPnC8/IqFJNW6Jys9IHnA= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2016 04:50:27.0575 (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 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 Reviewed-by: Yuval Shaia --- 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 | 473 ++++++++++++++++++++++++++++++++++ 1 file changed, 473 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..fedd7cb --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma.h @@ -0,0 +1,473 @@ +/* + * 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 "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 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); + +#endif /* __PVRDMA_H__ */