From patchwork Fri Aug 3 08:40:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jackm X-Patchwork-Id: 1269801 X-Patchwork-Delegate: roland@digitalvampire.org Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 4703BDF25A for ; Fri, 3 Aug 2012 08:41:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751533Ab2HCIlZ (ORCPT ); Fri, 3 Aug 2012 04:41:25 -0400 Received: from eu1sys200aog112.obsmtp.com ([207.126.144.133]:46259 "HELO eu1sys200aog112.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753110Ab2HCIlZ (ORCPT ); Fri, 3 Aug 2012 04:41:25 -0400 Received: from mtlsws123.lab.mtl.com ([82.166.227.17]) (using TLSv1) by eu1sys200aob112.postini.com ([207.126.147.11]) with SMTP ID DSNKUBuOscQOTxah0MrMT+heMN2Nm4SU+Lso@postini.com; Fri, 03 Aug 2012 08:41:24 UTC Received: from r-vnc04.lab.mtl.com (r-vnc04.lab.mtl.com [10.208.0.116]) by mtlsws123.lab.mtl.com (8.13.8/8.13.8) with ESMTP id q738f2Of027921; Fri, 3 Aug 2012 11:41:20 +0300 From: Jack Morgenstein To: roland@kernel.org Cc: linux-rdma@vger.kernel.org, ogerlitz@mellanox.com, Jack Morgenstein Subject: [PATCH for-next V2 03/22] IB/core: Add ib_find_exact_cached_pkey() to search for 16-bit pkey match Date: Fri, 3 Aug 2012 11:40:39 +0300 Message-Id: <1343983258-6268-4-git-send-email-jackm@dev.mellanox.co.il> X-Mailer: git-send-email 1.7.8.2 In-Reply-To: <1343983258-6268-1-git-send-email-jackm@dev.mellanox.co.il> References: <1343983258-6268-1-git-send-email-jackm@dev.mellanox.co.il> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org When port pkey table potentially contains both full and partial membership copies for the same pkey, we need a function to find the exact (16-bit) pkey index. This is particularly necessary when the master forwards QP1 MADS sent by guests. If the guest has sent the MAD with a limited membership pkey, we wish to forward the MAD using the same limited membership pkey. Since master may have both the limited and the full member pkeys in its table, we must make sure to retrieve the limited membership pkey in this case. This requires the 16-bit pkey lookup function (which includes the membership bit). Signed-off-by: Jack Morgenstein Signed-off-by: Or Gerlitz --- drivers/infiniband/core/cache.c | 32 ++++++++++++++++++++++++++++++++ include/rdma/ib_cache.h | 16 ++++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-) diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 0f2f2b7..d8a8c83 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c @@ -198,6 +198,38 @@ int ib_find_cached_pkey(struct ib_device *device, } EXPORT_SYMBOL(ib_find_cached_pkey); +int ib_find_exact_cached_pkey(struct ib_device *device, + u8 port_num, + u16 pkey, + u16 *index) +{ + struct ib_pkey_cache *cache; + unsigned long flags; + int i; + int ret = -ENOENT; + + if (port_num < start_port(device) || port_num > end_port(device)) + return -EINVAL; + + read_lock_irqsave(&device->cache.lock, flags); + + cache = device->cache.pkey_cache[port_num - start_port(device)]; + + *index = -1; + + for (i = 0; i < cache->table_len; ++i) + if (cache->table[i] == pkey) { + *index = i; + ret = 0; + break; + } + + read_unlock_irqrestore(&device->cache.lock, flags); + + return ret; +} +EXPORT_SYMBOL(ib_find_exact_cached_pkey); + int ib_get_cached_lmc(struct ib_device *device, u8 port_num, u8 *lmc) diff --git a/include/rdma/ib_cache.h b/include/rdma/ib_cache.h index 00a2b8e..ad9a3c2 100644 --- a/include/rdma/ib_cache.h +++ b/include/rdma/ib_cache.h @@ -101,6 +101,22 @@ int ib_find_cached_pkey(struct ib_device *device, u16 *index); /** + * ib_find_exact_cached_pkey - Returns the PKey table index where a specified + * PKey value occurs. Comparison uses the FULL 16 bits (incl membership bit) + * @device: The device to query. + * @port_num: The port number of the device to search for the PKey. + * @pkey: The PKey value to search for. + * @index: The index into the cached PKey table where the PKey was found. + * + * ib_find_exact_cached_pkey() searches the specified PKey table in + * the local software cache. + */ +int ib_find_exact_cached_pkey(struct ib_device *device, + u8 port_num, + u16 pkey, + u16 *index); + +/** * ib_get_cached_lmc - Returns a cached lmc table entry * @device: The device to query. * @port_num: The port number of the device to query.