?? art_if.c
字號:
/* art_if.c - contains the ART wrapper functions */
/* Copyright (c) 2000 Atheros Communications, Inc., All Rights Reserved */
#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
#include <bios.h>
#include "dk_structures.h"
#include "dk_common.h"
#include "common_hwext.h"
#endif // #ifdef __ATH_DJGPPDOS__
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "wlantype.h"
#include "wlanproto.h"
#include "athreg.h"
#include "manlib.h"
#include "test.h"
#include "dk_cmds.h"
#include "art_if.h"
#include "art_ani.h"
#ifndef __ATH_DJGPPDOS__
#include "MLIBif.h"
#ifdef LINUX
#include "sock_linux.h"
#else
#include "sock_win.h"
#endif
#else
#include "mlibif_dos.h"
#endif
#include "misc_routines.h"
//** the following added by ccshiang
#include "..\..\..\..\AgN4010WSODrv\AgN4010WSOAPI.h"
#include "..\..\..\..\ART.Common\AgiGlobalDefs.h"
//** the above added by ccshiang
extern A_BOOL thin_client;
extern A_BOOL usb_client;
extern A_BOOL sdio_client;
extern A_UINT32 sent_bytes;
extern A_UINT32 received_bytes;
extern MLD_CONFIG configSetup;
extern A_BOOL printLocalInfo;
// extern declarations for dut-golden sync
extern ART_SOCK_INFO *artSockInfo;
extern ART_SOCK_INFO *pArtPrimarySock;
extern ART_SOCK_INFO *pArtSecondarySock;
static A_UINT32 globalNumInstances = 0;
extern void *artConnect(void);
extern A_BOOL prepare2WayComms
(
void
);
extern void cleanupSockMem
(
void* pOSSock,
A_BOOL closeSocket
);
// Error number and error string
A_INT32 art_mdkErrNo = 0;
A_CHAR art_mdkErrStr[SIZE_ERROR_BUFFER];
// Remote error number and error string
A_INT32 remoteMdkErrNo = 0;
A_CHAR remoteMdkErrStr[SIZE_ERROR_BUFFER];
//static A_BOOL ownSocketClose = 0;
// holds the cmd replies sent over channel
PIPE_CMD GlobalCmd;
CMD_REPLY cmdReply;
// forward function declaration
ART_SOCK_INFO *openCommsChannel(A_CHAR *machineName);
A_BOOL artSendCmd(PIPE_CMD *pCmdStruct,A_UINT32 cmdSize,void **returnCmdStruct);
A_BOOL receiveCmdReturn(A_UINT32 *pReturnLength);
A_UINT32 art_createEvent(A_UINT32 devNum,A_UINT32 type, A_UINT32 persistent,
A_UINT32 param1,A_UINT32 param2,A_UINT32 param3);
A_INT32 art_setupDevice(A_UINT32 whichDevice)
{
A_UINT32 devNum;
A_UINT32 *pRegValue;
DK_DEV_INFO *pdkInfo=NULL;
A_UINT32 bootRomVer, bootRomMajVer, bootRomMinVer;
//at setup time, remote flag being set, applies to primary ART session being AP
if (configSetup.remote)
{
if(pArtPrimarySock == NULL) {
//printf("****Machine Name :%s ********\n",configSetup.machName);
artSockInfo = openCommsChannel(configSetup.machName);
pArtPrimarySock = artSockInfo;
if (artSockInfo == NULL) {
uiPrintf("Error: Unable to open communications channel to AP!\n");
return -1;
}
}
if (strnicmp(configSetup.machName, "USB", 3) == 0) {
whichDevice += USB_FN_DEV_START_NUM;
}
//if (thin_client)
GlobalCmd.devNum = (A_UINT8)getNextDevNum();
globalNumInstances++;
GlobalCmd.cmdID = INIT_F2_CMD_ID;
GlobalCmd.CMD_U.INIT_F2_CMD.whichF2 = whichDevice;
if (!artSendCmd(&GlobalCmd,
sizeof(GlobalCmd.CMD_U.INIT_F2_CMD) + sizeof(GlobalCmd.cmdID),
(void **)&pRegValue) )
{
uiPrintf("Error: Unable to send command to client! Handle not created.\n");
return -1;
}
devNum = *pRegValue & 0x0fffffff;
thin_client = (A_BOOL)((*pRegValue) >> 28);
configSetup.remote_exec = !thin_client;
if (!configSetup.remote_exec) {
pdkInfo = (DK_DEV_INFO *)(pRegValue+1);
#ifndef __ATH_DJGPPDOS__
devNum= setupDevice(whichDevice, pdkInfo, configSetup.remote);
#else
devNum= setupDevice(whichDevice);
#endif
if (devNum == -1) {
uiPrintf("art_setupDevice::Error: invalid devNum from setupDevice\n");
return -1;
}
bootRomVer = (art_ap_reg_read(devNum, 0xbfc00878) & 0xffff);
bootRomMajVer = bootRomVer >> 8;
bootRomMinVer = bootRomVer & 0xff;
uiPrintf("Boot rom version %x.%x\n", bootRomMajVer, bootRomMinVer);
art_createEvent(devNum, ISR_INTERRUPT, 1, 0, 0, 0);
}
}
if (!configSetup.remote)
{
#ifndef __ATH_DJGPPDOS__
devNum= setupDevice(whichDevice, pdkInfo, configSetup.remote);
#else
devNum= setupDevice(whichDevice);
#endif
if (devNum == -1) {
return -1;
}
}
if(checkLibError(devNum, 1)) {
return -1;
}
return devNum;
}
//#ifndef __ATH_DJGPPDOS__
/**************************************************************************
* create_event - Create an event
*
* RETURNS: The event handle for the event.
*/
A_UINT32 art_createEvent
(
A_UINT32 devNum,
A_UINT32 type,
A_UINT32 persistent,
A_UINT32 param1,
A_UINT32 param2,
A_UINT32 param3
)
{
EVT_HANDLE eventHdl;
A_UINT16 devIndex;
// check to see if we have a valid type
if (ISR_INTERRUPT != type)
{
uiPrintf("Error: Illegal event type\n");
return 0xffffffff;
}
eventHdl.eventID = 0;
eventHdl.f2Handle = (A_UINT16)devNum;
if (!configSetup.remote)
{
devIndex = (A_UINT16)dev2drv(devNum);
#ifndef __ATH_DJGPPDOS__
if (!hwCreateEvent(devIndex, ISR_INTERRUPT, 1, 0, 0, 0, eventHdl)) return 0xffffffff;
#endif
}
else
{
GlobalCmd.devNum = (A_INT8) devNum;
// create cmd to send
GlobalCmd.cmdID = CREATE_EVENT_CMD_ID;
GlobalCmd.CMD_U.CREATE_EVENT_CMD.type = type;
GlobalCmd.CMD_U.CREATE_EVENT_CMD.persistent = persistent;
GlobalCmd.CMD_U.CREATE_EVENT_CMD.param1 = param1;
GlobalCmd.CMD_U.CREATE_EVENT_CMD.param2 = param2;
GlobalCmd.CMD_U.CREATE_EVENT_CMD.param3 = param3;
GlobalCmd.CMD_U.CREATE_EVENT_CMD.eventHandle = eventHdl;
if (!artSendCmd(&GlobalCmd,
sizeof(GlobalCmd.CMD_U.CREATE_EVENT_CMD)+sizeof(GlobalCmd.cmdID),
NULL))
{
uiPrintf("Error: Unable to successfully send CREATE_EVENT command to client!\n");
return 0xffffffff;
}
}
return 0;
}
//#endif
/**************************************************************************
* cfg_read - User interface command for reading a pci configuration register
*
*
* RETURNS: value read
*/
A_UINT32 art_cfgRead
(
A_UINT32 devNum,
A_UINT32 regOffset
)
{
A_UINT32 *pRegValue, regReturn;
A_UINT16 devIndex;
devIndex = (A_UINT16)dev2drv(devNum);
//uiPrintf("SNOOP::art_cfgRead\n");
if(!configSetup.remote)
{
if (thin_client) {
#ifndef __ATH_DJGPPDOS__
regReturn = hwCfgRead32(devIndex, regOffset);
#endif
}
else {
regReturn = OScfgRead(devNum, regOffset);
}
pRegValue = ®Return;
}
else
{
/* create cmd structure and send command */
GlobalCmd.devNum = (A_INT8) devNum;
GlobalCmd.cmdID = CFG_READ_CMD_ID;
GlobalCmd.CMD_U.CFG_READ_CMD.cfgReadAddr = regOffset;
GlobalCmd.CMD_U.CFG_READ_CMD.readSize = 32;
if(!artSendCmd(&GlobalCmd,
sizeof(GlobalCmd.CMD_U.CFG_READ_CMD)+sizeof(GlobalCmd.cmdID),
(void **)&pRegValue))
{
uiPrintf("Error: Unable to successfully send CFG_READ command\n");
return 0xdeadbeef;
}
}
return(*pRegValue);
}
/**************************************************************************
* cfg_write - User interface command for writing a configuration register
*
*
* RETURNS: 1 if OK, 0 if error
*/
A_UINT32 art_cfgWrite
(
A_UINT32 devNum,
A_UINT32 regOffset,
A_UINT32 regValue
)
{
A_UINT16 devIndex = (A_UINT16)dev2drv(devNum);
// uiPrintf("SNOOP::art_cfgWrite\n");
if (!configSetup.remote)
{
#ifndef __ATH_DJGPPDOS__
hwCfgWrite32(devIndex, regOffset, regValue);
#else
OScfgWrite(devNum,regOffset,regValue );
#endif
}
else
{
GlobalCmd.devNum = (A_INT8) devNum;
/* create cmd structure and send command */
GlobalCmd.cmdID = CFG_WRITE_CMD_ID;
GlobalCmd.CMD_U.CFG_WRITE_CMD.cfgWriteAddr = regOffset;
GlobalCmd.CMD_U.CFG_WRITE_CMD.cfgValue = regValue;
GlobalCmd.CMD_U.CFG_WRITE_CMD.writeSize = 32;
if(!artSendCmd(&GlobalCmd,
sizeof(GlobalCmd.CMD_U.CFG_WRITE_CMD)+sizeof(GlobalCmd.cmdID),
NULL))
{
uiPrintf("Error: Unable to successfully send CFG_WRITE command\n");
return 0;
}
}
return 1;
}
A_UINT32 mem_read_block_2048
(
A_UINT32 devNum,
A_UINT32 physAddr,
A_UINT32 length,
A_UCHAR *buf
)
{
A_UINT32 *pReadValues;
A_UINT16 devIndex = (A_UINT16)dev2drv(devNum);
/* check to see if the size will make us bigger than the send buffer */
if (length > MAX_BLOCK_BYTES) {
uiPrintf("Error: block size too large, can only write %x bytes\n", MAX_BLOCK_BYTES);
return(0);
}
if (!configSetup.remote) {
/* read the memory */
#ifndef __ATH_DJGPPDOS__
if(hwMemReadBlock(devIndex, buf, physAddr, length) == -1) {
uiPrintf("Failed call to hwMemWriteBlock()\n");
return(0);
}
#else
uiPrintf(" Not Implemeted in DOS Version \n");
#endif
} else {
GlobalCmd.devNum = (A_INT8) devNum;
/* create cmd structure and send command */
GlobalCmd.cmdID = MEM_READ_BLOCK_CMD_ID;
GlobalCmd.CMD_U.MEM_READ_BLOCK_CMD.physAddr = physAddr;
GlobalCmd.CMD_U.MEM_READ_BLOCK_CMD.length = length;
if(!artSendCmd(&GlobalCmd,
sizeof(GlobalCmd.CMD_U.MEM_READ_BLOCK_CMD)+sizeof(GlobalCmd.cmdID),
(void **)&pReadValues))
{
uiPrintf("Error: Unable to successfully send MEM_READ_BLOCK command to addr %x for % bytes\n", physAddr, length);
return 0;
}
memcpy(buf, pReadValues, length);
}
return(1);
}
/**************************************************************************
* mem_read - Command for read a block of memory
*
* RETURNS: value write
*/
A_UINT32 art_memRead
(
A_UINT32 devNum,
A_UINT32 physAddr,
A_UCHAR *bytesRead,
A_UINT32 length
)
{
A_UINT16 devIndex;
A_UINT32 ii, startAddr_ii, len_ii, arrayStart_ii;
A_UINT32 retAddr=0;
//uiPrintf("SNOOP::art_memRead:physAddr=%x:length=%d\n", physAddr, length);
devIndex = (A_UINT16)dev2drv(devNum);
// Split the writes into blocks of 2048 bytes only if the memory is already allocated
ii = length;
startAddr_ii= physAddr;
arrayStart_ii=0;
while( ii > 0)
{
if(ii > MAX_MEM_CMD_BLOCK_SIZE) {
len_ii = MAX_MEM_CMD_BLOCK_SIZE;
} else {
len_ii = ii;
}
if (!mem_read_block_2048(devNum, startAddr_ii, len_ii, ((A_UCHAR *)bytesRead+arrayStart_ii))) {
bytesRead = NULL;
}
startAddr_ii += len_ii;
ii -= len_ii;
arrayStart_ii += len_ii;
}
return 1;
}
A_UINT32 art_memAlloc
(
A_UINT32 allocSize, /* how many bytes to allocate */
A_UINT32 physAddr, /* requested physical address */
A_UINT32 devNum /* optionally change select new F2 */
)
{
A_UINT32 *pAllocatedAddr, realAddr;
A_UINT16 devIndex;
devIndex = (A_UINT16)dev2drv(devNum);
pAllocatedAddr = &realAddr;
if (thin_client) {
realAddr = memAlloc(devNum, allocSize);
}
else {
if(!configSetup.remote || !configSetup.remote_exec) {
/* do the allocation */
#ifndef __ATH_DJGPPDOS__
realAddr = memAlloc(devNum, allocSize);
/* if(hwGetPhysMem(devIndex, allocSize, &realAddr) == NULL) {
return(0);
}
*/
#else
uiPrintf("Not Implemented in DOS Version\n");
#endif
} else {
GlobalCmd.devNum = (A_INT8) devNum;
/* create the command structure for alloc */
GlobalCmd.cmdID = MEM_ALLOC_CMD_ID;
GlobalCmd.CMD_U.MEM_ALLOC_CMD.allocSize = allocSize;
GlobalCmd.CMD_U.MEM_ALLOC_CMD.physAddr = physAddr;
if(!artSendCmd(&GlobalCmd, sizeof(GlobalCmd.CMD_U.MEM_ALLOC_CMD)+sizeof(GlobalCmd.cmdID),
(void **)&pAllocatedAddr)) {
uiPrintf("Error: Unable to successfully send MEM_ALLOC command\n");
return(0);
}
}
}
// q_uiPrintf("Memory allocated at physical address %08lx\n", *pAllocatedAddr);
/* no longer need to pass virtual address back to user, or keep it */
return(*pAllocatedAddr);
}
void art_memFree ( A_UINT32 fAddr, A_UINT32 devNum ) {
if (thin_client) {
memFree(devNum, fAddr);
}
}
void art_memFreeAll ( A_UINT32 devNum ) {
if (thin_client) {
memFreeAll(devNum);
}
}
A_UINT32 mem_write_block_2048
(
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -