cudbg_lib.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892
  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 int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,
  923. struct cudbg_buffer *dbg_buff,
  924. struct cudbg_error *cudbg_err,
  925. u8 mem_type)
  926. {
  927. struct adapter *padap = pdbg_init->adap;
  928. struct cudbg_meminfo mem_info;
  929. unsigned long size;
  930. u8 mc_idx;
  931. int rc;
  932. memset(&mem_info, 0, sizeof(struct cudbg_meminfo));
  933. rc = cudbg_fill_meminfo(padap, &mem_info);
  934. if (rc)
  935. return rc;
  936. cudbg_t4_fwcache(pdbg_init, cudbg_err);
  937. rc = cudbg_meminfo_get_mem_index(padap, &mem_info, mem_type, &mc_idx);
  938. if (rc)
  939. return rc;
  940. size = mem_info.avail[mc_idx].limit - mem_info.avail[mc_idx].base;
  941. return cudbg_read_fw_mem(pdbg_init, dbg_buff, mem_type, size,
  942. cudbg_err);
  943. }
  944. int cudbg_collect_edc0_meminfo(struct cudbg_init *pdbg_init,
  945. struct cudbg_buffer *dbg_buff,
  946. struct cudbg_error *cudbg_err)
  947. {
  948. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  949. MEM_EDC0);
  950. }
  951. int cudbg_collect_edc1_meminfo(struct cudbg_init *pdbg_init,
  952. struct cudbg_buffer *dbg_buff,
  953. struct cudbg_error *cudbg_err)
  954. {
  955. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  956. MEM_EDC1);
  957. }
  958. int cudbg_collect_mc0_meminfo(struct cudbg_init *pdbg_init,
  959. struct cudbg_buffer *dbg_buff,
  960. struct cudbg_error *cudbg_err)
  961. {
  962. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  963. MEM_MC0);
  964. }
  965. int cudbg_collect_mc1_meminfo(struct cudbg_init *pdbg_init,
  966. struct cudbg_buffer *dbg_buff,
  967. struct cudbg_error *cudbg_err)
  968. {
  969. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  970. MEM_MC1);
  971. }
  972. int cudbg_collect_hma_meminfo(struct cudbg_init *pdbg_init,
  973. struct cudbg_buffer *dbg_buff,
  974. struct cudbg_error *cudbg_err)
  975. {
  976. return cudbg_collect_mem_region(pdbg_init, dbg_buff, cudbg_err,
  977. MEM_HMA);
  978. }
  979. int cudbg_collect_rss(struct cudbg_init *pdbg_init,
  980. struct cudbg_buffer *dbg_buff,
  981. struct cudbg_error *cudbg_err)
  982. {
  983. struct adapter *padap = pdbg_init->adap;
  984. struct cudbg_buffer temp_buff = { 0 };
  985. int rc, nentries;
  986. nentries = t4_chip_rss_size(padap);
  987. rc = cudbg_get_buff(pdbg_init, dbg_buff, nentries * sizeof(u16),
  988. &temp_buff);
  989. if (rc)
  990. return rc;
  991. rc = t4_read_rss(padap, (u16 *)temp_buff.data);
  992. if (rc) {
  993. cudbg_err->sys_err = rc;
  994. cudbg_put_buff(pdbg_init, &temp_buff);
  995. return rc;
  996. }
  997. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  998. }
  999. int cudbg_collect_rss_vf_config(struct cudbg_init *pdbg_init,
  1000. struct cudbg_buffer *dbg_buff,
  1001. struct cudbg_error *cudbg_err)
  1002. {
  1003. struct adapter *padap = pdbg_init->adap;
  1004. struct cudbg_buffer temp_buff = { 0 };
  1005. struct cudbg_rss_vf_conf *vfconf;
  1006. int vf, rc, vf_count;
  1007. vf_count = padap->params.arch.vfcount;
  1008. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  1009. vf_count * sizeof(struct cudbg_rss_vf_conf),
  1010. &temp_buff);
  1011. if (rc)
  1012. return rc;
  1013. vfconf = (struct cudbg_rss_vf_conf *)temp_buff.data;
  1014. for (vf = 0; vf < vf_count; vf++)
  1015. t4_read_rss_vf_config(padap, vf, &vfconf[vf].rss_vf_vfl,
  1016. &vfconf[vf].rss_vf_vfh, true);
  1017. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1018. }
  1019. int cudbg_collect_path_mtu(struct cudbg_init *pdbg_init,
  1020. struct cudbg_buffer *dbg_buff,
  1021. struct cudbg_error *cudbg_err)
  1022. {
  1023. struct adapter *padap = pdbg_init->adap;
  1024. struct cudbg_buffer temp_buff = { 0 };
  1025. int rc;
  1026. rc = cudbg_get_buff(pdbg_init, dbg_buff, NMTUS * sizeof(u16),
  1027. &temp_buff);
  1028. if (rc)
  1029. return rc;
  1030. t4_read_mtu_tbl(padap, (u16 *)temp_buff.data, NULL);
  1031. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1032. }
  1033. int cudbg_collect_pm_stats(struct cudbg_init *pdbg_init,
  1034. struct cudbg_buffer *dbg_buff,
  1035. struct cudbg_error *cudbg_err)
  1036. {
  1037. struct adapter *padap = pdbg_init->adap;
  1038. struct cudbg_buffer temp_buff = { 0 };
  1039. struct cudbg_pm_stats *pm_stats_buff;
  1040. int rc;
  1041. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_pm_stats),
  1042. &temp_buff);
  1043. if (rc)
  1044. return rc;
  1045. pm_stats_buff = (struct cudbg_pm_stats *)temp_buff.data;
  1046. t4_pmtx_get_stats(padap, pm_stats_buff->tx_cnt, pm_stats_buff->tx_cyc);
  1047. t4_pmrx_get_stats(padap, pm_stats_buff->rx_cnt, pm_stats_buff->rx_cyc);
  1048. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1049. }
  1050. int cudbg_collect_hw_sched(struct cudbg_init *pdbg_init,
  1051. struct cudbg_buffer *dbg_buff,
  1052. struct cudbg_error *cudbg_err)
  1053. {
  1054. struct adapter *padap = pdbg_init->adap;
  1055. struct cudbg_buffer temp_buff = { 0 };
  1056. struct cudbg_hw_sched *hw_sched_buff;
  1057. int i, rc = 0;
  1058. if (!padap->params.vpd.cclk)
  1059. return CUDBG_STATUS_CCLK_NOT_DEFINED;
  1060. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_hw_sched),
  1061. &temp_buff);
  1062. hw_sched_buff = (struct cudbg_hw_sched *)temp_buff.data;
  1063. hw_sched_buff->map = t4_read_reg(padap, TP_TX_MOD_QUEUE_REQ_MAP_A);
  1064. hw_sched_buff->mode = TIMERMODE_G(t4_read_reg(padap, TP_MOD_CONFIG_A));
  1065. t4_read_pace_tbl(padap, hw_sched_buff->pace_tab);
  1066. for (i = 0; i < NTX_SCHED; ++i)
  1067. t4_get_tx_sched(padap, i, &hw_sched_buff->kbps[i],
  1068. &hw_sched_buff->ipg[i], true);
  1069. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1070. }
  1071. int cudbg_collect_tp_indirect(struct cudbg_init *pdbg_init,
  1072. struct cudbg_buffer *dbg_buff,
  1073. struct cudbg_error *cudbg_err)
  1074. {
  1075. struct adapter *padap = pdbg_init->adap;
  1076. struct cudbg_buffer temp_buff = { 0 };
  1077. struct ireg_buf *ch_tp_pio;
  1078. int i, rc, n = 0;
  1079. u32 size;
  1080. if (is_t5(padap->params.chip))
  1081. n = sizeof(t5_tp_pio_array) +
  1082. sizeof(t5_tp_tm_pio_array) +
  1083. sizeof(t5_tp_mib_index_array);
  1084. else
  1085. n = sizeof(t6_tp_pio_array) +
  1086. sizeof(t6_tp_tm_pio_array) +
  1087. sizeof(t6_tp_mib_index_array);
  1088. n = n / (IREG_NUM_ELEM * sizeof(u32));
  1089. size = sizeof(struct ireg_buf) * n;
  1090. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1091. if (rc)
  1092. return rc;
  1093. ch_tp_pio = (struct ireg_buf *)temp_buff.data;
  1094. /* TP_PIO */
  1095. if (is_t5(padap->params.chip))
  1096. n = sizeof(t5_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
  1097. else if (is_t6(padap->params.chip))
  1098. n = sizeof(t6_tp_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
  1099. for (i = 0; i < n; i++) {
  1100. struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
  1101. u32 *buff = ch_tp_pio->outbuf;
  1102. if (is_t5(padap->params.chip)) {
  1103. tp_pio->ireg_addr = t5_tp_pio_array[i][0];
  1104. tp_pio->ireg_data = t5_tp_pio_array[i][1];
  1105. tp_pio->ireg_local_offset = t5_tp_pio_array[i][2];
  1106. tp_pio->ireg_offset_range = t5_tp_pio_array[i][3];
  1107. } else if (is_t6(padap->params.chip)) {
  1108. tp_pio->ireg_addr = t6_tp_pio_array[i][0];
  1109. tp_pio->ireg_data = t6_tp_pio_array[i][1];
  1110. tp_pio->ireg_local_offset = t6_tp_pio_array[i][2];
  1111. tp_pio->ireg_offset_range = t6_tp_pio_array[i][3];
  1112. }
  1113. t4_tp_pio_read(padap, buff, tp_pio->ireg_offset_range,
  1114. tp_pio->ireg_local_offset, true);
  1115. ch_tp_pio++;
  1116. }
  1117. /* TP_TM_PIO */
  1118. if (is_t5(padap->params.chip))
  1119. n = sizeof(t5_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
  1120. else if (is_t6(padap->params.chip))
  1121. n = sizeof(t6_tp_tm_pio_array) / (IREG_NUM_ELEM * sizeof(u32));
  1122. for (i = 0; i < n; i++) {
  1123. struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
  1124. u32 *buff = ch_tp_pio->outbuf;
  1125. if (is_t5(padap->params.chip)) {
  1126. tp_pio->ireg_addr = t5_tp_tm_pio_array[i][0];
  1127. tp_pio->ireg_data = t5_tp_tm_pio_array[i][1];
  1128. tp_pio->ireg_local_offset = t5_tp_tm_pio_array[i][2];
  1129. tp_pio->ireg_offset_range = t5_tp_tm_pio_array[i][3];
  1130. } else if (is_t6(padap->params.chip)) {
  1131. tp_pio->ireg_addr = t6_tp_tm_pio_array[i][0];
  1132. tp_pio->ireg_data = t6_tp_tm_pio_array[i][1];
  1133. tp_pio->ireg_local_offset = t6_tp_tm_pio_array[i][2];
  1134. tp_pio->ireg_offset_range = t6_tp_tm_pio_array[i][3];
  1135. }
  1136. t4_tp_tm_pio_read(padap, buff, tp_pio->ireg_offset_range,
  1137. tp_pio->ireg_local_offset, true);
  1138. ch_tp_pio++;
  1139. }
  1140. /* TP_MIB_INDEX */
  1141. if (is_t5(padap->params.chip))
  1142. n = sizeof(t5_tp_mib_index_array) /
  1143. (IREG_NUM_ELEM * sizeof(u32));
  1144. else if (is_t6(padap->params.chip))
  1145. n = sizeof(t6_tp_mib_index_array) /
  1146. (IREG_NUM_ELEM * sizeof(u32));
  1147. for (i = 0; i < n ; i++) {
  1148. struct ireg_field *tp_pio = &ch_tp_pio->tp_pio;
  1149. u32 *buff = ch_tp_pio->outbuf;
  1150. if (is_t5(padap->params.chip)) {
  1151. tp_pio->ireg_addr = t5_tp_mib_index_array[i][0];
  1152. tp_pio->ireg_data = t5_tp_mib_index_array[i][1];
  1153. tp_pio->ireg_local_offset =
  1154. t5_tp_mib_index_array[i][2];
  1155. tp_pio->ireg_offset_range =
  1156. t5_tp_mib_index_array[i][3];
  1157. } else if (is_t6(padap->params.chip)) {
  1158. tp_pio->ireg_addr = t6_tp_mib_index_array[i][0];
  1159. tp_pio->ireg_data = t6_tp_mib_index_array[i][1];
  1160. tp_pio->ireg_local_offset =
  1161. t6_tp_mib_index_array[i][2];
  1162. tp_pio->ireg_offset_range =
  1163. t6_tp_mib_index_array[i][3];
  1164. }
  1165. t4_tp_mib_read(padap, buff, tp_pio->ireg_offset_range,
  1166. tp_pio->ireg_local_offset, true);
  1167. ch_tp_pio++;
  1168. }
  1169. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1170. }
  1171. static void cudbg_read_sge_qbase_indirect_reg(struct adapter *padap,
  1172. struct sge_qbase_reg_field *qbase,
  1173. u32 func, bool is_pf)
  1174. {
  1175. u32 *buff, i;
  1176. if (is_pf) {
  1177. buff = qbase->pf_data_value[func];
  1178. } else {
  1179. buff = qbase->vf_data_value[func];
  1180. /* In SGE_QBASE_INDEX,
  1181. * Entries 0->7 are PF0->7, Entries 8->263 are VFID0->256.
  1182. */
  1183. func += 8;
  1184. }
  1185. t4_write_reg(padap, qbase->reg_addr, func);
  1186. for (i = 0; i < SGE_QBASE_DATA_REG_NUM; i++, buff++)
  1187. *buff = t4_read_reg(padap, qbase->reg_data[i]);
  1188. }
  1189. int cudbg_collect_sge_indirect(struct cudbg_init *pdbg_init,
  1190. struct cudbg_buffer *dbg_buff,
  1191. struct cudbg_error *cudbg_err)
  1192. {
  1193. struct adapter *padap = pdbg_init->adap;
  1194. struct cudbg_buffer temp_buff = { 0 };
  1195. struct sge_qbase_reg_field *sge_qbase;
  1196. struct ireg_buf *ch_sge_dbg;
  1197. int i, rc;
  1198. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  1199. sizeof(*ch_sge_dbg) * 2 + sizeof(*sge_qbase),
  1200. &temp_buff);
  1201. if (rc)
  1202. return rc;
  1203. ch_sge_dbg = (struct ireg_buf *)temp_buff.data;
  1204. for (i = 0; i < 2; i++) {
  1205. struct ireg_field *sge_pio = &ch_sge_dbg->tp_pio;
  1206. u32 *buff = ch_sge_dbg->outbuf;
  1207. sge_pio->ireg_addr = t5_sge_dbg_index_array[i][0];
  1208. sge_pio->ireg_data = t5_sge_dbg_index_array[i][1];
  1209. sge_pio->ireg_local_offset = t5_sge_dbg_index_array[i][2];
  1210. sge_pio->ireg_offset_range = t5_sge_dbg_index_array[i][3];
  1211. t4_read_indirect(padap,
  1212. sge_pio->ireg_addr,
  1213. sge_pio->ireg_data,
  1214. buff,
  1215. sge_pio->ireg_offset_range,
  1216. sge_pio->ireg_local_offset);
  1217. ch_sge_dbg++;
  1218. }
  1219. if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5) {
  1220. sge_qbase = (struct sge_qbase_reg_field *)ch_sge_dbg;
  1221. /* 1 addr reg SGE_QBASE_INDEX and 4 data reg
  1222. * SGE_QBASE_MAP[0-3]
  1223. */
  1224. sge_qbase->reg_addr = t6_sge_qbase_index_array[0];
  1225. for (i = 0; i < SGE_QBASE_DATA_REG_NUM; i++)
  1226. sge_qbase->reg_data[i] =
  1227. t6_sge_qbase_index_array[i + 1];
  1228. for (i = 0; i <= PCIE_FW_MASTER_M; i++)
  1229. cudbg_read_sge_qbase_indirect_reg(padap, sge_qbase,
  1230. i, true);
  1231. for (i = 0; i < padap->params.arch.vfcount; i++)
  1232. cudbg_read_sge_qbase_indirect_reg(padap, sge_qbase,
  1233. i, false);
  1234. sge_qbase->vfcount = padap->params.arch.vfcount;
  1235. }
  1236. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1237. }
  1238. int cudbg_collect_ulprx_la(struct cudbg_init *pdbg_init,
  1239. struct cudbg_buffer *dbg_buff,
  1240. struct cudbg_error *cudbg_err)
  1241. {
  1242. struct adapter *padap = pdbg_init->adap;
  1243. struct cudbg_buffer temp_buff = { 0 };
  1244. struct cudbg_ulprx_la *ulprx_la_buff;
  1245. int rc;
  1246. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_ulprx_la),
  1247. &temp_buff);
  1248. if (rc)
  1249. return rc;
  1250. ulprx_la_buff = (struct cudbg_ulprx_la *)temp_buff.data;
  1251. t4_ulprx_read_la(padap, (u32 *)ulprx_la_buff->data);
  1252. ulprx_la_buff->size = ULPRX_LA_SIZE;
  1253. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1254. }
  1255. int cudbg_collect_tp_la(struct cudbg_init *pdbg_init,
  1256. struct cudbg_buffer *dbg_buff,
  1257. struct cudbg_error *cudbg_err)
  1258. {
  1259. struct adapter *padap = pdbg_init->adap;
  1260. struct cudbg_buffer temp_buff = { 0 };
  1261. struct cudbg_tp_la *tp_la_buff;
  1262. int size, rc;
  1263. size = sizeof(struct cudbg_tp_la) + TPLA_SIZE * sizeof(u64);
  1264. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1265. if (rc)
  1266. return rc;
  1267. tp_la_buff = (struct cudbg_tp_la *)temp_buff.data;
  1268. tp_la_buff->mode = DBGLAMODE_G(t4_read_reg(padap, TP_DBG_LA_CONFIG_A));
  1269. t4_tp_read_la(padap, (u64 *)tp_la_buff->data, NULL);
  1270. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1271. }
  1272. int cudbg_collect_meminfo(struct cudbg_init *pdbg_init,
  1273. struct cudbg_buffer *dbg_buff,
  1274. struct cudbg_error *cudbg_err)
  1275. {
  1276. struct adapter *padap = pdbg_init->adap;
  1277. struct cudbg_buffer temp_buff = { 0 };
  1278. struct cudbg_meminfo *meminfo_buff;
  1279. struct cudbg_ver_hdr *ver_hdr;
  1280. int rc;
  1281. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  1282. sizeof(struct cudbg_ver_hdr) +
  1283. sizeof(struct cudbg_meminfo),
  1284. &temp_buff);
  1285. if (rc)
  1286. return rc;
  1287. ver_hdr = (struct cudbg_ver_hdr *)temp_buff.data;
  1288. ver_hdr->signature = CUDBG_ENTITY_SIGNATURE;
  1289. ver_hdr->revision = CUDBG_MEMINFO_REV;
  1290. ver_hdr->size = sizeof(struct cudbg_meminfo);
  1291. meminfo_buff = (struct cudbg_meminfo *)(temp_buff.data +
  1292. sizeof(*ver_hdr));
  1293. rc = cudbg_fill_meminfo(padap, meminfo_buff);
  1294. if (rc) {
  1295. cudbg_err->sys_err = rc;
  1296. cudbg_put_buff(pdbg_init, &temp_buff);
  1297. return rc;
  1298. }
  1299. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1300. }
  1301. int cudbg_collect_cim_pif_la(struct cudbg_init *pdbg_init,
  1302. struct cudbg_buffer *dbg_buff,
  1303. struct cudbg_error *cudbg_err)
  1304. {
  1305. struct cudbg_cim_pif_la *cim_pif_la_buff;
  1306. struct adapter *padap = pdbg_init->adap;
  1307. struct cudbg_buffer temp_buff = { 0 };
  1308. int size, rc;
  1309. size = sizeof(struct cudbg_cim_pif_la) +
  1310. 2 * CIM_PIFLA_SIZE * 6 * sizeof(u32);
  1311. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1312. if (rc)
  1313. return rc;
  1314. cim_pif_la_buff = (struct cudbg_cim_pif_la *)temp_buff.data;
  1315. cim_pif_la_buff->size = CIM_PIFLA_SIZE;
  1316. t4_cim_read_pif_la(padap, (u32 *)cim_pif_la_buff->data,
  1317. (u32 *)cim_pif_la_buff->data + 6 * CIM_PIFLA_SIZE,
  1318. NULL, NULL);
  1319. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1320. }
  1321. int cudbg_collect_clk_info(struct cudbg_init *pdbg_init,
  1322. struct cudbg_buffer *dbg_buff,
  1323. struct cudbg_error *cudbg_err)
  1324. {
  1325. struct adapter *padap = pdbg_init->adap;
  1326. struct cudbg_buffer temp_buff = { 0 };
  1327. struct cudbg_clk_info *clk_info_buff;
  1328. u64 tp_tick_us;
  1329. int rc;
  1330. if (!padap->params.vpd.cclk)
  1331. return CUDBG_STATUS_CCLK_NOT_DEFINED;
  1332. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_clk_info),
  1333. &temp_buff);
  1334. if (rc)
  1335. return rc;
  1336. clk_info_buff = (struct cudbg_clk_info *)temp_buff.data;
  1337. clk_info_buff->cclk_ps = 1000000000 / padap->params.vpd.cclk; /* psec */
  1338. clk_info_buff->res = t4_read_reg(padap, TP_TIMER_RESOLUTION_A);
  1339. clk_info_buff->tre = TIMERRESOLUTION_G(clk_info_buff->res);
  1340. clk_info_buff->dack_re = DELAYEDACKRESOLUTION_G(clk_info_buff->res);
  1341. tp_tick_us = (clk_info_buff->cclk_ps << clk_info_buff->tre) / 1000000;
  1342. clk_info_buff->dack_timer =
  1343. (clk_info_buff->cclk_ps << clk_info_buff->dack_re) / 1000000 *
  1344. t4_read_reg(padap, TP_DACK_TIMER_A);
  1345. clk_info_buff->retransmit_min =
  1346. tp_tick_us * t4_read_reg(padap, TP_RXT_MIN_A);
  1347. clk_info_buff->retransmit_max =
  1348. tp_tick_us * t4_read_reg(padap, TP_RXT_MAX_A);
  1349. clk_info_buff->persist_timer_min =
  1350. tp_tick_us * t4_read_reg(padap, TP_PERS_MIN_A);
  1351. clk_info_buff->persist_timer_max =
  1352. tp_tick_us * t4_read_reg(padap, TP_PERS_MAX_A);
  1353. clk_info_buff->keepalive_idle_timer =
  1354. tp_tick_us * t4_read_reg(padap, TP_KEEP_IDLE_A);
  1355. clk_info_buff->keepalive_interval =
  1356. tp_tick_us * t4_read_reg(padap, TP_KEEP_INTVL_A);
  1357. clk_info_buff->initial_srtt =
  1358. tp_tick_us * INITSRTT_G(t4_read_reg(padap, TP_INIT_SRTT_A));
  1359. clk_info_buff->finwait2_timer =
  1360. tp_tick_us * t4_read_reg(padap, TP_FINWAIT2_TIMER_A);
  1361. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1362. }
  1363. int cudbg_collect_pcie_indirect(struct cudbg_init *pdbg_init,
  1364. struct cudbg_buffer *dbg_buff,
  1365. struct cudbg_error *cudbg_err)
  1366. {
  1367. struct adapter *padap = pdbg_init->adap;
  1368. struct cudbg_buffer temp_buff = { 0 };
  1369. struct ireg_buf *ch_pcie;
  1370. int i, rc, n;
  1371. u32 size;
  1372. n = sizeof(t5_pcie_pdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
  1373. size = sizeof(struct ireg_buf) * n * 2;
  1374. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1375. if (rc)
  1376. return rc;
  1377. ch_pcie = (struct ireg_buf *)temp_buff.data;
  1378. /* PCIE_PDBG */
  1379. for (i = 0; i < n; i++) {
  1380. struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
  1381. u32 *buff = ch_pcie->outbuf;
  1382. pcie_pio->ireg_addr = t5_pcie_pdbg_array[i][0];
  1383. pcie_pio->ireg_data = t5_pcie_pdbg_array[i][1];
  1384. pcie_pio->ireg_local_offset = t5_pcie_pdbg_array[i][2];
  1385. pcie_pio->ireg_offset_range = t5_pcie_pdbg_array[i][3];
  1386. t4_read_indirect(padap,
  1387. pcie_pio->ireg_addr,
  1388. pcie_pio->ireg_data,
  1389. buff,
  1390. pcie_pio->ireg_offset_range,
  1391. pcie_pio->ireg_local_offset);
  1392. ch_pcie++;
  1393. }
  1394. /* PCIE_CDBG */
  1395. n = sizeof(t5_pcie_cdbg_array) / (IREG_NUM_ELEM * sizeof(u32));
  1396. for (i = 0; i < n; i++) {
  1397. struct ireg_field *pcie_pio = &ch_pcie->tp_pio;
  1398. u32 *buff = ch_pcie->outbuf;
  1399. pcie_pio->ireg_addr = t5_pcie_cdbg_array[i][0];
  1400. pcie_pio->ireg_data = t5_pcie_cdbg_array[i][1];
  1401. pcie_pio->ireg_local_offset = t5_pcie_cdbg_array[i][2];
  1402. pcie_pio->ireg_offset_range = t5_pcie_cdbg_array[i][3];
  1403. t4_read_indirect(padap,
  1404. pcie_pio->ireg_addr,
  1405. pcie_pio->ireg_data,
  1406. buff,
  1407. pcie_pio->ireg_offset_range,
  1408. pcie_pio->ireg_local_offset);
  1409. ch_pcie++;
  1410. }
  1411. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1412. }
  1413. int cudbg_collect_pm_indirect(struct cudbg_init *pdbg_init,
  1414. struct cudbg_buffer *dbg_buff,
  1415. struct cudbg_error *cudbg_err)
  1416. {
  1417. struct adapter *padap = pdbg_init->adap;
  1418. struct cudbg_buffer temp_buff = { 0 };
  1419. struct ireg_buf *ch_pm;
  1420. int i, rc, n;
  1421. u32 size;
  1422. n = sizeof(t5_pm_rx_array) / (IREG_NUM_ELEM * sizeof(u32));
  1423. size = sizeof(struct ireg_buf) * n * 2;
  1424. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1425. if (rc)
  1426. return rc;
  1427. ch_pm = (struct ireg_buf *)temp_buff.data;
  1428. /* PM_RX */
  1429. for (i = 0; i < n; i++) {
  1430. struct ireg_field *pm_pio = &ch_pm->tp_pio;
  1431. u32 *buff = ch_pm->outbuf;
  1432. pm_pio->ireg_addr = t5_pm_rx_array[i][0];
  1433. pm_pio->ireg_data = t5_pm_rx_array[i][1];
  1434. pm_pio->ireg_local_offset = t5_pm_rx_array[i][2];
  1435. pm_pio->ireg_offset_range = t5_pm_rx_array[i][3];
  1436. t4_read_indirect(padap,
  1437. pm_pio->ireg_addr,
  1438. pm_pio->ireg_data,
  1439. buff,
  1440. pm_pio->ireg_offset_range,
  1441. pm_pio->ireg_local_offset);
  1442. ch_pm++;
  1443. }
  1444. /* PM_TX */
  1445. n = sizeof(t5_pm_tx_array) / (IREG_NUM_ELEM * sizeof(u32));
  1446. for (i = 0; i < n; i++) {
  1447. struct ireg_field *pm_pio = &ch_pm->tp_pio;
  1448. u32 *buff = ch_pm->outbuf;
  1449. pm_pio->ireg_addr = t5_pm_tx_array[i][0];
  1450. pm_pio->ireg_data = t5_pm_tx_array[i][1];
  1451. pm_pio->ireg_local_offset = t5_pm_tx_array[i][2];
  1452. pm_pio->ireg_offset_range = t5_pm_tx_array[i][3];
  1453. t4_read_indirect(padap,
  1454. pm_pio->ireg_addr,
  1455. pm_pio->ireg_data,
  1456. buff,
  1457. pm_pio->ireg_offset_range,
  1458. pm_pio->ireg_local_offset);
  1459. ch_pm++;
  1460. }
  1461. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1462. }
  1463. int cudbg_collect_tid(struct cudbg_init *pdbg_init,
  1464. struct cudbg_buffer *dbg_buff,
  1465. struct cudbg_error *cudbg_err)
  1466. {
  1467. struct adapter *padap = pdbg_init->adap;
  1468. struct cudbg_tid_info_region_rev1 *tid1;
  1469. struct cudbg_buffer temp_buff = { 0 };
  1470. struct cudbg_tid_info_region *tid;
  1471. u32 para[2], val[2];
  1472. int rc;
  1473. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  1474. sizeof(struct cudbg_tid_info_region_rev1),
  1475. &temp_buff);
  1476. if (rc)
  1477. return rc;
  1478. tid1 = (struct cudbg_tid_info_region_rev1 *)temp_buff.data;
  1479. tid = &tid1->tid;
  1480. tid1->ver_hdr.signature = CUDBG_ENTITY_SIGNATURE;
  1481. tid1->ver_hdr.revision = CUDBG_TID_INFO_REV;
  1482. tid1->ver_hdr.size = sizeof(struct cudbg_tid_info_region_rev1) -
  1483. sizeof(struct cudbg_ver_hdr);
  1484. /* If firmware is not attached/alive, use backdoor register
  1485. * access to collect dump.
  1486. */
  1487. if (!is_fw_attached(pdbg_init))
  1488. goto fill_tid;
  1489. #define FW_PARAM_PFVF_A(param) \
  1490. (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
  1491. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param) | \
  1492. FW_PARAMS_PARAM_Y_V(0) | \
  1493. FW_PARAMS_PARAM_Z_V(0))
  1494. para[0] = FW_PARAM_PFVF_A(ETHOFLD_START);
  1495. para[1] = FW_PARAM_PFVF_A(ETHOFLD_END);
  1496. rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2, para, val);
  1497. if (rc < 0) {
  1498. cudbg_err->sys_err = rc;
  1499. cudbg_put_buff(pdbg_init, &temp_buff);
  1500. return rc;
  1501. }
  1502. tid->uotid_base = val[0];
  1503. tid->nuotids = val[1] - val[0] + 1;
  1504. if (is_t5(padap->params.chip)) {
  1505. tid->sb = t4_read_reg(padap, LE_DB_SERVER_INDEX_A) / 4;
  1506. } else if (is_t6(padap->params.chip)) {
  1507. tid1->tid_start =
  1508. t4_read_reg(padap, LE_DB_ACTIVE_TABLE_START_INDEX_A);
  1509. tid->sb = t4_read_reg(padap, LE_DB_SRVR_START_INDEX_A);
  1510. para[0] = FW_PARAM_PFVF_A(HPFILTER_START);
  1511. para[1] = FW_PARAM_PFVF_A(HPFILTER_END);
  1512. rc = t4_query_params(padap, padap->mbox, padap->pf, 0, 2,
  1513. para, val);
  1514. if (rc < 0) {
  1515. cudbg_err->sys_err = rc;
  1516. cudbg_put_buff(pdbg_init, &temp_buff);
  1517. return rc;
  1518. }
  1519. tid->hpftid_base = val[0];
  1520. tid->nhpftids = val[1] - val[0] + 1;
  1521. }
  1522. #undef FW_PARAM_PFVF_A
  1523. fill_tid:
  1524. tid->ntids = padap->tids.ntids;
  1525. tid->nstids = padap->tids.nstids;
  1526. tid->stid_base = padap->tids.stid_base;
  1527. tid->hash_base = padap->tids.hash_base;
  1528. tid->natids = padap->tids.natids;
  1529. tid->nftids = padap->tids.nftids;
  1530. tid->ftid_base = padap->tids.ftid_base;
  1531. tid->aftid_base = padap->tids.aftid_base;
  1532. tid->aftid_end = padap->tids.aftid_end;
  1533. tid->sftid_base = padap->tids.sftid_base;
  1534. tid->nsftids = padap->tids.nsftids;
  1535. tid->flags = padap->flags;
  1536. tid->le_db_conf = t4_read_reg(padap, LE_DB_CONFIG_A);
  1537. tid->ip_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV4_A);
  1538. tid->ipv6_users = t4_read_reg(padap, LE_DB_ACT_CNT_IPV6_A);
  1539. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1540. }
  1541. int cudbg_collect_pcie_config(struct cudbg_init *pdbg_init,
  1542. struct cudbg_buffer *dbg_buff,
  1543. struct cudbg_error *cudbg_err)
  1544. {
  1545. struct adapter *padap = pdbg_init->adap;
  1546. struct cudbg_buffer temp_buff = { 0 };
  1547. u32 size, *value, j;
  1548. int i, rc, n;
  1549. size = sizeof(u32) * CUDBG_NUM_PCIE_CONFIG_REGS;
  1550. n = sizeof(t5_pcie_config_array) / (2 * sizeof(u32));
  1551. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1552. if (rc)
  1553. return rc;
  1554. value = (u32 *)temp_buff.data;
  1555. for (i = 0; i < n; i++) {
  1556. for (j = t5_pcie_config_array[i][0];
  1557. j <= t5_pcie_config_array[i][1]; j += 4) {
  1558. t4_hw_pci_read_cfg4(padap, j, value);
  1559. value++;
  1560. }
  1561. }
  1562. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1563. }
  1564. static int cudbg_sge_ctxt_check_valid(u32 *buf, int type)
  1565. {
  1566. int index, bit, bit_pos = 0;
  1567. switch (type) {
  1568. case CTXT_EGRESS:
  1569. bit_pos = 176;
  1570. break;
  1571. case CTXT_INGRESS:
  1572. bit_pos = 141;
  1573. break;
  1574. case CTXT_FLM:
  1575. bit_pos = 89;
  1576. break;
  1577. }
  1578. index = bit_pos / 32;
  1579. bit = bit_pos % 32;
  1580. return buf[index] & (1U << bit);
  1581. }
  1582. static int cudbg_get_ctxt_region_info(struct adapter *padap,
  1583. struct cudbg_region_info *ctx_info,
  1584. u8 *mem_type)
  1585. {
  1586. struct cudbg_mem_desc mem_desc;
  1587. struct cudbg_meminfo meminfo;
  1588. u32 i, j, value, found;
  1589. u8 flq;
  1590. int rc;
  1591. rc = cudbg_fill_meminfo(padap, &meminfo);
  1592. if (rc)
  1593. return rc;
  1594. /* Get EGRESS and INGRESS context region size */
  1595. for (i = CTXT_EGRESS; i <= CTXT_INGRESS; i++) {
  1596. found = 0;
  1597. memset(&mem_desc, 0, sizeof(struct cudbg_mem_desc));
  1598. for (j = 0; j < ARRAY_SIZE(meminfo.avail); j++) {
  1599. rc = cudbg_get_mem_region(padap, &meminfo, j,
  1600. cudbg_region[i],
  1601. &mem_desc);
  1602. if (!rc) {
  1603. found = 1;
  1604. rc = cudbg_get_mem_relative(padap, &meminfo, j,
  1605. &mem_desc.base,
  1606. &mem_desc.limit);
  1607. if (rc) {
  1608. ctx_info[i].exist = false;
  1609. break;
  1610. }
  1611. ctx_info[i].exist = true;
  1612. ctx_info[i].start = mem_desc.base;
  1613. ctx_info[i].end = mem_desc.limit;
  1614. mem_type[i] = j;
  1615. break;
  1616. }
  1617. }
  1618. if (!found)
  1619. ctx_info[i].exist = false;
  1620. }
  1621. /* Get FLM and CNM max qid. */
  1622. value = t4_read_reg(padap, SGE_FLM_CFG_A);
  1623. /* Get number of data freelist queues */
  1624. flq = HDRSTARTFLQ_G(value);
  1625. ctx_info[CTXT_FLM].exist = true;
  1626. ctx_info[CTXT_FLM].end = (CUDBG_MAX_FL_QIDS >> flq) * SGE_CTXT_SIZE;
  1627. /* The number of CONM contexts are same as number of freelist
  1628. * queues.
  1629. */
  1630. ctx_info[CTXT_CNM].exist = true;
  1631. ctx_info[CTXT_CNM].end = ctx_info[CTXT_FLM].end;
  1632. return 0;
  1633. }
  1634. int cudbg_dump_context_size(struct adapter *padap)
  1635. {
  1636. struct cudbg_region_info region_info[CTXT_CNM + 1] = { {0} };
  1637. u8 mem_type[CTXT_INGRESS + 1] = { 0 };
  1638. u32 i, size = 0;
  1639. int rc;
  1640. /* Get max valid qid for each type of queue */
  1641. rc = cudbg_get_ctxt_region_info(padap, region_info, mem_type);
  1642. if (rc)
  1643. return rc;
  1644. for (i = 0; i < CTXT_CNM; i++) {
  1645. if (!region_info[i].exist) {
  1646. if (i == CTXT_EGRESS || i == CTXT_INGRESS)
  1647. size += CUDBG_LOWMEM_MAX_CTXT_QIDS *
  1648. SGE_CTXT_SIZE;
  1649. continue;
  1650. }
  1651. size += (region_info[i].end - region_info[i].start + 1) /
  1652. SGE_CTXT_SIZE;
  1653. }
  1654. return size * sizeof(struct cudbg_ch_cntxt);
  1655. }
  1656. static void cudbg_read_sge_ctxt(struct cudbg_init *pdbg_init, u32 cid,
  1657. enum ctxt_type ctype, u32 *data)
  1658. {
  1659. struct adapter *padap = pdbg_init->adap;
  1660. int rc = -1;
  1661. /* Under heavy traffic, the SGE Queue contexts registers will be
  1662. * frequently accessed by firmware.
  1663. *
  1664. * To avoid conflicts with firmware, always ask firmware to fetch
  1665. * the SGE Queue contexts via mailbox. On failure, fallback to
  1666. * accessing hardware registers directly.
  1667. */
  1668. if (is_fw_attached(pdbg_init))
  1669. rc = t4_sge_ctxt_rd(padap, padap->mbox, cid, ctype, data);
  1670. if (rc)
  1671. t4_sge_ctxt_rd_bd(padap, cid, ctype, data);
  1672. }
  1673. static void cudbg_get_sge_ctxt_fw(struct cudbg_init *pdbg_init, u32 max_qid,
  1674. u8 ctxt_type,
  1675. struct cudbg_ch_cntxt **out_buff)
  1676. {
  1677. struct cudbg_ch_cntxt *buff = *out_buff;
  1678. int rc;
  1679. u32 j;
  1680. for (j = 0; j < max_qid; j++) {
  1681. cudbg_read_sge_ctxt(pdbg_init, j, ctxt_type, buff->data);
  1682. rc = cudbg_sge_ctxt_check_valid(buff->data, ctxt_type);
  1683. if (!rc)
  1684. continue;
  1685. buff->cntxt_type = ctxt_type;
  1686. buff->cntxt_id = j;
  1687. buff++;
  1688. if (ctxt_type == CTXT_FLM) {
  1689. cudbg_read_sge_ctxt(pdbg_init, j, CTXT_CNM, buff->data);
  1690. buff->cntxt_type = CTXT_CNM;
  1691. buff->cntxt_id = j;
  1692. buff++;
  1693. }
  1694. }
  1695. *out_buff = buff;
  1696. }
  1697. int cudbg_collect_dump_context(struct cudbg_init *pdbg_init,
  1698. struct cudbg_buffer *dbg_buff,
  1699. struct cudbg_error *cudbg_err)
  1700. {
  1701. struct cudbg_region_info region_info[CTXT_CNM + 1] = { {0} };
  1702. struct adapter *padap = pdbg_init->adap;
  1703. u32 j, size, max_ctx_size, max_ctx_qid;
  1704. u8 mem_type[CTXT_INGRESS + 1] = { 0 };
  1705. struct cudbg_buffer temp_buff = { 0 };
  1706. struct cudbg_ch_cntxt *buff;
  1707. u64 *dst_off, *src_off;
  1708. u8 *ctx_buf;
  1709. u8 i, k;
  1710. int rc;
  1711. /* Get max valid qid for each type of queue */
  1712. rc = cudbg_get_ctxt_region_info(padap, region_info, mem_type);
  1713. if (rc)
  1714. return rc;
  1715. rc = cudbg_dump_context_size(padap);
  1716. if (rc <= 0)
  1717. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  1718. size = rc;
  1719. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1720. if (rc)
  1721. return rc;
  1722. /* Get buffer with enough space to read the biggest context
  1723. * region in memory.
  1724. */
  1725. max_ctx_size = max(region_info[CTXT_EGRESS].end -
  1726. region_info[CTXT_EGRESS].start + 1,
  1727. region_info[CTXT_INGRESS].end -
  1728. region_info[CTXT_INGRESS].start + 1);
  1729. ctx_buf = kvzalloc(max_ctx_size, GFP_KERNEL);
  1730. if (!ctx_buf) {
  1731. cudbg_put_buff(pdbg_init, &temp_buff);
  1732. return -ENOMEM;
  1733. }
  1734. buff = (struct cudbg_ch_cntxt *)temp_buff.data;
  1735. /* Collect EGRESS and INGRESS context data.
  1736. * In case of failures, fallback to collecting via FW or
  1737. * backdoor access.
  1738. */
  1739. for (i = CTXT_EGRESS; i <= CTXT_INGRESS; i++) {
  1740. if (!region_info[i].exist) {
  1741. max_ctx_qid = CUDBG_LOWMEM_MAX_CTXT_QIDS;
  1742. cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, i,
  1743. &buff);
  1744. continue;
  1745. }
  1746. max_ctx_size = region_info[i].end - region_info[i].start + 1;
  1747. max_ctx_qid = max_ctx_size / SGE_CTXT_SIZE;
  1748. /* If firmware is not attached/alive, use backdoor register
  1749. * access to collect dump.
  1750. */
  1751. if (is_fw_attached(pdbg_init)) {
  1752. t4_sge_ctxt_flush(padap, padap->mbox, i);
  1753. rc = t4_memory_rw(padap, MEMWIN_NIC, mem_type[i],
  1754. region_info[i].start, max_ctx_size,
  1755. (__be32 *)ctx_buf, 1);
  1756. }
  1757. if (rc || !is_fw_attached(pdbg_init)) {
  1758. max_ctx_qid = CUDBG_LOWMEM_MAX_CTXT_QIDS;
  1759. cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, i,
  1760. &buff);
  1761. continue;
  1762. }
  1763. for (j = 0; j < max_ctx_qid; j++) {
  1764. src_off = (u64 *)(ctx_buf + j * SGE_CTXT_SIZE);
  1765. dst_off = (u64 *)buff->data;
  1766. /* The data is stored in 64-bit cpu order. Convert it
  1767. * to big endian before parsing.
  1768. */
  1769. for (k = 0; k < SGE_CTXT_SIZE / sizeof(u64); k++)
  1770. dst_off[k] = cpu_to_be64(src_off[k]);
  1771. rc = cudbg_sge_ctxt_check_valid(buff->data, i);
  1772. if (!rc)
  1773. continue;
  1774. buff->cntxt_type = i;
  1775. buff->cntxt_id = j;
  1776. buff++;
  1777. }
  1778. }
  1779. kvfree(ctx_buf);
  1780. /* Collect FREELIST and CONGESTION MANAGER contexts */
  1781. max_ctx_size = region_info[CTXT_FLM].end -
  1782. region_info[CTXT_FLM].start + 1;
  1783. max_ctx_qid = max_ctx_size / SGE_CTXT_SIZE;
  1784. /* Since FLM and CONM are 1-to-1 mapped, the below function
  1785. * will fetch both FLM and CONM contexts.
  1786. */
  1787. cudbg_get_sge_ctxt_fw(pdbg_init, max_ctx_qid, CTXT_FLM, &buff);
  1788. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1789. }
  1790. static inline void cudbg_tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
  1791. {
  1792. *mask = x | y;
  1793. y = (__force u64)cpu_to_be64(y);
  1794. memcpy(addr, (char *)&y + 2, ETH_ALEN);
  1795. }
  1796. static void cudbg_mps_rpl_backdoor(struct adapter *padap,
  1797. struct fw_ldst_mps_rplc *mps_rplc)
  1798. {
  1799. if (is_t5(padap->params.chip)) {
  1800. mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
  1801. MPS_VF_RPLCT_MAP3_A));
  1802. mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
  1803. MPS_VF_RPLCT_MAP2_A));
  1804. mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
  1805. MPS_VF_RPLCT_MAP1_A));
  1806. mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
  1807. MPS_VF_RPLCT_MAP0_A));
  1808. } else {
  1809. mps_rplc->rplc255_224 = htonl(t4_read_reg(padap,
  1810. MPS_VF_RPLCT_MAP7_A));
  1811. mps_rplc->rplc223_192 = htonl(t4_read_reg(padap,
  1812. MPS_VF_RPLCT_MAP6_A));
  1813. mps_rplc->rplc191_160 = htonl(t4_read_reg(padap,
  1814. MPS_VF_RPLCT_MAP5_A));
  1815. mps_rplc->rplc159_128 = htonl(t4_read_reg(padap,
  1816. MPS_VF_RPLCT_MAP4_A));
  1817. }
  1818. mps_rplc->rplc127_96 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP3_A));
  1819. mps_rplc->rplc95_64 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP2_A));
  1820. mps_rplc->rplc63_32 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP1_A));
  1821. mps_rplc->rplc31_0 = htonl(t4_read_reg(padap, MPS_VF_RPLCT_MAP0_A));
  1822. }
  1823. static int cudbg_collect_tcam_index(struct cudbg_init *pdbg_init,
  1824. struct cudbg_mps_tcam *tcam, u32 idx)
  1825. {
  1826. struct adapter *padap = pdbg_init->adap;
  1827. u64 tcamy, tcamx, val;
  1828. u32 ctl, data2;
  1829. int rc = 0;
  1830. if (CHELSIO_CHIP_VERSION(padap->params.chip) >= CHELSIO_T6) {
  1831. /* CtlReqID - 1: use Host Driver Requester ID
  1832. * CtlCmdType - 0: Read, 1: Write
  1833. * CtlTcamSel - 0: TCAM0, 1: TCAM1
  1834. * CtlXYBitSel- 0: Y bit, 1: X bit
  1835. */
  1836. /* Read tcamy */
  1837. ctl = CTLREQID_V(1) | CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
  1838. if (idx < 256)
  1839. ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
  1840. else
  1841. ctl |= CTLTCAMINDEX_V(idx - 256) | CTLTCAMSEL_V(1);
  1842. t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
  1843. val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
  1844. tcamy = DMACH_G(val) << 32;
  1845. tcamy |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
  1846. data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
  1847. tcam->lookup_type = DATALKPTYPE_G(data2);
  1848. /* 0 - Outer header, 1 - Inner header
  1849. * [71:48] bit locations are overloaded for
  1850. * outer vs. inner lookup types.
  1851. */
  1852. if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
  1853. /* Inner header VNI */
  1854. tcam->vniy = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
  1855. tcam->vniy = (tcam->vniy << 16) | VIDL_G(val);
  1856. tcam->dip_hit = data2 & DATADIPHIT_F;
  1857. } else {
  1858. tcam->vlan_vld = data2 & DATAVIDH2_F;
  1859. tcam->ivlan = VIDL_G(val);
  1860. }
  1861. tcam->port_num = DATAPORTNUM_G(data2);
  1862. /* Read tcamx. Change the control param */
  1863. ctl |= CTLXYBITSEL_V(1);
  1864. t4_write_reg(padap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
  1865. val = t4_read_reg(padap, MPS_CLS_TCAM_RDATA1_REQ_ID1_A);
  1866. tcamx = DMACH_G(val) << 32;
  1867. tcamx |= t4_read_reg(padap, MPS_CLS_TCAM_RDATA0_REQ_ID1_A);
  1868. data2 = t4_read_reg(padap, MPS_CLS_TCAM_RDATA2_REQ_ID1_A);
  1869. if (tcam->lookup_type && tcam->lookup_type != DATALKPTYPE_M) {
  1870. /* Inner header VNI mask */
  1871. tcam->vnix = (data2 & DATAVIDH2_F) | DATAVIDH1_G(data2);
  1872. tcam->vnix = (tcam->vnix << 16) | VIDL_G(val);
  1873. }
  1874. } else {
  1875. tcamy = t4_read_reg64(padap, MPS_CLS_TCAM_Y_L(idx));
  1876. tcamx = t4_read_reg64(padap, MPS_CLS_TCAM_X_L(idx));
  1877. }
  1878. /* If no entry, return */
  1879. if (tcamx & tcamy)
  1880. return rc;
  1881. tcam->cls_lo = t4_read_reg(padap, MPS_CLS_SRAM_L(idx));
  1882. tcam->cls_hi = t4_read_reg(padap, MPS_CLS_SRAM_H(idx));
  1883. if (is_t5(padap->params.chip))
  1884. tcam->repli = (tcam->cls_lo & REPLICATE_F);
  1885. else if (is_t6(padap->params.chip))
  1886. tcam->repli = (tcam->cls_lo & T6_REPLICATE_F);
  1887. if (tcam->repli) {
  1888. struct fw_ldst_cmd ldst_cmd;
  1889. struct fw_ldst_mps_rplc mps_rplc;
  1890. memset(&ldst_cmd, 0, sizeof(ldst_cmd));
  1891. ldst_cmd.op_to_addrspace =
  1892. htonl(FW_CMD_OP_V(FW_LDST_CMD) |
  1893. FW_CMD_REQUEST_F | FW_CMD_READ_F |
  1894. FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS));
  1895. ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
  1896. ldst_cmd.u.mps.rplc.fid_idx =
  1897. htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
  1898. FW_LDST_CMD_IDX_V(idx));
  1899. /* If firmware is not attached/alive, use backdoor register
  1900. * access to collect dump.
  1901. */
  1902. if (is_fw_attached(pdbg_init))
  1903. rc = t4_wr_mbox(padap, padap->mbox, &ldst_cmd,
  1904. sizeof(ldst_cmd), &ldst_cmd);
  1905. if (rc || !is_fw_attached(pdbg_init)) {
  1906. cudbg_mps_rpl_backdoor(padap, &mps_rplc);
  1907. /* Ignore error since we collected directly from
  1908. * reading registers.
  1909. */
  1910. rc = 0;
  1911. } else {
  1912. mps_rplc = ldst_cmd.u.mps.rplc;
  1913. }
  1914. tcam->rplc[0] = ntohl(mps_rplc.rplc31_0);
  1915. tcam->rplc[1] = ntohl(mps_rplc.rplc63_32);
  1916. tcam->rplc[2] = ntohl(mps_rplc.rplc95_64);
  1917. tcam->rplc[3] = ntohl(mps_rplc.rplc127_96);
  1918. if (padap->params.arch.mps_rplc_size > CUDBG_MAX_RPLC_SIZE) {
  1919. tcam->rplc[4] = ntohl(mps_rplc.rplc159_128);
  1920. tcam->rplc[5] = ntohl(mps_rplc.rplc191_160);
  1921. tcam->rplc[6] = ntohl(mps_rplc.rplc223_192);
  1922. tcam->rplc[7] = ntohl(mps_rplc.rplc255_224);
  1923. }
  1924. }
  1925. cudbg_tcamxy2valmask(tcamx, tcamy, tcam->addr, &tcam->mask);
  1926. tcam->idx = idx;
  1927. tcam->rplc_size = padap->params.arch.mps_rplc_size;
  1928. return rc;
  1929. }
  1930. int cudbg_collect_mps_tcam(struct cudbg_init *pdbg_init,
  1931. struct cudbg_buffer *dbg_buff,
  1932. struct cudbg_error *cudbg_err)
  1933. {
  1934. struct adapter *padap = pdbg_init->adap;
  1935. struct cudbg_buffer temp_buff = { 0 };
  1936. u32 size = 0, i, n, total_size = 0;
  1937. struct cudbg_mps_tcam *tcam;
  1938. int rc;
  1939. n = padap->params.arch.mps_tcam_size;
  1940. size = sizeof(struct cudbg_mps_tcam) * n;
  1941. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  1942. if (rc)
  1943. return rc;
  1944. tcam = (struct cudbg_mps_tcam *)temp_buff.data;
  1945. for (i = 0; i < n; i++) {
  1946. rc = cudbg_collect_tcam_index(pdbg_init, tcam, i);
  1947. if (rc) {
  1948. cudbg_err->sys_err = rc;
  1949. cudbg_put_buff(pdbg_init, &temp_buff);
  1950. return rc;
  1951. }
  1952. total_size += sizeof(struct cudbg_mps_tcam);
  1953. tcam++;
  1954. }
  1955. if (!total_size) {
  1956. rc = CUDBG_SYSTEM_ERROR;
  1957. cudbg_err->sys_err = rc;
  1958. cudbg_put_buff(pdbg_init, &temp_buff);
  1959. return rc;
  1960. }
  1961. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  1962. }
  1963. int cudbg_collect_vpd_data(struct cudbg_init *pdbg_init,
  1964. struct cudbg_buffer *dbg_buff,
  1965. struct cudbg_error *cudbg_err)
  1966. {
  1967. struct adapter *padap = pdbg_init->adap;
  1968. struct cudbg_buffer temp_buff = { 0 };
  1969. char vpd_str[CUDBG_VPD_VER_LEN + 1];
  1970. u32 scfg_vers, vpd_vers, fw_vers;
  1971. struct cudbg_vpd_data *vpd_data;
  1972. struct vpd_params vpd = { 0 };
  1973. int rc, ret;
  1974. rc = t4_get_raw_vpd_params(padap, &vpd);
  1975. if (rc)
  1976. return rc;
  1977. rc = t4_get_fw_version(padap, &fw_vers);
  1978. if (rc)
  1979. return rc;
  1980. /* Serial Configuration Version is located beyond the PF's vpd size.
  1981. * Temporarily give access to entire EEPROM to get it.
  1982. */
  1983. rc = pci_set_vpd_size(padap->pdev, EEPROMVSIZE);
  1984. if (rc < 0)
  1985. return rc;
  1986. ret = cudbg_read_vpd_reg(padap, CUDBG_SCFG_VER_ADDR, CUDBG_SCFG_VER_LEN,
  1987. &scfg_vers);
  1988. /* Restore back to original PF's vpd size */
  1989. rc = pci_set_vpd_size(padap->pdev, CUDBG_VPD_PF_SIZE);
  1990. if (rc < 0)
  1991. return rc;
  1992. if (ret)
  1993. return ret;
  1994. rc = cudbg_read_vpd_reg(padap, CUDBG_VPD_VER_ADDR, CUDBG_VPD_VER_LEN,
  1995. vpd_str);
  1996. if (rc)
  1997. return rc;
  1998. vpd_str[CUDBG_VPD_VER_LEN] = '\0';
  1999. rc = kstrtouint(vpd_str, 0, &vpd_vers);
  2000. if (rc)
  2001. return rc;
  2002. rc = cudbg_get_buff(pdbg_init, dbg_buff, sizeof(struct cudbg_vpd_data),
  2003. &temp_buff);
  2004. if (rc)
  2005. return rc;
  2006. vpd_data = (struct cudbg_vpd_data *)temp_buff.data;
  2007. memcpy(vpd_data->sn, vpd.sn, SERNUM_LEN + 1);
  2008. memcpy(vpd_data->bn, vpd.pn, PN_LEN + 1);
  2009. memcpy(vpd_data->na, vpd.na, MACADDR_LEN + 1);
  2010. memcpy(vpd_data->mn, vpd.id, ID_LEN + 1);
  2011. vpd_data->scfg_vers = scfg_vers;
  2012. vpd_data->vpd_vers = vpd_vers;
  2013. vpd_data->fw_major = FW_HDR_FW_VER_MAJOR_G(fw_vers);
  2014. vpd_data->fw_minor = FW_HDR_FW_VER_MINOR_G(fw_vers);
  2015. vpd_data->fw_micro = FW_HDR_FW_VER_MICRO_G(fw_vers);
  2016. vpd_data->fw_build = FW_HDR_FW_VER_BUILD_G(fw_vers);
  2017. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2018. }
  2019. static int cudbg_read_tid(struct cudbg_init *pdbg_init, u32 tid,
  2020. struct cudbg_tid_data *tid_data)
  2021. {
  2022. struct adapter *padap = pdbg_init->adap;
  2023. int i, cmd_retry = 8;
  2024. u32 val;
  2025. /* Fill REQ_DATA regs with 0's */
  2026. for (i = 0; i < NUM_LE_DB_DBGI_REQ_DATA_INSTANCES; i++)
  2027. t4_write_reg(padap, LE_DB_DBGI_REQ_DATA_A + (i << 2), 0);
  2028. /* Write DBIG command */
  2029. val = DBGICMD_V(4) | DBGITID_V(tid);
  2030. t4_write_reg(padap, LE_DB_DBGI_REQ_TCAM_CMD_A, val);
  2031. tid_data->dbig_cmd = val;
  2032. val = DBGICMDSTRT_F | DBGICMDMODE_V(1); /* LE mode */
  2033. t4_write_reg(padap, LE_DB_DBGI_CONFIG_A, val);
  2034. tid_data->dbig_conf = val;
  2035. /* Poll the DBGICMDBUSY bit */
  2036. val = 1;
  2037. while (val) {
  2038. val = t4_read_reg(padap, LE_DB_DBGI_CONFIG_A);
  2039. val = val & DBGICMDBUSY_F;
  2040. cmd_retry--;
  2041. if (!cmd_retry)
  2042. return CUDBG_SYSTEM_ERROR;
  2043. }
  2044. /* Check RESP status */
  2045. val = t4_read_reg(padap, LE_DB_DBGI_RSP_STATUS_A);
  2046. tid_data->dbig_rsp_stat = val;
  2047. if (!(val & 1))
  2048. return CUDBG_SYSTEM_ERROR;
  2049. /* Read RESP data */
  2050. for (i = 0; i < NUM_LE_DB_DBGI_RSP_DATA_INSTANCES; i++)
  2051. tid_data->data[i] = t4_read_reg(padap,
  2052. LE_DB_DBGI_RSP_DATA_A +
  2053. (i << 2));
  2054. tid_data->tid = tid;
  2055. return 0;
  2056. }
  2057. static int cudbg_get_le_type(u32 tid, struct cudbg_tcam tcam_region)
  2058. {
  2059. int type = LE_ET_UNKNOWN;
  2060. if (tid < tcam_region.server_start)
  2061. type = LE_ET_TCAM_CON;
  2062. else if (tid < tcam_region.filter_start)
  2063. type = LE_ET_TCAM_SERVER;
  2064. else if (tid < tcam_region.clip_start)
  2065. type = LE_ET_TCAM_FILTER;
  2066. else if (tid < tcam_region.routing_start)
  2067. type = LE_ET_TCAM_CLIP;
  2068. else if (tid < tcam_region.tid_hash_base)
  2069. type = LE_ET_TCAM_ROUTING;
  2070. else if (tid < tcam_region.max_tid)
  2071. type = LE_ET_HASH_CON;
  2072. else
  2073. type = LE_ET_INVALID_TID;
  2074. return type;
  2075. }
  2076. static int cudbg_is_ipv6_entry(struct cudbg_tid_data *tid_data,
  2077. struct cudbg_tcam tcam_region)
  2078. {
  2079. int ipv6 = 0;
  2080. int le_type;
  2081. le_type = cudbg_get_le_type(tid_data->tid, tcam_region);
  2082. if (tid_data->tid & 1)
  2083. return 0;
  2084. if (le_type == LE_ET_HASH_CON) {
  2085. ipv6 = tid_data->data[16] & 0x8000;
  2086. } else if (le_type == LE_ET_TCAM_CON) {
  2087. ipv6 = tid_data->data[16] & 0x8000;
  2088. if (ipv6)
  2089. ipv6 = tid_data->data[9] == 0x00C00000;
  2090. } else {
  2091. ipv6 = 0;
  2092. }
  2093. return ipv6;
  2094. }
  2095. void cudbg_fill_le_tcam_info(struct adapter *padap,
  2096. struct cudbg_tcam *tcam_region)
  2097. {
  2098. u32 value;
  2099. /* Get the LE regions */
  2100. value = t4_read_reg(padap, LE_DB_TID_HASHBASE_A); /* hash base index */
  2101. tcam_region->tid_hash_base = value;
  2102. /* Get routing table index */
  2103. value = t4_read_reg(padap, LE_DB_ROUTING_TABLE_INDEX_A);
  2104. tcam_region->routing_start = value;
  2105. /* Get clip table index. For T6 there is separate CLIP TCAM */
  2106. if (is_t6(padap->params.chip))
  2107. value = t4_read_reg(padap, LE_DB_CLCAM_TID_BASE_A);
  2108. else
  2109. value = t4_read_reg(padap, LE_DB_CLIP_TABLE_INDEX_A);
  2110. tcam_region->clip_start = value;
  2111. /* Get filter table index */
  2112. value = t4_read_reg(padap, LE_DB_FILTER_TABLE_INDEX_A);
  2113. tcam_region->filter_start = value;
  2114. /* Get server table index */
  2115. value = t4_read_reg(padap, LE_DB_SERVER_INDEX_A);
  2116. tcam_region->server_start = value;
  2117. /* Check whether hash is enabled and calculate the max tids */
  2118. value = t4_read_reg(padap, LE_DB_CONFIG_A);
  2119. if ((value >> HASHEN_S) & 1) {
  2120. value = t4_read_reg(padap, LE_DB_HASH_CONFIG_A);
  2121. if (CHELSIO_CHIP_VERSION(padap->params.chip) > CHELSIO_T5) {
  2122. tcam_region->max_tid = (value & 0xFFFFF) +
  2123. tcam_region->tid_hash_base;
  2124. } else {
  2125. value = HASHTIDSIZE_G(value);
  2126. value = 1 << value;
  2127. tcam_region->max_tid = value +
  2128. tcam_region->tid_hash_base;
  2129. }
  2130. } else { /* hash not enabled */
  2131. if (is_t6(padap->params.chip))
  2132. tcam_region->max_tid = (value & ASLIPCOMPEN_F) ?
  2133. CUDBG_MAX_TID_COMP_EN :
  2134. CUDBG_MAX_TID_COMP_DIS;
  2135. else
  2136. tcam_region->max_tid = CUDBG_MAX_TCAM_TID;
  2137. }
  2138. if (is_t6(padap->params.chip))
  2139. tcam_region->max_tid += CUDBG_T6_CLIP;
  2140. }
  2141. int cudbg_collect_le_tcam(struct cudbg_init *pdbg_init,
  2142. struct cudbg_buffer *dbg_buff,
  2143. struct cudbg_error *cudbg_err)
  2144. {
  2145. struct adapter *padap = pdbg_init->adap;
  2146. struct cudbg_buffer temp_buff = { 0 };
  2147. struct cudbg_tcam tcam_region = { 0 };
  2148. struct cudbg_tid_data *tid_data;
  2149. u32 bytes = 0;
  2150. int rc, size;
  2151. u32 i;
  2152. cudbg_fill_le_tcam_info(padap, &tcam_region);
  2153. size = sizeof(struct cudbg_tid_data) * tcam_region.max_tid;
  2154. size += sizeof(struct cudbg_tcam);
  2155. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2156. if (rc)
  2157. return rc;
  2158. memcpy(temp_buff.data, &tcam_region, sizeof(struct cudbg_tcam));
  2159. bytes = sizeof(struct cudbg_tcam);
  2160. tid_data = (struct cudbg_tid_data *)(temp_buff.data + bytes);
  2161. /* read all tid */
  2162. for (i = 0; i < tcam_region.max_tid; ) {
  2163. rc = cudbg_read_tid(pdbg_init, i, tid_data);
  2164. if (rc) {
  2165. cudbg_err->sys_warn = CUDBG_STATUS_PARTIAL_DATA;
  2166. /* Update tcam header and exit */
  2167. tcam_region.max_tid = i;
  2168. memcpy(temp_buff.data, &tcam_region,
  2169. sizeof(struct cudbg_tcam));
  2170. goto out;
  2171. }
  2172. if (cudbg_is_ipv6_entry(tid_data, tcam_region)) {
  2173. /* T6 CLIP TCAM: ipv6 takes 4 entries */
  2174. if (is_t6(padap->params.chip) &&
  2175. i >= tcam_region.clip_start &&
  2176. i < tcam_region.clip_start + CUDBG_T6_CLIP)
  2177. i += 4;
  2178. else /* Main TCAM: ipv6 takes two tids */
  2179. i += 2;
  2180. } else {
  2181. i++;
  2182. }
  2183. tid_data++;
  2184. bytes += sizeof(struct cudbg_tid_data);
  2185. }
  2186. out:
  2187. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2188. }
  2189. int cudbg_collect_cctrl(struct cudbg_init *pdbg_init,
  2190. struct cudbg_buffer *dbg_buff,
  2191. struct cudbg_error *cudbg_err)
  2192. {
  2193. struct adapter *padap = pdbg_init->adap;
  2194. struct cudbg_buffer temp_buff = { 0 };
  2195. u32 size;
  2196. int rc;
  2197. size = sizeof(u16) * NMTUS * NCCTRL_WIN;
  2198. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2199. if (rc)
  2200. return rc;
  2201. t4_read_cong_tbl(padap, (void *)temp_buff.data);
  2202. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2203. }
  2204. int cudbg_collect_ma_indirect(struct cudbg_init *pdbg_init,
  2205. struct cudbg_buffer *dbg_buff,
  2206. struct cudbg_error *cudbg_err)
  2207. {
  2208. struct adapter *padap = pdbg_init->adap;
  2209. struct cudbg_buffer temp_buff = { 0 };
  2210. struct ireg_buf *ma_indr;
  2211. int i, rc, n;
  2212. u32 size, j;
  2213. if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
  2214. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  2215. n = sizeof(t6_ma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
  2216. size = sizeof(struct ireg_buf) * n * 2;
  2217. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2218. if (rc)
  2219. return rc;
  2220. ma_indr = (struct ireg_buf *)temp_buff.data;
  2221. for (i = 0; i < n; i++) {
  2222. struct ireg_field *ma_fli = &ma_indr->tp_pio;
  2223. u32 *buff = ma_indr->outbuf;
  2224. ma_fli->ireg_addr = t6_ma_ireg_array[i][0];
  2225. ma_fli->ireg_data = t6_ma_ireg_array[i][1];
  2226. ma_fli->ireg_local_offset = t6_ma_ireg_array[i][2];
  2227. ma_fli->ireg_offset_range = t6_ma_ireg_array[i][3];
  2228. t4_read_indirect(padap, ma_fli->ireg_addr, ma_fli->ireg_data,
  2229. buff, ma_fli->ireg_offset_range,
  2230. ma_fli->ireg_local_offset);
  2231. ma_indr++;
  2232. }
  2233. n = sizeof(t6_ma_ireg_array2) / (IREG_NUM_ELEM * sizeof(u32));
  2234. for (i = 0; i < n; i++) {
  2235. struct ireg_field *ma_fli = &ma_indr->tp_pio;
  2236. u32 *buff = ma_indr->outbuf;
  2237. ma_fli->ireg_addr = t6_ma_ireg_array2[i][0];
  2238. ma_fli->ireg_data = t6_ma_ireg_array2[i][1];
  2239. ma_fli->ireg_local_offset = t6_ma_ireg_array2[i][2];
  2240. for (j = 0; j < t6_ma_ireg_array2[i][3]; j++) {
  2241. t4_read_indirect(padap, ma_fli->ireg_addr,
  2242. ma_fli->ireg_data, buff, 1,
  2243. ma_fli->ireg_local_offset);
  2244. buff++;
  2245. ma_fli->ireg_local_offset += 0x20;
  2246. }
  2247. ma_indr++;
  2248. }
  2249. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2250. }
  2251. int cudbg_collect_ulptx_la(struct cudbg_init *pdbg_init,
  2252. struct cudbg_buffer *dbg_buff,
  2253. struct cudbg_error *cudbg_err)
  2254. {
  2255. struct adapter *padap = pdbg_init->adap;
  2256. struct cudbg_buffer temp_buff = { 0 };
  2257. struct cudbg_ulptx_la *ulptx_la_buff;
  2258. struct cudbg_ver_hdr *ver_hdr;
  2259. u32 i, j;
  2260. int rc;
  2261. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  2262. sizeof(struct cudbg_ver_hdr) +
  2263. sizeof(struct cudbg_ulptx_la),
  2264. &temp_buff);
  2265. if (rc)
  2266. return rc;
  2267. ver_hdr = (struct cudbg_ver_hdr *)temp_buff.data;
  2268. ver_hdr->signature = CUDBG_ENTITY_SIGNATURE;
  2269. ver_hdr->revision = CUDBG_ULPTX_LA_REV;
  2270. ver_hdr->size = sizeof(struct cudbg_ulptx_la);
  2271. ulptx_la_buff = (struct cudbg_ulptx_la *)(temp_buff.data +
  2272. sizeof(*ver_hdr));
  2273. for (i = 0; i < CUDBG_NUM_ULPTX; i++) {
  2274. ulptx_la_buff->rdptr[i] = t4_read_reg(padap,
  2275. ULP_TX_LA_RDPTR_0_A +
  2276. 0x10 * i);
  2277. ulptx_la_buff->wrptr[i] = t4_read_reg(padap,
  2278. ULP_TX_LA_WRPTR_0_A +
  2279. 0x10 * i);
  2280. ulptx_la_buff->rddata[i] = t4_read_reg(padap,
  2281. ULP_TX_LA_RDDATA_0_A +
  2282. 0x10 * i);
  2283. for (j = 0; j < CUDBG_NUM_ULPTX_READ; j++)
  2284. ulptx_la_buff->rd_data[i][j] =
  2285. t4_read_reg(padap,
  2286. ULP_TX_LA_RDDATA_0_A + 0x10 * i);
  2287. }
  2288. for (i = 0; i < CUDBG_NUM_ULPTX_ASIC_READ; i++) {
  2289. t4_write_reg(padap, ULP_TX_ASIC_DEBUG_CTRL_A, 0x1);
  2290. ulptx_la_buff->rdptr_asic[i] =
  2291. t4_read_reg(padap, ULP_TX_ASIC_DEBUG_CTRL_A);
  2292. ulptx_la_buff->rddata_asic[i][0] =
  2293. t4_read_reg(padap, ULP_TX_ASIC_DEBUG_0_A);
  2294. ulptx_la_buff->rddata_asic[i][1] =
  2295. t4_read_reg(padap, ULP_TX_ASIC_DEBUG_1_A);
  2296. ulptx_la_buff->rddata_asic[i][2] =
  2297. t4_read_reg(padap, ULP_TX_ASIC_DEBUG_2_A);
  2298. ulptx_la_buff->rddata_asic[i][3] =
  2299. t4_read_reg(padap, ULP_TX_ASIC_DEBUG_3_A);
  2300. ulptx_la_buff->rddata_asic[i][4] =
  2301. t4_read_reg(padap, ULP_TX_ASIC_DEBUG_4_A);
  2302. ulptx_la_buff->rddata_asic[i][5] =
  2303. t4_read_reg(padap, PM_RX_BASE_ADDR);
  2304. }
  2305. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2306. }
  2307. int cudbg_collect_up_cim_indirect(struct cudbg_init *pdbg_init,
  2308. struct cudbg_buffer *dbg_buff,
  2309. struct cudbg_error *cudbg_err)
  2310. {
  2311. struct adapter *padap = pdbg_init->adap;
  2312. struct cudbg_buffer temp_buff = { 0 };
  2313. u32 local_offset, local_range;
  2314. struct ireg_buf *up_cim;
  2315. u32 size, j, iter;
  2316. u32 instance = 0;
  2317. int i, rc, n;
  2318. if (is_t5(padap->params.chip))
  2319. n = sizeof(t5_up_cim_reg_array) /
  2320. ((IREG_NUM_ELEM + 1) * sizeof(u32));
  2321. else if (is_t6(padap->params.chip))
  2322. n = sizeof(t6_up_cim_reg_array) /
  2323. ((IREG_NUM_ELEM + 1) * sizeof(u32));
  2324. else
  2325. return CUDBG_STATUS_NOT_IMPLEMENTED;
  2326. size = sizeof(struct ireg_buf) * n;
  2327. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2328. if (rc)
  2329. return rc;
  2330. up_cim = (struct ireg_buf *)temp_buff.data;
  2331. for (i = 0; i < n; i++) {
  2332. struct ireg_field *up_cim_reg = &up_cim->tp_pio;
  2333. u32 *buff = up_cim->outbuf;
  2334. if (is_t5(padap->params.chip)) {
  2335. up_cim_reg->ireg_addr = t5_up_cim_reg_array[i][0];
  2336. up_cim_reg->ireg_data = t5_up_cim_reg_array[i][1];
  2337. up_cim_reg->ireg_local_offset =
  2338. t5_up_cim_reg_array[i][2];
  2339. up_cim_reg->ireg_offset_range =
  2340. t5_up_cim_reg_array[i][3];
  2341. instance = t5_up_cim_reg_array[i][4];
  2342. } else if (is_t6(padap->params.chip)) {
  2343. up_cim_reg->ireg_addr = t6_up_cim_reg_array[i][0];
  2344. up_cim_reg->ireg_data = t6_up_cim_reg_array[i][1];
  2345. up_cim_reg->ireg_local_offset =
  2346. t6_up_cim_reg_array[i][2];
  2347. up_cim_reg->ireg_offset_range =
  2348. t6_up_cim_reg_array[i][3];
  2349. instance = t6_up_cim_reg_array[i][4];
  2350. }
  2351. switch (instance) {
  2352. case NUM_CIM_CTL_TSCH_CHANNEL_INSTANCES:
  2353. iter = up_cim_reg->ireg_offset_range;
  2354. local_offset = 0x120;
  2355. local_range = 1;
  2356. break;
  2357. case NUM_CIM_CTL_TSCH_CHANNEL_TSCH_CLASS_INSTANCES:
  2358. iter = up_cim_reg->ireg_offset_range;
  2359. local_offset = 0x10;
  2360. local_range = 1;
  2361. break;
  2362. default:
  2363. iter = 1;
  2364. local_offset = 0;
  2365. local_range = up_cim_reg->ireg_offset_range;
  2366. break;
  2367. }
  2368. for (j = 0; j < iter; j++, buff++) {
  2369. rc = t4_cim_read(padap,
  2370. up_cim_reg->ireg_local_offset +
  2371. (j * local_offset), local_range, buff);
  2372. if (rc) {
  2373. cudbg_put_buff(pdbg_init, &temp_buff);
  2374. return rc;
  2375. }
  2376. }
  2377. up_cim++;
  2378. }
  2379. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2380. }
  2381. int cudbg_collect_pbt_tables(struct cudbg_init *pdbg_init,
  2382. struct cudbg_buffer *dbg_buff,
  2383. struct cudbg_error *cudbg_err)
  2384. {
  2385. struct adapter *padap = pdbg_init->adap;
  2386. struct cudbg_buffer temp_buff = { 0 };
  2387. struct cudbg_pbt_tables *pbt;
  2388. int i, rc;
  2389. u32 addr;
  2390. rc = cudbg_get_buff(pdbg_init, dbg_buff,
  2391. sizeof(struct cudbg_pbt_tables),
  2392. &temp_buff);
  2393. if (rc)
  2394. return rc;
  2395. pbt = (struct cudbg_pbt_tables *)temp_buff.data;
  2396. /* PBT dynamic entries */
  2397. addr = CUDBG_CHAC_PBT_ADDR;
  2398. for (i = 0; i < CUDBG_PBT_DYNAMIC_ENTRIES; i++) {
  2399. rc = t4_cim_read(padap, addr + (i * 4), 1,
  2400. &pbt->pbt_dynamic[i]);
  2401. if (rc) {
  2402. cudbg_err->sys_err = rc;
  2403. cudbg_put_buff(pdbg_init, &temp_buff);
  2404. return rc;
  2405. }
  2406. }
  2407. /* PBT static entries */
  2408. /* static entries start when bit 6 is set */
  2409. addr = CUDBG_CHAC_PBT_ADDR + (1 << 6);
  2410. for (i = 0; i < CUDBG_PBT_STATIC_ENTRIES; i++) {
  2411. rc = t4_cim_read(padap, addr + (i * 4), 1,
  2412. &pbt->pbt_static[i]);
  2413. if (rc) {
  2414. cudbg_err->sys_err = rc;
  2415. cudbg_put_buff(pdbg_init, &temp_buff);
  2416. return rc;
  2417. }
  2418. }
  2419. /* LRF entries */
  2420. addr = CUDBG_CHAC_PBT_LRF;
  2421. for (i = 0; i < CUDBG_LRF_ENTRIES; i++) {
  2422. rc = t4_cim_read(padap, addr + (i * 4), 1,
  2423. &pbt->lrf_table[i]);
  2424. if (rc) {
  2425. cudbg_err->sys_err = rc;
  2426. cudbg_put_buff(pdbg_init, &temp_buff);
  2427. return rc;
  2428. }
  2429. }
  2430. /* PBT data entries */
  2431. addr = CUDBG_CHAC_PBT_DATA;
  2432. for (i = 0; i < CUDBG_PBT_DATA_ENTRIES; i++) {
  2433. rc = t4_cim_read(padap, addr + (i * 4), 1,
  2434. &pbt->pbt_data[i]);
  2435. if (rc) {
  2436. cudbg_err->sys_err = rc;
  2437. cudbg_put_buff(pdbg_init, &temp_buff);
  2438. return rc;
  2439. }
  2440. }
  2441. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2442. }
  2443. int cudbg_collect_mbox_log(struct cudbg_init *pdbg_init,
  2444. struct cudbg_buffer *dbg_buff,
  2445. struct cudbg_error *cudbg_err)
  2446. {
  2447. struct adapter *padap = pdbg_init->adap;
  2448. struct cudbg_mbox_log *mboxlog = NULL;
  2449. struct cudbg_buffer temp_buff = { 0 };
  2450. struct mbox_cmd_log *log = NULL;
  2451. struct mbox_cmd *entry;
  2452. unsigned int entry_idx;
  2453. u16 mbox_cmds;
  2454. int i, k, rc;
  2455. u64 flit;
  2456. u32 size;
  2457. log = padap->mbox_log;
  2458. mbox_cmds = padap->mbox_log->size;
  2459. size = sizeof(struct cudbg_mbox_log) * mbox_cmds;
  2460. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2461. if (rc)
  2462. return rc;
  2463. mboxlog = (struct cudbg_mbox_log *)temp_buff.data;
  2464. for (k = 0; k < mbox_cmds; k++) {
  2465. entry_idx = log->cursor + k;
  2466. if (entry_idx >= log->size)
  2467. entry_idx -= log->size;
  2468. entry = mbox_cmd_log_entry(log, entry_idx);
  2469. /* skip over unused entries */
  2470. if (entry->timestamp == 0)
  2471. continue;
  2472. memcpy(&mboxlog->entry, entry, sizeof(struct mbox_cmd));
  2473. for (i = 0; i < MBOX_LEN / 8; i++) {
  2474. flit = entry->cmd[i];
  2475. mboxlog->hi[i] = (u32)(flit >> 32);
  2476. mboxlog->lo[i] = (u32)flit;
  2477. }
  2478. mboxlog++;
  2479. }
  2480. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2481. }
  2482. int cudbg_collect_hma_indirect(struct cudbg_init *pdbg_init,
  2483. struct cudbg_buffer *dbg_buff,
  2484. struct cudbg_error *cudbg_err)
  2485. {
  2486. struct adapter *padap = pdbg_init->adap;
  2487. struct cudbg_buffer temp_buff = { 0 };
  2488. struct ireg_buf *hma_indr;
  2489. int i, rc, n;
  2490. u32 size;
  2491. if (CHELSIO_CHIP_VERSION(padap->params.chip) < CHELSIO_T6)
  2492. return CUDBG_STATUS_ENTITY_NOT_FOUND;
  2493. n = sizeof(t6_hma_ireg_array) / (IREG_NUM_ELEM * sizeof(u32));
  2494. size = sizeof(struct ireg_buf) * n;
  2495. rc = cudbg_get_buff(pdbg_init, dbg_buff, size, &temp_buff);
  2496. if (rc)
  2497. return rc;
  2498. hma_indr = (struct ireg_buf *)temp_buff.data;
  2499. for (i = 0; i < n; i++) {
  2500. struct ireg_field *hma_fli = &hma_indr->tp_pio;
  2501. u32 *buff = hma_indr->outbuf;
  2502. hma_fli->ireg_addr = t6_hma_ireg_array[i][0];
  2503. hma_fli->ireg_data = t6_hma_ireg_array[i][1];
  2504. hma_fli->ireg_local_offset = t6_hma_ireg_array[i][2];
  2505. hma_fli->ireg_offset_range = t6_hma_ireg_array[i][3];
  2506. t4_read_indirect(padap, hma_fli->ireg_addr, hma_fli->ireg_data,
  2507. buff, hma_fli->ireg_offset_range,
  2508. hma_fli->ireg_local_offset);
  2509. hma_indr++;
  2510. }
  2511. return cudbg_write_and_release_buff(pdbg_init, &temp_buff, dbg_buff);
  2512. }