[SCSI] qla2xxx: Add NVRAM 'Disable Serdes' bit support.
[safe/jmp/linux-2.6] / drivers / scsi / qla2xxx / qla_mbx.c
index 284eb84..39ddd38 100644 (file)
@@ -1,25 +1,12 @@
 /*
- *                  QLOGIC LINUX SOFTWARE
- *
- * QLogic ISP2x00 device driver for Linux 2.6.x
- * Copyright (C) 2003-2005 QLogic Corporation
- * (www.qlogic.com)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * QLogic Fibre Channel HBA Driver
+ * Copyright (c)  2003-2005 QLogic Corporation
  *
+ * See LICENSE.qla2xxx for copyright and licensing details.
  */
 #include "qla_def.h"
 
 #include <linux/delay.h>
-#include <scsi/scsi_transport_fc.h>
 
 static void
 qla2x00_mbx_sem_timeout(unsigned long data)
@@ -104,7 +91,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
        spin_lock_irqsave(&ha->hardware_lock, flags);
 
        /* Load mailbox registers. */
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
                optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
        else
                optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
@@ -168,7 +155,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
 
                set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
 
-               if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
+               if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
                        WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
                else
                        WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
@@ -192,7 +179,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
                DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
                    ha->host_no, command);)
 
-               if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
+               if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
                        WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
                else
                        WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
@@ -208,7 +195,9 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
                        /* Check for pending interrupts. */
                        qla2x00_poll(ha);
 
-                       udelay(10); /* v4.27 */
+                       if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
+                           !ha->flags.mbox_int)
+                               msleep(10);
                } /* while */
        }
 
@@ -248,7 +237,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
                uint16_t mb0;
                uint32_t ictrl;
 
-               if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+               if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                        mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
                        ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
                } else {
@@ -295,9 +284,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
                            "Mailbox command timeout occured. Scheduling ISP "
                            "abort.\n");
                        set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
-                       if (ha->dpc_wait && !ha->dpc_active)
-                               up(ha->dpc_wait);
-
+                       qla2xxx_wake_dpc(ha);
                } else if (!abort_active) {
                        /* call abort directly since we are in the DPC thread */
                        DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
@@ -337,114 +324,31 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
        return rval;
 }
 
-/*
- * qla2x00_load_ram
- *     Load adapter RAM using DMA.
- *
- * Input:
- *     ha = adapter block pointer.
- *
- * Returns:
- *     qla2x00 local function return status code.
- *
- * Context:
- *     Kernel context.
- */
 int
-qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr,
-    uint16_t risc_code_size)
+qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
+    uint32_t risc_code_size)
 {
        int rval;
        mbx_cmd_t mc;
        mbx_cmd_t *mcp = &mc;
-       uint32_t        req_len;
-       dma_addr_t      nml_dma;
-       uint32_t        nml_len;
-       uint32_t        normalized;
-
-       DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n",
-           ha->host_no);)
-
-       req_len = risc_code_size;
-       nml_dma = 0;
-       nml_len = 0;
-
-       normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
-           &nml_len);
-
-       /* Load first segment */
-       mcp->mb[0] = MBC_LOAD_RISC_RAM;
-       mcp->mb[1] = risc_addr;
-       mcp->mb[2] = MSW(req_dma);
-       mcp->mb[3] = LSW(req_dma);
-       mcp->mb[4] = (uint16_t)req_len;
-       mcp->mb[6] = MSW(MSD(req_dma));
-       mcp->mb[7] = LSW(MSD(req_dma));
-       mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
-       mcp->in_mb = MBX_0;
-       mcp->tov = 30;
-       mcp->flags = 0;
-       rval = qla2x00_mailbox_command(ha, mcp);
 
-       /* Load second segment - if necessary */
-       if (normalized && (rval == QLA_SUCCESS)) {
-               mcp->mb[0] = MBC_LOAD_RISC_RAM;
-               mcp->mb[1] = risc_addr + (uint16_t)req_len;
-               mcp->mb[2] = MSW(nml_dma);
-               mcp->mb[3] = LSW(nml_dma);
-               mcp->mb[4] = (uint16_t)nml_len;
-               mcp->mb[6] = MSW(MSD(nml_dma));
-               mcp->mb[7] = LSW(MSD(nml_dma));
-               mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
-               mcp->in_mb = MBX_0;
-               mcp->tov = 30;
-               mcp->flags = 0;
-               rval = qla2x00_mailbox_command(ha, mcp);
-       }
+       DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
 
