From patchwork Sat Sep 24 23:21:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9349341 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 A6051601C2 for ; Sat, 24 Sep 2016 23:22:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 974A9290C6 for ; Sat, 24 Sep 2016 23:22:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BCE6290D0; Sat, 24 Sep 2016 23:22:56 +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 DEFC7290C6 for ; Sat, 24 Sep 2016 23:22:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031661AbcIXXWm (ORCPT ); Sat, 24 Sep 2016 19:22:42 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:3081 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030340AbcIXXW3 (ORCPT ); Sat, 24 Sep 2016 19:22:29 -0400 Received: from sc9-mailhost1.vmware.com (10.113.161.71) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Sat, 24 Sep 2016 16:22:04 -0700 Received: from EX13-CAS-005.vmware.com (smtp-inbound.vmware.com [10.113.191.55]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 4D6B718445; Sat, 24 Sep 2016 16:22:28 -0700 (PDT) Received: from EX13-CAS-003.vmware.com (10.113.191.53) by EX13-MBX-004.vmware.com (10.113.191.24) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Sat, 24 Sep 2016 16:22:22 -0700 Received: from NAM03-CO1-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; Sat, 24 Sep 2016 16:22:22 -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=uCQBy24EKe+uwLu8sCnERwmUe1/2+EdSM3QNMgjvimg=; b=h2duSS1Q7EbmkZnRLL3YSvmoKg4ZAX8cgRQDLwqLCqloFagF7bpiSDD5t91N6HYuFZ73M1vkwTSQbzNLSE3gKJwnK6ePNRraKptEHtxm5LNh/RTOqlZDNsHvpvPJivpsAjRnQ8UyKx+z2mlHvACTn5ygOOHS2a1Xh7klLTu3PU8= 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 CO2PR0501MB837.namprd05.prod.outlook.com (10.141.244.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.639.2; Sat, 24 Sep 2016 23:22:19 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , , , Subject: [PATCH v5 08/16] IB/pvrdma: Add device command support Date: Sat, 24 Sep 2016 16:21:32 -0700 Message-ID: <47e16986707ddbe0ffa15795ef9ae60d15bdd728.1474759181.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: CY1PR18CA0027.namprd18.prod.outlook.com (10.163.31.37) To CO2PR0501MB837.namprd05.prod.outlook.com (10.141.244.147) X-MS-Office365-Filtering-Correlation-Id: 280b233e-7e5d-41c2-d430-08d3e4d1a24d X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 2:8OfggL8ExFkVTp6JOY7HsSjzB7h8rZuzGUkemUnP33dyuwCJaP3q2EZVanSMainc2R1QKgWtafwOayUJnQdjCG5ud8Lmp9NqEAu4SK4DDKbv+A43Q6Extms3ZHOTBrZFTKudQ/rGlfv3Mz/RJ7ElzDQtbCITSodDVRS/hwycyCaojjbV/LVuo7DTkM8B7XSy; 3:SCW5e/xrpGIca48hzw5uP0WyJVib4c9ql0KSyxdXfAxTlCH060bU4tBgHl4hA8PEYIgrfoVxnOqbbLljlGIxLE3nVRbBahoIT3Yi3Qf+3JKddnCxKh7WsFcquVXij0Wm X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR0501MB837; X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 25:t9VJ7uD2NHgcEJiJregkPPSy70kAyzz6rEy2QvPuvFfrSBpfld5CBzBhKNtFDIIJoYSbVywGugolApXscZa3pmytNXejVt8QWZkCrzS5lckJG7STbbVVseUksysr67jZMDfxOW5Z1Ktv069I9VVPR6kLyP72f29QGdoJD2pGmwlw5xL2RaktD7hlsxHloiorjrs2Q84aWypse1e7vsvZmIkXiJy5GG5LilarAzJwrHKv+xc7ERJpUFi2wIr8qhsVxl5RuL8TcKNQ2eG1VofLpECRQrL7e2lQCn3j8pltQcGMH7Eyekm4+ymCJ0OEjqXXNpK15bjR3rvoDApBJsLUX7+yZeLNZoN3WfEE5HD3N16Hc+JKoOC/qYEMwJ/OpTcCX/r2nna7TXtXJNoRf3syLVwo8QwZUk6tDW5xNUytypNZuL2wioNW/iXA5iz3ncU+8hPWJl9zokHK/C4Oq/cXBqb4XxC+tuLcMM8CRtK7FniDA7HTukvOddc/NYTRrwk5gZOF60LbQWOjcWvMOT+MFwTN+pEzpzJccW9KxZ7Pb97b8mgT4JATjMkXtHxg0q0BBiS3AWYg6DvJ9raDXGX0FNvqTHr8UCOqigjF+kVJEEBTsCAqGYqqGldIsIdGKkS9bk8SP8YYng6L70qKdkmtuxg6jkgWgD1W02karyFAziDnrMwUUNBsJze4/7N2SFmVFHJwLb9RNSYaSfUMYAPdHv3v/HHCMzfvB+2oVqjd2PQ25o4BikRfRonjTIoJx75oMDh5vx2xzpnkm/ZWWZ6UG11+dUgn6m/UiAf79ZjXzVmBf6hLqLVLugYg6IejaZR7 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 31:pqVbG6gY65zKZ6i7rZbdMwEgBbZ2TWtFPqgeg9j/3+a85t4EOoODwkpaUNp62GizBU1NctriAGd/+hgjFPccKCajrFVQBRHhsbBrGnUpAA0BU4xSkLYmP9jVDAtFa4NPwGYJIFOlrh5yR5tp+gpfQRgS1ttWlWMS8ixJjrMYH5gZL5PMrVB7wqDk6ev9dj43FSJAH2n9519ohI2oUM+SWw/mM+lfESohFLwc3nL8i9c=; 20:Bwum9YJn/GarHxy45HLKO5g6D30flLZktYoG2ZyMjDmb8bxgs2bll4dDIu98QyL4aTtxcntWMMI3TgOKd2FTaDu117yafpjxrzLg81Y3sm/Zd8jLpgO74blQb0rqQqd8pCpjiQoN84UINsADGYGyDcRkxUybktVU5fnymtSzkmMZsEYoPNTHFzkBa2IQb07IEB4SgugW1TEL8Mn/DOhPgIwarx2HGgm3a1SmvYHX8Z/YJWGBrBwZ8ewmLyAqilaFaT88VCXTBJgmkoXT0eOeEAECUMQkfMnJNhfGr20/7uJ7hFAtzQelibFxhx2Wkm6BSnshd7MUPv4AgH0BFQZ3H8PJ+e2kRyUDuzcNtEEgb1Co1299pC51BkHlCsz/2DpYdjvrnto8q0dzlRK7NrX3/igJs8eKTBNpfyRdxdVfQqPeNQfk2RIMcdpUEsgsdgwy1u21DYb07RHEPnFM2kMFRcSDPeNJE6xMF5OwC+2VKzyO5gRDNhwzkXpDAXCzAklo 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)(8121501046)(5005006)(3002001)(10201501046); SRVR:CO2PR0501MB837; BCL:0; PCL:0; RULEID:; SRVR:CO2PR0501MB837; X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 4:/pKk4PEwrVgfyTn6IFyWUWKD34FcFA2Jh/FY4Au+cHE6XsYAyjLf5Yd+h4UNaxaAGNc4bYC/2NnzO6ssoRG3L32SkCYUJ/dpwCkVJ55fighGhvDyukdc+JW87EjIyWSjdrN7a1zzvpKbw03cbTtQ8XPUpLIOdrJrs2E+ziKdnLJB5F2zrANQi5wekU/88grfwV3CZoRa78J4g5AOqcbHc2aT+5qvUfxMd/YtK3MusL+7yHJRZvp8U9E6msrUOKbCIZrV5rzLaHgizZodfrD+PRnyrAEWzNXLh8gRABwOVw/YySXL+piN9N7mpJW+BLvi14Nwp6zRKDil1rTwSHvyg+x/pOk2cL+SDsjMcgCyPAIeOMUIviCzzz3nd6vGy17vYMjHPUBnQDHznzcIahgIN8Cynwb0KE8rRlukkuJAxPBcy2oHUlywe0jqnI9M8gxaAnGoaG80r51plzyDk7MIqxcN29kSmBgx4ow/0kNWSpmLSRa6/AGVAkKvwFnre4JAAgjnn2aUig2mPweyg0JFjXKEDm4dkZtkhguGu7ScWpU= X-Forefront-PRVS: 0075CB064E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(189002)(199003)(107886002)(77096005)(97736004)(4326007)(106356001)(105586002)(15975445007)(76176999)(586003)(6862003)(118296001)(50986999)(2950100002)(33646002)(6116002)(5001770100001)(19580395003)(5660300001)(19580405001)(92566002)(2906002)(3846002)(47776003)(189998001)(50466002)(86362001)(48376002)(2201001)(81156014)(81166006)(101416001)(8676002)(50226002)(5003940100001)(36756003)(7736002)(7846002)(305945005)(229853001)(42186005)(68736007)(66066001)(4001430100002)(7099028)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR0501MB837; 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; CO2PR0501MB837; 23:6W0Tl9J77lYDpuzGJXa9HjqYlwxP4S+HPrSpS3HN?= =?us-ascii?Q?rZl5CqWAILpHaBeHiPiCskuNV/1KJ186m1zFlcjT37o2d6jUaA7gkhyn8kt3?= =?us-ascii?Q?EVYYnHOlmsx1OKI+sRWKIh1c+1aQh/eH0n0nthgPwptslxg/oJXAp79Z/gAY?= =?us-ascii?Q?//J4geoAP/0X+XdglisVUHrGT/8QWGhvrgl97RSgYr3XQ3ASVzEtSyX+QGbP?= =?us-ascii?Q?1tVTZuKpzdQdKXEfDkMky9tN9qKBMRBQacQLRdJIMXO+rAtSgSaJwUsbeJd2?= =?us-ascii?Q?jPmwHTpo4cF1ds1Qm9asZRdcZhpb1lmwFMPksV72dkK7tG3C/Szu/3yzmBBd?= =?us-ascii?Q?uJCdP17ZYj0umnhKswWeNVuJj9WBtHo9JPHa8W9XNhdna4EWbJgMAxspJV3G?= =?us-ascii?Q?XlZZUuxQVvT1a0H9S7hue+4w+BnsFxIf7W7l+15Jr79aC/eMLLrzY3Iy0XAM?= =?us-ascii?Q?EqDqu8eNZvZqYDP1pR2aOqKGVVoIk03NGL49pRou+P9v2ckArmLBTnBVwhDi?= =?us-ascii?Q?pyf0xOGzIqwVbOJsGqO2y751im3k8oF4oKKn+DzEgm97imwxsyJNjmt+ilx8?= =?us-ascii?Q?QBrZDHOjjSyFjauZrbFjZL0Ljf6XkS5aCasdhpWieBDXJ54s66sd/PeC0UuC?= =?us-ascii?Q?kzFcXWBUmQPf+f5Gg5QV3lZ9WsKILim5Fe2uwcJaKigl4rRRUVccJPqH4Nvp?= =?us-ascii?Q?8foo7WSYmDG/bv7faxDUqN8q+UxBduTK+nuro4IcmKFKGL3VBHE6d73ig0k0?= =?us-ascii?Q?hHHPwK5dTY3IdYmghVGKH/WULQP9VKoNJQQPRrwQobg6vwtdVNfgsKbLbSXK?= =?us-ascii?Q?7aQpTasSQvOoKQRcT1KvqidR/nssgJfpf3tsofxz37YCt16EzYZYl8xrx1xT?= =?us-ascii?Q?KKxkzXBV8Ywq1u4GZYlKTGQnz7uja1MkgFr15ufSqVIBaAMQsmTsKiYOxgeE?= =?us-ascii?Q?4+Cd5G33BpbfOnnIO3A24jQIa1fzEFdZRwOVadUswgwBeesvlsvdvX7idFEI?= =?us-ascii?Q?eKVVKxov70gyJYLC/F62h43j+pXMaPwT9zfNEDI39v3gcXss6MPwn0XaKimg?= =?us-ascii?Q?71w5x1MBBZWTnLbJ/5suCNWwVrQR6ONM4OtlpMDSPBe6ZK6wyqbsMI/UzhV6?= =?us-ascii?Q?0cHSp/7GMpASdsx0f49UaV3plopxH4dCEhSHLs7Curtsj6dicChlpP/BXbrK?= =?us-ascii?Q?VJ4ihLSxx44rIAXv3Edf3F2W1pC6DDn7XkgGp59WSm0BuwoxUj/nL715KA?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 6:7Drh1xclugZaBZBscKXM+1a6nv5DXGfFk1ny9+NFrDoXJ9Zk+vWDLR/Sx2xxUckh1iftbkpfaLJUbjzTk0fDBTVZkWUzxGrZfGZglR5l8UqGmGdQU7mFVNqtuGg+BXSzQdt54MWWBhTOvOYyqBFQI+hdD5KYGLhFoa+gkDa6fZvxV1vABYVtimwIlMRocYXR0LgO5bahvNFGn8DRD5MKPpzvBuesMiybiT0NTu7GGuommzNUzy1fLcnrbja/3DIMELju98vFjH8vyL3vkz2lEpXrPoJHxD+IbUoaSXv6kv4=; 5:KqYvWQtPblRG8gPXABxzNNUIpTbEEQMTwJX9kF7jil02XYMo63hBpS8HT5u8m3cid/kSRhSFpFU8YfLNGcGqxZFVKEfAtyAgEqPBhhRpTWnnZFJ1OTStf4CMSLV/OiVTSp4mBGNXu582CL60cWqbxQ==; 24:H7CeVxoubK01jd4BCOKpocRu2JMl5x7fG1Mn/+QbpLbtyDZebovgqENOAezJV/dEnEjFCahVvrkHpCSzfQb9yZrCaSI6MhoHkbKy467u16s=; 7:m9F+VAUVx12cZ75lz2keHTeYvABz3gtamRl+HI1MWd27KJ/eOOLLkqsoip2bvzfPcNiglhgKKIeQEkEzHbfV2iJqTsOLExbU9ISK3b1HKuH/7UoMvrwJSAXRrzKxP1cTHlOoMThweoX4Ge7pgF5SEXCYNmZHWdwI8bFTh3b0WyIBhy6WzwjGweg70ypdqtx100HykSFesSCF+NrylFW9IXUvYwN85Ez+hLXJr+wkNNzPsj5xjr9j8rJaZjYpkBpv/Ef/+x7U+WDKWgY7MGQtl56kR4SVNEVPdVQ7juGwlNXsHL52bz2ZEAEPAscPgWES SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CO2PR0501MB837; 20:r4YIB8NbONuADCHEoMsuHg2vmecB+QYGQYyLurfJxFCMPhbATFuMnPywyJzRD82iykNtKcoTQnnQDPQn5gTZsRGns+UcpBpjNpJpaN3+EEQEUm+NVchmIQ03pdyNxXVl2jfmHOLDsj30yHtsmBHiCGw65uyr8uTk3/dv3kEXQsY= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2016 23:22:19.8708 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR0501MB837 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 enables posting Verb requests and receiving responses to/from the backend PVRDMA emulation layer. 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 v4->v5: - Moved the timeout to pvrdma_cmd_recv. - Added additional response code parameter to pvrdma_cmd_post. Changes v3->v4: - Removed the min check and added a BUILD_BUG_ON check for size. Changes v2->v3: - Converted pvrdma_cmd_recv to inline. - Added a min check in the memcpy to cmd_slot. - Removed the boolean from pvrdma_cmd_post. --- drivers/infiniband/hw/pvrdma/pvrdma_cmd.c | 117 ++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 drivers/infiniband/hw/pvrdma/pvrdma_cmd.c diff --git a/drivers/infiniband/hw/pvrdma/pvrdma_cmd.c b/drivers/infiniband/hw/pvrdma/pvrdma_cmd.c new file mode 100644 index 0000000..21f1af8 --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma_cmd.c @@ -0,0 +1,117 @@ +/* + * 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. + */ + +#include + +#include "pvrdma.h" + +#define PVRDMA_CMD_TIMEOUT 10000 /* ms */ + +static inline int pvrdma_cmd_recv(struct pvrdma_dev *dev, + union pvrdma_cmd_resp *resp, + unsigned resp_code) +{ + int err; + + dev_dbg(&dev->pdev->dev, "receive response from device\n"); + + err = wait_for_completion_interruptible_timeout(&dev->cmd_done, + msecs_to_jiffies(PVRDMA_CMD_TIMEOUT)); + if (err == 0 || err == -ERESTARTSYS) { + dev_warn(&dev->pdev->dev, + "completion timeout or interrupted\n"); + return -ETIMEDOUT; + } + + spin_lock(&dev->cmd_lock); + memcpy(resp, dev->resp_slot, sizeof(*resp)); + spin_unlock(&dev->cmd_lock); + + if (resp->hdr.ack != resp_code) { + dev_warn(&dev->pdev->dev, + "unknown response %#x expected %#x\n", + resp->hdr.ack, resp_code); + return -EFAULT; + } + + return 0; +} + +int +pvrdma_cmd_post(struct pvrdma_dev *dev, union pvrdma_cmd_req *req, + union pvrdma_cmd_resp *resp, unsigned resp_code) +{ + int err; + + dev_dbg(&dev->pdev->dev, "post request to device\n"); + + /* Serializiation */ + down(&dev->cmd_sema); + + BUILD_BUG_ON(sizeof(union pvrdma_cmd_req) != + sizeof(struct pvrdma_cmd_modify_qp)); + + spin_lock(&dev->cmd_lock); + memcpy(dev->cmd_slot, req, sizeof(*req)); + spin_unlock(&dev->cmd_lock); + + init_completion(&dev->cmd_done); + pvrdma_write_reg(dev, PVRDMA_REG_REQUEST, 0); + + /* Make sure the request is written before reading status. */ + mb(); + + err = pvrdma_read_reg(dev, PVRDMA_REG_ERR); + if (err == 0) { + if (resp != NULL) + err = pvrdma_cmd_recv(dev, resp, resp_code); + } else { + dev_warn(&dev->pdev->dev, "failed to write request %d\n", err); + } + + up(&dev->cmd_sema); + + return err; +}