lpfc_els.c 290 KB

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