lpfc_attr.c 160 KB

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