lpfc_attr.c 126 KB

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