lpfc_attr.c 150 KB

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