[SCSI] be2iscsi: cleans up abort handling
[linux-2.6-block.git] / drivers / scsi / be2iscsi / be_main.c
index d611a13dabf0555252b9dab8e526cee22b07f1a3..aee3734d86172d3d596304ea6b9a2a62b4e90b5b 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (C) 2005 - 2009 ServerEngines
+ * Copyright (C) 2005 - 2010 ServerEngines
  * All rights reserved.
  *
  * This program is free software; you can redistribute it and/or
@@ -40,7 +40,6 @@
 static unsigned int be_iopoll_budget = 10;
 static unsigned int be_max_phys_size = 64;
 static unsigned int enable_msix = 1;
-static unsigned int ring_mode;
 
 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
 MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
@@ -59,13 +58,130 @@ static int beiscsi_slave_configure(struct scsi_device *sdev)
        return 0;
 }
 
+static int beiscsi_eh_abort(struct scsi_cmnd *sc)
+{
+       struct iscsi_cls_session *cls_session;
+       struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
+       struct beiscsi_io_task *aborted_io_task;
+       struct iscsi_conn *conn;
+       struct beiscsi_conn *beiscsi_conn;
+       struct beiscsi_hba *phba;
+       struct iscsi_session *session;
+       struct invalidate_command_table *inv_tbl;
+       unsigned int cid, tag, num_invalidate;
+
+       cls_session = starget_to_session(scsi_target(sc->device));
+       session = cls_session->dd_data;
+
+       spin_lock_bh(&session->lock);
+       if (!aborted_task || !aborted_task->sc) {
+               /* we raced */
+               spin_unlock_bh(&session->lock);
+               return SUCCESS;
+       }
+
+       aborted_io_task = aborted_task->dd_data;
+       if (!aborted_io_task->scsi_cmnd) {
+               /* raced or invalid command */
+               spin_unlock_bh(&session->lock);
+               return SUCCESS;
+       }
+       spin_unlock_bh(&session->lock);
+       conn = aborted_task->conn;
+       beiscsi_conn = conn->dd_data;
+       phba = beiscsi_conn->phba;
+
+       /* invalidate iocb */
+       cid = beiscsi_conn->beiscsi_conn_cid;
+       inv_tbl = phba->inv_tbl;
+       memset(inv_tbl, 0x0, sizeof(*inv_tbl));
+       inv_tbl->cid = cid;
+       inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
+       num_invalidate = 1;
+       tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, cid);
+       if (!tag) {
+               shost_printk(KERN_WARNING, phba->shost,
+                            "mgmt_invalidate_icds could not be"
+                            " submitted\n");
+               return FAILED;
+       } else {
+               wait_event_interruptible(phba->ctrl.mcc_wait[tag],
+                                        phba->ctrl.mcc_numtag[tag]);
+               free_mcc_tag(&phba->ctrl, tag);
+       }
+
+       return iscsi_eh_abort(sc);
+}
+
+static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
+{
+       struct iscsi_task *abrt_task;
+       struct beiscsi_io_task *abrt_io_task;
+       struct iscsi_conn *conn;
+       struct beiscsi_conn *beiscsi_conn;
+       struct beiscsi_hba *phba;
+       struct iscsi_session *session;
+       struct iscsi_cls_session *cls_session;
+       struct invalidate_command_table *inv_tbl;
+       unsigned int cid, tag, i, num_invalidate;
+       int rc = FAILED;
+
+       /* invalidate iocbs */
+       cls_session = starget_to_session(scsi_target(sc->device));
+       session = cls_session->dd_data;
+       spin_lock_bh(&session->lock);
+       if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
+               goto unlock;
+
+       conn = session->leadconn;
+       beiscsi_conn = conn->dd_data;
+       phba = beiscsi_conn->phba;
+       cid = beiscsi_conn->beiscsi_conn_cid;
+       inv_tbl = phba->inv_tbl;
+       memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
+       num_invalidate = 0;
+       for (i = 0; i < conn->session->cmds_max; i++) {
+               abrt_task = conn->session->cmds[i];
+               abrt_io_task = abrt_task->dd_data;
+               if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
+                       continue;
+
+               if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
+                       continue;
+
+               inv_tbl->cid = cid;
+               inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
+               num_invalidate++;
+               inv_tbl++;
+       }
+       spin_unlock_bh(&session->lock);
+       inv_tbl = phba->inv_tbl;
+
+       tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, cid);
+       if (!tag) {
+               shost_printk(KERN_WARNING, phba->shost,
+                            "mgmt_invalidate_icds could not be"
+                            " submitted\n");
+               return FAILED;
+       } else {
+               wait_event_interruptible(phba->ctrl.mcc_wait[tag],
+                                        phba->ctrl.mcc_numtag[tag]);
+               free_mcc_tag(&phba->ctrl, tag);
+       }
+
+       return iscsi_eh_device_reset(sc);
+unlock:
+       spin_unlock_bh(&session->lock);
+       return rc;
+}
+
 /*------------------- PCI Driver operations and data ----------------- */
 static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
        { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
+       { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
        { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
        { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
        { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
-       { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID4) },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
@@ -75,12 +191,12 @@ static struct scsi_host_template beiscsi_sht = {
        .name = "ServerEngines 10Gbe open-iscsi Initiator Driver",
        .proc_name = DRV_NAME,
        .queuecommand = iscsi_queuecommand,
-       .eh_abort_handler = iscsi_eh_abort,
        .change_queue_depth = iscsi_change_queue_depth,
        .slave_configure = beiscsi_slave_configure,
        .target_alloc = iscsi_target_alloc,
-       .eh_device_reset_handler = iscsi_eh_device_reset,
-       .eh_target_reset_handler = iscsi_eh_target_reset,
+       .eh_abort_handler = beiscsi_eh_abort,
+       .eh_device_reset_handler = beiscsi_eh_device_reset,
+       .eh_target_reset_handler = iscsi_eh_session_reset,
        .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
        .can_queue = BE2_IO_DEPTH,
        .this_id = -1,
@@ -144,6 +260,7 @@ static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
                                struct pci_dev *pcidev)
 {
        u8 __iomem *addr;
+       int pcicfg_reg;
 
        addr = ioremap_nocache(pci_resource_start(pcidev, 2),
                               pci_resource_len(pcidev, 2));
@@ -160,13 +277,19 @@ static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
        phba->db_va = addr;
        phba->db_pa.u.a64.address =  pci_resource_start(pcidev, 4);
 
-       addr = ioremap_nocache(pci_resource_start(pcidev, 1),
-                              pci_resource_len(pcidev, 1));
+       if (phba->generation == BE_GEN2)
+               pcicfg_reg = 1;
+       else
+               pcicfg_reg = 0;
+
+       addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
+                              pci_resource_len(pcidev, pcicfg_reg));
+
        if (addr == NULL)
                goto pci_map_err;
        phba->ctrl.pcicfg = addr;
        phba->pci_va = addr;
-       phba->pci_pa.u.a64.address = pci_resource_start(pcidev, 1);
+       phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
        return 0;
 
 pci_map_err:
@@ -671,9 +794,7 @@ static void
 free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
                struct wrb_handle *pwrb_handle)
 {
-       if (!ring_mode)
-               pwrb_context->pwrb_handle_base[pwrb_context->free_index] =
-                                              pwrb_handle;
+       pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
        pwrb_context->wrb_handles_available++;
        if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
                pwrb_context->free_index = 0;
@@ -865,7 +986,6 @@ hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
 {
        struct hwi_wrb_context *pwrb_context;
        struct wrb_handle *pwrb_handle = NULL;
-       struct sgl_handle *psgl_handle = NULL;
        struct hwi_controller *phwi_ctrlr;
        struct iscsi_task *task;
        struct beiscsi_io_task *io_task;
@@ -873,23 +993,14 @@ hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
        struct iscsi_session *session = conn->session;
 
        phwi_ctrlr = phba->phwi_ctrlr;
-       if (ring_mode) {
-               psgl_handle = phba->sgl_hndl_array[((psol->
-                             dw[offsetof(struct amap_sol_cqe_ring, icd_index) /
-                               32] & SOL_ICD_INDEX_MASK) >> 6)];
-               pwrb_context = &phwi_ctrlr->wrb_context[psgl_handle->cid];
-               task = psgl_handle->task;
-               pwrb_handle = NULL;
-       } else {
-               pwrb_context = &phwi_ctrlr->wrb_context[((psol->
+       pwrb_context = &phwi_ctrlr->wrb_context[((psol->
                                dw[offsetof(struct amap_sol_cqe, cid) / 32] &
                                SOL_CID_MASK) >> 6) -
                                phba->fw_config.iscsi_cid_start];
-               pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
+       pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
                                dw[offsetof(struct amap_sol_cqe, wrb_index) /
                                32] & SOL_WRB_INDEX_MASK) >> 16)];
-               task = pwrb_handle->pio_handle;
-       }
+       task = pwrb_handle->pio_handle;
 
        io_task = task->dd_data;
        spin_lock(&phba->mgmt_sgl_lock);
@@ -930,45 +1041,40 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
        struct iscsi_wrb *pwrb = NULL;
        struct hwi_controller *phwi_ctrlr;
        struct iscsi_task *task;
-       struct sgl_handle *psgl_handle = NULL;
        unsigned int type;
        struct iscsi_conn *conn = beiscsi_conn->conn;
        struct iscsi_session *session = conn->session;
 
        phwi_ctrlr = phba->phwi_ctrlr;
-       if (ring_mode) {
-               psgl_handle = phba->sgl_hndl_array[((psol->
-                             dw[offsetof(struct amap_sol_cqe_ring, icd_index) /
-                             32] & SOL_ICD_INDEX_MASK) >> 6)];
-               task = psgl_handle->task;
-               type = psgl_handle->type;
-       } else {
-               pwrb_context = &phwi_ctrlr->
-                               wrb_context[((psol->dw[offsetof
+       pwrb_context = &phwi_ctrlr->wrb_context[((psol->dw[offsetof
                                (struct amap_sol_cqe, cid) / 32]
                                & SOL_CID_MASK) >> 6) -
                                phba->fw_config.iscsi_cid_start];
-               pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
+       pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
                                dw[offsetof(struct amap_sol_cqe, wrb_index) /
                                32] & SOL_WRB_INDEX_MASK) >> 16)];
-               task = pwrb_handle->pio_handle;
-               pwrb = pwrb_handle->pwrb;
-               type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] &
-                        WRB_TYPE_MASK) >> 28;
-       }
+       task = pwrb_handle->pio_handle;
+       pwrb = pwrb_handle->pwrb;
+       type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] &
+                                WRB_TYPE_MASK) >> 28;
+
        spin_lock_bh(&session->lock);
        switch (type) {
        case HWH_TYPE_IO:
        case HWH_TYPE_IO_RD:
                if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
-                   ISCSI_OP_NOOP_OUT) {
+                    ISCSI_OP_NOOP_OUT)
                        be_complete_nopin_resp(beiscsi_conn, task, psol);
-               else
+               else
                        be_complete_io(beiscsi_conn, task, psol);
                break;
 
        case HWH_TYPE_LOGOUT:
-               be_complete_logout(beiscsi_conn, task, psol);
+               if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
+                       be_complete_logout(beiscsi_conn, task, psol);
+               else
+                       be_complete_tmf(beiscsi_conn, task, psol);
+
                break;
 
        case HWH_TYPE_LOGIN:
@@ -977,24 +1083,12 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
                         "- Solicited path \n");
                break;
 
-       case HWH_TYPE_TMF:
-               be_complete_tmf(beiscsi_conn, task, psol);
-               break;
-
        case HWH_TYPE_NOP:
                be_complete_nopin_resp(beiscsi_conn, task, psol);
                break;
 
        default:
-               if (ring_mode)
-                       shost_printk(KERN_WARNING, phba->shost,
-                               "In hwi_complete_cmd, unknown type = %d"
-                               "icd_index 0x%x CID 0x%x\n", type,
-                               ((psol->dw[offsetof(struct amap_sol_cqe_ring,
-                               icd_index) / 32] & SOL_ICD_INDEX_MASK) >> 6),
-                               psgl_handle->cid);
-               else
-                       shost_printk(KERN_WARNING, phba->shost,
+               shost_printk(KERN_WARNING, phba->shost,
                                "In hwi_complete_cmd, unknown type = %d"
                                "wrb_index 0x%x CID 0x%x\n", type,
                                ((psol->dw[offsetof(struct amap_iscsi_wrb,
@@ -1483,7 +1577,6 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
        unsigned int num_processed = 0;
        unsigned int tot_nump = 0;
        struct beiscsi_conn *beiscsi_conn;
-       struct sgl_handle *psgl_handle = NULL;
        struct beiscsi_endpoint *beiscsi_ep;
        struct iscsi_endpoint *ep;
        struct beiscsi_hba *phba;
@@ -1496,18 +1589,11 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
               CQE_VALID_MASK) {
                be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
 
-               if (ring_mode) {
-                       psgl_handle = phba->sgl_hndl_array[((sol->
-                                     dw[offsetof(struct amap_sol_cqe_ring,
-                                     icd_index) / 32] & SOL_ICD_INDEX_MASK)
-                                     >> 6)];
-                       ep = phba->ep_array[psgl_handle->cid];
-               } else {
-                       ep = phba->ep_array[(u32) ((sol->
+               ep = phba->ep_array[(u32) ((sol->
                                   dw[offsetof(struct amap_sol_cqe, cid) / 32] &
                                   SOL_CID_MASK) >> 6) -
                                   phba->fw_config.iscsi_cid_start];
-               }
+
                beiscsi_ep = ep->dd_data;
                beiscsi_conn = beiscsi_ep->conn;
 
@@ -1553,21 +1639,13 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
                case CMD_CXN_KILLED_ITT_INVALID:
                case CMD_CXN_KILLED_SEQ_OUTOFORDER:
                case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
-                       if (ring_mode) {
-                               SE_DEBUG(DBG_LVL_1,
-                                "CQ Error notification for cmd.. "
-                                "code %d cid 0x%x\n",
-                                sol->dw[offsetof(struct amap_sol_cqe, code) /
-                                32] & CQE_CODE_MASK, psgl_handle->cid);
-                       } else {
-                               SE_DEBUG(DBG_LVL_1,
+                       SE_DEBUG(DBG_LVL_1,
                                 "CQ Error notification for cmd.. "
                                 "code %d cid 0x%x\n",
                                 sol->dw[offsetof(struct amap_sol_cqe, code) /
                                 32] & CQE_CODE_MASK,
                                 (sol->dw[offsetof(struct amap_sol_cqe, cid) /
                                 32] & SOL_CID_MASK));
-                       }
                        break;
                case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
                        SE_DEBUG(DBG_LVL_1,
@@ -1589,37 +1667,23 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
                case CXN_KILLED_OVER_RUN_RESIDUAL:
                case CXN_KILLED_UNDER_RUN_RESIDUAL:
                case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
-                       if (ring_mode) {
-                               SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset CID "
-                                "0x%x...\n",
-                                sol->dw[offsetof(struct amap_sol_cqe, code) /
-                                32] & CQE_CODE_MASK, psgl_handle->cid);
-                       } else {
-                               SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset CID "
+                       SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset CID "
                                 "0x%x...\n",
                                 sol->dw[offsetof(struct amap_sol_cqe, code) /
                                 32] & CQE_CODE_MASK,
                                 (sol->dw[offsetof(struct amap_sol_cqe, cid) /
                                 32] & CQE_CID_MASK));
-                       }
                        iscsi_conn_failure(beiscsi_conn->conn,
                                           ISCSI_ERR_CONN_FAILED);
                        break;
                case CXN_KILLED_RST_SENT:
                case CXN_KILLED_RST_RCVD:
-                       if (ring_mode) {
-                               SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset"
-                               "received/sent on CID 0x%x...\n",
-                                sol->dw[offsetof(struct amap_sol_cqe, code) /
-                                32] & CQE_CODE_MASK, psgl_handle->cid);
-                       } else {
-                               SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset"
+                       SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset"
                                "received/sent on CID 0x%x...\n",
                                 sol->dw[offsetof(struct amap_sol_cqe, code) /
                                 32] & CQE_CODE_MASK,
                                 (sol->dw[offsetof(struct amap_sol_cqe, cid) /
                                 32] & CQE_CID_MASK));
-                       }
                        iscsi_conn_failure(beiscsi_conn->conn,
                                           ISCSI_ERR_CONN_FAILED);
                        break;
@@ -1723,11 +1787,7 @@ hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
                        AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
                                                        sg_len);
                        sge_len = sg_len;
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
-                                                       1);
                } else {
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
-                                                       0);
                        AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
                                                        pwrb, sge_len);
                        sg_len = sg_dma_len(sg);
@@ -1750,8 +1810,22 @@ hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
        AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
                        io_task->bhs_pa.u.a32.address_lo);
 
-       if (num_sg == 2)
-               AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, 1);
+       if (num_sg == 1) {
+               AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
+                                                               1);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
+                                                               0);
+       } else if (num_sg == 2) {
+               AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
+                                                               0);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
+                                                               1);
+       } else {
+               AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
+                                                               0);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
+                                                               0);
+       }
        sg = l_sg;
        psgl++;
        psgl++;
