blob: cb5fce2702a3727d57edf3e66eb009ae34a656c4 [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: device_main.c
20 *
21 * Purpose: driver entry for initial, open, close, tx and rx.
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Jan 8, 2003
26 *
27 * Functions:
28 *
29 * device_found1 - module initial (insmod) driver entry
30 * device_remove1 - module remove entry
31 * device_init_info - device structure resource allocation function
32 * device_free_info - device structure resource free function
33 * device_get_pci_info - get allocated pci io/mem resource
34 * device_print_info - print out resource
35 * device_open - allocate dma/descripter resource & initial mac/bbp function
36 * device_xmit - asynchrous data tx function
37 * device_intr - interrupt handle function
38 * device_set_multi - set mac filter
39 * device_ioctl - ioctl entry
40 * device_close - shutdown mac/bbp & free dma/descripter resource
41 * device_rx_srv - rx service function
42 * device_receive_frame - rx data function
43 * device_alloc_rx_buf - rx buffer pre-allocated function
44 * device_alloc_frag_buf - rx fragement pre-allocated function
45 * device_free_tx_buf - free tx buffer function
46 * device_free_frag_buf- free de-fragement buffer
47 * device_dma0_tx_80211- tx 802.11 frame via dma0
48 * device_dma0_xmit- tx PS bufferred frame via dma0
49 * device_init_rd0_ring- initial rd dma0 ring
50 * device_init_rd1_ring- initial rd dma1 ring
51 * device_init_td0_ring- initial tx dma0 ring buffer
52 * device_init_td1_ring- initial tx dma1 ring buffer
53 * device_init_registers- initial MAC & BBP & RF internal registers.
54 * device_init_rings- initial tx/rx ring buffer
55 * device_init_defrag_cb- initial & allocate de-fragement buffer.
56 * device_free_rings- free all allocated ring buffer
57 * device_tx_srv- tx interrupt service function
58 *
59 * Revision History:
60 */
61#undef __NO_VERSION__
62
63#if !defined(__DEVICE_H__)
64#include "device.h"
65#endif
66#if !defined(__CARD_H__)
67#include "card.h"
68#endif
69#if !defined(__TBIT_H__)
70#include "tbit.h"
71#endif
72#if !defined(__BASEBAND_H__)
73#include "baseband.h"
74#endif
75#if !defined(__MAC_H__)
76#include "mac.h"
77#endif
78#if !defined(__TETHER_H__)
79#include "tether.h"
80#endif
81#if !defined(__WMGR_H__)
82#include "wmgr.h"
83#endif
84#if !defined(__WCTL_H__)
85#include "wctl.h"
86#endif
87#if !defined(__POWER_H__)
88#include "power.h"
89#endif
90#if !defined(__WCMD_H__)
91#include "wcmd.h"
92#endif
93#if !defined(__IOCMD_H__)
94#include "iocmd.h"
95#endif
96#if !defined(__TCRC_H__)
97#include "tcrc.h"
98#endif
99#if !defined(__RXTX_H__)
100#include "rxtx.h"
101#endif
102#if !defined(__WROUTE_H__)
103#include "wroute.h"
104#endif
105#if !defined(__BSSDB_H__)
106#include "bssdb.h"
107#endif
108#if !defined(__HOSTAP_H__)
109#include "hostap.h"
110#endif
111#if !defined(__WPACTL_H__)
112#include "wpactl.h"
113#endif
114#if !defined(__IOCTL_H__)
115#include "ioctl.h"
116#endif
117#if !defined(__IWCTL_H__)
118#include "iwctl.h"
119#endif
120#if !defined(__DPC_H__)
121#include "dpc.h"
122#endif
123#if !defined(__DATARATE_H__)
124#include "datarate.h"
125#endif
126#if !defined(__RF_H__)
127#include "rf.h"
128#endif
129#if !defined(__IOWPA_H__)
130#include "iowpa.h"
131#endif
132
133#include <linux/delay.h>
134#include <linux/kthread.h>
Forest Bond5449c682009-04-25 10:30:44 -0400135
136
Forest Bond5449c682009-04-25 10:30:44 -0400137//#define DEBUG
138/*--------------------- Static Definitions -------------------------*/
139//static int msglevel =MSG_LEVEL_DEBUG;
140static int msglevel = MSG_LEVEL_INFO;
141
142//#define PLICE_DEBUG
143//
144// Define module options
145//
Forest Bond5449c682009-04-25 10:30:44 -0400146MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
147MODULE_LICENSE("GPL");
148MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
Forest Bond5449c682009-04-25 10:30:44 -0400149
150//PLICE_DEBUG ->
151 static int mlme_kill;
152 //static struct task_struct * mlme_task;
153//PLICE_DEBUG <-
154
155#define DEVICE_PARAM(N,D)
156/*
157 static const int N[MAX_UINTS]=OPTION_DEFAULT;\
158 MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
159 MODULE_PARM_DESC(N, D);
160*/
161
162#define RX_DESC_MIN0 16
163#define RX_DESC_MAX0 128
164#define RX_DESC_DEF0 32
165DEVICE_PARAM(RxDescriptors0,"Number of receive descriptors0");
166
167#define RX_DESC_MIN1 16
168#define RX_DESC_MAX1 128
169#define RX_DESC_DEF1 32
170DEVICE_PARAM(RxDescriptors1,"Number of receive descriptors1");
171
172#define TX_DESC_MIN0 16
173#define TX_DESC_MAX0 128
174#define TX_DESC_DEF0 32
175DEVICE_PARAM(TxDescriptors0,"Number of transmit descriptors0");
176
177#define TX_DESC_MIN1 16
178#define TX_DESC_MAX1 128
179#define TX_DESC_DEF1 64
180DEVICE_PARAM(TxDescriptors1,"Number of transmit descriptors1");
181
182
183#define IP_ALIG_DEF 0
184/* IP_byte_align[] is used for IP header DWORD byte aligned
185 0: indicate the IP header won't be DWORD byte aligned.(Default) .
186 1: indicate the IP header will be DWORD byte aligned.
187 In some enviroment, the IP header should be DWORD byte aligned,
188 or the packet will be droped when we receive it. (eg: IPVS)
189*/
190DEVICE_PARAM(IP_byte_align,"Enable IP header dword aligned");
191
192
193#define INT_WORKS_DEF 20
194#define INT_WORKS_MIN 10
195#define INT_WORKS_MAX 64
196
197DEVICE_PARAM(int_works,"Number of packets per interrupt services");
198
199#define CHANNEL_MIN 1
200#define CHANNEL_MAX 14
201#define CHANNEL_DEF 6
202
203DEVICE_PARAM(Channel, "Channel number");
204
205
206/* PreambleType[] is the preamble length used for transmit.
207 0: indicate allows long preamble type
208 1: indicate allows short preamble type
209*/
210
211#define PREAMBLE_TYPE_DEF 1
212
213DEVICE_PARAM(PreambleType, "Preamble Type");
214
215
216#define RTS_THRESH_MIN 512
217#define RTS_THRESH_MAX 2347
218#define RTS_THRESH_DEF 2347
219
220DEVICE_PARAM(RTSThreshold, "RTS threshold");
221
222
223#define FRAG_THRESH_MIN 256
224#define FRAG_THRESH_MAX 2346
225#define FRAG_THRESH_DEF 2346
226
227DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
228
229
230#define DATA_RATE_MIN 0
231#define DATA_RATE_MAX 13
232#define DATA_RATE_DEF 13
233/* datarate[] index
234 0: indicate 1 Mbps 0x02
235 1: indicate 2 Mbps 0x04
236 2: indicate 5.5 Mbps 0x0B
237 3: indicate 11 Mbps 0x16
238 4: indicate 6 Mbps 0x0c
239 5: indicate 9 Mbps 0x12
240 6: indicate 12 Mbps 0x18
241 7: indicate 18 Mbps 0x24
242 8: indicate 24 Mbps 0x30
243 9: indicate 36 Mbps 0x48
244 10: indicate 48 Mbps 0x60
245 11: indicate 54 Mbps 0x6c
246 12: indicate 72 Mbps 0x90
247 13: indicate auto rate
248*/
249
250DEVICE_PARAM(ConnectionRate, "Connection data rate");
251
252#define OP_MODE_DEF 0
253
254DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
255
256/* OpMode[] is used for transmit.
257 0: indicate infrastruct mode used
258 1: indicate adhoc mode used
259 2: indicate AP mode used
260*/
261
262
263/* PSMode[]
264 0: indicate disable power saving mode
265 1: indicate enable power saving mode
266*/
267
268#define PS_MODE_DEF 0
269
270DEVICE_PARAM(PSMode, "Power saving mode");
271
272
273#define SHORT_RETRY_MIN 0
274#define SHORT_RETRY_MAX 31
275#define SHORT_RETRY_DEF 8
276
277
278DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
279
280#define LONG_RETRY_MIN 0
281#define LONG_RETRY_MAX 15
282#define LONG_RETRY_DEF 4
283
284
285DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
286
287
288/* BasebandType[] baseband type selected
289 0: indicate 802.11a type
290 1: indicate 802.11b type
291 2: indicate 802.11g type
292*/
293#define BBP_TYPE_MIN 0
294#define BBP_TYPE_MAX 2
295#define BBP_TYPE_DEF 2
296
297DEVICE_PARAM(BasebandType, "baseband type");
298
299
300
301/* 80211hEnable[]
302 0: indicate disable 802.11h
303 1: indicate enable 802.11h
304*/
305
306#define X80211h_MODE_DEF 0
307
308DEVICE_PARAM(b80211hEnable, "802.11h mode");
309
310/* 80211hEnable[]
311 0: indicate disable 802.11h
312 1: indicate enable 802.11h
313*/
314
315#define DIVERSITY_ANT_DEF 0
316
317DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
318
319
320//
321// Static vars definitions
322//
323
324
Forest Bond5449c682009-04-25 10:30:44 -0400325static int device_nics =0;
326static PSDevice pDevice_Infos =NULL;
327static struct net_device *root_device_dev = NULL;
328
329static CHIP_INFO chip_info_table[]= {
330 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
331 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
332 {0,NULL}
333};
334
335static struct pci_device_id device_id_table[] __devinitdata = {
Alan Coxf408ade2009-06-10 17:30:49 +0100336{ 0x1106, 0x3253, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long)&chip_info_table[0]},
Forest Bond5449c682009-04-25 10:30:44 -0400337{ 0, }
338};
Forest Bond5449c682009-04-25 10:30:44 -0400339
340/*--------------------- Static Functions --------------------------*/
341
Forest Bond5449c682009-04-25 10:30:44 -0400342
343static int device_found1(struct pci_dev *pcid, const struct pci_device_id *ent);
344static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice, PCHIP_INFO);
345static void device_free_info(PSDevice pDevice);
346static BOOL device_get_pci_info(PSDevice, struct pci_dev* pcid);
347static void device_print_info(PSDevice pDevice);
348static struct net_device_stats *device_get_stats(struct net_device *dev);
349static void device_init_diversity_timer(PSDevice pDevice);
350static int device_open(struct net_device *dev);
351static int device_xmit(struct sk_buff *skb, struct net_device *dev);
352static irqreturn_t device_intr(int irq, void*dev_instance);
353static void device_set_multi(struct net_device *dev);
354static int device_close(struct net_device *dev);
355static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
356
Forest Bond5449c682009-04-25 10:30:44 -0400357#ifdef CONFIG_PM
358static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
Alan Coxf408ade2009-06-10 17:30:49 +0100359static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
Forest Bond5449c682009-04-25 10:30:44 -0400360static int viawget_resume(struct pci_dev *pcid);
361struct notifier_block device_notifier = {
362 notifier_call: device_notify_reboot,
363 next: NULL,
364 priority: 0
365};
366#endif
Forest Bond5449c682009-04-25 10:30:44 -0400367
Forest Bond5449c682009-04-25 10:30:44 -0400368
369static void device_init_rd0_ring(PSDevice pDevice);
370static void device_init_rd1_ring(PSDevice pDevice);
371static void device_init_defrag_cb(PSDevice pDevice);
372static void device_init_td0_ring(PSDevice pDevice);
373static void device_init_td1_ring(PSDevice pDevice);
374
Forest Bond5449c682009-04-25 10:30:44 -0400375static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
Forest Bond5449c682009-04-25 10:30:44 -0400376//2008-0714<Add>by Mike Liu
377static BOOL device_release_WPADEV(PSDevice pDevice);
378
379static int ethtool_ioctl(struct net_device *dev, void *useraddr);
380static int device_rx_srv(PSDevice pDevice, UINT uIdx);
381static int device_tx_srv(PSDevice pDevice, UINT uIdx);
382static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
383static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
384static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
385static void device_free_td0_ring(PSDevice pDevice);
386static void device_free_td1_ring(PSDevice pDevice);
387static void device_free_rd0_ring(PSDevice pDevice);
388static void device_free_rd1_ring(PSDevice pDevice);
389static void device_free_rings(PSDevice pDevice);
390static void device_free_frag_buf(PSDevice pDevice);
391static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source);
392
393
394/*--------------------- Export Variables --------------------------*/
395
396/*--------------------- Export Functions --------------------------*/
397
398
Forest Bond5449c682009-04-25 10:30:44 -0400399
400static char* get_chip_name(int chip_id) {
401 int i;
402 for (i=0;chip_info_table[i].name!=NULL;i++)
403 if (chip_info_table[i].chip_id==chip_id)
404 break;
405 return chip_info_table[i].name;
406}
407
408static void __devexit device_remove1(struct pci_dev *pcid)
409{
410 PSDevice pDevice=pci_get_drvdata(pcid);
411
412 if (pDevice==NULL)
413 return;
414 device_free_info(pDevice);
415
416}
417
Forest Bond5449c682009-04-25 10:30:44 -0400418/*
419static void
420device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
421 if (val==-1)
422 *opt=def;
423 else if (val<min || val>max) {
424 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
425 devname,name, min,max);
426 *opt=def;
427 } else {
428 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
429 devname, name, val);
430 *opt=val;
431 }
432}
433
434static void
435device_set_bool_opt(PU32 opt, int val,BOOL def,U32 flag, char* name,char* devname) {
436 (*opt)&=(~flag);
437 if (val==-1)
438 *opt|=(def ? flag : 0);
439 else if (val<0 || val>1) {
440 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE
441 "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
442 *opt|=(def ? flag : 0);
443 } else {
444 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
445 devname,name , val ? "TRUE" : "FALSE");
446 *opt|=(val ? flag : 0);
447 }
448}
449*/
450static void
451device_get_options(PSDevice pDevice, int index, char* devname) {
452
453 POPTIONS pOpts = &(pDevice->sOpts);
454 pOpts->nRxDescs0=RX_DESC_DEF0;
455 pOpts->nRxDescs1=RX_DESC_DEF1;
456 pOpts->nTxDescs[0]=TX_DESC_DEF0;
457 pOpts->nTxDescs[1]=TX_DESC_DEF1;
458pOpts->flags|=DEVICE_FLAGS_IP_ALIGN;
459 pOpts->int_works=INT_WORKS_DEF;
460 pOpts->rts_thresh=RTS_THRESH_DEF;
461 pOpts->frag_thresh=FRAG_THRESH_DEF;
462 pOpts->data_rate=DATA_RATE_DEF;
463 pOpts->channel_num=CHANNEL_DEF;
464
465pOpts->flags|=DEVICE_FLAGS_PREAMBLE_TYPE;
466pOpts->flags|=DEVICE_FLAGS_OP_MODE;
467//pOpts->flags|=DEVICE_FLAGS_PS_MODE;
468 pOpts->short_retry=SHORT_RETRY_DEF;
469 pOpts->long_retry=LONG_RETRY_DEF;
470 pOpts->bbp_type=BBP_TYPE_DEF;
471pOpts->flags|=DEVICE_FLAGS_80211h_MODE;
472pOpts->flags|=DEVICE_FLAGS_DiversityANT;
473
474
475}
476
477static void
478device_set_options(PSDevice pDevice) {
479
480 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
481 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
482 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
483
484
485 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
486 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
487 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
488
489 pDevice->uChannel = pDevice->sOpts.channel_num;
490 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
491 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
492 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
493 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
494 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
495 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
496 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
497 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
498 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
499 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
500 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
501 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
502 pDevice->byBBType = pDevice->sOpts.bbp_type;
503 pDevice->byPacketType = pDevice->byBBType;
504
505//PLICE_DEBUG->
506 pDevice->byAutoFBCtrl = AUTO_FB_0;
507 //pDevice->byAutoFBCtrl = AUTO_FB_1;
508//PLICE_DEBUG<-
509pDevice->bUpdateBBVGA = TRUE;
510 pDevice->byFOETuning = 0;
511 pDevice->wCTSDuration = 0;
512 pDevice->byPreambleType = 0;
513
514
515 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(INT)pDevice->uChannel);
516 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(INT)pDevice->byOpMode);
517 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(INT)pDevice->ePSMode);
518 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(INT)pDevice->wRTSThreshold);
519 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(INT)pDevice->byShortRetryLimit);
520 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(INT)pDevice->byLongRetryLimit);
521 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(INT)pDevice->byPreambleType);
522 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(INT)pDevice->byShortPreamble);
523 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(INT)pDevice->uConnectionRate);
524 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(INT)pDevice->byBBType);
525 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(INT)pDevice->b11hEnable);
526 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(INT)pDevice->bDiversityRegCtlON);
527}
528
529static VOID s_vCompleteCurrentMeasure (IN PSDevice pDevice, IN BYTE byResult)
530{
531 UINT ii;
532 DWORD dwDuration = 0;
533 BYTE byRPI0 = 0;
534
535 for(ii=1;ii<8;ii++) {
536 pDevice->dwRPIs[ii] *= 255;
537 dwDuration |= *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
538 dwDuration <<= 10;
539 pDevice->dwRPIs[ii] /= dwDuration;
540 pDevice->abyRPIs[ii] = (BYTE) pDevice->dwRPIs[ii];
541 byRPI0 += pDevice->abyRPIs[ii];
542 }
543 pDevice->abyRPIs[0] = (0xFF - byRPI0);
544
545 if (pDevice->uNumOfMeasureEIDs == 0) {
546 VNTWIFIbMeasureReport( pDevice->pMgmt,
547 TRUE,
548 pDevice->pCurrMeasureEID,
549 byResult,
550 pDevice->byBasicMap,
551 pDevice->byCCAFraction,
552 pDevice->abyRPIs
553 );
554 } else {
555 VNTWIFIbMeasureReport( pDevice->pMgmt,
556 FALSE,
557 pDevice->pCurrMeasureEID,
558 byResult,
559 pDevice->byBasicMap,
560 pDevice->byCCAFraction,
561 pDevice->abyRPIs
562 );
563 CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
564 }
565
566}
567
568
569
570//
571// Initialiation of MAC & BBP registers
572//
573
574static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
575{
576 UINT ii;
577 BYTE byValue;
578 BYTE byValue1;
579 BYTE byCCKPwrdBm = 0;
580 BYTE byOFDMPwrdBm = 0;
581 INT zonetype=0;
582 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
583 MACbShutdown(pDevice->PortOffset);
584 BBvSoftwareReset(pDevice->PortOffset);
585
586 if ((InitType == DEVICE_INIT_COLD) ||
587 (InitType == DEVICE_INIT_DXPL)) {
588 // Do MACbSoftwareReset in MACvInitialize
589 MACbSoftwareReset(pDevice->PortOffset);
590 // force CCK
591 pDevice->bCCK = TRUE;
592 pDevice->bAES = FALSE;
593 pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE
594 pDevice->bNonERPPresent = FALSE;
595 pDevice->bBarkerPreambleMd = FALSE;
596 pDevice->wCurrentRate = RATE_1M;
597 pDevice->byTopOFDMBasicRate = RATE_24M;
598 pDevice->byTopCCKBasicRate = RATE_1M;
599
600 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
601
602 // init MAC
603 MACvInitialize(pDevice->PortOffset);
604
605 // Get Local ID
606 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
607
608 spin_lock_irq(&pDevice->lock);
609 SROMvReadAllContents(pDevice->PortOffset,pDevice->abyEEPROM);
610
611 spin_unlock_irq(&pDevice->lock);
612
613 // Get Channel range
614
615 pDevice->byMinChannel = 1;
616 pDevice->byMaxChannel = CB_MAX_CHANNEL;
617
618 // Get Antena
619 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
620 if (byValue & EEP_ANTINV)
621 pDevice->bTxRxAntInv = TRUE;
622 else
623 pDevice->bTxRxAntInv = FALSE;
624#ifdef PLICE_DEBUG
625 //printk("init_register:TxRxAntInv is %d,byValue is %d\n",pDevice->bTxRxAntInv,byValue);
626#endif
627
628 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
629 if (byValue == 0) // if not set default is All
630 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
631#ifdef PLICE_DEBUG
632 //printk("init_register:byValue is %d\n",byValue);
633#endif
634 pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
635 pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
636 pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
637 pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
638 pDevice->ulSQ3TH = 0;//(ULONG) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
639 pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
640
641 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
642 pDevice->byAntennaCount = 2;
643 pDevice->byTxAntennaMode = ANT_B;
644 pDevice->dwTxAntennaSel = 1;
645 pDevice->dwRxAntennaSel = 1;
646 if (pDevice->bTxRxAntInv == TRUE)
647 pDevice->byRxAntennaMode = ANT_A;
648 else
649 pDevice->byRxAntennaMode = ANT_B;
650 // chester for antenna
651byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
652 // if (pDevice->bDiversityRegCtlON)
653 if((byValue1&0x08)==0)
654 pDevice->bDiversityEnable = FALSE;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
655 else
656 pDevice->bDiversityEnable = TRUE;
657#ifdef PLICE_DEBUG
658 //printk("aux |main antenna: RxAntennaMode is %d\n",pDevice->byRxAntennaMode);
659#endif
660 } else {
661 pDevice->bDiversityEnable = FALSE;
662 pDevice->byAntennaCount = 1;
663 pDevice->dwTxAntennaSel = 0;
664 pDevice->dwRxAntennaSel = 0;
665 if (byValue & EEP_ANTENNA_AUX) {
666 pDevice->byTxAntennaMode = ANT_A;
667 if (pDevice->bTxRxAntInv == TRUE)
668 pDevice->byRxAntennaMode = ANT_B;
669 else
670 pDevice->byRxAntennaMode = ANT_A;
671 } else {
672 pDevice->byTxAntennaMode = ANT_B;
673 if (pDevice->bTxRxAntInv == TRUE)
674 pDevice->byRxAntennaMode = ANT_A;
675 else
676 pDevice->byRxAntennaMode = ANT_B;
677 }
678 }
679#ifdef PLICE_DEBUG
680 //printk("init registers: TxAntennaMode is %d\n",pDevice->byTxAntennaMode);
681#endif
682 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
683 pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
684
685//#ifdef ZoneType_DefaultSetting
686//2008-8-4 <add> by chester
687//zonetype initial
688 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
689 if((zonetype=Config_FileOperation(pDevice,FALSE,NULL)) >= 0) { //read zonetype file ok!
690 if ((zonetype == 0)&&
691 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] !=0x00)){ //for USA
692 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
693 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
694 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :USA\n");
695 }
696 else if((zonetype == 1)&&
697 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x01)){ //for Japan
698 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
699 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
700 }
701 else if((zonetype == 2)&&
702 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x02)){ //for Europe
703 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
704 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
705 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :Europe\n");
706 }
707
708else
709{
710 if(zonetype!=pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
711 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype,pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
712 else
713 printk("Read Zonetype file sucess,use default zonetype setting[%02x]\n",zonetype);
714 }
715 }
716 else
717 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
718
719 // Get RFType
720 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
721
722 if ((pDevice->byRFType & RF_EMU) != 0) {
723 // force change RevID for VT3253 emu
724 pDevice->byRevId = 0x80;
725 }
726
727 pDevice->byRFType &= RF_MASK;
728 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
729
730 if (pDevice->bZoneRegExist == FALSE) {
731 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
732 }
733 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
734
735 //Init RF module
736 RFbInit(pDevice);
737
738 //Get Desire Power Value
739 pDevice->byCurPwr = 0xFF;
740 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
741 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
742 //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
743
744 //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
745//printk("CCKPwrdBm is 0x%x,byOFDMPwrdBm is 0x%x\n",byCCKPwrdBm,byOFDMPwrdBm);
746 // Load power Table
747
748
749 for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
750 pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_CCK_PWR_TBL));
751 if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
752 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
753 }
754 pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDM_PWR_TBL));
755 if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
756 pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
757 }
758 pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
759 pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
760 }
761 //2008-8-4 <add> by chester
762 //recover 12,13 ,14channel for EUROPE by 11 channel
763 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
764 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
765 (pDevice->byOriginalZonetype == ZoneType_USA)) {
766 for(ii=11;ii<14;ii++) {
767 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
768 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
769
770 }
771 }
772
773
774 // Load OFDM A Power Table
775 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
776 pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_TBL));
777 pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_dBm));
778 }
779 CARDvInitChannelTable((PVOID)pDevice);
780
781
782 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
783 MACvSelectPage1(pDevice->PortOffset);
784 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
785 MACvSelectPage0(pDevice->PortOffset);
786 }
787
788
789 // use relative tx timeout and 802.11i D4
790 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
791
792 // set performance parameter by registry
793 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
794 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
795
796 // reset TSF counter
797 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
798 // enable TSF counter
799 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
800
801 // initialize BBP registers
802 BBbVT3253Init(pDevice);
803
804 if (pDevice->bUpdateBBVGA) {
805 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
806 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
807 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
808 }
809#ifdef PLICE_DEBUG
810 //printk("init registers:RxAntennaMode is %x,TxAntennaMode is %x\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
811#endif
812 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
813 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
814
815 pDevice->byCurrentCh = 0;
816
817 //pDevice->NetworkType = Ndis802_11Automode;
818 // Set BB and packet type at the same time.
819 // Set Short Slot Time, xIFS, and RSPINF.
820 if (pDevice->uConnectionRate == RATE_AUTO) {
821 pDevice->wCurrentRate = RATE_54M;
822 } else {
823 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
824 }
825
826 // default G Mode
827 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
828 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
829
830 pDevice->bRadioOff = FALSE;
831
832 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
833 pDevice->bHWRadioOff = FALSE;
834
835 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
836 // Get GPIO
837 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
838//2008-4-14 <add> by chester for led issue
839 #ifdef FOR_LED_ON_NOTEBOOK
840if (BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA)){pDevice->bHWRadioOff = TRUE;}
841if (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA)){pDevice->bHWRadioOff = FALSE;}
842
843 }
844 if ( (pDevice->bRadioControlOff == TRUE)) {
845 CARDbRadioPowerOff(pDevice);
846 }
847else CARDbRadioPowerOn(pDevice);
848#else
849 if ((BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOff(pDevice->byRadioCtl, EEP_RADIOCTL_INV)) ||
850 (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV))) {
851 pDevice->bHWRadioOff = TRUE;
852 }
853 }
854 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
855 CARDbRadioPowerOff(pDevice);
856 }
857
858#endif
859 }
860 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
861 // get Permanent network address
862 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
863 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
864 pDevice->abyCurrentNetAddr[0],
865 pDevice->abyCurrentNetAddr[1],
866 pDevice->abyCurrentNetAddr[2],
867 pDevice->abyCurrentNetAddr[3],
868 pDevice->abyCurrentNetAddr[4],
869 pDevice->abyCurrentNetAddr[5]);
870
871
872 // reset Tx pointer
873 CARDvSafeResetRx(pDevice);
874 // reset Rx pointer
875 CARDvSafeResetTx(pDevice);
876
877 if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
878 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
879 }
880
881 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
882
883 // Turn On Rx DMA
884 MACvReceive0(pDevice->PortOffset);
885 MACvReceive1(pDevice->PortOffset);
886
887 // start the adapter
888 MACvStart(pDevice->PortOffset);
889
890 netif_stop_queue(pDevice->dev);
891
892
893}
894
895
896
897static VOID device_init_diversity_timer(PSDevice pDevice) {
898
899 init_timer(&pDevice->TimerSQ3Tmax1);
900 pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
901 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
902 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
903
904 init_timer(&pDevice->TimerSQ3Tmax2);
905 pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
906 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
907 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
908
909 init_timer(&pDevice->TimerSQ3Tmax3);
910 pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
911 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
912 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
913
914 return;
915}
916
917
918static BOOL device_release_WPADEV(PSDevice pDevice)
919{
920 viawget_wpa_header *wpahdr;
921 int ii=0;
922 // wait_queue_head_t Set_wait;
923 //send device close to wpa_supplicnat layer
924 if (pDevice->bWPADEVUp==TRUE) {
925 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
926 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
927 wpahdr->resp_ie_len = 0;
928 wpahdr->req_ie_len = 0;
929 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
930 pDevice->skb->dev = pDevice->wpadev;
Forest Bond5449c682009-04-25 10:30:44 -0400931 pDevice->skb->mac_header = pDevice->skb->data;
Forest Bond5449c682009-04-25 10:30:44 -0400932 pDevice->skb->pkt_type = PACKET_HOST;
933 pDevice->skb->protocol = htons(ETH_P_802_2);
934 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
935 netif_rx(pDevice->skb);
936 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
937
938 //wait release WPADEV
939 // init_waitqueue_head(&Set_wait);
940 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
941 while((pDevice->bWPADEVUp==TRUE)) {
942 set_current_state(TASK_UNINTERRUPTIBLE);
943 schedule_timeout (HZ/20); //wait 50ms
944 ii++;
945 if(ii>20)
946 break;
947 }
948 };
949 return TRUE;
950}
951
952
Forest Bond57211352009-06-02 14:44:33 -0400953static const struct net_device_ops device_netdev_ops = {
954 .ndo_open = device_open,
955 .ndo_stop = device_close,
956 .ndo_do_ioctl = device_ioctl,
957 .ndo_get_stats = device_get_stats,
958 .ndo_start_xmit = device_xmit,
959 .ndo_set_multicast_list = device_set_multi,
960};
961
962
Forest Bond5449c682009-04-25 10:30:44 -0400963
964static int
965device_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
966{
967 static BOOL bFirst = TRUE;
968 struct net_device* dev = NULL;
969 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
970 PSDevice pDevice;
Forest Bond5449c682009-04-25 10:30:44 -0400971 int rc;
Forest Bond5449c682009-04-25 10:30:44 -0400972 if (device_nics ++>= MAX_UINTS) {
973 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
974 return -ENODEV;
975 }
976
977
Forest Bondc9d03522009-06-01 20:00:14 -0400978 dev = alloc_etherdev(sizeof(DEVICE_INFO));
Forest Bond5449c682009-04-25 10:30:44 -0400979
Forest Bondc9d03522009-06-01 20:00:14 -0400980 pDevice = (PSDevice) netdev_priv(dev);
981
Forest Bond5449c682009-04-25 10:30:44 -0400982 if (dev == NULL) {
983 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
984 return -ENODEV;
985 }
986
Forest Bond5449c682009-04-25 10:30:44 -0400987 // Chain it all together
988 // SET_MODULE_OWNER(dev);
989 SET_NETDEV_DEV(dev, &pcid->dev);
Forest Bond5449c682009-04-25 10:30:44 -0400990
991 if (bFirst) {
992 printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
993 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
994 bFirst=FALSE;
995 }
996
997 if (!device_init_info(pcid, &pDevice, pChip_info)) {
998 return -ENOMEM;
999 }
1000 pDevice->dev = dev;
1001 pDevice->next_module = root_device_dev;
1002 root_device_dev = dev;
Forest Bond5449c682009-04-25 10:30:44 -04001003 dev->irq = pcid->irq;
1004
1005 if (pci_enable_device(pcid)) {
1006 device_free_info(pDevice);
1007 return -ENODEV;
1008 }
1009#ifdef DEBUG
1010 printk("Before get pci_info memaddr is %x\n",pDevice->memaddr);
1011#endif
1012 if (device_get_pci_info(pDevice,pcid) == FALSE) {
1013 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
1014 device_free_info(pDevice);
1015 return -ENODEV;
1016 }
1017
1018#if 1
1019
1020#ifdef DEBUG
1021
1022 //pci_read_config_byte(pcid, PCI_BASE_ADDRESS_0, &pDevice->byRevId);
1023 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice->memaddr,pDevice->ioaddr,pDevice->io_size);
1024 {
1025 int i;
1026 U32 bar,len;
1027 u32 address[] = {
1028 PCI_BASE_ADDRESS_0,
1029 PCI_BASE_ADDRESS_1,
1030 PCI_BASE_ADDRESS_2,
1031 PCI_BASE_ADDRESS_3,
1032 PCI_BASE_ADDRESS_4,
1033 PCI_BASE_ADDRESS_5,
1034 0};
1035 for (i=0;address[i];i++)
1036 {
1037 //pci_write_config_dword(pcid,address[i], 0xFFFFFFFF);
1038 pci_read_config_dword(pcid, address[i], &bar);
1039 printk("bar %d is %x\n",i,bar);
1040 if (!bar)
1041 {
1042 printk("bar %d not implemented\n",i);
1043 continue;
1044 }
1045 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1046 /* This is IO */
1047
1048 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
1049 len = len & ~(len - 1);
1050
1051 printk("IO space: len in IO %x, BAR %d\n", len, i);
1052 }
1053 else
1054 {
1055 len = bar & 0xFFFFFFF0;
1056 len = ~len + 1;
1057
1058 printk("len in MEM %x, BAR %d\n", len, i);
1059 }
1060 }
1061 }
1062#endif
1063
1064
1065#endif
1066
1067#ifdef DEBUG
1068 //return 0 ;
1069#endif
1070 pDevice->PortOffset = (DWORD)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
1071 //pDevice->PortOffset = (DWORD)ioremap(pDevice->ioaddr & PCI_BASE_ADDRESS_IO_MASK, pDevice->io_size);
1072
1073 if(pDevice->PortOffset == 0) {
1074 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
1075 device_free_info(pDevice);
1076 return -ENODEV;
1077 }
1078
1079
1080
1081
Forest Bond5449c682009-04-25 10:30:44 -04001082 rc = pci_request_regions(pcid, DEVICE_NAME);
1083 if (rc) {
1084 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1085 device_free_info(pDevice);
1086 return -ENODEV;
1087 }
Forest Bond5449c682009-04-25 10:30:44 -04001088
1089 dev->base_addr = pDevice->ioaddr;
1090#ifdef PLICE_DEBUG
1091 BYTE value;
1092
1093 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1094 printk("Before write: value is %x\n",value);
1095 //VNSvInPortB(pDevice->PortOffset+0x3F, 0x00);
1096 VNSvOutPortB(pDevice->PortOffset,value);
1097 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1098 printk("After write: value is %x\n",value);
1099#endif
1100
1101
1102
1103#ifdef IO_MAP
1104 pDevice->PortOffset = pDevice->ioaddr;
1105#endif
1106 // do reset
1107 if (!MACbSoftwareReset(pDevice->PortOffset)) {
1108 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
1109 device_free_info(pDevice);
1110 return -ENODEV;
1111 }
1112 // initial to reload eeprom
1113 MACvInitialize(pDevice->PortOffset);
1114 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
1115
1116 device_get_options(pDevice, device_nics-1, dev->name);
1117 device_set_options(pDevice);
1118 //Mask out the options cannot be set to the chip
1119 pDevice->sOpts.flags &= pChip_info->flags;
1120
1121 //Enable the chip specified capbilities
1122 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
1123 pDevice->tx_80211 = device_dma0_tx_80211;
1124 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
1125 pDevice->pMgmt = &(pDevice->sMgmtObj);
1126
1127 dev->irq = pcid->irq;
Forest Bond57211352009-06-02 14:44:33 -04001128 dev->netdev_ops = &device_netdev_ops;
Forest Bond5449c682009-04-25 10:30:44 -04001129
Forest Bond5449c682009-04-25 10:30:44 -04001130 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
Forest Bond5449c682009-04-25 10:30:44 -04001131
Forest Bond5449c682009-04-25 10:30:44 -04001132 rc = register_netdev(dev);
1133 if (rc)
1134 {
1135 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
1136 device_free_info(pDevice);
1137 return -ENODEV;
1138 }
Forest Bond5449c682009-04-25 10:30:44 -04001139//2008-07-21-01<Add>by MikeLiu
1140//register wpadev
1141 if(wpa_set_wpadev(pDevice, 1)!=0) {
1142 printk("Fail to Register WPADEV?\n");
1143 unregister_netdev(pDevice->dev);
1144 free_netdev(dev);
Forest Bond5449c682009-04-25 10:30:44 -04001145 }
1146 device_print_info(pDevice);
1147 pci_set_drvdata(pcid, pDevice);
1148 return 0;
1149
1150}
1151
1152static void device_print_info(PSDevice pDevice)
1153{
1154 struct net_device* dev=pDevice->dev;
1155
1156 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
1157 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
1158 dev->name,
1159 dev->dev_addr[0],dev->dev_addr[1],dev->dev_addr[2],
1160 dev->dev_addr[3],dev->dev_addr[4],dev->dev_addr[5]);
1161#ifdef IO_MAP
1162 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx ",(ULONG) pDevice->ioaddr);
1163 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1164#else
1165 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",(ULONG) pDevice->ioaddr,(ULONG) pDevice->PortOffset);
1166 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1167#endif
1168
1169}
1170
1171static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
1172 PCHIP_INFO pChip_info) {
1173
1174 PSDevice p;
1175
Forest Bond5449c682009-04-25 10:30:44 -04001176 memset(*ppDevice,0,sizeof(DEVICE_INFO));
1177
1178 if (pDevice_Infos == NULL) {
1179 pDevice_Infos =*ppDevice;
1180 }
1181 else {
1182 for (p=pDevice_Infos;p->next!=NULL;p=p->next)
1183 do {} while (0);
1184 p->next = *ppDevice;
1185 (*ppDevice)->prev = p;
1186 }
1187
1188 (*ppDevice)->pcid = pcid;
1189 (*ppDevice)->chip_id = pChip_info->chip_id;
1190 (*ppDevice)->io_size = pChip_info->io_size;
1191 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
1192 (*ppDevice)->multicast_limit =32;
1193
1194 spin_lock_init(&((*ppDevice)->lock));
1195
1196 return TRUE;
1197}
1198
1199static BOOL device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
1200
1201 U16 pci_cmd;
1202 U8 b;
1203 UINT cis_addr;
1204#ifdef PLICE_DEBUG
1205 BYTE pci_config[256];
1206 BYTE value =0x00;
1207 int ii,j;
1208 U16 max_lat=0x0000;
1209 memset(pci_config,0x00,256);
1210#endif
1211
1212 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1213 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,&pDevice->SubSystemID);
1214 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1215 pci_read_config_word(pcid, PCI_COMMAND, (u16 *) & (pci_cmd));
1216
1217 pci_set_master(pcid);
1218
1219 pDevice->memaddr = pci_resource_start(pcid,0);
1220 pDevice->ioaddr = pci_resource_start(pcid,1);
1221
1222#ifdef DEBUG
1223// pDevice->ioaddr = pci_resource_start(pcid, 0);
1224// pDevice->memaddr = pci_resource_start(pcid,1);
1225#endif
1226
1227 cis_addr = pci_resource_start(pcid,2);
1228
1229 pDevice->pcid = pcid;
1230
1231 pci_read_config_byte(pcid, PCI_REG_COMMAND, &b);
1232 pci_write_config_byte(pcid, PCI_REG_COMMAND, (b|COMMAND_BUSM));
1233
1234#ifdef PLICE_DEBUG
1235 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1236 //printk("max lat is %x,SubSystemID is %x\n",max_lat,pDevice->SubSystemID);
1237 //for (ii=0;ii<0xFF;ii++)
1238 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1239 //max_lat = 0x20;
1240 //pci_write_config_word(pcid,PCI_REG_MAX_LAT,max_lat);
1241 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1242 //printk("max lat is %x\n",max_lat);
1243
1244 for (ii=0;ii<0xFF;ii++)
1245 {
1246 pci_read_config_byte(pcid,ii,&value);
1247 pci_config[ii] = value;
1248 }
1249 for (ii=0,j=1;ii<0x100;ii++,j++)
1250 {
1251 if (j %16 == 0)
1252 {
1253 printk("%x:",pci_config[ii]);
1254 printk("\n");
1255 }
1256 else
1257 {
1258 printk("%x:",pci_config[ii]);
1259 }
1260 }
1261#endif
1262 return TRUE;
1263}
1264
1265static void device_free_info(PSDevice pDevice) {
1266 PSDevice ptr;
1267 struct net_device* dev=pDevice->dev;
1268
1269 ASSERT(pDevice);
1270//2008-0714-01<Add>by chester
1271device_release_WPADEV(pDevice);
1272
1273//2008-07-21-01<Add>by MikeLiu
1274//unregister wpadev
1275 if(wpa_set_wpadev(pDevice, 0)!=0)
1276 printk("unregister wpadev fail?\n");
1277
1278 if (pDevice_Infos==NULL)
1279 return;
1280
1281 for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
1282 do {} while (0);
1283
1284 if (ptr==pDevice) {
1285 if (ptr==pDevice_Infos)
1286 pDevice_Infos=ptr->next;
1287 else
1288 ptr->prev->next=ptr->next;
1289 }
1290 else {
1291 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1292 return;
1293 }
1294#ifdef HOSTAP
1295 if (dev)
1296 hostap_set_hostapd(pDevice, 0, 0);
1297#endif
1298 if (dev)
1299 unregister_netdev(dev);
1300
1301 if (pDevice->PortOffset)
1302 iounmap((PVOID)pDevice->PortOffset);
1303
Forest Bond5449c682009-04-25 10:30:44 -04001304 if (pDevice->pcid)
1305 pci_release_regions(pDevice->pcid);
1306 if (dev)
1307 free_netdev(dev);
Forest Bond5449c682009-04-25 10:30:44 -04001308
1309 if (pDevice->pcid) {
1310 pci_set_drvdata(pDevice->pcid,NULL);
1311 }
Forest Bond5449c682009-04-25 10:30:44 -04001312}
Forest Bond5449c682009-04-25 10:30:44 -04001313
1314static BOOL device_init_rings(PSDevice pDevice) {
1315 void* vir_pool;
1316
1317
1318 /*allocate all RD/TD rings a single pool*/
1319 vir_pool = pci_alloc_consistent(pDevice->pcid,
1320 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1321 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1322 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1323 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1324 &pDevice->pool_dma);
1325
1326 if (vir_pool == NULL) {
1327 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1328 return FALSE;
1329 }
1330
1331 memset(vir_pool, 0,
1332 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1333 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1334 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1335 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1336 );
1337
1338 pDevice->aRD0Ring = vir_pool;
1339 pDevice->aRD1Ring = vir_pool +
1340 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1341
1342
1343 pDevice->rd0_pool_dma = pDevice->pool_dma;
1344 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1345 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1346
1347 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1348 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1349 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1350 CB_BEACON_BUF_SIZE +
1351 CB_MAX_BUF_SIZE,
1352 &pDevice->tx_bufs_dma0);
1353
1354 if (pDevice->tx0_bufs == NULL) {
1355 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1356 pci_free_consistent(pDevice->pcid,
1357 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1358 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1359 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1360 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1361 vir_pool, pDevice->pool_dma
1362 );
1363 return FALSE;
1364 }
1365
1366 memset(pDevice->tx0_bufs, 0,
1367 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1368 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1369 CB_BEACON_BUF_SIZE +
1370 CB_MAX_BUF_SIZE
1371 );
1372
1373 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1374 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1375
1376 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1377 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1378
1379
1380 // vir_pool: pvoid type
1381 pDevice->apTD0Rings = vir_pool
1382 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1383 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1384
1385 pDevice->apTD1Rings = vir_pool
1386 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1387 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1388 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1389
1390
1391 pDevice->tx1_bufs = pDevice->tx0_bufs +
1392 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1393
1394
1395 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1396 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1397
1398 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1399 CB_BEACON_BUF_SIZE;
1400
1401 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1402 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1403
1404
1405 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1406 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1407
1408
1409 return TRUE;
1410}
1411
1412static void device_free_rings(PSDevice pDevice) {
1413
1414 pci_free_consistent(pDevice->pcid,
1415 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1416 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1417 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1418 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1419 ,
1420 pDevice->aRD0Ring, pDevice->pool_dma
1421 );
1422
1423 if (pDevice->tx0_bufs)
1424 pci_free_consistent(pDevice->pcid,
1425 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1426 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1427 CB_BEACON_BUF_SIZE +
1428 CB_MAX_BUF_SIZE,
1429 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1430 );
1431}
1432
1433static void device_init_rd0_ring(PSDevice pDevice) {
1434 int i;
1435 dma_addr_t curr = pDevice->rd0_pool_dma;
1436 PSRxDesc pDesc;
1437
1438 /* Init the RD0 ring entries */
1439 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1440 pDesc = &(pDevice->aRD0Ring[i]);
1441 pDesc->pRDInfo = alloc_rd_info();
1442 ASSERT(pDesc->pRDInfo);
1443 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1444 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1445 pDevice->dev->name);
1446 }
1447 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1448 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1449 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1450 }
1451
1452 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1453 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1454}
1455
1456
1457static void device_init_rd1_ring(PSDevice pDevice) {
1458 int i;
1459 dma_addr_t curr = pDevice->rd1_pool_dma;
1460 PSRxDesc pDesc;
1461
1462 /* Init the RD1 ring entries */
1463 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1464 pDesc = &(pDevice->aRD1Ring[i]);
1465 pDesc->pRDInfo = alloc_rd_info();
1466 ASSERT(pDesc->pRDInfo);
1467 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1468 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1469 pDevice->dev->name);
1470 }
1471 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1472 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1473 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1474 }
1475
1476 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1477 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1478}
1479
1480
1481static void device_init_defrag_cb(PSDevice pDevice) {
1482 int i;
1483 PSDeFragControlBlock pDeF;
1484
1485 /* Init the fragment ctl entries */
1486 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1487 pDeF = &(pDevice->sRxDFCB[i]);
1488 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1489 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
1490 pDevice->dev->name);
1491 };
1492 }
1493 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1494 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1495}
1496
1497
1498
1499
1500static void device_free_rd0_ring(PSDevice pDevice) {
1501 int i;
1502
1503 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1504 PSRxDesc pDesc =&(pDevice->aRD0Ring[i]);
1505 PDEVICE_RD_INFO pRDInfo =pDesc->pRDInfo;
1506
1507 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1508 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1509
1510 dev_kfree_skb(pRDInfo->skb);
1511
1512 kfree((PVOID)pDesc->pRDInfo);
1513 }
1514
1515}
1516
1517static void device_free_rd1_ring(PSDevice pDevice) {
1518 int i;
1519
1520
1521 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1522 PSRxDesc pDesc=&(pDevice->aRD1Ring[i]);
1523 PDEVICE_RD_INFO pRDInfo=pDesc->pRDInfo;
1524
1525 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1526 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1527
1528 dev_kfree_skb(pRDInfo->skb);
1529
1530 kfree((PVOID)pDesc->pRDInfo);
1531 }
1532
1533}
1534
1535static void device_free_frag_buf(PSDevice pDevice) {
1536 PSDeFragControlBlock pDeF;
1537 int i;
1538
1539 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1540
1541 pDeF = &(pDevice->sRxDFCB[i]);
1542
1543 if (pDeF->skb)
1544 dev_kfree_skb(pDeF->skb);
1545
1546 }
1547
1548}
1549
1550static void device_init_td0_ring(PSDevice pDevice) {
1551 int i;
1552 dma_addr_t curr;
1553 PSTxDesc pDesc;
1554
1555 curr = pDevice->td0_pool_dma;
1556 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1557 pDesc = &(pDevice->apTD0Rings[i]);
1558 pDesc->pTDInfo = alloc_td_info();
1559 ASSERT(pDesc->pTDInfo);
1560 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1561 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1562 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1563 }
1564 pDesc->next =&(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1565 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1566 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1567 }
1568
1569 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1570 pDevice->apTailTD[0] = pDevice->apCurrTD[0] =&(pDevice->apTD0Rings[0]);
1571
1572}
1573
1574static void device_init_td1_ring(PSDevice pDevice) {
1575 int i;
1576 dma_addr_t curr;
1577 PSTxDesc pDesc;
1578
1579 /* Init the TD ring entries */
1580 curr=pDevice->td1_pool_dma;
1581 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr+=sizeof(STxDesc)) {
1582 pDesc=&(pDevice->apTD1Rings[i]);
1583 pDesc->pTDInfo = alloc_td_info();
1584 ASSERT(pDesc->pTDInfo);
1585 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1586 pDesc->pTDInfo->buf=pDevice->tx1_bufs+(i)*PKT_BUF_SZ;
1587 pDesc->pTDInfo->buf_dma=pDevice->tx_bufs_dma1+(i)*PKT_BUF_SZ;
1588 }
1589 pDesc->next=&(pDevice->apTD1Rings[(i+1) % pDevice->sOpts.nTxDescs[1]]);
1590 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1591 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1592 }
1593
1594 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1595 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1596}
1597
1598
1599
1600static void device_free_td0_ring(PSDevice pDevice) {
1601 int i;
1602 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1603 PSTxDesc pDesc=&(pDevice->apTD0Rings[i]);
1604 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1605
1606 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1607 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,
1608 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1609
1610 if (pTDInfo->skb)
1611 dev_kfree_skb(pTDInfo->skb);
1612
1613 kfree((PVOID)pDesc->pTDInfo);
1614 }
1615}
1616
1617static void device_free_td1_ring(PSDevice pDevice) {
1618 int i;
1619
1620 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1621 PSTxDesc pDesc=&(pDevice->apTD1Rings[i]);
1622 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1623
1624 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1625 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1626 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1627
1628 if (pTDInfo->skb)
1629 dev_kfree_skb(pTDInfo->skb);
1630
1631 kfree((PVOID)pDesc->pTDInfo);
1632 }
1633
1634}
1635
1636
1637
1638/*-----------------------------------------------------------------*/
1639
1640static int device_rx_srv(PSDevice pDevice, UINT uIdx) {
1641 PSRxDesc pRD;
1642 int works = 0;
1643
1644
1645 for (pRD = pDevice->pCurrRD[uIdx];
1646 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1647 pRD = pRD->next) {
1648// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->pCurrRD = %x, works = %d\n", pRD, works);
1649 if (works++>15)
1650 break;
1651 if (device_receive_frame(pDevice, pRD)) {
1652 if (!device_alloc_rx_buf(pDevice,pRD)) {
1653 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR
1654 "%s: can not allocate rx buf\n", pDevice->dev->name);
1655 break;
1656 }
1657 }
1658 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
Forest Bond5449c682009-04-25 10:30:44 -04001659 pDevice->dev->last_rx = jiffies;
Forest Bond5449c682009-04-25 10:30:44 -04001660 }
1661
1662 pDevice->pCurrRD[uIdx]=pRD;
1663
1664 return works;
1665}
1666
1667
1668static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1669
1670 PDEVICE_RD_INFO pRDInfo=pRD->pRDInfo;
1671
Forest Bond5449c682009-04-25 10:30:44 -04001672
1673 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1674#ifdef PLICE_DEBUG
1675 //printk("device_alloc_rx_buf:skb is %x\n",pRDInfo->skb);
1676#endif
1677 if (pRDInfo->skb==NULL)
1678 return FALSE;
1679 ASSERT(pRDInfo->skb);
1680 pRDInfo->skb->dev = pDevice->dev;
1681 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, pRDInfo->skb->tail, pDevice->rx_buf_sz,
1682 PCI_DMA_FROMDEVICE);
Forest Bond5449c682009-04-25 10:30:44 -04001683 *((PU32) &(pRD->m_rd0RD0)) = 0;
1684
1685 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1686 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1687 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1688 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1689
1690 return TRUE;
1691}
1692
1693
1694
1695BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1696
Forest Bond5449c682009-04-25 10:30:44 -04001697 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1698 if (pDeF->skb == NULL)
1699 return FALSE;
1700 ASSERT(pDeF->skb);
1701 pDeF->skb->dev = pDevice->dev;
Forest Bond5449c682009-04-25 10:30:44 -04001702
1703 return TRUE;
1704}
1705
1706
1707
1708static int device_tx_srv(PSDevice pDevice, UINT uIdx) {
1709 PSTxDesc pTD;
1710 BOOL bFull=FALSE;
1711 int works = 0;
1712 BYTE byTsr0;
1713 BYTE byTsr1;
1714 UINT uFrameSize, uFIFOHeaderSize;
1715 PSTxBufHead pTxBufHead;
1716 struct net_device_stats* pStats = &pDevice->stats;
1717 struct sk_buff* skb;
1718 UINT uNodeIndex;
1719 PSMgmtObject pMgmt = pDevice->pMgmt;
Forest Bond5449c682009-04-25 10:30:44 -04001720
1721
1722 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] >0; pTD = pTD->next) {
1723
1724 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1725 break;
1726 if (works++>15)
1727 break;
1728
1729 byTsr0 = pTD->m_td0TD0.byTSR0;
1730 byTsr1 = pTD->m_td0TD0.byTSR1;
1731
1732 //Only the status of first TD in the chain is correct
1733 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1734
1735 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1736 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1737 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1738 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
Forest Bond5449c682009-04-25 10:30:44 -04001739 // Update the statistics based on the Transmit status
1740 // now, we DO'NT check TSR0_CDH
1741
1742 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1743 byTsr0, byTsr1,
1744 (PBYTE)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1745 uFrameSize, uIdx);
1746
1747
1748 BSSvUpdateNodeTxCounter(pDevice,
1749 byTsr0, byTsr1,
1750 (PBYTE)(pTD->pTDInfo->buf),
1751 uFIFOHeaderSize
1752 );
1753
1754 if (BITbIsBitOff(byTsr1, TSR1_TERR)) {
1755 if (byTsr0 != 0) {
1756 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1757 (INT)uIdx, byTsr1, byTsr0);
1758 }
1759 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
1760 pDevice->s802_11Counter.TransmittedFragmentCount ++;
1761 }
1762 pStats->tx_packets++;
Forest Bond5449c682009-04-25 10:30:44 -04001763 pStats->tx_bytes += pTD->pTDInfo->skb->len;
Forest Bond5449c682009-04-25 10:30:44 -04001764 }
1765 else {
1766 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1767 (INT)uIdx, byTsr1, byTsr0);
1768 pStats->tx_errors++;
1769 pStats->tx_dropped++;
1770 }
1771 }
1772
1773 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1774 if (pDevice->bEnableHostapd) {
1775 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
Forest Bond5449c682009-04-25 10:30:44 -04001776 skb = pTD->pTDInfo->skb;
1777 skb->dev = pDevice->apdev;
Forest Bond7bb8dc22009-06-01 20:00:35 -04001778 skb->mac_header = skb->data;
Forest Bond5449c682009-04-25 10:30:44 -04001779 skb->pkt_type = PACKET_OTHERHOST;
1780 //skb->protocol = htons(ETH_P_802_2);
1781 memset(skb->cb, 0, sizeof(skb->cb));
1782 netif_rx(skb);
Forest Bond5449c682009-04-25 10:30:44 -04001783 }
1784 }
1785
1786 if (BITbIsBitOn(byTsr1, TSR1_TERR)) {
1787 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1788 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1789 (INT)uIdx, byTsr1, byTsr0);
1790 }
1791
1792// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1793// (INT)uIdx, byTsr1, byTsr0);
1794
1795 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1796 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1797 WORD wAID;
1798 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1799
1800 skb = pTD->pTDInfo->skb;
1801 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
1802 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1803 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1804 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1805 // set tx map
1806 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1807 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1808 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1809 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1810 ,(INT)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1811 pStats->tx_errors--;
1812 pStats->tx_dropped--;
1813 }
1814 }
1815 }
1816 }
1817 device_free_tx_buf(pDevice,pTD);
1818 pDevice->iTDUsed[uIdx]--;
1819 }
1820 }
1821
1822
1823 if (uIdx == TYPE_AC0DMA) {
1824 // RESERV_AC0DMA reserved for relay
1825
1826 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1827 bFull = TRUE;
1828 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1829 }
1830 if (netif_queue_stopped(pDevice->dev) && (bFull==FALSE)){
1831 netif_wake_queue(pDevice->dev);
1832 }
1833 }
1834
1835
1836 pDevice->apTailTD[uIdx] = pTD;
1837
1838 return works;
1839}
1840
1841
1842static void device_error(PSDevice pDevice, WORD status) {
1843
1844 if (status & ISR_FETALERR) {
1845 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR
1846 "%s: Hardware fatal error.\n",
1847 pDevice->dev->name);
1848 netif_stop_queue(pDevice->dev);
1849 del_timer(&pDevice->sTimerCommand);
1850 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1851 pDevice->bCmdRunning = FALSE;
1852 MACbShutdown(pDevice->PortOffset);
1853 return;
1854 }
1855
1856}
1857
1858static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1859 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1860 struct sk_buff* skb=pTDInfo->skb;
1861
1862 // pre-allocated buf_dma can't be unmapped.
1863 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1864 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,skb->len,
1865 PCI_DMA_TODEVICE);
1866 }
1867
1868 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1869 dev_kfree_skb_irq(skb);
1870
1871 pTDInfo->skb_dma = 0;
1872 pTDInfo->skb = 0;
1873 pTDInfo->byFlags = 0;
1874}
1875
1876
1877
1878//PLICE_DEBUG ->
1879VOID InitRxManagementQueue(PSDevice pDevice)
1880{
1881 pDevice->rxManeQueue.packet_num = 0;
1882 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
1883}
1884//PLICE_DEBUG<-
1885
1886
1887
1888
1889
1890//PLICE_DEBUG ->
1891INT MlmeThread(
1892 void * Context)
1893{
1894 PSDevice pDevice = (PSDevice) Context;
1895 PSRxMgmtPacket pRxMgmtPacket;
1896 // int i ;
1897 //complete(&pDevice->notify);
1898//printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
1899
1900 //printk("Enter MlmeThread,packet _num is %d\n",pDevice->rxManeQueue.packet_num);
1901 //i = 0;
1902#if 1
1903 while (1)
1904 {
1905
1906 //printk("DDDD\n");
1907 //down(&pDevice->mlme_semaphore);
1908 // pRxMgmtPacket = DeQueue(pDevice);
1909#if 1
1910 spin_lock_irq(&pDevice->lock);
1911 while(pDevice->rxManeQueue.packet_num != 0)
1912 {
1913 pRxMgmtPacket = DeQueue(pDevice);
1914 //pDevice;
1915 //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
1916 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
1917 //printk("packet_num is %d\n",pDevice->rxManeQueue.packet_num);
1918
1919 }
1920 spin_unlock_irq(&pDevice->lock);
1921 if (mlme_kill == 0)
1922 break;
1923 //udelay(200);
1924#endif
1925 //printk("Before schedule thread jiffies is %x\n",jiffies);
1926 schedule();
1927 //printk("after schedule thread jiffies is %x\n",jiffies);
1928 if (mlme_kill == 0)
1929 break;
1930 //printk("i is %d\n",i);
1931 }
1932
1933#endif
1934 return 0;
1935
1936}
1937
1938
Forest Bond5449c682009-04-25 10:30:44 -04001939
1940static int device_open(struct net_device *dev) {
Forest Bondc9d03522009-06-01 20:00:14 -04001941 PSDevice pDevice=(PSDevice) netdev_priv(dev);
Forest Bond5449c682009-04-25 10:30:44 -04001942 int i;
Forest Bond5449c682009-04-25 10:30:44 -04001943 pDevice->rx_buf_sz = PKT_BUF_SZ;
1944 if (!device_init_rings(pDevice)) {
1945 return -ENOMEM;
1946 }
1947//2008-5-13 <add> by chester
Forest Bond5449c682009-04-25 10:30:44 -04001948 i=request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
Forest Bond5449c682009-04-25 10:30:44 -04001949 if (i)
1950 return i;
Forest Bond5449c682009-04-25 10:30:44 -04001951 //printk("DEBUG1\n");
1952#ifdef WPA_SM_Transtatus
1953 extern SWPAResult wpa_Result;
1954 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
1955 wpa_Result.proto = 0;
1956 wpa_Result.key_mgmt = 0;
1957 wpa_Result.eap_type = 0;
1958 wpa_Result.authenticated = FALSE;
1959 pDevice->fWPA_Authened = FALSE;
1960#endif
1961DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1962device_init_rd0_ring(pDevice);
1963 device_init_rd1_ring(pDevice);
1964 device_init_defrag_cb(pDevice);
1965 device_init_td0_ring(pDevice);
1966 device_init_td1_ring(pDevice);
1967// VNTWIFIvSet11h(pDevice->pMgmt, pDevice->b11hEnable);
1968
1969
1970 if (pDevice->bDiversityRegCtlON) {
1971 device_init_diversity_timer(pDevice);
1972 }
1973 vMgrObjectInit(pDevice);
1974 vMgrTimerInit(pDevice);
1975
1976//PLICE_DEBUG->
1977#ifdef TASK_LET
1978 tasklet_init (&pDevice->RxMngWorkItem,(void *)MngWorkItem,(unsigned long )pDevice);
1979#endif
1980#ifdef THREAD
1981 InitRxManagementQueue(pDevice);
1982 mlme_kill = 0;
1983 mlme_task = kthread_run(MlmeThread,(void *) pDevice, "MLME");
1984 if (IS_ERR(mlme_task)) {
1985 printk("thread create fail\n");
1986 return -1;
1987 }
1988
1989 mlme_kill = 1;
1990#endif
1991
1992
1993
1994#if 0
1995 pDevice->MLMEThr_pid = kernel_thread(MlmeThread, pDevice, CLONE_VM);
1996 if (pDevice->MLMEThr_pid <0 )
1997 {
1998 printk("unable start thread MlmeThread\n");
1999 return -1;
2000 }
2001#endif
2002
2003 //printk("thread id is %d\n",pDevice->MLMEThr_pid);
2004 //printk("Create thread time is %x\n",jiffies);
2005 //wait_for_completion(&pDevice->notify);
2006
2007
2008
2009
2010 // if (( SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL)&0x06)==0x04)
2011 // return -ENOMEM;
2012DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
2013 device_init_registers(pDevice, DEVICE_INIT_COLD);
2014 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
2015 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
Forest Bond5449c682009-04-25 10:30:44 -04002016 device_set_multi(pDevice->dev);
Forest Bond5449c682009-04-25 10:30:44 -04002017
2018 // Init for Key Management
2019 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2020 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
2021
2022 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2023 /*
2024 pDevice->bwextstep0 = FALSE;
2025 pDevice->bwextstep1 = FALSE;
2026 pDevice->bwextstep2 = FALSE;
2027 pDevice->bwextstep3 = FALSE;
2028 */
2029 pDevice->bwextcount=0;
2030 pDevice->bWPASuppWextEnabled = FALSE;
2031#endif
2032 pDevice->byReAssocCount = 0;
2033 pDevice->bWPADEVUp = FALSE;
2034 // Patch: if WEP key already set by iwconfig but device not yet open
2035 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
2036 KeybSetDefaultKey(&(pDevice->sKey),
2037 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
2038 pDevice->uKeyLength,
2039 NULL,
2040 pDevice->abyKey,
2041 KEY_CTL_WEP,
2042 pDevice->PortOffset,
2043 pDevice->byLocalID
2044 );
2045 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
2046 }
2047
2048//printk("DEBUG2\n");
2049
2050
2051DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
2052 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2053
2054 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2055 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
2056 }
2057 else {
2058 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
2059 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
2060 }
2061 pDevice->flags |=DEVICE_FLAGS_OPENED;
2062
Forest Bond5449c682009-04-25 10:30:44 -04002063 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
2064 return 0;
2065}
2066
2067
Forest Bond5449c682009-04-25 10:30:44 -04002068static int device_close(struct net_device *dev) {
Forest Bondc9d03522009-06-01 20:00:14 -04002069 PSDevice pDevice=(PSDevice) netdev_priv(dev);
Forest Bond5449c682009-04-25 10:30:44 -04002070 PSMgmtObject pMgmt = pDevice->pMgmt;
2071 //PLICE_DEBUG->
2072#ifdef THREAD
2073 mlme_kill = 0;
2074#endif
2075//PLICE_DEBUG<-
2076//2007-1121-02<Add>by EinsnLiu
2077 if (pDevice->bLinkPass) {
2078 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2079 mdelay(30);
2080 }
2081#ifdef TxInSleep
2082 del_timer(&pDevice->sTimerTxData);
2083#endif
2084 del_timer(&pDevice->sTimerCommand);
2085 del_timer(&pMgmt->sTimerSecondCallback);
2086 if (pDevice->bDiversityRegCtlON) {
2087 del_timer(&pDevice->TimerSQ3Tmax1);
2088 del_timer(&pDevice->TimerSQ3Tmax2);
2089 del_timer(&pDevice->TimerSQ3Tmax3);
2090 }
2091
2092#ifdef TASK_LET
2093 tasklet_kill(&pDevice->RxMngWorkItem);
2094#endif
2095 netif_stop_queue(dev);
2096 pDevice->bCmdRunning = FALSE;
2097 MACbShutdown(pDevice->PortOffset);
2098 MACbSoftwareReset(pDevice->PortOffset);
2099 CARDbRadioPowerOff(pDevice);
2100
2101 pDevice->bLinkPass = FALSE;
2102 memset(pMgmt->abyCurrBSSID, 0, 6);
2103 pMgmt->eCurrState = WMAC_STATE_IDLE;
2104 device_free_td0_ring(pDevice);
2105 device_free_td1_ring(pDevice);
2106 device_free_rd0_ring(pDevice);
2107 device_free_rd1_ring(pDevice);
2108 device_free_frag_buf(pDevice);
2109 device_free_rings(pDevice);
2110 BSSvClearNodeDBTable(pDevice, 0);
2111 free_irq(dev->irq, dev);
2112 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
2113 //2008-0714-01<Add>by chester
2114device_release_WPADEV(pDevice);
2115//PLICE_DEBUG->
2116 //tasklet_kill(&pDevice->RxMngWorkItem);
2117//PLICE_DEBUG<-
Forest Bond5449c682009-04-25 10:30:44 -04002118 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
2119 return 0;
2120}
2121
Forest Bond5449c682009-04-25 10:30:44 -04002122
2123
2124static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
Forest Bondc9d03522009-06-01 20:00:14 -04002125 PSDevice pDevice=netdev_priv(dev);
Forest Bond5449c682009-04-25 10:30:44 -04002126 PBYTE pbMPDU;
2127 UINT cbMPDULen = 0;
2128
2129
2130 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
2131 spin_lock_irq(&pDevice->lock);
2132
2133 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2134 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
2135 dev_kfree_skb_irq(skb);
2136 spin_unlock_irq(&pDevice->lock);
2137 return 0;
2138 }
2139
2140 if (pDevice->bStopTx0Pkt == TRUE) {
2141 dev_kfree_skb_irq(skb);
2142 spin_unlock_irq(&pDevice->lock);
2143 return 0;
2144 };
2145
Forest Bond5449c682009-04-25 10:30:44 -04002146 cbMPDULen = skb->len;
2147 pbMPDU = skb->data;
Forest Bond5449c682009-04-25 10:30:44 -04002148
2149 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
2150
2151 spin_unlock_irq(&pDevice->lock);
2152
2153 return 0;
2154
2155}
2156
2157
2158
2159BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex) {
2160 PSMgmtObject pMgmt = pDevice->pMgmt;
2161 PSTxDesc pHeadTD, pLastTD;
2162 UINT cbFrameBodySize;
2163 UINT uMACfragNum;
2164 BYTE byPktTyp;
2165 BOOL bNeedEncryption = FALSE;
2166 PSKeyItem pTransmitKey = NULL;
2167 UINT cbHeaderSize;
2168 UINT ii;
2169 SKeyItem STempKey;
2170// BYTE byKeyIndex = 0;
Forest Bond5449c682009-04-25 10:30:44 -04002171
2172
2173 if (pDevice->bStopTx0Pkt == TRUE) {
2174 dev_kfree_skb_irq(skb);
2175 return FALSE;
2176 };
2177
2178 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2179 dev_kfree_skb_irq(skb);
2180 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
2181 return FALSE;
2182 }
2183
2184 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2185 if (pDevice->uAssocCount == 0) {
2186 dev_kfree_skb_irq(skb);
2187 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
2188 return FALSE;
2189 }
2190 }
2191
Forest Bond5449c682009-04-25 10:30:44 -04002192 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
2193
2194 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2195
Forest Bond5449c682009-04-25 10:30:44 -04002196 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2197 cbFrameBodySize = skb->len - U_HEADER_LEN;
Forest Bond5449c682009-04-25 10:30:44 -04002198
2199 // 802.1H
2200 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2201 cbFrameBodySize += 8;
2202 }
2203 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2204
2205 if ( uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
2206 dev_kfree_skb_irq(skb);
2207 return FALSE;
2208 }
2209 byPktTyp = (BYTE)pDevice->byPacketType;
2210
2211
2212 if (pDevice->bFixRate) {
2213 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2214 if (pDevice->uConnectionRate >= RATE_11M) {
2215 pDevice->wCurrentRate = RATE_11M;
2216 } else {
2217 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2218 }
2219 } else {
2220 if (pDevice->uConnectionRate >= RATE_54M)
2221 pDevice->wCurrentRate = RATE_54M;
2222 else
2223 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2224 }
2225 }
2226 else {
2227 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2228 }
2229
2230 //preamble type
2231 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2232 pDevice->byPreambleType = pDevice->byShortPreamble;
2233 }
2234 else {
2235 pDevice->byPreambleType = PREAMBLE_LONG;
2236 }
2237
2238 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2239
2240
2241 if (pDevice->wCurrentRate <= RATE_11M) {
2242 byPktTyp = PK_TYPE_11B;
2243 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2244 byPktTyp = PK_TYPE_11A;
2245 } else {
2246 if (pDevice->bProtectMode == TRUE) {
2247 byPktTyp = PK_TYPE_11GB;
2248 } else {
2249 byPktTyp = PK_TYPE_11GA;
2250 }
2251 }
2252
2253 if (pDevice->bEncryptionEnable == TRUE)
2254 bNeedEncryption = TRUE;
2255
2256 if (pDevice->bEnableHostWEP) {
2257 pTransmitKey = &STempKey;
2258 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2259 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2260 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2261 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2262 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2263 memcpy(pTransmitKey->abyKey,
2264 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2265 pTransmitKey->uKeyLength
2266 );
2267 }
2268 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2269 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
2270 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2271 &uMACfragNum,
2272 &cbHeaderSize
2273 );
2274
2275 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2276 // Disable PS
2277 MACbPSWakeup(pDevice->PortOffset);
2278 }
2279
2280 pDevice->bPWBitOn = FALSE;
2281
2282 pLastTD = pHeadTD;
2283 for (ii = 0; ii < uMACfragNum; ii++) {
2284 // Poll Transmit the adapter
2285 wmb();
2286 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2287 wmb();
2288 if (ii == (uMACfragNum - 1))
2289 pLastTD = pHeadTD;
2290 pHeadTD = pHeadTD->next;
2291 }
2292
2293 // Save the information needed by the tx interrupt handler
2294 // to complete the Send request
2295 pLastTD->pTDInfo->skb = skb;
2296 pLastTD->pTDInfo->byFlags = 0;
2297 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2298
2299 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
2300
2301 MACvTransmit0(pDevice->PortOffset);
2302
2303
2304 return TRUE;
2305}
2306
2307//TYPE_AC0DMA data tx
Forest Bond5449c682009-04-25 10:30:44 -04002308static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
Forest Bondc9d03522009-06-01 20:00:14 -04002309 PSDevice pDevice=netdev_priv(dev);
Forest Bond5449c682009-04-25 10:30:44 -04002310
Forest Bond5449c682009-04-25 10:30:44 -04002311 PSMgmtObject pMgmt = pDevice->pMgmt;
2312 PSTxDesc pHeadTD, pLastTD;
2313 UINT uNodeIndex = 0;
2314 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2315 WORD wAID;
2316 UINT uMACfragNum = 1;
2317 UINT cbFrameBodySize;
2318 BYTE byPktTyp;
2319 UINT cbHeaderSize;
2320 BOOL bNeedEncryption = FALSE;
2321 PSKeyItem pTransmitKey = NULL;
2322 SKeyItem STempKey;
2323 UINT ii;
2324 BOOL bTKIP_UseGTK = FALSE;
2325 BOOL bNeedDeAuth = FALSE;
2326 PBYTE pbyBSSID;
2327 BOOL bNodeExist = FALSE;
2328
2329
2330
2331 spin_lock_irq(&pDevice->lock);
2332 if (pDevice->bLinkPass == FALSE) {
2333 dev_kfree_skb_irq(skb);
2334 spin_unlock_irq(&pDevice->lock);
2335 return 0;
2336 }
2337
2338 if (pDevice->bStopDataPkt) {
2339 dev_kfree_skb_irq(skb);
2340 spin_unlock_irq(&pDevice->lock);
2341 return 0;
2342 }
2343
Forest Bond5449c682009-04-25 10:30:44 -04002344
2345 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2346 if (pDevice->uAssocCount == 0) {
2347 dev_kfree_skb_irq(skb);
2348 spin_unlock_irq(&pDevice->lock);
2349 return 0;
2350 }
Forest Bond5449c682009-04-25 10:30:44 -04002351 if (IS_MULTICAST_ADDRESS((PBYTE)(skb->data))) {
Forest Bond5449c682009-04-25 10:30:44 -04002352 uNodeIndex = 0;
2353 bNodeExist = TRUE;
2354 if (pMgmt->sNodeDBTable[0].bPSEnable) {
Forest Bond5449c682009-04-25 10:30:44 -04002355 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
Forest Bond5449c682009-04-25 10:30:44 -04002356 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2357 // set tx map
2358 pMgmt->abyPSTxMap[0] |= byMask[0];
2359 spin_unlock_irq(&pDevice->lock);
2360 return 0;
2361 }
2362}else {
Forest Bond5449c682009-04-25 10:30:44 -04002363 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
Forest Bond5449c682009-04-25 10:30:44 -04002364 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
Forest Bond5449c682009-04-25 10:30:44 -04002365 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
Forest Bond5449c682009-04-25 10:30:44 -04002366 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2367 // set tx map
2368 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2369 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2370 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2371 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2372 spin_unlock_irq(&pDevice->lock);
2373 return 0;
2374 }
2375
2376 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2377 pDevice->byPreambleType = pDevice->byShortPreamble;
2378
2379 }else {
2380 pDevice->byPreambleType = PREAMBLE_LONG;
2381 }
2382 bNodeExist = TRUE;
2383
2384 }
2385 }
2386
2387 if (bNodeExist == FALSE) {
2388 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2389 dev_kfree_skb_irq(skb);
2390 spin_unlock_irq(&pDevice->lock);
2391 return 0;
2392 }
2393 }
2394
2395 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2396
2397 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2398
2399
Forest Bond5449c682009-04-25 10:30:44 -04002400 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2401 cbFrameBodySize = skb->len - U_HEADER_LEN;
Forest Bond5449c682009-04-25 10:30:44 -04002402 // 802.1H
2403 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2404 cbFrameBodySize += 8;
2405 }
2406
2407
2408 if (pDevice->bEncryptionEnable == TRUE) {
2409 bNeedEncryption = TRUE;
2410 // get Transmit key
2411 do {
2412 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2413 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2414 pbyBSSID = pDevice->abyBSSID;
2415 // get pairwise key
2416 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2417 // get group key
2418 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2419 bTKIP_UseGTK = TRUE;
2420 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2421 break;
2422 }
2423 } else {
2424 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2425 break;
2426 }
2427 }else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2428
2429 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2430 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2431 for (ii = 0; ii< 6; ii++)
2432 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2433 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2434
2435 // get pairwise key
2436 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2437 break;
2438 }
2439 // get group key
2440 pbyBSSID = pDevice->abyBroadcastAddr;
2441 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2442 pTransmitKey = NULL;
2443 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2444 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2445 }
2446 else
2447 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2448 } else {
2449 bTKIP_UseGTK = TRUE;
2450 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2451 }
2452 } while(FALSE);
2453 }
2454
2455 if (pDevice->bEnableHostWEP) {
2456 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2457 if (pDevice->bEncryptionEnable == TRUE) {
2458 pTransmitKey = &STempKey;
2459 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2460 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2461 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2462 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2463 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2464 memcpy(pTransmitKey->abyKey,
2465 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2466 pTransmitKey->uKeyLength
2467 );
2468 }
2469 }
2470
2471 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2472
2473 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2474 DEVICE_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2475 dev_kfree_skb_irq(skb);
2476 spin_unlock_irq(&pDevice->lock);
2477 return 0;
2478 }
2479
2480 if (pTransmitKey != NULL) {
2481 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2482 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2483 uMACfragNum = 1; //WEP256 doesn't support fragment
2484 }
2485 }
2486
2487 byPktTyp = (BYTE)pDevice->byPacketType;
2488
2489 if (pDevice->bFixRate) {
2490#ifdef PLICE_DEBUG
2491 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice->eCurrentPHYType,pDevice->uConnectionRate);
2492#endif
2493
2494 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2495 if (pDevice->uConnectionRate >= RATE_11M) {
2496 pDevice->wCurrentRate = RATE_11M;
2497 } else {
2498 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2499 }
2500 } else {
2501 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2502 (pDevice->uConnectionRate <= RATE_6M)) {
2503 pDevice->wCurrentRate = RATE_6M;
2504 } else {
2505 if (pDevice->uConnectionRate >= RATE_54M)
2506 pDevice->wCurrentRate = RATE_54M;
2507 else
2508 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2509
2510 }
2511 }
2512 pDevice->byACKRate = (BYTE) pDevice->wCurrentRate;
2513 pDevice->byTopCCKBasicRate = RATE_1M;
2514 pDevice->byTopOFDMBasicRate = RATE_6M;
2515 }
2516 else {
2517 //auto rate
2518 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2519 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2520 pDevice->wCurrentRate = RATE_1M;
2521 pDevice->byACKRate = RATE_1M;
2522 pDevice->byTopCCKBasicRate = RATE_1M;
2523 pDevice->byTopOFDMBasicRate = RATE_6M;
2524 } else {
2525 pDevice->wCurrentRate = RATE_6M;
2526 pDevice->byACKRate = RATE_6M;
2527 pDevice->byTopCCKBasicRate = RATE_1M;
2528 pDevice->byTopOFDMBasicRate = RATE_6M;
2529 }
2530 }
2531 else {
2532 VNTWIFIvGetTxRate( pDevice->pMgmt,
2533 pDevice->sTxEthHeader.abyDstAddr,
2534 &(pDevice->wCurrentRate),
2535 &(pDevice->byACKRate),
2536 &(pDevice->byTopCCKBasicRate),
2537 &(pDevice->byTopOFDMBasicRate));
2538
2539#if 0
2540printk("auto rate:Rate : %d,AckRate:%d,TopCCKRate:%d,TopOFDMRate:%d\n",
2541pDevice->wCurrentRate,pDevice->byACKRate,
2542pDevice->byTopCCKBasicRate,pDevice->byTopOFDMBasicRate);
2543
2544#endif
2545
2546#if 0
2547
2548 pDevice->wCurrentRate = 11;
2549 pDevice->byACKRate = 8;
2550 pDevice->byTopCCKBasicRate = 3;
2551 pDevice->byTopOFDMBasicRate = 8;
2552#endif
2553
2554
2555 }
2556 }
2557
2558// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2559
2560 if (pDevice->wCurrentRate <= RATE_11M) {
2561 byPktTyp = PK_TYPE_11B;
2562 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2563 byPktTyp = PK_TYPE_11A;
2564 } else {
2565 if (pDevice->bProtectMode == TRUE) {
2566 byPktTyp = PK_TYPE_11GB;
2567 } else {
2568 byPktTyp = PK_TYPE_11GA;
2569 }
2570 }
2571
2572//#ifdef PLICE_DEBUG
2573// printk("FIX RATE:CurrentRate is %d");
2574//#endif
2575
2576 if (bNeedEncryption == TRUE) {
2577 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2578 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2579 bNeedEncryption = FALSE;
2580 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2581 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2582 if (pTransmitKey == NULL) {
2583 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2584 }
2585 else {
2586 if (bTKIP_UseGTK == TRUE) {
2587 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2588 }
2589 else {
2590 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2591 bNeedEncryption = TRUE;
2592 }
2593 }
2594 }
2595
2596 if (pDevice->byCntMeasure == 2) {
2597 bNeedDeAuth = TRUE;
2598 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2599 }
2600
2601 if (pDevice->bEnableHostWEP) {
2602 if ((uNodeIndex != 0) &&
2603 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2604 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2605 bNeedEncryption = TRUE;
2606 }
2607 }
2608 }
2609 else {
2610 if (pTransmitKey == NULL) {
2611 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2612 dev_kfree_skb_irq(skb);
2613 spin_unlock_irq(&pDevice->lock);
2614 return 0;
2615 }
2616 }
2617 }
2618
2619
Forest Bond5449c682009-04-25 10:30:44 -04002620#ifdef PLICE_DEBUG
2621 //if (skb->len == 98)
2622 //{
2623 // printk("ping:len is %d\n");
2624 //}
2625#endif
2626 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2627 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2628 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2629 &uMACfragNum,
2630 &cbHeaderSize
2631 );
Forest Bond5449c682009-04-25 10:30:44 -04002632
2633 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2634 // Disable PS
2635 MACbPSWakeup(pDevice->PortOffset);
2636 }
2637 pDevice->bPWBitOn = FALSE;
2638
2639 pLastTD = pHeadTD;
2640 for (ii = 0; ii < uMACfragNum; ii++) {
2641 // Poll Transmit the adapter
2642 wmb();
2643 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2644 wmb();
2645 if (ii == uMACfragNum - 1)
2646 pLastTD = pHeadTD;
2647 pHeadTD = pHeadTD->next;
2648 }
2649
2650 // Save the information needed by the tx interrupt handler
2651 // to complete the Send request
Forest Bond5449c682009-04-25 10:30:44 -04002652 pLastTD->pTDInfo->skb = skb;
Forest Bond5449c682009-04-25 10:30:44 -04002653 pLastTD->pTDInfo->byFlags = 0;
2654 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2655#ifdef TxInSleep
2656 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2657 #endif
2658 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
2659 netif_stop_queue(dev);
2660 }
2661
2662 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2663//#ifdef PLICE_DEBUG
2664 if (pDevice->bFixRate)
2665 {
2666 printk("FixRate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2667 }
2668 else
2669 {
2670 //printk("Auto Rate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2671 }
2672//#endif
2673
2674{
2675 BYTE Protocol_Version; //802.1x Authentication
2676 BYTE Packet_Type; //802.1x Authentication
2677 BYTE Descriptor_type;
2678 WORD Key_info;
2679BOOL bTxeapol_key = FALSE;
2680 Protocol_Version = skb->data[U_HEADER_LEN];
2681 Packet_Type = skb->data[U_HEADER_LEN+1];
2682 Descriptor_type = skb->data[U_HEADER_LEN+1+1+2];
2683 Key_info = (skb->data[U_HEADER_LEN+1+1+2+1] << 8)|(skb->data[U_HEADER_LEN+1+1+2+2]);
2684 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2685 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
2686 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame transfer
2687 bTxeapol_key = TRUE;
2688 if((Descriptor_type==254)||(Descriptor_type==2)) { //WPA or RSN
2689 if(!(Key_info & BIT3) && //group-key challenge
2690 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2691 pDevice->fWPA_Authened = TRUE;
2692 if(Descriptor_type==254)
2693 printk("WPA ");
2694 else
2695 printk("WPA2 ");
2696 printk("Authentication completed!!\n");
2697 }
2698 }
2699 }
2700 }
2701}
2702
2703 MACvTransmitAC0(pDevice->PortOffset);
2704// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0:pDevice->apCurrTD= %p\n", pHeadTD);
2705
Forest Bond5449c682009-04-25 10:30:44 -04002706 dev->trans_start = jiffies;
Forest Bond5449c682009-04-25 10:30:44 -04002707
2708 spin_unlock_irq(&pDevice->lock);
2709 return 0;
2710
2711}
2712
Forest Bond5449c682009-04-25 10:30:44 -04002713static irqreturn_t device_intr(int irq, void *dev_instance) {
2714 struct net_device* dev=dev_instance;
Forest Bondc9d03522009-06-01 20:00:14 -04002715 PSDevice pDevice=(PSDevice) netdev_priv(dev);
Forest Bond5449c682009-04-25 10:30:44 -04002716
2717 int max_count=0;
2718 DWORD dwMIBCounter=0;
2719 PSMgmtObject pMgmt = pDevice->pMgmt;
2720 BYTE byOrgPageSel=0;
2721 int handled = 0;
2722 BYTE byData = 0;
2723 int ii= 0;
2724// BYTE byRSSI;
2725
2726
2727 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2728
2729 if (pDevice->dwIsr == 0)
2730 return IRQ_RETVAL(handled);
2731
2732 if (pDevice->dwIsr == 0xffffffff) {
2733 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2734 return IRQ_RETVAL(handled);
2735 }
2736 /*
2737 // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
2738
2739 if ((BITbIsBitOn(pDevice->dwIsr, ISR_RXDMA0)) &&
2740 (pDevice->byLocalID != REV_ID_VT3253_B0) &&
2741 (pDevice->bBSSIDFilter == TRUE)) {
2742 // update RSSI
2743 //BBbReadEmbeded(pDevice->PortOffset, 0x3E, &byRSSI);
2744 //pDevice->uCurrRSSI = byRSSI;
2745 }
2746 */
2747
2748 handled = 1;
2749 MACvIntDisable(pDevice->PortOffset);
2750 spin_lock_irq(&pDevice->lock);
2751
2752 //Make sure current page is 0
2753 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2754 if (byOrgPageSel == 1) {
2755 MACvSelectPage0(pDevice->PortOffset);
2756 }
2757 else
2758 byOrgPageSel = 0;
2759
2760 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2761 // TBD....
2762 // Must do this after doing rx/tx, cause ISR bit is slow
2763 // than RD/TD write back
2764 // update ISR counter
2765 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2766 while (pDevice->dwIsr != 0) {
2767
2768 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2769 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2770
2771 if (pDevice->dwIsr & ISR_FETALERR){
2772 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
2773 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2774 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2775 device_error(pDevice, pDevice->dwIsr);
2776 }
2777
2778 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2779
2780 if (BITbIsBitOn(pDevice->dwIsr, ISR_MEASURESTART)) {
2781 // 802.11h measure start
2782 pDevice->byOrgChannel = pDevice->byCurrentCh;
2783 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2784 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2785 MACvSelectPage1(pDevice->PortOffset);
2786 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2787 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2788 MACvSelectPage0(pDevice->PortOffset);
2789 //xxxx
2790 // WCMDbFlushCommandQueue(pDevice->pMgmt, TRUE);
2791 if (CARDbSetChannel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == TRUE) {
2792 pDevice->bMeasureInProgress = TRUE;
2793 MACvSelectPage1(pDevice->PortOffset);
2794 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2795 MACvSelectPage0(pDevice->PortOffset);
2796 pDevice->byBasicMap = 0;
2797 pDevice->byCCAFraction = 0;
2798 for(ii=0;ii<8;ii++) {
2799 pDevice->dwRPIs[ii] = 0;
2800 }
2801 } else {
2802 // can not measure because set channel fail
2803 // WCMDbResetCommandQueue(pDevice->pMgmt);
2804 // clear measure control
2805 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2806 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2807 MACvSelectPage1(pDevice->PortOffset);
2808 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2809 MACvSelectPage0(pDevice->PortOffset);
2810 }
2811 }
2812 if (BITbIsBitOn(pDevice->dwIsr, ISR_MEASUREEND)) {
2813 // 802.11h measure end
2814 pDevice->bMeasureInProgress = FALSE;
2815 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2816 MACvSelectPage1(pDevice->PortOffset);
2817 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2818 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2819 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2820 pDevice->byBasicMap |= (byData >> 4);
2821 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2822 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2823 // clear measure control
2824 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2825 MACvSelectPage0(pDevice->PortOffset);
2826 CARDbSetChannel(pDevice, pDevice->byOrgChannel);
2827 // WCMDbResetCommandQueue(pDevice->pMgmt);
2828 MACvSelectPage1(pDevice->PortOffset);
2829 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2830 MACvSelectPage0(pDevice->PortOffset);
2831 if (BITbIsBitOn(byData, MSRCTL_FINISH)) {
2832 // measure success
2833 s_vCompleteCurrentMeasure(pDevice, 0);
2834 } else {
2835 // can not measure because not ready before end of measure time
2836 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2837 }
2838 }
2839 if (BITbIsBitOn(pDevice->dwIsr, ISR_QUIETSTART)) {
2840 do {
2841 ;
2842 } while (CARDbStartQuiet(pDevice) == FALSE);
2843 }
2844 }
2845
2846 if (pDevice->dwIsr & ISR_TBTT) {
2847 if (pDevice->bEnableFirstQuiet == TRUE) {
2848 pDevice->byQuietStartCount--;
2849 if (pDevice->byQuietStartCount == 0) {
2850 pDevice->bEnableFirstQuiet = FALSE;
2851 MACvSelectPage1(pDevice->PortOffset);
2852 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2853 MACvSelectPage0(pDevice->PortOffset);
2854 }
2855 }
2856 if ((pDevice->bChannelSwitch == TRUE) &&
2857 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2858 pDevice->byChannelSwitchCount--;
2859 if (pDevice->byChannelSwitchCount == 0) {
2860 pDevice->bChannelSwitch = FALSE;
2861 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2862 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2863 MACvSelectPage1(pDevice->PortOffset);
2864 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2865 MACvSelectPage0(pDevice->PortOffset);
2866 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2867
2868 }
2869 }
2870 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2871 //pDevice->bBeaconSent = FALSE;
2872 } else {
2873 if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == TRUE) && (pDevice->uCurrRSSI != 0)) {
2874 LONG ldBm;
2875
2876 RFvRSSITodBm(pDevice, (BYTE) pDevice->uCurrRSSI, &ldBm);
2877 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
2878 if (ldBm < pDevice->ldBmThreshold[ii]) {
2879 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2880 break;
2881 }
2882 }
2883 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2884 pDevice->uBBVGADiffCount++;
2885 if (pDevice->uBBVGADiffCount == 1) {
2886 // first VGA diff gain
2887 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2888 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2889 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2890 }
2891 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2892 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2893 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2894 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2895 }
2896 } else {
2897 pDevice->uBBVGADiffCount = 1;
2898 }
2899 }
2900 }
2901
2902 pDevice->bBeaconSent = FALSE;
2903 if (pDevice->bEnablePSMode) {
2904 PSbIsNextTBTTWakeUp((HANDLE)pDevice);
2905 };
2906
2907 if ((pDevice->eOPMode == OP_MODE_AP) ||
2908 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2909
2910 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2911 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2912 }
2913
2914 if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
2915 // todo adhoc PS mode
2916 };
2917
2918 }
2919
2920 if (pDevice->dwIsr & ISR_BNTX) {
2921
2922 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2923 pDevice->bIsBeaconBufReadySet = FALSE;
2924 pDevice->cbBeaconBufReadySetCnt = 0;
2925 };
2926
2927 if (pDevice->eOPMode == OP_MODE_AP) {
2928 if(pMgmt->byDTIMCount > 0) {
2929 pMgmt->byDTIMCount --;
2930 pMgmt->sNodeDBTable[0].bRxPSPoll = FALSE;
2931 }
2932 else {
2933 if(pMgmt->byDTIMCount == 0) {
2934 // check if mutltcast tx bufferring
2935 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2936 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE;
2937 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2938 }
2939 }
2940 }
2941 pDevice->bBeaconSent = TRUE;
2942
2943 if (pDevice->bChannelSwitch == TRUE) {
2944 pDevice->byChannelSwitchCount--;
2945 if (pDevice->byChannelSwitchCount == 0) {
2946 pDevice->bChannelSwitch = FALSE;
2947 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2948 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2949 MACvSelectPage1(pDevice->PortOffset);
2950 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2951 MACvSelectPage0(pDevice->PortOffset);
2952 //VNTWIFIbSendBeacon(pDevice->pMgmt);
2953 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2954 }
2955 }
2956
2957 }
2958
2959 if (pDevice->dwIsr & ISR_RXDMA0) {
2960 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2961 }
2962 if (pDevice->dwIsr & ISR_RXDMA1) {
2963 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2964 }
2965 if (pDevice->dwIsr & ISR_TXDMA0){
2966 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2967 }
2968 if (pDevice->dwIsr & ISR_AC0DMA){
2969 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2970 }
2971 if (pDevice->dwIsr & ISR_SOFTTIMER) {
2972
2973 }
2974 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2975 if (pDevice->eOPMode == OP_MODE_AP) {
2976 if (pDevice->bShortSlotTime)
2977 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2978 else
2979 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2980 }
2981 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2982 pDevice->byCntMeasure = 0;
2983 }
2984
2985 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2986
2987 MACvReceive0(pDevice->PortOffset);
2988 MACvReceive1(pDevice->PortOffset);
2989
2990 if (max_count>pDevice->sOpts.int_works)
2991 break;
2992 }
2993
2994 if (byOrgPageSel == 1) {
2995 MACvSelectPage1(pDevice->PortOffset);
2996 }
2997
2998 spin_unlock_irq(&pDevice->lock);
2999 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3000
3001 return IRQ_RETVAL(handled);
3002}
3003
3004
3005static unsigned const ethernet_polynomial = 0x04c11db7U;
3006static inline u32 ether_crc(int length, unsigned char *data)
3007{
3008 int crc = -1;
3009
3010 while(--length >= 0) {
3011 unsigned char current_octet = *data++;
3012 int bit;
3013 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
3014 crc = (crc << 1) ^
3015 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
3016 }
3017 }
3018 return crc;
3019}
3020
3021//2008-8-4 <add> by chester
3022static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source)
3023{
3024 UCHAR buf1[100];
3025 int source_len = strlen(source);
3026
3027 memset(buf1,0,100);
3028 strcat(buf1, string);
3029 strcat(buf1, "=");
3030 source+=strlen(buf1);
3031
3032 memcpy(dest,source,source_len-strlen(buf1));
3033 return TRUE;
3034}
3035
3036int Config_FileOperation(PSDevice pDevice,BOOL fwrite,unsigned char *Parameter) {
3037 UCHAR *config_path=CONFIG_PATH;
3038 UCHAR *buffer=NULL;
3039 UCHAR tmpbuffer[20];
3040 struct file *filp=NULL;
3041 mm_segment_t old_fs = get_fs();
Forest Bond756f94e2009-04-25 10:32:25 -04003042 //int oldfsuid=0,oldfsgid=0;
Forest Bond5449c682009-04-25 10:30:44 -04003043 int result=0;
3044
3045 set_fs (KERNEL_DS);
Forest Bond756f94e2009-04-25 10:32:25 -04003046
3047 /* Can't do this anymore, so we rely on correct filesystem permissions:
3048 //Make sure a caller can read or write power as root
3049 oldfsuid=current->cred->fsuid;
3050 oldfsgid=current->cred->fsgid;
3051 current->cred->fsuid = 0;
3052 current->cred->fsgid = 0;
3053 */
Forest Bond5449c682009-04-25 10:30:44 -04003054
3055 //open file
3056 filp = filp_open(config_path, O_RDWR, 0);
3057 if (IS_ERR(filp)) {
3058 printk("Config_FileOperation:open file fail?\n");
3059 result=-1;
3060 goto error2;
3061 }
3062
3063 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
3064 printk("file %s cann't readable or writable?\n",config_path);
3065 result = -1;
3066 goto error1;
3067 }
3068
3069buffer = (UCHAR *)kmalloc(1024, GFP_KERNEL);
3070if(buffer==NULL) {
3071 printk("alllocate mem for file fail?\n");
3072 result = -1;
3073 goto error1;
3074}
3075
3076if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
3077 printk("read file error?\n");
3078 result = -1;
3079 goto error1;
3080}
3081
3082if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=TRUE) {
3083 printk("get parameter error?\n");
3084 result = -1;
3085 goto error1;
3086}
3087
3088if(memcmp(tmpbuffer,"USA",3)==0) {
3089 result=ZoneType_USA;
3090}
3091else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
3092 result=ZoneType_Japan;
3093}
3094else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
3095 result=ZoneType_Europe;
3096}
3097else {
3098 result = -1;
3099 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
3100}
3101
3102error1:
3103 if(buffer)
3104 kfree(buffer);
3105
3106 if(filp_close(filp,NULL))
3107 printk("Config_FileOperation:close file fail\n");
3108
3109error2:
3110 set_fs (old_fs);
Forest Bond756f94e2009-04-25 10:32:25 -04003111
3112 /*
3113 current->cred->fsuid=oldfsuid;
3114 current->cred->fsgid=oldfsgid;
3115 */
Forest Bond5449c682009-04-25 10:30:44 -04003116
3117 return result;
3118}
3119
3120
Forest Bond5449c682009-04-25 10:30:44 -04003121
3122static void device_set_multi(struct net_device *dev) {
Forest Bondc9d03522009-06-01 20:00:14 -04003123 PSDevice pDevice = (PSDevice) netdev_priv(dev);
Forest Bond5449c682009-04-25 10:30:44 -04003124
3125 PSMgmtObject pMgmt = pDevice->pMgmt;
3126 u32 mc_filter[2];
3127 int i;
3128 struct dev_mc_list *mclist;
3129
3130
3131 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
3132
Forest Bond5449c682009-04-25 10:30:44 -04003133 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
3134 DEVICE_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
Forest Bond5449c682009-04-25 10:30:44 -04003135 /* Unconditionally log net taps. */
3136 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
3137 }
Forest Bond5449c682009-04-25 10:30:44 -04003138 else if ((dev->mc_count > pDevice->multicast_limit)
3139 || (dev->flags & IFF_ALLMULTI)) {
Forest Bond5449c682009-04-25 10:30:44 -04003140 MACvSelectPage1(pDevice->PortOffset);
3141 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
3142 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
3143 MACvSelectPage0(pDevice->PortOffset);
3144 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3145 }
3146 else {
3147 memset(mc_filter, 0, sizeof(mc_filter));
Forest Bond5449c682009-04-25 10:30:44 -04003148 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
3149 i++, mclist = mclist->next) {
Forest Bond5449c682009-04-25 10:30:44 -04003150 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
3151 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
3152 }
3153 MACvSelectPage1(pDevice->PortOffset);
3154 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
3155 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
3156 MACvSelectPage0(pDevice->PortOffset);
3157 pDevice->byRxMode &= ~(RCR_UNICAST);
3158 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3159 }
3160
3161 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3162 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
3163 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3164 pDevice->byRxMode &= ~(RCR_UNICAST);
3165 }
3166
3167 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
3168 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode );
3169}
3170
3171
Forest Bond5449c682009-04-25 10:30:44 -04003172static struct net_device_stats *device_get_stats(struct net_device *dev) {
Forest Bondc9d03522009-06-01 20:00:14 -04003173 PSDevice pDevice=(PSDevice) netdev_priv(dev);
Forest Bond5449c682009-04-25 10:30:44 -04003174
3175 return &pDevice->stats;
3176}
3177
3178
Forest Bond5449c682009-04-25 10:30:44 -04003179
3180static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
Forest Bondc9d03522009-06-01 20:00:14 -04003181 PSDevice pDevice = (PSDevice)netdev_priv(dev);
Forest Bond5449c682009-04-25 10:30:44 -04003182
Forest Bond5449c682009-04-25 10:30:44 -04003183 struct iwreq *wrq = (struct iwreq *) rq;
3184 int rc =0;
Forest Bond5449c682009-04-25 10:30:44 -04003185 PSMgmtObject pMgmt = pDevice->pMgmt;
3186 PSCmdRequest pReq;
3187
3188
3189 if (pMgmt == NULL) {
3190 rc = -EFAULT;
3191 return rc;
3192 }
3193
3194 switch(cmd) {
3195
Forest Bond5449c682009-04-25 10:30:44 -04003196 case SIOCGIWNAME:
3197 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
3198 break;
3199
3200 case SIOCGIWNWID: //0x8b03 support
3201 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3202 rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);
3203 #else
3204 rc = -EOPNOTSUPP;
3205 #endif
3206 break;
3207
3208 // Set frequency/channel
3209 case SIOCSIWFREQ:
3210 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
3211 break;
3212
3213 // Get frequency/channel
3214 case SIOCGIWFREQ:
3215 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
3216 break;
3217
3218 // Set desired network name (ESSID)
3219 case SIOCSIWESSID:
3220
3221 {
3222 char essid[IW_ESSID_MAX_SIZE+1];
3223 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
3224 rc = -E2BIG;
3225 break;
3226 }
3227 if (copy_from_user(essid, wrq->u.essid.pointer,
3228 wrq->u.essid.length)) {
3229 rc = -EFAULT;
3230 break;
3231 }
3232 rc = iwctl_siwessid(dev, NULL,
3233 &(wrq->u.essid), essid);
3234 }
3235 break;
3236
3237
3238 // Get current network name (ESSID)
3239 case SIOCGIWESSID:
3240
3241 {
3242 char essid[IW_ESSID_MAX_SIZE+1];
3243 if (wrq->u.essid.pointer)
3244 rc = iwctl_giwessid(dev, NULL,
3245 &(wrq->u.essid), essid);
3246 if (copy_to_user(wrq->u.essid.pointer,
3247 essid,
3248 wrq->u.essid.length) )
3249 rc = -EFAULT;
3250 }
3251 break;
3252
3253 case SIOCSIWAP:
3254
3255 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3256 break;
3257
3258
3259 // Get current Access Point (BSSID)
3260 case SIOCGIWAP:
3261 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3262 break;
3263
3264
3265 // Set desired station name
3266 case SIOCSIWNICKN:
3267 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
3268 rc = -EOPNOTSUPP;
3269 break;
3270
3271 // Get current station name
3272 case SIOCGIWNICKN:
3273 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
3274 rc = -EOPNOTSUPP;
3275 break;
3276
3277 // Set the desired bit-rate
3278 case SIOCSIWRATE:
3279 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3280 break;
3281
3282 // Get the current bit-rate
3283 case SIOCGIWRATE:
3284
3285 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3286 break;
3287
3288 // Set the desired RTS threshold
3289 case SIOCSIWRTS:
3290
3291 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
3292 break;
3293
3294 // Get the current RTS threshold
3295 case SIOCGIWRTS:
3296
3297 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
3298 break;
3299
3300 // Set the desired fragmentation threshold
3301 case SIOCSIWFRAG:
3302
3303 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
3304 break;
3305
3306 // Get the current fragmentation threshold
3307 case SIOCGIWFRAG:
3308
3309 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
3310 break;
3311
3312 // Set mode of operation
3313 case SIOCSIWMODE:
3314 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
3315 break;
3316
3317 // Get mode of operation
3318 case SIOCGIWMODE:
3319 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
3320 break;
3321
3322 // Set WEP keys and mode
3323 case SIOCSIWENCODE:
3324 {
3325 char abyKey[WLAN_WEP232_KEYLEN];
3326
3327 if (wrq->u.encoding.pointer) {
3328
3329
3330 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
3331 rc = -E2BIG;
3332 break;
3333 }
3334 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
3335 if (copy_from_user(abyKey,
3336 wrq->u.encoding.pointer,
3337 wrq->u.encoding.length)) {
3338 rc = -EFAULT;
3339 break;
3340 }
3341 } else if (wrq->u.encoding.length != 0) {
3342 rc = -EINVAL;
3343 break;
3344 }
3345 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3346 }
3347 break;
3348
3349 // Get the WEP keys and mode
3350 case SIOCGIWENCODE:
3351
3352 if (!capable(CAP_NET_ADMIN)) {
3353 rc = -EPERM;
3354 break;
3355 }
3356 {
3357 char abyKey[WLAN_WEP232_KEYLEN];
3358
3359 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3360 if (rc != 0) break;
3361 if (wrq->u.encoding.pointer) {
3362 if (copy_to_user(wrq->u.encoding.pointer,
3363 abyKey,
3364 wrq->u.encoding.length))
3365 rc = -EFAULT;
3366 }
3367 }
3368 break;
3369
Forest Bond5449c682009-04-25 10:30:44 -04003370 // Get the current Tx-Power
3371 case SIOCGIWTXPOW:
3372 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3373 rc = -EOPNOTSUPP;
3374 break;
3375
3376 case SIOCSIWTXPOW:
3377 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3378 rc = -EOPNOTSUPP;
3379 break;
3380
Forest Bond5449c682009-04-25 10:30:44 -04003381 case SIOCSIWRETRY:
3382
3383 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
3384 break;
3385
3386 case SIOCGIWRETRY:
3387
3388 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
3389 break;
3390
Forest Bond5449c682009-04-25 10:30:44 -04003391 // Get range of parameters
3392 case SIOCGIWRANGE:
3393
3394 {
3395 struct iw_range range;
3396
3397 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
3398 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
3399 rc = -EFAULT;
3400 }
3401
3402 break;
3403
3404 case SIOCGIWPOWER:
3405
3406 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
3407 break;
3408
3409
3410 case SIOCSIWPOWER:
3411
3412 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
3413 break;
3414
3415
3416 case SIOCGIWSENS:
3417
3418 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
3419 break;
3420
3421 case SIOCSIWSENS:
3422 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
3423 rc = -EOPNOTSUPP;
3424 break;
3425
3426 case SIOCGIWAPLIST:
3427 {
3428 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
3429
3430 if (wrq->u.data.pointer) {
3431 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
3432 if (rc == 0) {
3433 if (copy_to_user(wrq->u.data.pointer,
3434 buffer,
3435 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
3436 ))
3437 rc = -EFAULT;
3438 }
3439 }
3440 }
3441 break;
3442
3443
3444#ifdef WIRELESS_SPY
3445 // Set the spy list
3446 case SIOCSIWSPY:
3447
3448 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3449 rc = -EOPNOTSUPP;
3450 break;
3451
3452 // Get the spy list
3453 case SIOCGIWSPY:
3454
3455 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3456 rc = -EOPNOTSUPP;
3457 break;
3458
3459#endif // WIRELESS_SPY
3460
3461 case SIOCGIWPRIV:
3462 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
3463 rc = -EOPNOTSUPP;
3464/*
3465 if(wrq->u.data.pointer) {
3466 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
3467
3468 if(copy_to_user(wrq->u.data.pointer,
3469 (u_char *) iwctl_private_args,
3470 sizeof(iwctl_private_args)))
3471 rc = -EFAULT;
3472 }
3473*/
3474 break;
3475
3476
Forest Bond5449c682009-04-25 10:30:44 -04003477//2008-0409-07, <Add> by Einsn Liu
3478#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3479 case SIOCSIWAUTH:
3480 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
3481 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
3482 break;
3483
3484 case SIOCGIWAUTH:
3485 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
3486 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
3487 break;
3488
3489 case SIOCSIWGENIE:
3490 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
3491 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3492 break;
3493
3494 case SIOCGIWGENIE:
3495 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
3496 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3497 break;
3498
3499 case SIOCSIWENCODEEXT:
3500 {
3501 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
3502 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
3503 if(wrq->u.encoding.pointer){
3504 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
3505 if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
3506 rc = -E2BIG;
3507 break;
3508 }
3509 if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
3510 rc = -EFAULT;
3511 break;
3512 }
3513 }else if(wrq->u.encoding.length != 0){
3514 rc = -EINVAL;
3515 break;
3516 }
3517 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3518 }
3519 break;
3520
3521 case SIOCGIWENCODEEXT:
3522 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3523 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3524 break;
3525
3526 case SIOCSIWMLME:
3527 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3528 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3529 break;
3530
3531#endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3532//End Add -- //2008-0409-07, <Add> by Einsn Liu
3533
Forest Bond5449c682009-04-25 10:30:44 -04003534 case IOCTL_CMD_TEST:
3535
3536 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3537 rc = -EFAULT;
3538 break;
3539 } else {
3540 rc = 0;
3541 }
3542 pReq = (PSCmdRequest)rq;
3543 pReq->wResult = MAGIC_CODE;
3544 break;
3545
3546 case IOCTL_CMD_SET:
3547
3548 #ifdef SndEvt_ToAPI
3549 if((((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_EVT) &&
3550 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3551 #else
3552 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3553 (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
3554 #endif
3555 {
3556 rc = -EFAULT;
3557 break;
3558 } else {
3559 rc = 0;
3560 }
3561
3562 if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
3563 return -EBUSY;
3564 }
3565 rc = private_ioctl(pDevice, rq);
3566 clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
3567 break;
3568
3569 case IOCTL_CMD_HOSTAPD:
3570
3571
Alexander Beregalov4c47b342009-06-20 20:07:50 +04003572 rc = hostap_ioctl(pDevice, &wrq->u.data);
Forest Bond5449c682009-04-25 10:30:44 -04003573 break;
3574
3575 case IOCTL_CMD_WPA:
3576
Alexander Beregalov4c47b342009-06-20 20:07:50 +04003577 rc = wpa_ioctl(pDevice, &wrq->u.data);
Forest Bond5449c682009-04-25 10:30:44 -04003578 break;
3579
3580 case SIOCETHTOOL:
3581 return ethtool_ioctl(dev, (void *) rq->ifr_data);
3582 // All other calls are currently unsupported
3583
3584 default:
3585 rc = -EOPNOTSUPP;
3586 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3587
3588
3589 }
3590
3591 if (pDevice->bCommit) {
3592 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3593 netif_stop_queue(pDevice->dev);
3594 spin_lock_irq(&pDevice->lock);
3595 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
3596 spin_unlock_irq(&pDevice->lock);
3597 }
3598 else {
3599 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3600 spin_lock_irq(&pDevice->lock);
3601 pDevice->bLinkPass = FALSE;
3602 memset(pMgmt->abyCurrBSSID, 0, 6);
3603 pMgmt->eCurrState = WMAC_STATE_IDLE;
3604 netif_stop_queue(pDevice->dev);
3605 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3606 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3607 if(pDevice->bWPASuppWextEnabled !=TRUE)
3608 #endif
3609 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3610 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3611 spin_unlock_irq(&pDevice->lock);
3612 }
3613 pDevice->bCommit = FALSE;
3614 }
3615
3616 return rc;
3617}
3618
3619
3620static int ethtool_ioctl(struct net_device *dev, void *useraddr)
3621{
3622 u32 ethcmd;
3623
3624 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
3625 return -EFAULT;
3626
3627 switch (ethcmd) {
3628 case ETHTOOL_GDRVINFO: {
3629 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3630 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3631 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3632 if (copy_to_user(useraddr, &info, sizeof(info)))
3633 return -EFAULT;
3634 return 0;
3635 }
3636
3637 }
3638
3639 return -EOPNOTSUPP;
3640}
3641
3642/*------------------------------------------------------------------*/
Forest Bond5449c682009-04-25 10:30:44 -04003643
3644MODULE_DEVICE_TABLE(pci, device_id_table);
3645
3646static struct pci_driver device_driver = {
3647 name: DEVICE_NAME,
3648 id_table: device_id_table,
3649 probe: device_found1,
3650 remove: device_remove1,
Forest Bond5449c682009-04-25 10:30:44 -04003651#ifdef CONFIG_PM
3652 suspend: viawget_suspend,
3653 resume: viawget_resume,
3654#endif
Forest Bond5449c682009-04-25 10:30:44 -04003655};
3656
3657static int __init device_init_module(void)
3658{
3659 int ret;
3660
3661
3662// ret=pci_module_init(&device_driver);
3663 //ret = pcie_port_service_register(&device_driver);
Forest Bond5449c682009-04-25 10:30:44 -04003664 ret = pci_register_driver(&device_driver);
Forest Bond5449c682009-04-25 10:30:44 -04003665#ifdef CONFIG_PM
3666 if(ret >= 0)
3667 register_reboot_notifier(&device_notifier);
3668#endif
Forest Bond5449c682009-04-25 10:30:44 -04003669
3670 return ret;
3671}
3672
3673static void __exit device_cleanup_module(void)
3674{
3675
3676
Forest Bond5449c682009-04-25 10:30:44 -04003677#ifdef CONFIG_PM
3678 unregister_reboot_notifier(&device_notifier);
3679#endif
Forest Bond5449c682009-04-25 10:30:44 -04003680 pci_unregister_driver(&device_driver);
3681
3682}
3683
3684module_init(device_init_module);
3685module_exit(device_cleanup_module);
3686
3687
Forest Bond5449c682009-04-25 10:30:44 -04003688#ifdef CONFIG_PM
3689static int
3690device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3691{
3692 struct pci_dev *pdev = NULL;
3693 switch(event) {
3694 case SYS_DOWN:
3695 case SYS_HALT:
3696 case SYS_POWER_OFF:
Forest Bond5449c682009-04-25 10:30:44 -04003697 while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
Forest Bond5449c682009-04-25 10:30:44 -04003698 if(pci_dev_driver(pdev) == &device_driver) {
3699 if (pci_get_drvdata(pdev))
Alan Coxf408ade2009-06-10 17:30:49 +01003700 viawget_suspend(pdev, PMSG_HIBERNATE);
Forest Bond5449c682009-04-25 10:30:44 -04003701 }
3702 }
3703 }
3704 return NOTIFY_DONE;
3705}
3706
3707static int
Alan Coxf408ade2009-06-10 17:30:49 +01003708viawget_suspend(struct pci_dev *pcid, pm_message_t state)
Forest Bond5449c682009-04-25 10:30:44 -04003709{
3710 int power_status; // to silence the compiler
3711
3712 PSDevice pDevice=pci_get_drvdata(pcid);
3713 PSMgmtObject pMgmt = pDevice->pMgmt;
3714
3715 netif_stop_queue(pDevice->dev);
3716 spin_lock_irq(&pDevice->lock);
Forest Bond5449c682009-04-25 10:30:44 -04003717 pci_save_state(pcid);
Forest Bond5449c682009-04-25 10:30:44 -04003718 del_timer(&pDevice->sTimerCommand);
3719 del_timer(&pMgmt->sTimerSecondCallback);
3720 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3721 pDevice->uCmdDequeueIdx = 0;
3722 pDevice->uCmdEnqueueIdx = 0;
3723 pDevice->bCmdRunning = FALSE;
3724 MACbShutdown(pDevice->PortOffset);
3725 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3726 pDevice->bLinkPass = FALSE;
3727 memset(pMgmt->abyCurrBSSID, 0, 6);
3728 pMgmt->eCurrState = WMAC_STATE_IDLE;
3729 pci_disable_device(pcid);
Alan Coxf408ade2009-06-10 17:30:49 +01003730 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
Forest Bond5449c682009-04-25 10:30:44 -04003731 spin_unlock_irq(&pDevice->lock);
3732 return 0;
3733}
3734
3735static int
3736viawget_resume(struct pci_dev *pcid)
3737{
3738 PSDevice pDevice=pci_get_drvdata(pcid);
3739 PSMgmtObject pMgmt = pDevice->pMgmt;
3740 int power_status; // to silence the compiler
3741
3742
3743 power_status = pci_set_power_state(pcid, 0);
3744 power_status = pci_enable_wake(pcid, 0, 0);
Forest Bond5449c682009-04-25 10:30:44 -04003745 pci_restore_state(pcid);
Forest Bond5449c682009-04-25 10:30:44 -04003746 if (netif_running(pDevice->dev)) {
3747 spin_lock_irq(&pDevice->lock);
3748 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3749 device_init_registers(pDevice, DEVICE_INIT_DXPL);
3750 if (pMgmt->sNodeDBTable[0].bActive == TRUE) { // Assoc with BSS
3751 pMgmt->sNodeDBTable[0].bActive = FALSE;
3752 pDevice->bLinkPass = FALSE;
3753 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3754 // In Adhoc, BSS state set back to started.
3755 pMgmt->eCurrState = WMAC_STATE_STARTED;
3756 }
3757 else {
3758 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3759 pMgmt->eCurrState = WMAC_STATE_IDLE;
3760 }
3761 }
3762 init_timer(&pMgmt->sTimerSecondCallback);
3763 init_timer(&pDevice->sTimerCommand);
3764 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3765 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
3766 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3767 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3768 spin_unlock_irq(&pDevice->lock);
3769 }
3770 return 0;
3771}
3772
3773#endif
Forest Bond5449c682009-04-25 10:30:44 -04003774
Forest Bond5449c682009-04-25 10:30:44 -04003775
Forest Bond5449c682009-04-25 10:30:44 -04003776
3777