]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - drivers/net/ethernet/amazon/ena/ena_netdev.c
net: ena: allow the driver to work with small number of msix vectors
[mirror_ubuntu-zesty-kernel.git] / drivers / net / ethernet / amazon / ena / ena_netdev.c
index fca8d51d0f91ee707c7b684dac66d6f9782f8d46..5c05db40936883a5f9c0a91d4b230730a17813d2 100644 (file)
@@ -87,6 +87,7 @@ static void ena_tx_timeout(struct net_device *dev)
        if (test_and_set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))
                return;
 
+       adapter->reset_reason = ENA_REGS_RESET_OS_NETDEV_WD;
        u64_stats_update_begin(&adapter->syncp);
        adapter->dev_stats.tx_timeout++;
        u64_stats_update_end(&adapter->syncp);
@@ -133,7 +134,7 @@ static int ena_init_rx_cpu_rmap(struct ena_adapter *adapter)
                int irq_idx = ENA_IO_IRQ_IDX(i);
 
                rc = irq_cpu_rmap_add(adapter->netdev->rx_cpu_rmap,
-                                     adapter->msix_entries[irq_idx].vector);
+                                     pci_irq_vector(adapter->pdev, irq_idx));
                if (rc) {
                        free_irq_cpu_rmap(adapter->netdev->rx_cpu_rmap);
                        adapter->netdev->rx_cpu_rmap = NULL;
@@ -190,6 +191,7 @@ static void ena_init_io_rings(struct ena_adapter *adapter)
                rxr->sgl_size = adapter->max_rx_sgl_size;
                rxr->smoothed_interval =
                        ena_com_get_nonadaptive_moderation_interval_rx(ena_dev);
+               rxr->empty_rx_queue = 0;
        }
 }
 
@@ -302,6 +304,24 @@ static void ena_free_all_io_tx_resources(struct ena_adapter *adapter)
                ena_free_tx_resources(adapter, i);
 }
 
+static inline int validate_rx_req_id(struct ena_ring *rx_ring, u16 req_id)
+{
+       if (likely(req_id < rx_ring->ring_size))
+               return 0;
+
+       netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
+                 "Invalid rx req_id: %hu\n", req_id);
+
+       u64_stats_update_begin(&rx_ring->syncp);
+       rx_ring->rx_stats.bad_req_id++;
+       u64_stats_update_end(&rx_ring->syncp);
+
+       /* Trigger device reset */
+       rx_ring->adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID;
+       set_bit(ENA_FLAG_TRIGGER_RESET, &rx_ring->adapter->flags);
+       return -EFAULT;
+}
+
 /* ena_setup_rx_resources - allocate I/O Rx resources (Descriptors)
  * @adapter: network interface device structure
  * @qid: queue index
@@ -313,7 +333,7 @@ static int ena_setup_rx_resources(struct ena_adapter *adapter,
 {
        struct ena_ring *rx_ring = &adapter->rx_ring[qid];
        struct ena_irq *ena_irq = &adapter->irq_tbl[ENA_IO_IRQ_IDX(qid)];
-       int size, node;
+       int size, node, i;
 
        if (rx_ring->rx_buffer_info) {
                netif_err(adapter, ifup, adapter->netdev,
@@ -334,6 +354,20 @@ static int ena_setup_rx_resources(struct ena_adapter *adapter,
                        return -ENOMEM;
        }
 
+       size = sizeof(u16) * rx_ring->ring_size;
+       rx_ring->free_rx_ids = vzalloc_node(size, node);
+       if (!rx_ring->free_rx_ids) {
+               rx_ring->free_rx_ids = vzalloc(size);
+               if (!rx_ring->free_rx_ids) {
+                       vfree(rx_ring->rx_buffer_info);
+                       return -ENOMEM;
+               }
+       }
+
+       /* Req id ring for receiving RX pkts out of order */
+       for (i = 0; i < rx_ring->ring_size; i++)
+               rx_ring->free_rx_ids[i] = i;
+
        /* Reset rx statistics */
        memset(&rx_ring->rx_stats, 0x0, sizeof(rx_ring->rx_stats));
 
