lpfc_attr.c 142 KB

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