lpfc_attr.c 138 KB

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