?? mconfig.c
字號:
/* mConfig.c - contians configuration and setup functions for manlib */
/* Copyright (c) 2001 Atheros Communications, Inc., All Rights Reserved */
#ident "ACI $Id: //depot/sw/branches/ART_V53_dragon/sw/src/dk/mdk/devlib/mConfig.c#9 $, $Header: //depot/sw/branches/ART_V53_dragon/sw/src/dk/mdk/devlib/mConfig.c#9 $"
/*
Revsision history
--------------------
1.0 Created.
*/
#ifdef VXWORKS
#include "vxworks.h"
#endif
#ifdef __ATH_DJGPPDOS__
#include <unistd.h>
#ifndef EILSEQ
#define EILSEQ EIO
#endif // EILSEQ
#define __int64 long long
#define HANDLE long
typedef unsigned long DWORD;
#define Sleep delay
#endif // #ifdef __ATH_DJGPPDOS__
#include "wlantype.h"
#include "ar5210reg.h"
#if defined(SPIRIT_AP) || defined(FREEDOM_AP)
#ifdef COBRA_AP
#include "ar531xPlusreg.h"
#else
#include "ar531xreg.h"
#endif
#ifdef FALCON_ART_CLIENT
#include "ar5513reg.h"
#endif
#endif
#include "athreg.h"
#include "manlib.h"
#include "mdata.h"
#include "mEeprom.h"
#include "mConfig.h"
#include "mDevtbl.h"
#ifdef LINUX
#include "../mdk/dk_ver.h"
#else
#include "..\mdk\dk_ver.h"
#endif
#include "mCfg210.h"
#include "mCfg211.h"
#include "mData211.h"
#include "mEEP210.h"
#include "mEEP211.h"
#include "..\ar5513\mCfg513.h"
#include "..\ar6000\mEep6000.h"
#include "artEar.h"
#include "art_ani.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <math.h>
#include "mIds.h"
#include "rate_constants.h"
//#ifdef LINUX
//#include "linuxdrv.h"
//#else
#include "ntdrv.h"
//#endif
#if !defined(VXWORKS) && !defined(LINUX)
#include <io.h>
#endif
#if (!CUSTOMER_REL) && (INCLUDE_DRIVER_CODE)
#if (MDK_AP)
int m_ar5212Reset(LIB_DEV_INFO *pLibDev, A_UCHAR *mac, A_UCHAR *bss, A_UINT32 freq, A_UINT32 turbo) {
return -1;
}
#else
#include "m_ar5212.h"
#endif
#endif //CUSTOMER_REL
// ARCH_BIG_ENDIAN is defined some where. Cannot determine where it is defined
// Undefined LINUX for now
//#ifdef LINUX
//#undef ARCH_BIG_ENDIAN
//#endif
// Mapping _access to access
#if defined (LINUX) || defined (__ATH_DJGPPDOS__ )
#define _access(fileName,mode) access((const char *)(fileName),(int)(mode))
#endif
#ifdef ARCH_BIG_ENDIAN
#include "endian_func.h"
#endif
//###########Temp place for ar5001 definitions
#define F2_EEPROM_ADDR 0x6000 // EEPROM address register (10 bit)
#define F2_EEPROM_DATA 0x6004 // EEPROM data register (16 bit)
#define F2_EEPROM_CMD 0x6008 // EEPROM command register
#define F2_EEPROM_CMD_READ 0x00000001
#define F2_EEPROM_CMD_WRITE 0x00000002
#define F2_EEPROM_CMD_RESET 0x00000004
#define F2_EEPROM_STS 0x600c // EEPROM status register
#define F2_EEPROM_STS_READ_ERROR 0x00000001
#define F2_EEPROM_STS_READ_COMPLETE 0x00000002
#define F2_EEPROM_STS_WRITE_ERROR 0x00000004
#define F2_EEPROM_STS_WRITE_COMPLETE 0x00000008
LIB_INFO gLibInfo = {0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
MANLIB_API A_UINT32 enableCal = DO_NF_CAL | DO_OFSET_CAL;
A_UINT32 lib_memory_range;
A_UINT32 cache_line_size;
static A_INT32 tempMDKErrno = 0;
static char tempMDKErrStr[SIZE_ERROR_BUFFER];
#ifndef MDK_AP
static FILE *logFileHandle;
static A_BOOL logging = 0;
#endif
PCI_VALUES pciValues[MAX_PCI_ENTRIES];
//MANLIB_API A_UINT32 checkSumLength=0x400; //default to 16k
//MANLIB_API A_UINT32 eepromSize=0;
// Local Functions
static void initializeTransmitPower(A_UINT32 devNum, A_UINT32 freq,
A_INT32 override, A_UCHAR *pwrSettings);
static A_BOOL setChannel(A_UINT32 devNum, A_UINT32 freq);
static void setSpurMitigation(A_UINT32 devNum, A_UINT32 freq);
static void testEEProm(A_UINT32 devNum);
static void enable_beamforming(A_UINT32 devNum);
static void init_beamforming_weights(A_UINT32 devNum);
#ifdef HEADER_LOAD_SCHEME
static A_BOOL setupEEPromHeaderMap(A_UINT32 devNum);
#endif //HEADER_LOAD_SCHEME
static PWR_CTL_PARAMS pwrParams = { {FALSE, FALSE, FALSE},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0} };
A_UINT32 hwReset ( A_UINT32 devNum, A_UINT32 resetMask) {
LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
//printf("SNOOP:::hwReset passing to %s\n", (pLibDev->devMap.remoteLib?"remote":"local"));
if (pLibDev->devMap.remoteLib)
return (pLibDev->devMap.r_hwReset(devNum, resetMask));
else {
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->hwReset(devNum, resetMask);
return(0xDEADBEEF); // it appears hwReset is overloaded to return macRev ONLY for remoteLib.
// return a bogus value in other case to suppress warnings. PD 1/04
}
}
void pllProgram ( A_UINT32 devNum, A_UINT32 turbo) {
LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
if (pLibDev->devMap.remoteLib) {
if((ar5kInitData[pLibDev->ar5kInitIndex].deviceID & 0xf000 == 0xa000) && pLibDev->mode == MODE_11B)
changeField(devNum,"bb_tx_frame_to_xpab_on", 0x7);
pLibDev->devMap.r_pllProgram(devNum, turbo, pLibDev->mode);
}
else
ar5kInitData[pLibDev->ar5kInitIndex].pMacAPI->pllProgram(devNum, turbo);
}
MANLIB_API A_INT32 getNextDevNum() {
A_UINT32 i;
for(i = 0; i < LIB_MAX_DEV; i++) {
if(gLibInfo.pLibDevArray[i] == NULL) {
return i;
}
}
return -1;
}
/**************************************************************************
* initializeDevice - Setup all structures associated with this device
*
*/
MANLIB_API A_UINT32 initializeDevice
(
struct DeviceMap map
)
{
A_UINT32 i, devNum = LIB_MAX_DEV;
LIB_DEV_INFO *pLibDev;
if (map.remoteLib) { // Thin client
lib_memory_range = 32 * 1024; // 100kB
//lib_memory_range = 10 * 1024; // 100kB
cache_line_size = 0x10;
}
else { // library present locally
lib_memory_range = 1048576; // 1mB
cache_line_size = 0x20;
}
//printf("SNOOP:: intializeDevice called\n");
if(gLibInfo.devCount+1 > LIB_MAX_DEV) {
mError(0xdead, EINVAL, "initializeDevice: Cannot initialize more than %d devices\n", LIB_MAX_DEV);
return 0xdead;
}
// Device sanity checks
if(map.DEV_CFG_RANGE != LIB_CFG_RANGE) {
mError(0xdead, EINVAL, "initializeDevice: DEV_CFG_RANGE should be %d, was given %d\n", LIB_CFG_RANGE, map.DEV_CFG_RANGE);
return 0xdead;
}
// Atleast 1 MB of memory is required
if(map.DEV_MEMORY_RANGE < lib_memory_range) {
mError(0xdead, EINVAL, "initializeDevice: DEV_MEMORY_RANGE should be more than %d, was given %d\n", lib_memory_range, map.DEV_MEMORY_RANGE);
return 0xdead;
}
if(map.DEV_REG_RANGE != LIB_REG_RANGE) {
mError(0xdead, EINVAL, "initializeDevice: DEV_REG_RANGE should be %d, was given %d\n", LIB_REG_RANGE, map.DEV_REG_RANGE);
return 0xdead;
}
//check for the allocated memory being cache line aligned.
if (map.DEV_MEMORY_ADDRESS & (cache_line_size - 1)) {
mError(0xdead, EINVAL,
"initializeDevice: DEV_MEMORY_ADDRESS should be cache line aligned (0x%x), was given 0x%08lx\n",
cache_line_size, map.DEV_MEMORY_ADDRESS);
return 0xdead;
}
for(i = 0; i < LIB_MAX_DEV; i++) {
if(gLibInfo.pLibDevArray[i] == NULL) {
devNum = i;
break;
}
}
assert(i < LIB_MAX_DEV);
// Allocate the structures for the new device
gLibInfo.pLibDevArray[devNum] = (LIB_DEV_INFO *)malloc(sizeof(LIB_DEV_INFO));
if (gLibInfo.pLibDevArray[devNum] == NULL) {
mError(devNum, ENOMEM, "initializeDevice: Failed to allocate the library device information structure\n");
return 0xdead;
}
// Zero out all structures
pLibDev = gLibInfo.pLibDevArray[devNum];
memset(pLibDev, 0, sizeof(LIB_DEV_INFO));
pLibDev->devNum = devNum;
pLibDev->ar5kInitIndex = UNKNOWN_INIT_INDEX;
gLibInfo.devCount++;
memcpy(&(pLibDev->devMap), &map, sizeof(struct DeviceMap));
/* Initialize the map bytes for tracking memory management: calloc will init to 0 as well*/
pLibDev->mem.allocMapSize = (pLibDev->devMap.DEV_MEMORY_RANGE / BUFF_BLOCK_SIZE) / 8;
pLibDev->mem.pAllocMap = (A_UCHAR *) calloc(pLibDev->mem.allocMapSize, sizeof(A_UCHAR));
if(pLibDev->mem.pAllocMap == NULL) {
mError(devNum, ENOMEM, "initializeDevice: Failed to allocate the allocation map\n");
free(gLibInfo.pLibDevArray[devNum]);
return 0xdead;
}
pLibDev->mem.pIndexBlocks = (A_UINT16 *) calloc((pLibDev->mem.allocMapSize * 8), sizeof(A_UINT16));
if(pLibDev->mem.pIndexBlocks == NULL) {
mError(devNum, ENOMEM, "initializeDevice: Failed to allocate the indexBlock map\n");
free(gLibInfo.pLibDevArray[devNum]->mem.pAllocMap);
free(gLibInfo.pLibDevArray[devNum]);
return 0xdead;
}
pLibDev->mem.usingExternalMemory = FALSE;
pLibDev->regFileRead = 0;
pLibDev->regFilename[0] = '\0'; // empty string
pLibDev->mdkErrno = 0;
pLibDev->mdkErrStr[0] = '\0';
pLibDev->libCfgParams.refClock = REF_CLK_DYNAMIC;
pLibDev->devState = INIT_STATE;
pLibDev->eepromStartLoc = 0x00; // default. set to 0x400 for the 2nd eeprom_block if present
pLibDev->maxLinPwrx4 = 0; // default init to 0 dBm
pLibDev->libCfgParams.chainSelect = 2;
pLibDev->libCfgParams.flashCalSectorErased = FALSE;
pLibDev->libCfgParams.useShadowEeprom = FALSE;
pLibDev->libCfgParams.useEepromNotFlash = FALSE; // AR5005 configured to use flash by default
pLibDev->libCfgParams.tx_chain_mask = 0x3; // default dual for falcon
pLibDev->libCfgParams.rx_chain_mask = 0x3; // default dual for falcon
pLibDev->libCfgParams.chain_mask_updated_from_eeprom = FALSE;
pLibDev->blockFlashWriteOn = FALSE;
pLibDev->noEndPacket = FALSE;
#ifndef __ATH_DJGPPDOS__
// enable ART ANI and reuse by default
configArtAniSetup(devNum, ART_ANI_ENABLED, ART_ANI_REUSE_ON);
#endif
return devNum;
}
/**************************************************************************
* useMDKMemory - Repoints the libraries memory map at the one used by
* MDK so they can share the map
*
*/
MANLIB_API void useMDKMemory
(
A_UINT32 devNum,
A_UCHAR *pExtAllocMap,
A_UINT16 *pExtIndexBlocks
)
{
LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
if(gLibInfo.pLibDevArray[devNum] == NULL) {
mError(devNum, EINVAL, "Device Number %d:useMDKMemory\n", devNum);
return;
}
if (gLibInfo.pLibDevArray[devNum]->devState < INIT_STATE) {
mError(devNum, EILSEQ, "Device Number %d:useMDKMemory: initializeDevice must be called first\n", devNum);
return;
}
if((pExtAllocMap == NULL) || (pExtIndexBlocks == NULL)) {
mError(devNum, EINVAL, "Device Number %d:useMDKMemory: provided memory pointers are NULL\n", devNum);
return;
}
// Free the current Memory Map
free(gLibInfo.pLibDevArray[devNum]->mem.pIndexBlocks);
free(gLibInfo.pLibDevArray[devNum]->mem.pAllocMap);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -