Skip to content

Commit 33c87f0

Browse files
Eli CohenRoland Dreier
authored andcommitted
mlx4_core: Allow protocol drivers to find corresponding interfaces
Add a mechanism for mlx4 protocol drivers to get a pointer to other drivers's device objects. For this, an exported function, mlx4_get_protocol_dev() is added, which allows a driver to get some other driver's device based on the protocol that the driver implements. Two protocols are added: MLX4_PROTOCOL_IB and MLX4_PROTOCOL_EN. This will be used in mlx4 IBoE support so that mlx4_ib can find the corresponding mlx4_en netdev. Signed-off-by: Eli Cohen <eli@mellanox.co.il> [ Clean up and rename a few things. - Roland ] Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent 2420b60 commit 33c87f0

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

‎drivers/net/mlx4/en_main.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ static int mlx4_en_get_profile(struct mlx4_en_dev *mdev)
124124
return 0;
125125
}
126126

127+
static void *mlx4_en_get_netdev(struct mlx4_dev *dev, void *ctx, u8 port)
128+
{
129+
struct mlx4_en_dev *endev = ctx;
130+
131+
return endev->pndev[port];
132+
}
133+
127134
static void mlx4_en_event(struct mlx4_dev *dev, void *endev_ptr,
128135
enum mlx4_dev_event event, int port)
129136
{
@@ -282,9 +289,11 @@ static void *mlx4_en_add(struct mlx4_dev *dev)
282289
}
283290

284291
static struct mlx4_interface mlx4_en_interface = {
285-
.add = mlx4_en_add,
286-
.remove = mlx4_en_remove,
287-
.event = mlx4_en_event,
292+
.add = mlx4_en_add,
293+
.remove = mlx4_en_remove,
294+
.event = mlx4_en_event,
295+
.get_dev = mlx4_en_get_netdev,
296+
.protocol = MLX4_PROTOCOL_EN,
288297
};
289298

290299
static int __init mlx4_en_init(void)

‎drivers/net/mlx4/intf.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,24 @@ void mlx4_unregister_device(struct mlx4_dev *dev)
161161

162162
mutex_unlock(&intf_mutex);
163163
}
164+
165+
void *mlx4_get_protocol_dev(struct mlx4_dev *dev, enum mlx4_protocol proto, int port)
166+
{
167+
struct mlx4_priv *priv = mlx4_priv(dev);
168+
struct mlx4_device_context *dev_ctx;
169+
unsigned long flags;
170+
void *result = NULL;
171+
172+
spin_lock_irqsave(&priv->ctx_lock, flags);
173+
174+
list_for_each_entry(dev_ctx, &priv->ctx_list, list)
175+
if (dev_ctx->intf->protocol == proto && dev_ctx->intf->get_dev) {
176+
result = dev_ctx->intf->get_dev(dev, dev_ctx->context, port);
177+
break;
178+
}
179+
180+
spin_unlock_irqrestore(&priv->ctx_lock, flags);
181+
182+
return result;
183+
}
184+
EXPORT_SYMBOL_GPL(mlx4_get_protocol_dev);

‎include/linux/mlx4/driver.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,24 @@ enum mlx4_dev_event {
4444
MLX4_DEV_EVENT_PORT_REINIT,
4545
};
4646

47+
enum mlx4_protocol {
48+
MLX4_PROTOCOL_IB,
49+
MLX4_PROTOCOL_EN,
50+
};
51+
4752
struct mlx4_interface {
4853
void * (*add) (struct mlx4_dev *dev);
4954
void (*remove)(struct mlx4_dev *dev, void *context);
5055
void (*event) (struct mlx4_dev *dev, void *context,
5156
enum mlx4_dev_event event, int port);
57+
void * (*get_dev)(struct mlx4_dev *dev, void *context, u8 port);
5258
struct list_head list;
59+
enum mlx4_protocol protocol;
5360
};
5461

5562
int mlx4_register_interface(struct mlx4_interface *intf);
5663
void mlx4_unregister_interface(struct mlx4_interface *intf);
5764

65+
void *mlx4_get_protocol_dev(struct mlx4_dev *dev, enum mlx4_protocol proto, int port);
66+
5867
#endif /* MLX4_DRIVER_H */

0 commit comments

Comments
 (0)