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

📄 mconfig.c

📁 atheros ar5001 5002 driver
💻 C
📖 第 1 页 / 共 5 页
字号:
/* 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_V45/sw/src/dk/mdk/devlib/mConfig.c#4 $, $Header: //depot/sw/branches/ART_V45/sw/src/dk/mdk/devlib/mConfig.c#4 $"

/* 
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 1


#include "wlantype.h"
#include "ar5210reg.h"

#if defined(SPIRIT_AP) || defined(FREEDOM_AP)
#include "ar531xreg.h"
#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 "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>
//#ifdef LINUX
//#include "linuxdrv.h"
//#else
//#include "ntdrv.h"
//#endif
#if !defined(VXWORKS) && !defined(LINUX)
#include <io.h>
#endif

#ifndef CUSTOMER_REL
#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

// BIG_ENDIAN is defined some where. Cannot determine where it is defined
// Undefined LINUX for now
#ifdef LINUX 
#undef 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 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;
static A_INT32 tempMDKErrno = 0;
static char tempMDKErrStr[SIZE_ERROR_BUFFER];
#ifndef MDK_AP
static FILE     *logFileHandle;
static A_BOOL	logging = 0;
#endif

//add rate extensions for venice
//                            6   9  12  18 24  36 48  54  
const A_UCHAR rateValues[] = {11, 15, 10, 14, 9, 13, 8, 12,    
//                       1L   2L   2S   5.5L 5.5S 11L  11S
                         0x1b,0x1a,0x1e,0x19,0x1d,0x18,0x1c,
//						 0.25 0.5 1  2  3
						 3,   7,  2, 6, 1
};

const A_UCHAR  rateCodes[] =  {6, 9, 12, 18, 24, 36, 48, 54, 0xb1, 0xb2, 0xd2, 0xb5, 0xd5, 0xbb, 0xdb, 
//                        XR0.25  XR0.5  XR1   XR2   XR3
							0xea, 0xeb,  0xe1, 0xe2, 0xe3};
const A_UINT16 numRateCodes = sizeof(rateCodes)/sizeof(A_UCHAR);
					

// 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 testEEProm(A_UINT32 devNum);
#ifdef HEADER_LOAD_SCHEME
static A_BOOL setupEEPromHeaderMap(A_UINT32 devNum);
#endif //HEADER_LOAD_SCHEME


/**************************************************************************
* 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(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));

	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->devNum = devNum;
	pLibDev->libCfgParams.refClock = REF_CLK_DYNAMIC;
    pLibDev->devState = INIT_STATE;
	gLibInfo.devCount++;
	pLibDev->ar5kInitIndex = UNKNOWN_INIT_INDEX;

#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);

    // Assign to the MDK Memory Map
    pLibDev->mem.pAllocMap = pExtAllocMap;
    pLibDev->mem.pIndexBlocks = pExtIndexBlocks;
    pLibDev->mem.usingExternalMemory = TRUE;
}

MANLIB_API A_UINT16 getDevIndex
(
	A_UINT32 devNum
)
{
	if (gLibInfo.pLibDevArray[devNum] == NULL) {
		mError(devNum, EINVAL, "Device Number %d:getDevIndex \n", devNum);
		return (A_UINT16)-1;
	}

	return gLibInfo.pLibDevArray[devNum]->devMap.devIndex;
}
/**************************************************************************
* closeDevice - Free all structures associated with this device
*
*/
MANLIB_API void closeDevice
(
	A_UINT32 devNum
) 
{
//   	FIELD_VALUES *pFieldValues;

	if(gLibInfo.pLibDevArray[devNum] == NULL) {
		mError(devNum, EINVAL, "Device Number %d:closeDevice\n", devNum);
		return;
	}
	if(gLibInfo.pLibDevArray[devNum]->mem.usingExternalMemory == FALSE) {
		if(gLibInfo.pLibDevArray[devNum]->mem.pIndexBlocks) {
			free(gLibInfo.pLibDevArray[devNum]->mem.pIndexBlocks);
		}
		if (gLibInfo.pLibDevArray[devNum]->mem.pAllocMap) {
			free(gLibInfo.pLibDevArray[devNum]->mem.pAllocMap);
		}
	}

	if(gLibInfo.pLibDevArray[devNum]->eepData.infoValid) {
		freeEepStructs(devNum);
		gLibInfo.pLibDevArray[devNum]->eepData.infoValid = FALSE;
	}

	
	if (gLibInfo.pLibDevArray[devNum]->regArray) {
		free(gLibInfo.pLibDevArray[devNum]->regArray);
	}
	if (gLibInfo.pLibDevArray[devNum]->pModeArray) {
		free(gLibInfo.pLibDevArray[devNum]->pModeArray);
	}

	if (gLibInfo.pLibDevArray[devNum]->pciValuesArray) {
		free(gLibInfo.pLibDevArray[devNum]->pciValuesArray);
	}
  
	if(gLibInfo.pLibDevArray[devNum]->pEarHead) {
		ar5212EarFree(gLibInfo.pLibDevArray[devNum]->pEarHead);
	}

	free(gLibInfo.pLibDevArray[devNum]);
	gLibInfo.pLibDevArray[devNum] = NULL;
	gLibInfo.devCount--;
}

