lpfc_hbadisc.c 188 KB

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