lpfc_hbadisc.c 181 KB

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