@@ -357,6 +391,9 @@ static void ena_free_rx_resources(struct ena_adapter *adapter,
 
        vfree(rx_ring->rx_buffer_info);
        rx_ring->rx_buffer_info = NULL;
+
+       vfree(rx_ring->free_rx_ids);
+       rx_ring->free_rx_ids = NULL;
 }
 
 /* ena_setup_all_rx_resources - allocate I/O Rx queues resources for all queues
@@ -462,15 +499,22 @@ static void ena_free_rx_page(struct ena_ring *rx_ring,
 
 static int ena_refill_rx_bufs(struct ena_ring *rx_ring, u32 num)
 {
-       u16 next_to_use;
+       u16 next_to_use, req_id;
        u32 i;
        int rc;
 
        next_to_use = rx_ring->next_to_use;
 
        for (i = 0; i < num; i++) {
-               struct ena_rx_buffer *rx_info =
-                       &rx_ring->rx_buffer_info[next_to_use];
+               struct ena_rx_buffer *rx_info;
+
+               req_id = rx_ring->free_rx_ids[next_to_use];
+               rc = validate_rx_req_id(rx_ring, req_id);
+               if (unlikely(rc < 0))
+                       break;
+
+               rx_info = &rx_ring->rx_buffer_info[req_id];
+
 
                rc = ena_alloc_rx_page(rx_ring, rx_info,
                                       __GFP_COLD | GFP_ATOMIC | __GFP_COMP);
@@ -482,7 +526,7 @@ static int ena_refill_rx_bufs(struct ena_ring *rx_ring, u32 num)
                }
                rc = ena_com_add_single_rx_desc(rx_ring->ena_com_io_sq,
                                                &rx_info->ena_buf,
-                                               next_to_use);
+                                               req_id);
                if (unlikely(rc)) {
                        netif_warn(rx_ring->adapter, rx_status, rx_ring->netdev,
                                   "failed to add buffer for rx queue %d\n",
@@ -669,6 +713,7 @@ static int validate_tx_req_id(struct ena_ring *tx_ring, u16 req_id)
        u64_stats_update_end(&tx_ring->syncp);
 
        /* Trigger device reset */
+       tx_ring->adapter->reset_reason = ENA_REGS_RESET_INV_TX_REQ_ID;
        set_bit(ENA_FLAG_TRIGGER_RESET, &tx_ring->adapter->flags);
        return -EFAULT;
 }
@@ -786,13 +831,14 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
                                  u16 *next_to_clean)
 {
        struct sk_buff *skb;
-       struct ena_rx_buffer *rx_info =
-               &rx_ring->rx_buffer_info[*next_to_clean];
-       u32 len;
-       u32 buf = 0;
+       struct ena_rx_buffer *rx_info;
+       u16 len, req_id, buf = 0;
        void *va;
 
-       len = ena_bufs[0].len;
+       len = ena_bufs[buf].len;
+       req_id = ena_bufs[buf].req_id;
+       rx_info = &rx_ring->rx_buffer_info[req_id];
+
        if (unlikely(!rx_info->page)) {
                netif_err(rx_ring->adapter, rx_err, rx_ring->netdev,
                          "Page is NULL\n");
@@ -864,13 +910,18 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
                          skb->len, skb->data_len);
 
                rx_info->page = NULL;
+
+               rx_ring->free_rx_ids[*next_to_clean] = req_id;
                *next_to_clean =
                        ENA_RX_RING_IDX_NEXT(*next_to_clean,
                                             rx_ring->ring_size);
                if (likely(--descs == 0))
                        break;
-               rx_info = &rx_ring->rx_buffer_info[*next_to_clean];
-               len = ena_bufs[++buf].len;
+
+               buf++;
+               len = ena_bufs[buf].len;
+               req_id = ena_bufs[buf].req_id;
+               rx_info = &rx_ring->rx_buffer_info[req_id];
        } while (1);
 
        return skb;
@@ -971,6 +1022,7 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,
        int rc = 0;
        int total_len = 0;
        int rx_copybreak_pkt = 0;
+       int i;
 
        netif_dbg(rx_ring->adapter, rx_status, rx_ring->netdev,
                  "%s qid %d\n", __func__, rx_ring->qid);
@@ -1000,9 +1052,13 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,
 
                /* exit if we failed to retrieve a buffer */
                if (unlikely(!skb)) {
-                       next_to_clean = ENA_RX_RING_IDX_ADD(next_to_clean,
-                                                           ena_rx_ctx.descs,
-                                                           rx_ring->ring_size);
+                       for (i = 0; i < ena_rx_ctx.descs; i++) {
+                               rx_ring->free_tx_ids[next_to_clean] =
+                                       rx_ring->ena_bufs[i].req_id;
+                               next_to_clean =
+                                       ENA_RX_RING_IDX_NEXT(next_to_clean,
+                                                            rx_ring->ring_size);
+                       }
                        break;
                }
 
@@ -1054,6 +1110,7 @@ error:
        u64_stats_update_end(&rx_ring->syncp);
 
        /* Too many desc from the device. Trigger reset */
+       adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS;
        set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
 
        return 0;
@@ -1078,6 +1135,26 @@ inline void ena_adjust_intr_moderation(struct ena_ring *rx_ring,
        rx_ring->per_napi_bytes = 0;
 }
 
