Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 15 | * File: card.c |
| 16 | * Purpose: Provide functions to setup NIC operation mode |
| 17 | * Functions: |
| 18 | * s_vSafeResetTx - Rest Tx |
| 19 | * CARDvSetRSPINF - Set RSPINF |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 20 | * CARDvUpdateBasicTopRate - Update BasicTopRate |
| 21 | * CARDbAddBasicRate - Add to BasicRateSet |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 22 | * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet |
| 23 | * CARDvSetLoopbackMode - Set Loopback mode |
| 24 | * CARDbSoftwareReset - Sortware reset NIC |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 25 | * CARDqGetTSFOffset - Calculate TSFOffset |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 26 | * CARDbGetCurrentTSF - Read Current NIC TSF counter |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 27 | * CARDqGetNextTBTT - Calculate Next Beacon TSF counter |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 28 | * 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 Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 32 | * |
| 33 | * Revision History: |
| 34 | * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 35 | * 08-26-2003 Kyle Hsu: Modify the defination type of iobase. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 36 | * 09-01-2003 Bryan YC Fan: Add vUpdateIFS(). |
| 37 | * |
| 38 | */ |
| 39 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 40 | #include "tmacro.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 41 | #include "card.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 42 | #include "baseband.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 43 | #include "mac.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 44 | #include "desc.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 45 | #include "rf.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 46 | #include "power.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 47 | |
| 48 | /*--------------------- Static Definitions -------------------------*/ |
| 49 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 50 | #define C_SIFS_A 16 /* micro sec. */ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 51 | #define C_SIFS_BG 10 |
| 52 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 53 | #define C_EIFS 80 /* micro sec. */ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 54 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 55 | #define C_SLOT_SHORT 9 /* micro sec. */ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 56 | #define C_SLOT_LONG 20 |
| 57 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 58 | #define C_CWMIN_A 15 /* slot time */ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 59 | #define C_CWMIN_B 31 |
| 60 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 61 | #define C_CWMAX 1023 /* slot time */ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 62 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 63 | #define WAIT_BEACON_TX_DOWN_TMO 3 /* Times */ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 64 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 65 | /*--------------------- Static Variables --------------------------*/ |
| 66 | |
Mariam Mohamed Fawzy | 1167ff9 | 2015-01-26 11:24:36 +0200 | [diff] [blame] | 67 | static const unsigned short cwRXBCNTSFOff[MAX_RATE] = { |
| 68 | 17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3}; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 69 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 70 | /*--------------------- Static Functions --------------------------*/ |
| 71 | |
| 72 | static |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 73 | void |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 74 | s_vCalculateOFDMRParameter( |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 75 | unsigned char byRate, |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 76 | u8 bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 77 | unsigned char *pbyTxRate, |
| 78 | unsigned char *pbyRsvTime |
| 79 | ); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 80 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 81 | /*--------------------- Export Functions --------------------------*/ |
| 82 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 83 | /* |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 84 | * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 85 | * |
| 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 Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 95 | */ |
| 96 | static |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 97 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 98 | s_vCalculateOFDMRParameter( |
| 99 | unsigned char byRate, |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 100 | u8 bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 101 | unsigned char *pbyTxRate, |
| 102 | unsigned char *pbyRsvTime |
| 103 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 104 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 105 | switch (byRate) { |
| 106 | case RATE_6M: |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 107 | if (bb_type == BB_TYPE_11A) { /* 5GHZ */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 108 | *pbyTxRate = 0x9B; |
| 109 | *pbyRsvTime = 44; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 110 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 111 | *pbyTxRate = 0x8B; |
| 112 | *pbyRsvTime = 50; |
| 113 | } |
| 114 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 115 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 116 | case RATE_9M: |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 117 | if (bb_type == BB_TYPE_11A) { /* 5GHZ */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 118 | *pbyTxRate = 0x9F; |
| 119 | *pbyRsvTime = 36; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 120 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 121 | *pbyTxRate = 0x8F; |
| 122 | *pbyRsvTime = 42; |
| 123 | } |
| 124 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 125 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 126 | case RATE_12M: |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 127 | if (bb_type == BB_TYPE_11A) { /* 5GHZ */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 128 | *pbyTxRate = 0x9A; |
| 129 | *pbyRsvTime = 32; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 130 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 131 | *pbyTxRate = 0x8A; |
| 132 | *pbyRsvTime = 38; |
| 133 | } |
| 134 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 135 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 136 | case RATE_18M: |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 137 | if (bb_type == BB_TYPE_11A) { /* 5GHZ */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 138 | *pbyTxRate = 0x9E; |
| 139 | *pbyRsvTime = 28; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 140 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 141 | *pbyTxRate = 0x8E; |
| 142 | *pbyRsvTime = 34; |
| 143 | } |
| 144 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 145 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 146 | case RATE_36M: |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 147 | if (bb_type == BB_TYPE_11A) { /* 5GHZ */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 148 | *pbyTxRate = 0x9D; |
| 149 | *pbyRsvTime = 24; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 150 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 151 | *pbyTxRate = 0x8D; |
| 152 | *pbyRsvTime = 30; |
| 153 | } |
| 154 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 155 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 156 | case RATE_48M: |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 157 | if (bb_type == BB_TYPE_11A) { /* 5GHZ */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 158 | *pbyTxRate = 0x98; |
| 159 | *pbyRsvTime = 24; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 160 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 161 | *pbyTxRate = 0x88; |
| 162 | *pbyRsvTime = 30; |
| 163 | } |
| 164 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 165 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 166 | case RATE_54M: |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 167 | if (bb_type == BB_TYPE_11A) { /* 5GHZ */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 168 | *pbyTxRate = 0x9C; |
| 169 | *pbyRsvTime = 24; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 170 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 171 | *pbyTxRate = 0x8C; |
| 172 | *pbyRsvTime = 30; |
| 173 | } |
| 174 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 175 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 176 | case RATE_24M: |
| 177 | default: |
Malcolm Priestley | d1ab520 | 2014-11-07 19:06:04 +0000 | [diff] [blame] | 178 | if (bb_type == BB_TYPE_11A) { /* 5GHZ */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 179 | *pbyTxRate = 0x99; |
| 180 | *pbyRsvTime = 28; |
Joe Perches | 5e0cc8a | 2013-03-18 20:55:37 -0700 | [diff] [blame] | 181 | } else { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 182 | *pbyTxRate = 0x89; |
| 183 | *pbyRsvTime = 34; |
| 184 | } |
| 185 | break; |
| 186 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 189 | /*--------------------- Export Functions --------------------------*/ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 190 | |
| 191 | /* |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 192 | * Description: Update IFS |
| 193 | * |
| 194 | * Parameters: |
| 195 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 196 | * priv - The adapter to be set |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 197 | * Out: |
| 198 | * none |
| 199 | * |
| 200 | * Return Value: None. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 201 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 202 | bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 203 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 204 | unsigned char byCWMaxMin = 0; |
| 205 | unsigned char bySlot = 0; |
| 206 | unsigned char bySIFS = 0; |
| 207 | unsigned char byDIFS = 0; |
| 208 | unsigned char byData; |
Malcolm Priestley | 0614a0e | 2014-10-29 17:43:51 +0000 | [diff] [blame] | 209 | int i; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 210 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 211 | /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */ |
Malcolm Priestley | a558e3d | 2014-11-07 19:06:02 +0000 | [diff] [blame] | 212 | if (bb_type == BB_TYPE_11A) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 213 | if (priv->byRFType == RF_AIROHA7230) { |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 214 | /* AL7230 use single PAPE and connect to PAPE_2.4G */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 215 | 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ínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 220 | if (byData == 0x1C) |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 221 | BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 222 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 223 | } else if (priv->byRFType == RF_UW2452) { |
| 224 | MACvSetBBType(priv->PortOffset, BB_TYPE_11A); |
| 225 | priv->abyBBVGA[0] = 0x18; |
| 226 | BBbReadEmbedded(priv, 0xE7, &byData); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 227 | if (byData == 0x14) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 228 | BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); |
| 229 | BBbWriteEmbedded(priv, 0xE1, 0x57); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 230 | } |
| 231 | } else { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 232 | MACvSetBBType(priv->PortOffset, BB_TYPE_11A); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 233 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 234 | BBbWriteEmbedded(priv, 0x88, 0x03); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 235 | bySlot = C_SLOT_SHORT; |
| 236 | bySIFS = C_SIFS_A; |
Burcin Akalin | 0cddeac | 2015-10-22 00:48:29 +0300 | [diff] [blame] | 237 | byDIFS = C_SIFS_A + 2 * C_SLOT_SHORT; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 238 | byCWMaxMin = 0xA4; |
Malcolm Priestley | a558e3d | 2014-11-07 19:06:02 +0000 | [diff] [blame] | 239 | } else if (bb_type == BB_TYPE_11B) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 240 | 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ínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 246 | if (byData == 0x20) |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 247 | BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 248 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 249 | } else if (priv->byRFType == RF_UW2452) { |
| 250 | priv->abyBBVGA[0] = 0x14; |
| 251 | BBbReadEmbedded(priv, 0xE7, &byData); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 252 | if (byData == 0x18) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 253 | BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); |
| 254 | BBbWriteEmbedded(priv, 0xE1, 0xD3); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 255 | } |
| 256 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 257 | BBbWriteEmbedded(priv, 0x88, 0x02); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 258 | bySlot = C_SLOT_LONG; |
| 259 | bySIFS = C_SIFS_BG; |
Varsha Rao | f9d033c | 2016-10-12 10:06:46 +0530 | [diff] [blame] | 260 | byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 261 | byCWMaxMin = 0xA5; |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 262 | } else { /* PK_TYPE_11GA & PK_TYPE_11GB */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 263 | 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ínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 269 | if (byData == 0x20) |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 270 | BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 271 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 272 | } else if (priv->byRFType == RF_UW2452) { |
| 273 | priv->abyBBVGA[0] = 0x14; |
| 274 | BBbReadEmbedded(priv, 0xE7, &byData); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 275 | if (byData == 0x18) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 276 | BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]); |
| 277 | BBbWriteEmbedded(priv, 0xE1, 0xD3); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 278 | } |
| 279 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 280 | BBbWriteEmbedded(priv, 0x88, 0x08); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 281 | bySIFS = C_SIFS_BG; |
Malcolm Priestley | 0614a0e | 2014-10-29 17:43:51 +0000 | [diff] [blame] | 282 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 283 | if (priv->bShortSlotTime) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 284 | bySlot = C_SLOT_SHORT; |
Burcin Akalin | 68535a1 | 2015-10-22 15:15:39 +0300 | [diff] [blame] | 285 | byDIFS = C_SIFS_BG + 2 * C_SLOT_SHORT; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 286 | } else { |
| 287 | bySlot = C_SLOT_LONG; |
Varsha Rao | f9d033c | 2016-10-12 10:06:46 +0530 | [diff] [blame] | 288 | byDIFS = C_SIFS_BG + 2 * C_SLOT_LONG; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 289 | } |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 290 | |
Malcolm Priestley | 0614a0e | 2014-10-29 17:43:51 +0000 | [diff] [blame] | 291 | byCWMaxMin = 0xa4; |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 292 | |
Malcolm Priestley | 0614a0e | 2014-10-29 17:43:51 +0000 | [diff] [blame] | 293 | for (i = RATE_54M; i >= RATE_6M; i--) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 294 | if (priv->basic_rates & ((u32)(0x1 << i))) { |
Malcolm Priestley | 0614a0e | 2014-10-29 17:43:51 +0000 | [diff] [blame] | 295 | byCWMaxMin |= 0x1; |
| 296 | break; |
| 297 | } |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 300 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 301 | if (priv->byRFType == RF_RFMD2959) { |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 302 | /* |
| 303 | * bcs TX_PE will reserve 3 us hardware's processing |
| 304 | * time here is 2 us. |
| 305 | */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 306 | bySIFS -= 3; |
| 307 | byDIFS -= 3; |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 308 | /* |
| 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 Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 313 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 314 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 315 | if (priv->bySIFS != bySIFS) { |
| 316 | priv->bySIFS = bySIFS; |
| 317 | VNSvOutPortB(priv->PortOffset + MAC_REG_SIFS, priv->bySIFS); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 318 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 319 | if (priv->byDIFS != byDIFS) { |
| 320 | priv->byDIFS = byDIFS; |
| 321 | VNSvOutPortB(priv->PortOffset + MAC_REG_DIFS, priv->byDIFS); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 322 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 323 | if (priv->byEIFS != C_EIFS) { |
| 324 | priv->byEIFS = C_EIFS; |
| 325 | VNSvOutPortB(priv->PortOffset + MAC_REG_EIFS, priv->byEIFS); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 326 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 327 | if (priv->bySlot != bySlot) { |
| 328 | priv->bySlot = bySlot; |
| 329 | VNSvOutPortB(priv->PortOffset + MAC_REG_SLOT, priv->bySlot); |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 330 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 331 | BBvSetShortSlotTime(priv); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 332 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 333 | if (priv->byCWMaxMin != byCWMaxMin) { |
| 334 | priv->byCWMaxMin = byCWMaxMin; |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 335 | VNSvOutPortB(priv->PortOffset + MAC_REG_CWMAXMIN0, |
| 336 | priv->byCWMaxMin); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 337 | } |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 338 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 339 | priv->byPacketType = CARDbyGetPktType(priv); |
Malcolm Priestley | 61b9099 | 2014-11-06 20:02:05 +0000 | [diff] [blame] | 340 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 341 | CARDvSetRSPINF(priv, bb_type); |
Malcolm Priestley | 0614a0e | 2014-10-29 17:43:51 +0000 | [diff] [blame] | 342 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 343 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Description: Sync. TSF counter to BSS |
| 348 | * Get TSF offset and write to HW |
| 349 | * |
| 350 | * Parameters: |
| 351 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 352 | * priv - The adapter to be sync. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 353 | * 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 Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 360 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 361 | bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate, |
Malcolm Priestley | 032ed34 | 2015-04-21 22:33:01 +0100 | [diff] [blame] | 362 | u64 qwBSSTimestamp) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 363 | { |
Malcolm Priestley | 032ed34 | 2015-04-21 22:33:01 +0100 | [diff] [blame] | 364 | u64 local_tsf; |
Malcolm Priestley | 0fc2a76 | 2014-08-10 12:21:58 +0100 | [diff] [blame] | 365 | u64 qwTSFOffset = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 366 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 367 | CARDbGetCurrentTSF(priv, &local_tsf); |
Malcolm Priestley | 032ed34 | 2015-04-21 22:33:01 +0100 | [diff] [blame] | 368 | |
| 369 | if (qwBSSTimestamp != local_tsf) { |
| 370 | qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, |
| 371 | local_tsf); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 372 | /* adjust TSF, HW's TSF add TSF Offset reg */ |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 373 | 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 Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 379 | } |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 380 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 381 | } |
| 382 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 383 | /* |
| 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 Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 389 | * priv - The adapter to be set. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 390 | * wBeaconInterval - Beacon Interval |
| 391 | * Out: |
| 392 | * none |
| 393 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 394 | * Return Value: true if succeed; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 395 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 396 | bool CARDbSetBeaconPeriod(struct vnt_private *priv, |
Malcolm Priestley | d052270 | 2014-08-10 15:46:57 +0100 | [diff] [blame] | 397 | unsigned short wBeaconInterval) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 398 | { |
Malcolm Priestley | 0fc2a76 | 2014-08-10 12:21:58 +0100 | [diff] [blame] | 399 | u64 qwNextTBTT = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 400 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 401 | CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 402 | |
Malcolm Priestley | 4a5f718 | 2014-08-10 12:22:00 +0100 | [diff] [blame] | 403 | qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 404 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 405 | /* set HW beacon interval */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 406 | VNSvOutPortW(priv->PortOffset + MAC_REG_BI, wBeaconInterval); |
| 407 | priv->wBeaconInterval = wBeaconInterval; |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 408 | /* Set NextTBTT */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 409 | VNSvOutPortD(priv->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 410 | VNSvOutPortD(priv->PortOffset + MAC_REG_NEXTTBTT + 4, |
| 411 | (u32)(qwNextTBTT >> 32)); |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 412 | MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 413 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 414 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 415 | } |
| 416 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 417 | /* |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 418 | * Description: Turn off Radio power |
| 419 | * |
| 420 | * Parameters: |
| 421 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 422 | * priv - The adapter to be turned off |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 423 | * Out: |
| 424 | * none |
| 425 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 426 | * Return Value: true if success; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 427 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 428 | bool CARDbRadioPowerOff(struct vnt_private *priv) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 429 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 430 | bool bResult = true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 431 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 432 | if (priv->bRadioOff) |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 433 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 434 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 435 | switch (priv->byRFType) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 436 | case RF_RFMD2959: |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 437 | MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, |
| 438 | SOFTPWRCTL_TXPEINV); |
| 439 | MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL, |
| 440 | SOFTPWRCTL_SWPE1); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 441 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 442 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 443 | case RF_AIROHA: |
| 444 | case RF_AL2230S: |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 445 | case RF_AIROHA7230: |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 446 | MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, |
| 447 | SOFTPWRCTL_SWPE2); |
| 448 | MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, |
| 449 | SOFTPWRCTL_SWPE3); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 450 | break; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 451 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 452 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 453 | MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 454 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 455 | BBvSetDeepSleep(priv, priv->byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 456 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 457 | priv->bRadioOff = true; |
Guillaume Clement | 941ead9 | 2014-07-25 01:06:21 +0200 | [diff] [blame] | 458 | pr_debug("chester power off\n"); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 459 | MACvRegBitsOn(priv->PortOffset, MAC_REG_GPIOCTL0, |
| 460 | LED_ACTSET); /* LED issue */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 461 | return bResult; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 462 | } |
| 463 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 464 | /* |
| 465 | * Description: Turn on Radio power |
| 466 | * |
| 467 | * Parameters: |
| 468 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 469 | * priv - The adapter to be turned on |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 470 | * Out: |
| 471 | * none |
| 472 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 473 | * Return Value: true if success; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 474 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 475 | bool CARDbRadioPowerOn(struct vnt_private *priv) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 476 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 477 | bool bResult = true; |
Igor Bezukh | f9dc1a8 | 2014-07-16 10:45:30 +0300 | [diff] [blame] | 478 | |
Guillaume Clement | 941ead9 | 2014-07-25 01:06:21 +0200 | [diff] [blame] | 479 | pr_debug("chester power on\n"); |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 480 | if (priv->bRadioControlOff) { |
| 481 | if (priv->bHWRadioOff) |
Guillaume Clement | a161342 | 2014-07-25 01:06:22 +0200 | [diff] [blame] | 482 | pr_debug("chester bHWRadioOff\n"); |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 483 | if (priv->bRadioControlOff) |
Guillaume Clement | a161342 | 2014-07-25 01:06:22 +0200 | [diff] [blame] | 484 | pr_debug("chester bRadioControlOff\n"); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 485 | return false; } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 486 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 487 | if (!priv->bRadioOff) { |
Guillaume Clement | 941ead9 | 2014-07-25 01:06:21 +0200 | [diff] [blame] | 488 | pr_debug("chester pbRadioOff\n"); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 489 | return true; } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 490 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 491 | BBvExitDeepSleep(priv, priv->byLocalID); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 492 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 493 | MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 494 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 495 | switch (priv->byRFType) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 496 | case RF_RFMD2959: |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 497 | MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL, |
| 498 | SOFTPWRCTL_TXPEINV); |
| 499 | MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, |
| 500 | SOFTPWRCTL_SWPE1); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 501 | break; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 502 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 503 | case RF_AIROHA: |
| 504 | case RF_AL2230S: |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 505 | case RF_AIROHA7230: |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 506 | MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL, |
| 507 | (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 508 | break; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 509 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 510 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 511 | priv->bRadioOff = false; |
Guillaume Clement | 941ead9 | 2014-07-25 01:06:21 +0200 | [diff] [blame] | 512 | pr_debug("chester power on\n"); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 513 | MACvRegBitsOff(priv->PortOffset, MAC_REG_GPIOCTL0, |
| 514 | LED_ACTSET); /* LED issue */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 515 | return bResult; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 518 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 519 | CARDvSafeResetTx( |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 520 | struct vnt_private *priv |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 521 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 522 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 523 | unsigned int uu; |
Malcolm Priestley | e235727 | 2015-08-14 22:58:51 +0100 | [diff] [blame] | 524 | struct vnt_tx_desc *pCurrTD; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 525 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 526 | /* initialize TD index */ |
Sreya Mittal | 6c9769c | 2017-03-05 17:42:28 +0530 | [diff] [blame] | 527 | priv->apTailTD[0] = &priv->apTD0Rings[0]; |
| 528 | priv->apCurrTD[0] = &priv->apTD0Rings[0]; |
Nick Rosbrook | ffbad99 | 2016-11-01 21:15:07 -0400 | [diff] [blame] | 529 | |
Sreya Mittal | 6c9769c | 2017-03-05 17:42:28 +0530 | [diff] [blame] | 530 | priv->apTailTD[1] = &priv->apTD1Rings[0]; |
| 531 | priv->apCurrTD[1] = &priv->apTD1Rings[0]; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 532 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 533 | for (uu = 0; uu < TYPE_MAXTD; uu++) |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 534 | priv->iTDUsed[uu] = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 535 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 536 | for (uu = 0; uu < priv->opts.tx_descs[0]; uu++) { |
Sreya Mittal | 6c9769c | 2017-03-05 17:42:28 +0530 | [diff] [blame] | 537 | pCurrTD = &priv->apTD0Rings[uu]; |
Malcolm Priestley | 5235ff6 | 2015-08-14 22:58:46 +0100 | [diff] [blame] | 538 | pCurrTD->td0.owner = OWNED_BY_HOST; |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 539 | /* init all Tx Packet pointer to NULL */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 540 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 541 | for (uu = 0; uu < priv->opts.tx_descs[1]; uu++) { |
Sreya Mittal | 6c9769c | 2017-03-05 17:42:28 +0530 | [diff] [blame] | 542 | pCurrTD = &priv->apTD1Rings[uu]; |
Malcolm Priestley | 5235ff6 | 2015-08-14 22:58:46 +0100 | [diff] [blame] | 543 | pCurrTD->td0.owner = OWNED_BY_HOST; |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 544 | /* init all Tx Packet pointer to NULL */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 545 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 546 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 547 | /* set MAC TD pointer */ |
Malcolm Priestley | f9f853a | 2015-11-22 09:07:22 +0000 | [diff] [blame] | 548 | MACvSetCurrTXDescAddr(TYPE_TXDMA0, priv, priv->td0_pool_dma); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 549 | |
Malcolm Priestley | f9f853a | 2015-11-22 09:07:22 +0000 | [diff] [blame] | 550 | MACvSetCurrTXDescAddr(TYPE_AC0DMA, priv, priv->td1_pool_dma); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 551 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 552 | /* set MAC Beacon TX pointer */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 553 | MACvSetCurrBCNTxDescAddr(priv->PortOffset, |
| 554 | (priv->tx_beacon_dma)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 555 | } |
| 556 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 557 | /* |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 558 | * Description: |
| 559 | * Reset Rx |
| 560 | * |
| 561 | * Parameters: |
| 562 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 563 | * priv - Pointer to the adapter |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 564 | * Out: |
| 565 | * none |
| 566 | * |
| 567 | * Return Value: none |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 568 | */ |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 569 | void |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 570 | CARDvSafeResetRx( |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 571 | struct vnt_private *priv |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 572 | ) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 573 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 574 | unsigned int uu; |
Malcolm Priestley | 9cb693f | 2015-08-15 21:57:35 +0100 | [diff] [blame] | 575 | struct vnt_rx_desc *pDesc; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 576 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 577 | /* initialize RD index */ |
Sreya Mittal | 6c9769c | 2017-03-05 17:42:28 +0530 | [diff] [blame] | 578 | priv->pCurrRD[0] = &priv->aRD0Ring[0]; |
| 579 | priv->pCurrRD[1] = &priv->aRD1Ring[0]; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 580 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 581 | /* init state, all RD is chip's */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 582 | for (uu = 0; uu < priv->opts.rx_descs0; uu++) { |
Sreya Mittal | 6c9769c | 2017-03-05 17:42:28 +0530 | [diff] [blame] | 583 | pDesc = &priv->aRD0Ring[uu]; |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 584 | pDesc->rd0.res_count = cpu_to_le16(priv->rx_buf_sz); |
Malcolm Priestley | de1c186 | 2015-08-15 21:57:32 +0100 | [diff] [blame] | 585 | pDesc->rd0.owner = OWNED_BY_NIC; |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 586 | pDesc->rd1.req_count = cpu_to_le16(priv->rx_buf_sz); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 587 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 588 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 589 | /* init state, all RD is chip's */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 590 | for (uu = 0; uu < priv->opts.rx_descs1; uu++) { |
Sreya Mittal | 6c9769c | 2017-03-05 17:42:28 +0530 | [diff] [blame] | 591 | pDesc = &priv->aRD1Ring[uu]; |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 592 | pDesc->rd0.res_count = cpu_to_le16(priv->rx_buf_sz); |
Malcolm Priestley | de1c186 | 2015-08-15 21:57:32 +0100 | [diff] [blame] | 593 | pDesc->rd0.owner = OWNED_BY_NIC; |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 594 | pDesc->rd1.req_count = cpu_to_le16(priv->rx_buf_sz); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 595 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 596 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 597 | /* set perPkt mode */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 598 | MACvRx0PerPktMode(priv->PortOffset); |
| 599 | MACvRx1PerPktMode(priv->PortOffset); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 600 | /* set MAC RD pointer */ |
Malcolm Priestley | f9f853a | 2015-11-22 09:07:22 +0000 | [diff] [blame] | 601 | MACvSetCurrRx0DescAddr(priv, priv->rd0_pool_dma); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 602 | |
Malcolm Priestley | f9f853a | 2015-11-22 09:07:22 +0000 | [diff] [blame] | 603 | MACvSetCurrRx1DescAddr(priv, priv->rd1_pool_dma); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 604 | } |
| 605 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 606 | /* |
| 607 | * Description: Get response Control frame rate in CCK mode |
| 608 | * |
| 609 | * Parameters: |
| 610 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 611 | * priv - The adapter to be set |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 612 | * wRateIdx - Receiving data rate |
| 613 | * Out: |
| 614 | * none |
| 615 | * |
| 616 | * Return Value: response Control frame rate |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 617 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 618 | static unsigned short CARDwGetCCKControlRate(struct vnt_private *priv, |
Malcolm Priestley | d052270 | 2014-08-10 15:46:57 +0100 | [diff] [blame] | 619 | unsigned short wRateIdx) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 620 | { |
Sandhya Bankar | 58d4474 | 2016-09-19 17:47:21 +0530 | [diff] [blame] | 621 | unsigned int ui = (unsigned int)wRateIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 622 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 623 | while (ui > RATE_1M) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 624 | if (priv->basic_rates & ((u32)0x1 << ui)) |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 625 | return (unsigned short)ui; |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 626 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 627 | ui--; |
| 628 | } |
| 629 | return (unsigned short)RATE_1M; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /* |
| 633 | * Description: Get response Control frame rate in OFDM mode |
| 634 | * |
| 635 | * Parameters: |
| 636 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 637 | * priv - The adapter to be set |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 638 | * wRateIdx - Receiving data rate |
| 639 | * Out: |
| 640 | * none |
| 641 | * |
| 642 | * Return Value: response Control frame rate |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 643 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 644 | static unsigned short CARDwGetOFDMControlRate(struct vnt_private *priv, |
Malcolm Priestley | d052270 | 2014-08-10 15:46:57 +0100 | [diff] [blame] | 645 | unsigned short wRateIdx) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 646 | { |
Sandhya Bankar | 58d4474 | 2016-09-19 17:47:21 +0530 | [diff] [blame] | 647 | unsigned int ui = (unsigned int)wRateIdx; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 648 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 649 | pr_debug("BASIC RATE: %X\n", priv->basic_rates); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 650 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 651 | if (!CARDbIsOFDMinBasicRate((void *)priv)) { |
Simo Koskinen | 6f67526 | 2017-07-17 14:59:05 +0200 | [diff] [blame] | 652 | pr_debug("%s:(NO OFDM) %d\n", __func__, wRateIdx); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 653 | if (wRateIdx > RATE_24M) |
| 654 | wRateIdx = RATE_24M; |
| 655 | return wRateIdx; |
| 656 | } |
| 657 | while (ui > RATE_11M) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 658 | if (priv->basic_rates & ((u32)0x1 << ui)) { |
Simo Koskinen | 6f67526 | 2017-07-17 14:59:05 +0200 | [diff] [blame] | 659 | pr_debug("%s : %d\n", __func__, ui); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 660 | return (unsigned short)ui; |
| 661 | } |
| 662 | ui--; |
| 663 | } |
Simo Koskinen | 6f67526 | 2017-07-17 14:59:05 +0200 | [diff] [blame] | 664 | pr_debug("%s: 6M\n", __func__); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 665 | return (unsigned short)RATE_24M; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 666 | } |
| 667 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 668 | /* |
| 669 | * Description: Set RSPINF |
| 670 | * |
| 671 | * Parameters: |
| 672 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 673 | * priv - The adapter to be set |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 674 | * Out: |
| 675 | * none |
| 676 | * |
| 677 | * Return Value: None. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 678 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 679 | void CARDvSetRSPINF(struct vnt_private *priv, u8 bb_type) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 680 | { |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 681 | union vnt_phy_field_swap phy; |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 682 | unsigned char byTxRate, byRsvTime; /* For OFDM */ |
Malcolm Priestley | 95775d1 | 2015-01-11 10:26:12 +0000 | [diff] [blame] | 683 | unsigned long flags; |
| 684 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 685 | spin_lock_irqsave(&priv->lock, flags); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 686 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 687 | /* Set to Page1 */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 688 | MACvSelectPage1(priv->PortOffset); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 689 | |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 690 | /* RSPINF_b_1 */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 691 | vnt_get_phy_field(priv, 14, |
| 692 | CARDwGetCCKControlRate(priv, RATE_1M), |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 693 | PK_TYPE_11B, &phy.field_read); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 694 | |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 695 | /* swap over to get correct write order */ |
| 696 | swap(phy.swap[0], phy.swap[1]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 697 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 698 | VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 699 | |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 700 | /* RSPINF_b_2 */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 701 | vnt_get_phy_field(priv, 14, |
| 702 | CARDwGetCCKControlRate(priv, RATE_2M), |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 703 | PK_TYPE_11B, &phy.field_read); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 704 | |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 705 | swap(phy.swap[0], phy.swap[1]); |
| 706 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 707 | VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write); |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 708 | |
| 709 | /* RSPINF_b_5 */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 710 | vnt_get_phy_field(priv, 14, |
| 711 | CARDwGetCCKControlRate(priv, RATE_5M), |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 712 | PK_TYPE_11B, &phy.field_read); |
| 713 | |
| 714 | swap(phy.swap[0], phy.swap[1]); |
| 715 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 716 | VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write); |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 717 | |
| 718 | /* RSPINF_b_11 */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 719 | vnt_get_phy_field(priv, 14, |
| 720 | CARDwGetCCKControlRate(priv, RATE_11M), |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 721 | PK_TYPE_11B, &phy.field_read); |
| 722 | |
| 723 | swap(phy.swap[0], phy.swap[1]); |
| 724 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 725 | VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write); |
Malcolm Priestley | 864a5a3 | 2014-08-20 22:30:30 +0100 | [diff] [blame] | 726 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 727 | /* RSPINF_a_6 */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 728 | s_vCalculateOFDMRParameter(RATE_6M, |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 729 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 730 | &byTxRate, |
| 731 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 732 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_6, |
| 733 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 734 | /* RSPINF_a_9 */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 735 | s_vCalculateOFDMRParameter(RATE_9M, |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 736 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 737 | &byTxRate, |
| 738 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 739 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_9, |
| 740 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 741 | /* RSPINF_a_12 */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 742 | s_vCalculateOFDMRParameter(RATE_12M, |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 743 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 744 | &byTxRate, |
| 745 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 746 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_12, |
| 747 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 748 | /* RSPINF_a_18 */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 749 | s_vCalculateOFDMRParameter(RATE_18M, |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 750 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 751 | &byTxRate, |
| 752 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 753 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_18, |
| 754 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 755 | /* RSPINF_a_24 */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 756 | s_vCalculateOFDMRParameter(RATE_24M, |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 757 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 758 | &byTxRate, |
| 759 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 760 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_24, |
| 761 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 762 | /* RSPINF_a_36 */ |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 763 | s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate( |
| 764 | (void *)priv, |
| 765 | RATE_36M), |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 766 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 767 | &byTxRate, |
| 768 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 769 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_36, |
| 770 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 771 | /* RSPINF_a_48 */ |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 772 | s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate( |
| 773 | (void *)priv, |
| 774 | RATE_48M), |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 775 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 776 | &byTxRate, |
| 777 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 778 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_48, |
| 779 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 780 | /* RSPINF_a_54 */ |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 781 | s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate( |
| 782 | (void *)priv, |
| 783 | RATE_54M), |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 784 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 785 | &byTxRate, |
| 786 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 787 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_54, |
| 788 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 789 | /* RSPINF_a_72 */ |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 790 | s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate( |
| 791 | (void *)priv, |
| 792 | RATE_54M), |
Malcolm Priestley | 6e1d14a | 2014-11-07 19:06:03 +0000 | [diff] [blame] | 793 | bb_type, |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 794 | &byTxRate, |
| 795 | &byRsvTime); |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 796 | VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_72, |
| 797 | MAKEWORD(byTxRate, byRsvTime)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 798 | /* Set to Page0 */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 799 | MACvSelectPage0(priv->PortOffset); |
Malcolm Priestley | 95775d1 | 2015-01-11 10:26:12 +0000 | [diff] [blame] | 800 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 801 | spin_unlock_irqrestore(&priv->lock, flags); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 802 | } |
| 803 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 804 | void CARDvUpdateBasicTopRate(struct vnt_private *priv) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 805 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 806 | unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M; |
| 807 | unsigned char ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 808 | |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 809 | /* Determines the highest basic rate. */ |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 810 | for (ii = RATE_54M; ii >= RATE_6M; ii--) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 811 | if ((priv->basic_rates) & ((u32)(1 << ii))) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 812 | byTopOFDM = ii; |
| 813 | break; |
| 814 | } |
| 815 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 816 | priv->byTopOFDMBasicRate = byTopOFDM; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 817 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 818 | for (ii = RATE_11M;; ii--) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 819 | if ((priv->basic_rates) & ((u32)(1 << ii))) { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 820 | byTopCCK = ii; |
| 821 | break; |
| 822 | } |
| 823 | if (ii == RATE_1M) |
| 824 | break; |
| 825 | } |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 826 | priv->byTopCCKBasicRate = byTopCCK; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 827 | } |
| 828 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 829 | bool CARDbIsOFDMinBasicRate(struct vnt_private *priv) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 830 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 831 | int ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 832 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 833 | for (ii = RATE_54M; ii >= RATE_6M; ii--) { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 834 | if ((priv->basic_rates) & ((u32)BIT(ii))) |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 835 | return true; |
| 836 | } |
| 837 | return false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 838 | } |
| 839 | |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 840 | unsigned char CARDbyGetPktType(struct vnt_private *priv) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 841 | { |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 842 | if (priv->byBBType == BB_TYPE_11A || priv->byBBType == BB_TYPE_11B) |
| 843 | return (unsigned char)priv->byBBType; |
| 844 | else if (CARDbIsOFDMinBasicRate((void *)priv)) |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 845 | return PK_TYPE_11GA; |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 846 | else |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 847 | return PK_TYPE_11GB; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | /* |
| 851 | * Description: Set NIC Loopback mode |
| 852 | * |
| 853 | * Parameters: |
| 854 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 855 | * priv - The adapter to be set |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 856 | * wLoopbackMode - Loopback mode to be set |
| 857 | * Out: |
| 858 | * none |
| 859 | * |
| 860 | * Return Value: none |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 861 | */ |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 862 | void CARDvSetLoopbackMode(struct vnt_private *priv, |
| 863 | unsigned short wLoopbackMode) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 864 | { |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 865 | switch (wLoopbackMode) { |
| 866 | case CARD_LB_NONE: |
| 867 | case CARD_LB_MAC: |
| 868 | case CARD_LB_PHY: |
| 869 | break; |
| 870 | default: |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 871 | break; |
| 872 | } |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 873 | /* set MAC loopback */ |
Malcolm Priestley | f9f853a | 2015-11-22 09:07:22 +0000 | [diff] [blame] | 874 | MACvSetLoopbackMode(priv, LOBYTE(wLoopbackMode)); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 875 | /* set Baseband loopback */ |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 876 | } |
| 877 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 878 | /* |
| 879 | * Description: Software Reset NIC |
| 880 | * |
| 881 | * Parameters: |
| 882 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 883 | * priv - The adapter to be reset |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 884 | * Out: |
| 885 | * none |
| 886 | * |
| 887 | * Return Value: none |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 888 | */ |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 889 | bool CARDbSoftwareReset(struct vnt_private *priv) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 890 | { |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 891 | /* reset MAC */ |
Malcolm Priestley | f9f853a | 2015-11-22 09:07:22 +0000 | [diff] [blame] | 892 | if (!MACbSafeSoftwareReset(priv)) |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 893 | return false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 894 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 895 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 896 | } |
| 897 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 898 | /* |
Justin P. Mattock | 7664ec8 | 2012-08-20 08:43:15 -0700 | [diff] [blame] | 899 | * Description: Calculate TSF offset of two TSF input |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 900 | * Get TSF Offset from RxBCN's TSF and local TSF |
| 901 | * |
| 902 | * Parameters: |
| 903 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 904 | * priv - The adapter to be sync. |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 905 | * qwTSF1 - Rx BCN's TSF |
| 906 | * qwTSF2 - Local TSF |
| 907 | * Out: |
| 908 | * none |
| 909 | * |
| 910 | * Return Value: TSF Offset value |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 911 | */ |
Malcolm Priestley | 0fc2a76 | 2014-08-10 12:21:58 +0100 | [diff] [blame] | 912 | u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 913 | { |
Amitoj Kaur Chawla | 5309c5b | 2015-10-15 13:45:39 +0530 | [diff] [blame] | 914 | unsigned short wRxBcnTSFOffst; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 915 | |
Marko Stankovic | 5b5d636 | 2017-05-20 18:50:37 +0200 | [diff] [blame] | 916 | wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE]; |
Guido Martínez | bc5cf65 | 2014-04-19 16:45:00 -0300 | [diff] [blame] | 917 | |
Malcolm Priestley | 0fc2a76 | 2014-08-10 12:21:58 +0100 | [diff] [blame] | 918 | qwTSF2 += (u64)wRxBcnTSFOffst; |
| 919 | |
simran singhal | 57ce4df | 2017-02-19 02:52:07 +0530 | [diff] [blame] | 920 | return qwTSF1 - qwTSF2; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 921 | } |
| 922 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 923 | /* |
| 924 | * Description: Read NIC TSF counter |
| 925 | * Get local TSF counter |
| 926 | * |
| 927 | * Parameters: |
| 928 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 929 | * priv - The adapter to be read |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 930 | * Out: |
| 931 | * qwCurrTSF - Current TSF counter |
| 932 | * |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 933 | * Return Value: true if success; otherwise false |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 934 | */ |
Malcolm Priestley | 738487f | 2014-11-12 21:11:09 +0000 | [diff] [blame] | 935 | bool CARDbGetCurrentTSF(struct vnt_private *priv, u64 *pqwCurrTSF) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 936 | { |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 937 | void __iomem *iobase = priv->PortOffset; |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 938 | unsigned short ww; |
| 939 | unsigned char byData; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 940 | |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 941 | MACvRegBitsOn(iobase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 942 | for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 943 | VNSvInPortB(iobase + MAC_REG_TFTCTL, &byData); |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 944 | if (!(byData & TFTCTL_TSFCNTRRD)) |
| 945 | break; |
| 946 | } |
| 947 | if (ww == W_MAX_TIMEOUT) |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 948 | return false; |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 949 | VNSvInPortD(iobase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF); |
| 950 | VNSvInPortD(iobase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 951 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 952 | return true; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 953 | } |
| 954 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 955 | /* |
| 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 Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 967 | */ |
Malcolm Priestley | 0fc2a76 | 2014-08-10 12:21:58 +0100 | [diff] [blame] | 968 | u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 969 | { |
Malcolm Priestley | 989ae86 | 2014-08-10 12:21:59 +0100 | [diff] [blame] | 970 | u32 beacon_int; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 971 | |
Malcolm Priestley | 989ae86 | 2014-08-10 12:21:59 +0100 | [diff] [blame] | 972 | beacon_int = wBeaconInterval * 1024; |
Malcolm Priestley | 989ae86 | 2014-08-10 12:21:59 +0100 | [diff] [blame] | 973 | if (beacon_int) { |
| 974 | do_div(qwTSF, beacon_int); |
| 975 | qwTSF += 1; |
| 976 | qwTSF *= beacon_int; |
| 977 | } |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 978 | |
Joe Perches | a4ef27a | 2013-03-18 20:55:38 -0700 | [diff] [blame] | 979 | return qwTSF; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 980 | } |
| 981 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 982 | /* |
| 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 Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 988 | * iobase - IO Base |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 989 | * wBeaconInterval - Beacon Interval |
| 990 | * Out: |
| 991 | * none |
| 992 | * |
| 993 | * Return Value: none |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 994 | */ |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 995 | void CARDvSetFirstNextTBTT(struct vnt_private *priv, |
| 996 | unsigned short wBeaconInterval) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 997 | { |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 998 | void __iomem *iobase = priv->PortOffset; |
Malcolm Priestley | 0fc2a76 | 2014-08-10 12:21:58 +0100 | [diff] [blame] | 999 | u64 qwNextTBTT = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1000 | |
Malcolm Priestley | 738487f | 2014-11-12 21:11:09 +0000 | [diff] [blame] | 1001 | CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */ |
Malcolm Priestley | 0fc2a76 | 2014-08-10 12:21:58 +0100 | [diff] [blame] | 1002 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1003 | qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 1004 | /* Set NextTBTT */ |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 1005 | 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 Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1008 | } |
| 1009 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1010 | /* |
| 1011 | * Description: Sync NIC TSF counter for Beacon time |
| 1012 | * Get NEXTTBTT and write to HW |
| 1013 | * |
| 1014 | * Parameters: |
| 1015 | * In: |
Malcolm Priestley | 9196124 | 2015-10-17 11:33:02 +0100 | [diff] [blame] | 1016 | * priv - The adapter to be set |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1017 | * qwTSF - Current TSF counter |
| 1018 | * wBeaconInterval - Beacon Interval |
| 1019 | * Out: |
| 1020 | * none |
| 1021 | * |
| 1022 | * Return Value: none |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1023 | */ |
Kathryn Hampton | 5150d01 | 2016-03-15 18:16:24 -0700 | [diff] [blame] | 1024 | void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 qwTSF, |
| 1025 | unsigned short wBeaconInterval) |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1026 | { |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 1027 | void __iomem *iobase = priv->PortOffset; |
Malcolm Priestley | 738487f | 2014-11-12 21:11:09 +0000 | [diff] [blame] | 1028 | |
Joe Perches | d4945f0 | 2013-03-18 10:44:40 -0700 | [diff] [blame] | 1029 | qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval); |
Veronika Kabatova | 77b6a6a | 2014-10-25 22:34:38 +0200 | [diff] [blame] | 1030 | /* Set NextTBTT */ |
Varsha Rao | 26f64a6 | 2016-10-15 16:02:58 +0530 | [diff] [blame] | 1031 | 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 Perches | 48caf5a | 2014-08-17 09:17:04 -0700 | [diff] [blame] | 1034 | pr_debug("Card:Update Next TBTT[%8llx]\n", qwTSF); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1035 | } |