lpfc_els.c 243 KB

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