lpfc_els.c 203 KB

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