lpfc_attr.c 137 KB

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