lpfc_attr.c 140 KB

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