lpfc_attr.c 140 KB

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