card.c 16.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 * File: card.c
 * Purpose: Provide functions to setup NIC operation mode
 * Functions:
19
 *      vnt_set_rspinf - Set RSPINF
20
 *      vnt_update_ifs - Update slotTime,SIFS,DIFS, and EIFS
21
 *      vnt_update_top_rates - Update BasicTopRate
22
 *      vnt_add_basic_rate - Add to BasicRateSet
23
 *      vnt_ofdm_min_rate - Check if any OFDM rate is in BasicRateSet
24
 *      vnt_get_tsf_offset - Calculate TSFOffset
25
 *      vnt_get_current_tsf - Read Current NIC TSF counter
26
 *      vnt_get_next_tbtt - Calculate Next Beacon TSF counter
27
 *      vnt_reset_next_tbtt - Set NIC Beacon time
28
 *      vnt_update_next_tbtt - Sync. NIC Beacon time
29
 *      vnt_radio_power_off - Turn Off NIC Radio Power
30
 *      vnt_radio_power_on - Turn On NIC Radio Power
31 32 33
 *
 * Revision History:
 *      06-10-2003 Bryan YC Fan:  Re-write codes to support VT3253 spec.
34
 *      08-26-2003 Kyle Hsu:      Modify the definition type of dwIoBase.
35
 *      09-01-2003 Bryan YC Fan:  Add vnt_update_ifs().
36 37 38
 *
 */

39
#include "device.h"
40 41 42 43 44 45 46
#include "card.h"
#include "baseband.h"
#include "mac.h"
#include "desc.h"
#include "rf.h"
#include "power.h"
#include "key.h"
47
#include "usbpipe.h"
48

49
/* const u16 cw_rxbcntsf_off[MAX_RATE] =
50 51
 *   {17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3};
 */
52

53
static const u16 cw_rxbcntsf_off[MAX_RATE] = {
54 55
	192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3
};
56 57 58 59 60 61 62

/*
 * Description: Set NIC media channel
 *
 * Parameters:
 *  In:
 *      pDevice             - The adapter to be set
63
 *      connection_channel  - Channel to be set
64 65 66
 *  Out:
 *      none
 */
67
void vnt_set_channel(struct vnt_private *priv, u32 connection_channel)
68
{
69 70
	if (connection_channel > CB_MAX_CHANNEL || !connection_channel)
		return;
71

72
	/* clear NAV */
73
	vnt_mac_reg_bits_on(priv, MAC_REG_MACCR, MACCR_CLRNAV);
74 75

	/* Set Channel[7] = 0 to tell H/W channel is changing now. */
76
	vnt_mac_reg_bits_off(priv, MAC_REG_CHANNEL, 0xb0);
77

78
	vnt_control_out(priv, MESSAGE_TYPE_SELECT_CHANNEL,
79
			connection_channel, 0, 0, NULL);
80

81
	vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL,
82
			   (u8)(connection_channel | 0x80));
83 84 85 86 87 88 89
}

/*
 * Description: Get CCK mode basic rate
 *
 * Parameters:
 *  In:
90 91
 *      priv		- The adapter to be set
 *      rate_idx	- Receiving data rate
92 93 94 95 96 97
 *  Out:
 *      none
 *
 * Return Value: response Control frame rate
 *
 */
98
static u16 vnt_get_cck_rate(struct vnt_private *priv, u16 rate_idx)
99
{
100
	u16 ui = rate_idx;
101 102

	while (ui > RATE_1M) {
103
		if (priv->basic_rates & (1 << ui))
104 105 106 107 108
			return ui;
		ui--;
	}

	return RATE_1M;
109 110 111 112 113 114 115
}

/*
 * Description: Get OFDM mode basic rate
 *
 * Parameters:
 *  In:
116 117
 *      priv		- The adapter to be set
 *      rate_idx	- Receiving data rate
118 119 120 121 122 123
 *  Out:
 *      none
 *
 * Return Value: response Control frame rate
 *
 */
124
static u16 vnt_get_ofdm_rate(struct vnt_private *priv, u16 rate_idx)
125
{
126
	u16 ui = rate_idx;
127

128
	dev_dbg(&priv->usb->dev, "%s basic rate: %d\n",
129
		__func__,  priv->basic_rates);
130

131
	if (!vnt_ofdm_min_rate(priv)) {
132
		dev_dbg(&priv->usb->dev, "%s (NO OFDM) %d\n",
133
			__func__, rate_idx);
134 135 136
		if (rate_idx > RATE_24M)
			rate_idx = RATE_24M;
		return rate_idx;
137 138 139
	}

	while (ui > RATE_11M) {
140
		if (priv->basic_rates & (1 << ui)) {
141
			dev_dbg(&priv->usb->dev, "%s rate: %d\n",
142
				__func__, ui);
143 144 145 146 147
			return ui;
		}
		ui--;
	}

148
	dev_dbg(&priv->usb->dev, "%s basic rate: 24M\n", __func__);
149 150

	return RATE_24M;
151 152 153
}

/*
154
 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
155 156
 *
 * Parameters:
157 158 159 160 161 162
 * In:
 *	rate	- Tx Rate
 *	bb_type	- Tx Packet type
 * Out:
 *	tx_rate	- pointer to RSPINF TxRate field
 *	rsv_time- pointer to RSPINF RsvTime field
163 164 165 166
 *
 * Return Value: none
 *
 */
167
static void vnt_calculate_ofdm_rate(u16 rate, u8 bb_type,
168
				    u8 *tx_rate, u8 *rsv_time)
169
{
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
	switch (rate) {
	case RATE_6M:
		if (bb_type == BB_TYPE_11A) {
			*tx_rate = 0x9b;
			*rsv_time = 24;
		} else {
			*tx_rate = 0x8b;
			*rsv_time = 30;
		}
			break;
	case RATE_9M:
		if (bb_type == BB_TYPE_11A) {
			*tx_rate = 0x9f;
			*rsv_time = 16;
		} else {
			*tx_rate = 0x8f;
			*rsv_time = 22;
		}
		break;
	case RATE_12M:
		if (bb_type == BB_TYPE_11A) {
			*tx_rate = 0x9a;
			*rsv_time = 12;
		} else {
			*tx_rate = 0x8a;
			*rsv_time = 18;
		}
		break;
	case RATE_18M:
		if (bb_type == BB_TYPE_11A) {
			*tx_rate = 0x9e;
			*rsv_time = 8;
		} else {
			*tx_rate = 0x8e;
			*rsv_time = 14;
		}
		break;
	case RATE_36M:
		if (bb_type == BB_TYPE_11A) {
			*tx_rate = 0x9d;
			*rsv_time = 4;
		} else {
			*tx_rate = 0x8d;
			*rsv_time = 10;
		}
		break;
	case RATE_48M:
		if (bb_type == BB_TYPE_11A) {
			*tx_rate = 0x98;
			*rsv_time = 4;
		} else {
			*tx_rate = 0x88;
222
			*rsv_time = 10;
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
		}
		break;
	case RATE_54M:
		if (bb_type == BB_TYPE_11A) {
			*tx_rate = 0x9c;
			*rsv_time = 4;
		} else {
			*tx_rate = 0x8c;
			*rsv_time = 10;
		}
		break;
	case RATE_24M:
	default:
		if (bb_type == BB_TYPE_11A) {
			*tx_rate = 0x99;
			*rsv_time = 8;
		} else {
			*tx_rate = 0x89;
			*rsv_time = 14;
		}
		break;
	}
245 246 247 248 249 250 251 252 253 254 255 256 257 258
}

/*
 * Description: Set RSPINF
 *
 * Parameters:
 *  In:
 *      pDevice             - The adapter to be set
 *  Out:
 *      none
 *
 * Return Value: None.
 *
 */
259

260
void vnt_set_rspinf(struct vnt_private *priv, u8 bb_type)
261
{
262
	struct vnt_phy_field phy[4];
263 264 265
	u8 tx_rate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */
	u8 rsv_time[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
	u8 data[34];
266
	int i;
267

268
	/*RSPINF_b_1*/
269 270
	vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_1M),
			  PK_TYPE_11B, &phy[0]);
271 272

	/*RSPINF_b_2*/
273 274
	vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_2M),
			  PK_TYPE_11B, &phy[1]);
