lpfc_els.c 248 KB

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