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