4 * Copyright(c) 2010-2014 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.
35 #ifdef RTE_EXEC_ENV_LINUXAPP
40 #include "virtio_pci.h"
41 #include "virtio_logs.h"
42 #include "virtqueue.h"
45 * Following macros are derived from linux/pci_regs.h, however,
46 * we can't simply include that header here, as there is no such
47 * file for non-Linux platform.
49 #define PCI_CAPABILITY_LIST 0x34
50 #define PCI_CAP_ID_VNDR 0x09
52 #define VIRTIO_PCI_REG_ADDR(hw, reg) \
53 (unsigned short)((hw)->io_base + (reg))
55 #define VIRTIO_READ_REG_1(hw, reg) \
56 inb((VIRTIO_PCI_REG_ADDR((hw), (reg))))
57 #define VIRTIO_WRITE_REG_1(hw, reg, value) \
58 outb_p((unsigned char)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))
60 #define VIRTIO_READ_REG_2(hw, reg) \
61 inw((VIRTIO_PCI_REG_ADDR((hw), (reg))))
62 #define VIRTIO_WRITE_REG_2(hw, reg, value) \
63 outw_p((unsigned short)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))
65 #define VIRTIO_READ_REG_4(hw, reg) \
66 inl((VIRTIO_PCI_REG_ADDR((hw), (reg))))
67 #define VIRTIO_WRITE_REG_4(hw, reg, value) \
68 outl_p((unsigned int)(value), (VIRTIO_PCI_REG_ADDR((hw), (reg))))
71 legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
72 void *dst, int length)
78 off = VIRTIO_PCI_CONFIG(hw) + offset;
79 for (d = dst; length > 0; d += size, off += size, length -= size) {
82 *(uint32_t *)d = VIRTIO_READ_REG_4(hw, off);
83 } else if (length >= 2) {
85 *(uint16_t *)d = VIRTIO_READ_REG_2(hw, off);
88 *d = VIRTIO_READ_REG_1(hw, off);
94 legacy_write_dev_config(struct virtio_hw *hw, size_t offset,
95 const void *src, int length)
101 off = VIRTIO_PCI_CONFIG(hw) + offset;
102 for (s = src; length > 0; s += size, off += size, length -= size) {
105 VIRTIO_WRITE_REG_4(hw, off, *(const uint32_t *)s);
106 } else if (length >= 2) {
108 VIRTIO_WRITE_REG_2(hw, off, *(const uint16_t *)s);
111 VIRTIO_WRITE_REG_1(hw, off, *s);
117 legacy_get_features(struct virtio_hw *hw)
119 return VIRTIO_READ_REG_4(hw, VIRTIO_PCI_HOST_FEATURES);
123 legacy_set_features(struct virtio_hw *hw, uint64_t features)
125 if ((features >> 32) != 0) {
127 "only 32 bit features are allowed for legacy virtio!");
130 VIRTIO_WRITE_REG_4(hw, VIRTIO_PCI_GUEST_FEATURES, features);
134 legacy_get_status(struct virtio_hw *hw)
136 return VIRTIO_READ_REG_1(hw, VIRTIO_PCI_STATUS);
140 legacy_set_status(struct virtio_hw *hw, uint8_t status)
142 VIRTIO_WRITE_REG_1(hw, VIRTIO_PCI_STATUS, status);
146 legacy_reset(struct virtio_hw *hw)
148 legacy_set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
152 legacy_get_isr(struct virtio_hw *hw)
154 return VIRTIO_READ_REG_1(hw, VIRTIO_PCI_ISR);
157 /* Enable one vector (0) for Link State Intrerrupt */
159 legacy_set_config_irq(struct virtio_hw *hw, uint16_t vec)
161 VIRTIO_WRITE_REG_2(hw, VIRTIO_MSI_CONFIG_VECTOR, vec);
162 return VIRTIO_READ_REG_2(hw, VIRTIO_MSI_CONFIG_VECTOR);
166 legacy_get_queue_num(struct virtio_hw *hw, uint16_t queue_id)
168 VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, queue_id);
169 return VIRTIO_READ_REG_2(hw, VIRTIO_PCI_QUEUE_NUM);
173 legacy_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
175 VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, vq->vq_queue_index);
177 VIRTIO_WRITE_REG_4(hw, VIRTIO_PCI_QUEUE_PFN,
178 vq->mz->phys_addr >> VIRTIO_PCI_QUEUE_ADDR_SHIFT);
182 legacy_del_queue(struct virtio_hw *hw, struct virtqueue *vq)
184 VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, vq->vq_queue_index);
186 VIRTIO_WRITE_REG_4(hw, VIRTIO_PCI_QUEUE_PFN, 0);
190 legacy_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
192 VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_NOTIFY, vq->vq_queue_index);
195 #ifdef RTE_EXEC_ENV_LINUXAPP
197 parse_sysfs_value(const char *filename, unsigned long *val)
203 f = fopen(filename, "r");
205 PMD_INIT_LOG(ERR, "%s(): cannot open sysfs value %s",
210 if (fgets(buf, sizeof(buf), f) == NULL) {
211 PMD_INIT_LOG(ERR, "%s(): cannot read sysfs value %s",
216 *val = strtoul(buf, &end, 0);
217 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
218 PMD_INIT_LOG(ERR, "%s(): cannot parse sysfs value %s",
228 get_uio_dev(struct rte_pci_addr *loc, char *buf, unsigned int buflen,
229 unsigned int *uio_num)
233 char dirname[PATH_MAX];
236 * depending on kernel version, uio can be located in uio/uioX
239 snprintf(dirname, sizeof(dirname),
240 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio",
241 loc->domain, loc->bus, loc->devid, loc->function);
242 dir = opendir(dirname);
244 /* retry with the parent directory */
245 snprintf(dirname, sizeof(dirname),
246 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT,
247 loc->domain, loc->bus, loc->devid, loc->function);
248 dir = opendir(dirname);
251 PMD_INIT_LOG(ERR, "Cannot opendir %s", dirname);
256 /* take the first file starting with "uio" */
257 while ((e = readdir(dir)) != NULL) {
258 /* format could be uio%d ...*/
259 int shortprefix_len = sizeof("uio") - 1;
260 /* ... or uio:uio%d */
261 int longprefix_len = sizeof("uio:uio") - 1;
264 if (strncmp(e->d_name, "uio", 3) != 0)
267 /* first try uio%d */
269 *uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10);
270 if (errno == 0 && endptr != (e->d_name + shortprefix_len)) {
271 snprintf(buf, buflen, "%s/uio%u", dirname, *uio_num);
275 /* then try uio:uio%d */
277 *uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10);
278 if (errno == 0 && endptr != (e->d_name + longprefix_len)) {
279 snprintf(buf, buflen, "%s/uio:uio%u", dirname,
286 /* No uio resource found */
288 PMD_INIT_LOG(ERR, "Could not find uio resource");
296 legacy_virtio_has_msix(const struct rte_pci_addr *loc)
299 char dirname[PATH_MAX];
301 snprintf(dirname, sizeof(dirname),
302 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs",
303 loc->domain, loc->bus, loc->devid, loc->function);
305 d = opendir(dirname);
312 /* Extract I/O port numbers from sysfs */
314 virtio_resource_init_by_uio(struct rte_pci_device *pci_dev)
316 char dirname[PATH_MAX];
317 char filename[PATH_MAX];
318 unsigned long start, size;
319 unsigned int uio_num;
321 if (get_uio_dev(&pci_dev->addr, dirname, sizeof(dirname), &uio_num) < 0)
324 /* get portio size */
325 snprintf(filename, sizeof(filename),
326 "%s/portio/port0/size", dirname);
327 if (parse_sysfs_value(filename, &size) < 0) {
328 PMD_INIT_LOG(ERR, "%s(): cannot parse size",
333 /* get portio start */
334 snprintf(filename, sizeof(filename),
335 "%s/portio/port0/start", dirname);
336 if (parse_sysfs_value(filename, &start) < 0) {
337 PMD_INIT_LOG(ERR, "%s(): cannot parse portio start",
341 pci_dev->mem_resource[0].addr = (void *)(uintptr_t)start;
342 pci_dev->mem_resource[0].len = (uint64_t)size;
344 "PCI Port IO found start=0x%lx with size=0x%lx",
348 memset(dirname, 0, sizeof(dirname));
349 snprintf(dirname, sizeof(dirname), "/dev/uio%u", uio_num);
350 pci_dev->intr_handle.fd = open(dirname, O_RDWR);
351 if (pci_dev->intr_handle.fd < 0) {
352 PMD_INIT_LOG(ERR, "Cannot open %s: %s\n",
353 dirname, strerror(errno));
357 pci_dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
358 pci_dev->driver->drv_flags |= RTE_PCI_DRV_INTR_LSC;
363 /* Extract port I/O numbers from proc/ioports */
365 virtio_resource_init_by_ioports(struct rte_pci_device *pci_dev)
375 snprintf(pci_id, sizeof(pci_id), PCI_PRI_FMT,
376 pci_dev->addr.domain,
379 pci_dev->addr.function);
381 fp = fopen("/proc/ioports", "r");
383 PMD_INIT_LOG(ERR, "%s(): can't open ioports", __func__);
387 while (getdelim(&line, &linesz, '\n', fp) > 0) {
392 n = strcspn(ptr, ":");
396 while (*left && isspace(*left))
399 if (!strncmp(left, pci_id, strlen(pci_id))) {
402 while (*ptr && isspace(*ptr))
405 sscanf(ptr, "%04hx-%04hx", &start, &end);
406 size = end - start + 1;
418 pci_dev->mem_resource[0].addr = (void *)(uintptr_t)(uint32_t)start;
419 pci_dev->mem_resource[0].len = (uint64_t)size;
421 "PCI Port IO found start=0x%x with size=0x%x",
424 /* can't support lsc interrupt without uio */
425 pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC;
430 /* Extract I/O port numbers from sysfs */
432 legacy_virtio_resource_init(struct rte_pci_device *pci_dev)
434 if (virtio_resource_init_by_uio(pci_dev) == 0)
437 return virtio_resource_init_by_ioports(pci_dev);
442 legacy_virtio_has_msix(const struct rte_pci_addr *loc __rte_unused)
444 /* nic_uio does not enable interrupts, return 0 (false). */
449 legacy_virtio_resource_init(struct rte_pci_device *pci_dev __rte_unused)
451 /* no setup required */
456 static const struct virtio_pci_ops legacy_ops = {
457 .read_dev_cfg = legacy_read_dev_config,
458 .write_dev_cfg = legacy_write_dev_config,
459 .reset = legacy_reset,
460 .get_status = legacy_get_status,
461 .set_status = legacy_set_status,
462 .get_features = legacy_get_features,
463 .set_features = legacy_set_features,
464 .get_isr = legacy_get_isr,
465 .set_config_irq = legacy_set_config_irq,
466 .get_queue_num = legacy_get_queue_num,
467 .setup_queue = legacy_setup_queue,
468 .del_queue = legacy_del_queue,
469 .notify_queue = legacy_notify_queue,
473 static inline uint8_t
474 io_read8(uint8_t *addr)
476 return *(volatile uint8_t *)addr;
480 io_write8(uint8_t val, uint8_t *addr)
482 *(volatile uint8_t *)addr = val;
485 static inline uint16_t
486 io_read16(uint16_t *addr)
488 return *(volatile uint16_t *)addr;
492 io_write16(uint16_t val, uint16_t *addr)
494 *(volatile uint16_t *)addr = val;
497 static inline uint32_t
498 io_read32(uint32_t *addr)
500 return *(volatile uint32_t *)addr;
504 io_write32(uint32_t val, uint32_t *addr)
506 *(volatile uint32_t *)addr = val;
510 io_write64_twopart(uint64_t val, uint32_t *lo, uint32_t *hi)
512 io_write32(val & ((1ULL << 32) - 1), lo);
513 io_write32(val >> 32, hi);
517 modern_read_dev_config(struct virtio_hw *hw, size_t offset,
518 void *dst, int length)
522 uint8_t old_gen, new_gen;
525 old_gen = io_read8(&hw->common_cfg->config_generation);
528 for (i = 0; i < length; i++)
529 *p++ = io_read8((uint8_t *)hw->dev_cfg + offset + i);
531 new_gen = io_read8(&hw->common_cfg->config_generation);
532 } while (old_gen != new_gen);
536 modern_write_dev_config(struct virtio_hw *hw, size_t offset,
537 const void *src, int length)
540 const uint8_t *p = src;
542 for (i = 0; i < length; i++)
543 io_write8(*p++, (uint8_t *)hw->dev_cfg + offset + i);
547 modern_get_features(struct virtio_hw *hw)
549 uint32_t features_lo, features_hi;
551 io_write32(0, &hw->common_cfg->device_feature_select);
552 features_lo = io_read32(&hw->common_cfg->device_feature);
554 io_write32(1, &hw->common_cfg->device_feature_select);
555 features_hi = io_read32(&hw->common_cfg->device_feature);
557 return ((uint64_t)features_hi << 32) | features_lo;
561 modern_set_features(struct virtio_hw *hw, uint64_t features)
563 io_write32(0, &hw->common_cfg->guest_feature_select);
564 io_write32(features & ((1ULL << 32) - 1),
565 &hw->common_cfg->guest_feature);
567 io_write32(1, &hw->common_cfg->guest_feature_select);
568 io_write32(features >> 32,
569 &hw->common_cfg->guest_feature);
573 modern_get_status(struct virtio_hw *hw)
575 return io_read8(&hw->common_cfg->device_status);
579 modern_set_status(struct virtio_hw *hw, uint8_t status)
581 io_write8(status, &hw->common_cfg->device_status);
585 modern_reset(struct virtio_hw *hw)
587 modern_set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
588 modern_get_status(hw);
592 modern_get_isr(struct virtio_hw *hw)
594 return io_read8(hw->isr);
598 modern_set_config_irq(struct virtio_hw *hw, uint16_t vec)
600 io_write16(vec, &hw->common_cfg->msix_config);
601 return io_read16(&hw->common_cfg->msix_config);
605 modern_get_queue_num(struct virtio_hw *hw, uint16_t queue_id)
607 io_write16(queue_id, &hw->common_cfg->queue_select);
608 return io_read16(&hw->common_cfg->queue_size);
612 modern_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
614 uint64_t desc_addr, avail_addr, used_addr;
617 desc_addr = vq->mz->phys_addr;
618 avail_addr = desc_addr + vq->vq_nentries * sizeof(struct vring_desc);
619 used_addr = RTE_ALIGN_CEIL(avail_addr + offsetof(struct vring_avail,
620 ring[vq->vq_nentries]),
621 VIRTIO_PCI_VRING_ALIGN);
623 io_write16(vq->vq_queue_index, &hw->common_cfg->queue_select);
625 io_write64_twopart(desc_addr, &hw->common_cfg->queue_desc_lo,
626 &hw->common_cfg->queue_desc_hi);
627 io_write64_twopart(avail_addr, &hw->common_cfg->queue_avail_lo,
628 &hw->common_cfg->queue_avail_hi);
629 io_write64_twopart(used_addr, &hw->common_cfg->queue_used_lo,
630 &hw->common_cfg->queue_used_hi);
632 notify_off = io_read16(&hw->common_cfg->queue_notify_off);
633 vq->notify_addr = (void *)((uint8_t *)hw->notify_base +
634 notify_off * hw->notify_off_multiplier);
636 io_write16(1, &hw->common_cfg->queue_enable);
638 PMD_INIT_LOG(DEBUG, "queue %u addresses:", vq->vq_queue_index);
639 PMD_INIT_LOG(DEBUG, "\t desc_addr: %" PRIx64, desc_addr);
640 PMD_INIT_LOG(DEBUG, "\t aval_addr: %" PRIx64, avail_addr);
641 PMD_INIT_LOG(DEBUG, "\t used_addr: %" PRIx64, used_addr);
642 PMD_INIT_LOG(DEBUG, "\t notify addr: %p (notify offset: %u)",
643 vq->notify_addr, notify_off);
647 modern_del_queue(struct virtio_hw *hw, struct virtqueue *vq)
649 io_write16(vq->vq_queue_index, &hw->common_cfg->queue_select);
651 io_write64_twopart(0, &hw->common_cfg->queue_desc_lo,
652 &hw->common_cfg->queue_desc_hi);
653 io_write64_twopart(0, &hw->common_cfg->queue_avail_lo,
654 &hw->common_cfg->queue_avail_hi);
655 io_write64_twopart(0, &hw->common_cfg->queue_used_lo,
656 &hw->common_cfg->queue_used_hi);
658 io_write16(0, &hw->common_cfg->queue_enable);
662 modern_notify_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq)
664 io_write16(1, vq->notify_addr);
667 static const struct virtio_pci_ops modern_ops = {
668 .read_dev_cfg = modern_read_dev_config,
669 .write_dev_cfg = modern_write_dev_config,
670 .reset = modern_reset,
671 .get_status = modern_get_status,
672 .set_status = modern_set_status,
673 .get_features = modern_get_features,
674 .set_features = modern_set_features,
675 .get_isr = modern_get_isr,
676 .set_config_irq = modern_set_config_irq,
677 .get_queue_num = modern_get_queue_num,
678 .setup_queue = modern_setup_queue,
679 .del_queue = modern_del_queue,
680 .notify_queue = modern_notify_queue,
685 vtpci_read_dev_config(struct virtio_hw *hw, size_t offset,
686 void *dst, int length)
688 hw->vtpci_ops->read_dev_cfg(hw, offset, dst, length);
692 vtpci_write_dev_config(struct virtio_hw *hw, size_t offset,
693 const void *src, int length)
695 hw->vtpci_ops->write_dev_cfg(hw, offset, src, length);
699 vtpci_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
704 * Limit negotiated features to what the driver, virtqueue, and
707 features = host_features & hw->guest_features;
708 hw->vtpci_ops->set_features(hw, features);
714 vtpci_reset(struct virtio_hw *hw)
716 hw->vtpci_ops->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
717 /* flush status write */
718 hw->vtpci_ops->get_status(hw);
722 vtpci_reinit_complete(struct virtio_hw *hw)
724 vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK);
728 vtpci_set_status(struct virtio_hw *hw, uint8_t status)
730 if (status != VIRTIO_CONFIG_STATUS_RESET)
731 status |= hw->vtpci_ops->get_status(hw);
733 hw->vtpci_ops->set_status(hw, status);
737 vtpci_get_status(struct virtio_hw *hw)
739 return hw->vtpci_ops->get_status(hw);
743 vtpci_isr(struct virtio_hw *hw)
745 return hw->vtpci_ops->get_isr(hw);
749 /* Enable one vector (0) for Link State Intrerrupt */
751 vtpci_irq_config(struct virtio_hw *hw, uint16_t vec)
753 return hw->vtpci_ops->set_config_irq(hw, vec);
757 get_cfg_addr(struct rte_pci_device *dev, struct virtio_pci_cap *cap)
759 uint8_t bar = cap->bar;
760 uint32_t length = cap->length;
761 uint32_t offset = cap->offset;
765 PMD_INIT_LOG(ERR, "invalid bar: %u", bar);
769 if (offset + length < offset) {
770 PMD_INIT_LOG(ERR, "offset(%u) + length(%u) overflows",
775 if (offset + length > dev->mem_resource[bar].len) {
777 "invalid cap: overflows bar space: %u > %" PRIu64,
778 offset + length, dev->mem_resource[bar].len);
782 base = dev->mem_resource[bar].addr;
784 PMD_INIT_LOG(ERR, "bar %u base addr is NULL", bar);
788 return base + offset;
792 virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
795 struct virtio_pci_cap cap;
798 if (rte_eal_pci_map_device(dev) < 0) {
799 PMD_INIT_LOG(DEBUG, "failed to map pci device!");
803 ret = rte_eal_pci_read_config(dev, &pos, 1, PCI_CAPABILITY_LIST);
805 PMD_INIT_LOG(DEBUG, "failed to read pci capability list");
810 ret = rte_eal_pci_read_config(dev, &cap, sizeof(cap), pos);
813 "failed to read pci cap at pos: %x", pos);
817 if (cap.cap_vndr != PCI_CAP_ID_VNDR) {
819 "[%2x] skipping non VNDR cap id: %02x",
825 "[%2x] cfg type: %u, bar: %u, offset: %04x, len: %u",
826 pos, cap.cfg_type, cap.bar, cap.offset, cap.length);
828 switch (cap.cfg_type) {
829 case VIRTIO_PCI_CAP_COMMON_CFG:
830 hw->common_cfg = get_cfg_addr(dev, &cap);
832 case VIRTIO_PCI_CAP_NOTIFY_CFG:
833 rte_eal_pci_read_config(dev, &hw->notify_off_multiplier,
834 4, pos + sizeof(cap));
835 hw->notify_base = get_cfg_addr(dev, &cap);
837 case VIRTIO_PCI_CAP_DEVICE_CFG:
838 hw->dev_cfg = get_cfg_addr(dev, &cap);
840 case VIRTIO_PCI_CAP_ISR_CFG:
841 hw->isr = get_cfg_addr(dev, &cap);
849 if (hw->common_cfg == NULL || hw->notify_base == NULL ||
850 hw->dev_cfg == NULL || hw->isr == NULL) {
851 PMD_INIT_LOG(INFO, "no modern virtio pci device found.");
855 PMD_INIT_LOG(INFO, "found modern virtio pci device.");
857 PMD_INIT_LOG(DEBUG, "common cfg mapped at: %p", hw->common_cfg);
858 PMD_INIT_LOG(DEBUG, "device cfg mapped at: %p", hw->dev_cfg);
859 PMD_INIT_LOG(DEBUG, "isr cfg mapped at: %p", hw->isr);
860 PMD_INIT_LOG(DEBUG, "notify base: %p, notify off multiplier: %u",
861 hw->notify_base, hw->notify_off_multiplier);
867 vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
872 * Try if we can succeed reading virtio pci caps, which exists
873 * only on modern pci device. If failed, we fallback to legacy
876 if (virtio_read_caps(dev, hw) == 0) {
877 PMD_INIT_LOG(INFO, "modern virtio pci detected.");
878 hw->vtpci_ops = &modern_ops;
880 dev->driver->drv_flags |= RTE_PCI_DRV_INTR_LSC;
884 PMD_INIT_LOG(INFO, "trying with legacy virtio pci.");
885 if (legacy_virtio_resource_init(dev) < 0)
888 hw->vtpci_ops = &legacy_ops;
889 hw->use_msix = legacy_virtio_has_msix(&dev->addr);
890 hw->io_base = (uint32_t)(uintptr_t)dev->mem_resource[0].addr;