lpfc_attr.c 151 KB

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