lpfc_attr.c 123 KB

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