@@ -292,10 +292,13 @@ static void bnxt_re_vf_res_config(struct bnxt_re_dev *rdev)
292
292
293
293
static void bnxt_re_shutdown (struct auxiliary_device * adev )
294
294
{
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 ;
296
297
297
- if (!rdev )
298
+ if (!en_info )
298
299
return ;
300
+
301
+ rdev = en_info -> rdev ;
299
302
ib_unregister_device (& rdev -> ibdev );
300
303
bnxt_re_dev_uninit (rdev );
301
304
}
@@ -1794,14 +1797,33 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev)
1794
1797
return rc ;
1795
1798
}
1796
1799
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
+
1797
1815
static int bnxt_re_add_device (struct auxiliary_device * adev )
1798
1816
{
1799
1817
struct bnxt_aux_priv * aux_priv =
1800
1818
container_of (adev , struct bnxt_aux_priv , aux_dev );
1819
+ struct bnxt_re_en_dev_info * en_info ;
1801
1820
struct bnxt_en_dev * en_dev ;
1802
1821
struct bnxt_re_dev * rdev ;
1803
1822
int rc ;
1804
1823
1824
+ en_info = auxiliary_get_drvdata (adev );
1825
+ en_dev = en_info -> en_dev ;
1826
+
1805
1827
/* en_dev should never be NULL as long as adev and aux_dev are valid. */
1806
1828
en_dev = aux_priv -> edev ;
1807
1829
@@ -1811,6 +1833,8 @@ static int bnxt_re_add_device(struct auxiliary_device *adev)
1811
1833
goto exit ;
1812
1834
}
1813
1835
1836
+ bnxt_re_update_en_info_rdev (rdev , en_info , adev );
1837
+
1814
1838
rc = bnxt_re_dev_init (rdev );
1815
1839
if (rc )
1816
1840
goto re_dev_dealloc ;
@@ -1821,11 +1845,11 @@ static int bnxt_re_add_device(struct auxiliary_device *adev)
1821
1845
aux_priv -> aux_dev .name );
1822
1846
goto re_dev_uninit ;
1823
1847
}
1824
- auxiliary_set_drvdata (adev , rdev );
1825
1848
1826
1849
return 0 ;
1827
1850
1828
1851
re_dev_uninit :
1852
+ bnxt_re_update_en_info_rdev (NULL , en_info , adev );
1829
1853
bnxt_re_dev_uninit (rdev );
1830
1854
re_dev_dealloc :
1831
1855
ib_dealloc_device (& rdev -> ibdev );
@@ -1911,12 +1935,18 @@ static int bnxt_re_netdev_event(struct notifier_block *notifier,
1911
1935
1912
1936
static void bnxt_re_remove (struct auxiliary_device * adev )
1913
1937
{
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 ;
1915
1940
1916
- if (!rdev )
1941
+ mutex_lock (& bnxt_re_mutex );
1942
+ if (!en_info ) {
1943
+ mutex_unlock (& bnxt_re_mutex );
1917
1944
return ;
1945
+ }
1946
+ rdev = en_info -> rdev ;
1947
+ if (!rdev )
1948
+ goto skip_remove ;
1918
1949
1919
- mutex_lock (& bnxt_re_mutex );
1920
1950
if (rdev -> nb .notifier_call ) {
1921
1951
unregister_netdevice_notifier (& rdev -> nb );
1922
1952
rdev -> nb .notifier_call = NULL ;
@@ -1931,24 +1961,39 @@ static void bnxt_re_remove(struct auxiliary_device *adev)
1931
1961
bnxt_re_dev_uninit (rdev );
1932
1962
ib_dealloc_device (& rdev -> ibdev );
1933
1963
skip_remove :
1964
+ kfree (en_info );
1934
1965
mutex_unlock (& bnxt_re_mutex );
1935
1966
}
1936
1967
1937
1968
static int bnxt_re_probe (struct auxiliary_device * adev ,
1938
1969
const struct auxiliary_device_id * id )
1939
1970
{
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 ;
1940
1975
struct bnxt_re_dev * rdev ;
1941
1976
int rc ;
1942
1977
1978
+ en_dev = aux_priv -> edev ;
1979
+
1943
1980
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 );
1944
1989
1945
1990
rc = bnxt_re_add_device (adev );
1946
1991
if (rc ) {
1947
1992
mutex_unlock (& bnxt_re_mutex );
1948
1993
return rc ;
1949
1994
}
1950
1995
1951
- rdev = auxiliary_get_drvdata ( adev ) ;
1996
+ rdev = en_info -> rdev ;
1952
1997
1953
1998
rdev -> nb .notifier_call = bnxt_re_netdev_event ;
1954
1999
rc = register_netdevice_notifier (& rdev -> nb );
@@ -1972,11 +2017,13 @@ static int bnxt_re_probe(struct auxiliary_device *adev,
1972
2017
1973
2018
static int bnxt_re_suspend (struct auxiliary_device * adev , pm_message_t state )
1974
2019
{
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 ;
1976
2022
1977
- if (!rdev )
2023
+ if (!en_info )
1978
2024
return 0 ;
1979
2025
2026
+ rdev = en_info -> rdev ;
1980
2027
mutex_lock (& bnxt_re_mutex );
1981
2028
/* L2 driver may invoke this callback during device error/crash or device
1982
2029
* 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)
2009
2056
2010
2057
static int bnxt_re_resume (struct auxiliary_device * adev )
2011
2058
{
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 ;
2013
2061
2014
- if (!rdev )
2062
+ if (!en_info )
2015
2063
return 0 ;
2016
2064
2065
+ rdev = en_info -> rdev ;
2017
2066
mutex_lock (& bnxt_re_mutex );
2018
2067
/* L2 driver may invoke this callback during device recovery, resume.
2019
2068
* reset. Current RoCE driver doesn't recover the device in case of
0 commit comments