cxgb4_debugfs.c 90 KB

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