net/ena: fix Tx SQ free space assessment
[dpdk.git] / drivers / net / virtio / virtio_pci.c
index e0d8a53..d27e9eb 100644 (file)
@@ -28,8 +28,8 @@
  * The remaining space is defined by each driver as the per-driver
  * configuration space.
  */
-#define VIRTIO_PCI_CONFIG(hw) \
-               (((hw)->use_msix == VIRTIO_MSIX_ENABLED) ? 24 : 20)
+#define VIRTIO_PCI_CONFIG(dev) \
+               (((dev)->msix_status == VIRTIO_MSIX_ENABLED) ? 24 : 20)
 
 
 struct virtio_pci_internal {
@@ -121,6 +121,7 @@ static void
 legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
                       void *dst, int length)
 {
+       struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 #ifdef RTE_ARCH_PPC_64
        int size;
 
@@ -128,17 +129,17 @@ legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
                if (length >= 4) {
                        size = 4;
                        rte_pci_ioport_read(VTPCI_IO(hw), dst, size,
-                               VIRTIO_PCI_CONFIG(hw) + offset);
+                               VIRTIO_PCI_CONFIG(dev) + offset);
                        *(uint32_t *)dst = rte_be_to_cpu_32(*(uint32_t *)dst);
                } else if (length >= 2) {
                        size = 2;
                        rte_pci_ioport_read(VTPCI_IO(hw), dst, size,
-                               VIRTIO_PCI_CONFIG(hw) + offset);
+                               VIRTIO_PCI_CONFIG(dev) + offset);
                        *(uint16_t *)dst = rte_be_to_cpu_16(*(uint16_t *)dst);
                } else {
                        size = 1;
                        rte_pci_ioport_read(VTPCI_IO(hw), dst, size,
-                               VIRTIO_PCI_CONFIG(hw) + offset);
+                               VIRTIO_PCI_CONFIG(dev) + offset);
                }
 
                dst = (char *)dst + size;
@@ -147,7 +148,7 @@ legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
        }
 #else
        rte_pci_ioport_read(VTPCI_IO(hw), dst, length,
-               VIRTIO_PCI_CONFIG(hw) + offset);
+               VIRTIO_PCI_CONFIG(dev) + offset);
 #endif
 }
 
@@ -155,6 +156,7 @@ static void
 legacy_write_dev_config(struct virtio_hw *hw, size_t offset,
                        const void *src, int length)
 {
+       struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 #ifdef RTE_ARCH_PPC_64
        union {
                uint32_t u32;
@@ -167,16 +169,16 @@ legacy_write_dev_config(struct virtio_hw *hw, size_t offset,
                        size = 4;
                        tmp.u32 = rte_cpu_to_be_32(*(const uint32_t *)src);
                        rte_pci_ioport_write(VTPCI_IO(hw), &tmp.u32, size,
-                               VIRTIO_PCI_CONFIG(hw) + offset);
+                               VIRTIO_PCI_CONFIG(dev) + offset);
                } else if (length >= 2) {
                        size = 2;
                        tmp.u16 = rte_cpu_to_be_16(*(const uint16_t *)src);
                        rte_pci_ioport_write(VTPCI_IO(hw), &tmp.u16, size,
-                               VIRTIO_PCI_CONFIG(hw) + offset);
+                               VIRTIO_PCI_CONFIG(dev) + offset);
                } else {
                        size = 1;
                        rte_pci_ioport_write(VTPCI_IO(hw), src, size,
-                               VIRTIO_PCI_CONFIG(hw) + offset);
+                               VIRTIO_PCI_CONFIG(dev) + offset);
                }
 
                src = (const char *)src + size;
@@ -185,7 +187,7 @@ legacy_write_dev_config(struct virtio_hw *hw, size_t offset,
        }
 #else
        rte_pci_ioport_write(VTPCI_IO(hw), src, length,
-               VIRTIO_PCI_CONFIG(hw) + offset);
+               VIRTIO_PCI_CONFIG(dev) + offset);
 #endif
 }
 
@@ -311,7 +313,8 @@ legacy_intr_detect(struct virtio_hw *hw)
 {
        struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 
-       hw->use_msix = vtpci_msix_detect(dev->pci_dev);
+       dev->msix_status = vtpci_msix_detect(dev->pci_dev);
+       hw->intr_lsc = !!dev->msix_status;
 }
 
 static int
