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

📄 mlibif.c

📁 atheros ar5001 5002 driver
💻 C
字号:
/* MLIBif.c - contians wrapper functions for MLIB */

/* Copyright (c) 2000 Atheros Communications, Inc., All Rights Reserved */
#ident  "ACI $Id: //depot/sw/branches/ART_V45/sw/src/dk/mdk/devmld/MLIBif.c#1 $, $Header: //depot/sw/branches/ART_V45/sw/src/dk/mdk/devmld/MLIBif.c#1 $"

#ifdef _WINDOWS 
#include <windows.h>
#endif

#include <time.h>
#include <errno.h>
#include <stdio.h>
#include "wlantype.h"
#include "athreg.h"
#include "manlib.h"
#include "manlibInst.h"
#include "dk_ver.h"
#ifdef ANWI
#include "mld_anwi.h"
#endif
#ifdef JUNGO
#include "mld.h"
#endif
#ifdef LINUX
#include "mld_linux.h"
#endif
#include "MLIBif.h"

// Dev to driverDev mapping table.  devNum must be in range 0 to LIB_MAX_DEV
A_UINT32   devNum2driverTable[LIB_MAX_DEV];
static A_BOOL last_op_was_read = 0;
static A_BOOL last_op_offset_was_fc = 0;

static void printRxStats(RX_STATS_STRUCT *pRxStats);
static void printTxStats(TX_STATS_STRUCT *pTxStats);

A_BOOL initializeEnvironment(A_BOOL remote) {
	A_BOOL	openDriver;
  
    // print version string
    uiPrintf("\n    --- Atheros Radio Test (ART) ---\n");
    uiPrintf(MAUIDK_VER2);
    uiPrintf(MAUIDK_VER3);
 
	openDriver = remote ?  0 : 1;

    // perform environment initialization
    if ( A_ERROR == envInit(FALSE, openDriver) ) {
        uiPrintf("Error: Unable to initialize the local environment... Closing down!\n");
        return FALSE;
    }
    return TRUE;
}


void closeEnvironment(void) {
    // clean up anything that was allocated and close the local driver
    envCleanup(TRUE);
}

A_BOOL devNumValid
(
 A_UINT32 devNum
)
{
    if(globDrvInfo.pDevInfoArray[dev2drv(devNum)] != NULL) {
        return TRUE;
    }
    else {
        return FALSE;
    }
}

void txPrintStats
(
 A_UINT32 devNum, 
 A_UINT32 rateInMb,
 A_UINT32 remote
)
{
    TX_STATS_STRUCT rStats;

    txGetStats(devNum, rateInMb, remote, &rStats);

	//check for errors
    if (!getMdkErrNo(devNum)) {
	    printTxStats(&rStats);
    }
}

void printTxStats
(
 TX_STATS_STRUCT *pTxStats
)
{
	uiPrintf("Good Packets           %10lu  ", pTxStats->goodPackets);
	uiPrintf("Ack sig strnth min     %10lu\n", pTxStats->ackSigStrengthMin);
	uiPrintf("Underruns              %10lu  ", pTxStats->underruns);
	uiPrintf("Ack sig strenth avg    %10lu\n", pTxStats->ackSigStrengthAvg);
	uiPrintf("Throughput             %10.2f  ",(float) pTxStats->throughput/1000);
	uiPrintf("Ack sig strenth max    %10lu\n", pTxStats->ackSigStrengthMax);
	uiPrintf("Excess retries         %10lu  ", pTxStats->excessiveRetries);
	uiPrintf("short retries 4        %10lu\n", pTxStats->shortRetry4); 
	uiPrintf("short retries 1        %10lu  ", pTxStats->shortRetry1); 
	uiPrintf("short retries 5        %10lu\n", pTxStats->shortRetry5); 
	uiPrintf("short retries 2        %10lu  ", pTxStats->shortRetry2); 
	uiPrintf("short retries 6-10     %10lu\n", pTxStats->shortRetry6to10); 
	uiPrintf("short retries 3        %10lu  ", pTxStats->shortRetry3); 
	uiPrintf("short retries 11-15    %10lu\n", pTxStats->shortRetry11to15); 
/*	uiPrintf("long  retries 1        %10lu  ", pTxStats->longRetry1); 
	uiPrintf("long  retries 2        %10lu\n", pTxStats->longRetry2); 
	uiPrintf("long  retries 3        %10lu  ", pTxStats->longRetry3); 
	uiPrintf("long  retries 4        %10lu\n", pTxStats->longRetry4); 
	uiPrintf("long  retries 5        %10lu  ", pTxStats->longRetry5); 
	uiPrintf("long  retries 6-10     %10lu\n", pTxStats->longRetry6to10); 
	uiPrintf("long  retries 11-15    %10lu\n", pTxStats->longRetry11to15);  */
}

