lpfc_attr.c 155 KB

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