lpfc_els.c 210 KB

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