lpfc_attr.c 134 KB

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