[SCSI] iscsi class: sysfs group is_visible callout for session attrs
[linux-2.6.git] / drivers / scsi / be2iscsi / be_main.c
index 67a7e3f..93a3c70 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (C) 2005 - 2010 ServerEngines
+ * Copyright (C) 2005 - 2011 Emulex
  * All rights reserved.
  *
  * This program is free software; you can redistribute it and/or
@@ -7,16 +7,16 @@
  * as published by the Free Software Foundation.  The full GNU General
  * Public License is included in this distribution in the file called COPYING.
  *
- * Written by: Jayamohan Kallickal (jayamohank@serverengines.com)
+ * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
  *
  * Contact Information:
- * linux-drivers@serverengines.com
- *
- *  ServerEngines
- * 209 N. Fair Oaks Ave
- * Sunnyvale, CA 94085
+ * linux-drivers@emulex.com
  *
+ * Emulex
+ * 3333 Susan Street
+ * Costa Mesa, CA 92626
  */
+
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
@@ -26,6 +26,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/semaphore.h>
+#include <linux/iscsi_boot_sysfs.h>
 
 #include <scsi/libiscsi.h>
 #include <scsi/scsi_transport_iscsi.h>
@@ -41,6 +42,8 @@
 static unsigned int be_iopoll_budget = 10;
 static unsigned int be_max_phys_size = 64;
 static unsigned int enable_msix = 1;
+static unsigned int gcrashmode = 0;
+static unsigned int num_hba = 0;
 
 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
 MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
@@ -69,6 +72,7 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc)
        struct beiscsi_hba *phba;
        struct iscsi_session *session;
        struct invalidate_command_table *inv_tbl;
+       struct be_dma_mem nonemb_cmd;
        unsigned int cid, tag, num_invalidate;
 
        cls_session = starget_to_session(scsi_target(sc->device));
@@ -99,18 +103,34 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc)
        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);
+       nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+                               sizeof(struct invalidate_commands_params_in),
+                               &nonemb_cmd.dma);
+       if (nonemb_cmd.va == NULL) {
+               SE_DEBUG(DBG_LVL_1,
+                        "Failed to allocate memory for"
+                        "mgmt_invalidate_icds\n");
+               return FAILED;
+       }
+       nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
+
+       tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
+                                  cid, &nonemb_cmd);
        if (!tag) {
                shost_printk(KERN_WARNING, phba->shost,
                             "mgmt_invalidate_icds could not be"
                             " submitted\n");
+               pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+                                   nonemb_cmd.va, nonemb_cmd.dma);
+
                return FAILED;
        } else {
                wait_event_interruptible(phba->ctrl.mcc_wait[tag],
                                         phba->ctrl.mcc_numtag[tag]);
                free_mcc_tag(&phba->ctrl, tag);
        }
-
+       pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+                           nonemb_cmd.va, nonemb_cmd.dma);
        return iscsi_eh_abort(sc);
 }
 
@@ -124,6 +144,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
        struct iscsi_session *session;
        struct iscsi_cls_session *cls_session;
        struct invalidate_command_table *inv_tbl;
+       struct be_dma_mem nonemb_cmd;
        unsigned int cid, tag, i, num_invalidate;
        int rc = FAILED;
 
@@ -158,24 +179,207 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
        spin_unlock_bh(&session->lock);
        inv_tbl = phba->inv_tbl;
 
-       tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, cid);
+       nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+                               sizeof(struct invalidate_commands_params_in),
+                               &nonemb_cmd.dma);
+       if (nonemb_cmd.va == NULL) {
+               SE_DEBUG(DBG_LVL_1,
+                        "Failed to allocate memory for"
+                        "mgmt_invalidate_icds\n");
+               return FAILED;
+       }
+       nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
+       memset(nonemb_cmd.va, 0, nonemb_cmd.size);
+       tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
+                                  cid, &nonemb_cmd);
        if (!tag) {
                shost_printk(KERN_WARNING, phba->shost,
                             "mgmt_invalidate_icds could not be"
                             " submitted\n");
+               pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+                                   nonemb_cmd.va, nonemb_cmd.dma);
                return FAILED;
        } else {
                wait_event_interruptible(phba->ctrl.mcc_wait[tag],
                                         phba->ctrl.mcc_numtag[tag]);
                free_mcc_tag(&phba->ctrl, tag);
        }
-
+       pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+                           nonemb_cmd.va, nonemb_cmd.dma);
        return iscsi_eh_device_reset(sc);
 unlock:
        spin_unlock_bh(&session->lock);
        return rc;
 }
 
+static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
+{
+       struct beiscsi_hba *phba = data;
+       struct mgmt_session_info *boot_sess = &phba->boot_sess;
+       struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
+       char *str = buf;
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_TGT_NAME:
+               rc = sprintf(buf, "%.*s\n",
+                           (int)strlen(boot_sess->target_name),
+                           (char *)&boot_sess->target_name);
+               break;
+       case ISCSI_BOOT_TGT_IP_ADDR:
+               if (boot_conn->dest_ipaddr.ip_type == 0x1)
+                       rc = sprintf(buf, "%pI4\n",
+                               (char *)&boot_conn->dest_ipaddr.ip_address);
+               else
+                       rc = sprintf(str, "%pI6\n",
+                               (char *)&boot_conn->dest_ipaddr.ip_address);
+               break;
+       case ISCSI_BOOT_TGT_PORT:
+               rc = sprintf(str, "%d\n", boot_conn->dest_port);
+               break;
+
+       case ISCSI_BOOT_TGT_CHAP_NAME:
+               rc = sprintf(str,  "%.*s\n",
+                            boot_conn->negotiated_login_options.auth_data.chap.
+                            target_chap_name_length,
+                            (char *)&boot_conn->negotiated_login_options.
+                            auth_data.chap.target_chap_name);
+               break;
+       case ISCSI_BOOT_TGT_CHAP_SECRET:
+               rc = sprintf(str,  "%.*s\n",
+                            boot_conn->negotiated_login_options.auth_data.chap.
+                            target_secret_length,
+                            (char *)&boot_conn->negotiated_login_options.
+                            auth_data.chap.target_secret);
+               break;
+       case ISCSI_BOOT_TGT_REV_CHAP_NAME:
+               rc = sprintf(str,  "%.*s\n",
+                            boot_conn->negotiated_login_options.auth_data.chap.
+                            intr_chap_name_length,
+                            (char *)&boot_conn->negotiated_login_options.
+                            auth_data.chap.intr_chap_name);
+               break;
+       case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
+               rc = sprintf(str,  "%.*s\n",
+                            boot_conn->negotiated_login_options.auth_data.chap.
+                            intr_secret_length,
+                            (char *)&boot_conn->negotiated_login_options.
+                            auth_data.chap.intr_secret);
+               break;
+       case ISCSI_BOOT_TGT_FLAGS:
+               rc = sprintf(str, "2\n");
+               break;
+       case ISCSI_BOOT_TGT_NIC_ASSOC:
+               rc = sprintf(str, "0\n");
+               break;
+       default:
+               rc = -ENOSYS;
+               break;
+       }
+       return rc;
+}
+
+static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
+{
+       struct beiscsi_hba *phba = data;
+       char *str = buf;
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_INI_INITIATOR_NAME:
+               rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
+               break;
+       default:
+               rc = -ENOSYS;
+               break;
+       }
+       return rc;
+}
+
+static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
+{
+       struct beiscsi_hba *phba = data;
+       char *str = buf;
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_ETH_FLAGS:
+               rc = sprintf(str, "2\n");
+               break;
+       case ISCSI_BOOT_ETH_INDEX:
+               rc = sprintf(str, "0\n");
+               break;
+       case ISCSI_BOOT_ETH_MAC:
+               rc  = beiscsi_get_macaddr(buf, phba);
+               if (rc < 0) {
+                       SE_DEBUG(DBG_LVL_1, "beiscsi_get_macaddr Failed\n");
+                       return rc;
+               }
+       break;
+       default:
+               rc = -ENOSYS;
+               break;
+       }
+       return rc;
+}
+
+
+static mode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
+{
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_TGT_NAME:
+       case ISCSI_BOOT_TGT_IP_ADDR:
+       case ISCSI_BOOT_TGT_PORT:
+       case ISCSI_BOOT_TGT_CHAP_NAME:
+       case ISCSI_BOOT_TGT_CHAP_SECRET:
+       case ISCSI_BOOT_TGT_REV_CHAP_NAME:
+       case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
+       case ISCSI_BOOT_TGT_NIC_ASSOC:
+       case ISCSI_BOOT_TGT_FLAGS:
+               rc = S_IRUGO;
+               break;
+       default:
+               rc = 0;
+               break;
+       }
+       return rc;
+}
+
+static mode_t beiscsi_ini_get_attr_visibility(void *data, int type)
+{
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_INI_INITIATOR_NAME:
+               rc = S_IRUGO;
+               break;
+       default:
+               rc = 0;
+               break;
+       }
+       return rc;
+}
+
+
+static mode_t beiscsi_eth_get_attr_visibility(void *data, int type)
+{
+       int rc;
+
+       switch (type) {
+       case ISCSI_BOOT_ETH_FLAGS:
+       case ISCSI_BOOT_ETH_MAC:
+       case ISCSI_BOOT_ETH_INDEX:
+               rc = S_IRUGO;
+               break;
+       default:
+               rc = 0;
+               break;
+       }
+       return rc;
+}
+
 /*------------------- PCI Driver operations and data ----------------- */
 static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
        { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
@@ -233,6 +437,7 @@ static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
 
        if (iscsi_host_add(shost, &phba->pcidev->dev))
                goto free_devices;
+
        return phba;
 
 free_devices:
@@ -361,7 +566,7 @@ static void beiscsi_get_params(struct beiscsi_hba *phba)
                                    + BE2_NOPOUT_REQ));
        phba->params.cxns_per_ctrl = phba->fw_config.iscsi_cid_count;
        phba->params.asyncpdus_per_ctrl = phba->fw_config.iscsi_cid_count * 2;
