[SCSI] qla2xxx: General checkpatch corrections.
[cascardo/linux.git] / drivers / scsi / qla2xxx / qla_os.c
index 209f50e..6bdc7de 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/kthread.h>
 #include <linux/mutex.h>
 #include <linux/kobject.h>
+#include <linux/slab.h>
 
 #include <scsi/scsi_tcq.h>
 #include <scsi/scsicam.h>
@@ -107,6 +108,12 @@ MODULE_PARM_DESC(ql2xfwloadbin,
                " 1 -- load firmware from flash.\n"
                " 0 -- use default semantics.\n");
 
+int ql2xetsenable;
+module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR);
+MODULE_PARM_DESC(ql2xetsenable,
+               "Enables firmware ETS burst."
+               "Default is 0 - skip ETS enablement.");
+
 /*
  * SCSI host template entry points
  */
@@ -682,44 +689,6 @@ qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
        return (return_status);
 }
 
-void
-qla2x00_abort_fcport_cmds(fc_port_t *fcport)
-{
-       int cnt;
-       unsigned long flags;
-       srb_t *sp;
-       scsi_qla_host_t *vha = fcport->vha;
-       struct qla_hw_data *ha = vha->hw;
-       struct req_que *req;
-
-       spin_lock_irqsave(&ha->hardware_lock, flags);
-       req = vha->req;
-       for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
-               sp = req->outstanding_cmds[cnt];
-               if (!sp)
-                       continue;
-               if (sp->fcport != fcport)
-                       continue;
-               if (sp->ctx)
-                       continue;
-
-               spin_unlock_irqrestore(&ha->hardware_lock, flags);
-               if (ha->isp_ops->abort_command(sp)) {
-                       DEBUG2(qla_printk(KERN_WARNING, ha,
-                       "Abort failed --  %lx\n",
-                       sp->cmd->serial_number));
-               } else {
-                       if (qla2x00_eh_wait_on_command(sp->cmd) !=
-                               QLA_SUCCESS)
-                               DEBUG2(qla_printk(KERN_WARNING, ha,
-                               "Abort failed while waiting --  %lx\n",
-                               sp->cmd->serial_number));
-               }
-               spin_lock_irqsave(&ha->hardware_lock, flags);
-       }
-       spin_unlock_irqrestore(&ha->hardware_lock, flags);
-}
-
 /**************************************************************************
 * qla2xxx_eh_abort
 *
@@ -1095,6 +1064,20 @@ qla2x00_loop_reset(scsi_qla_host_t *vha)
        struct fc_port *fcport;
        struct qla_hw_data *ha = vha->hw;
 
+       if (ha->flags.enable_target_reset) {
+               list_for_each_entry(fcport, &vha->vp_fcports, list) {
+                       if (fcport->port_type != FCT_TARGET)
+                               continue;
+
+                       ret = ha->isp_ops->target_reset(fcport, 0, 0);
+                       if (ret != QLA_SUCCESS) {
+                               DEBUG2_3(printk("%s(%ld): bus_reset failed: "
+                                   "target_reset=%d d_id=%x.\n", __func__,
+                                   vha->host_no, ret, fcport->d_id.b24));
+                       }
+               }
+       }
+
        if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
                ret = qla2x00_full_login_lip(vha);
                if (ret != QLA_SUCCESS) {
@@ -1117,19 +1100,6 @@ qla2x00_loop_reset(scsi_qla_host_t *vha)
                        qla2x00_wait_for_loop_ready(vha);
        }
 
-       if (ha->flags.enable_target_reset) {
-               list_for_each_entry(fcport, &vha->vp_fcports, list) {
-                       if (fcport->port_type != FCT_TARGET)
-                               continue;
-
-                       ret = ha->isp_ops->target_reset(fcport, 0, 0);
-                       if (ret != QLA_SUCCESS) {
-                               DEBUG2_3(printk("%s(%ld): bus_reset failed: "
-                                   "target_reset=%d d_id=%x.\n", __func__,
-                                   vha->host_no, ret, fcport->d_id.b24));
-                       }
-               }
-       }
        /* Issue marker command only when we are going to start the I/O */
        vha->marker_needed = 1;
 
