@@ -1414,23 +1414,12 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
1414
1414
u16 num_pages ;
1415
1415
int err ;
1416
1416
1417
- mutex_init (& mlxsw_pci -> cmd .lock );
1418
- init_waitqueue_head (& mlxsw_pci -> cmd .wait );
1419
-
1420
1417
mlxsw_pci -> core = mlxsw_core ;
1421
1418
1422
1419
mbox = mlxsw_cmd_mbox_alloc ();
1423
1420
if (!mbox )
1424
1421
return - ENOMEM ;
1425
1422
1426
- err = mlxsw_pci_mbox_alloc (mlxsw_pci , & mlxsw_pci -> cmd .in_mbox );
1427
- if (err )
1428
- goto mbox_put ;
1429
-
1430
- err = mlxsw_pci_mbox_alloc (mlxsw_pci , & mlxsw_pci -> cmd .out_mbox );
1431
- if (err )
1432
- goto err_out_mbox_alloc ;
1433
-
1434
1423
err = mlxsw_pci_sw_reset (mlxsw_pci , mlxsw_pci -> id );
1435
1424
if (err )
1436
1425
goto err_sw_reset ;
@@ -1537,9 +1526,6 @@ static int mlxsw_pci_init(void *bus_priv, struct mlxsw_core *mlxsw_core,
1537
1526
mlxsw_pci_free_irq_vectors (mlxsw_pci );
1538
1527
err_alloc_irq :
1539
1528
err_sw_reset :
1540
- mlxsw_pci_mbox_free (mlxsw_pci , & mlxsw_pci -> cmd .out_mbox );
1541
- err_out_mbox_alloc :
1542
- mlxsw_pci_mbox_free (mlxsw_pci , & mlxsw_pci -> cmd .in_mbox );
1543
1529
mbox_put :
1544
1530
mlxsw_cmd_mbox_free (mbox );
1545
1531
return err ;
@@ -1553,8 +1539,6 @@ static void mlxsw_pci_fini(void *bus_priv)
1553
1539
mlxsw_pci_aqs_fini (mlxsw_pci );
1554
1540
mlxsw_pci_fw_area_fini (mlxsw_pci );
1555
1541
mlxsw_pci_free_irq_vectors (mlxsw_pci );
1556
- mlxsw_pci_mbox_free (mlxsw_pci , & mlxsw_pci -> cmd .out_mbox );
1557
- mlxsw_pci_mbox_free (mlxsw_pci , & mlxsw_pci -> cmd .in_mbox );
1558
1542
}
1559
1543
1560
1544
static struct mlxsw_pci_queue *
@@ -1776,6 +1760,37 @@ static const struct mlxsw_bus mlxsw_pci_bus = {
1776
1760
.features = MLXSW_BUS_F_TXRX | MLXSW_BUS_F_RESET ,
1777
1761
};
1778
1762
1763
+ static int mlxsw_pci_cmd_init (struct mlxsw_pci * mlxsw_pci )
1764
+ {
1765
+ int err ;
1766
+
1767
+ mutex_init (& mlxsw_pci -> cmd .lock );
1768
+ init_waitqueue_head (& mlxsw_pci -> cmd .wait );
1769
+
1770
+ err = mlxsw_pci_mbox_alloc (mlxsw_pci , & mlxsw_pci -> cmd .in_mbox );
1771
+ if (err )
1772
+ goto err_in_mbox_alloc ;
1773
+
1774
+ err = mlxsw_pci_mbox_alloc (mlxsw_pci , & mlxsw_pci -> cmd .out_mbox );
1775
+ if (err )
1776
+ goto err_out_mbox_alloc ;
1777
+
1778
+ return 0 ;
1779
+
1780
+ err_out_mbox_alloc :
1781
+ mlxsw_pci_mbox_free (mlxsw_pci , & mlxsw_pci -> cmd .in_mbox );
1782
+ err_in_mbox_alloc :
1783
+ mutex_destroy (& mlxsw_pci -> cmd .lock );
1784
+ return err ;
1785
+ }
1786
+
1787
+ static void mlxsw_pci_cmd_fini (struct mlxsw_pci * mlxsw_pci )
1788
+ {
1789
+ mlxsw_pci_mbox_free (mlxsw_pci , & mlxsw_pci -> cmd .out_mbox );
1790
+ mlxsw_pci_mbox_free (mlxsw_pci , & mlxsw_pci -> cmd .in_mbox );
1791
+ mutex_destroy (& mlxsw_pci -> cmd .lock );
1792
+ }
1793
+
1779
1794
static int mlxsw_pci_probe (struct pci_dev * pdev , const struct pci_device_id * id )
1780
1795
{
1781
1796
const char * driver_name = pdev -> driver -> name ;
@@ -1831,6 +1846,10 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1831
1846
mlxsw_pci -> pdev = pdev ;
1832
1847
pci_set_drvdata (pdev , mlxsw_pci );
1833
1848
1849
+ err = mlxsw_pci_cmd_init (mlxsw_pci );
1850
+ if (err )
1851
+ goto err_pci_cmd_init ;
1852
+
1834
1853
mlxsw_pci -> bus_info .device_kind = driver_name ;
1835
1854
mlxsw_pci -> bus_info .device_name = pci_name (mlxsw_pci -> pdev );
1836
1855
mlxsw_pci -> bus_info .dev = & pdev -> dev ;
@@ -1848,6 +1867,8 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1848
1867
return 0 ;
1849
1868
1850
1869
err_bus_device_register :
1870
+ mlxsw_pci_cmd_fini (mlxsw_pci );
1871
+ err_pci_cmd_init :
1851
1872
iounmap (mlxsw_pci -> hw_addr );
1852
1873
err_ioremap :
1853
1874
err_pci_resource_len_check :
@@ -1865,6 +1886,7 @@ static void mlxsw_pci_remove(struct pci_dev *pdev)
1865
1886
struct mlxsw_pci * mlxsw_pci = pci_get_drvdata (pdev );
1866
1887
1867
1888
mlxsw_core_bus_device_unregister (mlxsw_pci -> core , false);
1889
+ mlxsw_pci_cmd_fini (mlxsw_pci );
1868
1890
iounmap (mlxsw_pci -> hw_addr );
1869
1891
pci_release_regions (mlxsw_pci -> pdev );
1870
1892
pci_disable_device (mlxsw_pci -> pdev );
0 commit comments