void rxPrintStats
(
 A_UINT32 devNum,
 A_UINT32 rateInMb,
 A_UINT32 remote
)
{
    RX_STATS_STRUCT rStats;

    rxGetStats(devNum, rateInMb, remote, &rStats);

	//check for errors
    if (!getMdkErrNo(devNum)) {
	    printRxStats(&rStats);
    }

}

void printRxStats
(
 RX_STATS_STRUCT *pRxStats
)
{
	uiPrintf("Good Packets           %10lu  ", pRxStats->goodPackets);
	uiPrintf("Data sig strenth min   %10lu\n", pRxStats->DataSigStrengthMin);
	uiPrintf("CRC-Failure Packets    %10lu  ", pRxStats->crcPackets);
	uiPrintf("Data sig strenth avg   %10lu\n", pRxStats->DataSigStrengthAvg);
	uiPrintf("Bad CRC Miscomps       %10lu  ", pRxStats->bitMiscompares);
	uiPrintf("Data sig strenth max   %10lu\n", pRxStats->DataSigStrengthMax);
	uiPrintf("Good Packet Miscomps   %10lu  ", pRxStats->bitErrorCompares);
	uiPrintf("PPM min                %10ld\n", pRxStats->ppmMin);
	uiPrintf("Single dups            %10lu  ", pRxStats->singleDups);
	uiPrintf("PPM avg                %10ld\n", pRxStats->ppmAvg);
	uiPrintf("Multiple dups          %10lu  ", pRxStats->multipleDups);
	uiPrintf("PPM max                %10ld\n", pRxStats->ppmMax);
	return;
}

/**************************************************************************
 * Workaround for HW bug that causes read or write bursts that
 * cross a 256-boundary to access the incorrect register.
 */  
static void
reg_burst_war
(
	A_UINT16 devIndex,
	A_UINT32 offset, 
	A_BOOL op_is_read
)
{
    A_UINT32 offset_lsb;
	MDK_WLAN_DEV_INFO *pdevInfo;
	
    offset_lsb = offset & 0xff;
	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

    // Check if offset is aligned to a 256-byte boundary
    if (offset_lsb == 0) {
      if (last_op_offset_was_fc && (last_op_was_read == op_is_read)) {
         // Last access was to an offset with lsbs of 0xfc and was
         // of the same type (read or write) as the current access, so
         // need to break a possible burst across the 256-byte boundary.
         // Do this by reading the SREV reg, as it's always safe to do so.
         hwMemRead32(devIndex, 0x4020 + pdevInfo->pdkInfo->f2MapAddress);
      }
    }
  
    last_op_was_read = op_is_read;
    last_op_offset_was_fc = (offset_lsb == 0xfc);
}

/**************************************************************************
* OSregRead - MLIB command for reading a register
*
* RETURNS: value read
*/
A_UINT32 OSregRead
(
    A_UINT32 devNum,
    A_UINT32 regOffset
)
{
    A_UINT32         regReturn;
    MDK_WLAN_DEV_INFO    *pdevInfo;
	A_UINT16 devIndex;

	if(devNumValid(devNum) == FALSE) {
		uiPrintf("Error: OSregRead did not receive a valid devNum\n");
	    return(0xdeadbeef);
	}
	devIndex = (A_UINT16)dev2drv(devNum);
   	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

   	/* check that the register is within the range of registers */
	if( (regOffset < pdevInfo->pdkInfo->f2MapAddress) || 
		(regOffset > (MAX_REG_OFFSET + pdevInfo->pdkInfo->f2MapAddress)) ) {
		uiPrintf("Error:  OSregRead Not a valid register offset\n");
		return(0xdeadbeef);
    }

	/* read the register */
	reg_burst_war(devIndex, regOffset, 1);
	regReturn = hwMemRead32(devIndex, regOffset); 
	// uiPrintf("Register at offset %08lx: %08lx\n", regOffset, regReturn);

    return(regReturn);
}

/**************************************************************************
* OSregWrite - MLIB command for writing a register
*
*/
void OSregWrite
(
	A_UINT32 devNum,
    A_UINT32 regOffset,
    A_UINT32 regValue
)
{
    MDK_WLAN_DEV_INFO    *pdevInfo;
	A_UINT16 devIndex;

	if(devNumValid(devNum) == FALSE) {
		uiPrintf("Error: OSregWrite did not receive a valid devNum\n");
		return;
	}
	devIndex = (A_UINT16)dev2drv(devNum);
	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

	if( (regOffset < pdevInfo->pdkInfo->f2MapAddress) || 
		(regOffset > (MAX_REG_OFFSET + pdevInfo->pdkInfo->f2MapAddress)) ) {
		uiPrintf("Error:  OSregWrite Not a valid register offset\n");
		return;
    }

	/* write the register */
	reg_burst_war(devIndex, regOffset, 0);
	hwMemWrite32(devIndex, regOffset, regValue); 
}


