Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/dlm
[sfrench/cifs-2.6.git] / drivers / staging / vt6656 / main_usb.c
index 098b0455e3255c6029d1092c0a77172902210b46..c528ef0f8ed4c81872728f8c659f021ecc26c1b2 100644 (file)
@@ -366,7 +366,7 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
     BYTE            byAntenna;
     unsigned int            ii;
     CMD_CARD_INIT   sInitCmd;
-    NTSTATUS        ntStatus = STATUS_SUCCESS;
+    int ntStatus = STATUS_SUCCESS;
     RSP_CARD_INIT   sInitRsp;
     PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
     BYTE            byTmp;
@@ -407,8 +407,8 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
 
     sInitCmd.byInitClass = (BYTE)InitType;
     sInitCmd.bExistSWNetAddr = (BYTE) pDevice->bExistSWNetAddr;
-    for(ii=0;ii<6;ii++)
-        sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii];
+    for (ii = 0; ii < 6; ii++)
+       sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii];
     sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit;
     sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit;
 
@@ -487,10 +487,10 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
           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];
+               }
          }
 
         //{{ RobertYu: 20041124
@@ -718,33 +718,32 @@ static BOOL device_release_WPADEV(PSDevice pDevice)
 
 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
 {
- PSDevice  pDevice = usb_get_intfdata(intf);
- struct net_device *dev = pDevice->dev;
+       PSDevice device = usb_get_intfdata(intf);
 
- printk("VNTWUSB Suspend Start======>\n");
-if(dev != NULL) {
-  if(pDevice->flags & DEVICE_FLAGS_OPENED)
-     device_close(dev);
-}
+       if (!device || !device->dev)
+               return -ENODEV;
 
- usb_put_dev(interface_to_usbdev(intf));
- return 0;
+       if (device->flags & DEVICE_FLAGS_OPENED)
+               device_close(device->dev);
+
+       usb_put_dev(interface_to_usbdev(intf));
+
+       return 0;
 }
 
 static int vt6656_resume(struct usb_interface *intf)
 {
- PSDevice  pDevice = usb_get_intfdata(intf);
- struct net_device *dev = pDevice->dev;
-
- printk("VNTWUSB Resume Start======>\n");
- if(dev != NULL) {
-  usb_get_dev(interface_to_usbdev(intf));
-  if(!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
-    if(device_open(dev)!=0)
-        printk("VNTWUSB Resume Start======>open fail\n");
-   }
- }
- return 0;
+       PSDevice device = usb_get_intfdata(intf);
+
+       if (!device || !device->dev)
+               return -ENODEV;
+
+       usb_get_dev(interface_to_usbdev(intf));
+
+       if (!(device->flags & DEVICE_FLAGS_OPENED))
+               device_open(device->dev);
+
+       return 0;
 }
 
 #endif /* CONFIG_PM */
@@ -758,93 +757,75 @@ static const struct net_device_ops device_netdev_ops = {
     .ndo_set_multicast_list = device_set_multi,
 };
 
