lpfc_els.c 253 KB

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