-       phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;;
+       phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;
        phba->params.num_sge_per_io = BE2_SGE;
        phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
        phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
@@ -524,7 +729,7 @@ static irqreturn_t be_isr(int irq, void *dev_id)
        int isr;
 
        phba = dev_id;
-       ctrl = &phba->ctrl;;
+       ctrl = &phba->ctrl;
        isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
                       (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
        if (!isr)
@@ -1783,7 +1988,7 @@ hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
              unsigned int num_sg, struct beiscsi_io_task *io_task)
 {
        struct iscsi_sge *psgl;
-       unsigned short sg_len, index;
+       unsigned int sg_len, index;
        unsigned int sge_len = 0;
        unsigned long long addr;
        struct scatterlist *l_sg;
@@ -3207,23 +3412,23 @@ static void hwi_enable_intr(struct beiscsi_hba *phba)
        addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
                        PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
        reg = ioread32(addr);
-       SE_DEBUG(DBG_LVL_8, "reg =x%08x\n", reg);
 
        enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
        if (!enabled) {
                reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
                SE_DEBUG(DBG_LVL_8, "reg =x%08x addr=%p\n", reg, addr);
                iowrite32(reg, addr);
-               if (!phba->msix_enabled) {
-                       eq = &phwi_context->be_eq[0].q;
+       }
+
+       if (!phba->msix_enabled) {
+               eq = &phwi_context->be_eq[0].q;
+               SE_DEBUG(DBG_LVL_8, "eq->id=%d\n", eq->id);
+               hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
+       } else {
+               for (i = 0; i <= phba->num_cpus; i++) {
+                       eq = &phwi_context->be_eq[i].q;
                        SE_DEBUG(DBG_LVL_8, "eq->id=%d\n", eq->id);
                        hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
-               } else {
-                       for (i = 0; i <= phba->num_cpus; i++) {
-                               eq = &phwi_context->be_eq[i].q;
-                               SE_DEBUG(DBG_LVL_8, "eq->id=%d\n", eq->id);
-                               hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
-                       }
                }
        }
 }
@@ -3244,6 +3449,145 @@ static void hwi_disable_intr(struct beiscsi_hba *phba)
                             "In hwi_disable_intr, Already Disabled\n");
 }
 