-
 static int __devinit
 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
 {
        u8 fake_mac[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
        struct usb_device *udev = interface_to_usbdev(intf);
-    int         rc = 0;
-    struct net_device *netdev = NULL;
-    PSDevice    pDevice = NULL;
-
+       int rc = 0;
+       struct net_device *netdev = NULL;
+       PSDevice pDevice = NULL;
 
-    printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
-    printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
+       printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
+       printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
 
-  udev = usb_get_dev(udev);
-
-    netdev = alloc_etherdev(sizeof(DEVICE_INFO));
-
-    if (netdev == NULL) {
-        printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
-        kfree(pDevice);
-           goto err_nomem;
-    }
+       udev = usb_get_dev(udev);
+       netdev = alloc_etherdev(sizeof(DEVICE_INFO));
 
-    pDevice = netdev_priv(netdev);
-    memset(pDevice, 0, sizeof(DEVICE_INFO));
+       if (!netdev) {
+               printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n");
+               kfree(pDevice);
+               goto err_nomem;
+       }
 
-    pDevice->dev = netdev;
-    pDevice->usb = udev;
+       pDevice = netdev_priv(netdev);
+       memset(pDevice, 0, sizeof(DEVICE_INFO));
 
-    // Set initial settings
-    device_set_options(pDevice);
-    spin_lock_init(&pDevice->lock);
+       pDevice->dev = netdev;
+       pDevice->usb = udev;
 
-    pDevice->tx_80211 = device_dma0_tx_80211;
-    pDevice->sMgmtObj.pAdapter = (void *)pDevice;
+       device_set_options(pDevice);
+       spin_lock_init(&pDevice->lock);
 
-    netdev->netdev_ops         = &device_netdev_ops;
+       pDevice->tx_80211 = device_dma0_tx_80211;
+       pDevice->sMgmtObj.pAdapter = (void *) pDevice;
 
-       netdev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
+       netdev->netdev_ops = &device_netdev_ops;
+       netdev->wireless_handlers =
+               (struct iw_handler_def *) &iwctl_handler_def;
 
-   //2008-0623-01<Remark>by MikeLiu
-  //2007-0821-01<Add>by MikeLiu
-         usb_set_intfdata(intf, pDevice);
+       usb_set_intfdata(intf, pDevice);
        SET_NETDEV_DEV(netdev, &intf->dev);
-    memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN);
-    rc = register_netdev(netdev);
-    if (rc != 0) {
-        printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
+       memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN);
+       rc = register_netdev(netdev);
+       if (rc) {
+               printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
                free_netdev(netdev);
-        kfree(pDevice);
-        return -ENODEV;
-    }
-
-//2008-07-21-01<Add>by MikeLiu
-//register wpadev
-#if 0
-   if(wpa_set_wpadev(pDevice, 1)!=0) {
-     printk("Fail to Register WPADEV?\n");
-        unregister_netdev(pDevice->dev);
-        free_netdev(netdev);
-        kfree(pDevice);
-   }
-#endif
-         usb_device_reset(pDevice);
+               kfree(pDevice);
+               return -ENODEV;
+       }
 
-#ifdef SndEvt_ToAPI
-{
-  union iwreq_data      wrqu;
-  memset(&wrqu, 0, sizeof(wrqu));
-  wrqu.data.flags = RT_INSMOD_EVENT_FLAG;
-  wrqu.data.length =IFNAMSIZ;
-  wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pDevice->dev->name);
-}
-#endif
+       usb_device_reset(pDevice);
+
+       {
+               union iwreq_data wrqu;
+               memset(&wrqu, 0, sizeof(wrqu));
+               wrqu.data.flags = RT_INSMOD_EVENT_FLAG;
+               wrqu.data.length = IFNAMSIZ;
+               wireless_send_event(pDevice->dev,
+                                   IWEVCUSTOM,
+                                   &wrqu,
+                                   pDevice->dev->name);
+       }
 
        return 0;
 
-
 err_nomem:
- //2008-0922-01<Add>by MikeLiu, decrease usb counter.
-    usb_put_dev(udev);
+       usb_put_dev(udev);
 
-    return -ENOMEM;
+       return -ENOMEM;
 }
 
