lpfc_attr.c 199 KB

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