lpfc_hbadisc.c 131 KB

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