From patchwork Sun Mar 27 11:30:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Majd Dibbiny X-Patchwork-Id: 8675791 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A8C849F44D for ; Sun, 27 Mar 2016 11:31:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A91532022A for ; Sun, 27 Mar 2016 11:31:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C1AEA20218 for ; Sun, 27 Mar 2016 11:31:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751344AbcC0LbL (ORCPT ); Sun, 27 Mar 2016 07:31:11 -0400 Received: from [193.47.165.129] ([193.47.165.129]:51573 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751323AbcC0LbL (ORCPT ); Sun, 27 Mar 2016 07:31:11 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from majd@mellanox.com) with ESMTPS (AES256-SHA encrypted); 27 Mar 2016 13:30:36 +0200 Received: from dev-l-vrt-202.mtl.labs.mlnx (dev-l-vrt-202.mtl.labs.mlnx [10.134.202.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id u2RBUaDw032487; Sun, 27 Mar 2016 14:30:36 +0300 From: Majd Dibbiny To: yishaih@mellanox.com Cc: linux-rdma@vger.kernel.org, matanb@mellanox.com, Majd Dibbiny Subject: [PATCH libmlx5] Add support for legacy context size Date: Sun, 27 Mar 2016 14:30:25 +0300 Message-Id: <1459078225-16205-1-git-send-email-majd@mellanox.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ibv_cmd_get_context fails in older kernels when passing a request length that the kernel doesn't know. To avoid breaking compatibility of new libmlx5 and older kernels, when ibv_cmd_get_context fails with the full request length, we try once again with the legacy length. Signed-off-by: Majd Dibbiny Reviewed-by: Yishai Hadas --- src/mlx5.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/mlx5.c b/src/mlx5.c index d19c376..7bd01bd 100644 --- a/src/mlx5.c +++ b/src/mlx5.c @@ -533,6 +533,28 @@ static int single_threaded_app(void) return 0; } +static int mlx5_cmd_get_context(struct mlx5_context *context, + struct mlx5_alloc_ucontext *req, + size_t req_len, + struct mlx5_alloc_ucontext_resp *resp, + size_t resp_len) +{ + if (!ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req, + req_len, &resp->ibv_resp, resp_len)) + return 0; + + /* The ibv_cmd_get_context fails in older kernels when passing + * a request length that the kernel doesn't know. + * To avoid breaking compatibility of new libmlx5 and older + * kernels, when ibv_cmd_get_context fails with the full + * request length, we try once again with the legacy length. + */ + return ibv_cmd_get_context(&context->ibv_ctx, &req->ibv_req, + offsetof(struct mlx5_alloc_ucontext, + cqe_version), + &resp->ibv_resp, resp_len); +} + static int mlx5_init_context(struct verbs_device *vdev, struct ibv_context *ctx, int cmd_fd) { @@ -598,8 +620,9 @@ static int mlx5_init_context(struct verbs_device *vdev, req.total_num_uuars = tot_uuars; req.num_low_latency_uuars = low_lat_uuars; req.cqe_version = MLX5_CQE_VERSION_V1; - if (ibv_cmd_get_context(&context->ibv_ctx, &req.ibv_req, sizeof req, - &resp.ibv_resp, sizeof resp)) + + if (mlx5_cmd_get_context(context, &req, sizeof(req), &resp, + sizeof(resp))) goto err_free_bf; context->max_num_qps = resp.qp_tab_size;