From patchwork Sat Feb 18 15:43:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 9581135 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 732BD604A4 for ; Sat, 18 Feb 2017 15:44:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64C362871E for ; Sat, 18 Feb 2017 15:44:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59AF728731; Sat, 18 Feb 2017 15:44:44 +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 C32832871E for ; Sat, 18 Feb 2017 15:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753410AbdBRPon (ORCPT ); Sat, 18 Feb 2017 10:44:43 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:33670 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752971AbdBRPom (ORCPT ); Sat, 18 Feb 2017 10:44:42 -0500 Received: by mail-wm0-f53.google.com with SMTP id t18so14733543wmt.0 for ; Sat, 18 Feb 2017 07:44:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=JN48GgPwPOorjTCY8f87oXuUdgyhCk3onov/FFE9b7g=; b=gVPzZp//pjCh/xwSZtufPPf1SMwFiLtZlMxr2L+2XNcyYJpw3GBDJsO3IwF/pYKjtj 9SV1Xb4WkpIh/lMuzW/j3KFFJ1hwJQ8KSk6/25Avm+OTNH2DG4kzuMLxPIbLfQiWxG2S 1P1g7WKli0GNaqdGtcA/K0GFCfsxD9ZFBm9gg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=JN48GgPwPOorjTCY8f87oXuUdgyhCk3onov/FFE9b7g=; b=YLvap650Lg/sKOXDk1sXsasLraq41XHYoJp3gobXzFKRZOBXUjpt03Qrny7LLC4cIo /13Ds55lfByP0Ya0iZBHEVAOLH0G1jkFDWgBlLOVbLcpjcoqoA5ZpYRT7F46wggLzr9G IIRelCBOZ/Xx/cOYc20DZY4zdpHt7gj3gkHDG4KGgUhDEUnGnLwP+hnppXdtidb25D+n 7rYGCNH8wZ08bPAe40c7qG49lh+1O5IOYb79Eu1c6AnIhcnS18a82PdUeB7iuOu0hpEx JfgxvKyVRhlggxcxvDIK/x0SmAB0VzQpktWLpyJn8ncSH3d32qii3Pr78BvqbmyT96/f xs7A== X-Gm-Message-State: AMke39mk+bHspxEeZ0yhMSjJG2TDhjUQLSrs7Vel0DQQmPXRpzK4Dk5ZMeDTlZVbwiv17tRs X-Received: by 10.28.92.193 with SMTP id q184mr10057446wmb.139.1487432680509; Sat, 18 Feb 2017 07:44:40 -0800 (PST) Received: from neo00-el73.iig.avagotech.net ([192.19.239.250]) by smtp.gmail.com with ESMTPSA id l67sm6076098wmf.1.2017.02.18.07.44.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 07:44:39 -0800 (PST) From: Devesh Sharma To: linux-rdma@vger.kernel.org Subject: [rdma-core v2 8/9] libbnxt_re: Add support for atomic operations Date: Sat, 18 Feb 2017 10:43:57 -0500 Message-Id: <1487432638-19607-9-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487432638-19607-1-git-send-email-devesh.sharma@broadcom.com> References: <1487432638-19607-1-git-send-email-devesh.sharma@broadcom.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 This patch adds support for compare-and-swap and fetch-and-add atomic operations in user library. v1->v2 -- Fixed the missing "break" -- Changed macros to inline function Signed-off-by: Sriharsha Basavapatna Signed-off-by: Somnath Kotur Signed-off-by: Selvin Xavier Signed-off-by: Devesh Sharma --- providers/bnxt_re/bnxt_re-abi.h | 3 ++- providers/bnxt_re/main.h | 8 +++++- providers/bnxt_re/memory.h | 10 +++++++ providers/bnxt_re/verbs.c | 58 +++++++++++++++++++++++++++++++++++------ 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/providers/bnxt_re/bnxt_re-abi.h b/providers/bnxt_re/bnxt_re-abi.h index 581e1b7..557221b 100644 --- a/providers/bnxt_re/bnxt_re-abi.h +++ b/providers/bnxt_re/bnxt_re-abi.h @@ -54,7 +54,8 @@ enum bnxt_re_wr_opcode { BNXT_RE_WR_OPCD_ATOMIC_FA = 0x0B, BNXT_RE_WR_OPCD_LOC_INVAL = 0x0C, BNXT_RE_WR_OPCD_BIND = 0x0E, - BNXT_RE_WR_OPCD_RECV = 0x80 + BNXT_RE_WR_OPCD_RECV = 0x80, + BNXT_RE_WR_OPCD_INVAL = 0xFF }; enum bnxt_re_wr_flags { diff --git a/providers/bnxt_re/main.h b/providers/bnxt_re/main.h index 9d99c64..a417328 100644 --- a/providers/bnxt_re/main.h +++ b/providers/bnxt_re/main.h @@ -236,9 +236,15 @@ static inline uint8_t bnxt_re_ibv_to_bnxt_wr_opcd(uint8_t ibv_opcd) case IBV_WR_RDMA_READ: bnxt_opcd = BNXT_RE_WR_OPCD_RDMA_READ; break; + case IBV_WR_ATOMIC_CMP_AND_SWP: + bnxt_opcd = BNXT_RE_WR_OPCD_ATOMIC_CS; + break; + case IBV_WR_ATOMIC_FETCH_AND_ADD: + bnxt_opcd = BNXT_RE_WR_OPCD_ATOMIC_FA; + break; /* TODO: Add other opcodes */ default: - bnxt_opcd = 0xFF; + bnxt_opcd = BNXT_RE_WR_OPCD_INVAL; break; }; diff --git a/providers/bnxt_re/memory.h b/providers/bnxt_re/memory.h index debb31a..d7e6a92 100644 --- a/providers/bnxt_re/memory.h +++ b/providers/bnxt_re/memory.h @@ -83,6 +83,16 @@ static inline void iowrite32(__u32 *dst, uint32_t *src) *(volatile __u32 *)dst = *src; } +static inline __u32 upper_32_bits(uint64_t n) +{ + return (__u32)((n >> 16) >> 16); +} + +static inline __u32 lower_32_bits(uint64_t n) +{ + return (__u32)(n & 0xFFFFFFFFUL); +} + /* Basic queue operation */ static inline uint32_t bnxt_re_is_que_full(struct bnxt_re_queue *que) { diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c index 36a1a6e..bc06386 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -1068,6 +1068,9 @@ static int bnxt_re_build_send_sqe(struct bnxt_re_qp *qp, void *wqe, /* Fill Header */ opcode = bnxt_re_ibv_to_bnxt_wr_opcd(wr->opcode); + if (opcode == BNXT_RE_WR_OPCD_INVAL) + return -EINVAL; + hdr->rsv_ws_fl_wt |= (opcode & BNXT_RE_HDR_WT_MASK); if (is_inline) { @@ -1116,6 +1119,44 @@ static int bnxt_re_build_rdma_sqe(struct bnxt_re_qp *qp, void *wqe, return len; } +static int bnxt_re_build_cns_sqe(struct bnxt_re_qp *qp, void *wqe, + struct ibv_send_wr *wr) +{ + struct bnxt_re_bsqe *hdr = wqe; + struct bnxt_re_atomic *sqe = ((void *)wqe + + sizeof(struct bnxt_re_bsqe)); + int len; + + len = bnxt_re_build_send_sqe(qp, wqe, wr, false); + hdr->key_immd = wr->wr.atomic.rkey; + sqe->rva_lo = lower_32_bits(wr->wr.atomic.remote_addr); + sqe->rva_hi = upper_32_bits(wr->wr.atomic.remote_addr); + sqe->cmp_dt_lo = lower_32_bits(wr->wr.atomic.compare_add); + sqe->cmp_dt_hi = upper_32_bits(wr->wr.atomic.compare_add); + sqe->swp_dt_lo = lower_32_bits(wr->wr.atomic.swap); + sqe->swp_dt_hi = upper_32_bits(wr->wr.atomic.swap); + + return len; +} + +static int bnxt_re_build_fna_sqe(struct bnxt_re_qp *qp, void *wqe, + struct ibv_send_wr *wr) +{ + struct bnxt_re_bsqe *hdr = wqe; + struct bnxt_re_atomic *sqe = ((void *)wqe + + sizeof(struct bnxt_re_bsqe)); + int len; + + len = bnxt_re_build_send_sqe(qp, wqe, wr, false); + hdr->key_immd = wr->wr.atomic.rkey; + sqe->rva_lo = lower_32_bits(wr->wr.atomic.remote_addr); + sqe->rva_hi = upper_32_bits(wr->wr.atomic.remote_addr); + sqe->cmp_dt_lo = lower_32_bits(wr->wr.atomic.compare_add); + sqe->cmp_dt_hi = upper_32_bits(wr->wr.atomic.compare_add); + + return len; +} + int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr, struct ibv_send_wr **bad) { @@ -1169,27 +1210,28 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr, else bytes = bnxt_re_build_send_sqe(qp, sqe, wr, is_inline); - if (bytes < 0) - ret = (bytes == -EINVAL) ? EINVAL : ENOMEM; break; case IBV_WR_RDMA_WRITE_WITH_IMM: hdr->key_immd = wr->imm_data; case IBV_WR_RDMA_WRITE: bytes = bnxt_re_build_rdma_sqe(qp, sqe, wr, is_inline); - if (bytes < 0) - ret = ENOMEM; break; case IBV_WR_RDMA_READ: bytes = bnxt_re_build_rdma_sqe(qp, sqe, wr, false); - if (bytes < 0) - ret = ENOMEM; + break; + case IBV_WR_ATOMIC_CMP_AND_SWP: + bytes = bnxt_re_build_cns_sqe(qp, sqe, wr); + break; + case IBV_WR_ATOMIC_FETCH_AND_ADD: + bytes = bnxt_re_build_fna_sqe(qp, sqe, wr); break; default: - ret = EINVAL; + bytes = -EINVAL; break; } - if (ret) { + if (bytes < 0) { + ret = (bytes == -EINVAL) ? EINVAL : ENOMEM; *bad = wr; break; }