[ofa-general][PATCH 1/3] mlx4: Query internal device

oren at mellanox.co.il oren at mellanox.co.il
Mon Sep 22 07:33:44 PDT 2008


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 <oren at mellanox.co.il>

Index: ofed_kernel-2.6.18-EL5.1.orig/drivers/net/mlx4/en_main.c
===================================================================
--- ofed_kernel-2.6.18-EL5.1.orig.orig/drivers/net/mlx4/en_main.c	2008-09-04 14:45:56.000000000 +0300
+++ ofed_kernel-2.6.18-EL5.1.orig/drivers/net/mlx4/en_main.c	2008-09-04 14:46:17.440543000 +0300
@@ -234,10 +234,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
+	.event	= mlx4_en_event,
+	.query  = mlx4_en_query
 };
 
 static int __init mlx4_en_init(void)
Index: ofed_kernel-2.6.18-EL5.1.orig/drivers/net/mlx4/intf.c
===================================================================
--- ofed_kernel-2.6.18-EL5.1.orig.orig/drivers/net/mlx4/intf.c	2008-09-04 14:45:47.000000000 +0300
+++ ofed_kernel-2.6.18-EL5.1.orig/drivers/net/mlx4/intf.c	2008-09-04 14:46:02.196098000 +0300
@@ -112,6 +112,36 @@ void mlx4_unregister_interface(struct ml
 }
 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);
Index: ofed_kernel-2.6.18-EL5.1.orig/include/linux/mlx4/driver.h
===================================================================
--- ofed_kernel-2.6.18-EL5.1.orig.orig/include/linux/mlx4/driver.h	2008-09-04 14:45:47.000000000 +0300
+++ ofed_kernel-2.6.18-EL5.1.orig/include/linux/mlx4/driver.h	2008-09-04 14:46:02.201102000 +0300
@@ -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 */



More information about the general mailing list