1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 2 /* Copyright(c) 2018-2019 Realtek Corporation 3 */ 4 5 #ifndef __RTK_MAIN_H_ 6 #define __RTK_MAIN_H_ 7 8 #include <net/mac80211.h> 9 #include <linux/vmalloc.h> 10 #include <linux/firmware.h> 11 #include <linux/average.h> 12 #include <linux/bitops.h> 13 #include <linux/bitfield.h> 14 #include <linux/interrupt.h> 15 16 #include "util.h" 17 18 #define RTW_MAX_MAC_ID_NUM 32 19 #define RTW_MAX_SEC_CAM_NUM 32 20 #define MAX_PG_CAM_BACKUP_NUM 8 21 22 #define RTW_MAX_PATTERN_NUM 12 23 #define RTW_MAX_PATTERN_MASK_SIZE 16 24 #define RTW_MAX_PATTERN_SIZE 128 25 26 #define RTW_WATCH_DOG_DELAY_TIME round_jiffies_relative(HZ * 2) 27 28 #define RFREG_MASK 0xfffff 29 #define INV_RF_DATA 0xffffffff 30 #define TX_PAGE_SIZE_SHIFT 7 31 32 #define RTW_CHANNEL_WIDTH_MAX 3 33 #define RTW_RF_PATH_MAX 4 34 #define HW_FEATURE_LEN 13 35 36 #define RTW_TP_SHIFT 18 /* bytes/2s --> Mbps */ 37 38 extern bool rtw_bf_support; 39 extern unsigned int rtw_fw_lps_deep_mode; 40 extern unsigned int rtw_debug_mask; 41 extern const struct ieee80211_ops rtw_ops; 42 extern struct rtw_chip_info rtw8822b_hw_spec; 43 extern struct rtw_chip_info rtw8822c_hw_spec; 44 45 #define RTW_MAX_CHANNEL_NUM_2G 14 46 #define RTW_MAX_CHANNEL_NUM_5G 49 47 48 struct rtw_dev; 49 50 enum rtw_hci_type { 51 RTW_HCI_TYPE_PCIE, 52 RTW_HCI_TYPE_USB, 53 RTW_HCI_TYPE_SDIO, 54 55 RTW_HCI_TYPE_UNDEFINE, 56 }; 57 58 struct rtw_hci { 59 struct rtw_hci_ops *ops; 60 enum rtw_hci_type type; 61 62 u32 rpwm_addr; 63 u32 cpwm_addr; 64 65 u8 bulkout_num; 66 }; 67 68 #define IS_CH_5G_BAND_1(channel) ((channel) >= 36 && (channel <= 48)) 69 #define IS_CH_5G_BAND_2(channel) ((channel) >= 52 && (channel <= 64)) 70 #define IS_CH_5G_BAND_3(channel) ((channel) >= 100 && (channel <= 144)) 71 #define IS_CH_5G_BAND_4(channel) ((channel) >= 149 && (channel <= 177)) 72 73 #define IS_CH_5G_BAND_MID(channel) \ 74 (IS_CH_5G_BAND_2(channel) || IS_CH_5G_BAND_3(channel)) 75 76 #define IS_CH_2G_BAND(channel) ((channel) <= 14) 77 #define IS_CH_5G_BAND(channel) \ 78 (IS_CH_5G_BAND_1(channel) || IS_CH_5G_BAND_2(channel) || \ 79 IS_CH_5G_BAND_3(channel) || IS_CH_5G_BAND_4(channel)) 80 81 enum rtw_supported_band { 82 RTW_BAND_2G = 1 << 0, 83 RTW_BAND_5G = 1 << 1, 84 RTW_BAND_60G = 1 << 2, 85 86 RTW_BAND_MAX, 87 }; 88 89 /* now, support upto 80M bw */ 90 #define RTW_MAX_CHANNEL_WIDTH RTW_CHANNEL_WIDTH_80 91 92 enum rtw_bandwidth { 93 RTW_CHANNEL_WIDTH_20 = 0, 94 RTW_CHANNEL_WIDTH_40 = 1, 95 RTW_CHANNEL_WIDTH_80 = 2, 96 RTW_CHANNEL_WIDTH_160 = 3, 97 RTW_CHANNEL_WIDTH_80_80 = 4, 98 RTW_CHANNEL_WIDTH_5 = 5, 99 RTW_CHANNEL_WIDTH_10 = 6, 100 }; 101 102 enum rtw_sc_offset { 103 RTW_SC_DONT_CARE = 0, 104 RTW_SC_20_UPPER = 1, 105 RTW_SC_20_LOWER = 2, 106 RTW_SC_20_UPMOST = 3, 107 RTW_SC_20_LOWEST = 4, 108 RTW_SC_40_UPPER = 9, 109 RTW_SC_40_LOWER = 10, 110 }; 111 112 enum rtw_net_type { 113 RTW_NET_NO_LINK = 0, 114 RTW_NET_AD_HOC = 1, 115 RTW_NET_MGD_LINKED = 2, 116 RTW_NET_AP_MODE = 3, 117 }; 118 119 enum rtw_rf_type { 120 RF_1T1R = 0, 121 RF_1T2R = 1, 122 RF_2T2R = 2, 123 RF_2T3R = 3, 124 RF_2T4R = 4, 125 RF_3T3R = 5, 126 RF_3T4R = 6, 127 RF_4T4R = 7, 128 RF_TYPE_MAX, 129 }; 130 131 enum rtw_rf_path { 132 RF_PATH_A = 0, 133 RF_PATH_B = 1, 134 RF_PATH_C = 2, 135 RF_PATH_D = 3, 136 }; 137 138 enum rtw_bb_path { 139 BB_PATH_A = BIT(0), 140 BB_PATH_B = BIT(1), 141 BB_PATH_C = BIT(2), 142 BB_PATH_D = BIT(3), 143 144 BB_PATH_AB = (BB_PATH_A | BB_PATH_B), 145 BB_PATH_AC = (BB_PATH_A | BB_PATH_C), 146 BB_PATH_AD = (BB_PATH_A | BB_PATH_D), 147 BB_PATH_BC = (BB_PATH_B | BB_PATH_C), 148 BB_PATH_BD = (BB_PATH_B | BB_PATH_D), 149 BB_PATH_CD = (BB_PATH_C | BB_PATH_D), 150 151 BB_PATH_ABC = (BB_PATH_A | BB_PATH_B | BB_PATH_C), 152 BB_PATH_ABD = (BB_PATH_A | BB_PATH_B | BB_PATH_D), 153 BB_PATH_ACD = (BB_PATH_A | BB_PATH_C | BB_PATH_D), 154 BB_PATH_BCD = (BB_PATH_B | BB_PATH_C | BB_PATH_D), 155 156 BB_PATH_ABCD = (BB_PATH_A | BB_PATH_B | BB_PATH_C | BB_PATH_D), 157 }; 158 159 enum rtw_rate_section { 160 RTW_RATE_SECTION_CCK = 0, 161 RTW_RATE_SECTION_OFDM, 162 RTW_RATE_SECTION_HT_1S, 163 RTW_RATE_SECTION_HT_2S, 164 RTW_RATE_SECTION_VHT_1S, 165 RTW_RATE_SECTION_VHT_2S, 166 167 /* keep last */ 168 RTW_RATE_SECTION_MAX, 169 }; 170 171 enum rtw_wireless_set { 172 WIRELESS_CCK = 0x00000001, 173 WIRELESS_OFDM = 0x00000002, 174 WIRELESS_HT = 0x00000004, 175 WIRELESS_VHT = 0x00000008, 176 }; 177 178 #define HT_STBC_EN BIT(0) 179 #define VHT_STBC_EN BIT(1) 180 #define HT_LDPC_EN BIT(0) 181 #define VHT_LDPC_EN BIT(1) 182 183 enum rtw_chip_type { 184 RTW_CHIP_TYPE_8822B, 185 RTW_CHIP_TYPE_8822C, 186 }; 187 188 enum rtw_tx_queue_type { 189 /* the order of AC queues matters */ 190 RTW_TX_QUEUE_BK = 0x0, 191 RTW_TX_QUEUE_BE = 0x1, 192 RTW_TX_QUEUE_VI = 0x2, 193 RTW_TX_QUEUE_VO = 0x3, 194 195 RTW_TX_QUEUE_BCN = 0x4, 196 RTW_TX_QUEUE_MGMT = 0x5, 197 RTW_TX_QUEUE_HI0 = 0x6, 198 RTW_TX_QUEUE_H2C = 0x7, 199 /* keep it last */ 200 RTK_MAX_TX_QUEUE_NUM 201 }; 202 203 enum rtw_rx_queue_type { 204 RTW_RX_QUEUE_MPDU = 0x0, 205 RTW_RX_QUEUE_C2H = 0x1, 206 /* keep it last */ 207 RTK_MAX_RX_QUEUE_NUM 208 }; 209 210 enum rtw_fw_type { 211 RTW_NORMAL_FW = 0x0, 212 RTW_WOWLAN_FW = 0x1, 213 }; 214 215 enum rtw_rate_index { 216 RTW_RATEID_BGN_40M_2SS = 0, 217 RTW_RATEID_BGN_40M_1SS = 1, 218 RTW_RATEID_BGN_20M_2SS = 2, 219 RTW_RATEID_BGN_20M_1SS = 3, 220 RTW_RATEID_GN_N2SS = 4, 221 RTW_RATEID_GN_N1SS = 5, 222 RTW_RATEID_BG = 6, 223 RTW_RATEID_G = 7, 224 RTW_RATEID_B_20M = 8, 225 RTW_RATEID_ARFR0_AC_2SS = 9, 226 RTW_RATEID_ARFR1_AC_1SS = 10, 227 RTW_RATEID_ARFR2_AC_2G_1SS = 11, 228 RTW_RATEID_ARFR3_AC_2G_2SS = 12, 229 RTW_RATEID_ARFR4_AC_3SS = 13, 230 RTW_RATEID_ARFR5_N_3SS = 14, 231 RTW_RATEID_ARFR7_N_4SS = 15, 232 RTW_RATEID_ARFR6_AC_4SS = 16 233 }; 234 235 enum rtw_trx_desc_rate { 236 DESC_RATE1M = 0x00, 237 DESC_RATE2M = 0x01, 238 DESC_RATE5_5M = 0x02, 239 DESC_RATE11M = 0x03, 240 241 DESC_RATE6M = 0x04, 242 DESC_RATE9M = 0x05, 243 DESC_RATE12M = 0x06, 244 DESC_RATE18M = 0x07, 245 DESC_RATE24M = 0x08, 246 DESC_RATE36M = 0x09, 247 DESC_RATE48M = 0x0a, 248 DESC_RATE54M = 0x0b, 249 250 DESC_RATEMCS0 = 0x0c, 251 DESC_RATEMCS1 = 0x0d, 252 DESC_RATEMCS2 = 0x0e, 253 DESC_RATEMCS3 = 0x0f, 254 DESC_RATEMCS4 = 0x10, 255 DESC_RATEMCS5 = 0x11, 256 DESC_RATEMCS6 = 0x12, 257 DESC_RATEMCS7 = 0x13, 258 DESC_RATEMCS8 = 0x14, 259 DESC_RATEMCS9 = 0x15, 260 DESC_RATEMCS10 = 0x16, 261 DESC_RATEMCS11 = 0x17, 262 DESC_RATEMCS12 = 0x18, 263 DESC_RATEMCS13 = 0x19, 264 DESC_RATEMCS14 = 0x1a, 265 DESC_RATEMCS15 = 0x1b, 266 DESC_RATEMCS16 = 0x1c, 267 DESC_RATEMCS17 = 0x1d, 268 DESC_RATEMCS18 = 0x1e, 269 DESC_RATEMCS19 = 0x1f, 270 DESC_RATEMCS20 = 0x20, 271 DESC_RATEMCS21 = 0x21, 272 DESC_RATEMCS22 = 0x22, 273 DESC_RATEMCS23 = 0x23, 274 DESC_RATEMCS24 = 0x24, 275 DESC_RATEMCS25 = 0x25, 276 DESC_RATEMCS26 = 0x26, 277 DESC_RATEMCS27 = 0x27, 278 DESC_RATEMCS28 = 0x28, 279 DESC_RATEMCS29 = 0x29, 280 DESC_RATEMCS30 = 0x2a, 281 DESC_RATEMCS31 = 0x2b, 282 283 DESC_RATEVHT1SS_MCS0 = 0x2c, 284 DESC_RATEVHT1SS_MCS1 = 0x2d, 285 DESC_RATEVHT1SS_MCS2 = 0x2e, 286 DESC_RATEVHT1SS_MCS3 = 0x2f, 287 DESC_RATEVHT1SS_MCS4 = 0x30, 288 DESC_RATEVHT1SS_MCS5 = 0x31, 289 DESC_RATEVHT1SS_MCS6 = 0x32, 290 DESC_RATEVHT1SS_MCS7 = 0x33, 291 DESC_RATEVHT1SS_MCS8 = 0x34, 292 DESC_RATEVHT1SS_MCS9 = 0x35, 293 294 DESC_RATEVHT2SS_MCS0 = 0x36, 295 DESC_RATEVHT2SS_MCS1 = 0x37, 296 DESC_RATEVHT2SS_MCS2 = 0x38, 297 DESC_RATEVHT2SS_MCS3 = 0x39, 298 DESC_RATEVHT2SS_MCS4 = 0x3a, 299 DESC_RATEVHT2SS_MCS5 = 0x3b, 300 DESC_RATEVHT2SS_MCS6 = 0x3c, 301 DESC_RATEVHT2SS_MCS7 = 0x3d, 302 DESC_RATEVHT2SS_MCS8 = 0x3e, 303 DESC_RATEVHT2SS_MCS9 = 0x3f, 304 305 DESC_RATEVHT3SS_MCS0 = 0x40, 306 DESC_RATEVHT3SS_MCS1 = 0x41, 307 DESC_RATEVHT3SS_MCS2 = 0x42, 308 DESC_RATEVHT3SS_MCS3 = 0x43, 309 DESC_RATEVHT3SS_MCS4 = 0x44, 310 DESC_RATEVHT3SS_MCS5 = 0x45, 311 DESC_RATEVHT3SS_MCS6 = 0x46, 312 DESC_RATEVHT3SS_MCS7 = 0x47, 313 DESC_RATEVHT3SS_MCS8 = 0x48, 314 DESC_RATEVHT3SS_MCS9 = 0x49, 315 316 DESC_RATEVHT4SS_MCS0 = 0x4a, 317 DESC_RATEVHT4SS_MCS1 = 0x4b, 318 DESC_RATEVHT4SS_MCS2 = 0x4c, 319 DESC_RATEVHT4SS_MCS3 = 0x4d, 320 DESC_RATEVHT4SS_MCS4 = 0x4e, 321 DESC_RATEVHT4SS_MCS5 = 0x4f, 322 DESC_RATEVHT4SS_MCS6 = 0x50, 323 DESC_RATEVHT4SS_MCS7 = 0x51, 324 DESC_RATEVHT4SS_MCS8 = 0x52, 325 DESC_RATEVHT4SS_MCS9 = 0x53, 326 327 DESC_RATE_MAX, 328 }; 329 330 enum rtw_regulatory_domains { 331 RTW_REGD_FCC = 0, 332 RTW_REGD_MKK = 1, 333 RTW_REGD_ETSI = 2, 334 RTW_REGD_IC = 3, 335 RTW_REGD_KCC = 4, 336 RTW_REGD_ACMA = 5, 337 RTW_REGD_CHILE = 6, 338 RTW_REGD_UKRAINE = 7, 339 RTW_REGD_MEXICO = 8, 340 RTW_REGD_WW, 341 342 RTW_REGD_MAX 343 }; 344 345 enum rtw_txq_flags { 346 RTW_TXQ_AMPDU, 347 RTW_TXQ_BLOCK_BA, 348 }; 349 350 enum rtw_flags { 351 RTW_FLAG_RUNNING, 352 RTW_FLAG_FW_RUNNING, 353 RTW_FLAG_SCANNING, 354 RTW_FLAG_INACTIVE_PS, 355 RTW_FLAG_LEISURE_PS, 356 RTW_FLAG_LEISURE_PS_DEEP, 357 RTW_FLAG_DIG_DISABLE, 358 RTW_FLAG_BUSY_TRAFFIC, 359 RTW_FLAG_WOWLAN, 360 361 NUM_OF_RTW_FLAGS, 362 }; 363 364 enum rtw_evm { 365 RTW_EVM_OFDM = 0, 366 RTW_EVM_1SS, 367 RTW_EVM_2SS_A, 368 RTW_EVM_2SS_B, 369 /* keep it last */ 370 RTW_EVM_NUM 371 }; 372 373 enum rtw_snr { 374 RTW_SNR_OFDM_A = 0, 375 RTW_SNR_OFDM_B, 376 RTW_SNR_OFDM_C, 377 RTW_SNR_OFDM_D, 378 RTW_SNR_1SS_A, 379 RTW_SNR_1SS_B, 380 RTW_SNR_1SS_C, 381 RTW_SNR_1SS_D, 382 RTW_SNR_2SS_A, 383 RTW_SNR_2SS_B, 384 RTW_SNR_2SS_C, 385 RTW_SNR_2SS_D, 386 /* keep it last */ 387 RTW_SNR_NUM 388 }; 389 390 enum rtw_wow_flags { 391 RTW_WOW_FLAG_EN_MAGIC_PKT, 392 RTW_WOW_FLAG_EN_REKEY_PKT, 393 RTW_WOW_FLAG_EN_DISCONNECT, 394 395 /* keep it last */ 396 RTW_WOW_FLAG_MAX, 397 }; 398 399 /* the power index is represented by differences, which cck-1s & ht40-1s are 400 * the base values, so for 1s's differences, there are only ht20 & ofdm 401 */ 402 struct rtw_2g_1s_pwr_idx_diff { 403 #ifdef __LITTLE_ENDIAN 404 s8 ofdm:4; 405 s8 bw20:4; 406 #else 407 s8 bw20:4; 408 s8 ofdm:4; 409 #endif 410 } __packed; 411 412 struct rtw_2g_ns_pwr_idx_diff { 413 #ifdef __LITTLE_ENDIAN 414 s8 bw20:4; 415 s8 bw40:4; 416 s8 cck:4; 417 s8 ofdm:4; 418 #else 419 s8 ofdm:4; 420 s8 cck:4; 421 s8 bw40:4; 422 s8 bw20:4; 423 #endif 424 } __packed; 425 426 struct rtw_2g_txpwr_idx { 427 u8 cck_base[6]; 428 u8 bw40_base[5]; 429 struct rtw_2g_1s_pwr_idx_diff ht_1s_diff; 430 struct rtw_2g_ns_pwr_idx_diff ht_2s_diff; 431 struct rtw_2g_ns_pwr_idx_diff ht_3s_diff; 432 struct rtw_2g_ns_pwr_idx_diff ht_4s_diff; 433 }; 434 435 struct rtw_5g_ht_1s_pwr_idx_diff { 436 #ifdef __LITTLE_ENDIAN 437 s8 ofdm:4; 438 s8 bw20:4; 439 #else 440 s8 bw20:4; 441 s8 ofdm:4; 442 #endif 443 } __packed; 444 445 struct rtw_5g_ht_ns_pwr_idx_diff { 446 #ifdef __LITTLE_ENDIAN 447 s8 bw20:4; 448 s8 bw40:4; 449 #else 450 s8 bw40:4; 451 s8 bw20:4; 452 #endif 453 } __packed; 454 455 struct rtw_5g_ofdm_ns_pwr_idx_diff { 456 #ifdef __LITTLE_ENDIAN 457 s8 ofdm_3s:4; 458 s8 ofdm_2s:4; 459 s8 ofdm_4s:4; 460 s8 res:4; 461 #else 462 s8 res:4; 463 s8 ofdm_4s:4; 464 s8 ofdm_2s:4; 465 s8 ofdm_3s:4; 466 #endif 467 } __packed; 468 469 struct rtw_5g_vht_ns_pwr_idx_diff { 470 #ifdef __LITTLE_ENDIAN 471 s8 bw160:4; 472 s8 bw80:4; 473 #else 474 s8 bw80:4; 475 s8 bw160:4; 476 #endif 477 } __packed; 478 479 struct rtw_5g_txpwr_idx { 480 u8 bw40_base[14]; 481 struct rtw_5g_ht_1s_pwr_idx_diff ht_1s_diff; 482 struct rtw_5g_ht_ns_pwr_idx_diff ht_2s_diff; 483 struct rtw_5g_ht_ns_pwr_idx_diff ht_3s_diff; 484 struct rtw_5g_ht_ns_pwr_idx_diff ht_4s_diff; 485 struct rtw_5g_ofdm_ns_pwr_idx_diff ofdm_diff; 486 struct rtw_5g_vht_ns_pwr_idx_diff vht_1s_diff; 487 struct rtw_5g_vht_ns_pwr_idx_diff vht_2s_diff; 488 struct rtw_5g_vht_ns_pwr_idx_diff vht_3s_diff; 489 struct rtw_5g_vht_ns_pwr_idx_diff vht_4s_diff; 490 }; 491 492 struct rtw_txpwr_idx { 493 struct rtw_2g_txpwr_idx pwr_idx_2g; 494 struct rtw_5g_txpwr_idx pwr_idx_5g; 495 }; 496 497 struct rtw_timer_list { 498 struct timer_list timer; 499 void (*function)(void *data); 500 void *args; 501 }; 502 503 struct rtw_channel_params { 504 u8 center_chan; 505 u8 bandwidth; 506 u8 primary_chan_idx; 507 /* center channel by different available bandwidth, 508 * val of (bw > current bandwidth) is invalid 509 */ 510 u8 cch_by_bw[RTW_MAX_CHANNEL_WIDTH + 1]; 511 }; 512 513 struct rtw_hw_reg { 514 u32 addr; 515 u32 mask; 516 }; 517 518 struct rtw_backup_info { 519 u8 len; 520 u32 reg; 521 u32 val; 522 }; 523 524 enum rtw_vif_port_set { 525 PORT_SET_MAC_ADDR = BIT(0), 526 PORT_SET_BSSID = BIT(1), 527 PORT_SET_NET_TYPE = BIT(2), 528 PORT_SET_AID = BIT(3), 529 PORT_SET_BCN_CTRL = BIT(4), 530 }; 531 532 struct rtw_vif_port { 533 struct rtw_hw_reg mac_addr; 534 struct rtw_hw_reg bssid; 535 struct rtw_hw_reg net_type; 536 struct rtw_hw_reg aid; 537 struct rtw_hw_reg bcn_ctrl; 538 }; 539 540 struct rtw_tx_pkt_info { 541 u32 tx_pkt_size; 542 u8 offset; 543 u8 pkt_offset; 544 u8 mac_id; 545 u8 rate_id; 546 u8 rate; 547 u8 qsel; 548 u8 bw; 549 u8 sec_type; 550 u8 sn; 551 bool ampdu_en; 552 u8 ampdu_factor; 553 u8 ampdu_density; 554 u16 seq; 555 bool stbc; 556 bool ldpc; 557 bool dis_rate_fallback; 558 bool bmc; 559 bool use_rate; 560 bool ls; 561 bool fs; 562 bool short_gi; 563 bool report; 564 bool rts; 565 }; 566 567 struct rtw_rx_pkt_stat { 568 bool phy_status; 569 bool icv_err; 570 bool crc_err; 571 bool decrypted; 572 bool is_c2h; 573 574 s32 signal_power; 575 u16 pkt_len; 576 u8 bw; 577 u8 drv_info_sz; 578 u8 shift; 579 u8 rate; 580 u8 mac_id; 581 u8 cam_id; 582 u8 ppdu_cnt; 583 u32 tsf_low; 584 s8 rx_power[RTW_RF_PATH_MAX]; 585 u8 rssi; 586 u8 rxsc; 587 s8 rx_snr[RTW_RF_PATH_MAX]; 588 u8 rx_evm[RTW_RF_PATH_MAX]; 589 s8 cfo_tail[RTW_RF_PATH_MAX]; 590 591 struct rtw_sta_info *si; 592 struct ieee80211_vif *vif; 593 }; 594 595 DECLARE_EWMA(tp, 10, 2); 596 597 struct rtw_traffic_stats { 598 /* units in bytes */ 599 u64 tx_unicast; 600 u64 rx_unicast; 601 602 /* count for packets */ 603 u64 tx_cnt; 604 u64 rx_cnt; 605 606 /* units in Mbps */ 607 u32 tx_throughput; 608 u32 rx_throughput; 609 struct ewma_tp tx_ewma_tp; 610 struct ewma_tp rx_ewma_tp; 611 }; 612 613 enum rtw_lps_mode { 614 RTW_MODE_ACTIVE = 0, 615 RTW_MODE_LPS = 1, 616 RTW_MODE_WMM_PS = 2, 617 }; 618 619 enum rtw_lps_deep_mode { 620 LPS_DEEP_MODE_NONE = 0, 621 LPS_DEEP_MODE_LCLK = 1, 622 LPS_DEEP_MODE_PG = 2, 623 }; 624 625 enum rtw_pwr_state { 626 RTW_RF_OFF = 0x0, 627 RTW_RF_ON = 0x4, 628 RTW_ALL_ON = 0xc, 629 }; 630 631 struct rtw_lps_conf { 632 enum rtw_lps_mode mode; 633 enum rtw_lps_deep_mode deep_mode; 634 enum rtw_pwr_state state; 635 u8 awake_interval; 636 u8 rlbm; 637 u8 smart_ps; 638 u8 port_id; 639 bool sec_cam_backup; 640 bool pattern_cam_backup; 641 }; 642 643 enum rtw_hw_key_type { 644 RTW_CAM_NONE = 0, 645 RTW_CAM_WEP40 = 1, 646 RTW_CAM_TKIP = 2, 647 RTW_CAM_AES = 4, 648 RTW_CAM_WEP104 = 5, 649 }; 650 651 struct rtw_cam_entry { 652 bool valid; 653 bool group; 654 u8 addr[ETH_ALEN]; 655 u8 hw_key_type; 656 struct ieee80211_key_conf *key; 657 }; 658 659 struct rtw_sec_desc { 660 /* search strategy */ 661 bool default_key_search; 662 663 u32 total_cam_num; 664 struct rtw_cam_entry cam_table[RTW_MAX_SEC_CAM_NUM]; 665 DECLARE_BITMAP(cam_map, RTW_MAX_SEC_CAM_NUM); 666 }; 667 668 struct rtw_tx_report { 669 /* protect the tx report queue */ 670 spinlock_t q_lock; 671 struct sk_buff_head queue; 672 atomic_t sn; 673 struct timer_list purge_timer; 674 }; 675 676 struct rtw_ra_report { 677 struct rate_info txrate; 678 u32 bit_rate; 679 u8 desc_rate; 680 }; 681 682 struct rtw_txq { 683 struct list_head list; 684 685 unsigned long flags; 686 unsigned long last_push; 687 }; 688 689 #define RTW_BC_MC_MACID 1 690 DECLARE_EWMA(rssi, 10, 16); 691 692 struct rtw_sta_info { 693 struct ieee80211_sta *sta; 694 struct ieee80211_vif *vif; 695 696 struct ewma_rssi avg_rssi; 697 u8 rssi_level; 698 699 u8 mac_id; 700 u8 rate_id; 701 enum rtw_bandwidth bw_mode; 702 enum rtw_rf_type rf_type; 703 enum rtw_wireless_set wireless_set; 704 u8 stbc_en:2; 705 u8 ldpc_en:2; 706 bool sgi_enable; 707 bool vht_enable; 708 bool updated; 709 u8 init_ra_lv; 710 u64 ra_mask; 711 712 DECLARE_BITMAP(tid_ba, IEEE80211_NUM_TIDS); 713 714 struct rtw_ra_report ra_report; 715 716 bool use_cfg_mask; 717 struct cfg80211_bitrate_mask *mask; 718 }; 719 720 enum rtw_bfee_role { 721 RTW_BFEE_NONE, 722 RTW_BFEE_SU, 723 RTW_BFEE_MU 724 }; 725 726 struct rtw_bfee { 727 enum rtw_bfee_role role; 728 729 u16 p_aid; 730 u8 g_id; 731 u8 mac_addr[ETH_ALEN]; 732 u8 sound_dim; 733 734 /* SU-MIMO */ 735 u8 su_reg_index; 736 737 /* MU-MIMO */ 738 u16 aid; 739 }; 740 741 struct rtw_bf_info { 742 u8 bfer_mu_cnt; 743 u8 bfer_su_cnt; 744 DECLARE_BITMAP(bfer_su_reg_maping, 2); 745 u8 cur_csi_rpt_rate; 746 }; 747 748 struct rtw_vif { 749 enum rtw_net_type net_type; 750 u16 aid; 751 u8 mac_addr[ETH_ALEN]; 752 u8 bssid[ETH_ALEN]; 753 u8 port; 754 u8 bcn_ctrl; 755 struct ieee80211_tx_queue_params tx_params[IEEE80211_NUM_ACS]; 756 const struct rtw_vif_port *conf; 757 758 struct rtw_traffic_stats stats; 759 760 struct rtw_bfee bfee; 761 }; 762 763 struct rtw_regulatory { 764 char alpha2[2]; 765 u8 chplan; 766 u8 txpwr_regd; 767 }; 768 769 struct rtw_chip_ops { 770 int (*mac_init)(struct rtw_dev *rtwdev); 771 int (*read_efuse)(struct rtw_dev *rtwdev, u8 *map); 772 void (*phy_set_param)(struct rtw_dev *rtwdev); 773 void (*set_channel)(struct rtw_dev *rtwdev, u8 channel, 774 u8 bandwidth, u8 primary_chan_idx); 775 void (*query_rx_desc)(struct rtw_dev *rtwdev, u8 *rx_desc, 776 struct rtw_rx_pkt_stat *pkt_stat, 777 struct ieee80211_rx_status *rx_status); 778 u32 (*read_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path, 779 u32 addr, u32 mask); 780 bool (*write_rf)(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path, 781 u32 addr, u32 mask, u32 data); 782 void (*set_tx_power_index)(struct rtw_dev *rtwdev); 783 int (*rsvd_page_dump)(struct rtw_dev *rtwdev, u8 *buf, u32 offset, 784 u32 size); 785 void (*set_antenna)(struct rtw_dev *rtwdev, u8 antenna_tx, 786 u8 antenna_rx); 787 void (*cfg_ldo25)(struct rtw_dev *rtwdev, bool enable); 788 void (*false_alarm_statistics)(struct rtw_dev *rtwdev); 789 void (*phy_calibration)(struct rtw_dev *rtwdev); 790 void (*dpk_track)(struct rtw_dev *rtwdev); 791 void (*cck_pd_set)(struct rtw_dev *rtwdev, u8 level); 792 void (*pwr_track)(struct rtw_dev *rtwdev); 793 void (*config_bfee)(struct rtw_dev *rtwdev, struct rtw_vif *vif, 794 struct rtw_bfee *bfee, bool enable); 795 void (*set_gid_table)(struct rtw_dev *rtwdev, 796 struct ieee80211_vif *vif, 797 struct ieee80211_bss_conf *conf); 798 void (*cfg_csi_rate)(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate, 799 u8 fixrate_en, u8 *new_rate); 800 801 /* for coex */ 802 void (*coex_set_init)(struct rtw_dev *rtwdev); 803 void (*coex_set_ant_switch)(struct rtw_dev *rtwdev, 804 u8 ctrl_type, u8 pos_type); 805 void (*coex_set_gnt_fix)(struct rtw_dev *rtwdev); 806 void (*coex_set_gnt_debug)(struct rtw_dev *rtwdev); 807 void (*coex_set_rfe_type)(struct rtw_dev *rtwdev); 808 void (*coex_set_wl_tx_power)(struct rtw_dev *rtwdev, u8 wl_pwr); 809 void (*coex_set_wl_rx_gain)(struct rtw_dev *rtwdev, bool low_gain); 810 }; 811 812 #define RTW_PWR_POLLING_CNT 20000 813 814 #define RTW_PWR_CMD_READ 0x00 815 #define RTW_PWR_CMD_WRITE 0x01 816 #define RTW_PWR_CMD_POLLING 0x02 817 #define RTW_PWR_CMD_DELAY 0x03 818 #define RTW_PWR_CMD_END 0x04 819 820 /* define the base address of each block */ 821 #define RTW_PWR_ADDR_MAC 0x00 822 #define RTW_PWR_ADDR_USB 0x01 823 #define RTW_PWR_ADDR_PCIE 0x02 824 #define RTW_PWR_ADDR_SDIO 0x03 825 826 #define RTW_PWR_INTF_SDIO_MSK BIT(0) 827 #define RTW_PWR_INTF_USB_MSK BIT(1) 828 #define RTW_PWR_INTF_PCI_MSK BIT(2) 829 #define RTW_PWR_INTF_ALL_MSK (BIT(0) | BIT(1) | BIT(2) | BIT(3)) 830 831 #define RTW_PWR_CUT_A_MSK BIT(1) 832 #define RTW_PWR_CUT_B_MSK BIT(2) 833 #define RTW_PWR_CUT_C_MSK BIT(3) 834 #define RTW_PWR_CUT_D_MSK BIT(4) 835 #define RTW_PWR_CUT_E_MSK BIT(5) 836 #define RTW_PWR_CUT_F_MSK BIT(6) 837 #define RTW_PWR_CUT_G_MSK BIT(7) 838 #define RTW_PWR_CUT_ALL_MSK 0xFF 839 840 enum rtw_pwr_seq_cmd_delay_unit { 841 RTW_PWR_DELAY_US, 842 RTW_PWR_DELAY_MS, 843 }; 844 845 struct rtw_pwr_seq_cmd { 846 u16 offset; 847 u8 cut_mask; 848 u8 intf_mask; 849 u8 base:4; 850 u8 cmd:4; 851 u8 mask; 852 u8 value; 853 }; 854 855 enum rtw_chip_ver { 856 RTW_CHIP_VER_CUT_A = 0x00, 857 RTW_CHIP_VER_CUT_B = 0x01, 858 RTW_CHIP_VER_CUT_C = 0x02, 859 RTW_CHIP_VER_CUT_D = 0x03, 860 RTW_CHIP_VER_CUT_E = 0x04, 861 RTW_CHIP_VER_CUT_F = 0x05, 862 RTW_CHIP_VER_CUT_G = 0x06, 863 }; 864 865 #define RTW_INTF_PHY_PLATFORM_ALL 0 866 867 enum rtw_intf_phy_cut { 868 RTW_INTF_PHY_CUT_A = BIT(0), 869 RTW_INTF_PHY_CUT_B = BIT(1), 870 RTW_INTF_PHY_CUT_C = BIT(2), 871 RTW_INTF_PHY_CUT_D = BIT(3), 872 RTW_INTF_PHY_CUT_E = BIT(4), 873 RTW_INTF_PHY_CUT_F = BIT(5), 874 RTW_INTF_PHY_CUT_G = BIT(6), 875 RTW_INTF_PHY_CUT_ALL = 0xFFFF, 876 }; 877 878 enum rtw_ip_sel { 879 RTW_IP_SEL_PHY = 0, 880 RTW_IP_SEL_MAC = 1, 881 RTW_IP_SEL_DBI = 2, 882 883 RTW_IP_SEL_UNDEF = 0xFFFF 884 }; 885 886 enum rtw_pq_map_id { 887 RTW_PQ_MAP_VO = 0x0, 888 RTW_PQ_MAP_VI = 0x1, 889 RTW_PQ_MAP_BE = 0x2, 890 RTW_PQ_MAP_BK = 0x3, 891 RTW_PQ_MAP_MG = 0x4, 892 RTW_PQ_MAP_HI = 0x5, 893 RTW_PQ_MAP_NUM = 0x6, 894 895 RTW_PQ_MAP_UNDEF, 896 }; 897 898 enum rtw_dma_mapping { 899 RTW_DMA_MAPPING_EXTRA = 0, 900 RTW_DMA_MAPPING_LOW = 1, 901 RTW_DMA_MAPPING_NORMAL = 2, 902 RTW_DMA_MAPPING_HIGH = 3, 903 904 RTW_DMA_MAPPING_MAX, 905 RTW_DMA_MAPPING_UNDEF, 906 }; 907 908 struct rtw_rqpn { 909 enum rtw_dma_mapping dma_map_vo; 910 enum rtw_dma_mapping dma_map_vi; 911 enum rtw_dma_mapping dma_map_be; 912 enum rtw_dma_mapping dma_map_bk; 913 enum rtw_dma_mapping dma_map_mg; 914 enum rtw_dma_mapping dma_map_hi; 915 }; 916 917 struct rtw_page_table { 918 u16 hq_num; 919 u16 nq_num; 920 u16 lq_num; 921 u16 exq_num; 922 u16 gapq_num; 923 }; 924 925 struct rtw_intf_phy_para { 926 u16 offset; 927 u16 value; 928 u16 ip_sel; 929 u16 cut_mask; 930 u16 platform; 931 }; 932 933 struct rtw_wow_pattern { 934 u16 crc; 935 u8 type; 936 u8 valid; 937 u8 mask[RTW_MAX_PATTERN_MASK_SIZE]; 938 }; 939 940 struct rtw_pno_request { 941 bool inited; 942 u32 match_set_cnt; 943 struct cfg80211_match_set *match_sets; 944 u8 channel_cnt; 945 struct ieee80211_channel *channels; 946 struct cfg80211_sched_scan_plan scan_plan; 947 }; 948 949 struct rtw_wow_param { 950 struct ieee80211_vif *wow_vif; 951 DECLARE_BITMAP(flags, RTW_WOW_FLAG_MAX); 952 u8 txpause; 953 u8 pattern_cnt; 954 struct rtw_wow_pattern patterns[RTW_MAX_PATTERN_NUM]; 955 956 bool ips_enabled; 957 struct rtw_pno_request pno_req; 958 }; 959 960 struct rtw_intf_phy_para_table { 961 const struct rtw_intf_phy_para *usb2_para; 962 const struct rtw_intf_phy_para *usb3_para; 963 const struct rtw_intf_phy_para *gen1_para; 964 const struct rtw_intf_phy_para *gen2_para; 965 u8 n_usb2_para; 966 u8 n_usb3_para; 967 u8 n_gen1_para; 968 u8 n_gen2_para; 969 }; 970 971 struct rtw_table { 972 const void *data; 973 const u32 size; 974 void (*parse)(struct rtw_dev *rtwdev, const struct rtw_table *tbl); 975 void (*do_cfg)(struct rtw_dev *rtwdev, const struct rtw_table *tbl, 976 u32 addr, u32 data); 977 enum rtw_rf_path rf_path; 978 }; 979 980 static inline void rtw_load_table(struct rtw_dev *rtwdev, 981 const struct rtw_table *tbl) 982 { 983 (*tbl->parse)(rtwdev, tbl); 984 } 985 986 enum rtw_rfe_fem { 987 RTW_RFE_IFEM, 988 RTW_RFE_EFEM, 989 RTW_RFE_IFEM2G_EFEM5G, 990 RTW_RFE_NUM, 991 }; 992 993 struct rtw_rfe_def { 994 const struct rtw_table *phy_pg_tbl; 995 const struct rtw_table *txpwr_lmt_tbl; 996 }; 997 998 #define RTW_DEF_RFE(chip, bb_pg, pwrlmt) { \ 999 .phy_pg_tbl = &rtw ## chip ## _bb_pg_type ## bb_pg ## _tbl, \ 1000 .txpwr_lmt_tbl = &rtw ## chip ## _txpwr_lmt_type ## pwrlmt ## _tbl, \ 1001 } 1002 1003 #define RTW_PWR_TRK_5G_1 0 1004 #define RTW_PWR_TRK_5G_2 1 1005 #define RTW_PWR_TRK_5G_3 2 1006 #define RTW_PWR_TRK_5G_NUM 3 1007 1008 #define RTW_PWR_TRK_TBL_SZ 30 1009 1010 /* This table stores the values of TX power that will be adjusted by power 1011 * tracking. 1012 * 1013 * For 5G bands, there are 3 different settings. 1014 * For 2G there are cck rate and ofdm rate with different settings. 1015 */ 1016 struct rtw_pwr_track_tbl { 1017 const u8 *pwrtrk_5gb_n[RTW_PWR_TRK_5G_NUM]; 1018 const u8 *pwrtrk_5gb_p[RTW_PWR_TRK_5G_NUM]; 1019 const u8 *pwrtrk_5ga_n[RTW_PWR_TRK_5G_NUM]; 1020 const u8 *pwrtrk_5ga_p[RTW_PWR_TRK_5G_NUM]; 1021 const u8 *pwrtrk_2gb_n; 1022 const u8 *pwrtrk_2gb_p; 1023 const u8 *pwrtrk_2ga_n; 1024 const u8 *pwrtrk_2ga_p; 1025 const u8 *pwrtrk_2g_cckb_n; 1026 const u8 *pwrtrk_2g_cckb_p; 1027 const u8 *pwrtrk_2g_ccka_n; 1028 const u8 *pwrtrk_2g_ccka_p; 1029 }; 1030 1031 /* hardware configuration for each IC */ 1032 struct rtw_chip_info { 1033 struct rtw_chip_ops *ops; 1034 u8 id; 1035 1036 const char *fw_name; 1037 u8 tx_pkt_desc_sz; 1038 u8 tx_buf_desc_sz; 1039 u8 rx_pkt_desc_sz; 1040 u8 rx_buf_desc_sz; 1041 u32 phy_efuse_size; 1042 u32 log_efuse_size; 1043 u32 ptct_efuse_size; 1044 u32 txff_size; 1045 u32 rxff_size; 1046 u8 band; 1047 u8 page_size; 1048 u8 csi_buf_pg_num; 1049 u8 dig_max; 1050 u8 dig_min; 1051 u8 txgi_factor; 1052 bool is_pwr_by_rate_dec; 1053 u8 max_power_index; 1054 1055 bool ht_supported; 1056 bool vht_supported; 1057 u8 lps_deep_mode_supported; 1058 1059 /* init values */ 1060 u8 sys_func_en; 1061 const struct rtw_pwr_seq_cmd **pwr_on_seq; 1062 const struct rtw_pwr_seq_cmd **pwr_off_seq; 1063 const struct rtw_rqpn *rqpn_table; 1064 const struct rtw_page_table *page_table; 1065 const struct rtw_intf_phy_para_table *intf_table; 1066 1067 const struct rtw_hw_reg *dig; 1068 u32 rf_base_addr[2]; 1069 u32 rf_sipi_addr[2]; 1070 1071 const struct rtw_table *mac_tbl; 1072 const struct rtw_table *agc_tbl; 1073 const struct rtw_table *bb_tbl; 1074 const struct rtw_table *rf_tbl[RTW_RF_PATH_MAX]; 1075 const struct rtw_table *rfk_init_tbl; 1076 1077 const struct rtw_rfe_def *rfe_defs; 1078 u32 rfe_defs_size; 1079 1080 bool en_dis_dpd; 1081 u16 dpd_ratemask; 1082 u8 iqk_threshold; 1083 const struct rtw_pwr_track_tbl *pwr_track_tbl; 1084 1085 u8 bfer_su_max_num; 1086 u8 bfer_mu_max_num; 1087 1088 const char *wow_fw_name; 1089 const struct wiphy_wowlan_support *wowlan_stub; 1090 const u8 max_sched_scan_ssids; 1091 1092 /* coex paras */ 1093 u32 coex_para_ver; 1094 u8 bt_desired_ver; 1095 bool scbd_support; 1096 bool new_scbd10_def; /* true: fix 2M(8822c) */ 1097 u8 pstdma_type; /* 0: LPSoff, 1:LPSon */ 1098 u8 bt_rssi_type; 1099 u8 ant_isolation; 1100 u8 rssi_tolerance; 1101 u8 table_sant_num; 1102 u8 table_nsant_num; 1103 u8 tdma_sant_num; 1104 u8 tdma_nsant_num; 1105 u8 bt_afh_span_bw20; 1106 u8 bt_afh_span_bw40; 1107 u8 afh_5g_num; 1108 u8 wl_rf_para_num; 1109 const u8 *bt_rssi_step; 1110 const u8 *wl_rssi_step; 1111 const struct coex_table_para *table_nsant; 1112 const struct coex_table_para *table_sant; 1113 const struct coex_tdma_para *tdma_sant; 1114 const struct coex_tdma_para *tdma_nsant; 1115 const struct coex_rf_para *wl_rf_para_tx; 1116 const struct coex_rf_para *wl_rf_para_rx; 1117 const struct coex_5g_afh_map *afh_5g; 1118 }; 1119 1120 enum rtw_coex_bt_state_cnt { 1121 COEX_CNT_BT_RETRY, 1122 COEX_CNT_BT_REINIT, 1123 COEX_CNT_BT_REENABLE, 1124 COEX_CNT_BT_POPEVENT, 1125 COEX_CNT_BT_SETUPLINK, 1126 COEX_CNT_BT_IGNWLANACT, 1127 COEX_CNT_BT_INQ, 1128 COEX_CNT_BT_PAGE, 1129 COEX_CNT_BT_ROLESWITCH, 1130 COEX_CNT_BT_AFHUPDATE, 1131 COEX_CNT_BT_INFOUPDATE, 1132 COEX_CNT_BT_IQK, 1133 COEX_CNT_BT_IQKFAIL, 1134 1135 COEX_CNT_BT_MAX 1136 }; 1137 1138 enum rtw_coex_wl_state_cnt { 1139 COEX_CNT_WL_CONNPKT, 1140 COEX_CNT_WL_COEXRUN, 1141 COEX_CNT_WL_NOISY0, 1142 COEX_CNT_WL_NOISY1, 1143 COEX_CNT_WL_NOISY2, 1144 COEX_CNT_WL_5MS_NOEXTEND, 1145 COEX_CNT_WL_FW_NOTIFY, 1146 1147 COEX_CNT_WL_MAX 1148 }; 1149 1150 struct rtw_coex_rfe { 1151 bool ant_switch_exist; 1152 bool ant_switch_diversity; 1153 bool ant_switch_with_bt; 1154 u8 rfe_module_type; 1155 u8 ant_switch_polarity; 1156 1157 /* true if WLG at BTG, else at WLAG */ 1158 bool wlg_at_btg; 1159 }; 1160 1161 struct rtw_coex_dm { 1162 bool cur_ps_tdma_on; 1163 bool cur_wl_rx_low_gain_en; 1164 1165 u8 reason; 1166 u8 bt_rssi_state[4]; 1167 u8 wl_rssi_state[4]; 1168 u8 wl_ch_info[3]; 1169 u8 cur_ps_tdma; 1170 u8 cur_table; 1171 u8 ps_tdma_para[5]; 1172 u8 cur_bt_pwr_lvl; 1173 u8 cur_bt_lna_lvl; 1174 u8 cur_wl_pwr_lvl; 1175 u8 bt_status; 1176 u32 cur_ant_pos_type; 1177 u32 cur_switch_status; 1178 u32 setting_tdma; 1179 }; 1180 1181 #define COEX_BTINFO_SRC_WL_FW 0x0 1182 #define COEX_BTINFO_SRC_BT_RSP 0x1 1183 #define COEX_BTINFO_SRC_BT_ACT 0x2 1184 #define COEX_BTINFO_SRC_BT_IQK 0x3 1185 #define COEX_BTINFO_SRC_BT_SCBD 0x4 1186 #define COEX_BTINFO_SRC_MAX 0x5 1187 1188 #define COEX_INFO_FTP BIT(7) 1189 #define COEX_INFO_A2DP BIT(6) 1190 #define COEX_INFO_HID BIT(5) 1191 #define COEX_INFO_SCO_BUSY BIT(4) 1192 #define COEX_INFO_ACL_BUSY BIT(3) 1193 #define COEX_INFO_INQ_PAGE BIT(2) 1194 #define COEX_INFO_SCO_ESCO BIT(1) 1195 #define COEX_INFO_CONNECTION BIT(0) 1196 #define COEX_BTINFO_LENGTH_MAX 10 1197 1198 struct rtw_coex_stat { 1199 bool bt_disabled; 1200 bool bt_disabled_pre; 1201 bool bt_link_exist; 1202 bool bt_whck_test; 1203 bool bt_inq_page; 1204 bool bt_inq; 1205 bool bt_page; 1206 bool bt_ble_voice; 1207 bool bt_ble_exist; 1208 bool bt_hfp_exist; 1209 bool bt_a2dp_exist; 1210 bool bt_hid_exist; 1211 bool bt_pan_exist; /* PAN or OPP */ 1212 bool bt_opp_exist; /* OPP only */ 1213 bool bt_acl_busy; 1214 bool bt_fix_2M; 1215 bool bt_setup_link; 1216 bool bt_multi_link; 1217 bool bt_a2dp_sink; 1218 bool bt_a2dp_active; 1219 bool bt_reenable; 1220 bool bt_ble_scan_en; 1221 bool bt_init_scan; 1222 bool bt_slave; 1223 bool bt_418_hid_exist; 1224 bool bt_mailbox_reply; 1225 1226 bool wl_under_lps; 1227 bool wl_under_ips; 1228 bool wl_hi_pri_task1; 1229 bool wl_hi_pri_task2; 1230 bool wl_force_lps_ctrl; 1231 bool wl_gl_busy; 1232 bool wl_linkscan_proc; 1233 bool wl_ps_state_fail; 1234 bool wl_tx_limit_en; 1235 bool wl_ampdu_limit_en; 1236 bool wl_connected; 1237 bool wl_slot_extend; 1238 bool wl_cck_lock; 1239 bool wl_cck_lock_pre; 1240 bool wl_cck_lock_ever; 1241 1242 u32 bt_supported_version; 1243 u32 bt_supported_feature; 1244 s8 bt_rssi; 1245 u8 kt_ver; 1246 u8 gnt_workaround_state; 1247 u8 tdma_timer_base; 1248 u8 bt_profile_num; 1249 u8 bt_info_c2h[COEX_BTINFO_SRC_MAX][COEX_BTINFO_LENGTH_MAX]; 1250 u8 bt_info_lb2; 1251 u8 bt_info_lb3; 1252 u8 bt_info_hb0; 1253 u8 bt_info_hb1; 1254 u8 bt_info_hb2; 1255 u8 bt_info_hb3; 1256 u8 bt_ble_scan_type; 1257 u8 bt_hid_pair_num; 1258 u8 bt_hid_slot; 1259 u8 bt_a2dp_bitpool; 1260 u8 bt_iqk_state; 1261 1262 u8 wl_noisy_level; 1263 u8 wl_fw_dbg_info[10]; 1264 u8 wl_fw_dbg_info_pre[10]; 1265 u8 wl_coex_mode; 1266 u8 ampdu_max_time; 1267 u8 wl_tput_dir; 1268 1269 u16 score_board; 1270 u16 retry_limit; 1271 1272 /* counters to record bt states */ 1273 u32 cnt_bt[COEX_CNT_BT_MAX]; 1274 1275 /* counters to record wifi states */ 1276 u32 cnt_wl[COEX_CNT_WL_MAX]; 1277 1278 u32 darfrc; 1279 u32 darfrch; 1280 }; 1281 1282 struct rtw_coex { 1283 /* protects coex info request section */ 1284 struct mutex mutex; 1285 struct sk_buff_head queue; 1286 wait_queue_head_t wait; 1287 1288 bool under_5g; 1289 bool stop_dm; 1290 bool freeze; 1291 bool freerun; 1292 bool wl_rf_off; 1293 1294 struct rtw_coex_stat stat; 1295 struct rtw_coex_dm dm; 1296 struct rtw_coex_rfe rfe; 1297 1298 struct delayed_work bt_relink_work; 1299 struct delayed_work bt_reenable_work; 1300 struct delayed_work defreeze_work; 1301 }; 1302 1303 #define DPK_RF_REG_NUM 7 1304 #define DPK_RF_PATH_NUM 2 1305 #define DPK_BB_REG_NUM 18 1306 #define DPK_CHANNEL_WIDTH_80 1 1307 1308 DECLARE_EWMA(thermal, 10, 4); 1309 1310 struct rtw_dpk_info { 1311 bool is_dpk_pwr_on; 1312 bool is_reload; 1313 1314 DECLARE_BITMAP(dpk_path_ok, DPK_RF_PATH_NUM); 1315 1316 u8 thermal_dpk[DPK_RF_PATH_NUM]; 1317 struct ewma_thermal avg_thermal[DPK_RF_PATH_NUM]; 1318 1319 u32 gnt_control; 1320 u32 gnt_value; 1321 1322 u8 result[RTW_RF_PATH_MAX]; 1323 u8 dpk_txagc[RTW_RF_PATH_MAX]; 1324 u32 coef[RTW_RF_PATH_MAX][20]; 1325 u16 dpk_gs[RTW_RF_PATH_MAX]; 1326 u8 thermal_dpk_delta[RTW_RF_PATH_MAX]; 1327 u8 pre_pwsf[RTW_RF_PATH_MAX]; 1328 1329 u8 dpk_band; 1330 u8 dpk_ch; 1331 u8 dpk_bw; 1332 }; 1333 1334 struct rtw_phy_cck_pd_reg { 1335 u32 reg_pd; 1336 u32 mask_pd; 1337 u32 reg_cs; 1338 u32 mask_cs; 1339 }; 1340 1341 #define DACK_MSBK_BACKUP_NUM 0xf 1342 #define DACK_DCK_BACKUP_NUM 0x2 1343 1344 struct rtw_swing_table { 1345 const u8 *p[RTW_RF_PATH_MAX]; 1346 const u8 *n[RTW_RF_PATH_MAX]; 1347 }; 1348 1349 struct rtw_pkt_count { 1350 u16 num_bcn_pkt; 1351 u16 num_qry_pkt[DESC_RATE_MAX]; 1352 }; 1353 1354 DECLARE_EWMA(evm, 10, 4); 1355 DECLARE_EWMA(snr, 10, 4); 1356 1357 struct rtw_dm_info { 1358 u32 cck_fa_cnt; 1359 u32 ofdm_fa_cnt; 1360 u32 total_fa_cnt; 1361 u32 cck_cca_cnt; 1362 u32 ofdm_cca_cnt; 1363 u32 total_cca_cnt; 1364 1365 u32 cck_ok_cnt; 1366 u32 cck_err_cnt; 1367 u32 ofdm_ok_cnt; 1368 u32 ofdm_err_cnt; 1369 u32 ht_ok_cnt; 1370 u32 ht_err_cnt; 1371 u32 vht_ok_cnt; 1372 u32 vht_err_cnt; 1373 1374 u8 min_rssi; 1375 u8 pre_min_rssi; 1376 u16 fa_history[4]; 1377 u8 igi_history[4]; 1378 u8 igi_bitmap; 1379 bool damping; 1380 u8 damping_cnt; 1381 u8 damping_rssi; 1382 1383 u8 cck_gi_u_bnd; 1384 u8 cck_gi_l_bnd; 1385 1386 u8 tx_rate; 1387 u8 thermal_avg[RTW_RF_PATH_MAX]; 1388 u8 thermal_meter_k; 1389 s8 delta_power_index[RTW_RF_PATH_MAX]; 1390 u8 default_ofdm_index; 1391 bool pwr_trk_triggered; 1392 bool pwr_trk_init_trigger; 1393 struct ewma_thermal avg_thermal[RTW_RF_PATH_MAX]; 1394 1395 /* backup dack results for each path and I/Q */ 1396 u32 dack_adck[RTW_RF_PATH_MAX]; 1397 u16 dack_msbk[RTW_RF_PATH_MAX][2][DACK_MSBK_BACKUP_NUM]; 1398 u8 dack_dck[RTW_RF_PATH_MAX][2][DACK_DCK_BACKUP_NUM]; 1399 1400 struct rtw_dpk_info dpk_info; 1401 1402 /* [bandwidth 0:20M/1:40M][number of path] */ 1403 u8 cck_pd_lv[2][RTW_RF_PATH_MAX]; 1404 u32 cck_fa_avg; 1405 1406 /* save the last rx phy status for debug */ 1407 s8 rx_snr[RTW_RF_PATH_MAX]; 1408 u8 rx_evm_dbm[RTW_RF_PATH_MAX]; 1409 s16 cfo_tail[RTW_RF_PATH_MAX]; 1410 u8 rssi[RTW_RF_PATH_MAX]; 1411 u8 curr_rx_rate; 1412 struct rtw_pkt_count cur_pkt_count; 1413 struct rtw_pkt_count last_pkt_count; 1414 struct ewma_evm ewma_evm[RTW_EVM_NUM]; 1415 struct ewma_snr ewma_snr[RTW_SNR_NUM]; 1416 }; 1417 1418 struct rtw_efuse { 1419 u32 size; 1420 u32 physical_size; 1421 u32 logical_size; 1422 u32 protect_size; 1423 1424 u8 addr[ETH_ALEN]; 1425 u8 channel_plan; 1426 u8 country_code[2]; 1427 u8 rf_board_option; 1428 u8 rfe_option; 1429 u8 power_track_type; 1430 u8 thermal_meter[RTW_RF_PATH_MAX]; 1431 u8 thermal_meter_k; 1432 u8 crystal_cap; 1433 u8 ant_div_cfg; 1434 u8 ant_div_type; 1435 u8 regd; 1436 1437 u8 lna_type_2g; 1438 u8 lna_type_5g; 1439 u8 glna_type; 1440 u8 alna_type; 1441 bool ext_lna_2g; 1442 bool ext_lna_5g; 1443 u8 pa_type_2g; 1444 u8 pa_type_5g; 1445 u8 gpa_type; 1446 u8 apa_type; 1447 bool ext_pa_2g; 1448 bool ext_pa_5g; 1449 1450 bool btcoex; 1451 /* bt share antenna with wifi */ 1452 bool share_ant; 1453 u8 bt_setting; 1454 1455 struct { 1456 u8 hci; 1457 u8 bw; 1458 u8 ptcl; 1459 u8 nss; 1460 u8 ant_num; 1461 } hw_cap; 1462 1463 struct rtw_txpwr_idx txpwr_idx_table[4]; 1464 }; 1465 1466 struct rtw_phy_cond { 1467 #ifdef __LITTLE_ENDIAN 1468 u32 rfe:8; 1469 u32 intf:4; 1470 u32 pkg:4; 1471 u32 plat:4; 1472 u32 intf_rsvd:4; 1473 u32 cut:4; 1474 u32 branch:2; 1475 u32 neg:1; 1476 u32 pos:1; 1477 #else 1478 u32 pos:1; 1479 u32 neg:1; 1480 u32 branch:2; 1481 u32 cut:4; 1482 u32 intf_rsvd:4; 1483 u32 plat:4; 1484 u32 pkg:4; 1485 u32 intf:4; 1486 u32 rfe:8; 1487 #endif 1488 /* for intf:4 */ 1489 #define INTF_PCIE BIT(0) 1490 #define INTF_USB BIT(1) 1491 #define INTF_SDIO BIT(2) 1492 /* for branch:2 */ 1493 #define BRANCH_IF 0 1494 #define BRANCH_ELIF 1 1495 #define BRANCH_ELSE 2 1496 #define BRANCH_ENDIF 3 1497 }; 1498 1499 struct rtw_fifo_conf { 1500 /* tx fifo information */ 1501 u16 rsvd_boundary; 1502 u16 rsvd_pg_num; 1503 u16 rsvd_drv_pg_num; 1504 u16 txff_pg_num; 1505 u16 acq_pg_num; 1506 u16 rsvd_drv_addr; 1507 u16 rsvd_h2c_info_addr; 1508 u16 rsvd_h2c_sta_info_addr; 1509 u16 rsvd_h2cq_addr; 1510 u16 rsvd_cpu_instr_addr; 1511 u16 rsvd_fw_txbuf_addr; 1512 u16 rsvd_csibuf_addr; 1513 const struct rtw_rqpn *rqpn; 1514 }; 1515 1516 struct rtw_fw_state { 1517 const struct firmware *firmware; 1518 struct rtw_dev *rtwdev; 1519 struct completion completion; 1520 u16 version; 1521 u8 sub_version; 1522 u8 sub_index; 1523 u16 h2c_version; 1524 }; 1525 1526 struct rtw_hal { 1527 u32 rcr; 1528 1529 u32 chip_version; 1530 u8 fab_version; 1531 u8 cut_version; 1532 u8 mp_chip; 1533 u8 oem_id; 1534 struct rtw_phy_cond phy_cond; 1535 1536 u8 ps_mode; 1537 u8 current_channel; 1538 u8 current_band_width; 1539 u8 current_band_type; 1540 1541 /* center channel for different available bandwidth, 1542 * val of (bw > current_band_width) is invalid 1543 */ 1544 u8 cch_by_bw[RTW_MAX_CHANNEL_WIDTH + 1]; 1545 1546 u8 sec_ch_offset; 1547 u8 rf_type; 1548 u8 rf_path_num; 1549 u8 antenna_tx; 1550 u8 antenna_rx; 1551 u8 bfee_sts_cap; 1552 1553 /* protect tx power section */ 1554 struct mutex tx_power_mutex; 1555 s8 tx_pwr_by_rate_offset_2g[RTW_RF_PATH_MAX] 1556 [DESC_RATE_MAX]; 1557 s8 tx_pwr_by_rate_offset_5g[RTW_RF_PATH_MAX] 1558 [DESC_RATE_MAX]; 1559 s8 tx_pwr_by_rate_base_2g[RTW_RF_PATH_MAX] 1560 [RTW_RATE_SECTION_MAX]; 1561 s8 tx_pwr_by_rate_base_5g[RTW_RF_PATH_MAX] 1562 [RTW_RATE_SECTION_MAX]; 1563 s8 tx_pwr_limit_2g[RTW_REGD_MAX] 1564 [RTW_CHANNEL_WIDTH_MAX] 1565 [RTW_RATE_SECTION_MAX] 1566 [RTW_MAX_CHANNEL_NUM_2G]; 1567 s8 tx_pwr_limit_5g[RTW_REGD_MAX] 1568 [RTW_CHANNEL_WIDTH_MAX] 1569 [RTW_RATE_SECTION_MAX] 1570 [RTW_MAX_CHANNEL_NUM_5G]; 1571 s8 tx_pwr_tbl[RTW_RF_PATH_MAX] 1572 [DESC_RATE_MAX]; 1573 }; 1574 1575 struct rtw_dev { 1576 struct ieee80211_hw *hw; 1577 struct device *dev; 1578 1579 struct rtw_hci hci; 1580 1581 struct rtw_chip_info *chip; 1582 struct rtw_hal hal; 1583 struct rtw_fifo_conf fifo; 1584 struct rtw_fw_state fw; 1585 struct rtw_efuse efuse; 1586 struct rtw_sec_desc sec; 1587 struct rtw_traffic_stats stats; 1588 struct rtw_regulatory regd; 1589 struct rtw_bf_info bf_info; 1590 1591 struct rtw_dm_info dm_info; 1592 struct rtw_coex coex; 1593 1594 /* ensures exclusive access from mac80211 callbacks */ 1595 struct mutex mutex; 1596 1597 /* read/write rf register */ 1598 spinlock_t rf_lock; 1599 1600 /* watch dog every 2 sec */ 1601 struct delayed_work watch_dog_work; 1602 u32 watch_dog_cnt; 1603 1604 struct list_head rsvd_page_list; 1605 1606 /* c2h cmd queue & handler work */ 1607 struct sk_buff_head c2h_queue; 1608 struct work_struct c2h_work; 1609 1610 /* used to protect txqs list */ 1611 spinlock_t txq_lock; 1612 struct list_head txqs; 1613 struct tasklet_struct tx_tasklet; 1614 struct work_struct ba_work; 1615 1616 struct rtw_tx_report tx_report; 1617 1618 struct { 1619 /* incicate the mail box to use with fw */ 1620 u8 last_box_num; 1621 /* protect to send h2c to fw */ 1622 spinlock_t lock; 1623 u32 seq; 1624 } h2c; 1625 1626 /* lps power state & handler work */ 1627 struct rtw_lps_conf lps_conf; 1628 bool ps_enabled; 1629 1630 struct dentry *debugfs; 1631 1632 u8 sta_cnt; 1633 u32 rts_threshold; 1634 1635 DECLARE_BITMAP(mac_id_map, RTW_MAX_MAC_ID_NUM); 1636 DECLARE_BITMAP(flags, NUM_OF_RTW_FLAGS); 1637 1638 u8 mp_mode; 1639 1640 struct rtw_fw_state wow_fw; 1641 struct rtw_wow_param wow; 1642 1643 /* hci related data, must be last */ 1644 u8 priv[0] __aligned(sizeof(void *)); 1645 }; 1646 1647 #include "hci.h" 1648 1649 static inline bool rtw_is_assoc(struct rtw_dev *rtwdev) 1650 { 1651 return !!rtwdev->sta_cnt; 1652 } 1653 1654 static inline struct ieee80211_txq *rtwtxq_to_txq(struct rtw_txq *rtwtxq) 1655 { 1656 void *p = rtwtxq; 1657 1658 return container_of(p, struct ieee80211_txq, drv_priv); 1659 } 1660 1661 static inline struct ieee80211_vif *rtwvif_to_vif(struct rtw_vif *rtwvif) 1662 { 1663 void *p = rtwvif; 1664 1665 return container_of(p, struct ieee80211_vif, drv_priv); 1666 } 1667 1668 static inline bool rtw_ssid_equal(struct cfg80211_ssid *a, 1669 struct cfg80211_ssid *b) 1670 { 1671 if (!a || !b || a->ssid_len != b->ssid_len) 1672 return false; 1673 1674 if (memcmp(a->ssid, b->ssid, a->ssid_len)) 1675 return false; 1676 1677 return true; 1678 } 1679 1680 void rtw_get_channel_params(struct cfg80211_chan_def *chandef, 1681 struct rtw_channel_params *ch_param); 1682 bool check_hw_ready(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 target); 1683 bool ltecoex_read_reg(struct rtw_dev *rtwdev, u16 offset, u32 *val); 1684 bool ltecoex_reg_write(struct rtw_dev *rtwdev, u16 offset, u32 value); 1685 void rtw_restore_reg(struct rtw_dev *rtwdev, 1686 struct rtw_backup_info *bckp, u32 num); 1687 void rtw_desc_to_mcsrate(u16 rate, u8 *mcs, u8 *nss); 1688 void rtw_set_channel(struct rtw_dev *rtwdev); 1689 void rtw_vif_port_config(struct rtw_dev *rtwdev, struct rtw_vif *rtwvif, 1690 u32 config); 1691 void rtw_tx_report_purge_timer(struct timer_list *t); 1692 void rtw_update_sta_info(struct rtw_dev *rtwdev, struct rtw_sta_info *si); 1693 int rtw_core_start(struct rtw_dev *rtwdev); 1694 void rtw_core_stop(struct rtw_dev *rtwdev); 1695 int rtw_chip_info_setup(struct rtw_dev *rtwdev); 1696 int rtw_core_init(struct rtw_dev *rtwdev); 1697 void rtw_core_deinit(struct rtw_dev *rtwdev); 1698 int rtw_register_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw); 1699 void rtw_unregister_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw); 1700 u16 rtw_desc_to_bitrate(u8 desc_rate); 1701 1702 #endif 1703