lpfc_hbadisc.c 169 KB

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