Skip to content

Commit

Permalink
net/mlx5: devcom only supports 2 ports
Browse files Browse the repository at this point in the history
Devcom API is intended to be used between 2 devices only add this
implied assumption into the code and check when it's no true.

Signed-off-by: Mark Bloch <[email protected]>
Reviewed-by: Maor Gottlieb <[email protected]>
Signed-off-by: Saeed Mahameed <[email protected]>
  • Loading branch information
mark-bloch authored and Saeed Mahameed committed May 10, 2022
1 parent 34a30d7 commit 8a6e75e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 9 additions & 7 deletions drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static LIST_HEAD(devcom_list);
struct mlx5_devcom_component {
struct {
void *data;
} device[MLX5_MAX_PORTS];
} device[MLX5_DEVCOM_PORTS_SUPPORTED];

mlx5_devcom_event_handler_t handler;
struct rw_semaphore sem;
Expand All @@ -25,7 +25,7 @@ struct mlx5_devcom_list {
struct list_head list;

struct mlx5_devcom_component components[MLX5_DEVCOM_NUM_COMPONENTS];
struct mlx5_core_dev *devs[MLX5_MAX_PORTS];
struct mlx5_core_dev *devs[MLX5_DEVCOM_PORTS_SUPPORTED];
};

struct mlx5_devcom {
Expand Down Expand Up @@ -74,13 +74,15 @@ struct mlx5_devcom *mlx5_devcom_register_device(struct mlx5_core_dev *dev)

if (!mlx5_core_is_pf(dev))
return NULL;
if (MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_DEVCOM_PORTS_SUPPORTED)
return NULL;

sguid0 = mlx5_query_nic_system_image_guid(dev);
list_for_each_entry(iter, &devcom_list, list) {
struct mlx5_core_dev *tmp_dev = NULL;

idx = -1;
for (i = 0; i < MLX5_MAX_PORTS; i++) {
for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++) {
if (iter->devs[i])
tmp_dev = iter->devs[i];
else
Expand Down Expand Up @@ -134,11 +136,11 @@ void mlx5_devcom_unregister_device(struct mlx5_devcom *devcom)

kfree(devcom);

for (i = 0; i < MLX5_MAX_PORTS; i++)
for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++)
if (priv->devs[i])
break;

if (i != MLX5_MAX_PORTS)
if (i != MLX5_DEVCOM_PORTS_SUPPORTED)
return;

list_del(&priv->list);
Expand Down Expand Up @@ -191,7 +193,7 @@ int mlx5_devcom_send_event(struct mlx5_devcom *devcom,

comp = &devcom->priv->components[id];
down_write(&comp->sem);
for (i = 0; i < MLX5_MAX_PORTS; i++)
for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++)
if (i != devcom->idx && comp->device[i].data) {
err = comp->handler(event, comp->device[i].data,
event_data);
Expand Down Expand Up @@ -239,7 +241,7 @@ void *mlx5_devcom_get_peer_data(struct mlx5_devcom *devcom,
return NULL;
}

for (i = 0; i < MLX5_MAX_PORTS; i++)
for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++)
if (i != devcom->idx)
break;

Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <linux/mlx5/driver.h>

#define MLX5_DEVCOM_PORTS_SUPPORTED 2

enum mlx5_devcom_components {
MLX5_DEVCOM_ESW_OFFLOADS,

Expand Down

0 comments on commit 8a6e75e

Please sign in to comment.