275 276

	/*RSPINF_b_5*/
277 278
	vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_5M),
			  PK_TYPE_11B, &phy[2]);
279 280

	/*RSPINF_b_11*/
281 282
	vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_11M),
			  PK_TYPE_11B, &phy[3]);
283 284

	/*RSPINF_a_6*/
285
	vnt_calculate_ofdm_rate(RATE_6M, bb_type, &tx_rate[0], &rsv_time[0]);
286 287

	/*RSPINF_a_9*/
288
	vnt_calculate_ofdm_rate(RATE_9M, bb_type, &tx_rate[1], &rsv_time[1]);
289 290

	/*RSPINF_a_12*/
291
	vnt_calculate_ofdm_rate(RATE_12M, bb_type, &tx_rate[2], &rsv_time[2]);
292 293

	/*RSPINF_a_18*/
294
	vnt_calculate_ofdm_rate(RATE_18M, bb_type, &tx_rate[3], &rsv_time[3]);
295

296
	/*RSPINF_a_24*/
297
	vnt_calculate_ofdm_rate(RATE_24M, bb_type, &tx_rate[4], &rsv_time[4]);
298 299

	/*RSPINF_a_36*/
300
	vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_36M),
301
				bb_type, &tx_rate[5], &rsv_time[5]);
302 303

	/*RSPINF_a_48*/
304
	vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_48M),
305
				bb_type, &tx_rate[6], &rsv_time[6]);
306 307

	/*RSPINF_a_54*/
308
	vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M),
309
				bb_type, &tx_rate[7], &rsv_time[7]);
310 311

	/*RSPINF_a_72*/
312
	vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M),
313
				bb_type, &tx_rate[8], &rsv_time[8]);
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334

	put_unaligned(phy[0].len, (u16 *)&data[0]);
	data[2] = phy[0].signal;
	data[3] = phy[0].service;

	put_unaligned(phy[1].len, (u16 *)&data[4]);
	data[6] = phy[1].signal;
	data[7] = phy[1].service;

	put_unaligned(phy[2].len, (u16 *)&data[8]);
	data[10] = phy[2].signal;
	data[11] = phy[2].service;

	put_unaligned(phy[3].len, (u16 *)&data[12]);
	data[14] = phy[3].signal;
	data[15] = phy[3].service;

	for (i = 0; i < 9; i++) {
		data[16 + i * 2] = tx_rate[i];
		data[16 + i * 2 + 1] = rsv_time[i];
	}
335

336 337
	vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_B_1,
			MESSAGE_REQUEST_MACREG, 34, &data[0]);
338 339 340 341 342 343 344
}

/*
 * Description: Update IFS
 *
 * Parameters:
 *  In:
345 346 347
 *	priv - The adapter to be set
 * Out:
 *	none
348 349 350 351
 *
 * Return Value: None.
 *
 */
352
void vnt_update_ifs(struct vnt_private *priv)
353
{
354 355 356
	u8 max_min = 0;
	u8 data[4];

357
	if (priv->packet_type == PK_TYPE_11A) {
358 359 360
		priv->slot = C_SLOT_SHORT;
		priv->sifs = C_SIFS_A;
		priv->difs = C_SIFS_A + 2 * C_SLOT_SHORT;
361
		max_min = 4;
362
	} else {
363
		priv->sifs = C_SIFS_BG;
364

365
		if (priv->short_slot_time) {
366
			priv->slot = C_SLOT_SHORT;
367 368
			max_min = 4;
		} else {
369
			priv->slot = C_SLOT_LONG;
370
			max_min = 5;
371 372
		}

373
		priv->difs = C_SIFS_BG + 2 * priv->slot;
374 375
	}

376
	priv->eifs = C_EIFS;
377

378
	switch (priv->rf_type) {
379
	case RF_VT3226D0:
380
		if (priv->bb_type != BB_TYPE_11B) {
381 382
			priv->sifs -= 1;
			priv->difs -= 1;
383 384 385 386 387
			break;
		}
	case RF_AIROHA7230:
	case RF_AL2230:
	case RF_AL2230S:
388
		if (priv->bb_type != BB_TYPE_11B)
389 390 391 392
			break;
	case RF_RFMD2959:
	case RF_VT3226:
	case RF_VT3342A0:
393 394
		priv->sifs -= 3;
		priv->difs -= 3;
395 396
		break;
	case RF_MAXIM2829:
397
		if (priv->bb_type == BB_TYPE_11A) {
398 399
			priv->sifs -= 5;
			priv->difs -= 5;
400
		} else {
401 402
			priv->sifs -= 2;
			priv->difs -= 2;
403 404 405 406 407
		}

		break;
	}

408 409 410 411
	data[0] = (u8)priv->sifs;
	data[1] = (u8)priv->difs;
	data[2] = (u8)priv->eifs;
	data[3] = (u8)priv->slot;
412

413
	vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_SIFS,
414
			MESSAGE_REQUEST_MACREG, 4, &data[0]);
415 416 417

	max_min |= 0xa0;

418
	vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_CWMAXMIN0,
419
			MESSAGE_REQUEST_MACREG, 1, &max_min);
420 421
}

422
void vnt_update_top_rates(struct vnt_private *priv)
423
{
424 425 426 427 428
	u8 top_ofdm = RATE_24M, top_cck = RATE_1M;
	u8 i;

	/*Determines the highest basic rate.*/
	for (i = RATE_54M; i >= RATE_6M; i--) {
429
		if (priv->basic_rates & (u16)(1 << i)) {
430 431 432 433 434
			top_ofdm = i;
			break;
		}
	}

435
	priv->top_ofdm_basic_rate = top_ofdm;
436 437

	for (i = RATE_11M;; i--) {
438
		if (priv->basic_rates & (u16)(1 << i)) {
439 440 441 442 443 444 445
			top_cck = i;
			break;
		}
		if (i == RATE_1M)
			break;
	}

446
	priv->top_cck_basic_rate = top_cck;
447
}
448

449
int vnt_ofdm_min_rate(struct vnt_private *priv)
450
{
451
	int ii;
452

453
	for (ii = RATE_54M; ii >= RATE_6M; ii--) {
454
		if ((priv->basic_rates) & ((u16)BIT(ii)))
455 456 457 458
			return true;
	}

	return false;
459 460
}

461
u8 vnt_get_pkt_type(struct vnt_private *priv)
462
{
463 464
	if (priv->bb_type == BB_TYPE_11A || priv->bb_type == BB_TYPE_11B)
		return (u8)priv->bb_type;
465
	else if (vnt_ofdm_min_rate(priv))
466
		return PK_TYPE_11GA;
467
	return PK_TYPE_11GB;
468 469 470
}

/*
471
 * Description: Calculate TSF offset of two TSF input
472 473 474 475
 *              Get TSF Offset from RxBCN's TSF and local TSF
 *
 * Parameters:
 *  In:
476 477 478
 *      rx_rate	- rx rate.
 *      tsf1	- Rx BCN's TSF
 *      tsf2	- Local TSF
479 480 481 482 483 484
 *  Out:
 *      none
 *
 * Return Value: TSF Offset value
 *
 */
485
u64 vnt_get_tsf_offset(u8 rx_rate, u64 tsf1, u64 tsf2)
486
{
487
	return tsf1 - tsf2 - (u64)cw_rxbcntsf_off[rx_rate % MAX_RATE];
488 489 490 491 492 493 494 495
}

/*
 * Description: Sync. TSF counter to BSS
 *              Get TSF offset and write to HW
 *
 * Parameters:
 *  In:
496 497 498
 *      priv		- The adapter to be sync.
 *      time_stamp	- Rx BCN's TSF
 *      local_tsf	- Local TSF
499 500 501 502 503 504
 *  Out:
 *      none
 *
 * Return Value: none
 *
 */
505
void vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate,
506
		    u64 time_stamp, u64 local_tsf)
507
{
508 509 510
	u64 tsf_offset = 0;
	u8 data[8];

511
	tsf_offset = vnt_get_tsf_offset(rx_rate, time_stamp, local_tsf);
512 513 514 515 516 517 518 519 520

	data[0] = (u8)tsf_offset;
	data[1] = (u8)(tsf_offset >> 8);
	data[2] = (u8)(tsf_offset >> 16);
	data[3] = (u8)(tsf_offset >> 24);
	data[4] = (u8)(tsf_offset >> 32);
	data[5] = (u8)(tsf_offset >> 40);
	data[6] = (u8)(tsf_offset >> 48);
	data[7] = (u8)(tsf_offset >> 56);
521

522
	vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
523
			MESSAGE_REQUEST_TSF, 0, 8, data);
524
}
525

526 527 528 529 530 531
/*
 * Description: Read NIC TSF counter
 *              Get local TSF counter
 *
 * Parameters:
 *  In:
532
 *	priv		- The adapter to be read
533
 *  Out:
534
 *	current_tsf	- Current TSF counter
535
 *
536
 * Return Value: true if success; otherwise false
537 538
 *
 */
539
bool vnt_get_current_tsf(struct vnt_private *priv, u64 *current_tsf)
540
{
541
	*current_tsf = priv->current_tsf;
542

543
	return true;
544 545 546 547 548 549 550 551
}

/*
 * Description: Clear NIC TSF counter
 *              Clear local TSF counter
 *
 * Parameters:
 *  In:
552
 *      priv	- The adapter to be read
553
 *
554
 * Return Value: true if success; otherwise false
555 556
 *
 */
557
bool vnt_clear_current_tsf(struct vnt_private *priv)
558
{
559
	vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
560

561
	priv->current_tsf = 0;
562

563
	return true;
564 565 566 567 568 569 570 571
}

/*
 * Description: Read NIC TSF counter
 *              Get NEXTTBTT from adjusted TSF and Beacon Interval
 *
 * Parameters:
 *  In:
572 573
 *      tsf		- Current TSF counter
 *      beacon_interval - Beacon Interval
574
 *  Out:
575
 *      tsf		- Current TSF counter
576 577 578 579
 *
 * Return Value: TSF value of next Beacon
 *
 */
580
u64 vnt_get_next_tbtt(u64 tsf, u16 beacon_interval)
581
{
582
	u32 beacon_int;
583

584
	beacon_int = beacon_interval * 1024;
585

586
	/* Next TBTT =
587 588
	 *	((local_current_TSF / beacon_interval) + 1) * beacon_interval
	 */
589 590 591 592
	if (beacon_int) {
		do_div(tsf, beacon_int);
		tsf += 1;
		tsf *= beacon_int;
593
	}
594

595
	return tsf;
596 597 598 599 600 601 602 603 604
}

/*
 * Description: Set NIC TSF counter for first Beacon time
 *              Get NEXTTBTT from adjusted TSF and Beacon Interval
 *
 * Parameters:
 *  In:
 *      dwIoBase        - IO Base
605
 *	beacon_interval - Beacon Interval
606 607 608 609 610 611
 *  Out:
 *      none
 *
 * Return Value: none
 *
 */
612
void vnt_reset_next_tbtt(struct vnt_private *priv, u16 beacon_interval)
613
{
614 615 616
	u64 next_tbtt = 0;
	u8 data[8];

617
	vnt_clear_current_tsf(priv);
618

619
	next_tbtt = vnt_get_next_tbtt(next_tbtt, beacon_interval);
620 621 622 623 624 625 626 627 628 629

	data[0] = (u8)next_tbtt;
	data[1] = (u8)(next_tbtt >> 8);
	data[2] = (u8)(next_tbtt >> 16);
	data[3] = (u8)(next_tbtt >> 24);
	data[4] = (u8)(next_tbtt >> 32);
	data[5] = (u8)(next_tbtt >> 40);
	data[6] = (u8)(next_tbtt >> 48);
	data[7] = (u8)(next_tbtt >> 56);

630
	vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
631
			MESSAGE_REQUEST_TBTT, 0, 8, data);
632 633 634 635 636 637 638 639
}

/*
 * Description: Sync NIC TSF counter for Beacon time
 *              Get NEXTTBTT and write to HW
 *
 * Parameters:
 *  In:
640 641 642
 *	priv		- The adapter to be set
 *      tsf		- Current TSF counter
 *      beacon_interval - Beacon Interval
643 644 645 646 647 648
 *  Out:
 *      none
 *
 * Return Value: none
 *
 */
649
void vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf,
650
			  u16 beacon_interval)
