From patchwork Wed Jul 6 06:14:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9215487 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 9646E608A6 for ; Wed, 6 Jul 2016 06:23:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 856D1286E0 for ; Wed, 6 Jul 2016 06:23:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A0B1286EE; Wed, 6 Jul 2016 06:23:37 +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 86A5B286F0 for ; Wed, 6 Jul 2016 06:23:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751149AbcGFGXe (ORCPT ); Wed, 6 Jul 2016 02:23:34 -0400 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]:37458 "EHLO smtp-outbound-1.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750974AbcGFGXb (ORCPT ); Wed, 6 Jul 2016 02:23:31 -0400 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 57DAB984F6; Tue, 5 Jul 2016 23:15:27 -0700 (PDT) Received: from EX13-CAS-005.vmware.com (ex13-cas-005.vmware.com [10.113.191.55]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 87D2B180F4; Tue, 5 Jul 2016 23:15:27 -0700 (PDT) Received: from EX13-CAS-003.vmware.com (10.113.191.53) by EX13-MBX-027.vmware.com (10.113.191.47) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Tue, 5 Jul 2016 23:15:27 -0700 Received: from NAM03-DM3-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, 5 Jul 2016 23:15:27 -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=OgK65DDeoUOnKJWHkGE1QXB7Ci3mk761OUNgHosW2W8=; b=RBJ5i7tsQ2jZCvWOAY22ypsLDncvp7SJqVM1jSPXcI83FYGQa8KE6SQu11LM0zGOk612STMg+G1N+TvVDw2QWRlnIO3yETwik84eX5S/gIYNYg2LpMuH7K7avnkX3a+z4Smb1rl+VagN2JYa77Q+1ny+JEo1LqEwKCpOnnod/t0= 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 SN2PR0501MB848.namprd05.prod.outlook.com (10.160.14.146) with Microsoft SMTP Server (TLS) id 15.1.528.16; Wed, 6 Jul 2016 06:15:24 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , Subject: [PATCH v1 11/15] IB/pvrdma: Add user-level shared functions Date: Tue, 5 Jul 2016 23:14:44 -0700 Message-ID: <1467785688-23229-12-git-send-email-aditr@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467785688-23229-1-git-send-email-aditr@vmware.com> References: <1467785688-23229-1-git-send-email-aditr@vmware.com> MIME-Version: 1.0 X-Originating-IP: [208.91.1.34] X-ClientProxiedBy: CO2PR11CA0028.namprd11.prod.outlook.com (10.141.242.166) To SN2PR0501MB848.namprd05.prod.outlook.com (10.160.14.146) X-MS-Office365-Filtering-Correlation-Id: ee3a5a4b-dd00-475b-6502-08d3a564eb14 X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB848; 2:1Hok/Am/YRIndosunHLwjRY2PF3sUpFmyzKFUaKnqZbysdkIk6LuCofENBcdhChKv4ZZGbeD7wAg51CoGXfSn5/LDqotG+oqueKNlfpLAEEKjgyunQQ1JXaGPAzOFpzrTn0eKrfviKOaNl5xDVWka5Wukc76ZYN6ZEugISgCJnLnk3ILoQZ2c/KlkNpCh+yx; 3:ypv61QzVBAo8S92tzJS7RD9CVkzu/ACHi4NCsGBVsf4SUcZeANL40lS6AS+pH60cDynIBwkEOsj/K+fE+v3Vp5Jelmbbr5YyOrimu0VdHKrVoJEMe3x8lEO0GqQCwnyz; 25:fOiWJRBzWlQpy4tjeCRE++zGk7iCOAKyM24p2zswj75OxyEFb48FpEZwTWXJyMDAA8TZxBwge5TPD0h6iY/uJJ0hRmJEaalm1jHPSaZTDRkQHs88nFZkzqslWyhSp0Y3RvcppoUICSqJAc5fL/VVyP8lkxlVoL/KODDqK0AbLaxegotAV1tCx0wt1lI7j/cPuvujE0zERUoDg4yyBB+whMb2/SkBI62QPw4Q+4/oZYtqHYsrGyB8FqDlXl2vfTcDJoXrdTNvOhZEHzFXb917l1nsYQA9vufK4Lb4VOCjphPhPLfXcUWmy+zyzMK9QqUfYNYILq+wXE/pRjr5fufpcFDy6/IF0y6n/Inbuvs+kPUDHMqDQPDEEra1g0n8Bnjv7JZvfKzXUm6GYWPY95vVgmyloSomaRsrp02ckwFLxhc= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR0501MB848; X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB848; 31:nDq7/bZ9mmvGMfIr7A/+TEx/9+yN7gLRqiGzh8UmX+gtpKAd5dmuE7Qje4fL2clnVPnKp1CPr9D1GF9FxtDgOtu9FgozYEpOcr9l+LOJa2l9y2K0m3B9ZQPlEYvilOuuEKaQJ8ldd1yi45kvY2wqofrzOZvR0KM9FmRISWSI/0AkbESVs7zzrJLF06oP/sZvOJLNoUmS7PFMh70ah1blSg==; 20:oSO3TUrgWd+aSC33ZRxzA64M2eye55Jq3Zmgsrj0K5NoUwIFMmXKNb8wNHcZ3neb/2jlXpQOGVTXGd2p1aCiHNxlGXIPLwAGCy4urUvA763By5hrEZ1wcJf2Ki3HCruFs2cDQbolXKU3qVTqBe++E1Xef8Ao8RMsPQVMoLWWrvDOBzExOhkV5i+Nt6GCptGSt4/9cIPPJCsZ4/o4RnS+FB6w2iGBMv1+YHRicRPiJDt2LNHXRhzianGGxpXKhRhq; 4:b8XnjDiHj1PSC3P/kA909Qxbex1hwmCIk2J5Hwg5IEuSS7DHztm02pOJR26do9kuUeBYvPU3s0lBPfgK9GnM11+JPDIVtWxk4Qqf7vODgaUbTzZpUe9Q6zU9PRAloC4mjL+Hy5jJgAZjn2knN5ouBuNcFvzxfOTed7aYmqKPhX6gyLO4D1qkj9uOcDGXQeT/1ul46mNZMJps/az/gcZpVyLmAuoJ9nafsduW2cSQyNrIIf1kMxxVzSDWcZ0QrjhdrMnZVJ9QRY39X542G98S59O+hKq1l4DBFWNyVef032UWcgCadQ0EwStqOCt1cjrXeCCpbM0/09QuuvtMX9jWS7LOt0tGh86igkrvtm9tvkR56hB3qINf8rNz33ulk6jAgPGtrl+Wqnpx4O/etxVq3o044PndnrP2yxAkMr0NQnkDJV2kXpjqUx1tZyIGyfWo7km63zEV0 E+oe+p7zO03Nvxs9y2q9XYMflBHunas+h w= 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:SN2PR0501MB848; BCL:0; PCL:0; RULEID:; SRVR:SN2PR0501MB848; X-Forefront-PRVS: 0995196AA2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(81166006)(81156014)(4001450100002)(92566002)(86362001)(19580395003)(4001430100002)(19580405001)(7846002)(7736002)(305945005)(8676002)(105586002)(2201001)(586003)(42186005)(33646002)(106356001)(3846002)(5003940100001)(6116002)(48376002)(36756003)(50466002)(5001770100001)(97736004)(189998001)(229853001)(47776003)(66066001)(76176999)(107886002)(50986999)(68736007)(101416001)(50226002)(4326007)(2950100001)(15975445007)(77096005)(2906002)(7099028)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR0501MB848; H:promb-2s-dhcp95-136.eng.vmware.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN2PR0501MB848; 23:DSB+SghLfnqaDR0zvV3rmYLb6s/k0Mu8HuVrL29m?= =?us-ascii?Q?h2f/VJp63s1Bn26kN76iaHKupFMlzs1TJ2v1RL5Z6ivkmLFQVKMDKfLF7YON?= =?us-ascii?Q?s/vRimTDuNCVxXc+HReBKlIT800ouF7wT442QPAWtP9X/rYZsTmivr2CFP6g?= =?us-ascii?Q?unJB2pgl5JjldX0JsW5C0Ey+S9byneTsXe5kh7emygmuZM2yYhl/GtwZFTt3?= =?us-ascii?Q?GOOErmkTmY5/4ADNOZbY9uT0QUqMrvL5i2ZJsuwJ5NXmHAMKtnVRkhHMuuTy?= =?us-ascii?Q?mlCtRG02hPt5Wk8Kk3PPKSw4v2WY3YSeFJkEyvXqXWeuQt8pQZlhKk2EJyF7?= =?us-ascii?Q?XfLpJt8qWFncROfkC3C6AiCiTf6fvdKcYgeGIijbox94m/TudR2S39RxcQk4?= =?us-ascii?Q?cnP2hW/L9qi4DmPlIpZ6b8ark41qvwgvEUaabNNm7CTulBl2ivXyUoyuu5xa?= =?us-ascii?Q?Rodt9Pb2C0h91kDDwr0gWjl7MasvGoGfmL2DTZXEVz0cAKTm7yxq+/e5XIEx?= =?us-ascii?Q?eMXRumf72KKOg0CguJGqYt1tyPa0Vj2aiufSmfoedwXvgcUwOfEAHncJgNJr?= =?us-ascii?Q?FEjMu/LfsDPNEPDQU+PBJznHJgNCChvF0IsNJp7twgcsQMz5hYllfyKgr4y1?= =?us-ascii?Q?y5+Oa4/Kn/2vlAbuPkU6+tq4Ja7t8hsYlNYabQpNmd9EuAODdY5YipioYzPW?= =?us-ascii?Q?yP9OmGvrC2DQA6sjSr2tG36FobKYDcMPGhWg0Yh4I7wX2snl263DnMiDkpOx?= =?us-ascii?Q?F2j4jq8cvipvP9oIrYHfx3S/2dduZkGi7JQw7D/LMKXefDFJPDLnUXHKVnY+?= =?us-ascii?Q?oTB5LHl6RCJ8JomQ+MjFiCyD5iR7/LfGi83dMmkZTJAGtc76uMv1gmrHRxcf?= =?us-ascii?Q?yKDWZToA9FZaq2dWfm0GL43Qd5bW+Lig1ydp7OQJcQ1yDztP3vRGBGyIb3+r?= =?us-ascii?Q?OzCO2xuHKVe0rRitqHIobN7X7RLAR1md91inomGWX4BRtnpfdlNDhs+eGl2K?= =?us-ascii?Q?VUULf7ee+jKx7dKdX3NYwV6K7XS0WstDbK8VpY/XhaoRRuyPgbnnucCpSQO0?= =?us-ascii?Q?PWkvhPBFwWzUxOjPGVVr/7AaSKUh3pg/55j+ct8gnMET8szoHvEE4r6aww07?= =?us-ascii?Q?fz5jaCmC1TnBZiuM9lgfP7YnsNknYOt74bg4IvXG72m6l2FQ8wUni73/zyO7?= =?us-ascii?Q?Hckce5IR7ZN6xlN72dujhr6co2VeUh0/kqYe5zyBr4pRAvfdqx4LOw3Dzw?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB848; 6:tiLxkHy5z7JrekXx35oYdrM3Fjgl9EUkJ2USghqFl4sO4mklTe1EbWzGV3Z01lld+QIEfQqGqYPlgZ9TspmOi/kRDdUqv7g21ydmvKRXfMIwZDBRgLr4vSiY94f5SRZ5DfcRyLiBRj//EjKBnmA82i5Ss0rW/oErns1+vQ/QBPcTW2RoKhGY0RwvCi8kWKFZxlx8o9SfQ4TCXK8B1EUdOEOZU5KTjlu3uBcCy3tZpIde5OyVpf3s/8VPiySCM+zAIV1L+cVfADbxIjA33lKORw8U25nejdjUDPmxstFZkcI=; 5:Q1Ohj7yrO29nf2oGz20kguCgteGf19wuVmxyUo0DxDv1Z0l566UMzAzQWLqfFhM0PiPv2ErsdcBlSxdaFXoSPGs1Acu8uPu8DdnPnb1F/Ov+SsJel9F1a8eXQ2sU7GnWC8MELFRXpsc6/bwVyN5LXw==; 24:75emFCmFu7EMILjJ/hSPFXhWEVHpUUMa9Z8CDWP/Exo1FBwuWMgpeQqK99QDvHcZfeQhl1wzYIznj3Slr4JXR/WyaLQ6nxugb+7R/nd47uY=; 7:NgbY/d7A2Uv3PEx58B/sWmKNlni95QEGUxzFAZVkBOiBFQ02S5dnaRnKwUk+H2S4LRT1jil27wPB2oJjLK2nVCxsInGppfCoVvOOXP7neu8GMdn60ZZa8U++/zxXYZwjY2tb32/LqDi+WrjxXsckb0C0x51zAZCXtQXibKb7PCtXgVhPD0vDSINXSbiI2EzVSeoOTVSQoXbvbYAfe8NihUZdwugzuMTAUBqDtbbbD3a3Zxzo+Gv4++dlG3d01nPf SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN2PR0501MB848; 20:nwe/9NEZ8lmNPhYk7PdJLdCIUCFRfo2uWZeFqqrkNd8T6ZLbezdkx3ioyf+0OiSbwUYIq7KCBXlp61/Hm2T+x6VhEMKtCDUAwMcp1BLP9R5AewwmJhItHJfpdaDnlnnKrOQCizpi1kdzoOCrvw7JRYI/eDmNnScABTde24cCSq8= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2016 06:15:24.0610 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR0501MB848 X-OriginatorOrg: vmware.com 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 We share some common structures with the user-level driver. This patch adds those structures and shared functions to traverse the QP/CQ rings. 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_uapi.h | 247 +++++++++++++++++++++++++++++ drivers/infiniband/hw/pvrdma/pvrdma_user.h | 99 ++++++++++++ 2 files changed, 346 insertions(+) create mode 100644 drivers/infiniband/hw/pvrdma/pvrdma_uapi.h create mode 100644 drivers/infiniband/hw/pvrdma/pvrdma_user.h diff --git a/drivers/infiniband/hw/pvrdma/pvrdma_uapi.h b/drivers/infiniband/hw/pvrdma/pvrdma_uapi.h new file mode 100644 index 0000000..274328c --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma_uapi.h @@ -0,0 +1,247 @@ +/* + * 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_UAPI_H__ +#define __PVRDMA_UAPI_H__ + +#include + +#define PVRDMA_VERSION 17 + +#define PVRDMA_UAR_HANDLE_MASK 0x00FFFFFF /* Bottom 24 bits. */ +#define PVRDMA_UAR_QP_OFFSET 0 /* Offset of QP doorbell. */ +#define PVRDMA_UAR_QP_SEND BIT(30) /* Send bit. */ +#define PVRDMA_UAR_QP_RECV BIT(31) /* Recv bit. */ +#define PVRDMA_UAR_CQ_OFFSET 4 /* Offset of CQ doorbell. */ +#define PVRDMA_UAR_CQ_ARM_SOL BIT(29) /* Arm solicited bit. */ +#define PVRDMA_UAR_CQ_ARM BIT(30) /* Arm bit. */ +#define PVRDMA_UAR_CQ_POLL BIT(31) /* Poll bit. */ + +/* PVRDMA atomic compare and swap */ +struct pvrdma_exp_cmp_swap { + __u64 swap_val; + __u64 compare_val; + __u64 swap_mask; + __u64 compare_mask; +}; + +/* PVRDMA atomic fetch and add */ +struct pvrdma_exp_fetch_add { + __u64 add_val; + __u64 field_boundary; +}; + +/* PVRDMA address vector. */ +struct pvrdma_av { + __u32 port_pd; + __u32 sl_tclass_flowlabel; + __u8 dgid[16]; + __u8 src_path_bits; + __u8 gid_index; + __u8 stat_rate; + __u8 hop_limit; + __u8 dmac[6]; + __u8 reserved[6]; +}; + +/* PVRDMA receive queue work request */ +struct pvrdma_rq_wqe_hdr { + __u64 wr_id; /* wr id */ + __u32 num_sge; /* size of s/g array */ + __u32 total_len; /* reserved */ +}; +/* Use pvrdma_sge (ib_sge) for receieve queue s/g array elements. */ + +/* PVRDMA send queue work request */ +struct pvrdma_sq_wqe_hdr { + __u64 wr_id; /* wr id */ + __u32 num_sge; /* size of s/g array */ + __u32 total_len; /* reserved */ + __u32 opcode; /* operation type */ + __u32 send_flags; /* wr flags */ + union { + __u32 imm_data; + __u32 invalidate_rkey; + } ex; + __u32 reserved; + union { + struct { + __u64 remote_addr; + __u32 rkey; + __u8 reserved[4]; + } rdma; + struct { + __u64 remote_addr; + __u64 compare_add; + __u64 swap; + __u32 rkey; + __u32 reserved; + } atomic; + struct { + __u64 remote_addr; + __u32 log_arg_sz; + __u32 rkey; + union { + struct pvrdma_exp_cmp_swap cmp_swap; + struct pvrdma_exp_fetch_add fetch_add; + } wr_data; + } masked_atomics; + struct { + __u64 iova_start; + __u64 pl_pdir_dma; + __u32 page_shift; + __u32 page_list_len; + __u32 length; + __u32 access_flags; + __u32 rkey; + } fast_reg; + struct { + __u32 remote_qpn; + __u32 remote_qkey; + struct pvrdma_av av; + } ud; + } wr; +}; +/* Use pvrdma_sge (ib_sge) for send queue s/g array elements. */ + +/* Completion queue element. */ +struct pvrdma_cqe { + __u64 wr_id; + __u64 qp; + __u32 opcode; + __u32 status; + __u32 byte_len; + __u32 imm_data; + __u32 src_qp; + __u32 wc_flags; + __u32 vendor_err; + __u16 pkey_index; + __u16 slid; + __u8 sl; + __u8 dlid_path_bits; + __u8 port_num; + __u8 smac[6]; + __u8 reserved2[7]; /* Pad to next power of 2 (64). */ +}; + +struct pvrdma_ring { + atomic_t prod_tail; /* Producer tail. */ + atomic_t cons_head; /* Consumer head. */ +}; + +struct pvrdma_ring_state { + struct pvrdma_ring tx; /* Tx ring. */ + struct pvrdma_ring rx; /* Rx ring. */ +}; + +static inline int pvrdma_idx_valid(__u32 idx, __u32 max_elems) +{ + /* Generates fewer instructions than a less-than. */ + return (idx & ~((max_elems << 1) - 1)) == 0; +} + +static inline __s32 pvrdma_idx(atomic_t *var, __u32 max_elems) +{ + const unsigned int idx = atomic_read(var); + + if (pvrdma_idx_valid(idx, max_elems)) + return idx & (max_elems - 1); + return -1; +} + +static inline void pvrdma_idx_ring_inc(atomic_t *var, __u32 max_elems) +{ + __u32 idx = atomic_read(var) + 1; /* Increment. */ + + idx &= (max_elems << 1) - 1; /* Modulo size, flip gen. */ + atomic_set(var, idx); +} + +static inline __s32 pvrdma_idx_ring_has_space(const struct pvrdma_ring *r, + __u32 max_elems, __u32 *out_tail) +{ + const __u32 tail = atomic_read(&r->prod_tail); + const __u32 head = atomic_read(&r->cons_head); + + if (pvrdma_idx_valid(tail, max_elems) && + pvrdma_idx_valid(head, max_elems)) { + *out_tail = tail & (max_elems - 1); + return tail != (head ^ max_elems); + } + return -1; +} + +static inline __s32 pvrdma_idx_ring_has_data(const struct pvrdma_ring *r, + __u32 max_elems, __u32 *out_head) +{ + const __u32 tail = atomic_read(&r->prod_tail); + const __u32 head = atomic_read(&r->cons_head); + + if (pvrdma_idx_valid(tail, max_elems) && + pvrdma_idx_valid(head, max_elems)) { + *out_head = head & (max_elems - 1); + return tail != head; + } + return -1; +} + +static inline __s32 pvrdma_idx_ring_is_valid_idx(const struct pvrdma_ring *r, + __u32 max_elems, __u32 *idx) +{ + const __u32 tail = atomic_read(&r->prod_tail); + const __u32 head = atomic_read(&r->cons_head); + + if (pvrdma_idx_valid(tail, max_elems) && + pvrdma_idx_valid(head, max_elems) && + pvrdma_idx_valid(*idx, max_elems)) { + if (tail > head && (*idx < tail && *idx >= head)) + return 1; + else if (head > tail && (*idx >= head || *idx < tail)) + return 1; + } + return 0; +} + +#endif /* __PVRDMA_UAPI_H__ */ diff --git a/drivers/infiniband/hw/pvrdma/pvrdma_user.h b/drivers/infiniband/hw/pvrdma/pvrdma_user.h new file mode 100644 index 0000000..35f8c1e --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma_user.h @@ -0,0 +1,99 @@ +/* + * 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_USER_H__ +#define __PVRDMA_USER_H__ + +#include + +#define PVRDMA_UVERBS_ABI_VERSION 3 +#define PVRDMA_BOARD_ID 1 +#define PVRDMA_REV_ID 1 + +struct pvrdma_alloc_ucontext_resp { + u32 qp_tab_size; + u32 reserved; +}; + +struct pvrdma_alloc_pd_resp { + u32 pdn; + u32 reserved; +}; + +struct pvrdma_create_cq { + u64 buf_addr; + u32 buf_size; + u32 reserved; +}; + +struct pvrdma_create_cq_resp { + u32 cqn; + u32 reserved; +}; + +struct pvrdma_resize_cq { + u64 buf_addr; + u32 buf_size; + u32 reserved; +}; + +struct pvrdma_create_srq { + u64 buf_addr; +}; + +struct pvrdma_create_srq_resp { + u32 srqn; + u32 reserved; +}; + +struct pvrdma_create_qp { + u64 rbuf_addr; + u64 sbuf_addr; + u32 rbuf_size; + u32 sbuf_size; + u64 qp_addr; +}; + +#endif /* __PVRDMA_USER_H__ */