1 /*************************************************************************
3 * 4F, No. 2 Technology 5th Rd. *
4 * Science-based Industrial Park *
5 * Hsin-chu, Taiwan, R.O.C. *
7 * (c) Copyright 2002, Ralink Technology, Inc. *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, write to the *
21 * Free Software Foundation, Inc., *
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
24 *************************************************************************
30 Miniport generic portion header file
34 -------- ---------- ----------------------------------------------
35 Paul Lin 08-01-2002 created
38 #include "rt_config.h"
41 // BBP register initialization set
43 ULONG BBPRegTable
[] = {
78 // MAC register initialization sets
80 RTMP_REG_PAIR MACRegTable
[] = {
81 {PSCSR0
, 0x00020002}, // 0xc8
82 {PSCSR1
, 0x00000002}, // 0xcc
83 // {PSCSR2, 0x00023f20}, // 0xd0
84 {PSCSR2
, 0x00020002}, // 0xd0
85 {PSCSR3
, 0x00000002}, // 0xd4
86 {TIMECSR
, 0x00003f21}, // 0xDC, to slower down our 1-us tick
87 {CSR9
, 0x00000780}, // 0x24
88 {CSR11
, 0x07041483}, // 0x2C, lrc=7, src=4, slot=20us, CWmax=2^8, CWmax=2^3
89 {CSR18
, 0x00140000}, // SIFS=10us - TR switch time, PIFS=SIFS+20us
90 {CSR19
, 0x016C0028}, // DIFS=SIFS+2*20us, EIFS=364us
91 {CNT3
, 0x00000000}, // Backoff_CCA_Th, RX_&_TX_CCA_Th
93 {TXCSR1
, 0x07614562}, // 0x64, ACK as 1Mb time
94 {TXCSR8
, 0x8c8d8b8a}, // 0x98, CCK TX BBP register ID
95 //{TXCSR9, 0x86870885}, // 0x94, OFDM TX BBP register ID
97 {ARCSR1
, 0x0000000f}, // 0x9c, Basic rate set bitmap
98 {PLCP1MCSR
, 0x00700400}, // 0x13c, ACK/CTS PLCP at 1 Mbps
99 {PLCP2MCSR
, 0x00380401}, // 0x140, ACK/CTS PLCP at 2 Mbps
100 {PLCP5MCSR
, 0x00150402}, // 0x144, ACK/CTS PLCP at 5.5 Mbps
101 {PLCP11MCSR
,0x000b8403}, // 0x148, ACK/CTS PLCP at 11 Mbps
103 {ARTCSR0
, 0x7038140a}, // 0x14c, ACK/CTS payload consumed time for 1/2/5.5/11 mbps
104 {ARTCSR1
, 0x1d21252d}, // 0x150, alexsu : OFDM ACK/CTS payload consumed time for 18/12/9/6 mbps
105 {ARTCSR2
, 0x1919191d}, // 0x154, alexsu : OFDM ACK/CTS payload consumed time for 54/48/36/24 mbps
107 {RXCSR0
, 0xffffffff}, // 0x80
108 {RXCSR3
, 0xb3aab3af}, // 0x90. RT2530 BBP 51:RSSI, R42:OFDM rate, R47:CCK SIGNAL
109 {PCICSR
, 0x000003b8}, // 0x8c, alexsu : PCI control register
110 {PWRCSR0
, 0x3f3b3100}, // 0xC4
111 {GPIOCSR
, 0x0000ff00}, // 0x120, GPIO default value
112 {TESTCSR
, 0x000000f0}, // 0x138, Test CSR, make sure it's running at normal mode
113 {PWRCSR1
, 0x000001ff}, // 0xd8
114 {MACCSR0
, 0x00213223}, // 0xE0, Enable Tx dribble mode - 2003/10/22:Gary
115 {MACCSR1
, 0x00235518}, // 0xE4, Disable Rx Reset, tx dribble count, 2x30x16 = 960n,
116 {MACCSR2
, 0x00000040}, // 0x0134, 64*33ns = 2us
117 {RALINKCSR
, 0x9a009a11}, // 0xE8
118 {CSR7
, 0xffffffff}, // 0x1C, Clear all pending interrupt source
119 {LEDCSR
, 0x00001E46}, // default both LEDs off
120 {BBPCSR1
, 0x82188200}, // for 2560+2522
121 {TXACKCSR0
, 0x00000020}, // 0x110, TX ACK timeout in usec
122 {SECCSR3
, 0x0000e78f}, // AES, mask off more data bit for MIC calculation
125 #define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(ULONG))
126 #define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(RTMP_REG_PAIR))
129 ========================================================================
132 Allocate all DMA releated resources
135 Adapter Pointer to our adapter
142 ========================================================================
144 NDIS_STATUS
RTMPAllocDMAMemory(
145 IN PRTMP_ADAPTER pAd
)
148 VOID
*ring
; // VA of ring descriptor
149 VOID
*ring_data
; // VA of DMA data buffer
150 dma_addr_t ring_dma
; // PA of ring descriptor
151 dma_addr_t ring_data_dma
; // PA of DMA data buffer
152 PTXD_STRUC pTxD
; // Tx type ring descriptor
153 PRXD_STRUC pRxD
; // Rx type ring descriptor
155 DBGPRINT(RT_DEBUG_INFO
, "--> RTMPAllocDMAMemory\n");
157 // 1. Allocate Tx Ring DMA descriptor and buffer memory
158 // Allocate Ring descriptors DMA block
159 ring
= pci_alloc_consistent(pAd
->pPci_Dev
, (TX_RING_SIZE
* RING_DESCRIPTOR_SIZE
), &ring_dma
);
161 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring descriptor memory.\n");
162 goto err_out_allocate_txring
;
165 // Zero init ring descriptors
166 memset(ring
, 0, (TX_RING_SIZE
* RING_DESCRIPTOR_SIZE
));
168 // Allocate Ring data DMA blocks
169 ring_data
= pci_alloc_consistent(pAd
->pPci_Dev
, (TX_RING_SIZE
* TX_BUFFER_SIZE
), &ring_data_dma
);
171 // If failed, release ring descriptors DMA block & exit
173 pci_free_consistent(pAd
->pPci_Dev
, (TX_RING_SIZE
* RING_DESCRIPTOR_SIZE
), ring
, ring_dma
);
174 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring buffer memory.\n");
175 goto err_out_allocate_txring
;
178 // Start with Tx ring & DMA buffer
179 for (index
= 0; index
< TX_RING_SIZE
; index
++)
181 // Init Tx Ring Size, Va, Pa variables
182 pAd
->TxRing
[index
].size
= RING_DESCRIPTOR_SIZE
;
183 pAd
->TxRing
[index
].va_addr
= ring
;
184 pAd
->TxRing
[index
].pa_addr
= ring_dma
;
185 ring
+= RING_DESCRIPTOR_SIZE
;
186 ring_dma
+= RING_DESCRIPTOR_SIZE
;
188 // Init Tx DMA buffer
189 pAd
->TxRing
[index
].data_size
= TX_BUFFER_SIZE
;
190 pAd
->TxRing
[index
].va_data_addr
= ring_data
;
191 pAd
->TxRing
[index
].pa_data_addr
= ring_data_dma
;
192 ring_data
+= TX_BUFFER_SIZE
;
193 ring_data_dma
+= TX_BUFFER_SIZE
;
195 // Write TxD buffer address & allocated buffer length
196 pTxD
= (PTXD_STRUC
) pAd
->TxRing
[index
].va_addr
;
198 pTxD
->BufferAddressPa
= pAd
->TxRing
[index
].pa_data_addr
;
200 pTxD
->BufferAddressPa
= SWAP32(pAd
->TxRing
[index
].pa_data_addr
);
203 DBGPRINT(RT_DEBUG_INFO
, "TxRing[%d] va = 0x%lu, pa = 0x%x, size = 0x%x\n",
204 index
, (unsigned long)pAd
->TxRing
[index
].va_addr
, (UINT
)pAd
->TxRing
[index
].pa_addr
, pAd
->TxRing
[index
].size
);
205 DBGPRINT(RT_DEBUG_INFO
, "TxRing[%d] va_data = 0x%lu, pa_data = 0x%x, size = 0x%x\n",
206 index
, (unsigned long)pAd
->TxRing
[index
].va_data_addr
, (UINT
)pAd
->TxRing
[index
].pa_data_addr
, pAd
->TxRing
[index
].data_size
);
209 // 2. Allocate Prio Ring DMA descriptor and buffer memory
210 // Allocate Ring descriptors DMA block
211 ring
= pci_alloc_consistent(pAd
->pPci_Dev
, (PRIO_RING_SIZE
* RING_DESCRIPTOR_SIZE
), &ring_dma
);
213 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring descriptor memory.\n");
214 goto err_out_allocate_prioring
;
217 // Zero init ring descriptors
218 memset(ring
, 0, (PRIO_RING_SIZE
* RING_DESCRIPTOR_SIZE
));
220 // Allocate Ring data DMA blocks
221 ring_data
= pci_alloc_consistent(pAd
->pPci_Dev
, (PRIO_RING_SIZE
* PRIO_BUFFER_SIZE
), &ring_data_dma
);
223 // If failed, release ring descriptors DMA block & exit
225 pci_free_consistent(pAd
->pPci_Dev
, (PRIO_RING_SIZE
* RING_DESCRIPTOR_SIZE
), ring
, ring_dma
);
226 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring buffer memory.\n");
227 goto err_out_allocate_prioring
;
230 // Second with Prio ring & DMA buffer
231 for (index
= 0; index
< PRIO_RING_SIZE
; index
++)
233 // Init Prio Ring Size, Va, Pa variables
234 pAd
->PrioRing
[index
].size
= RING_DESCRIPTOR_SIZE
;
235 pAd
->PrioRing
[index
].va_addr
= ring
;
236 pAd
->PrioRing
[index
].pa_addr
= ring_dma
;
237 ring
+= RING_DESCRIPTOR_SIZE
;
238 ring_dma
+= RING_DESCRIPTOR_SIZE
;
240 // Init Prio DMA buffer
241 pAd
->PrioRing
[index
].data_size
= PRIO_BUFFER_SIZE
;
242 pAd
->PrioRing
[index
].va_data_addr
= ring_data
;
243 pAd
->PrioRing
[index
].pa_data_addr
= ring_data_dma
;
244 ring_data
+= PRIO_BUFFER_SIZE
;
245 ring_data_dma
+= PRIO_BUFFER_SIZE
;
247 // Write TxD buffer address & allocated buffer length for priority ring
248 pTxD
= (PTXD_STRUC
) pAd
->PrioRing
[index
].va_addr
;
250 pTxD
->BufferAddressPa
= pAd
->PrioRing
[index
].pa_data_addr
;
252 pTxD
->BufferAddressPa
= SWAP32(pAd
->PrioRing
[index
].pa_data_addr
);
255 DBGPRINT(RT_DEBUG_INFO
, "PrioRing[%d] va = 0x%lu, pa = 0x%x, size = 0x%x\n",
256 index
, (unsigned long)pAd
->PrioRing
[index
].va_addr
, (UINT
)pAd
->PrioRing
[index
].pa_addr
, pAd
->PrioRing
[index
].size
);
257 DBGPRINT(RT_DEBUG_INFO
, "PrioRing[%d] va_data = 0x%lu, pa_data = 0x%x, size = 0x%x\n",
258 index
, (unsigned long)pAd
->PrioRing
[index
].va_data_addr
, (UINT
)pAd
->PrioRing
[index
].pa_data_addr
, pAd
->PrioRing
[index
].data_size
);
261 // 3. Allocate Atim Ring DMA descriptor and buffer memory
262 // Allocate Ring descriptors DMA block
263 ring
= pci_alloc_consistent(pAd
->pPci_Dev
, (ATIM_RING_SIZE
* RING_DESCRIPTOR_SIZE
), &ring_dma
);
265 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring descriptor memory.\n");
266 goto err_out_allocate_atimring
;
269 // Zero init ring descriptors
270 memset(ring
, 0, (ATIM_RING_SIZE
* RING_DESCRIPTOR_SIZE
));
272 // Allocate Ring data DMA blocks
273 ring_data
= pci_alloc_consistent(pAd
->pPci_Dev
, (ATIM_RING_SIZE
* ATIM_BUFFER_SIZE
), &ring_data_dma
);
275 // If failed, release ring descriptors DMA block & exit
277 pci_free_consistent(pAd
->pPci_Dev
, (ATIM_RING_SIZE
* RING_DESCRIPTOR_SIZE
), ring
, ring_dma
);
278 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring buffer memory.\n");
279 goto err_out_allocate_atimring
;
282 // Atim ring & DMA buffer
283 for (index
= 0; index
< ATIM_RING_SIZE
; index
++)
285 // Init Atim Ring Size, Va, Pa variables
286 pAd
->AtimRing
[index
].size
= RING_DESCRIPTOR_SIZE
;
287 pAd
->AtimRing
[index
].va_addr
= ring
;
288 pAd
->AtimRing
[index
].pa_addr
= ring_dma
;
289 ring
+= RING_DESCRIPTOR_SIZE
;
290 ring_dma
+= RING_DESCRIPTOR_SIZE
;
292 // Init Atim DMA buffer
293 pAd
->AtimRing
[index
].data_size
= ATIM_BUFFER_SIZE
;
294 pAd
->AtimRing
[index
].va_data_addr
= ring_data
;
295 pAd
->AtimRing
[index
].pa_data_addr
= ring_data_dma
;
296 ring_data
+= ATIM_BUFFER_SIZE
;
297 ring_data_dma
+= ATIM_BUFFER_SIZE
;
299 // Write TxD buffer address & allocated buffer length
300 pTxD
= (PTXD_STRUC
) pAd
->AtimRing
[index
].va_addr
;
302 pTxD
->BufferAddressPa
= pAd
->AtimRing
[index
].pa_data_addr
;
304 pTxD
->BufferAddressPa
= SWAP32(pAd
->AtimRing
[index
].pa_data_addr
);
307 DBGPRINT(RT_DEBUG_INFO
, "AtimRing[%d] va = 0x%lu, pa = 0x%x, size = 0x%x\n",
308 index
, (unsigned long)pAd
->AtimRing
[index
].va_addr
, (UINT
)pAd
->AtimRing
[index
].pa_addr
, pAd
->AtimRing
[index
].size
);
309 DBGPRINT(RT_DEBUG_INFO
, "AtimRing[%d] va_data = 0x%lu, pa_data = 0x%x, size = 0x%x\n",
310 index
, (unsigned long)pAd
->AtimRing
[index
].va_data_addr
, (UINT
)pAd
->AtimRing
[index
].pa_data_addr
, pAd
->AtimRing
[index
].data_size
);
313 // 4. Allocate Rx Ring DMA descriptor and buffer memory
314 // Allocate Ring descriptors DMA block
315 ring
= pci_alloc_consistent(pAd
->pPci_Dev
, (RX_RING_SIZE
* RING_DESCRIPTOR_SIZE
), &ring_dma
);
317 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring descriptor memory.\n");
318 goto err_out_allocate_rxring
;
321 // Zero init ring descriptors
322 memset(ring
, 0, (RX_RING_SIZE
* RING_DESCRIPTOR_SIZE
));
324 // Allocate Ring data DMA blocks
325 ring_data
= pci_alloc_consistent(pAd
->pPci_Dev
, (RX_RING_SIZE
* RX_BUFFER_SIZE
), &ring_data_dma
);
327 // If failed, release ring descriptors DMA block & exit
329 pci_free_consistent(pAd
->pPci_Dev
, (RX_RING_SIZE
* RING_DESCRIPTOR_SIZE
), ring
, ring_dma
);
330 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring buffer memory.\n");
331 goto err_out_allocate_rxring
;
334 // Rx ring & DMA buffer
335 for (index
= 0; index
< RX_RING_SIZE
; index
++)
337 // Init Rx Ring Size, Va, Pa variables
338 pAd
->RxRing
[index
].size
= RING_DESCRIPTOR_SIZE
;
339 pAd
->RxRing
[index
].va_addr
= ring
;
340 pAd
->RxRing
[index
].pa_addr
= ring_dma
;
341 ring
+= RING_DESCRIPTOR_SIZE
;
342 ring_dma
+= RING_DESCRIPTOR_SIZE
;
344 // Init Rx DMA buffer
345 pAd
->RxRing
[index
].data_size
= RX_BUFFER_SIZE
;
346 pAd
->RxRing
[index
].va_data_addr
= ring_data
;
347 pAd
->RxRing
[index
].pa_data_addr
= ring_data_dma
;
348 ring_data
+= RX_BUFFER_SIZE
;
349 ring_data_dma
+= RX_BUFFER_SIZE
;
351 // Write RxD buffer address & allocated buffer length
352 pRxD
= (PRXD_STRUC
) pAd
->RxRing
[index
].va_addr
;
354 pRxD
->BufferAddressPa
= pAd
->RxRing
[index
].pa_data_addr
;
356 pRxD
->BufferAddressPa
= SWAP32(pAd
->RxRing
[index
].pa_data_addr
);
358 // Rx owner bit assign to NIC immediately
359 pRxD
->Owner
= DESC_OWN_NIC
;
362 RTMPDescriptorEndianChange((PUCHAR
)pRxD
, TYPE_RXD
);
365 DBGPRINT(RT_DEBUG_INFO
, "RxRing[%d] va = 0x%lu, pa = 0x%x, size = 0x%x\n",
366 index
, (unsigned long)pAd
->RxRing
[index
].va_addr
, (UINT
)pAd
->RxRing
[index
].pa_addr
, pAd
->RxRing
[index
].size
);
367 DBGPRINT(RT_DEBUG_INFO
, "RxRing[%d] va_data = 0x%lu, pa_data = 0x%x, size = 0x%x\n",
368 index
, (unsigned long)pAd
->RxRing
[index
].va_data_addr
, (UINT
)pAd
->RxRing
[index
].pa_data_addr
, pAd
->RxRing
[index
].data_size
);
371 // 5. Allocate Beacon Ring DMA descriptor and buffer memory
372 // Init Beacon Ring Size, Va, Pa variables
373 ring
= pci_alloc_consistent(pAd
->pPci_Dev
, RING_DESCRIPTOR_SIZE
, &ring_dma
);
375 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring descriptor memory.\n");
376 goto err_out_allocate_beaconring
;
379 // Zero init ring descriptors
380 memset(ring
, 0, (RING_DESCRIPTOR_SIZE
));
382 // Allocate Ring data DMA blocks
383 ring_data
= pci_alloc_consistent(pAd
->pPci_Dev
, BEACON_BUFFER_SIZE
, &ring_data_dma
);
385 // If failed, release ring descriptors DMA block & exit
387 pci_free_consistent(pAd
->pPci_Dev
, RING_DESCRIPTOR_SIZE
, ring
, ring_dma
);
388 DBGPRINT(RT_DEBUG_ERROR
, "Could not allocate DMA ring buffer memory.\n");
389 goto err_out_allocate_beaconring
;
392 pAd
->BeaconRing
.size
= RING_DESCRIPTOR_SIZE
;
393 pAd
->BeaconRing
.va_addr
= ring
;
394 pAd
->BeaconRing
.pa_addr
= ring_dma
;
396 // Init Beacon DMA buffer
397 pAd
->BeaconRing
.data_size
= BEACON_BUFFER_SIZE
;
398 pAd
->BeaconRing
.va_data_addr
= ring_data
;
399 pAd
->BeaconRing
.pa_data_addr
= ring_data_dma
;
401 // Write RxD buffer address & allocated buffer length
402 pTxD
= (PTXD_STRUC
) pAd
->BeaconRing
.va_addr
;
404 pTxD
->BufferAddressPa
= pAd
->BeaconRing
.pa_data_addr
;
406 pTxD
->BufferAddressPa
= SWAP32(pAd
->BeaconRing
.pa_data_addr
);
409 DBGPRINT(RT_DEBUG_INFO
, "BeaconRing va = 0x%lu, pa = 0x%x, size = 0x%x\n",
410 (unsigned long)pAd
->BeaconRing
.va_addr
, (UINT
)pAd
->BeaconRing
.pa_addr
, pAd
->BeaconRing
.size
);
411 DBGPRINT(RT_DEBUG_INFO
, "BeaconRing va_data = 0x%lu, pa_data = 0x%x, size = 0x%x\n",
412 (unsigned long)pAd
->BeaconRing
.va_data_addr
, (UINT
)pAd
->BeaconRing
.pa_data_addr
, pAd
->BeaconRing
.data_size
);
414 DBGPRINT(RT_DEBUG_INFO
, "<-- RTMPAllocDMAMemory\n");
415 return NDIS_STATUS_SUCCESS
;
418 err_out_allocate_beaconring
:
419 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
420 pci_free_consistent(pAd
->pPci_Dev
, (RX_RING_SIZE
* RX_BUFFER_SIZE
),
421 pAd
->RxRing
[0].va_data_addr
, pAd
->RxRing
[0].pa_data_addr
);
422 // Free ring descriptor second, the start address is the same as TxRing first elment
423 pci_free_consistent(pAd
->pPci_Dev
, (RX_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
424 pAd
->RxRing
[0].va_addr
, pAd
->RxRing
[0].pa_addr
);
425 err_out_allocate_rxring
:
426 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
427 pci_free_consistent(pAd
->pPci_Dev
, (ATIM_RING_SIZE
* ATIM_BUFFER_SIZE
),
428 pAd
->AtimRing
[0].va_data_addr
, pAd
->AtimRing
[0].pa_data_addr
);
429 // Free ring descriptor second, the start address is the same as TxRing first elment
430 pci_free_consistent(pAd
->pPci_Dev
, (ATIM_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
431 pAd
->AtimRing
[0].va_addr
, pAd
->AtimRing
[0].pa_addr
);
432 err_out_allocate_atimring
:
433 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
434 pci_free_consistent(pAd
->pPci_Dev
, (PRIO_RING_SIZE
* PRIO_BUFFER_SIZE
),
435 pAd
->PrioRing
[0].va_data_addr
, pAd
->PrioRing
[0].pa_data_addr
);
436 // Free ring descriptor second, the start address is the same as TxRing first elment
437 pci_free_consistent(pAd
->pPci_Dev
, (PRIO_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
438 pAd
->PrioRing
[0].va_addr
, pAd
->PrioRing
[0].pa_addr
);
439 err_out_allocate_prioring
:
440 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
441 pci_free_consistent(pAd
->pPci_Dev
, (TX_RING_SIZE
* TX_BUFFER_SIZE
),
442 pAd
->TxRing
[0].va_data_addr
, pAd
->TxRing
[0].pa_data_addr
);
443 // Free ring descriptor second, the start address is the same as TxRing first elment
444 pci_free_consistent(pAd
->pPci_Dev
, (TX_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
445 pAd
->TxRing
[0].va_addr
, pAd
->TxRing
[0].pa_addr
);
446 err_out_allocate_txring
:
447 DBGPRINT(RT_DEBUG_ERROR
, "<-- RTMPAllocDMAMemory (memory not allocate successfully!)\n");
453 ========================================================================
459 Adapter Pointer to our adapter
466 ========================================================================
468 VOID
RTMPFreeDMAMemory(
469 IN PRTMP_ADAPTER pAd
)
471 DBGPRINT(RT_DEBUG_INFO
, "--> RTMPFreeDMAMemory\n");
473 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
474 pci_free_consistent(pAd
->pPci_Dev
, (TX_RING_SIZE
* TX_BUFFER_SIZE
),
475 pAd
->TxRing
[0].va_data_addr
, pAd
->TxRing
[0].pa_data_addr
);
476 // Free ring descriptor second, the start address is the same as TxRing first elment
477 pci_free_consistent(pAd
->pPci_Dev
, (TX_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
478 pAd
->TxRing
[0].va_addr
, pAd
->TxRing
[0].pa_addr
);
480 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
481 pci_free_consistent(pAd
->pPci_Dev
, (PRIO_RING_SIZE
* PRIO_BUFFER_SIZE
),
482 pAd
->PrioRing
[0].va_data_addr
, pAd
->PrioRing
[0].pa_data_addr
);
483 // Free ring descriptor second, the start address is the same as TxRing first elment
484 pci_free_consistent(pAd
->pPci_Dev
, (PRIO_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
485 pAd
->PrioRing
[0].va_addr
, pAd
->PrioRing
[0].pa_addr
);
487 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
488 pci_free_consistent(pAd
->pPci_Dev
, (ATIM_RING_SIZE
* ATIM_BUFFER_SIZE
),
489 pAd
->AtimRing
[0].va_data_addr
, pAd
->AtimRing
[0].pa_data_addr
);
490 // Free ring descriptor second, the start address is the same as TxRing first elment
491 pci_free_consistent(pAd
->pPci_Dev
, (ATIM_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
492 pAd
->AtimRing
[0].va_addr
, pAd
->AtimRing
[0].pa_addr
);
494 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
495 pci_free_consistent(pAd
->pPci_Dev
, (RX_RING_SIZE
* RX_BUFFER_SIZE
),
496 pAd
->RxRing
[0].va_data_addr
, pAd
->RxRing
[0].pa_data_addr
);
497 // Free ring descriptor second, the start address is the same as TxRing first elment
498 pci_free_consistent(pAd
->pPci_Dev
, (RX_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
499 pAd
->RxRing
[0].va_addr
, pAd
->RxRing
[0].pa_addr
);
501 // Free data DMA blocks first, the start address is the same as TxRing first DMA data block
502 pci_free_consistent(pAd
->pPci_Dev
, (BEACON_RING_SIZE
* BEACON_BUFFER_SIZE
),
503 pAd
->BeaconRing
.va_data_addr
, pAd
->BeaconRing
.pa_data_addr
);
504 // Free ring descriptor second, the start address is the same as TxRing first elment
505 pci_free_consistent(pAd
->pPci_Dev
, (BEACON_RING_SIZE
* RING_DESCRIPTOR_SIZE
),
506 pAd
->BeaconRing
.va_addr
, pAd
->BeaconRing
.pa_addr
);
511 ========================================================================
514 Initialize transmit data structures
517 Adapter Pointer to our adapter
523 Initialize all transmit releated private buffer, include those define
524 in RTMP_ADAPTER structure and all private data structures.
526 ========================================================================
528 VOID
NICInitTransmit(
529 IN PRTMP_ADAPTER pAdapter
)
531 DBGPRINT(RT_DEBUG_TRACE
, "--> NICInitTransmit\n");
533 // Initialize all Transmit releated queues
534 InitializeQueueHeader(&pAdapter
->TxSwQueue0
);
535 InitializeQueueHeader(&pAdapter
->TxSwQueue1
);
536 InitializeQueueHeader(&pAdapter
->TxSwQueue2
);
537 InitializeQueueHeader(&pAdapter
->TxSwQueue3
);
539 // Init Ring index pointer
540 pAdapter
->CurRxIndex
= 0;
541 pAdapter
->CurDecryptIndex
= 0;
542 pAdapter
->CurTxIndex
= 0;
543 pAdapter
->CurEncryptIndex
= 0;
544 pAdapter
->CurAtimIndex
= 0;
545 pAdapter
->CurPrioIndex
= 0;
546 pAdapter
->NextEncryptDoneIndex
= 0;
547 pAdapter
->NextTxDoneIndex
= 0;
548 pAdapter
->NextAtimDoneIndex
= 0;
549 pAdapter
->NextPrioDoneIndex
= 0;
550 pAdapter
->NextDecryptDoneIndex
= 0;
551 pAdapter
->PushMgmtIndex
= 0;
552 pAdapter
->PopMgmtIndex
= 0;
553 pAdapter
->MgmtQueueSize
= 0;
555 pAdapter
->PrivateInfo
.TxRingFullCnt
= 0;
557 DBGPRINT(RT_DEBUG_TRACE
, "<-- NICInitTransmit\n");
560 // By removing 'inline' directive from the function definitions.
561 // Then Driverloader is compiled and runs smooth after kernel 2.6.9
568 IN PRTMP_ADAPTER pAd
)
570 RTMP_IO_WRITE32(pAd
, CSR8
, 0xFFFF);
571 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_ACTIVE
);
581 IN PRTMP_ADAPTER pAd
)
583 // 0xFF37 : Txdone & Rxdone, 0xFF07: Txdonw, Rxdone, PrioDone, AtimDone,
584 RTMP_IO_WRITE32(pAd
, CSR8
, 0xFE14);
585 RTMP_SET_FLAG(pAd
, fRTMP_ADAPTER_INTERRUPT_ACTIVE
);
589 ========================================================================
592 Read additional information from EEPROM, such as MAC address
595 Adapter Pointer to our adapter
603 ========================================================================
605 NDIS_STATUS
NICReadAdapterInfo(
606 IN PRTMP_ADAPTER pAd
)
608 CSR3_STRUC StaMacReg0
;
609 CSR4_STRUC StaMacReg1
;
610 NDIS_STATUS Status
= NDIS_STATUS_SUCCESS
;
613 // Read MAC address from CSR3 & CSR4, these CSRs reflects real value
614 // stored with EEPROM.
616 RTMP_IO_READ32(pAd
, CSR3
, &StaMacReg0
.word
);
617 RTMP_IO_READ32(pAd
, CSR4
, &StaMacReg1
.word
);
618 // Set Current address
619 pAd
->CurrentAddress
[0] = StaMacReg0
.field
.Byte0
;
620 pAd
->CurrentAddress
[1] = StaMacReg0
.field
.Byte1
;
621 pAd
->CurrentAddress
[2] = StaMacReg0
.field
.Byte2
;
622 pAd
->CurrentAddress
[3] = StaMacReg0
.field
.Byte3
;
623 pAd
->CurrentAddress
[4] = StaMacReg1
.field
.Byte4
;
624 pAd
->CurrentAddress
[5] = StaMacReg1
.field
.Byte5
;
625 pAd
->PermanentAddress
[0] = StaMacReg0
.field
.Byte0
;
626 pAd
->PermanentAddress
[1] = StaMacReg0
.field
.Byte1
;
627 pAd
->PermanentAddress
[2] = StaMacReg0
.field
.Byte2
;
628 pAd
->PermanentAddress
[3] = StaMacReg0
.field
.Byte3
;
629 pAd
->PermanentAddress
[4] = StaMacReg1
.field
.Byte4
;
630 pAd
->PermanentAddress
[5] = StaMacReg1
.field
.Byte5
;
636 ========================================================================
639 Read initial parameters from EEPROM
642 Adapter Pointer to our adapter
649 ========================================================================
651 VOID
NICReadEEPROMParameters(
652 IN PRTMP_ADAPTER pAdapter
)
657 EEPROM_TX_PWR_STRUC Power
;
658 EEPROM_VERSION_STRUC Version
;
659 EEPROM_ANTENNA_STRUC Antenna
;
661 DBGPRINT(RT_DEBUG_TRACE
, "--> NICReadEEPROMParameters\n");
663 // Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8
664 RTMP_IO_READ32(pAdapter
, CSR21
, &data
);
667 pAdapter
->EEPROMAddressNum
= 6;
669 pAdapter
->EEPROMAddressNum
= 8;
671 // if E2PROM version mismatch with driver's expectation, then skip
672 // all subsequent E2RPOM retieval and set a system error bit to notify GUI
673 Version
.word
= RTMP_EEPROM_READ16(pAdapter
, EEPROM_VERSION_OFFSET
);
674 if (Version
.field
.Version
!= VALID_EEPROM_VERSION
)
676 DBGPRINT(RT_DEBUG_ERROR
, "WRONG E2PROM VERSION %d, should be %d\n",Version
.field
.Version
, VALID_EEPROM_VERSION
);
677 pAdapter
->PortCfg
.SystemErrorBitmap
|= 0x00000001;
681 // Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAdapter
682 for(i
= 0; i
< NUM_EEPROM_BBP_PARMS
; i
++)
684 value
= RTMP_EEPROM_READ16(pAdapter
, EEPROM_BBP_BASE_OFFSET
+ i
*2);
686 pAdapter
->EEPROMDefaultValue
[i
] = value
;
690 // We have to parse NIC configuration 0 at here.
691 // If TSSI did not have preloaded value, it should reset the TxAutoAgc to false
692 // Therefore, we have to read TxAutoAgc control beforehand.
693 // Read Tx AGC control bit
694 Antenna
.word
= pAdapter
->EEPROMDefaultValue
[0];
695 if (Antenna
.field
.DynamicTxAgcControl
== 1)
696 pAdapter
->PortCfg
.bAutoTxAgc
= TRUE
;
698 pAdapter
->PortCfg
.bAutoTxAgc
= FALSE
;
700 // Read Tx power value for all 14 channels
701 // Value from 1 - 0x7f. Default value is 24.
702 for (i
= 0; i
< NUM_EEPROM_TX_PARMS
; i
++)
704 Power
.word
= RTMP_EEPROM_READ16(pAdapter
, EEPROM_TX_PWR_OFFSET
+ i
*2);
705 pAdapter
->PortCfg
.ChannelTxPower
[i
* 2] = ((Power
.field
.Byte0
> 32) ? 24 : Power
.field
.Byte0
);
706 pAdapter
->PortCfg
.ChannelTxPower
[i
* 2 + 1] = ((Power
.field
.Byte1
> 32) ? 24 : Power
.field
.Byte1
);
709 // Read Tx TSSI reference value, OK to reuse Power data structure
710 for (i
= 0; i
< NUM_EEPROM_TX_PARMS
; i
++)
712 Power
.word
= RTMP_EEPROM_READ16(pAdapter
, EEPROM_TSSI_REF_OFFSET
+ i
* 2);
713 pAdapter
->PortCfg
.ChannelTssiRef
[i
* 2] = Power
.field
.Byte0
;
714 pAdapter
->PortCfg
.ChannelTssiRef
[i
* 2 + 1] = Power
.field
.Byte1
;
715 // Disable TxAgc if the value is not right
716 if ((pAdapter
->PortCfg
.ChannelTssiRef
[i
* 2] == 0xff) ||
717 (pAdapter
->PortCfg
.ChannelTssiRef
[i
* 2 + 1] == 0xff))
718 pAdapter
->PortCfg
.bAutoTxAgc
= FALSE
;
721 // Tx Tssi delta offset 0x24
722 Power
.word
= RTMP_EEPROM_READ16(pAdapter
, EEPROM_TSSI_DELTA_OFFSET
);
723 pAdapter
->PortCfg
.ChannelTssiDelta
= Power
.field
.Byte0
;
727 //CountryRegion byte offset = 0x35
728 value
= pAdapter
->EEPROMDefaultValue
[2] >> 8;
731 pAdapter
->PortCfg
.CountryRegion
= (UCHAR
) value
;
732 TmpPhy
= pAdapter
->PortCfg
.PhyMode
;
733 pAdapter
->PortCfg
.PhyMode
= 0xff;
734 RTMPSetPhyMode(pAdapter
, TmpPhy
);
736 // Read new Calibrated CV value, reuse the power variable
737 Power
.word
= RTMP_EEPROM_READ16(pAdapter
, EEPROM_CALIBRATE_OFFSET
);
738 if (Power
.field
.Byte0
== 0xff)
740 //pAdapter->PortCfg.R17Dec = 0;
741 pAdapter
->PortCfg
.RssiToDbm
= 0x79;
745 //pAdapter->PortCfg.R17Dec = 0x79 - Power.field.Byte0;
746 pAdapter
->PortCfg
.RssiToDbm
= Power
.field
.Byte0
;
749 DBGPRINT(RT_DEBUG_TRACE
, "<-- NICReadEEPROMParameters, pAdapter->PortCfg.RssiToDbm = %d\n", pAdapter
->PortCfg
.RssiToDbm
);
753 ========================================================================
756 Set default value from EEPROM
759 Adapter Pointer to our adapter
766 ========================================================================
768 VOID
NICInitAsicFromEEPROM(
769 IN PRTMP_ADAPTER pAdapter
)
773 UCHAR TxValue
,RxValue
;
774 EEPROM_ANTENNA_STRUC Antenna
;
775 EEPROM_NIC_CONFIG2_STRUC NicConfig2
;
777 DBGPRINT(RT_DEBUG_TRACE
, "--> NICInitAsicFromEEPROM\n");
779 for(i
= 3; i
< NUM_EEPROM_BBP_PARMS
; i
++)
781 value
= pAdapter
->EEPROMDefaultValue
[i
];
783 if((value
!= 0xFFFF) && (value
!= 0))
785 data
= value
| 0x18000;
786 RTMP_BBP_IO_WRITE32(pAdapter
, data
);
790 Antenna
.word
= pAdapter
->EEPROMDefaultValue
[0];
792 if ((Antenna
.word
== 0xFFFF) || (Antenna
.field
.TxDefaultAntenna
> 2) || (Antenna
.field
.RxDefaultAntenna
> 2))
794 DBGPRINT(RT_DEBUG_TRACE
, "E2PROM error(=0x%04x), hard code as 0x0002\n", Antenna
.word
);
795 Antenna
.word
= 0x0002;
798 pAdapter
->PortCfg
.NumberOfAntenna
= 2; // (UCHAR)Antenna.field.NumOfAntenna;
799 pAdapter
->PortCfg
.CurrentTxAntenna
= (UCHAR
)Antenna
.field
.TxDefaultAntenna
;
800 pAdapter
->PortCfg
.CurrentRxAntenna
= (UCHAR
)Antenna
.field
.RxDefaultAntenna
;
801 pAdapter
->PortCfg
.RfType
= (UCHAR
) Antenna
.field
.RfType
;
803 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter
, BBP_Tx_Configure
, &TxValue
);
804 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter
, BBP_Rx_Configure
, &RxValue
);
805 RTMP_IO_READ32(pAdapter
, BBPCSR1
, &BbpCsr1
);
808 if(Antenna
.field
.TxDefaultAntenna
== 1) // Antenna A
810 TxValue
= (TxValue
& 0xFC) | 0x00;
811 BbpCsr1
= (BbpCsr1
& 0xFFFCFFFC) | 0x00000000;
813 else if(Antenna
.field
.TxDefaultAntenna
== 2) // Antenna B
815 TxValue
= (TxValue
& 0xFC) | 0x02;
816 BbpCsr1
= (BbpCsr1
& 0xFFFCFFFC) | 0x00020002;
818 else // diverity - start from Antenna B
820 TxValue
= (TxValue
& 0xFC) | 0x02;
821 BbpCsr1
= (BbpCsr1
& 0xFFFCFFFC) | 0x00020002;
825 if(Antenna
.field
.RxDefaultAntenna
== 1) // Antenna A
826 RxValue
= (RxValue
& 0xFC) | 0x00;
827 else if(Antenna
.field
.RxDefaultAntenna
== 2) // Antenna B
828 RxValue
= (RxValue
& 0xFC) | 0x02;
829 else // Antenna Diversity
830 RxValue
= (RxValue
& 0xFC) | 0x02;
832 // RT5222 needs special treatment to swap TX I/Q
833 if (pAdapter
->PortCfg
.RfType
== RFIC_5222
)
835 BbpCsr1
|= 0x00040004;
836 TxValue
|= 0x04; // TX I/Q flip
838 // RT2525E need to flip TX I/Q but not RX I/Q
839 else if (pAdapter
->PortCfg
.RfType
== RFIC_2525E
)
841 BbpCsr1
|= 0x00040004;
842 TxValue
|= 0x04; // TX I/Q flip
843 RxValue
&= 0xfb; // RX I/Q no flip
846 // Change to match microsoft definition, 0xff: diversity, 0: A, 1: B
847 pAdapter
->PortCfg
.CurrentTxAntenna
--;
848 pAdapter
->PortCfg
.CurrentRxAntenna
--;
850 RTMP_IO_WRITE32(pAdapter
, BBPCSR1
, BbpCsr1
);
851 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter
, BBP_Tx_Configure
, TxValue
);
852 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter
, BBP_Rx_Configure
, RxValue
);
854 // 2003-12-16 software-based RX antenna diversity
855 // pAdapter->PortCfg.CurrentRxAntenna = 0xff; // Diversity ON
856 AsicSetRxAnt(pAdapter
);
858 if (Antenna
.field
.LedMode
== LED_MODE_TXRX_ACTIVITY
)
859 pAdapter
->PortCfg
.LedMode
= LED_MODE_TXRX_ACTIVITY
;
860 else if (Antenna
.field
.LedMode
== LED_MODE_SINGLE
)
862 pAdapter
->PortCfg
.LedMode
= LED_MODE_SINGLE
;
863 ASIC_LED_ACT_ON(pAdapter
);
865 else if (Antenna
.field
.LedMode
== LED_MODE_ASUS
)
867 pAdapter
->PortCfg
.LedMode
= LED_MODE_ASUS
;
868 RTMP_IO_WRITE32(pAdapter
, LEDCSR
, 0x0002461E);
871 pAdapter
->PortCfg
.LedMode
= LED_MODE_DEFAULT
;
873 // Read Hardware controlled Radio state enable bit
874 if (Antenna
.field
.HardwareRadioControl
== 1)
876 pAdapter
->PortCfg
.bHardwareRadio
= TRUE
;
878 // Read GPIO pin0 as Hardware controlled radio state
879 RTMP_IO_READ32(pAdapter
, GPIOCSR
, &data
);
880 if ((data
& 0x01) == 0)
882 pAdapter
->PortCfg
.bHwRadio
= FALSE
;
883 pAdapter
->PortCfg
.bRadio
= FALSE
;
884 RTMP_IO_WRITE32(pAdapter
, PWRCSR0
, 0x00000000);
885 RTMP_SET_FLAG(pAdapter
, fRTMP_ADAPTER_RADIO_OFF
);
886 if (pAdapter
->PortCfg
.LedMode
== LED_MODE_ASUS
)
888 // Turn bit 17 for Radio OFF
889 RTMP_IO_WRITE32(pAdapter
, LEDCSR
, 0x0000461E);
894 pAdapter
->PortCfg
.bHardwareRadio
= FALSE
;
896 NicConfig2
.word
= pAdapter
->EEPROMDefaultValue
[1];
897 if (NicConfig2
.word
== 0xffff)
898 NicConfig2
.word
= 0; // empty E2PROM, use default
900 // for dynamic BBP R17:RX sensibility tuning
903 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter
, 17, &r17
);
904 pAdapter
->PortCfg
.BbpTuningEnable
= (NicConfig2
.field
.DynamicBbpTuning
==0)? 1:0;
905 pAdapter
->PortCfg
.VgcLowerBound
= r17
;
907 // 2004-3-4 per David's request, R7 starts at upper bound
908 pAdapter
->PortCfg
.BbpTuning
.VgcUpperBound
= BBP_R17_DYNAMIC_UP_BOUND
;
909 r17
= pAdapter
->PortCfg
.BbpTuning
.VgcUpperBound
;
910 pAdapter
->PortCfg
.LastR17Value
= r17
;
911 RTMP_BBP_IO_WRITE32_BY_REG_ID(pAdapter
, 17, r17
);
913 // 2004-2-2 per David's request, lower R17 low-bound for very good quality NIC
914 pAdapter
->PortCfg
.VgcLowerBound
-= 6;
915 DBGPRINT(RT_DEBUG_TRACE
,"R17 tuning enable=%d, R17=0x%02x, range=<0x%02x, 0x%02x>\n",
916 pAdapter
->PortCfg
.BbpTuningEnable
, r17
, pAdapter
->PortCfg
.VgcLowerBound
, pAdapter
->PortCfg
.BbpTuning
.VgcUpperBound
);
919 DBGPRINT(RT_DEBUG_TRACE
, "RF IC=%d, LED mode=%d\n", pAdapter
->PortCfg
.RfType
, pAdapter
->PortCfg
.LedMode
);
921 DBGPRINT(RT_DEBUG_TRACE
, "<-- NICInitAsicFromEEPROM\n");
924 void NICInitializeAdapter(IN PRTMP_ADAPTER pAdapter
)
930 DBGPRINT(RT_DEBUG_TRACE
, "--> NICInitializeAdapter\n");
933 NdisAllocateSpinLock(&pAdapter
->TxRingLock
);
934 NdisAllocateSpinLock(&pAdapter
->PrioRingLock
);
935 NdisAllocateSpinLock(&pAdapter
->AtimRingLock
);
936 NdisAllocateSpinLock(&pAdapter
->RxRingLock
);
937 NdisAllocateSpinLock(&pAdapter
->TxSwQueueLock
);
938 NdisAllocateSpinLock(&pAdapter
->MemLock
);
940 // Write TXCSR2 register
941 TxCSR2
.field
.TxDSize
= RING_DESCRIPTOR_SIZE
;
942 TxCSR2
.field
.NumTxD
= TX_RING_SIZE
;
943 TxCSR2
.field
.NumAtimD
= ATIM_RING_SIZE
;
944 TxCSR2
.field
.NumPrioD
= PRIO_RING_SIZE
;
945 RTMP_IO_WRITE32(pAdapter
, TXCSR2
, TxCSR2
.word
);
947 // Write TXCSR3 register
948 Value
= pAdapter
->TxRing
[0].pa_addr
;
949 RTMP_IO_WRITE32(pAdapter
, TX_RING_BASE_REG
, Value
);
951 // Write TXCSR4 register
952 Value
= pAdapter
->PrioRing
[0].pa_addr
;
953 RTMP_IO_WRITE32(pAdapter
, PRIO_RING_BASE_REG
, Value
);
955 // Write TXCSR5 register
956 Value
= pAdapter
->AtimRing
[0].pa_addr
;
957 RTMP_IO_WRITE32(pAdapter
, ATIM_RING_BASE_REG
, Value
);
959 // Write TXCSR6 register
960 Value
= pAdapter
->BeaconRing
.pa_addr
;
961 RTMP_IO_WRITE32(pAdapter
, BEACON_BASE_REG
, Value
);
963 // Write RXCSR1 register
964 RxCSR1
.field
.RxDSize
= RING_DESCRIPTOR_SIZE
;
965 RxCSR1
.field
.NumRxD
= RX_RING_SIZE
;
966 RTMP_IO_WRITE32(pAdapter
, RXCSR1
, RxCSR1
.word
);
968 // Write RXCSR2 register
969 Value
= pAdapter
->RxRing
[0].pa_addr
;
970 RTMP_IO_WRITE32(pAdapter
, RX_RING_BASE_REG
, Value
);
972 // Write CSR1 for host ready
973 // Move Host reay to end of ASIC initialization
974 // to ensure no Rx will perform before ASIC init
975 // RTMP_IO_WRITE32(pAdapter, CSR1, 0x4);
977 // Initialze ASIC for TX & Rx operation
978 NICInitializeAsic(pAdapter
);
980 DBGPRINT(RT_DEBUG_TRACE
, "<-- NICInitializeAdapter\n");
983 void NICInitializeAsic(IN PRTMP_ADAPTER pAdapter
)
988 DBGPRINT(RT_DEBUG_TRACE
, "--> NICInitializeAsic\n");
990 // Initialize MAC register to default value
991 for (Index
= 0; Index
< NUM_MAC_REG_PARMS
; Index
++)
993 RTMP_IO_WRITE32(pAdapter
, MACRegTable
[Index
].Register
, MACRegTable
[Index
].Value
);
996 // Set Host ready before kicking Rx
997 RTMP_IO_WRITE32(pAdapter
, CSR1
, 0x1); // reset MAC state machine, requested by Kevin 2003-2-11
998 RTMP_IO_WRITE32(pAdapter
, CSR1
, 0x4);
1000 // Read BBP register, make sure BBP is up and running before write new data
1001 while ((Value
== 0xff) || (Value
== 0x00))
1003 RTMP_BBP_IO_READ32_BY_REG_ID(pAdapter
, BBP_Version
, &Value
);
1004 DBGPRINT(RT_DEBUG_TRACE
, "Value = %d\n", Value
);
1007 // Initialize BBP register to default value
1008 for (Index
= 0; Index
< NUM_BBP_REG_PARMS
; Index
++)
1010 RTMP_BBP_IO_WRITE32(pAdapter
, BBPRegTable
[Index
]);
1013 // Initialize RF register to default value
1014 AsicSwitchChannel(pAdapter
, pAdapter
->PortCfg
.Channel
);
1015 AsicLockChannel(pAdapter
, pAdapter
->PortCfg
.Channel
);
1017 // Add radio off control
1018 if (pAdapter
->PortCfg
.bRadio
== FALSE
)
1020 RTMP_IO_WRITE32(pAdapter
, PWRCSR0
, 0x00000000);
1021 RTMP_SET_FLAG(pAdapter
, fRTMP_ADAPTER_RADIO_OFF
);
1025 RTMP_IO_WRITE32(pAdapter
, RXCSR0
, 0x7e);
1026 // Clear old FCS jitter before init ASIC
1027 RTMP_IO_READ32(pAdapter
, CNT0
, &Index
);
1028 // Clear old Rx FIFO error jitter before init ASIC
1029 RTMP_IO_READ32(pAdapter
, CNT4
, &Index
);
1031 DBGPRINT(RT_DEBUG_TRACE
, "<-- NICInitializeAsic\n");
1035 ========================================================================
1037 Routine Description:
1041 Adapter Pointer to our adapter
1047 Reset NIC to initial state AS IS system boot up time.
1049 ========================================================================
1052 IN PRTMP_ADAPTER pAdapter
)
1054 CSR3_STRUC StaMacReg0
;
1055 CSR4_STRUC StaMacReg1
;
1057 DBGPRINT(RT_DEBUG_TRACE
, "--> NICIssueReset\n");
1059 // Abort Tx, prevent ASIC from writing to Host memory
1060 RTMP_IO_WRITE32(pAdapter
, TXCSR0
, 0x08);
1062 // Disable Rx, register value supposed will remain after reset
1063 RTMP_IO_WRITE32(pAdapter
, RXCSR0
, 0x01);
1065 if (pAdapter
->PortCfg
.bLocalAdminMAC
)
1067 // Write Back Permanent MAC address to CSR3 & CSR4
1068 StaMacReg0
.field
.Byte0
= pAdapter
->PermanentAddress
[0];
1069 StaMacReg0
.field
.Byte1
= pAdapter
->PermanentAddress
[1];
1070 StaMacReg0
.field
.Byte2
= pAdapter
->PermanentAddress
[2];
1071 StaMacReg0
.field
.Byte3
= pAdapter
->PermanentAddress
[3];
1072 StaMacReg1
.field
.Byte4
= pAdapter
->PermanentAddress
[4];
1073 StaMacReg1
.field
.Byte5
= pAdapter
->PermanentAddress
[5];
1074 RTMP_IO_WRITE32(pAdapter
, CSR3
, StaMacReg0
.word
);
1075 RTMP_IO_WRITE32(pAdapter
, CSR4
, StaMacReg1
.word
);
1078 // Issue reset and clear from reset state
1079 RTMP_IO_WRITE32(pAdapter
, CSR1
, 0x01);
1080 RTMP_IO_WRITE32(pAdapter
, CSR1
, 0x00);
1082 DBGPRINT(RT_DEBUG_TRACE
, "<-- NICIssueReset\n");
1086 ========================================================================
1088 Routine Description:
1089 Check ASIC registers and find any reason the system might hang
1092 Adapter Pointer to our adapter
1100 ========================================================================
1102 BOOLEAN
NICCheckForHang(
1103 IN PRTMP_ADAPTER pAd
)
1105 // garbage collection
1106 // if ((pAd->RalinkCounters.EncryptCount - pAd->RalinkCounters.TxDoneCount) == TX_RING_SIZE)
1108 // DBGPRINT(RT_DEBUG_WARNING,"\nNICCheckForHang --- Garbage Collection!!!\n\n");
1112 RTMPHandleTxRingTxDoneInterrupt(pAd
);
1113 RTMPHandleEncryptionDoneInterrupt(pAd
);
1120 ========================================================================
1122 Routine Description:
1123 Reset NIC from error
1126 Adapter Pointer to our adapter
1132 Reset NIC from error state
1134 ========================================================================
1136 VOID
NICResetFromError(
1137 IN PRTMP_ADAPTER pAdapter
)
1139 // Reset BBP (according to alex, reset ASIC will force reset BBP
1140 // Therefore, skip the reset BBP
1141 // RTMP_IO_WRITE32(pAdapter, CSR1, 0x2);
1142 // Release BBP reset
1143 // RTMP_IO_WRITE32(pAdapter, CSR1, 0x0);
1145 RTMP_IO_WRITE32(pAdapter
, CSR1
, 0x1);
1146 // Remove ASIC from reset state
1147 RTMP_IO_WRITE32(pAdapter
, CSR1
, 0x0);
1149 // Init send data structures and related parameters
1150 NICInitTransmit(pAdapter
);
1152 NICInitializeAdapter(pAdapter
);
1153 NICInitAsicFromEEPROM(pAdapter
);
1155 // Switch to current channel, since during reset process, the connection should remains on.
1156 AsicSwitchChannel(pAdapter
, pAdapter
->PortCfg
.Channel
);
1157 AsicLockChannel(pAdapter
, pAdapter
->PortCfg
.Channel
);
1160 ========================================================================
1162 Routine Description:
1163 Verify section is valid for Get key parameter.
1166 buffer Pointer to the buffer to start find the key section
1167 ptr pointer to section
1172 ========================================================================
1174 INT
RTMPIsFindSection(
1180 else if (ptr
> buffer
)
1182 while (ptr
> buffer
)
1187 else if( (*ptr
== ' ') || (*ptr
== '\t'))
1198 ========================================================================
1200 Routine Description:
1201 Find key section for Get key parameter.
1204 buffer Pointer to the buffer to start find the key section
1205 section the key of the secion to be find
1210 ========================================================================
1212 PUCHAR
RTMPFindSection(
1219 strcpy(temp_buf
, "["); /* and the opening bracket [ */
1220 strcat(temp_buf
, section
);
1221 strcat(temp_buf
, "]");
1223 if((ptr
= rtstrstr(buffer
, temp_buf
)) != NULL
)
1225 if(RTMPIsFindSection(ptr
, buffer
))
1226 return (ptr
+strlen("\n"));
1234 * strstr - Find the first substring in a %NUL terminated string
1235 * @s1: The string to be searched
1236 * @s2: The string to search for
1238 char * rtstrstr(const char * s1
,const char * s2
)
1248 if (!memcmp(s1
,s2
,l2
))
1255 ========================================================================
1257 Routine Description:
1261 section the key of the secion
1262 key Pointer to key string
1263 dest Pointer to destination
1264 destsize The datasize of the destination
1265 buffer Pointer to the buffer to start find the key
1272 This routine get the value with the matched key (case case-sensitive)
1273 ========================================================================
1275 INT
RTMPGetKeyParameter(
1282 char temp_buf1
[600];
1283 char temp_buf2
[600];
1292 if((offset
= RTMPFindSection(buffer
, section
)) == NULL
)
1295 strcpy(temp_buf1
, "\n");
1296 strcat(temp_buf1
, key
);
1297 strcat(temp_buf1
, "=");
1300 if((start_ptr
=rtstrstr(offset
, temp_buf1
))==NULL
)
1303 start_ptr
+=strlen("\n");
1304 if((too_far_ptr
=rtstrstr(offset
+1, "["))==NULL
)
1305 too_far_ptr
=offset
+strlen(offset
);
1307 if((end_ptr
=rtstrstr(start_ptr
, "\n"))==NULL
)
1308 end_ptr
=start_ptr
+strlen(start_ptr
);
1310 if (too_far_ptr
<start_ptr
)
1313 memcpy(temp_buf2
, start_ptr
, end_ptr
-start_ptr
);
1314 temp_buf2
[end_ptr
-start_ptr
]='\0';
1315 len
= strlen(temp_buf2
);
1316 strcpy(temp_buf1
, temp_buf2
);
1317 if((start_ptr
=rtstrstr(temp_buf1
, "=")) == NULL
)
1320 strcpy(temp_buf2
, start_ptr
+1);
1325 if( (*ptr
== ' ') || (*ptr
== '\t') )
1332 memset(dest
, 0x00, destsize
);
1333 strncpy(dest
, ptr
, len
>= destsize
? destsize
: len
);
1338 ========================================================================
1340 Routine Description:
1341 In kernel mode read parameters from file
1344 src the location of the file.
1345 dest put the parameters to the destination.
1346 Length size to read.
1353 ========================================================================
1356 VOID
RTMPReadParametersFromFile(
1357 IN PRTMP_ADAPTER pAd
)
1361 INT retval
, orgfsuid
, orgfsgid
;
1363 CHAR buffer
[MAX_INI_BUFFER_SIZE
];
1365 UCHAR keyMaterial
[40];
1368 RT_802_11_PREAMBLE Preamble
;
1371 BOOLEAN bIsHex
= TRUE
;
1372 ULONG rate_mapping
[12] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54}; //according to README
1376 // Save uid and gid used for filesystem access.
1377 // Set user and group to 0 (root)
1378 orgfsuid
= current
->fsuid
;
1379 orgfsgid
= current
->fsgid
;
1380 current
->fsuid
=current
->fsgid
= 0;
1386 srcf
= filp_open(src
, O_RDONLY
, 0);
1389 DBGPRINT(RT_DEBUG_TRACE
, "--> Error %ld opening %s\n", -PTR_ERR(srcf
),src
);
1393 /* The object must have a read method */
1394 if (srcf
->f_op
&& srcf
->f_op
->read
)
1396 memset(buffer
, 0x00, MAX_INI_BUFFER_SIZE
);
1397 retval
=srcf
->f_op
->read(srcf
, buffer
, MAX_INI_BUFFER_SIZE
, &srcf
->f_pos
);
1400 DBGPRINT(RT_DEBUG_TRACE
, "--> Read %s error %d\n", src
, -retval
);
1404 // set file parameter to portcfg
1406 if (RTMPGetKeyParameter("Default", "CountryRegion", tmpbuf
, 255, buffer
))
1408 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1409 if ((ulInfo
>= REGION_MIN
) && (ulInfo
<= REGION_MAX
) )
1411 pAd
->PortCfg
.CountryRegion
= (UCHAR
) ulInfo
;
1412 DBGPRINT(RT_DEBUG_TRACE
, "%s::(CountryRegion=%d)\n", __FUNCTION__
, pAd
->PortCfg
.CountryRegion
);
1416 memset(tmpbuf
, 0x00, 255);
1417 if (RTMPGetKeyParameter("Default", "SSID", tmpbuf
, 32, buffer
))
1419 pAd
->PortCfg
.SsidLen
= (UCHAR
) strlen(tmpbuf
);
1420 memcpy(pAd
->PortCfg
.Ssid
, tmpbuf
, pAd
->PortCfg
.SsidLen
);
1422 pAd
->Mlme
.CntlAux
.SsidLen
= pAd
->PortCfg
.SsidLen
;
1423 memcpy(pAd
->Mlme
.CntlAux
.Ssid
, tmpbuf
, pAd
->Mlme
.CntlAux
.SsidLen
);
1425 DBGPRINT(RT_DEBUG_TRACE
, "%s::(SSID=%s Len=%d)\n", __FUNCTION__
, tmpbuf
, pAd
->PortCfg
.SsidLen
);
1428 if (RTMPGetKeyParameter("Default", "NetworkType", tmpbuf
, 255, buffer
))
1430 pAd
->bConfigChanged
= TRUE
;
1431 if (strcmp(tmpbuf
, "Adhoc") == 0)
1432 pAd
->PortCfg
.BssType
= BSS_INDEP
;
1433 else //Default Infrastructure mode
1434 pAd
->PortCfg
.BssType
= BSS_INFRA
;
1435 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
1436 pAd
->PortCfg
.WpaState
= SS_NOTUSE
;
1437 DBGPRINT(RT_DEBUG_TRACE
, "%s::(NetworkType=%d)\n", __FUNCTION__
, pAd
->PortCfg
.BssType
);
1440 if (RTMPGetKeyParameter("Default", "WirelessMode", tmpbuf
, 10, buffer
))
1442 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1443 if ((ulInfo
== PHY_11BG_MIXED
) || (ulInfo
== PHY_11B
) ||
1444 (ulInfo
== PHY_11A
) || (ulInfo
== PHY_11ABG_MIXED
))
1446 RTMPSetPhyMode(pAd
, ulInfo
);
1447 DBGPRINT(RT_DEBUG_TRACE
, "%s::(WirelessMode=%d)\n", __FUNCTION__
, ulInfo
);
1451 if (RTMPGetKeyParameter("Default", "TxRate", tmpbuf
, 10, buffer
))
1453 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1456 RTMPSetDesiredRates(pAd
, -1);
1458 RTMPSetDesiredRates(pAd
, (LONG
) (rate_mapping
[ulInfo
-1] * 1000000));
1460 DBGPRINT(RT_DEBUG_TRACE
, "%s::(TxRate=%d)\n", __FUNCTION__
, ulInfo
);
1464 if (RTMPGetKeyParameter("Default", "Channel", tmpbuf
, 10, buffer
))
1466 Channel
= (UCHAR
) simple_strtol(tmpbuf
, 0, 10);
1467 if (ChannelSanity(pAd
, Channel
) == TRUE
)
1469 pAd
->PortCfg
.Channel
= Channel
;
1470 // If default profile in Registry is an ADHOC network, driver should use the specified channel
1471 // number when starting IBSS the first time, because RaConfig is passive and will not set this
1472 // via OID_802_11_CONFIGURATION upon driver bootup.
1473 pAd
->PortCfg
.IbssConfig
.Channel
= pAd
->PortCfg
.Channel
;
1474 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Channel=%d)\n", __FUNCTION__
, Channel
);
1478 if (RTMPGetKeyParameter("Default", "BGProtection", tmpbuf
, 10, buffer
))
1480 switch (simple_strtol(tmpbuf
, 0, 10))
1483 pAd
->PortCfg
.UseBGProtection
= 1;
1485 case 2: //Always OFF
1486 pAd
->PortCfg
.UseBGProtection
= 2;
1490 pAd
->PortCfg
.UseBGProtection
= 0;
1493 DBGPRINT(RT_DEBUG_TRACE
, "%s::(BGProtection=%d)\n", __FUNCTION__
, pAd
->PortCfg
.UseBGProtection
);
1495 //StaWithEtherBridge
1496 if (RTMPGetKeyParameter("Default", "StaWithEtherBridge", tmpbuf
, 10, buffer
))
1498 switch (simple_strtol(tmpbuf
, 0, 10))
1501 pAd
->PortCfg
.StaWithEtherBridge
.Enable
= FALSE
;
1504 pAd
->PortCfg
.StaWithEtherBridge
.Enable
= TRUE
;
1507 pAd
->PortCfg
.StaWithEtherBridge
.Enable
= FALSE
;
1510 DBGPRINT(RT_DEBUG_TRACE
, "%s::(StaWithEtherBridge=%d)\n", __FUNCTION__
, pAd
->PortCfg
.StaWithEtherBridge
.Enable
);
1513 if (RTMPGetKeyParameter("Default", "TxPreamble", tmpbuf
, 10, buffer
))
1515 Preamble
= simple_strtol(tmpbuf
, 0, 10);
1518 case Rt802_11PreambleShort
:
1519 pAd
->PortCfg
.WindowsTxPreamble
= Preamble
;
1520 MlmeSetTxPreamble(pAd
, Rt802_11PreambleShort
);
1522 case Rt802_11PreambleLong
:
1523 case Rt802_11PreambleAuto
:
1525 // if user wants AUTO, initialize to LONG here, then change according to AP's
1526 // capability upon association.
1527 pAd
->PortCfg
.WindowsTxPreamble
= Preamble
;
1528 MlmeSetTxPreamble(pAd
, Rt802_11PreambleLong
);
1530 DBGPRINT(RT_DEBUG_TRACE
, "%s::(TxPreamble=%d)\n", __FUNCTION__
, Preamble
);
1533 if (RTMPGetKeyParameter("Default", "RTSThreshold", tmpbuf
, 10, buffer
))
1535 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1537 if((ulInfo
> 0) && (ulInfo
<= MAX_RTS_THRESHOLD
))
1538 pAd
->PortCfg
.RtsThreshold
= (USHORT
)ulInfo
;
1540 pAd
->PortCfg
.RtsThreshold
= MAX_RTS_THRESHOLD
;
1542 DBGPRINT(RT_DEBUG_TRACE
, "%s::(RTSThreshold=%d)\n", __FUNCTION__
, pAd
->PortCfg
.RtsThreshold
);
1545 if (RTMPGetKeyParameter("Default", "FragThreshold", tmpbuf
, 10, buffer
))
1547 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1549 if ( (ulInfo
>= MIN_FRAG_THRESHOLD
) && (ulInfo
<= MAX_FRAG_THRESHOLD
))
1550 pAd
->PortCfg
.FragmentThreshold
= (USHORT
)ulInfo
;
1552 pAd
->PortCfg
.FragmentThreshold
= MAX_FRAG_THRESHOLD
;
1554 if (pAd
->PortCfg
.FragmentThreshold
== MAX_FRAG_THRESHOLD
)
1555 pAd
->PortCfg
.bFragmentZeroDisable
= TRUE
;
1557 pAd
->PortCfg
.bFragmentZeroDisable
= FALSE
;
1559 DBGPRINT(RT_DEBUG_TRACE
, "%s::(FragThreshold=%d)\n", __FUNCTION__
, ulInfo
);
1562 if (RTMPGetKeyParameter("Default", "AdhocOfdm", tmpbuf
, 10, buffer
))
1564 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1567 pAd
->PortCfg
.AdhocMode
= 1;
1569 pAd
->PortCfg
.AdhocMode
= 0;
1571 DBGPRINT(RT_DEBUG_TRACE
, "%s::(AdhocOfdm=%d)\n", __FUNCTION__
, pAd
->PortCfg
.AdhocMode
);
1574 if (RTMPGetKeyParameter("Default", "TxBurst", tmpbuf
, 10, buffer
))
1576 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1579 pAd
->PortCfg
.EnableTxBurst
= TRUE
;
1581 pAd
->PortCfg
.EnableTxBurst
= FALSE
;
1583 DBGPRINT(RT_DEBUG_TRACE
, "%s::(TxBurst=%d)\n", __FUNCTION__
, pAd
->PortCfg
.EnableTxBurst
);
1586 if (RTMPGetKeyParameter("Default", "TurboRate", tmpbuf
, 10, buffer
))
1588 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1591 pAd
->PortCfg
.EnableTurboRate
= TRUE
;
1593 pAd
->PortCfg
.EnableTurboRate
= FALSE
;
1595 DBGPRINT(RT_DEBUG_TRACE
, "%s::(TurboRate=%d)\n", __FUNCTION__
, pAd
->PortCfg
.EnableTurboRate
);
1598 if (RTMPGetKeyParameter("Default", "ShortSlot", tmpbuf
, 10, buffer
))
1600 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1603 pAd
->PortCfg
.UseShortSlotTime
= TRUE
;
1605 pAd
->PortCfg
.UseShortSlotTime
= FALSE
;
1607 DBGPRINT(RT_DEBUG_TRACE
, "%s::(ShortSlot=%d)\n", __FUNCTION__
, pAd
->PortCfg
.UseShortSlotTime
);
1610 if (RTMPGetKeyParameter("Default", "PSMode", tmpbuf
, 10, buffer
))
1612 if (pAd
->PortCfg
.BssType
== BSS_INFRA
)
1614 if ((strcmp(tmpbuf
, "MAX_PSP") == 0) || (strcmp(tmpbuf
, "max_psp") == 0))
1616 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1617 // to exclude certain situations.
1618 // MlmeSetPsmBit(pAdapter, PWR_SAVE);
1619 if (pAd
->PortCfg
.WindowsACCAMEnable
== FALSE
)
1620 pAd
->PortCfg
.WindowsPowerMode
= Ndis802_11PowerModeMAX_PSP
;
1621 pAd
->PortCfg
.WindowsBatteryPowerMode
= Ndis802_11PowerModeMAX_PSP
;
1622 pAd
->PortCfg
.RecvDtim
= TRUE
; // FALSE;
1623 pAd
->PortCfg
.DefaultListenCount
= 5;
1625 else if ((strcmp(tmpbuf
, "Fast_PSP") == 0) || (strcmp(tmpbuf
, "fast_psp") == 0)
1626 || (strcmp(tmpbuf
, "FAST_PSP") == 0))
1628 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1629 // to exclude certain situations.
1630 // MlmeSetPsmBit(pAdapter, PWR_SAVE);
1631 pAd
->PortCfg
.RecvDtim
= TRUE
;
1632 if (pAd
->PortCfg
.WindowsACCAMEnable
== FALSE
)
1633 pAd
->PortCfg
.WindowsPowerMode
= Ndis802_11PowerModeFast_PSP
;
1634 pAd
->PortCfg
.WindowsBatteryPowerMode
= Ndis802_11PowerModeFast_PSP
;
1635 pAd
->PortCfg
.DefaultListenCount
= 3;
1638 { //Default Ndis802_11PowerModeCAM
1639 // clear PSM bit immediately
1640 MlmeSetPsmBit(pAd
, PWR_ACTIVE
);
1641 pAd
->PortCfg
.RecvDtim
= TRUE
;
1642 if (pAd
->PortCfg
.WindowsACCAMEnable
== FALSE
)
1643 pAd
->PortCfg
.WindowsPowerMode
= Ndis802_11PowerModeCAM
;
1644 pAd
->PortCfg
.WindowsBatteryPowerMode
= Ndis802_11PowerModeCAM
;
1646 DBGPRINT(RT_DEBUG_TRACE
, "%s::(PSMode=%d)\n", __FUNCTION__
, pAd
->PortCfg
.WindowsPowerMode
);
1650 if (RTMPGetKeyParameter("Default", "AuthMode", tmpbuf
, 10, buffer
))
1652 if ((strcmp(tmpbuf
, "SHARED") == 0) || (strcmp(tmpbuf
, "shared") == 0))
1653 pAd
->PortCfg
.AuthMode
= Ndis802_11AuthModeShared
;
1654 else if ((strcmp(tmpbuf
, "WPAPSK") == 0) || (strcmp(tmpbuf
, "wpapsk") == 0))
1655 pAd
->PortCfg
.AuthMode
= Ndis802_11AuthModeWPAPSK
;
1656 else if ((strcmp(tmpbuf
, "AUTO") == 0) || (strcmp(tmpbuf
, "auto") == 0))
1657 pAd
->PortCfg
.AuthMode
= Ndis802_11AuthModeAutoSwitch
;
1658 else if ((strcmp(tmpbuf
, "WPANONE") == 0) || (strcmp(tmpbuf
, "wpanone") == 0))
1659 pAd
->PortCfg
.AuthMode
= Ndis802_11AuthModeWPANone
;
1661 pAd
->PortCfg
.AuthMode
= Ndis802_11AuthModeOpen
;
1663 pAd
->PortCfg
.PortSecured
= WPA_802_1X_PORT_NOT_SECURED
;
1664 DBGPRINT(RT_DEBUG_TRACE
, "%s::(AuthMode=%d)\n", __FUNCTION__
, pAd
->PortCfg
.AuthMode
);
1667 if (RTMPGetKeyParameter("Default", "EncrypType", tmpbuf
, 10, buffer
))
1669 if ((strcmp(tmpbuf
, "WEP") == 0) || (strcmp(tmpbuf
, "wep") == 0))
1670 pAd
->PortCfg
.WepStatus
= Ndis802_11WEPEnabled
;
1671 else if ((strcmp(tmpbuf
, "TKIP") == 0) || (strcmp(tmpbuf
, "tkip") == 0))
1672 pAd
->PortCfg
.WepStatus
= Ndis802_11Encryption2Enabled
;
1673 else if ((strcmp(tmpbuf
, "AES") == 0) || (strcmp(tmpbuf
, "aes") == 0))
1674 pAd
->PortCfg
.WepStatus
= Ndis802_11Encryption3Enabled
;
1676 pAd
->PortCfg
.WepStatus
= Ndis802_11WEPDisabled
;
1678 DBGPRINT(RT_DEBUG_TRACE
, "%s::(EncrypType=%d)\n", __FUNCTION__
, pAd
->PortCfg
.WepStatus
);
1681 if (RTMPGetKeyParameter("Default", "WPAPSK", tmpbuf
, 255, buffer
))
1683 if ((strlen(tmpbuf
) >= 8) && (strlen(tmpbuf
) < 64))
1685 PasswordHash((char *)tmpbuf
, pAd
->PortCfg
.Ssid
, pAd
->PortCfg
.SsidLen
, keyMaterial
);
1686 NdisMoveMemory(pAd
->PortCfg
.PskKey
.Key
, keyMaterial
, 32);
1687 // Use RaConfig as PSK agent.
1688 // Start STA supplicant state machine
1689 pAd
->PortCfg
.WpaState
= SS_START
;
1691 DBGPRINT(RT_DEBUG_TRACE
, "%s WPAPSK Key => \n", __FUNCTION__
);
1692 for (i
= 0; i
< 32; i
++)
1694 DBGPRINT(RT_DEBUG_TRACE
, "%02x:", pAd
->PortCfg
.PskKey
.Key
[i
]);
1696 DBGPRINT(RT_DEBUG_TRACE
, "\n");
1698 DBGPRINT(RT_DEBUG_TRACE
, "\n");
1701 else if (strlen(tmpbuf
) == 64)
1703 AtoH(tmpbuf
, pAd
->PortCfg
.PskKey
.Key
, 32);
1704 pAd
->PortCfg
.WpaState
= SS_START
;
1708 if (RTMPGetKeyParameter("Default", "DefaultKeyID", tmpbuf
, 10, buffer
))
1710 ulInfo
= simple_strtol(tmpbuf
, 0, 10);
1711 if((ulInfo
>= 1 ) && (ulInfo
<= 4))
1712 pAd
->PortCfg
.DefaultKeyId
= (UCHAR
) (ulInfo
- 1 );
1714 pAd
->PortCfg
.DefaultKeyId
= 0;
1716 DBGPRINT(RT_DEBUG_TRACE
, "%s::(DefaultKeyID=%d)\n", __FUNCTION__
, pAd
->PortCfg
.DefaultKeyId
);
1719 if (RTMPGetKeyParameter("Default", "Key1Str", tmpbuf
, 26, buffer
))
1721 KeyLen
= strlen(tmpbuf
);
1725 pAd
->PortCfg
.SharedKey
[0].KeyLen
= 0;
1727 case 5: //wep 40 Ascii type
1728 pAd
->PortCfg
.SharedKey
[0].KeyLen
= KeyLen
;
1729 memcpy(pAd
->PortCfg
.SharedKey
[0].Key
, tmpbuf
, KeyLen
);
1730 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key1=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Ascii");
1731 case 10: //wep 40 Hex type
1732 for(i
=0; i
< KeyLen
; i
++)
1734 if( !isxdigit(*(tmpbuf
+i
)) )
1743 pAd
->PortCfg
.SharedKey
[0].KeyLen
= KeyLen
/ 2 ;
1744 AtoH(tmpbuf
, pAd
->PortCfg
.SharedKey
[0].Key
, KeyLen
/ 2);
1745 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key1=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Hex");
1748 case 13: //wep 104 Ascii type
1749 pAd
->PortCfg
.SharedKey
[0].KeyLen
= KeyLen
;
1750 memcpy(pAd
->PortCfg
.SharedKey
[0].Key
, tmpbuf
, KeyLen
);
1751 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key1=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Ascii");
1753 case 26: //wep 104 Hex type
1754 for(i
=0; i
< KeyLen
; i
++)
1756 if( !isxdigit(*(tmpbuf
+i
)) )
1765 pAd
->PortCfg
.SharedKey
[0].KeyLen
= KeyLen
/ 2 ;
1766 AtoH(tmpbuf
, pAd
->PortCfg
.SharedKey
[0].Key
, KeyLen
/ 2);
1767 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key1=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Hex");
1771 pAd
->PortCfg
.SharedKey
[0].KeyLen
= 0;
1772 DBGPRINT(RT_DEBUG_TRACE
, "%s::Invalid Key (=%s)\n", __FUNCTION__
, tmpbuf
);
1776 if (RTMPGetKeyParameter("Default", "Key2Str", tmpbuf
, 26, buffer
))
1778 KeyLen
= strlen(tmpbuf
);
1782 pAd
->PortCfg
.SharedKey
[1].KeyLen
= 0;
1784 case 5: //wep 40 Ascii type
1785 pAd
->PortCfg
.SharedKey
[1].KeyLen
= KeyLen
;
1786 memcpy(pAd
->PortCfg
.SharedKey
[1].Key
, tmpbuf
, KeyLen
);
1787 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key2=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Ascii");
1788 case 10: //wep 40 Hex type
1789 for(i
=0; i
< KeyLen
; i
++)
1791 if( !isxdigit(*(tmpbuf
+i
)) )
1800 pAd
->PortCfg
.SharedKey
[1].KeyLen
= KeyLen
/ 2 ;
1801 AtoH(tmpbuf
, pAd
->PortCfg
.SharedKey
[1].Key
, KeyLen
/ 2);
1802 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key2=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Hex");
1805 case 13: //wep 104 Ascii type
1806 pAd
->PortCfg
.SharedKey
[1].KeyLen
= KeyLen
;
1807 memcpy(pAd
->PortCfg
.SharedKey
[1].Key
, tmpbuf
, KeyLen
);
1808 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key2=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Ascii");
1810 case 26: //wep 104 Hex type
1811 for(i
=0; i
< KeyLen
; i
++)
1813 if( !isxdigit(*(tmpbuf
+i
)) )
1822 pAd
->PortCfg
.SharedKey
[1].KeyLen
= KeyLen
/ 2 ;
1823 AtoH(tmpbuf
, pAd
->PortCfg
.SharedKey
[1].Key
, KeyLen
/ 2);
1824 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key2=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Hex");
1828 pAd
->PortCfg
.SharedKey
[1].KeyLen
= 0;
1829 DBGPRINT(RT_DEBUG_TRACE
, "%s::Invalid argument (=%s)\n", __FUNCTION__
, tmpbuf
);
1833 if (RTMPGetKeyParameter("Default", "Key3Str", tmpbuf
, 26, buffer
))
1835 KeyLen
= strlen(tmpbuf
);
1839 pAd
->PortCfg
.SharedKey
[2].KeyLen
= 0;
1841 case 5: //wep 40 Ascii type
1842 pAd
->PortCfg
.SharedKey
[2].KeyLen
= KeyLen
;
1843 memcpy(pAd
->PortCfg
.SharedKey
[2].Key
, tmpbuf
, KeyLen
);
1844 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key3=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Ascii");
1845 case 10: //wep 40 Hex type
1846 for(i
=0; i
< KeyLen
; i
++)
1848 if( !isxdigit(*(tmpbuf
+i
)) )
1857 pAd
->PortCfg
.SharedKey
[2].KeyLen
= KeyLen
/ 2 ;
1858 AtoH(tmpbuf
, pAd
->PortCfg
.SharedKey
[2].Key
, KeyLen
/ 2);
1859 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key3=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Hex");
1862 case 13: //wep 104 Ascii type
1863 pAd
->PortCfg
.SharedKey
[2].KeyLen
= KeyLen
;
1864 memcpy(pAd
->PortCfg
.SharedKey
[2].Key
, tmpbuf
, KeyLen
);
1865 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key3=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Ascii");
1867 case 26: //wep 104 Hex type
1868 for(i
=0; i
< KeyLen
; i
++)
1870 if( !isxdigit(*(tmpbuf
+i
)) )
1879 pAd
->PortCfg
.SharedKey
[2].KeyLen
= KeyLen
/ 2 ;
1880 AtoH(tmpbuf
, pAd
->PortCfg
.SharedKey
[2].Key
, KeyLen
/ 2);
1881 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key3=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Hex");
1885 pAd
->PortCfg
.SharedKey
[2].KeyLen
= 0;
1886 DBGPRINT(RT_DEBUG_TRACE
, "%s::Invalid argument (=%s)\n", __FUNCTION__
, tmpbuf
);
1890 if (RTMPGetKeyParameter("Default", "Key4Str", tmpbuf
, 26, buffer
))
1892 KeyLen
= strlen(tmpbuf
);
1896 pAd
->PortCfg
.SharedKey
[3].KeyLen
= 0;
1898 case 5: //wep 40 Ascii type
1899 pAd
->PortCfg
.SharedKey
[3].KeyLen
= KeyLen
;
1900 memcpy(pAd
->PortCfg
.SharedKey
[3].Key
, tmpbuf
, KeyLen
);
1901 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key4=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Ascii");
1902 case 10: //wep 40 Hex type
1903 for(i
=0; i
< KeyLen
; i
++)
1905 if( !isxdigit(*(tmpbuf
+i
)) )
1914 pAd
->PortCfg
.SharedKey
[3].KeyLen
= KeyLen
/ 2 ;
1915 AtoH(tmpbuf
, pAd
->PortCfg
.SharedKey
[3].Key
, KeyLen
/ 2);
1916 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key4=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Hex");
1919 case 13: //wep 104 Ascii type
1920 pAd
->PortCfg
.SharedKey
[3].KeyLen
= KeyLen
;
1921 memcpy(pAd
->PortCfg
.SharedKey
[3].Key
, tmpbuf
, KeyLen
);
1922 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key4=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Ascii");
1924 case 26: //wep 104 Hex type
1925 for(i
=0; i
< KeyLen
; i
++)
1927 if( !isxdigit(*(tmpbuf
+i
)) )
1936 pAd
->PortCfg
.SharedKey
[3].KeyLen
= KeyLen
/ 2 ;
1937 AtoH(tmpbuf
, pAd
->PortCfg
.SharedKey
[3].Key
, KeyLen
/ 2);
1938 DBGPRINT(RT_DEBUG_TRACE
, "%s::(Key4=%s and type=%s)\n", __FUNCTION__
, tmpbuf
, "Hex");
1942 pAd
->PortCfg
.SharedKey
[3].KeyLen
= 0;
1943 DBGPRINT(RT_DEBUG_TRACE
, "%s::Invalid argument (=%s)\n", __FUNCTION__
, tmpbuf
);
1950 DBGPRINT(RT_DEBUG_TRACE
, "--> %s does not have a write method\n", src
);
1953 retval
=filp_close(srcf
,NULL
);
1956 DBGPRINT(RT_DEBUG_TRACE
, "--> Error %d closing %s\n", -retval
, src
);
1959 } //if (src && *src)
1962 current
->fsuid
= orgfsuid
;
1963 current
->fsgid
= orgfsgid
;
1966 ========================================================================
1968 Routine Description:
1972 Adapter Pointer to our adapter
1978 Reset NIC to initial state AS IS system boot up time.
1980 ========================================================================
1982 VOID
RTMPRingCleanUp(
1983 IN PRTMP_ADAPTER pAdapter
,
1990 struct sk_buff
*skb
;
1996 // We have to clean all descriptos in case some error happened with reset
1999 pTxD
= (PTXD_STRUC
) pAdapter
->TxRing
[pAdapter
->NextTxDoneIndex
].va_addr
;
2001 pTxD
->Owner
= DESC_OWN_HOST
;
2002 pTxD
->Valid
= FALSE
;
2004 pAdapter
->NextTxDoneIndex
++;
2006 if (pAdapter
->NextTxDoneIndex
>= TX_RING_SIZE
)
2008 pAdapter
->NextTxDoneIndex
= 0;
2011 } while (Count
< TX_RING_SIZE
); // We have to scan all TX ring
2013 // Check for packet in send tx wait waiting queue
2014 while (pAdapter
->TxSwQueue0
.Head
!= NULL
)
2016 // Packets queued, Remove all and return to upper layer
2017 skb
= (struct sk_buff
*)RemoveHeadQueue(&pAdapter
->TxSwQueue0
);
2018 // Release packet by calling send failure
2019 RTMPFreeSkbBuffer(skb
);
2021 while (pAdapter
->TxSwQueue1
.Head
!= NULL
)
2023 // Packets queued, Remove all and return to upper layer
2024 skb
= (struct sk_buff
*)RemoveHeadQueue(&pAdapter
->TxSwQueue1
);
2025 // Release packet by calling send failure
2026 RTMPFreeSkbBuffer(skb
);
2028 while (pAdapter
->TxSwQueue2
.Head
!= NULL
)
2030 // Packets queued, Remove all and return to upper layer
2031 skb
= (struct sk_buff
*)RemoveHeadQueue(&pAdapter
->TxSwQueue2
);
2032 // Release packet by calling send failure
2033 RTMPFreeSkbBuffer(skb
);
2035 while (pAdapter
->TxSwQueue3
.Head
!= NULL
)
2037 // Packets queued, Remove all and return to upper layer
2038 skb
= (struct sk_buff
*)RemoveHeadQueue(&pAdapter
->TxSwQueue3
);
2039 // Release packet by calling send failure
2040 RTMPFreeSkbBuffer(skb
);
2045 // We have to clean all descriptos in case some error happened with reset
2048 pTxD
= (PTXD_STRUC
) pAdapter
->PrioRing
[pAdapter
->NextPrioDoneIndex
].va_addr
;
2050 // We just re-claim these ring spaces.
2051 pTxD
->Owner
= DESC_OWN_HOST
;
2052 pTxD
->Valid
= FALSE
;
2054 pAdapter
->NextPrioDoneIndex
++;
2056 if (pAdapter
->NextPrioDoneIndex
>= PRIO_RING_SIZE
)
2058 pAdapter
->NextPrioDoneIndex
= 0;
2061 } while (Count
< PRIO_RING_SIZE
); // We have to scan all Priority Ring
2063 // Clear managemt buffer ring
2064 while ((pAdapter
->PushMgmtIndex
!= pAdapter
->PopMgmtIndex
) || (pAdapter
->MgmtQueueSize
!= 0))
2066 pMgmt
= (PMGMT_STRUC
) &pAdapter
->MgmtRing
[pAdapter
->PopMgmtIndex
];
2067 if (pMgmt
->Valid
== TRUE
)
2069 MlmeFreeMemory(pAdapter
, pMgmt
->pBuffer
);
2070 pMgmt
->Valid
= FALSE
;
2071 pAdapter
->PopMgmtIndex
++;
2072 pAdapter
->MgmtQueueSize
--;
2073 if (pAdapter
->PopMgmtIndex
>= MGMT_RING_SIZE
)
2075 pAdapter
->PopMgmtIndex
= 0;
2079 pAdapter
->RalinkCounters
.MgmtRingFullCount
= 0;
2083 // We have to clean all descriptos in case some error happened with reset
2086 pRxD
= (PRXD_STRUC
) pAdapter
->RxRing
[pAdapter
->CurRxIndex
].va_addr
;
2088 // Re-initial Rx ring cell to owned by NIC.
2089 pRxD
->Owner
= DESC_OWN_NIC
;
2091 pAdapter
->CurRxIndex
++;
2093 if (pAdapter
->CurRxIndex
>= RX_RING_SIZE
)
2095 pAdapter
->CurRxIndex
= 0;
2098 } while (Count
< RX_RING_SIZE
); // We have to scan all Rx Ring
2108 ========================================================================
2110 Routine Description:
2111 Compare two memory block
2114 Adapter Pointer to our adapter
2118 0: memory are not equal
2122 ========================================================================
2124 ULONG
RTMPEqualMemory(
2133 pMem1
= (PUCHAR
) pSrc1
;
2134 pMem2
= (PUCHAR
) pSrc2
;
2136 for (Index
= 0; Index
< Length
; Index
++)
2138 if (pMem1
[Index
] != pMem2
[Index
])
2144 if (Index
== Length
)
2155 ========================================================================
2157 Routine Description:
2158 Compare two memory block
2161 pSrc1 Pointer to first memory address
2162 pSrc2 Pointer to second memory addres
2166 1: pSrc1 memory is larger
2167 2: pSrc2 memory is larger
2171 ========================================================================
2173 ULONG
RTMPCompareMemory(
2182 pMem1
= (PUCHAR
) pSrc1
;
2183 pMem2
= (PUCHAR
) pSrc2
;
2185 for (Index
= 0; Index
< Length
; Index
++)
2187 if (pMem1
[Index
] > pMem2
[Index
])
2189 else if (pMem1
[Index
] < pMem2
[Index
])
2198 ========================================================================
2200 Routine Description:
2201 Zero out memory block
2204 pSrc1 Pointer to memory address
2212 ========================================================================
2214 VOID
NdisZeroMemory(
2222 pMem
= (PUCHAR
) pSrc
;
2224 for (Index
= 0; Index
< Length
; Index
++)
2229 memset(pSrc
, 0, Length
);
2233 VOID
NdisFillMemory(
2242 pMem
= (PUCHAR
) pSrc
;
2244 for (Index
= 0; Index
< Length
; Index
++)
2249 memset(pSrc
, Fill
, Length
);
2254 ========================================================================
2256 Routine Description:
2257 Copy data from memory block 1 to memory block 2
2260 pDest Pointer to destination memory address
2261 pSrc Pointer to source memory address
2269 ========================================================================
2271 VOID
NdisMoveMemory(
2276 memcpy(pDest
, pSrc
, Length
);
2280 ========================================================================
2282 Routine Description:
2283 Initialize port configuration structure
2286 Adapter Pointer to our adapter
2293 ========================================================================
2296 IN PRTMP_ADAPTER pAdapter
)
2300 DBGPRINT(RT_DEBUG_TRACE
, "--> PortCfgInit\n");
2302 pAdapter
->PortCfg
.UseBGProtection
= 0; // 0: AUTO
2304 pAdapter
->PortCfg
.CapabilityInfo
= 0x0000;
2305 pAdapter
->PortCfg
.Psm
= PWR_ACTIVE
;
2306 pAdapter
->PortCfg
.BeaconPeriod
= 100; // in mSec
2308 pAdapter
->PortCfg
.CfpMaxDuration
= 0; // never mind, decided by AP later
2309 pAdapter
->PortCfg
.CfpDurRemain
= 0; // never mind, decided by AP later
2310 pAdapter
->PortCfg
.CfpCount
= 0; // never mind, decided by AP later
2311 pAdapter
->PortCfg
.CfpPeriod
= 0; // never mind, decided by AP later
2312 pAdapter
->PortCfg
.AuthMode
= Ndis802_11AuthModeOpen
;
2314 for(i
= 0; i
< SHARE_KEY_NO
; i
++) {
2315 pAdapter
->PortCfg
.SharedKey
[i
].KeyLen
= 0;
2318 for(i
= 0; i
< PAIRWISE_KEY_NO
; i
++) {
2319 pAdapter
->PortCfg
.PairwiseKey
[i
].KeyLen
= 0;
2322 for(i
= 0; i
< GROUP_KEY_NO
; i
++) {
2323 pAdapter
->PortCfg
.GroupKey
[i
].KeyLen
= 0;
2326 pAdapter
->PortCfg
.WepStatus
= Ndis802_11EncryptionDisabled
;
2327 pAdapter
->PortCfg
.DefaultKeyId
= 0;
2328 pAdapter
->PortCfg
.PrivacyFilter
= Ndis802_11PrivFilterAcceptAll
;
2330 // 802.1x port control
2331 pAdapter
->PortCfg
.PortSecured
= WPA_802_1X_PORT_NOT_SECURED
;
2332 pAdapter
->PortCfg
.LastMicErrorTime
= 0;
2333 pAdapter
->PortCfg
.MicErrCnt
= 0;
2334 pAdapter
->PortCfg
.bBlockAssoc
= FALSE
;
2335 pAdapter
->PortCfg
.WpaState
= SS_NOTUSE
;
2337 pAdapter
->PortCfg
.RtsThreshold
= 2347;
2338 pAdapter
->PortCfg
.FragmentThreshold
= 2346;
2339 pAdapter
->PortCfg
.bFragmentZeroDisable
= FALSE
;
2341 pAdapter
->PortCfg
.CurrentTxAntenna
= 0xff; // diversity
2342 pAdapter
->PortCfg
.CurrentRxAntenna
= 0xff; // diversity
2343 pAdapter
->PortCfg
.NumberOfAntenna
= 2;
2345 // pAdapter->PortCfg.TxPowerLevel[0] = 100;
2346 // pAdapter->PortCfg.NumOfTxPowerLevel = 1;
2347 pAdapter
->PortCfg
.TxPower
= 100; //mW
2348 pAdapter
->PortCfg
.TxPowerPercentage
= 0xffffffff; // AUTO
2350 pAdapter
->PortCfg
.AntennaSupportTx
= TRUE
;
2351 pAdapter
->PortCfg
.AntennaSupportRx
= TRUE
;
2352 pAdapter
->PortCfg
.AntennaSupportDiversityRx
= TRUE
;
2354 pAdapter
->PortCfg
.RecvDtim
= TRUE
;
2355 NdisZeroMemory(&pAdapter
->PortCfg
.Bssid
, MAC_ADDR_LEN
);
2356 NdisFillMemory(&pAdapter
->PortCfg
.Broadcast
, MAC_ADDR_LEN
, 0xff);
2357 pAdapter
->PortCfg
.Pss
= PWR_ACTIVE
;
2358 pAdapter
->PortCfg
.RssiTrigger
= 0;
2359 pAdapter
->PortCfg
.LastRssi
= 0;
2360 pAdapter
->PortCfg
.LastAvgRssi
= -95 + RSSI_TO_DBM_OFFSET
;// default -95dm
2361 pAdapter
->PortCfg
.AvgRssi
= 0;
2362 pAdapter
->PortCfg
.RssiTriggerMode
= RSSI_TRIGGERED_UPON_BELOW_THRESHOLD
;
2363 pAdapter
->PortCfg
.AtimWin
= 0;
2364 pAdapter
->PortCfg
.Channel
= 1;
2366 pAdapter
->PortCfg
.Aid
= 1;
2368 pAdapter
->PortCfg
.DefaultListenCount
= 3;//default listen count;
2369 pAdapter
->PortCfg
.BssType
= BSS_INFRA
; // BSS_INFRA or BSS_INDEP
2371 pAdapter
->PortCfg
.AdhocMode
= 0;
2373 pAdapter
->PortCfg
.SsidLen
= 0;
2374 NdisZeroMemory(pAdapter
->PortCfg
.Ssid
, MAX_LEN_OF_SSID
); // NOT NULL-terminated
2376 // global variables mXXXX used in MAC protocol state machines
2377 pAdapter
->PortCfg
.Mibss
= FALSE
;
2378 pAdapter
->PortCfg
.Massoc
= FALSE
;
2379 pAdapter
->PortCfg
.Mauth
= FALSE
;
2381 // PHY specification
2382 pAdapter
->PortCfg
.PhyMode
= 0xff;
2383 // RTMPSetPhyMode(pAdapter, PHY_11BG_MIXED); // default in 11BG mixed mode
2384 // pAdapter->PortCfg.Channel = FirstChannel(pAdapter);
2385 pAdapter
->PortCfg
.Dsifs
= 10; // in units of usec
2386 pAdapter
->PortCfg
.TxPreambleInUsed
= Rt802_11PreambleLong
; // use Long preamble on TX by defaut
2388 // user desired power mode
2389 pAdapter
->PortCfg
.WindowsPowerMode
= Ndis802_11PowerModeCAM
; // Ndis802_11PowerModeFast_PSP;
2390 pAdapter
->PortCfg
.WindowsBatteryPowerMode
= Ndis802_11PowerModeCAM
; // Ndis802_11PowerModeFast_PSP;
2391 pAdapter
->PortCfg
.WindowsTxPreamble
= Rt802_11PreambleAuto
; // use Long preamble on TX by defaut
2392 pAdapter
->PortCfg
.WindowsACCAMEnable
= FALSE
;
2393 // pAdapter->PortCfg.PacketFilter = NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST;
2394 pAdapter
->bAcceptDirect
= TRUE
;
2395 pAdapter
->bAcceptMulticast
= FALSE
;
2396 pAdapter
->bAcceptBroadcast
= TRUE
;
2397 pAdapter
->bAcceptAllMulticast
= TRUE
;
2399 // parameters to be used when this STA starts a new ADHOC network
2400 pAdapter
->PortCfg
.IbssConfig
.BeaconPeriod
= 100;
2401 pAdapter
->PortCfg
.IbssConfig
.AtimWin
= 0;
2402 pAdapter
->PortCfg
.IbssConfig
.Channel
= 1;
2403 pAdapter
->PortCfg
.RfType
= RFIC_2525
;
2404 pAdapter
->PortCfg
.LedMode
= LED_MODE_DEFAULT
;
2405 RTMPInitTimer(pAdapter
, &pAdapter
->PortCfg
.RfTuningTimer
, AsicRfTuningExec
);
2407 pAdapter
->PortCfg
.IgnoredScanNumber
= 0;
2408 pAdapter
->bTxBusy
= FALSE
;
2410 pAdapter
->PortCfg
.bHwRadio
= TRUE
;
2411 pAdapter
->PortCfg
.bSwRadio
= TRUE
;
2412 pAdapter
->PortCfg
.bRadio
= TRUE
;
2413 pAdapter
->PortCfg
.bHardwareRadio
= FALSE
; // Default is OFF
2414 pAdapter
->PortCfg
.bAutoTxAgc
= FALSE
; // Default is OFF
2415 pAdapter
->PortCfg
.bShowHiddenSSID
= FALSE
;
2417 // Nitro mode control
2418 pAdapter
->PortCfg
.EnableTxBurst
= 0;
2419 pAdapter
->PortCfg
.AutoReconnect
= TRUE
;
2421 // Save the init time as last scan time, the system should do scan after 2 seconds.
2422 pAdapter
->PortCfg
.LastScanTime
= 0;
2424 // Default Config change flag
2425 pAdapter
->bConfigChanged
= FALSE
;
2427 pAdapter
->PortCfg
.bLocalAdminMAC
= TRUE
;
2429 pAdapter
->NeedSwapToLittleEndian
= TRUE
;
2431 // dynamic BBP R17:sensibity tuning to overcome background noise
2432 pAdapter
->PortCfg
.BbpTuningEnable
= TRUE
; // overwritten by E2PROM setting
2433 pAdapter
->PortCfg
.VgcLowerBound
= 0x38; // overwritten by E2PROM setting
2434 pAdapter
->PortCfg
.BbpTuning
.FalseCcaLowerThreshold
= 100;
2435 pAdapter
->PortCfg
.BbpTuning
.FalseCcaUpperThreshold
= 4; // unit 128, 4*128 = 512
2436 pAdapter
->PortCfg
.BbpTuning
.VgcDelta
= 1;
2437 pAdapter
->PortCfg
.BbpTuning
.VgcUpperBound
= BBP_R17_DYNAMIC_UP_BOUND
;
2439 pAdapter
->PortCfg
.StaWithEtherBridge
.Enable
= FALSE
;
2440 NdisFillMemory(&pAdapter
->PortCfg
.StaWithEtherBridge
.EtherMacAddr
, MAC_ADDR_LEN
, 0xff);
2443 memset(&pAdapter
->ate
, 0, sizeof(ATE_INFO
));
2444 pAdapter
->ate
.Mode
= ATE_STASTART
;
2445 pAdapter
->ate
.TxCount
= TX_RING_SIZE
;
2446 pAdapter
->ate
.TxLength
= PRIO_BUFFER_SIZE
;
2447 pAdapter
->ate
.TxRate
= RATE_11
;
2448 pAdapter
->ate
.Channel
= 1;
2449 memcpy(&pAdapter
->ate
.Addr1
,"001122334455", ETH_LENGTH_OF_ADDRESS
);
2450 memcpy(&pAdapter
->ate
.Addr2
,"001122334455", ETH_LENGTH_OF_ADDRESS
);
2451 memcpy(&pAdapter
->ate
.Addr3
,"001122334455", ETH_LENGTH_OF_ADDRESS
);
2452 #endif //#ifdef RALINK_ATE
2454 RTMP_IO_READ32(pAdapter
, 0, &pAdapter
->PortCfg
.Rt2560Version
);
2456 DBGPRINT(RT_DEBUG_TRACE
, "<-- PortCfgInit\n");
2461 if (ch
>= '0' && ch
<= '9') return (ch
- '0'); // Handle numerals
2462 if (ch
>= 'A' && ch
<= 'F') return (ch
- 'A' + 0xA); // Handle capitol hex digits
2463 if (ch
>= 'a' && ch
<= 'f') return (ch
- 'a' + 0xA); // Handle small hex digits
2468 // FUNCTION: AtoH(char *, UCHAR *, int)
2470 // PURPOSE: Converts ascii string to network order hex
2473 // src - pointer to input ascii string
2474 // dest - pointer to output hex
2475 // destlen - size of dest
2479 // 2 ascii bytes make a hex byte so must put 1st ascii byte of pair
2480 // into upper nibble and 2nd ascii byte of pair into lower nibble.
2483 void AtoH(char * src
, UCHAR
* dest
, int destlen
)
2489 destTemp
= (PUCHAR
) dest
;
2493 *destTemp
= BtoH(*srcptr
++) << 4; // Put 1st ascii byte in upper nibble.
2494 *destTemp
+= BtoH(*srcptr
++); // Add 2nd ascii byte to above.
2500 ========================================================================
2502 Routine Description:
2506 pAdapter Pointer to our adapter
2507 pTimer Timer structure
2508 pTimerFunc Function to execute when timer expired
2509 Repeat Ture for period timer
2516 ========================================================================
2519 IN PRTMP_ADAPTER pAdapter
,
2520 IN PRALINK_TIMER_STRUCT pTimer
,
2521 IN PVOID pTimerFunc
)
2523 pTimer
->State
= FALSE
;
2524 init_timer(&pTimer
->TimerObj
);
2525 pTimer
->TimerObj
.data
= (unsigned long)pAdapter
;
2526 pTimer
->TimerObj
.function
= pTimerFunc
;
2530 ========================================================================
2532 Routine Description:
2536 pTimer Timer structure
2537 Value Timer value in milliseconds
2544 ========================================================================
2547 IN PRTMP_ADAPTER pAdapter
,
2548 IN PRALINK_TIMER_STRUCT pTimer
,
2551 pTimer
->TimerValue
= Value
;
2552 pTimer
->State
= FALSE
;
2553 pTimer
->TimerObj
.expires
= jiffies
+ (Value
* HZ
)/1000;
2554 add_timer(&pTimer
->TimerObj
);
2558 ========================================================================
2560 Routine Description:
2561 Cancel timer objects
2564 Adapter Pointer to our adapter
2570 Reset NIC to initial state AS IS system boot up time.
2572 ========================================================================
2574 VOID
RTMPCancelTimer(
2575 IN PRALINK_TIMER_STRUCT pTimer
)
2577 del_timer_sync(&pTimer
->TimerObj
);