qla2x00.c
来自「这个linux源代码是很全面的~基本完整了~使用c编译的~由于时间问题我没有亲自」· C语言 代码 · 共 2,417 行 · 第 1/5 页
C
2,417 行
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_unlock_irq(&io_request_lock);#endif if (qla2x00_initialize_adapter(ha) && !(ha->device_flags & DFLG_NO_CABLE)) { printk(KERN_WARNING "qla2x00: Failed to " "initialize adapter\n"); DEBUG2(printk("scsi%ld: Failed to initialize " "adapter - Adapter flags %x.\n", ha->host_no, ha->device_flags);) qla2x00_mem_free(ha); scsi_unregister(host); continue; } /* * Startup the kernel thread for this host adapter */#if defined(ISP2100) ha->dpc_notify = &qla2100_detect_sem;#endif#if defined(ISP2200) ha->dpc_notify = &qla2200_detect_sem;#endif#if defined(ISP2300) ha->dpc_notify = &qla2300_detect_sem;#endif kernel_thread((int (*)(void *))qla2x00_do_dpc, (void *) ha, 0); /* * Now wait for the kernel dpc thread to initialize * and go to sleep. */#if defined(ISP2100) down(&qla2100_detect_sem);#endif#if defined(ISP2200) down(&qla2200_detect_sem);#endif#if defined(ISP2300) down(&qla2300_detect_sem);#endif ha->dpc_notify = NULL; ha->next = NULL; /* Mark preallocated Loop IDs in use. */ ha->fabricid[SNS_FL_PORT].in_use = TRUE; ha->fabricid[FABRIC_CONTROLLER].in_use = TRUE; ha->fabricid[SIMPLE_NAME_SERVER].in_use = TRUE;#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_lock_irq(&io_request_lock);#endif /* Register our resources with Linux */ if (qla2x00_register_with_Linux(ha, bdp->numPorts-1)) { printk(KERN_WARNING "scsi%ld: Failed to " "register resources.\n", ha->host_no);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_unlock_irq(&io_request_lock);#endif qla2x00_mem_free(ha);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_lock_irq(&io_request_lock);#endif scsi_unregister(host);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_unlock_irq(&io_request_lock);#endif continue; } DEBUG2(printk("DEBUG: detect hba %ld at " "address = %p\n", ha->host_no,ha);) reg = ha->iobase; /* Disable ISP interrupts. */ qla2x00_disable_intrs(ha); /* Ensure mailbox registers are free. */ spin_lock_irqsave(&ha->hardware_lock, flags); WRT_REG_WORD(®->semaphore, 0); WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT); WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);#if defined(ISP2300) /* Enable SRAM, Instruction RAM and GP RAM parity. */ WRT_REG_WORD(®->host_cmd, (HC_ENABLE_PARITY + 0x7));#endif spin_unlock_irqrestore(&ha->hardware_lock, flags);#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_unlock_irq(&io_request_lock);#endif#if MPIO_SUPPORT /* * if failover is enabled read the user configuration */ if (ha->flags.failover_enabled) { if (ConfigRequired > 0) mp_config_required = 1; else mp_config_required = 0; DEBUG(printk("qla2x00_detect: qla2x00_cfg_init " "for hba %ld\n", ha->instance);) qla2x00_cfg_init(ha); }#endif /* Enable chip interrupts. */ qla2x00_enable_intrs(ha); /* Insert new entry into the list of adapters */ ha->next = NULL; if( qla2x00_hostlist == NULL ) { qla2x00_hostlist = ha; } else { cur_ha = qla2x00_hostlist; while( cur_ha->next != NULL ) cur_ha = cur_ha->next; cur_ha->next = ha; } /* v2.19.5b6 */ /* * Wait around max loop_reset_delay secs for the * devices to come on-line. We don't want Linux * scanning before we are ready. */ for (wait_switch = jiffies + (ha->loop_reset_delay * HZ); /* jiffies < wait_switch */ time_before(jiffies,wait_switch) && !(ha->device_flags & (DFLG_NO_CABLE | DFLG_FABRIC_DEVICES)) && (ha->device_flags & SWITCH_FOUND) ;) { qla2x00_check_fabric_devices(ha); set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(5); }/* FlexServ Patch */#if defined(CONFIG_MD_MULTIHOST) { unsigned long i; union { __u64 identifier; char wwn[WWN_SIZE]; } foo; for (i = 0; i < WWN_SIZE; i++) { foo.wwn[i] = ha->init_cb->port_name[i]; } host->host_identifier = foo.identifier; }#endif /* CONFIG_MD_MULTIHOST */ /* List the target we have found */ if (displayConfig && (!ha->flags.failover_enabled)) qla2x00_display_fc_names(ha); ha->init_done = 1; num_hosts++; } } /* end of FOR */#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) spin_lock_irq(&io_request_lock);#endif#if MPIO_SUPPORT if (displayConfig && ha->flags.failover_enabled) qla2x00_cfg_display_devices();#endif LEAVE("qla2x00_detect"); return num_hosts;}/*************************************************************************** qla2x00_register_with_Linux** Description:* Free the passed in Scsi_Host memory structures prior to unloading the* module.** Input:* ha - pointer to host adapter structure* maxchannels - MAX number of channels.** Returns:* 0 - Sucessfully reserved resources.* 1 - Failed to reserved a resource.**************************************************************************/STATIC uint8_tqla2x00_register_with_Linux(scsi_qla_host_t *ha, uint8_t maxchannels){ struct Scsi_Host *host = ha->host; host->can_queue = max_srbs; /* default value:-MAX_SRBS(4096) */ host->cmd_per_lun = 1; host->select_queue_depths = qla2x00_select_queue_depth; host->n_io_port = 0xFF;#if MEMORY_MAPPED_IO host->base = (unsigned long) ha->mmpbase;#else host->base = 0;#endif host->max_channel = maxchannels; /* fix: 07/31 host->max_lun = MAX_LUNS-1; */ host->max_lun = ha->max_luns; host->unique_id = ha->instance; host->max_id = ha->max_targets; /* set our host ID (need to do something about our two IDs) */ host->this_id = 255; /* Register the I/O space with Linux */ if (check_region(host->io_port, 0xff)) { printk(KERN_WARNING "qla2x00: Failed to reserved i/o base region " "0x%04lx-0x%04lx already in use\n", host->io_port, host->io_port + 0xff); /* 6/15/01 - free_irq(host->irq, NULL); */ return 1; } request_region(host->io_port, 0xff, DRIVER_NAME); /* Register the IRQ with Linux (sharable) */ if (request_irq(host->irq, qla2x00_intr_handler, SA_INTERRUPT|SA_SHIRQ, DRIVER_NAME, ha)) { printk(KERN_WARNING "qla2x00 : Failed to reserve interrupt %d " "already in use\n", host->irq); release_region(host->io_port, 0xff); return 1; } /* Initialized the timer */ START_TIMER(qla2x00_timer, ha, WATCH_INTERVAL); return 0;}/*************************************************************************** qla2x00_release** Description:* Free the passed in Scsi_Host memory structures prior to unloading the* module.** Input:* ha - pointer to host adapter structure** Returns:* 0 - Always returns good status**************************************************************************/intqla2x00_release(struct Scsi_Host *host){ scsi_qla_host_t *ha = (scsi_qla_host_t *) host->hostdata;#if QL_TRACE_MEMORY int t;#endif ENTER("qla2x00_release"); /* turn-off interrupts on the card */ if (ha->interrupts_on) qla2x00_disable_intrs(ha); /* Detach interrupts */ if (host->irq) free_irq(host->irq, ha); /* release io space registers */ if (host->io_port) release_region(host->io_port, 0xff); /* Disable timer */ if (ha->timer_active) STOP_TIMER(qla2x00_timer,ha) /* Kill the kernel thread for this host */ if (ha->dpc_handler != NULL ) {#if defined(ISP2100) ha->dpc_notify = &qla2100_detect_sem;#endif#if defined(ISP2200) ha->dpc_notify = &qla2200_detect_sem;#endif#if defined(ISP2300) ha->dpc_notify = &qla2300_detect_sem;#endif send_sig(SIGHUP, ha->dpc_handler, 1);#if defined(ISP2100) down(&qla2100_detect_sem);#endif#if defined(ISP2200) down(&qla2200_detect_sem);#endif#if defined(ISP2300) down(&qla2300_detect_sem);#endif ha->dpc_notify = NULL; }#if USE_FLASH_DATABASE /* Move driver database to flash, if enabled. */ if (ha->flags.enable_flash_db_update && ha->flags.updated_fc_db) { ha->flags.updated_fc_db = FALSE; qla2x00_save_database(ha); }#endif#if MEMORY_MAPPED_IO if (ha->mmpbase) { iounmap((void *) (((unsigned long) ha->mmpbase) & PAGE_MASK)); }#endif#if APIDEV apidev_cleanup();#endif qla2x00_mem_free(ha);#if MPIO_SUPPORT if (qla2x00_failover) qla2x00_cfg_mem_free(ha);#endif if (qla2x00_buffer != NULL) { kfree(qla2x00_buffer); qla2x00_buffer_size = 0; }#if QL_TRACE_MEMORY for (t = 0; t < 1000; t++) { if (mem_trace[t] == 0L) continue; printk("mem_trace[%d]=%lx, %lx\n", t, mem_trace[t],mem_id[t]); }#endif ha->flags.online = FALSE; LEAVE("qla2x00_release"); return 0;}/*************************************************************************** qla2x00_info** Description:** Input:* host - pointer to Scsi host adapter structure** Returns:* Return a text string describing the driver.**************************************************************************/const char *qla2x00_info(struct Scsi_Host *host){ static char qla2x00_buffer[255]; char *bp; scsi_qla_host_t *ha; qla_boards_t *bdp;#if APIDEV /* We must create the api node here instead of qla2x00_detect since we * want the api node to be subdirectory of /proc/scsi/qla2x00 which * will not have been created when qla2x00_detect exits, but which will * have been created by this point. */ apidev_init(host);#endif bp = &qla2x00_buffer[0]; ha = (scsi_qla_host_t *)host->hostdata; bdp = &QLBoardTbl_fc[ha->devnum]; memset(bp, 0, sizeof(qla2x00_buffer)); sprintf(bp, "QLogic %sPCI to Fibre Channel Host Adapter: " "bus %d device %d irq %d\n" " Firmware version: %2d.%02d.%02d, Driver version %s", (char *)&bdp->bdName[0], ha->pdev->bus->number, PCI_SLOT(ha->pdev->devfn), host->irq, bdp->fwver[0], bdp->fwver[1], bdp->fwver[2], QLA2100_VERSION); return bp;}/* * This routine will alloacte SP from the free queue * input: * scsi_qla_host_t * * output: * srb_t * or NULL */STATIC srb_t *qla2x00_get_new_sp (scsi_qla_host_t *ha){ srb_t * sp = NULL; ulong flags; spin_lock_irqsave(&ha->list_lock, flags); if (!list_empty(&ha->free_queue)) { sp = list_entry(ha->free_queue.next, srb_t, list); __del_from_free_queue (ha, sp); } spin_unlock_irqrestore(&ha->list_lock, flags); if (sp) { DEBUG4( if ((int)atomic_read(&sp->ref_count) != 0) { /* error */ printk("qla2x00_get_new_sp: WARNING " "ref_count not zero.\n"); }) sp_get(ha,sp); } return (sp);}/*************************************************************************** qla2x00_check_tgt_status** Description:* Checks to see if the target or loop is down.** Input:* cmd - pointer to Scsi cmd structure** Returns:* 1 - if target is present* 0 - if target is not present*************************************************************************
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?