lpfc_hbadisc.c 186 KB

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