Merge git://git.infradead.org/battery-2.6
[firefly-linux-kernel-4.4.55.git] / drivers / scsi / bnx2i / bnx2i_init.c
index af6a00a600fbff3c23d375d0559497e4ccec1160..50c2aa3b8eb1dfa7408dba3963ac39cc9475386e 100644 (file)
@@ -17,15 +17,17 @@ static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list);
 static u32 adapter_count;
 
 #define DRV_MODULE_NAME                "bnx2i"
-#define DRV_MODULE_VERSION     "2.1.1"
-#define DRV_MODULE_RELDATE     "Mar 24, 2010"
+#define DRV_MODULE_VERSION     "2.1.3"
+#define DRV_MODULE_RELDATE     "Aug 10, 2010"
 
 static char version[] __devinitdata =
                "Broadcom NetXtreme II iSCSI Driver " DRV_MODULE_NAME \
                " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
 
 
-MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com>");
+MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and "
+             "Eddie Wai <eddie.wai@broadcom.com>");
+
 MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/57710/57711"
                   " iSCSI Driver");
 MODULE_LICENSE("GPL");
@@ -166,6 +168,38 @@ void bnx2i_start(void *handle)
 }
 
 
+/**
+ * bnx2i_chip_cleanup - local routine to handle chip cleanup
+ * @hba:       Adapter instance to register
+ *
+ * Driver checks if adapter still has any active connections before
+ *     executing the cleanup process
+ */
+static void bnx2i_chip_cleanup(struct bnx2i_hba *hba)
+{
+       struct bnx2i_endpoint *bnx2i_ep;
+       struct list_head *pos, *tmp;
+
+       if (hba->ofld_conns_active) {
+               /* Stage to force the disconnection
+                * This is the case where the daemon is either slow or
+                * not present
+                */
+               printk(KERN_ALERT "bnx2i: (%s) chip cleanup for %d active "
+                       "connections\n", hba->netdev->name,
+                       hba->ofld_conns_active);
+               mutex_lock(&hba->net_dev_lock);
+               list_for_each_safe(pos, tmp, &hba->ep_active_list) {
+                       bnx2i_ep = list_entry(pos, struct bnx2i_endpoint, link);
+                       /* Clean up the chip only */
+                       bnx2i_hw_ep_disconnect(bnx2i_ep);
+                       bnx2i_ep->cm_sk = NULL;
+               }
+               mutex_unlock(&hba->net_dev_lock);
+       }
+}
+
+
 /**
  * bnx2i_stop - cnic callback to shutdown adapter instance
  * @handle:    transparent handle pointing to adapter structure
@@ -176,6 +210,7 @@ void bnx2i_start(void *handle)
 void bnx2i_stop(void *handle)
 {
        struct bnx2i_hba *hba = handle;
+       int conns_active;
 
        /* check if cleanup happened in GOING_DOWN context */
        if (!test_and_clear_bit(ADAPTER_STATE_GOING_DOWN,
@@ -187,9 +222,16 @@ void bnx2i_stop(void *handle)
         *  control returns to network driver. So it is required to cleanup and
         * release all connection resources before returning from this routine.
         */
-       wait_event_interruptible_timeout(hba->eh_wait,
-                                        (hba->ofld_conns_active == 0),
-                                        hba->hba_shutdown_tmo);
+       while (hba->ofld_conns_active) {
+               conns_active = hba->ofld_conns_active;
+               wait_event_interruptible_timeout(hba->eh_wait,
+                               (hba->ofld_conns_active != conns_active),
+                               hba->hba_shutdown_tmo);
+               if (hba->ofld_conns_active == conns_active)
+                       break;
+       }
+       bnx2i_chip_cleanup(hba);
+
        /* This flag should be cleared last so that ep_disconnect() gracefully
         * cleans up connection context
         */
@@ -430,6 +472,7 @@ static void __exit bnx2i_mod_exit(void)
                adapter_count--;
 
                if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
+                       bnx2i_chip_cleanup(hba);
                        hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
                        clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
                }