lpfc_hbadisc.c 210 KB

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