+static inline void ena_unmask_interrupt(struct ena_ring *tx_ring,
+                                       struct ena_ring *rx_ring)
+{
+       struct ena_eth_io_intr_reg intr_reg;
+
+       /* Update intr register: rx intr delay,
+        * tx intr delay and interrupt unmask
+        */
+       ena_com_update_intr_reg(&intr_reg,
+                               rx_ring->smoothed_interval,
+                               tx_ring->smoothed_interval,
+                               true);
+
+       /* It is a shared MSI-X.
+        * Tx and Rx CQ have pointer to it.
+        * So we use one of them to reach the intr reg
+        */
+       ena_com_unmask_intr(rx_ring->ena_com_io_cq, &intr_reg);
+}
+
 static inline void ena_update_ring_numa_node(struct ena_ring *tx_ring,
                                             struct ena_ring *rx_ring)
 {
@@ -1108,7 +1185,6 @@ static int ena_io_poll(struct napi_struct *napi, int budget)
 {
        struct ena_napi *ena_napi = container_of(napi, struct ena_napi, napi);
        struct ena_ring *tx_ring, *rx_ring;
-       struct ena_eth_io_intr_reg intr_reg;
 
        u32 tx_work_done;
        u32 rx_work_done;
@@ -1149,22 +1225,9 @@ static int ena_io_poll(struct napi_struct *napi, int budget)
                        if (ena_com_get_adaptive_moderation_enabled(rx_ring->ena_dev))
                                ena_adjust_intr_moderation(rx_ring, tx_ring);
 
-                       /* Update intr register: rx intr delay,
-                        * tx intr delay and interrupt unmask
-                        */
-                       ena_com_update_intr_reg(&intr_reg,
-                                               rx_ring->smoothed_interval,
-                                               tx_ring->smoothed_interval,
-                                               true);
-
-                       /* It is a shared MSI-X.
-                        * Tx and Rx CQ have pointer to it.
-                        * So we use one of them to reach the intr reg
-                        */
-                       ena_com_unmask_intr(rx_ring->ena_com_io_cq, &intr_reg);
+                       ena_unmask_interrupt(tx_ring, rx_ring);
                }
 
-
                ena_update_ring_numa_node(tx_ring, rx_ring);
 
                ret = rx_work_done;
@@ -1206,9 +1269,14 @@ static irqreturn_t ena_intr_msix_io(int irq, void *data)
        return IRQ_HANDLED;
 }
 
