lpfc_attr.c 122 KB

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