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

📄 mptscsih.c

📁 该文件是rt_linux
💻 C
📖 第 1 页 / 共 5 页
字号:
				hd->abortSCpnt = NULL;				hd->tmPtr = NULL;				hd->numTMrequests = 0;				/* Clear the pointer used to store				 * single-threaded commands, i.e., those				 * issued during a bus scan, dv and				 * configuration pages.				 */				hd->cmdPtr = NULL;				/* Attach the SCSI Host to the IOC structure				 */				this->sh = sh;				/* Initialize this SCSI Hosts' timers				 * To use, set the timer expires field				 * and add_timer				 */				init_timer(&hd->timer);				hd->timer.data = (unsigned long) hd;				hd->timer.function = mptscsih_timer_expired;				init_timer(&hd->TMtimer);				hd->TMtimer.data = (unsigned long) hd;				hd->TMtimer.function = mptscsih_taskmgmt_timeout;				hd->qtag_tick = jiffies;				/* Moved Earlier Pam D */				/* this->sh = sh;	*/				if (hd->is_spi) {					/* Update with the driver setup					 * values.					 */					if (hd->ioc->spi_data.maxBusWidth > driver_setup.max_width)						hd->ioc->spi_data.maxBusWidth = driver_setup.max_width;					if (hd->ioc->spi_data.minSyncFactor < driver_setup.min_sync_fac)						hd->ioc->spi_data.minSyncFactor = driver_setup.min_sync_fac;					if (hd->ioc->spi_data.minSyncFactor == MPT_ASYNC)						hd->ioc->spi_data.maxSyncOffset = 0;					hd->negoNvram = 0;#ifdef MPTSCSIH_DISABLE_DOMAIN_VALIDATION					hd->negoNvram = MPT_SCSICFG_USE_NVRAM;#endif					if (driver_setup.dv == 0)						hd->negoNvram = MPT_SCSICFG_USE_NVRAM;					hd->ioc->spi_data.forceDv = 0;					for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++)						hd->ioc->spi_data.dvStatus[ii] = MPT_SCSICFG_NEGOTIATE;						if (hd->negoNvram == 0) {						for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++)							hd->ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_DV_NOT_DONE;					}					ddvprintk((MYIOC_s_INFO_FMT						"dv %x width %x factor %x \n",						hd->ioc->name, driver_setup.dv,						driver_setup.max_width,						driver_setup.min_sync_fac));				}				mpt_scsi_hosts++;			}		}	/* for each adapter port */		this = mpt_adapter_find_next(this);	}done:	if (mpt_scsi_hosts > 0)		register_reboot_notifier(&mptscsih_notifier);	return mpt_scsi_hosts;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/    static char *info_kbuf = NULL;/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//** *	mptscsih_release - Unregister SCSI host from linux scsi mid-layer *	@host: Pointer to Scsi_Host structure * *	(linux Scsi_Host_Template.release routine) *	This routine releases all resources associated with the SCSI host *	adapter. * *	Returns 0 for success. */intmptscsih_release(struct Scsi_Host *host){	MPT_SCSI_HOST	*hd;	int 		 count;	unsigned long	 flags;	hd = (MPT_SCSI_HOST *) host->hostdata;#ifndef MPT_SCSI_USE_NEW_EH#ifndef MPTSCSIH_DISABLE_DOMAIN_VALIDATION	spin_lock_irqsave(&dvtaskQ_lock, flags);	dvtaskQ_release = 1;	spin_unlock_irqrestore(&dvtaskQ_lock, flags);#endif	count = 10 * HZ;	spin_lock_irqsave(&mytaskQ_lock, flags);	if (mytaskQ_bh_active) {		spin_unlock_irqrestore(&mytaskQ_lock, flags);		dprintk((KERN_INFO MYNAM ": Info: Zapping TaskMgmt thread!\n"));		clean_taskQ(hd);		while(mytaskQ_bh_active && --count) {			set_current_state(TASK_INTERRUPTIBLE);			schedule_timeout(1);		}	} else {		spin_unlock_irqrestore(&mytaskQ_lock, flags);	}	if (!count)		printk(KERN_ERR MYNAM ": ERROR - TaskMgmt thread still active!\n");#endif#ifndef MPTSCSIH_DISABLE_DOMAIN_VALIDATION	/* Check DV thread active */	count = 10 * HZ;	spin_lock_irqsave(&dvtaskQ_lock, flags);	if (dvtaskQ_active) {		spin_unlock_irqrestore(&dvtaskQ_lock, flags);		while(dvtaskQ_active && --count) {			set_current_state(TASK_INTERRUPTIBLE);			schedule_timeout(1);		}	} else {		spin_unlock_irqrestore(&dvtaskQ_lock, flags);	}	if (!count)		printk(KERN_ERR MYNAM ": ERROR - DV thread still active!\n");#if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY)	else		printk(KERN_ERR MYNAM ": DV thread orig %d, count %d\n", 10 * HZ, count);#endif#endif	unregister_reboot_notifier(&mptscsih_notifier);	if (hd != NULL) {		int sz1, sz2, sz3, sztarget=0;		int szr2chain = 0;		int szc2chain = 0;		int szchain = 0;		int szQ = 0;		int scale;		/* Synchronize disk caches		 */		(void) mptscsih_synchronize_cache(hd, 0);		sz1 = sz2 = sz3 = 0;		if (hd->ioc->req_sz <= 64)			scale = MPT_SG_REQ_64_SCALE;		else if (hd->ioc->req_sz <= 96)			scale = MPT_SG_REQ_96_SCALE;		else			scale = MPT_SG_REQ_128_SCALE;		if (hd->ScsiLookup != NULL) {			sz1 = hd->ioc->req_depth * sizeof(void *);			kfree(hd->ScsiLookup);			hd->ScsiLookup = NULL;		}		if (hd->ReqToChain != NULL) {			szr2chain = scale * hd->ioc->req_depth * sizeof(int);			kfree(hd->ReqToChain);			hd->ReqToChain = NULL;		}		if (hd->ChainToChain != NULL) {			szc2chain = scale * hd->ioc->req_depth * sizeof(int);			kfree(hd->ChainToChain);			hd->ChainToChain = NULL;		}		if (hd->ChainBuffer != NULL) {			sz2 = scale * hd->ioc->req_depth * hd->ioc->req_sz;			szchain = szr2chain + szc2chain + sz2;			pci_free_consistent(hd->ioc->pcidev, sz2,				    hd->ChainBuffer, hd->ChainBufferDMA);			hd->ChainBuffer = NULL;		}		if (hd->memQ != NULL) {			szQ = host->can_queue * sizeof(MPT_DONE_Q);			kfree(hd->memQ);			hd->memQ = NULL;		}		if (hd->Targets != NULL) {			int max, ii;			/*			 * Free any target structures that were allocated.			 */			if (hd->is_spi) {				max = MPT_MAX_SCSI_DEVICES;			} else {				max = MPT_MAX_FC_DEVICES;			}			for (ii=0; ii < max; ii++) {				if (hd->Targets[ii]) {					kfree(hd->Targets[ii]);					hd->Targets[ii] = NULL;					sztarget += sizeof(VirtDevice);				}			}			/*			 * Free pointer array.			 */			sz3 = max * sizeof(void *);			kfree(hd->Targets);			hd->Targets = NULL;		}		dprintk((MYIOC_s_INFO_FMT "Free'd ScsiLookup (%d), chain (%d) and Target (%d+%d) memory\n",				hd->ioc->name, sz1, szchain, sz3, sztarget));		dprintk(("Free'd done and free Q (%d) memory\n", szQ));	}	/* NULL the Scsi_Host pointer	 */	hd->ioc->sh = NULL;	scsi_unregister(host);	if (mpt_scsi_hosts) {		if (--mpt_scsi_hosts == 0) {			mpt_reset_deregister(ScsiDoneCtx);			dprintk((KERN_INFO MYNAM ": Deregistered for IOC reset notifications\n"));			mpt_event_deregister(ScsiDoneCtx);			dprintk((KERN_INFO MYNAM ": Deregistered for IOC event notifications\n"));			mpt_deregister(ScsiScanDvCtx);			mpt_deregister(ScsiTaskCtx);			mpt_deregister(ScsiDoneCtx);			if (info_kbuf != NULL)				kfree(info_kbuf);		}	}	return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//** *	mptscsih_halt - Process the reboot notification *	@nb: Pointer to a struct notifier_block (ignored) *	@event: event (SYS_HALT, SYS_RESTART, SYS_POWER_OFF) *	@buf: Pointer to a data buffer (ignored) * *	This routine called if a system shutdown or reboot is to occur. * *	Return NOTIFY_DONE if this is something other than a reboot message. *		NOTIFY_OK if this is a reboot message. */static intmptscsih_halt(struct notifier_block *nb, ulong event, void *buf){	MPT_ADAPTER *ioc = NULL;	MPT_SCSI_HOST *hd = NULL;	/* Ignore all messages other than reboot message	 */	if ((event != SYS_RESTART) && (event != SYS_HALT)		&& (event != SYS_POWER_OFF))		return (NOTIFY_DONE);	for (ioc = mpt_adapter_find_first(); ioc != NULL; ioc =	mpt_adapter_find_next(ioc)) {		/* Flush the cache of this adapter		 */		if (ioc->sh) {			hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;			if (hd) {				mptscsih_synchronize_cache(hd, 0);			}		}	}	unregister_reboot_notifier(&mptscsih_notifier);	return NOTIFY_OK;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//** *	mptscsih_info - Return information about MPT adapter *	@SChost: Pointer to Scsi_Host structure * *	(linux Scsi_Host_Template.info routine) * *	Returns pointer to buffer where information was written. */const char *mptscsih_info(struct Scsi_Host *SChost){	MPT_SCSI_HOST *h;	int size = 0;	if (info_kbuf == NULL)		if ((info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)			return info_kbuf;	h = (MPT_SCSI_HOST *)SChost->hostdata;	info_kbuf[0] = '\0';	mpt_print_ioc_summary(h->ioc, info_kbuf, &size, 0, 0);	info_kbuf[size-1] = '\0';	return info_kbuf;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/	static int max_qd = 1;#if 0static int index_log[128];static int index_ent = 0;static __inline__ void ADD_INDEX_LOG(int req_ent){	int i = index_ent++;	index_log[i & (128 - 1)] = req_ent;}#else#define ADD_INDEX_LOG(req_ent)	do { } while(0)#endif#ifdef	DROP_TEST#define DROP_IOC	1	/* IOC to force failures */#define DROP_TARGET	3	/* Target ID to force failures */#define	DROP_THIS_CMD	10000	/* iteration to drop command */static int dropCounter = 0;static int dropTestOK = 0;	/* num did good */static int dropTestBad = 0;	/* num did bad */static int dropTestNum = 0;	/* total = good + bad + incomplete */static int numTotCmds = 0;static MPT_FRAME_HDR *dropMfPtr = NULL;static int numTMrequested = 0;#endif/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* *	mptscsih_put_msgframe - Wrapper routine to post message frame to F/W. *	@context: Call back context (ScsiDoneCtx, ScsiScanDvCtx)  *	@id: IOC id number  *	@mf: Pointer to message frame  * *	Handles the call to mptbase for posting request and queue depth  *	tracking. * *	Returns none. */static voidmptscsih_put_msgframe(int context, int id, MPT_FRAME_HDR *mf){	/* Main banana... */	atomic_inc(&queue_depth);	if (atomic_read(&queue_depth) > max_qd) {		max_qd = atomic_read(&queue_depth);		dprintk((KERN_INFO MYNAM ": Queue depth now %d.\n", max_qd));	}	mpt_put_msg_frame(context, id, mf);	return;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//** *	mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine. *	@SCpnt: Pointer to Scsi_Cmnd structure *	@done: Pointer SCSI mid-layer IO completion function * *	(linux Scsi_Host_Template.queuecommand routine) *	This is the primary SCSI IO start routine.  Create a MPI SCSIIORequest *	from a linux Scsi_Cmnd request and send it to the IOC. * *	Returns 0. (rtn value discarded by linux scsi mid-layer) */intmptscsih_qcmd(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)){	MPT_SCSI_HOST		*hd;	MPT_FRAME_HDR		*mf;	SCSIIORequest_t		*pScsiReq;	VirtDevice		*pTarget;	MPT_DONE_Q		*buffer = NULL;	unsigned long		 flags;	int	 target;	int	 lun;	int	 datadir;	u32	 datalen;	u32	 scsictl;	u32	 scsidir;	u32	 qtag;	u32	 cmd_len;	int	 my_idx;	int	 ii;	int	 rc;	int	 did_errcode;	int	 issueCmd;	did_errcode = 0;	hd = (MPT_SCSI_HOST *) SCpnt->host->hostdata;	target = SCpnt->target;	lun = SCpnt->lun;	SCpnt->scsi_done = done;	pTarget = hd->Targets[target];	dmfprintk((MYIOC_s_INFO_FMT "qcmd: SCpnt=%p, done()=%p\n",			(hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt, done));	/* 20000617 -sralston	 *  GRRRRR...  Shouldn't have to do this but...	 *  Do explicit check for REQUEST_SENSE and cached SenseData.	 *  If yes, return cached SenseData.	 */	if (SCpnt->cmnd[0] == REQUEST_SENSE) {		u8 *dest = NULL;		int sz;		if (pTarget && (pTarget->tflags & MPT_TARGET_FLAGS_VALID_SENSE)) {			pTarget->tflags &= ~MPT_TARGET_FLAGS_VALID_SENSE;	//sjr-moved-here			if (!SCpnt->use_sg) {				dest = SCpnt->request_buffer;			} else {				struct scatterlist *sg = (struct scatterlist *) SCpnt->request_buffer;				if (sg)					dest = (u8 *)(ulong)sg_dma_address(sg);			}			if (dest) {				sz = MIN (SCSI_STD_SENSE_BYTES, SCpnt->request_bufflen);				memcpy(dest, pTarget->sense, sz);#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)				SCpnt->resid = SCpnt->request_bufflen - sz;#endif				SCpnt->result = 0;				SCpnt->scsi_done(SCpnt);				//sjr-moved-up//pTarget->tflags &= ~MPT_TARGET_FLAGS_VALID_SENSE;				return 0;			}

⌨️ 快捷键说明

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