lpfc_els.c 211 KB

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