📄 qla_mbx.c
字号:
/* * QLOGIC LINUX SOFTWARE * * QLogic ISP2x00 device driver for Linux 2.6.x * Copyright (C) 2003-2004 QLogic Corporation * (www.qlogic.com) * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * */#include "qla_def.h"#include <linux/delay.h>static voidqla2x00_mbx_sem_timeout(unsigned long data){ struct semaphore *sem_ptr = (struct semaphore *)data; DEBUG11(printk("qla2x00_sem_timeout: entered.\n");) if (sem_ptr != NULL) { up(sem_ptr); } DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");)}/* * qla2x00_mailbox_command * Issue mailbox command and waits for completion. * * Input: * ha = adapter block pointer. * mcp = driver internal mbx struct pointer. * * Output: * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data. * * Returns: * 0 : QLA_SUCCESS = cmd performed success * 1 : QLA_FUNCTION_FAILED (error encountered) * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered) * * Context: * Kernel context. */static intqla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp){ int rval; unsigned long flags = 0; device_reg_t __iomem *reg = ha->iobase; struct timer_list tmp_intr_timer; uint8_t abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); uint8_t io_lock_on = ha->flags.init_done; uint16_t command; uint16_t *iptr; uint16_t __iomem *optr; uint32_t cnt; uint32_t mboxes; unsigned long mbx_flags = 0; unsigned long wait_time; rval = QLA_SUCCESS; DEBUG11(printk("qla2x00_mailbox_command(%ld): entered.\n", ha->host_no);) /* * Wait for active mailbox commands to finish by waiting at most * tov seconds. This is to serialize actual issuing of mailbox cmds * during non ISP abort time. */ if (!abort_active) { if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) { /* Timeout occurred. Return error. */ DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): cmd " "access timeout. Exiting.\n", ha->host_no);) return QLA_FUNCTION_TIMEOUT; } } ha->flags.mbox_busy = 1; /* Save mailbox command for debug */ ha->mcp = mcp; /* Try to get mailbox register access */ if (!abort_active) spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags); DEBUG11(printk("scsi%d: prepare to issue mbox cmd=0x%x.\n", (int)ha->host_no, mcp->mb[0]);) spin_lock_irqsave(&ha->hardware_lock, flags); /* Load mailbox registers. */ optr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 0); iptr = mcp->mb; command = mcp->mb[0]; mboxes = mcp->out_mb; for (cnt = 0; cnt < ha->mbx_count; cnt++) { if (IS_QLA2200(ha) && cnt == 8) optr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8); if (mboxes & BIT_0) WRT_REG_WORD(optr, *iptr); mboxes >>= 1; optr++; iptr++; }#if defined(QL_DEBUG_LEVEL_1) printk("qla2x00_mailbox_command: Loaded MBX registers " "(displayed in bytes) = \n"); qla2x00_dump_buffer((uint8_t *)mcp->mb, 16); printk("\n"); qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16); printk("\n"); qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8); printk("\n"); printk("qla2x00_mailbox_command: I/O address = %lx.\n", (u_long)optr); qla2x00_dump_regs(ha);#endif /* Issue set host interrupt command to send cmd out. */ ha->flags.mbox_int = 0; clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); /* Unlock mbx registers and wait for interrupt */ DEBUG11(printk("qla2x00_mailbox_command: going to unlock irq & " "waiting for interrupt. jiffies=%lx.\n", jiffies);) /* Wait for mbx cmd completion until timeout */ if (!abort_active && io_lock_on) { /* sleep on completion semaphore */ DEBUG11(printk("qla2x00_mailbox_command(%ld): " "INTERRUPT MODE. Initializing timer.\n", ha->host_no);) init_timer(&tmp_intr_timer); tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem; tmp_intr_timer.expires = jiffies + mcp->tov * HZ; tmp_intr_timer.function = (void (*)(unsigned long))qla2x00_mbx_sem_timeout; DEBUG11(printk("qla2x00_mailbox_command(%ld): " "Adding timer.\n", ha->host_no);) add_timer(&tmp_intr_timer); DEBUG11(printk("qla2x00_mailbox_command: going to " "unlock & sleep. time=0x%lx.\n", jiffies);) set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); WRT_REG_WORD(®->hccr, HCCR_SET_HOST_INT); spin_unlock_irqrestore(&ha->hardware_lock, flags); if (!abort_active) spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags); /* Wait for either the timer to expire * or the mbox completion interrupt */ down(&ha->mbx_intr_sem); DEBUG11(printk("qla2x00_mailbox_command:" "waking up." "time=0x%lx\n", jiffies);) clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); /* delete the timer */ del_timer(&tmp_intr_timer); } else { DEBUG3_11(printk("qla2x00_mailbox_command(%ld): cmd=%x " "POLLING MODE.\n", ha->host_no, command);) WRT_REG_WORD(®->hccr, HCCR_SET_HOST_INT); spin_unlock_irqrestore(&ha->hardware_lock, flags); if (!abort_active) spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags); wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */ while (!ha->flags.mbox_int) { if (time_after(jiffies, wait_time)) break; /* Check for pending interrupts. */ qla2x00_poll(ha); udelay(10); /* v4.27 */ } /* while */ } if (!abort_active) spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags); /* Check whether we timed out */ if (ha->flags.mbox_int) { uint16_t *iptr2; DEBUG3_11(printk("qla2x00_mailbox_cmd: cmd %x completed.\n", command);) /* Got interrupt. Clear the flag. */ ha->flags.mbox_int = 0; clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE) { qla2x00_stats.mboxerr++; rval = QLA_FUNCTION_FAILED; } /* Load return mailbox registers. */ iptr2 = mcp->mb; iptr = (uint16_t *)&ha->mailbox_out[0]; mboxes = mcp->in_mb; for (cnt = 0; cnt < ha->mbx_count; cnt++) { if (mboxes & BIT_0) *iptr2 = *iptr; mboxes >>= 1; iptr2++; 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);#endif qla2x00_stats.mboxtout++; ha->total_mbx_timeout++; rval = QLA_FUNCTION_TIMEOUT; } if (!abort_active) spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags); ha->flags.mbox_busy = 0; /* 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. */ qla2x00_poll(ha); } if (rval == QLA_FUNCTION_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);) qla_printk(KERN_WARNING, ha, "Mailbox command timeout occured. Scheduling ISP " "abort.\n"); set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); if (ha->dpc_wait && !ha->dpc_active) 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);) qla_printk(KERN_WARNING, ha, "Mailbox command timeout occured. Issuing ISP " "abort.\n"); set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); if (qla2x00_abort_isp(ha)) { /* 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) up(&ha->mbx_cmd_sem); if (rval) { 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 rval;}/* * qla2x00_load_ram * Load adapter RAM using DMA. * * Input: * ha = adapter block pointer. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */intqla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr, uint16_t risc_code_size){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; uint32_t req_len; dma_addr_t nml_dma; uint32_t nml_len; uint32_t normalized; DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n", ha->host_no);) req_len = risc_code_size; nml_dma = 0; nml_len = 0; normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma, &nml_len); /* Load first segment */ mcp->mb[0] = MBC_LOAD_RISC_RAM; mcp->mb[1] = risc_addr; mcp->mb[2] = MSW(req_dma); mcp->mb[3] = LSW(req_dma); mcp->mb[4] = (uint16_t)req_len; mcp->mb[6] = MSW(MSD(req_dma)); mcp->mb[7] = LSW(MSD(req_dma)); mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; mcp->in_mb = MBX_0; mcp->tov = 30; mcp->flags = 0; rval = qla2x00_mailbox_command(ha, mcp); /* Load second segment - if necessary */ if (normalized && (rval == QLA_SUCCESS)) { mcp->mb[0] = MBC_LOAD_RISC_RAM; mcp->mb[1] = risc_addr + (uint16_t)req_len; mcp->mb[2] = MSW(nml_dma); mcp->mb[3] = LSW(nml_dma); mcp->mb[4] = (uint16_t)nml_len; mcp->mb[6] = MSW(MSD(nml_dma)); mcp->mb[7] = LSW(MSD(nml_dma)); mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; mcp->in_mb = MBX_0; mcp->tov = 30; mcp->flags = 0; rval = qla2x00_mailbox_command(ha, mcp); } if (rval == QLA_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_load_ram_ext * Load adapter extended RAM using DMA. * * Input: * ha = adapter block pointer. * * Returns: * qla2x00 local function return status code. * * Context: * Kernel context. */intqla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr, uint16_t risc_code_size){ int rval; mbx_cmd_t mc; mbx_cmd_t *mcp = &mc; uint32_t req_len; dma_addr_t nml_dma; uint32_t nml_len; uint32_t normalized; DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); req_len = risc_code_size; nml_dma = 0; nml_len = 0; normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma, &nml_len); /* Load first segment */ mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED; mcp->mb[1] = LSW(risc_addr); mcp->mb[2] = MSW(req_dma); mcp->mb[3] = LSW(req_dma); mcp->mb[4] = (uint16_t)req_len; mcp->mb[6] = MSW(MSD(req_dma)); mcp->mb[7] = LSW(MSD(req_dma)); mcp->mb[8] = MSW(risc_addr); mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; mcp->in_mb = MBX_0; mcp->tov = 30; mcp->flags = 0; rval = qla2x00_mailbox_command(ha, mcp); /* Load second segment - if necessary */ if (normalized && (rval == QLA_SUCCESS)) { risc_addr += req_len; mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED; mcp->mb[1] = LSW(risc_addr); mcp->mb[2] = MSW(nml_dma); mcp->mb[3] = LSW(nml_dma); mcp->mb[4] = (uint16_t)nml_len; mcp->mb[6] = MSW(MSD(nml_dma)); mcp->mb[7] = LSW(MSD(nml_dma)); mcp->mb[8] = MSW(risc_addr); mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; mcp->in_mb = MBX_0; mcp->tov = 30; mcp->flags = 0; rval = qla2x00_mailbox_command(ha, mcp); } if (rval != QLA_SUCCESS) { /*EMPTY*/ DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__, ha->host_no, rval, mcp->mb[0])); } else { /*EMPTY*/ DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); } return rval;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -