From patchwork Mon Oct 3 02:10:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adit Ranadive X-Patchwork-Id: 9359919 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 503B3608A6 for ; Mon, 3 Oct 2016 02:11:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4310328904 for ; Mon, 3 Oct 2016 02:11:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37A9D28986; Mon, 3 Oct 2016 02:11:12 +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 92DC228904 for ; Mon, 3 Oct 2016 02:11:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751998AbcJCCLK (ORCPT ); Sun, 2 Oct 2016 22:11:10 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:24857 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752065AbcJCCLI (ORCPT ); Sun, 2 Oct 2016 22:11:08 -0400 Received: from sc9-mailhost1.vmware.com (10.113.161.71) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Sun, 2 Oct 2016 19:10:29 -0700 Received: from EX13-CAS-001.vmware.com (smtp-inbound.vmware.com [10.113.191.51]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 1259A183C1; Sun, 2 Oct 2016 19:11:06 -0700 (PDT) Received: from EX13-CAS-004.vmware.com (10.113.191.54) by EX13-MBX-018.vmware.com (10.113.191.38) with Microsoft SMTP Server (TLS) id 15.0.1156.6; Sun, 2 Oct 2016 19:11:05 -0700 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (10.113.170.11) by EX13-CAS-004.vmware.com (10.113.191.54) with Microsoft SMTP Server (TLS) id 15.0.1156.6 via Frontend Transport; Sun, 2 Oct 2016 19:11:05 -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=ft4lQHSrRUQ8J+n7eAgEITsork7JVcIvFhO9GN1MxMg=; b=lpCWofxoWH8qUP6AcsIEJ3h0g0/dyNfyj0jgfHh0AMDS6OdqvwvoR2U35rtjV5QCSb5/1v8Csh0q/Wpi41e4TjNJXEF45XyM2t7vj/Vuq1p/62IyUURP2jbc+Ws0vt/Lhdtt4f7M9Qd60AgWXngwT5Smji39sxPQ7mVrDGxnqXQ= 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:03 +0000 From: Adit Ranadive To: , , CC: Adit Ranadive , , , , Subject: [PATCH v6 08/16] IB/pvrdma: Add device command support Date: Sun, 2 Oct 2016 19:10:28 -0700 Message-ID: <7f19172610c62f2f70a1c7212ba954a9173b0c2f.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: f146f68b-9221-40d6-4f27-08d3eb328745 X-Microsoft-Exchange-Diagnostics: 1; DM2PR0501MB841; 2:kbRSErAOj/qPvFplhL1xQg0Ra70aukno+d8dFQCPCYgLtRKJzrm9IJMK6C3DMYrbMvIKc9LDwW/19GPnwJyp57/5xveYuoGn2x0ZbhjOf8DvnIXGjkvevp3zPzcxxK82FW/p9M3QW2Kif9forJUREg1BYRF+hCTyVD4jsqBVIvaMBfgGAmZD0ShjNjcyTrQKlVgRRj7zExApdgNXwLto2w==; 3:Rc2rgHNRmOMSAQOx79FwLbBsJOm9cUtR+YFgnvHNeKs/QQsOsOJQxSchakx4Zq30637accGVbjvJNLCqSloIOAB/VboOeL1FN9cHrS5PH+Wmbul3fxDvOGPd5JUDwS6WsEWUxRwGAwY97A10mrPH7A== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR0501MB841; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0501MB841; 25:cecmT58DdXKj4tbtHjdG8I06kB9gSJKqNhLlUxyJdHAQNUXqauj5Vk5q82L8+YTtZ66ghrhzkWeBGQGtAvMs+DoazlEvt7tg+zJVAb/WW0Nbh2AGGof6SrbE0yrsXe0u5nAMK0kcXDYFg28RwaZQDhC7qvoEOvrCaVgnlkdr6XAy0rQ2o9OW9RM5kenHjEXeI1eixcLGw2crhOKuqrWvafPBeAJyhEa1pOIXYil8ih+32FnddB/zXMfyEmgtzvOMftiS96EZinGrFm1SxyjuB68eSReZGyX/rAFJP+87l/8Lm/zhdyvvkPVmwGuNTZ5RyNQHxRVazpPyxqzEjTmtjmzbOdO2lEA2lpn8dDXWVlMte474Laiyx0IicRzcLZJ6C7LEzLqtIZmWaQfVS1o+Ce/C7fxl0Z306dpunUE7WnTt/nu3wMCz9u15XrB6bkDEWyrL3MrUUGNdi586imG60RWK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yQoRhGaisK9LzsY8a/7dKz7+9wFzj/ODnpcdCKqimXFAzWy9I7UcSPJGIuNhdh8p2HiSj8GMwJoilVHGeNjWEcY6QdaOykro5TZvvGqzJpA5/ih/wfwtfVlMv7XxFlha5N 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:t84ZTqSrYindwkeE5a0f3Gv8qZjuJJ/OgOJNRh77tB+AdVSdiITNVwBMqcrikFBss3aVwZ23bBDafSq/BpeBJoGO38Qd1zWHrgIhLwVicFeD5/6YwHaBxAlRQdqnr8eLhw+AK53qRnA+ZJeUfz2xiPQEeJnrVh+/i3Pjy2yk2bDkuZMGoe2eyWAeMJZR3KGnEQC3/38SiYNlgeV+C+AOSrRZdK28r4i7YWIWVu5Dsgv3XX87YdhnczuCrhSZHFfa0j41vxSsBFPxjk6K690NWqpLK2fTNNBp2gnDfbWHqtdoR62Fi4jnL7R40VNMXmqU9QbqRhzDreOwMGe1CnYvZJ9wXlUgMb0O4+I07CdkCMAdI/UKmoLTb7SgvpCALZpoyAVA2ko/yXJAf0bl7ZfixlMKw9T7mXOOPHT8t9MZMING6MhQBYfW1j/YigfGp/2ZG601FKM/G4gl0QYAEECv+RsYPg2bKOirei1jluPzkWJ3h1KMv9PRADLdjBk9S8glXdP/lRXgG5QvP8oHEty6rkzV5YpyAYyN5W38nk/wqes= 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-001.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:FTMTeuiKQBDZKNtzUXfoDL13Ki1TkfCd0X8ogWJA?= =?us-ascii?Q?a6/QJICHQN666K6qVw+cXnogjc+e7LUZzYAdxuJ4aNtju5Dmar5/u8u9iPua?= =?us-ascii?Q?NQlgfJpA7aG127HEtv4rsFUl+Sbap2/CX+kgu+rB0JBIiDP2UEDEJVZziiPq?= =?us-ascii?Q?y0dSqPXv+FkhfJlzk0pcV75NDdsfZ49ZtP4eGoaWtZ2hoa2ly3LZRgFCGY0x?= =?us-ascii?Q?OfJ1c53pc/+ICG9NpHnyBhtP5JuE6q9z/xHpGGMlRo/g8WwFvMVDUZ6c8WE/?= =?us-ascii?Q?PthjEqfQz/ZrzJ0EVDDPAW2v/1ij10tKNXOxHpp34ZfOwfKwzpFYIyJ1y0kb?= =?us-ascii?Q?cnTL+OBRFj5Z+dys69C4nq8fKLuEnf+bcaMd8rU50enepbC1lSRZLZHvUYwv?= =?us-ascii?Q?LHvBBFtbrxgIGMbfvYOPRsF2r5OpLzDEvEOsWS/IeB9xHW60s00/1l3AI8s+?= =?us-ascii?Q?AAr1JNZvxmAk6WvuRAt/ZDm5xSy1LpyPYQK5/eWJPl2DOtYRu+X8fJ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DRcNLPSblPe+ogaVBmaW9fuYwj7kx9IIT6y6epUc= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2016 02:11:03.0573 (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 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 v5->v6: - Ensure we return an error code if read from error register fails. 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 | 119 ++++++++++++++++++++++++++++++ 1 file changed, 119 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..4a78c53 --- /dev/null +++ b/drivers/infiniband/hw/pvrdma/pvrdma_cmd.c @@ -0,0 +1,119 @@ +/* + * 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 error reg: %d\n", err); + err = -EFAULT; + } + + up(&dev->cmd_sema); + + return err; +}