lpfc_hbadisc.c 181 KB

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