lpfc_attr.c 118 KB

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