| .. | .. |
|---|
| 26 | 26 | * |
|---|
| 27 | 27 | */ |
|---|
| 28 | 28 | |
|---|
| 29 | +#include <linux/bitops.h> |
|---|
| 30 | +#include <linux/errno.h> |
|---|
| 29 | 31 | #include "device.h" |
|---|
| 30 | 32 | #include "card.h" |
|---|
| 31 | 33 | #include "baseband.h" |
|---|
| .. | .. |
|---|
| 44 | 46 | 192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3 |
|---|
| 45 | 47 | }; |
|---|
| 46 | 48 | |
|---|
| 47 | | -/* |
|---|
| 48 | | - * Description: Set NIC media channel |
|---|
| 49 | | - * |
|---|
| 50 | | - * Parameters: |
|---|
| 51 | | - * In: |
|---|
| 52 | | - * pDevice - The adapter to be set |
|---|
| 53 | | - * connection_channel - Channel to be set |
|---|
| 54 | | - * Out: |
|---|
| 55 | | - * none |
|---|
| 56 | | - */ |
|---|
| 57 | | -void vnt_set_channel(struct vnt_private *priv, u32 connection_channel) |
|---|
| 49 | +int vnt_set_channel(struct vnt_private *priv, u32 connection_channel) |
|---|
| 58 | 50 | { |
|---|
| 51 | + int ret; |
|---|
| 52 | + |
|---|
| 59 | 53 | if (connection_channel > CB_MAX_CHANNEL || !connection_channel) |
|---|
| 60 | | - return; |
|---|
| 54 | + return -EINVAL; |
|---|
| 61 | 55 | |
|---|
| 62 | 56 | /* clear NAV */ |
|---|
| 63 | 57 | vnt_mac_reg_bits_on(priv, MAC_REG_MACCR, MACCR_CLRNAV); |
|---|
| 64 | 58 | |
|---|
| 65 | 59 | /* Set Channel[7] = 0 to tell H/W channel is changing now. */ |
|---|
| 66 | | - vnt_mac_reg_bits_off(priv, MAC_REG_CHANNEL, 0xb0); |
|---|
| 60 | + vnt_mac_reg_bits_off(priv, MAC_REG_CHANNEL, |
|---|
| 61 | + (BIT(7) | BIT(5) | BIT(4))); |
|---|
| 67 | 62 | |
|---|
| 68 | | - vnt_control_out(priv, MESSAGE_TYPE_SELECT_CHANNEL, |
|---|
| 69 | | - connection_channel, 0, 0, NULL); |
|---|
| 63 | + ret = vnt_control_out(priv, MESSAGE_TYPE_SELECT_CHANNEL, |
|---|
| 64 | + connection_channel, 0, 0, NULL); |
|---|
| 65 | + if (ret) |
|---|
| 66 | + return ret; |
|---|
| 70 | 67 | |
|---|
| 71 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL, |
|---|
| 72 | | - (u8)(connection_channel | 0x80)); |
|---|
| 68 | + return vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL, |
|---|
| 69 | + (u8)(connection_channel | 0x80)); |
|---|
| 73 | 70 | } |
|---|
| 74 | 71 | |
|---|
| 75 | | -/* |
|---|
| 76 | | - * Description: Get CCK mode basic rate |
|---|
| 77 | | - * |
|---|
| 78 | | - * Parameters: |
|---|
| 79 | | - * In: |
|---|
| 80 | | - * priv - The adapter to be set |
|---|
| 81 | | - * rate_idx - Receiving data rate |
|---|
| 82 | | - * Out: |
|---|
| 83 | | - * none |
|---|
| 84 | | - * |
|---|
| 85 | | - * Return Value: response Control frame rate |
|---|
| 86 | | - * |
|---|
| 87 | | - */ |
|---|
| 88 | | -static u16 vnt_get_cck_rate(struct vnt_private *priv, u16 rate_idx) |
|---|
| 72 | +static const u8 vnt_rspinf_b_short_table[] = { |
|---|
| 73 | + 0x70, 0x00, 0x00, 0x00, 0x38, 0x00, 0x09, 0x00, |
|---|
| 74 | + 0x15, 0x00, 0x0a, 0x00, 0x0b, 0x00, 0x0b, 0x80 |
|---|
| 75 | +}; |
|---|
| 76 | + |
|---|
| 77 | +static const u8 vnt_rspinf_b_long_table[] = { |
|---|
| 78 | + 0x70, 0x00, 0x00, 0x00, 0x38, 0x00, 0x01, 0x00, |
|---|
| 79 | + 0x15, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x03, 0x80 |
|---|
| 80 | +}; |
|---|
| 81 | + |
|---|
| 82 | +static const u8 vnt_rspinf_a_table[] = { |
|---|
| 83 | + 0x9b, 0x18, 0x9f, 0x10, 0x9a, 0x0a, 0x9e, 0x08, 0x99, |
|---|
| 84 | + 0x08, 0x9d, 0x04, 0x98, 0x04, 0x9c, 0x04, 0x9c, 0x04 |
|---|
| 85 | +}; |
|---|
| 86 | + |
|---|
| 87 | +static const u8 vnt_rspinf_gb_table[] = { |
|---|
| 88 | + 0x8b, 0x1e, 0x8f, 0x16, 0x8a, 0x12, 0x8e, 0x0e, 0x89, |
|---|
| 89 | + 0x0e, 0x8d, 0x0a, 0x88, 0x0a, 0x8c, 0x0a, 0x8c, 0x0a |
|---|
| 90 | +}; |
|---|
| 91 | + |
|---|
| 92 | +int vnt_set_rspinf(struct vnt_private *priv, u8 bb_type) |
|---|
| 89 | 93 | { |
|---|
| 90 | | - u16 ui = rate_idx; |
|---|
| 94 | + const u8 *data; |
|---|
| 95 | + u16 len; |
|---|
| 96 | + int ret; |
|---|
| 91 | 97 | |
|---|
| 92 | | - while (ui > RATE_1M) { |
|---|
| 93 | | - if (priv->basic_rates & (1 << ui)) |
|---|
| 94 | | - return ui; |
|---|
| 95 | | - ui--; |
|---|
| 98 | + if (priv->preamble_type) { |
|---|
| 99 | + data = vnt_rspinf_b_short_table; |
|---|
| 100 | + len = ARRAY_SIZE(vnt_rspinf_b_short_table); |
|---|
| 101 | + } else { |
|---|
| 102 | + data = vnt_rspinf_b_long_table; |
|---|
| 103 | + len = ARRAY_SIZE(vnt_rspinf_b_long_table); |
|---|
| 96 | 104 | } |
|---|
| 97 | 105 | |
|---|
| 98 | | - return RATE_1M; |
|---|
| 106 | + /* RSPINF_b_1 to RSPINF_b_11 */ |
|---|
| 107 | + ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_B_1, |
|---|
| 108 | + MESSAGE_REQUEST_MACREG, len, data); |
|---|
| 109 | + if (ret) |
|---|
| 110 | + return ret; |
|---|
| 111 | + |
|---|
| 112 | + if (bb_type == BB_TYPE_11A) { |
|---|
| 113 | + data = vnt_rspinf_a_table; |
|---|
| 114 | + len = ARRAY_SIZE(vnt_rspinf_a_table); |
|---|
| 115 | + } else { |
|---|
| 116 | + data = vnt_rspinf_gb_table; |
|---|
| 117 | + len = ARRAY_SIZE(vnt_rspinf_gb_table); |
|---|
| 118 | + } |
|---|
| 119 | + |
|---|
| 120 | + /* RSPINF_a_6 to RSPINF_a_72 */ |
|---|
| 121 | + return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_A_6, |
|---|
| 122 | + MESSAGE_REQUEST_MACREG, len, data); |
|---|
| 99 | 123 | } |
|---|
| 100 | 124 | |
|---|
| 101 | | -/* |
|---|
| 102 | | - * Description: Get OFDM mode basic rate |
|---|
| 103 | | - * |
|---|
| 104 | | - * Parameters: |
|---|
| 105 | | - * In: |
|---|
| 106 | | - * priv - The adapter to be set |
|---|
| 107 | | - * rate_idx - Receiving data rate |
|---|
| 108 | | - * Out: |
|---|
| 109 | | - * none |
|---|
| 110 | | - * |
|---|
| 111 | | - * Return Value: response Control frame rate |
|---|
| 112 | | - * |
|---|
| 113 | | - */ |
|---|
| 114 | | -static u16 vnt_get_ofdm_rate(struct vnt_private *priv, u16 rate_idx) |
|---|
| 115 | | -{ |
|---|
| 116 | | - u16 ui = rate_idx; |
|---|
| 117 | | - |
|---|
| 118 | | - dev_dbg(&priv->usb->dev, "%s basic rate: %d\n", |
|---|
| 119 | | - __func__, priv->basic_rates); |
|---|
| 120 | | - |
|---|
| 121 | | - if (!vnt_ofdm_min_rate(priv)) { |
|---|
| 122 | | - dev_dbg(&priv->usb->dev, "%s (NO OFDM) %d\n", |
|---|
| 123 | | - __func__, rate_idx); |
|---|
| 124 | | - if (rate_idx > RATE_24M) |
|---|
| 125 | | - rate_idx = RATE_24M; |
|---|
| 126 | | - return rate_idx; |
|---|
| 127 | | - } |
|---|
| 128 | | - |
|---|
| 129 | | - while (ui > RATE_11M) { |
|---|
| 130 | | - if (priv->basic_rates & (1 << ui)) { |
|---|
| 131 | | - dev_dbg(&priv->usb->dev, "%s rate: %d\n", |
|---|
| 132 | | - __func__, ui); |
|---|
| 133 | | - return ui; |
|---|
| 134 | | - } |
|---|
| 135 | | - ui--; |
|---|
| 136 | | - } |
|---|
| 137 | | - |
|---|
| 138 | | - dev_dbg(&priv->usb->dev, "%s basic rate: 24M\n", __func__); |
|---|
| 139 | | - |
|---|
| 140 | | - return RATE_24M; |
|---|
| 141 | | -} |
|---|
| 142 | | - |
|---|
| 143 | | -/* |
|---|
| 144 | | - * Description: Calculate TxRate and RsvTime fields for RSPINF in OFDM mode. |
|---|
| 145 | | - * |
|---|
| 146 | | - * Parameters: |
|---|
| 147 | | - * In: |
|---|
| 148 | | - * rate - Tx Rate |
|---|
| 149 | | - * bb_type - Tx Packet type |
|---|
| 150 | | - * Out: |
|---|
| 151 | | - * tx_rate - pointer to RSPINF TxRate field |
|---|
| 152 | | - * rsv_time- pointer to RSPINF RsvTime field |
|---|
| 153 | | - * |
|---|
| 154 | | - * Return Value: none |
|---|
| 155 | | - * |
|---|
| 156 | | - */ |
|---|
| 157 | | -static void vnt_calculate_ofdm_rate(u16 rate, u8 bb_type, |
|---|
| 158 | | - u8 *tx_rate, u8 *rsv_time) |
|---|
| 159 | | -{ |
|---|
| 160 | | - switch (rate) { |
|---|
| 161 | | - case RATE_6M: |
|---|
| 162 | | - if (bb_type == BB_TYPE_11A) { |
|---|
| 163 | | - *tx_rate = 0x9b; |
|---|
| 164 | | - *rsv_time = 24; |
|---|
| 165 | | - } else { |
|---|
| 166 | | - *tx_rate = 0x8b; |
|---|
| 167 | | - *rsv_time = 30; |
|---|
| 168 | | - } |
|---|
| 169 | | - break; |
|---|
| 170 | | - case RATE_9M: |
|---|
| 171 | | - if (bb_type == BB_TYPE_11A) { |
|---|
| 172 | | - *tx_rate = 0x9f; |
|---|
| 173 | | - *rsv_time = 16; |
|---|
| 174 | | - } else { |
|---|
| 175 | | - *tx_rate = 0x8f; |
|---|
| 176 | | - *rsv_time = 22; |
|---|
| 177 | | - } |
|---|
| 178 | | - break; |
|---|
| 179 | | - case RATE_12M: |
|---|
| 180 | | - if (bb_type == BB_TYPE_11A) { |
|---|
| 181 | | - *tx_rate = 0x9a; |
|---|
| 182 | | - *rsv_time = 12; |
|---|
| 183 | | - } else { |
|---|
| 184 | | - *tx_rate = 0x8a; |
|---|
| 185 | | - *rsv_time = 18; |
|---|
| 186 | | - } |
|---|
| 187 | | - break; |
|---|
| 188 | | - case RATE_18M: |
|---|
| 189 | | - if (bb_type == BB_TYPE_11A) { |
|---|
| 190 | | - *tx_rate = 0x9e; |
|---|
| 191 | | - *rsv_time = 8; |
|---|
| 192 | | - } else { |
|---|
| 193 | | - *tx_rate = 0x8e; |
|---|
| 194 | | - *rsv_time = 14; |
|---|
| 195 | | - } |
|---|
| 196 | | - break; |
|---|
| 197 | | - case RATE_36M: |
|---|
| 198 | | - if (bb_type == BB_TYPE_11A) { |
|---|
| 199 | | - *tx_rate = 0x9d; |
|---|
| 200 | | - *rsv_time = 4; |
|---|
| 201 | | - } else { |
|---|
| 202 | | - *tx_rate = 0x8d; |
|---|
| 203 | | - *rsv_time = 10; |
|---|
| 204 | | - } |
|---|
| 205 | | - break; |
|---|
| 206 | | - case RATE_48M: |
|---|
| 207 | | - if (bb_type == BB_TYPE_11A) { |
|---|
| 208 | | - *tx_rate = 0x98; |
|---|
| 209 | | - *rsv_time = 4; |
|---|
| 210 | | - } else { |
|---|
| 211 | | - *tx_rate = 0x88; |
|---|
| 212 | | - *rsv_time = 10; |
|---|
| 213 | | - } |
|---|
| 214 | | - break; |
|---|
| 215 | | - case RATE_54M: |
|---|
| 216 | | - if (bb_type == BB_TYPE_11A) { |
|---|
| 217 | | - *tx_rate = 0x9c; |
|---|
| 218 | | - *rsv_time = 4; |
|---|
| 219 | | - } else { |
|---|
| 220 | | - *tx_rate = 0x8c; |
|---|
| 221 | | - *rsv_time = 10; |
|---|
| 222 | | - } |
|---|
| 223 | | - break; |
|---|
| 224 | | - case RATE_24M: |
|---|
| 225 | | - default: |
|---|
| 226 | | - if (bb_type == BB_TYPE_11A) { |
|---|
| 227 | | - *tx_rate = 0x99; |
|---|
| 228 | | - *rsv_time = 8; |
|---|
| 229 | | - } else { |
|---|
| 230 | | - *tx_rate = 0x89; |
|---|
| 231 | | - *rsv_time = 14; |
|---|
| 232 | | - } |
|---|
| 233 | | - break; |
|---|
| 234 | | - } |
|---|
| 235 | | -} |
|---|
| 236 | | - |
|---|
| 237 | | -/* |
|---|
| 238 | | - * Description: Set RSPINF |
|---|
| 239 | | - * |
|---|
| 240 | | - * Parameters: |
|---|
| 241 | | - * In: |
|---|
| 242 | | - * pDevice - The adapter to be set |
|---|
| 243 | | - * Out: |
|---|
| 244 | | - * none |
|---|
| 245 | | - * |
|---|
| 246 | | - * Return Value: None. |
|---|
| 247 | | - * |
|---|
| 248 | | - */ |
|---|
| 249 | | - |
|---|
| 250 | | -void vnt_set_rspinf(struct vnt_private *priv, u8 bb_type) |
|---|
| 251 | | -{ |
|---|
| 252 | | - struct vnt_phy_field phy[4]; |
|---|
| 253 | | - u8 tx_rate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */ |
|---|
| 254 | | - u8 rsv_time[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; |
|---|
| 255 | | - u8 data[34]; |
|---|
| 256 | | - int i; |
|---|
| 257 | | - |
|---|
| 258 | | - /*RSPINF_b_1*/ |
|---|
| 259 | | - vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_1M), |
|---|
| 260 | | - PK_TYPE_11B, &phy[0]); |
|---|
| 261 | | - |
|---|
| 262 | | - /*RSPINF_b_2*/ |
|---|
| 263 | | - vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_2M), |
|---|
| 264 | | - PK_TYPE_11B, &phy[1]); |
|---|
| 265 | | - |
|---|
| 266 | | - /*RSPINF_b_5*/ |
|---|
| 267 | | - vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_5M), |
|---|
| 268 | | - PK_TYPE_11B, &phy[2]); |
|---|
| 269 | | - |
|---|
| 270 | | - /*RSPINF_b_11*/ |
|---|
| 271 | | - vnt_get_phy_field(priv, 14, vnt_get_cck_rate(priv, RATE_11M), |
|---|
| 272 | | - PK_TYPE_11B, &phy[3]); |
|---|
| 273 | | - |
|---|
| 274 | | - /*RSPINF_a_6*/ |
|---|
| 275 | | - vnt_calculate_ofdm_rate(RATE_6M, bb_type, &tx_rate[0], &rsv_time[0]); |
|---|
| 276 | | - |
|---|
| 277 | | - /*RSPINF_a_9*/ |
|---|
| 278 | | - vnt_calculate_ofdm_rate(RATE_9M, bb_type, &tx_rate[1], &rsv_time[1]); |
|---|
| 279 | | - |
|---|
| 280 | | - /*RSPINF_a_12*/ |
|---|
| 281 | | - vnt_calculate_ofdm_rate(RATE_12M, bb_type, &tx_rate[2], &rsv_time[2]); |
|---|
| 282 | | - |
|---|
| 283 | | - /*RSPINF_a_18*/ |
|---|
| 284 | | - vnt_calculate_ofdm_rate(RATE_18M, bb_type, &tx_rate[3], &rsv_time[3]); |
|---|
| 285 | | - |
|---|
| 286 | | - /*RSPINF_a_24*/ |
|---|
| 287 | | - vnt_calculate_ofdm_rate(RATE_24M, bb_type, &tx_rate[4], &rsv_time[4]); |
|---|
| 288 | | - |
|---|
| 289 | | - /*RSPINF_a_36*/ |
|---|
| 290 | | - vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_36M), |
|---|
| 291 | | - bb_type, &tx_rate[5], &rsv_time[5]); |
|---|
| 292 | | - |
|---|
| 293 | | - /*RSPINF_a_48*/ |
|---|
| 294 | | - vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_48M), |
|---|
| 295 | | - bb_type, &tx_rate[6], &rsv_time[6]); |
|---|
| 296 | | - |
|---|
| 297 | | - /*RSPINF_a_54*/ |
|---|
| 298 | | - vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M), |
|---|
| 299 | | - bb_type, &tx_rate[7], &rsv_time[7]); |
|---|
| 300 | | - |
|---|
| 301 | | - /*RSPINF_a_72*/ |
|---|
| 302 | | - vnt_calculate_ofdm_rate(vnt_get_ofdm_rate(priv, RATE_54M), |
|---|
| 303 | | - bb_type, &tx_rate[8], &rsv_time[8]); |
|---|
| 304 | | - |
|---|
| 305 | | - put_unaligned(phy[0].len, (u16 *)&data[0]); |
|---|
| 306 | | - data[2] = phy[0].signal; |
|---|
| 307 | | - data[3] = phy[0].service; |
|---|
| 308 | | - |
|---|
| 309 | | - put_unaligned(phy[1].len, (u16 *)&data[4]); |
|---|
| 310 | | - data[6] = phy[1].signal; |
|---|
| 311 | | - data[7] = phy[1].service; |
|---|
| 312 | | - |
|---|
| 313 | | - put_unaligned(phy[2].len, (u16 *)&data[8]); |
|---|
| 314 | | - data[10] = phy[2].signal; |
|---|
| 315 | | - data[11] = phy[2].service; |
|---|
| 316 | | - |
|---|
| 317 | | - put_unaligned(phy[3].len, (u16 *)&data[12]); |
|---|
| 318 | | - data[14] = phy[3].signal; |
|---|
| 319 | | - data[15] = phy[3].service; |
|---|
| 320 | | - |
|---|
| 321 | | - for (i = 0; i < 9; i++) { |
|---|
| 322 | | - data[16 + i * 2] = tx_rate[i]; |
|---|
| 323 | | - data[16 + i * 2 + 1] = rsv_time[i]; |
|---|
| 324 | | - } |
|---|
| 325 | | - |
|---|
| 326 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_RSPINF_B_1, |
|---|
| 327 | | - MESSAGE_REQUEST_MACREG, 34, &data[0]); |
|---|
| 328 | | -} |
|---|
| 329 | | - |
|---|
| 330 | | -/* |
|---|
| 331 | | - * Description: Update IFS |
|---|
| 332 | | - * |
|---|
| 333 | | - * Parameters: |
|---|
| 334 | | - * In: |
|---|
| 335 | | - * priv - The adapter to be set |
|---|
| 336 | | - * Out: |
|---|
| 337 | | - * none |
|---|
| 338 | | - * |
|---|
| 339 | | - * Return Value: None. |
|---|
| 340 | | - * |
|---|
| 341 | | - */ |
|---|
| 342 | | -void vnt_update_ifs(struct vnt_private *priv) |
|---|
| 125 | +int vnt_update_ifs(struct vnt_private *priv) |
|---|
| 343 | 126 | { |
|---|
| 344 | 127 | u8 max_min = 0; |
|---|
| 345 | 128 | u8 data[4]; |
|---|
| 129 | + int ret; |
|---|
| 346 | 130 | |
|---|
| 347 | 131 | if (priv->packet_type == PK_TYPE_11A) { |
|---|
| 348 | 132 | priv->slot = C_SLOT_SHORT; |
|---|
| .. | .. |
|---|
| 365 | 149 | |
|---|
| 366 | 150 | priv->eifs = C_EIFS; |
|---|
| 367 | 151 | |
|---|
| 368 | | - switch (priv->rf_type) { |
|---|
| 369 | | - case RF_VT3226D0: |
|---|
| 370 | | - if (priv->bb_type != BB_TYPE_11B) { |
|---|
| 371 | | - priv->sifs -= 1; |
|---|
| 372 | | - priv->difs -= 1; |
|---|
| 373 | | - break; |
|---|
| 374 | | - } |
|---|
| 375 | | - /* fall through */ |
|---|
| 376 | | - case RF_AIROHA7230: |
|---|
| 377 | | - case RF_AL2230: |
|---|
| 378 | | - case RF_AL2230S: |
|---|
| 379 | | - if (priv->bb_type != BB_TYPE_11B) |
|---|
| 380 | | - break; |
|---|
| 381 | | - /* fall through */ |
|---|
| 382 | | - case RF_RFMD2959: |
|---|
| 383 | | - case RF_VT3226: |
|---|
| 384 | | - case RF_VT3342A0: |
|---|
| 385 | | - priv->sifs -= 3; |
|---|
| 386 | | - priv->difs -= 3; |
|---|
| 387 | | - break; |
|---|
| 388 | | - case RF_MAXIM2829: |
|---|
| 389 | | - if (priv->bb_type == BB_TYPE_11A) { |
|---|
| 390 | | - priv->sifs -= 5; |
|---|
| 391 | | - priv->difs -= 5; |
|---|
| 392 | | - } else { |
|---|
| 393 | | - priv->sifs -= 2; |
|---|
| 394 | | - priv->difs -= 2; |
|---|
| 395 | | - } |
|---|
| 396 | | - |
|---|
| 397 | | - break; |
|---|
| 398 | | - } |
|---|
| 399 | | - |
|---|
| 400 | 152 | data[0] = (u8)priv->sifs; |
|---|
| 401 | 153 | data[1] = (u8)priv->difs; |
|---|
| 402 | 154 | data[2] = (u8)priv->eifs; |
|---|
| 403 | 155 | data[3] = (u8)priv->slot; |
|---|
| 404 | 156 | |
|---|
| 405 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_SIFS, |
|---|
| 406 | | - MESSAGE_REQUEST_MACREG, 4, &data[0]); |
|---|
| 157 | + ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_SIFS, |
|---|
| 158 | + MESSAGE_REQUEST_MACREG, 4, &data[0]); |
|---|
| 159 | + if (ret) |
|---|
| 160 | + return ret; |
|---|
| 407 | 161 | |
|---|
| 408 | 162 | max_min |= 0xa0; |
|---|
| 409 | 163 | |
|---|
| 410 | | - vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_CWMAXMIN0, |
|---|
| 411 | | - MESSAGE_REQUEST_MACREG, 1, &max_min); |
|---|
| 164 | + return vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_CWMAXMIN0, |
|---|
| 165 | + MESSAGE_REQUEST_MACREG, 1, &max_min); |
|---|
| 412 | 166 | } |
|---|
| 413 | 167 | |
|---|
| 414 | 168 | void vnt_update_top_rates(struct vnt_private *priv) |
|---|
| 415 | 169 | { |
|---|
| 416 | | - u8 top_ofdm = RATE_24M, top_cck = RATE_1M; |
|---|
| 417 | | - u8 i; |
|---|
| 170 | + int pos; |
|---|
| 418 | 171 | |
|---|
| 419 | | - /*Determines the highest basic rate.*/ |
|---|
| 420 | | - for (i = RATE_54M; i >= RATE_6M; i--) { |
|---|
| 421 | | - if (priv->basic_rates & (u16)(1 << i)) { |
|---|
| 422 | | - top_ofdm = i; |
|---|
| 423 | | - break; |
|---|
| 424 | | - } |
|---|
| 425 | | - } |
|---|
| 172 | + pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M)); |
|---|
| 173 | + priv->top_ofdm_basic_rate = pos ? (pos - 1) : RATE_24M; |
|---|
| 426 | 174 | |
|---|
| 427 | | - priv->top_ofdm_basic_rate = top_ofdm; |
|---|
| 428 | | - |
|---|
| 429 | | - for (i = RATE_11M;; i--) { |
|---|
| 430 | | - if (priv->basic_rates & (u16)(1 << i)) { |
|---|
| 431 | | - top_cck = i; |
|---|
| 432 | | - break; |
|---|
| 433 | | - } |
|---|
| 434 | | - if (i == RATE_1M) |
|---|
| 435 | | - break; |
|---|
| 436 | | - } |
|---|
| 437 | | - |
|---|
| 438 | | - priv->top_cck_basic_rate = top_cck; |
|---|
| 175 | + pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M)); |
|---|
| 176 | + priv->top_cck_basic_rate = pos ? (pos - 1) : RATE_1M; |
|---|
| 439 | 177 | } |
|---|
| 440 | 178 | |
|---|
| 441 | | -int vnt_ofdm_min_rate(struct vnt_private *priv) |
|---|
| 179 | +bool vnt_ofdm_min_rate(struct vnt_private *priv) |
|---|
| 442 | 180 | { |
|---|
| 443 | | - int ii; |
|---|
| 444 | | - |
|---|
| 445 | | - for (ii = RATE_54M; ii >= RATE_6M; ii--) { |
|---|
| 446 | | - if ((priv->basic_rates) & ((u16)BIT(ii))) |
|---|
| 447 | | - return true; |
|---|
| 448 | | - } |
|---|
| 449 | | - |
|---|
| 450 | | - return false; |
|---|
| 181 | + return priv->basic_rates & GENMASK(RATE_54M, RATE_6M) ? true : false; |
|---|
| 451 | 182 | } |
|---|
| 452 | 183 | |
|---|
| 453 | 184 | u8 vnt_get_pkt_type(struct vnt_private *priv) |
|---|
| .. | .. |
|---|
| 479 | 210 | return tsf1 - tsf2 - (u64)cw_rxbcntsf_off[rx_rate % MAX_RATE]; |
|---|
| 480 | 211 | } |
|---|
| 481 | 212 | |
|---|
| 482 | | -/* |
|---|
| 483 | | - * Description: Sync. TSF counter to BSS |
|---|
| 484 | | - * Get TSF offset and write to HW |
|---|
| 485 | | - * |
|---|
| 486 | | - * Parameters: |
|---|
| 487 | | - * In: |
|---|
| 488 | | - * priv - The adapter to be sync. |
|---|
| 489 | | - * time_stamp - Rx BCN's TSF |
|---|
| 490 | | - * local_tsf - Local TSF |
|---|
| 491 | | - * Out: |
|---|
| 492 | | - * none |
|---|
| 493 | | - * |
|---|
| 494 | | - * Return Value: none |
|---|
| 495 | | - * |
|---|
| 496 | | - */ |
|---|
| 497 | | -void vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate, |
|---|
| 498 | | - u64 time_stamp, u64 local_tsf) |
|---|
| 213 | +int vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate, |
|---|
| 214 | + u64 time_stamp, u64 local_tsf) |
|---|
| 499 | 215 | { |
|---|
| 500 | 216 | u64 tsf_offset = 0; |
|---|
| 501 | 217 | u8 data[8]; |
|---|
| .. | .. |
|---|
| 511 | 227 | data[6] = (u8)(tsf_offset >> 48); |
|---|
| 512 | 228 | data[7] = (u8)(tsf_offset >> 56); |
|---|
| 513 | 229 | |
|---|
| 514 | | - vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, |
|---|
| 515 | | - MESSAGE_REQUEST_TSF, 0, 8, data); |
|---|
| 230 | + return vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, |
|---|
| 231 | + MESSAGE_REQUEST_TSF, 0, 8, data); |
|---|
| 516 | 232 | } |
|---|
| 517 | 233 | |
|---|
| 518 | 234 | /* |
|---|
| .. | .. |
|---|
| 587 | 303 | return tsf; |
|---|
| 588 | 304 | } |
|---|
| 589 | 305 | |
|---|
| 590 | | -/* |
|---|
| 591 | | - * Description: Set NIC TSF counter for first Beacon time |
|---|
| 592 | | - * Get NEXTTBTT from adjusted TSF and Beacon Interval |
|---|
| 593 | | - * |
|---|
| 594 | | - * Parameters: |
|---|
| 595 | | - * In: |
|---|
| 596 | | - * dwIoBase - IO Base |
|---|
| 597 | | - * beacon_interval - Beacon Interval |
|---|
| 598 | | - * Out: |
|---|
| 599 | | - * none |
|---|
| 600 | | - * |
|---|
| 601 | | - * Return Value: none |
|---|
| 602 | | - * |
|---|
| 603 | | - */ |
|---|
| 604 | | -void vnt_reset_next_tbtt(struct vnt_private *priv, u16 beacon_interval) |
|---|
| 306 | +int vnt_reset_next_tbtt(struct vnt_private *priv, u16 beacon_interval) |
|---|
| 605 | 307 | { |
|---|
| 606 | 308 | u64 next_tbtt = 0; |
|---|
| 607 | 309 | u8 data[8]; |
|---|
| .. | .. |
|---|
| 619 | 321 | data[6] = (u8)(next_tbtt >> 48); |
|---|
| 620 | 322 | data[7] = (u8)(next_tbtt >> 56); |
|---|
| 621 | 323 | |
|---|
| 622 | | - vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, |
|---|
| 623 | | - MESSAGE_REQUEST_TBTT, 0, 8, data); |
|---|
| 324 | + return vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, |
|---|
| 325 | + MESSAGE_REQUEST_TBTT, 0, 8, data); |
|---|
| 624 | 326 | } |
|---|
| 625 | 327 | |
|---|
| 626 | | -/* |
|---|
| 627 | | - * Description: Sync NIC TSF counter for Beacon time |
|---|
| 628 | | - * Get NEXTTBTT and write to HW |
|---|
| 629 | | - * |
|---|
| 630 | | - * Parameters: |
|---|
| 631 | | - * In: |
|---|
| 632 | | - * priv - The adapter to be set |
|---|
| 633 | | - * tsf - Current TSF counter |
|---|
| 634 | | - * beacon_interval - Beacon Interval |
|---|
| 635 | | - * Out: |
|---|
| 636 | | - * none |
|---|
| 637 | | - * |
|---|
| 638 | | - * Return Value: none |
|---|
| 639 | | - * |
|---|
| 640 | | - */ |
|---|
| 641 | | -void vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf, |
|---|
| 642 | | - u16 beacon_interval) |
|---|
| 328 | +int vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf, |
|---|
| 329 | + u16 beacon_interval) |
|---|
| 643 | 330 | { |
|---|
| 644 | 331 | u8 data[8]; |
|---|
| 332 | + int ret; |
|---|
| 645 | 333 | |
|---|
| 646 | 334 | tsf = vnt_get_next_tbtt(tsf, beacon_interval); |
|---|
| 647 | 335 | |
|---|
| .. | .. |
|---|
| 654 | 342 | data[6] = (u8)(tsf >> 48); |
|---|
| 655 | 343 | data[7] = (u8)(tsf >> 56); |
|---|
| 656 | 344 | |
|---|
| 657 | | - vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, |
|---|
| 658 | | - MESSAGE_REQUEST_TBTT, 0, 8, data); |
|---|
| 345 | + ret = vnt_control_out(priv, MESSAGE_TYPE_SET_TSFTBTT, |
|---|
| 346 | + MESSAGE_REQUEST_TBTT, 0, 8, data); |
|---|
| 347 | + if (ret) |
|---|
| 348 | + return ret; |
|---|
| 659 | 349 | |
|---|
| 660 | 350 | dev_dbg(&priv->usb->dev, "%s TBTT: %8llx\n", __func__, tsf); |
|---|
| 351 | + return 0; |
|---|
| 661 | 352 | } |
|---|
| 662 | 353 | |
|---|
| 663 | 354 | /* |
|---|
| .. | .. |
|---|
| 674 | 365 | */ |
|---|
| 675 | 366 | int vnt_radio_power_off(struct vnt_private *priv) |
|---|
| 676 | 367 | { |
|---|
| 677 | | - int ret = true; |
|---|
| 368 | + int ret = 0; |
|---|
| 678 | 369 | |
|---|
| 679 | 370 | switch (priv->rf_type) { |
|---|
| 680 | 371 | case RF_AL2230: |
|---|
| .. | .. |
|---|
| 683 | 374 | case RF_VT3226: |
|---|
| 684 | 375 | case RF_VT3226D0: |
|---|
| 685 | 376 | case RF_VT3342A0: |
|---|
| 686 | | - vnt_mac_reg_bits_off(priv, MAC_REG_SOFTPWRCTL, |
|---|
| 687 | | - (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); |
|---|
| 377 | + ret = vnt_mac_reg_bits_off(priv, MAC_REG_SOFTPWRCTL, |
|---|
| 378 | + (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); |
|---|
| 688 | 379 | break; |
|---|
| 689 | 380 | } |
|---|
| 690 | 381 | |
|---|
| 691 | | - vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_RXON); |
|---|
| 382 | + if (ret) |
|---|
| 383 | + goto end; |
|---|
| 692 | 384 | |
|---|
| 693 | | - vnt_set_deep_sleep(priv); |
|---|
| 385 | + ret = vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_RXON); |
|---|
| 386 | + if (ret) |
|---|
| 387 | + goto end; |
|---|
| 694 | 388 | |
|---|
| 695 | | - vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD); |
|---|
| 389 | + ret = vnt_set_deep_sleep(priv); |
|---|
| 390 | + if (ret) |
|---|
| 391 | + goto end; |
|---|
| 696 | 392 | |
|---|
| 393 | + ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD); |
|---|
| 394 | + |
|---|
| 395 | +end: |
|---|
| 697 | 396 | return ret; |
|---|
| 698 | 397 | } |
|---|
| 699 | 398 | |
|---|
| .. | .. |
|---|
| 711 | 410 | */ |
|---|
| 712 | 411 | int vnt_radio_power_on(struct vnt_private *priv) |
|---|
| 713 | 412 | { |
|---|
| 714 | | - int ret = true; |
|---|
| 413 | + int ret = 0; |
|---|
| 715 | 414 | |
|---|
| 716 | | - vnt_exit_deep_sleep(priv); |
|---|
| 415 | + ret = vnt_exit_deep_sleep(priv); |
|---|
| 416 | + if (ret) |
|---|
| 417 | + return ret; |
|---|
| 717 | 418 | |
|---|
| 718 | | - vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON); |
|---|
| 419 | + ret = vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON); |
|---|
| 420 | + if (ret) |
|---|
| 421 | + return ret; |
|---|
| 719 | 422 | |
|---|
| 720 | 423 | switch (priv->rf_type) { |
|---|
| 721 | 424 | case RF_AL2230: |
|---|
| .. | .. |
|---|
| 724 | 427 | case RF_VT3226: |
|---|
| 725 | 428 | case RF_VT3226D0: |
|---|
| 726 | 429 | case RF_VT3342A0: |
|---|
| 727 | | - vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL, |
|---|
| 728 | | - (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3)); |
|---|
| 729 | | - break; |
|---|
| 430 | + ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL, |
|---|
| 431 | + (SOFTPWRCTL_SWPE2 | |
|---|
| 432 | + SOFTPWRCTL_SWPE3)); |
|---|
| 433 | + if (ret) |
|---|
| 434 | + return ret; |
|---|
| 730 | 435 | } |
|---|
| 731 | 436 | |
|---|
| 732 | | - vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD); |
|---|
| 733 | | - |
|---|
| 734 | | - return ret; |
|---|
| 437 | + return vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD); |
|---|
| 735 | 438 | } |
|---|
| 736 | 439 | |
|---|
| 737 | | -void vnt_set_bss_mode(struct vnt_private *priv) |
|---|
| 440 | +int vnt_set_bss_mode(struct vnt_private *priv) |
|---|
| 738 | 441 | { |
|---|
| 442 | + int ret; |
|---|
| 443 | + unsigned char type = priv->bb_type; |
|---|
| 444 | + unsigned char data = 0; |
|---|
| 445 | + unsigned char bb_vga_0 = 0x1c; |
|---|
| 446 | + unsigned char bb_vga_2_3 = 0x00; |
|---|
| 447 | + |
|---|
| 739 | 448 | if (priv->rf_type == RF_AIROHA7230 && priv->bb_type == BB_TYPE_11A) |
|---|
| 740 | | - vnt_mac_set_bb_type(priv, BB_TYPE_11G); |
|---|
| 741 | | - else |
|---|
| 742 | | - vnt_mac_set_bb_type(priv, priv->bb_type); |
|---|
| 449 | + type = BB_TYPE_11G; |
|---|
| 450 | + |
|---|
| 451 | + ret = vnt_mac_set_bb_type(priv, type); |
|---|
| 452 | + if (ret) |
|---|
| 453 | + return ret; |
|---|
| 743 | 454 | |
|---|
| 744 | 455 | priv->packet_type = vnt_get_pkt_type(priv); |
|---|
| 745 | 456 | |
|---|
| 746 | | - if (priv->bb_type == BB_TYPE_11A) |
|---|
| 747 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x03); |
|---|
| 748 | | - else if (priv->bb_type == BB_TYPE_11B) |
|---|
| 749 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x02); |
|---|
| 750 | | - else if (priv->bb_type == BB_TYPE_11G) |
|---|
| 751 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x88, 0x08); |
|---|
| 752 | | - |
|---|
| 753 | | - vnt_update_ifs(priv); |
|---|
| 754 | | - vnt_set_rspinf(priv, (u8)priv->bb_type); |
|---|
| 755 | | - |
|---|
| 756 | 457 | if (priv->bb_type == BB_TYPE_11A) { |
|---|
| 757 | | - if (priv->rf_type == RF_AIROHA7230) { |
|---|
| 758 | | - priv->bb_vga[0] = 0x20; |
|---|
| 759 | | - |
|---|
| 760 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, |
|---|
| 761 | | - 0xe7, priv->bb_vga[0]); |
|---|
| 762 | | - } |
|---|
| 763 | | - |
|---|
| 764 | | - priv->bb_vga[2] = 0x10; |
|---|
| 765 | | - priv->bb_vga[3] = 0x10; |
|---|
| 766 | | - } else { |
|---|
| 767 | | - if (priv->rf_type == RF_AIROHA7230) { |
|---|
| 768 | | - priv->bb_vga[0] = 0x1c; |
|---|
| 769 | | - |
|---|
| 770 | | - vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, |
|---|
| 771 | | - 0xe7, priv->bb_vga[0]); |
|---|
| 772 | | - } |
|---|
| 773 | | - |
|---|
| 774 | | - priv->bb_vga[2] = 0x0; |
|---|
| 775 | | - priv->bb_vga[3] = 0x0; |
|---|
| 458 | + data = 0x03; |
|---|
| 459 | + bb_vga_0 = 0x20; |
|---|
| 460 | + bb_vga_2_3 = 0x10; |
|---|
| 461 | + } else if (priv->bb_type == BB_TYPE_11B) { |
|---|
| 462 | + data = 0x02; |
|---|
| 463 | + } else if (priv->bb_type == BB_TYPE_11G) { |
|---|
| 464 | + data = 0x08; |
|---|
| 776 | 465 | } |
|---|
| 777 | 466 | |
|---|
| 778 | | - vnt_set_vga_gain_offset(priv, priv->bb_vga[0]); |
|---|
| 467 | + if (data) { |
|---|
| 468 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, |
|---|
| 469 | + 0x88, data); |
|---|
| 470 | + if (ret) |
|---|
| 471 | + return ret; |
|---|
| 472 | + } |
|---|
| 473 | + |
|---|
| 474 | + ret = vnt_update_ifs(priv); |
|---|
| 475 | + if (ret) |
|---|
| 476 | + return ret; |
|---|
| 477 | + |
|---|
| 478 | + ret = vnt_set_rspinf(priv, priv->bb_type); |
|---|
| 479 | + if (ret) |
|---|
| 480 | + return ret; |
|---|
| 481 | + |
|---|
| 482 | + if (priv->rf_type == RF_AIROHA7230) { |
|---|
| 483 | + priv->bb_vga[0] = bb_vga_0; |
|---|
| 484 | + |
|---|
| 485 | + ret = vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, |
|---|
| 486 | + 0xe7, priv->bb_vga[0]); |
|---|
| 487 | + if (ret) |
|---|
| 488 | + return ret; |
|---|
| 489 | + } |
|---|
| 490 | + |
|---|
| 491 | + priv->bb_vga[2] = bb_vga_2_3; |
|---|
| 492 | + priv->bb_vga[3] = bb_vga_2_3; |
|---|
| 493 | + |
|---|
| 494 | + return vnt_set_vga_gain_offset(priv, priv->bb_vga[0]); |
|---|
| 779 | 495 | } |
|---|