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

📄 mptspi.c

📁 LINUX 2.6.17.4的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  linux/drivers/message/fusion/mptspi.c *      For use with LSI Logic PCI chip/adapter(s) *      running LSI Logic Fusion MPT (Message Passing Technology) firmware. * *  Copyright (c) 1999-2005 LSI Logic Corporation *  (mailto:mpt_linux_developer@lsil.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; version 2 of the License.    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.    NO WARRANTY    THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR    CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT    LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is    solely responsible for determining the appropriateness of using and    distributing the Program and assumes all risks associated with its    exercise of rights under this Agreement, including but not limited to    the risks and costs of program errors, damage to or loss of data,    programs or equipment, and unavailability or interruption of operations.    DISCLAIMER OF LIABILITY    NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL    DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE    USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED    HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/#include "linux_compat.h"	/* linux-2.6 tweaks */#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/errno.h>#include <linux/kdev_t.h>#include <linux/blkdev.h>#include <linux/delay.h>	/* for mdelay */#include <linux/interrupt.h>	/* needed for in_interrupt() proto */#include <linux/reboot.h>	/* notifier code */#include <linux/sched.h>#include <linux/workqueue.h>#include <linux/raid_class.h>#include <scsi/scsi.h>#include <scsi/scsi_cmnd.h>#include <scsi/scsi_device.h>#include <scsi/scsi_host.h>#include <scsi/scsi_tcq.h>#include <scsi/scsi_transport.h>#include <scsi/scsi_transport_spi.h>#include "mptbase.h"#include "mptscsih.h"/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/#define my_NAME		"Fusion MPT SPI Host driver"#define my_VERSION	MPT_LINUX_VERSION_COMMON#define MYNAM		"mptspi"MODULE_AUTHOR(MODULEAUTHOR);MODULE_DESCRIPTION(my_NAME);MODULE_LICENSE("GPL");/* Command line args */static int mpt_saf_te = MPTSCSIH_SAF_TE;module_param(mpt_saf_te, int, 0);MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1  (default=MPTSCSIH_SAF_TE=0)");static int mpt_pq_filter = 0;module_param(mpt_pq_filter, int, 0);MODULE_PARM_DESC(mpt_pq_filter, " Enable peripheral qualifier filter: enable=1  (default=0)");static void mptspi_write_offset(struct scsi_target *, int);static void mptspi_write_width(struct scsi_target *, int);static int mptspi_write_spi_device_pg1(struct scsi_target *,				       struct _CONFIG_PAGE_SCSI_DEVICE_1 *);static struct scsi_transport_template *mptspi_transport_template = NULL;static int	mptspiDoneCtx = -1;static int	mptspiTaskCtx = -1;static int	mptspiInternalCtx = -1; /* Used only for internal commands */static int mptspi_target_alloc(struct scsi_target *starget){	struct Scsi_Host *shost = dev_to_shost(&starget->dev);	struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;	int ret;	if (hd == NULL)		return -ENODEV;	ret = mptscsih_target_alloc(starget);	if (ret)		return ret;	/* if we're a device on virtual channel 1 and we're not part	 * of an array, just return here (otherwise the setup below	 * may actually affect a real physical device on channel 0 */	if (starget->channel == 1 &&	    mptscsih_raid_id_to_num(hd, starget->id) < 0)		return 0;	if (hd->ioc->spi_data.nvram &&	    hd->ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) {		u32 nvram = hd->ioc->spi_data.nvram[starget->id];		spi_min_period(starget) = (nvram & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;		spi_max_width(starget) = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;	} else {		spi_min_period(starget) = hd->ioc->spi_data.minSyncFactor;		spi_max_width(starget) = hd->ioc->spi_data.maxBusWidth;	}	spi_max_offset(starget) = hd->ioc->spi_data.maxSyncOffset;	spi_offset(starget) = 0;	mptspi_write_width(starget, 0);	return 0;}static int mptspi_read_spi_device_pg0(struct scsi_target *starget,			     struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0){	struct Scsi_Host *shost = dev_to_shost(&starget->dev);	struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;	struct _MPT_ADAPTER *ioc = hd->ioc;	struct _CONFIG_PAGE_SCSI_DEVICE_0 *pg0;	dma_addr_t pg0_dma;	int size;	struct _x_config_parms cfg;	struct _CONFIG_PAGE_HEADER hdr;	int err = -EBUSY;	/* No SPI parameters for RAID devices */	if (starget->channel == 0 &&	    (hd->ioc->raid_data.isRaid & (1 << starget->id)))		return -1;	size = ioc->spi_data.sdp0length * 4;	/*	if (ioc->spi_data.sdp0length & 1)		size += size + 4;	size += 2048;	*/	pg0 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg0_dma, GFP_KERNEL);	if (pg0 == NULL) {		starget_printk(KERN_ERR, starget, "dma_alloc_coherent for parameters failed\n");		return -EINVAL;	}	memset(&hdr, 0, sizeof(hdr));	hdr.PageVersion = ioc->spi_data.sdp0version;	hdr.PageLength = ioc->spi_data.sdp0length;	hdr.PageNumber = 0;	hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;	memset(&cfg, 0, sizeof(cfg));	cfg.cfghdr.hdr = &hdr;	cfg.physAddr = pg0_dma;	cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;	cfg.dir = 0;	cfg.pageAddr = starget->id;	if (mpt_config(ioc, &cfg)) {		starget_printk(KERN_ERR, starget, "mpt_config failed\n");		goto out_free;	}	err = 0;	memcpy(pass_pg0, pg0, size); out_free:	dma_free_coherent(&ioc->pcidev->dev, size, pg0, pg0_dma);	return err;}static u32 mptspi_getRP(struct scsi_target *starget){	u32 nego = 0;	nego |= spi_iu(starget) ? MPI_SCSIDEVPAGE1_RP_IU : 0;	nego |= spi_dt(starget) ? MPI_SCSIDEVPAGE1_RP_DT : 0;	nego |= spi_qas(starget) ? MPI_SCSIDEVPAGE1_RP_QAS : 0;	nego |= spi_hold_mcs(starget) ? MPI_SCSIDEVPAGE1_RP_HOLD_MCS : 0;	nego |= spi_wr_flow(starget) ? MPI_SCSIDEVPAGE1_RP_WR_FLOW : 0;	nego |= spi_rd_strm(starget) ? MPI_SCSIDEVPAGE1_RP_RD_STRM : 0;	nego |= spi_rti(starget) ? MPI_SCSIDEVPAGE1_RP_RTI : 0;	nego |= spi_pcomp_en(starget) ? MPI_SCSIDEVPAGE1_RP_PCOMP_EN : 0;	nego |= (spi_period(starget) <<  MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD) & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK;	nego |= (spi_offset(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MAX_SYNC_OFFSET) & MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK;	nego |= spi_width(starget) ?  MPI_SCSIDEVPAGE1_RP_WIDE : 0;	return nego;}static void mptspi_read_parameters(struct scsi_target *starget){	int nego;	struct _CONFIG_PAGE_SCSI_DEVICE_0 pg0;	mptspi_read_spi_device_pg0(starget, &pg0);	nego = le32_to_cpu(pg0.NegotiatedParameters);	spi_iu(starget) = (nego & MPI_SCSIDEVPAGE0_NP_IU) ? 1 : 0;	spi_dt(starget) = (nego & MPI_SCSIDEVPAGE0_NP_DT) ? 1 : 0;	spi_qas(starget) = (nego & MPI_SCSIDEVPAGE0_NP_QAS) ? 1 : 0;	spi_wr_flow(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WR_FLOW) ? 1 : 0;	spi_rd_strm(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RD_STRM) ? 1 : 0;	spi_rti(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RTI) ? 1 : 0;	spi_pcomp_en(starget) = (nego & MPI_SCSIDEVPAGE0_NP_PCOMP_EN) ? 1 : 0;	spi_hold_mcs(starget) = (nego & MPI_SCSIDEVPAGE0_NP_HOLD_MCS) ? 1 : 0;	spi_period(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_PERIOD;	spi_offset(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_OFFSET;	spi_width(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WIDE) ? 1 : 0;}static intmptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, int disk){	MpiRaidActionRequest_t	*pReq;	MPT_FRAME_HDR		*mf;	/* Get and Populate a free Frame	 */	if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {		ddvprintk((MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",					hd->ioc->name));		return -EAGAIN;	}	pReq = (MpiRaidActionRequest_t *)mf;	if (quiesce)		pReq->Action = MPI_RAID_ACTION_QUIESCE_PHYS_IO;	else		pReq->Action = MPI_RAID_ACTION_ENABLE_PHYS_IO;	pReq->Reserved1 = 0;	pReq->ChainOffset = 0;	pReq->Function = MPI_FUNCTION_RAID_ACTION;	pReq->VolumeID = disk;	pReq->VolumeBus = 0;	pReq->PhysDiskNum = 0;	pReq->MsgFlags = 0;	pReq->Reserved2 = 0;	pReq->ActionDataWord = 0; /* Reserved for this action */	mpt_add_sge((char *)&pReq->ActionDataSGE,		MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);	ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action %x id %d\n",			hd->ioc->name, action, io->id));	hd->pLocal = NULL;	hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */	hd->scandv_wait_done = 0;	/* Save cmd pointer, for resource free if timeout or	 * FW reload occurs	 */	hd->cmdPtr = mf;	add_timer(&hd->timer);	mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);	wait_event(hd->scandv_waitq, hd->scandv_wait_done);	if ((hd->pLocal == NULL) || (hd->pLocal->completion != 0))		return -1;	return 0;}static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,			     struct scsi_device *sdev){	VirtTarget *vtarget = scsi_target(sdev)->hostdata;	/* no DV on RAID devices */	if (sdev->channel == 0 &&	    (hd->ioc->raid_data.isRaid & (1 << sdev->id)))		return;	/* If this is a piece of a RAID, then quiesce first */	if (sdev->channel == 1 &&	    mptscsih_quiesce_raid(hd, 1, vtarget->target_id) < 0) {		starget_printk(KERN_ERR, scsi_target(sdev),			       "Integrated RAID quiesce failed\n");		return;	}	spi_dv_device(sdev);	if (sdev->channel == 1 &&	    mptscsih_quiesce_raid(hd, 0, vtarget->target_id) < 0)		starget_printk(KERN_ERR, scsi_target(sdev),			       "Integrated RAID resume failed\n");	mptspi_read_parameters(sdev->sdev_target);	spi_display_xfer_agreement(sdev->sdev_target);	mptspi_read_parameters(sdev->sdev_target);}static int mptspi_slave_alloc(struct scsi_device *sdev){	int ret;	MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sdev->host->hostdata;	/* gcc doesn't see that all uses of this variable occur within	 * the if() statements, so stop it from whining */	int physdisknum = 0;	if (sdev->channel == 1) {		physdisknum = mptscsih_raid_id_to_num(hd, sdev->id);		if (physdisknum < 0)			return physdisknum;	}	ret = mptscsih_slave_alloc(sdev);	if (ret)		return ret;	if (sdev->channel == 1) {		VirtDevice *vdev = sdev->hostdata;		sdev->no_uld_attach = 1;		vdev->vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;		/* The real channel for this device is zero */		vdev->vtarget->bus_id = 0;		/* The actual physdisknum (for RAID passthrough) */		vdev->vtarget->target_id = physdisknum;	}	return 0;}static int mptspi_slave_configure(struct scsi_device *sdev){	int ret = mptscsih_slave_configure(sdev);	struct _MPT_SCSI_HOST *hd =		(struct _MPT_SCSI_HOST *)sdev->host->hostdata;	if (ret)		return ret;	if ((sdev->channel == 1 ||	     !(hd->ioc->raid_data.isRaid & (1 << sdev->id))) &&	    !spi_initial_dv(sdev->sdev_target))		mptspi_dv_device(hd, sdev);	return 0;}static void mptspi_slave_destroy(struct scsi_device *sdev){	struct scsi_target *starget = scsi_target(sdev);	VirtTarget *vtarget = starget->hostdata;	VirtDevice *vdevice = sdev->hostdata;	/* Will this be the last lun on a non-raid device? */	if (vtarget->num_luns == 1 && vdevice->configured_lun) {		struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;		/* Async Narrow */		pg1.RequestedParameters = 0;		pg1.Reserved = 0;		pg1.Configuration = 0;		mptspi_write_spi_device_pg1(starget, &pg1);	}	mptscsih_slave_destroy(sdev);

⌨️ 快捷键说明

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