lpfc_attr.c 147 KB

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