lpfc_els.c 212 KB

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