lpfc_attr.c 148 KB

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