?? am930hw.c
字號:
/* am930_hw.c: Handles the specifics of the AM79C930/PRISM card* --------------------------------------------------------------------** Linux WLAN ** The contents of this file are subject to the Mozilla Public* License Version 1.0 (the "License"); you may not use this file* except in compliance with the License. You may obtain a copy of* the License at http://www.mozilla.org/MPL/** Software distributed under the License is distributed on an "AS* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or* implied. See the License for the specific language governing* rights and limitations under the License.** The initial developer of the original code is Mark S. Mathews* <mark@absoval.com>. Portions created by Mark S. Mathews* are Copyright (C) 1998 AbsoluteValue Software, Inc. All Rights Reserved.* * --------------------------------------------------------------------** The author may be reached as mark@absoval.com, or C/O AbsoluteValue* Software Inc., P.O. Box 941149, Maitland, FL, 32794-1149** Thanks to David Hinds, Donald Becker, and the rest of the Linux* developers worldwide for making all of this possible.** --------------------------------------------------------------------** The functions here implement all of the stuff that's specific* to this card. I've tried to keep all of the AM79C930 hardware and* firmware stuff here. Some specifics have bled into the mac and mgr* sections though.------------------------------------------------------------------------*//* The following prevents "kernel_version" from being set in this file. */#define __NO_VERSION__/* PCMCIA headers generated during PCMCIA package installation */#include <pcmcia/config.h>#include <pcmcia/k_compat.h>/* Module related headers, non-module drivers should not include */#include <linux/version.h>/* Standard driver includes */#include <assert.h>#include <linux/delay.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/fcntl.h>#include <linux/interrupt.h>#include <linux/ptrace.h>#include <linux/ioport.h>#include <linux/in.h>#include <linux/malloc.h>#include <linux/string.h>#include <linux/timer.h>#include <asm/system.h>#include <asm/bitops.h>#include <asm/io.h>#include <linux/errno.h>/* Ethernet and network includes */#include <linux/if_ether.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>#include <linux/if_arp.h>#include <linux/ioport.h>/* Card and Driver services includes */#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/ds.h>#include <pcmcia/cisreg.h>/* Local Includes */#include <wlan/version.h>#include <wlan/am930const.h>#include <wlan/p80211.h>#include <wlan/am930mib.h>#include "am930debug.h"#include "am930di.h"#include "am930mac.h"#include "am930hw.h"#include "am930mgr.h"#include "am930llc.h"/* This one sets up the bit for debug msg testing */#define FILEBIT DBHW/*================================================================*//* Local Macros *//* Am79c930, io port address methods (16 port mode) */#define GCR(hw) ((hw)->iobase)#define BSS(hw) (((hw)->iobase) + 0x01)#define LMAL(hw) (((hw)->iobase) + 0x02)#define LMAU(hw) (((hw)->iobase) + 0x03)#define DPLL(hw) (((hw)->iobase) + 0x04)#define DPLM(hw) (((hw)->iobase) + 0x05)#define DPUM(hw) (((hw)->iobase) + 0x06)#define DPUU(hw) (((hw)->iobase) + 0x07)#define TIR(index,base) /* TODO: write an inline for accessing the TIR's *//* General */#define ABS(N) ((N) < 0 ? -(N) : (N))#define AM930HW_FWNOTREADY (0x01)#define AM930HW_FWCMDTIMEOUT (0x02)#define AM930HW_CMD_SUCCESS 0#define AM930HW_CMD_GETMIBFAILED 1#define AM930HW_CMD_INITTXFAILED 2#define AM930HW_CMD_INITRXFAILED 3#define AM930HW_CMD_SCANFAILED 4#define AM930HW_CMD_SETMIBFAILED 5#define AM930HW_CMD_SYNCFAILED 6/*--- getset function action values ------------------*/#define SU_GET_INTMASK1 0x01#define SU_SET_INTMASK1 0x02#define SU_GET_INTMASK2 0x04#define SU_SET_INTMASK2 0x08#define SU_GET_INTSTATUS1 0x10#define SU_SET_INTSTATUS1 0x20#define SU_GET_INTSTATUS2 0x10#define SU_SET_INTSTATUS2 0x20#define SU_GETSET_INT_FAILED (BIT7) /* Queue setup values *//* See notes for 5/18/97 for discussion */#define AM930_NTXDESC 3#define AM930_MAX_TXDATA 1548/*================================================================*//* Local Types *//* return type for the f/w command send method */typedef struct am930hw_cmd_result{ UINT8 fw_status; /* f/w returned status */ UINT8 fw_err_off; /* f/w error offset */ UINT8 drvr_status; /* driver code errors */ UINT8 rsvd; } SU_PACK am930hw_cmd_result_t;/* types for setting up the tx queues in card memory */typedef struct am930tx_dataslot{ am930tx_desc_t desc; UINT8 data[AM930_MAX_TXDATA];} SU_PACK am930tx_dataslot_t;/*================================================================*//* Local Functions *//* private: *//* Hardware/firmware helper methods, (private) */static int am930hw_lockint( am930hw_t *hw);static void am930hw_unlockint( am930hw_t *hw);static UINT32 am930hw_read_rxnext(am930hw_t *hw);static am930hw_cmd_result_t am930hw_fw_cmd( am930hw_t *hw, UINT8 cmd, void* cmdparms, INT32 parmsize);static UINT16 am930hw_getset_int( am930hw_t *hw, int action, UINT8 mask, UINT8 status );static int am930hw_init_tx_queues( am930hw_t *hw);UINT32 am930hw_sync( am930hw_t *hw, UINT32 ch, UINT32 startBSS, wlan_bss_ts_t ts, UINT32 ref_time );/* firmware command helpers */static UINT32 am930hw_tx_enable(am930hw_t *hw);static UINT32 am930hw_rx_enable(am930hw_t *hw);/* ISR helpers */static void am930hw_onint_scancomplete( am930hw_t *hw);static void am930hw_onint_rx( am930hw_t *hw );static void am930hw_onint_tx( am930hw_t *hw );static void am930hw_onint_cmdcomplete( am930hw_t *hw );/* Card tx buffer memory mgmt */void am930mem_init( am930mem_t *mem, UINT32 start, UINT32 len);UINT32 am930mem_alloc( am930mem_t *mem, UINT32 size );UINT32 am930mem_free( am930mem_t *mem, UINT32 p, UINT32 len);/* Card memcpy functions */static void readcard( am930hw_t *hw, UINT32 cardaddr, void *buf, UINT32 len);static void writecard( am930hw_t *hw, UINT32 cardaddr, void *buf, UINT32 len);static UINT8 read8( am930hw_t *hw, UINT32 cardaddr );static UINT16 read16( am930hw_t *hw, UINT32 cardaddr );static UINT32 read32( am930hw_t *hw, UINT32 cardaddr );static void write8( am930hw_t *hw, UINT32 cardaddr, UINT8 val );static void write16( am930hw_t *hw, UINT32 cardaddr, UINT16 val );static void write32( am930hw_t *hw, UINT32 cardaddr, UINT32 val );/* Debug Helper Methods*/void am930hw_dbprintregs( am930hw_t *hw);void am930hw_dbprintCS_blk( am930hw_t *hw);void am930hw_dbprintCMD_blk( am930hw_t *hw);void am930hw_dbprintRXdesc( am930rx_desc_t *d);void am930hw_dbprintTXdesc( am930tx_desc_t *d);void am930hw_dbprintallMIBs(am930hw_t *hw);void am930hw_dbprintMIBlocal(am930hw_t *hw);void am930hw_dbprintMIBmac(am930hw_t *hw);void am930hw_dbprintMIBmac_addr_stat_grp(am930hw_t *hw);void am930hw_dbprintMIBmac_statistics(am930hw_t *hw);void am930hw_dbprintMIBmac_mgmt( am930hw_t *hw);void am930hw_dbprintMIBphy(am930hw_t *hw);void am930db_prrxdesc( am930rx_desc_t *desc);/*================================================================*//* Static variables */#if defined(FW_ORIG)char sutro_banner[] = "SUTRO: Oct 2 1996, 09:59:37";#elif defined(FW_NEW)char sutro_banner[] = "SUTRO: Jan 30 1997, 15:38:13";#elsechar sutro_banner[] = "SUTRO";#endif/* start mod: tld */static UINT32 rssi_tld=0;/* end mod: tld *//*================================================================*//* defined here because of inline *//*----------------------------------------------------------------* am930hw_(un)lockint** These two functions handle locking and unlocking driver access* to the control/status fields int_status and int_mask. * This is handled via the lockout_host and lockout_fw fields of* the cs block.** PS: if the firmware isn't locked out already, it doesn't hurt* anything to call unlockint** returns: 0 on success* non-zero on failure----------------------------------------------------------------*/static __INLINE__ void am930hw_unlockint( am930hw_t *hw){ DBFENTER; write8(hw, hw->cs + CS_OFF_LOCKOUT_FW, 0); DBFEXIT;}static __INLINE__ int am930hw_lockint( am930hw_t *hw){ u_int result = 0; int ntries; int count; u_long flags; DBFENTER; /* Disable interrupts */ save_flags(flags); cli(); /* Attempt the access procedure at most three times */ ntries = 3; do { /*--- check access ---*/ count = 10; /* waitloop */ while( count-- > 0 && read8(hw, hw->cs + CS_OFF_LOCKOUT_HOST)) { udelay(5); } if ( count > 0) { /*--- attempt lockout ---*/ write8(hw, hw->cs + CS_OFF_LOCKOUT_FW, 0xff); /* lockout the f/w */ /*--- check access again ---*/ if ( read8(hw, hw->cs + CS_OFF_LOCKOUT_HOST) != 0 ) { write8( hw, hw->cs + CS_OFF_LOCKOUT_FW, 0); } } } while ( read8(hw, hw->cs + CS_OFF_LOCKOUT_FW) == 0 && ntries--); /* Enable interrupts */ sti(); restore_flags(flags); if ( ntries <= 0 ) { DBPRT( DBFWSTATE,"Attempt to lockout f/w from cs block failed!\n"); result = 1; } DBFEXIT; return result;}/*----------------------------------------------------------------* am930hw_construct** Called _after_ someone has determined that we do in fact have* an am930 device present in the system _and_ we know where it * is. Compared to some drivers, this might be considered to be* "probe part 2".** This function will:* allocate the hw struct* fill in constant (possibly calculated) fields* initialize the ioports on the card,* perform a reset of the card (includes the f/w NOP test)* read the f/w banner to determine the f/w version* test the f/w version for a match with this driver*** When complete, we know that the card has been successfully reset* and the firmware is up and running. Additionally, the* firmware has been identified** Subsequent code will either prepare the card for tx/rx* or prepare the card for flash writes.** Arguments:* irq - IRQ being used by the card* iobase - base addr for io window* membase - base addr for memory window, if zero then there* is no memory window, use the io method to access* on card SRAM* * returns: addr. of the hw object if successful, NULL otherwise*----------------------------------------------------------------*/am930hw_t* am930hw_construct( UINT32 irq, UINT32 iobase, UINT32 membase, am930mac_t *mac){ am930hw_t *hw = NULL; char banner[SU_LEN_BANNER]; char *endp; UINT8 reg; su_mib_local_t mib; DBFENTER; /* allocate and zero the object */ hw = kmalloc( sizeof(am930hw_t), GFP_KERNEL); if (hw != NULL ) { memset( hw, 0, sizeof(am930hw_t)); hw->state |= AM930HW_CONFIG_PENDING; /* Initialize some of the members of the object */ hw->mac = mac; hw->membase = membase; hw->usemem = (membase != 0); hw->iobase = iobase; hw->irq = irq; printk(KERN_NOTICE"am930_cs: io=0x%lx irq=%ld", hw->iobase, hw->irq); if (hw->membase) { printk(" membase=0x%lx\n", hw->membase); } else { printk("\n"); } hw->banner = SU_OFF_BANNER; hw->cs = SU_OFF_CNTL_STATUS_BLK; hw->cmd = SU_OFF_CMD_BLK; hw->txcmplt = SU_OFF_LAST_TXDESC; hw->vbm = SU_OFF_VBM; /* Card is in an unknown state, perform a reset */ if ( am930hw_reset(hw) != 0 ) { am930hw_destruct( hw ); hw = NULL; } else { /* card should be in a post reset state and f/w NOP was successful, we can now issue f/w cmds and access oncard SRAM */ /* first get and check the firmware banner for correct version */ readcard( hw, hw->banner, banner, SU_LEN_BANNER); printk( KERN_NOTICE "am930_cs: Firmware Banner: %s \n", banner); hw->fw_major = simple_strtoul(banner+13, &endp, 10); hw->fw_minor = simple_strtoul(endp+1, &endp, 10); hw->fw_date = simple_strtoul(endp+1, &endp, 10); hw->fw_api = simple_strtoul(endp+4, &endp, 10); printk( KERN_DEBUG"f/w version:%lu.%02lu date:%lu api:%lu\n", hw->fw_major, hw->fw_minor, hw->fw_date, hw->fw_api); if ( !( (hw->fw_major == 2 && hw->fw_minor == 0) || (hw->fw_major == 2 && hw->fw_minor == 1) || (hw->fw_major == 1 && hw->fw_minor == 50) ) ) { DBPRT( DBINIT, "Unsupported firmware version!\n"); am930hw_destruct( hw ); hw = NULL; } else { /* First, enable ints from the 188 core, then enable f/w */ /* Enable Core Generated Interrupts */ outb_p( BIT1, GCR(hw) ); am930hw_getset_int( hw, SU_SET_INTMASK1 | SU_SET_INTSTATUS1 | SU_SET_INTMASK2 | SU_SET_INTSTATUS2, 0x00, 0x00 ); reg = inb_p( GCR(hw) ); reg |= BIT3; outb_p( reg, GCR(hw) ); /* Lets set usr_return to zero */ write8(hw, hw->cs + CS_OFF_USER_RTN, 0); /* Set the pwr_dn to zero *//* write8(hw, hw->cs + CS_OFF_DIS_PWR_DN, 1); */ /* Set the dis_pwr_dn register bit to zero */ /* reg = inb_p( GCR(hw) ); reg |= BIT5; outb_p( reg, GCR(hw) );*/ /* set the state bit for the object */ hw->state &= ~AM930HW_CONFIG_PENDING; hw->state |= AM930HW_CONFIG; DBPRT( DBINIT, "Card reset and firmware TestInterface are " "successful\n"); /* Get the rx buffer loc and size for sanity checking in */ /* onint_rx */ am930hw_mibget( hw, SUMIB_LOCAL, 0, sizeof(su_mib_local_t), &mib); hw->rx_base = mib.rx_buffer_offset; hw->rx_len = mib.rx_buffer_size; /* reset int bit in GCR (probably set by getmib cmd above) */ reg = inb_p( GCR(hw) ); reg |= BIT3; outb_p( reg, GCR(hw) ); reg = inb_p( GCR(hw) ); } } } DBFEXIT; return hw;} /*----------------------------------------------------------------* am930hw_destruct** returns: nothing----------------------------------------------------------------*/void am930hw_destruct(am930hw_t *hw){ DBFENTER; kfree_s( hw, sizeof(am930hw_t)); DBFEXIT; return;}/*----------------------------------------------------------------* am930hw_fw_cmd** This is a helper function used to send commands to the* firmware. It copies its arguments to the command block* and then sets the command. After setting the command, we then* wait for the command to complete. The wait includes a timeout* and if the command times out, that status is returned.* Otherwise we return the firmware indicated status. If the* firmware status is OK and if needed, the command parms are* copied to the buffer space provided by the caller.** Argument notes:* the ABS of the parmsize argument provides the number of * bytes to copy to the command parm area, and if the parm* is < 0 then after the command completes, we copy that* many bytes back from the command parm area as well.** returns: an am930cmd_result_t structure, which should be * four bytes long and can be played with like an int.----------------------------------------------------------------*/am930hw_cmd_result_t am930hw_fw_cmd( am930hw_t *hw, UINT8 cmd, void* cmdparms, INT32 parmsize){ am930hw_cmd_result_t result; UINT32 timeout; DBFENTER; /* clear the result struct */ memset( &result, 0, sizeof(result)); /* wait for the cmd block to be available */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -