lpfc_hbadisc.c 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2011 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/slab.h>
  24. #include <linux/pci.h>
  25. #include <linux/kthread.h>
  26. #include <linux/interrupt.h>
  27. #include <scsi/scsi.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include "lpfc_hw4.h"
  32. #include "lpfc_hw.h"
  33. #include "lpfc_nl.h"
  34. #include "lpfc_disc.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_logmsg.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_vport.h"
  42. #include "lpfc_debugfs.h"
  43. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  44. static uint8_t lpfcAlpaArray[] = {
  45. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  46. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  47. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  48. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  49. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  50. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  51. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  52. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  53. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  54. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  55. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  56. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  57. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  58. };
  59. static void lpfc_disc_timeout_handler(struct lpfc_vport *);
  60. static void lpfc_disc_flush_list(struct lpfc_vport *vport);
  61. static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
  62. static int lpfc_fcf_inuse(struct lpfc_hba *);
  63. void
  64. lpfc_terminate_rport_io(struct fc_rport *rport)
  65. {
  66. struct lpfc_rport_data *rdata;
  67. struct lpfc_nodelist * ndlp;
  68. struct lpfc_hba *phba;
  69. rdata = rport->dd_data;
  70. ndlp = rdata->pnode;
  71. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  72. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  73. printk(KERN_ERR "Cannot find remote node"
  74. " to terminate I/O Data x%x\n",
  75. rport->port_id);
  76. return;
  77. }
  78. phba = ndlp->phba;
  79. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  80. "rport terminate: sid:x%x did:x%x flg:x%x",
  81. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  82. if (ndlp->nlp_sid != NLP_NO_SID) {
  83. lpfc_sli_abort_iocb(ndlp->vport,
  84. &phba->sli.ring[phba->sli.fcp_ring],
  85. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  86. }
  87. }
  88. /*
  89. * This function will be called when dev_loss_tmo fire.
  90. */
  91. void
  92. lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
  93. {
  94. struct lpfc_rport_data *rdata;
  95. struct lpfc_nodelist * ndlp;
  96. struct lpfc_vport *vport;
  97. struct lpfc_hba *phba;
  98. struct lpfc_work_evt *evtp;
  99. int put_node;
  100. int put_rport;
  101. rdata = rport->dd_data;
  102. ndlp = rdata->pnode;
  103. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  104. return;
  105. vport = ndlp->vport;
  106. phba = vport->phba;
  107. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  108. "rport devlosscb: sid:x%x did:x%x flg:x%x",
  109. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  110. /* Don't defer this if we are in the process of deleting the vport
  111. * or unloading the driver. The unload will cleanup the node
  112. * appropriately we just need to cleanup the ndlp rport info here.
  113. */
  114. if (vport->load_flag & FC_UNLOADING) {
  115. put_node = rdata->pnode != NULL;
  116. put_rport = ndlp->rport != NULL;
  117. rdata->pnode = NULL;
  118. ndlp->rport = NULL;
  119. if (put_node)
  120. lpfc_nlp_put(ndlp);
  121. if (put_rport)
  122. put_device(&rport->dev);
  123. return;
  124. }
  125. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
  126. return;
  127. evtp = &ndlp->dev_loss_evt;
  128. if (!list_empty(&evtp->evt_listp))
  129. return;
  130. spin_lock_irq(&phba->hbalock);
  131. /* We need to hold the node by incrementing the reference
  132. * count until this queued work is done
  133. */
  134. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  135. if (evtp->evt_arg1) {
  136. evtp->evt = LPFC_EVT_DEV_LOSS;
  137. list_add_tail(&evtp->evt_listp, &phba->work_list);
  138. lpfc_worker_wake_up(phba);
  139. }
  140. spin_unlock_irq(&phba->hbalock);
  141. return;
  142. }
  143. /**
  144. * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
  145. * @ndlp: Pointer to remote node object.
  146. *
  147. * This function is called from the worker thread when devloss timeout timer
  148. * expires. For SLI4 host, this routine shall return 1 when at lease one
  149. * remote node, including this @ndlp, is still in use of FCF; otherwise, this
  150. * routine shall return 0 when there is no remote node is still in use of FCF
  151. * when devloss timeout happened to this @ndlp.
  152. **/
  153. static int
  154. lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
  155. {
  156. struct lpfc_rport_data *rdata;
  157. struct fc_rport *rport;
  158. struct lpfc_vport *vport;
  159. struct lpfc_hba *phba;
  160. uint8_t *name;
  161. int put_node;
  162. int put_rport;
  163. int warn_on = 0;
  164. int fcf_inuse = 0;
  165. rport = ndlp->rport;
  166. if (!rport)
  167. return fcf_inuse;
  168. rdata = rport->dd_data;
  169. name = (uint8_t *) &ndlp->nlp_portname;
  170. vport = ndlp->vport;
  171. phba = vport->phba;
  172. if (phba->sli_rev == LPFC_SLI_REV4)
  173. fcf_inuse = lpfc_fcf_inuse(phba);
  174. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  175. "rport devlosstmo:did:x%x type:x%x id:x%x",
  176. ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
  177. /* Don't defer this if we are in the process of deleting the vport
  178. * or unloading the driver. The unload will cleanup the node
  179. * appropriately we just need to cleanup the ndlp rport info here.
  180. */
  181. if (vport->load_flag & FC_UNLOADING) {
  182. if (ndlp->nlp_sid != NLP_NO_SID) {
  183. /* flush the target */
  184. lpfc_sli_abort_iocb(vport,
  185. &phba->sli.ring[phba->sli.fcp_ring],
  186. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  187. }
  188. put_node = rdata->pnode != NULL;
  189. put_rport = ndlp->rport != NULL;
  190. rdata->pnode = NULL;
  191. ndlp->rport = NULL;
  192. if (put_node)
  193. lpfc_nlp_put(ndlp);
  194. if (put_rport)
  195. put_device(&rport->dev);
  196. return fcf_inuse;
  197. }
  198. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
  199. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  200. "0284 Devloss timeout Ignored on "
  201. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  202. "NPort x%x\n",
  203. *name, *(name+1), *(name+2), *(name+3),
  204. *(name+4), *(name+5), *(name+6), *(name+7),
  205. ndlp->nlp_DID);
  206. return fcf_inuse;
  207. }
  208. if (ndlp->nlp_type & NLP_FABRIC) {
  209. /* We will clean up these Nodes in linkup */
  210. put_node = rdata->pnode != NULL;
  211. put_rport = ndlp->rport != NULL;
  212. rdata->pnode = NULL;
  213. ndlp->rport = NULL;
  214. if (put_node)
  215. lpfc_nlp_put(ndlp);
  216. if (put_rport)
  217. put_device(&rport->dev);
  218. return fcf_inuse;
  219. }
  220. if (ndlp->nlp_sid != NLP_NO_SID) {
  221. warn_on = 1;
  222. /* flush the target */
  223. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  224. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  225. }
  226. if (warn_on) {
  227. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  228. "0203 Devloss timeout on "
  229. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  230. "NPort x%06x Data: x%x x%x x%x\n",
  231. *name, *(name+1), *(name+2), *(name+3),
  232. *(name+4), *(name+5), *(name+6), *(name+7),
  233. ndlp->nlp_DID, ndlp->nlp_flag,
  234. ndlp->nlp_state, ndlp->nlp_rpi);
  235. } else {
  236. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  237. "0204 Devloss timeout on "
  238. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  239. "NPort x%06x Data: x%x x%x x%x\n",
  240. *name, *(name+1), *(name+2), *(name+3),
  241. *(name+4), *(name+5), *(name+6), *(name+7),
  242. ndlp->nlp_DID, ndlp->nlp_flag,
  243. ndlp->nlp_state, ndlp->nlp_rpi);
  244. }
  245. put_node = rdata->pnode != NULL;
  246. put_rport = ndlp->rport != NULL;
  247. rdata->pnode = NULL;
  248. ndlp->rport = NULL;
  249. if (put_node)
  250. lpfc_nlp_put(ndlp);
  251. if (put_rport)
  252. put_device(&rport->dev);
  253. if (!(vport->load_flag & FC_UNLOADING) &&
  254. !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  255. !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  256. (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  257. (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
  258. (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
  259. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  260. return fcf_inuse;
  261. }
  262. /**
  263. * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
  264. * @phba: Pointer to hba context object.
  265. * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
  266. * @nlp_did: remote node identifer with devloss timeout.
  267. *
  268. * This function is called from the worker thread after invoking devloss
  269. * timeout handler and releasing the reference count for the ndlp with
  270. * which the devloss timeout was handled for SLI4 host. For the devloss
  271. * timeout of the last remote node which had been in use of FCF, when this
  272. * routine is invoked, it shall be guaranteed that none of the remote are
  273. * in-use of FCF. When devloss timeout to the last remote using the FCF,
  274. * if the FIP engine is neither in FCF table scan process nor roundrobin
  275. * failover process, the in-use FCF shall be unregistered. If the FIP
  276. * engine is in FCF discovery process, the devloss timeout state shall
  277. * be set for either the FCF table scan process or roundrobin failover
  278. * process to unregister the in-use FCF.
  279. **/
  280. static void
  281. lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
  282. uint32_t nlp_did)
  283. {
  284. /* If devloss timeout happened to a remote node when FCF had no
  285. * longer been in-use, do nothing.
  286. */
  287. if (!fcf_inuse)
  288. return;
  289. if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
  290. spin_lock_irq(&phba->hbalock);
  291. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  292. if (phba->hba_flag & HBA_DEVLOSS_TMO) {
  293. spin_unlock_irq(&phba->hbalock);
  294. return;
  295. }
  296. phba->hba_flag |= HBA_DEVLOSS_TMO;
  297. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  298. "2847 Last remote node (x%x) using "
  299. "FCF devloss tmo\n", nlp_did);
  300. }
  301. if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
  302. spin_unlock_irq(&phba->hbalock);
  303. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  304. "2868 Devloss tmo to FCF rediscovery "
  305. "in progress\n");
  306. return;
  307. }
  308. if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
  309. spin_unlock_irq(&phba->hbalock);
  310. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  311. "2869 Devloss tmo to idle FIP engine, "
  312. "unreg in-use FCF and rescan.\n");
  313. /* Unregister in-use FCF and rescan */
  314. lpfc_unregister_fcf_rescan(phba);
  315. return;
  316. }
  317. spin_unlock_irq(&phba->hbalock);
  318. if (phba->hba_flag & FCF_TS_INPROG)
  319. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  320. "2870 FCF table scan in progress\n");
  321. if (phba->hba_flag & FCF_RR_INPROG)
  322. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  323. "2871 FLOGI roundrobin FCF failover "
  324. "in progress\n");
  325. }
  326. lpfc_unregister_unused_fcf(phba);
  327. }
  328. /**
  329. * lpfc_alloc_fast_evt - Allocates data structure for posting event
  330. * @phba: Pointer to hba context object.
  331. *
  332. * This function is called from the functions which need to post
  333. * events from interrupt context. This function allocates data
  334. * structure required for posting event. It also keeps track of
  335. * number of events pending and prevent event storm when there are
  336. * too many events.
  337. **/
  338. struct lpfc_fast_path_event *
  339. lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
  340. struct lpfc_fast_path_event *ret;
  341. /* If there are lot of fast event do not exhaust memory due to this */
  342. if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
  343. return NULL;
  344. ret = kzalloc(sizeof(struct lpfc_fast_path_event),
  345. GFP_ATOMIC);
  346. if (ret) {
  347. atomic_inc(&phba->fast_event_count);
  348. INIT_LIST_HEAD(&ret->work_evt.evt_listp);
  349. ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
  350. }
  351. return ret;
  352. }
  353. /**
  354. * lpfc_free_fast_evt - Frees event data structure
  355. * @phba: Pointer to hba context object.
  356. * @evt: Event object which need to be freed.
  357. *
  358. * This function frees the data structure required for posting
  359. * events.
  360. **/
  361. void
  362. lpfc_free_fast_evt(struct lpfc_hba *phba,
  363. struct lpfc_fast_path_event *evt) {
  364. atomic_dec(&phba->fast_event_count);
  365. kfree(evt);
  366. }
  367. /**
  368. * lpfc_send_fastpath_evt - Posts events generated from fast path
  369. * @phba: Pointer to hba context object.
  370. * @evtp: Event data structure.
  371. *
  372. * This function is called from worker thread, when the interrupt
  373. * context need to post an event. This function posts the event
  374. * to fc transport netlink interface.
  375. **/
  376. static void
  377. lpfc_send_fastpath_evt(struct lpfc_hba *phba,
  378. struct lpfc_work_evt *evtp)
  379. {
  380. unsigned long evt_category, evt_sub_category;
  381. struct lpfc_fast_path_event *fast_evt_data;
  382. char *evt_data;
  383. uint32_t evt_data_size;
  384. struct Scsi_Host *shost;
  385. fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
  386. work_evt);
  387. evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
  388. evt_sub_category = (unsigned long) fast_evt_data->un.
  389. fabric_evt.subcategory;
  390. shost = lpfc_shost_from_vport(fast_evt_data->vport);
  391. if (evt_category == FC_REG_FABRIC_EVENT) {
  392. if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
  393. evt_data = (char *) &fast_evt_data->un.read_check_error;
  394. evt_data_size = sizeof(fast_evt_data->un.
  395. read_check_error);
  396. } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
  397. (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
  398. evt_data = (char *) &fast_evt_data->un.fabric_evt;
  399. evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
  400. } else {
  401. lpfc_free_fast_evt(phba, fast_evt_data);
  402. return;
  403. }
  404. } else if (evt_category == FC_REG_SCSI_EVENT) {
  405. switch (evt_sub_category) {
  406. case LPFC_EVENT_QFULL:
  407. case LPFC_EVENT_DEVBSY:
  408. evt_data = (char *) &fast_evt_data->un.scsi_evt;
  409. evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
  410. break;
  411. case LPFC_EVENT_CHECK_COND:
  412. evt_data = (char *) &fast_evt_data->un.check_cond_evt;
  413. evt_data_size = sizeof(fast_evt_data->un.
  414. check_cond_evt);
  415. break;
  416. case LPFC_EVENT_VARQUEDEPTH:
  417. evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
  418. evt_data_size = sizeof(fast_evt_data->un.
  419. queue_depth_evt);
  420. break;
  421. default:
  422. lpfc_free_fast_evt(phba, fast_evt_data);
  423. return;
  424. }
  425. } else {
  426. lpfc_free_fast_evt(phba, fast_evt_data);
  427. return;
  428. }
  429. fc_host_post_vendor_event(shost,
  430. fc_get_event_number(),
  431. evt_data_size,
  432. evt_data,
  433. LPFC_NL_VENDOR_ID);
  434. lpfc_free_fast_evt(phba, fast_evt_data);
  435. return;
  436. }
  437. static void
  438. lpfc_work_list_done(struct lpfc_hba *phba)
  439. {
  440. struct lpfc_work_evt *evtp = NULL;
  441. struct lpfc_nodelist *ndlp;
  442. int free_evt;
  443. int fcf_inuse;
  444. uint32_t nlp_did;
  445. spin_lock_irq(&phba->hbalock);
  446. while (!list_empty(&phba->work_list)) {
  447. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  448. evt_listp);
  449. spin_unlock_irq(&phba->hbalock);
  450. free_evt = 1;
  451. switch (evtp->evt) {
  452. case LPFC_EVT_ELS_RETRY:
  453. ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
  454. lpfc_els_retry_delay_handler(ndlp);
  455. free_evt = 0; /* evt is part of ndlp */
  456. /* decrement the node reference count held
  457. * for this queued work
  458. */
  459. lpfc_nlp_put(ndlp);
  460. break;
  461. case LPFC_EVT_DEV_LOSS:
  462. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  463. fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
  464. free_evt = 0;
  465. /* decrement the node reference count held for
  466. * this queued work
  467. */
  468. nlp_did = ndlp->nlp_DID;
  469. lpfc_nlp_put(ndlp);
  470. if (phba->sli_rev == LPFC_SLI_REV4)
  471. lpfc_sli4_post_dev_loss_tmo_handler(phba,
  472. fcf_inuse,
  473. nlp_did);
  474. break;
  475. case LPFC_EVT_ONLINE:
  476. if (phba->link_state < LPFC_LINK_DOWN)
  477. *(int *) (evtp->evt_arg1) = lpfc_online(phba);
  478. else
  479. *(int *) (evtp->evt_arg1) = 0;
  480. complete((struct completion *)(evtp->evt_arg2));
  481. break;
  482. case LPFC_EVT_OFFLINE_PREP:
  483. if (phba->link_state >= LPFC_LINK_DOWN)
  484. lpfc_offline_prep(phba);
  485. *(int *)(evtp->evt_arg1) = 0;
  486. complete((struct completion *)(evtp->evt_arg2));
  487. break;
  488. case LPFC_EVT_OFFLINE:
  489. lpfc_offline(phba);
  490. lpfc_sli_brdrestart(phba);
  491. *(int *)(evtp->evt_arg1) =
  492. lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
  493. lpfc_unblock_mgmt_io(phba);
  494. complete((struct completion *)(evtp->evt_arg2));
  495. break;
  496. case LPFC_EVT_WARM_START:
  497. lpfc_offline(phba);
  498. lpfc_reset_barrier(phba);
  499. lpfc_sli_brdreset(phba);
  500. lpfc_hba_down_post(phba);
  501. *(int *)(evtp->evt_arg1) =
  502. lpfc_sli_brdready(phba, HS_MBRDY);
  503. lpfc_unblock_mgmt_io(phba);
  504. complete((struct completion *)(evtp->evt_arg2));
  505. break;
  506. case LPFC_EVT_KILL:
  507. lpfc_offline(phba);
  508. *(int *)(evtp->evt_arg1)
  509. = (phba->pport->stopped)
  510. ? 0 : lpfc_sli_brdkill(phba);
  511. lpfc_unblock_mgmt_io(phba);
  512. complete((struct completion *)(evtp->evt_arg2));
  513. break;
  514. case LPFC_EVT_FASTPATH_MGMT_EVT:
  515. lpfc_send_fastpath_evt(phba, evtp);
  516. free_evt = 0;
  517. break;
  518. case LPFC_EVT_RESET_HBA:
  519. if (!(phba->pport->load_flag & FC_UNLOADING))
  520. lpfc_reset_hba(phba);
  521. break;
  522. }
  523. if (free_evt)
  524. kfree(evtp);
  525. spin_lock_irq(&phba->hbalock);
  526. }
  527. spin_unlock_irq(&phba->hbalock);
  528. }
  529. static void
  530. lpfc_work_done(struct lpfc_hba *phba)
  531. {
  532. struct lpfc_sli_ring *pring;
  533. uint32_t ha_copy, status, control, work_port_events;
  534. struct lpfc_vport **vports;
  535. struct lpfc_vport *vport;
  536. int i;
  537. spin_lock_irq(&phba->hbalock);
  538. ha_copy = phba->work_ha;
  539. phba->work_ha = 0;
  540. spin_unlock_irq(&phba->hbalock);
  541. /* First, try to post the next mailbox command to SLI4 device */
  542. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
  543. lpfc_sli4_post_async_mbox(phba);
  544. if (ha_copy & HA_ERATT)
  545. /* Handle the error attention event */
  546. lpfc_handle_eratt(phba);
  547. if (ha_copy & HA_MBATT)
  548. lpfc_sli_handle_mb_event(phba);
  549. if (ha_copy & HA_LATT)
  550. lpfc_handle_latt(phba);
  551. /* Process SLI4 events */
  552. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
  553. if (phba->hba_flag & HBA_RRQ_ACTIVE)
  554. lpfc_handle_rrq_active(phba);
  555. if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
  556. lpfc_sli4_fcp_xri_abort_event_proc(phba);
  557. if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
  558. lpfc_sli4_els_xri_abort_event_proc(phba);
  559. if (phba->hba_flag & ASYNC_EVENT)
  560. lpfc_sli4_async_event_proc(phba);
  561. if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
  562. spin_lock_irq(&phba->hbalock);
  563. phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
  564. spin_unlock_irq(&phba->hbalock);
  565. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  566. }
  567. if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
  568. lpfc_sli4_fcf_redisc_event_proc(phba);
  569. }
  570. vports = lpfc_create_vport_work_array(phba);
  571. if (vports != NULL)
  572. for (i = 0; i <= phba->max_vports; i++) {
  573. /*
  574. * We could have no vports in array if unloading, so if
  575. * this happens then just use the pport
  576. */
  577. if (vports[i] == NULL && i == 0)
  578. vport = phba->pport;
  579. else
  580. vport = vports[i];
  581. if (vport == NULL)
  582. break;
  583. spin_lock_irq(&vport->work_port_lock);
  584. work_port_events = vport->work_port_events;
  585. vport->work_port_events &= ~work_port_events;
  586. spin_unlock_irq(&vport->work_port_lock);
  587. if (work_port_events & WORKER_DISC_TMO)
  588. lpfc_disc_timeout_handler(vport);
  589. if (work_port_events & WORKER_ELS_TMO)
  590. lpfc_els_timeout_handler(vport);
  591. if (work_port_events & WORKER_HB_TMO)
  592. lpfc_hb_timeout_handler(phba);
  593. if (work_port_events & WORKER_MBOX_TMO)
  594. lpfc_mbox_timeout_handler(phba);
  595. if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
  596. lpfc_unblock_fabric_iocbs(phba);
  597. if (work_port_events & WORKER_FDMI_TMO)
  598. lpfc_fdmi_timeout_handler(vport);
  599. if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
  600. lpfc_ramp_down_queue_handler(phba);
  601. if (work_port_events & WORKER_RAMP_UP_QUEUE)
  602. lpfc_ramp_up_queue_handler(phba);
  603. if (work_port_events & WORKER_DELAYED_DISC_TMO)
  604. lpfc_delayed_disc_timeout_handler(vport);
  605. }
  606. lpfc_destroy_vport_work_array(phba, vports);
  607. pring = &phba->sli.ring[LPFC_ELS_RING];
  608. status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  609. status >>= (4*LPFC_ELS_RING);
  610. if ((status & HA_RXMASK) ||
  611. (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
  612. (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
  613. if (pring->flag & LPFC_STOP_IOCB_EVENT) {
  614. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  615. /* Set the lpfc data pending flag */
  616. set_bit(LPFC_DATA_READY, &phba->data_flags);
  617. } else {
  618. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  619. lpfc_sli_handle_slow_ring_event(phba, pring,
  620. (status &
  621. HA_RXMASK));
  622. }
  623. if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt)
  624. lpfc_drain_txq(phba);
  625. /*
  626. * Turn on Ring interrupts
  627. */
  628. if (phba->sli_rev <= LPFC_SLI_REV3) {
  629. spin_lock_irq(&phba->hbalock);
  630. control = readl(phba->HCregaddr);
  631. if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
  632. lpfc_debugfs_slow_ring_trc(phba,
  633. "WRK Enable ring: cntl:x%x hacopy:x%x",
  634. control, ha_copy, 0);
  635. control |= (HC_R0INT_ENA << LPFC_ELS_RING);
  636. writel(control, phba->HCregaddr);
  637. readl(phba->HCregaddr); /* flush */
  638. } else {
  639. lpfc_debugfs_slow_ring_trc(phba,
  640. "WRK Ring ok: cntl:x%x hacopy:x%x",
  641. control, ha_copy, 0);
  642. }
  643. spin_unlock_irq(&phba->hbalock);
  644. }
  645. }
  646. lpfc_work_list_done(phba);
  647. }
  648. int
  649. lpfc_do_work(void *p)
  650. {
  651. struct lpfc_hba *phba = p;
  652. int rc;
  653. set_user_nice(current, -20);
  654. phba->data_flags = 0;
  655. while (!kthread_should_stop()) {
  656. /* wait and check worker queue activities */
  657. rc = wait_event_interruptible(phba->work_waitq,
  658. (test_and_clear_bit(LPFC_DATA_READY,
  659. &phba->data_flags)
  660. || kthread_should_stop()));
  661. /* Signal wakeup shall terminate the worker thread */
  662. if (rc) {
  663. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  664. "0433 Wakeup on signal: rc=x%x\n", rc);
  665. break;
  666. }
  667. /* Attend pending lpfc data processing */
  668. lpfc_work_done(phba);
  669. }
  670. phba->worker_thread = NULL;
  671. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  672. "0432 Worker thread stopped.\n");
  673. return 0;
  674. }
  675. /*
  676. * This is only called to handle FC worker events. Since this a rare
  677. * occurrence, we allocate a struct lpfc_work_evt structure here instead of
  678. * embedding it in the IOCB.
  679. */
  680. int
  681. lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
  682. uint32_t evt)
  683. {
  684. struct lpfc_work_evt *evtp;
  685. unsigned long flags;
  686. /*
  687. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  688. * be queued to worker thread for processing
  689. */
  690. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
  691. if (!evtp)
  692. return 0;
  693. evtp->evt_arg1 = arg1;
  694. evtp->evt_arg2 = arg2;
  695. evtp->evt = evt;
  696. spin_lock_irqsave(&phba->hbalock, flags);
  697. list_add_tail(&evtp->evt_listp, &phba->work_list);
  698. spin_unlock_irqrestore(&phba->hbalock, flags);
  699. lpfc_worker_wake_up(phba);
  700. return 1;
  701. }
  702. void
  703. lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
  704. {
  705. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  706. struct lpfc_hba *phba = vport->phba;
  707. struct lpfc_nodelist *ndlp, *next_ndlp;
  708. int rc;
  709. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  710. if (!NLP_CHK_NODE_ACT(ndlp))
  711. continue;
  712. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  713. continue;
  714. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
  715. ((vport->port_type == LPFC_NPIV_PORT) &&
  716. (ndlp->nlp_DID == NameServer_DID)))
  717. lpfc_unreg_rpi(vport, ndlp);
  718. /* Leave Fabric nodes alone on link down */
  719. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  720. (!remove && ndlp->nlp_type & NLP_FABRIC))
  721. continue;
  722. rc = lpfc_disc_state_machine(vport, ndlp, NULL,
  723. remove
  724. ? NLP_EVT_DEVICE_RM
  725. : NLP_EVT_DEVICE_RECOVERY);
  726. }
  727. if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
  728. if (phba->sli_rev == LPFC_SLI_REV4)
  729. lpfc_sli4_unreg_all_rpis(vport);
  730. lpfc_mbx_unreg_vpi(vport);
  731. spin_lock_irq(shost->host_lock);
  732. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  733. spin_unlock_irq(shost->host_lock);
  734. }
  735. }
  736. void
  737. lpfc_port_link_failure(struct lpfc_vport *vport)
  738. {
  739. lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
  740. /* Cleanup any outstanding received buffers */
  741. lpfc_cleanup_rcv_buffers(vport);
  742. /* Cleanup any outstanding RSCN activity */
  743. lpfc_els_flush_rscn(vport);
  744. /* Cleanup any outstanding ELS commands */
  745. lpfc_els_flush_cmd(vport);
  746. lpfc_cleanup_rpis(vport, 0);
  747. /* Turn off discovery timer if its running */
  748. lpfc_can_disctmo(vport);
  749. }
  750. void
  751. lpfc_linkdown_port(struct lpfc_vport *vport)
  752. {
  753. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  754. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
  755. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  756. "Link Down: state:x%x rtry:x%x flg:x%x",
  757. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  758. lpfc_port_link_failure(vport);
  759. /* Stop delayed Nport discovery */
  760. spin_lock_irq(shost->host_lock);
  761. vport->fc_flag &= ~FC_DISC_DELAYED;
  762. spin_unlock_irq(shost->host_lock);
  763. del_timer_sync(&vport->delayed_disc_tmo);
  764. }
  765. int
  766. lpfc_linkdown(struct lpfc_hba *phba)
  767. {
  768. struct lpfc_vport *vport = phba->pport;
  769. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  770. struct lpfc_vport **vports;
  771. LPFC_MBOXQ_t *mb;
  772. int i;
  773. if (phba->link_state == LPFC_LINK_DOWN)
  774. return 0;
  775. /* Block all SCSI stack I/Os */
  776. lpfc_scsi_dev_block(phba);
  777. spin_lock_irq(&phba->hbalock);
  778. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  779. spin_unlock_irq(&phba->hbalock);
  780. if (phba->link_state > LPFC_LINK_DOWN) {
  781. phba->link_state = LPFC_LINK_DOWN;
  782. spin_lock_irq(shost->host_lock);
  783. phba->pport->fc_flag &= ~FC_LBIT;
  784. spin_unlock_irq(shost->host_lock);
  785. }
  786. vports = lpfc_create_vport_work_array(phba);
  787. if (vports != NULL)
  788. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  789. /* Issue a LINK DOWN event to all nodes */
  790. lpfc_linkdown_port(vports[i]);
  791. }
  792. lpfc_destroy_vport_work_array(phba, vports);
  793. /* Clean up any firmware default rpi's */
  794. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  795. if (mb) {
  796. lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
  797. mb->vport = vport;
  798. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  799. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  800. == MBX_NOT_FINISHED) {
  801. mempool_free(mb, phba->mbox_mem_pool);
  802. }
  803. }
  804. /* Setup myDID for link up if we are in pt2pt mode */
  805. if (phba->pport->fc_flag & FC_PT2PT) {
  806. phba->pport->fc_myDID = 0;
  807. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  808. if (mb) {
  809. lpfc_config_link(phba, mb);
  810. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  811. mb->vport = vport;
  812. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  813. == MBX_NOT_FINISHED) {
  814. mempool_free(mb, phba->mbox_mem_pool);
  815. }
  816. }
  817. spin_lock_irq(shost->host_lock);
  818. phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  819. spin_unlock_irq(shost->host_lock);
  820. }
  821. return 0;
  822. }
  823. static void
  824. lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
  825. {
  826. struct lpfc_nodelist *ndlp;
  827. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  828. if (!NLP_CHK_NODE_ACT(ndlp))
  829. continue;
  830. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  831. continue;
  832. if (ndlp->nlp_type & NLP_FABRIC) {
  833. /* On Linkup its safe to clean up the ndlp
  834. * from Fabric connections.
  835. */
  836. if (ndlp->nlp_DID != Fabric_DID)
  837. lpfc_unreg_rpi(vport, ndlp);
  838. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  839. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  840. /* Fail outstanding IO now since device is
  841. * marked for PLOGI.
  842. */
  843. lpfc_unreg_rpi(vport, ndlp);
  844. }
  845. }
  846. }
  847. static void
  848. lpfc_linkup_port(struct lpfc_vport *vport)
  849. {
  850. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  851. struct lpfc_hba *phba = vport->phba;
  852. if ((vport->load_flag & FC_UNLOADING) != 0)
  853. return;
  854. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  855. "Link Up: top:x%x speed:x%x flg:x%x",
  856. phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
  857. /* If NPIV is not enabled, only bring the physical port up */
  858. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  859. (vport != phba->pport))
  860. return;
  861. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
  862. spin_lock_irq(shost->host_lock);
  863. vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  864. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  865. vport->fc_flag |= FC_NDISC_ACTIVE;
  866. vport->fc_ns_retry = 0;
  867. spin_unlock_irq(shost->host_lock);
  868. if (vport->fc_flag & FC_LBIT)
  869. lpfc_linkup_cleanup_nodes(vport);
  870. }
  871. static int
  872. lpfc_linkup(struct lpfc_hba *phba)
  873. {
  874. struct lpfc_vport **vports;
  875. int i;
  876. lpfc_cleanup_wt_rrqs(phba);
  877. phba->link_state = LPFC_LINK_UP;
  878. /* Unblock fabric iocbs if they are blocked */
  879. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  880. del_timer_sync(&phba->fabric_block_timer);
  881. vports = lpfc_create_vport_work_array(phba);
  882. if (vports != NULL)
  883. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  884. lpfc_linkup_port(vports[i]);
  885. lpfc_destroy_vport_work_array(phba, vports);
  886. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  887. (phba->sli_rev < LPFC_SLI_REV4))
  888. lpfc_issue_clear_la(phba, phba->pport);
  889. return 0;
  890. }
  891. /*
  892. * This routine handles processing a CLEAR_LA mailbox
  893. * command upon completion. It is setup in the LPFC_MBOXQ
  894. * as the completion routine when the command is
  895. * handed off to the SLI layer.
  896. */
  897. static void
  898. lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  899. {
  900. struct lpfc_vport *vport = pmb->vport;
  901. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  902. struct lpfc_sli *psli = &phba->sli;
  903. MAILBOX_t *mb = &pmb->u.mb;
  904. uint32_t control;
  905. /* Since we don't do discovery right now, turn these off here */
  906. psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  907. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  908. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  909. /* Check for error */
  910. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  911. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  912. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  913. "0320 CLEAR_LA mbxStatus error x%x hba "
  914. "state x%x\n",
  915. mb->mbxStatus, vport->port_state);
  916. phba->link_state = LPFC_HBA_ERROR;
  917. goto out;
  918. }
  919. if (vport->port_type == LPFC_PHYSICAL_PORT)
  920. phba->link_state = LPFC_HBA_READY;
  921. spin_lock_irq(&phba->hbalock);
  922. psli->sli_flag |= LPFC_PROCESS_LA;
  923. control = readl(phba->HCregaddr);
  924. control |= HC_LAINT_ENA;
  925. writel(control, phba->HCregaddr);
  926. readl(phba->HCregaddr); /* flush */
  927. spin_unlock_irq(&phba->hbalock);
  928. mempool_free(pmb, phba->mbox_mem_pool);
  929. return;
  930. out:
  931. /* Device Discovery completes */
  932. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  933. "0225 Device Discovery completes\n");
  934. mempool_free(pmb, phba->mbox_mem_pool);
  935. spin_lock_irq(shost->host_lock);
  936. vport->fc_flag &= ~FC_ABORT_DISCOVERY;
  937. spin_unlock_irq(shost->host_lock);
  938. lpfc_can_disctmo(vport);
  939. /* turn on Link Attention interrupts */
  940. spin_lock_irq(&phba->hbalock);
  941. psli->sli_flag |= LPFC_PROCESS_LA;
  942. control = readl(phba->HCregaddr);
  943. control |= HC_LAINT_ENA;
  944. writel(control, phba->HCregaddr);
  945. readl(phba->HCregaddr); /* flush */
  946. spin_unlock_irq(&phba->hbalock);
  947. return;
  948. }
  949. static void
  950. lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  951. {
  952. struct lpfc_vport *vport = pmb->vport;
  953. if (pmb->u.mb.mbxStatus)
  954. goto out;
  955. mempool_free(pmb, phba->mbox_mem_pool);
  956. /* don't perform discovery for SLI4 loopback diagnostic test */
  957. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  958. !(phba->hba_flag & HBA_FCOE_MODE) &&
  959. (phba->link_flag & LS_LOOPBACK_MODE))
  960. return;
  961. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
  962. vport->fc_flag & FC_PUBLIC_LOOP &&
  963. !(vport->fc_flag & FC_LBIT)) {
  964. /* Need to wait for FAN - use discovery timer
  965. * for timeout. port_state is identically
  966. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  967. */
  968. lpfc_set_disctmo(vport);
  969. return;
  970. }
  971. /* Start discovery by sending a FLOGI. port_state is identically
  972. * LPFC_FLOGI while waiting for FLOGI cmpl
  973. */
  974. if (vport->port_state != LPFC_FLOGI)
  975. lpfc_initial_flogi(vport);
  976. return;
  977. out:
  978. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  979. "0306 CONFIG_LINK mbxStatus error x%x "
  980. "HBA state x%x\n",
  981. pmb->u.mb.mbxStatus, vport->port_state);
  982. mempool_free(pmb, phba->mbox_mem_pool);
  983. lpfc_linkdown(phba);
  984. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  985. "0200 CONFIG_LINK bad hba state x%x\n",
  986. vport->port_state);
  987. lpfc_issue_clear_la(phba, vport);
  988. return;
  989. }
  990. /**
  991. * lpfc_sli4_clear_fcf_rr_bmask
  992. * @phba pointer to the struct lpfc_hba for this port.
  993. * This fucnction resets the round robin bit mask and clears the
  994. * fcf priority list. The list deletions are done while holding the
  995. * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
  996. * from the lpfc_fcf_pri record.
  997. **/
  998. void
  999. lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
  1000. {
  1001. struct lpfc_fcf_pri *fcf_pri;
  1002. struct lpfc_fcf_pri *next_fcf_pri;
  1003. memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
  1004. spin_lock_irq(&phba->hbalock);
  1005. list_for_each_entry_safe(fcf_pri, next_fcf_pri,
  1006. &phba->fcf.fcf_pri_list, list) {
  1007. list_del_init(&fcf_pri->list);
  1008. fcf_pri->fcf_rec.flag = 0;
  1009. }
  1010. spin_unlock_irq(&phba->hbalock);
  1011. }
  1012. static void
  1013. lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1014. {
  1015. struct lpfc_vport *vport = mboxq->vport;
  1016. if (mboxq->u.mb.mbxStatus) {
  1017. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1018. "2017 REG_FCFI mbxStatus error x%x "
  1019. "HBA state x%x\n",
  1020. mboxq->u.mb.mbxStatus, vport->port_state);
  1021. goto fail_out;
  1022. }
  1023. /* Start FCoE discovery by sending a FLOGI. */
  1024. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
  1025. /* Set the FCFI registered flag */
  1026. spin_lock_irq(&phba->hbalock);
  1027. phba->fcf.fcf_flag |= FCF_REGISTERED;
  1028. spin_unlock_irq(&phba->hbalock);
  1029. /* If there is a pending FCoE event, restart FCF table scan. */
  1030. if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
  1031. lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
  1032. goto fail_out;
  1033. /* Mark successful completion of FCF table scan */
  1034. spin_lock_irq(&phba->hbalock);
  1035. phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
  1036. phba->hba_flag &= ~FCF_TS_INPROG;
  1037. if (vport->port_state != LPFC_FLOGI) {
  1038. phba->hba_flag |= FCF_RR_INPROG;
  1039. spin_unlock_irq(&phba->hbalock);
  1040. lpfc_issue_init_vfi(vport);
  1041. goto out;
  1042. }
  1043. spin_unlock_irq(&phba->hbalock);
  1044. goto out;
  1045. fail_out:
  1046. spin_lock_irq(&phba->hbalock);
  1047. phba->hba_flag &= ~FCF_RR_INPROG;
  1048. spin_unlock_irq(&phba->hbalock);
  1049. out:
  1050. mempool_free(mboxq, phba->mbox_mem_pool);
  1051. }
  1052. /**
  1053. * lpfc_fab_name_match - Check if the fcf fabric name match.
  1054. * @fab_name: pointer to fabric name.
  1055. * @new_fcf_record: pointer to fcf record.
  1056. *
  1057. * This routine compare the fcf record's fabric name with provided
  1058. * fabric name. If the fabric name are identical this function
  1059. * returns 1 else return 0.
  1060. **/
  1061. static uint32_t
  1062. lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
  1063. {
  1064. if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
  1065. return 0;
  1066. if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
  1067. return 0;
  1068. if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
  1069. return 0;
  1070. if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
  1071. return 0;
  1072. if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
  1073. return 0;
  1074. if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
  1075. return 0;
  1076. if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
  1077. return 0;
  1078. if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
  1079. return 0;
  1080. return 1;
  1081. }
  1082. /**
  1083. * lpfc_sw_name_match - Check if the fcf switch name match.
  1084. * @fab_name: pointer to fabric name.
  1085. * @new_fcf_record: pointer to fcf record.
  1086. *
  1087. * This routine compare the fcf record's switch name with provided
  1088. * switch name. If the switch name are identical this function
  1089. * returns 1 else return 0.
  1090. **/
  1091. static uint32_t
  1092. lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
  1093. {
  1094. if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
  1095. return 0;
  1096. if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
  1097. return 0;
  1098. if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
  1099. return 0;
  1100. if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
  1101. return 0;
  1102. if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
  1103. return 0;
  1104. if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
  1105. return 0;
  1106. if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
  1107. return 0;
  1108. if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
  1109. return 0;
  1110. return 1;
  1111. }
  1112. /**
  1113. * lpfc_mac_addr_match - Check if the fcf mac address match.
  1114. * @mac_addr: pointer to mac address.
  1115. * @new_fcf_record: pointer to fcf record.
  1116. *
  1117. * This routine compare the fcf record's mac address with HBA's
  1118. * FCF mac address. If the mac addresses are identical this function
  1119. * returns 1 else return 0.
  1120. **/
  1121. static uint32_t
  1122. lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
  1123. {
  1124. if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
  1125. return 0;
  1126. if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
  1127. return 0;
  1128. if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
  1129. return 0;
  1130. if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
  1131. return 0;
  1132. if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
  1133. return 0;
  1134. if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
  1135. return 0;
  1136. return 1;
  1137. }
  1138. static bool
  1139. lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
  1140. {
  1141. return (curr_vlan_id == new_vlan_id);
  1142. }
  1143. /**
  1144. * lpfc_update_fcf_record - Update driver fcf record
  1145. * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
  1146. * @phba: pointer to lpfc hba data structure.
  1147. * @fcf_index: Index for the lpfc_fcf_record.
  1148. * @new_fcf_record: pointer to hba fcf record.
  1149. *
  1150. * This routine updates the driver FCF priority record from the new HBA FCF
  1151. * record. This routine is called with the host lock held.
  1152. **/
  1153. static void
  1154. __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
  1155. struct fcf_record *new_fcf_record
  1156. )
  1157. {
  1158. struct lpfc_fcf_pri *fcf_pri;
  1159. fcf_pri = &phba->fcf.fcf_pri[fcf_index];
  1160. fcf_pri->fcf_rec.fcf_index = fcf_index;
  1161. /* FCF record priority */
  1162. fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
  1163. }
  1164. /**
  1165. * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
  1166. * @fcf: pointer to driver fcf record.
  1167. * @new_fcf_record: pointer to fcf record.
  1168. *
  1169. * This routine copies the FCF information from the FCF
  1170. * record to lpfc_hba data structure.
  1171. **/
  1172. static void
  1173. lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
  1174. struct fcf_record *new_fcf_record)
  1175. {
  1176. /* Fabric name */
  1177. fcf_rec->fabric_name[0] =
  1178. bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
  1179. fcf_rec->fabric_name[1] =
  1180. bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
  1181. fcf_rec->fabric_name[2] =
  1182. bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
  1183. fcf_rec->fabric_name[3] =
  1184. bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
  1185. fcf_rec->fabric_name[4] =
  1186. bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
  1187. fcf_rec->fabric_name[5] =
  1188. bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
  1189. fcf_rec->fabric_name[6] =
  1190. bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
  1191. fcf_rec->fabric_name[7] =
  1192. bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
  1193. /* Mac address */
  1194. fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
  1195. fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
  1196. fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
  1197. fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
  1198. fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
  1199. fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
  1200. /* FCF record index */
  1201. fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  1202. /* FCF record priority */
  1203. fcf_rec->priority = new_fcf_record->fip_priority;
  1204. /* Switch name */
  1205. fcf_rec->switch_name[0] =
  1206. bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
  1207. fcf_rec->switch_name[1] =
  1208. bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
  1209. fcf_rec->switch_name[2] =
  1210. bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
  1211. fcf_rec->switch_name[3] =
  1212. bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
  1213. fcf_rec->switch_name[4] =
  1214. bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
  1215. fcf_rec->switch_name[5] =
  1216. bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
  1217. fcf_rec->switch_name[6] =
  1218. bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
  1219. fcf_rec->switch_name[7] =
  1220. bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
  1221. }
  1222. /**
  1223. * lpfc_update_fcf_record - Update driver fcf record
  1224. * @phba: pointer to lpfc hba data structure.
  1225. * @fcf_rec: pointer to driver fcf record.
  1226. * @new_fcf_record: pointer to hba fcf record.
  1227. * @addr_mode: address mode to be set to the driver fcf record.
  1228. * @vlan_id: vlan tag to be set to the driver fcf record.
  1229. * @flag: flag bits to be set to the driver fcf record.
  1230. *
  1231. * This routine updates the driver FCF record from the new HBA FCF record
  1232. * together with the address mode, vlan_id, and other informations. This
  1233. * routine is called with the host lock held.
  1234. **/
  1235. static void
  1236. __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
  1237. struct fcf_record *new_fcf_record, uint32_t addr_mode,
  1238. uint16_t vlan_id, uint32_t flag)
  1239. {
  1240. /* Copy the fields from the HBA's FCF record */
  1241. lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
  1242. /* Update other fields of driver FCF record */
  1243. fcf_rec->addr_mode = addr_mode;
  1244. fcf_rec->vlan_id = vlan_id;
  1245. fcf_rec->flag |= (flag | RECORD_VALID);
  1246. __lpfc_update_fcf_record_pri(phba,
  1247. bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
  1248. new_fcf_record);
  1249. }
  1250. /**
  1251. * lpfc_register_fcf - Register the FCF with hba.
  1252. * @phba: pointer to lpfc hba data structure.
  1253. *
  1254. * This routine issues a register fcfi mailbox command to register
  1255. * the fcf with HBA.
  1256. **/
  1257. static void
  1258. lpfc_register_fcf(struct lpfc_hba *phba)
  1259. {
  1260. LPFC_MBOXQ_t *fcf_mbxq;
  1261. int rc;
  1262. spin_lock_irq(&phba->hbalock);
  1263. /* If the FCF is not available do nothing. */
  1264. if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
  1265. phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
  1266. spin_unlock_irq(&phba->hbalock);
  1267. return;
  1268. }
  1269. /* The FCF is already registered, start discovery */
  1270. if (phba->fcf.fcf_flag & FCF_REGISTERED) {
  1271. phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
  1272. phba->hba_flag &= ~FCF_TS_INPROG;
  1273. if (phba->pport->port_state != LPFC_FLOGI) {
  1274. phba->hba_flag |= FCF_RR_INPROG;
  1275. spin_unlock_irq(&phba->hbalock);
  1276. lpfc_initial_flogi(phba->pport);
  1277. return;
  1278. }
  1279. spin_unlock_irq(&phba->hbalock);
  1280. return;
  1281. }
  1282. spin_unlock_irq(&phba->hbalock);
  1283. fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1284. if (!fcf_mbxq) {
  1285. spin_lock_irq(&phba->hbalock);
  1286. phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
  1287. spin_unlock_irq(&phba->hbalock);
  1288. return;
  1289. }
  1290. lpfc_reg_fcfi(phba, fcf_mbxq);
  1291. fcf_mbxq->vport = phba->pport;
  1292. fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
  1293. rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
  1294. if (rc == MBX_NOT_FINISHED) {
  1295. spin_lock_irq(&phba->hbalock);
  1296. phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
  1297. spin_unlock_irq(&phba->hbalock);
  1298. mempool_free(fcf_mbxq, phba->mbox_mem_pool);
  1299. }
  1300. return;
  1301. }
  1302. /**
  1303. * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
  1304. * @phba: pointer to lpfc hba data structure.
  1305. * @new_fcf_record: pointer to fcf record.
  1306. * @boot_flag: Indicates if this record used by boot bios.
  1307. * @addr_mode: The address mode to be used by this FCF
  1308. * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
  1309. *
  1310. * This routine compare the fcf record with connect list obtained from the
  1311. * config region to decide if this FCF can be used for SAN discovery. It returns
  1312. * 1 if this record can be used for SAN discovery else return zero. If this FCF
  1313. * record can be used for SAN discovery, the boot_flag will indicate if this FCF
  1314. * is used by boot bios and addr_mode will indicate the addressing mode to be
  1315. * used for this FCF when the function returns.
  1316. * If the FCF record need to be used with a particular vlan id, the vlan is
  1317. * set in the vlan_id on return of the function. If not VLAN tagging need to
  1318. * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
  1319. **/
  1320. static int
  1321. lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
  1322. struct fcf_record *new_fcf_record,
  1323. uint32_t *boot_flag, uint32_t *addr_mode,
  1324. uint16_t *vlan_id)
  1325. {
  1326. struct lpfc_fcf_conn_entry *conn_entry;
  1327. int i, j, fcf_vlan_id = 0;
  1328. /* Find the lowest VLAN id in the FCF record */
  1329. for (i = 0; i < 512; i++) {
  1330. if (new_fcf_record->vlan_bitmap[i]) {
  1331. fcf_vlan_id = i * 8;
  1332. j = 0;
  1333. while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
  1334. j++;
  1335. fcf_vlan_id++;
  1336. }
  1337. break;
  1338. }
  1339. }
  1340. /* If FCF not available return 0 */
  1341. if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
  1342. !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
  1343. return 0;
  1344. if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
  1345. *boot_flag = 0;
  1346. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1347. new_fcf_record);
  1348. if (phba->valid_vlan)
  1349. *vlan_id = phba->vlan_id;
  1350. else
  1351. *vlan_id = LPFC_FCOE_NULL_VID;
  1352. return 1;
  1353. }
  1354. /*
  1355. * If there are no FCF connection table entry, driver connect to all
  1356. * FCFs.
  1357. */
  1358. if (list_empty(&phba->fcf_conn_rec_list)) {
  1359. *boot_flag = 0;
  1360. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1361. new_fcf_record);
  1362. /*
  1363. * When there are no FCF connect entries, use driver's default
  1364. * addressing mode - FPMA.
  1365. */
  1366. if (*addr_mode & LPFC_FCF_FPMA)
  1367. *addr_mode = LPFC_FCF_FPMA;
  1368. /* If FCF record report a vlan id use that vlan id */
  1369. if (fcf_vlan_id)
  1370. *vlan_id = fcf_vlan_id;
  1371. else
  1372. *vlan_id = LPFC_FCOE_NULL_VID;
  1373. return 1;
  1374. }
  1375. list_for_each_entry(conn_entry,
  1376. &phba->fcf_conn_rec_list, list) {
  1377. if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
  1378. continue;
  1379. if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
  1380. !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
  1381. new_fcf_record))
  1382. continue;
  1383. if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
  1384. !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
  1385. new_fcf_record))
  1386. continue;
  1387. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
  1388. /*
  1389. * If the vlan bit map does not have the bit set for the
  1390. * vlan id to be used, then it is not a match.
  1391. */
  1392. if (!(new_fcf_record->vlan_bitmap
  1393. [conn_entry->conn_rec.vlan_tag / 8] &
  1394. (1 << (conn_entry->conn_rec.vlan_tag % 8))))
  1395. continue;
  1396. }
  1397. /*
  1398. * If connection record does not support any addressing mode,
  1399. * skip the FCF record.
  1400. */
  1401. if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
  1402. & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
  1403. continue;
  1404. /*
  1405. * Check if the connection record specifies a required
  1406. * addressing mode.
  1407. */
  1408. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1409. !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
  1410. /*
  1411. * If SPMA required but FCF not support this continue.
  1412. */
  1413. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1414. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1415. new_fcf_record) & LPFC_FCF_SPMA))
  1416. continue;
  1417. /*
  1418. * If FPMA required but FCF not support this continue.
  1419. */
  1420. if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1421. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1422. new_fcf_record) & LPFC_FCF_FPMA))
  1423. continue;
  1424. }
  1425. /*
  1426. * This fcf record matches filtering criteria.
  1427. */
  1428. if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
  1429. *boot_flag = 1;
  1430. else
  1431. *boot_flag = 0;
  1432. /*
  1433. * If user did not specify any addressing mode, or if the
  1434. * preferred addressing mode specified by user is not supported
  1435. * by FCF, allow fabric to pick the addressing mode.
  1436. */
  1437. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1438. new_fcf_record);
  1439. /*
  1440. * If the user specified a required address mode, assign that
  1441. * address mode
  1442. */
  1443. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1444. (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
  1445. *addr_mode = (conn_entry->conn_rec.flags &
  1446. FCFCNCT_AM_SPMA) ?
  1447. LPFC_FCF_SPMA : LPFC_FCF_FPMA;
  1448. /*
  1449. * If the user specified a preferred address mode, use the
  1450. * addr mode only if FCF support the addr_mode.
  1451. */
  1452. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1453. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1454. (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1455. (*addr_mode & LPFC_FCF_SPMA))
  1456. *addr_mode = LPFC_FCF_SPMA;
  1457. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1458. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1459. !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1460. (*addr_mode & LPFC_FCF_FPMA))
  1461. *addr_mode = LPFC_FCF_FPMA;
  1462. /* If matching connect list has a vlan id, use it */
  1463. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
  1464. *vlan_id = conn_entry->conn_rec.vlan_tag;
  1465. /*
  1466. * If no vlan id is specified in connect list, use the vlan id
  1467. * in the FCF record
  1468. */
  1469. else if (fcf_vlan_id)
  1470. *vlan_id = fcf_vlan_id;
  1471. else
  1472. *vlan_id = LPFC_FCOE_NULL_VID;
  1473. return 1;
  1474. }
  1475. return 0;
  1476. }
  1477. /**
  1478. * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
  1479. * @phba: pointer to lpfc hba data structure.
  1480. * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
  1481. *
  1482. * This function check if there is any fcoe event pending while driver
  1483. * scan FCF entries. If there is any pending event, it will restart the
  1484. * FCF saning and return 1 else return 0.
  1485. */
  1486. int
  1487. lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
  1488. {
  1489. /*
  1490. * If the Link is up and no FCoE events while in the
  1491. * FCF discovery, no need to restart FCF discovery.
  1492. */
  1493. if ((phba->link_state >= LPFC_LINK_UP) &&
  1494. (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
  1495. return 0;
  1496. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1497. "2768 Pending link or FCF event during current "
  1498. "handling of the previous event: link_state:x%x, "
  1499. "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
  1500. phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
  1501. phba->fcoe_eventtag);
  1502. spin_lock_irq(&phba->hbalock);
  1503. phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
  1504. spin_unlock_irq(&phba->hbalock);
  1505. if (phba->link_state >= LPFC_LINK_UP) {
  1506. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  1507. "2780 Restart FCF table scan due to "
  1508. "pending FCF event:evt_tag_at_scan:x%x, "
  1509. "evt_tag_current:x%x\n",
  1510. phba->fcoe_eventtag_at_fcf_scan,
  1511. phba->fcoe_eventtag);
  1512. lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  1513. } else {
  1514. /*
  1515. * Do not continue FCF discovery and clear FCF_TS_INPROG
  1516. * flag
  1517. */
  1518. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  1519. "2833 Stop FCF discovery process due to link "
  1520. "state change (x%x)\n", phba->link_state);
  1521. spin_lock_irq(&phba->hbalock);
  1522. phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
  1523. phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
  1524. spin_unlock_irq(&phba->hbalock);
  1525. }
  1526. /* Unregister the currently registered FCF if required */
  1527. if (unreg_fcf) {
  1528. spin_lock_irq(&phba->hbalock);
  1529. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  1530. spin_unlock_irq(&phba->hbalock);
  1531. lpfc_sli4_unregister_fcf(phba);
  1532. }
  1533. return 1;
  1534. }
  1535. /**
  1536. * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
  1537. * @phba: pointer to lpfc hba data structure.
  1538. * @fcf_cnt: number of eligible fcf record seen so far.
  1539. *
  1540. * This function makes an running random selection decision on FCF record to
  1541. * use through a sequence of @fcf_cnt eligible FCF records with equal
  1542. * probability. To perform integer manunipulation of random numbers with
  1543. * size unit32_t, the lower 16 bits of the 32-bit random number returned
  1544. * from random32() are taken as the random random number generated.
  1545. *
  1546. * Returns true when outcome is for the newly read FCF record should be
  1547. * chosen; otherwise, return false when outcome is for keeping the previously
  1548. * chosen FCF record.
  1549. **/
  1550. static bool
  1551. lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
  1552. {
  1553. uint32_t rand_num;
  1554. /* Get 16-bit uniform random number */
  1555. rand_num = (0xFFFF & random32());
  1556. /* Decision with probability 1/fcf_cnt */
  1557. if ((fcf_cnt * rand_num) < 0xFFFF)
  1558. return true;
  1559. else
  1560. return false;
  1561. }
  1562. /**
  1563. * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
  1564. * @phba: pointer to lpfc hba data structure.
  1565. * @mboxq: pointer to mailbox object.
  1566. * @next_fcf_index: pointer to holder of next fcf index.
  1567. *
  1568. * This routine parses the non-embedded fcf mailbox command by performing the
  1569. * necessarily error checking, non-embedded read FCF record mailbox command
  1570. * SGE parsing, and endianness swapping.
  1571. *
  1572. * Returns the pointer to the new FCF record in the non-embedded mailbox
  1573. * command DMA memory if successfully, other NULL.
  1574. */
  1575. static struct fcf_record *
  1576. lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  1577. uint16_t *next_fcf_index)
  1578. {
  1579. void *virt_addr;
  1580. dma_addr_t phys_addr;
  1581. struct lpfc_mbx_sge sge;
  1582. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  1583. uint32_t shdr_status, shdr_add_status;
  1584. union lpfc_sli4_cfg_shdr *shdr;
  1585. struct fcf_record *new_fcf_record;
  1586. /* Get the first SGE entry from the non-embedded DMA memory. This
  1587. * routine only uses a single SGE.
  1588. */
  1589. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  1590. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  1591. if (unlikely(!mboxq->sge_array)) {
  1592. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1593. "2524 Failed to get the non-embedded SGE "
  1594. "virtual address\n");
  1595. return NULL;
  1596. }
  1597. virt_addr = mboxq->sge_array->addr[0];
  1598. shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
  1599. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  1600. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  1601. if (shdr_status || shdr_add_status) {
  1602. if (shdr_status == STATUS_FCF_TABLE_EMPTY)
  1603. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1604. "2726 READ_FCF_RECORD Indicates empty "
  1605. "FCF table.\n");
  1606. else
  1607. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1608. "2521 READ_FCF_RECORD mailbox failed "
  1609. "with status x%x add_status x%x, "
  1610. "mbx\n", shdr_status, shdr_add_status);
  1611. return NULL;
  1612. }
  1613. /* Interpreting the returned information of the FCF record */
  1614. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  1615. lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
  1616. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1617. *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
  1618. new_fcf_record = (struct fcf_record *)(virt_addr +
  1619. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1620. lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
  1621. offsetof(struct fcf_record, vlan_bitmap));
  1622. new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
  1623. new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
  1624. return new_fcf_record;
  1625. }
  1626. /**
  1627. * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
  1628. * @phba: pointer to lpfc hba data structure.
  1629. * @fcf_record: pointer to the fcf record.
  1630. * @vlan_id: the lowest vlan identifier associated to this fcf record.
  1631. * @next_fcf_index: the index to the next fcf record in hba's fcf table.
  1632. *
  1633. * This routine logs the detailed FCF record if the LOG_FIP loggin is
  1634. * enabled.
  1635. **/
  1636. static void
  1637. lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
  1638. struct fcf_record *fcf_record,
  1639. uint16_t vlan_id,
  1640. uint16_t next_fcf_index)
  1641. {
  1642. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1643. "2764 READ_FCF_RECORD:\n"
  1644. "\tFCF_Index : x%x\n"
  1645. "\tFCF_Avail : x%x\n"
  1646. "\tFCF_Valid : x%x\n"
  1647. "\tFIP_Priority : x%x\n"
  1648. "\tMAC_Provider : x%x\n"
  1649. "\tLowest VLANID : x%x\n"
  1650. "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
  1651. "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
  1652. "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
  1653. "\tNext_FCF_Index: x%x\n",
  1654. bf_get(lpfc_fcf_record_fcf_index, fcf_record),
  1655. bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
  1656. bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
  1657. fcf_record->fip_priority,
  1658. bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
  1659. vlan_id,
  1660. bf_get(lpfc_fcf_record_mac_0, fcf_record),
  1661. bf_get(lpfc_fcf_record_mac_1, fcf_record),
  1662. bf_get(lpfc_fcf_record_mac_2, fcf_record),
  1663. bf_get(lpfc_fcf_record_mac_3, fcf_record),
  1664. bf_get(lpfc_fcf_record_mac_4, fcf_record),
  1665. bf_get(lpfc_fcf_record_mac_5, fcf_record),
  1666. bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
  1667. bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
  1668. bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
  1669. bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
  1670. bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
  1671. bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
  1672. bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
  1673. bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
  1674. bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
  1675. bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
  1676. bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
  1677. bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
  1678. bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
  1679. bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
  1680. bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
  1681. bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
  1682. next_fcf_index);
  1683. }
  1684. /**
  1685. lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
  1686. * @phba: pointer to lpfc hba data structure.
  1687. * @fcf_rec: pointer to an existing FCF record.
  1688. * @new_fcf_record: pointer to a new FCF record.
  1689. * @new_vlan_id: vlan id from the new FCF record.
  1690. *
  1691. * This function performs matching test of a new FCF record against an existing
  1692. * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
  1693. * will not be used as part of the FCF record matching criteria.
  1694. *
  1695. * Returns true if all the fields matching, otherwise returns false.
  1696. */
  1697. static bool
  1698. lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
  1699. struct lpfc_fcf_rec *fcf_rec,
  1700. struct fcf_record *new_fcf_record,
  1701. uint16_t new_vlan_id)
  1702. {
  1703. if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
  1704. if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
  1705. return false;
  1706. if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
  1707. return false;
  1708. if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
  1709. return false;
  1710. if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
  1711. return false;
  1712. if (fcf_rec->priority != new_fcf_record->fip_priority)
  1713. return false;
  1714. return true;
  1715. }
  1716. /**
  1717. * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
  1718. * @vport: Pointer to vport object.
  1719. * @fcf_index: index to next fcf.
  1720. *
  1721. * This function processing the roundrobin fcf failover to next fcf index.
  1722. * When this function is invoked, there will be a current fcf registered
  1723. * for flogi.
  1724. * Return: 0 for continue retrying flogi on currently registered fcf;
  1725. * 1 for stop flogi on currently registered fcf;
  1726. */
  1727. int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
  1728. {
  1729. struct lpfc_hba *phba = vport->phba;
  1730. int rc;
  1731. if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
  1732. spin_lock_irq(&phba->hbalock);
  1733. if (phba->hba_flag & HBA_DEVLOSS_TMO) {
  1734. spin_unlock_irq(&phba->hbalock);
  1735. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1736. "2872 Devloss tmo with no eligible "
  1737. "FCF, unregister in-use FCF (x%x) "
  1738. "and rescan FCF table\n",
  1739. phba->fcf.current_rec.fcf_indx);
  1740. lpfc_unregister_fcf_rescan(phba);
  1741. goto stop_flogi_current_fcf;
  1742. }
  1743. /* Mark the end to FLOGI roundrobin failover */
  1744. phba->hba_flag &= ~FCF_RR_INPROG;
  1745. /* Allow action to new fcf asynchronous event */
  1746. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  1747. spin_unlock_irq(&phba->hbalock);
  1748. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1749. "2865 No FCF available, stop roundrobin FCF "
  1750. "failover and change port state:x%x/x%x\n",
  1751. phba->pport->port_state, LPFC_VPORT_UNKNOWN);
  1752. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  1753. goto stop_flogi_current_fcf;
  1754. } else {
  1755. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
  1756. "2794 Try FLOGI roundrobin FCF failover to "
  1757. "(x%x)\n", fcf_index);
  1758. rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
  1759. if (rc)
  1760. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
  1761. "2761 FLOGI roundrobin FCF failover "
  1762. "failed (rc:x%x) to read FCF (x%x)\n",
  1763. rc, phba->fcf.current_rec.fcf_indx);
  1764. else
  1765. goto stop_flogi_current_fcf;
  1766. }
  1767. return 0;
  1768. stop_flogi_current_fcf:
  1769. lpfc_can_disctmo(vport);
  1770. return 1;
  1771. }
  1772. /**
  1773. * lpfc_sli4_fcf_pri_list_del
  1774. * @phba: pointer to lpfc hba data structure.
  1775. * @fcf_index the index of the fcf record to delete
  1776. * This routine checks the on list flag of the fcf_index to be deleted.
  1777. * If it is one the list then it is removed from the list, and the flag
  1778. * is cleared. This routine grab the hbalock before removing the fcf
  1779. * record from the list.
  1780. **/
  1781. static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
  1782. uint16_t fcf_index)
  1783. {
  1784. struct lpfc_fcf_pri *new_fcf_pri;
  1785. new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
  1786. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1787. "3058 deleting idx x%x pri x%x flg x%x\n",
  1788. fcf_index, new_fcf_pri->fcf_rec.priority,
  1789. new_fcf_pri->fcf_rec.flag);
  1790. spin_lock_irq(&phba->hbalock);
  1791. if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
  1792. if (phba->fcf.current_rec.priority ==
  1793. new_fcf_pri->fcf_rec.priority)
  1794. phba->fcf.eligible_fcf_cnt--;
  1795. list_del_init(&new_fcf_pri->list);
  1796. new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
  1797. }
  1798. spin_unlock_irq(&phba->hbalock);
  1799. }
  1800. /**
  1801. * lpfc_sli4_set_fcf_flogi_fail
  1802. * @phba: pointer to lpfc hba data structure.
  1803. * @fcf_index the index of the fcf record to update
  1804. * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
  1805. * flag so the the round robin slection for the particular priority level
  1806. * will try a different fcf record that does not have this bit set.
  1807. * If the fcf record is re-read for any reason this flag is cleared brfore
  1808. * adding it to the priority list.
  1809. **/
  1810. void
  1811. lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
  1812. {
  1813. struct lpfc_fcf_pri *new_fcf_pri;
  1814. new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
  1815. spin_lock_irq(&phba->hbalock);
  1816. new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
  1817. spin_unlock_irq(&phba->hbalock);
  1818. }
  1819. /**
  1820. * lpfc_sli4_fcf_pri_list_add
  1821. * @phba: pointer to lpfc hba data structure.
  1822. * @fcf_index the index of the fcf record to add
  1823. * This routine checks the priority of the fcf_index to be added.
  1824. * If it is a lower priority than the current head of the fcf_pri list
  1825. * then it is added to the list in the right order.
  1826. * If it is the same priority as the current head of the list then it
  1827. * is added to the head of the list and its bit in the rr_bmask is set.
  1828. * If the fcf_index to be added is of a higher priority than the current
  1829. * head of the list then the rr_bmask is cleared, its bit is set in the
  1830. * rr_bmask and it is added to the head of the list.
  1831. * returns:
  1832. * 0=success 1=failure
  1833. **/
  1834. int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, uint16_t fcf_index,
  1835. struct fcf_record *new_fcf_record)
  1836. {
  1837. uint16_t current_fcf_pri;
  1838. uint16_t last_index;
  1839. struct lpfc_fcf_pri *fcf_pri;
  1840. struct lpfc_fcf_pri *next_fcf_pri;
  1841. struct lpfc_fcf_pri *new_fcf_pri;
  1842. int ret;
  1843. new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
  1844. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1845. "3059 adding idx x%x pri x%x flg x%x\n",
  1846. fcf_index, new_fcf_record->fip_priority,
  1847. new_fcf_pri->fcf_rec.flag);
  1848. spin_lock_irq(&phba->hbalock);
  1849. if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
  1850. list_del_init(&new_fcf_pri->list);
  1851. new_fcf_pri->fcf_rec.fcf_index = fcf_index;
  1852. new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
  1853. if (list_empty(&phba->fcf.fcf_pri_list)) {
  1854. list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
  1855. ret = lpfc_sli4_fcf_rr_index_set(phba,
  1856. new_fcf_pri->fcf_rec.fcf_index);
  1857. goto out;
  1858. }
  1859. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  1860. LPFC_SLI4_FCF_TBL_INDX_MAX);
  1861. if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  1862. ret = 0; /* Empty rr list */
  1863. goto out;
  1864. }
  1865. current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
  1866. if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
  1867. list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
  1868. if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
  1869. memset(phba->fcf.fcf_rr_bmask, 0,
  1870. sizeof(*phba->fcf.fcf_rr_bmask));
  1871. /* fcfs_at_this_priority_level = 1; */
  1872. phba->fcf.eligible_fcf_cnt = 1;
  1873. } else
  1874. /* fcfs_at_this_priority_level++; */
  1875. phba->fcf.eligible_fcf_cnt++;
  1876. ret = lpfc_sli4_fcf_rr_index_set(phba,
  1877. new_fcf_pri->fcf_rec.fcf_index);
  1878. goto out;
  1879. }
  1880. list_for_each_entry_safe(fcf_pri, next_fcf_pri,
  1881. &phba->fcf.fcf_pri_list, list) {
  1882. if (new_fcf_pri->fcf_rec.priority <=
  1883. fcf_pri->fcf_rec.priority) {
  1884. if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
  1885. list_add(&new_fcf_pri->list,
  1886. &phba->fcf.fcf_pri_list);
  1887. else
  1888. list_add(&new_fcf_pri->list,
  1889. &((struct lpfc_fcf_pri *)
  1890. fcf_pri->list.prev)->list);
  1891. ret = 0;
  1892. goto out;
  1893. } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
  1894. || new_fcf_pri->fcf_rec.priority <
  1895. next_fcf_pri->fcf_rec.priority) {
  1896. list_add(&new_fcf_pri->list, &fcf_pri->list);
  1897. ret = 0;
  1898. goto out;
  1899. }
  1900. if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
  1901. continue;
  1902. }
  1903. ret = 1;
  1904. out:
  1905. /* we use = instead of |= to clear the FLOGI_FAILED flag. */
  1906. new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
  1907. spin_unlock_irq(&phba->hbalock);
  1908. return ret;
  1909. }
  1910. /**
  1911. * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
  1912. * @phba: pointer to lpfc hba data structure.
  1913. * @mboxq: pointer to mailbox object.
  1914. *
  1915. * This function iterates through all the fcf records available in
  1916. * HBA and chooses the optimal FCF record for discovery. After finding
  1917. * the FCF for discovery it registers the FCF record and kicks start
  1918. * discovery.
  1919. * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
  1920. * use an FCF record which matches fabric name and mac address of the
  1921. * currently used FCF record.
  1922. * If the driver supports only one FCF, it will try to use the FCF record
  1923. * used by BOOT_BIOS.
  1924. */
  1925. void
  1926. lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1927. {
  1928. struct fcf_record *new_fcf_record;
  1929. uint32_t boot_flag, addr_mode;
  1930. uint16_t fcf_index, next_fcf_index;
  1931. struct lpfc_fcf_rec *fcf_rec = NULL;
  1932. uint16_t vlan_id;
  1933. uint32_t seed;
  1934. bool select_new_fcf;
  1935. int rc;
  1936. /* If there is pending FCoE event restart FCF table scan */
  1937. if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
  1938. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1939. return;
  1940. }
  1941. /* Parse the FCF record from the non-embedded mailbox command */
  1942. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  1943. &next_fcf_index);
  1944. if (!new_fcf_record) {
  1945. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1946. "2765 Mailbox command READ_FCF_RECORD "
  1947. "failed to retrieve a FCF record.\n");
  1948. /* Let next new FCF event trigger fast failover */
  1949. spin_lock_irq(&phba->hbalock);
  1950. phba->hba_flag &= ~FCF_TS_INPROG;
  1951. spin_unlock_irq(&phba->hbalock);
  1952. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1953. return;
  1954. }
  1955. /* Check the FCF record against the connection list */
  1956. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  1957. &addr_mode, &vlan_id);
  1958. /* Log the FCF record information if turned on */
  1959. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  1960. next_fcf_index);
  1961. /*
  1962. * If the fcf record does not match with connect list entries
  1963. * read the next entry; otherwise, this is an eligible FCF
  1964. * record for roundrobin FCF failover.
  1965. */
  1966. if (!rc) {
  1967. lpfc_sli4_fcf_pri_list_del(phba,
  1968. bf_get(lpfc_fcf_record_fcf_index,
  1969. new_fcf_record));
  1970. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  1971. "2781 FCF (x%x) failed connection "
  1972. "list check: (x%x/x%x)\n",
  1973. bf_get(lpfc_fcf_record_fcf_index,
  1974. new_fcf_record),
  1975. bf_get(lpfc_fcf_record_fcf_avail,
  1976. new_fcf_record),
  1977. bf_get(lpfc_fcf_record_fcf_valid,
  1978. new_fcf_record));
  1979. if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
  1980. lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
  1981. new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
  1982. if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
  1983. phba->fcf.current_rec.fcf_indx) {
  1984. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1985. "2862 FCF (x%x) matches property "
  1986. "of in-use FCF (x%x)\n",
  1987. bf_get(lpfc_fcf_record_fcf_index,
  1988. new_fcf_record),
  1989. phba->fcf.current_rec.fcf_indx);
  1990. goto read_next_fcf;
  1991. }
  1992. /*
  1993. * In case the current in-use FCF record becomes
  1994. * invalid/unavailable during FCF discovery that
  1995. * was not triggered by fast FCF failover process,
  1996. * treat it as fast FCF failover.
  1997. */
  1998. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
  1999. !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
  2000. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  2001. "2835 Invalid in-use FCF "
  2002. "(x%x), enter FCF failover "
  2003. "table scan.\n",
  2004. phba->fcf.current_rec.fcf_indx);
  2005. spin_lock_irq(&phba->hbalock);
  2006. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  2007. spin_unlock_irq(&phba->hbalock);
  2008. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2009. lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  2010. LPFC_FCOE_FCF_GET_FIRST);
  2011. return;
  2012. }
  2013. }
  2014. goto read_next_fcf;
  2015. } else {
  2016. fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  2017. rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
  2018. new_fcf_record);
  2019. if (rc)
  2020. goto read_next_fcf;
  2021. }
  2022. /*
  2023. * If this is not the first FCF discovery of the HBA, use last
  2024. * FCF record for the discovery. The condition that a rescan
  2025. * matches the in-use FCF record: fabric name, switch name, mac
  2026. * address, and vlan_id.
  2027. */
  2028. spin_lock_irq(&phba->hbalock);
  2029. if (phba->fcf.fcf_flag & FCF_IN_USE) {
  2030. if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
  2031. lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
  2032. new_fcf_record, vlan_id)) {
  2033. if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
  2034. phba->fcf.current_rec.fcf_indx) {
  2035. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  2036. if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
  2037. /* Stop FCF redisc wait timer */
  2038. __lpfc_sli4_stop_fcf_redisc_wait_timer(
  2039. phba);
  2040. else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
  2041. /* Fast failover, mark completed */
  2042. phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
  2043. spin_unlock_irq(&phba->hbalock);
  2044. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2045. "2836 New FCF matches in-use "
  2046. "FCF (x%x)\n",
  2047. phba->fcf.current_rec.fcf_indx);
  2048. goto out;
  2049. } else
  2050. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  2051. "2863 New FCF (x%x) matches "
  2052. "property of in-use FCF (x%x)\n",
  2053. bf_get(lpfc_fcf_record_fcf_index,
  2054. new_fcf_record),
  2055. phba->fcf.current_rec.fcf_indx);
  2056. }
  2057. /*
  2058. * Read next FCF record from HBA searching for the matching
  2059. * with in-use record only if not during the fast failover
  2060. * period. In case of fast failover period, it shall try to
  2061. * determine whether the FCF record just read should be the
  2062. * next candidate.
  2063. */
  2064. if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
  2065. spin_unlock_irq(&phba->hbalock);
  2066. goto read_next_fcf;
  2067. }
  2068. }
  2069. /*
  2070. * Update on failover FCF record only if it's in FCF fast-failover
  2071. * period; otherwise, update on current FCF record.
  2072. */
  2073. if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
  2074. fcf_rec = &phba->fcf.failover_rec;
  2075. else
  2076. fcf_rec = &phba->fcf.current_rec;
  2077. if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
  2078. /*
  2079. * If the driver FCF record does not have boot flag
  2080. * set and new hba fcf record has boot flag set, use
  2081. * the new hba fcf record.
  2082. */
  2083. if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
  2084. /* Choose this FCF record */
  2085. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2086. "2837 Update current FCF record "
  2087. "(x%x) with new FCF record (x%x)\n",
  2088. fcf_rec->fcf_indx,
  2089. bf_get(lpfc_fcf_record_fcf_index,
  2090. new_fcf_record));
  2091. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  2092. addr_mode, vlan_id, BOOT_ENABLE);
  2093. spin_unlock_irq(&phba->hbalock);
  2094. goto read_next_fcf;
  2095. }
  2096. /*
  2097. * If the driver FCF record has boot flag set and the
  2098. * new hba FCF record does not have boot flag, read
  2099. * the next FCF record.
  2100. */
  2101. if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
  2102. spin_unlock_irq(&phba->hbalock);
  2103. goto read_next_fcf;
  2104. }
  2105. /*
  2106. * If the new hba FCF record has lower priority value
  2107. * than the driver FCF record, use the new record.
  2108. */
  2109. if (new_fcf_record->fip_priority < fcf_rec->priority) {
  2110. /* Choose the new FCF record with lower priority */
  2111. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2112. "2838 Update current FCF record "
  2113. "(x%x) with new FCF record (x%x)\n",
  2114. fcf_rec->fcf_indx,
  2115. bf_get(lpfc_fcf_record_fcf_index,
  2116. new_fcf_record));
  2117. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  2118. addr_mode, vlan_id, 0);
  2119. /* Reset running random FCF selection count */
  2120. phba->fcf.eligible_fcf_cnt = 1;
  2121. } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
  2122. /* Update running random FCF selection count */
  2123. phba->fcf.eligible_fcf_cnt++;
  2124. select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
  2125. phba->fcf.eligible_fcf_cnt);
  2126. if (select_new_fcf) {
  2127. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2128. "2839 Update current FCF record "
  2129. "(x%x) with new FCF record (x%x)\n",
  2130. fcf_rec->fcf_indx,
  2131. bf_get(lpfc_fcf_record_fcf_index,
  2132. new_fcf_record));
  2133. /* Choose the new FCF by random selection */
  2134. __lpfc_update_fcf_record(phba, fcf_rec,
  2135. new_fcf_record,
  2136. addr_mode, vlan_id, 0);
  2137. }
  2138. }
  2139. spin_unlock_irq(&phba->hbalock);
  2140. goto read_next_fcf;
  2141. }
  2142. /*
  2143. * This is the first suitable FCF record, choose this record for
  2144. * initial best-fit FCF.
  2145. */
  2146. if (fcf_rec) {
  2147. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2148. "2840 Update initial FCF candidate "
  2149. "with FCF (x%x)\n",
  2150. bf_get(lpfc_fcf_record_fcf_index,
  2151. new_fcf_record));
  2152. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  2153. addr_mode, vlan_id, (boot_flag ?
  2154. BOOT_ENABLE : 0));
  2155. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  2156. /* Setup initial running random FCF selection count */
  2157. phba->fcf.eligible_fcf_cnt = 1;
  2158. /* Seeding the random number generator for random selection */
  2159. seed = (uint32_t)(0xFFFFFFFF & jiffies);
  2160. srandom32(seed);
  2161. }
  2162. spin_unlock_irq(&phba->hbalock);
  2163. goto read_next_fcf;
  2164. read_next_fcf:
  2165. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2166. if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
  2167. if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
  2168. /*
  2169. * Case of FCF fast failover scan
  2170. */
  2171. /*
  2172. * It has not found any suitable FCF record, cancel
  2173. * FCF scan inprogress, and do nothing
  2174. */
  2175. if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
  2176. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  2177. "2782 No suitable FCF found: "
  2178. "(x%x/x%x)\n",
  2179. phba->fcoe_eventtag_at_fcf_scan,
  2180. bf_get(lpfc_fcf_record_fcf_index,
  2181. new_fcf_record));
  2182. spin_lock_irq(&phba->hbalock);
  2183. if (phba->hba_flag & HBA_DEVLOSS_TMO) {
  2184. phba->hba_flag &= ~FCF_TS_INPROG;
  2185. spin_unlock_irq(&phba->hbalock);
  2186. /* Unregister in-use FCF and rescan */
  2187. lpfc_printf_log(phba, KERN_INFO,
  2188. LOG_FIP,
  2189. "2864 On devloss tmo "
  2190. "unreg in-use FCF and "
  2191. "rescan FCF table\n");
  2192. lpfc_unregister_fcf_rescan(phba);
  2193. return;
  2194. }
  2195. /*
  2196. * Let next new FCF event trigger fast failover
  2197. */
  2198. phba->hba_flag &= ~FCF_TS_INPROG;
  2199. spin_unlock_irq(&phba->hbalock);
  2200. return;
  2201. }
  2202. /*
  2203. * It has found a suitable FCF record that is not
  2204. * the same as in-use FCF record, unregister the
  2205. * in-use FCF record, replace the in-use FCF record
  2206. * with the new FCF record, mark FCF fast failover
  2207. * completed, and then start register the new FCF
  2208. * record.
  2209. */
  2210. /* Unregister the current in-use FCF record */
  2211. lpfc_unregister_fcf(phba);
  2212. /* Replace in-use record with the new record */
  2213. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2214. "2842 Replace in-use FCF (x%x) "
  2215. "with failover FCF (x%x)\n",
  2216. phba->fcf.current_rec.fcf_indx,
  2217. phba->fcf.failover_rec.fcf_indx);
  2218. memcpy(&phba->fcf.current_rec,
  2219. &phba->fcf.failover_rec,
  2220. sizeof(struct lpfc_fcf_rec));
  2221. /*
  2222. * Mark the fast FCF failover rediscovery completed
  2223. * and the start of the first round of the roundrobin
  2224. * FCF failover.
  2225. */
  2226. spin_lock_irq(&phba->hbalock);
  2227. phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
  2228. spin_unlock_irq(&phba->hbalock);
  2229. /* Register to the new FCF record */
  2230. lpfc_register_fcf(phba);
  2231. } else {
  2232. /*
  2233. * In case of transaction period to fast FCF failover,
  2234. * do nothing when search to the end of the FCF table.
  2235. */
  2236. if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
  2237. (phba->fcf.fcf_flag & FCF_REDISC_PEND))
  2238. return;
  2239. if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
  2240. phba->fcf.fcf_flag & FCF_IN_USE) {
  2241. /*
  2242. * In case the current in-use FCF record no
  2243. * longer existed during FCF discovery that
  2244. * was not triggered by fast FCF failover
  2245. * process, treat it as fast FCF failover.
  2246. */
  2247. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2248. "2841 In-use FCF record (x%x) "
  2249. "not reported, entering fast "
  2250. "FCF failover mode scanning.\n",
  2251. phba->fcf.current_rec.fcf_indx);
  2252. spin_lock_irq(&phba->hbalock);
  2253. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  2254. spin_unlock_irq(&phba->hbalock);
  2255. lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  2256. LPFC_FCOE_FCF_GET_FIRST);
  2257. return;
  2258. }
  2259. /* Register to the new FCF record */
  2260. lpfc_register_fcf(phba);
  2261. }
  2262. } else
  2263. lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
  2264. return;
  2265. out:
  2266. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2267. lpfc_register_fcf(phba);
  2268. return;
  2269. }
  2270. /**
  2271. * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
  2272. * @phba: pointer to lpfc hba data structure.
  2273. * @mboxq: pointer to mailbox object.
  2274. *
  2275. * This is the callback function for FLOGI failure roundrobin FCF failover
  2276. * read FCF record mailbox command from the eligible FCF record bmask for
  2277. * performing the failover. If the FCF read back is not valid/available, it
  2278. * fails through to retrying FLOGI to the currently registered FCF again.
  2279. * Otherwise, if the FCF read back is valid and available, it will set the
  2280. * newly read FCF record to the failover FCF record, unregister currently
  2281. * registered FCF record, copy the failover FCF record to the current
  2282. * FCF record, and then register the current FCF record before proceeding
  2283. * to trying FLOGI on the new failover FCF.
  2284. */
  2285. void
  2286. lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2287. {
  2288. struct fcf_record *new_fcf_record;
  2289. uint32_t boot_flag, addr_mode;
  2290. uint16_t next_fcf_index, fcf_index;
  2291. uint16_t current_fcf_index;
  2292. uint16_t vlan_id;
  2293. int rc;
  2294. /* If link state is not up, stop the roundrobin failover process */
  2295. if (phba->link_state < LPFC_LINK_UP) {
  2296. spin_lock_irq(&phba->hbalock);
  2297. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  2298. phba->hba_flag &= ~FCF_RR_INPROG;
  2299. spin_unlock_irq(&phba->hbalock);
  2300. goto out;
  2301. }
  2302. /* Parse the FCF record from the non-embedded mailbox command */
  2303. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  2304. &next_fcf_index);
  2305. if (!new_fcf_record) {
  2306. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  2307. "2766 Mailbox command READ_FCF_RECORD "
  2308. "failed to retrieve a FCF record.\n");
  2309. goto error_out;
  2310. }
  2311. /* Get the needed parameters from FCF record */
  2312. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  2313. &addr_mode, &vlan_id);
  2314. /* Log the FCF record information if turned on */
  2315. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  2316. next_fcf_index);
  2317. fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  2318. if (!rc) {
  2319. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2320. "2848 Remove ineligible FCF (x%x) from "
  2321. "from roundrobin bmask\n", fcf_index);
  2322. /* Clear roundrobin bmask bit for ineligible FCF */
  2323. lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
  2324. /* Perform next round of roundrobin FCF failover */
  2325. fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
  2326. rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
  2327. if (rc)
  2328. goto out;
  2329. goto error_out;
  2330. }
  2331. if (fcf_index == phba->fcf.current_rec.fcf_indx) {
  2332. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2333. "2760 Perform FLOGI roundrobin FCF failover: "
  2334. "FCF (x%x) back to FCF (x%x)\n",
  2335. phba->fcf.current_rec.fcf_indx, fcf_index);
  2336. /* Wait 500 ms before retrying FLOGI to current FCF */
  2337. msleep(500);
  2338. lpfc_issue_init_vfi(phba->pport);
  2339. goto out;
  2340. }
  2341. /* Upload new FCF record to the failover FCF record */
  2342. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2343. "2834 Update current FCF (x%x) with new FCF (x%x)\n",
  2344. phba->fcf.failover_rec.fcf_indx, fcf_index);
  2345. spin_lock_irq(&phba->hbalock);
  2346. __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
  2347. new_fcf_record, addr_mode, vlan_id,
  2348. (boot_flag ? BOOT_ENABLE : 0));
  2349. spin_unlock_irq(&phba->hbalock);
  2350. current_fcf_index = phba->fcf.current_rec.fcf_indx;
  2351. /* Unregister the current in-use FCF record */
  2352. lpfc_unregister_fcf(phba);
  2353. /* Replace in-use record with the new record */
  2354. memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
  2355. sizeof(struct lpfc_fcf_rec));
  2356. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2357. "2783 Perform FLOGI roundrobin FCF failover: FCF "
  2358. "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
  2359. error_out:
  2360. lpfc_register_fcf(phba);
  2361. out:
  2362. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2363. }
  2364. /**
  2365. * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
  2366. * @phba: pointer to lpfc hba data structure.
  2367. * @mboxq: pointer to mailbox object.
  2368. *
  2369. * This is the callback function of read FCF record mailbox command for
  2370. * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
  2371. * failover when a new FCF event happened. If the FCF read back is
  2372. * valid/available and it passes the connection list check, it updates
  2373. * the bmask for the eligible FCF record for roundrobin failover.
  2374. */
  2375. void
  2376. lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2377. {
  2378. struct fcf_record *new_fcf_record;
  2379. uint32_t boot_flag, addr_mode;
  2380. uint16_t fcf_index, next_fcf_index;
  2381. uint16_t vlan_id;
  2382. int rc;
  2383. /* If link state is not up, no need to proceed */
  2384. if (phba->link_state < LPFC_LINK_UP)
  2385. goto out;
  2386. /* If FCF discovery period is over, no need to proceed */
  2387. if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
  2388. goto out;
  2389. /* Parse the FCF record from the non-embedded mailbox command */
  2390. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  2391. &next_fcf_index);
  2392. if (!new_fcf_record) {
  2393. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2394. "2767 Mailbox command READ_FCF_RECORD "
  2395. "failed to retrieve a FCF record.\n");
  2396. goto out;
  2397. }
  2398. /* Check the connection list for eligibility */
  2399. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  2400. &addr_mode, &vlan_id);
  2401. /* Log the FCF record information if turned on */
  2402. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  2403. next_fcf_index);
  2404. if (!rc)
  2405. goto out;
  2406. /* Update the eligible FCF record index bmask */
  2407. fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  2408. rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
  2409. out:
  2410. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2411. }
  2412. /**
  2413. * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
  2414. * @phba: pointer to lpfc hba data structure.
  2415. * @mboxq: pointer to mailbox data structure.
  2416. *
  2417. * This function handles completion of init vfi mailbox command.
  2418. */
  2419. void
  2420. lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2421. {
  2422. struct lpfc_vport *vport = mboxq->vport;
  2423. /*
  2424. * VFI not supported on interface type 0, just do the flogi
  2425. * Also continue if the VFI is in use - just use the same one.
  2426. */
  2427. if (mboxq->u.mb.mbxStatus &&
  2428. (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
  2429. LPFC_SLI_INTF_IF_TYPE_0) &&
  2430. mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
  2431. lpfc_printf_vlog(vport, KERN_ERR,
  2432. LOG_MBOX,
  2433. "2891 Init VFI mailbox failed 0x%x\n",
  2434. mboxq->u.mb.mbxStatus);
  2435. mempool_free(mboxq, phba->mbox_mem_pool);
  2436. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2437. return;
  2438. }
  2439. lpfc_initial_flogi(vport);
  2440. mempool_free(mboxq, phba->mbox_mem_pool);
  2441. return;
  2442. }
  2443. /**
  2444. * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
  2445. * @vport: pointer to lpfc_vport data structure.
  2446. *
  2447. * This function issue a init_vfi mailbox command to initialize the VFI and
  2448. * VPI for the physical port.
  2449. */
  2450. void
  2451. lpfc_issue_init_vfi(struct lpfc_vport *vport)
  2452. {
  2453. LPFC_MBOXQ_t *mboxq;
  2454. int rc;
  2455. struct lpfc_hba *phba = vport->phba;
  2456. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2457. if (!mboxq) {
  2458. lpfc_printf_vlog(vport, KERN_ERR,
  2459. LOG_MBOX, "2892 Failed to allocate "
  2460. "init_vfi mailbox\n");
  2461. return;
  2462. }
  2463. lpfc_init_vfi(mboxq, vport);
  2464. mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
  2465. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  2466. if (rc == MBX_NOT_FINISHED) {
  2467. lpfc_printf_vlog(vport, KERN_ERR,
  2468. LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
  2469. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  2470. }
  2471. }
  2472. /**
  2473. * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
  2474. * @phba: pointer to lpfc hba data structure.
  2475. * @mboxq: pointer to mailbox data structure.
  2476. *
  2477. * This function handles completion of init vpi mailbox command.
  2478. */
  2479. void
  2480. lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2481. {
  2482. struct lpfc_vport *vport = mboxq->vport;
  2483. struct lpfc_nodelist *ndlp;
  2484. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2485. if (mboxq->u.mb.mbxStatus) {
  2486. lpfc_printf_vlog(vport, KERN_ERR,
  2487. LOG_MBOX,
  2488. "2609 Init VPI mailbox failed 0x%x\n",
  2489. mboxq->u.mb.mbxStatus);
  2490. mempool_free(mboxq, phba->mbox_mem_pool);
  2491. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2492. return;
  2493. }
  2494. spin_lock_irq(shost->host_lock);
  2495. vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
  2496. spin_unlock_irq(shost->host_lock);
  2497. /* If this port is physical port or FDISC is done, do reg_vpi */
  2498. if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
  2499. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  2500. if (!ndlp)
  2501. lpfc_printf_vlog(vport, KERN_ERR,
  2502. LOG_DISCOVERY,
  2503. "2731 Cannot find fabric "
  2504. "controller node\n");
  2505. else
  2506. lpfc_register_new_vport(phba, vport, ndlp);
  2507. mempool_free(mboxq, phba->mbox_mem_pool);
  2508. return;
  2509. }
  2510. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  2511. lpfc_initial_fdisc(vport);
  2512. else {
  2513. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  2514. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2515. "2606 No NPIV Fabric support\n");
  2516. }
  2517. mempool_free(mboxq, phba->mbox_mem_pool);
  2518. return;
  2519. }
  2520. /**
  2521. * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
  2522. * @vport: pointer to lpfc_vport data structure.
  2523. *
  2524. * This function issue a init_vpi mailbox command to initialize
  2525. * VPI for the vport.
  2526. */
  2527. void
  2528. lpfc_issue_init_vpi(struct lpfc_vport *vport)
  2529. {
  2530. LPFC_MBOXQ_t *mboxq;
  2531. int rc;
  2532. mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
  2533. if (!mboxq) {
  2534. lpfc_printf_vlog(vport, KERN_ERR,
  2535. LOG_MBOX, "2607 Failed to allocate "
  2536. "init_vpi mailbox\n");
  2537. return;
  2538. }
  2539. lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
  2540. mboxq->vport = vport;
  2541. mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
  2542. rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
  2543. if (rc == MBX_NOT_FINISHED) {
  2544. lpfc_printf_vlog(vport, KERN_ERR,
  2545. LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
  2546. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  2547. }
  2548. }
  2549. /**
  2550. * lpfc_start_fdiscs - send fdiscs for each vports on this port.
  2551. * @phba: pointer to lpfc hba data structure.
  2552. *
  2553. * This function loops through the list of vports on the @phba and issues an
  2554. * FDISC if possible.
  2555. */
  2556. void
  2557. lpfc_start_fdiscs(struct lpfc_hba *phba)
  2558. {
  2559. struct lpfc_vport **vports;
  2560. int i;
  2561. vports = lpfc_create_vport_work_array(phba);
  2562. if (vports != NULL) {
  2563. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2564. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  2565. continue;
  2566. /* There are no vpi for this vport */
  2567. if (vports[i]->vpi > phba->max_vpi) {
  2568. lpfc_vport_set_state(vports[i],
  2569. FC_VPORT_FAILED);
  2570. continue;
  2571. }
  2572. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  2573. lpfc_vport_set_state(vports[i],
  2574. FC_VPORT_LINKDOWN);
  2575. continue;
  2576. }
  2577. if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
  2578. lpfc_issue_init_vpi(vports[i]);
  2579. continue;
  2580. }
  2581. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  2582. lpfc_initial_fdisc(vports[i]);
  2583. else {
  2584. lpfc_vport_set_state(vports[i],
  2585. FC_VPORT_NO_FABRIC_SUPP);
  2586. lpfc_printf_vlog(vports[i], KERN_ERR,
  2587. LOG_ELS,
  2588. "0259 No NPIV "
  2589. "Fabric support\n");
  2590. }
  2591. }
  2592. }
  2593. lpfc_destroy_vport_work_array(phba, vports);
  2594. }
  2595. void
  2596. lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2597. {
  2598. struct lpfc_dmabuf *dmabuf = mboxq->context1;
  2599. struct lpfc_vport *vport = mboxq->vport;
  2600. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2601. if (mboxq->u.mb.mbxStatus) {
  2602. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2603. "2018 REG_VFI mbxStatus error x%x "
  2604. "HBA state x%x\n",
  2605. mboxq->u.mb.mbxStatus, vport->port_state);
  2606. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  2607. /* FLOGI failed, use loop map to make discovery list */
  2608. lpfc_disc_list_loopmap(vport);
  2609. /* Start discovery */
  2610. lpfc_disc_start(vport);
  2611. goto out_free_mem;
  2612. }
  2613. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2614. goto out_free_mem;
  2615. }
  2616. /* The VPI is implicitly registered when the VFI is registered */
  2617. spin_lock_irq(shost->host_lock);
  2618. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2619. vport->fc_flag |= FC_VFI_REGISTERED;
  2620. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2621. vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
  2622. spin_unlock_irq(shost->host_lock);
  2623. /* In case SLI4 FC loopback test, we are ready */
  2624. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  2625. (phba->link_flag & LS_LOOPBACK_MODE)) {
  2626. phba->link_state = LPFC_HBA_READY;
  2627. goto out_free_mem;
  2628. }
  2629. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  2630. /* For private loop just start discovery and we are done. */
  2631. if ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
  2632. !(vport->fc_flag & FC_PUBLIC_LOOP)) {
  2633. /* Use loop map to make discovery list */
  2634. lpfc_disc_list_loopmap(vport);
  2635. /* Start discovery */
  2636. lpfc_disc_start(vport);
  2637. } else {
  2638. lpfc_start_fdiscs(phba);
  2639. lpfc_do_scr_ns_plogi(phba, vport);
  2640. }
  2641. }
  2642. out_free_mem:
  2643. mempool_free(mboxq, phba->mbox_mem_pool);
  2644. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  2645. kfree(dmabuf);
  2646. return;
  2647. }
  2648. static void
  2649. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2650. {
  2651. MAILBOX_t *mb = &pmb->u.mb;
  2652. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  2653. struct lpfc_vport *vport = pmb->vport;
  2654. /* Check for error */
  2655. if (mb->mbxStatus) {
  2656. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  2657. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2658. "0319 READ_SPARAM mbxStatus error x%x "
  2659. "hba state x%x>\n",
  2660. mb->mbxStatus, vport->port_state);
  2661. lpfc_linkdown(phba);
  2662. goto out;
  2663. }
  2664. memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
  2665. sizeof (struct serv_parm));
  2666. lpfc_update_vport_wwn(vport);
  2667. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2668. memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
  2669. memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
  2670. }
  2671. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2672. kfree(mp);
  2673. mempool_free(pmb, phba->mbox_mem_pool);
  2674. return;
  2675. out:
  2676. pmb->context1 = NULL;
  2677. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2678. kfree(mp);
  2679. lpfc_issue_clear_la(phba, vport);
  2680. mempool_free(pmb, phba->mbox_mem_pool);
  2681. return;
  2682. }
  2683. static void
  2684. lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
  2685. {
  2686. struct lpfc_vport *vport = phba->pport;
  2687. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
  2688. struct Scsi_Host *shost;
  2689. int i;
  2690. struct lpfc_dmabuf *mp;
  2691. int rc;
  2692. struct fcf_record *fcf_record;
  2693. spin_lock_irq(&phba->hbalock);
  2694. switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
  2695. case LPFC_LINK_SPEED_1GHZ:
  2696. case LPFC_LINK_SPEED_2GHZ:
  2697. case LPFC_LINK_SPEED_4GHZ:
  2698. case LPFC_LINK_SPEED_8GHZ:
  2699. case LPFC_LINK_SPEED_10GHZ:
  2700. case LPFC_LINK_SPEED_16GHZ:
  2701. phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
  2702. break;
  2703. default:
  2704. phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
  2705. break;
  2706. }
  2707. phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
  2708. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  2709. shost = lpfc_shost_from_vport(vport);
  2710. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  2711. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  2712. /* if npiv is enabled and this adapter supports npiv log
  2713. * a message that npiv is not supported in this topology
  2714. */
  2715. if (phba->cfg_enable_npiv && phba->max_vpi)
  2716. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2717. "1309 Link Up Event npiv not supported in loop "
  2718. "topology\n");
  2719. /* Get Loop Map information */
  2720. if (bf_get(lpfc_mbx_read_top_il, la)) {
  2721. spin_lock_irq(shost->host_lock);
  2722. vport->fc_flag |= FC_LBIT;
  2723. spin_unlock_irq(shost->host_lock);
  2724. }
  2725. vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
  2726. i = la->lilpBde64.tus.f.bdeSize;
  2727. if (i == 0) {
  2728. phba->alpa_map[0] = 0;
  2729. } else {
  2730. if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
  2731. int numalpa, j, k;
  2732. union {
  2733. uint8_t pamap[16];
  2734. struct {
  2735. uint32_t wd1;
  2736. uint32_t wd2;
  2737. uint32_t wd3;
  2738. uint32_t wd4;
  2739. } pa;
  2740. } un;
  2741. numalpa = phba->alpa_map[0];
  2742. j = 0;
  2743. while (j < numalpa) {
  2744. memset(un.pamap, 0, 16);
  2745. for (k = 1; j < numalpa; k++) {
  2746. un.pamap[k - 1] =
  2747. phba->alpa_map[j + 1];
  2748. j++;
  2749. if (k == 16)
  2750. break;
  2751. }
  2752. /* Link Up Event ALPA map */
  2753. lpfc_printf_log(phba,
  2754. KERN_WARNING,
  2755. LOG_LINK_EVENT,
  2756. "1304 Link Up Event "
  2757. "ALPA map Data: x%x "
  2758. "x%x x%x x%x\n",
  2759. un.pa.wd1, un.pa.wd2,
  2760. un.pa.wd3, un.pa.wd4);
  2761. }
  2762. }
  2763. }
  2764. } else {
  2765. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  2766. if (phba->max_vpi && phba->cfg_enable_npiv &&
  2767. (phba->sli_rev >= LPFC_SLI_REV3))
  2768. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  2769. }
  2770. vport->fc_myDID = phba->fc_pref_DID;
  2771. spin_lock_irq(shost->host_lock);
  2772. vport->fc_flag |= FC_LBIT;
  2773. spin_unlock_irq(shost->host_lock);
  2774. }
  2775. spin_unlock_irq(&phba->hbalock);
  2776. lpfc_linkup(phba);
  2777. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2778. if (!sparam_mbox)
  2779. goto out;
  2780. rc = lpfc_read_sparam(phba, sparam_mbox, 0);
  2781. if (rc) {
  2782. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  2783. goto out;
  2784. }
  2785. sparam_mbox->vport = vport;
  2786. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  2787. rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
  2788. if (rc == MBX_NOT_FINISHED) {
  2789. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  2790. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2791. kfree(mp);
  2792. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  2793. goto out;
  2794. }
  2795. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  2796. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2797. if (!cfglink_mbox)
  2798. goto out;
  2799. vport->port_state = LPFC_LOCAL_CFG_LINK;
  2800. lpfc_config_link(phba, cfglink_mbox);
  2801. cfglink_mbox->vport = vport;
  2802. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  2803. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
  2804. if (rc == MBX_NOT_FINISHED) {
  2805. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  2806. goto out;
  2807. }
  2808. } else {
  2809. vport->port_state = LPFC_VPORT_UNKNOWN;
  2810. /*
  2811. * Add the driver's default FCF record at FCF index 0 now. This
  2812. * is phase 1 implementation that support FCF index 0 and driver
  2813. * defaults.
  2814. */
  2815. if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
  2816. fcf_record = kzalloc(sizeof(struct fcf_record),
  2817. GFP_KERNEL);
  2818. if (unlikely(!fcf_record)) {
  2819. lpfc_printf_log(phba, KERN_ERR,
  2820. LOG_MBOX | LOG_SLI,
  2821. "2554 Could not allocate memory for "
  2822. "fcf record\n");
  2823. rc = -ENODEV;
  2824. goto out;
  2825. }
  2826. lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
  2827. LPFC_FCOE_FCF_DEF_INDEX);
  2828. rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
  2829. if (unlikely(rc)) {
  2830. lpfc_printf_log(phba, KERN_ERR,
  2831. LOG_MBOX | LOG_SLI,
  2832. "2013 Could not manually add FCF "
  2833. "record 0, status %d\n", rc);
  2834. rc = -ENODEV;
  2835. kfree(fcf_record);
  2836. goto out;
  2837. }
  2838. kfree(fcf_record);
  2839. }
  2840. /*
  2841. * The driver is expected to do FIP/FCF. Call the port
  2842. * and get the FCF Table.
  2843. */
  2844. spin_lock_irq(&phba->hbalock);
  2845. if (phba->hba_flag & FCF_TS_INPROG) {
  2846. spin_unlock_irq(&phba->hbalock);
  2847. return;
  2848. }
  2849. /* This is the initial FCF discovery scan */
  2850. phba->fcf.fcf_flag |= FCF_INIT_DISC;
  2851. spin_unlock_irq(&phba->hbalock);
  2852. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  2853. "2778 Start FCF table scan at linkup\n");
  2854. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  2855. LPFC_FCOE_FCF_GET_FIRST);
  2856. if (rc) {
  2857. spin_lock_irq(&phba->hbalock);
  2858. phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
  2859. spin_unlock_irq(&phba->hbalock);
  2860. goto out;
  2861. }
  2862. /* Reset FCF roundrobin bmask for new discovery */
  2863. lpfc_sli4_clear_fcf_rr_bmask(phba);
  2864. }
  2865. return;
  2866. out:
  2867. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2868. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2869. "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  2870. vport->port_state, sparam_mbox, cfglink_mbox);
  2871. lpfc_issue_clear_la(phba, vport);
  2872. return;
  2873. }
  2874. static void
  2875. lpfc_enable_la(struct lpfc_hba *phba)
  2876. {
  2877. uint32_t control;
  2878. struct lpfc_sli *psli = &phba->sli;
  2879. spin_lock_irq(&phba->hbalock);
  2880. psli->sli_flag |= LPFC_PROCESS_LA;
  2881. if (phba->sli_rev <= LPFC_SLI_REV3) {
  2882. control = readl(phba->HCregaddr);
  2883. control |= HC_LAINT_ENA;
  2884. writel(control, phba->HCregaddr);
  2885. readl(phba->HCregaddr); /* flush */
  2886. }
  2887. spin_unlock_irq(&phba->hbalock);
  2888. }
  2889. static void
  2890. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  2891. {
  2892. lpfc_linkdown(phba);
  2893. lpfc_enable_la(phba);
  2894. lpfc_unregister_unused_fcf(phba);
  2895. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  2896. }
  2897. /*
  2898. * This routine handles processing a READ_TOPOLOGY mailbox
  2899. * command upon completion. It is setup in the LPFC_MBOXQ
  2900. * as the completion routine when the command is
  2901. * handed off to the SLI layer.
  2902. */
  2903. void
  2904. lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2905. {
  2906. struct lpfc_vport *vport = pmb->vport;
  2907. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2908. struct lpfc_mbx_read_top *la;
  2909. MAILBOX_t *mb = &pmb->u.mb;
  2910. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2911. /* Unblock ELS traffic */
  2912. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  2913. /* Check for error */
  2914. if (mb->mbxStatus) {
  2915. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  2916. "1307 READ_LA mbox error x%x state x%x\n",
  2917. mb->mbxStatus, vport->port_state);
  2918. lpfc_mbx_issue_link_down(phba);
  2919. phba->link_state = LPFC_HBA_ERROR;
  2920. goto lpfc_mbx_cmpl_read_topology_free_mbuf;
  2921. }
  2922. la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
  2923. memcpy(&phba->alpa_map[0], mp->virt, 128);
  2924. spin_lock_irq(shost->host_lock);
  2925. if (bf_get(lpfc_mbx_read_top_pb, la))
  2926. vport->fc_flag |= FC_BYPASSED_MODE;
  2927. else
  2928. vport->fc_flag &= ~FC_BYPASSED_MODE;
  2929. spin_unlock_irq(shost->host_lock);
  2930. if ((phba->fc_eventTag < la->eventTag) ||
  2931. (phba->fc_eventTag == la->eventTag)) {
  2932. phba->fc_stat.LinkMultiEvent++;
  2933. if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
  2934. if (phba->fc_eventTag != 0)
  2935. lpfc_linkdown(phba);
  2936. }
  2937. phba->fc_eventTag = la->eventTag;
  2938. spin_lock_irq(&phba->hbalock);
  2939. if (bf_get(lpfc_mbx_read_top_mm, la))
  2940. phba->sli.sli_flag |= LPFC_MENLO_MAINT;
  2941. else
  2942. phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
  2943. spin_unlock_irq(&phba->hbalock);
  2944. phba->link_events++;
  2945. if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
  2946. (!bf_get(lpfc_mbx_read_top_mm, la))) {
  2947. phba->fc_stat.LinkUp++;
  2948. if (phba->link_flag & LS_LOOPBACK_MODE) {
  2949. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2950. "1306 Link Up Event in loop back mode "
  2951. "x%x received Data: x%x x%x x%x x%x\n",
  2952. la->eventTag, phba->fc_eventTag,
  2953. bf_get(lpfc_mbx_read_top_alpa_granted,
  2954. la),
  2955. bf_get(lpfc_mbx_read_top_link_spd, la),
  2956. phba->alpa_map[0]);
  2957. } else {
  2958. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2959. "1303 Link Up Event x%x received "
  2960. "Data: x%x x%x x%x x%x x%x x%x %d\n",
  2961. la->eventTag, phba->fc_eventTag,
  2962. bf_get(lpfc_mbx_read_top_alpa_granted,
  2963. la),
  2964. bf_get(lpfc_mbx_read_top_link_spd, la),
  2965. phba->alpa_map[0],
  2966. bf_get(lpfc_mbx_read_top_mm, la),
  2967. bf_get(lpfc_mbx_read_top_fa, la),
  2968. phba->wait_4_mlo_maint_flg);
  2969. }
  2970. lpfc_mbx_process_link_up(phba, la);
  2971. } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
  2972. LPFC_ATT_LINK_DOWN) {
  2973. phba->fc_stat.LinkDown++;
  2974. if (phba->link_flag & LS_LOOPBACK_MODE)
  2975. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2976. "1308 Link Down Event in loop back mode "
  2977. "x%x received "
  2978. "Data: x%x x%x x%x\n",
  2979. la->eventTag, phba->fc_eventTag,
  2980. phba->pport->port_state, vport->fc_flag);
  2981. else
  2982. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2983. "1305 Link Down Event x%x received "
  2984. "Data: x%x x%x x%x x%x x%x\n",
  2985. la->eventTag, phba->fc_eventTag,
  2986. phba->pport->port_state, vport->fc_flag,
  2987. bf_get(lpfc_mbx_read_top_mm, la),
  2988. bf_get(lpfc_mbx_read_top_fa, la));
  2989. lpfc_mbx_issue_link_down(phba);
  2990. }
  2991. if ((bf_get(lpfc_mbx_read_top_mm, la)) &&
  2992. (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)) {
  2993. if (phba->link_state != LPFC_LINK_DOWN) {
  2994. phba->fc_stat.LinkDown++;
  2995. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2996. "1312 Link Down Event x%x received "
  2997. "Data: x%x x%x x%x\n",
  2998. la->eventTag, phba->fc_eventTag,
  2999. phba->pport->port_state, vport->fc_flag);
  3000. lpfc_mbx_issue_link_down(phba);
  3001. } else
  3002. lpfc_enable_la(phba);
  3003. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  3004. "1310 Menlo Maint Mode Link up Event x%x rcvd "
  3005. "Data: x%x x%x x%x\n",
  3006. la->eventTag, phba->fc_eventTag,
  3007. phba->pport->port_state, vport->fc_flag);
  3008. /*
  3009. * The cmnd that triggered this will be waiting for this
  3010. * signal.
  3011. */
  3012. /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
  3013. if (phba->wait_4_mlo_maint_flg) {
  3014. phba->wait_4_mlo_maint_flg = 0;
  3015. wake_up_interruptible(&phba->wait_4_mlo_m_q);
  3016. }
  3017. }
  3018. if (bf_get(lpfc_mbx_read_top_fa, la)) {
  3019. if (bf_get(lpfc_mbx_read_top_mm, la))
  3020. lpfc_issue_clear_la(phba, vport);
  3021. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  3022. "1311 fa %d\n",
  3023. bf_get(lpfc_mbx_read_top_fa, la));
  3024. }
  3025. lpfc_mbx_cmpl_read_topology_free_mbuf:
  3026. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3027. kfree(mp);
  3028. mempool_free(pmb, phba->mbox_mem_pool);
  3029. return;
  3030. }
  3031. /*
  3032. * This routine handles processing a REG_LOGIN mailbox
  3033. * command upon completion. It is setup in the LPFC_MBOXQ
  3034. * as the completion routine when the command is
  3035. * handed off to the SLI layer.
  3036. */
  3037. void
  3038. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3039. {
  3040. struct lpfc_vport *vport = pmb->vport;
  3041. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3042. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3043. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3044. pmb->context1 = NULL;
  3045. pmb->context2 = NULL;
  3046. if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
  3047. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  3048. if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
  3049. ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
  3050. /* We rcvd a rscn after issuing this
  3051. * mbox reg login, we may have cycled
  3052. * back through the state and be
  3053. * back at reg login state so this
  3054. * mbox needs to be ignored becase
  3055. * there is another reg login in
  3056. * process.
  3057. */
  3058. spin_lock_irq(shost->host_lock);
  3059. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  3060. spin_unlock_irq(shost->host_lock);
  3061. } else
  3062. /* Good status, call state machine */
  3063. lpfc_disc_state_machine(vport, ndlp, pmb,
  3064. NLP_EVT_CMPL_REG_LOGIN);
  3065. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3066. kfree(mp);
  3067. mempool_free(pmb, phba->mbox_mem_pool);
  3068. /* decrement the node reference count held for this callback
  3069. * function.
  3070. */
  3071. lpfc_nlp_put(ndlp);
  3072. return;
  3073. }
  3074. static void
  3075. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3076. {
  3077. MAILBOX_t *mb = &pmb->u.mb;
  3078. struct lpfc_vport *vport = pmb->vport;
  3079. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3080. switch (mb->mbxStatus) {
  3081. case 0x0011:
  3082. case 0x0020:
  3083. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3084. "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
  3085. mb->mbxStatus);
  3086. break;
  3087. /* If VPI is busy, reset the HBA */
  3088. case 0x9700:
  3089. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  3090. "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
  3091. vport->vpi, mb->mbxStatus);
  3092. if (!(phba->pport->load_flag & FC_UNLOADING))
  3093. lpfc_workq_post_event(phba, NULL, NULL,
  3094. LPFC_EVT_RESET_HBA);
  3095. }
  3096. spin_lock_irq(shost->host_lock);
  3097. vport->vpi_state &= ~LPFC_VPI_REGISTERED;
  3098. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3099. spin_unlock_irq(shost->host_lock);
  3100. vport->unreg_vpi_cmpl = VPORT_OK;
  3101. mempool_free(pmb, phba->mbox_mem_pool);
  3102. lpfc_cleanup_vports_rrqs(vport, NULL);
  3103. /*
  3104. * This shost reference might have been taken at the beginning of
  3105. * lpfc_vport_delete()
  3106. */
  3107. if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
  3108. scsi_host_put(shost);
  3109. }
  3110. int
  3111. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  3112. {
  3113. struct lpfc_hba *phba = vport->phba;
  3114. LPFC_MBOXQ_t *mbox;
  3115. int rc;
  3116. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3117. if (!mbox)
  3118. return 1;
  3119. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  3120. mbox->vport = vport;
  3121. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  3122. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3123. if (rc == MBX_NOT_FINISHED) {
  3124. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  3125. "1800 Could not issue unreg_vpi\n");
  3126. mempool_free(mbox, phba->mbox_mem_pool);
  3127. vport->unreg_vpi_cmpl = VPORT_ERROR;
  3128. return rc;
  3129. }
  3130. return 0;
  3131. }
  3132. static void
  3133. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3134. {
  3135. struct lpfc_vport *vport = pmb->vport;
  3136. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3137. MAILBOX_t *mb = &pmb->u.mb;
  3138. switch (mb->mbxStatus) {
  3139. case 0x0011:
  3140. case 0x9601:
  3141. case 0x9602:
  3142. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3143. "0912 cmpl_reg_vpi, mb status = 0x%x\n",
  3144. mb->mbxStatus);
  3145. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3146. spin_lock_irq(shost->host_lock);
  3147. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  3148. spin_unlock_irq(shost->host_lock);
  3149. vport->fc_myDID = 0;
  3150. goto out;
  3151. }
  3152. spin_lock_irq(shost->host_lock);
  3153. vport->vpi_state |= LPFC_VPI_REGISTERED;
  3154. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3155. spin_unlock_irq(shost->host_lock);
  3156. vport->num_disc_nodes = 0;
  3157. /* go thru NPR list and issue ELS PLOGIs */
  3158. if (vport->fc_npr_cnt)
  3159. lpfc_els_disc_plogi(vport);
  3160. if (!vport->num_disc_nodes) {
  3161. spin_lock_irq(shost->host_lock);
  3162. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3163. spin_unlock_irq(shost->host_lock);
  3164. lpfc_can_disctmo(vport);
  3165. }
  3166. vport->port_state = LPFC_VPORT_READY;
  3167. out:
  3168. mempool_free(pmb, phba->mbox_mem_pool);
  3169. return;
  3170. }
  3171. /**
  3172. * lpfc_create_static_vport - Read HBA config region to create static vports.
  3173. * @phba: pointer to lpfc hba data structure.
  3174. *
  3175. * This routine issue a DUMP mailbox command for config region 22 to get
  3176. * the list of static vports to be created. The function create vports
  3177. * based on the information returned from the HBA.
  3178. **/
  3179. void
  3180. lpfc_create_static_vport(struct lpfc_hba *phba)
  3181. {
  3182. LPFC_MBOXQ_t *pmb = NULL;
  3183. MAILBOX_t *mb;
  3184. struct static_vport_info *vport_info;
  3185. int rc = 0, i;
  3186. struct fc_vport_identifiers vport_id;
  3187. struct fc_vport *new_fc_vport;
  3188. struct Scsi_Host *shost;
  3189. struct lpfc_vport *vport;
  3190. uint16_t offset = 0;
  3191. uint8_t *vport_buff;
  3192. struct lpfc_dmabuf *mp;
  3193. uint32_t byte_count = 0;
  3194. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3195. if (!pmb) {
  3196. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3197. "0542 lpfc_create_static_vport failed to"
  3198. " allocate mailbox memory\n");
  3199. return;
  3200. }
  3201. mb = &pmb->u.mb;
  3202. vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
  3203. if (!vport_info) {
  3204. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3205. "0543 lpfc_create_static_vport failed to"
  3206. " allocate vport_info\n");
  3207. mempool_free(pmb, phba->mbox_mem_pool);
  3208. return;
  3209. }
  3210. vport_buff = (uint8_t *) vport_info;
  3211. do {
  3212. if (lpfc_dump_static_vport(phba, pmb, offset))
  3213. goto out;
  3214. pmb->vport = phba->pport;
  3215. rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
  3216. if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
  3217. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3218. "0544 lpfc_create_static_vport failed to"
  3219. " issue dump mailbox command ret 0x%x "
  3220. "status 0x%x\n",
  3221. rc, mb->mbxStatus);
  3222. goto out;
  3223. }
  3224. if (phba->sli_rev == LPFC_SLI_REV4) {
  3225. byte_count = pmb->u.mqe.un.mb_words[5];
  3226. mp = (struct lpfc_dmabuf *) pmb->context2;
  3227. if (byte_count > sizeof(struct static_vport_info) -
  3228. offset)
  3229. byte_count = sizeof(struct static_vport_info)
  3230. - offset;
  3231. memcpy(vport_buff + offset, mp->virt, byte_count);
  3232. offset += byte_count;
  3233. } else {
  3234. if (mb->un.varDmp.word_cnt >
  3235. sizeof(struct static_vport_info) - offset)
  3236. mb->un.varDmp.word_cnt =
  3237. sizeof(struct static_vport_info)
  3238. - offset;
  3239. byte_count = mb->un.varDmp.word_cnt;
  3240. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  3241. vport_buff + offset,
  3242. byte_count);
  3243. offset += byte_count;
  3244. }
  3245. } while (byte_count &&
  3246. offset < sizeof(struct static_vport_info));
  3247. if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
  3248. ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
  3249. != VPORT_INFO_REV)) {
  3250. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3251. "0545 lpfc_create_static_vport bad"
  3252. " information header 0x%x 0x%x\n",
  3253. le32_to_cpu(vport_info->signature),
  3254. le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
  3255. goto out;
  3256. }
  3257. shost = lpfc_shost_from_vport(phba->pport);
  3258. for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
  3259. memset(&vport_id, 0, sizeof(vport_id));
  3260. vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
  3261. vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
  3262. if (!vport_id.port_name || !vport_id.node_name)
  3263. continue;
  3264. vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
  3265. vport_id.vport_type = FC_PORTTYPE_NPIV;
  3266. vport_id.disable = false;
  3267. new_fc_vport = fc_vport_create(shost, 0, &vport_id);
  3268. if (!new_fc_vport) {
  3269. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  3270. "0546 lpfc_create_static_vport failed to"
  3271. " create vport\n");
  3272. continue;
  3273. }
  3274. vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
  3275. vport->vport_flag |= STATIC_VPORT;
  3276. }
  3277. out:
  3278. kfree(vport_info);
  3279. if (rc != MBX_TIMEOUT) {
  3280. if (pmb->context2) {
  3281. mp = (struct lpfc_dmabuf *) pmb->context2;
  3282. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3283. kfree(mp);
  3284. }
  3285. mempool_free(pmb, phba->mbox_mem_pool);
  3286. }
  3287. return;
  3288. }
  3289. /*
  3290. * This routine handles processing a Fabric REG_LOGIN mailbox
  3291. * command upon completion. It is setup in the LPFC_MBOXQ
  3292. * as the completion routine when the command is
  3293. * handed off to the SLI layer.
  3294. */
  3295. void
  3296. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3297. {
  3298. struct lpfc_vport *vport = pmb->vport;
  3299. MAILBOX_t *mb = &pmb->u.mb;
  3300. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3301. struct lpfc_nodelist *ndlp;
  3302. struct Scsi_Host *shost;
  3303. ndlp = (struct lpfc_nodelist *) pmb->context2;
  3304. pmb->context1 = NULL;
  3305. pmb->context2 = NULL;
  3306. if (mb->mbxStatus) {
  3307. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3308. "0258 Register Fabric login error: 0x%x\n",
  3309. mb->mbxStatus);
  3310. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3311. kfree(mp);
  3312. mempool_free(pmb, phba->mbox_mem_pool);
  3313. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  3314. /* FLOGI failed, use loop map to make discovery list */
  3315. lpfc_disc_list_loopmap(vport);
  3316. /* Start discovery */
  3317. lpfc_disc_start(vport);
  3318. /* Decrement the reference count to ndlp after the
  3319. * reference to the ndlp are done.
  3320. */
  3321. lpfc_nlp_put(ndlp);
  3322. return;
  3323. }
  3324. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3325. /* Decrement the reference count to ndlp after the reference
  3326. * to the ndlp are done.
  3327. */
  3328. lpfc_nlp_put(ndlp);
  3329. return;
  3330. }
  3331. if (phba->sli_rev < LPFC_SLI_REV4)
  3332. ndlp->nlp_rpi = mb->un.varWords[0];
  3333. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  3334. ndlp->nlp_type |= NLP_FABRIC;
  3335. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3336. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  3337. /* when physical port receive logo donot start
  3338. * vport discovery */
  3339. if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
  3340. lpfc_start_fdiscs(phba);
  3341. else {
  3342. shost = lpfc_shost_from_vport(vport);
  3343. spin_lock_irq(shost->host_lock);
  3344. vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
  3345. spin_unlock_irq(shost->host_lock);
  3346. }
  3347. lpfc_do_scr_ns_plogi(phba, vport);
  3348. }
  3349. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3350. kfree(mp);
  3351. mempool_free(pmb, phba->mbox_mem_pool);
  3352. /* Drop the reference count from the mbox at the end after
  3353. * all the current reference to the ndlp have been done.
  3354. */
  3355. lpfc_nlp_put(ndlp);
  3356. return;
  3357. }
  3358. /*
  3359. * This routine handles processing a NameServer REG_LOGIN mailbox
  3360. * command upon completion. It is setup in the LPFC_MBOXQ
  3361. * as the completion routine when the command is
  3362. * handed off to the SLI layer.
  3363. */
  3364. void
  3365. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3366. {
  3367. MAILBOX_t *mb = &pmb->u.mb;
  3368. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3369. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3370. struct lpfc_vport *vport = pmb->vport;
  3371. pmb->context1 = NULL;
  3372. pmb->context2 = NULL;
  3373. if (mb->mbxStatus) {
  3374. out:
  3375. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3376. "0260 Register NameServer error: 0x%x\n",
  3377. mb->mbxStatus);
  3378. /* decrement the node reference count held for this
  3379. * callback function.
  3380. */
  3381. lpfc_nlp_put(ndlp);
  3382. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3383. kfree(mp);
  3384. mempool_free(pmb, phba->mbox_mem_pool);
  3385. /* If no other thread is using the ndlp, free it */
  3386. lpfc_nlp_not_used(ndlp);
  3387. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  3388. /*
  3389. * RegLogin failed, use loop map to make discovery
  3390. * list
  3391. */
  3392. lpfc_disc_list_loopmap(vport);
  3393. /* Start discovery */
  3394. lpfc_disc_start(vport);
  3395. return;
  3396. }
  3397. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3398. return;
  3399. }
  3400. if (phba->sli_rev < LPFC_SLI_REV4)
  3401. ndlp->nlp_rpi = mb->un.varWords[0];
  3402. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  3403. ndlp->nlp_type |= NLP_FABRIC;
  3404. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3405. if (vport->port_state < LPFC_VPORT_READY) {
  3406. /* Link up discovery requires Fabric registration. */
  3407. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  3408. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  3409. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  3410. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  3411. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  3412. /* Issue SCR just before NameServer GID_FT Query */
  3413. lpfc_issue_els_scr(vport, SCR_DID, 0);
  3414. }
  3415. vport->fc_ns_retry = 0;
  3416. /* Good status, issue CT Request to NameServer */
  3417. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  3418. /* Cannot issue NameServer Query, so finish up discovery */
  3419. goto out;
  3420. }
  3421. /* decrement the node reference count held for this
  3422. * callback function.
  3423. */
  3424. lpfc_nlp_put(ndlp);
  3425. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3426. kfree(mp);
  3427. mempool_free(pmb, phba->mbox_mem_pool);
  3428. return;
  3429. }
  3430. static void
  3431. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3432. {
  3433. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3434. struct fc_rport *rport;
  3435. struct lpfc_rport_data *rdata;
  3436. struct fc_rport_identifiers rport_ids;
  3437. struct lpfc_hba *phba = vport->phba;
  3438. /* Remote port has reappeared. Re-register w/ FC transport */
  3439. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  3440. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  3441. rport_ids.port_id = ndlp->nlp_DID;
  3442. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  3443. /*
  3444. * We leave our node pointer in rport->dd_data when we unregister a
  3445. * FCP target port. But fc_remote_port_add zeros the space to which
  3446. * rport->dd_data points. So, if we're reusing a previously
  3447. * registered port, drop the reference that we took the last time we
  3448. * registered the port.
  3449. */
  3450. if (ndlp->rport && ndlp->rport->dd_data &&
  3451. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
  3452. lpfc_nlp_put(ndlp);
  3453. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  3454. "rport add: did:x%x flg:x%x type x%x",
  3455. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3456. /* Don't add the remote port if unloading. */
  3457. if (vport->load_flag & FC_UNLOADING)
  3458. return;
  3459. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  3460. if (!rport || !get_device(&rport->dev)) {
  3461. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  3462. "Warning: fc_remote_port_add failed\n");
  3463. return;
  3464. }
  3465. /* initialize static port data */
  3466. rport->maxframe_size = ndlp->nlp_maxframe;
  3467. rport->supported_classes = ndlp->nlp_class_sup;
  3468. rdata = rport->dd_data;
  3469. rdata->pnode = lpfc_nlp_get(ndlp);
  3470. if (ndlp->nlp_type & NLP_FCP_TARGET)
  3471. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  3472. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  3473. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  3474. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  3475. fc_remote_port_rolechg(rport, rport_ids.roles);
  3476. if ((rport->scsi_target_id != -1) &&
  3477. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  3478. ndlp->nlp_sid = rport->scsi_target_id;
  3479. }
  3480. return;
  3481. }
  3482. static void
  3483. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  3484. {
  3485. struct fc_rport *rport = ndlp->rport;
  3486. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  3487. "rport delete: did:x%x flg:x%x type x%x",
  3488. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3489. fc_remote_port_delete(rport);
  3490. return;
  3491. }
  3492. static void
  3493. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  3494. {
  3495. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3496. spin_lock_irq(shost->host_lock);
  3497. switch (state) {
  3498. case NLP_STE_UNUSED_NODE:
  3499. vport->fc_unused_cnt += count;
  3500. break;
  3501. case NLP_STE_PLOGI_ISSUE:
  3502. vport->fc_plogi_cnt += count;
  3503. break;
  3504. case NLP_STE_ADISC_ISSUE:
  3505. vport->fc_adisc_cnt += count;
  3506. break;
  3507. case NLP_STE_REG_LOGIN_ISSUE:
  3508. vport->fc_reglogin_cnt += count;
  3509. break;
  3510. case NLP_STE_PRLI_ISSUE:
  3511. vport->fc_prli_cnt += count;
  3512. break;
  3513. case NLP_STE_UNMAPPED_NODE:
  3514. vport->fc_unmap_cnt += count;
  3515. break;
  3516. case NLP_STE_MAPPED_NODE:
  3517. vport->fc_map_cnt += count;
  3518. break;
  3519. case NLP_STE_NPR_NODE:
  3520. vport->fc_npr_cnt += count;
  3521. break;
  3522. }
  3523. spin_unlock_irq(shost->host_lock);
  3524. }
  3525. static void
  3526. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3527. int old_state, int new_state)
  3528. {
  3529. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3530. if (new_state == NLP_STE_UNMAPPED_NODE) {
  3531. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  3532. ndlp->nlp_type |= NLP_FC_NODE;
  3533. }
  3534. if (new_state == NLP_STE_MAPPED_NODE)
  3535. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  3536. if (new_state == NLP_STE_NPR_NODE)
  3537. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  3538. /* Transport interface */
  3539. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  3540. old_state == NLP_STE_UNMAPPED_NODE)) {
  3541. vport->phba->nport_event_cnt++;
  3542. lpfc_unregister_remote_port(ndlp);
  3543. }
  3544. if (new_state == NLP_STE_MAPPED_NODE ||
  3545. new_state == NLP_STE_UNMAPPED_NODE) {
  3546. vport->phba->nport_event_cnt++;
  3547. /*
  3548. * Tell the fc transport about the port, if we haven't
  3549. * already. If we have, and it's a scsi entity, be
  3550. * sure to unblock any attached scsi devices
  3551. */
  3552. lpfc_register_remote_port(vport, ndlp);
  3553. }
  3554. if ((new_state == NLP_STE_MAPPED_NODE) &&
  3555. (vport->stat_data_enabled)) {
  3556. /*
  3557. * A new target is discovered, if there is no buffer for
  3558. * statistical data collection allocate buffer.
  3559. */
  3560. ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
  3561. sizeof(struct lpfc_scsicmd_bkt),
  3562. GFP_KERNEL);
  3563. if (!ndlp->lat_data)
  3564. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  3565. "0286 lpfc_nlp_state_cleanup failed to "
  3566. "allocate statistical data buffer DID "
  3567. "0x%x\n", ndlp->nlp_DID);
  3568. }
  3569. /*
  3570. * if we added to Mapped list, but the remote port
  3571. * registration failed or assigned a target id outside
  3572. * our presentable range - move the node to the
  3573. * Unmapped List
  3574. */
  3575. if (new_state == NLP_STE_MAPPED_NODE &&
  3576. (!ndlp->rport ||
  3577. ndlp->rport->scsi_target_id == -1 ||
  3578. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  3579. spin_lock_irq(shost->host_lock);
  3580. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  3581. spin_unlock_irq(shost->host_lock);
  3582. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3583. }
  3584. }
  3585. static char *
  3586. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  3587. {
  3588. static char *states[] = {
  3589. [NLP_STE_UNUSED_NODE] = "UNUSED",
  3590. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  3591. [NLP_STE_ADISC_ISSUE] = "ADISC",
  3592. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  3593. [NLP_STE_PRLI_ISSUE] = "PRLI",
  3594. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  3595. [NLP_STE_MAPPED_NODE] = "MAPPED",
  3596. [NLP_STE_NPR_NODE] = "NPR",
  3597. };
  3598. if (state < NLP_STE_MAX_STATE && states[state])
  3599. strlcpy(buffer, states[state], size);
  3600. else
  3601. snprintf(buffer, size, "unknown (%d)", state);
  3602. return buffer;
  3603. }
  3604. void
  3605. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3606. int state)
  3607. {
  3608. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3609. int old_state = ndlp->nlp_state;
  3610. char name1[16], name2[16];
  3611. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3612. "0904 NPort state transition x%06x, %s -> %s\n",
  3613. ndlp->nlp_DID,
  3614. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  3615. lpfc_nlp_state_name(name2, sizeof(name2), state));
  3616. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3617. "node statechg did:x%x old:%d ste:%d",
  3618. ndlp->nlp_DID, old_state, state);
  3619. if (old_state == NLP_STE_NPR_NODE &&
  3620. state != NLP_STE_NPR_NODE)
  3621. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3622. if (old_state == NLP_STE_UNMAPPED_NODE) {
  3623. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  3624. ndlp->nlp_type &= ~NLP_FC_NODE;
  3625. }
  3626. if (list_empty(&ndlp->nlp_listp)) {
  3627. spin_lock_irq(shost->host_lock);
  3628. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  3629. spin_unlock_irq(shost->host_lock);
  3630. } else if (old_state)
  3631. lpfc_nlp_counters(vport, old_state, -1);
  3632. ndlp->nlp_state = state;
  3633. lpfc_nlp_counters(vport, state, 1);
  3634. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  3635. }
  3636. void
  3637. lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3638. {
  3639. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3640. if (list_empty(&ndlp->nlp_listp)) {
  3641. spin_lock_irq(shost->host_lock);
  3642. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  3643. spin_unlock_irq(shost->host_lock);
  3644. }
  3645. }
  3646. void
  3647. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3648. {
  3649. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3650. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3651. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  3652. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  3653. spin_lock_irq(shost->host_lock);
  3654. list_del_init(&ndlp->nlp_listp);
  3655. spin_unlock_irq(shost->host_lock);
  3656. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  3657. NLP_STE_UNUSED_NODE);
  3658. }
  3659. static void
  3660. lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3661. {
  3662. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3663. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  3664. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  3665. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  3666. NLP_STE_UNUSED_NODE);
  3667. }
  3668. /**
  3669. * lpfc_initialize_node - Initialize all fields of node object
  3670. * @vport: Pointer to Virtual Port object.
  3671. * @ndlp: Pointer to FC node object.
  3672. * @did: FC_ID of the node.
  3673. *
  3674. * This function is always called when node object need to be initialized.
  3675. * It initializes all the fields of the node object. Although the reference
  3676. * to phba from @ndlp can be obtained indirectly through it's reference to
  3677. * @vport, a direct reference to phba is taken here by @ndlp. This is due
  3678. * to the life-span of the @ndlp might go beyond the existence of @vport as
  3679. * the final release of ndlp is determined by its reference count. And, the
  3680. * operation on @ndlp needs the reference to phba.
  3681. **/
  3682. static inline void
  3683. lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3684. uint32_t did)
  3685. {
  3686. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  3687. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  3688. init_timer(&ndlp->nlp_delayfunc);
  3689. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  3690. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  3691. ndlp->nlp_DID = did;
  3692. ndlp->vport = vport;
  3693. ndlp->phba = vport->phba;
  3694. ndlp->nlp_sid = NLP_NO_SID;
  3695. kref_init(&ndlp->kref);
  3696. NLP_INT_NODE_ACT(ndlp);
  3697. atomic_set(&ndlp->cmd_pending, 0);
  3698. ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
  3699. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  3700. ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
  3701. }
  3702. struct lpfc_nodelist *
  3703. lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3704. int state)
  3705. {
  3706. struct lpfc_hba *phba = vport->phba;
  3707. uint32_t did;
  3708. unsigned long flags;
  3709. if (!ndlp)
  3710. return NULL;
  3711. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3712. /* The ndlp should not be in memory free mode */
  3713. if (NLP_CHK_FREE_REQ(ndlp)) {
  3714. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3715. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  3716. "0277 lpfc_enable_node: ndlp:x%p "
  3717. "usgmap:x%x refcnt:%d\n",
  3718. (void *)ndlp, ndlp->nlp_usg_map,
  3719. atomic_read(&ndlp->kref.refcount));
  3720. return NULL;
  3721. }
  3722. /* The ndlp should not already be in active mode */
  3723. if (NLP_CHK_NODE_ACT(ndlp)) {
  3724. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3725. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  3726. "0278 lpfc_enable_node: ndlp:x%p "
  3727. "usgmap:x%x refcnt:%d\n",
  3728. (void *)ndlp, ndlp->nlp_usg_map,
  3729. atomic_read(&ndlp->kref.refcount));
  3730. return NULL;
  3731. }
  3732. /* Keep the original DID */
  3733. did = ndlp->nlp_DID;
  3734. /* re-initialize ndlp except of ndlp linked list pointer */
  3735. memset((((char *)ndlp) + sizeof (struct list_head)), 0,
  3736. sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
  3737. lpfc_initialize_node(vport, ndlp, did);
  3738. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3739. if (state != NLP_STE_UNUSED_NODE)
  3740. lpfc_nlp_set_state(vport, ndlp, state);
  3741. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3742. "node enable: did:x%x",
  3743. ndlp->nlp_DID, 0, 0);
  3744. return ndlp;
  3745. }
  3746. void
  3747. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3748. {
  3749. /*
  3750. * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
  3751. * be used if we wish to issue the "last" lpfc_nlp_put() to remove
  3752. * the ndlp from the vport. The ndlp marked as UNUSED on the list
  3753. * until ALL other outstanding threads have completed. We check
  3754. * that the ndlp not already in the UNUSED state before we proceed.
  3755. */
  3756. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  3757. return;
  3758. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  3759. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  3760. lpfc_cleanup_vports_rrqs(vport, ndlp);
  3761. lpfc_nlp_put(ndlp);
  3762. return;
  3763. }
  3764. /*
  3765. * Start / ReStart rescue timer for Discovery / RSCN handling
  3766. */
  3767. void
  3768. lpfc_set_disctmo(struct lpfc_vport *vport)
  3769. {
  3770. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3771. struct lpfc_hba *phba = vport->phba;
  3772. uint32_t tmo;
  3773. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  3774. /* For FAN, timeout should be greater than edtov */
  3775. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  3776. } else {
  3777. /* Normal discovery timeout should be > than ELS/CT timeout
  3778. * FC spec states we need 3 * ratov for CT requests
  3779. */
  3780. tmo = ((phba->fc_ratov * 3) + 3);
  3781. }
  3782. if (!timer_pending(&vport->fc_disctmo)) {
  3783. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3784. "set disc timer: tmo:x%x state:x%x flg:x%x",
  3785. tmo, vport->port_state, vport->fc_flag);
  3786. }
  3787. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  3788. spin_lock_irq(shost->host_lock);
  3789. vport->fc_flag |= FC_DISC_TMO;
  3790. spin_unlock_irq(shost->host_lock);
  3791. /* Start Discovery Timer state <hba_state> */
  3792. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3793. "0247 Start Discovery Timer state x%x "
  3794. "Data: x%x x%lx x%x x%x\n",
  3795. vport->port_state, tmo,
  3796. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  3797. vport->fc_adisc_cnt);
  3798. return;
  3799. }
  3800. /*
  3801. * Cancel rescue timer for Discovery / RSCN handling
  3802. */
  3803. int
  3804. lpfc_can_disctmo(struct lpfc_vport *vport)
  3805. {
  3806. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3807. unsigned long iflags;
  3808. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3809. "can disc timer: state:x%x rtry:x%x flg:x%x",
  3810. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  3811. /* Turn off discovery timer if its running */
  3812. if (vport->fc_flag & FC_DISC_TMO) {
  3813. spin_lock_irqsave(shost->host_lock, iflags);
  3814. vport->fc_flag &= ~FC_DISC_TMO;
  3815. spin_unlock_irqrestore(shost->host_lock, iflags);
  3816. del_timer_sync(&vport->fc_disctmo);
  3817. spin_lock_irqsave(&vport->work_port_lock, iflags);
  3818. vport->work_port_events &= ~WORKER_DISC_TMO;
  3819. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  3820. }
  3821. /* Cancel Discovery Timer state <hba_state> */
  3822. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3823. "0248 Cancel Discovery Timer state x%x "
  3824. "Data: x%x x%x x%x\n",
  3825. vport->port_state, vport->fc_flag,
  3826. vport->fc_plogi_cnt, vport->fc_adisc_cnt);
  3827. return 0;
  3828. }
  3829. /*
  3830. * Check specified ring for outstanding IOCB on the SLI queue
  3831. * Return true if iocb matches the specified nport
  3832. */
  3833. int
  3834. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  3835. struct lpfc_sli_ring *pring,
  3836. struct lpfc_iocbq *iocb,
  3837. struct lpfc_nodelist *ndlp)
  3838. {
  3839. struct lpfc_sli *psli = &phba->sli;
  3840. IOCB_t *icmd = &iocb->iocb;
  3841. struct lpfc_vport *vport = ndlp->vport;
  3842. if (iocb->vport != vport)
  3843. return 0;
  3844. if (pring->ringno == LPFC_ELS_RING) {
  3845. switch (icmd->ulpCommand) {
  3846. case CMD_GEN_REQUEST64_CR:
  3847. if (iocb->context_un.ndlp == ndlp)
  3848. return 1;
  3849. case CMD_ELS_REQUEST64_CR:
  3850. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  3851. return 1;
  3852. case CMD_XMIT_ELS_RSP64_CX:
  3853. if (iocb->context1 == (uint8_t *) ndlp)
  3854. return 1;
  3855. }
  3856. } else if (pring->ringno == psli->extra_ring) {
  3857. } else if (pring->ringno == psli->fcp_ring) {
  3858. /* Skip match check if waiting to relogin to FCP target */
  3859. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  3860. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  3861. return 0;
  3862. }
  3863. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  3864. return 1;
  3865. }
  3866. } else if (pring->ringno == psli->next_ring) {
  3867. }
  3868. return 0;
  3869. }
  3870. /*
  3871. * Free resources / clean up outstanding I/Os
  3872. * associated with nlp_rpi in the LPFC_NODELIST entry.
  3873. */
  3874. static int
  3875. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  3876. {
  3877. LIST_HEAD(completions);
  3878. struct lpfc_sli *psli;
  3879. struct lpfc_sli_ring *pring;
  3880. struct lpfc_iocbq *iocb, *next_iocb;
  3881. uint32_t i;
  3882. lpfc_fabric_abort_nport(ndlp);
  3883. /*
  3884. * Everything that matches on txcmplq will be returned
  3885. * by firmware with a no rpi error.
  3886. */
  3887. psli = &phba->sli;
  3888. if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
  3889. /* Now process each ring */
  3890. for (i = 0; i < psli->num_rings; i++) {
  3891. pring = &psli->ring[i];
  3892. spin_lock_irq(&phba->hbalock);
  3893. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  3894. list) {
  3895. /*
  3896. * Check to see if iocb matches the nport we are
  3897. * looking for
  3898. */
  3899. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  3900. ndlp))) {
  3901. /* It matches, so deque and call compl
  3902. with an error */
  3903. list_move_tail(&iocb->list,
  3904. &completions);
  3905. pring->txq_cnt--;
  3906. }
  3907. }
  3908. spin_unlock_irq(&phba->hbalock);
  3909. }
  3910. }
  3911. /* Cancel all the IOCBs from the completions list */
  3912. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3913. IOERR_SLI_ABORTED);
  3914. return 0;
  3915. }
  3916. /*
  3917. * Free rpi associated with LPFC_NODELIST entry.
  3918. * This routine is called from lpfc_freenode(), when we are removing
  3919. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  3920. * LOGO that completes successfully, and we are waiting to PLOGI back
  3921. * to the remote NPort. In addition, it is called after we receive
  3922. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  3923. * we are waiting to PLOGI back to the remote NPort.
  3924. */
  3925. int
  3926. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3927. {
  3928. struct lpfc_hba *phba = vport->phba;
  3929. LPFC_MBOXQ_t *mbox;
  3930. int rc;
  3931. uint16_t rpi;
  3932. if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
  3933. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3934. if (mbox) {
  3935. /* SLI4 ports require the physical rpi value. */
  3936. rpi = ndlp->nlp_rpi;
  3937. if (phba->sli_rev == LPFC_SLI_REV4)
  3938. rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  3939. lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
  3940. mbox->vport = vport;
  3941. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3942. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3943. if (rc == MBX_NOT_FINISHED)
  3944. mempool_free(mbox, phba->mbox_mem_pool);
  3945. }
  3946. lpfc_no_rpi(phba, ndlp);
  3947. if (phba->sli_rev != LPFC_SLI_REV4)
  3948. ndlp->nlp_rpi = 0;
  3949. ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
  3950. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  3951. return 1;
  3952. }
  3953. return 0;
  3954. }
  3955. /**
  3956. * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
  3957. * @phba: pointer to lpfc hba data structure.
  3958. *
  3959. * This routine is invoked to unregister all the currently registered RPIs
  3960. * to the HBA.
  3961. **/
  3962. void
  3963. lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
  3964. {
  3965. struct lpfc_vport **vports;
  3966. struct lpfc_nodelist *ndlp;
  3967. struct Scsi_Host *shost;
  3968. int i;
  3969. vports = lpfc_create_vport_work_array(phba);
  3970. if (!vports) {
  3971. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  3972. "2884 Vport array allocation failed \n");
  3973. return;
  3974. }
  3975. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3976. shost = lpfc_shost_from_vport(vports[i]);
  3977. spin_lock_irq(shost->host_lock);
  3978. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  3979. if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
  3980. /* The mempool_alloc might sleep */
  3981. spin_unlock_irq(shost->host_lock);
  3982. lpfc_unreg_rpi(vports[i], ndlp);
  3983. spin_lock_irq(shost->host_lock);
  3984. }
  3985. }
  3986. spin_unlock_irq(shost->host_lock);
  3987. }
  3988. lpfc_destroy_vport_work_array(phba, vports);
  3989. }
  3990. void
  3991. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  3992. {
  3993. struct lpfc_hba *phba = vport->phba;
  3994. LPFC_MBOXQ_t *mbox;
  3995. int rc;
  3996. if (phba->sli_rev == LPFC_SLI_REV4) {
  3997. lpfc_sli4_unreg_all_rpis(vport);
  3998. return;
  3999. }
  4000. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4001. if (mbox) {
  4002. lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
  4003. mbox);
  4004. mbox->vport = vport;
  4005. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4006. mbox->context1 = NULL;
  4007. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  4008. if (rc != MBX_TIMEOUT)
  4009. mempool_free(mbox, phba->mbox_mem_pool);
  4010. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  4011. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  4012. "1836 Could not issue "
  4013. "unreg_login(all_rpis) status %d\n", rc);
  4014. }
  4015. }
  4016. void
  4017. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  4018. {
  4019. struct lpfc_hba *phba = vport->phba;
  4020. LPFC_MBOXQ_t *mbox;
  4021. int rc;
  4022. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4023. if (mbox) {
  4024. lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
  4025. mbox);
  4026. mbox->vport = vport;
  4027. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4028. mbox->context1 = NULL;
  4029. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  4030. if (rc != MBX_TIMEOUT)
  4031. mempool_free(mbox, phba->mbox_mem_pool);
  4032. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  4033. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  4034. "1815 Could not issue "
  4035. "unreg_did (default rpis) status %d\n",
  4036. rc);
  4037. }
  4038. }
  4039. /*
  4040. * Free resources associated with LPFC_NODELIST entry
  4041. * so it can be freed.
  4042. */
  4043. static int
  4044. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  4045. {
  4046. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4047. struct lpfc_hba *phba = vport->phba;
  4048. LPFC_MBOXQ_t *mb, *nextmb;
  4049. struct lpfc_dmabuf *mp;
  4050. /* Cleanup node for NPort <nlp_DID> */
  4051. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  4052. "0900 Cleanup node for NPort x%x "
  4053. "Data: x%x x%x x%x\n",
  4054. ndlp->nlp_DID, ndlp->nlp_flag,
  4055. ndlp->nlp_state, ndlp->nlp_rpi);
  4056. if (NLP_CHK_FREE_REQ(ndlp)) {
  4057. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  4058. "0280 lpfc_cleanup_node: ndlp:x%p "
  4059. "usgmap:x%x refcnt:%d\n",
  4060. (void *)ndlp, ndlp->nlp_usg_map,
  4061. atomic_read(&ndlp->kref.refcount));
  4062. lpfc_dequeue_node(vport, ndlp);
  4063. } else {
  4064. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  4065. "0281 lpfc_cleanup_node: ndlp:x%p "
  4066. "usgmap:x%x refcnt:%d\n",
  4067. (void *)ndlp, ndlp->nlp_usg_map,
  4068. atomic_read(&ndlp->kref.refcount));
  4069. lpfc_disable_node(vport, ndlp);
  4070. }
  4071. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  4072. if ((mb = phba->sli.mbox_active)) {
  4073. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  4074. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  4075. mb->context2 = NULL;
  4076. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4077. }
  4078. }
  4079. spin_lock_irq(&phba->hbalock);
  4080. /* Cleanup REG_LOGIN completions which are not yet processed */
  4081. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  4082. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
  4083. (ndlp != (struct lpfc_nodelist *) mb->context2))
  4084. continue;
  4085. mb->context2 = NULL;
  4086. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4087. }
  4088. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  4089. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  4090. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  4091. mp = (struct lpfc_dmabuf *) (mb->context1);
  4092. if (mp) {
  4093. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4094. kfree(mp);
  4095. }
  4096. list_del(&mb->list);
  4097. mempool_free(mb, phba->mbox_mem_pool);
  4098. /* We shall not invoke the lpfc_nlp_put to decrement
  4099. * the ndlp reference count as we are in the process
  4100. * of lpfc_nlp_release.
  4101. */
  4102. }
  4103. }
  4104. spin_unlock_irq(&phba->hbalock);
  4105. lpfc_els_abort(phba, ndlp);
  4106. spin_lock_irq(shost->host_lock);
  4107. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  4108. spin_unlock_irq(shost->host_lock);
  4109. ndlp->nlp_last_elscmd = 0;
  4110. del_timer_sync(&ndlp->nlp_delayfunc);
  4111. list_del_init(&ndlp->els_retry_evt.evt_listp);
  4112. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  4113. lpfc_cleanup_vports_rrqs(vport, ndlp);
  4114. lpfc_unreg_rpi(vport, ndlp);
  4115. return 0;
  4116. }
  4117. /*
  4118. * Check to see if we can free the nlp back to the freelist.
  4119. * If we are in the middle of using the nlp in the discovery state
  4120. * machine, defer the free till we reach the end of the state machine.
  4121. */
  4122. static void
  4123. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  4124. {
  4125. struct lpfc_hba *phba = vport->phba;
  4126. struct lpfc_rport_data *rdata;
  4127. LPFC_MBOXQ_t *mbox;
  4128. int rc;
  4129. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  4130. if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
  4131. !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
  4132. !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
  4133. /* For this case we need to cleanup the default rpi
  4134. * allocated by the firmware.
  4135. */
  4136. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
  4137. != NULL) {
  4138. rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
  4139. (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
  4140. if (rc) {
  4141. mempool_free(mbox, phba->mbox_mem_pool);
  4142. }
  4143. else {
  4144. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  4145. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  4146. mbox->vport = vport;
  4147. mbox->context2 = NULL;
  4148. rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4149. if (rc == MBX_NOT_FINISHED) {
  4150. mempool_free(mbox, phba->mbox_mem_pool);
  4151. }
  4152. }
  4153. }
  4154. }
  4155. lpfc_cleanup_node(vport, ndlp);
  4156. /*
  4157. * We can get here with a non-NULL ndlp->rport because when we
  4158. * unregister a rport we don't break the rport/node linkage. So if we
  4159. * do, make sure we don't leaving any dangling pointers behind.
  4160. */
  4161. if (ndlp->rport) {
  4162. rdata = ndlp->rport->dd_data;
  4163. rdata->pnode = NULL;
  4164. ndlp->rport = NULL;
  4165. }
  4166. }
  4167. static int
  4168. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  4169. uint32_t did)
  4170. {
  4171. D_ID mydid, ndlpdid, matchdid;
  4172. if (did == Bcast_DID)
  4173. return 0;
  4174. /* First check for Direct match */
  4175. if (ndlp->nlp_DID == did)
  4176. return 1;
  4177. /* Next check for area/domain identically equals 0 match */
  4178. mydid.un.word = vport->fc_myDID;
  4179. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  4180. return 0;
  4181. }
  4182. matchdid.un.word = did;
  4183. ndlpdid.un.word = ndlp->nlp_DID;
  4184. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  4185. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  4186. (mydid.un.b.area == matchdid.un.b.area)) {
  4187. if ((ndlpdid.un.b.domain == 0) &&
  4188. (ndlpdid.un.b.area == 0)) {
  4189. if (ndlpdid.un.b.id)
  4190. return 1;
  4191. }
  4192. return 0;
  4193. }
  4194. matchdid.un.word = ndlp->nlp_DID;
  4195. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  4196. (mydid.un.b.area == ndlpdid.un.b.area)) {
  4197. if ((matchdid.un.b.domain == 0) &&
  4198. (matchdid.un.b.area == 0)) {
  4199. if (matchdid.un.b.id)
  4200. return 1;
  4201. }
  4202. }
  4203. }
  4204. return 0;
  4205. }
  4206. /* Search for a nodelist entry */
  4207. static struct lpfc_nodelist *
  4208. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  4209. {
  4210. struct lpfc_nodelist *ndlp;
  4211. uint32_t data1;
  4212. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4213. if (lpfc_matchdid(vport, ndlp, did)) {
  4214. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  4215. ((uint32_t) ndlp->nlp_xri << 16) |
  4216. ((uint32_t) ndlp->nlp_type << 8) |
  4217. ((uint32_t) ndlp->nlp_rpi & 0xff));
  4218. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  4219. "0929 FIND node DID "
  4220. "Data: x%p x%x x%x x%x\n",
  4221. ndlp, ndlp->nlp_DID,
  4222. ndlp->nlp_flag, data1);
  4223. return ndlp;
  4224. }
  4225. }
  4226. /* FIND node did <did> NOT FOUND */
  4227. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  4228. "0932 FIND node did x%x NOT FOUND.\n", did);
  4229. return NULL;
  4230. }
  4231. struct lpfc_nodelist *
  4232. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  4233. {
  4234. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4235. struct lpfc_nodelist *ndlp;
  4236. unsigned long iflags;
  4237. spin_lock_irqsave(shost->host_lock, iflags);
  4238. ndlp = __lpfc_findnode_did(vport, did);
  4239. spin_unlock_irqrestore(shost->host_lock, iflags);
  4240. return ndlp;
  4241. }
  4242. struct lpfc_nodelist *
  4243. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  4244. {
  4245. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4246. struct lpfc_nodelist *ndlp;
  4247. ndlp = lpfc_findnode_did(vport, did);
  4248. if (!ndlp) {
  4249. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  4250. lpfc_rscn_payload_check(vport, did) == 0)
  4251. return NULL;
  4252. ndlp = (struct lpfc_nodelist *)
  4253. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  4254. if (!ndlp)
  4255. return NULL;
  4256. lpfc_nlp_init(vport, ndlp, did);
  4257. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  4258. spin_lock_irq(shost->host_lock);
  4259. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  4260. spin_unlock_irq(shost->host_lock);
  4261. return ndlp;
  4262. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  4263. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  4264. if (!ndlp)
  4265. return NULL;
  4266. spin_lock_irq(shost->host_lock);
  4267. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  4268. spin_unlock_irq(shost->host_lock);
  4269. return ndlp;
  4270. }
  4271. if ((vport->fc_flag & FC_RSCN_MODE) &&
  4272. !(vport->fc_flag & FC_NDISC_ACTIVE)) {
  4273. if (lpfc_rscn_payload_check(vport, did)) {
  4274. /* If we've already received a PLOGI from this NPort
  4275. * we don't need to try to discover it again.
  4276. */
  4277. if (ndlp->nlp_flag & NLP_RCV_PLOGI)
  4278. return NULL;
  4279. /* Since this node is marked for discovery,
  4280. * delay timeout is not needed.
  4281. */
  4282. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  4283. spin_lock_irq(shost->host_lock);
  4284. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  4285. spin_unlock_irq(shost->host_lock);
  4286. } else
  4287. ndlp = NULL;
  4288. } else {
  4289. /* If we've already received a PLOGI from this NPort,
  4290. * or we are already in the process of discovery on it,
  4291. * we don't need to try to discover it again.
  4292. */
  4293. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  4294. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  4295. ndlp->nlp_flag & NLP_RCV_PLOGI)
  4296. return NULL;
  4297. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  4298. spin_lock_irq(shost->host_lock);
  4299. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  4300. spin_unlock_irq(shost->host_lock);
  4301. }
  4302. return ndlp;
  4303. }
  4304. /* Build a list of nodes to discover based on the loopmap */
  4305. void
  4306. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  4307. {
  4308. struct lpfc_hba *phba = vport->phba;
  4309. int j;
  4310. uint32_t alpa, index;
  4311. if (!lpfc_is_link_up(phba))
  4312. return;
  4313. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
  4314. return;
  4315. /* Check for loop map present or not */
  4316. if (phba->alpa_map[0]) {
  4317. for (j = 1; j <= phba->alpa_map[0]; j++) {
  4318. alpa = phba->alpa_map[j];
  4319. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  4320. continue;
  4321. lpfc_setup_disc_node(vport, alpa);
  4322. }
  4323. } else {
  4324. /* No alpamap, so try all alpa's */
  4325. for (j = 0; j < FC_MAXLOOP; j++) {
  4326. /* If cfg_scan_down is set, start from highest
  4327. * ALPA (0xef) to lowest (0x1).
  4328. */
  4329. if (vport->cfg_scan_down)
  4330. index = j;
  4331. else
  4332. index = FC_MAXLOOP - j - 1;
  4333. alpa = lpfcAlpaArray[index];
  4334. if ((vport->fc_myDID & 0xff) == alpa)
  4335. continue;
  4336. lpfc_setup_disc_node(vport, alpa);
  4337. }
  4338. }
  4339. return;
  4340. }
  4341. void
  4342. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  4343. {
  4344. LPFC_MBOXQ_t *mbox;
  4345. struct lpfc_sli *psli = &phba->sli;
  4346. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  4347. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  4348. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  4349. int rc;
  4350. /*
  4351. * if it's not a physical port or if we already send
  4352. * clear_la then don't send it.
  4353. */
  4354. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  4355. (vport->port_type != LPFC_PHYSICAL_PORT) ||
  4356. (phba->sli_rev == LPFC_SLI_REV4))
  4357. return;
  4358. /* Link up discovery */
  4359. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  4360. phba->link_state = LPFC_CLEAR_LA;
  4361. lpfc_clear_la(phba, mbox);
  4362. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  4363. mbox->vport = vport;
  4364. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4365. if (rc == MBX_NOT_FINISHED) {
  4366. mempool_free(mbox, phba->mbox_mem_pool);
  4367. lpfc_disc_flush_list(vport);
  4368. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  4369. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  4370. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  4371. phba->link_state = LPFC_HBA_ERROR;
  4372. }
  4373. }
  4374. }
  4375. /* Reg_vpi to tell firmware to resume normal operations */
  4376. void
  4377. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  4378. {
  4379. LPFC_MBOXQ_t *regvpimbox;
  4380. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4381. if (regvpimbox) {
  4382. lpfc_reg_vpi(vport, regvpimbox);
  4383. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  4384. regvpimbox->vport = vport;
  4385. if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
  4386. == MBX_NOT_FINISHED) {
  4387. mempool_free(regvpimbox, phba->mbox_mem_pool);
  4388. }
  4389. }
  4390. }
  4391. /* Start Link up / RSCN discovery on NPR nodes */
  4392. void
  4393. lpfc_disc_start(struct lpfc_vport *vport)
  4394. {
  4395. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4396. struct lpfc_hba *phba = vport->phba;
  4397. uint32_t num_sent;
  4398. uint32_t clear_la_pending;
  4399. int did_changed;
  4400. if (!lpfc_is_link_up(phba))
  4401. return;
  4402. if (phba->link_state == LPFC_CLEAR_LA)
  4403. clear_la_pending = 1;
  4404. else
  4405. clear_la_pending = 0;
  4406. if (vport->port_state < LPFC_VPORT_READY)
  4407. vport->port_state = LPFC_DISC_AUTH;
  4408. lpfc_set_disctmo(vport);
  4409. if (vport->fc_prevDID == vport->fc_myDID)
  4410. did_changed = 0;
  4411. else
  4412. did_changed = 1;
  4413. vport->fc_prevDID = vport->fc_myDID;
  4414. vport->num_disc_nodes = 0;
  4415. /* Start Discovery state <hba_state> */
  4416. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4417. "0202 Start Discovery hba state x%x "
  4418. "Data: x%x x%x x%x\n",
  4419. vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
  4420. vport->fc_adisc_cnt);
  4421. /* First do ADISCs - if any */
  4422. num_sent = lpfc_els_disc_adisc(vport);
  4423. if (num_sent)
  4424. return;
  4425. /* Register the VPI for SLI3, NON-NPIV only. */
  4426. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  4427. !(vport->fc_flag & FC_PT2PT) &&
  4428. !(vport->fc_flag & FC_RSCN_MODE) &&
  4429. (phba->sli_rev < LPFC_SLI_REV4)) {
  4430. lpfc_issue_reg_vpi(phba, vport);
  4431. return;
  4432. }
  4433. /*
  4434. * For SLI2, we need to set port_state to READY and continue
  4435. * discovery.
  4436. */
  4437. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  4438. /* If we get here, there is nothing to ADISC */
  4439. if (vport->port_type == LPFC_PHYSICAL_PORT)
  4440. lpfc_issue_clear_la(phba, vport);
  4441. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  4442. vport->num_disc_nodes = 0;
  4443. /* go thru NPR nodes and issue ELS PLOGIs */
  4444. if (vport->fc_npr_cnt)
  4445. lpfc_els_disc_plogi(vport);
  4446. if (!vport->num_disc_nodes) {
  4447. spin_lock_irq(shost->host_lock);
  4448. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  4449. spin_unlock_irq(shost->host_lock);
  4450. lpfc_can_disctmo(vport);
  4451. }
  4452. }
  4453. vport->port_state = LPFC_VPORT_READY;
  4454. } else {
  4455. /* Next do PLOGIs - if any */
  4456. num_sent = lpfc_els_disc_plogi(vport);
  4457. if (num_sent)
  4458. return;
  4459. if (vport->fc_flag & FC_RSCN_MODE) {
  4460. /* Check to see if more RSCNs came in while we
  4461. * were processing this one.
  4462. */
  4463. if ((vport->fc_rscn_id_cnt == 0) &&
  4464. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  4465. spin_lock_irq(shost->host_lock);
  4466. vport->fc_flag &= ~FC_RSCN_MODE;
  4467. spin_unlock_irq(shost->host_lock);
  4468. lpfc_can_disctmo(vport);
  4469. } else
  4470. lpfc_els_handle_rscn(vport);
  4471. }
  4472. }
  4473. return;
  4474. }
  4475. /*
  4476. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  4477. * ring the match the sppecified nodelist.
  4478. */
  4479. static void
  4480. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  4481. {
  4482. LIST_HEAD(completions);
  4483. struct lpfc_sli *psli;
  4484. IOCB_t *icmd;
  4485. struct lpfc_iocbq *iocb, *next_iocb;
  4486. struct lpfc_sli_ring *pring;
  4487. psli = &phba->sli;
  4488. pring = &psli->ring[LPFC_ELS_RING];
  4489. /* Error matching iocb on txq or txcmplq
  4490. * First check the txq.
  4491. */
  4492. spin_lock_irq(&phba->hbalock);
  4493. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  4494. if (iocb->context1 != ndlp) {
  4495. continue;
  4496. }
  4497. icmd = &iocb->iocb;
  4498. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  4499. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  4500. list_move_tail(&iocb->list, &completions);
  4501. pring->txq_cnt--;
  4502. }
  4503. }
  4504. /* Next check the txcmplq */
  4505. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  4506. if (iocb->context1 != ndlp) {
  4507. continue;
  4508. }
  4509. icmd = &iocb->iocb;
  4510. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  4511. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  4512. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  4513. }
  4514. }
  4515. spin_unlock_irq(&phba->hbalock);
  4516. /* Cancel all the IOCBs from the completions list */
  4517. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  4518. IOERR_SLI_ABORTED);
  4519. }
  4520. static void
  4521. lpfc_disc_flush_list(struct lpfc_vport *vport)
  4522. {
  4523. struct lpfc_nodelist *ndlp, *next_ndlp;
  4524. struct lpfc_hba *phba = vport->phba;
  4525. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  4526. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  4527. nlp_listp) {
  4528. if (!NLP_CHK_NODE_ACT(ndlp))
  4529. continue;
  4530. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  4531. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  4532. lpfc_free_tx(phba, ndlp);
  4533. }
  4534. }
  4535. }
  4536. }
  4537. void
  4538. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  4539. {
  4540. lpfc_els_flush_rscn(vport);
  4541. lpfc_els_flush_cmd(vport);
  4542. lpfc_disc_flush_list(vport);
  4543. }
  4544. /*****************************************************************************/
  4545. /*
  4546. * NAME: lpfc_disc_timeout
  4547. *
  4548. * FUNCTION: Fibre Channel driver discovery timeout routine.
  4549. *
  4550. * EXECUTION ENVIRONMENT: interrupt only
  4551. *
  4552. * CALLED FROM:
  4553. * Timer function
  4554. *
  4555. * RETURNS:
  4556. * none
  4557. */
  4558. /*****************************************************************************/
  4559. void
  4560. lpfc_disc_timeout(unsigned long ptr)
  4561. {
  4562. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  4563. struct lpfc_hba *phba = vport->phba;
  4564. uint32_t tmo_posted;
  4565. unsigned long flags = 0;
  4566. if (unlikely(!phba))
  4567. return;
  4568. spin_lock_irqsave(&vport->work_port_lock, flags);
  4569. tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
  4570. if (!tmo_posted)
  4571. vport->work_port_events |= WORKER_DISC_TMO;
  4572. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  4573. if (!tmo_posted)
  4574. lpfc_worker_wake_up(phba);
  4575. return;
  4576. }
  4577. static void
  4578. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  4579. {
  4580. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4581. struct lpfc_hba *phba = vport->phba;
  4582. struct lpfc_sli *psli = &phba->sli;
  4583. struct lpfc_nodelist *ndlp, *next_ndlp;
  4584. LPFC_MBOXQ_t *initlinkmbox;
  4585. int rc, clrlaerr = 0;
  4586. if (!(vport->fc_flag & FC_DISC_TMO))
  4587. return;
  4588. spin_lock_irq(shost->host_lock);
  4589. vport->fc_flag &= ~FC_DISC_TMO;
  4590. spin_unlock_irq(shost->host_lock);
  4591. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4592. "disc timeout: state:x%x rtry:x%x flg:x%x",
  4593. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  4594. switch (vport->port_state) {
  4595. case LPFC_LOCAL_CFG_LINK:
  4596. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  4597. * FAN
  4598. */
  4599. /* FAN timeout */
  4600. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  4601. "0221 FAN timeout\n");
  4602. /* Start discovery by sending FLOGI, clean up old rpis */
  4603. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  4604. nlp_listp) {
  4605. if (!NLP_CHK_NODE_ACT(ndlp))
  4606. continue;
  4607. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  4608. continue;
  4609. if (ndlp->nlp_type & NLP_FABRIC) {
  4610. /* Clean up the ndlp on Fabric connections */
  4611. lpfc_drop_node(vport, ndlp);
  4612. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  4613. /* Fail outstanding IO now since device
  4614. * is marked for PLOGI.
  4615. */
  4616. lpfc_unreg_rpi(vport, ndlp);
  4617. }
  4618. }
  4619. if (vport->port_state != LPFC_FLOGI) {
  4620. if (phba->sli_rev <= LPFC_SLI_REV3)
  4621. lpfc_initial_flogi(vport);
  4622. else
  4623. lpfc_issue_init_vfi(vport);
  4624. return;
  4625. }
  4626. break;
  4627. case LPFC_FDISC:
  4628. case LPFC_FLOGI:
  4629. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  4630. /* Initial FLOGI timeout */
  4631. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4632. "0222 Initial %s timeout\n",
  4633. vport->vpi ? "FDISC" : "FLOGI");
  4634. /* Assume no Fabric and go on with discovery.
  4635. * Check for outstanding ELS FLOGI to abort.
  4636. */
  4637. /* FLOGI failed, so just use loop map to make discovery list */
  4638. lpfc_disc_list_loopmap(vport);
  4639. /* Start discovery */
  4640. lpfc_disc_start(vport);
  4641. break;
  4642. case LPFC_FABRIC_CFG_LINK:
  4643. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  4644. NameServer login */
  4645. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4646. "0223 Timeout while waiting for "
  4647. "NameServer login\n");
  4648. /* Next look for NameServer ndlp */
  4649. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4650. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  4651. lpfc_els_abort(phba, ndlp);
  4652. /* ReStart discovery */
  4653. goto restart_disc;
  4654. case LPFC_NS_QRY:
  4655. /* Check for wait for NameServer Rsp timeout */
  4656. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4657. "0224 NameServer Query timeout "
  4658. "Data: x%x x%x\n",
  4659. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  4660. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  4661. /* Try it one more time */
  4662. vport->fc_ns_retry++;
  4663. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  4664. vport->fc_ns_retry, 0);
  4665. if (rc == 0)
  4666. break;
  4667. }
  4668. vport->fc_ns_retry = 0;
  4669. restart_disc:
  4670. /*
  4671. * Discovery is over.
  4672. * set port_state to PORT_READY if SLI2.
  4673. * cmpl_reg_vpi will set port_state to READY for SLI3.
  4674. */
  4675. if (phba->sli_rev < LPFC_SLI_REV4) {
  4676. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  4677. lpfc_issue_reg_vpi(phba, vport);
  4678. else {
  4679. lpfc_issue_clear_la(phba, vport);
  4680. vport->port_state = LPFC_VPORT_READY;
  4681. }
  4682. }
  4683. /* Setup and issue mailbox INITIALIZE LINK command */
  4684. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4685. if (!initlinkmbox) {
  4686. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4687. "0206 Device Discovery "
  4688. "completion error\n");
  4689. phba->link_state = LPFC_HBA_ERROR;
  4690. break;
  4691. }
  4692. lpfc_linkdown(phba);
  4693. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  4694. phba->cfg_link_speed);
  4695. initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  4696. initlinkmbox->vport = vport;
  4697. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4698. rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
  4699. lpfc_set_loopback_flag(phba);
  4700. if (rc == MBX_NOT_FINISHED)
  4701. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  4702. break;
  4703. case LPFC_DISC_AUTH:
  4704. /* Node Authentication timeout */
  4705. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4706. "0227 Node Authentication timeout\n");
  4707. lpfc_disc_flush_list(vport);
  4708. /*
  4709. * set port_state to PORT_READY if SLI2.
  4710. * cmpl_reg_vpi will set port_state to READY for SLI3.
  4711. */
  4712. if (phba->sli_rev < LPFC_SLI_REV4) {
  4713. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  4714. lpfc_issue_reg_vpi(phba, vport);
  4715. else { /* NPIV Not enabled */
  4716. lpfc_issue_clear_la(phba, vport);
  4717. vport->port_state = LPFC_VPORT_READY;
  4718. }
  4719. }
  4720. break;
  4721. case LPFC_VPORT_READY:
  4722. if (vport->fc_flag & FC_RSCN_MODE) {
  4723. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4724. "0231 RSCN timeout Data: x%x "
  4725. "x%x\n",
  4726. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  4727. /* Cleanup any outstanding ELS commands */
  4728. lpfc_els_flush_cmd(vport);
  4729. lpfc_els_flush_rscn(vport);
  4730. lpfc_disc_flush_list(vport);
  4731. }
  4732. break;
  4733. default:
  4734. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4735. "0273 Unexpected discovery timeout, "
  4736. "vport State x%x\n", vport->port_state);
  4737. break;
  4738. }
  4739. switch (phba->link_state) {
  4740. case LPFC_CLEAR_LA:
  4741. /* CLEAR LA timeout */
  4742. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4743. "0228 CLEAR LA timeout\n");
  4744. clrlaerr = 1;
  4745. break;
  4746. case LPFC_LINK_UP:
  4747. lpfc_issue_clear_la(phba, vport);
  4748. /* Drop thru */
  4749. case LPFC_LINK_UNKNOWN:
  4750. case LPFC_WARM_START:
  4751. case LPFC_INIT_START:
  4752. case LPFC_INIT_MBX_CMDS:
  4753. case LPFC_LINK_DOWN:
  4754. case LPFC_HBA_ERROR:
  4755. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4756. "0230 Unexpected timeout, hba link "
  4757. "state x%x\n", phba->link_state);
  4758. clrlaerr = 1;
  4759. break;
  4760. case LPFC_HBA_READY:
  4761. break;
  4762. }
  4763. if (clrlaerr) {
  4764. lpfc_disc_flush_list(vport);
  4765. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4766. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4767. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4768. vport->port_state = LPFC_VPORT_READY;
  4769. }
  4770. return;
  4771. }
  4772. /*
  4773. * This routine handles processing a NameServer REG_LOGIN mailbox
  4774. * command upon completion. It is setup in the LPFC_MBOXQ
  4775. * as the completion routine when the command is
  4776. * handed off to the SLI layer.
  4777. */
  4778. void
  4779. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4780. {
  4781. MAILBOX_t *mb = &pmb->u.mb;
  4782. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  4783. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  4784. struct lpfc_vport *vport = pmb->vport;
  4785. pmb->context1 = NULL;
  4786. pmb->context2 = NULL;
  4787. if (phba->sli_rev < LPFC_SLI_REV4)
  4788. ndlp->nlp_rpi = mb->un.varWords[0];
  4789. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  4790. ndlp->nlp_type |= NLP_FABRIC;
  4791. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  4792. /*
  4793. * Start issuing Fabric-Device Management Interface (FDMI) command to
  4794. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  4795. * fdmi-on=2 (supporting RPA/hostnmae)
  4796. */
  4797. if (vport->cfg_fdmi_on == 1)
  4798. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  4799. else
  4800. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  4801. /* decrement the node reference count held for this callback
  4802. * function.
  4803. */
  4804. lpfc_nlp_put(ndlp);
  4805. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4806. kfree(mp);
  4807. mempool_free(pmb, phba->mbox_mem_pool);
  4808. return;
  4809. }
  4810. static int
  4811. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  4812. {
  4813. uint16_t *rpi = param;
  4814. return ndlp->nlp_rpi == *rpi;
  4815. }
  4816. static int
  4817. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  4818. {
  4819. return memcmp(&ndlp->nlp_portname, param,
  4820. sizeof(ndlp->nlp_portname)) == 0;
  4821. }
  4822. static struct lpfc_nodelist *
  4823. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  4824. {
  4825. struct lpfc_nodelist *ndlp;
  4826. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4827. if (filter(ndlp, param))
  4828. return ndlp;
  4829. }
  4830. return NULL;
  4831. }
  4832. /*
  4833. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  4834. * returns the node list element pointer else return NULL.
  4835. */
  4836. struct lpfc_nodelist *
  4837. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  4838. {
  4839. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  4840. }
  4841. /*
  4842. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  4843. * returns the node element list pointer else return NULL.
  4844. */
  4845. struct lpfc_nodelist *
  4846. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  4847. {
  4848. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4849. struct lpfc_nodelist *ndlp;
  4850. spin_lock_irq(shost->host_lock);
  4851. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  4852. spin_unlock_irq(shost->host_lock);
  4853. return ndlp;
  4854. }
  4855. /*
  4856. * This routine looks up the ndlp lists for the given RPI. If the rpi
  4857. * is found, the routine returns the node element list pointer else
  4858. * return NULL.
  4859. */
  4860. struct lpfc_nodelist *
  4861. lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  4862. {
  4863. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4864. struct lpfc_nodelist *ndlp;
  4865. spin_lock_irq(shost->host_lock);
  4866. ndlp = __lpfc_findnode_rpi(vport, rpi);
  4867. spin_unlock_irq(shost->host_lock);
  4868. return ndlp;
  4869. }
  4870. /**
  4871. * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
  4872. * @phba: pointer to lpfc hba data structure.
  4873. * @vpi: the physical host virtual N_Port identifier.
  4874. *
  4875. * This routine finds a vport on a HBA (referred by @phba) through a
  4876. * @vpi. The function walks the HBA's vport list and returns the address
  4877. * of the vport with the matching @vpi.
  4878. *
  4879. * Return code
  4880. * NULL - No vport with the matching @vpi found
  4881. * Otherwise - Address to the vport with the matching @vpi.
  4882. **/
  4883. struct lpfc_vport *
  4884. lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
  4885. {
  4886. struct lpfc_vport *vport;
  4887. unsigned long flags;
  4888. int i = 0;
  4889. /* The physical ports are always vpi 0 - translate is unnecessary. */
  4890. if (vpi > 0) {
  4891. /*
  4892. * Translate the physical vpi to the logical vpi. The
  4893. * vport stores the logical vpi.
  4894. */
  4895. for (i = 0; i < phba->max_vpi; i++) {
  4896. if (vpi == phba->vpi_ids[i])
  4897. break;
  4898. }
  4899. if (i >= phba->max_vpi) {
  4900. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  4901. "2936 Could not find Vport mapped "
  4902. "to vpi %d\n", vpi);
  4903. return NULL;
  4904. }
  4905. }
  4906. spin_lock_irqsave(&phba->hbalock, flags);
  4907. list_for_each_entry(vport, &phba->port_list, listentry) {
  4908. if (vport->vpi == i) {
  4909. spin_unlock_irqrestore(&phba->hbalock, flags);
  4910. return vport;
  4911. }
  4912. }
  4913. spin_unlock_irqrestore(&phba->hbalock, flags);
  4914. return NULL;
  4915. }
  4916. void
  4917. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  4918. uint32_t did)
  4919. {
  4920. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  4921. lpfc_initialize_node(vport, ndlp, did);
  4922. INIT_LIST_HEAD(&ndlp->nlp_listp);
  4923. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  4924. "node init: did:x%x",
  4925. ndlp->nlp_DID, 0, 0);
  4926. return;
  4927. }
  4928. /* This routine releases all resources associated with a specifc NPort's ndlp
  4929. * and mempool_free's the nodelist.
  4930. */
  4931. static void
  4932. lpfc_nlp_release(struct kref *kref)
  4933. {
  4934. struct lpfc_hba *phba;
  4935. unsigned long flags;
  4936. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  4937. kref);
  4938. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  4939. "node release: did:x%x flg:x%x type:x%x",
  4940. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  4941. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  4942. "0279 lpfc_nlp_release: ndlp:x%p "
  4943. "usgmap:x%x refcnt:%d\n",
  4944. (void *)ndlp, ndlp->nlp_usg_map,
  4945. atomic_read(&ndlp->kref.refcount));
  4946. /* remove ndlp from action. */
  4947. lpfc_nlp_remove(ndlp->vport, ndlp);
  4948. /* clear the ndlp active flag for all release cases */
  4949. phba = ndlp->phba;
  4950. spin_lock_irqsave(&phba->ndlp_lock, flags);
  4951. NLP_CLR_NODE_ACT(ndlp);
  4952. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4953. if (phba->sli_rev == LPFC_SLI_REV4)
  4954. lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
  4955. /* free ndlp memory for final ndlp release */
  4956. if (NLP_CHK_FREE_REQ(ndlp)) {
  4957. kfree(ndlp->lat_data);
  4958. mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
  4959. }
  4960. }
  4961. /* This routine bumps the reference count for a ndlp structure to ensure
  4962. * that one discovery thread won't free a ndlp while another discovery thread
  4963. * is using it.
  4964. */
  4965. struct lpfc_nodelist *
  4966. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  4967. {
  4968. struct lpfc_hba *phba;
  4969. unsigned long flags;
  4970. if (ndlp) {
  4971. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  4972. "node get: did:x%x flg:x%x refcnt:x%x",
  4973. ndlp->nlp_DID, ndlp->nlp_flag,
  4974. atomic_read(&ndlp->kref.refcount));
  4975. /* The check of ndlp usage to prevent incrementing the
  4976. * ndlp reference count that is in the process of being
  4977. * released.
  4978. */
  4979. phba = ndlp->phba;
  4980. spin_lock_irqsave(&phba->ndlp_lock, flags);
  4981. if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
  4982. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4983. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  4984. "0276 lpfc_nlp_get: ndlp:x%p "
  4985. "usgmap:x%x refcnt:%d\n",
  4986. (void *)ndlp, ndlp->nlp_usg_map,
  4987. atomic_read(&ndlp->kref.refcount));
  4988. return NULL;
  4989. } else
  4990. kref_get(&ndlp->kref);
  4991. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4992. }
  4993. return ndlp;
  4994. }
  4995. /* This routine decrements the reference count for a ndlp structure. If the
  4996. * count goes to 0, this indicates the the associated nodelist should be
  4997. * freed. Returning 1 indicates the ndlp resource has been released; on the
  4998. * other hand, returning 0 indicates the ndlp resource has not been released
  4999. * yet.
  5000. */
  5001. int
  5002. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  5003. {
  5004. struct lpfc_hba *phba;
  5005. unsigned long flags;
  5006. if (!ndlp)
  5007. return 1;
  5008. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  5009. "node put: did:x%x flg:x%x refcnt:x%x",
  5010. ndlp->nlp_DID, ndlp->nlp_flag,
  5011. atomic_read(&ndlp->kref.refcount));
  5012. phba = ndlp->phba;
  5013. spin_lock_irqsave(&phba->ndlp_lock, flags);
  5014. /* Check the ndlp memory free acknowledge flag to avoid the
  5015. * possible race condition that kref_put got invoked again
  5016. * after previous one has done ndlp memory free.
  5017. */
  5018. if (NLP_CHK_FREE_ACK(ndlp)) {
  5019. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  5020. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  5021. "0274 lpfc_nlp_put: ndlp:x%p "
  5022. "usgmap:x%x refcnt:%d\n",
  5023. (void *)ndlp, ndlp->nlp_usg_map,
  5024. atomic_read(&ndlp->kref.refcount));
  5025. return 1;
  5026. }
  5027. /* Check the ndlp inactivate log flag to avoid the possible
  5028. * race condition that kref_put got invoked again after ndlp
  5029. * is already in inactivating state.
  5030. */
  5031. if (NLP_CHK_IACT_REQ(ndlp)) {
  5032. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  5033. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  5034. "0275 lpfc_nlp_put: ndlp:x%p "
  5035. "usgmap:x%x refcnt:%d\n",
  5036. (void *)ndlp, ndlp->nlp_usg_map,
  5037. atomic_read(&ndlp->kref.refcount));
  5038. return 1;
  5039. }
  5040. /* For last put, mark the ndlp usage flags to make sure no
  5041. * other kref_get and kref_put on the same ndlp shall get
  5042. * in between the process when the final kref_put has been
  5043. * invoked on this ndlp.
  5044. */
  5045. if (atomic_read(&ndlp->kref.refcount) == 1) {
  5046. /* Indicate ndlp is put to inactive state. */
  5047. NLP_SET_IACT_REQ(ndlp);
  5048. /* Acknowledge ndlp memory free has been seen. */
  5049. if (NLP_CHK_FREE_REQ(ndlp))
  5050. NLP_SET_FREE_ACK(ndlp);
  5051. }
  5052. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  5053. /* Note, the kref_put returns 1 when decrementing a reference
  5054. * count that was 1, it invokes the release callback function,
  5055. * but it still left the reference count as 1 (not actually
  5056. * performs the last decrementation). Otherwise, it actually
  5057. * decrements the reference count and returns 0.
  5058. */
  5059. return kref_put(&ndlp->kref, lpfc_nlp_release);
  5060. }
  5061. /* This routine free's the specified nodelist if it is not in use
  5062. * by any other discovery thread. This routine returns 1 if the
  5063. * ndlp has been freed. A return value of 0 indicates the ndlp is
  5064. * not yet been released.
  5065. */
  5066. int
  5067. lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
  5068. {
  5069. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  5070. "node not used: did:x%x flg:x%x refcnt:x%x",
  5071. ndlp->nlp_DID, ndlp->nlp_flag,
  5072. atomic_read(&ndlp->kref.refcount));
  5073. if (atomic_read(&ndlp->kref.refcount) == 1)
  5074. if (lpfc_nlp_put(ndlp))
  5075. return 1;
  5076. return 0;
  5077. }
  5078. /**
  5079. * lpfc_fcf_inuse - Check if FCF can be unregistered.
  5080. * @phba: Pointer to hba context object.
  5081. *
  5082. * This function iterate through all FC nodes associated
  5083. * will all vports to check if there is any node with
  5084. * fc_rports associated with it. If there is an fc_rport
  5085. * associated with the node, then the node is either in
  5086. * discovered state or its devloss_timer is pending.
  5087. */
  5088. static int
  5089. lpfc_fcf_inuse(struct lpfc_hba *phba)
  5090. {
  5091. struct lpfc_vport **vports;
  5092. int i, ret = 0;
  5093. struct lpfc_nodelist *ndlp;
  5094. struct Scsi_Host *shost;
  5095. vports = lpfc_create_vport_work_array(phba);
  5096. /* If driver cannot allocate memory, indicate fcf is in use */
  5097. if (!vports)
  5098. return 1;
  5099. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  5100. shost = lpfc_shost_from_vport(vports[i]);
  5101. spin_lock_irq(shost->host_lock);
  5102. /*
  5103. * IF the CVL_RCVD bit is not set then we have sent the
  5104. * flogi.
  5105. * If dev_loss fires while we are waiting we do not want to
  5106. * unreg the fcf.
  5107. */
  5108. if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
  5109. spin_unlock_irq(shost->host_lock);
  5110. ret = 1;
  5111. goto out;
  5112. }
  5113. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  5114. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
  5115. (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  5116. ret = 1;
  5117. spin_unlock_irq(shost->host_lock);
  5118. goto out;
  5119. } else {
  5120. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  5121. "2624 RPI %x DID %x flg %x still "
  5122. "logged in\n",
  5123. ndlp->nlp_rpi, ndlp->nlp_DID,
  5124. ndlp->nlp_flag);
  5125. if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
  5126. ret = 1;
  5127. }
  5128. }
  5129. spin_unlock_irq(shost->host_lock);
  5130. }
  5131. out:
  5132. lpfc_destroy_vport_work_array(phba, vports);
  5133. return ret;
  5134. }
  5135. /**
  5136. * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
  5137. * @phba: Pointer to hba context object.
  5138. * @mboxq: Pointer to mailbox object.
  5139. *
  5140. * This function frees memory associated with the mailbox command.
  5141. */
  5142. void
  5143. lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5144. {
  5145. struct lpfc_vport *vport = mboxq->vport;
  5146. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5147. if (mboxq->u.mb.mbxStatus) {
  5148. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  5149. "2555 UNREG_VFI mbxStatus error x%x "
  5150. "HBA state x%x\n",
  5151. mboxq->u.mb.mbxStatus, vport->port_state);
  5152. }
  5153. spin_lock_irq(shost->host_lock);
  5154. phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
  5155. spin_unlock_irq(shost->host_lock);
  5156. mempool_free(mboxq, phba->mbox_mem_pool);
  5157. return;
  5158. }
  5159. /**
  5160. * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
  5161. * @phba: Pointer to hba context object.
  5162. * @mboxq: Pointer to mailbox object.
  5163. *
  5164. * This function frees memory associated with the mailbox command.
  5165. */
  5166. static void
  5167. lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  5168. {
  5169. struct lpfc_vport *vport = mboxq->vport;
  5170. if (mboxq->u.mb.mbxStatus) {
  5171. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  5172. "2550 UNREG_FCFI mbxStatus error x%x "
  5173. "HBA state x%x\n",
  5174. mboxq->u.mb.mbxStatus, vport->port_state);
  5175. }
  5176. mempool_free(mboxq, phba->mbox_mem_pool);
  5177. return;
  5178. }
  5179. /**
  5180. * lpfc_unregister_fcf_prep - Unregister fcf record preparation
  5181. * @phba: Pointer to hba context object.
  5182. *
  5183. * This function prepare the HBA for unregistering the currently registered
  5184. * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
  5185. * VFIs.
  5186. */
  5187. int
  5188. lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
  5189. {
  5190. struct lpfc_vport **vports;
  5191. struct lpfc_nodelist *ndlp;
  5192. struct Scsi_Host *shost;
  5193. int i, rc;
  5194. /* Unregister RPIs */
  5195. if (lpfc_fcf_inuse(phba))
  5196. lpfc_unreg_hba_rpis(phba);
  5197. /* At this point, all discovery is aborted */
  5198. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  5199. /* Unregister VPIs */
  5200. vports = lpfc_create_vport_work_array(phba);
  5201. if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
  5202. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  5203. /* Stop FLOGI/FDISC retries */
  5204. ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
  5205. if (ndlp)
  5206. lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
  5207. lpfc_cleanup_pending_mbox(vports[i]);
  5208. if (phba->sli_rev == LPFC_SLI_REV4)
  5209. lpfc_sli4_unreg_all_rpis(vports[i]);
  5210. lpfc_mbx_unreg_vpi(vports[i]);
  5211. shost = lpfc_shost_from_vport(vports[i]);
  5212. spin_lock_irq(shost->host_lock);
  5213. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  5214. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  5215. spin_unlock_irq(shost->host_lock);
  5216. }
  5217. lpfc_destroy_vport_work_array(phba, vports);
  5218. /* Cleanup any outstanding ELS commands */
  5219. lpfc_els_flush_all_cmd(phba);
  5220. /* Unregister the physical port VFI */
  5221. rc = lpfc_issue_unreg_vfi(phba->pport);
  5222. return rc;
  5223. }
  5224. /**
  5225. * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
  5226. * @phba: Pointer to hba context object.
  5227. *
  5228. * This function issues synchronous unregister FCF mailbox command to HBA to
  5229. * unregister the currently registered FCF record. The driver does not reset
  5230. * the driver FCF usage state flags.
  5231. *
  5232. * Return 0 if successfully issued, none-zero otherwise.
  5233. */
  5234. int
  5235. lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
  5236. {
  5237. LPFC_MBOXQ_t *mbox;
  5238. int rc;
  5239. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5240. if (!mbox) {
  5241. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  5242. "2551 UNREG_FCFI mbox allocation failed"
  5243. "HBA state x%x\n", phba->pport->port_state);
  5244. return -ENOMEM;
  5245. }
  5246. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  5247. mbox->vport = phba->pport;
  5248. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  5249. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  5250. if (rc == MBX_NOT_FINISHED) {
  5251. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  5252. "2552 Unregister FCFI command failed rc x%x "
  5253. "HBA state x%x\n",
  5254. rc, phba->pport->port_state);
  5255. return -EINVAL;
  5256. }
  5257. return 0;
  5258. }
  5259. /**
  5260. * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
  5261. * @phba: Pointer to hba context object.
  5262. *
  5263. * This function unregisters the currently reigstered FCF. This function
  5264. * also tries to find another FCF for discovery by rescan the HBA FCF table.
  5265. */
  5266. void
  5267. lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
  5268. {
  5269. int rc;
  5270. /* Preparation for unregistering fcf */
  5271. rc = lpfc_unregister_fcf_prep(phba);
  5272. if (rc) {
  5273. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  5274. "2748 Failed to prepare for unregistering "
  5275. "HBA's FCF record: rc=%d\n", rc);
  5276. return;
  5277. }
  5278. /* Now, unregister FCF record and reset HBA FCF state */
  5279. rc = lpfc_sli4_unregister_fcf(phba);
  5280. if (rc)
  5281. return;
  5282. /* Reset HBA FCF states after successful unregister FCF */
  5283. phba->fcf.fcf_flag = 0;
  5284. phba->fcf.current_rec.flag = 0;
  5285. /*
  5286. * If driver is not unloading, check if there is any other
  5287. * FCF record that can be used for discovery.
  5288. */
  5289. if ((phba->pport->load_flag & FC_UNLOADING) ||
  5290. (phba->link_state < LPFC_LINK_UP))
  5291. return;
  5292. /* This is considered as the initial FCF discovery scan */
  5293. spin_lock_irq(&phba->hbalock);
  5294. phba->fcf.fcf_flag |= FCF_INIT_DISC;
  5295. spin_unlock_irq(&phba->hbalock);
  5296. /* Reset FCF roundrobin bmask for new discovery */
  5297. lpfc_sli4_clear_fcf_rr_bmask(phba);
  5298. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  5299. if (rc) {
  5300. spin_lock_irq(&phba->hbalock);
  5301. phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
  5302. spin_unlock_irq(&phba->hbalock);
  5303. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  5304. "2553 lpfc_unregister_unused_fcf failed "
  5305. "to read FCF record HBA state x%x\n",
  5306. phba->pport->port_state);
  5307. }
  5308. }
  5309. /**
  5310. * lpfc_unregister_fcf - Unregister the currently registered fcf record
  5311. * @phba: Pointer to hba context object.
  5312. *
  5313. * This function just unregisters the currently reigstered FCF. It does not
  5314. * try to find another FCF for discovery.
  5315. */
  5316. void
  5317. lpfc_unregister_fcf(struct lpfc_hba *phba)
  5318. {
  5319. int rc;
  5320. /* Preparation for unregistering fcf */
  5321. rc = lpfc_unregister_fcf_prep(phba);
  5322. if (rc) {
  5323. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  5324. "2749 Failed to prepare for unregistering "
  5325. "HBA's FCF record: rc=%d\n", rc);
  5326. return;
  5327. }
  5328. /* Now, unregister FCF record and reset HBA FCF state */
  5329. rc = lpfc_sli4_unregister_fcf(phba);
  5330. if (rc)
  5331. return;
  5332. /* Set proper HBA FCF states after successful unregister FCF */
  5333. spin_lock_irq(&phba->hbalock);
  5334. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  5335. spin_unlock_irq(&phba->hbalock);
  5336. }
  5337. /**
  5338. * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
  5339. * @phba: Pointer to hba context object.
  5340. *
  5341. * This function check if there are any connected remote port for the FCF and
  5342. * if all the devices are disconnected, this function unregister FCFI.
  5343. * This function also tries to use another FCF for discovery.
  5344. */
  5345. void
  5346. lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
  5347. {
  5348. /*
  5349. * If HBA is not running in FIP mode, if HBA does not support
  5350. * FCoE, if FCF discovery is ongoing, or if FCF has not been
  5351. * registered, do nothing.
  5352. */
  5353. spin_lock_irq(&phba->hbalock);
  5354. if (!(phba->hba_flag & HBA_FCOE_MODE) ||
  5355. !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
  5356. !(phba->hba_flag & HBA_FIP_SUPPORT) ||
  5357. (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
  5358. (phba->pport->port_state == LPFC_FLOGI)) {
  5359. spin_unlock_irq(&phba->hbalock);
  5360. return;
  5361. }
  5362. spin_unlock_irq(&phba->hbalock);
  5363. if (lpfc_fcf_inuse(phba))
  5364. return;
  5365. lpfc_unregister_fcf_rescan(phba);
  5366. }
  5367. /**
  5368. * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
  5369. * @phba: Pointer to hba context object.
  5370. * @buff: Buffer containing the FCF connection table as in the config
  5371. * region.
  5372. * This function create driver data structure for the FCF connection
  5373. * record table read from config region 23.
  5374. */
  5375. static void
  5376. lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
  5377. uint8_t *buff)
  5378. {
  5379. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  5380. struct lpfc_fcf_conn_hdr *conn_hdr;
  5381. struct lpfc_fcf_conn_rec *conn_rec;
  5382. uint32_t record_count;
  5383. int i;
  5384. /* Free the current connect table */
  5385. list_for_each_entry_safe(conn_entry, next_conn_entry,
  5386. &phba->fcf_conn_rec_list, list) {
  5387. list_del_init(&conn_entry->list);
  5388. kfree(conn_entry);
  5389. }
  5390. conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
  5391. record_count = conn_hdr->length * sizeof(uint32_t)/
  5392. sizeof(struct lpfc_fcf_conn_rec);
  5393. conn_rec = (struct lpfc_fcf_conn_rec *)
  5394. (buff + sizeof(struct lpfc_fcf_conn_hdr));
  5395. for (i = 0; i < record_count; i++) {
  5396. if (!(conn_rec[i].flags & FCFCNCT_VALID))
  5397. continue;
  5398. conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
  5399. GFP_KERNEL);
  5400. if (!conn_entry) {
  5401. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5402. "2566 Failed to allocate connection"
  5403. " table entry\n");
  5404. return;
  5405. }
  5406. memcpy(&conn_entry->conn_rec, &conn_rec[i],
  5407. sizeof(struct lpfc_fcf_conn_rec));
  5408. conn_entry->conn_rec.vlan_tag =
  5409. le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
  5410. conn_entry->conn_rec.flags =
  5411. le16_to_cpu(conn_entry->conn_rec.flags);
  5412. list_add_tail(&conn_entry->list,
  5413. &phba->fcf_conn_rec_list);
  5414. }
  5415. }
  5416. /**
  5417. * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
  5418. * @phba: Pointer to hba context object.
  5419. * @buff: Buffer containing the FCoE parameter data structure.
  5420. *
  5421. * This function update driver data structure with config
  5422. * parameters read from config region 23.
  5423. */
  5424. static void
  5425. lpfc_read_fcoe_param(struct lpfc_hba *phba,
  5426. uint8_t *buff)
  5427. {
  5428. struct lpfc_fip_param_hdr *fcoe_param_hdr;
  5429. struct lpfc_fcoe_params *fcoe_param;
  5430. fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
  5431. buff;
  5432. fcoe_param = (struct lpfc_fcoe_params *)
  5433. (buff + sizeof(struct lpfc_fip_param_hdr));
  5434. if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
  5435. (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
  5436. return;
  5437. if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
  5438. phba->valid_vlan = 1;
  5439. phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
  5440. 0xFFF;
  5441. }
  5442. phba->fc_map[0] = fcoe_param->fc_map[0];
  5443. phba->fc_map[1] = fcoe_param->fc_map[1];
  5444. phba->fc_map[2] = fcoe_param->fc_map[2];
  5445. return;
  5446. }
  5447. /**
  5448. * lpfc_get_rec_conf23 - Get a record type in config region data.
  5449. * @buff: Buffer containing config region 23 data.
  5450. * @size: Size of the data buffer.
  5451. * @rec_type: Record type to be searched.
  5452. *
  5453. * This function searches config region data to find the beginning
  5454. * of the record specified by record_type. If record found, this
  5455. * function return pointer to the record else return NULL.
  5456. */
  5457. static uint8_t *
  5458. lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
  5459. {
  5460. uint32_t offset = 0, rec_length;
  5461. if ((buff[0] == LPFC_REGION23_LAST_REC) ||
  5462. (size < sizeof(uint32_t)))
  5463. return NULL;
  5464. rec_length = buff[offset + 1];
  5465. /*
  5466. * One TLV record has one word header and number of data words
  5467. * specified in the rec_length field of the record header.
  5468. */
  5469. while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
  5470. <= size) {
  5471. if (buff[offset] == rec_type)
  5472. return &buff[offset];
  5473. if (buff[offset] == LPFC_REGION23_LAST_REC)
  5474. return NULL;
  5475. offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
  5476. rec_length = buff[offset + 1];
  5477. }
  5478. return NULL;
  5479. }
  5480. /**
  5481. * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
  5482. * @phba: Pointer to lpfc_hba data structure.
  5483. * @buff: Buffer containing config region 23 data.
  5484. * @size: Size of the data buffer.
  5485. *
  5486. * This function parses the FCoE config parameters in config region 23 and
  5487. * populate driver data structure with the parameters.
  5488. */
  5489. void
  5490. lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
  5491. uint8_t *buff,
  5492. uint32_t size)
  5493. {
  5494. uint32_t offset = 0, rec_length;
  5495. uint8_t *rec_ptr;
  5496. /*
  5497. * If data size is less than 2 words signature and version cannot be
  5498. * verified.
  5499. */
  5500. if (size < 2*sizeof(uint32_t))
  5501. return;
  5502. /* Check the region signature first */
  5503. if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
  5504. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5505. "2567 Config region 23 has bad signature\n");
  5506. return;
  5507. }
  5508. offset += 4;
  5509. /* Check the data structure version */
  5510. if (buff[offset] != LPFC_REGION23_VERSION) {
  5511. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  5512. "2568 Config region 23 has bad version\n");
  5513. return;
  5514. }
  5515. offset += 4;
  5516. rec_length = buff[offset + 1];
  5517. /* Read FCoE param record */
  5518. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  5519. size - offset, FCOE_PARAM_TYPE);
  5520. if (rec_ptr)
  5521. lpfc_read_fcoe_param(phba, rec_ptr);
  5522. /* Read FCF connection table */
  5523. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  5524. size - offset, FCOE_CONN_TBL_TYPE);
  5525. if (rec_ptr)
  5526. lpfc_read_fcf_conn_tbl(phba, rec_ptr);
  5527. }