Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / scsi / qla2xxx / qla_gs.c
index 531dad9..2ebf259 100644 (file)
@@ -1,26 +1,11 @@
 /*
- *                  QLOGIC LINUX SOFTWARE
- *
- * QLogic ISP2x00 device driver for Linux 2.6.x
- * Copyright (C) 2003-2004 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"
 
-static inline ms_iocb_entry_t *
-qla2x00_prep_ms_iocb(scsi_qla_host_t *, uint32_t, uint32_t);
-
 static inline struct ct_sns_req *
 qla2x00_prep_ct_req(struct ct_sns_req *, uint16_t, uint16_t);
 
@@ -35,14 +20,14 @@ static int qla2x00_sns_rft_id(scsi_qla_host_t *);
 static int qla2x00_sns_rnn_id(scsi_qla_host_t *);
 
 /**
- * qla2x00_prep_ms_iocb() - Prepare common MS IOCB fields for SNS CT query.
+ * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
  * @ha: HA context
  * @req_size: request size in bytes
  * @rsp_size: response size in bytes
  *
  * Returns a pointer to the @ha's ms_iocb.
  */
-static inline ms_iocb_entry_t *
+void *
 qla2x00_prep_ms_iocb(scsi_qla_host_t *ha, uint32_t req_size, uint32_t rsp_size)
 {
        ms_iocb_entry_t *ms_pkt;
@@ -71,6 +56,42 @@ qla2x00_prep_ms_iocb(scsi_qla_host_t *ha, uint32_t req_size, uint32_t rsp_size)
        return (ms_pkt);
 }
 
+/**
+ * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query.
+ * @ha: HA context
+ * @req_size: request size in bytes
+ * @rsp_size: response size in bytes
+ *
+ * Returns a pointer to the @ha's ms_iocb.
+ */
+void *
+qla24xx_prep_ms_iocb(scsi_qla_host_t *ha, uint32_t req_size, uint32_t rsp_size)
+{
+       struct ct_entry_24xx *ct_pkt;
+
+       ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
+       memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
+
+       ct_pkt->entry_type = CT_IOCB_TYPE;
+       ct_pkt->entry_count = 1;
+       ct_pkt->nport_handle = __constant_cpu_to_le16(NPH_SNS);
+       ct_pkt->timeout = __constant_cpu_to_le16(25);
+       ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
+       ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
+       ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
+       ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
+
+       ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
+       ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
+       ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
+
+       ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
+       ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
+       ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
+
+       return (ct_pkt);
+}
+
 /**
  * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
  * @ct_req: CT request buffer
@@ -93,6 +114,47 @@ qla2x00_prep_ct_req(struct ct_sns_req *ct_req, uint16_t cmd, uint16_t rsp_size)
        return (ct_req);
 }
 
+static int
+qla2x00_chk_ms_status(scsi_qla_host_t *ha, ms_iocb_entry_t *ms_pkt,
+    struct ct_sns_rsp *ct_rsp, const char *routine)
+{
+       int rval;
+       uint16_t comp_status;
+
+       rval = QLA_FUNCTION_FAILED;
+       if (ms_pkt->entry_status != 0) {
+               DEBUG2_3(printk("scsi(%ld): %s failed, error status (%x).\n",
+                   ha->host_no, routine, ms_pkt->entry_status));
+       } else {
+               if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
+                       comp_status =
+                           ((struct ct_entry_24xx *)ms_pkt)->comp_status;
+               else
+                       comp_status = le16_to_cpu(ms_pkt->status);
+               switch (comp_status) {
+               case CS_COMPLETE:
+               case CS_DATA_UNDERRUN:
+               case CS_DATA_OVERRUN:           /* Overrun? */
+                       if (ct_rsp->header.response !=
+                           __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
+                               DEBUG2_3(printk("scsi(%ld): %s failed, "
+                                   "rejected request:\n", ha->host_no,
+                                   routine));
+                               DEBUG2_3(qla2x00_dump_buffer(
+                                   (uint8_t *)&ct_rsp->header,
+                                   sizeof(struct ct_rsp_hdr)));
+                       } else
+                               rval = QLA_SUCCESS;
+                       break;
+               default:
+                       DEBUG2_3(printk("scsi(%ld): %s failed, completion "
+                           "status (%x).\n", ha->host_no, routine,
+                           comp_status));
+                       break;
+               }
+       }
+       return rval;
+}
 
 /**
  * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
@@ -116,7 +178,7 @@ qla2x00_ga_nxt(scsi_qla_host_t *ha, fc_port_t *fcport)
 
        /* Issue GA_NXT */
        /* Prepare common MS IOCB */
-       ms_pkt = qla2x00_prep_ms_iocb(ha, GA_NXT_REQ_SIZE, GA_NXT_RSP_SIZE);
+       ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GA_NXT_REQ_SIZE, GA_NXT_RSP_SIZE);
 
        /* Prepare CT request */
        ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GA_NXT_CMD,
