lpfc_els.c 219 KB

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