lpfc_attr.c 160 KB

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