lpfc_hbadisc.c 131 KB

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