From patchwork Thu Nov 22 23:24:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06E7013B5 for ; Thu, 22 Nov 2018 23:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAA232C2F0 for ; Thu, 22 Nov 2018 23:24:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF66C2C3A1; Thu, 22 Nov 2018 23:24:24 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 5B8212BF0F for ; Thu, 22 Nov 2018 23:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407883AbeKWKGF (ORCPT ); Fri, 23 Nov 2018 05:06:05 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34136 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389637AbeKWKGF (ORCPT ); Fri, 23 Nov 2018 05:06:05 -0500 Received: by mail-pl1-f193.google.com with SMTP id f12-v6so9804385plo.1 for ; Thu, 22 Nov 2018 15:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zSJGlxOrn/Ub24PCVPiLHtSCkQlPAmuTG/OHc9Yo/t8=; b=h3uOexgmCwbv+oto8ae7pEbXU4H6eDOBL2WxtfN+qzBiWhAhxOkxfmUA0i/auLP/zu Uyy4elufxZswr2f45rnbBcJfH4MJYGWt4w/MSCei2yaBTc+7qrJCAByhS3TFdoQxy5RX nTUcRsZiz+pVtcZX/KVAW6REYSQSVW5EwTaZfVdNDhKUnQjkKkysjypEOsG9NxOqdffO r4BagcWu9BqPzqFv3oxK5bwyiinjhno6uSq9Y+fz12g5FKCtlUaE8M77TzHN+aUiFeiq NoYQAUnOkt0pBZXpCtLsIFj0fuBaTr1D2XdTAcap+S40H6/LhZbsuDRozQ37wHJQ92PH FE2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zSJGlxOrn/Ub24PCVPiLHtSCkQlPAmuTG/OHc9Yo/t8=; b=cEd6OqzxBqfOuK8Gr1PhALYBDRFu/G/kqa1Yp2ZNK51ebAeX0iyNK8FX/edXWV8v/P EVvylRcxZnuWAt3tJtMakv1SxzQpL3qk9cqmg+r88MVHr2dNMnT+0UASZ3mDVY6pGFxY yrYAYAmRoRSA4pZNHCb5CWrPASM3hkHO8oPPOZHGr4xqSzpeRuCR5tH6OwxB7p602nwk tHCTvk41CeaAvlNd93n2yR4J+6g6Fp7i6ryw7LbK+eS9qSaHWsmT4jC7IwWPa7+DDFnw CHzFHeYFjOai9rUug663AVGXrG8b+MmRb1EN/m953dB5pOtyahuWeyXSFzH+jQfAnety AUxg== X-Gm-Message-State: AA+aEWbqSXT4ja9XMfLK42CuZRs6z9hGeN+hQvYrH2pAwTEeMUNwbI06 /OtkeA8O23Rc1cIBgpjCfYm4imIWn3Q= X-Google-Smtp-Source: AFSGD/V5DRgjJbFmR2LIRAWVRNzEWu0vXgk2KT4kFcRrKyA1BX9LdBExLj12Pm00PFMq2Tx85/zURQ== X-Received: by 2002:a17:902:34a:: with SMTP id 68mr4521646pld.268.1542929061799; Thu, 22 Nov 2018 15:24:21 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id u69sm49256208pfj.116.2018.11.22.15.24.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Nov 2018 15:24:19 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1gPyKY-0007st-G6; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 06/10] verbs: Replace IBV_INIT_CMD() with execute_cmd_write_resp Date: Thu, 22 Nov 2018 16:24:12 -0700 Message-Id: <20181122232416.30132-7-jgg@ziepe.ca> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122232416.30132-1-jgg@ziepe.ca> References: <20181122232416.30132-1-jgg@ziepe.ca> MIME-Version: 1.0 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 From: Jason Gunthorpe Replace the entire IBV_INIT_CMD_RESP(); write(); return errno; Sequence with a single function call. This signature has enough information for the execute call to compute the location of all 5 components of a write command. This requires adding a the _v3 version of modify_srq to the command macros. This can be done without a lot of complexity by using core_payload instead of the struct member aliases. Signed-off-by: Jason Gunthorpe --- libibverbs/cmd.c | 36 ++++++++++++------------------------ libibverbs/cmd_write.h | 11 +++++++++++ libibverbs/ibverbs.h | 7 ------- libibverbs/kern-abi.h | 6 ++++-- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index 8123aae1ad89b8..d759ec89c843cc 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -719,19 +719,15 @@ static int ibv_cmd_modify_srq_v3(struct ibv_srq *srq, cmd = alloca(cmd_size); memcpy(cmd + 1, new_cmd + 1, new_cmd_size - sizeof *new_cmd); - IBV_INIT_CMD(cmd, cmd_size, MODIFY_SRQ); - - cmd->srq_handle = srq->handle; - cmd->attr_mask = srq_attr_mask; - cmd->max_wr = srq_attr->max_wr; - cmd->srq_limit = srq_attr->srq_limit; - cmd->max_sge = 0; - cmd->reserved = 0; - - if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; + cmd->core_payload = (struct ib_uverbs_modify_srq_v3){ + .srq_handle = srq->handle, + .attr_mask = srq_attr_mask, + .max_wr = srq_attr->max_wr, + .srq_limit = srq_attr->srq_limit, + }; - return 0; + return execute_cmd_write_req( + srq->context, IB_USER_VERBS_CMD_MODIFY_SRQ_V3, cmd, cmd_size); } int ibv_cmd_modify_srq(struct ibv_srq *srq, @@ -743,17 +739,13 @@ int ibv_cmd_modify_srq(struct ibv_srq *srq, return ibv_cmd_modify_srq_v3(srq, srq_attr, srq_attr_mask, cmd, cmd_size); - IBV_INIT_CMD(cmd, cmd_size, MODIFY_SRQ); - cmd->srq_handle = srq->handle; cmd->attr_mask = srq_attr_mask; cmd->max_wr = srq_attr->max_wr; cmd->srq_limit = srq_attr->srq_limit; - if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - return 0; + return execute_cmd_write_req(srq->context, IB_USER_VERBS_CMD_MODIFY_SRQ, + cmd, cmd_size); } int ibv_cmd_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, @@ -1288,14 +1280,10 @@ int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, if (attr_mask & ~(IBV_QP_RATE_LIMIT - 1)) return EOPNOTSUPP; - IBV_INIT_CMD(cmd, cmd_size, MODIFY_QP); - copy_modify_qp_fields(qp, attr, attr_mask, &cmd->core_payload); - if (write(qp->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - return 0; + return execute_cmd_write_req(qp->context, IB_USER_VERBS_CMD_MODIFY_QP, + cmd, cmd_size); } int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr, diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index c7a7ef0b50a22b..7ae26359b25f29 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -228,6 +228,17 @@ int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, sizeof(*(resp)), resp_size); \ }) +/* For write() commands that have no respone */ +#define execute_cmd_write_req(ctx, enum, cmd, cmd_size) \ + ({ \ + static_assert(sizeof(IBV_KABI_RESP(enum)) == 0, \ + "Method has a response!"); \ + _execute_cmd_write( \ + ctx, enum, \ + &(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *), \ + sizeof(*(cmd)), cmd_size, NULL, 0, 0); \ + }) + /* * Execute a write command that does not have a uhw component. THe cmd_size * and resp_size are the lengths of the core structure. This version is only diff --git a/libibverbs/ibverbs.h b/libibverbs/ibverbs.h index c99d617eace611..c70114f11e9bad 100644 --- a/libibverbs/ibverbs.h +++ b/libibverbs/ibverbs.h @@ -86,13 +86,6 @@ static inline const struct verbs_context_ops *get_ops(struct ibv_context *ctx) return &get_priv(ctx)->ops; } -#define IBV_INIT_CMD(cmd, size, opcode) \ - do { \ - (cmd)->hdr.command = IB_USER_VERBS_CMD_##opcode; \ - (cmd)->hdr.in_words = (size) / 4; \ - (cmd)->hdr.out_words = 0; \ - } while (0) - static inline uint32_t _cmd_ex(uint32_t cmd) { return IB_USER_VERBS_CMD_FLAG_EXTENDED | cmd; diff --git a/libibverbs/kern-abi.h b/libibverbs/kern-abi.h index 8c07b8d2731adb..dc2f33d3f78e45 100644 --- a/libibverbs/kern-abi.h +++ b/libibverbs/kern-abi.h @@ -277,8 +277,7 @@ struct ibv_kern_spec { }; }; -struct ibv_modify_srq_v3 { - struct ib_uverbs_cmd_hdr hdr; +struct ib_uverbs_modify_srq_v3 { __u32 srq_handle; __u32 attr_mask; __u32 max_wr; @@ -286,6 +285,9 @@ struct ibv_modify_srq_v3 { __u32 srq_limit; __u32 reserved; }; +#define _STRUCT_ib_uverbs_modify_srq_v3 +enum { IB_USER_VERBS_CMD_MODIFY_SRQ_V3 = IB_USER_VERBS_CMD_MODIFY_SRQ }; +DECLARE_CMDX(IB_USER_VERBS_CMD_MODIFY_SRQ_V3, ibv_modify_srq_v3, ib_uverbs_modify_srq_v3, empty); struct ibv_create_qp_resp_v3 { __u32 qp_handle;