lpfc_els.c 256 KB

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