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