+static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
+{
+       struct be_cmd_resp_get_boot_target *boot_resp;
+       struct be_cmd_resp_get_session *session_resp;
+       struct be_mcc_wrb *wrb;
+       struct be_dma_mem nonemb_cmd;
+       unsigned int tag, wrb_num;
+       unsigned short status, extd_status;
+       struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
+       int ret = -ENOMEM;
+
+       tag = beiscsi_get_boot_target(phba);
+       if (!tag) {
+               SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n");
+               return -EAGAIN;
+       } else
+               wait_event_interruptible(phba->ctrl.mcc_wait[tag],
+                                        phba->ctrl.mcc_numtag[tag]);
+
+       wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
+       extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
+       status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
+       if (status || extd_status) {
+               SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed"
+                                   " status = %d extd_status = %d\n",
+                                   status, extd_status);
+               free_mcc_tag(&phba->ctrl, tag);
+               return -EBUSY;
+       }
+       wrb = queue_get_wrb(mccq, wrb_num);
+       free_mcc_tag(&phba->ctrl, tag);
+       boot_resp = embedded_payload(wrb);
+
+       if (boot_resp->boot_session_handle < 0) {
+               shost_printk(KERN_INFO, phba->shost, "No Boot Session.\n");
+               return -ENXIO;
+       }
+
+       nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
+                               sizeof(*session_resp),
+                               &nonemb_cmd.dma);
+       if (nonemb_cmd.va == NULL) {
+               SE_DEBUG(DBG_LVL_1,
+                        "Failed to allocate memory for"
+                        "beiscsi_get_session_info\n");
+               return -ENOMEM;
+       }
+
+       memset(nonemb_cmd.va, 0, sizeof(*session_resp));
+       tag = beiscsi_get_session_info(phba,
+               boot_resp->boot_session_handle, &nonemb_cmd);
+       if (!tag) {
+               SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info"
+                       " Failed\n");
+               goto boot_freemem;
+       } else
+               wait_event_interruptible(phba->ctrl.mcc_wait[tag],
+                                        phba->ctrl.mcc_numtag[tag]);
+
+       wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
+       extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
+       status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
+       if (status || extd_status) {
+               SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info Failed"
+                                   " status = %d extd_status = %d\n",
+                                   status, extd_status);
+               free_mcc_tag(&phba->ctrl, tag);
+               goto boot_freemem;
+       }
+       wrb = queue_get_wrb(mccq, wrb_num);
+       free_mcc_tag(&phba->ctrl, tag);
+       session_resp = nonemb_cmd.va ;
+
+       memcpy(&phba->boot_sess, &session_resp->session_info,
+              sizeof(struct mgmt_session_info));
+       ret = 0;
+
+boot_freemem:
+       pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
+                   nonemb_cmd.va, nonemb_cmd.dma);
+       return ret;
+}
+
+static void beiscsi_boot_release(void *data)
+{
+       struct beiscsi_hba *phba = data;
+
+       scsi_host_put(phba->shost);
+}
+
+static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
+{
+       struct iscsi_boot_kobj *boot_kobj;
+
+       /* get boot info using mgmt cmd */
+       if (beiscsi_get_boot_info(phba))
+               /* Try to see if we can carry on without this */
+               return 0;
+
+       phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
+       if (!phba->boot_kset)
+               return -ENOMEM;
+
+       /* get a ref because the show function will ref the phba */
+       if (!scsi_host_get(phba->shost))
+               goto free_kset;
+       boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
+                                            beiscsi_show_boot_tgt_info,
+                                            beiscsi_tgt_get_attr_visibility,
+                                            beiscsi_boot_release);
+       if (!boot_kobj)
+               goto put_shost;
+
+       if (!scsi_host_get(phba->shost))
+               goto free_kset;
+       boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
+                                               beiscsi_show_boot_ini_info,
+                                               beiscsi_ini_get_attr_visibility,
+                                               beiscsi_boot_release);
+       if (!boot_kobj)
+               goto put_shost;
+
+       if (!scsi_host_get(phba->shost))
+               goto free_kset;
+       boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
+                                              beiscsi_show_boot_eth_info,
+                                              beiscsi_eth_get_attr_visibility,
+                                              beiscsi_boot_release);
+       if (!boot_kobj)
+               goto put_shost;
+       return 0;
+
+put_shost:
+       scsi_host_put(phba->shost);
+free_kset:
+       iscsi_boot_destroy_kset(phba->boot_kset);
+       return -ENOMEM;
+}
+
 static int beiscsi_init_port(struct beiscsi_hba *phba)
 {
        int ret;
@@ -3445,19 +3789,17 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
        dma_addr_t paddr;
 
        io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
-                                         GFP_KERNEL, &paddr);
+                                         GFP_ATOMIC, &paddr);
        if (!io_task->cmd_bhs)
                return -ENOMEM;
        io_task->bhs_pa.u.a64.address = paddr;
        io_task->libiscsi_itt = (itt_t)task->itt;
