⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qla_mbx.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * QLogic Fibre Channel HBA Driver * Copyright (c)  2003-2005 QLogic Corporation * * See LICENSE.qla2xxx for copyright and licensing details. */#include "qla_def.h"#include <linux/delay.h>#include <scsi/scsi_transport_fc.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;	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;	abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);	DEBUG11(printk("%s(%ld): entered.\n", __func__, 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("%s(%ld): cmd access timeout. "			    "Exiting.\n", __func__, 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(%ld): prepare to issue mbox cmd=0x%x.\n",	    ha->host_no, mcp->mb[0]);)	spin_lock_irqsave(&ha->hardware_lock, flags);	/* Load mailbox registers. */	if (IS_QLA24XX(ha) || IS_QLA25XX(ha))		optr = (uint16_t __iomem *)&reg->isp24.mailbox0;	else		optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 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->isp, 8);		if (mboxes & BIT_0)			WRT_REG_WORD(optr, *iptr);		mboxes >>= 1;		optr++;		iptr++;	}#if defined(QL_DEBUG_LEVEL_1)	printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",	    __func__, ha->host_no);	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("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, 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("%s(%ld): going to unlock irq & waiting for interrupt. "	    "jiffies=%lx.\n", __func__, ha->host_no, jiffies);)	/* Wait for mbx cmd completion until timeout */	if (!abort_active && io_lock_on) {		/* sleep on completion semaphore */		DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",		    __func__, 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("%s(%ld): Adding timer.\n", __func__,		    ha->host_no);)		add_timer(&tmp_intr_timer);		DEBUG11(printk("%s(%ld): going to unlock & sleep. "		    "time=0x%lx.\n", __func__, ha->host_no, jiffies);)		set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);		if (IS_QLA24XX(ha) || IS_QLA25XX(ha))			WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);		else			WRT_REG_WORD(&reg->isp.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("%s(%ld): waking up. time=0x%lx\n", __func__,		    ha->host_no, jiffies);)		clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);		/* delete the timer */		del_timer(&tmp_intr_timer);	} else {		DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,		    ha->host_no, command);)		if (IS_QLA24XX(ha) || IS_QLA25XX(ha))			WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);		else			WRT_REG_WORD(&reg->isp.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("%s(%ld): cmd %x completed.\n", __func__,		    ha->host_no, 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)			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)		uint16_t mb0;		uint32_t ictrl;		if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {			mb0 = RD_REG_WORD(&reg->isp24.mailbox0);			ictrl = RD_REG_DWORD(&reg->isp24.ictrl);		} else {			mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);			ictrl = RD_REG_WORD(&reg->isp.ictrl);		}		printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",		    __func__, ha->host_no, command);		printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,		    ha->host_no, ictrl, jiffies);		printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,		    ha->host_no, mb0);		qla2x00_dump_regs(ha);#endif		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("%s(%ld): checking for additional resp "		    "interrupt.\n", __func__, ha->host_no);)		/* polling mode for non isp_abort commands. */		qla2x00_poll(ha);	}	if (rval == QLA_FUNCTION_TIMEOUT &&	    mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {		if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {			/* not in dpc. schedule it for dpc to take over. */			DEBUG(printk("%s(%ld): timeout schedule "			    "isp_abort_needed.\n", __func__, ha->host_no);)			DEBUG2_3_11(printk("%s(%ld): timeout schedule "			    "isp_abort_needed.\n", __func__, 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("%s(%ld): timeout calling abort_isp\n",			    __func__, ha->host_no);)			DEBUG2_3_11(printk("%s(%ld): timeout calling "			    "abort_isp\n", __func__, 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("%s(%ld): finished abort_isp\n", __func__,			    ha->host_no);)			DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",			    __func__, ha->host_no);)		}	}	/* Allow next mbx cmd to come in. */	if (!abort_active)		up(&ha->mbx_cmd_sem);	if (rval) {		DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "		    "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,		    mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)	} else {		DEBUG11(printk("%s(%ld): done.\n", __func__, 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, uint32_t risc_code_size){	int rval;	mbx_cmd_t mc;	mbx_cmd_t *mcp = &mc;	DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));	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[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_3|MBX_2|MBX_1|MBX_0;	if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {		mcp->mb[4] = MSW(risc_code_size);		mcp->mb[5] = LSW(risc_code_size);		mcp->out_mb |= MBX_5|MBX_4;	} else {		mcp->mb[4] = LSW(risc_code_size);		mcp->out_mb |= MBX_4;	}	mcp->in_mb = MBX_0;	mcp->tov = 30;	mcp->flags = 0;	rval = qla2x00_mailbox_command(ha, mcp);	if (rval != QLA_SUCCESS) {		DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,		    ha->host_no, rval, mcp->mb[0]));	} else {		DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));	}	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. */intqla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr){	int rval;	mbx_cmd_t mc;	mbx_cmd_t *mcp = &mc;	DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)	mcp->mb[0] = MBC_EXECUTE_FIRMWARE;	mcp->out_mb = MBX_0;	mcp->in_mb = MBX_0;	if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {		mcp->mb[1] = MSW(risc_addr);		mcp->mb[2] = LSW(risc_addr);		mcp->mb[3] = 0;		mcp->out_mb |= MBX_3|MBX_2|MBX_1;		mcp->in_mb |= MBX_1;	} else {		mcp->mb[1] = LSW(risc_addr);		mcp->out_mb |= MBX_1;		if (IS_QLA2322(ha) || IS_QLA6322(ha)) {			mcp->mb[2] = 0;			mcp->out_mb |= MBX_2;		}	}	mcp->tov = 30;	mcp->flags = 0;	rval = qla2x00_mailbox_command(ha, mcp);	if (rval != QLA_SUCCESS) {		DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,		    ha->host_no, rval, mcp->mb[0]));	} else {		if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {			DEBUG11(printk("%s(%ld): done exchanges=%x.\n",			    __func__, ha->host_no, mcp->mb[1]);)		} else {			DEBUG11(printk("%s(%ld): done.\n", __func__,			    ha->host_no);)		}	}	return rval;}/* * qla2x00_get_fw_version *	Get firmware version. * * Input: *	ha:		adapter state pointer. *	major:		pointer for major number. *	minor:		pointer for minor number. *	subminor:	pointer for subminor number. * * Returns: *	qla2x00 local function return status code. * * Context: *	Kernel context. */voidqla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,    uint16_t *subminor, uint16_t *attributes, uint32_t *memory){	int		rval;	mbx_cmd_t	mc;	mbx_cmd_t	*mcp = &mc;	DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));	mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;	mcp->out_mb = MBX_0;	mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;	mcp->flags = 0;	mcp->tov = 30;	rval = qla2x00_mailbox_command(ha, mcp);	/* Return mailbox data. */	*major = mcp->mb[1];	*minor = mcp->mb[2];	*subminor = mcp->mb[3];	*attributes = mcp->mb[6];	if (IS_QLA2100(ha) || IS_QLA2200(ha))		*memory = 0x1FFFF;			/* Defaults to 128KB. */	else		*memory = (mcp->mb[5] << 16) | mcp->mb[4];	if (rval != QLA_SUCCESS) {		/*EMPTY*/		DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,		    ha->host_no, rval));	} else {		/*EMPTY*/		DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));	}}/* * qla2x00_get_fw_options *	Set firmware options. * * Input: *	ha = adapter block pointer. *	fwopt = pointer for firmware options. * * Returns: *	qla2x00 local function return status code. * * Context: *	Kernel context. */intqla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts){	int rval;	mbx_cmd_t mc;	mbx_cmd_t *mcp = &mc;	DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));	mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;	mcp->out_mb = MBX_0;	mcp->in_mb = MBX_3|MBX_2|MBX_1|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.\n", __func__,		    ha->host_no, rval));	} else {		fwopts[0] = mcp->mb[0];		fwopts[1] = mcp->mb[1];		fwopts[2] = mcp->mb[2];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -