From patchwork Mon Oct 17 16:31:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 77774 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp476981qge; Mon, 17 Oct 2016 09:32:45 -0700 (PDT) X-Received: by 10.66.233.3 with SMTP id ts3mr31365610pac.17.1476721965212; Mon, 17 Oct 2016 09:32:45 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h19si28143238pgn.301.2016.10.17.09.32.44; Mon, 17 Oct 2016 09:32:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936218AbcJQQch (ORCPT + 27 others); Mon, 17 Oct 2016 12:32:37 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:36078 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936059AbcJQQb4 (ORCPT ); Mon, 17 Oct 2016 12:31:56 -0400 Received: by mail-pf0-f182.google.com with SMTP id e6so80836206pfk.3 for ; Mon, 17 Oct 2016 09:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d4fIPw7yTCWKA9Adb9nsZGQS0p3+vqxUStTGCsy0Q/k=; b=UsRbYhmPi4w+m5tVcDjMGlbYE8n+jxI9shnMKKU1iQ1ng27ZFifLalSbVtrXFOoDzG TTaEvStiZY4U28CDSJCTRTSah950DlCwOn/SdBi4lnWsgYgY7eRR4FTSqvZGWmyJhW05 N0iH0hYS9X9gkd481onx888RISC0LOkf24NFo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=d4fIPw7yTCWKA9Adb9nsZGQS0p3+vqxUStTGCsy0Q/k=; b=QNrLlFc28Jdkat7OJ9B3bItqz4lAhXrf/D8uWN/WwW9EzDlgAjkOjg9sHTxiYFSeEB em8Qe7DnovuGOnjSo1nyE4HlftbHtWfg7eqfZUdXc3/KxLUHIX6cyp7NmJQZ4SAV6dzk 2ceBdW65UuIY2p4Rzf9onEJo9HL3xqW55j15jKezLu41F7nIciVpkruJPwXbzsELijfX lScxu1xrdRUZ+MGrLxmUCkLGqZQ7h7z6l3d0E+4/FAkrjWGdGBXKk/jL+9nNxTbPw3NP aZ1r5LtemLOS1KrMFS4xKHGHXykVDdaGZdN6OKcSHJlq1V6ahxZX451ELkuEdZKTkzQg NwCw== X-Gm-Message-State: AA6/9Rn/X3Gc3XEcLvv2df1oYujGryRcK9oopOVarCDH/HAUgrNTgwvZv8p8e6mz8jBpgQ7c X-Received: by 10.99.51.15 with SMTP id z15mr32697421pgz.41.1476721914053; Mon, 17 Oct 2016 09:31:54 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id o9sm43009638pac.27.2016.10.17.09.31.51 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Oct 2016 09:31:53 -0700 (PDT) From: Binoy Jayan To: Doug Ledford , Sean Hefty , Hal Rosenstock Cc: Arnd Bergmann , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Binoy Jayan Subject: [PATCH 6/8] IB/hns: Replace counting semaphore event_sem with wait condition Date: Mon, 17 Oct 2016 22:01:00 +0530 Message-Id: <1476721862-7070-7-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1476721862-7070-1-git-send-email-binoy.jayan@linaro.org> References: <1476721862-7070-1-git-send-email-binoy.jayan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Counting semaphores are going away in the future, so replace the semaphore hns_roce_cmdq::event_sem with an open-coded implementation. Signed-off-by: Binoy Jayan --- drivers/infiniband/hw/hns/hns_roce_cmd.c | 16 ++++++++++++---- drivers/infiniband/hw/hns/hns_roce_device.h | 3 ++- include/rdma/ib_sa.h | 5 +++++ 3 files changed, 19 insertions(+), 5 deletions(-) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project diff --git a/drivers/infiniband/hw/hns/hns_roce_cmd.c b/drivers/infiniband/hw/hns/hns_roce_cmd.c index 1421fdb..3e76717 100644 --- a/drivers/infiniband/hw/hns/hns_roce_cmd.c +++ b/drivers/infiniband/hw/hns/hns_roce_cmd.c @@ -248,10 +248,14 @@ static int hns_roce_cmd_mbox_wait(struct hns_roce_dev *hr_dev, u64 in_param, { int ret = 0; - down(&hr_dev->cmd.event_sem); + wait_event(hr_dev->cmd.event_sem.wq, + atomic_add_unless(&hr_dev->cmd.event_sem.count, -1, 0)); + ret = __hns_roce_cmd_mbox_wait(hr_dev, in_param, out_param, in_modifier, op_modifier, op, timeout); - up(&hr_dev->cmd.event_sem); + + if (atomic_inc_return(&hr_dev->cmd.event_sem.count) == 1) + wake_up(&hr_dev->cmd.event_sem.wq); return ret; } @@ -313,7 +317,9 @@ int hns_roce_cmd_use_events(struct hns_roce_dev *hr_dev) hr_cmd->context[hr_cmd->max_cmds - 1].next = -1; hr_cmd->free_head = 0; - sema_init(&hr_cmd->event_sem, hr_cmd->max_cmds); + init_waitqueue_head(&hr_cmd->event_sem.wq); + atomic_set(&hr_cmd->event_sem.count, hr_cmd->max_cmds); + spin_lock_init(&hr_cmd->context_lock); hr_cmd->token_mask = CMD_TOKEN_MASK; @@ -332,7 +338,9 @@ void hns_roce_cmd_use_polling(struct hns_roce_dev *hr_dev) hr_cmd->use_events = 0; for (i = 0; i < hr_cmd->max_cmds; ++i) - down(&hr_cmd->event_sem); + wait_event(hr_cmd->event_sem.wq, + atomic_add_unless( + &hr_dev->cmd.event_sem.count, -1, 0)); kfree(hr_cmd->context); mutex_unlock(&hr_cmd->poll_mutex); diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h index 2afe075..6aed04a 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -34,6 +34,7 @@ #define _HNS_ROCE_DEVICE_H #include +#include #include #define DRV_NAME "hns_roce" @@ -364,7 +365,7 @@ struct hns_roce_cmdq { * Event mode: cmd register mutex protection, * ensure to not exceed max_cmds and user use limit region */ - struct semaphore event_sem; + struct ib_semaphore event_sem; int max_cmds; spinlock_t context_lock; int free_head; diff --git a/include/rdma/ib_sa.h b/include/rdma/ib_sa.h index 5ee7aab..1901042 100644 --- a/include/rdma/ib_sa.h +++ b/include/rdma/ib_sa.h @@ -291,6 +291,11 @@ struct ib_sa_service_rec { #define IB_SA_GUIDINFO_REC_GID6 IB_SA_COMP_MASK(10) #define IB_SA_GUIDINFO_REC_GID7 IB_SA_COMP_MASK(11) +struct ib_semaphore { + wait_queue_head_t wq; + atomic_t count; +}; + struct ib_sa_guidinfo_rec { __be16 lid; u8 block_num;