lpfc_els.c 373 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. /* See Fibre Channel protocol T11 FC-LS for details */
  24. #include <linux/blkdev.h>
  25. #include <linux/pci.h>
  26. #include <linux/slab.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/delay.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_transport_fc.h>
  33. #include <uapi/scsi/fc/fc_fs.h>
  34. #include <uapi/scsi/fc/fc_els.h>
  35. #include "lpfc_hw4.h"
  36. #include "lpfc_hw.h"
  37. #include "lpfc_sli.h"
  38. #include "lpfc_sli4.h"
  39. #include "lpfc_nl.h"
  40. #include "lpfc_disc.h"
  41. #include "lpfc_scsi.h"
  42. #include "lpfc.h"
  43. #include "lpfc_logmsg.h"
  44. #include "lpfc_crtn.h"
  45. #include "lpfc_vport.h"
  46. #include "lpfc_debugfs.h"
  47. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  48. struct lpfc_iocbq *);
  49. static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
  50. struct lpfc_iocbq *);
  51. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
  52. static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
  53. struct lpfc_nodelist *ndlp, uint8_t retry);
  54. static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
  55. struct lpfc_iocbq *iocb);
  56. static void lpfc_cmpl_els_edc(struct lpfc_hba *phba,
  57. struct lpfc_iocbq *cmdiocb,
  58. struct lpfc_iocbq *rspiocb);
  59. static void lpfc_cmpl_els_uvem(struct lpfc_hba *, struct lpfc_iocbq *,
  60. struct lpfc_iocbq *);
  61. static int lpfc_max_els_tries = 3;
  62. static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport);
  63. static void lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max);
  64. static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid);
  65. /**
  66. * lpfc_els_chk_latt - Check host link attention event for a vport
  67. * @vport: pointer to a host virtual N_Port data structure.
  68. *
  69. * This routine checks whether there is an outstanding host link
  70. * attention event during the discovery process with the @vport. It is done
  71. * by reading the HBA's Host Attention (HA) register. If there is any host
  72. * link attention events during this @vport's discovery process, the @vport
  73. * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
  74. * be issued if the link state is not already in host link cleared state,
  75. * and a return code shall indicate whether the host link attention event
  76. * had happened.
  77. *
  78. * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
  79. * state in LPFC_VPORT_READY, the request for checking host link attention
  80. * event will be ignored and a return code shall indicate no host link
  81. * attention event had happened.
  82. *
  83. * Return codes
  84. * 0 - no host link attention event happened
  85. * 1 - host link attention event happened
  86. **/
  87. int
  88. lpfc_els_chk_latt(struct lpfc_vport *vport)
  89. {
  90. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  91. struct lpfc_hba *phba = vport->phba;
  92. uint32_t ha_copy;
  93. if (vport->port_state >= LPFC_VPORT_READY ||
  94. phba->link_state == LPFC_LINK_DOWN ||
  95. phba->sli_rev > LPFC_SLI_REV3)
  96. return 0;
  97. /* Read the HBA Host Attention Register */
  98. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  99. return 1;
  100. if (!(ha_copy & HA_LATT))
  101. return 0;
  102. /* Pending Link Event during Discovery */
  103. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  104. "0237 Pending Link Event during "
  105. "Discovery: State x%x\n",
  106. phba->pport->port_state);
  107. /* CLEAR_LA should re-enable link attention events and
  108. * we should then immediately take a LATT event. The
  109. * LATT processing should call lpfc_linkdown() which
  110. * will cleanup any left over in-progress discovery
  111. * events.
  112. */
  113. spin_lock_irq(shost->host_lock);
  114. vport->fc_flag |= FC_ABORT_DISCOVERY;
  115. spin_unlock_irq(shost->host_lock);
  116. if (phba->link_state != LPFC_CLEAR_LA)
  117. lpfc_issue_clear_la(phba, vport);
  118. return 1;
  119. }
  120. /**
  121. * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
  122. * @vport: pointer to a host virtual N_Port data structure.
  123. * @expect_rsp: flag indicating whether response is expected.
  124. * @cmd_size: size of the ELS command.
  125. * @retry: number of retries to the command when it fails.
  126. * @ndlp: pointer to a node-list data structure.
  127. * @did: destination identifier.
  128. * @elscmd: the ELS command code.
  129. *
  130. * This routine is used for allocating a lpfc-IOCB data structure from
  131. * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
  132. * passed into the routine for discovery state machine to issue an Extended
  133. * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
  134. * and preparation routine that is used by all the discovery state machine
  135. * routines and the ELS command-specific fields will be later set up by
  136. * the individual discovery machine routines after calling this routine
  137. * allocating and preparing a generic IOCB data structure. It fills in the
  138. * Buffer Descriptor Entries (BDEs), allocates buffers for both command
  139. * payload and response payload (if expected). The reference count on the
  140. * ndlp is incremented by 1 and the reference to the ndlp is put into
  141. * ndlp of the IOCB data structure for this IOCB to hold the ndlp
  142. * reference for the command's callback function to access later.
  143. *
  144. * Return code
  145. * Pointer to the newly allocated/prepared els iocb data structure
  146. * NULL - when els iocb data structure allocation/preparation failed
  147. **/
  148. struct lpfc_iocbq *
  149. lpfc_prep_els_iocb(struct lpfc_vport *vport, u8 expect_rsp,
  150. u16 cmd_size, u8 retry,
  151. struct lpfc_nodelist *ndlp, u32 did,
  152. u32 elscmd)
  153. {
  154. struct lpfc_hba *phba = vport->phba;
  155. struct lpfc_iocbq *elsiocb;
  156. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist, *bmp;
  157. struct ulp_bde64_le *bpl;
  158. u32 timeout = 0;
  159. if (!lpfc_is_link_up(phba))
  160. return NULL;
  161. /* Allocate buffer for command iocb */
  162. elsiocb = lpfc_sli_get_iocbq(phba);
  163. if (!elsiocb)
  164. return NULL;
  165. /*
  166. * If this command is for fabric controller and HBA running
  167. * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
  168. */
  169. if ((did == Fabric_DID) &&
  170. (phba->hba_flag & HBA_FIP_SUPPORT) &&
  171. ((elscmd == ELS_CMD_FLOGI) ||
  172. (elscmd == ELS_CMD_FDISC) ||
  173. (elscmd == ELS_CMD_LOGO)))
  174. switch (elscmd) {
  175. case ELS_CMD_FLOGI:
  176. elsiocb->cmd_flag |=
  177. ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
  178. & LPFC_FIP_ELS_ID_MASK);
  179. break;
  180. case ELS_CMD_FDISC:
  181. elsiocb->cmd_flag |=
  182. ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
  183. & LPFC_FIP_ELS_ID_MASK);
  184. break;
  185. case ELS_CMD_LOGO:
  186. elsiocb->cmd_flag |=
  187. ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
  188. & LPFC_FIP_ELS_ID_MASK);
  189. break;
  190. }
  191. else
  192. elsiocb->cmd_flag &= ~LPFC_FIP_ELS_ID_MASK;
  193. /* fill in BDEs for command */
  194. /* Allocate buffer for command payload */
  195. pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL);
  196. if (pcmd)
  197. pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
  198. if (!pcmd || !pcmd->virt)
  199. goto els_iocb_free_pcmb_exit;
  200. INIT_LIST_HEAD(&pcmd->list);
  201. /* Allocate buffer for response payload */
  202. if (expect_rsp) {
  203. prsp = kmalloc(sizeof(*prsp), GFP_KERNEL);
  204. if (prsp)
  205. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  206. &prsp->phys);
  207. if (!prsp || !prsp->virt)
  208. goto els_iocb_free_prsp_exit;
  209. INIT_LIST_HEAD(&prsp->list);
  210. } else {
  211. prsp = NULL;
  212. }
  213. /* Allocate buffer for Buffer ptr list */
  214. pbuflist = kmalloc(sizeof(*pbuflist), GFP_KERNEL);
  215. if (pbuflist)
  216. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  217. &pbuflist->phys);
  218. if (!pbuflist || !pbuflist->virt)
  219. goto els_iocb_free_pbuf_exit;
  220. INIT_LIST_HEAD(&pbuflist->list);
  221. if (expect_rsp) {
  222. switch (elscmd) {
  223. case ELS_CMD_FLOGI:
  224. timeout = FF_DEF_RATOV * 2;
  225. break;
  226. case ELS_CMD_LOGO:
  227. timeout = phba->fc_ratov;
  228. break;
  229. default:
  230. timeout = phba->fc_ratov * 2;
  231. }
  232. /* Fill SGE for the num bde count */
  233. elsiocb->num_bdes = 2;
  234. }
  235. if (phba->sli_rev == LPFC_SLI_REV4)
  236. bmp = pcmd;
  237. else
  238. bmp = pbuflist;
  239. lpfc_sli_prep_els_req_rsp(phba, elsiocb, vport, bmp, cmd_size, did,
  240. elscmd, timeout, expect_rsp);
  241. bpl = (struct ulp_bde64_le *)pbuflist->virt;
  242. bpl->addr_low = cpu_to_le32(putPaddrLow(pcmd->phys));
  243. bpl->addr_high = cpu_to_le32(putPaddrHigh(pcmd->phys));
  244. bpl->type_size = cpu_to_le32(cmd_size);
  245. bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
  246. if (expect_rsp) {
  247. bpl++;
  248. bpl->addr_low = cpu_to_le32(putPaddrLow(prsp->phys));
  249. bpl->addr_high = cpu_to_le32(putPaddrHigh(prsp->phys));
  250. bpl->type_size = cpu_to_le32(FCELSSIZE);
  251. bpl->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
  252. }
  253. elsiocb->cmd_dmabuf = pcmd;
  254. elsiocb->bpl_dmabuf = pbuflist;
  255. elsiocb->retry = retry;
  256. elsiocb->vport = vport;
  257. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  258. if (prsp)
  259. list_add(&prsp->list, &pcmd->list);
  260. if (expect_rsp) {
  261. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  262. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  263. "0116 Xmit ELS command x%x to remote "
  264. "NPORT x%x I/O tag: x%x, port state:x%x "
  265. "rpi x%x fc_flag:x%x\n",
  266. elscmd, did, elsiocb->iotag,
  267. vport->port_state, ndlp->nlp_rpi,
  268. vport->fc_flag);
  269. } else {
  270. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  271. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  272. "0117 Xmit ELS response x%x to remote "
  273. "NPORT x%x I/O tag: x%x, size: x%x "
  274. "port_state x%x rpi x%x fc_flag x%x\n",
  275. elscmd, ndlp->nlp_DID, elsiocb->iotag,
  276. cmd_size, vport->port_state,
  277. ndlp->nlp_rpi, vport->fc_flag);
  278. }
  279. return elsiocb;
  280. els_iocb_free_pbuf_exit:
  281. if (expect_rsp)
  282. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  283. kfree(pbuflist);
  284. els_iocb_free_prsp_exit:
  285. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  286. kfree(prsp);
  287. els_iocb_free_pcmb_exit:
  288. kfree(pcmd);
  289. lpfc_sli_release_iocbq(phba, elsiocb);
  290. return NULL;
  291. }
  292. /**
  293. * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
  294. * @vport: pointer to a host virtual N_Port data structure.
  295. *
  296. * This routine issues a fabric registration login for a @vport. An
  297. * active ndlp node with Fabric_DID must already exist for this @vport.
  298. * The routine invokes two mailbox commands to carry out fabric registration
  299. * login through the HBA firmware: the first mailbox command requests the
  300. * HBA to perform link configuration for the @vport; and the second mailbox
  301. * command requests the HBA to perform the actual fabric registration login
  302. * with the @vport.
  303. *
  304. * Return code
  305. * 0 - successfully issued fabric registration login for @vport
  306. * -ENXIO -- failed to issue fabric registration login for @vport
  307. **/
  308. int
  309. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  310. {
  311. struct lpfc_hba *phba = vport->phba;
  312. LPFC_MBOXQ_t *mbox;
  313. struct lpfc_nodelist *ndlp;
  314. struct serv_parm *sp;
  315. int rc;
  316. int err = 0;
  317. sp = &phba->fc_fabparam;
  318. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  319. if (!ndlp) {
  320. err = 1;
  321. goto fail;
  322. }
  323. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  324. if (!mbox) {
  325. err = 2;
  326. goto fail;
  327. }
  328. vport->port_state = LPFC_FABRIC_CFG_LINK;
  329. lpfc_config_link(phba, mbox);
  330. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  331. mbox->vport = vport;
  332. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  333. if (rc == MBX_NOT_FINISHED) {
  334. err = 3;
  335. goto fail_free_mbox;
  336. }
  337. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  338. if (!mbox) {
  339. err = 4;
  340. goto fail;
  341. }
  342. rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  343. ndlp->nlp_rpi);
  344. if (rc) {
  345. err = 5;
  346. goto fail_free_mbox;
  347. }
  348. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  349. mbox->vport = vport;
  350. /* increment the reference count on ndlp to hold reference
  351. * for the callback routine.
  352. */
  353. mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
  354. if (!mbox->ctx_ndlp) {
  355. err = 6;
  356. goto fail_free_mbox;
  357. }
  358. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  359. if (rc == MBX_NOT_FINISHED) {
  360. err = 7;
  361. goto fail_issue_reg_login;
  362. }
  363. return 0;
  364. fail_issue_reg_login:
  365. /* decrement the reference count on ndlp just incremented
  366. * for the failed mbox command.
  367. */
  368. lpfc_nlp_put(ndlp);
  369. fail_free_mbox:
  370. lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
  371. fail:
  372. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  373. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  374. "0249 Cannot issue Register Fabric login: Err %d\n",
  375. err);
  376. return -ENXIO;
  377. }
  378. /**
  379. * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
  380. * @vport: pointer to a host virtual N_Port data structure.
  381. *
  382. * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
  383. * the @vport. This mailbox command is necessary for SLI4 port only.
  384. *
  385. * Return code
  386. * 0 - successfully issued REG_VFI for @vport
  387. * A failure code otherwise.
  388. **/
  389. int
  390. lpfc_issue_reg_vfi(struct lpfc_vport *vport)
  391. {
  392. struct lpfc_hba *phba = vport->phba;
  393. LPFC_MBOXQ_t *mboxq = NULL;
  394. struct lpfc_nodelist *ndlp;
  395. struct lpfc_dmabuf *dmabuf = NULL;
  396. int rc = 0;
  397. /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
  398. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  399. !(phba->link_flag & LS_LOOPBACK_MODE) &&
  400. !(vport->fc_flag & FC_PT2PT)) {
  401. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  402. if (!ndlp) {
  403. rc = -ENODEV;
  404. goto fail;
  405. }
  406. }
  407. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  408. if (!mboxq) {
  409. rc = -ENOMEM;
  410. goto fail;
  411. }
  412. /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
  413. if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
  414. rc = lpfc_mbox_rsrc_prep(phba, mboxq);
  415. if (rc) {
  416. rc = -ENOMEM;
  417. goto fail_mbox;
  418. }
  419. dmabuf = mboxq->ctx_buf;
  420. memcpy(dmabuf->virt, &phba->fc_fabparam,
  421. sizeof(struct serv_parm));
  422. }
  423. vport->port_state = LPFC_FABRIC_CFG_LINK;
  424. if (dmabuf) {
  425. lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
  426. /* lpfc_reg_vfi memsets the mailbox. Restore the ctx_buf. */
  427. mboxq->ctx_buf = dmabuf;
  428. } else {
  429. lpfc_reg_vfi(mboxq, vport, 0);
  430. }
  431. mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
  432. mboxq->vport = vport;
  433. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  434. if (rc == MBX_NOT_FINISHED) {
  435. rc = -ENXIO;
  436. goto fail_mbox;
  437. }
  438. return 0;
  439. fail_mbox:
  440. lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
  441. fail:
  442. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  443. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  444. "0289 Issue Register VFI failed: Err %d\n", rc);
  445. return rc;
  446. }
  447. /**
  448. * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
  449. * @vport: pointer to a host virtual N_Port data structure.
  450. *
  451. * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
  452. * the @vport. This mailbox command is necessary for SLI4 port only.
  453. *
  454. * Return code
  455. * 0 - successfully issued REG_VFI for @vport
  456. * A failure code otherwise.
  457. **/
  458. int
  459. lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
  460. {
  461. struct lpfc_hba *phba = vport->phba;
  462. struct Scsi_Host *shost;
  463. LPFC_MBOXQ_t *mboxq;
  464. int rc;
  465. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  466. if (!mboxq) {
  467. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  468. "2556 UNREG_VFI mbox allocation failed"
  469. "HBA state x%x\n", phba->pport->port_state);
  470. return -ENOMEM;
  471. }
  472. lpfc_unreg_vfi(mboxq, vport);
  473. mboxq->vport = vport;
  474. mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  475. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  476. if (rc == MBX_NOT_FINISHED) {
  477. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  478. "2557 UNREG_VFI issue mbox failed rc x%x "
  479. "HBA state x%x\n",
  480. rc, phba->pport->port_state);
  481. mempool_free(mboxq, phba->mbox_mem_pool);
  482. return -EIO;
  483. }
  484. shost = lpfc_shost_from_vport(vport);
  485. spin_lock_irq(shost->host_lock);
  486. vport->fc_flag &= ~FC_VFI_REGISTERED;
  487. spin_unlock_irq(shost->host_lock);
  488. return 0;
  489. }
  490. /**
  491. * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
  492. * @vport: pointer to a host virtual N_Port data structure.
  493. * @sp: pointer to service parameter data structure.
  494. *
  495. * This routine is called from FLOGI/FDISC completion handler functions.
  496. * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
  497. * node nodename is changed in the completion service parameter else return
  498. * 0. This function also set flag in the vport data structure to delay
  499. * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
  500. * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
  501. * node nodename is changed in the completion service parameter.
  502. *
  503. * Return code
  504. * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
  505. * 1 - FCID or Fabric Nodename or Fabric portname is changed.
  506. *
  507. **/
  508. static uint8_t
  509. lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
  510. struct serv_parm *sp)
  511. {
  512. struct lpfc_hba *phba = vport->phba;
  513. uint8_t fabric_param_changed = 0;
  514. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  515. if ((vport->fc_prevDID != vport->fc_myDID) ||
  516. memcmp(&vport->fabric_portname, &sp->portName,
  517. sizeof(struct lpfc_name)) ||
  518. memcmp(&vport->fabric_nodename, &sp->nodeName,
  519. sizeof(struct lpfc_name)) ||
  520. (vport->vport_flag & FAWWPN_PARAM_CHG)) {
  521. fabric_param_changed = 1;
  522. vport->vport_flag &= ~FAWWPN_PARAM_CHG;
  523. }
  524. /*
  525. * Word 1 Bit 31 in common service parameter is overloaded.
  526. * Word 1 Bit 31 in FLOGI request is multiple NPort request
  527. * Word 1 Bit 31 in FLOGI response is clean address bit
  528. *
  529. * If fabric parameter is changed and clean address bit is
  530. * cleared delay nport discovery if
  531. * - vport->fc_prevDID != 0 (not initial discovery) OR
  532. * - lpfc_delay_discovery module parameter is set.
  533. */
  534. if (fabric_param_changed && !sp->cmn.clean_address_bit &&
  535. (vport->fc_prevDID || phba->cfg_delay_discovery)) {
  536. spin_lock_irq(shost->host_lock);
  537. vport->fc_flag |= FC_DISC_DELAYED;
  538. spin_unlock_irq(shost->host_lock);
  539. }
  540. return fabric_param_changed;
  541. }
  542. /**
  543. * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
  544. * @vport: pointer to a host virtual N_Port data structure.
  545. * @ndlp: pointer to a node-list data structure.
  546. * @sp: pointer to service parameter data structure.
  547. * @ulp_word4: command response value
  548. *
  549. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  550. * function to handle the completion of a Fabric Login (FLOGI) into a fabric
  551. * port in a fabric topology. It properly sets up the parameters to the @ndlp
  552. * from the IOCB response. It also check the newly assigned N_Port ID to the
  553. * @vport against the previously assigned N_Port ID. If it is different from
  554. * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
  555. * is invoked on all the remaining nodes with the @vport to unregister the
  556. * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
  557. * is invoked to register login to the fabric.
  558. *
  559. * Return code
  560. * 0 - Success (currently, always return 0)
  561. **/
  562. static int
  563. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  564. struct serv_parm *sp, uint32_t ulp_word4)
  565. {
  566. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  567. struct lpfc_hba *phba = vport->phba;
  568. struct lpfc_nodelist *np;
  569. struct lpfc_nodelist *next_np;
  570. uint8_t fabric_param_changed;
  571. spin_lock_irq(shost->host_lock);
  572. vport->fc_flag |= FC_FABRIC;
  573. spin_unlock_irq(shost->host_lock);
  574. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  575. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  576. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  577. phba->fc_edtovResol = sp->cmn.edtovResolution;
  578. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  579. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  580. spin_lock_irq(shost->host_lock);
  581. vport->fc_flag |= FC_PUBLIC_LOOP;
  582. spin_unlock_irq(shost->host_lock);
  583. }
  584. vport->fc_myDID = ulp_word4 & Mask_DID;
  585. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  586. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  587. ndlp->nlp_class_sup = 0;
  588. if (sp->cls1.classValid)
  589. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  590. if (sp->cls2.classValid)
  591. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  592. if (sp->cls3.classValid)
  593. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  594. if (sp->cls4.classValid)
  595. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  596. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  597. sp->cmn.bbRcvSizeLsb;
  598. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  599. if (fabric_param_changed) {
  600. /* Reset FDMI attribute masks based on config parameter */
  601. if (phba->cfg_enable_SmartSAN ||
  602. (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
  603. /* Setup appropriate attribute masks */
  604. vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
  605. if (phba->cfg_enable_SmartSAN)
  606. vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
  607. else
  608. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  609. } else {
  610. vport->fdmi_hba_mask = 0;
  611. vport->fdmi_port_mask = 0;
  612. }
  613. }
  614. memcpy(&vport->fabric_portname, &sp->portName,
  615. sizeof(struct lpfc_name));
  616. memcpy(&vport->fabric_nodename, &sp->nodeName,
  617. sizeof(struct lpfc_name));
  618. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  619. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  620. if (sp->cmn.response_multiple_NPort) {
  621. lpfc_printf_vlog(vport, KERN_WARNING,
  622. LOG_ELS | LOG_VPORT,
  623. "1816 FLOGI NPIV supported, "
  624. "response data 0x%x\n",
  625. sp->cmn.response_multiple_NPort);
  626. spin_lock_irq(&phba->hbalock);
  627. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  628. spin_unlock_irq(&phba->hbalock);
  629. } else {
  630. /* Because we asked f/w for NPIV it still expects us
  631. to call reg_vnpid at least for the physical host */
  632. lpfc_printf_vlog(vport, KERN_WARNING,
  633. LOG_ELS | LOG_VPORT,
  634. "1817 Fabric does not support NPIV "
  635. "- configuring single port mode.\n");
  636. spin_lock_irq(&phba->hbalock);
  637. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  638. spin_unlock_irq(&phba->hbalock);
  639. }
  640. }
  641. /*
  642. * For FC we need to do some special processing because of the SLI
  643. * Port's default settings of the Common Service Parameters.
  644. */
  645. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  646. (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
  647. /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
  648. if (fabric_param_changed)
  649. lpfc_unregister_fcf_prep(phba);
  650. /* This should just update the VFI CSPs*/
  651. if (vport->fc_flag & FC_VFI_REGISTERED)
  652. lpfc_issue_reg_vfi(vport);
  653. }
  654. if (fabric_param_changed &&
  655. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  656. /* If our NportID changed, we need to ensure all
  657. * remaining NPORTs get unreg_login'ed.
  658. */
  659. list_for_each_entry_safe(np, next_np,
  660. &vport->fc_nodes, nlp_listp) {
  661. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  662. !(np->nlp_flag & NLP_NPR_ADISC))
  663. continue;
  664. spin_lock_irq(&np->lock);
  665. np->nlp_flag &= ~NLP_NPR_ADISC;
  666. spin_unlock_irq(&np->lock);
  667. lpfc_unreg_rpi(vport, np);
  668. }
  669. lpfc_cleanup_pending_mbox(vport);
  670. if (phba->sli_rev == LPFC_SLI_REV4) {
  671. lpfc_sli4_unreg_all_rpis(vport);
  672. lpfc_mbx_unreg_vpi(vport);
  673. spin_lock_irq(shost->host_lock);
  674. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  675. spin_unlock_irq(shost->host_lock);
  676. }
  677. /*
  678. * For SLI3 and SLI4, the VPI needs to be reregistered in
  679. * response to this fabric parameter change event.
  680. */
  681. spin_lock_irq(shost->host_lock);
  682. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  683. spin_unlock_irq(shost->host_lock);
  684. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  685. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  686. /*
  687. * Driver needs to re-reg VPI in order for f/w
  688. * to update the MAC address.
  689. */
  690. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  691. lpfc_register_new_vport(phba, vport, ndlp);
  692. return 0;
  693. }
  694. if (phba->sli_rev < LPFC_SLI_REV4) {
  695. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  696. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  697. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  698. lpfc_register_new_vport(phba, vport, ndlp);
  699. else
  700. lpfc_issue_fabric_reglogin(vport);
  701. } else {
  702. ndlp->nlp_type |= NLP_FABRIC;
  703. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  704. if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
  705. (vport->vpi_state & LPFC_VPI_REGISTERED)) {
  706. lpfc_start_fdiscs(phba);
  707. lpfc_do_scr_ns_plogi(phba, vport);
  708. } else if (vport->fc_flag & FC_VFI_REGISTERED)
  709. lpfc_issue_init_vpi(vport);
  710. else {
  711. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  712. "3135 Need register VFI: (x%x/%x)\n",
  713. vport->fc_prevDID, vport->fc_myDID);
  714. lpfc_issue_reg_vfi(vport);
  715. }
  716. }
  717. return 0;
  718. }
  719. /**
  720. * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
  721. * @vport: pointer to a host virtual N_Port data structure.
  722. * @ndlp: pointer to a node-list data structure.
  723. * @sp: pointer to service parameter data structure.
  724. *
  725. * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
  726. * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
  727. * in a point-to-point topology. First, the @vport's N_Port Name is compared
  728. * with the received N_Port Name: if the @vport's N_Port Name is greater than
  729. * the received N_Port Name lexicographically, this node shall assign local
  730. * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
  731. * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
  732. * this node shall just wait for the remote node to issue PLOGI and assign
  733. * N_Port IDs.
  734. *
  735. * Return code
  736. * 0 - Success
  737. * -ENXIO - Fail
  738. **/
  739. static int
  740. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  741. struct serv_parm *sp)
  742. {
  743. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  744. struct lpfc_hba *phba = vport->phba;
  745. LPFC_MBOXQ_t *mbox;
  746. int rc;
  747. spin_lock_irq(shost->host_lock);
  748. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  749. vport->fc_flag |= FC_PT2PT;
  750. spin_unlock_irq(shost->host_lock);
  751. /* If we are pt2pt with another NPort, force NPIV off! */
  752. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  753. /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
  754. if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
  755. lpfc_unregister_fcf_prep(phba);
  756. spin_lock_irq(shost->host_lock);
  757. vport->fc_flag &= ~FC_VFI_REGISTERED;
  758. spin_unlock_irq(shost->host_lock);
  759. phba->fc_topology_changed = 0;
  760. }
  761. rc = memcmp(&vport->fc_portname, &sp->portName,
  762. sizeof(vport->fc_portname));
  763. if (rc >= 0) {
  764. /* This side will initiate the PLOGI */
  765. spin_lock_irq(shost->host_lock);
  766. vport->fc_flag |= FC_PT2PT_PLOGI;
  767. spin_unlock_irq(shost->host_lock);
  768. /*
  769. * N_Port ID cannot be 0, set our Id to LocalID
  770. * the other side will be RemoteID.
  771. */
  772. /* not equal */
  773. if (rc)
  774. vport->fc_myDID = PT2PT_LocalID;
  775. /* If not registered with a transport, decrement ndlp reference
  776. * count indicating that ndlp can be safely released when other
  777. * references are removed.
  778. */
  779. if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
  780. lpfc_nlp_put(ndlp);
  781. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  782. if (!ndlp) {
  783. /*
  784. * Cannot find existing Fabric ndlp, so allocate a
  785. * new one
  786. */
  787. ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
  788. if (!ndlp)
  789. goto fail;
  790. }
  791. memcpy(&ndlp->nlp_portname, &sp->portName,
  792. sizeof(struct lpfc_name));
  793. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  794. sizeof(struct lpfc_name));
  795. /* Set state will put ndlp onto node list if not already done */
  796. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  797. spin_lock_irq(&ndlp->lock);
  798. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  799. spin_unlock_irq(&ndlp->lock);
  800. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  801. if (!mbox)
  802. goto fail;
  803. lpfc_config_link(phba, mbox);
  804. mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  805. mbox->vport = vport;
  806. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  807. if (rc == MBX_NOT_FINISHED) {
  808. mempool_free(mbox, phba->mbox_mem_pool);
  809. goto fail;
  810. }
  811. } else {
  812. /* This side will wait for the PLOGI. If not registered with
  813. * a transport, decrement node reference count indicating that
  814. * ndlp can be released when other references are removed.
  815. */
  816. if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)))
  817. lpfc_nlp_put(ndlp);
  818. /* Start discovery - this should just do CLEAR_LA */
  819. lpfc_disc_start(vport);
  820. }
  821. return 0;
  822. fail:
  823. return -ENXIO;
  824. }
  825. /**
  826. * lpfc_cmpl_els_flogi - Completion callback function for flogi
  827. * @phba: pointer to lpfc hba data structure.
  828. * @cmdiocb: pointer to lpfc command iocb data structure.
  829. * @rspiocb: pointer to lpfc response iocb data structure.
  830. *
  831. * This routine is the top-level completion callback function for issuing
  832. * a Fabric Login (FLOGI) command. If the response IOCB reported error,
  833. * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
  834. * retry has been made (either immediately or delayed with lpfc_els_retry()
  835. * returning 1), the command IOCB will be released and function returned.
  836. * If the retry attempt has been given up (possibly reach the maximum
  837. * number of retries), one additional decrement of ndlp reference shall be
  838. * invoked before going out after releasing the command IOCB. This will
  839. * actually release the remote node (Note, lpfc_els_free_iocb() will also
  840. * invoke one decrement of ndlp reference count). If no error reported in
  841. * the IOCB status, the command Port ID field is used to determine whether
  842. * this is a point-to-point topology or a fabric topology: if the Port ID
  843. * field is assigned, it is a fabric topology; otherwise, it is a
  844. * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
  845. * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
  846. * specific topology completion conditions.
  847. **/
  848. static void
  849. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  850. struct lpfc_iocbq *rspiocb)
  851. {
  852. struct lpfc_vport *vport = cmdiocb->vport;
  853. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  854. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  855. IOCB_t *irsp;
  856. struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp;
  857. struct serv_parm *sp;
  858. uint16_t fcf_index;
  859. int rc;
  860. u32 ulp_status, ulp_word4, tmo;
  861. /* Check to see if link went down during discovery */
  862. if (lpfc_els_chk_latt(vport)) {
  863. /* One additional decrement on node reference count to
  864. * trigger the release of the node
  865. */
  866. if (!(ndlp->fc4_xpt_flags & SCSI_XPT_REGD))
  867. lpfc_nlp_put(ndlp);
  868. goto out;
  869. }
  870. ulp_status = get_job_ulpstatus(phba, rspiocb);
  871. ulp_word4 = get_job_word4(phba, rspiocb);
  872. if (phba->sli_rev == LPFC_SLI_REV4) {
  873. tmo = get_wqe_tmo(cmdiocb);
  874. } else {
  875. irsp = &rspiocb->iocb;
  876. tmo = irsp->ulpTimeout;
  877. }
  878. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  879. "FLOGI cmpl: status:x%x/x%x state:x%x",
  880. ulp_status, ulp_word4,
  881. vport->port_state);
  882. if (ulp_status) {
  883. /*
  884. * In case of FIP mode, perform roundrobin FCF failover
  885. * due to new FCF discovery
  886. */
  887. if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
  888. (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
  889. if (phba->link_state < LPFC_LINK_UP)
  890. goto stop_rr_fcf_flogi;
  891. if ((phba->fcoe_cvl_eventtag_attn ==
  892. phba->fcoe_cvl_eventtag) &&
  893. (ulp_status == IOSTAT_LOCAL_REJECT) &&
  894. ((ulp_word4 & IOERR_PARAM_MASK) ==
  895. IOERR_SLI_ABORTED))
  896. goto stop_rr_fcf_flogi;
  897. else
  898. phba->fcoe_cvl_eventtag_attn =
  899. phba->fcoe_cvl_eventtag;
  900. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
  901. "2611 FLOGI failed on FCF (x%x), "
  902. "status:x%x/x%x, tmo:x%x, perform "
  903. "roundrobin FCF failover\n",
  904. phba->fcf.current_rec.fcf_indx,
  905. ulp_status, ulp_word4, tmo);
  906. lpfc_sli4_set_fcf_flogi_fail(phba,
  907. phba->fcf.current_rec.fcf_indx);
  908. fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
  909. rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
  910. if (rc)
  911. goto out;
  912. }
  913. stop_rr_fcf_flogi:
  914. /* FLOGI failure */
  915. if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
  916. ((ulp_word4 & IOERR_PARAM_MASK) ==
  917. IOERR_LOOP_OPEN_FAILURE)))
  918. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  919. "2858 FLOGI failure Status:x%x/x%x TMO"
  920. ":x%x Data x%x x%x\n",
  921. ulp_status, ulp_word4, tmo,
  922. phba->hba_flag, phba->fcf.fcf_flag);
  923. /* Check for retry */
  924. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  925. goto out;
  926. lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
  927. "0150 FLOGI failure Status:x%x/x%x "
  928. "xri x%x TMO:x%x refcnt %d\n",
  929. ulp_status, ulp_word4, cmdiocb->sli4_xritag,
  930. tmo, kref_read(&ndlp->kref));
  931. /* If this is not a loop open failure, bail out */
  932. if (!(ulp_status == IOSTAT_LOCAL_REJECT &&
  933. ((ulp_word4 & IOERR_PARAM_MASK) ==
  934. IOERR_LOOP_OPEN_FAILURE))) {
  935. /* FLOGI failure */
  936. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  937. "0100 FLOGI failure Status:x%x/x%x "
  938. "TMO:x%x\n",
  939. ulp_status, ulp_word4, tmo);
  940. goto flogifail;
  941. }
  942. /* FLOGI failed, so there is no fabric */
  943. spin_lock_irq(shost->host_lock);
  944. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP |
  945. FC_PT2PT_NO_NVME);
  946. spin_unlock_irq(shost->host_lock);
  947. /* If private loop, then allow max outstanding els to be
  948. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  949. * alpa map would take too long otherwise.
  950. */
  951. if (phba->alpa_map[0] == 0)
  952. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  953. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  954. (!(vport->fc_flag & FC_VFI_REGISTERED) ||
  955. (vport->fc_prevDID != vport->fc_myDID) ||
  956. phba->fc_topology_changed)) {
  957. if (vport->fc_flag & FC_VFI_REGISTERED) {
  958. if (phba->fc_topology_changed) {
  959. lpfc_unregister_fcf_prep(phba);
  960. spin_lock_irq(shost->host_lock);
  961. vport->fc_flag &= ~FC_VFI_REGISTERED;
  962. spin_unlock_irq(shost->host_lock);
  963. phba->fc_topology_changed = 0;
  964. } else {
  965. lpfc_sli4_unreg_all_rpis(vport);
  966. }
  967. }
  968. /* Do not register VFI if the driver aborted FLOGI */
  969. if (!lpfc_error_lost_link(ulp_status, ulp_word4))
  970. lpfc_issue_reg_vfi(vport);
  971. lpfc_nlp_put(ndlp);
  972. goto out;
  973. }
  974. goto flogifail;
  975. }
  976. spin_lock_irq(shost->host_lock);
  977. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  978. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  979. spin_unlock_irq(shost->host_lock);
  980. /*
  981. * The FLogI succeeded. Sync the data for the CPU before
  982. * accessing it.
  983. */
  984. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  985. if (!prsp)
  986. goto out;
  987. sp = prsp->virt + sizeof(uint32_t);
  988. /* FLOGI completes successfully */
  989. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  990. "0101 FLOGI completes successfully, I/O tag:x%x "
  991. "xri x%x Data: x%x x%x x%x x%x x%x x%x x%x %d\n",
  992. cmdiocb->iotag, cmdiocb->sli4_xritag,
  993. ulp_word4, sp->cmn.e_d_tov,
  994. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
  995. vport->port_state, vport->fc_flag,
  996. sp->cmn.priority_tagging, kref_read(&ndlp->kref));
  997. if (sp->cmn.priority_tagging)
  998. vport->phba->pport->vmid_flag |= (LPFC_VMID_ISSUE_QFPA |
  999. LPFC_VMID_TYPE_PRIO);
  1000. if (vport->port_state == LPFC_FLOGI) {
  1001. /*
  1002. * If Common Service Parameters indicate Nport
  1003. * we are point to point, if Fport we are Fabric.
  1004. */
  1005. if (sp->cmn.fPort)
  1006. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp,
  1007. ulp_word4);
  1008. else if (!(phba->hba_flag & HBA_FCOE_MODE))
  1009. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  1010. else {
  1011. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1012. "2831 FLOGI response with cleared Fabric "
  1013. "bit fcf_index 0x%x "
  1014. "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
  1015. "Fabric Name "
  1016. "%02x%02x%02x%02x%02x%02x%02x%02x\n",
  1017. phba->fcf.current_rec.fcf_indx,
  1018. phba->fcf.current_rec.switch_name[0],
  1019. phba->fcf.current_rec.switch_name[1],
  1020. phba->fcf.current_rec.switch_name[2],
  1021. phba->fcf.current_rec.switch_name[3],
  1022. phba->fcf.current_rec.switch_name[4],
  1023. phba->fcf.current_rec.switch_name[5],
  1024. phba->fcf.current_rec.switch_name[6],
  1025. phba->fcf.current_rec.switch_name[7],
  1026. phba->fcf.current_rec.fabric_name[0],
  1027. phba->fcf.current_rec.fabric_name[1],
  1028. phba->fcf.current_rec.fabric_name[2],
  1029. phba->fcf.current_rec.fabric_name[3],
  1030. phba->fcf.current_rec.fabric_name[4],
  1031. phba->fcf.current_rec.fabric_name[5],
  1032. phba->fcf.current_rec.fabric_name[6],
  1033. phba->fcf.current_rec.fabric_name[7]);
  1034. lpfc_nlp_put(ndlp);
  1035. spin_lock_irq(&phba->hbalock);
  1036. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  1037. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  1038. spin_unlock_irq(&phba->hbalock);
  1039. phba->fcf.fcf_redisc_attempted = 0; /* reset */
  1040. goto out;
  1041. }
  1042. if (!rc) {
  1043. /* Mark the FCF discovery process done */
  1044. if (phba->hba_flag & HBA_FIP_SUPPORT)
  1045. lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
  1046. LOG_ELS,
  1047. "2769 FLOGI to FCF (x%x) "
  1048. "completed successfully\n",
  1049. phba->fcf.current_rec.fcf_indx);
  1050. spin_lock_irq(&phba->hbalock);
  1051. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  1052. phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
  1053. spin_unlock_irq(&phba->hbalock);
  1054. phba->fcf.fcf_redisc_attempted = 0; /* reset */
  1055. goto out;
  1056. }
  1057. } else if (vport->port_state > LPFC_FLOGI &&
  1058. vport->fc_flag & FC_PT2PT) {
  1059. /*
  1060. * In a p2p topology, it is possible that discovery has
  1061. * already progressed, and this completion can be ignored.
  1062. * Recheck the indicated topology.
  1063. */
  1064. if (!sp->cmn.fPort)
  1065. goto out;
  1066. }
  1067. flogifail:
  1068. spin_lock_irq(&phba->hbalock);
  1069. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  1070. spin_unlock_irq(&phba->hbalock);
  1071. if (!lpfc_error_lost_link(ulp_status, ulp_word4)) {
  1072. /* FLOGI failed, so just use loop map to make discovery list */
  1073. lpfc_disc_list_loopmap(vport);
  1074. /* Start discovery */
  1075. lpfc_disc_start(vport);
  1076. } else if (((ulp_status != IOSTAT_LOCAL_REJECT) ||
  1077. (((ulp_word4 & IOERR_PARAM_MASK) !=
  1078. IOERR_SLI_ABORTED) &&
  1079. ((ulp_word4 & IOERR_PARAM_MASK) !=
  1080. IOERR_SLI_DOWN))) &&
  1081. (phba->link_state != LPFC_CLEAR_LA)) {
  1082. /* If FLOGI failed enable link interrupt. */
  1083. lpfc_issue_clear_la(phba, vport);
  1084. }
  1085. out:
  1086. phba->hba_flag &= ~HBA_FLOGI_OUTSTANDING;
  1087. lpfc_els_free_iocb(phba, cmdiocb);
  1088. lpfc_nlp_put(ndlp);
  1089. }
  1090. /**
  1091. * lpfc_cmpl_els_link_down - Completion callback function for ELS command
  1092. * aborted during a link down
  1093. * @phba: pointer to lpfc hba data structure.
  1094. * @cmdiocb: pointer to lpfc command iocb data structure.
  1095. * @rspiocb: pointer to lpfc response iocb data structure.
  1096. *
  1097. */
  1098. static void
  1099. lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1100. struct lpfc_iocbq *rspiocb)
  1101. {
  1102. uint32_t *pcmd;
  1103. uint32_t cmd;
  1104. u32 ulp_status, ulp_word4;
  1105. pcmd = (uint32_t *)cmdiocb->cmd_dmabuf->virt;
  1106. cmd = *pcmd;
  1107. ulp_status = get_job_ulpstatus(phba, rspiocb);
  1108. ulp_word4 = get_job_word4(phba, rspiocb);
  1109. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1110. "6445 ELS completes after LINK_DOWN: "
  1111. " Status %x/%x cmd x%x flg x%x\n",
  1112. ulp_status, ulp_word4, cmd,
  1113. cmdiocb->cmd_flag);
  1114. if (cmdiocb->cmd_flag & LPFC_IO_FABRIC) {
  1115. cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
  1116. atomic_dec(&phba->fabric_iocb_count);
  1117. }
  1118. lpfc_els_free_iocb(phba, cmdiocb);
  1119. }
  1120. /**
  1121. * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
  1122. * @vport: pointer to a host virtual N_Port data structure.
  1123. * @ndlp: pointer to a node-list data structure.
  1124. * @retry: number of retries to the command IOCB.
  1125. *
  1126. * This routine issues a Fabric Login (FLOGI) Request ELS command
  1127. * for a @vport. The initiator service parameters are put into the payload
  1128. * of the FLOGI Request IOCB and the top-level callback function pointer
  1129. * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
  1130. * function field. The lpfc_issue_fabric_iocb routine is invoked to send
  1131. * out FLOGI ELS command with one outstanding fabric IOCB at a time.
  1132. *
  1133. * Note that the ndlp reference count will be incremented by 1 for holding the
  1134. * ndlp and the reference to ndlp will be stored into the ndlp field of
  1135. * the IOCB for the completion callback function to the FLOGI ELS command.
  1136. *
  1137. * Return code
  1138. * 0 - successfully issued flogi iocb for @vport
  1139. * 1 - failed to issue flogi iocb for @vport
  1140. **/
  1141. static int
  1142. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1143. uint8_t retry)
  1144. {
  1145. struct lpfc_hba *phba = vport->phba;
  1146. struct serv_parm *sp;
  1147. union lpfc_wqe128 *wqe = NULL;
  1148. IOCB_t *icmd = NULL;
  1149. struct lpfc_iocbq *elsiocb;
  1150. struct lpfc_iocbq defer_flogi_acc;
  1151. u8 *pcmd, ct;
  1152. uint16_t cmdsize;
  1153. uint32_t tmo, did;
  1154. int rc;
  1155. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1156. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1157. ndlp->nlp_DID, ELS_CMD_FLOGI);
  1158. if (!elsiocb)
  1159. return 1;
  1160. wqe = &elsiocb->wqe;
  1161. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  1162. icmd = &elsiocb->iocb;
  1163. /* For FLOGI request, remainder of payload is service parameters */
  1164. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  1165. pcmd += sizeof(uint32_t);
  1166. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1167. sp = (struct serv_parm *) pcmd;
  1168. /* Setup CSPs accordingly for Fabric */
  1169. sp->cmn.e_d_tov = 0;
  1170. sp->cmn.w2.r_a_tov = 0;
  1171. sp->cmn.virtual_fabric_support = 0;
  1172. sp->cls1.classValid = 0;
  1173. if (sp->cmn.fcphLow < FC_PH3)
  1174. sp->cmn.fcphLow = FC_PH3;
  1175. if (sp->cmn.fcphHigh < FC_PH3)
  1176. sp->cmn.fcphHigh = FC_PH3;
  1177. /* Determine if switch supports priority tagging */
  1178. if (phba->cfg_vmid_priority_tagging) {
  1179. sp->cmn.priority_tagging = 1;
  1180. /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */
  1181. if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid)) {
  1182. memcpy(vport->lpfc_vmid_host_uuid, phba->wwpn,
  1183. sizeof(phba->wwpn));
  1184. memcpy(&vport->lpfc_vmid_host_uuid[8], phba->wwnn,
  1185. sizeof(phba->wwnn));
  1186. }
  1187. }
  1188. if (phba->sli_rev == LPFC_SLI_REV4) {
  1189. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  1190. LPFC_SLI_INTF_IF_TYPE_0) {
  1191. /* FLOGI needs to be 3 for WQE FCFI */
  1192. ct = SLI4_CT_FCFI;
  1193. bf_set(wqe_ct, &wqe->els_req.wqe_com, ct);
  1194. /* Set the fcfi to the fcfi we registered with */
  1195. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  1196. phba->fcf.fcfi);
  1197. }
  1198. /* Can't do SLI4 class2 without support sequence coalescing */
  1199. sp->cls2.classValid = 0;
  1200. sp->cls2.seqDelivery = 0;
  1201. } else {
  1202. /* Historical, setting sequential-delivery bit for SLI3 */
  1203. sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
  1204. sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
  1205. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  1206. sp->cmn.request_multiple_Nport = 1;
  1207. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  1208. icmd->ulpCt_h = 1;
  1209. icmd->ulpCt_l = 0;
  1210. } else {
  1211. sp->cmn.request_multiple_Nport = 0;
  1212. }
  1213. if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
  1214. icmd->un.elsreq64.myID = 0;
  1215. icmd->un.elsreq64.fl = 1;
  1216. }
  1217. }
  1218. tmo = phba->fc_ratov;
  1219. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  1220. lpfc_set_disctmo(vport);
  1221. phba->fc_ratov = tmo;
  1222. phba->fc_stat.elsXmitFLOGI++;
  1223. elsiocb->cmd_cmpl = lpfc_cmpl_els_flogi;
  1224. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1225. "Issue FLOGI: opt:x%x",
  1226. phba->sli3_options, 0, 0);
  1227. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  1228. if (!elsiocb->ndlp) {
  1229. lpfc_els_free_iocb(phba, elsiocb);
  1230. return 1;
  1231. }
  1232. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  1233. if (rc == IOCB_ERROR) {
  1234. lpfc_els_free_iocb(phba, elsiocb);
  1235. lpfc_nlp_put(ndlp);
  1236. return 1;
  1237. }
  1238. phba->hba_flag |= (HBA_FLOGI_ISSUED | HBA_FLOGI_OUTSTANDING);
  1239. /* Clear external loopback plug detected flag */
  1240. phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
  1241. /* Check for a deferred FLOGI ACC condition */
  1242. if (phba->defer_flogi_acc_flag) {
  1243. /* lookup ndlp for received FLOGI */
  1244. ndlp = lpfc_findnode_did(vport, 0);
  1245. if (!ndlp)
  1246. return 0;
  1247. did = vport->fc_myDID;
  1248. vport->fc_myDID = Fabric_DID;
  1249. memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
  1250. if (phba->sli_rev == LPFC_SLI_REV4) {
  1251. bf_set(wqe_ctxt_tag,
  1252. &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
  1253. phba->defer_flogi_acc_rx_id);
  1254. bf_set(wqe_rcvoxid,
  1255. &defer_flogi_acc.wqe.xmit_els_rsp.wqe_com,
  1256. phba->defer_flogi_acc_ox_id);
  1257. } else {
  1258. icmd = &defer_flogi_acc.iocb;
  1259. icmd->ulpContext = phba->defer_flogi_acc_rx_id;
  1260. icmd->unsli3.rcvsli3.ox_id =
  1261. phba->defer_flogi_acc_ox_id;
  1262. }
  1263. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1264. "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
  1265. " ox_id: x%x, hba_flag x%x\n",
  1266. phba->defer_flogi_acc_rx_id,
  1267. phba->defer_flogi_acc_ox_id, phba->hba_flag);
  1268. /* Send deferred FLOGI ACC */
  1269. lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
  1270. ndlp, NULL);
  1271. phba->defer_flogi_acc_flag = false;
  1272. vport->fc_myDID = did;
  1273. /* Decrement ndlp reference count to indicate the node can be
  1274. * released when other references are removed.
  1275. */
  1276. lpfc_nlp_put(ndlp);
  1277. }
  1278. return 0;
  1279. }
  1280. /**
  1281. * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
  1282. * @phba: pointer to lpfc hba data structure.
  1283. *
  1284. * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
  1285. * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
  1286. * list and issues an abort IOCB commond on each outstanding IOCB that
  1287. * contains a active Fabric_DID ndlp. Note that this function is to issue
  1288. * the abort IOCB command on all the outstanding IOCBs, thus when this
  1289. * function returns, it does not guarantee all the IOCBs are actually aborted.
  1290. *
  1291. * Return code
  1292. * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
  1293. **/
  1294. int
  1295. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  1296. {
  1297. struct lpfc_sli_ring *pring;
  1298. struct lpfc_iocbq *iocb, *next_iocb;
  1299. struct lpfc_nodelist *ndlp;
  1300. u32 ulp_command;
  1301. /* Abort outstanding I/O on NPort <nlp_DID> */
  1302. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1303. "0201 Abort outstanding I/O on NPort x%x\n",
  1304. Fabric_DID);
  1305. pring = lpfc_phba_elsring(phba);
  1306. if (unlikely(!pring))
  1307. return -EIO;
  1308. /*
  1309. * Check the txcmplq for an iocb that matches the nport the driver is
  1310. * searching for.
  1311. */
  1312. spin_lock_irq(&phba->hbalock);
  1313. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  1314. ulp_command = get_job_cmnd(phba, iocb);
  1315. if (ulp_command == CMD_ELS_REQUEST64_CR) {
  1316. ndlp = iocb->ndlp;
  1317. if (ndlp && ndlp->nlp_DID == Fabric_DID) {
  1318. if ((phba->pport->fc_flag & FC_PT2PT) &&
  1319. !(phba->pport->fc_flag & FC_PT2PT_PLOGI))
  1320. iocb->fabric_cmd_cmpl =
  1321. lpfc_ignore_els_cmpl;
  1322. lpfc_sli_issue_abort_iotag(phba, pring, iocb,
  1323. NULL);
  1324. }
  1325. }
  1326. }
  1327. /* Make sure HBA is alive */
  1328. lpfc_issue_hb_tmo(phba);
  1329. spin_unlock_irq(&phba->hbalock);
  1330. return 0;
  1331. }
  1332. /**
  1333. * lpfc_initial_flogi - Issue an initial fabric login for a vport
  1334. * @vport: pointer to a host virtual N_Port data structure.
  1335. *
  1336. * This routine issues an initial Fabric Login (FLOGI) for the @vport
  1337. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1338. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1339. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1340. * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
  1341. * is then invoked with the @vport and the ndlp to perform the FLOGI for the
  1342. * @vport.
  1343. *
  1344. * Return code
  1345. * 0 - failed to issue initial flogi for @vport
  1346. * 1 - successfully issued initial flogi for @vport
  1347. **/
  1348. int
  1349. lpfc_initial_flogi(struct lpfc_vport *vport)
  1350. {
  1351. struct lpfc_nodelist *ndlp;
  1352. vport->port_state = LPFC_FLOGI;
  1353. lpfc_set_disctmo(vport);
  1354. /* First look for the Fabric ndlp */
  1355. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1356. if (!ndlp) {
  1357. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1358. ndlp = lpfc_nlp_init(vport, Fabric_DID);
  1359. if (!ndlp)
  1360. return 0;
  1361. /* Set the node type */
  1362. ndlp->nlp_type |= NLP_FABRIC;
  1363. /* Put ndlp onto node list */
  1364. lpfc_enqueue_node(vport, ndlp);
  1365. }
  1366. /* Reset the Fabric flag, topology change may have happened */
  1367. vport->fc_flag &= ~FC_FABRIC;
  1368. if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
  1369. /* A node reference should be retained while registered with a
  1370. * transport or dev-loss-evt work is pending.
  1371. * Otherwise, decrement node reference to trigger release.
  1372. */
  1373. if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
  1374. !(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
  1375. lpfc_nlp_put(ndlp);
  1376. return 0;
  1377. }
  1378. return 1;
  1379. }
  1380. /**
  1381. * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
  1382. * @vport: pointer to a host virtual N_Port data structure.
  1383. *
  1384. * This routine issues an initial Fabric Discover (FDISC) for the @vport
  1385. * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
  1386. * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
  1387. * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
  1388. * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
  1389. * is then invoked with the @vport and the ndlp to perform the FDISC for the
  1390. * @vport.
  1391. *
  1392. * Return code
  1393. * 0 - failed to issue initial fdisc for @vport
  1394. * 1 - successfully issued initial fdisc for @vport
  1395. **/
  1396. int
  1397. lpfc_initial_fdisc(struct lpfc_vport *vport)
  1398. {
  1399. struct lpfc_nodelist *ndlp;
  1400. /* First look for the Fabric ndlp */
  1401. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  1402. if (!ndlp) {
  1403. /* Cannot find existing Fabric ndlp, so allocate a new one */
  1404. ndlp = lpfc_nlp_init(vport, Fabric_DID);
  1405. if (!ndlp)
  1406. return 0;
  1407. /* NPIV is only supported in Fabrics. */
  1408. ndlp->nlp_type |= NLP_FABRIC;
  1409. /* Put ndlp onto node list */
  1410. lpfc_enqueue_node(vport, ndlp);
  1411. }
  1412. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  1413. /* A node reference should be retained while registered with a
  1414. * transport or dev-loss-evt work is pending.
  1415. * Otherwise, decrement node reference to trigger release.
  1416. */
  1417. if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
  1418. !(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
  1419. lpfc_nlp_put(ndlp);
  1420. return 0;
  1421. }
  1422. return 1;
  1423. }
  1424. /**
  1425. * lpfc_more_plogi - Check and issue remaining plogis for a vport
  1426. * @vport: pointer to a host virtual N_Port data structure.
  1427. *
  1428. * This routine checks whether there are more remaining Port Logins
  1429. * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
  1430. * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
  1431. * to issue ELS PLOGIs up to the configured discover threads with the
  1432. * @vport (@vport->cfg_discovery_threads). The function also decrement
  1433. * the @vport's num_disc_node by 1 if it is not already 0.
  1434. **/
  1435. void
  1436. lpfc_more_plogi(struct lpfc_vport *vport)
  1437. {
  1438. if (vport->num_disc_nodes)
  1439. vport->num_disc_nodes--;
  1440. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  1441. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1442. "0232 Continue discovery with %d PLOGIs to go "
  1443. "Data: x%x x%x x%x\n",
  1444. vport->num_disc_nodes, vport->fc_plogi_cnt,
  1445. vport->fc_flag, vport->port_state);
  1446. /* Check to see if there are more PLOGIs to be sent */
  1447. if (vport->fc_flag & FC_NLP_MORE)
  1448. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  1449. lpfc_els_disc_plogi(vport);
  1450. return;
  1451. }
  1452. /**
  1453. * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
  1454. * @phba: pointer to lpfc hba data structure.
  1455. * @prsp: pointer to response IOCB payload.
  1456. * @ndlp: pointer to a node-list data structure.
  1457. *
  1458. * This routine checks and indicates whether the WWPN of an N_Port, retrieved
  1459. * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
  1460. * The following cases are considered N_Port confirmed:
  1461. * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
  1462. * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
  1463. * it does not have WWPN assigned either. If the WWPN is confirmed, the
  1464. * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
  1465. * 1) if there is a node on vport list other than the @ndlp with the same
  1466. * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
  1467. * on that node to release the RPI associated with the node; 2) if there is
  1468. * no node found on vport list with the same WWPN of the N_Port PLOGI logged
  1469. * into, a new node shall be allocated (or activated). In either case, the
  1470. * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
  1471. * be released and the new_ndlp shall be put on to the vport node list and
  1472. * its pointer returned as the confirmed node.
  1473. *
  1474. * Note that before the @ndlp got "released", the keepDID from not-matching
  1475. * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
  1476. * of the @ndlp. This is because the release of @ndlp is actually to put it
  1477. * into an inactive state on the vport node list and the vport node list
  1478. * management algorithm does not allow two node with a same DID.
  1479. *
  1480. * Return code
  1481. * pointer to the PLOGI N_Port @ndlp
  1482. **/
  1483. static struct lpfc_nodelist *
  1484. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  1485. struct lpfc_nodelist *ndlp)
  1486. {
  1487. struct lpfc_vport *vport = ndlp->vport;
  1488. struct lpfc_nodelist *new_ndlp;
  1489. struct serv_parm *sp;
  1490. uint8_t name[sizeof(struct lpfc_name)];
  1491. uint32_t keepDID = 0, keep_nlp_flag = 0;
  1492. uint32_t keep_new_nlp_flag = 0;
  1493. uint16_t keep_nlp_state;
  1494. u32 keep_nlp_fc4_type = 0;
  1495. struct lpfc_nvme_rport *keep_nrport = NULL;
  1496. unsigned long *active_rrqs_xri_bitmap = NULL;
  1497. /* Fabric nodes can have the same WWPN so we don't bother searching
  1498. * by WWPN. Just return the ndlp that was given to us.
  1499. */
  1500. if (ndlp->nlp_type & NLP_FABRIC)
  1501. return ndlp;
  1502. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  1503. memset(name, 0, sizeof(struct lpfc_name));
  1504. /* Now we find out if the NPort we are logging into, matches the WWPN
  1505. * we have for that ndlp. If not, we have some work to do.
  1506. */
  1507. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  1508. /* return immediately if the WWPN matches ndlp */
  1509. if (!new_ndlp || (new_ndlp == ndlp))
  1510. return ndlp;
  1511. /*
  1512. * Unregister from backend if not done yet. Could have been skipped
  1513. * due to ADISC
  1514. */
  1515. lpfc_nlp_unreg_node(vport, new_ndlp);
  1516. if (phba->sli_rev == LPFC_SLI_REV4) {
  1517. active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
  1518. GFP_KERNEL);
  1519. if (active_rrqs_xri_bitmap)
  1520. memset(active_rrqs_xri_bitmap, 0,
  1521. phba->cfg_rrq_xri_bitmap_sz);
  1522. }
  1523. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
  1524. "3178 PLOGI confirm: ndlp x%x x%x x%x: "
  1525. "new_ndlp x%x x%x x%x\n",
  1526. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
  1527. (new_ndlp ? new_ndlp->nlp_DID : 0),
  1528. (new_ndlp ? new_ndlp->nlp_flag : 0),
  1529. (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
  1530. keepDID = new_ndlp->nlp_DID;
  1531. if (phba->sli_rev == LPFC_SLI_REV4 && active_rrqs_xri_bitmap)
  1532. memcpy(active_rrqs_xri_bitmap, new_ndlp->active_rrqs_xri_bitmap,
  1533. phba->cfg_rrq_xri_bitmap_sz);
  1534. /* At this point in this routine, we know new_ndlp will be
  1535. * returned. however, any previous GID_FTs that were done
  1536. * would have updated nlp_fc4_type in ndlp, so we must ensure
  1537. * new_ndlp has the right value.
  1538. */
  1539. if (vport->fc_flag & FC_FABRIC) {
  1540. keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
  1541. new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
  1542. }
  1543. lpfc_unreg_rpi(vport, new_ndlp);
  1544. new_ndlp->nlp_DID = ndlp->nlp_DID;
  1545. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  1546. if (phba->sli_rev == LPFC_SLI_REV4)
  1547. memcpy(new_ndlp->active_rrqs_xri_bitmap,
  1548. ndlp->active_rrqs_xri_bitmap,
  1549. phba->cfg_rrq_xri_bitmap_sz);
  1550. /* Lock both ndlps */
  1551. spin_lock_irq(&ndlp->lock);
  1552. spin_lock_irq(&new_ndlp->lock);
  1553. keep_new_nlp_flag = new_ndlp->nlp_flag;
  1554. keep_nlp_flag = ndlp->nlp_flag;
  1555. new_ndlp->nlp_flag = ndlp->nlp_flag;
  1556. /* if new_ndlp had NLP_UNREG_INP set, keep it */
  1557. if (keep_new_nlp_flag & NLP_UNREG_INP)
  1558. new_ndlp->nlp_flag |= NLP_UNREG_INP;
  1559. else
  1560. new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
  1561. /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
  1562. if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
  1563. new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  1564. else
  1565. new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
  1566. /*
  1567. * Retain the DROPPED flag. This will take care of the init
  1568. * refcount when affecting the state change
  1569. */
  1570. if (keep_new_nlp_flag & NLP_DROPPED)
  1571. new_ndlp->nlp_flag |= NLP_DROPPED;
  1572. else
  1573. new_ndlp->nlp_flag &= ~NLP_DROPPED;
  1574. ndlp->nlp_flag = keep_new_nlp_flag;
  1575. /* if ndlp had NLP_UNREG_INP set, keep it */
  1576. if (keep_nlp_flag & NLP_UNREG_INP)
  1577. ndlp->nlp_flag |= NLP_UNREG_INP;
  1578. else
  1579. ndlp->nlp_flag &= ~NLP_UNREG_INP;
  1580. /* if ndlp had NLP_RPI_REGISTERED set, keep it */
  1581. if (keep_nlp_flag & NLP_RPI_REGISTERED)
  1582. ndlp->nlp_flag |= NLP_RPI_REGISTERED;
  1583. else
  1584. ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
  1585. /*
  1586. * Retain the DROPPED flag. This will take care of the init
  1587. * refcount when affecting the state change
  1588. */
  1589. if (keep_nlp_flag & NLP_DROPPED)
  1590. ndlp->nlp_flag |= NLP_DROPPED;
  1591. else
  1592. ndlp->nlp_flag &= ~NLP_DROPPED;
  1593. spin_unlock_irq(&new_ndlp->lock);
  1594. spin_unlock_irq(&ndlp->lock);
  1595. /* Set nlp_states accordingly */
  1596. keep_nlp_state = new_ndlp->nlp_state;
  1597. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  1598. /* interchange the nvme remoteport structs */
  1599. keep_nrport = new_ndlp->nrport;
  1600. new_ndlp->nrport = ndlp->nrport;
  1601. /* Move this back to NPR state */
  1602. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
  1603. /* The ndlp doesn't have a portname yet, but does have an
  1604. * NPort ID. The new_ndlp portname matches the Rport's
  1605. * portname. Reinstantiate the new_ndlp and reset the ndlp.
  1606. */
  1607. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1608. "3179 PLOGI confirm NEW: %x %x\n",
  1609. new_ndlp->nlp_DID, keepDID);
  1610. /* Two ndlps cannot have the same did on the nodelist.
  1611. * The KeepDID and keep_nlp_fc4_type need to be swapped
  1612. * because ndlp is inflight with no WWPN.
  1613. */
  1614. ndlp->nlp_DID = keepDID;
  1615. ndlp->nlp_fc4_type = keep_nlp_fc4_type;
  1616. lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
  1617. if (phba->sli_rev == LPFC_SLI_REV4 &&
  1618. active_rrqs_xri_bitmap)
  1619. memcpy(ndlp->active_rrqs_xri_bitmap,
  1620. active_rrqs_xri_bitmap,
  1621. phba->cfg_rrq_xri_bitmap_sz);
  1622. } else {
  1623. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1624. "3180 PLOGI confirm SWAP: %x %x\n",
  1625. new_ndlp->nlp_DID, keepDID);
  1626. lpfc_unreg_rpi(vport, ndlp);
  1627. /* The ndlp and new_ndlp both have WWPNs but are swapping
  1628. * NPort Ids and attributes.
  1629. */
  1630. ndlp->nlp_DID = keepDID;
  1631. ndlp->nlp_fc4_type = keep_nlp_fc4_type;
  1632. if (phba->sli_rev == LPFC_SLI_REV4 &&
  1633. active_rrqs_xri_bitmap)
  1634. memcpy(ndlp->active_rrqs_xri_bitmap,
  1635. active_rrqs_xri_bitmap,
  1636. phba->cfg_rrq_xri_bitmap_sz);
  1637. /* Since we are switching over to the new_ndlp,
  1638. * reset the old ndlp state
  1639. */
  1640. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  1641. (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
  1642. keep_nlp_state = NLP_STE_NPR_NODE;
  1643. lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
  1644. ndlp->nrport = keep_nrport;
  1645. }
  1646. /*
  1647. * If ndlp is not associated with any rport we can drop it here else
  1648. * let dev_loss_tmo_callbk trigger DEVICE_RM event
  1649. */
  1650. if (!ndlp->rport && (ndlp->nlp_state == NLP_STE_NPR_NODE))
  1651. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  1652. if (phba->sli_rev == LPFC_SLI_REV4 &&
  1653. active_rrqs_xri_bitmap)
  1654. mempool_free(active_rrqs_xri_bitmap,
  1655. phba->active_rrq_pool);
  1656. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
  1657. "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
  1658. new_ndlp->nlp_DID, new_ndlp->nlp_flag,
  1659. new_ndlp->nlp_fc4_type);
  1660. return new_ndlp;
  1661. }
  1662. /**
  1663. * lpfc_end_rscn - Check and handle more rscn for a vport
  1664. * @vport: pointer to a host virtual N_Port data structure.
  1665. *
  1666. * This routine checks whether more Registration State Change
  1667. * Notifications (RSCNs) came in while the discovery state machine was in
  1668. * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
  1669. * invoked to handle the additional RSCNs for the @vport. Otherwise, the
  1670. * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
  1671. * handling the RSCNs.
  1672. **/
  1673. void
  1674. lpfc_end_rscn(struct lpfc_vport *vport)
  1675. {
  1676. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1677. if (vport->fc_flag & FC_RSCN_MODE) {
  1678. /*
  1679. * Check to see if more RSCNs came in while we were
  1680. * processing this one.
  1681. */
  1682. if (vport->fc_rscn_id_cnt ||
  1683. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  1684. lpfc_els_handle_rscn(vport);
  1685. else {
  1686. spin_lock_irq(shost->host_lock);
  1687. vport->fc_flag &= ~FC_RSCN_MODE;
  1688. spin_unlock_irq(shost->host_lock);
  1689. }
  1690. }
  1691. }
  1692. /**
  1693. * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
  1694. * @phba: pointer to lpfc hba data structure.
  1695. * @cmdiocb: pointer to lpfc command iocb data structure.
  1696. * @rspiocb: pointer to lpfc response iocb data structure.
  1697. *
  1698. * This routine will call the clear rrq function to free the rrq and
  1699. * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
  1700. * exist then the clear_rrq is still called because the rrq needs to
  1701. * be freed.
  1702. **/
  1703. static void
  1704. lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1705. struct lpfc_iocbq *rspiocb)
  1706. {
  1707. struct lpfc_vport *vport = cmdiocb->vport;
  1708. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  1709. struct lpfc_node_rrq *rrq;
  1710. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  1711. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  1712. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1713. rrq = cmdiocb->context_un.rrq;
  1714. cmdiocb->rsp_iocb = rspiocb;
  1715. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1716. "RRQ cmpl: status:x%x/x%x did:x%x",
  1717. ulp_status, ulp_word4,
  1718. get_job_els_rsp64_did(phba, cmdiocb));
  1719. /* rrq completes to NPort <nlp_DID> */
  1720. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1721. "2880 RRQ completes to DID x%x "
  1722. "Data: x%x x%x x%x x%x x%x\n",
  1723. ndlp->nlp_DID, ulp_status, ulp_word4,
  1724. get_wqe_tmo(cmdiocb), rrq->xritag, rrq->rxid);
  1725. if (ulp_status) {
  1726. /* Check for retry */
  1727. /* RRQ failed Don't print the vport to vport rjts */
  1728. if (ulp_status != IOSTAT_LS_RJT ||
  1729. (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
  1730. ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
  1731. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1732. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1733. "2881 RRQ failure DID:%06X Status:"
  1734. "x%x/x%x\n",
  1735. ndlp->nlp_DID, ulp_status,
  1736. ulp_word4);
  1737. }
  1738. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  1739. lpfc_els_free_iocb(phba, cmdiocb);
  1740. lpfc_nlp_put(ndlp);
  1741. return;
  1742. }
  1743. /**
  1744. * lpfc_cmpl_els_plogi - Completion callback function for plogi
  1745. * @phba: pointer to lpfc hba data structure.
  1746. * @cmdiocb: pointer to lpfc command iocb data structure.
  1747. * @rspiocb: pointer to lpfc response iocb data structure.
  1748. *
  1749. * This routine is the completion callback function for issuing the Port
  1750. * Login (PLOGI) command. For PLOGI completion, there must be an active
  1751. * ndlp on the vport node list that matches the remote node ID from the
  1752. * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
  1753. * ignored and command IOCB released. The PLOGI response IOCB status is
  1754. * checked for error conditions. If there is error status reported, PLOGI
  1755. * retry shall be attempted by invoking the lpfc_els_retry() routine.
  1756. * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
  1757. * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
  1758. * (DSM) is set for this PLOGI completion. Finally, it checks whether
  1759. * there are additional N_Port nodes with the vport that need to perform
  1760. * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
  1761. * PLOGIs.
  1762. **/
  1763. static void
  1764. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1765. struct lpfc_iocbq *rspiocb)
  1766. {
  1767. struct lpfc_vport *vport = cmdiocb->vport;
  1768. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1769. IOCB_t *irsp;
  1770. struct lpfc_nodelist *ndlp, *free_ndlp;
  1771. struct lpfc_dmabuf *prsp;
  1772. int disc;
  1773. struct serv_parm *sp = NULL;
  1774. u32 ulp_status, ulp_word4, did, iotag;
  1775. bool release_node = false;
  1776. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1777. cmdiocb->rsp_iocb = rspiocb;
  1778. ulp_status = get_job_ulpstatus(phba, rspiocb);
  1779. ulp_word4 = get_job_word4(phba, rspiocb);
  1780. did = get_job_els_rsp64_did(phba, cmdiocb);
  1781. if (phba->sli_rev == LPFC_SLI_REV4) {
  1782. iotag = get_wqe_reqtag(cmdiocb);
  1783. } else {
  1784. irsp = &rspiocb->iocb;
  1785. iotag = irsp->ulpIoTag;
  1786. }
  1787. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1788. "PLOGI cmpl: status:x%x/x%x did:x%x",
  1789. ulp_status, ulp_word4, did);
  1790. ndlp = lpfc_findnode_did(vport, did);
  1791. if (!ndlp) {
  1792. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1793. "0136 PLOGI completes to NPort x%x "
  1794. "with no ndlp. Data: x%x x%x x%x\n",
  1795. did, ulp_status, ulp_word4, iotag);
  1796. goto out_freeiocb;
  1797. }
  1798. /* Since ndlp can be freed in the disc state machine, note if this node
  1799. * is being used during discovery.
  1800. */
  1801. spin_lock_irq(&ndlp->lock);
  1802. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1803. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1804. spin_unlock_irq(&ndlp->lock);
  1805. /* PLOGI completes to NPort <nlp_DID> */
  1806. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1807. "0102 PLOGI completes to NPort x%06x "
  1808. "Data: x%x x%x x%x x%x x%x\n",
  1809. ndlp->nlp_DID, ndlp->nlp_fc4_type,
  1810. ulp_status, ulp_word4,
  1811. disc, vport->num_disc_nodes);
  1812. /* Check to see if link went down during discovery */
  1813. if (lpfc_els_chk_latt(vport)) {
  1814. spin_lock_irq(&ndlp->lock);
  1815. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1816. spin_unlock_irq(&ndlp->lock);
  1817. goto out;
  1818. }
  1819. if (ulp_status) {
  1820. /* Check for retry */
  1821. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1822. /* ELS command is being retried */
  1823. if (disc) {
  1824. spin_lock_irq(&ndlp->lock);
  1825. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1826. spin_unlock_irq(&ndlp->lock);
  1827. }
  1828. goto out;
  1829. }
  1830. /* PLOGI failed Don't print the vport to vport rjts */
  1831. if (ulp_status != IOSTAT_LS_RJT ||
  1832. (((ulp_word4) >> 16 != LSRJT_INVALID_CMD) &&
  1833. ((ulp_word4) >> 16 != LSRJT_UNABLE_TPC)) ||
  1834. (phba)->pport->cfg_log_verbose & LOG_ELS)
  1835. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  1836. "2753 PLOGI failure DID:%06X "
  1837. "Status:x%x/x%x\n",
  1838. ndlp->nlp_DID, ulp_status,
  1839. ulp_word4);
  1840. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1841. if (!lpfc_error_lost_link(ulp_status, ulp_word4))
  1842. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1843. NLP_EVT_CMPL_PLOGI);
  1844. /* If a PLOGI collision occurred, the node needs to continue
  1845. * with the reglogin process.
  1846. */
  1847. spin_lock_irq(&ndlp->lock);
  1848. if ((ndlp->nlp_flag & (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI)) &&
  1849. ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE) {
  1850. spin_unlock_irq(&ndlp->lock);
  1851. goto out;
  1852. }
  1853. /* No PLOGI collision and the node is not registered with the
  1854. * scsi or nvme transport. It is no longer an active node. Just
  1855. * start the device remove process.
  1856. */
  1857. if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
  1858. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1859. if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
  1860. release_node = true;
  1861. }
  1862. spin_unlock_irq(&ndlp->lock);
  1863. if (release_node)
  1864. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1865. NLP_EVT_DEVICE_RM);
  1866. } else {
  1867. /* Good status, call state machine */
  1868. prsp = list_entry(cmdiocb->cmd_dmabuf->list.next,
  1869. struct lpfc_dmabuf, list);
  1870. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  1871. sp = (struct serv_parm *)((u8 *)prsp->virt +
  1872. sizeof(u32));
  1873. ndlp->vmid_support = 0;
  1874. if ((phba->cfg_vmid_app_header && sp->cmn.app_hdr_support) ||
  1875. (phba->cfg_vmid_priority_tagging &&
  1876. sp->cmn.priority_tagging)) {
  1877. lpfc_printf_log(phba, KERN_DEBUG, LOG_ELS,
  1878. "4018 app_hdr_support %d tagging %d DID x%x\n",
  1879. sp->cmn.app_hdr_support,
  1880. sp->cmn.priority_tagging,
  1881. ndlp->nlp_DID);
  1882. /* if the dest port supports VMID, mark it in ndlp */
  1883. ndlp->vmid_support = 1;
  1884. }
  1885. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1886. NLP_EVT_CMPL_PLOGI);
  1887. }
  1888. if (disc && vport->num_disc_nodes) {
  1889. /* Check to see if there are more PLOGIs to be sent */
  1890. lpfc_more_plogi(vport);
  1891. if (vport->num_disc_nodes == 0) {
  1892. spin_lock_irq(shost->host_lock);
  1893. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1894. spin_unlock_irq(shost->host_lock);
  1895. lpfc_can_disctmo(vport);
  1896. lpfc_end_rscn(vport);
  1897. }
  1898. }
  1899. out:
  1900. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  1901. "PLOGI Cmpl PUT: did:x%x refcnt %d",
  1902. ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
  1903. out_freeiocb:
  1904. /* Release the reference on the original I/O request. */
  1905. free_ndlp = cmdiocb->ndlp;
  1906. lpfc_els_free_iocb(phba, cmdiocb);
  1907. lpfc_nlp_put(free_ndlp);
  1908. return;
  1909. }
  1910. /**
  1911. * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
  1912. * @vport: pointer to a host virtual N_Port data structure.
  1913. * @did: destination port identifier.
  1914. * @retry: number of retries to the command IOCB.
  1915. *
  1916. * This routine issues a Port Login (PLOGI) command to a remote N_Port
  1917. * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
  1918. * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
  1919. * This routine constructs the proper fields of the PLOGI IOCB and invokes
  1920. * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
  1921. *
  1922. * Note that the ndlp reference count will be incremented by 1 for holding
  1923. * the ndlp and the reference to ndlp will be stored into the ndlp field
  1924. * of the IOCB for the completion callback function to the PLOGI ELS command.
  1925. *
  1926. * Return code
  1927. * 0 - Successfully issued a plogi for @vport
  1928. * 1 - failed to issue a plogi for @vport
  1929. **/
  1930. int
  1931. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  1932. {
  1933. struct lpfc_hba *phba = vport->phba;
  1934. struct serv_parm *sp;
  1935. struct lpfc_nodelist *ndlp;
  1936. struct lpfc_iocbq *elsiocb;
  1937. uint8_t *pcmd;
  1938. uint16_t cmdsize;
  1939. int ret;
  1940. ndlp = lpfc_findnode_did(vport, did);
  1941. if (!ndlp)
  1942. return 1;
  1943. /* Defer the processing of the issue PLOGI until after the
  1944. * outstanding UNREG_RPI mbox command completes, unless we
  1945. * are going offline. This logic does not apply for Fabric DIDs
  1946. */
  1947. if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
  1948. ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
  1949. !(vport->fc_flag & FC_OFFLINE_MODE)) {
  1950. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1951. "4110 Issue PLOGI x%x deferred "
  1952. "on NPort x%x rpi x%x Data: x%px\n",
  1953. ndlp->nlp_defer_did, ndlp->nlp_DID,
  1954. ndlp->nlp_rpi, ndlp);
  1955. /* We can only defer 1st PLOGI */
  1956. if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
  1957. ndlp->nlp_defer_did = did;
  1958. return 0;
  1959. }
  1960. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  1961. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  1962. ELS_CMD_PLOGI);
  1963. if (!elsiocb)
  1964. return 1;
  1965. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  1966. /* For PLOGI request, remainder of payload is service parameters */
  1967. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  1968. pcmd += sizeof(uint32_t);
  1969. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  1970. sp = (struct serv_parm *) pcmd;
  1971. /*
  1972. * If we are a N-port connected to a Fabric, fix-up paramm's so logins
  1973. * to device on remote loops work.
  1974. */
  1975. if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
  1976. sp->cmn.altBbCredit = 1;
  1977. if (sp->cmn.fcphLow < FC_PH_4_3)
  1978. sp->cmn.fcphLow = FC_PH_4_3;
  1979. if (sp->cmn.fcphHigh < FC_PH3)
  1980. sp->cmn.fcphHigh = FC_PH3;
  1981. sp->cmn.valid_vendor_ver_level = 0;
  1982. memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
  1983. sp->cmn.bbRcvSizeMsb &= 0xF;
  1984. /* Check if the destination port supports VMID */
  1985. ndlp->vmid_support = 0;
  1986. if (vport->vmid_priority_tagging)
  1987. sp->cmn.priority_tagging = 1;
  1988. else if (phba->cfg_vmid_app_header &&
  1989. bf_get(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags))
  1990. sp->cmn.app_hdr_support = 1;
  1991. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1992. "Issue PLOGI: did:x%x",
  1993. did, 0, 0);
  1994. /* If our firmware supports this feature, convey that
  1995. * information to the target using the vendor specific field.
  1996. */
  1997. if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
  1998. sp->cmn.valid_vendor_ver_level = 1;
  1999. sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
  2000. sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
  2001. }
  2002. phba->fc_stat.elsXmitPLOGI++;
  2003. elsiocb->cmd_cmpl = lpfc_cmpl_els_plogi;
  2004. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2005. "Issue PLOGI: did:x%x refcnt %d",
  2006. did, kref_read(&ndlp->kref), 0);
  2007. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  2008. if (!elsiocb->ndlp) {
  2009. lpfc_els_free_iocb(phba, elsiocb);
  2010. return 1;
  2011. }
  2012. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  2013. if (ret) {
  2014. lpfc_els_free_iocb(phba, elsiocb);
  2015. lpfc_nlp_put(ndlp);
  2016. return 1;
  2017. }
  2018. return 0;
  2019. }
  2020. /**
  2021. * lpfc_cmpl_els_prli - Completion callback function for prli
  2022. * @phba: pointer to lpfc hba data structure.
  2023. * @cmdiocb: pointer to lpfc command iocb data structure.
  2024. * @rspiocb: pointer to lpfc response iocb data structure.
  2025. *
  2026. * This routine is the completion callback function for a Process Login
  2027. * (PRLI) ELS command. The PRLI response IOCB status is checked for error
  2028. * status. If there is error status reported, PRLI retry shall be attempted
  2029. * by invoking the lpfc_els_retry() routine. Otherwise, the state
  2030. * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
  2031. * ndlp to mark the PRLI completion.
  2032. **/
  2033. static void
  2034. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2035. struct lpfc_iocbq *rspiocb)
  2036. {
  2037. struct lpfc_vport *vport = cmdiocb->vport;
  2038. struct lpfc_nodelist *ndlp;
  2039. char *mode;
  2040. u32 loglevel;
  2041. u32 ulp_status;
  2042. u32 ulp_word4;
  2043. bool release_node = false;
  2044. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2045. cmdiocb->rsp_iocb = rspiocb;
  2046. ndlp = cmdiocb->ndlp;
  2047. ulp_status = get_job_ulpstatus(phba, rspiocb);
  2048. ulp_word4 = get_job_word4(phba, rspiocb);
  2049. spin_lock_irq(&ndlp->lock);
  2050. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  2051. /* Driver supports multiple FC4 types. Counters matter. */
  2052. vport->fc_prli_sent--;
  2053. ndlp->fc4_prli_sent--;
  2054. spin_unlock_irq(&ndlp->lock);
  2055. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2056. "PRLI cmpl: status:x%x/x%x did:x%x",
  2057. ulp_status, ulp_word4,
  2058. ndlp->nlp_DID);
  2059. /* PRLI completes to NPort <nlp_DID> */
  2060. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2061. "0103 PRLI completes to NPort x%06x "
  2062. "Data: x%x x%x x%x x%x\n",
  2063. ndlp->nlp_DID, ulp_status, ulp_word4,
  2064. vport->num_disc_nodes, ndlp->fc4_prli_sent);
  2065. /* Check to see if link went down during discovery */
  2066. if (lpfc_els_chk_latt(vport))
  2067. goto out;
  2068. if (ulp_status) {
  2069. /* Check for retry */
  2070. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2071. /* ELS command is being retried */
  2072. goto out;
  2073. }
  2074. /* If we don't send GFT_ID to Fabric, a PRLI error
  2075. * could be expected.
  2076. */
  2077. if ((vport->fc_flag & FC_FABRIC) ||
  2078. (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
  2079. mode = KERN_ERR;
  2080. loglevel = LOG_TRACE_EVENT;
  2081. } else {
  2082. mode = KERN_INFO;
  2083. loglevel = LOG_ELS;
  2084. }
  2085. /* PRLI failed */
  2086. lpfc_printf_vlog(vport, mode, loglevel,
  2087. "2754 PRLI failure DID:%06X Status:x%x/x%x, "
  2088. "data: x%x\n",
  2089. ndlp->nlp_DID, ulp_status,
  2090. ulp_word4, ndlp->fc4_prli_sent);
  2091. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  2092. if (!lpfc_error_lost_link(ulp_status, ulp_word4))
  2093. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2094. NLP_EVT_CMPL_PRLI);
  2095. /*
  2096. * For P2P topology, retain the node so that PLOGI can be
  2097. * attempted on it again.
  2098. */
  2099. if (vport->fc_flag & FC_PT2PT)
  2100. goto out;
  2101. /* As long as this node is not registered with the SCSI
  2102. * or NVMe transport and no other PRLIs are outstanding,
  2103. * it is no longer an active node. Otherwise devloss
  2104. * handles the final cleanup.
  2105. */
  2106. spin_lock_irq(&ndlp->lock);
  2107. if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD)) &&
  2108. !ndlp->fc4_prli_sent) {
  2109. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  2110. if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
  2111. release_node = true;
  2112. }
  2113. spin_unlock_irq(&ndlp->lock);
  2114. if (release_node)
  2115. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2116. NLP_EVT_DEVICE_RM);
  2117. } else {
  2118. /* Good status, call state machine. However, if another
  2119. * PRLI is outstanding, don't call the state machine
  2120. * because final disposition to Mapped or Unmapped is
  2121. * completed there.
  2122. */
  2123. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2124. NLP_EVT_CMPL_PRLI);
  2125. }
  2126. out:
  2127. lpfc_els_free_iocb(phba, cmdiocb);
  2128. lpfc_nlp_put(ndlp);
  2129. return;
  2130. }
  2131. /**
  2132. * lpfc_issue_els_prli - Issue a prli iocb command for a vport
  2133. * @vport: pointer to a host virtual N_Port data structure.
  2134. * @ndlp: pointer to a node-list data structure.
  2135. * @retry: number of retries to the command IOCB.
  2136. *
  2137. * This routine issues a Process Login (PRLI) ELS command for the
  2138. * @vport. The PRLI service parameters are set up in the payload of the
  2139. * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
  2140. * is put to the IOCB completion callback func field before invoking the
  2141. * routine lpfc_sli_issue_iocb() to send out PRLI command.
  2142. *
  2143. * Note that the ndlp reference count will be incremented by 1 for holding the
  2144. * ndlp and the reference to ndlp will be stored into the ndlp field of
  2145. * the IOCB for the completion callback function to the PRLI ELS command.
  2146. *
  2147. * Return code
  2148. * 0 - successfully issued prli iocb command for @vport
  2149. * 1 - failed to issue prli iocb command for @vport
  2150. **/
  2151. int
  2152. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2153. uint8_t retry)
  2154. {
  2155. int rc = 0;
  2156. struct lpfc_hba *phba = vport->phba;
  2157. PRLI *npr;
  2158. struct lpfc_nvme_prli *npr_nvme;
  2159. struct lpfc_iocbq *elsiocb;
  2160. uint8_t *pcmd;
  2161. uint16_t cmdsize;
  2162. u32 local_nlp_type, elscmd;
  2163. /*
  2164. * If we are in RSCN mode, the FC4 types supported from a
  2165. * previous GFT_ID command may not be accurate. So, if we
  2166. * are a NVME Initiator, always look for the possibility of
  2167. * the remote NPort beng a NVME Target.
  2168. */
  2169. if (phba->sli_rev == LPFC_SLI_REV4 &&
  2170. vport->fc_flag & FC_RSCN_MODE &&
  2171. vport->nvmei_support)
  2172. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  2173. local_nlp_type = ndlp->nlp_fc4_type;
  2174. /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
  2175. * fields here before any of them can complete.
  2176. */
  2177. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  2178. ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
  2179. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  2180. ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
  2181. ndlp->nvme_fb_size = 0;
  2182. send_next_prli:
  2183. if (local_nlp_type & NLP_FC4_FCP) {
  2184. /* Payload is 4 + 16 = 20 x14 bytes. */
  2185. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  2186. elscmd = ELS_CMD_PRLI;
  2187. } else if (local_nlp_type & NLP_FC4_NVME) {
  2188. /* Payload is 4 + 20 = 24 x18 bytes. */
  2189. cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
  2190. elscmd = ELS_CMD_NVMEPRLI;
  2191. } else {
  2192. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2193. "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
  2194. ndlp->nlp_fc4_type, ndlp->nlp_DID);
  2195. return 1;
  2196. }
  2197. /* SLI3 ports don't support NVME. If this rport is a strict NVME
  2198. * FC4 type, implicitly LOGO.
  2199. */
  2200. if (phba->sli_rev == LPFC_SLI_REV3 &&
  2201. ndlp->nlp_fc4_type == NLP_FC4_NVME) {
  2202. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2203. "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
  2204. ndlp->nlp_type);
  2205. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  2206. return 1;
  2207. }
  2208. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2209. ndlp->nlp_DID, elscmd);
  2210. if (!elsiocb)
  2211. return 1;
  2212. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  2213. /* For PRLI request, remainder of payload is service parameters */
  2214. memset(pcmd, 0, cmdsize);
  2215. if (local_nlp_type & NLP_FC4_FCP) {
  2216. /* Remainder of payload is FCP PRLI parameter page.
  2217. * Note: this data structure is defined as
  2218. * BE/LE in the structure definition so no
  2219. * byte swap call is made.
  2220. */
  2221. *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
  2222. pcmd += sizeof(uint32_t);
  2223. npr = (PRLI *)pcmd;
  2224. /*
  2225. * If our firmware version is 3.20 or later,
  2226. * set the following bits for FC-TAPE support.
  2227. */
  2228. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  2229. npr->ConfmComplAllowed = 1;
  2230. npr->Retry = 1;
  2231. npr->TaskRetryIdReq = 1;
  2232. }
  2233. npr->estabImagePair = 1;
  2234. npr->readXferRdyDis = 1;
  2235. if (vport->cfg_first_burst_size)
  2236. npr->writeXferRdyDis = 1;
  2237. /* For FCP support */
  2238. npr->prliType = PRLI_FCP_TYPE;
  2239. npr->initiatorFunc = 1;
  2240. elsiocb->cmd_flag |= LPFC_PRLI_FCP_REQ;
  2241. /* Remove FCP type - processed. */
  2242. local_nlp_type &= ~NLP_FC4_FCP;
  2243. } else if (local_nlp_type & NLP_FC4_NVME) {
  2244. /* Remainder of payload is NVME PRLI parameter page.
  2245. * This data structure is the newer definition that
  2246. * uses bf macros so a byte swap is required.
  2247. */
  2248. *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
  2249. pcmd += sizeof(uint32_t);
  2250. npr_nvme = (struct lpfc_nvme_prli *)pcmd;
  2251. bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
  2252. bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
  2253. if (phba->nsler) {
  2254. bf_set(prli_nsler, npr_nvme, 1);
  2255. bf_set(prli_conf, npr_nvme, 1);
  2256. }
  2257. /* Only initiators request first burst. */
  2258. if ((phba->cfg_nvme_enable_fb) &&
  2259. !phba->nvmet_support)
  2260. bf_set(prli_fba, npr_nvme, 1);
  2261. if (phba->nvmet_support) {
  2262. bf_set(prli_tgt, npr_nvme, 1);
  2263. bf_set(prli_disc, npr_nvme, 1);
  2264. } else {
  2265. bf_set(prli_init, npr_nvme, 1);
  2266. bf_set(prli_conf, npr_nvme, 1);
  2267. }
  2268. npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
  2269. npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
  2270. elsiocb->cmd_flag |= LPFC_PRLI_NVME_REQ;
  2271. /* Remove NVME type - processed. */
  2272. local_nlp_type &= ~NLP_FC4_NVME;
  2273. }
  2274. phba->fc_stat.elsXmitPRLI++;
  2275. elsiocb->cmd_cmpl = lpfc_cmpl_els_prli;
  2276. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2277. "Issue PRLI: did:x%x refcnt %d",
  2278. ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
  2279. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  2280. if (!elsiocb->ndlp) {
  2281. lpfc_els_free_iocb(phba, elsiocb);
  2282. return 1;
  2283. }
  2284. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  2285. if (rc == IOCB_ERROR) {
  2286. lpfc_els_free_iocb(phba, elsiocb);
  2287. lpfc_nlp_put(ndlp);
  2288. return 1;
  2289. }
  2290. /* The vport counters are used for lpfc_scan_finished, but
  2291. * the ndlp is used to track outstanding PRLIs for different
  2292. * FC4 types.
  2293. */
  2294. spin_lock_irq(&ndlp->lock);
  2295. ndlp->nlp_flag |= NLP_PRLI_SND;
  2296. vport->fc_prli_sent++;
  2297. ndlp->fc4_prli_sent++;
  2298. spin_unlock_irq(&ndlp->lock);
  2299. /* The driver supports 2 FC4 types. Make sure
  2300. * a PRLI is issued for all types before exiting.
  2301. */
  2302. if (phba->sli_rev == LPFC_SLI_REV4 &&
  2303. local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
  2304. goto send_next_prli;
  2305. else
  2306. return 0;
  2307. }
  2308. /**
  2309. * lpfc_rscn_disc - Perform rscn discovery for a vport
  2310. * @vport: pointer to a host virtual N_Port data structure.
  2311. *
  2312. * This routine performs Registration State Change Notification (RSCN)
  2313. * discovery for a @vport. If the @vport's node port recovery count is not
  2314. * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
  2315. * the nodes that need recovery. If none of the PLOGI were needed through
  2316. * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
  2317. * invoked to check and handle possible more RSCN came in during the period
  2318. * of processing the current ones.
  2319. **/
  2320. static void
  2321. lpfc_rscn_disc(struct lpfc_vport *vport)
  2322. {
  2323. lpfc_can_disctmo(vport);
  2324. /* RSCN discovery */
  2325. /* go thru NPR nodes and issue ELS PLOGIs */
  2326. if (vport->fc_npr_cnt)
  2327. if (lpfc_els_disc_plogi(vport))
  2328. return;
  2329. lpfc_end_rscn(vport);
  2330. }
  2331. /**
  2332. * lpfc_adisc_done - Complete the adisc phase of discovery
  2333. * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
  2334. *
  2335. * This function is called when the final ADISC is completed during discovery.
  2336. * This function handles clearing link attention or issuing reg_vpi depending
  2337. * on whether npiv is enabled. This function also kicks off the PLOGI phase of
  2338. * discovery.
  2339. * This function is called with no locks held.
  2340. **/
  2341. static void
  2342. lpfc_adisc_done(struct lpfc_vport *vport)
  2343. {
  2344. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2345. struct lpfc_hba *phba = vport->phba;
  2346. /*
  2347. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  2348. * and continue discovery.
  2349. */
  2350. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2351. !(vport->fc_flag & FC_RSCN_MODE) &&
  2352. (phba->sli_rev < LPFC_SLI_REV4)) {
  2353. /*
  2354. * If link is down, clear_la and reg_vpi will be done after
  2355. * flogi following a link up event
  2356. */
  2357. if (!lpfc_is_link_up(phba))
  2358. return;
  2359. /* The ADISCs are complete. Doesn't matter if they
  2360. * succeeded or failed because the ADISC completion
  2361. * routine guarantees to call the state machine and
  2362. * the RPI is either unregistered (failed ADISC response)
  2363. * or the RPI is still valid and the node is marked
  2364. * mapped for a target. The exchanges should be in the
  2365. * correct state. This code is specific to SLI3.
  2366. */
  2367. lpfc_issue_clear_la(phba, vport);
  2368. lpfc_issue_reg_vpi(phba, vport);
  2369. return;
  2370. }
  2371. /*
  2372. * For SLI2, we need to set port_state to READY
  2373. * and continue discovery.
  2374. */
  2375. if (vport->port_state < LPFC_VPORT_READY) {
  2376. /* If we get here, there is nothing to ADISC */
  2377. lpfc_issue_clear_la(phba, vport);
  2378. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  2379. vport->num_disc_nodes = 0;
  2380. /* go thru NPR list, issue ELS PLOGIs */
  2381. if (vport->fc_npr_cnt)
  2382. lpfc_els_disc_plogi(vport);
  2383. if (!vport->num_disc_nodes) {
  2384. spin_lock_irq(shost->host_lock);
  2385. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2386. spin_unlock_irq(shost->host_lock);
  2387. lpfc_can_disctmo(vport);
  2388. lpfc_end_rscn(vport);
  2389. }
  2390. }
  2391. vport->port_state = LPFC_VPORT_READY;
  2392. } else
  2393. lpfc_rscn_disc(vport);
  2394. }
  2395. /**
  2396. * lpfc_more_adisc - Issue more adisc as needed
  2397. * @vport: pointer to a host virtual N_Port data structure.
  2398. *
  2399. * This routine determines whether there are more ndlps on a @vport
  2400. * node list need to have Address Discover (ADISC) issued. If so, it will
  2401. * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
  2402. * remaining nodes which need to have ADISC sent.
  2403. **/
  2404. void
  2405. lpfc_more_adisc(struct lpfc_vport *vport)
  2406. {
  2407. if (vport->num_disc_nodes)
  2408. vport->num_disc_nodes--;
  2409. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  2410. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2411. "0210 Continue discovery with %d ADISCs to go "
  2412. "Data: x%x x%x x%x\n",
  2413. vport->num_disc_nodes, vport->fc_adisc_cnt,
  2414. vport->fc_flag, vport->port_state);
  2415. /* Check to see if there are more ADISCs to be sent */
  2416. if (vport->fc_flag & FC_NLP_MORE) {
  2417. lpfc_set_disctmo(vport);
  2418. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  2419. lpfc_els_disc_adisc(vport);
  2420. }
  2421. if (!vport->num_disc_nodes)
  2422. lpfc_adisc_done(vport);
  2423. return;
  2424. }
  2425. /**
  2426. * lpfc_cmpl_els_adisc - Completion callback function for adisc
  2427. * @phba: pointer to lpfc hba data structure.
  2428. * @cmdiocb: pointer to lpfc command iocb data structure.
  2429. * @rspiocb: pointer to lpfc response iocb data structure.
  2430. *
  2431. * This routine is the completion function for issuing the Address Discover
  2432. * (ADISC) command. It first checks to see whether link went down during
  2433. * the discovery process. If so, the node will be marked as node port
  2434. * recovery for issuing discover IOCB by the link attention handler and
  2435. * exit. Otherwise, the response status is checked. If error was reported
  2436. * in the response status, the ADISC command shall be retried by invoking
  2437. * the lpfc_els_retry() routine. Otherwise, if no error was reported in
  2438. * the response status, the state machine is invoked to set transition
  2439. * with respect to NLP_EVT_CMPL_ADISC event.
  2440. **/
  2441. static void
  2442. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2443. struct lpfc_iocbq *rspiocb)
  2444. {
  2445. struct lpfc_vport *vport = cmdiocb->vport;
  2446. IOCB_t *irsp;
  2447. struct lpfc_nodelist *ndlp;
  2448. int disc;
  2449. u32 ulp_status, ulp_word4, tmo;
  2450. bool release_node = false;
  2451. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2452. cmdiocb->rsp_iocb = rspiocb;
  2453. ndlp = cmdiocb->ndlp;
  2454. ulp_status = get_job_ulpstatus(phba, rspiocb);
  2455. ulp_word4 = get_job_word4(phba, rspiocb);
  2456. if (phba->sli_rev == LPFC_SLI_REV4) {
  2457. tmo = get_wqe_tmo(cmdiocb);
  2458. } else {
  2459. irsp = &rspiocb->iocb;
  2460. tmo = irsp->ulpTimeout;
  2461. }
  2462. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2463. "ADISC cmpl: status:x%x/x%x did:x%x",
  2464. ulp_status, ulp_word4,
  2465. ndlp->nlp_DID);
  2466. /* Since ndlp can be freed in the disc state machine, note if this node
  2467. * is being used during discovery.
  2468. */
  2469. spin_lock_irq(&ndlp->lock);
  2470. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  2471. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  2472. spin_unlock_irq(&ndlp->lock);
  2473. /* ADISC completes to NPort <nlp_DID> */
  2474. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2475. "0104 ADISC completes to NPort x%x "
  2476. "Data: x%x x%x x%x x%x x%x\n",
  2477. ndlp->nlp_DID, ulp_status, ulp_word4,
  2478. tmo, disc, vport->num_disc_nodes);
  2479. /* Check to see if link went down during discovery */
  2480. if (lpfc_els_chk_latt(vport)) {
  2481. spin_lock_irq(&ndlp->lock);
  2482. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2483. spin_unlock_irq(&ndlp->lock);
  2484. goto out;
  2485. }
  2486. if (ulp_status) {
  2487. /* Check for retry */
  2488. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  2489. /* ELS command is being retried */
  2490. if (disc) {
  2491. spin_lock_irq(&ndlp->lock);
  2492. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2493. spin_unlock_irq(&ndlp->lock);
  2494. lpfc_set_disctmo(vport);
  2495. }
  2496. goto out;
  2497. }
  2498. /* ADISC failed */
  2499. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  2500. "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
  2501. ndlp->nlp_DID, ulp_status,
  2502. ulp_word4);
  2503. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2504. NLP_EVT_CMPL_ADISC);
  2505. /* As long as this node is not registered with the SCSI or NVMe
  2506. * transport, it is no longer an active node. Otherwise
  2507. * devloss handles the final cleanup.
  2508. */
  2509. spin_lock_irq(&ndlp->lock);
  2510. if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
  2511. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  2512. if (!(ndlp->nlp_flag & NLP_IN_DEV_LOSS))
  2513. release_node = true;
  2514. }
  2515. spin_unlock_irq(&ndlp->lock);
  2516. if (release_node)
  2517. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2518. NLP_EVT_DEVICE_RM);
  2519. } else
  2520. /* Good status, call state machine */
  2521. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2522. NLP_EVT_CMPL_ADISC);
  2523. /* Check to see if there are more ADISCs to be sent */
  2524. if (disc && vport->num_disc_nodes)
  2525. lpfc_more_adisc(vport);
  2526. out:
  2527. lpfc_els_free_iocb(phba, cmdiocb);
  2528. lpfc_nlp_put(ndlp);
  2529. return;
  2530. }
  2531. /**
  2532. * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
  2533. * @vport: pointer to a virtual N_Port data structure.
  2534. * @ndlp: pointer to a node-list data structure.
  2535. * @retry: number of retries to the command IOCB.
  2536. *
  2537. * This routine issues an Address Discover (ADISC) for an @ndlp on a
  2538. * @vport. It prepares the payload of the ADISC ELS command, updates the
  2539. * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
  2540. * to issue the ADISC ELS command.
  2541. *
  2542. * Note that the ndlp reference count will be incremented by 1 for holding the
  2543. * ndlp and the reference to ndlp will be stored into the ndlp field of
  2544. * the IOCB for the completion callback function to the ADISC ELS command.
  2545. *
  2546. * Return code
  2547. * 0 - successfully issued adisc
  2548. * 1 - failed to issue adisc
  2549. **/
  2550. int
  2551. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2552. uint8_t retry)
  2553. {
  2554. int rc = 0;
  2555. struct lpfc_hba *phba = vport->phba;
  2556. ADISC *ap;
  2557. struct lpfc_iocbq *elsiocb;
  2558. uint8_t *pcmd;
  2559. uint16_t cmdsize;
  2560. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  2561. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2562. ndlp->nlp_DID, ELS_CMD_ADISC);
  2563. if (!elsiocb)
  2564. return 1;
  2565. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  2566. /* For ADISC request, remainder of payload is service parameters */
  2567. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  2568. pcmd += sizeof(uint32_t);
  2569. /* Fill in ADISC payload */
  2570. ap = (ADISC *) pcmd;
  2571. ap->hardAL_PA = phba->fc_pref_ALPA;
  2572. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2573. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2574. ap->DID = be32_to_cpu(vport->fc_myDID);
  2575. phba->fc_stat.elsXmitADISC++;
  2576. elsiocb->cmd_cmpl = lpfc_cmpl_els_adisc;
  2577. spin_lock_irq(&ndlp->lock);
  2578. ndlp->nlp_flag |= NLP_ADISC_SND;
  2579. spin_unlock_irq(&ndlp->lock);
  2580. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  2581. if (!elsiocb->ndlp) {
  2582. lpfc_els_free_iocb(phba, elsiocb);
  2583. goto err;
  2584. }
  2585. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2586. "Issue ADISC: did:x%x refcnt %d",
  2587. ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
  2588. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  2589. if (rc == IOCB_ERROR) {
  2590. lpfc_els_free_iocb(phba, elsiocb);
  2591. lpfc_nlp_put(ndlp);
  2592. goto err;
  2593. }
  2594. return 0;
  2595. err:
  2596. spin_lock_irq(&ndlp->lock);
  2597. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  2598. spin_unlock_irq(&ndlp->lock);
  2599. return 1;
  2600. }
  2601. /**
  2602. * lpfc_cmpl_els_logo - Completion callback function for logo
  2603. * @phba: pointer to lpfc hba data structure.
  2604. * @cmdiocb: pointer to lpfc command iocb data structure.
  2605. * @rspiocb: pointer to lpfc response iocb data structure.
  2606. *
  2607. * This routine is the completion function for issuing the ELS Logout (LOGO)
  2608. * command. If no error status was reported from the LOGO response, the
  2609. * state machine of the associated ndlp shall be invoked for transition with
  2610. * respect to NLP_EVT_CMPL_LOGO event.
  2611. **/
  2612. static void
  2613. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2614. struct lpfc_iocbq *rspiocb)
  2615. {
  2616. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  2617. struct lpfc_vport *vport = ndlp->vport;
  2618. IOCB_t *irsp;
  2619. unsigned long flags;
  2620. uint32_t skip_recovery = 0;
  2621. int wake_up_waiter = 0;
  2622. u32 ulp_status;
  2623. u32 ulp_word4;
  2624. u32 tmo;
  2625. /* we pass cmdiocb to state machine which needs rspiocb as well */
  2626. cmdiocb->rsp_iocb = rspiocb;
  2627. ulp_status = get_job_ulpstatus(phba, rspiocb);
  2628. ulp_word4 = get_job_word4(phba, rspiocb);
  2629. if (phba->sli_rev == LPFC_SLI_REV4) {
  2630. tmo = get_wqe_tmo(cmdiocb);
  2631. } else {
  2632. irsp = &rspiocb->iocb;
  2633. tmo = irsp->ulpTimeout;
  2634. }
  2635. spin_lock_irq(&ndlp->lock);
  2636. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2637. if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
  2638. wake_up_waiter = 1;
  2639. ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
  2640. }
  2641. spin_unlock_irq(&ndlp->lock);
  2642. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2643. "LOGO cmpl: status:x%x/x%x did:x%x",
  2644. ulp_status, ulp_word4,
  2645. ndlp->nlp_DID);
  2646. /* LOGO completes to NPort <nlp_DID> */
  2647. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2648. "0105 LOGO completes to NPort x%x "
  2649. "refcnt %d nflags x%x Data: x%x x%x x%x x%x\n",
  2650. ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
  2651. ulp_status, ulp_word4,
  2652. tmo, vport->num_disc_nodes);
  2653. if (lpfc_els_chk_latt(vport)) {
  2654. skip_recovery = 1;
  2655. goto out;
  2656. }
  2657. /* The LOGO will not be retried on failure. A LOGO was
  2658. * issued to the remote rport and a ACC or RJT or no Answer are
  2659. * all acceptable. Note the failure and move forward with
  2660. * discovery. The PLOGI will retry.
  2661. */
  2662. if (ulp_status) {
  2663. /* LOGO failed */
  2664. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  2665. "2756 LOGO failure, No Retry DID:%06X "
  2666. "Status:x%x/x%x\n",
  2667. ndlp->nlp_DID, ulp_status,
  2668. ulp_word4);
  2669. if (lpfc_error_lost_link(ulp_status, ulp_word4)) {
  2670. skip_recovery = 1;
  2671. goto out;
  2672. }
  2673. }
  2674. /* Call state machine. This will unregister the rpi if needed. */
  2675. lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
  2676. /* The driver sets this flag for an NPIV instance that doesn't want to
  2677. * log into the remote port.
  2678. */
  2679. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  2680. spin_lock_irq(&ndlp->lock);
  2681. if (phba->sli_rev == LPFC_SLI_REV4)
  2682. ndlp->nlp_flag |= NLP_RELEASE_RPI;
  2683. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  2684. spin_unlock_irq(&ndlp->lock);
  2685. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2686. NLP_EVT_DEVICE_RM);
  2687. goto out_rsrc_free;
  2688. }
  2689. out:
  2690. /* At this point, the LOGO processing is complete. NOTE: For a
  2691. * pt2pt topology, we are assuming the NPortID will only change
  2692. * on link up processing. For a LOGO / PLOGI initiated by the
  2693. * Initiator, we are assuming the NPortID is not going to change.
  2694. */
  2695. if (wake_up_waiter && ndlp->logo_waitq)
  2696. wake_up(ndlp->logo_waitq);
  2697. /*
  2698. * If the node is a target, the handling attempts to recover the port.
  2699. * For any other port type, the rpi is unregistered as an implicit
  2700. * LOGO.
  2701. */
  2702. if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
  2703. skip_recovery == 0) {
  2704. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2705. spin_lock_irqsave(&ndlp->lock, flags);
  2706. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2707. spin_unlock_irqrestore(&ndlp->lock, flags);
  2708. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2709. "3187 LOGO completes to NPort x%x: Start "
  2710. "Recovery Data: x%x x%x x%x x%x\n",
  2711. ndlp->nlp_DID, ulp_status,
  2712. ulp_word4, tmo,
  2713. vport->num_disc_nodes);
  2714. lpfc_els_free_iocb(phba, cmdiocb);
  2715. lpfc_nlp_put(ndlp);
  2716. lpfc_disc_start(vport);
  2717. return;
  2718. }
  2719. /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
  2720. * driver sends a LOGO to the rport to cleanup. For fabric and
  2721. * initiator ports cleanup the node as long as it the node is not
  2722. * register with the transport.
  2723. */
  2724. if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
  2725. spin_lock_irq(&ndlp->lock);
  2726. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  2727. spin_unlock_irq(&ndlp->lock);
  2728. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  2729. NLP_EVT_DEVICE_RM);
  2730. }
  2731. out_rsrc_free:
  2732. /* Driver is done with the I/O. */
  2733. lpfc_els_free_iocb(phba, cmdiocb);
  2734. lpfc_nlp_put(ndlp);
  2735. }
  2736. /**
  2737. * lpfc_issue_els_logo - Issue a logo to an node on a vport
  2738. * @vport: pointer to a virtual N_Port data structure.
  2739. * @ndlp: pointer to a node-list data structure.
  2740. * @retry: number of retries to the command IOCB.
  2741. *
  2742. * This routine constructs and issues an ELS Logout (LOGO) iocb command
  2743. * to a remote node, referred by an @ndlp on a @vport. It constructs the
  2744. * payload of the IOCB, properly sets up the @ndlp state, and invokes the
  2745. * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
  2746. *
  2747. * Note that the ndlp reference count will be incremented by 1 for holding the
  2748. * ndlp and the reference to ndlp will be stored into the ndlp field of
  2749. * the IOCB for the completion callback function to the LOGO ELS command.
  2750. *
  2751. * Callers of this routine are expected to unregister the RPI first
  2752. *
  2753. * Return code
  2754. * 0 - successfully issued logo
  2755. * 1 - failed to issue logo
  2756. **/
  2757. int
  2758. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2759. uint8_t retry)
  2760. {
  2761. struct lpfc_hba *phba = vport->phba;
  2762. struct lpfc_iocbq *elsiocb;
  2763. uint8_t *pcmd;
  2764. uint16_t cmdsize;
  2765. int rc;
  2766. spin_lock_irq(&ndlp->lock);
  2767. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  2768. spin_unlock_irq(&ndlp->lock);
  2769. return 0;
  2770. }
  2771. spin_unlock_irq(&ndlp->lock);
  2772. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  2773. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  2774. ndlp->nlp_DID, ELS_CMD_LOGO);
  2775. if (!elsiocb)
  2776. return 1;
  2777. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  2778. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  2779. pcmd += sizeof(uint32_t);
  2780. /* Fill in LOGO payload */
  2781. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  2782. pcmd += sizeof(uint32_t);
  2783. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  2784. phba->fc_stat.elsXmitLOGO++;
  2785. elsiocb->cmd_cmpl = lpfc_cmpl_els_logo;
  2786. spin_lock_irq(&ndlp->lock);
  2787. ndlp->nlp_flag |= NLP_LOGO_SND;
  2788. ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
  2789. spin_unlock_irq(&ndlp->lock);
  2790. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  2791. if (!elsiocb->ndlp) {
  2792. lpfc_els_free_iocb(phba, elsiocb);
  2793. goto err;
  2794. }
  2795. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2796. "Issue LOGO: did:x%x refcnt %d",
  2797. ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
  2798. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  2799. if (rc == IOCB_ERROR) {
  2800. lpfc_els_free_iocb(phba, elsiocb);
  2801. lpfc_nlp_put(ndlp);
  2802. goto err;
  2803. }
  2804. spin_lock_irq(&ndlp->lock);
  2805. ndlp->nlp_prev_state = ndlp->nlp_state;
  2806. spin_unlock_irq(&ndlp->lock);
  2807. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  2808. return 0;
  2809. err:
  2810. spin_lock_irq(&ndlp->lock);
  2811. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  2812. spin_unlock_irq(&ndlp->lock);
  2813. return 1;
  2814. }
  2815. /**
  2816. * lpfc_cmpl_els_cmd - Completion callback function for generic els command
  2817. * @phba: pointer to lpfc hba data structure.
  2818. * @cmdiocb: pointer to lpfc command iocb data structure.
  2819. * @rspiocb: pointer to lpfc response iocb data structure.
  2820. *
  2821. * This routine is a generic completion callback function for ELS commands.
  2822. * Specifically, it is the callback function which does not need to perform
  2823. * any command specific operations. It is currently used by the ELS command
  2824. * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
  2825. * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
  2826. * Other than certain debug loggings, this callback function simply invokes the
  2827. * lpfc_els_chk_latt() routine to check whether link went down during the
  2828. * discovery process.
  2829. **/
  2830. static void
  2831. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2832. struct lpfc_iocbq *rspiocb)
  2833. {
  2834. struct lpfc_vport *vport = cmdiocb->vport;
  2835. struct lpfc_nodelist *free_ndlp;
  2836. IOCB_t *irsp;
  2837. u32 ulp_status, ulp_word4, tmo, did, iotag;
  2838. ulp_status = get_job_ulpstatus(phba, rspiocb);
  2839. ulp_word4 = get_job_word4(phba, rspiocb);
  2840. did = get_job_els_rsp64_did(phba, cmdiocb);
  2841. if (phba->sli_rev == LPFC_SLI_REV4) {
  2842. tmo = get_wqe_tmo(cmdiocb);
  2843. iotag = get_wqe_reqtag(cmdiocb);
  2844. } else {
  2845. irsp = &rspiocb->iocb;
  2846. tmo = irsp->ulpTimeout;
  2847. iotag = irsp->ulpIoTag;
  2848. }
  2849. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2850. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  2851. ulp_status, ulp_word4, did);
  2852. /* ELS cmd tag <ulpIoTag> completes */
  2853. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2854. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  2855. iotag, ulp_status, ulp_word4, tmo);
  2856. /* Check to see if link went down during discovery */
  2857. lpfc_els_chk_latt(vport);
  2858. free_ndlp = cmdiocb->ndlp;
  2859. lpfc_els_free_iocb(phba, cmdiocb);
  2860. lpfc_nlp_put(free_ndlp);
  2861. }
  2862. /**
  2863. * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node.
  2864. * @vport: pointer to lpfc_vport data structure.
  2865. * @fc_ndlp: pointer to the fabric controller (0xfffffd) node.
  2866. *
  2867. * This routine registers the rpi assigned to the fabric controller
  2868. * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED
  2869. * state triggering a registration with the SCSI transport.
  2870. *
  2871. * This routine is single out because the fabric controller node
  2872. * does not receive a PLOGI. This routine is consumed by the
  2873. * SCR and RDF ELS commands. Callers are expected to qualify
  2874. * with SLI4 first.
  2875. **/
  2876. static int
  2877. lpfc_reg_fab_ctrl_node(struct lpfc_vport *vport, struct lpfc_nodelist *fc_ndlp)
  2878. {
  2879. int rc = 0;
  2880. struct lpfc_hba *phba = vport->phba;
  2881. struct lpfc_nodelist *ns_ndlp;
  2882. LPFC_MBOXQ_t *mbox;
  2883. if (fc_ndlp->nlp_flag & NLP_RPI_REGISTERED)
  2884. return rc;
  2885. ns_ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2886. if (!ns_ndlp)
  2887. return -ENODEV;
  2888. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2889. "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n",
  2890. __func__, fc_ndlp->nlp_rpi, fc_ndlp->nlp_DID,
  2891. ns_ndlp->nlp_state);
  2892. if (ns_ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
  2893. return -ENODEV;
  2894. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2895. if (!mbox) {
  2896. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  2897. "0936 %s: no memory for reg_login "
  2898. "Data: x%x x%x x%x x%x\n", __func__,
  2899. fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
  2900. fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
  2901. return -ENOMEM;
  2902. }
  2903. rc = lpfc_reg_rpi(phba, vport->vpi, fc_ndlp->nlp_DID,
  2904. (u8 *)&vport->fc_sparam, mbox, fc_ndlp->nlp_rpi);
  2905. if (rc) {
  2906. rc = -EACCES;
  2907. goto out;
  2908. }
  2909. fc_ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
  2910. mbox->mbox_cmpl = lpfc_mbx_cmpl_fc_reg_login;
  2911. mbox->ctx_ndlp = lpfc_nlp_get(fc_ndlp);
  2912. if (!mbox->ctx_ndlp) {
  2913. rc = -ENOMEM;
  2914. goto out;
  2915. }
  2916. mbox->vport = vport;
  2917. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2918. if (rc == MBX_NOT_FINISHED) {
  2919. rc = -ENODEV;
  2920. lpfc_nlp_put(fc_ndlp);
  2921. goto out;
  2922. }
  2923. /* Success path. Exit. */
  2924. lpfc_nlp_set_state(vport, fc_ndlp,
  2925. NLP_STE_REG_LOGIN_ISSUE);
  2926. return 0;
  2927. out:
  2928. lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
  2929. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  2930. "0938 %s: failed to format reg_login "
  2931. "Data: x%x x%x x%x x%x\n", __func__,
  2932. fc_ndlp->nlp_DID, fc_ndlp->nlp_state,
  2933. fc_ndlp->nlp_flag, fc_ndlp->nlp_rpi);
  2934. return rc;
  2935. }
  2936. /**
  2937. * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
  2938. * @phba: pointer to lpfc hba data structure.
  2939. * @cmdiocb: pointer to lpfc command iocb data structure.
  2940. * @rspiocb: pointer to lpfc response iocb data structure.
  2941. *
  2942. * This routine is a generic completion callback function for Discovery ELS cmd.
  2943. * Currently used by the ELS command issuing routines for the ELS State Change
  2944. * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
  2945. * These commands will be retried once only for ELS timeout errors.
  2946. **/
  2947. static void
  2948. lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  2949. struct lpfc_iocbq *rspiocb)
  2950. {
  2951. struct lpfc_vport *vport = cmdiocb->vport;
  2952. IOCB_t *irsp;
  2953. struct lpfc_els_rdf_rsp *prdf;
  2954. struct lpfc_dmabuf *pcmd, *prsp;
  2955. u32 *pdata;
  2956. u32 cmd;
  2957. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  2958. u32 ulp_status, ulp_word4, tmo, did, iotag;
  2959. ulp_status = get_job_ulpstatus(phba, rspiocb);
  2960. ulp_word4 = get_job_word4(phba, rspiocb);
  2961. did = get_job_els_rsp64_did(phba, cmdiocb);
  2962. if (phba->sli_rev == LPFC_SLI_REV4) {
  2963. tmo = get_wqe_tmo(cmdiocb);
  2964. iotag = get_wqe_reqtag(cmdiocb);
  2965. } else {
  2966. irsp = &rspiocb->iocb;
  2967. tmo = irsp->ulpTimeout;
  2968. iotag = irsp->ulpIoTag;
  2969. }
  2970. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2971. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  2972. ulp_status, ulp_word4, did);
  2973. /* ELS cmd tag <ulpIoTag> completes */
  2974. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
  2975. "0217 ELS cmd tag x%x completes Data: x%x x%x x%x x%x\n",
  2976. iotag, ulp_status, ulp_word4, tmo, cmdiocb->retry);
  2977. pcmd = cmdiocb->cmd_dmabuf;
  2978. if (!pcmd)
  2979. goto out;
  2980. pdata = (u32 *)pcmd->virt;
  2981. if (!pdata)
  2982. goto out;
  2983. cmd = *pdata;
  2984. /* Only 1 retry for ELS Timeout only */
  2985. if (ulp_status == IOSTAT_LOCAL_REJECT &&
  2986. ((ulp_word4 & IOERR_PARAM_MASK) ==
  2987. IOERR_SEQUENCE_TIMEOUT)) {
  2988. cmdiocb->retry++;
  2989. if (cmdiocb->retry <= 1) {
  2990. switch (cmd) {
  2991. case ELS_CMD_SCR:
  2992. lpfc_issue_els_scr(vport, cmdiocb->retry);
  2993. break;
  2994. case ELS_CMD_EDC:
  2995. lpfc_issue_els_edc(vport, cmdiocb->retry);
  2996. break;
  2997. case ELS_CMD_RDF:
  2998. lpfc_issue_els_rdf(vport, cmdiocb->retry);
  2999. break;
  3000. }
  3001. goto out;
  3002. }
  3003. phba->fc_stat.elsRetryExceeded++;
  3004. }
  3005. if (cmd == ELS_CMD_EDC) {
  3006. /* must be called before checking uplStatus and returning */
  3007. lpfc_cmpl_els_edc(phba, cmdiocb, rspiocb);
  3008. return;
  3009. }
  3010. if (ulp_status) {
  3011. /* ELS discovery cmd completes with error */
  3012. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
  3013. "4203 ELS cmd x%x error: x%x x%X\n", cmd,
  3014. ulp_status, ulp_word4);
  3015. goto out;
  3016. }
  3017. /* The RDF response doesn't have any impact on the running driver
  3018. * but the notification descriptors are dumped here for support.
  3019. */
  3020. if (cmd == ELS_CMD_RDF) {
  3021. int i;
  3022. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  3023. if (!prsp)
  3024. goto out;
  3025. prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
  3026. if (!prdf)
  3027. goto out;
  3028. for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
  3029. i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
  3030. lpfc_printf_vlog(vport, KERN_INFO,
  3031. LOG_ELS | LOG_CGN_MGMT,
  3032. "4677 Fabric RDF Notification Grant "
  3033. "Data: 0x%08x Reg: %x %x\n",
  3034. be32_to_cpu(
  3035. prdf->reg_d1.desc_tags[i]),
  3036. phba->cgn_reg_signal,
  3037. phba->cgn_reg_fpin);
  3038. }
  3039. out:
  3040. /* Check to see if link went down during discovery */
  3041. lpfc_els_chk_latt(vport);
  3042. lpfc_els_free_iocb(phba, cmdiocb);
  3043. lpfc_nlp_put(ndlp);
  3044. return;
  3045. }
  3046. /**
  3047. * lpfc_issue_els_scr - Issue a scr to an node on a vport
  3048. * @vport: pointer to a host virtual N_Port data structure.
  3049. * @retry: retry counter for the command IOCB.
  3050. *
  3051. * This routine issues a State Change Request (SCR) to a fabric node
  3052. * on a @vport. The remote node is Fabric Controller (0xfffffd). It
  3053. * first search the @vport node list to find the matching ndlp. If no such
  3054. * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
  3055. * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
  3056. * routine is invoked to send the SCR IOCB.
  3057. *
  3058. * Note that the ndlp reference count will be incremented by 1 for holding the
  3059. * ndlp and the reference to ndlp will be stored into the ndlp field of
  3060. * the IOCB for the completion callback function to the SCR ELS command.
  3061. *
  3062. * Return code
  3063. * 0 - Successfully issued scr command
  3064. * 1 - Failed to issue scr command
  3065. **/
  3066. int
  3067. lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
  3068. {
  3069. int rc = 0;
  3070. struct lpfc_hba *phba = vport->phba;
  3071. struct lpfc_iocbq *elsiocb;
  3072. uint8_t *pcmd;
  3073. uint16_t cmdsize;
  3074. struct lpfc_nodelist *ndlp;
  3075. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  3076. ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
  3077. if (!ndlp) {
  3078. ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
  3079. if (!ndlp)
  3080. return 1;
  3081. lpfc_enqueue_node(vport, ndlp);
  3082. }
  3083. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  3084. ndlp->nlp_DID, ELS_CMD_SCR);
  3085. if (!elsiocb)
  3086. return 1;
  3087. if (phba->sli_rev == LPFC_SLI_REV4) {
  3088. rc = lpfc_reg_fab_ctrl_node(vport, ndlp);
  3089. if (rc) {
  3090. lpfc_els_free_iocb(phba, elsiocb);
  3091. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  3092. "0937 %s: Failed to reg fc node, rc %d\n",
  3093. __func__, rc);
  3094. return 1;
  3095. }
  3096. }
  3097. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  3098. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  3099. pcmd += sizeof(uint32_t);
  3100. /* For SCR, remainder of payload is SCR parameter page */
  3101. memset(pcmd, 0, sizeof(SCR));
  3102. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  3103. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3104. "Issue SCR: did:x%x",
  3105. ndlp->nlp_DID, 0, 0);
  3106. phba->fc_stat.elsXmitSCR++;
  3107. elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
  3108. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  3109. if (!elsiocb->ndlp) {
  3110. lpfc_els_free_iocb(phba, elsiocb);
  3111. return 1;
  3112. }
  3113. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3114. "Issue SCR: did:x%x refcnt %d",
  3115. ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
  3116. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3117. if (rc == IOCB_ERROR) {
  3118. lpfc_els_free_iocb(phba, elsiocb);
  3119. lpfc_nlp_put(ndlp);
  3120. return 1;
  3121. }
  3122. return 0;
  3123. }
  3124. /**
  3125. * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
  3126. * or the other nport (pt2pt).
  3127. * @vport: pointer to a host virtual N_Port data structure.
  3128. * @retry: number of retries to the command IOCB.
  3129. *
  3130. * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
  3131. * when connected to a fabric, or to the remote port when connected
  3132. * in point-to-point mode. When sent to the Fabric Controller, it will
  3133. * replay the RSCN to registered recipients.
  3134. *
  3135. * Note that the ndlp reference count will be incremented by 1 for holding the
  3136. * ndlp and the reference to ndlp will be stored into the ndlp field of
  3137. * the IOCB for the completion callback function to the RSCN ELS command.
  3138. *
  3139. * Return code
  3140. * 0 - Successfully issued RSCN command
  3141. * 1 - Failed to issue RSCN command
  3142. **/
  3143. int
  3144. lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
  3145. {
  3146. int rc = 0;
  3147. struct lpfc_hba *phba = vport->phba;
  3148. struct lpfc_iocbq *elsiocb;
  3149. struct lpfc_nodelist *ndlp;
  3150. struct {
  3151. struct fc_els_rscn rscn;
  3152. struct fc_els_rscn_page portid;
  3153. } *event;
  3154. uint32_t nportid;
  3155. uint16_t cmdsize = sizeof(*event);
  3156. /* Not supported for private loop */
  3157. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
  3158. !(vport->fc_flag & FC_PUBLIC_LOOP))
  3159. return 1;
  3160. if (vport->fc_flag & FC_PT2PT) {
  3161. /* find any mapped nport - that would be the other nport */
  3162. ndlp = lpfc_findnode_mapped(vport);
  3163. if (!ndlp)
  3164. return 1;
  3165. } else {
  3166. nportid = FC_FID_FCTRL;
  3167. /* find the fabric controller node */
  3168. ndlp = lpfc_findnode_did(vport, nportid);
  3169. if (!ndlp) {
  3170. /* if one didn't exist, make one */
  3171. ndlp = lpfc_nlp_init(vport, nportid);
  3172. if (!ndlp)
  3173. return 1;
  3174. lpfc_enqueue_node(vport, ndlp);
  3175. }
  3176. }
  3177. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  3178. ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
  3179. if (!elsiocb)
  3180. return 1;
  3181. event = elsiocb->cmd_dmabuf->virt;
  3182. event->rscn.rscn_cmd = ELS_RSCN;
  3183. event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
  3184. event->rscn.rscn_plen = cpu_to_be16(cmdsize);
  3185. nportid = vport->fc_myDID;
  3186. /* appears that page flags must be 0 for fabric to broadcast RSCN */
  3187. event->portid.rscn_page_flags = 0;
  3188. event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
  3189. event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
  3190. event->portid.rscn_fid[2] = nportid & 0x000000FF;
  3191. phba->fc_stat.elsXmitRSCN++;
  3192. elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd;
  3193. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  3194. if (!elsiocb->ndlp) {
  3195. lpfc_els_free_iocb(phba, elsiocb);
  3196. return 1;
  3197. }
  3198. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3199. "Issue RSCN: did:x%x",
  3200. ndlp->nlp_DID, 0, 0);
  3201. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3202. if (rc == IOCB_ERROR) {
  3203. lpfc_els_free_iocb(phba, elsiocb);
  3204. lpfc_nlp_put(ndlp);
  3205. return 1;
  3206. }
  3207. return 0;
  3208. }
  3209. /**
  3210. * lpfc_issue_els_farpr - Issue a farp to an node on a vport
  3211. * @vport: pointer to a host virtual N_Port data structure.
  3212. * @nportid: N_Port identifier to the remote node.
  3213. * @retry: number of retries to the command IOCB.
  3214. *
  3215. * This routine issues a Fibre Channel Address Resolution Response
  3216. * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
  3217. * is passed into the function. It first search the @vport node list to find
  3218. * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
  3219. * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
  3220. * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
  3221. *
  3222. * Note that the ndlp reference count will be incremented by 1 for holding the
  3223. * ndlp and the reference to ndlp will be stored into the ndlp field of
  3224. * the IOCB for the completion callback function to the FARPR ELS command.
  3225. *
  3226. * Return code
  3227. * 0 - Successfully issued farpr command
  3228. * 1 - Failed to issue farpr command
  3229. **/
  3230. static int
  3231. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  3232. {
  3233. int rc = 0;
  3234. struct lpfc_hba *phba = vport->phba;
  3235. struct lpfc_iocbq *elsiocb;
  3236. FARP *fp;
  3237. uint8_t *pcmd;
  3238. uint32_t *lp;
  3239. uint16_t cmdsize;
  3240. struct lpfc_nodelist *ondlp;
  3241. struct lpfc_nodelist *ndlp;
  3242. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  3243. ndlp = lpfc_findnode_did(vport, nportid);
  3244. if (!ndlp) {
  3245. ndlp = lpfc_nlp_init(vport, nportid);
  3246. if (!ndlp)
  3247. return 1;
  3248. lpfc_enqueue_node(vport, ndlp);
  3249. }
  3250. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  3251. ndlp->nlp_DID, ELS_CMD_FARPR);
  3252. if (!elsiocb)
  3253. return 1;
  3254. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  3255. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  3256. pcmd += sizeof(uint32_t);
  3257. /* Fill in FARPR payload */
  3258. fp = (FARP *) (pcmd);
  3259. memset(fp, 0, sizeof(FARP));
  3260. lp = (uint32_t *) pcmd;
  3261. *lp++ = be32_to_cpu(nportid);
  3262. *lp++ = be32_to_cpu(vport->fc_myDID);
  3263. fp->Rflags = 0;
  3264. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  3265. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  3266. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  3267. ondlp = lpfc_findnode_did(vport, nportid);
  3268. if (ondlp) {
  3269. memcpy(&fp->OportName, &ondlp->nlp_portname,
  3270. sizeof(struct lpfc_name));
  3271. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  3272. sizeof(struct lpfc_name));
  3273. }
  3274. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3275. "Issue FARPR: did:x%x",
  3276. ndlp->nlp_DID, 0, 0);
  3277. phba->fc_stat.elsXmitFARPR++;
  3278. elsiocb->cmd_cmpl = lpfc_cmpl_els_cmd;
  3279. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  3280. if (!elsiocb->ndlp) {
  3281. lpfc_els_free_iocb(phba, elsiocb);
  3282. return 1;
  3283. }
  3284. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3285. if (rc == IOCB_ERROR) {
  3286. /* The additional lpfc_nlp_put will cause the following
  3287. * lpfc_els_free_iocb routine to trigger the release of
  3288. * the node.
  3289. */
  3290. lpfc_els_free_iocb(phba, elsiocb);
  3291. lpfc_nlp_put(ndlp);
  3292. return 1;
  3293. }
  3294. /* This will cause the callback-function lpfc_cmpl_els_cmd to
  3295. * trigger the release of the node.
  3296. */
  3297. /* Don't release reference count as RDF is likely outstanding */
  3298. return 0;
  3299. }
  3300. /**
  3301. * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
  3302. * @vport: pointer to a host virtual N_Port data structure.
  3303. * @retry: retry counter for the command IOCB.
  3304. *
  3305. * This routine issues an ELS RDF to the Fabric Controller to register
  3306. * for diagnostic functions.
  3307. *
  3308. * Note that the ndlp reference count will be incremented by 1 for holding the
  3309. * ndlp and the reference to ndlp will be stored into the ndlp field of
  3310. * the IOCB for the completion callback function to the RDF ELS command.
  3311. *
  3312. * Return code
  3313. * 0 - Successfully issued rdf command
  3314. * 1 - Failed to issue rdf command
  3315. **/
  3316. int
  3317. lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
  3318. {
  3319. struct lpfc_hba *phba = vport->phba;
  3320. struct lpfc_iocbq *elsiocb;
  3321. struct lpfc_els_rdf_req *prdf;
  3322. struct lpfc_nodelist *ndlp;
  3323. uint16_t cmdsize;
  3324. int rc;
  3325. cmdsize = sizeof(*prdf);
  3326. ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
  3327. if (!ndlp) {
  3328. ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
  3329. if (!ndlp)
  3330. return -ENODEV;
  3331. lpfc_enqueue_node(vport, ndlp);
  3332. }
  3333. /* RDF ELS is not required on an NPIV VN_Port. */
  3334. if (vport->port_type == LPFC_NPIV_PORT)
  3335. return -EACCES;
  3336. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  3337. ndlp->nlp_DID, ELS_CMD_RDF);
  3338. if (!elsiocb)
  3339. return -ENOMEM;
  3340. /* Configure the payload for the supported FPIN events. */
  3341. prdf = (struct lpfc_els_rdf_req *)elsiocb->cmd_dmabuf->virt;
  3342. memset(prdf, 0, cmdsize);
  3343. prdf->rdf.fpin_cmd = ELS_RDF;
  3344. prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
  3345. sizeof(struct fc_els_rdf));
  3346. prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
  3347. prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
  3348. FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
  3349. prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
  3350. prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
  3351. prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
  3352. prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
  3353. prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
  3354. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
  3355. "6444 Xmit RDF to remote NPORT x%x Reg: %x %x\n",
  3356. ndlp->nlp_DID, phba->cgn_reg_signal,
  3357. phba->cgn_reg_fpin);
  3358. phba->cgn_fpin_frequency = LPFC_FPIN_INIT_FREQ;
  3359. elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
  3360. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  3361. if (!elsiocb->ndlp) {
  3362. lpfc_els_free_iocb(phba, elsiocb);
  3363. return -EIO;
  3364. }
  3365. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3366. "Issue RDF: did:x%x refcnt %d",
  3367. ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
  3368. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3369. if (rc == IOCB_ERROR) {
  3370. lpfc_els_free_iocb(phba, elsiocb);
  3371. lpfc_nlp_put(ndlp);
  3372. return -EIO;
  3373. }
  3374. return 0;
  3375. }
  3376. /**
  3377. * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric.
  3378. * @vport: pointer to a host virtual N_Port data structure.
  3379. * @cmdiocb: pointer to lpfc command iocb data structure.
  3380. * @ndlp: pointer to a node-list data structure.
  3381. *
  3382. * A received RDF implies a possible change to fabric supported diagnostic
  3383. * functions. This routine sends LS_ACC and then has the Nx_Port issue a new
  3384. * RDF request to reregister for supported diagnostic functions.
  3385. *
  3386. * Return code
  3387. * 0 - Success
  3388. * -EIO - Failed to process received RDF
  3389. **/
  3390. static int
  3391. lpfc_els_rcv_rdf(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3392. struct lpfc_nodelist *ndlp)
  3393. {
  3394. /* Send LS_ACC */
  3395. if (lpfc_els_rsp_acc(vport, ELS_CMD_RDF, cmdiocb, ndlp, NULL)) {
  3396. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
  3397. "1623 Failed to RDF_ACC from x%x for x%x\n",
  3398. ndlp->nlp_DID, vport->fc_myDID);
  3399. return -EIO;
  3400. }
  3401. /* Issue new RDF for reregistering */
  3402. if (lpfc_issue_els_rdf(vport, 0)) {
  3403. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
  3404. "2623 Failed to re register RDF for x%x\n",
  3405. vport->fc_myDID);
  3406. return -EIO;
  3407. }
  3408. return 0;
  3409. }
  3410. /**
  3411. * lpfc_least_capable_settings - helper function for EDC rsp processing
  3412. * @phba: pointer to lpfc hba data structure.
  3413. * @pcgd: pointer to congestion detection descriptor in EDC rsp.
  3414. *
  3415. * This helper routine determines the least capable setting for
  3416. * congestion signals, signal freq, including scale, from the
  3417. * congestion detection descriptor in the EDC rsp. The routine
  3418. * sets @phba values in preparation for a set_featues mailbox.
  3419. **/
  3420. static void
  3421. lpfc_least_capable_settings(struct lpfc_hba *phba,
  3422. struct fc_diag_cg_sig_desc *pcgd)
  3423. {
  3424. u32 rsp_sig_cap = 0, drv_sig_cap = 0;
  3425. u32 rsp_sig_freq_cyc = 0, rsp_sig_freq_scale = 0;
  3426. /* Get rsp signal and frequency capabilities. */
  3427. rsp_sig_cap = be32_to_cpu(pcgd->xmt_signal_capability);
  3428. rsp_sig_freq_cyc = be16_to_cpu(pcgd->xmt_signal_frequency.count);
  3429. rsp_sig_freq_scale = be16_to_cpu(pcgd->xmt_signal_frequency.units);
  3430. /* If the Fport does not support signals. Set FPIN only */
  3431. if (rsp_sig_cap == EDC_CG_SIG_NOTSUPPORTED)
  3432. goto out_no_support;
  3433. /* Apply the xmt scale to the xmt cycle to get the correct frequency.
  3434. * Adapter default is 100 millisSeconds. Convert all xmt cycle values
  3435. * to milliSeconds.
  3436. */
  3437. switch (rsp_sig_freq_scale) {
  3438. case EDC_CG_SIGFREQ_SEC:
  3439. rsp_sig_freq_cyc *= MSEC_PER_SEC;
  3440. break;
  3441. case EDC_CG_SIGFREQ_MSEC:
  3442. rsp_sig_freq_cyc = 1;
  3443. break;
  3444. default:
  3445. goto out_no_support;
  3446. }
  3447. /* Convenient shorthand. */
  3448. drv_sig_cap = phba->cgn_reg_signal;
  3449. /* Choose the least capable frequency. */
  3450. if (rsp_sig_freq_cyc > phba->cgn_sig_freq)
  3451. phba->cgn_sig_freq = rsp_sig_freq_cyc;
  3452. /* Should be some common signals support. Settle on least capable
  3453. * signal and adjust FPIN values. Initialize defaults to ease the
  3454. * decision.
  3455. */
  3456. phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
  3457. phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
  3458. if (rsp_sig_cap == EDC_CG_SIG_WARN_ONLY &&
  3459. (drv_sig_cap == EDC_CG_SIG_WARN_ONLY ||
  3460. drv_sig_cap == EDC_CG_SIG_WARN_ALARM)) {
  3461. phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
  3462. phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
  3463. }
  3464. if (rsp_sig_cap == EDC_CG_SIG_WARN_ALARM) {
  3465. if (drv_sig_cap == EDC_CG_SIG_WARN_ALARM) {
  3466. phba->cgn_reg_signal = EDC_CG_SIG_WARN_ALARM;
  3467. phba->cgn_reg_fpin = LPFC_CGN_FPIN_NONE;
  3468. }
  3469. if (drv_sig_cap == EDC_CG_SIG_WARN_ONLY) {
  3470. phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY;
  3471. phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN;
  3472. }
  3473. }
  3474. /* We are NOT recording signal frequency in congestion info buffer */
  3475. return;
  3476. out_no_support:
  3477. phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
  3478. phba->cgn_sig_freq = 0;
  3479. phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
  3480. }
  3481. DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
  3482. FC_LS_TLV_DTAG_INIT);
  3483. /**
  3484. * lpfc_cmpl_els_edc - Completion callback function for EDC
  3485. * @phba: pointer to lpfc hba data structure.
  3486. * @cmdiocb: pointer to lpfc command iocb data structure.
  3487. * @rspiocb: pointer to lpfc response iocb data structure.
  3488. *
  3489. * This routine is the completion callback function for issuing the Exchange
  3490. * Diagnostic Capabilities (EDC) command. The driver issues an EDC to
  3491. * notify the FPort of its Congestion and Link Fault capabilities. This
  3492. * routine parses the FPort's response and decides on the least common
  3493. * values applicable to both FPort and NPort for Warnings and Alarms that
  3494. * are communicated via hardware signals.
  3495. **/
  3496. static void
  3497. lpfc_cmpl_els_edc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3498. struct lpfc_iocbq *rspiocb)
  3499. {
  3500. IOCB_t *irsp_iocb;
  3501. struct fc_els_edc_resp *edc_rsp;
  3502. struct fc_tlv_desc *tlv;
  3503. struct fc_diag_cg_sig_desc *pcgd;
  3504. struct fc_diag_lnkflt_desc *plnkflt;
  3505. struct lpfc_dmabuf *pcmd, *prsp;
  3506. const char *dtag_nm;
  3507. u32 *pdata, dtag;
  3508. int desc_cnt = 0, bytes_remain;
  3509. bool rcv_cap_desc = false;
  3510. struct lpfc_nodelist *ndlp;
  3511. u32 ulp_status, ulp_word4, tmo, did, iotag;
  3512. ndlp = cmdiocb->ndlp;
  3513. ulp_status = get_job_ulpstatus(phba, rspiocb);
  3514. ulp_word4 = get_job_word4(phba, rspiocb);
  3515. did = get_job_els_rsp64_did(phba, rspiocb);
  3516. if (phba->sli_rev == LPFC_SLI_REV4) {
  3517. tmo = get_wqe_tmo(rspiocb);
  3518. iotag = get_wqe_reqtag(rspiocb);
  3519. } else {
  3520. irsp_iocb = &rspiocb->iocb;
  3521. tmo = irsp_iocb->ulpTimeout;
  3522. iotag = irsp_iocb->ulpIoTag;
  3523. }
  3524. lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
  3525. "EDC cmpl: status:x%x/x%x did:x%x",
  3526. ulp_status, ulp_word4, did);
  3527. /* ELS cmd tag <ulpIoTag> completes */
  3528. lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
  3529. "4201 EDC cmd tag x%x completes Data: x%x x%x x%x\n",
  3530. iotag, ulp_status, ulp_word4, tmo);
  3531. pcmd = cmdiocb->cmd_dmabuf;
  3532. if (!pcmd)
  3533. goto out;
  3534. pdata = (u32 *)pcmd->virt;
  3535. if (!pdata)
  3536. goto out;
  3537. /* Need to clear signal values, send features MB and RDF with FPIN. */
  3538. if (ulp_status)
  3539. goto out;
  3540. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  3541. if (!prsp)
  3542. goto out;
  3543. edc_rsp = prsp->virt;
  3544. if (!edc_rsp)
  3545. goto out;
  3546. /* ELS cmd tag <ulpIoTag> completes */
  3547. lpfc_printf_log(phba, KERN_INFO,
  3548. LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
  3549. "4676 Fabric EDC Rsp: "
  3550. "0x%02x, 0x%08x\n",
  3551. edc_rsp->acc_hdr.la_cmd,
  3552. be32_to_cpu(edc_rsp->desc_list_len));
  3553. /*
  3554. * Payload length in bytes is the response descriptor list
  3555. * length minus the 12 bytes of Link Service Request
  3556. * Information descriptor in the reply.
  3557. */
  3558. bytes_remain = be32_to_cpu(edc_rsp->desc_list_len) -
  3559. sizeof(struct fc_els_lsri_desc);
  3560. if (bytes_remain <= 0)
  3561. goto out;
  3562. tlv = edc_rsp->desc;
  3563. /*
  3564. * cycle through EDC diagnostic descriptors to find the
  3565. * congestion signaling capability descriptor
  3566. */
  3567. while (bytes_remain) {
  3568. if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
  3569. lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
  3570. "6461 Truncated TLV hdr on "
  3571. "Diagnostic descriptor[%d]\n",
  3572. desc_cnt);
  3573. goto out;
  3574. }
  3575. dtag = be32_to_cpu(tlv->desc_tag);
  3576. switch (dtag) {
  3577. case ELS_DTAG_LNK_FAULT_CAP:
  3578. if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
  3579. FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
  3580. sizeof(struct fc_diag_lnkflt_desc)) {
  3581. lpfc_printf_log(phba, KERN_WARNING,
  3582. LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
  3583. "6462 Truncated Link Fault Diagnostic "
  3584. "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
  3585. desc_cnt, bytes_remain,
  3586. FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
  3587. sizeof(struct fc_diag_lnkflt_desc));
  3588. goto out;
  3589. }
  3590. plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
  3591. lpfc_printf_log(phba, KERN_INFO,
  3592. LOG_ELS | LOG_LDS_EVENT,
  3593. "4617 Link Fault Desc Data: 0x%08x 0x%08x "
  3594. "0x%08x 0x%08x 0x%08x\n",
  3595. be32_to_cpu(plnkflt->desc_tag),
  3596. be32_to_cpu(plnkflt->desc_len),
  3597. be32_to_cpu(
  3598. plnkflt->degrade_activate_threshold),
  3599. be32_to_cpu(
  3600. plnkflt->degrade_deactivate_threshold),
  3601. be32_to_cpu(plnkflt->fec_degrade_interval));
  3602. break;
  3603. case ELS_DTAG_CG_SIGNAL_CAP:
  3604. if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
  3605. FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
  3606. sizeof(struct fc_diag_cg_sig_desc)) {
  3607. lpfc_printf_log(
  3608. phba, KERN_WARNING, LOG_CGN_MGMT,
  3609. "6463 Truncated Cgn Signal Diagnostic "
  3610. "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
  3611. desc_cnt, bytes_remain,
  3612. FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
  3613. sizeof(struct fc_diag_cg_sig_desc));
  3614. goto out;
  3615. }
  3616. pcgd = (struct fc_diag_cg_sig_desc *)tlv;
  3617. lpfc_printf_log(
  3618. phba, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
  3619. "4616 CGN Desc Data: 0x%08x 0x%08x "
  3620. "0x%08x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x\n",
  3621. be32_to_cpu(pcgd->desc_tag),
  3622. be32_to_cpu(pcgd->desc_len),
  3623. be32_to_cpu(pcgd->xmt_signal_capability),
  3624. be16_to_cpu(pcgd->xmt_signal_frequency.count),
  3625. be16_to_cpu(pcgd->xmt_signal_frequency.units),
  3626. be32_to_cpu(pcgd->rcv_signal_capability),
  3627. be16_to_cpu(pcgd->rcv_signal_frequency.count),
  3628. be16_to_cpu(pcgd->rcv_signal_frequency.units));
  3629. /* Compare driver and Fport capabilities and choose
  3630. * least common.
  3631. */
  3632. lpfc_least_capable_settings(phba, pcgd);
  3633. rcv_cap_desc = true;
  3634. break;
  3635. default:
  3636. dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
  3637. lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
  3638. "4919 unknown Diagnostic "
  3639. "Descriptor[%d]: tag x%x (%s)\n",
  3640. desc_cnt, dtag, dtag_nm);
  3641. }
  3642. bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
  3643. tlv = fc_tlv_next_desc(tlv);
  3644. desc_cnt++;
  3645. }
  3646. out:
  3647. if (!rcv_cap_desc) {
  3648. phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
  3649. phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
  3650. phba->cgn_sig_freq = 0;
  3651. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_CGN_MGMT,
  3652. "4202 EDC rsp error - sending RDF "
  3653. "for FPIN only.\n");
  3654. }
  3655. lpfc_config_cgn_signal(phba);
  3656. /* Check to see if link went down during discovery */
  3657. lpfc_els_chk_latt(phba->pport);
  3658. lpfc_debugfs_disc_trc(phba->pport, LPFC_DISC_TRC_ELS_CMD,
  3659. "EDC Cmpl: did:x%x refcnt %d",
  3660. ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
  3661. lpfc_els_free_iocb(phba, cmdiocb);
  3662. lpfc_nlp_put(ndlp);
  3663. }
  3664. static void
  3665. lpfc_format_edc_lft_desc(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
  3666. {
  3667. struct fc_diag_lnkflt_desc *lft = (struct fc_diag_lnkflt_desc *)tlv;
  3668. lft->desc_tag = cpu_to_be32(ELS_DTAG_LNK_FAULT_CAP);
  3669. lft->desc_len = cpu_to_be32(
  3670. FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_lnkflt_desc));
  3671. lft->degrade_activate_threshold =
  3672. cpu_to_be32(phba->degrade_activate_threshold);
  3673. lft->degrade_deactivate_threshold =
  3674. cpu_to_be32(phba->degrade_deactivate_threshold);
  3675. lft->fec_degrade_interval = cpu_to_be32(phba->fec_degrade_interval);
  3676. }
  3677. static void
  3678. lpfc_format_edc_cgn_desc(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
  3679. {
  3680. struct fc_diag_cg_sig_desc *cgd = (struct fc_diag_cg_sig_desc *)tlv;
  3681. /* We are assuming cgd was zero'ed before calling this routine */
  3682. /* Configure the congestion detection capability */
  3683. cgd->desc_tag = cpu_to_be32(ELS_DTAG_CG_SIGNAL_CAP);
  3684. /* Descriptor len doesn't include the tag or len fields. */
  3685. cgd->desc_len = cpu_to_be32(
  3686. FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_cg_sig_desc));
  3687. /* xmt_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
  3688. * xmt_signal_frequency.count already set to 0.
  3689. * xmt_signal_frequency.units already set to 0.
  3690. */
  3691. if (phba->cmf_active_mode == LPFC_CFG_OFF) {
  3692. /* rcv_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
  3693. * rcv_signal_frequency.count already set to 0.
  3694. * rcv_signal_frequency.units already set to 0.
  3695. */
  3696. phba->cgn_sig_freq = 0;
  3697. return;
  3698. }
  3699. switch (phba->cgn_reg_signal) {
  3700. case EDC_CG_SIG_WARN_ONLY:
  3701. cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ONLY);
  3702. break;
  3703. case EDC_CG_SIG_WARN_ALARM:
  3704. cgd->rcv_signal_capability = cpu_to_be32(EDC_CG_SIG_WARN_ALARM);
  3705. break;
  3706. default:
  3707. /* rcv_signal_capability left 0 thus no support */
  3708. break;
  3709. }
  3710. /* We start negotiation with lpfc_fabric_cgn_frequency, after
  3711. * the completion we settle on the higher frequency.
  3712. */
  3713. cgd->rcv_signal_frequency.count =
  3714. cpu_to_be16(lpfc_fabric_cgn_frequency);
  3715. cgd->rcv_signal_frequency.units =
  3716. cpu_to_be16(EDC_CG_SIGFREQ_MSEC);
  3717. }
  3718. static bool
  3719. lpfc_link_is_lds_capable(struct lpfc_hba *phba)
  3720. {
  3721. if (!(phba->lmt & LMT_64Gb))
  3722. return false;
  3723. if (phba->sli_rev != LPFC_SLI_REV4)
  3724. return false;
  3725. if (phba->sli4_hba.conf_trunk) {
  3726. if (phba->trunk_link.phy_lnk_speed == LPFC_USER_LINK_SPEED_64G)
  3727. return true;
  3728. } else if (phba->fc_linkspeed == LPFC_LINK_SPEED_64GHZ) {
  3729. return true;
  3730. }
  3731. return false;
  3732. }
  3733. /**
  3734. * lpfc_issue_els_edc - Exchange Diagnostic Capabilities with the fabric.
  3735. * @vport: pointer to a host virtual N_Port data structure.
  3736. * @retry: retry counter for the command iocb.
  3737. *
  3738. * This routine issues an ELS EDC to the F-Port Controller to communicate
  3739. * this N_Port's support of hardware signals in its Congestion
  3740. * Capabilities Descriptor.
  3741. *
  3742. * Note: This routine does not check if one or more signals are
  3743. * set in the cgn_reg_signal parameter. The caller makes the
  3744. * decision to enforce cgn_reg_signal as nonzero or zero depending
  3745. * on the conditions. During Fabric requests, the driver
  3746. * requires cgn_reg_signals to be nonzero. But a dynamic request
  3747. * to set the congestion mode to OFF from Monitor or Manage
  3748. * would correctly issue an EDC with no signals enabled to
  3749. * turn off switch functionality and then update the FW.
  3750. *
  3751. * Return code
  3752. * 0 - Successfully issued edc command
  3753. * 1 - Failed to issue edc command
  3754. **/
  3755. int
  3756. lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry)
  3757. {
  3758. struct lpfc_hba *phba = vport->phba;
  3759. struct lpfc_iocbq *elsiocb;
  3760. struct fc_els_edc *edc_req;
  3761. struct fc_tlv_desc *tlv;
  3762. u16 cmdsize;
  3763. struct lpfc_nodelist *ndlp;
  3764. u8 *pcmd = NULL;
  3765. u32 cgn_desc_size, lft_desc_size;
  3766. int rc;
  3767. if (vport->port_type == LPFC_NPIV_PORT)
  3768. return -EACCES;
  3769. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  3770. if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
  3771. return -ENODEV;
  3772. cgn_desc_size = (phba->cgn_init_reg_signal) ?
  3773. sizeof(struct fc_diag_cg_sig_desc) : 0;
  3774. lft_desc_size = (lpfc_link_is_lds_capable(phba)) ?
  3775. sizeof(struct fc_diag_lnkflt_desc) : 0;
  3776. cmdsize = cgn_desc_size + lft_desc_size;
  3777. /* Skip EDC if no applicable descriptors */
  3778. if (!cmdsize)
  3779. goto try_rdf;
  3780. cmdsize += sizeof(struct fc_els_edc);
  3781. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  3782. ndlp->nlp_DID, ELS_CMD_EDC);
  3783. if (!elsiocb)
  3784. goto try_rdf;
  3785. /* Configure the payload for the supported Diagnostics capabilities. */
  3786. pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
  3787. memset(pcmd, 0, cmdsize);
  3788. edc_req = (struct fc_els_edc *)pcmd;
  3789. edc_req->desc_len = cpu_to_be32(cgn_desc_size + lft_desc_size);
  3790. edc_req->edc_cmd = ELS_EDC;
  3791. tlv = edc_req->desc;
  3792. if (cgn_desc_size) {
  3793. lpfc_format_edc_cgn_desc(phba, tlv);
  3794. phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
  3795. tlv = fc_tlv_next_desc(tlv);
  3796. }
  3797. if (lft_desc_size)
  3798. lpfc_format_edc_lft_desc(phba, tlv);
  3799. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_CGN_MGMT,
  3800. "4623 Xmit EDC to remote "
  3801. "NPORT x%x reg_sig x%x reg_fpin:x%x\n",
  3802. ndlp->nlp_DID, phba->cgn_reg_signal,
  3803. phba->cgn_reg_fpin);
  3804. elsiocb->cmd_cmpl = lpfc_cmpl_els_disc_cmd;
  3805. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  3806. if (!elsiocb->ndlp) {
  3807. lpfc_els_free_iocb(phba, elsiocb);
  3808. return -EIO;
  3809. }
  3810. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3811. "Issue EDC: did:x%x refcnt %d",
  3812. ndlp->nlp_DID, kref_read(&ndlp->kref), 0);
  3813. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  3814. if (rc == IOCB_ERROR) {
  3815. /* The additional lpfc_nlp_put will cause the following
  3816. * lpfc_els_free_iocb routine to trigger the rlease of
  3817. * the node.
  3818. */
  3819. lpfc_els_free_iocb(phba, elsiocb);
  3820. lpfc_nlp_put(ndlp);
  3821. goto try_rdf;
  3822. }
  3823. return 0;
  3824. try_rdf:
  3825. phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
  3826. phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
  3827. rc = lpfc_issue_els_rdf(vport, 0);
  3828. return rc;
  3829. }
  3830. /**
  3831. * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
  3832. * @vport: pointer to a host virtual N_Port data structure.
  3833. * @nlp: pointer to a node-list data structure.
  3834. *
  3835. * This routine cancels the timer with a delayed IOCB-command retry for
  3836. * a @vport's @ndlp. It stops the timer for the delayed function retrial and
  3837. * removes the ELS retry event if it presents. In addition, if the
  3838. * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
  3839. * commands are sent for the @vport's nodes that require issuing discovery
  3840. * ADISC.
  3841. **/
  3842. void
  3843. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  3844. {
  3845. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3846. struct lpfc_work_evt *evtp;
  3847. if (!(nlp->nlp_flag & NLP_DELAY_TMO))
  3848. return;
  3849. spin_lock_irq(&nlp->lock);
  3850. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  3851. spin_unlock_irq(&nlp->lock);
  3852. del_timer_sync(&nlp->nlp_delayfunc);
  3853. nlp->nlp_last_elscmd = 0;
  3854. if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
  3855. list_del_init(&nlp->els_retry_evt.evt_listp);
  3856. /* Decrement nlp reference count held for the delayed retry */
  3857. evtp = &nlp->els_retry_evt;
  3858. lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
  3859. }
  3860. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  3861. spin_lock_irq(&nlp->lock);
  3862. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  3863. spin_unlock_irq(&nlp->lock);
  3864. if (vport->num_disc_nodes) {
  3865. if (vport->port_state < LPFC_VPORT_READY) {
  3866. /* Check if there are more ADISCs to be sent */
  3867. lpfc_more_adisc(vport);
  3868. } else {
  3869. /* Check if there are more PLOGIs to be sent */
  3870. lpfc_more_plogi(vport);
  3871. if (vport->num_disc_nodes == 0) {
  3872. spin_lock_irq(shost->host_lock);
  3873. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3874. spin_unlock_irq(shost->host_lock);
  3875. lpfc_can_disctmo(vport);
  3876. lpfc_end_rscn(vport);
  3877. }
  3878. }
  3879. }
  3880. }
  3881. return;
  3882. }
  3883. /**
  3884. * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
  3885. * @t: pointer to the timer function associated data (ndlp).
  3886. *
  3887. * This routine is invoked by the ndlp delayed-function timer to check
  3888. * whether there is any pending ELS retry event(s) with the node. If not, it
  3889. * simply returns. Otherwise, if there is at least one ELS delayed event, it
  3890. * adds the delayed events to the HBA work list and invokes the
  3891. * lpfc_worker_wake_up() routine to wake up worker thread to process the
  3892. * event. Note that lpfc_nlp_get() is called before posting the event to
  3893. * the work list to hold reference count of ndlp so that it guarantees the
  3894. * reference to ndlp will still be available when the worker thread gets
  3895. * to the event associated with the ndlp.
  3896. **/
  3897. void
  3898. lpfc_els_retry_delay(struct timer_list *t)
  3899. {
  3900. struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
  3901. struct lpfc_vport *vport = ndlp->vport;
  3902. struct lpfc_hba *phba = vport->phba;
  3903. unsigned long flags;
  3904. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  3905. spin_lock_irqsave(&phba->hbalock, flags);
  3906. if (!list_empty(&evtp->evt_listp)) {
  3907. spin_unlock_irqrestore(&phba->hbalock, flags);
  3908. return;
  3909. }
  3910. /* We need to hold the node by incrementing the reference
  3911. * count until the queued work is done
  3912. */
  3913. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  3914. if (evtp->evt_arg1) {
  3915. evtp->evt = LPFC_EVT_ELS_RETRY;
  3916. list_add_tail(&evtp->evt_listp, &phba->work_list);
  3917. lpfc_worker_wake_up(phba);
  3918. }
  3919. spin_unlock_irqrestore(&phba->hbalock, flags);
  3920. return;
  3921. }
  3922. /**
  3923. * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
  3924. * @ndlp: pointer to a node-list data structure.
  3925. *
  3926. * This routine is the worker-thread handler for processing the @ndlp delayed
  3927. * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
  3928. * the last ELS command from the associated ndlp and invokes the proper ELS
  3929. * function according to the delayed ELS command to retry the command.
  3930. **/
  3931. void
  3932. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  3933. {
  3934. struct lpfc_vport *vport = ndlp->vport;
  3935. uint32_t cmd, retry;
  3936. spin_lock_irq(&ndlp->lock);
  3937. cmd = ndlp->nlp_last_elscmd;
  3938. ndlp->nlp_last_elscmd = 0;
  3939. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  3940. spin_unlock_irq(&ndlp->lock);
  3941. return;
  3942. }
  3943. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  3944. spin_unlock_irq(&ndlp->lock);
  3945. /*
  3946. * If a discovery event readded nlp_delayfunc after timer
  3947. * firing and before processing the timer, cancel the
  3948. * nlp_delayfunc.
  3949. */
  3950. del_timer_sync(&ndlp->nlp_delayfunc);
  3951. retry = ndlp->nlp_retry;
  3952. ndlp->nlp_retry = 0;
  3953. switch (cmd) {
  3954. case ELS_CMD_FLOGI:
  3955. lpfc_issue_els_flogi(vport, ndlp, retry);
  3956. break;
  3957. case ELS_CMD_PLOGI:
  3958. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  3959. ndlp->nlp_prev_state = ndlp->nlp_state;
  3960. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3961. }
  3962. break;
  3963. case ELS_CMD_ADISC:
  3964. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  3965. ndlp->nlp_prev_state = ndlp->nlp_state;
  3966. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  3967. }
  3968. break;
  3969. case ELS_CMD_PRLI:
  3970. case ELS_CMD_NVMEPRLI:
  3971. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  3972. ndlp->nlp_prev_state = ndlp->nlp_state;
  3973. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  3974. }
  3975. break;
  3976. case ELS_CMD_LOGO:
  3977. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  3978. ndlp->nlp_prev_state = ndlp->nlp_state;
  3979. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  3980. }
  3981. break;
  3982. case ELS_CMD_FDISC:
  3983. if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
  3984. lpfc_issue_els_fdisc(vport, ndlp, retry);
  3985. break;
  3986. }
  3987. return;
  3988. }
  3989. /**
  3990. * lpfc_link_reset - Issue link reset
  3991. * @vport: pointer to a virtual N_Port data structure.
  3992. *
  3993. * This routine performs link reset by sending INIT_LINK mailbox command.
  3994. * For SLI-3 adapter, link attention interrupt is enabled before issuing
  3995. * INIT_LINK mailbox command.
  3996. *
  3997. * Return code
  3998. * 0 - Link reset initiated successfully
  3999. * 1 - Failed to initiate link reset
  4000. **/
  4001. int
  4002. lpfc_link_reset(struct lpfc_vport *vport)
  4003. {
  4004. struct lpfc_hba *phba = vport->phba;
  4005. LPFC_MBOXQ_t *mbox;
  4006. uint32_t control;
  4007. int rc;
  4008. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  4009. "2851 Attempt link reset\n");
  4010. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4011. if (!mbox) {
  4012. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4013. "2852 Failed to allocate mbox memory");
  4014. return 1;
  4015. }
  4016. /* Enable Link attention interrupts */
  4017. if (phba->sli_rev <= LPFC_SLI_REV3) {
  4018. spin_lock_irq(&phba->hbalock);
  4019. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  4020. control = readl(phba->HCregaddr);
  4021. control |= HC_LAINT_ENA;
  4022. writel(control, phba->HCregaddr);
  4023. readl(phba->HCregaddr); /* flush */
  4024. spin_unlock_irq(&phba->hbalock);
  4025. }
  4026. lpfc_init_link(phba, mbox, phba->cfg_topology,
  4027. phba->cfg_link_speed);
  4028. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4029. mbox->vport = vport;
  4030. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4031. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  4032. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4033. "2853 Failed to issue INIT_LINK "
  4034. "mbox command, rc:x%x\n", rc);
  4035. mempool_free(mbox, phba->mbox_mem_pool);
  4036. return 1;
  4037. }
  4038. return 0;
  4039. }
  4040. /**
  4041. * lpfc_els_retry - Make retry decision on an els command iocb
  4042. * @phba: pointer to lpfc hba data structure.
  4043. * @cmdiocb: pointer to lpfc command iocb data structure.
  4044. * @rspiocb: pointer to lpfc response iocb data structure.
  4045. *
  4046. * This routine makes a retry decision on an ELS command IOCB, which has
  4047. * failed. The following ELS IOCBs use this function for retrying the command
  4048. * when previously issued command responsed with error status: FLOGI, PLOGI,
  4049. * PRLI, ADISC and FDISC. Based on the ELS command type and the
  4050. * returned error status, it makes the decision whether a retry shall be
  4051. * issued for the command, and whether a retry shall be made immediately or
  4052. * delayed. In the former case, the corresponding ELS command issuing-function
  4053. * is called to retry the command. In the later case, the ELS command shall
  4054. * be posted to the ndlp delayed event and delayed function timer set to the
  4055. * ndlp for the delayed command issusing.
  4056. *
  4057. * Return code
  4058. * 0 - No retry of els command is made
  4059. * 1 - Immediate or delayed retry of els command is made
  4060. **/
  4061. static int
  4062. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4063. struct lpfc_iocbq *rspiocb)
  4064. {
  4065. struct lpfc_vport *vport = cmdiocb->vport;
  4066. union lpfc_wqe128 *irsp = &rspiocb->wqe;
  4067. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  4068. struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
  4069. uint32_t *elscmd;
  4070. struct ls_rjt stat;
  4071. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  4072. int logerr = 0;
  4073. uint32_t cmd = 0;
  4074. uint32_t did;
  4075. int link_reset = 0, rc;
  4076. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  4077. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  4078. /* Note: cmd_dmabuf may be 0 for internal driver abort
  4079. * of delays ELS command.
  4080. */
  4081. if (pcmd && pcmd->virt) {
  4082. elscmd = (uint32_t *) (pcmd->virt);
  4083. cmd = *elscmd++;
  4084. }
  4085. if (ndlp)
  4086. did = ndlp->nlp_DID;
  4087. else {
  4088. /* We should only hit this case for retrying PLOGI */
  4089. did = get_job_els_rsp64_did(phba, rspiocb);
  4090. ndlp = lpfc_findnode_did(vport, did);
  4091. if (!ndlp && (cmd != ELS_CMD_PLOGI))
  4092. return 0;
  4093. }
  4094. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4095. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  4096. *(((uint32_t *)irsp) + 7), ulp_word4, did);
  4097. switch (ulp_status) {
  4098. case IOSTAT_FCP_RSP_ERROR:
  4099. break;
  4100. case IOSTAT_REMOTE_STOP:
  4101. if (phba->sli_rev == LPFC_SLI_REV4) {
  4102. /* This IO was aborted by the target, we don't
  4103. * know the rxid and because we did not send the
  4104. * ABTS we cannot generate and RRQ.
  4105. */
  4106. lpfc_set_rrq_active(phba, ndlp,
  4107. cmdiocb->sli4_lxritag, 0, 0);
  4108. }
  4109. break;
  4110. case IOSTAT_LOCAL_REJECT:
  4111. switch ((ulp_word4 & IOERR_PARAM_MASK)) {
  4112. case IOERR_LOOP_OPEN_FAILURE:
  4113. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  4114. delay = 1000;
  4115. retry = 1;
  4116. break;
  4117. case IOERR_ILLEGAL_COMMAND:
  4118. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  4119. "0124 Retry illegal cmd x%x "
  4120. "retry:x%x delay:x%x\n",
  4121. cmd, cmdiocb->retry, delay);
  4122. retry = 1;
  4123. /* All command's retry policy */
  4124. maxretry = 8;
  4125. if (cmdiocb->retry > 2)
  4126. delay = 1000;
  4127. break;
  4128. case IOERR_NO_RESOURCES:
  4129. logerr = 1; /* HBA out of resources */
  4130. retry = 1;
  4131. if (cmdiocb->retry > 100)
  4132. delay = 100;
  4133. maxretry = 250;
  4134. break;
  4135. case IOERR_ILLEGAL_FRAME:
  4136. delay = 100;
  4137. retry = 1;
  4138. break;
  4139. case IOERR_INVALID_RPI:
  4140. if (cmd == ELS_CMD_PLOGI &&
  4141. did == NameServer_DID) {
  4142. /* Continue forever if plogi to */
  4143. /* the nameserver fails */
  4144. maxretry = 0;
  4145. delay = 100;
  4146. }
  4147. retry = 1;
  4148. break;
  4149. case IOERR_SEQUENCE_TIMEOUT:
  4150. if (cmd == ELS_CMD_PLOGI &&
  4151. did == NameServer_DID &&
  4152. (cmdiocb->retry + 1) == maxretry) {
  4153. /* Reset the Link */
  4154. link_reset = 1;
  4155. break;
  4156. }
  4157. retry = 1;
  4158. delay = 100;
  4159. break;
  4160. case IOERR_SLI_ABORTED:
  4161. /* Retry ELS PLOGI command?
  4162. * Possibly the rport just wasn't ready.
  4163. */
  4164. if (cmd == ELS_CMD_PLOGI) {
  4165. /* No retry if state change */
  4166. if (ndlp &&
  4167. ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
  4168. goto out_retry;
  4169. retry = 1;
  4170. maxretry = 2;
  4171. }
  4172. break;
  4173. }
  4174. break;
  4175. case IOSTAT_NPORT_RJT:
  4176. case IOSTAT_FABRIC_RJT:
  4177. if (ulp_word4 & RJT_UNAVAIL_TEMP) {
  4178. retry = 1;
  4179. break;
  4180. }
  4181. break;
  4182. case IOSTAT_NPORT_BSY:
  4183. case IOSTAT_FABRIC_BSY:
  4184. logerr = 1; /* Fabric / Remote NPort out of resources */
  4185. retry = 1;
  4186. break;
  4187. case IOSTAT_LS_RJT:
  4188. stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
  4189. /* Added for Vendor specifc support
  4190. * Just keep retrying for these Rsn / Exp codes
  4191. */
  4192. if ((vport->fc_flag & FC_PT2PT) &&
  4193. cmd == ELS_CMD_NVMEPRLI) {
  4194. switch (stat.un.b.lsRjtRsnCode) {
  4195. case LSRJT_UNABLE_TPC:
  4196. case LSRJT_INVALID_CMD:
  4197. case LSRJT_LOGICAL_ERR:
  4198. case LSRJT_CMD_UNSUPPORTED:
  4199. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  4200. "0168 NVME PRLI LS_RJT "
  4201. "reason %x port doesn't "
  4202. "support NVME, disabling NVME\n",
  4203. stat.un.b.lsRjtRsnCode);
  4204. retry = 0;
  4205. vport->fc_flag |= FC_PT2PT_NO_NVME;
  4206. goto out_retry;
  4207. }
  4208. }
  4209. switch (stat.un.b.lsRjtRsnCode) {
  4210. case LSRJT_UNABLE_TPC:
  4211. /* Special case for PRLI LS_RJTs. Recall that lpfc
  4212. * uses a single routine to issue both PRLI FC4 types.
  4213. * If the PRLI is rejected because that FC4 type
  4214. * isn't really supported, don't retry and cause
  4215. * multiple transport registrations. Otherwise, parse
  4216. * the reason code/reason code explanation and take the
  4217. * appropriate action.
  4218. */
  4219. lpfc_printf_vlog(vport, KERN_INFO,
  4220. LOG_DISCOVERY | LOG_ELS | LOG_NODE,
  4221. "0153 ELS cmd x%x LS_RJT by x%x. "
  4222. "RsnCode x%x RsnCodeExp x%x\n",
  4223. cmd, did, stat.un.b.lsRjtRsnCode,
  4224. stat.un.b.lsRjtRsnCodeExp);
  4225. switch (stat.un.b.lsRjtRsnCodeExp) {
  4226. case LSEXP_CANT_GIVE_DATA:
  4227. case LSEXP_CMD_IN_PROGRESS:
  4228. if (cmd == ELS_CMD_PLOGI) {
  4229. delay = 1000;
  4230. maxretry = 48;
  4231. }
  4232. retry = 1;
  4233. break;
  4234. case LSEXP_REQ_UNSUPPORTED:
  4235. case LSEXP_NO_RSRC_ASSIGN:
  4236. /* These explanation codes get no retry. */
  4237. if (cmd == ELS_CMD_PRLI ||
  4238. cmd == ELS_CMD_NVMEPRLI)
  4239. break;
  4240. fallthrough;
  4241. default:
  4242. /* Limit the delay and retry action to a limited
  4243. * cmd set. There are other ELS commands where
  4244. * a retry is not expected.
  4245. */
  4246. if (cmd == ELS_CMD_PLOGI ||
  4247. cmd == ELS_CMD_PRLI ||
  4248. cmd == ELS_CMD_NVMEPRLI) {
  4249. delay = 1000;
  4250. maxretry = lpfc_max_els_tries + 1;
  4251. retry = 1;
  4252. }
  4253. break;
  4254. }
  4255. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  4256. (cmd == ELS_CMD_FDISC) &&
  4257. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  4258. lpfc_printf_vlog(vport, KERN_ERR,
  4259. LOG_TRACE_EVENT,
  4260. "0125 FDISC Failed (x%x). "
  4261. "Fabric out of resources\n",
  4262. stat.un.lsRjtError);
  4263. lpfc_vport_set_state(vport,
  4264. FC_VPORT_NO_FABRIC_RSCS);
  4265. }
  4266. break;
  4267. case LSRJT_LOGICAL_BSY:
  4268. if ((cmd == ELS_CMD_PLOGI) ||
  4269. (cmd == ELS_CMD_PRLI) ||
  4270. (cmd == ELS_CMD_NVMEPRLI)) {
  4271. delay = 1000;
  4272. maxretry = 48;
  4273. } else if (cmd == ELS_CMD_FDISC) {
  4274. /* FDISC retry policy */
  4275. maxretry = 48;
  4276. if (cmdiocb->retry >= 32)
  4277. delay = 1000;
  4278. }
  4279. retry = 1;
  4280. break;
  4281. case LSRJT_LOGICAL_ERR:
  4282. /* There are some cases where switches return this
  4283. * error when they are not ready and should be returning
  4284. * Logical Busy. We should delay every time.
  4285. */
  4286. if (cmd == ELS_CMD_FDISC &&
  4287. stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
  4288. maxretry = 3;
  4289. delay = 1000;
  4290. retry = 1;
  4291. } else if (cmd == ELS_CMD_FLOGI &&
  4292. stat.un.b.lsRjtRsnCodeExp ==
  4293. LSEXP_NOTHING_MORE) {
  4294. vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
  4295. retry = 1;
  4296. lpfc_printf_vlog(vport, KERN_ERR,
  4297. LOG_TRACE_EVENT,
  4298. "0820 FLOGI Failed (x%x). "
  4299. "BBCredit Not Supported\n",
  4300. stat.un.lsRjtError);
  4301. }
  4302. break;
  4303. case LSRJT_PROTOCOL_ERR:
  4304. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  4305. (cmd == ELS_CMD_FDISC) &&
  4306. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  4307. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  4308. ) {
  4309. lpfc_printf_vlog(vport, KERN_ERR,
  4310. LOG_TRACE_EVENT,
  4311. "0122 FDISC Failed (x%x). "
  4312. "Fabric Detected Bad WWN\n",
  4313. stat.un.lsRjtError);
  4314. lpfc_vport_set_state(vport,
  4315. FC_VPORT_FABRIC_REJ_WWN);
  4316. }
  4317. break;
  4318. case LSRJT_VENDOR_UNIQUE:
  4319. if ((stat.un.b.vendorUnique == 0x45) &&
  4320. (cmd == ELS_CMD_FLOGI)) {
  4321. goto out_retry;
  4322. }
  4323. break;
  4324. case LSRJT_CMD_UNSUPPORTED:
  4325. /* lpfc nvmet returns this type of LS_RJT when it
  4326. * receives an FCP PRLI because lpfc nvmet only
  4327. * support NVME. ELS request is terminated for FCP4
  4328. * on this rport.
  4329. */
  4330. if (stat.un.b.lsRjtRsnCodeExp ==
  4331. LSEXP_REQ_UNSUPPORTED) {
  4332. if (cmd == ELS_CMD_PRLI)
  4333. goto out_retry;
  4334. }
  4335. break;
  4336. }
  4337. break;
  4338. case IOSTAT_INTERMED_RSP:
  4339. case IOSTAT_BA_RJT:
  4340. break;
  4341. default:
  4342. break;
  4343. }
  4344. if (link_reset) {
  4345. rc = lpfc_link_reset(vport);
  4346. if (rc) {
  4347. /* Do not give up. Retry PLOGI one more time and attempt
  4348. * link reset if PLOGI fails again.
  4349. */
  4350. retry = 1;
  4351. delay = 100;
  4352. goto out_retry;
  4353. }
  4354. return 1;
  4355. }
  4356. if (did == FDMI_DID)
  4357. retry = 1;
  4358. if ((cmd == ELS_CMD_FLOGI) &&
  4359. (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
  4360. !lpfc_error_lost_link(ulp_status, ulp_word4)) {
  4361. /* FLOGI retry policy */
  4362. retry = 1;
  4363. /* retry FLOGI forever */
  4364. if (phba->link_flag != LS_LOOPBACK_MODE)
  4365. maxretry = 0;
  4366. else
  4367. maxretry = 2;
  4368. if (cmdiocb->retry >= 100)
  4369. delay = 5000;
  4370. else if (cmdiocb->retry >= 32)
  4371. delay = 1000;
  4372. } else if ((cmd == ELS_CMD_FDISC) &&
  4373. !lpfc_error_lost_link(ulp_status, ulp_word4)) {
  4374. /* retry FDISCs every second up to devloss */
  4375. retry = 1;
  4376. maxretry = vport->cfg_devloss_tmo;
  4377. delay = 1000;
  4378. }
  4379. cmdiocb->retry++;
  4380. if (maxretry && (cmdiocb->retry >= maxretry)) {
  4381. phba->fc_stat.elsRetryExceeded++;
  4382. retry = 0;
  4383. }
  4384. if ((vport->load_flag & FC_UNLOADING) != 0)
  4385. retry = 0;
  4386. out_retry:
  4387. if (retry) {
  4388. if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
  4389. /* Stop retrying PLOGI and FDISC if in FCF discovery */
  4390. if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
  4391. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4392. "2849 Stop retry ELS command "
  4393. "x%x to remote NPORT x%x, "
  4394. "Data: x%x x%x\n", cmd, did,
  4395. cmdiocb->retry, delay);
  4396. return 0;
  4397. }
  4398. }
  4399. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  4400. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4401. "0107 Retry ELS command x%x to remote "
  4402. "NPORT x%x Data: x%x x%x\n",
  4403. cmd, did, cmdiocb->retry, delay);
  4404. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  4405. ((ulp_status != IOSTAT_LOCAL_REJECT) ||
  4406. ((ulp_word4 & IOERR_PARAM_MASK) !=
  4407. IOERR_NO_RESOURCES))) {
  4408. /* Don't reset timer for no resources */
  4409. /* If discovery / RSCN timer is running, reset it */
  4410. if (timer_pending(&vport->fc_disctmo) ||
  4411. (vport->fc_flag & FC_RSCN_MODE))
  4412. lpfc_set_disctmo(vport);
  4413. }
  4414. phba->fc_stat.elsXmitRetry++;
  4415. if (ndlp && delay) {
  4416. phba->fc_stat.elsDelayRetry++;
  4417. ndlp->nlp_retry = cmdiocb->retry;
  4418. /* delay is specified in milliseconds */
  4419. mod_timer(&ndlp->nlp_delayfunc,
  4420. jiffies + msecs_to_jiffies(delay));
  4421. spin_lock_irq(&ndlp->lock);
  4422. ndlp->nlp_flag |= NLP_DELAY_TMO;
  4423. spin_unlock_irq(&ndlp->lock);
  4424. ndlp->nlp_prev_state = ndlp->nlp_state;
  4425. if ((cmd == ELS_CMD_PRLI) ||
  4426. (cmd == ELS_CMD_NVMEPRLI))
  4427. lpfc_nlp_set_state(vport, ndlp,
  4428. NLP_STE_PRLI_ISSUE);
  4429. else if (cmd != ELS_CMD_ADISC)
  4430. lpfc_nlp_set_state(vport, ndlp,
  4431. NLP_STE_NPR_NODE);
  4432. ndlp->nlp_last_elscmd = cmd;
  4433. return 1;
  4434. }
  4435. switch (cmd) {
  4436. case ELS_CMD_FLOGI:
  4437. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  4438. return 1;
  4439. case ELS_CMD_FDISC:
  4440. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  4441. return 1;
  4442. case ELS_CMD_PLOGI:
  4443. if (ndlp) {
  4444. ndlp->nlp_prev_state = ndlp->nlp_state;
  4445. lpfc_nlp_set_state(vport, ndlp,
  4446. NLP_STE_PLOGI_ISSUE);
  4447. }
  4448. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  4449. return 1;
  4450. case ELS_CMD_ADISC:
  4451. ndlp->nlp_prev_state = ndlp->nlp_state;
  4452. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  4453. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  4454. return 1;
  4455. case ELS_CMD_PRLI:
  4456. case ELS_CMD_NVMEPRLI:
  4457. ndlp->nlp_prev_state = ndlp->nlp_state;
  4458. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  4459. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  4460. return 1;
  4461. case ELS_CMD_LOGO:
  4462. ndlp->nlp_prev_state = ndlp->nlp_state;
  4463. lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
  4464. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  4465. return 1;
  4466. }
  4467. }
  4468. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  4469. if (logerr) {
  4470. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  4471. "0137 No retry ELS command x%x to remote "
  4472. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  4473. cmd, did, ulp_status,
  4474. ulp_word4);
  4475. }
  4476. else {
  4477. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4478. "0108 No retry ELS command x%x to remote "
  4479. "NPORT x%x Retried:%d Error:x%x/%x\n",
  4480. cmd, did, cmdiocb->retry, ulp_status,
  4481. ulp_word4);
  4482. }
  4483. return 0;
  4484. }
  4485. /**
  4486. * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
  4487. * @phba: pointer to lpfc hba data structure.
  4488. * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
  4489. *
  4490. * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
  4491. * associated with a command IOCB back to the lpfc DMA buffer pool. It first
  4492. * checks to see whether there is a lpfc DMA buffer associated with the
  4493. * response of the command IOCB. If so, it will be released before releasing
  4494. * the lpfc DMA buffer associated with the IOCB itself.
  4495. *
  4496. * Return code
  4497. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  4498. **/
  4499. static int
  4500. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  4501. {
  4502. struct lpfc_dmabuf *buf_ptr;
  4503. /* Free the response before processing the command. */
  4504. if (!list_empty(&buf_ptr1->list)) {
  4505. list_remove_head(&buf_ptr1->list, buf_ptr,
  4506. struct lpfc_dmabuf,
  4507. list);
  4508. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  4509. kfree(buf_ptr);
  4510. }
  4511. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  4512. kfree(buf_ptr1);
  4513. return 0;
  4514. }
  4515. /**
  4516. * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
  4517. * @phba: pointer to lpfc hba data structure.
  4518. * @buf_ptr: pointer to the lpfc dma buffer data structure.
  4519. *
  4520. * This routine releases the lpfc Direct Memory Access (DMA) buffer
  4521. * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
  4522. * pool.
  4523. *
  4524. * Return code
  4525. * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
  4526. **/
  4527. static int
  4528. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  4529. {
  4530. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  4531. kfree(buf_ptr);
  4532. return 0;
  4533. }
  4534. /**
  4535. * lpfc_els_free_iocb - Free a command iocb and its associated resources
  4536. * @phba: pointer to lpfc hba data structure.
  4537. * @elsiocb: pointer to lpfc els command iocb data structure.
  4538. *
  4539. * This routine frees a command IOCB and its associated resources. The
  4540. * command IOCB data structure contains the reference to various associated
  4541. * resources, these fields must be set to NULL if the associated reference
  4542. * not present:
  4543. * cmd_dmabuf - reference to cmd.
  4544. * cmd_dmabuf->next - reference to rsp
  4545. * rsp_dmabuf - unused
  4546. * bpl_dmabuf - reference to bpl
  4547. *
  4548. * It first properly decrements the reference count held on ndlp for the
  4549. * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
  4550. * set, it invokes the lpfc_els_free_data() routine to release the Direct
  4551. * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
  4552. * adds the DMA buffer the @phba data structure for the delayed release.
  4553. * If reference to the Buffer Pointer List (BPL) is present, the
  4554. * lpfc_els_free_bpl() routine is invoked to release the DMA memory
  4555. * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
  4556. * invoked to release the IOCB data structure back to @phba IOCBQ list.
  4557. *
  4558. * Return code
  4559. * 0 - Success (currently, always return 0)
  4560. **/
  4561. int
  4562. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  4563. {
  4564. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  4565. /* The I/O iocb is complete. Clear the node and first dmbuf */
  4566. elsiocb->ndlp = NULL;
  4567. /* cmd_dmabuf = cmd, cmd_dmabuf->next = rsp, bpl_dmabuf = bpl */
  4568. if (elsiocb->cmd_dmabuf) {
  4569. if (elsiocb->cmd_flag & LPFC_DELAY_MEM_FREE) {
  4570. /* Firmware could still be in progress of DMAing
  4571. * payload, so don't free data buffer till after
  4572. * a hbeat.
  4573. */
  4574. elsiocb->cmd_flag &= ~LPFC_DELAY_MEM_FREE;
  4575. buf_ptr = elsiocb->cmd_dmabuf;
  4576. elsiocb->cmd_dmabuf = NULL;
  4577. if (buf_ptr) {
  4578. buf_ptr1 = NULL;
  4579. spin_lock_irq(&phba->hbalock);
  4580. if (!list_empty(&buf_ptr->list)) {
  4581. list_remove_head(&buf_ptr->list,
  4582. buf_ptr1, struct lpfc_dmabuf,
  4583. list);
  4584. INIT_LIST_HEAD(&buf_ptr1->list);
  4585. list_add_tail(&buf_ptr1->list,
  4586. &phba->elsbuf);
  4587. phba->elsbuf_cnt++;
  4588. }
  4589. INIT_LIST_HEAD(&buf_ptr->list);
  4590. list_add_tail(&buf_ptr->list, &phba->elsbuf);
  4591. phba->elsbuf_cnt++;
  4592. spin_unlock_irq(&phba->hbalock);
  4593. }
  4594. } else {
  4595. buf_ptr1 = elsiocb->cmd_dmabuf;
  4596. lpfc_els_free_data(phba, buf_ptr1);
  4597. elsiocb->cmd_dmabuf = NULL;
  4598. }
  4599. }
  4600. if (elsiocb->bpl_dmabuf) {
  4601. buf_ptr = elsiocb->bpl_dmabuf;
  4602. lpfc_els_free_bpl(phba, buf_ptr);
  4603. elsiocb->bpl_dmabuf = NULL;
  4604. }
  4605. lpfc_sli_release_iocbq(phba, elsiocb);
  4606. return 0;
  4607. }
  4608. /**
  4609. * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
  4610. * @phba: pointer to lpfc hba data structure.
  4611. * @cmdiocb: pointer to lpfc command iocb data structure.
  4612. * @rspiocb: pointer to lpfc response iocb data structure.
  4613. *
  4614. * This routine is the completion callback function to the Logout (LOGO)
  4615. * Accept (ACC) Response ELS command. This routine is invoked to indicate
  4616. * the completion of the LOGO process. If the node has transitioned to NPR,
  4617. * this routine unregisters the RPI if it is still registered. The
  4618. * lpfc_els_free_iocb() is invoked to release the IOCB data structure.
  4619. **/
  4620. static void
  4621. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4622. struct lpfc_iocbq *rspiocb)
  4623. {
  4624. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  4625. struct lpfc_vport *vport = cmdiocb->vport;
  4626. u32 ulp_status, ulp_word4;
  4627. ulp_status = get_job_ulpstatus(phba, rspiocb);
  4628. ulp_word4 = get_job_word4(phba, rspiocb);
  4629. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4630. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  4631. ulp_status, ulp_word4, ndlp->nlp_DID);
  4632. /* ACC to LOGO completes to NPort <nlp_DID> */
  4633. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4634. "0109 ACC to LOGO completes to NPort x%x refcnt %d "
  4635. "Data: x%x x%x x%x\n",
  4636. ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp->nlp_flag,
  4637. ndlp->nlp_state, ndlp->nlp_rpi);
  4638. /* This clause allows the LOGO ACC to complete and free resources
  4639. * for the Fabric Domain Controller. It does deliberately skip
  4640. * the unreg_rpi and release rpi because some fabrics send RDP
  4641. * requests after logging out from the initiator.
  4642. */
  4643. if (ndlp->nlp_type & NLP_FABRIC &&
  4644. ((ndlp->nlp_DID & WELL_KNOWN_DID_MASK) != WELL_KNOWN_DID_MASK))
  4645. goto out;
  4646. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  4647. /* If PLOGI is being retried, PLOGI completion will cleanup the
  4648. * node. The NLP_NPR_2B_DISC flag needs to be retained to make
  4649. * progress on nodes discovered from last RSCN.
  4650. */
  4651. if ((ndlp->nlp_flag & NLP_DELAY_TMO) &&
  4652. (ndlp->nlp_last_elscmd == ELS_CMD_PLOGI))
  4653. goto out;
  4654. if (ndlp->nlp_flag & NLP_RPI_REGISTERED)
  4655. lpfc_unreg_rpi(vport, ndlp);
  4656. }
  4657. out:
  4658. /*
  4659. * The driver received a LOGO from the rport and has ACK'd it.
  4660. * At this point, the driver is done so release the IOCB
  4661. */
  4662. lpfc_els_free_iocb(phba, cmdiocb);
  4663. lpfc_nlp_put(ndlp);
  4664. }
  4665. /**
  4666. * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
  4667. * @phba: pointer to lpfc hba data structure.
  4668. * @pmb: pointer to the driver internal queue element for mailbox command.
  4669. *
  4670. * This routine is the completion callback function for unregister default
  4671. * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
  4672. * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
  4673. * decrements the ndlp reference count held for this completion callback
  4674. * function. After that, it invokes the lpfc_drop_node to check
  4675. * whether it is appropriate to release the node.
  4676. **/
  4677. void
  4678. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4679. {
  4680. struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
  4681. u32 mbx_flag = pmb->mbox_flag;
  4682. u32 mbx_cmd = pmb->u.mb.mbxCommand;
  4683. if (ndlp) {
  4684. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  4685. "0006 rpi x%x DID:%x flg:%x %d x%px "
  4686. "mbx_cmd x%x mbx_flag x%x x%px\n",
  4687. ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
  4688. kref_read(&ndlp->kref), ndlp, mbx_cmd,
  4689. mbx_flag, pmb);
  4690. /* This ends the default/temporary RPI cleanup logic for this
  4691. * ndlp and the node and rpi needs to be released. Free the rpi
  4692. * first on an UNREG_LOGIN and then release the final
  4693. * references.
  4694. */
  4695. spin_lock_irq(&ndlp->lock);
  4696. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  4697. if (mbx_cmd == MBX_UNREG_LOGIN)
  4698. ndlp->nlp_flag &= ~NLP_UNREG_INP;
  4699. spin_unlock_irq(&ndlp->lock);
  4700. lpfc_nlp_put(ndlp);
  4701. lpfc_drop_node(ndlp->vport, ndlp);
  4702. }
  4703. lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
  4704. }
  4705. /**
  4706. * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
  4707. * @phba: pointer to lpfc hba data structure.
  4708. * @cmdiocb: pointer to lpfc command iocb data structure.
  4709. * @rspiocb: pointer to lpfc response iocb data structure.
  4710. *
  4711. * This routine is the completion callback function for ELS Response IOCB
  4712. * command. In normal case, this callback function just properly sets the
  4713. * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
  4714. * field in the command IOCB is not NULL, the referred mailbox command will
  4715. * be send out, and then invokes the lpfc_els_free_iocb() routine to release
  4716. * the IOCB.
  4717. **/
  4718. static void
  4719. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4720. struct lpfc_iocbq *rspiocb)
  4721. {
  4722. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  4723. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  4724. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  4725. IOCB_t *irsp;
  4726. LPFC_MBOXQ_t *mbox = NULL;
  4727. u32 ulp_status, ulp_word4, tmo, did, iotag;
  4728. if (!vport) {
  4729. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4730. "3177 ELS response failed\n");
  4731. goto out;
  4732. }
  4733. if (cmdiocb->context_un.mbox)
  4734. mbox = cmdiocb->context_un.mbox;
  4735. ulp_status = get_job_ulpstatus(phba, rspiocb);
  4736. ulp_word4 = get_job_word4(phba, rspiocb);
  4737. did = get_job_els_rsp64_did(phba, cmdiocb);
  4738. if (phba->sli_rev == LPFC_SLI_REV4) {
  4739. tmo = get_wqe_tmo(cmdiocb);
  4740. iotag = get_wqe_reqtag(cmdiocb);
  4741. } else {
  4742. irsp = &rspiocb->iocb;
  4743. tmo = irsp->ulpTimeout;
  4744. iotag = irsp->ulpIoTag;
  4745. }
  4746. /* Check to see if link went down during discovery */
  4747. if (!ndlp || lpfc_els_chk_latt(vport)) {
  4748. if (mbox)
  4749. lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
  4750. goto out;
  4751. }
  4752. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4753. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  4754. ulp_status, ulp_word4, did);
  4755. /* ELS response tag <ulpIoTag> completes */
  4756. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  4757. "0110 ELS response tag x%x completes "
  4758. "Data: x%x x%x x%x x%x x%x x%x x%x x%x %p %p\n",
  4759. iotag, ulp_status, ulp_word4, tmo,
  4760. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4761. ndlp->nlp_rpi, kref_read(&ndlp->kref), mbox, ndlp);
  4762. if (mbox) {
  4763. if (ulp_status == 0
  4764. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  4765. if (!lpfc_unreg_rpi(vport, ndlp) &&
  4766. (!(vport->fc_flag & FC_PT2PT))) {
  4767. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  4768. ndlp->nlp_state ==
  4769. NLP_STE_REG_LOGIN_ISSUE) {
  4770. lpfc_printf_vlog(vport, KERN_INFO,
  4771. LOG_DISCOVERY,
  4772. "0314 PLOGI recov "
  4773. "DID x%x "
  4774. "Data: x%x x%x x%x\n",
  4775. ndlp->nlp_DID,
  4776. ndlp->nlp_state,
  4777. ndlp->nlp_rpi,
  4778. ndlp->nlp_flag);
  4779. goto out_free_mbox;
  4780. }
  4781. }
  4782. /* Increment reference count to ndlp to hold the
  4783. * reference to ndlp for the callback function.
  4784. */
  4785. mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
  4786. if (!mbox->ctx_ndlp)
  4787. goto out_free_mbox;
  4788. mbox->vport = vport;
  4789. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  4790. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  4791. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  4792. }
  4793. else {
  4794. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  4795. ndlp->nlp_prev_state = ndlp->nlp_state;
  4796. lpfc_nlp_set_state(vport, ndlp,
  4797. NLP_STE_REG_LOGIN_ISSUE);
  4798. }
  4799. ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
  4800. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  4801. != MBX_NOT_FINISHED)
  4802. goto out;
  4803. /* Decrement the ndlp reference count we
  4804. * set for this failed mailbox command.
  4805. */
  4806. lpfc_nlp_put(ndlp);
  4807. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  4808. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  4809. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  4810. "0138 ELS rsp: Cannot issue reg_login for x%x "
  4811. "Data: x%x x%x x%x\n",
  4812. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  4813. ndlp->nlp_rpi);
  4814. }
  4815. out_free_mbox:
  4816. lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
  4817. }
  4818. out:
  4819. if (ndlp && shost) {
  4820. spin_lock_irq(&ndlp->lock);
  4821. if (mbox)
  4822. ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
  4823. ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
  4824. spin_unlock_irq(&ndlp->lock);
  4825. }
  4826. /* An SLI4 NPIV instance wants to drop the node at this point under
  4827. * these conditions and release the RPI.
  4828. */
  4829. if (phba->sli_rev == LPFC_SLI_REV4 &&
  4830. vport && vport->port_type == LPFC_NPIV_PORT &&
  4831. !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
  4832. if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
  4833. if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE &&
  4834. ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
  4835. lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
  4836. spin_lock_irq(&ndlp->lock);
  4837. ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
  4838. ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
  4839. spin_unlock_irq(&ndlp->lock);
  4840. }
  4841. lpfc_drop_node(vport, ndlp);
  4842. } else if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE &&
  4843. ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE &&
  4844. ndlp->nlp_state != NLP_STE_PRLI_ISSUE) {
  4845. /* Drop ndlp if there is no planned or outstanding
  4846. * issued PRLI.
  4847. *
  4848. * In cases when the ndlp is acting as both an initiator
  4849. * and target function, let our issued PRLI determine
  4850. * the final ndlp kref drop.
  4851. */
  4852. lpfc_drop_node(vport, ndlp);
  4853. }
  4854. }
  4855. /* Release the originating I/O reference. */
  4856. lpfc_els_free_iocb(phba, cmdiocb);
  4857. lpfc_nlp_put(ndlp);
  4858. return;
  4859. }
  4860. /**
  4861. * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
  4862. * @vport: pointer to a host virtual N_Port data structure.
  4863. * @flag: the els command code to be accepted.
  4864. * @oldiocb: pointer to the original lpfc command iocb data structure.
  4865. * @ndlp: pointer to a node-list data structure.
  4866. * @mbox: pointer to the driver internal queue element for mailbox command.
  4867. *
  4868. * This routine prepares and issues an Accept (ACC) response IOCB
  4869. * command. It uses the @flag to properly set up the IOCB field for the
  4870. * specific ACC response command to be issued and invokes the
  4871. * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
  4872. * @mbox pointer is passed in, it will be put into the context_un.mbox
  4873. * field of the IOCB for the completion callback function to issue the
  4874. * mailbox command to the HBA later when callback is invoked.
  4875. *
  4876. * Note that the ndlp reference count will be incremented by 1 for holding the
  4877. * ndlp and the reference to ndlp will be stored into the ndlp field of
  4878. * the IOCB for the completion callback function to the corresponding
  4879. * response ELS IOCB command.
  4880. *
  4881. * Return code
  4882. * 0 - Successfully issued acc response
  4883. * 1 - Failed to issue acc response
  4884. **/
  4885. int
  4886. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  4887. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  4888. LPFC_MBOXQ_t *mbox)
  4889. {
  4890. struct lpfc_hba *phba = vport->phba;
  4891. IOCB_t *icmd;
  4892. IOCB_t *oldcmd;
  4893. union lpfc_wqe128 *wqe;
  4894. union lpfc_wqe128 *oldwqe = &oldiocb->wqe;
  4895. struct lpfc_iocbq *elsiocb;
  4896. uint8_t *pcmd;
  4897. struct serv_parm *sp;
  4898. uint16_t cmdsize;
  4899. int rc;
  4900. ELS_PKT *els_pkt_ptr;
  4901. struct fc_els_rdf_resp *rdf_resp;
  4902. switch (flag) {
  4903. case ELS_CMD_ACC:
  4904. cmdsize = sizeof(uint32_t);
  4905. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  4906. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  4907. if (!elsiocb) {
  4908. spin_lock_irq(&ndlp->lock);
  4909. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  4910. spin_unlock_irq(&ndlp->lock);
  4911. return 1;
  4912. }
  4913. if (phba->sli_rev == LPFC_SLI_REV4) {
  4914. wqe = &elsiocb->wqe;
  4915. /* XRI / rx_id */
  4916. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  4917. bf_get(wqe_ctxt_tag,
  4918. &oldwqe->xmit_els_rsp.wqe_com));
  4919. /* oxid */
  4920. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  4921. bf_get(wqe_rcvoxid,
  4922. &oldwqe->xmit_els_rsp.wqe_com));
  4923. } else {
  4924. icmd = &elsiocb->iocb;
  4925. oldcmd = &oldiocb->iocb;
  4926. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4927. icmd->unsli3.rcvsli3.ox_id =
  4928. oldcmd->unsli3.rcvsli3.ox_id;
  4929. }
  4930. pcmd = elsiocb->cmd_dmabuf->virt;
  4931. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4932. pcmd += sizeof(uint32_t);
  4933. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  4934. "Issue ACC: did:x%x flg:x%x",
  4935. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  4936. break;
  4937. case ELS_CMD_FLOGI:
  4938. case ELS_CMD_PLOGI:
  4939. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  4940. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  4941. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  4942. if (!elsiocb)
  4943. return 1;
  4944. if (phba->sli_rev == LPFC_SLI_REV4) {
  4945. wqe = &elsiocb->wqe;
  4946. /* XRI / rx_id */
  4947. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  4948. bf_get(wqe_ctxt_tag,
  4949. &oldwqe->xmit_els_rsp.wqe_com));
  4950. /* oxid */
  4951. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  4952. bf_get(wqe_rcvoxid,
  4953. &oldwqe->xmit_els_rsp.wqe_com));
  4954. } else {
  4955. icmd = &elsiocb->iocb;
  4956. oldcmd = &oldiocb->iocb;
  4957. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  4958. icmd->unsli3.rcvsli3.ox_id =
  4959. oldcmd->unsli3.rcvsli3.ox_id;
  4960. }
  4961. pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
  4962. if (mbox)
  4963. elsiocb->context_un.mbox = mbox;
  4964. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  4965. pcmd += sizeof(uint32_t);
  4966. sp = (struct serv_parm *)pcmd;
  4967. if (flag == ELS_CMD_FLOGI) {
  4968. /* Copy the received service parameters back */
  4969. memcpy(sp, &phba->fc_fabparam,
  4970. sizeof(struct serv_parm));
  4971. /* Clear the F_Port bit */
  4972. sp->cmn.fPort = 0;
  4973. /* Mark all class service parameters as invalid */
  4974. sp->cls1.classValid = 0;
  4975. sp->cls2.classValid = 0;
  4976. sp->cls3.classValid = 0;
  4977. sp->cls4.classValid = 0;
  4978. /* Copy our worldwide names */
  4979. memcpy(&sp->portName, &vport->fc_sparam.portName,
  4980. sizeof(struct lpfc_name));
  4981. memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
  4982. sizeof(struct lpfc_name));
  4983. } else {
  4984. memcpy(pcmd, &vport->fc_sparam,
  4985. sizeof(struct serv_parm));
  4986. sp->cmn.valid_vendor_ver_level = 0;
  4987. memset(sp->un.vendorVersion, 0,
  4988. sizeof(sp->un.vendorVersion));
  4989. sp->cmn.bbRcvSizeMsb &= 0xF;
  4990. /* If our firmware supports this feature, convey that
  4991. * info to the target using the vendor specific field.
  4992. */
  4993. if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
  4994. sp->cmn.valid_vendor_ver_level = 1;
  4995. sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
  4996. sp->un.vv.flags =
  4997. cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
  4998. }
  4999. }
  5000. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5001. "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
  5002. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  5003. break;
  5004. case ELS_CMD_PRLO:
  5005. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  5006. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  5007. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  5008. if (!elsiocb)
  5009. return 1;
  5010. if (phba->sli_rev == LPFC_SLI_REV4) {
  5011. wqe = &elsiocb->wqe;
  5012. /* XRI / rx_id */
  5013. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5014. bf_get(wqe_ctxt_tag,
  5015. &oldwqe->xmit_els_rsp.wqe_com));
  5016. /* oxid */
  5017. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5018. bf_get(wqe_rcvoxid,
  5019. &oldwqe->xmit_els_rsp.wqe_com));
  5020. } else {
  5021. icmd = &elsiocb->iocb;
  5022. oldcmd = &oldiocb->iocb;
  5023. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5024. icmd->unsli3.rcvsli3.ox_id =
  5025. oldcmd->unsli3.rcvsli3.ox_id;
  5026. }
  5027. pcmd = (u8 *) elsiocb->cmd_dmabuf->virt;
  5028. memcpy(pcmd, oldiocb->cmd_dmabuf->virt,
  5029. sizeof(uint32_t) + sizeof(PRLO));
  5030. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  5031. els_pkt_ptr = (ELS_PKT *) pcmd;
  5032. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  5033. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5034. "Issue ACC PRLO: did:x%x flg:x%x",
  5035. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  5036. break;
  5037. case ELS_CMD_RDF:
  5038. cmdsize = sizeof(*rdf_resp);
  5039. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  5040. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  5041. if (!elsiocb)
  5042. return 1;
  5043. if (phba->sli_rev == LPFC_SLI_REV4) {
  5044. wqe = &elsiocb->wqe;
  5045. /* XRI / rx_id */
  5046. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  5047. bf_get(wqe_ctxt_tag,
  5048. &oldwqe->xmit_els_rsp.wqe_com));
  5049. /* oxid */
  5050. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5051. bf_get(wqe_rcvoxid,
  5052. &oldwqe->xmit_els_rsp.wqe_com));
  5053. } else {
  5054. icmd = &elsiocb->iocb;
  5055. oldcmd = &oldiocb->iocb;
  5056. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5057. icmd->unsli3.rcvsli3.ox_id =
  5058. oldcmd->unsli3.rcvsli3.ox_id;
  5059. }
  5060. pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
  5061. rdf_resp = (struct fc_els_rdf_resp *)pcmd;
  5062. memset(rdf_resp, 0, sizeof(*rdf_resp));
  5063. rdf_resp->acc_hdr.la_cmd = ELS_LS_ACC;
  5064. /* FC-LS-5 specifies desc_list_len shall be set to 12 */
  5065. rdf_resp->desc_list_len = cpu_to_be32(12);
  5066. /* FC-LS-5 specifies LS REQ Information descriptor */
  5067. rdf_resp->lsri.desc_tag = cpu_to_be32(1);
  5068. rdf_resp->lsri.desc_len = cpu_to_be32(sizeof(u32));
  5069. rdf_resp->lsri.rqst_w0.cmd = ELS_RDF;
  5070. break;
  5071. default:
  5072. return 1;
  5073. }
  5074. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  5075. spin_lock_irq(&ndlp->lock);
  5076. if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
  5077. ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
  5078. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  5079. spin_unlock_irq(&ndlp->lock);
  5080. elsiocb->cmd_cmpl = lpfc_cmpl_els_logo_acc;
  5081. } else {
  5082. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  5083. }
  5084. phba->fc_stat.elsXmitACC++;
  5085. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  5086. if (!elsiocb->ndlp) {
  5087. lpfc_els_free_iocb(phba, elsiocb);
  5088. return 1;
  5089. }
  5090. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5091. if (rc == IOCB_ERROR) {
  5092. lpfc_els_free_iocb(phba, elsiocb);
  5093. lpfc_nlp_put(ndlp);
  5094. return 1;
  5095. }
  5096. /* Xmit ELS ACC response tag <ulpIoTag> */
  5097. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5098. "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
  5099. "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
  5100. "RPI: x%x, fc_flag x%x refcnt %d\n",
  5101. rc, elsiocb->iotag, elsiocb->sli4_xritag,
  5102. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5103. ndlp->nlp_rpi, vport->fc_flag, kref_read(&ndlp->kref));
  5104. return 0;
  5105. }
  5106. /**
  5107. * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command
  5108. * @vport: pointer to a virtual N_Port data structure.
  5109. * @rejectError: reject response to issue
  5110. * @oldiocb: pointer to the original lpfc command iocb data structure.
  5111. * @ndlp: pointer to a node-list data structure.
  5112. * @mbox: pointer to the driver internal queue element for mailbox command.
  5113. *
  5114. * This routine prepares and issue an Reject (RJT) response IOCB
  5115. * command. If a @mbox pointer is passed in, it will be put into the
  5116. * context_un.mbox field of the IOCB for the completion callback function
  5117. * to issue to the HBA later.
  5118. *
  5119. * Note that the ndlp reference count will be incremented by 1 for holding the
  5120. * ndlp and the reference to ndlp will be stored into the ndlp field of
  5121. * the IOCB for the completion callback function to the reject response
  5122. * ELS IOCB command.
  5123. *
  5124. * Return code
  5125. * 0 - Successfully issued reject response
  5126. * 1 - Failed to issue reject response
  5127. **/
  5128. int
  5129. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  5130. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  5131. LPFC_MBOXQ_t *mbox)
  5132. {
  5133. int rc;
  5134. struct lpfc_hba *phba = vport->phba;
  5135. IOCB_t *icmd;
  5136. IOCB_t *oldcmd;
  5137. union lpfc_wqe128 *wqe;
  5138. struct lpfc_iocbq *elsiocb;
  5139. uint8_t *pcmd;
  5140. uint16_t cmdsize;
  5141. cmdsize = 2 * sizeof(uint32_t);
  5142. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  5143. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  5144. if (!elsiocb)
  5145. return 1;
  5146. if (phba->sli_rev == LPFC_SLI_REV4) {
  5147. wqe = &elsiocb->wqe;
  5148. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
  5149. get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
  5150. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5151. get_job_rcvoxid(phba, oldiocb));
  5152. } else {
  5153. icmd = &elsiocb->iocb;
  5154. oldcmd = &oldiocb->iocb;
  5155. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5156. icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
  5157. }
  5158. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  5159. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  5160. pcmd += sizeof(uint32_t);
  5161. *((uint32_t *) (pcmd)) = rejectError;
  5162. if (mbox)
  5163. elsiocb->context_un.mbox = mbox;
  5164. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  5165. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5166. "0129 Xmit ELS RJT x%x response tag x%x "
  5167. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  5168. "rpi x%x\n",
  5169. rejectError, elsiocb->iotag,
  5170. get_job_ulpcontext(phba, elsiocb), ndlp->nlp_DID,
  5171. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  5172. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5173. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  5174. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  5175. phba->fc_stat.elsXmitLSRJT++;
  5176. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  5177. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  5178. if (!elsiocb->ndlp) {
  5179. lpfc_els_free_iocb(phba, elsiocb);
  5180. return 1;
  5181. }
  5182. /* The NPIV instance is rejecting this unsolicited ELS. Make sure the
  5183. * node's assigned RPI gets released provided this node is not already
  5184. * registered with the transport.
  5185. */
  5186. if (phba->sli_rev == LPFC_SLI_REV4 &&
  5187. vport->port_type == LPFC_NPIV_PORT &&
  5188. !(ndlp->fc4_xpt_flags & SCSI_XPT_REGD)) {
  5189. spin_lock_irq(&ndlp->lock);
  5190. ndlp->nlp_flag |= NLP_RELEASE_RPI;
  5191. spin_unlock_irq(&ndlp->lock);
  5192. }
  5193. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5194. if (rc == IOCB_ERROR) {
  5195. lpfc_els_free_iocb(phba, elsiocb);
  5196. lpfc_nlp_put(ndlp);
  5197. return 1;
  5198. }
  5199. return 0;
  5200. }
  5201. /**
  5202. * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric.
  5203. * @vport: pointer to a host virtual N_Port data structure.
  5204. * @cmdiocb: pointer to the original lpfc command iocb data structure.
  5205. * @ndlp: NPort to where rsp is directed
  5206. *
  5207. * This routine issues an EDC ACC RSP to the F-Port Controller to communicate
  5208. * this N_Port's support of hardware signals in its Congestion
  5209. * Capabilities Descriptor.
  5210. *
  5211. * Return code
  5212. * 0 - Successfully issued edc rsp command
  5213. * 1 - Failed to issue edc rsp command
  5214. **/
  5215. static int
  5216. lpfc_issue_els_edc_rsp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  5217. struct lpfc_nodelist *ndlp)
  5218. {
  5219. struct lpfc_hba *phba = vport->phba;
  5220. struct fc_els_edc_resp *edc_rsp;
  5221. struct fc_tlv_desc *tlv;
  5222. struct lpfc_iocbq *elsiocb;
  5223. IOCB_t *icmd, *cmd;
  5224. union lpfc_wqe128 *wqe;
  5225. u32 cgn_desc_size, lft_desc_size;
  5226. u16 cmdsize;
  5227. uint8_t *pcmd;
  5228. int rc;
  5229. cmdsize = sizeof(struct fc_els_edc_resp);
  5230. cgn_desc_size = sizeof(struct fc_diag_cg_sig_desc);
  5231. lft_desc_size = (lpfc_link_is_lds_capable(phba)) ?
  5232. sizeof(struct fc_diag_lnkflt_desc) : 0;
  5233. cmdsize += cgn_desc_size + lft_desc_size;
  5234. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, cmdiocb->retry,
  5235. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  5236. if (!elsiocb)
  5237. return 1;
  5238. if (phba->sli_rev == LPFC_SLI_REV4) {
  5239. wqe = &elsiocb->wqe;
  5240. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
  5241. get_job_ulpcontext(phba, cmdiocb)); /* Xri / rx_id */
  5242. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5243. get_job_rcvoxid(phba, cmdiocb));
  5244. } else {
  5245. icmd = &elsiocb->iocb;
  5246. cmd = &cmdiocb->iocb;
  5247. icmd->ulpContext = cmd->ulpContext; /* Xri / rx_id */
  5248. icmd->unsli3.rcvsli3.ox_id = cmd->unsli3.rcvsli3.ox_id;
  5249. }
  5250. pcmd = elsiocb->cmd_dmabuf->virt;
  5251. memset(pcmd, 0, cmdsize);
  5252. edc_rsp = (struct fc_els_edc_resp *)pcmd;
  5253. edc_rsp->acc_hdr.la_cmd = ELS_LS_ACC;
  5254. edc_rsp->desc_list_len = cpu_to_be32(sizeof(struct fc_els_lsri_desc) +
  5255. cgn_desc_size + lft_desc_size);
  5256. edc_rsp->lsri.desc_tag = cpu_to_be32(ELS_DTAG_LS_REQ_INFO);
  5257. edc_rsp->lsri.desc_len = cpu_to_be32(
  5258. FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc));
  5259. edc_rsp->lsri.rqst_w0.cmd = ELS_EDC;
  5260. tlv = edc_rsp->desc;
  5261. lpfc_format_edc_cgn_desc(phba, tlv);
  5262. tlv = fc_tlv_next_desc(tlv);
  5263. if (lft_desc_size)
  5264. lpfc_format_edc_lft_desc(phba, tlv);
  5265. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5266. "Issue EDC ACC: did:x%x flg:x%x refcnt %d",
  5267. ndlp->nlp_DID, ndlp->nlp_flag,
  5268. kref_read(&ndlp->kref));
  5269. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  5270. phba->fc_stat.elsXmitACC++;
  5271. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  5272. if (!elsiocb->ndlp) {
  5273. lpfc_els_free_iocb(phba, elsiocb);
  5274. return 1;
  5275. }
  5276. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5277. if (rc == IOCB_ERROR) {
  5278. lpfc_els_free_iocb(phba, elsiocb);
  5279. lpfc_nlp_put(ndlp);
  5280. return 1;
  5281. }
  5282. /* Xmit ELS ACC response tag <ulpIoTag> */
  5283. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5284. "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, "
  5285. "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
  5286. "RPI: x%x, fc_flag x%x\n",
  5287. rc, elsiocb->iotag, elsiocb->sli4_xritag,
  5288. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5289. ndlp->nlp_rpi, vport->fc_flag);
  5290. return 0;
  5291. }
  5292. /**
  5293. * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
  5294. * @vport: pointer to a virtual N_Port data structure.
  5295. * @oldiocb: pointer to the original lpfc command iocb data structure.
  5296. * @ndlp: pointer to a node-list data structure.
  5297. *
  5298. * This routine prepares and issues an Accept (ACC) response to Address
  5299. * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
  5300. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  5301. *
  5302. * Note that the ndlp reference count will be incremented by 1 for holding the
  5303. * ndlp and the reference to ndlp will be stored into the ndlp field of
  5304. * the IOCB for the completion callback function to the ADISC Accept response
  5305. * ELS IOCB command.
  5306. *
  5307. * Return code
  5308. * 0 - Successfully issued acc adisc response
  5309. * 1 - Failed to issue adisc acc response
  5310. **/
  5311. int
  5312. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  5313. struct lpfc_nodelist *ndlp)
  5314. {
  5315. struct lpfc_hba *phba = vport->phba;
  5316. ADISC *ap;
  5317. IOCB_t *icmd, *oldcmd;
  5318. union lpfc_wqe128 *wqe;
  5319. struct lpfc_iocbq *elsiocb;
  5320. uint8_t *pcmd;
  5321. uint16_t cmdsize;
  5322. int rc;
  5323. u32 ulp_context;
  5324. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  5325. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  5326. ndlp->nlp_DID, ELS_CMD_ACC);
  5327. if (!elsiocb)
  5328. return 1;
  5329. if (phba->sli_rev == LPFC_SLI_REV4) {
  5330. wqe = &elsiocb->wqe;
  5331. /* XRI / rx_id */
  5332. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
  5333. get_job_ulpcontext(phba, oldiocb));
  5334. ulp_context = get_job_ulpcontext(phba, elsiocb);
  5335. /* oxid */
  5336. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5337. get_job_rcvoxid(phba, oldiocb));
  5338. } else {
  5339. icmd = &elsiocb->iocb;
  5340. oldcmd = &oldiocb->iocb;
  5341. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5342. ulp_context = elsiocb->iocb.ulpContext;
  5343. icmd->unsli3.rcvsli3.ox_id =
  5344. oldcmd->unsli3.rcvsli3.ox_id;
  5345. }
  5346. /* Xmit ADISC ACC response tag <ulpIoTag> */
  5347. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5348. "0130 Xmit ADISC ACC response iotag x%x xri: "
  5349. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  5350. elsiocb->iotag, ulp_context,
  5351. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5352. ndlp->nlp_rpi);
  5353. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  5354. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5355. pcmd += sizeof(uint32_t);
  5356. ap = (ADISC *) (pcmd);
  5357. ap->hardAL_PA = phba->fc_pref_ALPA;
  5358. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  5359. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  5360. ap->DID = be32_to_cpu(vport->fc_myDID);
  5361. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5362. "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
  5363. ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
  5364. phba->fc_stat.elsXmitACC++;
  5365. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  5366. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  5367. if (!elsiocb->ndlp) {
  5368. lpfc_els_free_iocb(phba, elsiocb);
  5369. return 1;
  5370. }
  5371. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5372. if (rc == IOCB_ERROR) {
  5373. lpfc_els_free_iocb(phba, elsiocb);
  5374. lpfc_nlp_put(ndlp);
  5375. return 1;
  5376. }
  5377. return 0;
  5378. }
  5379. /**
  5380. * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
  5381. * @vport: pointer to a virtual N_Port data structure.
  5382. * @oldiocb: pointer to the original lpfc command iocb data structure.
  5383. * @ndlp: pointer to a node-list data structure.
  5384. *
  5385. * This routine prepares and issues an Accept (ACC) response to Process
  5386. * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
  5387. * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
  5388. *
  5389. * Note that the ndlp reference count will be incremented by 1 for holding the
  5390. * ndlp and the reference to ndlp will be stored into the ndlp field of
  5391. * the IOCB for the completion callback function to the PRLI Accept response
  5392. * ELS IOCB command.
  5393. *
  5394. * Return code
  5395. * 0 - Successfully issued acc prli response
  5396. * 1 - Failed to issue acc prli response
  5397. **/
  5398. int
  5399. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  5400. struct lpfc_nodelist *ndlp)
  5401. {
  5402. struct lpfc_hba *phba = vport->phba;
  5403. PRLI *npr;
  5404. struct lpfc_nvme_prli *npr_nvme;
  5405. lpfc_vpd_t *vpd;
  5406. IOCB_t *icmd;
  5407. IOCB_t *oldcmd;
  5408. union lpfc_wqe128 *wqe;
  5409. struct lpfc_iocbq *elsiocb;
  5410. uint8_t *pcmd;
  5411. uint16_t cmdsize;
  5412. uint32_t prli_fc4_req, *req_payload;
  5413. struct lpfc_dmabuf *req_buf;
  5414. int rc;
  5415. u32 elsrspcmd, ulp_context;
  5416. /* Need the incoming PRLI payload to determine if the ACC is for an
  5417. * FC4 or NVME PRLI type. The PRLI type is at word 1.
  5418. */
  5419. req_buf = oldiocb->cmd_dmabuf;
  5420. req_payload = (((uint32_t *)req_buf->virt) + 1);
  5421. /* PRLI type payload is at byte 3 for FCP or NVME. */
  5422. prli_fc4_req = be32_to_cpu(*req_payload);
  5423. prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
  5424. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5425. "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
  5426. prli_fc4_req, *((uint32_t *)req_payload));
  5427. if (prli_fc4_req == PRLI_FCP_TYPE) {
  5428. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  5429. elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  5430. } else if (prli_fc4_req == PRLI_NVME_TYPE) {
  5431. cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
  5432. elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
  5433. } else {
  5434. return 1;
  5435. }
  5436. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  5437. ndlp->nlp_DID, elsrspcmd);
  5438. if (!elsiocb)
  5439. return 1;
  5440. if (phba->sli_rev == LPFC_SLI_REV4) {
  5441. wqe = &elsiocb->wqe;
  5442. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
  5443. get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
  5444. ulp_context = get_job_ulpcontext(phba, elsiocb);
  5445. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5446. get_job_rcvoxid(phba, oldiocb));
  5447. } else {
  5448. icmd = &elsiocb->iocb;
  5449. oldcmd = &oldiocb->iocb;
  5450. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5451. ulp_context = elsiocb->iocb.ulpContext;
  5452. icmd->unsli3.rcvsli3.ox_id =
  5453. oldcmd->unsli3.rcvsli3.ox_id;
  5454. }
  5455. /* Xmit PRLI ACC response tag <ulpIoTag> */
  5456. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5457. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  5458. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  5459. elsiocb->iotag, ulp_context,
  5460. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  5461. ndlp->nlp_rpi);
  5462. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  5463. memset(pcmd, 0, cmdsize);
  5464. *((uint32_t *)(pcmd)) = elsrspcmd;
  5465. pcmd += sizeof(uint32_t);
  5466. /* For PRLI, remainder of payload is PRLI parameter page */
  5467. vpd = &phba->vpd;
  5468. if (prli_fc4_req == PRLI_FCP_TYPE) {
  5469. /*
  5470. * If the remote port is a target and our firmware version
  5471. * is 3.20 or later, set the following bits for FC-TAPE
  5472. * support.
  5473. */
  5474. npr = (PRLI *) pcmd;
  5475. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  5476. (vpd->rev.feaLevelHigh >= 0x02)) {
  5477. npr->ConfmComplAllowed = 1;
  5478. npr->Retry = 1;
  5479. npr->TaskRetryIdReq = 1;
  5480. }
  5481. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  5482. npr->estabImagePair = 1;
  5483. npr->readXferRdyDis = 1;
  5484. npr->ConfmComplAllowed = 1;
  5485. npr->prliType = PRLI_FCP_TYPE;
  5486. npr->initiatorFunc = 1;
  5487. } else if (prli_fc4_req == PRLI_NVME_TYPE) {
  5488. /* Respond with an NVME PRLI Type */
  5489. npr_nvme = (struct lpfc_nvme_prli *) pcmd;
  5490. bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
  5491. bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
  5492. bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
  5493. if (phba->nvmet_support) {
  5494. bf_set(prli_tgt, npr_nvme, 1);
  5495. bf_set(prli_disc, npr_nvme, 1);
  5496. if (phba->cfg_nvme_enable_fb) {
  5497. bf_set(prli_fba, npr_nvme, 1);
  5498. /* TBD. Target mode needs to post buffers
  5499. * that support the configured first burst
  5500. * byte size.
  5501. */
  5502. bf_set(prli_fb_sz, npr_nvme,
  5503. phba->cfg_nvmet_fb_size);
  5504. }
  5505. } else {
  5506. bf_set(prli_init, npr_nvme, 1);
  5507. }
  5508. lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
  5509. "6015 NVME issue PRLI ACC word1 x%08x "
  5510. "word4 x%08x word5 x%08x flag x%x, "
  5511. "fcp_info x%x nlp_type x%x\n",
  5512. npr_nvme->word1, npr_nvme->word4,
  5513. npr_nvme->word5, ndlp->nlp_flag,
  5514. ndlp->nlp_fcp_info, ndlp->nlp_type);
  5515. npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
  5516. npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
  5517. npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
  5518. } else
  5519. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  5520. "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
  5521. prli_fc4_req, ndlp->nlp_fc4_type,
  5522. ndlp->nlp_DID);
  5523. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5524. "Issue ACC PRLI: did:x%x flg:x%x",
  5525. ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
  5526. phba->fc_stat.elsXmitACC++;
  5527. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  5528. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  5529. if (!elsiocb->ndlp) {
  5530. lpfc_els_free_iocb(phba, elsiocb);
  5531. return 1;
  5532. }
  5533. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5534. if (rc == IOCB_ERROR) {
  5535. lpfc_els_free_iocb(phba, elsiocb);
  5536. lpfc_nlp_put(ndlp);
  5537. return 1;
  5538. }
  5539. return 0;
  5540. }
  5541. /**
  5542. * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
  5543. * @vport: pointer to a virtual N_Port data structure.
  5544. * @format: rnid command format.
  5545. * @oldiocb: pointer to the original lpfc command iocb data structure.
  5546. * @ndlp: pointer to a node-list data structure.
  5547. *
  5548. * This routine issues a Request Node Identification Data (RNID) Accept
  5549. * (ACC) response. It constructs the RNID ACC response command according to
  5550. * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
  5551. * issue the response.
  5552. *
  5553. * Note that the ndlp reference count will be incremented by 1 for holding the
  5554. * ndlp and the reference to ndlp will be stored into the ndlp field of
  5555. * the IOCB for the completion callback function.
  5556. *
  5557. * Return code
  5558. * 0 - Successfully issued acc rnid response
  5559. * 1 - Failed to issue acc rnid response
  5560. **/
  5561. static int
  5562. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  5563. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  5564. {
  5565. struct lpfc_hba *phba = vport->phba;
  5566. RNID *rn;
  5567. IOCB_t *icmd, *oldcmd;
  5568. union lpfc_wqe128 *wqe;
  5569. struct lpfc_iocbq *elsiocb;
  5570. uint8_t *pcmd;
  5571. uint16_t cmdsize;
  5572. int rc;
  5573. u32 ulp_context;
  5574. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  5575. + (2 * sizeof(struct lpfc_name));
  5576. if (format)
  5577. cmdsize += sizeof(RNID_TOP_DISC);
  5578. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  5579. ndlp->nlp_DID, ELS_CMD_ACC);
  5580. if (!elsiocb)
  5581. return 1;
  5582. if (phba->sli_rev == LPFC_SLI_REV4) {
  5583. wqe = &elsiocb->wqe;
  5584. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
  5585. get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
  5586. ulp_context = get_job_ulpcontext(phba, elsiocb);
  5587. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5588. get_job_rcvoxid(phba, oldiocb));
  5589. } else {
  5590. icmd = &elsiocb->iocb;
  5591. oldcmd = &oldiocb->iocb;
  5592. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5593. ulp_context = elsiocb->iocb.ulpContext;
  5594. icmd->unsli3.rcvsli3.ox_id =
  5595. oldcmd->unsli3.rcvsli3.ox_id;
  5596. }
  5597. /* Xmit RNID ACC response tag <ulpIoTag> */
  5598. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5599. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  5600. elsiocb->iotag, ulp_context);
  5601. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  5602. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5603. pcmd += sizeof(uint32_t);
  5604. memset(pcmd, 0, sizeof(RNID));
  5605. rn = (RNID *) (pcmd);
  5606. rn->Format = format;
  5607. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  5608. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  5609. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  5610. switch (format) {
  5611. case 0:
  5612. rn->SpecificLen = 0;
  5613. break;
  5614. case RNID_TOPOLOGY_DISC:
  5615. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  5616. memcpy(&rn->un.topologyDisc.portName,
  5617. &vport->fc_portname, sizeof(struct lpfc_name));
  5618. rn->un.topologyDisc.unitType = RNID_HBA;
  5619. rn->un.topologyDisc.physPort = 0;
  5620. rn->un.topologyDisc.attachedNodes = 0;
  5621. break;
  5622. default:
  5623. rn->CommonLen = 0;
  5624. rn->SpecificLen = 0;
  5625. break;
  5626. }
  5627. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5628. "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
  5629. ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
  5630. phba->fc_stat.elsXmitACC++;
  5631. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  5632. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  5633. if (!elsiocb->ndlp) {
  5634. lpfc_els_free_iocb(phba, elsiocb);
  5635. return 1;
  5636. }
  5637. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5638. if (rc == IOCB_ERROR) {
  5639. lpfc_els_free_iocb(phba, elsiocb);
  5640. lpfc_nlp_put(ndlp);
  5641. return 1;
  5642. }
  5643. return 0;
  5644. }
  5645. /**
  5646. * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
  5647. * @vport: pointer to a virtual N_Port data structure.
  5648. * @iocb: pointer to the lpfc command iocb data structure.
  5649. * @ndlp: pointer to a node-list data structure.
  5650. *
  5651. * Return
  5652. **/
  5653. static void
  5654. lpfc_els_clear_rrq(struct lpfc_vport *vport,
  5655. struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
  5656. {
  5657. struct lpfc_hba *phba = vport->phba;
  5658. uint8_t *pcmd;
  5659. struct RRQ *rrq;
  5660. uint16_t rxid;
  5661. uint16_t xri;
  5662. struct lpfc_node_rrq *prrq;
  5663. pcmd = (uint8_t *)iocb->cmd_dmabuf->virt;
  5664. pcmd += sizeof(uint32_t);
  5665. rrq = (struct RRQ *)pcmd;
  5666. rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
  5667. rxid = bf_get(rrq_rxid, rrq);
  5668. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5669. "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
  5670. " x%x x%x\n",
  5671. be32_to_cpu(bf_get(rrq_did, rrq)),
  5672. bf_get(rrq_oxid, rrq),
  5673. rxid,
  5674. get_wqe_reqtag(iocb),
  5675. get_job_ulpcontext(phba, iocb));
  5676. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5677. "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
  5678. ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
  5679. if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
  5680. xri = bf_get(rrq_oxid, rrq);
  5681. else
  5682. xri = rxid;
  5683. prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
  5684. if (prrq)
  5685. lpfc_clr_rrq_active(phba, xri, prrq);
  5686. return;
  5687. }
  5688. /**
  5689. * lpfc_els_rsp_echo_acc - Issue echo acc response
  5690. * @vport: pointer to a virtual N_Port data structure.
  5691. * @data: pointer to echo data to return in the accept.
  5692. * @oldiocb: pointer to the original lpfc command iocb data structure.
  5693. * @ndlp: pointer to a node-list data structure.
  5694. *
  5695. * Return code
  5696. * 0 - Successfully issued acc echo response
  5697. * 1 - Failed to issue acc echo response
  5698. **/
  5699. static int
  5700. lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
  5701. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  5702. {
  5703. struct lpfc_hba *phba = vport->phba;
  5704. IOCB_t *icmd, *oldcmd;
  5705. union lpfc_wqe128 *wqe;
  5706. struct lpfc_iocbq *elsiocb;
  5707. uint8_t *pcmd;
  5708. uint16_t cmdsize;
  5709. int rc;
  5710. u32 ulp_context;
  5711. if (phba->sli_rev == LPFC_SLI_REV4)
  5712. cmdsize = oldiocb->wcqe_cmpl.total_data_placed;
  5713. else
  5714. cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
  5715. /* The accumulated length can exceed the BPL_SIZE. For
  5716. * now, use this as the limit
  5717. */
  5718. if (cmdsize > LPFC_BPL_SIZE)
  5719. cmdsize = LPFC_BPL_SIZE;
  5720. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  5721. ndlp->nlp_DID, ELS_CMD_ACC);
  5722. if (!elsiocb)
  5723. return 1;
  5724. if (phba->sli_rev == LPFC_SLI_REV4) {
  5725. wqe = &elsiocb->wqe;
  5726. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
  5727. get_job_ulpcontext(phba, oldiocb)); /* Xri / rx_id */
  5728. ulp_context = get_job_ulpcontext(phba, elsiocb);
  5729. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  5730. get_job_rcvoxid(phba, oldiocb));
  5731. } else {
  5732. icmd = &elsiocb->iocb;
  5733. oldcmd = &oldiocb->iocb;
  5734. icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
  5735. ulp_context = elsiocb->iocb.ulpContext;
  5736. icmd->unsli3.rcvsli3.ox_id =
  5737. oldcmd->unsli3.rcvsli3.ox_id;
  5738. }
  5739. /* Xmit ECHO ACC response tag <ulpIoTag> */
  5740. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  5741. "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
  5742. elsiocb->iotag, ulp_context);
  5743. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  5744. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  5745. pcmd += sizeof(uint32_t);
  5746. memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
  5747. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  5748. "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
  5749. ndlp->nlp_DID, ndlp->nlp_flag, kref_read(&ndlp->kref));
  5750. phba->fc_stat.elsXmitACC++;
  5751. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  5752. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  5753. if (!elsiocb->ndlp) {
  5754. lpfc_els_free_iocb(phba, elsiocb);
  5755. return 1;
  5756. }
  5757. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  5758. if (rc == IOCB_ERROR) {
  5759. lpfc_els_free_iocb(phba, elsiocb);
  5760. lpfc_nlp_put(ndlp);
  5761. return 1;
  5762. }
  5763. return 0;
  5764. }
  5765. /**
  5766. * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
  5767. * @vport: pointer to a host virtual N_Port data structure.
  5768. *
  5769. * This routine issues Address Discover (ADISC) ELS commands to those
  5770. * N_Ports which are in node port recovery state and ADISC has not been issued
  5771. * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
  5772. * lpfc_issue_els_adisc() routine, the per @vport number of discover count
  5773. * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
  5774. * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
  5775. * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
  5776. * IOCBs quit for later pick up. On the other hand, after walking through
  5777. * all the ndlps with the @vport and there is none ADISC IOCB issued, the
  5778. * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
  5779. * no more ADISC need to be sent.
  5780. *
  5781. * Return code
  5782. * The number of N_Ports with adisc issued.
  5783. **/
  5784. int
  5785. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  5786. {
  5787. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5788. struct lpfc_nodelist *ndlp, *next_ndlp;
  5789. int sentadisc = 0;
  5790. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  5791. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  5792. if (ndlp->nlp_state != NLP_STE_NPR_NODE ||
  5793. !(ndlp->nlp_flag & NLP_NPR_ADISC))
  5794. continue;
  5795. spin_lock_irq(&ndlp->lock);
  5796. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  5797. spin_unlock_irq(&ndlp->lock);
  5798. if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
  5799. /* This node was marked for ADISC but was not picked
  5800. * for discovery. This is possible if the node was
  5801. * missing in gidft response.
  5802. *
  5803. * At time of marking node for ADISC, we skipped unreg
  5804. * from backend
  5805. */
  5806. lpfc_nlp_unreg_node(vport, ndlp);
  5807. lpfc_unreg_rpi(vport, ndlp);
  5808. continue;
  5809. }
  5810. ndlp->nlp_prev_state = ndlp->nlp_state;
  5811. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  5812. lpfc_issue_els_adisc(vport, ndlp, 0);
  5813. sentadisc++;
  5814. vport->num_disc_nodes++;
  5815. if (vport->num_disc_nodes >=
  5816. vport->cfg_discovery_threads) {
  5817. spin_lock_irq(shost->host_lock);
  5818. vport->fc_flag |= FC_NLP_MORE;
  5819. spin_unlock_irq(shost->host_lock);
  5820. break;
  5821. }
  5822. }
  5823. if (sentadisc == 0) {
  5824. spin_lock_irq(shost->host_lock);
  5825. vport->fc_flag &= ~FC_NLP_MORE;
  5826. spin_unlock_irq(shost->host_lock);
  5827. }
  5828. return sentadisc;
  5829. }
  5830. /**
  5831. * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
  5832. * @vport: pointer to a host virtual N_Port data structure.
  5833. *
  5834. * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
  5835. * which are in node port recovery state, with a @vport. Each time an ELS
  5836. * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
  5837. * the per @vport number of discover count (num_disc_nodes) shall be
  5838. * incremented. If the num_disc_nodes reaches a pre-configured threshold
  5839. * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
  5840. * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
  5841. * later pick up. On the other hand, after walking through all the ndlps with
  5842. * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
  5843. * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
  5844. * PLOGI need to be sent.
  5845. *
  5846. * Return code
  5847. * The number of N_Ports with plogi issued.
  5848. **/
  5849. int
  5850. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  5851. {
  5852. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  5853. struct lpfc_nodelist *ndlp, *next_ndlp;
  5854. int sentplogi = 0;
  5855. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  5856. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  5857. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  5858. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  5859. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  5860. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  5861. ndlp->nlp_prev_state = ndlp->nlp_state;
  5862. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  5863. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  5864. sentplogi++;
  5865. vport->num_disc_nodes++;
  5866. if (vport->num_disc_nodes >=
  5867. vport->cfg_discovery_threads) {
  5868. spin_lock_irq(shost->host_lock);
  5869. vport->fc_flag |= FC_NLP_MORE;
  5870. spin_unlock_irq(shost->host_lock);
  5871. break;
  5872. }
  5873. }
  5874. }
  5875. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  5876. "6452 Discover PLOGI %d flag x%x\n",
  5877. sentplogi, vport->fc_flag);
  5878. if (sentplogi) {
  5879. lpfc_set_disctmo(vport);
  5880. }
  5881. else {
  5882. spin_lock_irq(shost->host_lock);
  5883. vport->fc_flag &= ~FC_NLP_MORE;
  5884. spin_unlock_irq(shost->host_lock);
  5885. }
  5886. return sentplogi;
  5887. }
  5888. static uint32_t
  5889. lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
  5890. uint32_t word0)
  5891. {
  5892. desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
  5893. desc->payload.els_req = word0;
  5894. desc->length = cpu_to_be32(sizeof(desc->payload));
  5895. return sizeof(struct fc_rdp_link_service_desc);
  5896. }
  5897. static uint32_t
  5898. lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
  5899. uint8_t *page_a0, uint8_t *page_a2)
  5900. {
  5901. uint16_t wavelength;
  5902. uint16_t temperature;
  5903. uint16_t rx_power;
  5904. uint16_t tx_bias;
  5905. uint16_t tx_power;
  5906. uint16_t vcc;
  5907. uint16_t flag = 0;
  5908. struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
  5909. struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
  5910. desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
  5911. trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
  5912. &page_a0[SSF_TRANSCEIVER_CODE_B4];
  5913. trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
  5914. &page_a0[SSF_TRANSCEIVER_CODE_B5];
  5915. if ((trasn_code_byte4->fc_sw_laser) ||
  5916. (trasn_code_byte5->fc_sw_laser_sl) ||
  5917. (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
  5918. flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
  5919. } else if (trasn_code_byte4->fc_lw_laser) {
  5920. wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
  5921. page_a0[SSF_WAVELENGTH_B0];
  5922. if (wavelength == SFP_WAVELENGTH_LC1310)
  5923. flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
  5924. if (wavelength == SFP_WAVELENGTH_LL1550)
  5925. flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
  5926. }
  5927. /* check if its SFP+ */
  5928. flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
  5929. SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
  5930. << SFP_FLAG_CT_SHIFT;
  5931. /* check if its OPTICAL */
  5932. flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
  5933. SFP_FLAG_IS_OPTICAL_PORT : 0)
  5934. << SFP_FLAG_IS_OPTICAL_SHIFT;
  5935. temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
  5936. page_a2[SFF_TEMPERATURE_B0]);
  5937. vcc = (page_a2[SFF_VCC_B1] << 8 |
  5938. page_a2[SFF_VCC_B0]);
  5939. tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
  5940. page_a2[SFF_TXPOWER_B0]);
  5941. tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
  5942. page_a2[SFF_TX_BIAS_CURRENT_B0]);
  5943. rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
  5944. page_a2[SFF_RXPOWER_B0]);
  5945. desc->sfp_info.temperature = cpu_to_be16(temperature);
  5946. desc->sfp_info.rx_power = cpu_to_be16(rx_power);
  5947. desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
  5948. desc->sfp_info.tx_power = cpu_to_be16(tx_power);
  5949. desc->sfp_info.vcc = cpu_to_be16(vcc);
  5950. desc->sfp_info.flags = cpu_to_be16(flag);
  5951. desc->length = cpu_to_be32(sizeof(desc->sfp_info));
  5952. return sizeof(struct fc_rdp_sfp_desc);
  5953. }
  5954. static uint32_t
  5955. lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
  5956. READ_LNK_VAR *stat)
  5957. {
  5958. uint32_t type;
  5959. desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
  5960. type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
  5961. desc->info.port_type = cpu_to_be32(type);
  5962. desc->info.link_status.link_failure_cnt =
  5963. cpu_to_be32(stat->linkFailureCnt);
  5964. desc->info.link_status.loss_of_synch_cnt =
  5965. cpu_to_be32(stat->lossSyncCnt);
  5966. desc->info.link_status.loss_of_signal_cnt =
  5967. cpu_to_be32(stat->lossSignalCnt);
  5968. desc->info.link_status.primitive_seq_proto_err =
  5969. cpu_to_be32(stat->primSeqErrCnt);
  5970. desc->info.link_status.invalid_trans_word =
  5971. cpu_to_be32(stat->invalidXmitWord);
  5972. desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
  5973. desc->length = cpu_to_be32(sizeof(desc->info));
  5974. return sizeof(struct fc_rdp_link_error_status_desc);
  5975. }
  5976. static uint32_t
  5977. lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
  5978. struct lpfc_vport *vport)
  5979. {
  5980. uint32_t bbCredit;
  5981. desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
  5982. bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
  5983. (vport->fc_sparam.cmn.bbCreditMsb << 8);
  5984. desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
  5985. if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
  5986. bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
  5987. (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
  5988. desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
  5989. } else {
  5990. desc->bbc_info.attached_port_bbc = 0;
  5991. }
  5992. desc->bbc_info.rtt = 0;
  5993. desc->length = cpu_to_be32(sizeof(desc->bbc_info));
  5994. return sizeof(struct fc_rdp_bbc_desc);
  5995. }
  5996. static uint32_t
  5997. lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
  5998. struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
  5999. {
  6000. uint32_t flags = 0;
  6001. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  6002. desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
  6003. desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
  6004. desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
  6005. desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
  6006. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
  6007. flags |= RDP_OET_HIGH_ALARM;
  6008. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
  6009. flags |= RDP_OET_LOW_ALARM;
  6010. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
  6011. flags |= RDP_OET_HIGH_WARNING;
  6012. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
  6013. flags |= RDP_OET_LOW_WARNING;
  6014. flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
  6015. desc->oed_info.function_flags = cpu_to_be32(flags);
  6016. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  6017. return sizeof(struct fc_rdp_oed_sfp_desc);
  6018. }
  6019. static uint32_t
  6020. lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
  6021. struct fc_rdp_oed_sfp_desc *desc,
  6022. uint8_t *page_a2)
  6023. {
  6024. uint32_t flags = 0;
  6025. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  6026. desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
  6027. desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
  6028. desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
  6029. desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
  6030. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
  6031. flags |= RDP_OET_HIGH_ALARM;
  6032. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
  6033. flags |= RDP_OET_LOW_ALARM;
  6034. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
  6035. flags |= RDP_OET_HIGH_WARNING;
  6036. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
  6037. flags |= RDP_OET_LOW_WARNING;
  6038. flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
  6039. desc->oed_info.function_flags = cpu_to_be32(flags);
  6040. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  6041. return sizeof(struct fc_rdp_oed_sfp_desc);
  6042. }
  6043. static uint32_t
  6044. lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
  6045. struct fc_rdp_oed_sfp_desc *desc,
  6046. uint8_t *page_a2)
  6047. {
  6048. uint32_t flags = 0;
  6049. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  6050. desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
  6051. desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
  6052. desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
  6053. desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
  6054. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
  6055. flags |= RDP_OET_HIGH_ALARM;
  6056. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
  6057. flags |= RDP_OET_LOW_ALARM;
  6058. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
  6059. flags |= RDP_OET_HIGH_WARNING;
  6060. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
  6061. flags |= RDP_OET_LOW_WARNING;
  6062. flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
  6063. desc->oed_info.function_flags = cpu_to_be32(flags);
  6064. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  6065. return sizeof(struct fc_rdp_oed_sfp_desc);
  6066. }
  6067. static uint32_t
  6068. lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
  6069. struct fc_rdp_oed_sfp_desc *desc,
  6070. uint8_t *page_a2)
  6071. {
  6072. uint32_t flags = 0;
  6073. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  6074. desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
  6075. desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
  6076. desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
  6077. desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
  6078. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
  6079. flags |= RDP_OET_HIGH_ALARM;
  6080. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
  6081. flags |= RDP_OET_LOW_ALARM;
  6082. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
  6083. flags |= RDP_OET_HIGH_WARNING;
  6084. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
  6085. flags |= RDP_OET_LOW_WARNING;
  6086. flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
  6087. desc->oed_info.function_flags = cpu_to_be32(flags);
  6088. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  6089. return sizeof(struct fc_rdp_oed_sfp_desc);
  6090. }
  6091. static uint32_t
  6092. lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
  6093. struct fc_rdp_oed_sfp_desc *desc,
  6094. uint8_t *page_a2)
  6095. {
  6096. uint32_t flags = 0;
  6097. desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
  6098. desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
  6099. desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
  6100. desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
  6101. desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
  6102. if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
  6103. flags |= RDP_OET_HIGH_ALARM;
  6104. if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
  6105. flags |= RDP_OET_LOW_ALARM;
  6106. if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
  6107. flags |= RDP_OET_HIGH_WARNING;
  6108. if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
  6109. flags |= RDP_OET_LOW_WARNING;
  6110. flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
  6111. desc->oed_info.function_flags = cpu_to_be32(flags);
  6112. desc->length = cpu_to_be32(sizeof(desc->oed_info));
  6113. return sizeof(struct fc_rdp_oed_sfp_desc);
  6114. }
  6115. static uint32_t
  6116. lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
  6117. uint8_t *page_a0, struct lpfc_vport *vport)
  6118. {
  6119. desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
  6120. memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
  6121. memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
  6122. memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
  6123. memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
  6124. memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
  6125. desc->length = cpu_to_be32(sizeof(desc->opd_info));
  6126. return sizeof(struct fc_rdp_opd_sfp_desc);
  6127. }
  6128. static uint32_t
  6129. lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
  6130. {
  6131. if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
  6132. return 0;
  6133. desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
  6134. desc->info.CorrectedBlocks =
  6135. cpu_to_be32(stat->fecCorrBlkCount);
  6136. desc->info.UncorrectableBlocks =
  6137. cpu_to_be32(stat->fecUncorrBlkCount);
  6138. desc->length = cpu_to_be32(sizeof(desc->info));
  6139. return sizeof(struct fc_fec_rdp_desc);
  6140. }
  6141. static uint32_t
  6142. lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
  6143. {
  6144. uint16_t rdp_cap = 0;
  6145. uint16_t rdp_speed;
  6146. desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
  6147. switch (phba->fc_linkspeed) {
  6148. case LPFC_LINK_SPEED_1GHZ:
  6149. rdp_speed = RDP_PS_1GB;
  6150. break;
  6151. case LPFC_LINK_SPEED_2GHZ:
  6152. rdp_speed = RDP_PS_2GB;
  6153. break;
  6154. case LPFC_LINK_SPEED_4GHZ:
  6155. rdp_speed = RDP_PS_4GB;
  6156. break;
  6157. case LPFC_LINK_SPEED_8GHZ:
  6158. rdp_speed = RDP_PS_8GB;
  6159. break;
  6160. case LPFC_LINK_SPEED_10GHZ:
  6161. rdp_speed = RDP_PS_10GB;
  6162. break;
  6163. case LPFC_LINK_SPEED_16GHZ:
  6164. rdp_speed = RDP_PS_16GB;
  6165. break;
  6166. case LPFC_LINK_SPEED_32GHZ:
  6167. rdp_speed = RDP_PS_32GB;
  6168. break;
  6169. case LPFC_LINK_SPEED_64GHZ:
  6170. rdp_speed = RDP_PS_64GB;
  6171. break;
  6172. case LPFC_LINK_SPEED_128GHZ:
  6173. rdp_speed = RDP_PS_128GB;
  6174. break;
  6175. case LPFC_LINK_SPEED_256GHZ:
  6176. rdp_speed = RDP_PS_256GB;
  6177. break;
  6178. default:
  6179. rdp_speed = RDP_PS_UNKNOWN;
  6180. break;
  6181. }
  6182. desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
  6183. if (phba->lmt & LMT_256Gb)
  6184. rdp_cap |= RDP_PS_256GB;
  6185. if (phba->lmt & LMT_128Gb)
  6186. rdp_cap |= RDP_PS_128GB;
  6187. if (phba->lmt & LMT_64Gb)
  6188. rdp_cap |= RDP_PS_64GB;
  6189. if (phba->lmt & LMT_32Gb)
  6190. rdp_cap |= RDP_PS_32GB;
  6191. if (phba->lmt & LMT_16Gb)
  6192. rdp_cap |= RDP_PS_16GB;
  6193. if (phba->lmt & LMT_10Gb)
  6194. rdp_cap |= RDP_PS_10GB;
  6195. if (phba->lmt & LMT_8Gb)
  6196. rdp_cap |= RDP_PS_8GB;
  6197. if (phba->lmt & LMT_4Gb)
  6198. rdp_cap |= RDP_PS_4GB;
  6199. if (phba->lmt & LMT_2Gb)
  6200. rdp_cap |= RDP_PS_2GB;
  6201. if (phba->lmt & LMT_1Gb)
  6202. rdp_cap |= RDP_PS_1GB;
  6203. if (rdp_cap == 0)
  6204. rdp_cap = RDP_CAP_UNKNOWN;
  6205. if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
  6206. rdp_cap |= RDP_CAP_USER_CONFIGURED;
  6207. desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
  6208. desc->length = cpu_to_be32(sizeof(desc->info));
  6209. return sizeof(struct fc_rdp_port_speed_desc);
  6210. }
  6211. static uint32_t
  6212. lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
  6213. struct lpfc_vport *vport)
  6214. {
  6215. desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
  6216. memcpy(desc->port_names.wwnn, &vport->fc_nodename,
  6217. sizeof(desc->port_names.wwnn));
  6218. memcpy(desc->port_names.wwpn, &vport->fc_portname,
  6219. sizeof(desc->port_names.wwpn));
  6220. desc->length = cpu_to_be32(sizeof(desc->port_names));
  6221. return sizeof(struct fc_rdp_port_name_desc);
  6222. }
  6223. static uint32_t
  6224. lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
  6225. struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  6226. {
  6227. desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
  6228. if (vport->fc_flag & FC_FABRIC) {
  6229. memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
  6230. sizeof(desc->port_names.wwnn));
  6231. memcpy(desc->port_names.wwpn, &vport->fabric_portname,
  6232. sizeof(desc->port_names.wwpn));
  6233. } else { /* Point to Point */
  6234. memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
  6235. sizeof(desc->port_names.wwnn));
  6236. memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
  6237. sizeof(desc->port_names.wwpn));
  6238. }
  6239. desc->length = cpu_to_be32(sizeof(desc->port_names));
  6240. return sizeof(struct fc_rdp_port_name_desc);
  6241. }
  6242. static void
  6243. lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
  6244. int status)
  6245. {
  6246. struct lpfc_nodelist *ndlp = rdp_context->ndlp;
  6247. struct lpfc_vport *vport = ndlp->vport;
  6248. struct lpfc_iocbq *elsiocb;
  6249. struct ulp_bde64 *bpl;
  6250. IOCB_t *icmd;
  6251. union lpfc_wqe128 *wqe;
  6252. uint8_t *pcmd;
  6253. struct ls_rjt *stat;
  6254. struct fc_rdp_res_frame *rdp_res;
  6255. uint32_t cmdsize, len;
  6256. uint16_t *flag_ptr;
  6257. int rc;
  6258. u32 ulp_context;
  6259. if (status != SUCCESS)
  6260. goto error;
  6261. /* This will change once we know the true size of the RDP payload */
  6262. cmdsize = sizeof(struct fc_rdp_res_frame);
  6263. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
  6264. lpfc_max_els_tries, rdp_context->ndlp,
  6265. rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
  6266. if (!elsiocb)
  6267. goto free_rdp_context;
  6268. ulp_context = get_job_ulpcontext(phba, elsiocb);
  6269. if (phba->sli_rev == LPFC_SLI_REV4) {
  6270. wqe = &elsiocb->wqe;
  6271. /* ox-id of the frame */
  6272. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  6273. rdp_context->ox_id);
  6274. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  6275. rdp_context->rx_id);
  6276. } else {
  6277. icmd = &elsiocb->iocb;
  6278. icmd->ulpContext = rdp_context->rx_id;
  6279. icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
  6280. }
  6281. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6282. "2171 Xmit RDP response tag x%x xri x%x, "
  6283. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
  6284. elsiocb->iotag, ulp_context,
  6285. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  6286. ndlp->nlp_rpi);
  6287. rdp_res = (struct fc_rdp_res_frame *)elsiocb->cmd_dmabuf->virt;
  6288. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  6289. memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
  6290. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  6291. /* Update Alarm and Warning */
  6292. flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
  6293. phba->sfp_alarm |= *flag_ptr;
  6294. flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
  6295. phba->sfp_warning |= *flag_ptr;
  6296. /* For RDP payload */
  6297. len = 8;
  6298. len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
  6299. (len + pcmd), ELS_CMD_RDP);
  6300. len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
  6301. rdp_context->page_a0, rdp_context->page_a2);
  6302. len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
  6303. phba);
  6304. len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
  6305. (len + pcmd), &rdp_context->link_stat);
  6306. len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
  6307. (len + pcmd), vport);
  6308. len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
  6309. (len + pcmd), vport, ndlp);
  6310. len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
  6311. &rdp_context->link_stat);
  6312. len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
  6313. &rdp_context->link_stat, vport);
  6314. len += lpfc_rdp_res_oed_temp_desc(phba,
  6315. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  6316. rdp_context->page_a2);
  6317. len += lpfc_rdp_res_oed_voltage_desc(phba,
  6318. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  6319. rdp_context->page_a2);
  6320. len += lpfc_rdp_res_oed_txbias_desc(phba,
  6321. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  6322. rdp_context->page_a2);
  6323. len += lpfc_rdp_res_oed_txpower_desc(phba,
  6324. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  6325. rdp_context->page_a2);
  6326. len += lpfc_rdp_res_oed_rxpower_desc(phba,
  6327. (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
  6328. rdp_context->page_a2);
  6329. len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
  6330. rdp_context->page_a0, vport);
  6331. rdp_res->length = cpu_to_be32(len - 8);
  6332. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  6333. /* Now that we know the true size of the payload, update the BPL */
  6334. bpl = (struct ulp_bde64 *)elsiocb->bpl_dmabuf->virt;
  6335. bpl->tus.f.bdeSize = len;
  6336. bpl->tus.f.bdeFlags = 0;
  6337. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  6338. phba->fc_stat.elsXmitACC++;
  6339. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  6340. if (!elsiocb->ndlp) {
  6341. lpfc_els_free_iocb(phba, elsiocb);
  6342. goto free_rdp_context;
  6343. }
  6344. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  6345. if (rc == IOCB_ERROR) {
  6346. lpfc_els_free_iocb(phba, elsiocb);
  6347. lpfc_nlp_put(ndlp);
  6348. }
  6349. goto free_rdp_context;
  6350. error:
  6351. cmdsize = 2 * sizeof(uint32_t);
  6352. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
  6353. ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
  6354. if (!elsiocb)
  6355. goto free_rdp_context;
  6356. if (phba->sli_rev == LPFC_SLI_REV4) {
  6357. wqe = &elsiocb->wqe;
  6358. /* ox-id of the frame */
  6359. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  6360. rdp_context->ox_id);
  6361. bf_set(wqe_ctxt_tag,
  6362. &wqe->xmit_els_rsp.wqe_com,
  6363. rdp_context->rx_id);
  6364. } else {
  6365. icmd = &elsiocb->iocb;
  6366. icmd->ulpContext = rdp_context->rx_id;
  6367. icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
  6368. }
  6369. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  6370. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  6371. stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
  6372. stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  6373. phba->fc_stat.elsXmitLSRJT++;
  6374. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  6375. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  6376. if (!elsiocb->ndlp) {
  6377. lpfc_els_free_iocb(phba, elsiocb);
  6378. goto free_rdp_context;
  6379. }
  6380. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  6381. if (rc == IOCB_ERROR) {
  6382. lpfc_els_free_iocb(phba, elsiocb);
  6383. lpfc_nlp_put(ndlp);
  6384. }
  6385. free_rdp_context:
  6386. /* This reference put is for the original unsolicited RDP. If the
  6387. * prep failed, there is no reference to remove.
  6388. */
  6389. lpfc_nlp_put(ndlp);
  6390. kfree(rdp_context);
  6391. }
  6392. static int
  6393. lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
  6394. {
  6395. LPFC_MBOXQ_t *mbox = NULL;
  6396. int rc;
  6397. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6398. if (!mbox) {
  6399. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
  6400. "7105 failed to allocate mailbox memory");
  6401. return 1;
  6402. }
  6403. if (lpfc_sli4_dump_page_a0(phba, mbox))
  6404. goto rdp_fail;
  6405. mbox->vport = rdp_context->ndlp->vport;
  6406. mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
  6407. mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
  6408. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  6409. if (rc == MBX_NOT_FINISHED) {
  6410. lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
  6411. return 1;
  6412. }
  6413. return 0;
  6414. rdp_fail:
  6415. mempool_free(mbox, phba->mbox_mem_pool);
  6416. return 1;
  6417. }
  6418. /*
  6419. * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
  6420. * @vport: pointer to a host virtual N_Port data structure.
  6421. * @cmdiocb: pointer to lpfc command iocb data structure.
  6422. * @ndlp: pointer to a node-list data structure.
  6423. *
  6424. * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
  6425. * IOCB. First, the payload of the unsolicited RDP is checked.
  6426. * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
  6427. * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
  6428. * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
  6429. * gather all data and send RDP response.
  6430. *
  6431. * Return code
  6432. * 0 - Sent the acc response
  6433. * 1 - Sent the reject response.
  6434. */
  6435. static int
  6436. lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6437. struct lpfc_nodelist *ndlp)
  6438. {
  6439. struct lpfc_hba *phba = vport->phba;
  6440. struct lpfc_dmabuf *pcmd;
  6441. uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
  6442. struct fc_rdp_req_frame *rdp_req;
  6443. struct lpfc_rdp_context *rdp_context;
  6444. union lpfc_wqe128 *cmd = NULL;
  6445. struct ls_rjt stat;
  6446. if (phba->sli_rev < LPFC_SLI_REV4 ||
  6447. bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
  6448. LPFC_SLI_INTF_IF_TYPE_2) {
  6449. rjt_err = LSRJT_UNABLE_TPC;
  6450. rjt_expl = LSEXP_REQ_UNSUPPORTED;
  6451. goto error;
  6452. }
  6453. if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
  6454. rjt_err = LSRJT_UNABLE_TPC;
  6455. rjt_expl = LSEXP_REQ_UNSUPPORTED;
  6456. goto error;
  6457. }
  6458. pcmd = cmdiocb->cmd_dmabuf;
  6459. rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
  6460. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6461. "2422 ELS RDP Request "
  6462. "dec len %d tag x%x port_id %d len %d\n",
  6463. be32_to_cpu(rdp_req->rdp_des_length),
  6464. be32_to_cpu(rdp_req->nport_id_desc.tag),
  6465. be32_to_cpu(rdp_req->nport_id_desc.nport_id),
  6466. be32_to_cpu(rdp_req->nport_id_desc.length));
  6467. if (sizeof(struct fc_rdp_nport_desc) !=
  6468. be32_to_cpu(rdp_req->rdp_des_length))
  6469. goto rjt_logerr;
  6470. if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
  6471. goto rjt_logerr;
  6472. if (RDP_NPORT_ID_SIZE !=
  6473. be32_to_cpu(rdp_req->nport_id_desc.length))
  6474. goto rjt_logerr;
  6475. rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
  6476. if (!rdp_context) {
  6477. rjt_err = LSRJT_UNABLE_TPC;
  6478. goto error;
  6479. }
  6480. cmd = &cmdiocb->wqe;
  6481. rdp_context->ndlp = lpfc_nlp_get(ndlp);
  6482. if (!rdp_context->ndlp) {
  6483. kfree(rdp_context);
  6484. rjt_err = LSRJT_UNABLE_TPC;
  6485. goto error;
  6486. }
  6487. rdp_context->ox_id = bf_get(wqe_rcvoxid,
  6488. &cmd->xmit_els_rsp.wqe_com);
  6489. rdp_context->rx_id = bf_get(wqe_ctxt_tag,
  6490. &cmd->xmit_els_rsp.wqe_com);
  6491. rdp_context->cmpl = lpfc_els_rdp_cmpl;
  6492. if (lpfc_get_rdp_info(phba, rdp_context)) {
  6493. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
  6494. "2423 Unable to send mailbox");
  6495. kfree(rdp_context);
  6496. rjt_err = LSRJT_UNABLE_TPC;
  6497. lpfc_nlp_put(ndlp);
  6498. goto error;
  6499. }
  6500. return 0;
  6501. rjt_logerr:
  6502. rjt_err = LSRJT_LOGICAL_ERR;
  6503. error:
  6504. memset(&stat, 0, sizeof(stat));
  6505. stat.un.b.lsRjtRsnCode = rjt_err;
  6506. stat.un.b.lsRjtRsnCodeExp = rjt_expl;
  6507. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  6508. return 1;
  6509. }
  6510. static void
  6511. lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  6512. {
  6513. MAILBOX_t *mb;
  6514. IOCB_t *icmd;
  6515. union lpfc_wqe128 *wqe;
  6516. uint8_t *pcmd;
  6517. struct lpfc_iocbq *elsiocb;
  6518. struct lpfc_nodelist *ndlp;
  6519. struct ls_rjt *stat;
  6520. union lpfc_sli4_cfg_shdr *shdr;
  6521. struct lpfc_lcb_context *lcb_context;
  6522. struct fc_lcb_res_frame *lcb_res;
  6523. uint32_t cmdsize, shdr_status, shdr_add_status;
  6524. int rc;
  6525. mb = &pmb->u.mb;
  6526. lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
  6527. ndlp = lcb_context->ndlp;
  6528. pmb->ctx_ndlp = NULL;
  6529. pmb->ctx_buf = NULL;
  6530. shdr = (union lpfc_sli4_cfg_shdr *)
  6531. &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
  6532. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6533. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  6534. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
  6535. "0194 SET_BEACON_CONFIG mailbox "
  6536. "completed with status x%x add_status x%x,"
  6537. " mbx status x%x\n",
  6538. shdr_status, shdr_add_status, mb->mbxStatus);
  6539. if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
  6540. (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
  6541. (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
  6542. mempool_free(pmb, phba->mbox_mem_pool);
  6543. goto error;
  6544. }
  6545. mempool_free(pmb, phba->mbox_mem_pool);
  6546. cmdsize = sizeof(struct fc_lcb_res_frame);
  6547. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  6548. lpfc_max_els_tries, ndlp,
  6549. ndlp->nlp_DID, ELS_CMD_ACC);
  6550. /* Decrement the ndlp reference count from previous mbox command */
  6551. lpfc_nlp_put(ndlp);
  6552. if (!elsiocb)
  6553. goto free_lcb_context;
  6554. lcb_res = (struct fc_lcb_res_frame *)elsiocb->cmd_dmabuf->virt;
  6555. memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
  6556. if (phba->sli_rev == LPFC_SLI_REV4) {
  6557. wqe = &elsiocb->wqe;
  6558. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
  6559. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  6560. lcb_context->ox_id);
  6561. } else {
  6562. icmd = &elsiocb->iocb;
  6563. icmd->ulpContext = lcb_context->rx_id;
  6564. icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
  6565. }
  6566. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  6567. *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
  6568. lcb_res->lcb_sub_command = lcb_context->sub_command;
  6569. lcb_res->lcb_type = lcb_context->type;
  6570. lcb_res->capability = lcb_context->capability;
  6571. lcb_res->lcb_frequency = lcb_context->frequency;
  6572. lcb_res->lcb_duration = lcb_context->duration;
  6573. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  6574. phba->fc_stat.elsXmitACC++;
  6575. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  6576. if (!elsiocb->ndlp) {
  6577. lpfc_els_free_iocb(phba, elsiocb);
  6578. goto out;
  6579. }
  6580. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  6581. if (rc == IOCB_ERROR) {
  6582. lpfc_els_free_iocb(phba, elsiocb);
  6583. lpfc_nlp_put(ndlp);
  6584. }
  6585. out:
  6586. kfree(lcb_context);
  6587. return;
  6588. error:
  6589. cmdsize = sizeof(struct fc_lcb_res_frame);
  6590. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  6591. lpfc_max_els_tries, ndlp,
  6592. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  6593. lpfc_nlp_put(ndlp);
  6594. if (!elsiocb)
  6595. goto free_lcb_context;
  6596. if (phba->sli_rev == LPFC_SLI_REV4) {
  6597. wqe = &elsiocb->wqe;
  6598. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, lcb_context->rx_id);
  6599. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  6600. lcb_context->ox_id);
  6601. } else {
  6602. icmd = &elsiocb->iocb;
  6603. icmd->ulpContext = lcb_context->rx_id;
  6604. icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
  6605. }
  6606. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  6607. *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
  6608. stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
  6609. stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  6610. if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
  6611. stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
  6612. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  6613. phba->fc_stat.elsXmitLSRJT++;
  6614. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  6615. if (!elsiocb->ndlp) {
  6616. lpfc_els_free_iocb(phba, elsiocb);
  6617. goto free_lcb_context;
  6618. }
  6619. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  6620. if (rc == IOCB_ERROR) {
  6621. lpfc_els_free_iocb(phba, elsiocb);
  6622. lpfc_nlp_put(ndlp);
  6623. }
  6624. free_lcb_context:
  6625. kfree(lcb_context);
  6626. }
  6627. static int
  6628. lpfc_sli4_set_beacon(struct lpfc_vport *vport,
  6629. struct lpfc_lcb_context *lcb_context,
  6630. uint32_t beacon_state)
  6631. {
  6632. struct lpfc_hba *phba = vport->phba;
  6633. union lpfc_sli4_cfg_shdr *cfg_shdr;
  6634. LPFC_MBOXQ_t *mbox = NULL;
  6635. uint32_t len;
  6636. int rc;
  6637. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6638. if (!mbox)
  6639. return 1;
  6640. cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  6641. len = sizeof(struct lpfc_mbx_set_beacon_config) -
  6642. sizeof(struct lpfc_sli4_cfg_mhdr);
  6643. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  6644. LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
  6645. LPFC_SLI4_MBX_EMBED);
  6646. mbox->ctx_ndlp = (void *)lcb_context;
  6647. mbox->vport = phba->pport;
  6648. mbox->mbox_cmpl = lpfc_els_lcb_rsp;
  6649. bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
  6650. phba->sli4_hba.physical_port);
  6651. bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
  6652. beacon_state);
  6653. mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
  6654. /*
  6655. * Check bv1s bit before issuing the mailbox
  6656. * if bv1s == 1, LCB V1 supported
  6657. * else, LCB V0 supported
  6658. */
  6659. if (phba->sli4_hba.pc_sli4_params.bv1s) {
  6660. /* COMMON_SET_BEACON_CONFIG_V1 */
  6661. cfg_shdr->request.word9 = BEACON_VERSION_V1;
  6662. lcb_context->capability |= LCB_CAPABILITY_DURATION;
  6663. bf_set(lpfc_mbx_set_beacon_port_type,
  6664. &mbox->u.mqe.un.beacon_config, 0);
  6665. bf_set(lpfc_mbx_set_beacon_duration_v1,
  6666. &mbox->u.mqe.un.beacon_config,
  6667. be16_to_cpu(lcb_context->duration));
  6668. } else {
  6669. /* COMMON_SET_BEACON_CONFIG_V0 */
  6670. if (be16_to_cpu(lcb_context->duration) != 0) {
  6671. mempool_free(mbox, phba->mbox_mem_pool);
  6672. return 1;
  6673. }
  6674. cfg_shdr->request.word9 = BEACON_VERSION_V0;
  6675. lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
  6676. bf_set(lpfc_mbx_set_beacon_state,
  6677. &mbox->u.mqe.un.beacon_config, beacon_state);
  6678. bf_set(lpfc_mbx_set_beacon_port_type,
  6679. &mbox->u.mqe.un.beacon_config, 1);
  6680. bf_set(lpfc_mbx_set_beacon_duration,
  6681. &mbox->u.mqe.un.beacon_config,
  6682. be16_to_cpu(lcb_context->duration));
  6683. }
  6684. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  6685. if (rc == MBX_NOT_FINISHED) {
  6686. mempool_free(mbox, phba->mbox_mem_pool);
  6687. return 1;
  6688. }
  6689. return 0;
  6690. }
  6691. /**
  6692. * lpfc_els_rcv_lcb - Process an unsolicited LCB
  6693. * @vport: pointer to a host virtual N_Port data structure.
  6694. * @cmdiocb: pointer to lpfc command iocb data structure.
  6695. * @ndlp: pointer to a node-list data structure.
  6696. *
  6697. * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
  6698. * First, the payload of the unsolicited LCB is checked.
  6699. * Then based on Subcommand beacon will either turn on or off.
  6700. *
  6701. * Return code
  6702. * 0 - Sent the acc response
  6703. * 1 - Sent the reject response.
  6704. **/
  6705. static int
  6706. lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6707. struct lpfc_nodelist *ndlp)
  6708. {
  6709. struct lpfc_hba *phba = vport->phba;
  6710. struct lpfc_dmabuf *pcmd;
  6711. uint8_t *lp;
  6712. struct fc_lcb_request_frame *beacon;
  6713. struct lpfc_lcb_context *lcb_context;
  6714. u8 state, rjt_err = 0;
  6715. struct ls_rjt stat;
  6716. pcmd = cmdiocb->cmd_dmabuf;
  6717. lp = (uint8_t *)pcmd->virt;
  6718. beacon = (struct fc_lcb_request_frame *)pcmd->virt;
  6719. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  6720. "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
  6721. "type x%x frequency %x duration x%x\n",
  6722. lp[0], lp[1], lp[2],
  6723. beacon->lcb_command,
  6724. beacon->lcb_sub_command,
  6725. beacon->lcb_type,
  6726. beacon->lcb_frequency,
  6727. be16_to_cpu(beacon->lcb_duration));
  6728. if (beacon->lcb_sub_command != LPFC_LCB_ON &&
  6729. beacon->lcb_sub_command != LPFC_LCB_OFF) {
  6730. rjt_err = LSRJT_CMD_UNSUPPORTED;
  6731. goto rjt;
  6732. }
  6733. if (phba->sli_rev < LPFC_SLI_REV4 ||
  6734. phba->hba_flag & HBA_FCOE_MODE ||
  6735. (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
  6736. LPFC_SLI_INTF_IF_TYPE_2)) {
  6737. rjt_err = LSRJT_CMD_UNSUPPORTED;
  6738. goto rjt;
  6739. }
  6740. lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
  6741. if (!lcb_context) {
  6742. rjt_err = LSRJT_UNABLE_TPC;
  6743. goto rjt;
  6744. }
  6745. state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
  6746. lcb_context->sub_command = beacon->lcb_sub_command;
  6747. lcb_context->capability = 0;
  6748. lcb_context->type = beacon->lcb_type;
  6749. lcb_context->frequency = beacon->lcb_frequency;
  6750. lcb_context->duration = beacon->lcb_duration;
  6751. lcb_context->ox_id = get_job_rcvoxid(phba, cmdiocb);
  6752. lcb_context->rx_id = get_job_ulpcontext(phba, cmdiocb);
  6753. lcb_context->ndlp = lpfc_nlp_get(ndlp);
  6754. if (!lcb_context->ndlp) {
  6755. rjt_err = LSRJT_UNABLE_TPC;
  6756. goto rjt_free;
  6757. }
  6758. if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
  6759. lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
  6760. "0193 failed to send mail box");
  6761. lpfc_nlp_put(ndlp);
  6762. rjt_err = LSRJT_UNABLE_TPC;
  6763. goto rjt_free;
  6764. }
  6765. return 0;
  6766. rjt_free:
  6767. kfree(lcb_context);
  6768. rjt:
  6769. memset(&stat, 0, sizeof(stat));
  6770. stat.un.b.lsRjtRsnCode = rjt_err;
  6771. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  6772. return 1;
  6773. }
  6774. /**
  6775. * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
  6776. * @vport: pointer to a host virtual N_Port data structure.
  6777. *
  6778. * This routine cleans up any Registration State Change Notification
  6779. * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
  6780. * @vport together with the host_lock is used to prevent multiple thread
  6781. * trying to access the RSCN array on a same @vport at the same time.
  6782. **/
  6783. void
  6784. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  6785. {
  6786. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6787. struct lpfc_hba *phba = vport->phba;
  6788. int i;
  6789. spin_lock_irq(shost->host_lock);
  6790. if (vport->fc_rscn_flush) {
  6791. /* Another thread is walking fc_rscn_id_list on this vport */
  6792. spin_unlock_irq(shost->host_lock);
  6793. return;
  6794. }
  6795. /* Indicate we are walking lpfc_els_flush_rscn on this vport */
  6796. vport->fc_rscn_flush = 1;
  6797. spin_unlock_irq(shost->host_lock);
  6798. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  6799. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  6800. vport->fc_rscn_id_list[i] = NULL;
  6801. }
  6802. spin_lock_irq(shost->host_lock);
  6803. vport->fc_rscn_id_cnt = 0;
  6804. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  6805. spin_unlock_irq(shost->host_lock);
  6806. lpfc_can_disctmo(vport);
  6807. /* Indicate we are done walking this fc_rscn_id_list */
  6808. vport->fc_rscn_flush = 0;
  6809. }
  6810. /**
  6811. * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
  6812. * @vport: pointer to a host virtual N_Port data structure.
  6813. * @did: remote destination port identifier.
  6814. *
  6815. * This routine checks whether there is any pending Registration State
  6816. * Configuration Notification (RSCN) to a @did on @vport.
  6817. *
  6818. * Return code
  6819. * None zero - The @did matched with a pending rscn
  6820. * 0 - not able to match @did with a pending rscn
  6821. **/
  6822. int
  6823. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  6824. {
  6825. D_ID ns_did;
  6826. D_ID rscn_did;
  6827. uint32_t *lp;
  6828. uint32_t payload_len, i;
  6829. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6830. ns_did.un.word = did;
  6831. /* Never match fabric nodes for RSCNs */
  6832. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  6833. return 0;
  6834. /* If we are doing a FULL RSCN rediscovery, match everything */
  6835. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  6836. return did;
  6837. spin_lock_irq(shost->host_lock);
  6838. if (vport->fc_rscn_flush) {
  6839. /* Another thread is walking fc_rscn_id_list on this vport */
  6840. spin_unlock_irq(shost->host_lock);
  6841. return 0;
  6842. }
  6843. /* Indicate we are walking fc_rscn_id_list on this vport */
  6844. vport->fc_rscn_flush = 1;
  6845. spin_unlock_irq(shost->host_lock);
  6846. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  6847. lp = vport->fc_rscn_id_list[i]->virt;
  6848. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  6849. payload_len -= sizeof(uint32_t); /* take off word 0 */
  6850. while (payload_len) {
  6851. rscn_did.un.word = be32_to_cpu(*lp++);
  6852. payload_len -= sizeof(uint32_t);
  6853. switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
  6854. case RSCN_ADDRESS_FORMAT_PORT:
  6855. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  6856. && (ns_did.un.b.area == rscn_did.un.b.area)
  6857. && (ns_did.un.b.id == rscn_did.un.b.id))
  6858. goto return_did_out;
  6859. break;
  6860. case RSCN_ADDRESS_FORMAT_AREA:
  6861. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  6862. && (ns_did.un.b.area == rscn_did.un.b.area))
  6863. goto return_did_out;
  6864. break;
  6865. case RSCN_ADDRESS_FORMAT_DOMAIN:
  6866. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  6867. goto return_did_out;
  6868. break;
  6869. case RSCN_ADDRESS_FORMAT_FABRIC:
  6870. goto return_did_out;
  6871. }
  6872. }
  6873. }
  6874. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  6875. vport->fc_rscn_flush = 0;
  6876. return 0;
  6877. return_did_out:
  6878. /* Indicate we are done with walking fc_rscn_id_list on this vport */
  6879. vport->fc_rscn_flush = 0;
  6880. return did;
  6881. }
  6882. /**
  6883. * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
  6884. * @vport: pointer to a host virtual N_Port data structure.
  6885. *
  6886. * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
  6887. * state machine for a @vport's nodes that are with pending RSCN (Registration
  6888. * State Change Notification).
  6889. *
  6890. * Return code
  6891. * 0 - Successful (currently alway return 0)
  6892. **/
  6893. static int
  6894. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  6895. {
  6896. struct lpfc_nodelist *ndlp = NULL, *n;
  6897. /* Move all affected nodes by pending RSCNs to NPR state. */
  6898. list_for_each_entry_safe(ndlp, n, &vport->fc_nodes, nlp_listp) {
  6899. if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
  6900. !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
  6901. continue;
  6902. /* NVME Target mode does not do RSCN Recovery. */
  6903. if (vport->phba->nvmet_support)
  6904. continue;
  6905. /* If we are in the process of doing discovery on this
  6906. * NPort, let it continue on its own.
  6907. */
  6908. switch (ndlp->nlp_state) {
  6909. case NLP_STE_PLOGI_ISSUE:
  6910. case NLP_STE_ADISC_ISSUE:
  6911. case NLP_STE_REG_LOGIN_ISSUE:
  6912. case NLP_STE_PRLI_ISSUE:
  6913. case NLP_STE_LOGO_ISSUE:
  6914. continue;
  6915. }
  6916. lpfc_disc_state_machine(vport, ndlp, NULL,
  6917. NLP_EVT_DEVICE_RECOVERY);
  6918. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  6919. }
  6920. return 0;
  6921. }
  6922. /**
  6923. * lpfc_send_rscn_event - Send an RSCN event to management application
  6924. * @vport: pointer to a host virtual N_Port data structure.
  6925. * @cmdiocb: pointer to lpfc command iocb data structure.
  6926. *
  6927. * lpfc_send_rscn_event sends an RSCN netlink event to management
  6928. * applications.
  6929. */
  6930. static void
  6931. lpfc_send_rscn_event(struct lpfc_vport *vport,
  6932. struct lpfc_iocbq *cmdiocb)
  6933. {
  6934. struct lpfc_dmabuf *pcmd;
  6935. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6936. uint32_t *payload_ptr;
  6937. uint32_t payload_len;
  6938. struct lpfc_rscn_event_header *rscn_event_data;
  6939. pcmd = cmdiocb->cmd_dmabuf;
  6940. payload_ptr = (uint32_t *) pcmd->virt;
  6941. payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
  6942. rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
  6943. payload_len, GFP_KERNEL);
  6944. if (!rscn_event_data) {
  6945. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  6946. "0147 Failed to allocate memory for RSCN event\n");
  6947. return;
  6948. }
  6949. rscn_event_data->event_type = FC_REG_RSCN_EVENT;
  6950. rscn_event_data->payload_length = payload_len;
  6951. memcpy(rscn_event_data->rscn_payload, payload_ptr,
  6952. payload_len);
  6953. fc_host_post_vendor_event(shost,
  6954. fc_get_event_number(),
  6955. sizeof(struct lpfc_rscn_event_header) + payload_len,
  6956. (char *)rscn_event_data,
  6957. LPFC_NL_VENDOR_ID);
  6958. kfree(rscn_event_data);
  6959. }
  6960. /**
  6961. * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
  6962. * @vport: pointer to a host virtual N_Port data structure.
  6963. * @cmdiocb: pointer to lpfc command iocb data structure.
  6964. * @ndlp: pointer to a node-list data structure.
  6965. *
  6966. * This routine processes an unsolicited RSCN (Registration State Change
  6967. * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
  6968. * to invoke fc_host_post_event() routine to the FC transport layer. If the
  6969. * discover state machine is about to begin discovery, it just accepts the
  6970. * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
  6971. * contains N_Port IDs for other vports on this HBA, it just accepts the
  6972. * RSCN and ignore processing it. If the state machine is in the recovery
  6973. * state, the fc_rscn_id_list of this @vport is walked and the
  6974. * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
  6975. * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
  6976. * routine is invoked to handle the RSCN event.
  6977. *
  6978. * Return code
  6979. * 0 - Just sent the acc response
  6980. * 1 - Sent the acc response and waited for name server completion
  6981. **/
  6982. static int
  6983. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  6984. struct lpfc_nodelist *ndlp)
  6985. {
  6986. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  6987. struct lpfc_hba *phba = vport->phba;
  6988. struct lpfc_dmabuf *pcmd;
  6989. uint32_t *lp, *datap;
  6990. uint32_t payload_len, length, nportid, *cmd;
  6991. int rscn_cnt;
  6992. int rscn_id = 0, hba_id = 0;
  6993. int i, tmo;
  6994. pcmd = cmdiocb->cmd_dmabuf;
  6995. lp = (uint32_t *) pcmd->virt;
  6996. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  6997. payload_len -= sizeof(uint32_t); /* take off word 0 */
  6998. /* RSCN received */
  6999. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  7000. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  7001. vport->fc_flag, payload_len, *lp,
  7002. vport->fc_rscn_id_cnt);
  7003. /* Send an RSCN event to the management application */
  7004. lpfc_send_rscn_event(vport, cmdiocb);
  7005. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  7006. fc_host_post_event(shost, fc_get_event_number(),
  7007. FCH_EVT_RSCN, lp[i]);
  7008. /* Check if RSCN is coming from a direct-connected remote NPort */
  7009. if (vport->fc_flag & FC_PT2PT) {
  7010. /* If so, just ACC it, no other action needed for now */
  7011. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7012. "2024 pt2pt RSCN %08x Data: x%x x%x\n",
  7013. *lp, vport->fc_flag, payload_len);
  7014. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  7015. /* Check to see if we need to NVME rescan this target
  7016. * remoteport.
  7017. */
  7018. if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
  7019. ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
  7020. lpfc_nvme_rescan_port(vport, ndlp);
  7021. return 0;
  7022. }
  7023. /* If we are about to begin discovery, just ACC the RSCN.
  7024. * Discovery processing will satisfy it.
  7025. */
  7026. if (vport->port_state <= LPFC_NS_QRY) {
  7027. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7028. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  7029. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  7030. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  7031. return 0;
  7032. }
  7033. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  7034. * just ACC and ignore it.
  7035. */
  7036. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  7037. !(vport->cfg_peer_port_login)) {
  7038. i = payload_len;
  7039. datap = lp;
  7040. while (i > 0) {
  7041. nportid = *datap++;
  7042. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  7043. i -= sizeof(uint32_t);
  7044. rscn_id++;
  7045. if (lpfc_find_vport_by_did(phba, nportid))
  7046. hba_id++;
  7047. }
  7048. if (rscn_id == hba_id) {
  7049. /* ALL NPortIDs in RSCN are on HBA */
  7050. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  7051. "0219 Ignore RSCN "
  7052. "Data: x%x x%x x%x x%x\n",
  7053. vport->fc_flag, payload_len,
  7054. *lp, vport->fc_rscn_id_cnt);
  7055. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7056. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  7057. ndlp->nlp_DID, vport->port_state,
  7058. ndlp->nlp_flag);
  7059. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  7060. ndlp, NULL);
  7061. /* Restart disctmo if its already running */
  7062. if (vport->fc_flag & FC_DISC_TMO) {
  7063. tmo = ((phba->fc_ratov * 3) + 3);
  7064. mod_timer(&vport->fc_disctmo,
  7065. jiffies +
  7066. msecs_to_jiffies(1000 * tmo));
  7067. }
  7068. return 0;
  7069. }
  7070. }
  7071. spin_lock_irq(shost->host_lock);
  7072. if (vport->fc_rscn_flush) {
  7073. /* Another thread is walking fc_rscn_id_list on this vport */
  7074. vport->fc_flag |= FC_RSCN_DISCOVERY;
  7075. spin_unlock_irq(shost->host_lock);
  7076. /* Send back ACC */
  7077. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  7078. return 0;
  7079. }
  7080. /* Indicate we are walking fc_rscn_id_list on this vport */
  7081. vport->fc_rscn_flush = 1;
  7082. spin_unlock_irq(shost->host_lock);
  7083. /* Get the array count after successfully have the token */
  7084. rscn_cnt = vport->fc_rscn_id_cnt;
  7085. /* If we are already processing an RSCN, save the received
  7086. * RSCN payload buffer, cmdiocb->cmd_dmabuf to process later.
  7087. */
  7088. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  7089. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7090. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  7091. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  7092. spin_lock_irq(shost->host_lock);
  7093. vport->fc_flag |= FC_RSCN_DEFERRED;
  7094. /* Restart disctmo if its already running */
  7095. if (vport->fc_flag & FC_DISC_TMO) {
  7096. tmo = ((phba->fc_ratov * 3) + 3);
  7097. mod_timer(&vport->fc_disctmo,
  7098. jiffies + msecs_to_jiffies(1000 * tmo));
  7099. }
  7100. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  7101. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  7102. vport->fc_flag |= FC_RSCN_MODE;
  7103. spin_unlock_irq(shost->host_lock);
  7104. if (rscn_cnt) {
  7105. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  7106. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  7107. }
  7108. if ((rscn_cnt) &&
  7109. (payload_len + length <= LPFC_BPL_SIZE)) {
  7110. *cmd &= ELS_CMD_MASK;
  7111. *cmd |= cpu_to_be32(payload_len + length);
  7112. memcpy(((uint8_t *)cmd) + length, lp,
  7113. payload_len);
  7114. } else {
  7115. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  7116. vport->fc_rscn_id_cnt++;
  7117. /* If we zero, cmdiocb->cmd_dmabuf, the calling
  7118. * routine will not try to free it.
  7119. */
  7120. cmdiocb->cmd_dmabuf = NULL;
  7121. }
  7122. /* Deferred RSCN */
  7123. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  7124. "0235 Deferred RSCN "
  7125. "Data: x%x x%x x%x\n",
  7126. vport->fc_rscn_id_cnt, vport->fc_flag,
  7127. vport->port_state);
  7128. } else {
  7129. vport->fc_flag |= FC_RSCN_DISCOVERY;
  7130. spin_unlock_irq(shost->host_lock);
  7131. /* ReDiscovery RSCN */
  7132. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  7133. "0234 ReDiscovery RSCN "
  7134. "Data: x%x x%x x%x\n",
  7135. vport->fc_rscn_id_cnt, vport->fc_flag,
  7136. vport->port_state);
  7137. }
  7138. /* Indicate we are done walking fc_rscn_id_list on this vport */
  7139. vport->fc_rscn_flush = 0;
  7140. /* Send back ACC */
  7141. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  7142. /* send RECOVERY event for ALL nodes that match RSCN payload */
  7143. lpfc_rscn_recovery_check(vport);
  7144. return 0;
  7145. }
  7146. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  7147. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  7148. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  7149. spin_lock_irq(shost->host_lock);
  7150. vport->fc_flag |= FC_RSCN_MODE;
  7151. spin_unlock_irq(shost->host_lock);
  7152. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  7153. /* Indicate we are done walking fc_rscn_id_list on this vport */
  7154. vport->fc_rscn_flush = 0;
  7155. /*
  7156. * If we zero, cmdiocb->cmd_dmabuf, the calling routine will
  7157. * not try to free it.
  7158. */
  7159. cmdiocb->cmd_dmabuf = NULL;
  7160. lpfc_set_disctmo(vport);
  7161. /* Send back ACC */
  7162. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  7163. /* send RECOVERY event for ALL nodes that match RSCN payload */
  7164. lpfc_rscn_recovery_check(vport);
  7165. return lpfc_els_handle_rscn(vport);
  7166. }
  7167. /**
  7168. * lpfc_els_handle_rscn - Handle rscn for a vport
  7169. * @vport: pointer to a host virtual N_Port data structure.
  7170. *
  7171. * This routine handles the Registration State Configuration Notification
  7172. * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
  7173. * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
  7174. * if the ndlp to NameServer exists, a Common Transport (CT) command to the
  7175. * NameServer shall be issued. If CT command to the NameServer fails to be
  7176. * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
  7177. * RSCN activities with the @vport.
  7178. *
  7179. * Return code
  7180. * 0 - Cleaned up rscn on the @vport
  7181. * 1 - Wait for plogi to name server before proceed
  7182. **/
  7183. int
  7184. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  7185. {
  7186. struct lpfc_nodelist *ndlp;
  7187. struct lpfc_hba *phba = vport->phba;
  7188. /* Ignore RSCN if the port is being torn down. */
  7189. if (vport->load_flag & FC_UNLOADING) {
  7190. lpfc_els_flush_rscn(vport);
  7191. return 0;
  7192. }
  7193. /* Start timer for RSCN processing */
  7194. lpfc_set_disctmo(vport);
  7195. /* RSCN processed */
  7196. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  7197. "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
  7198. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  7199. vport->port_state, vport->num_disc_nodes,
  7200. vport->gidft_inp);
  7201. /* To process RSCN, first compare RSCN data with NameServer */
  7202. vport->fc_ns_retry = 0;
  7203. vport->num_disc_nodes = 0;
  7204. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  7205. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  7206. /* Good ndlp, issue CT Request to NameServer. Need to
  7207. * know how many gidfts were issued. If none, then just
  7208. * flush the RSCN. Otherwise, the outstanding requests
  7209. * need to complete.
  7210. */
  7211. if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
  7212. if (lpfc_issue_gidft(vport) > 0)
  7213. return 1;
  7214. } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
  7215. if (lpfc_issue_gidpt(vport) > 0)
  7216. return 1;
  7217. } else {
  7218. return 1;
  7219. }
  7220. } else {
  7221. /* Nameserver login in question. Revalidate. */
  7222. if (ndlp) {
  7223. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  7224. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  7225. } else {
  7226. ndlp = lpfc_nlp_init(vport, NameServer_DID);
  7227. if (!ndlp) {
  7228. lpfc_els_flush_rscn(vport);
  7229. return 0;
  7230. }
  7231. ndlp->nlp_prev_state = ndlp->nlp_state;
  7232. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  7233. }
  7234. ndlp->nlp_type |= NLP_FABRIC;
  7235. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  7236. /* Wait for NameServer login cmpl before we can
  7237. * continue
  7238. */
  7239. return 1;
  7240. }
  7241. lpfc_els_flush_rscn(vport);
  7242. return 0;
  7243. }
  7244. /**
  7245. * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
  7246. * @vport: pointer to a host virtual N_Port data structure.
  7247. * @cmdiocb: pointer to lpfc command iocb data structure.
  7248. * @ndlp: pointer to a node-list data structure.
  7249. *
  7250. * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
  7251. * unsolicited event. An unsolicited FLOGI can be received in a point-to-
  7252. * point topology. As an unsolicited FLOGI should not be received in a loop
  7253. * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
  7254. * lpfc_check_sparm() routine is invoked to check the parameters in the
  7255. * unsolicited FLOGI. If parameters validation failed, the routine
  7256. * lpfc_els_rsp_reject() shall be called with reject reason code set to
  7257. * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
  7258. * FLOGI shall be compared with the Port WWN of the @vport to determine who
  7259. * will initiate PLOGI. The higher lexicographical value party shall has
  7260. * higher priority (as the winning port) and will initiate PLOGI and
  7261. * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
  7262. * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
  7263. * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
  7264. *
  7265. * Return code
  7266. * 0 - Successfully processed the unsolicited flogi
  7267. * 1 - Failed to process the unsolicited flogi
  7268. **/
  7269. static int
  7270. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7271. struct lpfc_nodelist *ndlp)
  7272. {
  7273. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  7274. struct lpfc_hba *phba = vport->phba;
  7275. struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
  7276. uint32_t *lp = (uint32_t *) pcmd->virt;
  7277. union lpfc_wqe128 *wqe = &cmdiocb->wqe;
  7278. struct serv_parm *sp;
  7279. LPFC_MBOXQ_t *mbox;
  7280. uint32_t cmd, did;
  7281. int rc;
  7282. uint32_t fc_flag = 0;
  7283. uint32_t port_state = 0;
  7284. /* Clear external loopback plug detected flag */
  7285. phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
  7286. cmd = *lp++;
  7287. sp = (struct serv_parm *) lp;
  7288. /* FLOGI received */
  7289. lpfc_set_disctmo(vport);
  7290. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  7291. /* We should never receive a FLOGI in loop mode, ignore it */
  7292. did = bf_get(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest);
  7293. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  7294. Loop Mode */
  7295. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  7296. "0113 An FLOGI ELS command x%x was "
  7297. "received from DID x%x in Loop Mode\n",
  7298. cmd, did);
  7299. return 1;
  7300. }
  7301. (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
  7302. /*
  7303. * If our portname is greater than the remote portname,
  7304. * then we initiate Nport login.
  7305. */
  7306. rc = memcmp(&vport->fc_portname, &sp->portName,
  7307. sizeof(struct lpfc_name));
  7308. if (!rc) {
  7309. if (phba->sli_rev < LPFC_SLI_REV4) {
  7310. mbox = mempool_alloc(phba->mbox_mem_pool,
  7311. GFP_KERNEL);
  7312. if (!mbox)
  7313. return 1;
  7314. lpfc_linkdown(phba);
  7315. lpfc_init_link(phba, mbox,
  7316. phba->cfg_topology,
  7317. phba->cfg_link_speed);
  7318. mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  7319. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  7320. mbox->vport = vport;
  7321. rc = lpfc_sli_issue_mbox(phba, mbox,
  7322. MBX_NOWAIT);
  7323. lpfc_set_loopback_flag(phba);
  7324. if (rc == MBX_NOT_FINISHED)
  7325. mempool_free(mbox, phba->mbox_mem_pool);
  7326. return 1;
  7327. }
  7328. /* External loopback plug insertion detected */
  7329. phba->link_flag |= LS_EXTERNAL_LOOPBACK;
  7330. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_LIBDFC,
  7331. "1119 External Loopback plug detected\n");
  7332. /* abort the flogi coming back to ourselves
  7333. * due to external loopback on the port.
  7334. */
  7335. lpfc_els_abort_flogi(phba);
  7336. return 0;
  7337. } else if (rc > 0) { /* greater than */
  7338. spin_lock_irq(shost->host_lock);
  7339. vport->fc_flag |= FC_PT2PT_PLOGI;
  7340. spin_unlock_irq(shost->host_lock);
  7341. /* If we have the high WWPN we can assign our own
  7342. * myDID; otherwise, we have to WAIT for a PLOGI
  7343. * from the remote NPort to find out what it
  7344. * will be.
  7345. */
  7346. vport->fc_myDID = PT2PT_LocalID;
  7347. } else {
  7348. vport->fc_myDID = PT2PT_RemoteID;
  7349. }
  7350. /*
  7351. * The vport state should go to LPFC_FLOGI only
  7352. * AFTER we issue a FLOGI, not receive one.
  7353. */
  7354. spin_lock_irq(shost->host_lock);
  7355. fc_flag = vport->fc_flag;
  7356. port_state = vport->port_state;
  7357. vport->fc_flag |= FC_PT2PT;
  7358. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  7359. /* Acking an unsol FLOGI. Count 1 for link bounce
  7360. * work-around.
  7361. */
  7362. vport->rcv_flogi_cnt++;
  7363. spin_unlock_irq(shost->host_lock);
  7364. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7365. "3311 Rcv Flogi PS x%x new PS x%x "
  7366. "fc_flag x%x new fc_flag x%x\n",
  7367. port_state, vport->port_state,
  7368. fc_flag, vport->fc_flag);
  7369. /*
  7370. * We temporarily set fc_myDID to make it look like we are
  7371. * a Fabric. This is done just so we end up with the right
  7372. * did / sid on the FLOGI ACC rsp.
  7373. */
  7374. did = vport->fc_myDID;
  7375. vport->fc_myDID = Fabric_DID;
  7376. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  7377. /* Defer ACC response until AFTER we issue a FLOGI */
  7378. if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
  7379. phba->defer_flogi_acc_rx_id = bf_get(wqe_ctxt_tag,
  7380. &wqe->xmit_els_rsp.wqe_com);
  7381. phba->defer_flogi_acc_ox_id = bf_get(wqe_rcvoxid,
  7382. &wqe->xmit_els_rsp.wqe_com);
  7383. vport->fc_myDID = did;
  7384. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7385. "3344 Deferring FLOGI ACC: rx_id: x%x,"
  7386. " ox_id: x%x, hba_flag x%x\n",
  7387. phba->defer_flogi_acc_rx_id,
  7388. phba->defer_flogi_acc_ox_id, phba->hba_flag);
  7389. phba->defer_flogi_acc_flag = true;
  7390. return 0;
  7391. }
  7392. /* Send back ACC */
  7393. lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
  7394. /* Now lets put fc_myDID back to what its supposed to be */
  7395. vport->fc_myDID = did;
  7396. return 0;
  7397. }
  7398. /**
  7399. * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
  7400. * @vport: pointer to a host virtual N_Port data structure.
  7401. * @cmdiocb: pointer to lpfc command iocb data structure.
  7402. * @ndlp: pointer to a node-list data structure.
  7403. *
  7404. * This routine processes Request Node Identification Data (RNID) IOCB
  7405. * received as an ELS unsolicited event. Only when the RNID specified format
  7406. * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
  7407. * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
  7408. * Accept (ACC) the RNID ELS command. All the other RNID formats are
  7409. * rejected by invoking the lpfc_els_rsp_reject() routine.
  7410. *
  7411. * Return code
  7412. * 0 - Successfully processed rnid iocb (currently always return 0)
  7413. **/
  7414. static int
  7415. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7416. struct lpfc_nodelist *ndlp)
  7417. {
  7418. struct lpfc_dmabuf *pcmd;
  7419. uint32_t *lp;
  7420. RNID *rn;
  7421. struct ls_rjt stat;
  7422. pcmd = cmdiocb->cmd_dmabuf;
  7423. lp = (uint32_t *) pcmd->virt;
  7424. lp++;
  7425. rn = (RNID *) lp;
  7426. /* RNID received */
  7427. switch (rn->Format) {
  7428. case 0:
  7429. case RNID_TOPOLOGY_DISC:
  7430. /* Send back ACC */
  7431. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  7432. break;
  7433. default:
  7434. /* Reject this request because format not supported */
  7435. stat.un.b.lsRjtRsvd0 = 0;
  7436. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  7437. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  7438. stat.un.b.vendorUnique = 0;
  7439. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  7440. NULL);
  7441. }
  7442. return 0;
  7443. }
  7444. /**
  7445. * lpfc_els_rcv_echo - Process an unsolicited echo iocb
  7446. * @vport: pointer to a host virtual N_Port data structure.
  7447. * @cmdiocb: pointer to lpfc command iocb data structure.
  7448. * @ndlp: pointer to a node-list data structure.
  7449. *
  7450. * Return code
  7451. * 0 - Successfully processed echo iocb (currently always return 0)
  7452. **/
  7453. static int
  7454. lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7455. struct lpfc_nodelist *ndlp)
  7456. {
  7457. uint8_t *pcmd;
  7458. pcmd = (uint8_t *)cmdiocb->cmd_dmabuf->virt;
  7459. /* skip over first word of echo command to find echo data */
  7460. pcmd += sizeof(uint32_t);
  7461. lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
  7462. return 0;
  7463. }
  7464. /**
  7465. * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
  7466. * @vport: pointer to a host virtual N_Port data structure.
  7467. * @cmdiocb: pointer to lpfc command iocb data structure.
  7468. * @ndlp: pointer to a node-list data structure.
  7469. *
  7470. * This routine processes a Link Incident Report Registration(LIRR) IOCB
  7471. * received as an ELS unsolicited event. Currently, this function just invokes
  7472. * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
  7473. *
  7474. * Return code
  7475. * 0 - Successfully processed lirr iocb (currently always return 0)
  7476. **/
  7477. static int
  7478. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7479. struct lpfc_nodelist *ndlp)
  7480. {
  7481. struct ls_rjt stat;
  7482. /* For now, unconditionally reject this command */
  7483. stat.un.b.lsRjtRsvd0 = 0;
  7484. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  7485. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  7486. stat.un.b.vendorUnique = 0;
  7487. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  7488. return 0;
  7489. }
  7490. /**
  7491. * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
  7492. * @vport: pointer to a host virtual N_Port data structure.
  7493. * @cmdiocb: pointer to lpfc command iocb data structure.
  7494. * @ndlp: pointer to a node-list data structure.
  7495. *
  7496. * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
  7497. * received as an ELS unsolicited event. A request to RRQ shall only
  7498. * be accepted if the Originator Nx_Port N_Port_ID or the Responder
  7499. * Nx_Port N_Port_ID of the target Exchange is the same as the
  7500. * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
  7501. * not accepted, an LS_RJT with reason code "Unable to perform
  7502. * command request" and reason code explanation "Invalid Originator
  7503. * S_ID" shall be returned. For now, we just unconditionally accept
  7504. * RRQ from the target.
  7505. **/
  7506. static void
  7507. lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7508. struct lpfc_nodelist *ndlp)
  7509. {
  7510. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  7511. if (vport->phba->sli_rev == LPFC_SLI_REV4)
  7512. lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
  7513. }
  7514. /**
  7515. * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
  7516. * @phba: pointer to lpfc hba data structure.
  7517. * @pmb: pointer to the driver internal queue element for mailbox command.
  7518. *
  7519. * This routine is the completion callback function for the MBX_READ_LNK_STAT
  7520. * mailbox command. This callback function is to actually send the Accept
  7521. * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It
  7522. * collects the link statistics from the completion of the MBX_READ_LNK_STAT
  7523. * mailbox command, constructs the RLS response with the link statistics
  7524. * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
  7525. * response to the RLS.
  7526. *
  7527. * Note that the ndlp reference count will be incremented by 1 for holding the
  7528. * ndlp and the reference to ndlp will be stored into the ndlp field of
  7529. * the IOCB for the completion callback function to the RLS Accept Response
  7530. * ELS IOCB command.
  7531. *
  7532. **/
  7533. static void
  7534. lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  7535. {
  7536. int rc = 0;
  7537. MAILBOX_t *mb;
  7538. IOCB_t *icmd;
  7539. union lpfc_wqe128 *wqe;
  7540. struct RLS_RSP *rls_rsp;
  7541. uint8_t *pcmd;
  7542. struct lpfc_iocbq *elsiocb;
  7543. struct lpfc_nodelist *ndlp;
  7544. uint16_t oxid;
  7545. uint16_t rxid;
  7546. uint32_t cmdsize;
  7547. u32 ulp_context;
  7548. mb = &pmb->u.mb;
  7549. ndlp = pmb->ctx_ndlp;
  7550. rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
  7551. oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
  7552. pmb->ctx_buf = NULL;
  7553. pmb->ctx_ndlp = NULL;
  7554. if (mb->mbxStatus) {
  7555. mempool_free(pmb, phba->mbox_mem_pool);
  7556. return;
  7557. }
  7558. cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
  7559. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  7560. lpfc_max_els_tries, ndlp,
  7561. ndlp->nlp_DID, ELS_CMD_ACC);
  7562. /* Decrement the ndlp reference count from previous mbox command */
  7563. lpfc_nlp_put(ndlp);
  7564. if (!elsiocb) {
  7565. mempool_free(pmb, phba->mbox_mem_pool);
  7566. return;
  7567. }
  7568. ulp_context = get_job_ulpcontext(phba, elsiocb);
  7569. if (phba->sli_rev == LPFC_SLI_REV4) {
  7570. wqe = &elsiocb->wqe;
  7571. /* Xri / rx_id */
  7572. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com, rxid);
  7573. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, oxid);
  7574. } else {
  7575. icmd = &elsiocb->iocb;
  7576. icmd->ulpContext = rxid;
  7577. icmd->unsli3.rcvsli3.ox_id = oxid;
  7578. }
  7579. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  7580. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  7581. pcmd += sizeof(uint32_t); /* Skip past command */
  7582. rls_rsp = (struct RLS_RSP *)pcmd;
  7583. rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
  7584. rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
  7585. rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
  7586. rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
  7587. rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
  7588. rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
  7589. mempool_free(pmb, phba->mbox_mem_pool);
  7590. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  7591. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  7592. "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
  7593. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  7594. elsiocb->iotag, ulp_context,
  7595. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  7596. ndlp->nlp_rpi);
  7597. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  7598. phba->fc_stat.elsXmitACC++;
  7599. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  7600. if (!elsiocb->ndlp) {
  7601. lpfc_els_free_iocb(phba, elsiocb);
  7602. return;
  7603. }
  7604. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  7605. if (rc == IOCB_ERROR) {
  7606. lpfc_els_free_iocb(phba, elsiocb);
  7607. lpfc_nlp_put(ndlp);
  7608. }
  7609. return;
  7610. }
  7611. /**
  7612. * lpfc_els_rcv_rls - Process an unsolicited rls iocb
  7613. * @vport: pointer to a host virtual N_Port data structure.
  7614. * @cmdiocb: pointer to lpfc command iocb data structure.
  7615. * @ndlp: pointer to a node-list data structure.
  7616. *
  7617. * This routine processes Read Link Status (RLS) IOCB received as an
  7618. * ELS unsolicited event. It first checks the remote port state. If the
  7619. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  7620. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  7621. * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
  7622. * for reading the HBA link statistics. It is for the callback function,
  7623. * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
  7624. * to actually sending out RPL Accept (ACC) response.
  7625. *
  7626. * Return codes
  7627. * 0 - Successfully processed rls iocb (currently always return 0)
  7628. **/
  7629. static int
  7630. lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7631. struct lpfc_nodelist *ndlp)
  7632. {
  7633. struct lpfc_hba *phba = vport->phba;
  7634. LPFC_MBOXQ_t *mbox;
  7635. struct ls_rjt stat;
  7636. u32 ctx = get_job_ulpcontext(phba, cmdiocb);
  7637. u32 ox_id = get_job_rcvoxid(phba, cmdiocb);
  7638. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  7639. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  7640. /* reject the unsolicited RLS request and done with it */
  7641. goto reject_out;
  7642. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  7643. if (mbox) {
  7644. lpfc_read_lnk_stat(phba, mbox);
  7645. mbox->ctx_buf = (void *)((unsigned long)
  7646. (ox_id << 16 | ctx));
  7647. mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
  7648. if (!mbox->ctx_ndlp)
  7649. goto node_err;
  7650. mbox->vport = vport;
  7651. mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
  7652. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  7653. != MBX_NOT_FINISHED)
  7654. /* Mbox completion will send ELS Response */
  7655. return 0;
  7656. /* Decrement reference count used for the failed mbox
  7657. * command.
  7658. */
  7659. lpfc_nlp_put(ndlp);
  7660. node_err:
  7661. mempool_free(mbox, phba->mbox_mem_pool);
  7662. }
  7663. reject_out:
  7664. /* issue rejection response */
  7665. stat.un.b.lsRjtRsvd0 = 0;
  7666. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  7667. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  7668. stat.un.b.vendorUnique = 0;
  7669. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  7670. return 0;
  7671. }
  7672. /**
  7673. * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
  7674. * @vport: pointer to a host virtual N_Port data structure.
  7675. * @cmdiocb: pointer to lpfc command iocb data structure.
  7676. * @ndlp: pointer to a node-list data structure.
  7677. *
  7678. * This routine processes Read Timout Value (RTV) IOCB received as an
  7679. * ELS unsolicited event. It first checks the remote port state. If the
  7680. * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
  7681. * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
  7682. * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
  7683. * Value (RTV) unsolicited IOCB event.
  7684. *
  7685. * Note that the ndlp reference count will be incremented by 1 for holding the
  7686. * ndlp and the reference to ndlp will be stored into the ndlp field of
  7687. * the IOCB for the completion callback function to the RTV Accept Response
  7688. * ELS IOCB command.
  7689. *
  7690. * Return codes
  7691. * 0 - Successfully processed rtv iocb (currently always return 0)
  7692. **/
  7693. static int
  7694. lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7695. struct lpfc_nodelist *ndlp)
  7696. {
  7697. int rc = 0;
  7698. IOCB_t *icmd;
  7699. union lpfc_wqe128 *wqe;
  7700. struct lpfc_hba *phba = vport->phba;
  7701. struct ls_rjt stat;
  7702. struct RTV_RSP *rtv_rsp;
  7703. uint8_t *pcmd;
  7704. struct lpfc_iocbq *elsiocb;
  7705. uint32_t cmdsize;
  7706. u32 ulp_context;
  7707. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  7708. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
  7709. /* reject the unsolicited RTV request and done with it */
  7710. goto reject_out;
  7711. cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
  7712. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  7713. lpfc_max_els_tries, ndlp,
  7714. ndlp->nlp_DID, ELS_CMD_ACC);
  7715. if (!elsiocb)
  7716. return 1;
  7717. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  7718. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  7719. pcmd += sizeof(uint32_t); /* Skip past command */
  7720. ulp_context = get_job_ulpcontext(phba, elsiocb);
  7721. /* use the command's xri in the response */
  7722. if (phba->sli_rev == LPFC_SLI_REV4) {
  7723. wqe = &elsiocb->wqe;
  7724. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
  7725. get_job_ulpcontext(phba, cmdiocb));
  7726. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7727. get_job_rcvoxid(phba, cmdiocb));
  7728. } else {
  7729. icmd = &elsiocb->iocb;
  7730. icmd->ulpContext = get_job_ulpcontext(phba, cmdiocb);
  7731. icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, cmdiocb);
  7732. }
  7733. rtv_rsp = (struct RTV_RSP *)pcmd;
  7734. /* populate RTV payload */
  7735. rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
  7736. rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
  7737. bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
  7738. bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
  7739. rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
  7740. /* Xmit ELS RLS ACC response tag <ulpIoTag> */
  7741. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  7742. "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
  7743. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
  7744. "Data: x%x x%x x%x\n",
  7745. elsiocb->iotag, ulp_context,
  7746. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  7747. ndlp->nlp_rpi,
  7748. rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
  7749. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  7750. phba->fc_stat.elsXmitACC++;
  7751. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  7752. if (!elsiocb->ndlp) {
  7753. lpfc_els_free_iocb(phba, elsiocb);
  7754. return 0;
  7755. }
  7756. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  7757. if (rc == IOCB_ERROR) {
  7758. lpfc_els_free_iocb(phba, elsiocb);
  7759. lpfc_nlp_put(ndlp);
  7760. }
  7761. return 0;
  7762. reject_out:
  7763. /* issue rejection response */
  7764. stat.un.b.lsRjtRsvd0 = 0;
  7765. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  7766. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  7767. stat.un.b.vendorUnique = 0;
  7768. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  7769. return 0;
  7770. }
  7771. /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
  7772. * @vport: pointer to a host virtual N_Port data structure.
  7773. * @ndlp: pointer to a node-list data structure.
  7774. * @did: DID of the target.
  7775. * @rrq: Pointer to the rrq struct.
  7776. *
  7777. * Build a ELS RRQ command and send it to the target. If the issue_iocb is
  7778. * Successful the the completion handler will clear the RRQ.
  7779. *
  7780. * Return codes
  7781. * 0 - Successfully sent rrq els iocb.
  7782. * 1 - Failed to send rrq els iocb.
  7783. **/
  7784. static int
  7785. lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  7786. uint32_t did, struct lpfc_node_rrq *rrq)
  7787. {
  7788. struct lpfc_hba *phba = vport->phba;
  7789. struct RRQ *els_rrq;
  7790. struct lpfc_iocbq *elsiocb;
  7791. uint8_t *pcmd;
  7792. uint16_t cmdsize;
  7793. int ret;
  7794. if (!ndlp)
  7795. return 1;
  7796. /* If ndlp is not NULL, we will bump the reference count on it */
  7797. cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
  7798. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
  7799. ELS_CMD_RRQ);
  7800. if (!elsiocb)
  7801. return 1;
  7802. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  7803. /* For RRQ request, remainder of payload is Exchange IDs */
  7804. *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
  7805. pcmd += sizeof(uint32_t);
  7806. els_rrq = (struct RRQ *) pcmd;
  7807. bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
  7808. bf_set(rrq_rxid, els_rrq, rrq->rxid);
  7809. bf_set(rrq_did, els_rrq, vport->fc_myDID);
  7810. els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
  7811. els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
  7812. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  7813. "Issue RRQ: did:x%x",
  7814. did, rrq->xritag, rrq->rxid);
  7815. elsiocb->context_un.rrq = rrq;
  7816. elsiocb->cmd_cmpl = lpfc_cmpl_els_rrq;
  7817. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  7818. if (!elsiocb->ndlp)
  7819. goto io_err;
  7820. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  7821. if (ret == IOCB_ERROR) {
  7822. lpfc_nlp_put(ndlp);
  7823. goto io_err;
  7824. }
  7825. return 0;
  7826. io_err:
  7827. lpfc_els_free_iocb(phba, elsiocb);
  7828. return 1;
  7829. }
  7830. /**
  7831. * lpfc_send_rrq - Sends ELS RRQ if needed.
  7832. * @phba: pointer to lpfc hba data structure.
  7833. * @rrq: pointer to the active rrq.
  7834. *
  7835. * This routine will call the lpfc_issue_els_rrq if the rrq is
  7836. * still active for the xri. If this function returns a failure then
  7837. * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
  7838. *
  7839. * Returns 0 Success.
  7840. * 1 Failure.
  7841. **/
  7842. int
  7843. lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
  7844. {
  7845. struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
  7846. rrq->nlp_DID);
  7847. if (!ndlp)
  7848. return 1;
  7849. if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
  7850. return lpfc_issue_els_rrq(rrq->vport, ndlp,
  7851. rrq->nlp_DID, rrq);
  7852. else
  7853. return 1;
  7854. }
  7855. /**
  7856. * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
  7857. * @vport: pointer to a host virtual N_Port data structure.
  7858. * @cmdsize: size of the ELS command.
  7859. * @oldiocb: pointer to the original lpfc command iocb data structure.
  7860. * @ndlp: pointer to a node-list data structure.
  7861. *
  7862. * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
  7863. * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
  7864. *
  7865. * Note that the ndlp reference count will be incremented by 1 for holding the
  7866. * ndlp and the reference to ndlp will be stored into the ndlp field of
  7867. * the IOCB for the completion callback function to the RPL Accept Response
  7868. * ELS command.
  7869. *
  7870. * Return code
  7871. * 0 - Successfully issued ACC RPL ELS command
  7872. * 1 - Failed to issue ACC RPL ELS command
  7873. **/
  7874. static int
  7875. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  7876. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  7877. {
  7878. int rc = 0;
  7879. struct lpfc_hba *phba = vport->phba;
  7880. IOCB_t *icmd;
  7881. union lpfc_wqe128 *wqe;
  7882. RPL_RSP rpl_rsp;
  7883. struct lpfc_iocbq *elsiocb;
  7884. uint8_t *pcmd;
  7885. u32 ulp_context;
  7886. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  7887. ndlp->nlp_DID, ELS_CMD_ACC);
  7888. if (!elsiocb)
  7889. return 1;
  7890. ulp_context = get_job_ulpcontext(phba, elsiocb);
  7891. if (phba->sli_rev == LPFC_SLI_REV4) {
  7892. wqe = &elsiocb->wqe;
  7893. /* Xri / rx_id */
  7894. bf_set(wqe_ctxt_tag, &wqe->generic.wqe_com,
  7895. get_job_ulpcontext(phba, oldiocb));
  7896. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  7897. get_job_rcvoxid(phba, oldiocb));
  7898. } else {
  7899. icmd = &elsiocb->iocb;
  7900. icmd->ulpContext = get_job_ulpcontext(phba, oldiocb);
  7901. icmd->unsli3.rcvsli3.ox_id = get_job_rcvoxid(phba, oldiocb);
  7902. }
  7903. pcmd = elsiocb->cmd_dmabuf->virt;
  7904. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  7905. pcmd += sizeof(uint16_t);
  7906. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  7907. pcmd += sizeof(uint16_t);
  7908. /* Setup the RPL ACC payload */
  7909. rpl_rsp.listLen = be32_to_cpu(1);
  7910. rpl_rsp.index = 0;
  7911. rpl_rsp.port_num_blk.portNum = 0;
  7912. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  7913. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  7914. sizeof(struct lpfc_name));
  7915. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  7916. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  7917. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  7918. "0120 Xmit ELS RPL ACC response tag x%x "
  7919. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  7920. "rpi x%x\n",
  7921. elsiocb->iotag, ulp_context,
  7922. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  7923. ndlp->nlp_rpi);
  7924. elsiocb->cmd_cmpl = lpfc_cmpl_els_rsp;
  7925. phba->fc_stat.elsXmitACC++;
  7926. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  7927. if (!elsiocb->ndlp) {
  7928. lpfc_els_free_iocb(phba, elsiocb);
  7929. return 1;
  7930. }
  7931. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  7932. if (rc == IOCB_ERROR) {
  7933. lpfc_els_free_iocb(phba, elsiocb);
  7934. lpfc_nlp_put(ndlp);
  7935. return 1;
  7936. }
  7937. return 0;
  7938. }
  7939. /**
  7940. * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
  7941. * @vport: pointer to a host virtual N_Port data structure.
  7942. * @cmdiocb: pointer to lpfc command iocb data structure.
  7943. * @ndlp: pointer to a node-list data structure.
  7944. *
  7945. * This routine processes Read Port List (RPL) IOCB received as an ELS
  7946. * unsolicited event. It first checks the remote port state. If the remote
  7947. * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
  7948. * invokes the lpfc_els_rsp_reject() routine to send reject response.
  7949. * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
  7950. * to accept the RPL.
  7951. *
  7952. * Return code
  7953. * 0 - Successfully processed rpl iocb (currently always return 0)
  7954. **/
  7955. static int
  7956. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  7957. struct lpfc_nodelist *ndlp)
  7958. {
  7959. struct lpfc_dmabuf *pcmd;
  7960. uint32_t *lp;
  7961. uint32_t maxsize;
  7962. uint16_t cmdsize;
  7963. RPL *rpl;
  7964. struct ls_rjt stat;
  7965. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  7966. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  7967. /* issue rejection response */
  7968. stat.un.b.lsRjtRsvd0 = 0;
  7969. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  7970. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  7971. stat.un.b.vendorUnique = 0;
  7972. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  7973. NULL);
  7974. /* rejected the unsolicited RPL request and done with it */
  7975. return 0;
  7976. }
  7977. pcmd = cmdiocb->cmd_dmabuf;
  7978. lp = (uint32_t *) pcmd->virt;
  7979. rpl = (RPL *) (lp + 1);
  7980. maxsize = be32_to_cpu(rpl->maxsize);
  7981. /* We support only one port */
  7982. if ((rpl->index == 0) &&
  7983. ((maxsize == 0) ||
  7984. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  7985. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  7986. } else {
  7987. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  7988. }
  7989. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  7990. return 0;
  7991. }
  7992. /**
  7993. * lpfc_els_rcv_farp - Process an unsolicited farp request els command
  7994. * @vport: pointer to a virtual N_Port data structure.
  7995. * @cmdiocb: pointer to lpfc command iocb data structure.
  7996. * @ndlp: pointer to a node-list data structure.
  7997. *
  7998. * This routine processes Fibre Channel Address Resolution Protocol
  7999. * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
  8000. * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
  8001. * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
  8002. * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
  8003. * remote PortName is compared against the FC PortName stored in the @vport
  8004. * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
  8005. * compared against the FC NodeName stored in the @vport data structure.
  8006. * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
  8007. * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
  8008. * invoked to send out FARP Response to the remote node. Before sending the
  8009. * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
  8010. * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
  8011. * routine is invoked to log into the remote port first.
  8012. *
  8013. * Return code
  8014. * 0 - Either the FARP Match Mode not supported or successfully processed
  8015. **/
  8016. static int
  8017. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  8018. struct lpfc_nodelist *ndlp)
  8019. {
  8020. struct lpfc_dmabuf *pcmd;
  8021. uint32_t *lp;
  8022. FARP *fp;
  8023. uint32_t cnt, did;
  8024. did = get_job_els_rsp64_did(vport->phba, cmdiocb);
  8025. pcmd = cmdiocb->cmd_dmabuf;
  8026. lp = (uint32_t *) pcmd->virt;
  8027. lp++;
  8028. fp = (FARP *) lp;
  8029. /* FARP-REQ received from DID <did> */
  8030. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  8031. "0601 FARP-REQ received from DID x%x\n", did);
  8032. /* We will only support match on WWPN or WWNN */
  8033. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  8034. return 0;
  8035. }
  8036. cnt = 0;
  8037. /* If this FARP command is searching for my portname */
  8038. if (fp->Mflags & FARP_MATCH_PORT) {
  8039. if (memcmp(&fp->RportName, &vport->fc_portname,
  8040. sizeof(struct lpfc_name)) == 0)
  8041. cnt = 1;
  8042. }
  8043. /* If this FARP command is searching for my nodename */
  8044. if (fp->Mflags & FARP_MATCH_NODE) {
  8045. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  8046. sizeof(struct lpfc_name)) == 0)
  8047. cnt = 1;
  8048. }
  8049. if (cnt) {
  8050. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  8051. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  8052. /* Log back into the node before sending the FARP. */
  8053. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  8054. ndlp->nlp_prev_state = ndlp->nlp_state;
  8055. lpfc_nlp_set_state(vport, ndlp,
  8056. NLP_STE_PLOGI_ISSUE);
  8057. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  8058. }
  8059. /* Send a FARP response to that node */
  8060. if (fp->Rflags & FARP_REQUEST_FARPR)
  8061. lpfc_issue_els_farpr(vport, did, 0);
  8062. }
  8063. }
  8064. return 0;
  8065. }
  8066. /**
  8067. * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
  8068. * @vport: pointer to a host virtual N_Port data structure.
  8069. * @cmdiocb: pointer to lpfc command iocb data structure.
  8070. * @ndlp: pointer to a node-list data structure.
  8071. *
  8072. * This routine processes Fibre Channel Address Resolution Protocol
  8073. * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
  8074. * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
  8075. * the FARP response request.
  8076. *
  8077. * Return code
  8078. * 0 - Successfully processed FARPR IOCB (currently always return 0)
  8079. **/
  8080. static int
  8081. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  8082. struct lpfc_nodelist *ndlp)
  8083. {
  8084. struct lpfc_dmabuf *pcmd;
  8085. uint32_t *lp;
  8086. uint32_t did;
  8087. did = get_job_els_rsp64_did(vport->phba, cmdiocb);
  8088. pcmd = cmdiocb->cmd_dmabuf;
  8089. lp = (uint32_t *)pcmd->virt;
  8090. lp++;
  8091. /* FARP-RSP received from DID <did> */
  8092. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  8093. "0600 FARP-RSP received from DID x%x\n", did);
  8094. /* ACCEPT the Farp resp request */
  8095. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  8096. return 0;
  8097. }
  8098. /**
  8099. * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
  8100. * @vport: pointer to a host virtual N_Port data structure.
  8101. * @cmdiocb: pointer to lpfc command iocb data structure.
  8102. * @fan_ndlp: pointer to a node-list data structure.
  8103. *
  8104. * This routine processes a Fabric Address Notification (FAN) IOCB
  8105. * command received as an ELS unsolicited event. The FAN ELS command will
  8106. * only be processed on a physical port (i.e., the @vport represents the
  8107. * physical port). The fabric NodeName and PortName from the FAN IOCB are
  8108. * compared against those in the phba data structure. If any of those is
  8109. * different, the lpfc_initial_flogi() routine is invoked to initialize
  8110. * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
  8111. * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
  8112. * is invoked to register login to the fabric.
  8113. *
  8114. * Return code
  8115. * 0 - Successfully processed fan iocb (currently always return 0).
  8116. **/
  8117. static int
  8118. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  8119. struct lpfc_nodelist *fan_ndlp)
  8120. {
  8121. struct lpfc_hba *phba = vport->phba;
  8122. uint32_t *lp;
  8123. FAN *fp;
  8124. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
  8125. lp = (uint32_t *)cmdiocb->cmd_dmabuf->virt;
  8126. fp = (FAN *) ++lp;
  8127. /* FAN received; Fan does not have a reply sequence */
  8128. if ((vport == phba->pport) &&
  8129. (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
  8130. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  8131. sizeof(struct lpfc_name))) ||
  8132. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  8133. sizeof(struct lpfc_name)))) {
  8134. /* This port has switched fabrics. FLOGI is required */
  8135. lpfc_issue_init_vfi(vport);
  8136. } else {
  8137. /* FAN verified - skip FLOGI */
  8138. vport->fc_myDID = vport->fc_prevDID;
  8139. if (phba->sli_rev < LPFC_SLI_REV4)
  8140. lpfc_issue_fabric_reglogin(vport);
  8141. else {
  8142. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  8143. "3138 Need register VFI: (x%x/%x)\n",
  8144. vport->fc_prevDID, vport->fc_myDID);
  8145. lpfc_issue_reg_vfi(vport);
  8146. }
  8147. }
  8148. }
  8149. return 0;
  8150. }
  8151. /**
  8152. * lpfc_els_rcv_edc - Process an unsolicited EDC iocb
  8153. * @vport: pointer to a host virtual N_Port data structure.
  8154. * @cmdiocb: pointer to lpfc command iocb data structure.
  8155. * @ndlp: pointer to a node-list data structure.
  8156. *
  8157. * Return code
  8158. * 0 - Successfully processed echo iocb (currently always return 0)
  8159. **/
  8160. static int
  8161. lpfc_els_rcv_edc(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  8162. struct lpfc_nodelist *ndlp)
  8163. {
  8164. struct lpfc_hba *phba = vport->phba;
  8165. struct fc_els_edc *edc_req;
  8166. struct fc_tlv_desc *tlv;
  8167. uint8_t *payload;
  8168. uint32_t *ptr, dtag;
  8169. const char *dtag_nm;
  8170. int desc_cnt = 0, bytes_remain;
  8171. struct fc_diag_lnkflt_desc *plnkflt;
  8172. payload = cmdiocb->cmd_dmabuf->virt;
  8173. edc_req = (struct fc_els_edc *)payload;
  8174. bytes_remain = be32_to_cpu(edc_req->desc_len);
  8175. ptr = (uint32_t *)payload;
  8176. lpfc_printf_vlog(vport, KERN_INFO,
  8177. LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
  8178. "3319 Rcv EDC payload len %d: x%x x%x x%x\n",
  8179. bytes_remain, be32_to_cpu(*ptr),
  8180. be32_to_cpu(*(ptr + 1)), be32_to_cpu(*(ptr + 2)));
  8181. /* No signal support unless there is a congestion descriptor */
  8182. phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
  8183. phba->cgn_sig_freq = 0;
  8184. phba->cgn_reg_fpin = LPFC_CGN_FPIN_ALARM | LPFC_CGN_FPIN_WARN;
  8185. if (bytes_remain <= 0)
  8186. goto out;
  8187. tlv = edc_req->desc;
  8188. /*
  8189. * cycle through EDC diagnostic descriptors to find the
  8190. * congestion signaling capability descriptor
  8191. */
  8192. while (bytes_remain) {
  8193. if (bytes_remain < FC_TLV_DESC_HDR_SZ) {
  8194. lpfc_printf_log(phba, KERN_WARNING,
  8195. LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
  8196. "6464 Truncated TLV hdr on "
  8197. "Diagnostic descriptor[%d]\n",
  8198. desc_cnt);
  8199. goto out;
  8200. }
  8201. dtag = be32_to_cpu(tlv->desc_tag);
  8202. switch (dtag) {
  8203. case ELS_DTAG_LNK_FAULT_CAP:
  8204. if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
  8205. FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
  8206. sizeof(struct fc_diag_lnkflt_desc)) {
  8207. lpfc_printf_log(phba, KERN_WARNING,
  8208. LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
  8209. "6465 Truncated Link Fault Diagnostic "
  8210. "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
  8211. desc_cnt, bytes_remain,
  8212. FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
  8213. sizeof(struct fc_diag_lnkflt_desc));
  8214. goto out;
  8215. }
  8216. plnkflt = (struct fc_diag_lnkflt_desc *)tlv;
  8217. lpfc_printf_log(phba, KERN_INFO,
  8218. LOG_ELS | LOG_LDS_EVENT,
  8219. "4626 Link Fault Desc Data: x%08x len x%x "
  8220. "da x%x dd x%x interval x%x\n",
  8221. be32_to_cpu(plnkflt->desc_tag),
  8222. be32_to_cpu(plnkflt->desc_len),
  8223. be32_to_cpu(
  8224. plnkflt->degrade_activate_threshold),
  8225. be32_to_cpu(
  8226. plnkflt->degrade_deactivate_threshold),
  8227. be32_to_cpu(plnkflt->fec_degrade_interval));
  8228. break;
  8229. case ELS_DTAG_CG_SIGNAL_CAP:
  8230. if (bytes_remain < FC_TLV_DESC_SZ_FROM_LENGTH(tlv) ||
  8231. FC_TLV_DESC_SZ_FROM_LENGTH(tlv) !=
  8232. sizeof(struct fc_diag_cg_sig_desc)) {
  8233. lpfc_printf_log(
  8234. phba, KERN_WARNING, LOG_CGN_MGMT,
  8235. "6466 Truncated cgn signal Diagnostic "
  8236. "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
  8237. desc_cnt, bytes_remain,
  8238. FC_TLV_DESC_SZ_FROM_LENGTH(tlv),
  8239. sizeof(struct fc_diag_cg_sig_desc));
  8240. goto out;
  8241. }
  8242. phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
  8243. phba->cgn_reg_signal = phba->cgn_init_reg_signal;
  8244. /* We start negotiation with lpfc_fabric_cgn_frequency.
  8245. * When we process the EDC, we will settle on the
  8246. * higher frequency.
  8247. */
  8248. phba->cgn_sig_freq = lpfc_fabric_cgn_frequency;
  8249. lpfc_least_capable_settings(
  8250. phba, (struct fc_diag_cg_sig_desc *)tlv);
  8251. break;
  8252. default:
  8253. dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
  8254. lpfc_printf_log(phba, KERN_WARNING,
  8255. LOG_ELS | LOG_CGN_MGMT | LOG_LDS_EVENT,
  8256. "6467 unknown Diagnostic "
  8257. "Descriptor[%d]: tag x%x (%s)\n",
  8258. desc_cnt, dtag, dtag_nm);
  8259. }
  8260. bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
  8261. tlv = fc_tlv_next_desc(tlv);
  8262. desc_cnt++;
  8263. }
  8264. out:
  8265. /* Need to send back an ACC */
  8266. lpfc_issue_els_edc_rsp(vport, cmdiocb, ndlp);
  8267. lpfc_config_cgn_signal(phba);
  8268. return 0;
  8269. }
  8270. /**
  8271. * lpfc_els_timeout - Handler funciton to the els timer
  8272. * @t: timer context used to obtain the vport.
  8273. *
  8274. * This routine is invoked by the ELS timer after timeout. It posts the ELS
  8275. * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
  8276. * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
  8277. * up the worker thread. It is for the worker thread to invoke the routine
  8278. * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
  8279. **/
  8280. void
  8281. lpfc_els_timeout(struct timer_list *t)
  8282. {
  8283. struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
  8284. struct lpfc_hba *phba = vport->phba;
  8285. uint32_t tmo_posted;
  8286. unsigned long iflag;
  8287. spin_lock_irqsave(&vport->work_port_lock, iflag);
  8288. tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
  8289. if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
  8290. vport->work_port_events |= WORKER_ELS_TMO;
  8291. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  8292. if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
  8293. lpfc_worker_wake_up(phba);
  8294. return;
  8295. }
  8296. /**
  8297. * lpfc_els_timeout_handler - Process an els timeout event
  8298. * @vport: pointer to a virtual N_Port data structure.
  8299. *
  8300. * This routine is the actual handler function that processes an ELS timeout
  8301. * event. It walks the ELS ring to get and abort all the IOCBs (except the
  8302. * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
  8303. * invoking the lpfc_sli_issue_abort_iotag() routine.
  8304. **/
  8305. void
  8306. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  8307. {
  8308. struct lpfc_hba *phba = vport->phba;
  8309. struct lpfc_sli_ring *pring;
  8310. struct lpfc_iocbq *tmp_iocb, *piocb;
  8311. IOCB_t *cmd = NULL;
  8312. struct lpfc_dmabuf *pcmd;
  8313. uint32_t els_command = 0;
  8314. uint32_t timeout;
  8315. uint32_t remote_ID = 0xffffffff;
  8316. LIST_HEAD(abort_list);
  8317. u32 ulp_command = 0, ulp_context = 0, did = 0, iotag = 0;
  8318. timeout = (uint32_t)(phba->fc_ratov << 1);
  8319. pring = lpfc_phba_elsring(phba);
  8320. if (unlikely(!pring))
  8321. return;
  8322. if (phba->pport->load_flag & FC_UNLOADING)
  8323. return;
  8324. spin_lock_irq(&phba->hbalock);
  8325. if (phba->sli_rev == LPFC_SLI_REV4)
  8326. spin_lock(&pring->ring_lock);
  8327. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  8328. ulp_command = get_job_cmnd(phba, piocb);
  8329. ulp_context = get_job_ulpcontext(phba, piocb);
  8330. did = get_job_els_rsp64_did(phba, piocb);
  8331. if (phba->sli_rev == LPFC_SLI_REV4) {
  8332. iotag = get_wqe_reqtag(piocb);
  8333. } else {
  8334. cmd = &piocb->iocb;
  8335. iotag = cmd->ulpIoTag;
  8336. }
  8337. if ((piocb->cmd_flag & LPFC_IO_LIBDFC) != 0 ||
  8338. ulp_command == CMD_ABORT_XRI_CX ||
  8339. ulp_command == CMD_ABORT_XRI_CN ||
  8340. ulp_command == CMD_CLOSE_XRI_CN)
  8341. continue;
  8342. if (piocb->vport != vport)
  8343. continue;
  8344. pcmd = piocb->cmd_dmabuf;
  8345. if (pcmd)
  8346. els_command = *(uint32_t *) (pcmd->virt);
  8347. if (els_command == ELS_CMD_FARP ||
  8348. els_command == ELS_CMD_FARPR ||
  8349. els_command == ELS_CMD_FDISC)
  8350. continue;
  8351. if (piocb->drvrTimeout > 0) {
  8352. if (piocb->drvrTimeout >= timeout)
  8353. piocb->drvrTimeout -= timeout;
  8354. else
  8355. piocb->drvrTimeout = 0;
  8356. continue;
  8357. }
  8358. remote_ID = 0xffffffff;
  8359. if (ulp_command != CMD_GEN_REQUEST64_CR) {
  8360. remote_ID = did;
  8361. } else {
  8362. struct lpfc_nodelist *ndlp;
  8363. ndlp = __lpfc_findnode_rpi(vport, ulp_context);
  8364. if (ndlp)
  8365. remote_ID = ndlp->nlp_DID;
  8366. }
  8367. list_add_tail(&piocb->dlist, &abort_list);
  8368. }
  8369. if (phba->sli_rev == LPFC_SLI_REV4)
  8370. spin_unlock(&pring->ring_lock);
  8371. spin_unlock_irq(&phba->hbalock);
  8372. list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
  8373. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  8374. "0127 ELS timeout Data: x%x x%x x%x "
  8375. "x%x\n", els_command,
  8376. remote_ID, ulp_command, iotag);
  8377. spin_lock_irq(&phba->hbalock);
  8378. list_del_init(&piocb->dlist);
  8379. lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
  8380. spin_unlock_irq(&phba->hbalock);
  8381. }
  8382. /* Make sure HBA is alive */
  8383. lpfc_issue_hb_tmo(phba);
  8384. if (!list_empty(&pring->txcmplq))
  8385. if (!(phba->pport->load_flag & FC_UNLOADING))
  8386. mod_timer(&vport->els_tmofunc,
  8387. jiffies + msecs_to_jiffies(1000 * timeout));
  8388. }
  8389. /**
  8390. * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
  8391. * @vport: pointer to a host virtual N_Port data structure.
  8392. *
  8393. * This routine is used to clean up all the outstanding ELS commands on a
  8394. * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
  8395. * routine. After that, it walks the ELS transmit queue to remove all the
  8396. * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
  8397. * the IOCBs with a non-NULL completion callback function, the callback
  8398. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  8399. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
  8400. * callback function, the IOCB will simply be released. Finally, it walks
  8401. * the ELS transmit completion queue to issue an abort IOCB to any transmit
  8402. * completion queue IOCB that is associated with the @vport and is not
  8403. * an IOCB from libdfc (i.e., the management plane IOCBs that are not
  8404. * part of the discovery state machine) out to HBA by invoking the
  8405. * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
  8406. * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
  8407. * the IOCBs are aborted when this function returns.
  8408. **/
  8409. void
  8410. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  8411. {
  8412. LIST_HEAD(abort_list);
  8413. LIST_HEAD(cancel_list);
  8414. struct lpfc_hba *phba = vport->phba;
  8415. struct lpfc_sli_ring *pring;
  8416. struct lpfc_iocbq *tmp_iocb, *piocb;
  8417. u32 ulp_command;
  8418. unsigned long iflags = 0;
  8419. bool mbx_tmo_err;
  8420. lpfc_fabric_abort_vport(vport);
  8421. /*
  8422. * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
  8423. * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
  8424. * ultimately grabs the ring_lock, the driver must splice the list into
  8425. * a working list and release the locks before calling the abort.
  8426. */
  8427. spin_lock_irqsave(&phba->hbalock, iflags);
  8428. pring = lpfc_phba_elsring(phba);
  8429. /* Bail out if we've no ELS wq, like in PCI error recovery case. */
  8430. if (unlikely(!pring)) {
  8431. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8432. return;
  8433. }
  8434. if (phba->sli_rev == LPFC_SLI_REV4)
  8435. spin_lock(&pring->ring_lock);
  8436. mbx_tmo_err = test_bit(MBX_TMO_ERR, &phba->bit_flags);
  8437. /* First we need to issue aborts to outstanding cmds on txcmpl */
  8438. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  8439. if (piocb->cmd_flag & LPFC_IO_LIBDFC && !mbx_tmo_err)
  8440. continue;
  8441. if (piocb->vport != vport)
  8442. continue;
  8443. if (piocb->cmd_flag & LPFC_DRIVER_ABORTED && !mbx_tmo_err)
  8444. continue;
  8445. /* On the ELS ring we can have ELS_REQUESTs or
  8446. * GEN_REQUESTs waiting for a response.
  8447. */
  8448. ulp_command = get_job_cmnd(phba, piocb);
  8449. if (ulp_command == CMD_ELS_REQUEST64_CR) {
  8450. list_add_tail(&piocb->dlist, &abort_list);
  8451. /* If the link is down when flushing ELS commands
  8452. * the firmware will not complete them till after
  8453. * the link comes back up. This may confuse
  8454. * discovery for the new link up, so we need to
  8455. * change the compl routine to just clean up the iocb
  8456. * and avoid any retry logic.
  8457. */
  8458. if (phba->link_state == LPFC_LINK_DOWN)
  8459. piocb->cmd_cmpl = lpfc_cmpl_els_link_down;
  8460. } else if (ulp_command == CMD_GEN_REQUEST64_CR ||
  8461. mbx_tmo_err)
  8462. list_add_tail(&piocb->dlist, &abort_list);
  8463. }
  8464. if (phba->sli_rev == LPFC_SLI_REV4)
  8465. spin_unlock(&pring->ring_lock);
  8466. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8467. /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
  8468. list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
  8469. spin_lock_irqsave(&phba->hbalock, iflags);
  8470. list_del_init(&piocb->dlist);
  8471. if (mbx_tmo_err)
  8472. list_move_tail(&piocb->list, &cancel_list);
  8473. else
  8474. lpfc_sli_issue_abort_iotag(phba, pring, piocb, NULL);
  8475. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8476. }
  8477. if (!list_empty(&cancel_list))
  8478. lpfc_sli_cancel_iocbs(phba, &cancel_list, IOSTAT_LOCAL_REJECT,
  8479. IOERR_SLI_ABORTED);
  8480. else
  8481. /* Make sure HBA is alive */
  8482. lpfc_issue_hb_tmo(phba);
  8483. if (!list_empty(&abort_list))
  8484. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  8485. "3387 abort list for txq not empty\n");
  8486. INIT_LIST_HEAD(&abort_list);
  8487. spin_lock_irqsave(&phba->hbalock, iflags);
  8488. if (phba->sli_rev == LPFC_SLI_REV4)
  8489. spin_lock(&pring->ring_lock);
  8490. /* No need to abort the txq list,
  8491. * just queue them up for lpfc_sli_cancel_iocbs
  8492. */
  8493. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  8494. ulp_command = get_job_cmnd(phba, piocb);
  8495. if (piocb->cmd_flag & LPFC_IO_LIBDFC)
  8496. continue;
  8497. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  8498. if (ulp_command == CMD_QUE_RING_BUF_CN ||
  8499. ulp_command == CMD_QUE_RING_BUF64_CN ||
  8500. ulp_command == CMD_CLOSE_XRI_CN ||
  8501. ulp_command == CMD_ABORT_XRI_CN ||
  8502. ulp_command == CMD_ABORT_XRI_CX)
  8503. continue;
  8504. if (piocb->vport != vport)
  8505. continue;
  8506. list_del_init(&piocb->list);
  8507. list_add_tail(&piocb->list, &abort_list);
  8508. }
  8509. /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
  8510. if (vport == phba->pport) {
  8511. list_for_each_entry_safe(piocb, tmp_iocb,
  8512. &phba->fabric_iocb_list, list) {
  8513. list_del_init(&piocb->list);
  8514. list_add_tail(&piocb->list, &abort_list);
  8515. }
  8516. }
  8517. if (phba->sli_rev == LPFC_SLI_REV4)
  8518. spin_unlock(&pring->ring_lock);
  8519. spin_unlock_irqrestore(&phba->hbalock, iflags);
  8520. /* Cancel all the IOCBs from the completions list */
  8521. lpfc_sli_cancel_iocbs(phba, &abort_list,
  8522. IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
  8523. return;
  8524. }
  8525. /**
  8526. * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
  8527. * @phba: pointer to lpfc hba data structure.
  8528. *
  8529. * This routine is used to clean up all the outstanding ELS commands on a
  8530. * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
  8531. * routine. After that, it walks the ELS transmit queue to remove all the
  8532. * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
  8533. * the IOCBs with the completion callback function associated, the callback
  8534. * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
  8535. * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
  8536. * callback function associated, the IOCB will simply be released. Finally,
  8537. * it walks the ELS transmit completion queue to issue an abort IOCB to any
  8538. * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
  8539. * management plane IOCBs that are not part of the discovery state machine)
  8540. * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
  8541. **/
  8542. void
  8543. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  8544. {
  8545. struct lpfc_vport *vport;
  8546. spin_lock_irq(&phba->port_list_lock);
  8547. list_for_each_entry(vport, &phba->port_list, listentry)
  8548. lpfc_els_flush_cmd(vport);
  8549. spin_unlock_irq(&phba->port_list_lock);
  8550. return;
  8551. }
  8552. /**
  8553. * lpfc_send_els_failure_event - Posts an ELS command failure event
  8554. * @phba: Pointer to hba context object.
  8555. * @cmdiocbp: Pointer to command iocb which reported error.
  8556. * @rspiocbp: Pointer to response iocb which reported error.
  8557. *
  8558. * This function sends an event when there is an ELS command
  8559. * failure.
  8560. **/
  8561. void
  8562. lpfc_send_els_failure_event(struct lpfc_hba *phba,
  8563. struct lpfc_iocbq *cmdiocbp,
  8564. struct lpfc_iocbq *rspiocbp)
  8565. {
  8566. struct lpfc_vport *vport = cmdiocbp->vport;
  8567. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8568. struct lpfc_lsrjt_event lsrjt_event;
  8569. struct lpfc_fabric_event_header fabric_event;
  8570. struct ls_rjt stat;
  8571. struct lpfc_nodelist *ndlp;
  8572. uint32_t *pcmd;
  8573. u32 ulp_status, ulp_word4;
  8574. ndlp = cmdiocbp->ndlp;
  8575. if (!ndlp)
  8576. return;
  8577. ulp_status = get_job_ulpstatus(phba, rspiocbp);
  8578. ulp_word4 = get_job_word4(phba, rspiocbp);
  8579. if (ulp_status == IOSTAT_LS_RJT) {
  8580. lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
  8581. lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
  8582. memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
  8583. sizeof(struct lpfc_name));
  8584. memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
  8585. sizeof(struct lpfc_name));
  8586. pcmd = (uint32_t *)cmdiocbp->cmd_dmabuf->virt;
  8587. lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
  8588. stat.un.ls_rjt_error_be = cpu_to_be32(ulp_word4);
  8589. lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
  8590. lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
  8591. fc_host_post_vendor_event(shost,
  8592. fc_get_event_number(),
  8593. sizeof(lsrjt_event),
  8594. (char *)&lsrjt_event,
  8595. LPFC_NL_VENDOR_ID);
  8596. return;
  8597. }
  8598. if (ulp_status == IOSTAT_NPORT_BSY ||
  8599. ulp_status == IOSTAT_FABRIC_BSY) {
  8600. fabric_event.event_type = FC_REG_FABRIC_EVENT;
  8601. if (ulp_status == IOSTAT_NPORT_BSY)
  8602. fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
  8603. else
  8604. fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
  8605. memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
  8606. sizeof(struct lpfc_name));
  8607. memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
  8608. sizeof(struct lpfc_name));
  8609. fc_host_post_vendor_event(shost,
  8610. fc_get_event_number(),
  8611. sizeof(fabric_event),
  8612. (char *)&fabric_event,
  8613. LPFC_NL_VENDOR_ID);
  8614. return;
  8615. }
  8616. }
  8617. /**
  8618. * lpfc_send_els_event - Posts unsolicited els event
  8619. * @vport: Pointer to vport object.
  8620. * @ndlp: Pointer FC node object.
  8621. * @payload: ELS command code type.
  8622. *
  8623. * This function posts an event when there is an incoming
  8624. * unsolicited ELS command.
  8625. **/
  8626. static void
  8627. lpfc_send_els_event(struct lpfc_vport *vport,
  8628. struct lpfc_nodelist *ndlp,
  8629. uint32_t *payload)
  8630. {
  8631. struct lpfc_els_event_header *els_data = NULL;
  8632. struct lpfc_logo_event *logo_data = NULL;
  8633. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  8634. if (*payload == ELS_CMD_LOGO) {
  8635. logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
  8636. if (!logo_data) {
  8637. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  8638. "0148 Failed to allocate memory "
  8639. "for LOGO event\n");
  8640. return;
  8641. }
  8642. els_data = &logo_data->header;
  8643. } else {
  8644. els_data = kmalloc(sizeof(struct lpfc_els_event_header),
  8645. GFP_KERNEL);
  8646. if (!els_data) {
  8647. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  8648. "0149 Failed to allocate memory "
  8649. "for ELS event\n");
  8650. return;
  8651. }
  8652. }
  8653. els_data->event_type = FC_REG_ELS_EVENT;
  8654. switch (*payload) {
  8655. case ELS_CMD_PLOGI:
  8656. els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
  8657. break;
  8658. case ELS_CMD_PRLO:
  8659. els_data->subcategory = LPFC_EVENT_PRLO_RCV;
  8660. break;
  8661. case ELS_CMD_ADISC:
  8662. els_data->subcategory = LPFC_EVENT_ADISC_RCV;
  8663. break;
  8664. case ELS_CMD_LOGO:
  8665. els_data->subcategory = LPFC_EVENT_LOGO_RCV;
  8666. /* Copy the WWPN in the LOGO payload */
  8667. memcpy(logo_data->logo_wwpn, &payload[2],
  8668. sizeof(struct lpfc_name));
  8669. break;
  8670. default:
  8671. kfree(els_data);
  8672. return;
  8673. }
  8674. memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
  8675. memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
  8676. if (*payload == ELS_CMD_LOGO) {
  8677. fc_host_post_vendor_event(shost,
  8678. fc_get_event_number(),
  8679. sizeof(struct lpfc_logo_event),
  8680. (char *)logo_data,
  8681. LPFC_NL_VENDOR_ID);
  8682. kfree(logo_data);
  8683. } else {
  8684. fc_host_post_vendor_event(shost,
  8685. fc_get_event_number(),
  8686. sizeof(struct lpfc_els_event_header),
  8687. (char *)els_data,
  8688. LPFC_NL_VENDOR_ID);
  8689. kfree(els_data);
  8690. }
  8691. return;
  8692. }
  8693. DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
  8694. FC_FPIN_LI_EVT_TYPES_INIT);
  8695. DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm, fc_fpin_deli_event_types,
  8696. FC_FPIN_DELI_EVT_TYPES_INIT);
  8697. DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm, fc_fpin_congn_event_types,
  8698. FC_FPIN_CONGN_EVT_TYPES_INIT);
  8699. DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm,
  8700. fc_fpin_congn_severity_types,
  8701. FC_FPIN_CONGN_SEVERITY_INIT);
  8702. /**
  8703. * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port
  8704. * @phba: Pointer to phba object.
  8705. * @wwnlist: Pointer to list of WWPNs in FPIN payload
  8706. * @cnt: count of WWPNs in FPIN payload
  8707. *
  8708. * This routine is called by LI and PC descriptors.
  8709. * Limit the number of WWPNs displayed to 6 log messages, 6 per log message
  8710. */
  8711. static void
  8712. lpfc_display_fpin_wwpn(struct lpfc_hba *phba, __be64 *wwnlist, u32 cnt)
  8713. {
  8714. char buf[LPFC_FPIN_WWPN_LINE_SZ];
  8715. __be64 wwn;
  8716. u64 wwpn;
  8717. int i, len;
  8718. int line = 0;
  8719. int wcnt = 0;
  8720. bool endit = false;
  8721. len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ, "Accessible WWPNs:");
  8722. for (i = 0; i < cnt; i++) {
  8723. /* Are we on the last WWPN */
  8724. if (i == (cnt - 1))
  8725. endit = true;
  8726. /* Extract the next WWPN from the payload */
  8727. wwn = *wwnlist++;
  8728. wwpn = be64_to_cpu(wwn);
  8729. len += scnprintf(buf + len, LPFC_FPIN_WWPN_LINE_SZ - len,
  8730. " %016llx", wwpn);
  8731. /* Log a message if we are on the last WWPN
  8732. * or if we hit the max allowed per message.
  8733. */
  8734. wcnt++;
  8735. if (wcnt == LPFC_FPIN_WWPN_LINE_CNT || endit) {
  8736. buf[len] = 0;
  8737. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8738. "4686 %s\n", buf);
  8739. /* Check if we reached the last WWPN */
  8740. if (endit)
  8741. return;
  8742. /* Limit the number of log message displayed per FPIN */
  8743. line++;
  8744. if (line == LPFC_FPIN_WWPN_NUM_LINE) {
  8745. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8746. "4687 %d WWPNs Truncated\n",
  8747. cnt - i - 1);
  8748. return;
  8749. }
  8750. /* Start over with next log message */
  8751. wcnt = 0;
  8752. len = scnprintf(buf, LPFC_FPIN_WWPN_LINE_SZ,
  8753. "Additional WWPNs:");
  8754. }
  8755. }
  8756. }
  8757. /**
  8758. * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
  8759. * @phba: Pointer to phba object.
  8760. * @tlv: Pointer to the Link Integrity Notification Descriptor.
  8761. *
  8762. * This function processes a Link Integrity FPIN event by logging a message.
  8763. **/
  8764. static void
  8765. lpfc_els_rcv_fpin_li(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
  8766. {
  8767. struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
  8768. const char *li_evt_str;
  8769. u32 li_evt, cnt;
  8770. li_evt = be16_to_cpu(li->event_type);
  8771. li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
  8772. cnt = be32_to_cpu(li->pname_count);
  8773. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8774. "4680 FPIN Link Integrity %s (x%x) "
  8775. "Detecting PN x%016llx Attached PN x%016llx "
  8776. "Duration %d mSecs Count %d Port Cnt %d\n",
  8777. li_evt_str, li_evt,
  8778. be64_to_cpu(li->detecting_wwpn),
  8779. be64_to_cpu(li->attached_wwpn),
  8780. be32_to_cpu(li->event_threshold),
  8781. be32_to_cpu(li->event_count), cnt);
  8782. lpfc_display_fpin_wwpn(phba, (__be64 *)&li->pname_list, cnt);
  8783. }
  8784. /**
  8785. * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event.
  8786. * @phba: Pointer to hba object.
  8787. * @tlv: Pointer to the Delivery Notification Descriptor TLV
  8788. *
  8789. * This function processes a Delivery FPIN event by logging a message.
  8790. **/
  8791. static void
  8792. lpfc_els_rcv_fpin_del(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
  8793. {
  8794. struct fc_fn_deli_desc *del = (struct fc_fn_deli_desc *)tlv;
  8795. const char *del_rsn_str;
  8796. u32 del_rsn;
  8797. __be32 *frame;
  8798. del_rsn = be16_to_cpu(del->deli_reason_code);
  8799. del_rsn_str = lpfc_get_fpin_deli_event_nm(del_rsn);
  8800. /* Skip over desc_tag/desc_len header to payload */
  8801. frame = (__be32 *)(del + 1);
  8802. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  8803. "4681 FPIN Delivery %s (x%x) "
  8804. "Detecting PN x%016llx Attached PN x%016llx "
  8805. "DiscHdr0 x%08x "
  8806. "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x "
  8807. "DiscHdr4 x%08x DiscHdr5 x%08x\n",
  8808. del_rsn_str, del_rsn,
  8809. be64_to_cpu(del->detecting_wwpn),
  8810. be64_to_cpu(del->attached_wwpn),
  8811. be32_to_cpu(frame[0]),
  8812. be32_to_cpu(frame[1]),
  8813. be32_to_cpu(frame[2]),
  8814. be32_to_cpu(frame[3]),
  8815. be32_to_cpu(frame[4]),
  8816. be32_to_cpu(frame[5]));
  8817. }
  8818. /**
  8819. * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event.
  8820. * @phba: Pointer to hba object.
  8821. * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV
  8822. *
  8823. * This function processes a Peer Congestion FPIN event by logging a message.
  8824. **/
  8825. static void
  8826. lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
  8827. {
  8828. struct fc_fn_peer_congn_desc *pc = (struct fc_fn_peer_congn_desc *)tlv;
  8829. const char *pc_evt_str;
  8830. u32 pc_evt, cnt;
  8831. pc_evt = be16_to_cpu(pc->event_type);
  8832. pc_evt_str = lpfc_get_fpin_congn_event_nm(pc_evt);
  8833. cnt = be32_to_cpu(pc->pname_count);
  8834. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_ELS,
  8835. "4684 FPIN Peer Congestion %s (x%x) "
  8836. "Duration %d mSecs "
  8837. "Detecting PN x%016llx Attached PN x%016llx "
  8838. "Impacted Port Cnt %d\n",
  8839. pc_evt_str, pc_evt,
  8840. be32_to_cpu(pc->event_period),
  8841. be64_to_cpu(pc->detecting_wwpn),
  8842. be64_to_cpu(pc->attached_wwpn),
  8843. cnt);
  8844. lpfc_display_fpin_wwpn(phba, (__be64 *)&pc->pname_list, cnt);
  8845. }
  8846. /**
  8847. * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification
  8848. * @phba: Pointer to hba object.
  8849. * @tlv: Pointer to the Congestion Notification Descriptor TLV
  8850. *
  8851. * This function processes an FPIN Congestion Notifiction. The notification
  8852. * could be an Alarm or Warning. This routine feeds that data into driver's
  8853. * running congestion algorithm. It also processes the FPIN by
  8854. * logging a message. It returns 1 to indicate deliver this message
  8855. * to the upper layer or 0 to indicate don't deliver it.
  8856. **/
  8857. static int
  8858. lpfc_els_rcv_fpin_cgn(struct lpfc_hba *phba, struct fc_tlv_desc *tlv)
  8859. {
  8860. struct lpfc_cgn_info *cp;
  8861. struct fc_fn_congn_desc *cgn = (struct fc_fn_congn_desc *)tlv;
  8862. const char *cgn_evt_str;
  8863. u32 cgn_evt;
  8864. const char *cgn_sev_str;
  8865. u32 cgn_sev;
  8866. uint16_t value;
  8867. u32 crc;
  8868. bool nm_log = false;
  8869. int rc = 1;
  8870. cgn_evt = be16_to_cpu(cgn->event_type);
  8871. cgn_evt_str = lpfc_get_fpin_congn_event_nm(cgn_evt);
  8872. cgn_sev = cgn->severity;
  8873. cgn_sev_str = lpfc_get_fpin_congn_severity_nm(cgn_sev);
  8874. /* The driver only takes action on a Credit Stall or Oversubscription
  8875. * event type to engage the IO algorithm. The driver prints an
  8876. * unmaskable message only for Lost Credit and Credit Stall.
  8877. * TODO: Still need to have definition of host action on clear,
  8878. * lost credit and device specific event types.
  8879. */
  8880. switch (cgn_evt) {
  8881. case FPIN_CONGN_LOST_CREDIT:
  8882. nm_log = true;
  8883. break;
  8884. case FPIN_CONGN_CREDIT_STALL:
  8885. nm_log = true;
  8886. fallthrough;
  8887. case FPIN_CONGN_OVERSUBSCRIPTION:
  8888. if (cgn_evt == FPIN_CONGN_OVERSUBSCRIPTION)
  8889. nm_log = false;
  8890. switch (cgn_sev) {
  8891. case FPIN_CONGN_SEVERITY_ERROR:
  8892. /* Take action here for an Alarm event */
  8893. if (phba->cmf_active_mode != LPFC_CFG_OFF) {
  8894. if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) {
  8895. /* Track of alarm cnt for SYNC_WQE */
  8896. atomic_inc(&phba->cgn_sync_alarm_cnt);
  8897. }
  8898. /* Track alarm cnt for cgn_info regardless
  8899. * of whether CMF is configured for Signals
  8900. * or FPINs.
  8901. */
  8902. atomic_inc(&phba->cgn_fabric_alarm_cnt);
  8903. goto cleanup;
  8904. }
  8905. break;
  8906. case FPIN_CONGN_SEVERITY_WARNING:
  8907. /* Take action here for a Warning event */
  8908. if (phba->cmf_active_mode != LPFC_CFG_OFF) {
  8909. if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) {
  8910. /* Track of warning cnt for SYNC_WQE */
  8911. atomic_inc(&phba->cgn_sync_warn_cnt);
  8912. }
  8913. /* Track warning cnt and freq for cgn_info
  8914. * regardless of whether CMF is configured for
  8915. * Signals or FPINs.
  8916. */
  8917. atomic_inc(&phba->cgn_fabric_warn_cnt);
  8918. cleanup:
  8919. /* Save frequency in ms */
  8920. phba->cgn_fpin_frequency =
  8921. be32_to_cpu(cgn->event_period);
  8922. value = phba->cgn_fpin_frequency;
  8923. if (phba->cgn_i) {
  8924. cp = (struct lpfc_cgn_info *)
  8925. phba->cgn_i->virt;
  8926. cp->cgn_alarm_freq =
  8927. cpu_to_le16(value);
  8928. cp->cgn_warn_freq =
  8929. cpu_to_le16(value);
  8930. crc = lpfc_cgn_calc_crc32
  8931. (cp,
  8932. LPFC_CGN_INFO_SZ,
  8933. LPFC_CGN_CRC32_SEED);
  8934. cp->cgn_info_crc = cpu_to_le32(crc);
  8935. }
  8936. /* Don't deliver to upper layer since
  8937. * driver took action on this tlv.
  8938. */
  8939. rc = 0;
  8940. }
  8941. break;
  8942. }
  8943. break;
  8944. }
  8945. /* Change the log level to unmaskable for the following event types. */
  8946. lpfc_printf_log(phba, (nm_log ? KERN_WARNING : KERN_INFO),
  8947. LOG_CGN_MGMT | LOG_ELS,
  8948. "4683 FPIN CONGESTION %s type %s (x%x) Event "
  8949. "Duration %d mSecs\n",
  8950. cgn_sev_str, cgn_evt_str, cgn_evt,
  8951. be32_to_cpu(cgn->event_period));
  8952. return rc;
  8953. }
  8954. void
  8955. lpfc_els_rcv_fpin(struct lpfc_vport *vport, void *p, u32 fpin_length)
  8956. {
  8957. struct lpfc_hba *phba = vport->phba;
  8958. struct fc_els_fpin *fpin = (struct fc_els_fpin *)p;
  8959. struct fc_tlv_desc *tlv, *first_tlv, *current_tlv;
  8960. const char *dtag_nm;
  8961. int desc_cnt = 0, bytes_remain, cnt;
  8962. u32 dtag, deliver = 0;
  8963. int len;
  8964. /* FPINs handled only if we are in the right discovery state */
  8965. if (vport->port_state < LPFC_DISC_AUTH)
  8966. return;
  8967. /* make sure there is the full fpin header */
  8968. if (fpin_length < sizeof(struct fc_els_fpin))
  8969. return;
  8970. /* Sanity check descriptor length. The desc_len value does not
  8971. * include space for the ELS command and the desc_len fields.
  8972. */
  8973. len = be32_to_cpu(fpin->desc_len);
  8974. if (fpin_length < len + sizeof(struct fc_els_fpin)) {
  8975. lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
  8976. "4671 Bad ELS FPIN length %d: %d\n",
  8977. len, fpin_length);
  8978. return;
  8979. }
  8980. tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
  8981. first_tlv = tlv;
  8982. bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
  8983. bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
  8984. /* process each descriptor separately */
  8985. while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
  8986. bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
  8987. dtag = be32_to_cpu(tlv->desc_tag);
  8988. switch (dtag) {
  8989. case ELS_DTAG_LNK_INTEGRITY:
  8990. lpfc_els_rcv_fpin_li(phba, tlv);
  8991. deliver = 1;
  8992. break;
  8993. case ELS_DTAG_DELIVERY:
  8994. lpfc_els_rcv_fpin_del(phba, tlv);
  8995. deliver = 1;
  8996. break;
  8997. case ELS_DTAG_PEER_CONGEST:
  8998. lpfc_els_rcv_fpin_peer_cgn(phba, tlv);
  8999. deliver = 1;
  9000. break;
  9001. case ELS_DTAG_CONGESTION:
  9002. deliver = lpfc_els_rcv_fpin_cgn(phba, tlv);
  9003. break;
  9004. default:
  9005. dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
  9006. lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
  9007. "4678 unknown FPIN descriptor[%d]: "
  9008. "tag x%x (%s)\n",
  9009. desc_cnt, dtag, dtag_nm);
  9010. /* If descriptor is bad, drop the rest of the data */
  9011. return;
  9012. }
  9013. lpfc_cgn_update_stat(phba, dtag);
  9014. cnt = be32_to_cpu(tlv->desc_len);
  9015. /* Sanity check descriptor length. The desc_len value does not
  9016. * include space for the desc_tag and the desc_len fields.
  9017. */
  9018. len -= (cnt + sizeof(struct fc_tlv_desc));
  9019. if (len < 0) {
  9020. dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
  9021. lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
  9022. "4672 Bad FPIN descriptor TLV length "
  9023. "%d: %d %d %s\n",
  9024. cnt, len, fpin_length, dtag_nm);
  9025. return;
  9026. }
  9027. current_tlv = tlv;
  9028. bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
  9029. tlv = fc_tlv_next_desc(tlv);
  9030. /* Format payload such that the FPIN delivered to the
  9031. * upper layer is a single descriptor FPIN.
  9032. */
  9033. if (desc_cnt)
  9034. memcpy(first_tlv, current_tlv,
  9035. (cnt + sizeof(struct fc_els_fpin)));
  9036. /* Adjust the length so that it only reflects a
  9037. * single descriptor FPIN.
  9038. */
  9039. fpin_length = cnt + sizeof(struct fc_els_fpin);
  9040. fpin->desc_len = cpu_to_be32(fpin_length);
  9041. fpin_length += sizeof(struct fc_els_fpin); /* the entire FPIN */
  9042. /* Send every descriptor individually to the upper layer */
  9043. if (deliver)
  9044. fc_host_fpin_rcv(lpfc_shost_from_vport(vport),
  9045. fpin_length, (char *)fpin);
  9046. desc_cnt++;
  9047. }
  9048. }
  9049. /**
  9050. * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
  9051. * @phba: pointer to lpfc hba data structure.
  9052. * @pring: pointer to a SLI ring.
  9053. * @vport: pointer to a host virtual N_Port data structure.
  9054. * @elsiocb: pointer to lpfc els command iocb data structure.
  9055. *
  9056. * This routine is used for processing the IOCB associated with a unsolicited
  9057. * event. It first determines whether there is an existing ndlp that matches
  9058. * the DID from the unsolicited IOCB. If not, it will create a new one with
  9059. * the DID from the unsolicited IOCB. The ELS command from the unsolicited
  9060. * IOCB is then used to invoke the proper routine and to set up proper state
  9061. * of the discovery state machine.
  9062. **/
  9063. static void
  9064. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  9065. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  9066. {
  9067. struct lpfc_nodelist *ndlp;
  9068. struct ls_rjt stat;
  9069. u32 *payload, payload_len;
  9070. u32 cmd = 0, did = 0, newnode, status = 0;
  9071. uint8_t rjt_exp, rjt_err = 0, init_link = 0;
  9072. struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
  9073. LPFC_MBOXQ_t *mbox;
  9074. if (!vport || !elsiocb->cmd_dmabuf)
  9075. goto dropit;
  9076. newnode = 0;
  9077. wcqe_cmpl = &elsiocb->wcqe_cmpl;
  9078. payload = elsiocb->cmd_dmabuf->virt;
  9079. if (phba->sli_rev == LPFC_SLI_REV4)
  9080. payload_len = wcqe_cmpl->total_data_placed;
  9081. else
  9082. payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
  9083. status = get_job_ulpstatus(phba, elsiocb);
  9084. cmd = *payload;
  9085. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  9086. lpfc_sli3_post_buffer(phba, pring, 1);
  9087. did = get_job_els_rsp64_did(phba, elsiocb);
  9088. if (status) {
  9089. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9090. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  9091. status, get_job_word4(phba, elsiocb), did);
  9092. goto dropit;
  9093. }
  9094. /* Check to see if link went down during discovery */
  9095. if (lpfc_els_chk_latt(vport))
  9096. goto dropit;
  9097. /* Ignore traffic received during vport shutdown. */
  9098. if (vport->load_flag & FC_UNLOADING)
  9099. goto dropit;
  9100. /* If NPort discovery is delayed drop incoming ELS */
  9101. if ((vport->fc_flag & FC_DISC_DELAYED) &&
  9102. (cmd != ELS_CMD_PLOGI))
  9103. goto dropit;
  9104. ndlp = lpfc_findnode_did(vport, did);
  9105. if (!ndlp) {
  9106. /* Cannot find existing Fabric ndlp, so allocate a new one */
  9107. ndlp = lpfc_nlp_init(vport, did);
  9108. if (!ndlp)
  9109. goto dropit;
  9110. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  9111. newnode = 1;
  9112. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  9113. ndlp->nlp_type |= NLP_FABRIC;
  9114. } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  9115. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  9116. newnode = 1;
  9117. }
  9118. phba->fc_stat.elsRcvFrame++;
  9119. /*
  9120. * Do not process any unsolicited ELS commands
  9121. * if the ndlp is in DEV_LOSS
  9122. */
  9123. spin_lock_irq(&ndlp->lock);
  9124. if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
  9125. spin_unlock_irq(&ndlp->lock);
  9126. if (newnode)
  9127. lpfc_nlp_put(ndlp);
  9128. goto dropit;
  9129. }
  9130. spin_unlock_irq(&ndlp->lock);
  9131. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  9132. if (!elsiocb->ndlp)
  9133. goto dropit;
  9134. elsiocb->vport = vport;
  9135. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  9136. cmd &= ELS_CMD_MASK;
  9137. }
  9138. /* ELS command <elsCmd> received from NPORT <did> */
  9139. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  9140. "0112 ELS command x%x received from NPORT x%x "
  9141. "refcnt %d Data: x%x x%x x%x x%x\n",
  9142. cmd, did, kref_read(&ndlp->kref), vport->port_state,
  9143. vport->fc_flag, vport->fc_myDID, vport->fc_prevDID);
  9144. /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
  9145. if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
  9146. (cmd != ELS_CMD_FLOGI) &&
  9147. !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
  9148. rjt_err = LSRJT_LOGICAL_BSY;
  9149. rjt_exp = LSEXP_NOTHING_MORE;
  9150. goto lsrjt;
  9151. }
  9152. switch (cmd) {
  9153. case ELS_CMD_PLOGI:
  9154. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9155. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  9156. did, vport->port_state, ndlp->nlp_flag);
  9157. phba->fc_stat.elsRcvPLOGI++;
  9158. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  9159. if (phba->sli_rev == LPFC_SLI_REV4 &&
  9160. (phba->pport->fc_flag & FC_PT2PT)) {
  9161. vport->fc_prevDID = vport->fc_myDID;
  9162. /* Our DID needs to be updated before registering
  9163. * the vfi. This is done in lpfc_rcv_plogi but
  9164. * that is called after the reg_vfi.
  9165. */
  9166. vport->fc_myDID =
  9167. bf_get(els_rsp64_sid,
  9168. &elsiocb->wqe.xmit_els_rsp);
  9169. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  9170. "3312 Remote port assigned DID x%x "
  9171. "%x\n", vport->fc_myDID,
  9172. vport->fc_prevDID);
  9173. }
  9174. lpfc_send_els_event(vport, ndlp, payload);
  9175. /* If Nport discovery is delayed, reject PLOGIs */
  9176. if (vport->fc_flag & FC_DISC_DELAYED) {
  9177. rjt_err = LSRJT_UNABLE_TPC;
  9178. rjt_exp = LSEXP_NOTHING_MORE;
  9179. break;
  9180. }
  9181. if (vport->port_state < LPFC_DISC_AUTH) {
  9182. if (!(phba->pport->fc_flag & FC_PT2PT) ||
  9183. (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
  9184. rjt_err = LSRJT_UNABLE_TPC;
  9185. rjt_exp = LSEXP_NOTHING_MORE;
  9186. break;
  9187. }
  9188. }
  9189. spin_lock_irq(&ndlp->lock);
  9190. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  9191. spin_unlock_irq(&ndlp->lock);
  9192. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  9193. NLP_EVT_RCV_PLOGI);
  9194. break;
  9195. case ELS_CMD_FLOGI:
  9196. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9197. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  9198. did, vport->port_state, ndlp->nlp_flag);
  9199. phba->fc_stat.elsRcvFLOGI++;
  9200. /* If the driver believes fabric discovery is done and is ready,
  9201. * bounce the link. There is some descrepancy.
  9202. */
  9203. if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
  9204. vport->fc_flag & FC_PT2PT &&
  9205. vport->rcv_flogi_cnt >= 1) {
  9206. rjt_err = LSRJT_LOGICAL_BSY;
  9207. rjt_exp = LSEXP_NOTHING_MORE;
  9208. init_link++;
  9209. goto lsrjt;
  9210. }
  9211. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  9212. /* retain node if our response is deferred */
  9213. if (phba->defer_flogi_acc_flag)
  9214. break;
  9215. if (newnode)
  9216. lpfc_disc_state_machine(vport, ndlp, NULL,
  9217. NLP_EVT_DEVICE_RM);
  9218. break;
  9219. case ELS_CMD_LOGO:
  9220. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9221. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  9222. did, vport->port_state, ndlp->nlp_flag);
  9223. phba->fc_stat.elsRcvLOGO++;
  9224. lpfc_send_els_event(vport, ndlp, payload);
  9225. if (vport->port_state < LPFC_DISC_AUTH) {
  9226. rjt_err = LSRJT_UNABLE_TPC;
  9227. rjt_exp = LSEXP_NOTHING_MORE;
  9228. break;
  9229. }
  9230. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  9231. if (newnode)
  9232. lpfc_disc_state_machine(vport, ndlp, NULL,
  9233. NLP_EVT_DEVICE_RM);
  9234. break;
  9235. case ELS_CMD_PRLO:
  9236. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9237. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  9238. did, vport->port_state, ndlp->nlp_flag);
  9239. phba->fc_stat.elsRcvPRLO++;
  9240. lpfc_send_els_event(vport, ndlp, payload);
  9241. if (vport->port_state < LPFC_DISC_AUTH) {
  9242. rjt_err = LSRJT_UNABLE_TPC;
  9243. rjt_exp = LSEXP_NOTHING_MORE;
  9244. break;
  9245. }
  9246. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  9247. break;
  9248. case ELS_CMD_LCB:
  9249. phba->fc_stat.elsRcvLCB++;
  9250. lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
  9251. break;
  9252. case ELS_CMD_RDP:
  9253. phba->fc_stat.elsRcvRDP++;
  9254. lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
  9255. break;
  9256. case ELS_CMD_RSCN:
  9257. phba->fc_stat.elsRcvRSCN++;
  9258. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  9259. if (newnode)
  9260. lpfc_disc_state_machine(vport, ndlp, NULL,
  9261. NLP_EVT_DEVICE_RM);
  9262. break;
  9263. case ELS_CMD_ADISC:
  9264. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9265. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  9266. did, vport->port_state, ndlp->nlp_flag);
  9267. lpfc_send_els_event(vport, ndlp, payload);
  9268. phba->fc_stat.elsRcvADISC++;
  9269. if (vport->port_state < LPFC_DISC_AUTH) {
  9270. rjt_err = LSRJT_UNABLE_TPC;
  9271. rjt_exp = LSEXP_NOTHING_MORE;
  9272. break;
  9273. }
  9274. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  9275. NLP_EVT_RCV_ADISC);
  9276. break;
  9277. case ELS_CMD_PDISC:
  9278. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9279. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  9280. did, vport->port_state, ndlp->nlp_flag);
  9281. phba->fc_stat.elsRcvPDISC++;
  9282. if (vport->port_state < LPFC_DISC_AUTH) {
  9283. rjt_err = LSRJT_UNABLE_TPC;
  9284. rjt_exp = LSEXP_NOTHING_MORE;
  9285. break;
  9286. }
  9287. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  9288. NLP_EVT_RCV_PDISC);
  9289. break;
  9290. case ELS_CMD_FARPR:
  9291. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9292. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  9293. did, vport->port_state, ndlp->nlp_flag);
  9294. phba->fc_stat.elsRcvFARPR++;
  9295. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  9296. break;
  9297. case ELS_CMD_FARP:
  9298. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9299. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  9300. did, vport->port_state, ndlp->nlp_flag);
  9301. phba->fc_stat.elsRcvFARP++;
  9302. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  9303. break;
  9304. case ELS_CMD_FAN:
  9305. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9306. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  9307. did, vport->port_state, ndlp->nlp_flag);
  9308. phba->fc_stat.elsRcvFAN++;
  9309. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  9310. break;
  9311. case ELS_CMD_PRLI:
  9312. case ELS_CMD_NVMEPRLI:
  9313. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9314. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  9315. did, vport->port_state, ndlp->nlp_flag);
  9316. phba->fc_stat.elsRcvPRLI++;
  9317. if ((vport->port_state < LPFC_DISC_AUTH) &&
  9318. (vport->fc_flag & FC_FABRIC)) {
  9319. rjt_err = LSRJT_UNABLE_TPC;
  9320. rjt_exp = LSEXP_NOTHING_MORE;
  9321. break;
  9322. }
  9323. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  9324. break;
  9325. case ELS_CMD_LIRR:
  9326. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9327. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  9328. did, vport->port_state, ndlp->nlp_flag);
  9329. phba->fc_stat.elsRcvLIRR++;
  9330. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  9331. if (newnode)
  9332. lpfc_disc_state_machine(vport, ndlp, NULL,
  9333. NLP_EVT_DEVICE_RM);
  9334. break;
  9335. case ELS_CMD_RLS:
  9336. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9337. "RCV RLS: did:x%x/ste:x%x flg:x%x",
  9338. did, vport->port_state, ndlp->nlp_flag);
  9339. phba->fc_stat.elsRcvRLS++;
  9340. lpfc_els_rcv_rls(vport, elsiocb, ndlp);
  9341. if (newnode)
  9342. lpfc_disc_state_machine(vport, ndlp, NULL,
  9343. NLP_EVT_DEVICE_RM);
  9344. break;
  9345. case ELS_CMD_RPL:
  9346. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9347. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  9348. did, vport->port_state, ndlp->nlp_flag);
  9349. phba->fc_stat.elsRcvRPL++;
  9350. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  9351. if (newnode)
  9352. lpfc_disc_state_machine(vport, ndlp, NULL,
  9353. NLP_EVT_DEVICE_RM);
  9354. break;
  9355. case ELS_CMD_RNID:
  9356. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9357. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  9358. did, vport->port_state, ndlp->nlp_flag);
  9359. phba->fc_stat.elsRcvRNID++;
  9360. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  9361. if (newnode)
  9362. lpfc_disc_state_machine(vport, ndlp, NULL,
  9363. NLP_EVT_DEVICE_RM);
  9364. break;
  9365. case ELS_CMD_RTV:
  9366. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9367. "RCV RTV: did:x%x/ste:x%x flg:x%x",
  9368. did, vport->port_state, ndlp->nlp_flag);
  9369. phba->fc_stat.elsRcvRTV++;
  9370. lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
  9371. if (newnode)
  9372. lpfc_disc_state_machine(vport, ndlp, NULL,
  9373. NLP_EVT_DEVICE_RM);
  9374. break;
  9375. case ELS_CMD_RRQ:
  9376. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9377. "RCV RRQ: did:x%x/ste:x%x flg:x%x",
  9378. did, vport->port_state, ndlp->nlp_flag);
  9379. phba->fc_stat.elsRcvRRQ++;
  9380. lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
  9381. if (newnode)
  9382. lpfc_disc_state_machine(vport, ndlp, NULL,
  9383. NLP_EVT_DEVICE_RM);
  9384. break;
  9385. case ELS_CMD_ECHO:
  9386. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9387. "RCV ECHO: did:x%x/ste:x%x flg:x%x",
  9388. did, vport->port_state, ndlp->nlp_flag);
  9389. phba->fc_stat.elsRcvECHO++;
  9390. lpfc_els_rcv_echo(vport, elsiocb, ndlp);
  9391. if (newnode)
  9392. lpfc_disc_state_machine(vport, ndlp, NULL,
  9393. NLP_EVT_DEVICE_RM);
  9394. break;
  9395. case ELS_CMD_REC:
  9396. /* receive this due to exchange closed */
  9397. rjt_err = LSRJT_UNABLE_TPC;
  9398. rjt_exp = LSEXP_INVALID_OX_RX;
  9399. break;
  9400. case ELS_CMD_FPIN:
  9401. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9402. "RCV FPIN: did:x%x/ste:x%x flg:x%x",
  9403. did, vport->port_state, ndlp->nlp_flag);
  9404. lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
  9405. payload_len);
  9406. /* There are no replies, so no rjt codes */
  9407. break;
  9408. case ELS_CMD_EDC:
  9409. lpfc_els_rcv_edc(vport, elsiocb, ndlp);
  9410. break;
  9411. case ELS_CMD_RDF:
  9412. phba->fc_stat.elsRcvRDF++;
  9413. /* Accept RDF only from fabric controller */
  9414. if (did != Fabric_Cntl_DID) {
  9415. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  9416. "1115 Received RDF from invalid DID "
  9417. "x%x\n", did);
  9418. rjt_err = LSRJT_PROTOCOL_ERR;
  9419. rjt_exp = LSEXP_NOTHING_MORE;
  9420. goto lsrjt;
  9421. }
  9422. lpfc_els_rcv_rdf(vport, elsiocb, ndlp);
  9423. break;
  9424. default:
  9425. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  9426. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  9427. cmd, did, vport->port_state);
  9428. /* Unsupported ELS command, reject */
  9429. rjt_err = LSRJT_CMD_UNSUPPORTED;
  9430. rjt_exp = LSEXP_NOTHING_MORE;
  9431. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  9432. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9433. "0115 Unknown ELS command x%x "
  9434. "received from NPORT x%x\n", cmd, did);
  9435. if (newnode)
  9436. lpfc_disc_state_machine(vport, ndlp, NULL,
  9437. NLP_EVT_DEVICE_RM);
  9438. break;
  9439. }
  9440. lsrjt:
  9441. /* check if need to LS_RJT received ELS cmd */
  9442. if (rjt_err) {
  9443. memset(&stat, 0, sizeof(stat));
  9444. stat.un.b.lsRjtRsnCode = rjt_err;
  9445. stat.un.b.lsRjtRsnCodeExp = rjt_exp;
  9446. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  9447. NULL);
  9448. /* Remove the reference from above for new nodes. */
  9449. if (newnode)
  9450. lpfc_disc_state_machine(vport, ndlp, NULL,
  9451. NLP_EVT_DEVICE_RM);
  9452. }
  9453. /* Release the reference on this elsiocb, not the ndlp. */
  9454. lpfc_nlp_put(elsiocb->ndlp);
  9455. elsiocb->ndlp = NULL;
  9456. /* Special case. Driver received an unsolicited command that
  9457. * unsupportable given the driver's current state. Reset the
  9458. * link and start over.
  9459. */
  9460. if (init_link) {
  9461. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9462. if (!mbox)
  9463. return;
  9464. lpfc_linkdown(phba);
  9465. lpfc_init_link(phba, mbox,
  9466. phba->cfg_topology,
  9467. phba->cfg_link_speed);
  9468. mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  9469. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  9470. mbox->vport = vport;
  9471. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
  9472. MBX_NOT_FINISHED)
  9473. mempool_free(mbox, phba->mbox_mem_pool);
  9474. }
  9475. return;
  9476. dropit:
  9477. if (vport && !(vport->load_flag & FC_UNLOADING))
  9478. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9479. "0111 Dropping received ELS cmd "
  9480. "Data: x%x x%x x%x x%x\n",
  9481. cmd, status, get_job_word4(phba, elsiocb), did);
  9482. phba->fc_stat.elsRcvDrop++;
  9483. }
  9484. /**
  9485. * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
  9486. * @phba: pointer to lpfc hba data structure.
  9487. * @pring: pointer to a SLI ring.
  9488. * @elsiocb: pointer to lpfc els iocb data structure.
  9489. *
  9490. * This routine is used to process an unsolicited event received from a SLI
  9491. * (Service Level Interface) ring. The actual processing of the data buffer
  9492. * associated with the unsolicited event is done by invoking the routine
  9493. * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
  9494. * SLI ring on which the unsolicited event was received.
  9495. **/
  9496. void
  9497. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  9498. struct lpfc_iocbq *elsiocb)
  9499. {
  9500. struct lpfc_vport *vport = elsiocb->vport;
  9501. u32 ulp_command, status, parameter, bde_count = 0;
  9502. IOCB_t *icmd;
  9503. struct lpfc_wcqe_complete *wcqe_cmpl = NULL;
  9504. struct lpfc_dmabuf *bdeBuf1 = elsiocb->cmd_dmabuf;
  9505. struct lpfc_dmabuf *bdeBuf2 = elsiocb->bpl_dmabuf;
  9506. dma_addr_t paddr;
  9507. elsiocb->cmd_dmabuf = NULL;
  9508. elsiocb->rsp_dmabuf = NULL;
  9509. elsiocb->bpl_dmabuf = NULL;
  9510. wcqe_cmpl = &elsiocb->wcqe_cmpl;
  9511. ulp_command = get_job_cmnd(phba, elsiocb);
  9512. status = get_job_ulpstatus(phba, elsiocb);
  9513. parameter = get_job_word4(phba, elsiocb);
  9514. if (phba->sli_rev == LPFC_SLI_REV4)
  9515. bde_count = wcqe_cmpl->word3;
  9516. else
  9517. bde_count = elsiocb->iocb.ulpBdeCount;
  9518. if (status == IOSTAT_NEED_BUFFER) {
  9519. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  9520. } else if (status == IOSTAT_LOCAL_REJECT &&
  9521. (parameter & IOERR_PARAM_MASK) ==
  9522. IOERR_RCV_BUFFER_WAITING) {
  9523. phba->fc_stat.NoRcvBuf++;
  9524. /* Not enough posted buffers; Try posting more buffers */
  9525. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  9526. lpfc_sli3_post_buffer(phba, pring, 0);
  9527. return;
  9528. }
  9529. if (phba->sli_rev == LPFC_SLI_REV3) {
  9530. icmd = &elsiocb->iocb;
  9531. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  9532. (ulp_command == CMD_IOCB_RCV_ELS64_CX ||
  9533. ulp_command == CMD_IOCB_RCV_SEQ64_CX)) {
  9534. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  9535. vport = phba->pport;
  9536. else
  9537. vport = lpfc_find_vport_by_vpid(phba,
  9538. icmd->unsli3.rcvsli3.vpi);
  9539. }
  9540. }
  9541. /* If there are no BDEs associated
  9542. * with this IOCB, there is nothing to do.
  9543. */
  9544. if (bde_count == 0)
  9545. return;
  9546. /* Account for SLI2 or SLI3 and later unsolicited buffering */
  9547. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  9548. elsiocb->cmd_dmabuf = bdeBuf1;
  9549. if (bde_count == 2)
  9550. elsiocb->bpl_dmabuf = bdeBuf2;
  9551. } else {
  9552. icmd = &elsiocb->iocb;
  9553. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  9554. icmd->un.cont64[0].addrLow);
  9555. elsiocb->cmd_dmabuf = lpfc_sli_ringpostbuf_get(phba, pring,
  9556. paddr);
  9557. if (bde_count == 2) {
  9558. paddr = getPaddr(icmd->un.cont64[1].addrHigh,
  9559. icmd->un.cont64[1].addrLow);
  9560. elsiocb->bpl_dmabuf = lpfc_sli_ringpostbuf_get(phba,
  9561. pring,
  9562. paddr);
  9563. }
  9564. }
  9565. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  9566. /*
  9567. * The different unsolicited event handlers would tell us
  9568. * if they are done with "mp" by setting cmd_dmabuf to NULL.
  9569. */
  9570. if (elsiocb->cmd_dmabuf) {
  9571. lpfc_in_buf_free(phba, elsiocb->cmd_dmabuf);
  9572. elsiocb->cmd_dmabuf = NULL;
  9573. }
  9574. if (elsiocb->bpl_dmabuf) {
  9575. lpfc_in_buf_free(phba, elsiocb->bpl_dmabuf);
  9576. elsiocb->bpl_dmabuf = NULL;
  9577. }
  9578. }
  9579. static void
  9580. lpfc_start_fdmi(struct lpfc_vport *vport)
  9581. {
  9582. struct lpfc_nodelist *ndlp;
  9583. /* If this is the first time, allocate an ndlp and initialize
  9584. * it. Otherwise, make sure the node is enabled and then do the
  9585. * login.
  9586. */
  9587. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  9588. if (!ndlp) {
  9589. ndlp = lpfc_nlp_init(vport, FDMI_DID);
  9590. if (ndlp) {
  9591. ndlp->nlp_type |= NLP_FABRIC;
  9592. } else {
  9593. return;
  9594. }
  9595. }
  9596. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  9597. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  9598. }
  9599. /**
  9600. * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
  9601. * @phba: pointer to lpfc hba data structure.
  9602. * @vport: pointer to a virtual N_Port data structure.
  9603. *
  9604. * This routine issues a Port Login (PLOGI) to the Name Server with
  9605. * State Change Request (SCR) for a @vport. This routine will create an
  9606. * ndlp for the Name Server associated to the @vport if such node does
  9607. * not already exist. The PLOGI to Name Server is issued by invoking the
  9608. * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
  9609. * (FDMI) is configured to the @vport, a FDMI node will be created and
  9610. * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
  9611. **/
  9612. void
  9613. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  9614. {
  9615. struct lpfc_nodelist *ndlp;
  9616. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  9617. /*
  9618. * If lpfc_delay_discovery parameter is set and the clean address
  9619. * bit is cleared and fc fabric parameters chenged, delay FC NPort
  9620. * discovery.
  9621. */
  9622. spin_lock_irq(shost->host_lock);
  9623. if (vport->fc_flag & FC_DISC_DELAYED) {
  9624. spin_unlock_irq(shost->host_lock);
  9625. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9626. "3334 Delay fc port discovery for %d secs\n",
  9627. phba->fc_ratov);
  9628. mod_timer(&vport->delayed_disc_tmo,
  9629. jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
  9630. return;
  9631. }
  9632. spin_unlock_irq(shost->host_lock);
  9633. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  9634. if (!ndlp) {
  9635. ndlp = lpfc_nlp_init(vport, NameServer_DID);
  9636. if (!ndlp) {
  9637. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  9638. lpfc_disc_start(vport);
  9639. return;
  9640. }
  9641. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  9642. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9643. "0251 NameServer login: no memory\n");
  9644. return;
  9645. }
  9646. }
  9647. ndlp->nlp_type |= NLP_FABRIC;
  9648. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  9649. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  9650. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  9651. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9652. "0252 Cannot issue NameServer login\n");
  9653. return;
  9654. }
  9655. if ((phba->cfg_enable_SmartSAN ||
  9656. (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
  9657. (vport->load_flag & FC_ALLOW_FDMI))
  9658. lpfc_start_fdmi(vport);
  9659. }
  9660. /**
  9661. * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
  9662. * @phba: pointer to lpfc hba data structure.
  9663. * @pmb: pointer to the driver internal queue element for mailbox command.
  9664. *
  9665. * This routine is the completion callback function to register new vport
  9666. * mailbox command. If the new vport mailbox command completes successfully,
  9667. * the fabric registration login shall be performed on physical port (the
  9668. * new vport created is actually a physical port, with VPI 0) or the port
  9669. * login to Name Server for State Change Request (SCR) will be performed
  9670. * on virtual port (real virtual port, with VPI greater than 0).
  9671. **/
  9672. static void
  9673. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  9674. {
  9675. struct lpfc_vport *vport = pmb->vport;
  9676. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  9677. struct lpfc_nodelist *ndlp = pmb->ctx_ndlp;
  9678. MAILBOX_t *mb = &pmb->u.mb;
  9679. int rc;
  9680. spin_lock_irq(shost->host_lock);
  9681. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  9682. spin_unlock_irq(shost->host_lock);
  9683. if (mb->mbxStatus) {
  9684. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9685. "0915 Register VPI failed : Status: x%x"
  9686. " upd bit: x%x \n", mb->mbxStatus,
  9687. mb->un.varRegVpi.upd);
  9688. if (phba->sli_rev == LPFC_SLI_REV4 &&
  9689. mb->un.varRegVpi.upd)
  9690. goto mbox_err_exit ;
  9691. switch (mb->mbxStatus) {
  9692. case 0x11: /* unsupported feature */
  9693. case 0x9603: /* max_vpi exceeded */
  9694. case 0x9602: /* Link event since CLEAR_LA */
  9695. /* giving up on vport registration */
  9696. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  9697. spin_lock_irq(shost->host_lock);
  9698. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  9699. spin_unlock_irq(shost->host_lock);
  9700. lpfc_can_disctmo(vport);
  9701. break;
  9702. /* If reg_vpi fail with invalid VPI status, re-init VPI */
  9703. case 0x20:
  9704. spin_lock_irq(shost->host_lock);
  9705. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  9706. spin_unlock_irq(shost->host_lock);
  9707. lpfc_init_vpi(phba, pmb, vport->vpi);
  9708. pmb->vport = vport;
  9709. pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
  9710. rc = lpfc_sli_issue_mbox(phba, pmb,
  9711. MBX_NOWAIT);
  9712. if (rc == MBX_NOT_FINISHED) {
  9713. lpfc_printf_vlog(vport, KERN_ERR,
  9714. LOG_TRACE_EVENT,
  9715. "2732 Failed to issue INIT_VPI"
  9716. " mailbox command\n");
  9717. } else {
  9718. lpfc_nlp_put(ndlp);
  9719. return;
  9720. }
  9721. fallthrough;
  9722. default:
  9723. /* Try to recover from this error */
  9724. if (phba->sli_rev == LPFC_SLI_REV4)
  9725. lpfc_sli4_unreg_all_rpis(vport);
  9726. lpfc_mbx_unreg_vpi(vport);
  9727. spin_lock_irq(shost->host_lock);
  9728. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  9729. spin_unlock_irq(shost->host_lock);
  9730. if (mb->mbxStatus == MBX_NOT_FINISHED)
  9731. break;
  9732. if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
  9733. !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
  9734. if (phba->sli_rev == LPFC_SLI_REV4)
  9735. lpfc_issue_init_vfi(vport);
  9736. else
  9737. lpfc_initial_flogi(vport);
  9738. } else {
  9739. lpfc_initial_fdisc(vport);
  9740. }
  9741. break;
  9742. }
  9743. } else {
  9744. spin_lock_irq(shost->host_lock);
  9745. vport->vpi_state |= LPFC_VPI_REGISTERED;
  9746. spin_unlock_irq(shost->host_lock);
  9747. if (vport == phba->pport) {
  9748. if (phba->sli_rev < LPFC_SLI_REV4)
  9749. lpfc_issue_fabric_reglogin(vport);
  9750. else {
  9751. /*
  9752. * If the physical port is instantiated using
  9753. * FDISC, do not start vport discovery.
  9754. */
  9755. if (vport->port_state != LPFC_FDISC)
  9756. lpfc_start_fdiscs(phba);
  9757. lpfc_do_scr_ns_plogi(phba, vport);
  9758. }
  9759. } else {
  9760. lpfc_do_scr_ns_plogi(phba, vport);
  9761. }
  9762. }
  9763. mbox_err_exit:
  9764. /* Now, we decrement the ndlp reference count held for this
  9765. * callback function
  9766. */
  9767. lpfc_nlp_put(ndlp);
  9768. mempool_free(pmb, phba->mbox_mem_pool);
  9769. return;
  9770. }
  9771. /**
  9772. * lpfc_register_new_vport - Register a new vport with a HBA
  9773. * @phba: pointer to lpfc hba data structure.
  9774. * @vport: pointer to a host virtual N_Port data structure.
  9775. * @ndlp: pointer to a node-list data structure.
  9776. *
  9777. * This routine registers the @vport as a new virtual port with a HBA.
  9778. * It is done through a registering vpi mailbox command.
  9779. **/
  9780. void
  9781. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  9782. struct lpfc_nodelist *ndlp)
  9783. {
  9784. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  9785. LPFC_MBOXQ_t *mbox;
  9786. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  9787. if (mbox) {
  9788. lpfc_reg_vpi(vport, mbox);
  9789. mbox->vport = vport;
  9790. mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
  9791. if (!mbox->ctx_ndlp) {
  9792. mempool_free(mbox, phba->mbox_mem_pool);
  9793. goto mbox_err_exit;
  9794. }
  9795. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  9796. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  9797. == MBX_NOT_FINISHED) {
  9798. /* mailbox command not success, decrement ndlp
  9799. * reference count for this command
  9800. */
  9801. lpfc_nlp_put(ndlp);
  9802. mempool_free(mbox, phba->mbox_mem_pool);
  9803. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9804. "0253 Register VPI: Can't send mbox\n");
  9805. goto mbox_err_exit;
  9806. }
  9807. } else {
  9808. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9809. "0254 Register VPI: no memory\n");
  9810. goto mbox_err_exit;
  9811. }
  9812. return;
  9813. mbox_err_exit:
  9814. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  9815. spin_lock_irq(shost->host_lock);
  9816. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  9817. spin_unlock_irq(shost->host_lock);
  9818. return;
  9819. }
  9820. /**
  9821. * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
  9822. * @phba: pointer to lpfc hba data structure.
  9823. *
  9824. * This routine cancels the retry delay timers to all the vports.
  9825. **/
  9826. void
  9827. lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
  9828. {
  9829. struct lpfc_vport **vports;
  9830. struct lpfc_nodelist *ndlp;
  9831. uint32_t link_state;
  9832. int i;
  9833. /* Treat this failure as linkdown for all vports */
  9834. link_state = phba->link_state;
  9835. lpfc_linkdown(phba);
  9836. phba->link_state = link_state;
  9837. vports = lpfc_create_vport_work_array(phba);
  9838. if (vports) {
  9839. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  9840. ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
  9841. if (ndlp)
  9842. lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
  9843. lpfc_els_flush_cmd(vports[i]);
  9844. }
  9845. lpfc_destroy_vport_work_array(phba, vports);
  9846. }
  9847. }
  9848. /**
  9849. * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
  9850. * @phba: pointer to lpfc hba data structure.
  9851. *
  9852. * This routine abort all pending discovery commands and
  9853. * start a timer to retry FLOGI for the physical port
  9854. * discovery.
  9855. **/
  9856. void
  9857. lpfc_retry_pport_discovery(struct lpfc_hba *phba)
  9858. {
  9859. struct lpfc_nodelist *ndlp;
  9860. /* Cancel the all vports retry delay retry timers */
  9861. lpfc_cancel_all_vport_retry_delay_timer(phba);
  9862. /* If fabric require FLOGI, then re-instantiate physical login */
  9863. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  9864. if (!ndlp)
  9865. return;
  9866. mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
  9867. spin_lock_irq(&ndlp->lock);
  9868. ndlp->nlp_flag |= NLP_DELAY_TMO;
  9869. spin_unlock_irq(&ndlp->lock);
  9870. ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
  9871. phba->pport->port_state = LPFC_FLOGI;
  9872. return;
  9873. }
  9874. /**
  9875. * lpfc_fabric_login_reqd - Check if FLOGI required.
  9876. * @phba: pointer to lpfc hba data structure.
  9877. * @cmdiocb: pointer to FDISC command iocb.
  9878. * @rspiocb: pointer to FDISC response iocb.
  9879. *
  9880. * This routine checks if a FLOGI is reguired for FDISC
  9881. * to succeed.
  9882. **/
  9883. static int
  9884. lpfc_fabric_login_reqd(struct lpfc_hba *phba,
  9885. struct lpfc_iocbq *cmdiocb,
  9886. struct lpfc_iocbq *rspiocb)
  9887. {
  9888. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  9889. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  9890. if (ulp_status != IOSTAT_FABRIC_RJT ||
  9891. ulp_word4 != RJT_LOGIN_REQUIRED)
  9892. return 0;
  9893. else
  9894. return 1;
  9895. }
  9896. /**
  9897. * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
  9898. * @phba: pointer to lpfc hba data structure.
  9899. * @cmdiocb: pointer to lpfc command iocb data structure.
  9900. * @rspiocb: pointer to lpfc response iocb data structure.
  9901. *
  9902. * This routine is the completion callback function to a Fabric Discover
  9903. * (FDISC) ELS command. Since all the FDISC ELS commands are issued
  9904. * single threaded, each FDISC completion callback function will reset
  9905. * the discovery timer for all vports such that the timers will not get
  9906. * unnecessary timeout. The function checks the FDISC IOCB status. If error
  9907. * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
  9908. * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
  9909. * assigned to the vport has been changed with the completion of the FDISC
  9910. * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
  9911. * are unregistered from the HBA, and then the lpfc_register_new_vport()
  9912. * routine is invoked to register new vport with the HBA. Otherwise, the
  9913. * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
  9914. * Server for State Change Request (SCR).
  9915. **/
  9916. static void
  9917. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  9918. struct lpfc_iocbq *rspiocb)
  9919. {
  9920. struct lpfc_vport *vport = cmdiocb->vport;
  9921. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  9922. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  9923. struct lpfc_nodelist *np;
  9924. struct lpfc_nodelist *next_np;
  9925. struct lpfc_iocbq *piocb;
  9926. struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf, *prsp;
  9927. struct serv_parm *sp;
  9928. uint8_t fabric_param_changed;
  9929. u32 ulp_status, ulp_word4;
  9930. ulp_status = get_job_ulpstatus(phba, rspiocb);
  9931. ulp_word4 = get_job_word4(phba, rspiocb);
  9932. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  9933. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  9934. ulp_status, ulp_word4,
  9935. vport->fc_prevDID);
  9936. /* Since all FDISCs are being single threaded, we
  9937. * must reset the discovery timer for ALL vports
  9938. * waiting to send FDISC when one completes.
  9939. */
  9940. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  9941. lpfc_set_disctmo(piocb->vport);
  9942. }
  9943. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  9944. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  9945. ulp_status, ulp_word4, vport->fc_prevDID);
  9946. if (ulp_status) {
  9947. if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
  9948. lpfc_retry_pport_discovery(phba);
  9949. goto out;
  9950. }
  9951. /* Check for retry */
  9952. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  9953. goto out;
  9954. /* FDISC failed */
  9955. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  9956. "0126 FDISC failed. (x%x/x%x)\n",
  9957. ulp_status, ulp_word4);
  9958. goto fdisc_failed;
  9959. }
  9960. lpfc_check_nlp_post_devloss(vport, ndlp);
  9961. spin_lock_irq(shost->host_lock);
  9962. vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
  9963. vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
  9964. vport->fc_flag |= FC_FABRIC;
  9965. if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
  9966. vport->fc_flag |= FC_PUBLIC_LOOP;
  9967. spin_unlock_irq(shost->host_lock);
  9968. vport->fc_myDID = ulp_word4 & Mask_DID;
  9969. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  9970. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  9971. if (!prsp)
  9972. goto out;
  9973. sp = prsp->virt + sizeof(uint32_t);
  9974. fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
  9975. memcpy(&vport->fabric_portname, &sp->portName,
  9976. sizeof(struct lpfc_name));
  9977. memcpy(&vport->fabric_nodename, &sp->nodeName,
  9978. sizeof(struct lpfc_name));
  9979. if (fabric_param_changed &&
  9980. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  9981. /* If our NportID changed, we need to ensure all
  9982. * remaining NPORTs get unreg_login'ed so we can
  9983. * issue unreg_vpi.
  9984. */
  9985. list_for_each_entry_safe(np, next_np,
  9986. &vport->fc_nodes, nlp_listp) {
  9987. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  9988. !(np->nlp_flag & NLP_NPR_ADISC))
  9989. continue;
  9990. spin_lock_irq(&ndlp->lock);
  9991. np->nlp_flag &= ~NLP_NPR_ADISC;
  9992. spin_unlock_irq(&ndlp->lock);
  9993. lpfc_unreg_rpi(vport, np);
  9994. }
  9995. lpfc_cleanup_pending_mbox(vport);
  9996. if (phba->sli_rev == LPFC_SLI_REV4)
  9997. lpfc_sli4_unreg_all_rpis(vport);
  9998. lpfc_mbx_unreg_vpi(vport);
  9999. spin_lock_irq(shost->host_lock);
  10000. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  10001. if (phba->sli_rev == LPFC_SLI_REV4)
  10002. vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  10003. else
  10004. vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
  10005. spin_unlock_irq(shost->host_lock);
  10006. } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
  10007. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  10008. /*
  10009. * Driver needs to re-reg VPI in order for f/w
  10010. * to update the MAC address.
  10011. */
  10012. lpfc_register_new_vport(phba, vport, ndlp);
  10013. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  10014. goto out;
  10015. }
  10016. if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
  10017. lpfc_issue_init_vpi(vport);
  10018. else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  10019. lpfc_register_new_vport(phba, vport, ndlp);
  10020. else
  10021. lpfc_do_scr_ns_plogi(phba, vport);
  10022. /* The FDISC completed successfully. Move the fabric ndlp to
  10023. * UNMAPPED state and register with the transport.
  10024. */
  10025. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  10026. goto out;
  10027. fdisc_failed:
  10028. if (vport->fc_vport &&
  10029. (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
  10030. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  10031. /* Cancel discovery timer */
  10032. lpfc_can_disctmo(vport);
  10033. out:
  10034. lpfc_els_free_iocb(phba, cmdiocb);
  10035. lpfc_nlp_put(ndlp);
  10036. }
  10037. /**
  10038. * lpfc_issue_els_fdisc - Issue a fdisc iocb command
  10039. * @vport: pointer to a virtual N_Port data structure.
  10040. * @ndlp: pointer to a node-list data structure.
  10041. * @retry: number of retries to the command IOCB.
  10042. *
  10043. * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
  10044. * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
  10045. * routine to issue the IOCB, which makes sure only one outstanding fabric
  10046. * IOCB will be sent off HBA at any given time.
  10047. *
  10048. * Note that the ndlp reference count will be incremented by 1 for holding the
  10049. * ndlp and the reference to ndlp will be stored into the ndlp field of
  10050. * the IOCB for the completion callback function to the FDISC ELS command.
  10051. *
  10052. * Return code
  10053. * 0 - Successfully issued fdisc iocb command
  10054. * 1 - Failed to issue fdisc iocb command
  10055. **/
  10056. static int
  10057. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  10058. uint8_t retry)
  10059. {
  10060. struct lpfc_hba *phba = vport->phba;
  10061. IOCB_t *icmd;
  10062. union lpfc_wqe128 *wqe = NULL;
  10063. struct lpfc_iocbq *elsiocb;
  10064. struct serv_parm *sp;
  10065. uint8_t *pcmd;
  10066. uint16_t cmdsize;
  10067. int did = ndlp->nlp_DID;
  10068. int rc;
  10069. vport->port_state = LPFC_FDISC;
  10070. vport->fc_myDID = 0;
  10071. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  10072. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  10073. ELS_CMD_FDISC);
  10074. if (!elsiocb) {
  10075. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  10076. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  10077. "0255 Issue FDISC: no IOCB\n");
  10078. return 1;
  10079. }
  10080. if (phba->sli_rev == LPFC_SLI_REV4) {
  10081. wqe = &elsiocb->wqe;
  10082. bf_set(els_req64_sid, &wqe->els_req, 0);
  10083. bf_set(els_req64_sp, &wqe->els_req, 1);
  10084. } else {
  10085. icmd = &elsiocb->iocb;
  10086. icmd->un.elsreq64.myID = 0;
  10087. icmd->un.elsreq64.fl = 1;
  10088. icmd->ulpCt_h = 1;
  10089. icmd->ulpCt_l = 0;
  10090. }
  10091. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  10092. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  10093. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  10094. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  10095. sp = (struct serv_parm *) pcmd;
  10096. /* Setup CSPs accordingly for Fabric */
  10097. sp->cmn.e_d_tov = 0;
  10098. sp->cmn.w2.r_a_tov = 0;
  10099. sp->cmn.virtual_fabric_support = 0;
  10100. sp->cls1.classValid = 0;
  10101. sp->cls2.seqDelivery = 1;
  10102. sp->cls3.seqDelivery = 1;
  10103. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  10104. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  10105. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  10106. pcmd += sizeof(uint32_t); /* Port Name */
  10107. memcpy(pcmd, &vport->fc_portname, 8);
  10108. pcmd += sizeof(uint32_t); /* Node Name */
  10109. pcmd += sizeof(uint32_t); /* Node Name */
  10110. memcpy(pcmd, &vport->fc_nodename, 8);
  10111. sp->cmn.valid_vendor_ver_level = 0;
  10112. memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
  10113. lpfc_set_disctmo(vport);
  10114. phba->fc_stat.elsXmitFDISC++;
  10115. elsiocb->cmd_cmpl = lpfc_cmpl_els_fdisc;
  10116. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  10117. "Issue FDISC: did:x%x",
  10118. did, 0, 0);
  10119. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  10120. if (!elsiocb->ndlp)
  10121. goto err_out;
  10122. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  10123. if (rc == IOCB_ERROR) {
  10124. lpfc_nlp_put(ndlp);
  10125. goto err_out;
  10126. }
  10127. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  10128. return 0;
  10129. err_out:
  10130. lpfc_els_free_iocb(phba, elsiocb);
  10131. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  10132. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  10133. "0256 Issue FDISC: Cannot send IOCB\n");
  10134. return 1;
  10135. }
  10136. /**
  10137. * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
  10138. * @phba: pointer to lpfc hba data structure.
  10139. * @cmdiocb: pointer to lpfc command iocb data structure.
  10140. * @rspiocb: pointer to lpfc response iocb data structure.
  10141. *
  10142. * This routine is the completion callback function to the issuing of a LOGO
  10143. * ELS command off a vport. It frees the command IOCB and then decrement the
  10144. * reference count held on ndlp for this completion function, indicating that
  10145. * the reference to the ndlp is no long needed. Note that the
  10146. * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
  10147. * callback function and an additional explicit ndlp reference decrementation
  10148. * will trigger the actual release of the ndlp.
  10149. **/
  10150. static void
  10151. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  10152. struct lpfc_iocbq *rspiocb)
  10153. {
  10154. struct lpfc_vport *vport = cmdiocb->vport;
  10155. IOCB_t *irsp;
  10156. struct lpfc_nodelist *ndlp;
  10157. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  10158. u32 ulp_status, ulp_word4, did, tmo;
  10159. ndlp = cmdiocb->ndlp;
  10160. ulp_status = get_job_ulpstatus(phba, rspiocb);
  10161. ulp_word4 = get_job_word4(phba, rspiocb);
  10162. if (phba->sli_rev == LPFC_SLI_REV4) {
  10163. did = get_job_els_rsp64_did(phba, cmdiocb);
  10164. tmo = get_wqe_tmo(cmdiocb);
  10165. } else {
  10166. irsp = &rspiocb->iocb;
  10167. did = get_job_els_rsp64_did(phba, rspiocb);
  10168. tmo = irsp->ulpTimeout;
  10169. }
  10170. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  10171. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  10172. ulp_status, ulp_word4, did);
  10173. /* NPIV LOGO completes to NPort <nlp_DID> */
  10174. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  10175. "2928 NPIV LOGO completes to NPort x%x "
  10176. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  10177. ndlp->nlp_DID, ulp_status, ulp_word4,
  10178. tmo, vport->num_disc_nodes,
  10179. kref_read(&ndlp->kref), ndlp->nlp_flag,
  10180. ndlp->fc4_xpt_flags);
  10181. if (ulp_status == IOSTAT_SUCCESS) {
  10182. spin_lock_irq(shost->host_lock);
  10183. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  10184. vport->fc_flag &= ~FC_FABRIC;
  10185. spin_unlock_irq(shost->host_lock);
  10186. lpfc_can_disctmo(vport);
  10187. }
  10188. if (ndlp->save_flags & NLP_WAIT_FOR_LOGO) {
  10189. /* Wake up lpfc_vport_delete if waiting...*/
  10190. if (ndlp->logo_waitq)
  10191. wake_up(ndlp->logo_waitq);
  10192. spin_lock_irq(&ndlp->lock);
  10193. ndlp->nlp_flag &= ~(NLP_ISSUE_LOGO | NLP_LOGO_SND);
  10194. ndlp->save_flags &= ~NLP_WAIT_FOR_LOGO;
  10195. spin_unlock_irq(&ndlp->lock);
  10196. }
  10197. /* Safe to release resources now. */
  10198. lpfc_els_free_iocb(phba, cmdiocb);
  10199. lpfc_nlp_put(ndlp);
  10200. }
  10201. /**
  10202. * lpfc_issue_els_npiv_logo - Issue a logo off a vport
  10203. * @vport: pointer to a virtual N_Port data structure.
  10204. * @ndlp: pointer to a node-list data structure.
  10205. *
  10206. * This routine issues a LOGO ELS command to an @ndlp off a @vport.
  10207. *
  10208. * Note that the ndlp reference count will be incremented by 1 for holding the
  10209. * ndlp and the reference to ndlp will be stored into the ndlp field of
  10210. * the IOCB for the completion callback function to the LOGO ELS command.
  10211. *
  10212. * Return codes
  10213. * 0 - Successfully issued logo off the @vport
  10214. * 1 - Failed to issue logo off the @vport
  10215. **/
  10216. int
  10217. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  10218. {
  10219. int rc = 0;
  10220. struct lpfc_hba *phba = vport->phba;
  10221. struct lpfc_iocbq *elsiocb;
  10222. uint8_t *pcmd;
  10223. uint16_t cmdsize;
  10224. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  10225. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  10226. ELS_CMD_LOGO);
  10227. if (!elsiocb)
  10228. return 1;
  10229. pcmd = (uint8_t *)elsiocb->cmd_dmabuf->virt;
  10230. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  10231. pcmd += sizeof(uint32_t);
  10232. /* Fill in LOGO payload */
  10233. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  10234. pcmd += sizeof(uint32_t);
  10235. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  10236. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  10237. "Issue LOGO npiv did:x%x flg:x%x",
  10238. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  10239. elsiocb->cmd_cmpl = lpfc_cmpl_els_npiv_logo;
  10240. spin_lock_irq(&ndlp->lock);
  10241. ndlp->nlp_flag |= NLP_LOGO_SND;
  10242. spin_unlock_irq(&ndlp->lock);
  10243. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  10244. if (!elsiocb->ndlp) {
  10245. lpfc_els_free_iocb(phba, elsiocb);
  10246. goto err;
  10247. }
  10248. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
  10249. if (rc == IOCB_ERROR) {
  10250. lpfc_els_free_iocb(phba, elsiocb);
  10251. lpfc_nlp_put(ndlp);
  10252. goto err;
  10253. }
  10254. return 0;
  10255. err:
  10256. spin_lock_irq(&ndlp->lock);
  10257. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  10258. spin_unlock_irq(&ndlp->lock);
  10259. return 1;
  10260. }
  10261. /**
  10262. * lpfc_fabric_block_timeout - Handler function to the fabric block timer
  10263. * @t: timer context used to obtain the lpfc hba.
  10264. *
  10265. * This routine is invoked by the fabric iocb block timer after
  10266. * timeout. It posts the fabric iocb block timeout event by setting the
  10267. * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
  10268. * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
  10269. * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
  10270. * posted event WORKER_FABRIC_BLOCK_TMO.
  10271. **/
  10272. void
  10273. lpfc_fabric_block_timeout(struct timer_list *t)
  10274. {
  10275. struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
  10276. unsigned long iflags;
  10277. uint32_t tmo_posted;
  10278. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  10279. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  10280. if (!tmo_posted)
  10281. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  10282. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  10283. if (!tmo_posted)
  10284. lpfc_worker_wake_up(phba);
  10285. return;
  10286. }
  10287. /**
  10288. * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
  10289. * @phba: pointer to lpfc hba data structure.
  10290. *
  10291. * This routine issues one fabric iocb from the driver internal list to
  10292. * the HBA. It first checks whether it's ready to issue one fabric iocb to
  10293. * the HBA (whether there is no outstanding fabric iocb). If so, it shall
  10294. * remove one pending fabric iocb from the driver internal list and invokes
  10295. * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
  10296. **/
  10297. static void
  10298. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  10299. {
  10300. struct lpfc_iocbq *iocb;
  10301. unsigned long iflags;
  10302. int ret;
  10303. repeat:
  10304. iocb = NULL;
  10305. spin_lock_irqsave(&phba->hbalock, iflags);
  10306. /* Post any pending iocb to the SLI layer */
  10307. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  10308. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  10309. list);
  10310. if (iocb)
  10311. /* Increment fabric iocb count to hold the position */
  10312. atomic_inc(&phba->fabric_iocb_count);
  10313. }
  10314. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10315. if (iocb) {
  10316. iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
  10317. iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
  10318. iocb->cmd_flag |= LPFC_IO_FABRIC;
  10319. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  10320. "Fabric sched1: ste:x%x",
  10321. iocb->vport->port_state, 0, 0);
  10322. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  10323. if (ret == IOCB_ERROR) {
  10324. iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
  10325. iocb->fabric_cmd_cmpl = NULL;
  10326. iocb->cmd_flag &= ~LPFC_IO_FABRIC;
  10327. set_job_ulpstatus(iocb, IOSTAT_LOCAL_REJECT);
  10328. iocb->wcqe_cmpl.parameter = IOERR_SLI_ABORTED;
  10329. iocb->cmd_cmpl(phba, iocb, iocb);
  10330. atomic_dec(&phba->fabric_iocb_count);
  10331. goto repeat;
  10332. }
  10333. }
  10334. }
  10335. /**
  10336. * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
  10337. * @phba: pointer to lpfc hba data structure.
  10338. *
  10339. * This routine unblocks the issuing fabric iocb command. The function
  10340. * will clear the fabric iocb block bit and then invoke the routine
  10341. * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
  10342. * from the driver internal fabric iocb list.
  10343. **/
  10344. void
  10345. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  10346. {
  10347. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  10348. lpfc_resume_fabric_iocbs(phba);
  10349. return;
  10350. }
  10351. /**
  10352. * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
  10353. * @phba: pointer to lpfc hba data structure.
  10354. *
  10355. * This routine blocks the issuing fabric iocb for a specified amount of
  10356. * time (currently 100 ms). This is done by set the fabric iocb block bit
  10357. * and set up a timeout timer for 100ms. When the block bit is set, no more
  10358. * fabric iocb will be issued out of the HBA.
  10359. **/
  10360. static void
  10361. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  10362. {
  10363. int blocked;
  10364. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  10365. /* Start a timer to unblock fabric iocbs after 100ms */
  10366. if (!blocked)
  10367. mod_timer(&phba->fabric_block_timer,
  10368. jiffies + msecs_to_jiffies(100));
  10369. return;
  10370. }
  10371. /**
  10372. * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
  10373. * @phba: pointer to lpfc hba data structure.
  10374. * @cmdiocb: pointer to lpfc command iocb data structure.
  10375. * @rspiocb: pointer to lpfc response iocb data structure.
  10376. *
  10377. * This routine is the callback function that is put to the fabric iocb's
  10378. * callback function pointer (iocb->cmd_cmpl). The original iocb's callback
  10379. * function pointer has been stored in iocb->fabric_cmd_cmpl. This callback
  10380. * function first restores and invokes the original iocb's callback function
  10381. * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
  10382. * fabric bound iocb from the driver internal fabric iocb list onto the wire.
  10383. **/
  10384. static void
  10385. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  10386. struct lpfc_iocbq *rspiocb)
  10387. {
  10388. struct ls_rjt stat;
  10389. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  10390. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  10391. WARN_ON((cmdiocb->cmd_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
  10392. switch (ulp_status) {
  10393. case IOSTAT_NPORT_RJT:
  10394. case IOSTAT_FABRIC_RJT:
  10395. if (ulp_word4 & RJT_UNAVAIL_TEMP)
  10396. lpfc_block_fabric_iocbs(phba);
  10397. break;
  10398. case IOSTAT_NPORT_BSY:
  10399. case IOSTAT_FABRIC_BSY:
  10400. lpfc_block_fabric_iocbs(phba);
  10401. break;
  10402. case IOSTAT_LS_RJT:
  10403. stat.un.ls_rjt_error_be =
  10404. cpu_to_be32(ulp_word4);
  10405. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  10406. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  10407. lpfc_block_fabric_iocbs(phba);
  10408. break;
  10409. }
  10410. BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
  10411. cmdiocb->cmd_cmpl = cmdiocb->fabric_cmd_cmpl;
  10412. cmdiocb->fabric_cmd_cmpl = NULL;
  10413. cmdiocb->cmd_flag &= ~LPFC_IO_FABRIC;
  10414. cmdiocb->cmd_cmpl(phba, cmdiocb, rspiocb);
  10415. atomic_dec(&phba->fabric_iocb_count);
  10416. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  10417. /* Post any pending iocbs to HBA */
  10418. lpfc_resume_fabric_iocbs(phba);
  10419. }
  10420. }
  10421. /**
  10422. * lpfc_issue_fabric_iocb - Issue a fabric iocb command
  10423. * @phba: pointer to lpfc hba data structure.
  10424. * @iocb: pointer to lpfc command iocb data structure.
  10425. *
  10426. * This routine is used as the top-level API for issuing a fabric iocb command
  10427. * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
  10428. * function makes sure that only one fabric bound iocb will be outstanding at
  10429. * any given time. As such, this function will first check to see whether there
  10430. * is already an outstanding fabric iocb on the wire. If so, it will put the
  10431. * newly issued iocb onto the driver internal fabric iocb list, waiting to be
  10432. * issued later. Otherwise, it will issue the iocb on the wire and update the
  10433. * fabric iocb count it indicate that there is one fabric iocb on the wire.
  10434. *
  10435. * Note, this implementation has a potential sending out fabric IOCBs out of
  10436. * order. The problem is caused by the construction of the "ready" boolen does
  10437. * not include the condition that the internal fabric IOCB list is empty. As
  10438. * such, it is possible a fabric IOCB issued by this routine might be "jump"
  10439. * ahead of the fabric IOCBs in the internal list.
  10440. *
  10441. * Return code
  10442. * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
  10443. * IOCB_ERROR - failed to issue fabric iocb
  10444. **/
  10445. static int
  10446. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  10447. {
  10448. unsigned long iflags;
  10449. int ready;
  10450. int ret;
  10451. BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
  10452. spin_lock_irqsave(&phba->hbalock, iflags);
  10453. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  10454. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  10455. if (ready)
  10456. /* Increment fabric iocb count to hold the position */
  10457. atomic_inc(&phba->fabric_iocb_count);
  10458. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10459. if (ready) {
  10460. iocb->fabric_cmd_cmpl = iocb->cmd_cmpl;
  10461. iocb->cmd_cmpl = lpfc_cmpl_fabric_iocb;
  10462. iocb->cmd_flag |= LPFC_IO_FABRIC;
  10463. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  10464. "Fabric sched2: ste:x%x",
  10465. iocb->vport->port_state, 0, 0);
  10466. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
  10467. if (ret == IOCB_ERROR) {
  10468. iocb->cmd_cmpl = iocb->fabric_cmd_cmpl;
  10469. iocb->fabric_cmd_cmpl = NULL;
  10470. iocb->cmd_flag &= ~LPFC_IO_FABRIC;
  10471. atomic_dec(&phba->fabric_iocb_count);
  10472. }
  10473. } else {
  10474. spin_lock_irqsave(&phba->hbalock, iflags);
  10475. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  10476. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10477. ret = IOCB_SUCCESS;
  10478. }
  10479. return ret;
  10480. }
  10481. /**
  10482. * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
  10483. * @vport: pointer to a virtual N_Port data structure.
  10484. *
  10485. * This routine aborts all the IOCBs associated with a @vport from the
  10486. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  10487. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  10488. * list, removes each IOCB associated with the @vport off the list, set the
  10489. * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
  10490. * associated with the IOCB.
  10491. **/
  10492. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  10493. {
  10494. LIST_HEAD(completions);
  10495. struct lpfc_hba *phba = vport->phba;
  10496. struct lpfc_iocbq *tmp_iocb, *piocb;
  10497. spin_lock_irq(&phba->hbalock);
  10498. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  10499. list) {
  10500. if (piocb->vport != vport)
  10501. continue;
  10502. list_move_tail(&piocb->list, &completions);
  10503. }
  10504. spin_unlock_irq(&phba->hbalock);
  10505. /* Cancel all the IOCBs from the completions list */
  10506. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  10507. IOERR_SLI_ABORTED);
  10508. }
  10509. /**
  10510. * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
  10511. * @ndlp: pointer to a node-list data structure.
  10512. *
  10513. * This routine aborts all the IOCBs associated with an @ndlp from the
  10514. * driver internal fabric IOCB list. The list contains fabric IOCBs to be
  10515. * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
  10516. * list, removes each IOCB associated with the @ndlp off the list, set the
  10517. * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
  10518. * associated with the IOCB.
  10519. **/
  10520. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  10521. {
  10522. LIST_HEAD(completions);
  10523. struct lpfc_hba *phba = ndlp->phba;
  10524. struct lpfc_iocbq *tmp_iocb, *piocb;
  10525. struct lpfc_sli_ring *pring;
  10526. pring = lpfc_phba_elsring(phba);
  10527. if (unlikely(!pring))
  10528. return;
  10529. spin_lock_irq(&phba->hbalock);
  10530. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  10531. list) {
  10532. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  10533. list_move_tail(&piocb->list, &completions);
  10534. }
  10535. }
  10536. spin_unlock_irq(&phba->hbalock);
  10537. /* Cancel all the IOCBs from the completions list */
  10538. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  10539. IOERR_SLI_ABORTED);
  10540. }
  10541. /**
  10542. * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
  10543. * @phba: pointer to lpfc hba data structure.
  10544. *
  10545. * This routine aborts all the IOCBs currently on the driver internal
  10546. * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
  10547. * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
  10548. * list, removes IOCBs off the list, set the status field to
  10549. * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
  10550. * the IOCB.
  10551. **/
  10552. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  10553. {
  10554. LIST_HEAD(completions);
  10555. spin_lock_irq(&phba->hbalock);
  10556. list_splice_init(&phba->fabric_iocb_list, &completions);
  10557. spin_unlock_irq(&phba->hbalock);
  10558. /* Cancel all the IOCBs from the completions list */
  10559. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  10560. IOERR_SLI_ABORTED);
  10561. }
  10562. /**
  10563. * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
  10564. * @vport: pointer to lpfc vport data structure.
  10565. *
  10566. * This routine is invoked by the vport cleanup for deletions and the cleanup
  10567. * for an ndlp on removal.
  10568. **/
  10569. void
  10570. lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
  10571. {
  10572. struct lpfc_hba *phba = vport->phba;
  10573. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  10574. struct lpfc_nodelist *ndlp = NULL;
  10575. unsigned long iflag = 0;
  10576. spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
  10577. list_for_each_entry_safe(sglq_entry, sglq_next,
  10578. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  10579. if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport) {
  10580. lpfc_nlp_put(sglq_entry->ndlp);
  10581. ndlp = sglq_entry->ndlp;
  10582. sglq_entry->ndlp = NULL;
  10583. /* If the xri on the abts_els_sgl list is for the Fport
  10584. * node and the vport is unloading, the xri aborted wcqe
  10585. * likely isn't coming back. Just release the sgl.
  10586. */
  10587. if ((vport->load_flag & FC_UNLOADING) &&
  10588. ndlp->nlp_DID == Fabric_DID) {
  10589. list_del(&sglq_entry->list);
  10590. sglq_entry->state = SGL_FREED;
  10591. list_add_tail(&sglq_entry->list,
  10592. &phba->sli4_hba.lpfc_els_sgl_list);
  10593. }
  10594. }
  10595. }
  10596. spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
  10597. return;
  10598. }
  10599. /**
  10600. * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
  10601. * @phba: pointer to lpfc hba data structure.
  10602. * @axri: pointer to the els xri abort wcqe structure.
  10603. *
  10604. * This routine is invoked by the worker thread to process a SLI4 slow-path
  10605. * ELS aborted xri.
  10606. **/
  10607. void
  10608. lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
  10609. struct sli4_wcqe_xri_aborted *axri)
  10610. {
  10611. uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
  10612. uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
  10613. uint16_t lxri = 0;
  10614. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  10615. unsigned long iflag = 0;
  10616. struct lpfc_nodelist *ndlp;
  10617. struct lpfc_sli_ring *pring;
  10618. pring = lpfc_phba_elsring(phba);
  10619. spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock, iflag);
  10620. list_for_each_entry_safe(sglq_entry, sglq_next,
  10621. &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
  10622. if (sglq_entry->sli4_xritag == xri) {
  10623. list_del(&sglq_entry->list);
  10624. ndlp = sglq_entry->ndlp;
  10625. sglq_entry->ndlp = NULL;
  10626. list_add_tail(&sglq_entry->list,
  10627. &phba->sli4_hba.lpfc_els_sgl_list);
  10628. sglq_entry->state = SGL_FREED;
  10629. spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock,
  10630. iflag);
  10631. if (ndlp) {
  10632. lpfc_set_rrq_active(phba, ndlp,
  10633. sglq_entry->sli4_lxritag,
  10634. rxid, 1);
  10635. lpfc_nlp_put(ndlp);
  10636. }
  10637. /* Check if TXQ queue needs to be serviced */
  10638. if (pring && !list_empty(&pring->txq))
  10639. lpfc_worker_wake_up(phba);
  10640. return;
  10641. }
  10642. }
  10643. spin_unlock_irqrestore(&phba->sli4_hba.sgl_list_lock, iflag);
  10644. lxri = lpfc_sli4_xri_inrange(phba, xri);
  10645. if (lxri == NO_XRI)
  10646. return;
  10647. spin_lock_irqsave(&phba->hbalock, iflag);
  10648. sglq_entry = __lpfc_get_active_sglq(phba, lxri);
  10649. if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
  10650. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10651. return;
  10652. }
  10653. sglq_entry->state = SGL_XRI_ABORTED;
  10654. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10655. return;
  10656. }
  10657. /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
  10658. * @vport: pointer to virtual port object.
  10659. * @ndlp: nodelist pointer for the impacted node.
  10660. *
  10661. * The driver calls this routine in response to an SLI4 XRI ABORT CQE
  10662. * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
  10663. * the driver is required to send a LOGO to the remote node before it
  10664. * attempts to recover its login to the remote node.
  10665. */
  10666. void
  10667. lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
  10668. struct lpfc_nodelist *ndlp)
  10669. {
  10670. struct Scsi_Host *shost;
  10671. struct lpfc_hba *phba;
  10672. unsigned long flags = 0;
  10673. shost = lpfc_shost_from_vport(vport);
  10674. phba = vport->phba;
  10675. if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
  10676. lpfc_printf_log(phba, KERN_INFO,
  10677. LOG_SLI, "3093 No rport recovery needed. "
  10678. "rport in state 0x%x\n", ndlp->nlp_state);
  10679. return;
  10680. }
  10681. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10682. "3094 Start rport recovery on shost id 0x%x "
  10683. "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
  10684. "flags 0x%x\n",
  10685. shost->host_no, ndlp->nlp_DID,
  10686. vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
  10687. ndlp->nlp_flag);
  10688. /*
  10689. * The rport is not responding. Remove the FCP-2 flag to prevent
  10690. * an ADISC in the follow-up recovery code.
  10691. */
  10692. spin_lock_irqsave(&ndlp->lock, flags);
  10693. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  10694. ndlp->nlp_flag |= NLP_ISSUE_LOGO;
  10695. spin_unlock_irqrestore(&ndlp->lock, flags);
  10696. lpfc_unreg_rpi(vport, ndlp);
  10697. }
  10698. static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport *vport)
  10699. {
  10700. bitmap_zero(vport->vmid_priority_range, LPFC_VMID_MAX_PRIORITY_RANGE);
  10701. }
  10702. static void
  10703. lpfc_vmid_set_cs_ctl_range(struct lpfc_vport *vport, u32 min, u32 max)
  10704. {
  10705. u32 i;
  10706. if ((min > max) || (max > LPFC_VMID_MAX_PRIORITY_RANGE))
  10707. return;
  10708. for (i = min; i <= max; i++)
  10709. set_bit(i, vport->vmid_priority_range);
  10710. }
  10711. static void lpfc_vmid_put_cs_ctl(struct lpfc_vport *vport, u32 ctcl_vmid)
  10712. {
  10713. set_bit(ctcl_vmid, vport->vmid_priority_range);
  10714. }
  10715. u32 lpfc_vmid_get_cs_ctl(struct lpfc_vport *vport)
  10716. {
  10717. u32 i;
  10718. i = find_first_bit(vport->vmid_priority_range,
  10719. LPFC_VMID_MAX_PRIORITY_RANGE);
  10720. if (i == LPFC_VMID_MAX_PRIORITY_RANGE)
  10721. return 0;
  10722. clear_bit(i, vport->vmid_priority_range);
  10723. return i;
  10724. }
  10725. #define MAX_PRIORITY_DESC 255
  10726. static void
  10727. lpfc_cmpl_els_qfpa(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  10728. struct lpfc_iocbq *rspiocb)
  10729. {
  10730. struct lpfc_vport *vport = cmdiocb->vport;
  10731. struct priority_range_desc *desc;
  10732. struct lpfc_dmabuf *prsp = NULL;
  10733. struct lpfc_vmid_priority_range *vmid_range = NULL;
  10734. u32 *data;
  10735. struct lpfc_dmabuf *dmabuf = cmdiocb->cmd_dmabuf;
  10736. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  10737. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  10738. u8 *pcmd, max_desc;
  10739. u32 len, i;
  10740. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  10741. prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
  10742. if (!prsp)
  10743. goto out;
  10744. pcmd = prsp->virt;
  10745. data = (u32 *)pcmd;
  10746. if (data[0] == ELS_CMD_LS_RJT) {
  10747. lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
  10748. "3277 QFPA LS_RJT x%x x%x\n",
  10749. data[0], data[1]);
  10750. goto out;
  10751. }
  10752. if (ulp_status) {
  10753. lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
  10754. "6529 QFPA failed with status x%x x%x\n",
  10755. ulp_status, ulp_word4);
  10756. goto out;
  10757. }
  10758. if (!vport->qfpa_res) {
  10759. max_desc = FCELSSIZE / sizeof(*vport->qfpa_res);
  10760. vport->qfpa_res = kcalloc(max_desc, sizeof(*vport->qfpa_res),
  10761. GFP_KERNEL);
  10762. if (!vport->qfpa_res)
  10763. goto out;
  10764. }
  10765. len = *((u32 *)(pcmd + 4));
  10766. len = be32_to_cpu(len);
  10767. memcpy(vport->qfpa_res, pcmd, len + 8);
  10768. len = len / LPFC_PRIORITY_RANGE_DESC_SIZE;
  10769. desc = (struct priority_range_desc *)(pcmd + 8);
  10770. vmid_range = vport->vmid_priority.vmid_range;
  10771. if (!vmid_range) {
  10772. vmid_range = kcalloc(MAX_PRIORITY_DESC, sizeof(*vmid_range),
  10773. GFP_KERNEL);
  10774. if (!vmid_range) {
  10775. kfree(vport->qfpa_res);
  10776. goto out;
  10777. }
  10778. vport->vmid_priority.vmid_range = vmid_range;
  10779. }
  10780. vport->vmid_priority.num_descriptors = len;
  10781. for (i = 0; i < len; i++, vmid_range++, desc++) {
  10782. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
  10783. "6539 vmid values low=%d, high=%d, qos=%d, "
  10784. "local ve id=%d\n", desc->lo_range,
  10785. desc->hi_range, desc->qos_priority,
  10786. desc->local_ve_id);
  10787. vmid_range->low = desc->lo_range << 1;
  10788. if (desc->local_ve_id == QFPA_ODD_ONLY)
  10789. vmid_range->low++;
  10790. if (desc->qos_priority)
  10791. vport->vmid_flag |= LPFC_VMID_QOS_ENABLED;
  10792. vmid_range->qos = desc->qos_priority;
  10793. vmid_range->high = desc->hi_range << 1;
  10794. if ((desc->local_ve_id == QFPA_ODD_ONLY) ||
  10795. (desc->local_ve_id == QFPA_EVEN_ODD))
  10796. vmid_range->high++;
  10797. }
  10798. lpfc_init_cs_ctl_bitmap(vport);
  10799. for (i = 0; i < vport->vmid_priority.num_descriptors; i++) {
  10800. lpfc_vmid_set_cs_ctl_range(vport,
  10801. vport->vmid_priority.vmid_range[i].low,
  10802. vport->vmid_priority.vmid_range[i].high);
  10803. }
  10804. vport->vmid_flag |= LPFC_VMID_QFPA_CMPL;
  10805. out:
  10806. lpfc_els_free_iocb(phba, cmdiocb);
  10807. lpfc_nlp_put(ndlp);
  10808. }
  10809. int lpfc_issue_els_qfpa(struct lpfc_vport *vport)
  10810. {
  10811. struct lpfc_hba *phba = vport->phba;
  10812. struct lpfc_nodelist *ndlp;
  10813. struct lpfc_iocbq *elsiocb;
  10814. u8 *pcmd;
  10815. int ret;
  10816. ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
  10817. if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
  10818. return -ENXIO;
  10819. elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_QFPA_SIZE, 2, ndlp,
  10820. ndlp->nlp_DID, ELS_CMD_QFPA);
  10821. if (!elsiocb)
  10822. return -ENOMEM;
  10823. pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
  10824. *((u32 *)(pcmd)) = ELS_CMD_QFPA;
  10825. pcmd += 4;
  10826. elsiocb->cmd_cmpl = lpfc_cmpl_els_qfpa;
  10827. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  10828. if (!elsiocb->ndlp) {
  10829. lpfc_els_free_iocb(vport->phba, elsiocb);
  10830. return -ENXIO;
  10831. }
  10832. ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 2);
  10833. if (ret != IOCB_SUCCESS) {
  10834. lpfc_els_free_iocb(phba, elsiocb);
  10835. lpfc_nlp_put(ndlp);
  10836. return -EIO;
  10837. }
  10838. vport->vmid_flag &= ~LPFC_VMID_QOS_ENABLED;
  10839. return 0;
  10840. }
  10841. int
  10842. lpfc_vmid_uvem(struct lpfc_vport *vport,
  10843. struct lpfc_vmid *vmid, bool instantiated)
  10844. {
  10845. struct lpfc_vem_id_desc *vem_id_desc;
  10846. struct lpfc_nodelist *ndlp;
  10847. struct lpfc_iocbq *elsiocb;
  10848. struct instantiated_ve_desc *inst_desc;
  10849. struct lpfc_vmid_context *vmid_context;
  10850. u8 *pcmd;
  10851. u32 *len;
  10852. int ret = 0;
  10853. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  10854. if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
  10855. return -ENXIO;
  10856. vmid_context = kmalloc(sizeof(*vmid_context), GFP_KERNEL);
  10857. if (!vmid_context)
  10858. return -ENOMEM;
  10859. elsiocb = lpfc_prep_els_iocb(vport, 1, LPFC_UVEM_SIZE, 2,
  10860. ndlp, Fabric_DID, ELS_CMD_UVEM);
  10861. if (!elsiocb)
  10862. goto out;
  10863. lpfc_printf_vlog(vport, KERN_DEBUG, LOG_ELS,
  10864. "3427 Host vmid %s %d\n",
  10865. vmid->host_vmid, instantiated);
  10866. vmid_context->vmp = vmid;
  10867. vmid_context->nlp = ndlp;
  10868. vmid_context->instantiated = instantiated;
  10869. elsiocb->vmid_tag.vmid_context = vmid_context;
  10870. pcmd = (u8 *)elsiocb->cmd_dmabuf->virt;
  10871. if (uuid_is_null((uuid_t *)vport->lpfc_vmid_host_uuid))
  10872. memcpy(vport->lpfc_vmid_host_uuid, vmid->host_vmid,
  10873. LPFC_COMPRESS_VMID_SIZE);
  10874. *((u32 *)(pcmd)) = ELS_CMD_UVEM;
  10875. len = (u32 *)(pcmd + 4);
  10876. *len = cpu_to_be32(LPFC_UVEM_SIZE - 8);
  10877. vem_id_desc = (struct lpfc_vem_id_desc *)(pcmd + 8);
  10878. vem_id_desc->tag = be32_to_cpu(VEM_ID_DESC_TAG);
  10879. vem_id_desc->length = be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE);
  10880. memcpy(vem_id_desc->vem_id, vport->lpfc_vmid_host_uuid,
  10881. LPFC_COMPRESS_VMID_SIZE);
  10882. inst_desc = (struct instantiated_ve_desc *)(pcmd + 32);
  10883. inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
  10884. inst_desc->length = be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE);
  10885. memcpy(inst_desc->global_vem_id, vmid->host_vmid,
  10886. LPFC_COMPRESS_VMID_SIZE);
  10887. bf_set(lpfc_instantiated_nport_id, inst_desc, vport->fc_myDID);
  10888. bf_set(lpfc_instantiated_local_id, inst_desc,
  10889. vmid->un.cs_ctl_vmid);
  10890. if (instantiated) {
  10891. inst_desc->tag = be32_to_cpu(INSTANTIATED_VE_DESC_TAG);
  10892. } else {
  10893. inst_desc->tag = be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG);
  10894. lpfc_vmid_put_cs_ctl(vport, vmid->un.cs_ctl_vmid);
  10895. }
  10896. inst_desc->word6 = cpu_to_be32(inst_desc->word6);
  10897. elsiocb->cmd_cmpl = lpfc_cmpl_els_uvem;
  10898. elsiocb->ndlp = lpfc_nlp_get(ndlp);
  10899. if (!elsiocb->ndlp) {
  10900. lpfc_els_free_iocb(vport->phba, elsiocb);
  10901. goto out;
  10902. }
  10903. ret = lpfc_sli_issue_iocb(vport->phba, LPFC_ELS_RING, elsiocb, 0);
  10904. if (ret != IOCB_SUCCESS) {
  10905. lpfc_els_free_iocb(vport->phba, elsiocb);
  10906. lpfc_nlp_put(ndlp);
  10907. goto out;
  10908. }
  10909. return 0;
  10910. out:
  10911. kfree(vmid_context);
  10912. return -EIO;
  10913. }
  10914. static void
  10915. lpfc_cmpl_els_uvem(struct lpfc_hba *phba, struct lpfc_iocbq *icmdiocb,
  10916. struct lpfc_iocbq *rspiocb)
  10917. {
  10918. struct lpfc_vport *vport = icmdiocb->vport;
  10919. struct lpfc_dmabuf *prsp = NULL;
  10920. struct lpfc_vmid_context *vmid_context =
  10921. icmdiocb->vmid_tag.vmid_context;
  10922. struct lpfc_nodelist *ndlp = icmdiocb->ndlp;
  10923. u8 *pcmd;
  10924. u32 *data;
  10925. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  10926. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  10927. struct lpfc_dmabuf *dmabuf = icmdiocb->cmd_dmabuf;
  10928. struct lpfc_vmid *vmid;
  10929. vmid = vmid_context->vmp;
  10930. if (!ndlp || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
  10931. ndlp = NULL;
  10932. prsp = list_get_first(&dmabuf->list, struct lpfc_dmabuf, list);
  10933. if (!prsp)
  10934. goto out;
  10935. pcmd = prsp->virt;
  10936. data = (u32 *)pcmd;
  10937. if (data[0] == ELS_CMD_LS_RJT) {
  10938. lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
  10939. "4532 UVEM LS_RJT %x %x\n", data[0], data[1]);
  10940. goto out;
  10941. }
  10942. if (ulp_status) {
  10943. lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
  10944. "4533 UVEM error status %x: %x\n",
  10945. ulp_status, ulp_word4);
  10946. goto out;
  10947. }
  10948. spin_lock(&phba->hbalock);
  10949. /* Set IN USE flag */
  10950. vport->vmid_flag |= LPFC_VMID_IN_USE;
  10951. phba->pport->vmid_flag |= LPFC_VMID_IN_USE;
  10952. spin_unlock(&phba->hbalock);
  10953. if (vmid_context->instantiated) {
  10954. write_lock(&vport->vmid_lock);
  10955. vmid->flag |= LPFC_VMID_REGISTERED;
  10956. vmid->flag &= ~LPFC_VMID_REQ_REGISTER;
  10957. write_unlock(&vport->vmid_lock);
  10958. }
  10959. out:
  10960. kfree(vmid_context);
  10961. lpfc_els_free_iocb(phba, icmdiocb);
  10962. lpfc_nlp_put(ndlp);
  10963. }