lpfc_debugfs.c 134 KB

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