/**************************************************************************
* OScfgRead - MLIB command for reading a pci configuration register
*
* RETURNS: value read
*/
A_UINT32 OScfgRead
(
	A_UINT32 devNum,
    A_UINT32 regOffset
)
{
    A_UINT32         regReturn;
	A_UINT16 devIndex;

	if(devNumValid(devNum) == FALSE) {
		uiPrintf("Error: OScfgRead did not receive a valid devNum\n");
	    return(0xdeadbeef);
	}
	devIndex = (A_UINT16)dev2drv(devNum);

	if(regOffset > MAX_CFG_OFFSET) {
		uiPrintf("Error:  OScfgRead: not a valid config offset\n");
		return(0xdeadbeef);
    }
	regReturn = hwCfgRead32(devIndex, regOffset); 

    /* display the value */
    //uiPrintf("%08lx: ", regOffset);
    //uiPrintf("%08lx\n", regReturn);

    return(regReturn);
}

/**************************************************************************
* OScfgWrite - MLIB command for writing a pci config register
*
*/
void OScfgWrite
(
	A_UINT32 devNum,
    A_UINT32 regOffset,
    A_UINT32 regValue
)
{
   A_UINT16 devIndex; 
   
	if(devNumValid(devNum) == FALSE) {
		uiPrintf("Error: OScfgWrite did not receive a valid devNum\n");
		return;
	}

	devIndex = (A_UINT16)dev2drv(devNum);
	
	if(regOffset > MAX_CFG_OFFSET) {
		uiPrintf("Error:  OScfgWrite: not a valid config offset\n");
		return;
    }
	hwCfgWrite32(devIndex, regOffset, regValue); 
}

/**************************************************************************
* OSmemRead - MLIB command to read a block of memory
*
* read a block of memory
*
* RETURNS: An array containing the bytes read
*/
void OSmemRead
(
	A_UINT32 devNum,
    A_UINT32 physAddr, 
	A_UCHAR  *bytesRead,
    A_UINT32 length
)
{
	A_UINT16 devIndex; 

	if(devNumValid(devNum) == FALSE) {
		uiPrintf("Error: OSmemRead did not receive a valid devNum\n");
		return;
	}

    /* check to see if the size will make us bigger than the send buffer */
    if (length > MAX_MEMREAD_BYTES) {
        uiPrintf("Error: OSmemRead length too large, can only read %x bytes\n", MAX_MEMREAD_BYTES);
		return;
    }
	if (bytesRead == NULL) {
        uiPrintf("Error: OSmemRead received a NULL ptr to the bytes to read - please preallocate\n");
		return;
    }

	devIndex = (A_UINT16)dev2drv(devNum);

	if(hwMemReadBlock(devIndex, bytesRead, physAddr, length) == -1) {
		uiPrintf("Error: OSmemRead failed call to hwMemReadBlock()\n");
		return;
	}
}

/**************************************************************************
* OSmemWrite - MLIB command to write a block of memory
*
*/
void OSmemWrite
(
	A_UINT32 devNum,
    A_UINT32 physAddr,
	A_UCHAR  *bytesWrite,
	A_UINT32 length
)
{
	A_UINT16 devIndex; 

	if(devNumValid(devNum) == FALSE) {
		uiPrintf("Error: OSmemWrite did not receive a valid devNum\n");
		return;
	}
    /* check to see if the size will make us bigger than the send buffer */
    if (length > MAX_MEMREAD_BYTES) {
        uiPrintf("Error: OSmemWrite length too large, can only read %x bytes\n", MAX_MEMREAD_BYTES);
		return;
    }
	if (bytesWrite == NULL) {
        uiPrintf("Error: OSmemWrite received a NULL ptr to the bytes to write\n");
		return;	
	}
	devIndex = (A_UINT16)dev2drv(devNum);

	if(hwMemWriteBlock(devIndex,bytesWrite, length, &(physAddr)) == -1) {
			uiPrintf("Error:  OSmemWrite failed call to hwMemWriteBlock()\n");
			return;
    }
}

