lpfc_attr.c 126 KB

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