lpfc_attr.c 148 KB

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