cxgb4_debugfs.c 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/seq_file.h>
  35. #include <linux/debugfs.h>
  36. #include <linux/string_helpers.h>
  37. #include <linux/sort.h>
  38. #include <linux/ctype.h>
  39. #include "cxgb4.h"
  40. #include "t4_regs.h"
  41. #include "t4_values.h"
  42. #include "t4fw_api.h"
  43. #include "cxgb4_debugfs.h"
  44. #include "clip_tbl.h"
  45. #include "l2t.h"
  46. #include "cudbg_if.h"
  47. #include "cudbg_lib_common.h"
  48. #include "cudbg_entity.h"
  49. #include "cudbg_lib.h"
  50. /* generic seq_file support for showing a table of size rows x width. */
  51. static void *seq_tab_get_idx(struct seq_tab *tb, loff_t pos)
  52. {
  53. pos -= tb->skip_first;
  54. return pos >= tb->rows ? NULL : &tb->data[pos * tb->width];
  55. }
  56. static void *seq_tab_start(struct seq_file *seq, loff_t *pos)
  57. {
  58. struct seq_tab *tb = seq->private;
  59. if (tb->skip_first && *pos == 0)
  60. return SEQ_START_TOKEN;
  61. return seq_tab_get_idx(tb, *pos);
  62. }
  63. static void *seq_tab_next(struct seq_file *seq, void *v, loff_t *pos)
  64. {
  65. v = seq_tab_get_idx(seq->private, *pos + 1);
  66. if (v)
  67. ++*pos;
  68. return v;
  69. }
  70. static void seq_tab_stop(struct seq_file *seq, void *v)
  71. {
  72. }
  73. static int seq_tab_show(struct seq_file *seq, void *v)
  74. {
  75. const struct seq_tab *tb = seq->private;
  76. return tb->show(seq, v, ((char *)v - tb->data) / tb->width);
  77. }
  78. static const struct seq_operations seq_tab_ops = {
  79. .start = seq_tab_start,
  80. .next = seq_tab_next,
  81. .stop = seq_tab_stop,
  82. .show = seq_tab_show
  83. };
  84. struct seq_tab *seq_open_tab(struct file *f, unsigned int rows,
  85. unsigned int width, unsigned int have_header,
  86. int (*show)(struct seq_file *seq, void *v, int i))
  87. {
  88. struct seq_tab *p;
  89. p = __seq_open_private(f, &seq_tab_ops, sizeof(*p) + rows * width);
  90. if (p) {
  91. p->show = show;
  92. p->rows = rows;
  93. p->width = width;
  94. p->skip_first = have_header != 0;
  95. }
  96. return p;
  97. }
  98. /* Trim the size of a seq_tab to the supplied number of rows. The operation is
  99. * irreversible.
  100. */
  101. static int seq_tab_trim(struct seq_tab *p, unsigned int new_rows)
  102. {
  103. if (new_rows > p->rows)
  104. return -EINVAL;
  105. p->rows = new_rows;
  106. return 0;
  107. }
  108. static int cim_la_show(struct seq_file *seq, void *v, int idx)
  109. {
  110. if (v == SEQ_START_TOKEN)
  111. seq_puts(seq, "Status Data PC LS0Stat LS0Addr "
  112. " LS0Data\n");
  113. else {
  114. const u32 *p = v;
  115. seq_printf(seq,
  116. " %02x %x%07x %x%07x %08x %08x %08x%08x%08x%08x\n",
  117. (p[0] >> 4) & 0xff, p[0] & 0xf, p[1] >> 4,
  118. p[1] & 0xf, p[2] >> 4, p[2] & 0xf, p[3], p[4], p[5],
  119. p[6], p[7]);
  120. }
  121. return 0;
  122. }
  123. static int cim_la_show_3in1(struct seq_file *seq, void *v, int idx)
  124. {
  125. if (v == SEQ_START_TOKEN) {
  126. seq_puts(seq, "Status Data PC\n");
  127. } else {
  128. const u32 *p = v;
  129. seq_printf(seq, " %02x %08x %08x\n", p[5] & 0xff, p[6],
  130. p[7]);
  131. seq_printf(seq, " %02x %02x%06x %02x%06x\n",
  132. (p[3] >> 8) & 0xff, p[3] & 0xff, p[4] >> 8,
  133. p[4] & 0xff, p[5] >> 8);
  134. seq_printf(seq, " %02x %x%07x %x%07x\n", (p[0] >> 4) & 0xff,
  135. p[0] & 0xf, p[1] >> 4, p[1] & 0xf, p[2] >> 4);
  136. }
  137. return 0;
  138. }
  139. static int cim_la_show_t6(struct seq_file *seq, void *v, int idx)
  140. {
  141. if (v == SEQ_START_TOKEN) {
  142. seq_puts(seq, "Status Inst Data PC LS0Stat "
  143. "LS0Addr LS0Data LS1Stat LS1Addr LS1Data\n");
  144. } else {
  145. const u32 *p = v;
  146. seq_printf(seq, " %02x %04x%04x %04x%04x %04x%04x %08x %08x %08x %08x %08x %08x\n",
  147. (p[9] >> 16) & 0xff, /* Status */
  148. p[9] & 0xffff, p[8] >> 16, /* Inst */
  149. p[8] & 0xffff, p[7] >> 16, /* Data */
  150. p[7] & 0xffff, p[6] >> 16, /* PC */
  151. p[2], p[1], p[0], /* LS0 Stat, Addr and Data */
  152. p[5], p[4], p[3]); /* LS1 Stat, Addr and Data */
  153. }
  154. return 0;
  155. }
  156. static int cim_la_show_pc_t6(struct seq_file *seq, void *v, int idx)
  157. {
  158. if (v == SEQ_START_TOKEN) {
  159. seq_puts(seq, "Status Inst Data PC\n");
  160. } else {
  161. const u32 *p = v;
  162. seq_printf(seq, " %02x %08x %08x %08x\n",
  163. p[3] & 0xff, p[2], p[1], p[0]);
  164. seq_printf(seq, " %02x %02x%06x %02x%06x %02x%06x\n",
  165. (p[6] >> 8) & 0xff, p[6] & 0xff, p[5] >> 8,
  166. p[5] & 0xff, p[4] >> 8, p[4] & 0xff, p[3] >> 8);
  167. seq_printf(seq, " %02x %04x%04x %04x%04x %04x%04x\n",
  168. (p[9] >> 16) & 0xff, p[9] & 0xffff, p[8] >> 16,
  169. p[8] & 0xffff, p[7] >> 16, p[7] & 0xffff,
  170. p[6] >> 16);
  171. }
  172. return 0;
  173. }
  174. static int cim_la_open(struct inode *inode, struct file *file)
  175. {
  176. int ret;
  177. unsigned int cfg;
  178. struct seq_tab *p;
  179. struct adapter *adap = inode->i_private;
  180. ret = t4_cim_read(adap, UP_UP_DBG_LA_CFG_A, 1, &cfg);
  181. if (ret)
  182. return ret;
  183. if (is_t6(adap->params.chip)) {
  184. /* +1 to account for integer division of CIMLA_SIZE/10 */
  185. p = seq_open_tab(file, (adap->params.cim_la_size / 10) + 1,
  186. 10 * sizeof(u32), 1,
  187. cfg & UPDBGLACAPTPCONLY_F ?
  188. cim_la_show_pc_t6 : cim_la_show_t6);
  189. } else {
  190. p = seq_open_tab(file, adap->params.cim_la_size / 8,
  191. 8 * sizeof(u32), 1,
  192. cfg & UPDBGLACAPTPCONLY_F ? cim_la_show_3in1 :
  193. cim_la_show);
  194. }
  195. if (!p)
  196. return -ENOMEM;
  197. ret = t4_cim_read_la(adap, (u32 *)p->data, NULL);
  198. if (ret)
  199. seq_release_private(inode, file);
  200. return ret;
  201. }
  202. static const struct file_operations cim_la_fops = {
  203. .owner = THIS_MODULE,
  204. .open = cim_la_open,
  205. .read = seq_read,
  206. .llseek = seq_lseek,
  207. .release = seq_release_private
  208. };
  209. static int cim_pif_la_show(struct seq_file *seq, void *v, int idx)
  210. {
  211. const u32 *p = v;
  212. if (v == SEQ_START_TOKEN) {
  213. seq_puts(seq, "Cntl ID DataBE Addr Data\n");
  214. } else if (idx < CIM_PIFLA_SIZE) {
  215. seq_printf(seq, " %02x %02x %04x %08x %08x%08x%08x%08x\n",
  216. (p[5] >> 22) & 0xff, (p[5] >> 16) & 0x3f,
  217. p[5] & 0xffff, p[4], p[3], p[2], p[1], p[0]);
  218. } else {
  219. if (idx == CIM_PIFLA_SIZE)
  220. seq_puts(seq, "\nCntl ID Data\n");
  221. seq_printf(seq, " %02x %02x %08x%08x%08x%08x\n",
  222. (p[4] >> 6) & 0xff, p[4] & 0x3f,
  223. p[3], p[2], p[1], p[0]);
  224. }
  225. return 0;
  226. }
  227. static int cim_pif_la_open(struct inode *inode, struct file *file)
  228. {
  229. struct seq_tab *p;
  230. struct adapter *adap = inode->i_private;
  231. p = seq_open_tab(file, 2 * CIM_PIFLA_SIZE, 6 * sizeof(u32), 1,
  232. cim_pif_la_show);
  233. if (!p)
  234. return -ENOMEM;
  235. t4_cim_read_pif_la(adap, (u32 *)p->data,
  236. (u32 *)p->data + 6 * CIM_PIFLA_SIZE, NULL, NULL);
  237. return 0;
  238. }
  239. static const struct file_operations cim_pif_la_fops = {
  240. .owner = THIS_MODULE,
  241. .open = cim_pif_la_open,
  242. .read = seq_read,
  243. .llseek = seq_lseek,
  244. .release = seq_release_private
  245. };
  246. static int cim_ma_la_show(struct seq_file *seq, void *v, int idx)
  247. {
  248. const u32 *p = v;
  249. if (v == SEQ_START_TOKEN) {
  250. seq_puts(seq, "\n");
  251. } else if (idx < CIM_MALA_SIZE) {
  252. seq_printf(seq, "%02x%08x%08x%08x%08x\n",
  253. p[4], p[3], p[2], p[1], p[0]);
  254. } else {
  255. if (idx == CIM_MALA_SIZE)
  256. seq_puts(seq,
  257. "\nCnt ID Tag UE Data RDY VLD\n");
  258. seq_printf(seq, "%3u %2u %x %u %08x%08x %u %u\n",
  259. (p[2] >> 10) & 0xff, (p[2] >> 7) & 7,
  260. (p[2] >> 3) & 0xf, (p[2] >> 2) & 1,
  261. (p[1] >> 2) | ((p[2] & 3) << 30),
  262. (p[0] >> 2) | ((p[1] & 3) << 30), (p[0] >> 1) & 1,
  263. p[0] & 1);
  264. }
  265. return 0;
  266. }
  267. static int cim_ma_la_open(struct inode *inode, struct file *file)
  268. {
  269. struct seq_tab *p;
  270. struct adapter *adap = inode->i_private;
  271. p = seq_open_tab(file, 2 * CIM_MALA_SIZE, 5 * sizeof(u32), 1,
  272. cim_ma_la_show);
  273. if (!p)
  274. return -ENOMEM;
  275. t4_cim_read_ma_la(adap, (u32 *)p->data,
  276. (u32 *)p->data + 5 * CIM_MALA_SIZE);
  277. return 0;
  278. }
  279. static const struct file_operations cim_ma_la_fops = {
  280. .owner = THIS_MODULE,
  281. .open = cim_ma_la_open,
  282. .read = seq_read,
  283. .llseek = seq_lseek,
  284. .release = seq_release_private
  285. };
  286. static int cim_qcfg_show(struct seq_file *seq, void *v)
  287. {
  288. static const char * const qname[] = {
  289. "TP0", "TP1", "ULP", "SGE0", "SGE1", "NC-SI",
  290. "ULP0", "ULP1", "ULP2", "ULP3", "SGE", "NC-SI",
  291. "SGE0-RX", "SGE1-RX"
  292. };
  293. int i;
  294. struct adapter *adap = seq->private;
  295. u16 base[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
  296. u16 size[CIM_NUM_IBQ + CIM_NUM_OBQ_T5];
  297. u32 stat[(4 * (CIM_NUM_IBQ + CIM_NUM_OBQ_T5))];
  298. u16 thres[CIM_NUM_IBQ];
  299. u32 obq_wr_t4[2 * CIM_NUM_OBQ], *wr;
  300. u32 obq_wr_t5[2 * CIM_NUM_OBQ_T5];
  301. u32 *p = stat;
  302. int cim_num_obq = is_t4(adap->params.chip) ?
  303. CIM_NUM_OBQ : CIM_NUM_OBQ_T5;
  304. i = t4_cim_read(adap, is_t4(adap->params.chip) ? UP_IBQ_0_RDADDR_A :
  305. UP_IBQ_0_SHADOW_RDADDR_A,
  306. ARRAY_SIZE(stat), stat);
  307. if (!i) {
  308. if (is_t4(adap->params.chip)) {
  309. i = t4_cim_read(adap, UP_OBQ_0_REALADDR_A,
  310. ARRAY_SIZE(obq_wr_t4), obq_wr_t4);
  311. wr = obq_wr_t4;
  312. } else {
  313. i = t4_cim_read(adap, UP_OBQ_0_SHADOW_REALADDR_A,
  314. ARRAY_SIZE(obq_wr_t5), obq_wr_t5);
  315. wr = obq_wr_t5;
  316. }
  317. }
  318. if (i)
  319. return i;
  320. t4_read_cimq_cfg(adap, base, size, thres);
  321. seq_printf(seq,
  322. " Queue Base Size Thres RdPtr WrPtr SOP EOP Avail\n");
  323. for (i = 0; i < CIM_NUM_IBQ; i++, p += 4)
  324. seq_printf(seq, "%7s %5x %5u %5u %6x %4x %4u %4u %5u\n",
  325. qname[i], base[i], size[i], thres[i],
  326. IBQRDADDR_G(p[0]), IBQWRADDR_G(p[1]),
  327. QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
  328. QUEREMFLITS_G(p[2]) * 16);
  329. for ( ; i < CIM_NUM_IBQ + cim_num_obq; i++, p += 4, wr += 2)
  330. seq_printf(seq, "%7s %5x %5u %12x %4x %4u %4u %5u\n",
  331. qname[i], base[i], size[i],
  332. QUERDADDR_G(p[0]) & 0x3fff, wr[0] - base[i],
  333. QUESOPCNT_G(p[3]), QUEEOPCNT_G(p[3]),
  334. QUEREMFLITS_G(p[2]) * 16);
  335. return 0;
  336. }
  337. static int cim_qcfg_open(struct inode *inode, struct file *file)
  338. {
  339. return single_open(file, cim_qcfg_show, inode->i_private);
  340. }
  341. static const struct file_operations cim_qcfg_fops = {
  342. .owner = THIS_MODULE,
  343. .open = cim_qcfg_open,
  344. .read = seq_read,
  345. .llseek = seq_lseek,
  346. .release = single_release,
  347. };
  348. static int cimq_show(struct seq_file *seq, void *v, int idx)
  349. {
  350. const u32 *p = v;
  351. seq_printf(seq, "%#06x: %08x %08x %08x %08x\n", idx * 16, p[0], p[1],
  352. p[2], p[3]);
  353. return 0;
  354. }
  355. static int cim_ibq_open(struct inode *inode, struct file *file)
  356. {
  357. int ret;
  358. struct seq_tab *p;
  359. unsigned int qid = (uintptr_t)inode->i_private & 7;
  360. struct adapter *adap = inode->i_private - qid;
  361. p = seq_open_tab(file, CIM_IBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
  362. if (!p)
  363. return -ENOMEM;
  364. ret = t4_read_cim_ibq(adap, qid, (u32 *)p->data, CIM_IBQ_SIZE * 4);
  365. if (ret < 0)
  366. seq_release_private(inode, file);
  367. else
  368. ret = 0;
  369. return ret;
  370. }
  371. static const struct file_operations cim_ibq_fops = {
  372. .owner = THIS_MODULE,
  373. .open = cim_ibq_open,
  374. .read = seq_read,
  375. .llseek = seq_lseek,
  376. .release = seq_release_private
  377. };
  378. static int cim_obq_open(struct inode *inode, struct file *file)
  379. {
  380. int ret;
  381. struct seq_tab *p;
  382. unsigned int qid = (uintptr_t)inode->i_private & 7;
  383. struct adapter *adap = inode->i_private - qid;
  384. p = seq_open_tab(file, 6 * CIM_OBQ_SIZE, 4 * sizeof(u32), 0, cimq_show);
  385. if (!p)
  386. return -ENOMEM;
  387. ret = t4_read_cim_obq(adap, qid, (u32 *)p->data, 6 * CIM_OBQ_SIZE * 4);
  388. if (ret < 0) {
  389. seq_release_private(inode, file);
  390. } else {
  391. seq_tab_trim(p, ret / 4);
  392. ret = 0;
  393. }
  394. return ret;
  395. }
  396. static const struct file_operations cim_obq_fops = {
  397. .owner = THIS_MODULE,
  398. .open = cim_obq_open,
  399. .read = seq_read,
  400. .llseek = seq_lseek,
  401. .release = seq_release_private
  402. };
  403. struct field_desc {
  404. const char *name;
  405. unsigned int start;
  406. unsigned int width;
  407. };
  408. static void field_desc_show(struct seq_file *seq, u64 v,
  409. const struct field_desc *p)
  410. {
  411. char buf[32];
  412. int line_size = 0;
  413. while (p->name) {
  414. u64 mask = (1ULL << p->width) - 1;
  415. int len = scnprintf(buf, sizeof(buf), "%s: %llu", p->name,
  416. ((unsigned long long)v >> p->start) & mask);
  417. if (line_size + len >= 79) {
  418. line_size = 8;
  419. seq_puts(seq, "\n ");
  420. }
  421. seq_printf(seq, "%s ", buf);
  422. line_size += len + 1;
  423. p++;
  424. }
  425. seq_putc(seq, '\n');
  426. }
  427. static struct field_desc tp_la0[] = {
  428. { "RcfOpCodeOut", 60, 4 },
  429. { "State", 56, 4 },
  430. { "WcfState", 52, 4 },
  431. { "RcfOpcSrcOut", 50, 2 },
  432. { "CRxError", 49, 1 },
  433. { "ERxError", 48, 1 },
  434. { "SanityFailed", 47, 1 },
  435. { "SpuriousMsg", 46, 1 },
  436. { "FlushInputMsg", 45, 1 },
  437. { "FlushInputCpl", 44, 1 },
  438. { "RssUpBit", 43, 1 },
  439. { "RssFilterHit", 42, 1 },
  440. { "Tid", 32, 10 },
  441. { "InitTcb", 31, 1 },
  442. { "LineNumber", 24, 7 },
  443. { "Emsg", 23, 1 },
  444. { "EdataOut", 22, 1 },
  445. { "Cmsg", 21, 1 },
  446. { "CdataOut", 20, 1 },
  447. { "EreadPdu", 19, 1 },
  448. { "CreadPdu", 18, 1 },
  449. { "TunnelPkt", 17, 1 },
  450. { "RcfPeerFin", 16, 1 },
  451. { "RcfReasonOut", 12, 4 },
  452. { "TxCchannel", 10, 2 },
  453. { "RcfTxChannel", 8, 2 },
  454. { "RxEchannel", 6, 2 },
  455. { "RcfRxChannel", 5, 1 },
  456. { "RcfDataOutSrdy", 4, 1 },
  457. { "RxDvld", 3, 1 },
  458. { "RxOoDvld", 2, 1 },
  459. { "RxCongestion", 1, 1 },
  460. { "TxCongestion", 0, 1 },
  461. { NULL }
  462. };
  463. static int tp_la_show(struct seq_file *seq, void *v, int idx)
  464. {
  465. const u64 *p = v;
  466. field_desc_show(seq, *p, tp_la0);
  467. return 0;
  468. }
  469. static int tp_la_show2(struct seq_file *seq, void *v, int idx)
  470. {
  471. const u64 *p = v;
  472. if (idx)
  473. seq_putc(seq, '\n');
  474. field_desc_show(seq, p[0], tp_la0);
  475. if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
  476. field_desc_show(seq, p[1], tp_la0);
  477. return 0;
  478. }
  479. static int tp_la_show3(struct seq_file *seq, void *v, int idx)
  480. {
  481. static struct field_desc tp_la1[] = {
  482. { "CplCmdIn", 56, 8 },
  483. { "CplCmdOut", 48, 8 },
  484. { "ESynOut", 47, 1 },
  485. { "EAckOut", 46, 1 },
  486. { "EFinOut", 45, 1 },
  487. { "ERstOut", 44, 1 },
  488. { "SynIn", 43, 1 },
  489. { "AckIn", 42, 1 },
  490. { "FinIn", 41, 1 },
  491. { "RstIn", 40, 1 },
  492. { "DataIn", 39, 1 },
  493. { "DataInVld", 38, 1 },
  494. { "PadIn", 37, 1 },
  495. { "RxBufEmpty", 36, 1 },
  496. { "RxDdp", 35, 1 },
  497. { "RxFbCongestion", 34, 1 },
  498. { "TxFbCongestion", 33, 1 },
  499. { "TxPktSumSrdy", 32, 1 },
  500. { "RcfUlpType", 28, 4 },
  501. { "Eread", 27, 1 },
  502. { "Ebypass", 26, 1 },
  503. { "Esave", 25, 1 },
  504. { "Static0", 24, 1 },
  505. { "Cread", 23, 1 },
  506. { "Cbypass", 22, 1 },
  507. { "Csave", 21, 1 },
  508. { "CPktOut", 20, 1 },
  509. { "RxPagePoolFull", 18, 2 },
  510. { "RxLpbkPkt", 17, 1 },
  511. { "TxLpbkPkt", 16, 1 },
  512. { "RxVfValid", 15, 1 },
  513. { "SynLearned", 14, 1 },
  514. { "SetDelEntry", 13, 1 },
  515. { "SetInvEntry", 12, 1 },
  516. { "CpcmdDvld", 11, 1 },
  517. { "CpcmdSave", 10, 1 },
  518. { "RxPstructsFull", 8, 2 },
  519. { "EpcmdDvld", 7, 1 },
  520. { "EpcmdFlush", 6, 1 },
  521. { "EpcmdTrimPrefix", 5, 1 },
  522. { "EpcmdTrimPostfix", 4, 1 },
  523. { "ERssIp4Pkt", 3, 1 },
  524. { "ERssIp6Pkt", 2, 1 },
  525. { "ERssTcpUdpPkt", 1, 1 },
  526. { "ERssFceFipPkt", 0, 1 },
  527. { NULL }
  528. };
  529. static struct field_desc tp_la2[] = {
  530. { "CplCmdIn", 56, 8 },
  531. { "MpsVfVld", 55, 1 },
  532. { "MpsPf", 52, 3 },
  533. { "MpsVf", 44, 8 },
  534. { "SynIn", 43, 1 },
  535. { "AckIn", 42, 1 },
  536. { "FinIn", 41, 1 },
  537. { "RstIn", 40, 1 },
  538. { "DataIn", 39, 1 },
  539. { "DataInVld", 38, 1 },
  540. { "PadIn", 37, 1 },
  541. { "RxBufEmpty", 36, 1 },
  542. { "RxDdp", 35, 1 },
  543. { "RxFbCongestion", 34, 1 },
  544. { "TxFbCongestion", 33, 1 },
  545. { "TxPktSumSrdy", 32, 1 },
  546. { "RcfUlpType", 28, 4 },
  547. { "Eread", 27, 1 },
  548. { "Ebypass", 26, 1 },
  549. { "Esave", 25, 1 },
  550. { "Static0", 24, 1 },
  551. { "Cread", 23, 1 },
  552. { "Cbypass", 22, 1 },
  553. { "Csave", 21, 1 },
  554. { "CPktOut", 20, 1 },
  555. { "RxPagePoolFull", 18, 2 },
  556. { "RxLpbkPkt", 17, 1 },
  557. { "TxLpbkPkt", 16, 1 },
  558. { "RxVfValid", 15, 1 },
  559. { "SynLearned", 14, 1 },
  560. { "SetDelEntry", 13, 1 },
  561. { "SetInvEntry", 12, 1 },
  562. { "CpcmdDvld", 11, 1 },
  563. { "CpcmdSave", 10, 1 },
  564. { "RxPstructsFull", 8, 2 },
  565. { "EpcmdDvld", 7, 1 },
  566. { "EpcmdFlush", 6, 1 },
  567. { "EpcmdTrimPrefix", 5, 1 },
  568. { "EpcmdTrimPostfix", 4, 1 },
  569. { "ERssIp4Pkt", 3, 1 },
  570. { "ERssIp6Pkt", 2, 1 },
  571. { "ERssTcpUdpPkt", 1, 1 },
  572. { "ERssFceFipPkt", 0, 1 },
  573. { NULL }
  574. };
  575. const u64 *p = v;
  576. if (idx)
  577. seq_putc(seq, '\n');
  578. field_desc_show(seq, p[0], tp_la0);
  579. if (idx < (TPLA_SIZE / 2 - 1) || p[1] != ~0ULL)
  580. field_desc_show(seq, p[1], (p[0] & BIT(17)) ? tp_la2 : tp_la1);
  581. return 0;
  582. }
  583. static int tp_la_open(struct inode *inode, struct file *file)
  584. {
  585. struct seq_tab *p;
  586. struct adapter *adap = inode->i_private;
  587. switch (DBGLAMODE_G(t4_read_reg(adap, TP_DBG_LA_CONFIG_A))) {
  588. case 2:
  589. p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
  590. tp_la_show2);
  591. break;
  592. case 3:
  593. p = seq_open_tab(file, TPLA_SIZE / 2, 2 * sizeof(u64), 0,
  594. tp_la_show3);
  595. break;
  596. default:
  597. p = seq_open_tab(file, TPLA_SIZE, sizeof(u64), 0, tp_la_show);
  598. }
  599. if (!p)
  600. return -ENOMEM;
  601. t4_tp_read_la(adap, (u64 *)p->data, NULL);
  602. return 0;
  603. }
  604. static ssize_t tp_la_write(struct file *file, const char __user *buf,
  605. size_t count, loff_t *pos)
  606. {
  607. int err;
  608. char s[32];
  609. unsigned long val;
  610. size_t size = min(sizeof(s) - 1, count);
  611. struct adapter *adap = file_inode(file)->i_private;
  612. if (copy_from_user(s, buf, size))
  613. return -EFAULT;
  614. s[size] = '\0';
  615. err = kstrtoul(s, 0, &val);
  616. if (err)
  617. return err;
  618. if (val > 0xffff)
  619. return -EINVAL;
  620. adap->params.tp.la_mask = val << 16;
  621. t4_set_reg_field(adap, TP_DBG_LA_CONFIG_A, 0xffff0000U,
  622. adap->params.tp.la_mask);
  623. return count;
  624. }
  625. static const struct file_operations tp_la_fops = {
  626. .owner = THIS_MODULE,
  627. .open = tp_la_open,
  628. .read = seq_read,
  629. .llseek = seq_lseek,
  630. .release = seq_release_private,
  631. .write = tp_la_write
  632. };
  633. static int ulprx_la_show(struct seq_file *seq, void *v, int idx)
  634. {
  635. const u32 *p = v;
  636. if (v == SEQ_START_TOKEN)
  637. seq_puts(seq, " Pcmd Type Message"
  638. " Data\n");
  639. else
  640. seq_printf(seq, "%08x%08x %4x %08x %08x%08x%08x%08x\n",
  641. p[1], p[0], p[2], p[3], p[7], p[6], p[5], p[4]);
  642. return 0;
  643. }
  644. static int ulprx_la_open(struct inode *inode, struct file *file)
  645. {
  646. struct seq_tab *p;
  647. struct adapter *adap = inode->i_private;
  648. p = seq_open_tab(file, ULPRX_LA_SIZE, 8 * sizeof(u32), 1,
  649. ulprx_la_show);
  650. if (!p)
  651. return -ENOMEM;
  652. t4_ulprx_read_la(adap, (u32 *)p->data);
  653. return 0;
  654. }
  655. static const struct file_operations ulprx_la_fops = {
  656. .owner = THIS_MODULE,
  657. .open = ulprx_la_open,
  658. .read = seq_read,
  659. .llseek = seq_lseek,
  660. .release = seq_release_private
  661. };
  662. /* Show the PM memory stats. These stats include:
  663. *
  664. * TX:
  665. * Read: memory read operation
  666. * Write Bypass: cut-through
  667. * Bypass + mem: cut-through and save copy
  668. *
  669. * RX:
  670. * Read: memory read
  671. * Write Bypass: cut-through
  672. * Flush: payload trim or drop
  673. */
  674. static int pm_stats_show(struct seq_file *seq, void *v)
  675. {
  676. static const char * const tx_pm_stats[] = {
  677. "Read:", "Write bypass:", "Write mem:", "Bypass + mem:"
  678. };
  679. static const char * const rx_pm_stats[] = {
  680. "Read:", "Write bypass:", "Write mem:", "Flush:"
  681. };
  682. int i;
  683. u32 tx_cnt[T6_PM_NSTATS], rx_cnt[T6_PM_NSTATS];
  684. u64 tx_cyc[T6_PM_NSTATS], rx_cyc[T6_PM_NSTATS];
  685. struct adapter *adap = seq->private;
  686. t4_pmtx_get_stats(adap, tx_cnt, tx_cyc);
  687. t4_pmrx_get_stats(adap, rx_cnt, rx_cyc);
  688. seq_printf(seq, "%13s %10s %20s\n", " ", "Tx pcmds", "Tx bytes");
  689. for (i = 0; i < PM_NSTATS - 1; i++)
  690. seq_printf(seq, "%-13s %10u %20llu\n",
  691. tx_pm_stats[i], tx_cnt[i], tx_cyc[i]);
  692. seq_printf(seq, "%13s %10s %20s\n", " ", "Rx pcmds", "Rx bytes");
  693. for (i = 0; i < PM_NSTATS - 1; i++)
  694. seq_printf(seq, "%-13s %10u %20llu\n",
  695. rx_pm_stats[i], rx_cnt[i], rx_cyc[i]);
  696. if (CHELSIO_CHIP_VERSION(adap->params.chip) > CHELSIO_T5) {
  697. /* In T5 the granularity of the total wait is too fine.
  698. * It is not useful as it reaches the max value too fast.
  699. * Hence display this Input FIFO wait for T6 onwards.
  700. */
  701. seq_printf(seq, "%13s %10s %20s\n",
  702. " ", "Total wait", "Total Occupancy");
  703. seq_printf(seq, "Tx FIFO wait %10u %20llu\n",
  704. tx_cnt[i], tx_cyc[i]);
  705. seq_printf(seq, "Rx FIFO wait %10u %20llu\n",
  706. rx_cnt[i], rx_cyc[i]);
  707. /* Skip index 6 as there is nothing useful ihere */
  708. i += 2;
  709. /* At index 7, a new stat for read latency (count, total wait)
  710. * is added.
  711. */
  712. seq_printf(seq, "%13s %10s %20s\n",
  713. " ", "Reads", "Total wait");
  714. seq_printf(seq, "Tx latency %10u %20llu\n",
  715. tx_cnt[i], tx_cyc[i]);
  716. seq_printf(seq, "Rx latency %10u %20llu\n",
  717. rx_cnt[i], rx_cyc[i]);
  718. }
  719. return 0;
  720. }
  721. static int pm_stats_open(struct inode *inode, struct file *file)
  722. {
  723. return single_open(file, pm_stats_show, inode->i_private);
  724. }
  725. static ssize_t pm_stats_clear(struct file *file, const char __user *buf,
  726. size_t count, loff_t *pos)
  727. {
  728. struct adapter *adap = file_inode(file)->i_private;
  729. t4_write_reg(adap, PM_RX_STAT_CONFIG_A, 0);
  730. t4_write_reg(adap, PM_TX_STAT_CONFIG_A, 0);
  731. return count;
  732. }
  733. static const struct file_operations pm_stats_debugfs_fops = {
  734. .owner = THIS_MODULE,
  735. .open = pm_stats_open,
  736. .read = seq_read,
  737. .llseek = seq_lseek,
  738. .release = single_release,
  739. .write = pm_stats_clear
  740. };
  741. static int tx_rate_show(struct seq_file *seq, void *v)
  742. {
  743. u64 nrate[NCHAN], orate[NCHAN];
  744. struct adapter *adap = seq->private;
  745. t4_get_chan_txrate(adap, nrate, orate);
  746. if (adap->params.arch.nchan == NCHAN) {
  747. seq_puts(seq, " channel 0 channel 1 "
  748. "channel 2 channel 3\n");
  749. seq_printf(seq, "NIC B/s: %10llu %10llu %10llu %10llu\n",
  750. (unsigned long long)nrate[0],
  751. (unsigned long long)nrate[1],
  752. (unsigned long long)nrate[2],
  753. (unsigned long long)nrate[3]);
  754. seq_printf(seq, "Offload B/s: %10llu %10llu %10llu %10llu\n",
  755. (unsigned long long)orate[0],
  756. (unsigned long long)orate[1],
  757. (unsigned long long)orate[2],
  758. (unsigned long long)orate[3]);
  759. } else {
  760. seq_puts(seq, " channel 0 channel 1\n");
  761. seq_printf(seq, "NIC B/s: %10llu %10llu\n",
  762. (unsigned long long)nrate[0],
  763. (unsigned long long)nrate[1]);
  764. seq_printf(seq, "Offload B/s: %10llu %10llu\n",
  765. (unsigned long long)orate[0],
  766. (unsigned long long)orate[1]);
  767. }
  768. return 0;
  769. }
  770. DEFINE_SIMPLE_DEBUGFS_FILE(tx_rate);
  771. static int cctrl_tbl_show(struct seq_file *seq, void *v)
  772. {
  773. static const char * const dec_fac[] = {
  774. "0.5", "0.5625", "0.625", "0.6875", "0.75", "0.8125", "0.875",
  775. "0.9375" };
  776. int i;
  777. u16 (*incr)[NCCTRL_WIN];
  778. struct adapter *adap = seq->private;
  779. incr = kmalloc_array(NMTUS, sizeof(*incr), GFP_KERNEL);
  780. if (!incr)
  781. return -ENOMEM;
  782. t4_read_cong_tbl(adap, incr);
  783. for (i = 0; i < NCCTRL_WIN; ++i) {
  784. seq_printf(seq, "%2d: %4u %4u %4u %4u %4u %4u %4u %4u\n", i,
  785. incr[0][i], incr[1][i], incr[2][i], incr[3][i],
  786. incr[4][i], incr[5][i], incr[6][i], incr[7][i]);
  787. seq_printf(seq, "%8u %4u %4u %4u %4u %4u %4u %4u %5u %s\n",
  788. incr[8][i], incr[9][i], incr[10][i], incr[11][i],
  789. incr[12][i], incr[13][i], incr[14][i], incr[15][i],
  790. adap->params.a_wnd[i],
  791. dec_fac[adap->params.b_wnd[i]]);
  792. }
  793. kfree(incr);
  794. return 0;
  795. }
  796. DEFINE_SIMPLE_DEBUGFS_FILE(cctrl_tbl);
  797. /* Format a value in a unit that differs from the value's native unit by the
  798. * given factor.
  799. */
  800. static char *unit_conv(char *buf, size_t len, unsigned int val,
  801. unsigned int factor)
  802. {
  803. unsigned int rem = val % factor;
  804. if (rem == 0) {
  805. snprintf(buf, len, "%u", val / factor);
  806. } else {
  807. while (rem % 10 == 0)
  808. rem /= 10;
  809. snprintf(buf, len, "%u.%u", val / factor, rem);
  810. }
  811. return buf;
  812. }
  813. static int clk_show(struct seq_file *seq, void *v)
  814. {
  815. char buf[32];
  816. struct adapter *adap = seq->private;
  817. unsigned int cclk_ps = 1000000000 / adap->params.vpd.cclk; /* in ps */
  818. u32 res = t4_read_reg(adap, TP_TIMER_RESOLUTION_A);
  819. unsigned int tre = TIMERRESOLUTION_G(res);
  820. unsigned int dack_re = DELAYEDACKRESOLUTION_G(res);
  821. unsigned long long tp_tick_us = (cclk_ps << tre) / 1000000; /* in us */
  822. seq_printf(seq, "Core clock period: %s ns\n",
  823. unit_conv(buf, sizeof(buf), cclk_ps, 1000));
  824. seq_printf(seq, "TP timer tick: %s us\n",
  825. unit_conv(buf, sizeof(buf), (cclk_ps << tre), 1000000));
  826. seq_printf(seq, "TCP timestamp tick: %s us\n",
  827. unit_conv(buf, sizeof(buf),
  828. (cclk_ps << TIMESTAMPRESOLUTION_G(res)), 1000000));
  829. seq_printf(seq, "DACK tick: %s us\n",
  830. unit_conv(buf, sizeof(buf), (cclk_ps << dack_re), 1000000));
  831. seq_printf(seq, "DACK timer: %u us\n",
  832. ((cclk_ps << dack_re) / 1000000) *
  833. t4_read_reg(adap, TP_DACK_TIMER_A));
  834. seq_printf(seq, "Retransmit min: %llu us\n",
  835. tp_tick_us * t4_read_reg(adap, TP_RXT_MIN_A));
  836. seq_printf(seq, "Retransmit max: %llu us\n",
  837. tp_tick_us * t4_read_reg(adap, TP_RXT_MAX_A));
  838. seq_printf(seq, "Persist timer min: %llu us\n",
  839. tp_tick_us * t4_read_reg(adap, TP_PERS_MIN_A));
  840. seq_printf(seq, "Persist timer max: %llu us\n",
  841. tp_tick_us * t4_read_reg(adap, TP_PERS_MAX_A));
  842. seq_printf(seq, "Keepalive idle timer: %llu us\n",
  843. tp_tick_us * t4_read_reg(adap, TP_KEEP_IDLE_A));
  844. seq_printf(seq, "Keepalive interval: %llu us\n",
  845. tp_tick_us * t4_read_reg(adap, TP_KEEP_INTVL_A));
  846. seq_printf(seq, "Initial SRTT: %llu us\n",
  847. tp_tick_us * INITSRTT_G(t4_read_reg(adap, TP_INIT_SRTT_A)));
  848. seq_printf(seq, "FINWAIT2 timer: %llu us\n",
  849. tp_tick_us * t4_read_reg(adap, TP_FINWAIT2_TIMER_A));
  850. return 0;
  851. }
  852. DEFINE_SIMPLE_DEBUGFS_FILE(clk);
  853. /* Firmware Device Log dump. */
  854. static const char * const devlog_level_strings[] = {
  855. [FW_DEVLOG_LEVEL_EMERG] = "EMERG",
  856. [FW_DEVLOG_LEVEL_CRIT] = "CRIT",
  857. [FW_DEVLOG_LEVEL_ERR] = "ERR",
  858. [FW_DEVLOG_LEVEL_NOTICE] = "NOTICE",
  859. [FW_DEVLOG_LEVEL_INFO] = "INFO",
  860. [FW_DEVLOG_LEVEL_DEBUG] = "DEBUG"
  861. };
  862. static const char * const devlog_facility_strings[] = {
  863. [FW_DEVLOG_FACILITY_CORE] = "CORE",
  864. [FW_DEVLOG_FACILITY_CF] = "CF",
  865. [FW_DEVLOG_FACILITY_SCHED] = "SCHED",
  866. [FW_DEVLOG_FACILITY_TIMER] = "TIMER",
  867. [FW_DEVLOG_FACILITY_RES] = "RES",
  868. [FW_DEVLOG_FACILITY_HW] = "HW",
  869. [FW_DEVLOG_FACILITY_FLR] = "FLR",
  870. [FW_DEVLOG_FACILITY_DMAQ] = "DMAQ",
  871. [FW_DEVLOG_FACILITY_PHY] = "PHY",
  872. [FW_DEVLOG_FACILITY_MAC] = "MAC",
  873. [FW_DEVLOG_FACILITY_PORT] = "PORT",
  874. [FW_DEVLOG_FACILITY_VI] = "VI",
  875. [FW_DEVLOG_FACILITY_FILTER] = "FILTER",
  876. [FW_DEVLOG_FACILITY_ACL] = "ACL",
  877. [FW_DEVLOG_FACILITY_TM] = "TM",
  878. [FW_DEVLOG_FACILITY_QFC] = "QFC",
  879. [FW_DEVLOG_FACILITY_DCB] = "DCB",
  880. [FW_DEVLOG_FACILITY_ETH] = "ETH",
  881. [FW_DEVLOG_FACILITY_OFLD] = "OFLD",
  882. [FW_DEVLOG_FACILITY_RI] = "RI",
  883. [FW_DEVLOG_FACILITY_ISCSI] = "ISCSI",
  884. [FW_DEVLOG_FACILITY_FCOE] = "FCOE",
  885. [FW_DEVLOG_FACILITY_FOISCSI] = "FOISCSI",
  886. [FW_DEVLOG_FACILITY_FOFCOE] = "FOFCOE"
  887. };
  888. /* Information gathered by Device Log Open routine for the display routine.
  889. */
  890. struct devlog_info {
  891. unsigned int nentries; /* number of entries in log[] */
  892. unsigned int first; /* first [temporal] entry in log[] */
  893. struct fw_devlog_e log[0]; /* Firmware Device Log */
  894. };
  895. /* Dump a Firmaware Device Log entry.
  896. */
  897. static int devlog_show(struct seq_file *seq, void *v)
  898. {
  899. if (v == SEQ_START_TOKEN)
  900. seq_printf(seq, "%10s %15s %8s %8s %s\n",
  901. "Seq#", "Tstamp", "Level", "Facility", "Message");
  902. else {
  903. struct devlog_info *dinfo = seq->private;
  904. int fidx = (uintptr_t)v - 2;
  905. unsigned long index;
  906. struct fw_devlog_e *e;
  907. /* Get a pointer to the log entry to display. Skip unused log
  908. * entries.
  909. */
  910. index = dinfo->first + fidx;
  911. if (index >= dinfo->nentries)
  912. index -= dinfo->nentries;
  913. e = &dinfo->log[index];
  914. if (e->timestamp == 0)
  915. return 0;
  916. /* Print the message. This depends on the firmware using
  917. * exactly the same formating strings as the kernel so we may
  918. * eventually have to put a format interpreter in here ...
  919. */
  920. seq_printf(seq, "%10d %15llu %8s %8s ",
  921. be32_to_cpu(e->seqno),
  922. be64_to_cpu(e->timestamp),
  923. (e->level < ARRAY_SIZE(devlog_level_strings)
  924. ? devlog_level_strings[e->level]
  925. : "UNKNOWN"),
  926. (e->facility < ARRAY_SIZE(devlog_facility_strings)
  927. ? devlog_facility_strings[e->facility]
  928. : "UNKNOWN"));
  929. seq_printf(seq, e->fmt,
  930. be32_to_cpu(e->params[0]),
  931. be32_to_cpu(e->params[1]),
  932. be32_to_cpu(e->params[2]),
  933. be32_to_cpu(e->params[3]),
  934. be32_to_cpu(e->params[4]),
  935. be32_to_cpu(e->params[5]),
  936. be32_to_cpu(e->params[6]),
  937. be32_to_cpu(e->params[7]));
  938. }
  939. return 0;
  940. }
  941. /* Sequential File Operations for Device Log.
  942. */
  943. static inline void *devlog_get_idx(struct devlog_info *dinfo, loff_t pos)
  944. {
  945. if (pos > dinfo->nentries)
  946. return NULL;
  947. return (void *)(uintptr_t)(pos + 1);
  948. }
  949. static void *devlog_start(struct seq_file *seq, loff_t *pos)
  950. {
  951. struct devlog_info *dinfo = seq->private;
  952. return (*pos
  953. ? devlog_get_idx(dinfo, *pos)
  954. : SEQ_START_TOKEN);
  955. }
  956. static void *devlog_next(struct seq_file *seq, void *v, loff_t *pos)
  957. {
  958. struct devlog_info *dinfo = seq->private;
  959. (*pos)++;
  960. return devlog_get_idx(dinfo, *pos);
  961. }
  962. static void devlog_stop(struct seq_file *seq, void *v)
  963. {
  964. }
  965. static const struct seq_operations devlog_seq_ops = {
  966. .start = devlog_start,
  967. .next = devlog_next,
  968. .stop = devlog_stop,
  969. .show = devlog_show
  970. };
  971. /* Set up for reading the firmware's device log. We read the entire log here
  972. * and then display it incrementally in devlog_show().
  973. */
  974. static int devlog_open(struct inode *inode, struct file *file)
  975. {
  976. struct adapter *adap = inode->i_private;
  977. struct devlog_params *dparams = &adap->params.devlog;
  978. struct devlog_info *dinfo;
  979. unsigned int index;
  980. u32 fseqno;
  981. int ret;
  982. /* If we don't know where the log is we can't do anything.
  983. */
  984. if (dparams->start == 0)
  985. return -ENXIO;
  986. /* Allocate the space to read in the firmware's device log and set up
  987. * for the iterated call to our display function.
  988. */
  989. dinfo = __seq_open_private(file, &devlog_seq_ops,
  990. sizeof(*dinfo) + dparams->size);
  991. if (!dinfo)
  992. return -ENOMEM;
  993. /* Record the basic log buffer information and read in the raw log.
  994. */
  995. dinfo->nentries = (dparams->size / sizeof(struct fw_devlog_e));
  996. dinfo->first = 0;
  997. spin_lock(&adap->win0_lock);
  998. ret = t4_memory_rw(adap, adap->params.drv_memwin, dparams->memtype,
  999. dparams->start, dparams->size, (__be32 *)dinfo->log,
  1000. T4_MEMORY_READ);
  1001. spin_unlock(&adap->win0_lock);
  1002. if (ret) {
  1003. seq_release_private(inode, file);
  1004. return ret;
  1005. }
  1006. /* Find the earliest (lowest Sequence Number) log entry in the
  1007. * circular Device Log.
  1008. */
  1009. for (fseqno = ~((u32)0), index = 0; index < dinfo->nentries; index++) {
  1010. struct fw_devlog_e *e = &dinfo->log[index];
  1011. __u32 seqno;
  1012. if (e->timestamp == 0)
  1013. continue;
  1014. seqno = be32_to_cpu(e->seqno);
  1015. if (seqno < fseqno) {
  1016. fseqno = seqno;
  1017. dinfo->first = index;
  1018. }
  1019. }
  1020. return 0;
  1021. }
  1022. static const struct file_operations devlog_fops = {
  1023. .owner = THIS_MODULE,
  1024. .open = devlog_open,
  1025. .read = seq_read,
  1026. .llseek = seq_lseek,
  1027. .release = seq_release_private
  1028. };
  1029. /* Show Firmware Mailbox Command/Reply Log
  1030. *
  1031. * Note that we don't do any locking when dumping the Firmware Mailbox Log so
  1032. * it's possible that we can catch things during a log update and therefore
  1033. * see partially corrupted log entries. But it's probably Good Enough(tm).
  1034. * If we ever decide that we want to make sure that we're dumping a coherent
  1035. * log, we'd need to perform locking in the mailbox logging and in
  1036. * mboxlog_open() where we'd need to grab the entire mailbox log in one go
  1037. * like we do for the Firmware Device Log.
  1038. */
  1039. static int mboxlog_show(struct seq_file *seq, void *v)
  1040. {
  1041. struct adapter *adapter = seq->private;
  1042. struct mbox_cmd_log *log = adapter->mbox_log;
  1043. struct mbox_cmd *entry;
  1044. int entry_idx, i;
  1045. if (v == SEQ_START_TOKEN) {
  1046. seq_printf(seq,
  1047. "%10s %15s %5s %5s %s\n",
  1048. "Seq#", "Tstamp", "Atime", "Etime",
  1049. "Command/Reply");
  1050. return 0;
  1051. }
  1052. entry_idx = log->cursor + ((uintptr_t)v - 2);
  1053. if (entry_idx >= log->size)
  1054. entry_idx -= log->size;
  1055. entry = mbox_cmd_log_entry(log, entry_idx);
  1056. /* skip over unused entries */
  1057. if (entry->timestamp == 0)
  1058. return 0;
  1059. seq_printf(seq, "%10u %15llu %5d %5d",
  1060. entry->seqno, entry->timestamp,
  1061. entry->access, entry->execute);
  1062. for (i = 0; i < MBOX_LEN / 8; i++) {
  1063. u64 flit = entry->cmd[i];
  1064. u32 hi = (u32)(flit >> 32);
  1065. u32 lo = (u32)flit;
  1066. seq_printf(seq, " %08x %08x", hi, lo);
  1067. }
  1068. seq_puts(seq, "\n");
  1069. return 0;
  1070. }
  1071. static inline void *mboxlog_get_idx(struct seq_file *seq, loff_t pos)
  1072. {
  1073. struct adapter *adapter = seq->private;
  1074. struct mbox_cmd_log *log = adapter->mbox_log;
  1075. return ((pos <= log->size) ? (void *)(uintptr_t)(pos + 1) : NULL);
  1076. }
  1077. static void *mboxlog_start(struct seq_file *seq, loff_t *pos)
  1078. {
  1079. return *pos ? mboxlog_get_idx(seq, *pos) : SEQ_START_TOKEN;
  1080. }
  1081. static void *mboxlog_next(struct seq_file *seq, void *v, loff_t *pos)
  1082. {
  1083. ++*pos;
  1084. return mboxlog_get_idx(seq, *pos);
  1085. }
  1086. static void mboxlog_stop(struct seq_file *seq, void *v)
  1087. {
  1088. }
  1089. static const struct seq_operations mboxlog_seq_ops = {
  1090. .start = mboxlog_start,
  1091. .next = mboxlog_next,
  1092. .stop = mboxlog_stop,
  1093. .show = mboxlog_show
  1094. };
  1095. static int mboxlog_open(struct inode *inode, struct file *file)
  1096. {
  1097. int res = seq_open(file, &mboxlog_seq_ops);
  1098. if (!res) {
  1099. struct seq_file *seq = file->private_data;
  1100. seq->private = inode->i_private;
  1101. }
  1102. return res;
  1103. }
  1104. static const struct file_operations mboxlog_fops = {
  1105. .owner = THIS_MODULE,
  1106. .open = mboxlog_open,
  1107. .read = seq_read,
  1108. .llseek = seq_lseek,
  1109. .release = seq_release,
  1110. };
  1111. static int mbox_show(struct seq_file *seq, void *v)
  1112. {
  1113. static const char * const owner[] = { "none", "FW", "driver",
  1114. "unknown", "<unread>" };
  1115. int i;
  1116. unsigned int mbox = (uintptr_t)seq->private & 7;
  1117. struct adapter *adap = seq->private - mbox;
  1118. void __iomem *addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
  1119. /* For T4 we don't have a shadow copy of the Mailbox Control register.
  1120. * And since reading that real register causes a side effect of
  1121. * granting ownership, we're best of simply not reading it at all.
  1122. */
  1123. if (is_t4(adap->params.chip)) {
  1124. i = 4; /* index of "<unread>" */
  1125. } else {
  1126. unsigned int ctrl_reg = CIM_PF_MAILBOX_CTRL_SHADOW_COPY_A;
  1127. void __iomem *ctrl = adap->regs + PF_REG(mbox, ctrl_reg);
  1128. i = MBOWNER_G(readl(ctrl));
  1129. }
  1130. seq_printf(seq, "mailbox owned by %s\n\n", owner[i]);
  1131. for (i = 0; i < MBOX_LEN; i += 8)
  1132. seq_printf(seq, "%016llx\n",
  1133. (unsigned long long)readq(addr + i));
  1134. return 0;
  1135. }
  1136. static int mbox_open(struct inode *inode, struct file *file)
  1137. {
  1138. return single_open(file, mbox_show, inode->i_private);
  1139. }
  1140. static ssize_t mbox_write(struct file *file, const char __user *buf,
  1141. size_t count, loff_t *pos)
  1142. {
  1143. int i;
  1144. char c = '\n', s[256];
  1145. unsigned long long data[8];
  1146. const struct inode *ino;
  1147. unsigned int mbox;
  1148. struct adapter *adap;
  1149. void __iomem *addr;
  1150. void __iomem *ctrl;
  1151. if (count > sizeof(s) - 1 || !count)
  1152. return -EINVAL;
  1153. if (copy_from_user(s, buf, count))
  1154. return -EFAULT;
  1155. s[count] = '\0';
  1156. if (sscanf(s, "%llx %llx %llx %llx %llx %llx %llx %llx%c", &data[0],
  1157. &data[1], &data[2], &data[3], &data[4], &data[5], &data[6],
  1158. &data[7], &c) < 8 || c != '\n')
  1159. return -EINVAL;
  1160. ino = file_inode(file);
  1161. mbox = (uintptr_t)ino->i_private & 7;
  1162. adap = ino->i_private - mbox;
  1163. addr = adap->regs + PF_REG(mbox, CIM_PF_MAILBOX_DATA_A);
  1164. ctrl = addr + MBOX_LEN;
  1165. if (MBOWNER_G(readl(ctrl)) != X_MBOWNER_PL)
  1166. return -EBUSY;
  1167. for (i = 0; i < 8; i++)
  1168. writeq(data[i], addr + 8 * i);
  1169. writel(MBMSGVALID_F | MBOWNER_V(X_MBOWNER_FW), ctrl);
  1170. return count;
  1171. }
  1172. static const struct file_operations mbox_debugfs_fops = {
  1173. .owner = THIS_MODULE,
  1174. .open = mbox_open,
  1175. .read = seq_read,
  1176. .llseek = seq_lseek,
  1177. .release = single_release,
  1178. .write = mbox_write
  1179. };
  1180. static int mps_trc_show(struct seq_file *seq, void *v)
  1181. {
  1182. int enabled, i;
  1183. struct trace_params tp;
  1184. unsigned int trcidx = (uintptr_t)seq->private & 3;
  1185. struct adapter *adap = seq->private - trcidx;
  1186. t4_get_trace_filter(adap, &tp, trcidx, &enabled);
  1187. if (!enabled) {
  1188. seq_puts(seq, "tracer is disabled\n");
  1189. return 0;
  1190. }
  1191. if (tp.skip_ofst * 8 >= TRACE_LEN) {
  1192. dev_err(adap->pdev_dev, "illegal trace pattern skip offset\n");
  1193. return -EINVAL;
  1194. }
  1195. if (tp.port < 8) {
  1196. i = adap->chan_map[tp.port & 3];
  1197. if (i >= MAX_NPORTS) {
  1198. dev_err(adap->pdev_dev, "tracer %u is assigned "
  1199. "to non-existing port\n", trcidx);
  1200. return -EINVAL;
  1201. }
  1202. seq_printf(seq, "tracer is capturing %s %s, ",
  1203. adap->port[i]->name, tp.port < 4 ? "Rx" : "Tx");
  1204. } else
  1205. seq_printf(seq, "tracer is capturing loopback %d, ",
  1206. tp.port - 8);
  1207. seq_printf(seq, "snap length: %u, min length: %u\n", tp.snap_len,
  1208. tp.min_len);
  1209. seq_printf(seq, "packets captured %smatch filter\n",
  1210. tp.invert ? "do not " : "");
  1211. if (tp.skip_ofst) {
  1212. seq_puts(seq, "filter pattern: ");
  1213. for (i = 0; i < tp.skip_ofst * 2; i += 2)
  1214. seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
  1215. seq_putc(seq, '/');
  1216. for (i = 0; i < tp.skip_ofst * 2; i += 2)
  1217. seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
  1218. seq_puts(seq, "@0\n");
  1219. }
  1220. seq_puts(seq, "filter pattern: ");
  1221. for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
  1222. seq_printf(seq, "%08x%08x", tp.data[i], tp.data[i + 1]);
  1223. seq_putc(seq, '/');
  1224. for (i = tp.skip_ofst * 2; i < TRACE_LEN / 4; i += 2)
  1225. seq_printf(seq, "%08x%08x", tp.mask[i], tp.mask[i + 1]);
  1226. seq_printf(seq, "@%u\n", (tp.skip_ofst + tp.skip_len) * 8);
  1227. return 0;
  1228. }
  1229. static int mps_trc_open(struct inode *inode, struct file *file)
  1230. {
  1231. return single_open(file, mps_trc_show, inode->i_private);
  1232. }
  1233. static unsigned int xdigit2int(unsigned char c)
  1234. {
  1235. return isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
  1236. }
  1237. #define TRC_PORT_NONE 0xff
  1238. #define TRC_RSS_ENABLE 0x33
  1239. #define TRC_RSS_DISABLE 0x13
  1240. /* Set an MPS trace filter. Syntax is:
  1241. *
  1242. * disable
  1243. *
  1244. * to disable tracing, or
  1245. *
  1246. * interface qid=<qid no> [snaplen=<val>] [minlen=<val>] [not] [<pattern>]...
  1247. *
  1248. * where interface is one of rxN, txN, or loopbackN, N = 0..3, qid can be one
  1249. * of the NIC's response qid obtained from sge_qinfo and pattern has the form
  1250. *
  1251. * <pattern data>[/<pattern mask>][@<anchor>]
  1252. *
  1253. * Up to 2 filter patterns can be specified. If 2 are supplied the first one
  1254. * must be anchored at 0. An omitted mask is taken as a mask of 1s, an omitted
  1255. * anchor is taken as 0.
  1256. */
  1257. static ssize_t mps_trc_write(struct file *file, const char __user *buf,
  1258. size_t count, loff_t *pos)
  1259. {
  1260. int i, enable, ret;
  1261. u32 *data, *mask;
  1262. struct trace_params tp;
  1263. const struct inode *ino;
  1264. unsigned int trcidx;
  1265. char *s, *p, *word, *end;
  1266. struct adapter *adap;
  1267. u32 j;
  1268. ino = file_inode(file);
  1269. trcidx = (uintptr_t)ino->i_private & 3;
  1270. adap = ino->i_private - trcidx;
  1271. /* Don't accept input more than 1K, can't be anything valid except lots
  1272. * of whitespace. Well, use less.
  1273. */
  1274. if (count > 1024)
  1275. return -EFBIG;
  1276. p = s = kzalloc(count + 1, GFP_USER);
  1277. if (!s)
  1278. return -ENOMEM;
  1279. if (copy_from_user(s, buf, count)) {
  1280. count = -EFAULT;
  1281. goto out;
  1282. }
  1283. if (s[count - 1] == '\n')
  1284. s[count - 1] = '\0';
  1285. enable = strcmp("disable", s) != 0;
  1286. if (!enable)
  1287. goto apply;
  1288. /* enable or disable trace multi rss filter */
  1289. if (adap->trace_rss)
  1290. t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_ENABLE);
  1291. else
  1292. t4_write_reg(adap, MPS_TRC_CFG_A, TRC_RSS_DISABLE);
  1293. memset(&tp, 0, sizeof(tp));
  1294. tp.port = TRC_PORT_NONE;
  1295. i = 0; /* counts pattern nibbles */
  1296. while (p) {
  1297. while (isspace(*p))
  1298. p++;
  1299. word = strsep(&p, " ");
  1300. if (!*word)
  1301. break;
  1302. if (!strncmp(word, "qid=", 4)) {
  1303. end = (char *)word + 4;
  1304. ret = kstrtouint(end, 10, &j);
  1305. if (ret)
  1306. goto out;
  1307. if (!adap->trace_rss) {
  1308. t4_write_reg(adap, MPS_T5_TRC_RSS_CONTROL_A, j);
  1309. continue;
  1310. }
  1311. switch (trcidx) {
  1312. case 0:
  1313. t4_write_reg(adap, MPS_TRC_RSS_CONTROL_A, j);
  1314. break;
  1315. case 1:
  1316. t4_write_reg(adap,
  1317. MPS_TRC_FILTER1_RSS_CONTROL_A, j);
  1318. break;
  1319. case 2:
  1320. t4_write_reg(adap,
  1321. MPS_TRC_FILTER2_RSS_CONTROL_A, j);
  1322. break;
  1323. case 3:
  1324. t4_write_reg(adap,
  1325. MPS_TRC_FILTER3_RSS_CONTROL_A, j);
  1326. break;
  1327. }
  1328. continue;
  1329. }
  1330. if (!strncmp(word, "snaplen=", 8)) {
  1331. end = (char *)word + 8;
  1332. ret = kstrtouint(end, 10, &j);
  1333. if (ret || j > 9600) {
  1334. inval: count = -EINVAL;
  1335. goto out;
  1336. }
  1337. tp.snap_len = j;
  1338. continue;
  1339. }
  1340. if (!strncmp(word, "minlen=", 7)) {
  1341. end = (char *)word + 7;
  1342. ret = kstrtouint(end, 10, &j);
  1343. if (ret || j > TFMINPKTSIZE_M)
  1344. goto inval;
  1345. tp.min_len = j;
  1346. continue;
  1347. }
  1348. if (!strcmp(word, "not")) {
  1349. tp.invert = !tp.invert;
  1350. continue;
  1351. }
  1352. if (!strncmp(word, "loopback", 8) && tp.port == TRC_PORT_NONE) {
  1353. if (word[8] < '0' || word[8] > '3' || word[9])
  1354. goto inval;
  1355. tp.port = word[8] - '0' + 8;
  1356. continue;
  1357. }
  1358. if (!strncmp(word, "tx", 2) && tp.port == TRC_PORT_NONE) {
  1359. if (word[2] < '0' || word[2] > '3' || word[3])
  1360. goto inval;
  1361. tp.port = word[2] - '0' + 4;
  1362. if (adap->chan_map[tp.port & 3] >= MAX_NPORTS)
  1363. goto inval;
  1364. continue;
  1365. }
  1366. if (!strncmp(word, "rx", 2) && tp.port == TRC_PORT_NONE) {
  1367. if (word[2] < '0' || word[2] > '3' || word[3])
  1368. goto inval;
  1369. tp.port = word[2] - '0';
  1370. if (adap->chan_map[tp.port] >= MAX_NPORTS)
  1371. goto inval;
  1372. continue;
  1373. }
  1374. if (!isxdigit(*word))
  1375. goto inval;
  1376. /* we have found a trace pattern */
  1377. if (i) { /* split pattern */
  1378. if (tp.skip_len) /* too many splits */
  1379. goto inval;
  1380. tp.skip_ofst = i / 16;
  1381. }
  1382. data = &tp.data[i / 8];
  1383. mask = &tp.mask[i / 8];
  1384. j = i;
  1385. while (isxdigit(*word)) {
  1386. if (i >= TRACE_LEN * 2) {
  1387. count = -EFBIG;
  1388. goto out;
  1389. }
  1390. *data = (*data << 4) + xdigit2int(*word++);
  1391. if (++i % 8 == 0)
  1392. data++;
  1393. }
  1394. if (*word == '/') {
  1395. word++;
  1396. while (isxdigit(*word)) {
  1397. if (j >= i) /* mask longer than data */
  1398. goto inval;
  1399. *mask = (*mask << 4) + xdigit2int(*word++);
  1400. if (++j % 8 == 0)
  1401. mask++;
  1402. }
  1403. if (i != j) /* mask shorter than data */
  1404. goto inval;
  1405. } else { /* no mask, use all 1s */
  1406. for ( ; i - j >= 8; j += 8)
  1407. *mask++ = 0xffffffff;
  1408. if (i % 8)
  1409. *mask = (1 << (i % 8) * 4) - 1;
  1410. }
  1411. if (*word == '@') {
  1412. end = (char *)word + 1;
  1413. ret = kstrtouint(end, 10, &j);
  1414. if (*end && *end != '\n')
  1415. goto inval;
  1416. if (j & 7) /* doesn't start at multiple of 8 */
  1417. goto inval;
  1418. j /= 8;
  1419. if (j < tp.skip_ofst) /* overlaps earlier pattern */
  1420. goto inval;
  1421. if (j - tp.skip_ofst > 31) /* skip too big */
  1422. goto inval;
  1423. tp.skip_len = j - tp.skip_ofst;
  1424. }
  1425. if (i % 8) {
  1426. *data <<= (8 - i % 8) * 4;
  1427. *mask <<= (8 - i % 8) * 4;
  1428. i = (i + 15) & ~15; /* 8-byte align */
  1429. }
  1430. }
  1431. if (tp.port == TRC_PORT_NONE)
  1432. goto inval;
  1433. apply:
  1434. i = t4_set_trace_filter(adap, &tp, trcidx, enable);
  1435. if (i)
  1436. count = i;
  1437. out:
  1438. kfree(s);
  1439. return count;
  1440. }
  1441. static const struct file_operations mps_trc_debugfs_fops = {
  1442. .owner = THIS_MODULE,
  1443. .open = mps_trc_open,
  1444. .read = seq_read,
  1445. .llseek = seq_lseek,
  1446. .release = single_release,
  1447. .write = mps_trc_write
  1448. };
  1449. static ssize_t flash_read(struct file *file, char __user *buf, size_t count,
  1450. loff_t *ppos)
  1451. {
  1452. loff_t pos = *ppos;
  1453. loff_t avail = file_inode(file)->i_size;
  1454. struct adapter *adap = file->private_data;
  1455. if (pos < 0)
  1456. return -EINVAL;
  1457. if (pos >= avail)
  1458. return 0;
  1459. if (count > avail - pos)
  1460. count = avail - pos;
  1461. while (count) {
  1462. size_t len;
  1463. int ret, ofst;
  1464. u8 data[256];
  1465. ofst = pos & 3;
  1466. len = min(count + ofst, sizeof(data));
  1467. ret = t4_read_flash(adap, pos - ofst, (len + 3) / 4,
  1468. (u32 *)data, 1);
  1469. if (ret)
  1470. return ret;
  1471. len -= ofst;
  1472. if (copy_to_user(buf, data + ofst, len))
  1473. return -EFAULT;
  1474. buf += len;
  1475. pos += len;
  1476. count -= len;
  1477. }
  1478. count = pos - *ppos;
  1479. *ppos = pos;
  1480. return count;
  1481. }
  1482. static const struct file_operations flash_debugfs_fops = {
  1483. .owner = THIS_MODULE,
  1484. .open = mem_open,
  1485. .read = flash_read,
  1486. .llseek = default_llseek,
  1487. };
  1488. static inline void tcamxy2valmask(u64 x, u64 y, u8 *addr, u64 *mask)
  1489. {
  1490. *mask = x | y;
  1491. y = (__force u64)cpu_to_be64(y);
  1492. memcpy(addr, (char *)&y + 2, ETH_ALEN);
  1493. }
  1494. static int mps_tcam_show(struct seq_file *seq, void *v)
  1495. {
  1496. struct adapter *adap = seq->private;
  1497. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adap->params.chip);
  1498. if (v == SEQ_START_TOKEN) {
  1499. if (chip_ver > CHELSIO_T5) {
  1500. seq_puts(seq, "Idx Ethernet address Mask "
  1501. " VNI Mask IVLAN Vld "
  1502. "DIP_Hit Lookup Port "
  1503. "Vld Ports PF VF "
  1504. "Replication "
  1505. " P0 P1 P2 P3 ML\n");
  1506. } else {
  1507. if (adap->params.arch.mps_rplc_size > 128)
  1508. seq_puts(seq, "Idx Ethernet address Mask "
  1509. "Vld Ports PF VF "
  1510. "Replication "
  1511. " P0 P1 P2 P3 ML\n");
  1512. else
  1513. seq_puts(seq, "Idx Ethernet address Mask "
  1514. "Vld Ports PF VF Replication"
  1515. " P0 P1 P2 P3 ML\n");
  1516. }
  1517. } else {
  1518. u64 mask;
  1519. u8 addr[ETH_ALEN];
  1520. bool replicate, dip_hit = false, vlan_vld = false;
  1521. unsigned int idx = (uintptr_t)v - 2;
  1522. u64 tcamy, tcamx, val;
  1523. u32 cls_lo, cls_hi, ctl, data2, vnix = 0, vniy = 0;
  1524. u32 rplc[8] = {0};
  1525. u8 lookup_type = 0, port_num = 0;
  1526. u16 ivlan = 0;
  1527. if (chip_ver > CHELSIO_T5) {
  1528. /* CtlCmdType - 0: Read, 1: Write
  1529. * CtlTcamSel - 0: TCAM0, 1: TCAM1
  1530. * CtlXYBitSel- 0: Y bit, 1: X bit
  1531. */
  1532. /* Read tcamy */
  1533. ctl = CTLCMDTYPE_V(0) | CTLXYBITSEL_V(0);
  1534. if (idx < 256)
  1535. ctl |= CTLTCAMINDEX_V(idx) | CTLTCAMSEL_V(0);
  1536. else
  1537. ctl |= CTLTCAMINDEX_V(idx - 256) |
  1538. CTLTCAMSEL_V(1);
  1539. t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
  1540. val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
  1541. tcamy = DMACH_G(val) << 32;
  1542. tcamy |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
  1543. data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
  1544. lookup_type = DATALKPTYPE_G(data2);
  1545. /* 0 - Outer header, 1 - Inner header
  1546. * [71:48] bit locations are overloaded for
  1547. * outer vs. inner lookup types.
  1548. */
  1549. if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
  1550. /* Inner header VNI */
  1551. vniy = (data2 & DATAVIDH2_F) |
  1552. (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
  1553. dip_hit = data2 & DATADIPHIT_F;
  1554. } else {
  1555. vlan_vld = data2 & DATAVIDH2_F;
  1556. ivlan = VIDL_G(val);
  1557. }
  1558. port_num = DATAPORTNUM_G(data2);
  1559. /* Read tcamx. Change the control param */
  1560. vnix = 0;
  1561. ctl |= CTLXYBITSEL_V(1);
  1562. t4_write_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A, ctl);
  1563. val = t4_read_reg(adap, MPS_CLS_TCAM_DATA1_A);
  1564. tcamx = DMACH_G(val) << 32;
  1565. tcamx |= t4_read_reg(adap, MPS_CLS_TCAM_DATA0_A);
  1566. data2 = t4_read_reg(adap, MPS_CLS_TCAM_DATA2_CTL_A);
  1567. if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
  1568. /* Inner header VNI mask */
  1569. vnix = (data2 & DATAVIDH2_F) |
  1570. (DATAVIDH1_G(data2) << 16) | VIDL_G(val);
  1571. }
  1572. } else {
  1573. tcamy = t4_read_reg64(adap, MPS_CLS_TCAM_Y_L(idx));
  1574. tcamx = t4_read_reg64(adap, MPS_CLS_TCAM_X_L(idx));
  1575. }
  1576. cls_lo = t4_read_reg(adap, MPS_CLS_SRAM_L(idx));
  1577. cls_hi = t4_read_reg(adap, MPS_CLS_SRAM_H(idx));
  1578. if (tcamx & tcamy) {
  1579. seq_printf(seq, "%3u -\n", idx);
  1580. goto out;
  1581. }
  1582. rplc[0] = rplc[1] = rplc[2] = rplc[3] = 0;
  1583. if (chip_ver > CHELSIO_T5)
  1584. replicate = (cls_lo & T6_REPLICATE_F);
  1585. else
  1586. replicate = (cls_lo & REPLICATE_F);
  1587. if (replicate) {
  1588. struct fw_ldst_cmd ldst_cmd;
  1589. int ret;
  1590. struct fw_ldst_mps_rplc mps_rplc;
  1591. u32 ldst_addrspc;
  1592. memset(&ldst_cmd, 0, sizeof(ldst_cmd));
  1593. ldst_addrspc =
  1594. FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_MPS);
  1595. ldst_cmd.op_to_addrspace =
  1596. htonl(FW_CMD_OP_V(FW_LDST_CMD) |
  1597. FW_CMD_REQUEST_F |
  1598. FW_CMD_READ_F |
  1599. ldst_addrspc);
  1600. ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
  1601. ldst_cmd.u.mps.rplc.fid_idx =
  1602. htons(FW_LDST_CMD_FID_V(FW_LDST_MPS_RPLC) |
  1603. FW_LDST_CMD_IDX_V(idx));
  1604. ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd,
  1605. sizeof(ldst_cmd), &ldst_cmd);
  1606. if (ret)
  1607. dev_warn(adap->pdev_dev, "Can't read MPS "
  1608. "replication map for idx %d: %d\n",
  1609. idx, -ret);
  1610. else {
  1611. mps_rplc = ldst_cmd.u.mps.rplc;
  1612. rplc[0] = ntohl(mps_rplc.rplc31_0);
  1613. rplc[1] = ntohl(mps_rplc.rplc63_32);
  1614. rplc[2] = ntohl(mps_rplc.rplc95_64);
  1615. rplc[3] = ntohl(mps_rplc.rplc127_96);
  1616. if (adap->params.arch.mps_rplc_size > 128) {
  1617. rplc[4] = ntohl(mps_rplc.rplc159_128);
  1618. rplc[5] = ntohl(mps_rplc.rplc191_160);
  1619. rplc[6] = ntohl(mps_rplc.rplc223_192);
  1620. rplc[7] = ntohl(mps_rplc.rplc255_224);
  1621. }
  1622. }
  1623. }
  1624. tcamxy2valmask(tcamx, tcamy, addr, &mask);
  1625. if (chip_ver > CHELSIO_T5) {
  1626. /* Inner header lookup */
  1627. if (lookup_type && (lookup_type != DATALKPTYPE_M)) {
  1628. seq_printf(seq,
  1629. "%3u %02x:%02x:%02x:%02x:%02x:%02x "
  1630. "%012llx %06x %06x - - %3c"
  1631. " 'I' %4x "
  1632. "%3c %#x%4u%4d", idx, addr[0],
  1633. addr[1], addr[2], addr[3],
  1634. addr[4], addr[5],
  1635. (unsigned long long)mask,
  1636. vniy, (vnix | vniy),
  1637. dip_hit ? 'Y' : 'N',
  1638. port_num,
  1639. (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
  1640. PORTMAP_G(cls_hi),
  1641. T6_PF_G(cls_lo),
  1642. (cls_lo & T6_VF_VALID_F) ?
  1643. T6_VF_G(cls_lo) : -1);
  1644. } else {
  1645. seq_printf(seq,
  1646. "%3u %02x:%02x:%02x:%02x:%02x:%02x "
  1647. "%012llx - - ",
  1648. idx, addr[0], addr[1], addr[2],
  1649. addr[3], addr[4], addr[5],
  1650. (unsigned long long)mask);
  1651. if (vlan_vld)
  1652. seq_printf(seq, "%4u Y ", ivlan);
  1653. else
  1654. seq_puts(seq, " - N ");
  1655. seq_printf(seq,
  1656. "- %3c %4x %3c %#x%4u%4d",
  1657. lookup_type ? 'I' : 'O', port_num,
  1658. (cls_lo & T6_SRAM_VLD_F) ? 'Y' : 'N',
  1659. PORTMAP_G(cls_hi),
  1660. T6_PF_G(cls_lo),
  1661. (cls_lo & T6_VF_VALID_F) ?
  1662. T6_VF_G(cls_lo) : -1);
  1663. }
  1664. } else
  1665. seq_printf(seq, "%3u %02x:%02x:%02x:%02x:%02x:%02x "
  1666. "%012llx%3c %#x%4u%4d",
  1667. idx, addr[0], addr[1], addr[2], addr[3],
  1668. addr[4], addr[5], (unsigned long long)mask,
  1669. (cls_lo & SRAM_VLD_F) ? 'Y' : 'N',
  1670. PORTMAP_G(cls_hi),
  1671. PF_G(cls_lo),
  1672. (cls_lo & VF_VALID_F) ? VF_G(cls_lo) : -1);
  1673. if (replicate) {
  1674. if (adap->params.arch.mps_rplc_size > 128)
  1675. seq_printf(seq, " %08x %08x %08x %08x "
  1676. "%08x %08x %08x %08x",
  1677. rplc[7], rplc[6], rplc[5], rplc[4],
  1678. rplc[3], rplc[2], rplc[1], rplc[0]);
  1679. else
  1680. seq_printf(seq, " %08x %08x %08x %08x",
  1681. rplc[3], rplc[2], rplc[1], rplc[0]);
  1682. } else {
  1683. if (adap->params.arch.mps_rplc_size > 128)
  1684. seq_printf(seq, "%72c", ' ');
  1685. else
  1686. seq_printf(seq, "%36c", ' ');
  1687. }
  1688. if (chip_ver > CHELSIO_T5)
  1689. seq_printf(seq, "%4u%3u%3u%3u %#x\n",
  1690. T6_SRAM_PRIO0_G(cls_lo),
  1691. T6_SRAM_PRIO1_G(cls_lo),
  1692. T6_SRAM_PRIO2_G(cls_lo),
  1693. T6_SRAM_PRIO3_G(cls_lo),
  1694. (cls_lo >> T6_MULTILISTEN0_S) & 0xf);
  1695. else
  1696. seq_printf(seq, "%4u%3u%3u%3u %#x\n",
  1697. SRAM_PRIO0_G(cls_lo), SRAM_PRIO1_G(cls_lo),
  1698. SRAM_PRIO2_G(cls_lo), SRAM_PRIO3_G(cls_lo),
  1699. (cls_lo >> MULTILISTEN0_S) & 0xf);
  1700. }
  1701. out: return 0;
  1702. }
  1703. static inline void *mps_tcam_get_idx(struct seq_file *seq, loff_t pos)
  1704. {
  1705. struct adapter *adap = seq->private;
  1706. int max_mac_addr = is_t4(adap->params.chip) ?
  1707. NUM_MPS_CLS_SRAM_L_INSTANCES :
  1708. NUM_MPS_T5_CLS_SRAM_L_INSTANCES;
  1709. return ((pos <= max_mac_addr) ? (void *)(uintptr_t)(pos + 1) : NULL);
  1710. }
  1711. static void *mps_tcam_start(struct seq_file *seq, loff_t *pos)
  1712. {
  1713. return *pos ? mps_tcam_get_idx(seq, *pos) : SEQ_START_TOKEN;
  1714. }
  1715. static void *mps_tcam_next(struct seq_file *seq, void *v, loff_t *pos)
  1716. {
  1717. ++*pos;
  1718. return mps_tcam_get_idx(seq, *pos);
  1719. }
  1720. static void mps_tcam_stop(struct seq_file *seq, void *v)
  1721. {
  1722. }
  1723. static const struct seq_operations mps_tcam_seq_ops = {
  1724. .start = mps_tcam_start,
  1725. .next = mps_tcam_next,
  1726. .stop = mps_tcam_stop,
  1727. .show = mps_tcam_show
  1728. };
  1729. static int mps_tcam_open(struct inode *inode, struct file *file)
  1730. {
  1731. int res = seq_open(file, &mps_tcam_seq_ops);
  1732. if (!res) {
  1733. struct seq_file *seq = file->private_data;
  1734. seq->private = inode->i_private;
  1735. }
  1736. return res;
  1737. }
  1738. static const struct file_operations mps_tcam_debugfs_fops = {
  1739. .owner = THIS_MODULE,
  1740. .open = mps_tcam_open,
  1741. .read = seq_read,
  1742. .llseek = seq_lseek,
  1743. .release = seq_release,
  1744. };
  1745. /* Display various sensor information.
  1746. */
  1747. static int sensors_show(struct seq_file *seq, void *v)
  1748. {
  1749. struct adapter *adap = seq->private;
  1750. u32 param[7], val[7];
  1751. int ret;
  1752. /* Note that if the sensors haven't been initialized and turned on
  1753. * we'll get values of 0, so treat those as "<unknown>" ...
  1754. */
  1755. param[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  1756. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
  1757. FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
  1758. param[1] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  1759. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
  1760. FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_VDD));
  1761. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  1762. param, val);
  1763. if (ret < 0 || val[0] == 0)
  1764. seq_puts(seq, "Temperature: <unknown>\n");
  1765. else
  1766. seq_printf(seq, "Temperature: %dC\n", val[0]);
  1767. if (ret < 0 || val[1] == 0)
  1768. seq_puts(seq, "Core VDD: <unknown>\n");
  1769. else
  1770. seq_printf(seq, "Core VDD: %dmV\n", val[1]);
  1771. return 0;
  1772. }
  1773. DEFINE_SIMPLE_DEBUGFS_FILE(sensors);
  1774. #if IS_ENABLED(CONFIG_IPV6)
  1775. static int clip_tbl_open(struct inode *inode, struct file *file)
  1776. {
  1777. return single_open(file, clip_tbl_show, inode->i_private);
  1778. }
  1779. static const struct file_operations clip_tbl_debugfs_fops = {
  1780. .owner = THIS_MODULE,
  1781. .open = clip_tbl_open,
  1782. .read = seq_read,
  1783. .llseek = seq_lseek,
  1784. .release = single_release
  1785. };
  1786. #endif
  1787. /*RSS Table.
  1788. */
  1789. static int rss_show(struct seq_file *seq, void *v, int idx)
  1790. {
  1791. u16 *entry = v;
  1792. seq_printf(seq, "%4d: %4u %4u %4u %4u %4u %4u %4u %4u\n",
  1793. idx * 8, entry[0], entry[1], entry[2], entry[3], entry[4],
  1794. entry[5], entry[6], entry[7]);
  1795. return 0;
  1796. }
  1797. static int rss_open(struct inode *inode, struct file *file)
  1798. {
  1799. struct adapter *adap = inode->i_private;
  1800. int ret, nentries;
  1801. struct seq_tab *p;
  1802. nentries = t4_chip_rss_size(adap);
  1803. p = seq_open_tab(file, nentries / 8, 8 * sizeof(u16), 0, rss_show);
  1804. if (!p)
  1805. return -ENOMEM;
  1806. ret = t4_read_rss(adap, (u16 *)p->data);
  1807. if (ret)
  1808. seq_release_private(inode, file);
  1809. return ret;
  1810. }
  1811. static const struct file_operations rss_debugfs_fops = {
  1812. .owner = THIS_MODULE,
  1813. .open = rss_open,
  1814. .read = seq_read,
  1815. .llseek = seq_lseek,
  1816. .release = seq_release_private
  1817. };
  1818. /* RSS Configuration.
  1819. */
  1820. /* Small utility function to return the strings "yes" or "no" if the supplied
  1821. * argument is non-zero.
  1822. */
  1823. static const char *yesno(int x)
  1824. {
  1825. static const char *yes = "yes";
  1826. static const char *no = "no";
  1827. return x ? yes : no;
  1828. }
  1829. static int rss_config_show(struct seq_file *seq, void *v)
  1830. {
  1831. struct adapter *adapter = seq->private;
  1832. static const char * const keymode[] = {
  1833. "global",
  1834. "global and per-VF scramble",
  1835. "per-PF and per-VF scramble",
  1836. "per-VF and per-VF scramble",
  1837. };
  1838. u32 rssconf;
  1839. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_A);
  1840. seq_printf(seq, "TP_RSS_CONFIG: %#x\n", rssconf);
  1841. seq_printf(seq, " Tnl4TupEnIpv6: %3s\n", yesno(rssconf &
  1842. TNL4TUPENIPV6_F));
  1843. seq_printf(seq, " Tnl2TupEnIpv6: %3s\n", yesno(rssconf &
  1844. TNL2TUPENIPV6_F));
  1845. seq_printf(seq, " Tnl4TupEnIpv4: %3s\n", yesno(rssconf &
  1846. TNL4TUPENIPV4_F));
  1847. seq_printf(seq, " Tnl2TupEnIpv4: %3s\n", yesno(rssconf &
  1848. TNL2TUPENIPV4_F));
  1849. seq_printf(seq, " TnlTcpSel: %3s\n", yesno(rssconf & TNLTCPSEL_F));
  1850. seq_printf(seq, " TnlIp6Sel: %3s\n", yesno(rssconf & TNLIP6SEL_F));
  1851. seq_printf(seq, " TnlVrtSel: %3s\n", yesno(rssconf & TNLVRTSEL_F));
  1852. seq_printf(seq, " TnlMapEn: %3s\n", yesno(rssconf & TNLMAPEN_F));
  1853. seq_printf(seq, " OfdHashSave: %3s\n", yesno(rssconf &
  1854. OFDHASHSAVE_F));
  1855. seq_printf(seq, " OfdVrtSel: %3s\n", yesno(rssconf & OFDVRTSEL_F));
  1856. seq_printf(seq, " OfdMapEn: %3s\n", yesno(rssconf & OFDMAPEN_F));
  1857. seq_printf(seq, " OfdLkpEn: %3s\n", yesno(rssconf & OFDLKPEN_F));
  1858. seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
  1859. SYN4TUPENIPV6_F));
  1860. seq_printf(seq, " Syn2TupEnIpv6: %3s\n", yesno(rssconf &
  1861. SYN2TUPENIPV6_F));
  1862. seq_printf(seq, " Syn4TupEnIpv4: %3s\n", yesno(rssconf &
  1863. SYN4TUPENIPV4_F));
  1864. seq_printf(seq, " Syn2TupEnIpv4: %3s\n", yesno(rssconf &
  1865. SYN2TUPENIPV4_F));
  1866. seq_printf(seq, " Syn4TupEnIpv6: %3s\n", yesno(rssconf &
  1867. SYN4TUPENIPV6_F));
  1868. seq_printf(seq, " SynIp6Sel: %3s\n", yesno(rssconf & SYNIP6SEL_F));
  1869. seq_printf(seq, " SynVrt6Sel: %3s\n", yesno(rssconf & SYNVRTSEL_F));
  1870. seq_printf(seq, " SynMapEn: %3s\n", yesno(rssconf & SYNMAPEN_F));
  1871. seq_printf(seq, " SynLkpEn: %3s\n", yesno(rssconf & SYNLKPEN_F));
  1872. seq_printf(seq, " ChnEn: %3s\n", yesno(rssconf &
  1873. CHANNELENABLE_F));
  1874. seq_printf(seq, " PrtEn: %3s\n", yesno(rssconf &
  1875. PORTENABLE_F));
  1876. seq_printf(seq, " TnlAllLkp: %3s\n", yesno(rssconf &
  1877. TNLALLLOOKUP_F));
  1878. seq_printf(seq, " VrtEn: %3s\n", yesno(rssconf &
  1879. VIRTENABLE_F));
  1880. seq_printf(seq, " CngEn: %3s\n", yesno(rssconf &
  1881. CONGESTIONENABLE_F));
  1882. seq_printf(seq, " HashToeplitz: %3s\n", yesno(rssconf &
  1883. HASHTOEPLITZ_F));
  1884. seq_printf(seq, " Udp4En: %3s\n", yesno(rssconf & UDPENABLE_F));
  1885. seq_printf(seq, " Disable: %3s\n", yesno(rssconf & DISABLE_F));
  1886. seq_puts(seq, "\n");
  1887. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_TNL_A);
  1888. seq_printf(seq, "TP_RSS_CONFIG_TNL: %#x\n", rssconf);
  1889. seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
  1890. seq_printf(seq, " MaskFilter: %3d\n", MASKFILTER_G(rssconf));
  1891. if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
  1892. seq_printf(seq, " HashAll: %3s\n",
  1893. yesno(rssconf & HASHALL_F));
  1894. seq_printf(seq, " HashEth: %3s\n",
  1895. yesno(rssconf & HASHETH_F));
  1896. }
  1897. seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
  1898. seq_puts(seq, "\n");
  1899. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_OFD_A);
  1900. seq_printf(seq, "TP_RSS_CONFIG_OFD: %#x\n", rssconf);
  1901. seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
  1902. seq_printf(seq, " RRCplMapEn: %3s\n", yesno(rssconf &
  1903. RRCPLMAPEN_F));
  1904. seq_printf(seq, " RRCplQueWidth: %3d\n", RRCPLQUEWIDTH_G(rssconf));
  1905. seq_puts(seq, "\n");
  1906. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_SYN_A);
  1907. seq_printf(seq, "TP_RSS_CONFIG_SYN: %#x\n", rssconf);
  1908. seq_printf(seq, " MaskSize: %3d\n", MASKSIZE_G(rssconf));
  1909. seq_printf(seq, " UseWireCh: %3s\n", yesno(rssconf & USEWIRECH_F));
  1910. seq_puts(seq, "\n");
  1911. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_VRT_A);
  1912. seq_printf(seq, "TP_RSS_CONFIG_VRT: %#x\n", rssconf);
  1913. if (CHELSIO_CHIP_VERSION(adapter->params.chip) > CHELSIO_T5) {
  1914. seq_printf(seq, " KeyWrAddrX: %3d\n",
  1915. KEYWRADDRX_G(rssconf));
  1916. seq_printf(seq, " KeyExtend: %3s\n",
  1917. yesno(rssconf & KEYEXTEND_F));
  1918. }
  1919. seq_printf(seq, " VfRdRg: %3s\n", yesno(rssconf & VFRDRG_F));
  1920. seq_printf(seq, " VfRdEn: %3s\n", yesno(rssconf & VFRDEN_F));
  1921. seq_printf(seq, " VfPerrEn: %3s\n", yesno(rssconf & VFPERREN_F));
  1922. seq_printf(seq, " KeyPerrEn: %3s\n", yesno(rssconf & KEYPERREN_F));
  1923. seq_printf(seq, " DisVfVlan: %3s\n", yesno(rssconf &
  1924. DISABLEVLAN_F));
  1925. seq_printf(seq, " EnUpSwt: %3s\n", yesno(rssconf & ENABLEUP0_F));
  1926. seq_printf(seq, " HashDelay: %3d\n", HASHDELAY_G(rssconf));
  1927. if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5)
  1928. seq_printf(seq, " VfWrAddr: %3d\n", VFWRADDR_G(rssconf));
  1929. else
  1930. seq_printf(seq, " VfWrAddr: %3d\n",
  1931. T6_VFWRADDR_G(rssconf));
  1932. seq_printf(seq, " KeyMode: %s\n", keymode[KEYMODE_G(rssconf)]);
  1933. seq_printf(seq, " VfWrEn: %3s\n", yesno(rssconf & VFWREN_F));
  1934. seq_printf(seq, " KeyWrEn: %3s\n", yesno(rssconf & KEYWREN_F));
  1935. seq_printf(seq, " KeyWrAddr: %3d\n", KEYWRADDR_G(rssconf));
  1936. seq_puts(seq, "\n");
  1937. rssconf = t4_read_reg(adapter, TP_RSS_CONFIG_CNG_A);
  1938. seq_printf(seq, "TP_RSS_CONFIG_CNG: %#x\n", rssconf);
  1939. seq_printf(seq, " ChnCount3: %3s\n", yesno(rssconf & CHNCOUNT3_F));
  1940. seq_printf(seq, " ChnCount2: %3s\n", yesno(rssconf & CHNCOUNT2_F));
  1941. seq_printf(seq, " ChnCount1: %3s\n", yesno(rssconf & CHNCOUNT1_F));
  1942. seq_printf(seq, " ChnCount0: %3s\n", yesno(rssconf & CHNCOUNT0_F));
  1943. seq_printf(seq, " ChnUndFlow3: %3s\n", yesno(rssconf &
  1944. CHNUNDFLOW3_F));
  1945. seq_printf(seq, " ChnUndFlow2: %3s\n", yesno(rssconf &
  1946. CHNUNDFLOW2_F));
  1947. seq_printf(seq, " ChnUndFlow1: %3s\n", yesno(rssconf &
  1948. CHNUNDFLOW1_F));
  1949. seq_printf(seq, " ChnUndFlow0: %3s\n", yesno(rssconf &
  1950. CHNUNDFLOW0_F));
  1951. seq_printf(seq, " RstChn3: %3s\n", yesno(rssconf & RSTCHN3_F));
  1952. seq_printf(seq, " RstChn2: %3s\n", yesno(rssconf & RSTCHN2_F));
  1953. seq_printf(seq, " RstChn1: %3s\n", yesno(rssconf & RSTCHN1_F));
  1954. seq_printf(seq, " RstChn0: %3s\n", yesno(rssconf & RSTCHN0_F));
  1955. seq_printf(seq, " UpdVld: %3s\n", yesno(rssconf & UPDVLD_F));
  1956. seq_printf(seq, " Xoff: %3s\n", yesno(rssconf & XOFF_F));
  1957. seq_printf(seq, " UpdChn3: %3s\n", yesno(rssconf & UPDCHN3_F));
  1958. seq_printf(seq, " UpdChn2: %3s\n", yesno(rssconf & UPDCHN2_F));
  1959. seq_printf(seq, " UpdChn1: %3s\n", yesno(rssconf & UPDCHN1_F));
  1960. seq_printf(seq, " UpdChn0: %3s\n", yesno(rssconf & UPDCHN0_F));
  1961. seq_printf(seq, " Queue: %3d\n", QUEUE_G(rssconf));
  1962. return 0;
  1963. }
  1964. DEFINE_SIMPLE_DEBUGFS_FILE(rss_config);
  1965. /* RSS Secret Key.
  1966. */
  1967. static int rss_key_show(struct seq_file *seq, void *v)
  1968. {
  1969. u32 key[10];
  1970. t4_read_rss_key(seq->private, key, true);
  1971. seq_printf(seq, "%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x\n",
  1972. key[9], key[8], key[7], key[6], key[5], key[4], key[3],
  1973. key[2], key[1], key[0]);
  1974. return 0;
  1975. }
  1976. static int rss_key_open(struct inode *inode, struct file *file)
  1977. {
  1978. return single_open(file, rss_key_show, inode->i_private);
  1979. }
  1980. static ssize_t rss_key_write(struct file *file, const char __user *buf,
  1981. size_t count, loff_t *pos)
  1982. {
  1983. int i, j;
  1984. u32 key[10];
  1985. char s[100], *p;
  1986. struct adapter *adap = file_inode(file)->i_private;
  1987. if (count > sizeof(s) - 1)
  1988. return -EINVAL;
  1989. if (copy_from_user(s, buf, count))
  1990. return -EFAULT;
  1991. for (i = count; i > 0 && isspace(s[i - 1]); i--)
  1992. ;
  1993. s[i] = '\0';
  1994. for (p = s, i = 9; i >= 0; i--) {
  1995. key[i] = 0;
  1996. for (j = 0; j < 8; j++, p++) {
  1997. if (!isxdigit(*p))
  1998. return -EINVAL;
  1999. key[i] = (key[i] << 4) | hex2val(*p);
  2000. }
  2001. }
  2002. t4_write_rss_key(adap, key, -1, true);
  2003. return count;
  2004. }
  2005. static const struct file_operations rss_key_debugfs_fops = {
  2006. .owner = THIS_MODULE,
  2007. .open = rss_key_open,
  2008. .read = seq_read,
  2009. .llseek = seq_lseek,
  2010. .release = single_release,
  2011. .write = rss_key_write
  2012. };
  2013. /* PF RSS Configuration.
  2014. */
  2015. struct rss_pf_conf {
  2016. u32 rss_pf_map;
  2017. u32 rss_pf_mask;
  2018. u32 rss_pf_config;
  2019. };
  2020. static int rss_pf_config_show(struct seq_file *seq, void *v, int idx)
  2021. {
  2022. struct rss_pf_conf *pfconf;
  2023. if (v == SEQ_START_TOKEN) {
  2024. /* use the 0th entry to dump the PF Map Index Size */
  2025. pfconf = seq->private + offsetof(struct seq_tab, data);
  2026. seq_printf(seq, "PF Map Index Size = %d\n\n",
  2027. LKPIDXSIZE_G(pfconf->rss_pf_map));
  2028. seq_puts(seq, " RSS PF VF Hash Tuple Enable Default\n");
  2029. seq_puts(seq, " Enable IPF Mask Mask IPv6 IPv4 UDP Queue\n");
  2030. seq_puts(seq, " PF Map Chn Prt Map Size Size Four Two Four Two Four Ch1 Ch0\n");
  2031. } else {
  2032. #define G_PFnLKPIDX(map, n) \
  2033. (((map) >> PF1LKPIDX_S*(n)) & PF0LKPIDX_M)
  2034. #define G_PFnMSKSIZE(mask, n) \
  2035. (((mask) >> PF1MSKSIZE_S*(n)) & PF1MSKSIZE_M)
  2036. pfconf = v;
  2037. seq_printf(seq, "%3d %3s %3s %3s %3d %3d %3d %3s %3s %3s %3s %3s %3d %3d\n",
  2038. idx,
  2039. yesno(pfconf->rss_pf_config & MAPENABLE_F),
  2040. yesno(pfconf->rss_pf_config & CHNENABLE_F),
  2041. yesno(pfconf->rss_pf_config & PRTENABLE_F),
  2042. G_PFnLKPIDX(pfconf->rss_pf_map, idx),
  2043. G_PFnMSKSIZE(pfconf->rss_pf_mask, idx),
  2044. IVFWIDTH_G(pfconf->rss_pf_config),
  2045. yesno(pfconf->rss_pf_config & IP6FOURTUPEN_F),
  2046. yesno(pfconf->rss_pf_config & IP6TWOTUPEN_F),
  2047. yesno(pfconf->rss_pf_config & IP4FOURTUPEN_F),
  2048. yesno(pfconf->rss_pf_config & IP4TWOTUPEN_F),
  2049. yesno(pfconf->rss_pf_config & UDPFOURTUPEN_F),
  2050. CH1DEFAULTQUEUE_G(pfconf->rss_pf_config),
  2051. CH0DEFAULTQUEUE_G(pfconf->rss_pf_config));
  2052. #undef G_PFnLKPIDX
  2053. #undef G_PFnMSKSIZE
  2054. }
  2055. return 0;
  2056. }
  2057. static int rss_pf_config_open(struct inode *inode, struct file *file)
  2058. {
  2059. struct adapter *adapter = inode->i_private;
  2060. struct seq_tab *p;
  2061. u32 rss_pf_map, rss_pf_mask;
  2062. struct rss_pf_conf *pfconf;
  2063. int pf;
  2064. p = seq_open_tab(file, 8, sizeof(*pfconf), 1, rss_pf_config_show);
  2065. if (!p)
  2066. return -ENOMEM;
  2067. pfconf = (struct rss_pf_conf *)p->data;
  2068. rss_pf_map = t4_read_rss_pf_map(adapter, true);
  2069. rss_pf_mask = t4_read_rss_pf_mask(adapter, true);
  2070. for (pf = 0; pf < 8; pf++) {
  2071. pfconf[pf].rss_pf_map = rss_pf_map;
  2072. pfconf[pf].rss_pf_mask = rss_pf_mask;
  2073. t4_read_rss_pf_config(adapter, pf, &pfconf[pf].rss_pf_config,
  2074. true);
  2075. }
  2076. return 0;
  2077. }
  2078. static const struct file_operations rss_pf_config_debugfs_fops = {
  2079. .owner = THIS_MODULE,
  2080. .open = rss_pf_config_open,
  2081. .read = seq_read,
  2082. .llseek = seq_lseek,
  2083. .release = seq_release_private
  2084. };
  2085. /* VF RSS Configuration.
  2086. */
  2087. struct rss_vf_conf {
  2088. u32 rss_vf_vfl;
  2089. u32 rss_vf_vfh;
  2090. };
  2091. static int rss_vf_config_show(struct seq_file *seq, void *v, int idx)
  2092. {
  2093. if (v == SEQ_START_TOKEN) {
  2094. seq_puts(seq, " RSS Hash Tuple Enable\n");
  2095. seq_puts(seq, " Enable IVF Dis Enb IPv6 IPv4 UDP Def Secret Key\n");
  2096. seq_puts(seq, " VF Chn Prt Map VLAN uP Four Two Four Two Four Que Idx Hash\n");
  2097. } else {
  2098. struct rss_vf_conf *vfconf = v;
  2099. seq_printf(seq, "%3d %3s %3s %3d %3s %3s %3s %3s %3s %3s %3s %4d %3d %#10x\n",
  2100. idx,
  2101. yesno(vfconf->rss_vf_vfh & VFCHNEN_F),
  2102. yesno(vfconf->rss_vf_vfh & VFPRTEN_F),
  2103. VFLKPIDX_G(vfconf->rss_vf_vfh),
  2104. yesno(vfconf->rss_vf_vfh & VFVLNEX_F),
  2105. yesno(vfconf->rss_vf_vfh & VFUPEN_F),
  2106. yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
  2107. yesno(vfconf->rss_vf_vfh & VFIP6TWOTUPEN_F),
  2108. yesno(vfconf->rss_vf_vfh & VFIP4FOURTUPEN_F),
  2109. yesno(vfconf->rss_vf_vfh & VFIP4TWOTUPEN_F),
  2110. yesno(vfconf->rss_vf_vfh & ENABLEUDPHASH_F),
  2111. DEFAULTQUEUE_G(vfconf->rss_vf_vfh),
  2112. KEYINDEX_G(vfconf->rss_vf_vfh),
  2113. vfconf->rss_vf_vfl);
  2114. }
  2115. return 0;
  2116. }
  2117. static int rss_vf_config_open(struct inode *inode, struct file *file)
  2118. {
  2119. struct adapter *adapter = inode->i_private;
  2120. struct seq_tab *p;
  2121. struct rss_vf_conf *vfconf;
  2122. int vf, vfcount = adapter->params.arch.vfcount;
  2123. p = seq_open_tab(file, vfcount, sizeof(*vfconf), 1, rss_vf_config_show);
  2124. if (!p)
  2125. return -ENOMEM;
  2126. vfconf = (struct rss_vf_conf *)p->data;
  2127. for (vf = 0; vf < vfcount; vf++) {
  2128. t4_read_rss_vf_config(adapter, vf, &vfconf[vf].rss_vf_vfl,
  2129. &vfconf[vf].rss_vf_vfh, true);
  2130. }
  2131. return 0;
  2132. }
  2133. static const struct file_operations rss_vf_config_debugfs_fops = {
  2134. .owner = THIS_MODULE,
  2135. .open = rss_vf_config_open,
  2136. .read = seq_read,
  2137. .llseek = seq_lseek,
  2138. .release = seq_release_private
  2139. };
  2140. /**
  2141. * ethqset2pinfo - return port_info of an Ethernet Queue Set
  2142. * @adap: the adapter
  2143. * @qset: Ethernet Queue Set
  2144. */
  2145. static inline struct port_info *ethqset2pinfo(struct adapter *adap, int qset)
  2146. {
  2147. int pidx;
  2148. for_each_port(adap, pidx) {
  2149. struct port_info *pi = adap2pinfo(adap, pidx);
  2150. if (qset >= pi->first_qset &&
  2151. qset < pi->first_qset + pi->nqsets)
  2152. return pi;
  2153. }
  2154. /* should never happen! */
  2155. BUG_ON(1);
  2156. return NULL;
  2157. }
  2158. static int sge_qinfo_show(struct seq_file *seq, void *v)
  2159. {
  2160. struct adapter *adap = seq->private;
  2161. int eth_entries = DIV_ROUND_UP(adap->sge.ethqsets, 4);
  2162. int ofld_entries = DIV_ROUND_UP(adap->sge.ofldqsets, 4);
  2163. int ctrl_entries = DIV_ROUND_UP(MAX_CTRL_QUEUES, 4);
  2164. int i, r = (uintptr_t)v - 1;
  2165. int ofld_idx = r - eth_entries;
  2166. int ctrl_idx = ofld_idx - ofld_entries;
  2167. int fq_idx = ctrl_idx - ctrl_entries;
  2168. if (r)
  2169. seq_putc(seq, '\n');
  2170. #define S3(fmt_spec, s, v) \
  2171. do { \
  2172. seq_printf(seq, "%-12s", s); \
  2173. for (i = 0; i < n; ++i) \
  2174. seq_printf(seq, " %16" fmt_spec, v); \
  2175. seq_putc(seq, '\n'); \
  2176. } while (0)
  2177. #define S(s, v) S3("s", s, v)
  2178. #define T3(fmt_spec, s, v) S3(fmt_spec, s, tx[i].v)
  2179. #define T(s, v) S3("u", s, tx[i].v)
  2180. #define TL(s, v) T3("lu", s, v)
  2181. #define R3(fmt_spec, s, v) S3(fmt_spec, s, rx[i].v)
  2182. #define R(s, v) S3("u", s, rx[i].v)
  2183. #define RL(s, v) R3("lu", s, v)
  2184. if (r < eth_entries) {
  2185. int base_qset = r * 4;
  2186. const struct sge_eth_rxq *rx = &adap->sge.ethrxq[base_qset];
  2187. const struct sge_eth_txq *tx = &adap->sge.ethtxq[base_qset];
  2188. int n = min(4, adap->sge.ethqsets - 4 * r);
  2189. S("QType:", "Ethernet");
  2190. S("Interface:",
  2191. rx[i].rspq.netdev ? rx[i].rspq.netdev->name : "N/A");
  2192. T("TxQ ID:", q.cntxt_id);
  2193. T("TxQ size:", q.size);
  2194. T("TxQ inuse:", q.in_use);
  2195. T("TxQ CIDX:", q.cidx);
  2196. T("TxQ PIDX:", q.pidx);
  2197. #ifdef CONFIG_CHELSIO_T4_DCB
  2198. T("DCB Prio:", dcb_prio);
  2199. S3("u", "DCB PGID:",
  2200. (ethqset2pinfo(adap, base_qset + i)->dcb.pgid >>
  2201. 4*(7-tx[i].dcb_prio)) & 0xf);
  2202. S3("u", "DCB PFC:",
  2203. (ethqset2pinfo(adap, base_qset + i)->dcb.pfcen >>
  2204. 1*(7-tx[i].dcb_prio)) & 0x1);
  2205. #endif
  2206. R("RspQ ID:", rspq.abs_id);
  2207. R("RspQ size:", rspq.size);
  2208. R("RspQE size:", rspq.iqe_len);
  2209. R("RspQ CIDX:", rspq.cidx);
  2210. R("RspQ Gen:", rspq.gen);
  2211. S3("u", "Intr delay:", qtimer_val(adap, &rx[i].rspq));
  2212. S3("u", "Intr pktcnt:",
  2213. adap->sge.counter_val[rx[i].rspq.pktcnt_idx]);
  2214. R("FL ID:", fl.cntxt_id);
  2215. R("FL size:", fl.size - 8);
  2216. R("FL pend:", fl.pend_cred);
  2217. R("FL avail:", fl.avail);
  2218. R("FL PIDX:", fl.pidx);
  2219. R("FL CIDX:", fl.cidx);
  2220. RL("RxPackets:", stats.pkts);
  2221. RL("RxCSO:", stats.rx_cso);
  2222. RL("VLANxtract:", stats.vlan_ex);
  2223. RL("LROmerged:", stats.lro_merged);
  2224. RL("LROpackets:", stats.lro_pkts);
  2225. RL("RxDrops:", stats.rx_drops);
  2226. TL("TSO:", tso);
  2227. TL("TxCSO:", tx_cso);
  2228. TL("VLANins:", vlan_ins);
  2229. TL("TxQFull:", q.stops);
  2230. TL("TxQRestarts:", q.restarts);
  2231. TL("TxMapErr:", mapping_err);
  2232. RL("FLAllocErr:", fl.alloc_failed);
  2233. RL("FLLrgAlcErr:", fl.large_alloc_failed);
  2234. RL("FLMapErr:", fl.mapping_err);
  2235. RL("FLLow:", fl.low);
  2236. RL("FLStarving:", fl.starving);
  2237. } else if (ctrl_idx < ctrl_entries) {
  2238. const struct sge_ctrl_txq *tx = &adap->sge.ctrlq[ctrl_idx * 4];
  2239. int n = min(4, adap->params.nports - 4 * ctrl_idx);
  2240. S("QType:", "Control");
  2241. T("TxQ ID:", q.cntxt_id);
  2242. T("TxQ size:", q.size);
  2243. T("TxQ inuse:", q.in_use);
  2244. T("TxQ CIDX:", q.cidx);
  2245. T("TxQ PIDX:", q.pidx);
  2246. TL("TxQFull:", q.stops);
  2247. TL("TxQRestarts:", q.restarts);
  2248. } else if (fq_idx == 0) {
  2249. const struct sge_rspq *evtq = &adap->sge.fw_evtq;
  2250. seq_printf(seq, "%-12s %16s\n", "QType:", "FW event queue");
  2251. seq_printf(seq, "%-12s %16u\n", "RspQ ID:", evtq->abs_id);
  2252. seq_printf(seq, "%-12s %16u\n", "RspQ size:", evtq->size);
  2253. seq_printf(seq, "%-12s %16u\n", "RspQE size:", evtq->iqe_len);
  2254. seq_printf(seq, "%-12s %16u\n", "RspQ CIDX:", evtq->cidx);
  2255. seq_printf(seq, "%-12s %16u\n", "RspQ Gen:", evtq->gen);
  2256. seq_printf(seq, "%-12s %16u\n", "Intr delay:",
  2257. qtimer_val(adap, evtq));
  2258. seq_printf(seq, "%-12s %16u\n", "Intr pktcnt:",
  2259. adap->sge.counter_val[evtq->pktcnt_idx]);
  2260. }
  2261. #undef R
  2262. #undef RL
  2263. #undef T
  2264. #undef TL
  2265. #undef S
  2266. #undef R3
  2267. #undef T3
  2268. #undef S3
  2269. return 0;
  2270. }
  2271. static int sge_queue_entries(const struct adapter *adap)
  2272. {
  2273. return DIV_ROUND_UP(adap->sge.ethqsets, 4) +
  2274. DIV_ROUND_UP(adap->sge.ofldqsets, 4) +
  2275. DIV_ROUND_UP(MAX_CTRL_QUEUES, 4) + 1;
  2276. }
  2277. static void *sge_queue_start(struct seq_file *seq, loff_t *pos)
  2278. {
  2279. int entries = sge_queue_entries(seq->private);
  2280. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  2281. }
  2282. static void sge_queue_stop(struct seq_file *seq, void *v)
  2283. {
  2284. }
  2285. static void *sge_queue_next(struct seq_file *seq, void *v, loff_t *pos)
  2286. {
  2287. int entries = sge_queue_entries(seq->private);
  2288. ++*pos;
  2289. return *pos < entries ? (void *)((uintptr_t)*pos + 1) : NULL;
  2290. }
  2291. static const struct seq_operations sge_qinfo_seq_ops = {
  2292. .start = sge_queue_start,
  2293. .next = sge_queue_next,
  2294. .stop = sge_queue_stop,
  2295. .show = sge_qinfo_show
  2296. };
  2297. static int sge_qinfo_open(struct inode *inode, struct file *file)
  2298. {
  2299. int res = seq_open(file, &sge_qinfo_seq_ops);
  2300. if (!res) {
  2301. struct seq_file *seq = file->private_data;
  2302. seq->private = inode->i_private;
  2303. }
  2304. return res;
  2305. }
  2306. static const struct file_operations sge_qinfo_debugfs_fops = {
  2307. .owner = THIS_MODULE,
  2308. .open = sge_qinfo_open,
  2309. .read = seq_read,
  2310. .llseek = seq_lseek,
  2311. .release = seq_release,
  2312. };
  2313. int mem_open(struct inode *inode, struct file *file)
  2314. {
  2315. unsigned int mem;
  2316. struct adapter *adap;
  2317. file->private_data = inode->i_private;
  2318. mem = (uintptr_t)file->private_data & 0x7;
  2319. adap = file->private_data - mem;
  2320. (void)t4_fwcache(adap, FW_PARAM_DEV_FWCACHE_FLUSH);
  2321. return 0;
  2322. }
  2323. static ssize_t mem_read(struct file *file, char __user *buf, size_t count,
  2324. loff_t *ppos)
  2325. {
  2326. loff_t pos = *ppos;
  2327. loff_t avail = file_inode(file)->i_size;
  2328. unsigned int mem = (uintptr_t)file->private_data & 0x7;
  2329. struct adapter *adap = file->private_data - mem;
  2330. __be32 *data;
  2331. int ret;
  2332. if (pos < 0)
  2333. return -EINVAL;
  2334. if (pos >= avail)
  2335. return 0;
  2336. if (count > avail - pos)
  2337. count = avail - pos;
  2338. data = kvzalloc(count, GFP_KERNEL);
  2339. if (!data)
  2340. return -ENOMEM;
  2341. spin_lock(&adap->win0_lock);
  2342. ret = t4_memory_rw(adap, 0, mem, pos, count, data, T4_MEMORY_READ);
  2343. spin_unlock(&adap->win0_lock);
  2344. if (ret) {
  2345. kvfree(data);
  2346. return ret;
  2347. }
  2348. ret = copy_to_user(buf, data, count);
  2349. kvfree(data);
  2350. if (ret)
  2351. return -EFAULT;
  2352. *ppos = pos + count;
  2353. return count;
  2354. }
  2355. static const struct file_operations mem_debugfs_fops = {
  2356. .owner = THIS_MODULE,
  2357. .open = simple_open,
  2358. .read = mem_read,
  2359. .llseek = default_llseek,
  2360. };
  2361. static int tid_info_show(struct seq_file *seq, void *v)
  2362. {
  2363. unsigned int tid_start = 0;
  2364. struct adapter *adap = seq->private;
  2365. const struct tid_info *t = &adap->tids;
  2366. enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip);
  2367. if (chip > CHELSIO_T5)
  2368. tid_start = t4_read_reg(adap, LE_DB_ACTIVE_TABLE_START_INDEX_A);
  2369. if (t4_read_reg(adap, LE_DB_CONFIG_A) & HASHEN_F) {
  2370. unsigned int sb;
  2371. seq_printf(seq, "Connections in use: %u\n",
  2372. atomic_read(&t->conns_in_use));
  2373. if (chip <= CHELSIO_T5)
  2374. sb = t4_read_reg(adap, LE_DB_SERVER_INDEX_A) / 4;
  2375. else
  2376. sb = t4_read_reg(adap, LE_DB_SRVR_START_INDEX_A);
  2377. if (sb) {
  2378. seq_printf(seq, "TID range: %u..%u/%u..%u", tid_start,
  2379. sb - 1, adap->tids.hash_base,
  2380. t->ntids - 1);
  2381. seq_printf(seq, ", in use: %u/%u\n",
  2382. atomic_read(&t->tids_in_use),
  2383. atomic_read(&t->hash_tids_in_use));
  2384. } else if (adap->flags & FW_OFLD_CONN) {
  2385. seq_printf(seq, "TID range: %u..%u/%u..%u",
  2386. t->aftid_base,
  2387. t->aftid_end,
  2388. adap->tids.hash_base,
  2389. t->ntids - 1);
  2390. seq_printf(seq, ", in use: %u/%u\n",
  2391. atomic_read(&t->tids_in_use),
  2392. atomic_read(&t->hash_tids_in_use));
  2393. } else {
  2394. seq_printf(seq, "TID range: %u..%u",
  2395. adap->tids.hash_base,
  2396. t->ntids - 1);
  2397. seq_printf(seq, ", in use: %u\n",
  2398. atomic_read(&t->hash_tids_in_use));
  2399. }
  2400. } else if (t->ntids) {
  2401. seq_printf(seq, "Connections in use: %u\n",
  2402. atomic_read(&t->conns_in_use));
  2403. seq_printf(seq, "TID range: %u..%u", tid_start,
  2404. tid_start + t->ntids - 1);
  2405. seq_printf(seq, ", in use: %u\n",
  2406. atomic_read(&t->tids_in_use));
  2407. }
  2408. if (t->nstids)
  2409. seq_printf(seq, "STID range: %u..%u, in use-IPv4/IPv6: %u/%u\n",
  2410. (!t->stid_base &&
  2411. (chip <= CHELSIO_T5)) ?
  2412. t->stid_base + 1 : t->stid_base,
  2413. t->stid_base + t->nstids - 1,
  2414. t->stids_in_use - t->v6_stids_in_use,
  2415. t->v6_stids_in_use);
  2416. if (t->natids)
  2417. seq_printf(seq, "ATID range: 0..%u, in use: %u\n",
  2418. t->natids - 1, t->atids_in_use);
  2419. seq_printf(seq, "FTID range: %u..%u\n", t->ftid_base,
  2420. t->ftid_base + t->nftids - 1);
  2421. if (t->nsftids)
  2422. seq_printf(seq, "SFTID range: %u..%u in use: %u\n",
  2423. t->sftid_base, t->sftid_base + t->nsftids - 2,
  2424. t->sftids_in_use);
  2425. if (t->ntids)
  2426. seq_printf(seq, "HW TID usage: %u IP users, %u IPv6 users\n",
  2427. t4_read_reg(adap, LE_DB_ACT_CNT_IPV4_A),
  2428. t4_read_reg(adap, LE_DB_ACT_CNT_IPV6_A));
  2429. return 0;
  2430. }
  2431. DEFINE_SIMPLE_DEBUGFS_FILE(tid_info);
  2432. static void add_debugfs_mem(struct adapter *adap, const char *name,
  2433. unsigned int idx, unsigned int size_mb)
  2434. {
  2435. debugfs_create_file_size(name, 0400, adap->debugfs_root,
  2436. (void *)adap + idx, &mem_debugfs_fops,
  2437. size_mb << 20);
  2438. }
  2439. static ssize_t blocked_fl_read(struct file *filp, char __user *ubuf,
  2440. size_t count, loff_t *ppos)
  2441. {
  2442. int len;
  2443. const struct adapter *adap = filp->private_data;
  2444. char *buf;
  2445. ssize_t size = (adap->sge.egr_sz + 3) / 4 +
  2446. adap->sge.egr_sz / 32 + 2; /* includes ,/\n/\0 */
  2447. buf = kzalloc(size, GFP_KERNEL);
  2448. if (!buf)
  2449. return -ENOMEM;
  2450. len = snprintf(buf, size - 1, "%*pb\n",
  2451. adap->sge.egr_sz, adap->sge.blocked_fl);
  2452. len += sprintf(buf + len, "\n");
  2453. size = simple_read_from_buffer(ubuf, count, ppos, buf, len);
  2454. kvfree(buf);
  2455. return size;
  2456. }
  2457. static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
  2458. size_t count, loff_t *ppos)
  2459. {
  2460. int err;
  2461. unsigned long *t;
  2462. struct adapter *adap = filp->private_data;
  2463. t = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz), sizeof(long), GFP_KERNEL);
  2464. if (!t)
  2465. return -ENOMEM;
  2466. err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
  2467. if (err)
  2468. return err;
  2469. bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);
  2470. kvfree(t);
  2471. return count;
  2472. }
  2473. static const struct file_operations blocked_fl_fops = {
  2474. .owner = THIS_MODULE,
  2475. .open = simple_open,
  2476. .read = blocked_fl_read,
  2477. .write = blocked_fl_write,
  2478. .llseek = generic_file_llseek,
  2479. };
  2480. static void mem_region_show(struct seq_file *seq, const char *name,
  2481. unsigned int from, unsigned int to)
  2482. {
  2483. char buf[40];
  2484. string_get_size((u64)to - from + 1, 1, STRING_UNITS_2, buf,
  2485. sizeof(buf));
  2486. seq_printf(seq, "%-15s %#x-%#x [%s]\n", name, from, to, buf);
  2487. }
  2488. static int meminfo_show(struct seq_file *seq, void *v)
  2489. {
  2490. static const char * const memory[] = { "EDC0:", "EDC1:", "MC:",
  2491. "MC0:", "MC1:", "HMA:"};
  2492. struct adapter *adap = seq->private;
  2493. struct cudbg_meminfo meminfo;
  2494. int i, rc;
  2495. memset(&meminfo, 0, sizeof(struct cudbg_meminfo));
  2496. rc = cudbg_fill_meminfo(adap, &meminfo);
  2497. if (rc)
  2498. return -ENXIO;
  2499. for (i = 0; i < meminfo.avail_c; i++)
  2500. mem_region_show(seq, memory[meminfo.avail[i].idx],
  2501. meminfo.avail[i].base,
  2502. meminfo.avail[i].limit - 1);
  2503. seq_putc(seq, '\n');
  2504. for (i = 0; i < meminfo.mem_c; i++) {
  2505. if (meminfo.mem[i].idx >= ARRAY_SIZE(cudbg_region))
  2506. continue; /* skip holes */
  2507. if (!meminfo.mem[i].limit)
  2508. meminfo.mem[i].limit =
  2509. i < meminfo.mem_c - 1 ?
  2510. meminfo.mem[i + 1].base - 1 : ~0;
  2511. mem_region_show(seq, cudbg_region[meminfo.mem[i].idx],
  2512. meminfo.mem[i].base, meminfo.mem[i].limit);
  2513. }
  2514. seq_putc(seq, '\n');
  2515. mem_region_show(seq, "uP RAM:", meminfo.up_ram_lo, meminfo.up_ram_hi);
  2516. mem_region_show(seq, "uP Extmem2:", meminfo.up_extmem2_lo,
  2517. meminfo.up_extmem2_hi);
  2518. seq_printf(seq, "\n%u Rx pages of size %uKiB for %u channels\n",
  2519. meminfo.rx_pages_data[0], meminfo.rx_pages_data[1],
  2520. meminfo.rx_pages_data[2]);
  2521. seq_printf(seq, "%u Tx pages of size %u%ciB for %u channels\n",
  2522. meminfo.tx_pages_data[0], meminfo.tx_pages_data[1],
  2523. meminfo.tx_pages_data[2], meminfo.tx_pages_data[3]);
  2524. seq_printf(seq, "%u p-structs\n\n", meminfo.p_structs);
  2525. for (i = 0; i < 4; i++)
  2526. /* For T6 these are MAC buffer groups */
  2527. seq_printf(seq, "Port %d using %u pages out of %u allocated\n",
  2528. i, meminfo.port_used[i], meminfo.port_alloc[i]);
  2529. for (i = 0; i < adap->params.arch.nchan; i++)
  2530. /* For T6 these are MAC buffer groups */
  2531. seq_printf(seq,
  2532. "Loopback %d using %u pages out of %u allocated\n",
  2533. i, meminfo.loopback_used[i],
  2534. meminfo.loopback_alloc[i]);
  2535. return 0;
  2536. }
  2537. static int meminfo_open(struct inode *inode, struct file *file)
  2538. {
  2539. return single_open(file, meminfo_show, inode->i_private);
  2540. }
  2541. static const struct file_operations meminfo_fops = {
  2542. .owner = THIS_MODULE,
  2543. .open = meminfo_open,
  2544. .read = seq_read,
  2545. .llseek = seq_lseek,
  2546. .release = single_release,
  2547. };
  2548. static int chcr_show(struct seq_file *seq, void *v)
  2549. {
  2550. struct adapter *adap = seq->private;
  2551. seq_puts(seq, "Chelsio Crypto Accelerator Stats \n");
  2552. seq_printf(seq, "Cipher Ops: %10u \n",
  2553. atomic_read(&adap->chcr_stats.cipher_rqst));
  2554. seq_printf(seq, "Digest Ops: %10u \n",
  2555. atomic_read(&adap->chcr_stats.digest_rqst));
  2556. seq_printf(seq, "Aead Ops: %10u \n",
  2557. atomic_read(&adap->chcr_stats.aead_rqst));
  2558. seq_printf(seq, "Completion: %10u \n",
  2559. atomic_read(&adap->chcr_stats.complete));
  2560. seq_printf(seq, "Error: %10u \n",
  2561. atomic_read(&adap->chcr_stats.error));
  2562. seq_printf(seq, "Fallback: %10u \n",
  2563. atomic_read(&adap->chcr_stats.fallback));
  2564. seq_printf(seq, "IPSec PDU: %10u\n",
  2565. atomic_read(&adap->chcr_stats.ipsec_cnt));
  2566. return 0;
  2567. }
  2568. static int chcr_stats_open(struct inode *inode, struct file *file)
  2569. {
  2570. return single_open(file, chcr_show, inode->i_private);
  2571. }
  2572. static const struct file_operations chcr_stats_debugfs_fops = {
  2573. .owner = THIS_MODULE,
  2574. .open = chcr_stats_open,
  2575. .read = seq_read,
  2576. .llseek = seq_lseek,
  2577. .release = single_release,
  2578. };
  2579. /* Add an array of Debug FS files.
  2580. */
  2581. void add_debugfs_files(struct adapter *adap,
  2582. struct t4_debugfs_entry *files,
  2583. unsigned int nfiles)
  2584. {
  2585. int i;
  2586. /* debugfs support is best effort */
  2587. for (i = 0; i < nfiles; i++)
  2588. debugfs_create_file(files[i].name, files[i].mode,
  2589. adap->debugfs_root,
  2590. (void *)adap + files[i].data,
  2591. files[i].ops);
  2592. }
  2593. int t4_setup_debugfs(struct adapter *adap)
  2594. {
  2595. int i;
  2596. u32 size = 0;
  2597. struct dentry *de;
  2598. static struct t4_debugfs_entry t4_debugfs_files[] = {
  2599. { "cim_la", &cim_la_fops, 0400, 0 },
  2600. { "cim_pif_la", &cim_pif_la_fops, 0400, 0 },
  2601. { "cim_ma_la", &cim_ma_la_fops, 0400, 0 },
  2602. { "cim_qcfg", &cim_qcfg_fops, 0400, 0 },
  2603. { "clk", &clk_debugfs_fops, 0400, 0 },
  2604. { "devlog", &devlog_fops, 0400, 0 },
  2605. { "mboxlog", &mboxlog_fops, 0400, 0 },
  2606. { "mbox0", &mbox_debugfs_fops, 0600, 0 },
  2607. { "mbox1", &mbox_debugfs_fops, 0600, 1 },
  2608. { "mbox2", &mbox_debugfs_fops, 0600, 2 },
  2609. { "mbox3", &mbox_debugfs_fops, 0600, 3 },
  2610. { "mbox4", &mbox_debugfs_fops, 0600, 4 },
  2611. { "mbox5", &mbox_debugfs_fops, 0600, 5 },
  2612. { "mbox6", &mbox_debugfs_fops, 0600, 6 },
  2613. { "mbox7", &mbox_debugfs_fops, 0600, 7 },
  2614. { "trace0", &mps_trc_debugfs_fops, 0600, 0 },
  2615. { "trace1", &mps_trc_debugfs_fops, 0600, 1 },
  2616. { "trace2", &mps_trc_debugfs_fops, 0600, 2 },
  2617. { "trace3", &mps_trc_debugfs_fops, 0600, 3 },
  2618. { "l2t", &t4_l2t_fops, 0400, 0},
  2619. { "mps_tcam", &mps_tcam_debugfs_fops, 0400, 0 },
  2620. { "rss", &rss_debugfs_fops, 0400, 0 },
  2621. { "rss_config", &rss_config_debugfs_fops, 0400, 0 },
  2622. { "rss_key", &rss_key_debugfs_fops, 0400, 0 },
  2623. { "rss_pf_config", &rss_pf_config_debugfs_fops, 0400, 0 },
  2624. { "rss_vf_config", &rss_vf_config_debugfs_fops, 0400, 0 },
  2625. { "sge_qinfo", &sge_qinfo_debugfs_fops, 0400, 0 },
  2626. { "ibq_tp0", &cim_ibq_fops, 0400, 0 },
  2627. { "ibq_tp1", &cim_ibq_fops, 0400, 1 },
  2628. { "ibq_ulp", &cim_ibq_fops, 0400, 2 },
  2629. { "ibq_sge0", &cim_ibq_fops, 0400, 3 },
  2630. { "ibq_sge1", &cim_ibq_fops, 0400, 4 },
  2631. { "ibq_ncsi", &cim_ibq_fops, 0400, 5 },
  2632. { "obq_ulp0", &cim_obq_fops, 0400, 0 },
  2633. { "obq_ulp1", &cim_obq_fops, 0400, 1 },
  2634. { "obq_ulp2", &cim_obq_fops, 0400, 2 },
  2635. { "obq_ulp3", &cim_obq_fops, 0400, 3 },
  2636. { "obq_sge", &cim_obq_fops, 0400, 4 },
  2637. { "obq_ncsi", &cim_obq_fops, 0400, 5 },
  2638. { "tp_la", &tp_la_fops, 0400, 0 },
  2639. { "ulprx_la", &ulprx_la_fops, 0400, 0 },
  2640. { "sensors", &sensors_debugfs_fops, 0400, 0 },
  2641. { "pm_stats", &pm_stats_debugfs_fops, 0400, 0 },
  2642. { "tx_rate", &tx_rate_debugfs_fops, 0400, 0 },
  2643. { "cctrl", &cctrl_tbl_debugfs_fops, 0400, 0 },
  2644. #if IS_ENABLED(CONFIG_IPV6)
  2645. { "clip_tbl", &clip_tbl_debugfs_fops, 0400, 0 },
  2646. #endif
  2647. { "tids", &tid_info_debugfs_fops, 0400, 0},
  2648. { "blocked_fl", &blocked_fl_fops, 0600, 0 },
  2649. { "meminfo", &meminfo_fops, 0400, 0 },
  2650. { "crypto", &chcr_stats_debugfs_fops, 0400, 0 },
  2651. };
  2652. /* Debug FS nodes common to all T5 and later adapters.
  2653. */
  2654. static struct t4_debugfs_entry t5_debugfs_files[] = {
  2655. { "obq_sge_rx_q0", &cim_obq_fops, 0400, 6 },
  2656. { "obq_sge_rx_q1", &cim_obq_fops, 0400, 7 },
  2657. };
  2658. add_debugfs_files(adap,
  2659. t4_debugfs_files,
  2660. ARRAY_SIZE(t4_debugfs_files));
  2661. if (!is_t4(adap->params.chip))
  2662. add_debugfs_files(adap,
  2663. t5_debugfs_files,
  2664. ARRAY_SIZE(t5_debugfs_files));
  2665. i = t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A);
  2666. if (i & EDRAM0_ENABLE_F) {
  2667. size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
  2668. add_debugfs_mem(adap, "edc0", MEM_EDC0, EDRAM0_SIZE_G(size));
  2669. }
  2670. if (i & EDRAM1_ENABLE_F) {
  2671. size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
  2672. add_debugfs_mem(adap, "edc1", MEM_EDC1, EDRAM1_SIZE_G(size));
  2673. }
  2674. if (is_t5(adap->params.chip)) {
  2675. if (i & EXT_MEM0_ENABLE_F) {
  2676. size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
  2677. add_debugfs_mem(adap, "mc0", MEM_MC0,
  2678. EXT_MEM0_SIZE_G(size));
  2679. }
  2680. if (i & EXT_MEM1_ENABLE_F) {
  2681. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  2682. add_debugfs_mem(adap, "mc1", MEM_MC1,
  2683. EXT_MEM1_SIZE_G(size));
  2684. }
  2685. } else {
  2686. if (i & EXT_MEM_ENABLE_F) {
  2687. size = t4_read_reg(adap, MA_EXT_MEMORY_BAR_A);
  2688. add_debugfs_mem(adap, "mc", MEM_MC,
  2689. EXT_MEM_SIZE_G(size));
  2690. }
  2691. if (i & HMA_MUX_F) {
  2692. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  2693. add_debugfs_mem(adap, "hma", MEM_HMA,
  2694. EXT_MEM1_SIZE_G(size));
  2695. }
  2696. }
  2697. de = debugfs_create_file_size("flash", 0400, adap->debugfs_root, adap,
  2698. &flash_debugfs_fops, adap->params.sf_size);
  2699. debugfs_create_bool("use_backdoor", 0600,
  2700. adap->debugfs_root, &adap->use_bd);
  2701. debugfs_create_bool("trace_rss", 0600,
  2702. adap->debugfs_root, &adap->trace_rss);
  2703. return 0;
  2704. }