[SCSI] bnx2fc: use list_entry instead of explicit cast
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / scsi / bnx2fc / bnx2fc_tgt.c
index c1800b5..b9d0d9c 100644 (file)
@@ -150,8 +150,7 @@ tgt_init_err:
 void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
 {
        struct bnx2fc_cmd *io_req;
-       struct list_head *list;
-       struct list_head *tmp;
+       struct bnx2fc_cmd *tmp;
        int rc;
        int i = 0;
        BNX2FC_TGT_DBG(tgt, "Entered flush_active_ios - %d\n",
@@ -160,9 +159,8 @@ void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
        spin_lock_bh(&tgt->tgt_lock);
        tgt->flush_in_prog = 1;
 
-       list_for_each_safe(list, tmp, &tgt->active_cmd_queue) {
+       list_for_each_entry_safe(io_req, tmp, &tgt->active_cmd_queue, link) {
                i++;
-               io_req = (struct bnx2fc_cmd *)list;
                list_del_init(&io_req->link);
                io_req->on_active_queue = 0;
                BNX2FC_IO_DBG(io_req, "cmd_queue cleanup\n");
@@ -181,13 +179,27 @@ void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
 
                set_bit(BNX2FC_FLAG_IO_COMPL, &io_req->req_flags);
                set_bit(BNX2FC_FLAG_IO_CLEANUP, &io_req->req_flags);
-               rc = bnx2fc_initiate_cleanup(io_req);
-               BUG_ON(rc);
+
+               /* Do not issue cleanup when disable request failed */
+               if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags))
+                       bnx2fc_process_cleanup_compl(io_req, io_req->task, 0);
+               else {
+                       rc = bnx2fc_initiate_cleanup(io_req);
+                       BUG_ON(rc);
+               }
        }
 
-       list_for_each_safe(list, tmp, &tgt->els_queue) {
+       list_for_each_entry_safe(io_req, tmp, &tgt->active_tm_queue, link) {
+               i++;
+               list_del_init(&io_req->link);
+               io_req->on_tmf_queue = 0;
+               BNX2FC_IO_DBG(io_req, "tm_queue cleanup\n");
+               if (io_req->wait_for_comp)
+                       complete(&io_req->tm_done);
+       }
+
+       list_for_each_entry_safe(io_req, tmp, &tgt->els_queue, link) {
                i++;
-               io_req = (struct bnx2fc_cmd *)list;
                list_del_init(&io_req->link);
                io_req->on_active_queue = 0;
 
@@ -202,19 +214,32 @@ void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
                        io_req->cb_arg = NULL;
                }
 
-               rc = bnx2fc_initiate_cleanup(io_req);
-               BUG_ON(rc);
+               /* Do not issue cleanup when disable request failed */
+               if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags))
+                       bnx2fc_process_cleanup_compl(io_req, io_req->task, 0);
+               else {
+                       rc = bnx2fc_initiate_cleanup(io_req);
+                       BUG_ON(rc);
+               }
        }
 
-       list_for_each_safe(list, tmp, &tgt->io_retire_queue) {
+       list_for_each_entry_safe(io_req, tmp, &tgt->io_retire_queue, link) {
                i++;
-               io_req = (struct bnx2fc_cmd *)list;
                list_del_init(&io_req->link);
 
                BNX2FC_IO_DBG(io_req, "retire_queue flush\n");
 
-               if (cancel_delayed_work(&io_req->timeout_work))
+               if (cancel_delayed_work(&io_req->timeout_work)) {
+                       if (test_and_clear_bit(BNX2FC_FLAG_EH_ABORT,
+                                               &io_req->req_flags)) {
+                               /* Handle eh_abort timeout */
+                               BNX2FC_IO_DBG(io_req, "eh_abort for IO "
+                                             "in retire_q\n");
+                               if (io_req->wait_for_comp)
+                                       complete(&io_req->tm_done);
+                       }
                        kref_put(&io_req->refcount, bnx2fc_cmd_release);
+               }
 
                clear_bit(BNX2FC_FLAG_ISSUE_RRQ, &io_req->req_flags);
        }
@@ -302,9 +327,13 @@ static void bnx2fc_upload_session(struct fcoe_port *port,
 
                del_timer_sync(&tgt->upld_timer);
 
-       } else
+       } else if (test_bit(BNX2FC_FLAG_DISABLE_FAILED, &tgt->flags)) {
+               printk(KERN_ERR PFX "ERROR!! DISABLE req failed, destroy"
+                               " not sent to FW\n");
+       } else {
                printk(KERN_ERR PFX "ERROR!! DISABLE req timed out, destroy"
                                " not sent to FW\n");
+       }
 
        /* Free session resources */
        bnx2fc_free_session_resc(hba, tgt);