-       io_task->pwrb_handle = alloc_wrb_handle(phba,
-                                               beiscsi_conn->beiscsi_conn_cid -
-                                               phba->fw_config.iscsi_cid_start
-                                               );
        io_task->conn = beiscsi_conn;
 
        task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
        task->hdr_max = sizeof(struct be_cmd_bhs);
+       io_task->psgl_handle = NULL;
+       io_task->psgl_handle = NULL;
 
        if (task->sc) {
                spin_lock(&phba->io_sgl_lock);
@@ -3465,6 +3807,11 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
                spin_unlock(&phba->io_sgl_lock);
                if (!io_task->psgl_handle)
                        goto free_hndls;
+               io_task->pwrb_handle = alloc_wrb_handle(phba,
+                                       beiscsi_conn->beiscsi_conn_cid -
+                                       phba->fw_config.iscsi_cid_start);
+               if (!io_task->pwrb_handle)
+                       goto free_io_hndls;
        } else {
                io_task->scsi_cmnd = NULL;
                if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
@@ -3479,9 +3826,20 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
                                beiscsi_conn->login_in_progress = 1;
                                beiscsi_conn->plogin_sgl_handle =
                                                        io_task->psgl_handle;
+                               io_task->pwrb_handle =
+                                       alloc_wrb_handle(phba,
+                                       beiscsi_conn->beiscsi_conn_cid -
+                                       phba->fw_config.iscsi_cid_start);
+                               if (!io_task->pwrb_handle)
+                                       goto free_io_hndls;
+                               beiscsi_conn->plogin_wrb_handle =
+                                                       io_task->pwrb_handle;
+
                        } else {
                                io_task->psgl_handle =
                                                beiscsi_conn->plogin_sgl_handle;
+                               io_task->pwrb_handle =
+                                               beiscsi_conn->plogin_wrb_handle;
                        }
                } else {
                        spin_lock(&phba->mgmt_sgl_lock);
@@ -3489,6 +3847,13 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
                        spin_unlock(&phba->mgmt_sgl_lock);
                        if (!io_task->psgl_handle)
                                goto free_hndls;
+                       io_task->pwrb_handle =
+                                       alloc_wrb_handle(phba,
+                                       beiscsi_conn->beiscsi_conn_cid -
+                                       phba->fw_config.iscsi_cid_start);
+                       if (!io_task->pwrb_handle)
+                               goto free_mgmt_hndls;
+
                }
        }
        itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
@@ -3499,12 +3864,22 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
        io_task->cmd_bhs->iscsi_hdr.itt = itt;
        return 0;
 
+free_io_hndls:
+       spin_lock(&phba->io_sgl_lock);
+       free_io_sgl_handle(phba, io_task->psgl_handle);
+       spin_unlock(&phba->io_sgl_lock);
+       goto free_hndls;
+free_mgmt_hndls:
+       spin_lock(&phba->mgmt_sgl_lock);
+       free_mgmt_sgl_handle(phba, io_task->psgl_handle);
+       spin_unlock(&phba->mgmt_sgl_lock);
 free_hndls:
        phwi_ctrlr = phba->phwi_ctrlr;
        pwrb_context = &phwi_ctrlr->wrb_context[
                        beiscsi_conn->beiscsi_conn_cid -
                        phba->fw_config.iscsi_cid_start];
-       free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
+       if (io_task->pwrb_handle)
+               free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
        io_task->pwrb_handle = NULL;
        pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
                      io_task->bhs_pa.u.a64.address);
@@ -3543,7 +3918,8 @@ static void beiscsi_cleanup_task(struct iscsi_task *task)
                        io_task->psgl_handle = NULL;
                }
        } else {
-               if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN)
+               if (task->hdr &&
+                  ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN))
                        return;
                if (io_task->psgl_handle) {
                        spin_lock(&phba->mgmt_sgl_lock);
@@ -3590,11 +3966,10 @@ static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
        }
        memcpy(&io_task->cmd_bhs->iscsi_data_pdu.
               dw[offsetof(struct amap_pdu_data_out, lun) / 32],
-              io_task->cmd_bhs->iscsi_hdr.lun, sizeof(struct scsi_lun));
+              &io_task->cmd_bhs->iscsi_hdr.lun, sizeof(struct scsi_lun));
 
        AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
