lpfc_attr.c 106 KB

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