Merge branch 'for-linus' of git://gitorious.org/linux-omap-dss2/linux
[safe/jmp/linux-2.6] / drivers / scsi / qla2xxx / qla_mid.c
index e756576..b901aa2 100644 (file)
@@ -5,11 +5,10 @@
  * See LICENSE.qla2xxx for copyright and licensing details.
  */
 #include "qla_def.h"
+#include "qla_gbl.h"
 
-#include <linux/version.h>
 #include <linux/moduleparam.h>
 #include <linux/vmalloc.h>
-#include <linux/smp_lock.h>
 #include <linux/list.h>
 
 #include <scsi/scsi_tcq.h>
@@ -19,7 +18,7 @@
 void
 qla2x00_vp_stop_timer(scsi_qla_host_t *vha)
 {
-       if (vha->parent && vha->timer_active) {
+       if (vha->vp_idx && vha->timer_active) {
                del_timer_sync(&vha->timer);
                vha->timer_active = 0;
        }
@@ -29,7 +28,7 @@ static uint32_t
 qla24xx_allocate_vp_id(scsi_qla_host_t *vha)
 {
        uint32_t vp_id;
-       scsi_qla_host_t *ha = vha->parent;
+       struct qla_hw_data *ha = vha->hw;
 
        /* Find an empty slot and assign an vp_id */
        mutex_lock(&ha->vport_lock);
@@ -43,9 +42,8 @@ qla24xx_allocate_vp_id(scsi_qla_host_t *vha)
 
        set_bit(vp_id, ha->vp_idx_map);
        ha->num_vhosts++;
-       ha->cur_vport_count++;
        vha->vp_idx = vp_id;
-       list_add_tail(&vha->vp_list, &ha->vp_list);
+       list_add_tail(&vha->list, &ha->vp_list);
        mutex_unlock(&ha->vport_lock);
        return vp_id;
 }
@@ -54,24 +52,24 @@ void
 qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
 {
        uint16_t vp_id;
-       scsi_qla_host_t *ha = vha->parent;
+       struct qla_hw_data *ha = vha->hw;
 
        mutex_lock(&ha->vport_lock);
        vp_id = vha->vp_idx;
        ha->num_vhosts--;
-       ha->cur_vport_count--;
        clear_bit(vp_id, ha->vp_idx_map);
-       list_del(&vha->vp_list);
+       list_del(&vha->list);
        mutex_unlock(&ha->vport_lock);
 }
 
 static scsi_qla_host_t *
-qla24xx_find_vhost_by_name(scsi_qla_host_t *ha, uint8_t *port_name)
+qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name)
 {
        scsi_qla_host_t *vha;
+       struct scsi_qla_host *tvha;
 
        /* Locate matching device in database. */
-       list_for_each_entry(vha, &ha->vp_list, vp_list) {
+       list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
                if (!memcmp(port_name, vha->port_name, WWN_SIZE))
                        return vha;
        }
@@ -95,17 +93,15 @@ static void
 qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha)
 {
        fc_port_t *fcport;
-       scsi_qla_host_t *pha = to_qla_parent(vha);
-
-       list_for_each_entry(fcport, &pha->fcports, list) {
-               if (fcport->vp_idx != vha->vp_idx)
-                       continue;
 
+       list_for_each_entry(fcport, &vha->vp_fcports, list) {
                DEBUG15(printk("scsi(%ld): Marking port dead, "
                    "loop_id=0x%04x :%x\n",
                    vha->host_no, fcport->loop_id, fcport->vp_idx));
 
+               atomic_set(&fcport->state, FCS_DEVICE_DEAD);
                qla2x00_mark_device_lost(vha, fcport, 0, 0);
+               atomic_set(&fcport->state, FCS_UNCONFIGURED);
        }
 }
 
@@ -118,7 +114,6 @@ qla24xx_disable_vp(scsi_qla_host_t *vha)
        atomic_set(&vha->loop_state, LOOP_DOWN);
        atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
 
-       /* Delete all vp's fcports from parent's list */
        qla2x00_mark_vp_devices_dead(vha);
        atomic_set(&vha->vp_state, VP_FAILED);
        vha->flags.management_server_logged_in = 0;
@@ -135,11 +130,12 @@ int
 qla24xx_enable_vp(scsi_qla_host_t *vha)
 {
        int ret;
-       scsi_qla_host_t *ha = vha->parent;
+       struct qla_hw_data *ha = vha->hw;
+       scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
 
        /* Check if physical ha port is Up */
-       if (atomic_read(&ha->loop_state) == LOOP_DOWN  ||
-               atomic_read(&ha->loop_state) == LOOP_DEAD ) {
+       if (atomic_read(&base_vha->loop_state) == LOOP_DOWN  ||
+               atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
                vha->vp_err_state =  VP_ERR_PORTDWN;
                fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN);
                goto enable_failed;
@@ -177,8 +173,8 @@ qla24xx_configure_vp(scsi_qla_host_t *vha)
            vha->host_no, __func__));
        ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx);
        if (ret != QLA_SUCCESS) {
-               DEBUG15(qla_printk(KERN_ERR, vha, "Failed to enable receiving"
-                   " of RSCN requests: 0x%x\n", ret));
+               DEBUG15(qla_printk(KERN_ERR, vha->hw, "Failed to enable "
+                   "receiving of RSCN requests: 0x%x\n", ret));
                return;
        } else {
                /* Corresponds to SCR enabled */
@@ -194,25 +190,14 @@ qla24xx_configure_vp(scsi_qla_host_t *vha)
 }
 
 void
-qla2x00_alert_all_vps(scsi_qla_host_t *ha, uint16_t *mb)
+qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
 {
-       int i, vp_idx_matched;
-       scsi_qla_host_t *vha;
-
-       if (ha->parent)
-               return;
-
-       for_each_mapped_vp_idx(ha, i) {
-               vp_idx_matched = 0;
-
-               list_for_each_entry(vha, &ha->vp_list, vp_list) {
-                       if (i == vha->vp_idx) {
-                               vp_idx_matched = 1;
-                               break;
-                       }
-               }
+       scsi_qla_host_t *vha, *tvha;
+       struct qla_hw_data *ha = rsp->hw;
+       int i = 0;
 
-               if (vp_idx_matched) {
+       list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
+               if (vha->vp_idx) {
                        switch (mb[0]) {
                        case MBA_LIP_OCCURRED:
                        case MBA_LOOP_UP:
@@ -223,16 +208,17 @@ qla2x00_alert_all_vps(scsi_qla_host_t *ha, uint16_t *mb)
                        case MBA_PORT_UPDATE:
                        case MBA_RSCN_UPDATE:
                                DEBUG15(printk("scsi(%ld)%s: Async_event for"
-                                   " VP[%d], mb = 0x%x, vha=%p\n",
-                                   vha->host_no, __func__,i, *mb, vha));
-                               qla2x00_async_event(vha, mb);
+                               " VP[%d], mb = 0x%x, vha=%p\n",
+                               vha->host_no, __func__, i, *mb, vha));
+                               qla2x00_async_event(vha, rsp, mb);
                                break;
                        }
                }
+               i++;
        }
 }
 
