main.h 46 KB

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