lpfc_hbadisc.c 169 KB

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