lpfc_debugfs.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2007-2011 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or *
  9. * modify it under the terms of version 2 of the GNU General *
  10. * Public License as published by the Free Software Foundation. *
  11. * This program is distributed in the hope that it will be useful. *
  12. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  13. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  14. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  15. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  16. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  17. * more details, a copy of which can be found in the file COPYING *
  18. * included with this package. *
  19. *******************************************************************/
  20. #include <linux/blkdev.h>
  21. #include <linux/delay.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/idr.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/kthread.h>
  26. #include <linux/slab.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/ctype.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include "lpfc_hw4.h"
  35. #include "lpfc_hw.h"
  36. #include "lpfc_sli.h"
  37. #include "lpfc_sli4.h"
  38. #include "lpfc_nl.h"
  39. #include "lpfc_disc.h"
  40. #include "lpfc_scsi.h"
  41. #include "lpfc.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_crtn.h"
  44. #include "lpfc_vport.h"
  45. #include "lpfc_version.h"
  46. #include "lpfc_compat.h"
  47. #include "lpfc_debugfs.h"
  48. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  49. /*
  50. * debugfs interface
  51. *
  52. * To access this interface the user should:
  53. * # mount -t debugfs none /sys/kernel/debug
  54. *
  55. * The lpfc debugfs directory hierarchy is:
  56. * /sys/kernel/debug/lpfc/fnX/vportY
  57. * where X is the lpfc hba function unique_id
  58. * where Y is the vport VPI on that hba
  59. *
  60. * Debugging services available per vport:
  61. * discovery_trace
  62. * This is an ACSII readable file that contains a trace of the last
  63. * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
  64. * See lpfc_debugfs.h for different categories of discovery events.
  65. * To enable the discovery trace, the following module parameters must be set:
  66. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  67. * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
  68. * EACH vport. X MUST also be a power of 2.
  69. * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
  70. * lpfc_debugfs.h .
  71. *
  72. * slow_ring_trace
  73. * This is an ACSII readable file that contains a trace of the last
  74. * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
  75. * To enable the slow ring trace, the following module parameters must be set:
  76. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  77. * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
  78. * the HBA. X MUST also be a power of 2.
  79. */
  80. static int lpfc_debugfs_enable = 1;
  81. module_param(lpfc_debugfs_enable, int, S_IRUGO);
  82. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  83. /* This MUST be a power of 2 */
  84. static int lpfc_debugfs_max_disc_trc;
  85. module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
  86. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  87. "Set debugfs discovery trace depth");
  88. /* This MUST be a power of 2 */
  89. static int lpfc_debugfs_max_slow_ring_trc;
  90. module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
  91. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  92. "Set debugfs slow ring trace depth");
  93. static int lpfc_debugfs_mask_disc_trc;
  94. module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
  95. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  96. "Set debugfs discovery trace mask");
  97. #include <linux/debugfs.h>
  98. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  99. static unsigned long lpfc_debugfs_start_time = 0L;
  100. /* iDiag */
  101. static struct lpfc_idiag idiag;
  102. /**
  103. * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
  104. * @vport: The vport to gather the log info from.
  105. * @buf: The buffer to dump log into.
  106. * @size: The maximum amount of data to process.
  107. *
  108. * Description:
  109. * This routine gathers the lpfc discovery debugfs data from the @vport and
  110. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  111. * in the log and process the log until the end of the buffer. Then it will
  112. * gather from the beginning of the log and process until the current entry.
  113. *
  114. * Notes:
  115. * Discovery logging will be disabled while while this routine dumps the log.
  116. *
  117. * Return Value:
  118. * This routine returns the amount of bytes that were dumped into @buf and will
  119. * not exceed @size.
  120. **/
  121. static int
  122. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  123. {
  124. int i, index, len, enable;
  125. uint32_t ms;
  126. struct lpfc_debugfs_trc *dtp;
  127. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  128. enable = lpfc_debugfs_enable;
  129. lpfc_debugfs_enable = 0;
  130. len = 0;
  131. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  132. (lpfc_debugfs_max_disc_trc - 1);
  133. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  134. dtp = vport->disc_trc + i;
  135. if (!dtp->fmt)
  136. continue;
  137. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  138. snprintf(buffer,
  139. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  140. dtp->seq_cnt, ms, dtp->fmt);
  141. len += snprintf(buf+len, size-len, buffer,
  142. dtp->data1, dtp->data2, dtp->data3);
  143. }
  144. for (i = 0; i < index; i++) {
  145. dtp = vport->disc_trc + i;
  146. if (!dtp->fmt)
  147. continue;
  148. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  149. snprintf(buffer,
  150. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  151. dtp->seq_cnt, ms, dtp->fmt);
  152. len += snprintf(buf+len, size-len, buffer,
  153. dtp->data1, dtp->data2, dtp->data3);
  154. }
  155. lpfc_debugfs_enable = enable;
  156. return len;
  157. }
  158. /**
  159. * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
  160. * @phba: The HBA to gather the log info from.
  161. * @buf: The buffer to dump log into.
  162. * @size: The maximum amount of data to process.
  163. *
  164. * Description:
  165. * This routine gathers the lpfc slow ring debugfs data from the @phba and
  166. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  167. * in the log and process the log until the end of the buffer. Then it will
  168. * gather from the beginning of the log and process until the current entry.
  169. *
  170. * Notes:
  171. * Slow ring logging will be disabled while while this routine dumps the log.
  172. *
  173. * Return Value:
  174. * This routine returns the amount of bytes that were dumped into @buf and will
  175. * not exceed @size.
  176. **/
  177. static int
  178. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  179. {
  180. int i, index, len, enable;
  181. uint32_t ms;
  182. struct lpfc_debugfs_trc *dtp;
  183. char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE];
  184. enable = lpfc_debugfs_enable;
  185. lpfc_debugfs_enable = 0;
  186. len = 0;
  187. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  188. (lpfc_debugfs_max_slow_ring_trc - 1);
  189. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  190. dtp = phba->slow_ring_trc + i;
  191. if (!dtp->fmt)
  192. continue;
  193. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  194. snprintf(buffer,
  195. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  196. dtp->seq_cnt, ms, dtp->fmt);
  197. len += snprintf(buf+len, size-len, buffer,
  198. dtp->data1, dtp->data2, dtp->data3);
  199. }
  200. for (i = 0; i < index; i++) {
  201. dtp = phba->slow_ring_trc + i;
  202. if (!dtp->fmt)
  203. continue;
  204. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  205. snprintf(buffer,
  206. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  207. dtp->seq_cnt, ms, dtp->fmt);
  208. len += snprintf(buf+len, size-len, buffer,
  209. dtp->data1, dtp->data2, dtp->data3);
  210. }
  211. lpfc_debugfs_enable = enable;
  212. return len;
  213. }
  214. static int lpfc_debugfs_last_hbq = -1;
  215. /**
  216. * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
  217. * @phba: The HBA to gather host buffer info from.
  218. * @buf: The buffer to dump log into.
  219. * @size: The maximum amount of data to process.
  220. *
  221. * Description:
  222. * This routine dumps the host buffer queue info from the @phba to @buf up to
  223. * @size number of bytes. A header that describes the current hbq state will be
  224. * dumped to @buf first and then info on each hbq entry will be dumped to @buf
  225. * until @size bytes have been dumped or all the hbq info has been dumped.
  226. *
  227. * Notes:
  228. * This routine will rotate through each configured HBQ each time called.
  229. *
  230. * Return Value:
  231. * This routine returns the amount of bytes that were dumped into @buf and will
  232. * not exceed @size.
  233. **/
  234. static int
  235. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  236. {
  237. int len = 0;
  238. int cnt, i, j, found, posted, low;
  239. uint32_t phys, raw_index, getidx;
  240. struct lpfc_hbq_init *hip;
  241. struct hbq_s *hbqs;
  242. struct lpfc_hbq_entry *hbqe;
  243. struct lpfc_dmabuf *d_buf;
  244. struct hbq_dmabuf *hbq_buf;
  245. if (phba->sli_rev != 3)
  246. return 0;
  247. cnt = LPFC_HBQINFO_SIZE;
  248. spin_lock_irq(&phba->hbalock);
  249. /* toggle between multiple hbqs, if any */
  250. i = lpfc_sli_hbq_count();
  251. if (i > 1) {
  252. lpfc_debugfs_last_hbq++;
  253. if (lpfc_debugfs_last_hbq >= i)
  254. lpfc_debugfs_last_hbq = 0;
  255. }
  256. else
  257. lpfc_debugfs_last_hbq = 0;
  258. i = lpfc_debugfs_last_hbq;
  259. len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
  260. hbqs = &phba->hbqs[i];
  261. posted = 0;
  262. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  263. posted++;
  264. hip = lpfc_hbq_defs[i];
  265. len += snprintf(buf+len, size-len,
  266. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  267. hip->hbq_index, hip->profile, hip->rn,
  268. hip->buffer_count, hip->init_count, hip->add_count, posted);
  269. raw_index = phba->hbq_get[i];
  270. getidx = le32_to_cpu(raw_index);
  271. len += snprintf(buf+len, size-len,
  272. "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  273. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  274. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  275. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  276. for (j=0; j<hbqs->entry_count; j++) {
  277. len += snprintf(buf+len, size-len,
  278. "%03d: %08x %04x %05x ", j,
  279. le32_to_cpu(hbqe->bde.addrLow),
  280. le32_to_cpu(hbqe->bde.tus.w),
  281. le32_to_cpu(hbqe->buffer_tag));
  282. i = 0;
  283. found = 0;
  284. /* First calculate if slot has an associated posted buffer */
  285. low = hbqs->hbqPutIdx - posted;
  286. if (low >= 0) {
  287. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  288. len += snprintf(buf+len, size-len, "Unused\n");
  289. goto skipit;
  290. }
  291. }
  292. else {
  293. if ((j >= hbqs->hbqPutIdx) &&
  294. (j < (hbqs->entry_count+low))) {
  295. len += snprintf(buf+len, size-len, "Unused\n");
  296. goto skipit;
  297. }
  298. }
  299. /* Get the Buffer info for the posted buffer */
  300. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  301. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  302. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  303. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  304. len += snprintf(buf+len, size-len,
  305. "Buf%d: %p %06x\n", i,
  306. hbq_buf->dbuf.virt, hbq_buf->tag);
  307. found = 1;
  308. break;
  309. }
  310. i++;
  311. }
  312. if (!found) {
  313. len += snprintf(buf+len, size-len, "No DMAinfo?\n");
  314. }
  315. skipit:
  316. hbqe++;
  317. if (len > LPFC_HBQINFO_SIZE - 54)
  318. break;
  319. }
  320. spin_unlock_irq(&phba->hbalock);
  321. return len;
  322. }
  323. static int lpfc_debugfs_last_hba_slim_off;
  324. /**
  325. * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
  326. * @phba: The HBA to gather SLIM info from.
  327. * @buf: The buffer to dump log into.
  328. * @size: The maximum amount of data to process.
  329. *
  330. * Description:
  331. * This routine dumps the current contents of HBA SLIM for the HBA associated
  332. * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
  333. *
  334. * Notes:
  335. * This routine will only dump up to 1024 bytes of data each time called and
  336. * should be called multiple times to dump the entire HBA SLIM.
  337. *
  338. * Return Value:
  339. * This routine returns the amount of bytes that were dumped into @buf and will
  340. * not exceed @size.
  341. **/
  342. static int
  343. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  344. {
  345. int len = 0;
  346. int i, off;
  347. uint32_t *ptr;
  348. char buffer[1024];
  349. off = 0;
  350. spin_lock_irq(&phba->hbalock);
  351. len += snprintf(buf+len, size-len, "HBA SLIM\n");
  352. lpfc_memcpy_from_slim(buffer,
  353. phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
  354. ptr = (uint32_t *)&buffer[0];
  355. off = lpfc_debugfs_last_hba_slim_off;
  356. /* Set it up for the next time */
  357. lpfc_debugfs_last_hba_slim_off += 1024;
  358. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  359. lpfc_debugfs_last_hba_slim_off = 0;
  360. i = 1024;
  361. while (i > 0) {
  362. len += snprintf(buf+len, size-len,
  363. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  364. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  365. *(ptr+5), *(ptr+6), *(ptr+7));
  366. ptr += 8;
  367. i -= (8 * sizeof(uint32_t));
  368. off += (8 * sizeof(uint32_t));
  369. }
  370. spin_unlock_irq(&phba->hbalock);
  371. return len;
  372. }
  373. /**
  374. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
  375. * @phba: The HBA to gather Host SLIM info from.
  376. * @buf: The buffer to dump log into.
  377. * @size: The maximum amount of data to process.
  378. *
  379. * Description:
  380. * This routine dumps the current contents of host SLIM for the host associated
  381. * with @phba to @buf up to @size bytes of data. The dump will contain the
  382. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  383. *
  384. * Return Value:
  385. * This routine returns the amount of bytes that were dumped into @buf and will
  386. * not exceed @size.
  387. **/
  388. static int
  389. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  390. {
  391. int len = 0;
  392. int i, off;
  393. uint32_t word0, word1, word2, word3;
  394. uint32_t *ptr;
  395. struct lpfc_pgp *pgpp;
  396. struct lpfc_sli *psli = &phba->sli;
  397. struct lpfc_sli_ring *pring;
  398. off = 0;
  399. spin_lock_irq(&phba->hbalock);
  400. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  401. ptr = (uint32_t *)phba->slim2p.virt;
  402. i = sizeof(MAILBOX_t);
  403. while (i > 0) {
  404. len += snprintf(buf+len, size-len,
  405. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  406. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  407. *(ptr+5), *(ptr+6), *(ptr+7));
  408. ptr += 8;
  409. i -= (8 * sizeof(uint32_t));
  410. off += (8 * sizeof(uint32_t));
  411. }
  412. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  413. ptr = (uint32_t *)phba->pcb;
  414. i = sizeof(PCB_t);
  415. while (i > 0) {
  416. len += snprintf(buf+len, size-len,
  417. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  418. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  419. *(ptr+5), *(ptr+6), *(ptr+7));
  420. ptr += 8;
  421. i -= (8 * sizeof(uint32_t));
  422. off += (8 * sizeof(uint32_t));
  423. }
  424. for (i = 0; i < 4; i++) {
  425. pgpp = &phba->port_gp[i];
  426. pring = &psli->ring[i];
  427. len += snprintf(buf+len, size-len,
  428. "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
  429. "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
  430. i, pgpp->cmdGetInx, pring->numCiocb,
  431. pring->next_cmdidx, pring->local_getidx,
  432. pring->flag, pgpp->rspPutInx, pring->numRiocb);
  433. }
  434. if (phba->sli_rev <= LPFC_SLI_REV3) {
  435. word0 = readl(phba->HAregaddr);
  436. word1 = readl(phba->CAregaddr);
  437. word2 = readl(phba->HSregaddr);
  438. word3 = readl(phba->HCregaddr);
  439. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
  440. "HC:%08x\n", word0, word1, word2, word3);
  441. }
  442. spin_unlock_irq(&phba->hbalock);
  443. return len;
  444. }
  445. /**
  446. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
  447. * @vport: The vport to gather target node info from.
  448. * @buf: The buffer to dump log into.
  449. * @size: The maximum amount of data to process.
  450. *
  451. * Description:
  452. * This routine dumps the current target node list associated with @vport to
  453. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  454. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  455. *
  456. * Return Value:
  457. * This routine returns the amount of bytes that were dumped into @buf and will
  458. * not exceed @size.
  459. **/
  460. static int
  461. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  462. {
  463. int len = 0;
  464. int cnt;
  465. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  466. struct lpfc_nodelist *ndlp;
  467. unsigned char *statep, *name;
  468. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  469. spin_lock_irq(shost->host_lock);
  470. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  471. if (!cnt) {
  472. len += snprintf(buf+len, size-len,
  473. "Missing Nodelist Entries\n");
  474. break;
  475. }
  476. cnt--;
  477. switch (ndlp->nlp_state) {
  478. case NLP_STE_UNUSED_NODE:
  479. statep = "UNUSED";
  480. break;
  481. case NLP_STE_PLOGI_ISSUE:
  482. statep = "PLOGI ";
  483. break;
  484. case NLP_STE_ADISC_ISSUE:
  485. statep = "ADISC ";
  486. break;
  487. case NLP_STE_REG_LOGIN_ISSUE:
  488. statep = "REGLOG";
  489. break;
  490. case NLP_STE_PRLI_ISSUE:
  491. statep = "PRLI ";
  492. break;
  493. case NLP_STE_UNMAPPED_NODE:
  494. statep = "UNMAP ";
  495. break;
  496. case NLP_STE_MAPPED_NODE:
  497. statep = "MAPPED";
  498. break;
  499. case NLP_STE_NPR_NODE:
  500. statep = "NPR ";
  501. break;
  502. default:
  503. statep = "UNKNOWN";
  504. }
  505. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  506. statep, ndlp->nlp_DID);
  507. name = (unsigned char *)&ndlp->nlp_portname;
  508. len += snprintf(buf+len, size-len,
  509. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  510. *name, *(name+1), *(name+2), *(name+3),
  511. *(name+4), *(name+5), *(name+6), *(name+7));
  512. name = (unsigned char *)&ndlp->nlp_nodename;
  513. len += snprintf(buf+len, size-len,
  514. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  515. *name, *(name+1), *(name+2), *(name+3),
  516. *(name+4), *(name+5), *(name+6), *(name+7));
  517. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  518. ndlp->nlp_rpi, ndlp->nlp_flag);
  519. if (!ndlp->nlp_type)
  520. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  521. if (ndlp->nlp_type & NLP_FC_NODE)
  522. len += snprintf(buf+len, size-len, "FC_NODE ");
  523. if (ndlp->nlp_type & NLP_FABRIC)
  524. len += snprintf(buf+len, size-len, "FABRIC ");
  525. if (ndlp->nlp_type & NLP_FCP_TARGET)
  526. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  527. ndlp->nlp_sid);
  528. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  529. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  530. len += snprintf(buf+len, size-len, "usgmap:%x ",
  531. ndlp->nlp_usg_map);
  532. len += snprintf(buf+len, size-len, "refcnt:%x",
  533. atomic_read(&ndlp->kref.refcount));
  534. len += snprintf(buf+len, size-len, "\n");
  535. }
  536. spin_unlock_irq(shost->host_lock);
  537. return len;
  538. }
  539. #endif
  540. /**
  541. * lpfc_debugfs_disc_trc - Store discovery trace log
  542. * @vport: The vport to associate this trace string with for retrieval.
  543. * @mask: Log entry classification.
  544. * @fmt: Format string to be displayed when dumping the log.
  545. * @data1: 1st data parameter to be applied to @fmt.
  546. * @data2: 2nd data parameter to be applied to @fmt.
  547. * @data3: 3rd data parameter to be applied to @fmt.
  548. *
  549. * Description:
  550. * This routine is used by the driver code to add a debugfs log entry to the
  551. * discovery trace buffer associated with @vport. Only entries with a @mask that
  552. * match the current debugfs discovery mask will be saved. Entries that do not
  553. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  554. * printf when displaying the log.
  555. **/
  556. inline void
  557. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  558. uint32_t data1, uint32_t data2, uint32_t data3)
  559. {
  560. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  561. struct lpfc_debugfs_trc *dtp;
  562. int index;
  563. if (!(lpfc_debugfs_mask_disc_trc & mask))
  564. return;
  565. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  566. !vport || !vport->disc_trc)
  567. return;
  568. index = atomic_inc_return(&vport->disc_trc_cnt) &
  569. (lpfc_debugfs_max_disc_trc - 1);
  570. dtp = vport->disc_trc + index;
  571. dtp->fmt = fmt;
  572. dtp->data1 = data1;
  573. dtp->data2 = data2;
  574. dtp->data3 = data3;
  575. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  576. dtp->jif = jiffies;
  577. #endif
  578. return;
  579. }
  580. /**
  581. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
  582. * @phba: The phba to associate this trace string with for retrieval.
  583. * @fmt: Format string to be displayed when dumping the log.
  584. * @data1: 1st data parameter to be applied to @fmt.
  585. * @data2: 2nd data parameter to be applied to @fmt.
  586. * @data3: 3rd data parameter to be applied to @fmt.
  587. *
  588. * Description:
  589. * This routine is used by the driver code to add a debugfs log entry to the
  590. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  591. * @data3 are used like printf when displaying the log.
  592. **/
  593. inline void
  594. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  595. uint32_t data1, uint32_t data2, uint32_t data3)
  596. {
  597. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  598. struct lpfc_debugfs_trc *dtp;
  599. int index;
  600. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  601. !phba || !phba->slow_ring_trc)
  602. return;
  603. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  604. (lpfc_debugfs_max_slow_ring_trc - 1);
  605. dtp = phba->slow_ring_trc + index;
  606. dtp->fmt = fmt;
  607. dtp->data1 = data1;
  608. dtp->data2 = data2;
  609. dtp->data3 = data3;
  610. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  611. dtp->jif = jiffies;
  612. #endif
  613. return;
  614. }
  615. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  616. /**
  617. * lpfc_debugfs_disc_trc_open - Open the discovery trace log
  618. * @inode: The inode pointer that contains a vport pointer.
  619. * @file: The file pointer to attach the log output.
  620. *
  621. * Description:
  622. * This routine is the entry point for the debugfs open file operation. It gets
  623. * the vport from the i_private field in @inode, allocates the necessary buffer
  624. * for the log, fills the buffer from the in-memory log for this vport, and then
  625. * returns a pointer to that log in the private_data field in @file.
  626. *
  627. * Returns:
  628. * This function returns zero if successful. On error it will return an negative
  629. * error value.
  630. **/
  631. static int
  632. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  633. {
  634. struct lpfc_vport *vport = inode->i_private;
  635. struct lpfc_debug *debug;
  636. int size;
  637. int rc = -ENOMEM;
  638. if (!lpfc_debugfs_max_disc_trc) {
  639. rc = -ENOSPC;
  640. goto out;
  641. }
  642. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  643. if (!debug)
  644. goto out;
  645. /* Round to page boundary */
  646. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  647. size = PAGE_ALIGN(size);
  648. debug->buffer = kmalloc(size, GFP_KERNEL);
  649. if (!debug->buffer) {
  650. kfree(debug);
  651. goto out;
  652. }
  653. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  654. file->private_data = debug;
  655. rc = 0;
  656. out:
  657. return rc;
  658. }
  659. /**
  660. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
  661. * @inode: The inode pointer that contains a vport pointer.
  662. * @file: The file pointer to attach the log output.
  663. *
  664. * Description:
  665. * This routine is the entry point for the debugfs open file operation. It gets
  666. * the vport from the i_private field in @inode, allocates the necessary buffer
  667. * for the log, fills the buffer from the in-memory log for this vport, and then
  668. * returns a pointer to that log in the private_data field in @file.
  669. *
  670. * Returns:
  671. * This function returns zero if successful. On error it will return an negative
  672. * error value.
  673. **/
  674. static int
  675. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  676. {
  677. struct lpfc_hba *phba = inode->i_private;
  678. struct lpfc_debug *debug;
  679. int size;
  680. int rc = -ENOMEM;
  681. if (!lpfc_debugfs_max_slow_ring_trc) {
  682. rc = -ENOSPC;
  683. goto out;
  684. }
  685. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  686. if (!debug)
  687. goto out;
  688. /* Round to page boundary */
  689. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  690. size = PAGE_ALIGN(size);
  691. debug->buffer = kmalloc(size, GFP_KERNEL);
  692. if (!debug->buffer) {
  693. kfree(debug);
  694. goto out;
  695. }
  696. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  697. file->private_data = debug;
  698. rc = 0;
  699. out:
  700. return rc;
  701. }
  702. /**
  703. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
  704. * @inode: The inode pointer that contains a vport pointer.
  705. * @file: The file pointer to attach the log output.
  706. *
  707. * Description:
  708. * This routine is the entry point for the debugfs open file operation. It gets
  709. * the vport from the i_private field in @inode, allocates the necessary buffer
  710. * for the log, fills the buffer from the in-memory log for this vport, and then
  711. * returns a pointer to that log in the private_data field in @file.
  712. *
  713. * Returns:
  714. * This function returns zero if successful. On error it will return an negative
  715. * error value.
  716. **/
  717. static int
  718. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  719. {
  720. struct lpfc_hba *phba = inode->i_private;
  721. struct lpfc_debug *debug;
  722. int rc = -ENOMEM;
  723. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  724. if (!debug)
  725. goto out;
  726. /* Round to page boundary */
  727. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  728. if (!debug->buffer) {
  729. kfree(debug);
  730. goto out;
  731. }
  732. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  733. LPFC_HBQINFO_SIZE);
  734. file->private_data = debug;
  735. rc = 0;
  736. out:
  737. return rc;
  738. }
  739. /**
  740. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
  741. * @inode: The inode pointer that contains a vport pointer.
  742. * @file: The file pointer to attach the log output.
  743. *
  744. * Description:
  745. * This routine is the entry point for the debugfs open file operation. It gets
  746. * the vport from the i_private field in @inode, allocates the necessary buffer
  747. * for the log, fills the buffer from the in-memory log for this vport, and then
  748. * returns a pointer to that log in the private_data field in @file.
  749. *
  750. * Returns:
  751. * This function returns zero if successful. On error it will return an negative
  752. * error value.
  753. **/
  754. static int
  755. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  756. {
  757. struct lpfc_hba *phba = inode->i_private;
  758. struct lpfc_debug *debug;
  759. int rc = -ENOMEM;
  760. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  761. if (!debug)
  762. goto out;
  763. /* Round to page boundary */
  764. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  765. if (!debug->buffer) {
  766. kfree(debug);
  767. goto out;
  768. }
  769. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  770. LPFC_DUMPHBASLIM_SIZE);
  771. file->private_data = debug;
  772. rc = 0;
  773. out:
  774. return rc;
  775. }
  776. /**
  777. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
  778. * @inode: The inode pointer that contains a vport pointer.
  779. * @file: The file pointer to attach the log output.
  780. *
  781. * Description:
  782. * This routine is the entry point for the debugfs open file operation. It gets
  783. * the vport from the i_private field in @inode, allocates the necessary buffer
  784. * for the log, fills the buffer from the in-memory log for this vport, and then
  785. * returns a pointer to that log in the private_data field in @file.
  786. *
  787. * Returns:
  788. * This function returns zero if successful. On error it will return an negative
  789. * error value.
  790. **/
  791. static int
  792. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  793. {
  794. struct lpfc_hba *phba = inode->i_private;
  795. struct lpfc_debug *debug;
  796. int rc = -ENOMEM;
  797. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  798. if (!debug)
  799. goto out;
  800. /* Round to page boundary */
  801. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  802. if (!debug->buffer) {
  803. kfree(debug);
  804. goto out;
  805. }
  806. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  807. LPFC_DUMPHOSTSLIM_SIZE);
  808. file->private_data = debug;
  809. rc = 0;
  810. out:
  811. return rc;
  812. }
  813. static int
  814. lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
  815. {
  816. struct lpfc_debug *debug;
  817. int rc = -ENOMEM;
  818. if (!_dump_buf_data)
  819. return -EBUSY;
  820. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  821. if (!debug)
  822. goto out;
  823. /* Round to page boundary */
  824. printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
  825. __func__, _dump_buf_data);
  826. debug->buffer = _dump_buf_data;
  827. if (!debug->buffer) {
  828. kfree(debug);
  829. goto out;
  830. }
  831. debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
  832. file->private_data = debug;
  833. rc = 0;
  834. out:
  835. return rc;
  836. }
  837. static int
  838. lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
  839. {
  840. struct lpfc_debug *debug;
  841. int rc = -ENOMEM;
  842. if (!_dump_buf_dif)
  843. return -EBUSY;
  844. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  845. if (!debug)
  846. goto out;
  847. /* Round to page boundary */
  848. printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
  849. __func__, _dump_buf_dif, file->f_dentry->d_name.name);
  850. debug->buffer = _dump_buf_dif;
  851. if (!debug->buffer) {
  852. kfree(debug);
  853. goto out;
  854. }
  855. debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
  856. file->private_data = debug;
  857. rc = 0;
  858. out:
  859. return rc;
  860. }
  861. static ssize_t
  862. lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
  863. size_t nbytes, loff_t *ppos)
  864. {
  865. /*
  866. * The Data/DIF buffers only save one failing IO
  867. * The write op is used as a reset mechanism after an IO has
  868. * already been saved to the next one can be saved
  869. */
  870. spin_lock(&_dump_buf_lock);
  871. memset((void *)_dump_buf_data, 0,
  872. ((1 << PAGE_SHIFT) << _dump_buf_data_order));
  873. memset((void *)_dump_buf_dif, 0,
  874. ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
  875. _dump_buf_done = 0;
  876. spin_unlock(&_dump_buf_lock);
  877. return nbytes;
  878. }
  879. /**
  880. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  881. * @inode: The inode pointer that contains a vport pointer.
  882. * @file: The file pointer to attach the log output.
  883. *
  884. * Description:
  885. * This routine is the entry point for the debugfs open file operation. It gets
  886. * the vport from the i_private field in @inode, allocates the necessary buffer
  887. * for the log, fills the buffer from the in-memory log for this vport, and then
  888. * returns a pointer to that log in the private_data field in @file.
  889. *
  890. * Returns:
  891. * This function returns zero if successful. On error it will return an negative
  892. * error value.
  893. **/
  894. static int
  895. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  896. {
  897. struct lpfc_vport *vport = inode->i_private;
  898. struct lpfc_debug *debug;
  899. int rc = -ENOMEM;
  900. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  901. if (!debug)
  902. goto out;
  903. /* Round to page boundary */
  904. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  905. if (!debug->buffer) {
  906. kfree(debug);
  907. goto out;
  908. }
  909. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  910. LPFC_NODELIST_SIZE);
  911. file->private_data = debug;
  912. rc = 0;
  913. out:
  914. return rc;
  915. }
  916. /**
  917. * lpfc_debugfs_lseek - Seek through a debugfs file
  918. * @file: The file pointer to seek through.
  919. * @off: The offset to seek to or the amount to seek by.
  920. * @whence: Indicates how to seek.
  921. *
  922. * Description:
  923. * This routine is the entry point for the debugfs lseek file operation. The
  924. * @whence parameter indicates whether @off is the offset to directly seek to,
  925. * or if it is a value to seek forward or reverse by. This function figures out
  926. * what the new offset of the debugfs file will be and assigns that value to the
  927. * f_pos field of @file.
  928. *
  929. * Returns:
  930. * This function returns the new offset if successful and returns a negative
  931. * error if unable to process the seek.
  932. **/
  933. static loff_t
  934. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  935. {
  936. struct lpfc_debug *debug;
  937. loff_t pos = -1;
  938. debug = file->private_data;
  939. switch (whence) {
  940. case 0:
  941. pos = off;
  942. break;
  943. case 1:
  944. pos = file->f_pos + off;
  945. break;
  946. case 2:
  947. pos = debug->len - off;
  948. }
  949. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  950. }
  951. /**
  952. * lpfc_debugfs_read - Read a debugfs file
  953. * @file: The file pointer to read from.
  954. * @buf: The buffer to copy the data to.
  955. * @nbytes: The number of bytes to read.
  956. * @ppos: The position in the file to start reading from.
  957. *
  958. * Description:
  959. * This routine reads data from from the buffer indicated in the private_data
  960. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  961. * data to @buf.
  962. *
  963. * Returns:
  964. * This function returns the amount of data that was read (this could be less
  965. * than @nbytes if the end of the file was reached) or a negative error value.
  966. **/
  967. static ssize_t
  968. lpfc_debugfs_read(struct file *file, char __user *buf,
  969. size_t nbytes, loff_t *ppos)
  970. {
  971. struct lpfc_debug *debug = file->private_data;
  972. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  973. debug->len);
  974. }
  975. /**
  976. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  977. * @inode: The inode pointer that contains a vport pointer. (unused)
  978. * @file: The file pointer that contains the buffer to release.
  979. *
  980. * Description:
  981. * This routine frees the buffer that was allocated when the debugfs file was
  982. * opened.
  983. *
  984. * Returns:
  985. * This function returns zero.
  986. **/
  987. static int
  988. lpfc_debugfs_release(struct inode *inode, struct file *file)
  989. {
  990. struct lpfc_debug *debug = file->private_data;
  991. kfree(debug->buffer);
  992. kfree(debug);
  993. return 0;
  994. }
  995. static int
  996. lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
  997. {
  998. struct lpfc_debug *debug = file->private_data;
  999. debug->buffer = NULL;
  1000. kfree(debug);
  1001. return 0;
  1002. }
  1003. /*
  1004. * ---------------------------------
  1005. * iDiag debugfs file access methods
  1006. * ---------------------------------
  1007. *
  1008. * All access methods are through the proper SLI4 PCI function's debugfs
  1009. * iDiag directory:
  1010. *
  1011. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  1012. */
  1013. /**
  1014. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  1015. * @buf: The pointer to the user space buffer.
  1016. * @nbytes: The number of bytes in the user space buffer.
  1017. * @idiag_cmd: pointer to the idiag command struct.
  1018. *
  1019. * This routine reads data from debugfs user space buffer and parses the
  1020. * buffer for getting the idiag command and arguments. The while space in
  1021. * between the set of data is used as the parsing separator.
  1022. *
  1023. * This routine returns 0 when successful, it returns proper error code
  1024. * back to the user space in error conditions.
  1025. */
  1026. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  1027. struct lpfc_idiag_cmd *idiag_cmd)
  1028. {
  1029. char mybuf[64];
  1030. char *pbuf, *step_str;
  1031. int i;
  1032. size_t bsize;
  1033. /* Protect copy from user */
  1034. if (!access_ok(VERIFY_READ, buf, nbytes))
  1035. return -EFAULT;
  1036. memset(mybuf, 0, sizeof(mybuf));
  1037. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  1038. bsize = min(nbytes, (sizeof(mybuf)-1));
  1039. if (copy_from_user(mybuf, buf, bsize))
  1040. return -EFAULT;
  1041. pbuf = &mybuf[0];
  1042. step_str = strsep(&pbuf, "\t ");
  1043. /* The opcode must present */
  1044. if (!step_str)
  1045. return -EINVAL;
  1046. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  1047. if (idiag_cmd->opcode == 0)
  1048. return -EINVAL;
  1049. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  1050. step_str = strsep(&pbuf, "\t ");
  1051. if (!step_str)
  1052. return i;
  1053. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  1054. }
  1055. return i;
  1056. }
  1057. /**
  1058. * lpfc_idiag_open - idiag open debugfs
  1059. * @inode: The inode pointer that contains a pointer to phba.
  1060. * @file: The file pointer to attach the file operation.
  1061. *
  1062. * Description:
  1063. * This routine is the entry point for the debugfs open file operation. It
  1064. * gets the reference to phba from the i_private field in @inode, it then
  1065. * allocates buffer for the file operation, performs the necessary PCI config
  1066. * space read into the allocated buffer according to the idiag user command
  1067. * setup, and then returns a pointer to buffer in the private_data field in
  1068. * @file.
  1069. *
  1070. * Returns:
  1071. * This function returns zero if successful. On error it will return an
  1072. * negative error value.
  1073. **/
  1074. static int
  1075. lpfc_idiag_open(struct inode *inode, struct file *file)
  1076. {
  1077. struct lpfc_debug *debug;
  1078. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1079. if (!debug)
  1080. return -ENOMEM;
  1081. debug->i_private = inode->i_private;
  1082. debug->buffer = NULL;
  1083. file->private_data = debug;
  1084. return 0;
  1085. }
  1086. /**
  1087. * lpfc_idiag_release - Release idiag access file operation
  1088. * @inode: The inode pointer that contains a vport pointer. (unused)
  1089. * @file: The file pointer that contains the buffer to release.
  1090. *
  1091. * Description:
  1092. * This routine is the generic release routine for the idiag access file
  1093. * operation, it frees the buffer that was allocated when the debugfs file
  1094. * was opened.
  1095. *
  1096. * Returns:
  1097. * This function returns zero.
  1098. **/
  1099. static int
  1100. lpfc_idiag_release(struct inode *inode, struct file *file)
  1101. {
  1102. struct lpfc_debug *debug = file->private_data;
  1103. /* Free the buffers to the file operation */
  1104. kfree(debug->buffer);
  1105. kfree(debug);
  1106. return 0;
  1107. }
  1108. /**
  1109. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  1110. * @inode: The inode pointer that contains a vport pointer. (unused)
  1111. * @file: The file pointer that contains the buffer to release.
  1112. *
  1113. * Description:
  1114. * This routine frees the buffer that was allocated when the debugfs file
  1115. * was opened. It also reset the fields in the idiag command struct in the
  1116. * case of command for write operation.
  1117. *
  1118. * Returns:
  1119. * This function returns zero.
  1120. **/
  1121. static int
  1122. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  1123. {
  1124. struct lpfc_debug *debug = file->private_data;
  1125. if (debug->op == LPFC_IDIAG_OP_WR) {
  1126. switch (idiag.cmd.opcode) {
  1127. case LPFC_IDIAG_CMD_PCICFG_WR:
  1128. case LPFC_IDIAG_CMD_PCICFG_ST:
  1129. case LPFC_IDIAG_CMD_PCICFG_CL:
  1130. case LPFC_IDIAG_CMD_QUEACC_WR:
  1131. case LPFC_IDIAG_CMD_QUEACC_ST:
  1132. case LPFC_IDIAG_CMD_QUEACC_CL:
  1133. memset(&idiag, 0, sizeof(idiag));
  1134. break;
  1135. default:
  1136. break;
  1137. }
  1138. }
  1139. /* Free the buffers to the file operation */
  1140. kfree(debug->buffer);
  1141. kfree(debug);
  1142. return 0;
  1143. }
  1144. /**
  1145. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  1146. * @file: The file pointer to read from.
  1147. * @buf: The buffer to copy the data to.
  1148. * @nbytes: The number of bytes to read.
  1149. * @ppos: The position in the file to start reading from.
  1150. *
  1151. * Description:
  1152. * This routine reads data from the @phba pci config space according to the
  1153. * idiag command, and copies to user @buf. Depending on the PCI config space
  1154. * read command setup, it does either a single register read of a byte
  1155. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  1156. * registers from the 4K extended PCI config space.
  1157. *
  1158. * Returns:
  1159. * This function returns the amount of data that was read (this could be less
  1160. * than @nbytes if the end of the file was reached) or a negative error value.
  1161. **/
  1162. static ssize_t
  1163. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  1164. loff_t *ppos)
  1165. {
  1166. struct lpfc_debug *debug = file->private_data;
  1167. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1168. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  1169. int where, count;
  1170. char *pbuffer;
  1171. struct pci_dev *pdev;
  1172. uint32_t u32val;
  1173. uint16_t u16val;
  1174. uint8_t u8val;
  1175. pdev = phba->pcidev;
  1176. if (!pdev)
  1177. return 0;
  1178. /* This is a user read operation */
  1179. debug->op = LPFC_IDIAG_OP_RD;
  1180. if (!debug->buffer)
  1181. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  1182. if (!debug->buffer)
  1183. return 0;
  1184. pbuffer = debug->buffer;
  1185. if (*ppos)
  1186. return 0;
  1187. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1188. where = idiag.cmd.data[0];
  1189. count = idiag.cmd.data[1];
  1190. } else
  1191. return 0;
  1192. /* Read single PCI config space register */
  1193. switch (count) {
  1194. case SIZE_U8: /* byte (8 bits) */
  1195. pci_read_config_byte(pdev, where, &u8val);
  1196. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1197. "%03x: %02x\n", where, u8val);
  1198. break;
  1199. case SIZE_U16: /* word (16 bits) */
  1200. pci_read_config_word(pdev, where, &u16val);
  1201. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1202. "%03x: %04x\n", where, u16val);
  1203. break;
  1204. case SIZE_U32: /* double word (32 bits) */
  1205. pci_read_config_dword(pdev, where, &u32val);
  1206. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1207. "%03x: %08x\n", where, u32val);
  1208. break;
  1209. case LPFC_PCI_CFG_BROWSE: /* browse all */
  1210. goto pcicfg_browse;
  1211. break;
  1212. default:
  1213. /* illegal count */
  1214. len = 0;
  1215. break;
  1216. }
  1217. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1218. pcicfg_browse:
  1219. /* Browse all PCI config space registers */
  1220. offset_label = idiag.offset.last_rd;
  1221. offset = offset_label;
  1222. /* Read PCI config space */
  1223. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1224. "%03x: ", offset_label);
  1225. while (index > 0) {
  1226. pci_read_config_dword(pdev, offset, &u32val);
  1227. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1228. "%08x ", u32val);
  1229. offset += sizeof(uint32_t);
  1230. index -= sizeof(uint32_t);
  1231. if (!index)
  1232. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1233. "\n");
  1234. else if (!(index % (8 * sizeof(uint32_t)))) {
  1235. offset_label += (8 * sizeof(uint32_t));
  1236. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1237. "\n%03x: ", offset_label);
  1238. }
  1239. }
  1240. /* Set up the offset for next portion of pci cfg read */
  1241. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  1242. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  1243. idiag.offset.last_rd = 0;
  1244. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1245. }
  1246. /**
  1247. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  1248. * @file: The file pointer to read from.
  1249. * @buf: The buffer to copy the user data from.
  1250. * @nbytes: The number of bytes to get.
  1251. * @ppos: The position in the file to start reading from.
  1252. *
  1253. * This routine get the debugfs idiag command struct from user space and
  1254. * then perform the syntax check for PCI config space read or write command
  1255. * accordingly. In the case of PCI config space read command, it sets up
  1256. * the command in the idiag command struct for the debugfs read operation.
  1257. * In the case of PCI config space write operation, it executes the write
  1258. * operation into the PCI config space accordingly.
  1259. *
  1260. * It returns the @nbytges passing in from debugfs user space when successful.
  1261. * In case of error conditions, it returns proper error code back to the user
  1262. * space.
  1263. */
  1264. static ssize_t
  1265. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  1266. size_t nbytes, loff_t *ppos)
  1267. {
  1268. struct lpfc_debug *debug = file->private_data;
  1269. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1270. uint32_t where, value, count;
  1271. uint32_t u32val;
  1272. uint16_t u16val;
  1273. uint8_t u8val;
  1274. struct pci_dev *pdev;
  1275. int rc;
  1276. pdev = phba->pcidev;
  1277. if (!pdev)
  1278. return -EFAULT;
  1279. /* This is a user write operation */
  1280. debug->op = LPFC_IDIAG_OP_WR;
  1281. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1282. if (rc < 0)
  1283. return rc;
  1284. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1285. /* Sanity check on PCI config read command line arguments */
  1286. if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
  1287. goto error_out;
  1288. /* Read command from PCI config space, set up command fields */
  1289. where = idiag.cmd.data[0];
  1290. count = idiag.cmd.data[1];
  1291. if (count == LPFC_PCI_CFG_BROWSE) {
  1292. if (where % sizeof(uint32_t))
  1293. goto error_out;
  1294. /* Starting offset to browse */
  1295. idiag.offset.last_rd = where;
  1296. } else if ((count != sizeof(uint8_t)) &&
  1297. (count != sizeof(uint16_t)) &&
  1298. (count != sizeof(uint32_t)))
  1299. goto error_out;
  1300. if (count == sizeof(uint8_t)) {
  1301. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1302. goto error_out;
  1303. if (where % sizeof(uint8_t))
  1304. goto error_out;
  1305. }
  1306. if (count == sizeof(uint16_t)) {
  1307. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1308. goto error_out;
  1309. if (where % sizeof(uint16_t))
  1310. goto error_out;
  1311. }
  1312. if (count == sizeof(uint32_t)) {
  1313. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1314. goto error_out;
  1315. if (where % sizeof(uint32_t))
  1316. goto error_out;
  1317. }
  1318. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  1319. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  1320. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1321. /* Sanity check on PCI config write command line arguments */
  1322. if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
  1323. goto error_out;
  1324. /* Write command to PCI config space, read-modify-write */
  1325. where = idiag.cmd.data[0];
  1326. count = idiag.cmd.data[1];
  1327. value = idiag.cmd.data[2];
  1328. /* Sanity checks */
  1329. if ((count != sizeof(uint8_t)) &&
  1330. (count != sizeof(uint16_t)) &&
  1331. (count != sizeof(uint32_t)))
  1332. goto error_out;
  1333. if (count == sizeof(uint8_t)) {
  1334. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1335. goto error_out;
  1336. if (where % sizeof(uint8_t))
  1337. goto error_out;
  1338. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1339. pci_write_config_byte(pdev, where,
  1340. (uint8_t)value);
  1341. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1342. rc = pci_read_config_byte(pdev, where, &u8val);
  1343. if (!rc) {
  1344. u8val |= (uint8_t)value;
  1345. pci_write_config_byte(pdev, where,
  1346. u8val);
  1347. }
  1348. }
  1349. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1350. rc = pci_read_config_byte(pdev, where, &u8val);
  1351. if (!rc) {
  1352. u8val &= (uint8_t)(~value);
  1353. pci_write_config_byte(pdev, where,
  1354. u8val);
  1355. }
  1356. }
  1357. }
  1358. if (count == sizeof(uint16_t)) {
  1359. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1360. goto error_out;
  1361. if (where % sizeof(uint16_t))
  1362. goto error_out;
  1363. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1364. pci_write_config_word(pdev, where,
  1365. (uint16_t)value);
  1366. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1367. rc = pci_read_config_word(pdev, where, &u16val);
  1368. if (!rc) {
  1369. u16val |= (uint16_t)value;
  1370. pci_write_config_word(pdev, where,
  1371. u16val);
  1372. }
  1373. }
  1374. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1375. rc = pci_read_config_word(pdev, where, &u16val);
  1376. if (!rc) {
  1377. u16val &= (uint16_t)(~value);
  1378. pci_write_config_word(pdev, where,
  1379. u16val);
  1380. }
  1381. }
  1382. }
  1383. if (count == sizeof(uint32_t)) {
  1384. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1385. goto error_out;
  1386. if (where % sizeof(uint32_t))
  1387. goto error_out;
  1388. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1389. pci_write_config_dword(pdev, where, value);
  1390. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1391. rc = pci_read_config_dword(pdev, where,
  1392. &u32val);
  1393. if (!rc) {
  1394. u32val |= value;
  1395. pci_write_config_dword(pdev, where,
  1396. u32val);
  1397. }
  1398. }
  1399. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1400. rc = pci_read_config_dword(pdev, where,
  1401. &u32val);
  1402. if (!rc) {
  1403. u32val &= ~value;
  1404. pci_write_config_dword(pdev, where,
  1405. u32val);
  1406. }
  1407. }
  1408. }
  1409. } else
  1410. /* All other opecodes are illegal for now */
  1411. goto error_out;
  1412. return nbytes;
  1413. error_out:
  1414. memset(&idiag, 0, sizeof(idiag));
  1415. return -EINVAL;
  1416. }
  1417. /**
  1418. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  1419. * @file: The file pointer to read from.
  1420. * @buf: The buffer to copy the data to.
  1421. * @nbytes: The number of bytes to read.
  1422. * @ppos: The position in the file to start reading from.
  1423. *
  1424. * Description:
  1425. * This routine reads data from the @phba SLI4 PCI function queue information,
  1426. * and copies to user @buf.
  1427. *
  1428. * Returns:
  1429. * This function returns the amount of data that was read (this could be less
  1430. * than @nbytes if the end of the file was reached) or a negative error value.
  1431. **/
  1432. static ssize_t
  1433. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  1434. loff_t *ppos)
  1435. {
  1436. struct lpfc_debug *debug = file->private_data;
  1437. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1438. int len = 0, fcp_qidx;
  1439. char *pbuffer;
  1440. if (!debug->buffer)
  1441. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  1442. if (!debug->buffer)
  1443. return 0;
  1444. pbuffer = debug->buffer;
  1445. if (*ppos)
  1446. return 0;
  1447. /* Get slow-path event queue information */
  1448. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1449. "Slow-path EQ information:\n");
  1450. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1451. "\tEQID[%02d], "
  1452. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1453. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1454. phba->sli4_hba.sp_eq->queue_id,
  1455. phba->sli4_hba.sp_eq->entry_count,
  1456. phba->sli4_hba.sp_eq->entry_size,
  1457. phba->sli4_hba.sp_eq->host_index,
  1458. phba->sli4_hba.sp_eq->hba_index);
  1459. /* Get fast-path event queue information */
  1460. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1461. "Fast-path EQ information:\n");
  1462. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
  1463. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1464. "\tEQID[%02d], "
  1465. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1466. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1467. phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
  1468. phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
  1469. phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
  1470. phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
  1471. phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
  1472. }
  1473. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1474. /* Get mailbox complete queue information */
  1475. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1476. "Slow-path MBX CQ information:\n");
  1477. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1478. "Associated EQID[%02d]:\n",
  1479. phba->sli4_hba.mbx_cq->assoc_qid);
  1480. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1481. "\tCQID[%02d], "
  1482. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1483. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1484. phba->sli4_hba.mbx_cq->queue_id,
  1485. phba->sli4_hba.mbx_cq->entry_count,
  1486. phba->sli4_hba.mbx_cq->entry_size,
  1487. phba->sli4_hba.mbx_cq->host_index,
  1488. phba->sli4_hba.mbx_cq->hba_index);
  1489. /* Get slow-path complete queue information */
  1490. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1491. "Slow-path ELS CQ information:\n");
  1492. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1493. "Associated EQID[%02d]:\n",
  1494. phba->sli4_hba.els_cq->assoc_qid);
  1495. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1496. "\tCQID [%02d], "
  1497. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1498. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1499. phba->sli4_hba.els_cq->queue_id,
  1500. phba->sli4_hba.els_cq->entry_count,
  1501. phba->sli4_hba.els_cq->entry_size,
  1502. phba->sli4_hba.els_cq->host_index,
  1503. phba->sli4_hba.els_cq->hba_index);
  1504. /* Get fast-path complete queue information */
  1505. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1506. "Fast-path FCP CQ information:\n");
  1507. fcp_qidx = 0;
  1508. do {
  1509. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1510. "Associated EQID[%02d]:\n",
  1511. phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
  1512. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1513. "\tCQID[%02d], "
  1514. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1515. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1516. phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
  1517. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
  1518. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
  1519. phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
  1520. phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
  1521. } while (++fcp_qidx < phba->cfg_fcp_eq_count);
  1522. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1523. /* Get mailbox queue information */
  1524. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1525. "Slow-path MBX MQ information:\n");
  1526. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1527. "Associated CQID[%02d]:\n",
  1528. phba->sli4_hba.mbx_wq->assoc_qid);
  1529. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1530. "\tWQID[%02d], "
  1531. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1532. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1533. phba->sli4_hba.mbx_wq->queue_id,
  1534. phba->sli4_hba.mbx_wq->entry_count,
  1535. phba->sli4_hba.mbx_wq->entry_size,
  1536. phba->sli4_hba.mbx_wq->host_index,
  1537. phba->sli4_hba.mbx_wq->hba_index);
  1538. /* Get slow-path work queue information */
  1539. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1540. "Slow-path ELS WQ information:\n");
  1541. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1542. "Associated CQID[%02d]:\n",
  1543. phba->sli4_hba.els_wq->assoc_qid);
  1544. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1545. "\tWQID[%02d], "
  1546. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1547. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1548. phba->sli4_hba.els_wq->queue_id,
  1549. phba->sli4_hba.els_wq->entry_count,
  1550. phba->sli4_hba.els_wq->entry_size,
  1551. phba->sli4_hba.els_wq->host_index,
  1552. phba->sli4_hba.els_wq->hba_index);
  1553. /* Get fast-path work queue information */
  1554. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1555. "Fast-path FCP WQ information:\n");
  1556. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
  1557. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1558. "Associated CQID[%02d]:\n",
  1559. phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
  1560. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1561. "\tWQID[%02d], "
  1562. "QE-COUNT[%04d], WQE-SIZE[%04d], "
  1563. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1564. phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
  1565. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
  1566. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
  1567. phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
  1568. phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
  1569. }
  1570. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1571. /* Get receive queue information */
  1572. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1573. "Slow-path RQ information:\n");
  1574. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1575. "Associated CQID[%02d]:\n",
  1576. phba->sli4_hba.hdr_rq->assoc_qid);
  1577. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1578. "\tHQID[%02d], "
  1579. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1580. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1581. phba->sli4_hba.hdr_rq->queue_id,
  1582. phba->sli4_hba.hdr_rq->entry_count,
  1583. phba->sli4_hba.hdr_rq->entry_size,
  1584. phba->sli4_hba.hdr_rq->host_index,
  1585. phba->sli4_hba.hdr_rq->hba_index);
  1586. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1587. "\tDQID[%02d], "
  1588. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1589. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1590. phba->sli4_hba.dat_rq->queue_id,
  1591. phba->sli4_hba.dat_rq->entry_count,
  1592. phba->sli4_hba.dat_rq->entry_size,
  1593. phba->sli4_hba.dat_rq->host_index,
  1594. phba->sli4_hba.dat_rq->hba_index);
  1595. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1596. }
  1597. /**
  1598. * lpfc_idiag_que_param_check - queue access command parameter sanity check
  1599. * @q: The pointer to queue structure.
  1600. * @index: The index into a queue entry.
  1601. * @count: The number of queue entries to access.
  1602. *
  1603. * Description:
  1604. * The routine performs sanity check on device queue access method commands.
  1605. *
  1606. * Returns:
  1607. * This function returns -EINVAL when fails the sanity check, otherwise, it
  1608. * returns 0.
  1609. **/
  1610. static int
  1611. lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
  1612. {
  1613. /* Only support single entry read or browsing */
  1614. if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
  1615. return -EINVAL;
  1616. if (index > q->entry_count - 1)
  1617. return -EINVAL;
  1618. return 0;
  1619. }
  1620. /**
  1621. * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
  1622. * @pbuffer: The pointer to buffer to copy the read data into.
  1623. * @pque: The pointer to the queue to be read.
  1624. * @index: The index into the queue entry.
  1625. *
  1626. * Description:
  1627. * This routine reads out a single entry from the given queue's index location
  1628. * and copies it into the buffer provided.
  1629. *
  1630. * Returns:
  1631. * This function returns 0 when it fails, otherwise, it returns the length of
  1632. * the data read into the buffer provided.
  1633. **/
  1634. static int
  1635. lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
  1636. uint32_t index)
  1637. {
  1638. int offset, esize;
  1639. uint32_t *pentry;
  1640. if (!pbuffer || !pque)
  1641. return 0;
  1642. esize = pque->entry_size;
  1643. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  1644. "QE-INDEX[%04d]:\n", index);
  1645. offset = 0;
  1646. pentry = pque->qe[index].address;
  1647. while (esize > 0) {
  1648. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  1649. "%08x ", *pentry);
  1650. pentry++;
  1651. offset += sizeof(uint32_t);
  1652. esize -= sizeof(uint32_t);
  1653. if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
  1654. len += snprintf(pbuffer+len,
  1655. LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  1656. }
  1657. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  1658. return len;
  1659. }
  1660. /**
  1661. * lpfc_idiag_queacc_read - idiag debugfs read port queue
  1662. * @file: The file pointer to read from.
  1663. * @buf: The buffer to copy the data to.
  1664. * @nbytes: The number of bytes to read.
  1665. * @ppos: The position in the file to start reading from.
  1666. *
  1667. * Description:
  1668. * This routine reads data from the @phba device queue memory according to the
  1669. * idiag command, and copies to user @buf. Depending on the queue dump read
  1670. * command setup, it does either a single queue entry read or browing through
  1671. * all entries of the queue.
  1672. *
  1673. * Returns:
  1674. * This function returns the amount of data that was read (this could be less
  1675. * than @nbytes if the end of the file was reached) or a negative error value.
  1676. **/
  1677. static ssize_t
  1678. lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
  1679. loff_t *ppos)
  1680. {
  1681. struct lpfc_debug *debug = file->private_data;
  1682. uint32_t last_index, index, count;
  1683. struct lpfc_queue *pque = NULL;
  1684. char *pbuffer;
  1685. int len = 0;
  1686. /* This is a user read operation */
  1687. debug->op = LPFC_IDIAG_OP_RD;
  1688. if (!debug->buffer)
  1689. debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
  1690. if (!debug->buffer)
  1691. return 0;
  1692. pbuffer = debug->buffer;
  1693. if (*ppos)
  1694. return 0;
  1695. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  1696. index = idiag.cmd.data[2];
  1697. count = idiag.cmd.data[3];
  1698. pque = (struct lpfc_queue *)idiag.ptr_private;
  1699. } else
  1700. return 0;
  1701. /* Browse the queue starting from index */
  1702. if (count == LPFC_QUE_ACC_BROWSE)
  1703. goto que_browse;
  1704. /* Read a single entry from the queue */
  1705. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  1706. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1707. que_browse:
  1708. /* Browse all entries from the queue */
  1709. last_index = idiag.offset.last_rd;
  1710. index = last_index;
  1711. while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
  1712. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  1713. index++;
  1714. if (index > pque->entry_count - 1)
  1715. break;
  1716. }
  1717. /* Set up the offset for next portion of pci cfg read */
  1718. if (index > pque->entry_count - 1)
  1719. index = 0;
  1720. idiag.offset.last_rd = index;
  1721. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1722. }
  1723. /**
  1724. * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
  1725. * @file: The file pointer to read from.
  1726. * @buf: The buffer to copy the user data from.
  1727. * @nbytes: The number of bytes to get.
  1728. * @ppos: The position in the file to start reading from.
  1729. *
  1730. * This routine get the debugfs idiag command struct from user space and then
  1731. * perform the syntax check for port queue read (dump) or write (set) command
  1732. * accordingly. In the case of port queue read command, it sets up the command
  1733. * in the idiag command struct for the following debugfs read operation. In
  1734. * the case of port queue write operation, it executes the write operation
  1735. * into the port queue entry accordingly.
  1736. *
  1737. * It returns the @nbytges passing in from debugfs user space when successful.
  1738. * In case of error conditions, it returns proper error code back to the user
  1739. * space.
  1740. **/
  1741. static ssize_t
  1742. lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
  1743. size_t nbytes, loff_t *ppos)
  1744. {
  1745. struct lpfc_debug *debug = file->private_data;
  1746. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1747. uint32_t qidx, quetp, queid, index, count, offset, value;
  1748. uint32_t *pentry;
  1749. struct lpfc_queue *pque;
  1750. int rc;
  1751. /* This is a user write operation */
  1752. debug->op = LPFC_IDIAG_OP_WR;
  1753. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1754. if (rc < 0)
  1755. return rc;
  1756. /* Get and sanity check on command feilds */
  1757. quetp = idiag.cmd.data[0];
  1758. queid = idiag.cmd.data[1];
  1759. index = idiag.cmd.data[2];
  1760. count = idiag.cmd.data[3];
  1761. offset = idiag.cmd.data[4];
  1762. value = idiag.cmd.data[5];
  1763. /* Sanity check on command line arguments */
  1764. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  1765. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  1766. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  1767. if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
  1768. goto error_out;
  1769. if (count != 1)
  1770. goto error_out;
  1771. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  1772. if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
  1773. goto error_out;
  1774. } else
  1775. goto error_out;
  1776. switch (quetp) {
  1777. case LPFC_IDIAG_EQ:
  1778. /* Slow-path event queue */
  1779. if (phba->sli4_hba.sp_eq->queue_id == queid) {
  1780. /* Sanity check */
  1781. rc = lpfc_idiag_que_param_check(
  1782. phba->sli4_hba.sp_eq, index, count);
  1783. if (rc)
  1784. goto error_out;
  1785. idiag.ptr_private = phba->sli4_hba.sp_eq;
  1786. goto pass_check;
  1787. }
  1788. /* Fast-path event queue */
  1789. for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
  1790. if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
  1791. /* Sanity check */
  1792. rc = lpfc_idiag_que_param_check(
  1793. phba->sli4_hba.fp_eq[qidx],
  1794. index, count);
  1795. if (rc)
  1796. goto error_out;
  1797. idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
  1798. goto pass_check;
  1799. }
  1800. }
  1801. goto error_out;
  1802. break;
  1803. case LPFC_IDIAG_CQ:
  1804. /* MBX complete queue */
  1805. if (phba->sli4_hba.mbx_cq->queue_id == queid) {
  1806. /* Sanity check */
  1807. rc = lpfc_idiag_que_param_check(
  1808. phba->sli4_hba.mbx_cq, index, count);
  1809. if (rc)
  1810. goto error_out;
  1811. idiag.ptr_private = phba->sli4_hba.mbx_cq;
  1812. goto pass_check;
  1813. }
  1814. /* ELS complete queue */
  1815. if (phba->sli4_hba.els_cq->queue_id == queid) {
  1816. /* Sanity check */
  1817. rc = lpfc_idiag_que_param_check(
  1818. phba->sli4_hba.els_cq, index, count);
  1819. if (rc)
  1820. goto error_out;
  1821. idiag.ptr_private = phba->sli4_hba.els_cq;
  1822. goto pass_check;
  1823. }
  1824. /* FCP complete queue */
  1825. qidx = 0;
  1826. do {
  1827. if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
  1828. /* Sanity check */
  1829. rc = lpfc_idiag_que_param_check(
  1830. phba->sli4_hba.fcp_cq[qidx],
  1831. index, count);
  1832. if (rc)
  1833. goto error_out;
  1834. idiag.ptr_private =
  1835. phba->sli4_hba.fcp_cq[qidx];
  1836. goto pass_check;
  1837. }
  1838. } while (++qidx < phba->cfg_fcp_eq_count);
  1839. goto error_out;
  1840. break;
  1841. case LPFC_IDIAG_MQ:
  1842. /* MBX work queue */
  1843. if (phba->sli4_hba.mbx_wq->queue_id == queid) {
  1844. /* Sanity check */
  1845. rc = lpfc_idiag_que_param_check(
  1846. phba->sli4_hba.mbx_wq, index, count);
  1847. if (rc)
  1848. goto error_out;
  1849. idiag.ptr_private = phba->sli4_hba.mbx_wq;
  1850. goto pass_check;
  1851. }
  1852. break;
  1853. case LPFC_IDIAG_WQ:
  1854. /* ELS work queue */
  1855. if (phba->sli4_hba.els_wq->queue_id == queid) {
  1856. /* Sanity check */
  1857. rc = lpfc_idiag_que_param_check(
  1858. phba->sli4_hba.els_wq, index, count);
  1859. if (rc)
  1860. goto error_out;
  1861. idiag.ptr_private = phba->sli4_hba.els_wq;
  1862. goto pass_check;
  1863. }
  1864. /* FCP work queue */
  1865. for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
  1866. if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
  1867. /* Sanity check */
  1868. rc = lpfc_idiag_que_param_check(
  1869. phba->sli4_hba.fcp_wq[qidx],
  1870. index, count);
  1871. if (rc)
  1872. goto error_out;
  1873. idiag.ptr_private =
  1874. phba->sli4_hba.fcp_wq[qidx];
  1875. goto pass_check;
  1876. }
  1877. }
  1878. goto error_out;
  1879. break;
  1880. case LPFC_IDIAG_RQ:
  1881. /* HDR queue */
  1882. if (phba->sli4_hba.hdr_rq->queue_id == queid) {
  1883. /* Sanity check */
  1884. rc = lpfc_idiag_que_param_check(
  1885. phba->sli4_hba.hdr_rq, index, count);
  1886. if (rc)
  1887. goto error_out;
  1888. idiag.ptr_private = phba->sli4_hba.hdr_rq;
  1889. goto pass_check;
  1890. }
  1891. /* DAT queue */
  1892. if (phba->sli4_hba.dat_rq->queue_id == queid) {
  1893. /* Sanity check */
  1894. rc = lpfc_idiag_que_param_check(
  1895. phba->sli4_hba.dat_rq, index, count);
  1896. if (rc)
  1897. goto error_out;
  1898. idiag.ptr_private = phba->sli4_hba.dat_rq;
  1899. goto pass_check;
  1900. }
  1901. goto error_out;
  1902. break;
  1903. default:
  1904. goto error_out;
  1905. break;
  1906. }
  1907. pass_check:
  1908. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  1909. if (count == LPFC_QUE_ACC_BROWSE)
  1910. idiag.offset.last_rd = index;
  1911. }
  1912. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  1913. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  1914. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  1915. /* Additional sanity checks on write operation */
  1916. pque = (struct lpfc_queue *)idiag.ptr_private;
  1917. if (offset > pque->entry_size/sizeof(uint32_t) - 1)
  1918. goto error_out;
  1919. pentry = pque->qe[index].address;
  1920. pentry += offset;
  1921. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
  1922. *pentry = value;
  1923. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
  1924. *pentry |= value;
  1925. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
  1926. *pentry &= ~value;
  1927. }
  1928. return nbytes;
  1929. error_out:
  1930. /* Clean out command structure on command error out */
  1931. memset(&idiag, 0, sizeof(idiag));
  1932. return -EINVAL;
  1933. }
  1934. /**
  1935. * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
  1936. * @phba: The pointer to hba structure.
  1937. * @pbuffer: The pointer to the buffer to copy the data to.
  1938. * @len: The lenght of bytes to copied.
  1939. * @drbregid: The id to doorbell registers.
  1940. *
  1941. * Description:
  1942. * This routine reads a doorbell register and copies its content to the
  1943. * user buffer pointed to by @pbuffer.
  1944. *
  1945. * Returns:
  1946. * This function returns the amount of data that was copied into @pbuffer.
  1947. **/
  1948. static int
  1949. lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  1950. int len, uint32_t drbregid)
  1951. {
  1952. if (!pbuffer)
  1953. return 0;
  1954. switch (drbregid) {
  1955. case LPFC_DRB_EQCQ:
  1956. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  1957. "EQCQ-DRB-REG: 0x%08x\n",
  1958. readl(phba->sli4_hba.EQCQDBregaddr));
  1959. break;
  1960. case LPFC_DRB_MQ:
  1961. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  1962. "MQ-DRB-REG: 0x%08x\n",
  1963. readl(phba->sli4_hba.MQDBregaddr));
  1964. break;
  1965. case LPFC_DRB_WQ:
  1966. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  1967. "WQ-DRB-REG: 0x%08x\n",
  1968. readl(phba->sli4_hba.WQDBregaddr));
  1969. break;
  1970. case LPFC_DRB_RQ:
  1971. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  1972. "RQ-DRB-REG: 0x%08x\n",
  1973. readl(phba->sli4_hba.RQDBregaddr));
  1974. break;
  1975. default:
  1976. break;
  1977. }
  1978. return len;
  1979. }
  1980. /**
  1981. * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
  1982. * @file: The file pointer to read from.
  1983. * @buf: The buffer to copy the data to.
  1984. * @nbytes: The number of bytes to read.
  1985. * @ppos: The position in the file to start reading from.
  1986. *
  1987. * Description:
  1988. * This routine reads data from the @phba device doorbell register according
  1989. * to the idiag command, and copies to user @buf. Depending on the doorbell
  1990. * register read command setup, it does either a single doorbell register
  1991. * read or dump all doorbell registers.
  1992. *
  1993. * Returns:
  1994. * This function returns the amount of data that was read (this could be less
  1995. * than @nbytes if the end of the file was reached) or a negative error value.
  1996. **/
  1997. static ssize_t
  1998. lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
  1999. loff_t *ppos)
  2000. {
  2001. struct lpfc_debug *debug = file->private_data;
  2002. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2003. uint32_t drb_reg_id, i;
  2004. char *pbuffer;
  2005. int len = 0;
  2006. /* This is a user read operation */
  2007. debug->op = LPFC_IDIAG_OP_RD;
  2008. if (!debug->buffer)
  2009. debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
  2010. if (!debug->buffer)
  2011. return 0;
  2012. pbuffer = debug->buffer;
  2013. if (*ppos)
  2014. return 0;
  2015. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
  2016. drb_reg_id = idiag.cmd.data[0];
  2017. else
  2018. return 0;
  2019. if (drb_reg_id == LPFC_DRB_ACC_ALL)
  2020. for (i = 1; i <= LPFC_DRB_MAX; i++)
  2021. len = lpfc_idiag_drbacc_read_reg(phba,
  2022. pbuffer, len, i);
  2023. else
  2024. len = lpfc_idiag_drbacc_read_reg(phba,
  2025. pbuffer, len, drb_reg_id);
  2026. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2027. }
  2028. /**
  2029. * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
  2030. * @file: The file pointer to read from.
  2031. * @buf: The buffer to copy the user data from.
  2032. * @nbytes: The number of bytes to get.
  2033. * @ppos: The position in the file to start reading from.
  2034. *
  2035. * This routine get the debugfs idiag command struct from user space and then
  2036. * perform the syntax check for port doorbell register read (dump) or write
  2037. * (set) command accordingly. In the case of port queue read command, it sets
  2038. * up the command in the idiag command struct for the following debugfs read
  2039. * operation. In the case of port doorbell register write operation, it
  2040. * executes the write operation into the port doorbell register accordingly.
  2041. *
  2042. * It returns the @nbytges passing in from debugfs user space when successful.
  2043. * In case of error conditions, it returns proper error code back to the user
  2044. * space.
  2045. **/
  2046. static ssize_t
  2047. lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
  2048. size_t nbytes, loff_t *ppos)
  2049. {
  2050. struct lpfc_debug *debug = file->private_data;
  2051. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2052. uint32_t drb_reg_id, value, reg_val;
  2053. void __iomem *drb_reg;
  2054. int rc;
  2055. /* This is a user write operation */
  2056. debug->op = LPFC_IDIAG_OP_WR;
  2057. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2058. if (rc < 0)
  2059. return rc;
  2060. /* Sanity check on command line arguments */
  2061. drb_reg_id = idiag.cmd.data[0];
  2062. value = idiag.cmd.data[1];
  2063. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2064. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2065. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2066. if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
  2067. goto error_out;
  2068. if (drb_reg_id > LPFC_DRB_MAX)
  2069. goto error_out;
  2070. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
  2071. if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
  2072. goto error_out;
  2073. if ((drb_reg_id > LPFC_DRB_MAX) &&
  2074. (drb_reg_id != LPFC_DRB_ACC_ALL))
  2075. goto error_out;
  2076. } else
  2077. goto error_out;
  2078. /* Perform the write access operation */
  2079. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2080. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2081. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2082. switch (drb_reg_id) {
  2083. case LPFC_DRB_EQCQ:
  2084. drb_reg = phba->sli4_hba.EQCQDBregaddr;
  2085. break;
  2086. case LPFC_DRB_MQ:
  2087. drb_reg = phba->sli4_hba.MQDBregaddr;
  2088. break;
  2089. case LPFC_DRB_WQ:
  2090. drb_reg = phba->sli4_hba.WQDBregaddr;
  2091. break;
  2092. case LPFC_DRB_RQ:
  2093. drb_reg = phba->sli4_hba.RQDBregaddr;
  2094. break;
  2095. default:
  2096. goto error_out;
  2097. }
  2098. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
  2099. reg_val = value;
  2100. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
  2101. reg_val = readl(drb_reg);
  2102. reg_val |= value;
  2103. }
  2104. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2105. reg_val = readl(drb_reg);
  2106. reg_val &= ~value;
  2107. }
  2108. writel(reg_val, drb_reg);
  2109. readl(drb_reg); /* flush */
  2110. }
  2111. return nbytes;
  2112. error_out:
  2113. /* Clean out command structure on command error out */
  2114. memset(&idiag, 0, sizeof(idiag));
  2115. return -EINVAL;
  2116. }
  2117. #undef lpfc_debugfs_op_disc_trc
  2118. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  2119. .owner = THIS_MODULE,
  2120. .open = lpfc_debugfs_disc_trc_open,
  2121. .llseek = lpfc_debugfs_lseek,
  2122. .read = lpfc_debugfs_read,
  2123. .release = lpfc_debugfs_release,
  2124. };
  2125. #undef lpfc_debugfs_op_nodelist
  2126. static const struct file_operations lpfc_debugfs_op_nodelist = {
  2127. .owner = THIS_MODULE,
  2128. .open = lpfc_debugfs_nodelist_open,
  2129. .llseek = lpfc_debugfs_lseek,
  2130. .read = lpfc_debugfs_read,
  2131. .release = lpfc_debugfs_release,
  2132. };
  2133. #undef lpfc_debugfs_op_hbqinfo
  2134. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  2135. .owner = THIS_MODULE,
  2136. .open = lpfc_debugfs_hbqinfo_open,
  2137. .llseek = lpfc_debugfs_lseek,
  2138. .read = lpfc_debugfs_read,
  2139. .release = lpfc_debugfs_release,
  2140. };
  2141. #undef lpfc_debugfs_op_dumpHBASlim
  2142. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  2143. .owner = THIS_MODULE,
  2144. .open = lpfc_debugfs_dumpHBASlim_open,
  2145. .llseek = lpfc_debugfs_lseek,
  2146. .read = lpfc_debugfs_read,
  2147. .release = lpfc_debugfs_release,
  2148. };
  2149. #undef lpfc_debugfs_op_dumpHostSlim
  2150. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  2151. .owner = THIS_MODULE,
  2152. .open = lpfc_debugfs_dumpHostSlim_open,
  2153. .llseek = lpfc_debugfs_lseek,
  2154. .read = lpfc_debugfs_read,
  2155. .release = lpfc_debugfs_release,
  2156. };
  2157. #undef lpfc_debugfs_op_dumpData
  2158. static const struct file_operations lpfc_debugfs_op_dumpData = {
  2159. .owner = THIS_MODULE,
  2160. .open = lpfc_debugfs_dumpData_open,
  2161. .llseek = lpfc_debugfs_lseek,
  2162. .read = lpfc_debugfs_read,
  2163. .write = lpfc_debugfs_dumpDataDif_write,
  2164. .release = lpfc_debugfs_dumpDataDif_release,
  2165. };
  2166. #undef lpfc_debugfs_op_dumpDif
  2167. static const struct file_operations lpfc_debugfs_op_dumpDif = {
  2168. .owner = THIS_MODULE,
  2169. .open = lpfc_debugfs_dumpDif_open,
  2170. .llseek = lpfc_debugfs_lseek,
  2171. .read = lpfc_debugfs_read,
  2172. .write = lpfc_debugfs_dumpDataDif_write,
  2173. .release = lpfc_debugfs_dumpDataDif_release,
  2174. };
  2175. #undef lpfc_debugfs_op_slow_ring_trc
  2176. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  2177. .owner = THIS_MODULE,
  2178. .open = lpfc_debugfs_slow_ring_trc_open,
  2179. .llseek = lpfc_debugfs_lseek,
  2180. .read = lpfc_debugfs_read,
  2181. .release = lpfc_debugfs_release,
  2182. };
  2183. static struct dentry *lpfc_debugfs_root = NULL;
  2184. static atomic_t lpfc_debugfs_hba_count;
  2185. /*
  2186. * File operations for the iDiag debugfs
  2187. */
  2188. #undef lpfc_idiag_op_pciCfg
  2189. static const struct file_operations lpfc_idiag_op_pciCfg = {
  2190. .owner = THIS_MODULE,
  2191. .open = lpfc_idiag_open,
  2192. .llseek = lpfc_debugfs_lseek,
  2193. .read = lpfc_idiag_pcicfg_read,
  2194. .write = lpfc_idiag_pcicfg_write,
  2195. .release = lpfc_idiag_cmd_release,
  2196. };
  2197. #undef lpfc_idiag_op_queInfo
  2198. static const struct file_operations lpfc_idiag_op_queInfo = {
  2199. .owner = THIS_MODULE,
  2200. .open = lpfc_idiag_open,
  2201. .read = lpfc_idiag_queinfo_read,
  2202. .release = lpfc_idiag_release,
  2203. };
  2204. #undef lpfc_idiag_op_queacc
  2205. static const struct file_operations lpfc_idiag_op_queAcc = {
  2206. .owner = THIS_MODULE,
  2207. .open = lpfc_idiag_open,
  2208. .llseek = lpfc_debugfs_lseek,
  2209. .read = lpfc_idiag_queacc_read,
  2210. .write = lpfc_idiag_queacc_write,
  2211. .release = lpfc_idiag_cmd_release,
  2212. };
  2213. #undef lpfc_idiag_op_drbacc
  2214. static const struct file_operations lpfc_idiag_op_drbAcc = {
  2215. .owner = THIS_MODULE,
  2216. .open = lpfc_idiag_open,
  2217. .llseek = lpfc_debugfs_lseek,
  2218. .read = lpfc_idiag_drbacc_read,
  2219. .write = lpfc_idiag_drbacc_write,
  2220. .release = lpfc_idiag_cmd_release,
  2221. };
  2222. #endif
  2223. /**
  2224. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  2225. * @vport: The vport pointer to initialize.
  2226. *
  2227. * Description:
  2228. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  2229. * If not already created, this routine will create the lpfc directory, and
  2230. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  2231. * also create each file used to access lpfc specific debugfs information.
  2232. **/
  2233. inline void
  2234. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  2235. {
  2236. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2237. struct lpfc_hba *phba = vport->phba;
  2238. char name[64];
  2239. uint32_t num, i;
  2240. if (!lpfc_debugfs_enable)
  2241. return;
  2242. /* Setup lpfc root directory */
  2243. if (!lpfc_debugfs_root) {
  2244. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  2245. atomic_set(&lpfc_debugfs_hba_count, 0);
  2246. if (!lpfc_debugfs_root) {
  2247. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2248. "0408 Cannot create debugfs root\n");
  2249. goto debug_failed;
  2250. }
  2251. }
  2252. if (!lpfc_debugfs_start_time)
  2253. lpfc_debugfs_start_time = jiffies;
  2254. /* Setup funcX directory for specific HBA PCI function */
  2255. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  2256. if (!phba->hba_debugfs_root) {
  2257. phba->hba_debugfs_root =
  2258. debugfs_create_dir(name, lpfc_debugfs_root);
  2259. if (!phba->hba_debugfs_root) {
  2260. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2261. "0412 Cannot create debugfs hba\n");
  2262. goto debug_failed;
  2263. }
  2264. atomic_inc(&lpfc_debugfs_hba_count);
  2265. atomic_set(&phba->debugfs_vport_count, 0);
  2266. /* Setup hbqinfo */
  2267. snprintf(name, sizeof(name), "hbqinfo");
  2268. phba->debug_hbqinfo =
  2269. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2270. phba->hba_debugfs_root,
  2271. phba, &lpfc_debugfs_op_hbqinfo);
  2272. if (!phba->debug_hbqinfo) {
  2273. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2274. "0411 Cannot create debugfs hbqinfo\n");
  2275. goto debug_failed;
  2276. }
  2277. /* Setup dumpHBASlim */
  2278. if (phba->sli_rev < LPFC_SLI_REV4) {
  2279. snprintf(name, sizeof(name), "dumpHBASlim");
  2280. phba->debug_dumpHBASlim =
  2281. debugfs_create_file(name,
  2282. S_IFREG|S_IRUGO|S_IWUSR,
  2283. phba->hba_debugfs_root,
  2284. phba, &lpfc_debugfs_op_dumpHBASlim);
  2285. if (!phba->debug_dumpHBASlim) {
  2286. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2287. "0413 Cannot create debugfs "
  2288. "dumpHBASlim\n");
  2289. goto debug_failed;
  2290. }
  2291. } else
  2292. phba->debug_dumpHBASlim = NULL;
  2293. /* Setup dumpHostSlim */
  2294. if (phba->sli_rev < LPFC_SLI_REV4) {
  2295. snprintf(name, sizeof(name), "dumpHostSlim");
  2296. phba->debug_dumpHostSlim =
  2297. debugfs_create_file(name,
  2298. S_IFREG|S_IRUGO|S_IWUSR,
  2299. phba->hba_debugfs_root,
  2300. phba, &lpfc_debugfs_op_dumpHostSlim);
  2301. if (!phba->debug_dumpHostSlim) {
  2302. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2303. "0414 Cannot create debugfs "
  2304. "dumpHostSlim\n");
  2305. goto debug_failed;
  2306. }
  2307. } else
  2308. phba->debug_dumpHBASlim = NULL;
  2309. /* Setup dumpData */
  2310. snprintf(name, sizeof(name), "dumpData");
  2311. phba->debug_dumpData =
  2312. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2313. phba->hba_debugfs_root,
  2314. phba, &lpfc_debugfs_op_dumpData);
  2315. if (!phba->debug_dumpData) {
  2316. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2317. "0800 Cannot create debugfs dumpData\n");
  2318. goto debug_failed;
  2319. }
  2320. /* Setup dumpDif */
  2321. snprintf(name, sizeof(name), "dumpDif");
  2322. phba->debug_dumpDif =
  2323. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2324. phba->hba_debugfs_root,
  2325. phba, &lpfc_debugfs_op_dumpDif);
  2326. if (!phba->debug_dumpDif) {
  2327. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2328. "0801 Cannot create debugfs dumpDif\n");
  2329. goto debug_failed;
  2330. }
  2331. /* Setup slow ring trace */
  2332. if (lpfc_debugfs_max_slow_ring_trc) {
  2333. num = lpfc_debugfs_max_slow_ring_trc - 1;
  2334. if (num & lpfc_debugfs_max_slow_ring_trc) {
  2335. /* Change to be a power of 2 */
  2336. num = lpfc_debugfs_max_slow_ring_trc;
  2337. i = 0;
  2338. while (num > 1) {
  2339. num = num >> 1;
  2340. i++;
  2341. }
  2342. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  2343. printk(KERN_ERR
  2344. "lpfc_debugfs_max_disc_trc changed to "
  2345. "%d\n", lpfc_debugfs_max_disc_trc);
  2346. }
  2347. }
  2348. snprintf(name, sizeof(name), "slow_ring_trace");
  2349. phba->debug_slow_ring_trc =
  2350. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2351. phba->hba_debugfs_root,
  2352. phba, &lpfc_debugfs_op_slow_ring_trc);
  2353. if (!phba->debug_slow_ring_trc) {
  2354. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2355. "0415 Cannot create debugfs "
  2356. "slow_ring_trace\n");
  2357. goto debug_failed;
  2358. }
  2359. if (!phba->slow_ring_trc) {
  2360. phba->slow_ring_trc = kmalloc(
  2361. (sizeof(struct lpfc_debugfs_trc) *
  2362. lpfc_debugfs_max_slow_ring_trc),
  2363. GFP_KERNEL);
  2364. if (!phba->slow_ring_trc) {
  2365. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2366. "0416 Cannot create debugfs "
  2367. "slow_ring buffer\n");
  2368. goto debug_failed;
  2369. }
  2370. atomic_set(&phba->slow_ring_trc_cnt, 0);
  2371. memset(phba->slow_ring_trc, 0,
  2372. (sizeof(struct lpfc_debugfs_trc) *
  2373. lpfc_debugfs_max_slow_ring_trc));
  2374. }
  2375. }
  2376. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  2377. if (!vport->vport_debugfs_root) {
  2378. vport->vport_debugfs_root =
  2379. debugfs_create_dir(name, phba->hba_debugfs_root);
  2380. if (!vport->vport_debugfs_root) {
  2381. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2382. "0417 Can't create debugfs\n");
  2383. goto debug_failed;
  2384. }
  2385. atomic_inc(&phba->debugfs_vport_count);
  2386. }
  2387. if (lpfc_debugfs_max_disc_trc) {
  2388. num = lpfc_debugfs_max_disc_trc - 1;
  2389. if (num & lpfc_debugfs_max_disc_trc) {
  2390. /* Change to be a power of 2 */
  2391. num = lpfc_debugfs_max_disc_trc;
  2392. i = 0;
  2393. while (num > 1) {
  2394. num = num >> 1;
  2395. i++;
  2396. }
  2397. lpfc_debugfs_max_disc_trc = (1 << i);
  2398. printk(KERN_ERR
  2399. "lpfc_debugfs_max_disc_trc changed to %d\n",
  2400. lpfc_debugfs_max_disc_trc);
  2401. }
  2402. }
  2403. vport->disc_trc = kzalloc(
  2404. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  2405. GFP_KERNEL);
  2406. if (!vport->disc_trc) {
  2407. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2408. "0418 Cannot create debugfs disc trace "
  2409. "buffer\n");
  2410. goto debug_failed;
  2411. }
  2412. atomic_set(&vport->disc_trc_cnt, 0);
  2413. snprintf(name, sizeof(name), "discovery_trace");
  2414. vport->debug_disc_trc =
  2415. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2416. vport->vport_debugfs_root,
  2417. vport, &lpfc_debugfs_op_disc_trc);
  2418. if (!vport->debug_disc_trc) {
  2419. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2420. "0419 Cannot create debugfs "
  2421. "discovery_trace\n");
  2422. goto debug_failed;
  2423. }
  2424. snprintf(name, sizeof(name), "nodelist");
  2425. vport->debug_nodelist =
  2426. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2427. vport->vport_debugfs_root,
  2428. vport, &lpfc_debugfs_op_nodelist);
  2429. if (!vport->debug_nodelist) {
  2430. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2431. "0409 Can't create debugfs nodelist\n");
  2432. goto debug_failed;
  2433. }
  2434. /*
  2435. * iDiag debugfs root entry points for SLI4 device only
  2436. */
  2437. if (phba->sli_rev < LPFC_SLI_REV4)
  2438. goto debug_failed;
  2439. snprintf(name, sizeof(name), "iDiag");
  2440. if (!phba->idiag_root) {
  2441. phba->idiag_root =
  2442. debugfs_create_dir(name, phba->hba_debugfs_root);
  2443. if (!phba->idiag_root) {
  2444. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2445. "2922 Can't create idiag debugfs\n");
  2446. goto debug_failed;
  2447. }
  2448. /* Initialize iDiag data structure */
  2449. memset(&idiag, 0, sizeof(idiag));
  2450. }
  2451. /* iDiag read PCI config space */
  2452. snprintf(name, sizeof(name), "pciCfg");
  2453. if (!phba->idiag_pci_cfg) {
  2454. phba->idiag_pci_cfg =
  2455. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2456. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  2457. if (!phba->idiag_pci_cfg) {
  2458. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2459. "2923 Can't create idiag debugfs\n");
  2460. goto debug_failed;
  2461. }
  2462. idiag.offset.last_rd = 0;
  2463. }
  2464. /* iDiag get PCI function queue information */
  2465. snprintf(name, sizeof(name), "queInfo");
  2466. if (!phba->idiag_que_info) {
  2467. phba->idiag_que_info =
  2468. debugfs_create_file(name, S_IFREG|S_IRUGO,
  2469. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  2470. if (!phba->idiag_que_info) {
  2471. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2472. "2924 Can't create idiag debugfs\n");
  2473. goto debug_failed;
  2474. }
  2475. }
  2476. /* iDiag access PCI function queue */
  2477. snprintf(name, sizeof(name), "queAcc");
  2478. if (!phba->idiag_que_acc) {
  2479. phba->idiag_que_acc =
  2480. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2481. phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
  2482. if (!phba->idiag_que_acc) {
  2483. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2484. "2926 Can't create idiag debugfs\n");
  2485. goto debug_failed;
  2486. }
  2487. }
  2488. /* iDiag access PCI function doorbell registers */
  2489. snprintf(name, sizeof(name), "drbAcc");
  2490. if (!phba->idiag_drb_acc) {
  2491. phba->idiag_drb_acc =
  2492. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  2493. phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
  2494. if (!phba->idiag_drb_acc) {
  2495. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2496. "2927 Can't create idiag debugfs\n");
  2497. goto debug_failed;
  2498. }
  2499. }
  2500. debug_failed:
  2501. return;
  2502. #endif
  2503. }
  2504. /**
  2505. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  2506. * @vport: The vport pointer to remove from debugfs.
  2507. *
  2508. * Description:
  2509. * When Debugfs is configured this routine removes debugfs file system elements
  2510. * that are specific to this vport. It also checks to see if there are any
  2511. * users left for the debugfs directories associated with the HBA and driver. If
  2512. * this is the last user of the HBA directory or driver directory then it will
  2513. * remove those from the debugfs infrastructure as well.
  2514. **/
  2515. inline void
  2516. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  2517. {
  2518. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  2519. struct lpfc_hba *phba = vport->phba;
  2520. if (vport->disc_trc) {
  2521. kfree(vport->disc_trc);
  2522. vport->disc_trc = NULL;
  2523. }
  2524. if (vport->debug_disc_trc) {
  2525. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  2526. vport->debug_disc_trc = NULL;
  2527. }
  2528. if (vport->debug_nodelist) {
  2529. debugfs_remove(vport->debug_nodelist); /* nodelist */
  2530. vport->debug_nodelist = NULL;
  2531. }
  2532. if (vport->vport_debugfs_root) {
  2533. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  2534. vport->vport_debugfs_root = NULL;
  2535. atomic_dec(&phba->debugfs_vport_count);
  2536. }
  2537. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  2538. if (phba->debug_hbqinfo) {
  2539. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  2540. phba->debug_hbqinfo = NULL;
  2541. }
  2542. if (phba->debug_dumpHBASlim) {
  2543. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  2544. phba->debug_dumpHBASlim = NULL;
  2545. }
  2546. if (phba->debug_dumpHostSlim) {
  2547. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  2548. phba->debug_dumpHostSlim = NULL;
  2549. }
  2550. if (phba->debug_dumpData) {
  2551. debugfs_remove(phba->debug_dumpData); /* dumpData */
  2552. phba->debug_dumpData = NULL;
  2553. }
  2554. if (phba->debug_dumpDif) {
  2555. debugfs_remove(phba->debug_dumpDif); /* dumpDif */
  2556. phba->debug_dumpDif = NULL;
  2557. }
  2558. if (phba->slow_ring_trc) {
  2559. kfree(phba->slow_ring_trc);
  2560. phba->slow_ring_trc = NULL;
  2561. }
  2562. if (phba->debug_slow_ring_trc) {
  2563. /* slow_ring_trace */
  2564. debugfs_remove(phba->debug_slow_ring_trc);
  2565. phba->debug_slow_ring_trc = NULL;
  2566. }
  2567. /*
  2568. * iDiag release
  2569. */
  2570. if (phba->sli_rev == LPFC_SLI_REV4) {
  2571. if (phba->idiag_drb_acc) {
  2572. /* iDiag drbAcc */
  2573. debugfs_remove(phba->idiag_drb_acc);
  2574. phba->idiag_drb_acc = NULL;
  2575. }
  2576. if (phba->idiag_que_acc) {
  2577. /* iDiag queAcc */
  2578. debugfs_remove(phba->idiag_que_acc);
  2579. phba->idiag_que_acc = NULL;
  2580. }
  2581. if (phba->idiag_que_info) {
  2582. /* iDiag queInfo */
  2583. debugfs_remove(phba->idiag_que_info);
  2584. phba->idiag_que_info = NULL;
  2585. }
  2586. if (phba->idiag_pci_cfg) {
  2587. /* iDiag pciCfg */
  2588. debugfs_remove(phba->idiag_pci_cfg);
  2589. phba->idiag_pci_cfg = NULL;
  2590. }
  2591. /* Finally remove the iDiag debugfs root */
  2592. if (phba->idiag_root) {
  2593. /* iDiag root */
  2594. debugfs_remove(phba->idiag_root);
  2595. phba->idiag_root = NULL;
  2596. }
  2597. }
  2598. if (phba->hba_debugfs_root) {
  2599. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  2600. phba->hba_debugfs_root = NULL;
  2601. atomic_dec(&lpfc_debugfs_hba_count);
  2602. }
  2603. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  2604. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  2605. lpfc_debugfs_root = NULL;
  2606. }
  2607. }
  2608. #endif
  2609. return;
  2610. }