pci.c (62e86f9e828128ce6452a2d8ab4a26609885dda6) | pci.c (1d20d23c59c93a8b381063ef9785564018ad4c3a) |
---|---|
1/* 2 * drivers/net/ethernet/mellanox/mlxsw/pci.c 3 * Copyright (c) 2015 Mellanox Technologies. All rights reserved. 4 * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * --- 35 unchanged lines hidden (view full) --- 44#include <linux/skbuff.h> 45#include <linux/if_vlan.h> 46#include <linux/log2.h> 47#include <linux/debugfs.h> 48#include <linux/seq_file.h> 49#include <linux/string.h> 50 51#include "pci_hw.h" | 1/* 2 * drivers/net/ethernet/mellanox/mlxsw/pci.c 3 * Copyright (c) 2015 Mellanox Technologies. All rights reserved. 4 * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * --- 35 unchanged lines hidden (view full) --- 44#include <linux/skbuff.h> 45#include <linux/if_vlan.h> 46#include <linux/log2.h> 47#include <linux/debugfs.h> 48#include <linux/seq_file.h> 49#include <linux/string.h> 50 51#include "pci_hw.h" |
52#include "pci.h" |
|
52#include "core.h" 53#include "cmd.h" 54#include "port.h" 55#include "resources.h" 56 57static const char mlxsw_pci_driver_name[] = "mlxsw_pci"; 58 | 53#include "core.h" 54#include "cmd.h" 55#include "port.h" 56#include "resources.h" 57 58static const char mlxsw_pci_driver_name[] = "mlxsw_pci"; 59 |
59static const struct pci_device_id mlxsw_pci_id_table[] = { 60 {PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_SWITCHX2), 0}, 61 {PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_SPECTRUM), 0}, 62 {0, } 63}; 64 | |
65static struct dentry *mlxsw_pci_dbg_root; 66 | 60static struct dentry *mlxsw_pci_dbg_root; 61 |
67static const char *mlxsw_pci_device_kind_get(const struct pci_device_id *id) 68{ 69 switch (id->device) { 70 case PCI_DEVICE_ID_MELLANOX_SWITCHX2: 71 return MLXSW_DEVICE_KIND_SWITCHX2; 72 case PCI_DEVICE_ID_MELLANOX_SPECTRUM: 73 return MLXSW_DEVICE_KIND_SPECTRUM; 74 default: 75 BUG(); 76 } 77} 78 | |
79#define mlxsw_pci_write32(mlxsw_pci, reg, val) \ 80 iowrite32be(val, (mlxsw_pci)->hw_addr + (MLXSW_PCI_ ## reg)) 81#define mlxsw_pci_read32(mlxsw_pci, reg) \ 82 ioread32be((mlxsw_pci)->hw_addr + (MLXSW_PCI_ ## reg)) 83 84enum mlxsw_pci_queue_type { 85 MLXSW_PCI_QUEUE_TYPE_SDQ, 86 MLXSW_PCI_QUEUE_TYPE_RDQ, --- 1461 unchanged lines hidden (view full) --- 1548 goto err_config_profile; 1549 1550 err = mlxsw_pci_aqs_init(mlxsw_pci, mbox); 1551 if (err) 1552 goto err_aqs_init; 1553 1554 err = request_irq(mlxsw_pci->msix_entry.vector, 1555 mlxsw_pci_eq_irq_handler, 0, | 62#define mlxsw_pci_write32(mlxsw_pci, reg, val) \ 63 iowrite32be(val, (mlxsw_pci)->hw_addr + (MLXSW_PCI_ ## reg)) 64#define mlxsw_pci_read32(mlxsw_pci, reg) \ 65 ioread32be((mlxsw_pci)->hw_addr + (MLXSW_PCI_ ## reg)) 66 67enum mlxsw_pci_queue_type { 68 MLXSW_PCI_QUEUE_TYPE_SDQ, 69 MLXSW_PCI_QUEUE_TYPE_RDQ, --- 1461 unchanged lines hidden (view full) --- 1531 goto err_config_profile; 1532 1533 err = mlxsw_pci_aqs_init(mlxsw_pci, mbox); 1534 if (err) 1535 goto err_aqs_init; 1536 1537 err = request_irq(mlxsw_pci->msix_entry.vector, 1538 mlxsw_pci_eq_irq_handler, 0, |
1556 mlxsw_pci_driver_name, mlxsw_pci); | 1539 mlxsw_pci->bus_info.device_kind, mlxsw_pci); |
1557 if (err) { 1558 dev_err(&pdev->dev, "IRQ request failed\n"); 1559 goto err_request_eq_irq; 1560 } 1561 1562 goto mbox_put; 1563 1564err_request_eq_irq: --- 223 unchanged lines hidden (view full) --- 1788 break; 1789 cond_resched(); 1790 } while (time_before(jiffies, end)); 1791 return 0; 1792} 1793 1794static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1795{ | 1540 if (err) { 1541 dev_err(&pdev->dev, "IRQ request failed\n"); 1542 goto err_request_eq_irq; 1543 } 1544 1545 goto mbox_put; 1546 1547err_request_eq_irq: --- 223 unchanged lines hidden (view full) --- 1771 break; 1772 cond_resched(); 1773 } while (time_before(jiffies, end)); 1774 return 0; 1775} 1776 1777static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1778{ |
1779 const char *driver_name = pdev->driver->name; |
|
1796 struct mlxsw_pci *mlxsw_pci; 1797 int err; 1798 1799 mlxsw_pci = kzalloc(sizeof(*mlxsw_pci), GFP_KERNEL); 1800 if (!mlxsw_pci) 1801 return -ENOMEM; 1802 1803 err = pci_enable_device(pdev); 1804 if (err) { 1805 dev_err(&pdev->dev, "pci_enable_device failed\n"); 1806 goto err_pci_enable_device; 1807 } 1808 | 1780 struct mlxsw_pci *mlxsw_pci; 1781 int err; 1782 1783 mlxsw_pci = kzalloc(sizeof(*mlxsw_pci), GFP_KERNEL); 1784 if (!mlxsw_pci) 1785 return -ENOMEM; 1786 1787 err = pci_enable_device(pdev); 1788 if (err) { 1789 dev_err(&pdev->dev, "pci_enable_device failed\n"); 1790 goto err_pci_enable_device; 1791 } 1792 |
1809 err = pci_request_regions(pdev, mlxsw_pci_driver_name); | 1793 err = pci_request_regions(pdev, driver_name); |
1810 if (err) { 1811 dev_err(&pdev->dev, "pci_request_regions failed\n"); 1812 goto err_pci_request_regions; 1813 } 1814 1815 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); 1816 if (!err) { 1817 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); --- 34 unchanged lines hidden (view full) --- 1852 } 1853 1854 err = pci_enable_msix_exact(pdev, &mlxsw_pci->msix_entry, 1); 1855 if (err) { 1856 dev_err(&pdev->dev, "MSI-X init failed\n"); 1857 goto err_msix_init; 1858 } 1859 | 1794 if (err) { 1795 dev_err(&pdev->dev, "pci_request_regions failed\n"); 1796 goto err_pci_request_regions; 1797 } 1798 1799 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); 1800 if (!err) { 1801 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); --- 34 unchanged lines hidden (view full) --- 1836 } 1837 1838 err = pci_enable_msix_exact(pdev, &mlxsw_pci->msix_entry, 1); 1839 if (err) { 1840 dev_err(&pdev->dev, "MSI-X init failed\n"); 1841 goto err_msix_init; 1842 } 1843 |
1860 mlxsw_pci->bus_info.device_kind = mlxsw_pci_device_kind_get(id); | 1844 mlxsw_pci->bus_info.device_kind = driver_name; |
1861 mlxsw_pci->bus_info.device_name = pci_name(mlxsw_pci->pdev); 1862 mlxsw_pci->bus_info.dev = &pdev->dev; 1863 1864 mlxsw_pci->dbg_dir = debugfs_create_dir(mlxsw_pci->bus_info.device_name, 1865 mlxsw_pci_dbg_root); 1866 if (!mlxsw_pci->dbg_dir) { 1867 dev_err(&pdev->dev, "Failed to create debugfs dir\n"); 1868 err = -ENOMEM; --- 35 unchanged lines hidden (view full) --- 1904 debugfs_remove_recursive(mlxsw_pci->dbg_dir); 1905 pci_disable_msix(mlxsw_pci->pdev); 1906 iounmap(mlxsw_pci->hw_addr); 1907 pci_release_regions(mlxsw_pci->pdev); 1908 pci_disable_device(mlxsw_pci->pdev); 1909 kfree(mlxsw_pci); 1910} 1911 | 1845 mlxsw_pci->bus_info.device_name = pci_name(mlxsw_pci->pdev); 1846 mlxsw_pci->bus_info.dev = &pdev->dev; 1847 1848 mlxsw_pci->dbg_dir = debugfs_create_dir(mlxsw_pci->bus_info.device_name, 1849 mlxsw_pci_dbg_root); 1850 if (!mlxsw_pci->dbg_dir) { 1851 dev_err(&pdev->dev, "Failed to create debugfs dir\n"); 1852 err = -ENOMEM; --- 35 unchanged lines hidden (view full) --- 1888 debugfs_remove_recursive(mlxsw_pci->dbg_dir); 1889 pci_disable_msix(mlxsw_pci->pdev); 1890 iounmap(mlxsw_pci->hw_addr); 1891 pci_release_regions(mlxsw_pci->pdev); 1892 pci_disable_device(mlxsw_pci->pdev); 1893 kfree(mlxsw_pci); 1894} 1895 |
1912static struct pci_driver mlxsw_pci_driver = { 1913 .name = mlxsw_pci_driver_name, 1914 .id_table = mlxsw_pci_id_table, 1915 .probe = mlxsw_pci_probe, 1916 .remove = mlxsw_pci_remove, 1917}; | 1896int mlxsw_pci_driver_register(struct pci_driver *pci_driver) 1897{ 1898 pci_driver->probe = mlxsw_pci_probe; 1899 pci_driver->remove = mlxsw_pci_remove; 1900 return pci_register_driver(pci_driver); 1901} 1902EXPORT_SYMBOL(mlxsw_pci_driver_register); |
1918 | 1903 |
1919static int __init mlxsw_pci_module_init(void) | 1904void mlxsw_pci_driver_unregister(struct pci_driver *pci_driver) |
1920{ | 1905{ |
1921 int err; | 1906 pci_unregister_driver(pci_driver); 1907} 1908EXPORT_SYMBOL(mlxsw_pci_driver_unregister); |
1922 | 1909 |
1910static int __init mlxsw_pci_module_init(void) 1911{ |
|
1923 mlxsw_pci_dbg_root = debugfs_create_dir(mlxsw_pci_driver_name, NULL); 1924 if (!mlxsw_pci_dbg_root) 1925 return -ENOMEM; | 1912 mlxsw_pci_dbg_root = debugfs_create_dir(mlxsw_pci_driver_name, NULL); 1913 if (!mlxsw_pci_dbg_root) 1914 return -ENOMEM; |
1926 err = pci_register_driver(&mlxsw_pci_driver); 1927 if (err) 1928 goto err_register_driver; | |
1929 return 0; | 1915 return 0; |
1930 1931err_register_driver: 1932 debugfs_remove_recursive(mlxsw_pci_dbg_root); 1933 return err; | |
1934} 1935 1936static void __exit mlxsw_pci_module_exit(void) 1937{ | 1916} 1917 1918static void __exit mlxsw_pci_module_exit(void) 1919{ |
1938 pci_unregister_driver(&mlxsw_pci_driver); | |
1939 debugfs_remove_recursive(mlxsw_pci_dbg_root); 1940} 1941 1942module_init(mlxsw_pci_module_init); 1943module_exit(mlxsw_pci_module_exit); 1944 1945MODULE_LICENSE("Dual BSD/GPL"); 1946MODULE_AUTHOR("Jiri Pirko <jiri@mellanox.com>"); 1947MODULE_DESCRIPTION("Mellanox switch PCI interface driver"); | 1920 debugfs_remove_recursive(mlxsw_pci_dbg_root); 1921} 1922 1923module_init(mlxsw_pci_module_init); 1924module_exit(mlxsw_pci_module_exit); 1925 1926MODULE_LICENSE("Dual BSD/GPL"); 1927MODULE_AUTHOR("Jiri Pirko <jiri@mellanox.com>"); 1928MODULE_DESCRIPTION("Mellanox switch PCI interface driver"); |
1948MODULE_DEVICE_TABLE(pci, mlxsw_pci_id_table); | |