/**************************************************************************
* specifySubSystemID - Tell library what subsystemID to try if can't find
*                      a match 
*
* 
*
*/
MANLIB_API void specifySubSystemID
(
 A_UINT32   devNum,
 A_UINT32	subsystemID
)
{
	mError(devNum, EIO, "Device Number %d:specifySubSystemID is an obsolete library command\n", devNum);
	
	devNum = 0;			//quiet compiler warning.
	subsystemID = 0; 
	return;
}

/**************************************************************************
* setResetParams - Setup params prior to calling resetDevice 
*
* These are new params added for second generation products
*
*/
MANLIB_API void setResetParams
(
 A_UINT32   devNum,
 A_CHAR     *pFilename,
 A_BOOL		eePromLoad,
 A_BOOL		forceCfgLoad,  
 A_UCHAR	mode,
 A_UINT16     initCodeFlag
)
{
   	LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];


	if (checkDevNum(devNum) == FALSE) {
		mError(devNum, EINVAL, "Device Number %d:setResetParams\n", devNum);
		return;
	}
    
	pLibDev->eePromLoad = eePromLoad;
//	pLibDev->eePromHeaderLoad = eePromHeaderLoad;
	pLibDev->mode = mode;
	pLibDev->use_init = initCodeFlag;

	if(forceCfgLoad) {
		pLibDev->regFileRead = 0;		
	}

    if(( pFilename == '\0' ) || ( pFilename == NULL ) || (pFilename[0] == (A_CHAR)NULL)) {
		return;
   }


#ifndef MDK_AP    
    //do a check for file exist and is readable
    if(_access(pFilename, 04) != 0) {
        mError(devNum, EINVAL, "Device Number %d:setRegFilename: either file does not exist or is not readable\n", devNum);
        return;
    }

	//if there is a config file change then reset the config file reading
	if(strcmp(pLibDev->regFilename, pFilename) != 0) {
		pLibDev->regFileRead = 0;
	}

    strcpy(pLibDev->regFilename, pFilename);
#endif
}

/**************************************************************************
* configureLibParams - Allow certain library params to be configured.
*                      Similar to setResetParmams.  This function will
*                      use a strcuture to pass params as this will be device
*                      specific params that will grow through time.
*
*/
MANLIB_API void configureLibParams
(
 A_UINT32   devNum,
 LIB_PARAMS *pLibParamsInfo
)
{
   	LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];

	if (pLibDev->libCfgParams.loadEar != pLibParamsInfo->loadEar) {
		pLibDev->regFileRead = 0;
	} 

#ifndef __ATH_DJGPPDOS__
	if (pLibDev->artAniSetup.Enabled != pLibParamsInfo->artAniEnable) {

⌨️ 快捷键说明

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