lpfc_attr.c 134 KB

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