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

📄 cycx_drv.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
static void cycx_start(void __iomem *addr){	/* put in 0x30 offset the jump instruction to the code entry point */	writeb(0xea, addr + 0x30);	writeb(0x00, addr + 0x31);	writeb(0xc4, addr + 0x32);	writeb(0x00, addr + 0x33);	writeb(0x00, addr + 0x34);	/* cmd to start executing code */	writew(GEN_START, addr + CMD_OFFSET);}/* Load and boot reset code. */static void cycx_reset_boot(void __iomem *addr, u8 *code, u32 len){	void __iomem *pt_start = addr + START_OFFSET;	writeb(0xea, pt_start++); /* jmp to f000:3f00 */	writeb(0x00, pt_start++);	writeb(0xfc, pt_start++);	writeb(0x00, pt_start++);	writeb(0xf0, pt_start);	reset_load(addr, code, len);	/* 80186 was in hold, go */	writeb(0, addr + START_CPU);	msleep_interruptible(1 * 1000);}/* Load data.bin file through boot (reset) interface. */static int cycx_data_boot(void __iomem *addr, u8 *code, u32 len){	void __iomem *pt_boot_cmd = addr + CMD_OFFSET;	u32 i;	/* boot buffer lenght */	writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));	writew(GEN_DEFPAR, pt_boot_cmd);	if (wait_cyc(addr) < 0)		return -1;	writew(0, pt_boot_cmd + sizeof(u16));	writew(0x4000, pt_boot_cmd + 2 * sizeof(u16));	writew(GEN_SET_SEG, pt_boot_cmd);	if (wait_cyc(addr) < 0)		return -1;	for (i = 0 ; i < len ; i += CFM_LOAD_BUFSZ)		if (buffer_load(addr, code + i,				min_t(u32, CFM_LOAD_BUFSZ, (len - i))) < 0) {			printk(KERN_ERR "%s: Error !!\n", modname);			return -1;		}	return 0;}/* Load code.bin file through boot (reset) interface. */static int cycx_code_boot(void __iomem *addr, u8 *code, u32 len){	void __iomem *pt_boot_cmd = addr + CMD_OFFSET;	u32 i;	/* boot buffer lenght */	writew(CFM_LOAD_BUFSZ, pt_boot_cmd + sizeof(u16));	writew(GEN_DEFPAR, pt_boot_cmd);	if (wait_cyc(addr) < 0)		return -1;	writew(0x0000, pt_boot_cmd + sizeof(u16));	writew(0xc400, pt_boot_cmd + 2 * sizeof(u16));	writew(GEN_SET_SEG, pt_boot_cmd);	if (wait_cyc(addr) < 0)		return -1;	for (i = 0 ; i < len ; i += CFM_LOAD_BUFSZ)		if (buffer_load(addr, code + i,				min_t(u32, CFM_LOAD_BUFSZ, (len - i)))) {			printk(KERN_ERR "%s: Error !!\n", modname);			return -1;		}	return 0;}/* Load adapter from the memory image of the CYCX firmware module. * o verify firmware integrity and compatibility * o start adapter up */static int load_cyc2x(struct cycx_hw *hw, struct cycx_firmware *cfm, u32 len){	int i, j;	struct cycx_fw_header *img_hdr;	u8 *reset_image,	   *data_image,	   *code_image;	void __iomem *pt_cycld = hw->dpmbase + 0x400;	u16 cksum;	/* Announce */	printk(KERN_INFO "%s: firmware signature=\"%s\"\n", modname,							    cfm->signature);	/* Verify firmware signature */	if (strcmp(cfm->signature, CFM_SIGNATURE)) {		printk(KERN_ERR "%s:load_cyc2x: not Cyclom-2X firmware!\n",				modname);		return -EINVAL;	}	printk(KERN_INFO "%s: firmware version=%u\n", modname, cfm->version);	/* Verify firmware module format version */	if (cfm->version != CFM_VERSION) {		printk(KERN_ERR "%s:%s: firmware format %u rejected! "				"Expecting %u.\n",				modname, __FUNCTION__, cfm->version, CFM_VERSION);		return -EINVAL;	}	/* Verify firmware module length and checksum */	cksum = checksum((u8*)&cfm->info, sizeof(struct cycx_fw_info) +					  cfm->info.codesize);/*	FIXME cfm->info.codesize is off by 2	if (((len - sizeof(struct cycx_firmware) - 1) != cfm->info.codesize) ||*/	if (cksum != cfm->checksum) {		printk(KERN_ERR "%s:%s: firmware corrupted!\n",				modname, __FUNCTION__);		printk(KERN_ERR " cdsize = 0x%x (expected 0x%lx)\n",				len - (int)sizeof(struct cycx_firmware) - 1,				cfm->info.codesize);		printk(KERN_ERR " chksum = 0x%x (expected 0x%x)\n",				cksum, cfm->checksum);		return -EINVAL;	}	/* If everything is ok, set reset, data and code pointers */	img_hdr = (struct cycx_fw_header *)&cfm->image;#ifdef FIRMWARE_DEBUG	printk(KERN_INFO "%s:%s: image sizes\n", __FUNCTION__, modname);	printk(KERN_INFO " reset=%lu\n", img_hdr->reset_size);	printk(KERN_INFO "  data=%lu\n", img_hdr->data_size);	printk(KERN_INFO "  code=%lu\n", img_hdr->code_size);#endif	reset_image = ((u8 *)img_hdr) + sizeof(struct cycx_fw_header);	data_image = reset_image + img_hdr->reset_size;	code_image = data_image + img_hdr->data_size;	/*---- Start load ----*/	/* Announce */	printk(KERN_INFO "%s: loading firmware %s (ID=%u)...\n", modname,			 cfm->descr[0] ? cfm->descr : "unknown firmware",			 cfm->info.codeid);	for (i = 0 ; i < 5 ; i++) {		/* Reset Cyclom hardware */		if (!reset_cyc2x(hw->dpmbase)) {			printk(KERN_ERR "%s: dpm problem or board not found\n",					modname);			return -EINVAL;		}		/* Load reset.bin */		cycx_reset_boot(hw->dpmbase, reset_image, img_hdr->reset_size);		/* reset is waiting for boot */		writew(GEN_POWER_ON, pt_cycld);		msleep_interruptible(1 * 1000);		for (j = 0 ; j < 3 ; j++)			if (!readw(pt_cycld))				goto reset_loaded;			else				msleep_interruptible(1 * 1000);	}	printk(KERN_ERR "%s: reset not started.\n", modname);	return -EINVAL;reset_loaded:	/* Load data.bin */	if (cycx_data_boot(hw->dpmbase, data_image, img_hdr->data_size)) {		printk(KERN_ERR "%s: cannot load data file.\n", modname);		return -EINVAL;	}	/* Load code.bin */	if (cycx_code_boot(hw->dpmbase, code_image, img_hdr->code_size)) {		printk(KERN_ERR "%s: cannot load code file.\n", modname);		return -EINVAL;	}	/* Prepare boot-time configuration data */	cycx_bootcfg(hw);	/* kick-off CPU */	cycx_start(hw->dpmbase);	/* Arthur Ganzert's tip: wait a while after the firmware loading...	   seg abr 26 17:17:12 EST 1999 - acme */	msleep_interruptible(7 * 1000);	printk(KERN_INFO "%s: firmware loaded!\n", modname);	/* enable interrupts */	cycx_inten(hw);	return 0;}/* Prepare boot-time firmware configuration data. * o initialize configuration data area   From async.doc - V_3.4.0 - 07/18/1994   - As of now, only static buffers are available to the user.     So, the bit VD_RXDIRC must be set in 'valid'. That means that user     wants to use the static transmission and reception buffers. */static void cycx_bootcfg(struct cycx_hw *hw){	/* use fixed buffers */	writeb(FIXED_BUFFERS, hw->dpmbase + CONF_OFFSET);}/* Detect Cyclom 2x adapter. *	Following tests are used to detect Cyclom 2x adapter: *       to be completed based on the tests done below *	Return 1 if detected o.k. or 0 if failed. *	Note:	This test is destructive! Adapter will be left in shutdown *		state after the test. */static int detect_cyc2x(void __iomem *addr){	reset_cyc2x(addr);	return memory_exists(addr);}/* Miscellaneous *//* Get option's index into the options list. *	Return option's index (1 .. N) or zero if option is invalid. */static int get_option_index(long *optlist, long optval){	int i = 1;	for (; i <= optlist[0]; ++i)		if (optlist[i] == optval)			return i;	return 0;}/* Reset adapter's CPU. */static int reset_cyc2x(void __iomem *addr){	writeb(0, addr + RST_ENABLE);	msleep_interruptible(2 * 1000);	writeb(0, addr + RST_DISABLE);	msleep_interruptible(2 * 1000);	return memory_exists(addr);}/* Calculate 16-bit CRC using CCITT polynomial. */static u16 checksum(u8 *buf, u32 len){	u16 crc = 0;	u16 mask, flag;	for (; len; --len, ++buf)		for (mask = 0x80; mask; mask >>= 1) {			flag = (crc & 0x8000);			crc <<= 1;			crc |= ((*buf & mask) ? 1 : 0);			if (flag)				crc ^= 0x1021;		}	return crc;}module_init(cycx_drv_init);module_exit(cycx_drv_cleanup);/* End */

⌨️ 快捷键说明

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