lpfc_attr.c 175 KB

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