-                     cpu_to_be16((unsigned short)io_task->cmd_bhs->iscsi_hdr.
-                                 lun[0]));
+                     cpu_to_be16(*(unsigned short *)&io_task->cmd_bhs->iscsi_hdr.lun));
        AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
        AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
                      io_task->pwrb_handle->wrb_index);
@@ -3647,12 +4022,17 @@ static int beiscsi_mtask(struct iscsi_task *task)
                hwi_write_buffer(pwrb, task);
                break;
        case ISCSI_OP_NOOP_OUT:
-               AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
-                             INI_RD_CMD);
-               if (task->hdr->ttt == ISCSI_RESERVED_TAG)
+               if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
+                       AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
+                                     TGT_DM_CMD);
+                       AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt,
+                                     pwrb, 0);
                        AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
-               else
+               } else {
+                       AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
+                                     INI_RD_CMD);
                        AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
+               }
                hwi_write_buffer(pwrb, task);
                break;
        case ISCSI_OP_TEXT:
@@ -3711,8 +4091,6 @@ static int beiscsi_task_xmit(struct iscsi_task *task)
                SE_DEBUG(DBG_LVL_1, " scsi_dma_map Failed\n")
                return num_sg;
        }
-       SE_DEBUG(DBG_LVL_4, "xferlen=0x%08x scmd=%p num_sg=%d sernum=%lu\n",
-                 (scsi_bufflen(sc)), sc, num_sg, sc->serial_number);
        xferlen = scsi_bufflen(sc);
        sg = scsi_sglist(sc);
        if (sc->sc_data_direction == DMA_TO_DEVICE) {
@@ -3731,6 +4109,8 @@ static void beiscsi_remove(struct pci_dev *pcidev)
        struct hwi_context_memory *phwi_context;
        struct be_eq_obj *pbe_eq;
        unsigned int i, msix_vec;
+       u8 *real_offset = 0;
+       u32 value = 0;
 
        phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
        if (!phba) {
@@ -3759,11 +4139,20 @@ static void beiscsi_remove(struct pci_dev *pcidev)
 
        beiscsi_clean_port(phba);
        beiscsi_free_mem(phba);
+       real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
+
+       value = readl((void *)real_offset);
+
+       if (value & 0x00010000) {
+               value &= 0xfffeffff;
+               writel(value, (void *)real_offset);
+       }
        beiscsi_unmap_pci_function(phba);
        pci_free_consistent(phba->pcidev,
                            phba->ctrl.mbox_mem_alloced.size,
                            phba->ctrl.mbox_mem_alloced.va,
                            phba->ctrl.mbox_mem_alloced.dma);
+       iscsi_boot_destroy_kset(phba->boot_kset);
        iscsi_host_remove(phba->shost);
        pci_dev_put(phba->pcidev);
        iscsi_host_free(phba->shost);
@@ -3792,6 +4181,8 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
        struct hwi_context_memory *phwi_context;
        struct be_eq_obj *pbe_eq;
        int ret, num_cpus, i;
+       u8 *real_offset = 0;
+       u32 value = 0;
 
        ret = beiscsi_enable_pci(pcidev);
        if (ret < 0) {
@@ -3837,6 +4228,33 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
                goto hba_free;
        }
 
+       if (!num_hba) {
+               real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
+               value = readl((void *)real_offset);
+               if (value & 0x00010000) {
+                       gcrashmode++;
+                       shost_printk(KERN_ERR, phba->shost,
+                               "Loading Driver in crashdump mode\n");
+                       ret = beiscsi_pci_soft_reset(phba);
+                       if (ret) {
+                               shost_printk(KERN_ERR, phba->shost,
+                                       "Reset Failed. Aborting Crashdump\n");
+                               goto hba_free;
+                       }
+                       ret = be_chk_reset_complete(phba);
+                       if (ret) {
+                               shost_printk(KERN_ERR, phba->shost,
+                                       "Failed to get out of reset."
+                                       "Aborting Crashdump\n");
+                               goto hba_free;
+                       }
+               } else {
+                       value |= 0x00010000;
+                       writel(value, (void *)real_offset);
+                       num_hba++;
+               }
+       }
+
        spin_lock_init(&phba->io_sgl_lock);
        spin_lock_init(&phba->mgmt_sgl_lock);
        spin_lock_init(&phba->isr_lock);
@@ -3867,7 +4285,7 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
 
        snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_q_irq%u",
                 phba->shost->host_no);
-       phba->wq = create_workqueue(phba->wq_name);
+       phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1);
        if (!phba->wq) {
                shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
                                "Failed to allocate work queue\n");
