lpfc_attr.c 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2011 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/ctype.h>
  22. #include <linux/delay.h>
  23. #include <linux/pci.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/aer.h>
  26. #include <linux/gfp.h>
  27. #include <linux/kernel.h>
  28. #include <scsi/scsi.h>
  29. #include <scsi/scsi_device.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_tcq.h>
  32. #include <scsi/scsi_transport_fc.h>
  33. #include <scsi/fc/fc_fs.h>
  34. #include "lpfc_hw4.h"
  35. #include "lpfc_hw.h"
  36. #include "lpfc_sli.h"
  37. #include "lpfc_sli4.h"
  38. #include "lpfc_nl.h"
  39. #include "lpfc_disc.h"
  40. #include "lpfc_scsi.h"
  41. #include "lpfc.h"
  42. #include "lpfc_logmsg.h"
  43. #include "lpfc_version.h"
  44. #include "lpfc_compat.h"
  45. #include "lpfc_crtn.h"
  46. #include "lpfc_vport.h"
  47. #define LPFC_DEF_DEVLOSS_TMO 30
  48. #define LPFC_MIN_DEVLOSS_TMO 1
  49. #define LPFC_MAX_DEVLOSS_TMO 255
  50. /**
  51. * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
  52. * @incr: integer to convert.
  53. * @hdw: ascii string holding converted integer plus a string terminator.
  54. *
  55. * Description:
  56. * JEDEC Joint Electron Device Engineering Council.
  57. * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
  58. * character string. The string is then terminated with a NULL in byte 9.
  59. * Hex 0-9 becomes ascii '0' to '9'.
  60. * Hex a-f becomes ascii '=' to 'B' capital B.
  61. *
  62. * Notes:
  63. * Coded for 32 bit integers only.
  64. **/
  65. static void
  66. lpfc_jedec_to_ascii(int incr, char hdw[])
  67. {
  68. int i, j;
  69. for (i = 0; i < 8; i++) {
  70. j = (incr & 0xf);
  71. if (j <= 9)
  72. hdw[7 - i] = 0x30 + j;
  73. else
  74. hdw[7 - i] = 0x61 + j - 10;
  75. incr = (incr >> 4);
  76. }
  77. hdw[8] = 0;
  78. return;
  79. }
  80. /**
  81. * lpfc_drvr_version_show - Return the Emulex driver string with version number
  82. * @dev: class unused variable.
  83. * @attr: device attribute, not used.
  84. * @buf: on return contains the module description text.
  85. *
  86. * Returns: size of formatted string.
  87. **/
  88. static ssize_t
  89. lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
  90. char *buf)
  91. {
  92. return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
  93. }
  94. /**
  95. * lpfc_enable_fip_show - Return the fip mode of the HBA
  96. * @dev: class unused variable.
  97. * @attr: device attribute, not used.
  98. * @buf: on return contains the module description text.
  99. *
  100. * Returns: size of formatted string.
  101. **/
  102. static ssize_t
  103. lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
  104. char *buf)
  105. {
  106. struct Scsi_Host *shost = class_to_shost(dev);
  107. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  108. struct lpfc_hba *phba = vport->phba;
  109. if (phba->hba_flag & HBA_FIP_SUPPORT)
  110. return snprintf(buf, PAGE_SIZE, "1\n");
  111. else
  112. return snprintf(buf, PAGE_SIZE, "0\n");
  113. }
  114. static ssize_t
  115. lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
  116. char *buf)
  117. {
  118. struct Scsi_Host *shost = class_to_shost(dev);
  119. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  120. struct lpfc_hba *phba = vport->phba;
  121. if (phba->cfg_enable_bg)
  122. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
  123. return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
  124. else
  125. return snprintf(buf, PAGE_SIZE,
  126. "BlockGuard Not Supported\n");
  127. else
  128. return snprintf(buf, PAGE_SIZE,
  129. "BlockGuard Disabled\n");
  130. }
  131. static ssize_t
  132. lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
  133. char *buf)
  134. {
  135. struct Scsi_Host *shost = class_to_shost(dev);
  136. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  137. struct lpfc_hba *phba = vport->phba;
  138. return snprintf(buf, PAGE_SIZE, "%llu\n",
  139. (unsigned long long)phba->bg_guard_err_cnt);
  140. }
  141. static ssize_t
  142. lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
  143. char *buf)
  144. {
  145. struct Scsi_Host *shost = class_to_shost(dev);
  146. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  147. struct lpfc_hba *phba = vport->phba;
  148. return snprintf(buf, PAGE_SIZE, "%llu\n",
  149. (unsigned long long)phba->bg_apptag_err_cnt);
  150. }
  151. static ssize_t
  152. lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
  153. char *buf)
  154. {
  155. struct Scsi_Host *shost = class_to_shost(dev);
  156. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  157. struct lpfc_hba *phba = vport->phba;
  158. return snprintf(buf, PAGE_SIZE, "%llu\n",
  159. (unsigned long long)phba->bg_reftag_err_cnt);
  160. }
  161. /**
  162. * lpfc_info_show - Return some pci info about the host in ascii
  163. * @dev: class converted to a Scsi_host structure.
  164. * @attr: device attribute, not used.
  165. * @buf: on return contains the formatted text from lpfc_info().
  166. *
  167. * Returns: size of formatted string.
  168. **/
  169. static ssize_t
  170. lpfc_info_show(struct device *dev, struct device_attribute *attr,
  171. char *buf)
  172. {
  173. struct Scsi_Host *host = class_to_shost(dev);
  174. return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
  175. }
  176. /**
  177. * lpfc_serialnum_show - Return the hba serial number in ascii
  178. * @dev: class converted to a Scsi_host structure.
  179. * @attr: device attribute, not used.
  180. * @buf: on return contains the formatted text serial number.
  181. *
  182. * Returns: size of formatted string.
  183. **/
  184. static ssize_t
  185. lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
  186. char *buf)
  187. {
  188. struct Scsi_Host *shost = class_to_shost(dev);
  189. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  190. struct lpfc_hba *phba = vport->phba;
  191. return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
  192. }
  193. /**
  194. * lpfc_temp_sensor_show - Return the temperature sensor level
  195. * @dev: class converted to a Scsi_host structure.
  196. * @attr: device attribute, not used.
  197. * @buf: on return contains the formatted support level.
  198. *
  199. * Description:
  200. * Returns a number indicating the temperature sensor level currently
  201. * supported, zero or one in ascii.
  202. *
  203. * Returns: size of formatted string.
  204. **/
  205. static ssize_t
  206. lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
  207. char *buf)
  208. {
  209. struct Scsi_Host *shost = class_to_shost(dev);
  210. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  211. struct lpfc_hba *phba = vport->phba;
  212. return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
  213. }
  214. /**
  215. * lpfc_modeldesc_show - Return the model description of the hba
  216. * @dev: class converted to a Scsi_host structure.
  217. * @attr: device attribute, not used.
  218. * @buf: on return contains the scsi vpd model description.
  219. *
  220. * Returns: size of formatted string.
  221. **/
  222. static ssize_t
  223. lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
  224. char *buf)
  225. {
  226. struct Scsi_Host *shost = class_to_shost(dev);
  227. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  228. struct lpfc_hba *phba = vport->phba;
  229. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
  230. }
  231. /**
  232. * lpfc_modelname_show - Return the model name of the hba
  233. * @dev: class converted to a Scsi_host structure.
  234. * @attr: device attribute, not used.
  235. * @buf: on return contains the scsi vpd model name.
  236. *
  237. * Returns: size of formatted string.
  238. **/
  239. static ssize_t
  240. lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
  241. char *buf)
  242. {
  243. struct Scsi_Host *shost = class_to_shost(dev);
  244. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  245. struct lpfc_hba *phba = vport->phba;
  246. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
  247. }
  248. /**
  249. * lpfc_programtype_show - Return the program type of the hba
  250. * @dev: class converted to a Scsi_host structure.
  251. * @attr: device attribute, not used.
  252. * @buf: on return contains the scsi vpd program type.
  253. *
  254. * Returns: size of formatted string.
  255. **/
  256. static ssize_t
  257. lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
  258. char *buf)
  259. {
  260. struct Scsi_Host *shost = class_to_shost(dev);
  261. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  262. struct lpfc_hba *phba = vport->phba;
  263. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
  264. }
  265. /**
  266. * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
  267. * @dev: class converted to a Scsi_host structure.
  268. * @attr: device attribute, not used.
  269. * @buf: on return contains the Menlo Maintenance sli flag.
  270. *
  271. * Returns: size of formatted string.
  272. **/
  273. static ssize_t
  274. lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
  275. {
  276. struct Scsi_Host *shost = class_to_shost(dev);
  277. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  278. struct lpfc_hba *phba = vport->phba;
  279. return snprintf(buf, PAGE_SIZE, "%d\n",
  280. (phba->sli.sli_flag & LPFC_MENLO_MAINT));
  281. }
  282. /**
  283. * lpfc_vportnum_show - Return the port number in ascii of the hba
  284. * @dev: class converted to a Scsi_host structure.
  285. * @attr: device attribute, not used.
  286. * @buf: on return contains scsi vpd program type.
  287. *
  288. * Returns: size of formatted string.
  289. **/
  290. static ssize_t
  291. lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
  292. char *buf)
  293. {
  294. struct Scsi_Host *shost = class_to_shost(dev);
  295. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  296. struct lpfc_hba *phba = vport->phba;
  297. return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
  298. }
  299. /**
  300. * lpfc_fwrev_show - Return the firmware rev running in the hba
  301. * @dev: class converted to a Scsi_host structure.
  302. * @attr: device attribute, not used.
  303. * @buf: on return contains the scsi vpd program type.
  304. *
  305. * Returns: size of formatted string.
  306. **/
  307. static ssize_t
  308. lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
  309. char *buf)
  310. {
  311. struct Scsi_Host *shost = class_to_shost(dev);
  312. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  313. struct lpfc_hba *phba = vport->phba;
  314. char fwrev[32];
  315. lpfc_decode_firmware_rev(phba, fwrev, 1);
  316. return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
  317. }
  318. /**
  319. * lpfc_hdw_show - Return the jedec information about the hba
  320. * @dev: class converted to a Scsi_host structure.
  321. * @attr: device attribute, not used.
  322. * @buf: on return contains the scsi vpd program type.
  323. *
  324. * Returns: size of formatted string.
  325. **/
  326. static ssize_t
  327. lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
  328. {
  329. char hdw[9];
  330. struct Scsi_Host *shost = class_to_shost(dev);
  331. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  332. struct lpfc_hba *phba = vport->phba;
  333. lpfc_vpd_t *vp = &phba->vpd;
  334. lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
  335. return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
  336. }
  337. /**
  338. * lpfc_option_rom_version_show - Return the adapter ROM FCode version
  339. * @dev: class converted to a Scsi_host structure.
  340. * @attr: device attribute, not used.
  341. * @buf: on return contains the ROM and FCode ascii strings.
  342. *
  343. * Returns: size of formatted string.
  344. **/
  345. static ssize_t
  346. lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
  347. char *buf)
  348. {
  349. struct Scsi_Host *shost = class_to_shost(dev);
  350. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  351. struct lpfc_hba *phba = vport->phba;
  352. return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
  353. }
  354. /**
  355. * lpfc_state_show - Return the link state of the port
  356. * @dev: class converted to a Scsi_host structure.
  357. * @attr: device attribute, not used.
  358. * @buf: on return contains text describing the state of the link.
  359. *
  360. * Notes:
  361. * The switch statement has no default so zero will be returned.
  362. *
  363. * Returns: size of formatted string.
  364. **/
  365. static ssize_t
  366. lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
  367. char *buf)
  368. {
  369. struct Scsi_Host *shost = class_to_shost(dev);
  370. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  371. struct lpfc_hba *phba = vport->phba;
  372. int len = 0;
  373. switch (phba->link_state) {
  374. case LPFC_LINK_UNKNOWN:
  375. case LPFC_WARM_START:
  376. case LPFC_INIT_START:
  377. case LPFC_INIT_MBX_CMDS:
  378. case LPFC_LINK_DOWN:
  379. case LPFC_HBA_ERROR:
  380. if (phba->hba_flag & LINK_DISABLED)
  381. len += snprintf(buf + len, PAGE_SIZE-len,
  382. "Link Down - User disabled\n");
  383. else
  384. len += snprintf(buf + len, PAGE_SIZE-len,
  385. "Link Down\n");
  386. break;
  387. case LPFC_LINK_UP:
  388. case LPFC_CLEAR_LA:
  389. case LPFC_HBA_READY:
  390. len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
  391. switch (vport->port_state) {
  392. case LPFC_LOCAL_CFG_LINK:
  393. len += snprintf(buf + len, PAGE_SIZE-len,
  394. "Configuring Link\n");
  395. break;
  396. case LPFC_FDISC:
  397. case LPFC_FLOGI:
  398. case LPFC_FABRIC_CFG_LINK:
  399. case LPFC_NS_REG:
  400. case LPFC_NS_QRY:
  401. case LPFC_BUILD_DISC_LIST:
  402. case LPFC_DISC_AUTH:
  403. len += snprintf(buf + len, PAGE_SIZE - len,
  404. "Discovery\n");
  405. break;
  406. case LPFC_VPORT_READY:
  407. len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
  408. break;
  409. case LPFC_VPORT_FAILED:
  410. len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
  411. break;
  412. case LPFC_VPORT_UNKNOWN:
  413. len += snprintf(buf + len, PAGE_SIZE - len,
  414. "Unknown\n");
  415. break;
  416. }
  417. if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
  418. len += snprintf(buf + len, PAGE_SIZE-len,
  419. " Menlo Maint Mode\n");
  420. else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  421. if (vport->fc_flag & FC_PUBLIC_LOOP)
  422. len += snprintf(buf + len, PAGE_SIZE-len,
  423. " Public Loop\n");
  424. else
  425. len += snprintf(buf + len, PAGE_SIZE-len,
  426. " Private Loop\n");
  427. } else {
  428. if (vport->fc_flag & FC_FABRIC)
  429. len += snprintf(buf + len, PAGE_SIZE-len,
  430. " Fabric\n");
  431. else
  432. len += snprintf(buf + len, PAGE_SIZE-len,
  433. " Point-2-Point\n");
  434. }
  435. }
  436. return len;
  437. }
  438. /**
  439. * lpfc_link_state_store - Transition the link_state on an HBA port
  440. * @dev: class device that is converted into a Scsi_host.
  441. * @attr: device attribute, not used.
  442. * @buf: one or more lpfc_polling_flags values.
  443. * @count: not used.
  444. *
  445. * Returns:
  446. * -EINVAL if the buffer is not "up" or "down"
  447. * return from link state change function if non-zero
  448. * length of the buf on success
  449. **/
  450. static ssize_t
  451. lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
  452. const char *buf, size_t count)
  453. {
  454. struct Scsi_Host *shost = class_to_shost(dev);
  455. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  456. struct lpfc_hba *phba = vport->phba;
  457. int status = -EINVAL;
  458. if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
  459. (phba->link_state == LPFC_LINK_DOWN))
  460. status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  461. else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
  462. (phba->link_state >= LPFC_LINK_UP))
  463. status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
  464. if (status == 0)
  465. return strlen(buf);
  466. else
  467. return status;
  468. }
  469. /**
  470. * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
  471. * @dev: class device that is converted into a Scsi_host.
  472. * @attr: device attribute, not used.
  473. * @buf: on return contains the sum of fc mapped and unmapped.
  474. *
  475. * Description:
  476. * Returns the ascii text number of the sum of the fc mapped and unmapped
  477. * vport counts.
  478. *
  479. * Returns: size of formatted string.
  480. **/
  481. static ssize_t
  482. lpfc_num_discovered_ports_show(struct device *dev,
  483. struct device_attribute *attr, char *buf)
  484. {
  485. struct Scsi_Host *shost = class_to_shost(dev);
  486. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  487. return snprintf(buf, PAGE_SIZE, "%d\n",
  488. vport->fc_map_cnt + vport->fc_unmap_cnt);
  489. }
  490. /**
  491. * lpfc_issue_lip - Misnomer, name carried over from long ago
  492. * @shost: Scsi_Host pointer.
  493. *
  494. * Description:
  495. * Bring the link down gracefully then re-init the link. The firmware will
  496. * re-init the fiber channel interface as required. Does not issue a LIP.
  497. *
  498. * Returns:
  499. * -EPERM port offline or management commands are being blocked
  500. * -ENOMEM cannot allocate memory for the mailbox command
  501. * -EIO error sending the mailbox command
  502. * zero for success
  503. **/
  504. static int
  505. lpfc_issue_lip(struct Scsi_Host *shost)
  506. {
  507. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  508. struct lpfc_hba *phba = vport->phba;
  509. LPFC_MBOXQ_t *pmboxq;
  510. int mbxstatus = MBXERR_ERROR;
  511. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  512. (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
  513. return -EPERM;
  514. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  515. if (!pmboxq)
  516. return -ENOMEM;
  517. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  518. pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
  519. pmboxq->u.mb.mbxOwner = OWN_HOST;
  520. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
  521. if ((mbxstatus == MBX_SUCCESS) &&
  522. (pmboxq->u.mb.mbxStatus == 0 ||
  523. pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
  524. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  525. lpfc_init_link(phba, pmboxq, phba->cfg_topology,
  526. phba->cfg_link_speed);
  527. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
  528. phba->fc_ratov * 2);
  529. if ((mbxstatus == MBX_SUCCESS) &&
  530. (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  531. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
  532. "2859 SLI authentication is required "
  533. "for INIT_LINK but has not done yet\n");
  534. }
  535. lpfc_set_loopback_flag(phba);
  536. if (mbxstatus != MBX_TIMEOUT)
  537. mempool_free(pmboxq, phba->mbox_mem_pool);
  538. if (mbxstatus == MBXERR_ERROR)
  539. return -EIO;
  540. return 0;
  541. }
  542. /**
  543. * lpfc_do_offline - Issues a mailbox command to bring the link down
  544. * @phba: lpfc_hba pointer.
  545. * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
  546. *
  547. * Notes:
  548. * Assumes any error from lpfc_do_offline() will be negative.
  549. * Can wait up to 5 seconds for the port ring buffers count
  550. * to reach zero, prints a warning if it is not zero and continues.
  551. * lpfc_workq_post_event() returns a non-zero return code if call fails.
  552. *
  553. * Returns:
  554. * -EIO error posting the event
  555. * zero for success
  556. **/
  557. static int
  558. lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
  559. {
  560. struct completion online_compl;
  561. struct lpfc_sli_ring *pring;
  562. struct lpfc_sli *psli;
  563. int status = 0;
  564. int cnt = 0;
  565. int i;
  566. int rc;
  567. init_completion(&online_compl);
  568. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  569. LPFC_EVT_OFFLINE_PREP);
  570. if (rc == 0)
  571. return -ENOMEM;
  572. wait_for_completion(&online_compl);
  573. if (status != 0)
  574. return -EIO;
  575. psli = &phba->sli;
  576. /* Wait a little for things to settle down, but not
  577. * long enough for dev loss timeout to expire.
  578. */
  579. for (i = 0; i < psli->num_rings; i++) {
  580. pring = &psli->ring[i];
  581. while (pring->txcmplq_cnt) {
  582. msleep(10);
  583. if (cnt++ > 500) { /* 5 secs */
  584. lpfc_printf_log(phba,
  585. KERN_WARNING, LOG_INIT,
  586. "0466 Outstanding IO when "
  587. "bringing Adapter offline\n");
  588. break;
  589. }
  590. }
  591. }
  592. init_completion(&online_compl);
  593. rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
  594. if (rc == 0)
  595. return -ENOMEM;
  596. wait_for_completion(&online_compl);
  597. if (status != 0)
  598. return -EIO;
  599. return 0;
  600. }
  601. /**
  602. * lpfc_selective_reset - Offline then onlines the port
  603. * @phba: lpfc_hba pointer.
  604. *
  605. * Description:
  606. * If the port is configured to allow a reset then the hba is brought
  607. * offline then online.
  608. *
  609. * Notes:
  610. * Assumes any error from lpfc_do_offline() will be negative.
  611. * Do not make this function static.
  612. *
  613. * Returns:
  614. * lpfc_do_offline() return code if not zero
  615. * -EIO reset not configured or error posting the event
  616. * zero for success
  617. **/
  618. int
  619. lpfc_selective_reset(struct lpfc_hba *phba)
  620. {
  621. struct completion online_compl;
  622. int status = 0;
  623. int rc;
  624. if (!phba->cfg_enable_hba_reset)
  625. return -EIO;
  626. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  627. if (status != 0)
  628. return status;
  629. init_completion(&online_compl);
  630. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  631. LPFC_EVT_ONLINE);
  632. if (rc == 0)
  633. return -ENOMEM;
  634. wait_for_completion(&online_compl);
  635. if (status != 0)
  636. return -EIO;
  637. return 0;
  638. }
  639. /**
  640. * lpfc_issue_reset - Selectively resets an adapter
  641. * @dev: class device that is converted into a Scsi_host.
  642. * @attr: device attribute, not used.
  643. * @buf: containing the string "selective".
  644. * @count: unused variable.
  645. *
  646. * Description:
  647. * If the buf contains the string "selective" then lpfc_selective_reset()
  648. * is called to perform the reset.
  649. *
  650. * Notes:
  651. * Assumes any error from lpfc_selective_reset() will be negative.
  652. * If lpfc_selective_reset() returns zero then the length of the buffer
  653. * is returned which indicates success
  654. *
  655. * Returns:
  656. * -EINVAL if the buffer does not contain the string "selective"
  657. * length of buf if lpfc-selective_reset() if the call succeeds
  658. * return value of lpfc_selective_reset() if the call fails
  659. **/
  660. static ssize_t
  661. lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
  662. const char *buf, size_t count)
  663. {
  664. struct Scsi_Host *shost = class_to_shost(dev);
  665. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  666. struct lpfc_hba *phba = vport->phba;
  667. int status = -EINVAL;
  668. if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
  669. status = phba->lpfc_selective_reset(phba);
  670. if (status == 0)
  671. return strlen(buf);
  672. else
  673. return status;
  674. }
  675. /**
  676. * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
  677. * @phba: lpfc_hba pointer.
  678. *
  679. * Description:
  680. * SLI4 interface type-2 device to wait on the sliport status register for
  681. * the readyness after performing a firmware reset.
  682. *
  683. * Returns:
  684. * zero for success
  685. **/
  686. static int
  687. lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
  688. {
  689. struct lpfc_register portstat_reg;
  690. int i;
  691. lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  692. &portstat_reg.word0);
  693. /* wait for the SLI port firmware ready after firmware reset */
  694. for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
  695. msleep(10);
  696. lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  697. &portstat_reg.word0);
  698. if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
  699. continue;
  700. if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
  701. continue;
  702. if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
  703. continue;
  704. break;
  705. }
  706. if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
  707. return 0;
  708. else
  709. return -EIO;
  710. }
  711. /**
  712. * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
  713. * @phba: lpfc_hba pointer.
  714. *
  715. * Description:
  716. * Request SLI4 interface type-2 device to perform a physical register set
  717. * access.
  718. *
  719. * Returns:
  720. * zero for success
  721. **/
  722. static ssize_t
  723. lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
  724. {
  725. struct completion online_compl;
  726. uint32_t reg_val;
  727. int status = 0;
  728. int rc;
  729. if (!phba->cfg_enable_hba_reset)
  730. return -EIO;
  731. if ((phba->sli_rev < LPFC_SLI_REV4) ||
  732. (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  733. LPFC_SLI_INTF_IF_TYPE_2))
  734. return -EPERM;
  735. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  736. if (status != 0)
  737. return status;
  738. /* wait for the device to be quiesced before firmware reset */
  739. msleep(100);
  740. reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
  741. LPFC_CTL_PDEV_CTL_OFFSET);
  742. if (opcode == LPFC_FW_DUMP)
  743. reg_val |= LPFC_FW_DUMP_REQUEST;
  744. else if (opcode == LPFC_FW_RESET)
  745. reg_val |= LPFC_CTL_PDEV_CTL_FRST;
  746. else if (opcode == LPFC_DV_RESET)
  747. reg_val |= LPFC_CTL_PDEV_CTL_DRST;
  748. writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
  749. LPFC_CTL_PDEV_CTL_OFFSET);
  750. /* flush */
  751. readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
  752. /* delay driver action following IF_TYPE_2 reset */
  753. rc = lpfc_sli4_pdev_status_reg_wait(phba);
  754. if (rc)
  755. return -EIO;
  756. init_completion(&online_compl);
  757. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  758. LPFC_EVT_ONLINE);
  759. if (rc == 0)
  760. return -ENOMEM;
  761. wait_for_completion(&online_compl);
  762. if (status != 0)
  763. return -EIO;
  764. return 0;
  765. }
  766. /**
  767. * lpfc_nport_evt_cnt_show - Return the number of nport events
  768. * @dev: class device that is converted into a Scsi_host.
  769. * @attr: device attribute, not used.
  770. * @buf: on return contains the ascii number of nport events.
  771. *
  772. * Returns: size of formatted string.
  773. **/
  774. static ssize_t
  775. lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
  776. char *buf)
  777. {
  778. struct Scsi_Host *shost = class_to_shost(dev);
  779. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  780. struct lpfc_hba *phba = vport->phba;
  781. return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
  782. }
  783. /**
  784. * lpfc_board_mode_show - Return the state of the board
  785. * @dev: class device that is converted into a Scsi_host.
  786. * @attr: device attribute, not used.
  787. * @buf: on return contains the state of the adapter.
  788. *
  789. * Returns: size of formatted string.
  790. **/
  791. static ssize_t
  792. lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
  793. char *buf)
  794. {
  795. struct Scsi_Host *shost = class_to_shost(dev);
  796. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  797. struct lpfc_hba *phba = vport->phba;
  798. char * state;
  799. if (phba->link_state == LPFC_HBA_ERROR)
  800. state = "error";
  801. else if (phba->link_state == LPFC_WARM_START)
  802. state = "warm start";
  803. else if (phba->link_state == LPFC_INIT_START)
  804. state = "offline";
  805. else
  806. state = "online";
  807. return snprintf(buf, PAGE_SIZE, "%s\n", state);
  808. }
  809. /**
  810. * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
  811. * @dev: class device that is converted into a Scsi_host.
  812. * @attr: device attribute, not used.
  813. * @buf: containing one of the strings "online", "offline", "warm" or "error".
  814. * @count: unused variable.
  815. *
  816. * Returns:
  817. * -EACCES if enable hba reset not enabled
  818. * -EINVAL if the buffer does not contain a valid string (see above)
  819. * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
  820. * buf length greater than zero indicates success
  821. **/
  822. static ssize_t
  823. lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
  824. const char *buf, size_t count)
  825. {
  826. struct Scsi_Host *shost = class_to_shost(dev);
  827. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  828. struct lpfc_hba *phba = vport->phba;
  829. struct completion online_compl;
  830. int status=0;
  831. int rc;
  832. if (!phba->cfg_enable_hba_reset)
  833. return -EACCES;
  834. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  835. "3050 lpfc_board_mode set to %s\n", buf);
  836. init_completion(&online_compl);
  837. if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
  838. rc = lpfc_workq_post_event(phba, &status, &online_compl,
  839. LPFC_EVT_ONLINE);
  840. if (rc == 0)
  841. return -ENOMEM;
  842. wait_for_completion(&online_compl);
  843. } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
  844. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  845. else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
  846. if (phba->sli_rev == LPFC_SLI_REV4)
  847. return -EINVAL;
  848. else
  849. status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
  850. else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
  851. if (phba->sli_rev == LPFC_SLI_REV4)
  852. return -EINVAL;
  853. else
  854. status = lpfc_do_offline(phba, LPFC_EVT_KILL);
  855. else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
  856. status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
  857. else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
  858. status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
  859. else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
  860. status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
  861. else
  862. return -EINVAL;
  863. if (!status)
  864. return strlen(buf);
  865. else
  866. return -EIO;
  867. }
  868. /**
  869. * lpfc_get_hba_info - Return various bits of informaton about the adapter
  870. * @phba: pointer to the adapter structure.
  871. * @mxri: max xri count.
  872. * @axri: available xri count.
  873. * @mrpi: max rpi count.
  874. * @arpi: available rpi count.
  875. * @mvpi: max vpi count.
  876. * @avpi: available vpi count.
  877. *
  878. * Description:
  879. * If an integer pointer for an count is not null then the value for the
  880. * count is returned.
  881. *
  882. * Returns:
  883. * zero on error
  884. * one for success
  885. **/
  886. static int
  887. lpfc_get_hba_info(struct lpfc_hba *phba,
  888. uint32_t *mxri, uint32_t *axri,
  889. uint32_t *mrpi, uint32_t *arpi,
  890. uint32_t *mvpi, uint32_t *avpi)
  891. {
  892. struct lpfc_mbx_read_config *rd_config;
  893. LPFC_MBOXQ_t *pmboxq;
  894. MAILBOX_t *pmb;
  895. int rc = 0;
  896. uint32_t max_vpi;
  897. /*
  898. * prevent udev from issuing mailbox commands until the port is
  899. * configured.
  900. */
  901. if (phba->link_state < LPFC_LINK_DOWN ||
  902. !phba->mbox_mem_pool ||
  903. (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
  904. return 0;
  905. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  906. return 0;
  907. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  908. if (!pmboxq)
  909. return 0;
  910. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  911. pmb = &pmboxq->u.mb;
  912. pmb->mbxCommand = MBX_READ_CONFIG;
  913. pmb->mbxOwner = OWN_HOST;
  914. pmboxq->context1 = NULL;
  915. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  916. rc = MBX_NOT_FINISHED;
  917. else
  918. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  919. if (rc != MBX_SUCCESS) {
  920. if (rc != MBX_TIMEOUT)
  921. mempool_free(pmboxq, phba->mbox_mem_pool);
  922. return 0;
  923. }
  924. if (phba->sli_rev == LPFC_SLI_REV4) {
  925. rd_config = &pmboxq->u.mqe.un.rd_config;
  926. if (mrpi)
  927. *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
  928. if (arpi)
  929. *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
  930. phba->sli4_hba.max_cfg_param.rpi_used;
  931. if (mxri)
  932. *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
  933. if (axri)
  934. *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
  935. phba->sli4_hba.max_cfg_param.xri_used;
  936. /* Account for differences with SLI-3. Get vpi count from
  937. * mailbox data and subtract one for max vpi value.
  938. */
  939. max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
  940. (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
  941. if (mvpi)
  942. *mvpi = max_vpi;
  943. if (avpi)
  944. *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
  945. } else {
  946. if (mrpi)
  947. *mrpi = pmb->un.varRdConfig.max_rpi;
  948. if (arpi)
  949. *arpi = pmb->un.varRdConfig.avail_rpi;
  950. if (mxri)
  951. *mxri = pmb->un.varRdConfig.max_xri;
  952. if (axri)
  953. *axri = pmb->un.varRdConfig.avail_xri;
  954. if (mvpi)
  955. *mvpi = pmb->un.varRdConfig.max_vpi;
  956. if (avpi)
  957. *avpi = pmb->un.varRdConfig.avail_vpi;
  958. }
  959. mempool_free(pmboxq, phba->mbox_mem_pool);
  960. return 1;
  961. }
  962. /**
  963. * lpfc_max_rpi_show - Return maximum rpi
  964. * @dev: class device that is converted into a Scsi_host.
  965. * @attr: device attribute, not used.
  966. * @buf: on return contains the maximum rpi count in decimal or "Unknown".
  967. *
  968. * Description:
  969. * Calls lpfc_get_hba_info() asking for just the mrpi count.
  970. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  971. * to "Unknown" and the buffer length is returned, therefore the caller
  972. * must check for "Unknown" in the buffer to detect a failure.
  973. *
  974. * Returns: size of formatted string.
  975. **/
  976. static ssize_t
  977. lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
  978. char *buf)
  979. {
  980. struct Scsi_Host *shost = class_to_shost(dev);
  981. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  982. struct lpfc_hba *phba = vport->phba;
  983. uint32_t cnt;
  984. if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
  985. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  986. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  987. }
  988. /**
  989. * lpfc_used_rpi_show - Return maximum rpi minus available rpi
  990. * @dev: class device that is converted into a Scsi_host.
  991. * @attr: device attribute, not used.
  992. * @buf: containing the used rpi count in decimal or "Unknown".
  993. *
  994. * Description:
  995. * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
  996. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  997. * to "Unknown" and the buffer length is returned, therefore the caller
  998. * must check for "Unknown" in the buffer to detect a failure.
  999. *
  1000. * Returns: size of formatted string.
  1001. **/
  1002. static ssize_t
  1003. lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
  1004. char *buf)
  1005. {
  1006. struct Scsi_Host *shost = class_to_shost(dev);
  1007. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1008. struct lpfc_hba *phba = vport->phba;
  1009. uint32_t cnt, acnt;
  1010. if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
  1011. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  1012. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1013. }
  1014. /**
  1015. * lpfc_max_xri_show - Return maximum xri
  1016. * @dev: class device that is converted into a Scsi_host.
  1017. * @attr: device attribute, not used.
  1018. * @buf: on return contains the maximum xri count in decimal or "Unknown".
  1019. *
  1020. * Description:
  1021. * Calls lpfc_get_hba_info() asking for just the mrpi count.
  1022. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1023. * to "Unknown" and the buffer length is returned, therefore the caller
  1024. * must check for "Unknown" in the buffer to detect a failure.
  1025. *
  1026. * Returns: size of formatted string.
  1027. **/
  1028. static ssize_t
  1029. lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
  1030. char *buf)
  1031. {
  1032. struct Scsi_Host *shost = class_to_shost(dev);
  1033. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1034. struct lpfc_hba *phba = vport->phba;
  1035. uint32_t cnt;
  1036. if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
  1037. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  1038. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1039. }
  1040. /**
  1041. * lpfc_used_xri_show - Return maximum xpi minus the available xpi
  1042. * @dev: class device that is converted into a Scsi_host.
  1043. * @attr: device attribute, not used.
  1044. * @buf: on return contains the used xri count in decimal or "Unknown".
  1045. *
  1046. * Description:
  1047. * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
  1048. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1049. * to "Unknown" and the buffer length is returned, therefore the caller
  1050. * must check for "Unknown" in the buffer to detect a failure.
  1051. *
  1052. * Returns: size of formatted string.
  1053. **/
  1054. static ssize_t
  1055. lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
  1056. char *buf)
  1057. {
  1058. struct Scsi_Host *shost = class_to_shost(dev);
  1059. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1060. struct lpfc_hba *phba = vport->phba;
  1061. uint32_t cnt, acnt;
  1062. if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
  1063. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  1064. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1065. }
  1066. /**
  1067. * lpfc_max_vpi_show - Return maximum vpi
  1068. * @dev: class device that is converted into a Scsi_host.
  1069. * @attr: device attribute, not used.
  1070. * @buf: on return contains the maximum vpi count in decimal or "Unknown".
  1071. *
  1072. * Description:
  1073. * Calls lpfc_get_hba_info() asking for just the mvpi count.
  1074. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1075. * to "Unknown" and the buffer length is returned, therefore the caller
  1076. * must check for "Unknown" in the buffer to detect a failure.
  1077. *
  1078. * Returns: size of formatted string.
  1079. **/
  1080. static ssize_t
  1081. lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
  1082. char *buf)
  1083. {
  1084. struct Scsi_Host *shost = class_to_shost(dev);
  1085. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1086. struct lpfc_hba *phba = vport->phba;
  1087. uint32_t cnt;
  1088. if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
  1089. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  1090. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1091. }
  1092. /**
  1093. * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
  1094. * @dev: class device that is converted into a Scsi_host.
  1095. * @attr: device attribute, not used.
  1096. * @buf: on return contains the used vpi count in decimal or "Unknown".
  1097. *
  1098. * Description:
  1099. * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
  1100. * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
  1101. * to "Unknown" and the buffer length is returned, therefore the caller
  1102. * must check for "Unknown" in the buffer to detect a failure.
  1103. *
  1104. * Returns: size of formatted string.
  1105. **/
  1106. static ssize_t
  1107. lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
  1108. char *buf)
  1109. {
  1110. struct Scsi_Host *shost = class_to_shost(dev);
  1111. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1112. struct lpfc_hba *phba = vport->phba;
  1113. uint32_t cnt, acnt;
  1114. if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
  1115. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  1116. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  1117. }
  1118. /**
  1119. * lpfc_npiv_info_show - Return text about NPIV support for the adapter
  1120. * @dev: class device that is converted into a Scsi_host.
  1121. * @attr: device attribute, not used.
  1122. * @buf: text that must be interpreted to determine if npiv is supported.
  1123. *
  1124. * Description:
  1125. * Buffer will contain text indicating npiv is not suppoerted on the port,
  1126. * the port is an NPIV physical port, or it is an npiv virtual port with
  1127. * the id of the vport.
  1128. *
  1129. * Returns: size of formatted string.
  1130. **/
  1131. static ssize_t
  1132. lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
  1133. char *buf)
  1134. {
  1135. struct Scsi_Host *shost = class_to_shost(dev);
  1136. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1137. struct lpfc_hba *phba = vport->phba;
  1138. if (!(phba->max_vpi))
  1139. return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
  1140. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1141. return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
  1142. return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
  1143. }
  1144. /**
  1145. * lpfc_poll_show - Return text about poll support for the adapter
  1146. * @dev: class device that is converted into a Scsi_host.
  1147. * @attr: device attribute, not used.
  1148. * @buf: on return contains the cfg_poll in hex.
  1149. *
  1150. * Notes:
  1151. * cfg_poll should be a lpfc_polling_flags type.
  1152. *
  1153. * Returns: size of formatted string.
  1154. **/
  1155. static ssize_t
  1156. lpfc_poll_show(struct device *dev, struct device_attribute *attr,
  1157. char *buf)
  1158. {
  1159. struct Scsi_Host *shost = class_to_shost(dev);
  1160. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1161. struct lpfc_hba *phba = vport->phba;
  1162. return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
  1163. }
  1164. /**
  1165. * lpfc_poll_store - Set the value of cfg_poll for the adapter
  1166. * @dev: class device that is converted into a Scsi_host.
  1167. * @attr: device attribute, not used.
  1168. * @buf: one or more lpfc_polling_flags values.
  1169. * @count: not used.
  1170. *
  1171. * Notes:
  1172. * buf contents converted to integer and checked for a valid value.
  1173. *
  1174. * Returns:
  1175. * -EINVAL if the buffer connot be converted or is out of range
  1176. * length of the buf on success
  1177. **/
  1178. static ssize_t
  1179. lpfc_poll_store(struct device *dev, struct device_attribute *attr,
  1180. const char *buf, size_t count)
  1181. {
  1182. struct Scsi_Host *shost = class_to_shost(dev);
  1183. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1184. struct lpfc_hba *phba = vport->phba;
  1185. uint32_t creg_val;
  1186. uint32_t old_val;
  1187. int val=0;
  1188. if (!isdigit(buf[0]))
  1189. return -EINVAL;
  1190. if (sscanf(buf, "%i", &val) != 1)
  1191. return -EINVAL;
  1192. if ((val & 0x3) != val)
  1193. return -EINVAL;
  1194. if (phba->sli_rev == LPFC_SLI_REV4)
  1195. val = 0;
  1196. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1197. "3051 lpfc_poll changed from %d to %d\n",
  1198. phba->cfg_poll, val);
  1199. spin_lock_irq(&phba->hbalock);
  1200. old_val = phba->cfg_poll;
  1201. if (val & ENABLE_FCP_RING_POLLING) {
  1202. if ((val & DISABLE_FCP_RING_INT) &&
  1203. !(old_val & DISABLE_FCP_RING_INT)) {
  1204. if (lpfc_readl(phba->HCregaddr, &creg_val)) {
  1205. spin_unlock_irq(&phba->hbalock);
  1206. return -EINVAL;
  1207. }
  1208. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  1209. writel(creg_val, phba->HCregaddr);
  1210. readl(phba->HCregaddr); /* flush */
  1211. lpfc_poll_start_timer(phba);
  1212. }
  1213. } else if (val != 0x0) {
  1214. spin_unlock_irq(&phba->hbalock);
  1215. return -EINVAL;
  1216. }
  1217. if (!(val & DISABLE_FCP_RING_INT) &&
  1218. (old_val & DISABLE_FCP_RING_INT))
  1219. {
  1220. spin_unlock_irq(&phba->hbalock);
  1221. del_timer(&phba->fcp_poll_timer);
  1222. spin_lock_irq(&phba->hbalock);
  1223. if (lpfc_readl(phba->HCregaddr, &creg_val)) {
  1224. spin_unlock_irq(&phba->hbalock);
  1225. return -EINVAL;
  1226. }
  1227. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  1228. writel(creg_val, phba->HCregaddr);
  1229. readl(phba->HCregaddr); /* flush */
  1230. }
  1231. phba->cfg_poll = val;
  1232. spin_unlock_irq(&phba->hbalock);
  1233. return strlen(buf);
  1234. }
  1235. /**
  1236. * lpfc_fips_level_show - Return the current FIPS level for the HBA
  1237. * @dev: class unused variable.
  1238. * @attr: device attribute, not used.
  1239. * @buf: on return contains the module description text.
  1240. *
  1241. * Returns: size of formatted string.
  1242. **/
  1243. static ssize_t
  1244. lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
  1245. char *buf)
  1246. {
  1247. struct Scsi_Host *shost = class_to_shost(dev);
  1248. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1249. struct lpfc_hba *phba = vport->phba;
  1250. return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
  1251. }
  1252. /**
  1253. * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
  1254. * @dev: class unused variable.
  1255. * @attr: device attribute, not used.
  1256. * @buf: on return contains the module description text.
  1257. *
  1258. * Returns: size of formatted string.
  1259. **/
  1260. static ssize_t
  1261. lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
  1262. char *buf)
  1263. {
  1264. struct Scsi_Host *shost = class_to_shost(dev);
  1265. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1266. struct lpfc_hba *phba = vport->phba;
  1267. return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
  1268. }
  1269. /**
  1270. * lpfc_dss_show - Return the current state of dss and the configured state
  1271. * @dev: class converted to a Scsi_host structure.
  1272. * @attr: device attribute, not used.
  1273. * @buf: on return contains the formatted text.
  1274. *
  1275. * Returns: size of formatted string.
  1276. **/
  1277. static ssize_t
  1278. lpfc_dss_show(struct device *dev, struct device_attribute *attr,
  1279. char *buf)
  1280. {
  1281. struct Scsi_Host *shost = class_to_shost(dev);
  1282. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1283. struct lpfc_hba *phba = vport->phba;
  1284. return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
  1285. (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
  1286. (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
  1287. "" : "Not ");
  1288. }
  1289. /**
  1290. * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
  1291. * @dev: class converted to a Scsi_host structure.
  1292. * @attr: device attribute, not used.
  1293. * @buf: on return contains the formatted support level.
  1294. *
  1295. * Description:
  1296. * Returns the maximum number of virtual functions a physical function can
  1297. * support, 0 will be returned if called on virtual function.
  1298. *
  1299. * Returns: size of formatted string.
  1300. **/
  1301. static ssize_t
  1302. lpfc_sriov_hw_max_virtfn_show(struct device *dev,
  1303. struct device_attribute *attr,
  1304. char *buf)
  1305. {
  1306. struct Scsi_Host *shost = class_to_shost(dev);
  1307. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1308. struct lpfc_hba *phba = vport->phba;
  1309. uint16_t max_nr_virtfn;
  1310. max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
  1311. return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
  1312. }
  1313. /**
  1314. * lpfc_param_show - Return a cfg attribute value in decimal
  1315. *
  1316. * Description:
  1317. * Macro that given an attr e.g. hba_queue_depth expands
  1318. * into a function with the name lpfc_hba_queue_depth_show.
  1319. *
  1320. * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
  1321. * @dev: class device that is converted into a Scsi_host.
  1322. * @attr: device attribute, not used.
  1323. * @buf: on return contains the attribute value in decimal.
  1324. *
  1325. * Returns: size of formatted string.
  1326. **/
  1327. #define lpfc_param_show(attr) \
  1328. static ssize_t \
  1329. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  1330. char *buf) \
  1331. { \
  1332. struct Scsi_Host *shost = class_to_shost(dev);\
  1333. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1334. struct lpfc_hba *phba = vport->phba;\
  1335. uint val = 0;\
  1336. val = phba->cfg_##attr;\
  1337. return snprintf(buf, PAGE_SIZE, "%d\n",\
  1338. phba->cfg_##attr);\
  1339. }
  1340. /**
  1341. * lpfc_param_hex_show - Return a cfg attribute value in hex
  1342. *
  1343. * Description:
  1344. * Macro that given an attr e.g. hba_queue_depth expands
  1345. * into a function with the name lpfc_hba_queue_depth_show
  1346. *
  1347. * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
  1348. * @dev: class device that is converted into a Scsi_host.
  1349. * @attr: device attribute, not used.
  1350. * @buf: on return contains the attribute value in hexadecimal.
  1351. *
  1352. * Returns: size of formatted string.
  1353. **/
  1354. #define lpfc_param_hex_show(attr) \
  1355. static ssize_t \
  1356. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  1357. char *buf) \
  1358. { \
  1359. struct Scsi_Host *shost = class_to_shost(dev);\
  1360. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1361. struct lpfc_hba *phba = vport->phba;\
  1362. uint val = 0;\
  1363. val = phba->cfg_##attr;\
  1364. return snprintf(buf, PAGE_SIZE, "%#x\n",\
  1365. phba->cfg_##attr);\
  1366. }
  1367. /**
  1368. * lpfc_param_init - Initializes a cfg attribute
  1369. *
  1370. * Description:
  1371. * Macro that given an attr e.g. hba_queue_depth expands
  1372. * into a function with the name lpfc_hba_queue_depth_init. The macro also
  1373. * takes a default argument, a minimum and maximum argument.
  1374. *
  1375. * lpfc_##attr##_init: Initializes an attribute.
  1376. * @phba: pointer the the adapter structure.
  1377. * @val: integer attribute value.
  1378. *
  1379. * Validates the min and max values then sets the adapter config field
  1380. * accordingly, or uses the default if out of range and prints an error message.
  1381. *
  1382. * Returns:
  1383. * zero on success
  1384. * -EINVAL if default used
  1385. **/
  1386. #define lpfc_param_init(attr, default, minval, maxval) \
  1387. static int \
  1388. lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
  1389. { \
  1390. if (val >= minval && val <= maxval) {\
  1391. phba->cfg_##attr = val;\
  1392. return 0;\
  1393. }\
  1394. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  1395. "0449 lpfc_"#attr" attribute cannot be set to %d, "\
  1396. "allowed range is ["#minval", "#maxval"]\n", val); \
  1397. phba->cfg_##attr = default;\
  1398. return -EINVAL;\
  1399. }
  1400. /**
  1401. * lpfc_param_set - Set a cfg attribute value
  1402. *
  1403. * Description:
  1404. * Macro that given an attr e.g. hba_queue_depth expands
  1405. * into a function with the name lpfc_hba_queue_depth_set
  1406. *
  1407. * lpfc_##attr##_set: Sets an attribute value.
  1408. * @phba: pointer the the adapter structure.
  1409. * @val: integer attribute value.
  1410. *
  1411. * Description:
  1412. * Validates the min and max values then sets the
  1413. * adapter config field if in the valid range. prints error message
  1414. * and does not set the parameter if invalid.
  1415. *
  1416. * Returns:
  1417. * zero on success
  1418. * -EINVAL if val is invalid
  1419. **/
  1420. #define lpfc_param_set(attr, default, minval, maxval) \
  1421. static int \
  1422. lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
  1423. { \
  1424. if (val >= minval && val <= maxval) {\
  1425. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  1426. "3052 lpfc_" #attr " changed from %d to %d\n", \
  1427. phba->cfg_##attr, val); \
  1428. phba->cfg_##attr = val;\
  1429. return 0;\
  1430. }\
  1431. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  1432. "0450 lpfc_"#attr" attribute cannot be set to %d, "\
  1433. "allowed range is ["#minval", "#maxval"]\n", val); \
  1434. return -EINVAL;\
  1435. }
  1436. /**
  1437. * lpfc_param_store - Set a vport attribute value
  1438. *
  1439. * Description:
  1440. * Macro that given an attr e.g. hba_queue_depth expands
  1441. * into a function with the name lpfc_hba_queue_depth_store.
  1442. *
  1443. * lpfc_##attr##_store: Set an sttribute value.
  1444. * @dev: class device that is converted into a Scsi_host.
  1445. * @attr: device attribute, not used.
  1446. * @buf: contains the attribute value in ascii.
  1447. * @count: not used.
  1448. *
  1449. * Description:
  1450. * Convert the ascii text number to an integer, then
  1451. * use the lpfc_##attr##_set function to set the value.
  1452. *
  1453. * Returns:
  1454. * -EINVAL if val is invalid or lpfc_##attr##_set() fails
  1455. * length of buffer upon success.
  1456. **/
  1457. #define lpfc_param_store(attr) \
  1458. static ssize_t \
  1459. lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
  1460. const char *buf, size_t count) \
  1461. { \
  1462. struct Scsi_Host *shost = class_to_shost(dev);\
  1463. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1464. struct lpfc_hba *phba = vport->phba;\
  1465. uint val = 0;\
  1466. if (!isdigit(buf[0]))\
  1467. return -EINVAL;\
  1468. if (sscanf(buf, "%i", &val) != 1)\
  1469. return -EINVAL;\
  1470. if (lpfc_##attr##_set(phba, val) == 0) \
  1471. return strlen(buf);\
  1472. else \
  1473. return -EINVAL;\
  1474. }
  1475. /**
  1476. * lpfc_vport_param_show - Return decimal formatted cfg attribute value
  1477. *
  1478. * Description:
  1479. * Macro that given an attr e.g. hba_queue_depth expands
  1480. * into a function with the name lpfc_hba_queue_depth_show
  1481. *
  1482. * lpfc_##attr##_show: prints the attribute value in decimal.
  1483. * @dev: class device that is converted into a Scsi_host.
  1484. * @attr: device attribute, not used.
  1485. * @buf: on return contains the attribute value in decimal.
  1486. *
  1487. * Returns: length of formatted string.
  1488. **/
  1489. #define lpfc_vport_param_show(attr) \
  1490. static ssize_t \
  1491. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  1492. char *buf) \
  1493. { \
  1494. struct Scsi_Host *shost = class_to_shost(dev);\
  1495. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1496. uint val = 0;\
  1497. val = vport->cfg_##attr;\
  1498. return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
  1499. }
  1500. /**
  1501. * lpfc_vport_param_hex_show - Return hex formatted attribute value
  1502. *
  1503. * Description:
  1504. * Macro that given an attr e.g.
  1505. * hba_queue_depth expands into a function with the name
  1506. * lpfc_hba_queue_depth_show
  1507. *
  1508. * lpfc_##attr##_show: prints the attribute value in hexadecimal.
  1509. * @dev: class device that is converted into a Scsi_host.
  1510. * @attr: device attribute, not used.
  1511. * @buf: on return contains the attribute value in hexadecimal.
  1512. *
  1513. * Returns: length of formatted string.
  1514. **/
  1515. #define lpfc_vport_param_hex_show(attr) \
  1516. static ssize_t \
  1517. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  1518. char *buf) \
  1519. { \
  1520. struct Scsi_Host *shost = class_to_shost(dev);\
  1521. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1522. uint val = 0;\
  1523. val = vport->cfg_##attr;\
  1524. return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
  1525. }
  1526. /**
  1527. * lpfc_vport_param_init - Initialize a vport cfg attribute
  1528. *
  1529. * Description:
  1530. * Macro that given an attr e.g. hba_queue_depth expands
  1531. * into a function with the name lpfc_hba_queue_depth_init. The macro also
  1532. * takes a default argument, a minimum and maximum argument.
  1533. *
  1534. * lpfc_##attr##_init: validates the min and max values then sets the
  1535. * adapter config field accordingly, or uses the default if out of range
  1536. * and prints an error message.
  1537. * @phba: pointer the the adapter structure.
  1538. * @val: integer attribute value.
  1539. *
  1540. * Returns:
  1541. * zero on success
  1542. * -EINVAL if default used
  1543. **/
  1544. #define lpfc_vport_param_init(attr, default, minval, maxval) \
  1545. static int \
  1546. lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
  1547. { \
  1548. if (val >= minval && val <= maxval) {\
  1549. vport->cfg_##attr = val;\
  1550. return 0;\
  1551. }\
  1552. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  1553. "0423 lpfc_"#attr" attribute cannot be set to %d, "\
  1554. "allowed range is ["#minval", "#maxval"]\n", val); \
  1555. vport->cfg_##attr = default;\
  1556. return -EINVAL;\
  1557. }
  1558. /**
  1559. * lpfc_vport_param_set - Set a vport cfg attribute
  1560. *
  1561. * Description:
  1562. * Macro that given an attr e.g. hba_queue_depth expands
  1563. * into a function with the name lpfc_hba_queue_depth_set
  1564. *
  1565. * lpfc_##attr##_set: validates the min and max values then sets the
  1566. * adapter config field if in the valid range. prints error message
  1567. * and does not set the parameter if invalid.
  1568. * @phba: pointer the the adapter structure.
  1569. * @val: integer attribute value.
  1570. *
  1571. * Returns:
  1572. * zero on success
  1573. * -EINVAL if val is invalid
  1574. **/
  1575. #define lpfc_vport_param_set(attr, default, minval, maxval) \
  1576. static int \
  1577. lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
  1578. { \
  1579. if (val >= minval && val <= maxval) {\
  1580. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  1581. "3053 lpfc_" #attr " changed from %d to %d\n", \
  1582. vport->cfg_##attr, val); \
  1583. vport->cfg_##attr = val;\
  1584. return 0;\
  1585. }\
  1586. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  1587. "0424 lpfc_"#attr" attribute cannot be set to %d, "\
  1588. "allowed range is ["#minval", "#maxval"]\n", val); \
  1589. return -EINVAL;\
  1590. }
  1591. /**
  1592. * lpfc_vport_param_store - Set a vport attribute
  1593. *
  1594. * Description:
  1595. * Macro that given an attr e.g. hba_queue_depth
  1596. * expands into a function with the name lpfc_hba_queue_depth_store
  1597. *
  1598. * lpfc_##attr##_store: convert the ascii text number to an integer, then
  1599. * use the lpfc_##attr##_set function to set the value.
  1600. * @cdev: class device that is converted into a Scsi_host.
  1601. * @buf: contains the attribute value in decimal.
  1602. * @count: not used.
  1603. *
  1604. * Returns:
  1605. * -EINVAL if val is invalid or lpfc_##attr##_set() fails
  1606. * length of buffer upon success.
  1607. **/
  1608. #define lpfc_vport_param_store(attr) \
  1609. static ssize_t \
  1610. lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
  1611. const char *buf, size_t count) \
  1612. { \
  1613. struct Scsi_Host *shost = class_to_shost(dev);\
  1614. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  1615. uint val = 0;\
  1616. if (!isdigit(buf[0]))\
  1617. return -EINVAL;\
  1618. if (sscanf(buf, "%i", &val) != 1)\
  1619. return -EINVAL;\
  1620. if (lpfc_##attr##_set(vport, val) == 0) \
  1621. return strlen(buf);\
  1622. else \
  1623. return -EINVAL;\
  1624. }
  1625. #define LPFC_ATTR(name, defval, minval, maxval, desc) \
  1626. static uint lpfc_##name = defval;\
  1627. module_param(lpfc_##name, uint, S_IRUGO);\
  1628. MODULE_PARM_DESC(lpfc_##name, desc);\
  1629. lpfc_param_init(name, defval, minval, maxval)
  1630. #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
  1631. static uint lpfc_##name = defval;\
  1632. module_param(lpfc_##name, uint, S_IRUGO);\
  1633. MODULE_PARM_DESC(lpfc_##name, desc);\
  1634. lpfc_param_show(name)\
  1635. lpfc_param_init(name, defval, minval, maxval)\
  1636. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1637. #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
  1638. static uint lpfc_##name = defval;\
  1639. module_param(lpfc_##name, uint, S_IRUGO);\
  1640. MODULE_PARM_DESC(lpfc_##name, desc);\
  1641. lpfc_param_show(name)\
  1642. lpfc_param_init(name, defval, minval, maxval)\
  1643. lpfc_param_set(name, defval, minval, maxval)\
  1644. lpfc_param_store(name)\
  1645. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  1646. lpfc_##name##_show, lpfc_##name##_store)
  1647. #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
  1648. static uint lpfc_##name = defval;\
  1649. module_param(lpfc_##name, uint, S_IRUGO);\
  1650. MODULE_PARM_DESC(lpfc_##name, desc);\
  1651. lpfc_param_hex_show(name)\
  1652. lpfc_param_init(name, defval, minval, maxval)\
  1653. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1654. #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
  1655. static uint lpfc_##name = defval;\
  1656. module_param(lpfc_##name, uint, S_IRUGO);\
  1657. MODULE_PARM_DESC(lpfc_##name, desc);\
  1658. lpfc_param_hex_show(name)\
  1659. lpfc_param_init(name, defval, minval, maxval)\
  1660. lpfc_param_set(name, defval, minval, maxval)\
  1661. lpfc_param_store(name)\
  1662. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  1663. lpfc_##name##_show, lpfc_##name##_store)
  1664. #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
  1665. static uint lpfc_##name = defval;\
  1666. module_param(lpfc_##name, uint, S_IRUGO);\
  1667. MODULE_PARM_DESC(lpfc_##name, desc);\
  1668. lpfc_vport_param_init(name, defval, minval, maxval)
  1669. #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
  1670. static uint lpfc_##name = defval;\
  1671. module_param(lpfc_##name, uint, S_IRUGO);\
  1672. MODULE_PARM_DESC(lpfc_##name, desc);\
  1673. lpfc_vport_param_show(name)\
  1674. lpfc_vport_param_init(name, defval, minval, maxval)\
  1675. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1676. #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
  1677. static uint lpfc_##name = defval;\
  1678. module_param(lpfc_##name, uint, S_IRUGO);\
  1679. MODULE_PARM_DESC(lpfc_##name, desc);\
  1680. lpfc_vport_param_show(name)\
  1681. lpfc_vport_param_init(name, defval, minval, maxval)\
  1682. lpfc_vport_param_set(name, defval, minval, maxval)\
  1683. lpfc_vport_param_store(name)\
  1684. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  1685. lpfc_##name##_show, lpfc_##name##_store)
  1686. #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
  1687. static uint lpfc_##name = defval;\
  1688. module_param(lpfc_##name, uint, S_IRUGO);\
  1689. MODULE_PARM_DESC(lpfc_##name, desc);\
  1690. lpfc_vport_param_hex_show(name)\
  1691. lpfc_vport_param_init(name, defval, minval, maxval)\
  1692. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  1693. #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
  1694. static uint lpfc_##name = defval;\
  1695. module_param(lpfc_##name, uint, S_IRUGO);\
  1696. MODULE_PARM_DESC(lpfc_##name, desc);\
  1697. lpfc_vport_param_hex_show(name)\
  1698. lpfc_vport_param_init(name, defval, minval, maxval)\
  1699. lpfc_vport_param_set(name, defval, minval, maxval)\
  1700. lpfc_vport_param_store(name)\
  1701. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  1702. lpfc_##name##_show, lpfc_##name##_store)
  1703. static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
  1704. static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
  1705. static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
  1706. static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
  1707. static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
  1708. static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
  1709. static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
  1710. static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
  1711. static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
  1712. static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
  1713. static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
  1714. static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
  1715. static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
  1716. lpfc_link_state_store);
  1717. static DEVICE_ATTR(option_rom_version, S_IRUGO,
  1718. lpfc_option_rom_version_show, NULL);
  1719. static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
  1720. lpfc_num_discovered_ports_show, NULL);
  1721. static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
  1722. static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
  1723. static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
  1724. static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
  1725. static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
  1726. lpfc_board_mode_show, lpfc_board_mode_store);
  1727. static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
  1728. static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
  1729. static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
  1730. static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
  1731. static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
  1732. static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
  1733. static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
  1734. static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
  1735. static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
  1736. static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
  1737. static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
  1738. static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
  1739. static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
  1740. lpfc_sriov_hw_max_virtfn_show, NULL);
  1741. static char *lpfc_soft_wwn_key = "C99G71SL8032A";
  1742. /**
  1743. * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
  1744. * @dev: class device that is converted into a Scsi_host.
  1745. * @attr: device attribute, not used.
  1746. * @buf: containing the string lpfc_soft_wwn_key.
  1747. * @count: must be size of lpfc_soft_wwn_key.
  1748. *
  1749. * Returns:
  1750. * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
  1751. * length of buf indicates success
  1752. **/
  1753. static ssize_t
  1754. lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
  1755. const char *buf, size_t count)
  1756. {
  1757. struct Scsi_Host *shost = class_to_shost(dev);
  1758. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1759. struct lpfc_hba *phba = vport->phba;
  1760. unsigned int cnt = count;
  1761. /*
  1762. * We're doing a simple sanity check for soft_wwpn setting.
  1763. * We require that the user write a specific key to enable
  1764. * the soft_wwpn attribute to be settable. Once the attribute
  1765. * is written, the enable key resets. If further updates are
  1766. * desired, the key must be written again to re-enable the
  1767. * attribute.
  1768. *
  1769. * The "key" is not secret - it is a hardcoded string shown
  1770. * here. The intent is to protect against the random user or
  1771. * application that is just writing attributes.
  1772. */
  1773. /* count may include a LF at end of string */
  1774. if (buf[cnt-1] == '\n')
  1775. cnt--;
  1776. if ((cnt != strlen(lpfc_soft_wwn_key)) ||
  1777. (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
  1778. return -EINVAL;
  1779. phba->soft_wwn_enable = 1;
  1780. return count;
  1781. }
  1782. static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
  1783. lpfc_soft_wwn_enable_store);
  1784. /**
  1785. * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
  1786. * @dev: class device that is converted into a Scsi_host.
  1787. * @attr: device attribute, not used.
  1788. * @buf: on return contains the wwpn in hexadecimal.
  1789. *
  1790. * Returns: size of formatted string.
  1791. **/
  1792. static ssize_t
  1793. lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
  1794. char *buf)
  1795. {
  1796. struct Scsi_Host *shost = class_to_shost(dev);
  1797. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1798. struct lpfc_hba *phba = vport->phba;
  1799. return snprintf(buf, PAGE_SIZE, "0x%llx\n",
  1800. (unsigned long long)phba->cfg_soft_wwpn);
  1801. }
  1802. /**
  1803. * lpfc_soft_wwpn_store - Set the ww port name of the adapter
  1804. * @dev class device that is converted into a Scsi_host.
  1805. * @attr: device attribute, not used.
  1806. * @buf: contains the wwpn in hexadecimal.
  1807. * @count: number of wwpn bytes in buf
  1808. *
  1809. * Returns:
  1810. * -EACCES hba reset not enabled, adapter over temp
  1811. * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
  1812. * -EIO error taking adapter offline or online
  1813. * value of count on success
  1814. **/
  1815. static ssize_t
  1816. lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
  1817. const char *buf, size_t count)
  1818. {
  1819. struct Scsi_Host *shost = class_to_shost(dev);
  1820. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1821. struct lpfc_hba *phba = vport->phba;
  1822. struct completion online_compl;
  1823. int stat1=0, stat2=0;
  1824. unsigned int i, j, cnt=count;
  1825. u8 wwpn[8];
  1826. int rc;
  1827. if (!phba->cfg_enable_hba_reset)
  1828. return -EACCES;
  1829. spin_lock_irq(&phba->hbalock);
  1830. if (phba->over_temp_state == HBA_OVER_TEMP) {
  1831. spin_unlock_irq(&phba->hbalock);
  1832. return -EACCES;
  1833. }
  1834. spin_unlock_irq(&phba->hbalock);
  1835. /* count may include a LF at end of string */
  1836. if (buf[cnt-1] == '\n')
  1837. cnt--;
  1838. if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
  1839. ((cnt == 17) && (*buf++ != 'x')) ||
  1840. ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
  1841. return -EINVAL;
  1842. phba->soft_wwn_enable = 0;
  1843. memset(wwpn, 0, sizeof(wwpn));
  1844. /* Validate and store the new name */
  1845. for (i=0, j=0; i < 16; i++) {
  1846. int value;
  1847. value = hex_to_bin(*buf++);
  1848. if (value >= 0)
  1849. j = (j << 4) | value;
  1850. else
  1851. return -EINVAL;
  1852. if (i % 2) {
  1853. wwpn[i/2] = j & 0xff;
  1854. j = 0;
  1855. }
  1856. }
  1857. phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
  1858. fc_host_port_name(shost) = phba->cfg_soft_wwpn;
  1859. if (phba->cfg_soft_wwnn)
  1860. fc_host_node_name(shost) = phba->cfg_soft_wwnn;
  1861. dev_printk(KERN_NOTICE, &phba->pcidev->dev,
  1862. "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
  1863. stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  1864. if (stat1)
  1865. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1866. "0463 lpfc_soft_wwpn attribute set failed to "
  1867. "reinit adapter - %d\n", stat1);
  1868. init_completion(&online_compl);
  1869. rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
  1870. LPFC_EVT_ONLINE);
  1871. if (rc == 0)
  1872. return -ENOMEM;
  1873. wait_for_completion(&online_compl);
  1874. if (stat2)
  1875. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1876. "0464 lpfc_soft_wwpn attribute set failed to "
  1877. "reinit adapter - %d\n", stat2);
  1878. return (stat1 || stat2) ? -EIO : count;
  1879. }
  1880. static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
  1881. lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
  1882. /**
  1883. * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
  1884. * @dev: class device that is converted into a Scsi_host.
  1885. * @attr: device attribute, not used.
  1886. * @buf: on return contains the wwnn in hexadecimal.
  1887. *
  1888. * Returns: size of formatted string.
  1889. **/
  1890. static ssize_t
  1891. lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
  1892. char *buf)
  1893. {
  1894. struct Scsi_Host *shost = class_to_shost(dev);
  1895. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  1896. return snprintf(buf, PAGE_SIZE, "0x%llx\n",
  1897. (unsigned long long)phba->cfg_soft_wwnn);
  1898. }
  1899. /**
  1900. * lpfc_soft_wwnn_store - sets the ww node name of the adapter
  1901. * @cdev: class device that is converted into a Scsi_host.
  1902. * @buf: contains the ww node name in hexadecimal.
  1903. * @count: number of wwnn bytes in buf.
  1904. *
  1905. * Returns:
  1906. * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
  1907. * value of count on success
  1908. **/
  1909. static ssize_t
  1910. lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
  1911. const char *buf, size_t count)
  1912. {
  1913. struct Scsi_Host *shost = class_to_shost(dev);
  1914. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  1915. unsigned int i, j, cnt=count;
  1916. u8 wwnn[8];
  1917. /* count may include a LF at end of string */
  1918. if (buf[cnt-1] == '\n')
  1919. cnt--;
  1920. if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
  1921. ((cnt == 17) && (*buf++ != 'x')) ||
  1922. ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
  1923. return -EINVAL;
  1924. /*
  1925. * Allow wwnn to be set many times, as long as the enable is set.
  1926. * However, once the wwpn is set, everything locks.
  1927. */
  1928. memset(wwnn, 0, sizeof(wwnn));
  1929. /* Validate and store the new name */
  1930. for (i=0, j=0; i < 16; i++) {
  1931. int value;
  1932. value = hex_to_bin(*buf++);
  1933. if (value >= 0)
  1934. j = (j << 4) | value;
  1935. else
  1936. return -EINVAL;
  1937. if (i % 2) {
  1938. wwnn[i/2] = j & 0xff;
  1939. j = 0;
  1940. }
  1941. }
  1942. phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
  1943. dev_printk(KERN_NOTICE, &phba->pcidev->dev,
  1944. "lpfc%d: soft_wwnn set. Value will take effect upon "
  1945. "setting of the soft_wwpn\n", phba->brd_no);
  1946. return count;
  1947. }
  1948. static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
  1949. lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
  1950. static int lpfc_poll = 0;
  1951. module_param(lpfc_poll, int, S_IRUGO);
  1952. MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
  1953. " 0 - none,"
  1954. " 1 - poll with interrupts enabled"
  1955. " 3 - poll and disable FCP ring interrupts");
  1956. static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
  1957. lpfc_poll_show, lpfc_poll_store);
  1958. int lpfc_sli_mode = 0;
  1959. module_param(lpfc_sli_mode, int, S_IRUGO);
  1960. MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
  1961. " 0 - auto (SLI-3 if supported),"
  1962. " 2 - select SLI-2 even on SLI-3 capable HBAs,"
  1963. " 3 - select SLI-3");
  1964. int lpfc_enable_npiv = 1;
  1965. module_param(lpfc_enable_npiv, int, S_IRUGO);
  1966. MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
  1967. lpfc_param_show(enable_npiv);
  1968. lpfc_param_init(enable_npiv, 1, 0, 1);
  1969. static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
  1970. int lpfc_enable_rrq;
  1971. module_param(lpfc_enable_rrq, int, S_IRUGO);
  1972. MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
  1973. lpfc_param_show(enable_rrq);
  1974. lpfc_param_init(enable_rrq, 0, 0, 1);
  1975. static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
  1976. /*
  1977. # lpfc_suppress_link_up: Bring link up at initialization
  1978. # 0x0 = bring link up (issue MBX_INIT_LINK)
  1979. # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
  1980. # 0x2 = never bring up link
  1981. # Default value is 0.
  1982. */
  1983. LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
  1984. LPFC_DELAY_INIT_LINK_INDEFINITELY,
  1985. "Suppress Link Up at initialization");
  1986. /*
  1987. # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
  1988. # 1 - (1024)
  1989. # 2 - (2048)
  1990. # 3 - (3072)
  1991. # 4 - (4096)
  1992. # 5 - (5120)
  1993. */
  1994. static ssize_t
  1995. lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
  1996. {
  1997. struct Scsi_Host *shost = class_to_shost(dev);
  1998. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  1999. return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
  2000. }
  2001. static DEVICE_ATTR(iocb_hw, S_IRUGO,
  2002. lpfc_iocb_hw_show, NULL);
  2003. static ssize_t
  2004. lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
  2005. {
  2006. struct Scsi_Host *shost = class_to_shost(dev);
  2007. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  2008. return snprintf(buf, PAGE_SIZE, "%d\n",
  2009. phba->sli.ring[LPFC_ELS_RING].txq_max);
  2010. }
  2011. static DEVICE_ATTR(txq_hw, S_IRUGO,
  2012. lpfc_txq_hw_show, NULL);
  2013. static ssize_t
  2014. lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
  2015. char *buf)
  2016. {
  2017. struct Scsi_Host *shost = class_to_shost(dev);
  2018. struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
  2019. return snprintf(buf, PAGE_SIZE, "%d\n",
  2020. phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
  2021. }
  2022. static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
  2023. lpfc_txcmplq_hw_show, NULL);
  2024. int lpfc_iocb_cnt = 2;
  2025. module_param(lpfc_iocb_cnt, int, S_IRUGO);
  2026. MODULE_PARM_DESC(lpfc_iocb_cnt,
  2027. "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
  2028. lpfc_param_show(iocb_cnt);
  2029. lpfc_param_init(iocb_cnt, 2, 1, 5);
  2030. static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
  2031. lpfc_iocb_cnt_show, NULL);
  2032. /*
  2033. # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
  2034. # until the timer expires. Value range is [0,255]. Default value is 30.
  2035. */
  2036. static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
  2037. static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
  2038. module_param(lpfc_nodev_tmo, int, 0);
  2039. MODULE_PARM_DESC(lpfc_nodev_tmo,
  2040. "Seconds driver will hold I/O waiting "
  2041. "for a device to come back");
  2042. /**
  2043. * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
  2044. * @dev: class converted to a Scsi_host structure.
  2045. * @attr: device attribute, not used.
  2046. * @buf: on return contains the dev loss timeout in decimal.
  2047. *
  2048. * Returns: size of formatted string.
  2049. **/
  2050. static ssize_t
  2051. lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
  2052. char *buf)
  2053. {
  2054. struct Scsi_Host *shost = class_to_shost(dev);
  2055. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2056. return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
  2057. }
  2058. /**
  2059. * lpfc_nodev_tmo_init - Set the hba nodev timeout value
  2060. * @vport: lpfc vport structure pointer.
  2061. * @val: contains the nodev timeout value.
  2062. *
  2063. * Description:
  2064. * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
  2065. * a kernel error message is printed and zero is returned.
  2066. * Else if val is in range then nodev tmo and devloss tmo are set to val.
  2067. * Otherwise nodev tmo is set to the default value.
  2068. *
  2069. * Returns:
  2070. * zero if already set or if val is in range
  2071. * -EINVAL val out of range
  2072. **/
  2073. static int
  2074. lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
  2075. {
  2076. if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
  2077. vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
  2078. if (val != LPFC_DEF_DEVLOSS_TMO)
  2079. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2080. "0407 Ignoring nodev_tmo module "
  2081. "parameter because devloss_tmo is "
  2082. "set.\n");
  2083. return 0;
  2084. }
  2085. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  2086. vport->cfg_nodev_tmo = val;
  2087. vport->cfg_devloss_tmo = val;
  2088. return 0;
  2089. }
  2090. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2091. "0400 lpfc_nodev_tmo attribute cannot be set to"
  2092. " %d, allowed range is [%d, %d]\n",
  2093. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  2094. vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
  2095. return -EINVAL;
  2096. }
  2097. /**
  2098. * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
  2099. * @vport: lpfc vport structure pointer.
  2100. *
  2101. * Description:
  2102. * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
  2103. **/
  2104. static void
  2105. lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
  2106. {
  2107. struct Scsi_Host *shost;
  2108. struct lpfc_nodelist *ndlp;
  2109. shost = lpfc_shost_from_vport(vport);
  2110. spin_lock_irq(shost->host_lock);
  2111. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
  2112. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
  2113. ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
  2114. spin_unlock_irq(shost->host_lock);
  2115. }
  2116. /**
  2117. * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
  2118. * @vport: lpfc vport structure pointer.
  2119. * @val: contains the tmo value.
  2120. *
  2121. * Description:
  2122. * If the devloss tmo is already set or the vport dev loss tmo has changed
  2123. * then a kernel error message is printed and zero is returned.
  2124. * Else if val is in range then nodev tmo and devloss tmo are set to val.
  2125. * Otherwise nodev tmo is set to the default value.
  2126. *
  2127. * Returns:
  2128. * zero if already set or if val is in range
  2129. * -EINVAL val out of range
  2130. **/
  2131. static int
  2132. lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
  2133. {
  2134. if (vport->dev_loss_tmo_changed ||
  2135. (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
  2136. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2137. "0401 Ignoring change to nodev_tmo "
  2138. "because devloss_tmo is set.\n");
  2139. return 0;
  2140. }
  2141. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  2142. vport->cfg_nodev_tmo = val;
  2143. vport->cfg_devloss_tmo = val;
  2144. /*
  2145. * For compat: set the fc_host dev loss so new rports
  2146. * will get the value.
  2147. */
  2148. fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
  2149. lpfc_update_rport_devloss_tmo(vport);
  2150. return 0;
  2151. }
  2152. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2153. "0403 lpfc_nodev_tmo attribute cannot be set to"
  2154. "%d, allowed range is [%d, %d]\n",
  2155. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  2156. return -EINVAL;
  2157. }
  2158. lpfc_vport_param_store(nodev_tmo)
  2159. static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
  2160. lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
  2161. /*
  2162. # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
  2163. # disappear until the timer expires. Value range is [0,255]. Default
  2164. # value is 30.
  2165. */
  2166. module_param(lpfc_devloss_tmo, int, S_IRUGO);
  2167. MODULE_PARM_DESC(lpfc_devloss_tmo,
  2168. "Seconds driver will hold I/O waiting "
  2169. "for a device to come back");
  2170. lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
  2171. LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
  2172. lpfc_vport_param_show(devloss_tmo)
  2173. /**
  2174. * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
  2175. * @vport: lpfc vport structure pointer.
  2176. * @val: contains the tmo value.
  2177. *
  2178. * Description:
  2179. * If val is in a valid range then set the vport nodev tmo,
  2180. * devloss tmo, also set the vport dev loss tmo changed flag.
  2181. * Else a kernel error message is printed.
  2182. *
  2183. * Returns:
  2184. * zero if val is in range
  2185. * -EINVAL val out of range
  2186. **/
  2187. static int
  2188. lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
  2189. {
  2190. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  2191. vport->cfg_nodev_tmo = val;
  2192. vport->cfg_devloss_tmo = val;
  2193. vport->dev_loss_tmo_changed = 1;
  2194. fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
  2195. lpfc_update_rport_devloss_tmo(vport);
  2196. return 0;
  2197. }
  2198. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2199. "0404 lpfc_devloss_tmo attribute cannot be set to"
  2200. " %d, allowed range is [%d, %d]\n",
  2201. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  2202. return -EINVAL;
  2203. }
  2204. lpfc_vport_param_store(devloss_tmo)
  2205. static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
  2206. lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
  2207. /*
  2208. # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
  2209. # deluged with LOTS of information.
  2210. # You can set a bit mask to record specific types of verbose messages:
  2211. # See lpfc_logmsh.h for definitions.
  2212. */
  2213. LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
  2214. "Verbose logging bit-mask");
  2215. /*
  2216. # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
  2217. # objects that have been registered with the nameserver after login.
  2218. */
  2219. LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
  2220. "Deregister nameserver objects before LOGO");
  2221. /*
  2222. # lun_queue_depth: This parameter is used to limit the number of outstanding
  2223. # commands per FCP LUN. Value range is [1,128]. Default value is 30.
  2224. */
  2225. LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
  2226. "Max number of FCP commands we can queue to a specific LUN");
  2227. /*
  2228. # tgt_queue_depth: This parameter is used to limit the number of outstanding
  2229. # commands per target port. Value range is [10,65535]. Default value is 65535.
  2230. */
  2231. LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
  2232. "Max number of FCP commands we can queue to a specific target port");
  2233. /*
  2234. # hba_queue_depth: This parameter is used to limit the number of outstanding
  2235. # commands per lpfc HBA. Value range is [32,8192]. If this parameter
  2236. # value is greater than the maximum number of exchanges supported by the HBA,
  2237. # then maximum number of exchanges supported by the HBA is used to determine
  2238. # the hba_queue_depth.
  2239. */
  2240. LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
  2241. "Max number of FCP commands we can queue to a lpfc HBA");
  2242. /*
  2243. # peer_port_login: This parameter allows/prevents logins
  2244. # between peer ports hosted on the same physical port.
  2245. # When this parameter is set 0 peer ports of same physical port
  2246. # are not allowed to login to each other.
  2247. # When this parameter is set 1 peer ports of same physical port
  2248. # are allowed to login to each other.
  2249. # Default value of this parameter is 0.
  2250. */
  2251. LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
  2252. "Allow peer ports on the same physical port to login to each "
  2253. "other.");
  2254. /*
  2255. # restrict_login: This parameter allows/prevents logins
  2256. # between Virtual Ports and remote initiators.
  2257. # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
  2258. # other initiators and will attempt to PLOGI all remote ports.
  2259. # When this parameter is set (1) Virtual Ports will reject PLOGIs from
  2260. # remote ports and will not attempt to PLOGI to other initiators.
  2261. # This parameter does not restrict to the physical port.
  2262. # This parameter does not restrict logins to Fabric resident remote ports.
  2263. # Default value of this parameter is 1.
  2264. */
  2265. static int lpfc_restrict_login = 1;
  2266. module_param(lpfc_restrict_login, int, S_IRUGO);
  2267. MODULE_PARM_DESC(lpfc_restrict_login,
  2268. "Restrict virtual ports login to remote initiators.");
  2269. lpfc_vport_param_show(restrict_login);
  2270. /**
  2271. * lpfc_restrict_login_init - Set the vport restrict login flag
  2272. * @vport: lpfc vport structure pointer.
  2273. * @val: contains the restrict login value.
  2274. *
  2275. * Description:
  2276. * If val is not in a valid range then log a kernel error message and set
  2277. * the vport restrict login to one.
  2278. * If the port type is physical clear the restrict login flag and return.
  2279. * Else set the restrict login flag to val.
  2280. *
  2281. * Returns:
  2282. * zero if val is in range
  2283. * -EINVAL val out of range
  2284. **/
  2285. static int
  2286. lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
  2287. {
  2288. if (val < 0 || val > 1) {
  2289. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2290. "0422 lpfc_restrict_login attribute cannot "
  2291. "be set to %d, allowed range is [0, 1]\n",
  2292. val);
  2293. vport->cfg_restrict_login = 1;
  2294. return -EINVAL;
  2295. }
  2296. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2297. vport->cfg_restrict_login = 0;
  2298. return 0;
  2299. }
  2300. vport->cfg_restrict_login = val;
  2301. return 0;
  2302. }
  2303. /**
  2304. * lpfc_restrict_login_set - Set the vport restrict login flag
  2305. * @vport: lpfc vport structure pointer.
  2306. * @val: contains the restrict login value.
  2307. *
  2308. * Description:
  2309. * If val is not in a valid range then log a kernel error message and set
  2310. * the vport restrict login to one.
  2311. * If the port type is physical and the val is not zero log a kernel
  2312. * error message, clear the restrict login flag and return zero.
  2313. * Else set the restrict login flag to val.
  2314. *
  2315. * Returns:
  2316. * zero if val is in range
  2317. * -EINVAL val out of range
  2318. **/
  2319. static int
  2320. lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
  2321. {
  2322. if (val < 0 || val > 1) {
  2323. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2324. "0425 lpfc_restrict_login attribute cannot "
  2325. "be set to %d, allowed range is [0, 1]\n",
  2326. val);
  2327. vport->cfg_restrict_login = 1;
  2328. return -EINVAL;
  2329. }
  2330. if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
  2331. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2332. "0468 lpfc_restrict_login must be 0 for "
  2333. "Physical ports.\n");
  2334. vport->cfg_restrict_login = 0;
  2335. return 0;
  2336. }
  2337. vport->cfg_restrict_login = val;
  2338. return 0;
  2339. }
  2340. lpfc_vport_param_store(restrict_login);
  2341. static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
  2342. lpfc_restrict_login_show, lpfc_restrict_login_store);
  2343. /*
  2344. # Some disk devices have a "select ID" or "select Target" capability.
  2345. # From a protocol standpoint "select ID" usually means select the
  2346. # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
  2347. # annex" which contains a table that maps a "select ID" (a number
  2348. # between 0 and 7F) to an ALPA. By default, for compatibility with
  2349. # older drivers, the lpfc driver scans this table from low ALPA to high
  2350. # ALPA.
  2351. #
  2352. # Turning on the scan-down variable (on = 1, off = 0) will
  2353. # cause the lpfc driver to use an inverted table, effectively
  2354. # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
  2355. #
  2356. # (Note: This "select ID" functionality is a LOOP ONLY characteristic
  2357. # and will not work across a fabric. Also this parameter will take
  2358. # effect only in the case when ALPA map is not available.)
  2359. */
  2360. LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
  2361. "Start scanning for devices from highest ALPA to lowest");
  2362. /*
  2363. # lpfc_topology: link topology for init link
  2364. # 0x0 = attempt loop mode then point-to-point
  2365. # 0x01 = internal loopback mode
  2366. # 0x02 = attempt point-to-point mode only
  2367. # 0x04 = attempt loop mode only
  2368. # 0x06 = attempt point-to-point mode then loop
  2369. # Set point-to-point mode if you want to run as an N_Port.
  2370. # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
  2371. # Default value is 0.
  2372. */
  2373. /**
  2374. * lpfc_topology_set - Set the adapters topology field
  2375. * @phba: lpfc_hba pointer.
  2376. * @val: topology value.
  2377. *
  2378. * Description:
  2379. * If val is in a valid range then set the adapter's topology field and
  2380. * issue a lip; if the lip fails reset the topology to the old value.
  2381. *
  2382. * If the value is not in range log a kernel error message and return an error.
  2383. *
  2384. * Returns:
  2385. * zero if val is in range and lip okay
  2386. * non-zero return value from lpfc_issue_lip()
  2387. * -EINVAL val out of range
  2388. **/
  2389. static ssize_t
  2390. lpfc_topology_store(struct device *dev, struct device_attribute *attr,
  2391. const char *buf, size_t count)
  2392. {
  2393. struct Scsi_Host *shost = class_to_shost(dev);
  2394. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2395. struct lpfc_hba *phba = vport->phba;
  2396. int val = 0;
  2397. int nolip = 0;
  2398. const char *val_buf = buf;
  2399. int err;
  2400. uint32_t prev_val;
  2401. if (!strncmp(buf, "nolip ", strlen("nolip "))) {
  2402. nolip = 1;
  2403. val_buf = &buf[strlen("nolip ")];
  2404. }
  2405. if (!isdigit(val_buf[0]))
  2406. return -EINVAL;
  2407. if (sscanf(val_buf, "%i", &val) != 1)
  2408. return -EINVAL;
  2409. if (val >= 0 && val <= 6) {
  2410. prev_val = phba->cfg_topology;
  2411. phba->cfg_topology = val;
  2412. if (nolip)
  2413. return strlen(buf);
  2414. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2415. "3054 lpfc_topology changed from %d to %d\n",
  2416. prev_val, val);
  2417. err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
  2418. if (err) {
  2419. phba->cfg_topology = prev_val;
  2420. return -EINVAL;
  2421. } else
  2422. return strlen(buf);
  2423. }
  2424. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2425. "%d:0467 lpfc_topology attribute cannot be set to %d, "
  2426. "allowed range is [0, 6]\n",
  2427. phba->brd_no, val);
  2428. return -EINVAL;
  2429. }
  2430. static int lpfc_topology = 0;
  2431. module_param(lpfc_topology, int, S_IRUGO);
  2432. MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
  2433. lpfc_param_show(topology)
  2434. lpfc_param_init(topology, 0, 0, 6)
  2435. static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
  2436. lpfc_topology_show, lpfc_topology_store);
  2437. /**
  2438. * lpfc_static_vport_show: Read callback function for
  2439. * lpfc_static_vport sysfs file.
  2440. * @dev: Pointer to class device object.
  2441. * @attr: device attribute structure.
  2442. * @buf: Data buffer.
  2443. *
  2444. * This function is the read call back function for
  2445. * lpfc_static_vport sysfs file. The lpfc_static_vport
  2446. * sysfs file report the mageability of the vport.
  2447. **/
  2448. static ssize_t
  2449. lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
  2450. char *buf)
  2451. {
  2452. struct Scsi_Host *shost = class_to_shost(dev);
  2453. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2454. if (vport->vport_flag & STATIC_VPORT)
  2455. sprintf(buf, "1\n");
  2456. else
  2457. sprintf(buf, "0\n");
  2458. return strlen(buf);
  2459. }
  2460. /*
  2461. * Sysfs attribute to control the statistical data collection.
  2462. */
  2463. static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
  2464. lpfc_static_vport_show, NULL);
  2465. /**
  2466. * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
  2467. * @dev: Pointer to class device.
  2468. * @buf: Data buffer.
  2469. * @count: Size of the data buffer.
  2470. *
  2471. * This function get called when an user write to the lpfc_stat_data_ctrl
  2472. * sysfs file. This function parse the command written to the sysfs file
  2473. * and take appropriate action. These commands are used for controlling
  2474. * driver statistical data collection.
  2475. * Following are the command this function handles.
  2476. *
  2477. * setbucket <bucket_type> <base> <step>
  2478. * = Set the latency buckets.
  2479. * destroybucket = destroy all the buckets.
  2480. * start = start data collection
  2481. * stop = stop data collection
  2482. * reset = reset the collected data
  2483. **/
  2484. static ssize_t
  2485. lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
  2486. const char *buf, size_t count)
  2487. {
  2488. struct Scsi_Host *shost = class_to_shost(dev);
  2489. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2490. struct lpfc_hba *phba = vport->phba;
  2491. #define LPFC_MAX_DATA_CTRL_LEN 1024
  2492. static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
  2493. unsigned long i;
  2494. char *str_ptr, *token;
  2495. struct lpfc_vport **vports;
  2496. struct Scsi_Host *v_shost;
  2497. char *bucket_type_str, *base_str, *step_str;
  2498. unsigned long base, step, bucket_type;
  2499. if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
  2500. if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
  2501. return -EINVAL;
  2502. strcpy(bucket_data, buf);
  2503. str_ptr = &bucket_data[0];
  2504. /* Ignore this token - this is command token */
  2505. token = strsep(&str_ptr, "\t ");
  2506. if (!token)
  2507. return -EINVAL;
  2508. bucket_type_str = strsep(&str_ptr, "\t ");
  2509. if (!bucket_type_str)
  2510. return -EINVAL;
  2511. if (!strncmp(bucket_type_str, "linear", strlen("linear")))
  2512. bucket_type = LPFC_LINEAR_BUCKET;
  2513. else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
  2514. bucket_type = LPFC_POWER2_BUCKET;
  2515. else
  2516. return -EINVAL;
  2517. base_str = strsep(&str_ptr, "\t ");
  2518. if (!base_str)
  2519. return -EINVAL;
  2520. base = simple_strtoul(base_str, NULL, 0);
  2521. step_str = strsep(&str_ptr, "\t ");
  2522. if (!step_str)
  2523. return -EINVAL;
  2524. step = simple_strtoul(step_str, NULL, 0);
  2525. if (!step)
  2526. return -EINVAL;
  2527. /* Block the data collection for every vport */
  2528. vports = lpfc_create_vport_work_array(phba);
  2529. if (vports == NULL)
  2530. return -ENOMEM;
  2531. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2532. v_shost = lpfc_shost_from_vport(vports[i]);
  2533. spin_lock_irq(v_shost->host_lock);
  2534. /* Block and reset data collection */
  2535. vports[i]->stat_data_blocked = 1;
  2536. if (vports[i]->stat_data_enabled)
  2537. lpfc_vport_reset_stat_data(vports[i]);
  2538. spin_unlock_irq(v_shost->host_lock);
  2539. }
  2540. /* Set the bucket attributes */
  2541. phba->bucket_type = bucket_type;
  2542. phba->bucket_base = base;
  2543. phba->bucket_step = step;
  2544. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2545. v_shost = lpfc_shost_from_vport(vports[i]);
  2546. /* Unblock data collection */
  2547. spin_lock_irq(v_shost->host_lock);
  2548. vports[i]->stat_data_blocked = 0;
  2549. spin_unlock_irq(v_shost->host_lock);
  2550. }
  2551. lpfc_destroy_vport_work_array(phba, vports);
  2552. return strlen(buf);
  2553. }
  2554. if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
  2555. vports = lpfc_create_vport_work_array(phba);
  2556. if (vports == NULL)
  2557. return -ENOMEM;
  2558. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2559. v_shost = lpfc_shost_from_vport(vports[i]);
  2560. spin_lock_irq(shost->host_lock);
  2561. vports[i]->stat_data_blocked = 1;
  2562. lpfc_free_bucket(vport);
  2563. vport->stat_data_enabled = 0;
  2564. vports[i]->stat_data_blocked = 0;
  2565. spin_unlock_irq(shost->host_lock);
  2566. }
  2567. lpfc_destroy_vport_work_array(phba, vports);
  2568. phba->bucket_type = LPFC_NO_BUCKET;
  2569. phba->bucket_base = 0;
  2570. phba->bucket_step = 0;
  2571. return strlen(buf);
  2572. }
  2573. if (!strncmp(buf, "start", strlen("start"))) {
  2574. /* If no buckets configured return error */
  2575. if (phba->bucket_type == LPFC_NO_BUCKET)
  2576. return -EINVAL;
  2577. spin_lock_irq(shost->host_lock);
  2578. if (vport->stat_data_enabled) {
  2579. spin_unlock_irq(shost->host_lock);
  2580. return strlen(buf);
  2581. }
  2582. lpfc_alloc_bucket(vport);
  2583. vport->stat_data_enabled = 1;
  2584. spin_unlock_irq(shost->host_lock);
  2585. return strlen(buf);
  2586. }
  2587. if (!strncmp(buf, "stop", strlen("stop"))) {
  2588. spin_lock_irq(shost->host_lock);
  2589. if (vport->stat_data_enabled == 0) {
  2590. spin_unlock_irq(shost->host_lock);
  2591. return strlen(buf);
  2592. }
  2593. lpfc_free_bucket(vport);
  2594. vport->stat_data_enabled = 0;
  2595. spin_unlock_irq(shost->host_lock);
  2596. return strlen(buf);
  2597. }
  2598. if (!strncmp(buf, "reset", strlen("reset"))) {
  2599. if ((phba->bucket_type == LPFC_NO_BUCKET)
  2600. || !vport->stat_data_enabled)
  2601. return strlen(buf);
  2602. spin_lock_irq(shost->host_lock);
  2603. vport->stat_data_blocked = 1;
  2604. lpfc_vport_reset_stat_data(vport);
  2605. vport->stat_data_blocked = 0;
  2606. spin_unlock_irq(shost->host_lock);
  2607. return strlen(buf);
  2608. }
  2609. return -EINVAL;
  2610. }
  2611. /**
  2612. * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
  2613. * @dev: Pointer to class device object.
  2614. * @buf: Data buffer.
  2615. *
  2616. * This function is the read call back function for
  2617. * lpfc_stat_data_ctrl sysfs file. This function report the
  2618. * current statistical data collection state.
  2619. **/
  2620. static ssize_t
  2621. lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
  2622. char *buf)
  2623. {
  2624. struct Scsi_Host *shost = class_to_shost(dev);
  2625. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2626. struct lpfc_hba *phba = vport->phba;
  2627. int index = 0;
  2628. int i;
  2629. char *bucket_type;
  2630. unsigned long bucket_value;
  2631. switch (phba->bucket_type) {
  2632. case LPFC_LINEAR_BUCKET:
  2633. bucket_type = "linear";
  2634. break;
  2635. case LPFC_POWER2_BUCKET:
  2636. bucket_type = "power2";
  2637. break;
  2638. default:
  2639. bucket_type = "No Bucket";
  2640. break;
  2641. }
  2642. sprintf(&buf[index], "Statistical Data enabled :%d, "
  2643. "blocked :%d, Bucket type :%s, Bucket base :%d,"
  2644. " Bucket step :%d\nLatency Ranges :",
  2645. vport->stat_data_enabled, vport->stat_data_blocked,
  2646. bucket_type, phba->bucket_base, phba->bucket_step);
  2647. index = strlen(buf);
  2648. if (phba->bucket_type != LPFC_NO_BUCKET) {
  2649. for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
  2650. if (phba->bucket_type == LPFC_LINEAR_BUCKET)
  2651. bucket_value = phba->bucket_base +
  2652. phba->bucket_step * i;
  2653. else
  2654. bucket_value = phba->bucket_base +
  2655. (1 << i) * phba->bucket_step;
  2656. if (index + 10 > PAGE_SIZE)
  2657. break;
  2658. sprintf(&buf[index], "%08ld ", bucket_value);
  2659. index = strlen(buf);
  2660. }
  2661. }
  2662. sprintf(&buf[index], "\n");
  2663. return strlen(buf);
  2664. }
  2665. /*
  2666. * Sysfs attribute to control the statistical data collection.
  2667. */
  2668. static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
  2669. lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
  2670. /*
  2671. * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
  2672. */
  2673. /*
  2674. * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
  2675. * for each target.
  2676. */
  2677. #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
  2678. #define MAX_STAT_DATA_SIZE_PER_TARGET \
  2679. STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
  2680. /**
  2681. * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
  2682. * @filp: sysfs file
  2683. * @kobj: Pointer to the kernel object
  2684. * @bin_attr: Attribute object
  2685. * @buff: Buffer pointer
  2686. * @off: File offset
  2687. * @count: Buffer size
  2688. *
  2689. * This function is the read call back function for lpfc_drvr_stat_data
  2690. * sysfs file. This function export the statistical data to user
  2691. * applications.
  2692. **/
  2693. static ssize_t
  2694. sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
  2695. struct bin_attribute *bin_attr,
  2696. char *buf, loff_t off, size_t count)
  2697. {
  2698. struct device *dev = container_of(kobj, struct device,
  2699. kobj);
  2700. struct Scsi_Host *shost = class_to_shost(dev);
  2701. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2702. struct lpfc_hba *phba = vport->phba;
  2703. int i = 0, index = 0;
  2704. unsigned long nport_index;
  2705. struct lpfc_nodelist *ndlp = NULL;
  2706. nport_index = (unsigned long)off /
  2707. MAX_STAT_DATA_SIZE_PER_TARGET;
  2708. if (!vport->stat_data_enabled || vport->stat_data_blocked
  2709. || (phba->bucket_type == LPFC_NO_BUCKET))
  2710. return 0;
  2711. spin_lock_irq(shost->host_lock);
  2712. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2713. if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
  2714. continue;
  2715. if (nport_index > 0) {
  2716. nport_index--;
  2717. continue;
  2718. }
  2719. if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
  2720. > count)
  2721. break;
  2722. if (!ndlp->lat_data)
  2723. continue;
  2724. /* Print the WWN */
  2725. sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
  2726. ndlp->nlp_portname.u.wwn[0],
  2727. ndlp->nlp_portname.u.wwn[1],
  2728. ndlp->nlp_portname.u.wwn[2],
  2729. ndlp->nlp_portname.u.wwn[3],
  2730. ndlp->nlp_portname.u.wwn[4],
  2731. ndlp->nlp_portname.u.wwn[5],
  2732. ndlp->nlp_portname.u.wwn[6],
  2733. ndlp->nlp_portname.u.wwn[7]);
  2734. index = strlen(buf);
  2735. for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
  2736. sprintf(&buf[index], "%010u,",
  2737. ndlp->lat_data[i].cmd_count);
  2738. index = strlen(buf);
  2739. }
  2740. sprintf(&buf[index], "\n");
  2741. index = strlen(buf);
  2742. }
  2743. spin_unlock_irq(shost->host_lock);
  2744. return index;
  2745. }
  2746. static struct bin_attribute sysfs_drvr_stat_data_attr = {
  2747. .attr = {
  2748. .name = "lpfc_drvr_stat_data",
  2749. .mode = S_IRUSR,
  2750. },
  2751. .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
  2752. .read = sysfs_drvr_stat_data_read,
  2753. .write = NULL,
  2754. };
  2755. /*
  2756. # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
  2757. # connection.
  2758. # Value range is [0,16]. Default value is 0.
  2759. */
  2760. /**
  2761. * lpfc_link_speed_set - Set the adapters link speed
  2762. * @phba: lpfc_hba pointer.
  2763. * @val: link speed value.
  2764. *
  2765. * Description:
  2766. * If val is in a valid range then set the adapter's link speed field and
  2767. * issue a lip; if the lip fails reset the link speed to the old value.
  2768. *
  2769. * Notes:
  2770. * If the value is not in range log a kernel error message and return an error.
  2771. *
  2772. * Returns:
  2773. * zero if val is in range and lip okay.
  2774. * non-zero return value from lpfc_issue_lip()
  2775. * -EINVAL val out of range
  2776. **/
  2777. static ssize_t
  2778. lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
  2779. const char *buf, size_t count)
  2780. {
  2781. struct Scsi_Host *shost = class_to_shost(dev);
  2782. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2783. struct lpfc_hba *phba = vport->phba;
  2784. int val = LPFC_USER_LINK_SPEED_AUTO;
  2785. int nolip = 0;
  2786. const char *val_buf = buf;
  2787. int err;
  2788. uint32_t prev_val;
  2789. if (!strncmp(buf, "nolip ", strlen("nolip "))) {
  2790. nolip = 1;
  2791. val_buf = &buf[strlen("nolip ")];
  2792. }
  2793. if (!isdigit(val_buf[0]))
  2794. return -EINVAL;
  2795. if (sscanf(val_buf, "%i", &val) != 1)
  2796. return -EINVAL;
  2797. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  2798. "3055 lpfc_link_speed changed from %d to %d %s\n",
  2799. phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
  2800. if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
  2801. ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
  2802. ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
  2803. ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
  2804. ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
  2805. ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
  2806. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2807. "2879 lpfc_link_speed attribute cannot be set "
  2808. "to %d. Speed is not supported by this port.\n",
  2809. val);
  2810. return -EINVAL;
  2811. }
  2812. if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
  2813. (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
  2814. prev_val = phba->cfg_link_speed;
  2815. phba->cfg_link_speed = val;
  2816. if (nolip)
  2817. return strlen(buf);
  2818. err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
  2819. if (err) {
  2820. phba->cfg_link_speed = prev_val;
  2821. return -EINVAL;
  2822. } else
  2823. return strlen(buf);
  2824. }
  2825. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2826. "0469 lpfc_link_speed attribute cannot be set to %d, "
  2827. "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
  2828. return -EINVAL;
  2829. }
  2830. static int lpfc_link_speed = 0;
  2831. module_param(lpfc_link_speed, int, S_IRUGO);
  2832. MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
  2833. lpfc_param_show(link_speed)
  2834. /**
  2835. * lpfc_link_speed_init - Set the adapters link speed
  2836. * @phba: lpfc_hba pointer.
  2837. * @val: link speed value.
  2838. *
  2839. * Description:
  2840. * If val is in a valid range then set the adapter's link speed field.
  2841. *
  2842. * Notes:
  2843. * If the value is not in range log a kernel error message, clear the link
  2844. * speed and return an error.
  2845. *
  2846. * Returns:
  2847. * zero if val saved.
  2848. * -EINVAL val out of range
  2849. **/
  2850. static int
  2851. lpfc_link_speed_init(struct lpfc_hba *phba, int val)
  2852. {
  2853. if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
  2854. (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
  2855. phba->cfg_link_speed = val;
  2856. return 0;
  2857. }
  2858. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2859. "0405 lpfc_link_speed attribute cannot "
  2860. "be set to %d, allowed values are "
  2861. "["LPFC_LINK_SPEED_STRING"]\n", val);
  2862. phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
  2863. return -EINVAL;
  2864. }
  2865. static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
  2866. lpfc_link_speed_show, lpfc_link_speed_store);
  2867. /*
  2868. # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
  2869. # 0 = aer disabled or not supported
  2870. # 1 = aer supported and enabled (default)
  2871. # Value range is [0,1]. Default value is 1.
  2872. */
  2873. /**
  2874. * lpfc_aer_support_store - Set the adapter for aer support
  2875. *
  2876. * @dev: class device that is converted into a Scsi_host.
  2877. * @attr: device attribute, not used.
  2878. * @buf: containing enable or disable aer flag.
  2879. * @count: unused variable.
  2880. *
  2881. * Description:
  2882. * If the val is 1 and currently the device's AER capability was not
  2883. * enabled, invoke the kernel's enable AER helper routine, trying to
  2884. * enable the device's AER capability. If the helper routine enabling
  2885. * AER returns success, update the device's cfg_aer_support flag to
  2886. * indicate AER is supported by the device; otherwise, if the device
  2887. * AER capability is already enabled to support AER, then do nothing.
  2888. *
  2889. * If the val is 0 and currently the device's AER support was enabled,
  2890. * invoke the kernel's disable AER helper routine. After that, update
  2891. * the device's cfg_aer_support flag to indicate AER is not supported
  2892. * by the device; otherwise, if the device AER capability is already
  2893. * disabled from supporting AER, then do nothing.
  2894. *
  2895. * Returns:
  2896. * length of the buf on success if val is in range the intended mode
  2897. * is supported.
  2898. * -EINVAL if val out of range or intended mode is not supported.
  2899. **/
  2900. static ssize_t
  2901. lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
  2902. const char *buf, size_t count)
  2903. {
  2904. struct Scsi_Host *shost = class_to_shost(dev);
  2905. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  2906. struct lpfc_hba *phba = vport->phba;
  2907. int val = 0, rc = -EINVAL;
  2908. if (!isdigit(buf[0]))
  2909. return -EINVAL;
  2910. if (sscanf(buf, "%i", &val) != 1)
  2911. return -EINVAL;
  2912. switch (val) {
  2913. case 0:
  2914. if (phba->hba_flag & HBA_AER_ENABLED) {
  2915. rc = pci_disable_pcie_error_reporting(phba->pcidev);
  2916. if (!rc) {
  2917. spin_lock_irq(&phba->hbalock);
  2918. phba->hba_flag &= ~HBA_AER_ENABLED;
  2919. spin_unlock_irq(&phba->hbalock);
  2920. phba->cfg_aer_support = 0;
  2921. rc = strlen(buf);
  2922. } else
  2923. rc = -EPERM;
  2924. } else {
  2925. phba->cfg_aer_support = 0;
  2926. rc = strlen(buf);
  2927. }
  2928. break;
  2929. case 1:
  2930. if (!(phba->hba_flag & HBA_AER_ENABLED)) {
  2931. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  2932. if (!rc) {
  2933. spin_lock_irq(&phba->hbalock);
  2934. phba->hba_flag |= HBA_AER_ENABLED;
  2935. spin_unlock_irq(&phba->hbalock);
  2936. phba->cfg_aer_support = 1;
  2937. rc = strlen(buf);
  2938. } else
  2939. rc = -EPERM;
  2940. } else {
  2941. phba->cfg_aer_support = 1;
  2942. rc = strlen(buf);
  2943. }
  2944. break;
  2945. default:
  2946. rc = -EINVAL;
  2947. break;
  2948. }
  2949. return rc;
  2950. }
  2951. static int lpfc_aer_support = 1;
  2952. module_param(lpfc_aer_support, int, S_IRUGO);
  2953. MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
  2954. lpfc_param_show(aer_support)
  2955. /**
  2956. * lpfc_aer_support_init - Set the initial adapters aer support flag
  2957. * @phba: lpfc_hba pointer.
  2958. * @val: enable aer or disable aer flag.
  2959. *
  2960. * Description:
  2961. * If val is in a valid range [0,1], then set the adapter's initial
  2962. * cfg_aer_support field. It will be up to the driver's probe_one
  2963. * routine to determine whether the device's AER support can be set
  2964. * or not.
  2965. *
  2966. * Notes:
  2967. * If the value is not in range log a kernel error message, and
  2968. * choose the default value of setting AER support and return.
  2969. *
  2970. * Returns:
  2971. * zero if val saved.
  2972. * -EINVAL val out of range
  2973. **/
  2974. static int
  2975. lpfc_aer_support_init(struct lpfc_hba *phba, int val)
  2976. {
  2977. if (val == 0 || val == 1) {
  2978. phba->cfg_aer_support = val;
  2979. return 0;
  2980. }
  2981. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2982. "2712 lpfc_aer_support attribute value %d out "
  2983. "of range, allowed values are 0|1, setting it "
  2984. "to default value of 1\n", val);
  2985. /* By default, try to enable AER on a device */
  2986. phba->cfg_aer_support = 1;
  2987. return -EINVAL;
  2988. }
  2989. static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
  2990. lpfc_aer_support_show, lpfc_aer_support_store);
  2991. /**
  2992. * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
  2993. * @dev: class device that is converted into a Scsi_host.
  2994. * @attr: device attribute, not used.
  2995. * @buf: containing flag 1 for aer cleanup state.
  2996. * @count: unused variable.
  2997. *
  2998. * Description:
  2999. * If the @buf contains 1 and the device currently has the AER support
  3000. * enabled, then invokes the kernel AER helper routine
  3001. * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
  3002. * error status register.
  3003. *
  3004. * Notes:
  3005. *
  3006. * Returns:
  3007. * -EINVAL if the buf does not contain the 1 or the device is not currently
  3008. * enabled with the AER support.
  3009. **/
  3010. static ssize_t
  3011. lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
  3012. const char *buf, size_t count)
  3013. {
  3014. struct Scsi_Host *shost = class_to_shost(dev);
  3015. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3016. struct lpfc_hba *phba = vport->phba;
  3017. int val, rc = -1;
  3018. if (!isdigit(buf[0]))
  3019. return -EINVAL;
  3020. if (sscanf(buf, "%i", &val) != 1)
  3021. return -EINVAL;
  3022. if (val != 1)
  3023. return -EINVAL;
  3024. if (phba->hba_flag & HBA_AER_ENABLED)
  3025. rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
  3026. if (rc == 0)
  3027. return strlen(buf);
  3028. else
  3029. return -EPERM;
  3030. }
  3031. static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
  3032. lpfc_aer_cleanup_state);
  3033. /**
  3034. * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
  3035. *
  3036. * @dev: class device that is converted into a Scsi_host.
  3037. * @attr: device attribute, not used.
  3038. * @buf: containing the string the number of vfs to be enabled.
  3039. * @count: unused variable.
  3040. *
  3041. * Description:
  3042. * When this api is called either through user sysfs, the driver shall
  3043. * try to enable or disable SR-IOV virtual functions according to the
  3044. * following:
  3045. *
  3046. * If zero virtual function has been enabled to the physical function,
  3047. * the driver shall invoke the pci enable virtual function api trying
  3048. * to enable the virtual functions. If the nr_vfn provided is greater
  3049. * than the maximum supported, the maximum virtual function number will
  3050. * be used for invoking the api; otherwise, the nr_vfn provided shall
  3051. * be used for invoking the api. If the api call returned success, the
  3052. * actual number of virtual functions enabled will be set to the driver
  3053. * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
  3054. * cfg_sriov_nr_virtfn remains zero.
  3055. *
  3056. * If none-zero virtual functions have already been enabled to the
  3057. * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
  3058. * -EINVAL will be returned and the driver does nothing;
  3059. *
  3060. * If the nr_vfn provided is zero and none-zero virtual functions have
  3061. * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
  3062. * disabling virtual function api shall be invoded to disable all the
  3063. * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
  3064. * zero. Otherwise, if zero virtual function has been enabled, do
  3065. * nothing.
  3066. *
  3067. * Returns:
  3068. * length of the buf on success if val is in range the intended mode
  3069. * is supported.
  3070. * -EINVAL if val out of range or intended mode is not supported.
  3071. **/
  3072. static ssize_t
  3073. lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
  3074. const char *buf, size_t count)
  3075. {
  3076. struct Scsi_Host *shost = class_to_shost(dev);
  3077. struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
  3078. struct lpfc_hba *phba = vport->phba;
  3079. struct pci_dev *pdev = phba->pcidev;
  3080. int val = 0, rc = -EINVAL;
  3081. /* Sanity check on user data */
  3082. if (!isdigit(buf[0]))
  3083. return -EINVAL;
  3084. if (sscanf(buf, "%i", &val) != 1)
  3085. return -EINVAL;
  3086. if (val < 0)
  3087. return -EINVAL;
  3088. /* Request disabling virtual functions */
  3089. if (val == 0) {
  3090. if (phba->cfg_sriov_nr_virtfn > 0) {
  3091. pci_disable_sriov(pdev);
  3092. phba->cfg_sriov_nr_virtfn = 0;
  3093. }
  3094. return strlen(buf);
  3095. }
  3096. /* Request enabling virtual functions */
  3097. if (phba->cfg_sriov_nr_virtfn > 0) {
  3098. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3099. "3018 There are %d virtual functions "
  3100. "enabled on physical function.\n",
  3101. phba->cfg_sriov_nr_virtfn);
  3102. return -EEXIST;
  3103. }
  3104. if (val <= LPFC_MAX_VFN_PER_PFN)
  3105. phba->cfg_sriov_nr_virtfn = val;
  3106. else {
  3107. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3108. "3019 Enabling %d virtual functions is not "
  3109. "allowed.\n", val);
  3110. return -EINVAL;
  3111. }
  3112. rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
  3113. if (rc) {
  3114. phba->cfg_sriov_nr_virtfn = 0;
  3115. rc = -EPERM;
  3116. } else
  3117. rc = strlen(buf);
  3118. return rc;
  3119. }
  3120. static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
  3121. module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
  3122. MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
  3123. lpfc_param_show(sriov_nr_virtfn)
  3124. /**
  3125. * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
  3126. * @phba: lpfc_hba pointer.
  3127. * @val: link speed value.
  3128. *
  3129. * Description:
  3130. * If val is in a valid range [0,255], then set the adapter's initial
  3131. * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
  3132. * number shall be used instead. It will be up to the driver's probe_one
  3133. * routine to determine whether the device's SR-IOV is supported or not.
  3134. *
  3135. * Returns:
  3136. * zero if val saved.
  3137. * -EINVAL val out of range
  3138. **/
  3139. static int
  3140. lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
  3141. {
  3142. if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
  3143. phba->cfg_sriov_nr_virtfn = val;
  3144. return 0;
  3145. }
  3146. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3147. "3017 Enabling %d virtual functions is not "
  3148. "allowed.\n", val);
  3149. return -EINVAL;
  3150. }
  3151. static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
  3152. lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
  3153. /*
  3154. # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
  3155. # Value range is [2,3]. Default value is 3.
  3156. */
  3157. LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
  3158. "Select Fibre Channel class of service for FCP sequences");
  3159. /*
  3160. # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
  3161. # is [0,1]. Default value is 0.
  3162. */
  3163. LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
  3164. "Use ADISC on rediscovery to authenticate FCP devices");
  3165. /*
  3166. # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
  3167. # depth. Default value is 0. When the value of this parameter is zero the
  3168. # SCSI command completion time is not used for controlling I/O queue depth. When
  3169. # the parameter is set to a non-zero value, the I/O queue depth is controlled
  3170. # to limit the I/O completion time to the parameter value.
  3171. # The value is set in milliseconds.
  3172. */
  3173. static int lpfc_max_scsicmpl_time;
  3174. module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
  3175. MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
  3176. "Use command completion time to control queue depth");
  3177. lpfc_vport_param_show(max_scsicmpl_time);
  3178. lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
  3179. static int
  3180. lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
  3181. {
  3182. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3183. struct lpfc_nodelist *ndlp, *next_ndlp;
  3184. if (val == vport->cfg_max_scsicmpl_time)
  3185. return 0;
  3186. if ((val < 0) || (val > 60000))
  3187. return -EINVAL;
  3188. vport->cfg_max_scsicmpl_time = val;
  3189. spin_lock_irq(shost->host_lock);
  3190. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  3191. if (!NLP_CHK_NODE_ACT(ndlp))
  3192. continue;
  3193. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  3194. continue;
  3195. ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
  3196. }
  3197. spin_unlock_irq(shost->host_lock);
  3198. return 0;
  3199. }
  3200. lpfc_vport_param_store(max_scsicmpl_time);
  3201. static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
  3202. lpfc_max_scsicmpl_time_show,
  3203. lpfc_max_scsicmpl_time_store);
  3204. /*
  3205. # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
  3206. # range is [0,1]. Default value is 0.
  3207. */
  3208. LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
  3209. /*
  3210. # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
  3211. # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
  3212. # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
  3213. # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
  3214. # cr_delay is set to 0.
  3215. */
  3216. LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
  3217. "interrupt response is generated");
  3218. LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
  3219. "interrupt response is generated");
  3220. /*
  3221. # lpfc_multi_ring_support: Determines how many rings to spread available
  3222. # cmd/rsp IOCB entries across.
  3223. # Value range is [1,2]. Default value is 1.
  3224. */
  3225. LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
  3226. "SLI rings to spread IOCB entries across");
  3227. /*
  3228. # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
  3229. # identifies what rctl value to configure the additional ring for.
  3230. # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
  3231. */
  3232. LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
  3233. 255, "Identifies RCTL for additional ring configuration");
  3234. /*
  3235. # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
  3236. # identifies what type value to configure the additional ring for.
  3237. # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
  3238. */
  3239. LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
  3240. 255, "Identifies TYPE for additional ring configuration");
  3241. /*
  3242. # lpfc_fdmi_on: controls FDMI support.
  3243. # 0 = no FDMI support
  3244. # 1 = support FDMI without attribute of hostname
  3245. # 2 = support FDMI with attribute of hostname
  3246. # Value range [0,2]. Default value is 0.
  3247. */
  3248. LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
  3249. /*
  3250. # Specifies the maximum number of ELS cmds we can have outstanding (for
  3251. # discovery). Value range is [1,64]. Default value = 32.
  3252. */
  3253. LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
  3254. "during discovery");
  3255. /*
  3256. # lpfc_max_luns: maximum allowed LUN.
  3257. # Value range is [0,65535]. Default value is 255.
  3258. # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
  3259. */
  3260. LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
  3261. /*
  3262. # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
  3263. # Value range is [1,255], default value is 10.
  3264. */
  3265. LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
  3266. "Milliseconds driver will wait between polling FCP ring");
  3267. /*
  3268. # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
  3269. # support this feature
  3270. # 0 = MSI disabled
  3271. # 1 = MSI enabled
  3272. # 2 = MSI-X enabled (default)
  3273. # Value range is [0,2]. Default value is 2.
  3274. */
  3275. LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
  3276. "MSI-X (2), if possible");
  3277. /*
  3278. # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
  3279. #
  3280. # Value range is [636,651042]. Default value is 10000.
  3281. */
  3282. LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
  3283. "Set the maximum number of fast-path FCP interrupts per second");
  3284. /*
  3285. # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
  3286. #
  3287. # Value range is [1,31]. Default value is 4.
  3288. */
  3289. LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
  3290. "Set the number of fast-path FCP work queues, if possible");
  3291. /*
  3292. # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
  3293. #
  3294. # Value range is [1,7]. Default value is 1.
  3295. */
  3296. LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
  3297. "Set the number of fast-path FCP event queues, if possible");
  3298. /*
  3299. # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
  3300. # 0 = HBA resets disabled
  3301. # 1 = HBA resets enabled (default)
  3302. # Value range is [0,1]. Default value is 1.
  3303. */
  3304. LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
  3305. /*
  3306. # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
  3307. # 0 = HBA Heartbeat disabled
  3308. # 1 = HBA Heartbeat enabled (default)
  3309. # Value range is [0,1]. Default value is 1.
  3310. */
  3311. LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
  3312. /*
  3313. # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
  3314. # 0 = BlockGuard disabled (default)
  3315. # 1 = BlockGuard enabled
  3316. # Value range is [0,1]. Default value is 0.
  3317. */
  3318. LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
  3319. /*
  3320. # lpfc_prot_mask: i
  3321. # - Bit mask of host protection capabilities used to register with the
  3322. # SCSI mid-layer
  3323. # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
  3324. # - Allows you to ultimately specify which profiles to use
  3325. # - Default will result in registering capabilities for all profiles.
  3326. #
  3327. */
  3328. unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
  3329. SHOST_DIX_TYPE0_PROTECTION |
  3330. SHOST_DIX_TYPE1_PROTECTION;
  3331. module_param(lpfc_prot_mask, uint, S_IRUGO);
  3332. MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
  3333. /*
  3334. # lpfc_prot_guard: i
  3335. # - Bit mask of protection guard types to register with the SCSI mid-layer
  3336. # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
  3337. # - Allows you to ultimately specify which profiles to use
  3338. # - Default will result in registering capabilities for all guard types
  3339. #
  3340. */
  3341. unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
  3342. module_param(lpfc_prot_guard, byte, S_IRUGO);
  3343. MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
  3344. /*
  3345. * Delay initial NPort discovery when Clean Address bit is cleared in
  3346. * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
  3347. * This parameter can have value 0 or 1.
  3348. * When this parameter is set to 0, no delay is added to the initial
  3349. * discovery.
  3350. * When this parameter is set to non-zero value, initial Nport discovery is
  3351. * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
  3352. * accept and FCID/Fabric name/Fabric portname is changed.
  3353. * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
  3354. * when Clean Address bit is cleared in FLOGI/FDISC
  3355. * accept and FCID/Fabric name/Fabric portname is changed.
  3356. * Default value is 0.
  3357. */
  3358. int lpfc_delay_discovery;
  3359. module_param(lpfc_delay_discovery, int, S_IRUGO);
  3360. MODULE_PARM_DESC(lpfc_delay_discovery,
  3361. "Delay NPort discovery when Clean Address bit is cleared. "
  3362. "Allowed values: 0,1.");
  3363. /*
  3364. * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
  3365. * This value can be set to values between 64 and 256. The default value is
  3366. * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
  3367. * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
  3368. */
  3369. LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
  3370. LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
  3371. LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
  3372. LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
  3373. "Max Protection Scatter Gather Segment Count");
  3374. struct device_attribute *lpfc_hba_attrs[] = {
  3375. &dev_attr_bg_info,
  3376. &dev_attr_bg_guard_err,
  3377. &dev_attr_bg_apptag_err,
  3378. &dev_attr_bg_reftag_err,
  3379. &dev_attr_info,
  3380. &dev_attr_serialnum,
  3381. &dev_attr_modeldesc,
  3382. &dev_attr_modelname,
  3383. &dev_attr_programtype,
  3384. &dev_attr_portnum,
  3385. &dev_attr_fwrev,
  3386. &dev_attr_hdw,
  3387. &dev_attr_option_rom_version,
  3388. &dev_attr_link_state,
  3389. &dev_attr_num_discovered_ports,
  3390. &dev_attr_menlo_mgmt_mode,
  3391. &dev_attr_lpfc_drvr_version,
  3392. &dev_attr_lpfc_enable_fip,
  3393. &dev_attr_lpfc_temp_sensor,
  3394. &dev_attr_lpfc_log_verbose,
  3395. &dev_attr_lpfc_lun_queue_depth,
  3396. &dev_attr_lpfc_tgt_queue_depth,
  3397. &dev_attr_lpfc_hba_queue_depth,
  3398. &dev_attr_lpfc_peer_port_login,
  3399. &dev_attr_lpfc_nodev_tmo,
  3400. &dev_attr_lpfc_devloss_tmo,
  3401. &dev_attr_lpfc_fcp_class,
  3402. &dev_attr_lpfc_use_adisc,
  3403. &dev_attr_lpfc_ack0,
  3404. &dev_attr_lpfc_topology,
  3405. &dev_attr_lpfc_scan_down,
  3406. &dev_attr_lpfc_link_speed,
  3407. &dev_attr_lpfc_cr_delay,
  3408. &dev_attr_lpfc_cr_count,
  3409. &dev_attr_lpfc_multi_ring_support,
  3410. &dev_attr_lpfc_multi_ring_rctl,
  3411. &dev_attr_lpfc_multi_ring_type,
  3412. &dev_attr_lpfc_fdmi_on,
  3413. &dev_attr_lpfc_max_luns,
  3414. &dev_attr_lpfc_enable_npiv,
  3415. &dev_attr_lpfc_enable_rrq,
  3416. &dev_attr_nport_evt_cnt,
  3417. &dev_attr_board_mode,
  3418. &dev_attr_max_vpi,
  3419. &dev_attr_used_vpi,
  3420. &dev_attr_max_rpi,
  3421. &dev_attr_used_rpi,
  3422. &dev_attr_max_xri,
  3423. &dev_attr_used_xri,
  3424. &dev_attr_npiv_info,
  3425. &dev_attr_issue_reset,
  3426. &dev_attr_lpfc_poll,
  3427. &dev_attr_lpfc_poll_tmo,
  3428. &dev_attr_lpfc_use_msi,
  3429. &dev_attr_lpfc_fcp_imax,
  3430. &dev_attr_lpfc_fcp_wq_count,
  3431. &dev_attr_lpfc_fcp_eq_count,
  3432. &dev_attr_lpfc_enable_bg,
  3433. &dev_attr_lpfc_soft_wwnn,
  3434. &dev_attr_lpfc_soft_wwpn,
  3435. &dev_attr_lpfc_soft_wwn_enable,
  3436. &dev_attr_lpfc_enable_hba_reset,
  3437. &dev_attr_lpfc_enable_hba_heartbeat,
  3438. &dev_attr_lpfc_sg_seg_cnt,
  3439. &dev_attr_lpfc_max_scsicmpl_time,
  3440. &dev_attr_lpfc_stat_data_ctrl,
  3441. &dev_attr_lpfc_prot_sg_seg_cnt,
  3442. &dev_attr_lpfc_aer_support,
  3443. &dev_attr_lpfc_aer_state_cleanup,
  3444. &dev_attr_lpfc_sriov_nr_virtfn,
  3445. &dev_attr_lpfc_suppress_link_up,
  3446. &dev_attr_lpfc_iocb_cnt,
  3447. &dev_attr_iocb_hw,
  3448. &dev_attr_txq_hw,
  3449. &dev_attr_txcmplq_hw,
  3450. &dev_attr_lpfc_fips_level,
  3451. &dev_attr_lpfc_fips_rev,
  3452. &dev_attr_lpfc_dss,
  3453. &dev_attr_lpfc_sriov_hw_max_virtfn,
  3454. NULL,
  3455. };
  3456. struct device_attribute *lpfc_vport_attrs[] = {
  3457. &dev_attr_info,
  3458. &dev_attr_link_state,
  3459. &dev_attr_num_discovered_ports,
  3460. &dev_attr_lpfc_drvr_version,
  3461. &dev_attr_lpfc_log_verbose,
  3462. &dev_attr_lpfc_lun_queue_depth,
  3463. &dev_attr_lpfc_tgt_queue_depth,
  3464. &dev_attr_lpfc_nodev_tmo,
  3465. &dev_attr_lpfc_devloss_tmo,
  3466. &dev_attr_lpfc_hba_queue_depth,
  3467. &dev_attr_lpfc_peer_port_login,
  3468. &dev_attr_lpfc_restrict_login,
  3469. &dev_attr_lpfc_fcp_class,
  3470. &dev_attr_lpfc_use_adisc,
  3471. &dev_attr_lpfc_fdmi_on,
  3472. &dev_attr_lpfc_max_luns,
  3473. &dev_attr_nport_evt_cnt,
  3474. &dev_attr_npiv_info,
  3475. &dev_attr_lpfc_enable_da_id,
  3476. &dev_attr_lpfc_max_scsicmpl_time,
  3477. &dev_attr_lpfc_stat_data_ctrl,
  3478. &dev_attr_lpfc_static_vport,
  3479. &dev_attr_lpfc_fips_level,
  3480. &dev_attr_lpfc_fips_rev,
  3481. NULL,
  3482. };
  3483. /**
  3484. * sysfs_ctlreg_write - Write method for writing to ctlreg
  3485. * @filp: open sysfs file
  3486. * @kobj: kernel kobject that contains the kernel class device.
  3487. * @bin_attr: kernel attributes passed to us.
  3488. * @buf: contains the data to be written to the adapter IOREG space.
  3489. * @off: offset into buffer to beginning of data.
  3490. * @count: bytes to transfer.
  3491. *
  3492. * Description:
  3493. * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
  3494. * Uses the adapter io control registers to send buf contents to the adapter.
  3495. *
  3496. * Returns:
  3497. * -ERANGE off and count combo out of range
  3498. * -EINVAL off, count or buff address invalid
  3499. * -EPERM adapter is offline
  3500. * value of count, buf contents written
  3501. **/
  3502. static ssize_t
  3503. sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
  3504. struct bin_attribute *bin_attr,
  3505. char *buf, loff_t off, size_t count)
  3506. {
  3507. size_t buf_off;
  3508. struct device *dev = container_of(kobj, struct device, kobj);
  3509. struct Scsi_Host *shost = class_to_shost(dev);
  3510. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3511. struct lpfc_hba *phba = vport->phba;
  3512. if (phba->sli_rev >= LPFC_SLI_REV4)
  3513. return -EPERM;
  3514. if ((off + count) > FF_REG_AREA_SIZE)
  3515. return -ERANGE;
  3516. if (count == 0) return 0;
  3517. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  3518. return -EINVAL;
  3519. if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
  3520. return -EPERM;
  3521. }
  3522. spin_lock_irq(&phba->hbalock);
  3523. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
  3524. writel(*((uint32_t *)(buf + buf_off)),
  3525. phba->ctrl_regs_memmap_p + off + buf_off);
  3526. spin_unlock_irq(&phba->hbalock);
  3527. return count;
  3528. }
  3529. /**
  3530. * sysfs_ctlreg_read - Read method for reading from ctlreg
  3531. * @filp: open sysfs file
  3532. * @kobj: kernel kobject that contains the kernel class device.
  3533. * @bin_attr: kernel attributes passed to us.
  3534. * @buf: if successful contains the data from the adapter IOREG space.
  3535. * @off: offset into buffer to beginning of data.
  3536. * @count: bytes to transfer.
  3537. *
  3538. * Description:
  3539. * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
  3540. * Uses the adapter io control registers to read data into buf.
  3541. *
  3542. * Returns:
  3543. * -ERANGE off and count combo out of range
  3544. * -EINVAL off, count or buff address invalid
  3545. * value of count, buf contents read
  3546. **/
  3547. static ssize_t
  3548. sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
  3549. struct bin_attribute *bin_attr,
  3550. char *buf, loff_t off, size_t count)
  3551. {
  3552. size_t buf_off;
  3553. uint32_t * tmp_ptr;
  3554. struct device *dev = container_of(kobj, struct device, kobj);
  3555. struct Scsi_Host *shost = class_to_shost(dev);
  3556. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3557. struct lpfc_hba *phba = vport->phba;
  3558. if (phba->sli_rev >= LPFC_SLI_REV4)
  3559. return -EPERM;
  3560. if (off > FF_REG_AREA_SIZE)
  3561. return -ERANGE;
  3562. if ((off + count) > FF_REG_AREA_SIZE)
  3563. count = FF_REG_AREA_SIZE - off;
  3564. if (count == 0) return 0;
  3565. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  3566. return -EINVAL;
  3567. spin_lock_irq(&phba->hbalock);
  3568. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
  3569. tmp_ptr = (uint32_t *)(buf + buf_off);
  3570. *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
  3571. }
  3572. spin_unlock_irq(&phba->hbalock);
  3573. return count;
  3574. }
  3575. static struct bin_attribute sysfs_ctlreg_attr = {
  3576. .attr = {
  3577. .name = "ctlreg",
  3578. .mode = S_IRUSR | S_IWUSR,
  3579. },
  3580. .size = 256,
  3581. .read = sysfs_ctlreg_read,
  3582. .write = sysfs_ctlreg_write,
  3583. };
  3584. /**
  3585. * sysfs_mbox_idle - frees the sysfs mailbox
  3586. * @phba: lpfc_hba pointer
  3587. **/
  3588. static void
  3589. sysfs_mbox_idle(struct lpfc_hba *phba)
  3590. {
  3591. phba->sysfs_mbox.state = SMBOX_IDLE;
  3592. phba->sysfs_mbox.offset = 0;
  3593. if (phba->sysfs_mbox.mbox) {
  3594. mempool_free(phba->sysfs_mbox.mbox,
  3595. phba->mbox_mem_pool);
  3596. phba->sysfs_mbox.mbox = NULL;
  3597. }
  3598. }
  3599. /**
  3600. * sysfs_mbox_write - Write method for writing information via mbox
  3601. * @filp: open sysfs file
  3602. * @kobj: kernel kobject that contains the kernel class device.
  3603. * @bin_attr: kernel attributes passed to us.
  3604. * @buf: contains the data to be written to sysfs mbox.
  3605. * @off: offset into buffer to beginning of data.
  3606. * @count: bytes to transfer.
  3607. *
  3608. * Description:
  3609. * Accessed via /sys/class/scsi_host/hostxxx/mbox.
  3610. * Uses the sysfs mbox to send buf contents to the adapter.
  3611. *
  3612. * Returns:
  3613. * -ERANGE off and count combo out of range
  3614. * -EINVAL off, count or buff address invalid
  3615. * zero if count is zero
  3616. * -EPERM adapter is offline
  3617. * -ENOMEM failed to allocate memory for the mail box
  3618. * -EAGAIN offset, state or mbox is NULL
  3619. * count number of bytes transferred
  3620. **/
  3621. static ssize_t
  3622. sysfs_mbox_write(struct file *filp, struct kobject *kobj,
  3623. struct bin_attribute *bin_attr,
  3624. char *buf, loff_t off, size_t count)
  3625. {
  3626. struct device *dev = container_of(kobj, struct device, kobj);
  3627. struct Scsi_Host *shost = class_to_shost(dev);
  3628. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3629. struct lpfc_hba *phba = vport->phba;
  3630. struct lpfcMboxq *mbox = NULL;
  3631. if ((count + off) > MAILBOX_CMD_SIZE)
  3632. return -ERANGE;
  3633. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  3634. return -EINVAL;
  3635. if (count == 0)
  3636. return 0;
  3637. if (off == 0) {
  3638. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3639. if (!mbox)
  3640. return -ENOMEM;
  3641. memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
  3642. }
  3643. spin_lock_irq(&phba->hbalock);
  3644. if (off == 0) {
  3645. if (phba->sysfs_mbox.mbox)
  3646. mempool_free(mbox, phba->mbox_mem_pool);
  3647. else
  3648. phba->sysfs_mbox.mbox = mbox;
  3649. phba->sysfs_mbox.state = SMBOX_WRITING;
  3650. } else {
  3651. if (phba->sysfs_mbox.state != SMBOX_WRITING ||
  3652. phba->sysfs_mbox.offset != off ||
  3653. phba->sysfs_mbox.mbox == NULL) {
  3654. sysfs_mbox_idle(phba);
  3655. spin_unlock_irq(&phba->hbalock);
  3656. return -EAGAIN;
  3657. }
  3658. }
  3659. memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
  3660. buf, count);
  3661. phba->sysfs_mbox.offset = off + count;
  3662. spin_unlock_irq(&phba->hbalock);
  3663. return count;
  3664. }
  3665. /**
  3666. * sysfs_mbox_read - Read method for reading information via mbox
  3667. * @filp: open sysfs file
  3668. * @kobj: kernel kobject that contains the kernel class device.
  3669. * @bin_attr: kernel attributes passed to us.
  3670. * @buf: contains the data to be read from sysfs mbox.
  3671. * @off: offset into buffer to beginning of data.
  3672. * @count: bytes to transfer.
  3673. *
  3674. * Description:
  3675. * Accessed via /sys/class/scsi_host/hostxxx/mbox.
  3676. * Uses the sysfs mbox to receive data from to the adapter.
  3677. *
  3678. * Returns:
  3679. * -ERANGE off greater than mailbox command size
  3680. * -EINVAL off, count or buff address invalid
  3681. * zero if off and count are zero
  3682. * -EACCES adapter over temp
  3683. * -EPERM garbage can value to catch a multitude of errors
  3684. * -EAGAIN management IO not permitted, state or off error
  3685. * -ETIME mailbox timeout
  3686. * -ENODEV mailbox error
  3687. * count number of bytes transferred
  3688. **/
  3689. static ssize_t
  3690. sysfs_mbox_read(struct file *filp, struct kobject *kobj,
  3691. struct bin_attribute *bin_attr,
  3692. char *buf, loff_t off, size_t count)
  3693. {
  3694. struct device *dev = container_of(kobj, struct device, kobj);
  3695. struct Scsi_Host *shost = class_to_shost(dev);
  3696. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3697. struct lpfc_hba *phba = vport->phba;
  3698. int rc;
  3699. MAILBOX_t *pmb;
  3700. if (off > MAILBOX_CMD_SIZE)
  3701. return -ERANGE;
  3702. if ((count + off) > MAILBOX_CMD_SIZE)
  3703. count = MAILBOX_CMD_SIZE - off;
  3704. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  3705. return -EINVAL;
  3706. if (off && count == 0)
  3707. return 0;
  3708. spin_lock_irq(&phba->hbalock);
  3709. if (phba->over_temp_state == HBA_OVER_TEMP) {
  3710. sysfs_mbox_idle(phba);
  3711. spin_unlock_irq(&phba->hbalock);
  3712. return -EACCES;
  3713. }
  3714. if (off == 0 &&
  3715. phba->sysfs_mbox.state == SMBOX_WRITING &&
  3716. phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
  3717. pmb = &phba->sysfs_mbox.mbox->u.mb;
  3718. switch (pmb->mbxCommand) {
  3719. /* Offline only */
  3720. case MBX_INIT_LINK:
  3721. case MBX_DOWN_LINK:
  3722. case MBX_CONFIG_LINK:
  3723. case MBX_CONFIG_RING:
  3724. case MBX_RESET_RING:
  3725. case MBX_UNREG_LOGIN:
  3726. case MBX_CLEAR_LA:
  3727. case MBX_DUMP_CONTEXT:
  3728. case MBX_RUN_DIAGS:
  3729. case MBX_RESTART:
  3730. case MBX_SET_MASK:
  3731. case MBX_SET_DEBUG:
  3732. if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
  3733. printk(KERN_WARNING "mbox_read:Command 0x%x "
  3734. "is illegal in on-line state\n",
  3735. pmb->mbxCommand);
  3736. sysfs_mbox_idle(phba);
  3737. spin_unlock_irq(&phba->hbalock);
  3738. return -EPERM;
  3739. }
  3740. case MBX_WRITE_NV:
  3741. case MBX_WRITE_VPARMS:
  3742. case MBX_LOAD_SM:
  3743. case MBX_READ_NV:
  3744. case MBX_READ_CONFIG:
  3745. case MBX_READ_RCONFIG:
  3746. case MBX_READ_STATUS:
  3747. case MBX_READ_XRI:
  3748. case MBX_READ_REV:
  3749. case MBX_READ_LNK_STAT:
  3750. case MBX_DUMP_MEMORY:
  3751. case MBX_DOWN_LOAD:
  3752. case MBX_UPDATE_CFG:
  3753. case MBX_KILL_BOARD:
  3754. case MBX_LOAD_AREA:
  3755. case MBX_LOAD_EXP_ROM:
  3756. case MBX_BEACON:
  3757. case MBX_DEL_LD_ENTRY:
  3758. case MBX_SET_VARIABLE:
  3759. case MBX_WRITE_WWN:
  3760. case MBX_PORT_CAPABILITIES:
  3761. case MBX_PORT_IOV_CONTROL:
  3762. break;
  3763. case MBX_SECURITY_MGMT:
  3764. case MBX_AUTH_PORT:
  3765. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
  3766. printk(KERN_WARNING "mbox_read:Command 0x%x "
  3767. "is not permitted\n", pmb->mbxCommand);
  3768. sysfs_mbox_idle(phba);
  3769. spin_unlock_irq(&phba->hbalock);
  3770. return -EPERM;
  3771. }
  3772. break;
  3773. case MBX_READ_SPARM64:
  3774. case MBX_READ_TOPOLOGY:
  3775. case MBX_REG_LOGIN:
  3776. case MBX_REG_LOGIN64:
  3777. case MBX_CONFIG_PORT:
  3778. case MBX_RUN_BIU_DIAG:
  3779. printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
  3780. pmb->mbxCommand);
  3781. sysfs_mbox_idle(phba);
  3782. spin_unlock_irq(&phba->hbalock);
  3783. return -EPERM;
  3784. default:
  3785. printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
  3786. pmb->mbxCommand);
  3787. sysfs_mbox_idle(phba);
  3788. spin_unlock_irq(&phba->hbalock);
  3789. return -EPERM;
  3790. }
  3791. /* If HBA encountered an error attention, allow only DUMP
  3792. * or RESTART mailbox commands until the HBA is restarted.
  3793. */
  3794. if (phba->pport->stopped &&
  3795. pmb->mbxCommand != MBX_DUMP_MEMORY &&
  3796. pmb->mbxCommand != MBX_RESTART &&
  3797. pmb->mbxCommand != MBX_WRITE_VPARMS &&
  3798. pmb->mbxCommand != MBX_WRITE_WWN)
  3799. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  3800. "1259 mbox: Issued mailbox cmd "
  3801. "0x%x while in stopped state.\n",
  3802. pmb->mbxCommand);
  3803. phba->sysfs_mbox.mbox->vport = vport;
  3804. /* Don't allow mailbox commands to be sent when blocked
  3805. * or when in the middle of discovery
  3806. */
  3807. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
  3808. sysfs_mbox_idle(phba);
  3809. spin_unlock_irq(&phba->hbalock);
  3810. return -EAGAIN;
  3811. }
  3812. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  3813. (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
  3814. spin_unlock_irq(&phba->hbalock);
  3815. rc = lpfc_sli_issue_mbox (phba,
  3816. phba->sysfs_mbox.mbox,
  3817. MBX_POLL);
  3818. spin_lock_irq(&phba->hbalock);
  3819. } else {
  3820. spin_unlock_irq(&phba->hbalock);
  3821. rc = lpfc_sli_issue_mbox_wait (phba,
  3822. phba->sysfs_mbox.mbox,
  3823. lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
  3824. spin_lock_irq(&phba->hbalock);
  3825. }
  3826. if (rc != MBX_SUCCESS) {
  3827. if (rc == MBX_TIMEOUT) {
  3828. phba->sysfs_mbox.mbox = NULL;
  3829. }
  3830. sysfs_mbox_idle(phba);
  3831. spin_unlock_irq(&phba->hbalock);
  3832. return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
  3833. }
  3834. phba->sysfs_mbox.state = SMBOX_READING;
  3835. }
  3836. else if (phba->sysfs_mbox.offset != off ||
  3837. phba->sysfs_mbox.state != SMBOX_READING) {
  3838. printk(KERN_WARNING "mbox_read: Bad State\n");
  3839. sysfs_mbox_idle(phba);
  3840. spin_unlock_irq(&phba->hbalock);
  3841. return -EAGAIN;
  3842. }
  3843. memcpy(buf, (uint8_t *) &pmb + off, count);
  3844. phba->sysfs_mbox.offset = off + count;
  3845. if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
  3846. sysfs_mbox_idle(phba);
  3847. spin_unlock_irq(&phba->hbalock);
  3848. return count;
  3849. }
  3850. static struct bin_attribute sysfs_mbox_attr = {
  3851. .attr = {
  3852. .name = "mbox",
  3853. .mode = S_IRUSR | S_IWUSR,
  3854. },
  3855. .size = MAILBOX_SYSFS_MAX,
  3856. .read = sysfs_mbox_read,
  3857. .write = sysfs_mbox_write,
  3858. };
  3859. /**
  3860. * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
  3861. * @vport: address of lpfc vport structure.
  3862. *
  3863. * Return codes:
  3864. * zero on success
  3865. * error return code from sysfs_create_bin_file()
  3866. **/
  3867. int
  3868. lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
  3869. {
  3870. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3871. int error;
  3872. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  3873. &sysfs_drvr_stat_data_attr);
  3874. /* Virtual ports do not need ctrl_reg and mbox */
  3875. if (error || vport->port_type == LPFC_NPIV_PORT)
  3876. goto out;
  3877. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  3878. &sysfs_ctlreg_attr);
  3879. if (error)
  3880. goto out_remove_stat_attr;
  3881. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  3882. &sysfs_mbox_attr);
  3883. if (error)
  3884. goto out_remove_ctlreg_attr;
  3885. return 0;
  3886. out_remove_ctlreg_attr:
  3887. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
  3888. out_remove_stat_attr:
  3889. sysfs_remove_bin_file(&shost->shost_dev.kobj,
  3890. &sysfs_drvr_stat_data_attr);
  3891. out:
  3892. return error;
  3893. }
  3894. /**
  3895. * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
  3896. * @vport: address of lpfc vport structure.
  3897. **/
  3898. void
  3899. lpfc_free_sysfs_attr(struct lpfc_vport *vport)
  3900. {
  3901. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3902. sysfs_remove_bin_file(&shost->shost_dev.kobj,
  3903. &sysfs_drvr_stat_data_attr);
  3904. /* Virtual ports do not need ctrl_reg and mbox */
  3905. if (vport->port_type == LPFC_NPIV_PORT)
  3906. return;
  3907. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
  3908. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
  3909. }
  3910. /*
  3911. * Dynamic FC Host Attributes Support
  3912. */
  3913. /**
  3914. * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
  3915. * @shost: kernel scsi host pointer.
  3916. **/
  3917. static void
  3918. lpfc_get_host_port_id(struct Scsi_Host *shost)
  3919. {
  3920. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3921. /* note: fc_myDID already in cpu endianness */
  3922. fc_host_port_id(shost) = vport->fc_myDID;
  3923. }
  3924. /**
  3925. * lpfc_get_host_port_type - Set the value of the scsi host port type
  3926. * @shost: kernel scsi host pointer.
  3927. **/
  3928. static void
  3929. lpfc_get_host_port_type(struct Scsi_Host *shost)
  3930. {
  3931. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3932. struct lpfc_hba *phba = vport->phba;
  3933. spin_lock_irq(shost->host_lock);
  3934. if (vport->port_type == LPFC_NPIV_PORT) {
  3935. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  3936. } else if (lpfc_is_link_up(phba)) {
  3937. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  3938. if (vport->fc_flag & FC_PUBLIC_LOOP)
  3939. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  3940. else
  3941. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  3942. } else {
  3943. if (vport->fc_flag & FC_FABRIC)
  3944. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  3945. else
  3946. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  3947. }
  3948. } else
  3949. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  3950. spin_unlock_irq(shost->host_lock);
  3951. }
  3952. /**
  3953. * lpfc_get_host_port_state - Set the value of the scsi host port state
  3954. * @shost: kernel scsi host pointer.
  3955. **/
  3956. static void
  3957. lpfc_get_host_port_state(struct Scsi_Host *shost)
  3958. {
  3959. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3960. struct lpfc_hba *phba = vport->phba;
  3961. spin_lock_irq(shost->host_lock);
  3962. if (vport->fc_flag & FC_OFFLINE_MODE)
  3963. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  3964. else {
  3965. switch (phba->link_state) {
  3966. case LPFC_LINK_UNKNOWN:
  3967. case LPFC_LINK_DOWN:
  3968. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  3969. break;
  3970. case LPFC_LINK_UP:
  3971. case LPFC_CLEAR_LA:
  3972. case LPFC_HBA_READY:
  3973. /* Links up, beyond this port_type reports state */
  3974. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  3975. break;
  3976. case LPFC_HBA_ERROR:
  3977. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  3978. break;
  3979. default:
  3980. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  3981. break;
  3982. }
  3983. }
  3984. spin_unlock_irq(shost->host_lock);
  3985. }
  3986. /**
  3987. * lpfc_get_host_speed - Set the value of the scsi host speed
  3988. * @shost: kernel scsi host pointer.
  3989. **/
  3990. static void
  3991. lpfc_get_host_speed(struct Scsi_Host *shost)
  3992. {
  3993. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  3994. struct lpfc_hba *phba = vport->phba;
  3995. spin_lock_irq(shost->host_lock);
  3996. if (lpfc_is_link_up(phba)) {
  3997. switch(phba->fc_linkspeed) {
  3998. case LPFC_LINK_SPEED_1GHZ:
  3999. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  4000. break;
  4001. case LPFC_LINK_SPEED_2GHZ:
  4002. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  4003. break;
  4004. case LPFC_LINK_SPEED_4GHZ:
  4005. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  4006. break;
  4007. case LPFC_LINK_SPEED_8GHZ:
  4008. fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
  4009. break;
  4010. case LPFC_LINK_SPEED_10GHZ:
  4011. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  4012. break;
  4013. case LPFC_LINK_SPEED_16GHZ:
  4014. fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
  4015. break;
  4016. default:
  4017. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  4018. break;
  4019. }
  4020. } else
  4021. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  4022. spin_unlock_irq(shost->host_lock);
  4023. }
  4024. /**
  4025. * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
  4026. * @shost: kernel scsi host pointer.
  4027. **/
  4028. static void
  4029. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  4030. {
  4031. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4032. struct lpfc_hba *phba = vport->phba;
  4033. u64 node_name;
  4034. spin_lock_irq(shost->host_lock);
  4035. if ((vport->fc_flag & FC_FABRIC) ||
  4036. ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
  4037. (vport->fc_flag & FC_PUBLIC_LOOP)))
  4038. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  4039. else
  4040. /* fabric is local port if there is no F/FL_Port */
  4041. node_name = 0;
  4042. spin_unlock_irq(shost->host_lock);
  4043. fc_host_fabric_name(shost) = node_name;
  4044. }
  4045. /**
  4046. * lpfc_get_stats - Return statistical information about the adapter
  4047. * @shost: kernel scsi host pointer.
  4048. *
  4049. * Notes:
  4050. * NULL on error for link down, no mbox pool, sli2 active,
  4051. * management not allowed, memory allocation error, or mbox error.
  4052. *
  4053. * Returns:
  4054. * NULL for error
  4055. * address of the adapter host statistics
  4056. **/
  4057. static struct fc_host_statistics *
  4058. lpfc_get_stats(struct Scsi_Host *shost)
  4059. {
  4060. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4061. struct lpfc_hba *phba = vport->phba;
  4062. struct lpfc_sli *psli = &phba->sli;
  4063. struct fc_host_statistics *hs = &phba->link_stats;
  4064. struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
  4065. LPFC_MBOXQ_t *pmboxq;
  4066. MAILBOX_t *pmb;
  4067. unsigned long seconds;
  4068. int rc = 0;
  4069. /*
  4070. * prevent udev from issuing mailbox commands until the port is
  4071. * configured.
  4072. */
  4073. if (phba->link_state < LPFC_LINK_DOWN ||
  4074. !phba->mbox_mem_pool ||
  4075. (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
  4076. return NULL;
  4077. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  4078. return NULL;
  4079. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4080. if (!pmboxq)
  4081. return NULL;
  4082. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  4083. pmb = &pmboxq->u.mb;
  4084. pmb->mbxCommand = MBX_READ_STATUS;
  4085. pmb->mbxOwner = OWN_HOST;
  4086. pmboxq->context1 = NULL;
  4087. pmboxq->vport = vport;
  4088. if (vport->fc_flag & FC_OFFLINE_MODE)
  4089. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  4090. else
  4091. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  4092. if (rc != MBX_SUCCESS) {
  4093. if (rc != MBX_TIMEOUT)
  4094. mempool_free(pmboxq, phba->mbox_mem_pool);
  4095. return NULL;
  4096. }
  4097. memset(hs, 0, sizeof (struct fc_host_statistics));
  4098. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  4099. hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
  4100. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  4101. hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
  4102. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  4103. pmb->mbxCommand = MBX_READ_LNK_STAT;
  4104. pmb->mbxOwner = OWN_HOST;
  4105. pmboxq->context1 = NULL;
  4106. pmboxq->vport = vport;
  4107. if (vport->fc_flag & FC_OFFLINE_MODE)
  4108. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  4109. else
  4110. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  4111. if (rc != MBX_SUCCESS) {
  4112. if (rc != MBX_TIMEOUT)
  4113. mempool_free(pmboxq, phba->mbox_mem_pool);
  4114. return NULL;
  4115. }
  4116. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  4117. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  4118. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  4119. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  4120. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  4121. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  4122. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  4123. hs->link_failure_count -= lso->link_failure_count;
  4124. hs->loss_of_sync_count -= lso->loss_of_sync_count;
  4125. hs->loss_of_signal_count -= lso->loss_of_signal_count;
  4126. hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
  4127. hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
  4128. hs->invalid_crc_count -= lso->invalid_crc_count;
  4129. hs->error_frames -= lso->error_frames;
  4130. if (phba->hba_flag & HBA_FCOE_MODE) {
  4131. hs->lip_count = -1;
  4132. hs->nos_count = (phba->link_events >> 1);
  4133. hs->nos_count -= lso->link_events;
  4134. } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  4135. hs->lip_count = (phba->fc_eventTag >> 1);
  4136. hs->lip_count -= lso->link_events;
  4137. hs->nos_count = -1;
  4138. } else {
  4139. hs->lip_count = -1;
  4140. hs->nos_count = (phba->fc_eventTag >> 1);
  4141. hs->nos_count -= lso->link_events;
  4142. }
  4143. hs->dumped_frames = -1;
  4144. seconds = get_seconds();
  4145. if (seconds < psli->stats_start)
  4146. hs->seconds_since_last_reset = seconds +
  4147. ((unsigned long)-1 - psli->stats_start);
  4148. else
  4149. hs->seconds_since_last_reset = seconds - psli->stats_start;
  4150. mempool_free(pmboxq, phba->mbox_mem_pool);
  4151. return hs;
  4152. }
  4153. /**
  4154. * lpfc_reset_stats - Copy the adapter link stats information
  4155. * @shost: kernel scsi host pointer.
  4156. **/
  4157. static void
  4158. lpfc_reset_stats(struct Scsi_Host *shost)
  4159. {
  4160. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4161. struct lpfc_hba *phba = vport->phba;
  4162. struct lpfc_sli *psli = &phba->sli;
  4163. struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
  4164. LPFC_MBOXQ_t *pmboxq;
  4165. MAILBOX_t *pmb;
  4166. int rc = 0;
  4167. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  4168. return;
  4169. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4170. if (!pmboxq)
  4171. return;
  4172. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  4173. pmb = &pmboxq->u.mb;
  4174. pmb->mbxCommand = MBX_READ_STATUS;
  4175. pmb->mbxOwner = OWN_HOST;
  4176. pmb->un.varWords[0] = 0x1; /* reset request */
  4177. pmboxq->context1 = NULL;
  4178. pmboxq->vport = vport;
  4179. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  4180. (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
  4181. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  4182. else
  4183. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  4184. if (rc != MBX_SUCCESS) {
  4185. if (rc != MBX_TIMEOUT)
  4186. mempool_free(pmboxq, phba->mbox_mem_pool);
  4187. return;
  4188. }
  4189. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  4190. pmb->mbxCommand = MBX_READ_LNK_STAT;
  4191. pmb->mbxOwner = OWN_HOST;
  4192. pmboxq->context1 = NULL;
  4193. pmboxq->vport = vport;
  4194. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  4195. (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
  4196. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  4197. else
  4198. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  4199. if (rc != MBX_SUCCESS) {
  4200. if (rc != MBX_TIMEOUT)
  4201. mempool_free( pmboxq, phba->mbox_mem_pool);
  4202. return;
  4203. }
  4204. lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  4205. lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  4206. lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  4207. lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  4208. lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  4209. lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  4210. lso->error_frames = pmb->un.varRdLnk.crcCnt;
  4211. if (phba->hba_flag & HBA_FCOE_MODE)
  4212. lso->link_events = (phba->link_events >> 1);
  4213. else
  4214. lso->link_events = (phba->fc_eventTag >> 1);
  4215. psli->stats_start = get_seconds();
  4216. mempool_free(pmboxq, phba->mbox_mem_pool);
  4217. return;
  4218. }
  4219. /*
  4220. * The LPFC driver treats linkdown handling as target loss events so there
  4221. * are no sysfs handlers for link_down_tmo.
  4222. */
  4223. /**
  4224. * lpfc_get_node_by_target - Return the nodelist for a target
  4225. * @starget: kernel scsi target pointer.
  4226. *
  4227. * Returns:
  4228. * address of the node list if found
  4229. * NULL target not found
  4230. **/
  4231. static struct lpfc_nodelist *
  4232. lpfc_get_node_by_target(struct scsi_target *starget)
  4233. {
  4234. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  4235. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  4236. struct lpfc_nodelist *ndlp;
  4237. spin_lock_irq(shost->host_lock);
  4238. /* Search for this, mapped, target ID */
  4239. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4240. if (NLP_CHK_NODE_ACT(ndlp) &&
  4241. ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  4242. starget->id == ndlp->nlp_sid) {
  4243. spin_unlock_irq(shost->host_lock);
  4244. return ndlp;
  4245. }
  4246. }
  4247. spin_unlock_irq(shost->host_lock);
  4248. return NULL;
  4249. }
  4250. /**
  4251. * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
  4252. * @starget: kernel scsi target pointer.
  4253. **/
  4254. static void
  4255. lpfc_get_starget_port_id(struct scsi_target *starget)
  4256. {
  4257. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  4258. fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
  4259. }
  4260. /**
  4261. * lpfc_get_starget_node_name - Set the target node name
  4262. * @starget: kernel scsi target pointer.
  4263. *
  4264. * Description: Set the target node name to the ndlp node name wwn or zero.
  4265. **/
  4266. static void
  4267. lpfc_get_starget_node_name(struct scsi_target *starget)
  4268. {
  4269. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  4270. fc_starget_node_name(starget) =
  4271. ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
  4272. }
  4273. /**
  4274. * lpfc_get_starget_port_name - Set the target port name
  4275. * @starget: kernel scsi target pointer.
  4276. *
  4277. * Description: set the target port name to the ndlp port name wwn or zero.
  4278. **/
  4279. static void
  4280. lpfc_get_starget_port_name(struct scsi_target *starget)
  4281. {
  4282. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  4283. fc_starget_port_name(starget) =
  4284. ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
  4285. }
  4286. /**
  4287. * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
  4288. * @rport: fc rport address.
  4289. * @timeout: new value for dev loss tmo.
  4290. *
  4291. * Description:
  4292. * If timeout is non zero set the dev_loss_tmo to timeout, else set
  4293. * dev_loss_tmo to one.
  4294. **/
  4295. static void
  4296. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  4297. {
  4298. if (timeout)
  4299. rport->dev_loss_tmo = timeout;
  4300. else
  4301. rport->dev_loss_tmo = 1;
  4302. }
  4303. /**
  4304. * lpfc_rport_show_function - Return rport target information
  4305. *
  4306. * Description:
  4307. * Macro that uses field to generate a function with the name lpfc_show_rport_
  4308. *
  4309. * lpfc_show_rport_##field: returns the bytes formatted in buf
  4310. * @cdev: class converted to an fc_rport.
  4311. * @buf: on return contains the target_field or zero.
  4312. *
  4313. * Returns: size of formatted string.
  4314. **/
  4315. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  4316. static ssize_t \
  4317. lpfc_show_rport_##field (struct device *dev, \
  4318. struct device_attribute *attr, \
  4319. char *buf) \
  4320. { \
  4321. struct fc_rport *rport = transport_class_to_rport(dev); \
  4322. struct lpfc_rport_data *rdata = rport->hostdata; \
  4323. return snprintf(buf, sz, format_string, \
  4324. (rdata->target) ? cast rdata->target->field : 0); \
  4325. }
  4326. #define lpfc_rport_rd_attr(field, format_string, sz) \
  4327. lpfc_rport_show_function(field, format_string, sz, ) \
  4328. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  4329. /**
  4330. * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
  4331. * @fc_vport: The fc_vport who's symbolic name has been changed.
  4332. *
  4333. * Description:
  4334. * This function is called by the transport after the @fc_vport's symbolic name
  4335. * has been changed. This function re-registers the symbolic name with the
  4336. * switch to propagate the change into the fabric if the vport is active.
  4337. **/
  4338. static void
  4339. lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
  4340. {
  4341. struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
  4342. if (vport->port_state == LPFC_VPORT_READY)
  4343. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  4344. }
  4345. /**
  4346. * lpfc_hba_log_verbose_init - Set hba's log verbose level
  4347. * @phba: Pointer to lpfc_hba struct.
  4348. *
  4349. * This function is called by the lpfc_get_cfgparam() routine to set the
  4350. * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
  4351. * log message according to the module's lpfc_log_verbose parameter setting
  4352. * before hba port or vport created.
  4353. **/
  4354. static void
  4355. lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
  4356. {
  4357. phba->cfg_log_verbose = verbose;
  4358. }
  4359. struct fc_function_template lpfc_transport_functions = {
  4360. /* fixed attributes the driver supports */
  4361. .show_host_node_name = 1,
  4362. .show_host_port_name = 1,
  4363. .show_host_supported_classes = 1,
  4364. .show_host_supported_fc4s = 1,
  4365. .show_host_supported_speeds = 1,
  4366. .show_host_maxframe_size = 1,
  4367. .show_host_symbolic_name = 1,
  4368. /* dynamic attributes the driver supports */
  4369. .get_host_port_id = lpfc_get_host_port_id,
  4370. .show_host_port_id = 1,
  4371. .get_host_port_type = lpfc_get_host_port_type,
  4372. .show_host_port_type = 1,
  4373. .get_host_port_state = lpfc_get_host_port_state,
  4374. .show_host_port_state = 1,
  4375. /* active_fc4s is shown but doesn't change (thus no get function) */
  4376. .show_host_active_fc4s = 1,
  4377. .get_host_speed = lpfc_get_host_speed,
  4378. .show_host_speed = 1,
  4379. .get_host_fabric_name = lpfc_get_host_fabric_name,
  4380. .show_host_fabric_name = 1,
  4381. /*
  4382. * The LPFC driver treats linkdown handling as target loss events
  4383. * so there are no sysfs handlers for link_down_tmo.
  4384. */
  4385. .get_fc_host_stats = lpfc_get_stats,
  4386. .reset_fc_host_stats = lpfc_reset_stats,
  4387. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  4388. .show_rport_maxframe_size = 1,
  4389. .show_rport_supported_classes = 1,
  4390. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  4391. .show_rport_dev_loss_tmo = 1,
  4392. .get_starget_port_id = lpfc_get_starget_port_id,
  4393. .show_starget_port_id = 1,
  4394. .get_starget_node_name = lpfc_get_starget_node_name,
  4395. .show_starget_node_name = 1,
  4396. .get_starget_port_name = lpfc_get_starget_port_name,
  4397. .show_starget_port_name = 1,
  4398. .issue_fc_host_lip = lpfc_issue_lip,
  4399. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  4400. .terminate_rport_io = lpfc_terminate_rport_io,
  4401. .dd_fcvport_size = sizeof(struct lpfc_vport *),
  4402. .vport_disable = lpfc_vport_disable,
  4403. .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
  4404. .bsg_request = lpfc_bsg_request,
  4405. .bsg_timeout = lpfc_bsg_timeout,
  4406. };
  4407. struct fc_function_template lpfc_vport_transport_functions = {
  4408. /* fixed attributes the driver supports */
  4409. .show_host_node_name = 1,
  4410. .show_host_port_name = 1,
  4411. .show_host_supported_classes = 1,
  4412. .show_host_supported_fc4s = 1,
  4413. .show_host_supported_speeds = 1,
  4414. .show_host_maxframe_size = 1,
  4415. .show_host_symbolic_name = 1,
  4416. /* dynamic attributes the driver supports */
  4417. .get_host_port_id = lpfc_get_host_port_id,
  4418. .show_host_port_id = 1,
  4419. .get_host_port_type = lpfc_get_host_port_type,
  4420. .show_host_port_type = 1,
  4421. .get_host_port_state = lpfc_get_host_port_state,
  4422. .show_host_port_state = 1,
  4423. /* active_fc4s is shown but doesn't change (thus no get function) */
  4424. .show_host_active_fc4s = 1,
  4425. .get_host_speed = lpfc_get_host_speed,
  4426. .show_host_speed = 1,
  4427. .get_host_fabric_name = lpfc_get_host_fabric_name,
  4428. .show_host_fabric_name = 1,
  4429. /*
  4430. * The LPFC driver treats linkdown handling as target loss events
  4431. * so there are no sysfs handlers for link_down_tmo.
  4432. */
  4433. .get_fc_host_stats = lpfc_get_stats,
  4434. .reset_fc_host_stats = lpfc_reset_stats,
  4435. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  4436. .show_rport_maxframe_size = 1,
  4437. .show_rport_supported_classes = 1,
  4438. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  4439. .show_rport_dev_loss_tmo = 1,
  4440. .get_starget_port_id = lpfc_get_starget_port_id,
  4441. .show_starget_port_id = 1,
  4442. .get_starget_node_name = lpfc_get_starget_node_name,
  4443. .show_starget_node_name = 1,
  4444. .get_starget_port_name = lpfc_get_starget_port_name,
  4445. .show_starget_port_name = 1,
  4446. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  4447. .terminate_rport_io = lpfc_terminate_rport_io,
  4448. .vport_disable = lpfc_vport_disable,
  4449. .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
  4450. };
  4451. /**
  4452. * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
  4453. * @phba: lpfc_hba pointer.
  4454. **/
  4455. void
  4456. lpfc_get_cfgparam(struct lpfc_hba *phba)
  4457. {
  4458. lpfc_cr_delay_init(phba, lpfc_cr_delay);
  4459. lpfc_cr_count_init(phba, lpfc_cr_count);
  4460. lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
  4461. lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
  4462. lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
  4463. lpfc_ack0_init(phba, lpfc_ack0);
  4464. lpfc_topology_init(phba, lpfc_topology);
  4465. lpfc_link_speed_init(phba, lpfc_link_speed);
  4466. lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
  4467. lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
  4468. lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
  4469. lpfc_use_msi_init(phba, lpfc_use_msi);
  4470. lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
  4471. lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
  4472. lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
  4473. lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
  4474. lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
  4475. lpfc_enable_bg_init(phba, lpfc_enable_bg);
  4476. if (phba->sli_rev == LPFC_SLI_REV4)
  4477. phba->cfg_poll = 0;
  4478. else
  4479. phba->cfg_poll = lpfc_poll;
  4480. phba->cfg_soft_wwnn = 0L;
  4481. phba->cfg_soft_wwpn = 0L;
  4482. lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
  4483. lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
  4484. lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
  4485. lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
  4486. lpfc_aer_support_init(phba, lpfc_aer_support);
  4487. lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
  4488. lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
  4489. lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
  4490. phba->cfg_enable_dss = 1;
  4491. return;
  4492. }
  4493. /**
  4494. * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
  4495. * @vport: lpfc_vport pointer.
  4496. **/
  4497. void
  4498. lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
  4499. {
  4500. lpfc_log_verbose_init(vport, lpfc_log_verbose);
  4501. lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
  4502. lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
  4503. lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
  4504. lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
  4505. lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
  4506. lpfc_restrict_login_init(vport, lpfc_restrict_login);
  4507. lpfc_fcp_class_init(vport, lpfc_fcp_class);
  4508. lpfc_use_adisc_init(vport, lpfc_use_adisc);
  4509. lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
  4510. lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
  4511. lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
  4512. lpfc_max_luns_init(vport, lpfc_max_luns);
  4513. lpfc_scan_down_init(vport, lpfc_scan_down);
  4514. lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
  4515. return;
  4516. }