net-wireless-rtw88-6.2-git.patch 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378
  1. drivers/net/wireless/realtek/rtw88/Kconfig | 47 +++++++++
  2. drivers/net/wireless/realtek/rtw88/Makefile | 15 +++
  3. drivers/net/wireless/realtek/rtw88/coex.c | 3
  4. drivers/net/wireless/realtek/rtw88/debug.c | 15 +++
  5. drivers/net/wireless/realtek/rtw88/fw.c | 31 +++---
  6. drivers/net/wireless/realtek/rtw88/fw.h | 11 ++
  7. drivers/net/wireless/realtek/rtw88/hci.h | 9 -
  8. drivers/net/wireless/realtek/rtw88/mac.c | 21 ++++
  9. drivers/net/wireless/realtek/rtw88/mac80211.c | 2
  10. drivers/net/wireless/realtek/rtw88/main.c | 12 +-
  11. drivers/net/wireless/realtek/rtw88/main.h | 12 +-
  12. drivers/net/wireless/realtek/rtw88/phy.c | 6 -
  13. drivers/net/wireless/realtek/rtw88/ps.c | 2
  14. drivers/net/wireless/realtek/rtw88/reg.h | 1
  15. drivers/net/wireless/realtek/rtw88/rtw8723d.c | 28 +++++
  16. drivers/net/wireless/realtek/rtw88/rtw8723d.h | 13 ++
  17. drivers/net/wireless/realtek/rtw88/rtw8723du.c | 36 +++++++
  18. drivers/net/wireless/realtek/rtw88/rtw8821c.c | 18 +++
  19. drivers/net/wireless/realtek/rtw88/rtw8821c.h | 21 ++++
  20. drivers/net/wireless/realtek/rtw88/rtw8821cu.c | 50 ++++++++++
  21. drivers/net/wireless/realtek/rtw88/rtw8822b.c | 19 +++
  22. drivers/net/wireless/realtek/rtw88/rtw8822bu.c | 90 ++++++++++++++++++
  23. drivers/net/wireless/realtek/rtw88/rtw8822c.c | 24 ++++
  24. drivers/net/wireless/realtek/rtw88/rtw8822cu.c | 44 ++++++++
  25. drivers/net/wireless/realtek/rtw88/tx.h | 31 ++++++
  26. drivers/net/wireless/realtek/rtw88/usb.c | 911 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  27. drivers/net/wireless/realtek/rtw88/usb.h | 107 +++++++++++++++++++++
  28. drivers/net/wireless/realtek/rtw88/util.c | 103 ++++++++++++++++++++
  29. drivers/net/wireless/realtek/rtw88/util.h | 12 +-
  30. 29 files changed, 1650 insertions(+), 44 deletions(-)
  31. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/coex.c linux-6.2/drivers/net/wireless/realtek/rtw88/coex.c
  32. --- linux-6.1/drivers/net/wireless/realtek/rtw88/coex.c 2022-12-12 00:15:18.000000000 +0200
  33. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/coex.c 2022-12-24 00:49:25.771376835 +0200
  34. @@ -633,7 +633,7 @@ static struct sk_buff *rtw_coex_info_req
  35. struct rtw_coex *coex = &rtwdev->coex;
  36. struct sk_buff *skb_resp = NULL;
  37. - mutex_lock(&coex->mutex);
  38. + lockdep_assert_held(&rtwdev->mutex);
  39. rtw_fw_query_bt_mp_info(rtwdev, req);
  40. @@ -650,7 +650,6 @@ static struct sk_buff *rtw_coex_info_req
  41. }
  42. out:
  43. - mutex_unlock(&coex->mutex);
  44. return skb_resp;
  45. }
  46. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/debug.c linux-6.2/drivers/net/wireless/realtek/rtw88/debug.c
  47. --- linux-6.1/drivers/net/wireless/realtek/rtw88/debug.c 2022-12-12 00:15:18.000000000 +0200
  48. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/debug.c 2022-12-24 00:49:25.771376835 +0200
  49. @@ -144,7 +144,9 @@ static int rtw_debugfs_get_rf_read(struc
  50. addr = debugfs_priv->rf_addr;
  51. mask = debugfs_priv->rf_mask;
  52. + mutex_lock(&rtwdev->mutex);
  53. val = rtw_read_rf(rtwdev, path, addr, mask);
  54. + mutex_unlock(&rtwdev->mutex);
  55. seq_printf(m, "rf_read path:%d addr:0x%08x mask:0x%08x val=0x%08x\n",
  56. path, addr, mask, val);
  57. @@ -390,7 +392,9 @@ static ssize_t rtw_debugfs_set_h2c(struc
  58. return -EINVAL;
  59. }
  60. + mutex_lock(&rtwdev->mutex);
  61. rtw_fw_h2c_cmd_dbg(rtwdev, param);
  62. + mutex_unlock(&rtwdev->mutex);
  63. return count;
  64. }
  65. @@ -414,7 +418,9 @@ static ssize_t rtw_debugfs_set_rf_write(
  66. return count;
  67. }
  68. + mutex_lock(&rtwdev->mutex);
  69. rtw_write_rf(rtwdev, path, addr, mask, val);
  70. + mutex_unlock(&rtwdev->mutex);
  71. rtw_dbg(rtwdev, RTW_DBG_DEBUGFS,
  72. "write_rf path:%d addr:0x%08x mask:0x%08x, val:0x%08x\n",
  73. path, addr, mask, val);
  74. @@ -519,6 +525,8 @@ static int rtw_debug_get_rf_dump(struct
  75. u32 addr, offset, data;
  76. u8 path;
  77. + mutex_lock(&rtwdev->mutex);
  78. +
  79. for (path = 0; path < rtwdev->hal.rf_path_num; path++) {
  80. seq_printf(m, "RF path:%d\n", path);
  81. for (addr = 0; addr < 0x100; addr += 4) {
  82. @@ -533,6 +541,8 @@ static int rtw_debug_get_rf_dump(struct
  83. seq_puts(m, "\n");
  84. }
  85. + mutex_unlock(&rtwdev->mutex);
  86. +
  87. return 0;
  88. }
  89. @@ -831,7 +841,9 @@ static int rtw_debugfs_get_coex_info(str
  90. struct rtw_debugfs_priv *debugfs_priv = m->private;
  91. struct rtw_dev *rtwdev = debugfs_priv->rtwdev;
  92. + mutex_lock(&rtwdev->mutex);
  93. rtw_coex_display_coex_info(rtwdev, m);
  94. + mutex_unlock(&rtwdev->mutex);
  95. return 0;
  96. }
  97. @@ -1026,6 +1038,8 @@ static void dump_gapk_status(struct rtw_
  98. dm_info->dm_flags & BIT(RTW_DM_CAP_TXGAPK) ? '-' : '+',
  99. rtw_dm_cap_strs[RTW_DM_CAP_TXGAPK]);
  100. + mutex_lock(&rtwdev->mutex);
  101. +
  102. for (path = 0; path < rtwdev->hal.rf_path_num; path++) {
  103. val = rtw_read_rf(rtwdev, path, RF_GAINTX, RFREG_MASK);
  104. seq_printf(m, "path %d:\n0x%x = 0x%x\n", path, RF_GAINTX, val);
  105. @@ -1035,6 +1049,7 @@ static void dump_gapk_status(struct rtw_
  106. txgapk->rf3f_fs[path][i], i);
  107. seq_puts(m, "\n");
  108. }
  109. + mutex_unlock(&rtwdev->mutex);
  110. }
  111. static int rtw_debugfs_get_dm_cap(struct seq_file *m, void *v)
  112. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/fw.c linux-6.2/drivers/net/wireless/realtek/rtw88/fw.c
  113. --- linux-6.1/drivers/net/wireless/realtek/rtw88/fw.c 2022-12-12 00:15:18.000000000 +0200
  114. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/fw.c 2022-12-24 00:49:25.771376835 +0200
  115. @@ -311,10 +311,10 @@ EXPORT_SYMBOL(rtw_fw_c2h_cmd_isr);
  116. static void rtw_fw_send_h2c_command(struct rtw_dev *rtwdev,
  117. u8 *h2c)
  118. {
  119. + struct rtw_h2c_cmd *h2c_cmd = (struct rtw_h2c_cmd *)h2c;
  120. u8 box;
  121. u8 box_state;
  122. u32 box_reg, box_ex_reg;
  123. - int idx;
  124. int ret;
  125. rtw_dbg(rtwdev, RTW_DBG_FW,
  126. @@ -322,7 +322,7 @@ static void rtw_fw_send_h2c_command(stru
  127. h2c[3], h2c[2], h2c[1], h2c[0],
  128. h2c[7], h2c[6], h2c[5], h2c[4]);
  129. - spin_lock(&rtwdev->h2c.lock);
  130. + lockdep_assert_held(&rtwdev->mutex);
  131. box = rtwdev->h2c.last_box_num;
  132. switch (box) {
  133. @@ -344,7 +344,7 @@ static void rtw_fw_send_h2c_command(stru
  134. break;
  135. default:
  136. WARN(1, "invalid h2c mail box number\n");
  137. - goto out;
  138. + return;
  139. }
  140. ret = read_poll_timeout_atomic(rtw_read8, box_state,
  141. @@ -353,19 +353,14 @@ static void rtw_fw_send_h2c_command(stru
  142. if (ret) {
  143. rtw_err(rtwdev, "failed to send h2c command\n");
  144. - goto out;
  145. + return;
  146. }
  147. - for (idx = 0; idx < 4; idx++)
  148. - rtw_write8(rtwdev, box_reg + idx, h2c[idx]);
  149. - for (idx = 0; idx < 4; idx++)
  150. - rtw_write8(rtwdev, box_ex_reg + idx, h2c[idx + 4]);
  151. + rtw_write32(rtwdev, box_ex_reg, le32_to_cpu(h2c_cmd->msg_ext));
  152. + rtw_write32(rtwdev, box_reg, le32_to_cpu(h2c_cmd->msg));
  153. if (++rtwdev->h2c.last_box_num >= 4)
  154. rtwdev->h2c.last_box_num = 0;
  155. -
  156. -out:
  157. - spin_unlock(&rtwdev->h2c.lock);
  158. }
  159. void rtw_fw_h2c_cmd_dbg(struct rtw_dev *rtwdev, u8 *h2c)
  160. @@ -377,15 +372,13 @@ static void rtw_fw_send_h2c_packet(struc
  161. {
  162. int ret;
  163. - spin_lock(&rtwdev->h2c.lock);
  164. + lockdep_assert_held(&rtwdev->mutex);
  165. FW_OFFLOAD_H2C_SET_SEQ_NUM(h2c_pkt, rtwdev->h2c.seq);
  166. ret = rtw_hci_write_data_h2c(rtwdev, h2c_pkt, H2C_PKT_SIZE);
  167. if (ret)
  168. rtw_err(rtwdev, "failed to send h2c packet\n");
  169. rtwdev->h2c.seq++;
  170. -
  171. - spin_unlock(&rtwdev->h2c.lock);
  172. }
  173. void
  174. @@ -823,6 +816,16 @@ void rtw_fw_set_nlo_info(struct rtw_dev
  175. rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
  176. }
  177. +
  178. +void rtw_fw_set_recover_bt_device(struct rtw_dev *rtwdev)
  179. +{
  180. + u8 h2c_pkt[H2C_PKT_SIZE] = {0};
  181. +
  182. + SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_RECOVER_BT_DEV);
  183. + SET_RECOVER_BT_DEV_EN(h2c_pkt, 1);
  184. +
  185. + rtw_fw_send_h2c_command(rtwdev, h2c_pkt);
  186. +}
  187. void rtw_fw_set_pg_info(struct rtw_dev *rtwdev)
  188. {
  189. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/fw.h linux-6.2/drivers/net/wireless/realtek/rtw88/fw.h
  190. --- linux-6.1/drivers/net/wireless/realtek/rtw88/fw.h 2022-12-12 00:15:18.000000000 +0200
  191. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/fw.h 2022-12-24 00:49:25.771376835 +0200
  192. @@ -81,6 +81,11 @@ struct rtw_c2h_adaptivity {
  193. u8 option;
  194. } __packed;
  195. +struct rtw_h2c_cmd {
  196. + __le32 msg;
  197. + __le32 msg_ext;
  198. +} __packed;
  199. +
  200. enum rtw_rsvd_packet_type {
  201. RSVD_BEACON,
  202. RSVD_DUMMY,
  203. @@ -550,6 +555,8 @@ static inline void rtw_h2c_pkt_set_heade
  204. #define H2C_CMD_AOAC_GLOBAL_INFO 0x82
  205. #define H2C_CMD_NLO_INFO 0x8C
  206. +#define H2C_CMD_RECOVER_BT_DEV 0xD1
  207. +
  208. #define SET_H2C_CMD_ID_CLASS(h2c_pkt, value) \
  209. le32p_replace_bits((__le32 *)(h2c_pkt) + 0x00, value, GENMASK(7, 0))
  210. @@ -749,6 +756,9 @@ static inline void rtw_h2c_pkt_set_heade
  211. #define SET_NLO_LOC_NLO_INFO(h2c_pkt, value) \
  212. le32p_replace_bits((__le32 *)(h2c_pkt) + 0x00, value, GENMASK(23, 16))
  213. +#define SET_RECOVER_BT_DEV_EN(h2c_pkt, value) \
  214. + le32p_replace_bits((__le32 *)(h2c_pkt) + 0x00, value, BIT(8))
  215. +
  216. #define GET_FW_DUMP_LEN(_header) \
  217. le32_get_bits(*((__le32 *)(_header) + 0x00), GENMASK(15, 0))
  218. #define GET_FW_DUMP_SEQ(_header) \
  219. @@ -838,6 +848,7 @@ void rtw_fw_set_aoac_global_info_cmd(str
  220. u8 group_key_enc);
  221. void rtw_fw_set_nlo_info(struct rtw_dev *rtwdev, bool enable);
  222. +void rtw_fw_set_recover_bt_device(struct rtw_dev *rtwdev);
  223. void rtw_fw_update_pkt_probe_req(struct rtw_dev *rtwdev,
  224. struct cfg80211_ssid *ssid);
  225. void rtw_fw_channel_switch(struct rtw_dev *rtwdev, bool enable);
  226. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/hci.h linux-6.2/drivers/net/wireless/realtek/rtw88/hci.h
  227. --- linux-6.1/drivers/net/wireless/realtek/rtw88/hci.h 2022-12-12 00:15:18.000000000 +0200
  228. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/hci.h 2022-12-24 00:49:25.771376835 +0200
  229. @@ -166,12 +166,11 @@ static inline u32
  230. rtw_read_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
  231. u32 addr, u32 mask)
  232. {
  233. - unsigned long flags;
  234. u32 val;
  235. - spin_lock_irqsave(&rtwdev->rf_lock, flags);
  236. + lockdep_assert_held(&rtwdev->mutex);
  237. +
  238. val = rtwdev->chip->ops->read_rf(rtwdev, rf_path, addr, mask);
  239. - spin_unlock_irqrestore(&rtwdev->rf_lock, flags);
  240. return val;
  241. }
  242. @@ -180,11 +179,9 @@ static inline void
  243. rtw_write_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
  244. u32 addr, u32 mask, u32 data)
  245. {
  246. - unsigned long flags;
  247. + lockdep_assert_held(&rtwdev->mutex);
  248. - spin_lock_irqsave(&rtwdev->rf_lock, flags);
  249. rtwdev->chip->ops->write_rf(rtwdev, rf_path, addr, mask, data);
  250. - spin_unlock_irqrestore(&rtwdev->rf_lock, flags);
  251. }
  252. static inline u32
  253. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/Kconfig linux-6.2/drivers/net/wireless/realtek/rtw88/Kconfig
  254. --- linux-6.1/drivers/net/wireless/realtek/rtw88/Kconfig 2022-12-12 00:15:18.000000000 +0200
  255. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/Kconfig 2022-12-24 00:49:25.770376835 +0200
  256. @@ -16,6 +16,9 @@ config RTW88_CORE
  257. config RTW88_PCI
  258. tristate
  259. +config RTW88_USB
  260. + tristate
  261. +
  262. config RTW88_8822B
  263. tristate
  264. @@ -39,6 +42,17 @@ config RTW88_8822BE
  265. 802.11ac PCIe wireless network adapter
  266. +config RTW88_8822BU
  267. + tristate "Realtek 8822BU USB wireless network adapter"
  268. + depends on USB
  269. + select RTW88_CORE
  270. + select RTW88_USB
  271. + select RTW88_8822B
  272. + help
  273. + Select this option will enable support for 8822BU chipset
  274. +
  275. + 802.11ac USB wireless network adapter
  276. +
  277. config RTW88_8822CE
  278. tristate "Realtek 8822CE PCI wireless network adapter"
  279. depends on PCI
  280. @@ -50,6 +64,17 @@ config RTW88_8822CE
  281. 802.11ac PCIe wireless network adapter
  282. +config RTW88_8822CU
  283. + tristate "Realtek 8822CU USB wireless network adapter"
  284. + depends on USB
  285. + select RTW88_CORE
  286. + select RTW88_USB
  287. + select RTW88_8822C
  288. + help
  289. + Select this option will enable support for 8822CU chipset
  290. +
  291. + 802.11ac USB wireless network adapter
  292. +
  293. config RTW88_8723DE
  294. tristate "Realtek 8723DE PCI wireless network adapter"
  295. depends on PCI
  296. @@ -61,6 +86,17 @@ config RTW88_8723DE
  297. 802.11n PCIe wireless network adapter
  298. +config RTW88_8723DU
  299. + tristate "Realtek 8723DU USB wireless network adapter"
  300. + depends on USB
  301. + select RTW88_CORE
  302. + select RTW88_USB
  303. + select RTW88_8723D
  304. + help
  305. + Select this option will enable support for 8723DU chipset
  306. +
  307. + 802.11n USB wireless network adapter
  308. +
  309. config RTW88_8821CE
  310. tristate "Realtek 8821CE PCI wireless network adapter"
  311. depends on PCI
  312. @@ -72,6 +108,17 @@ config RTW88_8821CE
  313. 802.11ac PCIe wireless network adapter
  314. +config RTW88_8821CU
  315. + tristate "Realtek 8821CU USB wireless network adapter"
  316. + depends on USB
  317. + select RTW88_CORE
  318. + select RTW88_USB
  319. + select RTW88_8821C
  320. + help
  321. + Select this option will enable support for 8821CU chipset
  322. +
  323. + 802.11ac USB wireless network adapter
  324. +
  325. config RTW88_DEBUG
  326. bool "Realtek rtw88 debug support"
  327. depends on RTW88_CORE
  328. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/mac80211.c linux-6.2/drivers/net/wireless/realtek/rtw88/mac80211.c
  329. --- linux-6.1/drivers/net/wireless/realtek/rtw88/mac80211.c 2022-12-12 00:15:18.000000000 +0200
  330. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/mac80211.c 2022-12-24 00:49:25.772376835 +0200
  331. @@ -487,8 +487,8 @@ static int rtw_ops_sta_remove(struct iee
  332. {
  333. struct rtw_dev *rtwdev = hw->priv;
  334. - rtw_fw_beacon_filter_config(rtwdev, false, vif);
  335. mutex_lock(&rtwdev->mutex);
  336. + rtw_fw_beacon_filter_config(rtwdev, false, vif);
  337. rtw_sta_remove(rtwdev, sta, true);
  338. mutex_unlock(&rtwdev->mutex);
  339. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/mac.c linux-6.2/drivers/net/wireless/realtek/rtw88/mac.c
  340. --- linux-6.1/drivers/net/wireless/realtek/rtw88/mac.c 2022-12-12 00:15:18.000000000 +0200
  341. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/mac.c 2022-12-24 00:49:25.772376835 +0200
  342. @@ -906,7 +906,8 @@ out:
  343. return ret;
  344. }
  345. -int rtw_download_firmware(struct rtw_dev *rtwdev, struct rtw_fw_state *fw)
  346. +static
  347. +int _rtw_download_firmware(struct rtw_dev *rtwdev, struct rtw_fw_state *fw)
  348. {
  349. if (rtw_chip_wcpu_11n(rtwdev))
  350. return __rtw_download_firmware_legacy(rtwdev, fw);
  351. @@ -914,6 +915,21 @@ int rtw_download_firmware(struct rtw_dev
  352. return __rtw_download_firmware(rtwdev, fw);
  353. }
  354. +int rtw_download_firmware(struct rtw_dev *rtwdev, struct rtw_fw_state *fw)
  355. +{
  356. + int ret;
  357. +
  358. + ret = _rtw_download_firmware(rtwdev, fw);
  359. + if (ret)
  360. + return ret;
  361. +
  362. + if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_PCIE &&
  363. + rtwdev->chip->id == RTW_CHIP_TYPE_8821C)
  364. + rtw_fw_set_recover_bt_device(rtwdev);
  365. +
  366. + return 0;
  367. +}
  368. +
  369. static u32 get_priority_queues(struct rtw_dev *rtwdev, u32 queues)
  370. {
  371. const struct rtw_rqpn *rqpn = rtwdev->fifo.rqpn;
  372. @@ -1032,6 +1048,9 @@ static int txdma_queue_mapping(struct rt
  373. if (rtw_chip_wcpu_11ac(rtwdev))
  374. rtw_write32(rtwdev, REG_H2CQ_CSR, BIT_H2CQ_FULL);
  375. + if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_USB)
  376. + rtw_write8_set(rtwdev, REG_TXDMA_PQ_MAP, BIT_RXDMA_ARBBW_EN);
  377. +
  378. return 0;
  379. }
  380. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/main.c linux-6.2/drivers/net/wireless/realtek/rtw88/main.c
  381. --- linux-6.1/drivers/net/wireless/realtek/rtw88/main.c 2022-12-12 00:15:18.000000000 +0200
  382. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/main.c 2022-12-24 00:49:25.772376835 +0200
  383. @@ -1731,7 +1731,8 @@ static void rtw_load_firmware_cb(const s
  384. update_firmware_info(rtwdev, fw);
  385. complete_all(&fw->completion);
  386. - rtw_info(rtwdev, "Firmware version %u.%u.%u, H2C version %u\n",
  387. + rtw_info(rtwdev, "%sFirmware version %u.%u.%u, H2C version %u\n",
  388. + fw->type == RTW_WOWLAN_FW ? "WOW " : "",
  389. fw->version, fw->sub_version, fw->sub_index, fw->h2c_version);
  390. }
  391. @@ -1757,6 +1758,7 @@ static int rtw_load_firmware(struct rtw_
  392. return -ENOENT;
  393. }
  394. + fw->type = type;
  395. fw->rtwdev = rtwdev;
  396. init_completion(&fw->completion);
  397. @@ -1781,6 +1783,10 @@ static int rtw_chip_parameter_setup(stru
  398. rtwdev->hci.rpwm_addr = 0x03d9;
  399. rtwdev->hci.cpwm_addr = 0x03da;
  400. break;
  401. + case RTW_HCI_TYPE_USB:
  402. + rtwdev->hci.rpwm_addr = 0xfe58;
  403. + rtwdev->hci.cpwm_addr = 0xfe57;
  404. + break;
  405. default:
  406. rtw_err(rtwdev, "unsupported hci type\n");
  407. return -EINVAL;
  408. @@ -2065,13 +2071,10 @@ int rtw_core_init(struct rtw_dev *rtwdev
  409. skb_queue_head_init(&rtwdev->coex.queue);
  410. skb_queue_head_init(&rtwdev->tx_report.queue);
  411. - spin_lock_init(&rtwdev->rf_lock);
  412. - spin_lock_init(&rtwdev->h2c.lock);
  413. spin_lock_init(&rtwdev->txq_lock);
  414. spin_lock_init(&rtwdev->tx_report.q_lock);
  415. mutex_init(&rtwdev->mutex);
  416. - mutex_init(&rtwdev->coex.mutex);
  417. mutex_init(&rtwdev->hal.tx_power_mutex);
  418. init_waitqueue_head(&rtwdev->coex.wait);
  419. @@ -2143,7 +2146,6 @@ void rtw_core_deinit(struct rtw_dev *rtw
  420. }
  421. mutex_destroy(&rtwdev->mutex);
  422. - mutex_destroy(&rtwdev->coex.mutex);
  423. mutex_destroy(&rtwdev->hal.tx_power_mutex);
  424. }
  425. EXPORT_SYMBOL(rtw_core_deinit);
  426. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/main.h linux-6.2/drivers/net/wireless/realtek/rtw88/main.h
  427. --- linux-6.1/drivers/net/wireless/realtek/rtw88/main.h 2022-12-12 00:15:18.000000000 +0200
  428. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/main.h 2022-12-24 00:49:25.773376835 +0200
  429. @@ -871,6 +871,10 @@ struct rtw_chip_ops {
  430. bool is_tx2_path);
  431. void (*config_txrx_mode)(struct rtw_dev *rtwdev, u8 tx_path,
  432. u8 rx_path, bool is_tx2_path);
  433. + /* for USB/SDIO only */
  434. + void (*fill_txdesc_checksum)(struct rtw_dev *rtwdev,
  435. + struct rtw_tx_pkt_info *pkt_info,
  436. + u8 *txdesc);
  437. /* for coex */
  438. void (*coex_set_init)(struct rtw_dev *rtwdev);
  439. @@ -1501,8 +1505,6 @@ struct rtw_coex_stat {
  440. };
  441. struct rtw_coex {
  442. - /* protects coex info request section */
  443. - struct mutex mutex;
  444. struct sk_buff_head queue;
  445. wait_queue_head_t wait;
  446. @@ -1851,6 +1853,7 @@ struct rtw_fw_state {
  447. u16 h2c_version;
  448. u32 feature;
  449. u32 feature_ext;
  450. + enum rtw_fw_type type;
  451. };
  452. enum rtw_sar_sources {
  453. @@ -1994,9 +1997,6 @@ struct rtw_dev {
  454. /* ensures exclusive access from mac80211 callbacks */
  455. struct mutex mutex;
  456. - /* read/write rf register */
  457. - spinlock_t rf_lock;
  458. -
  459. /* watch dog every 2 sec */
  460. struct delayed_work watch_dog_work;
  461. u32 watch_dog_cnt;
  462. @@ -2022,8 +2022,6 @@ struct rtw_dev {
  463. struct {
  464. /* incicate the mail box to use with fw */
  465. u8 last_box_num;
  466. - /* protect to send h2c to fw */
  467. - spinlock_t lock;
  468. u32 seq;
  469. } h2c;
  470. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/Makefile linux-6.2/drivers/net/wireless/realtek/rtw88/Makefile
  471. --- linux-6.1/drivers/net/wireless/realtek/rtw88/Makefile 2022-12-12 00:15:18.000000000 +0200
  472. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/Makefile 2022-12-24 00:49:25.770376835 +0200
  473. @@ -26,23 +26,38 @@ rtw88_8822b-objs := rtw8822b.o rtw8822b
  474. obj-$(CONFIG_RTW88_8822BE) += rtw88_8822be.o
  475. rtw88_8822be-objs := rtw8822be.o
  476. +obj-$(CONFIG_RTW88_8822BU) += rtw88_8822bu.o
  477. +rtw88_8822bu-objs := rtw8822bu.o
  478. +
  479. obj-$(CONFIG_RTW88_8822C) += rtw88_8822c.o
  480. rtw88_8822c-objs := rtw8822c.o rtw8822c_table.o
  481. obj-$(CONFIG_RTW88_8822CE) += rtw88_8822ce.o
  482. rtw88_8822ce-objs := rtw8822ce.o
  483. +obj-$(CONFIG_RTW88_8822CU) += rtw88_8822cu.o
  484. +rtw88_8822cu-objs := rtw8822cu.o
  485. +
  486. obj-$(CONFIG_RTW88_8723D) += rtw88_8723d.o
  487. rtw88_8723d-objs := rtw8723d.o rtw8723d_table.o
  488. obj-$(CONFIG_RTW88_8723DE) += rtw88_8723de.o
  489. rtw88_8723de-objs := rtw8723de.o
  490. +obj-$(CONFIG_RTW88_8723DU) += rtw88_8723du.o
  491. +rtw88_8723du-objs := rtw8723du.o
  492. +
  493. obj-$(CONFIG_RTW88_8821C) += rtw88_8821c.o
  494. rtw88_8821c-objs := rtw8821c.o rtw8821c_table.o
  495. obj-$(CONFIG_RTW88_8821CE) += rtw88_8821ce.o
  496. rtw88_8821ce-objs := rtw8821ce.o
  497. +obj-$(CONFIG_RTW88_8821CU) += rtw88_8821cu.o
  498. +rtw88_8821cu-objs := rtw8821cu.o
  499. +
  500. obj-$(CONFIG_RTW88_PCI) += rtw88_pci.o
  501. rtw88_pci-objs := pci.o
  502. +
  503. +obj-$(CONFIG_RTW88_USB) += rtw88_usb.o
  504. +rtw88_usb-objs := usb.o
  505. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/phy.c linux-6.2/drivers/net/wireless/realtek/rtw88/phy.c
  506. --- linux-6.1/drivers/net/wireless/realtek/rtw88/phy.c 2022-12-12 00:15:18.000000000 +0200
  507. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/phy.c 2022-12-24 00:49:25.773376835 +0200
  508. @@ -300,7 +300,7 @@ static void rtw_phy_stat_rssi(struct rtw
  509. data.rtwdev = rtwdev;
  510. data.min_rssi = U8_MAX;
  511. - rtw_iterate_stas_atomic(rtwdev, rtw_phy_stat_rssi_iter, &data);
  512. + rtw_iterate_stas(rtwdev, rtw_phy_stat_rssi_iter, &data);
  513. dm_info->pre_min_rssi = dm_info->min_rssi;
  514. dm_info->min_rssi = data.min_rssi;
  515. @@ -544,7 +544,7 @@ static void rtw_phy_ra_info_update(struc
  516. if (rtwdev->watch_dog_cnt & 0x3)
  517. return;
  518. - rtw_iterate_stas_atomic(rtwdev, rtw_phy_ra_info_update_iter, rtwdev);
  519. + rtw_iterate_stas(rtwdev, rtw_phy_ra_info_update_iter, rtwdev);
  520. }
  521. static u32 rtw_phy_get_rrsr_mask(struct rtw_dev *rtwdev, u8 rate_idx)
  522. @@ -597,7 +597,7 @@ static void rtw_phy_rrsr_update(struct r
  523. struct rtw_dm_info *dm_info = &rtwdev->dm_info;
  524. dm_info->rrsr_mask_min = RRSR_RATE_ORDER_MAX;
  525. - rtw_iterate_stas_atomic(rtwdev, rtw_phy_rrsr_mask_min_iter, rtwdev);
  526. + rtw_iterate_stas(rtwdev, rtw_phy_rrsr_mask_min_iter, rtwdev);
  527. rtw_write32(rtwdev, REG_RRSR, dm_info->rrsr_val_init & dm_info->rrsr_mask_min);
  528. }
  529. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/ps.c linux-6.2/drivers/net/wireless/realtek/rtw88/ps.c
  530. --- linux-6.1/drivers/net/wireless/realtek/rtw88/ps.c 2022-12-12 00:15:18.000000000 +0200
  531. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/ps.c 2022-12-24 00:49:25.773376835 +0200
  532. @@ -61,7 +61,7 @@ int rtw_leave_ips(struct rtw_dev *rtwdev
  533. return ret;
  534. }
  535. - rtw_iterate_vifs_atomic(rtwdev, rtw_restore_port_cfg_iter, rtwdev);
  536. + rtw_iterate_vifs(rtwdev, rtw_restore_port_cfg_iter, rtwdev);
  537. rtw_coex_ips_notify(rtwdev, COEX_IPS_LEAVE);
  538. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/reg.h linux-6.2/drivers/net/wireless/realtek/rtw88/reg.h
  539. --- linux-6.1/drivers/net/wireless/realtek/rtw88/reg.h 2022-12-12 00:15:18.000000000 +0200
  540. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/reg.h 2022-12-24 00:49:25.773376835 +0200
  541. @@ -184,6 +184,7 @@
  542. #define BIT_TXDMA_VIQ_MAP(x) \
  543. (((x) & BIT_MASK_TXDMA_VIQ_MAP) << BIT_SHIFT_TXDMA_VIQ_MAP)
  544. #define REG_TXDMA_PQ_MAP 0x010C
  545. +#define BIT_RXDMA_ARBBW_EN BIT(0)
  546. #define BIT_SHIFT_TXDMA_BEQ_MAP 8
  547. #define BIT_MASK_TXDMA_BEQ_MAP 0x3
  548. #define BIT_TXDMA_BEQ_MAP(x) \
  549. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8723d.c linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8723d.c
  550. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8723d.c 2022-12-12 00:15:18.000000000 +0200
  551. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8723d.c 2022-12-24 00:49:25.773376835 +0200
  552. @@ -210,6 +210,12 @@ static void rtw8723de_efuse_parsing(stru
  553. ether_addr_copy(efuse->addr, map->e.mac_addr);
  554. }
  555. +static void rtw8723du_efuse_parsing(struct rtw_efuse *efuse,
  556. + struct rtw8723d_efuse *map)
  557. +{
  558. + ether_addr_copy(efuse->addr, map->u.mac_addr);
  559. +}
  560. +
  561. static int rtw8723d_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
  562. {
  563. struct rtw_efuse *efuse = &rtwdev->efuse;
  564. @@ -239,6 +245,9 @@ static int rtw8723d_read_efuse(struct rt
  565. case RTW_HCI_TYPE_PCIE:
  566. rtw8723de_efuse_parsing(efuse, map);
  567. break;
  568. + case RTW_HCI_TYPE_USB:
  569. + rtw8723du_efuse_parsing(efuse, map);
  570. + break;
  571. default:
  572. /* unsupported now */
  573. return -ENOTSUPP;
  574. @@ -1945,6 +1954,24 @@ static void rtw8723d_pwr_track(struct rt
  575. dm_info->pwr_trk_triggered = false;
  576. }
  577. +static void rtw8723d_fill_txdesc_checksum(struct rtw_dev *rtwdev,
  578. + struct rtw_tx_pkt_info *pkt_info,
  579. + u8 *txdesc)
  580. +{
  581. + size_t words = 32 / 2; /* calculate the first 32 bytes (16 words) */
  582. + __le16 chksum = 0;
  583. + __le16 *data = (__le16 *)(txdesc);
  584. +
  585. + SET_TX_DESC_TXDESC_CHECKSUM(txdesc, 0x0000);
  586. +
  587. + while (words--)
  588. + chksum ^= *data++;
  589. +
  590. + chksum = ~chksum;
  591. +
  592. + SET_TX_DESC_TXDESC_CHECKSUM(txdesc, __le16_to_cpu(chksum));
  593. +}
  594. +
  595. static struct rtw_chip_ops rtw8723d_ops = {
  596. .phy_set_param = rtw8723d_phy_set_param,
  597. .read_efuse = rtw8723d_read_efuse,
  598. @@ -1965,6 +1992,7 @@ static struct rtw_chip_ops rtw8723d_ops
  599. .config_bfee = NULL,
  600. .set_gid_table = NULL,
  601. .cfg_csi_rate = NULL,
  602. + .fill_txdesc_checksum = rtw8723d_fill_txdesc_checksum,
  603. .coex_set_init = rtw8723d_coex_cfg_init,
  604. .coex_set_ant_switch = NULL,
  605. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8723d.h linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8723d.h
  606. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8723d.h 2022-12-12 00:15:18.000000000 +0200
  607. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8723d.h 2022-12-24 00:49:25.773376835 +0200
  608. @@ -41,6 +41,14 @@ struct rtw8723de_efuse {
  609. u8 sub_device_id[2];
  610. };
  611. +struct rtw8723du_efuse {
  612. + u8 res4[48]; /* 0xd0 */
  613. + u8 vender_id[2]; /* 0x100 */
  614. + u8 product_id[2]; /* 0x102 */
  615. + u8 usb_option; /* 0x104 */
  616. + u8 mac_addr[ETH_ALEN]; /* 0x107 */
  617. +};
  618. +
  619. struct rtw8723d_efuse {
  620. __le16 rtl_id;
  621. u8 rsvd[2];
  622. @@ -69,7 +77,10 @@ struct rtw8723d_efuse {
  623. u8 rfe_option;
  624. u8 country_code[2];
  625. u8 res[3];
  626. - struct rtw8723de_efuse e;
  627. + union {
  628. + struct rtw8723de_efuse e;
  629. + struct rtw8723du_efuse u;
  630. + };
  631. };
  632. extern const struct rtw_chip_info rtw8723d_hw_spec;
  633. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8723du.c linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8723du.c
  634. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8723du.c 1970-01-01 02:00:00.000000000 +0200
  635. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8723du.c 2022-12-24 00:49:25.773376835 +0200
  636. @@ -0,0 +1,36 @@
  637. +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  638. +/* Copyright(c) 2018-2019 Realtek Corporation
  639. + */
  640. +
  641. +#include <linux/module.h>
  642. +#include <linux/usb.h>
  643. +#include "main.h"
  644. +#include "rtw8723d.h"
  645. +#include "usb.h"
  646. +
  647. +static const struct usb_device_id rtw_8723du_id_table[] = {
  648. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xd723, 0xff, 0xff, 0xff),
  649. + .driver_info = (kernel_ulong_t)&(rtw8723d_hw_spec) }, /* 8723DU 1*1 */
  650. + { USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xd611, 0xff, 0xff, 0xff),
  651. + .driver_info = (kernel_ulong_t)&(rtw8723d_hw_spec) }, /* Edimax EW-7611ULB V2 */
  652. + { },
  653. +};
  654. +MODULE_DEVICE_TABLE(usb, rtw_8723du_id_table);
  655. +
  656. +static int rtw8723du_probe(struct usb_interface *intf,
  657. + const struct usb_device_id *id)
  658. +{
  659. + return rtw_usb_probe(intf, id);
  660. +}
  661. +
  662. +static struct usb_driver rtw_8723du_driver = {
  663. + .name = "rtw_8723du",
  664. + .id_table = rtw_8723du_id_table,
  665. + .probe = rtw8723du_probe,
  666. + .disconnect = rtw_usb_disconnect,
  667. +};
  668. +module_usb_driver(rtw_8723du_driver);
  669. +
  670. +MODULE_AUTHOR("Hans Ulli Kroll <linux@ulli-kroll.de>");
  671. +MODULE_DESCRIPTION("Realtek 802.11n wireless 8723du driver");
  672. +MODULE_LICENSE("Dual BSD/GPL");
  673. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8821c.c linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8821c.c
  674. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8821c.c 2022-12-12 00:15:18.000000000 +0200
  675. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8821c.c 2022-12-24 00:49:25.774376835 +0200
  676. @@ -26,6 +26,12 @@ static void rtw8821ce_efuse_parsing(stru
  677. ether_addr_copy(efuse->addr, map->e.mac_addr);
  678. }
  679. +static void rtw8821cu_efuse_parsing(struct rtw_efuse *efuse,
  680. + struct rtw8821c_efuse *map)
  681. +{
  682. + ether_addr_copy(efuse->addr, map->u.mac_addr);
  683. +}
  684. +
  685. enum rtw8821ce_rf_set {
  686. SWITCH_TO_BTG,
  687. SWITCH_TO_WLG,
  688. @@ -68,6 +74,9 @@ static int rtw8821c_read_efuse(struct rt
  689. case RTW_HCI_TYPE_PCIE:
  690. rtw8821ce_efuse_parsing(efuse, map);
  691. break;
  692. + case RTW_HCI_TYPE_USB:
  693. + rtw8821cu_efuse_parsing(efuse, map);
  694. + break;
  695. default:
  696. /* unsupported now */
  697. return -ENOTSUPP;
  698. @@ -1148,6 +1157,13 @@ static void rtw8821c_phy_cck_pd_set(stru
  699. dm_info->cck_pd_default + new_lvl * 2);
  700. }
  701. +static void rtw8821c_fill_txdesc_checksum(struct rtw_dev *rtwdev,
  702. + struct rtw_tx_pkt_info *pkt_info,
  703. + u8 *txdesc)
  704. +{
  705. + fill_txdesc_checksum_common(txdesc, 16);
  706. +}
  707. +
  708. static struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8821c[] = {
  709. {0x0086,
  710. RTW_PWR_CUT_ALL_MSK,
  711. @@ -1521,6 +1537,7 @@ static const struct rtw_rfe_def rtw8821c
  712. [2] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2),
  713. [4] = RTW_DEF_RFE_EXT(8821c, 0, 0, 2),
  714. [6] = RTW_DEF_RFE(8821c, 0, 0),
  715. + [34] = RTW_DEF_RFE(8821c, 0, 0),
  716. };
  717. static struct rtw_hw_reg rtw8821c_dig[] = {
  718. @@ -1595,6 +1612,7 @@ static struct rtw_chip_ops rtw8821c_ops
  719. .config_bfee = rtw8821c_bf_config_bfee,
  720. .set_gid_table = rtw_bf_set_gid_table,
  721. .cfg_csi_rate = rtw_bf_cfg_csi_rate,
  722. + .fill_txdesc_checksum = rtw8821c_fill_txdesc_checksum,
  723. .coex_set_init = rtw8821c_coex_cfg_init,
  724. .coex_set_ant_switch = rtw8821c_coex_cfg_ant_switch,
  725. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8821c.h linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8821c.h
  726. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8821c.h 2022-12-12 00:15:18.000000000 +0200
  727. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8821c.h 2022-12-24 00:49:25.774376835 +0200
  728. @@ -9,6 +9,26 @@
  729. #define RCR_VHT_ACK BIT(26)
  730. +struct rtw8821cu_efuse {
  731. + u8 res4[4]; /* 0xd0 */
  732. + u8 usb_optional_function;
  733. + u8 res5[0x1e];
  734. + u8 res6[2];
  735. + u8 serial[0x0b]; /* 0xf5 */
  736. + u8 vid; /* 0x100 */
  737. + u8 res7;
  738. + u8 pid;
  739. + u8 res8[4];
  740. + u8 mac_addr[ETH_ALEN]; /* 0x107 */
  741. + u8 res9[2];
  742. + u8 vendor_name[0x07];
  743. + u8 res10[2];
  744. + u8 device_name[0x14];
  745. + u8 res11[0xcf];
  746. + u8 package_type; /* 0x1fb */
  747. + u8 res12[0x4];
  748. +};
  749. +
  750. struct rtw8821ce_efuse {
  751. u8 mac_addr[ETH_ALEN]; /* 0xd0 */
  752. u8 vender_id[2];
  753. @@ -73,6 +93,7 @@ struct rtw8821c_efuse {
  754. u8 res[3];
  755. union {
  756. struct rtw8821ce_efuse e;
  757. + struct rtw8821cu_efuse u;
  758. };
  759. };
  760. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8821cu.c linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8821cu.c
  761. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8821cu.c 1970-01-01 02:00:00.000000000 +0200
  762. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8821cu.c 2022-12-24 00:49:25.774376835 +0200
  763. @@ -0,0 +1,50 @@
  764. +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  765. +/* Copyright(c) 2018-2019 Realtek Corporation
  766. + */
  767. +
  768. +#include <linux/module.h>
  769. +#include <linux/usb.h>
  770. +#include "main.h"
  771. +#include "rtw8821c.h"
  772. +#include "usb.h"
  773. +
  774. +static const struct usb_device_id rtw_8821cu_id_table[] = {
  775. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xb82b, 0xff, 0xff, 0xff),
  776. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* 8821CU */
  777. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xb820, 0xff, 0xff, 0xff),
  778. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* 8821CU */
  779. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xc821, 0xff, 0xff, 0xff),
  780. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* 8821CU */
  781. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xc820, 0xff, 0xff, 0xff),
  782. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* 8821CU */
  783. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xc82a, 0xff, 0xff, 0xff),
  784. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* 8821CU */
  785. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xc82b, 0xff, 0xff, 0xff),
  786. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* 8821CU */
  787. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xc811, 0xff, 0xff, 0xff),
  788. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* 8811CU */
  789. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0x8811, 0xff, 0xff, 0xff),
  790. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* 8811CU */
  791. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0x2006, 0xff, 0xff, 0xff),
  792. + .driver_info = (kernel_ulong_t)&(rtw8821c_hw_spec) }, /* TOTOLINK A650UA v3 */
  793. + {},
  794. +};
  795. +MODULE_DEVICE_TABLE(usb, rtw_8821cu_id_table);
  796. +
  797. +static int rtw_8821cu_probe(struct usb_interface *intf,
  798. + const struct usb_device_id *id)
  799. +{
  800. + return rtw_usb_probe(intf, id);
  801. +}
  802. +
  803. +static struct usb_driver rtw_8821cu_driver = {
  804. + .name = "rtw_8821cu",
  805. + .id_table = rtw_8821cu_id_table,
  806. + .probe = rtw_8821cu_probe,
  807. + .disconnect = rtw_usb_disconnect,
  808. +};
  809. +module_usb_driver(rtw_8821cu_driver);
  810. +
  811. +MODULE_AUTHOR("Hans Ulli Kroll <linux@ulli-kroll.de>");
  812. +MODULE_DESCRIPTION("Realtek 802.11ac wireless 8821cu driver");
  813. +MODULE_LICENSE("Dual BSD/GPL");
  814. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8822b.c linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8822b.c
  815. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8822b.c 2022-12-12 00:15:18.000000000 +0200
  816. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8822b.c 2022-12-24 00:49:25.774376835 +0200
  817. @@ -26,6 +26,12 @@ static void rtw8822be_efuse_parsing(stru
  818. ether_addr_copy(efuse->addr, map->e.mac_addr);
  819. }
  820. +static void rtw8822bu_efuse_parsing(struct rtw_efuse *efuse,
  821. + struct rtw8822b_efuse *map)
  822. +{
  823. + ether_addr_copy(efuse->addr, map->u.mac_addr);
  824. +}
  825. +
  826. static int rtw8822b_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
  827. {
  828. struct rtw_efuse *efuse = &rtwdev->efuse;
  829. @@ -56,6 +62,9 @@ static int rtw8822b_read_efuse(struct rt
  830. case RTW_HCI_TYPE_PCIE:
  831. rtw8822be_efuse_parsing(efuse, map);
  832. break;
  833. + case RTW_HCI_TYPE_USB:
  834. + rtw8822bu_efuse_parsing(efuse, map);
  835. + break;
  836. default:
  837. /* unsupported now */
  838. return -ENOTSUPP;
  839. @@ -1588,6 +1597,15 @@ static void rtw8822b_adaptivity(struct r
  840. rtw_phy_set_edcca_th(rtwdev, l2h, h2l);
  841. }
  842. +static void rtw8822b_fill_txdesc_checksum(struct rtw_dev *rtwdev,
  843. + struct rtw_tx_pkt_info *pkt_info,
  844. + u8 *txdesc)
  845. +{
  846. + size_t words = 32 / 2; /* calculate the first 32 bytes (16 words) */
  847. +
  848. + fill_txdesc_checksum_common(txdesc, words);
  849. +}
  850. +
  851. static const struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8822b[] = {
  852. {0x0086,
  853. RTW_PWR_CUT_ALL_MSK,
  854. @@ -2163,6 +2181,7 @@ static struct rtw_chip_ops rtw8822b_ops
  855. .cfg_csi_rate = rtw_bf_cfg_csi_rate,
  856. .adaptivity_init = rtw8822b_adaptivity_init,
  857. .adaptivity = rtw8822b_adaptivity,
  858. + .fill_txdesc_checksum = rtw8822b_fill_txdesc_checksum,
  859. .coex_set_init = rtw8822b_coex_cfg_init,
  860. .coex_set_ant_switch = rtw8822b_coex_cfg_ant_switch,
  861. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8822bu.c linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8822bu.c
  862. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8822bu.c 1970-01-01 02:00:00.000000000 +0200
  863. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8822bu.c 2022-12-24 00:49:25.774376835 +0200
  864. @@ -0,0 +1,90 @@
  865. +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  866. +/* Copyright(c) 2018-2019 Realtek Corporation
  867. + */
  868. +
  869. +#include <linux/module.h>
  870. +#include <linux/usb.h>
  871. +#include "main.h"
  872. +#include "rtw8822b.h"
  873. +#include "usb.h"
  874. +
  875. +static const struct usb_device_id rtw_8822bu_id_table[] = {
  876. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xb812, 0xff, 0xff, 0xff),
  877. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) },
  878. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xb82c, 0xff, 0xff, 0xff),
  879. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) },
  880. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0x2102, 0xff, 0xff, 0xff),
  881. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* CCNC */
  882. + { USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xb822, 0xff, 0xff, 0xff),
  883. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Edimax EW-7822ULC */
  884. + { USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xc822, 0xff, 0xff, 0xff),
  885. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Edimax EW-7822UTC */
  886. + { USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xd822, 0xff, 0xff, 0xff),
  887. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Edimax */
  888. + { USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xe822, 0xff, 0xff, 0xff),
  889. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Edimax */
  890. + { USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xf822, 0xff, 0xff, 0xff),
  891. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Edimax EW-7822UAD */
  892. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xb81a, 0xff, 0xff, 0xff),
  893. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Default ID */
  894. + { USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x1841, 0xff, 0xff, 0xff),
  895. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* ASUS AC1300 USB-AC55 B1 */
  896. + { USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x184c, 0xff, 0xff, 0xff),
  897. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* ASUS U2 */
  898. + { USB_DEVICE_AND_INTERFACE_INFO(0x0B05, 0x19aa, 0xff, 0xff, 0xff),
  899. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* ASUS - USB-AC58 rev A1 */
  900. + { USB_DEVICE_AND_INTERFACE_INFO(0x0B05, 0x1870, 0xff, 0xff, 0xff),
  901. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* ASUS */
  902. + { USB_DEVICE_AND_INTERFACE_INFO(0x0B05, 0x1874, 0xff, 0xff, 0xff),
  903. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* ASUS */
  904. + { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331e, 0xff, 0xff, 0xff),
  905. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Dlink - DWA-181 */
  906. + { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331c, 0xff, 0xff, 0xff),
  907. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Dlink - DWA-182 - D1 */
  908. + {USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331f, 0xff, 0xff, 0xff),
  909. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec)}, /* Dlink - DWA-183 D Ver */
  910. + { USB_DEVICE_AND_INTERFACE_INFO(0x13b1, 0x0043, 0xff, 0xff, 0xff),
  911. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Linksys WUSB6400M */
  912. + { USB_DEVICE_AND_INTERFACE_INFO(0x13b1, 0x0045, 0xff, 0xff, 0xff),
  913. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Linksys WUSB3600 v2 */
  914. + { USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x012d, 0xff, 0xff, 0xff),
  915. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* TP-Link Archer T3U v1 */
  916. + { USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0138, 0xff, 0xff, 0xff),
  917. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* TP-Link Archer T3U Plus v1 */
  918. + { USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0115, 0xff, 0xff, 0xff),
  919. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* TP-Link Archer T4U V3 */
  920. + { USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x012e, 0xff, 0xff, 0xff),
  921. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* TP-LINK */
  922. + { USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0116, 0xff, 0xff, 0xff),
  923. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* TP-LINK */
  924. + { USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0117, 0xff, 0xff, 0xff),
  925. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* TP-LINK */
  926. + { USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9055, 0xff, 0xff, 0xff),
  927. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Netgear A6150 */
  928. + { USB_DEVICE_AND_INTERFACE_INFO(0x0e66, 0x0025, 0xff, 0xff, 0xff),
  929. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* Hawking HW12ACU */
  930. + { USB_DEVICE_AND_INTERFACE_INFO(0x04ca, 0x8602, 0xff, 0xff, 0xff),
  931. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* LiteOn */
  932. + { USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0x808a, 0xff, 0xff, 0xff),
  933. + .driver_info = (kernel_ulong_t)&(rtw8822b_hw_spec) }, /* TRENDnet TEW-808UBM */
  934. + {},
  935. +};
  936. +MODULE_DEVICE_TABLE(usb, rtw_8822bu_id_table);
  937. +
  938. +static int rtw8822bu_probe(struct usb_interface *intf,
  939. + const struct usb_device_id *id)
  940. +{
  941. + return rtw_usb_probe(intf, id);
  942. +}
  943. +
  944. +static struct usb_driver rtw_8822bu_driver = {
  945. + .name = "rtw_8822bu",
  946. + .id_table = rtw_8822bu_id_table,
  947. + .probe = rtw8822bu_probe,
  948. + .disconnect = rtw_usb_disconnect,
  949. +};
  950. +module_usb_driver(rtw_8822bu_driver);
  951. +
  952. +MODULE_AUTHOR("Realtek Corporation");
  953. +MODULE_DESCRIPTION("Realtek 802.11ac wireless 8822bu driver");
  954. +MODULE_LICENSE("Dual BSD/GPL");
  955. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8822c.c linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8822c.c
  956. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8822c.c 2022-12-12 00:15:18.000000000 +0200
  957. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8822c.c 2022-12-24 00:49:25.775376835 +0200
  958. @@ -29,6 +29,12 @@ static void rtw8822ce_efuse_parsing(stru
  959. ether_addr_copy(efuse->addr, map->e.mac_addr);
  960. }
  961. +static void rtw8822cu_efuse_parsing(struct rtw_efuse *efuse,
  962. + struct rtw8822c_efuse *map)
  963. +{
  964. + ether_addr_copy(efuse->addr, map->u.mac_addr);
  965. +}
  966. +
  967. static int rtw8822c_read_efuse(struct rtw_dev *rtwdev, u8 *log_map)
  968. {
  969. struct rtw_efuse *efuse = &rtwdev->efuse;
  970. @@ -58,6 +64,9 @@ static int rtw8822c_read_efuse(struct rt
  971. case RTW_HCI_TYPE_PCIE:
  972. rtw8822ce_efuse_parsing(efuse, map);
  973. break;
  974. + case RTW_HCI_TYPE_USB:
  975. + rtw8822cu_efuse_parsing(efuse, map);
  976. + break;
  977. default:
  978. /* unsupported now */
  979. return -ENOTSUPP;
  980. @@ -4557,6 +4566,18 @@ static void rtw8822c_adaptivity(struct r
  981. rtw_phy_set_edcca_th(rtwdev, l2h, h2l);
  982. }
  983. +static void rtw8822c_fill_txdesc_checksum(struct rtw_dev *rtwdev,
  984. + struct rtw_tx_pkt_info *pkt_info,
  985. + u8 *txdesc)
  986. +{
  987. + const struct rtw_chip_info *chip = rtwdev->chip;
  988. + size_t words;
  989. +
  990. + words = (pkt_info->pkt_offset * 8 + chip->tx_pkt_desc_sz) / 2;
  991. +
  992. + fill_txdesc_checksum_common(txdesc, words);
  993. +}
  994. +
  995. static const struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8822c[] = {
  996. {0x0086,
  997. RTW_PWR_CUT_ALL_MSK,
  998. @@ -4895,6 +4916,8 @@ static const struct rtw_rfe_def rtw8822c
  999. [0] = RTW_DEF_RFE(8822c, 0, 0),
  1000. [1] = RTW_DEF_RFE(8822c, 0, 0),
  1001. [2] = RTW_DEF_RFE(8822c, 0, 0),
  1002. + [3] = RTW_DEF_RFE(8822c, 0, 0),
  1003. + [4] = RTW_DEF_RFE(8822c, 0, 0),
  1004. [5] = RTW_DEF_RFE(8822c, 0, 5),
  1005. [6] = RTW_DEF_RFE(8822c, 0, 0),
  1006. };
  1007. @@ -4978,6 +5001,7 @@ static struct rtw_chip_ops rtw8822c_ops
  1008. .cfo_track = rtw8822c_cfo_track,
  1009. .config_tx_path = rtw8822c_config_tx_path,
  1010. .config_txrx_mode = rtw8822c_config_trx_mode,
  1011. + .fill_txdesc_checksum = rtw8822c_fill_txdesc_checksum,
  1012. .coex_set_init = rtw8822c_coex_cfg_init,
  1013. .coex_set_ant_switch = NULL,
  1014. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8822cu.c linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8822cu.c
  1015. --- linux-6.1/drivers/net/wireless/realtek/rtw88/rtw8822cu.c 1970-01-01 02:00:00.000000000 +0200
  1016. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/rtw8822cu.c 2022-12-24 00:49:25.775376835 +0200
  1017. @@ -0,0 +1,44 @@
  1018. +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  1019. +/* Copyright(c) 2018-2019 Realtek Corporation
  1020. + */
  1021. +
  1022. +#include <linux/module.h>
  1023. +#include <linux/usb.h>
  1024. +#include "main.h"
  1025. +#include "rtw8822c.h"
  1026. +#include "usb.h"
  1027. +
  1028. +static const struct usb_device_id rtw_8822cu_id_table[] = {
  1029. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xc82c, 0xff, 0xff, 0xff),
  1030. + .driver_info = (kernel_ulong_t)&(rtw8822c_hw_spec) },
  1031. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xc812, 0xff, 0xff, 0xff),
  1032. + .driver_info = (kernel_ulong_t)&(rtw8822c_hw_spec) },
  1033. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xc82e, 0xff, 0xff, 0xff),
  1034. + .driver_info = (kernel_ulong_t)&(rtw8822c_hw_spec) },
  1035. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xd820, 0xff, 0xff, 0xff),
  1036. + .driver_info = (kernel_ulong_t)&(rtw8822c_hw_spec) },
  1037. + { USB_DEVICE_AND_INTERFACE_INFO(RTW_USB_VENDOR_ID_REALTEK, 0xd82b, 0xff, 0xff, 0xff),
  1038. + .driver_info = (kernel_ulong_t)&(rtw8822c_hw_spec) },
  1039. + { USB_DEVICE_AND_INTERFACE_INFO(0x13b1, 0x0043, 0xff, 0xff, 0xff),
  1040. + .driver_info = (kernel_ulong_t)&(rtw8822c_hw_spec) }, /* Alpha - Alpha */
  1041. + {},
  1042. +};
  1043. +MODULE_DEVICE_TABLE(usb, rtw_8822cu_id_table);
  1044. +
  1045. +static int rtw8822bu_probe(struct usb_interface *intf,
  1046. + const struct usb_device_id *id)
  1047. +{
  1048. + return rtw_usb_probe(intf, id);
  1049. +}
  1050. +
  1051. +static struct usb_driver rtw_8822cu_driver = {
  1052. + .name = "rtw_8822cu",
  1053. + .id_table = rtw_8822cu_id_table,
  1054. + .probe = rtw8822bu_probe,
  1055. + .disconnect = rtw_usb_disconnect,
  1056. +};
  1057. +module_usb_driver(rtw_8822cu_driver);
  1058. +
  1059. +MODULE_AUTHOR("Realtek Corporation");
  1060. +MODULE_DESCRIPTION("Realtek 802.11ac wireless 8822cu driver");
  1061. +MODULE_LICENSE("Dual BSD/GPL");
  1062. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/tx.h linux-6.2/drivers/net/wireless/realtek/rtw88/tx.h
  1063. --- linux-6.1/drivers/net/wireless/realtek/rtw88/tx.h 2022-12-12 00:15:18.000000000 +0200
  1064. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/tx.h 2022-12-24 00:49:25.775376835 +0200
  1065. @@ -71,6 +71,14 @@
  1066. le32p_replace_bits((__le32 *)(txdesc) + 0x03, value, BIT(15))
  1067. #define SET_TX_DESC_BT_NULL(txdesc, value) \
  1068. le32p_replace_bits((__le32 *)(txdesc) + 0x02, value, BIT(23))
  1069. +#define SET_TX_DESC_TXDESC_CHECKSUM(txdesc, value) \
  1070. + le32p_replace_bits((__le32 *)(txdesc) + 0x07, value, GENMASK(15, 0))
  1071. +#define SET_TX_DESC_DMA_TXAGG_NUM(txdesc, value) \
  1072. + le32p_replace_bits((__le32 *)(txdesc) + 0x07, value, GENMASK(31, 24))
  1073. +#define GET_TX_DESC_PKT_OFFSET(txdesc) \
  1074. + le32_get_bits(*((__le32 *)(txdesc) + 0x01), GENMASK(28, 24))
  1075. +#define GET_TX_DESC_QSEL(txdesc) \
  1076. + le32_get_bits(*((__le32 *)(txdesc) + 0x01), GENMASK(12, 8))
  1077. enum rtw_tx_desc_queue_select {
  1078. TX_DESC_QSEL_TID0 = 0,
  1079. @@ -123,4 +131,27 @@ rtw_tx_write_data_h2c_get(struct rtw_dev
  1080. struct rtw_tx_pkt_info *pkt_info,
  1081. u8 *buf, u32 size);
  1082. +static inline
  1083. +void fill_txdesc_checksum_common(u8 *txdesc, size_t words)
  1084. +{
  1085. + __le16 chksum = 0;
  1086. + __le16 *data = (__le16 *)(txdesc);
  1087. +
  1088. + SET_TX_DESC_TXDESC_CHECKSUM(txdesc, 0x0000);
  1089. +
  1090. + while (words--)
  1091. + chksum ^= *data++;
  1092. +
  1093. + SET_TX_DESC_TXDESC_CHECKSUM(txdesc, __le16_to_cpu(chksum));
  1094. +}
  1095. +
  1096. +static inline void rtw_tx_fill_txdesc_checksum(struct rtw_dev *rtwdev,
  1097. + struct rtw_tx_pkt_info *pkt_info,
  1098. + u8 *txdesc)
  1099. +{
  1100. + const struct rtw_chip_info *chip = rtwdev->chip;
  1101. +
  1102. + chip->ops->fill_txdesc_checksum(rtwdev, pkt_info, txdesc);
  1103. +}
  1104. +
  1105. #endif
  1106. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/usb.c linux-6.2/drivers/net/wireless/realtek/rtw88/usb.c
  1107. --- linux-6.1/drivers/net/wireless/realtek/rtw88/usb.c 1970-01-01 02:00:00.000000000 +0200
  1108. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/usb.c 2022-12-24 00:49:25.775376835 +0200
  1109. @@ -0,0 +1,911 @@
  1110. +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  1111. +/* Copyright(c) 2018-2019 Realtek Corporation
  1112. + */
  1113. +
  1114. +#include <linux/module.h>
  1115. +#include <linux/usb.h>
  1116. +#include <linux/mutex.h>
  1117. +#include "main.h"
  1118. +#include "debug.h"
  1119. +#include "reg.h"
  1120. +#include "tx.h"
  1121. +#include "rx.h"
  1122. +#include "fw.h"
  1123. +#include "ps.h"
  1124. +#include "usb.h"
  1125. +
  1126. +#define RTW_USB_MAX_RXQ_LEN 512
  1127. +
  1128. +struct rtw_usb_txcb {
  1129. + struct rtw_dev *rtwdev;
  1130. + struct sk_buff_head tx_ack_queue;
  1131. +};
  1132. +
  1133. +static void rtw_usb_fill_tx_checksum(struct rtw_usb *rtwusb,
  1134. + struct sk_buff *skb, int agg_num)
  1135. +{
  1136. + struct rtw_dev *rtwdev = rtwusb->rtwdev;
  1137. + struct rtw_tx_pkt_info pkt_info;
  1138. +
  1139. + SET_TX_DESC_DMA_TXAGG_NUM(skb->data, agg_num);
  1140. + pkt_info.pkt_offset = GET_TX_DESC_PKT_OFFSET(skb->data);
  1141. + rtw_tx_fill_txdesc_checksum(rtwdev, &pkt_info, skb->data);
  1142. +}
  1143. +
  1144. +static u32 rtw_usb_read(struct rtw_dev *rtwdev, u32 addr, u16 len)
  1145. +{
  1146. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1147. + struct usb_device *udev = rtwusb->udev;
  1148. + __le32 *data;
  1149. + unsigned long flags;
  1150. + int idx, ret;
  1151. + static int count;
  1152. +
  1153. + spin_lock_irqsave(&rtwusb->usb_lock, flags);
  1154. +
  1155. + idx = rtwusb->usb_data_index;
  1156. + rtwusb->usb_data_index = (idx + 1) & (RTW_USB_MAX_RXTX_COUNT - 1);
  1157. +
  1158. + spin_unlock_irqrestore(&rtwusb->usb_lock, flags);
  1159. +
  1160. + data = &rtwusb->usb_data[idx];
  1161. +
  1162. + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  1163. + RTW_USB_CMD_REQ, RTW_USB_CMD_READ, addr,
  1164. + RTW_USB_VENQT_CMD_IDX, data, len, 1000);
  1165. + if (ret < 0 && ret != -ENODEV && count++ < 4)
  1166. + rtw_err(rtwdev, "read register 0x%x failed with %d\n",
  1167. + addr, ret);
  1168. +
  1169. + return le32_to_cpu(*data);
  1170. +}
  1171. +
  1172. +static u8 rtw_usb_read8(struct rtw_dev *rtwdev, u32 addr)
  1173. +{
  1174. + return (u8)rtw_usb_read(rtwdev, addr, 1);
  1175. +}
  1176. +
  1177. +static u16 rtw_usb_read16(struct rtw_dev *rtwdev, u32 addr)
  1178. +{
  1179. + return (u16)rtw_usb_read(rtwdev, addr, 2);
  1180. +}
  1181. +
  1182. +static u32 rtw_usb_read32(struct rtw_dev *rtwdev, u32 addr)
  1183. +{
  1184. + return (u32)rtw_usb_read(rtwdev, addr, 4);
  1185. +}
  1186. +
  1187. +static void rtw_usb_write(struct rtw_dev *rtwdev, u32 addr, u32 val, int len)
  1188. +{
  1189. + struct rtw_usb *rtwusb = (struct rtw_usb *)rtwdev->priv;
  1190. + struct usb_device *udev = rtwusb->udev;
  1191. + unsigned long flags;
  1192. + __le32 *data;
  1193. + int idx, ret;
  1194. + static int count;
  1195. +
  1196. + spin_lock_irqsave(&rtwusb->usb_lock, flags);
  1197. +
  1198. + idx = rtwusb->usb_data_index;
  1199. + rtwusb->usb_data_index = (idx + 1) & (RTW_USB_MAX_RXTX_COUNT - 1);
  1200. +
  1201. + spin_unlock_irqrestore(&rtwusb->usb_lock, flags);
  1202. +
  1203. + data = &rtwusb->usb_data[idx];
  1204. +
  1205. + *data = cpu_to_le32(val);
  1206. +
  1207. + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  1208. + RTW_USB_CMD_REQ, RTW_USB_CMD_WRITE,
  1209. + addr, 0, data, len, 30000);
  1210. + if (ret < 0 && ret != -ENODEV && count++ < 4)
  1211. + rtw_err(rtwdev, "write register 0x%x failed with %d\n",
  1212. + addr, ret);
  1213. +}
  1214. +
  1215. +static void rtw_usb_write8(struct rtw_dev *rtwdev, u32 addr, u8 val)
  1216. +{
  1217. + rtw_usb_write(rtwdev, addr, val, 1);
  1218. +}
  1219. +
  1220. +static void rtw_usb_write16(struct rtw_dev *rtwdev, u32 addr, u16 val)
  1221. +{
  1222. + rtw_usb_write(rtwdev, addr, val, 2);
  1223. +}
  1224. +
  1225. +static void rtw_usb_write32(struct rtw_dev *rtwdev, u32 addr, u32 val)
  1226. +{
  1227. + rtw_usb_write(rtwdev, addr, val, 4);
  1228. +}
  1229. +
  1230. +static int rtw_usb_parse(struct rtw_dev *rtwdev,
  1231. + struct usb_interface *interface)
  1232. +{
  1233. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1234. + struct usb_host_interface *host_interface = &interface->altsetting[0];
  1235. + struct usb_interface_descriptor *interface_desc = &host_interface->desc;
  1236. + struct usb_endpoint_descriptor *endpoint;
  1237. + struct usb_device *usbd = interface_to_usbdev(interface);
  1238. + int num_out_pipes = 0;
  1239. + int i;
  1240. + u8 num;
  1241. +
  1242. + for (i = 0; i < interface_desc->bNumEndpoints; i++) {
  1243. + endpoint = &host_interface->endpoint[i].desc;
  1244. + num = usb_endpoint_num(endpoint);
  1245. +
  1246. + if (usb_endpoint_dir_in(endpoint) &&
  1247. + usb_endpoint_xfer_bulk(endpoint)) {
  1248. + if (rtwusb->pipe_in) {
  1249. + rtw_err(rtwdev, "IN pipes overflow\n");
  1250. + return -EINVAL;
  1251. + }
  1252. +
  1253. + rtwusb->pipe_in = num;
  1254. + }
  1255. +
  1256. + if (usb_endpoint_dir_in(endpoint) &&
  1257. + usb_endpoint_xfer_int(endpoint)) {
  1258. + if (rtwusb->pipe_interrupt) {
  1259. + rtw_err(rtwdev, "INT pipes overflow\n");
  1260. + return -EINVAL;
  1261. + }
  1262. +
  1263. + rtwusb->pipe_interrupt = num;
  1264. + }
  1265. +
  1266. + if (usb_endpoint_dir_out(endpoint) &&
  1267. + usb_endpoint_xfer_bulk(endpoint)) {
  1268. + if (num_out_pipes >= ARRAY_SIZE(rtwusb->out_ep)) {
  1269. + rtw_err(rtwdev, "OUT pipes overflow\n");
  1270. + return -EINVAL;
  1271. + }
  1272. +
  1273. + rtwusb->out_ep[num_out_pipes++] = num;
  1274. + }
  1275. + }
  1276. +
  1277. + switch (usbd->speed) {
  1278. + case USB_SPEED_LOW:
  1279. + case USB_SPEED_FULL:
  1280. + rtwusb->bulkout_size = RTW_USB_FULL_SPEED_BULK_SIZE;
  1281. + break;
  1282. + case USB_SPEED_HIGH:
  1283. + rtwusb->bulkout_size = RTW_USB_HIGH_SPEED_BULK_SIZE;
  1284. + break;
  1285. + case USB_SPEED_SUPER:
  1286. + rtwusb->bulkout_size = RTW_USB_SUPER_SPEED_BULK_SIZE;
  1287. + break;
  1288. + default:
  1289. + rtw_err(rtwdev, "failed to detect usb speed\n");
  1290. + return -EINVAL;
  1291. + }
  1292. +
  1293. + rtwdev->hci.bulkout_num = num_out_pipes;
  1294. +
  1295. + switch (num_out_pipes) {
  1296. + case 4:
  1297. + case 3:
  1298. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID0] = 2;
  1299. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID1] = 2;
  1300. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID2] = 2;
  1301. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID3] = 2;
  1302. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID4] = 1;
  1303. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID5] = 1;
  1304. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID6] = 0;
  1305. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID7] = 0;
  1306. + break;
  1307. + case 2:
  1308. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID0] = 1;
  1309. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID1] = 1;
  1310. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID2] = 1;
  1311. + rtwusb->qsel_to_ep[TX_DESC_QSEL_TID3] = 1;
  1312. + break;
  1313. + case 1:
  1314. + break;
  1315. + default:
  1316. + rtw_err(rtwdev, "failed to get out_pipes(%d)\n", num_out_pipes);
  1317. + return -EINVAL;
  1318. + }
  1319. +
  1320. + return 0;
  1321. +}
  1322. +
  1323. +static void rtw_usb_write_port_tx_complete(struct urb *urb)
  1324. +{
  1325. + struct rtw_usb_txcb *txcb = urb->context;
  1326. + struct rtw_dev *rtwdev = txcb->rtwdev;
  1327. + struct ieee80211_hw *hw = rtwdev->hw;
  1328. +
  1329. + while (true) {
  1330. + struct sk_buff *skb = skb_dequeue(&txcb->tx_ack_queue);
  1331. + struct ieee80211_tx_info *info;
  1332. + struct rtw_usb_tx_data *tx_data;
  1333. +
  1334. + if (!skb)
  1335. + break;
  1336. +
  1337. + info = IEEE80211_SKB_CB(skb);
  1338. + tx_data = rtw_usb_get_tx_data(skb);
  1339. +
  1340. + /* enqueue to wait for tx report */
  1341. + if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) {
  1342. + rtw_tx_report_enqueue(rtwdev, skb, tx_data->sn);
  1343. + continue;
  1344. + }
  1345. +
  1346. + /* always ACK for others, then they won't be marked as drop */
  1347. + ieee80211_tx_info_clear_status(info);
  1348. + if (info->flags & IEEE80211_TX_CTL_NO_ACK)
  1349. + info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
  1350. + else
  1351. + info->flags |= IEEE80211_TX_STAT_ACK;
  1352. +
  1353. + ieee80211_tx_status_irqsafe(hw, skb);
  1354. + }
  1355. +
  1356. + kfree(txcb);
  1357. +}
  1358. +
  1359. +static int qsel_to_ep(struct rtw_usb *rtwusb, unsigned int qsel)
  1360. +{
  1361. + if (qsel >= ARRAY_SIZE(rtwusb->qsel_to_ep))
  1362. + return 0;
  1363. +
  1364. + return rtwusb->qsel_to_ep[qsel];
  1365. +}
  1366. +
  1367. +static int rtw_usb_write_port(struct rtw_dev *rtwdev, u8 qsel, struct sk_buff *skb,
  1368. + usb_complete_t cb, void *context)
  1369. +{
  1370. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1371. + struct usb_device *usbd = rtwusb->udev;
  1372. + struct urb *urb;
  1373. + unsigned int pipe;
  1374. + int ret;
  1375. + int ep = qsel_to_ep(rtwusb, qsel);
  1376. +
  1377. + pipe = usb_sndbulkpipe(usbd, rtwusb->out_ep[ep]);
  1378. + urb = usb_alloc_urb(0, GFP_ATOMIC);
  1379. + if (!urb)
  1380. + return -ENOMEM;
  1381. +
  1382. + usb_fill_bulk_urb(urb, usbd, pipe, skb->data, skb->len, cb, context);
  1383. + ret = usb_submit_urb(urb, GFP_ATOMIC);
  1384. +
  1385. + usb_free_urb(urb);
  1386. +
  1387. + return ret;
  1388. +}
  1389. +
  1390. +static bool rtw_usb_tx_agg_skb(struct rtw_usb *rtwusb, struct sk_buff_head *list)
  1391. +{
  1392. + struct rtw_dev *rtwdev = rtwusb->rtwdev;
  1393. + struct rtw_usb_txcb *txcb;
  1394. + struct sk_buff *skb_head;
  1395. + struct sk_buff *skb_iter;
  1396. + int agg_num = 0;
  1397. + unsigned int align_next = 0;
  1398. +
  1399. + if (skb_queue_empty(list))
  1400. + return false;
  1401. +
  1402. + txcb = kmalloc(sizeof(*txcb), GFP_ATOMIC);
  1403. + if (!txcb)
  1404. + return false;
  1405. +
  1406. + txcb->rtwdev = rtwdev;
  1407. + skb_queue_head_init(&txcb->tx_ack_queue);
  1408. +
  1409. + skb_iter = skb_dequeue(list);
  1410. +
  1411. + if (skb_queue_empty(list)) {
  1412. + skb_head = skb_iter;
  1413. + goto queue;
  1414. + }
  1415. +
  1416. + skb_head = dev_alloc_skb(RTW_USB_MAX_XMITBUF_SZ);
  1417. + if (!skb_head) {
  1418. + skb_head = skb_iter;
  1419. + goto queue;
  1420. + }
  1421. +
  1422. + while (skb_iter) {
  1423. + unsigned long flags;
  1424. +
  1425. + skb_put(skb_head, align_next);
  1426. + skb_put_data(skb_head, skb_iter->data, skb_iter->len);
  1427. +
  1428. + align_next = ALIGN(skb_iter->len, 8) - skb_iter->len;
  1429. +
  1430. + agg_num++;
  1431. +
  1432. + skb_queue_tail(&txcb->tx_ack_queue, skb_iter);
  1433. +
  1434. + spin_lock_irqsave(&list->lock, flags);
  1435. +
  1436. + skb_iter = skb_peek(list);
  1437. +
  1438. + if (skb_iter && skb_iter->len + skb_head->len <= RTW_USB_MAX_XMITBUF_SZ)
  1439. + __skb_unlink(skb_iter, list);
  1440. + else
  1441. + skb_iter = NULL;
  1442. + spin_unlock_irqrestore(&list->lock, flags);
  1443. + }
  1444. +
  1445. + if (agg_num > 1)
  1446. + rtw_usb_fill_tx_checksum(rtwusb, skb_head, agg_num);
  1447. +
  1448. +queue:
  1449. + skb_queue_tail(&txcb->tx_ack_queue, skb_head);
  1450. +
  1451. + rtw_usb_write_port(rtwdev, GET_TX_DESC_QSEL(skb_head->data), skb_head,
  1452. + rtw_usb_write_port_tx_complete, txcb);
  1453. +
  1454. + return true;
  1455. +}
  1456. +
  1457. +static void rtw_usb_tx_handler(struct work_struct *work)
  1458. +{
  1459. + struct rtw_usb *rtwusb = container_of(work, struct rtw_usb, tx_work);
  1460. + int i, limit;
  1461. +
  1462. + for (i = ARRAY_SIZE(rtwusb->tx_queue) - 1; i >= 0; i--) {
  1463. + for (limit = 0; limit < 200; limit++) {
  1464. + struct sk_buff_head *list = &rtwusb->tx_queue[i];
  1465. +
  1466. + if (!rtw_usb_tx_agg_skb(rtwusb, list))
  1467. + break;
  1468. + }
  1469. + }
  1470. +}
  1471. +
  1472. +static void rtw_usb_tx_queue_purge(struct rtw_usb *rtwusb)
  1473. +{
  1474. + int i;
  1475. +
  1476. + for (i = 0; i < ARRAY_SIZE(rtwusb->tx_queue); i++)
  1477. + skb_queue_purge(&rtwusb->tx_queue[i]);
  1478. +}
  1479. +
  1480. +static void rtw_usb_write_port_complete(struct urb *urb)
  1481. +{
  1482. + struct sk_buff *skb = urb->context;
  1483. +
  1484. + dev_kfree_skb_any(skb);
  1485. +}
  1486. +
  1487. +static int rtw_usb_write_data(struct rtw_dev *rtwdev,
  1488. + struct rtw_tx_pkt_info *pkt_info,
  1489. + u8 *buf)
  1490. +{
  1491. + const struct rtw_chip_info *chip = rtwdev->chip;
  1492. + struct sk_buff *skb;
  1493. + unsigned int desclen, headsize, size;
  1494. + u8 qsel;
  1495. + int ret = 0;
  1496. +
  1497. + size = pkt_info->tx_pkt_size;
  1498. + qsel = pkt_info->qsel;
  1499. + desclen = chip->tx_pkt_desc_sz;
  1500. + headsize = pkt_info->offset ? pkt_info->offset : desclen;
  1501. +
  1502. + skb = dev_alloc_skb(headsize + size);
  1503. + if (unlikely(!skb))
  1504. + return -ENOMEM;
  1505. +
  1506. + skb_reserve(skb, headsize);
  1507. + skb_put_data(skb, buf, size);
  1508. + skb_push(skb, headsize);
  1509. + memset(skb->data, 0, headsize);
  1510. + rtw_tx_fill_tx_desc(pkt_info, skb);
  1511. + rtw_tx_fill_txdesc_checksum(rtwdev, pkt_info, skb->data);
  1512. +
  1513. + ret = rtw_usb_write_port(rtwdev, qsel, skb,
  1514. + rtw_usb_write_port_complete, skb);
  1515. + if (unlikely(ret))
  1516. + rtw_err(rtwdev, "failed to do USB write, ret=%d\n", ret);
  1517. +
  1518. + return ret;
  1519. +}
  1520. +
  1521. +static int rtw_usb_write_data_rsvd_page(struct rtw_dev *rtwdev, u8 *buf,
  1522. + u32 size)
  1523. +{
  1524. + const struct rtw_chip_info *chip = rtwdev->chip;
  1525. + struct rtw_usb *rtwusb;
  1526. + struct rtw_tx_pkt_info pkt_info = {0};
  1527. + u32 len, desclen;
  1528. +
  1529. + rtwusb = rtw_get_usb_priv(rtwdev);
  1530. +
  1531. + pkt_info.tx_pkt_size = size;
  1532. + pkt_info.qsel = TX_DESC_QSEL_BEACON;
  1533. +
  1534. + desclen = chip->tx_pkt_desc_sz;
  1535. + len = desclen + size;
  1536. + if (len % rtwusb->bulkout_size == 0) {
  1537. + len += RTW_USB_PACKET_OFFSET_SZ;
  1538. + pkt_info.offset = desclen + RTW_USB_PACKET_OFFSET_SZ;
  1539. + pkt_info.pkt_offset = 1;
  1540. + } else {
  1541. + pkt_info.offset = desclen;
  1542. + }
  1543. +
  1544. + return rtw_usb_write_data(rtwdev, &pkt_info, buf);
  1545. +}
  1546. +
  1547. +static int rtw_usb_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)
  1548. +{
  1549. + struct rtw_tx_pkt_info pkt_info = {0};
  1550. +
  1551. + pkt_info.tx_pkt_size = size;
  1552. + pkt_info.qsel = TX_DESC_QSEL_H2C;
  1553. +
  1554. + return rtw_usb_write_data(rtwdev, &pkt_info, buf);
  1555. +}
  1556. +
  1557. +static u8 rtw_usb_tx_queue_mapping_to_qsel(struct sk_buff *skb)
  1558. +{
  1559. + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1560. + __le16 fc = hdr->frame_control;
  1561. + u8 qsel;
  1562. +
  1563. + if (unlikely(ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)))
  1564. + qsel = TX_DESC_QSEL_MGMT;
  1565. + else if (skb_get_queue_mapping(skb) <= IEEE80211_AC_BK)
  1566. + qsel = skb->priority;
  1567. + else
  1568. + qsel = TX_DESC_QSEL_BEACON;
  1569. +
  1570. + return qsel;
  1571. +}
  1572. +
  1573. +static int rtw_usb_tx_write(struct rtw_dev *rtwdev,
  1574. + struct rtw_tx_pkt_info *pkt_info,
  1575. + struct sk_buff *skb)
  1576. +{
  1577. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1578. + const struct rtw_chip_info *chip = rtwdev->chip;
  1579. + struct rtw_usb_tx_data *tx_data;
  1580. + u8 *pkt_desc;
  1581. + int ep;
  1582. +
  1583. + pkt_desc = skb_push(skb, chip->tx_pkt_desc_sz);
  1584. + memset(pkt_desc, 0, chip->tx_pkt_desc_sz);
  1585. + pkt_info->qsel = rtw_usb_tx_queue_mapping_to_qsel(skb);
  1586. + ep = qsel_to_ep(rtwusb, pkt_info->qsel);
  1587. + rtw_tx_fill_tx_desc(pkt_info, skb);
  1588. + rtw_tx_fill_txdesc_checksum(rtwdev, pkt_info, skb->data);
  1589. + tx_data = rtw_usb_get_tx_data(skb);
  1590. + tx_data->sn = pkt_info->sn;
  1591. +
  1592. + skb_queue_tail(&rtwusb->tx_queue[ep], skb);
  1593. +
  1594. + return 0;
  1595. +}
  1596. +
  1597. +static void rtw_usb_tx_kick_off(struct rtw_dev *rtwdev)
  1598. +{
  1599. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1600. +
  1601. + queue_work(rtwusb->txwq, &rtwusb->tx_work);
  1602. +}
  1603. +
  1604. +static void rtw_usb_rx_handler(struct work_struct *work)
  1605. +{
  1606. + struct rtw_usb *rtwusb = container_of(work, struct rtw_usb, rx_work);
  1607. + struct rtw_dev *rtwdev = rtwusb->rtwdev;
  1608. + const struct rtw_chip_info *chip = rtwdev->chip;
  1609. + struct rtw_rx_pkt_stat pkt_stat;
  1610. + struct ieee80211_rx_status rx_status;
  1611. + struct sk_buff *skb;
  1612. + u32 pkt_desc_sz = chip->rx_pkt_desc_sz;
  1613. + u32 pkt_offset;
  1614. + u8 *rx_desc;
  1615. + int limit;
  1616. +
  1617. + for (limit = 0; limit < 200; limit++) {
  1618. + skb = skb_dequeue(&rtwusb->rx_queue);
  1619. + if (!skb)
  1620. + break;
  1621. +
  1622. + rx_desc = skb->data;
  1623. + chip->ops->query_rx_desc(rtwdev, rx_desc, &pkt_stat,
  1624. + &rx_status);
  1625. + pkt_offset = pkt_desc_sz + pkt_stat.drv_info_sz +
  1626. + pkt_stat.shift;
  1627. +
  1628. + if (pkt_stat.is_c2h) {
  1629. + skb_put(skb, pkt_stat.pkt_len + pkt_offset);
  1630. + rtw_fw_c2h_cmd_rx_irqsafe(rtwdev, pkt_offset, skb);
  1631. + continue;
  1632. + }
  1633. +
  1634. + if (skb_queue_len(&rtwusb->rx_queue) >= RTW_USB_MAX_RXQ_LEN) {
  1635. + rtw_err(rtwdev, "failed to get rx_queue, overflow\n");
  1636. + dev_kfree_skb_any(skb);
  1637. + continue;
  1638. + }
  1639. +
  1640. + skb_put(skb, pkt_stat.pkt_len);
  1641. + skb_reserve(skb, pkt_offset);
  1642. + memcpy(skb->cb, &rx_status, sizeof(rx_status));
  1643. + ieee80211_rx_irqsafe(rtwdev->hw, skb);
  1644. + }
  1645. +}
  1646. +
  1647. +static void rtw_usb_read_port_complete(struct urb *urb);
  1648. +
  1649. +static void rtw_usb_rx_resubmit(struct rtw_usb *rtwusb, struct rx_usb_ctrl_block *rxcb)
  1650. +{
  1651. + struct rtw_dev *rtwdev = rtwusb->rtwdev;
  1652. + int error;
  1653. +
  1654. + rxcb->rx_skb = alloc_skb(RTW_USB_MAX_RECVBUF_SZ, GFP_ATOMIC);
  1655. + if (!rxcb->rx_skb)
  1656. + return;
  1657. +
  1658. + usb_fill_bulk_urb(rxcb->rx_urb, rtwusb->udev,
  1659. + usb_rcvbulkpipe(rtwusb->udev, rtwusb->pipe_in),
  1660. + rxcb->rx_skb->data, RTW_USB_MAX_RECVBUF_SZ,
  1661. + rtw_usb_read_port_complete, rxcb);
  1662. +
  1663. + error = usb_submit_urb(rxcb->rx_urb, GFP_ATOMIC);
  1664. + if (error) {
  1665. + kfree_skb(rxcb->rx_skb);
  1666. + if (error != -ENODEV)
  1667. + rtw_err(rtwdev, "Err sending rx data urb %d\n",
  1668. + error);
  1669. + }
  1670. +}
  1671. +
  1672. +static void rtw_usb_read_port_complete(struct urb *urb)
  1673. +{
  1674. + struct rx_usb_ctrl_block *rxcb = urb->context;
  1675. + struct rtw_dev *rtwdev = rxcb->rtwdev;
  1676. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1677. + struct sk_buff *skb = rxcb->rx_skb;
  1678. +
  1679. + if (urb->status == 0) {
  1680. + if (urb->actual_length >= RTW_USB_MAX_RECVBUF_SZ ||
  1681. + urb->actual_length < 24) {
  1682. + rtw_err(rtwdev, "failed to get urb length:%d\n",
  1683. + urb->actual_length);
  1684. + if (skb)
  1685. + dev_kfree_skb_any(skb);
  1686. + } else {
  1687. + skb_queue_tail(&rtwusb->rx_queue, skb);
  1688. + queue_work(rtwusb->rxwq, &rtwusb->rx_work);
  1689. + }
  1690. + rtw_usb_rx_resubmit(rtwusb, rxcb);
  1691. + } else {
  1692. + switch (urb->status) {
  1693. + case -EINVAL:
  1694. + case -EPIPE:
  1695. + case -ENODEV:
  1696. + case -ESHUTDOWN:
  1697. + case -ENOENT:
  1698. + case -EPROTO:
  1699. + case -EILSEQ:
  1700. + case -ETIME:
  1701. + case -ECOMM:
  1702. + case -EOVERFLOW:
  1703. + case -EINPROGRESS:
  1704. + break;
  1705. + default:
  1706. + rtw_err(rtwdev, "status %d\n", urb->status);
  1707. + break;
  1708. + }
  1709. + if (skb)
  1710. + dev_kfree_skb_any(skb);
  1711. + }
  1712. +}
  1713. +
  1714. +static void rtw_usb_cancel_rx_bufs(struct rtw_usb *rtwusb)
  1715. +{
  1716. + struct rx_usb_ctrl_block *rxcb;
  1717. + int i;
  1718. +
  1719. + for (i = 0; i < RTW_USB_RXCB_NUM; i++) {
  1720. + rxcb = &rtwusb->rx_cb[i];
  1721. + if (rxcb->rx_urb)
  1722. + usb_kill_urb(rxcb->rx_urb);
  1723. + }
  1724. +}
  1725. +
  1726. +static void rtw_usb_free_rx_bufs(struct rtw_usb *rtwusb)
  1727. +{
  1728. + struct rx_usb_ctrl_block *rxcb;
  1729. + int i;
  1730. +
  1731. + for (i = 0; i < RTW_USB_RXCB_NUM; i++) {
  1732. + rxcb = &rtwusb->rx_cb[i];
  1733. + if (rxcb->rx_urb) {
  1734. + usb_kill_urb(rxcb->rx_urb);
  1735. + usb_free_urb(rxcb->rx_urb);
  1736. + }
  1737. + }
  1738. +}
  1739. +
  1740. +static int rtw_usb_alloc_rx_bufs(struct rtw_usb *rtwusb)
  1741. +{
  1742. + int i;
  1743. +
  1744. + for (i = 0; i < RTW_USB_RXCB_NUM; i++) {
  1745. + struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i];
  1746. +
  1747. + rxcb->n = i;
  1748. + rxcb->rtwdev = rtwusb->rtwdev;
  1749. + rxcb->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
  1750. + if (!rxcb->rx_urb)
  1751. + goto err;
  1752. + }
  1753. +
  1754. + return 0;
  1755. +err:
  1756. + rtw_usb_free_rx_bufs(rtwusb);
  1757. + return -ENOMEM;
  1758. +}
  1759. +
  1760. +static int rtw_usb_setup(struct rtw_dev *rtwdev)
  1761. +{
  1762. + /* empty function for rtw_hci_ops */
  1763. + return 0;
  1764. +}
  1765. +
  1766. +static int rtw_usb_start(struct rtw_dev *rtwdev)
  1767. +{
  1768. + return 0;
  1769. +}
  1770. +
  1771. +static void rtw_usb_stop(struct rtw_dev *rtwdev)
  1772. +{
  1773. +}
  1774. +
  1775. +static void rtw_usb_deep_ps(struct rtw_dev *rtwdev, bool enter)
  1776. +{
  1777. + /* empty function for rtw_hci_ops */
  1778. +}
  1779. +
  1780. +static void rtw_usb_link_ps(struct rtw_dev *rtwdev, bool enter)
  1781. +{
  1782. + /* empty function for rtw_hci_ops */
  1783. +}
  1784. +
  1785. +static void rtw_usb_interface_cfg(struct rtw_dev *rtwdev)
  1786. +{
  1787. + /* empty function for rtw_hci_ops */
  1788. +}
  1789. +
  1790. +static struct rtw_hci_ops rtw_usb_ops = {
  1791. + .tx_write = rtw_usb_tx_write,
  1792. + .tx_kick_off = rtw_usb_tx_kick_off,
  1793. + .setup = rtw_usb_setup,
  1794. + .start = rtw_usb_start,
  1795. + .stop = rtw_usb_stop,
  1796. + .deep_ps = rtw_usb_deep_ps,
  1797. + .link_ps = rtw_usb_link_ps,
  1798. + .interface_cfg = rtw_usb_interface_cfg,
  1799. +
  1800. + .write8 = rtw_usb_write8,
  1801. + .write16 = rtw_usb_write16,
  1802. + .write32 = rtw_usb_write32,
  1803. + .read8 = rtw_usb_read8,
  1804. + .read16 = rtw_usb_read16,
  1805. + .read32 = rtw_usb_read32,
  1806. +
  1807. + .write_data_rsvd_page = rtw_usb_write_data_rsvd_page,
  1808. + .write_data_h2c = rtw_usb_write_data_h2c,
  1809. +};
  1810. +
  1811. +static int rtw_usb_init_rx(struct rtw_dev *rtwdev)
  1812. +{
  1813. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1814. + int i;
  1815. +
  1816. + rtwusb->rxwq = create_singlethread_workqueue("rtw88_usb: rx wq");
  1817. + if (!rtwusb->rxwq) {
  1818. + rtw_err(rtwdev, "failed to create RX work queue\n");
  1819. + return -ENOMEM;
  1820. + }
  1821. +
  1822. + skb_queue_head_init(&rtwusb->rx_queue);
  1823. +
  1824. + INIT_WORK(&rtwusb->rx_work, rtw_usb_rx_handler);
  1825. +
  1826. + for (i = 0; i < RTW_USB_RXCB_NUM; i++) {
  1827. + struct rx_usb_ctrl_block *rxcb = &rtwusb->rx_cb[i];
  1828. +
  1829. + rtw_usb_rx_resubmit(rtwusb, rxcb);
  1830. + }
  1831. +
  1832. + return 0;
  1833. +}
  1834. +
  1835. +static void rtw_usb_deinit_rx(struct rtw_dev *rtwdev)
  1836. +{
  1837. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1838. +
  1839. + skb_queue_purge(&rtwusb->rx_queue);
  1840. +
  1841. + flush_workqueue(rtwusb->rxwq);
  1842. + destroy_workqueue(rtwusb->rxwq);
  1843. +}
  1844. +
  1845. +static int rtw_usb_init_tx(struct rtw_dev *rtwdev)
  1846. +{
  1847. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1848. + int i;
  1849. +
  1850. + rtwusb->txwq = create_singlethread_workqueue("rtw88_usb: tx wq");
  1851. + if (!rtwusb->txwq) {
  1852. + rtw_err(rtwdev, "failed to create TX work queue\n");
  1853. + return -ENOMEM;
  1854. + }
  1855. +
  1856. + for (i = 0; i < ARRAY_SIZE(rtwusb->tx_queue); i++)
  1857. + skb_queue_head_init(&rtwusb->tx_queue[i]);
  1858. +
  1859. + INIT_WORK(&rtwusb->tx_work, rtw_usb_tx_handler);
  1860. +
  1861. + return 0;
  1862. +}
  1863. +
  1864. +static void rtw_usb_deinit_tx(struct rtw_dev *rtwdev)
  1865. +{
  1866. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1867. +
  1868. + rtw_usb_tx_queue_purge(rtwusb);
  1869. + flush_workqueue(rtwusb->txwq);
  1870. + destroy_workqueue(rtwusb->txwq);
  1871. +}
  1872. +
  1873. +static int rtw_usb_intf_init(struct rtw_dev *rtwdev,
  1874. + struct usb_interface *intf)
  1875. +{
  1876. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1877. + struct usb_device *udev = usb_get_dev(interface_to_usbdev(intf));
  1878. + int ret;
  1879. +
  1880. + rtwusb->udev = udev;
  1881. + ret = rtw_usb_parse(rtwdev, intf);
  1882. + if (ret)
  1883. + return ret;
  1884. +
  1885. + rtwusb->usb_data = kcalloc(RTW_USB_MAX_RXTX_COUNT, sizeof(u32),
  1886. + GFP_KERNEL);
  1887. + if (!rtwusb->usb_data)
  1888. + return -ENOMEM;
  1889. +
  1890. + usb_set_intfdata(intf, rtwdev->hw);
  1891. +
  1892. + SET_IEEE80211_DEV(rtwdev->hw, &intf->dev);
  1893. + spin_lock_init(&rtwusb->usb_lock);
  1894. +
  1895. + return 0;
  1896. +}
  1897. +
  1898. +static void rtw_usb_intf_deinit(struct rtw_dev *rtwdev,
  1899. + struct usb_interface *intf)
  1900. +{
  1901. + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
  1902. +
  1903. + usb_put_dev(rtwusb->udev);
  1904. + usb_set_intfdata(intf, NULL);
  1905. +}
  1906. +
  1907. +int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1908. +{
  1909. + struct rtw_dev *rtwdev;
  1910. + struct ieee80211_hw *hw;
  1911. + struct rtw_usb *rtwusb;
  1912. + int drv_data_size;
  1913. + int ret;
  1914. +
  1915. + drv_data_size = sizeof(struct rtw_dev) + sizeof(struct rtw_usb);
  1916. + hw = ieee80211_alloc_hw(drv_data_size, &rtw_ops);
  1917. + if (!hw)
  1918. + return -ENOMEM;
  1919. +
  1920. + rtwdev = hw->priv;
  1921. + rtwdev->hw = hw;
  1922. + rtwdev->dev = &intf->dev;
  1923. + rtwdev->chip = (struct rtw_chip_info *)id->driver_info;
  1924. + rtwdev->hci.ops = &rtw_usb_ops;
  1925. + rtwdev->hci.type = RTW_HCI_TYPE_USB;
  1926. +
  1927. + rtwusb = rtw_get_usb_priv(rtwdev);
  1928. + rtwusb->rtwdev = rtwdev;
  1929. +
  1930. + ret = rtw_usb_alloc_rx_bufs(rtwusb);
  1931. + if (ret)
  1932. + return ret;
  1933. +
  1934. + ret = rtw_core_init(rtwdev);
  1935. + if (ret)
  1936. + goto err_release_hw;
  1937. +
  1938. + ret = rtw_usb_intf_init(rtwdev, intf);
  1939. + if (ret) {
  1940. + rtw_err(rtwdev, "failed to init USB interface\n");
  1941. + goto err_deinit_core;
  1942. + }
  1943. +
  1944. + ret = rtw_usb_init_tx(rtwdev);
  1945. + if (ret) {
  1946. + rtw_err(rtwdev, "failed to init USB TX\n");
  1947. + goto err_destroy_usb;
  1948. + }
  1949. +
  1950. + ret = rtw_usb_init_rx(rtwdev);
  1951. + if (ret) {
  1952. + rtw_err(rtwdev, "failed to init USB RX\n");
  1953. + goto err_destroy_txwq;
  1954. + }
  1955. +
  1956. + ret = rtw_chip_info_setup(rtwdev);
  1957. + if (ret) {
  1958. + rtw_err(rtwdev, "failed to setup chip information\n");
  1959. + goto err_destroy_rxwq;
  1960. + }
  1961. +
  1962. + ret = rtw_register_hw(rtwdev, rtwdev->hw);
  1963. + if (ret) {
  1964. + rtw_err(rtwdev, "failed to register hw\n");
  1965. + goto err_destroy_rxwq;
  1966. + }
  1967. +
  1968. + return 0;
  1969. +
  1970. +err_destroy_rxwq:
  1971. + rtw_usb_deinit_rx(rtwdev);
  1972. +
  1973. +err_destroy_txwq:
  1974. + rtw_usb_deinit_tx(rtwdev);
  1975. +
  1976. +err_destroy_usb:
  1977. + rtw_usb_intf_deinit(rtwdev, intf);
  1978. +
  1979. +err_deinit_core:
  1980. + rtw_core_deinit(rtwdev);
  1981. +
  1982. +err_release_hw:
  1983. + ieee80211_free_hw(hw);
  1984. +
  1985. + return ret;
  1986. +}
  1987. +EXPORT_SYMBOL(rtw_usb_probe);
  1988. +
  1989. +void rtw_usb_disconnect(struct usb_interface *intf)
  1990. +{
  1991. + struct ieee80211_hw *hw = usb_get_intfdata(intf);
  1992. + struct rtw_dev *rtwdev;
  1993. + struct rtw_usb *rtwusb;
  1994. +
  1995. + if (!hw)
  1996. + return;
  1997. +
  1998. + rtwdev = hw->priv;
  1999. + rtwusb = rtw_get_usb_priv(rtwdev);
  2000. +
  2001. + rtw_usb_cancel_rx_bufs(rtwusb);
  2002. +
  2003. + rtw_unregister_hw(rtwdev, hw);
  2004. + rtw_usb_deinit_tx(rtwdev);
  2005. + rtw_usb_deinit_rx(rtwdev);
  2006. +
  2007. + if (rtwusb->udev->state != USB_STATE_NOTATTACHED)
  2008. + usb_reset_device(rtwusb->udev);
  2009. +
  2010. + rtw_usb_free_rx_bufs(rtwusb);
  2011. +
  2012. + rtw_usb_intf_deinit(rtwdev, intf);
  2013. + rtw_core_deinit(rtwdev);
  2014. + ieee80211_free_hw(hw);
  2015. +}
  2016. +EXPORT_SYMBOL(rtw_usb_disconnect);
  2017. +
  2018. +MODULE_AUTHOR("Realtek Corporation");
  2019. +MODULE_DESCRIPTION("Realtek 802.11ac wireless USB driver");
  2020. +MODULE_LICENSE("Dual BSD/GPL");
  2021. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/usb.h linux-6.2/drivers/net/wireless/realtek/rtw88/usb.h
  2022. --- linux-6.1/drivers/net/wireless/realtek/rtw88/usb.h 1970-01-01 02:00:00.000000000 +0200
  2023. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/usb.h 2022-12-24 00:49:25.775376835 +0200
  2024. @@ -0,0 +1,107 @@
  2025. +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2026. +/* Copyright(c) 2018-2019 Realtek Corporation
  2027. + */
  2028. +
  2029. +#ifndef __RTW_USB_H_
  2030. +#define __RTW_USB_H_
  2031. +
  2032. +#define FW_8192C_START_ADDRESS 0x1000
  2033. +#define FW_8192C_END_ADDRESS 0x5fff
  2034. +
  2035. +#define RTW_USB_MAX_RXTX_COUNT 128
  2036. +#define RTW_USB_VENQT_MAX_BUF_SIZE 254
  2037. +#define MAX_USBCTRL_VENDORREQ_TIMES 10
  2038. +
  2039. +#define RTW_USB_CMD_READ 0xc0
  2040. +#define RTW_USB_CMD_WRITE 0x40
  2041. +#define RTW_USB_CMD_REQ 0x05
  2042. +
  2043. +#define RTW_USB_VENQT_CMD_IDX 0x00
  2044. +
  2045. +#define RTW_USB_SUPER_SPEED_BULK_SIZE 1024
  2046. +#define RTW_USB_HIGH_SPEED_BULK_SIZE 512
  2047. +#define RTW_USB_FULL_SPEED_BULK_SIZE 64
  2048. +
  2049. +#define RTW_USB_TX_SEL_HQ BIT(0)
  2050. +#define RTW_USB_TX_SEL_LQ BIT(1)
  2051. +#define RTW_USB_TX_SEL_NQ BIT(2)
  2052. +#define RTW_USB_TX_SEL_EQ BIT(3)
  2053. +
  2054. +#define RTW_USB_BULK_IN_ADDR 0x80
  2055. +#define RTW_USB_INT_IN_ADDR 0x81
  2056. +
  2057. +#define RTW_USB_HW_QUEUE_ENTRY 8
  2058. +
  2059. +#define RTW_USB_PACKET_OFFSET_SZ 8
  2060. +#define RTW_USB_MAX_XMITBUF_SZ (1024 * 20)
  2061. +#define RTW_USB_MAX_RECVBUF_SZ 32768
  2062. +
  2063. +#define RTW_USB_RECVBUFF_ALIGN_SZ 8
  2064. +
  2065. +#define RTW_USB_RXAGG_SIZE 6
  2066. +#define RTW_USB_RXAGG_TIMEOUT 10
  2067. +
  2068. +#define RTW_USB_RXCB_NUM 4
  2069. +
  2070. +#define RTW_USB_EP_MAX 4
  2071. +
  2072. +#define TX_DESC_QSEL_MAX 20
  2073. +
  2074. +#define RTW_USB_VENDOR_ID_REALTEK 0x0bda
  2075. +
  2076. +static inline struct rtw_usb *rtw_get_usb_priv(struct rtw_dev *rtwdev)
  2077. +{
  2078. + return (struct rtw_usb *)rtwdev->priv;
  2079. +}
  2080. +
  2081. +struct rx_usb_ctrl_block {
  2082. + struct rtw_dev *rtwdev;
  2083. + struct urb *rx_urb;
  2084. + struct sk_buff *rx_skb;
  2085. + int n;
  2086. +};
  2087. +
  2088. +struct rtw_usb_tx_data {
  2089. + u8 sn;
  2090. +};
  2091. +
  2092. +struct rtw_usb {
  2093. + struct rtw_dev *rtwdev;
  2094. + struct usb_device *udev;
  2095. +
  2096. + /* protects usb_data_index */
  2097. + spinlock_t usb_lock;
  2098. + __le32 *usb_data;
  2099. + unsigned int usb_data_index;
  2100. +
  2101. + u32 bulkout_size;
  2102. + u8 pipe_interrupt;
  2103. + u8 pipe_in;
  2104. + u8 out_ep[RTW_USB_EP_MAX];
  2105. + u8 qsel_to_ep[TX_DESC_QSEL_MAX];
  2106. + u8 usb_txagg_num;
  2107. +
  2108. + struct workqueue_struct *txwq, *rxwq;
  2109. +
  2110. + struct sk_buff_head tx_queue[RTW_USB_EP_MAX];
  2111. + struct work_struct tx_work;
  2112. +
  2113. + struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM];
  2114. + struct sk_buff_head rx_queue;
  2115. + struct work_struct rx_work;
  2116. +};
  2117. +
  2118. +static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data(struct sk_buff *skb)
  2119. +{
  2120. + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2121. +
  2122. + BUILD_BUG_ON(sizeof(struct rtw_usb_tx_data) >
  2123. + sizeof(info->status.status_driver_data));
  2124. +
  2125. + return (struct rtw_usb_tx_data *)info->status.status_driver_data;
  2126. +}
  2127. +
  2128. +int rtw_usb_probe(struct usb_interface *intf, const struct usb_device_id *id);
  2129. +void rtw_usb_disconnect(struct usb_interface *intf);
  2130. +
  2131. +#endif
  2132. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/util.c linux-6.2/drivers/net/wireless/realtek/rtw88/util.c
  2133. --- linux-6.1/drivers/net/wireless/realtek/rtw88/util.c 2022-12-12 00:15:18.000000000 +0200
  2134. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/util.c 2022-12-24 00:49:25.775376835 +0200
  2135. @@ -105,3 +105,106 @@ void rtw_desc_to_mcsrate(u16 rate, u8 *m
  2136. *mcs = rate - DESC_RATEMCS0;
  2137. }
  2138. }
  2139. +
  2140. +struct rtw_stas_entry {
  2141. + struct list_head list;
  2142. + struct ieee80211_sta *sta;
  2143. +};
  2144. +
  2145. +struct rtw_iter_stas_data {
  2146. + struct rtw_dev *rtwdev;
  2147. + struct list_head list;
  2148. +};
  2149. +
  2150. +static void rtw_collect_sta_iter(void *data, struct ieee80211_sta *sta)
  2151. +{
  2152. + struct rtw_iter_stas_data *iter_stas = data;
  2153. + struct rtw_stas_entry *stas_entry;
  2154. +
  2155. + stas_entry = kmalloc(sizeof(*stas_entry), GFP_ATOMIC);
  2156. + if (!stas_entry)
  2157. + return;
  2158. +
  2159. + stas_entry->sta = sta;
  2160. + list_add_tail(&stas_entry->list, &iter_stas->list);
  2161. +}
  2162. +
  2163. +void rtw_iterate_stas(struct rtw_dev *rtwdev,
  2164. + void (*iterator)(void *data,
  2165. + struct ieee80211_sta *sta),
  2166. + void *data)
  2167. +{
  2168. + struct rtw_iter_stas_data iter_data;
  2169. + struct rtw_stas_entry *sta_entry, *tmp;
  2170. +
  2171. + /* &rtwdev->mutex makes sure no stations can be removed between
  2172. + * collecting the stations and iterating over them.
  2173. + */
  2174. + lockdep_assert_held(&rtwdev->mutex);
  2175. +
  2176. + iter_data.rtwdev = rtwdev;
  2177. + INIT_LIST_HEAD(&iter_data.list);
  2178. +
  2179. + ieee80211_iterate_stations_atomic(rtwdev->hw, rtw_collect_sta_iter,
  2180. + &iter_data);
  2181. +
  2182. + list_for_each_entry_safe(sta_entry, tmp, &iter_data.list,
  2183. + list) {
  2184. + list_del_init(&sta_entry->list);
  2185. + iterator(data, sta_entry->sta);
  2186. + kfree(sta_entry);
  2187. + }
  2188. +}
  2189. +
  2190. +struct rtw_vifs_entry {
  2191. + struct list_head list;
  2192. + struct ieee80211_vif *vif;
  2193. + u8 mac[ETH_ALEN];
  2194. +};
  2195. +
  2196. +struct rtw_iter_vifs_data {
  2197. + struct rtw_dev *rtwdev;
  2198. + struct list_head list;
  2199. +};
  2200. +
  2201. +static void rtw_collect_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  2202. +{
  2203. + struct rtw_iter_vifs_data *iter_stas = data;
  2204. + struct rtw_vifs_entry *vifs_entry;
  2205. +
  2206. + vifs_entry = kmalloc(sizeof(*vifs_entry), GFP_ATOMIC);
  2207. + if (!vifs_entry)
  2208. + return;
  2209. +
  2210. + vifs_entry->vif = vif;
  2211. + ether_addr_copy(vifs_entry->mac, mac);
  2212. + list_add_tail(&vifs_entry->list, &iter_stas->list);
  2213. +}
  2214. +
  2215. +void rtw_iterate_vifs(struct rtw_dev *rtwdev,
  2216. + void (*iterator)(void *data, u8 *mac,
  2217. + struct ieee80211_vif *vif),
  2218. + void *data)
  2219. +{
  2220. + struct rtw_iter_vifs_data iter_data;
  2221. + struct rtw_vifs_entry *vif_entry, *tmp;
  2222. +
  2223. + /* &rtwdev->mutex makes sure no interfaces can be removed between
  2224. + * collecting the interfaces and iterating over them.
  2225. + */
  2226. + lockdep_assert_held(&rtwdev->mutex);
  2227. +
  2228. + iter_data.rtwdev = rtwdev;
  2229. + INIT_LIST_HEAD(&iter_data.list);
  2230. +
  2231. + ieee80211_iterate_active_interfaces_atomic(rtwdev->hw,
  2232. + IEEE80211_IFACE_ITER_NORMAL,
  2233. + rtw_collect_vif_iter, &iter_data);
  2234. +
  2235. + list_for_each_entry_safe(vif_entry, tmp, &iter_data.list,
  2236. + list) {
  2237. + list_del_init(&vif_entry->list);
  2238. + iterator(data, vif_entry->mac, vif_entry->vif);
  2239. + kfree(vif_entry);
  2240. + }
  2241. +}
  2242. diff -Nurp linux-6.1/drivers/net/wireless/realtek/rtw88/util.h linux-6.2/drivers/net/wireless/realtek/rtw88/util.h
  2243. --- linux-6.1/drivers/net/wireless/realtek/rtw88/util.h 2022-12-12 00:15:18.000000000 +0200
  2244. +++ linux-6.2/drivers/net/wireless/realtek/rtw88/util.h 2022-12-24 00:49:25.775376835 +0200
  2245. @@ -7,9 +7,6 @@
  2246. struct rtw_dev;
  2247. -#define rtw_iterate_vifs(rtwdev, iterator, data) \
  2248. - ieee80211_iterate_active_interfaces(rtwdev->hw, \
  2249. - IEEE80211_IFACE_ITER_NORMAL, iterator, data)
  2250. #define rtw_iterate_vifs_atomic(rtwdev, iterator, data) \
  2251. ieee80211_iterate_active_interfaces_atomic(rtwdev->hw, \
  2252. IEEE80211_IFACE_ITER_NORMAL, iterator, data)
  2253. @@ -20,6 +17,15 @@ struct rtw_dev;
  2254. #define rtw_iterate_keys_rcu(rtwdev, vif, iterator, data) \
  2255. ieee80211_iter_keys_rcu((rtwdev)->hw, vif, iterator, data)
  2256. +void rtw_iterate_vifs(struct rtw_dev *rtwdev,
  2257. + void (*iterator)(void *data, u8 *mac,
  2258. + struct ieee80211_vif *vif),
  2259. + void *data);
  2260. +void rtw_iterate_stas(struct rtw_dev *rtwdev,
  2261. + void (*iterator)(void *data,
  2262. + struct ieee80211_sta *sta),
  2263. + void *data);
  2264. +
  2265. static inline u8 *get_hdr_bssid(struct ieee80211_hdr *hdr)
  2266. {
  2267. __le16 fc = hdr->frame_control;