lpfc_hbadisc.c 132 KB

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