@@ -1160,8 +1130,27 @@ qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
                                        qla2x00_sp_compl(ha, sp);
                                } else {
                                        ctx = sp->ctx;
-                                       del_timer_sync(&ctx->timer);
-                                       ctx->free(sp);
+                                       if (ctx->type == SRB_LOGIN_CMD ||
+                                           ctx->type == SRB_LOGOUT_CMD) {
+                                               del_timer_sync(&ctx->timer);
+                                               ctx->free(sp);
+                                       } else {
+                                               struct srb_bsg *sp_bsg =
+                                                   (struct srb_bsg *)sp->ctx;
+                                               struct fc_bsg_job *bsg_job =
+                                                   sp_bsg->bsg_job;
+
+                                               if (bsg_job->request->msgcode
+                                                   == FC_BSG_HST_CT)
+                                                       kfree(sp->fcport);
+                                               bsg_job->req->errors = 0;
+                                               bsg_job->reply->result = res;
+                                               bsg_job->job_done(
+                                                   sp_bsg->bsg_job);
+                                               kfree(sp->ctx);
+                                               mempool_free(sp,
+                                                   ha->srb_mempool);
+                                       }
                                }
                        }
                }
@@ -1188,7 +1177,6 @@ qla2xxx_slave_configure(struct scsi_device *sdev)
        scsi_qla_host_t *vha = shost_priv(sdev->host);
        struct qla_hw_data *ha = vha->hw;
        struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
-       fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
        struct req_que *req = vha->req;
 
        if (sdev->tagged_supported)
@@ -1197,8 +1185,6 @@ qla2xxx_slave_configure(struct scsi_device *sdev)
                scsi_deactivate_tcq(sdev, req->max_q_depth);
 
        rport->dev_loss_tmo = ha->port_down_retry_count;
-       if (sdev->type == TYPE_TAPE)
-               fcport->flags |= FCF_TAPE_PRESENT;
 
        return 0;
 }
@@ -1261,7 +1247,7 @@ qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
                qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
                break;
        default:
-               return EOPNOTSUPP;
+               return -EOPNOTSUPP;
        }
 
        return sdev->queue_depth;
@@ -1699,9 +1685,11 @@ skip_pio:
 
        /* Determine queue resources */
        ha->max_req_queues = ha->max_rsp_queues = 1;