651
{
652
	u8 data[8];
653

654
	tsf = vnt_get_next_tbtt(tsf, beacon_interval);
655

656 657 658 659 660 661 662 663
	data[0] = (u8)tsf;
	data[1] = (u8)(tsf >> 8);
	data[2] = (u8)(tsf >> 16);
	data[3] = (u8)(tsf >> 24);
	data[4] = (u8)(tsf >> 32);
	data[5] = (u8)(tsf >> 40);
	data[6] = (u8)(tsf >> 48);
	data[7] = (u8)(tsf >> 56);
664

665
	vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT,
666
			MESSAGE_REQUEST_TBTT, 0, 8, data);
667

668
	dev_dbg(&priv->usb->dev, "%s TBTT: %8llx\n", __func__, tsf);
669 670 671 672 673 674 675
}

/*
 * Description: Turn off Radio power
 *
 * Parameters:
 *  In:
676
 *      priv         - The adapter to be turned off
677 678 679
 *  Out:
 *      none
 *
680
 * Return Value: true if success; otherwise false
681 682
 *
 */
683
int vnt_radio_power_off(struct vnt_private *priv)
684
{
685 686
	int ret = true;

687
	switch (priv->rf_type) {
688 689 690 691 692 693
	case RF_AL2230:
	case RF_AL2230S:
	case RF_AIROHA7230:
	case RF_VT3226:
	case RF_VT3226D0:
	case RF_VT3342A0:
694
		vnt_mac_reg_bits_off(priv, MAC_REG_SOFTPWRCTL,
695
				     (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
696 697
		break;
	}
698

699
	vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
700

701
	vnt_set_deep_sleep(priv);
702

703 704
	vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD);

705
	return ret;
706 707 708 709 710 711 712
}

/*
 * Description: Turn on Radio power
 *
 * Parameters:
 *  In:
713
 *      priv         - The adapter to be turned on
714 715 716
 *  Out:
 *      none
 *
717
 * Return Value: true if success; otherwise false
718 719
 *
 */
720
int vnt_radio_power_on(struct vnt_private *priv)
721
{
722
	int ret = true;
723

724
	vnt_exit_deep_sleep(priv);
725

726
	vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
727

728
	switch (priv->rf_type) {
729 730 731 732 733 734
	case RF_AL2230:
	case RF_AL2230S:
	case RF_AIROHA7230:
	case RF_VT3226:
	case RF_VT3226D0:
	case RF_VT3342A0:
735
		vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
736
				    (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
737 738
		break;
	}
739

740 741
	vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD);

742
	return ret;
743 744
}

745
void vnt_set_bss_mode(struct vnt_private *priv)
746
{
747
	if (priv->rf_type == RF_AIROHA7230 && priv->bb_type == BB_TYPE_11A)
748
		vnt_mac_set_bb_type(priv, BB_TYPE_11G);
749
	else
750
		vnt_mac_set_bb_type(priv, priv->bb_type);
751

752
	priv->packet_type = vnt_get_pkt_type(priv);
753

754
	if (priv->bb_type == BB_TYPE_11A)
755
		vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x03);
756
	else if (priv->bb_type == BB_TYPE_11B)
757
		vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x02);
758
	else if (priv->bb_type == BB_TYPE_11G)
759
		vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x08);
760

761
	vnt_update_ifs(priv);
762
	vnt_set_rspinf(priv, (u8)priv->bb_type);
763

764
	if (priv->bb_type == BB_TYPE_11A) {
765
		if (priv->rf_type == RF_AIROHA7230) {
766
			priv->bb_vga[0] = 0x20;
767

768
			vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
769
					   0xe7, priv->bb_vga[0]);
770 771
		}

772 773
		priv->bb_vga[2] = 0x10;
		priv->bb_vga[3] = 0x10;
774
	} else {
775
		if (priv->rf_type == RF_AIROHA7230) {
776
			priv->bb_vga[0] = 0x1c;
777

778
			vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG,
779
					   0xe7, priv->bb_vga[0]);
780 781
		}

782 783
		priv->bb_vga[2] = 0x0;
		priv->bb_vga[3] = 0x0;
784
	}
785

786
	vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
787
}