nilfs2: segment usage file
[linux-2.6] / drivers / staging / rt2870 / rt_main_dev.c
1 /*
2  *************************************************************************
3  * Ralink Tech Inc.
4  * 5F., No.36, Taiyuan St., Jhubei City,
5  * Hsinchu County 302,
6  * Taiwan, R.O.C.
7  *
8  * (c) Copyright 2002-2007, Ralink Technology, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify  *
11  * it under the terms of the GNU General Public License as published by  *
12  * the Free Software Foundation; either version 2 of the License, or     *
13  * (at your option) any later version.                                   *
14  *                                                                       *
15  * This program is distributed in the hope that it will be useful,       *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  * GNU General Public License for more details.                          *
19  *                                                                       *
20  * You should have received a copy of the GNU General Public License     *
21  * along with this program; if not, write to the                         *
22  * Free Software Foundation, Inc.,                                       *
23  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24  *                                                                       *
25  *************************************************************************
26
27     Module Name:
28     rt_main_dev.c
29
30     Abstract:
31     Create and register network interface.
32
33     Revision History:
34     Who         When            What
35     --------    ----------      ----------------------------------------------
36         Sample          Mar/21/07               Merge RT2870 and RT2860 drivers.
37 */
38
39 #include "rt_config.h"
40
41 #define FORTY_MHZ_INTOLERANT_INTERVAL   (60*1000) // 1 min
42
43 #ifdef MULTIPLE_CARD_SUPPORT
44 // record whether the card in the card list is used in the card file
45 UINT8  MC_CardUsed[MAX_NUM_OF_MULTIPLE_CARD];
46 // record used card mac address in the card list
47 static UINT8  MC_CardMac[MAX_NUM_OF_MULTIPLE_CARD][6];
48 #endif // MULTIPLE_CARD_SUPPORT //
49
50 /*---------------------------------------------------------------------*/
51 /* Private Variables Used                                              */
52 /*---------------------------------------------------------------------*/
53 //static RALINK_TIMER_STRUCT     PeriodicTimer;
54
55 char *mac = "";            // default 00:00:00:00:00:00
56 char *hostname = "";
57 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,12)
58 MODULE_PARM (mac, "s");
59 #else
60 module_param (mac, charp, 0);
61 #endif
62 MODULE_PARM_DESC (mac, "rt28xx: wireless mac addr");
63
64
65 /*---------------------------------------------------------------------*/
66 /* Prototypes of Functions Used                                        */
67 /*---------------------------------------------------------------------*/
68 #ifdef DOT11_N_SUPPORT
69 extern BOOLEAN ba_reordering_resource_init(PRTMP_ADAPTER pAd, int num);
70 extern void ba_reordering_resource_release(PRTMP_ADAPTER pAd);
71 #endif // DOT11_N_SUPPORT //
72 extern NDIS_STATUS NICLoadRateSwitchingParams(IN PRTMP_ADAPTER pAd);
73
74
75 // public function prototype
76 INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
77                                                         IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
78
79 // private function prototype
80 static int rt28xx_init(IN struct net_device *net_dev);
81 INT rt28xx_send_packets(IN struct sk_buff *skb_p, IN struct net_device *net_dev);
82
83 #if LINUX_VERSION_CODE <= 0x20402       // Red Hat 7.1
84 struct net_device *alloc_netdev(
85         int sizeof_priv,
86         const char *mask,
87         void (*setup)(struct net_device *));
88 #endif // LINUX_VERSION_CODE //
89
90 static void CfgInitHook(PRTMP_ADAPTER pAd);
91 //static BOOLEAN RT28XXAvailRANameAssign(IN CHAR *name_p);
92
93 #ifdef CONFIG_STA_SUPPORT
94 extern  const struct iw_handler_def rt28xx_iw_handler_def;
95 #endif // CONFIG_STA_SUPPORT //
96
97 #if WIRELESS_EXT >= 12
98 // This function will be called when query /proc
99 struct iw_statistics *rt28xx_get_wireless_stats(
100     IN struct net_device *net_dev);
101 #endif
102
103 struct net_device_stats *RT28xx_get_ether_stats(
104     IN  struct net_device *net_dev);
105
106 /*
107 ========================================================================
108 Routine Description:
109     Close raxx interface.
110
111 Arguments:
112         *net_dev                        the raxx interface pointer
113
114 Return Value:
115     0                                   Open OK
116         otherwise                       Open Fail
117
118 Note:
119         1. if open fail, kernel will not call the close function.
120         2. Free memory for
121                 (1) Mlme Memory Handler:                MlmeHalt()
122                 (2) TX & RX:                                    RTMPFreeTxRxRingMemory()
123                 (3) BA Reordering:                              ba_reordering_resource_release()
124 ========================================================================
125 */
126 int MainVirtualIF_close(IN struct net_device *net_dev)
127 {
128     RTMP_ADAPTER *pAd = net_dev->ml_priv;
129
130         // Sanity check for pAd
131         if (pAd == NULL)
132                 return 0; // close ok
133
134         netif_carrier_off(pAd->net_dev);
135         netif_stop_queue(pAd->net_dev);
136
137
138
139         VIRTUAL_IF_DOWN(pAd);
140
141         RT_MOD_DEC_USE_COUNT();
142
143         return 0; // close ok
144 }
145
146 /*
147 ========================================================================
148 Routine Description:
149     Open raxx interface.
150
151 Arguments:
152         *net_dev                        the raxx interface pointer
153
154 Return Value:
155     0                                   Open OK
156         otherwise                       Open Fail
157
158 Note:
159         1. if open fail, kernel will not call the close function.
160         2. Free memory for
161                 (1) Mlme Memory Handler:                MlmeHalt()
162                 (2) TX & RX:                                    RTMPFreeTxRxRingMemory()
163                 (3) BA Reordering:                              ba_reordering_resource_release()
164 ========================================================================
165 */
166 int MainVirtualIF_open(IN struct net_device *net_dev)
167 {
168     RTMP_ADAPTER *pAd = net_dev->ml_priv;
169
170         // Sanity check for pAd
171         if (pAd == NULL)
172                 return 0; // close ok
173
174         if (VIRTUAL_IF_UP(pAd) != 0)
175                 return -1;
176
177         // increase MODULE use count
178         RT_MOD_INC_USE_COUNT();
179
180         netif_start_queue(net_dev);
181         netif_carrier_on(net_dev);
182         netif_wake_queue(net_dev);
183
184         return 0;
185 }
186
187 /*
188 ========================================================================
189 Routine Description:
190     Close raxx interface.
191
192 Arguments:
193         *net_dev                        the raxx interface pointer
194
195 Return Value:
196     0                                   Open OK
197         otherwise                       Open Fail
198
199 Note:
200         1. if open fail, kernel will not call the close function.
201         2. Free memory for
202                 (1) Mlme Memory Handler:                MlmeHalt()
203                 (2) TX & RX:                                    RTMPFreeTxRxRingMemory()
204                 (3) BA Reordering:                              ba_reordering_resource_release()
205 ========================================================================
206 */
207 int rt28xx_close(IN PNET_DEV dev)
208 {
209         struct net_device * net_dev = (struct net_device *)dev;
210     RTMP_ADAPTER        *pAd = net_dev->ml_priv;
211         BOOLEAN                 Cancelled = FALSE;
212         UINT32                  i = 0;
213 #ifdef RT2870
214         DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
215         DECLARE_WAITQUEUE(wait, current);
216
217         //RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
218 #endif // RT2870 //
219
220
221     DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
222
223         // Sanity check for pAd
224         if (pAd == NULL)
225                 return 0; // close ok
226
227
228 #ifdef CONFIG_STA_SUPPORT
229         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
230         {
231
232                 // If dirver doesn't wake up firmware here,
233                 // NICLoadFirmware will hang forever when interface is up again.
234                 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
235         {
236                     AsicForceWakeup(pAd, TRUE);
237         }
238
239 #ifdef QOS_DLS_SUPPORT
240                 // send DLS-TEAR_DOWN message,
241                 if (pAd->CommonCfg.bDLSCapable)
242                 {
243                         UCHAR i;
244
245                         // tear down local dls table entry
246                         for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
247                         {
248                                 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
249                                 {
250                                         RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
251                                         pAd->StaCfg.DLSEntry[i].Status  = DLS_NONE;
252                                         pAd->StaCfg.DLSEntry[i].Valid   = FALSE;
253                                 }
254                         }
255
256                         // tear down peer dls table entry
257                         for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
258                         {
259                                 if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
260                                 {
261                                         RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
262                                         pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
263                                         pAd->StaCfg.DLSEntry[i].Valid   = FALSE;
264                                 }
265                         }
266                         RT28XX_MLME_HANDLER(pAd);
267                 }
268 #endif // QOS_DLS_SUPPORT //
269
270                 if (INFRA_ON(pAd) &&
271                         (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)))
272                 {
273                         MLME_DISASSOC_REQ_STRUCT        DisReq;
274                         MLME_QUEUE_ELEM *MsgElem = (MLME_QUEUE_ELEM *) kmalloc(sizeof(MLME_QUEUE_ELEM), MEM_ALLOC_FLAG);
275
276                         COPY_MAC_ADDR(DisReq.Addr, pAd->CommonCfg.Bssid);
277                         DisReq.Reason =  REASON_DEAUTH_STA_LEAVING;
278
279                         MsgElem->Machine = ASSOC_STATE_MACHINE;
280                         MsgElem->MsgType = MT2_MLME_DISASSOC_REQ;
281                         MsgElem->MsgLen = sizeof(MLME_DISASSOC_REQ_STRUCT);
282                         NdisMoveMemory(MsgElem->Msg, &DisReq, sizeof(MLME_DISASSOC_REQ_STRUCT));
283
284                         // Prevent to connect AP again in STAMlmePeriodicExec
285                         pAd->MlmeAux.AutoReconnectSsidLen= 32;
286                         NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
287
288                         pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
289                         MlmeDisassocReqAction(pAd, MsgElem);
290                         kfree(MsgElem);
291
292                         RTMPusecDelay(1000);
293                 }
294
295 #ifdef RT2870
296         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
297 #endif // RT2870 //
298
299 #ifdef CCX_SUPPORT
300                 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &Cancelled);
301 #endif
302
303                 RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, &Cancelled);
304                 RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, &Cancelled);
305
306 #ifdef WPA_SUPPLICANT_SUPPORT
307 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
308                 {
309                         union iwreq_data    wrqu;
310                         // send wireless event to wpa_supplicant for infroming interface down.
311                         memset(&wrqu, 0, sizeof(wrqu));
312                         wrqu.data.flags = RT_INTERFACE_DOWN;
313                         wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
314                 }
315 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
316 #endif // WPA_SUPPLICANT_SUPPORT //
317
318                 MlmeRadioOff(pAd);
319         }
320 #endif // CONFIG_STA_SUPPORT //
321
322         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
323
324         for (i = 0 ; i < NUM_OF_TX_RING; i++)
325         {
326                 while (pAd->DeQueueRunning[i] == TRUE)
327                 {
328                         printk("Waiting for TxQueue[%d] done..........\n", i);
329                         RTMPusecDelay(1000);
330                 }
331         }
332
333 #ifdef RT2870
334         // ensure there are no more active urbs.
335         add_wait_queue (&unlink_wakeup, &wait);
336         pAd->wait = &unlink_wakeup;
337
338         // maybe wait for deletions to finish.
339         i = 0;
340         //while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
341         while(i < 25)
342         {
343                 unsigned long IrqFlags;
344
345                 RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
346                 if (pAd->PendingRx == 0)
347                 {
348                         RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
349                         break;
350                 }
351                 RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
352
353 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
354                 msleep(UNLINK_TIMEOUT_MS);      //Time in millisecond
355 #else
356                 RTMPusecDelay(UNLINK_TIMEOUT_MS*1000);  //Time in microsecond
357 #endif
358                 i++;
359         }
360         pAd->wait = NULL;
361         remove_wait_queue (&unlink_wakeup, &wait);
362 #endif // RT2870 //
363
364         //RTUSBCleanUpMLMEWaitQueue(pAd);       /*not used in RT28xx*/
365
366
367 #ifdef RT2870
368         // We need clear timerQ related structure before exits of the timer thread.
369         RT2870_TimerQ_Exit(pAd);
370         // Close kernel threads or tasklets
371         RT28xxThreadTerminate(pAd);
372 #endif // RT2870 //
373
374         // Stop Mlme state machine
375         MlmeHalt(pAd);
376
377         // Close kernel threads or tasklets
378         kill_thread_task(pAd);
379
380
381 #ifdef CONFIG_STA_SUPPORT
382         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
383         {
384                 MacTableReset(pAd);
385         }
386 #endif // CONFIG_STA_SUPPORT //
387
388
389         MeasureReqTabExit(pAd);
390         TpcReqTabExit(pAd);
391
392
393
394
395         // Free Ring or USB buffers
396         RTMPFreeTxRxRingMemory(pAd);
397
398         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
399
400 #ifdef DOT11_N_SUPPORT
401         // Free BA reorder resource
402         ba_reordering_resource_release(pAd);
403 #endif // DOT11_N_SUPPORT //
404
405 #ifdef RT2870
406 #ifdef INF_AMAZON_SE
407         if (pAd->UsbVendorReqBuf)
408                 os_free_mem(pAd, pAd->UsbVendorReqBuf);
409 #endif // INF_AMAZON_SE //
410 #endif // RT2870 //
411
412         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP);
413
414         return 0; // close ok
415 } /* End of rt28xx_close */
416
417 static int rt28xx_init(IN struct net_device *net_dev)
418 {
419         PRTMP_ADAPTER                   pAd = net_dev->ml_priv;
420         UINT                                    index;
421         UCHAR                                   TmpPhy;
422         NDIS_STATUS                             Status;
423         UINT32          MacCsr0 = 0;
424
425 #ifdef RT2870
426 #ifdef INF_AMAZON_SE
427         init_MUTEX(&(pAd->UsbVendorReq_semaphore));
428         os_alloc_mem(pAd, (PUCHAR)&pAd->UsbVendorReqBuf, MAX_PARAM_BUFFER_SIZE - 1);
429         if (pAd->UsbVendorReqBuf == NULL)
430         {
431                 DBGPRINT(RT_DEBUG_ERROR, ("Allocate vendor request temp buffer failed!\n"));
432                 goto err0;
433         }
434 #endif // INF_AMAZON_SE //
435 #endif // RT2870 //
436
437 #ifdef DOT11_N_SUPPORT
438         // Allocate BA Reordering memory
439         ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM);
440 #endif // DOT11_N_SUPPORT //
441
442         // Make sure MAC gets ready.
443         index = 0;
444         do
445         {
446                 RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);
447                 pAd->MACVersion = MacCsr0;
448
449                 if ((pAd->MACVersion != 0x00) && (pAd->MACVersion != 0xFFFFFFFF))
450                         break;
451
452                 RTMPusecDelay(10);
453         } while (index++ < 100);
454
455         DBGPRINT(RT_DEBUG_TRACE, ("MAC_CSR0  [ Ver:Rev=0x%08x]\n", pAd->MACVersion));
456
457         // Disable DMA
458         RT28XXDMADisable(pAd);
459
460
461         // Load 8051 firmware
462         Status = NICLoadFirmware(pAd);
463         if (Status != NDIS_STATUS_SUCCESS)
464         {
465                 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", Status));
466                 goto err1;
467         }
468
469         NICLoadRateSwitchingParams(pAd);
470
471         // Disable interrupts here which is as soon as possible
472         // This statement should never be true. We might consider to remove it later
473
474         Status = RTMPAllocTxRxRingMemory(pAd);
475         if (Status != NDIS_STATUS_SUCCESS)
476         {
477                 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status));
478                 goto err1;
479         }
480
481         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
482
483         // initialize MLME
484         //
485
486         Status = MlmeInit(pAd);
487         if (Status != NDIS_STATUS_SUCCESS)
488         {
489                 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status));
490                 goto err2;
491         }
492
493         // Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default
494         //
495         UserCfgInit(pAd);
496
497 #ifdef RT2870
498         // We need init timerQ related structure before create the timer thread.
499         RT2870_TimerQ_Init(pAd);
500 #endif // RT2870 //
501
502         RT28XX_TASK_THREAD_INIT(pAd, Status);
503         if (Status != NDIS_STATUS_SUCCESS)
504                 goto err1;
505
506 //      COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr);
507 //      pAd->bForcePrintTX = TRUE;
508
509         CfgInitHook(pAd);
510
511
512 #ifdef BLOCK_NET_IF
513         initblockQueueTab(pAd);
514 #endif // BLOCK_NET_IF //
515
516 #ifdef CONFIG_STA_SUPPORT
517         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
518                 NdisAllocateSpinLock(&pAd->MacTabLock);
519 #endif // CONFIG_STA_SUPPORT //
520
521         MeasureReqTabInit(pAd);
522         TpcReqTabInit(pAd);
523
524         //
525         // Init the hardware, we need to init asic before read registry, otherwise mac register will be reset
526         //
527         Status = NICInitializeAdapter(pAd, TRUE);
528         if (Status != NDIS_STATUS_SUCCESS)
529         {
530                 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", Status));
531                 if (Status != NDIS_STATUS_SUCCESS)
532                 goto err3;
533         }
534
535         // Read parameters from Config File
536         Status = RTMPReadParametersHook(pAd);
537
538         printk("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
539         if (Status != NDIS_STATUS_SUCCESS)
540         {
541                 DBGPRINT_ERR(("NICReadRegParameters failed, Status[=0x%08x]\n",Status));
542                 goto err4;
543         }
544
545 #ifdef RT2870
546         pAd->CommonCfg.bMultipleIRP = FALSE;
547
548         if (pAd->CommonCfg.bMultipleIRP)
549                 pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE;
550         else
551                 pAd->CommonCfg.NumOfBulkInIRP = 1;
552 #endif // RT2870 //
553
554
555         //Init Ba Capability parameters.
556 //      RT28XX_BA_INIT(pAd);
557 #ifdef DOT11_N_SUPPORT
558         pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
559         pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
560         pAd->CommonCfg.DesiredHtPhy.AmsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
561         pAd->CommonCfg.DesiredHtPhy.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
562         // UPdata to HT IE
563         pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
564         pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
565         pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
566 #endif // DOT11_N_SUPPORT //
567
568         // after reading Registry, we now know if in AP mode or STA mode
569
570         // Load 8051 firmware; crash when FW image not existent
571         // Status = NICLoadFirmware(pAd);
572         // if (Status != NDIS_STATUS_SUCCESS)
573         //    break;
574
575         printk("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
576
577         // We should read EEPROM for all cases.  rt2860b
578         NICReadEEPROMParameters(pAd, mac);
579 #ifdef CONFIG_STA_SUPPORT
580 #endif // CONFIG_STA_SUPPORT //
581
582         printk("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode);
583
584         NICInitAsicFromEEPROM(pAd); //rt2860b
585
586         // Set PHY to appropriate mode
587         TmpPhy = pAd->CommonCfg.PhyMode;
588         pAd->CommonCfg.PhyMode = 0xff;
589         RTMPSetPhyMode(pAd, TmpPhy);
590 #ifdef DOT11_N_SUPPORT
591         SetCommonHT(pAd);
592 #endif // DOT11_N_SUPPORT //
593
594         // No valid channels.
595         if (pAd->ChannelListNum == 0)
596         {
597                 printk("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n");
598                 goto err4;
599         }
600
601 #ifdef DOT11_N_SUPPORT
602         printk("MCS Set = %02x %02x %02x %02x %02x\n", pAd->CommonCfg.HtCapability.MCSSet[0],
603            pAd->CommonCfg.HtCapability.MCSSet[1], pAd->CommonCfg.HtCapability.MCSSet[2],
604            pAd->CommonCfg.HtCapability.MCSSet[3], pAd->CommonCfg.HtCapability.MCSSet[4]);
605 #endif // DOT11_N_SUPPORT //
606
607 #ifdef RT2870
608     //Init RT30xx RFRegisters after read RFIC type from EEPROM
609         NICInitRT30xxRFRegisters(pAd);
610 #endif // RT2870 //
611
612 #if 0
613         // Patch cardbus controller if EEPROM said so.
614         if (pAd->bTest1 == FALSE)
615                 RTMPPatchCardBus(pAd);
616 #endif
617
618
619 //              APInitialize(pAd);
620
621 #ifdef IKANOS_VX_1X0
622         VR_IKANOS_FP_Init(pAd->ApCfg.BssidNum, pAd->PermanentAddress);
623 #endif // IKANOS_VX_1X0 //
624
625                 //
626         // Initialize RF register to default value
627         //
628         AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
629         AsicLockChannel(pAd, pAd->CommonCfg.Channel);
630
631         // 8051 firmware require the signal during booting time.
632         AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00);
633
634         if (pAd && (Status != NDIS_STATUS_SUCCESS))
635         {
636                 //
637                 // Undo everything if it failed
638                 //
639                 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
640                 {
641 //                      NdisMDeregisterInterrupt(&pAd->Interrupt);
642                         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE);
643                 }
644 //              RTMPFreeAdapter(pAd); // we will free it in disconnect()
645         }
646         else if (pAd)
647         {
648                 // Microsoft HCT require driver send a disconnect event after driver initialization.
649                 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
650 //              pAd->IndicateMediaState = NdisMediaStateDisconnected;
651                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE);
652
653                 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n"));
654
655
656 #ifdef RT2870
657                 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS);
658                 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
659
660                 //
661                 // Support multiple BulkIn IRP,
662                 // the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1.
663                 //
664                 for(index=0; index<pAd->CommonCfg.NumOfBulkInIRP; index++)
665                 {
666                         RTUSBBulkReceive(pAd);
667                         DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n" ));
668                 }
669 #endif // RT2870 //
670         }// end of else
671
672
673         DBGPRINT_S(Status, ("<==== RTMPInitialize, Status=%x\n", Status));
674
675         return TRUE;
676
677
678 err4:
679 err3:
680         MlmeHalt(pAd);
681 err2:
682         RTMPFreeTxRxRingMemory(pAd);
683 //      RTMPFreeAdapter(pAd);
684 err1:
685
686 #ifdef DOT11_N_SUPPORT
687         os_free_mem(pAd, pAd->mpdu_blk_pool.mem); // free BA pool
688 #endif // DOT11_N_SUPPORT //
689         RT28XX_IRQ_RELEASE(net_dev);
690
691         // shall not set ml_priv to NULL here because the ml_priv didn't been free yet.
692         //net_dev->ml_priv = 0;
693 #ifdef INF_AMAZON_SE
694 err0:
695 #endif // INF_AMAZON_SE //
696         printk("!!! %s Initialized fail !!!\n", RT28xx_CHIP_NAME);
697         return FALSE;
698 } /* End of rt28xx_init */
699
700
701 /*
702 ========================================================================
703 Routine Description:
704     Open raxx interface.
705
706 Arguments:
707         *net_dev                        the raxx interface pointer
708
709 Return Value:
710     0                                   Open OK
711         otherwise                       Open Fail
712
713 Note:
714 ========================================================================
715 */
716 int rt28xx_open(IN PNET_DEV dev)
717 {
718         struct net_device * net_dev = (struct net_device *)dev;
719         PRTMP_ADAPTER pAd = net_dev->ml_priv;
720         int retval = 0;
721         POS_COOKIE pObj;
722
723
724         // Sanity check for pAd
725         if (pAd == NULL)
726         {
727                 /* if 1st open fail, pAd will be free;
728                    So the net_dev->ml_priv will be NULL in 2rd open */
729                 return -1;
730         }
731
732 #ifdef CONFIG_APSTA_MIXED_SUPPORT
733         if (pAd->OpMode == OPMODE_AP)
734         {
735                 CW_MAX_IN_BITS = 6;
736         }
737         else if (pAd->OpMode == OPMODE_STA)
738         {
739                 CW_MAX_IN_BITS = 10;
740         }
741
742 #if WIRELESS_EXT >= 12
743         if (net_dev->priv_flags == INT_MAIN)
744         {
745                 if (pAd->OpMode == OPMODE_AP)
746                         net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_ap_iw_handler_def;
747                 else if (pAd->OpMode == OPMODE_STA)
748                         net_dev->wireless_handlers = (struct iw_handler_def *) &rt28xx_iw_handler_def;
749         }
750 #endif // WIRELESS_EXT >= 12 //
751 #endif // CONFIG_APSTA_MIXED_SUPPORT //
752
753 #ifdef CONFIG_STA_SUPPORT
754 #endif // CONFIG_STA_SUPPORT //
755
756         // Init
757         pObj = (POS_COOKIE)pAd->OS_Cookie;
758
759         // reset Adapter flags
760         RTMP_CLEAR_FLAGS(pAd);
761
762         // Request interrupt service routine for PCI device
763         // register the interrupt routine with the os
764         RT28XX_IRQ_REQUEST(net_dev);
765
766
767         // Init BssTab & ChannelInfo tabbles for auto channel select.
768
769
770         // Chip & other init
771         if (rt28xx_init(net_dev) == FALSE)
772                 goto err;
773
774 #ifdef CONFIG_STA_SUPPORT
775         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
776         {
777                 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
778                 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, strlen(net_dev->name));
779         }
780 #endif // CONFIG_STA_SUPPORT //
781
782         // Set up the Mac address
783         NdisMoveMemory(net_dev->dev_addr, (void *) pAd->CurrentAddress, 6);
784
785         // Init IRQ parameters
786         RT28XX_IRQ_INIT(pAd);
787
788         // Various AP function init
789
790 #ifdef CONFIG_STA_SUPPORT
791         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
792         {
793 #ifdef WPA_SUPPLICANT_SUPPORT
794 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
795                 {
796                         union iwreq_data    wrqu;
797                         // send wireless event to wpa_supplicant for infroming interface down.
798                         memset(&wrqu, 0, sizeof(wrqu));
799                         wrqu.data.flags = RT_INTERFACE_UP;
800                         wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
801                 }
802 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
803 #endif // WPA_SUPPLICANT_SUPPORT //
804
805         }
806 #endif // CONFIG_STA_SUPPORT //
807
808         // Enable Interrupt
809         RT28XX_IRQ_ENABLE(pAd);
810
811         // Now Enable RxTx
812         RTMPEnableRxTx(pAd);
813         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP);
814
815         {
816         UINT32 reg = 0;
817         RTMP_IO_READ32(pAd, 0x1300, &reg);  // clear garbage interrupts
818         printk("0x1300 = %08x\n", reg);
819         }
820
821         {
822 //      u32 reg;
823 //      u8  byte;
824 //      u16 tmp;
825
826 //      RTMP_IO_READ32(pAd, XIFS_TIME_CFG, &reg);
827
828 //      tmp = 0x0805;
829 //      reg  = (reg & 0xffff0000) | tmp;
830 //      RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg);
831
832         }
833
834 #if 0
835         /*
836          * debugging helper
837          *              show the size of main table in Adapter structure
838          *              MacTab  -- 185K
839          *              BATable -- 137K
840          *              Total   -- 385K  !!!!! (5/26/2006)
841          */
842         printk("sizeof(pAd->MacTab) = %ld\n", sizeof(pAd->MacTab));
843         printk("sizeof(pAd->AccessControlList) = %ld\n", sizeof(pAd->AccessControlList));
844         printk("sizeof(pAd->ApCfg) = %ld\n", sizeof(pAd->ApCfg));
845         printk("sizeof(pAd->BATable) = %ld\n", sizeof(pAd->BATable));
846         BUG();
847 #endif
848
849 #ifdef CONFIG_STA_SUPPORT
850 #endif // CONFIG_STA_SUPPORT //
851
852         return (retval);
853
854 err:
855         return (-1);
856 } /* End of rt28xx_open */
857
858
859 /* Must not be called for mdev and apdev */
860 static NDIS_STATUS rt_ieee80211_if_setup(struct net_device *dev, PRTMP_ADAPTER pAd)
861 {
862         NDIS_STATUS Status;
863         INT     i=0;
864         CHAR    slot_name[IFNAMSIZ];
865         struct net_device   *device;
866
867
868         //ether_setup(dev);
869         dev->hard_start_xmit = rt28xx_send_packets;
870
871 #ifdef IKANOS_VX_1X0
872         dev->hard_start_xmit = IKANOS_DataFramesTx;
873 #endif // IKANOS_VX_1X0 //
874
875 //      dev->set_multicast_list = ieee80211_set_multicast_list;
876 //      dev->change_mtu = ieee80211_change_mtu;
877 #ifdef CONFIG_STA_SUPPORT
878 #if WIRELESS_EXT >= 12
879         if (pAd->OpMode == OPMODE_STA)
880         {
881                 dev->wireless_handlers = &rt28xx_iw_handler_def;
882         }
883 #endif //WIRELESS_EXT >= 12
884 #endif // CONFIG_STA_SUPPORT //
885
886 #ifdef CONFIG_APSTA_MIXED_SUPPORT
887 #if WIRELESS_EXT >= 12
888         if (pAd->OpMode == OPMODE_AP)
889         {
890                 dev->wireless_handlers = &rt28xx_ap_iw_handler_def;
891         }
892 #endif //WIRELESS_EXT >= 12
893 #endif // CONFIG_APSTA_MIXED_SUPPORT //
894
895 #if WIRELESS_EXT < 21
896                 dev->get_wireless_stats = rt28xx_get_wireless_stats;
897 #endif
898         dev->get_stats = RT28xx_get_ether_stats;
899         dev->open = MainVirtualIF_open; //rt28xx_open;
900         dev->stop = MainVirtualIF_close; //rt28xx_close;
901 //      dev->uninit = ieee80211_if_reinit;
902 //      dev->destructor = ieee80211_if_free;
903         dev->priv_flags = INT_MAIN;
904         dev->do_ioctl = rt28xx_ioctl;
905 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
906     dev->validate_addr = NULL;
907 #endif
908         // find available device name
909         for (i = 0; i < 8; i++)
910         {
911 #ifdef MULTIPLE_CARD_SUPPORT
912                 if (pAd->MC_RowID >= 0)
913                         sprintf(slot_name, "ra%02d_%d", pAd->MC_RowID, i);
914                 else
915 #endif // MULTIPLE_CARD_SUPPORT //
916                 sprintf(slot_name, "ra%d", i);
917
918 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
919 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
920 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
921         device = dev_get_by_name(dev_net(dev), slot_name);
922 #else
923         device = dev_get_by_name(dev->nd_net, slot_name);
924 #endif
925 #else
926                 device = dev_get_by_name(slot_name);
927 #endif
928                 if (device != NULL) dev_put(device);
929 #else
930                 for (device = dev_base; device != NULL; device = device->next)
931                 {
932                         if (strncmp(device->name, slot_name, 4) == 0)
933                                 break;
934                 }
935 #endif
936                 if(device == NULL)
937                         break;
938         }
939
940         if(i == 8)
941         {
942                 DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
943                 Status = NDIS_STATUS_FAILURE;
944         }
945         else
946         {
947 #ifdef MULTIPLE_CARD_SUPPORT
948                 if (pAd->MC_RowID >= 0)
949                 sprintf(dev->name, "ra%02d_%d", pAd->MC_RowID, i);
950                 else
951 #endif // MULTIPLE_CARD_SUPPORT //
952                 sprintf(dev->name, "ra%d", i);
953                 Status = NDIS_STATUS_SUCCESS;
954         }
955
956         return Status;
957
958 }
959
960
961 #ifdef MULTIPLE_CARD_SUPPORT
962 /*
963 ========================================================================
964 Routine Description:
965     Get card profile path.
966
967 Arguments:
968     pAd
969
970 Return Value:
971     TRUE                - Find a card profile
972         FALSE           - use default profile
973
974 Note:
975 ========================================================================
976 */
977 extern INT RTMPGetKeyParameter(
978     IN  PCHAR   key,
979     OUT PCHAR   dest,
980     IN  INT     destsize,
981     IN  PCHAR   buffer);
982
983 BOOLEAN RTMP_CardInfoRead(
984         IN      PRTMP_ADAPTER pAd)
985 {
986 #define MC_SELECT_CARDID                0       /* use CARD ID (0 ~ 31) to identify different cards */
987 #define MC_SELECT_MAC                   1       /* use CARD MAC to identify different cards */
988 #define MC_SELECT_CARDTYPE              2       /* use CARD type (abgn or bgn) to identify different cards */
989
990 #define LETTER_CASE_TRANSLATE(txt_p, card_id)                   \
991         {       UINT32 _len; char _char;                                                \
992                 for(_len=0; _len<strlen(card_id); _len++) {             \
993                         _char = *(txt_p + _len);                                        \
994                         if (('A' <= _char) && (_char <= 'Z'))           \
995                                 *(txt_p+_len) = 'a'+(_char-'A');                \
996                 } }
997
998         struct file *srcf;
999         INT retval, orgfsuid, orgfsgid;
1000         mm_segment_t orgfs;
1001         CHAR *buffer, *tmpbuf, card_id_buf[30], RFIC_word[30];
1002         BOOLEAN flg_match_ok = FALSE;
1003         INT32 card_select_method;
1004         INT32 card_free_id, card_nouse_id, card_same_mac_id, card_match_id;
1005         EEPROM_ANTENNA_STRUC antenna;
1006         USHORT addr01, addr23, addr45;
1007         UINT8 mac[6];
1008         UINT32 data, card_index;
1009         UCHAR *start_ptr;
1010
1011
1012         // init
1013         buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
1014         if (buffer == NULL)
1015         return FALSE;
1016
1017         tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
1018         if(tmpbuf == NULL)
1019         {
1020                 kfree(buffer);
1021         return NDIS_STATUS_FAILURE;
1022         }
1023
1024         orgfsuid = current->fsuid;
1025         orgfsgid = current->fsgid;
1026         current->fsuid = current->fsgid = 0;
1027     orgfs = get_fs();
1028     set_fs(KERNEL_DS);
1029
1030         // get RF IC type
1031         RTMP_IO_READ32(pAd, E2PROM_CSR, &data);
1032
1033         if ((data & 0x30) == 0)
1034                 pAd->EEPROMAddressNum = 6;      // 93C46
1035         else if ((data & 0x30) == 0x10)
1036                 pAd->EEPROMAddressNum = 8;      // 93C66
1037         else
1038                 pAd->EEPROMAddressNum = 8;      // 93C86
1039
1040         //antenna.word = RTMP_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET);
1041         RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, antenna.word);
1042
1043         if ((antenna.field.RfIcType == RFIC_2850) ||
1044                 (antenna.field.RfIcType == RFIC_2750))
1045         {
1046                 /* ABGN card */
1047                 strcpy(RFIC_word, "abgn");
1048         }
1049         else
1050         {
1051                 /* BGN card */
1052                 strcpy(RFIC_word, "bgn");
1053         }
1054
1055         // get MAC address
1056         //addr01 = RTMP_EEPROM_READ16(pAd, 0x04);
1057         //addr23 = RTMP_EEPROM_READ16(pAd, 0x06);
1058         //addr45 = RTMP_EEPROM_READ16(pAd, 0x08);
1059         RT28xx_EEPROM_READ16(pAd, 0x04, addr01);
1060         RT28xx_EEPROM_READ16(pAd, 0x06, addr23);
1061         RT28xx_EEPROM_READ16(pAd, 0x08, addr45);
1062
1063         mac[0] = (UCHAR)(addr01 & 0xff);
1064         mac[1] = (UCHAR)(addr01 >> 8);
1065         mac[2] = (UCHAR)(addr23 & 0xff);
1066         mac[3] = (UCHAR)(addr23 >> 8);
1067         mac[4] = (UCHAR)(addr45 & 0xff);
1068         mac[5] = (UCHAR)(addr45 >> 8);
1069
1070         // open card information file
1071         srcf = filp_open(CARD_INFO_PATH, O_RDONLY, 0);
1072         if (IS_ERR(srcf))
1073         {
1074                 /* card information file does not exist */
1075                         DBGPRINT(RT_DEBUG_TRACE,
1076                                 ("--> Error %ld opening %s\n", -PTR_ERR(srcf), CARD_INFO_PATH));
1077                 return FALSE;
1078         }
1079
1080         if (srcf->f_op && srcf->f_op->read)
1081         {
1082                 /* card information file exists so reading the card information */
1083                 memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
1084                 retval = srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
1085                 if (retval < 0)
1086                 {
1087                         /* read fail */
1088                                 DBGPRINT(RT_DEBUG_TRACE,
1089                                         ("--> Read %s error %d\n", CARD_INFO_PATH, -retval));
1090                 }
1091                 else
1092                 {
1093                         /* get card selection method */
1094                         memset(tmpbuf, 0x00, MAX_PARAM_BUFFER_SIZE);
1095                         card_select_method = MC_SELECT_CARDTYPE; // default
1096
1097                         if (RTMPGetKeyParameter("SELECT", tmpbuf, 256, buffer))
1098                         {
1099                                 if (strcmp(tmpbuf, "CARDID") == 0)
1100                                         card_select_method = MC_SELECT_CARDID;
1101                                 else if (strcmp(tmpbuf, "MAC") == 0)
1102                                         card_select_method = MC_SELECT_MAC;
1103                                 else if (strcmp(tmpbuf, "CARDTYPE") == 0)
1104                                         card_select_method = MC_SELECT_CARDTYPE;
1105                         }
1106
1107                         DBGPRINT(RT_DEBUG_TRACE,
1108                                         ("MC> Card Selection = %d\n", card_select_method));
1109
1110                         // init
1111                         card_free_id = -1;
1112                         card_nouse_id = -1;
1113                         card_same_mac_id = -1;
1114                         card_match_id = -1;
1115
1116                         // search current card information records
1117                         for(card_index=0;
1118                                 card_index<MAX_NUM_OF_MULTIPLE_CARD;
1119                                 card_index++)
1120                         {
1121                                 if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
1122                                         (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
1123                                 {
1124                                         // MAC is all-0 so the entry is available
1125                                         MC_CardUsed[card_index] = 0;
1126
1127                                         if (card_free_id < 0)
1128                                                 card_free_id = card_index; // 1st free entry
1129                                 }
1130                                 else
1131                                 {
1132                                         if (memcmp(MC_CardMac[card_index], mac, 6) == 0)
1133                                         {
1134                                                 // we find the entry with same MAC
1135                                                 if (card_same_mac_id < 0)
1136                                                         card_same_mac_id = card_index; // 1st same entry
1137                                         }
1138                                         else
1139                                         {
1140                                                 // MAC is not all-0 but used flag == 0
1141                                                 if ((MC_CardUsed[card_index] == 0) &&
1142                                                         (card_nouse_id < 0))
1143                                                 {
1144                                                         card_nouse_id = card_index; // 1st available entry
1145                                                 }
1146                                         }
1147                                 }
1148                         }
1149
1150                         DBGPRINT(RT_DEBUG_TRACE,
1151                                         ("MC> Free = %d, Same = %d, NOUSE = %d\n",
1152                                         card_free_id, card_same_mac_id, card_nouse_id));
1153
1154                         if ((card_same_mac_id >= 0) &&
1155                                 ((card_select_method == MC_SELECT_CARDID) ||
1156                                 (card_select_method == MC_SELECT_CARDTYPE)))
1157                         {
1158                                 // same MAC entry is found
1159                                 card_match_id = card_same_mac_id;
1160
1161                                 if (card_select_method == MC_SELECT_CARDTYPE)
1162                                 {
1163                                         // for CARDTYPE
1164                                         sprintf(card_id_buf, "%02dCARDTYPE%s",
1165                                                         card_match_id, RFIC_word);
1166
1167                                         if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
1168                                         {
1169                                                 // we found the card ID
1170                                                 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1171                                         }
1172                                 }
1173                         }
1174                         else
1175                         {
1176                                 // the card is 1st plug-in, try to find the match card profile
1177                                 switch(card_select_method)
1178                                 {
1179                                         case MC_SELECT_CARDID: // CARDID
1180                                         default:
1181                                                 if (card_free_id >= 0)
1182                                                         card_match_id = card_free_id;
1183                                                 else
1184                                                         card_match_id = card_nouse_id;
1185                                                 break;
1186
1187                                         case MC_SELECT_MAC: // MAC
1188                                                 sprintf(card_id_buf, "MAC%02x:%02x:%02x:%02x:%02x:%02x",
1189                                                                 mac[0], mac[1], mac[2],
1190                                                                 mac[3], mac[4], mac[5]);
1191
1192                                                 /* try to find the key word in the card file */
1193                                                 if ((start_ptr=rtstrstruncasecmp(buffer, card_id_buf)) != NULL)
1194                                                 {
1195                                                         LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1196
1197                                                         /* get the row ID (2 ASCII characters) */
1198                                                         start_ptr -= 2;
1199                                                         card_id_buf[0] = *(start_ptr);
1200                                                         card_id_buf[1] = *(start_ptr+1);
1201                                                         card_id_buf[2] = 0x00;
1202
1203                                                         card_match_id = simple_strtol(card_id_buf, 0, 10);
1204                                                 }
1205                                                 break;
1206
1207                                         case MC_SELECT_CARDTYPE: // CARDTYPE
1208                                                 card_nouse_id = -1;
1209
1210                                                 for(card_index=0;
1211                                                         card_index<MAX_NUM_OF_MULTIPLE_CARD;
1212                                                         card_index++)
1213                                                 {
1214                                                         sprintf(card_id_buf, "%02dCARDTYPE%s",
1215                                                                         card_index, RFIC_word);
1216
1217                                                         if ((start_ptr=rtstrstruncasecmp(buffer,
1218                                                                                                                 card_id_buf)) != NULL)
1219                                                         {
1220                                                                 LETTER_CASE_TRANSLATE(start_ptr, card_id_buf);
1221
1222                                                                 if (MC_CardUsed[card_index] == 0)
1223                                                                 {
1224                                                                         /* current the card profile is not used */
1225                                                                         if ((*(UINT32 *)&MC_CardMac[card_index][0] == 0) &&
1226                                                                                 (*(UINT16 *)&MC_CardMac[card_index][4] == 0))
1227                                                                         {
1228                                                                                 // find it and no previous card use it
1229                                                                                 card_match_id = card_index;
1230                                                                                 break;
1231                                                                         }
1232                                                                         else
1233                                                                         {
1234                                                                                 // ever a card use it
1235                                                                                 if (card_nouse_id < 0)
1236                                                                                         card_nouse_id = card_index;
1237                                                                         }
1238                                                                 }
1239                                                         }
1240                                                 }
1241
1242                                                 // if not find a free one, use the available one
1243                                                 if (card_match_id < 0)
1244                                                         card_match_id = card_nouse_id;
1245                                                 break;
1246                                 }
1247                         }
1248
1249                         if (card_match_id >= 0)
1250                         {
1251                                 // make up search keyword
1252                                 switch(card_select_method)
1253                                 {
1254                                         case MC_SELECT_CARDID: // CARDID
1255                                                 sprintf(card_id_buf, "%02dCARDID", card_match_id);
1256                                                 break;
1257
1258                                         case MC_SELECT_MAC: // MAC
1259                                                 sprintf(card_id_buf,
1260                                                                 "%02dmac%02x:%02x:%02x:%02x:%02x:%02x",
1261                                                                 card_match_id,
1262                                                                 mac[0], mac[1], mac[2],
1263                                                                 mac[3], mac[4], mac[5]);
1264                                                 break;
1265
1266                                         case MC_SELECT_CARDTYPE: // CARDTYPE
1267                                         default:
1268                                                 sprintf(card_id_buf, "%02dcardtype%s",
1269                                                                 card_match_id, RFIC_word);
1270                                                 break;
1271                                 }
1272
1273                                 DBGPRINT(RT_DEBUG_TRACE, ("Search Keyword = %s\n", card_id_buf));
1274
1275                                 // read card file path
1276                                 if (RTMPGetKeyParameter(card_id_buf, tmpbuf, 256, buffer))
1277                                 {
1278                                         if (strlen(tmpbuf) < sizeof(pAd->MC_FileName))
1279                                         {
1280                                                 // backup card information
1281                                                 pAd->MC_RowID = card_match_id; /* base 0 */
1282                                                 MC_CardUsed[card_match_id] = 1;
1283                                                 memcpy(MC_CardMac[card_match_id], mac, sizeof(mac));
1284
1285                                                 // backup card file path
1286                                                 NdisMoveMemory(pAd->MC_FileName, tmpbuf , strlen(tmpbuf));
1287                                                 pAd->MC_FileName[strlen(tmpbuf)] = '\0';
1288                                                 flg_match_ok = TRUE;
1289
1290                                                 DBGPRINT(RT_DEBUG_TRACE,
1291                                                                 ("Card Profile Name = %s\n", pAd->MC_FileName));
1292                                         }
1293                                         else
1294                                         {
1295                                                 DBGPRINT(RT_DEBUG_ERROR,
1296                                                                 ("Card Profile Name length too large!\n"));
1297                                         }
1298                                 }
1299                                 else
1300                                 {
1301                                         DBGPRINT(RT_DEBUG_ERROR,
1302                                                         ("Can not find search key word in card.dat!\n"));
1303                                 }
1304
1305                                 if ((flg_match_ok != TRUE) &&
1306                                         (card_match_id < MAX_NUM_OF_MULTIPLE_CARD))
1307                                 {
1308                                         MC_CardUsed[card_match_id] = 0;
1309                                         memset(MC_CardMac[card_match_id], 0, sizeof(mac));
1310                                 }
1311                         } // if (card_match_id >= 0)
1312                 }
1313         }
1314
1315         // close file
1316         retval = filp_close(srcf, NULL);
1317         set_fs(orgfs);
1318         current->fsuid = orgfsuid;
1319         current->fsgid = orgfsgid;
1320         kfree(buffer);
1321         kfree(tmpbuf);
1322         return flg_match_ok;
1323 }
1324 #endif // MULTIPLE_CARD_SUPPORT //
1325
1326
1327 /*
1328 ========================================================================
1329 Routine Description:
1330     Probe RT28XX chipset.
1331
1332 Arguments:
1333     _dev_p                              Point to the PCI or USB device
1334         _dev_id_p                       Point to the PCI or USB device ID
1335
1336 Return Value:
1337     0                                   Probe OK
1338         -ENODEV                         Probe Fail
1339
1340 Note:
1341 ========================================================================
1342 */
1343 INT __devinit   rt28xx_probe(
1344     IN  void *_dev_p,
1345     IN  void *_dev_id_p,
1346         IN  UINT argc,
1347         OUT PRTMP_ADAPTER *ppAd)
1348 {
1349     struct  net_device  *net_dev;
1350     PRTMP_ADAPTER       pAd = (PRTMP_ADAPTER) NULL;
1351     INT                 status;
1352         PVOID                           handle;
1353 #ifdef RT2870
1354 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)  /* kernel 2.4 series */
1355         struct usb_device *dev_p = (struct usb_device *)_dev_p;
1356 #else
1357         struct usb_interface *intf = (struct usb_interface *)_dev_p;
1358         struct usb_device *dev_p = interface_to_usbdev(intf);
1359
1360         dev_p = usb_get_dev(dev_p);
1361 #endif // LINUX_VERSION_CODE //
1362 #endif // RT2870 //
1363
1364
1365 #ifdef CONFIG_STA_SUPPORT
1366     DBGPRINT(RT_DEBUG_TRACE, ("STA Driver version-%s\n", STA_DRIVER_VERSION));
1367 #endif // CONFIG_STA_SUPPORT //
1368
1369         // Check chipset vendor/product ID
1370 //      if (RT28XXChipsetCheck(_dev_p) == FALSE)
1371 //              goto err_out;
1372
1373 #if LINUX_VERSION_CODE <= 0x20402       // Red Hat 7.1
1374     net_dev = alloc_netdev(sizeof(PRTMP_ADAPTER), "eth%d", ether_setup);
1375 #else
1376     net_dev = alloc_etherdev(sizeof(PRTMP_ADAPTER));
1377 #endif
1378     if (net_dev == NULL)
1379     {
1380         printk("alloc_netdev failed\n");
1381
1382 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1383 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1384                 module_put(THIS_MODULE);
1385 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
1386 #else
1387                 MOD_DEC_USE_COUNT;
1388 #endif
1389         goto err_out;
1390     }
1391
1392 // sample
1393 //      if (rt_ieee80211_if_setup(net_dev) != NDIS_STATUS_SUCCESS)
1394 //              goto err_out;
1395
1396 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1397     SET_MODULE_OWNER(net_dev);
1398 #endif
1399
1400         netif_stop_queue(net_dev);
1401 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
1402 /* for supporting Network Manager */
1403 /* Set the sysfs physical device reference for the network logical device
1404  * if set prior to registration will cause a symlink during initialization.
1405  */
1406 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
1407     SET_NETDEV_DEV(net_dev, &(dev_p->dev));
1408 #endif
1409 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
1410
1411         // Allocate RTMP_ADAPTER miniport adapter structure
1412         handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
1413         RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p);
1414
1415         status = RTMPAllocAdapterBlock(handle, &pAd);
1416         if (status != NDIS_STATUS_SUCCESS)
1417                 goto err_out_free_netdev;
1418
1419         net_dev->ml_priv = (PVOID)pAd;
1420     pAd->net_dev = net_dev; // must be before RT28XXNetDevInit()
1421
1422         RT28XXNetDevInit(_dev_p, net_dev, pAd);
1423
1424 #ifdef CONFIG_STA_SUPPORT
1425     pAd->StaCfg.OriDevType = net_dev->type;
1426 #endif // CONFIG_STA_SUPPORT //
1427
1428         // Find and assign a free interface name, raxx
1429 //      RT28XXAvailRANameAssign(net_dev->name);
1430
1431         // Post config
1432 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1433         if (RT28XXProbePostConfig(_dev_p, pAd, argc) == FALSE)
1434                 goto err_out_unmap;
1435 #else
1436         if (RT28XXProbePostConfig(_dev_p, pAd, 0) == FALSE)
1437                 goto err_out_unmap;
1438 #endif // LINUX_VERSION_CODE //
1439
1440 #ifdef CONFIG_STA_SUPPORT
1441         pAd->OpMode = OPMODE_STA;
1442 #endif // CONFIG_STA_SUPPORT //
1443
1444
1445 #ifdef MULTIPLE_CARD_SUPPORT
1446         // find its profile path
1447         pAd->MC_RowID = -1; // use default profile path
1448         RTMP_CardInfoRead(pAd);
1449
1450         if (pAd->MC_RowID == -1)
1451 #ifdef CONFIG_STA_SUPPORT
1452                 strcpy(pAd->MC_FileName, STA_PROFILE_PATH);
1453 #endif // CONFIG_STA_SUPPORT //
1454
1455         DBGPRINT(RT_DEBUG_TRACE,
1456                         ("MC> ROW = %d, PATH = %s\n", pAd->MC_RowID, pAd->MC_FileName));
1457 #endif // MULTIPLE_CARD_SUPPORT //
1458
1459         // sample move
1460         if (rt_ieee80211_if_setup(net_dev, pAd) != NDIS_STATUS_SUCCESS)
1461                 goto err_out_unmap;
1462
1463     // Register this device
1464     status = register_netdev(net_dev);
1465     if (status)
1466         goto err_out_unmap;
1467
1468     // Set driver data
1469         RT28XX_DRVDATA_SET(_dev_p);
1470
1471
1472
1473         *ppAd = pAd;
1474     return 0; // probe ok
1475
1476
1477         /* --------------------------- ERROR HANDLE --------------------------- */
1478 err_out_unmap:
1479         RTMPFreeAdapter(pAd);
1480         RT28XX_UNMAP();
1481
1482 err_out_free_netdev:
1483 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1484     free_netdev(net_dev);
1485 #else
1486         kfree(net_dev);
1487 #endif
1488
1489 err_out:
1490         RT28XX_PUT_DEVICE(dev_p);
1491
1492 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1493         return (LONG)NULL;
1494 #else
1495     return -ENODEV; /* probe fail */
1496 #endif // LINUX_VERSION_CODE //
1497 } /* End of rt28xx_probe */
1498
1499
1500 /*
1501 ========================================================================
1502 Routine Description:
1503     The entry point for Linux kernel sent packet to our driver.
1504
1505 Arguments:
1506     sk_buff *skb                the pointer refer to a sk_buffer.
1507
1508 Return Value:
1509     0
1510
1511 Note:
1512         This function is the entry point of Tx Path for Os delivery packet to
1513         our driver. You only can put OS-depened & STA/AP common handle procedures
1514         in here.
1515 ========================================================================
1516 */
1517 int rt28xx_packet_xmit(struct sk_buff *skb)
1518 {
1519         struct net_device *net_dev = skb->dev;
1520         PRTMP_ADAPTER pAd = net_dev->ml_priv;
1521         int status = 0;
1522         PNDIS_PACKET pPacket = (PNDIS_PACKET) skb;
1523
1524         /* RT2870STA does this in RTMPSendPackets() */
1525 #ifdef RALINK_ATE
1526         if (ATE_ON(pAd))
1527         {
1528                 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_RESOURCES);
1529                 return 0;
1530         }
1531 #endif // RALINK_ATE //
1532
1533 #ifdef CONFIG_STA_SUPPORT
1534         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1535         {
1536                 // Drop send request since we are in monitor mode
1537                 if (MONITOR_ON(pAd))
1538                 {
1539                         RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1540                         goto done;
1541                 }
1542         }
1543 #endif // CONFIG_STA_SUPPORT //
1544
1545         // EapolStart size is 18
1546         if (skb->len < 14)
1547         {
1548                 //printk("bad packet size: %d\n", pkt->len);
1549                 hex_dump("bad packet", skb->data, skb->len);
1550                 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
1551                 goto done;
1552         }
1553
1554 #if 0
1555 //      if ((pkt->data[0] & 0x1) == 0)
1556         {
1557                 //hex_dump(__func__, pkt->data, pkt->len);
1558                 printk("pPacket = %x\n", pPacket);
1559         }
1560 #endif
1561
1562         RTMP_SET_PACKET_5VT(pPacket, 0);
1563 //      MiniportMMRequest(pAd, pkt->data, pkt->len);
1564 #ifdef CONFIG_5VT_ENHANCE
1565     if (*(int*)(skb->cb) == BRIDGE_TAG) {
1566                 RTMP_SET_PACKET_5VT(pPacket, 1);
1567     }
1568 #endif
1569
1570
1571
1572 #ifdef CONFIG_STA_SUPPORT
1573         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1574         {
1575
1576                 STASendPackets((NDIS_HANDLE)pAd, (PPNDIS_PACKET) &pPacket, 1);
1577         }
1578
1579 #endif // CONFIG_STA_SUPPORT //
1580
1581         status = 0;
1582 done:
1583
1584         return status;
1585 }
1586
1587
1588 /*
1589 ========================================================================
1590 Routine Description:
1591     Send a packet to WLAN.
1592
1593 Arguments:
1594     skb_p           points to our adapter
1595     dev_p           which WLAN network interface
1596
1597 Return Value:
1598     0: transmit successfully
1599     otherwise: transmit fail
1600
1601 Note:
1602 ========================================================================
1603 */
1604 INT rt28xx_send_packets(
1605         IN struct sk_buff               *skb_p,
1606         IN struct net_device    *net_dev)
1607 {
1608     RTMP_ADAPTER *pAd = net_dev->ml_priv;
1609
1610         if (!(net_dev->flags & IFF_UP))
1611         {
1612                 RELEASE_NDIS_PACKET(pAd, (PNDIS_PACKET)skb_p, NDIS_STATUS_FAILURE);
1613                 return 0;
1614         }
1615
1616         NdisZeroMemory((PUCHAR)&skb_p->cb[CB_OFF], 15);
1617         RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID);
1618
1619         return rt28xx_packet_xmit(skb_p);
1620 } /* End of MBSS_VirtualIF_PacketSend */
1621
1622
1623
1624
1625 #if LINUX_VERSION_CODE <= 0x20402       // Red Hat 7.1
1626 //static struct net_device *alloc_netdev(int sizeof_priv, const char *mask, void (*setup)(struct net_device *)) //sample
1627 struct net_device *alloc_netdev(
1628         int sizeof_priv,
1629         const char *mask,
1630         void (*setup)(struct net_device *))
1631 {
1632     struct net_device   *dev;
1633     INT                                 alloc_size;
1634
1635
1636     /* ensure 32-byte alignment of the private area */
1637     alloc_size = sizeof (*dev) + sizeof_priv + 31;
1638
1639     dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
1640     if (dev == NULL)
1641     {
1642         DBGPRINT(RT_DEBUG_ERROR,
1643                                 ("alloc_netdev: Unable to allocate device memory.\n"));
1644         return NULL;
1645     }
1646
1647     memset(dev, 0, alloc_size);
1648
1649     if (sizeof_priv)
1650         dev->priv = (void *) (((long)(dev + 1) + 31) & ~31);
1651
1652     setup(dev);
1653     strcpy(dev->name, mask);
1654
1655     return dev;
1656 }
1657 #endif // LINUX_VERSION_CODE //
1658
1659
1660 void CfgInitHook(PRTMP_ADAPTER pAd)
1661 {
1662         pAd->bBroadComHT = TRUE;
1663 } /* End of CfgInitHook */
1664
1665
1666 #if 0   // Not used now, should keep it in our source tree??
1667 /*
1668 ========================================================================
1669 Routine Description:
1670     Find and assign a free interface name (raxx).
1671
1672 Arguments:
1673     *name_p                             the interface name pointer
1674
1675 Return Value:
1676         TRUE                            OK
1677         FALSE                           FAIL
1678
1679 Note:
1680 ========================================================================
1681 */
1682 static BOOLEAN RT28XXAvailRANameAssign(
1683         IN CHAR                 *name_p)
1684 {
1685     CHAR                                slot_name[IFNAMSIZ];
1686     struct net_device   *device;
1687         UINT32                          if_id;
1688
1689
1690     for(if_id=0; if_id<8; if_id++)
1691     {
1692         sprintf(slot_name, "ra%d", if_id);
1693
1694         for(device=dev_base; device!=NULL; device=device->next)
1695         {
1696             if (strncmp(device->name, slot_name, 4) == 0)
1697                 break;
1698         }
1699
1700         if (device == NULL)
1701                         break;
1702     }
1703
1704     if (if_id == 8)
1705     {
1706         DBGPRINT(RT_DEBUG_ERROR, ("No available slot name\n"));
1707         return FALSE;
1708     }
1709
1710     sprintf(name_p, "ra%d", if_id);
1711         return TRUE;
1712 } /* End of RT28XXAvailRANameAssign */
1713 #endif
1714
1715 #if WIRELESS_EXT >= 12
1716 // This function will be called when query /proc
1717 struct iw_statistics *rt28xx_get_wireless_stats(
1718     IN struct net_device *net_dev)
1719 {
1720         PRTMP_ADAPTER pAd = net_dev->ml_priv;
1721
1722
1723         DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n"));
1724
1725         pAd->iw_stats.status = 0; // Status - device dependent for now
1726
1727         // link quality
1728         pAd->iw_stats.qual.qual = ((pAd->Mlme.ChannelQuality * 12)/10 + 10);
1729         if(pAd->iw_stats.qual.qual > 100)
1730                 pAd->iw_stats.qual.qual = 100;
1731
1732 #ifdef CONFIG_STA_SUPPORT
1733         if (pAd->OpMode == OPMODE_STA)
1734                 pAd->iw_stats.qual.level = RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, pAd->StaCfg.RssiSample.LastRssi1, pAd->StaCfg.RssiSample.LastRssi2);
1735 #endif // CONFIG_STA_SUPPORT //
1736
1737         pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; // noise level (dBm)
1738
1739         pAd->iw_stats.qual.noise += 256 - 143;
1740         pAd->iw_stats.qual.updated = 1;     // Flags to know if updated
1741 #ifdef IW_QUAL_DBM
1742         pAd->iw_stats.qual.updated |= IW_QUAL_DBM;      // Level + Noise are dBm
1743 #endif // IW_QUAL_DBM //
1744
1745         pAd->iw_stats.discard.nwid = 0;     // Rx : Wrong nwid/essid
1746         pAd->iw_stats.miss.beacon = 0;      // Missed beacons/superframe
1747
1748         DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n"));
1749         return &pAd->iw_stats;
1750 } /* End of rt28xx_get_wireless_stats */
1751 #endif // WIRELESS_EXT //
1752
1753
1754
1755 void tbtt_tasklet(unsigned long data)
1756 {
1757 #define MAX_TX_IN_TBTT          (16)
1758
1759 }
1760
1761 INT rt28xx_ioctl(
1762         IN      struct net_device       *net_dev,
1763         IN      OUT     struct ifreq    *rq,
1764         IN      INT                                     cmd)
1765 {
1766         VIRTUAL_ADAPTER *pVirtualAd = NULL;
1767         RTMP_ADAPTER    *pAd = NULL;
1768         INT                             ret = 0;
1769
1770         if (net_dev->priv_flags == INT_MAIN)
1771         {
1772                 pAd = net_dev->ml_priv;
1773         }
1774         else
1775         {
1776                 pVirtualAd = net_dev->ml_priv;
1777                 pAd = pVirtualAd->RtmpDev->ml_priv;
1778         }
1779
1780         if (pAd == NULL)
1781         {
1782                 /* if 1st open fail, pAd will be free;
1783                    So the net_dev->ml_priv will be NULL in 2rd open */
1784                 return -ENETDOWN;
1785         }
1786
1787
1788 #ifdef CONFIG_STA_SUPPORT
1789         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1790         {
1791                 ret = rt28xx_sta_ioctl(net_dev, rq, cmd);
1792         }
1793 #endif // CONFIG_STA_SUPPORT //
1794
1795         return ret;
1796 }
1797
1798 /*
1799     ========================================================================
1800
1801     Routine Description:
1802         return ethernet statistics counter
1803
1804     Arguments:
1805         net_dev                     Pointer to net_device
1806
1807     Return Value:
1808         net_device_stats*
1809
1810     Note:
1811
1812     ========================================================================
1813 */
1814 struct net_device_stats *RT28xx_get_ether_stats(
1815     IN  struct net_device *net_dev)
1816 {
1817     RTMP_ADAPTER *pAd = NULL;
1818
1819         if (net_dev)
1820                 pAd = net_dev->ml_priv;
1821
1822         if (pAd)
1823         {
1824
1825                 pAd->stats.rx_packets = pAd->WlanCounters.ReceivedFragmentCount.QuadPart;
1826                 pAd->stats.tx_packets = pAd->WlanCounters.TransmittedFragmentCount.QuadPart;
1827
1828                 pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount;
1829                 pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount;
1830
1831                 pAd->stats.rx_errors = pAd->Counters8023.RxErrors;
1832                 pAd->stats.tx_errors = pAd->Counters8023.TxErrors;
1833
1834                 pAd->stats.rx_dropped = 0;
1835                 pAd->stats.tx_dropped = 0;
1836
1837             pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart;   // multicast packets received
1838             pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions;  // Collision packets
1839
1840             pAd->stats.rx_length_errors = 0;
1841             pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer;                   // receiver ring buff overflow
1842             pAd->stats.rx_crc_errors = 0;//pAd->WlanCounters.FCSErrorCount;     // recved pkt with crc error
1843             pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors;          // recv'd frame alignment error
1844             pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer;                   // recv'r fifo overrun
1845             pAd->stats.rx_missed_errors = 0;                                            // receiver missed packet
1846
1847             // detailed tx_errors
1848             pAd->stats.tx_aborted_errors = 0;
1849             pAd->stats.tx_carrier_errors = 0;
1850             pAd->stats.tx_fifo_errors = 0;
1851             pAd->stats.tx_heartbeat_errors = 0;
1852             pAd->stats.tx_window_errors = 0;
1853
1854             // for cslip etc
1855             pAd->stats.rx_compressed = 0;
1856             pAd->stats.tx_compressed = 0;
1857
1858                 return &pAd->stats;
1859         }
1860         else
1861         return NULL;
1862 }
1863