lpfc_hbadisc.c 159 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/slab.h>
  23. #include <linux/pci.h>
  24. #include <linux/kthread.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_nl.h"
  33. #include "lpfc_disc.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_sli4.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. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  43. static uint8_t lpfcAlpaArray[] = {
  44. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  45. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  46. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  47. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  48. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  49. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  50. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  51. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  52. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  53. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  54. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  55. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  56. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  57. };
  58. static void lpfc_disc_timeout_handler(struct lpfc_vport *);
  59. static void lpfc_disc_flush_list(struct lpfc_vport *vport);
  60. static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
  61. void
  62. lpfc_terminate_rport_io(struct fc_rport *rport)
  63. {
  64. struct lpfc_rport_data *rdata;
  65. struct lpfc_nodelist * ndlp;
  66. struct lpfc_hba *phba;
  67. rdata = rport->dd_data;
  68. ndlp = rdata->pnode;
  69. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
  70. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  71. printk(KERN_ERR "Cannot find remote node"
  72. " to terminate I/O Data x%x\n",
  73. rport->port_id);
  74. return;
  75. }
  76. phba = ndlp->phba;
  77. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  78. "rport terminate: sid:x%x did:x%x flg:x%x",
  79. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  80. if (ndlp->nlp_sid != NLP_NO_SID) {
  81. lpfc_sli_abort_iocb(ndlp->vport,
  82. &phba->sli.ring[phba->sli.fcp_ring],
  83. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  84. }
  85. }
  86. /*
  87. * This function will be called when dev_loss_tmo fire.
  88. */
  89. void
  90. lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
  91. {
  92. struct lpfc_rport_data *rdata;
  93. struct lpfc_nodelist * ndlp;
  94. struct lpfc_vport *vport;
  95. struct lpfc_hba *phba;
  96. struct lpfc_work_evt *evtp;
  97. int put_node;
  98. int put_rport;
  99. rdata = rport->dd_data;
  100. ndlp = rdata->pnode;
  101. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  102. return;
  103. vport = ndlp->vport;
  104. phba = vport->phba;
  105. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  106. "rport devlosscb: sid:x%x did:x%x flg:x%x",
  107. ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
  108. /* Don't defer this if we are in the process of deleting the vport
  109. * or unloading the driver. The unload will cleanup the node
  110. * appropriately we just need to cleanup the ndlp rport info here.
  111. */
  112. if (vport->load_flag & FC_UNLOADING) {
  113. put_node = rdata->pnode != NULL;
  114. put_rport = ndlp->rport != NULL;
  115. rdata->pnode = NULL;
  116. ndlp->rport = NULL;
  117. if (put_node)
  118. lpfc_nlp_put(ndlp);
  119. if (put_rport)
  120. put_device(&rport->dev);
  121. return;
  122. }
  123. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
  124. return;
  125. evtp = &ndlp->dev_loss_evt;
  126. if (!list_empty(&evtp->evt_listp))
  127. return;
  128. spin_lock_irq(&phba->hbalock);
  129. /* We need to hold the node by incrementing the reference
  130. * count until this queued work is done
  131. */
  132. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  133. if (evtp->evt_arg1) {
  134. evtp->evt = LPFC_EVT_DEV_LOSS;
  135. list_add_tail(&evtp->evt_listp, &phba->work_list);
  136. lpfc_worker_wake_up(phba);
  137. }
  138. spin_unlock_irq(&phba->hbalock);
  139. return;
  140. }
  141. /*
  142. * This function is called from the worker thread when dev_loss_tmo
  143. * expire.
  144. */
  145. static void
  146. lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
  147. {
  148. struct lpfc_rport_data *rdata;
  149. struct fc_rport *rport;
  150. struct lpfc_vport *vport;
  151. struct lpfc_hba *phba;
  152. uint8_t *name;
  153. int put_node;
  154. int put_rport;
  155. int warn_on = 0;
  156. rport = ndlp->rport;
  157. if (!rport)
  158. return;
  159. rdata = rport->dd_data;
  160. name = (uint8_t *) &ndlp->nlp_portname;
  161. vport = ndlp->vport;
  162. phba = vport->phba;
  163. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  164. "rport devlosstmo:did:x%x type:x%x id:x%x",
  165. ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
  166. /* Don't defer this if we are in the process of deleting the vport
  167. * or unloading the driver. The unload will cleanup the node
  168. * appropriately we just need to cleanup the ndlp rport info here.
  169. */
  170. if (vport->load_flag & FC_UNLOADING) {
  171. if (ndlp->nlp_sid != NLP_NO_SID) {
  172. /* flush the target */
  173. lpfc_sli_abort_iocb(vport,
  174. &phba->sli.ring[phba->sli.fcp_ring],
  175. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  176. }
  177. put_node = rdata->pnode != NULL;
  178. put_rport = ndlp->rport != NULL;
  179. rdata->pnode = NULL;
  180. ndlp->rport = NULL;
  181. if (put_node)
  182. lpfc_nlp_put(ndlp);
  183. if (put_rport)
  184. put_device(&rport->dev);
  185. return;
  186. }
  187. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
  188. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  189. "0284 Devloss timeout Ignored on "
  190. "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
  191. "NPort x%x\n",
  192. *name, *(name+1), *(name+2), *(name+3),
  193. *(name+4), *(name+5), *(name+6), *(name+7),
  194. ndlp->nlp_DID);
  195. return;
  196. }
  197. if (ndlp->nlp_type & NLP_FABRIC) {
  198. /* We will clean up these Nodes in linkup */
  199. put_node = rdata->pnode != NULL;
  200. put_rport = ndlp->rport != NULL;
  201. rdata->pnode = NULL;
  202. ndlp->rport = NULL;
  203. if (put_node)
  204. lpfc_nlp_put(ndlp);
  205. if (put_rport)
  206. put_device(&rport->dev);
  207. return;
  208. }
  209. if (ndlp->nlp_sid != NLP_NO_SID) {
  210. warn_on = 1;
  211. /* flush the target */
  212. lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
  213. ndlp->nlp_sid, 0, LPFC_CTX_TGT);
  214. }
  215. if (warn_on) {
  216. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  217. "0203 Devloss timeout on "
  218. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  219. "NPort x%06x Data: x%x x%x x%x\n",
  220. *name, *(name+1), *(name+2), *(name+3),
  221. *(name+4), *(name+5), *(name+6), *(name+7),
  222. ndlp->nlp_DID, ndlp->nlp_flag,
  223. ndlp->nlp_state, ndlp->nlp_rpi);
  224. } else {
  225. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  226. "0204 Devloss timeout on "
  227. "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
  228. "NPort x%06x Data: x%x x%x x%x\n",
  229. *name, *(name+1), *(name+2), *(name+3),
  230. *(name+4), *(name+5), *(name+6), *(name+7),
  231. ndlp->nlp_DID, ndlp->nlp_flag,
  232. ndlp->nlp_state, ndlp->nlp_rpi);
  233. }
  234. put_node = rdata->pnode != NULL;
  235. put_rport = ndlp->rport != NULL;
  236. rdata->pnode = NULL;
  237. ndlp->rport = NULL;
  238. if (put_node)
  239. lpfc_nlp_put(ndlp);
  240. if (put_rport)
  241. put_device(&rport->dev);
  242. if (!(vport->load_flag & FC_UNLOADING) &&
  243. !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
  244. !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  245. (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  246. (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
  247. (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
  248. lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
  249. lpfc_unregister_unused_fcf(phba);
  250. }
  251. /**
  252. * lpfc_alloc_fast_evt - Allocates data structure for posting event
  253. * @phba: Pointer to hba context object.
  254. *
  255. * This function is called from the functions which need to post
  256. * events from interrupt context. This function allocates data
  257. * structure required for posting event. It also keeps track of
  258. * number of events pending and prevent event storm when there are
  259. * too many events.
  260. **/
  261. struct lpfc_fast_path_event *
  262. lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
  263. struct lpfc_fast_path_event *ret;
  264. /* If there are lot of fast event do not exhaust memory due to this */
  265. if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
  266. return NULL;
  267. ret = kzalloc(sizeof(struct lpfc_fast_path_event),
  268. GFP_ATOMIC);
  269. if (ret) {
  270. atomic_inc(&phba->fast_event_count);
  271. INIT_LIST_HEAD(&ret->work_evt.evt_listp);
  272. ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
  273. }
  274. return ret;
  275. }
  276. /**
  277. * lpfc_free_fast_evt - Frees event data structure
  278. * @phba: Pointer to hba context object.
  279. * @evt: Event object which need to be freed.
  280. *
  281. * This function frees the data structure required for posting
  282. * events.
  283. **/
  284. void
  285. lpfc_free_fast_evt(struct lpfc_hba *phba,
  286. struct lpfc_fast_path_event *evt) {
  287. atomic_dec(&phba->fast_event_count);
  288. kfree(evt);
  289. }
  290. /**
  291. * lpfc_send_fastpath_evt - Posts events generated from fast path
  292. * @phba: Pointer to hba context object.
  293. * @evtp: Event data structure.
  294. *
  295. * This function is called from worker thread, when the interrupt
  296. * context need to post an event. This function posts the event
  297. * to fc transport netlink interface.
  298. **/
  299. static void
  300. lpfc_send_fastpath_evt(struct lpfc_hba *phba,
  301. struct lpfc_work_evt *evtp)
  302. {
  303. unsigned long evt_category, evt_sub_category;
  304. struct lpfc_fast_path_event *fast_evt_data;
  305. char *evt_data;
  306. uint32_t evt_data_size;
  307. struct Scsi_Host *shost;
  308. fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
  309. work_evt);
  310. evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
  311. evt_sub_category = (unsigned long) fast_evt_data->un.
  312. fabric_evt.subcategory;
  313. shost = lpfc_shost_from_vport(fast_evt_data->vport);
  314. if (evt_category == FC_REG_FABRIC_EVENT) {
  315. if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
  316. evt_data = (char *) &fast_evt_data->un.read_check_error;
  317. evt_data_size = sizeof(fast_evt_data->un.
  318. read_check_error);
  319. } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
  320. (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
  321. evt_data = (char *) &fast_evt_data->un.fabric_evt;
  322. evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
  323. } else {
  324. lpfc_free_fast_evt(phba, fast_evt_data);
  325. return;
  326. }
  327. } else if (evt_category == FC_REG_SCSI_EVENT) {
  328. switch (evt_sub_category) {
  329. case LPFC_EVENT_QFULL:
  330. case LPFC_EVENT_DEVBSY:
  331. evt_data = (char *) &fast_evt_data->un.scsi_evt;
  332. evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
  333. break;
  334. case LPFC_EVENT_CHECK_COND:
  335. evt_data = (char *) &fast_evt_data->un.check_cond_evt;
  336. evt_data_size = sizeof(fast_evt_data->un.
  337. check_cond_evt);
  338. break;
  339. case LPFC_EVENT_VARQUEDEPTH:
  340. evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
  341. evt_data_size = sizeof(fast_evt_data->un.
  342. queue_depth_evt);
  343. break;
  344. default:
  345. lpfc_free_fast_evt(phba, fast_evt_data);
  346. return;
  347. }
  348. } else {
  349. lpfc_free_fast_evt(phba, fast_evt_data);
  350. return;
  351. }
  352. fc_host_post_vendor_event(shost,
  353. fc_get_event_number(),
  354. evt_data_size,
  355. evt_data,
  356. LPFC_NL_VENDOR_ID);
  357. lpfc_free_fast_evt(phba, fast_evt_data);
  358. return;
  359. }
  360. static void
  361. lpfc_work_list_done(struct lpfc_hba *phba)
  362. {
  363. struct lpfc_work_evt *evtp = NULL;
  364. struct lpfc_nodelist *ndlp;
  365. int free_evt;
  366. spin_lock_irq(&phba->hbalock);
  367. while (!list_empty(&phba->work_list)) {
  368. list_remove_head((&phba->work_list), evtp, typeof(*evtp),
  369. evt_listp);
  370. spin_unlock_irq(&phba->hbalock);
  371. free_evt = 1;
  372. switch (evtp->evt) {
  373. case LPFC_EVT_ELS_RETRY:
  374. ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
  375. lpfc_els_retry_delay_handler(ndlp);
  376. free_evt = 0; /* evt is part of ndlp */
  377. /* decrement the node reference count held
  378. * for this queued work
  379. */
  380. lpfc_nlp_put(ndlp);
  381. break;
  382. case LPFC_EVT_DEV_LOSS:
  383. ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
  384. lpfc_dev_loss_tmo_handler(ndlp);
  385. free_evt = 0;
  386. /* decrement the node reference count held for
  387. * this queued work
  388. */
  389. lpfc_nlp_put(ndlp);
  390. break;
  391. case LPFC_EVT_ONLINE:
  392. if (phba->link_state < LPFC_LINK_DOWN)
  393. *(int *) (evtp->evt_arg1) = lpfc_online(phba);
  394. else
  395. *(int *) (evtp->evt_arg1) = 0;
  396. complete((struct completion *)(evtp->evt_arg2));
  397. break;
  398. case LPFC_EVT_OFFLINE_PREP:
  399. if (phba->link_state >= LPFC_LINK_DOWN)
  400. lpfc_offline_prep(phba);
  401. *(int *)(evtp->evt_arg1) = 0;
  402. complete((struct completion *)(evtp->evt_arg2));
  403. break;
  404. case LPFC_EVT_OFFLINE:
  405. lpfc_offline(phba);
  406. lpfc_sli_brdrestart(phba);
  407. *(int *)(evtp->evt_arg1) =
  408. lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
  409. lpfc_unblock_mgmt_io(phba);
  410. complete((struct completion *)(evtp->evt_arg2));
  411. break;
  412. case LPFC_EVT_WARM_START:
  413. lpfc_offline(phba);
  414. lpfc_reset_barrier(phba);
  415. lpfc_sli_brdreset(phba);
  416. lpfc_hba_down_post(phba);
  417. *(int *)(evtp->evt_arg1) =
  418. lpfc_sli_brdready(phba, HS_MBRDY);
  419. lpfc_unblock_mgmt_io(phba);
  420. complete((struct completion *)(evtp->evt_arg2));
  421. break;
  422. case LPFC_EVT_KILL:
  423. lpfc_offline(phba);
  424. *(int *)(evtp->evt_arg1)
  425. = (phba->pport->stopped)
  426. ? 0 : lpfc_sli_brdkill(phba);
  427. lpfc_unblock_mgmt_io(phba);
  428. complete((struct completion *)(evtp->evt_arg2));
  429. break;
  430. case LPFC_EVT_FASTPATH_MGMT_EVT:
  431. lpfc_send_fastpath_evt(phba, evtp);
  432. free_evt = 0;
  433. break;
  434. case LPFC_EVT_RESET_HBA:
  435. if (!(phba->pport->load_flag & FC_UNLOADING))
  436. lpfc_reset_hba(phba);
  437. break;
  438. }
  439. if (free_evt)
  440. kfree(evtp);
  441. spin_lock_irq(&phba->hbalock);
  442. }
  443. spin_unlock_irq(&phba->hbalock);
  444. }
  445. static void
  446. lpfc_work_done(struct lpfc_hba *phba)
  447. {
  448. struct lpfc_sli_ring *pring;
  449. uint32_t ha_copy, status, control, work_port_events;
  450. struct lpfc_vport **vports;
  451. struct lpfc_vport *vport;
  452. int i;
  453. spin_lock_irq(&phba->hbalock);
  454. ha_copy = phba->work_ha;
  455. phba->work_ha = 0;
  456. spin_unlock_irq(&phba->hbalock);
  457. /* First, try to post the next mailbox command to SLI4 device */
  458. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
  459. lpfc_sli4_post_async_mbox(phba);
  460. if (ha_copy & HA_ERATT)
  461. /* Handle the error attention event */
  462. lpfc_handle_eratt(phba);
  463. if (ha_copy & HA_MBATT)
  464. lpfc_sli_handle_mb_event(phba);
  465. if (ha_copy & HA_LATT)
  466. lpfc_handle_latt(phba);
  467. /* Process SLI4 events */
  468. if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
  469. if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
  470. lpfc_sli4_fcp_xri_abort_event_proc(phba);
  471. if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
  472. lpfc_sli4_els_xri_abort_event_proc(phba);
  473. if (phba->hba_flag & ASYNC_EVENT)
  474. lpfc_sli4_async_event_proc(phba);
  475. if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
  476. spin_lock_irq(&phba->hbalock);
  477. phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
  478. spin_unlock_irq(&phba->hbalock);
  479. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  480. }
  481. if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
  482. lpfc_sli4_fcf_redisc_event_proc(phba);
  483. }
  484. vports = lpfc_create_vport_work_array(phba);
  485. if (vports != NULL)
  486. for (i = 0; i <= phba->max_vports; i++) {
  487. /*
  488. * We could have no vports in array if unloading, so if
  489. * this happens then just use the pport
  490. */
  491. if (vports[i] == NULL && i == 0)
  492. vport = phba->pport;
  493. else
  494. vport = vports[i];
  495. if (vport == NULL)
  496. break;
  497. spin_lock_irq(&vport->work_port_lock);
  498. work_port_events = vport->work_port_events;
  499. vport->work_port_events &= ~work_port_events;
  500. spin_unlock_irq(&vport->work_port_lock);
  501. if (work_port_events & WORKER_DISC_TMO)
  502. lpfc_disc_timeout_handler(vport);
  503. if (work_port_events & WORKER_ELS_TMO)
  504. lpfc_els_timeout_handler(vport);
  505. if (work_port_events & WORKER_HB_TMO)
  506. lpfc_hb_timeout_handler(phba);
  507. if (work_port_events & WORKER_MBOX_TMO)
  508. lpfc_mbox_timeout_handler(phba);
  509. if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
  510. lpfc_unblock_fabric_iocbs(phba);
  511. if (work_port_events & WORKER_FDMI_TMO)
  512. lpfc_fdmi_timeout_handler(vport);
  513. if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
  514. lpfc_ramp_down_queue_handler(phba);
  515. if (work_port_events & WORKER_RAMP_UP_QUEUE)
  516. lpfc_ramp_up_queue_handler(phba);
  517. }
  518. lpfc_destroy_vport_work_array(phba, vports);
  519. pring = &phba->sli.ring[LPFC_ELS_RING];
  520. status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  521. status >>= (4*LPFC_ELS_RING);
  522. if ((status & HA_RXMASK) ||
  523. (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
  524. (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
  525. if (pring->flag & LPFC_STOP_IOCB_EVENT) {
  526. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  527. /* Set the lpfc data pending flag */
  528. set_bit(LPFC_DATA_READY, &phba->data_flags);
  529. } else {
  530. pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
  531. lpfc_sli_handle_slow_ring_event(phba, pring,
  532. (status &
  533. HA_RXMASK));
  534. }
  535. if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt)
  536. lpfc_drain_txq(phba);
  537. /*
  538. * Turn on Ring interrupts
  539. */
  540. if (phba->sli_rev <= LPFC_SLI_REV3) {
  541. spin_lock_irq(&phba->hbalock);
  542. control = readl(phba->HCregaddr);
  543. if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
  544. lpfc_debugfs_slow_ring_trc(phba,
  545. "WRK Enable ring: cntl:x%x hacopy:x%x",
  546. control, ha_copy, 0);
  547. control |= (HC_R0INT_ENA << LPFC_ELS_RING);
  548. writel(control, phba->HCregaddr);
  549. readl(phba->HCregaddr); /* flush */
  550. } else {
  551. lpfc_debugfs_slow_ring_trc(phba,
  552. "WRK Ring ok: cntl:x%x hacopy:x%x",
  553. control, ha_copy, 0);
  554. }
  555. spin_unlock_irq(&phba->hbalock);
  556. }
  557. }
  558. lpfc_work_list_done(phba);
  559. }
  560. int
  561. lpfc_do_work(void *p)
  562. {
  563. struct lpfc_hba *phba = p;
  564. int rc;
  565. set_user_nice(current, -20);
  566. phba->data_flags = 0;
  567. while (!kthread_should_stop()) {
  568. /* wait and check worker queue activities */
  569. rc = wait_event_interruptible(phba->work_waitq,
  570. (test_and_clear_bit(LPFC_DATA_READY,
  571. &phba->data_flags)
  572. || kthread_should_stop()));
  573. /* Signal wakeup shall terminate the worker thread */
  574. if (rc) {
  575. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  576. "0433 Wakeup on signal: rc=x%x\n", rc);
  577. break;
  578. }
  579. /* Attend pending lpfc data processing */
  580. lpfc_work_done(phba);
  581. }
  582. phba->worker_thread = NULL;
  583. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  584. "0432 Worker thread stopped.\n");
  585. return 0;
  586. }
  587. /*
  588. * This is only called to handle FC worker events. Since this a rare
  589. * occurance, we allocate a struct lpfc_work_evt structure here instead of
  590. * embedding it in the IOCB.
  591. */
  592. int
  593. lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
  594. uint32_t evt)
  595. {
  596. struct lpfc_work_evt *evtp;
  597. unsigned long flags;
  598. /*
  599. * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
  600. * be queued to worker thread for processing
  601. */
  602. evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
  603. if (!evtp)
  604. return 0;
  605. evtp->evt_arg1 = arg1;
  606. evtp->evt_arg2 = arg2;
  607. evtp->evt = evt;
  608. spin_lock_irqsave(&phba->hbalock, flags);
  609. list_add_tail(&evtp->evt_listp, &phba->work_list);
  610. spin_unlock_irqrestore(&phba->hbalock, flags);
  611. lpfc_worker_wake_up(phba);
  612. return 1;
  613. }
  614. void
  615. lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
  616. {
  617. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  618. struct lpfc_hba *phba = vport->phba;
  619. struct lpfc_nodelist *ndlp, *next_ndlp;
  620. int rc;
  621. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  622. if (!NLP_CHK_NODE_ACT(ndlp))
  623. continue;
  624. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  625. continue;
  626. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
  627. ((vport->port_type == LPFC_NPIV_PORT) &&
  628. (ndlp->nlp_DID == NameServer_DID)))
  629. lpfc_unreg_rpi(vport, ndlp);
  630. /* Leave Fabric nodes alone on link down */
  631. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  632. (!remove && ndlp->nlp_type & NLP_FABRIC))
  633. continue;
  634. rc = lpfc_disc_state_machine(vport, ndlp, NULL,
  635. remove
  636. ? NLP_EVT_DEVICE_RM
  637. : NLP_EVT_DEVICE_RECOVERY);
  638. }
  639. if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
  640. lpfc_mbx_unreg_vpi(vport);
  641. spin_lock_irq(shost->host_lock);
  642. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  643. spin_unlock_irq(shost->host_lock);
  644. }
  645. }
  646. void
  647. lpfc_port_link_failure(struct lpfc_vport *vport)
  648. {
  649. lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
  650. /* Cleanup any outstanding received buffers */
  651. lpfc_cleanup_rcv_buffers(vport);
  652. /* Cleanup any outstanding RSCN activity */
  653. lpfc_els_flush_rscn(vport);
  654. /* Cleanup any outstanding ELS commands */
  655. lpfc_els_flush_cmd(vport);
  656. lpfc_cleanup_rpis(vport, 0);
  657. /* Turn off discovery timer if its running */
  658. lpfc_can_disctmo(vport);
  659. }
  660. void
  661. lpfc_linkdown_port(struct lpfc_vport *vport)
  662. {
  663. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  664. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
  665. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  666. "Link Down: state:x%x rtry:x%x flg:x%x",
  667. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  668. lpfc_port_link_failure(vport);
  669. }
  670. int
  671. lpfc_linkdown(struct lpfc_hba *phba)
  672. {
  673. struct lpfc_vport *vport = phba->pport;
  674. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  675. struct lpfc_vport **vports;
  676. LPFC_MBOXQ_t *mb;
  677. int i;
  678. if (phba->link_state == LPFC_LINK_DOWN)
  679. return 0;
  680. /* Block all SCSI stack I/Os */
  681. lpfc_scsi_dev_block(phba);
  682. spin_lock_irq(&phba->hbalock);
  683. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
  684. spin_unlock_irq(&phba->hbalock);
  685. if (phba->link_state > LPFC_LINK_DOWN) {
  686. phba->link_state = LPFC_LINK_DOWN;
  687. spin_lock_irq(shost->host_lock);
  688. phba->pport->fc_flag &= ~FC_LBIT;
  689. spin_unlock_irq(shost->host_lock);
  690. }
  691. vports = lpfc_create_vport_work_array(phba);
  692. if (vports != NULL)
  693. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  694. /* Issue a LINK DOWN event to all nodes */
  695. lpfc_linkdown_port(vports[i]);
  696. }
  697. lpfc_destroy_vport_work_array(phba, vports);
  698. /* Clean up any firmware default rpi's */
  699. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  700. if (mb) {
  701. lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
  702. mb->vport = vport;
  703. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  704. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  705. == MBX_NOT_FINISHED) {
  706. mempool_free(mb, phba->mbox_mem_pool);
  707. }
  708. }
  709. /* Setup myDID for link up if we are in pt2pt mode */
  710. if (phba->pport->fc_flag & FC_PT2PT) {
  711. phba->pport->fc_myDID = 0;
  712. mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  713. if (mb) {
  714. lpfc_config_link(phba, mb);
  715. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  716. mb->vport = vport;
  717. if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
  718. == MBX_NOT_FINISHED) {
  719. mempool_free(mb, phba->mbox_mem_pool);
  720. }
  721. }
  722. spin_lock_irq(shost->host_lock);
  723. phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
  724. spin_unlock_irq(shost->host_lock);
  725. }
  726. return 0;
  727. }
  728. static void
  729. lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
  730. {
  731. struct lpfc_nodelist *ndlp;
  732. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  733. if (!NLP_CHK_NODE_ACT(ndlp))
  734. continue;
  735. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  736. continue;
  737. if (ndlp->nlp_type & NLP_FABRIC) {
  738. /* On Linkup its safe to clean up the ndlp
  739. * from Fabric connections.
  740. */
  741. if (ndlp->nlp_DID != Fabric_DID)
  742. lpfc_unreg_rpi(vport, ndlp);
  743. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  744. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  745. /* Fail outstanding IO now since device is
  746. * marked for PLOGI.
  747. */
  748. lpfc_unreg_rpi(vport, ndlp);
  749. }
  750. }
  751. }
  752. static void
  753. lpfc_linkup_port(struct lpfc_vport *vport)
  754. {
  755. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  756. struct lpfc_hba *phba = vport->phba;
  757. if ((vport->load_flag & FC_UNLOADING) != 0)
  758. return;
  759. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  760. "Link Up: top:x%x speed:x%x flg:x%x",
  761. phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
  762. /* If NPIV is not enabled, only bring the physical port up */
  763. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  764. (vport != phba->pport))
  765. return;
  766. fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
  767. spin_lock_irq(shost->host_lock);
  768. vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
  769. FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
  770. vport->fc_flag |= FC_NDISC_ACTIVE;
  771. vport->fc_ns_retry = 0;
  772. spin_unlock_irq(shost->host_lock);
  773. if (vport->fc_flag & FC_LBIT)
  774. lpfc_linkup_cleanup_nodes(vport);
  775. }
  776. static int
  777. lpfc_linkup(struct lpfc_hba *phba)
  778. {
  779. struct lpfc_vport **vports;
  780. int i;
  781. phba->link_state = LPFC_LINK_UP;
  782. /* Unblock fabric iocbs if they are blocked */
  783. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  784. del_timer_sync(&phba->fabric_block_timer);
  785. vports = lpfc_create_vport_work_array(phba);
  786. if (vports != NULL)
  787. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
  788. lpfc_linkup_port(vports[i]);
  789. lpfc_destroy_vport_work_array(phba, vports);
  790. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  791. (phba->sli_rev < LPFC_SLI_REV4))
  792. lpfc_issue_clear_la(phba, phba->pport);
  793. return 0;
  794. }
  795. /*
  796. * This routine handles processing a CLEAR_LA mailbox
  797. * command upon completion. It is setup in the LPFC_MBOXQ
  798. * as the completion routine when the command is
  799. * handed off to the SLI layer.
  800. */
  801. static void
  802. lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  803. {
  804. struct lpfc_vport *vport = pmb->vport;
  805. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  806. struct lpfc_sli *psli = &phba->sli;
  807. MAILBOX_t *mb = &pmb->u.mb;
  808. uint32_t control;
  809. /* Since we don't do discovery right now, turn these off here */
  810. psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  811. psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  812. psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
  813. /* Check for error */
  814. if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
  815. /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
  816. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  817. "0320 CLEAR_LA mbxStatus error x%x hba "
  818. "state x%x\n",
  819. mb->mbxStatus, vport->port_state);
  820. phba->link_state = LPFC_HBA_ERROR;
  821. goto out;
  822. }
  823. if (vport->port_type == LPFC_PHYSICAL_PORT)
  824. phba->link_state = LPFC_HBA_READY;
  825. spin_lock_irq(&phba->hbalock);
  826. psli->sli_flag |= LPFC_PROCESS_LA;
  827. control = readl(phba->HCregaddr);
  828. control |= HC_LAINT_ENA;
  829. writel(control, phba->HCregaddr);
  830. readl(phba->HCregaddr); /* flush */
  831. spin_unlock_irq(&phba->hbalock);
  832. mempool_free(pmb, phba->mbox_mem_pool);
  833. return;
  834. out:
  835. /* Device Discovery completes */
  836. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  837. "0225 Device Discovery completes\n");
  838. mempool_free(pmb, phba->mbox_mem_pool);
  839. spin_lock_irq(shost->host_lock);
  840. vport->fc_flag &= ~FC_ABORT_DISCOVERY;
  841. spin_unlock_irq(shost->host_lock);
  842. lpfc_can_disctmo(vport);
  843. /* turn on Link Attention interrupts */
  844. spin_lock_irq(&phba->hbalock);
  845. psli->sli_flag |= LPFC_PROCESS_LA;
  846. control = readl(phba->HCregaddr);
  847. control |= HC_LAINT_ENA;
  848. writel(control, phba->HCregaddr);
  849. readl(phba->HCregaddr); /* flush */
  850. spin_unlock_irq(&phba->hbalock);
  851. return;
  852. }
  853. static void
  854. lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  855. {
  856. struct lpfc_vport *vport = pmb->vport;
  857. if (pmb->u.mb.mbxStatus)
  858. goto out;
  859. mempool_free(pmb, phba->mbox_mem_pool);
  860. if (phba->fc_topology == TOPOLOGY_LOOP &&
  861. vport->fc_flag & FC_PUBLIC_LOOP &&
  862. !(vport->fc_flag & FC_LBIT)) {
  863. /* Need to wait for FAN - use discovery timer
  864. * for timeout. port_state is identically
  865. * LPFC_LOCAL_CFG_LINK while waiting for FAN
  866. */
  867. lpfc_set_disctmo(vport);
  868. return;
  869. }
  870. /* Start discovery by sending a FLOGI. port_state is identically
  871. * LPFC_FLOGI while waiting for FLOGI cmpl
  872. */
  873. if (vport->port_state != LPFC_FLOGI) {
  874. lpfc_initial_flogi(vport);
  875. }
  876. return;
  877. out:
  878. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  879. "0306 CONFIG_LINK mbxStatus error x%x "
  880. "HBA state x%x\n",
  881. pmb->u.mb.mbxStatus, vport->port_state);
  882. mempool_free(pmb, phba->mbox_mem_pool);
  883. lpfc_linkdown(phba);
  884. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  885. "0200 CONFIG_LINK bad hba state x%x\n",
  886. vport->port_state);
  887. lpfc_issue_clear_la(phba, vport);
  888. return;
  889. }
  890. static void
  891. lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  892. {
  893. struct lpfc_vport *vport = mboxq->vport;
  894. if (mboxq->u.mb.mbxStatus) {
  895. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  896. "2017 REG_FCFI mbxStatus error x%x "
  897. "HBA state x%x\n",
  898. mboxq->u.mb.mbxStatus, vport->port_state);
  899. mempool_free(mboxq, phba->mbox_mem_pool);
  900. return;
  901. }
  902. /* Start FCoE discovery by sending a FLOGI. */
  903. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
  904. /* Set the FCFI registered flag */
  905. spin_lock_irq(&phba->hbalock);
  906. phba->fcf.fcf_flag |= FCF_REGISTERED;
  907. spin_unlock_irq(&phba->hbalock);
  908. /* If there is a pending FCoE event, restart FCF table scan. */
  909. if (lpfc_check_pending_fcoe_event(phba, 1)) {
  910. mempool_free(mboxq, phba->mbox_mem_pool);
  911. return;
  912. }
  913. spin_lock_irq(&phba->hbalock);
  914. phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
  915. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  916. spin_unlock_irq(&phba->hbalock);
  917. if (vport->port_state != LPFC_FLOGI)
  918. lpfc_initial_flogi(vport);
  919. mempool_free(mboxq, phba->mbox_mem_pool);
  920. return;
  921. }
  922. /**
  923. * lpfc_fab_name_match - Check if the fcf fabric name match.
  924. * @fab_name: pointer to fabric name.
  925. * @new_fcf_record: pointer to fcf record.
  926. *
  927. * This routine compare the fcf record's fabric name with provided
  928. * fabric name. If the fabric name are identical this function
  929. * returns 1 else return 0.
  930. **/
  931. static uint32_t
  932. lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
  933. {
  934. if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
  935. return 0;
  936. if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
  937. return 0;
  938. if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
  939. return 0;
  940. if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
  941. return 0;
  942. if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
  943. return 0;
  944. if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
  945. return 0;
  946. if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
  947. return 0;
  948. if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
  949. return 0;
  950. return 1;
  951. }
  952. /**
  953. * lpfc_sw_name_match - Check if the fcf switch name match.
  954. * @fab_name: pointer to fabric name.
  955. * @new_fcf_record: pointer to fcf record.
  956. *
  957. * This routine compare the fcf record's switch name with provided
  958. * switch name. If the switch name are identical this function
  959. * returns 1 else return 0.
  960. **/
  961. static uint32_t
  962. lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
  963. {
  964. if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
  965. return 0;
  966. if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
  967. return 0;
  968. if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
  969. return 0;
  970. if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
  971. return 0;
  972. if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
  973. return 0;
  974. if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
  975. return 0;
  976. if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
  977. return 0;
  978. if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
  979. return 0;
  980. return 1;
  981. }
  982. /**
  983. * lpfc_mac_addr_match - Check if the fcf mac address match.
  984. * @mac_addr: pointer to mac address.
  985. * @new_fcf_record: pointer to fcf record.
  986. *
  987. * This routine compare the fcf record's mac address with HBA's
  988. * FCF mac address. If the mac addresses are identical this function
  989. * returns 1 else return 0.
  990. **/
  991. static uint32_t
  992. lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
  993. {
  994. if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
  995. return 0;
  996. if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
  997. return 0;
  998. if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
  999. return 0;
  1000. if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
  1001. return 0;
  1002. if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
  1003. return 0;
  1004. if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
  1005. return 0;
  1006. return 1;
  1007. }
  1008. static bool
  1009. lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
  1010. {
  1011. return (curr_vlan_id == new_vlan_id);
  1012. }
  1013. /**
  1014. * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
  1015. * @fcf: pointer to driver fcf record.
  1016. * @new_fcf_record: pointer to fcf record.
  1017. *
  1018. * This routine copies the FCF information from the FCF
  1019. * record to lpfc_hba data structure.
  1020. **/
  1021. static void
  1022. lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
  1023. struct fcf_record *new_fcf_record)
  1024. {
  1025. /* Fabric name */
  1026. fcf_rec->fabric_name[0] =
  1027. bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
  1028. fcf_rec->fabric_name[1] =
  1029. bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
  1030. fcf_rec->fabric_name[2] =
  1031. bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
  1032. fcf_rec->fabric_name[3] =
  1033. bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
  1034. fcf_rec->fabric_name[4] =
  1035. bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
  1036. fcf_rec->fabric_name[5] =
  1037. bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
  1038. fcf_rec->fabric_name[6] =
  1039. bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
  1040. fcf_rec->fabric_name[7] =
  1041. bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
  1042. /* Mac address */
  1043. fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
  1044. fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
  1045. fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
  1046. fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
  1047. fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
  1048. fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
  1049. /* FCF record index */
  1050. fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  1051. /* FCF record priority */
  1052. fcf_rec->priority = new_fcf_record->fip_priority;
  1053. /* Switch name */
  1054. fcf_rec->switch_name[0] =
  1055. bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
  1056. fcf_rec->switch_name[1] =
  1057. bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
  1058. fcf_rec->switch_name[2] =
  1059. bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
  1060. fcf_rec->switch_name[3] =
  1061. bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
  1062. fcf_rec->switch_name[4] =
  1063. bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
  1064. fcf_rec->switch_name[5] =
  1065. bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
  1066. fcf_rec->switch_name[6] =
  1067. bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
  1068. fcf_rec->switch_name[7] =
  1069. bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
  1070. }
  1071. /**
  1072. * lpfc_update_fcf_record - Update driver fcf record
  1073. * @phba: pointer to lpfc hba data structure.
  1074. * @fcf_rec: pointer to driver fcf record.
  1075. * @new_fcf_record: pointer to hba fcf record.
  1076. * @addr_mode: address mode to be set to the driver fcf record.
  1077. * @vlan_id: vlan tag to be set to the driver fcf record.
  1078. * @flag: flag bits to be set to the driver fcf record.
  1079. *
  1080. * This routine updates the driver FCF record from the new HBA FCF record
  1081. * together with the address mode, vlan_id, and other informations. This
  1082. * routine is called with the host lock held.
  1083. **/
  1084. static void
  1085. __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
  1086. struct fcf_record *new_fcf_record, uint32_t addr_mode,
  1087. uint16_t vlan_id, uint32_t flag)
  1088. {
  1089. /* Copy the fields from the HBA's FCF record */
  1090. lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
  1091. /* Update other fields of driver FCF record */
  1092. fcf_rec->addr_mode = addr_mode;
  1093. fcf_rec->vlan_id = vlan_id;
  1094. fcf_rec->flag |= (flag | RECORD_VALID);
  1095. }
  1096. /**
  1097. * lpfc_register_fcf - Register the FCF with hba.
  1098. * @phba: pointer to lpfc hba data structure.
  1099. *
  1100. * This routine issues a register fcfi mailbox command to register
  1101. * the fcf with HBA.
  1102. **/
  1103. static void
  1104. lpfc_register_fcf(struct lpfc_hba *phba)
  1105. {
  1106. LPFC_MBOXQ_t *fcf_mbxq;
  1107. int rc;
  1108. spin_lock_irq(&phba->hbalock);
  1109. /* If the FCF is not availabe do nothing. */
  1110. if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
  1111. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1112. spin_unlock_irq(&phba->hbalock);
  1113. return;
  1114. }
  1115. /* The FCF is already registered, start discovery */
  1116. if (phba->fcf.fcf_flag & FCF_REGISTERED) {
  1117. phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
  1118. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1119. spin_unlock_irq(&phba->hbalock);
  1120. if (phba->pport->port_state != LPFC_FLOGI)
  1121. lpfc_initial_flogi(phba->pport);
  1122. return;
  1123. }
  1124. spin_unlock_irq(&phba->hbalock);
  1125. fcf_mbxq = mempool_alloc(phba->mbox_mem_pool,
  1126. GFP_KERNEL);
  1127. if (!fcf_mbxq) {
  1128. spin_lock_irq(&phba->hbalock);
  1129. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1130. spin_unlock_irq(&phba->hbalock);
  1131. return;
  1132. }
  1133. lpfc_reg_fcfi(phba, fcf_mbxq);
  1134. fcf_mbxq->vport = phba->pport;
  1135. fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
  1136. rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
  1137. if (rc == MBX_NOT_FINISHED) {
  1138. spin_lock_irq(&phba->hbalock);
  1139. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1140. spin_unlock_irq(&phba->hbalock);
  1141. mempool_free(fcf_mbxq, phba->mbox_mem_pool);
  1142. }
  1143. return;
  1144. }
  1145. /**
  1146. * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
  1147. * @phba: pointer to lpfc hba data structure.
  1148. * @new_fcf_record: pointer to fcf record.
  1149. * @boot_flag: Indicates if this record used by boot bios.
  1150. * @addr_mode: The address mode to be used by this FCF
  1151. * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
  1152. *
  1153. * This routine compare the fcf record with connect list obtained from the
  1154. * config region to decide if this FCF can be used for SAN discovery. It returns
  1155. * 1 if this record can be used for SAN discovery else return zero. If this FCF
  1156. * record can be used for SAN discovery, the boot_flag will indicate if this FCF
  1157. * is used by boot bios and addr_mode will indicate the addressing mode to be
  1158. * used for this FCF when the function returns.
  1159. * If the FCF record need to be used with a particular vlan id, the vlan is
  1160. * set in the vlan_id on return of the function. If not VLAN tagging need to
  1161. * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
  1162. **/
  1163. static int
  1164. lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
  1165. struct fcf_record *new_fcf_record,
  1166. uint32_t *boot_flag, uint32_t *addr_mode,
  1167. uint16_t *vlan_id)
  1168. {
  1169. struct lpfc_fcf_conn_entry *conn_entry;
  1170. int i, j, fcf_vlan_id = 0;
  1171. /* Find the lowest VLAN id in the FCF record */
  1172. for (i = 0; i < 512; i++) {
  1173. if (new_fcf_record->vlan_bitmap[i]) {
  1174. fcf_vlan_id = i * 8;
  1175. j = 0;
  1176. while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
  1177. j++;
  1178. fcf_vlan_id++;
  1179. }
  1180. break;
  1181. }
  1182. }
  1183. /* If FCF not available return 0 */
  1184. if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
  1185. !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
  1186. return 0;
  1187. if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
  1188. *boot_flag = 0;
  1189. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1190. new_fcf_record);
  1191. if (phba->valid_vlan)
  1192. *vlan_id = phba->vlan_id;
  1193. else
  1194. *vlan_id = LPFC_FCOE_NULL_VID;
  1195. return 1;
  1196. }
  1197. /*
  1198. * If there are no FCF connection table entry, driver connect to all
  1199. * FCFs.
  1200. */
  1201. if (list_empty(&phba->fcf_conn_rec_list)) {
  1202. *boot_flag = 0;
  1203. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1204. new_fcf_record);
  1205. /*
  1206. * When there are no FCF connect entries, use driver's default
  1207. * addressing mode - FPMA.
  1208. */
  1209. if (*addr_mode & LPFC_FCF_FPMA)
  1210. *addr_mode = LPFC_FCF_FPMA;
  1211. /* If FCF record report a vlan id use that vlan id */
  1212. if (fcf_vlan_id)
  1213. *vlan_id = fcf_vlan_id;
  1214. else
  1215. *vlan_id = LPFC_FCOE_NULL_VID;
  1216. return 1;
  1217. }
  1218. list_for_each_entry(conn_entry,
  1219. &phba->fcf_conn_rec_list, list) {
  1220. if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
  1221. continue;
  1222. if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
  1223. !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
  1224. new_fcf_record))
  1225. continue;
  1226. if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
  1227. !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
  1228. new_fcf_record))
  1229. continue;
  1230. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
  1231. /*
  1232. * If the vlan bit map does not have the bit set for the
  1233. * vlan id to be used, then it is not a match.
  1234. */
  1235. if (!(new_fcf_record->vlan_bitmap
  1236. [conn_entry->conn_rec.vlan_tag / 8] &
  1237. (1 << (conn_entry->conn_rec.vlan_tag % 8))))
  1238. continue;
  1239. }
  1240. /*
  1241. * If connection record does not support any addressing mode,
  1242. * skip the FCF record.
  1243. */
  1244. if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
  1245. & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
  1246. continue;
  1247. /*
  1248. * Check if the connection record specifies a required
  1249. * addressing mode.
  1250. */
  1251. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1252. !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
  1253. /*
  1254. * If SPMA required but FCF not support this continue.
  1255. */
  1256. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1257. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1258. new_fcf_record) & LPFC_FCF_SPMA))
  1259. continue;
  1260. /*
  1261. * If FPMA required but FCF not support this continue.
  1262. */
  1263. if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1264. !(bf_get(lpfc_fcf_record_mac_addr_prov,
  1265. new_fcf_record) & LPFC_FCF_FPMA))
  1266. continue;
  1267. }
  1268. /*
  1269. * This fcf record matches filtering criteria.
  1270. */
  1271. if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
  1272. *boot_flag = 1;
  1273. else
  1274. *boot_flag = 0;
  1275. /*
  1276. * If user did not specify any addressing mode, or if the
  1277. * prefered addressing mode specified by user is not supported
  1278. * by FCF, allow fabric to pick the addressing mode.
  1279. */
  1280. *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
  1281. new_fcf_record);
  1282. /*
  1283. * If the user specified a required address mode, assign that
  1284. * address mode
  1285. */
  1286. if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1287. (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
  1288. *addr_mode = (conn_entry->conn_rec.flags &
  1289. FCFCNCT_AM_SPMA) ?
  1290. LPFC_FCF_SPMA : LPFC_FCF_FPMA;
  1291. /*
  1292. * If the user specified a prefered address mode, use the
  1293. * addr mode only if FCF support the addr_mode.
  1294. */
  1295. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1296. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1297. (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1298. (*addr_mode & LPFC_FCF_SPMA))
  1299. *addr_mode = LPFC_FCF_SPMA;
  1300. else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
  1301. (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
  1302. !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
  1303. (*addr_mode & LPFC_FCF_FPMA))
  1304. *addr_mode = LPFC_FCF_FPMA;
  1305. /* If matching connect list has a vlan id, use it */
  1306. if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
  1307. *vlan_id = conn_entry->conn_rec.vlan_tag;
  1308. /*
  1309. * If no vlan id is specified in connect list, use the vlan id
  1310. * in the FCF record
  1311. */
  1312. else if (fcf_vlan_id)
  1313. *vlan_id = fcf_vlan_id;
  1314. else
  1315. *vlan_id = LPFC_FCOE_NULL_VID;
  1316. return 1;
  1317. }
  1318. return 0;
  1319. }
  1320. /**
  1321. * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
  1322. * @phba: pointer to lpfc hba data structure.
  1323. * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
  1324. *
  1325. * This function check if there is any fcoe event pending while driver
  1326. * scan FCF entries. If there is any pending event, it will restart the
  1327. * FCF saning and return 1 else return 0.
  1328. */
  1329. int
  1330. lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
  1331. {
  1332. /*
  1333. * If the Link is up and no FCoE events while in the
  1334. * FCF discovery, no need to restart FCF discovery.
  1335. */
  1336. if ((phba->link_state >= LPFC_LINK_UP) &&
  1337. (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
  1338. return 0;
  1339. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1340. "2768 Pending link or FCF event during current "
  1341. "handling of the previous event: link_state:x%x, "
  1342. "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
  1343. phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
  1344. phba->fcoe_eventtag);
  1345. spin_lock_irq(&phba->hbalock);
  1346. phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
  1347. spin_unlock_irq(&phba->hbalock);
  1348. if (phba->link_state >= LPFC_LINK_UP) {
  1349. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  1350. "2780 Restart FCF table scan due to "
  1351. "pending FCF event:evt_tag_at_scan:x%x, "
  1352. "evt_tag_current:x%x\n",
  1353. phba->fcoe_eventtag_at_fcf_scan,
  1354. phba->fcoe_eventtag);
  1355. lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  1356. } else {
  1357. /*
  1358. * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS
  1359. * flag
  1360. */
  1361. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  1362. "2833 Stop FCF discovery process due to link "
  1363. "state change (x%x)\n", phba->link_state);
  1364. spin_lock_irq(&phba->hbalock);
  1365. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1366. phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
  1367. spin_unlock_irq(&phba->hbalock);
  1368. }
  1369. /* Unregister the currently registered FCF if required */
  1370. if (unreg_fcf) {
  1371. spin_lock_irq(&phba->hbalock);
  1372. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  1373. spin_unlock_irq(&phba->hbalock);
  1374. lpfc_sli4_unregister_fcf(phba);
  1375. }
  1376. return 1;
  1377. }
  1378. /**
  1379. * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
  1380. * @phba: pointer to lpfc hba data structure.
  1381. * @fcf_cnt: number of eligible fcf record seen so far.
  1382. *
  1383. * This function makes an running random selection decision on FCF record to
  1384. * use through a sequence of @fcf_cnt eligible FCF records with equal
  1385. * probability. To perform integer manunipulation of random numbers with
  1386. * size unit32_t, the lower 16 bits of the 32-bit random number returned
  1387. * from random32() are taken as the random random number generated.
  1388. *
  1389. * Returns true when outcome is for the newly read FCF record should be
  1390. * chosen; otherwise, return false when outcome is for keeping the previously
  1391. * chosen FCF record.
  1392. **/
  1393. static bool
  1394. lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
  1395. {
  1396. uint32_t rand_num;
  1397. /* Get 16-bit uniform random number */
  1398. rand_num = (0xFFFF & random32());
  1399. /* Decision with probability 1/fcf_cnt */
  1400. if ((fcf_cnt * rand_num) < 0xFFFF)
  1401. return true;
  1402. else
  1403. return false;
  1404. }
  1405. /**
  1406. * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
  1407. * @phba: pointer to lpfc hba data structure.
  1408. * @mboxq: pointer to mailbox object.
  1409. * @next_fcf_index: pointer to holder of next fcf index.
  1410. *
  1411. * This routine parses the non-embedded fcf mailbox command by performing the
  1412. * necessarily error checking, non-embedded read FCF record mailbox command
  1413. * SGE parsing, and endianness swapping.
  1414. *
  1415. * Returns the pointer to the new FCF record in the non-embedded mailbox
  1416. * command DMA memory if successfully, other NULL.
  1417. */
  1418. static struct fcf_record *
  1419. lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  1420. uint16_t *next_fcf_index)
  1421. {
  1422. void *virt_addr;
  1423. dma_addr_t phys_addr;
  1424. struct lpfc_mbx_sge sge;
  1425. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  1426. uint32_t shdr_status, shdr_add_status;
  1427. union lpfc_sli4_cfg_shdr *shdr;
  1428. struct fcf_record *new_fcf_record;
  1429. /* Get the first SGE entry from the non-embedded DMA memory. This
  1430. * routine only uses a single SGE.
  1431. */
  1432. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  1433. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  1434. if (unlikely(!mboxq->sge_array)) {
  1435. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1436. "2524 Failed to get the non-embedded SGE "
  1437. "virtual address\n");
  1438. return NULL;
  1439. }
  1440. virt_addr = mboxq->sge_array->addr[0];
  1441. shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
  1442. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  1443. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  1444. if (shdr_status || shdr_add_status) {
  1445. if (shdr_status == STATUS_FCF_TABLE_EMPTY)
  1446. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1447. "2726 READ_FCF_RECORD Indicates empty "
  1448. "FCF table.\n");
  1449. else
  1450. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1451. "2521 READ_FCF_RECORD mailbox failed "
  1452. "with status x%x add_status x%x, "
  1453. "mbx\n", shdr_status, shdr_add_status);
  1454. return NULL;
  1455. }
  1456. /* Interpreting the returned information of the FCF record */
  1457. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  1458. lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
  1459. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1460. *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
  1461. new_fcf_record = (struct fcf_record *)(virt_addr +
  1462. sizeof(struct lpfc_mbx_read_fcf_tbl));
  1463. lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
  1464. offsetof(struct fcf_record, vlan_bitmap));
  1465. new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
  1466. new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
  1467. return new_fcf_record;
  1468. }
  1469. /**
  1470. * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
  1471. * @phba: pointer to lpfc hba data structure.
  1472. * @fcf_record: pointer to the fcf record.
  1473. * @vlan_id: the lowest vlan identifier associated to this fcf record.
  1474. * @next_fcf_index: the index to the next fcf record in hba's fcf table.
  1475. *
  1476. * This routine logs the detailed FCF record if the LOG_FIP loggin is
  1477. * enabled.
  1478. **/
  1479. static void
  1480. lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
  1481. struct fcf_record *fcf_record,
  1482. uint16_t vlan_id,
  1483. uint16_t next_fcf_index)
  1484. {
  1485. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1486. "2764 READ_FCF_RECORD:\n"
  1487. "\tFCF_Index : x%x\n"
  1488. "\tFCF_Avail : x%x\n"
  1489. "\tFCF_Valid : x%x\n"
  1490. "\tFIP_Priority : x%x\n"
  1491. "\tMAC_Provider : x%x\n"
  1492. "\tLowest VLANID : x%x\n"
  1493. "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
  1494. "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
  1495. "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
  1496. "\tNext_FCF_Index: x%x\n",
  1497. bf_get(lpfc_fcf_record_fcf_index, fcf_record),
  1498. bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
  1499. bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
  1500. fcf_record->fip_priority,
  1501. bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
  1502. vlan_id,
  1503. bf_get(lpfc_fcf_record_mac_0, fcf_record),
  1504. bf_get(lpfc_fcf_record_mac_1, fcf_record),
  1505. bf_get(lpfc_fcf_record_mac_2, fcf_record),
  1506. bf_get(lpfc_fcf_record_mac_3, fcf_record),
  1507. bf_get(lpfc_fcf_record_mac_4, fcf_record),
  1508. bf_get(lpfc_fcf_record_mac_5, fcf_record),
  1509. bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
  1510. bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
  1511. bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
  1512. bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
  1513. bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
  1514. bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
  1515. bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
  1516. bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
  1517. bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
  1518. bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
  1519. bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
  1520. bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
  1521. bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
  1522. bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
  1523. bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
  1524. bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
  1525. next_fcf_index);
  1526. }
  1527. /**
  1528. lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
  1529. * @phba: pointer to lpfc hba data structure.
  1530. * @fcf_rec: pointer to an existing FCF record.
  1531. * @new_fcf_record: pointer to a new FCF record.
  1532. * @new_vlan_id: vlan id from the new FCF record.
  1533. *
  1534. * This function performs matching test of a new FCF record against an existing
  1535. * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
  1536. * will not be used as part of the FCF record matching criteria.
  1537. *
  1538. * Returns true if all the fields matching, otherwise returns false.
  1539. */
  1540. static bool
  1541. lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
  1542. struct lpfc_fcf_rec *fcf_rec,
  1543. struct fcf_record *new_fcf_record,
  1544. uint16_t new_vlan_id)
  1545. {
  1546. if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
  1547. if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
  1548. return false;
  1549. if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
  1550. return false;
  1551. if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
  1552. return false;
  1553. if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
  1554. return false;
  1555. return true;
  1556. }
  1557. /**
  1558. * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
  1559. * @phba: pointer to lpfc hba data structure.
  1560. * @mboxq: pointer to mailbox object.
  1561. *
  1562. * This function iterates through all the fcf records available in
  1563. * HBA and chooses the optimal FCF record for discovery. After finding
  1564. * the FCF for discovery it registers the FCF record and kicks start
  1565. * discovery.
  1566. * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
  1567. * use an FCF record which matches fabric name and mac address of the
  1568. * currently used FCF record.
  1569. * If the driver supports only one FCF, it will try to use the FCF record
  1570. * used by BOOT_BIOS.
  1571. */
  1572. void
  1573. lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1574. {
  1575. struct fcf_record *new_fcf_record;
  1576. uint32_t boot_flag, addr_mode;
  1577. uint16_t fcf_index, next_fcf_index;
  1578. struct lpfc_fcf_rec *fcf_rec = NULL;
  1579. uint16_t vlan_id;
  1580. uint32_t seed;
  1581. bool select_new_fcf;
  1582. int rc;
  1583. /* If there is pending FCoE event restart FCF table scan */
  1584. if (lpfc_check_pending_fcoe_event(phba, 0)) {
  1585. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1586. return;
  1587. }
  1588. /* Parse the FCF record from the non-embedded mailbox command */
  1589. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  1590. &next_fcf_index);
  1591. if (!new_fcf_record) {
  1592. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  1593. "2765 Mailbox command READ_FCF_RECORD "
  1594. "failed to retrieve a FCF record.\n");
  1595. /* Let next new FCF event trigger fast failover */
  1596. spin_lock_irq(&phba->hbalock);
  1597. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1598. spin_unlock_irq(&phba->hbalock);
  1599. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1600. return;
  1601. }
  1602. /* Check the FCF record against the connection list */
  1603. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  1604. &addr_mode, &vlan_id);
  1605. /* Log the FCF record information if turned on */
  1606. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  1607. next_fcf_index);
  1608. /*
  1609. * If the fcf record does not match with connect list entries
  1610. * read the next entry; otherwise, this is an eligible FCF
  1611. * record for round robin FCF failover.
  1612. */
  1613. if (!rc) {
  1614. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  1615. "2781 FCF record (x%x) failed FCF "
  1616. "connection list check, fcf_avail:x%x, "
  1617. "fcf_valid:x%x\n",
  1618. bf_get(lpfc_fcf_record_fcf_index,
  1619. new_fcf_record),
  1620. bf_get(lpfc_fcf_record_fcf_avail,
  1621. new_fcf_record),
  1622. bf_get(lpfc_fcf_record_fcf_valid,
  1623. new_fcf_record));
  1624. if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
  1625. lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
  1626. new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
  1627. if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
  1628. phba->fcf.current_rec.fcf_indx) {
  1629. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1630. "2862 FCF (x%x) matches property "
  1631. "of in-use FCF (x%x)\n",
  1632. bf_get(lpfc_fcf_record_fcf_index,
  1633. new_fcf_record),
  1634. phba->fcf.current_rec.fcf_indx);
  1635. goto read_next_fcf;
  1636. }
  1637. /*
  1638. * In case the current in-use FCF record becomes
  1639. * invalid/unavailable during FCF discovery that
  1640. * was not triggered by fast FCF failover process,
  1641. * treat it as fast FCF failover.
  1642. */
  1643. if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
  1644. !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
  1645. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  1646. "2835 Invalid in-use FCF "
  1647. "record (x%x) reported, "
  1648. "entering fast FCF failover "
  1649. "mode scanning.\n",
  1650. phba->fcf.current_rec.fcf_indx);
  1651. spin_lock_irq(&phba->hbalock);
  1652. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  1653. spin_unlock_irq(&phba->hbalock);
  1654. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1655. lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  1656. LPFC_FCOE_FCF_GET_FIRST);
  1657. return;
  1658. }
  1659. }
  1660. goto read_next_fcf;
  1661. } else {
  1662. fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  1663. rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
  1664. if (rc)
  1665. goto read_next_fcf;
  1666. }
  1667. /*
  1668. * If this is not the first FCF discovery of the HBA, use last
  1669. * FCF record for the discovery. The condition that a rescan
  1670. * matches the in-use FCF record: fabric name, switch name, mac
  1671. * address, and vlan_id.
  1672. */
  1673. spin_lock_irq(&phba->hbalock);
  1674. if (phba->fcf.fcf_flag & FCF_IN_USE) {
  1675. if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
  1676. new_fcf_record, vlan_id)) {
  1677. if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
  1678. phba->fcf.current_rec.fcf_indx) {
  1679. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  1680. if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
  1681. /* Stop FCF redisc wait timer */
  1682. __lpfc_sli4_stop_fcf_redisc_wait_timer(
  1683. phba);
  1684. else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
  1685. /* Fast failover, mark completed */
  1686. phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
  1687. spin_unlock_irq(&phba->hbalock);
  1688. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1689. "2836 New FCF matches in-use "
  1690. "FCF (x%x)\n",
  1691. phba->fcf.current_rec.fcf_indx);
  1692. goto out;
  1693. } else
  1694. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  1695. "2863 New FCF (x%x) matches "
  1696. "property of in-use FCF (x%x)\n",
  1697. bf_get(lpfc_fcf_record_fcf_index,
  1698. new_fcf_record),
  1699. phba->fcf.current_rec.fcf_indx);
  1700. }
  1701. /*
  1702. * Read next FCF record from HBA searching for the matching
  1703. * with in-use record only if not during the fast failover
  1704. * period. In case of fast failover period, it shall try to
  1705. * determine whether the FCF record just read should be the
  1706. * next candidate.
  1707. */
  1708. if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
  1709. spin_unlock_irq(&phba->hbalock);
  1710. goto read_next_fcf;
  1711. }
  1712. }
  1713. /*
  1714. * Update on failover FCF record only if it's in FCF fast-failover
  1715. * period; otherwise, update on current FCF record.
  1716. */
  1717. if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
  1718. fcf_rec = &phba->fcf.failover_rec;
  1719. else
  1720. fcf_rec = &phba->fcf.current_rec;
  1721. if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
  1722. /*
  1723. * If the driver FCF record does not have boot flag
  1724. * set and new hba fcf record has boot flag set, use
  1725. * the new hba fcf record.
  1726. */
  1727. if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
  1728. /* Choose this FCF record */
  1729. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1730. "2837 Update current FCF record "
  1731. "(x%x) with new FCF record (x%x)\n",
  1732. fcf_rec->fcf_indx,
  1733. bf_get(lpfc_fcf_record_fcf_index,
  1734. new_fcf_record));
  1735. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  1736. addr_mode, vlan_id, BOOT_ENABLE);
  1737. spin_unlock_irq(&phba->hbalock);
  1738. goto read_next_fcf;
  1739. }
  1740. /*
  1741. * If the driver FCF record has boot flag set and the
  1742. * new hba FCF record does not have boot flag, read
  1743. * the next FCF record.
  1744. */
  1745. if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
  1746. spin_unlock_irq(&phba->hbalock);
  1747. goto read_next_fcf;
  1748. }
  1749. /*
  1750. * If the new hba FCF record has lower priority value
  1751. * than the driver FCF record, use the new record.
  1752. */
  1753. if (new_fcf_record->fip_priority < fcf_rec->priority) {
  1754. /* Choose the new FCF record with lower priority */
  1755. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1756. "2838 Update current FCF record "
  1757. "(x%x) with new FCF record (x%x)\n",
  1758. fcf_rec->fcf_indx,
  1759. bf_get(lpfc_fcf_record_fcf_index,
  1760. new_fcf_record));
  1761. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  1762. addr_mode, vlan_id, 0);
  1763. /* Reset running random FCF selection count */
  1764. phba->fcf.eligible_fcf_cnt = 1;
  1765. } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
  1766. /* Update running random FCF selection count */
  1767. phba->fcf.eligible_fcf_cnt++;
  1768. select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
  1769. phba->fcf.eligible_fcf_cnt);
  1770. if (select_new_fcf) {
  1771. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1772. "2839 Update current FCF record "
  1773. "(x%x) with new FCF record (x%x)\n",
  1774. fcf_rec->fcf_indx,
  1775. bf_get(lpfc_fcf_record_fcf_index,
  1776. new_fcf_record));
  1777. /* Choose the new FCF by random selection */
  1778. __lpfc_update_fcf_record(phba, fcf_rec,
  1779. new_fcf_record,
  1780. addr_mode, vlan_id, 0);
  1781. }
  1782. }
  1783. spin_unlock_irq(&phba->hbalock);
  1784. goto read_next_fcf;
  1785. }
  1786. /*
  1787. * This is the first suitable FCF record, choose this record for
  1788. * initial best-fit FCF.
  1789. */
  1790. if (fcf_rec) {
  1791. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1792. "2840 Update current FCF record "
  1793. "with initial FCF record (x%x)\n",
  1794. bf_get(lpfc_fcf_record_fcf_index,
  1795. new_fcf_record));
  1796. __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
  1797. addr_mode, vlan_id, (boot_flag ?
  1798. BOOT_ENABLE : 0));
  1799. phba->fcf.fcf_flag |= FCF_AVAILABLE;
  1800. /* Setup initial running random FCF selection count */
  1801. phba->fcf.eligible_fcf_cnt = 1;
  1802. /* Seeding the random number generator for random selection */
  1803. seed = (uint32_t)(0xFFFFFFFF & jiffies);
  1804. srandom32(seed);
  1805. }
  1806. spin_unlock_irq(&phba->hbalock);
  1807. goto read_next_fcf;
  1808. read_next_fcf:
  1809. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1810. if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
  1811. if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
  1812. /*
  1813. * Case of FCF fast failover scan
  1814. */
  1815. /*
  1816. * It has not found any suitable FCF record, cancel
  1817. * FCF scan inprogress, and do nothing
  1818. */
  1819. if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
  1820. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  1821. "2782 No suitable FCF record "
  1822. "found during this round of "
  1823. "post FCF rediscovery scan: "
  1824. "fcf_evt_tag:x%x, fcf_index: "
  1825. "x%x\n",
  1826. phba->fcoe_eventtag_at_fcf_scan,
  1827. bf_get(lpfc_fcf_record_fcf_index,
  1828. new_fcf_record));
  1829. /*
  1830. * Let next new FCF event trigger fast
  1831. * failover
  1832. */
  1833. spin_lock_irq(&phba->hbalock);
  1834. phba->hba_flag &= ~FCF_DISC_INPROGRESS;
  1835. spin_unlock_irq(&phba->hbalock);
  1836. return;
  1837. }
  1838. /*
  1839. * It has found a suitable FCF record that is not
  1840. * the same as in-use FCF record, unregister the
  1841. * in-use FCF record, replace the in-use FCF record
  1842. * with the new FCF record, mark FCF fast failover
  1843. * completed, and then start register the new FCF
  1844. * record.
  1845. */
  1846. /* Unregister the current in-use FCF record */
  1847. lpfc_unregister_fcf(phba);
  1848. /* Replace in-use record with the new record */
  1849. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1850. "2842 Replace the current in-use "
  1851. "FCF record (x%x) with failover FCF "
  1852. "record (x%x)\n",
  1853. phba->fcf.current_rec.fcf_indx,
  1854. phba->fcf.failover_rec.fcf_indx);
  1855. memcpy(&phba->fcf.current_rec,
  1856. &phba->fcf.failover_rec,
  1857. sizeof(struct lpfc_fcf_rec));
  1858. /*
  1859. * Mark the fast FCF failover rediscovery completed
  1860. * and the start of the first round of the roundrobin
  1861. * FCF failover.
  1862. */
  1863. spin_lock_irq(&phba->hbalock);
  1864. phba->fcf.fcf_flag &=
  1865. ~(FCF_REDISC_FOV | FCF_REDISC_RRU);
  1866. spin_unlock_irq(&phba->hbalock);
  1867. /*
  1868. * Set up the initial registered FCF index for FLOGI
  1869. * round robin FCF failover.
  1870. */
  1871. phba->fcf.fcf_rr_init_indx =
  1872. phba->fcf.failover_rec.fcf_indx;
  1873. /* Register to the new FCF record */
  1874. lpfc_register_fcf(phba);
  1875. } else {
  1876. /*
  1877. * In case of transaction period to fast FCF failover,
  1878. * do nothing when search to the end of the FCF table.
  1879. */
  1880. if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
  1881. (phba->fcf.fcf_flag & FCF_REDISC_PEND))
  1882. return;
  1883. if (phba->fcf.fcf_flag & FCF_IN_USE) {
  1884. /*
  1885. * In case the current in-use FCF record no
  1886. * longer existed during FCF discovery that
  1887. * was not triggered by fast FCF failover
  1888. * process, treat it as fast FCF failover.
  1889. */
  1890. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1891. "2841 In-use FCF record (x%x) "
  1892. "not reported, entering fast "
  1893. "FCF failover mode scanning.\n",
  1894. phba->fcf.current_rec.fcf_indx);
  1895. spin_lock_irq(&phba->hbalock);
  1896. phba->fcf.fcf_flag |= FCF_REDISC_FOV;
  1897. spin_unlock_irq(&phba->hbalock);
  1898. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1899. lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  1900. LPFC_FCOE_FCF_GET_FIRST);
  1901. return;
  1902. }
  1903. /* Register to the new FCF record */
  1904. lpfc_register_fcf(phba);
  1905. }
  1906. } else
  1907. lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
  1908. return;
  1909. out:
  1910. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1911. lpfc_register_fcf(phba);
  1912. return;
  1913. }
  1914. /**
  1915. * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf round robin read_fcf mbox cmpl hdler
  1916. * @phba: pointer to lpfc hba data structure.
  1917. * @mboxq: pointer to mailbox object.
  1918. *
  1919. * This is the callback function for FLOGI failure round robin FCF failover
  1920. * read FCF record mailbox command from the eligible FCF record bmask for
  1921. * performing the failover. If the FCF read back is not valid/available, it
  1922. * fails through to retrying FLOGI to the currently registered FCF again.
  1923. * Otherwise, if the FCF read back is valid and available, it will set the
  1924. * newly read FCF record to the failover FCF record, unregister currently
  1925. * registered FCF record, copy the failover FCF record to the current
  1926. * FCF record, and then register the current FCF record before proceeding
  1927. * to trying FLOGI on the new failover FCF.
  1928. */
  1929. void
  1930. lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1931. {
  1932. struct fcf_record *new_fcf_record;
  1933. uint32_t boot_flag, addr_mode;
  1934. uint16_t next_fcf_index;
  1935. uint16_t current_fcf_index;
  1936. uint16_t vlan_id;
  1937. /* If link state is not up, stop the round robin failover process */
  1938. if (phba->link_state < LPFC_LINK_UP) {
  1939. spin_lock_irq(&phba->hbalock);
  1940. phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
  1941. spin_unlock_irq(&phba->hbalock);
  1942. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1943. return;
  1944. }
  1945. /* Parse the FCF record from the non-embedded mailbox command */
  1946. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  1947. &next_fcf_index);
  1948. if (!new_fcf_record) {
  1949. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  1950. "2766 Mailbox command READ_FCF_RECORD "
  1951. "failed to retrieve a FCF record.\n");
  1952. goto out;
  1953. }
  1954. /* Get the needed parameters from FCF record */
  1955. lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  1956. &addr_mode, &vlan_id);
  1957. /* Log the FCF record information if turned on */
  1958. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  1959. next_fcf_index);
  1960. /* Upload new FCF record to the failover FCF record */
  1961. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1962. "2834 Update the current FCF record (x%x) "
  1963. "with the next FCF record (x%x)\n",
  1964. phba->fcf.failover_rec.fcf_indx,
  1965. bf_get(lpfc_fcf_record_fcf_index, new_fcf_record));
  1966. spin_lock_irq(&phba->hbalock);
  1967. __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
  1968. new_fcf_record, addr_mode, vlan_id,
  1969. (boot_flag ? BOOT_ENABLE : 0));
  1970. spin_unlock_irq(&phba->hbalock);
  1971. current_fcf_index = phba->fcf.current_rec.fcf_indx;
  1972. /* Unregister the current in-use FCF record */
  1973. lpfc_unregister_fcf(phba);
  1974. /* Replace in-use record with the new record */
  1975. memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
  1976. sizeof(struct lpfc_fcf_rec));
  1977. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  1978. "2783 FLOGI round robin FCF failover from FCF "
  1979. "(x%x) to FCF (x%x).\n",
  1980. current_fcf_index,
  1981. bf_get(lpfc_fcf_record_fcf_index, new_fcf_record));
  1982. out:
  1983. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  1984. lpfc_register_fcf(phba);
  1985. }
  1986. /**
  1987. * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
  1988. * @phba: pointer to lpfc hba data structure.
  1989. * @mboxq: pointer to mailbox object.
  1990. *
  1991. * This is the callback function of read FCF record mailbox command for
  1992. * updating the eligible FCF bmask for FLOGI failure round robin FCF
  1993. * failover when a new FCF event happened. If the FCF read back is
  1994. * valid/available and it passes the connection list check, it updates
  1995. * the bmask for the eligible FCF record for round robin failover.
  1996. */
  1997. void
  1998. lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1999. {
  2000. struct fcf_record *new_fcf_record;
  2001. uint32_t boot_flag, addr_mode;
  2002. uint16_t fcf_index, next_fcf_index;
  2003. uint16_t vlan_id;
  2004. int rc;
  2005. /* If link state is not up, no need to proceed */
  2006. if (phba->link_state < LPFC_LINK_UP)
  2007. goto out;
  2008. /* If FCF discovery period is over, no need to proceed */
  2009. if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
  2010. goto out;
  2011. /* Parse the FCF record from the non-embedded mailbox command */
  2012. new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
  2013. &next_fcf_index);
  2014. if (!new_fcf_record) {
  2015. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  2016. "2767 Mailbox command READ_FCF_RECORD "
  2017. "failed to retrieve a FCF record.\n");
  2018. goto out;
  2019. }
  2020. /* Check the connection list for eligibility */
  2021. rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
  2022. &addr_mode, &vlan_id);
  2023. /* Log the FCF record information if turned on */
  2024. lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
  2025. next_fcf_index);
  2026. if (!rc)
  2027. goto out;
  2028. /* Update the eligible FCF record index bmask */
  2029. fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
  2030. rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
  2031. out:
  2032. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  2033. }
  2034. /**
  2035. * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
  2036. * @phba: pointer to lpfc hba data structure.
  2037. * @mboxq: pointer to mailbox data structure.
  2038. *
  2039. * This function handles completion of init vpi mailbox command.
  2040. */
  2041. void
  2042. lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2043. {
  2044. struct lpfc_vport *vport = mboxq->vport;
  2045. struct lpfc_nodelist *ndlp;
  2046. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2047. if (mboxq->u.mb.mbxStatus) {
  2048. lpfc_printf_vlog(vport, KERN_ERR,
  2049. LOG_MBOX,
  2050. "2609 Init VPI mailbox failed 0x%x\n",
  2051. mboxq->u.mb.mbxStatus);
  2052. mempool_free(mboxq, phba->mbox_mem_pool);
  2053. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2054. return;
  2055. }
  2056. spin_lock_irq(shost->host_lock);
  2057. vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
  2058. spin_unlock_irq(shost->host_lock);
  2059. /* If this port is physical port or FDISC is done, do reg_vpi */
  2060. if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
  2061. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  2062. if (!ndlp)
  2063. lpfc_printf_vlog(vport, KERN_ERR,
  2064. LOG_DISCOVERY,
  2065. "2731 Cannot find fabric "
  2066. "controller node\n");
  2067. else
  2068. lpfc_register_new_vport(phba, vport, ndlp);
  2069. mempool_free(mboxq, phba->mbox_mem_pool);
  2070. return;
  2071. }
  2072. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  2073. lpfc_initial_fdisc(vport);
  2074. else {
  2075. lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
  2076. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2077. "2606 No NPIV Fabric support\n");
  2078. }
  2079. mempool_free(mboxq, phba->mbox_mem_pool);
  2080. return;
  2081. }
  2082. /**
  2083. * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
  2084. * @vport: pointer to lpfc_vport data structure.
  2085. *
  2086. * This function issue a init_vpi mailbox command to initialize
  2087. * VPI for the vport.
  2088. */
  2089. void
  2090. lpfc_issue_init_vpi(struct lpfc_vport *vport)
  2091. {
  2092. LPFC_MBOXQ_t *mboxq;
  2093. int rc;
  2094. mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
  2095. if (!mboxq) {
  2096. lpfc_printf_vlog(vport, KERN_ERR,
  2097. LOG_MBOX, "2607 Failed to allocate "
  2098. "init_vpi mailbox\n");
  2099. return;
  2100. }
  2101. lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
  2102. mboxq->vport = vport;
  2103. mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
  2104. rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
  2105. if (rc == MBX_NOT_FINISHED) {
  2106. lpfc_printf_vlog(vport, KERN_ERR,
  2107. LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
  2108. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  2109. }
  2110. }
  2111. /**
  2112. * lpfc_start_fdiscs - send fdiscs for each vports on this port.
  2113. * @phba: pointer to lpfc hba data structure.
  2114. *
  2115. * This function loops through the list of vports on the @phba and issues an
  2116. * FDISC if possible.
  2117. */
  2118. void
  2119. lpfc_start_fdiscs(struct lpfc_hba *phba)
  2120. {
  2121. struct lpfc_vport **vports;
  2122. int i;
  2123. vports = lpfc_create_vport_work_array(phba);
  2124. if (vports != NULL) {
  2125. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  2126. if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
  2127. continue;
  2128. /* There are no vpi for this vport */
  2129. if (vports[i]->vpi > phba->max_vpi) {
  2130. lpfc_vport_set_state(vports[i],
  2131. FC_VPORT_FAILED);
  2132. continue;
  2133. }
  2134. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2135. lpfc_vport_set_state(vports[i],
  2136. FC_VPORT_LINKDOWN);
  2137. continue;
  2138. }
  2139. if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
  2140. lpfc_issue_init_vpi(vports[i]);
  2141. continue;
  2142. }
  2143. if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
  2144. lpfc_initial_fdisc(vports[i]);
  2145. else {
  2146. lpfc_vport_set_state(vports[i],
  2147. FC_VPORT_NO_FABRIC_SUPP);
  2148. lpfc_printf_vlog(vports[i], KERN_ERR,
  2149. LOG_ELS,
  2150. "0259 No NPIV "
  2151. "Fabric support\n");
  2152. }
  2153. }
  2154. }
  2155. lpfc_destroy_vport_work_array(phba, vports);
  2156. }
  2157. void
  2158. lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2159. {
  2160. struct lpfc_dmabuf *dmabuf = mboxq->context1;
  2161. struct lpfc_vport *vport = mboxq->vport;
  2162. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2163. if (mboxq->u.mb.mbxStatus) {
  2164. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2165. "2018 REG_VFI mbxStatus error x%x "
  2166. "HBA state x%x\n",
  2167. mboxq->u.mb.mbxStatus, vport->port_state);
  2168. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2169. /* FLOGI failed, use loop map to make discovery list */
  2170. lpfc_disc_list_loopmap(vport);
  2171. /* Start discovery */
  2172. lpfc_disc_start(vport);
  2173. goto fail_free_mem;
  2174. }
  2175. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2176. goto fail_free_mem;
  2177. }
  2178. /* The VPI is implicitly registered when the VFI is registered */
  2179. spin_lock_irq(shost->host_lock);
  2180. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2181. vport->fc_flag |= FC_VFI_REGISTERED;
  2182. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2183. spin_unlock_irq(shost->host_lock);
  2184. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  2185. lpfc_start_fdiscs(phba);
  2186. lpfc_do_scr_ns_plogi(phba, vport);
  2187. }
  2188. fail_free_mem:
  2189. mempool_free(mboxq, phba->mbox_mem_pool);
  2190. lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
  2191. kfree(dmabuf);
  2192. return;
  2193. }
  2194. static void
  2195. lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2196. {
  2197. MAILBOX_t *mb = &pmb->u.mb;
  2198. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
  2199. struct lpfc_vport *vport = pmb->vport;
  2200. /* Check for error */
  2201. if (mb->mbxStatus) {
  2202. /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
  2203. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2204. "0319 READ_SPARAM mbxStatus error x%x "
  2205. "hba state x%x>\n",
  2206. mb->mbxStatus, vport->port_state);
  2207. lpfc_linkdown(phba);
  2208. goto out;
  2209. }
  2210. memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
  2211. sizeof (struct serv_parm));
  2212. if (phba->cfg_soft_wwnn)
  2213. u64_to_wwn(phba->cfg_soft_wwnn,
  2214. vport->fc_sparam.nodeName.u.wwn);
  2215. if (phba->cfg_soft_wwpn)
  2216. u64_to_wwn(phba->cfg_soft_wwpn,
  2217. vport->fc_sparam.portName.u.wwn);
  2218. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  2219. sizeof(vport->fc_nodename));
  2220. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  2221. sizeof(vport->fc_portname));
  2222. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  2223. memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
  2224. memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
  2225. }
  2226. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2227. kfree(mp);
  2228. mempool_free(pmb, phba->mbox_mem_pool);
  2229. return;
  2230. out:
  2231. pmb->context1 = NULL;
  2232. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2233. kfree(mp);
  2234. lpfc_issue_clear_la(phba, vport);
  2235. mempool_free(pmb, phba->mbox_mem_pool);
  2236. return;
  2237. }
  2238. static void
  2239. lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
  2240. {
  2241. struct lpfc_vport *vport = phba->pport;
  2242. LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
  2243. int i;
  2244. struct lpfc_dmabuf *mp;
  2245. int rc;
  2246. struct fcf_record *fcf_record;
  2247. spin_lock_irq(&phba->hbalock);
  2248. switch (la->UlnkSpeed) {
  2249. case LA_1GHZ_LINK:
  2250. phba->fc_linkspeed = LA_1GHZ_LINK;
  2251. break;
  2252. case LA_2GHZ_LINK:
  2253. phba->fc_linkspeed = LA_2GHZ_LINK;
  2254. break;
  2255. case LA_4GHZ_LINK:
  2256. phba->fc_linkspeed = LA_4GHZ_LINK;
  2257. break;
  2258. case LA_8GHZ_LINK:
  2259. phba->fc_linkspeed = LA_8GHZ_LINK;
  2260. break;
  2261. case LA_10GHZ_LINK:
  2262. phba->fc_linkspeed = LA_10GHZ_LINK;
  2263. break;
  2264. default:
  2265. phba->fc_linkspeed = LA_UNKNW_LINK;
  2266. break;
  2267. }
  2268. phba->fc_topology = la->topology;
  2269. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  2270. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2271. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  2272. /* if npiv is enabled and this adapter supports npiv log
  2273. * a message that npiv is not supported in this topology
  2274. */
  2275. if (phba->cfg_enable_npiv && phba->max_vpi)
  2276. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2277. "1309 Link Up Event npiv not supported in loop "
  2278. "topology\n");
  2279. /* Get Loop Map information */
  2280. if (la->il)
  2281. vport->fc_flag |= FC_LBIT;
  2282. vport->fc_myDID = la->granted_AL_PA;
  2283. i = la->un.lilpBde64.tus.f.bdeSize;
  2284. if (i == 0) {
  2285. phba->alpa_map[0] = 0;
  2286. } else {
  2287. if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
  2288. int numalpa, j, k;
  2289. union {
  2290. uint8_t pamap[16];
  2291. struct {
  2292. uint32_t wd1;
  2293. uint32_t wd2;
  2294. uint32_t wd3;
  2295. uint32_t wd4;
  2296. } pa;
  2297. } un;
  2298. numalpa = phba->alpa_map[0];
  2299. j = 0;
  2300. while (j < numalpa) {
  2301. memset(un.pamap, 0, 16);
  2302. for (k = 1; j < numalpa; k++) {
  2303. un.pamap[k - 1] =
  2304. phba->alpa_map[j + 1];
  2305. j++;
  2306. if (k == 16)
  2307. break;
  2308. }
  2309. /* Link Up Event ALPA map */
  2310. lpfc_printf_log(phba,
  2311. KERN_WARNING,
  2312. LOG_LINK_EVENT,
  2313. "1304 Link Up Event "
  2314. "ALPA map Data: x%x "
  2315. "x%x x%x x%x\n",
  2316. un.pa.wd1, un.pa.wd2,
  2317. un.pa.wd3, un.pa.wd4);
  2318. }
  2319. }
  2320. }
  2321. } else {
  2322. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  2323. if (phba->max_vpi && phba->cfg_enable_npiv &&
  2324. (phba->sli_rev == 3))
  2325. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  2326. }
  2327. vport->fc_myDID = phba->fc_pref_DID;
  2328. vport->fc_flag |= FC_LBIT;
  2329. }
  2330. spin_unlock_irq(&phba->hbalock);
  2331. lpfc_linkup(phba);
  2332. sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2333. if (!sparam_mbox)
  2334. goto out;
  2335. rc = lpfc_read_sparam(phba, sparam_mbox, 0);
  2336. if (rc) {
  2337. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  2338. goto out;
  2339. }
  2340. sparam_mbox->vport = vport;
  2341. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  2342. rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
  2343. if (rc == MBX_NOT_FINISHED) {
  2344. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  2345. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2346. kfree(mp);
  2347. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  2348. goto out;
  2349. }
  2350. if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  2351. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2352. if (!cfglink_mbox)
  2353. goto out;
  2354. vport->port_state = LPFC_LOCAL_CFG_LINK;
  2355. lpfc_config_link(phba, cfglink_mbox);
  2356. cfglink_mbox->vport = vport;
  2357. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  2358. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
  2359. if (rc == MBX_NOT_FINISHED) {
  2360. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  2361. goto out;
  2362. }
  2363. } else {
  2364. vport->port_state = LPFC_VPORT_UNKNOWN;
  2365. /*
  2366. * Add the driver's default FCF record at FCF index 0 now. This
  2367. * is phase 1 implementation that support FCF index 0 and driver
  2368. * defaults.
  2369. */
  2370. if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
  2371. fcf_record = kzalloc(sizeof(struct fcf_record),
  2372. GFP_KERNEL);
  2373. if (unlikely(!fcf_record)) {
  2374. lpfc_printf_log(phba, KERN_ERR,
  2375. LOG_MBOX | LOG_SLI,
  2376. "2554 Could not allocate memmory for "
  2377. "fcf record\n");
  2378. rc = -ENODEV;
  2379. goto out;
  2380. }
  2381. lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
  2382. LPFC_FCOE_FCF_DEF_INDEX);
  2383. rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
  2384. if (unlikely(rc)) {
  2385. lpfc_printf_log(phba, KERN_ERR,
  2386. LOG_MBOX | LOG_SLI,
  2387. "2013 Could not manually add FCF "
  2388. "record 0, status %d\n", rc);
  2389. rc = -ENODEV;
  2390. kfree(fcf_record);
  2391. goto out;
  2392. }
  2393. kfree(fcf_record);
  2394. }
  2395. /*
  2396. * The driver is expected to do FIP/FCF. Call the port
  2397. * and get the FCF Table.
  2398. */
  2399. spin_lock_irq(&phba->hbalock);
  2400. if (phba->hba_flag & FCF_DISC_INPROGRESS) {
  2401. spin_unlock_irq(&phba->hbalock);
  2402. return;
  2403. }
  2404. /* This is the initial FCF discovery scan */
  2405. phba->fcf.fcf_flag |= FCF_INIT_DISC;
  2406. spin_unlock_irq(&phba->hbalock);
  2407. lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
  2408. "2778 Start FCF table scan at linkup\n");
  2409. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
  2410. LPFC_FCOE_FCF_GET_FIRST);
  2411. if (rc) {
  2412. spin_lock_irq(&phba->hbalock);
  2413. phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
  2414. spin_unlock_irq(&phba->hbalock);
  2415. goto out;
  2416. }
  2417. /* Reset FCF roundrobin bmask for new discovery */
  2418. memset(phba->fcf.fcf_rr_bmask, 0,
  2419. sizeof(*phba->fcf.fcf_rr_bmask));
  2420. }
  2421. return;
  2422. out:
  2423. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2424. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2425. "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  2426. vport->port_state, sparam_mbox, cfglink_mbox);
  2427. lpfc_issue_clear_la(phba, vport);
  2428. return;
  2429. }
  2430. static void
  2431. lpfc_enable_la(struct lpfc_hba *phba)
  2432. {
  2433. uint32_t control;
  2434. struct lpfc_sli *psli = &phba->sli;
  2435. spin_lock_irq(&phba->hbalock);
  2436. psli->sli_flag |= LPFC_PROCESS_LA;
  2437. if (phba->sli_rev <= LPFC_SLI_REV3) {
  2438. control = readl(phba->HCregaddr);
  2439. control |= HC_LAINT_ENA;
  2440. writel(control, phba->HCregaddr);
  2441. readl(phba->HCregaddr); /* flush */
  2442. }
  2443. spin_unlock_irq(&phba->hbalock);
  2444. }
  2445. static void
  2446. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  2447. {
  2448. lpfc_linkdown(phba);
  2449. lpfc_enable_la(phba);
  2450. lpfc_unregister_unused_fcf(phba);
  2451. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  2452. }
  2453. /*
  2454. * This routine handles processing a READ_LA mailbox
  2455. * command upon completion. It is setup in the LPFC_MBOXQ
  2456. * as the completion routine when the command is
  2457. * handed off to the SLI layer.
  2458. */
  2459. void
  2460. lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2461. {
  2462. struct lpfc_vport *vport = pmb->vport;
  2463. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2464. READ_LA_VAR *la;
  2465. MAILBOX_t *mb = &pmb->u.mb;
  2466. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2467. /* Unblock ELS traffic */
  2468. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  2469. /* Check for error */
  2470. if (mb->mbxStatus) {
  2471. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  2472. "1307 READ_LA mbox error x%x state x%x\n",
  2473. mb->mbxStatus, vport->port_state);
  2474. lpfc_mbx_issue_link_down(phba);
  2475. phba->link_state = LPFC_HBA_ERROR;
  2476. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  2477. }
  2478. la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
  2479. memcpy(&phba->alpa_map[0], mp->virt, 128);
  2480. spin_lock_irq(shost->host_lock);
  2481. if (la->pb)
  2482. vport->fc_flag |= FC_BYPASSED_MODE;
  2483. else
  2484. vport->fc_flag &= ~FC_BYPASSED_MODE;
  2485. spin_unlock_irq(shost->host_lock);
  2486. if ((phba->fc_eventTag < la->eventTag) ||
  2487. (phba->fc_eventTag == la->eventTag)) {
  2488. phba->fc_stat.LinkMultiEvent++;
  2489. if (la->attType == AT_LINK_UP)
  2490. if (phba->fc_eventTag != 0)
  2491. lpfc_linkdown(phba);
  2492. }
  2493. phba->fc_eventTag = la->eventTag;
  2494. spin_lock_irq(&phba->hbalock);
  2495. if (la->mm)
  2496. phba->sli.sli_flag |= LPFC_MENLO_MAINT;
  2497. else
  2498. phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
  2499. spin_unlock_irq(&phba->hbalock);
  2500. phba->link_events++;
  2501. if (la->attType == AT_LINK_UP && (!la->mm)) {
  2502. phba->fc_stat.LinkUp++;
  2503. if (phba->link_flag & LS_LOOPBACK_MODE) {
  2504. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2505. "1306 Link Up Event in loop back mode "
  2506. "x%x received Data: x%x x%x x%x x%x\n",
  2507. la->eventTag, phba->fc_eventTag,
  2508. la->granted_AL_PA, la->UlnkSpeed,
  2509. phba->alpa_map[0]);
  2510. } else {
  2511. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2512. "1303 Link Up Event x%x received "
  2513. "Data: x%x x%x x%x x%x x%x x%x %d\n",
  2514. la->eventTag, phba->fc_eventTag,
  2515. la->granted_AL_PA, la->UlnkSpeed,
  2516. phba->alpa_map[0],
  2517. la->mm, la->fa,
  2518. phba->wait_4_mlo_maint_flg);
  2519. }
  2520. lpfc_mbx_process_link_up(phba, la);
  2521. } else if (la->attType == AT_LINK_DOWN) {
  2522. phba->fc_stat.LinkDown++;
  2523. if (phba->link_flag & LS_LOOPBACK_MODE) {
  2524. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2525. "1308 Link Down Event in loop back mode "
  2526. "x%x received "
  2527. "Data: x%x x%x x%x\n",
  2528. la->eventTag, phba->fc_eventTag,
  2529. phba->pport->port_state, vport->fc_flag);
  2530. }
  2531. else {
  2532. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2533. "1305 Link Down Event x%x received "
  2534. "Data: x%x x%x x%x x%x x%x\n",
  2535. la->eventTag, phba->fc_eventTag,
  2536. phba->pport->port_state, vport->fc_flag,
  2537. la->mm, la->fa);
  2538. }
  2539. lpfc_mbx_issue_link_down(phba);
  2540. }
  2541. if (la->mm && la->attType == AT_LINK_UP) {
  2542. if (phba->link_state != LPFC_LINK_DOWN) {
  2543. phba->fc_stat.LinkDown++;
  2544. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2545. "1312 Link Down Event x%x received "
  2546. "Data: x%x x%x x%x\n",
  2547. la->eventTag, phba->fc_eventTag,
  2548. phba->pport->port_state, vport->fc_flag);
  2549. lpfc_mbx_issue_link_down(phba);
  2550. } else
  2551. lpfc_enable_la(phba);
  2552. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  2553. "1310 Menlo Maint Mode Link up Event x%x rcvd "
  2554. "Data: x%x x%x x%x\n",
  2555. la->eventTag, phba->fc_eventTag,
  2556. phba->pport->port_state, vport->fc_flag);
  2557. /*
  2558. * The cmnd that triggered this will be waiting for this
  2559. * signal.
  2560. */
  2561. /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
  2562. if (phba->wait_4_mlo_maint_flg) {
  2563. phba->wait_4_mlo_maint_flg = 0;
  2564. wake_up_interruptible(&phba->wait_4_mlo_m_q);
  2565. }
  2566. }
  2567. if (la->fa) {
  2568. if (la->mm)
  2569. lpfc_issue_clear_la(phba, vport);
  2570. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  2571. "1311 fa %d\n", la->fa);
  2572. }
  2573. lpfc_mbx_cmpl_read_la_free_mbuf:
  2574. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2575. kfree(mp);
  2576. mempool_free(pmb, phba->mbox_mem_pool);
  2577. return;
  2578. }
  2579. /*
  2580. * This routine handles processing a REG_LOGIN mailbox
  2581. * command upon completion. It is setup in the LPFC_MBOXQ
  2582. * as the completion routine when the command is
  2583. * handed off to the SLI layer.
  2584. */
  2585. void
  2586. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2587. {
  2588. struct lpfc_vport *vport = pmb->vport;
  2589. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2590. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2591. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2592. pmb->context1 = NULL;
  2593. pmb->context2 = NULL;
  2594. if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
  2595. ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
  2596. if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
  2597. ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
  2598. /* We rcvd a rscn after issuing this
  2599. * mbox reg login, we may have cycled
  2600. * back through the state and be
  2601. * back at reg login state so this
  2602. * mbox needs to be ignored becase
  2603. * there is another reg login in
  2604. * proccess.
  2605. */
  2606. spin_lock_irq(shost->host_lock);
  2607. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  2608. spin_unlock_irq(shost->host_lock);
  2609. if (phba->sli_rev == LPFC_SLI_REV4)
  2610. lpfc_sli4_free_rpi(phba,
  2611. pmb->u.mb.un.varRegLogin.rpi);
  2612. } else
  2613. /* Good status, call state machine */
  2614. lpfc_disc_state_machine(vport, ndlp, pmb,
  2615. NLP_EVT_CMPL_REG_LOGIN);
  2616. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2617. kfree(mp);
  2618. mempool_free(pmb, phba->mbox_mem_pool);
  2619. /* decrement the node reference count held for this callback
  2620. * function.
  2621. */
  2622. lpfc_nlp_put(ndlp);
  2623. return;
  2624. }
  2625. static void
  2626. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2627. {
  2628. MAILBOX_t *mb = &pmb->u.mb;
  2629. struct lpfc_vport *vport = pmb->vport;
  2630. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2631. switch (mb->mbxStatus) {
  2632. case 0x0011:
  2633. case 0x0020:
  2634. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2635. "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
  2636. mb->mbxStatus);
  2637. break;
  2638. /* If VPI is busy, reset the HBA */
  2639. case 0x9700:
  2640. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  2641. "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
  2642. vport->vpi, mb->mbxStatus);
  2643. if (!(phba->pport->load_flag & FC_UNLOADING))
  2644. lpfc_workq_post_event(phba, NULL, NULL,
  2645. LPFC_EVT_RESET_HBA);
  2646. }
  2647. spin_lock_irq(shost->host_lock);
  2648. vport->vpi_state &= ~LPFC_VPI_REGISTERED;
  2649. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  2650. spin_unlock_irq(shost->host_lock);
  2651. vport->unreg_vpi_cmpl = VPORT_OK;
  2652. mempool_free(pmb, phba->mbox_mem_pool);
  2653. /*
  2654. * This shost reference might have been taken at the beginning of
  2655. * lpfc_vport_delete()
  2656. */
  2657. if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
  2658. scsi_host_put(shost);
  2659. }
  2660. int
  2661. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  2662. {
  2663. struct lpfc_hba *phba = vport->phba;
  2664. LPFC_MBOXQ_t *mbox;
  2665. int rc;
  2666. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2667. if (!mbox)
  2668. return 1;
  2669. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  2670. mbox->vport = vport;
  2671. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  2672. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2673. if (rc == MBX_NOT_FINISHED) {
  2674. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2675. "1800 Could not issue unreg_vpi\n");
  2676. mempool_free(mbox, phba->mbox_mem_pool);
  2677. vport->unreg_vpi_cmpl = VPORT_ERROR;
  2678. return rc;
  2679. }
  2680. return 0;
  2681. }
  2682. static void
  2683. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2684. {
  2685. struct lpfc_vport *vport = pmb->vport;
  2686. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2687. MAILBOX_t *mb = &pmb->u.mb;
  2688. switch (mb->mbxStatus) {
  2689. case 0x0011:
  2690. case 0x9601:
  2691. case 0x9602:
  2692. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2693. "0912 cmpl_reg_vpi, mb status = 0x%x\n",
  2694. mb->mbxStatus);
  2695. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2696. spin_lock_irq(shost->host_lock);
  2697. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2698. spin_unlock_irq(shost->host_lock);
  2699. vport->fc_myDID = 0;
  2700. goto out;
  2701. }
  2702. spin_lock_irq(shost->host_lock);
  2703. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2704. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2705. spin_unlock_irq(shost->host_lock);
  2706. vport->num_disc_nodes = 0;
  2707. /* go thru NPR list and issue ELS PLOGIs */
  2708. if (vport->fc_npr_cnt)
  2709. lpfc_els_disc_plogi(vport);
  2710. if (!vport->num_disc_nodes) {
  2711. spin_lock_irq(shost->host_lock);
  2712. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  2713. spin_unlock_irq(shost->host_lock);
  2714. lpfc_can_disctmo(vport);
  2715. }
  2716. vport->port_state = LPFC_VPORT_READY;
  2717. out:
  2718. mempool_free(pmb, phba->mbox_mem_pool);
  2719. return;
  2720. }
  2721. /**
  2722. * lpfc_create_static_vport - Read HBA config region to create static vports.
  2723. * @phba: pointer to lpfc hba data structure.
  2724. *
  2725. * This routine issue a DUMP mailbox command for config region 22 to get
  2726. * the list of static vports to be created. The function create vports
  2727. * based on the information returned from the HBA.
  2728. **/
  2729. void
  2730. lpfc_create_static_vport(struct lpfc_hba *phba)
  2731. {
  2732. LPFC_MBOXQ_t *pmb = NULL;
  2733. MAILBOX_t *mb;
  2734. struct static_vport_info *vport_info;
  2735. int rc = 0, i;
  2736. struct fc_vport_identifiers vport_id;
  2737. struct fc_vport *new_fc_vport;
  2738. struct Scsi_Host *shost;
  2739. struct lpfc_vport *vport;
  2740. uint16_t offset = 0;
  2741. uint8_t *vport_buff;
  2742. struct lpfc_dmabuf *mp;
  2743. uint32_t byte_count = 0;
  2744. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2745. if (!pmb) {
  2746. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2747. "0542 lpfc_create_static_vport failed to"
  2748. " allocate mailbox memory\n");
  2749. return;
  2750. }
  2751. mb = &pmb->u.mb;
  2752. vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
  2753. if (!vport_info) {
  2754. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2755. "0543 lpfc_create_static_vport failed to"
  2756. " allocate vport_info\n");
  2757. mempool_free(pmb, phba->mbox_mem_pool);
  2758. return;
  2759. }
  2760. vport_buff = (uint8_t *) vport_info;
  2761. do {
  2762. if (lpfc_dump_static_vport(phba, pmb, offset))
  2763. goto out;
  2764. pmb->vport = phba->pport;
  2765. rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
  2766. if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
  2767. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2768. "0544 lpfc_create_static_vport failed to"
  2769. " issue dump mailbox command ret 0x%x "
  2770. "status 0x%x\n",
  2771. rc, mb->mbxStatus);
  2772. goto out;
  2773. }
  2774. if (phba->sli_rev == LPFC_SLI_REV4) {
  2775. byte_count = pmb->u.mqe.un.mb_words[5];
  2776. mp = (struct lpfc_dmabuf *) pmb->context2;
  2777. if (byte_count > sizeof(struct static_vport_info) -
  2778. offset)
  2779. byte_count = sizeof(struct static_vport_info)
  2780. - offset;
  2781. memcpy(vport_buff + offset, mp->virt, byte_count);
  2782. offset += byte_count;
  2783. } else {
  2784. if (mb->un.varDmp.word_cnt >
  2785. sizeof(struct static_vport_info) - offset)
  2786. mb->un.varDmp.word_cnt =
  2787. sizeof(struct static_vport_info)
  2788. - offset;
  2789. byte_count = mb->un.varDmp.word_cnt;
  2790. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  2791. vport_buff + offset,
  2792. byte_count);
  2793. offset += byte_count;
  2794. }
  2795. } while (byte_count &&
  2796. offset < sizeof(struct static_vport_info));
  2797. if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
  2798. ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
  2799. != VPORT_INFO_REV)) {
  2800. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  2801. "0545 lpfc_create_static_vport bad"
  2802. " information header 0x%x 0x%x\n",
  2803. le32_to_cpu(vport_info->signature),
  2804. le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
  2805. goto out;
  2806. }
  2807. shost = lpfc_shost_from_vport(phba->pport);
  2808. for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
  2809. memset(&vport_id, 0, sizeof(vport_id));
  2810. vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
  2811. vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
  2812. if (!vport_id.port_name || !vport_id.node_name)
  2813. continue;
  2814. vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
  2815. vport_id.vport_type = FC_PORTTYPE_NPIV;
  2816. vport_id.disable = false;
  2817. new_fc_vport = fc_vport_create(shost, 0, &vport_id);
  2818. if (!new_fc_vport) {
  2819. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  2820. "0546 lpfc_create_static_vport failed to"
  2821. " create vport\n");
  2822. continue;
  2823. }
  2824. vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
  2825. vport->vport_flag |= STATIC_VPORT;
  2826. }
  2827. out:
  2828. kfree(vport_info);
  2829. if (rc != MBX_TIMEOUT) {
  2830. if (pmb->context2) {
  2831. mp = (struct lpfc_dmabuf *) pmb->context2;
  2832. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2833. kfree(mp);
  2834. }
  2835. mempool_free(pmb, phba->mbox_mem_pool);
  2836. }
  2837. return;
  2838. }
  2839. /*
  2840. * This routine handles processing a Fabric REG_LOGIN mailbox
  2841. * command upon completion. It is setup in the LPFC_MBOXQ
  2842. * as the completion routine when the command is
  2843. * handed off to the SLI layer.
  2844. */
  2845. void
  2846. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2847. {
  2848. struct lpfc_vport *vport = pmb->vport;
  2849. MAILBOX_t *mb = &pmb->u.mb;
  2850. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2851. struct lpfc_nodelist *ndlp;
  2852. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2853. pmb->context1 = NULL;
  2854. pmb->context2 = NULL;
  2855. if (mb->mbxStatus) {
  2856. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  2857. "0258 Register Fabric login error: 0x%x\n",
  2858. mb->mbxStatus);
  2859. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2860. kfree(mp);
  2861. mempool_free(pmb, phba->mbox_mem_pool);
  2862. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2863. /* FLOGI failed, use loop map to make discovery list */
  2864. lpfc_disc_list_loopmap(vport);
  2865. /* Start discovery */
  2866. lpfc_disc_start(vport);
  2867. /* Decrement the reference count to ndlp after the
  2868. * reference to the ndlp are done.
  2869. */
  2870. lpfc_nlp_put(ndlp);
  2871. return;
  2872. }
  2873. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2874. /* Decrement the reference count to ndlp after the reference
  2875. * to the ndlp are done.
  2876. */
  2877. lpfc_nlp_put(ndlp);
  2878. return;
  2879. }
  2880. ndlp->nlp_rpi = mb->un.varWords[0];
  2881. ndlp->nlp_flag |= NLP_RPI_VALID;
  2882. ndlp->nlp_type |= NLP_FABRIC;
  2883. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2884. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  2885. /* when physical port receive logo donot start
  2886. * vport discovery */
  2887. if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
  2888. lpfc_start_fdiscs(phba);
  2889. else
  2890. vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
  2891. lpfc_do_scr_ns_plogi(phba, vport);
  2892. }
  2893. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2894. kfree(mp);
  2895. mempool_free(pmb, phba->mbox_mem_pool);
  2896. /* Drop the reference count from the mbox at the end after
  2897. * all the current reference to the ndlp have been done.
  2898. */
  2899. lpfc_nlp_put(ndlp);
  2900. return;
  2901. }
  2902. /*
  2903. * This routine handles processing a NameServer REG_LOGIN mailbox
  2904. * command upon completion. It is setup in the LPFC_MBOXQ
  2905. * as the completion routine when the command is
  2906. * handed off to the SLI layer.
  2907. */
  2908. void
  2909. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2910. {
  2911. MAILBOX_t *mb = &pmb->u.mb;
  2912. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2913. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2914. struct lpfc_vport *vport = pmb->vport;
  2915. pmb->context1 = NULL;
  2916. pmb->context2 = NULL;
  2917. if (mb->mbxStatus) {
  2918. out:
  2919. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2920. "0260 Register NameServer error: 0x%x\n",
  2921. mb->mbxStatus);
  2922. /* decrement the node reference count held for this
  2923. * callback function.
  2924. */
  2925. lpfc_nlp_put(ndlp);
  2926. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2927. kfree(mp);
  2928. mempool_free(pmb, phba->mbox_mem_pool);
  2929. /* If no other thread is using the ndlp, free it */
  2930. lpfc_nlp_not_used(ndlp);
  2931. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2932. /*
  2933. * RegLogin failed, use loop map to make discovery
  2934. * list
  2935. */
  2936. lpfc_disc_list_loopmap(vport);
  2937. /* Start discovery */
  2938. lpfc_disc_start(vport);
  2939. return;
  2940. }
  2941. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2942. return;
  2943. }
  2944. ndlp->nlp_rpi = mb->un.varWords[0];
  2945. ndlp->nlp_flag |= NLP_RPI_VALID;
  2946. ndlp->nlp_type |= NLP_FABRIC;
  2947. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2948. if (vport->port_state < LPFC_VPORT_READY) {
  2949. /* Link up discovery requires Fabric registration. */
  2950. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  2951. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  2952. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  2953. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  2954. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  2955. /* Issue SCR just before NameServer GID_FT Query */
  2956. lpfc_issue_els_scr(vport, SCR_DID, 0);
  2957. }
  2958. vport->fc_ns_retry = 0;
  2959. /* Good status, issue CT Request to NameServer */
  2960. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  2961. /* Cannot issue NameServer Query, so finish up discovery */
  2962. goto out;
  2963. }
  2964. /* decrement the node reference count held for this
  2965. * callback function.
  2966. */
  2967. lpfc_nlp_put(ndlp);
  2968. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2969. kfree(mp);
  2970. mempool_free(pmb, phba->mbox_mem_pool);
  2971. return;
  2972. }
  2973. static void
  2974. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2975. {
  2976. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2977. struct fc_rport *rport;
  2978. struct lpfc_rport_data *rdata;
  2979. struct fc_rport_identifiers rport_ids;
  2980. struct lpfc_hba *phba = vport->phba;
  2981. /* Remote port has reappeared. Re-register w/ FC transport */
  2982. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  2983. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  2984. rport_ids.port_id = ndlp->nlp_DID;
  2985. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2986. /*
  2987. * We leave our node pointer in rport->dd_data when we unregister a
  2988. * FCP target port. But fc_remote_port_add zeros the space to which
  2989. * rport->dd_data points. So, if we're reusing a previously
  2990. * registered port, drop the reference that we took the last time we
  2991. * registered the port.
  2992. */
  2993. if (ndlp->rport && ndlp->rport->dd_data &&
  2994. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
  2995. lpfc_nlp_put(ndlp);
  2996. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  2997. "rport add: did:x%x flg:x%x type x%x",
  2998. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2999. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  3000. if (!rport || !get_device(&rport->dev)) {
  3001. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  3002. "Warning: fc_remote_port_add failed\n");
  3003. return;
  3004. }
  3005. /* initialize static port data */
  3006. rport->maxframe_size = ndlp->nlp_maxframe;
  3007. rport->supported_classes = ndlp->nlp_class_sup;
  3008. rdata = rport->dd_data;
  3009. rdata->pnode = lpfc_nlp_get(ndlp);
  3010. if (ndlp->nlp_type & NLP_FCP_TARGET)
  3011. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  3012. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  3013. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  3014. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  3015. fc_remote_port_rolechg(rport, rport_ids.roles);
  3016. if ((rport->scsi_target_id != -1) &&
  3017. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  3018. ndlp->nlp_sid = rport->scsi_target_id;
  3019. }
  3020. return;
  3021. }
  3022. static void
  3023. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  3024. {
  3025. struct fc_rport *rport = ndlp->rport;
  3026. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  3027. "rport delete: did:x%x flg:x%x type x%x",
  3028. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3029. fc_remote_port_delete(rport);
  3030. return;
  3031. }
  3032. static void
  3033. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  3034. {
  3035. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3036. spin_lock_irq(shost->host_lock);
  3037. switch (state) {
  3038. case NLP_STE_UNUSED_NODE:
  3039. vport->fc_unused_cnt += count;
  3040. break;
  3041. case NLP_STE_PLOGI_ISSUE:
  3042. vport->fc_plogi_cnt += count;
  3043. break;
  3044. case NLP_STE_ADISC_ISSUE:
  3045. vport->fc_adisc_cnt += count;
  3046. break;
  3047. case NLP_STE_REG_LOGIN_ISSUE:
  3048. vport->fc_reglogin_cnt += count;
  3049. break;
  3050. case NLP_STE_PRLI_ISSUE:
  3051. vport->fc_prli_cnt += count;
  3052. break;
  3053. case NLP_STE_UNMAPPED_NODE:
  3054. vport->fc_unmap_cnt += count;
  3055. break;
  3056. case NLP_STE_MAPPED_NODE:
  3057. vport->fc_map_cnt += count;
  3058. break;
  3059. case NLP_STE_NPR_NODE:
  3060. vport->fc_npr_cnt += count;
  3061. break;
  3062. }
  3063. spin_unlock_irq(shost->host_lock);
  3064. }
  3065. static void
  3066. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3067. int old_state, int new_state)
  3068. {
  3069. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3070. if (new_state == NLP_STE_UNMAPPED_NODE) {
  3071. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  3072. ndlp->nlp_type |= NLP_FC_NODE;
  3073. }
  3074. if (new_state == NLP_STE_MAPPED_NODE)
  3075. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  3076. if (new_state == NLP_STE_NPR_NODE)
  3077. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  3078. /* Transport interface */
  3079. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  3080. old_state == NLP_STE_UNMAPPED_NODE)) {
  3081. vport->phba->nport_event_cnt++;
  3082. lpfc_unregister_remote_port(ndlp);
  3083. }
  3084. if (new_state == NLP_STE_MAPPED_NODE ||
  3085. new_state == NLP_STE_UNMAPPED_NODE) {
  3086. vport->phba->nport_event_cnt++;
  3087. /*
  3088. * Tell the fc transport about the port, if we haven't
  3089. * already. If we have, and it's a scsi entity, be
  3090. * sure to unblock any attached scsi devices
  3091. */
  3092. lpfc_register_remote_port(vport, ndlp);
  3093. }
  3094. if ((new_state == NLP_STE_MAPPED_NODE) &&
  3095. (vport->stat_data_enabled)) {
  3096. /*
  3097. * A new target is discovered, if there is no buffer for
  3098. * statistical data collection allocate buffer.
  3099. */
  3100. ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
  3101. sizeof(struct lpfc_scsicmd_bkt),
  3102. GFP_KERNEL);
  3103. if (!ndlp->lat_data)
  3104. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  3105. "0286 lpfc_nlp_state_cleanup failed to "
  3106. "allocate statistical data buffer DID "
  3107. "0x%x\n", ndlp->nlp_DID);
  3108. }
  3109. /*
  3110. * if we added to Mapped list, but the remote port
  3111. * registration failed or assigned a target id outside
  3112. * our presentable range - move the node to the
  3113. * Unmapped List
  3114. */
  3115. if (new_state == NLP_STE_MAPPED_NODE &&
  3116. (!ndlp->rport ||
  3117. ndlp->rport->scsi_target_id == -1 ||
  3118. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  3119. spin_lock_irq(shost->host_lock);
  3120. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  3121. spin_unlock_irq(shost->host_lock);
  3122. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3123. }
  3124. }
  3125. static char *
  3126. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  3127. {
  3128. static char *states[] = {
  3129. [NLP_STE_UNUSED_NODE] = "UNUSED",
  3130. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  3131. [NLP_STE_ADISC_ISSUE] = "ADISC",
  3132. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  3133. [NLP_STE_PRLI_ISSUE] = "PRLI",
  3134. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  3135. [NLP_STE_MAPPED_NODE] = "MAPPED",
  3136. [NLP_STE_NPR_NODE] = "NPR",
  3137. };
  3138. if (state < NLP_STE_MAX_STATE && states[state])
  3139. strlcpy(buffer, states[state], size);
  3140. else
  3141. snprintf(buffer, size, "unknown (%d)", state);
  3142. return buffer;
  3143. }
  3144. void
  3145. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3146. int state)
  3147. {
  3148. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3149. int old_state = ndlp->nlp_state;
  3150. char name1[16], name2[16];
  3151. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3152. "0904 NPort state transition x%06x, %s -> %s\n",
  3153. ndlp->nlp_DID,
  3154. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  3155. lpfc_nlp_state_name(name2, sizeof(name2), state));
  3156. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3157. "node statechg did:x%x old:%d ste:%d",
  3158. ndlp->nlp_DID, old_state, state);
  3159. if (old_state == NLP_STE_NPR_NODE &&
  3160. state != NLP_STE_NPR_NODE)
  3161. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3162. if (old_state == NLP_STE_UNMAPPED_NODE) {
  3163. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  3164. ndlp->nlp_type &= ~NLP_FC_NODE;
  3165. }
  3166. if (list_empty(&ndlp->nlp_listp)) {
  3167. spin_lock_irq(shost->host_lock);
  3168. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  3169. spin_unlock_irq(shost->host_lock);
  3170. } else if (old_state)
  3171. lpfc_nlp_counters(vport, old_state, -1);
  3172. ndlp->nlp_state = state;
  3173. lpfc_nlp_counters(vport, state, 1);
  3174. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  3175. }
  3176. void
  3177. lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3178. {
  3179. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3180. if (list_empty(&ndlp->nlp_listp)) {
  3181. spin_lock_irq(shost->host_lock);
  3182. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  3183. spin_unlock_irq(shost->host_lock);
  3184. }
  3185. }
  3186. void
  3187. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3188. {
  3189. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3190. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3191. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  3192. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  3193. spin_lock_irq(shost->host_lock);
  3194. list_del_init(&ndlp->nlp_listp);
  3195. spin_unlock_irq(shost->host_lock);
  3196. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  3197. NLP_STE_UNUSED_NODE);
  3198. }
  3199. static void
  3200. lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3201. {
  3202. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3203. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  3204. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  3205. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  3206. NLP_STE_UNUSED_NODE);
  3207. }
  3208. /**
  3209. * lpfc_initialize_node - Initialize all fields of node object
  3210. * @vport: Pointer to Virtual Port object.
  3211. * @ndlp: Pointer to FC node object.
  3212. * @did: FC_ID of the node.
  3213. *
  3214. * This function is always called when node object need to be initialized.
  3215. * It initializes all the fields of the node object. Although the reference
  3216. * to phba from @ndlp can be obtained indirectly through it's reference to
  3217. * @vport, a direct reference to phba is taken here by @ndlp. This is due
  3218. * to the life-span of the @ndlp might go beyond the existence of @vport as
  3219. * the final release of ndlp is determined by its reference count. And, the
  3220. * operation on @ndlp needs the reference to phba.
  3221. **/
  3222. static inline void
  3223. lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3224. uint32_t did)
  3225. {
  3226. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  3227. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  3228. init_timer(&ndlp->nlp_delayfunc);
  3229. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  3230. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  3231. ndlp->nlp_DID = did;
  3232. ndlp->vport = vport;
  3233. ndlp->phba = vport->phba;
  3234. ndlp->nlp_sid = NLP_NO_SID;
  3235. kref_init(&ndlp->kref);
  3236. NLP_INT_NODE_ACT(ndlp);
  3237. atomic_set(&ndlp->cmd_pending, 0);
  3238. ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
  3239. }
  3240. struct lpfc_nodelist *
  3241. lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3242. int state)
  3243. {
  3244. struct lpfc_hba *phba = vport->phba;
  3245. uint32_t did;
  3246. unsigned long flags;
  3247. if (!ndlp)
  3248. return NULL;
  3249. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3250. /* The ndlp should not be in memory free mode */
  3251. if (NLP_CHK_FREE_REQ(ndlp)) {
  3252. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3253. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  3254. "0277 lpfc_enable_node: ndlp:x%p "
  3255. "usgmap:x%x refcnt:%d\n",
  3256. (void *)ndlp, ndlp->nlp_usg_map,
  3257. atomic_read(&ndlp->kref.refcount));
  3258. return NULL;
  3259. }
  3260. /* The ndlp should not already be in active mode */
  3261. if (NLP_CHK_NODE_ACT(ndlp)) {
  3262. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3263. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  3264. "0278 lpfc_enable_node: ndlp:x%p "
  3265. "usgmap:x%x refcnt:%d\n",
  3266. (void *)ndlp, ndlp->nlp_usg_map,
  3267. atomic_read(&ndlp->kref.refcount));
  3268. return NULL;
  3269. }
  3270. /* Keep the original DID */
  3271. did = ndlp->nlp_DID;
  3272. /* re-initialize ndlp except of ndlp linked list pointer */
  3273. memset((((char *)ndlp) + sizeof (struct list_head)), 0,
  3274. sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
  3275. lpfc_initialize_node(vport, ndlp, did);
  3276. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3277. if (state != NLP_STE_UNUSED_NODE)
  3278. lpfc_nlp_set_state(vport, ndlp, state);
  3279. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3280. "node enable: did:x%x",
  3281. ndlp->nlp_DID, 0, 0);
  3282. return ndlp;
  3283. }
  3284. void
  3285. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3286. {
  3287. /*
  3288. * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
  3289. * be used if we wish to issue the "last" lpfc_nlp_put() to remove
  3290. * the ndlp from the vport. The ndlp marked as UNUSED on the list
  3291. * until ALL other outstanding threads have completed. We check
  3292. * that the ndlp not already in the UNUSED state before we proceed.
  3293. */
  3294. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  3295. return;
  3296. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  3297. lpfc_nlp_put(ndlp);
  3298. return;
  3299. }
  3300. /*
  3301. * Start / ReStart rescue timer for Discovery / RSCN handling
  3302. */
  3303. void
  3304. lpfc_set_disctmo(struct lpfc_vport *vport)
  3305. {
  3306. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3307. struct lpfc_hba *phba = vport->phba;
  3308. uint32_t tmo;
  3309. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  3310. /* For FAN, timeout should be greater than edtov */
  3311. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  3312. } else {
  3313. /* Normal discovery timeout should be > than ELS/CT timeout
  3314. * FC spec states we need 3 * ratov for CT requests
  3315. */
  3316. tmo = ((phba->fc_ratov * 3) + 3);
  3317. }
  3318. if (!timer_pending(&vport->fc_disctmo)) {
  3319. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3320. "set disc timer: tmo:x%x state:x%x flg:x%x",
  3321. tmo, vport->port_state, vport->fc_flag);
  3322. }
  3323. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  3324. spin_lock_irq(shost->host_lock);
  3325. vport->fc_flag |= FC_DISC_TMO;
  3326. spin_unlock_irq(shost->host_lock);
  3327. /* Start Discovery Timer state <hba_state> */
  3328. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3329. "0247 Start Discovery Timer state x%x "
  3330. "Data: x%x x%lx x%x x%x\n",
  3331. vport->port_state, tmo,
  3332. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  3333. vport->fc_adisc_cnt);
  3334. return;
  3335. }
  3336. /*
  3337. * Cancel rescue timer for Discovery / RSCN handling
  3338. */
  3339. int
  3340. lpfc_can_disctmo(struct lpfc_vport *vport)
  3341. {
  3342. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3343. unsigned long iflags;
  3344. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3345. "can disc timer: state:x%x rtry:x%x flg:x%x",
  3346. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  3347. /* Turn off discovery timer if its running */
  3348. if (vport->fc_flag & FC_DISC_TMO) {
  3349. spin_lock_irqsave(shost->host_lock, iflags);
  3350. vport->fc_flag &= ~FC_DISC_TMO;
  3351. spin_unlock_irqrestore(shost->host_lock, iflags);
  3352. del_timer_sync(&vport->fc_disctmo);
  3353. spin_lock_irqsave(&vport->work_port_lock, iflags);
  3354. vport->work_port_events &= ~WORKER_DISC_TMO;
  3355. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  3356. }
  3357. /* Cancel Discovery Timer state <hba_state> */
  3358. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3359. "0248 Cancel Discovery Timer state x%x "
  3360. "Data: x%x x%x x%x\n",
  3361. vport->port_state, vport->fc_flag,
  3362. vport->fc_plogi_cnt, vport->fc_adisc_cnt);
  3363. return 0;
  3364. }
  3365. /*
  3366. * Check specified ring for outstanding IOCB on the SLI queue
  3367. * Return true if iocb matches the specified nport
  3368. */
  3369. int
  3370. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  3371. struct lpfc_sli_ring *pring,
  3372. struct lpfc_iocbq *iocb,
  3373. struct lpfc_nodelist *ndlp)
  3374. {
  3375. struct lpfc_sli *psli = &phba->sli;
  3376. IOCB_t *icmd = &iocb->iocb;
  3377. struct lpfc_vport *vport = ndlp->vport;
  3378. if (iocb->vport != vport)
  3379. return 0;
  3380. if (pring->ringno == LPFC_ELS_RING) {
  3381. switch (icmd->ulpCommand) {
  3382. case CMD_GEN_REQUEST64_CR:
  3383. if (iocb->context_un.ndlp == ndlp)
  3384. return 1;
  3385. case CMD_ELS_REQUEST64_CR:
  3386. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  3387. return 1;
  3388. case CMD_XMIT_ELS_RSP64_CX:
  3389. if (iocb->context1 == (uint8_t *) ndlp)
  3390. return 1;
  3391. }
  3392. } else if (pring->ringno == psli->extra_ring) {
  3393. } else if (pring->ringno == psli->fcp_ring) {
  3394. /* Skip match check if waiting to relogin to FCP target */
  3395. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  3396. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  3397. return 0;
  3398. }
  3399. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  3400. return 1;
  3401. }
  3402. } else if (pring->ringno == psli->next_ring) {
  3403. }
  3404. return 0;
  3405. }
  3406. /*
  3407. * Free resources / clean up outstanding I/Os
  3408. * associated with nlp_rpi in the LPFC_NODELIST entry.
  3409. */
  3410. static int
  3411. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  3412. {
  3413. LIST_HEAD(completions);
  3414. struct lpfc_sli *psli;
  3415. struct lpfc_sli_ring *pring;
  3416. struct lpfc_iocbq *iocb, *next_iocb;
  3417. uint32_t i;
  3418. lpfc_fabric_abort_nport(ndlp);
  3419. /*
  3420. * Everything that matches on txcmplq will be returned
  3421. * by firmware with a no rpi error.
  3422. */
  3423. psli = &phba->sli;
  3424. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  3425. /* Now process each ring */
  3426. for (i = 0; i < psli->num_rings; i++) {
  3427. pring = &psli->ring[i];
  3428. spin_lock_irq(&phba->hbalock);
  3429. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  3430. list) {
  3431. /*
  3432. * Check to see if iocb matches the nport we are
  3433. * looking for
  3434. */
  3435. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  3436. ndlp))) {
  3437. /* It matches, so deque and call compl
  3438. with an error */
  3439. list_move_tail(&iocb->list,
  3440. &completions);
  3441. pring->txq_cnt--;
  3442. }
  3443. }
  3444. spin_unlock_irq(&phba->hbalock);
  3445. }
  3446. }
  3447. /* Cancel all the IOCBs from the completions list */
  3448. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3449. IOERR_SLI_ABORTED);
  3450. return 0;
  3451. }
  3452. /*
  3453. * Free rpi associated with LPFC_NODELIST entry.
  3454. * This routine is called from lpfc_freenode(), when we are removing
  3455. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  3456. * LOGO that completes successfully, and we are waiting to PLOGI back
  3457. * to the remote NPort. In addition, it is called after we receive
  3458. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  3459. * we are waiting to PLOGI back to the remote NPort.
  3460. */
  3461. int
  3462. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3463. {
  3464. struct lpfc_hba *phba = vport->phba;
  3465. LPFC_MBOXQ_t *mbox;
  3466. int rc;
  3467. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  3468. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3469. if (mbox) {
  3470. lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
  3471. mbox->vport = vport;
  3472. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3473. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3474. if (rc == MBX_NOT_FINISHED)
  3475. mempool_free(mbox, phba->mbox_mem_pool);
  3476. }
  3477. lpfc_no_rpi(phba, ndlp);
  3478. ndlp->nlp_rpi = 0;
  3479. ndlp->nlp_flag &= ~NLP_RPI_VALID;
  3480. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  3481. return 1;
  3482. }
  3483. return 0;
  3484. }
  3485. /**
  3486. * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
  3487. * @phba: pointer to lpfc hba data structure.
  3488. *
  3489. * This routine is invoked to unregister all the currently registered RPIs
  3490. * to the HBA.
  3491. **/
  3492. void
  3493. lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
  3494. {
  3495. struct lpfc_vport **vports;
  3496. struct lpfc_nodelist *ndlp;
  3497. struct Scsi_Host *shost;
  3498. int i;
  3499. vports = lpfc_create_vport_work_array(phba);
  3500. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3501. shost = lpfc_shost_from_vport(vports[i]);
  3502. spin_lock_irq(shost->host_lock);
  3503. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  3504. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  3505. /* The mempool_alloc might sleep */
  3506. spin_unlock_irq(shost->host_lock);
  3507. lpfc_unreg_rpi(vports[i], ndlp);
  3508. spin_lock_irq(shost->host_lock);
  3509. }
  3510. }
  3511. spin_unlock_irq(shost->host_lock);
  3512. }
  3513. lpfc_destroy_vport_work_array(phba, vports);
  3514. }
  3515. void
  3516. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  3517. {
  3518. struct lpfc_hba *phba = vport->phba;
  3519. LPFC_MBOXQ_t *mbox;
  3520. int rc;
  3521. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3522. if (mbox) {
  3523. lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
  3524. mbox->vport = vport;
  3525. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3526. mbox->context1 = NULL;
  3527. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  3528. if (rc != MBX_TIMEOUT)
  3529. mempool_free(mbox, phba->mbox_mem_pool);
  3530. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  3531. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  3532. "1836 Could not issue "
  3533. "unreg_login(all_rpis) status %d\n", rc);
  3534. }
  3535. }
  3536. void
  3537. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  3538. {
  3539. struct lpfc_hba *phba = vport->phba;
  3540. LPFC_MBOXQ_t *mbox;
  3541. int rc;
  3542. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3543. if (mbox) {
  3544. lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
  3545. mbox->vport = vport;
  3546. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3547. mbox->context1 = NULL;
  3548. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  3549. if (rc != MBX_TIMEOUT)
  3550. mempool_free(mbox, phba->mbox_mem_pool);
  3551. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  3552. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  3553. "1815 Could not issue "
  3554. "unreg_did (default rpis) status %d\n",
  3555. rc);
  3556. }
  3557. }
  3558. /*
  3559. * Free resources associated with LPFC_NODELIST entry
  3560. * so it can be freed.
  3561. */
  3562. static int
  3563. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3564. {
  3565. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3566. struct lpfc_hba *phba = vport->phba;
  3567. LPFC_MBOXQ_t *mb, *nextmb;
  3568. struct lpfc_dmabuf *mp;
  3569. /* Cleanup node for NPort <nlp_DID> */
  3570. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3571. "0900 Cleanup node for NPort x%x "
  3572. "Data: x%x x%x x%x\n",
  3573. ndlp->nlp_DID, ndlp->nlp_flag,
  3574. ndlp->nlp_state, ndlp->nlp_rpi);
  3575. if (NLP_CHK_FREE_REQ(ndlp)) {
  3576. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  3577. "0280 lpfc_cleanup_node: ndlp:x%p "
  3578. "usgmap:x%x refcnt:%d\n",
  3579. (void *)ndlp, ndlp->nlp_usg_map,
  3580. atomic_read(&ndlp->kref.refcount));
  3581. lpfc_dequeue_node(vport, ndlp);
  3582. } else {
  3583. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  3584. "0281 lpfc_cleanup_node: ndlp:x%p "
  3585. "usgmap:x%x refcnt:%d\n",
  3586. (void *)ndlp, ndlp->nlp_usg_map,
  3587. atomic_read(&ndlp->kref.refcount));
  3588. lpfc_disable_node(vport, ndlp);
  3589. }
  3590. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  3591. if ((mb = phba->sli.mbox_active)) {
  3592. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  3593. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  3594. mb->context2 = NULL;
  3595. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3596. }
  3597. }
  3598. spin_lock_irq(&phba->hbalock);
  3599. /* Cleanup REG_LOGIN completions which are not yet processed */
  3600. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  3601. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
  3602. (ndlp != (struct lpfc_nodelist *) mb->context2))
  3603. continue;
  3604. mb->context2 = NULL;
  3605. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3606. }
  3607. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  3608. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  3609. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  3610. mp = (struct lpfc_dmabuf *) (mb->context1);
  3611. if (mp) {
  3612. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3613. kfree(mp);
  3614. }
  3615. list_del(&mb->list);
  3616. if (phba->sli_rev == LPFC_SLI_REV4)
  3617. lpfc_sli4_free_rpi(phba,
  3618. mb->u.mb.un.varRegLogin.rpi);
  3619. mempool_free(mb, phba->mbox_mem_pool);
  3620. /* We shall not invoke the lpfc_nlp_put to decrement
  3621. * the ndlp reference count as we are in the process
  3622. * of lpfc_nlp_release.
  3623. */
  3624. }
  3625. }
  3626. spin_unlock_irq(&phba->hbalock);
  3627. lpfc_els_abort(phba, ndlp);
  3628. spin_lock_irq(shost->host_lock);
  3629. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  3630. spin_unlock_irq(shost->host_lock);
  3631. ndlp->nlp_last_elscmd = 0;
  3632. del_timer_sync(&ndlp->nlp_delayfunc);
  3633. list_del_init(&ndlp->els_retry_evt.evt_listp);
  3634. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  3635. lpfc_unreg_rpi(vport, ndlp);
  3636. return 0;
  3637. }
  3638. /*
  3639. * Check to see if we can free the nlp back to the freelist.
  3640. * If we are in the middle of using the nlp in the discovery state
  3641. * machine, defer the free till we reach the end of the state machine.
  3642. */
  3643. static void
  3644. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3645. {
  3646. struct lpfc_hba *phba = vport->phba;
  3647. struct lpfc_rport_data *rdata;
  3648. LPFC_MBOXQ_t *mbox;
  3649. int rc;
  3650. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3651. if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
  3652. !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
  3653. !(ndlp->nlp_flag & NLP_RPI_VALID)) {
  3654. /* For this case we need to cleanup the default rpi
  3655. * allocated by the firmware.
  3656. */
  3657. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
  3658. != NULL) {
  3659. rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
  3660. (uint8_t *) &vport->fc_sparam, mbox, 0);
  3661. if (rc) {
  3662. mempool_free(mbox, phba->mbox_mem_pool);
  3663. }
  3664. else {
  3665. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  3666. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  3667. mbox->vport = vport;
  3668. mbox->context2 = NULL;
  3669. rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3670. if (rc == MBX_NOT_FINISHED) {
  3671. mempool_free(mbox, phba->mbox_mem_pool);
  3672. }
  3673. }
  3674. }
  3675. }
  3676. lpfc_cleanup_node(vport, ndlp);
  3677. /*
  3678. * We can get here with a non-NULL ndlp->rport because when we
  3679. * unregister a rport we don't break the rport/node linkage. So if we
  3680. * do, make sure we don't leaving any dangling pointers behind.
  3681. */
  3682. if (ndlp->rport) {
  3683. rdata = ndlp->rport->dd_data;
  3684. rdata->pnode = NULL;
  3685. ndlp->rport = NULL;
  3686. }
  3687. }
  3688. static int
  3689. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3690. uint32_t did)
  3691. {
  3692. D_ID mydid, ndlpdid, matchdid;
  3693. if (did == Bcast_DID)
  3694. return 0;
  3695. /* First check for Direct match */
  3696. if (ndlp->nlp_DID == did)
  3697. return 1;
  3698. /* Next check for area/domain identically equals 0 match */
  3699. mydid.un.word = vport->fc_myDID;
  3700. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  3701. return 0;
  3702. }
  3703. matchdid.un.word = did;
  3704. ndlpdid.un.word = ndlp->nlp_DID;
  3705. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  3706. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  3707. (mydid.un.b.area == matchdid.un.b.area)) {
  3708. if ((ndlpdid.un.b.domain == 0) &&
  3709. (ndlpdid.un.b.area == 0)) {
  3710. if (ndlpdid.un.b.id)
  3711. return 1;
  3712. }
  3713. return 0;
  3714. }
  3715. matchdid.un.word = ndlp->nlp_DID;
  3716. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  3717. (mydid.un.b.area == ndlpdid.un.b.area)) {
  3718. if ((matchdid.un.b.domain == 0) &&
  3719. (matchdid.un.b.area == 0)) {
  3720. if (matchdid.un.b.id)
  3721. return 1;
  3722. }
  3723. }
  3724. }
  3725. return 0;
  3726. }
  3727. /* Search for a nodelist entry */
  3728. static struct lpfc_nodelist *
  3729. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  3730. {
  3731. struct lpfc_nodelist *ndlp;
  3732. uint32_t data1;
  3733. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3734. if (lpfc_matchdid(vport, ndlp, did)) {
  3735. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  3736. ((uint32_t) ndlp->nlp_xri << 16) |
  3737. ((uint32_t) ndlp->nlp_type << 8) |
  3738. ((uint32_t) ndlp->nlp_rpi & 0xff));
  3739. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3740. "0929 FIND node DID "
  3741. "Data: x%p x%x x%x x%x\n",
  3742. ndlp, ndlp->nlp_DID,
  3743. ndlp->nlp_flag, data1);
  3744. return ndlp;
  3745. }
  3746. }
  3747. /* FIND node did <did> NOT FOUND */
  3748. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  3749. "0932 FIND node did x%x NOT FOUND.\n", did);
  3750. return NULL;
  3751. }
  3752. struct lpfc_nodelist *
  3753. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  3754. {
  3755. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3756. struct lpfc_nodelist *ndlp;
  3757. spin_lock_irq(shost->host_lock);
  3758. ndlp = __lpfc_findnode_did(vport, did);
  3759. spin_unlock_irq(shost->host_lock);
  3760. return ndlp;
  3761. }
  3762. struct lpfc_nodelist *
  3763. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  3764. {
  3765. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3766. struct lpfc_nodelist *ndlp;
  3767. ndlp = lpfc_findnode_did(vport, did);
  3768. if (!ndlp) {
  3769. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  3770. lpfc_rscn_payload_check(vport, did) == 0)
  3771. return NULL;
  3772. ndlp = (struct lpfc_nodelist *)
  3773. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  3774. if (!ndlp)
  3775. return NULL;
  3776. lpfc_nlp_init(vport, ndlp, did);
  3777. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3778. spin_lock_irq(shost->host_lock);
  3779. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3780. spin_unlock_irq(shost->host_lock);
  3781. return ndlp;
  3782. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  3783. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  3784. if (!ndlp)
  3785. return NULL;
  3786. spin_lock_irq(shost->host_lock);
  3787. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3788. spin_unlock_irq(shost->host_lock);
  3789. return ndlp;
  3790. }
  3791. if ((vport->fc_flag & FC_RSCN_MODE) &&
  3792. !(vport->fc_flag & FC_NDISC_ACTIVE)) {
  3793. if (lpfc_rscn_payload_check(vport, did)) {
  3794. /* If we've already recieved a PLOGI from this NPort
  3795. * we don't need to try to discover it again.
  3796. */
  3797. if (ndlp->nlp_flag & NLP_RCV_PLOGI)
  3798. return NULL;
  3799. /* Since this node is marked for discovery,
  3800. * delay timeout is not needed.
  3801. */
  3802. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  3803. spin_lock_irq(shost->host_lock);
  3804. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3805. spin_unlock_irq(shost->host_lock);
  3806. } else
  3807. ndlp = NULL;
  3808. } else {
  3809. /* If we've already recieved a PLOGI from this NPort,
  3810. * or we are already in the process of discovery on it,
  3811. * we don't need to try to discover it again.
  3812. */
  3813. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  3814. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  3815. ndlp->nlp_flag & NLP_RCV_PLOGI)
  3816. return NULL;
  3817. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3818. spin_lock_irq(shost->host_lock);
  3819. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  3820. spin_unlock_irq(shost->host_lock);
  3821. }
  3822. return ndlp;
  3823. }
  3824. /* Build a list of nodes to discover based on the loopmap */
  3825. void
  3826. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  3827. {
  3828. struct lpfc_hba *phba = vport->phba;
  3829. int j;
  3830. uint32_t alpa, index;
  3831. if (!lpfc_is_link_up(phba))
  3832. return;
  3833. if (phba->fc_topology != TOPOLOGY_LOOP)
  3834. return;
  3835. /* Check for loop map present or not */
  3836. if (phba->alpa_map[0]) {
  3837. for (j = 1; j <= phba->alpa_map[0]; j++) {
  3838. alpa = phba->alpa_map[j];
  3839. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  3840. continue;
  3841. lpfc_setup_disc_node(vport, alpa);
  3842. }
  3843. } else {
  3844. /* No alpamap, so try all alpa's */
  3845. for (j = 0; j < FC_MAXLOOP; j++) {
  3846. /* If cfg_scan_down is set, start from highest
  3847. * ALPA (0xef) to lowest (0x1).
  3848. */
  3849. if (vport->cfg_scan_down)
  3850. index = j;
  3851. else
  3852. index = FC_MAXLOOP - j - 1;
  3853. alpa = lpfcAlpaArray[index];
  3854. if ((vport->fc_myDID & 0xff) == alpa)
  3855. continue;
  3856. lpfc_setup_disc_node(vport, alpa);
  3857. }
  3858. }
  3859. return;
  3860. }
  3861. void
  3862. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3863. {
  3864. LPFC_MBOXQ_t *mbox;
  3865. struct lpfc_sli *psli = &phba->sli;
  3866. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  3867. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  3868. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  3869. int rc;
  3870. /*
  3871. * if it's not a physical port or if we already send
  3872. * clear_la then don't send it.
  3873. */
  3874. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  3875. (vport->port_type != LPFC_PHYSICAL_PORT) ||
  3876. (phba->sli_rev == LPFC_SLI_REV4))
  3877. return;
  3878. /* Link up discovery */
  3879. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  3880. phba->link_state = LPFC_CLEAR_LA;
  3881. lpfc_clear_la(phba, mbox);
  3882. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  3883. mbox->vport = vport;
  3884. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3885. if (rc == MBX_NOT_FINISHED) {
  3886. mempool_free(mbox, phba->mbox_mem_pool);
  3887. lpfc_disc_flush_list(vport);
  3888. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3889. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3890. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  3891. phba->link_state = LPFC_HBA_ERROR;
  3892. }
  3893. }
  3894. }
  3895. /* Reg_vpi to tell firmware to resume normal operations */
  3896. void
  3897. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3898. {
  3899. LPFC_MBOXQ_t *regvpimbox;
  3900. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3901. if (regvpimbox) {
  3902. lpfc_reg_vpi(vport, regvpimbox);
  3903. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  3904. regvpimbox->vport = vport;
  3905. if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
  3906. == MBX_NOT_FINISHED) {
  3907. mempool_free(regvpimbox, phba->mbox_mem_pool);
  3908. }
  3909. }
  3910. }
  3911. /* Start Link up / RSCN discovery on NPR nodes */
  3912. void
  3913. lpfc_disc_start(struct lpfc_vport *vport)
  3914. {
  3915. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3916. struct lpfc_hba *phba = vport->phba;
  3917. uint32_t num_sent;
  3918. uint32_t clear_la_pending;
  3919. int did_changed;
  3920. if (!lpfc_is_link_up(phba))
  3921. return;
  3922. if (phba->link_state == LPFC_CLEAR_LA)
  3923. clear_la_pending = 1;
  3924. else
  3925. clear_la_pending = 0;
  3926. if (vport->port_state < LPFC_VPORT_READY)
  3927. vport->port_state = LPFC_DISC_AUTH;
  3928. lpfc_set_disctmo(vport);
  3929. if (vport->fc_prevDID == vport->fc_myDID)
  3930. did_changed = 0;
  3931. else
  3932. did_changed = 1;
  3933. vport->fc_prevDID = vport->fc_myDID;
  3934. vport->num_disc_nodes = 0;
  3935. /* Start Discovery state <hba_state> */
  3936. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3937. "0202 Start Discovery hba state x%x "
  3938. "Data: x%x x%x x%x\n",
  3939. vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
  3940. vport->fc_adisc_cnt);
  3941. /* First do ADISCs - if any */
  3942. num_sent = lpfc_els_disc_adisc(vport);
  3943. if (num_sent)
  3944. return;
  3945. /*
  3946. * For SLI3, cmpl_reg_vpi will set port_state to READY, and
  3947. * continue discovery.
  3948. */
  3949. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3950. !(vport->fc_flag & FC_PT2PT) &&
  3951. !(vport->fc_flag & FC_RSCN_MODE) &&
  3952. (phba->sli_rev < LPFC_SLI_REV4)) {
  3953. lpfc_issue_reg_vpi(phba, vport);
  3954. return;
  3955. }
  3956. /*
  3957. * For SLI2, we need to set port_state to READY and continue
  3958. * discovery.
  3959. */
  3960. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  3961. /* If we get here, there is nothing to ADISC */
  3962. if (vport->port_type == LPFC_PHYSICAL_PORT)
  3963. lpfc_issue_clear_la(phba, vport);
  3964. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  3965. vport->num_disc_nodes = 0;
  3966. /* go thru NPR nodes and issue ELS PLOGIs */
  3967. if (vport->fc_npr_cnt)
  3968. lpfc_els_disc_plogi(vport);
  3969. if (!vport->num_disc_nodes) {
  3970. spin_lock_irq(shost->host_lock);
  3971. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3972. spin_unlock_irq(shost->host_lock);
  3973. lpfc_can_disctmo(vport);
  3974. }
  3975. }
  3976. vport->port_state = LPFC_VPORT_READY;
  3977. } else {
  3978. /* Next do PLOGIs - if any */
  3979. num_sent = lpfc_els_disc_plogi(vport);
  3980. if (num_sent)
  3981. return;
  3982. if (vport->fc_flag & FC_RSCN_MODE) {
  3983. /* Check to see if more RSCNs came in while we
  3984. * were processing this one.
  3985. */
  3986. if ((vport->fc_rscn_id_cnt == 0) &&
  3987. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  3988. spin_lock_irq(shost->host_lock);
  3989. vport->fc_flag &= ~FC_RSCN_MODE;
  3990. spin_unlock_irq(shost->host_lock);
  3991. lpfc_can_disctmo(vport);
  3992. } else
  3993. lpfc_els_handle_rscn(vport);
  3994. }
  3995. }
  3996. return;
  3997. }
  3998. /*
  3999. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  4000. * ring the match the sppecified nodelist.
  4001. */
  4002. static void
  4003. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  4004. {
  4005. LIST_HEAD(completions);
  4006. struct lpfc_sli *psli;
  4007. IOCB_t *icmd;
  4008. struct lpfc_iocbq *iocb, *next_iocb;
  4009. struct lpfc_sli_ring *pring;
  4010. psli = &phba->sli;
  4011. pring = &psli->ring[LPFC_ELS_RING];
  4012. /* Error matching iocb on txq or txcmplq
  4013. * First check the txq.
  4014. */
  4015. spin_lock_irq(&phba->hbalock);
  4016. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  4017. if (iocb->context1 != ndlp) {
  4018. continue;
  4019. }
  4020. icmd = &iocb->iocb;
  4021. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  4022. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  4023. list_move_tail(&iocb->list, &completions);
  4024. pring->txq_cnt--;
  4025. }
  4026. }
  4027. /* Next check the txcmplq */
  4028. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  4029. if (iocb->context1 != ndlp) {
  4030. continue;
  4031. }
  4032. icmd = &iocb->iocb;
  4033. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  4034. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  4035. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  4036. }
  4037. }
  4038. spin_unlock_irq(&phba->hbalock);
  4039. /* Cancel all the IOCBs from the completions list */
  4040. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  4041. IOERR_SLI_ABORTED);
  4042. }
  4043. static void
  4044. lpfc_disc_flush_list(struct lpfc_vport *vport)
  4045. {
  4046. struct lpfc_nodelist *ndlp, *next_ndlp;
  4047. struct lpfc_hba *phba = vport->phba;
  4048. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  4049. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  4050. nlp_listp) {
  4051. if (!NLP_CHK_NODE_ACT(ndlp))
  4052. continue;
  4053. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  4054. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  4055. lpfc_free_tx(phba, ndlp);
  4056. }
  4057. }
  4058. }
  4059. }
  4060. void
  4061. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  4062. {
  4063. lpfc_els_flush_rscn(vport);
  4064. lpfc_els_flush_cmd(vport);
  4065. lpfc_disc_flush_list(vport);
  4066. }
  4067. /*****************************************************************************/
  4068. /*
  4069. * NAME: lpfc_disc_timeout
  4070. *
  4071. * FUNCTION: Fibre Channel driver discovery timeout routine.
  4072. *
  4073. * EXECUTION ENVIRONMENT: interrupt only
  4074. *
  4075. * CALLED FROM:
  4076. * Timer function
  4077. *
  4078. * RETURNS:
  4079. * none
  4080. */
  4081. /*****************************************************************************/
  4082. void
  4083. lpfc_disc_timeout(unsigned long ptr)
  4084. {
  4085. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  4086. struct lpfc_hba *phba = vport->phba;
  4087. uint32_t tmo_posted;
  4088. unsigned long flags = 0;
  4089. if (unlikely(!phba))
  4090. return;
  4091. spin_lock_irqsave(&vport->work_port_lock, flags);
  4092. tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
  4093. if (!tmo_posted)
  4094. vport->work_port_events |= WORKER_DISC_TMO;
  4095. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  4096. if (!tmo_posted)
  4097. lpfc_worker_wake_up(phba);
  4098. return;
  4099. }
  4100. static void
  4101. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  4102. {
  4103. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4104. struct lpfc_hba *phba = vport->phba;
  4105. struct lpfc_sli *psli = &phba->sli;
  4106. struct lpfc_nodelist *ndlp, *next_ndlp;
  4107. LPFC_MBOXQ_t *initlinkmbox;
  4108. int rc, clrlaerr = 0;
  4109. if (!(vport->fc_flag & FC_DISC_TMO))
  4110. return;
  4111. spin_lock_irq(shost->host_lock);
  4112. vport->fc_flag &= ~FC_DISC_TMO;
  4113. spin_unlock_irq(shost->host_lock);
  4114. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  4115. "disc timeout: state:x%x rtry:x%x flg:x%x",
  4116. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  4117. switch (vport->port_state) {
  4118. case LPFC_LOCAL_CFG_LINK:
  4119. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  4120. * FAN
  4121. */
  4122. /* FAN timeout */
  4123. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  4124. "0221 FAN timeout\n");
  4125. /* Start discovery by sending FLOGI, clean up old rpis */
  4126. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  4127. nlp_listp) {
  4128. if (!NLP_CHK_NODE_ACT(ndlp))
  4129. continue;
  4130. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  4131. continue;
  4132. if (ndlp->nlp_type & NLP_FABRIC) {
  4133. /* Clean up the ndlp on Fabric connections */
  4134. lpfc_drop_node(vport, ndlp);
  4135. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  4136. /* Fail outstanding IO now since device
  4137. * is marked for PLOGI.
  4138. */
  4139. lpfc_unreg_rpi(vport, ndlp);
  4140. }
  4141. }
  4142. if (vport->port_state != LPFC_FLOGI) {
  4143. lpfc_initial_flogi(vport);
  4144. return;
  4145. }
  4146. break;
  4147. case LPFC_FDISC:
  4148. case LPFC_FLOGI:
  4149. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  4150. /* Initial FLOGI timeout */
  4151. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4152. "0222 Initial %s timeout\n",
  4153. vport->vpi ? "FDISC" : "FLOGI");
  4154. /* Assume no Fabric and go on with discovery.
  4155. * Check for outstanding ELS FLOGI to abort.
  4156. */
  4157. /* FLOGI failed, so just use loop map to make discovery list */
  4158. lpfc_disc_list_loopmap(vport);
  4159. /* Start discovery */
  4160. lpfc_disc_start(vport);
  4161. break;
  4162. case LPFC_FABRIC_CFG_LINK:
  4163. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  4164. NameServer login */
  4165. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4166. "0223 Timeout while waiting for "
  4167. "NameServer login\n");
  4168. /* Next look for NameServer ndlp */
  4169. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  4170. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  4171. lpfc_els_abort(phba, ndlp);
  4172. /* ReStart discovery */
  4173. goto restart_disc;
  4174. case LPFC_NS_QRY:
  4175. /* Check for wait for NameServer Rsp timeout */
  4176. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4177. "0224 NameServer Query timeout "
  4178. "Data: x%x x%x\n",
  4179. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  4180. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  4181. /* Try it one more time */
  4182. vport->fc_ns_retry++;
  4183. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  4184. vport->fc_ns_retry, 0);
  4185. if (rc == 0)
  4186. break;
  4187. }
  4188. vport->fc_ns_retry = 0;
  4189. restart_disc:
  4190. /*
  4191. * Discovery is over.
  4192. * set port_state to PORT_READY if SLI2.
  4193. * cmpl_reg_vpi will set port_state to READY for SLI3.
  4194. */
  4195. if (phba->sli_rev < LPFC_SLI_REV4) {
  4196. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  4197. lpfc_issue_reg_vpi(phba, vport);
  4198. else { /* NPIV Not enabled */
  4199. lpfc_issue_clear_la(phba, vport);
  4200. vport->port_state = LPFC_VPORT_READY;
  4201. }
  4202. }
  4203. /* Setup and issue mailbox INITIALIZE LINK command */
  4204. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4205. if (!initlinkmbox) {
  4206. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4207. "0206 Device Discovery "
  4208. "completion error\n");
  4209. phba->link_state = LPFC_HBA_ERROR;
  4210. break;
  4211. }
  4212. lpfc_linkdown(phba);
  4213. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  4214. phba->cfg_link_speed);
  4215. initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  4216. initlinkmbox->vport = vport;
  4217. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4218. rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
  4219. lpfc_set_loopback_flag(phba);
  4220. if (rc == MBX_NOT_FINISHED)
  4221. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  4222. break;
  4223. case LPFC_DISC_AUTH:
  4224. /* Node Authentication timeout */
  4225. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4226. "0227 Node Authentication timeout\n");
  4227. lpfc_disc_flush_list(vport);
  4228. /*
  4229. * set port_state to PORT_READY if SLI2.
  4230. * cmpl_reg_vpi will set port_state to READY for SLI3.
  4231. */
  4232. if (phba->sli_rev < LPFC_SLI_REV4) {
  4233. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  4234. lpfc_issue_reg_vpi(phba, vport);
  4235. else { /* NPIV Not enabled */
  4236. lpfc_issue_clear_la(phba, vport);
  4237. vport->port_state = LPFC_VPORT_READY;
  4238. }
  4239. }
  4240. break;
  4241. case LPFC_VPORT_READY:
  4242. if (vport->fc_flag & FC_RSCN_MODE) {
  4243. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4244. "0231 RSCN timeout Data: x%x "
  4245. "x%x\n",
  4246. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  4247. /* Cleanup any outstanding ELS commands */
  4248. lpfc_els_flush_cmd(vport);
  4249. lpfc_els_flush_rscn(vport);
  4250. lpfc_disc_flush_list(vport);
  4251. }
  4252. break;
  4253. default:
  4254. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4255. "0273 Unexpected discovery timeout, "
  4256. "vport State x%x\n", vport->port_state);
  4257. break;
  4258. }
  4259. switch (phba->link_state) {
  4260. case LPFC_CLEAR_LA:
  4261. /* CLEAR LA timeout */
  4262. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4263. "0228 CLEAR LA timeout\n");
  4264. clrlaerr = 1;
  4265. break;
  4266. case LPFC_LINK_UP:
  4267. lpfc_issue_clear_la(phba, vport);
  4268. /* Drop thru */
  4269. case LPFC_LINK_UNKNOWN:
  4270. case LPFC_WARM_START:
  4271. case LPFC_INIT_START:
  4272. case LPFC_INIT_MBX_CMDS:
  4273. case LPFC_LINK_DOWN:
  4274. case LPFC_HBA_ERROR:
  4275. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  4276. "0230 Unexpected timeout, hba link "
  4277. "state x%x\n", phba->link_state);
  4278. clrlaerr = 1;
  4279. break;
  4280. case LPFC_HBA_READY:
  4281. break;
  4282. }
  4283. if (clrlaerr) {
  4284. lpfc_disc_flush_list(vport);
  4285. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4286. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4287. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  4288. vport->port_state = LPFC_VPORT_READY;
  4289. }
  4290. return;
  4291. }
  4292. /*
  4293. * This routine handles processing a NameServer REG_LOGIN mailbox
  4294. * command upon completion. It is setup in the LPFC_MBOXQ
  4295. * as the completion routine when the command is
  4296. * handed off to the SLI layer.
  4297. */
  4298. void
  4299. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  4300. {
  4301. MAILBOX_t *mb = &pmb->u.mb;
  4302. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  4303. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  4304. struct lpfc_vport *vport = pmb->vport;
  4305. pmb->context1 = NULL;
  4306. pmb->context2 = NULL;
  4307. ndlp->nlp_rpi = mb->un.varWords[0];
  4308. ndlp->nlp_flag |= NLP_RPI_VALID;
  4309. ndlp->nlp_type |= NLP_FABRIC;
  4310. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  4311. /*
  4312. * Start issuing Fabric-Device Management Interface (FDMI) command to
  4313. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  4314. * fdmi-on=2 (supporting RPA/hostnmae)
  4315. */
  4316. if (vport->cfg_fdmi_on == 1)
  4317. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  4318. else
  4319. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  4320. /* decrement the node reference count held for this callback
  4321. * function.
  4322. */
  4323. lpfc_nlp_put(ndlp);
  4324. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  4325. kfree(mp);
  4326. mempool_free(pmb, phba->mbox_mem_pool);
  4327. return;
  4328. }
  4329. static int
  4330. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  4331. {
  4332. uint16_t *rpi = param;
  4333. return ndlp->nlp_rpi == *rpi;
  4334. }
  4335. static int
  4336. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  4337. {
  4338. return memcmp(&ndlp->nlp_portname, param,
  4339. sizeof(ndlp->nlp_portname)) == 0;
  4340. }
  4341. static struct lpfc_nodelist *
  4342. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  4343. {
  4344. struct lpfc_nodelist *ndlp;
  4345. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  4346. if (filter(ndlp, param))
  4347. return ndlp;
  4348. }
  4349. return NULL;
  4350. }
  4351. /*
  4352. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  4353. * returns the node list element pointer else return NULL.
  4354. */
  4355. struct lpfc_nodelist *
  4356. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  4357. {
  4358. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  4359. }
  4360. /*
  4361. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  4362. * returns the node element list pointer else return NULL.
  4363. */
  4364. struct lpfc_nodelist *
  4365. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  4366. {
  4367. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4368. struct lpfc_nodelist *ndlp;
  4369. spin_lock_irq(shost->host_lock);
  4370. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  4371. spin_unlock_irq(shost->host_lock);
  4372. return ndlp;
  4373. }
  4374. void
  4375. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  4376. uint32_t did)
  4377. {
  4378. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  4379. lpfc_initialize_node(vport, ndlp, did);
  4380. INIT_LIST_HEAD(&ndlp->nlp_listp);
  4381. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  4382. "node init: did:x%x",
  4383. ndlp->nlp_DID, 0, 0);
  4384. return;
  4385. }
  4386. /* This routine releases all resources associated with a specifc NPort's ndlp
  4387. * and mempool_free's the nodelist.
  4388. */
  4389. static void
  4390. lpfc_nlp_release(struct kref *kref)
  4391. {
  4392. struct lpfc_hba *phba;
  4393. unsigned long flags;
  4394. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  4395. kref);
  4396. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  4397. "node release: did:x%x flg:x%x type:x%x",
  4398. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  4399. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  4400. "0279 lpfc_nlp_release: ndlp:x%p "
  4401. "usgmap:x%x refcnt:%d\n",
  4402. (void *)ndlp, ndlp->nlp_usg_map,
  4403. atomic_read(&ndlp->kref.refcount));
  4404. /* remove ndlp from action. */
  4405. lpfc_nlp_remove(ndlp->vport, ndlp);
  4406. /* clear the ndlp active flag for all release cases */
  4407. phba = ndlp->phba;
  4408. spin_lock_irqsave(&phba->ndlp_lock, flags);
  4409. NLP_CLR_NODE_ACT(ndlp);
  4410. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4411. /* free ndlp memory for final ndlp release */
  4412. if (NLP_CHK_FREE_REQ(ndlp)) {
  4413. kfree(ndlp->lat_data);
  4414. mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
  4415. }
  4416. }
  4417. /* This routine bumps the reference count for a ndlp structure to ensure
  4418. * that one discovery thread won't free a ndlp while another discovery thread
  4419. * is using it.
  4420. */
  4421. struct lpfc_nodelist *
  4422. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  4423. {
  4424. struct lpfc_hba *phba;
  4425. unsigned long flags;
  4426. if (ndlp) {
  4427. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  4428. "node get: did:x%x flg:x%x refcnt:x%x",
  4429. ndlp->nlp_DID, ndlp->nlp_flag,
  4430. atomic_read(&ndlp->kref.refcount));
  4431. /* The check of ndlp usage to prevent incrementing the
  4432. * ndlp reference count that is in the process of being
  4433. * released.
  4434. */
  4435. phba = ndlp->phba;
  4436. spin_lock_irqsave(&phba->ndlp_lock, flags);
  4437. if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
  4438. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4439. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  4440. "0276 lpfc_nlp_get: ndlp:x%p "
  4441. "usgmap:x%x refcnt:%d\n",
  4442. (void *)ndlp, ndlp->nlp_usg_map,
  4443. atomic_read(&ndlp->kref.refcount));
  4444. return NULL;
  4445. } else
  4446. kref_get(&ndlp->kref);
  4447. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4448. }
  4449. return ndlp;
  4450. }
  4451. /* This routine decrements the reference count for a ndlp structure. If the
  4452. * count goes to 0, this indicates the the associated nodelist should be
  4453. * freed. Returning 1 indicates the ndlp resource has been released; on the
  4454. * other hand, returning 0 indicates the ndlp resource has not been released
  4455. * yet.
  4456. */
  4457. int
  4458. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  4459. {
  4460. struct lpfc_hba *phba;
  4461. unsigned long flags;
  4462. if (!ndlp)
  4463. return 1;
  4464. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  4465. "node put: did:x%x flg:x%x refcnt:x%x",
  4466. ndlp->nlp_DID, ndlp->nlp_flag,
  4467. atomic_read(&ndlp->kref.refcount));
  4468. phba = ndlp->phba;
  4469. spin_lock_irqsave(&phba->ndlp_lock, flags);
  4470. /* Check the ndlp memory free acknowledge flag to avoid the
  4471. * possible race condition that kref_put got invoked again
  4472. * after previous one has done ndlp memory free.
  4473. */
  4474. if (NLP_CHK_FREE_ACK(ndlp)) {
  4475. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4476. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  4477. "0274 lpfc_nlp_put: ndlp:x%p "
  4478. "usgmap:x%x refcnt:%d\n",
  4479. (void *)ndlp, ndlp->nlp_usg_map,
  4480. atomic_read(&ndlp->kref.refcount));
  4481. return 1;
  4482. }
  4483. /* Check the ndlp inactivate log flag to avoid the possible
  4484. * race condition that kref_put got invoked again after ndlp
  4485. * is already in inactivating state.
  4486. */
  4487. if (NLP_CHK_IACT_REQ(ndlp)) {
  4488. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4489. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  4490. "0275 lpfc_nlp_put: ndlp:x%p "
  4491. "usgmap:x%x refcnt:%d\n",
  4492. (void *)ndlp, ndlp->nlp_usg_map,
  4493. atomic_read(&ndlp->kref.refcount));
  4494. return 1;
  4495. }
  4496. /* For last put, mark the ndlp usage flags to make sure no
  4497. * other kref_get and kref_put on the same ndlp shall get
  4498. * in between the process when the final kref_put has been
  4499. * invoked on this ndlp.
  4500. */
  4501. if (atomic_read(&ndlp->kref.refcount) == 1) {
  4502. /* Indicate ndlp is put to inactive state. */
  4503. NLP_SET_IACT_REQ(ndlp);
  4504. /* Acknowledge ndlp memory free has been seen. */
  4505. if (NLP_CHK_FREE_REQ(ndlp))
  4506. NLP_SET_FREE_ACK(ndlp);
  4507. }
  4508. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  4509. /* Note, the kref_put returns 1 when decrementing a reference
  4510. * count that was 1, it invokes the release callback function,
  4511. * but it still left the reference count as 1 (not actually
  4512. * performs the last decrementation). Otherwise, it actually
  4513. * decrements the reference count and returns 0.
  4514. */
  4515. return kref_put(&ndlp->kref, lpfc_nlp_release);
  4516. }
  4517. /* This routine free's the specified nodelist if it is not in use
  4518. * by any other discovery thread. This routine returns 1 if the
  4519. * ndlp has been freed. A return value of 0 indicates the ndlp is
  4520. * not yet been released.
  4521. */
  4522. int
  4523. lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
  4524. {
  4525. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  4526. "node not used: did:x%x flg:x%x refcnt:x%x",
  4527. ndlp->nlp_DID, ndlp->nlp_flag,
  4528. atomic_read(&ndlp->kref.refcount));
  4529. if (atomic_read(&ndlp->kref.refcount) == 1)
  4530. if (lpfc_nlp_put(ndlp))
  4531. return 1;
  4532. return 0;
  4533. }
  4534. /**
  4535. * lpfc_fcf_inuse - Check if FCF can be unregistered.
  4536. * @phba: Pointer to hba context object.
  4537. *
  4538. * This function iterate through all FC nodes associated
  4539. * will all vports to check if there is any node with
  4540. * fc_rports associated with it. If there is an fc_rport
  4541. * associated with the node, then the node is either in
  4542. * discovered state or its devloss_timer is pending.
  4543. */
  4544. static int
  4545. lpfc_fcf_inuse(struct lpfc_hba *phba)
  4546. {
  4547. struct lpfc_vport **vports;
  4548. int i, ret = 0;
  4549. struct lpfc_nodelist *ndlp;
  4550. struct Scsi_Host *shost;
  4551. vports = lpfc_create_vport_work_array(phba);
  4552. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  4553. shost = lpfc_shost_from_vport(vports[i]);
  4554. spin_lock_irq(shost->host_lock);
  4555. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  4556. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
  4557. (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  4558. ret = 1;
  4559. spin_unlock_irq(shost->host_lock);
  4560. goto out;
  4561. } else {
  4562. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  4563. "2624 RPI %x DID %x flg %x still "
  4564. "logged in\n",
  4565. ndlp->nlp_rpi, ndlp->nlp_DID,
  4566. ndlp->nlp_flag);
  4567. if (ndlp->nlp_flag & NLP_RPI_VALID)
  4568. ret = 1;
  4569. }
  4570. }
  4571. spin_unlock_irq(shost->host_lock);
  4572. }
  4573. out:
  4574. lpfc_destroy_vport_work_array(phba, vports);
  4575. return ret;
  4576. }
  4577. /**
  4578. * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
  4579. * @phba: Pointer to hba context object.
  4580. * @mboxq: Pointer to mailbox object.
  4581. *
  4582. * This function frees memory associated with the mailbox command.
  4583. */
  4584. static void
  4585. lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4586. {
  4587. struct lpfc_vport *vport = mboxq->vport;
  4588. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  4589. if (mboxq->u.mb.mbxStatus) {
  4590. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4591. "2555 UNREG_VFI mbxStatus error x%x "
  4592. "HBA state x%x\n",
  4593. mboxq->u.mb.mbxStatus, vport->port_state);
  4594. }
  4595. spin_lock_irq(shost->host_lock);
  4596. phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
  4597. spin_unlock_irq(shost->host_lock);
  4598. mempool_free(mboxq, phba->mbox_mem_pool);
  4599. return;
  4600. }
  4601. /**
  4602. * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
  4603. * @phba: Pointer to hba context object.
  4604. * @mboxq: Pointer to mailbox object.
  4605. *
  4606. * This function frees memory associated with the mailbox command.
  4607. */
  4608. static void
  4609. lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  4610. {
  4611. struct lpfc_vport *vport = mboxq->vport;
  4612. if (mboxq->u.mb.mbxStatus) {
  4613. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4614. "2550 UNREG_FCFI mbxStatus error x%x "
  4615. "HBA state x%x\n",
  4616. mboxq->u.mb.mbxStatus, vport->port_state);
  4617. }
  4618. mempool_free(mboxq, phba->mbox_mem_pool);
  4619. return;
  4620. }
  4621. /**
  4622. * lpfc_unregister_fcf_prep - Unregister fcf record preparation
  4623. * @phba: Pointer to hba context object.
  4624. *
  4625. * This function prepare the HBA for unregistering the currently registered
  4626. * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
  4627. * VFIs.
  4628. */
  4629. int
  4630. lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
  4631. {
  4632. LPFC_MBOXQ_t *mbox;
  4633. struct lpfc_vport **vports;
  4634. struct lpfc_nodelist *ndlp;
  4635. struct Scsi_Host *shost;
  4636. int i, rc;
  4637. /* Unregister RPIs */
  4638. if (lpfc_fcf_inuse(phba))
  4639. lpfc_unreg_hba_rpis(phba);
  4640. /* At this point, all discovery is aborted */
  4641. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  4642. /* Unregister VPIs */
  4643. vports = lpfc_create_vport_work_array(phba);
  4644. if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
  4645. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  4646. /* Stop FLOGI/FDISC retries */
  4647. ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
  4648. if (ndlp)
  4649. lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
  4650. lpfc_cleanup_pending_mbox(vports[i]);
  4651. lpfc_mbx_unreg_vpi(vports[i]);
  4652. shost = lpfc_shost_from_vport(vports[i]);
  4653. spin_lock_irq(shost->host_lock);
  4654. vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
  4655. vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
  4656. spin_unlock_irq(shost->host_lock);
  4657. }
  4658. lpfc_destroy_vport_work_array(phba, vports);
  4659. /* Cleanup any outstanding ELS commands */
  4660. lpfc_els_flush_all_cmd(phba);
  4661. /* Unregister VFI */
  4662. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4663. if (!mbox) {
  4664. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4665. "2556 UNREG_VFI mbox allocation failed"
  4666. "HBA state x%x\n", phba->pport->port_state);
  4667. return -ENOMEM;
  4668. }
  4669. lpfc_unreg_vfi(mbox, phba->pport);
  4670. mbox->vport = phba->pport;
  4671. mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  4672. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4673. if (rc == MBX_NOT_FINISHED) {
  4674. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4675. "2557 UNREG_VFI issue mbox failed rc x%x "
  4676. "HBA state x%x\n",
  4677. rc, phba->pport->port_state);
  4678. mempool_free(mbox, phba->mbox_mem_pool);
  4679. return -EIO;
  4680. }
  4681. shost = lpfc_shost_from_vport(phba->pport);
  4682. spin_lock_irq(shost->host_lock);
  4683. phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
  4684. spin_unlock_irq(shost->host_lock);
  4685. return 0;
  4686. }
  4687. /**
  4688. * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
  4689. * @phba: Pointer to hba context object.
  4690. *
  4691. * This function issues synchronous unregister FCF mailbox command to HBA to
  4692. * unregister the currently registered FCF record. The driver does not reset
  4693. * the driver FCF usage state flags.
  4694. *
  4695. * Return 0 if successfully issued, none-zero otherwise.
  4696. */
  4697. int
  4698. lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
  4699. {
  4700. LPFC_MBOXQ_t *mbox;
  4701. int rc;
  4702. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4703. if (!mbox) {
  4704. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4705. "2551 UNREG_FCFI mbox allocation failed"
  4706. "HBA state x%x\n", phba->pport->port_state);
  4707. return -ENOMEM;
  4708. }
  4709. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  4710. mbox->vport = phba->pport;
  4711. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  4712. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  4713. if (rc == MBX_NOT_FINISHED) {
  4714. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  4715. "2552 Unregister FCFI command failed rc x%x "
  4716. "HBA state x%x\n",
  4717. rc, phba->pport->port_state);
  4718. return -EINVAL;
  4719. }
  4720. return 0;
  4721. }
  4722. /**
  4723. * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
  4724. * @phba: Pointer to hba context object.
  4725. *
  4726. * This function unregisters the currently reigstered FCF. This function
  4727. * also tries to find another FCF for discovery by rescan the HBA FCF table.
  4728. */
  4729. void
  4730. lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
  4731. {
  4732. int rc;
  4733. /* Preparation for unregistering fcf */
  4734. rc = lpfc_unregister_fcf_prep(phba);
  4735. if (rc) {
  4736. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  4737. "2748 Failed to prepare for unregistering "
  4738. "HBA's FCF record: rc=%d\n", rc);
  4739. return;
  4740. }
  4741. /* Now, unregister FCF record and reset HBA FCF state */
  4742. rc = lpfc_sli4_unregister_fcf(phba);
  4743. if (rc)
  4744. return;
  4745. /* Reset HBA FCF states after successful unregister FCF */
  4746. phba->fcf.fcf_flag = 0;
  4747. phba->fcf.current_rec.flag = 0;
  4748. /*
  4749. * If driver is not unloading, check if there is any other
  4750. * FCF record that can be used for discovery.
  4751. */
  4752. if ((phba->pport->load_flag & FC_UNLOADING) ||
  4753. (phba->link_state < LPFC_LINK_UP))
  4754. return;
  4755. /* This is considered as the initial FCF discovery scan */
  4756. spin_lock_irq(&phba->hbalock);
  4757. phba->fcf.fcf_flag |= FCF_INIT_DISC;
  4758. spin_unlock_irq(&phba->hbalock);
  4759. /* Reset FCF roundrobin bmask for new discovery */
  4760. memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
  4761. rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
  4762. if (rc) {
  4763. spin_lock_irq(&phba->hbalock);
  4764. phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
  4765. spin_unlock_irq(&phba->hbalock);
  4766. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  4767. "2553 lpfc_unregister_unused_fcf failed "
  4768. "to read FCF record HBA state x%x\n",
  4769. phba->pport->port_state);
  4770. }
  4771. }
  4772. /**
  4773. * lpfc_unregister_fcf - Unregister the currently registered fcf record
  4774. * @phba: Pointer to hba context object.
  4775. *
  4776. * This function just unregisters the currently reigstered FCF. It does not
  4777. * try to find another FCF for discovery.
  4778. */
  4779. void
  4780. lpfc_unregister_fcf(struct lpfc_hba *phba)
  4781. {
  4782. int rc;
  4783. /* Preparation for unregistering fcf */
  4784. rc = lpfc_unregister_fcf_prep(phba);
  4785. if (rc) {
  4786. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  4787. "2749 Failed to prepare for unregistering "
  4788. "HBA's FCF record: rc=%d\n", rc);
  4789. return;
  4790. }
  4791. /* Now, unregister FCF record and reset HBA FCF state */
  4792. rc = lpfc_sli4_unregister_fcf(phba);
  4793. if (rc)
  4794. return;
  4795. /* Set proper HBA FCF states after successful unregister FCF */
  4796. spin_lock_irq(&phba->hbalock);
  4797. phba->fcf.fcf_flag &= ~FCF_REGISTERED;
  4798. spin_unlock_irq(&phba->hbalock);
  4799. }
  4800. /**
  4801. * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
  4802. * @phba: Pointer to hba context object.
  4803. *
  4804. * This function check if there are any connected remote port for the FCF and
  4805. * if all the devices are disconnected, this function unregister FCFI.
  4806. * This function also tries to use another FCF for discovery.
  4807. */
  4808. void
  4809. lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
  4810. {
  4811. /*
  4812. * If HBA is not running in FIP mode, if HBA does not support
  4813. * FCoE, if FCF discovery is ongoing, or if FCF has not been
  4814. * registered, do nothing.
  4815. */
  4816. spin_lock_irq(&phba->hbalock);
  4817. if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
  4818. !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
  4819. !(phba->hba_flag & HBA_FIP_SUPPORT) ||
  4820. (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
  4821. (phba->pport->port_state == LPFC_FLOGI)) {
  4822. spin_unlock_irq(&phba->hbalock);
  4823. return;
  4824. }
  4825. spin_unlock_irq(&phba->hbalock);
  4826. if (lpfc_fcf_inuse(phba))
  4827. return;
  4828. lpfc_unregister_fcf_rescan(phba);
  4829. }
  4830. /**
  4831. * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
  4832. * @phba: Pointer to hba context object.
  4833. * @buff: Buffer containing the FCF connection table as in the config
  4834. * region.
  4835. * This function create driver data structure for the FCF connection
  4836. * record table read from config region 23.
  4837. */
  4838. static void
  4839. lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
  4840. uint8_t *buff)
  4841. {
  4842. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  4843. struct lpfc_fcf_conn_hdr *conn_hdr;
  4844. struct lpfc_fcf_conn_rec *conn_rec;
  4845. uint32_t record_count;
  4846. int i;
  4847. /* Free the current connect table */
  4848. list_for_each_entry_safe(conn_entry, next_conn_entry,
  4849. &phba->fcf_conn_rec_list, list) {
  4850. list_del_init(&conn_entry->list);
  4851. kfree(conn_entry);
  4852. }
  4853. conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
  4854. record_count = conn_hdr->length * sizeof(uint32_t)/
  4855. sizeof(struct lpfc_fcf_conn_rec);
  4856. conn_rec = (struct lpfc_fcf_conn_rec *)
  4857. (buff + sizeof(struct lpfc_fcf_conn_hdr));
  4858. for (i = 0; i < record_count; i++) {
  4859. if (!(conn_rec[i].flags & FCFCNCT_VALID))
  4860. continue;
  4861. conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
  4862. GFP_KERNEL);
  4863. if (!conn_entry) {
  4864. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4865. "2566 Failed to allocate connection"
  4866. " table entry\n");
  4867. return;
  4868. }
  4869. memcpy(&conn_entry->conn_rec, &conn_rec[i],
  4870. sizeof(struct lpfc_fcf_conn_rec));
  4871. conn_entry->conn_rec.vlan_tag =
  4872. le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
  4873. conn_entry->conn_rec.flags =
  4874. le16_to_cpu(conn_entry->conn_rec.flags);
  4875. list_add_tail(&conn_entry->list,
  4876. &phba->fcf_conn_rec_list);
  4877. }
  4878. }
  4879. /**
  4880. * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
  4881. * @phba: Pointer to hba context object.
  4882. * @buff: Buffer containing the FCoE parameter data structure.
  4883. *
  4884. * This function update driver data structure with config
  4885. * parameters read from config region 23.
  4886. */
  4887. static void
  4888. lpfc_read_fcoe_param(struct lpfc_hba *phba,
  4889. uint8_t *buff)
  4890. {
  4891. struct lpfc_fip_param_hdr *fcoe_param_hdr;
  4892. struct lpfc_fcoe_params *fcoe_param;
  4893. fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
  4894. buff;
  4895. fcoe_param = (struct lpfc_fcoe_params *)
  4896. (buff + sizeof(struct lpfc_fip_param_hdr));
  4897. if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
  4898. (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
  4899. return;
  4900. if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
  4901. phba->valid_vlan = 1;
  4902. phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
  4903. 0xFFF;
  4904. }
  4905. phba->fc_map[0] = fcoe_param->fc_map[0];
  4906. phba->fc_map[1] = fcoe_param->fc_map[1];
  4907. phba->fc_map[2] = fcoe_param->fc_map[2];
  4908. return;
  4909. }
  4910. /**
  4911. * lpfc_get_rec_conf23 - Get a record type in config region data.
  4912. * @buff: Buffer containing config region 23 data.
  4913. * @size: Size of the data buffer.
  4914. * @rec_type: Record type to be searched.
  4915. *
  4916. * This function searches config region data to find the begining
  4917. * of the record specified by record_type. If record found, this
  4918. * function return pointer to the record else return NULL.
  4919. */
  4920. static uint8_t *
  4921. lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
  4922. {
  4923. uint32_t offset = 0, rec_length;
  4924. if ((buff[0] == LPFC_REGION23_LAST_REC) ||
  4925. (size < sizeof(uint32_t)))
  4926. return NULL;
  4927. rec_length = buff[offset + 1];
  4928. /*
  4929. * One TLV record has one word header and number of data words
  4930. * specified in the rec_length field of the record header.
  4931. */
  4932. while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
  4933. <= size) {
  4934. if (buff[offset] == rec_type)
  4935. return &buff[offset];
  4936. if (buff[offset] == LPFC_REGION23_LAST_REC)
  4937. return NULL;
  4938. offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
  4939. rec_length = buff[offset + 1];
  4940. }
  4941. return NULL;
  4942. }
  4943. /**
  4944. * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
  4945. * @phba: Pointer to lpfc_hba data structure.
  4946. * @buff: Buffer containing config region 23 data.
  4947. * @size: Size of the data buffer.
  4948. *
  4949. * This function parses the FCoE config parameters in config region 23 and
  4950. * populate driver data structure with the parameters.
  4951. */
  4952. void
  4953. lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
  4954. uint8_t *buff,
  4955. uint32_t size)
  4956. {
  4957. uint32_t offset = 0, rec_length;
  4958. uint8_t *rec_ptr;
  4959. /*
  4960. * If data size is less than 2 words signature and version cannot be
  4961. * verified.
  4962. */
  4963. if (size < 2*sizeof(uint32_t))
  4964. return;
  4965. /* Check the region signature first */
  4966. if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
  4967. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4968. "2567 Config region 23 has bad signature\n");
  4969. return;
  4970. }
  4971. offset += 4;
  4972. /* Check the data structure version */
  4973. if (buff[offset] != LPFC_REGION23_VERSION) {
  4974. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  4975. "2568 Config region 23 has bad version\n");
  4976. return;
  4977. }
  4978. offset += 4;
  4979. rec_length = buff[offset + 1];
  4980. /* Read FCoE param record */
  4981. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  4982. size - offset, FCOE_PARAM_TYPE);
  4983. if (rec_ptr)
  4984. lpfc_read_fcoe_param(phba, rec_ptr);
  4985. /* Read FCF connection table */
  4986. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  4987. size - offset, FCOE_CONN_TBL_TYPE);
  4988. if (rec_ptr)
  4989. lpfc_read_fcf_conn_tbl(phba, rec_ptr);
  4990. }