lpfc_attr.c 160 KB

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