lpfc_els.c 215 KB

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