lpfc_attr.c 154 KB

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