cudbg_lib.c 81 KB

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