lpfc_els.c 216 KB

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