cudbg_lib.c 80 KB

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