-       if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
+       if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
+               (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
                (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
                goto mqiobase_exit;
+
        ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
                        pci_resource_len(ha->pdev, 3));
        if (ha->mqiobase) {
@@ -1821,7 +1809,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        /* Set EEH reset type to fundamental if required by hba */
        if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
                pdev->needs_freset = 1;
-               pci_save_state(pdev);
        }
 
        /* Configure PCI I/O space */
@@ -1973,11 +1960,15 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        host->max_channel = MAX_BUSES - 1;
        host->max_lun = MAX_LUNS;
        host->transportt = qla2xxx_transport_template;
+       sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
 
        /* Set up the irqs */
        ret = qla2x00_request_irqs(ha, rsp);
        if (ret)
                goto probe_init_failed;
+
+       pci_save_state(pdev);
+
        /* Alloc arrays of request and response ring ptrs */
 que_init:
        if (!qla2x00_alloc_queues(ha)) {
@@ -2179,6 +2170,8 @@ qla2x00_remove_one(struct pci_dev *pdev)
        kfree(ha);
        ha = NULL;
 
+       pci_disable_pcie_error_reporting(pdev);
+
        pci_disable_device(pdev);
        pci_set_drvdata(pdev, NULL);
 }
@@ -2805,7 +2798,7 @@ void qla2x00_relogin(struct scsi_qla_host *vha)
 
                        fcport->login_retry--;
                        if (fcport->flags & FCF_FABRIC_DEVICE) {
-                               if (fcport->flags & FCF_TAPE_PRESENT)
+                               if (fcport->flags & FCF_FCP2_DEVICE)
                                        ha->isp_ops->fabric_logout(vha,
                                                        fcport->loop_id,
                                                        fcport->d_id.b.domain,
@@ -3141,7 +3134,10 @@ qla2x00_timer(scsi_qla_host_t *vha)
                        if (!IS_QLA2100(ha) && vha->link_down_timeout)
                                atomic_set(&vha->loop_state, LOOP_DEAD);
 
-                       /* Schedule an ISP abort to return any tape commands. */
+                       /*
+                        * Schedule an ISP abort to return any FCP2-device
+                        * commands.
+                        */
                        /* NPIV - scan physical port only */
                        if (!vha->vp_idx) {
                                spin_lock_irqsave(&ha->hardware_lock,
@@ -3158,7 +3154,7 @@ qla2x00_timer(scsi_qla_host_t *vha)
                                        if (sp->ctx)
                                                continue;
                                        sfcp = sp->fcport;
-                                       if (!(sfcp->flags & FCF_TAPE_PRESENT))
+                                       if (!(sfcp->flags & FCF_FCP2_DEVICE))
                                                continue;
 
                                        set_bit(ISP_ABORT_NEEDED,
@@ -3310,6 +3306,7 @@ qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
                return PCI_ERS_RESULT_CAN_RECOVER;
        case pci_channel_io_frozen:
                ha->flags.eeh_busy = 1;
+               qla2x00_free_irqs(vha);
                pci_disable_device(pdev);
                return PCI_ERS_RESULT_NEED_RESET;
        case pci_channel_io_perm_failure:
@@ -3363,10 +3360,24 @@ qla2xxx_pci_slot_reset(struct pci_dev *pdev)
        pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
        scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
        struct qla_hw_data *ha = base_vha->hw;
-       int rc;
+       struct rsp_que *rsp;
+       int rc, retries = 10;
 
        DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
 
+       /* Workaround: qla2xxx driver which access hardware earlier
+        * needs error state to be pci_channel_io_online.
+        * Otherwise mailbox command timesout.
+        */
+       pdev->error_state = pci_channel_io_normal;
+
+       pci_restore_state(pdev);
+
+       /* pci_restore_state() clears the saved_state flag of the device
+        * save restored state which resets saved_state flag
+        */
+       pci_save_state(pdev);
+
        if (ha->mem_only)
                rc = pci_enable_device_mem(pdev);
        else
@@ -3378,27 +3389,23 @@ qla2xxx_pci_slot_reset(struct pci_dev *pdev)
                return ret;
        }
 
+       rsp = ha->rsp_q_map[0];
+       if (qla2x00_request_irqs(ha, rsp))
+               return ret;
+
        if (ha->isp_ops->pci_config(base_vha))
                return ret;
 
-#ifdef QL_DEBUG_LEVEL_17
-       {
-               uint8_t b;
-               uint32_t i;
+       while (ha->flags.mbox_busy && retries--)
+               msleep(1000);
 
-               printk("slot_reset_1: ");
-               for (i = 0; i < 256; i++) {
-                       pci_read_config_byte(ha->pdev, i, &b);
-                       printk("%s%02x", (i%16) ? " " : "\n", b);
-               }
-               printk("\n");
-       }
-#endif
        set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
        if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
                ret =  PCI_ERS_RESULT_RECOVERED;
        clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
 
+       pci_cleanup_aer_uncorrect_error_status(pdev);
+
        DEBUG17(qla_printk(KERN_WARNING, ha,
            "slot_reset-return:ret=%x\n", ret));
 
@@ -3422,8 +3429,6 @@ qla2xxx_pci_resume(struct pci_dev *pdev)
        }
 
        ha->flags.eeh_busy = 0;
-
-       pci_cleanup_aer_uncorrect_error_status(pdev);
 }
 
 static struct pci_error_handlers qla2xxx_err_handler = {
@@ -3536,4 +3541,3 @@ MODULE_FIRMWARE(FW_FILE_ISP2300);
 MODULE_FIRMWARE(FW_FILE_ISP2322);
 MODULE_FIRMWARE(FW_FILE_ISP24XX);
 MODULE_FIRMWARE(FW_FILE_ISP25XX);
-MODULE_FIRMWARE(FW_FILE_ISP81XX);