lpfc_els.c 260 KB

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