lpfc_attr.c 122 KB

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