@@ -2092,10 +2166,9 @@ static void beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
        }
        idx = 0;
        pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
-       num_cxn_wrb =
-           ((mem_descr_wrb->mem_array[idx].size) / (sizeof(struct iscsi_wrb)) *
-            phba->params.wrbs_per_cxn);
-
+       num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
+                     ((sizeof(struct iscsi_wrb) *
+                       phba->params.wrbs_per_cxn));
        for (index = 0; index < phba->params.cxns_per_ctrl; index += 2) {
                pwrb_context = &phwi_ctrlr->wrb_context[index];
                if (num_cxn_wrb) {
@@ -2108,9 +2181,9 @@ static void beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
                } else {
                        idx++;
                        pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
-                       num_cxn_wrb = ((mem_descr_wrb->mem_array[idx].size) /
-                                       (sizeof(struct iscsi_wrb)) *
-                                       phba->params.wrbs_per_cxn);
+                       num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
+                                     ((sizeof(struct iscsi_wrb) *
+                                       phba->params.wrbs_per_cxn));
                        for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
                                pwrb_handle = pwrb_context->pwrb_handle_base[j];
                                pwrb_handle->pwrb = pwrb;
@@ -2848,11 +2921,6 @@ static int hwi_init_port(struct beiscsi_hba *phba)
                goto error;
        }
 
-       if (phba->fw_config.iscsi_features == 0x1)
-               ring_mode = 1;
-       else
-               ring_mode = 0;
-
        status = beiscsi_create_cqs(phba, phwi_context);
        if (status != 0) {
                shost_printk(KERN_ERR, phba->shost, "CQ not created\n");
@@ -2980,17 +3048,6 @@ static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
        phba->io_sgl_hndl_avbl = 0;
        phba->eh_sgl_hndl_avbl = 0;
 
-       if (ring_mode) {
-               phba->sgl_hndl_array = kzalloc(sizeof(struct sgl_handle *) *
-                                             phba->params.icds_per_ctrl,
-                                                GFP_KERNEL);
-               if (!phba->sgl_hndl_array) {
-                       shost_printk(KERN_ERR, phba->shost,
-                            "Mem Alloc Failed. Failing to load\n");
-                       return -ENOMEM;
-               }
-       }
-
        mem_descr_sglh = phba->init_mem;
        mem_descr_sglh += HWI_MEM_SGLH;
        if (1 == mem_descr_sglh->num_elements) {
@@ -2998,8 +3055,6 @@ static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
                                                 phba->params.ios_per_ctrl,
                                                 GFP_KERNEL);
                if (!phba->io_sgl_hndl_base) {
-                       if (ring_mode)
-                               kfree(phba->sgl_hndl_array);
                        shost_printk(KERN_ERR, phba->shost,
                                     "Mem Alloc Failed. Failing to load\n");
                        return -ENOMEM;
@@ -3184,8 +3239,6 @@ static int beiscsi_init_port(struct beiscsi_hba *phba)
        if (hba_setup_cid_tbls(phba)) {
                shost_printk(KERN_ERR, phba->shost,
                             "Failed in hba_setup_cid_tbls\n");
-               if (ring_mode)
-                       kfree(phba->sgl_hndl_array);
                kfree(phba->io_sgl_hndl_base);
                kfree(phba->eh_sgl_hndl_base);
                goto do_cleanup_ctrlr;
@@ -3242,8 +3295,6 @@ static void beiscsi_clean_port(struct beiscsi_hba *phba)
 
        hwi_purge_eq(phba);
        hwi_cleanup(phba);
-       if (ring_mode)
-               kfree(phba->sgl_hndl_array);
        kfree(phba->io_sgl_hndl_base);
        kfree(phba->eh_sgl_hndl_base);
        kfree(phba->cid_array);
@@ -3329,8 +3380,7 @@ beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
        be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb));
 
        doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
-       if (!ring_mode)
-               doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
+       doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
                             << DB_DEF_PDU_WRB_INDEX_SHIFT;
        doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
 
@@ -3417,15 +3467,7 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
        itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
                                 wrb_index << 16) | (unsigned int)
                                (io_task->psgl_handle->sgl_index));