@@ -135,12 +197,8 @@ qla2x00_ga_nxt(scsi_qla_host_t *ha, fc_port_t *fcport)
                /*EMPTY*/
                DEBUG2_3(printk("scsi(%ld): GA_NXT issue IOCB failed (%d).\n",
                    ha->host_no, rval));
-       } else if (ct_rsp->header.response !=
-           __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
-               DEBUG2_3(printk("scsi(%ld): GA_NXT failed, rejected request, "
-                   "ga_nxt_rsp:\n", ha->host_no));
-               DEBUG2_3(qla2x00_dump_buffer((uint8_t *)&ct_rsp->header,
-                   sizeof(struct ct_rsp_hdr)));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "GA_NXT") !=
+           QLA_SUCCESS) {
                rval = QLA_FUNCTION_FAILED;
        } else {
                /* Populate fc_port_t entry. */
@@ -206,7 +264,7 @@ qla2x00_gid_pt(scsi_qla_host_t *ha, sw_info_t *list)
 
        /* Issue GID_PT */
        /* Prepare common MS IOCB */
-       ms_pkt = qla2x00_prep_ms_iocb(ha, GID_PT_REQ_SIZE, GID_PT_RSP_SIZE);
+       ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GID_PT_REQ_SIZE, GID_PT_RSP_SIZE);
 
        /* Prepare CT request */
        ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, GID_PT_CMD,
@@ -223,12 +281,8 @@ qla2x00_gid_pt(scsi_qla_host_t *ha, sw_info_t *list)
                /*EMPTY*/
                DEBUG2_3(printk("scsi(%ld): GID_PT issue IOCB failed (%d).\n",
                    ha->host_no, rval));
-       } else if (ct_rsp->header.response !=
-           __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
-               DEBUG2_3(printk("scsi(%ld): GID_PT failed, rejected request, "
-                   "gid_pt_rsp:\n", ha->host_no));
-               DEBUG2_3(qla2x00_dump_buffer((uint8_t *)&ct_rsp->header,
-                   sizeof(struct ct_rsp_hdr)));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "GID_PT") !=
+           QLA_SUCCESS) {
                rval = QLA_FUNCTION_FAILED;
        } else {
                /* Set port IDs in switch info list. */
@@ -251,7 +305,7 @@ qla2x00_gid_pt(scsi_qla_host_t *ha, sw_info_t *list)
                 * single call.  Return a failed status, and let GA_NXT handle
                 * the overload.
                 */
-               if (i == MAX_FIBRE_DEVICES) 
+               if (i == MAX_FIBRE_DEVICES)
                        rval = QLA_FUNCTION_FAILED;
        }
 
@@ -282,7 +336,7 @@ qla2x00_gpn_id(scsi_qla_host_t *ha, sw_info_t *list)
        for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
                /* Issue GPN_ID */
                /* Prepare common MS IOCB */
-               ms_pkt = qla2x00_prep_ms_iocb(ha, GPN_ID_REQ_SIZE,
+               ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GPN_ID_REQ_SIZE,
                    GPN_ID_RSP_SIZE);
 
                /* Prepare CT request */
@@ -302,12 +356,8 @@ qla2x00_gpn_id(scsi_qla_host_t *ha, sw_info_t *list)
                        /*EMPTY*/
                        DEBUG2_3(printk("scsi(%ld): GPN_ID issue IOCB failed "
                            "(%d).\n", ha->host_no, rval));