+/* Reserve a single MSI-X vector for management (admin + aenq).
+ * plus reserve one vector for each potential io queue.
+ * the number of potential io queues is the minimum of what the device
+ * supports and the number of vCPUs.
+ */
 static int ena_enable_msix(struct ena_adapter *adapter, int num_queues)
 {
-       int i, msix_vecs, rc;
+       int msix_vecs, irq_cnt;
 
        if (test_bit(ENA_FLAG_MSIX_ENABLED, &adapter->flags)) {
                netif_err(adapter, probe, adapter->netdev,
@@ -1222,32 +1290,27 @@ static int ena_enable_msix(struct ena_adapter *adapter, int num_queues)
        netif_dbg(adapter, probe, adapter->netdev,
                  "trying to enable MSI-X, vectors %d\n", msix_vecs);
 
-       adapter->msix_entries = vzalloc(msix_vecs * sizeof(struct msix_entry));
+       irq_cnt = pci_alloc_irq_vectors(adapter->pdev, ENA_MIN_MSIX_VEC,
+                                       msix_vecs, PCI_IRQ_MSIX);
 
-       if (!adapter->msix_entries)
-               return -ENOMEM;
-
-       for (i = 0; i < msix_vecs; i++)
-               adapter->msix_entries[i].entry = i;
-
-       rc = pci_enable_msix(adapter->pdev, adapter->msix_entries, msix_vecs);
-       if (rc != 0) {
+       if (irq_cnt < 0) {
                netif_err(adapter, probe, adapter->netdev,
-                         "Failed to enable MSI-X, vectors %d rc %d\n",
-                         msix_vecs, rc);
+                         "Failed to enable MSI-X. irq_cnt %d\n", irq_cnt);
                return -ENOSPC;
        }
 
-       netif_dbg(adapter, probe, adapter->netdev, "enable MSI-X, vectors %d\n",
-                 msix_vecs);
-
-       if (msix_vecs >= 1) {
-               if (ena_init_rx_cpu_rmap(adapter))
-                       netif_warn(adapter, probe, adapter->netdev,
-                                  "Failed to map IRQs to CPUs\n");
+       if (irq_cnt != msix_vecs) {
+               netif_notice(adapter, probe, adapter->netdev,
+                            "enable only %d MSI-X (out of %d), reduce the number of queues\n",
+                            irq_cnt, msix_vecs);
+               adapter->num_queues = irq_cnt - ENA_ADMIN_MSIX_VEC;
        }
 
-       adapter->msix_vecs = msix_vecs;
+       if (ena_init_rx_cpu_rmap(adapter))
+               netif_warn(adapter, probe, adapter->netdev,
+                          "Failed to map IRQs to CPUs\n");
+
+       adapter->msix_vecs = irq_cnt;
        set_bit(ENA_FLAG_MSIX_ENABLED, &adapter->flags);
 
        return 0;
@@ -1264,7 +1327,7 @@ static void ena_setup_mgmnt_intr(struct ena_adapter *adapter)
                ena_intr_msix_mgmnt;
        adapter->irq_tbl[ENA_MGMNT_IRQ_IDX].data = adapter;
        adapter->irq_tbl[ENA_MGMNT_IRQ_IDX].vector =
-               adapter->msix_entries[ENA_MGMNT_IRQ_IDX].vector;
+               pci_irq_vector(adapter->pdev, ENA_MGMNT_IRQ_IDX);
        cpu = cpumask_first(cpu_online_mask);
        adapter->irq_tbl[ENA_MGMNT_IRQ_IDX].cpu = cpu;
        cpumask_set_cpu(cpu,
@@ -1287,7 +1350,7 @@ static void ena_setup_io_intr(struct ena_adapter *adapter)
                adapter->irq_tbl[irq_idx].handler = ena_intr_msix_io;
                adapter->irq_tbl[irq_idx].data = &adapter->ena_napi[i];
                adapter->irq_tbl[irq_idx].vector =
-                       adapter->msix_entries[irq_idx].vector;
+                       pci_irq_vector(adapter->pdev, irq_idx);
                adapter->irq_tbl[irq_idx].cpu = cpu;
 
                cpumask_set_cpu(cpu,
@@ -1392,11 +1455,7 @@ static void ena_free_io_irq(struct ena_adapter *adapter)
 static void ena_disable_msix(struct ena_adapter *adapter)
 {
        if (test_and_clear_bit(ENA_FLAG_MSIX_ENABLED, &adapter->flags))
-               pci_disable_msix(adapter->pdev);
-
-       if (adapter->msix_entries)
-               vfree(adapter->msix_entries);
-       adapter->msix_entries = NULL;
+               pci_free_irq_vectors(adapter->pdev);
 }
 
 static void ena_disable_io_intr_sync(struct ena_adapter *adapter)
@@ -1469,7 +1528,7 @@ static int ena_rss_configure(struct ena_adapter *adapter)
        /* In case the RSS table wasn't initialized by probe */
        if (!ena_dev->rss.tbl_log_size) {
                rc = ena_rss_init_default(adapter);
-               if (rc && (rc != -EPERM)) {
+               if (rc && (rc != -EOPNOTSUPP)) {
                        netif_err(adapter, ifup, adapter->netdev,
                                  "Failed to init RSS rc: %d\n", rc);
                        return rc;
@@ -1478,17 +1537,17 @@ static int ena_rss_configure(struct ena_adapter *adapter)
 
        /* Set indirect table */
        rc = ena_com_indirect_table_set(ena_dev);
-       if (unlikely(rc && rc != -EPERM))
+       if (unlikely(rc && rc != -EOPNOTSUPP))
                return rc;
 
        /* Configure hash function (if supported) */
        rc = ena_com_set_hash_function(ena_dev);
-       if (unlikely(rc && (rc != -EPERM)))
+       if (unlikely(rc && (rc != -EOPNOTSUPP)))
                return rc;
 
        /* Configure hash inputs (if supported) */
        rc = ena_com_set_hash_ctrl(ena_dev);
-       if (unlikely(rc && (rc != -EPERM)))
+       if (unlikely(rc && (rc != -EOPNOTSUPP)))
                return rc;
 
        return 0;
@@ -1515,6 +1574,11 @@ static int ena_up_complete(struct ena_adapter *adapter)
 
        ena_napi_enable_all(adapter);
 
+       /* Enable completion queues interrupt */
+       for (i = 0; i < adapter->num_queues; i++)
+               ena_unmask_interrupt(&adapter->tx_ring[i],
+                                    &adapter->rx_ring[i]);
+
        /* schedule napi in case we had pending packets
         * from the last time we disable napi
         */
@@ -1562,6 +1626,7 @@ static int ena_create_io_tx_queue(struct ena_adapter *adapter, int qid)
                          "Failed to get TX queue handlers. TX queue num %d rc: %d\n",
                          qid, rc);
                ena_com_destroy_io_queue(ena_dev, ena_qid);
+               return rc;
        }
 
        ena_com_update_numa_node(tx_ring->ena_com_io_cq, ctx.numa_node);
@@ -1626,6 +1691,7 @@ static int ena_create_io_rx_queue(struct ena_adapter *adapter, int qid)
                          "Failed to get RX queue handlers. RX queue num %d rc: %d\n",
                          qid, rc);
                ena_com_destroy_io_queue(ena_dev, ena_qid);
+               return rc;
        }
 
        ena_com_update_numa_node(rx_ring->ena_com_io_cq, ctx.numa_node);
@@ -1736,7 +1802,7 @@ static void ena_down(struct ena_adapter *adapter)
        if (test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags)) {
                int rc;
 
-               rc = ena_com_dev_reset(adapter->ena_dev);
+               rc = ena_com_dev_reset(adapter->ena_dev, adapter->reset_reason);
                if (rc)
                        dev_err(&adapter->pdev->dev, "Device reset failed\n");
        }
@@ -2011,6 +2077,7 @@ static netdev_tx_t ena_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        tx_info->tx_descs = nb_hw_desc;
        tx_info->last_jiffies = jiffies;
+       tx_info->print_once = 0;
 
        tx_ring->next_to_use = ENA_TX_RING_IDX_NEXT(next_to_use,
                tx_ring->ring_size);
@@ -2159,7 +2226,7 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev)
 
        rc = ena_com_set_host_attributes(ena_dev);
        if (rc) {
-               if (rc == -EPERM)
+               if (rc == -EOPNOTSUPP)
                        pr_warn("Cannot set host attributes\n");
                else
                        pr_err("Cannot set host attributes\n");
@@ -2196,7 +2263,7 @@ static void ena_config_debug_area(struct ena_adapter *adapter)
 
        rc = ena_com_set_host_attributes(adapter->ena_dev);
        if (rc) {
-               if (rc == -EPERM)
+               if (rc == -EOPNOTSUPP)
                        netif_warn(adapter, drv, adapter->netdev,
                                   "Cannot set host attributes\n");
                else
@@ -2370,7 +2437,7 @@ static int ena_device_init(struct ena_com_dev *ena_dev, struct pci_dev *pdev,
        readless_supported = !(pdev->revision & ENA_MMIO_DISABLE_REG_READ);
        ena_com_set_mmio_read_mode(ena_dev, readless_supported);
 
-       rc = ena_com_dev_reset(ena_dev);
+       rc = ena_com_dev_reset(ena_dev, ENA_REGS_RESET_NORMAL);
        if (rc) {
                dev_err(dev, "Can not reset device\n");
                goto err_mmio_read_less;
@@ -2530,6 +2597,7 @@ static void ena_fw_reset_device(struct work_struct *work)
 
        ena_com_mmio_reg_read_request_destroy(ena_dev);
 
+       adapter->reset_reason = ENA_REGS_RESET_NORMAL;
        clear_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
 
        /* Finish with the destroy part. Start the init part */
@@ -2583,13 +2651,47 @@ err:
                "Reset attempt failed. Can not reset the device\n");
 }
 
-static void check_for_missing_tx_completions(struct ena_adapter *adapter)
+static int check_missing_comp_in_queue(struct ena_adapter *adapter,
+                                      struct ena_ring *tx_ring)
 {
        struct ena_tx_buffer *tx_buf;
        unsigned long last_jiffies;
+       u32 missed_tx = 0;
+       int i;
+
+       for (i = 0; i < tx_ring->ring_size; i++) {
+               tx_buf = &tx_ring->tx_buffer_info[i];
+               last_jiffies = tx_buf->last_jiffies;
+               if (unlikely(last_jiffies &&
+                            time_is_before_jiffies(last_jiffies + adapter->missing_tx_completion_to))) {
+                       if (!tx_buf->print_once)
+                               netif_notice(adapter, tx_err, adapter->netdev,
+                                            "Found a Tx that wasn't completed on time, qid %d, index %d.\n",
+                                            tx_ring->qid, i);
+
+                       tx_buf->print_once = 1;
+                       missed_tx++;
+
+                       if (unlikely(missed_tx > adapter->missing_tx_completion_threshold)) {
+                               netif_err(adapter, tx_err, adapter->netdev,
+                                         "The number of lost tx completions is above the threshold (%d > %d). Reset the device\n",
+                                         missed_tx,
+                                         adapter->missing_tx_completion_threshold);
+                               adapter->reset_reason =
+                                       ENA_REGS_RESET_MISS_TX_CMPL;
+                               set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
+                               return -EIO;
+                       }
+               }
+       }
+
+       return 0;
+}
+
+static void check_for_missing_tx_completions(struct ena_adapter *adapter)
+{
        struct ena_ring *tx_ring;
-       int i, j, budget;
-       u32 missed_tx;
+       int i, budget, rc;
 
        /* Make sure the driver doesn't turn the device in other process */
        smp_rmb();
@@ -2600,36 +2702,17 @@ static void check_for_missing_tx_completions(struct ena_adapter *adapter)
        if (test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))
                return;
 
+       if (adapter->missing_tx_completion_to == ENA_HW_HINTS_NO_TIMEOUT)
+               return;
+
        budget = ENA_MONITORED_TX_QUEUES;
 
        for (i = adapter->last_monitored_tx_qid; i < adapter->num_queues; i++) {
                tx_ring = &adapter->tx_ring[i];
 
-               for (j = 0; j < tx_ring->ring_size; j++) {
-                       tx_buf = &tx_ring->tx_buffer_info[j];
-                       last_jiffies = tx_buf->last_jiffies;
-                       if (unlikely(last_jiffies && time_is_before_jiffies(last_jiffies + TX_TIMEOUT))) {
-                               netif_notice(adapter, tx_err, adapter->netdev,
-                                            "Found a Tx that wasn't completed on time, qid %d, index %d.\n",
-                                            tx_ring->qid, j);
-
-                               u64_stats_update_begin(&tx_ring->syncp);
-                               missed_tx = tx_ring->tx_stats.missing_tx_comp++;
-                               u64_stats_update_end(&tx_ring->syncp);
-
-                               /* Clear last jiffies so the lost buffer won't
-                                * be counted twice.
-                                */
-                               tx_buf->last_jiffies = 0;
-
-                               if (unlikely(missed_tx > MAX_NUM_OF_TIMEOUTED_PACKETS)) {
-                                       netif_err(adapter, tx_err, adapter->netdev,
-                                                 "The number of lost tx completion is above the threshold (%d > %d). Reset the device\n",
-                                                 missed_tx, MAX_NUM_OF_TIMEOUTED_PACKETS);
-                                       set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
-                               }
-                       }
-               }
+               rc = check_missing_comp_in_queue(adapter, tx_ring);
+               if (unlikely(rc))
+                       return;
 
                budget--;
                if (!budget)
@@ -2639,6 +2722,58 @@ static void check_for_missing_tx_completions(struct ena_adapter *adapter)
        adapter->last_monitored_tx_qid = i % adapter->num_queues;
 }
 
+/* trigger napi schedule after 2 consecutive detections */
+#define EMPTY_RX_REFILL 2
+/* For the rare case where the device runs out of Rx descriptors and the
+ * napi handler failed to refill new Rx descriptors (due to a lack of memory
+ * for example).
+ * This case will lead to a deadlock:
+ * The device won't send interrupts since all the new Rx packets will be dropped
+ * The napi handler won't allocate new Rx descriptors so the device will be
+ * able to send new packets.
+ *
+ * This scenario can happen when the kernel's vm.min_free_kbytes is too small.
+ * It is recommended to have at least 512MB, with a minimum of 128MB for
+ * constrained environment).
+ *
+ * When such a situation is detected - Reschedule napi
+ */
+static void check_for_empty_rx_ring(struct ena_adapter *adapter)
+{
+       struct ena_ring *rx_ring;
+       int i, refill_required;
+
+       if (!test_bit(ENA_FLAG_DEV_UP, &adapter->flags))
+               return;
+
+       if (test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))
+               return;
+
+       for (i = 0; i < adapter->num_queues; i++) {
+               rx_ring = &adapter->rx_ring[i];
+
+               refill_required =
+                       ena_com_sq_empty_space(rx_ring->ena_com_io_sq);
+               if (unlikely(refill_required == (rx_ring->ring_size - 1))) {
+                       rx_ring->empty_rx_queue++;
+
+                       if (rx_ring->empty_rx_queue >= EMPTY_RX_REFILL) {
+                               u64_stats_update_begin(&rx_ring->syncp);
+                               rx_ring->rx_stats.empty_rx_ring++;
+                               u64_stats_update_end(&rx_ring->syncp);
+
+                               netif_err(adapter, drv, adapter->netdev,
+                                         "trigger refill for ring %d\n", i);
+
+                               napi_schedule(rx_ring->napi);
+                               rx_ring->empty_rx_queue = 0;
+                       }
+               } else {
+                       rx_ring->empty_rx_queue = 0;
+               }
+       }
+}
+
 /* Check for keep alive expiration */
 static void check_for_missing_keep_alive(struct ena_adapter *adapter)
 {
@@ -2647,14 +2782,18 @@ static void check_for_missing_keep_alive(struct ena_adapter *adapter)
        if (!adapter->wd_state)
                return;
 
-       keep_alive_expired = round_jiffies(adapter->last_keep_alive_jiffies
-                                          + ENA_DEVICE_KALIVE_TIMEOUT);
+       if (adapter->keep_alive_timeout == ENA_HW_HINTS_NO_TIMEOUT)
+               return;
+
+       keep_alive_expired = round_jiffies(adapter->last_keep_alive_jiffies +
+                                          adapter->keep_alive_timeout);
        if (unlikely(time_is_before_jiffies(keep_alive_expired))) {
                netif_err(adapter, drv, adapter->netdev,
                          "Keep alive watchdog timeout.\n");
                u64_stats_update_begin(&adapter->syncp);
                adapter->dev_stats.wd_expired++;
                u64_stats_update_end(&adapter->syncp);
+               adapter->reset_reason = ENA_REGS_RESET_KEEP_ALIVE_TO;
                set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
        }
 }
@@ -2667,10 +2806,49 @@ static void check_for_admin_com_state(struct ena_adapter *adapter)
                u64_stats_update_begin(&adapter->syncp);
                adapter->dev_stats.admin_q_pause++;
                u64_stats_update_end(&adapter->syncp);
+               adapter->reset_reason = ENA_REGS_RESET_ADMIN_TO;
                set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
        }
 }
 
+static void ena_update_hints(struct ena_adapter *adapter,
+                            struct ena_admin_ena_hw_hints *hints)
+{
+       struct net_device *netdev = adapter->netdev;
+
+       if (hints->admin_completion_tx_timeout)
+               adapter->ena_dev->admin_queue.completion_timeout =
+                       hints->admin_completion_tx_timeout * 1000;
+
+       if (hints->mmio_read_timeout)
+               /* convert to usec */
+               adapter->ena_dev->mmio_read.reg_read_to =
+                       hints->mmio_read_timeout * 1000;
+
+       if (hints->missed_tx_completion_count_threshold_to_reset)
+               adapter->missing_tx_completion_threshold =
+                       hints->missed_tx_completion_count_threshold_to_reset;
+
+       if (hints->missing_tx_completion_timeout) {
+               if (hints->missing_tx_completion_timeout == ENA_HW_HINTS_NO_TIMEOUT)
+                       adapter->missing_tx_completion_to = ENA_HW_HINTS_NO_TIMEOUT;
+               else
+                       adapter->missing_tx_completion_to =
+                               msecs_to_jiffies(hints->missing_tx_completion_timeout);
+       }
+
+       if (hints->netdev_wd_timeout)
+               netdev->watchdog_timeo = msecs_to_jiffies(hints->netdev_wd_timeout);
+
+       if (hints->driver_watchdog_timeout) {
+               if (hints->driver_watchdog_timeout == ENA_HW_HINTS_NO_TIMEOUT)
+                       adapter->keep_alive_timeout = ENA_HW_HINTS_NO_TIMEOUT;
+               else
+                       adapter->keep_alive_timeout =
+                               msecs_to_jiffies(hints->driver_watchdog_timeout);
+       }
+}
+
 static void ena_update_host_info(struct ena_admin_host_info *host_info,
                                 struct net_device *netdev)
 {
@@ -2693,6 +2871,8 @@ static void ena_timer_service(unsigned long data)
 
        check_for_missing_tx_completions(adapter);
 
+       check_for_empty_rx_ring(adapter);
+
        if (debug_area)
                ena_dump_stats_to_buf(adapter, debug_area);
 
@@ -2841,7 +3021,7 @@ static int ena_rss_init_default(struct ena_adapter *adapter)
                val = ethtool_rxfh_indir_default(i, adapter->num_queues);
                rc = ena_com_indirect_table_fill_entry(ena_dev, i,
                                                       ENA_IO_RXQ_IDX(val));
-               if (unlikely(rc && (rc != -EPERM))) {
+               if (unlikely(rc && (rc != -EOPNOTSUPP))) {
                        dev_err(dev, "Cannot fill indirect table\n");
                        goto err_fill_indir;
                }
@@ -2849,13 +3029,13 @@ static int ena_rss_init_default(struct ena_adapter *adapter)
 
        rc = ena_com_fill_hash_function(ena_dev, ENA_ADMIN_CRC32, NULL,
                                        ENA_HASH_KEY_SIZE, 0xFFFFFFFF);
-       if (unlikely(rc && (rc != -EPERM))) {
+       if (unlikely(rc && (rc != -EOPNOTSUPP))) {
                dev_err(dev, "Cannot fill hash function\n");
                goto err_fill_indir;
        }
 
        rc = ena_com_set_default_hash_ctrl(ena_dev);
-       if (unlikely(rc && (rc != -EPERM))) {
+       if (unlikely(rc && (rc != -EOPNOTSUPP))) {
                dev_err(dev, "Cannot fill hash control\n");
                goto err_fill_indir;
        }
@@ -2873,6 +3053,11 @@ static void ena_release_bars(struct ena_com_dev *ena_dev, struct pci_dev *pdev)
 {
        int release_bars;
 
+       if (ena_dev->mem_bar)
+               devm_iounmap(&pdev->dev, ena_dev->mem_bar);
+
+       devm_iounmap(&pdev->dev, ena_dev->reg_bar);
+
        release_bars = pci_select_bars(pdev, IORESOURCE_MEM) & ENA_BAR_MASK;
        pci_release_selected_regions(pdev, release_bars);
 }
@@ -2960,8 +3145,9 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto err_free_ena_dev;
        }
 
-       ena_dev->reg_bar = ioremap(pci_resource_start(pdev, ENA_REG_BAR),
-                                  pci_resource_len(pdev, ENA_REG_BAR));
+       ena_dev->reg_bar = devm_ioremap(&pdev->dev,
+                                       pci_resource_start(pdev, ENA_REG_BAR),
+                                       pci_resource_len(pdev, ENA_REG_BAR));
        if (!ena_dev->reg_bar) {
                dev_err(&pdev->dev, "failed to remap regs bar\n");
                rc = -EFAULT;
@@ -2981,8 +3167,9 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        ena_set_push_mode(pdev, ena_dev, &get_feat_ctx);
 
        if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) {
-               ena_dev->mem_bar = ioremap_wc(pci_resource_start(pdev, ENA_MEM_BAR),
-                                             pci_resource_len(pdev, ENA_MEM_BAR));
+               ena_dev->mem_bar = devm_ioremap_wc(&pdev->dev,
+                                                  pci_resource_start(pdev, ENA_MEM_BAR),
+                                                  pci_resource_len(pdev, ENA_MEM_BAR));
                if (!ena_dev->mem_bar) {
                        rc = -EFAULT;
                        goto err_device_destroy;
@@ -3024,6 +3211,7 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        ena_set_conf_feat_params(adapter, &get_feat_ctx);
 
        adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
+       adapter->reset_reason = ENA_REGS_RESET_NORMAL;
 
        adapter->tx_ring_size = queue_size;
        adapter->rx_ring_size = queue_size;
@@ -3062,7 +3250,7 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto err_worker_destroy;
        }
        rc = ena_rss_init_default(adapter);
-       if (rc && (rc != -EPERM)) {
+       if (rc && (rc != -EOPNOTSUPP)) {
                dev_err(&pdev->dev, "Cannot init RSS rc: %d\n", rc);
                goto err_free_msix;
        }
@@ -3084,6 +3272,11 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        INIT_WORK(&adapter->reset_task, ena_fw_reset_device);
 
        adapter->last_keep_alive_jiffies = jiffies;
+       adapter->keep_alive_timeout = ENA_DEVICE_KALIVE_TIMEOUT;
+       adapter->missing_tx_completion_to = TX_TIMEOUT;
+       adapter->missing_tx_completion_threshold = MAX_NUM_OF_TIMEOUTED_PACKETS;
+
+       ena_update_hints(adapter, &get_feat_ctx.hw_hints);
 
        setup_timer(&adapter->timer_service, ena_timer_service,
                    (unsigned long)adapter);
@@ -3103,7 +3296,7 @@ err_rss:
        ena_com_delete_debug_area(ena_dev);
        ena_com_rss_destroy(ena_dev);
 err_free_msix:
-       ena_com_dev_reset(ena_dev);
+       ena_com_dev_reset(ena_dev, ENA_REGS_RESET_INIT_ERR);
        ena_free_mgmnt_irq(adapter);
        ena_disable_msix(adapter);
 err_worker_destroy:
@@ -3165,12 +3358,6 @@ static void ena_remove(struct pci_dev *pdev)
        struct ena_com_dev *ena_dev;
        struct net_device *netdev;
 
-       if (!adapter)
-               /* This device didn't load properly and it's resources
-                * already released, nothing to do
-                */
-               return;
-
        ena_dev = adapter->ena_dev;
        netdev = adapter->netdev;
 
@@ -3192,7 +3379,7 @@ static void ena_remove(struct pci_dev *pdev)
 
        /* Reset the device only if the device is running. */
        if (test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags))
-               ena_com_dev_reset(ena_dev);
+               ena_com_dev_reset(ena_dev, adapter->reset_reason);
 
        ena_free_mgmnt_irq(adapter);
 
@@ -3291,6 +3478,7 @@ static void ena_notification(void *adapter_data,
                             struct ena_admin_aenq_entry *aenq_e)
 {
        struct ena_adapter *adapter = (struct ena_adapter *)adapter_data;
+       struct ena_admin_ena_hw_hints *hints;
 
        WARN(aenq_e->aenq_common_desc.group != ENA_ADMIN_NOTIFICATION,
             "Invalid group(%x) expected %x\n",
@@ -3308,6 +3496,11 @@ static void ena_notification(void *adapter_data,
        case ENA_ADMIN_RESUME:
                queue_work(ena_wq, &adapter->resume_io_task);
                break;
+       case ENA_ADMIN_UPDATE_HINTS:
+               hints = (struct ena_admin_ena_hw_hints *)
+                       (&aenq_e->inline_data_w4);
+               ena_update_hints(adapter, hints);
+               break;
        default:
                netif_err(adapter, drv, adapter->netdev,
                          "Invalid aenq notification link state %d\n",