.. | .. |
---|
3 | 3 | |
---|
4 | 4 | #include <linux/mlx5/vport.h> |
---|
5 | 5 | #include "lib/devcom.h" |
---|
| 6 | +#include "mlx5_core.h" |
---|
6 | 7 | |
---|
7 | 8 | static LIST_HEAD(devcom_list); |
---|
8 | 9 | |
---|
.. | .. |
---|
14 | 15 | struct mlx5_devcom_component { |
---|
15 | 16 | struct { |
---|
16 | 17 | void *data; |
---|
17 | | - } device[MLX5_MAX_PORTS]; |
---|
| 18 | + } device[MLX5_DEVCOM_PORTS_SUPPORTED]; |
---|
18 | 19 | |
---|
19 | 20 | mlx5_devcom_event_handler_t handler; |
---|
20 | 21 | struct rw_semaphore sem; |
---|
.. | .. |
---|
25 | 26 | struct list_head list; |
---|
26 | 27 | |
---|
27 | 28 | 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]; |
---|
29 | 30 | }; |
---|
30 | 31 | |
---|
31 | 32 | struct mlx5_devcom { |
---|
.. | .. |
---|
74 | 75 | |
---|
75 | 76 | if (!mlx5_core_is_pf(dev)) |
---|
76 | 77 | return NULL; |
---|
| 78 | + if (MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_DEVCOM_PORTS_SUPPORTED) |
---|
| 79 | + return NULL; |
---|
77 | 80 | |
---|
| 81 | + mlx5_dev_list_lock(); |
---|
78 | 82 | sguid0 = mlx5_query_nic_system_image_guid(dev); |
---|
79 | 83 | list_for_each_entry(iter, &devcom_list, list) { |
---|
80 | 84 | struct mlx5_core_dev *tmp_dev = NULL; |
---|
81 | 85 | |
---|
82 | 86 | idx = -1; |
---|
83 | | - for (i = 0; i < MLX5_MAX_PORTS; i++) { |
---|
| 87 | + for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++) { |
---|
84 | 88 | if (iter->devs[i]) |
---|
85 | 89 | tmp_dev = iter->devs[i]; |
---|
86 | 90 | else |
---|
.. | .. |
---|
100 | 104 | |
---|
101 | 105 | if (!priv) { |
---|
102 | 106 | 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 | + } |
---|
105 | 111 | |
---|
106 | 112 | idx = 0; |
---|
107 | 113 | new_priv = true; |
---|
.. | .. |
---|
110 | 116 | priv->devs[idx] = dev; |
---|
111 | 117 | devcom = mlx5_devcom_alloc(priv, idx); |
---|
112 | 118 | 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; |
---|
115 | 123 | } |
---|
116 | 124 | |
---|
117 | 125 | if (new_priv) |
---|
118 | 126 | list_add(&priv->list, &devcom_list); |
---|
119 | | - |
---|
| 127 | +out: |
---|
| 128 | + mlx5_dev_list_unlock(); |
---|
120 | 129 | return devcom; |
---|
121 | 130 | } |
---|
122 | 131 | |
---|
.. | .. |
---|
129 | 138 | if (IS_ERR_OR_NULL(devcom)) |
---|
130 | 139 | return; |
---|
131 | 140 | |
---|
| 141 | + mlx5_dev_list_lock(); |
---|
132 | 142 | priv = devcom->priv; |
---|
133 | 143 | priv->devs[devcom->idx] = NULL; |
---|
134 | 144 | |
---|
135 | 145 | kfree(devcom); |
---|
136 | 146 | |
---|
137 | | - for (i = 0; i < MLX5_MAX_PORTS; i++) |
---|
| 147 | + for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++) |
---|
138 | 148 | if (priv->devs[i]) |
---|
139 | 149 | break; |
---|
140 | 150 | |
---|
141 | | - if (i != MLX5_MAX_PORTS) |
---|
142 | | - return; |
---|
| 151 | + if (i != MLX5_DEVCOM_PORTS_SUPPORTED) |
---|
| 152 | + goto out; |
---|
143 | 153 | |
---|
144 | 154 | list_del(&priv->list); |
---|
145 | 155 | kfree(priv); |
---|
| 156 | +out: |
---|
| 157 | + mlx5_dev_list_unlock(); |
---|
146 | 158 | } |
---|
147 | 159 | |
---|
148 | 160 | void mlx5_devcom_register_component(struct mlx5_devcom *devcom, |
---|
.. | .. |
---|
191 | 203 | |
---|
192 | 204 | comp = &devcom->priv->components[id]; |
---|
193 | 205 | down_write(&comp->sem); |
---|
194 | | - for (i = 0; i < MLX5_MAX_PORTS; i++) |
---|
| 206 | + for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++) |
---|
195 | 207 | if (i != devcom->idx && comp->device[i].data) { |
---|
196 | 208 | err = comp->handler(event, comp->device[i].data, |
---|
197 | 209 | event_data); |
---|
.. | .. |
---|
239 | 251 | return NULL; |
---|
240 | 252 | } |
---|
241 | 253 | |
---|
242 | | - for (i = 0; i < MLX5_MAX_PORTS; i++) |
---|
| 254 | + for (i = 0; i < MLX5_DEVCOM_PORTS_SUPPORTED; i++) |
---|
243 | 255 | if (i != devcom->idx) |
---|
244 | 256 | break; |
---|
245 | 257 | |
---|