Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
[firefly-linux-kernel-4.4.55.git] / drivers / staging / vt6655 / device_main.c
index 7892f861521e9ba61ae8f07619182af21339171b..83e4162c0094c4b2bed6853bc8cfb5636011191a 100644 (file)
  *   device_intr - interrupt handle function
  *   device_rx_srv - rx service 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_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
  *
@@ -58,7 +55,6 @@
 #include "channel.h"
 #include "baseband.h"
 #include "mac.h"
-#include "wmgr.h"
 #include "power.h"
 #include "rxtx.h"
 #include "dpc.h"
@@ -97,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
@@ -203,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");
@@ -257,7 +166,6 @@ 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);
 
@@ -271,7 +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);
 
 /*---------------------  Export Variables  --------------------------*/
 
@@ -304,63 +211,31 @@ 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};
-
-       ether_addr_copy(pDevice->abyBroadcastAddr, abyBroadcastAddr);
-       ether_addr_copy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042);
-       ether_addr_copy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel);
-
-       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->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(" 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);
 }
@@ -379,7 +254,7 @@ static void device_init_registers(struct vnt_private *pDevice)
        unsigned char byOFDMPwrdBm = 0;
 
        MACbShutdown(pDevice->PortOffset);
-       BBvSoftwareReset(pDevice->PortOffset);
+       BBvSoftwareReset(pDevice);
 
        /* Do MACbSoftwareReset in MACvInitialize */
        MACbSoftwareReset(pDevice->PortOffset);
@@ -571,15 +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);
+       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;
+       pDevice->wCurrentRate = RATE_54M;
 
        pDevice->bRadioOff = false;
 
@@ -625,17 +497,17 @@ 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);
 }
 
@@ -854,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;
@@ -903,20 +760,6 @@ static void device_free_rd1_ring(struct vnt_private *pDevice)
        }
 }
 
-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);
-
-       }
-}
-
 static void device_init_td0_ring(struct vnt_private *pDevice)
 {
        int i;
@@ -1057,17 +900,6 @@ 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)
-{
-       pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-       if (pDeF->skb == NULL)
-               return false;
-       ASSERT(pDeF->skb);
-
-       return true;
-}
-
 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},
@@ -1182,10 +1014,6 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
                        }
                        device_free_tx_buf(pDevice, pTD);
                        pDevice->iTDUsed[uIdx]--;
-
-                       /* Make sure queue is available */
-                       if (AVAIL_TD(pDevice, uIdx))
-                               ieee80211_wake_queues(pDevice->hw);
                }
        }
 
@@ -1358,6 +1186,14 @@ static  irqreturn_t  device_intr(int irq,  void *dev_instance)
                        }
                }
 
+               /* 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);
 
                MACvReceive0(pDevice->PortOffset);
@@ -1467,7 +1303,6 @@ static int vnt_start(struct ieee80211_hw *hw)
        dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
        device_init_rd0_ring(priv);
        device_init_rd1_ring(priv);
-       device_init_defrag_cb(priv);
        device_init_td0_ring(priv);
        device_init_td1_ring(priv);
 
@@ -1495,7 +1330,6 @@ static void vnt_stop(struct ieee80211_hw *hw)
        device_free_td1_ring(priv);
        device_free_rd0_ring(priv);
        device_free_rd1_ring(priv);
-       device_free_frag_buf(priv);
        device_free_rings(priv);
 
        free_irq(priv->pcid->irq, priv);
@@ -1591,8 +1425,7 @@ static int vnt_config(struct ieee80211_hw *hw, u32 changed)
                if (priv->byBBType != bb_type) {
                        priv->byBBType = bb_type;
 
-                       CARDbSetPhyParameter(priv,
-                                            priv->byBBType, 0, 0, NULL, NULL);
+                       CARDbSetPhyParameter(priv, priv->byBBType);
                }
        }
 
@@ -1652,8 +1485,7 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
                else
                        priv->bShortSlotTime = false;
 
-               vUpdateIFS(priv);
-               CARDbSetPhyParameter(priv, priv->byBBType, 0, 0, NULL, NULL);
+               CARDbSetPhyParameter(priv, priv->byBBType);
                BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
        }
 
@@ -1681,8 +1513,7 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
 
                        CARDbSetBeaconPeriod(priv, conf->beacon_int);
 
-                       CARDvSetFirstNextTBTT(priv->PortOffset,
-                                             conf->beacon_int);
+                       CARDvSetFirstNextTBTT(priv, conf->beacon_int);
                } else {
                        VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
                                     TFTCTL_TSFCNTRST);
@@ -1801,7 +1632,7 @@ static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
        struct vnt_private *priv = hw->priv;
        u64 tsf;
 
-       CARDbGetCurrentTSF(priv->PortOffset, &tsf);
+       CARDbGetCurrentTSF(priv, &tsf);
 
        return tsf;
 }
@@ -1811,7 +1642,7 @@ static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 {
        struct vnt_private *priv = hw->priv;
 
-       CARDvUpdateNextTBTT(priv->PortOffset, tsf, vif->bss_conf.beacon_int);
+       CARDvUpdateNextTBTT(priv, tsf, vif->bss_conf.beacon_int);
 }
 
 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)