enic: do hang reset only in case of tx timeout
[cascardo/linux.git] / drivers / net / ethernet / cisco / enic / enic_main.c
index 918a8e4..0c22fd0 100644 (file)
@@ -178,13 +178,15 @@ static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
        return 0;
 }
 
-static void enic_log_q_error(struct enic *enic)
+static bool enic_log_q_error(struct enic *enic)
 {
        unsigned int i;
        u32 error_status;
+       bool err = false;
 
        for (i = 0; i < enic->wq_count; i++) {
                error_status = vnic_wq_error_status(&enic->wq[i]);
+               err |= error_status;
                if (error_status)
                        netdev_err(enic->netdev, "WQ[%d] error_status %d\n",
                                i, error_status);
@@ -192,10 +194,13 @@ static void enic_log_q_error(struct enic *enic)
 
        for (i = 0; i < enic->rq_count; i++) {
                error_status = vnic_rq_error_status(&enic->rq[i]);
+               err |= error_status;
                if (error_status)
                        netdev_err(enic->netdev, "RQ[%d] error_status %d\n",
                                i, error_status);
        }
+
+       return err;
 }
 
 static void enic_msglvl_check(struct enic *enic)
@@ -333,10 +338,9 @@ static irqreturn_t enic_isr_msix_err(int irq, void *data)
 
        vnic_intr_return_all_credits(&enic->intr[intr]);
 
-       enic_log_q_error(enic);
-
-       /* schedule recovery from WQ/RQ error */
-       schedule_work(&enic->reset);
+       if (enic_log_q_error(enic))
+               /* schedule recovery from WQ/RQ error */
+               schedule_work(&enic->reset);
 
        return IRQ_HANDLED;
 }
@@ -804,7 +808,7 @@ static void enic_set_rx_mode(struct net_device *netdev)
 static void enic_tx_timeout(struct net_device *netdev)
 {
        struct enic *enic = netdev_priv(netdev);
-       schedule_work(&enic->reset);
+       schedule_work(&enic->tx_hang_reset);
 }
 
 static int enic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
@@ -1149,6 +1153,64 @@ static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
        return 0;
 }
 
+static void enic_set_int_moderation(struct enic *enic, struct vnic_rq *rq)
+{
+       unsigned int intr = enic_msix_rq_intr(enic, rq->index);
+       struct vnic_cq *cq = &enic->cq[enic_cq_rq(enic, rq->index)];
+       u32 timer = cq->tobe_rx_coal_timeval;
+
+       if (cq->tobe_rx_coal_timeval != cq->cur_rx_coal_timeval) {
+               vnic_intr_coalescing_timer_set(&enic->intr[intr], timer);
+               cq->cur_rx_coal_timeval = cq->tobe_rx_coal_timeval;
+       }
+}
+
+static void enic_calc_int_moderation(struct enic *enic, struct vnic_rq *rq)
+{
+       struct enic_rx_coal *rx_coal = &enic->rx_coalesce_setting;
+       struct vnic_cq *cq = &enic->cq[enic_cq_rq(enic, rq->index)];
+       struct vnic_rx_bytes_counter *pkt_size_counter = &cq->pkt_size_counter;
+       int index;
+       u32 timer;
+       u32 range_start;
+       u32 traffic;
+       u64 delta;
+       ktime_t now = ktime_get();
+
+       delta = ktime_us_delta(now, cq->prev_ts);
+       if (delta < ENIC_AIC_TS_BREAK)
+               return;
+       cq->prev_ts = now;
+
+       traffic = pkt_size_counter->large_pkt_bytes_cnt +
+                 pkt_size_counter->small_pkt_bytes_cnt;
+       /* The table takes Mbps
+        * traffic *= 8    => bits
+        * traffic *= (10^6 / delta)    => bps
+        * traffic /= 10^6     => Mbps
+        *
+        * Combining, traffic *= (8 / delta)
+        */
+
+       traffic <<= 3;
+       traffic = delta > UINT_MAX ? 0 : traffic / (u32)delta;
+
+       for (index = 0; index < ENIC_MAX_COALESCE_TIMERS; index++)
+               if (traffic < mod_table[index].rx_rate)
+                       break;
+       range_start = (pkt_size_counter->small_pkt_bytes_cnt >
+                      pkt_size_counter->large_pkt_bytes_cnt << 1) ?
+                     rx_coal->small_pkt_range_start :
+                     rx_coal->large_pkt_range_start;
+       timer = range_start + ((rx_coal->range_end - range_start) *
+                              mod_table[index].range_percent / 100);
+       /* Damping */
+       cq->tobe_rx_coal_timeval = (timer + cq->tobe_rx_coal_timeval) >> 1;
+
+       pkt_size_counter->large_pkt_bytes_cnt = 0;
+       pkt_size_counter->small_pkt_bytes_cnt = 0;
+}
+
 static int enic_poll(struct napi_struct *napi, int budget)
 {
        struct net_device *netdev = napi->dev;
@@ -1199,6 +1261,11 @@ static int enic_poll(struct napi_struct *napi, int budget)
 
        if (err)
                rq_work_done = rq_work_to_do;
+       if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce)
+               /* Call the function which refreshes the intr coalescing timer
+                * value based on the traffic.
+                */
+               enic_calc_int_moderation(enic, &enic->rq[0]);
 
        if (rq_work_done < rq_work_to_do) {
 
@@ -1207,70 +1274,14 @@ static int enic_poll(struct napi_struct *napi, int budget)
                 */
 
                napi_complete(napi);
+               if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce)
+                       enic_set_int_moderation(enic, &enic->rq[0]);
                vnic_intr_unmask(&enic->intr[intr]);
        }
 
        return rq_work_done;
 }
 
