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