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

📄 i2o_core.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	if (status[0]==I2O_CMD_IN_PROGRESS)	{ 		/* 		 * Once the reset is sent, the IOP goes into the INIT state 		 * which is indeterminate.  We need to wait until the IOP 		 * has rebooted before we can let the system talk to 		 * it. We read the inbound Free_List until a message is 		 * available.  If we can't read one in the given ammount of 		 * time, we assume the IOP could not reboot properly.  		 */ 		dprintk(KERN_INFO "%s: Reset in progress, waiting for reboot...\n",			c->name); 		time = jiffies; 		m = I2O_POST_READ32(c); 		while(m == 0XFFFFFFFF) 		{ 			if((jiffies-time) >= 30*HZ)			{				printk(KERN_ERR "%s: Timeout waiting for IOP reset.\n", 						c->name); 				return -ETIMEDOUT; 			} 			schedule(); 			barrier(); 			m = I2O_POST_READ32(c); 		}		i2o_flush_reply(c,m);	}	/* If IopReset was rejected or didn't perform reset, try IopClear */	i2o_status_get(c);	if (status[0] == I2O_CMD_REJECTED || 		c->status_block->iop_state != ADAPTER_STATE_RESET)	{		printk(KERN_WARNING "%s: Reset rejected, trying to clear\n",c->name);		i2o_clear_controller(c);	}	else		dprintk(KERN_INFO "%s: Reset completed.\n", c->name);	/* Enable other IOPs */	for (iop = i2o_controller_chain; iop; iop = iop->next)		if (iop != c)			i2o_enable_controller(iop);	kfree(status);	return 0;}/** * 	i2o_status_get	-	get the status block for the IOP *	@c: controller * *	Issue a status query on the controller. This updates the *	attached status_block. If the controller fails to reply or an *	error occurs then a negative errno code is returned. On success *	zero is returned and the status_blok is updated. */ int i2o_status_get(struct i2o_controller *c){	long time;	u32 m;	u32 *msg;	u8 *status_block;	if (c->status_block == NULL) 	{		c->status_block = (i2o_status_block *)			kmalloc(sizeof(i2o_status_block),GFP_KERNEL);		if (c->status_block == NULL)		{			printk(KERN_CRIT "%s: Get Status Block failed; Out of memory.\n",				c->name);			return -ENOMEM;		}	}	status_block = (u8*)c->status_block;	memset(c->status_block,0,sizeof(i2o_status_block));		m=i2o_wait_message(c, "StatusGet");	if(m==0xFFFFFFFF)		return -ETIMEDOUT;		msg=(u32 *)(c->mem_offset+m);	msg[0]=NINE_WORD_MSG_SIZE|SGL_OFFSET_0;	msg[1]=I2O_CMD_STATUS_GET<<24|HOST_TID<<12|ADAPTER_TID;	msg[2]=core_context;	msg[3]=0;	msg[4]=0;	msg[5]=0;	msg[6]=virt_to_bus(c->status_block);	msg[7]=0;   /* 64bit host FIXME */	msg[8]=sizeof(i2o_status_block); /* always 88 bytes */	i2o_post_message(c,m);	/* Wait for a reply */	time=jiffies;	while(status_block[87]!=0xFF)	{		if((jiffies-time)>=5*HZ)		{			printk(KERN_ERR "%s: Get status timeout.\n",c->name);			return -ETIMEDOUT;		}		schedule();		barrier();	}#ifdef DRIVERDEBUG	printk(KERN_INFO "%s: State = ", c->name);	switch (c->status_block->iop_state) {		case 0x01:  			printk("INIT\n");			break;		case 0x02:			printk("RESET\n");			break;		case 0x04:			printk("HOLD\n");			break;		case 0x05:			printk("READY\n");			break;		case 0x08:			printk("OPERATIONAL\n");			break;		case 0x10:			printk("FAILED\n");			break;		case 0x11:			printk("FAULTED\n");			break;		default: 			printk("%x (unknown !!)\n",c->status_block->iop_state);}     #endif   	return 0;}/* * Get the Hardware Resource Table for the device. * The HRT contains information about possible hidden devices * but is mostly useless to us  */int i2o_hrt_get(struct i2o_controller *c){	u32 msg[6];	int ret, size = sizeof(i2o_hrt);	/* Read first just the header to figure out the real size */	do  {		if (c->hrt == NULL) {			c->hrt=kmalloc(size, GFP_KERNEL);			if (c->hrt == NULL) {				printk(KERN_CRIT "%s: Hrt Get failed; Out of memory.\n", c->name);				return -ENOMEM;			}		}		msg[0]= SIX_WORD_MSG_SIZE| SGL_OFFSET_4;		msg[1]= I2O_CMD_HRT_GET<<24 | HOST_TID<<12 | ADAPTER_TID;		msg[3]= 0;		msg[4]= (0xD0000000 | size);	/* Simple transaction */		msg[5]= virt_to_bus(c->hrt);	/* Dump it here */		if ((ret = i2o_post_wait(c, msg, sizeof(msg), 20))) {			printk(KERN_ERR "%s: Unable to get HRT (status=%#x)\n",				c->name, -ret);				return ret;		}		if (c->hrt->num_entries * c->hrt->entry_len << 2 > size) {			size = c->hrt->num_entries * c->hrt->entry_len << 2;			kfree(c->hrt);			c->hrt = NULL;		}	} while (c->hrt == NULL);	i2o_parse_hrt(c); // just for debugging	return 0;}/* * Send the I2O System Table to the specified IOP * * The system table contains information about all the IOPs in the * system.  It is build and then sent to each IOP so that IOPs can * establish connections between each other. * */static int i2o_systab_send(struct i2o_controller *iop){	u32 msg[12];	u32 privmem[2];	u32 privio[2];	int ret;	privmem[0] = iop->status_block->current_mem_base;	privmem[1] = iop->status_block->current_mem_size;	privio[0] = iop->status_block->current_io_base;	privio[1] = iop->status_block->current_io_size;	msg[0] = I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6;	msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;	msg[3] = 0;	msg[4] = (0<<16) | ((iop->unit+2) << 12); /* Host 0 IOP ID (unit + 2) */	msg[5] = 0;                               /* Segment 0 */	/*  	 * Provide three SGL-elements: 	 * System table (SysTab), Private memory space declaration and  	 * Private i/o space declaration   	 */	msg[6] = 0x54000000 | sys_tbl_len;	msg[7] = virt_to_bus(sys_tbl);	msg[8] = 0x54000000 | 0;	msg[9] = virt_to_bus(privmem);	msg[10] = 0xD4000000 | 0;	msg[11] = virt_to_bus(privio);	if ((ret=i2o_post_wait(iop, msg, sizeof(msg), 120)))		printk(KERN_INFO "%s: Unable to set SysTab (status=%#x).\n", 			iop->name, -ret);	else		dprintk(KERN_INFO "%s: SysTab set.\n", iop->name);	i2o_status_get(iop); // Entered READY state	return ret;	 }/* * Initialize I2O subsystem. */static void __init i2o_sys_init(void){	struct i2o_controller *iop, *niop = NULL;	printk(KERN_INFO "Activating I2O controllers...\n");	printk(KERN_INFO "This may take a few minutes if there are many devices\n");		/* In INIT state, Activate IOPs */	for (iop = i2o_controller_chain; iop; iop = niop) {		dprintk(KERN_INFO "Calling i2o_activate_controller for %s...\n", 			iop->name);		niop = iop->next;		if (i2o_activate_controller(iop) < 0)			i2o_delete_controller(iop);	}	/* Active IOPs in HOLD state */rebuild_sys_tab:	if (i2o_controller_chain == NULL)		return;	/*	 * If build_sys_table fails, we kill everything and bail	 * as we can't init the IOPs w/o a system table	 */		dprintk(KERN_INFO "i2o_core: Calling i2o_build_sys_table...\n");	if (i2o_build_sys_table() < 0) {		i2o_sys_shutdown();		return;	}	/* If IOP don't get online, we need to rebuild the System table */	for (iop = i2o_controller_chain; iop; iop = niop) {		niop = iop->next;		dprintk(KERN_INFO "Calling i2o_online_controller for %s...\n", iop->name);		if (i2o_online_controller(iop) < 0) {			i2o_delete_controller(iop);				goto rebuild_sys_tab;		}	}		/* Active IOPs now in OPERATIONAL state */	/*	 * Register for status updates from all IOPs	 */	for(iop = i2o_controller_chain; iop; iop=iop->next) {		/* Create a kernel thread to deal with dynamic LCT updates */		iop->lct_pid = kernel_thread(i2o_dyn_lct, iop, CLONE_SIGHAND);			/* Update change ind on DLCT */		iop->dlct->change_ind = iop->lct->change_ind;		/* Start dynamic LCT updates */		i2o_lct_notify(iop);		/* Register for all events from IRTOS */		i2o_event_register(iop, core_context, 0, 0, 0xFFFFFFFF);	}}/** *	i2o_sys_shutdown - shutdown I2O system * *	Bring down each i2o controller and then return. Each controller *	is taken through an orderly shutdown */ static void i2o_sys_shutdown(void){	struct i2o_controller *iop, *niop;	/* Delete all IOPs from the controller chain */	/* that will reset all IOPs too */	for (iop = i2o_controller_chain; iop; iop = niop) {		niop = iop->next;		i2o_delete_controller(iop);	}}/** *	i2o_activate_controller	-	bring controller up to HOLD *	@iop: controller * *	This function brings an I2O controller into HOLD state. The adapter *	is reset if neccessary and then the queues and resource table *	are read. -1 is returned on a failure, 0 on success. *	 */ int i2o_activate_controller(struct i2o_controller *iop){	/* In INIT state, Wait Inbound Q to initialize (in i2o_status_get) */	/* In READY state, Get status */	if (i2o_status_get(iop) < 0) {		printk(KERN_INFO "Unable to obtain status of %s, "			"attempting a reset.\n", iop->name);		if (i2o_reset_controller(iop) < 0)			return -1;	}	if(iop->status_block->iop_state == ADAPTER_STATE_FAULTED) {		printk(KERN_CRIT "%s: hardware fault\n", iop->name);		return -1;	}	if (iop->status_block->i2o_version > I2OVER15) {		printk(KERN_ERR "%s: Not running vrs. 1.5. of the I2O Specification.\n",			iop->name);		return -1;	}	if (iop->status_block->iop_state == ADAPTER_STATE_READY ||	    iop->status_block->iop_state == ADAPTER_STATE_OPERATIONAL ||	    iop->status_block->iop_state == ADAPTER_STATE_HOLD ||	    iop->status_block->iop_state == ADAPTER_STATE_FAILED)	{		dprintk(KERN_INFO "%s: Already running, trying to reset...\n",			iop->name);		if (i2o_reset_controller(iop) < 0)			return -1;	}	if (i2o_init_outbound_q(iop) < 0)		return -1;	if (i2o_post_outbound_messages(iop)) 		return -1;	/* In HOLD state */		if (i2o_hrt_get(iop) < 0)		return -1;	return 0;}/** *	i2o_init_outbound_queue	- setup the outbound queue *	@c: controller * *	Clear and (re)initialize IOP's outbound queue. Returns 0 on *	success or a negative errno code on a failure. */ int i2o_init_outbound_q(struct i2o_controller *c){	u8 *status;	u32 m;	u32 *msg;	u32 time;	dprintk(KERN_INFO "%s: Initializing Outbound Queue...\n", c->name);	m=i2o_wait_message(c, "OutboundInit");	if(m==0xFFFFFFFF)		return -ETIMEDOUT;	msg=(u32 *)(c->mem_offset+m);	status = kmalloc(4,GFP_KERNEL);	if (status==NULL) {		printk(KERN_ERR "%s: Outbound Queue initialization failed - no free memory.\n",			c->name);		return -ENOMEM;	}	memset(status, 0, 4);	msg[0]= EIGHT_WORD_MSG_SIZE| TRL_OFFSET_6;	msg[1]= I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID;	msg[2]= core_context;	msg[3]= 0x0106;				/* Transaction context */	msg[4]= 4096;				/* Host page frame size */	/* Frame size is in words. Pick 128, its what everyone elses uses and		other sizes break some adapters. */	msg[5]= MSG_FRAME_SIZE<<16|0x80;	/* Outbound msg frame size and Initcode */	msg[6]= 0xD0000004;			/* Simple SG LE, EOB */	msg[7]= virt_to_bus(status);	i2o_post_message(c,m);		barrier();	time=jiffies;	while(status[0] < I2O_CMD_REJECTED)	{		if((jiffies-time)>=30*HZ)		{			if(status[0]==0x00)				printk(KERN_ERR "%s: Ignored queue initialize request.\n",					c->name);			else  				printk(KERN_ERR "%s: Outbound queue initialize timeout.\n",					c->name);			kfree(status);			return -ETIMEDOUT;		}  		schedule();		barrier();	}  	if(status[0] != I2O_CMD_COMPLETED)	{		printk(KERN_ERR "%s: IOP outbound initialise failed.\n", c->name);		kfree(status);		return -ETIMEDOUT;	}	return 0;}/** *	i2o_post_outbound_messages	-	fill message queue *	@c: controller * *	Allocate a message frame and load the messages into the IOP. The *	function returns zero on success or a negative errno code on *	failure. */int i2o_post_outbound_messages(struct i2o_controller *c){	int i;	u32 m;	/* Alloc space for IOP's outbound queue message frames */	c->page_frame = kmalloc(MSG_POOL_SIZE, GFP_KERNEL);	if(c->page_frame==NULL) {		printk(KERN_CRIT "%s: Outbound Q initialize failed; out of memory.\n",			c->name);		return -ENOMEM;	}	m=virt_to_bus(c->page_frame);	/* Post frames */	for(i=0; i< NMBR_MSG_FRAMES; i++) {		I2O_REPLY_WRITE32(c,m);		mb();		m += MSG_FRAME_SIZE;	}	return 0;}/* * Get the IOP's Logical Configuration Table */int i2o_lct_get(struct i2o_controller *c){	u32 msg[8];	int ret, size = c->status_block->expected_lct_size;	do {		if (c->lct == NULL) {			c->lct = kmalloc(size, GFP_KERNEL);			if(c->lct == NULL) {				printk(KERN_CRIT "%s: Lct Get failed. Out of memory.\n",					c->name);				return -ENOMEM;			}		}		memset(c->lct, 0, size);		msg[0] = EIGHT_WORD_MSG_SIZE|SGL_OFFSET_6;		msg[1] = I2O_CMD_LCT_NOTIFY<<24 | HOST_TID<<12 | ADAPTER_TID;		/* msg[2] filled in i2o_post_wait */		msg[3] = 0;		msg[4] = 0xFFFFFFFF;	/* All devices */		msg[5] = 0x00000000;	/* Report now */		msg[6] = 0xD0000000|size;		msg[7] = virt_to_bus(c->lct);		if ((ret=i2o_post_wait(c, msg, sizeof(msg), 120))) {			printk(KERN_ERR "%s: LCT Get failed (status=%#x.\n", 				c->name, -ret);				return ret;		}		if (c->lct->table_size << 2 > size) {			size = c->lct->table_size << 2;			kfree(c->lct);			c->lct = NULL;		}	} while (c->lct == NULL);        if ((ret=i2o_parse_lct(c)) < 0)                return ret;	return 0;}/* * Like above, but used for async notification.  The main * difference is that we keep track of the CurrentChangeIndiicator * so that we only get updates when it actually changes. *

⌨️ 快捷键说明

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