lpfc_attr.c 158 KB

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