lpfc_els.c 281 KB

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