-void
+int
 qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
 {
        /*
@@ -247,30 +233,46 @@ qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
                        atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
        }
 
+       /*
+        * To exclusively reset vport, we need to log it out first.  Note: this
+        * control_vp can fail if ISP reset is already issued, this is
+        * expected, as the vp would be already logged out due to ISP reset.
+        */
+       if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
+               qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
+
        DEBUG15(printk("scsi(%ld): Scheduling enable of Vport %d...\n",
            vha->host_no, vha->vp_idx));
-       qla24xx_enable_vp(vha);
+       return qla24xx_enable_vp(vha);
 }
 
 static int
 qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
 {
-       scsi_qla_host_t *ha = vha->parent;
+       qla2x00_do_work(vha);
 
        if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) {
                /* VP acquired. complete port configuration */
-               if (atomic_read(&ha->loop_state) == LOOP_READY) {
-                       qla24xx_configure_vp(vha);
-               } else {
-                       set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
-                       set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
-               }
-
+               qla24xx_configure_vp(vha);
                return 0;
        }
 
-       if (test_and_clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
-               qla2x00_vp_abort_isp(vha);
+       if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) {
+               qla2x00_update_fcports(vha);
+               clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
+       }
+
+       if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) &&
+               !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) &&
+               atomic_read(&vha->loop_state) != LOOP_DOWN) {
+
+               DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
+                                               vha->host_no));
+               qla2x00_relogin(vha);
+
+               DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
+                                                       vha->host_no));
+       }
 
        if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) &&
            (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) {
@@ -288,38 +290,34 @@ qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
 }
 
 void
