📄 mld_anwi.c
字号:
* Perform the initialization needed for a device. This includes creating a
* devInfo structure and initializing its contents
*
* RETURNS: A_OK if successful, A_ERROR if not
*/
A_STATUS deviceInit
(
A_UINT16 devIndex /* index of globalDrvInfo which to add device to */
)
{
MDK_WLAN_DEV_INFO *pdevInfo;
A_UINT32 regValue;
anwiOutClientInfo cliInfo;
#ifndef LEGACY
HANDLE hDevice;
#endif
/* check to see if we already have a devInfo structure created for this device */
if (globDrvInfo.pDevInfoArray[devIndex]) {
uiPrintf("Error : Device already in use \n");
return A_ERROR;
}
pdevInfo = (MDK_WLAN_DEV_INFO *) A_MALLOC(sizeof(MDK_WLAN_DEV_INFO));
if(!pdevInfo) {
uiPrintf("Error: Unable to allocate MDK_WLAN_DEV_INFO struct!\n");
return(A_ERROR);
}
pdevInfo->pdkInfo = (DK_DEV_INFO *) A_MALLOC(sizeof(DK_DEV_INFO));
if(!pdevInfo->pdkInfo) {
A_FREE(pdevInfo);
uiPrintf("Error: Unable to allocate DK_DEV_INFO struct!\n");
return A_ERROR;
}
/* zero out the dkInfo struct */
A_MEM_ZERO(pdevInfo->pdkInfo, sizeof(DK_DEV_INFO));
#ifdef LEGACY
if (!RegisterClient(devIndex,&cliInfo)) {
uiPrintf("Error: Unable to register client with the driver \n");
A_FREE(pdevInfo->pdkInfo);
A_FREE(pdevInfo);
return A_ERROR;
}
pdevInfo->cliId = cliInfo.cliId;
#else
hDevice = getDeviceViaInterface((LPGUID)&ANWI_GUID,devIndex);
if (hDevice == INVALID_HANDLE_VALUE) {
uiPrintf("Error: Failed to obtain file handle to device \n");
return A_ERROR;
}
if (getClientInfo(hDevice,&cliInfo) < 0) {
uiPrintf("Unable to get client info \n");
CloseHandle(hDevice);
return A_ERROR;
}
pdevInfo->hDevice = hDevice;
#endif
pdevInfo->pdkInfo->f2Mapped = 1;
pdevInfo->pdkInfo->devIndex = devIndex;
pdevInfo->pdkInfo->f2MapAddress = cliInfo.regPhyAddr;
pdevInfo->pdkInfo->regMapRange = cliInfo.regRange;
pdevInfo->pdkInfo->regVirAddr = cliInfo.regVirAddr;
pdevInfo->pdkInfo->memPhyAddr = cliInfo.memPhyAddr;
pdevInfo->pdkInfo->memVirAddr = cliInfo.memVirAddr;
pdevInfo->pdkInfo->memSize = cliInfo.memSize;
q_uiPrintf("+ Allocated memory in the driver.\n");
q_uiPrintf("+ VirtAddress = %08x\n", (A_UINT32)(pdevInfo->pdkInfo->memPhyAddr));
q_uiPrintf("+ PhysAddress = %08x\n", (A_UINT32)(pdevInfo->pdkInfo->memVirAddr));
globDrvInfo.pDevInfoArray[devIndex] = pdevInfo;
globDrvInfo.devCount++;
// Setup memory window, bus mastering, & SERR
regValue = hwCfgRead32(devIndex, F2_PCI_CMD);
regValue |= (MEM_ACCESS_ENABLE | MASTER_ENABLE | SYSTEMERROR_ENABLE);
regValue &= ~MEM_WRITE_INVALIDATE; // Disable write & invalidate for our device
hwCfgWrite32(devIndex, F2_PCI_CMD, regValue);
regValue = hwCfgRead32(devIndex, F2_PCI_CACHELINESIZE);
regValue = (regValue & 0xffff) | (0x40 << 8) | 0x08;
hwCfgWrite32(devIndex, F2_PCI_CACHELINESIZE, regValue);
return A_OK;
}
/**************************************************************************
* deviceCleanup - performs any memory cleanup needed for a device
*
* Perform any cleanup needed for a device. This includes deleting any
* memory allocated by a device, and unregistering the card with the driver
*
* RETURNS: 1 if successful, 0 if not
*/
void deviceCleanup
(
A_UINT16 devIndex
)
{
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
// disable the interrupts from the hardware
hwMemWrite32(devIndex, pdevInfo->pdkInfo->f2MapAddress + F2_IER, F2_IER_DISABLE);
// place the hardware into reset to quiesce all transfers
hwMemWrite32(devIndex, pdevInfo->pdkInfo->f2MapAddress + F2_RC, (F2_RC_PCI | F2_RC_F2 | F2_RC_D2 |
F2_RC_DMA | F2_RC_PCU) );
#ifdef LEGACY
unRegisterClient(pdevInfo->cliId);
#else
CloseHandle(pdevInfo->hDevice);
#endif
/* free the DK_DEV_INFO struct */
A_FREE(pdevInfo->pdkInfo);
A_FREE(pdevInfo);
globDrvInfo.pDevInfoArray[devIndex] = NULL;
globDrvInfo.devCount--;
}
/**************************************************************************
* driverOpen - Only needed in NT_HW environment to open comms with driver
*
* Called within the NT_HW environment. Opens and gets a handle to the
* driver for doing the hardware access.
*
* RETURNS: 1 if OK and driver open, 0 if not
*/
A_UINT16 driverOpen()
{
// Opening a handle to the device.
#ifdef LEGACY
hDriver = CreateFile ("\\\\.\\Anwiwdm",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL );
if (hDriver == INVALID_HANDLE_VALUE) {
printf("Failed to obtain file handle to device: %d", GetLastError() );
return 0;
}
#endif
return 1;
}
/**************************************************************************
* checkRegSpace - Check to see if an address sits in the setup register space
*
* This internal routine checks to see if an address lies in the register space
*
* RETURNS: A_OK to signify a valid address or A_ENOENT
*/
A_STATUS checkRegSpace
(
MDK_WLAN_DEV_INFO *pdevInfo,
A_UINT32 address
)
{
if((address >= pdevInfo->pdkInfo->f2MapAddress) &&
(address < pdevInfo->pdkInfo->f2MapAddress + pdevInfo->pdkInfo->regMapRange))
return A_OK;
else
return A_ENOENT;
}
/**************************************************************************
* checkMemSpace - Check to see if an address sits in the setup physical memory space
*
* This internal routine checks to see if an address lies in the physical memory space
*
* RETURNS: A_OK to signify a valid address or A_ENOENT
*/
A_STATUS checkMemSpace
(
MDK_WLAN_DEV_INFO *pdevInfo,
A_UINT32 address
)
{
if((address >= (A_UINT32)pdevInfo->pdkInfo->memPhyAddr) &&
(address < (A_UINT32)((A_UCHAR *)(pdevInfo->pdkInfo->memPhyAddr) + pdevInfo->pdkInfo->memSize)))
return A_OK;
else
return A_ENOENT;
}
/**************************************************************************
* hwCfgRead32 - read an 32 bit value
*
* This routine will call into the driver
* 32 bit PCI configuration read.
*
* RETURNS: the value read
*/
A_UINT32 hwCfgRead32
(
A_UINT16 devIndex,
A_UINT32 offset /* the address to read from */
)
{
A_BOOL status;
A_UINT32 bR = 0;
anwiReturnContext returnContext;
anwiDevOpStruct inStruct;
pAnwiDevOpStruct pOutStruct;
A_UINT32 data;
HANDLE hnd;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
#ifdef LEGACY
inStruct.cliId = pdevInfo->cliId;
#endif
inStruct.opType = ANWI_CFG_READ;
inStruct.param1 = offset;
#ifdef LEGACY
inStruct.param2 = 0;
#else
inStruct.param2 = 4;
inStruct.param3 = 0;
#endif
#ifdef LEGACY
hnd = hDriver;
#else
hnd = pdevInfo->hDevice;
#endif
status = DeviceIoControl (hnd,
IOCTL_ANWI_DEV_OP,
&inStruct,
sizeof(anwiDevOpStruct),
&returnContext,
sizeof(anwiReturnContext),
&bR,
NULL);
if ((!status) || (returnContext.returnCode != ANWI_OK)) {
printf("Error returned by DEV_OP DeviceIoControl call \n");
return 0xdeadbeef;
}
if (returnContext.contextLen != sizeof(anwiDevOpStruct)) {
printf("Return size (%d) from DEV_OP DeviceIoControl call doesnt match the expected size (%d) \n",returnContext.contextLen,sizeof(anwiDevOpStruct));
return 0xdeadbeef;
}
pOutStruct = (pAnwiDevOpStruct) returnContext.context;
data = pOutStruct->param1;
// printf("Cfg read at %x : %x \n",offset,data);
return data;
}
/**************************************************************************
* hwCfgWrite32 - write a 32 bit value
*
* This routine will call into the driver to activate a
* 32 bit PCI configuration write.
*
* RETURNS: N/A
*/
void hwCfgWrite32
(
A_UINT16 devIndex,
A_UINT32 offset, /* the address to write */
A_UINT32 value /* value to write */
)
{
A_BOOL status;
A_UINT32 bR = 0;
anwiReturnContext returnContext;
anwiDevOpStruct inStruct;
HANDLE hnd;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
#ifdef LEGACY
inStruct.cliId = pdevInfo->cliId;
#endif
inStruct.opType = ANWI_CFG_WRITE;
inStruct.param1 = offset;
#ifdef LEGACY
inStruct.param2 = value;
#else
inStruct.param2 = 4;
inStruct.param3 = value;
#endif
#ifdef LEGACY
hnd = hDriver;
#else
hnd = pdevInfo->hDevice;
#endif
status = DeviceIoControl (hnd,
IOCTL_ANWI_DEV_OP,
&inStruct,
sizeof(anwiDevOpStruct),
&returnContext,
sizeof(anwiReturnContext),
&bR,
NULL);
if ((!status) || (returnContext.returnCode != ANWI_OK)) {
printf("Error returned by DEV_OP DeviceIoControl call \n");
return;
}
if (returnContext.contextLen != sizeof(anwiDevOpStruct)) {
printf("Return size (%d) from DEV_OP DeviceIoControl call doesnt match the expected size (%d) \n",returnContext.contextLen,sizeof(anwiDevOpStruct));
return;
}
return;
}
/**************************************************************************
* hwMemRead32 - read an 32 bit value
*
* This routine will call into the simulation environment to activate a
* 32 bit PCI memory read cycle, value read is returned to caller
*
* RETURNS: the value read
*/
A_UINT32 hwMemRead32
(
A_UINT16 devIndex,
A_UINT32 address /* the address to read from */
)
{
A_UINT32 *pMem;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
// check within the register regions
if (A_OK == checkRegSpace(pdevInfo, address))
{
pMem = (A_UINT32 *) (pdevInfo->pdkInfo->regVirAddr + (address - pdevInfo->pdkInfo->f2MapAddress));
return(*pMem);
}
//check within memory allocation
if(A_OK == checkMemSpace(pdevInfo, address))
{
pMem = (A_UINT32 *) (pdevInfo->pdkInfo->memVirAddr +
(address - pdevInfo->pdkInfo->memPhyAddr));
return(*pMem);
}
uiPrintf("ERROR: hwMemRead32 could not access hardware address: %08lx\n", address);
return (0xdeadbeef);
}
/**************************************************************************
* hwMemWrite32 - write a 32 bit value
*
* This routine will call into the simulation environment to activate a
* 32 bit PCI memory write cycle
*
* RETURNS: N/A
*/
void hwMemWrite32
(
A_UINT16 devIndex,
A_UINT32 address, /* the address to write */
A_UINT32 value /* value to write */
)
{
A_UINT32 *pMem;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
// check within the register regions
if (A_OK == checkRegSpace(pdevInfo, address))
{
pMem = (A_UINT32 *) (pdevInfo->pdkInfo->regVirAddr + (address - pdevInfo->pdkInfo->f2MapAddress));
*pMem = value;
return;
}
// check within our malloc area
if(A_OK == checkMemSpace(pdevInfo, address))
{
pMem = (A_UINT32 *) (pdevInfo->pdkInfo->memVirAddr +
(address - pdevInfo->pdkInfo->memPhyAddr));
*pMem = value;
return;
}
uiPrintf("ERROR: hwMemWrite32 could not access hardware address: %08lx\n", address);
}
/**************************************************************************
* hwCreateEvent - Handle event creation within windows environment
*
* Create an event within windows environment
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwCreateEvent
(
A_UINT16 devIndex,
A_UINT32 type,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -