Commit 9fe890cc authored by Arthur Kiyanovski's avatar Arthur Kiyanovski Committed by Jakub Kicinski

net: ena: Extract recurring driver reset code into a function

Create an inline function for resetting the driver
to reduce code duplication.
Signed-off-by: default avatarNati Koler <nkoler@amazon.com>
Signed-off-by: default avatarArthur Kiyanovski <akiyano@amazon.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d0e8831d
...@@ -103,7 +103,7 @@ static void ena_tx_timeout(struct net_device *dev, unsigned int txqueue) ...@@ -103,7 +103,7 @@ static void ena_tx_timeout(struct net_device *dev, unsigned int txqueue)
if (test_and_set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags)) if (test_and_set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags))
return; return;
adapter->reset_reason = ENA_REGS_RESET_OS_NETDEV_WD; ena_reset_device(adapter, ENA_REGS_RESET_OS_NETDEV_WD);
ena_increase_stat(&adapter->dev_stats.tx_timeout, 1, &adapter->syncp); ena_increase_stat(&adapter->dev_stats.tx_timeout, 1, &adapter->syncp);
netif_err(adapter, tx_err, dev, "Transmit time out\n"); netif_err(adapter, tx_err, dev, "Transmit time out\n");
...@@ -166,11 +166,9 @@ static int ena_xmit_common(struct net_device *dev, ...@@ -166,11 +166,9 @@ static int ena_xmit_common(struct net_device *dev,
"Failed to prepare tx bufs\n"); "Failed to prepare tx bufs\n");
ena_increase_stat(&ring->tx_stats.prepare_ctx_err, 1, ena_increase_stat(&ring->tx_stats.prepare_ctx_err, 1,
&ring->syncp); &ring->syncp);
if (rc != -ENOMEM) { if (rc != -ENOMEM)
adapter->reset_reason = ena_reset_device(adapter,
ENA_REGS_RESET_DRIVER_INVALID_STATE; ENA_REGS_RESET_DRIVER_INVALID_STATE);
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
}
return rc; return rc;
} }
...@@ -1279,10 +1277,8 @@ static int handle_invalid_req_id(struct ena_ring *ring, u16 req_id, ...@@ -1279,10 +1277,8 @@ static int handle_invalid_req_id(struct ena_ring *ring, u16 req_id,
req_id, ring->qid); req_id, ring->qid);
ena_increase_stat(&ring->tx_stats.bad_req_id, 1, &ring->syncp); ena_increase_stat(&ring->tx_stats.bad_req_id, 1, &ring->syncp);
ena_reset_device(ring->adapter, ENA_REGS_RESET_INV_TX_REQ_ID);
/* Trigger device reset */
ring->adapter->reset_reason = ENA_REGS_RESET_INV_TX_REQ_ID;
set_bit(ENA_FLAG_TRIGGER_RESET, &ring->adapter->flags);
return -EFAULT; return -EFAULT;
} }
...@@ -1445,10 +1441,7 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring, ...@@ -1445,10 +1441,7 @@ static struct sk_buff *ena_rx_skb(struct ena_ring *rx_ring,
netif_err(adapter, rx_err, rx_ring->netdev, netif_err(adapter, rx_err, rx_ring->netdev,
"Page is NULL. qid %u req_id %u\n", rx_ring->qid, req_id); "Page is NULL. qid %u req_id %u\n", rx_ring->qid, req_id);
ena_increase_stat(&rx_ring->rx_stats.bad_req_id, 1, &rx_ring->syncp); ena_increase_stat(&rx_ring->rx_stats.bad_req_id, 1, &rx_ring->syncp);
adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID; ena_reset_device(adapter, ENA_REGS_RESET_INV_RX_REQ_ID);
/* Make sure reset reason is set before triggering the reset */
smp_mb__before_atomic();
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
return NULL; return NULL;
} }
...@@ -1781,15 +1774,12 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi, ...@@ -1781,15 +1774,12 @@ static int ena_clean_rx_irq(struct ena_ring *rx_ring, struct napi_struct *napi,
if (rc == -ENOSPC) { if (rc == -ENOSPC) {
ena_increase_stat(&rx_ring->rx_stats.bad_desc_num, 1, ena_increase_stat(&rx_ring->rx_stats.bad_desc_num, 1,
&rx_ring->syncp); &rx_ring->syncp);
adapter->reset_reason = ENA_REGS_RESET_TOO_MANY_RX_DESCS; ena_reset_device(adapter, ENA_REGS_RESET_TOO_MANY_RX_DESCS);
} else { } else {
ena_increase_stat(&rx_ring->rx_stats.bad_req_id, 1, ena_increase_stat(&rx_ring->rx_stats.bad_req_id, 1,
&rx_ring->syncp); &rx_ring->syncp);
adapter->reset_reason = ENA_REGS_RESET_INV_RX_REQ_ID; ena_reset_device(adapter, ENA_REGS_RESET_INV_RX_REQ_ID);
} }
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
return 0; return 0;
} }
...@@ -3707,9 +3697,8 @@ static int check_for_rx_interrupt_queue(struct ena_adapter *adapter, ...@@ -3707,9 +3697,8 @@ static int check_for_rx_interrupt_queue(struct ena_adapter *adapter,
netif_err(adapter, rx_err, adapter->netdev, netif_err(adapter, rx_err, adapter->netdev,
"Potential MSIX issue on Rx side Queue = %d. Reset the device\n", "Potential MSIX issue on Rx side Queue = %d. Reset the device\n",
rx_ring->qid); rx_ring->qid);
adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT;
smp_mb__before_atomic(); ena_reset_device(adapter, ENA_REGS_RESET_MISS_INTERRUPT);
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
return -EIO; return -EIO;
} }
...@@ -3746,9 +3735,7 @@ static int check_missing_comp_in_tx_queue(struct ena_adapter *adapter, ...@@ -3746,9 +3735,7 @@ static int check_missing_comp_in_tx_queue(struct ena_adapter *adapter,
netif_err(adapter, tx_err, adapter->netdev, netif_err(adapter, tx_err, adapter->netdev,
"Potential MSIX issue on Tx side Queue = %d. Reset the device\n", "Potential MSIX issue on Tx side Queue = %d. Reset the device\n",
tx_ring->qid); tx_ring->qid);
adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT; ena_reset_device(adapter, ENA_REGS_RESET_MISS_INTERRUPT);
smp_mb__before_atomic();
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
return -EIO; return -EIO;
} }
...@@ -3774,9 +3761,7 @@ static int check_missing_comp_in_tx_queue(struct ena_adapter *adapter, ...@@ -3774,9 +3761,7 @@ static int check_missing_comp_in_tx_queue(struct ena_adapter *adapter,
"The number of lost tx completions is above the threshold (%d > %d). Reset the device\n", "The number of lost tx completions is above the threshold (%d > %d). Reset the device\n",
missed_tx, missed_tx,
adapter->missing_tx_completion_threshold); adapter->missing_tx_completion_threshold);
adapter->reset_reason = ena_reset_device(adapter, ENA_REGS_RESET_MISS_TX_CMPL);
ENA_REGS_RESET_MISS_TX_CMPL;
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
rc = -EIO; rc = -EIO;
} }
...@@ -3897,8 +3882,7 @@ static void check_for_missing_keep_alive(struct ena_adapter *adapter) ...@@ -3897,8 +3882,7 @@ static void check_for_missing_keep_alive(struct ena_adapter *adapter)
"Keep alive watchdog timeout.\n"); "Keep alive watchdog timeout.\n");
ena_increase_stat(&adapter->dev_stats.wd_expired, 1, ena_increase_stat(&adapter->dev_stats.wd_expired, 1,
&adapter->syncp); &adapter->syncp);
adapter->reset_reason = ENA_REGS_RESET_KEEP_ALIVE_TO; ena_reset_device(adapter, ENA_REGS_RESET_KEEP_ALIVE_TO);
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
} }
} }
...@@ -3909,8 +3893,7 @@ static void check_for_admin_com_state(struct ena_adapter *adapter) ...@@ -3909,8 +3893,7 @@ static void check_for_admin_com_state(struct ena_adapter *adapter)
"ENA admin queue is not in running state!\n"); "ENA admin queue is not in running state!\n");
ena_increase_stat(&adapter->dev_stats.admin_q_pause, 1, ena_increase_stat(&adapter->dev_stats.admin_q_pause, 1,
&adapter->syncp); &adapter->syncp);
adapter->reset_reason = ENA_REGS_RESET_ADMIN_TO; ena_reset_device(adapter, ENA_REGS_RESET_ADMIN_TO);
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
} }
} }
......
...@@ -394,6 +394,15 @@ int ena_update_queue_count(struct ena_adapter *adapter, u32 new_channel_count); ...@@ -394,6 +394,15 @@ int ena_update_queue_count(struct ena_adapter *adapter, u32 new_channel_count);
int ena_get_sset_count(struct net_device *netdev, int sset); int ena_get_sset_count(struct net_device *netdev, int sset);
static inline void ena_reset_device(struct ena_adapter *adapter,
enum ena_regs_reset_reason_types reset_reason)
{
adapter->reset_reason = reset_reason;
/* Make sure reset reason is set before triggering the reset */
smp_mb__before_atomic();
set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
}
enum ena_xdp_errors_t { enum ena_xdp_errors_t {
ENA_XDP_ALLOWED = 0, ENA_XDP_ALLOWED = 0,
ENA_XDP_CURRENT_MTU_TOO_LARGE, ENA_XDP_CURRENT_MTU_TOO_LARGE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment