blob: 14034e342aa648df43a204c5b2d4eaeac7ca9ecc [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
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 *
Forest Bond5449c682009-04-25 10:30:44 -040015 * File: card.c
16 * Purpose: Provide functions to setup NIC operation mode
17 * Functions:
18 * s_vSafeResetTx - Rest Tx
19 * CARDvSetRSPINF - Set RSPINF
Forest Bond5449c682009-04-25 10:30:44 -040020 * CARDvUpdateBasicTopRate - Update BasicTopRate
21 * CARDbAddBasicRate - Add to BasicRateSet
Forest Bond5449c682009-04-25 10:30:44 -040022 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
23 * CARDvSetLoopbackMode - Set Loopback mode
24 * CARDbSoftwareReset - Sortware reset NIC
Justin P. Mattock7664ec82012-08-20 08:43:15 -070025 * CARDqGetTSFOffset - Calculate TSFOffset
Forest Bond5449c682009-04-25 10:30:44 -040026 * CARDbGetCurrentTSF - Read Current NIC TSF counter
Justin P. Mattock7664ec82012-08-20 08:43:15 -070027 * CARDqGetNextTBTT - Calculate Next Beacon TSF counter
Forest Bond5449c682009-04-25 10:30:44 -040028 * CARDvSetFirstNextTBTT - Set NIC Beacon time
29 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
30 * CARDbRadioPowerOff - Turn Off NIC Radio Power
31 * CARDbRadioPowerOn - Turn On NIC Radio Power
Forest Bond5449c682009-04-25 10:30:44 -040032 *
33 * Revision History:
34 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
Varsha Rao26f64a62016-10-15 16:02:58 +053035 * 08-26-2003 Kyle Hsu: Modify the defination type of iobase.
Forest Bond5449c682009-04-25 10:30:44 -040036 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
37 *
38 */
39
Forest Bond5449c682009-04-25 10:30:44 -040040#include "tmacro.h"
Forest Bond5449c682009-04-25 10:30:44 -040041#include "card.h"
Forest Bond5449c682009-04-25 10:30:44 -040042#include "baseband.h"
Forest Bond5449c682009-04-25 10:30:44 -040043#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040044#include "desc.h"
Forest Bond5449c682009-04-25 10:30:44 -040045#include "rf.h"
Forest Bond5449c682009-04-25 10:30:44 -040046#include "power.h"
Forest Bond5449c682009-04-25 10:30:44 -040047
48/*--------------------- Static Definitions -------------------------*/
49
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020050#define C_SIFS_A 16 /* micro sec. */
Forest Bond5449c682009-04-25 10:30:44 -040051#define C_SIFS_BG 10
52
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020053#define C_EIFS 80 /* micro sec. */
Forest Bond5449c682009-04-25 10:30:44 -040054
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020055#define C_SLOT_SHORT 9 /* micro sec. */
Forest Bond5449c682009-04-25 10:30:44 -040056#define C_SLOT_LONG 20
57
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020058#define C_CWMIN_A 15 /* slot time */
Forest Bond5449c682009-04-25 10:30:44 -040059#define C_CWMIN_B 31
60
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020061#define C_CWMAX 1023 /* slot time */
Forest Bond5449c682009-04-25 10:30:44 -040062
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +020063#define WAIT_BEACON_TX_DOWN_TMO 3 /* Times */
Forest Bond5449c682009-04-25 10:30:44 -040064
Forest Bond5449c682009-04-25 10:30:44 -040065/*--------------------- Static Variables --------------------------*/
66
Mariam Mohamed Fawzy1167ff92015-01-26 11:24:36 +020067static const unsigned short cwRXBCNTSFOff[MAX_RATE] = {
68 17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
Forest Bond5449c682009-04-25 10:30:44 -040069
Forest Bond5449c682009-04-25 10:30:44 -040070/*--------------------- Static Functions --------------------------*/
71
72static
Charles Clément6b35b7b2010-05-07 12:30:19 -070073void
Justin P. Mattock7664ec82012-08-20 08:43:15 -070074s_vCalculateOFDMRParameter(
Joe Perchesd4945f02013-03-18 10:44:40 -070075 unsigned char byRate,
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +000076 u8 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -070077 unsigned char *pbyTxRate,
78 unsigned char *pbyRsvTime
79);
Forest Bond5449c682009-04-25 10:30:44 -040080
Forest Bond5449c682009-04-25 10:30:44 -040081/*--------------------- Export Functions --------------------------*/
82
Forest Bond5449c682009-04-25 10:30:44 -040083/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -070084 * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode.
Forest Bond5449c682009-04-25 10:30:44 -040085 *
86 * Parameters:
87 * In:
88 * wRate - Tx Rate
89 * byPktType - Tx Packet type
90 * Out:
91 * pbyTxRate - pointer to RSPINF TxRate field
92 * pbyRsvTime - pointer to RSPINF RsvTime field
93 *
94 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -040095 */
96static
Charles Clément6b35b7b2010-05-07 12:30:19 -070097void
Joe Perchesd4945f02013-03-18 10:44:40 -070098s_vCalculateOFDMRParameter(
99 unsigned char byRate,
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000100 u8 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700101 unsigned char *pbyTxRate,
102 unsigned char *pbyRsvTime
103)
Forest Bond5449c682009-04-25 10:30:44 -0400104{
Joe Perchesd4945f02013-03-18 10:44:40 -0700105 switch (byRate) {
106 case RATE_6M:
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000107 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700108 *pbyTxRate = 0x9B;
109 *pbyRsvTime = 44;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700110 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700111 *pbyTxRate = 0x8B;
112 *pbyRsvTime = 50;
113 }
114 break;
Forest Bond5449c682009-04-25 10:30:44 -0400115
Joe Perchesd4945f02013-03-18 10:44:40 -0700116 case RATE_9M:
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000117 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700118 *pbyTxRate = 0x9F;
119 *pbyRsvTime = 36;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700120 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700121 *pbyTxRate = 0x8F;
122 *pbyRsvTime = 42;
123 }
124 break;
Forest Bond5449c682009-04-25 10:30:44 -0400125
Joe Perchesd4945f02013-03-18 10:44:40 -0700126 case RATE_12M:
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000127 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700128 *pbyTxRate = 0x9A;
129 *pbyRsvTime = 32;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700130 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700131 *pbyTxRate = 0x8A;
132 *pbyRsvTime = 38;
133 }
134 break;
Forest Bond5449c682009-04-25 10:30:44 -0400135
Joe Perchesd4945f02013-03-18 10:44:40 -0700136 case RATE_18M:
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000137 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700138 *pbyTxRate = 0x9E;
139 *pbyRsvTime = 28;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700140 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700141 *pbyTxRate = 0x8E;
142 *pbyRsvTime = 34;
143 }
144 break;
Forest Bond5449c682009-04-25 10:30:44 -0400145
Joe Perchesd4945f02013-03-18 10:44:40 -0700146 case RATE_36M:
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000147 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700148 *pbyTxRate = 0x9D;
149 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700150 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700151 *pbyTxRate = 0x8D;
152 *pbyRsvTime = 30;
153 }
154 break;
Forest Bond5449c682009-04-25 10:30:44 -0400155
Joe Perchesd4945f02013-03-18 10:44:40 -0700156 case RATE_48M:
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000157 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700158 *pbyTxRate = 0x98;
159 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700160 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700161 *pbyTxRate = 0x88;
162 *pbyRsvTime = 30;
163 }
164 break;
Forest Bond5449c682009-04-25 10:30:44 -0400165
Joe Perchesd4945f02013-03-18 10:44:40 -0700166 case RATE_54M:
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000167 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700168 *pbyTxRate = 0x9C;
169 *pbyRsvTime = 24;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700170 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700171 *pbyTxRate = 0x8C;
172 *pbyRsvTime = 30;
173 }
174 break;
Forest Bond5449c682009-04-25 10:30:44 -0400175
Joe Perchesd4945f02013-03-18 10:44:40 -0700176 case RATE_24M:
177 default:
Malcolm Priestleyd1ab5202014-11-07 19:06:04 +0000178 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
Joe Perchesd4945f02013-03-18 10:44:40 -0700179 *pbyTxRate = 0x99;
180 *pbyRsvTime = 28;
Joe Perches5e0cc8a2013-03-18 20:55:37 -0700181 } else {
Joe Perchesd4945f02013-03-18 10:44:40 -0700182 *pbyTxRate = 0x89;
183 *pbyRsvTime = 34;
184 }
185 break;
186 }
Forest Bond5449c682009-04-25 10:30:44 -0400187}
188
Forest Bond5449c682009-04-25 10:30:44 -0400189/*--------------------- Export Functions --------------------------*/
Forest Bond5449c682009-04-25 10:30:44 -0400190
191/*
Forest Bond5449c682009-04-25 10:30:44 -0400192 * Description: Update IFS
193 *
194 * Parameters:
195 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100196 * priv - The adapter to be set
Forest Bond5449c682009-04-25 10:30:44 -0400197 * Out:
198 * none
199 *
200 * Return Value: None.
Forest Bond5449c682009-04-25 10:30:44 -0400201 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100202bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type)
Forest Bond5449c682009-04-25 10:30:44 -0400203{
Joe Perchesd4945f02013-03-18 10:44:40 -0700204 unsigned char byCWMaxMin = 0;
205 unsigned char bySlot = 0;
206 unsigned char bySIFS = 0;
207 unsigned char byDIFS = 0;
208 unsigned char byData;
Malcolm Priestley0614a0e2014-10-29 17:43:51 +0000209 int i;
Forest Bond5449c682009-04-25 10:30:44 -0400210
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200211 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
Malcolm Priestleya558e3d2014-11-07 19:06:02 +0000212 if (bb_type == BB_TYPE_11A) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100213 if (priv->byRFType == RF_AIROHA7230) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200214 /* AL7230 use single PAPE and connect to PAPE_2.4G */
Malcolm Priestley91961242015-10-17 11:33:02 +0100215 MACvSetBBType(priv->PortOffset, BB_TYPE_11G);
216 priv->abyBBVGA[0] = 0x20;
217 priv->abyBBVGA[2] = 0x10;
218 priv->abyBBVGA[3] = 0x10;
219 BBbReadEmbedded(priv, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300220 if (byData == 0x1C)
Malcolm Priestley91961242015-10-17 11:33:02 +0100221 BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300222
Malcolm Priestley91961242015-10-17 11:33:02 +0100223 } else if (priv->byRFType == RF_UW2452) {
224 MACvSetBBType(priv->PortOffset, BB_TYPE_11A);
225 priv->abyBBVGA[0] = 0x18;
226 BBbReadEmbedded(priv, 0xE7, &byData);
Joe Perchesd4945f02013-03-18 10:44:40 -0700227 if (byData == 0x14) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100228 BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
229 BBbWriteEmbedded(priv, 0xE1, 0x57);
Joe Perchesd4945f02013-03-18 10:44:40 -0700230 }
231 } else {
Malcolm Priestley91961242015-10-17 11:33:02 +0100232 MACvSetBBType(priv->PortOffset, BB_TYPE_11A);
Joe Perchesd4945f02013-03-18 10:44:40 -0700233 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100234 BBbWriteEmbedded(priv, 0x88, 0x03);
Joe Perchesd4945f02013-03-18 10:44:40 -0700235 bySlot = C_SLOT_SHORT;
236 bySIFS = C_SIFS_A;
Burcin Akalin0cddeac2015-10-22 00:48:29 +0300237 byDIFS = C_SIFS_A + 2 * C_SLOT_SHORT;
Joe Perchesd4945f02013-03-18 10:44:40 -0700238 byCWMaxMin = 0xA4;
Malcolm Priestleya558e3d2014-11-07 19:06:02 +0000239 } else if (bb_type == BB_TYPE_11B) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100240 MACvSetBBType(priv->PortOffset, BB_TYPE_11B);
241 if (priv->byRFType == RF_AIROHA7230) {
242 priv->abyBBVGA[0] = 0x1C;
243 priv->abyBBVGA[2] = 0x00;
244 priv->abyBBVGA[3] = 0x00;
245 BBbReadEmbedded(priv, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300246 if (byData == 0x20)
Malcolm Priestley91961242015-10-17 11:33:02 +0100247 BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300248
Malcolm Priestley91961242015-10-17 11:33:02 +0100249 } else if (priv->byRFType == RF_UW2452) {
250 priv->abyBBVGA[0] = 0x14;
251 BBbReadEmbedded(priv, 0xE7, &byData);
Joe Perchesd4945f02013-03-18 10:44:40 -0700252 if (byData == 0x18) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100253 BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
254 BBbWriteEmbedded(priv, 0xE1, 0xD3);
Joe Perchesd4945f02013-03-18 10:44:40 -0700255 }
256 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100257 BBbWriteEmbedded(priv, 0x88, 0x02);
Joe Perchesd4945f02013-03-18 10:44:40 -0700258 bySlot = C_SLOT_LONG;
259 bySIFS = C_SIFS_BG;
Varsha Raof9d033c2016-10-12 10:06:46 +0530260 byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG;
Joe Perchesd4945f02013-03-18 10:44:40 -0700261 byCWMaxMin = 0xA5;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200262 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
Malcolm Priestley91961242015-10-17 11:33:02 +0100263 MACvSetBBType(priv->PortOffset, BB_TYPE_11G);
264 if (priv->byRFType == RF_AIROHA7230) {
265 priv->abyBBVGA[0] = 0x1C;
266 priv->abyBBVGA[2] = 0x00;
267 priv->abyBBVGA[3] = 0x00;
268 BBbReadEmbedded(priv, 0xE7, &byData);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300269 if (byData == 0x20)
Malcolm Priestley91961242015-10-17 11:33:02 +0100270 BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300271
Malcolm Priestley91961242015-10-17 11:33:02 +0100272 } else if (priv->byRFType == RF_UW2452) {
273 priv->abyBBVGA[0] = 0x14;
274 BBbReadEmbedded(priv, 0xE7, &byData);
Joe Perchesd4945f02013-03-18 10:44:40 -0700275 if (byData == 0x18) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100276 BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
277 BBbWriteEmbedded(priv, 0xE1, 0xD3);
Joe Perchesd4945f02013-03-18 10:44:40 -0700278 }
279 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100280 BBbWriteEmbedded(priv, 0x88, 0x08);
Joe Perchesd4945f02013-03-18 10:44:40 -0700281 bySIFS = C_SIFS_BG;
Malcolm Priestley0614a0e2014-10-29 17:43:51 +0000282
Malcolm Priestley91961242015-10-17 11:33:02 +0100283 if (priv->bShortSlotTime) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700284 bySlot = C_SLOT_SHORT;
Burcin Akalin68535a12015-10-22 15:15:39 +0300285 byDIFS = C_SIFS_BG + 2 * C_SLOT_SHORT;
Joe Perchesd4945f02013-03-18 10:44:40 -0700286 } else {
287 bySlot = C_SLOT_LONG;
Varsha Raof9d033c2016-10-12 10:06:46 +0530288 byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG;
Joe Perchesd4945f02013-03-18 10:44:40 -0700289 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300290
Malcolm Priestley0614a0e2014-10-29 17:43:51 +0000291 byCWMaxMin = 0xa4;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300292
Malcolm Priestley0614a0e2014-10-29 17:43:51 +0000293 for (i = RATE_54M; i >= RATE_6M; i--) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100294 if (priv->basic_rates & ((u32)(0x1 << i))) {
Malcolm Priestley0614a0e2014-10-29 17:43:51 +0000295 byCWMaxMin |= 0x1;
296 break;
297 }
Joe Perchesd4945f02013-03-18 10:44:40 -0700298 }
299 }
Forest Bond5449c682009-04-25 10:30:44 -0400300
Malcolm Priestley91961242015-10-17 11:33:02 +0100301 if (priv->byRFType == RF_RFMD2959) {
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200302 /*
303 * bcs TX_PE will reserve 3 us hardware's processing
304 * time here is 2 us.
305 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700306 bySIFS -= 3;
307 byDIFS -= 3;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200308 /*
309 * TX_PE will reserve 3 us for MAX2829 A mode only, it is for
310 * better TX throughput; MAC will need 2 us to process, so the
311 * SIFS, DIFS can be shorter by 2 us.
312 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700313 }
Forest Bond5449c682009-04-25 10:30:44 -0400314
Malcolm Priestley91961242015-10-17 11:33:02 +0100315 if (priv->bySIFS != bySIFS) {
316 priv->bySIFS = bySIFS;
317 VNSvOutPortB(priv->PortOffset + MAC_REG_SIFS, priv->bySIFS);
Joe Perchesd4945f02013-03-18 10:44:40 -0700318 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100319 if (priv->byDIFS != byDIFS) {
320 priv->byDIFS = byDIFS;
321 VNSvOutPortB(priv->PortOffset + MAC_REG_DIFS, priv->byDIFS);
Joe Perchesd4945f02013-03-18 10:44:40 -0700322 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100323 if (priv->byEIFS != C_EIFS) {
324 priv->byEIFS = C_EIFS;
325 VNSvOutPortB(priv->PortOffset + MAC_REG_EIFS, priv->byEIFS);
Joe Perchesd4945f02013-03-18 10:44:40 -0700326 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100327 if (priv->bySlot != bySlot) {
328 priv->bySlot = bySlot;
329 VNSvOutPortB(priv->PortOffset + MAC_REG_SLOT, priv->bySlot);
Guido Martínezbc5cf652014-04-19 16:45:00 -0300330
Malcolm Priestley91961242015-10-17 11:33:02 +0100331 BBvSetShortSlotTime(priv);
Joe Perchesd4945f02013-03-18 10:44:40 -0700332 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100333 if (priv->byCWMaxMin != byCWMaxMin) {
334 priv->byCWMaxMin = byCWMaxMin;
Kathryn Hampton5150d012016-03-15 18:16:24 -0700335 VNSvOutPortB(priv->PortOffset + MAC_REG_CWMAXMIN0,
336 priv->byCWMaxMin);
Joe Perchesd4945f02013-03-18 10:44:40 -0700337 }
Guido Martínezbc5cf652014-04-19 16:45:00 -0300338
Malcolm Priestley91961242015-10-17 11:33:02 +0100339 priv->byPacketType = CARDbyGetPktType(priv);
Malcolm Priestley61b90992014-11-06 20:02:05 +0000340
Malcolm Priestley91961242015-10-17 11:33:02 +0100341 CARDvSetRSPINF(priv, bb_type);
Malcolm Priestley0614a0e2014-10-29 17:43:51 +0000342
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700343 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400344}
345
346/*
347 * Description: Sync. TSF counter to BSS
348 * Get TSF offset and write to HW
349 *
350 * Parameters:
351 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100352 * priv - The adapter to be sync.
Forest Bond5449c682009-04-25 10:30:44 -0400353 * byRxRate - data rate of receive beacon
354 * qwBSSTimestamp - Rx BCN's TSF
355 * qwLocalTSF - Local TSF
356 * Out:
357 * none
358 *
359 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -0400360 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100361bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate,
Malcolm Priestley032ed342015-04-21 22:33:01 +0100362 u64 qwBSSTimestamp)
Forest Bond5449c682009-04-25 10:30:44 -0400363{
Malcolm Priestley032ed342015-04-21 22:33:01 +0100364 u64 local_tsf;
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100365 u64 qwTSFOffset = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400366
Malcolm Priestley91961242015-10-17 11:33:02 +0100367 CARDbGetCurrentTSF(priv, &local_tsf);
Malcolm Priestley032ed342015-04-21 22:33:01 +0100368
369 if (qwBSSTimestamp != local_tsf) {
370 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp,
371 local_tsf);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200372 /* adjust TSF, HW's TSF add TSF Offset reg */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700373 VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST,
374 (u32)qwTSFOffset);
375 VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST + 4,
376 (u32)(qwTSFOffset >> 32));
377 MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL,
378 TFTCTL_TSFSYNCEN);
Joe Perchesd4945f02013-03-18 10:44:40 -0700379 }
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700380 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400381}
382
Forest Bond5449c682009-04-25 10:30:44 -0400383/*
384 * Description: Set NIC TSF counter for first Beacon time
385 * Get NEXTTBTT from adjusted TSF and Beacon Interval
386 *
387 * Parameters:
388 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100389 * priv - The adapter to be set.
Forest Bond5449c682009-04-25 10:30:44 -0400390 * wBeaconInterval - Beacon Interval
391 * Out:
392 * none
393 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200394 * Return Value: true if succeed; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400395 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100396bool CARDbSetBeaconPeriod(struct vnt_private *priv,
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100397 unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -0400398{
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100399 u64 qwNextTBTT = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400400
Malcolm Priestley91961242015-10-17 11:33:02 +0100401 CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */
Forest Bond5449c682009-04-25 10:30:44 -0400402
Malcolm Priestley4a5f7182014-08-10 12:22:00 +0100403 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
Forest Bond5449c682009-04-25 10:30:44 -0400404
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200405 /* set HW beacon interval */
Malcolm Priestley91961242015-10-17 11:33:02 +0100406 VNSvOutPortW(priv->PortOffset + MAC_REG_BI, wBeaconInterval);
407 priv->wBeaconInterval = wBeaconInterval;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200408 /* Set NextTBTT */
Malcolm Priestley91961242015-10-17 11:33:02 +0100409 VNSvOutPortD(priv->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700410 VNSvOutPortD(priv->PortOffset + MAC_REG_NEXTTBTT + 4,
411 (u32)(qwNextTBTT >> 32));
Malcolm Priestley91961242015-10-17 11:33:02 +0100412 MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Forest Bond5449c682009-04-25 10:30:44 -0400413
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700414 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400415}
416
Forest Bond5449c682009-04-25 10:30:44 -0400417/*
Forest Bond5449c682009-04-25 10:30:44 -0400418 * Description: Turn off Radio power
419 *
420 * Parameters:
421 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100422 * priv - The adapter to be turned off
Forest Bond5449c682009-04-25 10:30:44 -0400423 * Out:
424 * none
425 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200426 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400427 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100428bool CARDbRadioPowerOff(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400429{
Joe Perchesd4945f02013-03-18 10:44:40 -0700430 bool bResult = true;
Forest Bond5449c682009-04-25 10:30:44 -0400431
Malcolm Priestley91961242015-10-17 11:33:02 +0100432 if (priv->bRadioOff)
Joe Perchesd4945f02013-03-18 10:44:40 -0700433 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400434
Malcolm Priestley91961242015-10-17 11:33:02 +0100435 switch (priv->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700436 case RF_RFMD2959:
Kathryn Hampton5150d012016-03-15 18:16:24 -0700437 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
438 SOFTPWRCTL_TXPEINV);
439 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
440 SOFTPWRCTL_SWPE1);
Joe Perchesd4945f02013-03-18 10:44:40 -0700441 break;
Forest Bond5449c682009-04-25 10:30:44 -0400442
Joe Perchesd4945f02013-03-18 10:44:40 -0700443 case RF_AIROHA:
444 case RF_AL2230S:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200445 case RF_AIROHA7230:
Kathryn Hampton5150d012016-03-15 18:16:24 -0700446 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
447 SOFTPWRCTL_SWPE2);
448 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
449 SOFTPWRCTL_SWPE3);
Joe Perchesd4945f02013-03-18 10:44:40 -0700450 break;
Joe Perchesd4945f02013-03-18 10:44:40 -0700451 }
Forest Bond5449c682009-04-25 10:30:44 -0400452
Malcolm Priestley91961242015-10-17 11:33:02 +0100453 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400454
Malcolm Priestley91961242015-10-17 11:33:02 +0100455 BBvSetDeepSleep(priv, priv->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400456
Malcolm Priestley91961242015-10-17 11:33:02 +0100457 priv->bRadioOff = true;
Guillaume Clement941ead92014-07-25 01:06:21 +0200458 pr_debug("chester power off\n");
Kathryn Hampton5150d012016-03-15 18:16:24 -0700459 MACvRegBitsOn(priv->PortOffset, MAC_REG_GPIOCTL0,
460 LED_ACTSET); /* LED issue */
Joe Perchesd4945f02013-03-18 10:44:40 -0700461 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400462}
463
Forest Bond5449c682009-04-25 10:30:44 -0400464/*
465 * Description: Turn on Radio power
466 *
467 * Parameters:
468 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100469 * priv - The adapter to be turned on
Forest Bond5449c682009-04-25 10:30:44 -0400470 * Out:
471 * none
472 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200473 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400474 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100475bool CARDbRadioPowerOn(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400476{
Joe Perchesd4945f02013-03-18 10:44:40 -0700477 bool bResult = true;
Igor Bezukhf9dc1a82014-07-16 10:45:30 +0300478
Guillaume Clement941ead92014-07-25 01:06:21 +0200479 pr_debug("chester power on\n");
Malcolm Priestley91961242015-10-17 11:33:02 +0100480 if (priv->bRadioControlOff) {
481 if (priv->bHWRadioOff)
Guillaume Clementa1613422014-07-25 01:06:22 +0200482 pr_debug("chester bHWRadioOff\n");
Malcolm Priestley91961242015-10-17 11:33:02 +0100483 if (priv->bRadioControlOff)
Guillaume Clementa1613422014-07-25 01:06:22 +0200484 pr_debug("chester bRadioControlOff\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700485 return false; }
Forest Bond5449c682009-04-25 10:30:44 -0400486
Malcolm Priestley91961242015-10-17 11:33:02 +0100487 if (!priv->bRadioOff) {
Guillaume Clement941ead92014-07-25 01:06:21 +0200488 pr_debug("chester pbRadioOff\n");
Joe Perchesd4945f02013-03-18 10:44:40 -0700489 return true; }
Forest Bond5449c682009-04-25 10:30:44 -0400490
Malcolm Priestley91961242015-10-17 11:33:02 +0100491 BBvExitDeepSleep(priv, priv->byLocalID);
Forest Bond5449c682009-04-25 10:30:44 -0400492
Malcolm Priestley91961242015-10-17 11:33:02 +0100493 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
Forest Bond5449c682009-04-25 10:30:44 -0400494
Malcolm Priestley91961242015-10-17 11:33:02 +0100495 switch (priv->byRFType) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700496 case RF_RFMD2959:
Kathryn Hampton5150d012016-03-15 18:16:24 -0700497 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
498 SOFTPWRCTL_TXPEINV);
499 MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL,
500 SOFTPWRCTL_SWPE1);
Joe Perchesd4945f02013-03-18 10:44:40 -0700501 break;
Forest Bond5449c682009-04-25 10:30:44 -0400502
Joe Perchesd4945f02013-03-18 10:44:40 -0700503 case RF_AIROHA:
504 case RF_AL2230S:
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200505 case RF_AIROHA7230:
Kathryn Hampton5150d012016-03-15 18:16:24 -0700506 MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL,
507 (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
Joe Perchesd4945f02013-03-18 10:44:40 -0700508 break;
Joe Perchesd4945f02013-03-18 10:44:40 -0700509 }
Forest Bond5449c682009-04-25 10:30:44 -0400510
Malcolm Priestley91961242015-10-17 11:33:02 +0100511 priv->bRadioOff = false;
Guillaume Clement941ead92014-07-25 01:06:21 +0200512 pr_debug("chester power on\n");
Kathryn Hampton5150d012016-03-15 18:16:24 -0700513 MACvRegBitsOff(priv->PortOffset, MAC_REG_GPIOCTL0,
514 LED_ACTSET); /* LED issue */
Joe Perchesd4945f02013-03-18 10:44:40 -0700515 return bResult;
Forest Bond5449c682009-04-25 10:30:44 -0400516}
517
Charles Clément6b35b7b2010-05-07 12:30:19 -0700518void
Joe Perchesd4945f02013-03-18 10:44:40 -0700519CARDvSafeResetTx(
Malcolm Priestley91961242015-10-17 11:33:02 +0100520 struct vnt_private *priv
Joe Perchesd4945f02013-03-18 10:44:40 -0700521)
Forest Bond5449c682009-04-25 10:30:44 -0400522{
Joe Perchesd4945f02013-03-18 10:44:40 -0700523 unsigned int uu;
Malcolm Priestleye2357272015-08-14 22:58:51 +0100524 struct vnt_tx_desc *pCurrTD;
Forest Bond5449c682009-04-25 10:30:44 -0400525
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200526 /* initialize TD index */
Sreya Mittal6c9769c2017-03-05 17:42:28 +0530527 priv->apTailTD[0] = &priv->apTD0Rings[0];
528 priv->apCurrTD[0] = &priv->apTD0Rings[0];
Nick Rosbrookffbad992016-11-01 21:15:07 -0400529
Sreya Mittal6c9769c2017-03-05 17:42:28 +0530530 priv->apTailTD[1] = &priv->apTD1Rings[0];
531 priv->apCurrTD[1] = &priv->apTD1Rings[0];
Forest Bond5449c682009-04-25 10:30:44 -0400532
Joe Perchesd4945f02013-03-18 10:44:40 -0700533 for (uu = 0; uu < TYPE_MAXTD; uu++)
Malcolm Priestley91961242015-10-17 11:33:02 +0100534 priv->iTDUsed[uu] = 0;
Forest Bond5449c682009-04-25 10:30:44 -0400535
Malcolm Priestley91961242015-10-17 11:33:02 +0100536 for (uu = 0; uu < priv->opts.tx_descs[0]; uu++) {
Sreya Mittal6c9769c2017-03-05 17:42:28 +0530537 pCurrTD = &priv->apTD0Rings[uu];
Malcolm Priestley5235ff62015-08-14 22:58:46 +0100538 pCurrTD->td0.owner = OWNED_BY_HOST;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200539 /* init all Tx Packet pointer to NULL */
Joe Perchesd4945f02013-03-18 10:44:40 -0700540 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100541 for (uu = 0; uu < priv->opts.tx_descs[1]; uu++) {
Sreya Mittal6c9769c2017-03-05 17:42:28 +0530542 pCurrTD = &priv->apTD1Rings[uu];
Malcolm Priestley5235ff62015-08-14 22:58:46 +0100543 pCurrTD->td0.owner = OWNED_BY_HOST;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200544 /* init all Tx Packet pointer to NULL */
Joe Perchesd4945f02013-03-18 10:44:40 -0700545 }
Forest Bond5449c682009-04-25 10:30:44 -0400546
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200547 /* set MAC TD pointer */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000548 MACvSetCurrTXDescAddr(TYPE_TXDMA0, priv, priv->td0_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -0400549
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000550 MACvSetCurrTXDescAddr(TYPE_AC0DMA, priv, priv->td1_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -0400551
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200552 /* set MAC Beacon TX pointer */
Malcolm Priestley91961242015-10-17 11:33:02 +0100553 MACvSetCurrBCNTxDescAddr(priv->PortOffset,
554 (priv->tx_beacon_dma));
Forest Bond5449c682009-04-25 10:30:44 -0400555}
556
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200557/*
Forest Bond5449c682009-04-25 10:30:44 -0400558 * Description:
559 * Reset Rx
560 *
561 * Parameters:
562 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100563 * priv - Pointer to the adapter
Forest Bond5449c682009-04-25 10:30:44 -0400564 * Out:
565 * none
566 *
567 * Return Value: none
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200568 */
Charles Clément6b35b7b2010-05-07 12:30:19 -0700569void
Joe Perchesd4945f02013-03-18 10:44:40 -0700570CARDvSafeResetRx(
Malcolm Priestley91961242015-10-17 11:33:02 +0100571 struct vnt_private *priv
Joe Perchesd4945f02013-03-18 10:44:40 -0700572)
Forest Bond5449c682009-04-25 10:30:44 -0400573{
Joe Perchesd4945f02013-03-18 10:44:40 -0700574 unsigned int uu;
Malcolm Priestley9cb693f2015-08-15 21:57:35 +0100575 struct vnt_rx_desc *pDesc;
Forest Bond5449c682009-04-25 10:30:44 -0400576
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200577 /* initialize RD index */
Sreya Mittal6c9769c2017-03-05 17:42:28 +0530578 priv->pCurrRD[0] = &priv->aRD0Ring[0];
579 priv->pCurrRD[1] = &priv->aRD1Ring[0];
Forest Bond5449c682009-04-25 10:30:44 -0400580
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200581 /* init state, all RD is chip's */
Malcolm Priestley91961242015-10-17 11:33:02 +0100582 for (uu = 0; uu < priv->opts.rx_descs0; uu++) {
Sreya Mittal6c9769c2017-03-05 17:42:28 +0530583 pDesc = &priv->aRD0Ring[uu];
Malcolm Priestley91961242015-10-17 11:33:02 +0100584 pDesc->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
Malcolm Priestleyde1c1862015-08-15 21:57:32 +0100585 pDesc->rd0.owner = OWNED_BY_NIC;
Malcolm Priestley91961242015-10-17 11:33:02 +0100586 pDesc->rd1.req_count = cpu_to_le16(priv->rx_buf_sz);
Joe Perchesd4945f02013-03-18 10:44:40 -0700587 }
Forest Bond5449c682009-04-25 10:30:44 -0400588
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200589 /* init state, all RD is chip's */
Malcolm Priestley91961242015-10-17 11:33:02 +0100590 for (uu = 0; uu < priv->opts.rx_descs1; uu++) {
Sreya Mittal6c9769c2017-03-05 17:42:28 +0530591 pDesc = &priv->aRD1Ring[uu];
Malcolm Priestley91961242015-10-17 11:33:02 +0100592 pDesc->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
Malcolm Priestleyde1c1862015-08-15 21:57:32 +0100593 pDesc->rd0.owner = OWNED_BY_NIC;
Malcolm Priestley91961242015-10-17 11:33:02 +0100594 pDesc->rd1.req_count = cpu_to_le16(priv->rx_buf_sz);
Joe Perchesd4945f02013-03-18 10:44:40 -0700595 }
Forest Bond5449c682009-04-25 10:30:44 -0400596
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200597 /* set perPkt mode */
Malcolm Priestley91961242015-10-17 11:33:02 +0100598 MACvRx0PerPktMode(priv->PortOffset);
599 MACvRx1PerPktMode(priv->PortOffset);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200600 /* set MAC RD pointer */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000601 MACvSetCurrRx0DescAddr(priv, priv->rd0_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -0400602
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000603 MACvSetCurrRx1DescAddr(priv, priv->rd1_pool_dma);
Forest Bond5449c682009-04-25 10:30:44 -0400604}
605
Forest Bond5449c682009-04-25 10:30:44 -0400606/*
607 * Description: Get response Control frame rate in CCK mode
608 *
609 * Parameters:
610 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100611 * priv - The adapter to be set
Forest Bond5449c682009-04-25 10:30:44 -0400612 * wRateIdx - Receiving data rate
613 * Out:
614 * none
615 *
616 * Return Value: response Control frame rate
Forest Bond5449c682009-04-25 10:30:44 -0400617 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100618static unsigned short CARDwGetCCKControlRate(struct vnt_private *priv,
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100619 unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -0400620{
Sandhya Bankar58d44742016-09-19 17:47:21 +0530621 unsigned int ui = (unsigned int)wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -0400622
Joe Perchesd4945f02013-03-18 10:44:40 -0700623 while (ui > RATE_1M) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100624 if (priv->basic_rates & ((u32)0x1 << ui))
Joe Perchesd4945f02013-03-18 10:44:40 -0700625 return (unsigned short)ui;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300626
Joe Perchesd4945f02013-03-18 10:44:40 -0700627 ui--;
628 }
629 return (unsigned short)RATE_1M;
Forest Bond5449c682009-04-25 10:30:44 -0400630}
631
632/*
633 * Description: Get response Control frame rate in OFDM mode
634 *
635 * Parameters:
636 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100637 * priv - The adapter to be set
Forest Bond5449c682009-04-25 10:30:44 -0400638 * wRateIdx - Receiving data rate
639 * Out:
640 * none
641 *
642 * Return Value: response Control frame rate
Forest Bond5449c682009-04-25 10:30:44 -0400643 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100644static unsigned short CARDwGetOFDMControlRate(struct vnt_private *priv,
Malcolm Priestleyd0522702014-08-10 15:46:57 +0100645 unsigned short wRateIdx)
Forest Bond5449c682009-04-25 10:30:44 -0400646{
Sandhya Bankar58d44742016-09-19 17:47:21 +0530647 unsigned int ui = (unsigned int)wRateIdx;
Forest Bond5449c682009-04-25 10:30:44 -0400648
Malcolm Priestley91961242015-10-17 11:33:02 +0100649 pr_debug("BASIC RATE: %X\n", priv->basic_rates);
Forest Bond5449c682009-04-25 10:30:44 -0400650
Malcolm Priestley91961242015-10-17 11:33:02 +0100651 if (!CARDbIsOFDMinBasicRate((void *)priv)) {
Simo Koskinen6f675262017-07-17 14:59:05 +0200652 pr_debug("%s:(NO OFDM) %d\n", __func__, wRateIdx);
Joe Perchesd4945f02013-03-18 10:44:40 -0700653 if (wRateIdx > RATE_24M)
654 wRateIdx = RATE_24M;
655 return wRateIdx;
656 }
657 while (ui > RATE_11M) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100658 if (priv->basic_rates & ((u32)0x1 << ui)) {
Simo Koskinen6f675262017-07-17 14:59:05 +0200659 pr_debug("%s : %d\n", __func__, ui);
Joe Perchesd4945f02013-03-18 10:44:40 -0700660 return (unsigned short)ui;
661 }
662 ui--;
663 }
Simo Koskinen6f675262017-07-17 14:59:05 +0200664 pr_debug("%s: 6M\n", __func__);
Joe Perchesd4945f02013-03-18 10:44:40 -0700665 return (unsigned short)RATE_24M;
Forest Bond5449c682009-04-25 10:30:44 -0400666}
667
Forest Bond5449c682009-04-25 10:30:44 -0400668/*
669 * Description: Set RSPINF
670 *
671 * Parameters:
672 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100673 * priv - The adapter to be set
Forest Bond5449c682009-04-25 10:30:44 -0400674 * Out:
675 * none
676 *
677 * Return Value: None.
Forest Bond5449c682009-04-25 10:30:44 -0400678 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100679void CARDvSetRSPINF(struct vnt_private *priv, u8 bb_type)
Forest Bond5449c682009-04-25 10:30:44 -0400680{
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100681 union vnt_phy_field_swap phy;
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200682 unsigned char byTxRate, byRsvTime; /* For OFDM */
Malcolm Priestley95775d12015-01-11 10:26:12 +0000683 unsigned long flags;
684
Malcolm Priestley91961242015-10-17 11:33:02 +0100685 spin_lock_irqsave(&priv->lock, flags);
Forest Bond5449c682009-04-25 10:30:44 -0400686
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200687 /* Set to Page1 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100688 MACvSelectPage1(priv->PortOffset);
Forest Bond5449c682009-04-25 10:30:44 -0400689
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100690 /* RSPINF_b_1 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100691 vnt_get_phy_field(priv, 14,
692 CARDwGetCCKControlRate(priv, RATE_1M),
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100693 PK_TYPE_11B, &phy.field_read);
Forest Bond5449c682009-04-25 10:30:44 -0400694
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100695 /* swap over to get correct write order */
696 swap(phy.swap[0], phy.swap[1]);
Forest Bond5449c682009-04-25 10:30:44 -0400697
Malcolm Priestley91961242015-10-17 11:33:02 +0100698 VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
Forest Bond5449c682009-04-25 10:30:44 -0400699
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100700 /* RSPINF_b_2 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100701 vnt_get_phy_field(priv, 14,
702 CARDwGetCCKControlRate(priv, RATE_2M),
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100703 PK_TYPE_11B, &phy.field_read);
Forest Bond5449c682009-04-25 10:30:44 -0400704
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100705 swap(phy.swap[0], phy.swap[1]);
706
Malcolm Priestley91961242015-10-17 11:33:02 +0100707 VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100708
709 /* RSPINF_b_5 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100710 vnt_get_phy_field(priv, 14,
711 CARDwGetCCKControlRate(priv, RATE_5M),
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100712 PK_TYPE_11B, &phy.field_read);
713
714 swap(phy.swap[0], phy.swap[1]);
715
Malcolm Priestley91961242015-10-17 11:33:02 +0100716 VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100717
718 /* RSPINF_b_11 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100719 vnt_get_phy_field(priv, 14,
720 CARDwGetCCKControlRate(priv, RATE_11M),
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100721 PK_TYPE_11B, &phy.field_read);
722
723 swap(phy.swap[0], phy.swap[1]);
724
Malcolm Priestley91961242015-10-17 11:33:02 +0100725 VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
Malcolm Priestley864a5a32014-08-20 22:30:30 +0100726
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200727 /* RSPINF_a_6 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700728 s_vCalculateOFDMRParameter(RATE_6M,
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000729 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700730 &byTxRate,
731 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700732 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_6,
733 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200734 /* RSPINF_a_9 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700735 s_vCalculateOFDMRParameter(RATE_9M,
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000736 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700737 &byTxRate,
738 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700739 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_9,
740 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200741 /* RSPINF_a_12 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700742 s_vCalculateOFDMRParameter(RATE_12M,
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000743 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700744 &byTxRate,
745 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700746 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_12,
747 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200748 /* RSPINF_a_18 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700749 s_vCalculateOFDMRParameter(RATE_18M,
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000750 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700751 &byTxRate,
752 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700753 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_18,
754 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200755 /* RSPINF_a_24 */
Joe Perchesd4945f02013-03-18 10:44:40 -0700756 s_vCalculateOFDMRParameter(RATE_24M,
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000757 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700758 &byTxRate,
759 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700760 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_24,
761 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200762 /* RSPINF_a_36 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700763 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
764 (void *)priv,
765 RATE_36M),
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000766 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700767 &byTxRate,
768 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700769 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_36,
770 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200771 /* RSPINF_a_48 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700772 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
773 (void *)priv,
774 RATE_48M),
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000775 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700776 &byTxRate,
777 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700778 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_48,
779 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200780 /* RSPINF_a_54 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700781 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
782 (void *)priv,
783 RATE_54M),
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000784 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700785 &byTxRate,
786 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700787 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_54,
788 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200789 /* RSPINF_a_72 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700790 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate(
791 (void *)priv,
792 RATE_54M),
Malcolm Priestley6e1d14a2014-11-07 19:06:03 +0000793 bb_type,
Joe Perchesd4945f02013-03-18 10:44:40 -0700794 &byTxRate,
795 &byRsvTime);
Kathryn Hampton5150d012016-03-15 18:16:24 -0700796 VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_72,
797 MAKEWORD(byTxRate, byRsvTime));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200798 /* Set to Page0 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100799 MACvSelectPage0(priv->PortOffset);
Malcolm Priestley95775d12015-01-11 10:26:12 +0000800
Malcolm Priestley91961242015-10-17 11:33:02 +0100801 spin_unlock_irqrestore(&priv->lock, flags);
Forest Bond5449c682009-04-25 10:30:44 -0400802}
803
Malcolm Priestley91961242015-10-17 11:33:02 +0100804void CARDvUpdateBasicTopRate(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400805{
Joe Perchesd4945f02013-03-18 10:44:40 -0700806 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
807 unsigned char ii;
Forest Bond5449c682009-04-25 10:30:44 -0400808
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200809 /* Determines the highest basic rate. */
Joe Perchesd4945f02013-03-18 10:44:40 -0700810 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100811 if ((priv->basic_rates) & ((u32)(1 << ii))) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700812 byTopOFDM = ii;
813 break;
814 }
815 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100816 priv->byTopOFDMBasicRate = byTopOFDM;
Forest Bond5449c682009-04-25 10:30:44 -0400817
Joe Perchesd4945f02013-03-18 10:44:40 -0700818 for (ii = RATE_11M;; ii--) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100819 if ((priv->basic_rates) & ((u32)(1 << ii))) {
Joe Perchesd4945f02013-03-18 10:44:40 -0700820 byTopCCK = ii;
821 break;
822 }
823 if (ii == RATE_1M)
824 break;
825 }
Malcolm Priestley91961242015-10-17 11:33:02 +0100826 priv->byTopCCKBasicRate = byTopCCK;
Forest Bond5449c682009-04-25 10:30:44 -0400827}
828
Malcolm Priestley91961242015-10-17 11:33:02 +0100829bool CARDbIsOFDMinBasicRate(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400830{
Joe Perchesd4945f02013-03-18 10:44:40 -0700831 int ii;
Forest Bond5449c682009-04-25 10:30:44 -0400832
Joe Perchesd4945f02013-03-18 10:44:40 -0700833 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
Malcolm Priestley91961242015-10-17 11:33:02 +0100834 if ((priv->basic_rates) & ((u32)BIT(ii)))
Joe Perchesd4945f02013-03-18 10:44:40 -0700835 return true;
836 }
837 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400838}
839
Malcolm Priestley91961242015-10-17 11:33:02 +0100840unsigned char CARDbyGetPktType(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400841{
Malcolm Priestley91961242015-10-17 11:33:02 +0100842 if (priv->byBBType == BB_TYPE_11A || priv->byBBType == BB_TYPE_11B)
843 return (unsigned char)priv->byBBType;
844 else if (CARDbIsOFDMinBasicRate((void *)priv))
Joe Perchesd4945f02013-03-18 10:44:40 -0700845 return PK_TYPE_11GA;
Guido Martínezbc5cf652014-04-19 16:45:00 -0300846 else
Joe Perchesd4945f02013-03-18 10:44:40 -0700847 return PK_TYPE_11GB;
Forest Bond5449c682009-04-25 10:30:44 -0400848}
849
850/*
851 * Description: Set NIC Loopback mode
852 *
853 * Parameters:
854 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100855 * priv - The adapter to be set
Forest Bond5449c682009-04-25 10:30:44 -0400856 * wLoopbackMode - Loopback mode to be set
857 * Out:
858 * none
859 *
860 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -0400861 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700862void CARDvSetLoopbackMode(struct vnt_private *priv,
863 unsigned short wLoopbackMode)
Forest Bond5449c682009-04-25 10:30:44 -0400864{
Joe Perchesd4945f02013-03-18 10:44:40 -0700865 switch (wLoopbackMode) {
866 case CARD_LB_NONE:
867 case CARD_LB_MAC:
868 case CARD_LB_PHY:
869 break;
870 default:
Joe Perchesd4945f02013-03-18 10:44:40 -0700871 break;
872 }
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200873 /* set MAC loopback */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000874 MACvSetLoopbackMode(priv, LOBYTE(wLoopbackMode));
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200875 /* set Baseband loopback */
Forest Bond5449c682009-04-25 10:30:44 -0400876}
877
Forest Bond5449c682009-04-25 10:30:44 -0400878/*
879 * Description: Software Reset NIC
880 *
881 * Parameters:
882 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100883 * priv - The adapter to be reset
Forest Bond5449c682009-04-25 10:30:44 -0400884 * Out:
885 * none
886 *
887 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -0400888 */
Malcolm Priestley91961242015-10-17 11:33:02 +0100889bool CARDbSoftwareReset(struct vnt_private *priv)
Forest Bond5449c682009-04-25 10:30:44 -0400890{
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +0200891 /* reset MAC */
Malcolm Priestleyf9f853a2015-11-22 09:07:22 +0000892 if (!MACbSafeSoftwareReset(priv))
Joe Perchesd4945f02013-03-18 10:44:40 -0700893 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400894
Joe Perchesd4945f02013-03-18 10:44:40 -0700895 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400896}
897
Forest Bond5449c682009-04-25 10:30:44 -0400898/*
Justin P. Mattock7664ec82012-08-20 08:43:15 -0700899 * Description: Calculate TSF offset of two TSF input
Forest Bond5449c682009-04-25 10:30:44 -0400900 * Get TSF Offset from RxBCN's TSF and local TSF
901 *
902 * Parameters:
903 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100904 * priv - The adapter to be sync.
Forest Bond5449c682009-04-25 10:30:44 -0400905 * qwTSF1 - Rx BCN's TSF
906 * qwTSF2 - Local TSF
907 * Out:
908 * none
909 *
910 * Return Value: TSF Offset value
Forest Bond5449c682009-04-25 10:30:44 -0400911 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100912u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
Forest Bond5449c682009-04-25 10:30:44 -0400913{
Amitoj Kaur Chawla5309c5b2015-10-15 13:45:39 +0530914 unsigned short wRxBcnTSFOffst;
Forest Bond5449c682009-04-25 10:30:44 -0400915
Marko Stankovic5b5d6362017-05-20 18:50:37 +0200916 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE];
Guido Martínezbc5cf652014-04-19 16:45:00 -0300917
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100918 qwTSF2 += (u64)wRxBcnTSFOffst;
919
simran singhal57ce4df2017-02-19 02:52:07 +0530920 return qwTSF1 - qwTSF2;
Forest Bond5449c682009-04-25 10:30:44 -0400921}
922
Forest Bond5449c682009-04-25 10:30:44 -0400923/*
924 * Description: Read NIC TSF counter
925 * Get local TSF counter
926 *
927 * Parameters:
928 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +0100929 * priv - The adapter to be read
Forest Bond5449c682009-04-25 10:30:44 -0400930 * Out:
931 * qwCurrTSF - Current TSF counter
932 *
Charles Clément5a5a2a62010-08-01 17:15:49 +0200933 * Return Value: true if success; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -0400934 */
Malcolm Priestley738487f2014-11-12 21:11:09 +0000935bool CARDbGetCurrentTSF(struct vnt_private *priv, u64 *pqwCurrTSF)
Forest Bond5449c682009-04-25 10:30:44 -0400936{
Varsha Rao26f64a62016-10-15 16:02:58 +0530937 void __iomem *iobase = priv->PortOffset;
Joe Perchesd4945f02013-03-18 10:44:40 -0700938 unsigned short ww;
939 unsigned char byData;
Forest Bond5449c682009-04-25 10:30:44 -0400940
Varsha Rao26f64a62016-10-15 16:02:58 +0530941 MACvRegBitsOn(iobase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
Joe Perchesd4945f02013-03-18 10:44:40 -0700942 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
Varsha Rao26f64a62016-10-15 16:02:58 +0530943 VNSvInPortB(iobase + MAC_REG_TFTCTL, &byData);
Joe Perchesd4945f02013-03-18 10:44:40 -0700944 if (!(byData & TFTCTL_TSFCNTRRD))
945 break;
946 }
947 if (ww == W_MAX_TIMEOUT)
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700948 return false;
Varsha Rao26f64a62016-10-15 16:02:58 +0530949 VNSvInPortD(iobase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
950 VNSvInPortD(iobase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
Forest Bond5449c682009-04-25 10:30:44 -0400951
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700952 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400953}
954
Forest Bond5449c682009-04-25 10:30:44 -0400955/*
956 * Description: Read NIC TSF counter
957 * Get NEXTTBTT from adjusted TSF and Beacon Interval
958 *
959 * Parameters:
960 * In:
961 * qwTSF - Current TSF counter
962 * wbeaconInterval - Beacon Interval
963 * Out:
964 * qwCurrTSF - Current TSF counter
965 *
966 * Return Value: TSF value of next Beacon
Forest Bond5449c682009-04-25 10:30:44 -0400967 */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100968u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -0400969{
Malcolm Priestley989ae862014-08-10 12:21:59 +0100970 u32 beacon_int;
Forest Bond5449c682009-04-25 10:30:44 -0400971
Malcolm Priestley989ae862014-08-10 12:21:59 +0100972 beacon_int = wBeaconInterval * 1024;
Malcolm Priestley989ae862014-08-10 12:21:59 +0100973 if (beacon_int) {
974 do_div(qwTSF, beacon_int);
975 qwTSF += 1;
976 qwTSF *= beacon_int;
977 }
Forest Bond5449c682009-04-25 10:30:44 -0400978
Joe Perchesa4ef27a2013-03-18 20:55:38 -0700979 return qwTSF;
Forest Bond5449c682009-04-25 10:30:44 -0400980}
981
Forest Bond5449c682009-04-25 10:30:44 -0400982/*
983 * Description: Set NIC TSF counter for first Beacon time
984 * Get NEXTTBTT from adjusted TSF and Beacon Interval
985 *
986 * Parameters:
987 * In:
Varsha Rao26f64a62016-10-15 16:02:58 +0530988 * iobase - IO Base
Forest Bond5449c682009-04-25 10:30:44 -0400989 * wBeaconInterval - Beacon Interval
990 * Out:
991 * none
992 *
993 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -0400994 */
Kathryn Hampton5150d012016-03-15 18:16:24 -0700995void CARDvSetFirstNextTBTT(struct vnt_private *priv,
996 unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -0400997{
Varsha Rao26f64a62016-10-15 16:02:58 +0530998 void __iomem *iobase = priv->PortOffset;
Malcolm Priestley0fc2a762014-08-10 12:21:58 +0100999 u64 qwNextTBTT = 0;
Forest Bond5449c682009-04-25 10:30:44 -04001000
Malcolm Priestley738487f2014-11-12 21:11:09 +00001001 CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */
Malcolm Priestley0fc2a762014-08-10 12:21:58 +01001002
Joe Perchesd4945f02013-03-18 10:44:40 -07001003 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001004 /* Set NextTBTT */
Varsha Rao26f64a62016-10-15 16:02:58 +05301005 VNSvOutPortD(iobase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
1006 VNSvOutPortD(iobase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
1007 MACvRegBitsOn(iobase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Forest Bond5449c682009-04-25 10:30:44 -04001008}
1009
Forest Bond5449c682009-04-25 10:30:44 -04001010/*
1011 * Description: Sync NIC TSF counter for Beacon time
1012 * Get NEXTTBTT and write to HW
1013 *
1014 * Parameters:
1015 * In:
Malcolm Priestley91961242015-10-17 11:33:02 +01001016 * priv - The adapter to be set
Forest Bond5449c682009-04-25 10:30:44 -04001017 * qwTSF - Current TSF counter
1018 * wBeaconInterval - Beacon Interval
1019 * Out:
1020 * none
1021 *
1022 * Return Value: none
Forest Bond5449c682009-04-25 10:30:44 -04001023 */
Kathryn Hampton5150d012016-03-15 18:16:24 -07001024void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 qwTSF,
1025 unsigned short wBeaconInterval)
Forest Bond5449c682009-04-25 10:30:44 -04001026{
Varsha Rao26f64a62016-10-15 16:02:58 +05301027 void __iomem *iobase = priv->PortOffset;
Malcolm Priestley738487f2014-11-12 21:11:09 +00001028
Joe Perchesd4945f02013-03-18 10:44:40 -07001029 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
Veronika Kabatova77b6a6a2014-10-25 22:34:38 +02001030 /* Set NextTBTT */
Varsha Rao26f64a62016-10-15 16:02:58 +05301031 VNSvOutPortD(iobase + MAC_REG_NEXTTBTT, (u32)qwTSF);
1032 VNSvOutPortD(iobase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
1033 MACvRegBitsOn(iobase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
Joe Perches48caf5a2014-08-17 09:17:04 -07001034 pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF);
Forest Bond5449c682009-04-25 10:30:44 -04001035}