@@ -151,7 +151,6 @@ int (*flexport_phases[MAX_FLEX_PHASES]) (int unit, soc_port_schedule_state_t
151
151
NULL /* 24 */
152
152
};
153
153
154
-
155
154
/*! @fn void *soc_tomahawk_port_lane_info_alloc(void)
156
155
* @brief Allocates memory pointed to by soc_port_lane_info_t. Need this
157
156
* special function because SystemVerilog-C DPI limitations in
@@ -248,6 +247,20 @@ soc_tomahawk_reconfigure_ports (
248
247
)
249
248
{
250
249
int i , j , rv ;
250
+ static sal_mutex_t mtx = NULL ;
251
+
252
+ // Only runs once
253
+ // TODO: make init thread-safe
254
+ if (!mtx ) {
255
+ mtx = sal_mutex_create ("Tomahawk port reconfiguration mutex" );
256
+ }
257
+
258
+ if (sal_mutex_take (mtx , 1000 * 1000 /* us */ )) {
259
+ LOG_ERROR (BSL_LS_SOC_PORT ,
260
+ (BSL_META_U (unit , "Port reconfiguration mutex could not be"
261
+ " taken within timeout. Deadlock?\n" )));
262
+ return SOC_E_FAIL ;
263
+ }
251
264
252
265
if (LOG_CHECK (BSL_LS_SOC_PORT )) {
253
266
LOG_DEBUG (BSL_LS_SOC_PORT ,
@@ -303,13 +316,16 @@ soc_tomahawk_reconfigure_ports (
303
316
rv = flexport_phases [i ](unit , port_schedule_state );
304
317
if (rv != SOC_E_NONE ) {
305
318
sal_free (port_schedule_state -> cookie );
319
+ port_schedule_state -> cookie = NULL ;
306
320
LOG_DEBUG (BSL_LS_SOC_PORT , (BSL_META_U (unit ,
307
321
"Error encountered. Cookie space deallocated.\n" )));
322
+ sal_mutex_give (mtx );
308
323
return rv ;
309
324
}
310
325
}
311
326
}
312
327
328
+ sal_mutex_give (mtx );
313
329
return SOC_E_NONE ;
314
330
}
315
331
0 commit comments