-       if (ring_mode) {
-               phba->sgl_hndl_array[io_task->psgl_handle->sgl_index -
-                                    phba->fw_config.iscsi_icd_start] =
-                                    io_task->psgl_handle;
-               io_task->psgl_handle->task = task;
-               io_task->psgl_handle->cid = beiscsi_conn->beiscsi_conn_cid  -
-                                           phba->fw_config.iscsi_cid_start;
-       } else
-               io_task->pwrb_handle->pio_handle = task;
+       io_task->pwrb_handle->pio_handle = task;
 
        io_task->cmd_bhs->iscsi_hdr.itt = itt;
        return 0;
@@ -3511,18 +3553,12 @@ static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
                              ISCSI_OPCODE_SCSI_DATA_OUT);
                AMAP_SET_BITS(struct amap_pdu_data_out, final_bit,
                              &io_task->cmd_bhs->iscsi_data_pdu, 1);
-               if (ring_mode)
-                       io_task->psgl_handle->type = INI_WR_CMD;
-               else
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
-                                     INI_WR_CMD);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
+                             INI_WR_CMD);
                AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
        } else {
-               if (ring_mode)
-                       io_task->psgl_handle->type = INI_RD_CMD;
-               else
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
-                                     INI_RD_CMD);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
+                             INI_RD_CMD);
                AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
        }
        memcpy(&io_task->cmd_bhs->iscsi_data_pdu.
@@ -3547,8 +3583,7 @@ static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
        be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
 
        doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
-       if (!ring_mode)
-               doorbell |= (io_task->pwrb_handle->wrb_index &
+       doorbell |= (io_task->pwrb_handle->wrb_index &
                     DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
        doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
 
@@ -3558,22 +3593,17 @@ static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
 
 static int beiscsi_mtask(struct iscsi_task *task)
 {
-       struct beiscsi_io_task *aborted_io_task, *io_task = task->dd_data;
+       struct beiscsi_io_task *io_task = task->dd_data;
        struct iscsi_conn *conn = task->conn;
        struct beiscsi_conn *beiscsi_conn = conn->dd_data;
        struct beiscsi_hba *phba = beiscsi_conn->phba;
-       struct iscsi_session *session;
        struct iscsi_wrb *pwrb = NULL;
-       struct hwi_controller *phwi_ctrlr;
-       struct hwi_wrb_context *pwrb_context;
-       struct wrb_handle *pwrb_handle;
        unsigned int doorbell = 0;
-       unsigned int i, cid;
-       struct iscsi_task *aborted_task;
-       unsigned int tag;
+       unsigned int cid;
 
        cid = beiscsi_conn->beiscsi_conn_cid;
        pwrb = io_task->pwrb_handle->pwrb;
+       memset(pwrb, 0, sizeof(*pwrb));
        AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
                      be32_to_cpu(task->cmdsn));
        AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
@@ -3583,21 +3613,15 @@ static int beiscsi_mtask(struct iscsi_task *task)
 
        switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
        case ISCSI_OP_LOGIN:
-               if (ring_mode)
-                       io_task->psgl_handle->type = TGT_DM_CMD;
-               else
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
-                                     TGT_DM_CMD);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
+                             TGT_DM_CMD);
                AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
                AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
                hwi_write_buffer(pwrb, task);
                break;
        case ISCSI_OP_NOOP_OUT:
-               if (ring_mode)
-                       io_task->psgl_handle->type = INI_RD_CMD;
-               else
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
-                                     INI_RD_CMD);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
+                             INI_RD_CMD);
                if (task->hdr->ttt == ISCSI_RESERVED_TAG)
                        AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
                else
