1
1
/*
2
- * Copyright (c) 2013 Johannes Berg <[email protected] >
2
+ * Copyright (c) 2013, 2021 Johannes Berg <[email protected] >
3
3
*
4
4
* This file is free software: you may copy, redistribute and/or modify it
5
5
* under the terms of the GNU General Public License as published by the
@@ -1091,8 +1091,9 @@ static int alx_init_sw(struct alx_priv *alx)
1091
1091
ALX_MAC_CTRL_RXFC_EN |
1092
1092
ALX_MAC_CTRL_TXFC_EN |
1093
1093
7 << ALX_MAC_CTRL_PRMBLEN_SHIFT ;
1094
+ mutex_init (& alx -> mtx );
1094
1095
1095
- return err ;
1096
+ return 0 ;
1096
1097
}
1097
1098
1098
1099
@@ -1122,6 +1123,8 @@ static void alx_halt(struct alx_priv *alx)
1122
1123
{
1123
1124
struct alx_hw * hw = & alx -> hw ;
1124
1125
1126
+ lockdep_assert_held (& alx -> mtx );
1127
+
1125
1128
alx_netif_stop (alx );
1126
1129
hw -> link_speed = SPEED_UNKNOWN ;
1127
1130
hw -> duplex = DUPLEX_UNKNOWN ;
@@ -1147,6 +1150,8 @@ static void alx_configure(struct alx_priv *alx)
1147
1150
1148
1151
static void alx_activate (struct alx_priv * alx )
1149
1152
{
1153
+ lockdep_assert_held (& alx -> mtx );
1154
+
1150
1155
/* hardware setting lost, restore it */
1151
1156
alx_reinit_rings (alx );
1152
1157
alx_configure (alx );
@@ -1161,7 +1166,7 @@ static void alx_activate(struct alx_priv *alx)
1161
1166
1162
1167
static void alx_reinit (struct alx_priv * alx )
1163
1168
{
1164
- ASSERT_RTNL ( );
1169
+ lockdep_assert_held ( & alx -> mtx );
1165
1170
1166
1171
alx_halt (alx );
1167
1172
alx_activate (alx );
@@ -1249,6 +1254,8 @@ static int __alx_open(struct alx_priv *alx, bool resume)
1249
1254
1250
1255
static void __alx_stop (struct alx_priv * alx )
1251
1256
{
1257
+ lockdep_assert_held (& alx -> mtx );
1258
+
1252
1259
alx_free_irq (alx );
1253
1260
1254
1261
cancel_work_sync (& alx -> link_check_wk );
@@ -1284,6 +1291,8 @@ static void alx_check_link(struct alx_priv *alx)
1284
1291
int old_speed ;
1285
1292
int err ;
1286
1293
1294
+ lockdep_assert_held (& alx -> mtx );
1295
+
1287
1296
/* clear PHY internal interrupt status, otherwise the main
1288
1297
* interrupt status will be asserted forever
1289
1298
*/
@@ -1338,12 +1347,24 @@ static void alx_check_link(struct alx_priv *alx)
1338
1347
1339
1348
static int alx_open (struct net_device * netdev )
1340
1349
{
1341
- return __alx_open (netdev_priv (netdev ), false);
1350
+ struct alx_priv * alx = netdev_priv (netdev );
1351
+ int ret ;
1352
+
1353
+ mutex_lock (& alx -> mtx );
1354
+ ret = __alx_open (alx , false);
1355
+ mutex_unlock (& alx -> mtx );
1356
+
1357
+ return ret ;
1342
1358
}
1343
1359
1344
1360
static int alx_stop (struct net_device * netdev )
1345
1361
{
1346
- __alx_stop (netdev_priv (netdev ));
1362
+ struct alx_priv * alx = netdev_priv (netdev );
1363
+
1364
+ mutex_lock (& alx -> mtx );
1365
+ __alx_stop (alx );
1366
+ mutex_unlock (& alx -> mtx );
1367
+
1347
1368
return 0 ;
1348
1369
}
1349
1370
@@ -1353,18 +1374,18 @@ static void alx_link_check(struct work_struct *work)
1353
1374
1354
1375
alx = container_of (work , struct alx_priv , link_check_wk );
1355
1376
1356
- rtnl_lock ( );
1377
+ mutex_lock ( & alx -> mtx );
1357
1378
alx_check_link (alx );
1358
- rtnl_unlock ( );
1379
+ mutex_unlock ( & alx -> mtx );
1359
1380
}
1360
1381
1361
1382
static void alx_reset (struct work_struct * work )
1362
1383
{
1363
1384
struct alx_priv * alx = container_of (work , struct alx_priv , reset_wk );
1364
1385
1365
- rtnl_lock ( );
1386
+ mutex_lock ( & alx -> mtx );
1366
1387
alx_reinit (alx );
1367
- rtnl_unlock ( );
1388
+ mutex_unlock ( & alx -> mtx );
1368
1389
}
1369
1390
1370
1391
static int alx_tpd_req (struct sk_buff * skb )
@@ -1771,6 +1792,8 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1771
1792
goto out_unmap ;
1772
1793
}
1773
1794
1795
+ mutex_lock (& alx -> mtx );
1796
+
1774
1797
alx_reset_pcie (hw );
1775
1798
1776
1799
phy_configured = alx_phy_configured (hw );
@@ -1781,7 +1804,7 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1781
1804
err = alx_reset_mac (hw );
1782
1805
if (err ) {
1783
1806
dev_err (& pdev -> dev , "MAC Reset failed, error = %d\n" , err );
1784
- goto out_unmap ;
1807
+ goto out_unlock ;
1785
1808
}
1786
1809
1787
1810
/* setup link to put it in a known good starting state */
@@ -1791,7 +1814,7 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1791
1814
dev_err (& pdev -> dev ,
1792
1815
"failed to configure PHY speed/duplex (err=%d)\n" ,
1793
1816
err );
1794
- goto out_unmap ;
1817
+ goto out_unlock ;
1795
1818
}
1796
1819
}
1797
1820
@@ -1824,17 +1847,19 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1824
1847
if (!alx_get_phy_info (hw )) {
1825
1848
dev_err (& pdev -> dev , "failed to identify PHY\n" );
1826
1849
err = - EIO ;
1827
- goto out_unmap ;
1850
+ goto out_unlock ;
1828
1851
}
1829
1852
1853
+ mutex_unlock (& alx -> mtx );
1854
+
1830
1855
INIT_WORK (& alx -> link_check_wk , alx_link_check );
1831
1856
INIT_WORK (& alx -> reset_wk , alx_reset );
1832
1857
netif_carrier_off (netdev );
1833
1858
1834
1859
err = register_netdev (netdev );
1835
1860
if (err ) {
1836
1861
dev_err (& pdev -> dev , "register netdevice failed\n" );
1837
- goto out_unmap ;
1862
+ goto out_unlock ;
1838
1863
}
1839
1864
1840
1865
netdev_info (netdev ,
@@ -1843,6 +1868,8 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1843
1868
1844
1869
return 0 ;
1845
1870
1871
+ out_unlock :
1872
+ mutex_unlock (& alx -> mtx );
1846
1873
out_unmap :
1847
1874
iounmap (hw -> hw_addr );
1848
1875
out_free_netdev :
@@ -1869,6 +1896,8 @@ static void alx_remove(struct pci_dev *pdev)
1869
1896
pci_disable_pcie_error_reporting (pdev );
1870
1897
pci_disable_device (pdev );
1871
1898
1899
+ mutex_destroy (& alx -> mtx );
1900
+
1872
1901
free_netdev (alx -> dev );
1873
1902
}
1874
1903
@@ -1880,7 +1909,11 @@ static int alx_suspend(struct device *dev)
1880
1909
if (!netif_running (alx -> dev ))
1881
1910
return 0 ;
1882
1911
netif_device_detach (alx -> dev );
1912
+
1913
+ mutex_lock (& alx -> mtx );
1883
1914
__alx_stop (alx );
1915
+ mutex_unlock (& alx -> mtx );
1916
+
1884
1917
return 0 ;
1885
1918
}
1886
1919
@@ -1890,20 +1923,23 @@ static int alx_resume(struct device *dev)
1890
1923
struct alx_hw * hw = & alx -> hw ;
1891
1924
int err ;
1892
1925
1926
+ mutex_lock (& alx -> mtx );
1893
1927
alx_reset_phy (hw );
1894
1928
1895
- if (!netif_running (alx -> dev ))
1896
- return 0 ;
1929
+ if (!netif_running (alx -> dev )) {
1930
+ err = 0 ;
1931
+ goto unlock ;
1932
+ }
1897
1933
1898
- rtnl_lock ();
1899
1934
err = __alx_open (alx , true);
1900
- rtnl_unlock ();
1901
1935
if (err )
1902
- return err ;
1936
+ goto unlock ;
1903
1937
1904
1938
netif_device_attach (alx -> dev );
1905
1939
1906
- return 0 ;
1940
+ unlock :
1941
+ mutex_unlock (& alx -> mtx );
1942
+ return err ;
1907
1943
}
1908
1944
1909
1945
static SIMPLE_DEV_PM_OPS (alx_pm_ops , alx_suspend , alx_resume ) ;
@@ -1922,7 +1958,7 @@ static pci_ers_result_t alx_pci_error_detected(struct pci_dev *pdev,
1922
1958
1923
1959
dev_info (& pdev -> dev , "pci error detected\n" );
1924
1960
1925
- rtnl_lock ( );
1961
+ mutex_lock ( & alx -> mtx );
1926
1962
1927
1963
if (netif_running (netdev )) {
1928
1964
netif_device_detach (netdev );
@@ -1934,7 +1970,7 @@ static pci_ers_result_t alx_pci_error_detected(struct pci_dev *pdev,
1934
1970
else
1935
1971
pci_disable_device (pdev );
1936
1972
1937
- rtnl_unlock ( );
1973
+ mutex_unlock ( & alx -> mtx );
1938
1974
1939
1975
return rc ;
1940
1976
}
@@ -1947,7 +1983,7 @@ static pci_ers_result_t alx_pci_error_slot_reset(struct pci_dev *pdev)
1947
1983
1948
1984
dev_info (& pdev -> dev , "pci error slot reset\n" );
1949
1985
1950
- rtnl_lock ( );
1986
+ mutex_lock ( & alx -> mtx );
1951
1987
1952
1988
if (pci_enable_device (pdev )) {
1953
1989
dev_err (& pdev -> dev , "Failed to re-enable PCI device after reset\n" );
@@ -1960,7 +1996,7 @@ static pci_ers_result_t alx_pci_error_slot_reset(struct pci_dev *pdev)
1960
1996
if (!alx_reset_mac (hw ))
1961
1997
rc = PCI_ERS_RESULT_RECOVERED ;
1962
1998
out :
1963
- rtnl_unlock ( );
1999
+ mutex_unlock ( & alx -> mtx );
1964
2000
1965
2001
return rc ;
1966
2002
}
@@ -1972,14 +2008,14 @@ static void alx_pci_error_resume(struct pci_dev *pdev)
1972
2008
1973
2009
dev_info (& pdev -> dev , "pci error resume\n" );
1974
2010
1975
- rtnl_lock ( );
2011
+ mutex_lock ( & alx -> mtx );
1976
2012
1977
2013
if (netif_running (netdev )) {
1978
2014
alx_activate (alx );
1979
2015
netif_device_attach (netdev );
1980
2016
}
1981
2017
1982
- rtnl_unlock ( );
2018
+ mutex_unlock ( & alx -> mtx );
1983
2019
}
1984
2020
1985
2021
static const struct pci_error_handlers alx_err_handlers = {
0 commit comments