lpfc_els.c 251 KB

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