hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/net/ethernet/mellanox/mlx5/core/lib/devcom.c
....@@ -3,6 +3,7 @@
33
44 #include <linux/mlx5/vport.h>
55 #include "lib/devcom.h"
6
+#include "mlx5_core.h"
67
78 static LIST_HEAD(devcom_list);
89
....@@ -14,7 +15,7 @@
1415 struct mlx5_devcom_component {
1516 struct {
1617 void *data;
17
- } device[MLX5_MAX_PORTS];
18
+ } device[MLX5_DEVCOM_PORTS_SUPPORTED];
1819
1920 mlx5_devcom_event_handler_t handler;
2021 struct rw_semaphore sem;
....@@ -25,7 +26,7 @@
2526 struct list_head list;
2627
2728 struct mlx5_devcom_component components[MLX5_DEVCOM_NUM_COMPONENTS];
28
- struct mlx5_core_dev *devs[MLX5_MAX_PORTS];
29
+ struct mlx5_core_dev *devs[MLX5_DEVCOM_PORTS_SUPPORTED];
2930 };
3031
3132 struct mlx5_devcom {
....@@ -74,13 +75,16 @@
7475
7576 if (!mlx5_core_is_pf(dev))
7677 return NULL;
78
+ if (MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_DEVCOM_PORTS_SUPPORTED)
79
+ return NULL;
7780
81
+ mlx5_dev_list_lock();
7882 sguid0 = mlx5_query_nic_system_image_guid(dev);
7983 list_for_each_entry(iter, &devcom_list, list) {
8084 struct mlx5_core_dev *tmp_dev = NULL;
8185
8286 idx = -1;
83
- for (i = 0; i < MLX5_MAX_PORTS; i++) {
87
+ for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++) {
8488 if (iter->devs[i])
8589 tmp_dev = iter->devs[i];
8690 else
....@@ -100,8 +104,10 @@
100104
101105 if (!priv) {
102106 priv = mlx5_devcom_list_alloc();
103
- if (!priv)
104
- return ERR_PTR(-ENOMEM);
107
+ if (!priv) {
108
+ devcom = ERR_PTR(-ENOMEM);
109
+ goto out;
110
+ }
105111
106112 idx = 0;
107113 new_priv = true;
....@@ -110,13 +116,16 @@
110116 priv->devs[idx] = dev;
111117 devcom = mlx5_devcom_alloc(priv, idx);
112118 if (!devcom) {
113
- kfree(priv);
114
- return ERR_PTR(-ENOMEM);
119
+ if (new_priv)
120
+ kfree(priv);
121
+ devcom = ERR_PTR(-ENOMEM);
122
+ goto out;
115123 }
116124
117125 if (new_priv)
118126 list_add(&priv->list, &devcom_list);
119
-
127
+out:
128
+ mlx5_dev_list_unlock();
120129 return devcom;
121130 }
122131
....@@ -129,20 +138,23 @@
129138 if (IS_ERR_OR_NULL(devcom))
130139 return;
131140
141
+ mlx5_dev_list_lock();
132142 priv = devcom->priv;
133143 priv->devs[devcom->idx] = NULL;
134144
135145 kfree(devcom);
136146
137
- for (i = 0; i < MLX5_MAX_PORTS; i++)
147
+ for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++)
138148 if (priv->devs[i])
139149 break;
140150
141
- if (i != MLX5_MAX_PORTS)
142
- return;
151
+ if (i != MLX5_DEVCOM_PORTS_SUPPORTED)
152
+ goto out;
143153
144154 list_del(&priv->list);
145155 kfree(priv);
156
+out:
157
+ mlx5_dev_list_unlock();
146158 }
147159
148160 void mlx5_devcom_register_component(struct mlx5_devcom *devcom,
....@@ -191,7 +203,7 @@
191203
192204 comp = &devcom->priv->components[id];
193205 down_write(&comp->sem);
194
- for (i = 0; i < MLX5_MAX_PORTS; i++)
206
+ for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++)
195207 if (i != devcom->idx && comp->device[i].data) {
196208 err = comp->handler(event, comp->device[i].data,
197209 event_data);
....@@ -239,7 +251,7 @@
239251 return NULL;
240252 }
241253
242
- for (i = 0; i < MLX5_MAX_PORTS; i++)
254
+ for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++)
243255 if (i != devcom->idx)
244256 break;
245257