@@ -415,7 +418,7 @@ modern_set_features(struct virtio_hw *hw, uint64_t features)
 static int
 modern_features_ok(struct virtio_hw *hw)
 {
-       if (!vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
+       if (!virtio_with_feature(hw, VIRTIO_F_VERSION_1)) {
                PMD_INIT_LOG(ERR, "Version 1+ required with modern devices\n");
                return -1;
        }
@@ -489,7 +492,7 @@ modern_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
        avail_addr = desc_addr + vq->vq_nentries * sizeof(struct vring_desc);
        used_addr = RTE_ALIGN_CEIL(avail_addr + offsetof(struct vring_avail,
                                                         ring[vq->vq_nentries]),
-                                  VIRTIO_PCI_VRING_ALIGN);
+                                  VIRTIO_VRING_ALIGN);
 
        rte_write16(vq->vq_queue_index, &dev->common_cfg->queue_select);
 
@@ -538,12 +541,12 @@ modern_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
 {
        uint32_t notify_data;
 
-       if (!vtpci_with_feature(hw, VIRTIO_F_NOTIFICATION_DATA)) {
+       if (!virtio_with_feature(hw, VIRTIO_F_NOTIFICATION_DATA)) {
                rte_write16(vq->vq_queue_index, vq->notify_addr);
                return;
        }
 
-       if (vtpci_with_feature(hw, VIRTIO_F_RING_PACKED)) {
+       if (virtio_with_packed_queue(hw)) {
                /*
                 * Bit[0:15]: vq queue index
                 * Bit[16:30]: avail index
@@ -571,7 +574,8 @@ modern_intr_detect(struct virtio_hw *hw)
 {
        struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 
-       hw->use_msix = vtpci_msix_detect(dev->pci_dev);
+       dev->msix_status = vtpci_msix_detect(dev->pci_dev);
+       hw->intr_lsc = !!dev->msix_status;
 }
 
 static int
@@ -603,71 +607,6 @@ const struct virtio_ops modern_ops = {
        .dev_close      = modern_dev_close,
 };
 
-
-void
-vtpci_read_dev_config(struct virtio_hw *hw, size_t offset,
-                     void *dst, int length)
-{
-       VIRTIO_OPS(hw)->read_dev_cfg(hw, offset, dst, length);
-}
-
-void
-vtpci_write_dev_config(struct virtio_hw *hw, size_t offset,
-                      const void *src, int length)
-{
-       VIRTIO_OPS(hw)->write_dev_cfg(hw, offset, src, length);
-}
-
-uint64_t
-vtpci_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
-{
-       uint64_t features;
-
-       /*
-        * Limit negotiated features to what the driver, virtqueue, and
-        * host all support.
-        */
-       features = host_features & hw->guest_features;
-       VIRTIO_OPS(hw)->set_features(hw, features);
-
-       return features;
-}
-
-void
-vtpci_reset(struct virtio_hw *hw)
-{
-       VIRTIO_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
-       /* flush status write */
-       VIRTIO_OPS(hw)->get_status(hw);
-}
-
-void
-vtpci_reinit_complete(struct virtio_hw *hw)
-{
-       vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK);
-}
-
-void
-vtpci_set_status(struct virtio_hw *hw, uint8_t status)
-{
-       if (status != VIRTIO_CONFIG_STATUS_RESET)
-               status |= VIRTIO_OPS(hw)->get_status(hw);
-
-       VIRTIO_OPS(hw)->set_status(hw, status);
-}
-
-uint8_t
-vtpci_get_status(struct virtio_hw *hw)
-{
-       return VIRTIO_OPS(hw)->get_status(hw);
-}
-
-uint8_t
-vtpci_isr(struct virtio_hw *hw)
-{
-       return VIRTIO_OPS(hw)->get_isr(hw);
-}
-
 static void *
 get_cfg_addr(struct rte_pci_device *dev, struct virtio_pci_cap *cap)
 {
@@ -750,9 +689,9 @@ virtio_read_caps(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
                        }
 
                        if (flags & PCI_MSIX_ENABLE)
-                               hw->use_msix = VIRTIO_MSIX_ENABLED;
+                               dev->msix_status = VIRTIO_MSIX_ENABLED;
                        else
-                               hw->use_msix = VIRTIO_MSIX_DISABLED;
+                               dev->msix_status = VIRTIO_MSIX_DISABLED;
                }
 
                if (cap.cap_vndr != PCI_CAP_ID_VNDR) {