lpfc_els.c 224 KB

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