📄 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.------------------------------------------------------------------------*/#include <linux/config.h>#include <wlan/wlan_compat.h>#if (WLAN_OS == WLAN_LINUX_KERNEL)/* The following prevents "kernel_version" from being set in this file. */#define __NO_VERSION__/* PCMCIA headers generated during PCMCIA package installation */#ifdef WLAN_PCMCIA#include <pcmcia/config.h>#include <pcmcia/k_compat.h>#endif/* Module related headers, non-module drivers should not include */#include <linux/version.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.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>/* Standard driver includes */#include <linux/delay.h>#include <linux/types.h>#include <linux/fcntl.h>#include <asm/system.h>#include <asm/bitops.h>#include <asm/io.h>#include <linux/ptrace.h>#include <linux/interrupt.h>#include <linux/in.h>#include <linux/malloc.h>#include <linux/string.h>#include <linux/timer.h>#include <linux/errno.h>/* Card and Driver services includes */#ifdef WLAN_PCMCIA#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>#endif/* Local Includes */#include <wlan/version.h>#include <wlan/wlan_compat.h>#include <wlan/p80211hdr.h>#include <wlan/p80211mgmt.h>#include <wlan/am930mib.h>#include <wlan/wlan_ioctl.h>#ifdef WLAN_PCMCIA#include "am930di.h"#endif#include "am930llc.h"#include "am930mac.h"#include "am930hw.h"#include "am930mgr.h"#elif (WLAN_OS == WLAN_LWOS)#include <stddef.h>#include <stdlibsys.h>#include <clock.h>#include <direct.h>#include <hal.h>#include <kernel.h>#include <spi.h>#include <wlan/wlan_compat.h>#include <wlan/version.h>#include <wlan/p80211hdr.h>#include <wlan/p80211mgmt.h>#include <wlan/am930mib.h>#include <wlan/wlan_stable.h>#include <lw-wlan.h>#include <wlan/am930mac.h>#include <wlan/am930hw.h>#include <wlan/am930mgr.h>#else #error "No WLAN_OS match!"#endif/*================================================================*//* 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 */#define AM930_NTXDESC 5#define AM930_MAX_TXDATA 1550 /* NEED TO CHANGE THIS TO 802.11 MAX */#define AM930_TXSLOT_LEN (sizeof(am930tx_desc_t) + AM930_MAX_TXDATA)/*================================================================*//* Local Types *//* return type for the f/w command send method */__WLAN_PRAGMA_PACK1__typedef struct am930hw_cmd_result{ UINT8 fw_status __WLAN_ATTRIB_PACK__; /* f/w returned status */ UINT8 fw_err_off __WLAN_ATTRIB_PACK__; /* f/w error offset */ UINT8 drvr_status __WLAN_ATTRIB_PACK__; /* driver code errors */ UINT8 rsvd __WLAN_ATTRIB_PACK__; } am930hw_cmd_result_t;__WLAN_PRAGMA_PACKDFLT__/* types for setting up the tx queues in card memory */__WLAN_PRAGMA_PACK1__typedef struct am930tx_dataslot{ am930tx_desc_t desc __WLAN_ATTRIB_PACK__; UINT8 data[AM930_MAX_TXDATA] __WLAN_ATTRIB_PACK__;} am930tx_dataslot_t;__WLAN_PRAGMA_PACKDFLT__/*================================================================*//* 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 void memsetcard( am930hw_t *hw, UINT32 cardaddr, UINT8 val, 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 UINT32 reread32( 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 (WLAN_OS == WLAN_LWOS)static am930hw_t ghw;#endif/*================================================================*//* 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 __WLAN_INLINE__ void am930hw_unlockint( am930hw_t *hw){ DBFENTER; write8(hw, hw->cs + CS_OFF_LOCKOUT_FW, 0); DBFEXIT;}static __WLAN_INLINE__ int am930hw_lockint( am930hw_t *hw){ int result = 0; int ntries; int count; wlan_flags_t flags; DBFENTER; WLAN_INT_DISABLE(flags); /* 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--); WLAN_INT_ENABLE(flags); if ( ntries <= 0 ) { WLAN_LOG_DEBUG0(2, "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; UINT32 rx_buffer_top; UINT8 one = 1; su_mib_mac_statistics_t mib_stats; DBFENTER; /* allocate and zero the object */#if (WLAN_OS == WLAN_LINUX_KERNEL) hw = kmalloc( sizeof(am930hw_t), GFP_KERNEL);#elif (WLAN_OS == WLAN_LWOS) hw = &ghw;#else #error "No WLAN_OS match!"#endif 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; if (hw->membase) { WLAN_LOG_NOTICE3("am930: io=0x%lx irq=%ld\n membase=0x%lx\n", hw->iobase, hw->irq, hw->membase); } else { WLAN_LOG_NOTICE2("am930: io=0x%lx irq=%ld\n", hw->iobase, hw->irq); } 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 */ hw->mac->hw = hw; /* hook up with mac so interrupts are handled */ 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 */#if (WLAN_OS == WLAN_LWOS )// LED_Blink( WLAN_HLED_POWER, LED_ON);#endif /* first get and check the firmware banner for correct version */ readcard( hw, hw->banner, banner, SU_LEN_BANNER); WLAN_LOG_NOTICE1("am930: Firmware Banner: %s \n", banner);#if (WLAN_OS == WLAN_LINUX_KERNEL ) 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);#elif (WLAN_OS == WLAN_LWOS ) hw->fw_major = 2; hw->fw_minor = 1; hw->fw_date = 0; hw->fw_api = 0;#else #error "No WLAN_OS match!"#endif WLAN_LOG_NOTICE4( "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) ) ) { WLAN_LOG_ERROR0("Unsupported firmware version!\n"); am930hw_destruct( hw ); hw = NULL; } else { /*--------------------------------------------*/ /* Set the control area variables */ /* Lets set usr_return to zero */ write8(hw, hw->cs + CS_OFF_USER_RTN, 0); /* Set the pwr_dn to one */ write8(hw, hw->cs + CS_OFF_DIS_PWR_DN, 1); /* set the state bit for the object */ hw->state &= ~AM930HW_CONFIG_PENDING; hw->state |= AM930HW_CONFIG; WLAN_LOG_INFO0("Reset and f/w TestInterface are successful\n"); /*--------------------------------------------*/ /* Set some MIB items */ /* disable TX fragmentation, because of host-based WEP */ am930hw_mibsetitem( hw, LOC_FRAGDISABLE, &one, MI_SZ(LOC_FRAGDISABLE)); /* disable RX fragment reassembly, too much SRAM load */ am930hw_mibsetitem( hw, LOC_REASSEMBLY_DISABLE, &one, MI_SZ(LOC_REASSEMBLY_DISABLE));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -