2008-10-01 12:36:56 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) 1996-2002 Winbond Electronic Corporation
|
|
|
|
//
|
|
|
|
// Module Name:
|
|
|
|
// Wb35Rx.c
|
|
|
|
//
|
|
|
|
// Abstract:
|
|
|
|
// Processing the Rx message from down layer
|
|
|
|
//
|
|
|
|
//============================================================================
|
2008-10-30 11:04:29 +00:00
|
|
|
#include <linux/usb.h>
|
|
|
|
|
2008-10-30 14:14:39 +00:00
|
|
|
#include "core.h"
|
2008-10-01 12:36:56 +00:00
|
|
|
#include "sysdef.h"
|
2008-10-30 11:04:29 +00:00
|
|
|
#include "wb35rx_f.h"
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-30 14:14:39 +00:00
|
|
|
void Wb35Rx_start(struct ieee80211_hw *hw)
|
2008-10-01 12:36:56 +00:00
|
|
|
{
|
2008-10-30 14:14:39 +00:00
|
|
|
struct wbsoft_priv *priv = hw->priv;
|
|
|
|
phw_data_t pHwData = &priv->sHwData;
|
2008-10-01 12:36:56 +00:00
|
|
|
PWB35RX pWb35Rx = &pHwData->Wb35Rx;
|
|
|
|
|
|
|
|
// Allow only one thread to run into the Wb35Rx() function
|
2008-10-29 18:10:32 +00:00
|
|
|
if (atomic_inc_return(&pWb35Rx->RxFireCounter) == 1) {
|
2008-10-01 12:36:56 +00:00
|
|
|
pWb35Rx->EP3vm_state = VM_RUNNING;
|
2008-10-30 14:14:39 +00:00
|
|
|
Wb35Rx(hw);
|
2008-10-01 12:36:56 +00:00
|
|
|
} else
|
2008-10-29 18:10:32 +00:00
|
|
|
atomic_dec(&pWb35Rx->RxFireCounter);
|
2008-10-01 12:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This function cannot reentrain
|
2008-10-30 14:14:39 +00:00
|
|
|
void Wb35Rx(struct ieee80211_hw *hw)
|
2008-10-01 12:36:56 +00:00
|
|
|
{
|
2008-10-30 14:14:39 +00:00
|
|
|
struct wbsoft_priv *priv = hw->priv;
|
|
|
|
phw_data_t pHwData = &priv->sHwData;
|
2008-10-01 12:36:56 +00:00
|
|
|
PWB35RX pWb35Rx = &pHwData->Wb35Rx;
|
2008-10-20 21:03:41 +00:00
|
|
|
u8 * pRxBufferAddress;
|
2008-10-22 08:01:16 +00:00
|
|
|
struct urb *urb = pWb35Rx->RxUrb;
|
2008-10-01 12:36:56 +00:00
|
|
|
int retv;
|
|
|
|
u32 RxBufferId;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Issuing URB
|
|
|
|
//
|
2008-10-21 09:14:58 +00:00
|
|
|
if (pHwData->SurpriseRemove || pHwData->HwStop)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (pWb35Rx->rx_halt)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
// Get RxBuffer's ID
|
|
|
|
RxBufferId = pWb35Rx->RxBufferId;
|
|
|
|
if (!pWb35Rx->RxOwner[RxBufferId]) {
|
|
|
|
// It's impossible to run here.
|
|
|
|
#ifdef _PE_RX_DUMP_
|
|
|
|
WBDEBUG(("Rx driver fifo unavailable\n"));
|
|
|
|
#endif
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update buffer point, then start to bulkin the data from USB
|
|
|
|
pWb35Rx->RxBufferId++;
|
|
|
|
pWb35Rx->RxBufferId %= MAX_USB_RX_BUFFER_NUMBER;
|
|
|
|
|
|
|
|
pWb35Rx->CurrentRxBufferId = RxBufferId;
|
|
|
|
|
2008-10-27 20:47:12 +00:00
|
|
|
pWb35Rx->pDRx = kzalloc(MAX_USB_RX_BUFFER, GFP_ATOMIC);
|
|
|
|
if (!pWb35Rx->pDRx) {
|
2008-10-21 09:14:58 +00:00
|
|
|
printk("w35und: Rx memory alloc failed\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
pRxBufferAddress = pWb35Rx->pDRx;
|
|
|
|
|
2008-10-22 08:01:16 +00:00
|
|
|
usb_fill_bulk_urb(urb, pHwData->WbUsb.udev,
|
2008-10-21 09:14:58 +00:00
|
|
|
usb_rcvbulkpipe(pHwData->WbUsb.udev, 3),
|
|
|
|
pRxBufferAddress, MAX_USB_RX_BUFFER,
|
2008-10-30 14:14:39 +00:00
|
|
|
Wb35Rx_Complete, hw);
|
2008-10-21 09:14:58 +00:00
|
|
|
|
|
|
|
pWb35Rx->EP3vm_state = VM_RUNNING;
|
|
|
|
|
2008-10-27 21:21:24 +00:00
|
|
|
retv = usb_submit_urb(urb, GFP_ATOMIC);
|
2008-10-21 09:14:58 +00:00
|
|
|
|
|
|
|
if (retv != 0) {
|
|
|
|
printk("Rx URB sending error\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2008-10-01 12:36:56 +00:00
|
|
|
// VM stop
|
|
|
|
pWb35Rx->EP3vm_state = VM_STOP;
|
2008-10-29 18:10:32 +00:00
|
|
|
atomic_dec(&pWb35Rx->RxFireCounter);
|
2008-10-01 12:36:56 +00:00
|
|
|
}
|
|
|
|
|
2008-10-22 08:01:16 +00:00
|
|
|
void Wb35Rx_Complete(struct urb *urb)
|
2008-10-01 12:36:56 +00:00
|
|
|
{
|
2008-10-30 14:14:39 +00:00
|
|
|
struct ieee80211_hw *hw = urb->context;
|
|
|
|
struct wbsoft_priv *priv = hw->priv;
|
|
|
|
phw_data_t pHwData = &priv->sHwData;
|
2008-10-01 12:36:56 +00:00
|
|
|
PWB35RX pWb35Rx = &pHwData->Wb35Rx;
|
2008-10-20 21:03:41 +00:00
|
|
|
u8 * pRxBufferAddress;
|
2008-10-01 12:36:56 +00:00
|
|
|
u32 SizeCheck;
|
|
|
|
u16 BulkLength;
|
|
|
|
u32 RxBufferId;
|
|
|
|
R00_DESCRIPTOR R00;
|
|
|
|
|
|
|
|
// Variable setting
|
|
|
|
pWb35Rx->EP3vm_state = VM_COMPLETED;
|
2008-10-22 08:01:16 +00:00
|
|
|
pWb35Rx->EP3VM_status = urb->status;//Store the last result of Irp
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-21 09:14:58 +00:00
|
|
|
RxBufferId = pWb35Rx->CurrentRxBufferId;
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-21 09:14:58 +00:00
|
|
|
pRxBufferAddress = pWb35Rx->pDRx;
|
2008-10-22 08:01:16 +00:00
|
|
|
BulkLength = (u16)urb->actual_length;
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-21 09:14:58 +00:00
|
|
|
// The IRP is completed
|
|
|
|
pWb35Rx->EP3vm_state = VM_COMPLETED;
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-21 09:14:58 +00:00
|
|
|
if (pHwData->SurpriseRemove || pHwData->HwStop) // Must be here, or RxBufferId is invalid
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (pWb35Rx->rx_halt)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
// Start to process the data only in successful condition
|
|
|
|
pWb35Rx->RxOwner[ RxBufferId ] = 0; // Set the owner to driver
|
|
|
|
R00.value = le32_to_cpu(*(u32 *)pRxBufferAddress);
|
|
|
|
|
|
|
|
// The URB is completed, check the result
|
|
|
|
if (pWb35Rx->EP3VM_status != 0) {
|
|
|
|
#ifdef _PE_USB_STATE_DUMP_
|
|
|
|
WBDEBUG(("EP3 IoCompleteRoutine return error\n"));
|
|
|
|
DebugUsbdStatusInformation( pWb35Rx->EP3VM_status );
|
|
|
|
#endif
|
|
|
|
pWb35Rx->EP3vm_state = VM_STOP;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 20060220 For recovering. check if operating in single USB mode
|
|
|
|
if (!HAL_USB_MODE_BURST(pHwData)) {
|
|
|
|
SizeCheck = R00.R00_receive_byte_count; //20060926 anson's endian
|
|
|
|
if ((SizeCheck & 0x03) > 0)
|
|
|
|
SizeCheck -= 4;
|
|
|
|
SizeCheck = (SizeCheck + 3) & ~0x03;
|
|
|
|
SizeCheck += 12; // 8 + 4 badbeef
|
|
|
|
if ((BulkLength > 1600) ||
|
|
|
|
(SizeCheck > 1600) ||
|
|
|
|
(BulkLength != SizeCheck) ||
|
|
|
|
(BulkLength == 0)) { // Add for fail Urb
|
2008-10-01 12:36:56 +00:00
|
|
|
pWb35Rx->EP3vm_state = VM_STOP;
|
2008-10-21 09:14:58 +00:00
|
|
|
pWb35Rx->Ep3ErrorCount2++;
|
2008-10-01 12:36:56 +00:00
|
|
|
}
|
2008-10-21 09:14:58 +00:00
|
|
|
}
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-21 09:14:58 +00:00
|
|
|
// Indicating the receiving data
|
|
|
|
pWb35Rx->ByteReceived += BulkLength;
|
|
|
|
pWb35Rx->RxBufferSize[ RxBufferId ] = BulkLength;
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-21 09:14:58 +00:00
|
|
|
if (!pWb35Rx->RxOwner[ RxBufferId ])
|
2008-10-30 14:14:39 +00:00
|
|
|
Wb35Rx_indicate(hw);
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-21 09:14:58 +00:00
|
|
|
kfree(pWb35Rx->pDRx);
|
|
|
|
// Do the next receive
|
2008-10-30 14:14:39 +00:00
|
|
|
Wb35Rx(hw);
|
2008-10-21 09:14:58 +00:00
|
|
|
return;
|
2008-10-01 12:36:56 +00:00
|
|
|
|
2008-10-21 09:14:58 +00:00
|
|
|
error:
|
2008-10-01 12:36:56 +00:00
|
|
|
pWb35Rx->RxOwner[ RxBufferId ] = 1; // Set the owner to hardware
|
2008-10-29 18:10:32 +00:00
|
|
|
atomic_dec(&pWb35Rx->RxFireCounter);
|
2008-10-01 12:36:56 +00:00
|
|
|
pWb35Rx->EP3vm_state = VM_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================================
|
|
|
|
unsigned char Wb35Rx_initial(phw_data_t pHwData)
|
|
|
|
{
|
|
|
|
PWB35RX pWb35Rx = &pHwData->Wb35Rx;
|
|
|
|
|
|
|
|
// Initial the Buffer Queue
|
|
|
|
Wb35Rx_reset_descriptor( pHwData );
|
|
|
|
|
2008-10-27 21:21:24 +00:00
|
|
|
pWb35Rx->RxUrb = usb_alloc_urb(0, GFP_ATOMIC);
|
2008-10-01 12:36:56 +00:00
|
|
|
return (!!pWb35Rx->RxUrb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wb35Rx_stop(phw_data_t pHwData)
|
|
|
|
{
|
|
|
|
PWB35RX pWb35Rx = &pHwData->Wb35Rx;
|
|
|
|
|
|
|
|
// Canceling the Irp if already sends it out.
|
|
|
|
if (pWb35Rx->EP3vm_state == VM_RUNNING) {
|
|
|
|
usb_unlink_urb( pWb35Rx->RxUrb ); // Only use unlink, let Wb35Rx_destroy to free them
|
|
|
|
#ifdef _PE_RX_DUMP_
|
|
|
|
WBDEBUG(("EP3 Rx stop\n"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Needs process context
|
|
|
|
void Wb35Rx_destroy(phw_data_t pHwData)
|
|
|
|
{
|
|
|
|
PWB35RX pWb35Rx = &pHwData->Wb35Rx;
|
|
|
|
|
|
|
|
do {
|
2008-10-22 16:07:03 +00:00
|
|
|
msleep(10); // Delay for waiting function enter 940623.1.a
|
2008-10-01 12:36:56 +00:00
|
|
|
} while (pWb35Rx->EP3vm_state != VM_STOP);
|
2008-10-22 16:07:03 +00:00
|
|
|
msleep(10); // Delay for waiting function exit 940623.1.b
|
2008-10-01 12:36:56 +00:00
|
|
|
|
|
|
|
if (pWb35Rx->RxUrb)
|
|
|
|
usb_free_urb( pWb35Rx->RxUrb );
|
|
|
|
#ifdef _PE_RX_DUMP_
|
|
|
|
WBDEBUG(("Wb35Rx_destroy OK\n"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wb35Rx_reset_descriptor( phw_data_t pHwData )
|
|
|
|
{
|
|
|
|
PWB35RX pWb35Rx = &pHwData->Wb35Rx;
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
pWb35Rx->ByteReceived = 0;
|
|
|
|
pWb35Rx->RxProcessIndex = 0;
|
|
|
|
pWb35Rx->RxBufferId = 0;
|
|
|
|
pWb35Rx->EP3vm_state = VM_STOP;
|
|
|
|
pWb35Rx->rx_halt = 0;
|
|
|
|
|
|
|
|
// Initial the Queue. The last buffer is reserved for used if the Rx resource is unavailable.
|
|
|
|
for( i=0; i<MAX_USB_RX_BUFFER_NUMBER; i++ )
|
|
|
|
pWb35Rx->RxOwner[i] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wb35Rx_adjust(PDESCRIPTOR pRxDes)
|
|
|
|
{
|
2008-10-20 21:03:41 +00:00
|
|
|
u32 * pRxBufferAddress;
|
2008-10-01 12:36:56 +00:00
|
|
|
u32 DecryptionMethod;
|
|
|
|
u32 i;
|
|
|
|
u16 BufferSize;
|
|
|
|
|
|
|
|
DecryptionMethod = pRxDes->R01.R01_decryption_method;
|
|
|
|
pRxBufferAddress = pRxDes->buffer_address[0];
|
|
|
|
BufferSize = pRxDes->buffer_size[0];
|
|
|
|
|
|
|
|
// Adjust the last part of data. Only data left
|
|
|
|
BufferSize -= 4; // For CRC-32
|
|
|
|
if (DecryptionMethod)
|
|
|
|
BufferSize -= 4;
|
|
|
|
if (DecryptionMethod == 3) // For CCMP
|
|
|
|
BufferSize -= 4;
|
|
|
|
|
|
|
|
// Adjust the IV field which after 802.11 header and ICV field.
|
|
|
|
if (DecryptionMethod == 1) // For WEP
|
|
|
|
{
|
|
|
|
for( i=6; i>0; i-- )
|
|
|
|
pRxBufferAddress[i] = pRxBufferAddress[i-1];
|
|
|
|
pRxDes->buffer_address[0] = pRxBufferAddress + 1;
|
|
|
|
BufferSize -= 4; // 4 byte for IV
|
|
|
|
}
|
|
|
|
else if( DecryptionMethod ) // For TKIP and CCMP
|
|
|
|
{
|
|
|
|
for (i=7; i>1; i--)
|
|
|
|
pRxBufferAddress[i] = pRxBufferAddress[i-2];
|
|
|
|
pRxDes->buffer_address[0] = pRxBufferAddress + 2;//Update the descriptor, shift 8 byte
|
|
|
|
BufferSize -= 8; // 8 byte for IV + ICV
|
|
|
|
}
|
|
|
|
pRxDes->buffer_size[0] = BufferSize;
|
|
|
|
}
|
|
|
|
|
2008-10-30 14:14:39 +00:00
|
|
|
extern void packet_came(struct ieee80211_hw *hw, char *pRxBufferAddress, int PacketSize);
|
2008-10-01 12:36:56 +00:00
|
|
|
|
|
|
|
|
2008-10-30 14:14:39 +00:00
|
|
|
u16 Wb35Rx_indicate(struct ieee80211_hw *hw)
|
2008-10-01 12:36:56 +00:00
|
|
|
{
|
2008-10-30 14:14:39 +00:00
|
|
|
struct wbsoft_priv *priv = hw->priv;
|
|
|
|
phw_data_t pHwData = &priv->sHwData;
|
2008-10-01 12:36:56 +00:00
|
|
|
DESCRIPTOR RxDes;
|
|
|
|
PWB35RX pWb35Rx = &pHwData->Wb35Rx;
|
2008-10-20 21:03:41 +00:00
|
|
|
u8 * pRxBufferAddress;
|
2008-10-01 12:36:56 +00:00
|
|
|
u16 PacketSize;
|
|
|
|
u16 stmp, BufferSize, stmp2 = 0;
|
|
|
|
u32 RxBufferId;
|
|
|
|
|
|
|
|
// Only one thread be allowed to run into the following
|
|
|
|
do {
|
|
|
|
RxBufferId = pWb35Rx->RxProcessIndex;
|
|
|
|
if (pWb35Rx->RxOwner[ RxBufferId ]) //Owner by VM
|
|
|
|
break;
|
|
|
|
|
|
|
|
pWb35Rx->RxProcessIndex++;
|
|
|
|
pWb35Rx->RxProcessIndex %= MAX_USB_RX_BUFFER_NUMBER;
|
|
|
|
|
|
|
|
pRxBufferAddress = pWb35Rx->pDRx;
|
|
|
|
BufferSize = pWb35Rx->RxBufferSize[ RxBufferId ];
|
|
|
|
|
|
|
|
// Parse the bulkin buffer
|
|
|
|
while (BufferSize >= 4) {
|
2008-10-20 21:03:41 +00:00
|
|
|
if ((cpu_to_le32(*(u32 *)pRxBufferAddress) & 0x0fffffff) == RX_END_TAG) //Is ending? 921002.9.a
|
2008-10-01 12:36:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Get the R00 R01 first
|
2008-10-20 21:03:41 +00:00
|
|
|
RxDes.R00.value = le32_to_cpu(*(u32 *)pRxBufferAddress);
|
2008-10-01 12:36:56 +00:00
|
|
|
PacketSize = (u16)RxDes.R00.R00_receive_byte_count;
|
2008-10-20 21:03:41 +00:00
|
|
|
RxDes.R01.value = le32_to_cpu(*((u32 *)(pRxBufferAddress+4)));
|
2008-10-01 12:36:56 +00:00
|
|
|
// For new DMA 4k
|
|
|
|
if ((PacketSize & 0x03) > 0)
|
|
|
|
PacketSize -= 4;
|
|
|
|
|
|
|
|
// Basic check for Rx length. Is length valid?
|
|
|
|
if (PacketSize > MAX_PACKET_SIZE) {
|
|
|
|
#ifdef _PE_RX_DUMP_
|
|
|
|
WBDEBUG(("Serious ERROR : Rx data size too long, size =%d\n", PacketSize));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pWb35Rx->EP3vm_state = VM_STOP;
|
|
|
|
pWb35Rx->Ep3ErrorCount2++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start to process Rx buffer
|
|
|
|
// RxDes.Descriptor_ID = RxBufferId; // Due to synchronous indicate, the field doesn't necessary to use.
|
|
|
|
BufferSize -= 8; //subtract 8 byte for 35's USB header length
|
|
|
|
pRxBufferAddress += 8;
|
|
|
|
|
|
|
|
RxDes.buffer_address[0] = pRxBufferAddress;
|
|
|
|
RxDes.buffer_size[0] = PacketSize;
|
|
|
|
RxDes.buffer_number = 1;
|
|
|
|
RxDes.buffer_start_index = 0;
|
|
|
|
RxDes.buffer_total_size = RxDes.buffer_size[0];
|
|
|
|
Wb35Rx_adjust(&RxDes);
|
|
|
|
|
2008-10-30 14:14:39 +00:00
|
|
|
packet_came(hw, pRxBufferAddress, PacketSize);
|
2008-10-01 12:36:56 +00:00
|
|
|
|
|
|
|
// Move RxBuffer point to the next
|
|
|
|
stmp = PacketSize + 3;
|
|
|
|
stmp &= ~0x03; // 4n alignment
|
|
|
|
pRxBufferAddress += stmp;
|
|
|
|
BufferSize -= stmp;
|
|
|
|
stmp2 += stmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reclaim resource
|
|
|
|
pWb35Rx->RxOwner[ RxBufferId ] = 1;
|
2008-10-27 20:46:39 +00:00
|
|
|
} while (true);
|
2008-10-01 12:36:56 +00:00
|
|
|
|
|
|
|
return stmp2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|