From patchwork Wed Mar 11 04:56:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Somnath Kotur X-Patchwork-Id: 5977331 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B996BBF440 for ; Tue, 10 Mar 2015 12:30:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9CCBC2022D for ; Tue, 10 Mar 2015 12:30:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 255972021F for ; Tue, 10 Mar 2015 12:30:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751390AbbCJMan (ORCPT ); Tue, 10 Mar 2015 08:30:43 -0400 Received: from cmexedge2.emulex.com ([138.239.224.100]:30457 "EHLO CMEXEDGE2.ext.emulex.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751666AbbCJMal (ORCPT ); Tue, 10 Mar 2015 08:30:41 -0400 Received: from CMEXHTCAS2.ad.emulex.com (138.239.115.218) by CMEXEDGE2.ext.emulex.com (138.239.224.100) with Microsoft SMTP Server (TLS) id 14.3.210.2; Tue, 10 Mar 2015 05:30:44 -0700 Received: from codebrowse.emulex.com (10.192.207.129) by smtp.emulex.com (138.239.115.208) with Microsoft SMTP Server id 14.3.210.2; Tue, 10 Mar 2015 05:30:37 -0700 From: Somnath Kotur To: CC: , Matan Barak , "Somnath Kotur" Subject: [PATCH v2 for-next 09/32] IB/core: Support find sgid index using a filter function Date: Wed, 11 Mar 2015 10:26:01 +0530 X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1426049785-30364-1-git-send-email-somnath.kotur@emulex.com> References: <1426049785-30364-1-git-send-email-somnath.kotur@emulex.com> MIME-Version: 1.0 Message-ID: Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matan Barak Sometimes a sgid index need to be found based on variable parameters. For example, when the CM gets a packet from network, it needs to match a sgid_index that matches the appropriate L2 attributes of a packet. Extending the cache's API to include Ethernet L2 attribute is problematic, since they may be vastly extended in the future. As a result, we add a find function that gets a user filter function and searches the GID table until a match is found. Signed-off-by: Matan Barak Signed-off-by: Somnath Kotur --- drivers/infiniband/core/cache.c | 24 ++++++++++++ drivers/infiniband/core/core_priv.h | 9 +++++ drivers/infiniband/core/roce_gid_cache.c | 66 ++++++++++++++++++++++++++++++++ include/rdma/ib_cache.h | 27 +++++++++++++ 4 files changed, 126 insertions(+) diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c index 882d491..ae86fe8 100644 --- a/drivers/infiniband/core/cache.c +++ b/drivers/infiniband/core/cache.c @@ -273,6 +273,30 @@ int ib_find_cached_gid_by_port(struct ib_device *device, } EXPORT_SYMBOL(ib_find_cached_gid_by_port); +int ib_find_gid_by_filter(struct ib_device *device, + union ib_gid *gid, + u8 port_num, + bool (*filter)(const union ib_gid *gid, + const struct ib_gid_attr *, + void *), + void *context, u16 *index) +{ + /* Look for a RoCE device with the specified GID. */ + if (!ib_cache_use_roce_gid_cache(device, port_num)) + return roce_gid_cache_find_gid_by_filter(device, gid, + port_num, filter, + context, index); + + /* Only RoCE GID cache supports filter function */ + if (filter) + return -ENOSYS; + + /* If no RoCE devices with the specified GID, look for IB device. */ + return __ib_find_cached_gid_by_port(device, port_num, + gid, index); +} +EXPORT_SYMBOL(ib_find_gid_by_filter); + int ib_get_cached_pkey(struct ib_device *device, u8 port_num, int index, diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index 411672f..d6e73f8 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -84,6 +84,15 @@ int roce_gid_cache_find_gid_by_port(struct ib_device *ib_dev, union ib_gid *gid, enum ib_gid_type gid_type, u8 port, struct net *net, int if_index, u16 *index); +int roce_gid_cache_find_gid_by_filter(struct ib_device *ib_dev, + union ib_gid *gid, + u8 port, + bool (*filter)(const union ib_gid *gid, + const struct ib_gid_attr *, + void *), + void *context, + u16 *index); + int roce_gid_cache_is_active(struct ib_device *ib_dev, u8 port); enum roce_gid_cache_default_mode { diff --git a/drivers/infiniband/core/roce_gid_cache.c b/drivers/infiniband/core/roce_gid_cache.c index 5c109f7..ee9ac4d 100644 --- a/drivers/infiniband/core/roce_gid_cache.c +++ b/drivers/infiniband/core/roce_gid_cache.c @@ -436,6 +436,72 @@ int roce_gid_cache_find_gid_by_port(struct ib_device *ib_dev, union ib_gid *gid, return -ENOENT; } +int roce_gid_cache_find_gid_by_filter(struct ib_device *ib_dev, + union ib_gid *gid, + u8 port, + bool (*filter)(const union ib_gid *, + const struct ib_gid_attr *, + void *), + void *context, + u16 *index) +{ + struct ib_roce_gid_cache *cache; + unsigned int i; + bool found = false; + + if (!ib_dev->cache.roce_gid_cache) + return -ENOSYS; + + if (port < start_port(ib_dev) || + port > start_port(ib_dev) + ib_dev->phys_port_cnt || + rdma_port_get_link_layer(ib_dev, port) != + IB_LINK_LAYER_ETHERNET) + return -ENOSYS; + + cache = ib_dev->cache.roce_gid_cache[port - start_port(ib_dev)]; + + if (!cache || !cache->active) + return -ENOENT; + + for (i = 0; i < cache->sz; i++) { + unsigned int orig_seq; + struct ib_gid_attr attr; + + orig_seq = cache->data_vec[i].seq; + if (orig_seq == -1) + continue; + /* Make sure the sequence number we remeber was read + * before the gid cache entry content is read. + */ + smp_rmb(); + + if (memcmp(gid, &cache->data_vec[i].gid, sizeof(*gid))) + continue; + + memcpy(&attr, &cache->data_vec[i].attr, sizeof(attr)); + + rcu_read_lock(); + + /* Make sure we finished reading the attribute */ + smp_rmb(); + if (orig_seq == ACCESS_ONCE(cache->data_vec[i].seq)) + if (!filter || filter(gid, &attr, context)) + found = true; + + rcu_read_unlock(); + + if (found) + break; + } + + if (!found) + return -ENOENT; + + if (index) + *index = i; + return 0; +} + static struct ib_roce_gid_cache *alloc_roce_gid_cache(int sz) { struct ib_roce_gid_cache *cache = diff --git a/include/rdma/ib_cache.h b/include/rdma/ib_cache.h index 36b72bf..5ed728c 100644 --- a/include/rdma/ib_cache.h +++ b/include/rdma/ib_cache.h @@ -111,6 +111,33 @@ int ib_find_cached_gid_by_port(struct ib_device *device, struct net *net, int if_index, u16 *index); + +/** + * ib_find_gid_by_filter - Returns the GID table index where a specified + * GID value occurs + * @device: The device to query. + * @gid: The GID value to search for. + * @port_num: The port number of the device where the GID value could be + * searched. + * @filter: The filter function is executed on any matching GID in the table. + * If the filter function returns true, the corresponding index is returned, + * otherwise, we continue searching the GID table. It's guaranteed that + * while filter is executed, ndev field is valid and the structure won't + * change. filter is executed in an atomic context. filter must be NULL + * when RoCE GID cache isn't supported on the respective device's port. + * @index: The index into the cached GID table where the GID was found. This + * parameter may be NULL. + * + * ib_find_gid_by_filter() searches for the specified GID value in + * the local software cache. + */ +int ib_find_gid_by_filter(struct ib_device *device, + union ib_gid *gid, + u8 port_num, + bool (*filter)(const union ib_gid *gid, + const struct ib_gid_attr *, + void *), + void *context, u16 *index); /** * ib_get_cached_pkey - Returns a cached PKey table entry * @device: The device to query.