lpfc_attr.c 151 KB

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