-       if (rval == QLA_SUCCESS) {
-               /* Empty */
-               DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);)
+       if (MSW(risc_addr) || IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
+               mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
+               mcp->mb[8] = MSW(risc_addr);
+               mcp->out_mb = MBX_8|MBX_0;
        } else {
-               /* Empty */
-               DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x "
-                   "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);)
+               mcp->mb[0] = MBC_LOAD_RISC_RAM;
+               mcp->out_mb = MBX_0;
        }
-       return rval;
-}
-
-/*
- * qla2x00_load_ram_ext
- *     Load adapter extended RAM using DMA.
- *
- * Input:
- *     ha = adapter block pointer.
- *
- * Returns:
- *     qla2x00 local function return status code.
- *
- * Context:
- *     Kernel context.
- */
-int
-qla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma,
-    uint32_t risc_addr, uint32_t risc_code_size)
-{
-       int rval;
-       mbx_cmd_t mc;
-       mbx_cmd_t *mcp = &mc;
-
-       DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
-
-       mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
        mcp->mb[1] = LSW(risc_addr);
        mcp->mb[2] = MSW(req_dma);
        mcp->mb[3] = LSW(req_dma);
        mcp->mb[6] = MSW(MSD(req_dma));
        mcp->mb[7] = LSW(MSD(req_dma));
-       mcp->mb[8] = MSW(risc_addr);
-       mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                mcp->mb[4] = MSW(risc_code_size);
                mcp->mb[5] = LSW(risc_code_size);
                mcp->out_mb |= MBX_5|MBX_4;
@@ -495,7 +399,7 @@ qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
        mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
        mcp->out_mb = MBX_0;
        mcp->in_mb = MBX_0;
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                mcp->mb[1] = MSW(risc_addr);
                mcp->mb[2] = LSW(risc_addr);
                mcp->mb[3] = 0;
@@ -518,7 +422,7 @@ qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
                DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
                    ha->host_no, rval, mcp->mb[0]));
        } else {
-               if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+               if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                        DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
                            __func__, ha->host_no, mcp->mb[1]);)
                } else {
@@ -659,7 +563,7 @@ qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
        mcp->mb[3] = fwopts[3];
        mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
        mcp->in_mb = MBX_0;
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                mcp->in_mb |= MBX_1;
        } else {
                mcp->mb[10] = fwopts[10];
@@ -772,7 +676,7 @@ qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
        mcp->mb[0] = MBC_VERIFY_CHECKSUM;
        mcp->out_mb = MBX_0;
        mcp->in_mb = MBX_0;
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                mcp->mb[1] = MSW(risc_addr);
                mcp->mb[2] = LSW(risc_addr);
                mcp->out_mb |= MBX_2|MBX_1;
@@ -789,7 +693,7 @@ qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
 
        if (rval != QLA_SUCCESS) {
                DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
-                   ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
+                   ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
                    (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));)
        } else {
                DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
@@ -847,7 +751,7 @@ qla2x00_issue_iocb(scsi_qla_host_t *ha, void*  buffer, dma_addr_t phys_addr,
 
                /* Mask reserved bits. */
                sts_entry->entry_status &=
-                   IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RF_MASK_24XX :RF_MASK;
+                   IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RF_MASK_24XX :RF_MASK;
        }
 
        return rval;
@@ -880,10 +784,6 @@ qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
        DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
 
        fcport = sp->fcport;
-       if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
-           atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
-               return 1;
-       }
 
        spin_lock_irqsave(&ha->hardware_lock, flags);
        for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
