lpfc_hbadisc.c 196 KB

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