drivers: use PCI registration macro
[dpdk.git] / drivers / net / ena / ena_ethdev.c
index e2716b5..85c5086 100644 (file)
@@ -38,6 +38,7 @@
 #include <rte_dev.h>
 #include <rte_errno.h>
 #include <rte_version.h>
+#include <rte_eal_memconfig.h>
 
 #include "ena_ethdev.h"
 #include "ena_logs.h"
@@ -168,10 +169,9 @@ static const struct ena_stats ena_stats_ena_com_strings[] = {
 #define PCI_DEVICE_ID_ENA_LLQ_VF       0xEC21
 
 static struct rte_pci_id pci_id_ena_map[] = {
-#define RTE_PCI_DEV_ID_DECL_ENA(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
-       RTE_PCI_DEV_ID_DECL_ENA(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_VF)
-       RTE_PCI_DEV_ID_DECL_ENA(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_LLQ_VF)
-       {.device_id = 0},
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_VF) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_AMAZON, PCI_DEVICE_ID_ENA_LLQ_VF) },
+       { .device_id = 0 },
 };
 
 static int ena_device_init(struct ena_com_dev *ena_dev,
@@ -232,6 +232,18 @@ static struct eth_dev_ops ena_dev_ops = {
        .reta_query           = ena_rss_reta_query,
 };
 
+#define NUMA_NO_NODE   SOCKET_ID_ANY
+
+static inline int ena_cpu_to_node(int cpu)
+{
+       struct rte_config *config = rte_eal_get_configuration();
+
+       if (likely(cpu < RTE_MAX_MEMZONE))
+               return config->mem_config->memzone[cpu].socket_id;
+
+       return NUMA_NO_NODE;
+}
+
 static inline void ena_rx_mbuf_prepare(struct rte_mbuf *mbuf,
                                       struct ena_com_rx_ctx *ena_rx_ctx)
 {
@@ -338,7 +350,8 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev)
        host_info->driver_version =
                (DRV_MODULE_VER_MAJOR) |
                (DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |
-               (DRV_MODULE_VER_SUBMINOR << ENA_ADMIN_HOST_INFO_SUB_MINOR_SHIFT);
+               (DRV_MODULE_VER_SUBMINOR <<
+                       ENA_ADMIN_HOST_INFO_SUB_MINOR_SHIFT);
 
        rc = ena_com_set_host_attributes(ena_dev);
        if (rc) {
@@ -961,6 +974,7 @@ static int ena_tx_queue_setup(struct rte_eth_dev *dev,
        ctx.msix_vector = -1; /* admin interrupts not used */
        ctx.mem_queue_type = ena_dev->tx_mem_queue_type;
        ctx.queue_size = adapter->tx_ring_size;
+       ctx.numa_node = ena_cpu_to_node(queue_idx);
 
        rc = ena_com_create_io_queue(ena_dev, &ctx);
        if (rc) {
@@ -1054,6 +1068,7 @@ static int ena_rx_queue_setup(struct rte_eth_dev *dev,
        ctx.mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
        ctx.msix_vector = -1; /* admin interrupts not used */
        ctx.queue_size = adapter->rx_ring_size;
+       ctx.numa_node = ena_cpu_to_node(queue_idx);
 
        rc = ena_com_create_io_queue(ena_dev, &ctx);
        if (rc)
@@ -1139,10 +1154,14 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)
                next_to_use = ENA_RX_RING_IDX_NEXT(next_to_use, ring_size);
        }
 
-       rte_wmb();
-       rxq->next_to_use = next_to_use;
-       /* let HW know that it can fill buffers with data */
-       ena_com_write_sq_doorbell(rxq->ena_com_io_sq);
+       /* When we submitted free recources to device... */
+       if (i > 0) {
+               /* ...let HW know that it can fill buffers with data */
+               rte_wmb();
+               ena_com_write_sq_doorbell(rxq->ena_com_io_sq);
+
+               rxq->next_to_use = next_to_use;
+       }
 
        return i;
 }
@@ -1151,6 +1170,7 @@ static int ena_device_init(struct ena_com_dev *ena_dev,
                           struct ena_com_dev_get_features_ctx *get_feat_ctx)
 {
        int rc;
+       bool readless_supported;
 
        /* Initialize mmio registers */
        rc = ena_com_mmio_reg_read_request_init(ena_dev);
@@ -1159,6 +1179,14 @@ static int ena_device_init(struct ena_com_dev *ena_dev,
                return rc;
        }
 
+       /* The PCIe configuration space revision id indicate if mmio reg
+        * read is disabled.
+        */
+       readless_supported =
+               !(((struct rte_pci_device *)ena_dev->dmadev)->id.class_id
+                              & ENA_MMIO_DISABLE_REG_READ);
+       ena_com_set_mmio_read_mode(ena_dev, readless_supported);
+
        /* reset device */
        rc = ena_com_dev_reset(ena_dev);
        if (rc) {
@@ -1539,7 +1567,7 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
        struct ena_tx_buffer *tx_info;
        struct ena_com_buf *ebuf;
        uint16_t rc, req_id, total_tx_descs = 0;
-       int sent_idx = 0;
+       uint16_t sent_idx = 0;
        int nb_hw_desc;
 
        /* Check adapter state */
@@ -1618,9 +1646,14 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                next_to_use = ENA_TX_RING_IDX_NEXT(next_to_use, ring_size);
        }
 
-       /* Let HW do it's best :-) */
-       rte_wmb();
-       ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
+       /* If there are ready packets to be xmitted... */
+       if (sent_idx > 0) {
+               /* ...let HW do its best :-) */
+               rte_wmb();
+               ena_com_write_sq_doorbell(tx_ring->ena_com_io_sq);
+
+               tx_ring->next_to_use = next_to_use;
+       }
 
        /* Clear complete packets  */
        while (ena_com_tx_comp_req_id_get(tx_ring->ena_com_io_cq, &req_id) >= 0) {
@@ -1643,34 +1676,25 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                        break;
        }
 
-       /* acknowledge completion of sent packets */
-       ena_com_comp_ack(tx_ring->ena_com_io_sq, total_tx_descs);
-       tx_ring->next_to_use = next_to_use;
+       if (total_tx_descs > 0) {
+               /* acknowledge completion of sent packets */
+               ena_com_comp_ack(tx_ring->ena_com_io_sq, total_tx_descs);
+       }
+
        return sent_idx;
 }
 
 static struct eth_driver rte_ena_pmd = {
-       {
+       .pci_drv = {
                .name = "rte_ena_pmd",
                .id_table = pci_id_ena_map,
                .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+               .probe = rte_eth_dev_pci_probe,
+               .remove = rte_eth_dev_pci_remove,
        },
        .eth_dev_init = eth_ena_dev_init,
        .dev_private_size = sizeof(struct ena_adapter),
 };
 
-static int
-rte_ena_pmd_init(const char *name __rte_unused,
-                const char *params __rte_unused)
-{
-       rte_eth_driver_register(&rte_ena_pmd);
-       return 0;
-};
-
-struct rte_driver ena_pmd_drv = {
-       .type = PMD_PDEV,
-       .init = rte_ena_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(ena_pmd_drv, ena);
-DRIVER_REGISTER_PCI_TABLE(ena, pci_id_ena_map);
+DRIVER_REGISTER_PCI(net_ena, rte_ena_pmd.pci_drv);
+DRIVER_REGISTER_PCI_TABLE(net_ena, pci_id_ena_map);