lpfc_attr.c 159 KB

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