@@ -3605,58 +3629,21 @@ static int beiscsi_mtask(struct iscsi_task *task)
                hwi_write_buffer(pwrb, task);
                break;
        case ISCSI_OP_TEXT:
-               if (ring_mode)
-                       io_task->psgl_handle->type = INI_WR_CMD;
-               else
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
-                                     INI_WR_CMD);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
+                             TGT_DM_CMD);
                AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
-               AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
                hwi_write_buffer(pwrb, task);
                break;
        case ISCSI_OP_SCSI_TMFUNC:
-               session = conn->session;
-               i = ((struct iscsi_tm *)task->hdr)->rtt;
-               phwi_ctrlr = phba->phwi_ctrlr;
-               pwrb_context = &phwi_ctrlr->wrb_context[cid -
-                                           phba->fw_config.iscsi_cid_start];
-               pwrb_handle = pwrb_context->pwrb_handle_basestd[be32_to_cpu(i)
-                                                               >> 16];
-               aborted_task = pwrb_handle->pio_handle;
-                if (!aborted_task)
-                       return 0;
-
-               aborted_io_task = aborted_task->dd_data;
-               if (!aborted_io_task->scsi_cmnd)
-                       return 0;
-
-               tag = mgmt_invalidate_icds(phba,
-                                    aborted_io_task->psgl_handle->sgl_index,
-                                    cid);
-               if (!tag) {
-                       shost_printk(KERN_WARNING, phba->shost,
-                                    "mgmt_invalidate_icds could not be"
-                                    " submitted\n");
-               } else {
-                       wait_event_interruptible(phba->ctrl.mcc_wait[tag],
-                                                phba->ctrl.mcc_numtag[tag]);
-                       free_mcc_tag(&phba->ctrl, tag);
-               }
-               if (ring_mode)
-                       io_task->psgl_handle->type = INI_TMF_CMD;
-               else
-                       AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
-                                     INI_TMF_CMD);
+               AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
+                             INI_TMF_CMD);
                AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
                hwi_write_buffer(pwrb, task);
                break;
        case ISCSI_OP_LOGOUT:
                AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
