diff options
Diffstat (limited to 'drivers/staging/vt6655/device_main.c')
-rw-r--r-- | drivers/staging/vt6655/device_main.c | 2533 |
1 files changed, 657 insertions, 1876 deletions
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c index 54e16f40d8ed..83e4162c0094 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -32,27 +32,16 @@ * device_free_info - device structure resource free function * device_get_pci_info - get allocated pci io/mem resource * device_print_info - print out resource - * device_open - allocate dma/descripter resource & initial mac/bbp function - * device_xmit - asynchrous data tx function * device_intr - interrupt handle function - * device_set_multi - set mac filter - * device_ioctl - ioctl entry - * device_close - shutdown mac/bbp & free dma/descripter resource * device_rx_srv - rx service function - * device_receive_frame - rx data function * device_alloc_rx_buf - rx buffer pre-allocated function - * device_alloc_frag_buf - rx fragement pre-allocated function * device_free_tx_buf - free tx buffer function - * device_free_frag_buf- free de-fragement buffer - * device_dma0_tx_80211- tx 802.11 frame via dma0 - * device_dma0_xmit- tx PS bufferred frame via dma0 * device_init_rd0_ring- initial rd dma0 ring * device_init_rd1_ring- initial rd dma1 ring * device_init_td0_ring- initial tx dma0 ring buffer * device_init_td1_ring- initial tx dma1 ring buffer * device_init_registers- initial MAC & BBP & RF internal registers. * device_init_rings- initial tx/rx ring buffer - * device_init_defrag_cb- initial & allocate de-fragement buffer. * device_free_rings- free all allocated ring buffer * device_tx_srv- tx interrupt service function * @@ -66,24 +55,10 @@ #include "channel.h" #include "baseband.h" #include "mac.h" -#include "tether.h" -#include "wmgr.h" -#include "wctl.h" #include "power.h" -#include "wcmd.h" -#include "iocmd.h" -#include "tcrc.h" #include "rxtx.h" -#include "wroute.h" -#include "bssdb.h" -#include "hostap.h" -#include "wpactl.h" -#include "ioctl.h" -#include "iwctl.h" #include "dpc.h" -#include "datarate.h" #include "rf.h" -#include "iowpa.h" #include <linux/delay.h> #include <linux/kthread.h> #include <linux/slab.h> @@ -118,89 +93,16 @@ DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0"); #define TX_DESC_DEF1 64 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1"); -#define IP_ALIG_DEF 0 -/* IP_byte_align[] is used for IP header unsigned long byte aligned - 0: indicate the IP header won't be unsigned long byte aligned.(Default) . - 1: indicate the IP header will be unsigned long byte aligned. - In some environment, the IP header should be unsigned long byte aligned, - or the packet will be droped when we receive it. (eg: IPVS) -*/ -DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned"); - #define INT_WORKS_DEF 20 #define INT_WORKS_MIN 10 #define INT_WORKS_MAX 64 DEVICE_PARAM(int_works, "Number of packets per interrupt services"); -#define CHANNEL_MIN 1 -#define CHANNEL_MAX 14 -#define CHANNEL_DEF 6 - -DEVICE_PARAM(Channel, "Channel number"); - -/* PreambleType[] is the preamble length used for transmit. - 0: indicate allows long preamble type - 1: indicate allows short preamble type -*/ - -#define PREAMBLE_TYPE_DEF 1 - -DEVICE_PARAM(PreambleType, "Preamble Type"); - -#define RTS_THRESH_MIN 512 -#define RTS_THRESH_MAX 2347 #define RTS_THRESH_DEF 2347 -DEVICE_PARAM(RTSThreshold, "RTS threshold"); - -#define FRAG_THRESH_MIN 256 -#define FRAG_THRESH_MAX 2346 #define FRAG_THRESH_DEF 2346 -DEVICE_PARAM(FragThreshold, "Fragmentation threshold"); - -#define DATA_RATE_MIN 0 -#define DATA_RATE_MAX 13 -#define DATA_RATE_DEF 13 -/* datarate[] index - 0: indicate 1 Mbps 0x02 - 1: indicate 2 Mbps 0x04 - 2: indicate 5.5 Mbps 0x0B - 3: indicate 11 Mbps 0x16 - 4: indicate 6 Mbps 0x0c - 5: indicate 9 Mbps 0x12 - 6: indicate 12 Mbps 0x18 - 7: indicate 18 Mbps 0x24 - 8: indicate 24 Mbps 0x30 - 9: indicate 36 Mbps 0x48 - 10: indicate 48 Mbps 0x60 - 11: indicate 54 Mbps 0x6c - 12: indicate 72 Mbps 0x90 - 13: indicate auto rate -*/ - -DEVICE_PARAM(ConnectionRate, "Connection data rate"); - -#define OP_MODE_DEF 0 - -DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode "); - -/* OpMode[] is used for transmit. - 0: indicate infrastruct mode used - 1: indicate adhoc mode used - 2: indicate AP mode used -*/ - -/* PSMode[] - 0: indicate disable power saving mode - 1: indicate enable power saving mode -*/ - -#define PS_MODE_DEF 0 - -DEVICE_PARAM(PSMode, "Power saving mode"); - #define SHORT_RETRY_MIN 0 #define SHORT_RETRY_MAX 31 #define SHORT_RETRY_DEF 8 @@ -224,20 +126,6 @@ DEVICE_PARAM(LongRetryLimit, "long frame retry limits"); DEVICE_PARAM(BasebandType, "baseband type"); -/* 80211hEnable[] - 0: indicate disable 802.11h - 1: indicate enable 802.11h -*/ - -#define X80211h_MODE_DEF 0 - -DEVICE_PARAM(b80211hEnable, "802.11h mode"); - -/* 80211hEnable[] - 0: indicate disable 802.11h - 1: indicate enable 802.11h -*/ - #define DIVERSITY_ANT_DEF 0 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode"); @@ -265,17 +153,10 @@ static void device_free_info(struct vnt_private *pDevice); static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid); static void device_print_info(struct vnt_private *pDevice); static void device_init_diversity_timer(struct vnt_private *pDevice); -static int device_open(struct net_device *dev); -static int device_xmit(struct sk_buff *skb, struct net_device *dev); static irqreturn_t device_intr(int irq, void *dev_instance); -static void device_set_multi(struct net_device *dev); -static int device_close(struct net_device *dev); -static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); #ifdef CONFIG_PM static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr); -static int viawget_suspend(struct pci_dev *pcid, pm_message_t state); -static int viawget_resume(struct pci_dev *pcid); static struct notifier_block device_notifier = { .notifier_call = device_notify_reboot, .next = NULL, @@ -285,15 +166,9 @@ static struct notifier_block device_notifier = { static void device_init_rd0_ring(struct vnt_private *pDevice); static void device_init_rd1_ring(struct vnt_private *pDevice); -static void device_init_defrag_cb(struct vnt_private *pDevice); static void device_init_td0_ring(struct vnt_private *pDevice); static void device_init_td1_ring(struct vnt_private *pDevice); -static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev); -//2008-0714<Add>by Mike Liu -static bool device_release_WPADEV(struct vnt_private *pDevice); - -static int ethtool_ioctl(struct net_device *dev, void __user *useraddr); static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx); static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx); static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc); @@ -304,9 +179,6 @@ static void device_free_td1_ring(struct vnt_private *pDevice); static void device_free_rd0_ring(struct vnt_private *pDevice); static void device_free_rd1_ring(struct vnt_private *pDevice); static void device_free_rings(struct vnt_private *pDevice); -static void device_free_frag_buf(struct vnt_private *pDevice); -static int Config_FileGetParameter(unsigned char *string, - unsigned char *dest, unsigned char *source); /*--------------------- Export Variables --------------------------*/ @@ -339,124 +211,50 @@ static void device_get_options(struct vnt_private *pDevice) pOpts->nRxDescs1 = RX_DESC_DEF1; pOpts->nTxDescs[0] = TX_DESC_DEF0; pOpts->nTxDescs[1] = TX_DESC_DEF1; - pOpts->flags |= DEVICE_FLAGS_IP_ALIGN; pOpts->int_works = INT_WORKS_DEF; - pOpts->rts_thresh = RTS_THRESH_DEF; - pOpts->frag_thresh = FRAG_THRESH_DEF; - pOpts->data_rate = DATA_RATE_DEF; - pOpts->channel_num = CHANNEL_DEF; - pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE; - pOpts->flags |= DEVICE_FLAGS_OP_MODE; pOpts->short_retry = SHORT_RETRY_DEF; pOpts->long_retry = LONG_RETRY_DEF; pOpts->bbp_type = BBP_TYPE_DEF; - pOpts->flags |= DEVICE_FLAGS_80211h_MODE; pOpts->flags |= DEVICE_FLAGS_DiversityANT; } static void device_set_options(struct vnt_private *pDevice) { - unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; - unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; - - memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN); - memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN); - memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN); - - pDevice->uChannel = pDevice->sOpts.channel_num; - pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh; - pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh; pDevice->byShortRetryLimit = pDevice->sOpts.short_retry; pDevice->byLongRetryLimit = pDevice->sOpts.long_retry; - pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME; - pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0; - pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0; - pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0; - pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0; pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0; - pDevice->uConnectionRate = pDevice->sOpts.data_rate; - if (pDevice->uConnectionRate < RATE_AUTO) - pDevice->bFixRate = true; pDevice->byBBType = pDevice->sOpts.bbp_type; - pDevice->byPacketType = (VIA_PKT_TYPE)pDevice->byBBType; + pDevice->byPacketType = pDevice->byBBType; pDevice->byAutoFBCtrl = AUTO_FB_0; pDevice->bUpdateBBVGA = true; - pDevice->byFOETuning = 0; pDevice->byPreambleType = 0; - pr_debug(" uChannel= %d\n", (int)pDevice->uChannel); - pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode); - pr_debug(" ePSMode= %d\n", (int)pDevice->ePSMode); - pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold); pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit); pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit); pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType); pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble); - pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate); pr_debug(" byBBType= %d\n", (int)pDevice->byBBType); - pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable); pr_debug(" pDevice->bDiversityRegCtlON= %d\n", (int)pDevice->bDiversityRegCtlON); } -static void s_vCompleteCurrentMeasure(struct vnt_private *pDevice, - unsigned char byResult) -{ - unsigned int ii; - unsigned long dwDuration = 0; - unsigned char byRPI0 = 0; - - for (ii = 1; ii < 8; ii++) { - pDevice->dwRPIs[ii] *= 255; - dwDuration |= *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration)); - dwDuration <<= 10; - pDevice->dwRPIs[ii] /= dwDuration; - pDevice->abyRPIs[ii] = (unsigned char)pDevice->dwRPIs[ii]; - byRPI0 += pDevice->abyRPIs[ii]; - } - pDevice->abyRPIs[0] = (0xFF - byRPI0); - - if (pDevice->uNumOfMeasureEIDs == 0) { - VNTWIFIbMeasureReport(pDevice->pMgmt, - true, - pDevice->pCurrMeasureEID, - byResult, - pDevice->byBasicMap, - pDevice->byCCAFraction, - pDevice->abyRPIs - ); - } else { - VNTWIFIbMeasureReport(pDevice->pMgmt, - false, - pDevice->pCurrMeasureEID, - byResult, - pDevice->byBasicMap, - pDevice->byCCAFraction, - pDevice->abyRPIs - ); - CARDbStartMeasure(pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs); - } -} - // // Initialisation of MAC & BBP registers // static void device_init_registers(struct vnt_private *pDevice) { + unsigned long flags; unsigned int ii; unsigned char byValue; unsigned char byValue1; unsigned char byCCKPwrdBm = 0; unsigned char byOFDMPwrdBm = 0; - int zonetype = 0; - PSMgmtObject pMgmt = &(pDevice->sMgmtObj); MACbShutdown(pDevice->PortOffset); - BBvSoftwareReset(pDevice->PortOffset); + BBvSoftwareReset(pDevice); /* Do MACbSoftwareReset in MACvInitialize */ MACbSoftwareReset(pDevice->PortOffset); @@ -481,11 +279,11 @@ static void device_init_registers(struct vnt_private *pDevice) /* Get Local ID */ VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID); - spin_lock_irq(&pDevice->lock); + spin_lock_irqsave(&pDevice->lock, flags); SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM); - spin_unlock_irq(&pDevice->lock); + spin_unlock_irqrestore(&pDevice->lock, flags); /* Get Channel range */ pDevice->byMinChannel = 1; @@ -558,41 +356,6 @@ static void device_init_registers(struct vnt_private *pDevice) /* zonetype initial */ pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE]; - zonetype = Config_FileOperation(pDevice, false, NULL); - - if (zonetype >= 0) { - if ((zonetype == 0) && - (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) { - /* for USA */ - pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0; - pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B; - - pr_debug("Init Zone Type :USA\n"); - } else if ((zonetype == 1) && - (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) { - /* for Japan */ - pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01; - pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D; - } else if ((zonetype == 2) && - (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) { - /* for Europe */ - pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02; - pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D; - - pr_debug("Init Zone Type :Europe\n"); - } else { - if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE]) - pr_debug("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n", - zonetype, - pDevice->abyEEPROM[EEP_OFS_ZONETYPE]); - else - pr_debug("Read Zonetype file success,use default zonetype setting[%02x]\n", - zonetype); - } - } else { - pr_debug("Read Zonetype file fail,use default zonetype setting[%02x]\n", - SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE)); - } /* Get RFType */ pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE); @@ -636,14 +399,9 @@ static void device_init_registers(struct vnt_private *pDevice) } /* recover 12,13 ,14channel for EUROPE by 11 channel */ - if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) || - (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) && - (pDevice->byOriginalZonetype == ZoneType_USA)) { - for (ii = 11; ii < 14; ii++) { - pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10]; - pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10]; - - } + for (ii = 11; ii < 14; ii++) { + pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10]; + pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10]; } /* Load OFDM A Power Table */ @@ -657,8 +415,6 @@ static void device_init_registers(struct vnt_private *pDevice) (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm)); } - init_channel_table((void *)pDevice); - if (pDevice->byLocalID > REV_ID_VT3253_B1) { MACvSelectPage1(pDevice->PortOffset); @@ -690,21 +446,12 @@ static void device_init_registers(struct vnt_private *pDevice) BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]); } - BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode); - BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode); - - pDevice->byCurrentCh = 0; + BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode); + BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode); /* Set BB and packet type at the same time. */ /* Set Short Slot Time, xIFS, and RSPINF. */ - if (pDevice->uConnectionRate == RATE_AUTO) - pDevice->wCurrentRate = RATE_54M; - else - pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate; - - /* default G Mode */ - VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G); - VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO); + pDevice->wCurrentRate = RATE_54M; pDevice->bRadioOff = false; @@ -726,8 +473,6 @@ static void device_init_registers(struct vnt_private *pDevice) if (pDevice->bHWRadioOff || pDevice->bRadioControlOff) CARDbRadioPowerOff(pDevice); - pMgmt->eScanType = WMAC_SCAN_PASSIVE; - /* get Permanent network address */ SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr); pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr); @@ -740,223 +485,39 @@ static void device_init_registers(struct vnt_private *pDevice) if (pDevice->byLocalID <= REV_ID_VT3253_A1) MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR); - pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; - /* Turn On Rx DMA */ MACvReceive0(pDevice->PortOffset); MACvReceive1(pDevice->PortOffset); /* start the adapter */ MACvStart(pDevice->PortOffset); - - netif_stop_queue(pDevice->dev); } static void device_init_diversity_timer(struct vnt_private *pDevice) { init_timer(&pDevice->TimerSQ3Tmax1); pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice; - pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack; + pDevice->TimerSQ3Tmax1.function = TimerSQ3CallBack; pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ); init_timer(&pDevice->TimerSQ3Tmax2); pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice; - pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack; + pDevice->TimerSQ3Tmax2.function = TimerSQ3CallBack; pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ); init_timer(&pDevice->TimerSQ3Tmax3); pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice; - pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack; + pDevice->TimerSQ3Tmax3.function = TimerState1CallBack; pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ); } -static bool device_release_WPADEV(struct vnt_private *pDevice) -{ - viawget_wpa_header *wpahdr; - int ii = 0; - - //send device close to wpa_supplicnat layer - if (pDevice->bWPADEVUp) { - wpahdr = (viawget_wpa_header *)pDevice->skb->data; - wpahdr->type = VIAWGET_DEVICECLOSE_MSG; - wpahdr->resp_ie_len = 0; - wpahdr->req_ie_len = 0; - skb_put(pDevice->skb, sizeof(viawget_wpa_header)); - pDevice->skb->dev = pDevice->wpadev; - skb_reset_mac_header(pDevice->skb); - pDevice->skb->pkt_type = PACKET_HOST; - pDevice->skb->protocol = htons(ETH_P_802_2); - memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb)); - netif_rx(pDevice->skb); - pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); - - while (pDevice->bWPADEVUp) { - set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(HZ / 20); //wait 50ms - ii++; - if (ii > 20) - break; - } - } - return true; -} - -static const struct net_device_ops device_netdev_ops = { - .ndo_open = device_open, - .ndo_stop = device_close, - .ndo_do_ioctl = device_ioctl, - .ndo_start_xmit = device_xmit, - .ndo_set_rx_mode = device_set_multi, -}; - -static int -vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent) -{ - static bool bFirst = true; - struct net_device *dev = NULL; - PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data; - struct vnt_private *pDevice; - int rc; - - dev = alloc_etherdev(sizeof(*pDevice)); - - pDevice = netdev_priv(dev); - - if (dev == NULL) { - pr_err(DEVICE_NAME ": allocate net device failed\n"); - return -ENOMEM; - } - - // Chain it all together - SET_NETDEV_DEV(dev, &pcid->dev); - - if (bFirst) { - pr_notice("%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION); - pr_notice("Copyright (c) 2003 VIA Networking Technologies, Inc.\n"); - bFirst = false; - } - - vt6655_init_info(pcid, &pDevice, pChip_info); - pDevice->dev = dev; - - if (pci_enable_device(pcid)) { - device_free_info(pDevice); - return -ENODEV; - } - dev->irq = pcid->irq; - -#ifdef DEBUG - pr_debug("Before get pci_info memaddr is %x\n", pDevice->memaddr); -#endif - if (!device_get_pci_info(pDevice, pcid)) { - pr_err(DEVICE_NAME ": Failed to find PCI device.\n"); - device_free_info(pDevice); - return -ENODEV; - } - -#if 1 - -#ifdef DEBUG - - pr_debug("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n", pDevice->memaddr, pDevice->ioaddr, pDevice->io_size); - { - int i; - u32 bar, len; - u32 address[] = { - PCI_BASE_ADDRESS_0, - PCI_BASE_ADDRESS_1, - PCI_BASE_ADDRESS_2, - PCI_BASE_ADDRESS_3, - PCI_BASE_ADDRESS_4, - PCI_BASE_ADDRESS_5, - 0}; - for (i = 0; address[i]; i++) { - pci_read_config_dword(pcid, address[i], &bar); - pr_debug("bar %d is %x\n", i, bar); - if (!bar) { - pr_debug("bar %d not implemented\n", i); - continue; - } - if (bar & PCI_BASE_ADDRESS_SPACE_IO) { - /* This is IO */ - - len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF); - len = len & ~(len - 1); - - pr_debug("IO space: len in IO %x, BAR %d\n", len, i); - } else { - len = bar & 0xFFFFFFF0; - len = ~len + 1; - - pr_debug("len in MEM %x, BAR %d\n", len, i); - } - } - } -#endif - -#endif - - pDevice->PortOffset = ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size); - - if (pDevice->PortOffset == NULL) { - pr_err(DEVICE_NAME ": Failed to IO remapping ..\n"); - device_free_info(pDevice); - return -ENODEV; - } - - rc = pci_request_regions(pcid, DEVICE_NAME); - if (rc) { - pr_err(DEVICE_NAME ": Failed to find PCI device\n"); - device_free_info(pDevice); - return -ENODEV; - } - - dev->base_addr = pDevice->ioaddr; - // do reset - if (!MACbSoftwareReset(pDevice->PortOffset)) { - pr_err(DEVICE_NAME ": Failed to access MAC hardware..\n"); - device_free_info(pDevice); - return -ENODEV; - } - // initial to reload eeprom - MACvInitialize(pDevice->PortOffset); - MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr); - - device_get_options(pDevice); - device_set_options(pDevice); - //Mask out the options cannot be set to the chip - pDevice->sOpts.flags &= pChip_info->flags; - - //Enable the chip specified capabilities - pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL); - pDevice->tx_80211 = device_dma0_tx_80211; - pDevice->sMgmtObj.pAdapter = (void *)pDevice; - pDevice->pMgmt = &(pDevice->sMgmtObj); - - dev->irq = pcid->irq; - dev->netdev_ops = &device_netdev_ops; - - dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def; - - rc = register_netdev(dev); - if (rc) { - pr_err(DEVICE_NAME " Failed to register netdev\n"); - device_free_info(pDevice); - return -ENODEV; - } - device_print_info(pDevice); - pci_set_drvdata(pcid, pDevice); - return 0; -} - static void device_print_info(struct vnt_private *pDevice) { - struct net_device *dev = pDevice->dev; + dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id)); - pr_info("%s: %s\n", dev->name, get_chip_name(pDevice->chip_id)); - pr_info("%s: MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n", - dev->name, dev->dev_addr, (unsigned long)pDevice->ioaddr, - (unsigned long)pDevice->PortOffset, pDevice->dev->irq); + dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n", + pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr, + (unsigned long)pDevice->PortOffset, pDevice->pcid->irq); } static void vt6655_init_info(struct pci_dev *pcid, @@ -1003,31 +564,20 @@ static bool device_get_pci_info(struct vnt_private *pDevice, static void device_free_info(struct vnt_private *pDevice) { - struct net_device *dev = pDevice->dev; - - ASSERT(pDevice); -//2008-0714-01<Add>by chester - device_release_WPADEV(pDevice); - -//2008-07-21-01<Add>by MikeLiu -//unregister wpadev - if (wpa_set_wpadev(pDevice, 0) != 0) - pr_err("unregister wpadev fail?\n"); + if (!pDevice) + return; -#ifdef HOSTAP - if (dev) - vt6655_hostap_set_hostapd(pDevice, 0, 0); -#endif - if (dev) - unregister_netdev(dev); + if (pDevice->mac_hw) + ieee80211_unregister_hw(pDevice->hw); if (pDevice->PortOffset) iounmap(pDevice->PortOffset); if (pDevice->pcid) pci_release_regions(pDevice->pcid); - if (dev) - free_netdev(dev); + + if (pDevice->hw) + ieee80211_free_hw(pDevice->hw); } static bool device_init_rings(struct vnt_private *pDevice) @@ -1176,21 +726,6 @@ static void device_init_rd1_ring(struct vnt_private *pDevice) pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]); } -static void device_init_defrag_cb(struct vnt_private *pDevice) -{ - int i; - PSDeFragControlBlock pDeF; - - /* Init the fragment ctl entries */ - for (i = 0; i < CB_MAX_RX_FRAG; i++) { - pDeF = &(pDevice->sRxDFCB[i]); - if (!device_alloc_frag_buf(pDevice, pDeF)) - dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n"); - } - pDevice->cbDFCB = CB_MAX_RX_FRAG; - pDevice->cbFreeDFCB = pDevice->cbDFCB; -} - static void device_free_rd0_ring(struct vnt_private *pDevice) { int i; @@ -1204,7 +739,7 @@ static void device_free_rd0_ring(struct vnt_private *pDevice) dev_kfree_skb(pRDInfo->skb); - kfree((void *)pDesc->pRDInfo); + kfree(pDesc->pRDInfo); } } @@ -1221,21 +756,7 @@ static void device_free_rd1_ring(struct vnt_private *pDevice) dev_kfree_skb(pRDInfo->skb); - kfree((void *)pDesc->pRDInfo); - } -} - -static void device_free_frag_buf(struct vnt_private *pDevice) -{ - PSDeFragControlBlock pDeF; - int i; - - for (i = 0; i < CB_MAX_RX_FRAG; i++) { - pDeF = &(pDevice->sRxDFCB[i]); - - if (pDeF->skb) - dev_kfree_skb(pDeF->skb); - + kfree(pDesc->pRDInfo); } } @@ -1305,7 +826,7 @@ static void device_free_td0_ring(struct vnt_private *pDevice) if (pTDInfo->skb) dev_kfree_skb(pTDInfo->skb); - kfree((void *)pDesc->pTDInfo); + kfree(pDesc->pTDInfo); } } @@ -1324,7 +845,7 @@ static void device_free_td1_ring(struct vnt_private *pDevice) if (pTDInfo->skb) dev_kfree_skb(pTDInfo->skb); - kfree((void *)pDesc->pTDInfo); + kfree(pDesc->pTDInfo); } } @@ -1340,7 +861,7 @@ static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx) pRD = pRD->next) { if (works++ > 15) break; - if (device_receive_frame(pDevice, pRD)) { + if (vnt_receive_frame(pDevice, pRD)) { if (!device_alloc_rx_buf(pDevice, pRD)) { dev_err(&pDevice->pcid->dev, "can not allocate rx buf\n"); @@ -1348,7 +869,6 @@ static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx) } } pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC; - pDevice->dev->last_rx = jiffies; } pDevice->pCurrRD[uIdx] = pRD; @@ -1364,9 +884,12 @@ static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD) if (pRDInfo->skb == NULL) return false; ASSERT(pRDInfo->skb); - pRDInfo->skb->dev = pDevice->dev; - pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb), - pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE); + + pRDInfo->skb_dma = + pci_map_single(pDevice->pcid, + skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)), + pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE); + *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */ pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz); @@ -1377,31 +900,84 @@ static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD) return true; } -bool device_alloc_frag_buf(struct vnt_private *pDevice, - PSDeFragControlBlock pDeF) +static const u8 fallback_rate0[5][5] = { + {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M}, + {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M}, + {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M}, + {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M}, + {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M} +}; + +static const u8 fallback_rate1[5][5] = { + {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M}, + {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M}, + {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M}, + {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M}, + {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M} +}; + +static int vnt_int_report_rate(struct vnt_private *priv, + PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1) { - pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); - if (pDeF->skb == NULL) - return false; - ASSERT(pDeF->skb); - pDeF->skb->dev = pDevice->dev; + struct vnt_tx_fifo_head *fifo_head; + struct ieee80211_tx_info *info; + struct ieee80211_rate *rate; + u16 fb_option; + u8 tx_retry = (tsr0 & TSR0_NCR); + s8 idx; + + if (!context) + return -ENOMEM; - return true; + if (!context->skb) + return -EINVAL; + + fifo_head = (struct vnt_tx_fifo_head *)context->buf; + fb_option = (le16_to_cpu(fifo_head->fifo_ctl) & + (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1)); + + info = IEEE80211_SKB_CB(context->skb); + idx = info->control.rates[0].idx; + + if (fb_option && !(tsr1 & TSR1_TERR)) { + u8 tx_rate; + u8 retry = tx_retry; + + rate = ieee80211_get_tx_rate(priv->hw, info); + tx_rate = rate->hw_value - RATE_18M; + + if (retry > 4) + retry = 4; + + if (fb_option & FIFOCTL_AUTO_FB_0) + tx_rate = fallback_rate0[tx_rate][retry]; + else if (fb_option & FIFOCTL_AUTO_FB_1) + tx_rate = fallback_rate1[tx_rate][retry]; + + if (info->band == IEEE80211_BAND_5GHZ) + idx = tx_rate - RATE_6M; + else + idx = tx_rate; + } + + ieee80211_tx_info_clear_status(info); + + info->status.rates[0].count = tx_retry; + + if (!(tsr1 & TSR1_TERR)) { + info->status.rates[0].idx = idx; + info->flags |= IEEE80211_TX_STAT_ACK; + } + + return 0; } static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx) { PSTxDesc pTD; - bool bFull = false; int works = 0; unsigned char byTsr0; unsigned char byTsr1; - unsigned int uFrameSize, uFIFOHeaderSize; - PSTxBufHead pTxBufHead; - struct net_device_stats *pStats = &pDevice->dev->stats; - struct sk_buff *skb; - unsigned int uNodeIndex; - PSMgmtObject pMgmt = pDevice->pMgmt; for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) { if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC) @@ -1415,22 +991,8 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx) //Only the status of first TD in the chain is correct if (pTD->m_td1TD1.byTCR & TCR_STP) { if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) { - uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength; - uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize; - pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf); - // Update the statistics based on the Transmit status - // now, we DONT check TSR0_CDH - - STAvUpdateTDStatCounter(&pDevice->scStatistic, - byTsr0, byTsr1, - (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize), - uFrameSize, uIdx); - - BSSvUpdateNodeTxCounter(pDevice, - byTsr0, byTsr1, - (unsigned char *)(pTD->pTDInfo->buf), - uFIFOHeaderSize - ); + + vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1); if (!(byTsr1 & TSR1_TERR)) { if (byTsr0 != 0) { @@ -1438,28 +1000,9 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx) (int)uIdx, byTsr1, byTsr0); } - if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) - pDevice->s802_11Counter.TransmittedFragmentCount++; - - pStats->tx_packets++; - pStats->tx_bytes += pTD->pTDInfo->skb->len; } else { pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n", (int)uIdx, byTsr1, byTsr0); - pStats->tx_errors++; - pStats->tx_dropped++; - } - } - - if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) { - if (pDevice->bEnableHostapd) { - pr_debug("tx call back netif..\n"); - skb = pTD->pTDInfo->skb; - skb->dev = pDevice->apdev; - skb_reset_mac_header(skb); - skb->pkt_type = PACKET_OTHERHOST; - memset(skb->cb, 0, sizeof(skb->cb)); - netif_rx(skb); } } @@ -1468,49 +1011,12 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx) pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n", (int)uIdx, byTsr1, byTsr0); } - - - if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && - (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) { - unsigned short wAID; - unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; - - skb = pTD->pTDInfo->skb; - if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) { - if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) { - skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb); - pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++; - // set tx map - wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID; - pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7]; - pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB); - pr_debug("tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n", - (int)uNodeIndex, - pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt); - pStats->tx_errors--; - pStats->tx_dropped--; - } - } - } } device_free_tx_buf(pDevice, pTD); pDevice->iTDUsed[uIdx]--; } } - if (uIdx == TYPE_AC0DMA) { - // RESERV_AC0DMA reserved for relay - - if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) { - bFull = true; - pr_debug(" AC0DMA is Full = %d\n", - pDevice->iTDUsed[uIdx]); - } - if (netif_queue_stopped(pDevice->dev) && !bFull) - netif_wake_queue(pDevice->dev); - - } - pDevice->apTailTD[uIdx] = pTD; return works; @@ -1521,10 +1027,6 @@ static void device_error(struct vnt_private *pDevice, unsigned short status) if (status & ISR_FETALERR) { dev_err(&pDevice->pcid->dev, "Hardware fatal error\n"); - netif_stop_queue(pDevice->dev); - del_timer(&pDevice->sTimerCommand); - del_timer(&(pDevice->pMgmt->sTimerSecondCallback)); - pDevice->bCmdRunning = false; MACbShutdown(pDevice->PortOffset); return; } @@ -1541,7 +1043,9 @@ static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc) PCI_DMA_TODEVICE); } - if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) + if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) + ieee80211_tx_status_irqsafe(pDevice->hw, skb); + else dev_kfree_skb_irq(skb); pTDInfo->skb_dma = 0; @@ -1549,671 +1053,13 @@ static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc) pTDInfo->byFlags = 0; } -static int device_open(struct net_device *dev) -{ - struct vnt_private *pDevice = netdev_priv(dev); - int i; -#ifdef WPA_SM_Transtatus - extern SWPAResult wpa_Result; -#endif - - pDevice->rx_buf_sz = PKT_BUF_SZ; - if (!device_init_rings(pDevice)) - return -ENOMEM; - -//2008-5-13 <add> by chester - i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev); - if (i) - return i; - -#ifdef WPA_SM_Transtatus - memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname)); - wpa_Result.proto = 0; - wpa_Result.key_mgmt = 0; - wpa_Result.eap_type = 0; - wpa_Result.authenticated = false; - pDevice->fWPA_Authened = false; -#endif - pr_debug("call device init rd0 ring\n"); - device_init_rd0_ring(pDevice); - device_init_rd1_ring(pDevice); - device_init_defrag_cb(pDevice); - device_init_td0_ring(pDevice); - device_init_td1_ring(pDevice); - - if (pDevice->bDiversityRegCtlON) - device_init_diversity_timer(pDevice); - - vMgrObjectInit(pDevice); - vMgrTimerInit(pDevice); - - pr_debug("call device_init_registers\n"); - device_init_registers(pDevice); - - MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr); - memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN); - device_set_multi(pDevice->dev); - - // Init for Key Management - KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); - add_timer(&(pDevice->pMgmt->sTimerSecondCallback)); - -#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT - pDevice->bwextcount = 0; - pDevice->bWPASuppWextEnabled = false; -#endif - pDevice->byReAssocCount = 0; - pDevice->bWPADEVUp = false; - // Patch: if WEP key already set by iwconfig but device not yet open - if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) { - KeybSetDefaultKey(&(pDevice->sKey), - (unsigned long)(pDevice->byKeyIndex | (1 << 31)), - pDevice->uKeyLength, - NULL, - pDevice->abyKey, - KEY_CTL_WEP, - pDevice->PortOffset, - pDevice->byLocalID - ); - pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; - } - - pr_debug("call MACvIntEnable\n"); - MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE); - - if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) { - bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL); - } else { - bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL); - bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL); - } - pDevice->flags |= DEVICE_FLAGS_OPENED; - - pr_debug("device_open success..\n"); - return 0; -} - -static int device_close(struct net_device *dev) -{ - struct vnt_private *pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = pDevice->pMgmt; -//2007-1121-02<Add>by EinsnLiu - if (pDevice->bLinkPass) { - bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL); - mdelay(30); - } - - del_timer(&pDevice->sTimerTxData); - del_timer(&pDevice->sTimerCommand); - del_timer(&pMgmt->sTimerSecondCallback); - if (pDevice->bDiversityRegCtlON) { - del_timer(&pDevice->TimerSQ3Tmax1); - del_timer(&pDevice->TimerSQ3Tmax2); - del_timer(&pDevice->TimerSQ3Tmax3); - } - - netif_stop_queue(dev); - pDevice->bCmdRunning = false; - MACbShutdown(pDevice->PortOffset); - MACbSoftwareReset(pDevice->PortOffset); - CARDbRadioPowerOff(pDevice); - - pDevice->bLinkPass = false; - memset(pMgmt->abyCurrBSSID, 0, 6); - pMgmt->eCurrState = WMAC_STATE_IDLE; - device_free_td0_ring(pDevice); - device_free_td1_ring(pDevice); - device_free_rd0_ring(pDevice); - device_free_rd1_ring(pDevice); - device_free_frag_buf(pDevice); - device_free_rings(pDevice); - BSSvClearNodeDBTable(pDevice, 0); - free_irq(dev->irq, dev); - pDevice->flags &= (~DEVICE_FLAGS_OPENED); - //2008-0714-01<Add>by chester - device_release_WPADEV(pDevice); - - pr_debug("device_close..\n"); - return 0; -} - -static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) -{ - struct vnt_private *pDevice = netdev_priv(dev); - unsigned char *pbMPDU; - unsigned int cbMPDULen = 0; - - pr_debug("device_dma0_tx_80211\n"); - spin_lock_irq(&pDevice->lock); - - if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) { - pr_debug("device_dma0_tx_80211, td0 <=0\n"); - dev_kfree_skb_irq(skb); - spin_unlock_irq(&pDevice->lock); - return 0; - } - - if (pDevice->bStopTx0Pkt) { - dev_kfree_skb_irq(skb); - spin_unlock_irq(&pDevice->lock); - return 0; - } - - cbMPDULen = skb->len; - pbMPDU = skb->data; - - vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen); - - spin_unlock_irq(&pDevice->lock); - - return 0; -} - -bool device_dma0_xmit(struct vnt_private *pDevice, - struct sk_buff *skb, unsigned int uNodeIndex) -{ - PSMgmtObject pMgmt = pDevice->pMgmt; - PSTxDesc pHeadTD, pLastTD; - unsigned int cbFrameBodySize; - unsigned int uMACfragNum; - unsigned char byPktType; - bool bNeedEncryption = false; - PSKeyItem pTransmitKey = NULL; - unsigned int cbHeaderSize; - unsigned int ii; - SKeyItem STempKey; - - if (pDevice->bStopTx0Pkt) { - dev_kfree_skb_irq(skb); - return false; - } - - if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) { - dev_kfree_skb_irq(skb); - pr_debug("device_dma0_xmit, td0 <=0\n"); - return false; - } - - if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { - if (pDevice->uAssocCount == 0) { - dev_kfree_skb_irq(skb); - pr_debug("device_dma0_xmit, assocCount = 0\n"); - return false; - } - } - - pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0]; - - pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP); - - memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN); - cbFrameBodySize = skb->len - ETH_HLEN; - - // 802.1H - if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) - cbFrameBodySize += 8; - - uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader); - - if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) { - dev_kfree_skb_irq(skb); - return false; - } - byPktType = (unsigned char)pDevice->byPacketType; - - if (pDevice->bFixRate) { - if (pDevice->eCurrentPHYType == PHY_TYPE_11B) { - if (pDevice->uConnectionRate >= RATE_11M) - pDevice->wCurrentRate = RATE_11M; - else - pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate; - } else { - if (pDevice->uConnectionRate >= RATE_54M) - pDevice->wCurrentRate = RATE_54M; - else - pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate; - } - } else { - pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate; - } - - //preamble type - if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) - pDevice->byPreambleType = pDevice->byShortPreamble; - else - pDevice->byPreambleType = PREAMBLE_LONG; - - pr_debug("dma0: pDevice->wCurrentRate = %d\n", pDevice->wCurrentRate); - - if (pDevice->wCurrentRate <= RATE_11M) { - byPktType = PK_TYPE_11B; - } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) { - byPktType = PK_TYPE_11A; - } else { - if (pDevice->bProtectMode) - byPktType = PK_TYPE_11GB; - else - byPktType = PK_TYPE_11GA; - } - - if (pDevice->bEncryptionEnable) - bNeedEncryption = true; - - if (pDevice->bEnableHostWEP) { - pTransmitKey = &STempKey; - pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite; - pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex; - pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength; - pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16; - pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0; - memcpy(pTransmitKey->abyKey, - &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0], - pTransmitKey->uKeyLength - ); - } - vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption, - cbFrameBodySize, TYPE_TXDMA0, pHeadTD, - &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex, - &uMACfragNum, - &cbHeaderSize - ); - - if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) { - // Disable PS - MACbPSWakeup(pDevice->PortOffset); - } - - pDevice->bPWBitOn = false; - - pLastTD = pHeadTD; - for (ii = 0; ii < uMACfragNum; ii++) { - // Poll Transmit the adapter - wmb(); - pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC; - wmb(); - if (ii == (uMACfragNum - 1)) - pLastTD = pHeadTD; - pHeadTD = pHeadTD->next; - } - - // Save the information needed by the tx interrupt handler - // to complete the Send request - pLastTD->pTDInfo->skb = skb; - pLastTD->pTDInfo->byFlags = 0; - pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB; - - pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD; - - MACvTransmit0(pDevice->PortOffset); - - return true; -} - -//TYPE_AC0DMA data tx -static int device_xmit(struct sk_buff *skb, struct net_device *dev) { - struct vnt_private *pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = pDevice->pMgmt; - PSTxDesc pHeadTD, pLastTD; - unsigned int uNodeIndex = 0; - unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; - unsigned short wAID; - unsigned int uMACfragNum = 1; - unsigned int cbFrameBodySize; - unsigned char byPktType; - unsigned int cbHeaderSize; - bool bNeedEncryption = false; - PSKeyItem pTransmitKey = NULL; - SKeyItem STempKey; - unsigned int ii; - bool bTKIP_UseGTK = false; - bool bNeedDeAuth = false; - unsigned char *pbyBSSID; - bool bNodeExist = false; - - spin_lock_irq(&pDevice->lock); - if (!pDevice->bLinkPass) { - dev_kfree_skb_irq(skb); - spin_unlock_irq(&pDevice->lock); - return 0; - } - - if (pDevice->bStopDataPkt) { - dev_kfree_skb_irq(skb); - spin_unlock_irq(&pDevice->lock); - return 0; - } - - if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { - if (pDevice->uAssocCount == 0) { - dev_kfree_skb_irq(skb); - spin_unlock_irq(&pDevice->lock); - return 0; - } - if (is_multicast_ether_addr((unsigned char *)(skb->data))) { - uNodeIndex = 0; - bNodeExist = true; - if (pMgmt->sNodeDBTable[0].bPSEnable) { - skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb); - pMgmt->sNodeDBTable[0].wEnQueueCnt++; - // set tx map - pMgmt->abyPSTxMap[0] |= byMask[0]; - spin_unlock_irq(&pDevice->lock); - return 0; - } - } else { - if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) { - if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) { - skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb); - pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++; - // set tx map - wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID; - pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7]; - pr_debug("Set:pMgmt->abyPSTxMap[%d]= %d\n", - (wAID >> 3), - pMgmt->abyPSTxMap[wAID >> 3]); - spin_unlock_irq(&pDevice->lock); - return 0; - } - - if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) - pDevice->byPreambleType = pDevice->byShortPreamble; - else - pDevice->byPreambleType = PREAMBLE_LONG; - - bNodeExist = true; - - } - } - - if (!bNodeExist) { - pr_debug("Unknown STA not found in node DB\n"); - dev_kfree_skb_irq(skb); - spin_unlock_irq(&pDevice->lock); - return 0; - } - } - - pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA]; - - pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP); - - memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN); - cbFrameBodySize = skb->len - ETH_HLEN; - // 802.1H - if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) - cbFrameBodySize += 8; - - if (pDevice->bEncryptionEnable) { - bNeedEncryption = true; - // get Transmit key - do { - if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && - (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) { - pbyBSSID = pDevice->abyBSSID; - // get pairwise key - if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) { - // get group key - if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) { - bTKIP_UseGTK = true; - pr_debug("Get GTK\n"); - break; - } - } else { - pr_debug("Get PTK\n"); - break; - } - } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { - pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 - pr_debug("IBSS Serach Key:\n"); - for (ii = 0; ii < 6; ii++) - pr_debug("%x\n", *(pbyBSSID+ii)); - pr_debug("\n"); - - // get pairwise key - if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) - break; - } - // get group key - pbyBSSID = pDevice->abyBroadcastAddr; - if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) { - pTransmitKey = NULL; - if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) - pr_debug("IBSS and KEY is NULL. [%d]\n", - pDevice->pMgmt->eCurrMode); - else - pr_debug("NOT IBSS and KEY is NULL. [%d]\n", - pDevice->pMgmt->eCurrMode); - } else { - bTKIP_UseGTK = true; - pr_debug("Get GTK\n"); - } - } while (false); - } - - if (pDevice->bEnableHostWEP) { - pr_debug("acdma0: STA index %d\n", uNodeIndex); - if (pDevice->bEncryptionEnable) { - pTransmitKey = &STempKey; - pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite; - pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex; - pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength; - pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16; - pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0; - memcpy(pTransmitKey->abyKey, - &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0], - pTransmitKey->uKeyLength - ); - } - } - - uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader); - - if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) { - pr_debug("uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", - uMACfragNum); - dev_kfree_skb_irq(skb); - spin_unlock_irq(&pDevice->lock); - return 0; - } - - if (pTransmitKey != NULL) { - if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) && - (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) { - uMACfragNum = 1; //WEP256 doesn't support fragment - } - } - - byPktType = (unsigned char)pDevice->byPacketType; - - if (pDevice->bFixRate) { - if (pDevice->eCurrentPHYType == PHY_TYPE_11B) { - if (pDevice->uConnectionRate >= RATE_11M) - pDevice->wCurrentRate = RATE_11M; - else - pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate; - } else { - if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) && - (pDevice->uConnectionRate <= RATE_6M)) { - pDevice->wCurrentRate = RATE_6M; - } else { - if (pDevice->uConnectionRate >= RATE_54M) - pDevice->wCurrentRate = RATE_54M; - else - pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate; - - } - } - pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate; - pDevice->byTopCCKBasicRate = RATE_1M; - pDevice->byTopOFDMBasicRate = RATE_6M; - } else { - //auto rate - if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) { - if (pDevice->eCurrentPHYType != PHY_TYPE_11A) { - pDevice->wCurrentRate = RATE_1M; - pDevice->byACKRate = RATE_1M; - pDevice->byTopCCKBasicRate = RATE_1M; - pDevice->byTopOFDMBasicRate = RATE_6M; - } else { - pDevice->wCurrentRate = RATE_6M; - pDevice->byACKRate = RATE_6M; - pDevice->byTopCCKBasicRate = RATE_1M; - pDevice->byTopOFDMBasicRate = RATE_6M; - } - } else { - VNTWIFIvGetTxRate(pDevice->pMgmt, - pDevice->sTxEthHeader.abyDstAddr, - &(pDevice->wCurrentRate), - &(pDevice->byACKRate), - &(pDevice->byTopCCKBasicRate), - &(pDevice->byTopOFDMBasicRate)); - - } - } - - - if (pDevice->wCurrentRate <= RATE_11M) { - byPktType = PK_TYPE_11B; - } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) { - byPktType = PK_TYPE_11A; - } else { - if (pDevice->bProtectMode) - byPktType = PK_TYPE_11GB; - else - byPktType = PK_TYPE_11GA; - } - - if (bNeedEncryption) { - pr_debug("ntohs Pkt Type=%04x\n", - ntohs(pDevice->sTxEthHeader.wType)); - if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) { - bNeedEncryption = false; - pr_debug("Pkt Type=%04x\n", - (pDevice->sTxEthHeader.wType)); - if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) { - if (pTransmitKey == NULL) { - pr_debug("Don't Find TX KEY\n"); - } else { - if (bTKIP_UseGTK) { - pr_debug("error: KEY is GTK!!~~\n"); - } else { - pr_debug("Find PTK [%lX]\n", - pTransmitKey->dwKeyIndex); - bNeedEncryption = true; - } - } - } - - if (pDevice->byCntMeasure == 2) { - bNeedDeAuth = true; - pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++; - } - - if (pDevice->bEnableHostWEP) { - if ((uNodeIndex != 0) && - (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) { - pr_debug("Find PTK [%lX]\n", - pTransmitKey->dwKeyIndex); - bNeedEncryption = true; - } - } - } else { - if (pTransmitKey == NULL) { - pr_debug("return no tx key\n"); - dev_kfree_skb_irq(skb); - spin_unlock_irq(&pDevice->lock); - return 0; - } - } - } - - vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption, - cbFrameBodySize, TYPE_AC0DMA, pHeadTD, - &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex, - &uMACfragNum, - &cbHeaderSize - ); - - if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) { - // Disable PS - MACbPSWakeup(pDevice->PortOffset); - } - pDevice->bPWBitOn = false; - - pLastTD = pHeadTD; - for (ii = 0; ii < uMACfragNum; ii++) { - // Poll Transmit the adapter - wmb(); - pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC; - wmb(); - if (ii == uMACfragNum - 1) - pLastTD = pHeadTD; - pHeadTD = pHeadTD->next; - } - - // Save the information needed by the tx interrupt handler - // to complete the Send request - pLastTD->pTDInfo->skb = skb; - pLastTD->pTDInfo->byFlags = 0; - pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB; - pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet - - if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) - netif_stop_queue(dev); - - pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD; - - if (pDevice->bFixRate) - pr_debug("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr); - - { - unsigned char Protocol_Version; //802.1x Authentication - unsigned char Packet_Type; //802.1x Authentication - unsigned char Descriptor_type; - unsigned short Key_info; - bool bTxeapol_key = false; - - Protocol_Version = skb->data[ETH_HLEN]; - Packet_Type = skb->data[ETH_HLEN+1]; - Descriptor_type = skb->data[ETH_HLEN+1+1+2]; - Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]); - if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) { - if (((Protocol_Version == 1) || (Protocol_Version == 2)) && - (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer - bTxeapol_key = true; - if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN - if (!(Key_info & BIT3) && //group-key challenge - (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key - pDevice->fWPA_Authened = true; - if (Descriptor_type == 254) - pr_debug("WPA "); - else - pr_debug("WPA2 "); - pr_debug("Authentication completed!!\n"); - } - } - } - } - } - - MACvTransmitAC0(pDevice->PortOffset); - - dev->trans_start = jiffies; - - spin_unlock_irq(&pDevice->lock); - return 0; -} - static irqreturn_t device_intr(int irq, void *dev_instance) { - struct net_device *dev = dev_instance; - struct vnt_private *pDevice = netdev_priv(dev); + struct vnt_private *pDevice = dev_instance; int max_count = 0; unsigned long dwMIBCounter = 0; - PSMgmtObject pMgmt = pDevice->pMgmt; unsigned char byOrgPageSel = 0; int handled = 0; - unsigned char byData = 0; int ii = 0; unsigned long flags; @@ -2256,96 +1102,13 @@ static irqreturn_t device_intr(int irq, void *dev_instance) device_error(pDevice, pDevice->dwIsr); } - if (pDevice->byLocalID > REV_ID_VT3253_B1) { - if (pDevice->dwIsr & ISR_MEASURESTART) { - // 802.11h measure start - pDevice->byOrgChannel = pDevice->byCurrentCh; - VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR)); - VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR)); - MACvSelectPage1(pDevice->PortOffset); - VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0)); - VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4)); - MACvSelectPage0(pDevice->PortOffset); - //xxxx - if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) { - pDevice->bMeasureInProgress = true; - MACvSelectPage1(pDevice->PortOffset); - MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY); - MACvSelectPage0(pDevice->PortOffset); - pDevice->byBasicMap = 0; - pDevice->byCCAFraction = 0; - for (ii = 0; ii < 8; ii++) - pDevice->dwRPIs[ii] = 0; - - } else { - // can not measure because set channel fail - // clear measure control - MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN); - s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE); - MACvSelectPage1(pDevice->PortOffset); - MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE); - MACvSelectPage0(pDevice->PortOffset); - } - } - if (pDevice->dwIsr & ISR_MEASUREEND) { - // 802.11h measure end - pDevice->bMeasureInProgress = false; - VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR); - MACvSelectPage1(pDevice->PortOffset); - VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0); - VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4); - VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData); - pDevice->byBasicMap |= (byData >> 4); - VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction); - VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData); - // clear measure control - MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN); - MACvSelectPage0(pDevice->PortOffset); - set_channel(pDevice, pDevice->byOrgChannel); - MACvSelectPage1(pDevice->PortOffset); - MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE); - MACvSelectPage0(pDevice->PortOffset); - if (byData & MSRCTL_FINISH) { - // measure success - s_vCompleteCurrentMeasure(pDevice, 0); - } else { - // can not measure because not ready before end of measure time - s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE); - } - } - if (pDevice->dwIsr & ISR_QUIETSTART) { - do { - ; - } while (!CARDbStartQuiet(pDevice)); - } - } - if (pDevice->dwIsr & ISR_TBTT) { - if (pDevice->bEnableFirstQuiet) { - pDevice->byQuietStartCount--; - if (pDevice->byQuietStartCount == 0) { - pDevice->bEnableFirstQuiet = false; - MACvSelectPage1(pDevice->PortOffset); - MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN)); - MACvSelectPage0(pDevice->PortOffset); - } - } - if (pDevice->bChannelSwitch && - (pDevice->op_mode == NL80211_IFTYPE_STATION)) { - pDevice->byChannelSwitchCount--; - if (pDevice->byChannelSwitchCount == 0) { - pDevice->bChannelSwitch = false; - set_channel(pDevice, pDevice->byNewChannel); - VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel); - MACvSelectPage1(pDevice->PortOffset); - MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE); - MACvSelectPage0(pDevice->PortOffset); - CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL); - - } - } - if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) { - if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) { + if (pDevice->vif && + pDevice->op_mode != NL80211_IFTYPE_ADHOC) { + if (pDevice->bUpdateBBVGA && + !(pDevice->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && + pDevice->vif->bss_conf.assoc && + pDevice->uCurrRSSI) { long ldBm; RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm); @@ -2384,10 +1147,11 @@ static irqreturn_t device_intr(int irq, void *dev_instance) if (pDevice->bEnablePSMode) PSbIsNextTBTTWakeUp((void *)pDevice); - if ((pDevice->op_mode == NL80211_IFTYPE_AP) || - (pDevice->op_mode == NL80211_IFTYPE_ADHOC)) { + if ((pDevice->op_mode == NL80211_IFTYPE_AP || + pDevice->op_mode == NL80211_IFTYPE_ADHOC) && + pDevice->vif->bss_conf.enable_beacon) { MACvOneShotTimer1MicroSec(pDevice->PortOffset, - (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10); + (pDevice->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10); } /* TODO: adhoc PS mode */ @@ -2400,34 +1164,7 @@ static irqreturn_t device_intr(int irq, void *dev_instance) pDevice->cbBeaconBufReadySetCnt = 0; } - if (pDevice->op_mode == NL80211_IFTYPE_AP) { - if (pMgmt->byDTIMCount > 0) { - pMgmt->byDTIMCount--; - pMgmt->sNodeDBTable[0].bRxPSPoll = false; - } else { - if (pMgmt->byDTIMCount == 0) { - // check if mutltcast tx bufferring - pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1; - pMgmt->sNodeDBTable[0].bRxPSPoll = true; - bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL); - } - } - } pDevice->bBeaconSent = true; - - if (pDevice->bChannelSwitch) { - pDevice->byChannelSwitchCount--; - if (pDevice->byChannelSwitchCount == 0) { - pDevice->bChannelSwitch = false; - set_channel(pDevice, pDevice->byNewChannel); - VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel); - MACvSelectPage1(pDevice->PortOffset); - MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE); - MACvSelectPage0(pDevice->PortOffset); - CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL); - } - } - } if (pDevice->dwIsr & ISR_RXDMA0) @@ -2443,14 +1180,18 @@ static irqreturn_t device_intr(int irq, void *dev_instance) max_count += device_tx_srv(pDevice, TYPE_AC0DMA); if (pDevice->dwIsr & ISR_SOFTTIMER1) { - if (pDevice->op_mode == NL80211_IFTYPE_AP) { - if (pDevice->bShortSlotTime) - pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1); - else - pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)); + if (pDevice->vif) { + if (pDevice->vif->bss_conf.enable_beacon) + vnt_beacon_make(pDevice, pDevice->vif); } - bMgrPrepareBeaconToSend(pDevice, pMgmt); - pDevice->byCntMeasure = 0; + } + + /* If both buffers available wake the queue */ + if (pDevice->vif) { + if (AVAIL_TD(pDevice, TYPE_TXDMA0) && + AVAIL_TD(pDevice, TYPE_AC0DMA) && + ieee80211_queue_stopped(pDevice->hw, 0)) + ieee80211_wake_queues(pDevice->hw); } MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr); @@ -2472,550 +1213,655 @@ static irqreturn_t device_intr(int irq, void *dev_instance) return IRQ_RETVAL(handled); } -//2008-8-4 <add> by chester -static int Config_FileGetParameter(unsigned char *string, - unsigned char *dest, unsigned char *source) +static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) { - unsigned char buf1[100]; - int source_len = strlen(source); + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; + PSTxDesc head_td; + u32 dma_idx = TYPE_AC0DMA; + unsigned long flags; - memset(buf1, 0, 100); - strcat(buf1, string); - strcat(buf1, "="); - source += strlen(buf1); + spin_lock_irqsave(&priv->lock, flags); - memcpy(dest, source, source_len - strlen(buf1)); - return true; -} + if (!ieee80211_is_data(hdr->frame_control)) + dma_idx = TYPE_TXDMA0; -int Config_FileOperation(struct vnt_private *pDevice, - bool fwrite, unsigned char *Parameter) -{ - unsigned char *buffer = kmalloc(1024, GFP_KERNEL); - unsigned char tmpbuffer[20]; - struct file *file; - int result = 0; - - if (!buffer) { - pr_err("allocate mem for file fail?\n"); - return -1; - } - file = filp_open(CONFIG_PATH, O_RDONLY, 0); - if (IS_ERR(file)) { - kfree(buffer); - pr_err("Config_FileOperation:open file fail?\n"); - return -1; + if (AVAIL_TD(priv, dma_idx) < 1) { + spin_unlock_irqrestore(&priv->lock, flags); + return -ENOMEM; } - if (kernel_read(file, 0, buffer, 1024) < 0) { - pr_err("read file error?\n"); - result = -1; - goto error1; - } + head_td = priv->apCurrTD[dma_idx]; - if (Config_FileGetParameter("ZONETYPE", tmpbuffer, buffer) != true) { - pr_err("get parameter error?\n"); - result = -1; - goto error1; - } + head_td->m_td1TD1.byTCR = (TCR_EDP|TCR_STP); - if (memcmp(tmpbuffer, "USA", 3) == 0) { - result = ZoneType_USA; - } else if (memcmp(tmpbuffer, "JAPAN", 5) == 0) { - result = ZoneType_Japan; - } else if (memcmp(tmpbuffer, "EUROPE", 5) == 0) { - result = ZoneType_Europe; - } else { - result = -1; - pr_err("Unknown Zonetype[%s]?\n", tmpbuffer); - } + head_td->pTDInfo->skb = skb; + + priv->iTDUsed[dma_idx]++; + + /* Take ownership */ + wmb(); + head_td->m_td0TD0.f1Owner = OWNED_BY_NIC; + + /* get Next */ + wmb(); + priv->apCurrTD[dma_idx] = head_td->next; + + spin_unlock_irqrestore(&priv->lock, flags); + + vnt_generate_fifo_header(priv, dma_idx, head_td, skb); + + if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) + MACbPSWakeup(priv->PortOffset); + + spin_lock_irqsave(&priv->lock, flags); -error1: - kfree(buffer); - fput(file); - return result; + priv->bPWBitOn = false; + + head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB; + + if (dma_idx == TYPE_AC0DMA) + MACvTransmitAC0(priv->PortOffset); + else + MACvTransmit0(priv->PortOffset); + + spin_unlock_irqrestore(&priv->lock, flags); + + return 0; } -static void device_set_multi(struct net_device *dev) { - struct vnt_private *pDevice = netdev_priv(dev); - PSMgmtObject pMgmt = pDevice->pMgmt; - u32 mc_filter[2]; - struct netdev_hw_addr *ha; +static void vnt_tx_80211(struct ieee80211_hw *hw, + struct ieee80211_tx_control *control, + struct sk_buff *skb) +{ + struct vnt_private *priv = hw->priv; - VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode)); + ieee80211_stop_queues(hw); - if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ - pr_notice("%s: Promiscuous mode enabled\n", dev->name); - /* Unconditionally log net taps. */ - pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST); - } else if ((netdev_mc_count(dev) > pDevice->multicast_limit) - || (dev->flags & IFF_ALLMULTI)) { - MACvSelectPage1(pDevice->PortOffset); - VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff); - VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff); - MACvSelectPage0(pDevice->PortOffset); - pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); - } else { - memset(mc_filter, 0, sizeof(mc_filter)); - netdev_for_each_mc_addr(ha, dev) { - int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; + if (vnt_tx_packet(priv, skb)) { + ieee80211_free_txskb(hw, skb); - mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31)); - } - MACvSelectPage1(pDevice->PortOffset); - VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]); - VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]); - MACvSelectPage0(pDevice->PortOffset); - pDevice->byRxMode &= ~(RCR_UNICAST); - pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); + ieee80211_wake_queues(hw); } +} + +static int vnt_start(struct ieee80211_hw *hw) +{ + struct vnt_private *priv = hw->priv; + int ret; - if (pMgmt->eConfigMode == WMAC_CONFIG_AP) { - // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac. - pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); - pDevice->byRxMode &= ~(RCR_UNICAST); + priv->rx_buf_sz = PKT_BUF_SZ; + if (!device_init_rings(priv)) + return -ENOMEM; + + ret = request_irq(priv->pcid->irq, &device_intr, + IRQF_SHARED, "vt6655", priv); + if (ret) { + dev_dbg(&priv->pcid->dev, "failed to start irq\n"); + return ret; } - VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode); - pr_debug("pDevice->byRxMode = %x\n", pDevice->byRxMode); + dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n"); + device_init_rd0_ring(priv); + device_init_rd1_ring(priv); + device_init_td0_ring(priv); + device_init_td1_ring(priv); + + device_init_registers(priv); + + dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n"); + MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE); + + ieee80211_wake_queues(hw); + + return 0; } -static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) +static void vnt_stop(struct ieee80211_hw *hw) { - struct vnt_private *pDevice = netdev_priv(dev); - struct iwreq *wrq = (struct iwreq *)rq; - int rc = 0; - PSMgmtObject pMgmt = pDevice->pMgmt; - PSCmdRequest pReq; - - if (pMgmt == NULL) { - rc = -EFAULT; - return rc; - } + struct vnt_private *priv = hw->priv; - switch (cmd) { - case SIOCGIWNAME: - rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL); - break; + ieee80211_stop_queues(hw); + + MACbShutdown(priv->PortOffset); + MACbSoftwareReset(priv->PortOffset); + CARDbRadioPowerOff(priv); + + device_free_td0_ring(priv); + device_free_td1_ring(priv); + device_free_rd0_ring(priv); + device_free_rd1_ring(priv); + device_free_rings(priv); + + free_irq(priv->pcid->irq, priv); +} + +static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) +{ + struct vnt_private *priv = hw->priv; + + priv->vif = vif; - case SIOCGIWNWID: //0x8b03 support - rc = -EOPNOTSUPP; + switch (vif->type) { + case NL80211_IFTYPE_STATION: + if (priv->bDiversityRegCtlON) + device_init_diversity_timer(priv); break; + case NL80211_IFTYPE_ADHOC: + MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST); + + MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC); - // Set frequency/channel - case SIOCSIWFREQ: - rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL); break; + case NL80211_IFTYPE_AP: + MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST); + + MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP); - // Get frequency/channel - case SIOCGIWFREQ: - rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL); break; + default: + return -EOPNOTSUPP; + } - // Set desired network name (ESSID) - case SIOCSIWESSID: + priv->op_mode = vif->type; - { - char essid[IW_ESSID_MAX_SIZE+1]; + return 0; +} - if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) { - rc = -E2BIG; - break; - } - if (copy_from_user(essid, wrq->u.essid.pointer, - wrq->u.essid.length)) { - rc = -EFAULT; - break; +static void vnt_remove_interface(struct ieee80211_hw *hw, + struct ieee80211_vif *vif) +{ + struct vnt_private *priv = hw->priv; + + switch (vif->type) { + case NL80211_IFTYPE_STATION: + if (priv->bDiversityRegCtlON) { + del_timer(&priv->TimerSQ3Tmax1); + del_timer(&priv->TimerSQ3Tmax2); + del_timer(&priv->TimerSQ3Tmax3); } - rc = iwctl_siwessid(dev, NULL, - &(wrq->u.essid), essid); + break; + case NL80211_IFTYPE_ADHOC: + MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX); + MACvRegBitsOff(priv->PortOffset, + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); + MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC); + break; + case NL80211_IFTYPE_AP: + MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX); + MACvRegBitsOff(priv->PortOffset, + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); + MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP); + break; + default: + break; } - break; - // Get current network name (ESSID) - case SIOCGIWESSID: + priv->op_mode = NL80211_IFTYPE_UNSPECIFIED; +} - { - char essid[IW_ESSID_MAX_SIZE+1]; - - if (wrq->u.essid.pointer) - rc = iwctl_giwessid(dev, NULL, - &(wrq->u.essid), essid); - if (copy_to_user(wrq->u.essid.pointer, - essid, - wrq->u.essid.length)) - rc = -EFAULT; + +static int vnt_config(struct ieee80211_hw *hw, u32 changed) +{ + struct vnt_private *priv = hw->priv; + struct ieee80211_conf *conf = &hw->conf; + u8 bb_type; + + if (changed & IEEE80211_CONF_CHANGE_PS) { + if (conf->flags & IEEE80211_CONF_PS) + PSvEnablePowerSaving(priv, conf->listen_interval); + else + PSvDisablePowerSaving(priv); } - break; - case SIOCSIWAP: + if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || + (conf->flags & IEEE80211_CONF_OFFCHANNEL)) { + set_channel(priv, conf->chandef.chan->hw_value); - rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL); - break; + if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ) + bb_type = BB_TYPE_11A; + else + bb_type = BB_TYPE_11G; - // Get current Access Point (BSSID) - case SIOCGIWAP: - rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL); - break; + if (priv->byBBType != bb_type) { + priv->byBBType = bb_type; - // Set desired station name - case SIOCSIWNICKN: - pr_debug(" SIOCSIWNICKN\n"); - rc = -EOPNOTSUPP; - break; + CARDbSetPhyParameter(priv, priv->byBBType); + } + } - // Get current station name - case SIOCGIWNICKN: - pr_debug(" SIOCGIWNICKN\n"); - rc = -EOPNOTSUPP; - break; + if (changed & IEEE80211_CONF_CHANGE_POWER) { + if (priv->byBBType == BB_TYPE_11B) + priv->wCurrentRate = RATE_1M; + else + priv->wCurrentRate = RATE_54M; - // Set the desired bit-rate - case SIOCSIWRATE: - rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL); - break; + RFbSetPower(priv, priv->wCurrentRate, + conf->chandef.chan->hw_value); + } + + return 0; +} - // Get the current bit-rate - case SIOCGIWRATE: +static void vnt_bss_info_changed(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf, + u32 changed) +{ + struct vnt_private *priv = hw->priv; - rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL); - break; + priv->current_aid = conf->aid; - // Set the desired RTS threshold - case SIOCSIWRTS: + if (changed & BSS_CHANGED_BSSID) + MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid); - rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL); - break; + if (changed & BSS_CHANGED_BASIC_RATES) { + priv->basic_rates = conf->basic_rates; - // Get the current RTS threshold - case SIOCGIWRTS: + CARDvUpdateBasicTopRate(priv); - rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL); - break; + dev_dbg(&priv->pcid->dev, + "basic rates %x\n", conf->basic_rates); + } - // Set the desired fragmentation threshold - case SIOCSIWFRAG: + if (changed & BSS_CHANGED_ERP_PREAMBLE) { + if (conf->use_short_preamble) { + MACvEnableBarkerPreambleMd(priv->PortOffset); + priv->byPreambleType = true; + } else { + MACvDisableBarkerPreambleMd(priv->PortOffset); + priv->byPreambleType = false; + } + } - rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL); - break; + if (changed & BSS_CHANGED_ERP_CTS_PROT) { + if (conf->use_cts_prot) + MACvEnableProtectMD(priv->PortOffset); + else + MACvDisableProtectMD(priv->PortOffset); + } - // Get the current fragmentation threshold - case SIOCGIWFRAG: + if (changed & BSS_CHANGED_ERP_SLOT) { + if (conf->use_short_slot) + priv->bShortSlotTime = true; + else + priv->bShortSlotTime = false; - rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL); - break; + CARDbSetPhyParameter(priv, priv->byBBType); + BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]); + } - // Set mode of operation - case SIOCSIWMODE: - rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL); - break; + if (changed & BSS_CHANGED_TXPOWER) + RFbSetPower(priv, priv->wCurrentRate, + conf->chandef.chan->hw_value); - // Get mode of operation - case SIOCGIWMODE: - rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL); - break; + if (changed & BSS_CHANGED_BEACON_ENABLED) { + dev_dbg(&priv->pcid->dev, + "Beacon enable %d\n", conf->enable_beacon); - // Set WEP keys and mode - case SIOCSIWENCODE: { - char abyKey[WLAN_WEP232_KEYLEN]; + if (conf->enable_beacon) { + vnt_beacon_enable(priv, vif, conf); - if (wrq->u.encoding.pointer) { - if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) { - rc = -E2BIG; - break; - } - memset(abyKey, 0, WLAN_WEP232_KEYLEN); - if (copy_from_user(abyKey, - wrq->u.encoding.pointer, - wrq->u.encoding.length)) { - rc = -EFAULT; - break; - } - } else if (wrq->u.encoding.length != 0) { - rc = -EINVAL; - break; + MACvRegBitsOn(priv, MAC_REG_TCR, TCR_AUTOBCNTX); + } else { + MACvRegBitsOff(priv, MAC_REG_TCR, TCR_AUTOBCNTX); } - rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey); } - break; - // Get the WEP keys and mode - case SIOCGIWENCODE: + if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) { + if (conf->assoc) { + CARDbUpdateTSF(priv, conf->beacon_rate->hw_value, + conf->sync_device_ts, conf->sync_tsf); - if (!capable(CAP_NET_ADMIN)) { - rc = -EPERM; - break; + CARDbSetBeaconPeriod(priv, conf->beacon_int); + + CARDvSetFirstNextTBTT(priv, conf->beacon_int); + } else { + VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, + TFTCTL_TSFCNTRST); + VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, + TFTCTL_TSFCNTREN); } - { - char abyKey[WLAN_WEP232_KEYLEN]; + } +} - rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey); - if (rc != 0) - break; - if (wrq->u.encoding.pointer) { - if (copy_to_user(wrq->u.encoding.pointer, - abyKey, - wrq->u.encoding.length)) - rc = -EFAULT; +static u64 vnt_prepare_multicast(struct ieee80211_hw *hw, + struct netdev_hw_addr_list *mc_list) +{ + struct vnt_private *priv = hw->priv; + struct netdev_hw_addr *ha; + u64 mc_filter = 0; + u32 bit_nr = 0; + + netdev_hw_addr_list_for_each(ha, mc_list) { + bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; + + mc_filter |= 1ULL << (bit_nr & 0x3f); + } + + priv->mc_list_count = mc_list->count; + + return mc_filter; +} + +static void vnt_configure(struct ieee80211_hw *hw, + unsigned int changed_flags, unsigned int *total_flags, u64 multicast) +{ + struct vnt_private *priv = hw->priv; + u8 rx_mode = 0; + + *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS | + FIF_BCN_PRBRESP_PROMISC; + + VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode); + + dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode); + + if (changed_flags & FIF_PROMISC_IN_BSS) { + /* unconditionally log net taps */ + if (*total_flags & FIF_PROMISC_IN_BSS) + rx_mode |= RCR_UNICAST; + else + rx_mode &= ~RCR_UNICAST; + } + + if (changed_flags & FIF_ALLMULTI) { + if (*total_flags & FIF_ALLMULTI) { + if (priv->mc_list_count > 2) { + MACvSelectPage1(priv->PortOffset); + + VNSvOutPortD(priv->PortOffset + + MAC_REG_MAR0, 0xffffffff); + VNSvOutPortD(priv->PortOffset + + MAC_REG_MAR0 + 4, 0xffffffff); + + MACvSelectPage0(priv->PortOffset); + } else { + MACvSelectPage1(priv->PortOffset); + + VNSvOutPortD(priv->PortOffset + + MAC_REG_MAR0, (u32)multicast); + VNSvOutPortD(priv->PortOffset + + MAC_REG_MAR0 + 4, + (u32)(multicast >> 32)); + + MACvSelectPage0(priv->PortOffset); } + + rx_mode |= RCR_MULTICAST | RCR_BROADCAST; + } else { + rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST); } - break; + } - // Get the current Tx-Power - case SIOCGIWTXPOW: - pr_debug(" SIOCGIWTXPOW\n"); - rc = -EOPNOTSUPP; - break; + if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) { + rx_mode |= RCR_MULTICAST | RCR_BROADCAST; - case SIOCSIWTXPOW: - pr_debug(" SIOCSIWTXPOW\n"); - rc = -EOPNOTSUPP; - break; + if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) + rx_mode &= ~RCR_BSSID; + else + rx_mode |= RCR_BSSID; + } - case SIOCSIWRETRY: + VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode); - rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL); - break; + dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode); +} - case SIOCGIWRETRY: +static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, + struct ieee80211_vif *vif, struct ieee80211_sta *sta, + struct ieee80211_key_conf *key) +{ + struct vnt_private *priv = hw->priv; - rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL); + switch (cmd) { + case SET_KEY: + if (vnt_set_keys(hw, sta, vif, key)) + return -EOPNOTSUPP; break; + case DISABLE_KEY: + if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) + clear_bit(key->hw_key_idx, &priv->key_entry_inuse); + default: + break; + } - // Get range of parameters - case SIOCGIWRANGE: + return 0; +} - { - struct iw_range range; +static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) +{ + struct vnt_private *priv = hw->priv; + u64 tsf; - rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range); - if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range))) - rc = -EFAULT; - } + CARDbGetCurrentTSF(priv, &tsf); - break; + return tsf; +} - case SIOCGIWPOWER: +static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, + u64 tsf) +{ + struct vnt_private *priv = hw->priv; - rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL); - break; + CARDvUpdateNextTBTT(priv, tsf, vif->bss_conf.beacon_int); +} - case SIOCSIWPOWER: +static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) +{ + struct vnt_private *priv = hw->priv; - rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL); - break; + /* reset TSF counter */ + VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST); +} - case SIOCGIWSENS: +static const struct ieee80211_ops vnt_mac_ops = { + .tx = vnt_tx_80211, + .start = vnt_start, + .stop = vnt_stop, + .add_interface = vnt_add_interface, + .remove_interface = vnt_remove_interface, + .config = vnt_config, + .bss_info_changed = vnt_bss_info_changed, + .prepare_multicast = vnt_prepare_multicast, + .configure_filter = vnt_configure, + .set_key = vnt_set_key, + .get_tsf = vnt_get_tsf, + .set_tsf = vnt_set_tsf, + .reset_tsf = vnt_reset_tsf, +}; - rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL); - break; +int vnt_init(struct vnt_private *priv) +{ + SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr); - case SIOCSIWSENS: - pr_debug(" SIOCSIWSENS\n"); - rc = -EOPNOTSUPP; - break; + vnt_init_bands(priv); - case SIOCGIWAPLIST: { - char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))]; - - if (wrq->u.data.pointer) { - rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer); - if (rc == 0) { - if (copy_to_user(wrq->u.data.pointer, - buffer, - (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality))) - )) - rc = -EFAULT; - } - } - } - break; + if (ieee80211_register_hw(priv->hw)) + return -ENODEV; -#ifdef WIRELESS_SPY - // Set the spy list - case SIOCSIWSPY: + priv->mac_hw = true; - pr_debug(" SIOCSIWSPY\n"); - rc = -EOPNOTSUPP; - break; + CARDbRadioPowerOff(priv); - // Get the spy list - case SIOCGIWSPY: + return 0; +} - pr_debug(" SIOCGIWSPY\n"); - rc = -EOPNOTSUPP; - break; +static int +vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent) +{ + PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data; + struct vnt_private *priv; + struct ieee80211_hw *hw; + struct wiphy *wiphy; + int rc; -#endif // WIRELESS_SPY + dev_notice(&pcid->dev, + "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION); - case SIOCGIWPRIV: - pr_debug(" SIOCGIWPRIV\n"); - rc = -EOPNOTSUPP; - break; + dev_notice(&pcid->dev, + "Copyright (c) 2003 VIA Networking Technologies, Inc.\n"); -//2008-0409-07, <Add> by Einsn Liu -#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT - case SIOCSIWAUTH: - pr_debug(" SIOCSIWAUTH\n"); - rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL); - break; + hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops); + if (!hw) { + dev_err(&pcid->dev, "could not register ieee80211_hw\n"); + return -ENOMEM; + } - case SIOCGIWAUTH: - pr_debug(" SIOCGIWAUTH\n"); - rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL); - break; + priv = hw->priv; - case SIOCSIWGENIE: - pr_debug(" SIOCSIWGENIE\n"); - rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer); - break; + vt6655_init_info(pcid, &priv, pChip_info); - case SIOCGIWGENIE: - pr_debug(" SIOCGIWGENIE\n"); - rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer); - break; + priv->hw = hw; - case SIOCSIWENCODEEXT: { - char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1]; + SET_IEEE80211_DEV(priv->hw, &pcid->dev); - pr_debug(" SIOCSIWENCODEEXT\n"); - if (wrq->u.encoding.pointer) { - memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1); - if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) { - rc = -E2BIG; - break; - } - if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) { - rc = -EFAULT; - break; - } - } else if (wrq->u.encoding.length != 0) { - rc = -EINVAL; - break; - } - rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra); + if (pci_enable_device(pcid)) { + device_free_info(priv); + return -ENODEV; } - break; - case SIOCGIWENCODEEXT: - pr_debug(" SIOCGIWENCODEEXT\n"); - rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL); - break; + dev_dbg(&pcid->dev, + "Before get pci_info memaddr is %x\n", priv->memaddr); - case SIOCSIWMLME: - pr_debug(" SIOCSIWMLME\n"); - rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer); - break; + if (!device_get_pci_info(priv, pcid)) { + dev_err(&pcid->dev, ": Failed to find PCI device.\n"); + device_free_info(priv); + return -ENODEV; + } -#endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT -//End Add -- //2008-0409-07, <Add> by Einsn Liu +#ifdef DEBUG + dev_dbg(&pcid->dev, + "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n", + priv->memaddr, priv->ioaddr, priv->io_size); + { + int i; + u32 bar, len; + u32 address[] = { + PCI_BASE_ADDRESS_0, + PCI_BASE_ADDRESS_1, + PCI_BASE_ADDRESS_2, + PCI_BASE_ADDRESS_3, + PCI_BASE_ADDRESS_4, + PCI_BASE_ADDRESS_5, + 0}; + for (i = 0; address[i]; i++) { + pci_read_config_dword(pcid, address[i], &bar); - case IOCTL_CMD_TEST: + dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar); - if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) { - rc = -EFAULT; - break; - } else { - rc = 0; - } - pReq = (PSCmdRequest)rq; - pReq->wResult = MAGIC_CODE; - break; + if (!bar) { + dev_dbg(&pcid->dev, + "bar %d not implemented\n", i); + continue; + } - case IOCTL_CMD_SET: + if (bar & PCI_BASE_ADDRESS_SPACE_IO) { + /* This is IO */ -#ifdef SndEvt_ToAPI - if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) && - !(pDevice->flags & DEVICE_FLAGS_OPENED)) -#else - if (!(pDevice->flags & DEVICE_FLAGS_OPENED) && - (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA)) -#endif - { - rc = -EFAULT; - break; + len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff); + len = len & ~(len - 1); + + dev_dbg(&pcid->dev, + "IO space: len in IO %x, BAR %d\n", + len, i); } else { - rc = 0; + len = bar & 0xfffffff0; + len = ~len + 1; + + dev_dbg(&pcid->dev, + "len in MEM %x, BAR %d\n", len, i); } + } + } +#endif - if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy))) - return -EBUSY; + priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK, + priv->io_size); + if (!priv->PortOffset) { + dev_err(&pcid->dev, ": Failed to IO remapping ..\n"); + device_free_info(priv); + return -ENODEV; + } - rc = private_ioctl(pDevice, rq); - clear_bit(0, (void *)&(pMgmt->uCmdBusy)); - break; + rc = pci_request_regions(pcid, DEVICE_NAME); + if (rc) { + dev_err(&pcid->dev, ": Failed to find PCI device\n"); + device_free_info(priv); + return -ENODEV; + } - case IOCTL_CMD_HOSTAPD: + /* do reset */ + if (!MACbSoftwareReset(priv->PortOffset)) { + dev_err(&pcid->dev, ": Failed to access MAC hardware..\n"); + device_free_info(priv); + return -ENODEV; + } + /* initial to reload eeprom */ + MACvInitialize(priv->PortOffset); + MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr); - rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data); - break; + device_get_options(priv); + device_set_options(priv); + /* Mask out the options cannot be set to the chip */ + priv->sOpts.flags &= pChip_info->flags; - case IOCTL_CMD_WPA: + /* Enable the chip specified capabilities */ + priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL); - rc = wpa_ioctl(pDevice, &wrq->u.data); - break; + wiphy = priv->hw->wiphy; - case SIOCETHTOOL: - return ethtool_ioctl(dev, rq->ifr_data); - // All other calls are currently unsupported + wiphy->frag_threshold = FRAG_THRESH_DEF; + wiphy->rts_threshold = RTS_THRESH_DEF; + wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | + BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP); - default: - rc = -EOPNOTSUPP; - pr_debug("Ioctl command not support..%x\n", cmd); + priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | + IEEE80211_HW_REPORTS_TX_ACK_STATUS | + IEEE80211_HW_SIGNAL_DBM | + IEEE80211_HW_TIMING_BEACON_ONLY; - } + priv->hw->max_signal = 100; - if (pDevice->bCommit) { - if (pMgmt->eConfigMode == WMAC_CONFIG_AP) { - netif_stop_queue(pDevice->dev); - spin_lock_irq(&pDevice->lock); - bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL); - spin_unlock_irq(&pDevice->lock); - } else { - pr_debug("Commit the settings\n"); - spin_lock_irq(&pDevice->lock); - pDevice->bLinkPass = false; - memset(pMgmt->abyCurrBSSID, 0, 6); - pMgmt->eCurrState = WMAC_STATE_IDLE; - netif_stop_queue(pDevice->dev); -#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT - pMgmt->eScanType = WMAC_SCAN_ACTIVE; - if (!pDevice->bWPASuppWextEnabled) -#endif - bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID); - bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL); - spin_unlock_irq(&pDevice->lock); - } - pDevice->bCommit = false; - } + if (vnt_init(priv)) + return -ENODEV; - return rc; + device_print_info(priv); + pci_set_drvdata(pcid, priv); + + return 0; } -static int ethtool_ioctl(struct net_device *dev, void __user *useraddr) +/*------------------------------------------------------------------*/ + +#ifdef CONFIG_PM +static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state) { - u32 ethcmd; + struct vnt_private *priv = pci_get_drvdata(pcid); + unsigned long flags; - if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) - return -EFAULT; + spin_lock_irqsave(&priv->lock, flags); - switch (ethcmd) { - case ETHTOOL_GDRVINFO: { - struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO}; + pci_save_state(pcid); - strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1); - strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1); - if (copy_to_user(useraddr, &info, sizeof(info))) - return -EFAULT; - return 0; - } + MACbShutdown(priv->PortOffset); - } + pci_disable_device(pcid); + pci_set_power_state(pcid, pci_choose_state(pcid, state)); + + spin_unlock_irqrestore(&priv->lock, flags); - return -EOPNOTSUPP; + return 0; } -/*------------------------------------------------------------------*/ +static int vt6655_resume(struct pci_dev *pcid) +{ + + pci_set_power_state(pcid, PCI_D0); + pci_enable_wake(pcid, PCI_D0, 0); + pci_restore_state(pcid); + + return 0; +} +#endif MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table); @@ -3025,8 +1871,8 @@ static struct pci_driver device_driver = { .probe = vt6655_probe, .remove = vt6655_remove, #ifdef CONFIG_PM - .suspend = viawget_suspend, - .resume = viawget_resume, + .suspend = vt6655_suspend, + .resume = vt6655_resume, #endif }; @@ -3067,75 +1913,10 @@ device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p) for_each_pci_dev(pdev) { if (pci_dev_driver(pdev) == &device_driver) { if (pci_get_drvdata(pdev)) - viawget_suspend(pdev, PMSG_HIBERNATE); + vt6655_suspend(pdev, PMSG_HIBERNATE); } } } return NOTIFY_DONE; } - -static int -viawget_suspend(struct pci_dev *pcid, pm_message_t state) -{ - int power_status; // to silence the compiler - - struct vnt_private *pDevice = pci_get_drvdata(pcid); - PSMgmtObject pMgmt = pDevice->pMgmt; - - netif_stop_queue(pDevice->dev); - spin_lock_irq(&pDevice->lock); - pci_save_state(pcid); - del_timer(&pDevice->sTimerCommand); - del_timer(&pMgmt->sTimerSecondCallback); - pDevice->cbFreeCmdQueue = CMD_Q_SIZE; - pDevice->uCmdDequeueIdx = 0; - pDevice->uCmdEnqueueIdx = 0; - pDevice->bCmdRunning = false; - MACbShutdown(pDevice->PortOffset); - MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext); - pDevice->bLinkPass = false; - memset(pMgmt->abyCurrBSSID, 0, 6); - pMgmt->eCurrState = WMAC_STATE_IDLE; - pci_disable_device(pcid); - power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state)); - spin_unlock_irq(&pDevice->lock); - return 0; -} - -static int -viawget_resume(struct pci_dev *pcid) -{ - struct vnt_private *pDevice = pci_get_drvdata(pcid); - PSMgmtObject pMgmt = pDevice->pMgmt; - int power_status; // to silence the compiler - - power_status = pci_set_power_state(pcid, PCI_D0); - power_status = pci_enable_wake(pcid, PCI_D0, 0); - pci_restore_state(pcid); - if (netif_running(pDevice->dev)) { - spin_lock_irq(&pDevice->lock); - MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext); - device_init_registers(pDevice); - if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS - pMgmt->sNodeDBTable[0].bActive = false; - pDevice->bLinkPass = false; - if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { - // In Adhoc, BSS state set back to started. - pMgmt->eCurrState = WMAC_STATE_STARTED; - } else { - pMgmt->eCurrMode = WMAC_MODE_STANDBY; - pMgmt->eCurrState = WMAC_STATE_IDLE; - } - } - init_timer(&pMgmt->sTimerSecondCallback); - init_timer(&pDevice->sTimerCommand); - MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE); - BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass); - bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL); - bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL); - spin_unlock_irq(&pDevice->lock); - } - return 0; -} - #endif |