debug.c 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680
  1. // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  2. /* Copyright(c) 2019-2020 Realtek Corporation
  3. */
  4. #include <linux/vmalloc.h>
  5. #include "coex.h"
  6. #include "debug.h"
  7. #include "fw.h"
  8. #include "mac.h"
  9. #include "pci.h"
  10. #include "ps.h"
  11. #include "reg.h"
  12. #include "sar.h"
  13. #ifdef CONFIG_RTW89_DEBUGMSG
  14. unsigned int rtw89_debug_mask;
  15. EXPORT_SYMBOL(rtw89_debug_mask);
  16. module_param_named(debug_mask, rtw89_debug_mask, uint, 0644);
  17. MODULE_PARM_DESC(debug_mask, "Debugging mask");
  18. #endif
  19. #ifdef CONFIG_RTW89_DEBUGFS
  20. struct rtw89_debugfs_priv {
  21. struct rtw89_dev *rtwdev;
  22. int (*cb_read)(struct seq_file *m, void *v);
  23. ssize_t (*cb_write)(struct file *filp, const char __user *buffer,
  24. size_t count, loff_t *loff);
  25. union {
  26. u32 cb_data;
  27. struct {
  28. u32 addr;
  29. u32 len;
  30. } read_reg;
  31. struct {
  32. u32 addr;
  33. u32 mask;
  34. u8 path;
  35. } read_rf;
  36. struct {
  37. u8 ss_dbg:1;
  38. u8 dle_dbg:1;
  39. u8 dmac_dbg:1;
  40. u8 cmac_dbg:1;
  41. u8 dbg_port:1;
  42. } dbgpkg_en;
  43. struct {
  44. u32 start;
  45. u32 len;
  46. u8 sel;
  47. } mac_mem;
  48. };
  49. };
  50. static const u16 rtw89_rate_info_bw_to_mhz_map[] = {
  51. [RATE_INFO_BW_20] = 20,
  52. [RATE_INFO_BW_40] = 40,
  53. [RATE_INFO_BW_80] = 80,
  54. [RATE_INFO_BW_160] = 160,
  55. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0)
  56. [RATE_INFO_BW_320] = 320,
  57. #endif
  58. };
  59. static u16 rtw89_rate_info_bw_to_mhz(enum rate_info_bw bw)
  60. {
  61. if (bw < ARRAY_SIZE(rtw89_rate_info_bw_to_mhz_map))
  62. return rtw89_rate_info_bw_to_mhz_map[bw];
  63. return 0;
  64. }
  65. static int rtw89_debugfs_single_show(struct seq_file *m, void *v)
  66. {
  67. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  68. return debugfs_priv->cb_read(m, v);
  69. }
  70. static ssize_t rtw89_debugfs_single_write(struct file *filp,
  71. const char __user *buffer,
  72. size_t count, loff_t *loff)
  73. {
  74. struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
  75. return debugfs_priv->cb_write(filp, buffer, count, loff);
  76. }
  77. static ssize_t rtw89_debugfs_seq_file_write(struct file *filp,
  78. const char __user *buffer,
  79. size_t count, loff_t *loff)
  80. {
  81. struct seq_file *seqpriv = (struct seq_file *)filp->private_data;
  82. struct rtw89_debugfs_priv *debugfs_priv = seqpriv->private;
  83. return debugfs_priv->cb_write(filp, buffer, count, loff);
  84. }
  85. static int rtw89_debugfs_single_open(struct inode *inode, struct file *filp)
  86. {
  87. return single_open(filp, rtw89_debugfs_single_show, inode->i_private);
  88. }
  89. static int rtw89_debugfs_close(struct inode *inode, struct file *filp)
  90. {
  91. return 0;
  92. }
  93. static const struct file_operations file_ops_single_r = {
  94. .owner = THIS_MODULE,
  95. .open = rtw89_debugfs_single_open,
  96. .read = seq_read,
  97. .llseek = seq_lseek,
  98. .release = single_release,
  99. };
  100. static const struct file_operations file_ops_common_rw = {
  101. .owner = THIS_MODULE,
  102. .open = rtw89_debugfs_single_open,
  103. .release = single_release,
  104. .read = seq_read,
  105. .llseek = seq_lseek,
  106. .write = rtw89_debugfs_seq_file_write,
  107. };
  108. static const struct file_operations file_ops_single_w = {
  109. .owner = THIS_MODULE,
  110. .write = rtw89_debugfs_single_write,
  111. .open = simple_open,
  112. .release = rtw89_debugfs_close,
  113. };
  114. static ssize_t
  115. rtw89_debug_priv_read_reg_select(struct file *filp,
  116. const char __user *user_buf,
  117. size_t count, loff_t *loff)
  118. {
  119. struct seq_file *m = (struct seq_file *)filp->private_data;
  120. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  121. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  122. char buf[32];
  123. size_t buf_size;
  124. u32 addr, len;
  125. int num;
  126. buf_size = min(count, sizeof(buf) - 1);
  127. if (copy_from_user(buf, user_buf, buf_size))
  128. return -EFAULT;
  129. buf[buf_size] = '\0';
  130. num = sscanf(buf, "%x %x", &addr, &len);
  131. if (num != 2) {
  132. rtw89_info(rtwdev, "invalid format: <addr> <len>\n");
  133. return -EINVAL;
  134. }
  135. debugfs_priv->read_reg.addr = addr;
  136. debugfs_priv->read_reg.len = len;
  137. rtw89_info(rtwdev, "select read %d bytes from 0x%08x\n", len, addr);
  138. return count;
  139. }
  140. static int rtw89_debug_priv_read_reg_get(struct seq_file *m, void *v)
  141. {
  142. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  143. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  144. u32 addr, end, data, k;
  145. u32 len;
  146. len = debugfs_priv->read_reg.len;
  147. addr = debugfs_priv->read_reg.addr;
  148. if (len > 4)
  149. goto ndata;
  150. switch (len) {
  151. case 1:
  152. data = rtw89_read8(rtwdev, addr);
  153. break;
  154. case 2:
  155. data = rtw89_read16(rtwdev, addr);
  156. break;
  157. case 4:
  158. data = rtw89_read32(rtwdev, addr);
  159. break;
  160. default:
  161. rtw89_info(rtwdev, "invalid read reg len %d\n", len);
  162. return -EINVAL;
  163. }
  164. seq_printf(m, "get %d bytes at 0x%08x=0x%08x\n", len, addr, data);
  165. return 0;
  166. ndata:
  167. end = addr + len;
  168. for (; addr < end; addr += 16) {
  169. seq_printf(m, "%08xh : ", 0x18600000 + addr);
  170. for (k = 0; k < 16; k += 4) {
  171. data = rtw89_read32(rtwdev, addr + k);
  172. seq_printf(m, "%08x ", data);
  173. }
  174. seq_puts(m, "\n");
  175. }
  176. return 0;
  177. }
  178. static ssize_t rtw89_debug_priv_write_reg_set(struct file *filp,
  179. const char __user *user_buf,
  180. size_t count, loff_t *loff)
  181. {
  182. struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
  183. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  184. char buf[32];
  185. size_t buf_size;
  186. u32 addr, val, len;
  187. int num;
  188. buf_size = min(count, sizeof(buf) - 1);
  189. if (copy_from_user(buf, user_buf, buf_size))
  190. return -EFAULT;
  191. buf[buf_size] = '\0';
  192. num = sscanf(buf, "%x %x %x", &addr, &val, &len);
  193. if (num != 3) {
  194. rtw89_info(rtwdev, "invalid format: <addr> <val> <len>\n");
  195. return -EINVAL;
  196. }
  197. switch (len) {
  198. case 1:
  199. rtw89_info(rtwdev, "reg write8 0x%08x: 0x%02x\n", addr, val);
  200. rtw89_write8(rtwdev, addr, (u8)val);
  201. break;
  202. case 2:
  203. rtw89_info(rtwdev, "reg write16 0x%08x: 0x%04x\n", addr, val);
  204. rtw89_write16(rtwdev, addr, (u16)val);
  205. break;
  206. case 4:
  207. rtw89_info(rtwdev, "reg write32 0x%08x: 0x%08x\n", addr, val);
  208. rtw89_write32(rtwdev, addr, (u32)val);
  209. break;
  210. default:
  211. rtw89_info(rtwdev, "invalid read write len %d\n", len);
  212. break;
  213. }
  214. return count;
  215. }
  216. static ssize_t
  217. rtw89_debug_priv_read_rf_select(struct file *filp,
  218. const char __user *user_buf,
  219. size_t count, loff_t *loff)
  220. {
  221. struct seq_file *m = (struct seq_file *)filp->private_data;
  222. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  223. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  224. char buf[32];
  225. size_t buf_size;
  226. u32 addr, mask;
  227. u8 path;
  228. int num;
  229. buf_size = min(count, sizeof(buf) - 1);
  230. if (copy_from_user(buf, user_buf, buf_size))
  231. return -EFAULT;
  232. buf[buf_size] = '\0';
  233. num = sscanf(buf, "%hhd %x %x", &path, &addr, &mask);
  234. if (num != 3) {
  235. rtw89_info(rtwdev, "invalid format: <path> <addr> <mask>\n");
  236. return -EINVAL;
  237. }
  238. if (path >= rtwdev->chip->rf_path_num) {
  239. rtw89_info(rtwdev, "wrong rf path\n");
  240. return -EINVAL;
  241. }
  242. debugfs_priv->read_rf.addr = addr;
  243. debugfs_priv->read_rf.mask = mask;
  244. debugfs_priv->read_rf.path = path;
  245. rtw89_info(rtwdev, "select read rf path %d from 0x%08x\n", path, addr);
  246. return count;
  247. }
  248. static int rtw89_debug_priv_read_rf_get(struct seq_file *m, void *v)
  249. {
  250. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  251. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  252. u32 addr, data, mask;
  253. u8 path;
  254. addr = debugfs_priv->read_rf.addr;
  255. mask = debugfs_priv->read_rf.mask;
  256. path = debugfs_priv->read_rf.path;
  257. data = rtw89_read_rf(rtwdev, path, addr, mask);
  258. seq_printf(m, "path %d, rf register 0x%08x=0x%08x\n", path, addr, data);
  259. return 0;
  260. }
  261. static ssize_t rtw89_debug_priv_write_rf_set(struct file *filp,
  262. const char __user *user_buf,
  263. size_t count, loff_t *loff)
  264. {
  265. struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
  266. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  267. char buf[32];
  268. size_t buf_size;
  269. u32 addr, val, mask;
  270. u8 path;
  271. int num;
  272. buf_size = min(count, sizeof(buf) - 1);
  273. if (copy_from_user(buf, user_buf, buf_size))
  274. return -EFAULT;
  275. buf[buf_size] = '\0';
  276. num = sscanf(buf, "%hhd %x %x %x", &path, &addr, &mask, &val);
  277. if (num != 4) {
  278. rtw89_info(rtwdev, "invalid format: <path> <addr> <mask> <val>\n");
  279. return -EINVAL;
  280. }
  281. if (path >= rtwdev->chip->rf_path_num) {
  282. rtw89_info(rtwdev, "wrong rf path\n");
  283. return -EINVAL;
  284. }
  285. rtw89_info(rtwdev, "path %d, rf register write 0x%08x=0x%08x (mask = 0x%08x)\n",
  286. path, addr, val, mask);
  287. rtw89_write_rf(rtwdev, path, addr, mask, val);
  288. return count;
  289. }
  290. static int rtw89_debug_priv_rf_reg_dump_get(struct seq_file *m, void *v)
  291. {
  292. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  293. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  294. const struct rtw89_chip_info *chip = rtwdev->chip;
  295. u32 addr, offset, data;
  296. u8 path;
  297. for (path = 0; path < chip->rf_path_num; path++) {
  298. seq_printf(m, "RF path %d:\n\n", path);
  299. for (addr = 0; addr < 0x100; addr += 4) {
  300. seq_printf(m, "0x%08x: ", addr);
  301. for (offset = 0; offset < 4; offset++) {
  302. data = rtw89_read_rf(rtwdev, path,
  303. addr + offset, RFREG_MASK);
  304. seq_printf(m, "0x%05x ", data);
  305. }
  306. seq_puts(m, "\n");
  307. }
  308. seq_puts(m, "\n");
  309. }
  310. return 0;
  311. }
  312. struct txpwr_ent {
  313. const char *txt;
  314. u8 len;
  315. };
  316. struct txpwr_map {
  317. const struct txpwr_ent *ent;
  318. u8 size;
  319. u32 addr_from;
  320. u32 addr_to;
  321. u32 addr_to_1ss;
  322. };
  323. #define __GEN_TXPWR_ENT2(_t, _e0, _e1) \
  324. { .len = 2, .txt = _t "\t- " _e0 " " _e1 }
  325. #define __GEN_TXPWR_ENT4(_t, _e0, _e1, _e2, _e3) \
  326. { .len = 4, .txt = _t "\t- " _e0 " " _e1 " " _e2 " " _e3 }
  327. #define __GEN_TXPWR_ENT8(_t, _e0, _e1, _e2, _e3, _e4, _e5, _e6, _e7) \
  328. { .len = 8, .txt = _t "\t- " \
  329. _e0 " " _e1 " " _e2 " " _e3 " " \
  330. _e4 " " _e5 " " _e6 " " _e7 }
  331. static const struct txpwr_ent __txpwr_ent_byr[] = {
  332. __GEN_TXPWR_ENT4("CCK ", "1M ", "2M ", "5.5M ", "11M "),
  333. __GEN_TXPWR_ENT4("LEGACY ", "6M ", "9M ", "12M ", "18M "),
  334. __GEN_TXPWR_ENT4("LEGACY ", "24M ", "36M ", "48M ", "54M "),
  335. /* 1NSS */
  336. __GEN_TXPWR_ENT4("MCS_1NSS ", "MCS0 ", "MCS1 ", "MCS2 ", "MCS3 "),
  337. __GEN_TXPWR_ENT4("MCS_1NSS ", "MCS4 ", "MCS5 ", "MCS6 ", "MCS7 "),
  338. __GEN_TXPWR_ENT4("MCS_1NSS ", "MCS8 ", "MCS9 ", "MCS10", "MCS11"),
  339. __GEN_TXPWR_ENT4("HEDCM_1NSS", "MCS0 ", "MCS1 ", "MCS3 ", "MCS4 "),
  340. /* 2NSS */
  341. __GEN_TXPWR_ENT4("MCS_2NSS ", "MCS0 ", "MCS1 ", "MCS2 ", "MCS3 "),
  342. __GEN_TXPWR_ENT4("MCS_2NSS ", "MCS4 ", "MCS5 ", "MCS6 ", "MCS7 "),
  343. __GEN_TXPWR_ENT4("MCS_2NSS ", "MCS8 ", "MCS9 ", "MCS10", "MCS11"),
  344. __GEN_TXPWR_ENT4("HEDCM_2NSS", "MCS0 ", "MCS1 ", "MCS3 ", "MCS4 "),
  345. };
  346. static_assert((ARRAY_SIZE(__txpwr_ent_byr) * 4) ==
  347. (R_AX_PWR_BY_RATE_MAX - R_AX_PWR_BY_RATE + 4));
  348. static const struct txpwr_map __txpwr_map_byr = {
  349. .ent = __txpwr_ent_byr,
  350. .size = ARRAY_SIZE(__txpwr_ent_byr),
  351. .addr_from = R_AX_PWR_BY_RATE,
  352. .addr_to = R_AX_PWR_BY_RATE_MAX,
  353. .addr_to_1ss = R_AX_PWR_BY_RATE_1SS_MAX,
  354. };
  355. static const struct txpwr_ent __txpwr_ent_lmt[] = {
  356. /* 1TX */
  357. __GEN_TXPWR_ENT2("CCK_1TX_20M ", "NON_BF", "BF"),
  358. __GEN_TXPWR_ENT2("CCK_1TX_40M ", "NON_BF", "BF"),
  359. __GEN_TXPWR_ENT2("OFDM_1TX ", "NON_BF", "BF"),
  360. __GEN_TXPWR_ENT2("MCS_1TX_20M_0 ", "NON_BF", "BF"),
  361. __GEN_TXPWR_ENT2("MCS_1TX_20M_1 ", "NON_BF", "BF"),
  362. __GEN_TXPWR_ENT2("MCS_1TX_20M_2 ", "NON_BF", "BF"),
  363. __GEN_TXPWR_ENT2("MCS_1TX_20M_3 ", "NON_BF", "BF"),
  364. __GEN_TXPWR_ENT2("MCS_1TX_20M_4 ", "NON_BF", "BF"),
  365. __GEN_TXPWR_ENT2("MCS_1TX_20M_5 ", "NON_BF", "BF"),
  366. __GEN_TXPWR_ENT2("MCS_1TX_20M_6 ", "NON_BF", "BF"),
  367. __GEN_TXPWR_ENT2("MCS_1TX_20M_7 ", "NON_BF", "BF"),
  368. __GEN_TXPWR_ENT2("MCS_1TX_40M_0 ", "NON_BF", "BF"),
  369. __GEN_TXPWR_ENT2("MCS_1TX_40M_1 ", "NON_BF", "BF"),
  370. __GEN_TXPWR_ENT2("MCS_1TX_40M_2 ", "NON_BF", "BF"),
  371. __GEN_TXPWR_ENT2("MCS_1TX_40M_3 ", "NON_BF", "BF"),
  372. __GEN_TXPWR_ENT2("MCS_1TX_80M_0 ", "NON_BF", "BF"),
  373. __GEN_TXPWR_ENT2("MCS_1TX_80M_1 ", "NON_BF", "BF"),
  374. __GEN_TXPWR_ENT2("MCS_1TX_160M ", "NON_BF", "BF"),
  375. __GEN_TXPWR_ENT2("MCS_1TX_40M_0p5", "NON_BF", "BF"),
  376. __GEN_TXPWR_ENT2("MCS_1TX_40M_2p5", "NON_BF", "BF"),
  377. /* 2TX */
  378. __GEN_TXPWR_ENT2("CCK_2TX_20M ", "NON_BF", "BF"),
  379. __GEN_TXPWR_ENT2("CCK_2TX_40M ", "NON_BF", "BF"),
  380. __GEN_TXPWR_ENT2("OFDM_2TX ", "NON_BF", "BF"),
  381. __GEN_TXPWR_ENT2("MCS_2TX_20M_0 ", "NON_BF", "BF"),
  382. __GEN_TXPWR_ENT2("MCS_2TX_20M_1 ", "NON_BF", "BF"),
  383. __GEN_TXPWR_ENT2("MCS_2TX_20M_2 ", "NON_BF", "BF"),
  384. __GEN_TXPWR_ENT2("MCS_2TX_20M_3 ", "NON_BF", "BF"),
  385. __GEN_TXPWR_ENT2("MCS_2TX_20M_4 ", "NON_BF", "BF"),
  386. __GEN_TXPWR_ENT2("MCS_2TX_20M_5 ", "NON_BF", "BF"),
  387. __GEN_TXPWR_ENT2("MCS_2TX_20M_6 ", "NON_BF", "BF"),
  388. __GEN_TXPWR_ENT2("MCS_2TX_20M_7 ", "NON_BF", "BF"),
  389. __GEN_TXPWR_ENT2("MCS_2TX_40M_0 ", "NON_BF", "BF"),
  390. __GEN_TXPWR_ENT2("MCS_2TX_40M_1 ", "NON_BF", "BF"),
  391. __GEN_TXPWR_ENT2("MCS_2TX_40M_2 ", "NON_BF", "BF"),
  392. __GEN_TXPWR_ENT2("MCS_2TX_40M_3 ", "NON_BF", "BF"),
  393. __GEN_TXPWR_ENT2("MCS_2TX_80M_0 ", "NON_BF", "BF"),
  394. __GEN_TXPWR_ENT2("MCS_2TX_80M_1 ", "NON_BF", "BF"),
  395. __GEN_TXPWR_ENT2("MCS_2TX_160M ", "NON_BF", "BF"),
  396. __GEN_TXPWR_ENT2("MCS_2TX_40M_0p5", "NON_BF", "BF"),
  397. __GEN_TXPWR_ENT2("MCS_2TX_40M_2p5", "NON_BF", "BF"),
  398. };
  399. static_assert((ARRAY_SIZE(__txpwr_ent_lmt) * 2) ==
  400. (R_AX_PWR_LMT_MAX - R_AX_PWR_LMT + 4));
  401. static const struct txpwr_map __txpwr_map_lmt = {
  402. .ent = __txpwr_ent_lmt,
  403. .size = ARRAY_SIZE(__txpwr_ent_lmt),
  404. .addr_from = R_AX_PWR_LMT,
  405. .addr_to = R_AX_PWR_LMT_MAX,
  406. .addr_to_1ss = R_AX_PWR_LMT_1SS_MAX,
  407. };
  408. static const struct txpwr_ent __txpwr_ent_lmt_ru[] = {
  409. /* 1TX */
  410. __GEN_TXPWR_ENT8("1TX", "RU26__0", "RU26__1", "RU26__2", "RU26__3",
  411. "RU26__4", "RU26__5", "RU26__6", "RU26__7"),
  412. __GEN_TXPWR_ENT8("1TX", "RU52__0", "RU52__1", "RU52__2", "RU52__3",
  413. "RU52__4", "RU52__5", "RU52__6", "RU52__7"),
  414. __GEN_TXPWR_ENT8("1TX", "RU106_0", "RU106_1", "RU106_2", "RU106_3",
  415. "RU106_4", "RU106_5", "RU106_6", "RU106_7"),
  416. /* 2TX */
  417. __GEN_TXPWR_ENT8("2TX", "RU26__0", "RU26__1", "RU26__2", "RU26__3",
  418. "RU26__4", "RU26__5", "RU26__6", "RU26__7"),
  419. __GEN_TXPWR_ENT8("2TX", "RU52__0", "RU52__1", "RU52__2", "RU52__3",
  420. "RU52__4", "RU52__5", "RU52__6", "RU52__7"),
  421. __GEN_TXPWR_ENT8("2TX", "RU106_0", "RU106_1", "RU106_2", "RU106_3",
  422. "RU106_4", "RU106_5", "RU106_6", "RU106_7"),
  423. };
  424. static_assert((ARRAY_SIZE(__txpwr_ent_lmt_ru) * 8) ==
  425. (R_AX_PWR_RU_LMT_MAX - R_AX_PWR_RU_LMT + 4));
  426. static const struct txpwr_map __txpwr_map_lmt_ru = {
  427. .ent = __txpwr_ent_lmt_ru,
  428. .size = ARRAY_SIZE(__txpwr_ent_lmt_ru),
  429. .addr_from = R_AX_PWR_RU_LMT,
  430. .addr_to = R_AX_PWR_RU_LMT_MAX,
  431. .addr_to_1ss = R_AX_PWR_RU_LMT_1SS_MAX,
  432. };
  433. static u8 __print_txpwr_ent(struct seq_file *m, const struct txpwr_ent *ent,
  434. const s8 *buf, const u8 cur)
  435. {
  436. char *fmt;
  437. switch (ent->len) {
  438. case 2:
  439. fmt = "%s\t| %3d, %3d,\tdBm\n";
  440. seq_printf(m, fmt, ent->txt, buf[cur], buf[cur + 1]);
  441. return 2;
  442. case 4:
  443. fmt = "%s\t| %3d, %3d, %3d, %3d,\tdBm\n";
  444. seq_printf(m, fmt, ent->txt, buf[cur], buf[cur + 1],
  445. buf[cur + 2], buf[cur + 3]);
  446. return 4;
  447. case 8:
  448. fmt = "%s\t| %3d, %3d, %3d, %3d, %3d, %3d, %3d, %3d,\tdBm\n";
  449. seq_printf(m, fmt, ent->txt, buf[cur], buf[cur + 1],
  450. buf[cur + 2], buf[cur + 3], buf[cur + 4],
  451. buf[cur + 5], buf[cur + 6], buf[cur + 7]);
  452. return 8;
  453. default:
  454. return 0;
  455. }
  456. }
  457. static int __print_txpwr_map(struct seq_file *m, struct rtw89_dev *rtwdev,
  458. const struct txpwr_map *map)
  459. {
  460. u8 fct = rtwdev->chip->txpwr_factor_mac;
  461. u8 path_num = rtwdev->chip->rf_path_num;
  462. u32 max_valid_addr;
  463. u32 val, addr;
  464. s8 *buf, tmp;
  465. u8 cur, i;
  466. int ret;
  467. buf = vzalloc(map->addr_to - map->addr_from + 4);
  468. if (!buf)
  469. return -ENOMEM;
  470. if (path_num == 1)
  471. max_valid_addr = map->addr_to_1ss;
  472. else
  473. max_valid_addr = map->addr_to;
  474. for (addr = map->addr_from; addr <= max_valid_addr; addr += 4) {
  475. ret = rtw89_mac_txpwr_read32(rtwdev, RTW89_PHY_0, addr, &val);
  476. if (ret)
  477. val = MASKDWORD;
  478. cur = addr - map->addr_from;
  479. for (i = 0; i < 4; i++, val >>= 8) {
  480. /* signed 7 bits, and reserved BIT(7) */
  481. tmp = sign_extend32(val, 6);
  482. buf[cur + i] = tmp >> fct;
  483. }
  484. }
  485. for (cur = 0, i = 0; i < map->size; i++)
  486. cur += __print_txpwr_ent(m, &map->ent[i], buf, cur);
  487. vfree(buf);
  488. return 0;
  489. }
  490. #define case_REGD(_regd) \
  491. case RTW89_ ## _regd: \
  492. seq_puts(m, #_regd "\n"); \
  493. break
  494. static void __print_regd(struct seq_file *m, struct rtw89_dev *rtwdev,
  495. const struct rtw89_chan *chan)
  496. {
  497. u8 band = chan->band_type;
  498. u8 regd = rtw89_regd_get(rtwdev, band);
  499. switch (regd) {
  500. default:
  501. seq_printf(m, "UNKNOWN: %d\n", regd);
  502. break;
  503. case_REGD(WW);
  504. case_REGD(ETSI);
  505. case_REGD(FCC);
  506. case_REGD(MKK);
  507. case_REGD(NA);
  508. case_REGD(IC);
  509. case_REGD(KCC);
  510. case_REGD(NCC);
  511. case_REGD(CHILE);
  512. case_REGD(ACMA);
  513. case_REGD(MEXICO);
  514. case_REGD(UKRAINE);
  515. case_REGD(CN);
  516. }
  517. }
  518. #undef case_REGD
  519. static int rtw89_debug_priv_txpwr_table_get(struct seq_file *m, void *v)
  520. {
  521. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  522. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  523. const struct rtw89_chan *chan;
  524. int ret = 0;
  525. mutex_lock(&rtwdev->mutex);
  526. rtw89_leave_ps_mode(rtwdev);
  527. chan = rtw89_chan_get(rtwdev, RTW89_SUB_ENTITY_0);
  528. seq_puts(m, "[Regulatory] ");
  529. __print_regd(m, rtwdev, chan);
  530. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
  531. seq_puts(m, "[SAR]\n");
  532. rtw89_print_sar(m, rtwdev, chan->freq);
  533. seq_puts(m, "[TAS]\n");
  534. rtw89_print_tas(m, rtwdev);
  535. #endif
  536. seq_puts(m, "\n[TX power byrate]\n");
  537. ret = __print_txpwr_map(m, rtwdev, &__txpwr_map_byr);
  538. if (ret)
  539. goto err;
  540. seq_puts(m, "\n[TX power limit]\n");
  541. ret = __print_txpwr_map(m, rtwdev, &__txpwr_map_lmt);
  542. if (ret)
  543. goto err;
  544. seq_puts(m, "\n[TX power limit_ru]\n");
  545. ret = __print_txpwr_map(m, rtwdev, &__txpwr_map_lmt_ru);
  546. if (ret)
  547. goto err;
  548. err:
  549. mutex_unlock(&rtwdev->mutex);
  550. return ret;
  551. }
  552. static ssize_t
  553. rtw89_debug_priv_mac_reg_dump_select(struct file *filp,
  554. const char __user *user_buf,
  555. size_t count, loff_t *loff)
  556. {
  557. struct seq_file *m = (struct seq_file *)filp->private_data;
  558. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  559. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  560. const struct rtw89_chip_info *chip = rtwdev->chip;
  561. char buf[32];
  562. size_t buf_size;
  563. int sel;
  564. int ret;
  565. buf_size = min(count, sizeof(buf) - 1);
  566. if (copy_from_user(buf, user_buf, buf_size))
  567. return -EFAULT;
  568. buf[buf_size] = '\0';
  569. ret = kstrtoint(buf, 0, &sel);
  570. if (ret)
  571. return ret;
  572. if (sel < RTW89_DBG_SEL_MAC_00 || sel > RTW89_DBG_SEL_RFC) {
  573. rtw89_info(rtwdev, "invalid args: %d\n", sel);
  574. return -EINVAL;
  575. }
  576. if (sel == RTW89_DBG_SEL_MAC_30 && chip->chip_id != RTL8852C) {
  577. rtw89_info(rtwdev, "sel %d is address hole on chip %d\n", sel,
  578. chip->chip_id);
  579. return -EINVAL;
  580. }
  581. debugfs_priv->cb_data = sel;
  582. rtw89_info(rtwdev, "select mac page dump %d\n", debugfs_priv->cb_data);
  583. return count;
  584. }
  585. #define RTW89_MAC_PAGE_SIZE 0x100
  586. static int rtw89_debug_priv_mac_reg_dump_get(struct seq_file *m, void *v)
  587. {
  588. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  589. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  590. enum rtw89_debug_mac_reg_sel reg_sel = debugfs_priv->cb_data;
  591. u32 start, end;
  592. u32 i, j, k, page;
  593. u32 val;
  594. switch (reg_sel) {
  595. case RTW89_DBG_SEL_MAC_00:
  596. seq_puts(m, "Debug selected MAC page 0x00\n");
  597. start = 0x000;
  598. end = 0x014;
  599. break;
  600. case RTW89_DBG_SEL_MAC_30:
  601. seq_puts(m, "Debug selected MAC page 0x30\n");
  602. start = 0x030;
  603. end = 0x033;
  604. break;
  605. case RTW89_DBG_SEL_MAC_40:
  606. seq_puts(m, "Debug selected MAC page 0x40\n");
  607. start = 0x040;
  608. end = 0x07f;
  609. break;
  610. case RTW89_DBG_SEL_MAC_80:
  611. seq_puts(m, "Debug selected MAC page 0x80\n");
  612. start = 0x080;
  613. end = 0x09f;
  614. break;
  615. case RTW89_DBG_SEL_MAC_C0:
  616. seq_puts(m, "Debug selected MAC page 0xc0\n");
  617. start = 0x0c0;
  618. end = 0x0df;
  619. break;
  620. case RTW89_DBG_SEL_MAC_E0:
  621. seq_puts(m, "Debug selected MAC page 0xe0\n");
  622. start = 0x0e0;
  623. end = 0x0ff;
  624. break;
  625. case RTW89_DBG_SEL_BB:
  626. seq_puts(m, "Debug selected BB register\n");
  627. start = 0x100;
  628. end = 0x17f;
  629. break;
  630. case RTW89_DBG_SEL_IQK:
  631. seq_puts(m, "Debug selected IQK register\n");
  632. start = 0x180;
  633. end = 0x1bf;
  634. break;
  635. case RTW89_DBG_SEL_RFC:
  636. seq_puts(m, "Debug selected RFC register\n");
  637. start = 0x1c0;
  638. end = 0x1ff;
  639. break;
  640. default:
  641. seq_puts(m, "Selected invalid register page\n");
  642. return -EINVAL;
  643. }
  644. for (i = start; i <= end; i++) {
  645. page = i << 8;
  646. for (j = page; j < page + RTW89_MAC_PAGE_SIZE; j += 16) {
  647. seq_printf(m, "%08xh : ", 0x18600000 + j);
  648. for (k = 0; k < 4; k++) {
  649. val = rtw89_read32(rtwdev, j + (k << 2));
  650. seq_printf(m, "%08x ", val);
  651. }
  652. seq_puts(m, "\n");
  653. }
  654. }
  655. return 0;
  656. }
  657. static ssize_t
  658. rtw89_debug_priv_mac_mem_dump_select(struct file *filp,
  659. const char __user *user_buf,
  660. size_t count, loff_t *loff)
  661. {
  662. struct seq_file *m = (struct seq_file *)filp->private_data;
  663. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  664. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  665. char buf[32];
  666. size_t buf_size;
  667. u32 sel, start_addr, len;
  668. int num;
  669. buf_size = min(count, sizeof(buf) - 1);
  670. if (copy_from_user(buf, user_buf, buf_size))
  671. return -EFAULT;
  672. buf[buf_size] = '\0';
  673. num = sscanf(buf, "%x %x %x", &sel, &start_addr, &len);
  674. if (num != 3) {
  675. rtw89_info(rtwdev, "invalid format: <sel> <start> <len>\n");
  676. return -EINVAL;
  677. }
  678. debugfs_priv->mac_mem.sel = sel;
  679. debugfs_priv->mac_mem.start = start_addr;
  680. debugfs_priv->mac_mem.len = len;
  681. rtw89_info(rtwdev, "select mem %d start %d len %d\n",
  682. sel, start_addr, len);
  683. return count;
  684. }
  685. static void rtw89_debug_dump_mac_mem(struct seq_file *m,
  686. struct rtw89_dev *rtwdev,
  687. u8 sel, u32 start_addr, u32 len)
  688. {
  689. const struct rtw89_mac_gen_def *mac = rtwdev->chip->mac_def;
  690. u32 filter_model_addr = mac->filter_model_addr;
  691. u32 indir_access_addr = mac->indir_access_addr;
  692. u32 base_addr, start_page, residue;
  693. u32 i, j, p, pages;
  694. u32 dump_len, remain;
  695. u32 val;
  696. remain = len;
  697. pages = len / MAC_MEM_DUMP_PAGE_SIZE + 1;
  698. start_page = start_addr / MAC_MEM_DUMP_PAGE_SIZE;
  699. residue = start_addr % MAC_MEM_DUMP_PAGE_SIZE;
  700. base_addr = mac->mem_base_addrs[sel];
  701. base_addr += start_page * MAC_MEM_DUMP_PAGE_SIZE;
  702. for (p = 0; p < pages; p++) {
  703. dump_len = min_t(u32, remain, MAC_MEM_DUMP_PAGE_SIZE);
  704. rtw89_write32(rtwdev, filter_model_addr, base_addr);
  705. for (i = indir_access_addr + residue;
  706. i < indir_access_addr + dump_len;) {
  707. seq_printf(m, "%08xh:", i);
  708. for (j = 0;
  709. j < 4 && i < indir_access_addr + dump_len;
  710. j++, i += 4) {
  711. val = rtw89_read32(rtwdev, i);
  712. seq_printf(m, " %08x", val);
  713. remain -= 4;
  714. }
  715. seq_puts(m, "\n");
  716. }
  717. base_addr += MAC_MEM_DUMP_PAGE_SIZE;
  718. }
  719. }
  720. static int
  721. rtw89_debug_priv_mac_mem_dump_get(struct seq_file *m, void *v)
  722. {
  723. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  724. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  725. bool grant_read = false;
  726. if (debugfs_priv->mac_mem.sel >= RTW89_MAC_MEM_NUM)
  727. return -ENOENT;
  728. if (rtwdev->chip->chip_id == RTL8852C) {
  729. switch (debugfs_priv->mac_mem.sel) {
  730. case RTW89_MAC_MEM_TXD_FIFO_0_V1:
  731. case RTW89_MAC_MEM_TXD_FIFO_1_V1:
  732. case RTW89_MAC_MEM_TXDATA_FIFO_0:
  733. case RTW89_MAC_MEM_TXDATA_FIFO_1:
  734. grant_read = true;
  735. break;
  736. default:
  737. break;
  738. }
  739. }
  740. mutex_lock(&rtwdev->mutex);
  741. rtw89_leave_ps_mode(rtwdev);
  742. if (grant_read)
  743. rtw89_write32_set(rtwdev, R_AX_TCR1, B_AX_TCR_FORCE_READ_TXDFIFO);
  744. rtw89_debug_dump_mac_mem(m, rtwdev,
  745. debugfs_priv->mac_mem.sel,
  746. debugfs_priv->mac_mem.start,
  747. debugfs_priv->mac_mem.len);
  748. if (grant_read)
  749. rtw89_write32_clr(rtwdev, R_AX_TCR1, B_AX_TCR_FORCE_READ_TXDFIFO);
  750. mutex_unlock(&rtwdev->mutex);
  751. return 0;
  752. }
  753. static ssize_t
  754. rtw89_debug_priv_mac_dbg_port_dump_select(struct file *filp,
  755. const char __user *user_buf,
  756. size_t count, loff_t *loff)
  757. {
  758. struct seq_file *m = (struct seq_file *)filp->private_data;
  759. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  760. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  761. char buf[32];
  762. size_t buf_size;
  763. int sel, set;
  764. int num;
  765. bool enable;
  766. buf_size = min(count, sizeof(buf) - 1);
  767. if (copy_from_user(buf, user_buf, buf_size))
  768. return -EFAULT;
  769. buf[buf_size] = '\0';
  770. num = sscanf(buf, "%d %d", &sel, &set);
  771. if (num != 2) {
  772. rtw89_info(rtwdev, "invalid format: <sel> <set>\n");
  773. return -EINVAL;
  774. }
  775. enable = set != 0;
  776. switch (sel) {
  777. case 0:
  778. debugfs_priv->dbgpkg_en.ss_dbg = enable;
  779. break;
  780. case 1:
  781. debugfs_priv->dbgpkg_en.dle_dbg = enable;
  782. break;
  783. case 2:
  784. debugfs_priv->dbgpkg_en.dmac_dbg = enable;
  785. break;
  786. case 3:
  787. debugfs_priv->dbgpkg_en.cmac_dbg = enable;
  788. break;
  789. case 4:
  790. debugfs_priv->dbgpkg_en.dbg_port = enable;
  791. break;
  792. default:
  793. rtw89_info(rtwdev, "invalid args: sel %d set %d\n", sel, set);
  794. return -EINVAL;
  795. }
  796. rtw89_info(rtwdev, "%s debug port dump %d\n",
  797. enable ? "Enable" : "Disable", sel);
  798. return count;
  799. }
  800. static int rtw89_debug_mac_dump_ss_dbg(struct rtw89_dev *rtwdev,
  801. struct seq_file *m)
  802. {
  803. return 0;
  804. }
  805. static int rtw89_debug_mac_dump_dle_dbg(struct rtw89_dev *rtwdev,
  806. struct seq_file *m)
  807. {
  808. #define DLE_DFI_DUMP(__type, __target, __sel) \
  809. ({ \
  810. u32 __ctrl; \
  811. u32 __reg_ctrl = R_AX_##__type##_DBG_FUN_INTF_CTL; \
  812. u32 __reg_data = R_AX_##__type##_DBG_FUN_INTF_DATA; \
  813. u32 __data, __val32; \
  814. int __ret; \
  815. \
  816. __ctrl = FIELD_PREP(B_AX_##__type##_DFI_TRGSEL_MASK, \
  817. DLE_DFI_TYPE_##__target) | \
  818. FIELD_PREP(B_AX_##__type##_DFI_ADDR_MASK, __sel) | \
  819. B_AX_WDE_DFI_ACTIVE; \
  820. rtw89_write32(rtwdev, __reg_ctrl, __ctrl); \
  821. __ret = read_poll_timeout(rtw89_read32, __val32, \
  822. !(__val32 & B_AX_##__type##_DFI_ACTIVE), \
  823. 1000, 50000, false, \
  824. rtwdev, __reg_ctrl); \
  825. if (__ret) { \
  826. rtw89_err(rtwdev, "failed to dump DLE %s %s %d\n", \
  827. #__type, #__target, __sel); \
  828. return __ret; \
  829. } \
  830. \
  831. __data = rtw89_read32(rtwdev, __reg_data); \
  832. __data; \
  833. })
  834. #define DLE_DFI_FREE_PAGE_DUMP(__m, __type) \
  835. ({ \
  836. u32 __freepg, __pubpg; \
  837. u32 __freepg_head, __freepg_tail, __pubpg_num; \
  838. \
  839. __freepg = DLE_DFI_DUMP(__type, FREEPG, 0); \
  840. __pubpg = DLE_DFI_DUMP(__type, FREEPG, 1); \
  841. __freepg_head = FIELD_GET(B_AX_DLE_FREE_HEADPG, __freepg); \
  842. __freepg_tail = FIELD_GET(B_AX_DLE_FREE_TAILPG, __freepg); \
  843. __pubpg_num = FIELD_GET(B_AX_DLE_PUB_PGNUM, __pubpg); \
  844. seq_printf(__m, "[%s] freepg head: %d\n", \
  845. #__type, __freepg_head); \
  846. seq_printf(__m, "[%s] freepg tail: %d\n", \
  847. #__type, __freepg_tail); \
  848. seq_printf(__m, "[%s] pubpg num : %d\n", \
  849. #__type, __pubpg_num); \
  850. })
  851. #define case_QUOTA(__m, __type, __id) \
  852. case __type##_QTAID_##__id: \
  853. val32 = DLE_DFI_DUMP(__type, QUOTA, __type##_QTAID_##__id); \
  854. rsv_pgnum = FIELD_GET(B_AX_DLE_RSV_PGNUM, val32); \
  855. use_pgnum = FIELD_GET(B_AX_DLE_USE_PGNUM, val32); \
  856. seq_printf(__m, "[%s][%s] rsv_pgnum: %d\n", \
  857. #__type, #__id, rsv_pgnum); \
  858. seq_printf(__m, "[%s][%s] use_pgnum: %d\n", \
  859. #__type, #__id, use_pgnum); \
  860. break
  861. u32 quota_id;
  862. u32 val32;
  863. u16 rsv_pgnum, use_pgnum;
  864. int ret;
  865. ret = rtw89_mac_check_mac_en(rtwdev, 0, RTW89_DMAC_SEL);
  866. if (ret) {
  867. seq_puts(m, "[DLE] : DMAC not enabled\n");
  868. return ret;
  869. }
  870. DLE_DFI_FREE_PAGE_DUMP(m, WDE);
  871. DLE_DFI_FREE_PAGE_DUMP(m, PLE);
  872. for (quota_id = 0; quota_id <= WDE_QTAID_CPUIO; quota_id++) {
  873. switch (quota_id) {
  874. case_QUOTA(m, WDE, HOST_IF);
  875. case_QUOTA(m, WDE, WLAN_CPU);
  876. case_QUOTA(m, WDE, DATA_CPU);
  877. case_QUOTA(m, WDE, PKTIN);
  878. case_QUOTA(m, WDE, CPUIO);
  879. }
  880. }
  881. for (quota_id = 0; quota_id <= PLE_QTAID_CPUIO; quota_id++) {
  882. switch (quota_id) {
  883. case_QUOTA(m, PLE, B0_TXPL);
  884. case_QUOTA(m, PLE, B1_TXPL);
  885. case_QUOTA(m, PLE, C2H);
  886. case_QUOTA(m, PLE, H2C);
  887. case_QUOTA(m, PLE, WLAN_CPU);
  888. case_QUOTA(m, PLE, MPDU);
  889. case_QUOTA(m, PLE, CMAC0_RX);
  890. case_QUOTA(m, PLE, CMAC1_RX);
  891. case_QUOTA(m, PLE, CMAC1_BBRPT);
  892. case_QUOTA(m, PLE, WDRLS);
  893. case_QUOTA(m, PLE, CPUIO);
  894. }
  895. }
  896. return 0;
  897. #undef case_QUOTA
  898. #undef DLE_DFI_DUMP
  899. #undef DLE_DFI_FREE_PAGE_DUMP
  900. }
  901. static int rtw89_debug_mac_dump_dmac_dbg(struct rtw89_dev *rtwdev,
  902. struct seq_file *m)
  903. {
  904. const struct rtw89_chip_info *chip = rtwdev->chip;
  905. u32 dmac_err;
  906. int i, ret;
  907. ret = rtw89_mac_check_mac_en(rtwdev, 0, RTW89_DMAC_SEL);
  908. if (ret) {
  909. seq_puts(m, "[DMAC] : DMAC not enabled\n");
  910. return ret;
  911. }
  912. dmac_err = rtw89_read32(rtwdev, R_AX_DMAC_ERR_ISR);
  913. seq_printf(m, "R_AX_DMAC_ERR_ISR=0x%08x\n", dmac_err);
  914. seq_printf(m, "R_AX_DMAC_ERR_IMR=0x%08x\n",
  915. rtw89_read32(rtwdev, R_AX_DMAC_ERR_IMR));
  916. if (dmac_err) {
  917. seq_printf(m, "R_AX_WDE_ERR_FLAG_CFG=0x%08x\n",
  918. rtw89_read32(rtwdev, R_AX_WDE_ERR_FLAG_CFG_NUM1));
  919. seq_printf(m, "R_AX_PLE_ERR_FLAG_CFG=0x%08x\n",
  920. rtw89_read32(rtwdev, R_AX_PLE_ERR_FLAG_CFG_NUM1));
  921. if (chip->chip_id == RTL8852C) {
  922. seq_printf(m, "R_AX_PLE_ERRFLAG_MSG=0x%08x\n",
  923. rtw89_read32(rtwdev, R_AX_PLE_ERRFLAG_MSG));
  924. seq_printf(m, "R_AX_WDE_ERRFLAG_MSG=0x%08x\n",
  925. rtw89_read32(rtwdev, R_AX_WDE_ERRFLAG_MSG));
  926. seq_printf(m, "R_AX_PLE_DBGERR_LOCKEN=0x%08x\n",
  927. rtw89_read32(rtwdev, R_AX_PLE_DBGERR_LOCKEN));
  928. seq_printf(m, "R_AX_PLE_DBGERR_STS=0x%08x\n",
  929. rtw89_read32(rtwdev, R_AX_PLE_DBGERR_STS));
  930. }
  931. }
  932. if (dmac_err & B_AX_WDRLS_ERR_FLAG) {
  933. seq_printf(m, "R_AX_WDRLS_ERR_IMR=0x%08x\n",
  934. rtw89_read32(rtwdev, R_AX_WDRLS_ERR_IMR));
  935. seq_printf(m, "R_AX_WDRLS_ERR_ISR=0x%08x\n",
  936. rtw89_read32(rtwdev, R_AX_WDRLS_ERR_ISR));
  937. if (chip->chip_id == RTL8852C)
  938. seq_printf(m, "R_AX_RPQ_RXBD_IDX=0x%08x\n",
  939. rtw89_read32(rtwdev, R_AX_RPQ_RXBD_IDX_V1));
  940. else
  941. seq_printf(m, "R_AX_RPQ_RXBD_IDX=0x%08x\n",
  942. rtw89_read32(rtwdev, R_AX_RPQ_RXBD_IDX));
  943. }
  944. if (dmac_err & B_AX_WSEC_ERR_FLAG) {
  945. if (chip->chip_id == RTL8852C) {
  946. seq_printf(m, "R_AX_SEC_ERR_IMR=0x%08x\n",
  947. rtw89_read32(rtwdev, R_AX_SEC_ERROR_FLAG_IMR));
  948. seq_printf(m, "R_AX_SEC_ERR_ISR=0x%08x\n",
  949. rtw89_read32(rtwdev, R_AX_SEC_ERROR_FLAG));
  950. seq_printf(m, "R_AX_SEC_ENG_CTRL=0x%08x\n",
  951. rtw89_read32(rtwdev, R_AX_SEC_ENG_CTRL));
  952. seq_printf(m, "R_AX_SEC_MPDU_PROC=0x%08x\n",
  953. rtw89_read32(rtwdev, R_AX_SEC_MPDU_PROC));
  954. seq_printf(m, "R_AX_SEC_CAM_ACCESS=0x%08x\n",
  955. rtw89_read32(rtwdev, R_AX_SEC_CAM_ACCESS));
  956. seq_printf(m, "R_AX_SEC_CAM_RDATA=0x%08x\n",
  957. rtw89_read32(rtwdev, R_AX_SEC_CAM_RDATA));
  958. seq_printf(m, "R_AX_SEC_DEBUG1=0x%08x\n",
  959. rtw89_read32(rtwdev, R_AX_SEC_DEBUG1));
  960. seq_printf(m, "R_AX_SEC_TX_DEBUG=0x%08x\n",
  961. rtw89_read32(rtwdev, R_AX_SEC_TX_DEBUG));
  962. seq_printf(m, "R_AX_SEC_RX_DEBUG=0x%08x\n",
  963. rtw89_read32(rtwdev, R_AX_SEC_RX_DEBUG));
  964. rtw89_write32_mask(rtwdev, R_AX_DBG_CTRL,
  965. B_AX_DBG_SEL0, 0x8B);
  966. rtw89_write32_mask(rtwdev, R_AX_DBG_CTRL,
  967. B_AX_DBG_SEL1, 0x8B);
  968. rtw89_write32_mask(rtwdev, R_AX_SYS_STATUS1,
  969. B_AX_SEL_0XC0_MASK, 1);
  970. for (i = 0; i < 0x10; i++) {
  971. rtw89_write32_mask(rtwdev, R_AX_SEC_ENG_CTRL,
  972. B_AX_SEC_DBG_PORT_FIELD_MASK, i);
  973. seq_printf(m, "sel=%x,R_AX_SEC_DEBUG2=0x%08x\n",
  974. i, rtw89_read32(rtwdev, R_AX_SEC_DEBUG2));
  975. }
  976. } else {
  977. seq_printf(m, "R_AX_SEC_ERR_IMR_ISR=0x%08x\n",
  978. rtw89_read32(rtwdev, R_AX_SEC_DEBUG));
  979. seq_printf(m, "R_AX_SEC_ENG_CTRL=0x%08x\n",
  980. rtw89_read32(rtwdev, R_AX_SEC_ENG_CTRL));
  981. seq_printf(m, "R_AX_SEC_MPDU_PROC=0x%08x\n",
  982. rtw89_read32(rtwdev, R_AX_SEC_MPDU_PROC));
  983. seq_printf(m, "R_AX_SEC_CAM_ACCESS=0x%08x\n",
  984. rtw89_read32(rtwdev, R_AX_SEC_CAM_ACCESS));
  985. seq_printf(m, "R_AX_SEC_CAM_RDATA=0x%08x\n",
  986. rtw89_read32(rtwdev, R_AX_SEC_CAM_RDATA));
  987. seq_printf(m, "R_AX_SEC_CAM_WDATA=0x%08x\n",
  988. rtw89_read32(rtwdev, R_AX_SEC_CAM_WDATA));
  989. seq_printf(m, "R_AX_SEC_TX_DEBUG=0x%08x\n",
  990. rtw89_read32(rtwdev, R_AX_SEC_TX_DEBUG));
  991. seq_printf(m, "R_AX_SEC_RX_DEBUG=0x%08x\n",
  992. rtw89_read32(rtwdev, R_AX_SEC_RX_DEBUG));
  993. seq_printf(m, "R_AX_SEC_TRX_PKT_CNT=0x%08x\n",
  994. rtw89_read32(rtwdev, R_AX_SEC_TRX_PKT_CNT));
  995. seq_printf(m, "R_AX_SEC_TRX_BLK_CNT=0x%08x\n",
  996. rtw89_read32(rtwdev, R_AX_SEC_TRX_BLK_CNT));
  997. }
  998. }
  999. if (dmac_err & B_AX_MPDU_ERR_FLAG) {
  1000. seq_printf(m, "R_AX_MPDU_TX_ERR_IMR=0x%08x\n",
  1001. rtw89_read32(rtwdev, R_AX_MPDU_TX_ERR_IMR));
  1002. seq_printf(m, "R_AX_MPDU_TX_ERR_ISR=0x%08x\n",
  1003. rtw89_read32(rtwdev, R_AX_MPDU_TX_ERR_ISR));
  1004. seq_printf(m, "R_AX_MPDU_RX_ERR_IMR=0x%08x\n",
  1005. rtw89_read32(rtwdev, R_AX_MPDU_RX_ERR_IMR));
  1006. seq_printf(m, "R_AX_MPDU_RX_ERR_ISR=0x%08x\n",
  1007. rtw89_read32(rtwdev, R_AX_MPDU_RX_ERR_ISR));
  1008. }
  1009. if (dmac_err & B_AX_STA_SCHEDULER_ERR_FLAG) {
  1010. seq_printf(m, "R_AX_STA_SCHEDULER_ERR_IMR=0x%08x\n",
  1011. rtw89_read32(rtwdev, R_AX_STA_SCHEDULER_ERR_IMR));
  1012. seq_printf(m, "R_AX_STA_SCHEDULER_ERR_ISR=0x%08x\n",
  1013. rtw89_read32(rtwdev, R_AX_STA_SCHEDULER_ERR_ISR));
  1014. }
  1015. if (dmac_err & B_AX_WDE_DLE_ERR_FLAG) {
  1016. seq_printf(m, "R_AX_WDE_ERR_IMR=0x%08x\n",
  1017. rtw89_read32(rtwdev, R_AX_WDE_ERR_IMR));
  1018. seq_printf(m, "R_AX_WDE_ERR_ISR=0x%08x\n",
  1019. rtw89_read32(rtwdev, R_AX_WDE_ERR_ISR));
  1020. seq_printf(m, "R_AX_PLE_ERR_IMR=0x%08x\n",
  1021. rtw89_read32(rtwdev, R_AX_PLE_ERR_IMR));
  1022. seq_printf(m, "R_AX_PLE_ERR_FLAG_ISR=0x%08x\n",
  1023. rtw89_read32(rtwdev, R_AX_PLE_ERR_FLAG_ISR));
  1024. }
  1025. if (dmac_err & B_AX_TXPKTCTRL_ERR_FLAG) {
  1026. if (chip->chip_id == RTL8852C) {
  1027. seq_printf(m, "R_AX_TXPKTCTL_B0_ERRFLAG_IMR=0x%08x\n",
  1028. rtw89_read32(rtwdev, R_AX_TXPKTCTL_B0_ERRFLAG_IMR));
  1029. seq_printf(m, "R_AX_TXPKTCTL_B0_ERRFLAG_ISR=0x%08x\n",
  1030. rtw89_read32(rtwdev, R_AX_TXPKTCTL_B0_ERRFLAG_ISR));
  1031. seq_printf(m, "R_AX_TXPKTCTL_B1_ERRFLAG_IMR=0x%08x\n",
  1032. rtw89_read32(rtwdev, R_AX_TXPKTCTL_B1_ERRFLAG_IMR));
  1033. seq_printf(m, "R_AX_TXPKTCTL_B1_ERRFLAG_ISR=0x%08x\n",
  1034. rtw89_read32(rtwdev, R_AX_TXPKTCTL_B1_ERRFLAG_ISR));
  1035. } else {
  1036. seq_printf(m, "R_AX_TXPKTCTL_ERR_IMR_ISR=0x%08x\n",
  1037. rtw89_read32(rtwdev, R_AX_TXPKTCTL_ERR_IMR_ISR));
  1038. seq_printf(m, "R_AX_TXPKTCTL_ERR_IMR_ISR_B1=0x%08x\n",
  1039. rtw89_read32(rtwdev, R_AX_TXPKTCTL_ERR_IMR_ISR_B1));
  1040. }
  1041. }
  1042. if (dmac_err & B_AX_PLE_DLE_ERR_FLAG) {
  1043. seq_printf(m, "R_AX_WDE_ERR_IMR=0x%08x\n",
  1044. rtw89_read32(rtwdev, R_AX_WDE_ERR_IMR));
  1045. seq_printf(m, "R_AX_WDE_ERR_ISR=0x%08x\n",
  1046. rtw89_read32(rtwdev, R_AX_WDE_ERR_ISR));
  1047. seq_printf(m, "R_AX_PLE_ERR_IMR=0x%08x\n",
  1048. rtw89_read32(rtwdev, R_AX_PLE_ERR_IMR));
  1049. seq_printf(m, "R_AX_PLE_ERR_FLAG_ISR=0x%08x\n",
  1050. rtw89_read32(rtwdev, R_AX_PLE_ERR_FLAG_ISR));
  1051. seq_printf(m, "R_AX_WD_CPUQ_OP_0=0x%08x\n",
  1052. rtw89_read32(rtwdev, R_AX_WD_CPUQ_OP_0));
  1053. seq_printf(m, "R_AX_WD_CPUQ_OP_1=0x%08x\n",
  1054. rtw89_read32(rtwdev, R_AX_WD_CPUQ_OP_1));
  1055. seq_printf(m, "R_AX_WD_CPUQ_OP_2=0x%08x\n",
  1056. rtw89_read32(rtwdev, R_AX_WD_CPUQ_OP_2));
  1057. seq_printf(m, "R_AX_WD_CPUQ_OP_STATUS=0x%08x\n",
  1058. rtw89_read32(rtwdev, R_AX_WD_CPUQ_OP_STATUS));
  1059. seq_printf(m, "R_AX_PL_CPUQ_OP_0=0x%08x\n",
  1060. rtw89_read32(rtwdev, R_AX_PL_CPUQ_OP_0));
  1061. seq_printf(m, "R_AX_PL_CPUQ_OP_1=0x%08x\n",
  1062. rtw89_read32(rtwdev, R_AX_PL_CPUQ_OP_1));
  1063. seq_printf(m, "R_AX_PL_CPUQ_OP_2=0x%08x\n",
  1064. rtw89_read32(rtwdev, R_AX_PL_CPUQ_OP_2));
  1065. seq_printf(m, "R_AX_PL_CPUQ_OP_STATUS=0x%08x\n",
  1066. rtw89_read32(rtwdev, R_AX_PL_CPUQ_OP_STATUS));
  1067. if (chip->chip_id == RTL8852C) {
  1068. seq_printf(m, "R_AX_RX_CTRL0=0x%08x\n",
  1069. rtw89_read32(rtwdev, R_AX_RX_CTRL0));
  1070. seq_printf(m, "R_AX_RX_CTRL1=0x%08x\n",
  1071. rtw89_read32(rtwdev, R_AX_RX_CTRL1));
  1072. seq_printf(m, "R_AX_RX_CTRL2=0x%08x\n",
  1073. rtw89_read32(rtwdev, R_AX_RX_CTRL2));
  1074. } else {
  1075. seq_printf(m, "R_AX_RXDMA_PKT_INFO_0=0x%08x\n",
  1076. rtw89_read32(rtwdev, R_AX_RXDMA_PKT_INFO_0));
  1077. seq_printf(m, "R_AX_RXDMA_PKT_INFO_1=0x%08x\n",
  1078. rtw89_read32(rtwdev, R_AX_RXDMA_PKT_INFO_1));
  1079. seq_printf(m, "R_AX_RXDMA_PKT_INFO_2=0x%08x\n",
  1080. rtw89_read32(rtwdev, R_AX_RXDMA_PKT_INFO_2));
  1081. }
  1082. }
  1083. if (dmac_err & B_AX_PKTIN_ERR_FLAG) {
  1084. seq_printf(m, "R_AX_PKTIN_ERR_IMR=0x%08x\n",
  1085. rtw89_read32(rtwdev, R_AX_PKTIN_ERR_IMR));
  1086. seq_printf(m, "R_AX_PKTIN_ERR_ISR=0x%08x\n",
  1087. rtw89_read32(rtwdev, R_AX_PKTIN_ERR_ISR));
  1088. }
  1089. if (dmac_err & B_AX_DISPATCH_ERR_FLAG) {
  1090. seq_printf(m, "R_AX_HOST_DISPATCHER_ERR_IMR=0x%08x\n",
  1091. rtw89_read32(rtwdev, R_AX_HOST_DISPATCHER_ERR_IMR));
  1092. seq_printf(m, "R_AX_HOST_DISPATCHER_ERR_ISR=0x%08x\n",
  1093. rtw89_read32(rtwdev, R_AX_HOST_DISPATCHER_ERR_ISR));
  1094. seq_printf(m, "R_AX_CPU_DISPATCHER_ERR_IMR=0x%08x\n",
  1095. rtw89_read32(rtwdev, R_AX_CPU_DISPATCHER_ERR_IMR));
  1096. seq_printf(m, "R_AX_CPU_DISPATCHER_ERR_ISR=0x%08x\n",
  1097. rtw89_read32(rtwdev, R_AX_CPU_DISPATCHER_ERR_ISR));
  1098. seq_printf(m, "R_AX_OTHER_DISPATCHER_ERR_IMR=0x%08x\n",
  1099. rtw89_read32(rtwdev, R_AX_OTHER_DISPATCHER_ERR_IMR));
  1100. seq_printf(m, "R_AX_OTHER_DISPATCHER_ERR_ISR=0x%08x\n",
  1101. rtw89_read32(rtwdev, R_AX_OTHER_DISPATCHER_ERR_ISR));
  1102. }
  1103. if (dmac_err & B_AX_BBRPT_ERR_FLAG) {
  1104. if (chip->chip_id == RTL8852C) {
  1105. seq_printf(m, "R_AX_BBRPT_COM_ERR_IMR=0x%08x\n",
  1106. rtw89_read32(rtwdev, R_AX_BBRPT_COM_ERR_IMR));
  1107. seq_printf(m, "R_AX_BBRPT_COM_ERR_ISR=0x%08x\n",
  1108. rtw89_read32(rtwdev, R_AX_BBRPT_COM_ERR_ISR));
  1109. seq_printf(m, "R_AX_BBRPT_CHINFO_ERR_ISR=0x%08x\n",
  1110. rtw89_read32(rtwdev, R_AX_BBRPT_CHINFO_ERR_ISR));
  1111. seq_printf(m, "R_AX_BBRPT_CHINFO_ERR_IMR=0x%08x\n",
  1112. rtw89_read32(rtwdev, R_AX_BBRPT_CHINFO_ERR_IMR));
  1113. seq_printf(m, "R_AX_BBRPT_DFS_ERR_IMR=0x%08x\n",
  1114. rtw89_read32(rtwdev, R_AX_BBRPT_DFS_ERR_IMR));
  1115. seq_printf(m, "R_AX_BBRPT_DFS_ERR_ISR=0x%08x\n",
  1116. rtw89_read32(rtwdev, R_AX_BBRPT_DFS_ERR_ISR));
  1117. } else {
  1118. seq_printf(m, "R_AX_BBRPT_COM_ERR_IMR_ISR=0x%08x\n",
  1119. rtw89_read32(rtwdev, R_AX_BBRPT_COM_ERR_IMR_ISR));
  1120. seq_printf(m, "R_AX_BBRPT_CHINFO_ERR_ISR=0x%08x\n",
  1121. rtw89_read32(rtwdev, R_AX_BBRPT_CHINFO_ERR_ISR));
  1122. seq_printf(m, "R_AX_BBRPT_CHINFO_ERR_IMR=0x%08x\n",
  1123. rtw89_read32(rtwdev, R_AX_BBRPT_CHINFO_ERR_IMR));
  1124. seq_printf(m, "R_AX_BBRPT_DFS_ERR_IMR=0x%08x\n",
  1125. rtw89_read32(rtwdev, R_AX_BBRPT_DFS_ERR_IMR));
  1126. seq_printf(m, "R_AX_BBRPT_DFS_ERR_ISR=0x%08x\n",
  1127. rtw89_read32(rtwdev, R_AX_BBRPT_DFS_ERR_ISR));
  1128. }
  1129. }
  1130. if (dmac_err & B_AX_HAXIDMA_ERR_FLAG && chip->chip_id == RTL8852C) {
  1131. seq_printf(m, "R_AX_HAXIDMA_ERR_IMR=0x%08x\n",
  1132. rtw89_read32(rtwdev, R_AX_HAXI_IDCT_MSK));
  1133. seq_printf(m, "R_AX_HAXIDMA_ERR_ISR=0x%08x\n",
  1134. rtw89_read32(rtwdev, R_AX_HAXI_IDCT));
  1135. }
  1136. return 0;
  1137. }
  1138. static int rtw89_debug_mac_dump_cmac_err(struct rtw89_dev *rtwdev,
  1139. struct seq_file *m,
  1140. enum rtw89_mac_idx band)
  1141. {
  1142. const struct rtw89_chip_info *chip = rtwdev->chip;
  1143. u32 offset = 0;
  1144. u32 cmac_err;
  1145. int ret;
  1146. ret = rtw89_mac_check_mac_en(rtwdev, band, RTW89_CMAC_SEL);
  1147. if (ret) {
  1148. if (band)
  1149. seq_puts(m, "[CMAC] : CMAC1 not enabled\n");
  1150. else
  1151. seq_puts(m, "[CMAC] : CMAC0 not enabled\n");
  1152. return ret;
  1153. }
  1154. if (band)
  1155. offset = RTW89_MAC_AX_BAND_REG_OFFSET;
  1156. cmac_err = rtw89_read32(rtwdev, R_AX_CMAC_ERR_ISR + offset);
  1157. seq_printf(m, "R_AX_CMAC_ERR_ISR [%d]=0x%08x\n", band,
  1158. rtw89_read32(rtwdev, R_AX_CMAC_ERR_ISR + offset));
  1159. seq_printf(m, "R_AX_CMAC_FUNC_EN [%d]=0x%08x\n", band,
  1160. rtw89_read32(rtwdev, R_AX_CMAC_FUNC_EN + offset));
  1161. seq_printf(m, "R_AX_CK_EN [%d]=0x%08x\n", band,
  1162. rtw89_read32(rtwdev, R_AX_CK_EN + offset));
  1163. if (cmac_err & B_AX_SCHEDULE_TOP_ERR_IND) {
  1164. seq_printf(m, "R_AX_SCHEDULE_ERR_IMR [%d]=0x%08x\n", band,
  1165. rtw89_read32(rtwdev, R_AX_SCHEDULE_ERR_IMR + offset));
  1166. seq_printf(m, "R_AX_SCHEDULE_ERR_ISR [%d]=0x%08x\n", band,
  1167. rtw89_read32(rtwdev, R_AX_SCHEDULE_ERR_ISR + offset));
  1168. }
  1169. if (cmac_err & B_AX_PTCL_TOP_ERR_IND) {
  1170. seq_printf(m, "R_AX_PTCL_IMR0 [%d]=0x%08x\n", band,
  1171. rtw89_read32(rtwdev, R_AX_PTCL_IMR0 + offset));
  1172. seq_printf(m, "R_AX_PTCL_ISR0 [%d]=0x%08x\n", band,
  1173. rtw89_read32(rtwdev, R_AX_PTCL_ISR0 + offset));
  1174. }
  1175. if (cmac_err & B_AX_DMA_TOP_ERR_IND) {
  1176. if (chip->chip_id == RTL8852C) {
  1177. seq_printf(m, "R_AX_RX_ERR_FLAG [%d]=0x%08x\n", band,
  1178. rtw89_read32(rtwdev, R_AX_RX_ERR_FLAG + offset));
  1179. seq_printf(m, "R_AX_RX_ERR_FLAG_IMR [%d]=0x%08x\n", band,
  1180. rtw89_read32(rtwdev, R_AX_RX_ERR_FLAG_IMR + offset));
  1181. } else {
  1182. seq_printf(m, "R_AX_DLE_CTRL [%d]=0x%08x\n", band,
  1183. rtw89_read32(rtwdev, R_AX_DLE_CTRL + offset));
  1184. }
  1185. }
  1186. if (cmac_err & B_AX_DMA_TOP_ERR_IND || cmac_err & B_AX_WMAC_RX_ERR_IND) {
  1187. if (chip->chip_id == RTL8852C) {
  1188. seq_printf(m, "R_AX_PHYINFO_ERR_ISR [%d]=0x%08x\n", band,
  1189. rtw89_read32(rtwdev, R_AX_PHYINFO_ERR_ISR + offset));
  1190. seq_printf(m, "R_AX_PHYINFO_ERR_IMR [%d]=0x%08x\n", band,
  1191. rtw89_read32(rtwdev, R_AX_PHYINFO_ERR_IMR + offset));
  1192. } else {
  1193. seq_printf(m, "R_AX_PHYINFO_ERR_IMR [%d]=0x%08x\n", band,
  1194. rtw89_read32(rtwdev, R_AX_PHYINFO_ERR_IMR + offset));
  1195. }
  1196. }
  1197. if (cmac_err & B_AX_TXPWR_CTRL_ERR_IND) {
  1198. seq_printf(m, "R_AX_TXPWR_IMR [%d]=0x%08x\n", band,
  1199. rtw89_read32(rtwdev, R_AX_TXPWR_IMR + offset));
  1200. seq_printf(m, "R_AX_TXPWR_ISR [%d]=0x%08x\n", band,
  1201. rtw89_read32(rtwdev, R_AX_TXPWR_ISR + offset));
  1202. }
  1203. if (cmac_err & B_AX_WMAC_TX_ERR_IND) {
  1204. if (chip->chip_id == RTL8852C) {
  1205. seq_printf(m, "R_AX_TRXPTCL_ERROR_INDICA [%d]=0x%08x\n", band,
  1206. rtw89_read32(rtwdev, R_AX_TRXPTCL_ERROR_INDICA + offset));
  1207. seq_printf(m, "R_AX_TRXPTCL_ERROR_INDICA_MASK [%d]=0x%08x\n", band,
  1208. rtw89_read32(rtwdev, R_AX_TRXPTCL_ERROR_INDICA_MASK + offset));
  1209. } else {
  1210. seq_printf(m, "R_AX_TMAC_ERR_IMR_ISR [%d]=0x%08x\n", band,
  1211. rtw89_read32(rtwdev, R_AX_TMAC_ERR_IMR_ISR + offset));
  1212. }
  1213. seq_printf(m, "R_AX_DBGSEL_TRXPTCL [%d]=0x%08x\n", band,
  1214. rtw89_read32(rtwdev, R_AX_DBGSEL_TRXPTCL + offset));
  1215. }
  1216. seq_printf(m, "R_AX_CMAC_ERR_IMR [%d]=0x%08x\n", band,
  1217. rtw89_read32(rtwdev, R_AX_CMAC_ERR_IMR + offset));
  1218. return 0;
  1219. }
  1220. static int rtw89_debug_mac_dump_cmac_dbg(struct rtw89_dev *rtwdev,
  1221. struct seq_file *m)
  1222. {
  1223. rtw89_debug_mac_dump_cmac_err(rtwdev, m, RTW89_MAC_0);
  1224. if (rtwdev->dbcc_en)
  1225. rtw89_debug_mac_dump_cmac_err(rtwdev, m, RTW89_MAC_1);
  1226. return 0;
  1227. }
  1228. static const struct rtw89_mac_dbg_port_info dbg_port_ptcl_c0 = {
  1229. .sel_addr = R_AX_PTCL_DBG,
  1230. .sel_byte = 1,
  1231. .sel_msk = B_AX_PTCL_DBG_SEL_MASK,
  1232. .srt = 0x00,
  1233. .end = 0x3F,
  1234. .rd_addr = R_AX_PTCL_DBG_INFO,
  1235. .rd_byte = 4,
  1236. .rd_msk = B_AX_PTCL_DBG_INFO_MASK
  1237. };
  1238. static const struct rtw89_mac_dbg_port_info dbg_port_ptcl_c1 = {
  1239. .sel_addr = R_AX_PTCL_DBG_C1,
  1240. .sel_byte = 1,
  1241. .sel_msk = B_AX_PTCL_DBG_SEL_MASK,
  1242. .srt = 0x00,
  1243. .end = 0x3F,
  1244. .rd_addr = R_AX_PTCL_DBG_INFO_C1,
  1245. .rd_byte = 4,
  1246. .rd_msk = B_AX_PTCL_DBG_INFO_MASK
  1247. };
  1248. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_tx0_5 = {
  1249. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1250. .sel_byte = 2,
  1251. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1252. .srt = 0x0,
  1253. .end = 0xD,
  1254. .rd_addr = R_AX_DBG_PORT_SEL,
  1255. .rd_byte = 4,
  1256. .rd_msk = B_AX_DEBUG_ST_MASK
  1257. };
  1258. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_tx6 = {
  1259. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1260. .sel_byte = 2,
  1261. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1262. .srt = 0x0,
  1263. .end = 0x5,
  1264. .rd_addr = R_AX_DBG_PORT_SEL,
  1265. .rd_byte = 4,
  1266. .rd_msk = B_AX_DEBUG_ST_MASK
  1267. };
  1268. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_tx7 = {
  1269. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1270. .sel_byte = 2,
  1271. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1272. .srt = 0x0,
  1273. .end = 0x9,
  1274. .rd_addr = R_AX_DBG_PORT_SEL,
  1275. .rd_byte = 4,
  1276. .rd_msk = B_AX_DEBUG_ST_MASK
  1277. };
  1278. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_tx8 = {
  1279. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1280. .sel_byte = 2,
  1281. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1282. .srt = 0x0,
  1283. .end = 0x3,
  1284. .rd_addr = R_AX_DBG_PORT_SEL,
  1285. .rd_byte = 4,
  1286. .rd_msk = B_AX_DEBUG_ST_MASK
  1287. };
  1288. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_tx9_C = {
  1289. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1290. .sel_byte = 2,
  1291. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1292. .srt = 0x0,
  1293. .end = 0x1,
  1294. .rd_addr = R_AX_DBG_PORT_SEL,
  1295. .rd_byte = 4,
  1296. .rd_msk = B_AX_DEBUG_ST_MASK
  1297. };
  1298. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_txD = {
  1299. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1300. .sel_byte = 2,
  1301. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1302. .srt = 0x0,
  1303. .end = 0x0,
  1304. .rd_addr = R_AX_DBG_PORT_SEL,
  1305. .rd_byte = 4,
  1306. .rd_msk = B_AX_DEBUG_ST_MASK
  1307. };
  1308. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_tx0 = {
  1309. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1310. .sel_byte = 2,
  1311. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1312. .srt = 0x0,
  1313. .end = 0xB,
  1314. .rd_addr = R_AX_DBG_PORT_SEL,
  1315. .rd_byte = 4,
  1316. .rd_msk = B_AX_DEBUG_ST_MASK
  1317. };
  1318. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_tx1 = {
  1319. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1320. .sel_byte = 2,
  1321. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1322. .srt = 0x0,
  1323. .end = 0x4,
  1324. .rd_addr = R_AX_DBG_PORT_SEL,
  1325. .rd_byte = 4,
  1326. .rd_msk = B_AX_DEBUG_ST_MASK
  1327. };
  1328. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_tx3 = {
  1329. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1330. .sel_byte = 2,
  1331. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1332. .srt = 0x0,
  1333. .end = 0x8,
  1334. .rd_addr = R_AX_DBG_PORT_SEL,
  1335. .rd_byte = 4,
  1336. .rd_msk = B_AX_DEBUG_ST_MASK
  1337. };
  1338. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_tx4 = {
  1339. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1340. .sel_byte = 2,
  1341. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1342. .srt = 0x0,
  1343. .end = 0x7,
  1344. .rd_addr = R_AX_DBG_PORT_SEL,
  1345. .rd_byte = 4,
  1346. .rd_msk = B_AX_DEBUG_ST_MASK
  1347. };
  1348. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_tx5_8 = {
  1349. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1350. .sel_byte = 2,
  1351. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1352. .srt = 0x0,
  1353. .end = 0x1,
  1354. .rd_addr = R_AX_DBG_PORT_SEL,
  1355. .rd_byte = 4,
  1356. .rd_msk = B_AX_DEBUG_ST_MASK
  1357. };
  1358. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_tx9 = {
  1359. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1360. .sel_byte = 2,
  1361. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1362. .srt = 0x0,
  1363. .end = 0x3,
  1364. .rd_addr = R_AX_DBG_PORT_SEL,
  1365. .rd_byte = 4,
  1366. .rd_msk = B_AX_DEBUG_ST_MASK
  1367. };
  1368. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_txA_C = {
  1369. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1370. .sel_byte = 2,
  1371. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1372. .srt = 0x0,
  1373. .end = 0x0,
  1374. .rd_addr = R_AX_DBG_PORT_SEL,
  1375. .rd_byte = 4,
  1376. .rd_msk = B_AX_DEBUG_ST_MASK
  1377. };
  1378. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_rx0 = {
  1379. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1380. .sel_byte = 2,
  1381. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1382. .srt = 0x0,
  1383. .end = 0x8,
  1384. .rd_addr = R_AX_DBG_PORT_SEL,
  1385. .rd_byte = 4,
  1386. .rd_msk = B_AX_DEBUG_ST_MASK
  1387. };
  1388. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_rx1_2 = {
  1389. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1390. .sel_byte = 2,
  1391. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1392. .srt = 0x0,
  1393. .end = 0x0,
  1394. .rd_addr = R_AX_DBG_PORT_SEL,
  1395. .rd_byte = 4,
  1396. .rd_msk = B_AX_DEBUG_ST_MASK
  1397. };
  1398. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_rx3 = {
  1399. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1400. .sel_byte = 2,
  1401. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1402. .srt = 0x0,
  1403. .end = 0x6,
  1404. .rd_addr = R_AX_DBG_PORT_SEL,
  1405. .rd_byte = 4,
  1406. .rd_msk = B_AX_DEBUG_ST_MASK
  1407. };
  1408. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_rx4 = {
  1409. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1410. .sel_byte = 2,
  1411. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1412. .srt = 0x0,
  1413. .end = 0x0,
  1414. .rd_addr = R_AX_DBG_PORT_SEL,
  1415. .rd_byte = 4,
  1416. .rd_msk = B_AX_DEBUG_ST_MASK
  1417. };
  1418. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_hdt_rx5 = {
  1419. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1420. .sel_byte = 2,
  1421. .sel_msk = B_AX_DISPATCHER_DBG_SEL_MASK,
  1422. .srt = 0x0,
  1423. .end = 0x0,
  1424. .rd_addr = R_AX_DBG_PORT_SEL,
  1425. .rd_byte = 4,
  1426. .rd_msk = B_AX_DEBUG_ST_MASK
  1427. };
  1428. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_rx_p0_0 = {
  1429. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1430. .sel_byte = 1,
  1431. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1432. .srt = 0x0,
  1433. .end = 0x3,
  1434. .rd_addr = R_AX_DBG_PORT_SEL,
  1435. .rd_byte = 4,
  1436. .rd_msk = B_AX_DEBUG_ST_MASK
  1437. };
  1438. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_rx_p0_1 = {
  1439. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1440. .sel_byte = 1,
  1441. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1442. .srt = 0x0,
  1443. .end = 0x6,
  1444. .rd_addr = R_AX_DBG_PORT_SEL,
  1445. .rd_byte = 4,
  1446. .rd_msk = B_AX_DEBUG_ST_MASK
  1447. };
  1448. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_rx_p0_2 = {
  1449. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1450. .sel_byte = 1,
  1451. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1452. .srt = 0x0,
  1453. .end = 0x0,
  1454. .rd_addr = R_AX_DBG_PORT_SEL,
  1455. .rd_byte = 4,
  1456. .rd_msk = B_AX_DEBUG_ST_MASK
  1457. };
  1458. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_cdt_rx_p1 = {
  1459. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1460. .sel_byte = 1,
  1461. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1462. .srt = 0x8,
  1463. .end = 0xE,
  1464. .rd_addr = R_AX_DBG_PORT_SEL,
  1465. .rd_byte = 4,
  1466. .rd_msk = B_AX_DEBUG_ST_MASK
  1467. };
  1468. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_stf_ctrl = {
  1469. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1470. .sel_byte = 1,
  1471. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1472. .srt = 0x0,
  1473. .end = 0x5,
  1474. .rd_addr = R_AX_DBG_PORT_SEL,
  1475. .rd_byte = 4,
  1476. .rd_msk = B_AX_DEBUG_ST_MASK
  1477. };
  1478. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_addr_ctrl = {
  1479. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1480. .sel_byte = 1,
  1481. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1482. .srt = 0x0,
  1483. .end = 0x6,
  1484. .rd_addr = R_AX_DBG_PORT_SEL,
  1485. .rd_byte = 4,
  1486. .rd_msk = B_AX_DEBUG_ST_MASK
  1487. };
  1488. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_wde_intf = {
  1489. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1490. .sel_byte = 1,
  1491. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1492. .srt = 0x0,
  1493. .end = 0xF,
  1494. .rd_addr = R_AX_DBG_PORT_SEL,
  1495. .rd_byte = 4,
  1496. .rd_msk = B_AX_DEBUG_ST_MASK
  1497. };
  1498. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_ple_intf = {
  1499. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1500. .sel_byte = 1,
  1501. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1502. .srt = 0x0,
  1503. .end = 0x9,
  1504. .rd_addr = R_AX_DBG_PORT_SEL,
  1505. .rd_byte = 4,
  1506. .rd_msk = B_AX_DEBUG_ST_MASK
  1507. };
  1508. static const struct rtw89_mac_dbg_port_info dbg_port_dspt_flow_ctrl = {
  1509. .sel_addr = R_AX_DISPATCHER_DBG_PORT,
  1510. .sel_byte = 1,
  1511. .sel_msk = B_AX_DISPATCHER_CH_SEL_MASK,
  1512. .srt = 0x0,
  1513. .end = 0x3,
  1514. .rd_addr = R_AX_DBG_PORT_SEL,
  1515. .rd_byte = 4,
  1516. .rd_msk = B_AX_DEBUG_ST_MASK
  1517. };
  1518. static const struct rtw89_mac_dbg_port_info dbg_port_sch_c0 = {
  1519. .sel_addr = R_AX_SCH_DBG_SEL,
  1520. .sel_byte = 1,
  1521. .sel_msk = B_AX_SCH_DBG_SEL_MASK,
  1522. .srt = 0x00,
  1523. .end = 0x2F,
  1524. .rd_addr = R_AX_SCH_DBG,
  1525. .rd_byte = 4,
  1526. .rd_msk = B_AX_SCHEDULER_DBG_MASK
  1527. };
  1528. static const struct rtw89_mac_dbg_port_info dbg_port_sch_c1 = {
  1529. .sel_addr = R_AX_SCH_DBG_SEL_C1,
  1530. .sel_byte = 1,
  1531. .sel_msk = B_AX_SCH_DBG_SEL_MASK,
  1532. .srt = 0x00,
  1533. .end = 0x2F,
  1534. .rd_addr = R_AX_SCH_DBG_C1,
  1535. .rd_byte = 4,
  1536. .rd_msk = B_AX_SCHEDULER_DBG_MASK
  1537. };
  1538. static const struct rtw89_mac_dbg_port_info dbg_port_tmac_c0 = {
  1539. .sel_addr = R_AX_MACTX_DBG_SEL_CNT,
  1540. .sel_byte = 1,
  1541. .sel_msk = B_AX_DBGSEL_MACTX_MASK,
  1542. .srt = 0x00,
  1543. .end = 0x19,
  1544. .rd_addr = R_AX_DBG_PORT_SEL,
  1545. .rd_byte = 4,
  1546. .rd_msk = B_AX_DEBUG_ST_MASK
  1547. };
  1548. static const struct rtw89_mac_dbg_port_info dbg_port_tmac_c1 = {
  1549. .sel_addr = R_AX_MACTX_DBG_SEL_CNT_C1,
  1550. .sel_byte = 1,
  1551. .sel_msk = B_AX_DBGSEL_MACTX_MASK,
  1552. .srt = 0x00,
  1553. .end = 0x19,
  1554. .rd_addr = R_AX_DBG_PORT_SEL,
  1555. .rd_byte = 4,
  1556. .rd_msk = B_AX_DEBUG_ST_MASK
  1557. };
  1558. static const struct rtw89_mac_dbg_port_info dbg_port_rmac_c0 = {
  1559. .sel_addr = R_AX_RX_DEBUG_SELECT,
  1560. .sel_byte = 1,
  1561. .sel_msk = B_AX_DEBUG_SEL_MASK,
  1562. .srt = 0x00,
  1563. .end = 0x58,
  1564. .rd_addr = R_AX_DBG_PORT_SEL,
  1565. .rd_byte = 4,
  1566. .rd_msk = B_AX_DEBUG_ST_MASK
  1567. };
  1568. static const struct rtw89_mac_dbg_port_info dbg_port_rmac_c1 = {
  1569. .sel_addr = R_AX_RX_DEBUG_SELECT_C1,
  1570. .sel_byte = 1,
  1571. .sel_msk = B_AX_DEBUG_SEL_MASK,
  1572. .srt = 0x00,
  1573. .end = 0x58,
  1574. .rd_addr = R_AX_DBG_PORT_SEL,
  1575. .rd_byte = 4,
  1576. .rd_msk = B_AX_DEBUG_ST_MASK
  1577. };
  1578. static const struct rtw89_mac_dbg_port_info dbg_port_rmacst_c0 = {
  1579. .sel_addr = R_AX_RX_STATE_MONITOR,
  1580. .sel_byte = 1,
  1581. .sel_msk = B_AX_STATE_SEL_MASK,
  1582. .srt = 0x00,
  1583. .end = 0x17,
  1584. .rd_addr = R_AX_RX_STATE_MONITOR,
  1585. .rd_byte = 4,
  1586. .rd_msk = B_AX_RX_STATE_MONITOR_MASK
  1587. };
  1588. static const struct rtw89_mac_dbg_port_info dbg_port_rmacst_c1 = {
  1589. .sel_addr = R_AX_RX_STATE_MONITOR_C1,
  1590. .sel_byte = 1,
  1591. .sel_msk = B_AX_STATE_SEL_MASK,
  1592. .srt = 0x00,
  1593. .end = 0x17,
  1594. .rd_addr = R_AX_RX_STATE_MONITOR_C1,
  1595. .rd_byte = 4,
  1596. .rd_msk = B_AX_RX_STATE_MONITOR_MASK
  1597. };
  1598. static const struct rtw89_mac_dbg_port_info dbg_port_rmac_plcp_c0 = {
  1599. .sel_addr = R_AX_RMAC_PLCP_MON,
  1600. .sel_byte = 4,
  1601. .sel_msk = B_AX_PCLP_MON_SEL_MASK,
  1602. .srt = 0x0,
  1603. .end = 0xF,
  1604. .rd_addr = R_AX_RMAC_PLCP_MON,
  1605. .rd_byte = 4,
  1606. .rd_msk = B_AX_RMAC_PLCP_MON_MASK
  1607. };
  1608. static const struct rtw89_mac_dbg_port_info dbg_port_rmac_plcp_c1 = {
  1609. .sel_addr = R_AX_RMAC_PLCP_MON_C1,
  1610. .sel_byte = 4,
  1611. .sel_msk = B_AX_PCLP_MON_SEL_MASK,
  1612. .srt = 0x0,
  1613. .end = 0xF,
  1614. .rd_addr = R_AX_RMAC_PLCP_MON_C1,
  1615. .rd_byte = 4,
  1616. .rd_msk = B_AX_RMAC_PLCP_MON_MASK
  1617. };
  1618. static const struct rtw89_mac_dbg_port_info dbg_port_trxptcl_c0 = {
  1619. .sel_addr = R_AX_DBGSEL_TRXPTCL,
  1620. .sel_byte = 1,
  1621. .sel_msk = B_AX_DBGSEL_TRXPTCL_MASK,
  1622. .srt = 0x08,
  1623. .end = 0x10,
  1624. .rd_addr = R_AX_DBG_PORT_SEL,
  1625. .rd_byte = 4,
  1626. .rd_msk = B_AX_DEBUG_ST_MASK
  1627. };
  1628. static const struct rtw89_mac_dbg_port_info dbg_port_trxptcl_c1 = {
  1629. .sel_addr = R_AX_DBGSEL_TRXPTCL_C1,
  1630. .sel_byte = 1,
  1631. .sel_msk = B_AX_DBGSEL_TRXPTCL_MASK,
  1632. .srt = 0x08,
  1633. .end = 0x10,
  1634. .rd_addr = R_AX_DBG_PORT_SEL,
  1635. .rd_byte = 4,
  1636. .rd_msk = B_AX_DEBUG_ST_MASK
  1637. };
  1638. static const struct rtw89_mac_dbg_port_info dbg_port_tx_infol_c0 = {
  1639. .sel_addr = R_AX_WMAC_TX_CTRL_DEBUG,
  1640. .sel_byte = 1,
  1641. .sel_msk = B_AX_TX_CTRL_DEBUG_SEL_MASK,
  1642. .srt = 0x00,
  1643. .end = 0x07,
  1644. .rd_addr = R_AX_WMAC_TX_INFO0_DEBUG,
  1645. .rd_byte = 4,
  1646. .rd_msk = B_AX_TX_CTRL_INFO_P0_MASK
  1647. };
  1648. static const struct rtw89_mac_dbg_port_info dbg_port_tx_infoh_c0 = {
  1649. .sel_addr = R_AX_WMAC_TX_CTRL_DEBUG,
  1650. .sel_byte = 1,
  1651. .sel_msk = B_AX_TX_CTRL_DEBUG_SEL_MASK,
  1652. .srt = 0x00,
  1653. .end = 0x07,
  1654. .rd_addr = R_AX_WMAC_TX_INFO1_DEBUG,
  1655. .rd_byte = 4,
  1656. .rd_msk = B_AX_TX_CTRL_INFO_P1_MASK
  1657. };
  1658. static const struct rtw89_mac_dbg_port_info dbg_port_tx_infol_c1 = {
  1659. .sel_addr = R_AX_WMAC_TX_CTRL_DEBUG_C1,
  1660. .sel_byte = 1,
  1661. .sel_msk = B_AX_TX_CTRL_DEBUG_SEL_MASK,
  1662. .srt = 0x00,
  1663. .end = 0x07,
  1664. .rd_addr = R_AX_WMAC_TX_INFO0_DEBUG_C1,
  1665. .rd_byte = 4,
  1666. .rd_msk = B_AX_TX_CTRL_INFO_P0_MASK
  1667. };
  1668. static const struct rtw89_mac_dbg_port_info dbg_port_tx_infoh_c1 = {
  1669. .sel_addr = R_AX_WMAC_TX_CTRL_DEBUG_C1,
  1670. .sel_byte = 1,
  1671. .sel_msk = B_AX_TX_CTRL_DEBUG_SEL_MASK,
  1672. .srt = 0x00,
  1673. .end = 0x07,
  1674. .rd_addr = R_AX_WMAC_TX_INFO1_DEBUG_C1,
  1675. .rd_byte = 4,
  1676. .rd_msk = B_AX_TX_CTRL_INFO_P1_MASK
  1677. };
  1678. static const struct rtw89_mac_dbg_port_info dbg_port_txtf_infol_c0 = {
  1679. .sel_addr = R_AX_WMAC_TX_TF_INFO_0,
  1680. .sel_byte = 1,
  1681. .sel_msk = B_AX_WMAC_TX_TF_INFO_SEL_MASK,
  1682. .srt = 0x00,
  1683. .end = 0x04,
  1684. .rd_addr = R_AX_WMAC_TX_TF_INFO_1,
  1685. .rd_byte = 4,
  1686. .rd_msk = B_AX_WMAC_TX_TF_INFO_P0_MASK
  1687. };
  1688. static const struct rtw89_mac_dbg_port_info dbg_port_txtf_infoh_c0 = {
  1689. .sel_addr = R_AX_WMAC_TX_TF_INFO_0,
  1690. .sel_byte = 1,
  1691. .sel_msk = B_AX_WMAC_TX_TF_INFO_SEL_MASK,
  1692. .srt = 0x00,
  1693. .end = 0x04,
  1694. .rd_addr = R_AX_WMAC_TX_TF_INFO_2,
  1695. .rd_byte = 4,
  1696. .rd_msk = B_AX_WMAC_TX_TF_INFO_P1_MASK
  1697. };
  1698. static const struct rtw89_mac_dbg_port_info dbg_port_txtf_infol_c1 = {
  1699. .sel_addr = R_AX_WMAC_TX_TF_INFO_0_C1,
  1700. .sel_byte = 1,
  1701. .sel_msk = B_AX_WMAC_TX_TF_INFO_SEL_MASK,
  1702. .srt = 0x00,
  1703. .end = 0x04,
  1704. .rd_addr = R_AX_WMAC_TX_TF_INFO_1_C1,
  1705. .rd_byte = 4,
  1706. .rd_msk = B_AX_WMAC_TX_TF_INFO_P0_MASK
  1707. };
  1708. static const struct rtw89_mac_dbg_port_info dbg_port_txtf_infoh_c1 = {
  1709. .sel_addr = R_AX_WMAC_TX_TF_INFO_0_C1,
  1710. .sel_byte = 1,
  1711. .sel_msk = B_AX_WMAC_TX_TF_INFO_SEL_MASK,
  1712. .srt = 0x00,
  1713. .end = 0x04,
  1714. .rd_addr = R_AX_WMAC_TX_TF_INFO_2_C1,
  1715. .rd_byte = 4,
  1716. .rd_msk = B_AX_WMAC_TX_TF_INFO_P1_MASK
  1717. };
  1718. static const struct rtw89_mac_dbg_port_info dbg_port_wde_bufmgn_freepg = {
  1719. .sel_addr = R_AX_WDE_DBG_FUN_INTF_CTL,
  1720. .sel_byte = 4,
  1721. .sel_msk = B_AX_WDE_DFI_DATA_MASK,
  1722. .srt = 0x80000000,
  1723. .end = 0x80000001,
  1724. .rd_addr = R_AX_WDE_DBG_FUN_INTF_DATA,
  1725. .rd_byte = 4,
  1726. .rd_msk = B_AX_WDE_DFI_DATA_MASK
  1727. };
  1728. static const struct rtw89_mac_dbg_port_info dbg_port_wde_bufmgn_quota = {
  1729. .sel_addr = R_AX_WDE_DBG_FUN_INTF_CTL,
  1730. .sel_byte = 4,
  1731. .sel_msk = B_AX_WDE_DFI_DATA_MASK,
  1732. .srt = 0x80010000,
  1733. .end = 0x80010004,
  1734. .rd_addr = R_AX_WDE_DBG_FUN_INTF_DATA,
  1735. .rd_byte = 4,
  1736. .rd_msk = B_AX_WDE_DFI_DATA_MASK
  1737. };
  1738. static const struct rtw89_mac_dbg_port_info dbg_port_wde_bufmgn_pagellt = {
  1739. .sel_addr = R_AX_WDE_DBG_FUN_INTF_CTL,
  1740. .sel_byte = 4,
  1741. .sel_msk = B_AX_WDE_DFI_DATA_MASK,
  1742. .srt = 0x80020000,
  1743. .end = 0x80020FFF,
  1744. .rd_addr = R_AX_WDE_DBG_FUN_INTF_DATA,
  1745. .rd_byte = 4,
  1746. .rd_msk = B_AX_WDE_DFI_DATA_MASK
  1747. };
  1748. static const struct rtw89_mac_dbg_port_info dbg_port_wde_bufmgn_pktinfo = {
  1749. .sel_addr = R_AX_WDE_DBG_FUN_INTF_CTL,
  1750. .sel_byte = 4,
  1751. .sel_msk = B_AX_WDE_DFI_DATA_MASK,
  1752. .srt = 0x80030000,
  1753. .end = 0x80030FFF,
  1754. .rd_addr = R_AX_WDE_DBG_FUN_INTF_DATA,
  1755. .rd_byte = 4,
  1756. .rd_msk = B_AX_WDE_DFI_DATA_MASK
  1757. };
  1758. static const struct rtw89_mac_dbg_port_info dbg_port_wde_quemgn_prepkt = {
  1759. .sel_addr = R_AX_WDE_DBG_FUN_INTF_CTL,
  1760. .sel_byte = 4,
  1761. .sel_msk = B_AX_WDE_DFI_DATA_MASK,
  1762. .srt = 0x80040000,
  1763. .end = 0x80040FFF,
  1764. .rd_addr = R_AX_WDE_DBG_FUN_INTF_DATA,
  1765. .rd_byte = 4,
  1766. .rd_msk = B_AX_WDE_DFI_DATA_MASK
  1767. };
  1768. static const struct rtw89_mac_dbg_port_info dbg_port_wde_quemgn_nxtpkt = {
  1769. .sel_addr = R_AX_WDE_DBG_FUN_INTF_CTL,
  1770. .sel_byte = 4,
  1771. .sel_msk = B_AX_WDE_DFI_DATA_MASK,
  1772. .srt = 0x80050000,
  1773. .end = 0x80050FFF,
  1774. .rd_addr = R_AX_WDE_DBG_FUN_INTF_DATA,
  1775. .rd_byte = 4,
  1776. .rd_msk = B_AX_WDE_DFI_DATA_MASK
  1777. };
  1778. static const struct rtw89_mac_dbg_port_info dbg_port_wde_quemgn_qlnktbl = {
  1779. .sel_addr = R_AX_WDE_DBG_FUN_INTF_CTL,
  1780. .sel_byte = 4,
  1781. .sel_msk = B_AX_WDE_DFI_DATA_MASK,
  1782. .srt = 0x80060000,
  1783. .end = 0x80060453,
  1784. .rd_addr = R_AX_WDE_DBG_FUN_INTF_DATA,
  1785. .rd_byte = 4,
  1786. .rd_msk = B_AX_WDE_DFI_DATA_MASK
  1787. };
  1788. static const struct rtw89_mac_dbg_port_info dbg_port_wde_quemgn_qempty = {
  1789. .sel_addr = R_AX_WDE_DBG_FUN_INTF_CTL,
  1790. .sel_byte = 4,
  1791. .sel_msk = B_AX_WDE_DFI_DATA_MASK,
  1792. .srt = 0x80070000,
  1793. .end = 0x80070011,
  1794. .rd_addr = R_AX_WDE_DBG_FUN_INTF_DATA,
  1795. .rd_byte = 4,
  1796. .rd_msk = B_AX_WDE_DFI_DATA_MASK
  1797. };
  1798. static const struct rtw89_mac_dbg_port_info dbg_port_ple_bufmgn_freepg = {
  1799. .sel_addr = R_AX_PLE_DBG_FUN_INTF_CTL,
  1800. .sel_byte = 4,
  1801. .sel_msk = B_AX_PLE_DFI_DATA_MASK,
  1802. .srt = 0x80000000,
  1803. .end = 0x80000001,
  1804. .rd_addr = R_AX_PLE_DBG_FUN_INTF_DATA,
  1805. .rd_byte = 4,
  1806. .rd_msk = B_AX_PLE_DFI_DATA_MASK
  1807. };
  1808. static const struct rtw89_mac_dbg_port_info dbg_port_ple_bufmgn_quota = {
  1809. .sel_addr = R_AX_PLE_DBG_FUN_INTF_CTL,
  1810. .sel_byte = 4,
  1811. .sel_msk = B_AX_PLE_DFI_DATA_MASK,
  1812. .srt = 0x80010000,
  1813. .end = 0x8001000A,
  1814. .rd_addr = R_AX_PLE_DBG_FUN_INTF_DATA,
  1815. .rd_byte = 4,
  1816. .rd_msk = B_AX_PLE_DFI_DATA_MASK
  1817. };
  1818. static const struct rtw89_mac_dbg_port_info dbg_port_ple_bufmgn_pagellt = {
  1819. .sel_addr = R_AX_PLE_DBG_FUN_INTF_CTL,
  1820. .sel_byte = 4,
  1821. .sel_msk = B_AX_PLE_DFI_DATA_MASK,
  1822. .srt = 0x80020000,
  1823. .end = 0x80020DBF,
  1824. .rd_addr = R_AX_PLE_DBG_FUN_INTF_DATA,
  1825. .rd_byte = 4,
  1826. .rd_msk = B_AX_PLE_DFI_DATA_MASK
  1827. };
  1828. static const struct rtw89_mac_dbg_port_info dbg_port_ple_bufmgn_pktinfo = {
  1829. .sel_addr = R_AX_PLE_DBG_FUN_INTF_CTL,
  1830. .sel_byte = 4,
  1831. .sel_msk = B_AX_PLE_DFI_DATA_MASK,
  1832. .srt = 0x80030000,
  1833. .end = 0x80030DBF,
  1834. .rd_addr = R_AX_PLE_DBG_FUN_INTF_DATA,
  1835. .rd_byte = 4,
  1836. .rd_msk = B_AX_PLE_DFI_DATA_MASK
  1837. };
  1838. static const struct rtw89_mac_dbg_port_info dbg_port_ple_quemgn_prepkt = {
  1839. .sel_addr = R_AX_PLE_DBG_FUN_INTF_CTL,
  1840. .sel_byte = 4,
  1841. .sel_msk = B_AX_PLE_DFI_DATA_MASK,
  1842. .srt = 0x80040000,
  1843. .end = 0x80040DBF,
  1844. .rd_addr = R_AX_PLE_DBG_FUN_INTF_DATA,
  1845. .rd_byte = 4,
  1846. .rd_msk = B_AX_PLE_DFI_DATA_MASK
  1847. };
  1848. static const struct rtw89_mac_dbg_port_info dbg_port_ple_quemgn_nxtpkt = {
  1849. .sel_addr = R_AX_PLE_DBG_FUN_INTF_CTL,
  1850. .sel_byte = 4,
  1851. .sel_msk = B_AX_PLE_DFI_DATA_MASK,
  1852. .srt = 0x80050000,
  1853. .end = 0x80050DBF,
  1854. .rd_addr = R_AX_PLE_DBG_FUN_INTF_DATA,
  1855. .rd_byte = 4,
  1856. .rd_msk = B_AX_PLE_DFI_DATA_MASK
  1857. };
  1858. static const struct rtw89_mac_dbg_port_info dbg_port_ple_quemgn_qlnktbl = {
  1859. .sel_addr = R_AX_PLE_DBG_FUN_INTF_CTL,
  1860. .sel_byte = 4,
  1861. .sel_msk = B_AX_PLE_DFI_DATA_MASK,
  1862. .srt = 0x80060000,
  1863. .end = 0x80060041,
  1864. .rd_addr = R_AX_PLE_DBG_FUN_INTF_DATA,
  1865. .rd_byte = 4,
  1866. .rd_msk = B_AX_PLE_DFI_DATA_MASK
  1867. };
  1868. static const struct rtw89_mac_dbg_port_info dbg_port_ple_quemgn_qempty = {
  1869. .sel_addr = R_AX_PLE_DBG_FUN_INTF_CTL,
  1870. .sel_byte = 4,
  1871. .sel_msk = B_AX_PLE_DFI_DATA_MASK,
  1872. .srt = 0x80070000,
  1873. .end = 0x80070001,
  1874. .rd_addr = R_AX_PLE_DBG_FUN_INTF_DATA,
  1875. .rd_byte = 4,
  1876. .rd_msk = B_AX_PLE_DFI_DATA_MASK
  1877. };
  1878. static const struct rtw89_mac_dbg_port_info dbg_port_pktinfo = {
  1879. .sel_addr = R_AX_DBG_FUN_INTF_CTL,
  1880. .sel_byte = 4,
  1881. .sel_msk = B_AX_DFI_DATA_MASK,
  1882. .srt = 0x80000000,
  1883. .end = 0x8000017f,
  1884. .rd_addr = R_AX_DBG_FUN_INTF_DATA,
  1885. .rd_byte = 4,
  1886. .rd_msk = B_AX_DFI_DATA_MASK
  1887. };
  1888. static const struct rtw89_mac_dbg_port_info dbg_port_pcie_txdma = {
  1889. .sel_addr = R_AX_PCIE_DBG_CTRL,
  1890. .sel_byte = 2,
  1891. .sel_msk = B_AX_PCIE_DBG_SEL_MASK,
  1892. .srt = 0x00,
  1893. .end = 0x03,
  1894. .rd_addr = R_AX_DBG_PORT_SEL,
  1895. .rd_byte = 4,
  1896. .rd_msk = B_AX_DEBUG_ST_MASK
  1897. };
  1898. static const struct rtw89_mac_dbg_port_info dbg_port_pcie_rxdma = {
  1899. .sel_addr = R_AX_PCIE_DBG_CTRL,
  1900. .sel_byte = 2,
  1901. .sel_msk = B_AX_PCIE_DBG_SEL_MASK,
  1902. .srt = 0x00,
  1903. .end = 0x04,
  1904. .rd_addr = R_AX_DBG_PORT_SEL,
  1905. .rd_byte = 4,
  1906. .rd_msk = B_AX_DEBUG_ST_MASK
  1907. };
  1908. static const struct rtw89_mac_dbg_port_info dbg_port_pcie_cvt = {
  1909. .sel_addr = R_AX_PCIE_DBG_CTRL,
  1910. .sel_byte = 2,
  1911. .sel_msk = B_AX_PCIE_DBG_SEL_MASK,
  1912. .srt = 0x00,
  1913. .end = 0x01,
  1914. .rd_addr = R_AX_DBG_PORT_SEL,
  1915. .rd_byte = 4,
  1916. .rd_msk = B_AX_DEBUG_ST_MASK
  1917. };
  1918. static const struct rtw89_mac_dbg_port_info dbg_port_pcie_cxpl = {
  1919. .sel_addr = R_AX_PCIE_DBG_CTRL,
  1920. .sel_byte = 2,
  1921. .sel_msk = B_AX_PCIE_DBG_SEL_MASK,
  1922. .srt = 0x00,
  1923. .end = 0x05,
  1924. .rd_addr = R_AX_DBG_PORT_SEL,
  1925. .rd_byte = 4,
  1926. .rd_msk = B_AX_DEBUG_ST_MASK
  1927. };
  1928. static const struct rtw89_mac_dbg_port_info dbg_port_pcie_io = {
  1929. .sel_addr = R_AX_PCIE_DBG_CTRL,
  1930. .sel_byte = 2,
  1931. .sel_msk = B_AX_PCIE_DBG_SEL_MASK,
  1932. .srt = 0x00,
  1933. .end = 0x05,
  1934. .rd_addr = R_AX_DBG_PORT_SEL,
  1935. .rd_byte = 4,
  1936. .rd_msk = B_AX_DEBUG_ST_MASK
  1937. };
  1938. static const struct rtw89_mac_dbg_port_info dbg_port_pcie_misc = {
  1939. .sel_addr = R_AX_PCIE_DBG_CTRL,
  1940. .sel_byte = 2,
  1941. .sel_msk = B_AX_PCIE_DBG_SEL_MASK,
  1942. .srt = 0x00,
  1943. .end = 0x06,
  1944. .rd_addr = R_AX_DBG_PORT_SEL,
  1945. .rd_byte = 4,
  1946. .rd_msk = B_AX_DEBUG_ST_MASK
  1947. };
  1948. static const struct rtw89_mac_dbg_port_info dbg_port_pcie_misc2 = {
  1949. .sel_addr = R_AX_DBG_CTRL,
  1950. .sel_byte = 1,
  1951. .sel_msk = B_AX_DBG_SEL0,
  1952. .srt = 0x34,
  1953. .end = 0x3C,
  1954. .rd_addr = R_AX_DBG_PORT_SEL,
  1955. .rd_byte = 4,
  1956. .rd_msk = B_AX_DEBUG_ST_MASK
  1957. };
  1958. static const struct rtw89_mac_dbg_port_info *
  1959. rtw89_debug_mac_dbg_port_sel(struct seq_file *m,
  1960. struct rtw89_dev *rtwdev, u32 sel)
  1961. {
  1962. const struct rtw89_mac_dbg_port_info *info;
  1963. u32 index;
  1964. u32 val32;
  1965. u16 val16;
  1966. u8 val8;
  1967. switch (sel) {
  1968. case RTW89_DBG_PORT_SEL_PTCL_C0:
  1969. info = &dbg_port_ptcl_c0;
  1970. val16 = rtw89_read16(rtwdev, R_AX_PTCL_DBG);
  1971. val16 |= B_AX_PTCL_DBG_EN;
  1972. rtw89_write16(rtwdev, R_AX_PTCL_DBG, val16);
  1973. seq_puts(m, "Enable PTCL C0 dbgport.\n");
  1974. break;
  1975. case RTW89_DBG_PORT_SEL_PTCL_C1:
  1976. info = &dbg_port_ptcl_c1;
  1977. val16 = rtw89_read16(rtwdev, R_AX_PTCL_DBG_C1);
  1978. val16 |= B_AX_PTCL_DBG_EN;
  1979. rtw89_write16(rtwdev, R_AX_PTCL_DBG_C1, val16);
  1980. seq_puts(m, "Enable PTCL C1 dbgport.\n");
  1981. break;
  1982. case RTW89_DBG_PORT_SEL_SCH_C0:
  1983. info = &dbg_port_sch_c0;
  1984. val32 = rtw89_read32(rtwdev, R_AX_SCH_DBG_SEL);
  1985. val32 |= B_AX_SCH_DBG_EN;
  1986. rtw89_write32(rtwdev, R_AX_SCH_DBG_SEL, val32);
  1987. seq_puts(m, "Enable SCH C0 dbgport.\n");
  1988. break;
  1989. case RTW89_DBG_PORT_SEL_SCH_C1:
  1990. info = &dbg_port_sch_c1;
  1991. val32 = rtw89_read32(rtwdev, R_AX_SCH_DBG_SEL_C1);
  1992. val32 |= B_AX_SCH_DBG_EN;
  1993. rtw89_write32(rtwdev, R_AX_SCH_DBG_SEL_C1, val32);
  1994. seq_puts(m, "Enable SCH C1 dbgport.\n");
  1995. break;
  1996. case RTW89_DBG_PORT_SEL_TMAC_C0:
  1997. info = &dbg_port_tmac_c0;
  1998. val32 = rtw89_read32(rtwdev, R_AX_DBGSEL_TRXPTCL);
  1999. val32 = u32_replace_bits(val32, TRXPTRL_DBG_SEL_TMAC,
  2000. B_AX_DBGSEL_TRXPTCL_MASK);
  2001. rtw89_write32(rtwdev, R_AX_DBGSEL_TRXPTCL, val32);
  2002. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2003. val32 = u32_replace_bits(val32, TMAC_DBG_SEL_C0, B_AX_DBG_SEL0);
  2004. val32 = u32_replace_bits(val32, TMAC_DBG_SEL_C0, B_AX_DBG_SEL1);
  2005. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2006. val32 = rtw89_read32(rtwdev, R_AX_SYS_STATUS1);
  2007. val32 = u32_replace_bits(val32, MAC_DBG_SEL, B_AX_SEL_0XC0_MASK);
  2008. rtw89_write32(rtwdev, R_AX_SYS_STATUS1, val32);
  2009. seq_puts(m, "Enable TMAC C0 dbgport.\n");
  2010. break;
  2011. case RTW89_DBG_PORT_SEL_TMAC_C1:
  2012. info = &dbg_port_tmac_c1;
  2013. val32 = rtw89_read32(rtwdev, R_AX_DBGSEL_TRXPTCL_C1);
  2014. val32 = u32_replace_bits(val32, TRXPTRL_DBG_SEL_TMAC,
  2015. B_AX_DBGSEL_TRXPTCL_MASK);
  2016. rtw89_write32(rtwdev, R_AX_DBGSEL_TRXPTCL_C1, val32);
  2017. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2018. val32 = u32_replace_bits(val32, TMAC_DBG_SEL_C1, B_AX_DBG_SEL0);
  2019. val32 = u32_replace_bits(val32, TMAC_DBG_SEL_C1, B_AX_DBG_SEL1);
  2020. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2021. val32 = rtw89_read32(rtwdev, R_AX_SYS_STATUS1);
  2022. val32 = u32_replace_bits(val32, MAC_DBG_SEL, B_AX_SEL_0XC0_MASK);
  2023. rtw89_write32(rtwdev, R_AX_SYS_STATUS1, val32);
  2024. seq_puts(m, "Enable TMAC C1 dbgport.\n");
  2025. break;
  2026. case RTW89_DBG_PORT_SEL_RMAC_C0:
  2027. info = &dbg_port_rmac_c0;
  2028. val32 = rtw89_read32(rtwdev, R_AX_DBGSEL_TRXPTCL);
  2029. val32 = u32_replace_bits(val32, TRXPTRL_DBG_SEL_RMAC,
  2030. B_AX_DBGSEL_TRXPTCL_MASK);
  2031. rtw89_write32(rtwdev, R_AX_DBGSEL_TRXPTCL, val32);
  2032. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2033. val32 = u32_replace_bits(val32, RMAC_DBG_SEL_C0, B_AX_DBG_SEL0);
  2034. val32 = u32_replace_bits(val32, RMAC_DBG_SEL_C0, B_AX_DBG_SEL1);
  2035. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2036. val32 = rtw89_read32(rtwdev, R_AX_SYS_STATUS1);
  2037. val32 = u32_replace_bits(val32, MAC_DBG_SEL, B_AX_SEL_0XC0_MASK);
  2038. rtw89_write32(rtwdev, R_AX_SYS_STATUS1, val32);
  2039. val8 = rtw89_read8(rtwdev, R_AX_DBGSEL_TRXPTCL);
  2040. val8 = u8_replace_bits(val8, RMAC_CMAC_DBG_SEL,
  2041. B_AX_DBGSEL_TRXPTCL_MASK);
  2042. rtw89_write8(rtwdev, R_AX_DBGSEL_TRXPTCL, val8);
  2043. seq_puts(m, "Enable RMAC C0 dbgport.\n");
  2044. break;
  2045. case RTW89_DBG_PORT_SEL_RMAC_C1:
  2046. info = &dbg_port_rmac_c1;
  2047. val32 = rtw89_read32(rtwdev, R_AX_DBGSEL_TRXPTCL_C1);
  2048. val32 = u32_replace_bits(val32, TRXPTRL_DBG_SEL_RMAC,
  2049. B_AX_DBGSEL_TRXPTCL_MASK);
  2050. rtw89_write32(rtwdev, R_AX_DBGSEL_TRXPTCL_C1, val32);
  2051. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2052. val32 = u32_replace_bits(val32, RMAC_DBG_SEL_C1, B_AX_DBG_SEL0);
  2053. val32 = u32_replace_bits(val32, RMAC_DBG_SEL_C1, B_AX_DBG_SEL1);
  2054. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2055. val32 = rtw89_read32(rtwdev, R_AX_SYS_STATUS1);
  2056. val32 = u32_replace_bits(val32, MAC_DBG_SEL, B_AX_SEL_0XC0_MASK);
  2057. rtw89_write32(rtwdev, R_AX_SYS_STATUS1, val32);
  2058. val8 = rtw89_read8(rtwdev, R_AX_DBGSEL_TRXPTCL_C1);
  2059. val8 = u8_replace_bits(val8, RMAC_CMAC_DBG_SEL,
  2060. B_AX_DBGSEL_TRXPTCL_MASK);
  2061. rtw89_write8(rtwdev, R_AX_DBGSEL_TRXPTCL_C1, val8);
  2062. seq_puts(m, "Enable RMAC C1 dbgport.\n");
  2063. break;
  2064. case RTW89_DBG_PORT_SEL_RMACST_C0:
  2065. info = &dbg_port_rmacst_c0;
  2066. seq_puts(m, "Enable RMAC state C0 dbgport.\n");
  2067. break;
  2068. case RTW89_DBG_PORT_SEL_RMACST_C1:
  2069. info = &dbg_port_rmacst_c1;
  2070. seq_puts(m, "Enable RMAC state C1 dbgport.\n");
  2071. break;
  2072. case RTW89_DBG_PORT_SEL_RMAC_PLCP_C0:
  2073. info = &dbg_port_rmac_plcp_c0;
  2074. seq_puts(m, "Enable RMAC PLCP C0 dbgport.\n");
  2075. break;
  2076. case RTW89_DBG_PORT_SEL_RMAC_PLCP_C1:
  2077. info = &dbg_port_rmac_plcp_c1;
  2078. seq_puts(m, "Enable RMAC PLCP C1 dbgport.\n");
  2079. break;
  2080. case RTW89_DBG_PORT_SEL_TRXPTCL_C0:
  2081. info = &dbg_port_trxptcl_c0;
  2082. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2083. val32 = u32_replace_bits(val32, TRXPTCL_DBG_SEL_C0, B_AX_DBG_SEL0);
  2084. val32 = u32_replace_bits(val32, TRXPTCL_DBG_SEL_C0, B_AX_DBG_SEL1);
  2085. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2086. val32 = rtw89_read32(rtwdev, R_AX_SYS_STATUS1);
  2087. val32 = u32_replace_bits(val32, MAC_DBG_SEL, B_AX_SEL_0XC0_MASK);
  2088. rtw89_write32(rtwdev, R_AX_SYS_STATUS1, val32);
  2089. seq_puts(m, "Enable TRXPTCL C0 dbgport.\n");
  2090. break;
  2091. case RTW89_DBG_PORT_SEL_TRXPTCL_C1:
  2092. info = &dbg_port_trxptcl_c1;
  2093. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2094. val32 = u32_replace_bits(val32, TRXPTCL_DBG_SEL_C1, B_AX_DBG_SEL0);
  2095. val32 = u32_replace_bits(val32, TRXPTCL_DBG_SEL_C1, B_AX_DBG_SEL1);
  2096. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2097. val32 = rtw89_read32(rtwdev, R_AX_SYS_STATUS1);
  2098. val32 = u32_replace_bits(val32, MAC_DBG_SEL, B_AX_SEL_0XC0_MASK);
  2099. rtw89_write32(rtwdev, R_AX_SYS_STATUS1, val32);
  2100. seq_puts(m, "Enable TRXPTCL C1 dbgport.\n");
  2101. break;
  2102. case RTW89_DBG_PORT_SEL_TX_INFOL_C0:
  2103. info = &dbg_port_tx_infol_c0;
  2104. val32 = rtw89_read32(rtwdev, R_AX_TCR1);
  2105. val32 |= B_AX_TCR_FORCE_READ_TXDFIFO;
  2106. rtw89_write32(rtwdev, R_AX_TCR1, val32);
  2107. seq_puts(m, "Enable tx infol dump.\n");
  2108. break;
  2109. case RTW89_DBG_PORT_SEL_TX_INFOH_C0:
  2110. info = &dbg_port_tx_infoh_c0;
  2111. val32 = rtw89_read32(rtwdev, R_AX_TCR1);
  2112. val32 |= B_AX_TCR_FORCE_READ_TXDFIFO;
  2113. rtw89_write32(rtwdev, R_AX_TCR1, val32);
  2114. seq_puts(m, "Enable tx infoh dump.\n");
  2115. break;
  2116. case RTW89_DBG_PORT_SEL_TX_INFOL_C1:
  2117. info = &dbg_port_tx_infol_c1;
  2118. val32 = rtw89_read32(rtwdev, R_AX_TCR1_C1);
  2119. val32 |= B_AX_TCR_FORCE_READ_TXDFIFO;
  2120. rtw89_write32(rtwdev, R_AX_TCR1_C1, val32);
  2121. seq_puts(m, "Enable tx infol dump.\n");
  2122. break;
  2123. case RTW89_DBG_PORT_SEL_TX_INFOH_C1:
  2124. info = &dbg_port_tx_infoh_c1;
  2125. val32 = rtw89_read32(rtwdev, R_AX_TCR1_C1);
  2126. val32 |= B_AX_TCR_FORCE_READ_TXDFIFO;
  2127. rtw89_write32(rtwdev, R_AX_TCR1_C1, val32);
  2128. seq_puts(m, "Enable tx infoh dump.\n");
  2129. break;
  2130. case RTW89_DBG_PORT_SEL_TXTF_INFOL_C0:
  2131. info = &dbg_port_txtf_infol_c0;
  2132. val32 = rtw89_read32(rtwdev, R_AX_TCR1);
  2133. val32 |= B_AX_TCR_FORCE_READ_TXDFIFO;
  2134. rtw89_write32(rtwdev, R_AX_TCR1, val32);
  2135. seq_puts(m, "Enable tx tf infol dump.\n");
  2136. break;
  2137. case RTW89_DBG_PORT_SEL_TXTF_INFOH_C0:
  2138. info = &dbg_port_txtf_infoh_c0;
  2139. val32 = rtw89_read32(rtwdev, R_AX_TCR1);
  2140. val32 |= B_AX_TCR_FORCE_READ_TXDFIFO;
  2141. rtw89_write32(rtwdev, R_AX_TCR1, val32);
  2142. seq_puts(m, "Enable tx tf infoh dump.\n");
  2143. break;
  2144. case RTW89_DBG_PORT_SEL_TXTF_INFOL_C1:
  2145. info = &dbg_port_txtf_infol_c1;
  2146. val32 = rtw89_read32(rtwdev, R_AX_TCR1_C1);
  2147. val32 |= B_AX_TCR_FORCE_READ_TXDFIFO;
  2148. rtw89_write32(rtwdev, R_AX_TCR1_C1, val32);
  2149. seq_puts(m, "Enable tx tf infol dump.\n");
  2150. break;
  2151. case RTW89_DBG_PORT_SEL_TXTF_INFOH_C1:
  2152. info = &dbg_port_txtf_infoh_c1;
  2153. val32 = rtw89_read32(rtwdev, R_AX_TCR1_C1);
  2154. val32 |= B_AX_TCR_FORCE_READ_TXDFIFO;
  2155. rtw89_write32(rtwdev, R_AX_TCR1_C1, val32);
  2156. seq_puts(m, "Enable tx tf infoh dump.\n");
  2157. break;
  2158. case RTW89_DBG_PORT_SEL_WDE_BUFMGN_FREEPG:
  2159. info = &dbg_port_wde_bufmgn_freepg;
  2160. seq_puts(m, "Enable wde bufmgn freepg dump.\n");
  2161. break;
  2162. case RTW89_DBG_PORT_SEL_WDE_BUFMGN_QUOTA:
  2163. info = &dbg_port_wde_bufmgn_quota;
  2164. seq_puts(m, "Enable wde bufmgn quota dump.\n");
  2165. break;
  2166. case RTW89_DBG_PORT_SEL_WDE_BUFMGN_PAGELLT:
  2167. info = &dbg_port_wde_bufmgn_pagellt;
  2168. seq_puts(m, "Enable wde bufmgn pagellt dump.\n");
  2169. break;
  2170. case RTW89_DBG_PORT_SEL_WDE_BUFMGN_PKTINFO:
  2171. info = &dbg_port_wde_bufmgn_pktinfo;
  2172. seq_puts(m, "Enable wde bufmgn pktinfo dump.\n");
  2173. break;
  2174. case RTW89_DBG_PORT_SEL_WDE_QUEMGN_PREPKT:
  2175. info = &dbg_port_wde_quemgn_prepkt;
  2176. seq_puts(m, "Enable wde quemgn prepkt dump.\n");
  2177. break;
  2178. case RTW89_DBG_PORT_SEL_WDE_QUEMGN_NXTPKT:
  2179. info = &dbg_port_wde_quemgn_nxtpkt;
  2180. seq_puts(m, "Enable wde quemgn nxtpkt dump.\n");
  2181. break;
  2182. case RTW89_DBG_PORT_SEL_WDE_QUEMGN_QLNKTBL:
  2183. info = &dbg_port_wde_quemgn_qlnktbl;
  2184. seq_puts(m, "Enable wde quemgn qlnktbl dump.\n");
  2185. break;
  2186. case RTW89_DBG_PORT_SEL_WDE_QUEMGN_QEMPTY:
  2187. info = &dbg_port_wde_quemgn_qempty;
  2188. seq_puts(m, "Enable wde quemgn qempty dump.\n");
  2189. break;
  2190. case RTW89_DBG_PORT_SEL_PLE_BUFMGN_FREEPG:
  2191. info = &dbg_port_ple_bufmgn_freepg;
  2192. seq_puts(m, "Enable ple bufmgn freepg dump.\n");
  2193. break;
  2194. case RTW89_DBG_PORT_SEL_PLE_BUFMGN_QUOTA:
  2195. info = &dbg_port_ple_bufmgn_quota;
  2196. seq_puts(m, "Enable ple bufmgn quota dump.\n");
  2197. break;
  2198. case RTW89_DBG_PORT_SEL_PLE_BUFMGN_PAGELLT:
  2199. info = &dbg_port_ple_bufmgn_pagellt;
  2200. seq_puts(m, "Enable ple bufmgn pagellt dump.\n");
  2201. break;
  2202. case RTW89_DBG_PORT_SEL_PLE_BUFMGN_PKTINFO:
  2203. info = &dbg_port_ple_bufmgn_pktinfo;
  2204. seq_puts(m, "Enable ple bufmgn pktinfo dump.\n");
  2205. break;
  2206. case RTW89_DBG_PORT_SEL_PLE_QUEMGN_PREPKT:
  2207. info = &dbg_port_ple_quemgn_prepkt;
  2208. seq_puts(m, "Enable ple quemgn prepkt dump.\n");
  2209. break;
  2210. case RTW89_DBG_PORT_SEL_PLE_QUEMGN_NXTPKT:
  2211. info = &dbg_port_ple_quemgn_nxtpkt;
  2212. seq_puts(m, "Enable ple quemgn nxtpkt dump.\n");
  2213. break;
  2214. case RTW89_DBG_PORT_SEL_PLE_QUEMGN_QLNKTBL:
  2215. info = &dbg_port_ple_quemgn_qlnktbl;
  2216. seq_puts(m, "Enable ple quemgn qlnktbl dump.\n");
  2217. break;
  2218. case RTW89_DBG_PORT_SEL_PLE_QUEMGN_QEMPTY:
  2219. info = &dbg_port_ple_quemgn_qempty;
  2220. seq_puts(m, "Enable ple quemgn qempty dump.\n");
  2221. break;
  2222. case RTW89_DBG_PORT_SEL_PKTINFO:
  2223. info = &dbg_port_pktinfo;
  2224. seq_puts(m, "Enable pktinfo dump.\n");
  2225. break;
  2226. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX0:
  2227. rtw89_write32_mask(rtwdev, R_AX_DBG_CTRL,
  2228. B_AX_DBG_SEL0, 0x80);
  2229. rtw89_write32_mask(rtwdev, R_AX_SYS_STATUS1,
  2230. B_AX_SEL_0XC0_MASK, 1);
  2231. fallthrough;
  2232. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX1:
  2233. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX2:
  2234. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX3:
  2235. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX4:
  2236. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX5:
  2237. info = &dbg_port_dspt_hdt_tx0_5;
  2238. index = sel - RTW89_DBG_PORT_SEL_DSPT_HDT_TX0;
  2239. rtw89_write16_mask(rtwdev, info->sel_addr,
  2240. B_AX_DISPATCHER_INTN_SEL_MASK, 0);
  2241. rtw89_write16_mask(rtwdev, info->sel_addr,
  2242. B_AX_DISPATCHER_CH_SEL_MASK, index);
  2243. seq_printf(m, "Enable Dispatcher hdt tx%x dump.\n", index);
  2244. break;
  2245. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX6:
  2246. info = &dbg_port_dspt_hdt_tx6;
  2247. rtw89_write16_mask(rtwdev, info->sel_addr,
  2248. B_AX_DISPATCHER_INTN_SEL_MASK, 0);
  2249. rtw89_write16_mask(rtwdev, info->sel_addr,
  2250. B_AX_DISPATCHER_CH_SEL_MASK, 6);
  2251. seq_puts(m, "Enable Dispatcher hdt tx6 dump.\n");
  2252. break;
  2253. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX7:
  2254. info = &dbg_port_dspt_hdt_tx7;
  2255. rtw89_write16_mask(rtwdev, info->sel_addr,
  2256. B_AX_DISPATCHER_INTN_SEL_MASK, 0);
  2257. rtw89_write16_mask(rtwdev, info->sel_addr,
  2258. B_AX_DISPATCHER_CH_SEL_MASK, 7);
  2259. seq_puts(m, "Enable Dispatcher hdt tx7 dump.\n");
  2260. break;
  2261. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX8:
  2262. info = &dbg_port_dspt_hdt_tx8;
  2263. rtw89_write16_mask(rtwdev, info->sel_addr,
  2264. B_AX_DISPATCHER_INTN_SEL_MASK, 0);
  2265. rtw89_write16_mask(rtwdev, info->sel_addr,
  2266. B_AX_DISPATCHER_CH_SEL_MASK, 8);
  2267. seq_puts(m, "Enable Dispatcher hdt tx8 dump.\n");
  2268. break;
  2269. case RTW89_DBG_PORT_SEL_DSPT_HDT_TX9:
  2270. case RTW89_DBG_PORT_SEL_DSPT_HDT_TXA:
  2271. case RTW89_DBG_PORT_SEL_DSPT_HDT_TXB:
  2272. case RTW89_DBG_PORT_SEL_DSPT_HDT_TXC:
  2273. info = &dbg_port_dspt_hdt_tx9_C;
  2274. index = sel + 9 - RTW89_DBG_PORT_SEL_DSPT_HDT_TX9;
  2275. rtw89_write16_mask(rtwdev, info->sel_addr,
  2276. B_AX_DISPATCHER_INTN_SEL_MASK, 0);
  2277. rtw89_write16_mask(rtwdev, info->sel_addr,
  2278. B_AX_DISPATCHER_CH_SEL_MASK, index);
  2279. seq_printf(m, "Enable Dispatcher hdt tx%x dump.\n", index);
  2280. break;
  2281. case RTW89_DBG_PORT_SEL_DSPT_HDT_TXD:
  2282. info = &dbg_port_dspt_hdt_txD;
  2283. rtw89_write16_mask(rtwdev, info->sel_addr,
  2284. B_AX_DISPATCHER_INTN_SEL_MASK, 0);
  2285. rtw89_write16_mask(rtwdev, info->sel_addr,
  2286. B_AX_DISPATCHER_CH_SEL_MASK, 0xD);
  2287. seq_puts(m, "Enable Dispatcher hdt txD dump.\n");
  2288. break;
  2289. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX0:
  2290. info = &dbg_port_dspt_cdt_tx0;
  2291. rtw89_write16_mask(rtwdev, info->sel_addr,
  2292. B_AX_DISPATCHER_INTN_SEL_MASK, 1);
  2293. rtw89_write16_mask(rtwdev, info->sel_addr,
  2294. B_AX_DISPATCHER_CH_SEL_MASK, 0);
  2295. seq_puts(m, "Enable Dispatcher cdt tx0 dump.\n");
  2296. break;
  2297. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX1:
  2298. info = &dbg_port_dspt_cdt_tx1;
  2299. rtw89_write16_mask(rtwdev, info->sel_addr,
  2300. B_AX_DISPATCHER_INTN_SEL_MASK, 1);
  2301. rtw89_write16_mask(rtwdev, info->sel_addr,
  2302. B_AX_DISPATCHER_CH_SEL_MASK, 1);
  2303. seq_puts(m, "Enable Dispatcher cdt tx1 dump.\n");
  2304. break;
  2305. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX3:
  2306. info = &dbg_port_dspt_cdt_tx3;
  2307. rtw89_write16_mask(rtwdev, info->sel_addr,
  2308. B_AX_DISPATCHER_INTN_SEL_MASK, 1);
  2309. rtw89_write16_mask(rtwdev, info->sel_addr,
  2310. B_AX_DISPATCHER_CH_SEL_MASK, 3);
  2311. seq_puts(m, "Enable Dispatcher cdt tx3 dump.\n");
  2312. break;
  2313. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX4:
  2314. info = &dbg_port_dspt_cdt_tx4;
  2315. rtw89_write16_mask(rtwdev, info->sel_addr,
  2316. B_AX_DISPATCHER_INTN_SEL_MASK, 1);
  2317. rtw89_write16_mask(rtwdev, info->sel_addr,
  2318. B_AX_DISPATCHER_CH_SEL_MASK, 4);
  2319. seq_puts(m, "Enable Dispatcher cdt tx4 dump.\n");
  2320. break;
  2321. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX5:
  2322. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX6:
  2323. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX7:
  2324. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX8:
  2325. info = &dbg_port_dspt_cdt_tx5_8;
  2326. index = sel + 5 - RTW89_DBG_PORT_SEL_DSPT_CDT_TX5;
  2327. rtw89_write16_mask(rtwdev, info->sel_addr,
  2328. B_AX_DISPATCHER_INTN_SEL_MASK, 1);
  2329. rtw89_write16_mask(rtwdev, info->sel_addr,
  2330. B_AX_DISPATCHER_CH_SEL_MASK, index);
  2331. seq_printf(m, "Enable Dispatcher cdt tx%x dump.\n", index);
  2332. break;
  2333. case RTW89_DBG_PORT_SEL_DSPT_CDT_TX9:
  2334. info = &dbg_port_dspt_cdt_tx9;
  2335. rtw89_write16_mask(rtwdev, info->sel_addr,
  2336. B_AX_DISPATCHER_INTN_SEL_MASK, 1);
  2337. rtw89_write16_mask(rtwdev, info->sel_addr,
  2338. B_AX_DISPATCHER_CH_SEL_MASK, 9);
  2339. seq_puts(m, "Enable Dispatcher cdt tx9 dump.\n");
  2340. break;
  2341. case RTW89_DBG_PORT_SEL_DSPT_CDT_TXA:
  2342. case RTW89_DBG_PORT_SEL_DSPT_CDT_TXB:
  2343. case RTW89_DBG_PORT_SEL_DSPT_CDT_TXC:
  2344. info = &dbg_port_dspt_cdt_txA_C;
  2345. index = sel + 0xA - RTW89_DBG_PORT_SEL_DSPT_CDT_TXA;
  2346. rtw89_write16_mask(rtwdev, info->sel_addr,
  2347. B_AX_DISPATCHER_INTN_SEL_MASK, 1);
  2348. rtw89_write16_mask(rtwdev, info->sel_addr,
  2349. B_AX_DISPATCHER_CH_SEL_MASK, index);
  2350. seq_printf(m, "Enable Dispatcher cdt tx%x dump.\n", index);
  2351. break;
  2352. case RTW89_DBG_PORT_SEL_DSPT_HDT_RX0:
  2353. info = &dbg_port_dspt_hdt_rx0;
  2354. rtw89_write16_mask(rtwdev, info->sel_addr,
  2355. B_AX_DISPATCHER_INTN_SEL_MASK, 2);
  2356. rtw89_write16_mask(rtwdev, info->sel_addr,
  2357. B_AX_DISPATCHER_CH_SEL_MASK, 0);
  2358. seq_puts(m, "Enable Dispatcher hdt rx0 dump.\n");
  2359. break;
  2360. case RTW89_DBG_PORT_SEL_DSPT_HDT_RX1:
  2361. case RTW89_DBG_PORT_SEL_DSPT_HDT_RX2:
  2362. info = &dbg_port_dspt_hdt_rx1_2;
  2363. index = sel + 1 - RTW89_DBG_PORT_SEL_DSPT_HDT_RX1;
  2364. rtw89_write16_mask(rtwdev, info->sel_addr,
  2365. B_AX_DISPATCHER_INTN_SEL_MASK, 2);
  2366. rtw89_write16_mask(rtwdev, info->sel_addr,
  2367. B_AX_DISPATCHER_CH_SEL_MASK, index);
  2368. seq_printf(m, "Enable Dispatcher hdt rx%x dump.\n", index);
  2369. break;
  2370. case RTW89_DBG_PORT_SEL_DSPT_HDT_RX3:
  2371. info = &dbg_port_dspt_hdt_rx3;
  2372. rtw89_write16_mask(rtwdev, info->sel_addr,
  2373. B_AX_DISPATCHER_INTN_SEL_MASK, 2);
  2374. rtw89_write16_mask(rtwdev, info->sel_addr,
  2375. B_AX_DISPATCHER_CH_SEL_MASK, 3);
  2376. seq_puts(m, "Enable Dispatcher hdt rx3 dump.\n");
  2377. break;
  2378. case RTW89_DBG_PORT_SEL_DSPT_HDT_RX4:
  2379. info = &dbg_port_dspt_hdt_rx4;
  2380. rtw89_write16_mask(rtwdev, info->sel_addr,
  2381. B_AX_DISPATCHER_INTN_SEL_MASK, 2);
  2382. rtw89_write16_mask(rtwdev, info->sel_addr,
  2383. B_AX_DISPATCHER_CH_SEL_MASK, 4);
  2384. seq_puts(m, "Enable Dispatcher hdt rx4 dump.\n");
  2385. break;
  2386. case RTW89_DBG_PORT_SEL_DSPT_HDT_RX5:
  2387. info = &dbg_port_dspt_hdt_rx5;
  2388. rtw89_write16_mask(rtwdev, info->sel_addr,
  2389. B_AX_DISPATCHER_INTN_SEL_MASK, 2);
  2390. rtw89_write16_mask(rtwdev, info->sel_addr,
  2391. B_AX_DISPATCHER_CH_SEL_MASK, 5);
  2392. seq_puts(m, "Enable Dispatcher hdt rx5 dump.\n");
  2393. break;
  2394. case RTW89_DBG_PORT_SEL_DSPT_CDT_RX_P0_0:
  2395. info = &dbg_port_dspt_cdt_rx_p0_0;
  2396. rtw89_write16_mask(rtwdev, info->sel_addr,
  2397. B_AX_DISPATCHER_INTN_SEL_MASK, 3);
  2398. rtw89_write16_mask(rtwdev, info->sel_addr,
  2399. B_AX_DISPATCHER_CH_SEL_MASK, 0);
  2400. seq_puts(m, "Enable Dispatcher cdt rx part0 0 dump.\n");
  2401. break;
  2402. case RTW89_DBG_PORT_SEL_DSPT_CDT_RX_P0:
  2403. case RTW89_DBG_PORT_SEL_DSPT_CDT_RX_P0_1:
  2404. info = &dbg_port_dspt_cdt_rx_p0_1;
  2405. rtw89_write16_mask(rtwdev, info->sel_addr,
  2406. B_AX_DISPATCHER_INTN_SEL_MASK, 3);
  2407. rtw89_write16_mask(rtwdev, info->sel_addr,
  2408. B_AX_DISPATCHER_CH_SEL_MASK, 1);
  2409. seq_puts(m, "Enable Dispatcher cdt rx part0 1 dump.\n");
  2410. break;
  2411. case RTW89_DBG_PORT_SEL_DSPT_CDT_RX_P0_2:
  2412. info = &dbg_port_dspt_cdt_rx_p0_2;
  2413. rtw89_write16_mask(rtwdev, info->sel_addr,
  2414. B_AX_DISPATCHER_INTN_SEL_MASK, 3);
  2415. rtw89_write16_mask(rtwdev, info->sel_addr,
  2416. B_AX_DISPATCHER_CH_SEL_MASK, 2);
  2417. seq_puts(m, "Enable Dispatcher cdt rx part0 2 dump.\n");
  2418. break;
  2419. case RTW89_DBG_PORT_SEL_DSPT_CDT_RX_P1:
  2420. info = &dbg_port_dspt_cdt_rx_p1;
  2421. rtw89_write8_mask(rtwdev, info->sel_addr,
  2422. B_AX_DISPATCHER_INTN_SEL_MASK, 3);
  2423. seq_puts(m, "Enable Dispatcher cdt rx part1 dump.\n");
  2424. break;
  2425. case RTW89_DBG_PORT_SEL_DSPT_STF_CTRL:
  2426. info = &dbg_port_dspt_stf_ctrl;
  2427. rtw89_write8_mask(rtwdev, info->sel_addr,
  2428. B_AX_DISPATCHER_INTN_SEL_MASK, 4);
  2429. seq_puts(m, "Enable Dispatcher stf control dump.\n");
  2430. break;
  2431. case RTW89_DBG_PORT_SEL_DSPT_ADDR_CTRL:
  2432. info = &dbg_port_dspt_addr_ctrl;
  2433. rtw89_write8_mask(rtwdev, info->sel_addr,
  2434. B_AX_DISPATCHER_INTN_SEL_MASK, 5);
  2435. seq_puts(m, "Enable Dispatcher addr control dump.\n");
  2436. break;
  2437. case RTW89_DBG_PORT_SEL_DSPT_WDE_INTF:
  2438. info = &dbg_port_dspt_wde_intf;
  2439. rtw89_write8_mask(rtwdev, info->sel_addr,
  2440. B_AX_DISPATCHER_INTN_SEL_MASK, 6);
  2441. seq_puts(m, "Enable Dispatcher wde interface dump.\n");
  2442. break;
  2443. case RTW89_DBG_PORT_SEL_DSPT_PLE_INTF:
  2444. info = &dbg_port_dspt_ple_intf;
  2445. rtw89_write8_mask(rtwdev, info->sel_addr,
  2446. B_AX_DISPATCHER_INTN_SEL_MASK, 7);
  2447. seq_puts(m, "Enable Dispatcher ple interface dump.\n");
  2448. break;
  2449. case RTW89_DBG_PORT_SEL_DSPT_FLOW_CTRL:
  2450. info = &dbg_port_dspt_flow_ctrl;
  2451. rtw89_write8_mask(rtwdev, info->sel_addr,
  2452. B_AX_DISPATCHER_INTN_SEL_MASK, 8);
  2453. seq_puts(m, "Enable Dispatcher flow control dump.\n");
  2454. break;
  2455. case RTW89_DBG_PORT_SEL_PCIE_TXDMA:
  2456. info = &dbg_port_pcie_txdma;
  2457. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2458. val32 = u32_replace_bits(val32, PCIE_TXDMA_DBG_SEL, B_AX_DBG_SEL0);
  2459. val32 = u32_replace_bits(val32, PCIE_TXDMA_DBG_SEL, B_AX_DBG_SEL1);
  2460. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2461. seq_puts(m, "Enable pcie txdma dump.\n");
  2462. break;
  2463. case RTW89_DBG_PORT_SEL_PCIE_RXDMA:
  2464. info = &dbg_port_pcie_rxdma;
  2465. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2466. val32 = u32_replace_bits(val32, PCIE_RXDMA_DBG_SEL, B_AX_DBG_SEL0);
  2467. val32 = u32_replace_bits(val32, PCIE_RXDMA_DBG_SEL, B_AX_DBG_SEL1);
  2468. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2469. seq_puts(m, "Enable pcie rxdma dump.\n");
  2470. break;
  2471. case RTW89_DBG_PORT_SEL_PCIE_CVT:
  2472. info = &dbg_port_pcie_cvt;
  2473. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2474. val32 = u32_replace_bits(val32, PCIE_CVT_DBG_SEL, B_AX_DBG_SEL0);
  2475. val32 = u32_replace_bits(val32, PCIE_CVT_DBG_SEL, B_AX_DBG_SEL1);
  2476. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2477. seq_puts(m, "Enable pcie cvt dump.\n");
  2478. break;
  2479. case RTW89_DBG_PORT_SEL_PCIE_CXPL:
  2480. info = &dbg_port_pcie_cxpl;
  2481. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2482. val32 = u32_replace_bits(val32, PCIE_CXPL_DBG_SEL, B_AX_DBG_SEL0);
  2483. val32 = u32_replace_bits(val32, PCIE_CXPL_DBG_SEL, B_AX_DBG_SEL1);
  2484. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2485. seq_puts(m, "Enable pcie cxpl dump.\n");
  2486. break;
  2487. case RTW89_DBG_PORT_SEL_PCIE_IO:
  2488. info = &dbg_port_pcie_io;
  2489. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2490. val32 = u32_replace_bits(val32, PCIE_IO_DBG_SEL, B_AX_DBG_SEL0);
  2491. val32 = u32_replace_bits(val32, PCIE_IO_DBG_SEL, B_AX_DBG_SEL1);
  2492. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2493. seq_puts(m, "Enable pcie io dump.\n");
  2494. break;
  2495. case RTW89_DBG_PORT_SEL_PCIE_MISC:
  2496. info = &dbg_port_pcie_misc;
  2497. val32 = rtw89_read32(rtwdev, R_AX_DBG_CTRL);
  2498. val32 = u32_replace_bits(val32, PCIE_MISC_DBG_SEL, B_AX_DBG_SEL0);
  2499. val32 = u32_replace_bits(val32, PCIE_MISC_DBG_SEL, B_AX_DBG_SEL1);
  2500. rtw89_write32(rtwdev, R_AX_DBG_CTRL, val32);
  2501. seq_puts(m, "Enable pcie misc dump.\n");
  2502. break;
  2503. case RTW89_DBG_PORT_SEL_PCIE_MISC2:
  2504. info = &dbg_port_pcie_misc2;
  2505. val16 = rtw89_read16(rtwdev, R_AX_PCIE_DBG_CTRL);
  2506. val16 = u16_replace_bits(val16, PCIE_MISC2_DBG_SEL,
  2507. B_AX_PCIE_DBG_SEL_MASK);
  2508. rtw89_write16(rtwdev, R_AX_PCIE_DBG_CTRL, val16);
  2509. seq_puts(m, "Enable pcie misc2 dump.\n");
  2510. break;
  2511. default:
  2512. seq_puts(m, "Dbg port select err\n");
  2513. return NULL;
  2514. }
  2515. return info;
  2516. }
  2517. static bool is_dbg_port_valid(struct rtw89_dev *rtwdev, u32 sel)
  2518. {
  2519. if (rtwdev->hci.type != RTW89_HCI_TYPE_PCIE &&
  2520. sel >= RTW89_DBG_PORT_SEL_PCIE_TXDMA &&
  2521. sel <= RTW89_DBG_PORT_SEL_PCIE_MISC2)
  2522. return false;
  2523. if (rtwdev->chip->chip_id == RTL8852B &&
  2524. sel >= RTW89_DBG_PORT_SEL_PTCL_C1 &&
  2525. sel <= RTW89_DBG_PORT_SEL_TXTF_INFOH_C1)
  2526. return false;
  2527. if (rtw89_mac_check_mac_en(rtwdev, 0, RTW89_DMAC_SEL) &&
  2528. sel >= RTW89_DBG_PORT_SEL_WDE_BUFMGN_FREEPG &&
  2529. sel <= RTW89_DBG_PORT_SEL_PKTINFO)
  2530. return false;
  2531. if (rtw89_mac_check_mac_en(rtwdev, 0, RTW89_DMAC_SEL) &&
  2532. sel >= RTW89_DBG_PORT_SEL_DSPT_HDT_TX0 &&
  2533. sel <= RTW89_DBG_PORT_SEL_DSPT_FLOW_CTRL)
  2534. return false;
  2535. if (rtw89_mac_check_mac_en(rtwdev, 0, RTW89_CMAC_SEL) &&
  2536. sel >= RTW89_DBG_PORT_SEL_PTCL_C0 &&
  2537. sel <= RTW89_DBG_PORT_SEL_TXTF_INFOH_C0)
  2538. return false;
  2539. if (rtw89_mac_check_mac_en(rtwdev, 1, RTW89_CMAC_SEL) &&
  2540. sel >= RTW89_DBG_PORT_SEL_PTCL_C1 &&
  2541. sel <= RTW89_DBG_PORT_SEL_TXTF_INFOH_C1)
  2542. return false;
  2543. return true;
  2544. }
  2545. static int rtw89_debug_mac_dbg_port_dump(struct rtw89_dev *rtwdev,
  2546. struct seq_file *m, u32 sel)
  2547. {
  2548. const struct rtw89_mac_dbg_port_info *info;
  2549. u8 val8;
  2550. u16 val16;
  2551. u32 val32;
  2552. u32 i;
  2553. info = rtw89_debug_mac_dbg_port_sel(m, rtwdev, sel);
  2554. if (!info) {
  2555. rtw89_err(rtwdev, "failed to select debug port %d\n", sel);
  2556. return -EINVAL;
  2557. }
  2558. #define case_DBG_SEL(__sel) \
  2559. case RTW89_DBG_PORT_SEL_##__sel: \
  2560. seq_puts(m, "Dump debug port " #__sel ":\n"); \
  2561. break
  2562. switch (sel) {
  2563. case_DBG_SEL(PTCL_C0);
  2564. case_DBG_SEL(PTCL_C1);
  2565. case_DBG_SEL(SCH_C0);
  2566. case_DBG_SEL(SCH_C1);
  2567. case_DBG_SEL(TMAC_C0);
  2568. case_DBG_SEL(TMAC_C1);
  2569. case_DBG_SEL(RMAC_C0);
  2570. case_DBG_SEL(RMAC_C1);
  2571. case_DBG_SEL(RMACST_C0);
  2572. case_DBG_SEL(RMACST_C1);
  2573. case_DBG_SEL(TRXPTCL_C0);
  2574. case_DBG_SEL(TRXPTCL_C1);
  2575. case_DBG_SEL(TX_INFOL_C0);
  2576. case_DBG_SEL(TX_INFOH_C0);
  2577. case_DBG_SEL(TX_INFOL_C1);
  2578. case_DBG_SEL(TX_INFOH_C1);
  2579. case_DBG_SEL(TXTF_INFOL_C0);
  2580. case_DBG_SEL(TXTF_INFOH_C0);
  2581. case_DBG_SEL(TXTF_INFOL_C1);
  2582. case_DBG_SEL(TXTF_INFOH_C1);
  2583. case_DBG_SEL(WDE_BUFMGN_FREEPG);
  2584. case_DBG_SEL(WDE_BUFMGN_QUOTA);
  2585. case_DBG_SEL(WDE_BUFMGN_PAGELLT);
  2586. case_DBG_SEL(WDE_BUFMGN_PKTINFO);
  2587. case_DBG_SEL(WDE_QUEMGN_PREPKT);
  2588. case_DBG_SEL(WDE_QUEMGN_NXTPKT);
  2589. case_DBG_SEL(WDE_QUEMGN_QLNKTBL);
  2590. case_DBG_SEL(WDE_QUEMGN_QEMPTY);
  2591. case_DBG_SEL(PLE_BUFMGN_FREEPG);
  2592. case_DBG_SEL(PLE_BUFMGN_QUOTA);
  2593. case_DBG_SEL(PLE_BUFMGN_PAGELLT);
  2594. case_DBG_SEL(PLE_BUFMGN_PKTINFO);
  2595. case_DBG_SEL(PLE_QUEMGN_PREPKT);
  2596. case_DBG_SEL(PLE_QUEMGN_NXTPKT);
  2597. case_DBG_SEL(PLE_QUEMGN_QLNKTBL);
  2598. case_DBG_SEL(PLE_QUEMGN_QEMPTY);
  2599. case_DBG_SEL(PKTINFO);
  2600. case_DBG_SEL(DSPT_HDT_TX0);
  2601. case_DBG_SEL(DSPT_HDT_TX1);
  2602. case_DBG_SEL(DSPT_HDT_TX2);
  2603. case_DBG_SEL(DSPT_HDT_TX3);
  2604. case_DBG_SEL(DSPT_HDT_TX4);
  2605. case_DBG_SEL(DSPT_HDT_TX5);
  2606. case_DBG_SEL(DSPT_HDT_TX6);
  2607. case_DBG_SEL(DSPT_HDT_TX7);
  2608. case_DBG_SEL(DSPT_HDT_TX8);
  2609. case_DBG_SEL(DSPT_HDT_TX9);
  2610. case_DBG_SEL(DSPT_HDT_TXA);
  2611. case_DBG_SEL(DSPT_HDT_TXB);
  2612. case_DBG_SEL(DSPT_HDT_TXC);
  2613. case_DBG_SEL(DSPT_HDT_TXD);
  2614. case_DBG_SEL(DSPT_HDT_TXE);
  2615. case_DBG_SEL(DSPT_HDT_TXF);
  2616. case_DBG_SEL(DSPT_CDT_TX0);
  2617. case_DBG_SEL(DSPT_CDT_TX1);
  2618. case_DBG_SEL(DSPT_CDT_TX3);
  2619. case_DBG_SEL(DSPT_CDT_TX4);
  2620. case_DBG_SEL(DSPT_CDT_TX5);
  2621. case_DBG_SEL(DSPT_CDT_TX6);
  2622. case_DBG_SEL(DSPT_CDT_TX7);
  2623. case_DBG_SEL(DSPT_CDT_TX8);
  2624. case_DBG_SEL(DSPT_CDT_TX9);
  2625. case_DBG_SEL(DSPT_CDT_TXA);
  2626. case_DBG_SEL(DSPT_CDT_TXB);
  2627. case_DBG_SEL(DSPT_CDT_TXC);
  2628. case_DBG_SEL(DSPT_HDT_RX0);
  2629. case_DBG_SEL(DSPT_HDT_RX1);
  2630. case_DBG_SEL(DSPT_HDT_RX2);
  2631. case_DBG_SEL(DSPT_HDT_RX3);
  2632. case_DBG_SEL(DSPT_HDT_RX4);
  2633. case_DBG_SEL(DSPT_HDT_RX5);
  2634. case_DBG_SEL(DSPT_CDT_RX_P0);
  2635. case_DBG_SEL(DSPT_CDT_RX_P0_0);
  2636. case_DBG_SEL(DSPT_CDT_RX_P0_1);
  2637. case_DBG_SEL(DSPT_CDT_RX_P0_2);
  2638. case_DBG_SEL(DSPT_CDT_RX_P1);
  2639. case_DBG_SEL(DSPT_STF_CTRL);
  2640. case_DBG_SEL(DSPT_ADDR_CTRL);
  2641. case_DBG_SEL(DSPT_WDE_INTF);
  2642. case_DBG_SEL(DSPT_PLE_INTF);
  2643. case_DBG_SEL(DSPT_FLOW_CTRL);
  2644. case_DBG_SEL(PCIE_TXDMA);
  2645. case_DBG_SEL(PCIE_RXDMA);
  2646. case_DBG_SEL(PCIE_CVT);
  2647. case_DBG_SEL(PCIE_CXPL);
  2648. case_DBG_SEL(PCIE_IO);
  2649. case_DBG_SEL(PCIE_MISC);
  2650. case_DBG_SEL(PCIE_MISC2);
  2651. }
  2652. #undef case_DBG_SEL
  2653. seq_printf(m, "Sel addr = 0x%X\n", info->sel_addr);
  2654. seq_printf(m, "Read addr = 0x%X\n", info->rd_addr);
  2655. for (i = info->srt; i <= info->end; i++) {
  2656. switch (info->sel_byte) {
  2657. case 1:
  2658. default:
  2659. rtw89_write8_mask(rtwdev, info->sel_addr,
  2660. info->sel_msk, i);
  2661. seq_printf(m, "0x%02X: ", i);
  2662. break;
  2663. case 2:
  2664. rtw89_write16_mask(rtwdev, info->sel_addr,
  2665. info->sel_msk, i);
  2666. seq_printf(m, "0x%04X: ", i);
  2667. break;
  2668. case 4:
  2669. rtw89_write32_mask(rtwdev, info->sel_addr,
  2670. info->sel_msk, i);
  2671. seq_printf(m, "0x%04X: ", i);
  2672. break;
  2673. }
  2674. udelay(10);
  2675. switch (info->rd_byte) {
  2676. case 1:
  2677. default:
  2678. val8 = rtw89_read8_mask(rtwdev,
  2679. info->rd_addr, info->rd_msk);
  2680. seq_printf(m, "0x%02X\n", val8);
  2681. break;
  2682. case 2:
  2683. val16 = rtw89_read16_mask(rtwdev,
  2684. info->rd_addr, info->rd_msk);
  2685. seq_printf(m, "0x%04X\n", val16);
  2686. break;
  2687. case 4:
  2688. val32 = rtw89_read32_mask(rtwdev,
  2689. info->rd_addr, info->rd_msk);
  2690. seq_printf(m, "0x%08X\n", val32);
  2691. break;
  2692. }
  2693. }
  2694. return 0;
  2695. }
  2696. static int rtw89_debug_mac_dump_dbg_port(struct rtw89_dev *rtwdev,
  2697. struct seq_file *m)
  2698. {
  2699. u32 sel;
  2700. int ret = 0;
  2701. for (sel = RTW89_DBG_PORT_SEL_PTCL_C0;
  2702. sel < RTW89_DBG_PORT_SEL_LAST; sel++) {
  2703. if (!is_dbg_port_valid(rtwdev, sel))
  2704. continue;
  2705. ret = rtw89_debug_mac_dbg_port_dump(rtwdev, m, sel);
  2706. if (ret) {
  2707. rtw89_err(rtwdev,
  2708. "failed to dump debug port %d\n", sel);
  2709. break;
  2710. }
  2711. }
  2712. return ret;
  2713. }
  2714. static int
  2715. rtw89_debug_priv_mac_dbg_port_dump_get(struct seq_file *m, void *v)
  2716. {
  2717. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  2718. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2719. if (debugfs_priv->dbgpkg_en.ss_dbg)
  2720. rtw89_debug_mac_dump_ss_dbg(rtwdev, m);
  2721. if (debugfs_priv->dbgpkg_en.dle_dbg)
  2722. rtw89_debug_mac_dump_dle_dbg(rtwdev, m);
  2723. if (debugfs_priv->dbgpkg_en.dmac_dbg)
  2724. rtw89_debug_mac_dump_dmac_dbg(rtwdev, m);
  2725. if (debugfs_priv->dbgpkg_en.cmac_dbg)
  2726. rtw89_debug_mac_dump_cmac_dbg(rtwdev, m);
  2727. if (debugfs_priv->dbgpkg_en.dbg_port)
  2728. rtw89_debug_mac_dump_dbg_port(rtwdev, m);
  2729. return 0;
  2730. };
  2731. static u8 *rtw89_hex2bin_user(struct rtw89_dev *rtwdev,
  2732. const char __user *user_buf, size_t count)
  2733. {
  2734. char *buf;
  2735. u8 *bin;
  2736. int num;
  2737. int err = 0;
  2738. buf = memdup_user(user_buf, count);
  2739. if (IS_ERR(buf))
  2740. return buf;
  2741. num = count / 2;
  2742. bin = kmalloc(num, GFP_KERNEL);
  2743. if (!bin) {
  2744. err = -EFAULT;
  2745. goto out;
  2746. }
  2747. if (hex2bin(bin, buf, num)) {
  2748. rtw89_info(rtwdev, "valid format: H1H2H3...\n");
  2749. kfree(bin);
  2750. err = -EINVAL;
  2751. }
  2752. out:
  2753. kfree(buf);
  2754. return err ? ERR_PTR(err) : bin;
  2755. }
  2756. static ssize_t rtw89_debug_priv_send_h2c_set(struct file *filp,
  2757. const char __user *user_buf,
  2758. size_t count, loff_t *loff)
  2759. {
  2760. struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
  2761. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2762. u8 *h2c;
  2763. int ret;
  2764. u16 h2c_len = count / 2;
  2765. h2c = rtw89_hex2bin_user(rtwdev, user_buf, count);
  2766. if (IS_ERR(h2c))
  2767. return -EFAULT;
  2768. ret = rtw89_fw_h2c_raw(rtwdev, h2c, h2c_len);
  2769. kfree(h2c);
  2770. return ret ? ret : count;
  2771. }
  2772. static int
  2773. rtw89_debug_priv_early_h2c_get(struct seq_file *m, void *v)
  2774. {
  2775. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  2776. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2777. struct rtw89_early_h2c *early_h2c;
  2778. int seq = 0;
  2779. mutex_lock(&rtwdev->mutex);
  2780. list_for_each_entry(early_h2c, &rtwdev->early_h2c_list, list)
  2781. seq_printf(m, "%d: %*ph\n", ++seq, early_h2c->h2c_len, early_h2c->h2c);
  2782. mutex_unlock(&rtwdev->mutex);
  2783. return 0;
  2784. }
  2785. static ssize_t
  2786. rtw89_debug_priv_early_h2c_set(struct file *filp, const char __user *user_buf,
  2787. size_t count, loff_t *loff)
  2788. {
  2789. struct seq_file *m = (struct seq_file *)filp->private_data;
  2790. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  2791. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2792. struct rtw89_early_h2c *early_h2c;
  2793. u8 *h2c;
  2794. u16 h2c_len = count / 2;
  2795. h2c = rtw89_hex2bin_user(rtwdev, user_buf, count);
  2796. if (IS_ERR(h2c))
  2797. return -EFAULT;
  2798. if (h2c_len >= 2 && h2c[0] == 0x00 && h2c[1] == 0x00) {
  2799. kfree(h2c);
  2800. rtw89_fw_free_all_early_h2c(rtwdev);
  2801. goto out;
  2802. }
  2803. early_h2c = kmalloc(sizeof(*early_h2c), GFP_KERNEL);
  2804. if (!early_h2c) {
  2805. kfree(h2c);
  2806. return -EFAULT;
  2807. }
  2808. early_h2c->h2c = h2c;
  2809. early_h2c->h2c_len = h2c_len;
  2810. mutex_lock(&rtwdev->mutex);
  2811. list_add_tail(&early_h2c->list, &rtwdev->early_h2c_list);
  2812. mutex_unlock(&rtwdev->mutex);
  2813. out:
  2814. return count;
  2815. }
  2816. static int rtw89_dbg_trigger_ctrl_error(struct rtw89_dev *rtwdev)
  2817. {
  2818. struct rtw89_cpuio_ctrl ctrl_para = {0};
  2819. u16 pkt_id;
  2820. int ret;
  2821. rtw89_leave_ps_mode(rtwdev);
  2822. ret = rtw89_mac_dle_buf_req(rtwdev, 0x20, true, &pkt_id);
  2823. if (ret)
  2824. return ret;
  2825. /* intentionally, enqueue two pkt, but has only one pkt id */
  2826. ctrl_para.cmd_type = CPUIO_OP_CMD_ENQ_TO_HEAD;
  2827. ctrl_para.start_pktid = pkt_id;
  2828. ctrl_para.end_pktid = pkt_id;
  2829. ctrl_para.pkt_num = 1; /* start from 0 */
  2830. ctrl_para.dst_pid = WDE_DLE_PORT_ID_WDRLS;
  2831. ctrl_para.dst_qid = WDE_DLE_QUEID_NO_REPORT;
  2832. if (rtw89_mac_set_cpuio(rtwdev, &ctrl_para, true))
  2833. return -EFAULT;
  2834. return 0;
  2835. }
  2836. static int
  2837. rtw89_debug_priv_fw_crash_get(struct seq_file *m, void *v)
  2838. {
  2839. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  2840. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2841. seq_printf(m, "%d\n",
  2842. test_bit(RTW89_FLAG_CRASH_SIMULATING, rtwdev->flags));
  2843. return 0;
  2844. }
  2845. enum rtw89_dbg_crash_simulation_type {
  2846. RTW89_DBG_SIM_CPU_EXCEPTION = 1,
  2847. RTW89_DBG_SIM_CTRL_ERROR = 2,
  2848. };
  2849. static ssize_t
  2850. rtw89_debug_priv_fw_crash_set(struct file *filp, const char __user *user_buf,
  2851. size_t count, loff_t *loff)
  2852. {
  2853. struct seq_file *m = (struct seq_file *)filp->private_data;
  2854. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  2855. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2856. int (*sim)(struct rtw89_dev *rtwdev);
  2857. u8 crash_type;
  2858. int ret;
  2859. ret = kstrtou8_from_user(user_buf, count, 0, &crash_type);
  2860. if (ret)
  2861. return -EINVAL;
  2862. switch (crash_type) {
  2863. case RTW89_DBG_SIM_CPU_EXCEPTION:
  2864. if (!RTW89_CHK_FW_FEATURE(CRASH_TRIGGER, &rtwdev->fw))
  2865. return -EOPNOTSUPP;
  2866. sim = rtw89_fw_h2c_trigger_cpu_exception;
  2867. break;
  2868. case RTW89_DBG_SIM_CTRL_ERROR:
  2869. sim = rtw89_dbg_trigger_ctrl_error;
  2870. break;
  2871. default:
  2872. return -EINVAL;
  2873. }
  2874. mutex_lock(&rtwdev->mutex);
  2875. set_bit(RTW89_FLAG_CRASH_SIMULATING, rtwdev->flags);
  2876. ret = sim(rtwdev);
  2877. mutex_unlock(&rtwdev->mutex);
  2878. if (ret)
  2879. return ret;
  2880. return count;
  2881. }
  2882. static int rtw89_debug_priv_btc_info_get(struct seq_file *m, void *v)
  2883. {
  2884. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  2885. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2886. rtw89_btc_dump_info(rtwdev, m);
  2887. return 0;
  2888. }
  2889. static ssize_t rtw89_debug_priv_btc_manual_set(struct file *filp,
  2890. const char __user *user_buf,
  2891. size_t count, loff_t *loff)
  2892. {
  2893. struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
  2894. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2895. struct rtw89_btc *btc = &rtwdev->btc;
  2896. bool btc_manual;
  2897. int ret;
  2898. ret = kstrtobool_from_user(user_buf, count, &btc_manual);
  2899. if (ret)
  2900. return ret;
  2901. btc->ctrl.manual = btc_manual;
  2902. return count;
  2903. }
  2904. static ssize_t rtw89_debug_fw_log_manual_set(struct file *filp,
  2905. const char __user *user_buf,
  2906. size_t count, loff_t *loff)
  2907. {
  2908. struct rtw89_debugfs_priv *debugfs_priv = filp->private_data;
  2909. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  2910. struct rtw89_fw_log *log = &rtwdev->fw.log;
  2911. bool fw_log_manual;
  2912. if (kstrtobool_from_user(user_buf, count, &fw_log_manual))
  2913. goto out;
  2914. mutex_lock(&rtwdev->mutex);
  2915. log->enable = fw_log_manual;
  2916. if (log->enable)
  2917. rtw89_fw_log_prepare(rtwdev);
  2918. rtw89_fw_h2c_fw_log(rtwdev, fw_log_manual);
  2919. mutex_unlock(&rtwdev->mutex);
  2920. out:
  2921. return count;
  2922. }
  2923. static void rtw89_sta_info_get_iter(void *data, struct ieee80211_sta *sta)
  2924. {
  2925. static const char * const he_gi_str[] = {
  2926. [NL80211_RATE_INFO_HE_GI_0_8] = "0.8",
  2927. [NL80211_RATE_INFO_HE_GI_1_6] = "1.6",
  2928. [NL80211_RATE_INFO_HE_GI_3_2] = "3.2",
  2929. };
  2930. struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
  2931. struct rate_info *rate = &rtwsta->ra_report.txrate;
  2932. struct ieee80211_rx_status *status = &rtwsta->rx_status;
  2933. struct seq_file *m = (struct seq_file *)data;
  2934. struct rtw89_dev *rtwdev = rtwsta->rtwdev;
  2935. struct rtw89_hal *hal = &rtwdev->hal;
  2936. u8 ant_num = hal->ant_diversity ? 2 : rtwdev->chip->rf_path_num;
  2937. bool ant_asterisk = hal->tx_path_diversity || hal->ant_diversity;
  2938. u8 evm_min, evm_max;
  2939. u8 rssi;
  2940. u8 snr;
  2941. int i;
  2942. seq_printf(m, "TX rate [%d]: ", rtwsta->mac_id);
  2943. if (rate->flags & RATE_INFO_FLAGS_MCS)
  2944. seq_printf(m, "HT MCS-%d%s", rate->mcs,
  2945. rate->flags & RATE_INFO_FLAGS_SHORT_GI ? " SGI" : "");
  2946. else if (rate->flags & RATE_INFO_FLAGS_VHT_MCS)
  2947. seq_printf(m, "VHT %dSS MCS-%d%s", rate->nss, rate->mcs,
  2948. rate->flags & RATE_INFO_FLAGS_SHORT_GI ? " SGI" : "");
  2949. else if (rate->flags & RATE_INFO_FLAGS_HE_MCS)
  2950. seq_printf(m, "HE %dSS MCS-%d GI:%s", rate->nss, rate->mcs,
  2951. rate->he_gi <= NL80211_RATE_INFO_HE_GI_3_2 ?
  2952. he_gi_str[rate->he_gi] : "N/A");
  2953. else
  2954. seq_printf(m, "Legacy %d", rate->legacy);
  2955. seq_printf(m, "%s", rtwsta->ra_report.might_fallback_legacy ? " FB_G" : "");
  2956. seq_printf(m, " BW:%u", rtw89_rate_info_bw_to_mhz(rate->bw));
  2957. seq_printf(m, "\t(hw_rate=0x%x)", rtwsta->ra_report.hw_rate);
  2958. seq_printf(m, "\t==> agg_wait=%d (%d)\n", rtwsta->max_agg_wait,
  2959. #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
  2960. sta->deflink.agg.max_rc_amsdu_len);
  2961. #else
  2962. sta->max_rc_amsdu_len);
  2963. #endif
  2964. seq_printf(m, "RX rate [%d]: ", rtwsta->mac_id);
  2965. switch (status->encoding) {
  2966. case RX_ENC_LEGACY:
  2967. seq_printf(m, "Legacy %d", status->rate_idx +
  2968. (status->band != NL80211_BAND_2GHZ ? 4 : 0));
  2969. break;
  2970. case RX_ENC_HT:
  2971. seq_printf(m, "HT MCS-%d%s", status->rate_idx,
  2972. status->enc_flags & RX_ENC_FLAG_SHORT_GI ? " SGI" : "");
  2973. break;
  2974. case RX_ENC_VHT:
  2975. seq_printf(m, "VHT %dSS MCS-%d%s", status->nss, status->rate_idx,
  2976. status->enc_flags & RX_ENC_FLAG_SHORT_GI ? " SGI" : "");
  2977. break;
  2978. case RX_ENC_HE:
  2979. seq_printf(m, "HE %dSS MCS-%d GI:%s", status->nss, status->rate_idx,
  2980. status->he_gi <= NL80211_RATE_INFO_HE_GI_3_2 ?
  2981. he_gi_str[rate->he_gi] : "N/A");
  2982. break;
  2983. }
  2984. seq_printf(m, " BW:%u", rtw89_rate_info_bw_to_mhz(status->bw));
  2985. seq_printf(m, "\t(hw_rate=0x%x)\n", rtwsta->rx_hw_rate);
  2986. rssi = ewma_rssi_read(&rtwsta->avg_rssi);
  2987. seq_printf(m, "RSSI: %d dBm (raw=%d, prev=%d) [",
  2988. RTW89_RSSI_RAW_TO_DBM(rssi), rssi, rtwsta->prev_rssi);
  2989. for (i = 0; i < ant_num; i++) {
  2990. rssi = ewma_rssi_read(&rtwsta->rssi[i]);
  2991. seq_printf(m, "%d%s%s", RTW89_RSSI_RAW_TO_DBM(rssi),
  2992. ant_asterisk && (hal->antenna_tx & BIT(i)) ? "*" : "",
  2993. i + 1 == ant_num ? "" : ", ");
  2994. }
  2995. seq_puts(m, "]\n");
  2996. seq_puts(m, "EVM: [");
  2997. for (i = 0; i < (hal->ant_diversity ? 2 : 1); i++) {
  2998. evm_min = ewma_evm_read(&rtwsta->evm_min[i]);
  2999. evm_max = ewma_evm_read(&rtwsta->evm_max[i]);
  3000. seq_printf(m, "%s(%2u.%02u, %2u.%02u)", i == 0 ? "" : " ",
  3001. evm_min >> 2, (evm_min & 0x3) * 25,
  3002. evm_max >> 2, (evm_max & 0x3) * 25);
  3003. }
  3004. seq_puts(m, "]\t");
  3005. snr = ewma_snr_read(&rtwsta->avg_snr);
  3006. seq_printf(m, "SNR: %u\n", snr);
  3007. }
  3008. static void
  3009. rtw89_debug_append_rx_rate(struct seq_file *m, struct rtw89_pkt_stat *pkt_stat,
  3010. enum rtw89_hw_rate first_rate, int len)
  3011. {
  3012. int i;
  3013. for (i = 0; i < len; i++)
  3014. seq_printf(m, "%s%u", i == 0 ? "" : ", ",
  3015. pkt_stat->rx_rate_cnt[first_rate + i]);
  3016. }
  3017. #define FIRST_RATE_SAME(rate) {RTW89_HW_RATE_ ## rate, RTW89_HW_RATE_ ## rate}
  3018. #define FIRST_RATE_ENUM(rate) {RTW89_HW_RATE_ ## rate, RTW89_HW_RATE_V1_ ## rate}
  3019. #define FIRST_RATE_GEV1(rate) {RTW89_HW_RATE_INVAL, RTW89_HW_RATE_V1_ ## rate}
  3020. static const struct rtw89_rx_rate_cnt_info {
  3021. enum rtw89_hw_rate first_rate[RTW89_CHIP_GEN_NUM];
  3022. int len;
  3023. int ext;
  3024. const char *rate_mode;
  3025. } rtw89_rx_rate_cnt_infos[] = {
  3026. {FIRST_RATE_SAME(CCK1), 4, 0, "Legacy:"},
  3027. {FIRST_RATE_SAME(OFDM6), 8, 0, "OFDM:"},
  3028. {FIRST_RATE_ENUM(MCS0), 8, 0, "HT 0:"},
  3029. {FIRST_RATE_ENUM(MCS8), 8, 0, "HT 1:"},
  3030. {FIRST_RATE_ENUM(VHT_NSS1_MCS0), 10, 2, "VHT 1SS:"},
  3031. {FIRST_RATE_ENUM(VHT_NSS2_MCS0), 10, 2, "VHT 2SS:"},
  3032. {FIRST_RATE_ENUM(HE_NSS1_MCS0), 12, 0, "HE 1SS:"},
  3033. {FIRST_RATE_ENUM(HE_NSS2_MCS0), 12, 0, "HE 2SS:"},
  3034. {FIRST_RATE_GEV1(EHT_NSS1_MCS0), 14, 2, "EHT 1SS:"},
  3035. {FIRST_RATE_GEV1(EHT_NSS2_MCS0), 14, 0, "EHT 2SS:"},
  3036. };
  3037. static int rtw89_debug_priv_phy_info_get(struct seq_file *m, void *v)
  3038. {
  3039. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  3040. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  3041. struct rtw89_traffic_stats *stats = &rtwdev->stats;
  3042. struct rtw89_pkt_stat *pkt_stat = &rtwdev->phystat.last_pkt_stat;
  3043. const struct rtw89_chip_info *chip = rtwdev->chip;
  3044. const struct rtw89_rx_rate_cnt_info *info;
  3045. enum rtw89_hw_rate first_rate;
  3046. int i;
  3047. seq_printf(m, "TP TX: %u [%u] Mbps (lv: %d), RX: %u [%u] Mbps (lv: %d)\n",
  3048. stats->tx_throughput, stats->tx_throughput_raw, stats->tx_tfc_lv,
  3049. stats->rx_throughput, stats->rx_throughput_raw, stats->rx_tfc_lv);
  3050. seq_printf(m, "Beacon: %u, TF: %u\n", pkt_stat->beacon_nr,
  3051. stats->rx_tf_periodic);
  3052. seq_printf(m, "Avg packet length: TX=%u, RX=%u\n", stats->tx_avg_len,
  3053. stats->rx_avg_len);
  3054. seq_puts(m, "RX count:\n");
  3055. for (i = 0; i < ARRAY_SIZE(rtw89_rx_rate_cnt_infos); i++) {
  3056. info = &rtw89_rx_rate_cnt_infos[i];
  3057. first_rate = info->first_rate[chip->chip_gen];
  3058. if (first_rate >= RTW89_HW_RATE_NR)
  3059. continue;
  3060. seq_printf(m, "%10s [", info->rate_mode);
  3061. rtw89_debug_append_rx_rate(m, pkt_stat,
  3062. first_rate, info->len);
  3063. if (info->ext) {
  3064. seq_puts(m, "][");
  3065. rtw89_debug_append_rx_rate(m, pkt_stat,
  3066. first_rate + info->len, info->ext);
  3067. }
  3068. seq_puts(m, "]\n");
  3069. }
  3070. ieee80211_iterate_stations_atomic(rtwdev->hw, rtw89_sta_info_get_iter, m);
  3071. return 0;
  3072. }
  3073. static void rtw89_dump_addr_cam(struct seq_file *m,
  3074. struct rtw89_addr_cam_entry *addr_cam)
  3075. {
  3076. struct rtw89_sec_cam_entry *sec_entry;
  3077. int i;
  3078. seq_printf(m, "\taddr_cam_idx=%u\n", addr_cam->addr_cam_idx);
  3079. seq_printf(m, "\t-> bssid_cam_idx=%u\n", addr_cam->bssid_cam_idx);
  3080. seq_printf(m, "\tsec_cam_bitmap=%*ph\n", (int)sizeof(addr_cam->sec_cam_map),
  3081. addr_cam->sec_cam_map);
  3082. for (i = 0; i < RTW89_SEC_CAM_IN_ADDR_CAM; i++) {
  3083. sec_entry = addr_cam->sec_entries[i];
  3084. if (!sec_entry)
  3085. continue;
  3086. seq_printf(m, "\tsec[%d]: sec_cam_idx %u", i, sec_entry->sec_cam_idx);
  3087. if (sec_entry->ext_key)
  3088. seq_printf(m, ", %u", sec_entry->sec_cam_idx + 1);
  3089. seq_puts(m, "\n");
  3090. }
  3091. }
  3092. __printf(3, 4)
  3093. static void rtw89_dump_pkt_offload(struct seq_file *m, struct list_head *pkt_list,
  3094. const char *fmt, ...)
  3095. {
  3096. struct rtw89_pktofld_info *info;
  3097. struct va_format vaf;
  3098. va_list args;
  3099. if (list_empty(pkt_list))
  3100. return;
  3101. va_start(args, fmt);
  3102. vaf.va = &args;
  3103. vaf.fmt = fmt;
  3104. seq_printf(m, "%pV", &vaf);
  3105. va_end(args);
  3106. list_for_each_entry(info, pkt_list, list)
  3107. seq_printf(m, "%d ", info->id);
  3108. seq_puts(m, "\n");
  3109. }
  3110. static
  3111. void rtw89_vif_ids_get_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  3112. {
  3113. struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv;
  3114. struct seq_file *m = (struct seq_file *)data;
  3115. struct rtw89_bssid_cam_entry *bssid_cam = &rtwvif->bssid_cam;
  3116. seq_printf(m, "VIF [%d] %pM\n", rtwvif->mac_id, rtwvif->mac_addr);
  3117. seq_printf(m, "\tbssid_cam_idx=%u\n", bssid_cam->bssid_cam_idx);
  3118. rtw89_dump_addr_cam(m, &rtwvif->addr_cam);
  3119. rtw89_dump_pkt_offload(m, &rtwvif->general_pkt_list, "\tpkt_ofld[GENERAL]: ");
  3120. }
  3121. static void rtw89_dump_ba_cam(struct seq_file *m, struct rtw89_sta *rtwsta)
  3122. {
  3123. struct rtw89_vif *rtwvif = rtwsta->rtwvif;
  3124. struct rtw89_dev *rtwdev = rtwvif->rtwdev;
  3125. struct rtw89_ba_cam_entry *entry;
  3126. bool first = true;
  3127. list_for_each_entry(entry, &rtwsta->ba_cam_list, list) {
  3128. if (first) {
  3129. seq_puts(m, "\tba_cam ");
  3130. first = false;
  3131. } else {
  3132. seq_puts(m, ", ");
  3133. }
  3134. seq_printf(m, "tid[%u]=%d", entry->tid,
  3135. (int)(entry - rtwdev->cam_info.ba_cam_entry));
  3136. }
  3137. seq_puts(m, "\n");
  3138. }
  3139. static void rtw89_sta_ids_get_iter(void *data, struct ieee80211_sta *sta)
  3140. {
  3141. struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
  3142. struct seq_file *m = (struct seq_file *)data;
  3143. seq_printf(m, "STA [%d] %pM %s\n", rtwsta->mac_id, sta->addr,
  3144. sta->tdls ? "(TDLS)" : "");
  3145. rtw89_dump_addr_cam(m, &rtwsta->addr_cam);
  3146. rtw89_dump_ba_cam(m, rtwsta);
  3147. }
  3148. static int rtw89_debug_priv_stations_get(struct seq_file *m, void *v)
  3149. {
  3150. struct rtw89_debugfs_priv *debugfs_priv = m->private;
  3151. struct rtw89_dev *rtwdev = debugfs_priv->rtwdev;
  3152. struct rtw89_cam_info *cam_info = &rtwdev->cam_info;
  3153. u8 idx;
  3154. mutex_lock(&rtwdev->mutex);
  3155. seq_puts(m, "map:\n");
  3156. seq_printf(m, "\tmac_id: %*ph\n", (int)sizeof(rtwdev->mac_id_map),
  3157. rtwdev->mac_id_map);
  3158. seq_printf(m, "\taddr_cam: %*ph\n", (int)sizeof(cam_info->addr_cam_map),
  3159. cam_info->addr_cam_map);
  3160. seq_printf(m, "\tbssid_cam: %*ph\n", (int)sizeof(cam_info->bssid_cam_map),
  3161. cam_info->bssid_cam_map);
  3162. seq_printf(m, "\tsec_cam: %*ph\n", (int)sizeof(cam_info->sec_cam_map),
  3163. cam_info->sec_cam_map);
  3164. seq_printf(m, "\tba_cam: %*ph\n", (int)sizeof(cam_info->ba_cam_map),
  3165. cam_info->ba_cam_map);
  3166. seq_printf(m, "\tpkt_ofld: %*ph\n", (int)sizeof(rtwdev->pkt_offload),
  3167. rtwdev->pkt_offload);
  3168. for (idx = NL80211_BAND_2GHZ; idx < NUM_NL80211_BANDS; idx++) {
  3169. if (!(rtwdev->chip->support_bands & BIT(idx)))
  3170. continue;
  3171. rtw89_dump_pkt_offload(m, &rtwdev->scan_info.pkt_list[idx],
  3172. "\t\t[SCAN %u]: ", idx);
  3173. }
  3174. ieee80211_iterate_active_interfaces_atomic(rtwdev->hw,
  3175. IEEE80211_IFACE_ITER_NORMAL, rtw89_vif_ids_get_iter, m);
  3176. ieee80211_iterate_stations_atomic(rtwdev->hw, rtw89_sta_ids_get_iter, m);
  3177. mutex_unlock(&rtwdev->mutex);
  3178. return 0;
  3179. }
  3180. static struct rtw89_debugfs_priv rtw89_debug_priv_read_reg = {
  3181. .cb_read = rtw89_debug_priv_read_reg_get,
  3182. .cb_write = rtw89_debug_priv_read_reg_select,
  3183. };
  3184. static struct rtw89_debugfs_priv rtw89_debug_priv_write_reg = {
  3185. .cb_write = rtw89_debug_priv_write_reg_set,
  3186. };
  3187. static struct rtw89_debugfs_priv rtw89_debug_priv_read_rf = {
  3188. .cb_read = rtw89_debug_priv_read_rf_get,
  3189. .cb_write = rtw89_debug_priv_read_rf_select,
  3190. };
  3191. static struct rtw89_debugfs_priv rtw89_debug_priv_write_rf = {
  3192. .cb_write = rtw89_debug_priv_write_rf_set,
  3193. };
  3194. static struct rtw89_debugfs_priv rtw89_debug_priv_rf_reg_dump = {
  3195. .cb_read = rtw89_debug_priv_rf_reg_dump_get,
  3196. };
  3197. static struct rtw89_debugfs_priv rtw89_debug_priv_txpwr_table = {
  3198. .cb_read = rtw89_debug_priv_txpwr_table_get,
  3199. };
  3200. static struct rtw89_debugfs_priv rtw89_debug_priv_mac_reg_dump = {
  3201. .cb_read = rtw89_debug_priv_mac_reg_dump_get,
  3202. .cb_write = rtw89_debug_priv_mac_reg_dump_select,
  3203. };
  3204. static struct rtw89_debugfs_priv rtw89_debug_priv_mac_mem_dump = {
  3205. .cb_read = rtw89_debug_priv_mac_mem_dump_get,
  3206. .cb_write = rtw89_debug_priv_mac_mem_dump_select,
  3207. };
  3208. static struct rtw89_debugfs_priv rtw89_debug_priv_mac_dbg_port_dump = {
  3209. .cb_read = rtw89_debug_priv_mac_dbg_port_dump_get,
  3210. .cb_write = rtw89_debug_priv_mac_dbg_port_dump_select,
  3211. };
  3212. static struct rtw89_debugfs_priv rtw89_debug_priv_send_h2c = {
  3213. .cb_write = rtw89_debug_priv_send_h2c_set,
  3214. };
  3215. static struct rtw89_debugfs_priv rtw89_debug_priv_early_h2c = {
  3216. .cb_read = rtw89_debug_priv_early_h2c_get,
  3217. .cb_write = rtw89_debug_priv_early_h2c_set,
  3218. };
  3219. static struct rtw89_debugfs_priv rtw89_debug_priv_fw_crash = {
  3220. .cb_read = rtw89_debug_priv_fw_crash_get,
  3221. .cb_write = rtw89_debug_priv_fw_crash_set,
  3222. };
  3223. static struct rtw89_debugfs_priv rtw89_debug_priv_btc_info = {
  3224. .cb_read = rtw89_debug_priv_btc_info_get,
  3225. };
  3226. static struct rtw89_debugfs_priv rtw89_debug_priv_btc_manual = {
  3227. .cb_write = rtw89_debug_priv_btc_manual_set,
  3228. };
  3229. static struct rtw89_debugfs_priv rtw89_debug_priv_fw_log_manual = {
  3230. .cb_write = rtw89_debug_fw_log_manual_set,
  3231. };
  3232. static struct rtw89_debugfs_priv rtw89_debug_priv_phy_info = {
  3233. .cb_read = rtw89_debug_priv_phy_info_get,
  3234. };
  3235. static struct rtw89_debugfs_priv rtw89_debug_priv_stations = {
  3236. .cb_read = rtw89_debug_priv_stations_get,
  3237. };
  3238. #define rtw89_debugfs_add(name, mode, fopname, parent) \
  3239. do { \
  3240. rtw89_debug_priv_ ##name.rtwdev = rtwdev; \
  3241. if (!debugfs_create_file(#name, mode, \
  3242. parent, &rtw89_debug_priv_ ##name, \
  3243. &file_ops_ ##fopname)) \
  3244. pr_debug("Unable to initialize debugfs:%s\n", #name); \
  3245. } while (0)
  3246. #define rtw89_debugfs_add_w(name) \
  3247. rtw89_debugfs_add(name, S_IFREG | 0222, single_w, debugfs_topdir)
  3248. #define rtw89_debugfs_add_rw(name) \
  3249. rtw89_debugfs_add(name, S_IFREG | 0666, common_rw, debugfs_topdir)
  3250. #define rtw89_debugfs_add_r(name) \
  3251. rtw89_debugfs_add(name, S_IFREG | 0444, single_r, debugfs_topdir)
  3252. void rtw89_debugfs_init(struct rtw89_dev *rtwdev)
  3253. {
  3254. struct dentry *debugfs_topdir;
  3255. debugfs_topdir = debugfs_create_dir("rtw89",
  3256. rtwdev->hw->wiphy->debugfsdir);
  3257. rtw89_debugfs_add_rw(read_reg);
  3258. rtw89_debugfs_add_w(write_reg);
  3259. rtw89_debugfs_add_rw(read_rf);
  3260. rtw89_debugfs_add_w(write_rf);
  3261. rtw89_debugfs_add_r(rf_reg_dump);
  3262. rtw89_debugfs_add_r(txpwr_table);
  3263. rtw89_debugfs_add_rw(mac_reg_dump);
  3264. rtw89_debugfs_add_rw(mac_mem_dump);
  3265. rtw89_debugfs_add_rw(mac_dbg_port_dump);
  3266. rtw89_debugfs_add_w(send_h2c);
  3267. rtw89_debugfs_add_rw(early_h2c);
  3268. rtw89_debugfs_add_rw(fw_crash);
  3269. rtw89_debugfs_add_r(btc_info);
  3270. rtw89_debugfs_add_w(btc_manual);
  3271. rtw89_debugfs_add_w(fw_log_manual);
  3272. rtw89_debugfs_add_r(phy_info);
  3273. rtw89_debugfs_add_r(stations);
  3274. }
  3275. #endif
  3276. #ifdef CONFIG_RTW89_DEBUGMSG
  3277. void __rtw89_debug(struct rtw89_dev *rtwdev,
  3278. enum rtw89_debug_mask mask,
  3279. const char *fmt, ...)
  3280. {
  3281. struct va_format vaf = {
  3282. .fmt = fmt,
  3283. };
  3284. va_list args;
  3285. va_start(args, fmt);
  3286. vaf.va = &args;
  3287. if (rtw89_debug_mask & mask)
  3288. dev_printk(KERN_DEBUG, rtwdev->dev, "%pV", &vaf);
  3289. va_end(args);
  3290. }
  3291. EXPORT_SYMBOL(__rtw89_debug);
  3292. #endif