lpfc_attr.c 126 KB

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