card.c revision f320314435163773a03a33ca533ba9dd926c376b
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 31 * CARDqGetTSFOffset - Calculate TSFOffset 32 * CARDbGetCurrentTSF - Read Current NIC TSF counter 33 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter 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. 43 * 08-26-2003 Kyle Hsu: Modify the definition type of dwIoBase. 44 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS(). 45 * 46 */ 47 48#include "device.h" 49#include "tmacro.h" 50#include "card.h" 51#include "baseband.h" 52#include "mac.h" 53#include "desc.h" 54#include "rf.h" 55#include "power.h" 56#include "key.h" 57#include "rc4.h" 58#include "country.h" 59#include "datarate.h" 60#include "control.h" 61 62//static int msglevel =MSG_LEVEL_DEBUG; 63static int msglevel =MSG_LEVEL_INFO; 64 65//const u16 cwRXBCNTSFOff[MAX_RATE] = 66//{17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3}; 67 68static const u16 cwRXBCNTSFOff[MAX_RATE] = 69{192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3}; 70 71/* 72 * Description: Set NIC media channel 73 * 74 * Parameters: 75 * In: 76 * pDevice - The adapter to be set 77 * connection_channel - Channel to be set 78 * Out: 79 * none 80 */ 81void CARDbSetMediaChannel(struct vnt_private *priv, u32 connection_channel) 82{ 83 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 } 93 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 } 116 117 ControlvWriteByte(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL, 118 (u8)(connection_channel|0x80)); 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 */ 134static u16 swGetCCKControlRate(struct vnt_private *pDevice, u16 wRateIdx) 135{ 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; 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 */ 160static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx) 161{ 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); 170 if (wRateIdx > RATE_24M) 171 wRateIdx = RATE_24M; 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; 187} 188 189/* 190 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode. 191 * 192 * Parameters: 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 199 * 200 * Return Value: none 201 * 202 */ 203void CARDvCalculateOFDMRParameter(u16 rate, u8 bb_type, 204 u8 *tx_rate, u8 *rsv_time) 205{ 206 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 } 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 */ 296 297void CARDvSetRSPINF(struct vnt_private *priv, u8 bb_type) 298{ 299 struct vnt_phy_field phy[4]; 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]; 303 int i; 304 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]); 337 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 } 378 379 CONTROLnsRequestOut(priv, MESSAGE_TYPE_WRITE, 380 MAC_REG_RSPINF_B_1, MESSAGE_REQUEST_MACREG, 34, &data[0]); 381} 382 383/* 384 * Description: Update IFS 385 * 386 * Parameters: 387 * In: 388 * priv - The adapter to be set 389 * Out: 390 * none 391 * 392 * Return Value: None. 393 * 394 */ 395void vUpdateIFS(struct vnt_private *priv) 396{ 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); 474} 475 476void CARDvUpdateBasicTopRate(struct vnt_private *priv) 477{ 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; 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 * 513 * Return Value: true if succeeded; false if failed. 514 * 515 */ 516void CARDbAddBasicRate(struct vnt_private *priv, u16 rate_idx) 517{ 518 519 priv->wBasicRate |= (1 << rate_idx); 520 521 /*Determines the highest basic rate.*/ 522 CARDvUpdateBasicTopRate(priv); 523} 524 525int CARDbIsOFDMinBasicRate(struct vnt_private *priv) 526{ 527 int ii; 528 529 for (ii = RATE_54M; ii >= RATE_6M; ii--) { 530 if ((priv->wBasicRate) & ((u16)(1 << ii))) 531 return true; 532 } 533 534 return false; 535} 536 537u8 CARDbyGetPktType(struct vnt_private *priv) 538{ 539 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; 546} 547 548/* 549 * Description: Calculate TSF offset of two TSF input 550 * Get TSF Offset from RxBCN's TSF and local TSF 551 * 552 * Parameters: 553 * In: 554 * rx_rate - rx rate. 555 * tsf1 - Rx BCN's TSF 556 * tsf2 - Local TSF 557 * Out: 558 * none 559 * 560 * Return Value: TSF Offset value 561 * 562 */ 563u64 CARDqGetTSFOffset(u8 rx_rate, u64 tsf1, u64 tsf2) 564{ 565 u64 tsf_offset = 0; 566 u16 rx_bcn_offset = 0; 567 568 rx_bcn_offset = cwRXBCNTSFOff[rx_rate % MAX_RATE]; 569 570 tsf2 += (u64)rx_bcn_offset; 571 572 tsf_offset = tsf1 - tsf2; 573 574 return tsf_offset; 575} 576 577/* 578 * Description: Sync. TSF counter to BSS 579 * Get TSF offset and write to HW 580 * 581 * Parameters: 582 * In: 583 * priv - The adapter to be sync. 584 * time_stamp - Rx BCN's TSF 585 * local_tsf - Local TSF 586 * Out: 587 * none 588 * 589 * Return Value: none 590 * 591 */ 592void CARDvAdjustTSF(struct vnt_private *priv, u8 rx_rate, 593 u64 time_stamp, u64 local_tsf) 594{ 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); 608 609 CONTROLnsRequestOut(priv, MESSAGE_TYPE_SET_TSFTBTT, 610 MESSAGE_REQUEST_TSF, 0, 8, data); 611} 612/* 613 * Description: Read NIC TSF counter 614 * Get local TSF counter 615 * 616 * Parameters: 617 * In: 618 * priv - The adapter to be read 619 * Out: 620 * current_tsf - Current TSF counter 621 * 622 * Return Value: true if success; otherwise false 623 * 624 */ 625bool CARDbGetCurrentTSF(struct vnt_private *priv, u64 *current_tsf) 626{ 627 628 *current_tsf = priv->qwCurrTSF; 629 630 return true; 631} 632 633/* 634 * Description: Clear NIC TSF counter 635 * Clear local TSF counter 636 * 637 * Parameters: 638 * In: 639 * priv - The adapter to be read 640 * 641 * Return Value: true if success; otherwise false 642 * 643 */ 644bool CARDbClearCurrentTSF(struct vnt_private *priv) 645{ 646 647 MACvRegBitsOn(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST); 648 649 priv->qwCurrTSF = 0; 650 651 return true; 652} 653 654/* 655 * Description: Read NIC TSF counter 656 * Get NEXTTBTT from adjusted TSF and Beacon Interval 657 * 658 * Parameters: 659 * In: 660 * tsf - Current TSF counter 661 * beacon_interval - Beacon Interval 662 * Out: 663 * tsf - Current TSF counter 664 * 665 * Return Value: TSF value of next Beacon 666 * 667 */ 668u64 CARDqGetNextTBTT(u64 tsf, u16 beacon_interval) 669{ 670 u32 beacon_int; 671 672 beacon_int = beacon_interval * 1024; 673 674 /* Next TBTT = 675 * ((local_current_TSF / beacon_interval) + 1) * beacon_interval 676 */ 677 if (beacon_int) { 678 do_div(tsf, beacon_int); 679 tsf += 1; 680 tsf *= beacon_int; 681 } 682 683 return tsf; 684} 685 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 693 * beacon_interval - Beacon Interval 694 * Out: 695 * none 696 * 697 * Return Value: none 698 * 699 */ 700void CARDvSetFirstNextTBTT(struct vnt_private *priv, u16 beacon_interval) 701{ 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); 720 721 return; 722} 723 724/* 725 * Description: Sync NIC TSF counter for Beacon time 726 * Get NEXTTBTT and write to HW 727 * 728 * Parameters: 729 * In: 730 * priv - The adapter to be set 731 * tsf - Current TSF counter 732 * beacon_interval - Beacon Interval 733 * Out: 734 * none 735 * 736 * Return Value: none 737 * 738 */ 739void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 tsf, 740 u16 beacon_interval) 741{ 742 u8 data[8]; 743 744 tsf = CARDqGetNextTBTT(tsf, beacon_interval); 745 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); 754 755 CONTROLnsRequestOut(priv, MESSAGE_TYPE_SET_TSFTBTT, 756 MESSAGE_REQUEST_TBTT, 0, 8, data); 757 758 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO 759 "Card:Update Next TBTT[%8lx]\n", (unsigned long)tsf); 760 761 return; 762} 763 764/* 765 * Description: Turn off Radio power 766 * 767 * Parameters: 768 * In: 769 * priv - The adapter to be turned off 770 * Out: 771 * none 772 * 773 * Return Value: true if success; otherwise false 774 * 775 */ 776int CARDbRadioPowerOff(struct vnt_private *priv) 777{ 778 int ret = true; 779 780 priv->bRadioOff = true; 781 782 switch (priv->byRFType) { 783 case RF_AL2230: 784 case RF_AL2230S: 785 case RF_AIROHA7230: 786 case RF_VT3226: 787 case RF_VT3226D0: 788 case RF_VT3342A0: 789 MACvRegBitsOff(priv, MAC_REG_SOFTPWRCTL, 790 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); 791 break; 792 } 793 794 MACvRegBitsOff(priv, MAC_REG_HOSTCR, HOSTCR_RXON); 795 796 BBvSetDeepSleep(priv); 797 798 return ret; 799} 800 801/* 802 * Description: Turn on Radio power 803 * 804 * Parameters: 805 * In: 806 * priv - The adapter to be turned on 807 * Out: 808 * none 809 * 810 * Return Value: true if success; otherwise false 811 * 812 */ 813int CARDbRadioPowerOn(struct vnt_private *priv) 814{ 815 int ret = true; 816 817 if (priv->bHWRadioOff == true || priv->bRadioControlOff == true) 818 return false; 819 820 priv->bRadioOff = false; 821 822 BBvExitDeepSleep(priv); 823 824 MACvRegBitsOn(priv, MAC_REG_HOSTCR, HOSTCR_RXON); 825 826 switch (priv->byRFType) { 827 case RF_AL2230: 828 case RF_AL2230S: 829 case RF_AIROHA7230: 830 case RF_VT3226: 831 case RF_VT3226D0: 832 case RF_VT3342A0: 833 MACvRegBitsOn(priv, MAC_REG_SOFTPWRCTL, 834 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); 835 break; 836 } 837 838 return ret; 839} 840 841void CARDvSetBSSMode(struct vnt_private *pDevice) 842{ 843 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now 844 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA 845 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) ) 846 { 847 MACvSetBBType(pDevice, BB_TYPE_11G); 848 } 849 else 850 { 851 MACvSetBBType(pDevice, pDevice->byBBType); 852 } 853 pDevice->byPacketType = CARDbyGetPktType(pDevice); 854 855 if (pDevice->byBBType == BB_TYPE_11A) { 856 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03); 857 } else if (pDevice->byBBType == BB_TYPE_11B) { 858 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02); 859 } else if (pDevice->byBBType == BB_TYPE_11G) { 860 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x08); 861 } 862 863 vUpdateIFS(pDevice); 864 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType); 865 866 if ( pDevice->byBBType == BB_TYPE_11A ) { 867 //request by Jack 2005-04-26 868 if (pDevice->byRFType == RF_AIROHA7230) { 869 pDevice->abyBBVGA[0] = 0x20; 870 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]); 871 } 872 pDevice->abyBBVGA[2] = 0x10; 873 pDevice->abyBBVGA[3] = 0x10; 874 } else { 875 //request by Jack 2005-04-26 876 if (pDevice->byRFType == RF_AIROHA7230) { 877 pDevice->abyBBVGA[0] = 0x1C; 878 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, pDevice->abyBBVGA[0]); 879 } 880 pDevice->abyBBVGA[2] = 0x0; 881 pDevice->abyBBVGA[3] = 0x0; 882 } 883} 884