lpfc_els.c 216 KB

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