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

📄 aachba.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 3 页
字号:
		writecmd->sg.sg[0].addr = cpu_to_le32(addr);		writecmd->sg.sg[0].count = cpu_to_le32(scsicmd->request_bufflen);  		scsicmd->SCp.ptr = (void *)addr;		byte_count = scsicmd->request_bufflen;		if (byte_count > (64 * 1024))			BUG();	}	if (byte_count != writecmd->count)		BUG();	/*	 *	Now send the Fib to the adapter	 */	fibsize = sizeof (struct aac_write) + ((writecmd->sg.count - 1) * sizeof (struct sgentry));	status = fib_send(ContainerCommand, 			  cmd_fibcontext,			  fibsize, FsaNormal,			  0, 1,			  (fib_callback) write_callback,			  (void *) scsicmd);	/*	 *	Check that the command queued to the controller	 */	if (status == -EINPROGRESS)		return 0;	printk(KERN_WARNING "aac_write: fib_send failed with status: %d\n", status);	/*	 *	For some reason, the Fib didn't queue, return QUEUE_FULL	 */	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | QUEUE_FULL;	aac_io_done(scsicmd);	fib_complete(cmd_fibcontext);	fib_free(cmd_fibcontext);	return -1;}/** *	aac_scsi_cmd()		-	Process SCSI command *	@scsicmd:		SCSI command block *	@wait:			1 if the user wants to await completion * *	Emulate a SCSI command and queue the required request for the *	aacraid firmware. */ int aac_scsi_cmd(Scsi_Cmnd * scsicmd){	int cid = 0;	struct fsa_scsi_hba *fsa_dev_ptr;	int cardtype;	int ret;	struct aac_dev *dev = (struct aac_dev *)scsicmd->host->hostdata;		cardtype = dev->cardtype;	fsa_dev_ptr = fsa_dev[scsicmd->host->unique_id];	/*	 *	If the bus, target or lun is out of range, return fail	 *	Test does not apply to ID 16, the pseudo id for the controller	 *	itself.	 */	if (scsicmd->target != scsicmd->host->this_id) {		if ((scsicmd->channel > 0) ||(scsicmd->target > 15) || (scsicmd->lun > 7)) 		{			dprintk((KERN_DEBUG "The bus, target or lun is out of range = %d, %d, %d.\n", 				scsicmd->channel, scsicmd->target, scsicmd->lun));			scsicmd->result = DID_BAD_TARGET << 16;			__aac_io_done(scsicmd);			return -1;		}		cid = TARGET_LUN_TO_CONTAINER(scsicmd->target, scsicmd->lun);		/*		 *	If the target container doesn't exist, it may have		 *	been newly created		 */		if (fsa_dev_ptr->valid[cid] == 0) {			switch (scsicmd->cmnd[0]) {			case SS_INQUIR:			case SS_RDCAP:			case SS_TEST:				spin_unlock_irq(&io_request_lock);				probe_container(dev, cid);				spin_lock_irq(&io_request_lock);			default:				break;			}		}		/*		 *	If the target container still doesn't exist, 		 *	return failure		 */		if (fsa_dev_ptr->valid[cid] == 0) {			scsicmd->result = DID_BAD_TARGET << 16;			__aac_io_done(scsicmd);			return -1;		}	} 	else if ((scsicmd->cmnd[0] != SS_INQUIR) &&	/* only INQUIRY & TUR cmnd supported for controller */	    (scsicmd->cmnd[0] != SS_TEST)) 	{		/*		 *	Command aimed at the controller		 */		dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | CHECK_CONDITION;		set_sense((char *) &sense_data[cid],			    SENKEY_ILLEGAL,			    SENCODE_INVALID_COMMAND,			    ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);		__aac_io_done(scsicmd);		return -1;	}	/* Handle commands here that don't really require going out to the adapter */	switch (scsicmd->cmnd[0]) 	{		case SS_INQUIR:		{			struct inquiry_data *inq_data_ptr;			dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->target));			inq_data_ptr = (struct inquiry_data *)scsicmd->request_buffer;			memset(inq_data_ptr, 0, sizeof (struct inquiry_data));			inq_data_ptr->inqd_ver = 2;	/* claim compliance to SCSI-2 */			inq_data_ptr->inqd_dtq = 0x80;	/* set RMB bit to one indicating that the medium is removable */			inq_data_ptr->inqd_rdf = 2;	/* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */			inq_data_ptr->inqd_len = 31;			/*			 *	Set the Vendor, Product, and Revision Level			 *	see: <vendor>.c i.e. aac.c			 */			setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr->type[cid]);			if (scsicmd->target == scsicmd->host->this_id)			    	inq_data_ptr->inqd_pdt = INQD_PDT_PROC;	/* Processor device */			else				inq_data_ptr->inqd_pdt = INQD_PDT_DA;	/* Direct/random access device */			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | GOOD;			__aac_io_done(scsicmd);			return 0;		}		case SS_RDCAP:		{			int capacity;			char *cp;			dprintk((KERN_DEBUG "READ CAPACITY command.\n"));			capacity = fsa_dev_ptr->size[cid] - 1;			cp = scsicmd->request_buffer;			cp[0] = (capacity >> 24) & 0xff;			cp[1] = (capacity >> 16) & 0xff;			cp[2] = (capacity >> 8) & 0xff;			cp[3] = (capacity >> 0) & 0xff;			cp[4] = 0;			cp[5] = 0;			cp[6] = 2;			cp[7] = 0;			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | GOOD;			__aac_io_done(scsicmd);			return 0;		}		case SS_MODESEN:		{			char *mode_buf;			dprintk((KERN_DEBUG "MODE SENSE command.\n"));			mode_buf = scsicmd->request_buffer;			mode_buf[0] = 0;	/* Mode data length (MSB) */			mode_buf[1] = 6;	/* Mode data length (LSB) */			mode_buf[2] = 0;	/* Medium type - default */			mode_buf[3] = 0;	/* Device-specific param, bit 8: 0/1 = write enabled/protected */			mode_buf[4] = 0;	/* reserved */			mode_buf[5] = 0;	/* reserved */			mode_buf[6] = 0;	/* Block descriptor length (MSB) */			mode_buf[7] = 0;	/* Block descriptor length (LSB) */			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | GOOD;			__aac_io_done(scsicmd);			return 0;		}		case SS_REQSEN:			dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));			memcpy(scsicmd->sense_buffer, &sense_data[cid], sizeof (struct sense_data));			memset(&sense_data[cid], 0, sizeof (struct sense_data));			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | GOOD;			__aac_io_done(scsicmd);			return (0);		case SS_LOCK:			dprintk((KERN_DEBUG "LOCK command.\n"));			if (scsicmd->cmnd[4])				fsa_dev_ptr->locked[cid] = 1;			else				fsa_dev_ptr->locked[cid] = 0;			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | GOOD;			__aac_io_done(scsicmd);			return 0;		/*		 *	These commands are all No-Ops		 */		case SS_TEST:		case SS_RESERV:		case SS_RELES:		case SS_REZERO:		case SS_REASGN:		case SS_SEEK:		case SS_ST_SP:			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | GOOD;			__aac_io_done(scsicmd);			return (0);	}	switch (scsicmd->cmnd[0]) 	{		case SS_READ:		case SM_READ:			/*			 *	Hack to keep track of ordinal number of the device that			 *	corresponds to a container. Needed to convert			 *	containers to /dev/sd device names			 */			 			spin_unlock_irq(&io_request_lock);			fsa_dev_ptr->devno[cid] = DEVICE_NR(scsicmd->request.rq_dev);			ret = aac_read(scsicmd, cid);			spin_lock_irq(&io_request_lock);			return ret;		case SS_WRITE:		case SM_WRITE:			spin_unlock_irq(&io_request_lock);			ret = aac_write(scsicmd, cid);			spin_lock_irq(&io_request_lock);			return ret;		default:			/*			 *	Unhandled commands			 */			printk(KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]);			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | CHECK_CONDITION;			set_sense((char *) &sense_data[cid],				SENKEY_ILLEGAL, SENCODE_INVALID_COMMAND,			ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);			__aac_io_done(scsicmd);			return -1;	}}static int query_disk(struct aac_dev *dev, void *arg){	struct aac_query_disk qd;	struct fsa_scsi_hba *fsa_dev_ptr;	fsa_dev_ptr = &(dev->fsa_dev);	if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))		return -EFAULT;	if (qd.cnum == -1)		qd.cnum = TARGET_LUN_TO_CONTAINER(qd.target, qd.lun);	else if ((qd.bus == -1) && (qd.target == -1) && (qd.lun == -1)) 	{		if (qd.cnum < 0 || qd.cnum > MAXIMUM_NUM_CONTAINERS)			return -EINVAL;		qd.instance = dev->scsi_host_ptr->host_no;		qd.bus = 0;		qd.target = CONTAINER_TO_TARGET(qd.cnum);		qd.lun = CONTAINER_TO_LUN(qd.cnum);	}	else return -EINVAL;	qd.valid = fsa_dev_ptr->valid[qd.cnum];	qd.locked = fsa_dev_ptr->locked[qd.cnum];	qd.deleted = fsa_dev_ptr->deleted[qd.cnum];	if (fsa_dev_ptr->devno[qd.cnum] == -1)		qd.unmapped = 1;	else		qd.unmapped = 0;	get_sd_devname(fsa_dev_ptr->devno[qd.cnum], qd.name);	if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))		return -EFAULT;	return 0;}static void get_sd_devname(int disknum, char *buffer){	if (disknum < 0) {		sprintf(buffer, "%s", "");		return;	}	if (disknum < 26)		sprintf(buffer, "sd%c", 'a' + disknum);	else {		unsigned int min1;		unsigned int min2;		/*		 * For larger numbers of disks, we need to go to a new		 * naming scheme.		 */		min1 = disknum / 26;		min2 = disknum % 26;		sprintf(buffer, "sd%c%c", 'a' + min1 - 1, 'a' + min2);	}}static int force_delete_disk(struct aac_dev *dev, void *arg){	struct aac_delete_disk dd;	struct fsa_scsi_hba *fsa_dev_ptr;	fsa_dev_ptr = &(dev->fsa_dev);	if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))		return -EFAULT;	if (dd.cnum > MAXIMUM_NUM_CONTAINERS)		return -EINVAL;	/*	 *	Mark this container as being deleted.	 */	fsa_dev_ptr->deleted[dd.cnum] = 1;	/*	 *	Mark the container as no longer valid	 */	fsa_dev_ptr->valid[dd.cnum] = 0;	return 0;}static int delete_disk(struct aac_dev *dev, void *arg){	struct aac_delete_disk dd;	struct fsa_scsi_hba *fsa_dev_ptr;	fsa_dev_ptr = &(dev->fsa_dev);	if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))		return -EFAULT;	if (dd.cnum > MAXIMUM_NUM_CONTAINERS)		return -EINVAL;	/*	 *	If the container is locked, it can not be deleted by the API.	 */	if (fsa_dev_ptr->locked[dd.cnum])		return -EBUSY;	else {		/*		 *	Mark the container as no longer being valid.		 */		fsa_dev_ptr->valid[dd.cnum] = 0;		fsa_dev_ptr->devno[dd.cnum] = -1;		return 0;	}}int aac_dev_ioctl(struct aac_dev *dev, int cmd, void *arg){	switch (cmd) {	case FSACTL_QUERY_DISK:		return query_disk(dev, arg);	case FSACTL_DELETE_DISK:		return delete_disk(dev, arg);	case FSACTL_FORCE_DELETE_DISK:		return force_delete_disk(dev, arg);	case 2131:		return aac_get_containers(dev);	default:		return -ENOTTY;	}}

⌨️ 快捷键说明

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