lpfc_els.c 257 KB

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