cudbg_lib.c 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843
  1. /*
  2. * Copyright (C) 2017 Chelsio Communications. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. */
  17. #include <linux/sort.h>
  18. #include "t4_regs.h"
  19. #include "cxgb4.h"
  20. #include "cudbg_if.h"
  21. #include "cudbg_lib_common.h"
  22. #include "cudbg_entity.h"
  23. #include "cudbg_lib.h"
  24. #include "cudbg_zlib.h"
  25. static int cudbg_do_compression(struct cudbg_init *pdbg_init,
  26. struct cudbg_buffer *pin_buff,
  27. struct cudbg_buffer *dbg_buff)
  28. {
  29. struct cudbg_buffer temp_in_buff = { 0 };
  30. int bytes_left, bytes_read, bytes;
  31. u32 offset = dbg_buff->offset;
  32. int rc;
  33. temp_in_buff.offset = pin_buff->offset;
  34. temp_in_buff.data = pin_buff->data;
  35. temp_in_buff.size = pin_buff->size;
  36. bytes_left = pin_buff->size;
  37. bytes_read = 0;
  38. while (bytes_left > 0) {
  39. /* Do compression in smaller chunks */
  40. bytes = min_t(unsigned long, bytes_left,
  41. (unsigned long)CUDBG_CHUNK_SIZE);
  42. temp_in_buff.data = (char *)pin_buff->data + bytes_read;
  43. temp_in_buff.size = bytes;
  44. rc = cudbg_compress_buff(pdbg_init, &temp_in_buff, dbg_buff);
  45. if (rc)
  46. return rc;
  47. bytes_left -= bytes;
  48. bytes_read += bytes;
  49. }
  50. pin_buff->size = dbg_buff->offset - offset;
  51. return 0;
  52. }
  53. static int cudbg_write_and_release_buff(struct cudbg_init *pdbg_init,
  54. struct cudbg_buffer *pin_buff,
  55. struct cudbg_buffer *dbg_buff)
  56. {
  57. int rc = 0;
  58. if (pdbg_init->compress_type == CUDBG_COMPRESSION_NONE) {
  59. cudbg_update_buff(pin_buff, dbg_buff);
  60. } else {
  61. rc = cudbg_do_compression(pdbg_init, pin_buff, dbg_buff);
  62. if (rc)
  63. goto out;
  64. }
  65. out:
  66. cudbg_put_buff(pdbg_init, pin_buff);
  67. return rc;
  68. }
  69. static int is_fw_attached(struct cudbg_init *pdbg_init)
  70. {
  71. struct adapter *padap = pdbg_init->adap;
  72. if (!(padap->flags & FW_OK) || padap->use_bd)
  73. return 0;
  74. return 1;
  75. }
  76. /* This function will add additional padding bytes into debug_buffer to make it
  77. * 4 byte aligned.
  78. */
  79. void cudbg_align_debug_buffer(struct cudbg_buffer *dbg_buff,
  80. struct cudbg_entity_hdr *entity_hdr)
  81. {
  82. u8 zero_buf[4] = {0};
  83. u8 padding, remain;
  84. remain = (dbg_buff->offset - entity_hdr->start_offset) % 4;
  85. padding = 4 - remain;
  86. if (remain) {
  87. memcpy(((u8 *)dbg_buff->data) + dbg_buff->offset, &zero_buf,
  88. padding);
  89. dbg_buff->offset += padding;
  90. entity_hdr->num_pad = padding;
  91. }
  92. entity_hdr->size = dbg_buff->offset - entity_hdr->start_offset;
  93. }
  94. struct cudbg_entity_hdr *cudbg_get_entity_hdr(void *outbuf, int i)
  95. {
  96. struct cudbg_hdr *cudbg_hdr = (struct cudbg_hdr *)outbuf;
  97. return (struct cudbg_entity_hdr *)
  98. ((char *)outbuf + cudbg_hdr->hdr_len +
  99. (sizeof(struct cudbg_entity_hdr) * (i - 1)));
  100. }
  101. static int cudbg_read_vpd_reg(struct adapter *padap, u32 addr, u32 len,
  102. void *dest)
  103. {
  104. int vaddr, rc;
  105. vaddr = t4_eeprom_ptov(addr, padap->pf, EEPROMPFSIZE);
  106. if (vaddr < 0)
  107. return vaddr;
  108. rc = pci_read_vpd(padap->pdev, vaddr, len, dest);
  109. if (rc < 0)
  110. return rc;
  111. return 0;
  112. }
  113. static int cudbg_mem_desc_cmp(const void *a, const void *b)
  114. {
  115. return ((const struct cudbg_mem_desc *)a)->base -
  116. ((const struct cudbg_mem_desc *)b)->base;
  117. }
  118. int cudbg_fill_meminfo(struct adapter *padap,
  119. struct cudbg_meminfo *meminfo_buff)
  120. {
  121. struct cudbg_mem_desc *md;
  122. u32 lo, hi, used, alloc;
  123. int n, i;
  124. memset(meminfo_buff->avail, 0,
  125. ARRAY_SIZE(meminfo_buff->avail) *
  126. sizeof(struct cudbg_mem_desc));
  127. memset(meminfo_buff->mem, 0,
  128. (ARRAY_SIZE(cudbg_region) + 3) * sizeof(struct cudbg_mem_desc));
  129. md = meminfo_buff->mem;
  130. for (i = 0; i < ARRAY_SIZE(meminfo_buff->mem); i++) {
  131. meminfo_buff->mem[i].limit = 0;
  132. meminfo_buff->mem[i].idx = i;
  133. }
  134. /* Find and sort the populated memory ranges */
  135. i = 0;
  136. lo = t4_read_reg(padap, MA_TARGET_MEM_ENABLE_A);
  137. if (lo & EDRAM0_ENABLE_F) {
  138. hi = t4_read_reg(padap, MA_EDRAM0_BAR_A);
  139. meminfo_buff->avail[i].base =
  140. cudbg_mbytes_to_bytes(EDRAM0_BASE_G(hi));
  141. meminfo_buff->avail[i].limit =
  142. meminfo_buff->avail[i].base +
  143. cudbg_mbytes_to_bytes(EDRAM0_SIZE_G(hi));
  144. meminfo_buff->avail[i].idx = 0;
  145. i++;
  146. }
  147. if (lo & EDRAM1_ENABLE_F) {
  148. hi = t4_read_reg(padap, MA_EDRAM1_BAR_A);
  149. meminfo_buff->avail[i].base =
  150. cudbg_mbytes_to_bytes(EDRAM1_BASE_G(hi));
  151. meminfo_buff->avail[i].limit =
  152. meminfo_buff->avail[i].base +
  153. cudbg_mbytes_to_bytes(EDRAM1_SIZE_G(hi));
  154. meminfo_buff->avail[i].idx = 1;
  155. i++;
  156. }
  157. if (is_t5(padap->params.chip)) {
  158. if (lo & EXT_MEM0_ENABLE_F) {
  159. hi = t4_read_reg(padap, MA_EXT_MEMORY0_BAR_A);
  160. meminfo_buff->avail[i].base =
  161. cudbg_mbytes_to_bytes(EXT_MEM_BASE_G(hi));
  162. meminfo_buff->avail[i].limit =
  163. meminfo_buff->avail[i].base +
  164. cudbg_mbytes_to_bytes(EXT_MEM_SIZE_G(hi));
  165. meminfo_buff->avail[i].idx = 3;
  166. i++;
  167. }
  168. if (lo & EXT_MEM1_ENABLE_F) {
  169. hi = t4_read_reg(padap, MA_EXT_MEMORY1_BAR_A);
  170. meminfo_buff->avail[i].base =
  171. cudbg_mbytes_to_bytes(EXT_MEM1_BASE_G(hi));
  172. meminfo_buff->avail[i].limit =
  173. meminfo_buff->avail[i].base +
  174. cudbg_mbytes_to_bytes(EXT_MEM1_SIZE_G(hi));
  175. meminfo_buff->avail[i].idx = 4;
  176. i++;
  177. }
  178. } else {
  179. if (lo & EXT_MEM_ENABLE_F) {
  180. hi = t4_read_reg(padap, MA_EXT_MEMORY_BAR_A);
  181. meminfo_buff->avail[i].base =
  182. cudbg_mbytes_to_bytes(EXT_MEM_BASE_G(hi));
  183. meminfo_buff->avail[i].limit =
  184. meminfo_buff->avail[i].base +
  185. cudbg_mbytes_to_bytes(EXT_MEM_SIZE_G(hi));
  186. meminfo_buff->avail[i].idx = 2;
  187. i++;
  188. }
  189. if (lo & HMA_MUX_F) {
  190. hi = t4_read_reg(padap, MA_EXT_MEMORY1_BAR_A);
  191. meminfo_buff->avail[i].base =
  192. cudbg_mbytes_to_bytes(EXT_MEM1_BASE_G(hi));
  193. meminfo_buff->avail[i].limit =
  194. meminfo_buff->avail[i].base +
  195. cudbg_mbytes_to_bytes(EXT_MEM1_SIZE_G(hi));
  196. meminfo_buff->avail[i].idx = 5;
  197. i++;
  198. }
  199. }
  200. if (!i) /* no memory available */
  201. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  202. meminfo_buff->avail_c = i;
  203. sort(meminfo_buff->avail, i, sizeof(struct cudbg_mem_desc),
  204. cudbg_mem_desc_cmp, NULL);
  205. (md++)->base = t4_read_reg(padap, SGE_DBQ_CTXT_BADDR_A);
  206. (md++)->base = t4_read_reg(padap, SGE_IMSG_CTXT_BADDR_A);
  207. (md++)->base = t4_read_reg(padap, SGE_FLM_CACHE_BADDR_A);
  208. (md++)->base = t4_read_reg(padap, TP_CMM_TCB_BASE_A);
  209. (md++)->base = t4_read_reg(padap, TP_CMM_MM_BASE_A);
  210. (md++)->base = t4_read_reg(padap, TP_CMM_TIMER_BASE_A);
  211. (md++)->base = t4_read_reg(padap, TP_CMM_MM_RX_FLST_BASE_A);
  212. (md++)->base = t4_read_reg(padap, TP_CMM_MM_TX_FLST_BASE_A);
  213. (md++)->base = t4_read_reg(padap, TP_CMM_MM_PS_FLST_BASE_A);
  214. /* the next few have explicit upper bounds */
  215. md->base = t4_read_reg(padap, TP_PMM_TX_BASE_A);
  216. md->limit = md->base - 1 +
  217. t4_read_reg(padap, TP_PMM_TX_PAGE_SIZE_A) *
  218. PMTXMAXPAGE_G(t4_read_reg(padap, TP_PMM_TX_MAX_PAGE_A));
  219. md++;
  220. md->base = t4_read_reg(padap, TP_PMM_RX_BASE_A);
  221. md->limit = md->base - 1 +
  222. t4_read_reg(padap, TP_PMM_RX_PAGE_SIZE_A) *
  223. PMRXMAXPAGE_G(t4_read_reg(padap, TP_PMM_RX_MAX_PAGE_A));
  224. md++;
  225. if (t4_read_reg(padap, LE_DB_CONFIG_A) & HASHEN_F) {
  226. if (CHELSIO_CHIP_VERSION(padap->params.chip) <= CHELSIO_T5) {
  227. hi = t4_read_reg(padap, LE_DB_TID_HASHBASE_A) / 4;
  228. md->base = t4_read_reg(padap, LE_DB_HASH_TID_BASE_A);
  229. } else {
  230. hi = t4_read_reg(padap, LE_DB_HASH_TID_BASE_A);
  231. md->base = t4_read_reg(padap,
  232. LE_DB_HASH_TBL_BASE_ADDR_A);
  233. }
  234. md->limit = 0;
  235. } else {
  236. md->base = 0;
  237. md->idx = ARRAY_SIZE(cudbg_region); /* hide it */
  238. }
  239. md++;
  240. #define ulp_region(reg) do { \
  241. md->base = t4_read_reg(padap, ULP_ ## reg ## _LLIMIT_A);\
  242. (md++)->limit = t4_read_reg(padap, ULP_ ## reg ## _ULIMIT_A);\
  243. } while (0)
  244. ulp_region(RX_ISCSI);
  245. ulp_region(RX_TDDP);
  246. ulp_region(TX_TPT);
  247. ulp_region(RX_STAG);
  248. ulp_region(RX_RQ);
  249. ulp_region(RX_RQUDP);
  250. ulp_region(RX_PBL);
  251. ulp_region(TX_PBL);
  252. #undef ulp_region
  253. md->base = 0;
  254. md->idx = ARRAY_SIZE(cudbg_region);
  255. if (!is_t4(padap->params.chip)) {
  256. u32 fifo_size = t4_read_reg(padap, SGE_DBVFIFO_SIZE_A);
  257. u32 sge_ctrl = t4_read_reg(padap, SGE_CONTROL2_A);
  258. u32 size = 0;
  259. if (is_t5(padap->params.chip)) {
  260. if (sge_ctrl & VFIFO_ENABLE_F)
  261. size = DBVFIFO_SIZE_G(fifo_size);
  262. } else {
  263. size = T6_DBVFIFO_SIZE_G(fifo_size);
  264. }
  265. if (size) {
  266. md->base = BASEADDR_G(t4_read_reg(padap,
  267. SGE_DBVFIFO_BADDR_A));
  268. md->limit = md->base + (size << 2) - 1;
  269. }
  270. }
  271. md++;
  272. md->base = t4_read_reg(padap, ULP_RX_CTX_BASE_A);
  273. md->limit = 0;
  274. md++;
  275. md->base = t4_read_reg(padap, ULP_TX_ERR_TABLE_BASE_A);
  276. md->limit = 0;
  277. md++;
  278. md->base = padap->vres.ocq.start;
  279. if (padap->vres.ocq.size)
  280. md->limit = md->base + padap->vres.ocq.size - 1;
  281. else
  282. md->idx = ARRAY_SIZE(cudbg_region); /* hide it */
  283. md++;
  284. /* add any address-space holes, there can be up to 3 */
  285. for (n = 0; n < i - 1; n++)
  286. if (meminfo_buff->avail[n].limit <
  287. meminfo_buff->avail[n + 1].base)
  288. (md++)->base = meminfo_buff->avail[n].limit;
  289. if (meminfo_buff->avail[n].limit)
  290. (md++)->base = meminfo_buff->avail[n].limit;
  291. n = md - meminfo_buff->mem;
  292. meminfo_buff->mem_c = n;
  293. sort(meminfo_buff->mem, n, sizeof(struct cudbg_mem_desc),
  294. cudbg_mem_desc_cmp, NULL);
  295. lo = t4_read_reg(padap, CIM_SDRAM_BASE_ADDR_A);
  296. hi = t4_read_reg(padap, CIM_SDRAM_ADDR_SIZE_A) + lo - 1;
  297. meminfo_buff->up_ram_lo = lo;
  298. meminfo_buff->up_ram_hi = hi;
  299. lo = t4_read_reg(padap, CIM_EXTMEM2_BASE_ADDR_A);
  300. hi = t4_read_reg(padap, CIM_EXTMEM2_ADDR_SIZE_A) + lo - 1;
  301. meminfo_buff->up_extmem2_lo = lo;
  302. meminfo_buff->up_extmem2_hi = hi;
  303. lo = t4_read_reg(padap, TP_PMM_RX_MAX_PAGE_A);
  304. meminfo_buff->rx_pages_data[0] = PMRXMAXPAGE_G(lo);
  305. meminfo_buff->rx_pages_data[1] =
  306. t4_read_reg(padap, TP_PMM_RX_PAGE_SIZE_A) >> 10;
  307. meminfo_buff->rx_pages_data[2] = (lo & PMRXNUMCHN_F) ? 2 : 1;
  308. lo = t4_read_reg(padap, TP_PMM_TX_MAX_PAGE_A);
  309. hi = t4_read_reg(padap, TP_PMM_TX_PAGE_SIZE_A);
  310. meminfo_buff->tx_pages_data[0] = PMTXMAXPAGE_G(lo);
  311. meminfo_buff->tx_pages_data[1] =
  312. hi >= (1 << 20) ? (hi >> 20) : (hi >> 10);
  313. meminfo_buff->tx_pages_data[2] =
  314. hi >= (1 << 20) ? 'M' : 'K';
  315. meminfo_buff->tx_pages_data[3] = 1 << PMTXNUMCHN_G(lo);
  316. meminfo_buff->p_structs = t4_read_reg(padap, TP_CMM_MM_MAX_PSTRUCT_A);
  317. for (i = 0; i < 4; i++) {
  318. if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5)
  319. lo = t4_read_reg(padap,
  320. MPS_RX_MAC_BG_PG_CNT0_A + i * 4);
  321. else
  322. lo = t4_read_reg(padap, MPS_RX_PG_RSV0_A + i * 4);
  323. if (is_t5(padap->params.chip)) {
  324. used = T5_USED_G(lo);
  325. alloc = T5_ALLOC_G(lo);
  326. } else {
  327. used = USED_G(lo);
  328. alloc = ALLOC_G(lo);
  329. }
  330. meminfo_buff->port_used[i] = used;
  331. meminfo_buff->port_alloc[i] = alloc;
  332. }
  333. for (i = 0; i < padap->params.arch.nchan; i++) {
  334. if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5)
  335. lo = t4_read_reg(padap,
  336. MPS_RX_LPBK_BG_PG_CNT0_A + i * 4);
  337. else
  338. lo = t4_read_reg(padap, MPS_RX_PG_RSV4_A + i * 4);
  339. if (is_t5(padap->params.chip)) {
  340. used = T5_USED_G(lo);
  341. alloc = T5_ALLOC_G(lo);
  342. } else {
  343. used = USED_G(lo);
  344. alloc = ALLOC_G(lo);
  345. }
  346. meminfo_buff->loopback_used[i] = used;
  347. meminfo_buff->loopback_alloc[i] = alloc;
  348. }
  349. return 0;
  350. }
  351. int cudbg_collect_reg_dump(struct cudbg_init *pdbg_init,
  352. struct cudbg_buffer *dbg_buff,
  353. struct cudbg_error *cudbg_err)
  354. {
  355. struct adapter *padap = pdbg_init->adap;
  356. struct cudbg_buffer temp_buff = { 0 };
  357. u32 buf_size = 0;
  358. int rc = 0;
  359. if (is_t4(padap->params.chip))
  360. buf_size = T4_REGMAP_SIZE;
  361. else if (is_t5(padap->params.chip) || is_t6(padap->params.chip))
  362. buf_size = T5_REGMAP_SIZE;
  363. rc = cudbg_get_buff(pdbg_init, dbg_buff, buf_size, &temp_buff);
  364. if (rc)
  365. return rc;
  366. t4_get_regs(padap, (void *)temp_buff.data, temp_buff.size);
  367. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  368. }
  369. int cudbg_collect_fw_devlog(struct cudbg_init *pdbg_init,
  370. struct cudbg_buffer *dbg_buff,
  371. struct cudbg_error *cudbg_err)
  372. {
  373. struct adapter *padap = pdbg_init->adap;
  374. struct cudbg_buffer temp_buff = { 0 };
  375. struct devlog_params *dparams;
  376. int rc = 0;
  377. rc = t4_init_devlog_params(padap);
  378. if (rc < 0) {
  379. cudbg_err->sys_err = rc;
  380. return rc;
  381. }
  382. dparams = &padap->params.devlog;
  383. rc = cudbg_get_buff(pdbg_init, dbg_buff, dparams->size, &temp_buff);
  384. if (rc)
  385. return rc;
  386. /* Collect FW devlog */
  387. if (dparams->start != 0) {
  388. spin_lock(&padap->win0_lock);
  389. rc = t4_memory_rw(padap, padap->params.drv_memwin,
  390. dparams->memtype, dparams->start,
  391. dparams->size,
  392. (__be32 *)(char *)temp_buff.data,
  393. 1);
  394. spin_unlock(&padap->win0_lock);
  395. if (rc) {
  396. cudbg_err->sys_err = rc;
  397. cudbg_put_buff(pdbg_init, &temp_buff);
  398. return rc;
  399. }
  400. }
  401. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  402. }
  403. int cudbg_collect_cim_la(struct cudbg_init *pdbg_init,
  404. struct cudbg_buffer *dbg_buff,
  405. struct cudbg_error *cudbg_err)
  406. {
  407. struct adapter *padap = pdbg_init->adap;
  408. struct cudbg_buffer temp_buff = { 0 };
  409. int size, rc;
  410. u32 cfg = 0;
  411. if (is_t6(padap->params.chip)) {
  412. size = padap->params.cim_la_size / 10 + 1;
  413. size *= 10 * sizeof(u32);
  414. } else {
  415. size = padap->params.cim_la_size / 8;
  416. size *= 8 * sizeof(u32);
  417. }
  418. size += sizeof(cfg);
  419. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  420. if (rc)
  421. return rc;
  422. rc = t4_cim_read(padap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
  423. if (rc) {
  424. cudbg_err->sys_err = rc;
  425. cudbg_put_buff(pdbg_init, &temp_buff);
  426. return rc;
  427. }
  428. memcpy((char *)temp_buff.data, &cfg, sizeof(cfg));
  429. rc = t4_cim_read_la(padap,
  430. (u32 *)((char *)temp_buff.data + sizeof(cfg)),
  431. NULL);
  432. if (rc < 0) {
  433. cudbg_err->sys_err = rc;
  434. cudbg_put_buff(pdbg_init, &temp_buff);
  435. return rc;
  436. }
  437. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  438. }
  439. int cudbg_collect_cim_ma_la(struct cudbg_init *pdbg_init,
  440. struct cudbg_buffer *dbg_buff,
  441. struct cudbg_error *cudbg_err)
  442. {
  443. struct adapter *padap = pdbg_init->adap;
  444. struct cudbg_buffer temp_buff = { 0 };
  445. int size, rc;
  446. size = 2 * CIM_MALA_SIZE * 5 * sizeof(u32);
  447. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  448. if (rc)
  449. return rc;
  450. t4_cim_read_ma_la(padap,
  451. (u32 *)temp_buff.data,
  452. (u32 *)((char *)temp_buff.data +
  453. 5 * CIM_MALA_SIZE));
  454. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  455. }
  456. int cudbg_collect_cim_qcfg(struct cudbg_init *pdbg_init,
  457. struct cudbg_buffer *dbg_buff,
  458. struct cudbg_error *cudbg_err)
  459. {
  460. struct adapter *padap = pdbg_init->adap;
  461. struct cudbg_buffer temp_buff = { 0 };
  462. struct cudbg_cim_qcfg *cim_qcfg_data;
  463. int rc;
  464. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_cim_qcfg),
  465. &temp_buff);
  466. if (rc)
  467. return rc;
  468. cim_qcfg_data = (struct cudbg_cim_qcfg *)temp_buff.data;
  469. cim_qcfg_data->chip = padap->params.chip;
  470. rc = t4_cim_read(padap, UP_IBQ_0_RDADDR_A,
  471. ARRAY_SIZE(cim_qcfg_data->stat), cim_qcfg_data->stat);
  472. if (rc) {
  473. cudbg_err->sys_err = rc;
  474. cudbg_put_buff(pdbg_init, &temp_buff);
  475. return rc;
  476. }
  477. rc = t4_cim_read(padap, UP_OBQ_0_REALADDR_A,
  478. ARRAY_SIZE(cim_qcfg_data->obq_wr),
  479. cim_qcfg_data->obq_wr);
  480. if (rc) {
  481. cudbg_err->sys_err = rc;
  482. cudbg_put_buff(pdbg_init, &temp_buff);
  483. return rc;
  484. }
  485. t4_read_cimq_cfg(padap, cim_qcfg_data->base, cim_qcfg_data->size,
  486. cim_qcfg_data->thres);
  487. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  488. }
  489. static int cudbg_read_cim_ibq(struct cudbg_init *pdbg_init,
  490. struct cudbg_buffer *dbg_buff,
  491. struct cudbg_error *cudbg_err, int qid)
  492. {
  493. struct adapter *padap = pdbg_init->adap;
  494. struct cudbg_buffer temp_buff = { 0 };
  495. int no_of_read_words, rc = 0;
  496. u32 qsize;
  497. /* collect CIM IBQ */
  498. qsize = CIM_IBQ_SIZE * 4 * sizeof(u32);
  499. rc = cudbg_get_buff(pdbg_init, dbg_buff, qsize, &temp_buff);
  500. if (rc)
  501. return rc;
  502. /* t4_read_cim_ibq will return no. of read words or error */
  503. no_of_read_words = t4_read_cim_ibq(padap, qid,
  504. (u32 *)temp_buff.data, qsize);
  505. /* no_of_read_words is less than or equal to 0 means error */
  506. if (no_of_read_words <= 0) {
  507. if (!no_of_read_words)
  508. rc = CUDBG_SYSTEM_ERROR;
  509. else
  510. rc = no_of_read_words;
  511. cudbg_err->sys_err = rc;
  512. cudbg_put_buff(pdbg_init, &temp_buff);
  513. return rc;
  514. }
  515. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  516. }
  517. int cudbg_collect_cim_ibq_tp0(struct cudbg_init *pdbg_init,
  518. struct cudbg_buffer *dbg_buff,
  519. struct cudbg_error *cudbg_err)
  520. {
  521. return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 0);
  522. }
  523. int cudbg_collect_cim_ibq_tp1(struct cudbg_init *pdbg_init,
  524. struct cudbg_buffer *dbg_buff,
  525. struct cudbg_error *cudbg_err)
  526. {
  527. return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 1);
  528. }
  529. int cudbg_collect_cim_ibq_ulp(struct cudbg_init *pdbg_init,
  530. struct cudbg_buffer *dbg_buff,
  531. struct cudbg_error *cudbg_err)
  532. {
  533. return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 2);
  534. }
  535. int cudbg_collect_cim_ibq_sge0(struct cudbg_init *pdbg_init,
  536. struct cudbg_buffer *dbg_buff,
  537. struct cudbg_error *cudbg_err)
  538. {
  539. return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 3);
  540. }
  541. int cudbg_collect_cim_ibq_sge1(struct cudbg_init *pdbg_init,
  542. struct cudbg_buffer *dbg_buff,
  543. struct cudbg_error *cudbg_err)
  544. {
  545. return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 4);
  546. }
  547. int cudbg_collect_cim_ibq_ncsi(struct cudbg_init *pdbg_init,
  548. struct cudbg_buffer *dbg_buff,
  549. struct cudbg_error *cudbg_err)
  550. {
  551. return cudbg_read_cim_ibq(pdbg_init, dbg_buff, cudbg_err, 5);
  552. }
  553. u32 cudbg_cim_obq_size(struct adapter *padap, int qid)
  554. {
  555. u32 value;
  556. t4_write_reg(padap, CIM_QUEUE_CONFIG_REF_A, OBQSELECT_F |
  557. QUENUMSELECT_V(qid));
  558. value = t4_read_reg(padap, CIM_QUEUE_CONFIG_CTRL_A);
  559. value = CIMQSIZE_G(value) * 64; /* size in number of words */
  560. return value * sizeof(u32);
  561. }
  562. static int cudbg_read_cim_obq(struct cudbg_init *pdbg_init,
  563. struct cudbg_buffer *dbg_buff,
  564. struct cudbg_error *cudbg_err, int qid)
  565. {
  566. struct adapter *padap = pdbg_init->adap;
  567. struct cudbg_buffer temp_buff = { 0 };
  568. int no_of_read_words, rc = 0;
  569. u32 qsize;
  570. /* collect CIM OBQ */
  571. qsize = cudbg_cim_obq_size(padap, qid);
  572. rc = cudbg_get_buff(pdbg_init, dbg_buff, qsize, &temp_buff);
  573. if (rc)
  574. return rc;
  575. /* t4_read_cim_obq will return no. of read words or error */
  576. no_of_read_words = t4_read_cim_obq(padap, qid,
  577. (u32 *)temp_buff.data, qsize);
  578. /* no_of_read_words is less than or equal to 0 means error */
  579. if (no_of_read_words <= 0) {
  580. if (!no_of_read_words)
  581. rc = CUDBG_SYSTEM_ERROR;
  582. else
  583. rc = no_of_read_words;
  584. cudbg_err->sys_err = rc;
  585. cudbg_put_buff(pdbg_init, &temp_buff);
  586. return rc;
  587. }
  588. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  589. }
  590. int cudbg_collect_cim_obq_ulp0(struct cudbg_init *pdbg_init,
  591. struct cudbg_buffer *dbg_buff,
  592. struct cudbg_error *cudbg_err)
  593. {
  594. return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 0);
  595. }
  596. int cudbg_collect_cim_obq_ulp1(struct cudbg_init *pdbg_init,
  597. struct cudbg_buffer *dbg_buff,
  598. struct cudbg_error *cudbg_err)
  599. {
  600. return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 1);
  601. }
  602. int cudbg_collect_cim_obq_ulp2(struct cudbg_init *pdbg_init,
  603. struct cudbg_buffer *dbg_buff,
  604. struct cudbg_error *cudbg_err)
  605. {
  606. return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 2);
  607. }
  608. int cudbg_collect_cim_obq_ulp3(struct cudbg_init *pdbg_init,
  609. struct cudbg_buffer *dbg_buff,
  610. struct cudbg_error *cudbg_err)
  611. {
  612. return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 3);
  613. }
  614. int cudbg_collect_cim_obq_sge(struct cudbg_init *pdbg_init,
  615. struct cudbg_buffer *dbg_buff,
  616. struct cudbg_error *cudbg_err)
  617. {
  618. return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 4);
  619. }
  620. int cudbg_collect_cim_obq_ncsi(struct cudbg_init *pdbg_init,
  621. struct cudbg_buffer *dbg_buff,
  622. struct cudbg_error *cudbg_err)
  623. {
  624. return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 5);
  625. }
  626. int cudbg_collect_obq_sge_rx_q0(struct cudbg_init *pdbg_init,
  627. struct cudbg_buffer *dbg_buff,
  628. struct cudbg_error *cudbg_err)
  629. {
  630. return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 6);
  631. }
  632. int cudbg_collect_obq_sge_rx_q1(struct cudbg_init *pdbg_init,
  633. struct cudbg_buffer *dbg_buff,
  634. struct cudbg_error *cudbg_err)
  635. {
  636. return cudbg_read_cim_obq(pdbg_init, dbg_buff, cudbg_err, 7);
  637. }
  638. static int cudbg_meminfo_get_mem_index(struct adapter *padap,
  639. struct cudbg_meminfo *mem_info,
  640. u8 mem_type, u8 *idx)
  641. {
  642. u8 i, flag;
  643. switch (mem_type) {
  644. case MEM_EDC0:
  645. flag = EDC0_FLAG;
  646. break;
  647. case MEM_EDC1:
  648. flag = EDC1_FLAG;
  649. break;
  650. case MEM_MC0:
  651. /* Some T5 cards have both MC0 and MC1. */
  652. flag = is_t5(padap->params.chip) ? MC0_FLAG : MC_FLAG;
  653. break;
  654. case MEM_MC1:
  655. flag = MC1_FLAG;
  656. break;
  657. case MEM_HMA:
  658. flag = HMA_FLAG;
  659. break;
  660. default:
  661. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  662. }
  663. for (i = 0; i < mem_info->avail_c; i++) {
  664. if (mem_info->avail[i].idx == flag) {
  665. *idx = i;
  666. return 0;
  667. }
  668. }
  669. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  670. }
  671. /* Fetch the @region_name's start and end from @meminfo. */
  672. static int cudbg_get_mem_region(struct adapter *padap,
  673. struct cudbg_meminfo *meminfo,
  674. u8 mem_type, const char *region_name,
  675. struct cudbg_mem_desc *mem_desc)
  676. {
  677. u8 mc, found = 0;
  678. u32 i, idx = 0;
  679. int rc;
  680. rc = cudbg_meminfo_get_mem_index(padap, meminfo, mem_type, &mc);
  681. if (rc)
  682. return rc;
  683. for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
  684. if (!strcmp(cudbg_region[i], region_name)) {
  685. found = 1;
  686. idx = i;
  687. break;
  688. }
  689. }
  690. if (!found)
  691. return -EINVAL;
  692. found = 0;
  693. for (i = 0; i < meminfo->mem_c; i++) {
  694. if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
  695. continue; /* Skip holes */
  696. if (!(meminfo->mem[i].limit))
  697. meminfo->mem[i].limit =
  698. i < meminfo->mem_c - 1 ?
  699. meminfo->mem[i + 1].base - 1 : ~0;
  700. if (meminfo->mem[i].idx == idx) {
  701. /* Check if the region exists in @mem_type memory */
  702. if (meminfo->mem[i].base < meminfo->avail[mc].base &&
  703. meminfo->mem[i].limit < meminfo->avail[mc].base)
  704. return -EINVAL;
  705. if (meminfo->mem[i].base > meminfo->avail[mc].limit)
  706. return -EINVAL;
  707. memcpy(mem_desc, &meminfo->mem[i],
  708. sizeof(struct cudbg_mem_desc));
  709. found = 1;
  710. break;
  711. }
  712. }
  713. if (!found)
  714. return -EINVAL;
  715. return 0;
  716. }
  717. /* Fetch and update the start and end of the requested memory region w.r.t 0
  718. * in the corresponding EDC/MC/HMA.
  719. */
  720. static int cudbg_get_mem_relative(struct adapter *padap,
  721. struct cudbg_meminfo *meminfo,
  722. u8 mem_type, u32 *out_base, u32 *out_end)
  723. {
  724. u8 mc_idx;
  725. int rc;
  726. rc = cudbg_meminfo_get_mem_index(padap, meminfo, mem_type, &mc_idx);
  727. if (rc)
  728. return rc;
  729. if (*out_base < meminfo->avail[mc_idx].base)
  730. *out_base = 0;
  731. else
  732. *out_base -= meminfo->avail[mc_idx].base;
  733. if (*out_end > meminfo->avail[mc_idx].limit)
  734. *out_end = meminfo->avail[mc_idx].limit;
  735. else
  736. *out_end -= meminfo->avail[mc_idx].base;
  737. return 0;
  738. }
  739. /* Get TX and RX Payload region */
  740. static int cudbg_get_payload_range(struct adapter *padap, u8 mem_type,
  741. const char *region_name,
  742. struct cudbg_region_info *payload)
  743. {
  744. struct cudbg_mem_desc mem_desc = { 0 };
  745. struct cudbg_meminfo meminfo;
  746. int rc;
  747. rc = cudbg_fill_meminfo(padap, &meminfo);
  748. if (rc)
  749. return rc;
  750. rc = cudbg_get_mem_region(padap, &meminfo, mem_type, region_name,
  751. &mem_desc);
  752. if (rc) {
  753. payload->exist = false;
  754. return 0;
  755. }
  756. payload->exist = true;
  757. payload->start = mem_desc.base;
  758. payload->end = mem_desc.limit;
  759. return cudbg_get_mem_relative(padap, &meminfo, mem_type,
  760. &payload->start, &payload->end);
  761. }
  762. static int cudbg_memory_read(struct cudbg_init *pdbg_init, int win,
  763. int mtype, u32 addr, u32 len, void *hbuf)
  764. {
  765. u32 win_pf, memoffset, mem_aperture, mem_base;
  766. struct adapter *adap = pdbg_init->adap;
  767. u32 pos, offset, resid;
  768. u32 *res_buf;
  769. u64 *buf;
  770. int ret;
  771. /* Argument sanity checks ...
  772. */
  773. if (addr & 0x3 || (uintptr_t)hbuf & 0x3)
  774. return -EINVAL;
  775. buf = (u64 *)hbuf;
  776. /* Try to do 64-bit reads. Residual will be handled later. */
  777. resid = len & 0x7;
  778. len -= resid;
  779. ret = t4_memory_rw_init(adap, win, mtype, &memoffset, &mem_base,
  780. &mem_aperture);
  781. if (ret)
  782. return ret;
  783. addr = addr + memoffset;
  784. win_pf = is_t4(adap->params.chip) ? 0 : PFNUM_V(adap->pf);
  785. pos = addr & ~(mem_aperture - 1);
  786. offset = addr - pos;
  787. /* Set up initial PCI-E Memory Window to cover the start of our
  788. * transfer.
  789. */
  790. t4_memory_update_win(adap, win, pos | win_pf);
  791. /* Transfer data from the adapter */
  792. while (len > 0) {
  793. *buf++ = le64_to_cpu((__force __le64)
  794. t4_read_reg64(adap, mem_base + offset));
  795. offset += sizeof(u64);
  796. len -= sizeof(u64);
  797. /* If we've reached the end of our current window aperture,
  798. * move the PCI-E Memory Window on to the next.
  799. */
  800. if (offset == mem_aperture) {
  801. pos += mem_aperture;
  802. offset = 0;
  803. t4_memory_update_win(adap, win, pos | win_pf);
  804. }
  805. }
  806. res_buf = (u32 *)buf;
  807. /* Read residual in 32-bit multiples */
  808. while (resid > sizeof(u32)) {
  809. *res_buf++ = le32_to_cpu((__force __le32)
  810. t4_read_reg(adap, mem_base + offset));
  811. offset += sizeof(u32);
  812. resid -= sizeof(u32);
  813. /* If we've reached the end of our current window aperture,
  814. * move the PCI-E Memory Window on to the next.
  815. */
  816. if (offset == mem_aperture) {
  817. pos += mem_aperture;
  818. offset = 0;
  819. t4_memory_update_win(adap, win, pos | win_pf);
  820. }
  821. }
  822. /* Transfer residual < 32-bits */
  823. if (resid)
  824. t4_memory_rw_residual(adap, resid, mem_base + offset,
  825. (u8 *)res_buf, T4_MEMORY_READ);
  826. return 0;
  827. }
  828. #define CUDBG_YIELD_ITERATION 256
  829. static int cudbg_read_fw_mem(struct cudbg_init *pdbg_init,
  830. struct cudbg_buffer *dbg_buff, u8 mem_type,
  831. unsigned long tot_len,
  832. struct cudbg_error *cudbg_err)
  833. {
  834. static const char * const region_name[] = { "Tx payload:",
  835. "Rx payload:" };
  836. unsigned long bytes, bytes_left, bytes_read = 0;
  837. struct adapter *padap = pdbg_init->adap;
  838. struct cudbg_buffer temp_buff = { 0 };
  839. struct cudbg_region_info payload[2];
  840. u32 yield_count = 0;
  841. int rc = 0;
  842. u8 i;
  843. /* Get TX/RX Payload region range if they exist */
  844. memset(payload, 0, sizeof(payload));
  845. for (i = 0; i < ARRAY_SIZE(region_name); i++) {
  846. rc = cudbg_get_payload_range(padap, mem_type, region_name[i],
  847. &payload[i]);
  848. if (rc)
  849. return rc;
  850. if (payload[i].exist) {
  851. /* Align start and end to avoid wrap around */
  852. payload[i].start = roundup(payload[i].start,
  853. CUDBG_CHUNK_SIZE);
  854. payload[i].end = rounddown(payload[i].end,
  855. CUDBG_CHUNK_SIZE);
  856. }
  857. }
  858. bytes_left = tot_len;
  859. while (bytes_left > 0) {
  860. /* As MC size is huge and read through PIO access, this
  861. * loop will hold cpu for a longer time. OS may think that
  862. * the process is hanged and will generate CPU stall traces.
  863. * So yield the cpu regularly.
  864. */
  865. yield_count++;
  866. if (!(yield_count % CUDBG_YIELD_ITERATION))
  867. schedule();
  868. bytes = min_t(unsigned long, bytes_left,
  869. (unsigned long)CUDBG_CHUNK_SIZE);
  870. rc = cudbg_get_buff(pdbg_init, dbg_buff, bytes, &temp_buff);
  871. if (rc)
  872. return rc;
  873. for (i = 0; i < ARRAY_SIZE(payload); i++)
  874. if (payload[i].exist &&
  875. bytes_read >= payload[i].start &&
  876. bytes_read + bytes <= payload[i].end)
  877. /* TX and RX Payload regions can't overlap */
  878. goto skip_read;
  879. spin_lock(&padap->win0_lock);
  880. rc = cudbg_memory_read(pdbg_init, MEMWIN_NIC, mem_type,
  881. bytes_read, bytes, temp_buff.data);
  882. spin_unlock(&padap->win0_lock);
  883. if (rc) {
  884. cudbg_err->sys_err = rc;
  885. cudbg_put_buff(pdbg_init, &temp_buff);
  886. return rc;
  887. }
  888. skip_read:
  889. bytes_left -= bytes;
  890. bytes_read += bytes;
  891. rc = cudbg_write_and_release_buff(pdbg_init, &temp_buff,
  892. dbg_buff);
  893. if (rc) {
  894. cudbg_put_buff(pdbg_init, &temp_buff);
  895. return rc;
  896. }
  897. }
  898. return rc;
  899. }
  900. static void cudbg_t4_fwcache(struct cudbg_init *pdbg_init,
  901. struct cudbg_error *cudbg_err)
  902. {
  903. struct adapter *padap = pdbg_init->adap;
  904. int rc;
  905. if (is_fw_attached(pdbg_init)) {
  906. /* Flush uP dcache before reading edcX/mcX */
  907. rc = t4_fwcache(padap, FW_PARAM_DEV_FWCACHE_FLUSH);
  908. if (rc)
  909. cudbg_err->sys_warn = rc;
  910. }
  911. }
  912. static int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,
  913. struct cudbg_buffer *dbg_buff,
  914. struct cudbg_error *cudbg_err,
  915. u8 mem_type)
  916. {
  917. struct adapter *padap = pdbg_init->adap;
  918. struct cudbg_meminfo mem_info;
  919. unsigned long size;
  920. u8 mc_idx;
  921. int rc;
  922. memset(&mem_info, 0, sizeof(struct cudbg_meminfo));
  923. rc = cudbg_fill_meminfo(padap, &mem_info);
  924. if (rc)
  925. return rc;
  926. cudbg_t4_fwcache(pdbg_init, cudbg_err);
  927. rc = cudbg_meminfo_get_mem_index(padap, &mem_info, mem_type, &mc_idx);
  928. if (rc)
  929. return rc;
  930. size = mem_info.avail[mc_idx].limit - mem_info.avail[mc_idx].base;
  931. return cudbg_read_fw_mem(pdbg_init, dbg_buff, mem_type, size,
  932. cudbg_err);
  933. }
  934. int cudbg_collect_edc0_meminfo(struct cudbg_init *pdbg_init,
  935. struct cudbg_buffer *dbg_buff,
  936. struct cudbg_error *cudbg_err)
  937. {
  938. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  939. MEM_EDC0);
  940. }
  941. int cudbg_collect_edc1_meminfo(struct cudbg_init *pdbg_init,
  942. struct cudbg_buffer *dbg_buff,
  943. struct cudbg_error *cudbg_err)
  944. {
  945. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  946. MEM_EDC1);
  947. }
  948. int cudbg_collect_mc0_meminfo(struct cudbg_init *pdbg_init,
  949. struct cudbg_buffer *dbg_buff,
  950. struct cudbg_error *cudbg_err)
  951. {
  952. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  953. MEM_MC0);
  954. }
  955. int cudbg_collect_mc1_meminfo(struct cudbg_init *pdbg_init,
  956. struct cudbg_buffer *dbg_buff,
  957. struct cudbg_error *cudbg_err)
  958. {
  959. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  960. MEM_MC1);
  961. }
  962. int cudbg_collect_hma_meminfo(struct cudbg_init *pdbg_init,
  963. struct cudbg_buffer *dbg_buff,
  964. struct cudbg_error *cudbg_err)
  965. {
  966. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  967. MEM_HMA);
  968. }
  969. int cudbg_collect_rss(struct cudbg_init *pdbg_init,
  970. struct cudbg_buffer *dbg_buff,
  971. struct cudbg_error *cudbg_err)
  972. {
  973. struct adapter *padap = pdbg_init->adap;
  974. struct cudbg_buffer temp_buff = { 0 };
  975. int rc, nentries;
  976. nentries = t4_chip_rss_size(padap);
  977. rc = cudbg_get_buff(pdbg_init, dbg_buff, nentries * sizeof(u16),
  978. &temp_buff);
  979. if (rc)
  980. return rc;
  981. rc = t4_read_rss(padap, (u16 *)temp_buff.data);
  982. if (rc) {
  983. cudbg_err->sys_err = rc;
  984. cudbg_put_buff(pdbg_init, &temp_buff);
  985. return rc;
  986. }
  987. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  988. }
  989. int cudbg_collect_rss_vf_config(struct cudbg_init *pdbg_init,
  990. struct cudbg_buffer *dbg_buff,
  991. struct cudbg_error *cudbg_err)
  992. {
  993. struct adapter *padap = pdbg_init->adap;
  994. struct cudbg_buffer temp_buff = { 0 };
  995. struct cudbg_rss_vf_conf *vfconf;
  996. int vf, rc, vf_count;
  997. vf_count = padap->params.arch.vfcount;
  998. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  999. vf_count * sizeof(struct cudbg_rss_vf_conf),
  1000. &temp_buff);
  1001. if (rc)
  1002. return rc;
  1003. vfconf = (struct cudbg_rss_vf_conf *)temp_buff.data;
  1004. for (vf = 0; vf < vf_count; vf++)
  1005. t4_read_rss_vf_config(padap, vf, &vfconf[vf].rss_vf_vfl,
  1006. &vfconf[vf].rss_vf_vfh, true);
  1007. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1008. }
  1009. int cudbg_collect_path_mtu(struct cudbg_init *pdbg_init,
  1010. struct cudbg_buffer *dbg_buff,
  1011. struct cudbg_error *cudbg_err)
  1012. {
  1013. struct adapter *padap = pdbg_init->adap;
  1014. struct cudbg_buffer temp_buff = { 0 };
  1015. int rc;
  1016. rc = cudbg_get_buff(pdbg_init, dbg_buff, NMTUS * sizeof(u16),
  1017. &temp_buff);
  1018. if (rc)
  1019. return rc;
  1020. t4_read_mtu_tbl(padap, (u16 *)temp_buff.data, NULL);
  1021. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1022. }
  1023. int cudbg_collect_pm_stats(struct cudbg_init *pdbg_init,
  1024. struct cudbg_buffer *dbg_buff,
  1025. struct cudbg_error *cudbg_err)
  1026. {
  1027. struct adapter *padap = pdbg_init->adap;
  1028. struct cudbg_buffer temp_buff = { 0 };
  1029. struct cudbg_pm_stats *pm_stats_buff;
  1030. int rc;
  1031. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_pm_stats),
  1032. &temp_buff);
  1033. if (rc)
  1034. return rc;
  1035. pm_stats_buff = (struct cudbg_pm_stats *)temp_buff.data;
  1036. t4_pmtx_get_stats(padap, pm_stats_buff->tx_cnt, pm_stats_buff->tx_cyc);
  1037. t4_pmrx_get_stats(padap, pm_stats_buff->rx_cnt, pm_stats_buff->rx_cyc);
  1038. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1039. }
  1040. int cudbg_collect_hw_sched(struct cudbg_init *pdbg_init,
  1041. struct cudbg_buffer *dbg_buff,
  1042. struct cudbg_error *cudbg_err)
  1043. {
  1044. struct adapter *padap = pdbg_init->adap;
  1045. struct cudbg_buffer temp_buff = { 0 };
  1046. struct cudbg_hw_sched *hw_sched_buff;
  1047. int i, rc = 0;
  1048. if (!padap->params.vpd.cclk)
  1049. return CUDBG_STATUS_CCLK_NOT_DEFINED;
  1050. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_hw_sched),
  1051. &temp_buff);
  1052. hw_sched_buff = (struct cudbg_hw_sched *)temp_buff.data;
  1053. hw_sched_buff->map = t4_read_reg(padap, TP_TX_MOD_QUEUE_REQ_MAP_A);
  1054. hw_sched_buff->mode = TIMERMODE_G(t4_read_reg(padap, TP_MOD_CONFIG_A));
  1055. t4_read_pace_tbl(padap, hw_sched_buff->pace_tab);
  1056. for (i = 0; i < NTX_SCHED; ++i)
  1057. t4_get_tx_sched(padap, i, &hw_sched_buff->kbps[i],
  1058. &hw_sched_buff->ipg[i], true);
  1059. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1060. }
  1061. int cudbg_collect_tp_indirect(struct cudbg_init *pdbg_init,
  1062. struct cudbg_buffer *dbg_buff,
  1063. struct cudbg_error *cudbg_err)
  1064. {
  1065. struct adapter *padap = pdbg_init->adap;
  1066. struct cudbg_buffer temp_buff = { 0 };
  1067. struct ireg_buf *ch_tp_pio;
  1068. int i, rc, n = 0;
  1069. u32 size;
  1070. if (is_t5(padap->params.chip))
  1071. n = sizeof(t5_tp_pio_array) +
  1072. sizeof(t5_tp_tm_pio_array) +
  1073. sizeof(t5_tp_mib_index_array);
  1074. else
  1075. n = sizeof(t6_tp_pio_array) +
  1076. sizeof(t6_tp_tm_pio_array) +
  1077. sizeof(t6_tp_mib_index_array);
  1078. n = n / (IREG_NUM_ELEM * sizeof(u32));
  1079. size = sizeof(struct ireg_buf) * n;
  1080. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1081. if (rc)
  1082. return rc;
  1083. ch_tp_pio = (struct ireg_buf *)temp_buff.data;
  1084. /* TP_PIO */
  1085. if (is_t5(padap->params.chip))
  1086. n = sizeof(t5_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
  1087. else if (is_t6(padap->params.chip))
  1088. n = sizeof(t6_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
  1089. for (i = 0; i < n; i++) {
  1090. struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
  1091. u32 *buff = ch_tp_pio->outbuf;
  1092. if (is_t5(padap->params.chip)) {
  1093. tp_pio->ireg_addr = t5_tp_pio_array[i][0];
  1094. tp_pio->ireg_data = t5_tp_pio_array[i][1];
  1095. tp_pio->ireg_local_offset = t5_tp_pio_array[i][2];
  1096. tp_pio->ireg_offset_range = t5_tp_pio_array[i][3];
  1097. } else if (is_t6(padap->params.chip)) {
  1098. tp_pio->ireg_addr = t6_tp_pio_array[i][0];
  1099. tp_pio->ireg_data = t6_tp_pio_array[i][1];
  1100. tp_pio->ireg_local_offset = t6_tp_pio_array[i][2];
  1101. tp_pio->ireg_offset_range = t6_tp_pio_array[i][3];
  1102. }
  1103. t4_tp_pio_read(padap, buff, tp_pio->ireg_offset_range,
  1104. tp_pio->ireg_local_offset, true);
  1105. ch_tp_pio++;
  1106. }
  1107. /* TP_TM_PIO */
  1108. if (is_t5(padap->params.chip))
  1109. n = sizeof(t5_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
  1110. else if (is_t6(padap->params.chip))
  1111. n = sizeof(t6_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
  1112. for (i = 0; i < n; i++) {
  1113. struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
  1114. u32 *buff = ch_tp_pio->outbuf;
  1115. if (is_t5(padap->params.chip)) {
  1116. tp_pio->ireg_addr = t5_tp_tm_pio_array[i][0];
  1117. tp_pio->ireg_data = t5_tp_tm_pio_array[i][1];
  1118. tp_pio->ireg_local_offset = t5_tp_tm_pio_array[i][2];
  1119. tp_pio->ireg_offset_range = t5_tp_tm_pio_array[i][3];
  1120. } else if (is_t6(padap->params.chip)) {
  1121. tp_pio->ireg_addr = t6_tp_tm_pio_array[i][0];
  1122. tp_pio->ireg_data = t6_tp_tm_pio_array[i][1];
  1123. tp_pio->ireg_local_offset = t6_tp_tm_pio_array[i][2];
  1124. tp_pio->ireg_offset_range = t6_tp_tm_pio_array[i][3];
  1125. }
  1126. t4_tp_tm_pio_read(padap, buff, tp_pio->ireg_offset_range,
  1127. tp_pio->ireg_local_offset, true);
  1128. ch_tp_pio++;
  1129. }
  1130. /* TP_MIB_INDEX */
  1131. if (is_t5(padap->params.chip))
  1132. n = sizeof(t5_tp_mib_index_array) /
  1133. (IREG_NUM_ELEM * sizeof(u32));
  1134. else if (is_t6(padap->params.chip))
  1135. n = sizeof(t6_tp_mib_index_array) /
  1136. (IREG_NUM_ELEM * sizeof(u32));
  1137. for (i = 0; i < n ; i++) {
  1138. struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
  1139. u32 *buff = ch_tp_pio->outbuf;
  1140. if (is_t5(padap->params.chip)) {
  1141. tp_pio->ireg_addr = t5_tp_mib_index_array[i][0];
  1142. tp_pio->ireg_data = t5_tp_mib_index_array[i][1];
  1143. tp_pio->ireg_local_offset =
  1144. t5_tp_mib_index_array[i][2];
  1145. tp_pio->ireg_offset_range =
  1146. t5_tp_mib_index_array[i][3];
  1147. } else if (is_t6(padap->params.chip)) {
  1148. tp_pio->ireg_addr = t6_tp_mib_index_array[i][0];
  1149. tp_pio->ireg_data = t6_tp_mib_index_array[i][1];
  1150. tp_pio->ireg_local_offset =
  1151. t6_tp_mib_index_array[i][2];
  1152. tp_pio->ireg_offset_range =
  1153. t6_tp_mib_index_array[i][3];
  1154. }
  1155. t4_tp_mib_read(padap, buff, tp_pio->ireg_offset_range,
  1156. tp_pio->ireg_local_offset, true);
  1157. ch_tp_pio++;
  1158. }
  1159. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1160. }
  1161. static void cudbg_read_sge_qbase_indirect_reg(struct adapter *padap,
  1162. struct sge_qbase_reg_field *qbase,
  1163. u32 func, bool is_pf)
  1164. {
  1165. u32 *buff, i;
  1166. if (is_pf) {
  1167. buff = qbase->pf_data_value[func];
  1168. } else {
  1169. buff = qbase->vf_data_value[func];
  1170. /* In SGE_QBASE_INDEX,
  1171. * Entries 0->7 are PF0->7, Entries 8->263 are VFID0->256.
  1172. */
  1173. func += 8;
  1174. }
  1175. t4_write_reg(padap, qbase->reg_addr, func);
  1176. for (i = 0; i < SGE_QBASE_DATA_REG_NUM; i++, buff++)
  1177. *buff = t4_read_reg(padap, qbase->reg_data[i]);
  1178. }
  1179. int cudbg_collect_sge_indirect(struct cudbg_init *pdbg_init,
  1180. struct cudbg_buffer *dbg_buff,
  1181. struct cudbg_error *cudbg_err)
  1182. {
  1183. struct adapter *padap = pdbg_init->adap;
  1184. struct cudbg_buffer temp_buff = { 0 };
  1185. struct sge_qbase_reg_field *sge_qbase;
  1186. struct ireg_buf *ch_sge_dbg;
  1187. int i, rc;
  1188. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  1189. sizeof(*ch_sge_dbg) * 2 + sizeof(*sge_qbase),
  1190. &temp_buff);
  1191. if (rc)
  1192. return rc;
  1193. ch_sge_dbg = (struct ireg_buf *)temp_buff.data;
  1194. for (i = 0; i < 2; i++) {
  1195. struct ireg_field *sge_pio = &ch_sge_dbg->tp_pio;
  1196. u32 *buff = ch_sge_dbg->outbuf;
  1197. sge_pio->ireg_addr = t5_sge_dbg_index_array[i][0];
  1198. sge_pio->ireg_data = t5_sge_dbg_index_array[i][1];
  1199. sge_pio->ireg_local_offset = t5_sge_dbg_index_array[i][2];
  1200. sge_pio->ireg_offset_range = t5_sge_dbg_index_array[i][3];
  1201. t4_read_indirect(padap,
  1202. sge_pio->ireg_addr,
  1203. sge_pio->ireg_data,
  1204. buff,
  1205. sge_pio->ireg_offset_range,
  1206. sge_pio->ireg_local_offset);
  1207. ch_sge_dbg++;
  1208. }
  1209. if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5) {
  1210. sge_qbase = (struct sge_qbase_reg_field *)ch_sge_dbg;
  1211. /* 1 addr reg SGE_QBASE_INDEX and 4 data reg
  1212. * SGE_QBASE_MAP[0-3]
  1213. */
  1214. sge_qbase->reg_addr = t6_sge_qbase_index_array[0];
  1215. for (i = 0; i < SGE_QBASE_DATA_REG_NUM; i++)
  1216. sge_qbase->reg_data[i] =
  1217. t6_sge_qbase_index_array[i + 1];
  1218. for (i = 0; i <= PCIE_FW_MASTER_M; i++)
  1219. cudbg_read_sge_qbase_indirect_reg(padap, sge_qbase,
  1220. i, true);
  1221. for (i = 0; i < padap->params.arch.vfcount; i++)
  1222. cudbg_read_sge_qbase_indirect_reg(padap, sge_qbase,
  1223. i, false);
  1224. sge_qbase->vfcount = padap->params.arch.vfcount;
  1225. }
  1226. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1227. }
  1228. int cudbg_collect_ulprx_la(struct cudbg_init *pdbg_init,
  1229. struct cudbg_buffer *dbg_buff,
  1230. struct cudbg_error *cudbg_err)
  1231. {
  1232. struct adapter *padap = pdbg_init->adap;
  1233. struct cudbg_buffer temp_buff = { 0 };
  1234. struct cudbg_ulprx_la *ulprx_la_buff;
  1235. int rc;
  1236. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_ulprx_la),
  1237. &temp_buff);
  1238. if (rc)
  1239. return rc;
  1240. ulprx_la_buff = (struct cudbg_ulprx_la *)temp_buff.data;
  1241. t4_ulprx_read_la(padap, (u32 *)ulprx_la_buff->data);
  1242. ulprx_la_buff->size = ULPRX_LA_SIZE;
  1243. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1244. }
  1245. int cudbg_collect_tp_la(struct cudbg_init *pdbg_init,
  1246. struct cudbg_buffer *dbg_buff,
  1247. struct cudbg_error *cudbg_err)
  1248. {
  1249. struct adapter *padap = pdbg_init->adap;
  1250. struct cudbg_buffer temp_buff = { 0 };
  1251. struct cudbg_tp_la *tp_la_buff;
  1252. int size, rc;
  1253. size = sizeof(struct cudbg_tp_la) + TPLA_SIZE * sizeof(u64);
  1254. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1255. if (rc)
  1256. return rc;
  1257. tp_la_buff = (struct cudbg_tp_la *)temp_buff.data;
  1258. tp_la_buff->mode = DBGLAMODE_G(t4_read_reg(padap, TP_DBG_LA_CONFIG_A));
  1259. t4_tp_read_la(padap, (u64 *)tp_la_buff->data, NULL);
  1260. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1261. }
  1262. int cudbg_collect_meminfo(struct cudbg_init *pdbg_init,
  1263. struct cudbg_buffer *dbg_buff,
  1264. struct cudbg_error *cudbg_err)
  1265. {
  1266. struct adapter *padap = pdbg_init->adap;
  1267. struct cudbg_buffer temp_buff = { 0 };
  1268. struct cudbg_meminfo *meminfo_buff;
  1269. int rc;
  1270. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_meminfo),
  1271. &temp_buff);
  1272. if (rc)
  1273. return rc;
  1274. meminfo_buff = (struct cudbg_meminfo *)temp_buff.data;
  1275. rc = cudbg_fill_meminfo(padap, meminfo_buff);
  1276. if (rc) {
  1277. cudbg_err->sys_err = rc;
  1278. cudbg_put_buff(pdbg_init, &temp_buff);
  1279. return rc;
  1280. }
  1281. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1282. }
  1283. int cudbg_collect_cim_pif_la(struct cudbg_init *pdbg_init,
  1284. struct cudbg_buffer *dbg_buff,
  1285. struct cudbg_error *cudbg_err)
  1286. {
  1287. struct cudbg_cim_pif_la *cim_pif_la_buff;
  1288. struct adapter *padap = pdbg_init->adap;
  1289. struct cudbg_buffer temp_buff = { 0 };
  1290. int size, rc;
  1291. size = sizeof(struct cudbg_cim_pif_la) +
  1292. 2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
  1293. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1294. if (rc)
  1295. return rc;
  1296. cim_pif_la_buff = (struct cudbg_cim_pif_la *)temp_buff.data;
  1297. cim_pif_la_buff->size = CIM_PIFLA_SIZE;
  1298. t4_cim_read_pif_la(padap, (u32 *)cim_pif_la_buff->data,
  1299. (u32 *)cim_pif_la_buff->data + 6 * CIM_PIFLA_SIZE,
  1300. NULL, NULL);
  1301. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1302. }
  1303. int cudbg_collect_clk_info(struct cudbg_init *pdbg_init,
  1304. struct cudbg_buffer *dbg_buff,
  1305. struct cudbg_error *cudbg_err)
  1306. {
  1307. struct adapter *padap = pdbg_init->adap;
  1308. struct cudbg_buffer temp_buff = { 0 };
  1309. struct cudbg_clk_info *clk_info_buff;
  1310. u64 tp_tick_us;
  1311. int rc;
  1312. if (!padap->params.vpd.cclk)
  1313. return CUDBG_STATUS_CCLK_NOT_DEFINED;
  1314. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_clk_info),
  1315. &temp_buff);
  1316. if (rc)
  1317. return rc;
  1318. clk_info_buff = (struct cudbg_clk_info *)temp_buff.data;
  1319. clk_info_buff->cclk_ps = 1000000000 / padap->params.vpd.cclk; /* psec */
  1320. clk_info_buff->res = t4_read_reg(padap, TP_TIMER_RESOLUTION_A);
  1321. clk_info_buff->tre = TIMERRESOLUTION_G(clk_info_buff->res);
  1322. clk_info_buff->dack_re = DELAYEDACKRESOLUTION_G(clk_info_buff->res);
  1323. tp_tick_us = (clk_info_buff->cclk_ps << clk_info_buff->tre) / 1000000;
  1324. clk_info_buff->dack_timer =
  1325. (clk_info_buff->cclk_ps << clk_info_buff->dack_re) / 1000000 *
  1326. t4_read_reg(padap, TP_DACK_TIMER_A);
  1327. clk_info_buff->retransmit_min =
  1328. tp_tick_us * t4_read_reg(padap, TP_RXT_MIN_A);
  1329. clk_info_buff->retransmit_max =
  1330. tp_tick_us * t4_read_reg(padap, TP_RXT_MAX_A);
  1331. clk_info_buff->persist_timer_min =
  1332. tp_tick_us * t4_read_reg(padap, TP_PERS_MIN_A);
  1333. clk_info_buff->persist_timer_max =
  1334. tp_tick_us * t4_read_reg(padap, TP_PERS_MAX_A);
  1335. clk_info_buff->keepalive_idle_timer =
  1336. tp_tick_us * t4_read_reg(padap, TP_KEEP_IDLE_A);
  1337. clk_info_buff->keepalive_interval =
  1338. tp_tick_us * t4_read_reg(padap, TP_KEEP_INTVL_A);
  1339. clk_info_buff->initial_srtt =
  1340. tp_tick_us * INITSRTT_G(t4_read_reg(padap, TP_INIT_SRTT_A));
  1341. clk_info_buff->finwait2_timer =
  1342. tp_tick_us * t4_read_reg(padap, TP_FINWAIT2_TIMER_A);
  1343. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1344. }
  1345. int cudbg_collect_pcie_indirect(struct cudbg_init *pdbg_init,
  1346. struct cudbg_buffer *dbg_buff,
  1347. struct cudbg_error *cudbg_err)
  1348. {
  1349. struct adapter *padap = pdbg_init->adap;
  1350. struct cudbg_buffer temp_buff = { 0 };
  1351. struct ireg_buf *ch_pcie;
  1352. int i, rc, n;
  1353. u32 size;
  1354. n = sizeof(t5_pcie_pdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
  1355. size = sizeof(struct ireg_buf) * n * 2;
  1356. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1357. if (rc)
  1358. return rc;
  1359. ch_pcie = (struct ireg_buf *)temp_buff.data;
  1360. /* PCIE_PDBG */
  1361. for (i = 0; i < n; i++) {
  1362. struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
  1363. u32 *buff = ch_pcie->outbuf;
  1364. pcie_pio->ireg_addr = t5_pcie_pdbg_array[i][0];
  1365. pcie_pio->ireg_data = t5_pcie_pdbg_array[i][1];
  1366. pcie_pio->ireg_local_offset = t5_pcie_pdbg_array[i][2];
  1367. pcie_pio->ireg_offset_range = t5_pcie_pdbg_array[i][3];
  1368. t4_read_indirect(padap,
  1369. pcie_pio->ireg_addr,
  1370. pcie_pio->ireg_data,
  1371. buff,
  1372. pcie_pio->ireg_offset_range,
  1373. pcie_pio->ireg_local_offset);
  1374. ch_pcie++;
  1375. }
  1376. /* PCIE_CDBG */
  1377. n = sizeof(t5_pcie_cdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
  1378. for (i = 0; i < n; i++) {
  1379. struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
  1380. u32 *buff = ch_pcie->outbuf;
  1381. pcie_pio->ireg_addr = t5_pcie_cdbg_array[i][0];
  1382. pcie_pio->ireg_data = t5_pcie_cdbg_array[i][1];
  1383. pcie_pio->ireg_local_offset = t5_pcie_cdbg_array[i][2];
  1384. pcie_pio->ireg_offset_range = t5_pcie_cdbg_array[i][3];
  1385. t4_read_indirect(padap,
  1386. pcie_pio->ireg_addr,
  1387. pcie_pio->ireg_data,
  1388. buff,
  1389. pcie_pio->ireg_offset_range,
  1390. pcie_pio->ireg_local_offset);
  1391. ch_pcie++;
  1392. }
  1393. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1394. }
  1395. int cudbg_collect_pm_indirect(struct cudbg_init *pdbg_init,
  1396. struct cudbg_buffer *dbg_buff,
  1397. struct cudbg_error *cudbg_err)
  1398. {
  1399. struct adapter *padap = pdbg_init->adap;
  1400. struct cudbg_buffer temp_buff = { 0 };
  1401. struct ireg_buf *ch_pm;
  1402. int i, rc, n;
  1403. u32 size;
  1404. n = sizeof(t5_pm_rx_array) / (IREG_NUM_ELEM * sizeof(u32));
  1405. size = sizeof(struct ireg_buf) * n * 2;
  1406. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1407. if (rc)
  1408. return rc;
  1409. ch_pm = (struct ireg_buf *)temp_buff.data;
  1410. /* PM_RX */
  1411. for (i = 0; i < n; i++) {
  1412. struct ireg_field *pm_pio = &ch_pm->tp_pio;
  1413. u32 *buff = ch_pm->outbuf;
  1414. pm_pio->ireg_addr = t5_pm_rx_array[i][0];
  1415. pm_pio->ireg_data = t5_pm_rx_array[i][1];
  1416. pm_pio->ireg_local_offset = t5_pm_rx_array[i][2];
  1417. pm_pio->ireg_offset_range = t5_pm_rx_array[i][3];
  1418. t4_read_indirect(padap,
  1419. pm_pio->ireg_addr,
  1420. pm_pio->ireg_data,
  1421. buff,
  1422. pm_pio->ireg_offset_range,
  1423. pm_pio->ireg_local_offset);
  1424. ch_pm++;
  1425. }
  1426. /* PM_TX */
  1427. n = sizeof(t5_pm_tx_array) / (IREG_NUM_ELEM * sizeof(u32));
  1428. for (i = 0; i < n; i++) {
  1429. struct ireg_field *pm_pio = &ch_pm->tp_pio;
  1430. u32 *buff = ch_pm->outbuf;
  1431. pm_pio->ireg_addr = t5_pm_tx_array[i][0];
  1432. pm_pio->ireg_data = t5_pm_tx_array[i][1];
  1433. pm_pio->ireg_local_offset = t5_pm_tx_array[i][2];
  1434. pm_pio->ireg_offset_range = t5_pm_tx_array[i][3];
  1435. t4_read_indirect(padap,
  1436. pm_pio->ireg_addr,
  1437. pm_pio->ireg_data,
  1438. buff,
  1439. pm_pio->ireg_offset_range,
  1440. pm_pio->ireg_local_offset);
  1441. ch_pm++;
  1442. }
  1443. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1444. }
  1445. int cudbg_collect_tid(struct cudbg_init *pdbg_init,
  1446. struct cudbg_buffer *dbg_buff,
  1447. struct cudbg_error *cudbg_err)
  1448. {
  1449. struct adapter *padap = pdbg_init->adap;
  1450. struct cudbg_tid_info_region_rev1 *tid1;
  1451. struct cudbg_buffer temp_buff = { 0 };
  1452. struct cudbg_tid_info_region *tid;
  1453. u32 para[2], val[2];
  1454. int rc;
  1455. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  1456. sizeof(struct cudbg_tid_info_region_rev1),
  1457. &temp_buff);
  1458. if (rc)
  1459. return rc;
  1460. tid1 = (struct cudbg_tid_info_region_rev1 *)temp_buff.data;
  1461. tid = &tid1->tid;
  1462. tid1->ver_hdr.signature = CUDBG_ENTITY_SIGNATURE;
  1463. tid1->ver_hdr.revision = CUDBG_TID_INFO_REV;
  1464. tid1->ver_hdr.size = sizeof(struct cudbg_tid_info_region_rev1) -
  1465. sizeof(struct cudbg_ver_hdr);
  1466. /* If firmware is not attached/alive, use backdoor register
  1467. * access to collect dump.
  1468. */
  1469. if (!is_fw_attached(pdbg_init))
  1470. goto fill_tid;
  1471. #define FW_PARAM_PFVF_A(param) \
  1472. (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
  1473. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param) | \
  1474. FW_PARAMS_PARAM_Y_V(0) | \
  1475. FW_PARAMS_PARAM_Z_V(0))
  1476. para[0] = FW_PARAM_PFVF_A(ETHOFLD_START);
  1477. para[1] = FW_PARAM_PFVF_A(ETHOFLD_END);
  1478. rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2, para, val);
  1479. if (rc < 0) {
  1480. cudbg_err->sys_err = rc;
  1481. cudbg_put_buff(pdbg_init, &temp_buff);
  1482. return rc;
  1483. }
  1484. tid->uotid_base = val[0];
  1485. tid->nuotids = val[1] - val[0] + 1;
  1486. if (is_t5(padap->params.chip)) {
  1487. tid->sb = t4_read_reg(padap, LE_DB_SERVER_INDEX_A) / 4;
  1488. } else if (is_t6(padap->params.chip)) {
  1489. tid1->tid_start =
  1490. t4_read_reg(padap, LE_DB_ACTIVE_TABLE_START_INDEX_A);
  1491. tid->sb = t4_read_reg(padap, LE_DB_SRVR_START_INDEX_A);
  1492. para[0] = FW_PARAM_PFVF_A(HPFILTER_START);
  1493. para[1] = FW_PARAM_PFVF_A(HPFILTER_END);
  1494. rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2,
  1495. para, val);
  1496. if (rc < 0) {
  1497. cudbg_err->sys_err = rc;
  1498. cudbg_put_buff(pdbg_init, &temp_buff);
  1499. return rc;
  1500. }
  1501. tid->hpftid_base = val[0];
  1502. tid->nhpftids = val[1] - val[0] + 1;
  1503. }
  1504. #undef FW_PARAM_PFVF_A
  1505. fill_tid:
  1506. tid->ntids = padap->tids.ntids;
  1507. tid->nstids = padap->tids.nstids;
  1508. tid->stid_base = padap->tids.stid_base;
  1509. tid->hash_base = padap->tids.hash_base;
  1510. tid->natids = padap->tids.natids;
  1511. tid->nftids = padap->tids.nftids;
  1512. tid->ftid_base = padap->tids.ftid_base;
  1513. tid->aftid_base = padap->tids.aftid_base;
  1514. tid->aftid_end = padap->tids.aftid_end;
  1515. tid->sftid_base = padap->tids.sftid_base;
  1516. tid->nsftids = padap->tids.nsftids;
  1517. tid->flags = padap->flags;
  1518. tid->le_db_conf = t4_read_reg(padap, LE_DB_CONFIG_A);
  1519. tid->ip_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV4_A);
  1520. tid->ipv6_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV6_A);
  1521. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1522. }
  1523. int cudbg_collect_pcie_config(struct cudbg_init *pdbg_init,
  1524. struct cudbg_buffer *dbg_buff,
  1525. struct cudbg_error *cudbg_err)
  1526. {
  1527. struct adapter *padap = pdbg_init->adap;
  1528. struct cudbg_buffer temp_buff = { 0 };
  1529. u32 size, *value, j;
  1530. int i, rc, n;
  1531. size = sizeof(u32) * CUDBG_NUM_PCIE_CONFIG_REGS;
  1532. n = sizeof(t5_pcie_config_array) / (2 * sizeof(u32));
  1533. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1534. if (rc)
  1535. return rc;
  1536. value = (u32 *)temp_buff.data;
  1537. for (i = 0; i < n; i++) {
  1538. for (j = t5_pcie_config_array[i][0];
  1539. j <= t5_pcie_config_array[i][1]; j += 4) {
  1540. t4_hw_pci_read_cfg4(padap, j, value);
  1541. value++;
  1542. }
  1543. }
  1544. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1545. }
  1546. static int cudbg_sge_ctxt_check_valid(u32 *buf, int type)
  1547. {
  1548. int index, bit, bit_pos = 0;
  1549. switch (type) {
  1550. case CTXT_EGRESS:
  1551. bit_pos = 176;
  1552. break;
  1553. case CTXT_INGRESS:
  1554. bit_pos = 141;
  1555. break;
  1556. case CTXT_FLM:
  1557. bit_pos = 89;
  1558. break;
  1559. }
  1560. index = bit_pos / 32;
  1561. bit = bit_pos % 32;
  1562. return buf[index] & (1U << bit);
  1563. }
  1564. static int cudbg_get_ctxt_region_info(struct adapter *padap,
  1565. struct cudbg_region_info *ctx_info,
  1566. u8 *mem_type)
  1567. {
  1568. struct cudbg_mem_desc mem_desc;
  1569. struct cudbg_meminfo meminfo;
  1570. u32 i, j, value, found;
  1571. u8 flq;
  1572. int rc;
  1573. rc = cudbg_fill_meminfo(padap, &meminfo);
  1574. if (rc)
  1575. return rc;
  1576. /* Get EGRESS and INGRESS context region size */
  1577. for (i = CTXT_EGRESS; i <= CTXT_INGRESS; i++) {
  1578. found = 0;
  1579. memset(&mem_desc, 0, sizeof(struct cudbg_mem_desc));
  1580. for (j = 0; j < ARRAY_SIZE(meminfo.avail); j++) {
  1581. rc = cudbg_get_mem_region(padap, &meminfo, j,
  1582. cudbg_region[i],
  1583. &mem_desc);
  1584. if (!rc) {
  1585. found = 1;
  1586. rc = cudbg_get_mem_relative(padap, &meminfo, j,
  1587. &mem_desc.base,
  1588. &mem_desc.limit);
  1589. if (rc) {
  1590. ctx_info[i].exist = false;
  1591. break;
  1592. }
  1593. ctx_info[i].exist = true;
  1594. ctx_info[i].start = mem_desc.base;
  1595. ctx_info[i].end = mem_desc.limit;
  1596. mem_type[i] = j;
  1597. break;
  1598. }
  1599. }
  1600. if (!found)
  1601. ctx_info[i].exist = false;
  1602. }
  1603. /* Get FLM and CNM max qid. */
  1604. value = t4_read_reg(padap, SGE_FLM_CFG_A);
  1605. /* Get number of data freelist queues */
  1606. flq = HDRSTARTFLQ_G(value);
  1607. ctx_info[CTXT_FLM].exist = true;
  1608. ctx_info[CTXT_FLM].end = (CUDBG_MAX_FL_QIDS >> flq) * SGE_CTXT_SIZE;
  1609. /* The number of CONM contexts are same as number of freelist
  1610. * queues.
  1611. */
  1612. ctx_info[CTXT_CNM].exist = true;
  1613. ctx_info[CTXT_CNM].end = ctx_info[CTXT_FLM].end;
  1614. return 0;
  1615. }
  1616. int cudbg_dump_context_size(struct adapter *padap)
  1617. {
  1618. struct cudbg_region_info region_info[CTXT_CNM + 1] = { {0} };
  1619. u8 mem_type[CTXT_INGRESS + 1] = { 0 };
  1620. u32 i, size = 0;
  1621. int rc;
  1622. /* Get max valid qid for each type of queue */
  1623. rc = cudbg_get_ctxt_region_info(padap, region_info, mem_type);
  1624. if (rc)
  1625. return rc;
  1626. for (i = 0; i < CTXT_CNM; i++) {
  1627. if (!region_info[i].exist) {
  1628. if (i == CTXT_EGRESS || i == CTXT_INGRESS)
  1629. size += CUDBG_LOWMEM_MAX_CTXT_QIDS *
  1630. SGE_CTXT_SIZE;
  1631. continue;
  1632. }
  1633. size += (region_info[i].end - region_info[i].start + 1) /
  1634. SGE_CTXT_SIZE;
  1635. }
  1636. return size * sizeof(struct cudbg_ch_cntxt);
  1637. }
  1638. static void cudbg_read_sge_ctxt(struct cudbg_init *pdbg_init, u32 cid,
  1639. enum ctxt_type ctype, u32 *data)
  1640. {
  1641. struct adapter *padap = pdbg_init->adap;
  1642. int rc = -1;
  1643. /* Under heavy traffic, the SGE Queue contexts registers will be
  1644. * frequently accessed by firmware.
  1645. *
  1646. * To avoid conflicts with firmware, always ask firmware to fetch
  1647. * the SGE Queue contexts via mailbox. On failure, fallback to
  1648. * accessing hardware registers directly.
  1649. */
  1650. if (is_fw_attached(pdbg_init))
  1651. rc = t4_sge_ctxt_rd(padap, padap->mbox, cid, ctype, data);
  1652. if (rc)
  1653. t4_sge_ctxt_rd_bd(padap, cid, ctype, data);
  1654. }
  1655. static void cudbg_get_sge_ctxt_fw(struct cudbg_init *pdbg_init, u32 max_qid,
  1656. u8 ctxt_type,
  1657. struct cudbg_ch_cntxt **out_buff)
  1658. {
  1659. struct cudbg_ch_cntxt *buff = *out_buff;
  1660. int rc;
  1661. u32 j;
  1662. for (j = 0; j < max_qid; j++) {
  1663. cudbg_read_sge_ctxt(pdbg_init, j, ctxt_type, buff->data);
  1664. rc = cudbg_sge_ctxt_check_valid(buff->data, ctxt_type);
  1665. if (!rc)
  1666. continue;
  1667. buff->cntxt_type = ctxt_type;
  1668. buff->cntxt_id = j;
  1669. buff++;
  1670. if (ctxt_type == CTXT_FLM) {
  1671. cudbg_read_sge_ctxt(pdbg_init, j, CTXT_CNM, buff->data);
  1672. buff->cntxt_type = CTXT_CNM;
  1673. buff->cntxt_id = j;
  1674. buff++;
  1675. }
  1676. }
  1677. *out_buff = buff;
  1678. }
  1679. int cudbg_collect_dump_context(struct cudbg_init *pdbg_init,
  1680. struct cudbg_buffer *dbg_buff,
  1681. struct cudbg_error *cudbg_err)
  1682. {
  1683. struct cudbg_region_info region_info[CTXT_CNM + 1] = { {0} };
  1684. struct adapter *padap = pdbg_init->adap;
  1685. u32 j, size, max_ctx_size, max_ctx_qid;
  1686. u8 mem_type[CTXT_INGRESS + 1] = { 0 };
  1687. struct cudbg_buffer temp_buff = { 0 };
  1688. struct cudbg_ch_cntxt *buff;
  1689. u64 *dst_off, *src_off;
  1690. u8 *ctx_buf;
  1691. u8 i, k;
  1692. int rc;
  1693. /* Get max valid qid for each type of queue */
  1694. rc = cudbg_get_ctxt_region_info(padap, region_info, mem_type);
  1695. if (rc)
  1696. return rc;
  1697. rc = cudbg_dump_context_size(padap);
  1698. if (rc <= 0)
  1699. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  1700. size = rc;
  1701. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1702. if (rc)
  1703. return rc;
  1704. /* Get buffer with enough space to read the biggest context
  1705. * region in memory.
  1706. */
  1707. max_ctx_size = max(region_info[CTXT_EGRESS].end -
  1708. region_info[CTXT_EGRESS].start + 1,
  1709. region_info[CTXT_INGRESS].end -
  1710. region_info[CTXT_INGRESS].start + 1);
  1711. ctx_buf = kvzalloc(max_ctx_size, GFP_KERNEL);
  1712. if (!ctx_buf) {
  1713. cudbg_put_buff(pdbg_init, &temp_buff);
  1714. return -ENOMEM;
  1715. }
  1716. buff = (struct cudbg_ch_cntxt *)temp_buff.data;
  1717. /* Collect EGRESS and INGRESS context data.
  1718. * In case of failures, fallback to collecting via FW or
  1719. * backdoor access.
  1720. */
  1721. for (i = CTXT_EGRESS; i <= CTXT_INGRESS; i++) {
  1722. if (!region_info[i].exist) {
  1723. max_ctx_qid = CUDBG_LOWMEM_MAX_CTXT_QIDS;
  1724. cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, i,
  1725. &buff);
  1726. continue;
  1727. }
  1728. max_ctx_size = region_info[i].end - region_info[i].start + 1;
  1729. max_ctx_qid = max_ctx_size / SGE_CTXT_SIZE;
  1730. /* If firmware is not attached/alive, use backdoor register
  1731. * access to collect dump.
  1732. */
  1733. if (is_fw_attached(pdbg_init)) {
  1734. t4_sge_ctxt_flush(padap, padap->mbox, i);
  1735. rc = t4_memory_rw(padap, MEMWIN_NIC, mem_type[i],
  1736. region_info[i].start, max_ctx_size,
  1737. (__be32 *)ctx_buf, 1);
  1738. }
  1739. if (rc || !is_fw_attached(pdbg_init)) {
  1740. max_ctx_qid = CUDBG_LOWMEM_MAX_CTXT_QIDS;
  1741. cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, i,
  1742. &buff);
  1743. continue;
  1744. }
  1745. for (j = 0; j < max_ctx_qid; j++) {
  1746. src_off = (u64 *)(ctx_buf + j * SGE_CTXT_SIZE);
  1747. dst_off = (u64 *)buff->data;
  1748. /* The data is stored in 64-bit cpu order. Convert it
  1749. * to big endian before parsing.
  1750. */
  1751. for (k = 0; k < SGE_CTXT_SIZE / sizeof(u64); k++)
  1752. dst_off[k] = cpu_to_be64(src_off[k]);
  1753. rc = cudbg_sge_ctxt_check_valid(buff->data, i);
  1754. if (!rc)
  1755. continue;
  1756. buff->cntxt_type = i;
  1757. buff->cntxt_id = j;
  1758. buff++;
  1759. }
  1760. }
  1761. kvfree(ctx_buf);
  1762. /* Collect FREELIST and CONGESTION MANAGER contexts */
  1763. max_ctx_size = region_info[CTXT_FLM].end -
  1764. region_info[CTXT_FLM].start + 1;
  1765. max_ctx_qid = max_ctx_size / SGE_CTXT_SIZE;
  1766. /* Since FLM and CONM are 1-to-1 mapped, the below function
  1767. * will fetch both FLM and CONM contexts.
  1768. */
  1769. cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, CTXT_FLM, &buff);
  1770. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1771. }
  1772. static inline void cudbg_tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
  1773. {
  1774. *mask = x | y;
  1775. y = (__force u64)cpu_to_be64(y);
  1776. memcpy(addr, (char *)&y + 2, ETH_ALEN);
  1777. }
  1778. static void cudbg_mps_rpl_backdoor(struct adapter *padap,
  1779. struct fw_ldst_mps_rplc *mps_rplc)
  1780. {
  1781. if (is_t5(padap->params.chip)) {
  1782. mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
  1783. MPS_VF_RPLCT_MAP3_A));
  1784. mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
  1785. MPS_VF_RPLCT_MAP2_A));
  1786. mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
  1787. MPS_VF_RPLCT_MAP1_A));
  1788. mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
  1789. MPS_VF_RPLCT_MAP0_A));
  1790. } else {
  1791. mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
  1792. MPS_VF_RPLCT_MAP7_A));
  1793. mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
  1794. MPS_VF_RPLCT_MAP6_A));
  1795. mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
  1796. MPS_VF_RPLCT_MAP5_A));
  1797. mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
  1798. MPS_VF_RPLCT_MAP4_A));
  1799. }
  1800. mps_rplc->rplc127_96 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP3_A));
  1801. mps_rplc->rplc95_64 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP2_A));
  1802. mps_rplc->rplc63_32 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP1_A));
  1803. mps_rplc->rplc31_0 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP0_A));
  1804. }
  1805. static int cudbg_collect_tcam_index(struct cudbg_init *pdbg_init,
  1806. struct cudbg_mps_tcam *tcam, u32 idx)
  1807. {
  1808. struct adapter *padap = pdbg_init->adap;
  1809. u64 tcamy, tcamx, val;
  1810. u32 ctl, data2;
  1811. int rc = 0;
  1812. if (CHELSIO_CHIP_VERSION(padap->params.chip) >= CHELSIO_T6) {
  1813. /* CtlReqID - 1: use Host Driver Requester ID
  1814. * CtlCmdType - 0: Read, 1: Write
  1815. * CtlTcamSel - 0: TCAM0, 1: TCAM1
  1816. * CtlXYBitSel- 0: Y bit, 1: X bit
  1817. */
  1818. /* Read tcamy */
  1819. ctl = CTLREQID_V(1) | CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
  1820. if (idx < 256)
  1821. ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
  1822. else
  1823. ctl |= CTLTCAMINDEX_V(idx - 256) | CTLTCAMSEL_V(1);
  1824. t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
  1825. val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
  1826. tcamy = DMACH_G(val) << 32;
  1827. tcamy |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
  1828. data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
  1829. tcam->lookup_type = DATALKPTYPE_G(data2);
  1830. /* 0 - Outer header, 1 - Inner header
  1831. * [71:48] bit locations are overloaded for
  1832. * outer vs. inner lookup types.
  1833. */
  1834. if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
  1835. /* Inner header VNI */
  1836. tcam->vniy = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
  1837. tcam->vniy = (tcam->vniy << 16) | VIDL_G(val);
  1838. tcam->dip_hit = data2 & DATADIPHIT_F;
  1839. } else {
  1840. tcam->vlan_vld = data2 & DATAVIDH2_F;
  1841. tcam->ivlan = VIDL_G(val);
  1842. }
  1843. tcam->port_num = DATAPORTNUM_G(data2);
  1844. /* Read tcamx. Change the control param */
  1845. ctl |= CTLXYBITSEL_V(1);
  1846. t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
  1847. val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
  1848. tcamx = DMACH_G(val) << 32;
  1849. tcamx |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
  1850. data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
  1851. if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
  1852. /* Inner header VNI mask */
  1853. tcam->vnix = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
  1854. tcam->vnix = (tcam->vnix << 16) | VIDL_G(val);
  1855. }
  1856. } else {
  1857. tcamy = t4_read_reg64(padap, MPS_CLS_TCAM_Y_L(idx));
  1858. tcamx = t4_read_reg64(padap, MPS_CLS_TCAM_X_L(idx));
  1859. }
  1860. /* If no entry, return */
  1861. if (tcamx & tcamy)
  1862. return rc;
  1863. tcam->cls_lo = t4_read_reg(padap, MPS_CLS_SRAM_L(idx));
  1864. tcam->cls_hi = t4_read_reg(padap, MPS_CLS_SRAM_H(idx));
  1865. if (is_t5(padap->params.chip))
  1866. tcam->repli = (tcam->cls_lo & REPLICATE_F);
  1867. else if (is_t6(padap->params.chip))
  1868. tcam->repli = (tcam->cls_lo & T6_REPLICATE_F);
  1869. if (tcam->repli) {
  1870. struct fw_ldst_cmd ldst_cmd;
  1871. struct fw_ldst_mps_rplc mps_rplc;
  1872. memset(&ldst_cmd, 0, sizeof(ldst_cmd));
  1873. ldst_cmd.op_to_addrspace =
  1874. htonl(FW_CMD_OP_V(FW_LDST_CMD) |
  1875. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  1876. FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS));
  1877. ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
  1878. ldst_cmd.u.mps.rplc.fid_idx =
  1879. htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
  1880. FW_LDST_CMD_IDX_V(idx));
  1881. /* If firmware is not attached/alive, use backdoor register
  1882. * access to collect dump.
  1883. */
  1884. if (is_fw_attached(pdbg_init))
  1885. rc = t4_wr_mbox(padap, padap->mbox, &ldst_cmd,
  1886. sizeof(ldst_cmd), &ldst_cmd);
  1887. if (rc || !is_fw_attached(pdbg_init)) {
  1888. cudbg_mps_rpl_backdoor(padap, &mps_rplc);
  1889. /* Ignore error since we collected directly from
  1890. * reading registers.
  1891. */
  1892. rc = 0;
  1893. } else {
  1894. mps_rplc = ldst_cmd.u.mps.rplc;
  1895. }
  1896. tcam->rplc[0] = ntohl(mps_rplc.rplc31_0);
  1897. tcam->rplc[1] = ntohl(mps_rplc.rplc63_32);
  1898. tcam->rplc[2] = ntohl(mps_rplc.rplc95_64);
  1899. tcam->rplc[3] = ntohl(mps_rplc.rplc127_96);
  1900. if (padap->params.arch.mps_rplc_size > CUDBG_MAX_RPLC_SIZE) {
  1901. tcam->rplc[4] = ntohl(mps_rplc.rplc159_128);
  1902. tcam->rplc[5] = ntohl(mps_rplc.rplc191_160);
  1903. tcam->rplc[6] = ntohl(mps_rplc.rplc223_192);
  1904. tcam->rplc[7] = ntohl(mps_rplc.rplc255_224);
  1905. }
  1906. }
  1907. cudbg_tcamxy2valmask(tcamx, tcamy, tcam->addr, &tcam->mask);
  1908. tcam->idx = idx;
  1909. tcam->rplc_size = padap->params.arch.mps_rplc_size;
  1910. return rc;
  1911. }
  1912. int cudbg_collect_mps_tcam(struct cudbg_init *pdbg_init,
  1913. struct cudbg_buffer *dbg_buff,
  1914. struct cudbg_error *cudbg_err)
  1915. {
  1916. struct adapter *padap = pdbg_init->adap;
  1917. struct cudbg_buffer temp_buff = { 0 };
  1918. u32 size = 0, i, n, total_size = 0;
  1919. struct cudbg_mps_tcam *tcam;
  1920. int rc;
  1921. n = padap->params.arch.mps_tcam_size;
  1922. size = sizeof(struct cudbg_mps_tcam) * n;
  1923. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1924. if (rc)
  1925. return rc;
  1926. tcam = (struct cudbg_mps_tcam *)temp_buff.data;
  1927. for (i = 0; i < n; i++) {
  1928. rc = cudbg_collect_tcam_index(pdbg_init, tcam, i);
  1929. if (rc) {
  1930. cudbg_err->sys_err = rc;
  1931. cudbg_put_buff(pdbg_init, &temp_buff);
  1932. return rc;
  1933. }
  1934. total_size += sizeof(struct cudbg_mps_tcam);
  1935. tcam++;
  1936. }
  1937. if (!total_size) {
  1938. rc = CUDBG_SYSTEM_ERROR;
  1939. cudbg_err->sys_err = rc;
  1940. cudbg_put_buff(pdbg_init, &temp_buff);
  1941. return rc;
  1942. }
  1943. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1944. }
  1945. int cudbg_collect_vpd_data(struct cudbg_init *pdbg_init,
  1946. struct cudbg_buffer *dbg_buff,
  1947. struct cudbg_error *cudbg_err)
  1948. {
  1949. struct adapter *padap = pdbg_init->adap;
  1950. struct cudbg_buffer temp_buff = { 0 };
  1951. char vpd_str[CUDBG_VPD_VER_LEN + 1];
  1952. u32 scfg_vers, vpd_vers, fw_vers;
  1953. struct cudbg_vpd_data *vpd_data;
  1954. struct vpd_params vpd = { 0 };
  1955. int rc, ret;
  1956. rc = t4_get_raw_vpd_params(padap, &vpd);
  1957. if (rc)
  1958. return rc;
  1959. rc = t4_get_fw_version(padap, &fw_vers);
  1960. if (rc)
  1961. return rc;
  1962. /* Serial Configuration Version is located beyond the PF's vpd size.
  1963. * Temporarily give access to entire EEPROM to get it.
  1964. */
  1965. rc = pci_set_vpd_size(padap->pdev, EEPROMVSIZE);
  1966. if (rc < 0)
  1967. return rc;
  1968. ret = cudbg_read_vpd_reg(padap, CUDBG_SCFG_VER_ADDR, CUDBG_SCFG_VER_LEN,
  1969. &scfg_vers);
  1970. /* Restore back to original PF's vpd size */
  1971. rc = pci_set_vpd_size(padap->pdev, CUDBG_VPD_PF_SIZE);
  1972. if (rc < 0)
  1973. return rc;
  1974. if (ret)
  1975. return ret;
  1976. rc = cudbg_read_vpd_reg(padap, CUDBG_VPD_VER_ADDR, CUDBG_VPD_VER_LEN,
  1977. vpd_str);
  1978. if (rc)
  1979. return rc;
  1980. vpd_str[CUDBG_VPD_VER_LEN] = '\0';
  1981. rc = kstrtouint(vpd_str, 0, &vpd_vers);
  1982. if (rc)
  1983. return rc;
  1984. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_vpd_data),
  1985. &temp_buff);
  1986. if (rc)
  1987. return rc;
  1988. vpd_data = (struct cudbg_vpd_data *)temp_buff.data;
  1989. memcpy(vpd_data->sn, vpd.sn, SERNUM_LEN + 1);
  1990. memcpy(vpd_data->bn, vpd.pn, PN_LEN + 1);
  1991. memcpy(vpd_data->na, vpd.na, MACADDR_LEN + 1);
  1992. memcpy(vpd_data->mn, vpd.id, ID_LEN + 1);
  1993. vpd_data->scfg_vers = scfg_vers;
  1994. vpd_data->vpd_vers = vpd_vers;
  1995. vpd_data->fw_major = FW_HDR_FW_VER_MAJOR_G(fw_vers);
  1996. vpd_data->fw_minor = FW_HDR_FW_VER_MINOR_G(fw_vers);
  1997. vpd_data->fw_micro = FW_HDR_FW_VER_MICRO_G(fw_vers);
  1998. vpd_data->fw_build = FW_HDR_FW_VER_BUILD_G(fw_vers);
  1999. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2000. }
  2001. static int cudbg_read_tid(struct cudbg_init *pdbg_init, u32 tid,
  2002. struct cudbg_tid_data *tid_data)
  2003. {
  2004. struct adapter *padap = pdbg_init->adap;
  2005. int i, cmd_retry = 8;
  2006. u32 val;
  2007. /* Fill REQ_DATA regs with 0's */
  2008. for (i = 0; i < NUM_LE_DB_DBGI_REQ_DATA_INSTANCES; i++)
  2009. t4_write_reg(padap, LE_DB_DBGI_REQ_DATA_A + (i << 2), 0);
  2010. /* Write DBIG command */
  2011. val = DBGICMD_V(4) | DBGITID_V(tid);
  2012. t4_write_reg(padap, LE_DB_DBGI_REQ_TCAM_CMD_A, val);
  2013. tid_data->dbig_cmd = val;
  2014. val = DBGICMDSTRT_F | DBGICMDMODE_V(1); /* LE mode */
  2015. t4_write_reg(padap, LE_DB_DBGI_CONFIG_A, val);
  2016. tid_data->dbig_conf = val;
  2017. /* Poll the DBGICMDBUSY bit */
  2018. val = 1;
  2019. while (val) {
  2020. val = t4_read_reg(padap, LE_DB_DBGI_CONFIG_A);
  2021. val = val & DBGICMDBUSY_F;
  2022. cmd_retry--;
  2023. if (!cmd_retry)
  2024. return CUDBG_SYSTEM_ERROR;
  2025. }
  2026. /* Check RESP status */
  2027. val = t4_read_reg(padap, LE_DB_DBGI_RSP_STATUS_A);
  2028. tid_data->dbig_rsp_stat = val;
  2029. if (!(val & 1))
  2030. return CUDBG_SYSTEM_ERROR;
  2031. /* Read RESP data */
  2032. for (i = 0; i < NUM_LE_DB_DBGI_RSP_DATA_INSTANCES; i++)
  2033. tid_data->data[i] = t4_read_reg(padap,
  2034. LE_DB_DBGI_RSP_DATA_A +
  2035. (i << 2));
  2036. tid_data->tid = tid;
  2037. return 0;
  2038. }
  2039. static int cudbg_get_le_type(u32 tid, struct cudbg_tcam tcam_region)
  2040. {
  2041. int type = LE_ET_UNKNOWN;
  2042. if (tid < tcam_region.server_start)
  2043. type = LE_ET_TCAM_CON;
  2044. else if (tid < tcam_region.filter_start)
  2045. type = LE_ET_TCAM_SERVER;
  2046. else if (tid < tcam_region.clip_start)
  2047. type = LE_ET_TCAM_FILTER;
  2048. else if (tid < tcam_region.routing_start)
  2049. type = LE_ET_TCAM_CLIP;
  2050. else if (tid < tcam_region.tid_hash_base)
  2051. type = LE_ET_TCAM_ROUTING;
  2052. else if (tid < tcam_region.max_tid)
  2053. type = LE_ET_HASH_CON;
  2054. else
  2055. type = LE_ET_INVALID_TID;
  2056. return type;
  2057. }
  2058. static int cudbg_is_ipv6_entry(struct cudbg_tid_data *tid_data,
  2059. struct cudbg_tcam tcam_region)
  2060. {
  2061. int ipv6 = 0;
  2062. int le_type;
  2063. le_type = cudbg_get_le_type(tid_data->tid, tcam_region);
  2064. if (tid_data->tid & 1)
  2065. return 0;
  2066. if (le_type == LE_ET_HASH_CON) {
  2067. ipv6 = tid_data->data[16] & 0x8000;
  2068. } else if (le_type == LE_ET_TCAM_CON) {
  2069. ipv6 = tid_data->data[16] & 0x8000;
  2070. if (ipv6)
  2071. ipv6 = tid_data->data[9] == 0x00C00000;
  2072. } else {
  2073. ipv6 = 0;
  2074. }
  2075. return ipv6;
  2076. }
  2077. void cudbg_fill_le_tcam_info(struct adapter *padap,
  2078. struct cudbg_tcam *tcam_region)
  2079. {
  2080. u32 value;
  2081. /* Get the LE regions */
  2082. value = t4_read_reg(padap, LE_DB_TID_HASHBASE_A); /* hash base index */
  2083. tcam_region->tid_hash_base = value;
  2084. /* Get routing table index */
  2085. value = t4_read_reg(padap, LE_DB_ROUTING_TABLE_INDEX_A);
  2086. tcam_region->routing_start = value;
  2087. /* Get clip table index. For T6 there is separate CLIP TCAM */
  2088. if (is_t6(padap->params.chip))
  2089. value = t4_read_reg(padap, LE_DB_CLCAM_TID_BASE_A);
  2090. else
  2091. value = t4_read_reg(padap, LE_DB_CLIP_TABLE_INDEX_A);
  2092. tcam_region->clip_start = value;
  2093. /* Get filter table index */
  2094. value = t4_read_reg(padap, LE_DB_FILTER_TABLE_INDEX_A);
  2095. tcam_region->filter_start = value;
  2096. /* Get server table index */
  2097. value = t4_read_reg(padap, LE_DB_SERVER_INDEX_A);
  2098. tcam_region->server_start = value;
  2099. /* Check whether hash is enabled and calculate the max tids */
  2100. value = t4_read_reg(padap, LE_DB_CONFIG_A);
  2101. if ((value >> HASHEN_S) & 1) {
  2102. value = t4_read_reg(padap, LE_DB_HASH_CONFIG_A);
  2103. if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5) {
  2104. tcam_region->max_tid = (value & 0xFFFFF) +
  2105. tcam_region->tid_hash_base;
  2106. } else {
  2107. value = HASHTIDSIZE_G(value);
  2108. value = 1 << value;
  2109. tcam_region->max_tid = value +
  2110. tcam_region->tid_hash_base;
  2111. }
  2112. } else { /* hash not enabled */
  2113. if (is_t6(padap->params.chip))
  2114. tcam_region->max_tid = (value & ASLIPCOMPEN_F) ?
  2115. CUDBG_MAX_TID_COMP_EN :
  2116. CUDBG_MAX_TID_COMP_DIS;
  2117. else
  2118. tcam_region->max_tid = CUDBG_MAX_TCAM_TID;
  2119. }
  2120. if (is_t6(padap->params.chip))
  2121. tcam_region->max_tid += CUDBG_T6_CLIP;
  2122. }
  2123. int cudbg_collect_le_tcam(struct cudbg_init *pdbg_init,
  2124. struct cudbg_buffer *dbg_buff,
  2125. struct cudbg_error *cudbg_err)
  2126. {
  2127. struct adapter *padap = pdbg_init->adap;
  2128. struct cudbg_buffer temp_buff = { 0 };
  2129. struct cudbg_tcam tcam_region = { 0 };
  2130. struct cudbg_tid_data *tid_data;
  2131. u32 bytes = 0;
  2132. int rc, size;
  2133. u32 i;
  2134. cudbg_fill_le_tcam_info(padap, &tcam_region);
  2135. size = sizeof(struct cudbg_tid_data) * tcam_region.max_tid;
  2136. size += sizeof(struct cudbg_tcam);
  2137. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2138. if (rc)
  2139. return rc;
  2140. memcpy(temp_buff.data, &tcam_region, sizeof(struct cudbg_tcam));
  2141. bytes = sizeof(struct cudbg_tcam);
  2142. tid_data = (struct cudbg_tid_data *)(temp_buff.data + bytes);
  2143. /* read all tid */
  2144. for (i = 0; i < tcam_region.max_tid; ) {
  2145. rc = cudbg_read_tid(pdbg_init, i, tid_data);
  2146. if (rc) {
  2147. cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
  2148. /* Update tcam header and exit */
  2149. tcam_region.max_tid = i;
  2150. memcpy(temp_buff.data, &tcam_region,
  2151. sizeof(struct cudbg_tcam));
  2152. goto out;
  2153. }
  2154. if (cudbg_is_ipv6_entry(tid_data, tcam_region)) {
  2155. /* T6 CLIP TCAM: ipv6 takes 4 entries */
  2156. if (is_t6(padap->params.chip) &&
  2157. i >= tcam_region.clip_start &&
  2158. i < tcam_region.clip_start + CUDBG_T6_CLIP)
  2159. i += 4;
  2160. else /* Main TCAM: ipv6 takes two tids */
  2161. i += 2;
  2162. } else {
  2163. i++;
  2164. }
  2165. tid_data++;
  2166. bytes += sizeof(struct cudbg_tid_data);
  2167. }
  2168. out:
  2169. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2170. }
  2171. int cudbg_collect_cctrl(struct cudbg_init *pdbg_init,
  2172. struct cudbg_buffer *dbg_buff,
  2173. struct cudbg_error *cudbg_err)
  2174. {
  2175. struct adapter *padap = pdbg_init->adap;
  2176. struct cudbg_buffer temp_buff = { 0 };
  2177. u32 size;
  2178. int rc;
  2179. size = sizeof(u16) * NMTUS * NCCTRL_WIN;
  2180. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2181. if (rc)
  2182. return rc;
  2183. t4_read_cong_tbl(padap, (void *)temp_buff.data);
  2184. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2185. }
  2186. int cudbg_collect_ma_indirect(struct cudbg_init *pdbg_init,
  2187. struct cudbg_buffer *dbg_buff,
  2188. struct cudbg_error *cudbg_err)
  2189. {
  2190. struct adapter *padap = pdbg_init->adap;
  2191. struct cudbg_buffer temp_buff = { 0 };
  2192. struct ireg_buf *ma_indr;
  2193. int i, rc, n;
  2194. u32 size, j;
  2195. if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
  2196. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  2197. n = sizeof(t6_ma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
  2198. size = sizeof(struct ireg_buf) * n * 2;
  2199. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2200. if (rc)
  2201. return rc;
  2202. ma_indr = (struct ireg_buf *)temp_buff.data;
  2203. for (i = 0; i < n; i++) {
  2204. struct ireg_field *ma_fli = &ma_indr->tp_pio;
  2205. u32 *buff = ma_indr->outbuf;
  2206. ma_fli->ireg_addr = t6_ma_ireg_array[i][0];
  2207. ma_fli->ireg_data = t6_ma_ireg_array[i][1];
  2208. ma_fli->ireg_local_offset = t6_ma_ireg_array[i][2];
  2209. ma_fli->ireg_offset_range = t6_ma_ireg_array[i][3];
  2210. t4_read_indirect(padap, ma_fli->ireg_addr, ma_fli->ireg_data,
  2211. buff, ma_fli->ireg_offset_range,
  2212. ma_fli->ireg_local_offset);
  2213. ma_indr++;
  2214. }
  2215. n = sizeof(t6_ma_ireg_array2) / (IREG_NUM_ELEM * sizeof(u32));
  2216. for (i = 0; i < n; i++) {
  2217. struct ireg_field *ma_fli = &ma_indr->tp_pio;
  2218. u32 *buff = ma_indr->outbuf;
  2219. ma_fli->ireg_addr = t6_ma_ireg_array2[i][0];
  2220. ma_fli->ireg_data = t6_ma_ireg_array2[i][1];
  2221. ma_fli->ireg_local_offset = t6_ma_ireg_array2[i][2];
  2222. for (j = 0; j < t6_ma_ireg_array2[i][3]; j++) {
  2223. t4_read_indirect(padap, ma_fli->ireg_addr,
  2224. ma_fli->ireg_data, buff, 1,
  2225. ma_fli->ireg_local_offset);
  2226. buff++;
  2227. ma_fli->ireg_local_offset += 0x20;
  2228. }
  2229. ma_indr++;
  2230. }
  2231. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2232. }
  2233. int cudbg_collect_ulptx_la(struct cudbg_init *pdbg_init,
  2234. struct cudbg_buffer *dbg_buff,
  2235. struct cudbg_error *cudbg_err)
  2236. {
  2237. struct adapter *padap = pdbg_init->adap;
  2238. struct cudbg_buffer temp_buff = { 0 };
  2239. struct cudbg_ulptx_la *ulptx_la_buff;
  2240. u32 i, j;
  2241. int rc;
  2242. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_ulptx_la),
  2243. &temp_buff);
  2244. if (rc)
  2245. return rc;
  2246. ulptx_la_buff = (struct cudbg_ulptx_la *)temp_buff.data;
  2247. for (i = 0; i < CUDBG_NUM_ULPTX; i++) {
  2248. ulptx_la_buff->rdptr[i] = t4_read_reg(padap,
  2249. ULP_TX_LA_RDPTR_0_A +
  2250. 0x10 * i);
  2251. ulptx_la_buff->wrptr[i] = t4_read_reg(padap,
  2252. ULP_TX_LA_WRPTR_0_A +
  2253. 0x10 * i);
  2254. ulptx_la_buff->rddata[i] = t4_read_reg(padap,
  2255. ULP_TX_LA_RDDATA_0_A +
  2256. 0x10 * i);
  2257. for (j = 0; j < CUDBG_NUM_ULPTX_READ; j++)
  2258. ulptx_la_buff->rd_data[i][j] =
  2259. t4_read_reg(padap,
  2260. ULP_TX_LA_RDDATA_0_A + 0x10 * i);
  2261. }
  2262. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2263. }
  2264. int cudbg_collect_up_cim_indirect(struct cudbg_init *pdbg_init,
  2265. struct cudbg_buffer *dbg_buff,
  2266. struct cudbg_error *cudbg_err)
  2267. {
  2268. struct adapter *padap = pdbg_init->adap;
  2269. struct cudbg_buffer temp_buff = { 0 };
  2270. u32 local_offset, local_range;
  2271. struct ireg_buf *up_cim;
  2272. u32 size, j, iter;
  2273. u32 instance = 0;
  2274. int i, rc, n;
  2275. if (is_t5(padap->params.chip))
  2276. n = sizeof(t5_up_cim_reg_array) /
  2277. ((IREG_NUM_ELEM + 1) * sizeof(u32));
  2278. else if (is_t6(padap->params.chip))
  2279. n = sizeof(t6_up_cim_reg_array) /
  2280. ((IREG_NUM_ELEM + 1) * sizeof(u32));
  2281. else
  2282. return CUDBG_STATUS_NOT_IMPLEMENTED;
  2283. size = sizeof(struct ireg_buf) * n;
  2284. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2285. if (rc)
  2286. return rc;
  2287. up_cim = (struct ireg_buf *)temp_buff.data;
  2288. for (i = 0; i < n; i++) {
  2289. struct ireg_field *up_cim_reg = &up_cim->tp_pio;
  2290. u32 *buff = up_cim->outbuf;
  2291. if (is_t5(padap->params.chip)) {
  2292. up_cim_reg->ireg_addr = t5_up_cim_reg_array[i][0];
  2293. up_cim_reg->ireg_data = t5_up_cim_reg_array[i][1];
  2294. up_cim_reg->ireg_local_offset =
  2295. t5_up_cim_reg_array[i][2];
  2296. up_cim_reg->ireg_offset_range =
  2297. t5_up_cim_reg_array[i][3];
  2298. instance = t5_up_cim_reg_array[i][4];
  2299. } else if (is_t6(padap->params.chip)) {
  2300. up_cim_reg->ireg_addr = t6_up_cim_reg_array[i][0];
  2301. up_cim_reg->ireg_data = t6_up_cim_reg_array[i][1];
  2302. up_cim_reg->ireg_local_offset =
  2303. t6_up_cim_reg_array[i][2];
  2304. up_cim_reg->ireg_offset_range =
  2305. t6_up_cim_reg_array[i][3];
  2306. instance = t6_up_cim_reg_array[i][4];
  2307. }
  2308. switch (instance) {
  2309. case NUM_CIM_CTL_TSCH_CHANNEL_INSTANCES:
  2310. iter = up_cim_reg->ireg_offset_range;
  2311. local_offset = 0x120;
  2312. local_range = 1;
  2313. break;
  2314. case NUM_CIM_CTL_TSCH_CHANNEL_TSCH_CLASS_INSTANCES:
  2315. iter = up_cim_reg->ireg_offset_range;
  2316. local_offset = 0x10;
  2317. local_range = 1;
  2318. break;
  2319. default:
  2320. iter = 1;
  2321. local_offset = 0;
  2322. local_range = up_cim_reg->ireg_offset_range;
  2323. break;
  2324. }
  2325. for (j = 0; j < iter; j++, buff++) {
  2326. rc = t4_cim_read(padap,
  2327. up_cim_reg->ireg_local_offset +
  2328. (j * local_offset), local_range, buff);
  2329. if (rc) {
  2330. cudbg_put_buff(pdbg_init, &temp_buff);
  2331. return rc;
  2332. }
  2333. }
  2334. up_cim++;
  2335. }
  2336. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2337. }
  2338. int cudbg_collect_pbt_tables(struct cudbg_init *pdbg_init,
  2339. struct cudbg_buffer *dbg_buff,
  2340. struct cudbg_error *cudbg_err)
  2341. {
  2342. struct adapter *padap = pdbg_init->adap;
  2343. struct cudbg_buffer temp_buff = { 0 };
  2344. struct cudbg_pbt_tables *pbt;
  2345. int i, rc;
  2346. u32 addr;
  2347. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  2348. sizeof(struct cudbg_pbt_tables),
  2349. &temp_buff);
  2350. if (rc)
  2351. return rc;
  2352. pbt = (struct cudbg_pbt_tables *)temp_buff.data;
  2353. /* PBT dynamic entries */
  2354. addr = CUDBG_CHAC_PBT_ADDR;
  2355. for (i = 0; i < CUDBG_PBT_DYNAMIC_ENTRIES; i++) {
  2356. rc = t4_cim_read(padap, addr + (i * 4), 1,
  2357. &pbt->pbt_dynamic[i]);
  2358. if (rc) {
  2359. cudbg_err->sys_err = rc;
  2360. cudbg_put_buff(pdbg_init, &temp_buff);
  2361. return rc;
  2362. }
  2363. }
  2364. /* PBT static entries */
  2365. /* static entries start when bit 6 is set */
  2366. addr = CUDBG_CHAC_PBT_ADDR + (1 << 6);
  2367. for (i = 0; i < CUDBG_PBT_STATIC_ENTRIES; i++) {
  2368. rc = t4_cim_read(padap, addr + (i * 4), 1,
  2369. &pbt->pbt_static[i]);
  2370. if (rc) {
  2371. cudbg_err->sys_err = rc;
  2372. cudbg_put_buff(pdbg_init, &temp_buff);
  2373. return rc;
  2374. }
  2375. }
  2376. /* LRF entries */
  2377. addr = CUDBG_CHAC_PBT_LRF;
  2378. for (i = 0; i < CUDBG_LRF_ENTRIES; i++) {
  2379. rc = t4_cim_read(padap, addr + (i * 4), 1,
  2380. &pbt->lrf_table[i]);
  2381. if (rc) {
  2382. cudbg_err->sys_err = rc;
  2383. cudbg_put_buff(pdbg_init, &temp_buff);
  2384. return rc;
  2385. }
  2386. }
  2387. /* PBT data entries */
  2388. addr = CUDBG_CHAC_PBT_DATA;
  2389. for (i = 0; i < CUDBG_PBT_DATA_ENTRIES; i++) {
  2390. rc = t4_cim_read(padap, addr + (i * 4), 1,
  2391. &pbt->pbt_data[i]);
  2392. if (rc) {
  2393. cudbg_err->sys_err = rc;
  2394. cudbg_put_buff(pdbg_init, &temp_buff);
  2395. return rc;
  2396. }
  2397. }
  2398. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2399. }
  2400. int cudbg_collect_mbox_log(struct cudbg_init *pdbg_init,
  2401. struct cudbg_buffer *dbg_buff,
  2402. struct cudbg_error *cudbg_err)
  2403. {
  2404. struct adapter *padap = pdbg_init->adap;
  2405. struct cudbg_mbox_log *mboxlog = NULL;
  2406. struct cudbg_buffer temp_buff = { 0 };
  2407. struct mbox_cmd_log *log = NULL;
  2408. struct mbox_cmd *entry;
  2409. unsigned int entry_idx;
  2410. u16 mbox_cmds;
  2411. int i, k, rc;
  2412. u64 flit;
  2413. u32 size;
  2414. log = padap->mbox_log;
  2415. mbox_cmds = padap->mbox_log->size;
  2416. size = sizeof(struct cudbg_mbox_log) * mbox_cmds;
  2417. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2418. if (rc)
  2419. return rc;
  2420. mboxlog = (struct cudbg_mbox_log *)temp_buff.data;
  2421. for (k = 0; k < mbox_cmds; k++) {
  2422. entry_idx = log->cursor + k;
  2423. if (entry_idx >= log->size)
  2424. entry_idx -= log->size;
  2425. entry = mbox_cmd_log_entry(log, entry_idx);
  2426. /* skip over unused entries */
  2427. if (entry->timestamp == 0)
  2428. continue;
  2429. memcpy(&mboxlog->entry, entry, sizeof(struct mbox_cmd));
  2430. for (i = 0; i < MBOX_LEN / 8; i++) {
  2431. flit = entry->cmd[i];
  2432. mboxlog->hi[i] = (u32)(flit >> 32);
  2433. mboxlog->lo[i] = (u32)flit;
  2434. }
  2435. mboxlog++;
  2436. }
  2437. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2438. }
  2439. int cudbg_collect_hma_indirect(struct cudbg_init *pdbg_init,
  2440. struct cudbg_buffer *dbg_buff,
  2441. struct cudbg_error *cudbg_err)
  2442. {
  2443. struct adapter *padap = pdbg_init->adap;
  2444. struct cudbg_buffer temp_buff = { 0 };
  2445. struct ireg_buf *hma_indr;
  2446. int i, rc, n;
  2447. u32 size;
  2448. if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
  2449. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  2450. n = sizeof(t6_hma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
  2451. size = sizeof(struct ireg_buf) * n;
  2452. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2453. if (rc)
  2454. return rc;
  2455. hma_indr = (struct ireg_buf *)temp_buff.data;
  2456. for (i = 0; i < n; i++) {
  2457. struct ireg_field *hma_fli = &hma_indr->tp_pio;
  2458. u32 *buff = hma_indr->outbuf;
  2459. hma_fli->ireg_addr = t6_hma_ireg_array[i][0];
  2460. hma_fli->ireg_data = t6_hma_ireg_array[i][1];
  2461. hma_fli->ireg_local_offset = t6_hma_ireg_array[i][2];
  2462. hma_fli->ireg_offset_range = t6_hma_ireg_array[i][3];
  2463. t4_read_indirect(padap, hma_fli->ireg_addr, hma_fli->ireg_data,
  2464. buff, hma_fli->ireg_offset_range,
  2465. hma_fli->ireg_local_offset);
  2466. hma_indr++;
  2467. }
  2468. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2469. }