-qla2x00_do_dpc_all_vps(scsi_qla_host_t *ha)
+qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
 {
        int ret;
-       int i, vp_idx_matched;
-       scsi_qla_host_t *vha;
+       struct qla_hw_data *ha = vha->hw;
+       scsi_qla_host_t *vp;
+       struct scsi_qla_host *tvp;
 
-       if (ha->parent)
+       if (vha->vp_idx)
                return;
        if (list_empty(&ha->vp_list))
                return;
 
-       clear_bit(VP_DPC_NEEDED, &ha->dpc_flags);
-
-       for_each_mapped_vp_idx(ha, i) {
-               vp_idx_matched = 0;
+       clear_bit(VP_DPC_NEEDED, &vha->dpc_flags);
 
-               list_for_each_entry(vha, &ha->vp_list, vp_list) {
-                       if (i == vha->vp_idx) {
-                               vp_idx_matched = 1;
-                               break;
-                       }
-               }
+       if (!(ha->current_topology & ISP_CFG_F))
+               return;
 
-               if (vp_idx_matched)
-                       ret = qla2x00_do_dpc_vp(vha);
+       list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
+               if (vp->vp_idx)
+                       ret = qla2x00_do_dpc_vp(vp);
        }
 }
 
 int
 qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
 {
-       scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
+       scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
+       struct qla_hw_data *ha = base_vha->hw;
        scsi_qla_host_t *vha;
        uint8_t port_name[WWN_SIZE];
 
@@ -336,7 +334,7 @@ qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
 
        /* Check up unique WWPN */
        u64_to_wwn(fc_vport->port_name, port_name);
-       if (!memcmp(port_name, ha->port_name, WWN_SIZE))
+       if (!memcmp(port_name, base_vha->port_name, WWN_SIZE))
                return VPCERR_BAD_WWN;
        vha = qla24xx_find_vhost_by_name(ha, port_name);
        if (vha)
@@ -345,7 +343,7 @@ qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
        /* Check up max-npiv-supports */
        if (ha->num_vhosts > ha->max_npiv_vports) {
                DEBUG15(printk("scsi(%ld): num_vhosts %ud is bigger than "
-                   "max_npv_vports %ud.\n", ha->host_no,
+                   "max_npv_vports %ud.\n", base_vha->host_no,
                    ha->num_vhosts, ha->max_npiv_vports));
                return VPCERR_UNSUPPORTED;
        }
@@ -355,62 +353,35 @@ qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
 scsi_qla_host_t *
 qla24xx_create_vhost(struct fc_vport *fc_vport)
 {
-       scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
+       scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
+       struct qla_hw_data *ha = base_vha->hw;
        scsi_qla_host_t *vha;
+       struct scsi_host_template *sht = &qla2xxx_driver_template;
        struct Scsi_Host *host;
 
-       host = scsi_host_alloc(&qla24xx_driver_template,
-           sizeof(scsi_qla_host_t));
-       if (!host) {
-               printk(KERN_WARNING
-                   "qla2xxx: scsi_host_alloc() failed for vport\n");
+       vha = qla2x00_create_host(sht, ha);
+       if (!vha) {
+               DEBUG(printk("qla2xxx: scsi_host_alloc() failed for vport\n"));
                return(NULL);
        }
 
-       vha = shost_priv(host);
-
-       /* clone the parent hba */
-       memcpy(vha, ha, sizeof (scsi_qla_host_t));
-
+       host = vha->host;
        fc_vport->dd_data = vha;
-
-       vha->node_name = kmalloc(WWN_SIZE * sizeof(char), GFP_KERNEL);
-       if (!vha->node_name)
-               goto create_vhost_failed_1;
-
-       vha->port_name = kmalloc(WWN_SIZE * sizeof(char), GFP_KERNEL);
-       if (!vha->port_name)
-               goto create_vhost_failed_2;
-
        /* New host info */
        u64_to_wwn(fc_vport->node_name, vha->node_name);
        u64_to_wwn(fc_vport->port_name, vha->port_name);
 
-       vha->host = host;
-       vha->host_no = host->host_no;
-       vha->parent = ha;
        vha->fc_vport = fc_vport;
        vha->device_flags = 0;
        vha->vp_idx = qla24xx_allocate_vp_id(vha);
        if (vha->vp_idx > ha->max_npiv_vports) {
                DEBUG15(printk("scsi(%ld): Couldn't allocate vp_id.\n",
                        vha->host_no));
-               goto create_vhost_failed_3;
+               goto create_vhost_failed;
        }
        vha->mgmt_svr_loop_id = 10 + vha->vp_idx;
 
-       init_completion(&vha->mbx_cmd_comp);
-       complete(&vha->mbx_cmd_comp);
-       init_completion(&vha->mbx_intr_comp);
-
-       INIT_LIST_HEAD(&vha->list);
-       INIT_LIST_HEAD(&vha->fcports);
-       INIT_LIST_HEAD(&vha->vp_fcports);
-       INIT_LIST_HEAD(&vha->work_list);
-
        vha->dpc_flags = 0L;
-       set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
-       set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
 
        /*
         * To fix the issue of processing a parent's RSCN for the vport before
@@ -422,7 +393,8 @@ qla24xx_create_vhost(struct fc_vport *fc_vport)
 
        qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL);
 
-       host->can_queue = vha->request_q_length + 128;
+       vha->req = base_vha->req;
+       host->can_queue = base_vha->req->length + 128;
        host->this_id = 255;
        host->cmd_per_lun = 3;
        host->max_cmd_len = MAX_CMDSZ;
@@ -437,14 +409,362 @@ qla24xx_create_vhost(struct fc_vport *fc_vport)
 
        vha->flags.init_done = 1;
 
+       mutex_lock(&ha->vport_lock);
+       set_bit(vha->vp_idx, ha->vp_idx_map);
+       ha->cur_vport_count++;
+       mutex_unlock(&ha->vport_lock);
+
        return vha;
 
-create_vhost_failed_3:
-       kfree(vha->port_name);
+create_vhost_failed:
+       return NULL;
+}
 
-create_vhost_failed_2:
-       kfree(vha->node_name);
+static void
+qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint16_t que_id = req->id;
+
+       dma_free_coherent(&ha->pdev->dev, (req->length + 1) *
+               sizeof(request_t), req->ring, req->dma);
+       req->ring = NULL;
+       req->dma = 0;
+       if (que_id) {
+               ha->req_q_map[que_id] = NULL;
+               mutex_lock(&ha->vport_lock);
+               clear_bit(que_id, ha->req_qid_map);
+               mutex_unlock(&ha->vport_lock);
+       }
+       kfree(req);
+       req = NULL;
+}
 
-create_vhost_failed_1:
-       return NULL;
+static void
+qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
+{
+       struct qla_hw_data *ha = vha->hw;
+       uint16_t que_id = rsp->id;
+
+       if (rsp->msix && rsp->msix->have_irq) {
+               free_irq(rsp->msix->vector, rsp);
+               rsp->msix->have_irq = 0;
+               rsp->msix->rsp = NULL;
+       }
+       dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) *
+               sizeof(response_t), rsp->ring, rsp->dma);
+       rsp->ring = NULL;
+       rsp->dma = 0;
+       if (que_id) {
+               ha->rsp_q_map[que_id] = NULL;
+               mutex_lock(&ha->vport_lock);
+               clear_bit(que_id, ha->rsp_qid_map);
+               mutex_unlock(&ha->vport_lock);
+       }
+       kfree(rsp);
+       rsp = NULL;
+}
+
+int
+qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req)
+{
+       int ret = -1;
+
+       if (req) {
+               req->options |= BIT_0;
+               ret = qla25xx_init_req_que(vha, req);
+       }
+       if (ret == QLA_SUCCESS)
+               qla25xx_free_req_que(vha, req);
+
+       return ret;
+}
+
+int
+qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
+{
+       int ret = -1;
+
+       if (rsp) {
+               rsp->options |= BIT_0;
+               ret = qla25xx_init_rsp_que(vha, rsp);
+       }
+       if (ret == QLA_SUCCESS)
+               qla25xx_free_rsp_que(vha, rsp);
+
+       return ret;
+}
+
+int qla25xx_update_req_que(struct scsi_qla_host *vha, uint8_t que, uint8_t qos)
+{
+       int ret = 0;
+       struct qla_hw_data *ha = vha->hw;
+       struct req_que *req = ha->req_q_map[que];
+
+       req->options |= BIT_3;
+       req->qos = qos;
+       ret = qla25xx_init_req_que(vha, req);
+       if (ret != QLA_SUCCESS)
+               DEBUG2_17(printk(KERN_WARNING "%s failed\n", __func__));
+       /* restore options bit */
+       req->options &= ~BIT_3;
+       return ret;
+}
+
+
+/* Delete all queues for a given vhost */
+int
+qla25xx_delete_queues(struct scsi_qla_host *vha)
+{
+       int cnt, ret = 0;
+       struct req_que *req = NULL;
+       struct rsp_que *rsp = NULL;
+       struct qla_hw_data *ha = vha->hw;
+
+       /* Delete request queues */
+       for (cnt = 1; cnt < ha->max_req_queues; cnt++) {
+               req = ha->req_q_map[cnt];
+               if (req) {
+                       ret = qla25xx_delete_req_que(vha, req);
+                       if (ret != QLA_SUCCESS) {
+                               qla_printk(KERN_WARNING, ha,
+                               "Couldn't delete req que %d\n",
+                               req->id);
+                               return ret;
+                       }
+               }
+       }
+
+       /* Delete response queues */
+       for (cnt = 1; cnt < ha->max_rsp_queues; cnt++) {
+               rsp = ha->rsp_q_map[cnt];
+               if (rsp) {
+                       ret = qla25xx_delete_rsp_que(vha, rsp);
+                       if (ret != QLA_SUCCESS) {
+                               qla_printk(KERN_WARNING, ha,
+                               "Couldn't delete rsp que %d\n",
+                               rsp->id);
+                               return ret;
+                       }
+               }
+       }
+       return ret;
+}
+
+int
+qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options,
+       uint8_t vp_idx, uint16_t rid, int rsp_que, uint8_t qos)
+{
+       int ret = 0;
+       struct req_que *req = NULL;
+       struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
+       uint16_t que_id = 0;
+       device_reg_t __iomem *reg;
+       uint32_t cnt;
+
+       req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
+       if (req == NULL) {
+               qla_printk(KERN_WARNING, ha, "could not allocate memory"
+                       "for request que\n");
+               goto failed;
+       }
+
+       req->length = REQUEST_ENTRY_CNT_24XX;
+       req->ring = dma_alloc_coherent(&ha->pdev->dev,
+                       (req->length + 1) * sizeof(request_t),
+                       &req->dma, GFP_KERNEL);
+       if (req->ring == NULL) {
+               qla_printk(KERN_WARNING, ha,
+               "Memory Allocation failed - request_ring\n");
+               goto que_failed;
+       }
+
+       mutex_lock(&ha->vport_lock);
+       que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues);
+       if (que_id >= ha->max_req_queues) {
+               mutex_unlock(&ha->vport_lock);
+               qla_printk(KERN_INFO, ha, "No resources to create "
+                        "additional request queue\n");
+               goto que_failed;
+       }
+       set_bit(que_id, ha->req_qid_map);
+       ha->req_q_map[que_id] = req;
+       req->rid = rid;
+       req->vp_idx = vp_idx;
+       req->qos = qos;
+
+       if (rsp_que < 0)
+               req->rsp = NULL;
+       else
+               req->rsp = ha->rsp_q_map[rsp_que];
+       /* Use alternate PCI bus number */
+       if (MSB(req->rid))
+               options |= BIT_4;
+       /* Use alternate PCI devfn */
+       if (LSB(req->rid))
+               options |= BIT_5;
+       req->options = options;
+
+       for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
+               req->outstanding_cmds[cnt] = NULL;
+       req->current_outstanding_cmd = 1;
+
+       req->ring_ptr = req->ring;
+       req->ring_index = 0;
+       req->cnt = req->length;
+       req->id = que_id;
+       reg = ISP_QUE_REG(ha, que_id);
+       req->max_q_depth = ha->req_q_map[0]->max_q_depth;
+       mutex_unlock(&ha->vport_lock);
+
+       ret = qla25xx_init_req_que(base_vha, req);
+       if (ret != QLA_SUCCESS) {
+               qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
+               mutex_lock(&ha->vport_lock);
+               clear_bit(que_id, ha->req_qid_map);
+               mutex_unlock(&ha->vport_lock);
+               goto que_failed;
+       }
+
+       return req->id;
+
+que_failed:
+       qla25xx_free_req_que(base_vha, req);
+failed:
+       return 0;
+}
+
+static void qla_do_work(struct work_struct *work)
+{
+       struct rsp_que *rsp = container_of(work, struct rsp_que, q_work);
+       struct scsi_qla_host *vha;
+
+       spin_lock_irq(&rsp->hw->hardware_lock);
+       vha = qla25xx_get_host(rsp);
+       qla24xx_process_response_queue(vha, rsp);
+       spin_unlock_irq(&rsp->hw->hardware_lock);
+}
+
+/* create response queue */
+int
+qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
+       uint8_t vp_idx, uint16_t rid, int req)
+{
+       int ret = 0;
+       struct rsp_que *rsp = NULL;
+       struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
+       uint16_t que_id = 0;
+       device_reg_t __iomem *reg;
+
+       rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
+       if (rsp == NULL) {
+               qla_printk(KERN_WARNING, ha, "could not allocate memory for"
+                               " response que\n");
+               goto failed;
+       }
+
+       rsp->length = RESPONSE_ENTRY_CNT_MQ;
+       rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
+                       (rsp->length + 1) * sizeof(response_t),
+                       &rsp->dma, GFP_KERNEL);
+       if (rsp->ring == NULL) {
+               qla_printk(KERN_WARNING, ha,
+               "Memory Allocation failed - response_ring\n");
+               goto que_failed;
+       }
+
+       mutex_lock(&ha->vport_lock);
+       que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues);
+       if (que_id >= ha->max_rsp_queues) {
+               mutex_unlock(&ha->vport_lock);
+               qla_printk(KERN_INFO, ha, "No resources to create "
+                        "additional response queue\n");
+               goto que_failed;
+       }
+       set_bit(que_id, ha->rsp_qid_map);
+
+       if (ha->flags.msix_enabled)
+               rsp->msix = &ha->msix_entries[que_id + 1];
+       else
+               qla_printk(KERN_WARNING, ha, "msix not enabled\n");
+
+       ha->rsp_q_map[que_id] = rsp;
+       rsp->rid = rid;
+       rsp->vp_idx = vp_idx;
+       rsp->hw = ha;
+       /* Use alternate PCI bus number */
+       if (MSB(rsp->rid))
+               options |= BIT_4;
+       /* Use alternate PCI devfn */
+       if (LSB(rsp->rid))
+               options |= BIT_5;
+       /* Enable MSIX handshake mode on for uncapable adapters */
+       if (!IS_MSIX_NACK_CAPABLE(ha))
+               options |= BIT_6;
+
+       rsp->options = options;
+       rsp->id = que_id;
+       reg = ISP_QUE_REG(ha, que_id);
+       rsp->rsp_q_in = &reg->isp25mq.rsp_q_in;
+       rsp->rsp_q_out = &reg->isp25mq.rsp_q_out;
+       mutex_unlock(&ha->vport_lock);
+
+       ret = qla25xx_request_irq(rsp);
+       if (ret)
+               goto que_failed;
+
+       ret = qla25xx_init_rsp_que(base_vha, rsp);
+       if (ret != QLA_SUCCESS) {
+               qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
+               mutex_lock(&ha->vport_lock);
+               clear_bit(que_id, ha->rsp_qid_map);
+               mutex_unlock(&ha->vport_lock);
+               goto que_failed;
+       }
+       if (req >= 0)
+               rsp->req = ha->req_q_map[req];
+       else
+               rsp->req = NULL;
+
+       qla2x00_init_response_q_entries(rsp);
+       if (rsp->hw->wq)
+               INIT_WORK(&rsp->q_work, qla_do_work);
+       return rsp->id;
+
+que_failed:
+       qla25xx_free_rsp_que(base_vha, rsp);
+failed:
+       return 0;
+}
+
+int
+qla25xx_create_queues(struct scsi_qla_host *vha, uint8_t qos)
+{
+       uint16_t options = 0;
+       uint8_t ret = 0;
+       struct qla_hw_data *ha = vha->hw;
+       struct rsp_que *rsp;
+
+       options |= BIT_1;
+       ret = qla25xx_create_rsp_que(ha, options, vha->vp_idx, 0, -1);
+       if (!ret) {
+               qla_printk(KERN_WARNING, ha, "Response Que create failed\n");
+               return ret;
+       } else
+               qla_printk(KERN_INFO, ha, "Response Que:%d created.\n", ret);
+       rsp = ha->rsp_q_map[ret];
+
+       options = 0;
+       if (qos & BIT_7)
+               options |= BIT_8;
+       ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, ret,
+                                       qos & ~BIT_7);
+       if (ret) {
+               vha->req = ha->req_q_map[ret];
+               qla_printk(KERN_INFO, ha, "Request Que:%d created.\n", ret);
+       } else
+               qla_printk(KERN_WARNING, ha, "Request Que create failed\n");
+       rsp->req = ha->req_q_map[ret];
+
+       return ret;
 }