📄 spectrum_cs.c
字号:
/* * 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>#ifdef __IN_PCMCIA_PACKAGE__#include <pcmcia/k_compat.h>#endif /* __IN_PCMCIA_PACKAGE__ */#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/ptrace.h>#include <linux/slab.h>#include <linux/string.h>#include <linux/ioport.h>#include <linux/netdevice.h>#include <linux/if_arp.h>#include <linux/etherdevice.h>#include <linux/wireless.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/cisreg.h>#include <pcmcia/ds.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/system.h>#include "orinoco.h"/* * If SPECTRUM_FW_INCLUDED is defined, the firmware is hardcoded into * the driver. Use get_symbol_fw script to generate spectrum_fw.h and * copy it to the same directory as spectrum_cs.c. * * If SPECTRUM_FW_INCLUDED is not defined, the firmware is loaded at the * runtime using hotplug. Use the same get_symbol_fw script to generate * files symbol_sp24t_prim_fw symbol_sp24t_sec_fw, copy them to the * hotplug firmware directory (typically /usr/lib/hotplug/firmware) and * make sure that you have hotplug installed and enabled in the kernel. *//* #define SPECTRUM_FW_INCLUDED 1 */#ifdef SPECTRUM_FW_INCLUDED/* Header with the firmware */#include "spectrum_fw.h"#else /* !SPECTRUM_FW_INCLUDED */#include <linux/firmware.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";#endif /* !SPECTRUM_FW_INCLUDED *//********************************************************************//* 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 *//********************************************************************//* device methods */static int spectrum_cs_hard_reset(struct orinoco_private *priv);/* PCMCIA gumpf */static void spectrum_cs_config(dev_link_t * link);static void spectrum_cs_release(dev_link_t * link);static int spectrum_cs_event(event_t event, int priority, event_callback_args_t * args);static dev_link_t *spectrum_cs_attach(void);static void spectrum_cs_detach(dev_link_t *);/********************************************************************//* 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 { u32 _addr; /* adapter address where to write the block */ u16 _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 { u32 _id; /* record ID */ u32 _addr; /* adapter address where to write the data */ u32 _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 { u16 _len; /* length of ID and data, in words */ u16 _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, ®)); 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, ®)); udelay(1000); /* Read CCSR */ reg.Action = CS_READ; reg.Offset = CISREG_CCSR; CS_CHECK(AccessConfigurationRegister, pcmcia_access_configuration_register(link->handle, ®)); /* * 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, ®)); 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, ®)); 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -