lpfc_els.c 206 KB

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