return failure ? budget : (int)total_rx_packets;
 }
 
-static inline u32 i40e_buildreg_itr(const int type, u16 itr)
+/**
+ * i40e_buildreg_itr - build a value for writing to I40E_PFINT_DYN_CTLN register
+ * @itr_idx: interrupt throttling index
+ * @interval: interrupt throttling interval value in usecs
+ * @force_swint: force software interrupt
+ *
+ * The function builds a value for I40E_PFINT_DYN_CTLN register that
+ * is used to update interrupt throttling interval for specified ITR index
+ * and optionally enforces a software interrupt. If the @itr_idx is equal
+ * to I40E_ITR_NONE then no interval change is applied and only @force_swint
+ * parameter is taken into account. If the interval change and enforced
+ * software interrupt are not requested then the built value just enables
+ * appropriate vector interrupt.
+ **/
+static u32 i40e_buildreg_itr(enum i40e_dyn_idx itr_idx, u16 interval,
+                            bool force_swint)
 {
        u32 val;
 
         * an event in the PBA anyway so we need to rely on the automask
         * to hold pending events for us until the interrupt is re-enabled
         *
-        * The itr value is reported in microseconds, and the register
-        * value is recorded in 2 microsecond units. For this reason we
-        * only need to shift by the interval shift - 1 instead of the
-        * full value.
+        * We have to shift the given value as it is reported in microseconds
+        * and the register value is recorded in 2 microsecond units.
         */
-       itr &= I40E_ITR_MASK;
+       interval >>= 1;
 
+       /* 1. Enable vector interrupt
+        * 2. Update the interval for the specified ITR index
+        *    (I40E_ITR_NONE in the register is used to indicate that
+        *     no interval update is requested)
+        */
        val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
-             (type << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
-             (itr << (I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT - 1));
+             FIELD_PREP(I40E_PFINT_DYN_CTLN_ITR_INDX_MASK, itr_idx) |
+             FIELD_PREP(I40E_PFINT_DYN_CTLN_INTERVAL_MASK, interval);
+
+       /* 3. Enforce software interrupt trigger if requested
+        *    (These software interrupts rate is limited by ITR2 that is
+        *     set to 20K interrupts per second)
+        */
+       if (force_swint)
+               val |= I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK |
+                      I40E_PFINT_DYN_CTLN_SW_ITR_INDX_ENA_MASK |
+                      FIELD_PREP(I40E_PFINT_DYN_CTLN_SW_ITR_INDX_MASK,
+                                 I40E_SW_ITR);
 
        return val;
 }
 
-/* a small macro to shorten up some long lines */
-#define INTREG I40E_PFINT_DYN_CTLN
-
 /* The act of updating the ITR will cause it to immediately trigger. In order
  * to prevent this from throwing off adaptive update statistics we defer the
  * update so that it can only happen so often. So after either Tx or Rx are
 static inline void i40e_update_enable_itr(struct i40e_vsi *vsi,
                                          struct i40e_q_vector *q_vector)
 {
+       enum i40e_dyn_idx itr_idx = I40E_ITR_NONE;
        struct i40e_hw *hw = &vsi->back->hw;
-       u32 intval;
+       u16 interval = 0;
+       u32 itr_val;
 
        /* If we don't have MSIX, then we only need to re-enable icr0 */
        if (!test_bit(I40E_FLAG_MSIX_ENA, vsi->back->flags)) {
         */
        if (q_vector->rx.target_itr < q_vector->rx.current_itr) {
                /* Rx ITR needs to be reduced, this is highest priority */
-               intval = i40e_buildreg_itr(I40E_RX_ITR,
-                                          q_vector->rx.target_itr);
+               itr_idx = I40E_RX_ITR;
+               interval = q_vector->rx.target_itr;
                q_vector->rx.current_itr = q_vector->rx.target_itr;
                q_vector->itr_countdown = ITR_COUNTDOWN_START;
        } else if ((q_vector->tx.target_itr < q_vector->tx.current_itr) ||
                /* Tx ITR needs to be reduced, this is second priority
                 * Tx ITR needs to be increased more than Rx, fourth priority
                 */
-               intval = i40e_buildreg_itr(I40E_TX_ITR,
-                                          q_vector->tx.target_itr);
+               itr_idx = I40E_TX_ITR;
+               interval = q_vector->tx.target_itr;
                q_vector->tx.current_itr = q_vector->tx.target_itr;
                q_vector->itr_countdown = ITR_COUNTDOWN_START;
        } else if (q_vector->rx.current_itr != q_vector->rx.target_itr) {
                /* Rx ITR needs to be increased, third priority */
-               intval = i40e_buildreg_itr(I40E_RX_ITR,
-                                          q_vector->rx.target_itr);
+               itr_idx = I40E_RX_ITR;
+               interval = q_vector->rx.target_itr;
                q_vector->rx.current_itr = q_vector->rx.target_itr;
                q_vector->itr_countdown = ITR_COUNTDOWN_START;
        } else {
                /* No ITR update, lowest priority */
-               intval = i40e_buildreg_itr(I40E_ITR_NONE, 0);
                if (q_vector->itr_countdown)
                        q_vector->itr_countdown--;
        }
 
-       if (!test_bit(__I40E_VSI_DOWN, vsi->state))
-               wr32(hw, INTREG(q_vector->reg_idx), intval);
+       /* Do not update interrupt control register if VSI is down */
+       if (test_bit(__I40E_VSI_DOWN, vsi->state))
+               return;
+
+       /* Update ITR interval if necessary and enforce software interrupt
+        * if we are exiting busy poll.
+        */
+       if (q_vector->in_busy_poll) {
+               itr_val = i40e_buildreg_itr(itr_idx, interval, true);
+               q_vector->in_busy_poll = false;
+       } else {
+               itr_val = i40e_buildreg_itr(itr_idx, interval, false);
+       }
+       wr32(hw, I40E_PFINT_DYN_CTLN(q_vector->reg_idx), itr_val);
 }
 
 /**
         */
        if (likely(napi_complete_done(napi, work_done)))
                i40e_update_enable_itr(vsi, q_vector);
+       else
+               q_vector->in_busy_poll = true;
 
        return min(work_done, budget - 1);
 }