qla2x00.c
来自「这个linux源代码是很全面的~基本完整了~使用c编译的~由于时间问题我没有亲自」· C语言 代码 · 共 2,417 行 · 第 1/5 页
C
2,417 行
static inline void__sp_put(struct scsi_qla_host * ha, srb_t *sp){ if (atomic_read(&sp->ref_count) == 0) BUG(); if (!atomic_dec_and_test(&sp->ref_count)) { return; } qla2x00_callback(ha, sp->cmd);}/*************************************************************************** qla2x00_cmd_timeout** Description:* Handles the command if it times out in any state.** Input:* sp - pointer to validate** Returns:* None.* Note:Need to add the support for if( sp->state == SRB_FAILOVER_STATE).**************************************************************************/voidqla2x00_cmd_timeout(srb_t *sp){ int t, l; int processed; scsi_qla_host_t *vis_ha, *dest_ha; Scsi_Cmnd *cmd; ulong flags;#if defined(QL_DEBUG_LEVEL_3) ulong cpu_flags;#endif fc_port_t *fcport; cmd = sp->cmd; vis_ha = (scsi_qla_host_t *) cmd->host->hostdata; DEBUG3(printk("cmd_timeout: Entering sp->state = %x\n", sp->state);) t = SCSI_TCN_32(cmd); l = SCSI_LUN_32(cmd); fcport = sp->fclun->fcport; dest_ha = sp->ha; /* * If IO is found either in retry Queue * OR in Lun Queue * Return this IO back to host */ spin_lock_irqsave(&vis_ha->list_lock, flags); processed = 0; if (sp->state == SRB_PENDING_STATE) { __del_from_pending_queue(vis_ha, sp); DEBUG2(printk("qla2100%ld: Found in Pending queue " "pid %ld, State = %x., " "fcport state=%d jiffies=%lx\n", vis_ha->host_no, sp->cmd->serial_number, sp->state, atomic_read(&fcport->state), jiffies);) /* * If FC_DEVICE is marked as dead return the cmd with * DID_NO_CONNECT status. Otherwise set the host_byte to * DID_BUS_BUSY to let the OS retry this cmd. */ if (atomic_read(&fcport->state) == FC_DEVICE_DEAD) { cmd->result = DID_NO_CONNECT << 16; } else { cmd->result = DID_BUS_BUSY << 16; } __add_to_done_queue(vis_ha, sp); processed++; } spin_unlock_irqrestore(&vis_ha->list_lock, flags); if (processed) {#if QLA2X_PERFORMANCE tasklet_schedule(&vis_ha->run_qla_task);#else if (vis_ha->dpc_wait && !vis_ha->dpc_active) up(vis_ha->dpc_wait);#endif return; } spin_lock_irqsave(&dest_ha->list_lock, flags); if ((sp->state == SRB_RETRY_STATE) || (sp->state == SRB_SCSI_RETRY_STATE) || (sp->state == SRB_FAILOVER_STATE)) { DEBUG2(printk("qla2100%ld: Found in (Scsi) Retry queue or " "failover Q pid %ld, State = %x., " "fcport state=%d jiffies=%lx retried=%d\n", dest_ha->host_no, sp->cmd->serial_number, sp->state, atomic_read(&fcport->state), jiffies, sp->cmd->retries);) if ((sp->state == SRB_RETRY_STATE)) { __del_from_retry_queue(dest_ha, sp); } else if ((sp->state == SRB_SCSI_RETRY_STATE)) { __del_from_scsi_retry_queue(dest_ha, sp);#if MPIO_SUPPORT } else if ((sp->state == SRB_FAILOVER_STATE)) { __del_from_failover_queue(dest_ha, sp);#endif } /* * If FC_DEVICE is marked as dead return the cmd with * DID_NO_CONNECT status. Otherwise set the host_byte to * DID_BUS_BUSY to let the OS retry this cmd. */#if MPIO_SUPPORT cmd->result = DID_BUS_BUSY << 16;#else if (atomic_read(&fcport->state) == FC_DEVICE_DEAD) { cmd->result = DID_NO_CONNECT << 16; qla2x00_extend_timeout(cmd, EXTEND_CMD_TIMEOUT); } else { cmd->result = DID_BUS_BUSY << 16; }#endif __add_to_done_queue(dest_ha, sp); processed++; } spin_unlock_irqrestore(&dest_ha->list_lock, flags); if (processed) {#if QLA2X_PERFORMANCE tasklet_schedule(&dest_ha->run_qla_task);#else if (dest_ha->dpc_wait && !dest_ha->dpc_active) up(dest_ha->dpc_wait);#endif return; }#if defined(QL_DEBUG_LEVEL_3) spin_lock_irqsave(&dest_ha->list_lock, cpu_flags); if (sp->state == SRB_DONE_STATE) { /* IO in done_q -- leave it */ DEBUG(printk("qla2100%ld: Found in Done queue pid %ld sp=%p.\n", dest_ha->host_no, sp->cmd->serial_number, sp);) } else if (sp->state == SRB_SUSPENDED_STATE) { DEBUG(printk("qla2100%ld: Found SP %p in suspended state " "- pid %d:\n", dest_ha->host_no,sp, (int)sp->cmd->serial_number);) DEBUG(qla2x00_dump_buffer((uint8_t *)sp, sizeof(srb_t));) } else if (sp->state == SRB_ACTIVE_STATE) { /* * IO is with ISP find the command in our active list. */ spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags); spin_lock_irqsave(&dest_ha->hardware_lock, flags); if (sp == dest_ha->outstanding_cmds [(u_long)CMD_HANDLE(sp->cmd)]) { DEBUG(printk("cmd_timeout: Found in ISP \n");) sp->state = SRB_ACTIVE_TIMEOUT_STATE; spin_unlock_irqrestore(&dest_ha->hardware_lock, flags); } else { spin_unlock_irqrestore(&dest_ha->hardware_lock, flags); printk(KERN_INFO "qla_cmd_timeout: State indicates it is with " "ISP, But not in active array\n"); } spin_lock_irqsave(&dest_ha->list_lock, cpu_flags); } else if (sp->state == SRB_ACTIVE_TIMEOUT_STATE) { DEBUG(printk("qla2100%ld: Found in Active timeout state" "pid %ld, State = %x., \n", dest_ha->host_no, sp->cmd->serial_number, sp->state);) } else { /* EMPTY */ DEBUG2(printk("cmd_timeout%ld: LOST command state = " "0x%x, sp=%p\n", vis_ha->host_no, sp->state,sp);) printk(KERN_INFO "cmd_timeout: LOST command state = 0x%x\n", sp->state); } spin_unlock_irqrestore(&dest_ha->list_lock, cpu_flags);#endif DEBUG3(printk("cmd_timeout: Leaving\n");)}/*************************************************************************** qla2x00_add_timer_to_cmd** Description:* Creates a timer for the specified command. The timeout is usually* the command time from kernel minus 2 secs.** Input:* sp - pointer to validate** Returns:* None.**************************************************************************/voidqla2x00_add_timer_to_cmd(srb_t *sp, int timeout){ init_timer(&sp->timer); sp->timer.expires = jiffies + timeout * HZ; sp->timer.data = (unsigned long) sp; sp->timer.function = (void (*) (unsigned long))qla2x00_cmd_timeout; add_timer(&sp->timer);}/*************************************************************************** qla2x00_delete_timer_from_cmd** Description:* Delete the timer for the specified command.** Input:* sp - pointer to validate** Returns:* None.**************************************************************************/voidqla2x00_delete_timer_from_cmd(srb_t *sp ){ if (sp->timer.function != NULL) { del_timer(&sp->timer); sp->timer.function = NULL; sp->timer.data = (unsigned long) NULL; }}/*************************************************************************** qla2x00_detect** Description:* This routine will probe for Qlogic FC SCSI host adapters.* It returns the number of host adapters of a particular* type that were found. It also initialize all data necessary for* the driver. It is passed-in the host number, so that it* knows where its first entry is in the scsi_hosts[] array.** Input:* template - pointer to SCSI template** Returns:* num - number of host adapters found.**************************************************************************/intqla2x00_detect(Scsi_Host_Template *template){ device_reg_t *reg; int i; uint16_t subsystem_vendor, subsystem_device; struct Scsi_Host *host; scsi_qla_host_t *ha = NULL, *cur_ha; struct _qlaboards *bdp; unsigned long flags = 0; unsigned long wait_switch = 0; struct pci_dev *pdev = NULL; ENTER("qla2x00_detect");#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_unlock_irq(&io_request_lock);#endif#if defined(MODULE) DEBUG2(printk("DEBUG: qla2x00_set_info starts at address = %p\n", qla2x00_set_info);) printk(KERN_INFO "qla2x00_set_info starts at address = %p\n", qla2x00_set_info); /* * If we are called as a module, the qla2100 pointer may not be null * and it would point to our bootup string, just like on the lilo * command line. IF not NULL, then process this config string with * qla2x00_setup * * Boot time Options To add options at boot time add a line to your * lilo.conf file like: * append="qla2100=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}" * which will result in the first four devices on the first two * controllers being set to a tagged queue depth of 32. */ if (ql2xopts) qla2x00_setup(ql2xopts); if (dummy_buffer[0] != 'P') printk(KERN_WARNING "qla2x00: Please read the file " "/usr/src/linux/drivers/scsi/README.qla2x00\n" "qla2x00: to see the proper way to specify options to " "the qla2x00 module\n" "qla2x00: Specifically, don't use any commas when " "passing arguments to\n" "qla2x00: insmod or else it might trash certain memory " "areas.\n");#endif if (!pci_present()) { printk("scsi: PCI not present\n");#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_lock_irq(&io_request_lock);#endif return 0; } /* end of !pci_present() */ bdp = &QLBoardTbl_fc[0]; qla2x00_hostlist = NULL; template->proc_name = DRIVER_NAME; /* Try and find each different type of adapter we support */ for (i = 0; bdp->device_id != 0 && i < NUM_OF_ISP_DEVICES; i++, bdp++) { /* PCI_SUBSYSTEM_IDS supported */ while ((pdev = pci_find_subsys(QLA2X00_VENDOR_ID, bdp->device_id, PCI_ANY_ID, PCI_ANY_ID, pdev))) { if (pci_enable_device(pdev)) continue; /* found a adapter */ printk(KERN_INFO "qla2x00: Found VID=%x DID=%x " "SSVID=%x SSDID=%x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, pdev->subsystem_device); subsystem_vendor = pdev->subsystem_vendor; subsystem_device = pdev->subsystem_device; /* If it's an XXX SubSys Vendor ID adapter, skip it. */ /* if (pdev->subsystem_vendor == PCI_VENDOR_ID_XXX) { printk(KERN_WARNING "qla2x00: Skip XXX SubSys Vendor ID " "Controller\n"); continue; } */#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_lock_irq(&io_request_lock);#endif#if defined(ISP2100) template->name = "QLogic Fibre Channel 2100";#endif#if defined(ISP2200) template->name = "QLogic Fibre Channel 2200";#endif#if defined(ISP2300) template->name = "QLogic Fibre Channel 2300";#endif if ((host = scsi_register( template, sizeof(scsi_qla_host_t))) == NULL) { printk(KERN_WARNING "qla2x00: couldn't register " "with scsi layer\n"); return 0; } ha = (scsi_qla_host_t *)host->hostdata; /* Clear our data area */ memset(ha, 0, sizeof(scsi_qla_host_t)); ha->host_no = host->host_no; ha->host = host; /* Sanitize the information from PCI BIOS. */ host->irq = pdev->irq; host->io_port = pci_resource_start(pdev, 0); ha->subsystem_vendor = subsystem_vendor; ha->subsystem_device = subsystem_device; ha->pdev = pdev;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,4) scsi_set_pci_device(host, pdev);#endif ha->device_id = bdp->device_id; ha->devnum = i; if (qla2x00_verbose) { printk(KERN_INFO "scsi%d: Found a %s @ bus %d, " "device 0x%x, irq %d, iobase 0x%lx\n", host->host_no, bdp->bdName, ha->pdev->bus->number, PCI_SLOT(ha->pdev->devfn), host->irq, (unsigned long)host->io_port); } ha->iobase = (device_reg_t *) host->io_port; spin_lock_init(&ha->hardware_lock); /* 4.23 Initialize /proc/scsi/qla2x00 counters */ ha->actthreads = 0; ha->qthreads = 0; ha->dump_done = 0; ha->total_isr_cnt = 0; ha->total_isp_aborts = 0; ha->total_lip_cnt = 0; ha->total_dev_errs = 0; ha->total_ios = 0; ha->total_bytes = 0; if (qla2x00_mem_alloc(ha)) { printk(KERN_WARNING "scsi%d: [ERROR] Failed to allocate " "memory for adapter\n",host->host_no); qla2x00_mem_free(ha);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_unlock_irq(&io_request_lock);#endif continue; } ha->prev_topology = 0; ha->ports = bdp->numPorts;#if defined(ISP2100) ha->max_targets = MAX_TARGETS_2100;#else ha->max_targets = MAX_TARGETS_2200;#endif /* load the F/W, read paramaters, and init the H/W */ ha->instance = num_hosts; init_MUTEX_LOCKED(&ha->mbx_intr_sem); INIT_LIST_HEAD(&ha->done_queue); INIT_LIST_HEAD(&ha->retry_queue); INIT_LIST_HEAD(&ha->scsi_retry_queue); INIT_LIST_HEAD(&ha->failover_queue); INIT_LIST_HEAD(&ha->pending_queue);#if MPIO_SUPPORT if (qla2x00_failover) ha->flags.failover_enabled = 1;#else ha->flags.failover_enabled = 0;#endif#if QLA2X_PERFORMANCE tasklet_init(&ha->run_qla_task, (void *)qla2x00_done_tasklet, (unsigned long) ha);#endif /* * These locks are used to prevent more than one CPU * from modifying the queue at the same time. The * higher level "io_request_lock" will reduce most * contention for these locks. */ spin_lock_init(&ha->mbx_bits_lock); spin_lock_init(&ha->mbx_reg_lock); spin_lock_init(&ha->mbx_q_lock); spin_lock_init(&ha->list_lock);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?