/**************************************************************************
* getISREvent - MLIB command get latest ISR event
*
*/
ISR_EVENT getISREvent
(
 A_UINT32 devNum
)
{
    MDK_WLAN_DEV_INFO    *pdevInfo;
#if defined(ANWI) || defined(LINUX)
	EVENT_STRUCT pLocEventSpace;
#else
	EVENT_STRUCT *pLocEventSpace;
#endif
	// Initialize event to invalid.
	ISR_EVENT event = {0, 0};
	A_UINT16 devIndex; 

	if(devNumValid(devNum) == FALSE) {
		uiPrintf("Error: getISREvent did not receive a valid devNum\n");
	    return event;
	}
	devIndex = (A_UINT16)dev2drv(devNum);
	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
	

#ifdef JUNGO
    if(checkForEvents(globDrvInfo.triggeredQ)) {
		//call into the kernel plugin to get the event
		if((pLocEventSpace = popEvent(globDrvInfo.triggeredQ)) != NULL) {
			if(pLocEventSpace->type == ISR_INTERRUPT) {
				event.valid = 1;
				event.ISRValue = pLocEventSpace->result;
			}
			else {
				uiPrintf("Error: getISREvent - found a non-ISR event in a client - is this possible???\n");
				uiPrintf("If this has become a possibility... then remove this error check\n");
			}
		}
		else {
			uiPrintf("Error: getISREvent Unable to get event\n");
		}
	}
#endif
#if defined(ANWI) || defined (LINUX)
	if (getNextEvent(devIndex, &pLocEventSpace)) {
		if(pLocEventSpace.type == ISR_INTERRUPT) {
				event.valid = 1;
				event.ISRValue = pLocEventSpace.result[0];
		}	
	}
#endif
	return(event);
}

/**************************************************************************
* setupDevice - initialization call to ManLIB
*
* RETURNS: devNum or -1 if fail
*/
A_INT32 setupDevice
(
 A_UINT32 whichDevice
)
{
	static DEVICE_MAP devMap;
    MDK_WLAN_DEV_INFO    *pdevInfo;
    A_UINT32 devNum;
    EVT_HANDLE  eventHdl;
	A_UINT16 devIndex;

 	if ( whichDevice > WLAN_MAX_DEV ) {
		/* don't have a large enough array to accommodate this device */
		uiPrintf("Error: devInfo array not large enough, only support %d devices\n", WLAN_MAX_DEV);
	    return -1;
	}


    devIndex = (A_UINT16)(whichDevice - 1);
	if ( A_FAILED( deviceInit(devIndex) ) ) {
		uiPrintf("setupDevice Error: Failed call to local deviceInit()!\n");
	    return -1;
	}
	pdevInfo = globDrvInfo.pDevInfoArray[devIndex];

    // Finally, setup the library mapping
	devMap.DEV_CFG_ADDRESS = 0;
	devMap.DEV_CFG_RANGE = MAX_CFG_OFFSET;
#if defined(ANWI) || defined (LINUX)
	devMap.DEV_MEMORY_ADDRESS = (unsigned long) pdevInfo->pdkInfo->memPhyAddr;
#endif
#ifdef JUNGO
	devMap.DEV_MEMORY_ADDRESS = (unsigned long) pdevInfo->pdkInfo->dma.Page[0].pPhysicalAddr;
#endif
	devMap.DEV_MEMORY_RANGE = pdevInfo->pdkInfo->memSize; 
	devMap.DEV_REG_ADDRESS = pdevInfo->pdkInfo->f2MapAddress;
	devMap.DEV_REG_RANGE = 65536;
	devMap.OScfgRead = OScfgRead;
	devMap.OScfgWrite = OScfgWrite;
	devMap.OSmemRead = OSmemRead;
	devMap.OSmemWrite = OSmemWrite;
	devMap.OSregRead = OSregRead;
	devMap.OSregWrite = OSregWrite;
	devMap.getISREvent = getISREvent;
	devMap.devIndex = devIndex;
	devNum = initializeDevice(devMap);

    if(devNum > WLAN_MAX_DEV) {
        uiPrintf("setupDevice Error: Manlib Failed to initialize for this Device\n");
        return -1;
    }
   	devNum2driverTable[devNum] = devIndex;

    // assign the handle (id, actually) that will be sent back to Perl to uniquely
    eventHdl.eventID = 0;
    eventHdl.f2Handle = (A_UINT16)devNum;

	if(!pdevInfo->pdkInfo->haveEvent) {
        if(hwCreateEvent(devIndex, ISR_INTERRUPT, 1, 0, 0, 0, eventHdl) == -1) {
            uiPrintf("setupDevice Error: Could not initalize driver ISR events\n");
            teardownDevice(devNum);
            return -1;
        }
		pdevInfo->pdkInfo->haveEvent = TRUE;
	}

    return devNum;
}

void teardownDevice
(
 A_UINT32 devNum
) 
{
    if(devNumValid(devNum) == FALSE) {
		uiPrintf("Error: teardownDevice did not receive a valid devNum\n");
	    return;
	}

    // Close the Manufacturing Lib
    closeDevice(devNum);
    // Close the driver Jungo driver entries
    deviceCleanup((A_UINT16)dev2drv(devNum));
	
}

⌨️ 快捷键说明

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