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