lpfc_els.c 250 KB

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