1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include "tmacro.h"
45#include "card.h"
46#include "baseband.h"
47#include "mac.h"
48#include "desc.h"
49#include "rf.h"
50#include "power.h"
51
52
53
54#define C_SIFS_A 16
55#define C_SIFS_BG 10
56
57#define C_EIFS 80
58
59#define C_SLOT_SHORT 9
60#define C_SLOT_LONG 20
61
62#define C_CWMIN_A 15
63#define C_CWMIN_B 31
64
65#define C_CWMAX 1023
66
67#define WAIT_BEACON_TX_DOWN_TMO 3
68
69
70
71static const unsigned short cwRXBCNTSFOff[MAX_RATE] = {
72 17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
73
74
75
76static
77void
78s_vCalculateOFDMRParameter(
79 unsigned char byRate,
80 u8 bb_type,
81 unsigned char *pbyTxRate,
82 unsigned char *pbyRsvTime
83);
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100static
101void
102s_vCalculateOFDMRParameter(
103 unsigned char byRate,
104 u8 bb_type,
105 unsigned char *pbyTxRate,
106 unsigned char *pbyRsvTime
107)
108{
109 switch (byRate) {
110 case RATE_6M:
111 if (bb_type == BB_TYPE_11A) {
112 *pbyTxRate = 0x9B;
113 *pbyRsvTime = 44;
114 } else {
115 *pbyTxRate = 0x8B;
116 *pbyRsvTime = 50;
117 }
118 break;
119
120 case RATE_9M:
121 if (bb_type == BB_TYPE_11A) {
122 *pbyTxRate = 0x9F;
123 *pbyRsvTime = 36;
124 } else {
125 *pbyTxRate = 0x8F;
126 *pbyRsvTime = 42;
127 }
128 break;
129
130 case RATE_12M:
131 if (bb_type == BB_TYPE_11A) {
132 *pbyTxRate = 0x9A;
133 *pbyRsvTime = 32;
134 } else {
135 *pbyTxRate = 0x8A;
136 *pbyRsvTime = 38;
137 }
138 break;
139
140 case RATE_18M:
141 if (bb_type == BB_TYPE_11A) {
142 *pbyTxRate = 0x9E;
143 *pbyRsvTime = 28;
144 } else {
145 *pbyTxRate = 0x8E;
146 *pbyRsvTime = 34;
147 }
148 break;
149
150 case RATE_36M:
151 if (bb_type == BB_TYPE_11A) {
152 *pbyTxRate = 0x9D;
153 *pbyRsvTime = 24;
154 } else {
155 *pbyTxRate = 0x8D;
156 *pbyRsvTime = 30;
157 }
158 break;
159
160 case RATE_48M:
161 if (bb_type == BB_TYPE_11A) {
162 *pbyTxRate = 0x98;
163 *pbyRsvTime = 24;
164 } else {
165 *pbyTxRate = 0x88;
166 *pbyRsvTime = 30;
167 }
168 break;
169
170 case RATE_54M:
171 if (bb_type == BB_TYPE_11A) {
172 *pbyTxRate = 0x9C;
173 *pbyRsvTime = 24;
174 } else {
175 *pbyTxRate = 0x8C;
176 *pbyRsvTime = 30;
177 }
178 break;
179
180 case RATE_24M:
181 default:
182 if (bb_type == BB_TYPE_11A) {
183 *pbyTxRate = 0x99;
184 *pbyRsvTime = 28;
185 } else {
186 *pbyTxRate = 0x89;
187 *pbyRsvTime = 34;
188 }
189 break;
190 }
191}
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
207{
208 unsigned char byCWMaxMin = 0;
209 unsigned char bySlot = 0;
210 unsigned char bySIFS = 0;
211 unsigned char byDIFS = 0;
212 unsigned char byData;
213 int i;
214
215
216 if (bb_type == BB_TYPE_11A) {
217 if (pDevice->byRFType == RF_AIROHA7230) {
218
219 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
220 pDevice->abyBBVGA[0] = 0x20;
221 pDevice->abyBBVGA[2] = 0x10;
222 pDevice->abyBBVGA[3] = 0x10;
223 BBbReadEmbedded(pDevice, 0xE7, &byData);
224 if (byData == 0x1C)
225 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
226
227 } else if (pDevice->byRFType == RF_UW2452) {
228 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
229 pDevice->abyBBVGA[0] = 0x18;
230 BBbReadEmbedded(pDevice, 0xE7, &byData);
231 if (byData == 0x14) {
232 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
233 BBbWriteEmbedded(pDevice, 0xE1, 0x57);
234 }
235 } else {
236 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
237 }
238 BBbWriteEmbedded(pDevice, 0x88, 0x03);
239 bySlot = C_SLOT_SHORT;
240 bySIFS = C_SIFS_A;
241 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
242 byCWMaxMin = 0xA4;
243 } else if (bb_type == BB_TYPE_11B) {
244 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
245 if (pDevice->byRFType == RF_AIROHA7230) {
246 pDevice->abyBBVGA[0] = 0x1C;
247 pDevice->abyBBVGA[2] = 0x00;
248 pDevice->abyBBVGA[3] = 0x00;
249 BBbReadEmbedded(pDevice, 0xE7, &byData);
250 if (byData == 0x20)
251 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
252
253 } else if (pDevice->byRFType == RF_UW2452) {
254 pDevice->abyBBVGA[0] = 0x14;
255 BBbReadEmbedded(pDevice, 0xE7, &byData);
256 if (byData == 0x18) {
257 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
258 BBbWriteEmbedded(pDevice, 0xE1, 0xD3);
259 }
260 }
261 BBbWriteEmbedded(pDevice, 0x88, 0x02);
262 bySlot = C_SLOT_LONG;
263 bySIFS = C_SIFS_BG;
264 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
265 byCWMaxMin = 0xA5;
266 } else {
267 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
268 if (pDevice->byRFType == RF_AIROHA7230) {
269 pDevice->abyBBVGA[0] = 0x1C;
270 pDevice->abyBBVGA[2] = 0x00;
271 pDevice->abyBBVGA[3] = 0x00;
272 BBbReadEmbedded(pDevice, 0xE7, &byData);
273 if (byData == 0x20)
274 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
275
276 } else if (pDevice->byRFType == RF_UW2452) {
277 pDevice->abyBBVGA[0] = 0x14;
278 BBbReadEmbedded(pDevice, 0xE7, &byData);
279 if (byData == 0x18) {
280 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
281 BBbWriteEmbedded(pDevice, 0xE1, 0xD3);
282 }
283 }
284 BBbWriteEmbedded(pDevice, 0x88, 0x08);
285 bySIFS = C_SIFS_BG;
286
287 if (pDevice->bShortSlotTime) {
288 bySlot = C_SLOT_SHORT;
289 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
290 } else {
291 bySlot = C_SLOT_LONG;
292 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
293 }
294
295 byCWMaxMin = 0xa4;
296
297 for (i = RATE_54M; i >= RATE_6M; i--) {
298 if (pDevice->basic_rates & ((u32)(0x1 << i))) {
299 byCWMaxMin |= 0x1;
300 break;
301 }
302 }
303 }
304
305 if (pDevice->byRFType == RF_RFMD2959) {
306
307
308
309
310 bySIFS -= 3;
311 byDIFS -= 3;
312
313
314
315
316
317 }
318
319 if (pDevice->bySIFS != bySIFS) {
320 pDevice->bySIFS = bySIFS;
321 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
322 }
323 if (pDevice->byDIFS != byDIFS) {
324 pDevice->byDIFS = byDIFS;
325 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
326 }
327 if (pDevice->byEIFS != C_EIFS) {
328 pDevice->byEIFS = C_EIFS;
329 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
330 }
331 if (pDevice->bySlot != bySlot) {
332 pDevice->bySlot = bySlot;
333 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
334
335 BBvSetShortSlotTime(pDevice);
336 }
337 if (pDevice->byCWMaxMin != byCWMaxMin) {
338 pDevice->byCWMaxMin = byCWMaxMin;
339 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
340 }
341
342 pDevice->byPacketType = CARDbyGetPktType(pDevice);
343
344 CARDvSetRSPINF(pDevice, bb_type);
345
346 return true;
347}
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
365 u64 qwBSSTimestamp, u64 qwLocalTSF)
366{
367 u64 qwTSFOffset = 0;
368
369 if (qwBSSTimestamp != qwLocalTSF) {
370 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
371
372 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
373 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
374 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
375 }
376 return true;
377}
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
393 unsigned short wBeaconInterval)
394{
395 u64 qwNextTBTT = 0;
396
397 CARDbGetCurrentTSF(pDevice, &qwNextTBTT);
398
399 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
400
401
402 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
403 pDevice->wBeaconInterval = wBeaconInterval;
404
405 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
406 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
407 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
408
409 return true;
410}
411
412
413
414
415
416
417
418
419
420
421
422
423bool CARDbRadioPowerOff(struct vnt_private *pDevice)
424{
425 bool bResult = true;
426
427 if (pDevice->bRadioOff == true)
428 return true;
429
430 switch (pDevice->byRFType) {
431 case RF_RFMD2959:
432 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
433 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
434 break;
435
436 case RF_AIROHA:
437 case RF_AL2230S:
438 case RF_AIROHA7230:
439 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
440 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
441 break;
442
443 }
444
445 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
446
447 BBvSetDeepSleep(pDevice, pDevice->byLocalID);
448
449 pDevice->bRadioOff = true;
450 pr_debug("chester power off\n");
451 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET);
452 return bResult;
453}
454
455
456
457
458
459
460
461
462
463
464
465
466bool CARDbRadioPowerOn(struct vnt_private *pDevice)
467{
468 bool bResult = true;
469
470 pr_debug("chester power on\n");
471 if (pDevice->bRadioControlOff == true) {
472 if (pDevice->bHWRadioOff == true)
473 pr_debug("chester bHWRadioOff\n");
474 if (pDevice->bRadioControlOff == true)
475 pr_debug("chester bRadioControlOff\n");
476 return false; }
477
478 if (pDevice->bRadioOff == false) {
479 pr_debug("chester pbRadioOff\n");
480 return true; }
481
482 BBvExitDeepSleep(pDevice, pDevice->byLocalID);
483
484 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
485
486 switch (pDevice->byRFType) {
487 case RF_RFMD2959:
488 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
489 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
490 break;
491
492 case RF_AIROHA:
493 case RF_AL2230S:
494 case RF_AIROHA7230:
495 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
496 SOFTPWRCTL_SWPE3));
497 break;
498
499 }
500
501 pDevice->bRadioOff = false;
502 pr_debug("chester power on\n");
503 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET);
504 return bResult;
505}
506
507void
508CARDvSafeResetTx(
509 struct vnt_private *pDevice
510)
511{
512 unsigned int uu;
513 PSTxDesc pCurrTD;
514
515
516 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
517 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
518
519 for (uu = 0; uu < TYPE_MAXTD; uu++)
520 pDevice->iTDUsed[uu] = 0;
521
522 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
523 pCurrTD = &(pDevice->apTD0Rings[uu]);
524 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
525
526 }
527 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
528 pCurrTD = &(pDevice->apTD1Rings[uu]);
529 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
530
531 }
532
533
534 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
535 (pDevice->td0_pool_dma));
536
537 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
538 (pDevice->td1_pool_dma));
539
540
541 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
542 (pDevice->tx_beacon_dma));
543}
544
545
546
547
548
549
550
551
552
553
554
555
556
557void
558CARDvSafeResetRx(
559 struct vnt_private *pDevice
560)
561{
562 unsigned int uu;
563 PSRxDesc pDesc;
564
565
566 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
567 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
568
569
570 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
571 pDesc = &(pDevice->aRD0Ring[uu]);
572 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
573 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
574 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
575 }
576
577
578 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
579 pDesc = &(pDevice->aRD1Ring[uu]);
580 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
581 pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
582 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
583 }
584
585
586 MACvRx0PerPktMode(pDevice->PortOffset);
587 MACvRx1PerPktMode(pDevice->PortOffset);
588
589 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
590 pDevice->rd0_pool_dma);
591
592 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
593 pDevice->rd1_pool_dma);
594}
595
596
597
598
599
600
601
602
603
604
605
606
607
608static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
609 unsigned short wRateIdx)
610{
611 unsigned int ui = (unsigned int) wRateIdx;
612
613 while (ui > RATE_1M) {
614 if (pDevice->basic_rates & ((u32)0x1 << ui))
615 return (unsigned short)ui;
616
617 ui--;
618 }
619 return (unsigned short)RATE_1M;
620}
621
622
623
624
625
626
627
628
629
630
631
632
633
634static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
635 unsigned short wRateIdx)
636{
637 unsigned int ui = (unsigned int) wRateIdx;
638
639 pr_debug("BASIC RATE: %X\n", pDevice->basic_rates);
640
641 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
642 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
643 if (wRateIdx > RATE_24M)
644 wRateIdx = RATE_24M;
645 return wRateIdx;
646 }
647 while (ui > RATE_11M) {
648 if (pDevice->basic_rates & ((u32)0x1 << ui)) {
649 pr_debug("CARDwGetOFDMControlRate : %d\n", ui);
650 return (unsigned short)ui;
651 }
652 ui--;
653 }
654 pr_debug("CARDwGetOFDMControlRate: 6M\n");
655 return (unsigned short)RATE_24M;
656}
657
658
659
660
661
662
663
664
665
666
667
668
669void CARDvSetRSPINF(struct vnt_private *pDevice, u8 bb_type)
670{
671 union vnt_phy_field_swap phy;
672 unsigned char byTxRate, byRsvTime;
673 unsigned long flags;
674
675 spin_lock_irqsave(&pDevice->lock, flags);
676
677
678 MACvSelectPage1(pDevice->PortOffset);
679
680
681 vnt_get_phy_field(pDevice, 14,
682 CARDwGetCCKControlRate(pDevice, RATE_1M),
683 PK_TYPE_11B, &phy.field_read);
684
685
686 swap(phy.swap[0], phy.swap[1]);
687
688 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
689
690
691 vnt_get_phy_field(pDevice, 14,
692 CARDwGetCCKControlRate(pDevice, RATE_2M),
693 PK_TYPE_11B, &phy.field_read);
694
695 swap(phy.swap[0], phy.swap[1]);
696
697 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
698
699
700 vnt_get_phy_field(pDevice, 14,
701 CARDwGetCCKControlRate(pDevice, RATE_5M),
702 PK_TYPE_11B, &phy.field_read);
703
704 swap(phy.swap[0], phy.swap[1]);
705
706 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
707
708
709 vnt_get_phy_field(pDevice, 14,
710 CARDwGetCCKControlRate(pDevice, RATE_11M),
711 PK_TYPE_11B, &phy.field_read);
712
713 swap(phy.swap[0], phy.swap[1]);
714
715 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
716
717
718 s_vCalculateOFDMRParameter(RATE_6M,
719 bb_type,
720 &byTxRate,
721 &byRsvTime);
722 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
723
724 s_vCalculateOFDMRParameter(RATE_9M,
725 bb_type,
726 &byTxRate,
727 &byRsvTime);
728 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
729
730 s_vCalculateOFDMRParameter(RATE_12M,
731 bb_type,
732 &byTxRate,
733 &byRsvTime);
734 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
735
736 s_vCalculateOFDMRParameter(RATE_18M,
737 bb_type,
738 &byTxRate,
739 &byRsvTime);
740 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
741
742 s_vCalculateOFDMRParameter(RATE_24M,
743 bb_type,
744 &byTxRate,
745 &byRsvTime);
746 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
747
748 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
749 bb_type,
750 &byTxRate,
751 &byRsvTime);
752 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
753
754 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
755 bb_type,
756 &byTxRate,
757 &byRsvTime);
758 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
759
760 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
761 bb_type,
762 &byTxRate,
763 &byRsvTime);
764 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
765
766 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
767 bb_type,
768 &byTxRate,
769 &byRsvTime);
770 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
771
772 MACvSelectPage0(pDevice->PortOffset);
773
774 spin_unlock_irqrestore(&pDevice->lock, flags);
775}
776
777void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
778{
779 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
780 unsigned char ii;
781
782
783 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
784 if ((pDevice->basic_rates) & ((u32)(1 << ii))) {
785 byTopOFDM = ii;
786 break;
787 }
788 }
789 pDevice->byTopOFDMBasicRate = byTopOFDM;
790
791 for (ii = RATE_11M;; ii--) {
792 if ((pDevice->basic_rates) & ((u32)(1 << ii))) {
793 byTopCCK = ii;
794 break;
795 }
796 if (ii == RATE_1M)
797 break;
798 }
799 pDevice->byTopCCKBasicRate = byTopCCK;
800}
801
802bool CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
803{
804 int ii;
805
806 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
807 if ((pDevice->basic_rates) & ((u32)(1 << ii)))
808 return true;
809 }
810 return false;
811}
812
813unsigned char CARDbyGetPktType(struct vnt_private *pDevice)
814{
815
816 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
817 return (unsigned char)pDevice->byBBType;
818 else if (CARDbIsOFDMinBasicRate((void *)pDevice))
819 return PK_TYPE_11GA;
820 else
821 return PK_TYPE_11GB;
822}
823
824
825
826
827
828
829
830
831
832
833
834
835
836void CARDvSetLoopbackMode(struct vnt_private *priv, unsigned short wLoopbackMode)
837{
838 void __iomem *dwIoBase = priv->PortOffset;
839
840 switch (wLoopbackMode) {
841 case CARD_LB_NONE:
842 case CARD_LB_MAC:
843 case CARD_LB_PHY:
844 break;
845 default:
846 ASSERT(false);
847 break;
848 }
849
850 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
851
852}
853
854
855
856
857
858
859
860
861
862
863
864
865bool CARDbSoftwareReset(struct vnt_private *pDevice)
866{
867
868
869 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
870 return false;
871
872 return true;
873}
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
890{
891 u64 qwTSFOffset = 0;
892 unsigned short wRxBcnTSFOffst = 0;
893
894 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
895
896 qwTSF2 += (u64)wRxBcnTSFOffst;
897
898 qwTSFOffset = qwTSF1 - qwTSF2;
899
900 return qwTSFOffset;
901}
902
903
904
905
906
907
908
909
910
911
912
913
914
915bool CARDbGetCurrentTSF(struct vnt_private *priv, u64 *pqwCurrTSF)
916{
917 void __iomem *dwIoBase = priv->PortOffset;
918 unsigned short ww;
919 unsigned char byData;
920
921 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
922 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
923 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
924 if (!(byData & TFTCTL_TSFCNTRRD))
925 break;
926 }
927 if (ww == W_MAX_TIMEOUT)
928 return false;
929 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
930 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
931
932 return true;
933}
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
949{
950 u32 beacon_int;
951
952 beacon_int = wBeaconInterval * 1024;
953 if (beacon_int) {
954 do_div(qwTSF, beacon_int);
955 qwTSF += 1;
956 qwTSF *= beacon_int;
957 }
958
959 return qwTSF;
960}
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975void CARDvSetFirstNextTBTT(struct vnt_private *priv, unsigned short wBeaconInterval)
976{
977 void __iomem *dwIoBase = priv->PortOffset;
978 u64 qwNextTBTT = 0;
979
980 CARDbGetCurrentTSF(priv, &qwNextTBTT);
981
982 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
983
984 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
985 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
986 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
987}
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 qwTSF, unsigned short wBeaconInterval)
1004{
1005 void __iomem *dwIoBase = priv->PortOffset;
1006
1007 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
1008
1009 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF);
1010 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
1011 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
1012 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF);
1013}
1014