lpfc_attr.c 175 KB

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