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