From patchwork Fri Aug 6 22:50:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vu Pham X-Patchwork-Id: 118085 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o76MtctV027523 for ; Fri, 6 Aug 2010 22:57:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965177Ab0HFW5W (ORCPT ); Fri, 6 Aug 2010 18:57:22 -0400 Received: from p02c11o144.mxlogic.net ([208.65.144.77]:60794 "EHLO p02c11o144.mxlogic.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964904Ab0HFW5V (ORCPT ); Fri, 6 Aug 2010 18:57:21 -0400 Received: from unknown [63.251.237.3] (EHLO p02c11o144.mxlogic.net) by p02c11o144.mxlogic.net(mxl_mta-6.7.0-0) with ESMTP id 1539c5c4.4d1f3940.32287.00-554.74981.p02c11o144.mxlogic.net (envelope-from ); Fri, 06 Aug 2010 16:57:21 -0600 (MDT) X-MXL-Hash: 4c5c93517eda0d27-98a5757235dcaccb20622f4fc1ccb3a2cce48ee6 Received: from unknown [63.251.237.3] by p02c11o144.mxlogic.net(mxl_mta-6.7.0-0) with SMTP id fa19c5c4.0.31574.00-375.73730.p02c11o144.mxlogic.net (envelope-from ); Fri, 06 Aug 2010 16:50:24 -0600 (MDT) X-MXL-Hash: 4c5c91b00dbd9119-ed1a5d6b2ebebf336f76949ff1a135fa296ebbc4 Received: from vu-lt.mti.mtl.com ([10.2.1.17]) by mtiexch01.mti.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 6 Aug 2010 15:54:17 -0700 Message-ID: <4C5C9199.8060901@mellanox.com> Date: Fri, 06 Aug 2010 15:50:01 -0700 From: Vu Pham User-Agent: Thunderbird 2.0.0.23 (X11/20090812) MIME-Version: 1.0 To: Roland Dreier CC: Oren Duer , Linux RDMA , OpenFabrics EWG Subject: [PATCH 02/10] api to query mlx4_en device for given mlx4 device X-OriginalArrivalTime: 06 Aug 2010 22:54:17.0531 (UTC) FILETIME=[4C9678B0:01CB35BA] X-Spam: [F=0.2000000000; CM=0.500; S=0.200(2010073001)] X-MAIL-FROM: X-SOURCE-IP: [63.251.237.3] X-AnalysisOut: [v=1.0 c=1 a=gN3pC--7Pi4A:10 a=VphdPIyG4kEA:10 a=xupnbh4h0Y] X-AnalysisOut: [LOHZnncC45HQ==:17 a=SeBm4QpjAAAA:8 a=SVFCCoEm53K0Q8al0SMA:] X-AnalysisOut: [9 a=LWO2U9FHxvlFsFLu1o0CTr12Y5EA:4 a=wPNLvfGTeEIA:10 a=T2c] X-AnalysisOut: [JKXzbRCYA:10 a=nS1d9FodoZi8Ht-aXW8A:9 a=MOydnZlHLN_uEGQ4Nk] X-AnalysisOut: [EA:7 a=GyOR5mCaOhF59aNfHF41Aj9BXYQA:4] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 06 Aug 2010 22:57:22 +0000 (UTC) mlx4: Add API to query interfaces for given internal device Updated mlx4_en interface to provide a query function for it's internal net_device structure. Signed-off-by: Oren Duer Signed-off-by: Vu Pham drivers/net/mlx4/en_main.c | 14 ++++++++++++++ drivers/net/mlx4/intf.c | 30 ++++++++++++++++++++++++++++++ include/linux/mlx4/driver.h | 7 +++++++ 3 files changed, 51 insertions(+), 0 deletions(-) diff --git a/drivers/net/mlx4/en_main.c b/drivers/net/mlx4/en_main.c index cbabf14..6fce433 100644 --- a/drivers/net/mlx4/en_main.c +++ b/drivers/net/mlx4/en_main.c @@ -262,10 +262,24 @@ err_free_res: return NULL; } +enum mlx4_query_reply mlx4_en_query(void *endev_ptr, void *int_dev) +{ + struct mlx4_en_dev *mdev = endev_ptr; + struct net_device *netdev = int_dev; + int p; + + for (p = 1; p <= MLX4_MAX_PORTS; ++p) + if (mdev->pndev[p] == netdev) + return p; + + return MLX4_QUERY_NOT_MINE; +} + static struct mlx4_interface mlx4_en_interface = { .add = mlx4_en_add, .remove = mlx4_en_remove, .event = mlx4_en_event, + .query = mlx4_en_query }; static int __init mlx4_en_init(void) diff --git a/drivers/net/mlx4/intf.c b/drivers/net/mlx4/intf.c index 5550678..beeed80 100644 --- a/drivers/net/mlx4/intf.c +++ b/drivers/net/mlx4/intf.c @@ -114,6 +114,36 @@ void mlx4_unregister_interface(struct mlx4_interface *intf) } EXPORT_SYMBOL_GPL(mlx4_unregister_interface); +struct mlx4_dev *mlx4_query_interface(void *int_dev, int *port) +{ + struct mlx4_priv *priv; + struct mlx4_device_context *dev_ctx; + enum mlx4_query_reply r; + unsigned long flags; + + mutex_lock(&intf_mutex); + + list_for_each_entry(priv, &dev_list, dev_list) { + spin_lock_irqsave(&priv->ctx_lock, flags); + list_for_each_entry(dev_ctx, &priv->ctx_list, list) { + if (!dev_ctx->intf->query) + continue; + r = dev_ctx->intf->query(dev_ctx->context, int_dev); + if (r != MLX4_QUERY_NOT_MINE) { + *port = r; + spin_unlock_irqrestore(&priv->ctx_lock, flags); + mutex_unlock(&intf_mutex); + return &priv->dev; + } + } + spin_unlock_irqrestore(&priv->ctx_lock, flags); + } + + mutex_unlock(&intf_mutex); + return NULL; +} +EXPORT_SYMBOL_GPL(mlx4_query_interface); + void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type, int port) { struct mlx4_priv *priv = mlx4_priv(dev); diff --git a/include/linux/mlx4/driver.h b/include/linux/mlx4/driver.h index 53c5fdb..55b45a6 100644 --- a/include/linux/mlx4/driver.h +++ b/include/linux/mlx4/driver.h @@ -44,15 +44,22 @@ enum mlx4_dev_event { MLX4_DEV_EVENT_PORT_REINIT, }; +enum mlx4_query_reply { + MLX4_QUERY_NOT_MINE = -1, + MLX4_QUERY_MINE_NOPORT = 0 +}; + struct mlx4_interface { void * (*add) (struct mlx4_dev *dev); void (*remove)(struct mlx4_dev *dev, void *context); void (*event) (struct mlx4_dev *dev, void *context, enum mlx4_dev_event event, int port); + enum mlx4_query_reply (*query) (void *context, void *); struct list_head list; }; int mlx4_register_interface(struct mlx4_interface *intf); void mlx4_unregister_interface(struct mlx4_interface *intf); +struct mlx4_dev *mlx4_query_interface(void *, int *port); #endif /* MLX4_DRIVER_H */