lpfc_attr.c 175 KB

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