lpfc_attr.c 137 KB

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