DPDK  /usr/bin/make-f/build/dpdk-1mgIfo/dpdk-16.11.6/mk/rte.sdkconfig.mkshowversion
rte_pci.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2015 Intel Corporation. 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 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.
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 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 /* BSD LICENSE
34  *
35  * Copyright 2013-2014 6WIND S.A.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  *
41  * * Redistributions of source code must retain the above copyright
42  * notice, this list of conditions and the following disclaimer.
43  * * Redistributions in binary form must reproduce the above copyright
44  * notice, this list of conditions and the following disclaimer in
45  * the documentation and/or other materials provided with the
46  * distribution.
47  * * Neither the name of 6WIND S.A. nor the names of its
48  * contributors may be used to endorse or promote products derived
49  * from this software without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  */
63 
64 #ifndef _RTE_PCI_H_
65 #define _RTE_PCI_H_
66 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 #include <stdio.h>
78 #include <stdlib.h>
79 #include <limits.h>
80 #include <errno.h>
81 #include <sys/queue.h>
82 #include <stdint.h>
83 #include <inttypes.h>
84 
85 #include <rte_debug.h>
86 #include <rte_interrupts.h>
87 #include <rte_dev.h>
88 
92 extern struct pci_driver_list pci_driver_list;
93 extern struct pci_device_list pci_device_list;
96 const char *pci_get_sysfs_path(void);
97 
99 #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
100 #define PCI_PRI_STR_SIZE sizeof("XXXX:XX:XX.X")
101 
103 #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
104 
106 #define PCI_FMT_NVAL 4
107 
109 #define PCI_RESOURCE_FMT_NVAL 3
110 
112 #define PCI_MAX_RESOURCE 6
113 
118 struct rte_pci_id {
119  uint32_t class_id;
120  uint16_t vendor_id;
121  uint16_t device_id;
124 };
125 
129 struct rte_pci_addr {
130  uint16_t domain;
131  uint8_t bus;
132  uint8_t devid;
133  uint8_t function;
134 };
135 
136 struct rte_devargs;
137 
138 enum rte_kernel_driver {
139  RTE_KDRV_UNKNOWN = 0,
140  RTE_KDRV_IGB_UIO,
141  RTE_KDRV_VFIO,
142  RTE_KDRV_UIO_GENERIC,
143  RTE_KDRV_NIC_UIO,
144  RTE_KDRV_NONE,
145 };
146 
151  TAILQ_ENTRY(rte_pci_device) next;
152  struct rte_device device;
153  struct rte_pci_addr addr;
154  struct rte_pci_id id;
155  struct rte_mem_resource mem_resource[PCI_MAX_RESOURCE];
157  struct rte_intr_handle intr_handle;
159  uint16_t max_vfs;
160  enum rte_kernel_driver kdrv;
161 };
162 
164 #define PCI_ANY_ID (0xffff)
165 #define RTE_CLASS_ANY_ID (0xffffff)
166 
167 #ifdef __cplusplus
168 
169 #define RTE_PCI_DEVICE(vend, dev) \
170  RTE_CLASS_ANY_ID, \
171  (vend), \
172  (dev), \
173  PCI_ANY_ID, \
174  PCI_ANY_ID
175 #else
176 
177 #define RTE_PCI_DEVICE(vend, dev) \
178  .class_id = RTE_CLASS_ANY_ID, \
179  .vendor_id = (vend), \
180  .device_id = (dev), \
181  .subsystem_vendor_id = PCI_ANY_ID, \
182  .subsystem_device_id = PCI_ANY_ID
183 #endif
184 
185 struct rte_pci_driver;
186 
190 typedef int (pci_probe_t)(struct rte_pci_driver *, struct rte_pci_device *);
191 
195 typedef int (pci_remove_t)(struct rte_pci_device *);
196 
201  TAILQ_ENTRY(rte_pci_driver) next;
202  struct rte_driver driver;
204  pci_remove_t *remove;
205  const struct rte_pci_id *id_table;
206  uint32_t drv_flags;
207 };
208 
210 #define RTE_PCI_DRV_NEED_MAPPING 0x0001
211 
212 #define RTE_PCI_DRV_FORCE_UNBIND 0x0004
213 
214 #define RTE_PCI_DRV_INTR_LSC 0x0008
215 
216 #define RTE_PCI_DRV_DETACHABLE 0x0010
217 
221 struct pci_map {
222  void *addr;
223  char *path;
224  uint64_t offset;
225  uint64_t size;
226  uint64_t phaddr;
227 };
228 
235  TAILQ_ENTRY(mapped_pci_resource) next;
236 
237  struct rte_pci_addr pci_addr;
238  char path[PATH_MAX];
239  int nb_maps;
240  struct pci_map maps[PCI_MAX_RESOURCE];
241 };
242 
244 TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
245 
247 #define GET_PCIADDR_FIELD(in, fd, lim, dlm) \
248 do { \
249  unsigned long val; \
250  char *end; \
251  errno = 0; \
252  val = strtoul((in), &end, 16); \
253  if (errno != 0 || end[0] != (dlm) || val > (lim)) \
254  return -EINVAL; \
255  (fd) = (typeof (fd))val; \
256  (in) = end + 1; \
257 } while(0)
258 
272 static inline int
273 eal_parse_pci_BDF(const char *input, struct rte_pci_addr *dev_addr)
274 {
275  dev_addr->domain = 0;
276  GET_PCIADDR_FIELD(input, dev_addr->bus, UINT8_MAX, ':');
277  GET_PCIADDR_FIELD(input, dev_addr->devid, UINT8_MAX, '.');
278  GET_PCIADDR_FIELD(input, dev_addr->function, UINT8_MAX, 0);
279  return 0;
280 }
281 
294 static inline int
295 eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
296 {
297  GET_PCIADDR_FIELD(input, dev_addr->domain, UINT16_MAX, ':');
298  GET_PCIADDR_FIELD(input, dev_addr->bus, UINT8_MAX, ':');
299  GET_PCIADDR_FIELD(input, dev_addr->devid, UINT8_MAX, '.');
300  GET_PCIADDR_FIELD(input, dev_addr->function, UINT8_MAX, 0);
301  return 0;
302 }
303 #undef GET_PCIADDR_FIELD
304 
317 static inline void
319  char *output, size_t size)
320 {
321  RTE_VERIFY(size >= PCI_PRI_STR_SIZE);
322  RTE_VERIFY(snprintf(output, size, PCI_PRI_FMT,
323  addr->domain, addr->bus,
324  addr->devid, addr->function) >= 0);
325 }
326 
327 /* Compare two PCI device addresses. */
340 static inline int
342  const struct rte_pci_addr *addr2)
343 {
344  uint64_t dev_addr, dev_addr2;
345 
346  if ((addr == NULL) || (addr2 == NULL))
347  return -1;
348 
349  dev_addr = (addr->domain << 24) | (addr->bus << 16) |
350  (addr->devid << 8) | addr->function;
351  dev_addr2 = (addr2->domain << 24) | (addr2->bus << 16) |
352  (addr2->devid << 8) | addr2->function;
353 
354  if (dev_addr > dev_addr2)
355  return 1;
356  else if (dev_addr < dev_addr2)
357  return -1;
358  else
359  return 0;
360 }
361 
369 int rte_eal_pci_scan(void);
370 
382 int rte_eal_pci_probe(void);
383 
399 int rte_eal_pci_map_device(struct rte_pci_device *dev);
400 
408 void rte_eal_pci_unmap_device(struct rte_pci_device *dev);
409 
428 void *pci_map_resource(void *requested_addr, int fd, off_t offset,
429  size_t size, int additional_flags);
430 
440 void pci_unmap_resource(void *requested_addr, size_t size);
441 
455 int rte_eal_pci_probe_one(const struct rte_pci_addr *addr);
456 
470 int rte_eal_pci_detach(const struct rte_pci_addr *addr);
471 
478 void rte_eal_pci_dump(FILE *f);
479 
487 void rte_eal_pci_register(struct rte_pci_driver *driver);
488 
490 #define RTE_PMD_REGISTER_PCI(nm, pci_drv) \
491 RTE_INIT(pciinitfn_ ##nm); \
492 static void pciinitfn_ ##nm(void) \
493 {\
494  (pci_drv).driver.name = RTE_STR(nm);\
495  rte_eal_pci_register(&pci_drv); \
496 } \
497 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
498 
506 void rte_eal_pci_unregister(struct rte_pci_driver *driver);
507 
521 int rte_eal_pci_read_config(const struct rte_pci_device *device,
522  void *buf, size_t len, off_t offset);
523 
537 int rte_eal_pci_write_config(const struct rte_pci_device *device,
538  const void *buf, size_t len, off_t offset);
539 
546  struct rte_pci_device *dev;
547  uint64_t base;
548  uint64_t len; /* only filled for memory mapped ports */
549 };
550 
566 int rte_eal_pci_ioport_map(struct rte_pci_device *dev, int bar,
567  struct rte_pci_ioport *p);
568 
578 
592  void *data, size_t len, off_t offset);
593 
607  const void *data, size_t len, off_t offset);
608 
609 #ifdef __cplusplus
610 }
611 #endif
612 
613 #endif /* _RTE_PCI_H_ */
int rte_eal_pci_ioport_map(struct rte_pci_device *dev, int bar, struct rte_pci_ioport *p)
struct rte_pci_driver * driver
Definition: rte_pci.h:158
void rte_eal_pci_register(struct rte_pci_driver *driver)
int rte_eal_pci_scan(void)
TAILQ_HEAD(pci_device_list, rte_pci_device)
uint16_t domain
Definition: rte_pci.h:130
struct pci_driver_list pci_driver_list
int rte_eal_pci_probe(void)
void rte_eal_pci_ioport_write(struct rte_pci_ioport *p, const void *data, size_t len, off_t offset)
int rte_eal_pci_write_config(const struct rte_pci_device *device, const void *buf, size_t len, off_t offset)
uint16_t device_id
Definition: rte_pci.h:121
uint8_t bus
Definition: rte_pci.h:131
uint8_t function
Definition: rte_pci.h:133
int() pci_probe_t(struct rte_pci_driver *, struct rte_pci_device *)
Definition: rte_pci.h:190
int rte_eal_pci_read_config(const struct rte_pci_device *device, void *buf, size_t len, off_t offset)
int rte_eal_pci_map_device(struct rte_pci_device *dev)
uint32_t class_id
Definition: rte_pci.h:119
static void rte_eal_pci_device_name(const struct rte_pci_addr *addr, char *output, size_t size)
Definition: rte_pci.h:318
#define PCI_PRI_FMT
Definition: rte_pci.h:99
uint8_t devid
Definition: rte_pci.h:132
int() pci_remove_t(struct rte_pci_device *)
Definition: rte_pci.h:195
static int eal_parse_pci_DomBDF(const char *input, struct rte_pci_addr *dev_addr)
Definition: rte_pci.h:295
static int eal_parse_pci_BDF(const char *input, struct rte_pci_addr *dev_addr)
Definition: rte_pci.h:273
const struct rte_pci_id * id_table
Definition: rte_pci.h:205
#define PCI_MAX_RESOURCE
Definition: rte_pci.h:112
int rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
uint16_t subsystem_device_id
Definition: rte_pci.h:123
void rte_eal_pci_dump(FILE *f)
int rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
void rte_eal_pci_unmap_device(struct rte_pci_device *dev)
int rte_eal_pci_detach(const struct rte_pci_addr *addr)
pci_probe_t * probe
Definition: rte_pci.h:203
void rte_eal_pci_ioport_read(struct rte_pci_ioport *p, void *data, size_t len, off_t offset)
uint32_t drv_flags
Definition: rte_pci.h:206
void rte_eal_pci_unregister(struct rte_pci_driver *driver)
uint16_t subsystem_vendor_id
Definition: rte_pci.h:122
struct pci_device_list pci_device_list
uint16_t vendor_id
Definition: rte_pci.h:120
uint16_t max_vfs
Definition: rte_pci.h:159
const char * pci_get_sysfs_path(void)
static int rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, const struct rte_pci_addr *addr2)
Definition: rte_pci.h:341