]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ice: wait for reset before reporting devlink info
authorJacob Keller <jacob.e.keller@intel.com>
Thu, 6 May 2021 15:39:59 +0000 (08:39 -0700)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Mon, 7 Jun 2021 15:59:01 +0000 (08:59 -0700)
Requesting device firmware information while the device is busy cleaning
up after a reset can result in an unexpected failure:

This occurs because the command is attempting to access the device
AdminQ while it is down. Resolve this by having the command wait for
a while until the reset is complete. To do this, introduce
a reset_wait_queue and associated helper function "ice_wait_for_reset".

This helper will use the wait queue to sleep until the driver is done
rebuilding. Use of a wait queue is preferred because the potential sleep
duration can be several seconds.

To ensure that the thread wakes up properly, a new wake_up call is added
during all code paths which clear the reset state bits associated with
the driver rebuild flow.

Using this ensures that tools can request device information without
worrying about whether the driver is cleaning up from a reset.
Specifically, it is expected that a flash update could result in
a device reset, and it is better to delay the response for information
until the reset is complete rather than exit with an immediate failure.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Tony Brelinski <tonyx.brelinski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice.h
drivers/net/ethernet/intel/ice/ice_devlink.c
drivers/net/ethernet/intel/ice/ice_lib.c
drivers/net/ethernet/intel/ice/ice_lib.h
drivers/net/ethernet/intel/ice/ice_main.c

index 228055e8f33bc54ed67ae1186c5075e18986f810..21f8b36df11a530f7816e719df47468fbdc2f3df 100644 (file)
@@ -455,6 +455,8 @@ struct ice_pf {
        struct hlist_head aq_wait_list;
        wait_queue_head_t aq_wait_queue;
 
+       wait_queue_head_t reset_wait_queue;
+
        u32 hw_csum_rx_error;
        u16 oicr_idx;           /* Other interrupt cause MSIX vector index */
        u16 num_avail_sw_msix;  /* remaining MSIX SW vectors left unclaimed */
index 2923591d01ea5ebc1e5b69a0e2b3d56b605b88ba..91b545ab8b8f7590539482e857dc6baf03f2b59b 100644 (file)
@@ -276,6 +276,12 @@ static int ice_devlink_info_get(struct devlink *devlink,
        size_t i;
        int err;
 
+       err = ice_wait_for_reset(pf, 10 * HZ);
+       if (err) {
+               NL_SET_ERR_MSG_MOD(extack, "Device is busy resetting");
+               return err;
+       }
+
        ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
        if (!ctx)
                return -ENOMEM;
index 357c5d39913dabef82bb6738a7bbc39f3c8a3b5e..1c636f4bb4fcd2dc291290133b545e54536975a3 100644 (file)
@@ -3218,6 +3218,34 @@ bool ice_is_reset_in_progress(unsigned long *state)
               test_bit(ICE_GLOBR_REQ, state);
 }
 
+/**
+ * ice_wait_for_reset - Wait for driver to finish reset and rebuild
+ * @pf: pointer to the PF structure
+ * @timeout: length of time to wait, in jiffies
+ *
+ * Wait (sleep) for a short time until the driver finishes cleaning up from
+ * a device reset. The caller must be able to sleep. Use this to delay
+ * operations that could fail while the driver is cleaning up after a device
+ * reset.
+ *
+ * Returns 0 on success, -EBUSY if the reset is not finished within the
+ * timeout, and -ERESTARTSYS if the thread was interrupted.
+ */
+int ice_wait_for_reset(struct ice_pf *pf, unsigned long timeout)
+{
+       long ret;
+
+       ret = wait_event_interruptible_timeout(pf->reset_wait_queue,
+                                              !ice_is_reset_in_progress(pf->state),
+                                              timeout);
+       if (ret < 0)
+               return ret;
+       else if (!ret)
+               return -EBUSY;
+       else
+               return 0;
+}
+
 #ifdef CONFIG_DCB
 /**
  * ice_vsi_update_q_map - update our copy of the VSI info with new queue map
index 9bd619e2399a58bae171f2cff1ba69118081e967..6e2b8c2c8aa0cb2d91041cffd92705919553ea4d 100644 (file)
@@ -77,6 +77,7 @@ ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id);
 int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi);
 
 bool ice_is_reset_in_progress(unsigned long *state);
+int ice_wait_for_reset(struct ice_pf *pf, unsigned long timeout);
 
 void
 ice_write_qrxflxp_cntxt(struct ice_hw *hw, u16 pf_q, u32 rxdid, u32 prio);
index 254cfc14d6b43d21ff82eba501d6a1008cab8038..a89ca799109f642b3f9b408244c3d1832ebf1cbc 100644 (file)
@@ -503,6 +503,7 @@ static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
                clear_bit(ICE_PFR_REQ, pf->state);
                clear_bit(ICE_CORER_REQ, pf->state);
                clear_bit(ICE_GLOBR_REQ, pf->state);
+               wake_up(&pf->reset_wait_queue);
                return;
        }
 
@@ -515,6 +516,7 @@ static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
                ice_rebuild(pf, reset_type);
                clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
                clear_bit(ICE_PFR_REQ, pf->state);
+               wake_up(&pf->reset_wait_queue);
                ice_reset_all_vfs(pf, true);
        }
 }
@@ -565,6 +567,7 @@ static void ice_reset_subtask(struct ice_pf *pf)
                        clear_bit(ICE_PFR_REQ, pf->state);
                        clear_bit(ICE_CORER_REQ, pf->state);
                        clear_bit(ICE_GLOBR_REQ, pf->state);
+                       wake_up(&pf->reset_wait_queue);
                        ice_reset_all_vfs(pf, true);
                }
 
@@ -3343,6 +3346,8 @@ static int ice_init_pf(struct ice_pf *pf)
        spin_lock_init(&pf->aq_wait_lock);
        init_waitqueue_head(&pf->aq_wait_queue);
 
+       init_waitqueue_head(&pf->reset_wait_queue);
+
        /* setup service timer and periodic service task */
        timer_setup(&pf->serv_tmr, ice_service_timer, 0);
        pf->serv_tmr_period = HZ;