staging: vt6656: camel case clean up CARDvUpdateNextTBTT
[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:
3fd2a69c
MP
554 * rx_rate - rx rate.
555 * tsf1 - Rx BCN's TSF
556 * tsf2 - Local TSF
92b96797
FB
557 * Out:
558 * none
559 *
560 * Return Value: TSF Offset value
561 *
562 */
3fd2a69c 563u64 CARDqGetTSFOffset(u8 rx_rate, u64 tsf1, u64 tsf2)
92b96797 564{
3fd2a69c
MP
565 u64 tsf_offset = 0;
566 u16 rx_bcn_offset = 0;
92b96797 567
3fd2a69c 568 rx_bcn_offset = cwRXBCNTSFOff[rx_rate % MAX_RATE];
92b96797 569
3fd2a69c 570 tsf2 += (u64)rx_bcn_offset;
7c65fa2a 571
3fd2a69c 572 tsf_offset = tsf1 - tsf2;
7c65fa2a 573
3fd2a69c 574 return tsf_offset;
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:
302361d4
MP
583 * priv - The adapter to be sync.
584 * time_stamp - Rx BCN's TSF
585 * local_tsf - Local TSF
92b96797
FB
586 * Out:
587 * none
588 *
589 * Return Value: none
590 *
591 */
302361d4
MP
592void CARDvAdjustTSF(struct vnt_private *priv, u8 rx_rate,
593 u64 time_stamp, u64 local_tsf)
92b96797 594{
302361d4
MP
595 u64 tsf_offset = 0;
596 u8 data[8];
597
598 tsf_offset = CARDqGetTSFOffset(rx_rate, time_stamp, local_tsf);
599
600 data[0] = (u8)tsf_offset;
601 data[1] = (u8)(tsf_offset >> 8);
602 data[2] = (u8)(tsf_offset >> 16);
603 data[3] = (u8)(tsf_offset >> 24);
604 data[4] = (u8)(tsf_offset >> 32);
605 data[5] = (u8)(tsf_offset >> 40);
606 data[6] = (u8)(tsf_offset >> 48);
607 data[7] = (u8)(tsf_offset >> 56);
92b96797 608
302361d4
MP
609 CONTROLnsRequestOut(priv, MESSAGE_TYPE_SET_TSFTBTT,
610 MESSAGE_REQUEST_TSF, 0, 8, data);
92b96797
FB
611}
612/*
613 * Description: Read NIC TSF counter
614 * Get local TSF counter
615 *
616 * Parameters:
617 * In:
2092dfa4 618 * priv - The adapter to be read
92b96797 619 * Out:
2092dfa4 620 * current_tsf - Current TSF counter
92b96797 621 *
4e9b5e2b 622 * Return Value: true if success; otherwise false
92b96797
FB
623 *
624 */
2092dfa4 625bool CARDbGetCurrentTSF(struct vnt_private *priv, u64 *current_tsf)
92b96797 626{
92b96797 627
2092dfa4 628 *current_tsf = priv->qwCurrTSF;
92b96797 629
4e9b5e2b 630 return true;
92b96797
FB
631}
632
92b96797
FB
633/*
634 * Description: Clear NIC TSF counter
635 * Clear local TSF counter
636 *
637 * Parameters:
638 * In:
e151e478 639 * priv - The adapter to be read
92b96797 640 *
4e9b5e2b 641 * Return Value: true if success; otherwise false
92b96797
FB
642 *
643 */
e151e478 644bool CARDbClearCurrentTSF(struct vnt_private *priv)
92b96797 645{
92b96797 646
e151e478 647 MACvRegBitsOn(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
92b96797 648
e151e478 649 priv->qwCurrTSF = 0;
92b96797 650
4e9b5e2b 651 return true;
92b96797
FB
652}
653
654/*
655 * Description: Read NIC TSF counter
656 * Get NEXTTBTT from adjusted TSF and Beacon Interval
657 *
658 * Parameters:
659 * In:
5f4dfb66
MP
660 * tsf - Current TSF counter
661 * beacon_interval - Beacon Interval
92b96797 662 * Out:
5f4dfb66 663 * tsf - Current TSF counter
92b96797
FB
664 *
665 * Return Value: TSF value of next Beacon
666 *
667 */
5f4dfb66 668u64 CARDqGetNextTBTT(u64 tsf, u16 beacon_interval)
92b96797 669{
5f4dfb66 670 u32 beacon_int;
92b96797 671
5f4dfb66 672 beacon_int = beacon_interval * 1024;
92b96797 673
6e28024e
MP
674 /* Next TBTT =
675 * ((local_current_TSF / beacon_interval) + 1) * beacon_interval
676 */
5f4dfb66
MP
677 if (beacon_int) {
678 do_div(tsf, beacon_int);
679 tsf += 1;
680 tsf *= beacon_int;
6e28024e 681 }
92b96797 682
5f4dfb66 683 return tsf;
92b96797
FB
684}
685
92b96797
FB
686/*
687 * Description: Set NIC TSF counter for first Beacon time
688 * Get NEXTTBTT from adjusted TSF and Beacon Interval
689 *
690 * Parameters:
691 * In:
692 * dwIoBase - IO Base
414475f6 693 * beacon_interval - Beacon Interval
92b96797
FB
694 * Out:
695 * none
696 *
697 * Return Value: none
698 *
699 */
414475f6 700void CARDvSetFirstNextTBTT(struct vnt_private *priv, u16 beacon_interval)
92b96797 701{
414475f6
MP
702 u64 next_tbtt = 0;
703 u8 data[8];
704
705 CARDbClearCurrentTSF(priv);
706
707 next_tbtt = CARDqGetNextTBTT(next_tbtt, beacon_interval);
708
709 data[0] = (u8)next_tbtt;
710 data[1] = (u8)(next_tbtt >> 8);
711 data[2] = (u8)(next_tbtt >> 16);
712 data[3] = (u8)(next_tbtt >> 24);
713 data[4] = (u8)(next_tbtt >> 32);
714 data[5] = (u8)(next_tbtt >> 40);
715 data[6] = (u8)(next_tbtt >> 48);
716 data[7] = (u8)(next_tbtt >> 56);
717
718 CONTROLnsRequestOut(priv, MESSAGE_TYPE_SET_TSFTBTT,
719 MESSAGE_REQUEST_TBTT, 0, 8, data);
92b96797 720
414475f6 721 return;
92b96797
FB
722}
723
92b96797
FB
724/*
725 * Description: Sync NIC TSF counter for Beacon time
726 * Get NEXTTBTT and write to HW
727 *
728 * Parameters:
729 * In:
8b515de7
MP
730 * priv - The adapter to be set
731 * tsf - Current TSF counter
732 * beacon_interval - Beacon Interval
92b96797
FB
733 * Out:
734 * none
735 *
736 * Return Value: none
737 *
738 */
8b515de7
MP
739void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 tsf,
740 u16 beacon_interval)
92b96797 741{
8b515de7 742 u8 data[8];
92b96797 743
8b515de7 744 tsf = CARDqGetNextTBTT(tsf, beacon_interval);
7c65fa2a 745
8b515de7
MP
746 data[0] = (u8)tsf;
747 data[1] = (u8)(tsf >> 8);
748 data[2] = (u8)(tsf >> 16);
749 data[3] = (u8)(tsf >> 24);
750 data[4] = (u8)(tsf >> 32);
751 data[5] = (u8)(tsf >> 40);
752 data[6] = (u8)(tsf >> 48);
753 data[7] = (u8)(tsf >> 56);
92b96797 754
8b515de7
MP
755 CONTROLnsRequestOut(priv, MESSAGE_TYPE_SET_TSFTBTT,
756 MESSAGE_REQUEST_TBTT, 0, 8, data);
92b96797 757
7c65fa2a 758 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
8b515de7 759 "Card:Update Next TBTT[%8lx]\n", (unsigned long)tsf);
92b96797 760
8b515de7 761 return;
92b96797
FB
762}
763
764/*
765 * Description: Turn off Radio power
766 *
767 * Parameters:
768 * In:
769 * pDevice - The adapter to be turned off
770 * Out:
771 * none
772 *
4e9b5e2b 773 * Return Value: true if success; otherwise false
92b96797
FB
774 *
775 */
dd0a774f 776int CARDbRadioPowerOff(struct vnt_private *pDevice)
92b96797 777{
4e9b5e2b 778 int bResult = true;
92b96797 779
4e9b5e2b
AM
780 //if (pDevice->bRadioOff == true)
781 // return true;
92b96797 782
4e9b5e2b 783 pDevice->bRadioOff = true;
92b96797
FB
784
785 switch (pDevice->byRFType) {
786 case RF_AL2230:
787 case RF_AL2230S:
788 case RF_AIROHA7230:
789 case RF_VT3226: //RobertYu:20051111
790 case RF_VT3226D0:
791 case RF_VT3342A0: //RobertYu:20060609
792 MACvRegBitsOff(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
793 break;
794 }
795
796 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
797
798 BBvSetDeepSleep(pDevice);
799
800 return bResult;
801}
802
92b96797
FB
803/*
804 * Description: Turn on Radio power
805 *
806 * Parameters:
807 * In:
808 * pDevice - The adapter to be turned on
809 * Out:
810 * none
811 *
4e9b5e2b 812 * Return Value: true if success; otherwise false
92b96797
FB
813 *
814 */
dd0a774f 815int CARDbRadioPowerOn(struct vnt_private *pDevice)
92b96797 816{
4e9b5e2b 817 int bResult = true;
92b96797 818
4e9b5e2b 819 if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
e269fc2d 820 return false;
92b96797
FB
821 }
822
e269fc2d 823 //if (pDevice->bRadioOff == false)
4e9b5e2b 824 // return true;
92b96797 825
e269fc2d 826 pDevice->bRadioOff = false;
92b96797
FB
827
828 BBvExitDeepSleep(pDevice);
829
830 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_RXON);
831
832 switch (pDevice->byRFType) {
833 case RF_AL2230:
834 case RF_AL2230S:
835 case RF_AIROHA7230:
836 case RF_VT3226: //RobertYu:20051111
837 case RF_VT3226D0:
838 case RF_VT3342A0: //RobertYu:20060609
839 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
840 break;
841 }
842
843 return bResult;
844}
845
dd0a774f 846void CARDvSetBSSMode(struct vnt_private *pDevice)
92b96797 847{
92b96797
FB
848 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
849 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
850 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
851 {
852 MACvSetBBType(pDevice, BB_TYPE_11G);
853 }
854 else
855 {
856 MACvSetBBType(pDevice, pDevice->byBBType);
857 }
858 pDevice->byPacketType = CARDbyGetPktType(pDevice);
859
860 if (pDevice->byBBType == BB_TYPE_11A) {
861 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
862 } else if (pDevice->byBBType == BB_TYPE_11B) {
863 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
864 } else if (pDevice->byBBType == BB_TYPE_11G) {
865 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
866 }
867
868 vUpdateIFS(pDevice);
b902fbfe 869 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
92b96797
FB
870
871 if ( pDevice->byBBType == BB_TYPE_11A ) {
872 //request by Jack 2005-04-26
873 if (pDevice->byRFType == RF_AIROHA7230) {
874 pDevice->abyBBVGA[0] = 0x20;
875 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
876 }
877 pDevice->abyBBVGA[2] = 0x10;
878 pDevice->abyBBVGA[3] = 0x10;
879 } else {
880 //request by Jack 2005-04-26
881 if (pDevice->byRFType == RF_AIROHA7230) {
882 pDevice->abyBBVGA[0] = 0x1C;
883 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]);
884 }
885 pDevice->abyBBVGA[2] = 0x0;
886 pDevice->abyBBVGA[3] = 0x0;
887 }
888}
This page took 0.503135 seconds and 5 git commands to generate.