lpfc_attr.c 134 KB

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