lpfc_hbadisc.c 188 KB

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