-               } else if (ct_rsp->header.response !=
-                   __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
-                       DEBUG2_3(printk("scsi(%ld): GPN_ID failed, rejected "
-                           "request, gpn_id_rsp:\n", ha->host_no));
-                       DEBUG2_3(qla2x00_dump_buffer((uint8_t *)&ct_rsp->header,
-                           sizeof(struct ct_rsp_hdr)));
+               } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
+                   "GPN_ID") != QLA_SUCCESS) {
                        rval = QLA_FUNCTION_FAILED;
                } else {
                        /* Save portname */
@@ -347,7 +397,7 @@ qla2x00_gnn_id(scsi_qla_host_t *ha, sw_info_t *list)
        for (i = 0; i < MAX_FIBRE_DEVICES; i++) {
                /* Issue GNN_ID */
                /* Prepare common MS IOCB */
-               ms_pkt = qla2x00_prep_ms_iocb(ha, GNN_ID_REQ_SIZE,
+               ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GNN_ID_REQ_SIZE,
                    GNN_ID_RSP_SIZE);
 
                /* Prepare CT request */
@@ -367,12 +417,8 @@ qla2x00_gnn_id(scsi_qla_host_t *ha, sw_info_t *list)
                        /*EMPTY*/
                        DEBUG2_3(printk("scsi(%ld): GNN_ID issue IOCB failed "
                            "(%d).\n", ha->host_no, rval));
-               } else if (ct_rsp->header.response !=
-                   __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
-                       DEBUG2_3(printk("scsi(%ld): GNN_ID failed, rejected "
-                           "request, gnn_id_rsp:\n", ha->host_no));
-                       DEBUG2_3(qla2x00_dump_buffer((uint8_t *)&ct_rsp->header,
-                           sizeof(struct ct_rsp_hdr)));
+               } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
+                   "GNN_ID") != QLA_SUCCESS) {
                        rval = QLA_FUNCTION_FAILED;
                } else {
                        /* Save nodename */
@@ -425,7 +471,7 @@ qla2x00_rft_id(scsi_qla_host_t *ha)
 
        /* Issue RFT_ID */
        /* Prepare common MS IOCB */
-       ms_pkt = qla2x00_prep_ms_iocb(ha, RFT_ID_REQ_SIZE, RFT_ID_RSP_SIZE);
+       ms_pkt = ha->isp_ops.prep_ms_iocb(ha, RFT_ID_REQ_SIZE, RFT_ID_RSP_SIZE);
 
        /* Prepare CT request */
        ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RFT_ID_CMD,
@@ -446,12 +492,8 @@ qla2x00_rft_id(scsi_qla_host_t *ha)
                /*EMPTY*/
                DEBUG2_3(printk("scsi(%ld): RFT_ID issue IOCB failed (%d).\n",
                    ha->host_no, rval));
-       } else if (ct_rsp->header.response !=
-           __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
-               DEBUG2_3(printk("scsi(%ld): RFT_ID failed, rejected "
-                   "request, rft_id_rsp:\n", ha->host_no));
-               DEBUG2_3(qla2x00_dump_buffer((uint8_t *)&ct_rsp->header,
-                   sizeof(struct ct_rsp_hdr)));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RFT_ID") !=
+           QLA_SUCCESS) {
                rval = QLA_FUNCTION_FAILED;
        } else {
                DEBUG2(printk("scsi(%ld): RFT_ID exiting normally.\n",
@@ -484,7 +526,7 @@ qla2x00_rff_id(scsi_qla_host_t *ha)
 
        /* Issue RFF_ID */
        /* Prepare common MS IOCB */
-       ms_pkt = qla2x00_prep_ms_iocb(ha, RFF_ID_REQ_SIZE, RFF_ID_RSP_SIZE);
+       ms_pkt = ha->isp_ops.prep_ms_iocb(ha, RFF_ID_REQ_SIZE, RFF_ID_RSP_SIZE);
 
        /* Prepare CT request */
        ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RFF_ID_CMD,
@@ -496,6 +538,7 @@ qla2x00_rff_id(scsi_qla_host_t *ha)
        ct_req->req.rff_id.port_id[1] = ha->d_id.b.area;
        ct_req->req.rff_id.port_id[2] = ha->d_id.b.al_pa;
 
+       ct_req->req.rff_id.fc4_feature = BIT_1;
        ct_req->req.rff_id.fc4_type = 0x08;             /* SCSI - FCP */
 
        /* Execute MS IOCB */
@@ -505,12 +548,8 @@ qla2x00_rff_id(scsi_qla_host_t *ha)
                /*EMPTY*/
                DEBUG2_3(printk("scsi(%ld): RFF_ID issue IOCB failed (%d).\n",
                    ha->host_no, rval));
-       } else if (ct_rsp->header.response !=
-           __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
-               DEBUG2_3(printk("scsi(%ld): RFF_ID failed, rejected "
-                   "request, rff_id_rsp:\n", ha->host_no));
-               DEBUG2_3(qla2x00_dump_buffer((uint8_t *)&ct_rsp->header,
-                   sizeof(struct ct_rsp_hdr)));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RFF_ID") !=
+           QLA_SUCCESS) {
                rval = QLA_FUNCTION_FAILED;
        } else {
                DEBUG2(printk("scsi(%ld): RFF_ID exiting normally.\n",
@@ -541,7 +580,7 @@ qla2x00_rnn_id(scsi_qla_host_t *ha)
 
        /* Issue RNN_ID */
        /* Prepare common MS IOCB */
-       ms_pkt = qla2x00_prep_ms_iocb(ha, RNN_ID_REQ_SIZE, RNN_ID_RSP_SIZE);
+       ms_pkt = ha->isp_ops.prep_ms_iocb(ha, RNN_ID_REQ_SIZE, RNN_ID_RSP_SIZE);
 
        /* Prepare CT request */
        ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RNN_ID_CMD,
@@ -553,7 +592,7 @@ qla2x00_rnn_id(scsi_qla_host_t *ha)
        ct_req->req.rnn_id.port_id[1] = ha->d_id.b.area;
        ct_req->req.rnn_id.port_id[2] = ha->d_id.b.al_pa;
 
-       memcpy(ct_req->req.rnn_id.node_name, ha->init_cb->node_name, WWN_SIZE);
+       memcpy(ct_req->req.rnn_id.node_name, ha->node_name, WWN_SIZE);
 
        /* Execute MS IOCB */
        rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
@@ -562,12 +601,8 @@ qla2x00_rnn_id(scsi_qla_host_t *ha)
                /*EMPTY*/
                DEBUG2_3(printk("scsi(%ld): RNN_ID issue IOCB failed (%d).\n",
                    ha->host_no, rval));
-       } else if (ct_rsp->header.response !=
-           __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
-               DEBUG2_3(printk("scsi(%ld): RNN_ID failed, rejected "
-                   "request, rnn_id_rsp:\n", ha->host_no));
-               DEBUG2_3(qla2x00_dump_buffer((uint8_t *)&ct_rsp->header,
-                   sizeof(struct ct_rsp_hdr)));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RNN_ID") !=
+           QLA_SUCCESS) {
                rval = QLA_FUNCTION_FAILED;
        } else {
                DEBUG2(printk("scsi(%ld): RNN_ID exiting normally.\n",
@@ -603,7 +638,7 @@ qla2x00_rsnn_nn(scsi_qla_host_t *ha)
        /* Issue RSNN_NN */
        /* Prepare common MS IOCB */
        /*   Request size adjusted after CT preparation */
-       ms_pkt = qla2x00_prep_ms_iocb(ha, 0, RSNN_NN_RSP_SIZE);
+       ms_pkt = ha->isp_ops.prep_ms_iocb(ha, 0, RSNN_NN_RSP_SIZE);
 
        /* Prepare CT request */
        ct_req = qla2x00_prep_ct_req(&ha->ct_sns->p.req, RSNN_NN_CMD,
@@ -611,8 +646,8 @@ qla2x00_rsnn_nn(scsi_qla_host_t *ha)
        ct_rsp = &ha->ct_sns->p.rsp;
 
        /* Prepare CT arguments -- node_name, symbolic node_name, size */
-       memcpy(ct_req->req.rsnn_nn.node_name, ha->init_cb->node_name, WWN_SIZE);
-       
+       memcpy(ct_req->req.rsnn_nn.node_name, ha->node_name, WWN_SIZE);
+
        /* Prepare the Symbolic Node Name */
        /* Board type */
        snn = ct_req->req.rsnn_nn.sym_node_name;
@@ -641,12 +676,8 @@ qla2x00_rsnn_nn(scsi_qla_host_t *ha)
                /*EMPTY*/
                DEBUG2_3(printk("scsi(%ld): RSNN_NN issue IOCB failed (%d).\n",
                    ha->host_no, rval));
-       } else if (ct_rsp->header.response !=
-           __constant_cpu_to_be16(CT_ACCEPT_RESPONSE)) {
-               DEBUG2_3(printk("scsi(%ld): RSNN_NN failed, rejected "
-                   "request, rsnn_id_rsp:\n", ha->host_no));
-               DEBUG2_3(qla2x00_dump_buffer((uint8_t *)&ct_rsp->header,
-                   sizeof(struct ct_rsp_hdr)));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RSNN_NN") !=
+           QLA_SUCCESS) {
                rval = QLA_FUNCTION_FAILED;
        } else {
                DEBUG2(printk("scsi(%ld): RSNN_NN exiting normally.\n",
@@ -821,7 +852,7 @@ qla2x00_sns_gid_pt(scsi_qla_host_t *ha, sw_info_t *list)
                 * single call.  Return a failed status, and let GA_NXT handle
                 * the overload.
                 */
-               if (i == MAX_FIBRE_DEVICES) 
+               if (i == MAX_FIBRE_DEVICES)
                        rval = QLA_FUNCTION_FAILED;
        }
 
@@ -1028,14 +1059,14 @@ qla2x00_sns_rnn_id(scsi_qla_host_t *ha)
        sns_cmd->p.cmd.param[1] = ha->d_id.b.area;
        sns_cmd->p.cmd.param[2] = ha->d_id.b.domain;
 
-       sns_cmd->p.cmd.param[4] = ha->init_cb->node_name[7];
-       sns_cmd->p.cmd.param[5] = ha->init_cb->node_name[6];
-       sns_cmd->p.cmd.param[6] = ha->init_cb->node_name[5];
-       sns_cmd->p.cmd.param[7] = ha->init_cb->node_name[4];
-       sns_cmd->p.cmd.param[8] = ha->init_cb->node_name[3];
-       sns_cmd->p.cmd.param[9] = ha->init_cb->node_name[2];
-       sns_cmd->p.cmd.param[10] = ha->init_cb->node_name[1];
-       sns_cmd->p.cmd.param[11] = ha->init_cb->node_name[0];
+       sns_cmd->p.cmd.param[4] = ha->node_name[7];
+       sns_cmd->p.cmd.param[5] = ha->node_name[6];
+       sns_cmd->p.cmd.param[6] = ha->node_name[5];
+       sns_cmd->p.cmd.param[7] = ha->node_name[4];
+       sns_cmd->p.cmd.param[8] = ha->node_name[3];
+       sns_cmd->p.cmd.param[9] = ha->node_name[2];
+       sns_cmd->p.cmd.param[10] = ha->node_name[1];
+       sns_cmd->p.cmd.param[11] = ha->node_name[0];
 
        /* Execute SNS command. */
        rval = qla2x00_send_sns(ha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
@@ -1057,3 +1088,562 @@ qla2x00_sns_rnn_id(scsi_qla_host_t *ha)
 
        return (rval);
 }
+
+/**
+ * qla2x00_mgmt_svr_login() - Login to fabric Managment Service.
+ * @ha: HA context
+ *
+ * Returns 0 on success.
+ */
+static int
+qla2x00_mgmt_svr_login(scsi_qla_host_t *ha)
+{
+       int ret;
+       uint16_t mb[MAILBOX_REGISTER_COUNT];
+
+       ret = QLA_SUCCESS;
+       if (ha->flags.management_server_logged_in)
+               return ret;
+
+       ha->isp_ops.fabric_login(ha, ha->mgmt_svr_loop_id, 0xff, 0xff, 0xfa,
+           mb, BIT_1);
+       if (mb[0] != MBS_COMMAND_COMPLETE) {
+               DEBUG2_13(printk("%s(%ld): Failed MANAGEMENT_SERVER login: "
+                   "loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x\n",
+                   __func__, ha->host_no, ha->mgmt_svr_loop_id, mb[0], mb[1],
+                   mb[2], mb[6], mb[7]));
+               ret = QLA_FUNCTION_FAILED;
+       } else
+               ha->flags.management_server_logged_in = 1;
+
+       return ret;
+}
+
+/**
+ * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
+ * @ha: HA context
+ * @req_size: request size in bytes
+ * @rsp_size: response size in bytes
+ *
+ * Returns a pointer to the @ha's ms_iocb.
+ */
+void *
+qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size,
+    uint32_t rsp_size)
+{
+       ms_iocb_entry_t *ms_pkt;
+
+       ms_pkt = ha->ms_iocb;
+       memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
+
+       ms_pkt->entry_type = MS_IOCB_TYPE;
+       ms_pkt->entry_count = 1;
+       SET_TARGET_ID(ha, ms_pkt->loop_id, ha->mgmt_svr_loop_id);
+       ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
+       ms_pkt->timeout = __constant_cpu_to_le16(59);
+       ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
+       ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
+       ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
+       ms_pkt->req_bytecount = cpu_to_le32(req_size);
+
+       ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
+       ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
+       ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
+
+       ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
+       ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
+       ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
+
+       return ms_pkt;
+}
+
+/**
+ * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
+ * @ha: HA context
+ * @req_size: request size in bytes
+ * @rsp_size: response size in bytes
+ *
+ * Returns a pointer to the @ha's ms_iocb.
+ */
+void *
+qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size,
+    uint32_t rsp_size)
+{
+       struct ct_entry_24xx *ct_pkt;
+
+       ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
+       memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
+
+       ct_pkt->entry_type = CT_IOCB_TYPE;
+       ct_pkt->entry_count = 1;
+       ct_pkt->nport_handle = cpu_to_le16(ha->mgmt_svr_loop_id);
+       ct_pkt->timeout = __constant_cpu_to_le16(59);
+       ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
+       ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
+       ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
+       ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
+
+       ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
+       ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
+       ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
+
+       ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
+       ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
+       ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
+
+       return ct_pkt;
+}
+
+static inline ms_iocb_entry_t *
+qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size)
+{
+       ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
+       struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
+
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
+               ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
+               ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
+       } else {
+               ms_pkt->req_bytecount = cpu_to_le32(req_size);
+               ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
+       }
+
+       return ms_pkt;
+}
+
+/**
+ * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
+ * @ct_req: CT request buffer
+ * @cmd: GS command
+ * @rsp_size: response size in bytes
+ *
+ * Returns a pointer to the intitialized @ct_req.
+ */
+static inline struct ct_sns_req *
+qla2x00_prep_ct_fdmi_req(struct ct_sns_req *ct_req, uint16_t cmd,
+    uint16_t rsp_size)
+{
+       memset(ct_req, 0, sizeof(struct ct_sns_pkt));
+
+       ct_req->header.revision = 0x01;
+       ct_req->header.gs_type = 0xFA;
+       ct_req->header.gs_subtype = 0x10;
+       ct_req->command = cpu_to_be16(cmd);
+       ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
+
+       return ct_req;
+}
+
+/**
+ * qla2x00_fdmi_rhba() -
+ * @ha: HA context
+ *
+ * Returns 0 on success.
+ */
+static int
+qla2x00_fdmi_rhba(scsi_qla_host_t *ha)
+{
+       int rval, alen;
+       uint32_t size, sn;
+
+       ms_iocb_entry_t *ms_pkt;
+       struct ct_sns_req *ct_req;
+       struct ct_sns_rsp *ct_rsp;
+       uint8_t *entries;
+       struct ct_fdmi_hba_attr *eiter;
+
+       /* Issue RHBA */
+       /* Prepare common MS IOCB */
+       /*   Request size adjusted after CT preparation */
+       ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RHBA_RSP_SIZE);
+
+       /* Prepare CT request */
+       ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RHBA_CMD,
+           RHBA_RSP_SIZE);
+       ct_rsp = &ha->ct_sns->p.rsp;
+
+       /* Prepare FDMI command arguments -- attribute block, attributes. */
+       memcpy(ct_req->req.rhba.hba_identifier, ha->port_name, WWN_SIZE);
+       ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
+       memcpy(ct_req->req.rhba.port_name, ha->port_name, WWN_SIZE);
+       size = 2 * WWN_SIZE + 4 + 4;
+
+       /* Attributes */
+       ct_req->req.rhba.attrs.count =
+           __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
+       entries = ct_req->req.rhba.hba_identifier;
+
+       /* Nodename. */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
+       eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
+       memcpy(eiter->a.node_name, ha->node_name, WWN_SIZE);
+       size += 4 + WWN_SIZE;
+
+       DEBUG13(printk("%s(%ld): NODENAME=%02x%02x%02x%02x%02x%02x%02x%02x.\n",
+           __func__, ha->host_no,
+           eiter->a.node_name[0], eiter->a.node_name[1], eiter->a.node_name[2],
+           eiter->a.node_name[3], eiter->a.node_name[4], eiter->a.node_name[5],
+           eiter->a.node_name[6], eiter->a.node_name[7]));
+
+       /* Manufacturer. */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
+       strcpy(eiter->a.manufacturer, "QLogic Corporation");
+       alen = strlen(eiter->a.manufacturer);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): MANUFACTURER=%s.\n", __func__, ha->host_no,
+           eiter->a.manufacturer));
+
+       /* Serial number. */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
+       sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
+       sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
+       alen = strlen(eiter->a.serial_num);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): SERIALNO=%s.\n", __func__, ha->host_no,
+           eiter->a.serial_num));
+
+       /* Model name. */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
+       strcpy(eiter->a.model, ha->model_number);
+       alen = strlen(eiter->a.model);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): MODEL_NAME=%s.\n", __func__, ha->host_no,
+           eiter->a.model));
+
+       /* Model description. */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
+       if (ha->model_desc)
+               strncpy(eiter->a.model_desc, ha->model_desc, 80);
+       alen = strlen(eiter->a.model_desc);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): MODEL_DESC=%s.\n", __func__, ha->host_no,
+           eiter->a.model_desc));
+
+       /* Hardware version. */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
+       strcpy(eiter->a.hw_version, ha->adapter_id);
+       alen = strlen(eiter->a.hw_version);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): HARDWAREVER=%s.\n", __func__, ha->host_no,
+           eiter->a.hw_version));
+
+       /* Driver version. */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
+       strcpy(eiter->a.driver_version, qla2x00_version_str);
+       alen = strlen(eiter->a.driver_version);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): DRIVERVER=%s.\n", __func__, ha->host_no,
+           eiter->a.driver_version));
+
+       /* Option ROM version. */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
+       strcpy(eiter->a.orom_version, "0.00");
+       alen = strlen(eiter->a.orom_version);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): OPTROMVER=%s.\n", __func__, ha->host_no,
+           eiter->a.orom_version));
+
+       /* Firmware version */
+       eiter = (struct ct_fdmi_hba_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
+       ha->isp_ops.fw_version_str(ha, eiter->a.fw_version);
+       alen = strlen(eiter->a.fw_version);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): FIRMWAREVER=%s.\n", __func__, ha->host_no,
+           eiter->a.fw_version));
+
+       /* Update MS request size. */
+       qla2x00_update_ms_fdmi_iocb(ha, size + 16);
+
+       DEBUG13(printk("%s(%ld): RHBA identifier="
+           "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
+           ha->host_no, ct_req->req.rhba.hba_identifier[0],
+           ct_req->req.rhba.hba_identifier[1],
+           ct_req->req.rhba.hba_identifier[2],
+           ct_req->req.rhba.hba_identifier[3],
+           ct_req->req.rhba.hba_identifier[4],
+           ct_req->req.rhba.hba_identifier[5],
+           ct_req->req.rhba.hba_identifier[6],
+           ct_req->req.rhba.hba_identifier[7], size));
+       DEBUG13(qla2x00_dump_buffer(entries, size));
+
+       /* Execute MS IOCB */
+       rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
+           sizeof(ms_iocb_entry_t));
+       if (rval != QLA_SUCCESS) {
+               /*EMPTY*/
+               DEBUG2_3(printk("scsi(%ld): RHBA issue IOCB failed (%d).\n",
+                   ha->host_no, rval));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RHBA") !=
+           QLA_SUCCESS) {
+               rval = QLA_FUNCTION_FAILED;
+               if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
+                   ct_rsp->header.explanation_code ==
+                   CT_EXPL_ALREADY_REGISTERED) {
+                       DEBUG2_13(printk("%s(%ld): HBA already registered.\n",
+                           __func__, ha->host_no));
+                       rval = QLA_ALREADY_REGISTERED;
+               }
+       } else {
+               DEBUG2(printk("scsi(%ld): RHBA exiting normally.\n",
+                   ha->host_no));
+       }
+
+       return rval;
+}
+
+/**
+ * qla2x00_fdmi_dhba() -
+ * @ha: HA context
+ *
+ * Returns 0 on success.
+ */
+static int
+qla2x00_fdmi_dhba(scsi_qla_host_t *ha)
+{
+       int rval;
+
+       ms_iocb_entry_t *ms_pkt;
+       struct ct_sns_req *ct_req;
+       struct ct_sns_rsp *ct_rsp;
+
+       /* Issue RPA */
+       /* Prepare common MS IOCB */
+       ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, DHBA_REQ_SIZE,
+           DHBA_RSP_SIZE);
+
+       /* Prepare CT request */
+       ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, DHBA_CMD,
+           DHBA_RSP_SIZE);
+       ct_rsp = &ha->ct_sns->p.rsp;
+
+       /* Prepare FDMI command arguments -- portname. */
+       memcpy(ct_req->req.dhba.port_name, ha->port_name, WWN_SIZE);
+
+       DEBUG13(printk("%s(%ld): DHBA portname="
+           "%02x%02x%02x%02x%02x%02x%02x%02x.\n", __func__, ha->host_no,
+           ct_req->req.dhba.port_name[0], ct_req->req.dhba.port_name[1],
+           ct_req->req.dhba.port_name[2], ct_req->req.dhba.port_name[3],
+           ct_req->req.dhba.port_name[4], ct_req->req.dhba.port_name[5],
+           ct_req->req.dhba.port_name[6], ct_req->req.dhba.port_name[7]));
+
+       /* Execute MS IOCB */
+       rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
+           sizeof(ms_iocb_entry_t));
+       if (rval != QLA_SUCCESS) {
+               /*EMPTY*/
+               DEBUG2_3(printk("scsi(%ld): DHBA issue IOCB failed (%d).\n",
+                   ha->host_no, rval));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "DHBA") !=
+           QLA_SUCCESS) {
+               rval = QLA_FUNCTION_FAILED;
+       } else {
+               DEBUG2(printk("scsi(%ld): DHBA exiting normally.\n",
+                   ha->host_no));
+       }
+
+       return rval;
+}
+
+/**
+ * qla2x00_fdmi_rpa() -
+ * @ha: HA context
+ *
+ * Returns 0 on success.
+ */
+static int
+qla2x00_fdmi_rpa(scsi_qla_host_t *ha)
+{
+       int rval, alen;
+       uint32_t size, max_frame_size;
+
+       ms_iocb_entry_t *ms_pkt;
+       struct ct_sns_req *ct_req;
+       struct ct_sns_rsp *ct_rsp;
+       uint8_t *entries;
+       struct ct_fdmi_port_attr *eiter;
+       struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
+
+       /* Issue RPA */
+       /* Prepare common MS IOCB */
+       /*   Request size adjusted after CT preparation */
+       ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RPA_RSP_SIZE);
+
+       /* Prepare CT request */
+       ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RPA_CMD,
+           RPA_RSP_SIZE);
+       ct_rsp = &ha->ct_sns->p.rsp;
+
+       /* Prepare FDMI command arguments -- attribute block, attributes. */
+       memcpy(ct_req->req.rpa.port_name, ha->port_name, WWN_SIZE);
+       size = WWN_SIZE + 4;
+
+       /* Attributes */
+       ct_req->req.rpa.attrs.count =
+           __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
+       entries = ct_req->req.rpa.port_name;
+
+       /* FC4 types. */
+       eiter = (struct ct_fdmi_port_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
+       eiter->len = __constant_cpu_to_be16(4 + 32);
+       eiter->a.fc4_types[2] = 0x01;
+       size += 4 + 32;
+
+       DEBUG13(printk("%s(%ld): FC4_TYPES=%02x %02x.\n", __func__, ha->host_no,
+           eiter->a.fc4_types[2], eiter->a.fc4_types[1]));
+
+       /* Supported speed. */
+       eiter = (struct ct_fdmi_port_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
+       eiter->len = __constant_cpu_to_be16(4 + 4);
+       if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
+               eiter->a.sup_speed = __constant_cpu_to_be32(4);
+       else if (IS_QLA23XX(ha))
+               eiter->a.sup_speed = __constant_cpu_to_be32(2);
+       else
+               eiter->a.sup_speed = __constant_cpu_to_be32(1);
+       size += 4 + 4;
+
+       DEBUG13(printk("%s(%ld): SUPPORTED_SPEED=%x.\n", __func__, ha->host_no,
+           eiter->a.sup_speed));
+
+       /* Current speed. */
+       eiter = (struct ct_fdmi_port_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
+       eiter->len = __constant_cpu_to_be16(4 + 4);
+       switch (ha->link_data_rate) {
+       case 0:
+               eiter->a.cur_speed = __constant_cpu_to_be32(1);
+               break;
+       case 1:
+               eiter->a.cur_speed = __constant_cpu_to_be32(2);
+               break;
+       case 3:
+               eiter->a.cur_speed = __constant_cpu_to_be32(4);
+               break;
+       }
+       size += 4 + 4;
+
+       DEBUG13(printk("%s(%ld): CURRENT_SPEED=%x.\n", __func__, ha->host_no,
+           eiter->a.cur_speed));
+
+       /* Max frame size. */
+       eiter = (struct ct_fdmi_port_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
+       eiter->len = __constant_cpu_to_be16(4 + 4);
+       max_frame_size = IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
+               (uint32_t) icb24->frame_payload_size:
+               (uint32_t) ha->init_cb->frame_payload_size;
+       eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
+       size += 4 + 4;
+
+       DEBUG13(printk("%s(%ld): MAX_FRAME_SIZE=%x.\n", __func__, ha->host_no,
+           eiter->a.max_frame_size));
+
+       /* OS device name. */
+       eiter = (struct ct_fdmi_port_attr *) (entries + size);
+       eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
+       sprintf(eiter->a.os_dev_name, "/proc/scsi/qla2xxx/%ld", ha->host_no);
+       alen = strlen(eiter->a.os_dev_name);
+       alen += (alen & 3) ? (4 - (alen & 3)) : 4;
+       eiter->len = cpu_to_be16(4 + alen);
+       size += 4 + alen;
+
+       DEBUG13(printk("%s(%ld): OS_DEVICE_NAME=%s.\n", __func__, ha->host_no,
+           eiter->a.os_dev_name));
+
+       /* Update MS request size. */
+       qla2x00_update_ms_fdmi_iocb(ha, size + 16);
+
+       DEBUG13(printk("%s(%ld): RPA portname="
+           "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
+           ha->host_no, ct_req->req.rpa.port_name[0],
+           ct_req->req.rpa.port_name[1], ct_req->req.rpa.port_name[2],
+           ct_req->req.rpa.port_name[3], ct_req->req.rpa.port_name[4],
+           ct_req->req.rpa.port_name[5], ct_req->req.rpa.port_name[6],
+           ct_req->req.rpa.port_name[7], size));
+       DEBUG13(qla2x00_dump_buffer(entries, size));
+
+       /* Execute MS IOCB */
+       rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
+           sizeof(ms_iocb_entry_t));
+       if (rval != QLA_SUCCESS) {
+               /*EMPTY*/
+               DEBUG2_3(printk("scsi(%ld): RPA issue IOCB failed (%d).\n",
+                   ha->host_no, rval));
+       } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RPA") !=
+           QLA_SUCCESS) {
+               rval = QLA_FUNCTION_FAILED;
+       } else {
+               DEBUG2(printk("scsi(%ld): RPA exiting normally.\n",
+                   ha->host_no));
+       }
+
+       return rval;
+}
+
+/**
+ * qla2x00_fdmi_register() -
+ * @ha: HA context
+ *
+ * Returns 0 on success.
+ */
+int
+qla2x00_fdmi_register(scsi_qla_host_t *ha)
+{
+       int rval;
+
+       rval = qla2x00_mgmt_svr_login(ha);
+       if (rval)
+               return rval;
+
+       rval = qla2x00_fdmi_rhba(ha);
+       if (rval) {
+               if (rval != QLA_ALREADY_REGISTERED)
+                       return rval;
+
+               rval = qla2x00_fdmi_dhba(ha);
+               if (rval)
+                       return rval;
+
+               rval = qla2x00_fdmi_rhba(ha);
+               if (rval)
+                       return rval;
+       }
+       rval = qla2x00_fdmi_rpa(ha);
+
+       return rval;
+}