lpfc_attr.c 107 KB

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