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