lpfc_attr.c 135 KB

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