@@ -3893,6 +4311,15 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
                goto free_blkenbld;
        }
        hwi_enable_intr(phba);
+
+       if (beiscsi_setup_boot_info(phba))
+               /*
+                * log error but continue, because we may not be using
+                * iscsi boot.
+                */
+               shost_printk(KERN_ERR, phba->shost, "Could not set up "
+                            "iSCSI boot info.");
+
        SE_DEBUG(DBG_LVL_8, "\n\n\n SUCCESS - DRIVER LOADED\n\n\n");
        return 0;
 
@@ -3907,6 +4334,15 @@ free_twq:
        beiscsi_clean_port(phba);
        beiscsi_free_mem(phba);
 free_port:
+       real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
+
+       value = readl((void *)real_offset);
+
+       if (value & 0x00010000) {
+               value &= 0xfffeffff;
+               writel(value, (void *)real_offset);
+       }
+
        pci_free_consistent(phba->pcidev,
                            phba->ctrl.mbox_mem_alloced.size,
                            phba->ctrl.mbox_mem_alloced.va,
@@ -3928,30 +4364,6 @@ struct iscsi_transport beiscsi_iscsi_transport = {
        .name = DRV_NAME,
        .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
                CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
-       .param_mask = ISCSI_MAX_RECV_DLENGTH |
-               ISCSI_MAX_XMIT_DLENGTH |
-               ISCSI_HDRDGST_EN |
-               ISCSI_DATADGST_EN |
-               ISCSI_INITIAL_R2T_EN |
-               ISCSI_MAX_R2T |
-               ISCSI_IMM_DATA_EN |
-               ISCSI_FIRST_BURST |
-               ISCSI_MAX_BURST |
-               ISCSI_PDU_INORDER_EN |
-               ISCSI_DATASEQ_INORDER_EN |
-               ISCSI_ERL |
-               ISCSI_CONN_PORT |
-               ISCSI_CONN_ADDRESS |
-               ISCSI_EXP_STATSN |
-               ISCSI_PERSISTENT_PORT |
-               ISCSI_PERSISTENT_ADDRESS |
-               ISCSI_TARGET_NAME | ISCSI_TPGT |
-               ISCSI_USERNAME | ISCSI_PASSWORD |
-               ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
-               ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
-               ISCSI_LU_RESET_TMO |
-               ISCSI_PING_TMO | ISCSI_RECV_TMO |
-               ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
        .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
                                ISCSI_HOST_INITIATOR_NAME,
        .create_session = beiscsi_session_create,
@@ -3959,8 +4371,9 @@ struct iscsi_transport beiscsi_iscsi_transport = {
        .create_conn = beiscsi_conn_create,
        .bind_conn = beiscsi_conn_bind,
        .destroy_conn = iscsi_conn_teardown,
+       .attr_is_visible = be2iscsi_attr_is_visible,
        .set_param = beiscsi_set_param,
-       .get_conn_param = beiscsi_conn_get_param,
+       .get_conn_param = iscsi_conn_get_param,
        .get_session_param = iscsi_session_get_param,
        .get_host_param = beiscsi_get_host_param,
        .start_conn = beiscsi_conn_start,
@@ -3971,6 +4384,7 @@ struct iscsi_transport beiscsi_iscsi_transport = {
        .alloc_pdu = beiscsi_alloc_pdu,
        .parse_pdu_itt = beiscsi_parse_pdu,
        .get_stats = beiscsi_conn_get_stats,
+       .get_ep_param = beiscsi_ep_get_param,
        .ep_connect = beiscsi_ep_connect,
        .ep_poll = beiscsi_ep_poll,
        .ep_disconnect = beiscsi_ep_disconnect,