From patchwork Wed Feb 6 19:40:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 2106791 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id ED0713FDF1 for ; Wed, 6 Feb 2013 19:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758211Ab3BFTug (ORCPT ); Wed, 6 Feb 2013 14:50:36 -0500 Received: from mail-ob0-f170.google.com ([209.85.214.170]:56023 "EHLO mail-ob0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758029Ab3BFTud (ORCPT ); Wed, 6 Feb 2013 14:50:33 -0500 Received: by mail-ob0-f170.google.com with SMTP id wc20so1885841obb.15 for ; Wed, 06 Feb 2013 11:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=clmEE8bHJdeddG8a1wC3qdZ8UxcgQ7Uotqxj9Kaw8Fk=; b=qn+YUE1EMywa85SnuCljX817atm8h74bKl1bim7V/CcA+hA1eXzoZYAB8KDVEqCe2f CGkcCw58PtmvOHKb8ynRLzlTm9yrO+5Imi1Ei6Y+Uq1W/hLZGi8CEK645RNlN82cUJE7 RNWbOY98lVAgvUFZowNjX+FzLQGp72OPvWBFP6p/GhUuSYpZrG3M9eNey+XP1piEYyRP esaBnZpMI9illB0KnDuhr2By0SEVt6wEuhMlblLF+ob6z5mX2rrwijR5hZzxWgEr5Riq QLRLw2a3Cz3LDX7pvKXCZpjX/Rxh0ZVrS/9EHmMMcLTJrVlAYCzGUx+Set8AVClmGWHl x+aQ== X-Received: by 10.60.5.231 with SMTP id v7mr23234726oev.62.1360180233104; Wed, 06 Feb 2013 11:50:33 -0800 (PST) Received: from htj.dyndns.org (c-69-181-251-227.hsd1.ca.comcast.net. [69.181.251.227]) by mx.google.com with ESMTPS id l5sm39989590pax.10.2013.02.06.11.50.31 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 06 Feb 2013 11:50:32 -0800 (PST) From: Tejun Heo To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Tejun Heo , Hoang-Nam Nguyen , Christoph Raisch , linux-rdma@vger.kernel.org Subject: [PATCH 42/77] IB/ehca: convert to idr_alloc() Date: Wed, 6 Feb 2013 11:40:14 -0800 Message-Id: <1360179649-22465-43-git-send-email-tj@kernel.org> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1360179649-22465-1-git-send-email-tj@kernel.org> References: <1360179649-22465-1-git-send-email-tj@kernel.org> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Convert to the much saner new idr interface. Only compile tested. Signed-off-by: Tejun Heo Cc: Hoang-Nam Nguyen Cc: Christoph Raisch Cc: linux-rdma@vger.kernel.org --- drivers/infiniband/hw/ehca/ehca_cq.c | 27 +++++++-------------------- drivers/infiniband/hw/ehca/ehca_qp.c | 34 +++++++++++++++------------------- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/drivers/infiniband/hw/ehca/ehca_cq.c b/drivers/infiniband/hw/ehca/ehca_cq.c index 8f52901..212150c 100644 --- a/drivers/infiniband/hw/ehca/ehca_cq.c +++ b/drivers/infiniband/hw/ehca/ehca_cq.c @@ -128,7 +128,7 @@ struct ib_cq *ehca_create_cq(struct ib_device *device, int cqe, int comp_vector, void *vpage; u32 counter; u64 rpage, cqx_fec, h_ret; - int ipz_rc, ret, i; + int ipz_rc, i; unsigned long flags; if (cqe >= 0xFFFFFFFF - 64 - additional_cqe) @@ -163,32 +163,19 @@ struct ib_cq *ehca_create_cq(struct ib_device *device, int cqe, int comp_vector, adapter_handle = shca->ipz_hca_handle; param.eq_handle = shca->eq.ipz_eq_handle; - do { - if (!idr_pre_get(&ehca_cq_idr, GFP_KERNEL)) { - cq = ERR_PTR(-ENOMEM); - ehca_err(device, "Can't reserve idr nr. device=%p", - device); - goto create_cq_exit1; - } - - write_lock_irqsave(&ehca_cq_idr_lock, flags); - ret = idr_get_new(&ehca_cq_idr, my_cq, &my_cq->token); - write_unlock_irqrestore(&ehca_cq_idr_lock, flags); - } while (ret == -EAGAIN); + idr_preload(GFP_KERNEL); + write_lock_irqsave(&ehca_cq_idr_lock, flags); + my_cq->token = idr_alloc(&ehca_cq_idr, my_cq, 0, 0x2000000, GFP_NOWAIT); + write_unlock_irqrestore(&ehca_cq_idr_lock, flags); + idr_preload_end(); - if (ret) { + if (my_cq->token < 0) { cq = ERR_PTR(-ENOMEM); ehca_err(device, "Can't allocate new idr entry. device=%p", device); goto create_cq_exit1; } - if (my_cq->token > 0x1FFFFFF) { - cq = ERR_PTR(-ENOMEM); - ehca_err(device, "Invalid number of cq. device=%p", device); - goto create_cq_exit2; - } - /* * CQs maximum depth is 4GB-64, but we need additional 20 as buffer * for receiving errors CQEs. diff --git a/drivers/infiniband/hw/ehca/ehca_qp.c b/drivers/infiniband/hw/ehca/ehca_qp.c index 1493939..00d6861 100644 --- a/drivers/infiniband/hw/ehca/ehca_qp.c +++ b/drivers/infiniband/hw/ehca/ehca_qp.c @@ -636,30 +636,26 @@ static struct ehca_qp *internal_create_qp( my_qp->send_cq = container_of(init_attr->send_cq, struct ehca_cq, ib_cq); - do { - if (!idr_pre_get(&ehca_qp_idr, GFP_KERNEL)) { - ret = -ENOMEM; - ehca_err(pd->device, "Can't reserve idr resources."); - goto create_qp_exit0; - } + idr_preload(GFP_KERNEL); + write_lock_irqsave(&ehca_qp_idr_lock, flags); - write_lock_irqsave(&ehca_qp_idr_lock, flags); - ret = idr_get_new(&ehca_qp_idr, my_qp, &my_qp->token); - write_unlock_irqrestore(&ehca_qp_idr_lock, flags); - } while (ret == -EAGAIN); + ret = idr_alloc(&ehca_qp_idr, my_qp, 0, 0x2000000, GFP_NOWAIT); + if (ret >= 0) + my_qp->token = ret; - if (ret) { - ret = -ENOMEM; - ehca_err(pd->device, "Can't allocate new idr entry."); + write_unlock_irqrestore(&ehca_qp_idr_lock, flags); + idr_preload_end(); + if (ret < 0) { + if (ret == -ENOSPC) { + ret = -EINVAL; + ehca_err(pd->device, "Invalid number of qp"); + } else { + ret = -ENOMEM; + ehca_err(pd->device, "Can't allocate new idr entry."); + } goto create_qp_exit0; } - if (my_qp->token > 0x1FFFFFF) { - ret = -EINVAL; - ehca_err(pd->device, "Invalid number of qp"); - goto create_qp_exit1; - } - if (has_srq) parms.srq_token = my_qp->token;