qla_mbx.c
来自「这个linux源代码是很全面的~基本完整了~使用c编译的~由于时间问题我没有亲自」· C语言 代码 · 共 2,536 行 · 第 1/4 页
C
2,536 行
while (!ha->flags.mbox_int) { if (cnt <= jiffies) break; spin_lock_irqsave(&ha->hardware_lock, flags); /* Check for pending interrupts. */#if defined(ISP2300) if (ha->device_id == QLA2312_DEVICE_ID) { while ((data =RD_REG_WORD( ®->istatus)) & RISC_INT) { data =RD_REG_WORD(®->host_status_lo); qla2x00_isr(ha, data, &discard); } } else { while((data = RD_REG_WORD(®->host_status_lo)) & HOST_STATUS_INT) { qla2x00_isr(ha, data, &discard); } }#else /* QLA2100 or QLA2200 */ while((data = RD_REG_WORD(®->istatus)) & RISC_INT) { qla2x00_isr(ha, data, &discard); }#endif spin_unlock_irqrestore(&ha->hardware_lock, flags); udelay(10); /* v4.27 */ } /* while */ } if (!abort_active) QLA_MBX_REG_LOCK(ha); /* Check whether we timed out */ if (ha->flags.mbox_int) { DEBUG3_11(printk("qla2x00_mailbox_cmd: cmd %x completed.\n", command);) /* Got interrupt. Clear the flag. */ ha->flags.mbox_int = FALSE; clear_bit(MBX_INTERRUPT, (void *)&(ha->mbx_cmd_flags)); if( ha->mailbox_out[0] != MBS_CMD_CMP ) { qla2x00_stats.mboxerr++; status = QL_STATUS_ERROR; } /* Load return mailbox registers. */ optr = mcp->mb; iptr = (uint16_t *)&ha->mailbox_out[0]; mboxes = mcp->in_mb; for (cnt = 0; cnt < mbx_count; cnt++) { if (mboxes & BIT_0) *optr = *iptr; mboxes >>= 1; optr++; iptr++; } } else {#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \ defined(QL_DEBUG_LEVEL_11) printk("qla2x00_mailbox_command(%ld): **** MB Command Timeout " "for cmd %x ****\n", ha->host_no, command); printk("qla2x00_mailbox_command: icontrol=%x jiffies=%lx\n", RD_REG_WORD(®->ictrl), jiffies); printk("qla2x00_mailbox_command: *** mailbox[0] = 0x%x ***\n", RD_REG_WORD(optr)); qla2x00_dump_regs(ha->host);#endif qla2x00_stats.mboxtout++; status = QL_STATUS_TIMEOUT; } if (!abort_active) QLA_MBX_REG_UNLOCK(ha); ha->flags.mbox_busy = FALSE; /* Clean up */ ha->mcp = NULL; if (!abort_active) { DEBUG11(printk("qla2x00_mailbox_cmd: checking for additional " "resp interrupt.\n");) /* polling mode for non isp_abort commands. */ /* Go check for any more response interrupts pending. */ spin_lock_irqsave(&ha->hardware_lock, flags);#if defined(ISP2300) while (!(ha->flags.in_isr) && ((data = qla2x00_debounce_register(®->host_status_lo)) & HOST_STATUS_INT)) qla2x00_isr(ha, data, &discard);#else while (!(ha->flags.in_isr) && ((data = qla2x00_debounce_register(®->istatus)) & RISC_INT)) qla2x00_isr(ha, data,&discard);#endif spin_unlock_irqrestore(&ha->hardware_lock, flags); } if (status == QL_STATUS_TIMEOUT ) { if (!io_lock_on || (mcp->flags & IOCTL_CMD)) { /* not in dpc. schedule it for dpc to take over. */ DEBUG(printk("qla2x00_mailbox_command(%ld): timeout " "schedule isp_abort_needed.\n", ha->host_no);) DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): " "timeout schedule isp_abort_needed.\n", ha->host_no);) set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); up(ha->dpc_wait); } else if (!abort_active) { /* call abort directly since we are in the DPC thread */ DEBUG(printk("qla2x00_mailbox_command(%ld): timeout " "calling abort_isp\n", ha->host_no);) DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): " "timeout calling abort_isp\n", ha->host_no);) set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); if (qla2x00_abort_isp(ha, 0)) { /* failed. retry later. */ set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); } clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); DEBUG(printk("qla2x00_mailbox_command: finished " "abort_isp\n");) DEBUG2_3_11(printk("qla2x00_mailbox_command: finished " "abort_isp\n");) } } /* Allow next mbx cmd to come in. */ if (!abort_active) { tmp_stat = qla2x00_release_mbx_access(ha, mcp->tov); if (status == 0) status = tmp_stat; } if (status) { DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): **** FAILED. " "mbx0=%x, mbx1=%x, mbx2=%x, cmd=%x ****\n", ha->host_no, mcp->mb[0], mcp->mb[1], mcp->mb[2], command);) } else { DEBUG11(printk("qla2x00_mailbox_command(%ld): done.\n", ha->host_no);) } DEBUG11(printk("qla2x00_mailbox_command(%ld): exiting.\n", ha->host_no);) return status;}/* * qla2x00_load_ram * Load adapter RAM using DMA. * * Input: * ha = adapter block pointer. * dptr = DMA memory physical address. * TARGET_QUEUE_LOCK must be released. * ADAPTER_STATE_LOCK must be released. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_load_ram(scsi_qla_host_t *ha, uint32_t dptr, uint32_t addr, uint16_t size){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n", ha->host_no);)#if BITS_PER_LONG > 32#if defined(ISP2300) mcp->mb[0] = MBC_LOAD_RAM_EXTENDED; mcp->mb[6] = 0; mcp->mb[7] = 0; mcp->mb[8] = MSW(addr); mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;#else mcp->mb[0] = MBC_LOAD_RAM; mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;#endif#else mcp->mb[0] = MBC_LOAD_RAM; mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;#endif mcp->mb[1] = LSW(addr); mcp->mb[2] = MSW(dptr); mcp->mb[3] = LSW(dptr); mcp->mb[4] = size; mcp->in_mb = MBX_0; mcp->tov = 30; mcp->flags = 0; rval = (int)qla2x00_mailbox_command(ha, mcp); if (rval == QL_STATUS_SUCCESS) { /* Empty */ DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);) } else { /* Empty */ DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x " "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);) } return rval;}/* * qla2x00_execute_fw * Start adapter firmware. * * Input: * ha = adapter block pointer. * TARGET_QUEUE_LOCK must be released. * ADAPTER_STATE_LOCK must be released. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_execute_fw(scsi_qla_host_t *ha){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; DEBUG11(printk("qla2x00_execute_fw(%ld): entered.\n", ha->host_no);) mcp->mb[0] = MBC_EXECUTE_FIRMWARE; mcp->mb[1] = *QLBoardTbl_fc[ha->devnum].fwstart; mcp->out_mb = MBX_1|MBX_0; mcp->in_mb = MBX_0; mcp->tov = 30; mcp->flags = 0; rval = qla2x00_mailbox_command(ha, mcp); DEBUG11(printk("qla2x00_execute_fw(%ld): done.\n", ha->host_no);) return rval;}#if defined(WORD_FW_LOAD)/* * qla2x00_write_ram_word * * Input: * ha = adapter block pointer. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_write_ram_word(scsi_qla_host_t *ha, uint16_t addr, uint16_t data){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; DEBUG11(printk("qla2x00_write_ram_word(%ld): entered.\n", ha->host_no);) mcp->mb[0] = MBC_WRITE_RAM_WORD; mcp->mb[1] = addr; mcp->mb[2] = data; mcp->out_mb = MBX_2|MBX_1|MBX_0; mcp->in_mb = MBX_0; mcp->tov = 30; mcp->flags = 0; rval = (int)qla2x00_mailbox_command(ha, mcp); if (rval != QL_STATUS_SUCCESS) { /*EMPTY*/ DEBUG2_3_11(printk("qla2x00_write_ram_word(%ld): failed=%x.\n", ha->host_no, rval);) } else { /*EMPTY*/ DEBUG11(printk("qla2x00_write_ram_word(%ld): done.\n", ha->host_no);) } return rval;}/* * qla2x00_read_ram_word * * Input: * ha = adapter block pointer. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_read_ram_word(scsi_qla_host_t *ha, uint16_t addr, uint16_t *data){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; DEBUG11(printk("qla2x00_read_ram_word(%ld): entered.\n", ha->host_no);) mcp->mb[0] = MBC_READ_RAM_WORD; mcp->mb[1] = addr; mcp->out_mb = MBX_1|MBX_0; mcp->in_mb = MBX_0|MBX_2; mcp->tov = 30; mcp->flags = 0; rval = (int)qla2x00_mailbox_command(ha, mcp); if (rval != QL_STATUS_SUCCESS) { /*EMPTY*/ DEBUG2_3_11(printk("qla2x00_read_ram_word(%ld): failed=%x.\n", ha->host_no, rval);) } else { *data = mcp->mb[2]; DEBUG11(printk("qla2x00_read_ram_word(%ld): done.\n", ha->host_no);) } return rval;}#endif/* * qla2x00_mbx_reg_test * Mailbox register wrap test. * * Input: * ha = adapter block pointer. * TARGET_QUEUE_LOCK must be released. * ADAPTER_STATE_LOCK must be released. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_mbx_reg_test(scsi_qla_host_t *ha){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);) mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST; mcp->mb[1] = 0xAAAA; mcp->mb[2] = 0x5555; mcp->mb[3] = 0xAA55; mcp->mb[4] = 0x55AA; mcp->mb[5] = 0xA5A5; mcp->mb[6] = 0x5A5A; mcp->mb[7] = 0x2525; mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; mcp->tov = 30; mcp->flags = 0; rval = (int)qla2x00_mailbox_command(ha, mcp); if (rval == QL_STATUS_SUCCESS) { if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 || mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA) rval = QL_STATUS_ERROR; if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A || mcp->mb[7] != 0x2525) rval = QL_STATUS_ERROR; } if (rval != QL_STATUS_SUCCESS) { /*EMPTY*/ DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n", ha->host_no, rval);) } else { /*EMPTY*/ DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n", ha->host_no);) } return rval;}/* * qla2x00_verify_checksum * Verify firmware checksum. * * Input: * ha = adapter block pointer. * TARGET_QUEUE_LOCK must be released. * ADAPTER_STATE_LOCK must be released. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_verify_checksum(scsi_qla_host_t *ha){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; DEBUG11(printk("qla2x00_verify_checksum(%ld): entered.\n", ha->host_no);) mcp->mb[0] = MBC_VERIFY_CHECKSUM; mcp->mb[1] = *QLBoardTbl_fc[ha->devnum].fwstart; mcp->out_mb = MBX_1|MBX_0; mcp->in_mb = MBX_2|MBX_0; mcp->tov = 30; mcp->flags = 0; rval = (int)qla2x00_mailbox_command(ha, mcp); if (rval != QL_STATUS_SUCCESS) { /*EMPTY*/ DEBUG2_3_11(printk("qla2x00_verify_checksum(%ld): failed=%x.\n", ha->host_no, rval);) } else { /*EMPTY*/ DEBUG11(printk("qla2x00_verify_checksum(%ld): done.\n", ha->host_no);) } return rval;}/* * qla2x00_issue_iocb * Issue IOCB using mailbox command * * Input: * ha = adapter state pointer. * buffer = buffer pointer. * phys_addr = physical address of buffer. * size = size of buffer. * TARGET_QUEUE_LOCK must be released. * ADAPTER_STATE_LOCK must be released. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr, size_t size){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; ENTER("qla2x00_issue_iocb: started"); mcp->mb[0] = MBC_IOCB_EXECUTE; mcp->mb[1] = 0; mcp->mb[2] = MSW(phys_addr); mcp->mb[3] = LSW(phys_addr); mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; mcp->in_mb = MBX_2|MBX_0; mcp->tov = 30; mcp->flags = 0; rval = (int)qla2x00_mailbox_command(ha, mcp); if (rval != QLA2X00_SUCCESS) { /*EMPTY*/ DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x", ha->host_no,rval);) DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x", ha->host_no,rval);) } else { /*EMPTY*/ LEAVE("qla2x00_issue_iocb: exiting normally"); } return rval;}/* * qla2x00_abort_command * Abort command aborts a specified IOCB. * * Input: * ha = adapter block pointer. * sp = SB structure pointer. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp){ unsigned long flags = 0; scsi_qla_host_t *curr_ha; fc_port_t *fcport; int rval; uint32_t handle; uint16_t t; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; os_lun_t *lq = sp->lun_queue; DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);) curr_ha = lq->fclun->fcport->ha; t = SCSI_TCN_32(sp->cmd); fcport = lq->fclun->fcport; if (curr_ha->loop_state == LOOP_DOWN || atomic_read(&fcport->state) == FC_DEVICE_LOST) { /* v2.19.8 Ignore abort request if port is down */ return 1; } spin_lock_irqsave(&ha->hardware_lock, flags); for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) { if( ha->outstanding_cmds[handle] == sp ) break; } spin_unlock_irqrestore(&ha->hardware_lock, flags); if (handle == MAX_OUTSTANDING_COMMANDS) { /* command not found */ return QL_STATUS_ERROR; } mcp->mb[0] = MBC_ABORT_COMMAND; mcp->mb[1] = fcport->loop_id << 8; mcp->mb[2] = (uint16_t)handle; mcp->mb[3] = (uint16_t)(handle >> 16); mcp->mb[6] = (uint16_t)lq->fclun->lun; mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; mcp->in_mb = MBX_0; mcp->tov = 30; mcp->flags = 0; rval = (int)qla2x00_mailbox_command(ha, mcp); if (rval != QL_STATUS_SUCCESS) { set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); up(ha->dpc_wait); DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n", ha->host_no, rval);) } else { sp->flags |= SRB_ABORT_PENDING; DEBUG11(printk("qla2x00_abort_command(%ld): done.\n", ha->host_no);) } return rval;}/* * qla2x00_abort_device * * Input: * ha = adapter block pointer. * loop_id = FC loop ID * lun = SCSI LUN. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */STATIC intqla2x00_abort_device(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; DEBUG11(printk("qla2x00_abort_device(%ld): entered.\n",
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?