-
 static void device_free_tx_bufs(PSDevice pDevice)
 {
     PUSB_SEND_CONTEXT pTxContext;
@@ -1065,7 +1046,6 @@ BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
 static int  device_open(struct net_device *dev) {
     PSDevice    pDevice=(PSDevice) netdev_priv(dev);
 
-#ifdef WPA_SM_Transtatus
      extern SWPAResult wpa_Result;
      memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
      wpa_Result.proto = 0;
@@ -1073,7 +1053,6 @@ static int  device_open(struct net_device *dev) {
      wpa_Result.eap_type = 0;
      wpa_Result.authenticated = FALSE;
      pDevice->fWPA_Authened = FALSE;
-#endif
 
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
 
@@ -1172,14 +1151,12 @@ static int  device_open(struct net_device *dev) {
     netif_stop_queue(pDevice->dev);
     pDevice->flags |= DEVICE_FLAGS_OPENED;
 
-#ifdef SndEvt_ToAPI
 {
   union iwreq_data      wrqu;
   memset(&wrqu, 0, sizeof(wrqu));
   wrqu.data.flags = RT_UPDEV_EVENT_FLAG;
   wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
 }
-#endif
 
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
     return 0;
@@ -1211,14 +1188,12 @@ static int  device_close(struct net_device *dev) {
     if (pDevice == NULL)
         return -ENODEV;
 
-#ifdef SndEvt_ToAPI
 {
   union iwreq_data      wrqu;
   memset(&wrqu, 0, sizeof(wrqu));
   wrqu.data.flags = RT_DOWNDEV_EVENT_FLAG;
   wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
 }
-#endif
 
 //2007-1121-02<Add>by EinsnLiu
     if (pDevice->bLinkPass) {
@@ -1234,10 +1209,10 @@ device_release_WPADEV(pDevice);
         pMgmt->bShareKeyAlgorithm = FALSE;
         pDevice->bEncryptionEnable = FALSE;
         pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
-            spin_lock_irq(&pDevice->lock);
-            for(uu=0;uu<MAX_KEY_TABLE;uu++)
+       spin_lock_irq(&pDevice->lock);
+       for (uu = 0; uu < MAX_KEY_TABLE; uu++)
                 MACvDisableKeyEntry(pDevice,uu);
-            spin_unlock_irq(&pDevice->lock);
+       spin_unlock_irq(&pDevice->lock);
 
     if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == FALSE) {
         MACbShutdown(pDevice);
@@ -1250,10 +1225,7 @@ device_release_WPADEV(pDevice);
     del_timer(&pDevice->sTimerCommand);
     del_timer(&pMgmt->sTimerSecondCallback);
 
-//2007-0115-02<Add>by MikeLiu
-#ifdef TxInSleep
     del_timer(&pDevice->sTimerTxData);
-#endif
 
     if (pDevice->bDiversityRegCtlON) {
         del_timer(&pDevice->TimerSQ3Tmax1);
@@ -1290,112 +1262,81 @@ device_release_WPADEV(pDevice);
     return 0;
 }
 
-
 static void __devexit vt6656_disconnect(struct usb_interface *intf)
 {
+       PSDevice device = usb_get_intfdata(intf);
 
-       PSDevice  pDevice = usb_get_intfdata(intf);
+       if (!device)
+               return;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_disconnect1.. \n");
-    if (pDevice == NULL)
-        return;
-
-#ifdef SndEvt_ToAPI
-{
-  union iwreq_data      wrqu;
-  memset(&wrqu, 0, sizeof(wrqu));
-  wrqu.data.flags = RT_RMMOD_EVENT_FLAG;
-  wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
-}
-#endif
+       {
+               union iwreq_data req;
+               memset(&req, 0, sizeof(req));
+               req.data.flags = RT_RMMOD_EVENT_FLAG;
+               wireless_send_event(device->dev, IWEVCUSTOM, &req, NULL);
+       }
 
-//2008-0714-01<Add>by MikeLiu
-device_release_WPADEV(pDevice);
+       device_release_WPADEV(device);
 
        usb_set_intfdata(intf, NULL);
-//2008-0922-01<Add>by MikeLiu, decrease usb counter.
-     usb_put_dev(interface_to_usbdev(intf));
+       usb_put_dev(interface_to_usbdev(intf));
 
-    pDevice->flags |= DEVICE_FLAGS_UNPLUG;
-    if (pDevice->dev != NULL) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "unregister_netdev..\n");
-        unregister_netdev(pDevice->dev);
+       device->flags |= DEVICE_FLAGS_UNPLUG;
 
-//2008-07-21-01<Add>by MikeLiu
-//unregister wpadev
-   if(wpa_set_wpadev(pDevice, 0)!=0)
-     printk("unregister wpadev fail?\n");
-
-        free_netdev(pDevice->dev);
-    }
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_disconnect3.. \n");
+       if (device->dev) {
+               unregister_netdev(device->dev);
+               wpa_set_wpadev(device, 0);
+               free_netdev(device->dev);
+       }
 }
 
+static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
+{
+       PSDevice pDevice = netdev_priv(dev);
 
+       spin_lock_irq(&pDevice->lock);
 
+       if (unlikely(pDevice->bStopTx0Pkt))
+               dev_kfree_skb_irq(skb);
+       else
+               vDMA0_tx_80211(pDevice, skb);
 
-static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
-    PSDevice        pDevice=netdev_priv(dev);
-    PBYTE           pbMPDU;
-    unsigned int            cbMPDULen = 0;
-
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
-    spin_lock_irq(&pDevice->lock);
-
-    if (pDevice->bStopTx0Pkt == TRUE) {
-        dev_kfree_skb_irq(skb);
-        spin_unlock_irq(&pDevice->lock);
-        return 0;
-    };
-
-
-    cbMPDULen = skb->len;
-    pbMPDU = skb->data;
-
-    vDMA0_tx_80211(pDevice, skb);
-
-    spin_unlock_irq(&pDevice->lock);
-
-    return 0;
+       spin_unlock_irq(&pDevice->lock);
 
+       return NETDEV_TX_OK;
 }
 
+static int device_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       PSDevice pDevice = netdev_priv(dev);
+       struct net_device_stats *stats = &pDevice->stats;
 
-static int  device_xmit(struct sk_buff *skb, struct net_device *dev) {
-    PSDevice    pDevice=netdev_priv(dev);
-    struct net_device_stats* pStats = &pDevice->stats;
-
+       spin_lock_irq(&pDevice->lock);
 
-    spin_lock_irq(&pDevice->lock);
+       netif_stop_queue(dev);
 
-    netif_stop_queue(pDevice->dev);
+       if (!pDevice->bLinkPass) {
+               dev_kfree_skb_irq(skb);
+               goto out;
+       }
 
-    if (pDevice->bLinkPass == FALSE) {
-        dev_kfree_skb_irq(skb);
-        spin_unlock_irq(&pDevice->lock);
-        return 0;
-    }
-    if (pDevice->bStopDataPkt == TRUE) {
-        dev_kfree_skb_irq(skb);
-        pStats->tx_dropped++;
-        spin_unlock_irq(&pDevice->lock);
-        return 0;
-    }
+       if (pDevice->bStopDataPkt) {
+               dev_kfree_skb_irq(skb);
+               stats->tx_dropped++;
+               goto out;
+       }
 
-    if(nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) !=0) {  //mike add:xmit fail!
-         if (netif_queue_stopped(pDevice->dev))
-              netif_wake_queue(pDevice->dev);
-    }
+       if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb)) {
+               if (netif_queue_stopped(dev))
+                       netif_wake_queue(dev);
+       }
 
-    spin_unlock_irq(&pDevice->lock);
+out:
+       spin_unlock_irq(&pDevice->lock);
 
-    return 0;
+       return NETDEV_TX_OK;
 }
 
-
-
 static unsigned const ethernet_polynomial = 0x04c11db7U;
 static inline u32 ether_crc(int length, unsigned char *data)
 {
@@ -1447,12 +1388,12 @@ static int Config_FileGetParameter(unsigned char *string,
        return FALSE;
 
 //check if current config line is marked by "#" ??
-for(ii=1;;ii++) {
-  if(memcmp(start_p-ii,"\n",1)==0)
-      break;
-  if(memcmp(start_p-ii,"#",1)==0)
-      return FALSE;
-}
+    for (ii = 1; ; ii++) {
+       if (memcmp(start_p - ii, "\n", 1) == 0)
+               break;
+       if (memcmp(start_p - ii, "#", 1) == 0)
+               return FALSE;
+    }
 
 //find target string end point
      end_p = kstrstr(start_p,"\n");
@@ -1585,7 +1526,6 @@ static int Read_config_file(PSDevice pDevice) {
  }
 }
 
-#if 1
 //get other parameter
   {
        memset(tmpbuffer,0,sizeof(tmpbuffer));
@@ -1598,7 +1538,6 @@ static int Read_config_file(PSDevice pDevice) {
         pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
        }
   }
-#endif
 
   kfree(buffer);
   return result;