lpfc_attr.c 136 KB

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