lpfc_attr.c 149 KB

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