lpfc_els.c 260 KB

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