lpfc_els.c 256 KB

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