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

📄 spectrum_cs.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as * Symbol Wireless Networker LA4100, CompactFlash cards by Socket * Communications and Intel PRO/Wireless 2011B. * * The driver implements Symbol firmware download.  The rest is handled * in hermes.c and orinoco.c. * * Utilities for downloading the Symbol firmware are available at * http://sourceforge.net/projects/orinoco/ * * Copyright (C) 2002-2005 Pavel Roskin <proski@gnu.org> * Portions based on orinoco_cs.c: * 	Copyright (C) David Gibson, Linuxcare Australia * Portions based on Spectrum24tDnld.c from original spectrum24 driver: * 	Copyright (C) Symbol Technologies. * * See copyright notice in file orinoco.c. */#define DRIVER_NAME "spectrum_cs"#define PFX DRIVER_NAME ": "#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/firmware.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/cisreg.h>#include <pcmcia/ds.h>#include "orinoco.h"static unsigned char *primsym;static unsigned char *secsym;static const char primary_fw_name[] = "symbol_sp24t_prim_fw";static const char secondary_fw_name[] = "symbol_sp24t_sec_fw";/********************************************************************//* Module stuff							    *//********************************************************************/MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader");MODULE_LICENSE("Dual MPL/GPL");/* Module parameters *//* Some D-Link cards have buggy CIS. They do work at 5v properly, but * don't have any CIS entry for it. This workaround it... */static int ignore_cis_vcc; /* = 0 */module_param(ignore_cis_vcc, int, 0);MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket");/********************************************************************//* Magic constants						    *//********************************************************************//* * The dev_info variable is the "key" that is used to match up this * device driver with appropriate cards, through the card * configuration database. */static dev_info_t dev_info = DRIVER_NAME;/********************************************************************//* Data structures						    *//********************************************************************//* PCMCIA specific device information (goes in the card field of * struct orinoco_private */struct orinoco_pccard {	dev_link_t link;	dev_node_t node;};/* * A linked list of "instances" of the device.  Each actual PCMCIA * card corresponds to one device instance, and is described by one * dev_link_t structure (defined in ds.h). */static dev_link_t *dev_list; /* = NULL *//********************************************************************//* Function prototypes						    *//********************************************************************/static void spectrum_cs_release(dev_link_t *link);static void spectrum_cs_detach(dev_link_t *link);/********************************************************************//* Firmware downloader						    *//********************************************************************//* Position of PDA in the adapter memory */#define EEPROM_ADDR	0x3000#define EEPROM_LEN	0x200#define PDA_OFFSET	0x100#define PDA_ADDR	(EEPROM_ADDR + PDA_OFFSET)#define PDA_WORDS	((EEPROM_LEN - PDA_OFFSET) / 2)/* Constants for the CISREG_CCSR register */#define HCR_RUN		0x07	/* run firmware after reset */#define HCR_IDLE	0x0E	/* don't run firmware after reset */#define HCR_MEM16	0x10	/* memory width bit, should be preserved *//* * AUX port access.  To unlock the AUX port write the access keys to the * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL * register.  Then read it and make sure it's HERMES_AUX_ENABLED. */#define HERMES_AUX_ENABLE	0x8000	/* Enable auxiliary port access */#define HERMES_AUX_DISABLE	0x4000	/* Disable to auxiliary port access */#define HERMES_AUX_ENABLED	0xC000	/* Auxiliary port is open */#define HERMES_AUX_PW0	0xFE01#define HERMES_AUX_PW1	0xDC23#define HERMES_AUX_PW2	0xBA45/* End markers */#define PDI_END		0x00000000	/* End of PDA */#define BLOCK_END	0xFFFFFFFF	/* Last image block */#define TEXT_END	0x1A		/* End of text header *//* * The following structures have little-endian fields denoted by * the leading underscore.  Don't access them directly - use inline * functions defined below. *//* * The binary image to be downloaded consists of series of data blocks. * Each block has the following structure. */struct dblock {	__le32 _addr;		/* adapter address where to write the block */	__le16 _len;		/* length of the data only, in bytes */	char data[0];		/* data to be written */} __attribute__ ((packed));/* * Plug Data References are located in in the image after the last data * block.  They refer to areas in the adapter memory where the plug data * items with matching ID should be written. */struct pdr {	__le32 _id;		/* record ID */	__le32 _addr;		/* adapter address where to write the data */	__le32 _len;		/* expected length of the data, in bytes */	char next[0];		/* next PDR starts here */} __attribute__ ((packed));/* * Plug Data Items are located in the EEPROM read from the adapter by * primary firmware.  They refer to the device-specific data that should * be plugged into the secondary firmware. */struct pdi {	__le16 _len;		/* length of ID and data, in words */	__le16 _id;		/* record ID */	char data[0];		/* plug data */} __attribute__ ((packed));;/* Functions for access to little-endian data */static inline u32dblock_addr(const struct dblock *blk){	return le32_to_cpu(blk->_addr);}static inline u32dblock_len(const struct dblock *blk){	return le16_to_cpu(blk->_len);}static inline u32pdr_id(const struct pdr *pdr){	return le32_to_cpu(pdr->_id);}static inline u32pdr_addr(const struct pdr *pdr){	return le32_to_cpu(pdr->_addr);}static inline u32pdr_len(const struct pdr *pdr){	return le32_to_cpu(pdr->_len);}static inline u32pdi_id(const struct pdi *pdi){	return le16_to_cpu(pdi->_id);}/* Return length of the data only, in bytes */static inline u32pdi_len(const struct pdi *pdi){	return 2 * (le16_to_cpu(pdi->_len) - 1);}/* Set address of the auxiliary port */static inline voidspectrum_aux_setaddr(hermes_t *hw, u32 addr){	hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));	hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));}/* Open access to the auxiliary port */static intspectrum_aux_open(hermes_t *hw){	int i;	/* Already open? */	if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED)		return 0;	hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);	hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);	hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);	hermes_write_reg(hw, HERMES_CONTROL, HERMES_AUX_ENABLE);	for (i = 0; i < 20; i++) {		udelay(10);		if (hermes_read_reg(hw, HERMES_CONTROL) ==		    HERMES_AUX_ENABLED)			return 0;	}	return -EBUSY;}#define CS_CHECK(fn, ret) \  do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)/* * Reset the card using configuration registers COR and CCSR. * If IDLE is 1, stop the firmware, so that it can be safely rewritten. */static intspectrum_reset(dev_link_t *link, int idle){	int last_ret, last_fn;	conf_reg_t reg;	u_int save_cor;	/* Doing it if hardware is gone is guaranteed crash */	if (!(link->state & DEV_CONFIG))		return -ENODEV;	/* Save original COR value */	reg.Function = 0;	reg.Action = CS_READ;	reg.Offset = CISREG_COR;	CS_CHECK(AccessConfigurationRegister,		 pcmcia_access_configuration_register(link->handle, &reg));	save_cor = reg.Value;	/* Soft-Reset card */	reg.Action = CS_WRITE;	reg.Offset = CISREG_COR;	reg.Value = (save_cor | COR_SOFT_RESET);	CS_CHECK(AccessConfigurationRegister,		 pcmcia_access_configuration_register(link->handle, &reg));	udelay(1000);	/* Read CCSR */	reg.Action = CS_READ;	reg.Offset = CISREG_CCSR;	CS_CHECK(AccessConfigurationRegister,		 pcmcia_access_configuration_register(link->handle, &reg));	/*	 * Start or stop the firmware.  Memory width bit should be	 * preserved from the value we've just read.	 */	reg.Action = CS_WRITE;	reg.Offset = CISREG_CCSR;	reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16);	CS_CHECK(AccessConfigurationRegister,		 pcmcia_access_configuration_register(link->handle, &reg));	udelay(1000);	/* Restore original COR configuration index */	reg.Action = CS_WRITE;	reg.Offset = CISREG_COR;	reg.Value = (save_cor & ~COR_SOFT_RESET);	CS_CHECK(AccessConfigurationRegister,		 pcmcia_access_configuration_register(link->handle, &reg));	udelay(1000);	return 0;      cs_failed:	cs_error(link->handle, last_fn, last_ret);	return -ENODEV;}/* * Scan PDR for the record with the specified RECORD_ID. * If it's not found, return NULL. */static struct pdr *spectrum_find_pdr(struct pdr *first_pdr, u32 record_id){	struct pdr *pdr = first_pdr;	while (pdr_id(pdr) != PDI_END) {		/*		 * PDR area is currently not terminated by PDI_END.		 * It's followed by CRC records, which have the type		 * field where PDR has length.  The type can be 0 or 1.		 */		if (pdr_len(pdr) < 2)			return NULL;		/* If the record ID matches, we are done */		if (pdr_id(pdr) == record_id)			return pdr;		pdr = (struct pdr *) pdr->next;	}	return NULL;}/* Process one Plug Data Item - find corresponding PDR and plug it */static intspectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi){	struct pdr *pdr;	/* Find the PDI corresponding to this PDR */	pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi));	/* No match is found, safe to ignore */	if (!pdr)		return 0;	/* Lengths of the data in PDI and PDR must match */	if (pdi_len(pdi) != pdr_len(pdr))		return -EINVAL;	/* do the actual plugging */	spectrum_aux_setaddr(hw, pdr_addr(pdr));	hermes_write_words(hw, HERMES_AUXDATA, pdi->data,			   pdi_len(pdi) / 2);	return 0;}/* Read PDA from the adapter */static intspectrum_read_pda(hermes_t *hw, __le16 *pda, int pda_len){	int ret;	int pda_size;	/* Issue command to read EEPROM */	ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);	if (ret)		return ret;	/* Open auxiliary port */	ret = spectrum_aux_open(hw);	if (ret)		return ret;	/* read PDA from EEPROM */	spectrum_aux_setaddr(hw, PDA_ADDR);	hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2);	/* Check PDA length */	pda_size = le16_to_cpu(pda[0]);	if (pda_size > pda_len)		return -EINVAL;	return 0;}/* Parse PDA and write the records into the adapter */static intspectrum_apply_pda(hermes_t *hw, const struct dblock *first_block,		   __le16 *pda){	int ret;	struct pdi *pdi;	struct pdr *first_pdr;	const struct dblock *blk = first_block;	/* Skip all blocks to locate Plug Data References */	while (dblock_addr(blk) != BLOCK_END)		blk = (struct dblock *) &blk->data[dblock_len(blk)];	first_pdr = (struct pdr *) blk;	/* Go through every PDI and plug them into the adapter */	pdi = (struct pdi *) (pda + 2);	while (pdi_id(pdi) != PDI_END) {		ret = spectrum_plug_pdi(hw, first_pdr, pdi);		if (ret)			return ret;		/* Increment to the next PDI */		pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];	}	return 0;}/* Load firmware blocks into the adapter */static intspectrum_load_blocks(hermes_t *hw, const struct dblock *first_block){	const struct dblock *blk;	u32 blkaddr;	u32 blklen;	blk = first_block;	blkaddr = dblock_addr(blk);	blklen = dblock_len(blk);	while (dblock_addr(blk) != BLOCK_END) {		spectrum_aux_setaddr(hw, blkaddr);		hermes_write_words(hw, HERMES_AUXDATA, blk->data,				   blklen / 2);		blk = (struct dblock *) &blk->data[blklen];		blkaddr = dblock_addr(blk);		blklen = dblock_len(blk);	}	return 0;}/* * Process a firmware image - stop the card, load the firmware, reset * the card and make sure it responds.  For the secondary firmware take * care of the PDA - read it and then write it on top of the firmware. */static intspectrum_dl_image(hermes_t *hw, dev_link_t *link,		  const unsigned char *image){	int ret;	const unsigned char *ptr;	const struct dblock *first_block;	/* Plug Data Area (PDA) */	__le16 pda[PDA_WORDS];	/* Binary block begins after the 0x1A marker */	ptr = image;	while (*ptr++ != TEXT_END);	first_block = (const struct dblock *) ptr;	/* Read the PDA */	if (image != primsym) {		ret = spectrum_read_pda(hw, pda, sizeof(pda));		if (ret)			return ret;	}	/* Stop the firmware, so that it can be safely rewritten */	ret = spectrum_reset(link, 1);	if (ret)		return ret;	/* Program the adapter with new firmware */	ret = spectrum_load_blocks(hw, first_block);	if (ret)		return ret;	/* Write the PDA to the adapter */	if (image != primsym) {		ret = spectrum_apply_pda(hw, first_block, pda);		if (ret)			return ret;	}	/* Run the firmware */	ret = spectrum_reset(link, 0);	if (ret)		return ret;	/* Reset hermes chip and make sure it responds */	ret = hermes_init(hw);	/* hermes_reset() should return 0 with the secondary firmware */	if (image != primsym && ret != 0)		return -ENODEV;	/* And this should work with any firmware */	if (!hermes_present(hw))		return -ENODEV;	return 0;}/* * Download the firmware into the card, this also does a PCMCIA soft * reset on the card, to make sure it's in a sane state. */static intspectrum_dl_firmware(hermes_t *hw, dev_link_t *link){	int ret;	client_handle_t handle = link->handle;	const struct firmware *fw_entry;	if (request_firmware(&fw_entry, primary_fw_name,			     &handle_to_dev(handle)) == 0) {		primsym = fw_entry->data;	} else {		printk(KERN_ERR PFX "Cannot find firmware: %s\n",		       primary_fw_name);

⌨️ 快捷键说明

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