lpfc_attr.c 214 KB

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