net/liquidio: register VF
[dpdk.git] / drivers / net / liquidio / lio_ethdev.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Cavium, Inc. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <rte_ethdev.h>
35 #include <rte_cycles.h>
36 #include <rte_malloc.h>
37 #include <rte_alarm.h>
38
39 #include "lio_logs.h"
40 #include "lio_struct.h"
41 #include "lio_ethdev.h"
42
43 static int
44 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
45 {
46         PMD_INIT_FUNC_TRACE();
47
48         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
49                 return -EPERM;
50
51         rte_free(eth_dev->data->mac_addrs);
52         eth_dev->data->mac_addrs = NULL;
53
54         return 0;
55 }
56
57 static int
58 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
59 {
60         struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
61         struct lio_device *lio_dev = LIO_DEV(eth_dev);
62
63         PMD_INIT_FUNC_TRACE();
64
65         /* Primary does the initialization. */
66         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
67                 return 0;
68
69         rte_eth_copy_pci_info(eth_dev, pdev);
70         eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
71
72         if (pdev->mem_resource[0].addr) {
73                 lio_dev->hw_addr = pdev->mem_resource[0].addr;
74         } else {
75                 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
76                 return -ENODEV;
77         }
78
79         lio_dev->eth_dev = eth_dev;
80         /* set lio device print string */
81         snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
82                  "%s[%02x:%02x.%x]", pdev->driver->driver.name,
83                  pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
84
85         lio_dev->port_id = eth_dev->data->port_id;
86
87         eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
88         if (eth_dev->data->mac_addrs == NULL) {
89                 lio_dev_err(lio_dev,
90                             "MAC addresses memory allocation failed\n");
91                 return -ENOMEM;
92         }
93
94         return 0;
95 }
96
97 /* Set of PCI devices this driver supports */
98 static const struct rte_pci_id pci_id_liovf_map[] = {
99         { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
100         { .vendor_id = 0, /* sentinel */ }
101 };
102
103 static struct eth_driver rte_liovf_pmd = {
104         .pci_drv = {
105                 .id_table       = pci_id_liovf_map,
106                 .drv_flags      = RTE_PCI_DRV_NEED_MAPPING,
107                 .probe          = rte_eth_dev_pci_probe,
108                 .remove         = rte_eth_dev_pci_remove,
109         },
110         .eth_dev_init           = lio_eth_dev_init,
111         .eth_dev_uninit         = lio_eth_dev_uninit,
112         .dev_private_size       = sizeof(struct lio_device),
113 };
114
115 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
116 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
117 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");