Skip to content

Commit 5e12d08

Browse files
idoschdavem330
authored andcommittedNov 18, 2023
mlxsw: pci: Implement PCI reset handlers
Implement reset_prepare() and reset_done() handlers that are invoked by the PCI core before and after issuing a PCI reset, respectively. Specifically, implement reset_prepare() by calling mlxsw_core_bus_device_unregister() and reset_done() by calling mlxsw_core_bus_device_register(). This is the same implementation as the reload_{down,up}() devlink operations with the following differences: 1. The devlink instance is unregistered and then registered again after the reset. 2. A reset via the device's command interface (using MRSR register) is not issued during reset_done() as PCI core already issued a PCI reset. Tested: # for i in $(seq 1 10); do echo 1 > /sys/bus/pci/devices/0000\:01\:00.0/reset; done Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f257c73 commit 5e12d08

File tree

1 file changed

+28
-0
lines changed
  • drivers/net/ethernet/mellanox/mlxsw

1 file changed

+28
-0
lines changed
 

‎drivers/net/ethernet/mellanox/mlxsw/pci.c

+28
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct mlxsw_pci {
130130
const struct pci_device_id *id;
131131
enum mlxsw_pci_cqe_v max_cqe_ver; /* Maximal supported CQE version */
132132
u8 num_sdq_cqs; /* Number of CQs used for SDQs */
133+
bool skip_reset;
133134
};
134135

135136
static void mlxsw_pci_queue_tasklet_schedule(struct mlxsw_pci_queue *q)
@@ -1527,6 +1528,10 @@ mlxsw_pci_reset(struct mlxsw_pci *mlxsw_pci, const struct pci_device_id *id)
15271528
return err;
15281529
}
15291530

1531+
/* PCI core already issued a PCI reset, do not issue another reset. */
1532+
if (mlxsw_pci->skip_reset)
1533+
return 0;
1534+
15301535
mlxsw_reg_mcam_pack(mcam_pl,
15311536
MLXSW_REG_MCAM_FEATURE_GROUP_ENHANCED_FEATURES);
15321537
err = mlxsw_reg_query(mlxsw_pci->core, MLXSW_REG(mcam), mcam_pl);
@@ -2107,11 +2112,34 @@ static void mlxsw_pci_remove(struct pci_dev *pdev)
21072112
kfree(mlxsw_pci);
21082113
}
21092114

2115+
static void mlxsw_pci_reset_prepare(struct pci_dev *pdev)
2116+
{
2117+
struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev);
2118+
2119+
mlxsw_core_bus_device_unregister(mlxsw_pci->core, false);
2120+
}
2121+
2122+
static void mlxsw_pci_reset_done(struct pci_dev *pdev)
2123+
{
2124+
struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev);
2125+
2126+
mlxsw_pci->skip_reset = true;
2127+
mlxsw_core_bus_device_register(&mlxsw_pci->bus_info, &mlxsw_pci_bus,
2128+
mlxsw_pci, false, NULL, NULL);
2129+
mlxsw_pci->skip_reset = false;
2130+
}
2131+
2132+
static const struct pci_error_handlers mlxsw_pci_err_handler = {
2133+
.reset_prepare = mlxsw_pci_reset_prepare,
2134+
.reset_done = mlxsw_pci_reset_done,
2135+
};
2136+
21102137
int mlxsw_pci_driver_register(struct pci_driver *pci_driver)
21112138
{
21122139
pci_driver->probe = mlxsw_pci_probe;
21132140
pci_driver->remove = mlxsw_pci_remove;
21142141
pci_driver->shutdown = mlxsw_pci_remove;
2142+
pci_driver->err_handler = &mlxsw_pci_err_handler;
21152143
return pci_register_driver(pci_driver);
21162144
}
21172145
EXPORT_SYMBOL(mlxsw_pci_driver_register);

0 commit comments

Comments
 (0)
Please sign in to comment.