-               if (ring_mode)
-                       io_task->psgl_handle->type = HWH_TYPE_LOGOUT;
-               else
                AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
-                               HWH_TYPE_LOGOUT);
+                             HWH_TYPE_LOGOUT);
                hwi_write_buffer(pwrb, task);
                break;
 
@@ -3673,8 +3660,7 @@ static int beiscsi_mtask(struct iscsi_task *task)
        be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
 
        doorbell |= cid & DB_WRB_POST_CID_MASK;
-       if (!ring_mode)
-               doorbell |= (io_task->pwrb_handle->wrb_index &
+       doorbell |= (io_task->pwrb_handle->wrb_index &
                     DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
        doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
        iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
@@ -3683,17 +3669,12 @@ static int beiscsi_mtask(struct iscsi_task *task)
 
 static int beiscsi_task_xmit(struct iscsi_task *task)
 {
-       struct iscsi_conn *conn = task->conn;
        struct beiscsi_io_task *io_task = task->dd_data;
        struct scsi_cmnd *sc = task->sc;
-       struct beiscsi_conn *beiscsi_conn = conn->dd_data;
        struct scatterlist *sg;
        int num_sg;
        unsigned int  writedir = 0, xferlen = 0;
 
-       SE_DEBUG(DBG_LVL_4, "\n cid=%d In beiscsi_task_xmit task=%p conn=%p \t"
-                "beiscsi_conn=%p \n", beiscsi_conn->beiscsi_conn_cid,
-                task, conn, beiscsi_conn);
        if (!sc)
                return beiscsi_mtask(task);
 
@@ -3800,6 +3781,20 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
        }
        SE_DEBUG(DBG_LVL_8, " phba = %p \n", phba);
 
+       switch (pcidev->device) {
+       case BE_DEVICE_ID1:
+       case OC_DEVICE_ID1:
+       case OC_DEVICE_ID2:
+               phba->generation = BE_GEN2;
+               break;
+       case BE_DEVICE_ID2:
+       case OC_DEVICE_ID3:
+               phba->generation = BE_GEN3;
+               break;
+       default:
+               phba->generation = 0;
+       }
+
        if (enable_msix)
                num_cpus = find_num_cpus();
        else
@@ -3987,7 +3982,7 @@ static int __init beiscsi_module_init(void)
                SE_DEBUG(DBG_LVL_1,
                         "beiscsi_module_init - Unable to  register beiscsi"
                         "transport.\n");
-               ret = -ENOMEM;
+               return -ENOMEM;
        }
        SE_DEBUG(DBG_LVL_8, "In beiscsi_module_init, tt=%p \n",
                 &beiscsi_iscsi_transport);
@@ -3999,7 +3994,6 @@ static int __init beiscsi_module_init(void)
                         "beiscsi pci driver.\n");
                goto unregister_iscsi_transport;
        }
-       ring_mode = 0;
        return 0;
 
 unregister_iscsi_transport: