Skip to content

Commit dee3da3

Browse files
chandramohan-akularleon
authored andcommitted
RDMA/bnxt_re: Change aux driver data to en_info to hold more information
rdev will be destroyed and recreated during the FW error recovery scenarios. So to keep the state, if any, use an en_info structure which gets created/freed based on auxiliary device initialization/de-initialization. Signed-off-by: Chandramohan Akula <[email protected]> Reviewed-by: Kashyap Desai <[email protected]> Reviewed-by: Kalesh AP <[email protected]> Signed-off-by: Selvin Xavier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 12fb115 commit dee3da3

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed

drivers/infiniband/hw/bnxt_re/bnxt_re.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ struct bnxt_re_gsi_context {
107107
struct bnxt_re_sqp_entries *sqp_tbl;
108108
};
109109

110+
struct bnxt_re_en_dev_info {
111+
struct bnxt_en_dev *en_dev;
112+
struct bnxt_re_dev *rdev;
113+
};
114+
110115
#define BNXT_RE_AEQ_IDX 0
111116
#define BNXT_RE_NQ_IDX 1
112117
#define BNXT_RE_GEN_P5_MAX_VF 64
@@ -155,6 +160,7 @@ struct bnxt_re_dev {
155160
#define BNXT_RE_FLAG_ERR_DEVICE_DETACHED 17
156161
#define BNXT_RE_FLAG_ISSUE_ROCE_STATS 29
157162
struct net_device *netdev;
163+
struct auxiliary_device *adev;
158164
struct notifier_block nb;
159165
unsigned int version, major, minor;
160166
struct bnxt_qplib_chip_ctx *chip_ctx;

drivers/infiniband/hw/bnxt_re/main.c

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,13 @@ static void bnxt_re_vf_res_config(struct bnxt_re_dev *rdev)
292292

293293
static void bnxt_re_shutdown(struct auxiliary_device *adev)
294294
{
295-
struct bnxt_re_dev *rdev = auxiliary_get_drvdata(adev);
295+
struct bnxt_re_en_dev_info *en_info = auxiliary_get_drvdata(adev);
296+
struct bnxt_re_dev *rdev;
296297

297-
if (!rdev)
298+
if (!en_info)
298299
return;
300+
301+
rdev = en_info->rdev;
299302
ib_unregister_device(&rdev->ibdev);
300303
bnxt_re_dev_uninit(rdev);
301304
}
@@ -1794,14 +1797,33 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev)
17941797
return rc;
17951798
}
17961799

1800+
static void bnxt_re_update_en_info_rdev(struct bnxt_re_dev *rdev,
1801+
struct bnxt_re_en_dev_info *en_info,
1802+
struct auxiliary_device *adev)
1803+
{
1804+
/* Before updating the rdev pointer in bnxt_re_en_dev_info structure,
1805+
* take the rtnl lock to avoid accessing invalid rdev pointer from
1806+
* L2 ULP callbacks. This is applicable in all the places where rdev
1807+
* pointer is updated in bnxt_re_en_dev_info.
1808+
*/
1809+
rtnl_lock();
1810+
en_info->rdev = rdev;
1811+
rdev->adev = adev;
1812+
rtnl_unlock();
1813+
}
1814+
17971815
static int bnxt_re_add_device(struct auxiliary_device *adev)
17981816
{
17991817
struct bnxt_aux_priv *aux_priv =
18001818
container_of(adev, struct bnxt_aux_priv, aux_dev);
1819+
struct bnxt_re_en_dev_info *en_info;
18011820
struct bnxt_en_dev *en_dev;
18021821
struct bnxt_re_dev *rdev;
18031822
int rc;
18041823

1824+
en_info = auxiliary_get_drvdata(adev);
1825+
en_dev = en_info->en_dev;
1826+
18051827
/* en_dev should never be NULL as long as adev and aux_dev are valid. */
18061828
en_dev = aux_priv->edev;
18071829

@@ -1811,6 +1833,8 @@ static int bnxt_re_add_device(struct auxiliary_device *adev)
18111833
goto exit;
18121834
}
18131835

1836+
bnxt_re_update_en_info_rdev(rdev, en_info, adev);
1837+
18141838
rc = bnxt_re_dev_init(rdev);
18151839
if (rc)
18161840
goto re_dev_dealloc;
@@ -1821,11 +1845,11 @@ static int bnxt_re_add_device(struct auxiliary_device *adev)
18211845
aux_priv->aux_dev.name);
18221846
goto re_dev_uninit;
18231847
}
1824-
auxiliary_set_drvdata(adev, rdev);
18251848

18261849
return 0;
18271850

18281851
re_dev_uninit:
1852+
bnxt_re_update_en_info_rdev(NULL, en_info, adev);
18291853
bnxt_re_dev_uninit(rdev);
18301854
re_dev_dealloc:
18311855
ib_dealloc_device(&rdev->ibdev);
@@ -1911,12 +1935,18 @@ static int bnxt_re_netdev_event(struct notifier_block *notifier,
19111935

19121936
static void bnxt_re_remove(struct auxiliary_device *adev)
19131937
{
1914-
struct bnxt_re_dev *rdev = auxiliary_get_drvdata(adev);
1938+
struct bnxt_re_en_dev_info *en_info = auxiliary_get_drvdata(adev);
1939+
struct bnxt_re_dev *rdev;
19151940

1916-
if (!rdev)
1941+
mutex_lock(&bnxt_re_mutex);
1942+
if (!en_info) {
1943+
mutex_unlock(&bnxt_re_mutex);
19171944
return;
1945+
}
1946+
rdev = en_info->rdev;
1947+
if (!rdev)
1948+
goto skip_remove;
19181949

1919-
mutex_lock(&bnxt_re_mutex);
19201950
if (rdev->nb.notifier_call) {
19211951
unregister_netdevice_notifier(&rdev->nb);
19221952
rdev->nb.notifier_call = NULL;
@@ -1931,24 +1961,39 @@ static void bnxt_re_remove(struct auxiliary_device *adev)
19311961
bnxt_re_dev_uninit(rdev);
19321962
ib_dealloc_device(&rdev->ibdev);
19331963
skip_remove:
1964+
kfree(en_info);
19341965
mutex_unlock(&bnxt_re_mutex);
19351966
}
19361967

19371968
static int bnxt_re_probe(struct auxiliary_device *adev,
19381969
const struct auxiliary_device_id *id)
19391970
{
1971+
struct bnxt_aux_priv *aux_priv =
1972+
container_of(adev, struct bnxt_aux_priv, aux_dev);
1973+
struct bnxt_re_en_dev_info *en_info;
1974+
struct bnxt_en_dev *en_dev;
19401975
struct bnxt_re_dev *rdev;
19411976
int rc;
19421977

1978+
en_dev = aux_priv->edev;
1979+
19431980
mutex_lock(&bnxt_re_mutex);
1981+
en_info = kzalloc(sizeof(*en_info), GFP_KERNEL);
1982+
if (!en_info) {
1983+
mutex_unlock(&bnxt_re_mutex);
1984+
return -ENOMEM;
1985+
}
1986+
en_info->en_dev = en_dev;
1987+
1988+
auxiliary_set_drvdata(adev, en_info);
19441989

19451990
rc = bnxt_re_add_device(adev);
19461991
if (rc) {
19471992
mutex_unlock(&bnxt_re_mutex);
19481993
return rc;
19491994
}
19501995

1951-
rdev = auxiliary_get_drvdata(adev);
1996+
rdev = en_info->rdev;
19521997

19531998
rdev->nb.notifier_call = bnxt_re_netdev_event;
19541999
rc = register_netdevice_notifier(&rdev->nb);
@@ -1972,11 +2017,13 @@ static int bnxt_re_probe(struct auxiliary_device *adev,
19722017

19732018
static int bnxt_re_suspend(struct auxiliary_device *adev, pm_message_t state)
19742019
{
1975-
struct bnxt_re_dev *rdev = auxiliary_get_drvdata(adev);
2020+
struct bnxt_re_en_dev_info *en_info = auxiliary_get_drvdata(adev);
2021+
struct bnxt_re_dev *rdev;
19762022

1977-
if (!rdev)
2023+
if (!en_info)
19782024
return 0;
19792025

2026+
rdev = en_info->rdev;
19802027
mutex_lock(&bnxt_re_mutex);
19812028
/* L2 driver may invoke this callback during device error/crash or device
19822029
* reset. Current RoCE driver doesn't recover the device in case of
@@ -2009,11 +2056,13 @@ static int bnxt_re_suspend(struct auxiliary_device *adev, pm_message_t state)
20092056

20102057
static int bnxt_re_resume(struct auxiliary_device *adev)
20112058
{
2012-
struct bnxt_re_dev *rdev = auxiliary_get_drvdata(adev);
2059+
struct bnxt_re_en_dev_info *en_info = auxiliary_get_drvdata(adev);
2060+
struct bnxt_re_dev *rdev;
20132061

2014-
if (!rdev)
2062+
if (!en_info)
20152063
return 0;
20162064

2065+
rdev = en_info->rdev;
20172066
mutex_lock(&bnxt_re_mutex);
20182067
/* L2 driver may invoke this callback during device recovery, resume.
20192068
* reset. Current RoCE driver doesn't recover the device in case of

0 commit comments

Comments
 (0)