4 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
17 * * Neither the name of Intel Corporation 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.
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 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.
38 #include <sys/queue.h>
40 #include <cmdline_parse.h>
42 #include <rte_interrupts.h>
48 #define TEST_BLACKLIST_NUM 0x100
54 * - Register a driver with a ``devinit()`` function.
56 * - Dump all PCI devices.
58 * - Check that the ``devinit()`` function is called at least once.
61 int test_pci_run = 0; /* value checked by the multiprocess test */
62 static unsigned pci_dev_count;
63 static unsigned driver_registered = 0;
64 static struct rte_pci_addr blacklist[TEST_BLACKLIST_NUM];
66 static int my_driver_init(struct rte_pci_driver *dr,
67 struct rte_pci_device *dev);
70 * To test cases where RTE_PCI_DRV_NEED_IGB_UIO is set, and isn't set, two
71 * drivers are created (one with IGB devices, the other with IXGBE devices).
75 struct rte_pci_id my_driver_id[] = {
77 #define RTE_PCI_DEV_ID_DECL_IXGBE(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
78 #include <rte_pci_dev_ids.h>
80 { .vendor_id = 0, /* sentinel */ },
83 struct rte_pci_id my_driver_id2[] = {
86 #define RTE_PCI_DEV_ID_DECL_EM(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
87 #define RTE_PCI_DEV_ID_DECL_IGB(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
88 #define RTE_PCI_DEV_USE_82575EB_COPPER
89 #include <rte_pci_dev_ids.h>
91 { .vendor_id = 0, /* sentinel */ },
94 struct rte_pci_driver my_driver = {
95 .name = "test_driver",
96 .devinit = my_driver_init,
97 .id_table = my_driver_id,
98 #ifdef RTE_EAL_UNBIND_PORTS
99 .drv_flags = RTE_PCI_DRV_NEED_IGB_UIO,
103 struct rte_pci_driver my_driver2 = {
104 .name = "test_driver2",
105 .devinit = my_driver_init,
106 .id_table = my_driver_id2,
111 my_driver_init(__attribute__((unused)) struct rte_pci_driver *dr,
112 struct rte_pci_device *dev)
114 printf("My driver init called in %s\n", dr->name);
115 printf("%x:%x:%x.%d", dev->addr.domain, dev->addr.bus,
116 dev->addr.devid, dev->addr.function);
117 printf(" - vendor:%x device:%x\n", dev->id.vendor_id, dev->id.device_id);
124 blacklist_clear(void)
126 rte_eal_pci_set_blacklist(NULL, 0);
132 blacklist_all_devices(void)
134 struct rte_pci_device *dev = NULL;
137 memset(blacklist, 0, sizeof (blacklist));
139 TAILQ_FOREACH(dev, &device_list, next) {
140 if (idx >= sizeof (blacklist) / sizeof (blacklist[0])) {
141 printf("Error: too many devices to blacklist");
144 blacklist[idx] = dev->addr;
148 rte_eal_pci_set_blacklist(blacklist, idx);
149 printf("%u devices blacklisted\n", idx);
156 printf("Dump all devices\n");
158 if (driver_registered == 0) {
159 rte_eal_pci_register(&my_driver);
160 rte_eal_pci_register(&my_driver2);
161 driver_registered = 1;
165 printf("Scan bus\n");
168 if (pci_dev_count == 0) {
169 printf("no device detected\n");
173 blacklist_all_devices();
176 printf("Scan bus with all devices blacklisted\n");
181 if (pci_dev_count != 0) {
182 printf("not all devices are blacklisted\n");
187 if (driver_registered == 1) {
188 rte_eal_pci_unregister(&my_driver);
189 rte_eal_pci_unregister(&my_driver2);
190 driver_registered = 0;