lpfc_attr.c 132 KB

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