lpfc_hbadisc.c 181 KB

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