lpfc_els.c 253 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2012 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. /* See Fibre Channel protocol T11 FC-LS for details */
  22. #include <linux/blkdev.h>
  23. #include <linux/pci.h>
  24. #include <linux/slab.h>
  25. #include <linux/interrupt.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_host.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include "lpfc_hw4.h"
  31. #include "lpfc_hw.h"
  32. #include "lpfc_sli.h"
  33. #include "lpfc_sli4.h"
  34. #include "lpfc_nl.h"
  35. #include "lpfc_disc.h"
  36. #include "lpfc_scsi.h"
  37. #include "lpfc.h"
  38. #include "lpfc_logmsg.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_vport.h"
  41. #include "lpfc_debugfs.h"
  42. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  43. struct lpfc_iocbq *);
  44. static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
  45. struct lpfc_iocbq *);
  46. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
  47. static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
  48. struct lpfc_nodelist *ndlp, uint8_t retry);
  49. static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
  50. struct lpfc_iocbq *iocb);
  51. static int lpfc_max_els_tries = 3;
  52. /**
  53. * lpfc_els_chk_latt - Check host link attention event for a vport
  54. * @vport: pointer to a host virtual N_Port data structure.
  55. *
  56. * This routine checks whether there is an outstanding host link
  57. * attention event during the discovery process with the @vport. It is done
  58. * by reading the HBA's Host Attention (HA) register. If there is any host
  59. * link attention events during this @vport's discovery process, the @vport
  60. * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
  61. * be issued if the link state is not already in host link cleared state,
  62. * and a return code shall indicate whether the host link attention event
  63. * had happened.
  64. *
  65. * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
  66. * state in LPFC_VPORT_READY, the request for checking host link attention
  67. * event will be ignored and a return code shall indicate no host link
  68. * attention event had happened.
  69. *
  70. * Return codes
  71. * 0 - no host link attention event happened
  72. * 1 - host link attention event happened
  73. **/
  74. int
  75. lpfc_els_chk_latt(struct lpfc_vport *vport)
  76. {
  77. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  78. struct lpfc_hba *phba = vport->phba;
  79. uint32_t ha_copy;
  80. if (vport->port_state >= LPFC_VPORT_READY ||
  81. phba->link_state == LPFC_LINK_DOWN ||
  82. phba->sli_rev > LPFC_SLI_REV3)
  83. return 0;
  84. /* Read the HBA Host Attention Register */
  85. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  86. return 1;
  87. if (!(ha_copy & HA_LATT))
  88. return 0;
  89. /* Pending Link Event during Discovery */
  90. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  91. "0237 Pending Link Event during "
  92. "Discovery: State x%x\n",
  93. phba->pport->port_state);
  94. /* CLEAR_LA should re-enable link attention events and
  95. * we should then immediately take a LATT event. The
  96. * LATT processing should call lpfc_linkdown() which
  97. * will cleanup any left over in-progress discovery
  98. * events.
  99. */
  100. spin_lock_irq(shost->host_lock);
  101. vport->fc_flag |= FC_ABORT_DISCOVERY;
  102. spin_unlock_irq(shost->host_lock);
  103. if (phba->link_state != LPFC_CLEAR_LA)
  104. lpfc_issue_clear_la(phba, vport);
  105. return 1;
  106. }
  107. /**
  108. * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
  109. * @vport: pointer to a host virtual N_Port data structure.
  110. * @expectRsp: flag indicating whether response is expected.
  111. * @cmdSize: size of the ELS command.
  112. * @retry: number of retries to the command IOCB when it fails.
  113. * @ndlp: pointer to a node-list data structure.
  114. * @did: destination identifier.
  115. * @elscmd: the ELS command code.
  116. *
  117. * This routine is used for allocating a lpfc-IOCB data structure from
  118. * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
  119. * passed into the routine for discovery state machine to issue an Extended
  120. * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
  121. * and preparation routine that is used by all the discovery state machine
  122. * routines and the ELS command-specific fields will be later set up by
  123. * the individual discovery machine routines after calling this routine
  124. * allocating and preparing a generic IOCB data structure. It fills in the
  125. * Buffer Descriptor Entries (BDEs), allocates buffers for both command
  126. * payload and response payload (if expected). The reference count on the
  127. * ndlp is incremented by 1 and the reference to the ndlp is put into
  128. * context1 of the IOCB data structure for this IOCB to hold the ndlp
  129. * reference for the command's callback function to access later.
  130. *
  131. * Return code
  132. * Pointer to the newly allocated/prepared els iocb data structure
  133. * NULL - when els iocb data structure allocation/preparation failed
  134. **/
  135. struct lpfc_iocbq *
  136. lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
  137. uint16_t cmdSize, uint8_t retry,
  138. struct lpfc_nodelist *ndlp, uint32_t did,
  139. uint32_t elscmd)
  140. {
  141. struct lpfc_hba *phba = vport->phba;
  142. struct lpfc_iocbq *elsiocb;
  143. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
  144. struct ulp_bde64 *bpl;
  145. IOCB_t *icmd;
  146. if (!lpfc_is_link_up(phba))
  147. return NULL;
  148. /* Allocate buffer for command iocb */
  149. elsiocb = lpfc_sli_get_iocbq(phba);
  150. if (elsiocb == NULL)
  151. return NULL;
  152. /*
  153. * If this command is for fabric controller and HBA running
  154. * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
  155. */
  156. if ((did == Fabric_DID) &&
  157. (phba->hba_flag & HBA_FIP_SUPPORT) &&
  158. ((elscmd == ELS_CMD_FLOGI) ||
  159. (elscmd == ELS_CMD_FDISC) ||
  160. (elscmd == ELS_CMD_LOGO)))
  161. switch (elscmd) {
  162. case ELS_CMD_FLOGI:
  163. elsiocb->iocb_flag |=
  164. ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
  165. & LPFC_FIP_ELS_ID_MASK);
  166. break;
  167. case ELS_CMD_FDISC:
  168. elsiocb->iocb_flag |=
  169. ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
  170. & LPFC_FIP_ELS_ID_MASK);
  171. break;
  172. case ELS_CMD_LOGO:
  173. elsiocb->iocb_flag |=
  174. ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
  175. & LPFC_FIP_ELS_ID_MASK);
  176. break;
  177. }
  178. else
  179. elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
  180. icmd = &elsiocb->iocb;
  181. /* fill in BDEs for command */
  182. /* Allocate buffer for command payload */
  183. pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  184. if (pcmd)
  185. pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
  186. if (!pcmd || !pcmd->virt)
  187. goto els_iocb_free_pcmb_exit;
  188. INIT_LIST_HEAD(&pcmd->list);
  189. /* Allocate buffer for response payload */
  190. if (expectRsp) {
  191. prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  192. if (prsp)
  193. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  194. &prsp->phys);
  195. if (!prsp || !prsp->virt)
  196. goto els_iocb_free_prsp_exit;
  197. INIT_LIST_HEAD(&prsp->list);
  198. } else
  199. prsp = NULL;
  200. /* Allocate buffer for Buffer ptr list */
  201. pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  202. if (pbuflist)
  203. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  204. &pbuflist->phys);
  205. if (!pbuflist || !pbuflist->virt)
  206. goto els_iocb_free_pbuf_exit;
  207. INIT_LIST_HEAD(&pbuflist->list);
  208. if (expectRsp) {
  209. icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  210. icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  211. icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  212. icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  213. icmd->un.elsreq64.remoteID = did; /* DID */
  214. icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  215. icmd->ulpTimeout = phba->fc_ratov * 2;
  216. } else {
  217. icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  218. icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  219. icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  220. icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
  221. icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
  222. icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  223. }
  224. icmd->ulpBdeCount = 1;
  225. icmd->ulpLe = 1;
  226. icmd->ulpClass = CLASS3;
  227. /*
  228. * If we have NPIV enabled, we want to send ELS traffic by VPI.
  229. * For SLI4, since the driver controls VPIs we also want to include
  230. * all ELS pt2pt protocol traffic as well.
  231. */
  232. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
  233. ((phba->sli_rev == LPFC_SLI_REV4) &&
  234. (vport->fc_flag & FC_PT2PT))) {
  235. if (expectRsp) {
  236. icmd->un.elsreq64.myID = vport->fc_myDID;
  237. /* For ELS_REQUEST64_CR, use the VPI by default */
  238. icmd->ulpContext = phba->vpi_ids[vport->vpi];
  239. }
  240. icmd->ulpCt_h = 0;
  241. /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
  242. if (elscmd == ELS_CMD_ECHO)
  243. icmd->ulpCt_l = 0; /* context = invalid RPI */
  244. else
  245. icmd->ulpCt_l = 1; /* context = VPI */
  246. }
  247. bpl = (struct ulp_bde64 *) pbuflist->virt;
  248. bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
  249. bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
  250. bpl->tus.f.bdeSize = cmdSize;
  251. bpl->tus.f.bdeFlags = 0;
  252. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  253. if (expectRsp) {
  254. bpl++;
  255. bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
  256. bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
  257. bpl->tus.f.bdeSize = FCELSSIZE;
  258. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  259. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  260. }
  261. /* prevent preparing iocb with NULL ndlp reference */
  262. elsiocb->context1 = lpfc_nlp_get(ndlp);
  263. if (!elsiocb->context1)
  264. goto els_iocb_free_pbuf_exit;
  265. elsiocb->context2 = pcmd;
  266. elsiocb->context3 = pbuflist;
  267. elsiocb->retry = retry;
  268. elsiocb->vport = vport;
  269. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  270. if (prsp) {
  271. list_add(&prsp->list, &pcmd->list);
  272. }
  273. if (expectRsp) {
  274. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  275. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  276. "0116 Xmit ELS command x%x to remote "
  277. "NPORT x%x I/O tag: x%x, port state: x%x\n",
  278. elscmd, did, elsiocb->iotag,
  279. vport->port_state);
  280. } else {
  281. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  282. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  283. "0117 Xmit ELS response x%x to remote "
  284. "NPORT x%x I/O tag: x%x, size: x%x\n",
  285. elscmd, ndlp->nlp_DID, elsiocb->iotag,
  286. cmdSize);
  287. }
  288. return elsiocb;
  289. els_iocb_free_pbuf_exit:
  290. if (expectRsp)
  291. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  292. kfree(pbuflist);
  293. els_iocb_free_prsp_exit:
  294. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  295. kfree(prsp);
  296. els_iocb_free_pcmb_exit:
  297. kfree(pcmd);
  298. lpfc_sli_release_iocbq(phba, elsiocb);
  299. return NULL;
  300. }
  301. /**
  302. * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
  303. * @vport: pointer to a host virtual N_Port data structure.
  304. *
  305. * This routine issues a fabric registration login for a @vport. An
  306. * active ndlp node with Fabric_DID must already exist for this @vport.
  307. * The routine invokes two mailbox commands to carry out fabric registration
  308. * login through the HBA firmware: the first mailbox command requests the
  309. * HBA to perform link configuration for the @vport; and the second mailbox
  310. * command requests the HBA to perform the actual fabric registration login
  311. * with the @vport.
  312. *
  313. * Return code
  314. * 0 - successfully issued fabric registration login for @vport
  315. * -ENXIO -- failed to issue fabric registration login for @vport
  316. **/
  317. int
  318. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  319. {
  320. struct lpfc_hba *phba = vport->phba;
  321. LPFC_MBOXQ_t *mbox;
  322. struct lpfc_dmabuf *mp;
  323. struct lpfc_nodelist *ndlp;
  324. struct serv_parm *sp;
  325. int rc;
  326. int err = 0;
  327. sp = &phba->fc_fabparam;
  328. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  329. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  330. err = 1;
  331. goto fail;
  332. }
  333. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  334. if (!mbox) {
  335. err = 2;
  336. goto fail;
  337. }
  338. vport->port_state = LPFC_FABRIC_CFG_LINK;
  339. lpfc_config_link(phba, mbox);
  340. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  341. mbox->vport = vport;
  342. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  343. if (rc == MBX_NOT_FINISHED) {
  344. err = 3;
  345. goto fail_free_mbox;
  346. }
  347. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  348. if (!mbox) {
  349. err = 4;
  350. goto fail;
  351. }
  352. rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  353. ndlp->nlp_rpi);
  354. if (rc) {
  355. err = 5;
  356. goto fail_free_mbox;
  357. }
  358. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  359. mbox->vport = vport;
  360. /* increment the reference count on ndlp to hold reference
  361. * for the callback routine.
  362. */
  363. mbox->context2 = lpfc_nlp_get(ndlp);
  364. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  365. if (rc == MBX_NOT_FINISHED) {
  366. err = 6;
  367. goto fail_issue_reg_login;
  368. }
  369. return 0;
  370. fail_issue_reg_login:
  371. /* decrement the reference count on ndlp just incremented
  372. * for the failed mbox command.
  373. */
  374. lpfc_nlp_put(ndlp);
  375. mp = (struct lpfc_dmabuf *) mbox->context1;
  376. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  377. kfree(mp);
  378. fail_free_mbox:
  379. mempool_free(mbox, phba->mbox_mem_pool);
  380. fail:
  381. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  382. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  383. "0249 Cannot issue Register Fabric login: Err %d\n", err);
  384. return -ENXIO;
  385. }
  386. /**
  387. * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
  388. * @vport: pointer to a host virtual N_Port data structure.
  389. *
  390. * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
  391. * the @vport. This mailbox command is necessary for SLI4 port only.
  392. *
  393. * Return code
  394. * 0 - successfully issued REG_VFI for @vport
  395. * A failure code otherwise.
  396. **/
  397. int
  398. lpfc_issue_reg_vfi(struct lpfc_vport *vport)
  399. {
  400. struct lpfc_hba *phba = vport->phba;
  401. LPFC_MBOXQ_t *mboxq;
  402. struct lpfc_nodelist *ndlp;
  403. struct serv_parm *sp;
  404. struct lpfc_dmabuf *dmabuf;
  405. int rc = 0;
  406. sp = &phba->fc_fabparam;
  407. /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
  408. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  409. !(phba->link_flag & LS_LOOPBACK_MODE) &&
  410. !(vport->fc_flag & FC_PT2PT)) {
  411. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  412. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  413. rc = -ENODEV;
  414. goto fail;
  415. }
  416. }
  417. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  418. if (!dmabuf) {
  419. rc = -ENOMEM;
  420. goto fail;
  421. }
  422. dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
  423. if (!dmabuf->virt) {
  424. rc = -ENOMEM;
  425. goto fail_free_dmabuf;
  426. }
  427. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  428. if (!mboxq) {
  429. rc = -ENOMEM;
  430. goto fail_free_coherent;
  431. }
  432. vport->port_state = LPFC_FABRIC_CFG_LINK;
  433. memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
  434. lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
  435. mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
  436. mboxq->vport = vport;
  437. mboxq->context1 = dmabuf;
  438. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  439. if (rc == MBX_NOT_FINISHED) {
  440. rc = -ENXIO;
  441. goto fail_free_mbox;
  442. }
  443. return 0;
  444. fail_free_mbox:
  445. mempool_free(mboxq, phba->mbox_mem_pool);
  446. fail_free_coherent:
  447. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  448. fail_free_dmabuf:
  449. kfree(dmabuf);
  450. fail:
  451. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  452. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  453. "0289 Issue Register VFI failed: Err %d\n", rc);
  454. return rc;
  455. }
  456. /**
  457. * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
  458. * @vport: pointer to a host virtual N_Port data structure.
  459. *
  460. * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
  461. * the @vport. This mailbox command is necessary for SLI4 port only.
  462. *
  463. * Return code
  464. * 0 - successfully issued REG_VFI for @vport
  465. * A failure code otherwise.
  466. **/
  467. int
  468. lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
  469. {
  470. struct lpfc_hba *phba = vport->phba;
  471. struct Scsi_Host *shost;
  472. LPFC_MBOXQ_t *mboxq;
  473. int rc;
  474. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  475. if (!mboxq) {
  476. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  477. "2556 UNREG_VFI mbox allocation failed"
  478. "HBA state x%x\n", phba->pport->port_state);
  479. return -ENOMEM;
  480. }
  481. lpfc_unreg_vfi(mboxq, vport);
  482. mboxq->vport = vport;
  483. mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  484. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  485. if (rc == MBX_NOT_FINISHED) {
  486. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  487. "2557 UNREG_VFI issue mbox failed rc x%x "
  488. "HBA state x%x\n",
  489. rc, phba->pport->port_state);
  490. mempool_free(mboxq, phba->mbox_mem_pool);
  491. return -EIO;
  492. }
  493. shost = lpfc_shost_from_vport(vport);
  494. spin_lock_irq(shost->host_lock);
  495. vport->fc_flag &= ~FC_VFI_REGISTERED;
  496. spin_unlock_irq(shost->host_lock);
  497. return 0;
  498. }
  499. /**
  500. * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
  501. * @vport: pointer to a host virtual N_Port data structure.
  502. * @sp: pointer to service parameter data structure.
  503. *
  504. * This routine is called from FLOGI/FDISC completion handler functions.
  505. * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
  506. * node nodename is changed in the completion service parameter else return
  507. * 0. This function also set flag in the vport data structure to delay
  508. * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
  509. * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
  510. * node nodename is changed in the completion service parameter.
  511. *
  512. * Return code
  513. * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
  514. * 1 - FCID or Fabric Nodename or Fabric portname is changed.
  515. *
  516. **/
  517. static uint8_t
  518. lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
  519. struct serv_parm *sp)
  520. {
  521. uint8_t fabric_param_changed = 0;
  522. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  523. if ((vport->fc_prevDID != vport->fc_myDID) ||
  524. memcmp(&vport->fabric_portname, &sp->portName,
  525. sizeof(struct lpfc_name)) ||
  526. memcmp(&vport->fabric_nodename, &sp->nodeName,
  527. sizeof(struct lpfc_name)))
  528. fabric_param_changed = 1;
  529. /*
  530. * Word 1 Bit 31 in common service parameter is overloaded.
  531. * Word 1 Bit 31 in FLOGI request is multiple NPort request
  532. * Word 1 Bit 31 in FLOGI response is clean address bit
  533. *
  534. * If fabric parameter is changed and clean address bit is
  535. * cleared delay nport discovery if
  536. * - vport->fc_prevDID != 0 (not initial discovery) OR
  537. * - lpfc_delay_discovery module parameter is set.
  538. */
  539. if (fabric_param_changed && !sp->cmn.clean_address_bit &&
  540. (vport->fc_prevDID || lpfc_delay_discovery)) {
  541. spin_lock_irq(shost->host_lock);
  542. vport->fc_flag |= FC_DISC_DELAYED;
  543. spin_unlock_irq(shost->host_lock);
  544. }
  545. return fabric_param_changed;
  546. }
  547. /**
  548. * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
  549. * @vport: pointer to a host virtual N_Port data structure.
  550. * @ndlp: pointer to a node-list data structure.
  551. * @sp: pointer to service parameter data structure.
  552. * @irsp: pointer to the IOCB within the lpfc response IOCB.
  553. *
  554. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  555. * function to handle the completion of a Fabric Login (FLOGI) into a fabric
  556. * port in a fabric topology. It properly sets up the parameters to the @ndlp
  557. * from the IOCB response. It also check the newly assigned N_Port ID to the
  558. * @vport against the previously assigned N_Port ID. If it is different from
  559. * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
  560. * is invoked on all the remaining nodes with the @vport to unregister the
  561. * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
  562. * is invoked to register login to the fabric.
  563. *
  564. * Return code
  565. * 0 - Success (currently, always return 0)
  566. **/
  567. static int
  568. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  569. struct serv_parm *sp, IOCB_t *irsp)
  570. {
  571. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  572. struct lpfc_hba *phba = vport->phba;
  573. struct lpfc_nodelist *np;
  574. struct lpfc_nodelist *next_np;
  575. uint8_t fabric_param_changed;
  576. spin_lock_irq(shost->host_lock);
  577. vport->fc_flag |= FC_FABRIC;
  578. spin_unlock_irq(shost->host_lock);
  579. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  580. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  581. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  582. phba->fc_edtovResol = sp->cmn.edtovResolution;
  583. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  584. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  585. spin_lock_irq(shost->host_lock);
  586. vport->fc_flag |= FC_PUBLIC_LOOP;
  587. spin_unlock_irq(shost->host_lock);
  588. }
  589. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  590. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  591. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  592. ndlp->nlp_class_sup = 0;
  593. if (sp->cls1.classValid)
  594. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  595. if (sp->cls2.classValid)
  596. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  597. if (sp->cls3.classValid)
  598. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  599. if (sp->cls4.classValid)
  600. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  601. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  602. sp->cmn.bbRcvSizeLsb;
  603. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  604. memcpy(&vport->fabric_portname, &sp->portName,
  605. sizeof(struct lpfc_name));
  606. memcpy(&vport->fabric_nodename, &sp->nodeName,
  607. sizeof(struct lpfc_name));
  608. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  609. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  610. if (sp->cmn.response_multiple_NPort) {
  611. lpfc_printf_vlog(vport, KERN_WARNING,
  612. LOG_ELS | LOG_VPORT,
  613. "1816 FLOGI NPIV supported, "
  614. "response data 0x%x\n",
  615. sp->cmn.response_multiple_NPort);
  616. spin_lock_irq(&phba->hbalock);
  617. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  618. spin_unlock_irq(&phba->hbalock);
  619. } else {
  620. /* Because we asked f/w for NPIV it still expects us
  621. to call reg_vnpid atleast for the physcial host */
  622. lpfc_printf_vlog(vport, KERN_WARNING,
  623. LOG_ELS | LOG_VPORT,
  624. "1817 Fabric does not support NPIV "
  625. "- configuring single port mode.\n");
  626. spin_lock_irq(&phba->hbalock);
  627. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  628. spin_unlock_irq(&phba->hbalock);
  629. }
  630. }
  631. if (fabric_param_changed &&
  632. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  633. /* If our NportID changed, we need to ensure all
  634. * remaining NPORTs get unreg_login'ed.
  635. */
  636. list_for_each_entry_safe(np, next_np,
  637. &vport->fc_nodes, nlp_listp) {
  638. if (!NLP_CHK_NODE_ACT(np))
  639. continue;
  640. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  641. !(np->nlp_flag & NLP_NPR_ADISC))
  642. continue;
  643. spin_lock_irq(shost->host_lock);
  644. np->nlp_flag &= ~NLP_NPR_ADISC;
  645. spin_unlock_irq(shost->host_lock);
  646. lpfc_unreg_rpi(vport, np);
  647. }
  648. lpfc_cleanup_pending_mbox(vport);
  649. if (phba->sli_rev == LPFC_SLI_REV4) {
  650. lpfc_sli4_unreg_all_rpis(vport);
  651. lpfc_mbx_unreg_vpi(vport);
  652. spin_lock_irq(shost->host_lock);
  653. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  654. spin_unlock_irq(shost->host_lock);
  655. }
  656. /*
  657. * For SLI3 and SLI4, the VPI needs to be reregistered in
  658. * response to this fabric parameter change event.
  659. */
  660. spin_lock_irq(shost->host_lock);
  661. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  662. spin_unlock_irq(shost->host_lock);
  663. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  664. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  665. /*
  666. * Driver needs to re-reg VPI in order for f/w
  667. * to update the MAC address.
  668. */
  669. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  670. lpfc_register_new_vport(phba, vport, ndlp);
  671. return 0;
  672. }
  673. if (phba->sli_rev < LPFC_SLI_REV4) {
  674. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  675. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  676. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  677. lpfc_register_new_vport(phba, vport, ndlp);
  678. else
  679. lpfc_issue_fabric_reglogin(vport);
  680. } else {
  681. ndlp->nlp_type |= NLP_FABRIC;
  682. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  683. if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
  684. (vport->vpi_state & LPFC_VPI_REGISTERED)) {
  685. lpfc_start_fdiscs(phba);
  686. lpfc_do_scr_ns_plogi(phba, vport);
  687. } else if (vport->fc_flag & FC_VFI_REGISTERED)
  688. lpfc_issue_init_vpi(vport);
  689. else {
  690. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  691. "3135 Need register VFI: (x%x/%x)\n",
  692. vport->fc_prevDID, vport->fc_myDID);
  693. lpfc_issue_reg_vfi(vport);
  694. }
  695. }
  696. return 0;
  697. }
  698. /**
  699. * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
  700. * @vport: pointer to a host virtual N_Port data structure.
  701. * @ndlp: pointer to a node-list data structure.
  702. * @sp: pointer to service parameter data structure.
  703. *
  704. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  705. * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
  706. * in a point-to-point topology. First, the @vport's N_Port Name is compared
  707. * with the received N_Port Name: if the @vport's N_Port Name is greater than
  708. * the received N_Port Name lexicographically, this node shall assign local
  709. * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
  710. * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
  711. * this node shall just wait for the remote node to issue PLOGI and assign
  712. * N_Port IDs.
  713. *
  714. * Return code
  715. * 0 - Success
  716. * -ENXIO - Fail
  717. **/
  718. static int
  719. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  720. struct serv_parm *sp)
  721. {
  722. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  723. struct lpfc_hba *phba = vport->phba;
  724. LPFC_MBOXQ_t *mbox;
  725. int rc;
  726. spin_lock_irq(shost->host_lock);
  727. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  728. spin_unlock_irq(shost->host_lock);
  729. phba->fc_edtov = FF_DEF_EDTOV;
  730. phba->fc_ratov = FF_DEF_RATOV;
  731. rc = memcmp(&vport->fc_portname, &sp->portName,
  732. sizeof(vport->fc_portname));
  733. if (rc >= 0) {
  734. /* This side will initiate the PLOGI */
  735. spin_lock_irq(shost->host_lock);
  736. vport->fc_flag |= FC_PT2PT_PLOGI;
  737. spin_unlock_irq(shost->host_lock);
  738. /*
  739. * N_Port ID cannot be 0, set our to LocalID the other
  740. * side will be RemoteID.
  741. */
  742. /* not equal */
  743. if (rc)
  744. vport->fc_myDID = PT2PT_LocalID;
  745. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  746. if (!mbox)
  747. goto fail;
  748. lpfc_config_link(phba, mbox);
  749. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  750. mbox->vport = vport;
  751. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  752. if (rc == MBX_NOT_FINISHED) {
  753. mempool_free(mbox, phba->mbox_mem_pool);
  754. goto fail;
  755. }
  756. /*
  757. * For SLI4, the VFI/VPI are registered AFTER the
  758. * Nport with the higher WWPN sends the PLOGI with
  759. * an assigned NPortId.
  760. */
  761. /* not equal */
  762. if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
  763. lpfc_issue_reg_vfi(vport);
  764. /* Decrement ndlp reference count indicating that ndlp can be
  765. * safely released when other references to it are done.
  766. */
  767. lpfc_nlp_put(ndlp);
  768. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  769. if (!ndlp) {
  770. /*
  771. * Cannot find existing Fabric ndlp, so allocate a
  772. * new one
  773. */
  774. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  775. if (!ndlp)
  776. goto fail;
  777. lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
  778. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  779. ndlp = lpfc_enable_node(vport, ndlp,
  780. NLP_STE_UNUSED_NODE);
  781. if(!ndlp)
  782. goto fail;
  783. }
  784. memcpy(&ndlp->nlp_portname, &sp->portName,
  785. sizeof(struct lpfc_name));
  786. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  787. sizeof(struct lpfc_name));
  788. /* Set state will put ndlp onto node list if not already done */
  789. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  790. spin_lock_irq(shost->host_lock);
  791. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  792. spin_unlock_irq(shost->host_lock);
  793. } else
  794. /* This side will wait for the PLOGI, decrement ndlp reference
  795. * count indicating that ndlp can be released when other
  796. * references to it are done.
  797. */
  798. lpfc_nlp_put(ndlp);
  799. /* If we are pt2pt with another NPort, force NPIV off! */
  800. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  801. spin_lock_irq(shost->host_lock);
  802. vport->fc_flag |= FC_PT2PT;
  803. spin_unlock_irq(shost->host_lock);
  804. /* Start discovery - this should just do CLEAR_LA */
  805. lpfc_disc_start(vport);
  806. return 0;
  807. fail:
  808. return -ENXIO;
  809. }
  810. /**
  811. * lpfc_cmpl_els_flogi - Completion callback function for flogi
  812. * @phba: pointer to lpfc hba data structure.
  813. * @cmdiocb: pointer to lpfc command iocb data structure.
  814. * @rspiocb: pointer to lpfc response iocb data structure.
  815. *
  816. * This routine is the top-level completion callback function for issuing
  817. * a Fabric Login (FLOGI) command. If the response IOCB reported error,
  818. * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
  819. * retry has been made (either immediately or delayed with lpfc_els_retry()
  820. * returning 1), the command IOCB will be released and function returned.
  821. * If the retry attempt has been given up (possibly reach the maximum
  822. * number of retries), one additional decrement of ndlp reference shall be
  823. * invoked before going out after releasing the command IOCB. This will
  824. * actually release the remote node (Note, lpfc_els_free_iocb() will also
  825. * invoke one decrement of ndlp reference count). If no error reported in
  826. * the IOCB status, the command Port ID field is used to determine whether
  827. * this is a point-to-point topology or a fabric topology: if the Port ID
  828. * field is assigned, it is a fabric topology; otherwise, it is a
  829. * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
  830. * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
  831. * specific topology completion conditions.
  832. **/
  833. static void
  834. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  835. struct lpfc_iocbq *rspiocb)
  836. {
  837. struct lpfc_vport *vport = cmdiocb->vport;
  838. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  839. IOCB_t *irsp = &rspiocb->iocb;
  840. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  841. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  842. struct serv_parm *sp;
  843. uint16_t fcf_index;
  844. int rc;
  845. /* Check to see if link went down during discovery */
  846. if (lpfc_els_chk_latt(vport)) {
  847. /* One additional decrement on node reference count to
  848. * trigger the release of the node
  849. */
  850. lpfc_nlp_put(ndlp);
  851. goto out;
  852. }
  853. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  854. "FLOGI cmpl: status:x%x/x%x state:x%x",
  855. irsp->ulpStatus, irsp->un.ulpWord[4],
  856. vport->port_state);
  857. if (irsp->ulpStatus) {
  858. /*
  859. * In case of FIP mode, perform roundrobin FCF failover
  860. * due to new FCF discovery
  861. */
  862. if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
  863. (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
  864. if (phba->link_state < LPFC_LINK_UP)
  865. goto stop_rr_fcf_flogi;
  866. if ((phba->fcoe_cvl_eventtag_attn ==
  867. phba->fcoe_cvl_eventtag) &&
  868. (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  869. (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))
  870. goto stop_rr_fcf_flogi;
  871. else
  872. phba->fcoe_cvl_eventtag_attn =
  873. phba->fcoe_cvl_eventtag;
  874. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
  875. "2611 FLOGI failed on FCF (x%x), "
  876. "status:x%x/x%x, tmo:x%x, perform "
  877. "roundrobin FCF failover\n",
  878. phba->fcf.current_rec.fcf_indx,
  879. irsp->ulpStatus, irsp->un.ulpWord[4],
  880. irsp->ulpTimeout);
  881. lpfc_sli4_set_fcf_flogi_fail(phba,
  882. phba->fcf.current_rec.fcf_indx);
  883. fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
  884. rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
  885. if (rc)
  886. goto out;
  887. }
  888. stop_rr_fcf_flogi:
  889. /* FLOGI failure */
  890. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  891. "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
  892. irsp->ulpStatus, irsp->un.ulpWord[4],
  893. irsp->ulpTimeout);
  894. /* Check for retry */
  895. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  896. goto out;
  897. /* FLOGI failure */
  898. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  899. "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
  900. irsp->ulpStatus, irsp->un.ulpWord[4],
  901. irsp->ulpTimeout);
  902. /* FLOGI failed, so there is no fabric */
  903. spin_lock_irq(shost->host_lock);
  904. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  905. spin_unlock_irq(shost->host_lock);
  906. /* If private loop, then allow max outstanding els to be
  907. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  908. * alpa map would take too long otherwise.
  909. */
  910. if (phba->alpa_map[0] == 0)
  911. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  912. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  913. (!(vport->fc_flag & FC_VFI_REGISTERED) ||
  914. (vport->fc_prevDID != vport->fc_myDID))) {
  915. if (vport->fc_flag & FC_VFI_REGISTERED)
  916. lpfc_sli4_unreg_all_rpis(vport);
  917. lpfc_issue_reg_vfi(vport);
  918. lpfc_nlp_put(ndlp);
  919. goto out;
  920. }
  921. goto flogifail;
  922. }
  923. spin_lock_irq(shost->host_lock);
  924. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  925. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  926. spin_unlock_irq(shost->host_lock);
  927. /*
  928. * The FLogI succeeded. Sync the data for the CPU before
  929. * accessing it.
  930. */
  931. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  932. sp = prsp->virt + sizeof(uint32_t);
  933. /* FLOGI completes successfully */
  934. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  935. "0101 FLOGI completes successfully "
  936. "Data: x%x x%x x%x x%x\n",
  937. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  938. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
  939. if (vport->port_state == LPFC_FLOGI) {
  940. /*
  941. * If Common Service Parameters indicate Nport
  942. * we are point to point, if Fport we are Fabric.
  943. */
  944. if (sp->cmn.fPort)
  945. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
  946. else if (!(phba->hba_flag & HBA_FCOE_MODE))
  947. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  948. else {
  949. lpfc_printf_vlog(vport, KERN_ERR,
  950. LOG_FIP | LOG_ELS,
  951. "2831 FLOGI response with cleared Fabric "
  952. "bit fcf_index 0x%x "
  953. "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
  954. "Fabric Name "
  955. "%02x%02x%02x%02x%02x%02x%02x%02x\n",
  956. phba->fcf.current_rec.fcf_indx,
  957. phba->fcf.current_rec.switch_name[0],
  958. phba->fcf.current_rec.switch_name[1],
  959. phba->fcf.current_rec.switch_name[2],
  960. phba->fcf.current_rec.switch_name[3],
  961. phba->fcf.current_rec.switch_name[4],
  962. phba->fcf.current_rec.switch_name[5],
  963. phba->fcf.current_rec.switch_name[6],
  964. phba->fcf.current_rec.switch_name[7],
  965. phba->fcf.current_rec.fabric_name[0],
  966. phba->fcf.current_rec.fabric_name[1],
  967. phba->fcf.current_rec.fabric_name[2],
  968. phba->fcf.current_rec.fabric_name[3],
  969. phba->fcf.current_rec.fabric_name[4],
  970. phba->fcf.current_rec.fabric_name[5],
  971. phba->fcf.current_rec.fabric_name[6],
  972. phba->fcf.current_rec.fabric_name[7]);
  973. lpfc_nlp_put(ndlp);
  974. spin_lock_irq(&phba->hbalock);
  975. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  976. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  977. spin_unlock_irq(&phba->hbalock);
  978. goto out;
  979. }
  980. if (!rc) {
  981. /* Mark the FCF discovery process done */
  982. if (phba->hba_flag & HBA_FIP_SUPPORT)
  983. lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
  984. LOG_ELS,
  985. "2769 FLOGI to FCF (x%x) "
  986. "completed successfully\n",
  987. phba->fcf.current_rec.fcf_indx);
  988. spin_lock_irq(&phba->hbalock);
  989. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  990. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  991. spin_unlock_irq(&phba->hbalock);
  992. goto out;
  993. }
  994. }
  995. flogifail:
  996. lpfc_nlp_put(ndlp);
  997. if (!lpfc_error_lost_link(irsp)) {
  998. /* FLOGI failed, so just use loop map to make discovery list */
  999. lpfc_disc_list_loopmap(vport);
  1000. /* Start discovery */
  1001. lpfc_disc_start(vport);
  1002. } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1003. ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
  1004. (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
  1005. (phba->link_state != LPFC_CLEAR_LA)) {
  1006. /* If FLOGI failed enable link interrupt. */
  1007. lpfc_issue_clear_la(phba, vport);
  1008. }
  1009. out:
  1010. lpfc_els_free_iocb(phba, cmdiocb);
  1011. }
  1012. /**
  1013. * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
  1014. * @vport: pointer to a host virtual N_Port data structure.
  1015. * @ndlp: pointer to a node-list data structure.
  1016. * @retry: number of retries to the command IOCB.
  1017. *
  1018. * This routine issues a Fabric Login (FLOGI) Request ELS command
  1019. * for a @vport. The initiator service parameters are put into the payload
  1020. * of the FLOGI Request IOCB and the top-level callback function pointer
  1021. * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
  1022. * function field. The lpfc_issue_fabric_iocb routine is invoked to send
  1023. * out FLOGI ELS command with one outstanding fabric IOCB at a time.
  1024. *
  1025. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1026. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1027. * will be stored into the context1 field of the IOCB for the completion
  1028. * callback function to the FLOGI ELS command.
  1029. *
  1030. * Return code
  1031. * 0 - successfully issued flogi iocb for @vport
  1032. * 1 - failed to issue flogi iocb for @vport
  1033. **/
  1034. static int
  1035. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1036. uint8_t retry)
  1037. {
  1038. struct lpfc_hba *phba = vport->phba;
  1039. struct serv_parm *sp;
  1040. IOCB_t *icmd;
  1041. struct lpfc_iocbq *elsiocb;
  1042. struct lpfc_sli_ring *pring;
  1043. uint8_t *pcmd;
  1044. uint16_t cmdsize;
  1045. uint32_t tmo;
  1046. int rc;
  1047. pring = &phba->sli.ring[LPFC_ELS_RING];
  1048. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1049. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1050. ndlp->nlp_DID, ELS_CMD_FLOGI);
  1051. if (!elsiocb)
  1052. return 1;
  1053. icmd = &elsiocb->iocb;
  1054. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1055. /* For FLOGI request, remainder of payload is service parameters */
  1056. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  1057. pcmd += sizeof(uint32_t);
  1058. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1059. sp = (struct serv_parm *) pcmd;
  1060. /* Setup CSPs accordingly for Fabric */
  1061. sp->cmn.e_d_tov = 0;
  1062. sp->cmn.w2.r_a_tov = 0;
  1063. sp->cmn.virtual_fabric_support = 0;
  1064. sp->cls1.classValid = 0;
  1065. sp->cls2.seqDelivery = 1;
  1066. sp->cls3.seqDelivery = 1;
  1067. if (sp->cmn.fcphLow < FC_PH3)
  1068. sp->cmn.fcphLow = FC_PH3;
  1069. if (sp->cmn.fcphHigh < FC_PH3)
  1070. sp->cmn.fcphHigh = FC_PH3;
  1071. if (phba->sli_rev == LPFC_SLI_REV4) {
  1072. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  1073. LPFC_SLI_INTF_IF_TYPE_0) {
  1074. elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
  1075. elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
  1076. /* FLOGI needs to be 3 for WQE FCFI */
  1077. /* Set the fcfi to the fcfi we registered with */
  1078. elsiocb->iocb.ulpContext = phba->fcf.fcfi;
  1079. }
  1080. } else {
  1081. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  1082. sp->cmn.request_multiple_Nport = 1;
  1083. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  1084. icmd->ulpCt_h = 1;
  1085. icmd->ulpCt_l = 0;
  1086. } else
  1087. sp->cmn.request_multiple_Nport = 0;
  1088. }
  1089. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
  1090. icmd->un.elsreq64.myID = 0;
  1091. icmd->un.elsreq64.fl = 1;
  1092. }
  1093. tmo = phba->fc_ratov;
  1094. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  1095. lpfc_set_disctmo(vport);
  1096. phba->fc_ratov = tmo;
  1097. phba->fc_stat.elsXmitFLOGI++;
  1098. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  1099. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1100. "Issue FLOGI: opt:x%x",
  1101. phba->sli3_options, 0, 0);
  1102. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  1103. if (rc == IOCB_ERROR) {
  1104. lpfc_els_free_iocb(phba, elsiocb);
  1105. return 1;
  1106. }
  1107. return 0;
  1108. }
  1109. /**
  1110. * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
  1111. * @phba: pointer to lpfc hba data structure.
  1112. *
  1113. * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
  1114. * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
  1115. * list and issues an abort IOCB commond on each outstanding IOCB that
  1116. * contains a active Fabric_DID ndlp. Note that this function is to issue
  1117. * the abort IOCB command on all the outstanding IOCBs, thus when this
  1118. * function returns, it does not guarantee all the IOCBs are actually aborted.
  1119. *
  1120. * Return code
  1121. * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
  1122. **/
  1123. int
  1124. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  1125. {
  1126. struct lpfc_sli_ring *pring;
  1127. struct lpfc_iocbq *iocb, *next_iocb;
  1128. struct lpfc_nodelist *ndlp;
  1129. IOCB_t *icmd;
  1130. /* Abort outstanding I/O on NPort <nlp_DID> */
  1131. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1132. "0201 Abort outstanding I/O on NPort x%x\n",
  1133. Fabric_DID);
  1134. pring = &phba->sli.ring[LPFC_ELS_RING];
  1135. /*
  1136. * Check the txcmplq for an iocb that matches the nport the driver is
  1137. * searching for.
  1138. */
  1139. spin_lock_irq(&phba->hbalock);
  1140. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1141. icmd = &iocb->iocb;
  1142. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
  1143. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  1144. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  1145. (ndlp->nlp_DID == Fabric_DID))
  1146. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  1147. }
  1148. }
  1149. spin_unlock_irq(&phba->hbalock);
  1150. return 0;
  1151. }
  1152. /**
  1153. * lpfc_initial_flogi - Issue an initial fabric login for a vport
  1154. * @vport: pointer to a host virtual N_Port data structure.
  1155. *
  1156. * This routine issues an initial Fabric Login (FLOGI) for the @vport
  1157. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1158. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1159. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1160. * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
  1161. * is then invoked with the @vport and the ndlp to perform the FLOGI for the
  1162. * @vport.
  1163. *
  1164. * Return code
  1165. * 0 - failed to issue initial flogi for @vport
  1166. * 1 - successfully issued initial flogi for @vport
  1167. **/
  1168. int
  1169. lpfc_initial_flogi(struct lpfc_vport *vport)
  1170. {
  1171. struct lpfc_hba *phba = vport->phba;
  1172. struct lpfc_nodelist *ndlp;
  1173. vport->port_state = LPFC_FLOGI;
  1174. lpfc_set_disctmo(vport);
  1175. /* First look for the Fabric ndlp */
  1176. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1177. if (!ndlp) {
  1178. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1179. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1180. if (!ndlp)
  1181. return 0;
  1182. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  1183. /* Set the node type */
  1184. ndlp->nlp_type |= NLP_FABRIC;
  1185. /* Put ndlp onto node list */
  1186. lpfc_enqueue_node(vport, ndlp);
  1187. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1188. /* re-setup ndlp without removing from node list */
  1189. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1190. if (!ndlp)
  1191. return 0;
  1192. }
  1193. if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
  1194. /* This decrement of reference count to node shall kick off
  1195. * the release of the node.
  1196. */
  1197. lpfc_nlp_put(ndlp);
  1198. return 0;
  1199. }
  1200. return 1;
  1201. }
  1202. /**
  1203. * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
  1204. * @vport: pointer to a host virtual N_Port data structure.
  1205. *
  1206. * This routine issues an initial Fabric Discover (FDISC) for the @vport
  1207. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1208. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1209. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1210. * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
  1211. * is then invoked with the @vport and the ndlp to perform the FDISC for the
  1212. * @vport.
  1213. *
  1214. * Return code
  1215. * 0 - failed to issue initial fdisc for @vport
  1216. * 1 - successfully issued initial fdisc for @vport
  1217. **/
  1218. int
  1219. lpfc_initial_fdisc(struct lpfc_vport *vport)
  1220. {
  1221. struct lpfc_hba *phba = vport->phba;
  1222. struct lpfc_nodelist *ndlp;
  1223. /* First look for the Fabric ndlp */
  1224. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1225. if (!ndlp) {
  1226. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1227. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1228. if (!ndlp)
  1229. return 0;
  1230. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  1231. /* Put ndlp onto node list */
  1232. lpfc_enqueue_node(vport, ndlp);
  1233. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  1234. /* re-setup ndlp without removing from node list */
  1235. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  1236. if (!ndlp)
  1237. return 0;
  1238. }
  1239. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  1240. /* decrement node reference count to trigger the release of
  1241. * the node.
  1242. */
  1243. lpfc_nlp_put(ndlp);
  1244. return 0;
  1245. }
  1246. return 1;
  1247. }
  1248. /**
  1249. * lpfc_more_plogi - Check and issue remaining plogis for a vport
  1250. * @vport: pointer to a host virtual N_Port data structure.
  1251. *
  1252. * This routine checks whether there are more remaining Port Logins
  1253. * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
  1254. * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
  1255. * to issue ELS PLOGIs up to the configured discover threads with the
  1256. * @vport (@vport->cfg_discovery_threads). The function also decrement
  1257. * the @vport's num_disc_node by 1 if it is not already 0.
  1258. **/
  1259. void
  1260. lpfc_more_plogi(struct lpfc_vport *vport)
  1261. {
  1262. int sentplogi;
  1263. if (vport->num_disc_nodes)
  1264. vport->num_disc_nodes--;
  1265. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  1266. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1267. "0232 Continue discovery with %d PLOGIs to go "
  1268. "Data: x%x x%x x%x\n",
  1269. vport->num_disc_nodes, vport->fc_plogi_cnt,
  1270. vport->fc_flag, vport->port_state);
  1271. /* Check to see if there are more PLOGIs to be sent */
  1272. if (vport->fc_flag & FC_NLP_MORE)
  1273. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  1274. sentplogi = lpfc_els_disc_plogi(vport);
  1275. return;
  1276. }
  1277. /**
  1278. * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
  1279. * @phba: pointer to lpfc hba data structure.
  1280. * @prsp: pointer to response IOCB payload.
  1281. * @ndlp: pointer to a node-list data structure.
  1282. *
  1283. * This routine checks and indicates whether the WWPN of an N_Port, retrieved
  1284. * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
  1285. * The following cases are considered N_Port confirmed:
  1286. * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
  1287. * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
  1288. * it does not have WWPN assigned either. If the WWPN is confirmed, the
  1289. * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
  1290. * 1) if there is a node on vport list other than the @ndlp with the same
  1291. * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
  1292. * on that node to release the RPI associated with the node; 2) if there is
  1293. * no node found on vport list with the same WWPN of the N_Port PLOGI logged
  1294. * into, a new node shall be allocated (or activated). In either case, the
  1295. * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
  1296. * be released and the new_ndlp shall be put on to the vport node list and
  1297. * its pointer returned as the confirmed node.
  1298. *
  1299. * Note that before the @ndlp got "released", the keepDID from not-matching
  1300. * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
  1301. * of the @ndlp. This is because the release of @ndlp is actually to put it
  1302. * into an inactive state on the vport node list and the vport node list
  1303. * management algorithm does not allow two node with a same DID.
  1304. *
  1305. * Return code
  1306. * pointer to the PLOGI N_Port @ndlp
  1307. **/
  1308. static struct lpfc_nodelist *
  1309. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  1310. struct lpfc_nodelist *ndlp)
  1311. {
  1312. struct lpfc_vport *vport = ndlp->vport;
  1313. struct lpfc_nodelist *new_ndlp;
  1314. struct lpfc_rport_data *rdata;
  1315. struct fc_rport *rport;
  1316. struct serv_parm *sp;
  1317. uint8_t name[sizeof(struct lpfc_name)];
  1318. uint32_t rc, keepDID = 0;
  1319. int put_node;
  1320. int put_rport;
  1321. struct lpfc_node_rrqs rrq;
  1322. /* Fabric nodes can have the same WWPN so we don't bother searching
  1323. * by WWPN. Just return the ndlp that was given to us.
  1324. */
  1325. if (ndlp->nlp_type & NLP_FABRIC)
  1326. return ndlp;
  1327. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  1328. memset(name, 0, sizeof(struct lpfc_name));
  1329. /* Now we find out if the NPort we are logging into, matches the WWPN
  1330. * we have for that ndlp. If not, we have some work to do.
  1331. */
  1332. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  1333. if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
  1334. return ndlp;
  1335. memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1336. if (!new_ndlp) {
  1337. rc = memcmp(&ndlp->nlp_portname, name,
  1338. sizeof(struct lpfc_name));
  1339. if (!rc)
  1340. return ndlp;
  1341. new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  1342. if (!new_ndlp)
  1343. return ndlp;
  1344. lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
  1345. } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
  1346. rc = memcmp(&ndlp->nlp_portname, name,
  1347. sizeof(struct lpfc_name));
  1348. if (!rc)
  1349. return ndlp;
  1350. new_ndlp = lpfc_enable_node(vport, new_ndlp,
  1351. NLP_STE_UNUSED_NODE);
  1352. if (!new_ndlp)
  1353. return ndlp;
  1354. keepDID = new_ndlp->nlp_DID;
  1355. if (phba->sli_rev == LPFC_SLI_REV4)
  1356. memcpy(&rrq.xri_bitmap,
  1357. &new_ndlp->active_rrqs.xri_bitmap,
  1358. sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1359. } else {
  1360. keepDID = new_ndlp->nlp_DID;
  1361. if (phba->sli_rev == LPFC_SLI_REV4)
  1362. memcpy(&rrq.xri_bitmap,
  1363. &new_ndlp->active_rrqs.xri_bitmap,
  1364. sizeof(new_ndlp->active_rrqs.xri_bitmap));
  1365. }
  1366. lpfc_unreg_rpi(vport, new_ndlp);
  1367. new_ndlp->nlp_DID = ndlp->nlp_DID;
  1368. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  1369. if (phba->sli_rev == LPFC_SLI_REV4)
  1370. memcpy(new_ndlp->active_rrqs.xri_bitmap,
  1371. &ndlp->active_rrqs.xri_bitmap,
  1372. sizeof(ndlp->active_rrqs.xri_bitmap));
  1373. if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
  1374. new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1375. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1376. /* Set state will put new_ndlp on to node list if not already done */
  1377. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  1378. /* Move this back to NPR state */
  1379. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
  1380. /* The new_ndlp is replacing ndlp totally, so we need
  1381. * to put ndlp on UNUSED list and try to free it.
  1382. */
  1383. /* Fix up the rport accordingly */
  1384. rport = ndlp->rport;
  1385. if (rport) {
  1386. rdata = rport->dd_data;
  1387. if (rdata->pnode == ndlp) {
  1388. lpfc_nlp_put(ndlp);
  1389. ndlp->rport = NULL;
  1390. rdata->pnode = lpfc_nlp_get(new_ndlp);
  1391. new_ndlp->rport = rport;
  1392. }
  1393. new_ndlp->nlp_type = ndlp->nlp_type;
  1394. }
  1395. /* We shall actually free the ndlp with both nlp_DID and
  1396. * nlp_portname fields equals 0 to avoid any ndlp on the
  1397. * nodelist never to be used.
  1398. */
  1399. if (ndlp->nlp_DID == 0) {
  1400. spin_lock_irq(&phba->ndlp_lock);
  1401. NLP_SET_FREE_REQ(ndlp);
  1402. spin_unlock_irq(&phba->ndlp_lock);
  1403. }
  1404. /* Two ndlps cannot have the same did on the nodelist */
  1405. ndlp->nlp_DID = keepDID;
  1406. if (phba->sli_rev == LPFC_SLI_REV4)
  1407. memcpy(&ndlp->active_rrqs.xri_bitmap,
  1408. &rrq.xri_bitmap,
  1409. sizeof(ndlp->active_rrqs.xri_bitmap));
  1410. lpfc_drop_node(vport, ndlp);
  1411. }
  1412. else {
  1413. lpfc_unreg_rpi(vport, ndlp);
  1414. /* Two ndlps cannot have the same did */
  1415. ndlp->nlp_DID = keepDID;
  1416. if (phba->sli_rev == LPFC_SLI_REV4)
  1417. memcpy(&ndlp->active_rrqs.xri_bitmap,
  1418. &rrq.xri_bitmap,
  1419. sizeof(ndlp->active_rrqs.xri_bitmap));
  1420. /* Since we are swapping the ndlp passed in with the new one
  1421. * and the did has already been swapped, copy over the
  1422. * state and names.
  1423. */
  1424. memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
  1425. sizeof(struct lpfc_name));
  1426. memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
  1427. sizeof(struct lpfc_name));
  1428. new_ndlp->nlp_state = ndlp->nlp_state;
  1429. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1430. /* Fix up the rport accordingly */
  1431. rport = ndlp->rport;
  1432. if (rport) {
  1433. rdata = rport->dd_data;
  1434. put_node = rdata->pnode != NULL;
  1435. put_rport = ndlp->rport != NULL;
  1436. rdata->pnode = NULL;
  1437. ndlp->rport = NULL;
  1438. if (put_node)
  1439. lpfc_nlp_put(ndlp);
  1440. if (put_rport)
  1441. put_device(&rport->dev);
  1442. }
  1443. }
  1444. return new_ndlp;
  1445. }
  1446. /**
  1447. * lpfc_end_rscn - Check and handle more rscn for a vport
  1448. * @vport: pointer to a host virtual N_Port data structure.
  1449. *
  1450. * This routine checks whether more Registration State Change
  1451. * Notifications (RSCNs) came in while the discovery state machine was in
  1452. * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
  1453. * invoked to handle the additional RSCNs for the @vport. Otherwise, the
  1454. * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
  1455. * handling the RSCNs.
  1456. **/
  1457. void
  1458. lpfc_end_rscn(struct lpfc_vport *vport)
  1459. {
  1460. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1461. if (vport->fc_flag & FC_RSCN_MODE) {
  1462. /*
  1463. * Check to see if more RSCNs came in while we were
  1464. * processing this one.
  1465. */
  1466. if (vport->fc_rscn_id_cnt ||
  1467. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  1468. lpfc_els_handle_rscn(vport);
  1469. else {
  1470. spin_lock_irq(shost->host_lock);
  1471. vport->fc_flag &= ~FC_RSCN_MODE;
  1472. spin_unlock_irq(shost->host_lock);
  1473. }
  1474. }
  1475. }
  1476. /**
  1477. * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
  1478. * @phba: pointer to lpfc hba data structure.
  1479. * @cmdiocb: pointer to lpfc command iocb data structure.
  1480. * @rspiocb: pointer to lpfc response iocb data structure.
  1481. *
  1482. * This routine will call the clear rrq function to free the rrq and
  1483. * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
  1484. * exist then the clear_rrq is still called because the rrq needs to
  1485. * be freed.
  1486. **/
  1487. static void
  1488. lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1489. struct lpfc_iocbq *rspiocb)
  1490. {
  1491. struct lpfc_vport *vport = cmdiocb->vport;
  1492. IOCB_t *irsp;
  1493. struct lpfc_nodelist *ndlp;
  1494. struct lpfc_node_rrq *rrq;
  1495. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1496. rrq = cmdiocb->context_un.rrq;
  1497. cmdiocb->context_un.rsp_iocb = rspiocb;
  1498. irsp = &rspiocb->iocb;
  1499. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1500. "RRQ cmpl: status:x%x/x%x did:x%x",
  1501. irsp->ulpStatus, irsp->un.ulpWord[4],
  1502. irsp->un.elsreq64.remoteID);
  1503. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1504. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
  1505. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1506. "2882 RRQ completes to NPort x%x "
  1507. "with no ndlp. Data: x%x x%x x%x\n",
  1508. irsp->un.elsreq64.remoteID,
  1509. irsp->ulpStatus, irsp->un.ulpWord[4],
  1510. irsp->ulpIoTag);
  1511. goto out;
  1512. }
  1513. /* rrq completes to NPort <nlp_DID> */
  1514. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1515. "2880 RRQ completes to NPort x%x "
  1516. "Data: x%x x%x x%x x%x x%x\n",
  1517. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1518. irsp->ulpTimeout, rrq->xritag, rrq->rxid);
  1519. if (irsp->ulpStatus) {
  1520. /* Check for retry */
  1521. /* RRQ failed Don't print the vport to vport rjts */
  1522. if (irsp->ulpStatus != IOSTAT_LS_RJT ||
  1523. (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
  1524. ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
  1525. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1526. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1527. "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
  1528. ndlp->nlp_DID, irsp->ulpStatus,
  1529. irsp->un.ulpWord[4]);
  1530. }
  1531. out:
  1532. if (rrq)
  1533. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  1534. lpfc_els_free_iocb(phba, cmdiocb);
  1535. return;
  1536. }
  1537. /**
  1538. * lpfc_cmpl_els_plogi - Completion callback function for plogi
  1539. * @phba: pointer to lpfc hba data structure.
  1540. * @cmdiocb: pointer to lpfc command iocb data structure.
  1541. * @rspiocb: pointer to lpfc response iocb data structure.
  1542. *
  1543. * This routine is the completion callback function for issuing the Port
  1544. * Login (PLOGI) command. For PLOGI completion, there must be an active
  1545. * ndlp on the vport node list that matches the remote node ID from the
  1546. * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
  1547. * ignored and command IOCB released. The PLOGI response IOCB status is
  1548. * checked for error conditons. If there is error status reported, PLOGI
  1549. * retry shall be attempted by invoking the lpfc_els_retry() routine.
  1550. * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
  1551. * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
  1552. * (DSM) is set for this PLOGI completion. Finally, it checks whether
  1553. * there are additional N_Port nodes with the vport that need to perform
  1554. * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
  1555. * PLOGIs.
  1556. **/
  1557. static void
  1558. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1559. struct lpfc_iocbq *rspiocb)
  1560. {
  1561. struct lpfc_vport *vport = cmdiocb->vport;
  1562. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1563. IOCB_t *irsp;
  1564. struct lpfc_nodelist *ndlp;
  1565. struct lpfc_dmabuf *prsp;
  1566. int disc, rc, did, type;
  1567. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1568. cmdiocb->context_un.rsp_iocb = rspiocb;
  1569. irsp = &rspiocb->iocb;
  1570. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1571. "PLOGI cmpl: status:x%x/x%x did:x%x",
  1572. irsp->ulpStatus, irsp->un.ulpWord[4],
  1573. irsp->un.elsreq64.remoteID);
  1574. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  1575. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  1576. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1577. "0136 PLOGI completes to NPort x%x "
  1578. "with no ndlp. Data: x%x x%x x%x\n",
  1579. irsp->un.elsreq64.remoteID,
  1580. irsp->ulpStatus, irsp->un.ulpWord[4],
  1581. irsp->ulpIoTag);
  1582. goto out;
  1583. }
  1584. /* Since ndlp can be freed in the disc state machine, note if this node
  1585. * is being used during discovery.
  1586. */
  1587. spin_lock_irq(shost->host_lock);
  1588. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1589. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1590. spin_unlock_irq(shost->host_lock);
  1591. rc = 0;
  1592. /* PLOGI completes to NPort <nlp_DID> */
  1593. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1594. "0102 PLOGI completes to NPort x%x "
  1595. "Data: x%x x%x x%x x%x x%x\n",
  1596. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1597. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  1598. /* Check to see if link went down during discovery */
  1599. if (lpfc_els_chk_latt(vport)) {
  1600. spin_lock_irq(shost->host_lock);
  1601. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1602. spin_unlock_irq(shost->host_lock);
  1603. goto out;
  1604. }
  1605. /* ndlp could be freed in DSM, save these values now */
  1606. type = ndlp->nlp_type;
  1607. did = ndlp->nlp_DID;
  1608. if (irsp->ulpStatus) {
  1609. /* Check for retry */
  1610. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1611. /* ELS command is being retried */
  1612. if (disc) {
  1613. spin_lock_irq(shost->host_lock);
  1614. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1615. spin_unlock_irq(shost->host_lock);
  1616. }
  1617. goto out;
  1618. }
  1619. /* PLOGI failed Don't print the vport to vport rjts */
  1620. if (irsp->ulpStatus != IOSTAT_LS_RJT ||
  1621. (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
  1622. ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
  1623. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1624. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1625. "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
  1626. ndlp->nlp_DID, irsp->ulpStatus,
  1627. irsp->un.ulpWord[4]);
  1628. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1629. if (lpfc_error_lost_link(irsp))
  1630. rc = NLP_STE_FREED_NODE;
  1631. else
  1632. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1633. NLP_EVT_CMPL_PLOGI);
  1634. } else {
  1635. /* Good status, call state machine */
  1636. prsp = list_entry(((struct lpfc_dmabuf *)
  1637. cmdiocb->context2)->list.next,
  1638. struct lpfc_dmabuf, list);
  1639. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  1640. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1641. NLP_EVT_CMPL_PLOGI);
  1642. }
  1643. if (disc && vport->num_disc_nodes) {
  1644. /* Check to see if there are more PLOGIs to be sent */
  1645. lpfc_more_plogi(vport);
  1646. if (vport->num_disc_nodes == 0) {
  1647. spin_lock_irq(shost->host_lock);
  1648. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1649. spin_unlock_irq(shost->host_lock);
  1650. lpfc_can_disctmo(vport);
  1651. lpfc_end_rscn(vport);
  1652. }
  1653. }
  1654. out:
  1655. lpfc_els_free_iocb(phba, cmdiocb);
  1656. return;
  1657. }
  1658. /**
  1659. * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
  1660. * @vport: pointer to a host virtual N_Port data structure.
  1661. * @did: destination port identifier.
  1662. * @retry: number of retries to the command IOCB.
  1663. *
  1664. * This routine issues a Port Login (PLOGI) command to a remote N_Port
  1665. * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
  1666. * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
  1667. * This routine constructs the proper feilds of the PLOGI IOCB and invokes
  1668. * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
  1669. *
  1670. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1671. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1672. * will be stored into the context1 field of the IOCB for the completion
  1673. * callback function to the PLOGI ELS command.
  1674. *
  1675. * Return code
  1676. * 0 - Successfully issued a plogi for @vport
  1677. * 1 - failed to issue a plogi for @vport
  1678. **/
  1679. int
  1680. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  1681. {
  1682. struct lpfc_hba *phba = vport->phba;
  1683. struct serv_parm *sp;
  1684. IOCB_t *icmd;
  1685. struct lpfc_nodelist *ndlp;
  1686. struct lpfc_iocbq *elsiocb;
  1687. struct lpfc_sli *psli;
  1688. uint8_t *pcmd;
  1689. uint16_t cmdsize;
  1690. int ret;
  1691. psli = &phba->sli;
  1692. ndlp = lpfc_findnode_did(vport, did);
  1693. if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
  1694. ndlp = NULL;
  1695. /* If ndlp is not NULL, we will bump the reference count on it */
  1696. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1697. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  1698. ELS_CMD_PLOGI);
  1699. if (!elsiocb)
  1700. return 1;
  1701. icmd = &elsiocb->iocb;
  1702. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1703. /* For PLOGI request, remainder of payload is service parameters */
  1704. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  1705. pcmd += sizeof(uint32_t);
  1706. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1707. sp = (struct serv_parm *) pcmd;
  1708. /*
  1709. * If we are a N-port connected to a Fabric, fix-up paramm's so logins
  1710. * to device on remote loops work.
  1711. */
  1712. if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
  1713. sp->cmn.altBbCredit = 1;
  1714. if (sp->cmn.fcphLow < FC_PH_4_3)
  1715. sp->cmn.fcphLow = FC_PH_4_3;
  1716. if (sp->cmn.fcphHigh < FC_PH3)
  1717. sp->cmn.fcphHigh = FC_PH3;
  1718. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1719. "Issue PLOGI: did:x%x",
  1720. did, 0, 0);
  1721. phba->fc_stat.elsXmitPLOGI++;
  1722. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  1723. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  1724. if (ret == IOCB_ERROR) {
  1725. lpfc_els_free_iocb(phba, elsiocb);
  1726. return 1;
  1727. }
  1728. return 0;
  1729. }
  1730. /**
  1731. * lpfc_cmpl_els_prli - Completion callback function for prli
  1732. * @phba: pointer to lpfc hba data structure.
  1733. * @cmdiocb: pointer to lpfc command iocb data structure.
  1734. * @rspiocb: pointer to lpfc response iocb data structure.
  1735. *
  1736. * This routine is the completion callback function for a Process Login
  1737. * (PRLI) ELS command. The PRLI response IOCB status is checked for error
  1738. * status. If there is error status reported, PRLI retry shall be attempted
  1739. * by invoking the lpfc_els_retry() routine. Otherwise, the state
  1740. * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
  1741. * ndlp to mark the PRLI completion.
  1742. **/
  1743. static void
  1744. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1745. struct lpfc_iocbq *rspiocb)
  1746. {
  1747. struct lpfc_vport *vport = cmdiocb->vport;
  1748. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1749. IOCB_t *irsp;
  1750. struct lpfc_sli *psli;
  1751. struct lpfc_nodelist *ndlp;
  1752. psli = &phba->sli;
  1753. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1754. cmdiocb->context_un.rsp_iocb = rspiocb;
  1755. irsp = &(rspiocb->iocb);
  1756. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1757. spin_lock_irq(shost->host_lock);
  1758. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1759. spin_unlock_irq(shost->host_lock);
  1760. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1761. "PRLI cmpl: status:x%x/x%x did:x%x",
  1762. irsp->ulpStatus, irsp->un.ulpWord[4],
  1763. ndlp->nlp_DID);
  1764. /* PRLI completes to NPort <nlp_DID> */
  1765. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1766. "0103 PRLI completes to NPort x%x "
  1767. "Data: x%x x%x x%x x%x\n",
  1768. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1769. irsp->ulpTimeout, vport->num_disc_nodes);
  1770. vport->fc_prli_sent--;
  1771. /* Check to see if link went down during discovery */
  1772. if (lpfc_els_chk_latt(vport))
  1773. goto out;
  1774. if (irsp->ulpStatus) {
  1775. /* Check for retry */
  1776. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1777. /* ELS command is being retried */
  1778. goto out;
  1779. }
  1780. /* PRLI failed */
  1781. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1782. "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
  1783. ndlp->nlp_DID, irsp->ulpStatus,
  1784. irsp->un.ulpWord[4]);
  1785. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1786. if (lpfc_error_lost_link(irsp))
  1787. goto out;
  1788. else
  1789. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1790. NLP_EVT_CMPL_PRLI);
  1791. } else
  1792. /* Good status, call state machine */
  1793. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1794. NLP_EVT_CMPL_PRLI);
  1795. out:
  1796. lpfc_els_free_iocb(phba, cmdiocb);
  1797. return;
  1798. }
  1799. /**
  1800. * lpfc_issue_els_prli - Issue a prli iocb command for a vport
  1801. * @vport: pointer to a host virtual N_Port data structure.
  1802. * @ndlp: pointer to a node-list data structure.
  1803. * @retry: number of retries to the command IOCB.
  1804. *
  1805. * This routine issues a Process Login (PRLI) ELS command for the
  1806. * @vport. The PRLI service parameters are set up in the payload of the
  1807. * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
  1808. * is put to the IOCB completion callback func field before invoking the
  1809. * routine lpfc_sli_issue_iocb() to send out PRLI command.
  1810. *
  1811. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  1812. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  1813. * will be stored into the context1 field of the IOCB for the completion
  1814. * callback function to the PRLI ELS command.
  1815. *
  1816. * Return code
  1817. * 0 - successfully issued prli iocb command for @vport
  1818. * 1 - failed to issue prli iocb command for @vport
  1819. **/
  1820. int
  1821. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1822. uint8_t retry)
  1823. {
  1824. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1825. struct lpfc_hba *phba = vport->phba;
  1826. PRLI *npr;
  1827. IOCB_t *icmd;
  1828. struct lpfc_iocbq *elsiocb;
  1829. uint8_t *pcmd;
  1830. uint16_t cmdsize;
  1831. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  1832. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1833. ndlp->nlp_DID, ELS_CMD_PRLI);
  1834. if (!elsiocb)
  1835. return 1;
  1836. icmd = &elsiocb->iocb;
  1837. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1838. /* For PRLI request, remainder of payload is service parameters */
  1839. memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
  1840. *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
  1841. pcmd += sizeof(uint32_t);
  1842. /* For PRLI, remainder of payload is PRLI parameter page */
  1843. npr = (PRLI *) pcmd;
  1844. /*
  1845. * If our firmware version is 3.20 or later,
  1846. * set the following bits for FC-TAPE support.
  1847. */
  1848. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  1849. npr->ConfmComplAllowed = 1;
  1850. npr->Retry = 1;
  1851. npr->TaskRetryIdReq = 1;
  1852. }
  1853. npr->estabImagePair = 1;
  1854. npr->readXferRdyDis = 1;
  1855. /* For FCP support */
  1856. npr->prliType = PRLI_FCP_TYPE;
  1857. npr->initiatorFunc = 1;
  1858. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1859. "Issue PRLI: did:x%x",
  1860. ndlp->nlp_DID, 0, 0);
  1861. phba->fc_stat.elsXmitPRLI++;
  1862. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  1863. spin_lock_irq(shost->host_lock);
  1864. ndlp->nlp_flag |= NLP_PRLI_SND;
  1865. spin_unlock_irq(shost->host_lock);
  1866. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  1867. IOCB_ERROR) {
  1868. spin_lock_irq(shost->host_lock);
  1869. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  1870. spin_unlock_irq(shost->host_lock);
  1871. lpfc_els_free_iocb(phba, elsiocb);
  1872. return 1;
  1873. }
  1874. vport->fc_prli_sent++;
  1875. return 0;
  1876. }
  1877. /**
  1878. * lpfc_rscn_disc - Perform rscn discovery for a vport
  1879. * @vport: pointer to a host virtual N_Port data structure.
  1880. *
  1881. * This routine performs Registration State Change Notification (RSCN)
  1882. * discovery for a @vport. If the @vport's node port recovery count is not
  1883. * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
  1884. * the nodes that need recovery. If none of the PLOGI were needed through
  1885. * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
  1886. * invoked to check and handle possible more RSCN came in during the period
  1887. * of processing the current ones.
  1888. **/
  1889. static void
  1890. lpfc_rscn_disc(struct lpfc_vport *vport)
  1891. {
  1892. lpfc_can_disctmo(vport);
  1893. /* RSCN discovery */
  1894. /* go thru NPR nodes and issue ELS PLOGIs */
  1895. if (vport->fc_npr_cnt)
  1896. if (lpfc_els_disc_plogi(vport))
  1897. return;
  1898. lpfc_end_rscn(vport);
  1899. }
  1900. /**
  1901. * lpfc_adisc_done - Complete the adisc phase of discovery
  1902. * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
  1903. *
  1904. * This function is called when the final ADISC is completed during discovery.
  1905. * This function handles clearing link attention or issuing reg_vpi depending
  1906. * on whether npiv is enabled. This function also kicks off the PLOGI phase of
  1907. * discovery.
  1908. * This function is called with no locks held.
  1909. **/
  1910. static void
  1911. lpfc_adisc_done(struct lpfc_vport *vport)
  1912. {
  1913. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1914. struct lpfc_hba *phba = vport->phba;
  1915. /*
  1916. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  1917. * and continue discovery.
  1918. */
  1919. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1920. !(vport->fc_flag & FC_RSCN_MODE) &&
  1921. (phba->sli_rev < LPFC_SLI_REV4)) {
  1922. lpfc_issue_reg_vpi(phba, vport);
  1923. return;
  1924. }
  1925. /*
  1926. * For SLI2, we need to set port_state to READY
  1927. * and continue discovery.
  1928. */
  1929. if (vport->port_state < LPFC_VPORT_READY) {
  1930. /* If we get here, there is nothing to ADISC */
  1931. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1932. lpfc_issue_clear_la(phba, vport);
  1933. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  1934. vport->num_disc_nodes = 0;
  1935. /* go thru NPR list, issue ELS PLOGIs */
  1936. if (vport->fc_npr_cnt)
  1937. lpfc_els_disc_plogi(vport);
  1938. if (!vport->num_disc_nodes) {
  1939. spin_lock_irq(shost->host_lock);
  1940. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1941. spin_unlock_irq(shost->host_lock);
  1942. lpfc_can_disctmo(vport);
  1943. lpfc_end_rscn(vport);
  1944. }
  1945. }
  1946. vport->port_state = LPFC_VPORT_READY;
  1947. } else
  1948. lpfc_rscn_disc(vport);
  1949. }
  1950. /**
  1951. * lpfc_more_adisc - Issue more adisc as needed
  1952. * @vport: pointer to a host virtual N_Port data structure.
  1953. *
  1954. * This routine determines whether there are more ndlps on a @vport
  1955. * node list need to have Address Discover (ADISC) issued. If so, it will
  1956. * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
  1957. * remaining nodes which need to have ADISC sent.
  1958. **/
  1959. void
  1960. lpfc_more_adisc(struct lpfc_vport *vport)
  1961. {
  1962. int sentadisc;
  1963. if (vport->num_disc_nodes)
  1964. vport->num_disc_nodes--;
  1965. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  1966. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1967. "0210 Continue discovery with %d ADISCs to go "
  1968. "Data: x%x x%x x%x\n",
  1969. vport->num_disc_nodes, vport->fc_adisc_cnt,
  1970. vport->fc_flag, vport->port_state);
  1971. /* Check to see if there are more ADISCs to be sent */
  1972. if (vport->fc_flag & FC_NLP_MORE) {
  1973. lpfc_set_disctmo(vport);
  1974. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  1975. sentadisc = lpfc_els_disc_adisc(vport);
  1976. }
  1977. if (!vport->num_disc_nodes)
  1978. lpfc_adisc_done(vport);
  1979. return;
  1980. }
  1981. /**
  1982. * lpfc_cmpl_els_adisc - Completion callback function for adisc
  1983. * @phba: pointer to lpfc hba data structure.
  1984. * @cmdiocb: pointer to lpfc command iocb data structure.
  1985. * @rspiocb: pointer to lpfc response iocb data structure.
  1986. *
  1987. * This routine is the completion function for issuing the Address Discover
  1988. * (ADISC) command. It first checks to see whether link went down during
  1989. * the discovery process. If so, the node will be marked as node port
  1990. * recovery for issuing discover IOCB by the link attention handler and
  1991. * exit. Otherwise, the response status is checked. If error was reported
  1992. * in the response status, the ADISC command shall be retried by invoking
  1993. * the lpfc_els_retry() routine. Otherwise, if no error was reported in
  1994. * the response status, the state machine is invoked to set transition
  1995. * with respect to NLP_EVT_CMPL_ADISC event.
  1996. **/
  1997. static void
  1998. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1999. struct lpfc_iocbq *rspiocb)
  2000. {
  2001. struct lpfc_vport *vport = cmdiocb->vport;
  2002. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2003. IOCB_t *irsp;
  2004. struct lpfc_nodelist *ndlp;
  2005. int disc;
  2006. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2007. cmdiocb->context_un.rsp_iocb = rspiocb;
  2008. irsp = &(rspiocb->iocb);
  2009. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2010. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2011. "ADISC cmpl: status:x%x/x%x did:x%x",
  2012. irsp->ulpStatus, irsp->un.ulpWord[4],
  2013. ndlp->nlp_DID);
  2014. /* Since ndlp can be freed in the disc state machine, note if this node
  2015. * is being used during discovery.
  2016. */
  2017. spin_lock_irq(shost->host_lock);
  2018. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  2019. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  2020. spin_unlock_irq(shost->host_lock);
  2021. /* ADISC completes to NPort <nlp_DID> */
  2022. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2023. "0104 ADISC completes to NPort x%x "
  2024. "Data: x%x x%x x%x x%x x%x\n",
  2025. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2026. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  2027. /* Check to see if link went down during discovery */
  2028. if (lpfc_els_chk_latt(vport)) {
  2029. spin_lock_irq(shost->host_lock);
  2030. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2031. spin_unlock_irq(shost->host_lock);
  2032. goto out;
  2033. }
  2034. if (irsp->ulpStatus) {
  2035. /* Check for retry */
  2036. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2037. /* ELS command is being retried */
  2038. if (disc) {
  2039. spin_lock_irq(shost->host_lock);
  2040. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2041. spin_unlock_irq(shost->host_lock);
  2042. lpfc_set_disctmo(vport);
  2043. }
  2044. goto out;
  2045. }
  2046. /* ADISC failed */
  2047. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2048. "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
  2049. ndlp->nlp_DID, irsp->ulpStatus,
  2050. irsp->un.ulpWord[4]);
  2051. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2052. if (!lpfc_error_lost_link(irsp))
  2053. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2054. NLP_EVT_CMPL_ADISC);
  2055. } else
  2056. /* Good status, call state machine */
  2057. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2058. NLP_EVT_CMPL_ADISC);
  2059. /* Check to see if there are more ADISCs to be sent */
  2060. if (disc && vport->num_disc_nodes)
  2061. lpfc_more_adisc(vport);
  2062. out:
  2063. lpfc_els_free_iocb(phba, cmdiocb);
  2064. return;
  2065. }
  2066. /**
  2067. * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
  2068. * @vport: pointer to a virtual N_Port data structure.
  2069. * @ndlp: pointer to a node-list data structure.
  2070. * @retry: number of retries to the command IOCB.
  2071. *
  2072. * This routine issues an Address Discover (ADISC) for an @ndlp on a
  2073. * @vport. It prepares the payload of the ADISC ELS command, updates the
  2074. * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
  2075. * to issue the ADISC ELS command.
  2076. *
  2077. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2078. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2079. * will be stored into the context1 field of the IOCB for the completion
  2080. * callback function to the ADISC ELS command.
  2081. *
  2082. * Return code
  2083. * 0 - successfully issued adisc
  2084. * 1 - failed to issue adisc
  2085. **/
  2086. int
  2087. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2088. uint8_t retry)
  2089. {
  2090. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2091. struct lpfc_hba *phba = vport->phba;
  2092. ADISC *ap;
  2093. IOCB_t *icmd;
  2094. struct lpfc_iocbq *elsiocb;
  2095. uint8_t *pcmd;
  2096. uint16_t cmdsize;
  2097. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  2098. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2099. ndlp->nlp_DID, ELS_CMD_ADISC);
  2100. if (!elsiocb)
  2101. return 1;
  2102. icmd = &elsiocb->iocb;
  2103. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2104. /* For ADISC request, remainder of payload is service parameters */
  2105. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  2106. pcmd += sizeof(uint32_t);
  2107. /* Fill in ADISC payload */
  2108. ap = (ADISC *) pcmd;
  2109. ap->hardAL_PA = phba->fc_pref_ALPA;
  2110. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2111. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2112. ap->DID = be32_to_cpu(vport->fc_myDID);
  2113. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2114. "Issue ADISC: did:x%x",
  2115. ndlp->nlp_DID, 0, 0);
  2116. phba->fc_stat.elsXmitADISC++;
  2117. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  2118. spin_lock_irq(shost->host_lock);
  2119. ndlp->nlp_flag |= NLP_ADISC_SND;
  2120. spin_unlock_irq(shost->host_lock);
  2121. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2122. IOCB_ERROR) {
  2123. spin_lock_irq(shost->host_lock);
  2124. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  2125. spin_unlock_irq(shost->host_lock);
  2126. lpfc_els_free_iocb(phba, elsiocb);
  2127. return 1;
  2128. }
  2129. return 0;
  2130. }
  2131. /**
  2132. * lpfc_cmpl_els_logo - Completion callback function for logo
  2133. * @phba: pointer to lpfc hba data structure.
  2134. * @cmdiocb: pointer to lpfc command iocb data structure.
  2135. * @rspiocb: pointer to lpfc response iocb data structure.
  2136. *
  2137. * This routine is the completion function for issuing the ELS Logout (LOGO)
  2138. * command. If no error status was reported from the LOGO response, the
  2139. * state machine of the associated ndlp shall be invoked for transition with
  2140. * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
  2141. * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
  2142. **/
  2143. static void
  2144. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2145. struct lpfc_iocbq *rspiocb)
  2146. {
  2147. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2148. struct lpfc_vport *vport = ndlp->vport;
  2149. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2150. IOCB_t *irsp;
  2151. struct lpfc_sli *psli;
  2152. struct lpfcMboxq *mbox;
  2153. psli = &phba->sli;
  2154. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2155. cmdiocb->context_un.rsp_iocb = rspiocb;
  2156. irsp = &(rspiocb->iocb);
  2157. spin_lock_irq(shost->host_lock);
  2158. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2159. spin_unlock_irq(shost->host_lock);
  2160. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2161. "LOGO cmpl: status:x%x/x%x did:x%x",
  2162. irsp->ulpStatus, irsp->un.ulpWord[4],
  2163. ndlp->nlp_DID);
  2164. /* LOGO completes to NPort <nlp_DID> */
  2165. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2166. "0105 LOGO completes to NPort x%x "
  2167. "Data: x%x x%x x%x x%x\n",
  2168. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  2169. irsp->ulpTimeout, vport->num_disc_nodes);
  2170. /* Check to see if link went down during discovery */
  2171. if (lpfc_els_chk_latt(vport))
  2172. goto out;
  2173. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  2174. /* NLP_EVT_DEVICE_RM should unregister the RPI
  2175. * which should abort all outstanding IOs.
  2176. */
  2177. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2178. NLP_EVT_DEVICE_RM);
  2179. goto out;
  2180. }
  2181. if (irsp->ulpStatus) {
  2182. /* Check for retry */
  2183. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  2184. /* ELS command is being retried */
  2185. goto out;
  2186. /* LOGO failed */
  2187. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2188. "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
  2189. ndlp->nlp_DID, irsp->ulpStatus,
  2190. irsp->un.ulpWord[4]);
  2191. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2192. if (lpfc_error_lost_link(irsp))
  2193. goto out;
  2194. else
  2195. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2196. NLP_EVT_CMPL_LOGO);
  2197. } else
  2198. /* Good status, call state machine.
  2199. * This will unregister the rpi if needed.
  2200. */
  2201. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2202. NLP_EVT_CMPL_LOGO);
  2203. out:
  2204. lpfc_els_free_iocb(phba, cmdiocb);
  2205. /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
  2206. if ((vport->fc_flag & FC_PT2PT) &&
  2207. !(vport->fc_flag & FC_PT2PT_PLOGI)) {
  2208. phba->pport->fc_myDID = 0;
  2209. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2210. if (mbox) {
  2211. lpfc_config_link(phba, mbox);
  2212. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2213. mbox->vport = vport;
  2214. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
  2215. MBX_NOT_FINISHED) {
  2216. mempool_free(mbox, phba->mbox_mem_pool);
  2217. }
  2218. }
  2219. }
  2220. return;
  2221. }
  2222. /**
  2223. * lpfc_issue_els_logo - Issue a logo to an node on a vport
  2224. * @vport: pointer to a virtual N_Port data structure.
  2225. * @ndlp: pointer to a node-list data structure.
  2226. * @retry: number of retries to the command IOCB.
  2227. *
  2228. * This routine constructs and issues an ELS Logout (LOGO) iocb command
  2229. * to a remote node, referred by an @ndlp on a @vport. It constructs the
  2230. * payload of the IOCB, properly sets up the @ndlp state, and invokes the
  2231. * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
  2232. *
  2233. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2234. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2235. * will be stored into the context1 field of the IOCB for the completion
  2236. * callback function to the LOGO ELS command.
  2237. *
  2238. * Return code
  2239. * 0 - successfully issued logo
  2240. * 1 - failed to issue logo
  2241. **/
  2242. int
  2243. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2244. uint8_t retry)
  2245. {
  2246. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2247. struct lpfc_hba *phba = vport->phba;
  2248. IOCB_t *icmd;
  2249. struct lpfc_iocbq *elsiocb;
  2250. uint8_t *pcmd;
  2251. uint16_t cmdsize;
  2252. int rc;
  2253. spin_lock_irq(shost->host_lock);
  2254. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  2255. spin_unlock_irq(shost->host_lock);
  2256. return 0;
  2257. }
  2258. spin_unlock_irq(shost->host_lock);
  2259. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  2260. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2261. ndlp->nlp_DID, ELS_CMD_LOGO);
  2262. if (!elsiocb)
  2263. return 1;
  2264. icmd = &elsiocb->iocb;
  2265. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2266. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  2267. pcmd += sizeof(uint32_t);
  2268. /* Fill in LOGO payload */
  2269. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  2270. pcmd += sizeof(uint32_t);
  2271. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  2272. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2273. "Issue LOGO: did:x%x",
  2274. ndlp->nlp_DID, 0, 0);
  2275. phba->fc_stat.elsXmitLOGO++;
  2276. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  2277. spin_lock_irq(shost->host_lock);
  2278. ndlp->nlp_flag |= NLP_LOGO_SND;
  2279. spin_unlock_irq(shost->host_lock);
  2280. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  2281. if (rc == IOCB_ERROR) {
  2282. spin_lock_irq(shost->host_lock);
  2283. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2284. spin_unlock_irq(shost->host_lock);
  2285. lpfc_els_free_iocb(phba, elsiocb);
  2286. return 1;
  2287. }
  2288. return 0;
  2289. }
  2290. /**
  2291. * lpfc_cmpl_els_cmd - Completion callback function for generic els command
  2292. * @phba: pointer to lpfc hba data structure.
  2293. * @cmdiocb: pointer to lpfc command iocb data structure.
  2294. * @rspiocb: pointer to lpfc response iocb data structure.
  2295. *
  2296. * This routine is a generic completion callback function for ELS commands.
  2297. * Specifically, it is the callback function which does not need to perform
  2298. * any command specific operations. It is currently used by the ELS command
  2299. * issuing routines for the ELS State Change Request (SCR),
  2300. * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
  2301. * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
  2302. * certain debug loggings, this callback function simply invokes the
  2303. * lpfc_els_chk_latt() routine to check whether link went down during the
  2304. * discovery process.
  2305. **/
  2306. static void
  2307. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2308. struct lpfc_iocbq *rspiocb)
  2309. {
  2310. struct lpfc_vport *vport = cmdiocb->vport;
  2311. IOCB_t *irsp;
  2312. irsp = &rspiocb->iocb;
  2313. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2314. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  2315. irsp->ulpStatus, irsp->un.ulpWord[4],
  2316. irsp->un.elsreq64.remoteID);
  2317. /* ELS cmd tag <ulpIoTag> completes */
  2318. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2319. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  2320. irsp->ulpIoTag, irsp->ulpStatus,
  2321. irsp->un.ulpWord[4], irsp->ulpTimeout);
  2322. /* Check to see if link went down during discovery */
  2323. lpfc_els_chk_latt(vport);
  2324. lpfc_els_free_iocb(phba, cmdiocb);
  2325. return;
  2326. }
  2327. /**
  2328. * lpfc_issue_els_scr - Issue a scr to an node on a vport
  2329. * @vport: pointer to a host virtual N_Port data structure.
  2330. * @nportid: N_Port identifier to the remote node.
  2331. * @retry: number of retries to the command IOCB.
  2332. *
  2333. * This routine issues a State Change Request (SCR) to a fabric node
  2334. * on a @vport. The remote node @nportid is passed into the function. It
  2335. * first search the @vport node list to find the matching ndlp. If no such
  2336. * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
  2337. * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
  2338. * routine is invoked to send the SCR IOCB.
  2339. *
  2340. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2341. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2342. * will be stored into the context1 field of the IOCB for the completion
  2343. * callback function to the SCR ELS command.
  2344. *
  2345. * Return code
  2346. * 0 - Successfully issued scr command
  2347. * 1 - Failed to issue scr command
  2348. **/
  2349. int
  2350. lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  2351. {
  2352. struct lpfc_hba *phba = vport->phba;
  2353. IOCB_t *icmd;
  2354. struct lpfc_iocbq *elsiocb;
  2355. struct lpfc_sli *psli;
  2356. uint8_t *pcmd;
  2357. uint16_t cmdsize;
  2358. struct lpfc_nodelist *ndlp;
  2359. psli = &phba->sli;
  2360. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  2361. ndlp = lpfc_findnode_did(vport, nportid);
  2362. if (!ndlp) {
  2363. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2364. if (!ndlp)
  2365. return 1;
  2366. lpfc_nlp_init(vport, ndlp, nportid);
  2367. lpfc_enqueue_node(vport, ndlp);
  2368. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2369. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  2370. if (!ndlp)
  2371. return 1;
  2372. }
  2373. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2374. ndlp->nlp_DID, ELS_CMD_SCR);
  2375. if (!elsiocb) {
  2376. /* This will trigger the release of the node just
  2377. * allocated
  2378. */
  2379. lpfc_nlp_put(ndlp);
  2380. return 1;
  2381. }
  2382. icmd = &elsiocb->iocb;
  2383. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2384. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  2385. pcmd += sizeof(uint32_t);
  2386. /* For SCR, remainder of payload is SCR parameter page */
  2387. memset(pcmd, 0, sizeof(SCR));
  2388. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  2389. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2390. "Issue SCR: did:x%x",
  2391. ndlp->nlp_DID, 0, 0);
  2392. phba->fc_stat.elsXmitSCR++;
  2393. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  2394. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2395. IOCB_ERROR) {
  2396. /* The additional lpfc_nlp_put will cause the following
  2397. * lpfc_els_free_iocb routine to trigger the rlease of
  2398. * the node.
  2399. */
  2400. lpfc_nlp_put(ndlp);
  2401. lpfc_els_free_iocb(phba, elsiocb);
  2402. return 1;
  2403. }
  2404. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2405. * trigger the release of node.
  2406. */
  2407. lpfc_nlp_put(ndlp);
  2408. return 0;
  2409. }
  2410. /**
  2411. * lpfc_issue_els_farpr - Issue a farp to an node on a vport
  2412. * @vport: pointer to a host virtual N_Port data structure.
  2413. * @nportid: N_Port identifier to the remote node.
  2414. * @retry: number of retries to the command IOCB.
  2415. *
  2416. * This routine issues a Fibre Channel Address Resolution Response
  2417. * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
  2418. * is passed into the function. It first search the @vport node list to find
  2419. * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
  2420. * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
  2421. * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
  2422. *
  2423. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  2424. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  2425. * will be stored into the context1 field of the IOCB for the completion
  2426. * callback function to the PARPR ELS command.
  2427. *
  2428. * Return code
  2429. * 0 - Successfully issued farpr command
  2430. * 1 - Failed to issue farpr command
  2431. **/
  2432. static int
  2433. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  2434. {
  2435. struct lpfc_hba *phba = vport->phba;
  2436. IOCB_t *icmd;
  2437. struct lpfc_iocbq *elsiocb;
  2438. struct lpfc_sli *psli;
  2439. FARP *fp;
  2440. uint8_t *pcmd;
  2441. uint32_t *lp;
  2442. uint16_t cmdsize;
  2443. struct lpfc_nodelist *ondlp;
  2444. struct lpfc_nodelist *ndlp;
  2445. psli = &phba->sli;
  2446. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  2447. ndlp = lpfc_findnode_did(vport, nportid);
  2448. if (!ndlp) {
  2449. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2450. if (!ndlp)
  2451. return 1;
  2452. lpfc_nlp_init(vport, ndlp, nportid);
  2453. lpfc_enqueue_node(vport, ndlp);
  2454. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2455. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  2456. if (!ndlp)
  2457. return 1;
  2458. }
  2459. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2460. ndlp->nlp_DID, ELS_CMD_RNID);
  2461. if (!elsiocb) {
  2462. /* This will trigger the release of the node just
  2463. * allocated
  2464. */
  2465. lpfc_nlp_put(ndlp);
  2466. return 1;
  2467. }
  2468. icmd = &elsiocb->iocb;
  2469. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2470. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  2471. pcmd += sizeof(uint32_t);
  2472. /* Fill in FARPR payload */
  2473. fp = (FARP *) (pcmd);
  2474. memset(fp, 0, sizeof(FARP));
  2475. lp = (uint32_t *) pcmd;
  2476. *lp++ = be32_to_cpu(nportid);
  2477. *lp++ = be32_to_cpu(vport->fc_myDID);
  2478. fp->Rflags = 0;
  2479. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  2480. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  2481. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2482. ondlp = lpfc_findnode_did(vport, nportid);
  2483. if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
  2484. memcpy(&fp->OportName, &ondlp->nlp_portname,
  2485. sizeof(struct lpfc_name));
  2486. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  2487. sizeof(struct lpfc_name));
  2488. }
  2489. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2490. "Issue FARPR: did:x%x",
  2491. ndlp->nlp_DID, 0, 0);
  2492. phba->fc_stat.elsXmitFARPR++;
  2493. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  2494. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  2495. IOCB_ERROR) {
  2496. /* The additional lpfc_nlp_put will cause the following
  2497. * lpfc_els_free_iocb routine to trigger the release of
  2498. * the node.
  2499. */
  2500. lpfc_nlp_put(ndlp);
  2501. lpfc_els_free_iocb(phba, elsiocb);
  2502. return 1;
  2503. }
  2504. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  2505. * trigger the release of the node.
  2506. */
  2507. lpfc_nlp_put(ndlp);
  2508. return 0;
  2509. }
  2510. /**
  2511. * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
  2512. * @vport: pointer to a host virtual N_Port data structure.
  2513. * @nlp: pointer to a node-list data structure.
  2514. *
  2515. * This routine cancels the timer with a delayed IOCB-command retry for
  2516. * a @vport's @ndlp. It stops the timer for the delayed function retrial and
  2517. * removes the ELS retry event if it presents. In addition, if the
  2518. * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
  2519. * commands are sent for the @vport's nodes that require issuing discovery
  2520. * ADISC.
  2521. **/
  2522. void
  2523. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  2524. {
  2525. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2526. struct lpfc_work_evt *evtp;
  2527. if (!(nlp->nlp_flag & NLP_DELAY_TMO))
  2528. return;
  2529. spin_lock_irq(shost->host_lock);
  2530. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  2531. spin_unlock_irq(shost->host_lock);
  2532. del_timer_sync(&nlp->nlp_delayfunc);
  2533. nlp->nlp_last_elscmd = 0;
  2534. if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
  2535. list_del_init(&nlp->els_retry_evt.evt_listp);
  2536. /* Decrement nlp reference count held for the delayed retry */
  2537. evtp = &nlp->els_retry_evt;
  2538. lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
  2539. }
  2540. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  2541. spin_lock_irq(shost->host_lock);
  2542. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  2543. spin_unlock_irq(shost->host_lock);
  2544. if (vport->num_disc_nodes) {
  2545. if (vport->port_state < LPFC_VPORT_READY) {
  2546. /* Check if there are more ADISCs to be sent */
  2547. lpfc_more_adisc(vport);
  2548. } else {
  2549. /* Check if there are more PLOGIs to be sent */
  2550. lpfc_more_plogi(vport);
  2551. if (vport->num_disc_nodes == 0) {
  2552. spin_lock_irq(shost->host_lock);
  2553. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2554. spin_unlock_irq(shost->host_lock);
  2555. lpfc_can_disctmo(vport);
  2556. lpfc_end_rscn(vport);
  2557. }
  2558. }
  2559. }
  2560. }
  2561. return;
  2562. }
  2563. /**
  2564. * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
  2565. * @ptr: holder for the pointer to the timer function associated data (ndlp).
  2566. *
  2567. * This routine is invoked by the ndlp delayed-function timer to check
  2568. * whether there is any pending ELS retry event(s) with the node. If not, it
  2569. * simply returns. Otherwise, if there is at least one ELS delayed event, it
  2570. * adds the delayed events to the HBA work list and invokes the
  2571. * lpfc_worker_wake_up() routine to wake up worker thread to process the
  2572. * event. Note that lpfc_nlp_get() is called before posting the event to
  2573. * the work list to hold reference count of ndlp so that it guarantees the
  2574. * reference to ndlp will still be available when the worker thread gets
  2575. * to the event associated with the ndlp.
  2576. **/
  2577. void
  2578. lpfc_els_retry_delay(unsigned long ptr)
  2579. {
  2580. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  2581. struct lpfc_vport *vport = ndlp->vport;
  2582. struct lpfc_hba *phba = vport->phba;
  2583. unsigned long flags;
  2584. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  2585. spin_lock_irqsave(&phba->hbalock, flags);
  2586. if (!list_empty(&evtp->evt_listp)) {
  2587. spin_unlock_irqrestore(&phba->hbalock, flags);
  2588. return;
  2589. }
  2590. /* We need to hold the node by incrementing the reference
  2591. * count until the queued work is done
  2592. */
  2593. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  2594. if (evtp->evt_arg1) {
  2595. evtp->evt = LPFC_EVT_ELS_RETRY;
  2596. list_add_tail(&evtp->evt_listp, &phba->work_list);
  2597. lpfc_worker_wake_up(phba);
  2598. }
  2599. spin_unlock_irqrestore(&phba->hbalock, flags);
  2600. return;
  2601. }
  2602. /**
  2603. * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
  2604. * @ndlp: pointer to a node-list data structure.
  2605. *
  2606. * This routine is the worker-thread handler for processing the @ndlp delayed
  2607. * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
  2608. * the last ELS command from the associated ndlp and invokes the proper ELS
  2609. * function according to the delayed ELS command to retry the command.
  2610. **/
  2611. void
  2612. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  2613. {
  2614. struct lpfc_vport *vport = ndlp->vport;
  2615. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2616. uint32_t cmd, did, retry;
  2617. spin_lock_irq(shost->host_lock);
  2618. did = ndlp->nlp_DID;
  2619. cmd = ndlp->nlp_last_elscmd;
  2620. ndlp->nlp_last_elscmd = 0;
  2621. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2622. spin_unlock_irq(shost->host_lock);
  2623. return;
  2624. }
  2625. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  2626. spin_unlock_irq(shost->host_lock);
  2627. /*
  2628. * If a discovery event readded nlp_delayfunc after timer
  2629. * firing and before processing the timer, cancel the
  2630. * nlp_delayfunc.
  2631. */
  2632. del_timer_sync(&ndlp->nlp_delayfunc);
  2633. retry = ndlp->nlp_retry;
  2634. ndlp->nlp_retry = 0;
  2635. switch (cmd) {
  2636. case ELS_CMD_FLOGI:
  2637. lpfc_issue_els_flogi(vport, ndlp, retry);
  2638. break;
  2639. case ELS_CMD_PLOGI:
  2640. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  2641. ndlp->nlp_prev_state = ndlp->nlp_state;
  2642. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2643. }
  2644. break;
  2645. case ELS_CMD_ADISC:
  2646. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  2647. ndlp->nlp_prev_state = ndlp->nlp_state;
  2648. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2649. }
  2650. break;
  2651. case ELS_CMD_PRLI:
  2652. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  2653. ndlp->nlp_prev_state = ndlp->nlp_state;
  2654. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  2655. }
  2656. break;
  2657. case ELS_CMD_LOGO:
  2658. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  2659. ndlp->nlp_prev_state = ndlp->nlp_state;
  2660. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2661. }
  2662. break;
  2663. case ELS_CMD_FDISC:
  2664. if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
  2665. lpfc_issue_els_fdisc(vport, ndlp, retry);
  2666. break;
  2667. }
  2668. return;
  2669. }
  2670. /**
  2671. * lpfc_els_retry - Make retry decision on an els command iocb
  2672. * @phba: pointer to lpfc hba data structure.
  2673. * @cmdiocb: pointer to lpfc command iocb data structure.
  2674. * @rspiocb: pointer to lpfc response iocb data structure.
  2675. *
  2676. * This routine makes a retry decision on an ELS command IOCB, which has
  2677. * failed. The following ELS IOCBs use this function for retrying the command
  2678. * when previously issued command responsed with error status: FLOGI, PLOGI,
  2679. * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
  2680. * returned error status, it makes the decision whether a retry shall be
  2681. * issued for the command, and whether a retry shall be made immediately or
  2682. * delayed. In the former case, the corresponding ELS command issuing-function
  2683. * is called to retry the command. In the later case, the ELS command shall
  2684. * be posted to the ndlp delayed event and delayed function timer set to the
  2685. * ndlp for the delayed command issusing.
  2686. *
  2687. * Return code
  2688. * 0 - No retry of els command is made
  2689. * 1 - Immediate or delayed retry of els command is made
  2690. **/
  2691. static int
  2692. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2693. struct lpfc_iocbq *rspiocb)
  2694. {
  2695. struct lpfc_vport *vport = cmdiocb->vport;
  2696. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2697. IOCB_t *irsp = &rspiocb->iocb;
  2698. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  2699. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2700. uint32_t *elscmd;
  2701. struct ls_rjt stat;
  2702. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  2703. int logerr = 0;
  2704. uint32_t cmd = 0;
  2705. uint32_t did;
  2706. /* Note: context2 may be 0 for internal driver abort
  2707. * of delays ELS command.
  2708. */
  2709. if (pcmd && pcmd->virt) {
  2710. elscmd = (uint32_t *) (pcmd->virt);
  2711. cmd = *elscmd++;
  2712. }
  2713. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  2714. did = ndlp->nlp_DID;
  2715. else {
  2716. /* We should only hit this case for retrying PLOGI */
  2717. did = irsp->un.elsreq64.remoteID;
  2718. ndlp = lpfc_findnode_did(vport, did);
  2719. if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  2720. && (cmd != ELS_CMD_PLOGI))
  2721. return 1;
  2722. }
  2723. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2724. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  2725. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  2726. switch (irsp->ulpStatus) {
  2727. case IOSTAT_FCP_RSP_ERROR:
  2728. break;
  2729. case IOSTAT_REMOTE_STOP:
  2730. if (phba->sli_rev == LPFC_SLI_REV4) {
  2731. /* This IO was aborted by the target, we don't
  2732. * know the rxid and because we did not send the
  2733. * ABTS we cannot generate and RRQ.
  2734. */
  2735. lpfc_set_rrq_active(phba, ndlp,
  2736. cmdiocb->sli4_lxritag, 0, 0);
  2737. }
  2738. break;
  2739. case IOSTAT_LOCAL_REJECT:
  2740. switch ((irsp->un.ulpWord[4] & 0xff)) {
  2741. case IOERR_LOOP_OPEN_FAILURE:
  2742. if (cmd == ELS_CMD_FLOGI) {
  2743. if (PCI_DEVICE_ID_HORNET ==
  2744. phba->pcidev->device) {
  2745. phba->fc_topology = LPFC_TOPOLOGY_LOOP;
  2746. phba->pport->fc_myDID = 0;
  2747. phba->alpa_map[0] = 0;
  2748. phba->alpa_map[1] = 0;
  2749. }
  2750. }
  2751. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  2752. delay = 1000;
  2753. retry = 1;
  2754. break;
  2755. case IOERR_ILLEGAL_COMMAND:
  2756. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2757. "0124 Retry illegal cmd x%x "
  2758. "retry:x%x delay:x%x\n",
  2759. cmd, cmdiocb->retry, delay);
  2760. retry = 1;
  2761. /* All command's retry policy */
  2762. maxretry = 8;
  2763. if (cmdiocb->retry > 2)
  2764. delay = 1000;
  2765. break;
  2766. case IOERR_NO_RESOURCES:
  2767. logerr = 1; /* HBA out of resources */
  2768. retry = 1;
  2769. if (cmdiocb->retry > 100)
  2770. delay = 100;
  2771. maxretry = 250;
  2772. break;
  2773. case IOERR_ILLEGAL_FRAME:
  2774. delay = 100;
  2775. retry = 1;
  2776. break;
  2777. case IOERR_SEQUENCE_TIMEOUT:
  2778. case IOERR_INVALID_RPI:
  2779. retry = 1;
  2780. break;
  2781. }
  2782. break;
  2783. case IOSTAT_NPORT_RJT:
  2784. case IOSTAT_FABRIC_RJT:
  2785. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  2786. retry = 1;
  2787. break;
  2788. }
  2789. break;
  2790. case IOSTAT_NPORT_BSY:
  2791. case IOSTAT_FABRIC_BSY:
  2792. logerr = 1; /* Fabric / Remote NPort out of resources */
  2793. retry = 1;
  2794. break;
  2795. case IOSTAT_LS_RJT:
  2796. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  2797. /* Added for Vendor specifc support
  2798. * Just keep retrying for these Rsn / Exp codes
  2799. */
  2800. switch (stat.un.b.lsRjtRsnCode) {
  2801. case LSRJT_UNABLE_TPC:
  2802. if (stat.un.b.lsRjtRsnCodeExp ==
  2803. LSEXP_CMD_IN_PROGRESS) {
  2804. if (cmd == ELS_CMD_PLOGI) {
  2805. delay = 1000;
  2806. maxretry = 48;
  2807. }
  2808. retry = 1;
  2809. break;
  2810. }
  2811. if (stat.un.b.lsRjtRsnCodeExp ==
  2812. LSEXP_CANT_GIVE_DATA) {
  2813. if (cmd == ELS_CMD_PLOGI) {
  2814. delay = 1000;
  2815. maxretry = 48;
  2816. }
  2817. retry = 1;
  2818. break;
  2819. }
  2820. if (cmd == ELS_CMD_PLOGI) {
  2821. delay = 1000;
  2822. maxretry = lpfc_max_els_tries + 1;
  2823. retry = 1;
  2824. break;
  2825. }
  2826. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2827. (cmd == ELS_CMD_FDISC) &&
  2828. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  2829. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2830. "0125 FDISC Failed (x%x). "
  2831. "Fabric out of resources\n",
  2832. stat.un.lsRjtError);
  2833. lpfc_vport_set_state(vport,
  2834. FC_VPORT_NO_FABRIC_RSCS);
  2835. }
  2836. break;
  2837. case LSRJT_LOGICAL_BSY:
  2838. if ((cmd == ELS_CMD_PLOGI) ||
  2839. (cmd == ELS_CMD_PRLI)) {
  2840. delay = 1000;
  2841. maxretry = 48;
  2842. } else if (cmd == ELS_CMD_FDISC) {
  2843. /* FDISC retry policy */
  2844. maxretry = 48;
  2845. if (cmdiocb->retry >= 32)
  2846. delay = 1000;
  2847. }
  2848. retry = 1;
  2849. break;
  2850. case LSRJT_LOGICAL_ERR:
  2851. /* There are some cases where switches return this
  2852. * error when they are not ready and should be returning
  2853. * Logical Busy. We should delay every time.
  2854. */
  2855. if (cmd == ELS_CMD_FDISC &&
  2856. stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
  2857. maxretry = 3;
  2858. delay = 1000;
  2859. retry = 1;
  2860. break;
  2861. }
  2862. case LSRJT_PROTOCOL_ERR:
  2863. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2864. (cmd == ELS_CMD_FDISC) &&
  2865. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  2866. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  2867. ) {
  2868. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2869. "0122 FDISC Failed (x%x). "
  2870. "Fabric Detected Bad WWN\n",
  2871. stat.un.lsRjtError);
  2872. lpfc_vport_set_state(vport,
  2873. FC_VPORT_FABRIC_REJ_WWN);
  2874. }
  2875. break;
  2876. }
  2877. break;
  2878. case IOSTAT_INTERMED_RSP:
  2879. case IOSTAT_BA_RJT:
  2880. break;
  2881. default:
  2882. break;
  2883. }
  2884. if (did == FDMI_DID)
  2885. retry = 1;
  2886. if ((cmd == ELS_CMD_FLOGI) &&
  2887. (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
  2888. !lpfc_error_lost_link(irsp)) {
  2889. /* FLOGI retry policy */
  2890. retry = 1;
  2891. /* retry FLOGI forever */
  2892. maxretry = 0;
  2893. if (cmdiocb->retry >= 100)
  2894. delay = 5000;
  2895. else if (cmdiocb->retry >= 32)
  2896. delay = 1000;
  2897. } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
  2898. /* retry FDISCs every second up to devloss */
  2899. retry = 1;
  2900. maxretry = vport->cfg_devloss_tmo;
  2901. delay = 1000;
  2902. }
  2903. cmdiocb->retry++;
  2904. if (maxretry && (cmdiocb->retry >= maxretry)) {
  2905. phba->fc_stat.elsRetryExceeded++;
  2906. retry = 0;
  2907. }
  2908. if ((vport->load_flag & FC_UNLOADING) != 0)
  2909. retry = 0;
  2910. if (retry) {
  2911. if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
  2912. /* Stop retrying PLOGI and FDISC if in FCF discovery */
  2913. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  2914. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2915. "2849 Stop retry ELS command "
  2916. "x%x to remote NPORT x%x, "
  2917. "Data: x%x x%x\n", cmd, did,
  2918. cmdiocb->retry, delay);
  2919. return 0;
  2920. }
  2921. }
  2922. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  2923. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2924. "0107 Retry ELS command x%x to remote "
  2925. "NPORT x%x Data: x%x x%x\n",
  2926. cmd, did, cmdiocb->retry, delay);
  2927. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  2928. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  2929. ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
  2930. /* Don't reset timer for no resources */
  2931. /* If discovery / RSCN timer is running, reset it */
  2932. if (timer_pending(&vport->fc_disctmo) ||
  2933. (vport->fc_flag & FC_RSCN_MODE))
  2934. lpfc_set_disctmo(vport);
  2935. }
  2936. phba->fc_stat.elsXmitRetry++;
  2937. if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
  2938. phba->fc_stat.elsDelayRetry++;
  2939. ndlp->nlp_retry = cmdiocb->retry;
  2940. /* delay is specified in milliseconds */
  2941. mod_timer(&ndlp->nlp_delayfunc,
  2942. jiffies + msecs_to_jiffies(delay));
  2943. spin_lock_irq(shost->host_lock);
  2944. ndlp->nlp_flag |= NLP_DELAY_TMO;
  2945. spin_unlock_irq(shost->host_lock);
  2946. ndlp->nlp_prev_state = ndlp->nlp_state;
  2947. if (cmd == ELS_CMD_PRLI)
  2948. lpfc_nlp_set_state(vport, ndlp,
  2949. NLP_STE_REG_LOGIN_ISSUE);
  2950. else
  2951. lpfc_nlp_set_state(vport, ndlp,
  2952. NLP_STE_NPR_NODE);
  2953. ndlp->nlp_last_elscmd = cmd;
  2954. return 1;
  2955. }
  2956. switch (cmd) {
  2957. case ELS_CMD_FLOGI:
  2958. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  2959. return 1;
  2960. case ELS_CMD_FDISC:
  2961. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  2962. return 1;
  2963. case ELS_CMD_PLOGI:
  2964. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  2965. ndlp->nlp_prev_state = ndlp->nlp_state;
  2966. lpfc_nlp_set_state(vport, ndlp,
  2967. NLP_STE_PLOGI_ISSUE);
  2968. }
  2969. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  2970. return 1;
  2971. case ELS_CMD_ADISC:
  2972. ndlp->nlp_prev_state = ndlp->nlp_state;
  2973. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2974. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  2975. return 1;
  2976. case ELS_CMD_PRLI:
  2977. ndlp->nlp_prev_state = ndlp->nlp_state;
  2978. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  2979. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  2980. return 1;
  2981. case ELS_CMD_LOGO:
  2982. ndlp->nlp_prev_state = ndlp->nlp_state;
  2983. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2984. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  2985. return 1;
  2986. }
  2987. }
  2988. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  2989. if (logerr) {
  2990. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2991. "0137 No retry ELS command x%x to remote "
  2992. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  2993. cmd, did, irsp->ulpStatus,
  2994. irsp->un.ulpWord[4]);
  2995. }
  2996. else {
  2997. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2998. "0108 No retry ELS command x%x to remote "
  2999. "NPORT x%x Retried:%d Error:x%x/%x\n",
  3000. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  3001. irsp->un.ulpWord[4]);
  3002. }
  3003. return 0;
  3004. }
  3005. /**
  3006. * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
  3007. * @phba: pointer to lpfc hba data structure.
  3008. * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
  3009. *
  3010. * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
  3011. * associated with a command IOCB back to the lpfc DMA buffer pool. It first
  3012. * checks to see whether there is a lpfc DMA buffer associated with the
  3013. * response of the command IOCB. If so, it will be released before releasing
  3014. * the lpfc DMA buffer associated with the IOCB itself.
  3015. *
  3016. * Return code
  3017. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  3018. **/
  3019. static int
  3020. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  3021. {
  3022. struct lpfc_dmabuf *buf_ptr;
  3023. /* Free the response before processing the command. */
  3024. if (!list_empty(&buf_ptr1->list)) {
  3025. list_remove_head(&buf_ptr1->list, buf_ptr,
  3026. struct lpfc_dmabuf,
  3027. list);
  3028. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3029. kfree(buf_ptr);
  3030. }
  3031. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  3032. kfree(buf_ptr1);
  3033. return 0;
  3034. }
  3035. /**
  3036. * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
  3037. * @phba: pointer to lpfc hba data structure.
  3038. * @buf_ptr: pointer to the lpfc dma buffer data structure.
  3039. *
  3040. * This routine releases the lpfc Direct Memory Access (DMA) buffer
  3041. * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
  3042. * pool.
  3043. *
  3044. * Return code
  3045. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  3046. **/
  3047. static int
  3048. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  3049. {
  3050. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  3051. kfree(buf_ptr);
  3052. return 0;
  3053. }
  3054. /**
  3055. * lpfc_els_free_iocb - Free a command iocb and its associated resources
  3056. * @phba: pointer to lpfc hba data structure.
  3057. * @elsiocb: pointer to lpfc els command iocb data structure.
  3058. *
  3059. * This routine frees a command IOCB and its associated resources. The
  3060. * command IOCB data structure contains the reference to various associated
  3061. * resources, these fields must be set to NULL if the associated reference
  3062. * not present:
  3063. * context1 - reference to ndlp
  3064. * context2 - reference to cmd
  3065. * context2->next - reference to rsp
  3066. * context3 - reference to bpl
  3067. *
  3068. * It first properly decrements the reference count held on ndlp for the
  3069. * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
  3070. * set, it invokes the lpfc_els_free_data() routine to release the Direct
  3071. * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
  3072. * adds the DMA buffer the @phba data structure for the delayed release.
  3073. * If reference to the Buffer Pointer List (BPL) is present, the
  3074. * lpfc_els_free_bpl() routine is invoked to release the DMA memory
  3075. * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
  3076. * invoked to release the IOCB data structure back to @phba IOCBQ list.
  3077. *
  3078. * Return code
  3079. * 0 - Success (currently, always return 0)
  3080. **/
  3081. int
  3082. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  3083. {
  3084. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  3085. struct lpfc_nodelist *ndlp;
  3086. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  3087. if (ndlp) {
  3088. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  3089. lpfc_nlp_put(ndlp);
  3090. /* If the ndlp is not being used by another discovery
  3091. * thread, free it.
  3092. */
  3093. if (!lpfc_nlp_not_used(ndlp)) {
  3094. /* If ndlp is being used by another discovery
  3095. * thread, just clear NLP_DEFER_RM
  3096. */
  3097. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  3098. }
  3099. }
  3100. else
  3101. lpfc_nlp_put(ndlp);
  3102. elsiocb->context1 = NULL;
  3103. }
  3104. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  3105. if (elsiocb->context2) {
  3106. if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
  3107. /* Firmware could still be in progress of DMAing
  3108. * payload, so don't free data buffer till after
  3109. * a hbeat.
  3110. */
  3111. elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
  3112. buf_ptr = elsiocb->context2;
  3113. elsiocb->context2 = NULL;
  3114. if (buf_ptr) {
  3115. buf_ptr1 = NULL;
  3116. spin_lock_irq(&phba->hbalock);
  3117. if (!list_empty(&buf_ptr->list)) {
  3118. list_remove_head(&buf_ptr->list,
  3119. buf_ptr1, struct lpfc_dmabuf,
  3120. list);
  3121. INIT_LIST_HEAD(&buf_ptr1->list);
  3122. list_add_tail(&buf_ptr1->list,
  3123. &phba->elsbuf);
  3124. phba->elsbuf_cnt++;
  3125. }
  3126. INIT_LIST_HEAD(&buf_ptr->list);
  3127. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  3128. phba->elsbuf_cnt++;
  3129. spin_unlock_irq(&phba->hbalock);
  3130. }
  3131. } else {
  3132. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  3133. lpfc_els_free_data(phba, buf_ptr1);
  3134. }
  3135. }
  3136. if (elsiocb->context3) {
  3137. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  3138. lpfc_els_free_bpl(phba, buf_ptr);
  3139. }
  3140. lpfc_sli_release_iocbq(phba, elsiocb);
  3141. return 0;
  3142. }
  3143. /**
  3144. * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
  3145. * @phba: pointer to lpfc hba data structure.
  3146. * @cmdiocb: pointer to lpfc command iocb data structure.
  3147. * @rspiocb: pointer to lpfc response iocb data structure.
  3148. *
  3149. * This routine is the completion callback function to the Logout (LOGO)
  3150. * Accept (ACC) Response ELS command. This routine is invoked to indicate
  3151. * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
  3152. * release the ndlp if it has the last reference remaining (reference count
  3153. * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
  3154. * field to NULL to inform the following lpfc_els_free_iocb() routine no
  3155. * ndlp reference count needs to be decremented. Otherwise, the ndlp
  3156. * reference use-count shall be decremented by the lpfc_els_free_iocb()
  3157. * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
  3158. * IOCB data structure.
  3159. **/
  3160. static void
  3161. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3162. struct lpfc_iocbq *rspiocb)
  3163. {
  3164. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3165. struct lpfc_vport *vport = cmdiocb->vport;
  3166. IOCB_t *irsp;
  3167. irsp = &rspiocb->iocb;
  3168. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3169. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  3170. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  3171. /* ACC to LOGO completes to NPort <nlp_DID> */
  3172. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3173. "0109 ACC to LOGO completes to NPort x%x "
  3174. "Data: x%x x%x x%x\n",
  3175. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3176. ndlp->nlp_rpi);
  3177. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  3178. /* NPort Recovery mode or node is just allocated */
  3179. if (!lpfc_nlp_not_used(ndlp)) {
  3180. /* If the ndlp is being used by another discovery
  3181. * thread, just unregister the RPI.
  3182. */
  3183. lpfc_unreg_rpi(vport, ndlp);
  3184. } else {
  3185. /* Indicate the node has already released, should
  3186. * not reference to it from within lpfc_els_free_iocb.
  3187. */
  3188. cmdiocb->context1 = NULL;
  3189. }
  3190. }
  3191. /*
  3192. * The driver received a LOGO from the rport and has ACK'd it.
  3193. * At this point, the driver is done so release the IOCB
  3194. */
  3195. lpfc_els_free_iocb(phba, cmdiocb);
  3196. /*
  3197. * Remove the ndlp reference if it's a fabric node that has
  3198. * sent us an unsolicted LOGO.
  3199. */
  3200. if (ndlp->nlp_type & NLP_FABRIC)
  3201. lpfc_nlp_put(ndlp);
  3202. return;
  3203. }
  3204. /**
  3205. * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
  3206. * @phba: pointer to lpfc hba data structure.
  3207. * @pmb: pointer to the driver internal queue element for mailbox command.
  3208. *
  3209. * This routine is the completion callback function for unregister default
  3210. * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
  3211. * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
  3212. * decrements the ndlp reference count held for this completion callback
  3213. * function. After that, it invokes the lpfc_nlp_not_used() to check
  3214. * whether there is only one reference left on the ndlp. If so, it will
  3215. * perform one more decrement and trigger the release of the ndlp.
  3216. **/
  3217. void
  3218. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3219. {
  3220. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3221. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3222. pmb->context1 = NULL;
  3223. pmb->context2 = NULL;
  3224. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3225. kfree(mp);
  3226. mempool_free(pmb, phba->mbox_mem_pool);
  3227. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  3228. lpfc_nlp_put(ndlp);
  3229. /* This is the end of the default RPI cleanup logic for this
  3230. * ndlp. If no other discovery threads are using this ndlp.
  3231. * we should free all resources associated with it.
  3232. */
  3233. lpfc_nlp_not_used(ndlp);
  3234. }
  3235. return;
  3236. }
  3237. /**
  3238. * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
  3239. * @phba: pointer to lpfc hba data structure.
  3240. * @cmdiocb: pointer to lpfc command iocb data structure.
  3241. * @rspiocb: pointer to lpfc response iocb data structure.
  3242. *
  3243. * This routine is the completion callback function for ELS Response IOCB
  3244. * command. In normal case, this callback function just properly sets the
  3245. * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
  3246. * field in the command IOCB is not NULL, the referred mailbox command will
  3247. * be send out, and then invokes the lpfc_els_free_iocb() routine to release
  3248. * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
  3249. * link down event occurred during the discovery, the lpfc_nlp_not_used()
  3250. * routine shall be invoked trying to release the ndlp if no other threads
  3251. * are currently referring it.
  3252. **/
  3253. static void
  3254. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3255. struct lpfc_iocbq *rspiocb)
  3256. {
  3257. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3258. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  3259. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  3260. IOCB_t *irsp;
  3261. uint8_t *pcmd;
  3262. LPFC_MBOXQ_t *mbox = NULL;
  3263. struct lpfc_dmabuf *mp = NULL;
  3264. uint32_t ls_rjt = 0;
  3265. irsp = &rspiocb->iocb;
  3266. if (cmdiocb->context_un.mbox)
  3267. mbox = cmdiocb->context_un.mbox;
  3268. /* First determine if this is a LS_RJT cmpl. Note, this callback
  3269. * function can have cmdiocb->contest1 (ndlp) field set to NULL.
  3270. */
  3271. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  3272. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  3273. (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
  3274. /* A LS_RJT associated with Default RPI cleanup has its own
  3275. * separate code path.
  3276. */
  3277. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  3278. ls_rjt = 1;
  3279. }
  3280. /* Check to see if link went down during discovery */
  3281. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
  3282. if (mbox) {
  3283. mp = (struct lpfc_dmabuf *) mbox->context1;
  3284. if (mp) {
  3285. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3286. kfree(mp);
  3287. }
  3288. mempool_free(mbox, phba->mbox_mem_pool);
  3289. }
  3290. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  3291. (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  3292. if (lpfc_nlp_not_used(ndlp)) {
  3293. ndlp = NULL;
  3294. /* Indicate the node has already released,
  3295. * should not reference to it from within
  3296. * the routine lpfc_els_free_iocb.
  3297. */
  3298. cmdiocb->context1 = NULL;
  3299. }
  3300. goto out;
  3301. }
  3302. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3303. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  3304. irsp->ulpStatus, irsp->un.ulpWord[4],
  3305. cmdiocb->iocb.un.elsreq64.remoteID);
  3306. /* ELS response tag <ulpIoTag> completes */
  3307. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3308. "0110 ELS response tag x%x completes "
  3309. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  3310. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  3311. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  3312. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3313. ndlp->nlp_rpi);
  3314. if (mbox) {
  3315. if ((rspiocb->iocb.ulpStatus == 0)
  3316. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  3317. lpfc_unreg_rpi(vport, ndlp);
  3318. /* Increment reference count to ndlp to hold the
  3319. * reference to ndlp for the callback function.
  3320. */
  3321. mbox->context2 = lpfc_nlp_get(ndlp);
  3322. mbox->vport = vport;
  3323. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  3324. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  3325. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  3326. }
  3327. else {
  3328. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  3329. ndlp->nlp_prev_state = ndlp->nlp_state;
  3330. lpfc_nlp_set_state(vport, ndlp,
  3331. NLP_STE_REG_LOGIN_ISSUE);
  3332. }
  3333. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  3334. != MBX_NOT_FINISHED)
  3335. goto out;
  3336. else
  3337. /* Decrement the ndlp reference count we
  3338. * set for this failed mailbox command.
  3339. */
  3340. lpfc_nlp_put(ndlp);
  3341. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  3342. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3343. "0138 ELS rsp: Cannot issue reg_login for x%x "
  3344. "Data: x%x x%x x%x\n",
  3345. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3346. ndlp->nlp_rpi);
  3347. if (lpfc_nlp_not_used(ndlp)) {
  3348. ndlp = NULL;
  3349. /* Indicate node has already been released,
  3350. * should not reference to it from within
  3351. * the routine lpfc_els_free_iocb.
  3352. */
  3353. cmdiocb->context1 = NULL;
  3354. }
  3355. } else {
  3356. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  3357. if (!lpfc_error_lost_link(irsp) &&
  3358. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  3359. if (lpfc_nlp_not_used(ndlp)) {
  3360. ndlp = NULL;
  3361. /* Indicate node has already been
  3362. * released, should not reference
  3363. * to it from within the routine
  3364. * lpfc_els_free_iocb.
  3365. */
  3366. cmdiocb->context1 = NULL;
  3367. }
  3368. }
  3369. }
  3370. mp = (struct lpfc_dmabuf *) mbox->context1;
  3371. if (mp) {
  3372. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3373. kfree(mp);
  3374. }
  3375. mempool_free(mbox, phba->mbox_mem_pool);
  3376. }
  3377. out:
  3378. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  3379. spin_lock_irq(shost->host_lock);
  3380. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  3381. spin_unlock_irq(shost->host_lock);
  3382. /* If the node is not being used by another discovery thread,
  3383. * and we are sending a reject, we are done with it.
  3384. * Release driver reference count here and free associated
  3385. * resources.
  3386. */
  3387. if (ls_rjt)
  3388. if (lpfc_nlp_not_used(ndlp))
  3389. /* Indicate node has already been released,
  3390. * should not reference to it from within
  3391. * the routine lpfc_els_free_iocb.
  3392. */
  3393. cmdiocb->context1 = NULL;
  3394. }
  3395. lpfc_els_free_iocb(phba, cmdiocb);
  3396. return;
  3397. }
  3398. /**
  3399. * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
  3400. * @vport: pointer to a host virtual N_Port data structure.
  3401. * @flag: the els command code to be accepted.
  3402. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3403. * @ndlp: pointer to a node-list data structure.
  3404. * @mbox: pointer to the driver internal queue element for mailbox command.
  3405. *
  3406. * This routine prepares and issues an Accept (ACC) response IOCB
  3407. * command. It uses the @flag to properly set up the IOCB field for the
  3408. * specific ACC response command to be issued and invokes the
  3409. * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
  3410. * @mbox pointer is passed in, it will be put into the context_un.mbox
  3411. * field of the IOCB for the completion callback function to issue the
  3412. * mailbox command to the HBA later when callback is invoked.
  3413. *
  3414. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3415. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3416. * will be stored into the context1 field of the IOCB for the completion
  3417. * callback function to the corresponding response ELS IOCB command.
  3418. *
  3419. * Return code
  3420. * 0 - Successfully issued acc response
  3421. * 1 - Failed to issue acc response
  3422. **/
  3423. int
  3424. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  3425. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  3426. LPFC_MBOXQ_t *mbox)
  3427. {
  3428. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3429. struct lpfc_hba *phba = vport->phba;
  3430. IOCB_t *icmd;
  3431. IOCB_t *oldcmd;
  3432. struct lpfc_iocbq *elsiocb;
  3433. struct lpfc_sli *psli;
  3434. uint8_t *pcmd;
  3435. uint16_t cmdsize;
  3436. int rc;
  3437. ELS_PKT *els_pkt_ptr;
  3438. psli = &phba->sli;
  3439. oldcmd = &oldiocb->iocb;
  3440. switch (flag) {
  3441. case ELS_CMD_ACC:
  3442. cmdsize = sizeof(uint32_t);
  3443. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3444. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  3445. if (!elsiocb) {
  3446. spin_lock_irq(shost->host_lock);
  3447. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  3448. spin_unlock_irq(shost->host_lock);
  3449. return 1;
  3450. }
  3451. icmd = &elsiocb->iocb;
  3452. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3453. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3454. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3455. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3456. pcmd += sizeof(uint32_t);
  3457. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3458. "Issue ACC: did:x%x flg:x%x",
  3459. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3460. break;
  3461. case ELS_CMD_PLOGI:
  3462. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  3463. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3464. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  3465. if (!elsiocb)
  3466. return 1;
  3467. icmd = &elsiocb->iocb;
  3468. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3469. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3470. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3471. if (mbox)
  3472. elsiocb->context_un.mbox = mbox;
  3473. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3474. pcmd += sizeof(uint32_t);
  3475. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  3476. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3477. "Issue ACC PLOGI: did:x%x flg:x%x",
  3478. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3479. break;
  3480. case ELS_CMD_PRLO:
  3481. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  3482. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  3483. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  3484. if (!elsiocb)
  3485. return 1;
  3486. icmd = &elsiocb->iocb;
  3487. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3488. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3489. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3490. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  3491. sizeof(uint32_t) + sizeof(PRLO));
  3492. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  3493. els_pkt_ptr = (ELS_PKT *) pcmd;
  3494. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  3495. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3496. "Issue ACC PRLO: did:x%x flg:x%x",
  3497. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3498. break;
  3499. default:
  3500. return 1;
  3501. }
  3502. /* Xmit ELS ACC response tag <ulpIoTag> */
  3503. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3504. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  3505. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
  3506. "fc_flag x%x\n",
  3507. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3508. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3509. ndlp->nlp_rpi, vport->fc_flag);
  3510. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  3511. spin_lock_irq(shost->host_lock);
  3512. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  3513. spin_unlock_irq(shost->host_lock);
  3514. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  3515. } else {
  3516. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3517. }
  3518. phba->fc_stat.elsXmitACC++;
  3519. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3520. if (rc == IOCB_ERROR) {
  3521. lpfc_els_free_iocb(phba, elsiocb);
  3522. return 1;
  3523. }
  3524. return 0;
  3525. }
  3526. /**
  3527. * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
  3528. * @vport: pointer to a virtual N_Port data structure.
  3529. * @rejectError:
  3530. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3531. * @ndlp: pointer to a node-list data structure.
  3532. * @mbox: pointer to the driver internal queue element for mailbox command.
  3533. *
  3534. * This routine prepares and issue an Reject (RJT) response IOCB
  3535. * command. If a @mbox pointer is passed in, it will be put into the
  3536. * context_un.mbox field of the IOCB for the completion callback function
  3537. * to issue to the HBA later.
  3538. *
  3539. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3540. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3541. * will be stored into the context1 field of the IOCB for the completion
  3542. * callback function to the reject response ELS IOCB command.
  3543. *
  3544. * Return code
  3545. * 0 - Successfully issued reject response
  3546. * 1 - Failed to issue reject response
  3547. **/
  3548. int
  3549. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  3550. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  3551. LPFC_MBOXQ_t *mbox)
  3552. {
  3553. struct lpfc_hba *phba = vport->phba;
  3554. IOCB_t *icmd;
  3555. IOCB_t *oldcmd;
  3556. struct lpfc_iocbq *elsiocb;
  3557. struct lpfc_sli *psli;
  3558. uint8_t *pcmd;
  3559. uint16_t cmdsize;
  3560. int rc;
  3561. psli = &phba->sli;
  3562. cmdsize = 2 * sizeof(uint32_t);
  3563. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3564. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  3565. if (!elsiocb)
  3566. return 1;
  3567. icmd = &elsiocb->iocb;
  3568. oldcmd = &oldiocb->iocb;
  3569. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3570. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3571. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3572. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  3573. pcmd += sizeof(uint32_t);
  3574. *((uint32_t *) (pcmd)) = rejectError;
  3575. if (mbox)
  3576. elsiocb->context_un.mbox = mbox;
  3577. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  3578. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3579. "0129 Xmit ELS RJT x%x response tag x%x "
  3580. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  3581. "rpi x%x\n",
  3582. rejectError, elsiocb->iotag,
  3583. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  3584. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  3585. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3586. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  3587. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  3588. phba->fc_stat.elsXmitLSRJT++;
  3589. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3590. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3591. if (rc == IOCB_ERROR) {
  3592. lpfc_els_free_iocb(phba, elsiocb);
  3593. return 1;
  3594. }
  3595. return 0;
  3596. }
  3597. /**
  3598. * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
  3599. * @vport: pointer to a virtual N_Port data structure.
  3600. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3601. * @ndlp: pointer to a node-list data structure.
  3602. *
  3603. * This routine prepares and issues an Accept (ACC) response to Address
  3604. * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
  3605. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  3606. *
  3607. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3608. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3609. * will be stored into the context1 field of the IOCB for the completion
  3610. * callback function to the ADISC Accept response ELS IOCB command.
  3611. *
  3612. * Return code
  3613. * 0 - Successfully issued acc adisc response
  3614. * 1 - Failed to issue adisc acc response
  3615. **/
  3616. int
  3617. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  3618. struct lpfc_nodelist *ndlp)
  3619. {
  3620. struct lpfc_hba *phba = vport->phba;
  3621. ADISC *ap;
  3622. IOCB_t *icmd, *oldcmd;
  3623. struct lpfc_iocbq *elsiocb;
  3624. uint8_t *pcmd;
  3625. uint16_t cmdsize;
  3626. int rc;
  3627. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  3628. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3629. ndlp->nlp_DID, ELS_CMD_ACC);
  3630. if (!elsiocb)
  3631. return 1;
  3632. icmd = &elsiocb->iocb;
  3633. oldcmd = &oldiocb->iocb;
  3634. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3635. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3636. /* Xmit ADISC ACC response tag <ulpIoTag> */
  3637. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3638. "0130 Xmit ADISC ACC response iotag x%x xri: "
  3639. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  3640. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3641. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3642. ndlp->nlp_rpi);
  3643. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3644. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3645. pcmd += sizeof(uint32_t);
  3646. ap = (ADISC *) (pcmd);
  3647. ap->hardAL_PA = phba->fc_pref_ALPA;
  3648. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  3649. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3650. ap->DID = be32_to_cpu(vport->fc_myDID);
  3651. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3652. "Issue ACC ADISC: did:x%x flg:x%x",
  3653. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3654. phba->fc_stat.elsXmitACC++;
  3655. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3656. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3657. if (rc == IOCB_ERROR) {
  3658. lpfc_els_free_iocb(phba, elsiocb);
  3659. return 1;
  3660. }
  3661. return 0;
  3662. }
  3663. /**
  3664. * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
  3665. * @vport: pointer to a virtual N_Port data structure.
  3666. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3667. * @ndlp: pointer to a node-list data structure.
  3668. *
  3669. * This routine prepares and issues an Accept (ACC) response to Process
  3670. * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
  3671. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  3672. *
  3673. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3674. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3675. * will be stored into the context1 field of the IOCB for the completion
  3676. * callback function to the PRLI Accept response ELS IOCB command.
  3677. *
  3678. * Return code
  3679. * 0 - Successfully issued acc prli response
  3680. * 1 - Failed to issue acc prli response
  3681. **/
  3682. int
  3683. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  3684. struct lpfc_nodelist *ndlp)
  3685. {
  3686. struct lpfc_hba *phba = vport->phba;
  3687. PRLI *npr;
  3688. lpfc_vpd_t *vpd;
  3689. IOCB_t *icmd;
  3690. IOCB_t *oldcmd;
  3691. struct lpfc_iocbq *elsiocb;
  3692. struct lpfc_sli *psli;
  3693. uint8_t *pcmd;
  3694. uint16_t cmdsize;
  3695. int rc;
  3696. psli = &phba->sli;
  3697. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  3698. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3699. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  3700. if (!elsiocb)
  3701. return 1;
  3702. icmd = &elsiocb->iocb;
  3703. oldcmd = &oldiocb->iocb;
  3704. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3705. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3706. /* Xmit PRLI ACC response tag <ulpIoTag> */
  3707. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3708. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  3709. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  3710. elsiocb->iotag, elsiocb->iocb.ulpContext,
  3711. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  3712. ndlp->nlp_rpi);
  3713. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3714. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  3715. pcmd += sizeof(uint32_t);
  3716. /* For PRLI, remainder of payload is PRLI parameter page */
  3717. memset(pcmd, 0, sizeof(PRLI));
  3718. npr = (PRLI *) pcmd;
  3719. vpd = &phba->vpd;
  3720. /*
  3721. * If the remote port is a target and our firmware version is 3.20 or
  3722. * later, set the following bits for FC-TAPE support.
  3723. */
  3724. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  3725. (vpd->rev.feaLevelHigh >= 0x02)) {
  3726. npr->ConfmComplAllowed = 1;
  3727. npr->Retry = 1;
  3728. npr->TaskRetryIdReq = 1;
  3729. }
  3730. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  3731. npr->estabImagePair = 1;
  3732. npr->readXferRdyDis = 1;
  3733. npr->ConfmComplAllowed = 1;
  3734. npr->prliType = PRLI_FCP_TYPE;
  3735. npr->initiatorFunc = 1;
  3736. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3737. "Issue ACC PRLI: did:x%x flg:x%x",
  3738. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3739. phba->fc_stat.elsXmitACC++;
  3740. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3741. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3742. if (rc == IOCB_ERROR) {
  3743. lpfc_els_free_iocb(phba, elsiocb);
  3744. return 1;
  3745. }
  3746. return 0;
  3747. }
  3748. /**
  3749. * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
  3750. * @vport: pointer to a virtual N_Port data structure.
  3751. * @format: rnid command format.
  3752. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3753. * @ndlp: pointer to a node-list data structure.
  3754. *
  3755. * This routine issues a Request Node Identification Data (RNID) Accept
  3756. * (ACC) response. It constructs the RNID ACC response command according to
  3757. * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
  3758. * issue the response. Note that this command does not need to hold the ndlp
  3759. * reference count for the callback. So, the ndlp reference count taken by
  3760. * the lpfc_prep_els_iocb() routine is put back and the context1 field of
  3761. * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
  3762. * there is no ndlp reference available.
  3763. *
  3764. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  3765. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  3766. * will be stored into the context1 field of the IOCB for the completion
  3767. * callback function. However, for the RNID Accept Response ELS command,
  3768. * this is undone later by this routine after the IOCB is allocated.
  3769. *
  3770. * Return code
  3771. * 0 - Successfully issued acc rnid response
  3772. * 1 - Failed to issue acc rnid response
  3773. **/
  3774. static int
  3775. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  3776. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3777. {
  3778. struct lpfc_hba *phba = vport->phba;
  3779. RNID *rn;
  3780. IOCB_t *icmd, *oldcmd;
  3781. struct lpfc_iocbq *elsiocb;
  3782. struct lpfc_sli *psli;
  3783. uint8_t *pcmd;
  3784. uint16_t cmdsize;
  3785. int rc;
  3786. psli = &phba->sli;
  3787. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  3788. + (2 * sizeof(struct lpfc_name));
  3789. if (format)
  3790. cmdsize += sizeof(RNID_TOP_DISC);
  3791. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3792. ndlp->nlp_DID, ELS_CMD_ACC);
  3793. if (!elsiocb)
  3794. return 1;
  3795. icmd = &elsiocb->iocb;
  3796. oldcmd = &oldiocb->iocb;
  3797. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  3798. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  3799. /* Xmit RNID ACC response tag <ulpIoTag> */
  3800. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3801. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  3802. elsiocb->iotag, elsiocb->iocb.ulpContext);
  3803. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3804. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3805. pcmd += sizeof(uint32_t);
  3806. memset(pcmd, 0, sizeof(RNID));
  3807. rn = (RNID *) (pcmd);
  3808. rn->Format = format;
  3809. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  3810. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  3811. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3812. switch (format) {
  3813. case 0:
  3814. rn->SpecificLen = 0;
  3815. break;
  3816. case RNID_TOPOLOGY_DISC:
  3817. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  3818. memcpy(&rn->un.topologyDisc.portName,
  3819. &vport->fc_portname, sizeof(struct lpfc_name));
  3820. rn->un.topologyDisc.unitType = RNID_HBA;
  3821. rn->un.topologyDisc.physPort = 0;
  3822. rn->un.topologyDisc.attachedNodes = 0;
  3823. break;
  3824. default:
  3825. rn->CommonLen = 0;
  3826. rn->SpecificLen = 0;
  3827. break;
  3828. }
  3829. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3830. "Issue ACC RNID: did:x%x flg:x%x",
  3831. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3832. phba->fc_stat.elsXmitACC++;
  3833. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3834. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3835. if (rc == IOCB_ERROR) {
  3836. lpfc_els_free_iocb(phba, elsiocb);
  3837. return 1;
  3838. }
  3839. return 0;
  3840. }
  3841. /**
  3842. * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
  3843. * @vport: pointer to a virtual N_Port data structure.
  3844. * @iocb: pointer to the lpfc command iocb data structure.
  3845. * @ndlp: pointer to a node-list data structure.
  3846. *
  3847. * Return
  3848. **/
  3849. static void
  3850. lpfc_els_clear_rrq(struct lpfc_vport *vport,
  3851. struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
  3852. {
  3853. struct lpfc_hba *phba = vport->phba;
  3854. uint8_t *pcmd;
  3855. struct RRQ *rrq;
  3856. uint16_t rxid;
  3857. uint16_t xri;
  3858. struct lpfc_node_rrq *prrq;
  3859. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
  3860. pcmd += sizeof(uint32_t);
  3861. rrq = (struct RRQ *)pcmd;
  3862. rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
  3863. rxid = bf_get(rrq_rxid, rrq);
  3864. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3865. "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
  3866. " x%x x%x\n",
  3867. be32_to_cpu(bf_get(rrq_did, rrq)),
  3868. bf_get(rrq_oxid, rrq),
  3869. rxid,
  3870. iocb->iotag, iocb->iocb.ulpContext);
  3871. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3872. "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
  3873. ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
  3874. if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
  3875. xri = bf_get(rrq_oxid, rrq);
  3876. else
  3877. xri = rxid;
  3878. prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
  3879. if (prrq)
  3880. lpfc_clr_rrq_active(phba, xri, prrq);
  3881. return;
  3882. }
  3883. /**
  3884. * lpfc_els_rsp_echo_acc - Issue echo acc response
  3885. * @vport: pointer to a virtual N_Port data structure.
  3886. * @data: pointer to echo data to return in the accept.
  3887. * @oldiocb: pointer to the original lpfc command iocb data structure.
  3888. * @ndlp: pointer to a node-list data structure.
  3889. *
  3890. * Return code
  3891. * 0 - Successfully issued acc echo response
  3892. * 1 - Failed to issue acc echo response
  3893. **/
  3894. static int
  3895. lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
  3896. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  3897. {
  3898. struct lpfc_hba *phba = vport->phba;
  3899. struct lpfc_iocbq *elsiocb;
  3900. struct lpfc_sli *psli;
  3901. uint8_t *pcmd;
  3902. uint16_t cmdsize;
  3903. int rc;
  3904. psli = &phba->sli;
  3905. cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
  3906. /* The accumulated length can exceed the BPL_SIZE. For
  3907. * now, use this as the limit
  3908. */
  3909. if (cmdsize > LPFC_BPL_SIZE)
  3910. cmdsize = LPFC_BPL_SIZE;
  3911. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  3912. ndlp->nlp_DID, ELS_CMD_ACC);
  3913. if (!elsiocb)
  3914. return 1;
  3915. elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
  3916. elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
  3917. /* Xmit ECHO ACC response tag <ulpIoTag> */
  3918. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3919. "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
  3920. elsiocb->iotag, elsiocb->iocb.ulpContext);
  3921. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3922. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  3923. pcmd += sizeof(uint32_t);
  3924. memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
  3925. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  3926. "Issue ACC ECHO: did:x%x flg:x%x",
  3927. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3928. phba->fc_stat.elsXmitACC++;
  3929. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  3930. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3931. if (rc == IOCB_ERROR) {
  3932. lpfc_els_free_iocb(phba, elsiocb);
  3933. return 1;
  3934. }
  3935. return 0;
  3936. }
  3937. /**
  3938. * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
  3939. * @vport: pointer to a host virtual N_Port data structure.
  3940. *
  3941. * This routine issues Address Discover (ADISC) ELS commands to those
  3942. * N_Ports which are in node port recovery state and ADISC has not been issued
  3943. * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
  3944. * lpfc_issue_els_adisc() routine, the per @vport number of discover count
  3945. * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
  3946. * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
  3947. * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
  3948. * IOCBs quit for later pick up. On the other hand, after walking through
  3949. * all the ndlps with the @vport and there is none ADISC IOCB issued, the
  3950. * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
  3951. * no more ADISC need to be sent.
  3952. *
  3953. * Return code
  3954. * The number of N_Ports with adisc issued.
  3955. **/
  3956. int
  3957. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  3958. {
  3959. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3960. struct lpfc_nodelist *ndlp, *next_ndlp;
  3961. int sentadisc = 0;
  3962. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  3963. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  3964. if (!NLP_CHK_NODE_ACT(ndlp))
  3965. continue;
  3966. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  3967. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  3968. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  3969. spin_lock_irq(shost->host_lock);
  3970. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  3971. spin_unlock_irq(shost->host_lock);
  3972. ndlp->nlp_prev_state = ndlp->nlp_state;
  3973. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  3974. lpfc_issue_els_adisc(vport, ndlp, 0);
  3975. sentadisc++;
  3976. vport->num_disc_nodes++;
  3977. if (vport->num_disc_nodes >=
  3978. vport->cfg_discovery_threads) {
  3979. spin_lock_irq(shost->host_lock);
  3980. vport->fc_flag |= FC_NLP_MORE;
  3981. spin_unlock_irq(shost->host_lock);
  3982. break;
  3983. }
  3984. }
  3985. }
  3986. if (sentadisc == 0) {
  3987. spin_lock_irq(shost->host_lock);
  3988. vport->fc_flag &= ~FC_NLP_MORE;
  3989. spin_unlock_irq(shost->host_lock);
  3990. }
  3991. return sentadisc;
  3992. }
  3993. /**
  3994. * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
  3995. * @vport: pointer to a host virtual N_Port data structure.
  3996. *
  3997. * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
  3998. * which are in node port recovery state, with a @vport. Each time an ELS
  3999. * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
  4000. * the per @vport number of discover count (num_disc_nodes) shall be
  4001. * incremented. If the num_disc_nodes reaches a pre-configured threshold
  4002. * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
  4003. * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
  4004. * later pick up. On the other hand, after walking through all the ndlps with
  4005. * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
  4006. * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
  4007. * PLOGI need to be sent.
  4008. *
  4009. * Return code
  4010. * The number of N_Ports with plogi issued.
  4011. **/
  4012. int
  4013. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  4014. {
  4015. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4016. struct lpfc_nodelist *ndlp, *next_ndlp;
  4017. int sentplogi = 0;
  4018. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  4019. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  4020. if (!NLP_CHK_NODE_ACT(ndlp))
  4021. continue;
  4022. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  4023. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  4024. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  4025. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  4026. ndlp->nlp_prev_state = ndlp->nlp_state;
  4027. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  4028. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  4029. sentplogi++;
  4030. vport->num_disc_nodes++;
  4031. if (vport->num_disc_nodes >=
  4032. vport->cfg_discovery_threads) {
  4033. spin_lock_irq(shost->host_lock);
  4034. vport->fc_flag |= FC_NLP_MORE;
  4035. spin_unlock_irq(shost->host_lock);
  4036. break;
  4037. }
  4038. }
  4039. }
  4040. if (sentplogi) {
  4041. lpfc_set_disctmo(vport);
  4042. }
  4043. else {
  4044. spin_lock_irq(shost->host_lock);
  4045. vport->fc_flag &= ~FC_NLP_MORE;
  4046. spin_unlock_irq(shost->host_lock);
  4047. }
  4048. return sentplogi;
  4049. }
  4050. /**
  4051. * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
  4052. * @vport: pointer to a host virtual N_Port data structure.
  4053. *
  4054. * This routine cleans up any Registration State Change Notification
  4055. * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
  4056. * @vport together with the host_lock is used to prevent multiple thread
  4057. * trying to access the RSCN array on a same @vport at the same time.
  4058. **/
  4059. void
  4060. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  4061. {
  4062. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4063. struct lpfc_hba *phba = vport->phba;
  4064. int i;
  4065. spin_lock_irq(shost->host_lock);
  4066. if (vport->fc_rscn_flush) {
  4067. /* Another thread is walking fc_rscn_id_list on this vport */
  4068. spin_unlock_irq(shost->host_lock);
  4069. return;
  4070. }
  4071. /* Indicate we are walking lpfc_els_flush_rscn on this vport */
  4072. vport->fc_rscn_flush = 1;
  4073. spin_unlock_irq(shost->host_lock);
  4074. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  4075. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  4076. vport->fc_rscn_id_list[i] = NULL;
  4077. }
  4078. spin_lock_irq(shost->host_lock);
  4079. vport->fc_rscn_id_cnt = 0;
  4080. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  4081. spin_unlock_irq(shost->host_lock);
  4082. lpfc_can_disctmo(vport);
  4083. /* Indicate we are done walking this fc_rscn_id_list */
  4084. vport->fc_rscn_flush = 0;
  4085. }
  4086. /**
  4087. * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
  4088. * @vport: pointer to a host virtual N_Port data structure.
  4089. * @did: remote destination port identifier.
  4090. *
  4091. * This routine checks whether there is any pending Registration State
  4092. * Configuration Notification (RSCN) to a @did on @vport.
  4093. *
  4094. * Return code
  4095. * None zero - The @did matched with a pending rscn
  4096. * 0 - not able to match @did with a pending rscn
  4097. **/
  4098. int
  4099. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  4100. {
  4101. D_ID ns_did;
  4102. D_ID rscn_did;
  4103. uint32_t *lp;
  4104. uint32_t payload_len, i;
  4105. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4106. ns_did.un.word = did;
  4107. /* Never match fabric nodes for RSCNs */
  4108. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  4109. return 0;
  4110. /* If we are doing a FULL RSCN rediscovery, match everything */
  4111. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  4112. return did;
  4113. spin_lock_irq(shost->host_lock);
  4114. if (vport->fc_rscn_flush) {
  4115. /* Another thread is walking fc_rscn_id_list on this vport */
  4116. spin_unlock_irq(shost->host_lock);
  4117. return 0;
  4118. }
  4119. /* Indicate we are walking fc_rscn_id_list on this vport */
  4120. vport->fc_rscn_flush = 1;
  4121. spin_unlock_irq(shost->host_lock);
  4122. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  4123. lp = vport->fc_rscn_id_list[i]->virt;
  4124. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  4125. payload_len -= sizeof(uint32_t); /* take off word 0 */
  4126. while (payload_len) {
  4127. rscn_did.un.word = be32_to_cpu(*lp++);
  4128. payload_len -= sizeof(uint32_t);
  4129. switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
  4130. case RSCN_ADDRESS_FORMAT_PORT:
  4131. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  4132. && (ns_did.un.b.area == rscn_did.un.b.area)
  4133. && (ns_did.un.b.id == rscn_did.un.b.id))
  4134. goto return_did_out;
  4135. break;
  4136. case RSCN_ADDRESS_FORMAT_AREA:
  4137. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  4138. && (ns_did.un.b.area == rscn_did.un.b.area))
  4139. goto return_did_out;
  4140. break;
  4141. case RSCN_ADDRESS_FORMAT_DOMAIN:
  4142. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  4143. goto return_did_out;
  4144. break;
  4145. case RSCN_ADDRESS_FORMAT_FABRIC:
  4146. goto return_did_out;
  4147. }
  4148. }
  4149. }
  4150. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  4151. vport->fc_rscn_flush = 0;
  4152. return 0;
  4153. return_did_out:
  4154. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  4155. vport->fc_rscn_flush = 0;
  4156. return did;
  4157. }
  4158. /**
  4159. * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
  4160. * @vport: pointer to a host virtual N_Port data structure.
  4161. *
  4162. * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
  4163. * state machine for a @vport's nodes that are with pending RSCN (Registration
  4164. * State Change Notification).
  4165. *
  4166. * Return code
  4167. * 0 - Successful (currently alway return 0)
  4168. **/
  4169. static int
  4170. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  4171. {
  4172. struct lpfc_nodelist *ndlp = NULL;
  4173. /* Move all affected nodes by pending RSCNs to NPR state. */
  4174. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4175. if (!NLP_CHK_NODE_ACT(ndlp) ||
  4176. (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
  4177. !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
  4178. continue;
  4179. lpfc_disc_state_machine(vport, ndlp, NULL,
  4180. NLP_EVT_DEVICE_RECOVERY);
  4181. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  4182. }
  4183. return 0;
  4184. }
  4185. /**
  4186. * lpfc_send_rscn_event - Send an RSCN event to management application
  4187. * @vport: pointer to a host virtual N_Port data structure.
  4188. * @cmdiocb: pointer to lpfc command iocb data structure.
  4189. *
  4190. * lpfc_send_rscn_event sends an RSCN netlink event to management
  4191. * applications.
  4192. */
  4193. static void
  4194. lpfc_send_rscn_event(struct lpfc_vport *vport,
  4195. struct lpfc_iocbq *cmdiocb)
  4196. {
  4197. struct lpfc_dmabuf *pcmd;
  4198. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4199. uint32_t *payload_ptr;
  4200. uint32_t payload_len;
  4201. struct lpfc_rscn_event_header *rscn_event_data;
  4202. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4203. payload_ptr = (uint32_t *) pcmd->virt;
  4204. payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
  4205. rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
  4206. payload_len, GFP_KERNEL);
  4207. if (!rscn_event_data) {
  4208. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4209. "0147 Failed to allocate memory for RSCN event\n");
  4210. return;
  4211. }
  4212. rscn_event_data->event_type = FC_REG_RSCN_EVENT;
  4213. rscn_event_data->payload_length = payload_len;
  4214. memcpy(rscn_event_data->rscn_payload, payload_ptr,
  4215. payload_len);
  4216. fc_host_post_vendor_event(shost,
  4217. fc_get_event_number(),
  4218. sizeof(struct lpfc_els_event_header) + payload_len,
  4219. (char *)rscn_event_data,
  4220. LPFC_NL_VENDOR_ID);
  4221. kfree(rscn_event_data);
  4222. }
  4223. /**
  4224. * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
  4225. * @vport: pointer to a host virtual N_Port data structure.
  4226. * @cmdiocb: pointer to lpfc command iocb data structure.
  4227. * @ndlp: pointer to a node-list data structure.
  4228. *
  4229. * This routine processes an unsolicited RSCN (Registration State Change
  4230. * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
  4231. * to invoke fc_host_post_event() routine to the FC transport layer. If the
  4232. * discover state machine is about to begin discovery, it just accepts the
  4233. * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
  4234. * contains N_Port IDs for other vports on this HBA, it just accepts the
  4235. * RSCN and ignore processing it. If the state machine is in the recovery
  4236. * state, the fc_rscn_id_list of this @vport is walked and the
  4237. * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
  4238. * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
  4239. * routine is invoked to handle the RSCN event.
  4240. *
  4241. * Return code
  4242. * 0 - Just sent the acc response
  4243. * 1 - Sent the acc response and waited for name server completion
  4244. **/
  4245. static int
  4246. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4247. struct lpfc_nodelist *ndlp)
  4248. {
  4249. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4250. struct lpfc_hba *phba = vport->phba;
  4251. struct lpfc_dmabuf *pcmd;
  4252. uint32_t *lp, *datap;
  4253. IOCB_t *icmd;
  4254. uint32_t payload_len, length, nportid, *cmd;
  4255. int rscn_cnt;
  4256. int rscn_id = 0, hba_id = 0;
  4257. int i;
  4258. icmd = &cmdiocb->iocb;
  4259. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4260. lp = (uint32_t *) pcmd->virt;
  4261. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  4262. payload_len -= sizeof(uint32_t); /* take off word 0 */
  4263. /* RSCN received */
  4264. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4265. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  4266. vport->fc_flag, payload_len, *lp,
  4267. vport->fc_rscn_id_cnt);
  4268. /* Send an RSCN event to the management application */
  4269. lpfc_send_rscn_event(vport, cmdiocb);
  4270. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  4271. fc_host_post_event(shost, fc_get_event_number(),
  4272. FCH_EVT_RSCN, lp[i]);
  4273. /* If we are about to begin discovery, just ACC the RSCN.
  4274. * Discovery processing will satisfy it.
  4275. */
  4276. if (vport->port_state <= LPFC_NS_QRY) {
  4277. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4278. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  4279. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4280. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4281. return 0;
  4282. }
  4283. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  4284. * just ACC and ignore it.
  4285. */
  4286. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  4287. !(vport->cfg_peer_port_login)) {
  4288. i = payload_len;
  4289. datap = lp;
  4290. while (i > 0) {
  4291. nportid = *datap++;
  4292. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  4293. i -= sizeof(uint32_t);
  4294. rscn_id++;
  4295. if (lpfc_find_vport_by_did(phba, nportid))
  4296. hba_id++;
  4297. }
  4298. if (rscn_id == hba_id) {
  4299. /* ALL NPortIDs in RSCN are on HBA */
  4300. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4301. "0219 Ignore RSCN "
  4302. "Data: x%x x%x x%x x%x\n",
  4303. vport->fc_flag, payload_len,
  4304. *lp, vport->fc_rscn_id_cnt);
  4305. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4306. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  4307. ndlp->nlp_DID, vport->port_state,
  4308. ndlp->nlp_flag);
  4309. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  4310. ndlp, NULL);
  4311. return 0;
  4312. }
  4313. }
  4314. spin_lock_irq(shost->host_lock);
  4315. if (vport->fc_rscn_flush) {
  4316. /* Another thread is walking fc_rscn_id_list on this vport */
  4317. vport->fc_flag |= FC_RSCN_DISCOVERY;
  4318. spin_unlock_irq(shost->host_lock);
  4319. /* Send back ACC */
  4320. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4321. return 0;
  4322. }
  4323. /* Indicate we are walking fc_rscn_id_list on this vport */
  4324. vport->fc_rscn_flush = 1;
  4325. spin_unlock_irq(shost->host_lock);
  4326. /* Get the array count after successfully have the token */
  4327. rscn_cnt = vport->fc_rscn_id_cnt;
  4328. /* If we are already processing an RSCN, save the received
  4329. * RSCN payload buffer, cmdiocb->context2 to process later.
  4330. */
  4331. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  4332. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4333. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  4334. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4335. spin_lock_irq(shost->host_lock);
  4336. vport->fc_flag |= FC_RSCN_DEFERRED;
  4337. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  4338. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  4339. vport->fc_flag |= FC_RSCN_MODE;
  4340. spin_unlock_irq(shost->host_lock);
  4341. if (rscn_cnt) {
  4342. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  4343. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  4344. }
  4345. if ((rscn_cnt) &&
  4346. (payload_len + length <= LPFC_BPL_SIZE)) {
  4347. *cmd &= ELS_CMD_MASK;
  4348. *cmd |= cpu_to_be32(payload_len + length);
  4349. memcpy(((uint8_t *)cmd) + length, lp,
  4350. payload_len);
  4351. } else {
  4352. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  4353. vport->fc_rscn_id_cnt++;
  4354. /* If we zero, cmdiocb->context2, the calling
  4355. * routine will not try to free it.
  4356. */
  4357. cmdiocb->context2 = NULL;
  4358. }
  4359. /* Deferred RSCN */
  4360. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4361. "0235 Deferred RSCN "
  4362. "Data: x%x x%x x%x\n",
  4363. vport->fc_rscn_id_cnt, vport->fc_flag,
  4364. vport->port_state);
  4365. } else {
  4366. vport->fc_flag |= FC_RSCN_DISCOVERY;
  4367. spin_unlock_irq(shost->host_lock);
  4368. /* ReDiscovery RSCN */
  4369. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4370. "0234 ReDiscovery RSCN "
  4371. "Data: x%x x%x x%x\n",
  4372. vport->fc_rscn_id_cnt, vport->fc_flag,
  4373. vport->port_state);
  4374. }
  4375. /* Indicate we are done walking fc_rscn_id_list on this vport */
  4376. vport->fc_rscn_flush = 0;
  4377. /* Send back ACC */
  4378. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4379. /* send RECOVERY event for ALL nodes that match RSCN payload */
  4380. lpfc_rscn_recovery_check(vport);
  4381. spin_lock_irq(shost->host_lock);
  4382. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  4383. spin_unlock_irq(shost->host_lock);
  4384. return 0;
  4385. }
  4386. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  4387. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  4388. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  4389. spin_lock_irq(shost->host_lock);
  4390. vport->fc_flag |= FC_RSCN_MODE;
  4391. spin_unlock_irq(shost->host_lock);
  4392. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  4393. /* Indicate we are done walking fc_rscn_id_list on this vport */
  4394. vport->fc_rscn_flush = 0;
  4395. /*
  4396. * If we zero, cmdiocb->context2, the calling routine will
  4397. * not try to free it.
  4398. */
  4399. cmdiocb->context2 = NULL;
  4400. lpfc_set_disctmo(vport);
  4401. /* Send back ACC */
  4402. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4403. /* send RECOVERY event for ALL nodes that match RSCN payload */
  4404. lpfc_rscn_recovery_check(vport);
  4405. return lpfc_els_handle_rscn(vport);
  4406. }
  4407. /**
  4408. * lpfc_els_handle_rscn - Handle rscn for a vport
  4409. * @vport: pointer to a host virtual N_Port data structure.
  4410. *
  4411. * This routine handles the Registration State Configuration Notification
  4412. * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
  4413. * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
  4414. * if the ndlp to NameServer exists, a Common Transport (CT) command to the
  4415. * NameServer shall be issued. If CT command to the NameServer fails to be
  4416. * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
  4417. * RSCN activities with the @vport.
  4418. *
  4419. * Return code
  4420. * 0 - Cleaned up rscn on the @vport
  4421. * 1 - Wait for plogi to name server before proceed
  4422. **/
  4423. int
  4424. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  4425. {
  4426. struct lpfc_nodelist *ndlp;
  4427. struct lpfc_hba *phba = vport->phba;
  4428. /* Ignore RSCN if the port is being torn down. */
  4429. if (vport->load_flag & FC_UNLOADING) {
  4430. lpfc_els_flush_rscn(vport);
  4431. return 0;
  4432. }
  4433. /* Start timer for RSCN processing */
  4434. lpfc_set_disctmo(vport);
  4435. /* RSCN processed */
  4436. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  4437. "0215 RSCN processed Data: x%x x%x x%x x%x\n",
  4438. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  4439. vport->port_state);
  4440. /* To process RSCN, first compare RSCN data with NameServer */
  4441. vport->fc_ns_retry = 0;
  4442. vport->num_disc_nodes = 0;
  4443. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4444. if (ndlp && NLP_CHK_NODE_ACT(ndlp)
  4445. && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  4446. /* Good ndlp, issue CT Request to NameServer */
  4447. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
  4448. /* Wait for NameServer query cmpl before we can
  4449. continue */
  4450. return 1;
  4451. } else {
  4452. /* If login to NameServer does not exist, issue one */
  4453. /* Good status, issue PLOGI to NameServer */
  4454. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4455. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  4456. /* Wait for NameServer login cmpl before we can
  4457. continue */
  4458. return 1;
  4459. if (ndlp) {
  4460. ndlp = lpfc_enable_node(vport, ndlp,
  4461. NLP_STE_PLOGI_ISSUE);
  4462. if (!ndlp) {
  4463. lpfc_els_flush_rscn(vport);
  4464. return 0;
  4465. }
  4466. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  4467. } else {
  4468. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  4469. if (!ndlp) {
  4470. lpfc_els_flush_rscn(vport);
  4471. return 0;
  4472. }
  4473. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  4474. ndlp->nlp_prev_state = ndlp->nlp_state;
  4475. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  4476. }
  4477. ndlp->nlp_type |= NLP_FABRIC;
  4478. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  4479. /* Wait for NameServer login cmpl before we can
  4480. * continue
  4481. */
  4482. return 1;
  4483. }
  4484. lpfc_els_flush_rscn(vport);
  4485. return 0;
  4486. }
  4487. /**
  4488. * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
  4489. * @vport: pointer to a host virtual N_Port data structure.
  4490. * @cmdiocb: pointer to lpfc command iocb data structure.
  4491. * @ndlp: pointer to a node-list data structure.
  4492. *
  4493. * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
  4494. * unsolicited event. An unsolicited FLOGI can be received in a point-to-
  4495. * point topology. As an unsolicited FLOGI should not be received in a loop
  4496. * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
  4497. * lpfc_check_sparm() routine is invoked to check the parameters in the
  4498. * unsolicited FLOGI. If parameters validation failed, the routine
  4499. * lpfc_els_rsp_reject() shall be called with reject reason code set to
  4500. * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
  4501. * FLOGI shall be compared with the Port WWN of the @vport to determine who
  4502. * will initiate PLOGI. The higher lexicographical value party shall has
  4503. * higher priority (as the winning port) and will initiate PLOGI and
  4504. * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
  4505. * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
  4506. * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
  4507. *
  4508. * Return code
  4509. * 0 - Successfully processed the unsolicited flogi
  4510. * 1 - Failed to process the unsolicited flogi
  4511. **/
  4512. static int
  4513. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4514. struct lpfc_nodelist *ndlp)
  4515. {
  4516. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4517. struct lpfc_hba *phba = vport->phba;
  4518. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4519. uint32_t *lp = (uint32_t *) pcmd->virt;
  4520. IOCB_t *icmd = &cmdiocb->iocb;
  4521. struct serv_parm *sp;
  4522. LPFC_MBOXQ_t *mbox;
  4523. struct ls_rjt stat;
  4524. uint32_t cmd, did;
  4525. int rc;
  4526. cmd = *lp++;
  4527. sp = (struct serv_parm *) lp;
  4528. /* FLOGI received */
  4529. lpfc_set_disctmo(vport);
  4530. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  4531. /* We should never receive a FLOGI in loop mode, ignore it */
  4532. did = icmd->un.elsreq64.remoteID;
  4533. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  4534. Loop Mode */
  4535. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4536. "0113 An FLOGI ELS command x%x was "
  4537. "received from DID x%x in Loop Mode\n",
  4538. cmd, did);
  4539. return 1;
  4540. }
  4541. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
  4542. /* For a FLOGI we accept, then if our portname is greater
  4543. * then the remote portname we initiate Nport login.
  4544. */
  4545. rc = memcmp(&vport->fc_portname, &sp->portName,
  4546. sizeof(struct lpfc_name));
  4547. if (!rc) {
  4548. if (phba->sli_rev < LPFC_SLI_REV4) {
  4549. mbox = mempool_alloc(phba->mbox_mem_pool,
  4550. GFP_KERNEL);
  4551. if (!mbox)
  4552. return 1;
  4553. lpfc_linkdown(phba);
  4554. lpfc_init_link(phba, mbox,
  4555. phba->cfg_topology,
  4556. phba->cfg_link_speed);
  4557. mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  4558. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4559. mbox->vport = vport;
  4560. rc = lpfc_sli_issue_mbox(phba, mbox,
  4561. MBX_NOWAIT);
  4562. lpfc_set_loopback_flag(phba);
  4563. if (rc == MBX_NOT_FINISHED)
  4564. mempool_free(mbox, phba->mbox_mem_pool);
  4565. return 1;
  4566. } else {
  4567. /* abort the flogi coming back to ourselves
  4568. * due to external loopback on the port.
  4569. */
  4570. lpfc_els_abort_flogi(phba);
  4571. return 0;
  4572. }
  4573. } else if (rc > 0) { /* greater than */
  4574. spin_lock_irq(shost->host_lock);
  4575. vport->fc_flag |= FC_PT2PT_PLOGI;
  4576. spin_unlock_irq(shost->host_lock);
  4577. /* If we have the high WWPN we can assign our own
  4578. * myDID; otherwise, we have to WAIT for a PLOGI
  4579. * from the remote NPort to find out what it
  4580. * will be.
  4581. */
  4582. vport->fc_myDID = PT2PT_LocalID;
  4583. }
  4584. /*
  4585. * The vport state should go to LPFC_FLOGI only
  4586. * AFTER we issue a FLOGI, not receive one.
  4587. */
  4588. spin_lock_irq(shost->host_lock);
  4589. vport->fc_flag |= FC_PT2PT;
  4590. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  4591. spin_unlock_irq(shost->host_lock);
  4592. /*
  4593. * We temporarily set fc_myDID to make it look like we are
  4594. * a Fabric. This is done just so we end up with the right
  4595. * did / sid on the FLOGI ACC rsp.
  4596. */
  4597. did = vport->fc_myDID;
  4598. vport->fc_myDID = Fabric_DID;
  4599. } else {
  4600. /* Reject this request because invalid parameters */
  4601. stat.un.b.lsRjtRsvd0 = 0;
  4602. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4603. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  4604. stat.un.b.vendorUnique = 0;
  4605. /*
  4606. * We temporarily set fc_myDID to make it look like we are
  4607. * a Fabric. This is done just so we end up with the right
  4608. * did / sid on the FLOGI LS_RJT rsp.
  4609. */
  4610. did = vport->fc_myDID;
  4611. vport->fc_myDID = Fabric_DID;
  4612. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  4613. NULL);
  4614. /* Now lets put fc_myDID back to what its supposed to be */
  4615. vport->fc_myDID = did;
  4616. return 1;
  4617. }
  4618. /* Send back ACC */
  4619. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  4620. /* Now lets put fc_myDID back to what its supposed to be */
  4621. vport->fc_myDID = did;
  4622. if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
  4623. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4624. if (!mbox)
  4625. goto fail;
  4626. lpfc_config_link(phba, mbox);
  4627. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4628. mbox->vport = vport;
  4629. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4630. if (rc == MBX_NOT_FINISHED) {
  4631. mempool_free(mbox, phba->mbox_mem_pool);
  4632. goto fail;
  4633. }
  4634. }
  4635. return 0;
  4636. fail:
  4637. return 1;
  4638. }
  4639. /**
  4640. * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
  4641. * @vport: pointer to a host virtual N_Port data structure.
  4642. * @cmdiocb: pointer to lpfc command iocb data structure.
  4643. * @ndlp: pointer to a node-list data structure.
  4644. *
  4645. * This routine processes Request Node Identification Data (RNID) IOCB
  4646. * received as an ELS unsolicited event. Only when the RNID specified format
  4647. * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
  4648. * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
  4649. * Accept (ACC) the RNID ELS command. All the other RNID formats are
  4650. * rejected by invoking the lpfc_els_rsp_reject() routine.
  4651. *
  4652. * Return code
  4653. * 0 - Successfully processed rnid iocb (currently always return 0)
  4654. **/
  4655. static int
  4656. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4657. struct lpfc_nodelist *ndlp)
  4658. {
  4659. struct lpfc_dmabuf *pcmd;
  4660. uint32_t *lp;
  4661. IOCB_t *icmd;
  4662. RNID *rn;
  4663. struct ls_rjt stat;
  4664. uint32_t cmd, did;
  4665. icmd = &cmdiocb->iocb;
  4666. did = icmd->un.elsreq64.remoteID;
  4667. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4668. lp = (uint32_t *) pcmd->virt;
  4669. cmd = *lp++;
  4670. rn = (RNID *) lp;
  4671. /* RNID received */
  4672. switch (rn->Format) {
  4673. case 0:
  4674. case RNID_TOPOLOGY_DISC:
  4675. /* Send back ACC */
  4676. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  4677. break;
  4678. default:
  4679. /* Reject this request because format not supported */
  4680. stat.un.b.lsRjtRsvd0 = 0;
  4681. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4682. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4683. stat.un.b.vendorUnique = 0;
  4684. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  4685. NULL);
  4686. }
  4687. return 0;
  4688. }
  4689. /**
  4690. * lpfc_els_rcv_echo - Process an unsolicited echo iocb
  4691. * @vport: pointer to a host virtual N_Port data structure.
  4692. * @cmdiocb: pointer to lpfc command iocb data structure.
  4693. * @ndlp: pointer to a node-list data structure.
  4694. *
  4695. * Return code
  4696. * 0 - Successfully processed echo iocb (currently always return 0)
  4697. **/
  4698. static int
  4699. lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4700. struct lpfc_nodelist *ndlp)
  4701. {
  4702. uint8_t *pcmd;
  4703. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  4704. /* skip over first word of echo command to find echo data */
  4705. pcmd += sizeof(uint32_t);
  4706. lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
  4707. return 0;
  4708. }
  4709. /**
  4710. * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
  4711. * @vport: pointer to a host virtual N_Port data structure.
  4712. * @cmdiocb: pointer to lpfc command iocb data structure.
  4713. * @ndlp: pointer to a node-list data structure.
  4714. *
  4715. * This routine processes a Link Incident Report Registration(LIRR) IOCB
  4716. * received as an ELS unsolicited event. Currently, this function just invokes
  4717. * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
  4718. *
  4719. * Return code
  4720. * 0 - Successfully processed lirr iocb (currently always return 0)
  4721. **/
  4722. static int
  4723. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4724. struct lpfc_nodelist *ndlp)
  4725. {
  4726. struct ls_rjt stat;
  4727. /* For now, unconditionally reject this command */
  4728. stat.un.b.lsRjtRsvd0 = 0;
  4729. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4730. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4731. stat.un.b.vendorUnique = 0;
  4732. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  4733. return 0;
  4734. }
  4735. /**
  4736. * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
  4737. * @vport: pointer to a host virtual N_Port data structure.
  4738. * @cmdiocb: pointer to lpfc command iocb data structure.
  4739. * @ndlp: pointer to a node-list data structure.
  4740. *
  4741. * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
  4742. * received as an ELS unsolicited event. A request to RRQ shall only
  4743. * be accepted if the Originator Nx_Port N_Port_ID or the Responder
  4744. * Nx_Port N_Port_ID of the target Exchange is the same as the
  4745. * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
  4746. * not accepted, an LS_RJT with reason code "Unable to perform
  4747. * command request" and reason code explanation "Invalid Originator
  4748. * S_ID" shall be returned. For now, we just unconditionally accept
  4749. * RRQ from the target.
  4750. **/
  4751. static void
  4752. lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4753. struct lpfc_nodelist *ndlp)
  4754. {
  4755. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  4756. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  4757. lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
  4758. }
  4759. /**
  4760. * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
  4761. * @phba: pointer to lpfc hba data structure.
  4762. * @pmb: pointer to the driver internal queue element for mailbox command.
  4763. *
  4764. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  4765. * mailbox command. This callback function is to actually send the Accept
  4766. * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
  4767. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  4768. * mailbox command, constructs the RPS response with the link statistics
  4769. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  4770. * response to the RPS.
  4771. *
  4772. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4773. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4774. * will be stored into the context1 field of the IOCB for the completion
  4775. * callback function to the RPS Accept Response ELS IOCB command.
  4776. *
  4777. **/
  4778. static void
  4779. lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4780. {
  4781. MAILBOX_t *mb;
  4782. IOCB_t *icmd;
  4783. struct RLS_RSP *rls_rsp;
  4784. uint8_t *pcmd;
  4785. struct lpfc_iocbq *elsiocb;
  4786. struct lpfc_nodelist *ndlp;
  4787. uint16_t oxid;
  4788. uint16_t rxid;
  4789. uint32_t cmdsize;
  4790. mb = &pmb->u.mb;
  4791. ndlp = (struct lpfc_nodelist *) pmb->context2;
  4792. rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
  4793. oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
  4794. pmb->context1 = NULL;
  4795. pmb->context2 = NULL;
  4796. if (mb->mbxStatus) {
  4797. mempool_free(pmb, phba->mbox_mem_pool);
  4798. return;
  4799. }
  4800. cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
  4801. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  4802. lpfc_max_els_tries, ndlp,
  4803. ndlp->nlp_DID, ELS_CMD_ACC);
  4804. /* Decrement the ndlp reference count from previous mbox command */
  4805. lpfc_nlp_put(ndlp);
  4806. if (!elsiocb) {
  4807. mempool_free(pmb, phba->mbox_mem_pool);
  4808. return;
  4809. }
  4810. icmd = &elsiocb->iocb;
  4811. icmd->ulpContext = rxid;
  4812. icmd->unsli3.rcvsli3.ox_id = oxid;
  4813. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4814. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4815. pcmd += sizeof(uint32_t); /* Skip past command */
  4816. rls_rsp = (struct RLS_RSP *)pcmd;
  4817. rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  4818. rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  4819. rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  4820. rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  4821. rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  4822. rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  4823. mempool_free(pmb, phba->mbox_mem_pool);
  4824. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  4825. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  4826. "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
  4827. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  4828. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4829. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4830. ndlp->nlp_rpi);
  4831. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4832. phba->fc_stat.elsXmitACC++;
  4833. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  4834. lpfc_els_free_iocb(phba, elsiocb);
  4835. }
  4836. /**
  4837. * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
  4838. * @phba: pointer to lpfc hba data structure.
  4839. * @pmb: pointer to the driver internal queue element for mailbox command.
  4840. *
  4841. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  4842. * mailbox command. This callback function is to actually send the Accept
  4843. * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
  4844. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  4845. * mailbox command, constructs the RPS response with the link statistics
  4846. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  4847. * response to the RPS.
  4848. *
  4849. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4850. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4851. * will be stored into the context1 field of the IOCB for the completion
  4852. * callback function to the RPS Accept Response ELS IOCB command.
  4853. *
  4854. **/
  4855. static void
  4856. lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4857. {
  4858. MAILBOX_t *mb;
  4859. IOCB_t *icmd;
  4860. RPS_RSP *rps_rsp;
  4861. uint8_t *pcmd;
  4862. struct lpfc_iocbq *elsiocb;
  4863. struct lpfc_nodelist *ndlp;
  4864. uint16_t status;
  4865. uint16_t oxid;
  4866. uint16_t rxid;
  4867. uint32_t cmdsize;
  4868. mb = &pmb->u.mb;
  4869. ndlp = (struct lpfc_nodelist *) pmb->context2;
  4870. rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
  4871. oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
  4872. pmb->context1 = NULL;
  4873. pmb->context2 = NULL;
  4874. if (mb->mbxStatus) {
  4875. mempool_free(pmb, phba->mbox_mem_pool);
  4876. return;
  4877. }
  4878. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  4879. mempool_free(pmb, phba->mbox_mem_pool);
  4880. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  4881. lpfc_max_els_tries, ndlp,
  4882. ndlp->nlp_DID, ELS_CMD_ACC);
  4883. /* Decrement the ndlp reference count from previous mbox command */
  4884. lpfc_nlp_put(ndlp);
  4885. if (!elsiocb)
  4886. return;
  4887. icmd = &elsiocb->iocb;
  4888. icmd->ulpContext = rxid;
  4889. icmd->unsli3.rcvsli3.ox_id = oxid;
  4890. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  4891. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4892. pcmd += sizeof(uint32_t); /* Skip past command */
  4893. rps_rsp = (RPS_RSP *)pcmd;
  4894. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
  4895. status = 0x10;
  4896. else
  4897. status = 0x8;
  4898. if (phba->pport->fc_flag & FC_FABRIC)
  4899. status |= 0x4;
  4900. rps_rsp->rsvd1 = 0;
  4901. rps_rsp->portStatus = cpu_to_be16(status);
  4902. rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  4903. rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  4904. rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  4905. rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  4906. rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  4907. rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  4908. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  4909. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  4910. "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  4911. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  4912. elsiocb->iotag, elsiocb->iocb.ulpContext,
  4913. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4914. ndlp->nlp_rpi);
  4915. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  4916. phba->fc_stat.elsXmitACC++;
  4917. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  4918. lpfc_els_free_iocb(phba, elsiocb);
  4919. return;
  4920. }
  4921. /**
  4922. * lpfc_els_rcv_rls - Process an unsolicited rls iocb
  4923. * @vport: pointer to a host virtual N_Port data structure.
  4924. * @cmdiocb: pointer to lpfc command iocb data structure.
  4925. * @ndlp: pointer to a node-list data structure.
  4926. *
  4927. * This routine processes Read Port Status (RPL) IOCB received as an
  4928. * ELS unsolicited event. It first checks the remote port state. If the
  4929. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  4930. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  4931. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  4932. * for reading the HBA link statistics. It is for the callback function,
  4933. * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
  4934. * to actually sending out RPL Accept (ACC) response.
  4935. *
  4936. * Return codes
  4937. * 0 - Successfully processed rls iocb (currently always return 0)
  4938. **/
  4939. static int
  4940. lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  4941. struct lpfc_nodelist *ndlp)
  4942. {
  4943. struct lpfc_hba *phba = vport->phba;
  4944. LPFC_MBOXQ_t *mbox;
  4945. struct lpfc_dmabuf *pcmd;
  4946. struct ls_rjt stat;
  4947. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  4948. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  4949. /* reject the unsolicited RPS request and done with it */
  4950. goto reject_out;
  4951. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  4952. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  4953. if (mbox) {
  4954. lpfc_read_lnk_stat(phba, mbox);
  4955. mbox->context1 = (void *)((unsigned long)
  4956. ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
  4957. cmdiocb->iocb.ulpContext)); /* rx_id */
  4958. mbox->context2 = lpfc_nlp_get(ndlp);
  4959. mbox->vport = vport;
  4960. mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
  4961. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  4962. != MBX_NOT_FINISHED)
  4963. /* Mbox completion will send ELS Response */
  4964. return 0;
  4965. /* Decrement reference count used for the failed mbox
  4966. * command.
  4967. */
  4968. lpfc_nlp_put(ndlp);
  4969. mempool_free(mbox, phba->mbox_mem_pool);
  4970. }
  4971. reject_out:
  4972. /* issue rejection response */
  4973. stat.un.b.lsRjtRsvd0 = 0;
  4974. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  4975. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  4976. stat.un.b.vendorUnique = 0;
  4977. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  4978. return 0;
  4979. }
  4980. /**
  4981. * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
  4982. * @vport: pointer to a host virtual N_Port data structure.
  4983. * @cmdiocb: pointer to lpfc command iocb data structure.
  4984. * @ndlp: pointer to a node-list data structure.
  4985. *
  4986. * This routine processes Read Timout Value (RTV) IOCB received as an
  4987. * ELS unsolicited event. It first checks the remote port state. If the
  4988. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  4989. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  4990. * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
  4991. * Value (RTV) unsolicited IOCB event.
  4992. *
  4993. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  4994. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  4995. * will be stored into the context1 field of the IOCB for the completion
  4996. * callback function to the RPS Accept Response ELS IOCB command.
  4997. *
  4998. * Return codes
  4999. * 0 - Successfully processed rtv iocb (currently always return 0)
  5000. **/
  5001. static int
  5002. lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5003. struct lpfc_nodelist *ndlp)
  5004. {
  5005. struct lpfc_hba *phba = vport->phba;
  5006. struct ls_rjt stat;
  5007. struct RTV_RSP *rtv_rsp;
  5008. uint8_t *pcmd;
  5009. struct lpfc_iocbq *elsiocb;
  5010. uint32_t cmdsize;
  5011. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5012. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  5013. /* reject the unsolicited RPS request and done with it */
  5014. goto reject_out;
  5015. cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
  5016. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  5017. lpfc_max_els_tries, ndlp,
  5018. ndlp->nlp_DID, ELS_CMD_ACC);
  5019. if (!elsiocb)
  5020. return 1;
  5021. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5022. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5023. pcmd += sizeof(uint32_t); /* Skip past command */
  5024. /* use the command's xri in the response */
  5025. elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
  5026. elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
  5027. rtv_rsp = (struct RTV_RSP *)pcmd;
  5028. /* populate RTV payload */
  5029. rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
  5030. rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
  5031. bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
  5032. bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
  5033. rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
  5034. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  5035. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  5036. "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
  5037. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
  5038. "Data: x%x x%x x%x\n",
  5039. elsiocb->iotag, elsiocb->iocb.ulpContext,
  5040. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5041. ndlp->nlp_rpi,
  5042. rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
  5043. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5044. phba->fc_stat.elsXmitACC++;
  5045. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
  5046. lpfc_els_free_iocb(phba, elsiocb);
  5047. return 0;
  5048. reject_out:
  5049. /* issue rejection response */
  5050. stat.un.b.lsRjtRsvd0 = 0;
  5051. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5052. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5053. stat.un.b.vendorUnique = 0;
  5054. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5055. return 0;
  5056. }
  5057. /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
  5058. * @vport: pointer to a host virtual N_Port data structure.
  5059. * @cmdiocb: pointer to lpfc command iocb data structure.
  5060. * @ndlp: pointer to a node-list data structure.
  5061. *
  5062. * This routine processes Read Port Status (RPS) IOCB received as an
  5063. * ELS unsolicited event. It first checks the remote port state. If the
  5064. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  5065. * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
  5066. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  5067. * for reading the HBA link statistics. It is for the callback function,
  5068. * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
  5069. * to actually sending out RPS Accept (ACC) response.
  5070. *
  5071. * Return codes
  5072. * 0 - Successfully processed rps iocb (currently always return 0)
  5073. **/
  5074. static int
  5075. lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5076. struct lpfc_nodelist *ndlp)
  5077. {
  5078. struct lpfc_hba *phba = vport->phba;
  5079. uint32_t *lp;
  5080. uint8_t flag;
  5081. LPFC_MBOXQ_t *mbox;
  5082. struct lpfc_dmabuf *pcmd;
  5083. RPS *rps;
  5084. struct ls_rjt stat;
  5085. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5086. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  5087. /* reject the unsolicited RPS request and done with it */
  5088. goto reject_out;
  5089. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5090. lp = (uint32_t *) pcmd->virt;
  5091. flag = (be32_to_cpu(*lp++) & 0xf);
  5092. rps = (RPS *) lp;
  5093. if ((flag == 0) ||
  5094. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  5095. ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
  5096. sizeof(struct lpfc_name)) == 0))) {
  5097. printk("Fix me....\n");
  5098. dump_stack();
  5099. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  5100. if (mbox) {
  5101. lpfc_read_lnk_stat(phba, mbox);
  5102. mbox->context1 = (void *)((unsigned long)
  5103. ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
  5104. cmdiocb->iocb.ulpContext)); /* rx_id */
  5105. mbox->context2 = lpfc_nlp_get(ndlp);
  5106. mbox->vport = vport;
  5107. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  5108. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  5109. != MBX_NOT_FINISHED)
  5110. /* Mbox completion will send ELS Response */
  5111. return 0;
  5112. /* Decrement reference count used for the failed mbox
  5113. * command.
  5114. */
  5115. lpfc_nlp_put(ndlp);
  5116. mempool_free(mbox, phba->mbox_mem_pool);
  5117. }
  5118. }
  5119. reject_out:
  5120. /* issue rejection response */
  5121. stat.un.b.lsRjtRsvd0 = 0;
  5122. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5123. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5124. stat.un.b.vendorUnique = 0;
  5125. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  5126. return 0;
  5127. }
  5128. /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
  5129. * @vport: pointer to a host virtual N_Port data structure.
  5130. * @ndlp: pointer to a node-list data structure.
  5131. * @did: DID of the target.
  5132. * @rrq: Pointer to the rrq struct.
  5133. *
  5134. * Build a ELS RRQ command and send it to the target. If the issue_iocb is
  5135. * Successful the the completion handler will clear the RRQ.
  5136. *
  5137. * Return codes
  5138. * 0 - Successfully sent rrq els iocb.
  5139. * 1 - Failed to send rrq els iocb.
  5140. **/
  5141. static int
  5142. lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  5143. uint32_t did, struct lpfc_node_rrq *rrq)
  5144. {
  5145. struct lpfc_hba *phba = vport->phba;
  5146. struct RRQ *els_rrq;
  5147. IOCB_t *icmd;
  5148. struct lpfc_iocbq *elsiocb;
  5149. uint8_t *pcmd;
  5150. uint16_t cmdsize;
  5151. int ret;
  5152. if (ndlp != rrq->ndlp)
  5153. ndlp = rrq->ndlp;
  5154. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  5155. return 1;
  5156. /* If ndlp is not NULL, we will bump the reference count on it */
  5157. cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
  5158. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
  5159. ELS_CMD_RRQ);
  5160. if (!elsiocb)
  5161. return 1;
  5162. icmd = &elsiocb->iocb;
  5163. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5164. /* For RRQ request, remainder of payload is Exchange IDs */
  5165. *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
  5166. pcmd += sizeof(uint32_t);
  5167. els_rrq = (struct RRQ *) pcmd;
  5168. bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
  5169. bf_set(rrq_rxid, els_rrq, rrq->rxid);
  5170. bf_set(rrq_did, els_rrq, vport->fc_myDID);
  5171. els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
  5172. els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
  5173. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  5174. "Issue RRQ: did:x%x",
  5175. did, rrq->xritag, rrq->rxid);
  5176. elsiocb->context_un.rrq = rrq;
  5177. elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
  5178. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5179. if (ret == IOCB_ERROR) {
  5180. lpfc_els_free_iocb(phba, elsiocb);
  5181. return 1;
  5182. }
  5183. return 0;
  5184. }
  5185. /**
  5186. * lpfc_send_rrq - Sends ELS RRQ if needed.
  5187. * @phba: pointer to lpfc hba data structure.
  5188. * @rrq: pointer to the active rrq.
  5189. *
  5190. * This routine will call the lpfc_issue_els_rrq if the rrq is
  5191. * still active for the xri. If this function returns a failure then
  5192. * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
  5193. *
  5194. * Returns 0 Success.
  5195. * 1 Failure.
  5196. **/
  5197. int
  5198. lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
  5199. {
  5200. struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
  5201. rrq->nlp_DID);
  5202. if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
  5203. return lpfc_issue_els_rrq(rrq->vport, ndlp,
  5204. rrq->nlp_DID, rrq);
  5205. else
  5206. return 1;
  5207. }
  5208. /**
  5209. * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
  5210. * @vport: pointer to a host virtual N_Port data structure.
  5211. * @cmdsize: size of the ELS command.
  5212. * @oldiocb: pointer to the original lpfc command iocb data structure.
  5213. * @ndlp: pointer to a node-list data structure.
  5214. *
  5215. * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
  5216. * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
  5217. *
  5218. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  5219. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  5220. * will be stored into the context1 field of the IOCB for the completion
  5221. * callback function to the RPL Accept Response ELS command.
  5222. *
  5223. * Return code
  5224. * 0 - Successfully issued ACC RPL ELS command
  5225. * 1 - Failed to issue ACC RPL ELS command
  5226. **/
  5227. static int
  5228. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  5229. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  5230. {
  5231. struct lpfc_hba *phba = vport->phba;
  5232. IOCB_t *icmd, *oldcmd;
  5233. RPL_RSP rpl_rsp;
  5234. struct lpfc_iocbq *elsiocb;
  5235. uint8_t *pcmd;
  5236. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  5237. ndlp->nlp_DID, ELS_CMD_ACC);
  5238. if (!elsiocb)
  5239. return 1;
  5240. icmd = &elsiocb->iocb;
  5241. oldcmd = &oldiocb->iocb;
  5242. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5243. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  5244. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  5245. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5246. pcmd += sizeof(uint16_t);
  5247. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  5248. pcmd += sizeof(uint16_t);
  5249. /* Setup the RPL ACC payload */
  5250. rpl_rsp.listLen = be32_to_cpu(1);
  5251. rpl_rsp.index = 0;
  5252. rpl_rsp.port_num_blk.portNum = 0;
  5253. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  5254. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  5255. sizeof(struct lpfc_name));
  5256. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  5257. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  5258. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5259. "0120 Xmit ELS RPL ACC response tag x%x "
  5260. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  5261. "rpi x%x\n",
  5262. elsiocb->iotag, elsiocb->iocb.ulpContext,
  5263. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5264. ndlp->nlp_rpi);
  5265. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  5266. phba->fc_stat.elsXmitACC++;
  5267. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  5268. IOCB_ERROR) {
  5269. lpfc_els_free_iocb(phba, elsiocb);
  5270. return 1;
  5271. }
  5272. return 0;
  5273. }
  5274. /**
  5275. * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
  5276. * @vport: pointer to a host virtual N_Port data structure.
  5277. * @cmdiocb: pointer to lpfc command iocb data structure.
  5278. * @ndlp: pointer to a node-list data structure.
  5279. *
  5280. * This routine processes Read Port List (RPL) IOCB received as an ELS
  5281. * unsolicited event. It first checks the remote port state. If the remote
  5282. * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
  5283. * invokes the lpfc_els_rsp_reject() routine to send reject response.
  5284. * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
  5285. * to accept the RPL.
  5286. *
  5287. * Return code
  5288. * 0 - Successfully processed rpl iocb (currently always return 0)
  5289. **/
  5290. static int
  5291. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5292. struct lpfc_nodelist *ndlp)
  5293. {
  5294. struct lpfc_dmabuf *pcmd;
  5295. uint32_t *lp;
  5296. uint32_t maxsize;
  5297. uint16_t cmdsize;
  5298. RPL *rpl;
  5299. struct ls_rjt stat;
  5300. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  5301. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  5302. /* issue rejection response */
  5303. stat.un.b.lsRjtRsvd0 = 0;
  5304. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  5305. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  5306. stat.un.b.vendorUnique = 0;
  5307. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  5308. NULL);
  5309. /* rejected the unsolicited RPL request and done with it */
  5310. return 0;
  5311. }
  5312. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5313. lp = (uint32_t *) pcmd->virt;
  5314. rpl = (RPL *) (lp + 1);
  5315. maxsize = be32_to_cpu(rpl->maxsize);
  5316. /* We support only one port */
  5317. if ((rpl->index == 0) &&
  5318. ((maxsize == 0) ||
  5319. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  5320. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  5321. } else {
  5322. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  5323. }
  5324. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  5325. return 0;
  5326. }
  5327. /**
  5328. * lpfc_els_rcv_farp - Process an unsolicited farp request els command
  5329. * @vport: pointer to a virtual N_Port data structure.
  5330. * @cmdiocb: pointer to lpfc command iocb data structure.
  5331. * @ndlp: pointer to a node-list data structure.
  5332. *
  5333. * This routine processes Fibre Channel Address Resolution Protocol
  5334. * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
  5335. * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
  5336. * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
  5337. * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
  5338. * remote PortName is compared against the FC PortName stored in the @vport
  5339. * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
  5340. * compared against the FC NodeName stored in the @vport data structure.
  5341. * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
  5342. * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
  5343. * invoked to send out FARP Response to the remote node. Before sending the
  5344. * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
  5345. * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
  5346. * routine is invoked to log into the remote port first.
  5347. *
  5348. * Return code
  5349. * 0 - Either the FARP Match Mode not supported or successfully processed
  5350. **/
  5351. static int
  5352. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5353. struct lpfc_nodelist *ndlp)
  5354. {
  5355. struct lpfc_dmabuf *pcmd;
  5356. uint32_t *lp;
  5357. IOCB_t *icmd;
  5358. FARP *fp;
  5359. uint32_t cmd, cnt, did;
  5360. icmd = &cmdiocb->iocb;
  5361. did = icmd->un.elsreq64.remoteID;
  5362. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5363. lp = (uint32_t *) pcmd->virt;
  5364. cmd = *lp++;
  5365. fp = (FARP *) lp;
  5366. /* FARP-REQ received from DID <did> */
  5367. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5368. "0601 FARP-REQ received from DID x%x\n", did);
  5369. /* We will only support match on WWPN or WWNN */
  5370. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  5371. return 0;
  5372. }
  5373. cnt = 0;
  5374. /* If this FARP command is searching for my portname */
  5375. if (fp->Mflags & FARP_MATCH_PORT) {
  5376. if (memcmp(&fp->RportName, &vport->fc_portname,
  5377. sizeof(struct lpfc_name)) == 0)
  5378. cnt = 1;
  5379. }
  5380. /* If this FARP command is searching for my nodename */
  5381. if (fp->Mflags & FARP_MATCH_NODE) {
  5382. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  5383. sizeof(struct lpfc_name)) == 0)
  5384. cnt = 1;
  5385. }
  5386. if (cnt) {
  5387. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  5388. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  5389. /* Log back into the node before sending the FARP. */
  5390. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  5391. ndlp->nlp_prev_state = ndlp->nlp_state;
  5392. lpfc_nlp_set_state(vport, ndlp,
  5393. NLP_STE_PLOGI_ISSUE);
  5394. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  5395. }
  5396. /* Send a FARP response to that node */
  5397. if (fp->Rflags & FARP_REQUEST_FARPR)
  5398. lpfc_issue_els_farpr(vport, did, 0);
  5399. }
  5400. }
  5401. return 0;
  5402. }
  5403. /**
  5404. * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
  5405. * @vport: pointer to a host virtual N_Port data structure.
  5406. * @cmdiocb: pointer to lpfc command iocb data structure.
  5407. * @ndlp: pointer to a node-list data structure.
  5408. *
  5409. * This routine processes Fibre Channel Address Resolution Protocol
  5410. * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
  5411. * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
  5412. * the FARP response request.
  5413. *
  5414. * Return code
  5415. * 0 - Successfully processed FARPR IOCB (currently always return 0)
  5416. **/
  5417. static int
  5418. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5419. struct lpfc_nodelist *ndlp)
  5420. {
  5421. struct lpfc_dmabuf *pcmd;
  5422. uint32_t *lp;
  5423. IOCB_t *icmd;
  5424. uint32_t cmd, did;
  5425. icmd = &cmdiocb->iocb;
  5426. did = icmd->un.elsreq64.remoteID;
  5427. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  5428. lp = (uint32_t *) pcmd->virt;
  5429. cmd = *lp++;
  5430. /* FARP-RSP received from DID <did> */
  5431. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5432. "0600 FARP-RSP received from DID x%x\n", did);
  5433. /* ACCEPT the Farp resp request */
  5434. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  5435. return 0;
  5436. }
  5437. /**
  5438. * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
  5439. * @vport: pointer to a host virtual N_Port data structure.
  5440. * @cmdiocb: pointer to lpfc command iocb data structure.
  5441. * @fan_ndlp: pointer to a node-list data structure.
  5442. *
  5443. * This routine processes a Fabric Address Notification (FAN) IOCB
  5444. * command received as an ELS unsolicited event. The FAN ELS command will
  5445. * only be processed on a physical port (i.e., the @vport represents the
  5446. * physical port). The fabric NodeName and PortName from the FAN IOCB are
  5447. * compared against those in the phba data structure. If any of those is
  5448. * different, the lpfc_initial_flogi() routine is invoked to initialize
  5449. * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
  5450. * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
  5451. * is invoked to register login to the fabric.
  5452. *
  5453. * Return code
  5454. * 0 - Successfully processed fan iocb (currently always return 0).
  5455. **/
  5456. static int
  5457. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5458. struct lpfc_nodelist *fan_ndlp)
  5459. {
  5460. struct lpfc_hba *phba = vport->phba;
  5461. uint32_t *lp;
  5462. FAN *fp;
  5463. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
  5464. lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
  5465. fp = (FAN *) ++lp;
  5466. /* FAN received; Fan does not have a reply sequence */
  5467. if ((vport == phba->pport) &&
  5468. (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
  5469. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  5470. sizeof(struct lpfc_name))) ||
  5471. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  5472. sizeof(struct lpfc_name)))) {
  5473. /* This port has switched fabrics. FLOGI is required */
  5474. lpfc_issue_init_vfi(vport);
  5475. } else {
  5476. /* FAN verified - skip FLOGI */
  5477. vport->fc_myDID = vport->fc_prevDID;
  5478. if (phba->sli_rev < LPFC_SLI_REV4)
  5479. lpfc_issue_fabric_reglogin(vport);
  5480. else {
  5481. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5482. "3138 Need register VFI: (x%x/%x)\n",
  5483. vport->fc_prevDID, vport->fc_myDID);
  5484. lpfc_issue_reg_vfi(vport);
  5485. }
  5486. }
  5487. }
  5488. return 0;
  5489. }
  5490. /**
  5491. * lpfc_els_timeout - Handler funciton to the els timer
  5492. * @ptr: holder for the timer function associated data.
  5493. *
  5494. * This routine is invoked by the ELS timer after timeout. It posts the ELS
  5495. * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
  5496. * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
  5497. * up the worker thread. It is for the worker thread to invoke the routine
  5498. * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
  5499. **/
  5500. void
  5501. lpfc_els_timeout(unsigned long ptr)
  5502. {
  5503. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  5504. struct lpfc_hba *phba = vport->phba;
  5505. uint32_t tmo_posted;
  5506. unsigned long iflag;
  5507. spin_lock_irqsave(&vport->work_port_lock, iflag);
  5508. tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
  5509. if (!tmo_posted)
  5510. vport->work_port_events |= WORKER_ELS_TMO;
  5511. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  5512. if (!tmo_posted)
  5513. lpfc_worker_wake_up(phba);
  5514. return;
  5515. }
  5516. /**
  5517. * lpfc_els_timeout_handler - Process an els timeout event
  5518. * @vport: pointer to a virtual N_Port data structure.
  5519. *
  5520. * This routine is the actual handler function that processes an ELS timeout
  5521. * event. It walks the ELS ring to get and abort all the IOCBs (except the
  5522. * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
  5523. * invoking the lpfc_sli_issue_abort_iotag() routine.
  5524. **/
  5525. void
  5526. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  5527. {
  5528. struct lpfc_hba *phba = vport->phba;
  5529. struct lpfc_sli_ring *pring;
  5530. struct lpfc_iocbq *tmp_iocb, *piocb;
  5531. IOCB_t *cmd = NULL;
  5532. struct lpfc_dmabuf *pcmd;
  5533. uint32_t els_command = 0;
  5534. uint32_t timeout;
  5535. uint32_t remote_ID = 0xffffffff;
  5536. LIST_HEAD(txcmplq_completions);
  5537. LIST_HEAD(abort_list);
  5538. timeout = (uint32_t)(phba->fc_ratov << 1);
  5539. pring = &phba->sli.ring[LPFC_ELS_RING];
  5540. spin_lock_irq(&phba->hbalock);
  5541. list_splice_init(&pring->txcmplq, &txcmplq_completions);
  5542. spin_unlock_irq(&phba->hbalock);
  5543. list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
  5544. cmd = &piocb->iocb;
  5545. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  5546. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  5547. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  5548. continue;
  5549. if (piocb->vport != vport)
  5550. continue;
  5551. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  5552. if (pcmd)
  5553. els_command = *(uint32_t *) (pcmd->virt);
  5554. if (els_command == ELS_CMD_FARP ||
  5555. els_command == ELS_CMD_FARPR ||
  5556. els_command == ELS_CMD_FDISC)
  5557. continue;
  5558. if (piocb->drvrTimeout > 0) {
  5559. if (piocb->drvrTimeout >= timeout)
  5560. piocb->drvrTimeout -= timeout;
  5561. else
  5562. piocb->drvrTimeout = 0;
  5563. continue;
  5564. }
  5565. remote_ID = 0xffffffff;
  5566. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  5567. remote_ID = cmd->un.elsreq64.remoteID;
  5568. else {
  5569. struct lpfc_nodelist *ndlp;
  5570. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  5571. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  5572. remote_ID = ndlp->nlp_DID;
  5573. }
  5574. list_add_tail(&piocb->dlist, &abort_list);
  5575. }
  5576. spin_lock_irq(&phba->hbalock);
  5577. list_splice(&txcmplq_completions, &pring->txcmplq);
  5578. spin_unlock_irq(&phba->hbalock);
  5579. list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
  5580. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5581. "0127 ELS timeout Data: x%x x%x x%x "
  5582. "x%x\n", els_command,
  5583. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  5584. spin_lock_irq(&phba->hbalock);
  5585. list_del_init(&piocb->dlist);
  5586. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5587. spin_unlock_irq(&phba->hbalock);
  5588. }
  5589. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  5590. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  5591. }
  5592. /**
  5593. * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
  5594. * @vport: pointer to a host virtual N_Port data structure.
  5595. *
  5596. * This routine is used to clean up all the outstanding ELS commands on a
  5597. * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
  5598. * routine. After that, it walks the ELS transmit queue to remove all the
  5599. * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
  5600. * the IOCBs with a non-NULL completion callback function, the callback
  5601. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  5602. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
  5603. * callback function, the IOCB will simply be released. Finally, it walks
  5604. * the ELS transmit completion queue to issue an abort IOCB to any transmit
  5605. * completion queue IOCB that is associated with the @vport and is not
  5606. * an IOCB from libdfc (i.e., the management plane IOCBs that are not
  5607. * part of the discovery state machine) out to HBA by invoking the
  5608. * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
  5609. * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
  5610. * the IOCBs are aborted when this function returns.
  5611. **/
  5612. void
  5613. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  5614. {
  5615. LIST_HEAD(completions);
  5616. struct lpfc_hba *phba = vport->phba;
  5617. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  5618. struct lpfc_iocbq *tmp_iocb, *piocb;
  5619. IOCB_t *cmd = NULL;
  5620. lpfc_fabric_abort_vport(vport);
  5621. spin_lock_irq(&phba->hbalock);
  5622. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  5623. cmd = &piocb->iocb;
  5624. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  5625. continue;
  5626. }
  5627. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  5628. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  5629. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  5630. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  5631. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  5632. continue;
  5633. if (piocb->vport != vport)
  5634. continue;
  5635. list_move_tail(&piocb->list, &completions);
  5636. pring->txq_cnt--;
  5637. }
  5638. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  5639. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  5640. continue;
  5641. }
  5642. if (piocb->vport != vport)
  5643. continue;
  5644. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5645. }
  5646. spin_unlock_irq(&phba->hbalock);
  5647. /* Cancell all the IOCBs from the completions list */
  5648. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5649. IOERR_SLI_ABORTED);
  5650. return;
  5651. }
  5652. /**
  5653. * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
  5654. * @phba: pointer to lpfc hba data structure.
  5655. *
  5656. * This routine is used to clean up all the outstanding ELS commands on a
  5657. * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
  5658. * routine. After that, it walks the ELS transmit queue to remove all the
  5659. * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
  5660. * the IOCBs with the completion callback function associated, the callback
  5661. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  5662. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
  5663. * callback function associated, the IOCB will simply be released. Finally,
  5664. * it walks the ELS transmit completion queue to issue an abort IOCB to any
  5665. * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
  5666. * management plane IOCBs that are not part of the discovery state machine)
  5667. * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
  5668. **/
  5669. void
  5670. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  5671. {
  5672. LIST_HEAD(completions);
  5673. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  5674. struct lpfc_iocbq *tmp_iocb, *piocb;
  5675. IOCB_t *cmd = NULL;
  5676. lpfc_fabric_abort_hba(phba);
  5677. spin_lock_irq(&phba->hbalock);
  5678. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  5679. cmd = &piocb->iocb;
  5680. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  5681. continue;
  5682. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  5683. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  5684. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  5685. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  5686. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  5687. continue;
  5688. list_move_tail(&piocb->list, &completions);
  5689. pring->txq_cnt--;
  5690. }
  5691. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  5692. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  5693. continue;
  5694. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  5695. }
  5696. spin_unlock_irq(&phba->hbalock);
  5697. /* Cancel all the IOCBs from the completions list */
  5698. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  5699. IOERR_SLI_ABORTED);
  5700. return;
  5701. }
  5702. /**
  5703. * lpfc_send_els_failure_event - Posts an ELS command failure event
  5704. * @phba: Pointer to hba context object.
  5705. * @cmdiocbp: Pointer to command iocb which reported error.
  5706. * @rspiocbp: Pointer to response iocb which reported error.
  5707. *
  5708. * This function sends an event when there is an ELS command
  5709. * failure.
  5710. **/
  5711. void
  5712. lpfc_send_els_failure_event(struct lpfc_hba *phba,
  5713. struct lpfc_iocbq *cmdiocbp,
  5714. struct lpfc_iocbq *rspiocbp)
  5715. {
  5716. struct lpfc_vport *vport = cmdiocbp->vport;
  5717. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5718. struct lpfc_lsrjt_event lsrjt_event;
  5719. struct lpfc_fabric_event_header fabric_event;
  5720. struct ls_rjt stat;
  5721. struct lpfc_nodelist *ndlp;
  5722. uint32_t *pcmd;
  5723. ndlp = cmdiocbp->context1;
  5724. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  5725. return;
  5726. if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
  5727. lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
  5728. lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
  5729. memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
  5730. sizeof(struct lpfc_name));
  5731. memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
  5732. sizeof(struct lpfc_name));
  5733. pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
  5734. cmdiocbp->context2)->virt);
  5735. lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
  5736. stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
  5737. lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
  5738. lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
  5739. fc_host_post_vendor_event(shost,
  5740. fc_get_event_number(),
  5741. sizeof(lsrjt_event),
  5742. (char *)&lsrjt_event,
  5743. LPFC_NL_VENDOR_ID);
  5744. return;
  5745. }
  5746. if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
  5747. (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
  5748. fabric_event.event_type = FC_REG_FABRIC_EVENT;
  5749. if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
  5750. fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
  5751. else
  5752. fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
  5753. memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
  5754. sizeof(struct lpfc_name));
  5755. memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
  5756. sizeof(struct lpfc_name));
  5757. fc_host_post_vendor_event(shost,
  5758. fc_get_event_number(),
  5759. sizeof(fabric_event),
  5760. (char *)&fabric_event,
  5761. LPFC_NL_VENDOR_ID);
  5762. return;
  5763. }
  5764. }
  5765. /**
  5766. * lpfc_send_els_event - Posts unsolicited els event
  5767. * @vport: Pointer to vport object.
  5768. * @ndlp: Pointer FC node object.
  5769. * @cmd: ELS command code.
  5770. *
  5771. * This function posts an event when there is an incoming
  5772. * unsolicited ELS command.
  5773. **/
  5774. static void
  5775. lpfc_send_els_event(struct lpfc_vport *vport,
  5776. struct lpfc_nodelist *ndlp,
  5777. uint32_t *payload)
  5778. {
  5779. struct lpfc_els_event_header *els_data = NULL;
  5780. struct lpfc_logo_event *logo_data = NULL;
  5781. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5782. if (*payload == ELS_CMD_LOGO) {
  5783. logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
  5784. if (!logo_data) {
  5785. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5786. "0148 Failed to allocate memory "
  5787. "for LOGO event\n");
  5788. return;
  5789. }
  5790. els_data = &logo_data->header;
  5791. } else {
  5792. els_data = kmalloc(sizeof(struct lpfc_els_event_header),
  5793. GFP_KERNEL);
  5794. if (!els_data) {
  5795. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  5796. "0149 Failed to allocate memory "
  5797. "for ELS event\n");
  5798. return;
  5799. }
  5800. }
  5801. els_data->event_type = FC_REG_ELS_EVENT;
  5802. switch (*payload) {
  5803. case ELS_CMD_PLOGI:
  5804. els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
  5805. break;
  5806. case ELS_CMD_PRLO:
  5807. els_data->subcategory = LPFC_EVENT_PRLO_RCV;
  5808. break;
  5809. case ELS_CMD_ADISC:
  5810. els_data->subcategory = LPFC_EVENT_ADISC_RCV;
  5811. break;
  5812. case ELS_CMD_LOGO:
  5813. els_data->subcategory = LPFC_EVENT_LOGO_RCV;
  5814. /* Copy the WWPN in the LOGO payload */
  5815. memcpy(logo_data->logo_wwpn, &payload[2],
  5816. sizeof(struct lpfc_name));
  5817. break;
  5818. default:
  5819. kfree(els_data);
  5820. return;
  5821. }
  5822. memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
  5823. memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
  5824. if (*payload == ELS_CMD_LOGO) {
  5825. fc_host_post_vendor_event(shost,
  5826. fc_get_event_number(),
  5827. sizeof(struct lpfc_logo_event),
  5828. (char *)logo_data,
  5829. LPFC_NL_VENDOR_ID);
  5830. kfree(logo_data);
  5831. } else {
  5832. fc_host_post_vendor_event(shost,
  5833. fc_get_event_number(),
  5834. sizeof(struct lpfc_els_event_header),
  5835. (char *)els_data,
  5836. LPFC_NL_VENDOR_ID);
  5837. kfree(els_data);
  5838. }
  5839. return;
  5840. }
  5841. /**
  5842. * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
  5843. * @phba: pointer to lpfc hba data structure.
  5844. * @pring: pointer to a SLI ring.
  5845. * @vport: pointer to a host virtual N_Port data structure.
  5846. * @elsiocb: pointer to lpfc els command iocb data structure.
  5847. *
  5848. * This routine is used for processing the IOCB associated with a unsolicited
  5849. * event. It first determines whether there is an existing ndlp that matches
  5850. * the DID from the unsolicited IOCB. If not, it will create a new one with
  5851. * the DID from the unsolicited IOCB. The ELS command from the unsolicited
  5852. * IOCB is then used to invoke the proper routine and to set up proper state
  5853. * of the discovery state machine.
  5854. **/
  5855. static void
  5856. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  5857. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  5858. {
  5859. struct Scsi_Host *shost;
  5860. struct lpfc_nodelist *ndlp;
  5861. struct ls_rjt stat;
  5862. uint32_t *payload;
  5863. uint32_t cmd, did, newnode, rjt_err = 0;
  5864. IOCB_t *icmd = &elsiocb->iocb;
  5865. if (!vport || !(elsiocb->context2))
  5866. goto dropit;
  5867. newnode = 0;
  5868. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  5869. cmd = *payload;
  5870. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  5871. lpfc_post_buffer(phba, pring, 1);
  5872. did = icmd->un.rcvels.remoteID;
  5873. if (icmd->ulpStatus) {
  5874. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5875. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  5876. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  5877. goto dropit;
  5878. }
  5879. /* Check to see if link went down during discovery */
  5880. if (lpfc_els_chk_latt(vport))
  5881. goto dropit;
  5882. /* Ignore traffic received during vport shutdown. */
  5883. if (vport->load_flag & FC_UNLOADING)
  5884. goto dropit;
  5885. /* If NPort discovery is delayed drop incoming ELS */
  5886. if ((vport->fc_flag & FC_DISC_DELAYED) &&
  5887. (cmd != ELS_CMD_PLOGI))
  5888. goto dropit;
  5889. ndlp = lpfc_findnode_did(vport, did);
  5890. if (!ndlp) {
  5891. /* Cannot find existing Fabric ndlp, so allocate a new one */
  5892. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  5893. if (!ndlp)
  5894. goto dropit;
  5895. lpfc_nlp_init(vport, ndlp, did);
  5896. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5897. newnode = 1;
  5898. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  5899. ndlp->nlp_type |= NLP_FABRIC;
  5900. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  5901. ndlp = lpfc_enable_node(vport, ndlp,
  5902. NLP_STE_UNUSED_NODE);
  5903. if (!ndlp)
  5904. goto dropit;
  5905. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5906. newnode = 1;
  5907. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  5908. ndlp->nlp_type |= NLP_FABRIC;
  5909. } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  5910. /* This is similar to the new node path */
  5911. ndlp = lpfc_nlp_get(ndlp);
  5912. if (!ndlp)
  5913. goto dropit;
  5914. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  5915. newnode = 1;
  5916. }
  5917. phba->fc_stat.elsRcvFrame++;
  5918. elsiocb->context1 = lpfc_nlp_get(ndlp);
  5919. elsiocb->vport = vport;
  5920. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  5921. cmd &= ELS_CMD_MASK;
  5922. }
  5923. /* ELS command <elsCmd> received from NPORT <did> */
  5924. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5925. "0112 ELS command x%x received from NPORT x%x "
  5926. "Data: x%x\n", cmd, did, vport->port_state);
  5927. switch (cmd) {
  5928. case ELS_CMD_PLOGI:
  5929. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5930. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  5931. did, vport->port_state, ndlp->nlp_flag);
  5932. phba->fc_stat.elsRcvPLOGI++;
  5933. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  5934. lpfc_send_els_event(vport, ndlp, payload);
  5935. /* If Nport discovery is delayed, reject PLOGIs */
  5936. if (vport->fc_flag & FC_DISC_DELAYED) {
  5937. rjt_err = LSRJT_UNABLE_TPC;
  5938. break;
  5939. }
  5940. if (vport->port_state < LPFC_DISC_AUTH) {
  5941. if (!(phba->pport->fc_flag & FC_PT2PT) ||
  5942. (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
  5943. rjt_err = LSRJT_UNABLE_TPC;
  5944. break;
  5945. }
  5946. /* We get here, and drop thru, if we are PT2PT with
  5947. * another NPort and the other side has initiated
  5948. * the PLOGI before responding to our FLOGI.
  5949. */
  5950. }
  5951. shost = lpfc_shost_from_vport(vport);
  5952. spin_lock_irq(shost->host_lock);
  5953. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  5954. spin_unlock_irq(shost->host_lock);
  5955. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  5956. NLP_EVT_RCV_PLOGI);
  5957. break;
  5958. case ELS_CMD_FLOGI:
  5959. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5960. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  5961. did, vport->port_state, ndlp->nlp_flag);
  5962. phba->fc_stat.elsRcvFLOGI++;
  5963. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  5964. if (newnode)
  5965. lpfc_nlp_put(ndlp);
  5966. break;
  5967. case ELS_CMD_LOGO:
  5968. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5969. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  5970. did, vport->port_state, ndlp->nlp_flag);
  5971. phba->fc_stat.elsRcvLOGO++;
  5972. lpfc_send_els_event(vport, ndlp, payload);
  5973. if (vport->port_state < LPFC_DISC_AUTH) {
  5974. rjt_err = LSRJT_UNABLE_TPC;
  5975. break;
  5976. }
  5977. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  5978. break;
  5979. case ELS_CMD_PRLO:
  5980. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5981. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  5982. did, vport->port_state, ndlp->nlp_flag);
  5983. phba->fc_stat.elsRcvPRLO++;
  5984. lpfc_send_els_event(vport, ndlp, payload);
  5985. if (vport->port_state < LPFC_DISC_AUTH) {
  5986. rjt_err = LSRJT_UNABLE_TPC;
  5987. break;
  5988. }
  5989. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  5990. break;
  5991. case ELS_CMD_RSCN:
  5992. phba->fc_stat.elsRcvRSCN++;
  5993. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  5994. if (newnode)
  5995. lpfc_nlp_put(ndlp);
  5996. break;
  5997. case ELS_CMD_ADISC:
  5998. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  5999. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  6000. did, vport->port_state, ndlp->nlp_flag);
  6001. lpfc_send_els_event(vport, ndlp, payload);
  6002. phba->fc_stat.elsRcvADISC++;
  6003. if (vport->port_state < LPFC_DISC_AUTH) {
  6004. rjt_err = LSRJT_UNABLE_TPC;
  6005. break;
  6006. }
  6007. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  6008. NLP_EVT_RCV_ADISC);
  6009. break;
  6010. case ELS_CMD_PDISC:
  6011. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6012. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  6013. did, vport->port_state, ndlp->nlp_flag);
  6014. phba->fc_stat.elsRcvPDISC++;
  6015. if (vport->port_state < LPFC_DISC_AUTH) {
  6016. rjt_err = LSRJT_UNABLE_TPC;
  6017. break;
  6018. }
  6019. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  6020. NLP_EVT_RCV_PDISC);
  6021. break;
  6022. case ELS_CMD_FARPR:
  6023. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6024. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  6025. did, vport->port_state, ndlp->nlp_flag);
  6026. phba->fc_stat.elsRcvFARPR++;
  6027. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  6028. break;
  6029. case ELS_CMD_FARP:
  6030. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6031. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  6032. did, vport->port_state, ndlp->nlp_flag);
  6033. phba->fc_stat.elsRcvFARP++;
  6034. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  6035. break;
  6036. case ELS_CMD_FAN:
  6037. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6038. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  6039. did, vport->port_state, ndlp->nlp_flag);
  6040. phba->fc_stat.elsRcvFAN++;
  6041. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  6042. break;
  6043. case ELS_CMD_PRLI:
  6044. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6045. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  6046. did, vport->port_state, ndlp->nlp_flag);
  6047. phba->fc_stat.elsRcvPRLI++;
  6048. if (vport->port_state < LPFC_DISC_AUTH) {
  6049. rjt_err = LSRJT_UNABLE_TPC;
  6050. break;
  6051. }
  6052. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  6053. break;
  6054. case ELS_CMD_LIRR:
  6055. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6056. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  6057. did, vport->port_state, ndlp->nlp_flag);
  6058. phba->fc_stat.elsRcvLIRR++;
  6059. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  6060. if (newnode)
  6061. lpfc_nlp_put(ndlp);
  6062. break;
  6063. case ELS_CMD_RLS:
  6064. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6065. "RCV RLS: did:x%x/ste:x%x flg:x%x",
  6066. did, vport->port_state, ndlp->nlp_flag);
  6067. phba->fc_stat.elsRcvRLS++;
  6068. lpfc_els_rcv_rls(vport, elsiocb, ndlp);
  6069. if (newnode)
  6070. lpfc_nlp_put(ndlp);
  6071. break;
  6072. case ELS_CMD_RPS:
  6073. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6074. "RCV RPS: did:x%x/ste:x%x flg:x%x",
  6075. did, vport->port_state, ndlp->nlp_flag);
  6076. phba->fc_stat.elsRcvRPS++;
  6077. lpfc_els_rcv_rps(vport, elsiocb, ndlp);
  6078. if (newnode)
  6079. lpfc_nlp_put(ndlp);
  6080. break;
  6081. case ELS_CMD_RPL:
  6082. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6083. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  6084. did, vport->port_state, ndlp->nlp_flag);
  6085. phba->fc_stat.elsRcvRPL++;
  6086. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  6087. if (newnode)
  6088. lpfc_nlp_put(ndlp);
  6089. break;
  6090. case ELS_CMD_RNID:
  6091. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6092. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  6093. did, vport->port_state, ndlp->nlp_flag);
  6094. phba->fc_stat.elsRcvRNID++;
  6095. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  6096. if (newnode)
  6097. lpfc_nlp_put(ndlp);
  6098. break;
  6099. case ELS_CMD_RTV:
  6100. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6101. "RCV RTV: did:x%x/ste:x%x flg:x%x",
  6102. did, vport->port_state, ndlp->nlp_flag);
  6103. phba->fc_stat.elsRcvRTV++;
  6104. lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
  6105. if (newnode)
  6106. lpfc_nlp_put(ndlp);
  6107. break;
  6108. case ELS_CMD_RRQ:
  6109. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6110. "RCV RRQ: did:x%x/ste:x%x flg:x%x",
  6111. did, vport->port_state, ndlp->nlp_flag);
  6112. phba->fc_stat.elsRcvRRQ++;
  6113. lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
  6114. if (newnode)
  6115. lpfc_nlp_put(ndlp);
  6116. break;
  6117. case ELS_CMD_ECHO:
  6118. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6119. "RCV ECHO: did:x%x/ste:x%x flg:x%x",
  6120. did, vport->port_state, ndlp->nlp_flag);
  6121. phba->fc_stat.elsRcvECHO++;
  6122. lpfc_els_rcv_echo(vport, elsiocb, ndlp);
  6123. if (newnode)
  6124. lpfc_nlp_put(ndlp);
  6125. break;
  6126. default:
  6127. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  6128. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  6129. cmd, did, vport->port_state);
  6130. /* Unsupported ELS command, reject */
  6131. rjt_err = LSRJT_CMD_UNSUPPORTED;
  6132. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  6133. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6134. "0115 Unknown ELS command x%x "
  6135. "received from NPORT x%x\n", cmd, did);
  6136. if (newnode)
  6137. lpfc_nlp_put(ndlp);
  6138. break;
  6139. }
  6140. /* check if need to LS_RJT received ELS cmd */
  6141. if (rjt_err) {
  6142. memset(&stat, 0, sizeof(stat));
  6143. stat.un.b.lsRjtRsnCode = rjt_err;
  6144. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  6145. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  6146. NULL);
  6147. }
  6148. lpfc_nlp_put(elsiocb->context1);
  6149. elsiocb->context1 = NULL;
  6150. return;
  6151. dropit:
  6152. if (vport && !(vport->load_flag & FC_UNLOADING))
  6153. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6154. "0111 Dropping received ELS cmd "
  6155. "Data: x%x x%x x%x\n",
  6156. icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
  6157. phba->fc_stat.elsRcvDrop++;
  6158. }
  6159. /**
  6160. * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
  6161. * @phba: pointer to lpfc hba data structure.
  6162. * @pring: pointer to a SLI ring.
  6163. * @elsiocb: pointer to lpfc els iocb data structure.
  6164. *
  6165. * This routine is used to process an unsolicited event received from a SLI
  6166. * (Service Level Interface) ring. The actual processing of the data buffer
  6167. * associated with the unsolicited event is done by invoking the routine
  6168. * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
  6169. * SLI ring on which the unsolicited event was received.
  6170. **/
  6171. void
  6172. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  6173. struct lpfc_iocbq *elsiocb)
  6174. {
  6175. struct lpfc_vport *vport = phba->pport;
  6176. IOCB_t *icmd = &elsiocb->iocb;
  6177. dma_addr_t paddr;
  6178. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  6179. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  6180. elsiocb->context1 = NULL;
  6181. elsiocb->context2 = NULL;
  6182. elsiocb->context3 = NULL;
  6183. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  6184. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  6185. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  6186. (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
  6187. phba->fc_stat.NoRcvBuf++;
  6188. /* Not enough posted buffers; Try posting more buffers */
  6189. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  6190. lpfc_post_buffer(phba, pring, 0);
  6191. return;
  6192. }
  6193. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  6194. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  6195. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  6196. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  6197. vport = phba->pport;
  6198. else
  6199. vport = lpfc_find_vport_by_vpid(phba,
  6200. icmd->unsli3.rcvsli3.vpi);
  6201. }
  6202. /* If there are no BDEs associated
  6203. * with this IOCB, there is nothing to do.
  6204. */
  6205. if (icmd->ulpBdeCount == 0)
  6206. return;
  6207. /* type of ELS cmd is first 32bit word
  6208. * in packet
  6209. */
  6210. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  6211. elsiocb->context2 = bdeBuf1;
  6212. } else {
  6213. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  6214. icmd->un.cont64[0].addrLow);
  6215. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  6216. paddr);
  6217. }
  6218. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  6219. /*
  6220. * The different unsolicited event handlers would tell us
  6221. * if they are done with "mp" by setting context2 to NULL.
  6222. */
  6223. if (elsiocb->context2) {
  6224. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  6225. elsiocb->context2 = NULL;
  6226. }
  6227. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  6228. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  6229. icmd->ulpBdeCount == 2) {
  6230. elsiocb->context2 = bdeBuf2;
  6231. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  6232. /* free mp if we are done with it */
  6233. if (elsiocb->context2) {
  6234. lpfc_in_buf_free(phba, elsiocb->context2);
  6235. elsiocb->context2 = NULL;
  6236. }
  6237. }
  6238. }
  6239. /**
  6240. * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
  6241. * @phba: pointer to lpfc hba data structure.
  6242. * @vport: pointer to a virtual N_Port data structure.
  6243. *
  6244. * This routine issues a Port Login (PLOGI) to the Name Server with
  6245. * State Change Request (SCR) for a @vport. This routine will create an
  6246. * ndlp for the Name Server associated to the @vport if such node does
  6247. * not already exist. The PLOGI to Name Server is issued by invoking the
  6248. * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
  6249. * (FDMI) is configured to the @vport, a FDMI node will be created and
  6250. * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
  6251. **/
  6252. void
  6253. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  6254. {
  6255. struct lpfc_nodelist *ndlp, *ndlp_fdmi;
  6256. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6257. /*
  6258. * If lpfc_delay_discovery parameter is set and the clean address
  6259. * bit is cleared and fc fabric parameters chenged, delay FC NPort
  6260. * discovery.
  6261. */
  6262. spin_lock_irq(shost->host_lock);
  6263. if (vport->fc_flag & FC_DISC_DELAYED) {
  6264. spin_unlock_irq(shost->host_lock);
  6265. mod_timer(&vport->delayed_disc_tmo,
  6266. jiffies + HZ * phba->fc_ratov);
  6267. return;
  6268. }
  6269. spin_unlock_irq(shost->host_lock);
  6270. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  6271. if (!ndlp) {
  6272. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  6273. if (!ndlp) {
  6274. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  6275. lpfc_disc_start(vport);
  6276. return;
  6277. }
  6278. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6279. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6280. "0251 NameServer login: no memory\n");
  6281. return;
  6282. }
  6283. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  6284. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  6285. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
  6286. if (!ndlp) {
  6287. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  6288. lpfc_disc_start(vport);
  6289. return;
  6290. }
  6291. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6292. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6293. "0348 NameServer login: node freed\n");
  6294. return;
  6295. }
  6296. }
  6297. ndlp->nlp_type |= NLP_FABRIC;
  6298. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  6299. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  6300. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6301. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6302. "0252 Cannot issue NameServer login\n");
  6303. return;
  6304. }
  6305. if (vport->cfg_fdmi_on) {
  6306. /* If this is the first time, allocate an ndlp and initialize
  6307. * it. Otherwise, make sure the node is enabled and then do the
  6308. * login.
  6309. */
  6310. ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
  6311. if (!ndlp_fdmi) {
  6312. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  6313. GFP_KERNEL);
  6314. if (ndlp_fdmi) {
  6315. lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
  6316. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  6317. } else
  6318. return;
  6319. }
  6320. if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
  6321. ndlp_fdmi = lpfc_enable_node(vport,
  6322. ndlp_fdmi,
  6323. NLP_STE_NPR_NODE);
  6324. if (ndlp_fdmi) {
  6325. lpfc_nlp_set_state(vport, ndlp_fdmi,
  6326. NLP_STE_PLOGI_ISSUE);
  6327. lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
  6328. }
  6329. }
  6330. }
  6331. /**
  6332. * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
  6333. * @phba: pointer to lpfc hba data structure.
  6334. * @pmb: pointer to the driver internal queue element for mailbox command.
  6335. *
  6336. * This routine is the completion callback function to register new vport
  6337. * mailbox command. If the new vport mailbox command completes successfully,
  6338. * the fabric registration login shall be performed on physical port (the
  6339. * new vport created is actually a physical port, with VPI 0) or the port
  6340. * login to Name Server for State Change Request (SCR) will be performed
  6341. * on virtual port (real virtual port, with VPI greater than 0).
  6342. **/
  6343. static void
  6344. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  6345. {
  6346. struct lpfc_vport *vport = pmb->vport;
  6347. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6348. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  6349. MAILBOX_t *mb = &pmb->u.mb;
  6350. int rc;
  6351. spin_lock_irq(shost->host_lock);
  6352. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  6353. spin_unlock_irq(shost->host_lock);
  6354. if (mb->mbxStatus) {
  6355. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6356. "0915 Register VPI failed : Status: x%x"
  6357. " upd bit: x%x \n", mb->mbxStatus,
  6358. mb->un.varRegVpi.upd);
  6359. if (phba->sli_rev == LPFC_SLI_REV4 &&
  6360. mb->un.varRegVpi.upd)
  6361. goto mbox_err_exit ;
  6362. switch (mb->mbxStatus) {
  6363. case 0x11: /* unsupported feature */
  6364. case 0x9603: /* max_vpi exceeded */
  6365. case 0x9602: /* Link event since CLEAR_LA */
  6366. /* giving up on vport registration */
  6367. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6368. spin_lock_irq(shost->host_lock);
  6369. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  6370. spin_unlock_irq(shost->host_lock);
  6371. lpfc_can_disctmo(vport);
  6372. break;
  6373. /* If reg_vpi fail with invalid VPI status, re-init VPI */
  6374. case 0x20:
  6375. spin_lock_irq(shost->host_lock);
  6376. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6377. spin_unlock_irq(shost->host_lock);
  6378. lpfc_init_vpi(phba, pmb, vport->vpi);
  6379. pmb->vport = vport;
  6380. pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
  6381. rc = lpfc_sli_issue_mbox(phba, pmb,
  6382. MBX_NOWAIT);
  6383. if (rc == MBX_NOT_FINISHED) {
  6384. lpfc_printf_vlog(vport,
  6385. KERN_ERR, LOG_MBOX,
  6386. "2732 Failed to issue INIT_VPI"
  6387. " mailbox command\n");
  6388. } else {
  6389. lpfc_nlp_put(ndlp);
  6390. return;
  6391. }
  6392. default:
  6393. /* Try to recover from this error */
  6394. if (phba->sli_rev == LPFC_SLI_REV4)
  6395. lpfc_sli4_unreg_all_rpis(vport);
  6396. lpfc_mbx_unreg_vpi(vport);
  6397. spin_lock_irq(shost->host_lock);
  6398. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6399. spin_unlock_irq(shost->host_lock);
  6400. if (vport->port_type == LPFC_PHYSICAL_PORT
  6401. && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
  6402. lpfc_issue_init_vfi(vport);
  6403. else
  6404. lpfc_initial_fdisc(vport);
  6405. break;
  6406. }
  6407. } else {
  6408. spin_lock_irq(shost->host_lock);
  6409. vport->vpi_state |= LPFC_VPI_REGISTERED;
  6410. spin_unlock_irq(shost->host_lock);
  6411. if (vport == phba->pport) {
  6412. if (phba->sli_rev < LPFC_SLI_REV4)
  6413. lpfc_issue_fabric_reglogin(vport);
  6414. else {
  6415. /*
  6416. * If the physical port is instantiated using
  6417. * FDISC, do not start vport discovery.
  6418. */
  6419. if (vport->port_state != LPFC_FDISC)
  6420. lpfc_start_fdiscs(phba);
  6421. lpfc_do_scr_ns_plogi(phba, vport);
  6422. }
  6423. } else
  6424. lpfc_do_scr_ns_plogi(phba, vport);
  6425. }
  6426. mbox_err_exit:
  6427. /* Now, we decrement the ndlp reference count held for this
  6428. * callback function
  6429. */
  6430. lpfc_nlp_put(ndlp);
  6431. mempool_free(pmb, phba->mbox_mem_pool);
  6432. return;
  6433. }
  6434. /**
  6435. * lpfc_register_new_vport - Register a new vport with a HBA
  6436. * @phba: pointer to lpfc hba data structure.
  6437. * @vport: pointer to a host virtual N_Port data structure.
  6438. * @ndlp: pointer to a node-list data structure.
  6439. *
  6440. * This routine registers the @vport as a new virtual port with a HBA.
  6441. * It is done through a registering vpi mailbox command.
  6442. **/
  6443. void
  6444. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  6445. struct lpfc_nodelist *ndlp)
  6446. {
  6447. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6448. LPFC_MBOXQ_t *mbox;
  6449. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6450. if (mbox) {
  6451. lpfc_reg_vpi(vport, mbox);
  6452. mbox->vport = vport;
  6453. mbox->context2 = lpfc_nlp_get(ndlp);
  6454. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  6455. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  6456. == MBX_NOT_FINISHED) {
  6457. /* mailbox command not success, decrement ndlp
  6458. * reference count for this command
  6459. */
  6460. lpfc_nlp_put(ndlp);
  6461. mempool_free(mbox, phba->mbox_mem_pool);
  6462. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6463. "0253 Register VPI: Can't send mbox\n");
  6464. goto mbox_err_exit;
  6465. }
  6466. } else {
  6467. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  6468. "0254 Register VPI: no memory\n");
  6469. goto mbox_err_exit;
  6470. }
  6471. return;
  6472. mbox_err_exit:
  6473. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6474. spin_lock_irq(shost->host_lock);
  6475. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  6476. spin_unlock_irq(shost->host_lock);
  6477. return;
  6478. }
  6479. /**
  6480. * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
  6481. * @phba: pointer to lpfc hba data structure.
  6482. *
  6483. * This routine cancels the retry delay timers to all the vports.
  6484. **/
  6485. void
  6486. lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
  6487. {
  6488. struct lpfc_vport **vports;
  6489. struct lpfc_nodelist *ndlp;
  6490. uint32_t link_state;
  6491. int i;
  6492. /* Treat this failure as linkdown for all vports */
  6493. link_state = phba->link_state;
  6494. lpfc_linkdown(phba);
  6495. phba->link_state = link_state;
  6496. vports = lpfc_create_vport_work_array(phba);
  6497. if (vports) {
  6498. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  6499. ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
  6500. if (ndlp)
  6501. lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
  6502. lpfc_els_flush_cmd(vports[i]);
  6503. }
  6504. lpfc_destroy_vport_work_array(phba, vports);
  6505. }
  6506. }
  6507. /**
  6508. * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
  6509. * @phba: pointer to lpfc hba data structure.
  6510. *
  6511. * This routine abort all pending discovery commands and
  6512. * start a timer to retry FLOGI for the physical port
  6513. * discovery.
  6514. **/
  6515. void
  6516. lpfc_retry_pport_discovery(struct lpfc_hba *phba)
  6517. {
  6518. struct lpfc_nodelist *ndlp;
  6519. struct Scsi_Host *shost;
  6520. /* Cancel the all vports retry delay retry timers */
  6521. lpfc_cancel_all_vport_retry_delay_timer(phba);
  6522. /* If fabric require FLOGI, then re-instantiate physical login */
  6523. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  6524. if (!ndlp)
  6525. return;
  6526. shost = lpfc_shost_from_vport(phba->pport);
  6527. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  6528. spin_lock_irq(shost->host_lock);
  6529. ndlp->nlp_flag |= NLP_DELAY_TMO;
  6530. spin_unlock_irq(shost->host_lock);
  6531. ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
  6532. phba->pport->port_state = LPFC_FLOGI;
  6533. return;
  6534. }
  6535. /**
  6536. * lpfc_fabric_login_reqd - Check if FLOGI required.
  6537. * @phba: pointer to lpfc hba data structure.
  6538. * @cmdiocb: pointer to FDISC command iocb.
  6539. * @rspiocb: pointer to FDISC response iocb.
  6540. *
  6541. * This routine checks if a FLOGI is reguired for FDISC
  6542. * to succeed.
  6543. **/
  6544. static int
  6545. lpfc_fabric_login_reqd(struct lpfc_hba *phba,
  6546. struct lpfc_iocbq *cmdiocb,
  6547. struct lpfc_iocbq *rspiocb)
  6548. {
  6549. if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
  6550. (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
  6551. return 0;
  6552. else
  6553. return 1;
  6554. }
  6555. /**
  6556. * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
  6557. * @phba: pointer to lpfc hba data structure.
  6558. * @cmdiocb: pointer to lpfc command iocb data structure.
  6559. * @rspiocb: pointer to lpfc response iocb data structure.
  6560. *
  6561. * This routine is the completion callback function to a Fabric Discover
  6562. * (FDISC) ELS command. Since all the FDISC ELS commands are issued
  6563. * single threaded, each FDISC completion callback function will reset
  6564. * the discovery timer for all vports such that the timers will not get
  6565. * unnecessary timeout. The function checks the FDISC IOCB status. If error
  6566. * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
  6567. * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
  6568. * assigned to the vport has been changed with the completion of the FDISC
  6569. * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
  6570. * are unregistered from the HBA, and then the lpfc_register_new_vport()
  6571. * routine is invoked to register new vport with the HBA. Otherwise, the
  6572. * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
  6573. * Server for State Change Request (SCR).
  6574. **/
  6575. static void
  6576. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6577. struct lpfc_iocbq *rspiocb)
  6578. {
  6579. struct lpfc_vport *vport = cmdiocb->vport;
  6580. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6581. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  6582. struct lpfc_nodelist *np;
  6583. struct lpfc_nodelist *next_np;
  6584. IOCB_t *irsp = &rspiocb->iocb;
  6585. struct lpfc_iocbq *piocb;
  6586. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  6587. struct serv_parm *sp;
  6588. uint8_t fabric_param_changed;
  6589. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6590. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  6591. irsp->ulpStatus, irsp->un.ulpWord[4],
  6592. vport->fc_prevDID);
  6593. /* Since all FDISCs are being single threaded, we
  6594. * must reset the discovery timer for ALL vports
  6595. * waiting to send FDISC when one completes.
  6596. */
  6597. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  6598. lpfc_set_disctmo(piocb->vport);
  6599. }
  6600. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6601. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  6602. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  6603. if (irsp->ulpStatus) {
  6604. if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
  6605. lpfc_retry_pport_discovery(phba);
  6606. goto out;
  6607. }
  6608. /* Check for retry */
  6609. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  6610. goto out;
  6611. /* FDISC failed */
  6612. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6613. "0126 FDISC failed. (x%x/x%x)\n",
  6614. irsp->ulpStatus, irsp->un.ulpWord[4]);
  6615. goto fdisc_failed;
  6616. }
  6617. spin_lock_irq(shost->host_lock);
  6618. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  6619. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  6620. vport->fc_flag |= FC_FABRIC;
  6621. if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
  6622. vport->fc_flag |= FC_PUBLIC_LOOP;
  6623. spin_unlock_irq(shost->host_lock);
  6624. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  6625. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  6626. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  6627. sp = prsp->virt + sizeof(uint32_t);
  6628. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  6629. memcpy(&vport->fabric_portname, &sp->portName,
  6630. sizeof(struct lpfc_name));
  6631. memcpy(&vport->fabric_nodename, &sp->nodeName,
  6632. sizeof(struct lpfc_name));
  6633. if (fabric_param_changed &&
  6634. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  6635. /* If our NportID changed, we need to ensure all
  6636. * remaining NPORTs get unreg_login'ed so we can
  6637. * issue unreg_vpi.
  6638. */
  6639. list_for_each_entry_safe(np, next_np,
  6640. &vport->fc_nodes, nlp_listp) {
  6641. if (!NLP_CHK_NODE_ACT(ndlp) ||
  6642. (np->nlp_state != NLP_STE_NPR_NODE) ||
  6643. !(np->nlp_flag & NLP_NPR_ADISC))
  6644. continue;
  6645. spin_lock_irq(shost->host_lock);
  6646. np->nlp_flag &= ~NLP_NPR_ADISC;
  6647. spin_unlock_irq(shost->host_lock);
  6648. lpfc_unreg_rpi(vport, np);
  6649. }
  6650. lpfc_cleanup_pending_mbox(vport);
  6651. if (phba->sli_rev == LPFC_SLI_REV4)
  6652. lpfc_sli4_unreg_all_rpis(vport);
  6653. lpfc_mbx_unreg_vpi(vport);
  6654. spin_lock_irq(shost->host_lock);
  6655. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  6656. if (phba->sli_rev == LPFC_SLI_REV4)
  6657. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  6658. else
  6659. vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
  6660. spin_unlock_irq(shost->host_lock);
  6661. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  6662. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  6663. /*
  6664. * Driver needs to re-reg VPI in order for f/w
  6665. * to update the MAC address.
  6666. */
  6667. lpfc_register_new_vport(phba, vport, ndlp);
  6668. goto out;
  6669. }
  6670. if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
  6671. lpfc_issue_init_vpi(vport);
  6672. else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  6673. lpfc_register_new_vport(phba, vport, ndlp);
  6674. else
  6675. lpfc_do_scr_ns_plogi(phba, vport);
  6676. goto out;
  6677. fdisc_failed:
  6678. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6679. /* Cancel discovery timer */
  6680. lpfc_can_disctmo(vport);
  6681. lpfc_nlp_put(ndlp);
  6682. out:
  6683. lpfc_els_free_iocb(phba, cmdiocb);
  6684. }
  6685. /**
  6686. * lpfc_issue_els_fdisc - Issue a fdisc iocb command
  6687. * @vport: pointer to a virtual N_Port data structure.
  6688. * @ndlp: pointer to a node-list data structure.
  6689. * @retry: number of retries to the command IOCB.
  6690. *
  6691. * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
  6692. * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
  6693. * routine to issue the IOCB, which makes sure only one outstanding fabric
  6694. * IOCB will be sent off HBA at any given time.
  6695. *
  6696. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6697. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6698. * will be stored into the context1 field of the IOCB for the completion
  6699. * callback function to the FDISC ELS command.
  6700. *
  6701. * Return code
  6702. * 0 - Successfully issued fdisc iocb command
  6703. * 1 - Failed to issue fdisc iocb command
  6704. **/
  6705. static int
  6706. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  6707. uint8_t retry)
  6708. {
  6709. struct lpfc_hba *phba = vport->phba;
  6710. IOCB_t *icmd;
  6711. struct lpfc_iocbq *elsiocb;
  6712. struct serv_parm *sp;
  6713. uint8_t *pcmd;
  6714. uint16_t cmdsize;
  6715. int did = ndlp->nlp_DID;
  6716. int rc;
  6717. vport->port_state = LPFC_FDISC;
  6718. vport->fc_myDID = 0;
  6719. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  6720. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  6721. ELS_CMD_FDISC);
  6722. if (!elsiocb) {
  6723. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6724. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6725. "0255 Issue FDISC: no IOCB\n");
  6726. return 1;
  6727. }
  6728. icmd = &elsiocb->iocb;
  6729. icmd->un.elsreq64.myID = 0;
  6730. icmd->un.elsreq64.fl = 1;
  6731. /*
  6732. * SLI3 ports require a different context type value than SLI4.
  6733. * Catch SLI3 ports here and override the prep.
  6734. */
  6735. if (phba->sli_rev == LPFC_SLI_REV3) {
  6736. icmd->ulpCt_h = 1;
  6737. icmd->ulpCt_l = 0;
  6738. }
  6739. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6740. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  6741. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  6742. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  6743. sp = (struct serv_parm *) pcmd;
  6744. /* Setup CSPs accordingly for Fabric */
  6745. sp->cmn.e_d_tov = 0;
  6746. sp->cmn.w2.r_a_tov = 0;
  6747. sp->cmn.virtual_fabric_support = 0;
  6748. sp->cls1.classValid = 0;
  6749. sp->cls2.seqDelivery = 1;
  6750. sp->cls3.seqDelivery = 1;
  6751. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  6752. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  6753. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  6754. pcmd += sizeof(uint32_t); /* Port Name */
  6755. memcpy(pcmd, &vport->fc_portname, 8);
  6756. pcmd += sizeof(uint32_t); /* Node Name */
  6757. pcmd += sizeof(uint32_t); /* Node Name */
  6758. memcpy(pcmd, &vport->fc_nodename, 8);
  6759. lpfc_set_disctmo(vport);
  6760. phba->fc_stat.elsXmitFDISC++;
  6761. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  6762. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6763. "Issue FDISC: did:x%x",
  6764. did, 0, 0);
  6765. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  6766. if (rc == IOCB_ERROR) {
  6767. lpfc_els_free_iocb(phba, elsiocb);
  6768. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  6769. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  6770. "0256 Issue FDISC: Cannot send IOCB\n");
  6771. return 1;
  6772. }
  6773. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  6774. return 0;
  6775. }
  6776. /**
  6777. * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
  6778. * @phba: pointer to lpfc hba data structure.
  6779. * @cmdiocb: pointer to lpfc command iocb data structure.
  6780. * @rspiocb: pointer to lpfc response iocb data structure.
  6781. *
  6782. * This routine is the completion callback function to the issuing of a LOGO
  6783. * ELS command off a vport. It frees the command IOCB and then decrement the
  6784. * reference count held on ndlp for this completion function, indicating that
  6785. * the reference to the ndlp is no long needed. Note that the
  6786. * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
  6787. * callback function and an additional explicit ndlp reference decrementation
  6788. * will trigger the actual release of the ndlp.
  6789. **/
  6790. static void
  6791. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  6792. struct lpfc_iocbq *rspiocb)
  6793. {
  6794. struct lpfc_vport *vport = cmdiocb->vport;
  6795. IOCB_t *irsp;
  6796. struct lpfc_nodelist *ndlp;
  6797. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6798. ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
  6799. irsp = &rspiocb->iocb;
  6800. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6801. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  6802. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  6803. lpfc_els_free_iocb(phba, cmdiocb);
  6804. vport->unreg_vpi_cmpl = VPORT_ERROR;
  6805. /* Trigger the release of the ndlp after logo */
  6806. lpfc_nlp_put(ndlp);
  6807. /* NPIV LOGO completes to NPort <nlp_DID> */
  6808. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6809. "2928 NPIV LOGO completes to NPort x%x "
  6810. "Data: x%x x%x x%x x%x\n",
  6811. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  6812. irsp->ulpTimeout, vport->num_disc_nodes);
  6813. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  6814. spin_lock_irq(shost->host_lock);
  6815. vport->fc_flag &= ~FC_FABRIC;
  6816. spin_unlock_irq(shost->host_lock);
  6817. }
  6818. }
  6819. /**
  6820. * lpfc_issue_els_npiv_logo - Issue a logo off a vport
  6821. * @vport: pointer to a virtual N_Port data structure.
  6822. * @ndlp: pointer to a node-list data structure.
  6823. *
  6824. * This routine issues a LOGO ELS command to an @ndlp off a @vport.
  6825. *
  6826. * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
  6827. * will be incremented by 1 for holding the ndlp and the reference to ndlp
  6828. * will be stored into the context1 field of the IOCB for the completion
  6829. * callback function to the LOGO ELS command.
  6830. *
  6831. * Return codes
  6832. * 0 - Successfully issued logo off the @vport
  6833. * 1 - Failed to issue logo off the @vport
  6834. **/
  6835. int
  6836. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  6837. {
  6838. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6839. struct lpfc_hba *phba = vport->phba;
  6840. IOCB_t *icmd;
  6841. struct lpfc_iocbq *elsiocb;
  6842. uint8_t *pcmd;
  6843. uint16_t cmdsize;
  6844. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  6845. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  6846. ELS_CMD_LOGO);
  6847. if (!elsiocb)
  6848. return 1;
  6849. icmd = &elsiocb->iocb;
  6850. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  6851. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  6852. pcmd += sizeof(uint32_t);
  6853. /* Fill in LOGO payload */
  6854. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  6855. pcmd += sizeof(uint32_t);
  6856. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  6857. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  6858. "Issue LOGO npiv did:x%x flg:x%x",
  6859. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  6860. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  6861. spin_lock_irq(shost->host_lock);
  6862. ndlp->nlp_flag |= NLP_LOGO_SND;
  6863. spin_unlock_irq(shost->host_lock);
  6864. if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
  6865. IOCB_ERROR) {
  6866. spin_lock_irq(shost->host_lock);
  6867. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  6868. spin_unlock_irq(shost->host_lock);
  6869. lpfc_els_free_iocb(phba, elsiocb);
  6870. return 1;
  6871. }
  6872. return 0;
  6873. }
  6874. /**
  6875. * lpfc_fabric_block_timeout - Handler function to the fabric block timer
  6876. * @ptr: holder for the timer function associated data.
  6877. *
  6878. * This routine is invoked by the fabric iocb block timer after
  6879. * timeout. It posts the fabric iocb block timeout event by setting the
  6880. * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
  6881. * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
  6882. * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
  6883. * posted event WORKER_FABRIC_BLOCK_TMO.
  6884. **/
  6885. void
  6886. lpfc_fabric_block_timeout(unsigned long ptr)
  6887. {
  6888. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  6889. unsigned long iflags;
  6890. uint32_t tmo_posted;
  6891. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  6892. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  6893. if (!tmo_posted)
  6894. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  6895. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  6896. if (!tmo_posted)
  6897. lpfc_worker_wake_up(phba);
  6898. return;
  6899. }
  6900. /**
  6901. * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
  6902. * @phba: pointer to lpfc hba data structure.
  6903. *
  6904. * This routine issues one fabric iocb from the driver internal list to
  6905. * the HBA. It first checks whether it's ready to issue one fabric iocb to
  6906. * the HBA (whether there is no outstanding fabric iocb). If so, it shall
  6907. * remove one pending fabric iocb from the driver internal list and invokes
  6908. * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
  6909. **/
  6910. static void
  6911. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  6912. {
  6913. struct lpfc_iocbq *iocb;
  6914. unsigned long iflags;
  6915. int ret;
  6916. IOCB_t *cmd;
  6917. repeat:
  6918. iocb = NULL;
  6919. spin_lock_irqsave(&phba->hbalock, iflags);
  6920. /* Post any pending iocb to the SLI layer */
  6921. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  6922. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  6923. list);
  6924. if (iocb)
  6925. /* Increment fabric iocb count to hold the position */
  6926. atomic_inc(&phba->fabric_iocb_count);
  6927. }
  6928. spin_unlock_irqrestore(&phba->hbalock, iflags);
  6929. if (iocb) {
  6930. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  6931. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  6932. iocb->iocb_flag |= LPFC_IO_FABRIC;
  6933. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  6934. "Fabric sched1: ste:x%x",
  6935. iocb->vport->port_state, 0, 0);
  6936. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  6937. if (ret == IOCB_ERROR) {
  6938. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  6939. iocb->fabric_iocb_cmpl = NULL;
  6940. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  6941. cmd = &iocb->iocb;
  6942. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  6943. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  6944. iocb->iocb_cmpl(phba, iocb, iocb);
  6945. atomic_dec(&phba->fabric_iocb_count);
  6946. goto repeat;
  6947. }
  6948. }
  6949. return;
  6950. }
  6951. /**
  6952. * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
  6953. * @phba: pointer to lpfc hba data structure.
  6954. *
  6955. * This routine unblocks the issuing fabric iocb command. The function
  6956. * will clear the fabric iocb block bit and then invoke the routine
  6957. * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
  6958. * from the driver internal fabric iocb list.
  6959. **/
  6960. void
  6961. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  6962. {
  6963. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  6964. lpfc_resume_fabric_iocbs(phba);
  6965. return;
  6966. }
  6967. /**
  6968. * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
  6969. * @phba: pointer to lpfc hba data structure.
  6970. *
  6971. * This routine blocks the issuing fabric iocb for a specified amount of
  6972. * time (currently 100 ms). This is done by set the fabric iocb block bit
  6973. * and set up a timeout timer for 100ms. When the block bit is set, no more
  6974. * fabric iocb will be issued out of the HBA.
  6975. **/
  6976. static void
  6977. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  6978. {
  6979. int blocked;
  6980. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  6981. /* Start a timer to unblock fabric iocbs after 100ms */
  6982. if (!blocked)
  6983. mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
  6984. return;
  6985. }
  6986. /**
  6987. * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
  6988. * @phba: pointer to lpfc hba data structure.
  6989. * @cmdiocb: pointer to lpfc command iocb data structure.
  6990. * @rspiocb: pointer to lpfc response iocb data structure.
  6991. *
  6992. * This routine is the callback function that is put to the fabric iocb's
  6993. * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
  6994. * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
  6995. * function first restores and invokes the original iocb's callback function
  6996. * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
  6997. * fabric bound iocb from the driver internal fabric iocb list onto the wire.
  6998. **/
  6999. static void
  7000. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  7001. struct lpfc_iocbq *rspiocb)
  7002. {
  7003. struct ls_rjt stat;
  7004. if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
  7005. BUG();
  7006. switch (rspiocb->iocb.ulpStatus) {
  7007. case IOSTAT_NPORT_RJT:
  7008. case IOSTAT_FABRIC_RJT:
  7009. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  7010. lpfc_block_fabric_iocbs(phba);
  7011. }
  7012. break;
  7013. case IOSTAT_NPORT_BSY:
  7014. case IOSTAT_FABRIC_BSY:
  7015. lpfc_block_fabric_iocbs(phba);
  7016. break;
  7017. case IOSTAT_LS_RJT:
  7018. stat.un.lsRjtError =
  7019. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  7020. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  7021. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  7022. lpfc_block_fabric_iocbs(phba);
  7023. break;
  7024. }
  7025. if (atomic_read(&phba->fabric_iocb_count) == 0)
  7026. BUG();
  7027. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  7028. cmdiocb->fabric_iocb_cmpl = NULL;
  7029. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  7030. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  7031. atomic_dec(&phba->fabric_iocb_count);
  7032. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  7033. /* Post any pending iocbs to HBA */
  7034. lpfc_resume_fabric_iocbs(phba);
  7035. }
  7036. }
  7037. /**
  7038. * lpfc_issue_fabric_iocb - Issue a fabric iocb command
  7039. * @phba: pointer to lpfc hba data structure.
  7040. * @iocb: pointer to lpfc command iocb data structure.
  7041. *
  7042. * This routine is used as the top-level API for issuing a fabric iocb command
  7043. * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
  7044. * function makes sure that only one fabric bound iocb will be outstanding at
  7045. * any given time. As such, this function will first check to see whether there
  7046. * is already an outstanding fabric iocb on the wire. If so, it will put the
  7047. * newly issued iocb onto the driver internal fabric iocb list, waiting to be
  7048. * issued later. Otherwise, it will issue the iocb on the wire and update the
  7049. * fabric iocb count it indicate that there is one fabric iocb on the wire.
  7050. *
  7051. * Note, this implementation has a potential sending out fabric IOCBs out of
  7052. * order. The problem is caused by the construction of the "ready" boolen does
  7053. * not include the condition that the internal fabric IOCB list is empty. As
  7054. * such, it is possible a fabric IOCB issued by this routine might be "jump"
  7055. * ahead of the fabric IOCBs in the internal list.
  7056. *
  7057. * Return code
  7058. * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
  7059. * IOCB_ERROR - failed to issue fabric iocb
  7060. **/
  7061. static int
  7062. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  7063. {
  7064. unsigned long iflags;
  7065. int ready;
  7066. int ret;
  7067. if (atomic_read(&phba->fabric_iocb_count) > 1)
  7068. BUG();
  7069. spin_lock_irqsave(&phba->hbalock, iflags);
  7070. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  7071. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  7072. if (ready)
  7073. /* Increment fabric iocb count to hold the position */
  7074. atomic_inc(&phba->fabric_iocb_count);
  7075. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7076. if (ready) {
  7077. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  7078. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  7079. iocb->iocb_flag |= LPFC_IO_FABRIC;
  7080. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  7081. "Fabric sched2: ste:x%x",
  7082. iocb->vport->port_state, 0, 0);
  7083. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  7084. if (ret == IOCB_ERROR) {
  7085. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  7086. iocb->fabric_iocb_cmpl = NULL;
  7087. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  7088. atomic_dec(&phba->fabric_iocb_count);
  7089. }
  7090. } else {
  7091. spin_lock_irqsave(&phba->hbalock, iflags);
  7092. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  7093. spin_unlock_irqrestore(&phba->hbalock, iflags);
  7094. ret = IOCB_SUCCESS;
  7095. }
  7096. return ret;
  7097. }
  7098. /**
  7099. * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
  7100. * @vport: pointer to a virtual N_Port data structure.
  7101. *
  7102. * This routine aborts all the IOCBs associated with a @vport from the
  7103. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  7104. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  7105. * list, removes each IOCB associated with the @vport off the list, set the
  7106. * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
  7107. * associated with the IOCB.
  7108. **/
  7109. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  7110. {
  7111. LIST_HEAD(completions);
  7112. struct lpfc_hba *phba = vport->phba;
  7113. struct lpfc_iocbq *tmp_iocb, *piocb;
  7114. spin_lock_irq(&phba->hbalock);
  7115. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  7116. list) {
  7117. if (piocb->vport != vport)
  7118. continue;
  7119. list_move_tail(&piocb->list, &completions);
  7120. }
  7121. spin_unlock_irq(&phba->hbalock);
  7122. /* Cancel all the IOCBs from the completions list */
  7123. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7124. IOERR_SLI_ABORTED);
  7125. }
  7126. /**
  7127. * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
  7128. * @ndlp: pointer to a node-list data structure.
  7129. *
  7130. * This routine aborts all the IOCBs associated with an @ndlp from the
  7131. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  7132. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  7133. * list, removes each IOCB associated with the @ndlp off the list, set the
  7134. * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
  7135. * associated with the IOCB.
  7136. **/
  7137. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  7138. {
  7139. LIST_HEAD(completions);
  7140. struct lpfc_hba *phba = ndlp->phba;
  7141. struct lpfc_iocbq *tmp_iocb, *piocb;
  7142. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7143. spin_lock_irq(&phba->hbalock);
  7144. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  7145. list) {
  7146. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  7147. list_move_tail(&piocb->list, &completions);
  7148. }
  7149. }
  7150. spin_unlock_irq(&phba->hbalock);
  7151. /* Cancel all the IOCBs from the completions list */
  7152. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7153. IOERR_SLI_ABORTED);
  7154. }
  7155. /**
  7156. * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
  7157. * @phba: pointer to lpfc hba data structure.
  7158. *
  7159. * This routine aborts all the IOCBs currently on the driver internal
  7160. * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
  7161. * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
  7162. * list, removes IOCBs off the list, set the status feild to
  7163. * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
  7164. * the IOCB.
  7165. **/
  7166. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  7167. {
  7168. LIST_HEAD(completions);
  7169. spin_lock_irq(&phba->hbalock);
  7170. list_splice_init(&phba->fabric_iocb_list, &completions);
  7171. spin_unlock_irq(&phba->hbalock);
  7172. /* Cancel all the IOCBs from the completions list */
  7173. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  7174. IOERR_SLI_ABORTED);
  7175. }
  7176. /**
  7177. * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
  7178. * @vport: pointer to lpfc vport data structure.
  7179. *
  7180. * This routine is invoked by the vport cleanup for deletions and the cleanup
  7181. * for an ndlp on removal.
  7182. **/
  7183. void
  7184. lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
  7185. {
  7186. struct lpfc_hba *phba = vport->phba;
  7187. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  7188. unsigned long iflag = 0;
  7189. spin_lock_irqsave(&phba->hbalock, iflag);
  7190. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  7191. list_for_each_entry_safe(sglq_entry, sglq_next,
  7192. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  7193. if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
  7194. sglq_entry->ndlp = NULL;
  7195. }
  7196. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7197. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7198. return;
  7199. }
  7200. /**
  7201. * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
  7202. * @phba: pointer to lpfc hba data structure.
  7203. * @axri: pointer to the els xri abort wcqe structure.
  7204. *
  7205. * This routine is invoked by the worker thread to process a SLI4 slow-path
  7206. * ELS aborted xri.
  7207. **/
  7208. void
  7209. lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
  7210. struct sli4_wcqe_xri_aborted *axri)
  7211. {
  7212. uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
  7213. uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
  7214. uint16_t lxri = 0;
  7215. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  7216. unsigned long iflag = 0;
  7217. struct lpfc_nodelist *ndlp;
  7218. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  7219. spin_lock_irqsave(&phba->hbalock, iflag);
  7220. spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
  7221. list_for_each_entry_safe(sglq_entry, sglq_next,
  7222. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  7223. if (sglq_entry->sli4_xritag == xri) {
  7224. list_del(&sglq_entry->list);
  7225. ndlp = sglq_entry->ndlp;
  7226. sglq_entry->ndlp = NULL;
  7227. list_add_tail(&sglq_entry->list,
  7228. &phba->sli4_hba.lpfc_sgl_list);
  7229. sglq_entry->state = SGL_FREED;
  7230. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7231. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7232. lpfc_set_rrq_active(phba, ndlp,
  7233. sglq_entry->sli4_lxritag,
  7234. rxid, 1);
  7235. /* Check if TXQ queue needs to be serviced */
  7236. if (pring->txq_cnt)
  7237. lpfc_worker_wake_up(phba);
  7238. return;
  7239. }
  7240. }
  7241. spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
  7242. lxri = lpfc_sli4_xri_inrange(phba, xri);
  7243. if (lxri == NO_XRI) {
  7244. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7245. return;
  7246. }
  7247. sglq_entry = __lpfc_get_active_sglq(phba, lxri);
  7248. if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
  7249. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7250. return;
  7251. }
  7252. sglq_entry->state = SGL_XRI_ABORTED;
  7253. spin_unlock_irqrestore(&phba->hbalock, iflag);
  7254. return;
  7255. }