OSDN Git Service

fd108cd9745780145cd82bb5d02105c461aa243b
[uclinux-h8/linux.git] / drivers / net / ethernet / cavium / liquidio / lio_vf_main.c
1 /**********************************************************************
2  * Author: Cavium, Inc.
3  *
4  * Contact: support@cavium.com
5  *          Please include "LiquidIO" in the subject.
6  *
7  * Copyright (c) 2003-2016 Cavium, Inc.
8  *
9  * This file is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License, Version 2, as
11  * published by the Free Software Foundation.
12  *
13  * This file is distributed in the hope that it will be useful, but
14  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16  * NONINFRINGEMENT.  See the GNU General Public License for more details.
17  ***********************************************************************/
18 #include <linux/pci.h>
19 #include <net/vxlan.h>
20 #include "liquidio_common.h"
21 #include "octeon_droq.h"
22 #include "octeon_iq.h"
23 #include "response_manager.h"
24 #include "octeon_device.h"
25
26 MODULE_AUTHOR("Cavium Networks, <support@cavium.com>");
27 MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Virtual Function Driver");
28 MODULE_LICENSE("GPL");
29 MODULE_VERSION(LIQUIDIO_VERSION);
30
31 struct octeon_device_priv {
32         /* Tasklet structures for this device. */
33         struct tasklet_struct droq_tasklet;
34         unsigned long napi_mask;
35 };
36
37 static int
38 liquidio_vf_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
39 static void liquidio_vf_remove(struct pci_dev *pdev);
40
41 static const struct pci_device_id liquidio_vf_pci_tbl[] = {
42         {
43                 PCI_VENDOR_ID_CAVIUM, OCTEON_CN23XX_VF_VID,
44                 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
45         },
46         {
47                 0, 0, 0, 0, 0, 0, 0
48         }
49 };
50 MODULE_DEVICE_TABLE(pci, liquidio_vf_pci_tbl);
51
52 static struct pci_driver liquidio_vf_pci_driver = {
53         .name           = "LiquidIO_VF",
54         .id_table       = liquidio_vf_pci_tbl,
55         .probe          = liquidio_vf_probe,
56         .remove         = liquidio_vf_remove,
57 };
58
59 /**
60  * \brief PCI probe handler
61  * @param pdev PCI device structure
62  * @param ent unused
63  */
64 static int
65 liquidio_vf_probe(struct pci_dev *pdev,
66                   const struct pci_device_id *ent __attribute__((unused)))
67 {
68         struct octeon_device *oct_dev = NULL;
69
70         oct_dev = octeon_allocate_device(pdev->device,
71                                          sizeof(struct octeon_device_priv));
72
73         if (!oct_dev) {
74                 dev_err(&pdev->dev, "Unable to allocate device\n");
75                 return -ENOMEM;
76         }
77
78         dev_info(&pdev->dev, "Initializing device %x:%x.\n",
79                  (u32)pdev->vendor, (u32)pdev->device);
80
81         /* Assign octeon_device for this device to the private data area. */
82         pci_set_drvdata(pdev, oct_dev);
83
84         /* set linux specific device pointer */
85         oct_dev->pci_dev = pdev;
86
87         return 0;
88 }
89
90 /**
91  * \brief Cleans up resources at unload time
92  * @param pdev PCI device structure
93  */
94 static void liquidio_vf_remove(struct pci_dev *pdev)
95 {
96         struct octeon_device *oct_dev = pci_get_drvdata(pdev);
97
98         dev_dbg(&oct_dev->pci_dev->dev, "Stopping device\n");
99
100         /* This octeon device has been removed. Update the global
101          * data structure to reflect this. Free the device structure.
102          */
103         octeon_free_device_mem(oct_dev);
104 }
105
106 static int __init liquidio_vf_init(void)
107 {
108         octeon_init_device_list(0);
109         return pci_register_driver(&liquidio_vf_pci_driver);
110 }
111
112 static void __exit liquidio_vf_exit(void)
113 {
114         pci_unregister_driver(&liquidio_vf_pci_driver);
115
116         pr_info("LiquidIO_VF network module is now unloaded\n");
117 }
118
119 module_init(liquidio_vf_init);
120 module_exit(liquidio_vf_exit);