lpfc_attr.c 134 KB

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