lpfc_debugfs.c 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351
  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. #include "lpfc_bsg.h"
  49. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  50. /*
  51. * debugfs interface
  52. *
  53. * To access this interface the user should:
  54. * # mount -t debugfs none /sys/kernel/debug
  55. *
  56. * The lpfc debugfs directory hierarchy is:
  57. * /sys/kernel/debug/lpfc/fnX/vportY
  58. * where X is the lpfc hba function unique_id
  59. * where Y is the vport VPI on that hba
  60. *
  61. * Debugging services available per vport:
  62. * discovery_trace
  63. * This is an ACSII readable file that contains a trace of the last
  64. * lpfc_debugfs_max_disc_trc events that happened on a specific vport.
  65. * See lpfc_debugfs.h for different categories of discovery events.
  66. * To enable the discovery trace, the following module parameters must be set:
  67. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  68. * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for
  69. * EACH vport. X MUST also be a power of 2.
  70. * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in
  71. * lpfc_debugfs.h .
  72. *
  73. * slow_ring_trace
  74. * This is an ACSII readable file that contains a trace of the last
  75. * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA.
  76. * To enable the slow ring trace, the following module parameters must be set:
  77. * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support
  78. * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for
  79. * the HBA. X MUST also be a power of 2.
  80. */
  81. static int lpfc_debugfs_enable = 1;
  82. module_param(lpfc_debugfs_enable, int, S_IRUGO);
  83. MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services");
  84. /* This MUST be a power of 2 */
  85. static int lpfc_debugfs_max_disc_trc;
  86. module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO);
  87. MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc,
  88. "Set debugfs discovery trace depth");
  89. /* This MUST be a power of 2 */
  90. static int lpfc_debugfs_max_slow_ring_trc;
  91. module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO);
  92. MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc,
  93. "Set debugfs slow ring trace depth");
  94. static int lpfc_debugfs_mask_disc_trc;
  95. module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO);
  96. MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
  97. "Set debugfs discovery trace mask");
  98. #include <linux/debugfs.h>
  99. static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
  100. static unsigned long lpfc_debugfs_start_time = 0L;
  101. /* iDiag */
  102. static struct lpfc_idiag idiag;
  103. /**
  104. * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer
  105. * @vport: The vport to gather the log info from.
  106. * @buf: The buffer to dump log into.
  107. * @size: The maximum amount of data to process.
  108. *
  109. * Description:
  110. * This routine gathers the lpfc discovery debugfs data from the @vport and
  111. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  112. * in the log and process the log until the end of the buffer. Then it will
  113. * gather from the beginning of the log and process until the current entry.
  114. *
  115. * Notes:
  116. * Discovery logging will be disabled while while this routine dumps the log.
  117. *
  118. * Return Value:
  119. * This routine returns the amount of bytes that were dumped into @buf and will
  120. * not exceed @size.
  121. **/
  122. static int
  123. lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
  124. {
  125. int i, index, len, enable;
  126. uint32_t ms;
  127. struct lpfc_debugfs_trc *dtp;
  128. char *buffer;
  129. buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
  130. if (!buffer)
  131. return 0;
  132. enable = lpfc_debugfs_enable;
  133. lpfc_debugfs_enable = 0;
  134. len = 0;
  135. index = (atomic_read(&vport->disc_trc_cnt) + 1) &
  136. (lpfc_debugfs_max_disc_trc - 1);
  137. for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
  138. dtp = vport->disc_trc + i;
  139. if (!dtp->fmt)
  140. continue;
  141. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  142. snprintf(buffer,
  143. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  144. dtp->seq_cnt, ms, dtp->fmt);
  145. len += snprintf(buf+len, size-len, buffer,
  146. dtp->data1, dtp->data2, dtp->data3);
  147. }
  148. for (i = 0; i < index; i++) {
  149. dtp = vport->disc_trc + i;
  150. if (!dtp->fmt)
  151. continue;
  152. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  153. snprintf(buffer,
  154. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  155. dtp->seq_cnt, ms, dtp->fmt);
  156. len += snprintf(buf+len, size-len, buffer,
  157. dtp->data1, dtp->data2, dtp->data3);
  158. }
  159. lpfc_debugfs_enable = enable;
  160. kfree(buffer);
  161. return len;
  162. }
  163. /**
  164. * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer
  165. * @phba: The HBA to gather the log info from.
  166. * @buf: The buffer to dump log into.
  167. * @size: The maximum amount of data to process.
  168. *
  169. * Description:
  170. * This routine gathers the lpfc slow ring debugfs data from the @phba and
  171. * dumps it to @buf up to @size number of bytes. It will start at the next entry
  172. * in the log and process the log until the end of the buffer. Then it will
  173. * gather from the beginning of the log and process until the current entry.
  174. *
  175. * Notes:
  176. * Slow ring logging will be disabled while while this routine dumps the log.
  177. *
  178. * Return Value:
  179. * This routine returns the amount of bytes that were dumped into @buf and will
  180. * not exceed @size.
  181. **/
  182. static int
  183. lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
  184. {
  185. int i, index, len, enable;
  186. uint32_t ms;
  187. struct lpfc_debugfs_trc *dtp;
  188. char *buffer;
  189. buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL);
  190. if (!buffer)
  191. return 0;
  192. enable = lpfc_debugfs_enable;
  193. lpfc_debugfs_enable = 0;
  194. len = 0;
  195. index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
  196. (lpfc_debugfs_max_slow_ring_trc - 1);
  197. for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
  198. dtp = phba->slow_ring_trc + i;
  199. if (!dtp->fmt)
  200. continue;
  201. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  202. snprintf(buffer,
  203. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  204. dtp->seq_cnt, ms, dtp->fmt);
  205. len += snprintf(buf+len, size-len, buffer,
  206. dtp->data1, dtp->data2, dtp->data3);
  207. }
  208. for (i = 0; i < index; i++) {
  209. dtp = phba->slow_ring_trc + i;
  210. if (!dtp->fmt)
  211. continue;
  212. ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time);
  213. snprintf(buffer,
  214. LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n",
  215. dtp->seq_cnt, ms, dtp->fmt);
  216. len += snprintf(buf+len, size-len, buffer,
  217. dtp->data1, dtp->data2, dtp->data3);
  218. }
  219. lpfc_debugfs_enable = enable;
  220. kfree(buffer);
  221. return len;
  222. }
  223. static int lpfc_debugfs_last_hbq = -1;
  224. /**
  225. * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer
  226. * @phba: The HBA to gather host buffer info from.
  227. * @buf: The buffer to dump log into.
  228. * @size: The maximum amount of data to process.
  229. *
  230. * Description:
  231. * This routine dumps the host buffer queue info from the @phba to @buf up to
  232. * @size number of bytes. A header that describes the current hbq state will be
  233. * dumped to @buf first and then info on each hbq entry will be dumped to @buf
  234. * until @size bytes have been dumped or all the hbq info has been dumped.
  235. *
  236. * Notes:
  237. * This routine will rotate through each configured HBQ each time called.
  238. *
  239. * Return Value:
  240. * This routine returns the amount of bytes that were dumped into @buf and will
  241. * not exceed @size.
  242. **/
  243. static int
  244. lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size)
  245. {
  246. int len = 0;
  247. int cnt, i, j, found, posted, low;
  248. uint32_t phys, raw_index, getidx;
  249. struct lpfc_hbq_init *hip;
  250. struct hbq_s *hbqs;
  251. struct lpfc_hbq_entry *hbqe;
  252. struct lpfc_dmabuf *d_buf;
  253. struct hbq_dmabuf *hbq_buf;
  254. if (phba->sli_rev != 3)
  255. return 0;
  256. cnt = LPFC_HBQINFO_SIZE;
  257. spin_lock_irq(&phba->hbalock);
  258. /* toggle between multiple hbqs, if any */
  259. i = lpfc_sli_hbq_count();
  260. if (i > 1) {
  261. lpfc_debugfs_last_hbq++;
  262. if (lpfc_debugfs_last_hbq >= i)
  263. lpfc_debugfs_last_hbq = 0;
  264. }
  265. else
  266. lpfc_debugfs_last_hbq = 0;
  267. i = lpfc_debugfs_last_hbq;
  268. len += snprintf(buf+len, size-len, "HBQ %d Info\n", i);
  269. hbqs = &phba->hbqs[i];
  270. posted = 0;
  271. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list)
  272. posted++;
  273. hip = lpfc_hbq_defs[i];
  274. len += snprintf(buf+len, size-len,
  275. "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n",
  276. hip->hbq_index, hip->profile, hip->rn,
  277. hip->buffer_count, hip->init_count, hip->add_count, posted);
  278. raw_index = phba->hbq_get[i];
  279. getidx = le32_to_cpu(raw_index);
  280. len += snprintf(buf+len, size-len,
  281. "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n",
  282. hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx,
  283. hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx);
  284. hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt;
  285. for (j=0; j<hbqs->entry_count; j++) {
  286. len += snprintf(buf+len, size-len,
  287. "%03d: %08x %04x %05x ", j,
  288. le32_to_cpu(hbqe->bde.addrLow),
  289. le32_to_cpu(hbqe->bde.tus.w),
  290. le32_to_cpu(hbqe->buffer_tag));
  291. i = 0;
  292. found = 0;
  293. /* First calculate if slot has an associated posted buffer */
  294. low = hbqs->hbqPutIdx - posted;
  295. if (low >= 0) {
  296. if ((j >= hbqs->hbqPutIdx) || (j < low)) {
  297. len += snprintf(buf+len, size-len, "Unused\n");
  298. goto skipit;
  299. }
  300. }
  301. else {
  302. if ((j >= hbqs->hbqPutIdx) &&
  303. (j < (hbqs->entry_count+low))) {
  304. len += snprintf(buf+len, size-len, "Unused\n");
  305. goto skipit;
  306. }
  307. }
  308. /* Get the Buffer info for the posted buffer */
  309. list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) {
  310. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  311. phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff);
  312. if (phys == le32_to_cpu(hbqe->bde.addrLow)) {
  313. len += snprintf(buf+len, size-len,
  314. "Buf%d: %p %06x\n", i,
  315. hbq_buf->dbuf.virt, hbq_buf->tag);
  316. found = 1;
  317. break;
  318. }
  319. i++;
  320. }
  321. if (!found) {
  322. len += snprintf(buf+len, size-len, "No DMAinfo?\n");
  323. }
  324. skipit:
  325. hbqe++;
  326. if (len > LPFC_HBQINFO_SIZE - 54)
  327. break;
  328. }
  329. spin_unlock_irq(&phba->hbalock);
  330. return len;
  331. }
  332. static int lpfc_debugfs_last_hba_slim_off;
  333. /**
  334. * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer
  335. * @phba: The HBA to gather SLIM info from.
  336. * @buf: The buffer to dump log into.
  337. * @size: The maximum amount of data to process.
  338. *
  339. * Description:
  340. * This routine dumps the current contents of HBA SLIM for the HBA associated
  341. * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data.
  342. *
  343. * Notes:
  344. * This routine will only dump up to 1024 bytes of data each time called and
  345. * should be called multiple times to dump the entire HBA SLIM.
  346. *
  347. * Return Value:
  348. * This routine returns the amount of bytes that were dumped into @buf and will
  349. * not exceed @size.
  350. **/
  351. static int
  352. lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
  353. {
  354. int len = 0;
  355. int i, off;
  356. uint32_t *ptr;
  357. char *buffer;
  358. buffer = kmalloc(1024, GFP_KERNEL);
  359. if (!buffer)
  360. return 0;
  361. off = 0;
  362. spin_lock_irq(&phba->hbalock);
  363. len += snprintf(buf+len, size-len, "HBA SLIM\n");
  364. lpfc_memcpy_from_slim(buffer,
  365. phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024);
  366. ptr = (uint32_t *)&buffer[0];
  367. off = lpfc_debugfs_last_hba_slim_off;
  368. /* Set it up for the next time */
  369. lpfc_debugfs_last_hba_slim_off += 1024;
  370. if (lpfc_debugfs_last_hba_slim_off >= 4096)
  371. lpfc_debugfs_last_hba_slim_off = 0;
  372. i = 1024;
  373. while (i > 0) {
  374. len += snprintf(buf+len, size-len,
  375. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  376. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  377. *(ptr+5), *(ptr+6), *(ptr+7));
  378. ptr += 8;
  379. i -= (8 * sizeof(uint32_t));
  380. off += (8 * sizeof(uint32_t));
  381. }
  382. spin_unlock_irq(&phba->hbalock);
  383. kfree(buffer);
  384. return len;
  385. }
  386. /**
  387. * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer
  388. * @phba: The HBA to gather Host SLIM info from.
  389. * @buf: The buffer to dump log into.
  390. * @size: The maximum amount of data to process.
  391. *
  392. * Description:
  393. * This routine dumps the current contents of host SLIM for the host associated
  394. * with @phba to @buf up to @size bytes of data. The dump will contain the
  395. * Mailbox, PCB, Rings, and Registers that are located in host memory.
  396. *
  397. * Return Value:
  398. * This routine returns the amount of bytes that were dumped into @buf and will
  399. * not exceed @size.
  400. **/
  401. static int
  402. lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size)
  403. {
  404. int len = 0;
  405. int i, off;
  406. uint32_t word0, word1, word2, word3;
  407. uint32_t *ptr;
  408. struct lpfc_pgp *pgpp;
  409. struct lpfc_sli *psli = &phba->sli;
  410. struct lpfc_sli_ring *pring;
  411. off = 0;
  412. spin_lock_irq(&phba->hbalock);
  413. len += snprintf(buf+len, size-len, "SLIM Mailbox\n");
  414. ptr = (uint32_t *)phba->slim2p.virt;
  415. i = sizeof(MAILBOX_t);
  416. while (i > 0) {
  417. len += snprintf(buf+len, size-len,
  418. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  419. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  420. *(ptr+5), *(ptr+6), *(ptr+7));
  421. ptr += 8;
  422. i -= (8 * sizeof(uint32_t));
  423. off += (8 * sizeof(uint32_t));
  424. }
  425. len += snprintf(buf+len, size-len, "SLIM PCB\n");
  426. ptr = (uint32_t *)phba->pcb;
  427. i = sizeof(PCB_t);
  428. while (i > 0) {
  429. len += snprintf(buf+len, size-len,
  430. "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
  431. off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4),
  432. *(ptr+5), *(ptr+6), *(ptr+7));
  433. ptr += 8;
  434. i -= (8 * sizeof(uint32_t));
  435. off += (8 * sizeof(uint32_t));
  436. }
  437. for (i = 0; i < 4; i++) {
  438. pgpp = &phba->port_gp[i];
  439. pring = &psli->ring[i];
  440. len += snprintf(buf+len, size-len,
  441. "Ring %d: CMD GetInx:%d (Max:%d Next:%d "
  442. "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n",
  443. i, pgpp->cmdGetInx, pring->numCiocb,
  444. pring->next_cmdidx, pring->local_getidx,
  445. pring->flag, pgpp->rspPutInx, pring->numRiocb);
  446. }
  447. if (phba->sli_rev <= LPFC_SLI_REV3) {
  448. word0 = readl(phba->HAregaddr);
  449. word1 = readl(phba->CAregaddr);
  450. word2 = readl(phba->HSregaddr);
  451. word3 = readl(phba->HCregaddr);
  452. len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x "
  453. "HC:%08x\n", word0, word1, word2, word3);
  454. }
  455. spin_unlock_irq(&phba->hbalock);
  456. return len;
  457. }
  458. /**
  459. * lpfc_debugfs_nodelist_data - Dump target node list to a buffer
  460. * @vport: The vport to gather target node info from.
  461. * @buf: The buffer to dump log into.
  462. * @size: The maximum amount of data to process.
  463. *
  464. * Description:
  465. * This routine dumps the current target node list associated with @vport to
  466. * @buf up to @size bytes of data. Each node entry in the dump will contain a
  467. * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields.
  468. *
  469. * Return Value:
  470. * This routine returns the amount of bytes that were dumped into @buf and will
  471. * not exceed @size.
  472. **/
  473. static int
  474. lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size)
  475. {
  476. int len = 0;
  477. int cnt;
  478. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  479. struct lpfc_nodelist *ndlp;
  480. unsigned char *statep, *name;
  481. cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE);
  482. spin_lock_irq(shost->host_lock);
  483. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  484. if (!cnt) {
  485. len += snprintf(buf+len, size-len,
  486. "Missing Nodelist Entries\n");
  487. break;
  488. }
  489. cnt--;
  490. switch (ndlp->nlp_state) {
  491. case NLP_STE_UNUSED_NODE:
  492. statep = "UNUSED";
  493. break;
  494. case NLP_STE_PLOGI_ISSUE:
  495. statep = "PLOGI ";
  496. break;
  497. case NLP_STE_ADISC_ISSUE:
  498. statep = "ADISC ";
  499. break;
  500. case NLP_STE_REG_LOGIN_ISSUE:
  501. statep = "REGLOG";
  502. break;
  503. case NLP_STE_PRLI_ISSUE:
  504. statep = "PRLI ";
  505. break;
  506. case NLP_STE_UNMAPPED_NODE:
  507. statep = "UNMAP ";
  508. break;
  509. case NLP_STE_MAPPED_NODE:
  510. statep = "MAPPED";
  511. break;
  512. case NLP_STE_NPR_NODE:
  513. statep = "NPR ";
  514. break;
  515. default:
  516. statep = "UNKNOWN";
  517. }
  518. len += snprintf(buf+len, size-len, "%s DID:x%06x ",
  519. statep, ndlp->nlp_DID);
  520. name = (unsigned char *)&ndlp->nlp_portname;
  521. len += snprintf(buf+len, size-len,
  522. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  523. *name, *(name+1), *(name+2), *(name+3),
  524. *(name+4), *(name+5), *(name+6), *(name+7));
  525. name = (unsigned char *)&ndlp->nlp_nodename;
  526. len += snprintf(buf+len, size-len,
  527. "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
  528. *name, *(name+1), *(name+2), *(name+3),
  529. *(name+4), *(name+5), *(name+6), *(name+7));
  530. len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ",
  531. ndlp->nlp_rpi, ndlp->nlp_flag);
  532. if (!ndlp->nlp_type)
  533. len += snprintf(buf+len, size-len, "UNKNOWN_TYPE ");
  534. if (ndlp->nlp_type & NLP_FC_NODE)
  535. len += snprintf(buf+len, size-len, "FC_NODE ");
  536. if (ndlp->nlp_type & NLP_FABRIC)
  537. len += snprintf(buf+len, size-len, "FABRIC ");
  538. if (ndlp->nlp_type & NLP_FCP_TARGET)
  539. len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ",
  540. ndlp->nlp_sid);
  541. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  542. len += snprintf(buf+len, size-len, "FCP_INITIATOR ");
  543. len += snprintf(buf+len, size-len, "usgmap:%x ",
  544. ndlp->nlp_usg_map);
  545. len += snprintf(buf+len, size-len, "refcnt:%x",
  546. atomic_read(&ndlp->kref.refcount));
  547. len += snprintf(buf+len, size-len, "\n");
  548. }
  549. spin_unlock_irq(shost->host_lock);
  550. return len;
  551. }
  552. #endif
  553. /**
  554. * lpfc_debugfs_disc_trc - Store discovery trace log
  555. * @vport: The vport to associate this trace string with for retrieval.
  556. * @mask: Log entry classification.
  557. * @fmt: Format string to be displayed when dumping the log.
  558. * @data1: 1st data parameter to be applied to @fmt.
  559. * @data2: 2nd data parameter to be applied to @fmt.
  560. * @data3: 3rd data parameter to be applied to @fmt.
  561. *
  562. * Description:
  563. * This routine is used by the driver code to add a debugfs log entry to the
  564. * discovery trace buffer associated with @vport. Only entries with a @mask that
  565. * match the current debugfs discovery mask will be saved. Entries that do not
  566. * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like
  567. * printf when displaying the log.
  568. **/
  569. inline void
  570. lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
  571. uint32_t data1, uint32_t data2, uint32_t data3)
  572. {
  573. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  574. struct lpfc_debugfs_trc *dtp;
  575. int index;
  576. if (!(lpfc_debugfs_mask_disc_trc & mask))
  577. return;
  578. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc ||
  579. !vport || !vport->disc_trc)
  580. return;
  581. index = atomic_inc_return(&vport->disc_trc_cnt) &
  582. (lpfc_debugfs_max_disc_trc - 1);
  583. dtp = vport->disc_trc + index;
  584. dtp->fmt = fmt;
  585. dtp->data1 = data1;
  586. dtp->data2 = data2;
  587. dtp->data3 = data3;
  588. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  589. dtp->jif = jiffies;
  590. #endif
  591. return;
  592. }
  593. /**
  594. * lpfc_debugfs_slow_ring_trc - Store slow ring trace log
  595. * @phba: The phba to associate this trace string with for retrieval.
  596. * @fmt: Format string to be displayed when dumping the log.
  597. * @data1: 1st data parameter to be applied to @fmt.
  598. * @data2: 2nd data parameter to be applied to @fmt.
  599. * @data3: 3rd data parameter to be applied to @fmt.
  600. *
  601. * Description:
  602. * This routine is used by the driver code to add a debugfs log entry to the
  603. * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and
  604. * @data3 are used like printf when displaying the log.
  605. **/
  606. inline void
  607. lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
  608. uint32_t data1, uint32_t data2, uint32_t data3)
  609. {
  610. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  611. struct lpfc_debugfs_trc *dtp;
  612. int index;
  613. if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc ||
  614. !phba || !phba->slow_ring_trc)
  615. return;
  616. index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
  617. (lpfc_debugfs_max_slow_ring_trc - 1);
  618. dtp = phba->slow_ring_trc + index;
  619. dtp->fmt = fmt;
  620. dtp->data1 = data1;
  621. dtp->data2 = data2;
  622. dtp->data3 = data3;
  623. dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
  624. dtp->jif = jiffies;
  625. #endif
  626. return;
  627. }
  628. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  629. /**
  630. * lpfc_debugfs_disc_trc_open - Open the discovery trace log
  631. * @inode: The inode pointer that contains a vport pointer.
  632. * @file: The file pointer to attach the log output.
  633. *
  634. * Description:
  635. * This routine is the entry point for the debugfs open file operation. It gets
  636. * the vport from the i_private field in @inode, allocates the necessary buffer
  637. * for the log, fills the buffer from the in-memory log for this vport, and then
  638. * returns a pointer to that log in the private_data field in @file.
  639. *
  640. * Returns:
  641. * This function returns zero if successful. On error it will return an negative
  642. * error value.
  643. **/
  644. static int
  645. lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file)
  646. {
  647. struct lpfc_vport *vport = inode->i_private;
  648. struct lpfc_debug *debug;
  649. int size;
  650. int rc = -ENOMEM;
  651. if (!lpfc_debugfs_max_disc_trc) {
  652. rc = -ENOSPC;
  653. goto out;
  654. }
  655. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  656. if (!debug)
  657. goto out;
  658. /* Round to page boundary */
  659. size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  660. size = PAGE_ALIGN(size);
  661. debug->buffer = kmalloc(size, GFP_KERNEL);
  662. if (!debug->buffer) {
  663. kfree(debug);
  664. goto out;
  665. }
  666. debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size);
  667. file->private_data = debug;
  668. rc = 0;
  669. out:
  670. return rc;
  671. }
  672. /**
  673. * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log
  674. * @inode: The inode pointer that contains a vport pointer.
  675. * @file: The file pointer to attach the log output.
  676. *
  677. * Description:
  678. * This routine is the entry point for the debugfs open file operation. It gets
  679. * the vport from the i_private field in @inode, allocates the necessary buffer
  680. * for the log, fills the buffer from the in-memory log for this vport, and then
  681. * returns a pointer to that log in the private_data field in @file.
  682. *
  683. * Returns:
  684. * This function returns zero if successful. On error it will return an negative
  685. * error value.
  686. **/
  687. static int
  688. lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file)
  689. {
  690. struct lpfc_hba *phba = inode->i_private;
  691. struct lpfc_debug *debug;
  692. int size;
  693. int rc = -ENOMEM;
  694. if (!lpfc_debugfs_max_slow_ring_trc) {
  695. rc = -ENOSPC;
  696. goto out;
  697. }
  698. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  699. if (!debug)
  700. goto out;
  701. /* Round to page boundary */
  702. size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE);
  703. size = PAGE_ALIGN(size);
  704. debug->buffer = kmalloc(size, GFP_KERNEL);
  705. if (!debug->buffer) {
  706. kfree(debug);
  707. goto out;
  708. }
  709. debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size);
  710. file->private_data = debug;
  711. rc = 0;
  712. out:
  713. return rc;
  714. }
  715. /**
  716. * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer
  717. * @inode: The inode pointer that contains a vport pointer.
  718. * @file: The file pointer to attach the log output.
  719. *
  720. * Description:
  721. * This routine is the entry point for the debugfs open file operation. It gets
  722. * the vport from the i_private field in @inode, allocates the necessary buffer
  723. * for the log, fills the buffer from the in-memory log for this vport, and then
  724. * returns a pointer to that log in the private_data field in @file.
  725. *
  726. * Returns:
  727. * This function returns zero if successful. On error it will return an negative
  728. * error value.
  729. **/
  730. static int
  731. lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file)
  732. {
  733. struct lpfc_hba *phba = inode->i_private;
  734. struct lpfc_debug *debug;
  735. int rc = -ENOMEM;
  736. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  737. if (!debug)
  738. goto out;
  739. /* Round to page boundary */
  740. debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL);
  741. if (!debug->buffer) {
  742. kfree(debug);
  743. goto out;
  744. }
  745. debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer,
  746. LPFC_HBQINFO_SIZE);
  747. file->private_data = debug;
  748. rc = 0;
  749. out:
  750. return rc;
  751. }
  752. /**
  753. * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer
  754. * @inode: The inode pointer that contains a vport pointer.
  755. * @file: The file pointer to attach the log output.
  756. *
  757. * Description:
  758. * This routine is the entry point for the debugfs open file operation. It gets
  759. * the vport from the i_private field in @inode, allocates the necessary buffer
  760. * for the log, fills the buffer from the in-memory log for this vport, and then
  761. * returns a pointer to that log in the private_data field in @file.
  762. *
  763. * Returns:
  764. * This function returns zero if successful. On error it will return an negative
  765. * error value.
  766. **/
  767. static int
  768. lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file)
  769. {
  770. struct lpfc_hba *phba = inode->i_private;
  771. struct lpfc_debug *debug;
  772. int rc = -ENOMEM;
  773. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  774. if (!debug)
  775. goto out;
  776. /* Round to page boundary */
  777. debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL);
  778. if (!debug->buffer) {
  779. kfree(debug);
  780. goto out;
  781. }
  782. debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer,
  783. LPFC_DUMPHBASLIM_SIZE);
  784. file->private_data = debug;
  785. rc = 0;
  786. out:
  787. return rc;
  788. }
  789. /**
  790. * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer
  791. * @inode: The inode pointer that contains a vport pointer.
  792. * @file: The file pointer to attach the log output.
  793. *
  794. * Description:
  795. * This routine is the entry point for the debugfs open file operation. It gets
  796. * the vport from the i_private field in @inode, allocates the necessary buffer
  797. * for the log, fills the buffer from the in-memory log for this vport, and then
  798. * returns a pointer to that log in the private_data field in @file.
  799. *
  800. * Returns:
  801. * This function returns zero if successful. On error it will return an negative
  802. * error value.
  803. **/
  804. static int
  805. lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
  806. {
  807. struct lpfc_hba *phba = inode->i_private;
  808. struct lpfc_debug *debug;
  809. int rc = -ENOMEM;
  810. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  811. if (!debug)
  812. goto out;
  813. /* Round to page boundary */
  814. debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL);
  815. if (!debug->buffer) {
  816. kfree(debug);
  817. goto out;
  818. }
  819. debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer,
  820. LPFC_DUMPHOSTSLIM_SIZE);
  821. file->private_data = debug;
  822. rc = 0;
  823. out:
  824. return rc;
  825. }
  826. static int
  827. lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file)
  828. {
  829. struct lpfc_debug *debug;
  830. int rc = -ENOMEM;
  831. if (!_dump_buf_data)
  832. return -EBUSY;
  833. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  834. if (!debug)
  835. goto out;
  836. /* Round to page boundary */
  837. printk(KERN_ERR "9059 BLKGRD: %s: _dump_buf_data=0x%p\n",
  838. __func__, _dump_buf_data);
  839. debug->buffer = _dump_buf_data;
  840. if (!debug->buffer) {
  841. kfree(debug);
  842. goto out;
  843. }
  844. debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT;
  845. file->private_data = debug;
  846. rc = 0;
  847. out:
  848. return rc;
  849. }
  850. static int
  851. lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file)
  852. {
  853. struct lpfc_debug *debug;
  854. int rc = -ENOMEM;
  855. if (!_dump_buf_dif)
  856. return -EBUSY;
  857. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  858. if (!debug)
  859. goto out;
  860. /* Round to page boundary */
  861. printk(KERN_ERR "9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%s\n",
  862. __func__, _dump_buf_dif, file->f_dentry->d_name.name);
  863. debug->buffer = _dump_buf_dif;
  864. if (!debug->buffer) {
  865. kfree(debug);
  866. goto out;
  867. }
  868. debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT;
  869. file->private_data = debug;
  870. rc = 0;
  871. out:
  872. return rc;
  873. }
  874. static ssize_t
  875. lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf,
  876. size_t nbytes, loff_t *ppos)
  877. {
  878. /*
  879. * The Data/DIF buffers only save one failing IO
  880. * The write op is used as a reset mechanism after an IO has
  881. * already been saved to the next one can be saved
  882. */
  883. spin_lock(&_dump_buf_lock);
  884. memset((void *)_dump_buf_data, 0,
  885. ((1 << PAGE_SHIFT) << _dump_buf_data_order));
  886. memset((void *)_dump_buf_dif, 0,
  887. ((1 << PAGE_SHIFT) << _dump_buf_dif_order));
  888. _dump_buf_done = 0;
  889. spin_unlock(&_dump_buf_lock);
  890. return nbytes;
  891. }
  892. static int
  893. lpfc_debugfs_dif_err_open(struct inode *inode, struct file *file)
  894. {
  895. file->private_data = inode->i_private;
  896. return 0;
  897. }
  898. static ssize_t
  899. lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
  900. size_t nbytes, loff_t *ppos)
  901. {
  902. struct dentry *dent = file->f_dentry;
  903. struct lpfc_hba *phba = file->private_data;
  904. char cbuf[16];
  905. int cnt = 0;
  906. if (dent == phba->debug_writeGuard)
  907. cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wgrd_cnt);
  908. else if (dent == phba->debug_writeApp)
  909. cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wapp_cnt);
  910. else if (dent == phba->debug_writeRef)
  911. cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_wref_cnt);
  912. else if (dent == phba->debug_readApp)
  913. cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rapp_cnt);
  914. else if (dent == phba->debug_readRef)
  915. cnt = snprintf(cbuf, 16, "%u\n", phba->lpfc_injerr_rref_cnt);
  916. else if (dent == phba->debug_InjErrLBA)
  917. cnt = snprintf(cbuf, 16, "0x%lx\n",
  918. (unsigned long) phba->lpfc_injerr_lba);
  919. else
  920. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  921. "0547 Unknown debugfs error injection entry\n");
  922. return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt);
  923. }
  924. static ssize_t
  925. lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
  926. size_t nbytes, loff_t *ppos)
  927. {
  928. struct dentry *dent = file->f_dentry;
  929. struct lpfc_hba *phba = file->private_data;
  930. char dstbuf[32];
  931. unsigned long tmp;
  932. int size;
  933. memset(dstbuf, 0, 32);
  934. size = (nbytes < 32) ? nbytes : 32;
  935. if (copy_from_user(dstbuf, buf, size))
  936. return 0;
  937. if (strict_strtoul(dstbuf, 0, &tmp))
  938. return 0;
  939. if (dent == phba->debug_writeGuard)
  940. phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
  941. else if (dent == phba->debug_writeApp)
  942. phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
  943. else if (dent == phba->debug_writeRef)
  944. phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
  945. else if (dent == phba->debug_readApp)
  946. phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
  947. else if (dent == phba->debug_readRef)
  948. phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
  949. else if (dent == phba->debug_InjErrLBA)
  950. phba->lpfc_injerr_lba = (sector_t)tmp;
  951. else
  952. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  953. "0548 Unknown debugfs error injection entry\n");
  954. return nbytes;
  955. }
  956. static int
  957. lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file)
  958. {
  959. return 0;
  960. }
  961. /**
  962. * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file
  963. * @inode: The inode pointer that contains a vport pointer.
  964. * @file: The file pointer to attach the log output.
  965. *
  966. * Description:
  967. * This routine is the entry point for the debugfs open file operation. It gets
  968. * the vport from the i_private field in @inode, allocates the necessary buffer
  969. * for the log, fills the buffer from the in-memory log for this vport, and then
  970. * returns a pointer to that log in the private_data field in @file.
  971. *
  972. * Returns:
  973. * This function returns zero if successful. On error it will return an negative
  974. * error value.
  975. **/
  976. static int
  977. lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file)
  978. {
  979. struct lpfc_vport *vport = inode->i_private;
  980. struct lpfc_debug *debug;
  981. int rc = -ENOMEM;
  982. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  983. if (!debug)
  984. goto out;
  985. /* Round to page boundary */
  986. debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL);
  987. if (!debug->buffer) {
  988. kfree(debug);
  989. goto out;
  990. }
  991. debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer,
  992. LPFC_NODELIST_SIZE);
  993. file->private_data = debug;
  994. rc = 0;
  995. out:
  996. return rc;
  997. }
  998. /**
  999. * lpfc_debugfs_lseek - Seek through a debugfs file
  1000. * @file: The file pointer to seek through.
  1001. * @off: The offset to seek to or the amount to seek by.
  1002. * @whence: Indicates how to seek.
  1003. *
  1004. * Description:
  1005. * This routine is the entry point for the debugfs lseek file operation. The
  1006. * @whence parameter indicates whether @off is the offset to directly seek to,
  1007. * or if it is a value to seek forward or reverse by. This function figures out
  1008. * what the new offset of the debugfs file will be and assigns that value to the
  1009. * f_pos field of @file.
  1010. *
  1011. * Returns:
  1012. * This function returns the new offset if successful and returns a negative
  1013. * error if unable to process the seek.
  1014. **/
  1015. static loff_t
  1016. lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
  1017. {
  1018. struct lpfc_debug *debug;
  1019. loff_t pos = -1;
  1020. debug = file->private_data;
  1021. switch (whence) {
  1022. case 0:
  1023. pos = off;
  1024. break;
  1025. case 1:
  1026. pos = file->f_pos + off;
  1027. break;
  1028. case 2:
  1029. pos = debug->len - off;
  1030. }
  1031. return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
  1032. }
  1033. /**
  1034. * lpfc_debugfs_read - Read a debugfs file
  1035. * @file: The file pointer to read from.
  1036. * @buf: The buffer to copy the data to.
  1037. * @nbytes: The number of bytes to read.
  1038. * @ppos: The position in the file to start reading from.
  1039. *
  1040. * Description:
  1041. * This routine reads data from from the buffer indicated in the private_data
  1042. * field of @file. It will start reading at @ppos and copy up to @nbytes of
  1043. * data to @buf.
  1044. *
  1045. * Returns:
  1046. * This function returns the amount of data that was read (this could be less
  1047. * than @nbytes if the end of the file was reached) or a negative error value.
  1048. **/
  1049. static ssize_t
  1050. lpfc_debugfs_read(struct file *file, char __user *buf,
  1051. size_t nbytes, loff_t *ppos)
  1052. {
  1053. struct lpfc_debug *debug = file->private_data;
  1054. return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer,
  1055. debug->len);
  1056. }
  1057. /**
  1058. * lpfc_debugfs_release - Release the buffer used to store debugfs file data
  1059. * @inode: The inode pointer that contains a vport pointer. (unused)
  1060. * @file: The file pointer that contains the buffer to release.
  1061. *
  1062. * Description:
  1063. * This routine frees the buffer that was allocated when the debugfs file was
  1064. * opened.
  1065. *
  1066. * Returns:
  1067. * This function returns zero.
  1068. **/
  1069. static int
  1070. lpfc_debugfs_release(struct inode *inode, struct file *file)
  1071. {
  1072. struct lpfc_debug *debug = file->private_data;
  1073. kfree(debug->buffer);
  1074. kfree(debug);
  1075. return 0;
  1076. }
  1077. static int
  1078. lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file)
  1079. {
  1080. struct lpfc_debug *debug = file->private_data;
  1081. debug->buffer = NULL;
  1082. kfree(debug);
  1083. return 0;
  1084. }
  1085. /*
  1086. * ---------------------------------
  1087. * iDiag debugfs file access methods
  1088. * ---------------------------------
  1089. *
  1090. * All access methods are through the proper SLI4 PCI function's debugfs
  1091. * iDiag directory:
  1092. *
  1093. * /sys/kernel/debug/lpfc/fn<#>/iDiag
  1094. */
  1095. /**
  1096. * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space
  1097. * @buf: The pointer to the user space buffer.
  1098. * @nbytes: The number of bytes in the user space buffer.
  1099. * @idiag_cmd: pointer to the idiag command struct.
  1100. *
  1101. * This routine reads data from debugfs user space buffer and parses the
  1102. * buffer for getting the idiag command and arguments. The while space in
  1103. * between the set of data is used as the parsing separator.
  1104. *
  1105. * This routine returns 0 when successful, it returns proper error code
  1106. * back to the user space in error conditions.
  1107. */
  1108. static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
  1109. struct lpfc_idiag_cmd *idiag_cmd)
  1110. {
  1111. char mybuf[64];
  1112. char *pbuf, *step_str;
  1113. int i;
  1114. size_t bsize;
  1115. /* Protect copy from user */
  1116. if (!access_ok(VERIFY_READ, buf, nbytes))
  1117. return -EFAULT;
  1118. memset(mybuf, 0, sizeof(mybuf));
  1119. memset(idiag_cmd, 0, sizeof(*idiag_cmd));
  1120. bsize = min(nbytes, (sizeof(mybuf)-1));
  1121. if (copy_from_user(mybuf, buf, bsize))
  1122. return -EFAULT;
  1123. pbuf = &mybuf[0];
  1124. step_str = strsep(&pbuf, "\t ");
  1125. /* The opcode must present */
  1126. if (!step_str)
  1127. return -EINVAL;
  1128. idiag_cmd->opcode = simple_strtol(step_str, NULL, 0);
  1129. if (idiag_cmd->opcode == 0)
  1130. return -EINVAL;
  1131. for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) {
  1132. step_str = strsep(&pbuf, "\t ");
  1133. if (!step_str)
  1134. return i;
  1135. idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0);
  1136. }
  1137. return i;
  1138. }
  1139. /**
  1140. * lpfc_idiag_open - idiag open debugfs
  1141. * @inode: The inode pointer that contains a pointer to phba.
  1142. * @file: The file pointer to attach the file operation.
  1143. *
  1144. * Description:
  1145. * This routine is the entry point for the debugfs open file operation. It
  1146. * gets the reference to phba from the i_private field in @inode, it then
  1147. * allocates buffer for the file operation, performs the necessary PCI config
  1148. * space read into the allocated buffer according to the idiag user command
  1149. * setup, and then returns a pointer to buffer in the private_data field in
  1150. * @file.
  1151. *
  1152. * Returns:
  1153. * This function returns zero if successful. On error it will return an
  1154. * negative error value.
  1155. **/
  1156. static int
  1157. lpfc_idiag_open(struct inode *inode, struct file *file)
  1158. {
  1159. struct lpfc_debug *debug;
  1160. debug = kmalloc(sizeof(*debug), GFP_KERNEL);
  1161. if (!debug)
  1162. return -ENOMEM;
  1163. debug->i_private = inode->i_private;
  1164. debug->buffer = NULL;
  1165. file->private_data = debug;
  1166. return 0;
  1167. }
  1168. /**
  1169. * lpfc_idiag_release - Release idiag access file operation
  1170. * @inode: The inode pointer that contains a vport pointer. (unused)
  1171. * @file: The file pointer that contains the buffer to release.
  1172. *
  1173. * Description:
  1174. * This routine is the generic release routine for the idiag access file
  1175. * operation, it frees the buffer that was allocated when the debugfs file
  1176. * was opened.
  1177. *
  1178. * Returns:
  1179. * This function returns zero.
  1180. **/
  1181. static int
  1182. lpfc_idiag_release(struct inode *inode, struct file *file)
  1183. {
  1184. struct lpfc_debug *debug = file->private_data;
  1185. /* Free the buffers to the file operation */
  1186. kfree(debug->buffer);
  1187. kfree(debug);
  1188. return 0;
  1189. }
  1190. /**
  1191. * lpfc_idiag_cmd_release - Release idiag cmd access file operation
  1192. * @inode: The inode pointer that contains a vport pointer. (unused)
  1193. * @file: The file pointer that contains the buffer to release.
  1194. *
  1195. * Description:
  1196. * This routine frees the buffer that was allocated when the debugfs file
  1197. * was opened. It also reset the fields in the idiag command struct in the
  1198. * case of command for write operation.
  1199. *
  1200. * Returns:
  1201. * This function returns zero.
  1202. **/
  1203. static int
  1204. lpfc_idiag_cmd_release(struct inode *inode, struct file *file)
  1205. {
  1206. struct lpfc_debug *debug = file->private_data;
  1207. if (debug->op == LPFC_IDIAG_OP_WR) {
  1208. switch (idiag.cmd.opcode) {
  1209. case LPFC_IDIAG_CMD_PCICFG_WR:
  1210. case LPFC_IDIAG_CMD_PCICFG_ST:
  1211. case LPFC_IDIAG_CMD_PCICFG_CL:
  1212. case LPFC_IDIAG_CMD_QUEACC_WR:
  1213. case LPFC_IDIAG_CMD_QUEACC_ST:
  1214. case LPFC_IDIAG_CMD_QUEACC_CL:
  1215. memset(&idiag, 0, sizeof(idiag));
  1216. break;
  1217. default:
  1218. break;
  1219. }
  1220. }
  1221. /* Free the buffers to the file operation */
  1222. kfree(debug->buffer);
  1223. kfree(debug);
  1224. return 0;
  1225. }
  1226. /**
  1227. * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg
  1228. * @file: The file pointer to read from.
  1229. * @buf: The buffer to copy the data to.
  1230. * @nbytes: The number of bytes to read.
  1231. * @ppos: The position in the file to start reading from.
  1232. *
  1233. * Description:
  1234. * This routine reads data from the @phba pci config space according to the
  1235. * idiag command, and copies to user @buf. Depending on the PCI config space
  1236. * read command setup, it does either a single register read of a byte
  1237. * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all
  1238. * registers from the 4K extended PCI config space.
  1239. *
  1240. * Returns:
  1241. * This function returns the amount of data that was read (this could be less
  1242. * than @nbytes if the end of the file was reached) or a negative error value.
  1243. **/
  1244. static ssize_t
  1245. lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes,
  1246. loff_t *ppos)
  1247. {
  1248. struct lpfc_debug *debug = file->private_data;
  1249. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1250. int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE;
  1251. int where, count;
  1252. char *pbuffer;
  1253. struct pci_dev *pdev;
  1254. uint32_t u32val;
  1255. uint16_t u16val;
  1256. uint8_t u8val;
  1257. pdev = phba->pcidev;
  1258. if (!pdev)
  1259. return 0;
  1260. /* This is a user read operation */
  1261. debug->op = LPFC_IDIAG_OP_RD;
  1262. if (!debug->buffer)
  1263. debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL);
  1264. if (!debug->buffer)
  1265. return 0;
  1266. pbuffer = debug->buffer;
  1267. if (*ppos)
  1268. return 0;
  1269. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1270. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1271. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1272. } else
  1273. return 0;
  1274. /* Read single PCI config space register */
  1275. switch (count) {
  1276. case SIZE_U8: /* byte (8 bits) */
  1277. pci_read_config_byte(pdev, where, &u8val);
  1278. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1279. "%03x: %02x\n", where, u8val);
  1280. break;
  1281. case SIZE_U16: /* word (16 bits) */
  1282. pci_read_config_word(pdev, where, &u16val);
  1283. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1284. "%03x: %04x\n", where, u16val);
  1285. break;
  1286. case SIZE_U32: /* double word (32 bits) */
  1287. pci_read_config_dword(pdev, where, &u32val);
  1288. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1289. "%03x: %08x\n", where, u32val);
  1290. break;
  1291. case LPFC_PCI_CFG_BROWSE: /* browse all */
  1292. goto pcicfg_browse;
  1293. break;
  1294. default:
  1295. /* illegal count */
  1296. len = 0;
  1297. break;
  1298. }
  1299. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1300. pcicfg_browse:
  1301. /* Browse all PCI config space registers */
  1302. offset_label = idiag.offset.last_rd;
  1303. offset = offset_label;
  1304. /* Read PCI config space */
  1305. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1306. "%03x: ", offset_label);
  1307. while (index > 0) {
  1308. pci_read_config_dword(pdev, offset, &u32val);
  1309. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1310. "%08x ", u32val);
  1311. offset += sizeof(uint32_t);
  1312. if (offset >= LPFC_PCI_CFG_SIZE) {
  1313. len += snprintf(pbuffer+len,
  1314. LPFC_PCI_CFG_SIZE-len, "\n");
  1315. break;
  1316. }
  1317. index -= sizeof(uint32_t);
  1318. if (!index)
  1319. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1320. "\n");
  1321. else if (!(index % (8 * sizeof(uint32_t)))) {
  1322. offset_label += (8 * sizeof(uint32_t));
  1323. len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len,
  1324. "\n%03x: ", offset_label);
  1325. }
  1326. }
  1327. /* Set up the offset for next portion of pci cfg read */
  1328. if (index == 0) {
  1329. idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE;
  1330. if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE)
  1331. idiag.offset.last_rd = 0;
  1332. } else
  1333. idiag.offset.last_rd = 0;
  1334. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1335. }
  1336. /**
  1337. * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands
  1338. * @file: The file pointer to read from.
  1339. * @buf: The buffer to copy the user data from.
  1340. * @nbytes: The number of bytes to get.
  1341. * @ppos: The position in the file to start reading from.
  1342. *
  1343. * This routine get the debugfs idiag command struct from user space and
  1344. * then perform the syntax check for PCI config space read or write command
  1345. * accordingly. In the case of PCI config space read command, it sets up
  1346. * the command in the idiag command struct for the debugfs read operation.
  1347. * In the case of PCI config space write operation, it executes the write
  1348. * operation into the PCI config space accordingly.
  1349. *
  1350. * It returns the @nbytges passing in from debugfs user space when successful.
  1351. * In case of error conditions, it returns proper error code back to the user
  1352. * space.
  1353. */
  1354. static ssize_t
  1355. lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf,
  1356. size_t nbytes, loff_t *ppos)
  1357. {
  1358. struct lpfc_debug *debug = file->private_data;
  1359. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1360. uint32_t where, value, count;
  1361. uint32_t u32val;
  1362. uint16_t u16val;
  1363. uint8_t u8val;
  1364. struct pci_dev *pdev;
  1365. int rc;
  1366. pdev = phba->pcidev;
  1367. if (!pdev)
  1368. return -EFAULT;
  1369. /* This is a user write operation */
  1370. debug->op = LPFC_IDIAG_OP_WR;
  1371. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1372. if (rc < 0)
  1373. return rc;
  1374. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) {
  1375. /* Sanity check on PCI config read command line arguments */
  1376. if (rc != LPFC_PCI_CFG_RD_CMD_ARG)
  1377. goto error_out;
  1378. /* Read command from PCI config space, set up command fields */
  1379. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1380. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1381. if (count == LPFC_PCI_CFG_BROWSE) {
  1382. if (where % sizeof(uint32_t))
  1383. goto error_out;
  1384. /* Starting offset to browse */
  1385. idiag.offset.last_rd = where;
  1386. } else if ((count != sizeof(uint8_t)) &&
  1387. (count != sizeof(uint16_t)) &&
  1388. (count != sizeof(uint32_t)))
  1389. goto error_out;
  1390. if (count == sizeof(uint8_t)) {
  1391. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1392. goto error_out;
  1393. if (where % sizeof(uint8_t))
  1394. goto error_out;
  1395. }
  1396. if (count == sizeof(uint16_t)) {
  1397. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1398. goto error_out;
  1399. if (where % sizeof(uint16_t))
  1400. goto error_out;
  1401. }
  1402. if (count == sizeof(uint32_t)) {
  1403. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1404. goto error_out;
  1405. if (where % sizeof(uint32_t))
  1406. goto error_out;
  1407. }
  1408. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR ||
  1409. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST ||
  1410. idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1411. /* Sanity check on PCI config write command line arguments */
  1412. if (rc != LPFC_PCI_CFG_WR_CMD_ARG)
  1413. goto error_out;
  1414. /* Write command to PCI config space, read-modify-write */
  1415. where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX];
  1416. count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX];
  1417. value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX];
  1418. /* Sanity checks */
  1419. if ((count != sizeof(uint8_t)) &&
  1420. (count != sizeof(uint16_t)) &&
  1421. (count != sizeof(uint32_t)))
  1422. goto error_out;
  1423. if (count == sizeof(uint8_t)) {
  1424. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t))
  1425. goto error_out;
  1426. if (where % sizeof(uint8_t))
  1427. goto error_out;
  1428. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1429. pci_write_config_byte(pdev, where,
  1430. (uint8_t)value);
  1431. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1432. rc = pci_read_config_byte(pdev, where, &u8val);
  1433. if (!rc) {
  1434. u8val |= (uint8_t)value;
  1435. pci_write_config_byte(pdev, where,
  1436. u8val);
  1437. }
  1438. }
  1439. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1440. rc = pci_read_config_byte(pdev, where, &u8val);
  1441. if (!rc) {
  1442. u8val &= (uint8_t)(~value);
  1443. pci_write_config_byte(pdev, where,
  1444. u8val);
  1445. }
  1446. }
  1447. }
  1448. if (count == sizeof(uint16_t)) {
  1449. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t))
  1450. goto error_out;
  1451. if (where % sizeof(uint16_t))
  1452. goto error_out;
  1453. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1454. pci_write_config_word(pdev, where,
  1455. (uint16_t)value);
  1456. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1457. rc = pci_read_config_word(pdev, where, &u16val);
  1458. if (!rc) {
  1459. u16val |= (uint16_t)value;
  1460. pci_write_config_word(pdev, where,
  1461. u16val);
  1462. }
  1463. }
  1464. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1465. rc = pci_read_config_word(pdev, where, &u16val);
  1466. if (!rc) {
  1467. u16val &= (uint16_t)(~value);
  1468. pci_write_config_word(pdev, where,
  1469. u16val);
  1470. }
  1471. }
  1472. }
  1473. if (count == sizeof(uint32_t)) {
  1474. if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t))
  1475. goto error_out;
  1476. if (where % sizeof(uint32_t))
  1477. goto error_out;
  1478. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR)
  1479. pci_write_config_dword(pdev, where, value);
  1480. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) {
  1481. rc = pci_read_config_dword(pdev, where,
  1482. &u32val);
  1483. if (!rc) {
  1484. u32val |= value;
  1485. pci_write_config_dword(pdev, where,
  1486. u32val);
  1487. }
  1488. }
  1489. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) {
  1490. rc = pci_read_config_dword(pdev, where,
  1491. &u32val);
  1492. if (!rc) {
  1493. u32val &= ~value;
  1494. pci_write_config_dword(pdev, where,
  1495. u32val);
  1496. }
  1497. }
  1498. }
  1499. } else
  1500. /* All other opecodes are illegal for now */
  1501. goto error_out;
  1502. return nbytes;
  1503. error_out:
  1504. memset(&idiag, 0, sizeof(idiag));
  1505. return -EINVAL;
  1506. }
  1507. /**
  1508. * lpfc_idiag_baracc_read - idiag debugfs pci bar access read
  1509. * @file: The file pointer to read from.
  1510. * @buf: The buffer to copy the data to.
  1511. * @nbytes: The number of bytes to read.
  1512. * @ppos: The position in the file to start reading from.
  1513. *
  1514. * Description:
  1515. * This routine reads data from the @phba pci bar memory mapped space
  1516. * according to the idiag command, and copies to user @buf.
  1517. *
  1518. * Returns:
  1519. * This function returns the amount of data that was read (this could be less
  1520. * than @nbytes if the end of the file was reached) or a negative error value.
  1521. **/
  1522. static ssize_t
  1523. lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes,
  1524. loff_t *ppos)
  1525. {
  1526. struct lpfc_debug *debug = file->private_data;
  1527. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1528. int offset_label, offset, offset_run, len = 0, index;
  1529. int bar_num, acc_range, bar_size;
  1530. char *pbuffer;
  1531. void __iomem *mem_mapped_bar;
  1532. uint32_t if_type;
  1533. struct pci_dev *pdev;
  1534. uint32_t u32val;
  1535. pdev = phba->pcidev;
  1536. if (!pdev)
  1537. return 0;
  1538. /* This is a user read operation */
  1539. debug->op = LPFC_IDIAG_OP_RD;
  1540. if (!debug->buffer)
  1541. debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL);
  1542. if (!debug->buffer)
  1543. return 0;
  1544. pbuffer = debug->buffer;
  1545. if (*ppos)
  1546. return 0;
  1547. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  1548. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  1549. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  1550. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  1551. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  1552. } else
  1553. return 0;
  1554. if (acc_range == 0)
  1555. return 0;
  1556. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1557. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1558. if (bar_num == IDIAG_BARACC_BAR_0)
  1559. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1560. else if (bar_num == IDIAG_BARACC_BAR_1)
  1561. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  1562. else if (bar_num == IDIAG_BARACC_BAR_2)
  1563. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  1564. else
  1565. return 0;
  1566. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1567. if (bar_num == IDIAG_BARACC_BAR_0)
  1568. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1569. else
  1570. return 0;
  1571. } else
  1572. return 0;
  1573. /* Read single PCI bar space register */
  1574. if (acc_range == SINGLE_WORD) {
  1575. offset_run = offset;
  1576. u32val = readl(mem_mapped_bar + offset_run);
  1577. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1578. "%05x: %08x\n", offset_run, u32val);
  1579. } else
  1580. goto baracc_browse;
  1581. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1582. baracc_browse:
  1583. /* Browse all PCI bar space registers */
  1584. offset_label = idiag.offset.last_rd;
  1585. offset_run = offset_label;
  1586. /* Read PCI bar memory mapped space */
  1587. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1588. "%05x: ", offset_label);
  1589. index = LPFC_PCI_BAR_RD_SIZE;
  1590. while (index > 0) {
  1591. u32val = readl(mem_mapped_bar + offset_run);
  1592. len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1593. "%08x ", u32val);
  1594. offset_run += sizeof(uint32_t);
  1595. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1596. if (offset_run >= bar_size) {
  1597. len += snprintf(pbuffer+len,
  1598. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1599. break;
  1600. }
  1601. } else {
  1602. if (offset_run >= offset +
  1603. (acc_range * sizeof(uint32_t))) {
  1604. len += snprintf(pbuffer+len,
  1605. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1606. break;
  1607. }
  1608. }
  1609. index -= sizeof(uint32_t);
  1610. if (!index)
  1611. len += snprintf(pbuffer+len,
  1612. LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n");
  1613. else if (!(index % (8 * sizeof(uint32_t)))) {
  1614. offset_label += (8 * sizeof(uint32_t));
  1615. len += snprintf(pbuffer+len,
  1616. LPFC_PCI_BAR_RD_BUF_SIZE-len,
  1617. "\n%05x: ", offset_label);
  1618. }
  1619. }
  1620. /* Set up the offset for next portion of pci bar read */
  1621. if (index == 0) {
  1622. idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE;
  1623. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1624. if (idiag.offset.last_rd >= bar_size)
  1625. idiag.offset.last_rd = 0;
  1626. } else {
  1627. if (offset_run >= offset +
  1628. (acc_range * sizeof(uint32_t)))
  1629. idiag.offset.last_rd = offset;
  1630. }
  1631. } else {
  1632. if (acc_range == LPFC_PCI_BAR_BROWSE)
  1633. idiag.offset.last_rd = 0;
  1634. else
  1635. idiag.offset.last_rd = offset;
  1636. }
  1637. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1638. }
  1639. /**
  1640. * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands
  1641. * @file: The file pointer to read from.
  1642. * @buf: The buffer to copy the user data from.
  1643. * @nbytes: The number of bytes to get.
  1644. * @ppos: The position in the file to start reading from.
  1645. *
  1646. * This routine get the debugfs idiag command struct from user space and
  1647. * then perform the syntax check for PCI bar memory mapped space read or
  1648. * write command accordingly. In the case of PCI bar memory mapped space
  1649. * read command, it sets up the command in the idiag command struct for
  1650. * the debugfs read operation. In the case of PCI bar memorpy mapped space
  1651. * write operation, it executes the write operation into the PCI bar memory
  1652. * mapped space accordingly.
  1653. *
  1654. * It returns the @nbytges passing in from debugfs user space when successful.
  1655. * In case of error conditions, it returns proper error code back to the user
  1656. * space.
  1657. */
  1658. static ssize_t
  1659. lpfc_idiag_baracc_write(struct file *file, const char __user *buf,
  1660. size_t nbytes, loff_t *ppos)
  1661. {
  1662. struct lpfc_debug *debug = file->private_data;
  1663. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1664. uint32_t bar_num, bar_size, offset, value, acc_range;
  1665. struct pci_dev *pdev;
  1666. void __iomem *mem_mapped_bar;
  1667. uint32_t if_type;
  1668. uint32_t u32val;
  1669. int rc;
  1670. pdev = phba->pcidev;
  1671. if (!pdev)
  1672. return -EFAULT;
  1673. /* This is a user write operation */
  1674. debug->op = LPFC_IDIAG_OP_WR;
  1675. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  1676. if (rc < 0)
  1677. return rc;
  1678. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  1679. bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX];
  1680. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1681. if ((bar_num != IDIAG_BARACC_BAR_0) &&
  1682. (bar_num != IDIAG_BARACC_BAR_1) &&
  1683. (bar_num != IDIAG_BARACC_BAR_2))
  1684. goto error_out;
  1685. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1686. if (bar_num != IDIAG_BARACC_BAR_0)
  1687. goto error_out;
  1688. } else
  1689. goto error_out;
  1690. if (if_type == LPFC_SLI_INTF_IF_TYPE_0) {
  1691. if (bar_num == IDIAG_BARACC_BAR_0) {
  1692. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1693. LPFC_PCI_IF0_BAR0_SIZE;
  1694. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1695. } else if (bar_num == IDIAG_BARACC_BAR_1) {
  1696. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1697. LPFC_PCI_IF0_BAR1_SIZE;
  1698. mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p;
  1699. } else if (bar_num == IDIAG_BARACC_BAR_2) {
  1700. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1701. LPFC_PCI_IF0_BAR2_SIZE;
  1702. mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p;
  1703. } else
  1704. goto error_out;
  1705. } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) {
  1706. if (bar_num == IDIAG_BARACC_BAR_0) {
  1707. idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] =
  1708. LPFC_PCI_IF2_BAR0_SIZE;
  1709. mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p;
  1710. } else
  1711. goto error_out;
  1712. } else
  1713. goto error_out;
  1714. offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX];
  1715. if (offset % sizeof(uint32_t))
  1716. goto error_out;
  1717. bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX];
  1718. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) {
  1719. /* Sanity check on PCI config read command line arguments */
  1720. if (rc != LPFC_PCI_BAR_RD_CMD_ARG)
  1721. goto error_out;
  1722. acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX];
  1723. if (acc_range == LPFC_PCI_BAR_BROWSE) {
  1724. if (offset > bar_size - sizeof(uint32_t))
  1725. goto error_out;
  1726. /* Starting offset to browse */
  1727. idiag.offset.last_rd = offset;
  1728. } else if (acc_range > SINGLE_WORD) {
  1729. if (offset + acc_range * sizeof(uint32_t) > bar_size)
  1730. goto error_out;
  1731. /* Starting offset to browse */
  1732. idiag.offset.last_rd = offset;
  1733. } else if (acc_range != SINGLE_WORD)
  1734. goto error_out;
  1735. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR ||
  1736. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST ||
  1737. idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  1738. /* Sanity check on PCI bar write command line arguments */
  1739. if (rc != LPFC_PCI_BAR_WR_CMD_ARG)
  1740. goto error_out;
  1741. /* Write command to PCI bar space, read-modify-write */
  1742. acc_range = SINGLE_WORD;
  1743. value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX];
  1744. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) {
  1745. writel(value, mem_mapped_bar + offset);
  1746. readl(mem_mapped_bar + offset);
  1747. }
  1748. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) {
  1749. u32val = readl(mem_mapped_bar + offset);
  1750. u32val |= value;
  1751. writel(u32val, mem_mapped_bar + offset);
  1752. readl(mem_mapped_bar + offset);
  1753. }
  1754. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) {
  1755. u32val = readl(mem_mapped_bar + offset);
  1756. u32val &= ~value;
  1757. writel(u32val, mem_mapped_bar + offset);
  1758. readl(mem_mapped_bar + offset);
  1759. }
  1760. } else
  1761. /* All other opecodes are illegal for now */
  1762. goto error_out;
  1763. return nbytes;
  1764. error_out:
  1765. memset(&idiag, 0, sizeof(idiag));
  1766. return -EINVAL;
  1767. }
  1768. /**
  1769. * lpfc_idiag_queinfo_read - idiag debugfs read queue information
  1770. * @file: The file pointer to read from.
  1771. * @buf: The buffer to copy the data to.
  1772. * @nbytes: The number of bytes to read.
  1773. * @ppos: The position in the file to start reading from.
  1774. *
  1775. * Description:
  1776. * This routine reads data from the @phba SLI4 PCI function queue information,
  1777. * and copies to user @buf.
  1778. *
  1779. * Returns:
  1780. * This function returns the amount of data that was read (this could be less
  1781. * than @nbytes if the end of the file was reached) or a negative error value.
  1782. **/
  1783. static ssize_t
  1784. lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes,
  1785. loff_t *ppos)
  1786. {
  1787. struct lpfc_debug *debug = file->private_data;
  1788. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  1789. int len = 0, fcp_qidx;
  1790. char *pbuffer;
  1791. if (!debug->buffer)
  1792. debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL);
  1793. if (!debug->buffer)
  1794. return 0;
  1795. pbuffer = debug->buffer;
  1796. if (*ppos)
  1797. return 0;
  1798. /* Get slow-path event queue information */
  1799. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1800. "Slow-path EQ information:\n");
  1801. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1802. "\tEQID[%02d], "
  1803. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1804. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1805. phba->sli4_hba.sp_eq->queue_id,
  1806. phba->sli4_hba.sp_eq->entry_count,
  1807. phba->sli4_hba.sp_eq->entry_size,
  1808. phba->sli4_hba.sp_eq->host_index,
  1809. phba->sli4_hba.sp_eq->hba_index);
  1810. /* Get fast-path event queue information */
  1811. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1812. "Fast-path EQ information:\n");
  1813. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) {
  1814. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1815. "\tEQID[%02d], "
  1816. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1817. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1818. phba->sli4_hba.fp_eq[fcp_qidx]->queue_id,
  1819. phba->sli4_hba.fp_eq[fcp_qidx]->entry_count,
  1820. phba->sli4_hba.fp_eq[fcp_qidx]->entry_size,
  1821. phba->sli4_hba.fp_eq[fcp_qidx]->host_index,
  1822. phba->sli4_hba.fp_eq[fcp_qidx]->hba_index);
  1823. }
  1824. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1825. /* Get mailbox complete queue information */
  1826. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1827. "Slow-path MBX CQ information:\n");
  1828. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1829. "Associated EQID[%02d]:\n",
  1830. phba->sli4_hba.mbx_cq->assoc_qid);
  1831. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1832. "\tCQID[%02d], "
  1833. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1834. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1835. phba->sli4_hba.mbx_cq->queue_id,
  1836. phba->sli4_hba.mbx_cq->entry_count,
  1837. phba->sli4_hba.mbx_cq->entry_size,
  1838. phba->sli4_hba.mbx_cq->host_index,
  1839. phba->sli4_hba.mbx_cq->hba_index);
  1840. /* Get slow-path complete queue information */
  1841. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1842. "Slow-path ELS CQ information:\n");
  1843. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1844. "Associated EQID[%02d]:\n",
  1845. phba->sli4_hba.els_cq->assoc_qid);
  1846. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1847. "\tCQID [%02d], "
  1848. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1849. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1850. phba->sli4_hba.els_cq->queue_id,
  1851. phba->sli4_hba.els_cq->entry_count,
  1852. phba->sli4_hba.els_cq->entry_size,
  1853. phba->sli4_hba.els_cq->host_index,
  1854. phba->sli4_hba.els_cq->hba_index);
  1855. /* Get fast-path complete queue information */
  1856. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1857. "Fast-path FCP CQ information:\n");
  1858. fcp_qidx = 0;
  1859. do {
  1860. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1861. "Associated EQID[%02d]:\n",
  1862. phba->sli4_hba.fcp_cq[fcp_qidx]->assoc_qid);
  1863. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1864. "\tCQID[%02d], "
  1865. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1866. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1867. phba->sli4_hba.fcp_cq[fcp_qidx]->queue_id,
  1868. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_count,
  1869. phba->sli4_hba.fcp_cq[fcp_qidx]->entry_size,
  1870. phba->sli4_hba.fcp_cq[fcp_qidx]->host_index,
  1871. phba->sli4_hba.fcp_cq[fcp_qidx]->hba_index);
  1872. } while (++fcp_qidx < phba->cfg_fcp_eq_count);
  1873. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1874. /* Get mailbox queue information */
  1875. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1876. "Slow-path MBX MQ information:\n");
  1877. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1878. "Associated CQID[%02d]:\n",
  1879. phba->sli4_hba.mbx_wq->assoc_qid);
  1880. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1881. "\tWQID[%02d], "
  1882. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1883. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1884. phba->sli4_hba.mbx_wq->queue_id,
  1885. phba->sli4_hba.mbx_wq->entry_count,
  1886. phba->sli4_hba.mbx_wq->entry_size,
  1887. phba->sli4_hba.mbx_wq->host_index,
  1888. phba->sli4_hba.mbx_wq->hba_index);
  1889. /* Get slow-path work queue information */
  1890. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1891. "Slow-path ELS WQ information:\n");
  1892. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1893. "Associated CQID[%02d]:\n",
  1894. phba->sli4_hba.els_wq->assoc_qid);
  1895. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1896. "\tWQID[%02d], "
  1897. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1898. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n\n",
  1899. phba->sli4_hba.els_wq->queue_id,
  1900. phba->sli4_hba.els_wq->entry_count,
  1901. phba->sli4_hba.els_wq->entry_size,
  1902. phba->sli4_hba.els_wq->host_index,
  1903. phba->sli4_hba.els_wq->hba_index);
  1904. /* Get fast-path work queue information */
  1905. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1906. "Fast-path FCP WQ information:\n");
  1907. for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) {
  1908. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1909. "Associated CQID[%02d]:\n",
  1910. phba->sli4_hba.fcp_wq[fcp_qidx]->assoc_qid);
  1911. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1912. "\tWQID[%02d], "
  1913. "QE-COUNT[%04d], WQE-SIZE[%04d], "
  1914. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1915. phba->sli4_hba.fcp_wq[fcp_qidx]->queue_id,
  1916. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_count,
  1917. phba->sli4_hba.fcp_wq[fcp_qidx]->entry_size,
  1918. phba->sli4_hba.fcp_wq[fcp_qidx]->host_index,
  1919. phba->sli4_hba.fcp_wq[fcp_qidx]->hba_index);
  1920. }
  1921. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len, "\n");
  1922. /* Get receive queue information */
  1923. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1924. "Slow-path RQ information:\n");
  1925. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1926. "Associated CQID[%02d]:\n",
  1927. phba->sli4_hba.hdr_rq->assoc_qid);
  1928. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1929. "\tHQID[%02d], "
  1930. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1931. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1932. phba->sli4_hba.hdr_rq->queue_id,
  1933. phba->sli4_hba.hdr_rq->entry_count,
  1934. phba->sli4_hba.hdr_rq->entry_size,
  1935. phba->sli4_hba.hdr_rq->host_index,
  1936. phba->sli4_hba.hdr_rq->hba_index);
  1937. len += snprintf(pbuffer+len, LPFC_QUE_INFO_GET_BUF_SIZE-len,
  1938. "\tDQID[%02d], "
  1939. "QE-COUNT[%04d], QE-SIZE[%04d], "
  1940. "HOST-INDEX[%04d], PORT-INDEX[%04d]\n",
  1941. phba->sli4_hba.dat_rq->queue_id,
  1942. phba->sli4_hba.dat_rq->entry_count,
  1943. phba->sli4_hba.dat_rq->entry_size,
  1944. phba->sli4_hba.dat_rq->host_index,
  1945. phba->sli4_hba.dat_rq->hba_index);
  1946. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  1947. }
  1948. /**
  1949. * lpfc_idiag_que_param_check - queue access command parameter sanity check
  1950. * @q: The pointer to queue structure.
  1951. * @index: The index into a queue entry.
  1952. * @count: The number of queue entries to access.
  1953. *
  1954. * Description:
  1955. * The routine performs sanity check on device queue access method commands.
  1956. *
  1957. * Returns:
  1958. * This function returns -EINVAL when fails the sanity check, otherwise, it
  1959. * returns 0.
  1960. **/
  1961. static int
  1962. lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count)
  1963. {
  1964. /* Only support single entry read or browsing */
  1965. if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE))
  1966. return -EINVAL;
  1967. if (index > q->entry_count - 1)
  1968. return -EINVAL;
  1969. return 0;
  1970. }
  1971. /**
  1972. * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index
  1973. * @pbuffer: The pointer to buffer to copy the read data into.
  1974. * @pque: The pointer to the queue to be read.
  1975. * @index: The index into the queue entry.
  1976. *
  1977. * Description:
  1978. * This routine reads out a single entry from the given queue's index location
  1979. * and copies it into the buffer provided.
  1980. *
  1981. * Returns:
  1982. * This function returns 0 when it fails, otherwise, it returns the length of
  1983. * the data read into the buffer provided.
  1984. **/
  1985. static int
  1986. lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque,
  1987. uint32_t index)
  1988. {
  1989. int offset, esize;
  1990. uint32_t *pentry;
  1991. if (!pbuffer || !pque)
  1992. return 0;
  1993. esize = pque->entry_size;
  1994. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  1995. "QE-INDEX[%04d]:\n", index);
  1996. offset = 0;
  1997. pentry = pque->qe[index].address;
  1998. while (esize > 0) {
  1999. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len,
  2000. "%08x ", *pentry);
  2001. pentry++;
  2002. offset += sizeof(uint32_t);
  2003. esize -= sizeof(uint32_t);
  2004. if (esize > 0 && !(offset % (4 * sizeof(uint32_t))))
  2005. len += snprintf(pbuffer+len,
  2006. LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  2007. }
  2008. len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n");
  2009. return len;
  2010. }
  2011. /**
  2012. * lpfc_idiag_queacc_read - idiag debugfs read port queue
  2013. * @file: The file pointer to read from.
  2014. * @buf: The buffer to copy the data to.
  2015. * @nbytes: The number of bytes to read.
  2016. * @ppos: The position in the file to start reading from.
  2017. *
  2018. * Description:
  2019. * This routine reads data from the @phba device queue memory according to the
  2020. * idiag command, and copies to user @buf. Depending on the queue dump read
  2021. * command setup, it does either a single queue entry read or browing through
  2022. * all entries of the queue.
  2023. *
  2024. * Returns:
  2025. * This function returns the amount of data that was read (this could be less
  2026. * than @nbytes if the end of the file was reached) or a negative error value.
  2027. **/
  2028. static ssize_t
  2029. lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes,
  2030. loff_t *ppos)
  2031. {
  2032. struct lpfc_debug *debug = file->private_data;
  2033. uint32_t last_index, index, count;
  2034. struct lpfc_queue *pque = NULL;
  2035. char *pbuffer;
  2036. int len = 0;
  2037. /* This is a user read operation */
  2038. debug->op = LPFC_IDIAG_OP_RD;
  2039. if (!debug->buffer)
  2040. debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL);
  2041. if (!debug->buffer)
  2042. return 0;
  2043. pbuffer = debug->buffer;
  2044. if (*ppos)
  2045. return 0;
  2046. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  2047. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  2048. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  2049. pque = (struct lpfc_queue *)idiag.ptr_private;
  2050. } else
  2051. return 0;
  2052. /* Browse the queue starting from index */
  2053. if (count == LPFC_QUE_ACC_BROWSE)
  2054. goto que_browse;
  2055. /* Read a single entry from the queue */
  2056. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  2057. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2058. que_browse:
  2059. /* Browse all entries from the queue */
  2060. last_index = idiag.offset.last_rd;
  2061. index = last_index;
  2062. while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) {
  2063. len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index);
  2064. index++;
  2065. if (index > pque->entry_count - 1)
  2066. break;
  2067. }
  2068. /* Set up the offset for next portion of pci cfg read */
  2069. if (index > pque->entry_count - 1)
  2070. index = 0;
  2071. idiag.offset.last_rd = index;
  2072. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2073. }
  2074. /**
  2075. * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands
  2076. * @file: The file pointer to read from.
  2077. * @buf: The buffer to copy the user data from.
  2078. * @nbytes: The number of bytes to get.
  2079. * @ppos: The position in the file to start reading from.
  2080. *
  2081. * This routine get the debugfs idiag command struct from user space and then
  2082. * perform the syntax check for port queue read (dump) or write (set) command
  2083. * accordingly. In the case of port queue read command, it sets up the command
  2084. * in the idiag command struct for the following debugfs read operation. In
  2085. * the case of port queue write operation, it executes the write operation
  2086. * into the port queue entry accordingly.
  2087. *
  2088. * It returns the @nbytges passing in from debugfs user space when successful.
  2089. * In case of error conditions, it returns proper error code back to the user
  2090. * space.
  2091. **/
  2092. static ssize_t
  2093. lpfc_idiag_queacc_write(struct file *file, const char __user *buf,
  2094. size_t nbytes, loff_t *ppos)
  2095. {
  2096. struct lpfc_debug *debug = file->private_data;
  2097. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2098. uint32_t qidx, quetp, queid, index, count, offset, value;
  2099. uint32_t *pentry;
  2100. struct lpfc_queue *pque;
  2101. int rc;
  2102. /* This is a user write operation */
  2103. debug->op = LPFC_IDIAG_OP_WR;
  2104. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2105. if (rc < 0)
  2106. return rc;
  2107. /* Get and sanity check on command feilds */
  2108. quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX];
  2109. queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX];
  2110. index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX];
  2111. count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX];
  2112. offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX];
  2113. value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX];
  2114. /* Sanity check on command line arguments */
  2115. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  2116. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  2117. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  2118. if (rc != LPFC_QUE_ACC_WR_CMD_ARG)
  2119. goto error_out;
  2120. if (count != 1)
  2121. goto error_out;
  2122. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  2123. if (rc != LPFC_QUE_ACC_RD_CMD_ARG)
  2124. goto error_out;
  2125. } else
  2126. goto error_out;
  2127. switch (quetp) {
  2128. case LPFC_IDIAG_EQ:
  2129. /* Slow-path event queue */
  2130. if (phba->sli4_hba.sp_eq->queue_id == queid) {
  2131. /* Sanity check */
  2132. rc = lpfc_idiag_que_param_check(
  2133. phba->sli4_hba.sp_eq, index, count);
  2134. if (rc)
  2135. goto error_out;
  2136. idiag.ptr_private = phba->sli4_hba.sp_eq;
  2137. goto pass_check;
  2138. }
  2139. /* Fast-path event queue */
  2140. for (qidx = 0; qidx < phba->cfg_fcp_eq_count; qidx++) {
  2141. if (phba->sli4_hba.fp_eq[qidx]->queue_id == queid) {
  2142. /* Sanity check */
  2143. rc = lpfc_idiag_que_param_check(
  2144. phba->sli4_hba.fp_eq[qidx],
  2145. index, count);
  2146. if (rc)
  2147. goto error_out;
  2148. idiag.ptr_private = phba->sli4_hba.fp_eq[qidx];
  2149. goto pass_check;
  2150. }
  2151. }
  2152. goto error_out;
  2153. break;
  2154. case LPFC_IDIAG_CQ:
  2155. /* MBX complete queue */
  2156. if (phba->sli4_hba.mbx_cq->queue_id == queid) {
  2157. /* Sanity check */
  2158. rc = lpfc_idiag_que_param_check(
  2159. phba->sli4_hba.mbx_cq, index, count);
  2160. if (rc)
  2161. goto error_out;
  2162. idiag.ptr_private = phba->sli4_hba.mbx_cq;
  2163. goto pass_check;
  2164. }
  2165. /* ELS complete queue */
  2166. if (phba->sli4_hba.els_cq->queue_id == queid) {
  2167. /* Sanity check */
  2168. rc = lpfc_idiag_que_param_check(
  2169. phba->sli4_hba.els_cq, index, count);
  2170. if (rc)
  2171. goto error_out;
  2172. idiag.ptr_private = phba->sli4_hba.els_cq;
  2173. goto pass_check;
  2174. }
  2175. /* FCP complete queue */
  2176. qidx = 0;
  2177. do {
  2178. if (phba->sli4_hba.fcp_cq[qidx]->queue_id == queid) {
  2179. /* Sanity check */
  2180. rc = lpfc_idiag_que_param_check(
  2181. phba->sli4_hba.fcp_cq[qidx],
  2182. index, count);
  2183. if (rc)
  2184. goto error_out;
  2185. idiag.ptr_private =
  2186. phba->sli4_hba.fcp_cq[qidx];
  2187. goto pass_check;
  2188. }
  2189. } while (++qidx < phba->cfg_fcp_eq_count);
  2190. goto error_out;
  2191. break;
  2192. case LPFC_IDIAG_MQ:
  2193. /* MBX work queue */
  2194. if (phba->sli4_hba.mbx_wq->queue_id == queid) {
  2195. /* Sanity check */
  2196. rc = lpfc_idiag_que_param_check(
  2197. phba->sli4_hba.mbx_wq, index, count);
  2198. if (rc)
  2199. goto error_out;
  2200. idiag.ptr_private = phba->sli4_hba.mbx_wq;
  2201. goto pass_check;
  2202. }
  2203. break;
  2204. case LPFC_IDIAG_WQ:
  2205. /* ELS work queue */
  2206. if (phba->sli4_hba.els_wq->queue_id == queid) {
  2207. /* Sanity check */
  2208. rc = lpfc_idiag_que_param_check(
  2209. phba->sli4_hba.els_wq, index, count);
  2210. if (rc)
  2211. goto error_out;
  2212. idiag.ptr_private = phba->sli4_hba.els_wq;
  2213. goto pass_check;
  2214. }
  2215. /* FCP work queue */
  2216. for (qidx = 0; qidx < phba->cfg_fcp_wq_count; qidx++) {
  2217. if (phba->sli4_hba.fcp_wq[qidx]->queue_id == queid) {
  2218. /* Sanity check */
  2219. rc = lpfc_idiag_que_param_check(
  2220. phba->sli4_hba.fcp_wq[qidx],
  2221. index, count);
  2222. if (rc)
  2223. goto error_out;
  2224. idiag.ptr_private =
  2225. phba->sli4_hba.fcp_wq[qidx];
  2226. goto pass_check;
  2227. }
  2228. }
  2229. goto error_out;
  2230. break;
  2231. case LPFC_IDIAG_RQ:
  2232. /* HDR queue */
  2233. if (phba->sli4_hba.hdr_rq->queue_id == queid) {
  2234. /* Sanity check */
  2235. rc = lpfc_idiag_que_param_check(
  2236. phba->sli4_hba.hdr_rq, index, count);
  2237. if (rc)
  2238. goto error_out;
  2239. idiag.ptr_private = phba->sli4_hba.hdr_rq;
  2240. goto pass_check;
  2241. }
  2242. /* DAT queue */
  2243. if (phba->sli4_hba.dat_rq->queue_id == queid) {
  2244. /* Sanity check */
  2245. rc = lpfc_idiag_que_param_check(
  2246. phba->sli4_hba.dat_rq, index, count);
  2247. if (rc)
  2248. goto error_out;
  2249. idiag.ptr_private = phba->sli4_hba.dat_rq;
  2250. goto pass_check;
  2251. }
  2252. goto error_out;
  2253. break;
  2254. default:
  2255. goto error_out;
  2256. break;
  2257. }
  2258. pass_check:
  2259. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) {
  2260. if (count == LPFC_QUE_ACC_BROWSE)
  2261. idiag.offset.last_rd = index;
  2262. }
  2263. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR ||
  2264. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST ||
  2265. idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) {
  2266. /* Additional sanity checks on write operation */
  2267. pque = (struct lpfc_queue *)idiag.ptr_private;
  2268. if (offset > pque->entry_size/sizeof(uint32_t) - 1)
  2269. goto error_out;
  2270. pentry = pque->qe[index].address;
  2271. pentry += offset;
  2272. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR)
  2273. *pentry = value;
  2274. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST)
  2275. *pentry |= value;
  2276. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL)
  2277. *pentry &= ~value;
  2278. }
  2279. return nbytes;
  2280. error_out:
  2281. /* Clean out command structure on command error out */
  2282. memset(&idiag, 0, sizeof(idiag));
  2283. return -EINVAL;
  2284. }
  2285. /**
  2286. * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register
  2287. * @phba: The pointer to hba structure.
  2288. * @pbuffer: The pointer to the buffer to copy the data to.
  2289. * @len: The lenght of bytes to copied.
  2290. * @drbregid: The id to doorbell registers.
  2291. *
  2292. * Description:
  2293. * This routine reads a doorbell register and copies its content to the
  2294. * user buffer pointed to by @pbuffer.
  2295. *
  2296. * Returns:
  2297. * This function returns the amount of data that was copied into @pbuffer.
  2298. **/
  2299. static int
  2300. lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  2301. int len, uint32_t drbregid)
  2302. {
  2303. if (!pbuffer)
  2304. return 0;
  2305. switch (drbregid) {
  2306. case LPFC_DRB_EQCQ:
  2307. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2308. "EQCQ-DRB-REG: 0x%08x\n",
  2309. readl(phba->sli4_hba.EQCQDBregaddr));
  2310. break;
  2311. case LPFC_DRB_MQ:
  2312. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2313. "MQ-DRB-REG: 0x%08x\n",
  2314. readl(phba->sli4_hba.MQDBregaddr));
  2315. break;
  2316. case LPFC_DRB_WQ:
  2317. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2318. "WQ-DRB-REG: 0x%08x\n",
  2319. readl(phba->sli4_hba.WQDBregaddr));
  2320. break;
  2321. case LPFC_DRB_RQ:
  2322. len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len,
  2323. "RQ-DRB-REG: 0x%08x\n",
  2324. readl(phba->sli4_hba.RQDBregaddr));
  2325. break;
  2326. default:
  2327. break;
  2328. }
  2329. return len;
  2330. }
  2331. /**
  2332. * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell
  2333. * @file: The file pointer to read from.
  2334. * @buf: The buffer to copy the data to.
  2335. * @nbytes: The number of bytes to read.
  2336. * @ppos: The position in the file to start reading from.
  2337. *
  2338. * Description:
  2339. * This routine reads data from the @phba device doorbell register according
  2340. * to the idiag command, and copies to user @buf. Depending on the doorbell
  2341. * register read command setup, it does either a single doorbell register
  2342. * read or dump all doorbell registers.
  2343. *
  2344. * Returns:
  2345. * This function returns the amount of data that was read (this could be less
  2346. * than @nbytes if the end of the file was reached) or a negative error value.
  2347. **/
  2348. static ssize_t
  2349. lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes,
  2350. loff_t *ppos)
  2351. {
  2352. struct lpfc_debug *debug = file->private_data;
  2353. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2354. uint32_t drb_reg_id, i;
  2355. char *pbuffer;
  2356. int len = 0;
  2357. /* This is a user read operation */
  2358. debug->op = LPFC_IDIAG_OP_RD;
  2359. if (!debug->buffer)
  2360. debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL);
  2361. if (!debug->buffer)
  2362. return 0;
  2363. pbuffer = debug->buffer;
  2364. if (*ppos)
  2365. return 0;
  2366. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD)
  2367. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  2368. else
  2369. return 0;
  2370. if (drb_reg_id == LPFC_DRB_ACC_ALL)
  2371. for (i = 1; i <= LPFC_DRB_MAX; i++)
  2372. len = lpfc_idiag_drbacc_read_reg(phba,
  2373. pbuffer, len, i);
  2374. else
  2375. len = lpfc_idiag_drbacc_read_reg(phba,
  2376. pbuffer, len, drb_reg_id);
  2377. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2378. }
  2379. /**
  2380. * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands
  2381. * @file: The file pointer to read from.
  2382. * @buf: The buffer to copy the user data from.
  2383. * @nbytes: The number of bytes to get.
  2384. * @ppos: The position in the file to start reading from.
  2385. *
  2386. * This routine get the debugfs idiag command struct from user space and then
  2387. * perform the syntax check for port doorbell register read (dump) or write
  2388. * (set) command accordingly. In the case of port queue read command, it sets
  2389. * up the command in the idiag command struct for the following debugfs read
  2390. * operation. In the case of port doorbell register write operation, it
  2391. * executes the write operation into the port doorbell register accordingly.
  2392. *
  2393. * It returns the @nbytges passing in from debugfs user space when successful.
  2394. * In case of error conditions, it returns proper error code back to the user
  2395. * space.
  2396. **/
  2397. static ssize_t
  2398. lpfc_idiag_drbacc_write(struct file *file, const char __user *buf,
  2399. size_t nbytes, loff_t *ppos)
  2400. {
  2401. struct lpfc_debug *debug = file->private_data;
  2402. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2403. uint32_t drb_reg_id, value, reg_val = 0;
  2404. void __iomem *drb_reg;
  2405. int rc;
  2406. /* This is a user write operation */
  2407. debug->op = LPFC_IDIAG_OP_WR;
  2408. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2409. if (rc < 0)
  2410. return rc;
  2411. /* Sanity check on command line arguments */
  2412. drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX];
  2413. value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX];
  2414. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2415. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2416. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2417. if (rc != LPFC_DRB_ACC_WR_CMD_ARG)
  2418. goto error_out;
  2419. if (drb_reg_id > LPFC_DRB_MAX)
  2420. goto error_out;
  2421. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) {
  2422. if (rc != LPFC_DRB_ACC_RD_CMD_ARG)
  2423. goto error_out;
  2424. if ((drb_reg_id > LPFC_DRB_MAX) &&
  2425. (drb_reg_id != LPFC_DRB_ACC_ALL))
  2426. goto error_out;
  2427. } else
  2428. goto error_out;
  2429. /* Perform the write access operation */
  2430. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR ||
  2431. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST ||
  2432. idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2433. switch (drb_reg_id) {
  2434. case LPFC_DRB_EQCQ:
  2435. drb_reg = phba->sli4_hba.EQCQDBregaddr;
  2436. break;
  2437. case LPFC_DRB_MQ:
  2438. drb_reg = phba->sli4_hba.MQDBregaddr;
  2439. break;
  2440. case LPFC_DRB_WQ:
  2441. drb_reg = phba->sli4_hba.WQDBregaddr;
  2442. break;
  2443. case LPFC_DRB_RQ:
  2444. drb_reg = phba->sli4_hba.RQDBregaddr;
  2445. break;
  2446. default:
  2447. goto error_out;
  2448. }
  2449. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR)
  2450. reg_val = value;
  2451. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) {
  2452. reg_val = readl(drb_reg);
  2453. reg_val |= value;
  2454. }
  2455. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) {
  2456. reg_val = readl(drb_reg);
  2457. reg_val &= ~value;
  2458. }
  2459. writel(reg_val, drb_reg);
  2460. readl(drb_reg); /* flush */
  2461. }
  2462. return nbytes;
  2463. error_out:
  2464. /* Clean out command structure on command error out */
  2465. memset(&idiag, 0, sizeof(idiag));
  2466. return -EINVAL;
  2467. }
  2468. /**
  2469. * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers
  2470. * @phba: The pointer to hba structure.
  2471. * @pbuffer: The pointer to the buffer to copy the data to.
  2472. * @len: The lenght of bytes to copied.
  2473. * @drbregid: The id to doorbell registers.
  2474. *
  2475. * Description:
  2476. * This routine reads a control register and copies its content to the
  2477. * user buffer pointed to by @pbuffer.
  2478. *
  2479. * Returns:
  2480. * This function returns the amount of data that was copied into @pbuffer.
  2481. **/
  2482. static int
  2483. lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer,
  2484. int len, uint32_t ctlregid)
  2485. {
  2486. if (!pbuffer)
  2487. return 0;
  2488. switch (ctlregid) {
  2489. case LPFC_CTL_PORT_SEM:
  2490. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2491. "Port SemReg: 0x%08x\n",
  2492. readl(phba->sli4_hba.conf_regs_memmap_p +
  2493. LPFC_CTL_PORT_SEM_OFFSET));
  2494. break;
  2495. case LPFC_CTL_PORT_STA:
  2496. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2497. "Port StaReg: 0x%08x\n",
  2498. readl(phba->sli4_hba.conf_regs_memmap_p +
  2499. LPFC_CTL_PORT_STA_OFFSET));
  2500. break;
  2501. case LPFC_CTL_PORT_CTL:
  2502. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2503. "Port CtlReg: 0x%08x\n",
  2504. readl(phba->sli4_hba.conf_regs_memmap_p +
  2505. LPFC_CTL_PORT_CTL_OFFSET));
  2506. break;
  2507. case LPFC_CTL_PORT_ER1:
  2508. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2509. "Port Er1Reg: 0x%08x\n",
  2510. readl(phba->sli4_hba.conf_regs_memmap_p +
  2511. LPFC_CTL_PORT_ER1_OFFSET));
  2512. break;
  2513. case LPFC_CTL_PORT_ER2:
  2514. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2515. "Port Er2Reg: 0x%08x\n",
  2516. readl(phba->sli4_hba.conf_regs_memmap_p +
  2517. LPFC_CTL_PORT_ER2_OFFSET));
  2518. break;
  2519. case LPFC_CTL_PDEV_CTL:
  2520. len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len,
  2521. "PDev CtlReg: 0x%08x\n",
  2522. readl(phba->sli4_hba.conf_regs_memmap_p +
  2523. LPFC_CTL_PDEV_CTL_OFFSET));
  2524. break;
  2525. default:
  2526. break;
  2527. }
  2528. return len;
  2529. }
  2530. /**
  2531. * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register
  2532. * @file: The file pointer to read from.
  2533. * @buf: The buffer to copy the data to.
  2534. * @nbytes: The number of bytes to read.
  2535. * @ppos: The position in the file to start reading from.
  2536. *
  2537. * Description:
  2538. * This routine reads data from the @phba port and device registers according
  2539. * to the idiag command, and copies to user @buf.
  2540. *
  2541. * Returns:
  2542. * This function returns the amount of data that was read (this could be less
  2543. * than @nbytes if the end of the file was reached) or a negative error value.
  2544. **/
  2545. static ssize_t
  2546. lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes,
  2547. loff_t *ppos)
  2548. {
  2549. struct lpfc_debug *debug = file->private_data;
  2550. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2551. uint32_t ctl_reg_id, i;
  2552. char *pbuffer;
  2553. int len = 0;
  2554. /* This is a user read operation */
  2555. debug->op = LPFC_IDIAG_OP_RD;
  2556. if (!debug->buffer)
  2557. debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL);
  2558. if (!debug->buffer)
  2559. return 0;
  2560. pbuffer = debug->buffer;
  2561. if (*ppos)
  2562. return 0;
  2563. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD)
  2564. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  2565. else
  2566. return 0;
  2567. if (ctl_reg_id == LPFC_CTL_ACC_ALL)
  2568. for (i = 1; i <= LPFC_CTL_MAX; i++)
  2569. len = lpfc_idiag_ctlacc_read_reg(phba,
  2570. pbuffer, len, i);
  2571. else
  2572. len = lpfc_idiag_ctlacc_read_reg(phba,
  2573. pbuffer, len, ctl_reg_id);
  2574. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2575. }
  2576. /**
  2577. * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands
  2578. * @file: The file pointer to read from.
  2579. * @buf: The buffer to copy the user data from.
  2580. * @nbytes: The number of bytes to get.
  2581. * @ppos: The position in the file to start reading from.
  2582. *
  2583. * This routine get the debugfs idiag command struct from user space and then
  2584. * perform the syntax check for port and device control register read (dump)
  2585. * or write (set) command accordingly.
  2586. *
  2587. * It returns the @nbytges passing in from debugfs user space when successful.
  2588. * In case of error conditions, it returns proper error code back to the user
  2589. * space.
  2590. **/
  2591. static ssize_t
  2592. lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf,
  2593. size_t nbytes, loff_t *ppos)
  2594. {
  2595. struct lpfc_debug *debug = file->private_data;
  2596. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2597. uint32_t ctl_reg_id, value, reg_val = 0;
  2598. void __iomem *ctl_reg;
  2599. int rc;
  2600. /* This is a user write operation */
  2601. debug->op = LPFC_IDIAG_OP_WR;
  2602. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2603. if (rc < 0)
  2604. return rc;
  2605. /* Sanity check on command line arguments */
  2606. ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX];
  2607. value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX];
  2608. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  2609. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  2610. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2611. if (rc != LPFC_CTL_ACC_WR_CMD_ARG)
  2612. goto error_out;
  2613. if (ctl_reg_id > LPFC_CTL_MAX)
  2614. goto error_out;
  2615. } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) {
  2616. if (rc != LPFC_CTL_ACC_RD_CMD_ARG)
  2617. goto error_out;
  2618. if ((ctl_reg_id > LPFC_CTL_MAX) &&
  2619. (ctl_reg_id != LPFC_CTL_ACC_ALL))
  2620. goto error_out;
  2621. } else
  2622. goto error_out;
  2623. /* Perform the write access operation */
  2624. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR ||
  2625. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST ||
  2626. idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2627. switch (ctl_reg_id) {
  2628. case LPFC_CTL_PORT_SEM:
  2629. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2630. LPFC_CTL_PORT_SEM_OFFSET;
  2631. break;
  2632. case LPFC_CTL_PORT_STA:
  2633. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2634. LPFC_CTL_PORT_STA_OFFSET;
  2635. break;
  2636. case LPFC_CTL_PORT_CTL:
  2637. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2638. LPFC_CTL_PORT_CTL_OFFSET;
  2639. break;
  2640. case LPFC_CTL_PORT_ER1:
  2641. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2642. LPFC_CTL_PORT_ER1_OFFSET;
  2643. break;
  2644. case LPFC_CTL_PORT_ER2:
  2645. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2646. LPFC_CTL_PORT_ER2_OFFSET;
  2647. break;
  2648. case LPFC_CTL_PDEV_CTL:
  2649. ctl_reg = phba->sli4_hba.conf_regs_memmap_p +
  2650. LPFC_CTL_PDEV_CTL_OFFSET;
  2651. break;
  2652. default:
  2653. goto error_out;
  2654. }
  2655. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR)
  2656. reg_val = value;
  2657. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) {
  2658. reg_val = readl(ctl_reg);
  2659. reg_val |= value;
  2660. }
  2661. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) {
  2662. reg_val = readl(ctl_reg);
  2663. reg_val &= ~value;
  2664. }
  2665. writel(reg_val, ctl_reg);
  2666. readl(ctl_reg); /* flush */
  2667. }
  2668. return nbytes;
  2669. error_out:
  2670. /* Clean out command structure on command error out */
  2671. memset(&idiag, 0, sizeof(idiag));
  2672. return -EINVAL;
  2673. }
  2674. /**
  2675. * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup
  2676. * @phba: Pointer to HBA context object.
  2677. * @pbuffer: Pointer to data buffer.
  2678. *
  2679. * Description:
  2680. * This routine gets the driver mailbox access debugfs setup information.
  2681. *
  2682. * Returns:
  2683. * This function returns the amount of data that was read (this could be less
  2684. * than @nbytes if the end of the file was reached) or a negative error value.
  2685. **/
  2686. static int
  2687. lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer)
  2688. {
  2689. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  2690. int len = 0;
  2691. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  2692. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  2693. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  2694. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  2695. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2696. "mbx_dump_map: 0x%08x\n", mbx_dump_map);
  2697. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2698. "mbx_dump_cnt: %04d\n", mbx_dump_cnt);
  2699. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2700. "mbx_word_cnt: %04d\n", mbx_word_cnt);
  2701. len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len,
  2702. "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd);
  2703. return len;
  2704. }
  2705. /**
  2706. * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access
  2707. * @file: The file pointer to read from.
  2708. * @buf: The buffer to copy the data to.
  2709. * @nbytes: The number of bytes to read.
  2710. * @ppos: The position in the file to start reading from.
  2711. *
  2712. * Description:
  2713. * This routine reads data from the @phba driver mailbox access debugfs setup
  2714. * information.
  2715. *
  2716. * Returns:
  2717. * This function returns the amount of data that was read (this could be less
  2718. * than @nbytes if the end of the file was reached) or a negative error value.
  2719. **/
  2720. static ssize_t
  2721. lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes,
  2722. loff_t *ppos)
  2723. {
  2724. struct lpfc_debug *debug = file->private_data;
  2725. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  2726. char *pbuffer;
  2727. int len = 0;
  2728. /* This is a user read operation */
  2729. debug->op = LPFC_IDIAG_OP_RD;
  2730. if (!debug->buffer)
  2731. debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL);
  2732. if (!debug->buffer)
  2733. return 0;
  2734. pbuffer = debug->buffer;
  2735. if (*ppos)
  2736. return 0;
  2737. if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) &&
  2738. (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP))
  2739. return 0;
  2740. len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer);
  2741. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  2742. }
  2743. /**
  2744. * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands
  2745. * @file: The file pointer to read from.
  2746. * @buf: The buffer to copy the user data from.
  2747. * @nbytes: The number of bytes to get.
  2748. * @ppos: The position in the file to start reading from.
  2749. *
  2750. * This routine get the debugfs idiag command struct from user space and then
  2751. * perform the syntax check for driver mailbox command (dump) and sets up the
  2752. * necessary states in the idiag command struct accordingly.
  2753. *
  2754. * It returns the @nbytges passing in from debugfs user space when successful.
  2755. * In case of error conditions, it returns proper error code back to the user
  2756. * space.
  2757. **/
  2758. static ssize_t
  2759. lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf,
  2760. size_t nbytes, loff_t *ppos)
  2761. {
  2762. struct lpfc_debug *debug = file->private_data;
  2763. uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd;
  2764. int rc;
  2765. /* This is a user write operation */
  2766. debug->op = LPFC_IDIAG_OP_WR;
  2767. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  2768. if (rc < 0)
  2769. return rc;
  2770. /* Sanity check on command line arguments */
  2771. mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  2772. mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  2773. mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  2774. mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  2775. if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) {
  2776. if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL))
  2777. goto error_out;
  2778. if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) &&
  2779. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  2780. goto error_out;
  2781. if (mbx_word_cnt > sizeof(MAILBOX_t))
  2782. goto error_out;
  2783. } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) {
  2784. if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL))
  2785. goto error_out;
  2786. if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) &&
  2787. (mbx_dump_map != LPFC_MBX_DMP_ALL))
  2788. goto error_out;
  2789. if (mbx_word_cnt > (BSG_MBOX_SIZE)/4)
  2790. goto error_out;
  2791. if (mbx_mbox_cmd != 0x9b)
  2792. goto error_out;
  2793. } else
  2794. goto error_out;
  2795. if (mbx_word_cnt == 0)
  2796. goto error_out;
  2797. if (rc != LPFC_MBX_DMP_ARG)
  2798. goto error_out;
  2799. if (mbx_mbox_cmd & ~0xff)
  2800. goto error_out;
  2801. /* condition for stop mailbox dump */
  2802. if (mbx_dump_cnt == 0)
  2803. goto reset_out;
  2804. return nbytes;
  2805. reset_out:
  2806. /* Clean out command structure on command error out */
  2807. memset(&idiag, 0, sizeof(idiag));
  2808. return nbytes;
  2809. error_out:
  2810. /* Clean out command structure on command error out */
  2811. memset(&idiag, 0, sizeof(idiag));
  2812. return -EINVAL;
  2813. }
  2814. /**
  2815. * lpfc_idiag_extacc_avail_get - get the available extents information
  2816. * @phba: pointer to lpfc hba data structure.
  2817. * @pbuffer: pointer to internal buffer.
  2818. * @len: length into the internal buffer data has been copied.
  2819. *
  2820. * Description:
  2821. * This routine is to get the available extent information.
  2822. *
  2823. * Returns:
  2824. * overall lenth of the data read into the internal buffer.
  2825. **/
  2826. static int
  2827. lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len)
  2828. {
  2829. uint16_t ext_cnt, ext_size;
  2830. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2831. "\nAvailable Extents Information:\n");
  2832. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2833. "\tPort Available VPI extents: ");
  2834. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI,
  2835. &ext_cnt, &ext_size);
  2836. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2837. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2838. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2839. "\tPort Available VFI extents: ");
  2840. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI,
  2841. &ext_cnt, &ext_size);
  2842. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2843. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2844. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2845. "\tPort Available RPI extents: ");
  2846. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI,
  2847. &ext_cnt, &ext_size);
  2848. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2849. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2850. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2851. "\tPort Available XRI extents: ");
  2852. lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI,
  2853. &ext_cnt, &ext_size);
  2854. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2855. "Count %3d, Size %3d\n", ext_cnt, ext_size);
  2856. return len;
  2857. }
  2858. /**
  2859. * lpfc_idiag_extacc_alloc_get - get the allocated extents information
  2860. * @phba: pointer to lpfc hba data structure.
  2861. * @pbuffer: pointer to internal buffer.
  2862. * @len: length into the internal buffer data has been copied.
  2863. *
  2864. * Description:
  2865. * This routine is to get the allocated extent information.
  2866. *
  2867. * Returns:
  2868. * overall lenth of the data read into the internal buffer.
  2869. **/
  2870. static int
  2871. lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len)
  2872. {
  2873. uint16_t ext_cnt, ext_size;
  2874. int rc;
  2875. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2876. "\nAllocated Extents Information:\n");
  2877. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2878. "\tHost Allocated VPI extents: ");
  2879. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI,
  2880. &ext_cnt, &ext_size);
  2881. if (!rc)
  2882. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2883. "Port %d Extent %3d, Size %3d\n",
  2884. phba->brd_no, ext_cnt, ext_size);
  2885. else
  2886. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2887. "N/A\n");
  2888. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2889. "\tHost Allocated VFI extents: ");
  2890. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI,
  2891. &ext_cnt, &ext_size);
  2892. if (!rc)
  2893. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2894. "Port %d Extent %3d, Size %3d\n",
  2895. phba->brd_no, ext_cnt, ext_size);
  2896. else
  2897. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2898. "N/A\n");
  2899. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2900. "\tHost Allocated RPI extents: ");
  2901. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI,
  2902. &ext_cnt, &ext_size);
  2903. if (!rc)
  2904. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2905. "Port %d Extent %3d, Size %3d\n",
  2906. phba->brd_no, ext_cnt, ext_size);
  2907. else
  2908. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2909. "N/A\n");
  2910. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2911. "\tHost Allocated XRI extents: ");
  2912. rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI,
  2913. &ext_cnt, &ext_size);
  2914. if (!rc)
  2915. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2916. "Port %d Extent %3d, Size %3d\n",
  2917. phba->brd_no, ext_cnt, ext_size);
  2918. else
  2919. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2920. "N/A\n");
  2921. return len;
  2922. }
  2923. /**
  2924. * lpfc_idiag_extacc_drivr_get - get driver extent information
  2925. * @phba: pointer to lpfc hba data structure.
  2926. * @pbuffer: pointer to internal buffer.
  2927. * @len: length into the internal buffer data has been copied.
  2928. *
  2929. * Description:
  2930. * This routine is to get the driver extent information.
  2931. *
  2932. * Returns:
  2933. * overall lenth of the data read into the internal buffer.
  2934. **/
  2935. static int
  2936. lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len)
  2937. {
  2938. struct lpfc_rsrc_blks *rsrc_blks;
  2939. int index;
  2940. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2941. "\nDriver Extents Information:\n");
  2942. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2943. "\tVPI extents:\n");
  2944. index = 0;
  2945. list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) {
  2946. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2947. "\t\tBlock %3d: Start %4d, Count %4d\n",
  2948. index, rsrc_blks->rsrc_start,
  2949. rsrc_blks->rsrc_size);
  2950. index++;
  2951. }
  2952. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2953. "\tVFI extents:\n");
  2954. index = 0;
  2955. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list,
  2956. list) {
  2957. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2958. "\t\tBlock %3d: Start %4d, Count %4d\n",
  2959. index, rsrc_blks->rsrc_start,
  2960. rsrc_blks->rsrc_size);
  2961. index++;
  2962. }
  2963. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2964. "\tRPI extents:\n");
  2965. index = 0;
  2966. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list,
  2967. list) {
  2968. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2969. "\t\tBlock %3d: Start %4d, Count %4d\n",
  2970. index, rsrc_blks->rsrc_start,
  2971. rsrc_blks->rsrc_size);
  2972. index++;
  2973. }
  2974. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2975. "\tXRI extents:\n");
  2976. index = 0;
  2977. list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list,
  2978. list) {
  2979. len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len,
  2980. "\t\tBlock %3d: Start %4d, Count %4d\n",
  2981. index, rsrc_blks->rsrc_start,
  2982. rsrc_blks->rsrc_size);
  2983. index++;
  2984. }
  2985. return len;
  2986. }
  2987. /**
  2988. * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands
  2989. * @file: The file pointer to read from.
  2990. * @buf: The buffer to copy the user data from.
  2991. * @nbytes: The number of bytes to get.
  2992. * @ppos: The position in the file to start reading from.
  2993. *
  2994. * This routine get the debugfs idiag command struct from user space and then
  2995. * perform the syntax check for extent information access commands and sets
  2996. * up the necessary states in the idiag command struct accordingly.
  2997. *
  2998. * It returns the @nbytges passing in from debugfs user space when successful.
  2999. * In case of error conditions, it returns proper error code back to the user
  3000. * space.
  3001. **/
  3002. static ssize_t
  3003. lpfc_idiag_extacc_write(struct file *file, const char __user *buf,
  3004. size_t nbytes, loff_t *ppos)
  3005. {
  3006. struct lpfc_debug *debug = file->private_data;
  3007. uint32_t ext_map;
  3008. int rc;
  3009. /* This is a user write operation */
  3010. debug->op = LPFC_IDIAG_OP_WR;
  3011. rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd);
  3012. if (rc < 0)
  3013. return rc;
  3014. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  3015. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  3016. goto error_out;
  3017. if (rc != LPFC_EXT_ACC_CMD_ARG)
  3018. goto error_out;
  3019. if (!(ext_map & LPFC_EXT_ACC_ALL))
  3020. goto error_out;
  3021. return nbytes;
  3022. error_out:
  3023. /* Clean out command structure on command error out */
  3024. memset(&idiag, 0, sizeof(idiag));
  3025. return -EINVAL;
  3026. }
  3027. /**
  3028. * lpfc_idiag_extacc_read - idiag debugfs read access to extent information
  3029. * @file: The file pointer to read from.
  3030. * @buf: The buffer to copy the data to.
  3031. * @nbytes: The number of bytes to read.
  3032. * @ppos: The position in the file to start reading from.
  3033. *
  3034. * Description:
  3035. * This routine reads data from the proper extent information according to
  3036. * the idiag command, and copies to user @buf.
  3037. *
  3038. * Returns:
  3039. * This function returns the amount of data that was read (this could be less
  3040. * than @nbytes if the end of the file was reached) or a negative error value.
  3041. **/
  3042. static ssize_t
  3043. lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes,
  3044. loff_t *ppos)
  3045. {
  3046. struct lpfc_debug *debug = file->private_data;
  3047. struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private;
  3048. char *pbuffer;
  3049. uint32_t ext_map;
  3050. int len = 0;
  3051. /* This is a user read operation */
  3052. debug->op = LPFC_IDIAG_OP_RD;
  3053. if (!debug->buffer)
  3054. debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL);
  3055. if (!debug->buffer)
  3056. return 0;
  3057. pbuffer = debug->buffer;
  3058. if (*ppos)
  3059. return 0;
  3060. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD)
  3061. return 0;
  3062. ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX];
  3063. if (ext_map & LPFC_EXT_ACC_AVAIL)
  3064. len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len);
  3065. if (ext_map & LPFC_EXT_ACC_ALLOC)
  3066. len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len);
  3067. if (ext_map & LPFC_EXT_ACC_DRIVR)
  3068. len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len);
  3069. return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len);
  3070. }
  3071. #undef lpfc_debugfs_op_disc_trc
  3072. static const struct file_operations lpfc_debugfs_op_disc_trc = {
  3073. .owner = THIS_MODULE,
  3074. .open = lpfc_debugfs_disc_trc_open,
  3075. .llseek = lpfc_debugfs_lseek,
  3076. .read = lpfc_debugfs_read,
  3077. .release = lpfc_debugfs_release,
  3078. };
  3079. #undef lpfc_debugfs_op_nodelist
  3080. static const struct file_operations lpfc_debugfs_op_nodelist = {
  3081. .owner = THIS_MODULE,
  3082. .open = lpfc_debugfs_nodelist_open,
  3083. .llseek = lpfc_debugfs_lseek,
  3084. .read = lpfc_debugfs_read,
  3085. .release = lpfc_debugfs_release,
  3086. };
  3087. #undef lpfc_debugfs_op_hbqinfo
  3088. static const struct file_operations lpfc_debugfs_op_hbqinfo = {
  3089. .owner = THIS_MODULE,
  3090. .open = lpfc_debugfs_hbqinfo_open,
  3091. .llseek = lpfc_debugfs_lseek,
  3092. .read = lpfc_debugfs_read,
  3093. .release = lpfc_debugfs_release,
  3094. };
  3095. #undef lpfc_debugfs_op_dumpHBASlim
  3096. static const struct file_operations lpfc_debugfs_op_dumpHBASlim = {
  3097. .owner = THIS_MODULE,
  3098. .open = lpfc_debugfs_dumpHBASlim_open,
  3099. .llseek = lpfc_debugfs_lseek,
  3100. .read = lpfc_debugfs_read,
  3101. .release = lpfc_debugfs_release,
  3102. };
  3103. #undef lpfc_debugfs_op_dumpHostSlim
  3104. static const struct file_operations lpfc_debugfs_op_dumpHostSlim = {
  3105. .owner = THIS_MODULE,
  3106. .open = lpfc_debugfs_dumpHostSlim_open,
  3107. .llseek = lpfc_debugfs_lseek,
  3108. .read = lpfc_debugfs_read,
  3109. .release = lpfc_debugfs_release,
  3110. };
  3111. #undef lpfc_debugfs_op_dumpData
  3112. static const struct file_operations lpfc_debugfs_op_dumpData = {
  3113. .owner = THIS_MODULE,
  3114. .open = lpfc_debugfs_dumpData_open,
  3115. .llseek = lpfc_debugfs_lseek,
  3116. .read = lpfc_debugfs_read,
  3117. .write = lpfc_debugfs_dumpDataDif_write,
  3118. .release = lpfc_debugfs_dumpDataDif_release,
  3119. };
  3120. #undef lpfc_debugfs_op_dumpDif
  3121. static const struct file_operations lpfc_debugfs_op_dumpDif = {
  3122. .owner = THIS_MODULE,
  3123. .open = lpfc_debugfs_dumpDif_open,
  3124. .llseek = lpfc_debugfs_lseek,
  3125. .read = lpfc_debugfs_read,
  3126. .write = lpfc_debugfs_dumpDataDif_write,
  3127. .release = lpfc_debugfs_dumpDataDif_release,
  3128. };
  3129. #undef lpfc_debugfs_op_dif_err
  3130. static const struct file_operations lpfc_debugfs_op_dif_err = {
  3131. .owner = THIS_MODULE,
  3132. .open = lpfc_debugfs_dif_err_open,
  3133. .llseek = lpfc_debugfs_lseek,
  3134. .read = lpfc_debugfs_dif_err_read,
  3135. .write = lpfc_debugfs_dif_err_write,
  3136. .release = lpfc_debugfs_dif_err_release,
  3137. };
  3138. #undef lpfc_debugfs_op_slow_ring_trc
  3139. static const struct file_operations lpfc_debugfs_op_slow_ring_trc = {
  3140. .owner = THIS_MODULE,
  3141. .open = lpfc_debugfs_slow_ring_trc_open,
  3142. .llseek = lpfc_debugfs_lseek,
  3143. .read = lpfc_debugfs_read,
  3144. .release = lpfc_debugfs_release,
  3145. };
  3146. static struct dentry *lpfc_debugfs_root = NULL;
  3147. static atomic_t lpfc_debugfs_hba_count;
  3148. /*
  3149. * File operations for the iDiag debugfs
  3150. */
  3151. #undef lpfc_idiag_op_pciCfg
  3152. static const struct file_operations lpfc_idiag_op_pciCfg = {
  3153. .owner = THIS_MODULE,
  3154. .open = lpfc_idiag_open,
  3155. .llseek = lpfc_debugfs_lseek,
  3156. .read = lpfc_idiag_pcicfg_read,
  3157. .write = lpfc_idiag_pcicfg_write,
  3158. .release = lpfc_idiag_cmd_release,
  3159. };
  3160. #undef lpfc_idiag_op_barAcc
  3161. static const struct file_operations lpfc_idiag_op_barAcc = {
  3162. .owner = THIS_MODULE,
  3163. .open = lpfc_idiag_open,
  3164. .llseek = lpfc_debugfs_lseek,
  3165. .read = lpfc_idiag_baracc_read,
  3166. .write = lpfc_idiag_baracc_write,
  3167. .release = lpfc_idiag_cmd_release,
  3168. };
  3169. #undef lpfc_idiag_op_queInfo
  3170. static const struct file_operations lpfc_idiag_op_queInfo = {
  3171. .owner = THIS_MODULE,
  3172. .open = lpfc_idiag_open,
  3173. .read = lpfc_idiag_queinfo_read,
  3174. .release = lpfc_idiag_release,
  3175. };
  3176. #undef lpfc_idiag_op_queAcc
  3177. static const struct file_operations lpfc_idiag_op_queAcc = {
  3178. .owner = THIS_MODULE,
  3179. .open = lpfc_idiag_open,
  3180. .llseek = lpfc_debugfs_lseek,
  3181. .read = lpfc_idiag_queacc_read,
  3182. .write = lpfc_idiag_queacc_write,
  3183. .release = lpfc_idiag_cmd_release,
  3184. };
  3185. #undef lpfc_idiag_op_drbAcc
  3186. static const struct file_operations lpfc_idiag_op_drbAcc = {
  3187. .owner = THIS_MODULE,
  3188. .open = lpfc_idiag_open,
  3189. .llseek = lpfc_debugfs_lseek,
  3190. .read = lpfc_idiag_drbacc_read,
  3191. .write = lpfc_idiag_drbacc_write,
  3192. .release = lpfc_idiag_cmd_release,
  3193. };
  3194. #undef lpfc_idiag_op_ctlAcc
  3195. static const struct file_operations lpfc_idiag_op_ctlAcc = {
  3196. .owner = THIS_MODULE,
  3197. .open = lpfc_idiag_open,
  3198. .llseek = lpfc_debugfs_lseek,
  3199. .read = lpfc_idiag_ctlacc_read,
  3200. .write = lpfc_idiag_ctlacc_write,
  3201. .release = lpfc_idiag_cmd_release,
  3202. };
  3203. #undef lpfc_idiag_op_mbxAcc
  3204. static const struct file_operations lpfc_idiag_op_mbxAcc = {
  3205. .owner = THIS_MODULE,
  3206. .open = lpfc_idiag_open,
  3207. .llseek = lpfc_debugfs_lseek,
  3208. .read = lpfc_idiag_mbxacc_read,
  3209. .write = lpfc_idiag_mbxacc_write,
  3210. .release = lpfc_idiag_cmd_release,
  3211. };
  3212. #undef lpfc_idiag_op_extAcc
  3213. static const struct file_operations lpfc_idiag_op_extAcc = {
  3214. .owner = THIS_MODULE,
  3215. .open = lpfc_idiag_open,
  3216. .llseek = lpfc_debugfs_lseek,
  3217. .read = lpfc_idiag_extacc_read,
  3218. .write = lpfc_idiag_extacc_write,
  3219. .release = lpfc_idiag_cmd_release,
  3220. };
  3221. #endif
  3222. /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command
  3223. * @phba: Pointer to HBA context object.
  3224. * @dmabuf: Pointer to a DMA buffer descriptor.
  3225. *
  3226. * Description:
  3227. * This routine dump a bsg pass-through non-embedded mailbox command with
  3228. * external buffer.
  3229. **/
  3230. void
  3231. lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp,
  3232. enum mbox_type mbox_tp, enum dma_type dma_tp,
  3233. enum sta_type sta_tp,
  3234. struct lpfc_dmabuf *dmabuf, uint32_t ext_buf)
  3235. {
  3236. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3237. uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt;
  3238. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  3239. int len = 0;
  3240. uint32_t do_dump = 0;
  3241. uint32_t *pword;
  3242. uint32_t i;
  3243. if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)
  3244. return;
  3245. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  3246. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  3247. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  3248. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  3249. if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) ||
  3250. (*mbx_dump_cnt == 0) ||
  3251. (*mbx_word_cnt == 0))
  3252. return;
  3253. if (*mbx_mbox_cmd != 0x9B)
  3254. return;
  3255. if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) {
  3256. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) {
  3257. do_dump |= LPFC_BSG_DMP_MBX_RD_MBX;
  3258. printk(KERN_ERR "\nRead mbox command (x%x), "
  3259. "nemb:0x%x, extbuf_cnt:%d:\n",
  3260. sta_tp, nemb_tp, ext_buf);
  3261. }
  3262. }
  3263. if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) {
  3264. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) {
  3265. do_dump |= LPFC_BSG_DMP_MBX_RD_BUF;
  3266. printk(KERN_ERR "\nRead mbox buffer (x%x), "
  3267. "nemb:0x%x, extbuf_seq:%d:\n",
  3268. sta_tp, nemb_tp, ext_buf);
  3269. }
  3270. }
  3271. if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) {
  3272. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) {
  3273. do_dump |= LPFC_BSG_DMP_MBX_WR_MBX;
  3274. printk(KERN_ERR "\nWrite mbox command (x%x), "
  3275. "nemb:0x%x, extbuf_cnt:%d:\n",
  3276. sta_tp, nemb_tp, ext_buf);
  3277. }
  3278. }
  3279. if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) {
  3280. if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) {
  3281. do_dump |= LPFC_BSG_DMP_MBX_WR_BUF;
  3282. printk(KERN_ERR "\nWrite mbox buffer (x%x), "
  3283. "nemb:0x%x, extbuf_seq:%d:\n",
  3284. sta_tp, nemb_tp, ext_buf);
  3285. }
  3286. }
  3287. /* dump buffer content */
  3288. if (do_dump) {
  3289. pword = (uint32_t *)dmabuf->virt;
  3290. for (i = 0; i < *mbx_word_cnt; i++) {
  3291. if (!(i % 8)) {
  3292. if (i != 0)
  3293. printk(KERN_ERR "%s\n", line_buf);
  3294. len = 0;
  3295. len += snprintf(line_buf+len,
  3296. LPFC_MBX_ACC_LBUF_SZ-len,
  3297. "%03d: ", i);
  3298. }
  3299. len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  3300. "%08x ", (uint32_t)*pword);
  3301. pword++;
  3302. }
  3303. if ((i - 1) % 8)
  3304. printk(KERN_ERR "%s\n", line_buf);
  3305. (*mbx_dump_cnt)--;
  3306. }
  3307. /* Clean out command structure on reaching dump count */
  3308. if (*mbx_dump_cnt == 0)
  3309. memset(&idiag, 0, sizeof(idiag));
  3310. return;
  3311. #endif
  3312. }
  3313. /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command
  3314. * @phba: Pointer to HBA context object.
  3315. * @dmabuf: Pointer to a DMA buffer descriptor.
  3316. *
  3317. * Description:
  3318. * This routine dump a pass-through non-embedded mailbox command from issue
  3319. * mailbox command.
  3320. **/
  3321. void
  3322. lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox)
  3323. {
  3324. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3325. uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd;
  3326. char line_buf[LPFC_MBX_ACC_LBUF_SZ];
  3327. int len = 0;
  3328. uint32_t *pword;
  3329. uint8_t *pbyte;
  3330. uint32_t i, j;
  3331. if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP)
  3332. return;
  3333. mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX];
  3334. mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX];
  3335. mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX];
  3336. mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX];
  3337. if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) ||
  3338. (*mbx_dump_cnt == 0) ||
  3339. (*mbx_word_cnt == 0))
  3340. return;
  3341. if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) &&
  3342. (*mbx_mbox_cmd != pmbox->mbxCommand))
  3343. return;
  3344. /* dump buffer content */
  3345. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) {
  3346. printk(KERN_ERR "Mailbox command:0x%x dump by word:\n",
  3347. pmbox->mbxCommand);
  3348. pword = (uint32_t *)pmbox;
  3349. for (i = 0; i < *mbx_word_cnt; i++) {
  3350. if (!(i % 8)) {
  3351. if (i != 0)
  3352. printk(KERN_ERR "%s\n", line_buf);
  3353. len = 0;
  3354. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  3355. len += snprintf(line_buf+len,
  3356. LPFC_MBX_ACC_LBUF_SZ-len,
  3357. "%03d: ", i);
  3358. }
  3359. len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len,
  3360. "%08x ",
  3361. ((uint32_t)*pword) & 0xffffffff);
  3362. pword++;
  3363. }
  3364. if ((i - 1) % 8)
  3365. printk(KERN_ERR "%s\n", line_buf);
  3366. printk(KERN_ERR "\n");
  3367. }
  3368. if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) {
  3369. printk(KERN_ERR "Mailbox command:0x%x dump by byte:\n",
  3370. pmbox->mbxCommand);
  3371. pbyte = (uint8_t *)pmbox;
  3372. for (i = 0; i < *mbx_word_cnt; i++) {
  3373. if (!(i % 8)) {
  3374. if (i != 0)
  3375. printk(KERN_ERR "%s\n", line_buf);
  3376. len = 0;
  3377. memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ);
  3378. len += snprintf(line_buf+len,
  3379. LPFC_MBX_ACC_LBUF_SZ-len,
  3380. "%03d: ", i);
  3381. }
  3382. for (j = 0; j < 4; j++) {
  3383. len += snprintf(line_buf+len,
  3384. LPFC_MBX_ACC_LBUF_SZ-len,
  3385. "%02x",
  3386. ((uint8_t)*pbyte) & 0xff);
  3387. pbyte++;
  3388. }
  3389. len += snprintf(line_buf+len,
  3390. LPFC_MBX_ACC_LBUF_SZ-len, " ");
  3391. }
  3392. if ((i - 1) % 8)
  3393. printk(KERN_ERR "%s\n", line_buf);
  3394. printk(KERN_ERR "\n");
  3395. }
  3396. (*mbx_dump_cnt)--;
  3397. /* Clean out command structure on reaching dump count */
  3398. if (*mbx_dump_cnt == 0)
  3399. memset(&idiag, 0, sizeof(idiag));
  3400. return;
  3401. #endif
  3402. }
  3403. /**
  3404. * lpfc_debugfs_initialize - Initialize debugfs for a vport
  3405. * @vport: The vport pointer to initialize.
  3406. *
  3407. * Description:
  3408. * When Debugfs is configured this routine sets up the lpfc debugfs file system.
  3409. * If not already created, this routine will create the lpfc directory, and
  3410. * lpfcX directory (for this HBA), and vportX directory for this vport. It will
  3411. * also create each file used to access lpfc specific debugfs information.
  3412. **/
  3413. inline void
  3414. lpfc_debugfs_initialize(struct lpfc_vport *vport)
  3415. {
  3416. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3417. struct lpfc_hba *phba = vport->phba;
  3418. char name[64];
  3419. uint32_t num, i;
  3420. if (!lpfc_debugfs_enable)
  3421. return;
  3422. /* Setup lpfc root directory */
  3423. if (!lpfc_debugfs_root) {
  3424. lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL);
  3425. atomic_set(&lpfc_debugfs_hba_count, 0);
  3426. if (!lpfc_debugfs_root) {
  3427. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3428. "0408 Cannot create debugfs root\n");
  3429. goto debug_failed;
  3430. }
  3431. }
  3432. if (!lpfc_debugfs_start_time)
  3433. lpfc_debugfs_start_time = jiffies;
  3434. /* Setup funcX directory for specific HBA PCI function */
  3435. snprintf(name, sizeof(name), "fn%d", phba->brd_no);
  3436. if (!phba->hba_debugfs_root) {
  3437. phba->hba_debugfs_root =
  3438. debugfs_create_dir(name, lpfc_debugfs_root);
  3439. if (!phba->hba_debugfs_root) {
  3440. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3441. "0412 Cannot create debugfs hba\n");
  3442. goto debug_failed;
  3443. }
  3444. atomic_inc(&lpfc_debugfs_hba_count);
  3445. atomic_set(&phba->debugfs_vport_count, 0);
  3446. /* Setup hbqinfo */
  3447. snprintf(name, sizeof(name), "hbqinfo");
  3448. phba->debug_hbqinfo =
  3449. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3450. phba->hba_debugfs_root,
  3451. phba, &lpfc_debugfs_op_hbqinfo);
  3452. if (!phba->debug_hbqinfo) {
  3453. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3454. "0411 Cannot create debugfs hbqinfo\n");
  3455. goto debug_failed;
  3456. }
  3457. /* Setup dumpHBASlim */
  3458. if (phba->sli_rev < LPFC_SLI_REV4) {
  3459. snprintf(name, sizeof(name), "dumpHBASlim");
  3460. phba->debug_dumpHBASlim =
  3461. debugfs_create_file(name,
  3462. S_IFREG|S_IRUGO|S_IWUSR,
  3463. phba->hba_debugfs_root,
  3464. phba, &lpfc_debugfs_op_dumpHBASlim);
  3465. if (!phba->debug_dumpHBASlim) {
  3466. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3467. "0413 Cannot create debugfs "
  3468. "dumpHBASlim\n");
  3469. goto debug_failed;
  3470. }
  3471. } else
  3472. phba->debug_dumpHBASlim = NULL;
  3473. /* Setup dumpHostSlim */
  3474. if (phba->sli_rev < LPFC_SLI_REV4) {
  3475. snprintf(name, sizeof(name), "dumpHostSlim");
  3476. phba->debug_dumpHostSlim =
  3477. debugfs_create_file(name,
  3478. S_IFREG|S_IRUGO|S_IWUSR,
  3479. phba->hba_debugfs_root,
  3480. phba, &lpfc_debugfs_op_dumpHostSlim);
  3481. if (!phba->debug_dumpHostSlim) {
  3482. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3483. "0414 Cannot create debugfs "
  3484. "dumpHostSlim\n");
  3485. goto debug_failed;
  3486. }
  3487. } else
  3488. phba->debug_dumpHBASlim = NULL;
  3489. /* Setup dumpData */
  3490. snprintf(name, sizeof(name), "dumpData");
  3491. phba->debug_dumpData =
  3492. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3493. phba->hba_debugfs_root,
  3494. phba, &lpfc_debugfs_op_dumpData);
  3495. if (!phba->debug_dumpData) {
  3496. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3497. "0800 Cannot create debugfs dumpData\n");
  3498. goto debug_failed;
  3499. }
  3500. /* Setup dumpDif */
  3501. snprintf(name, sizeof(name), "dumpDif");
  3502. phba->debug_dumpDif =
  3503. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3504. phba->hba_debugfs_root,
  3505. phba, &lpfc_debugfs_op_dumpDif);
  3506. if (!phba->debug_dumpDif) {
  3507. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3508. "0801 Cannot create debugfs dumpDif\n");
  3509. goto debug_failed;
  3510. }
  3511. /* Setup DIF Error Injections */
  3512. snprintf(name, sizeof(name), "InjErrLBA");
  3513. phba->debug_InjErrLBA =
  3514. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3515. phba->hba_debugfs_root,
  3516. phba, &lpfc_debugfs_op_dif_err);
  3517. if (!phba->debug_InjErrLBA) {
  3518. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3519. "0807 Cannot create debugfs InjErrLBA\n");
  3520. goto debug_failed;
  3521. }
  3522. phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
  3523. snprintf(name, sizeof(name), "writeGuardInjErr");
  3524. phba->debug_writeGuard =
  3525. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3526. phba->hba_debugfs_root,
  3527. phba, &lpfc_debugfs_op_dif_err);
  3528. if (!phba->debug_writeGuard) {
  3529. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3530. "0802 Cannot create debugfs writeGuard\n");
  3531. goto debug_failed;
  3532. }
  3533. snprintf(name, sizeof(name), "writeAppInjErr");
  3534. phba->debug_writeApp =
  3535. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3536. phba->hba_debugfs_root,
  3537. phba, &lpfc_debugfs_op_dif_err);
  3538. if (!phba->debug_writeApp) {
  3539. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3540. "0803 Cannot create debugfs writeApp\n");
  3541. goto debug_failed;
  3542. }
  3543. snprintf(name, sizeof(name), "writeRefInjErr");
  3544. phba->debug_writeRef =
  3545. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3546. phba->hba_debugfs_root,
  3547. phba, &lpfc_debugfs_op_dif_err);
  3548. if (!phba->debug_writeRef) {
  3549. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3550. "0804 Cannot create debugfs writeRef\n");
  3551. goto debug_failed;
  3552. }
  3553. snprintf(name, sizeof(name), "readAppInjErr");
  3554. phba->debug_readApp =
  3555. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3556. phba->hba_debugfs_root,
  3557. phba, &lpfc_debugfs_op_dif_err);
  3558. if (!phba->debug_readApp) {
  3559. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3560. "0805 Cannot create debugfs readApp\n");
  3561. goto debug_failed;
  3562. }
  3563. snprintf(name, sizeof(name), "readRefInjErr");
  3564. phba->debug_readRef =
  3565. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3566. phba->hba_debugfs_root,
  3567. phba, &lpfc_debugfs_op_dif_err);
  3568. if (!phba->debug_readRef) {
  3569. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3570. "0806 Cannot create debugfs readApp\n");
  3571. goto debug_failed;
  3572. }
  3573. /* Setup slow ring trace */
  3574. if (lpfc_debugfs_max_slow_ring_trc) {
  3575. num = lpfc_debugfs_max_slow_ring_trc - 1;
  3576. if (num & lpfc_debugfs_max_slow_ring_trc) {
  3577. /* Change to be a power of 2 */
  3578. num = lpfc_debugfs_max_slow_ring_trc;
  3579. i = 0;
  3580. while (num > 1) {
  3581. num = num >> 1;
  3582. i++;
  3583. }
  3584. lpfc_debugfs_max_slow_ring_trc = (1 << i);
  3585. printk(KERN_ERR
  3586. "lpfc_debugfs_max_disc_trc changed to "
  3587. "%d\n", lpfc_debugfs_max_disc_trc);
  3588. }
  3589. }
  3590. snprintf(name, sizeof(name), "slow_ring_trace");
  3591. phba->debug_slow_ring_trc =
  3592. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3593. phba->hba_debugfs_root,
  3594. phba, &lpfc_debugfs_op_slow_ring_trc);
  3595. if (!phba->debug_slow_ring_trc) {
  3596. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3597. "0415 Cannot create debugfs "
  3598. "slow_ring_trace\n");
  3599. goto debug_failed;
  3600. }
  3601. if (!phba->slow_ring_trc) {
  3602. phba->slow_ring_trc = kmalloc(
  3603. (sizeof(struct lpfc_debugfs_trc) *
  3604. lpfc_debugfs_max_slow_ring_trc),
  3605. GFP_KERNEL);
  3606. if (!phba->slow_ring_trc) {
  3607. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3608. "0416 Cannot create debugfs "
  3609. "slow_ring buffer\n");
  3610. goto debug_failed;
  3611. }
  3612. atomic_set(&phba->slow_ring_trc_cnt, 0);
  3613. memset(phba->slow_ring_trc, 0,
  3614. (sizeof(struct lpfc_debugfs_trc) *
  3615. lpfc_debugfs_max_slow_ring_trc));
  3616. }
  3617. }
  3618. snprintf(name, sizeof(name), "vport%d", vport->vpi);
  3619. if (!vport->vport_debugfs_root) {
  3620. vport->vport_debugfs_root =
  3621. debugfs_create_dir(name, phba->hba_debugfs_root);
  3622. if (!vport->vport_debugfs_root) {
  3623. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3624. "0417 Can't create debugfs\n");
  3625. goto debug_failed;
  3626. }
  3627. atomic_inc(&phba->debugfs_vport_count);
  3628. }
  3629. if (lpfc_debugfs_max_disc_trc) {
  3630. num = lpfc_debugfs_max_disc_trc - 1;
  3631. if (num & lpfc_debugfs_max_disc_trc) {
  3632. /* Change to be a power of 2 */
  3633. num = lpfc_debugfs_max_disc_trc;
  3634. i = 0;
  3635. while (num > 1) {
  3636. num = num >> 1;
  3637. i++;
  3638. }
  3639. lpfc_debugfs_max_disc_trc = (1 << i);
  3640. printk(KERN_ERR
  3641. "lpfc_debugfs_max_disc_trc changed to %d\n",
  3642. lpfc_debugfs_max_disc_trc);
  3643. }
  3644. }
  3645. vport->disc_trc = kzalloc(
  3646. (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc),
  3647. GFP_KERNEL);
  3648. if (!vport->disc_trc) {
  3649. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3650. "0418 Cannot create debugfs disc trace "
  3651. "buffer\n");
  3652. goto debug_failed;
  3653. }
  3654. atomic_set(&vport->disc_trc_cnt, 0);
  3655. snprintf(name, sizeof(name), "discovery_trace");
  3656. vport->debug_disc_trc =
  3657. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3658. vport->vport_debugfs_root,
  3659. vport, &lpfc_debugfs_op_disc_trc);
  3660. if (!vport->debug_disc_trc) {
  3661. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3662. "0419 Cannot create debugfs "
  3663. "discovery_trace\n");
  3664. goto debug_failed;
  3665. }
  3666. snprintf(name, sizeof(name), "nodelist");
  3667. vport->debug_nodelist =
  3668. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3669. vport->vport_debugfs_root,
  3670. vport, &lpfc_debugfs_op_nodelist);
  3671. if (!vport->debug_nodelist) {
  3672. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3673. "2985 Can't create debugfs nodelist\n");
  3674. goto debug_failed;
  3675. }
  3676. /*
  3677. * iDiag debugfs root entry points for SLI4 device only
  3678. */
  3679. if (phba->sli_rev < LPFC_SLI_REV4)
  3680. goto debug_failed;
  3681. snprintf(name, sizeof(name), "iDiag");
  3682. if (!phba->idiag_root) {
  3683. phba->idiag_root =
  3684. debugfs_create_dir(name, phba->hba_debugfs_root);
  3685. if (!phba->idiag_root) {
  3686. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3687. "2922 Can't create idiag debugfs\n");
  3688. goto debug_failed;
  3689. }
  3690. /* Initialize iDiag data structure */
  3691. memset(&idiag, 0, sizeof(idiag));
  3692. }
  3693. /* iDiag read PCI config space */
  3694. snprintf(name, sizeof(name), "pciCfg");
  3695. if (!phba->idiag_pci_cfg) {
  3696. phba->idiag_pci_cfg =
  3697. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3698. phba->idiag_root, phba, &lpfc_idiag_op_pciCfg);
  3699. if (!phba->idiag_pci_cfg) {
  3700. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3701. "2923 Can't create idiag debugfs\n");
  3702. goto debug_failed;
  3703. }
  3704. idiag.offset.last_rd = 0;
  3705. }
  3706. /* iDiag PCI BAR access */
  3707. snprintf(name, sizeof(name), "barAcc");
  3708. if (!phba->idiag_bar_acc) {
  3709. phba->idiag_bar_acc =
  3710. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3711. phba->idiag_root, phba, &lpfc_idiag_op_barAcc);
  3712. if (!phba->idiag_bar_acc) {
  3713. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3714. "3056 Can't create idiag debugfs\n");
  3715. goto debug_failed;
  3716. }
  3717. idiag.offset.last_rd = 0;
  3718. }
  3719. /* iDiag get PCI function queue information */
  3720. snprintf(name, sizeof(name), "queInfo");
  3721. if (!phba->idiag_que_info) {
  3722. phba->idiag_que_info =
  3723. debugfs_create_file(name, S_IFREG|S_IRUGO,
  3724. phba->idiag_root, phba, &lpfc_idiag_op_queInfo);
  3725. if (!phba->idiag_que_info) {
  3726. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3727. "2924 Can't create idiag debugfs\n");
  3728. goto debug_failed;
  3729. }
  3730. }
  3731. /* iDiag access PCI function queue */
  3732. snprintf(name, sizeof(name), "queAcc");
  3733. if (!phba->idiag_que_acc) {
  3734. phba->idiag_que_acc =
  3735. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3736. phba->idiag_root, phba, &lpfc_idiag_op_queAcc);
  3737. if (!phba->idiag_que_acc) {
  3738. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3739. "2926 Can't create idiag debugfs\n");
  3740. goto debug_failed;
  3741. }
  3742. }
  3743. /* iDiag access PCI function doorbell registers */
  3744. snprintf(name, sizeof(name), "drbAcc");
  3745. if (!phba->idiag_drb_acc) {
  3746. phba->idiag_drb_acc =
  3747. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3748. phba->idiag_root, phba, &lpfc_idiag_op_drbAcc);
  3749. if (!phba->idiag_drb_acc) {
  3750. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3751. "2927 Can't create idiag debugfs\n");
  3752. goto debug_failed;
  3753. }
  3754. }
  3755. /* iDiag access PCI function control registers */
  3756. snprintf(name, sizeof(name), "ctlAcc");
  3757. if (!phba->idiag_ctl_acc) {
  3758. phba->idiag_ctl_acc =
  3759. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3760. phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc);
  3761. if (!phba->idiag_ctl_acc) {
  3762. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3763. "2981 Can't create idiag debugfs\n");
  3764. goto debug_failed;
  3765. }
  3766. }
  3767. /* iDiag access mbox commands */
  3768. snprintf(name, sizeof(name), "mbxAcc");
  3769. if (!phba->idiag_mbx_acc) {
  3770. phba->idiag_mbx_acc =
  3771. debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
  3772. phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc);
  3773. if (!phba->idiag_mbx_acc) {
  3774. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3775. "2980 Can't create idiag debugfs\n");
  3776. goto debug_failed;
  3777. }
  3778. }
  3779. /* iDiag extents access commands */
  3780. if (phba->sli4_hba.extents_in_use) {
  3781. snprintf(name, sizeof(name), "extAcc");
  3782. if (!phba->idiag_ext_acc) {
  3783. phba->idiag_ext_acc =
  3784. debugfs_create_file(name,
  3785. S_IFREG|S_IRUGO|S_IWUSR,
  3786. phba->idiag_root, phba,
  3787. &lpfc_idiag_op_extAcc);
  3788. if (!phba->idiag_ext_acc) {
  3789. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  3790. "2986 Cant create "
  3791. "idiag debugfs\n");
  3792. goto debug_failed;
  3793. }
  3794. }
  3795. }
  3796. debug_failed:
  3797. return;
  3798. #endif
  3799. }
  3800. /**
  3801. * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport
  3802. * @vport: The vport pointer to remove from debugfs.
  3803. *
  3804. * Description:
  3805. * When Debugfs is configured this routine removes debugfs file system elements
  3806. * that are specific to this vport. It also checks to see if there are any
  3807. * users left for the debugfs directories associated with the HBA and driver. If
  3808. * this is the last user of the HBA directory or driver directory then it will
  3809. * remove those from the debugfs infrastructure as well.
  3810. **/
  3811. inline void
  3812. lpfc_debugfs_terminate(struct lpfc_vport *vport)
  3813. {
  3814. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  3815. struct lpfc_hba *phba = vport->phba;
  3816. if (vport->disc_trc) {
  3817. kfree(vport->disc_trc);
  3818. vport->disc_trc = NULL;
  3819. }
  3820. if (vport->debug_disc_trc) {
  3821. debugfs_remove(vport->debug_disc_trc); /* discovery_trace */
  3822. vport->debug_disc_trc = NULL;
  3823. }
  3824. if (vport->debug_nodelist) {
  3825. debugfs_remove(vport->debug_nodelist); /* nodelist */
  3826. vport->debug_nodelist = NULL;
  3827. }
  3828. if (vport->vport_debugfs_root) {
  3829. debugfs_remove(vport->vport_debugfs_root); /* vportX */
  3830. vport->vport_debugfs_root = NULL;
  3831. atomic_dec(&phba->debugfs_vport_count);
  3832. }
  3833. if (atomic_read(&phba->debugfs_vport_count) == 0) {
  3834. if (phba->debug_hbqinfo) {
  3835. debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */
  3836. phba->debug_hbqinfo = NULL;
  3837. }
  3838. if (phba->debug_dumpHBASlim) {
  3839. debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */
  3840. phba->debug_dumpHBASlim = NULL;
  3841. }
  3842. if (phba->debug_dumpHostSlim) {
  3843. debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */
  3844. phba->debug_dumpHostSlim = NULL;
  3845. }
  3846. if (phba->debug_dumpData) {
  3847. debugfs_remove(phba->debug_dumpData); /* dumpData */
  3848. phba->debug_dumpData = NULL;
  3849. }
  3850. if (phba->debug_dumpDif) {
  3851. debugfs_remove(phba->debug_dumpDif); /* dumpDif */
  3852. phba->debug_dumpDif = NULL;
  3853. }
  3854. if (phba->debug_InjErrLBA) {
  3855. debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */
  3856. phba->debug_InjErrLBA = NULL;
  3857. }
  3858. if (phba->debug_writeGuard) {
  3859. debugfs_remove(phba->debug_writeGuard); /* writeGuard */
  3860. phba->debug_writeGuard = NULL;
  3861. }
  3862. if (phba->debug_writeApp) {
  3863. debugfs_remove(phba->debug_writeApp); /* writeApp */
  3864. phba->debug_writeApp = NULL;
  3865. }
  3866. if (phba->debug_writeRef) {
  3867. debugfs_remove(phba->debug_writeRef); /* writeRef */
  3868. phba->debug_writeRef = NULL;
  3869. }
  3870. if (phba->debug_readApp) {
  3871. debugfs_remove(phba->debug_readApp); /* readApp */
  3872. phba->debug_readApp = NULL;
  3873. }
  3874. if (phba->debug_readRef) {
  3875. debugfs_remove(phba->debug_readRef); /* readRef */
  3876. phba->debug_readRef = NULL;
  3877. }
  3878. if (phba->slow_ring_trc) {
  3879. kfree(phba->slow_ring_trc);
  3880. phba->slow_ring_trc = NULL;
  3881. }
  3882. if (phba->debug_slow_ring_trc) {
  3883. /* slow_ring_trace */
  3884. debugfs_remove(phba->debug_slow_ring_trc);
  3885. phba->debug_slow_ring_trc = NULL;
  3886. }
  3887. /*
  3888. * iDiag release
  3889. */
  3890. if (phba->sli_rev == LPFC_SLI_REV4) {
  3891. if (phba->idiag_ext_acc) {
  3892. /* iDiag extAcc */
  3893. debugfs_remove(phba->idiag_ext_acc);
  3894. phba->idiag_ext_acc = NULL;
  3895. }
  3896. if (phba->idiag_mbx_acc) {
  3897. /* iDiag mbxAcc */
  3898. debugfs_remove(phba->idiag_mbx_acc);
  3899. phba->idiag_mbx_acc = NULL;
  3900. }
  3901. if (phba->idiag_ctl_acc) {
  3902. /* iDiag ctlAcc */
  3903. debugfs_remove(phba->idiag_ctl_acc);
  3904. phba->idiag_ctl_acc = NULL;
  3905. }
  3906. if (phba->idiag_drb_acc) {
  3907. /* iDiag drbAcc */
  3908. debugfs_remove(phba->idiag_drb_acc);
  3909. phba->idiag_drb_acc = NULL;
  3910. }
  3911. if (phba->idiag_que_acc) {
  3912. /* iDiag queAcc */
  3913. debugfs_remove(phba->idiag_que_acc);
  3914. phba->idiag_que_acc = NULL;
  3915. }
  3916. if (phba->idiag_que_info) {
  3917. /* iDiag queInfo */
  3918. debugfs_remove(phba->idiag_que_info);
  3919. phba->idiag_que_info = NULL;
  3920. }
  3921. if (phba->idiag_bar_acc) {
  3922. /* iDiag barAcc */
  3923. debugfs_remove(phba->idiag_bar_acc);
  3924. phba->idiag_bar_acc = NULL;
  3925. }
  3926. if (phba->idiag_pci_cfg) {
  3927. /* iDiag pciCfg */
  3928. debugfs_remove(phba->idiag_pci_cfg);
  3929. phba->idiag_pci_cfg = NULL;
  3930. }
  3931. /* Finally remove the iDiag debugfs root */
  3932. if (phba->idiag_root) {
  3933. /* iDiag root */
  3934. debugfs_remove(phba->idiag_root);
  3935. phba->idiag_root = NULL;
  3936. }
  3937. }
  3938. if (phba->hba_debugfs_root) {
  3939. debugfs_remove(phba->hba_debugfs_root); /* fnX */
  3940. phba->hba_debugfs_root = NULL;
  3941. atomic_dec(&lpfc_debugfs_hba_count);
  3942. }
  3943. if (atomic_read(&lpfc_debugfs_hba_count) == 0) {
  3944. debugfs_remove(lpfc_debugfs_root); /* lpfc */
  3945. lpfc_debugfs_root = NULL;
  3946. }
  3947. }
  3948. #endif
  3949. return;
  3950. }