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

📄 aachba.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
			  cmd_fibcontext, 			  fibsize, 			  FsaNormal, 			  0, 1, 			  (fib_callback) write_callback, 			  (void *) scsicmd);	}	else 	{		struct aac_write *writecmd;		writecmd = (struct aac_write *) fib_data(cmd_fibcontext);		writecmd->command = cpu_to_le32(VM_CtBlockWrite);		writecmd->cid = cpu_to_le32(cid);		writecmd->block = cpu_to_le32(lba);		writecmd->count = cpu_to_le32(count * 512);		writecmd->sg.count = cpu_to_le32(1);		/* ->stable is not used - it did mean which type of write */		if (count * 512 > (64 * 1024))			BUG();		aac_build_sg(scsicmd, &writecmd->sg);		if(writecmd->sg.count > MAX_DRIVER_SG_SEGMENT_COUNT)			BUG();		fibsize = sizeof(struct aac_write) + ((writecmd->sg.count - 1) * sizeof (struct sgentry));		/*		 *	Now send the Fib to the adapter		 */		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){	u32 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) ){			if( (scsicmd->target >= AAC_MAX_TARGET) || (scsicmd->lun != 0)){ 				scsicmd->result = DID_NO_CONNECT << 16;				__aac_io_done(scsicmd);				return 0;			}			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);					if (fsa_dev_ptr->valid[cid] == 0) {						scsicmd->result = DID_NO_CONNECT << 16;						__aac_io_done(scsicmd);						return 0;					}				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 {  /* check for physical non-dasd devices */			if(dev->nondasd_support == 1){				return aac_send_srb_fib(scsicmd);			} else {				scsicmd->result = DID_NO_CONNECT << 16;				__aac_io_done(scsicmd);				return 0;			}		}	}	/*	 * else Command for the controller itself	 */	else if ((scsicmd->cmnd[0] != SS_INQUIR) &&	/* only INQUIRY & TUR cmnd supported for controller */		(scsicmd->cmnd[0] != SS_TEST)) 	{		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((u8 *) &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_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;		/*Format for "pad2" is  RelAdr | WBus32 | WBus16 |  Sync  | Linked |Reserved| CmdQue | SftRe */		inq_data_ptr->inqd_pad2= 0x32 ;	 /*WBus16|Sync|CmdQue */		/*		 *	Set the Vendor, Product, and Revision Level		 *	see: <vendor>.c i.e. aac.c		 */		if (scsicmd->target == scsicmd->host->this_id) {			setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), (sizeof(container_types)/sizeof(char *)));			inq_data_ptr->inqd_pdt = INQD_PDT_PROC;	/* Processor device */		} else {			setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr->type[cid]);			aac_get_container_name(dev, cid, inq_data_ptr->inqd_pid);			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((u8 *) &sense_data[cid],				SENKEY_ILLEGAL, SENCODE_INVALID_COMMAND,			ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);			__aac_io_done(scsicmd);			return 0;	}}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;	}}/** * * aac_srb_callback * @context: the context set in the fib - here it is scsi cmd * @fibptr: pointer to the fib * * Handles the completion of a scsi command to a non dasd device * */static void aac_srb_callback(void *context, struct fib * fibptr){	struct aac_dev *dev;	struct aac_srb_reply *srbreply;	Scsi_Cmnd *scsicmd;	scsicmd = (Scsi_Cmnd *) context;	dev = (struct aac_dev *)scsicmd->host->hostdata;	if (fibptr == NULL)		BUG();	srbreply = (struct aac_srb_reply *) fib_data(fibptr);	scsicmd->sense_buffer[0] = '\0';  // initialize sense valid flag to false	// calculate resid for sg 	scsicmd->resid = scsicmd->request_bufflen - srbreply->data_xfer_length;	if(scsicmd->use_sg)		pci_unmap_sg(dev->pdev, 			(struct scatterlist *)scsicmd->buffer,			scsicmd->use_sg,			scsi_to_pci_dma_dir(scsicmd->sc_data_direction));	else if(scsicmd->request_bufflen)		pci_unmap_single(dev->pdev, (ulong)scsicmd->SCp.ptr, scsicmd->request_bufflen,			scsi_to_pci_dma_dir(scsicmd->sc_data_direction));

⌨️ 快捷键说明

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