staging: vt6656: camel case and cleanup CARDbyGetPktType
[deliverable/linux.git] / drivers / staging / vt6656 / card.c
CommitLineData
92b96797
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: card.c
20 * Purpose: Provide functions to setup NIC operation mode
21 * Functions:
22 * s_vSafeResetTx - Rest Tx
23 * CARDvSetRSPINF - Set RSPINF
24 * vUpdateIFS - Update slotTime,SIFS,DIFS, and EIFS
25 * CARDvUpdateBasicTopRate - Update BasicTopRate
26 * CARDbAddBasicRate - Add to BasicRateSet
27 * CARDbSetBasicRate - Set Basic Tx Rate
28 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
29 * CARDvSetLoopbackMode - Set Loopback mode
30 * CARDbSoftwareReset - Sortware reset NIC
a0a1f61a 31 * CARDqGetTSFOffset - Calculate TSFOffset
92b96797 32 * CARDbGetCurrentTSF - Read Current NIC TSF counter
a0a1f61a 33 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
92b96797
FB
34 * CARDvSetFirstNextTBTT - Set NIC Beacon time
35 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
36 * CARDbRadioPowerOff - Turn Off NIC Radio Power
37 * CARDbRadioPowerOn - Turn On NIC Radio Power
38 * CARDbSetWEPMode - Set NIC Wep mode
39 * CARDbSetTxPower - Set NIC tx power
40 *
41 * Revision History:
42 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
a0a1f61a 43 * 08-26-2003 Kyle Hsu: Modify the definition type of dwIoBase.
92b96797
FB
44 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
45 *
46 */
47
dd0a774f 48#include "device.h"
92b96797 49#include "tmacro.h"
92b96797 50#include "card.h"
92b96797 51#include "baseband.h"
92b96797 52#include "mac.h"
92b96797 53#include "desc.h"
92b96797 54#include "rf.h"
92b96797 55#include "power.h"
92b96797 56#include "key.h"
92b96797 57#include "rc4.h"
92b96797 58#include "country.h"
92b96797 59#include "datarate.h"
92b96797 60#include "control.h"
92b96797 61
92b96797
FB
62//static int msglevel =MSG_LEVEL_DEBUG;
63static int msglevel =MSG_LEVEL_INFO;
64
3eaca0d2 65//const u16 cwRXBCNTSFOff[MAX_RATE] =
92b96797
FB
66//{17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3};
67
3b138851 68static const u16 cwRXBCNTSFOff[MAX_RATE] =
92b96797
FB
69{192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3};
70
92b96797
FB
71/*
72 * Description: Set NIC media channel
73 *
74 * Parameters:
75 * In:
76 * pDevice - The adapter to be set
7387f438 77 * connection_channel - Channel to be set
92b96797
FB
78 * Out:
79 * none
92b96797 80 */
7387f438 81void CARDbSetMediaChannel(struct vnt_private *priv, u32 connection_channel)
92b96797 82{
92b96797 83
7387f438
MP
84 if (priv->byBBType == BB_TYPE_11A) {
85 if ((connection_channel < (CB_MAX_CHANNEL_24G + 1)) ||
86 (connection_channel > CB_MAX_CHANNEL))
87 connection_channel = (CB_MAX_CHANNEL_24G + 1);
88 } else {
89 if ((connection_channel > CB_MAX_CHANNEL_24G) ||
90 (connection_channel == 0))
91 connection_channel = 1;
92 }
92b96797 93
7387f438
MP
94 /* clear NAV */
95 MACvRegBitsOn(priv, MAC_REG_MACCR, MACCR_CLRNAV);
96
97 /* Set Channel[7] = 0 to tell H/W channel is changing now. */
98 MACvRegBitsOff(priv, MAC_REG_CHANNEL, 0xb0);
99
100 CONTROLnsRequestOut(priv, MESSAGE_TYPE_SELECT_CHANNLE,
101 connection_channel, 0, 0, NULL);
102
103 if (priv->byBBType == BB_TYPE_11A) {
104 priv->byCurPwr = 0xff;
105 RFbRawSetPower(priv,
106 priv->abyOFDMAPwrTbl[connection_channel-15], RATE_54M);
107 } else if (priv->byBBType == BB_TYPE_11G) {
108 priv->byCurPwr = 0xff;
109 RFbRawSetPower(priv,
110 priv->abyOFDMPwrTbl[connection_channel-1], RATE_54M);
111 } else {
112 priv->byCurPwr = 0xff;
113 RFbRawSetPower(priv,
114 priv->abyCCKPwrTbl[connection_channel-1], RATE_1M);
115 }
92b96797 116
7387f438
MP
117 ControlvWriteByte(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL,
118 (u8)(connection_channel|0x80));
92b96797
FB
119}
120
121/*
122 * Description: Get CCK mode basic rate
123 *
124 * Parameters:
125 * In:
126 * pDevice - The adapter to be set
127 * wRateIdx - Receiving data rate
128 * Out:
129 * none
130 *
131 * Return Value: response Control frame rate
132 *
133 */
dd0a774f 134static u16 swGetCCKControlRate(struct vnt_private *pDevice, u16 wRateIdx)
92b96797 135{
dd0a774f
MP
136 u16 ui = wRateIdx;
137
138 while (ui > RATE_1M) {
139 if (pDevice->wBasicRate & (1 << ui))
140 return ui;
141 ui--;
142 }
143
144 return RATE_1M;
92b96797
FB
145}
146
147/*
148 * Description: Get OFDM mode basic rate
149 *
150 * Parameters:
151 * In:
152 * pDevice - The adapter to be set
153 * wRateIdx - Receiving data rate
154 * Out:
155 * none
156 *
157 * Return Value: response Control frame rate
158 *
159 */
dd0a774f 160static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx)
92b96797 161{
dd0a774f
MP
162 u16 ui = wRateIdx;
163
164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n",
165 pDevice->wBasicRate);
166
167 if (!CARDbIsOFDMinBasicRate(pDevice)) {
168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
169 "swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
0b7cb697
DJ
170 if (wRateIdx > RATE_24M)
171 wRateIdx = RATE_24M;
dd0a774f
MP
172 return wRateIdx;
173 }
174
175 while (ui > RATE_11M) {
176 if (pDevice->wBasicRate & (1 << ui)) {
177 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
178 "swGetOFDMControlRate: %d\n", ui);
179 return ui;
180 }
181 ui--;
182 }
183
184 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n");
185
186 return RATE_24M;
92b96797
FB
187}
188
189/*
a0a1f61a 190 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
92b96797
FB
191 *
192 * Parameters:
3605f84e
MP
193 * In:
194 * rate - Tx Rate
195 * bb_type - Tx Packet type
196 * Out:
197 * tx_rate - pointer to RSPINF TxRate field
198 * rsv_time- pointer to RSPINF RsvTime field
92b96797
FB
199 *
200 * Return Value: none
201 *
202 */
3605f84e
MP
203void CARDvCalculateOFDMRParameter(u16 rate, u8 bb_type,
204 u8 *tx_rate, u8 *rsv_time)
92b96797 205{
92b96797 206
3605f84e
MP
207 switch (rate) {
208 case RATE_6M:
209 if (bb_type == BB_TYPE_11A) {
210 *tx_rate = 0x9b;
211 *rsv_time = 24;
212 } else {
213 *tx_rate = 0x8b;
214 *rsv_time = 30;
215 }
216 break;
217 case RATE_9M:
218 if (bb_type == BB_TYPE_11A) {
219 *tx_rate = 0x9f;
220 *rsv_time = 16;
221 } else {
222 *tx_rate = 0x8f;
223 *rsv_time = 22;
224 }
225 break;
226 case RATE_12M:
227 if (bb_type == BB_TYPE_11A) {
228 *tx_rate = 0x9a;
229 *rsv_time = 12;
230 } else {
231 *tx_rate = 0x8a;
232 *rsv_time = 18;
233 }
234 break;
235 case RATE_18M:
236 if (bb_type == BB_TYPE_11A) {
237 *tx_rate = 0x9e;
238 *rsv_time = 8;
239 } else {
240 *tx_rate = 0x8e;
241 *rsv_time = 14;
242 }
243 break;
244 case RATE_36M:
245 if (bb_type == BB_TYPE_11A) {
246 *tx_rate = 0x9d;
247 *rsv_time = 4;
248 } else {
249 *tx_rate = 0x8d;
250 *rsv_time = 10;
251 }
252 break;
253 case RATE_48M:
254 if (bb_type == BB_TYPE_11A) {
255 *tx_rate = 0x98;
256 *rsv_time = 4;
257 } else {
258 *tx_rate = 0x88;
259 *rsv_time = 10;
260 }
261 break;
262 case RATE_54M:
263 if (bb_type == BB_TYPE_11A) {
264 *tx_rate = 0x9c;
265 *rsv_time = 4;
266 } else {
267 *tx_rate = 0x8c;
268 *rsv_time = 10;
269 }
270 break;
271 case RATE_24M:
272 default:
273 if (bb_type == BB_TYPE_11A) {
274 *tx_rate = 0x99;
275 *rsv_time = 8;
276 } else {
277 *tx_rate = 0x89;
278 *rsv_time = 14;
279 }
280 break;
281 }
92b96797
FB
282}
283
284/*
285 * Description: Set RSPINF
286 *
287 * Parameters:
288 * In:
289 * pDevice - The adapter to be set
290 * Out:
291 * none
292 *
293 * Return Value: None.
294 *
295 */
652d0f00
MP
296
297void CARDvSetRSPINF(struct vnt_private *priv, u8 bb_type)
92b96797 298{
aed387c7 299 struct vnt_phy_field phy[4];
652d0f00
MP
300 u8 tx_rate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */
301 u8 rsv_time[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
302 u8 data[34];
dd0a774f 303 int i;
92b96797 304
652d0f00
MP
305 /*RSPINF_b_1*/
306 BBvCalculateParameter(priv, 14,
307 swGetCCKControlRate(priv, RATE_1M), PK_TYPE_11B, &phy[0]);
308
309 /*RSPINF_b_2*/
310 BBvCalculateParameter(priv, 14,
311 swGetCCKControlRate(priv, RATE_2M), PK_TYPE_11B, &phy[1]);
312
313 /*RSPINF_b_5*/
314 BBvCalculateParameter(priv, 14,
315 swGetCCKControlRate(priv, RATE_5M), PK_TYPE_11B, &phy[2]);
316
317 /*RSPINF_b_11*/
318 BBvCalculateParameter(priv, 14,
319 swGetCCKControlRate(priv, RATE_11M), PK_TYPE_11B, &phy[3]);
320
321
322 /*RSPINF_a_6*/
323 CARDvCalculateOFDMRParameter(RATE_6M, bb_type,
324 &tx_rate[0], &rsv_time[0]);
325
326 /*RSPINF_a_9*/
327 CARDvCalculateOFDMRParameter(RATE_9M, bb_type,
328 &tx_rate[1], &rsv_time[1]);
329
330 /*RSPINF_a_12*/
331 CARDvCalculateOFDMRParameter(RATE_12M, bb_type,
332 &tx_rate[2], &rsv_time[2]);
333
334 /*RSPINF_a_18*/
335 CARDvCalculateOFDMRParameter(RATE_18M, bb_type,
336 &tx_rate[3], &rsv_time[3]);
92b96797 337
652d0f00
MP
338 /*RSPINF_a_24*/
339 CARDvCalculateOFDMRParameter(RATE_24M, bb_type,
340 &tx_rate[4], &rsv_time[4]);
341
342 /*RSPINF_a_36*/
343 CARDvCalculateOFDMRParameter(swGetOFDMControlRate(priv, RATE_36M),
344 bb_type, &tx_rate[5], &rsv_time[5]);
345
346 /*RSPINF_a_48*/
347 CARDvCalculateOFDMRParameter(swGetOFDMControlRate(priv, RATE_48M),
348 bb_type, &tx_rate[6], &rsv_time[6]);
349
350 /*RSPINF_a_54*/
351 CARDvCalculateOFDMRParameter(swGetOFDMControlRate(priv, RATE_54M),
352 bb_type, &tx_rate[7], &rsv_time[7]);
353
354 /*RSPINF_a_72*/
355 CARDvCalculateOFDMRParameter(swGetOFDMControlRate(priv, RATE_54M),
356 bb_type, &tx_rate[8], &rsv_time[8]);
357
358 put_unaligned(phy[0].len, (u16 *)&data[0]);
359 data[2] = phy[0].signal;
360 data[3] = phy[0].service;
361
362 put_unaligned(phy[1].len, (u16 *)&data[4]);
363 data[6] = phy[1].signal;
364 data[7] = phy[1].service;
365
366 put_unaligned(phy[2].len, (u16 *)&data[8]);
367 data[10] = phy[2].signal;
368 data[11] = phy[2].service;
369
370 put_unaligned(phy[3].len, (u16 *)&data[12]);
371 data[14] = phy[3].signal;
372 data[15] = phy[3].service;
373
374 for (i = 0; i < 9; i++) {
375 data[16 + i * 2] = tx_rate[i];
376 data[16 + i * 2 + 1] = rsv_time[i];
377 }
92b96797 378
652d0f00
MP
379 CONTROLnsRequestOut(priv, MESSAGE_TYPE_WRITE,
380 MAC_REG_RSPINF_B_1, MESSAGE_REQUEST_MACREG, 34, &data[0]);
92b96797
FB
381}
382
383/*
384 * Description: Update IFS
385 *
386 * Parameters:
387 * In:
5ebc46d6
MP
388 * priv - The adapter to be set
389 * Out:
390 * none
92b96797
FB
391 *
392 * Return Value: None.
393 *
394 */
5ebc46d6 395void vUpdateIFS(struct vnt_private *priv)
92b96797 396{
5ebc46d6
MP
397 u8 max_min = 0;
398 u8 data[4];
399
400 if (priv->byPacketType == PK_TYPE_11A) {
401 priv->uSlot = C_SLOT_SHORT;
402 priv->uSIFS = C_SIFS_A;
403 priv->uDIFS = C_SIFS_A + 2 * C_SLOT_SHORT;
404 priv->uCwMin = C_CWMIN_A;
405 max_min = 4;
406 } else if (priv->byPacketType == PK_TYPE_11B) {
407 priv->uSlot = C_SLOT_LONG;
408 priv->uSIFS = C_SIFS_BG;
409 priv->uDIFS = C_SIFS_BG + 2 * C_SLOT_LONG;
410 priv->uCwMin = C_CWMIN_B;
411 max_min = 5;
412 } else {/* PK_TYPE_11GA & PK_TYPE_11GB */
413 u8 rate = 0;
414 bool ofdm_rate = false;
415 unsigned int ii = 0;
416 PWLAN_IE_SUPP_RATES item_rates = NULL;
417
418 priv->uSIFS = C_SIFS_BG;
419
420 if (priv->bShortSlotTime)
421 priv->uSlot = C_SLOT_SHORT;
422 else
423 priv->uSlot = C_SLOT_LONG;
424
425 priv->uDIFS = C_SIFS_BG + 2 * priv->uSlot;
426
427 item_rates =
428 (PWLAN_IE_SUPP_RATES)priv->vnt_mgmt.abyCurrSuppRates;
429
430 for (ii = 0; ii < item_rates->len; ii++) {
431 rate = (u8)(item_rates->abyRates[ii] & 0x7f);
432 if (RATEwGetRateIdx(rate) > RATE_11M) {
433 ofdm_rate = true;
434 break;
435 }
436 }
437
438 if (ofdm_rate == false) {
439 item_rates = (PWLAN_IE_SUPP_RATES)priv->vnt_mgmt
440 .abyCurrExtSuppRates;
441 for (ii = 0; ii < item_rates->len; ii++) {
442 rate = (u8)(item_rates->abyRates[ii] & 0x7f);
443 if (RATEwGetRateIdx(rate) > RATE_11M) {
444 ofdm_rate = true;
445 break;
446 }
447 }
448 }
449
450 if (ofdm_rate == true) {
451 priv->uCwMin = C_CWMIN_A;
452 max_min = 4;
453 } else {
454 priv->uCwMin = C_CWMIN_B;
455 max_min = 5;
456 }
457 }
458
459 priv->uCwMax = C_CWMAX;
460 priv->uEIFS = C_EIFS;
461
462 data[0] = (u8)priv->uSIFS;
463 data[1] = (u8)priv->uDIFS;
464 data[2] = (u8)priv->uEIFS;
465 data[3] = (u8)priv->uSlot;
466
467 CONTROLnsRequestOut(priv, MESSAGE_TYPE_WRITE, MAC_REG_SIFS,
468 MESSAGE_REQUEST_MACREG, 4, &data[0]);
469
470 max_min |= 0xa0;
471
472 CONTROLnsRequestOut(priv, MESSAGE_TYPE_WRITE, MAC_REG_CWMAXMIN0,
473 MESSAGE_REQUEST_MACREG, 1, &max_min);
92b96797
FB
474}
475
dcce9e0b 476void CARDvUpdateBasicTopRate(struct vnt_private *priv)
92b96797 477{
dcce9e0b
MP
478 u8 top_ofdm = RATE_24M, top_cck = RATE_1M;
479 u8 i;
480
481 /*Determines the highest basic rate.*/
482 for (i = RATE_54M; i >= RATE_6M; i--) {
483 if (priv->wBasicRate & (u16)(1 << i)) {
484 top_ofdm = i;
485 break;
486 }
487 }
488
489 priv->byTopOFDMBasicRate = top_ofdm;
490
491 for (i = RATE_11M;; i--) {
492 if (priv->wBasicRate & (u16)(1 << i)) {
493 top_cck = i;
494 break;
495 }
496 if (i == RATE_1M)
497 break;
498 }
499
500 priv->byTopCCKBasicRate = top_cck;
92b96797
FB
501 }
502
503/*
504 * Description: Set NIC Tx Basic Rate
505 *
506 * Parameters:
507 * In:
508 * pDevice - The adapter to be set
509 * wBasicRate - Basic Rate to be set
510 * Out:
511 * none
512 *
4e9b5e2b 513 * Return Value: true if succeeded; false if failed.
92b96797
FB
514 *
515 */
6db0deae 516void CARDbAddBasicRate(struct vnt_private *priv, u16 rate_idx)
92b96797 517{
92b96797 518
6db0deae 519 priv->wBasicRate |= (1 << rate_idx);
92b96797 520
6db0deae
MP
521 /*Determines the highest basic rate.*/
522 CARDvUpdateBasicTopRate(priv);
92b96797
FB
523}
524
de0eb9ef 525int CARDbIsOFDMinBasicRate(struct vnt_private *priv)
92b96797 526{
dd0a774f 527 int ii;
92b96797 528
de0eb9ef
MP
529 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
530 if ((priv->wBasicRate) & ((u16)(1 << ii)))
531 return true;
532 }
533
534 return false;
92b96797
FB
535}
536
1f44238f 537u8 CARDbyGetPktType(struct vnt_private *priv)
92b96797 538{
92b96797 539
1f44238f
MP
540 if (priv->byBBType == BB_TYPE_11A || priv->byBBType == BB_TYPE_11B)
541 return (u8)priv->byBBType;
542 else if (CARDbIsOFDMinBasicRate(priv))
543 return PK_TYPE_11GA;
544 else
545 return PK_TYPE_11GB;
92b96797
FB
546}
547
92b96797 548/*
a0a1f61a 549 * Description: Calculate TSF offset of two TSF input
92b96797
FB
550 * Get TSF Offset from RxBCN's TSF and local TSF
551 *
552 * Parameters:
553 * In:
554 * pDevice - The adapter to be sync.
555 * qwTSF1 - Rx BCN's TSF
556 * qwTSF2 - Local TSF
557 * Out:
558 * none
559 *
560 * Return Value: TSF Offset value
561 *
562 */
b902fbfe 563u64 CARDqGetTSFOffset(u8 byRxRate, u64 qwTSF1, u64 qwTSF2)
92b96797 564{
7c65fa2a 565 u64 qwTSFOffset = 0;
3eaca0d2 566 u16 wRxBcnTSFOffst = 0;
92b96797 567
7c65fa2a 568 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE];
92b96797 569
7c65fa2a
MP
570 qwTSF2 += (u64)wRxBcnTSFOffst;
571
572 qwTSFOffset = qwTSF1 - qwTSF2;
573
574 return qwTSFOffset;
92b96797
FB
575}
576
92b96797
FB
577/*
578 * Description: Sync. TSF counter to BSS
579 * Get TSF offset and write to HW
580 *
581 * Parameters:
582 * In:
583 * pDevice - The adapter to be sync.
584 * qwBSSTimestamp - Rx BCN's TSF
585 * qwLocalTSF - Local TSF
586 * Out:
587 * none
588 *
589 * Return Value: none
590 *
591 */
dd0a774f 592void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
7c65fa2a 593 u64 qwBSSTimestamp, u64 qwLocalTSF)
92b96797 594{
7c65fa2a 595 u64 qwTSFOffset = 0;
dd0a774f 596 u8 pbyData[8];
92b96797 597
92b96797
FB
598 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
599 // adjust TSF
600 // HW's TSF add TSF Offset reg
92b96797 601
7c65fa2a
MP
602 pbyData[0] = (u8)qwTSFOffset;
603 pbyData[1] = (u8)(qwTSFOffset >> 8);
604 pbyData[2] = (u8)(qwTSFOffset >> 16);
605 pbyData[3] = (u8)(qwTSFOffset >> 24);
606 pbyData[4] = (u8)(qwTSFOffset >> 32);
607 pbyData[5] = (u8)(qwTSFOffset >> 40);
608 pbyData[6] = (u8)(qwTSFOffset >> 48);
609 pbyData[7] = (u8)(qwTSFOffset >> 56);
92b96797
FB
610
611 CONTROLnsRequestOut(pDevice,
612 MESSAGE_TYPE_SET_TSFTBTT,
613 MESSAGE_REQUEST_TSF,
614 0,
615 8,
616 pbyData
617 );
618
619}
620/*
621 * Description: Read NIC TSF counter
622 * Get local TSF counter
623 *
624 * Parameters:
625 * In:
626 * pDevice - The adapter to be read
627 * Out:
628 * qwCurrTSF - Current TSF counter
629 *
4e9b5e2b 630 * Return Value: true if success; otherwise false
92b96797
FB
631 *
632 */
dfdcc425 633bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF)
92b96797 634{
92b96797 635
7c65fa2a 636 *pqwCurrTSF = pDevice->qwCurrTSF;
92b96797 637
4e9b5e2b 638 return true;
92b96797
FB
639}
640
92b96797
FB
641/*
642 * Description: Clear NIC TSF counter
643 * Clear local TSF counter
644 *
645 * Parameters:
646 * In:
647 * pDevice - The adapter to be read
648 *
4e9b5e2b 649 * Return Value: true if success; otherwise false
92b96797
FB
650 *
651 */
dfdcc425 652bool CARDbClearCurrentTSF(struct vnt_private *pDevice)
92b96797 653{
92b96797 654
dd0a774f 655 MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
92b96797 656
7c65fa2a 657 pDevice->qwCurrTSF = 0;
92b96797 658
4e9b5e2b 659 return true;
92b96797
FB
660}
661
662/*
663 * Description: Read NIC TSF counter
664 * Get NEXTTBTT from adjusted TSF and Beacon Interval
665 *
666 * Parameters:
667 * In:
668 * qwTSF - Current TSF counter
669 * wbeaconInterval - Beacon Interval
670 * Out:
671 * qwCurrTSF - Current TSF counter
672 *
673 * Return Value: TSF value of next Beacon
674 *
675 */
3eaca0d2 676u64 CARDqGetNextTBTT(u64 qwTSF, u16 wBeaconInterval)
92b96797 677{
6e28024e 678 u32 uBeaconInterval;
92b96797 679
6e28024e 680 uBeaconInterval = wBeaconInterval * 1024;
92b96797 681
6e28024e
MP
682 /* Next TBTT =
683 * ((local_current_TSF / beacon_interval) + 1) * beacon_interval
684 */
685 if (uBeaconInterval) {
686 do_div(qwTSF, uBeaconInterval);
687 qwTSF += 1;
688 qwTSF *= uBeaconInterval;
689 }
92b96797 690
6e28024e 691 return qwTSF;
92b96797
FB
692}
693
92b96797
FB
694/*
695 * Description: Set NIC TSF counter for first Beacon time
696 * Get NEXTTBTT from adjusted TSF and Beacon Interval
697 *
698 * Parameters:
699 * In:
700 * dwIoBase - IO Base
701 * wBeaconInterval - Beacon Interval
702 * Out:
703 * none
704 *
705 * Return Value: none
706 *
707 */
3eaca0d2 708void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, u16 wBeaconInterval)
92b96797 709{
7c65fa2a 710 u64 qwNextTBTT = 0;
dd0a774f 711 u8 pbyData[8];
92b96797 712
7c65fa2a 713 CARDbClearCurrentTSF(pDevice);
92b96797 714 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
7c65fa2a 715 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
92b96797
FB
716 // Set NextTBTT
717
7c65fa2a
MP
718 pbyData[0] = (u8)qwNextTBTT;
719 pbyData[1] = (u8)(qwNextTBTT >> 8);
720 pbyData[2] = (u8)(qwNextTBTT >> 16);
721 pbyData[3] = (u8)(qwNextTBTT >> 24);
722 pbyData[4] = (u8)(qwNextTBTT >> 32);
723 pbyData[5] = (u8)(qwNextTBTT >> 40);
724 pbyData[6] = (u8)(qwNextTBTT >> 48);
725 pbyData[7] = (u8)(qwNextTBTT >> 56);
92b96797
FB
726
727 CONTROLnsRequestOut(pDevice,
728 MESSAGE_TYPE_SET_TSFTBTT,
729 MESSAGE_REQUEST_TBTT,
730 0,
731 8,
732 pbyData
733 );
734
735 return;
736}
737
92b96797
FB
738/*
739 * Description: Sync NIC TSF counter for Beacon time
740 * Get NEXTTBTT and write to HW
741 *
742 * Parameters:
743 * In:
744 * pDevice - The adapter to be set
745 * qwTSF - Current TSF counter
746 * wBeaconInterval - Beacon Interval
747 * Out:
748 * none
749 *
750 * Return Value: none
751 *
752 */
dd0a774f
MP
753void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
754 u16 wBeaconInterval)
92b96797 755{
dd0a774f 756 u8 pbyData[8];
92b96797
FB
757
758 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
759
760 // Set NextTBTT
7c65fa2a
MP
761
762 pbyData[0] = (u8)qwTSF;
763 pbyData[1] = (u8)(qwTSF >> 8);
764 pbyData[2] = (u8)(qwTSF >> 16);
765 pbyData[3] = (u8)(qwTSF >> 24);
766 pbyData[4] = (u8)(qwTSF >> 32);
767 pbyData[5] = (u8)(qwTSF >> 40);
768 pbyData[6] = (u8)(qwTSF >> 48);
769 pbyData[7] = (u8)(qwTSF >> 56);
92b96797
FB
770
771 CONTROLnsRequestOut(pDevice,
772 MESSAGE_TYPE_SET_TSFTBTT,
773 MESSAGE_REQUEST_TBTT,
774 0,
775 8,
776 pbyData
777 );
778
7c65fa2a
MP
779 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
780 "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF);
92b96797
FB
781
782 return;
783}
784
785/*
786 * Description: Turn off Radio power
787 *
788 * Parameters:
789 * In:
790 * pDevice - The adapter to be turned off
791 * Out:
792 * none
793 *
4e9b5e2b 794 * Return Value: true if success; otherwise false
92b96797
FB
795 *
796 */
dd0a774f 797int CARDbRadioPowerOff(struct vnt_private *pDevice)
92b96797 798{
4e9b5e2b 799 int bResult = true;
92b96797 800
4e9b5e2b
AM
801 //if (pDevice->bRadioOff == true)
802 // return true;
92b96797 803
4e9b5e2b 804 pDevice->bRadioOff = true;
92b96797
FB
805
806 switch (pDevice->byRFType) {
807 case RF_AL2230:
808 case RF_AL2230S:
809 case RF_AIROHA7230:
810 case RF_VT3226: //RobertYu:20051111
811 case RF_VT3226D0:
812 case RF_VT3342A0: //RobertYu:20060609
813 MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
814 break;
815 }
816
817 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
818
819 BBvSetDeepSleep(pDevice);
820
821 return bResult;
822}
823
92b96797
FB
824/*
825 * Description: Turn on Radio power
826 *
827 * Parameters:
828 * In:
829 * pDevice - The adapter to be turned on
830 * Out:
831 * none
832 *
4e9b5e2b 833 * Return Value: true if success; otherwise false
92b96797
FB
834 *
835 */
dd0a774f 836int CARDbRadioPowerOn(struct vnt_private *pDevice)
92b96797 837{
4e9b5e2b 838 int bResult = true;
92b96797 839
4e9b5e2b 840 if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
e269fc2d 841 return false;
92b96797
FB
842 }
843
e269fc2d 844 //if (pDevice->bRadioOff == false)
4e9b5e2b 845 // return true;
92b96797 846
e269fc2d 847 pDevice->bRadioOff = false;
92b96797
FB
848
849 BBvExitDeepSleep(pDevice);
850
851 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
852
853 switch (pDevice->byRFType) {
854 case RF_AL2230:
855 case RF_AL2230S:
856 case RF_AIROHA7230:
857 case RF_VT3226: //RobertYu:20051111
858 case RF_VT3226D0:
859 case RF_VT3342A0: //RobertYu:20060609
860 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
861 break;
862 }
863
864 return bResult;
865}
866
dd0a774f 867void CARDvSetBSSMode(struct vnt_private *pDevice)
92b96797 868{
92b96797
FB
869 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
870 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
871 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
872 {
873 MACvSetBBType(pDevice, BB_TYPE_11G);
874 }
875 else
876 {
877 MACvSetBBType(pDevice, pDevice->byBBType);
878 }
879 pDevice->byPacketType = CARDbyGetPktType(pDevice);
880
881 if (pDevice->byBBType == BB_TYPE_11A) {
882 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
883 } else if (pDevice->byBBType == BB_TYPE_11B) {
884 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
885 } else if (pDevice->byBBType == BB_TYPE_11G) {
886 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
887 }
888
889 vUpdateIFS(pDevice);
b902fbfe 890 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
92b96797
FB
891
892 if ( pDevice->byBBType == BB_TYPE_11A ) {
893 //request by Jack 2005-04-26
894 if (pDevice->byRFType == RF_AIROHA7230) {
895 pDevice->abyBBVGA[0] = 0x20;
896 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
897 }
898 pDevice->abyBBVGA[2] = 0x10;
899 pDevice->abyBBVGA[3] = 0x10;
900 } else {
901 //request by Jack 2005-04-26
902 if (pDevice->byRFType == RF_AIROHA7230) {
903 pDevice->abyBBVGA[0] = 0x1C;
904 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
905 }
906 pDevice->abyBBVGA[2] = 0x0;
907 pDevice->abyBBVGA[3] = 0x0;
908 }
909}
This page took 0.654019 seconds and 5 git commands to generate.