lpfc_attr.c 191 KB

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