lpfc_els.c 222 KB

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