From patchwork Mon Apr 24 18:53:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 9696991 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 5BFB860224 for ; Mon, 24 Apr 2017 18:53:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5004228419 for ; Mon, 24 Apr 2017 18:53:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44DCC2841F; Mon, 24 Apr 2017 18:53:45 +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 CA99A28419 for ; Mon, 24 Apr 2017 18:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1173872AbdDXSxn (ORCPT ); Mon, 24 Apr 2017 14:53:43 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:34072 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1173868AbdDXSxn (ORCPT ); Mon, 24 Apr 2017 14:53:43 -0400 Received: by mail-pf0-f181.google.com with SMTP id c198so16429735pfc.1 for ; Mon, 24 Apr 2017 11:53:43 -0700 (PDT) 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=0qNbLUuwzmSRhACLhhQkbKofYULMwy3ybVCyJqCQmAw=; b=gdmoeX/bAQda/NnMu81tQIkzhOUD5iXO3Mf/zBXnv3/sU8tn2OkknkFdxAfF2pXCwK obBiEBpS9C2NLiwenDYUorrQ1s9NI6eHpMFvqieIuBV9cY3jHsR4nMkYEdB18gnc0b6W mVRm66H0I9l+awKg9FCjMjsZ5Gs3909GjfZ+U= 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=0qNbLUuwzmSRhACLhhQkbKofYULMwy3ybVCyJqCQmAw=; b=ee8o/7V99EZcTY1rXEhiPWx82cHf0RuOcMc77Fc6fEi26XkkusDgs+Bg3mkAguhE/0 5C6CTNWjOb+FqpQWrkS/XaEZb/dthDaejYR0hJ3FR3eS+fccbE9iN0oImfGK+eEyRgQP RVjKhtUtJiAm6x8Vguz99V9Kszo7afhEPNteydG18X2CqNFY1sf+lQ/Y6bA9W/dAPkt7 /GuO/y01luId0Nv+VKwBfrASLIj6B12YOSwqOl8qtAk+H4dCZwI34QfudjEryal4OFCi Cnx1QMk+REkKPlfnBHSCpVp8PrQM9IM6zHivo+mnq37J+qn2x8H0u88863kotKTiMatY +mcg== X-Gm-Message-State: AN3rC/4Pw5BS9ELXLYjrLMDZ6ZaofgUgXJPhK8nqAQM9vZjtngJrrXJE jDkNbS/gOrhFZd1/iA8= X-Received: by 10.84.192.37 with SMTP id b34mr5790970pld.174.1493060022080; Mon, 24 Apr 2017 11:53:42 -0700 (PDT) Received: from neo00-el73.iig.avagotech.net ([192.19.239.250]) by smtp.gmail.com with ESMTPSA id w5sm20333554pfd.23.2017.04.24.11.53.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Apr 2017 11:53:41 -0700 (PDT) From: Devesh Sharma To: linux-rdma@vger.kernel.org Subject: [rdma-core v5 8/8] libbnxt_re: Add support for atomic operations Date: Mon, 24 Apr 2017 14:53:15 -0400 Message-Id: <1493059995-636-9-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1493059995-636-1-git-send-email-devesh.sharma@broadcom.com> References: <1493059995-636-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. v4->v5 -- Removed definition of upper_32_bits and lower_32_bits. v3->v4 -- Changed weq init code to match the DMA ABI. 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/verbs.c | 52 ++++++++++++++++++++++++++++++++++------- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/providers/bnxt_re/bnxt_re-abi.h b/providers/bnxt_re/bnxt_re-abi.h index db11322..205d8c4 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 1a4dc06..4cc8abd 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/verbs.c b/providers/bnxt_re/verbs.c index 1f8ff8e..2768a56 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -1068,6 +1068,8 @@ 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; hdrval = (opcode & BNXT_RE_HDR_WT_MASK); if (is_inline) { @@ -1115,6 +1117,39 @@ 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 = htole32(wr->wr.atomic.rkey); + sqe->rva = htole64(wr->wr.atomic.remote_addr); + sqe->cmp_dt = htole64(wr->wr.atomic.compare_add); + sqe->swp_dt = htole64(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 = htole32(wr->wr.atomic.rkey); + sqe->rva = htole64(wr->wr.atomic.remote_addr); + sqe->cmp_dt = htole64(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) { @@ -1168,27 +1203,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 = htole32(be32toh(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; }