Skip to content

Commit 4be4779

Browse files
vadimp-nvidiakuba-moo
authored andcommitted
mlxsw: core_linecards: Separate line card init and fini flow
Currently, each line card is initialized using the following steps: 1. Initializing its various fields (e.g., slot index). 2. Creating the corresponding devlink object. 3. Enabling events (i.e., traps) for changes in line card status. 4. Querying and processing line card status. Unlike traps, the IRQ that notifies the CPU about line card status changes cannot be enabled / disabled on a per line card basis. If a handler is registered before the line cards are initialized, the handler risks accessing uninitialized memory. On the other hand, if the handler is registered after initialization, we risk missing events. For example, in step 4, the driver might see that a line card is in ready state and will tell the device to enable it. When enablement is done, the line card will be activated and the IRQ will be triggered. Since a handler was not registered, the event will be missed. Solve this by splitting the initialization sequence into two steps (1-2 and 3-4). In a subsequent patch, the handler will be registered between both steps. Signed-off-by: Vadim Pasternak <vadimp@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 510156a commit 4be4779

File tree

1 file changed

+50
-21
lines changed

1 file changed

+50
-21
lines changed

drivers/net/ethernet/mellanox/mlxsw/core_linecards.c

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,6 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core,
12381238
{
12391239
struct devlink_linecard *devlink_linecard;
12401240
struct mlxsw_linecard *linecard;
1241-
int err;
12421241

12431242
linecard = mlxsw_linecard_get(linecards, slot_index);
12441243
linecard->slot_index = slot_index;
@@ -1248,17 +1247,45 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core,
12481247
devlink_linecard = devlink_linecard_create(priv_to_devlink(mlxsw_core),
12491248
slot_index, &mlxsw_linecard_ops,
12501249
linecard);
1251-
if (IS_ERR(devlink_linecard)) {
1252-
err = PTR_ERR(devlink_linecard);
1253-
goto err_devlink_linecard_create;
1254-
}
1250+
if (IS_ERR(devlink_linecard))
1251+
return PTR_ERR(devlink_linecard);
1252+
12551253
linecard->devlink_linecard = devlink_linecard;
12561254
INIT_DELAYED_WORK(&linecard->status_event_to_dw,
12571255
&mlxsw_linecard_status_event_to_work);
12581256

1257+
return 0;
1258+
}
1259+
1260+
static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core,
1261+
struct mlxsw_linecards *linecards,
1262+
u8 slot_index)
1263+
{
1264+
struct mlxsw_linecard *linecard;
1265+
1266+
linecard = mlxsw_linecard_get(linecards, slot_index);
1267+
cancel_delayed_work_sync(&linecard->status_event_to_dw);
1268+
/* Make sure all scheduled events are processed */
1269+
mlxsw_core_flush_owq();
1270+
if (linecard->active)
1271+
mlxsw_linecard_active_clear(linecard);
1272+
mlxsw_linecard_bdev_del(linecard);
1273+
devlink_linecard_destroy(linecard->devlink_linecard);
1274+
mutex_destroy(&linecard->lock);
1275+
}
1276+
1277+
static int
1278+
mlxsw_linecard_event_delivery_init(struct mlxsw_core *mlxsw_core,
1279+
struct mlxsw_linecards *linecards,
1280+
u8 slot_index)
1281+
{
1282+
struct mlxsw_linecard *linecard;
1283+
int err;
1284+
1285+
linecard = mlxsw_linecard_get(linecards, slot_index);
12591286
err = mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, true);
12601287
if (err)
1261-
goto err_event_delivery_set;
1288+
return err;
12621289

12631290
err = mlxsw_linecard_status_get_and_process(mlxsw_core, linecards,
12641291
linecard);
@@ -1269,29 +1296,18 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core,
12691296

12701297
err_status_get_and_process:
12711298
mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false);
1272-
err_event_delivery_set:
1273-
devlink_linecard_destroy(linecard->devlink_linecard);
1274-
err_devlink_linecard_create:
1275-
mutex_destroy(&linecard->lock);
12761299
return err;
12771300
}
12781301

1279-
static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core,
1280-
struct mlxsw_linecards *linecards,
1281-
u8 slot_index)
1302+
static void
1303+
mlxsw_linecard_event_delivery_fini(struct mlxsw_core *mlxsw_core,
1304+
struct mlxsw_linecards *linecards,
1305+
u8 slot_index)
12821306
{
12831307
struct mlxsw_linecard *linecard;
12841308

12851309
linecard = mlxsw_linecard_get(linecards, slot_index);
12861310
mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false);
1287-
cancel_delayed_work_sync(&linecard->status_event_to_dw);
1288-
/* Make sure all scheduled events are processed */
1289-
mlxsw_core_flush_owq();
1290-
if (linecard->active)
1291-
mlxsw_linecard_active_clear(linecard);
1292-
mlxsw_linecard_bdev_del(linecard);
1293-
devlink_linecard_destroy(linecard->devlink_linecard);
1294-
mutex_destroy(&linecard->lock);
12951311
}
12961312

12971313
/* LINECARDS INI BUNDLE FILE
@@ -1513,8 +1529,19 @@ int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core,
15131529
goto err_linecard_init;
15141530
}
15151531

1532+
for (i = 0; i < linecards->count; i++) {
1533+
err = mlxsw_linecard_event_delivery_init(mlxsw_core, linecards,
1534+
i + 1);
1535+
if (err)
1536+
goto err_linecard_event_delivery_init;
1537+
}
1538+
15161539
return 0;
15171540

1541+
err_linecard_event_delivery_init:
1542+
for (i--; i >= 0; i--)
1543+
mlxsw_linecard_event_delivery_fini(mlxsw_core, linecards, i + 1);
1544+
i = linecards->count;
15181545
err_linecard_init:
15191546
for (i--; i >= 0; i--)
15201547
mlxsw_linecard_fini(mlxsw_core, linecards, i + 1);
@@ -1535,6 +1562,8 @@ void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core)
15351562

15361563
if (!linecards)
15371564
return;
1565+
for (i = 0; i < linecards->count; i++)
1566+
mlxsw_linecard_event_delivery_fini(mlxsw_core, linecards, i + 1);
15381567
for (i = 0; i < linecards->count; i++)
15391568
mlxsw_linecard_fini(mlxsw_core, linecards, i + 1);
15401569
mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener,

0 commit comments

Comments
 (0)