-static void enic_set_int_moderation(struct enic *enic, struct vnic_rq *rq)
-{
-       unsigned int intr = enic_msix_rq_intr(enic, rq->index);
-       struct vnic_cq *cq = &enic->cq[enic_cq_rq(enic, rq->index)];
-       u32 timer = cq->tobe_rx_coal_timeval;
-
-       if (cq->tobe_rx_coal_timeval != cq->cur_rx_coal_timeval) {
-               vnic_intr_coalescing_timer_set(&enic->intr[intr], timer);
-               cq->cur_rx_coal_timeval = cq->tobe_rx_coal_timeval;
-       }
-}
-
-static void enic_calc_int_moderation(struct enic *enic, struct vnic_rq *rq)
-{
-       struct enic_rx_coal *rx_coal = &enic->rx_coalesce_setting;
-       struct vnic_cq *cq = &enic->cq[enic_cq_rq(enic, rq->index)];
-       struct vnic_rx_bytes_counter *pkt_size_counter = &cq->pkt_size_counter;
-       int index;
-       u32 timer;
-       u32 range_start;
-       u32 traffic;
-       u64 delta;
-       ktime_t now = ktime_get();
-
-       delta = ktime_us_delta(now, cq->prev_ts);
-       if (delta < ENIC_AIC_TS_BREAK)
-               return;
-       cq->prev_ts = now;
-
-       traffic = pkt_size_counter->large_pkt_bytes_cnt +
-                 pkt_size_counter->small_pkt_bytes_cnt;
-       /* The table takes Mbps
-        * traffic *= 8    => bits
-        * traffic *= (10^6 / delta)    => bps
-        * traffic /= 10^6     => Mbps
-        *
-        * Combining, traffic *= (8 / delta)
-        */
-
-       traffic <<= 3;
-       traffic = delta > UINT_MAX ? 0 : traffic / (u32)delta;
-
-       for (index = 0; index < ENIC_MAX_COALESCE_TIMERS; index++)
-               if (traffic < mod_table[index].rx_rate)
-                       break;
-       range_start = (pkt_size_counter->small_pkt_bytes_cnt >
-                      pkt_size_counter->large_pkt_bytes_cnt << 1) ?
-                     rx_coal->small_pkt_range_start :
-                     rx_coal->large_pkt_range_start;
-       timer = range_start + ((rx_coal->range_end - range_start) *
-                              mod_table[index].range_percent / 100);
-       /* Damping */
-       cq->tobe_rx_coal_timeval = (timer + cq->tobe_rx_coal_timeval) >> 1;
-
-       pkt_size_counter->large_pkt_bytes_cnt = 0;
-       pkt_size_counter->small_pkt_bytes_cnt = 0;
-}
-
 #ifdef CONFIG_RFS_ACCEL
 static void enic_free_rx_cpu_rmap(struct enic *enic)
 {
@@ -1407,10 +1418,8 @@ static int enic_poll_msix_rq(struct napi_struct *napi, int budget)
        if (err)
                work_done = work_to_do;
        if (enic->rx_coalesce_setting.use_adaptive_rx_coalesce)
-               /* Call the function which refreshes
-                * the intr coalescing timer value based on
-                * the traffic.  This is supported only in
-                * the case of MSI-x mode
+               /* Call the function which refreshes the intr coalescing timer
+                * value based on the traffic.
                 */
                enic_calc_int_moderation(enic, &enic->rq[rq]);
 
@@ -1569,12 +1578,6 @@ static void enic_set_rx_coal_setting(struct enic *enic)
        int index = -1;
        struct enic_rx_coal *rx_coal = &enic->rx_coalesce_setting;
 
-       /* If intr mode is not MSIX, do not do adaptive coalescing */
-       if (VNIC_DEV_INTR_MODE_MSIX != vnic_dev_get_intr_mode(enic->vdev)) {
-               netdev_info(enic->netdev, "INTR mode is not MSIX, Not initializing adaptive coalescing");
-               return;
-       }
-
        /* 1. Read the link speed from fw
         * 2. Pick the default range for the speed
         * 3. Update it in enic->rx_coalesce_setting
@@ -1925,6 +1928,19 @@ static int enic_dev_open(struct enic *enic)
        return err;
 }
 
+static int enic_dev_soft_reset(struct enic *enic)
+{
+       int err;
+
+       err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
+                           vnic_dev_soft_reset_done, 0);
+       if (err)
+               netdev_err(enic->netdev, "vNIC soft reset failed, err %d\n",
+                          err);
+
+       return err;
+}
+
 static int enic_dev_hang_reset(struct enic *enic)
 {
        int err;
@@ -2060,6 +2076,26 @@ static void enic_reset(struct work_struct *work)
 
        rtnl_lock();
 
+       spin_lock(&enic->enic_api_lock);
+       enic_stop(enic->netdev);
+       enic_dev_soft_reset(enic);
+       enic_reset_addr_lists(enic);
+       enic_init_vnic_resources(enic);
+       enic_set_rss_nic_cfg(enic);
+       enic_dev_set_ig_vlan_rewrite_mode(enic);
+       enic_open(enic->netdev);
+       spin_unlock(&enic->enic_api_lock);
+       call_netdevice_notifiers(NETDEV_REBOOT, enic->netdev);
+
+       rtnl_unlock();
+}
+
+static void enic_tx_hang_reset(struct work_struct *work)
+{
+       struct enic *enic = container_of(work, struct enic, tx_hang_reset);
+
+       rtnl_lock();
+
        spin_lock(&enic->enic_api_lock);
        enic_dev_hang_notify(enic);
        enic_stop(enic->netdev);
@@ -2485,6 +2521,11 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto err_out_iounmap;
        }
 
+       err = vnic_devcmd_init(enic->vdev);
+
+       if (err)
+               goto err_out_vnic_unregister;
+
 #ifdef CONFIG_PCI_IOV
        /* Get number of subvnics */
        pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
@@ -2579,6 +2620,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        enic_set_rx_coal_setting(enic);
        INIT_WORK(&enic->reset, enic_reset);
+       INIT_WORK(&enic->tx_hang_reset, enic_tx_hang_reset);
        INIT_WORK(&enic->change_mtu_work, enic_change_mtu_work);
 
        for (i = 0; i < enic->wq_count; i++)
@@ -2659,8 +2701,8 @@ err_out_disable_sriov_pp:
                pci_disable_sriov(pdev);
                enic->priv_flags &= ~ENIC_SRIOV_ENABLED;
        }
-err_out_vnic_unregister:
 #endif
+err_out_vnic_unregister:
        vnic_dev_unregister(enic->vdev);
 err_out_iounmap:
        enic_iounmap(enic);