@@ -984,58 +884,6 @@ qla2x00_abort_target(fc_port_t *fcport)
 #endif
 
 /*
- * qla2x00_target_reset
- *     Issue target reset mailbox command.
- *
- * Input:
- *     ha = adapter block pointer.
- *     TARGET_QUEUE_LOCK must be released.
- *     ADAPTER_STATE_LOCK must be released.
- *
- * Returns:
- *     qla2x00 local function return status code.
- *
- * Context:
- *     Kernel context.
- */
-int
-qla2x00_target_reset(scsi_qla_host_t *ha, struct fc_port *fcport)
-{
-       int rval;
-       mbx_cmd_t mc;
-       mbx_cmd_t *mcp = &mc;
-
-       DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha->host_no);)
-
-       if (atomic_read(&fcport->state) != FCS_ONLINE)
-               return 0;
-
-       mcp->mb[0] = MBC_TARGET_RESET;
-       if (HAS_EXTENDED_IDS(ha))
-               mcp->mb[1] = fcport->loop_id;
-       else
-               mcp->mb[1] = fcport->loop_id << 8;
-       mcp->mb[2] = ha->loop_reset_delay;
-       mcp->out_mb = MBX_2|MBX_1|MBX_0;
-       mcp->in_mb = MBX_0;
-       mcp->tov = 30;
-       mcp->flags = 0;
-       rval = qla2x00_mailbox_command(ha, mcp);
-
-       if (rval != QLA_SUCCESS) {
-               /*EMPTY*/
-               DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n",
-                   ha->host_no, rval);)
-       } else {
-               /*EMPTY*/
-               DEBUG11(printk("qla2x00_target_reset(%ld): done.\n",
-                   ha->host_no);)
-       }
-
-       return rval;
-}
-
-/*
  * qla2x00_get_adapter_id
  *     Get adapter ID and topology.
  *
@@ -1072,6 +920,8 @@ qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
        mcp->tov = 30;
        mcp->flags = 0;
        rval = qla2x00_mailbox_command(ha, mcp);
+       if (mcp->mb[0] == MBS_COMMAND_ERROR)
+               rval = QLA_COMMAND_ERROR;
 
        /* Return data. */
        *id = mcp->mb[1];
@@ -1241,7 +1091,7 @@ qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
        memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
 
        mcp->mb[0] = MBC_GET_PORT_DATABASE;
-       if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA25XX(ha))
+       if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA54XX(ha))
                mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
        mcp->mb[2] = MSW(pd_dma);
        mcp->mb[3] = LSW(pd_dma);
@@ -1249,7 +1099,7 @@ qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
        mcp->mb[7] = LSW(MSD(pd_dma));
        mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
        mcp->in_mb = MBX_0;
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                mcp->mb[1] = fcport->loop_id;
                mcp->mb[10] = opt;
                mcp->out_mb |= MBX_10|MBX_1;
@@ -1262,7 +1112,7 @@ qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
                mcp->mb[1] = fcport->loop_id << 8 | opt;
                mcp->out_mb |= MBX_1;
        }
-       mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
+       mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
            PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
        mcp->flags = MBX_DMA_IN;
        mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
@@ -1270,7 +1120,7 @@ qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
        if (rval != QLA_SUCCESS)
                goto gpd_error_out;
 
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                pd24 = (struct port_database_24xx *) pd;
 
                /* Check for logged in state. */
@@ -1487,7 +1337,7 @@ qla2x00_lip_reset(scsi_qla_host_t *ha)
 
        DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
 
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                mcp->mb[0] = MBC_LIP_FULL_LOGIN;
                mcp->mb[1] = BIT_0;
                mcp->mb[2] = 0xff;
@@ -1781,20 +1631,25 @@ qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  *
  */
 int
-qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
+qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
     uint16_t *mb_ret, uint8_t opt)
 {
        int rval;
        mbx_cmd_t mc;
        mbx_cmd_t *mcp = &mc;
 
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
+               return qla24xx_login_fabric(ha, fcport->loop_id,
+                   fcport->d_id.b.domain, fcport->d_id.b.area,
+                   fcport->d_id.b.al_pa, mb_ret, opt);
+
        DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
 
        mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
        if (HAS_EXTENDED_IDS(ha))
-               mcp->mb[1] = loop_id;
+               mcp->mb[1] = fcport->loop_id;
        else
-               mcp->mb[1] = loop_id << 8;
+               mcp->mb[1] = fcport->loop_id << 8;
        mcp->mb[2] = opt;
        mcp->out_mb = MBX_2|MBX_1|MBX_0;
        mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
@@ -2016,12 +1871,13 @@ qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
 
        mcp->mb[0] = MBC_GET_ID_LIST;
        mcp->out_mb = MBX_0;
-       if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
                mcp->mb[2] = MSW(id_list_dma);
                mcp->mb[3] = LSW(id_list_dma);
                mcp->mb[6] = MSW(MSD(id_list_dma));
                mcp->mb[7] = LSW(MSD(id_list_dma));
-               mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2;
+               mcp->mb[8] = 0;
+               mcp->out_mb |= MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
        } else {
                mcp->mb[1] = MSW(id_list_dma);
                mcp->mb[2] = LSW(id_list_dma);
@@ -2164,8 +2020,109 @@ qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
 
        return rval;
 }
+#endif
 
-uint8_t
+/*
+ * qla2x00_get_link_status
+ *
+ * Input:
+ *     ha = adapter block pointer.
+ *     loop_id = device loop ID.
+ *     ret_buf = pointer to link status return buffer.
+ *
+ * Returns:
+ *     0 = success.
+ *     BIT_0 = mem alloc error.
+ *     BIT_1 = mailbox error.
+ */
+int
+qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
+    link_stat_t *ret_buf, uint16_t *status)
+{
+       int rval;
+       mbx_cmd_t mc;
+       mbx_cmd_t *mcp = &mc;
+       link_stat_t *stat_buf;
+       dma_addr_t stat_buf_dma;
+
+       DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
+
+       stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma);
+       if (stat_buf == NULL) {
+               DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
+                   __func__, ha->host_no));
+               return BIT_0;
+       }
+       memset(stat_buf, 0, sizeof(link_stat_t));
+
+       mcp->mb[0] = MBC_GET_LINK_STATUS;
+       mcp->mb[2] = MSW(stat_buf_dma);
+       mcp->mb[3] = LSW(stat_buf_dma);
+       mcp->mb[6] = MSW(MSD(stat_buf_dma));
+       mcp->mb[7] = LSW(MSD(stat_buf_dma));
+       mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
+       mcp->in_mb = MBX_0;
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
+               mcp->mb[1] = loop_id;
+               mcp->mb[4] = 0;
+               mcp->mb[10] = 0;
+               mcp->out_mb |= MBX_10|MBX_4|MBX_1;
+               mcp->in_mb |= MBX_1;
+       } else if (HAS_EXTENDED_IDS(ha)) {
+               mcp->mb[1] = loop_id;
+               mcp->mb[10] = 0;
+               mcp->out_mb |= MBX_10|MBX_1;
+       } else {
+               mcp->mb[1] = loop_id << 8;
+               mcp->out_mb |= MBX_1;
+       }
+       mcp->tov = 30;
+       mcp->flags = IOCTL_CMD;
+       rval = qla2x00_mailbox_command(ha, mcp);
+
+       if (rval == QLA_SUCCESS) {
+               if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
+                       DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
+                           __func__, ha->host_no, mcp->mb[0]);)
+                       status[0] = mcp->mb[0];
+                       rval = BIT_1;
+               } else {
+                       /* copy over data -- firmware data is LE. */
+                       ret_buf->link_fail_cnt =
+                           le32_to_cpu(stat_buf->link_fail_cnt);
+                       ret_buf->loss_sync_cnt =
+                           le32_to_cpu(stat_buf->loss_sync_cnt);
+                       ret_buf->loss_sig_cnt =
+                           le32_to_cpu(stat_buf->loss_sig_cnt);
+                       ret_buf->prim_seq_err_cnt =
+                           le32_to_cpu(stat_buf->prim_seq_err_cnt);
+                       ret_buf->inval_xmit_word_cnt =
+                           le32_to_cpu(stat_buf->inval_xmit_word_cnt);
+                       ret_buf->inval_crc_cnt =
+                           le32_to_cpu(stat_buf->inval_crc_cnt);
+
+                       DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d "
+                           "loss_sync=%d loss_sig=%d seq_err=%d "
+                           "inval_xmt_word=%d inval_crc=%d.\n", __func__,
+                           ha->host_no, stat_buf->link_fail_cnt,
+                           stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt,
+                           stat_buf->prim_seq_err_cnt,
+                           stat_buf->inval_xmit_word_cnt,
+                           stat_buf->inval_crc_cnt);)
+               }
+       } else {
+               /* Failed. */
+               DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
+                   ha->host_no, rval);)
+               rval = BIT_1;
+       }
+
+       dma_pool_free(ha->s_dma_pool, stat_buf, stat_buf_dma);
+
+       return rval;
+}
+
+int
 qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
     uint16_t *status)
 {
@@ -2227,7 +2184,6 @@ qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
 
        return rval;
 }
-#endif
 
 int
 qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
@@ -2243,10 +2199,6 @@ qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
        DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
 
        fcport = sp->fcport;
-       if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
-           atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
-               return QLA_FUNCTION_FAILED;
-       }
 
        spin_lock_irqsave(&ha->hardware_lock, flags);
        for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
@@ -2377,7 +2329,7 @@ qla2x00_system_error(scsi_qla_host_t *ha)
        mbx_cmd_t mc;
        mbx_cmd_t *mcp = &mc;
 
-       if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
+       if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
                return QLA_FUNCTION_FAILED;
 
        DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
@@ -2459,9 +2411,9 @@ qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
 
        mcp->mb[0] = MBC_SERDES_PARAMS;
        mcp->mb[1] = BIT_0;
-       mcp->mb[2] = sw_em_1g;
-       mcp->mb[3] = sw_em_2g;
-       mcp->mb[4] = sw_em_4g;
+       mcp->mb[2] = sw_em_1g | BIT_15;
+       mcp->mb[3] = sw_em_2g | BIT_15;
+       mcp->mb[4] = sw_em_4g | BIT_15;
        mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
        mcp->in_mb = MBX_0;
        mcp->tov = 30;
@@ -2479,3 +2431,74 @@ qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
 
        return rval;
 }
+
+int
+qla2x00_stop_firmware(scsi_qla_host_t *ha)
+{
+       int rval;
+       mbx_cmd_t mc;
+       mbx_cmd_t *mcp = &mc;
+
+       if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
+               return QLA_FUNCTION_FAILED;
+
+       DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
+
+       mcp->mb[0] = MBC_STOP_FIRMWARE;
+       mcp->out_mb = MBX_0;
+       mcp->in_mb = MBX_0;
+       mcp->tov = 5;
+       mcp->flags = 0;
+       rval = qla2x00_mailbox_command(ha, mcp);
+
+       if (rval != QLA_SUCCESS) {
+               DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
+                   ha->host_no, rval));
+       } else {
+               DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
+       }
+
+       return rval;
+}
+
+int
+qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
+    uint16_t buffers)
+{
+       int rval;
+       mbx_cmd_t mc;
+       mbx_cmd_t *mcp = &mc;
+
+       if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
+               return QLA_FUNCTION_FAILED;
+
+       DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
+
+       mcp->mb[0] = MBC_TRACE_CONTROL;
+       mcp->mb[1] = ctrl;
+       mcp->out_mb = MBX_1|MBX_0;
+       mcp->in_mb = MBX_1|MBX_0;
+       if (ctrl == TC_ENABLE) {
+               mcp->mb[2] = LSW(eft_dma);
+               mcp->mb[3] = MSW(eft_dma);
+               mcp->mb[4] = LSW(MSD(eft_dma));
+               mcp->mb[5] = MSW(MSD(eft_dma));
+               mcp->mb[6] = buffers;
+               mcp->mb[7] = buffers;
+               mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
+       }
+       mcp->tov = 30;
+       mcp->flags = 0;
+       rval = qla2x00_mailbox_command(ha, mcp);
+
+       if (rval != QLA_SUCCESS) {
+               DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
+                   __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
+       } else {
+               DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
+       }
+
+       return rval;
+}
+
+