lpfc_hbadisc.c 120 KB

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