lpfc_hbadisc.c 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/kthread.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_device.h>
  27. #include <scsi/scsi_host.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include "lpfc_hw4.h"
  30. #include "lpfc_hw.h"
  31. #include "lpfc_nl.h"
  32. #include "lpfc_disc.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_scsi.h"
  36. #include "lpfc.h"
  37. #include "lpfc_logmsg.h"
  38. #include "lpfc_crtn.h"
  39. #include "lpfc_vport.h"
  40. #include "lpfc_debugfs.h"
  41. /* AlpaArray for assignment of scsid for scan-down and bind_method */
  42. static uint8_t lpfcAlpaArray[] = {
  43. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
  44. 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
  45. 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
  46. 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
  47. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
  48. 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
  49. 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
  50. 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
  51. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
  52. 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
  53. 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
  54. 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
  55. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
  56. };
  57. static void lpfc_disc_timeout_handler(struct lpfc_vport *);
  58. static void lpfc_disc_flush_list(struct lpfc_vport *vport);
  59. 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. case LA_10GHZ_LINK:
  1481. phba->fc_linkspeed = LA_10GHZ_LINK;
  1482. break;
  1483. default:
  1484. phba->fc_linkspeed = LA_UNKNW_LINK;
  1485. break;
  1486. }
  1487. phba->fc_topology = la->topology;
  1488. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  1489. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1490. phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
  1491. if (phba->cfg_enable_npiv)
  1492. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1493. "1309 Link Up Event npiv not supported in loop "
  1494. "topology\n");
  1495. /* Get Loop Map information */
  1496. if (la->il)
  1497. vport->fc_flag |= FC_LBIT;
  1498. vport->fc_myDID = la->granted_AL_PA;
  1499. i = la->un.lilpBde64.tus.f.bdeSize;
  1500. if (i == 0) {
  1501. phba->alpa_map[0] = 0;
  1502. } else {
  1503. if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
  1504. int numalpa, j, k;
  1505. union {
  1506. uint8_t pamap[16];
  1507. struct {
  1508. uint32_t wd1;
  1509. uint32_t wd2;
  1510. uint32_t wd3;
  1511. uint32_t wd4;
  1512. } pa;
  1513. } un;
  1514. numalpa = phba->alpa_map[0];
  1515. j = 0;
  1516. while (j < numalpa) {
  1517. memset(un.pamap, 0, 16);
  1518. for (k = 1; j < numalpa; k++) {
  1519. un.pamap[k - 1] =
  1520. phba->alpa_map[j + 1];
  1521. j++;
  1522. if (k == 16)
  1523. break;
  1524. }
  1525. /* Link Up Event ALPA map */
  1526. lpfc_printf_log(phba,
  1527. KERN_WARNING,
  1528. LOG_LINK_EVENT,
  1529. "1304 Link Up Event "
  1530. "ALPA map Data: x%x "
  1531. "x%x x%x x%x\n",
  1532. un.pa.wd1, un.pa.wd2,
  1533. un.pa.wd3, un.pa.wd4);
  1534. }
  1535. }
  1536. }
  1537. } else {
  1538. if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
  1539. if (phba->max_vpi && phba->cfg_enable_npiv &&
  1540. (phba->sli_rev == 3))
  1541. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  1542. }
  1543. vport->fc_myDID = phba->fc_pref_DID;
  1544. vport->fc_flag |= FC_LBIT;
  1545. }
  1546. spin_unlock_irq(&phba->hbalock);
  1547. lpfc_linkup(phba);
  1548. if (sparam_mbox) {
  1549. lpfc_read_sparam(phba, sparam_mbox, 0);
  1550. sparam_mbox->vport = vport;
  1551. sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
  1552. rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
  1553. if (rc == MBX_NOT_FINISHED) {
  1554. mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
  1555. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1556. kfree(mp);
  1557. mempool_free(sparam_mbox, phba->mbox_mem_pool);
  1558. goto out;
  1559. }
  1560. }
  1561. if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) {
  1562. cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1563. if (!cfglink_mbox)
  1564. goto out;
  1565. vport->port_state = LPFC_LOCAL_CFG_LINK;
  1566. lpfc_config_link(phba, cfglink_mbox);
  1567. cfglink_mbox->vport = vport;
  1568. cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
  1569. rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
  1570. if (rc == MBX_NOT_FINISHED) {
  1571. mempool_free(cfglink_mbox, phba->mbox_mem_pool);
  1572. goto out;
  1573. }
  1574. } else {
  1575. /*
  1576. * Add the driver's default FCF record at FCF index 0 now. This
  1577. * is phase 1 implementation that support FCF index 0 and driver
  1578. * defaults.
  1579. */
  1580. if (phba->cfg_enable_fip == 0) {
  1581. fcf_record = kzalloc(sizeof(struct fcf_record),
  1582. GFP_KERNEL);
  1583. if (unlikely(!fcf_record)) {
  1584. lpfc_printf_log(phba, KERN_ERR,
  1585. LOG_MBOX | LOG_SLI,
  1586. "2554 Could not allocate memmory for "
  1587. "fcf record\n");
  1588. rc = -ENODEV;
  1589. goto out;
  1590. }
  1591. lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
  1592. LPFC_FCOE_FCF_DEF_INDEX);
  1593. rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
  1594. if (unlikely(rc)) {
  1595. lpfc_printf_log(phba, KERN_ERR,
  1596. LOG_MBOX | LOG_SLI,
  1597. "2013 Could not manually add FCF "
  1598. "record 0, status %d\n", rc);
  1599. rc = -ENODEV;
  1600. kfree(fcf_record);
  1601. goto out;
  1602. }
  1603. kfree(fcf_record);
  1604. }
  1605. /*
  1606. * The driver is expected to do FIP/FCF. Call the port
  1607. * and get the FCF Table.
  1608. */
  1609. rc = lpfc_sli4_read_fcf_record(phba,
  1610. LPFC_FCOE_FCF_GET_FIRST);
  1611. if (rc)
  1612. goto out;
  1613. }
  1614. return;
  1615. out:
  1616. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1617. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1618. "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
  1619. vport->port_state, sparam_mbox, cfglink_mbox);
  1620. lpfc_issue_clear_la(phba, vport);
  1621. return;
  1622. }
  1623. static void
  1624. lpfc_enable_la(struct lpfc_hba *phba)
  1625. {
  1626. uint32_t control;
  1627. struct lpfc_sli *psli = &phba->sli;
  1628. spin_lock_irq(&phba->hbalock);
  1629. psli->sli_flag |= LPFC_PROCESS_LA;
  1630. if (phba->sli_rev <= LPFC_SLI_REV3) {
  1631. control = readl(phba->HCregaddr);
  1632. control |= HC_LAINT_ENA;
  1633. writel(control, phba->HCregaddr);
  1634. readl(phba->HCregaddr); /* flush */
  1635. }
  1636. spin_unlock_irq(&phba->hbalock);
  1637. }
  1638. static void
  1639. lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
  1640. {
  1641. lpfc_linkdown(phba);
  1642. lpfc_enable_la(phba);
  1643. lpfc_unregister_unused_fcf(phba);
  1644. /* turn on Link Attention interrupts - no CLEAR_LA needed */
  1645. }
  1646. /*
  1647. * This routine handles processing a READ_LA mailbox
  1648. * command upon completion. It is setup in the LPFC_MBOXQ
  1649. * as the completion routine when the command is
  1650. * handed off to the SLI layer.
  1651. */
  1652. void
  1653. lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1654. {
  1655. struct lpfc_vport *vport = pmb->vport;
  1656. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1657. READ_LA_VAR *la;
  1658. MAILBOX_t *mb = &pmb->u.mb;
  1659. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1660. /* Unblock ELS traffic */
  1661. phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
  1662. /* Check for error */
  1663. if (mb->mbxStatus) {
  1664. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1665. "1307 READ_LA mbox error x%x state x%x\n",
  1666. mb->mbxStatus, vport->port_state);
  1667. lpfc_mbx_issue_link_down(phba);
  1668. phba->link_state = LPFC_HBA_ERROR;
  1669. goto lpfc_mbx_cmpl_read_la_free_mbuf;
  1670. }
  1671. la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
  1672. memcpy(&phba->alpa_map[0], mp->virt, 128);
  1673. spin_lock_irq(shost->host_lock);
  1674. if (la->pb)
  1675. vport->fc_flag |= FC_BYPASSED_MODE;
  1676. else
  1677. vport->fc_flag &= ~FC_BYPASSED_MODE;
  1678. spin_unlock_irq(shost->host_lock);
  1679. if (((phba->fc_eventTag + 1) < la->eventTag) ||
  1680. (phba->fc_eventTag == la->eventTag)) {
  1681. phba->fc_stat.LinkMultiEvent++;
  1682. if (la->attType == AT_LINK_UP)
  1683. if (phba->fc_eventTag != 0)
  1684. lpfc_linkdown(phba);
  1685. }
  1686. phba->fc_eventTag = la->eventTag;
  1687. if (la->mm)
  1688. phba->sli.sli_flag |= LPFC_MENLO_MAINT;
  1689. else
  1690. phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
  1691. if (la->attType == AT_LINK_UP && (!la->mm)) {
  1692. phba->fc_stat.LinkUp++;
  1693. if (phba->link_flag & LS_LOOPBACK_MODE) {
  1694. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1695. "1306 Link Up Event in loop back mode "
  1696. "x%x received Data: x%x x%x x%x x%x\n",
  1697. la->eventTag, phba->fc_eventTag,
  1698. la->granted_AL_PA, la->UlnkSpeed,
  1699. phba->alpa_map[0]);
  1700. } else {
  1701. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1702. "1303 Link Up Event x%x received "
  1703. "Data: x%x x%x x%x x%x x%x x%x %d\n",
  1704. la->eventTag, phba->fc_eventTag,
  1705. la->granted_AL_PA, la->UlnkSpeed,
  1706. phba->alpa_map[0],
  1707. la->mm, la->fa,
  1708. phba->wait_4_mlo_maint_flg);
  1709. }
  1710. lpfc_mbx_process_link_up(phba, la);
  1711. } else if (la->attType == AT_LINK_DOWN) {
  1712. phba->fc_stat.LinkDown++;
  1713. if (phba->link_flag & LS_LOOPBACK_MODE) {
  1714. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1715. "1308 Link Down Event in loop back mode "
  1716. "x%x received "
  1717. "Data: x%x x%x x%x\n",
  1718. la->eventTag, phba->fc_eventTag,
  1719. phba->pport->port_state, vport->fc_flag);
  1720. }
  1721. else {
  1722. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1723. "1305 Link Down Event x%x received "
  1724. "Data: x%x x%x x%x x%x x%x\n",
  1725. la->eventTag, phba->fc_eventTag,
  1726. phba->pport->port_state, vport->fc_flag,
  1727. la->mm, la->fa);
  1728. }
  1729. lpfc_mbx_issue_link_down(phba);
  1730. }
  1731. if (la->mm && la->attType == AT_LINK_UP) {
  1732. if (phba->link_state != LPFC_LINK_DOWN) {
  1733. phba->fc_stat.LinkDown++;
  1734. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1735. "1312 Link Down Event x%x received "
  1736. "Data: x%x x%x x%x\n",
  1737. la->eventTag, phba->fc_eventTag,
  1738. phba->pport->port_state, vport->fc_flag);
  1739. lpfc_mbx_issue_link_down(phba);
  1740. } else
  1741. lpfc_enable_la(phba);
  1742. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1743. "1310 Menlo Maint Mode Link up Event x%x rcvd "
  1744. "Data: x%x x%x x%x\n",
  1745. la->eventTag, phba->fc_eventTag,
  1746. phba->pport->port_state, vport->fc_flag);
  1747. /*
  1748. * The cmnd that triggered this will be waiting for this
  1749. * signal.
  1750. */
  1751. /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
  1752. if (phba->wait_4_mlo_maint_flg) {
  1753. phba->wait_4_mlo_maint_flg = 0;
  1754. wake_up_interruptible(&phba->wait_4_mlo_m_q);
  1755. }
  1756. }
  1757. if (la->fa) {
  1758. if (la->mm)
  1759. lpfc_issue_clear_la(phba, vport);
  1760. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  1761. "1311 fa %d\n", la->fa);
  1762. }
  1763. lpfc_mbx_cmpl_read_la_free_mbuf:
  1764. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1765. kfree(mp);
  1766. mempool_free(pmb, phba->mbox_mem_pool);
  1767. return;
  1768. }
  1769. /*
  1770. * This routine handles processing a REG_LOGIN mailbox
  1771. * command upon completion. It is setup in the LPFC_MBOXQ
  1772. * as the completion routine when the command is
  1773. * handed off to the SLI layer.
  1774. */
  1775. void
  1776. lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1777. {
  1778. struct lpfc_vport *vport = pmb->vport;
  1779. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1780. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  1781. pmb->context1 = NULL;
  1782. /* Good status, call state machine */
  1783. lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
  1784. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1785. kfree(mp);
  1786. mempool_free(pmb, phba->mbox_mem_pool);
  1787. /* decrement the node reference count held for this callback
  1788. * function.
  1789. */
  1790. lpfc_nlp_put(ndlp);
  1791. return;
  1792. }
  1793. static void
  1794. lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1795. {
  1796. MAILBOX_t *mb = &pmb->u.mb;
  1797. struct lpfc_vport *vport = pmb->vport;
  1798. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1799. switch (mb->mbxStatus) {
  1800. case 0x0011:
  1801. case 0x0020:
  1802. case 0x9700:
  1803. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1804. "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
  1805. mb->mbxStatus);
  1806. break;
  1807. }
  1808. vport->unreg_vpi_cmpl = VPORT_OK;
  1809. mempool_free(pmb, phba->mbox_mem_pool);
  1810. /*
  1811. * This shost reference might have been taken at the beginning of
  1812. * lpfc_vport_delete()
  1813. */
  1814. if (vport->load_flag & FC_UNLOADING)
  1815. scsi_host_put(shost);
  1816. }
  1817. int
  1818. lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
  1819. {
  1820. struct lpfc_hba *phba = vport->phba;
  1821. LPFC_MBOXQ_t *mbox;
  1822. int rc;
  1823. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1824. if (!mbox)
  1825. return 1;
  1826. lpfc_unreg_vpi(phba, vport->vpi, mbox);
  1827. mbox->vport = vport;
  1828. mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
  1829. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  1830. if (rc == MBX_NOT_FINISHED) {
  1831. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  1832. "1800 Could not issue unreg_vpi\n");
  1833. mempool_free(mbox, phba->mbox_mem_pool);
  1834. vport->unreg_vpi_cmpl = VPORT_ERROR;
  1835. return rc;
  1836. }
  1837. return 0;
  1838. }
  1839. static void
  1840. lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1841. {
  1842. struct lpfc_vport *vport = pmb->vport;
  1843. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1844. MAILBOX_t *mb = &pmb->u.mb;
  1845. switch (mb->mbxStatus) {
  1846. case 0x0011:
  1847. case 0x9601:
  1848. case 0x9602:
  1849. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  1850. "0912 cmpl_reg_vpi, mb status = 0x%x\n",
  1851. mb->mbxStatus);
  1852. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  1853. spin_lock_irq(shost->host_lock);
  1854. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  1855. spin_unlock_irq(shost->host_lock);
  1856. vport->fc_myDID = 0;
  1857. goto out;
  1858. }
  1859. vport->num_disc_nodes = 0;
  1860. /* go thru NPR list and issue ELS PLOGIs */
  1861. if (vport->fc_npr_cnt)
  1862. lpfc_els_disc_plogi(vport);
  1863. if (!vport->num_disc_nodes) {
  1864. spin_lock_irq(shost->host_lock);
  1865. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1866. spin_unlock_irq(shost->host_lock);
  1867. lpfc_can_disctmo(vport);
  1868. }
  1869. vport->port_state = LPFC_VPORT_READY;
  1870. out:
  1871. mempool_free(pmb, phba->mbox_mem_pool);
  1872. return;
  1873. }
  1874. /**
  1875. * lpfc_create_static_vport - Read HBA config region to create static vports.
  1876. * @phba: pointer to lpfc hba data structure.
  1877. *
  1878. * This routine issue a DUMP mailbox command for config region 22 to get
  1879. * the list of static vports to be created. The function create vports
  1880. * based on the information returned from the HBA.
  1881. **/
  1882. void
  1883. lpfc_create_static_vport(struct lpfc_hba *phba)
  1884. {
  1885. LPFC_MBOXQ_t *pmb = NULL;
  1886. MAILBOX_t *mb;
  1887. struct static_vport_info *vport_info;
  1888. int rc, i;
  1889. struct fc_vport_identifiers vport_id;
  1890. struct fc_vport *new_fc_vport;
  1891. struct Scsi_Host *shost;
  1892. struct lpfc_vport *vport;
  1893. uint16_t offset = 0;
  1894. uint8_t *vport_buff;
  1895. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1896. if (!pmb) {
  1897. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1898. "0542 lpfc_create_static_vport failed to"
  1899. " allocate mailbox memory\n");
  1900. return;
  1901. }
  1902. mb = &pmb->u.mb;
  1903. vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
  1904. if (!vport_info) {
  1905. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1906. "0543 lpfc_create_static_vport failed to"
  1907. " allocate vport_info\n");
  1908. mempool_free(pmb, phba->mbox_mem_pool);
  1909. return;
  1910. }
  1911. vport_buff = (uint8_t *) vport_info;
  1912. do {
  1913. lpfc_dump_static_vport(phba, pmb, offset);
  1914. pmb->vport = phba->pport;
  1915. rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
  1916. if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
  1917. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1918. "0544 lpfc_create_static_vport failed to"
  1919. " issue dump mailbox command ret 0x%x "
  1920. "status 0x%x\n",
  1921. rc, mb->mbxStatus);
  1922. goto out;
  1923. }
  1924. if (mb->un.varDmp.word_cnt >
  1925. sizeof(struct static_vport_info) - offset)
  1926. mb->un.varDmp.word_cnt =
  1927. sizeof(struct static_vport_info) - offset;
  1928. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  1929. vport_buff + offset,
  1930. mb->un.varDmp.word_cnt);
  1931. offset += mb->un.varDmp.word_cnt;
  1932. } while (mb->un.varDmp.word_cnt &&
  1933. offset < sizeof(struct static_vport_info));
  1934. if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
  1935. ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
  1936. != VPORT_INFO_REV)) {
  1937. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1938. "0545 lpfc_create_static_vport bad"
  1939. " information header 0x%x 0x%x\n",
  1940. le32_to_cpu(vport_info->signature),
  1941. le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
  1942. goto out;
  1943. }
  1944. shost = lpfc_shost_from_vport(phba->pport);
  1945. for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
  1946. memset(&vport_id, 0, sizeof(vport_id));
  1947. vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
  1948. vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
  1949. if (!vport_id.port_name || !vport_id.node_name)
  1950. continue;
  1951. vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
  1952. vport_id.vport_type = FC_PORTTYPE_NPIV;
  1953. vport_id.disable = false;
  1954. new_fc_vport = fc_vport_create(shost, 0, &vport_id);
  1955. if (!new_fc_vport) {
  1956. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1957. "0546 lpfc_create_static_vport failed to"
  1958. " create vport \n");
  1959. continue;
  1960. }
  1961. vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
  1962. vport->vport_flag |= STATIC_VPORT;
  1963. }
  1964. out:
  1965. /*
  1966. * If this is timed out command, setting NULL to context2 tell SLI
  1967. * layer not to use this buffer.
  1968. */
  1969. spin_lock_irq(&phba->hbalock);
  1970. pmb->context2 = NULL;
  1971. spin_unlock_irq(&phba->hbalock);
  1972. kfree(vport_info);
  1973. if (rc != MBX_TIMEOUT)
  1974. mempool_free(pmb, phba->mbox_mem_pool);
  1975. return;
  1976. }
  1977. /*
  1978. * This routine handles processing a Fabric REG_LOGIN mailbox
  1979. * command upon completion. It is setup in the LPFC_MBOXQ
  1980. * as the completion routine when the command is
  1981. * handed off to the SLI layer.
  1982. */
  1983. void
  1984. lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1985. {
  1986. struct lpfc_vport *vport = pmb->vport;
  1987. MAILBOX_t *mb = &pmb->u.mb;
  1988. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1989. struct lpfc_nodelist *ndlp;
  1990. ndlp = (struct lpfc_nodelist *) pmb->context2;
  1991. pmb->context1 = NULL;
  1992. pmb->context2 = NULL;
  1993. if (mb->mbxStatus) {
  1994. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  1995. "0258 Register Fabric login error: 0x%x\n",
  1996. mb->mbxStatus);
  1997. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1998. kfree(mp);
  1999. mempool_free(pmb, phba->mbox_mem_pool);
  2000. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2001. /* FLOGI failed, use loop map to make discovery list */
  2002. lpfc_disc_list_loopmap(vport);
  2003. /* Start discovery */
  2004. lpfc_disc_start(vport);
  2005. /* Decrement the reference count to ndlp after the
  2006. * reference to the ndlp are done.
  2007. */
  2008. lpfc_nlp_put(ndlp);
  2009. return;
  2010. }
  2011. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2012. /* Decrement the reference count to ndlp after the reference
  2013. * to the ndlp are done.
  2014. */
  2015. lpfc_nlp_put(ndlp);
  2016. return;
  2017. }
  2018. ndlp->nlp_rpi = mb->un.varWords[0];
  2019. ndlp->nlp_flag |= NLP_RPI_VALID;
  2020. ndlp->nlp_type |= NLP_FABRIC;
  2021. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2022. if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
  2023. lpfc_start_fdiscs(phba);
  2024. lpfc_do_scr_ns_plogi(phba, vport);
  2025. }
  2026. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2027. kfree(mp);
  2028. mempool_free(pmb, phba->mbox_mem_pool);
  2029. /* Drop the reference count from the mbox at the end after
  2030. * all the current reference to the ndlp have been done.
  2031. */
  2032. lpfc_nlp_put(ndlp);
  2033. return;
  2034. }
  2035. /*
  2036. * This routine handles processing a NameServer REG_LOGIN mailbox
  2037. * command upon completion. It is setup in the LPFC_MBOXQ
  2038. * as the completion routine when the command is
  2039. * handed off to the SLI layer.
  2040. */
  2041. void
  2042. lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2043. {
  2044. MAILBOX_t *mb = &pmb->u.mb;
  2045. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  2046. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  2047. struct lpfc_vport *vport = pmb->vport;
  2048. if (mb->mbxStatus) {
  2049. out:
  2050. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2051. "0260 Register NameServer error: 0x%x\n",
  2052. mb->mbxStatus);
  2053. /* decrement the node reference count held for this
  2054. * callback function.
  2055. */
  2056. lpfc_nlp_put(ndlp);
  2057. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2058. kfree(mp);
  2059. mempool_free(pmb, phba->mbox_mem_pool);
  2060. /* If no other thread is using the ndlp, free it */
  2061. lpfc_nlp_not_used(ndlp);
  2062. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2063. /*
  2064. * RegLogin failed, use loop map to make discovery
  2065. * list
  2066. */
  2067. lpfc_disc_list_loopmap(vport);
  2068. /* Start discovery */
  2069. lpfc_disc_start(vport);
  2070. return;
  2071. }
  2072. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  2073. return;
  2074. }
  2075. pmb->context1 = NULL;
  2076. ndlp->nlp_rpi = mb->un.varWords[0];
  2077. ndlp->nlp_flag |= NLP_RPI_VALID;
  2078. ndlp->nlp_type |= NLP_FABRIC;
  2079. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2080. if (vport->port_state < LPFC_VPORT_READY) {
  2081. /* Link up discovery requires Fabric registration. */
  2082. lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
  2083. lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
  2084. lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
  2085. lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
  2086. lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
  2087. /* Issue SCR just before NameServer GID_FT Query */
  2088. lpfc_issue_els_scr(vport, SCR_DID, 0);
  2089. }
  2090. vport->fc_ns_retry = 0;
  2091. /* Good status, issue CT Request to NameServer */
  2092. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
  2093. /* Cannot issue NameServer Query, so finish up discovery */
  2094. goto out;
  2095. }
  2096. /* decrement the node reference count held for this
  2097. * callback function.
  2098. */
  2099. lpfc_nlp_put(ndlp);
  2100. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2101. kfree(mp);
  2102. mempool_free(pmb, phba->mbox_mem_pool);
  2103. return;
  2104. }
  2105. static void
  2106. lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2107. {
  2108. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2109. struct fc_rport *rport;
  2110. struct lpfc_rport_data *rdata;
  2111. struct fc_rport_identifiers rport_ids;
  2112. struct lpfc_hba *phba = vport->phba;
  2113. /* Remote port has reappeared. Re-register w/ FC transport */
  2114. rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  2115. rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  2116. rport_ids.port_id = ndlp->nlp_DID;
  2117. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2118. /*
  2119. * We leave our node pointer in rport->dd_data when we unregister a
  2120. * FCP target port. But fc_remote_port_add zeros the space to which
  2121. * rport->dd_data points. So, if we're reusing a previously
  2122. * registered port, drop the reference that we took the last time we
  2123. * registered the port.
  2124. */
  2125. if (ndlp->rport && ndlp->rport->dd_data &&
  2126. ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
  2127. lpfc_nlp_put(ndlp);
  2128. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
  2129. "rport add: did:x%x flg:x%x type x%x",
  2130. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2131. ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
  2132. if (!rport || !get_device(&rport->dev)) {
  2133. dev_printk(KERN_WARNING, &phba->pcidev->dev,
  2134. "Warning: fc_remote_port_add failed\n");
  2135. return;
  2136. }
  2137. /* initialize static port data */
  2138. rport->maxframe_size = ndlp->nlp_maxframe;
  2139. rport->supported_classes = ndlp->nlp_class_sup;
  2140. rdata = rport->dd_data;
  2141. rdata->pnode = lpfc_nlp_get(ndlp);
  2142. if (ndlp->nlp_type & NLP_FCP_TARGET)
  2143. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2144. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  2145. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2146. if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
  2147. fc_remote_port_rolechg(rport, rport_ids.roles);
  2148. if ((rport->scsi_target_id != -1) &&
  2149. (rport->scsi_target_id < LPFC_MAX_TARGET)) {
  2150. ndlp->nlp_sid = rport->scsi_target_id;
  2151. }
  2152. return;
  2153. }
  2154. static void
  2155. lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
  2156. {
  2157. struct fc_rport *rport = ndlp->rport;
  2158. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
  2159. "rport delete: did:x%x flg:x%x type x%x",
  2160. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  2161. fc_remote_port_delete(rport);
  2162. return;
  2163. }
  2164. static void
  2165. lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
  2166. {
  2167. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2168. spin_lock_irq(shost->host_lock);
  2169. switch (state) {
  2170. case NLP_STE_UNUSED_NODE:
  2171. vport->fc_unused_cnt += count;
  2172. break;
  2173. case NLP_STE_PLOGI_ISSUE:
  2174. vport->fc_plogi_cnt += count;
  2175. break;
  2176. case NLP_STE_ADISC_ISSUE:
  2177. vport->fc_adisc_cnt += count;
  2178. break;
  2179. case NLP_STE_REG_LOGIN_ISSUE:
  2180. vport->fc_reglogin_cnt += count;
  2181. break;
  2182. case NLP_STE_PRLI_ISSUE:
  2183. vport->fc_prli_cnt += count;
  2184. break;
  2185. case NLP_STE_UNMAPPED_NODE:
  2186. vport->fc_unmap_cnt += count;
  2187. break;
  2188. case NLP_STE_MAPPED_NODE:
  2189. vport->fc_map_cnt += count;
  2190. break;
  2191. case NLP_STE_NPR_NODE:
  2192. vport->fc_npr_cnt += count;
  2193. break;
  2194. }
  2195. spin_unlock_irq(shost->host_lock);
  2196. }
  2197. static void
  2198. lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2199. int old_state, int new_state)
  2200. {
  2201. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2202. if (new_state == NLP_STE_UNMAPPED_NODE) {
  2203. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  2204. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  2205. ndlp->nlp_type |= NLP_FC_NODE;
  2206. }
  2207. if (new_state == NLP_STE_MAPPED_NODE)
  2208. ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
  2209. if (new_state == NLP_STE_NPR_NODE)
  2210. ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
  2211. /* Transport interface */
  2212. if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
  2213. old_state == NLP_STE_UNMAPPED_NODE)) {
  2214. vport->phba->nport_event_cnt++;
  2215. lpfc_unregister_remote_port(ndlp);
  2216. }
  2217. if (new_state == NLP_STE_MAPPED_NODE ||
  2218. new_state == NLP_STE_UNMAPPED_NODE) {
  2219. vport->phba->nport_event_cnt++;
  2220. /*
  2221. * Tell the fc transport about the port, if we haven't
  2222. * already. If we have, and it's a scsi entity, be
  2223. * sure to unblock any attached scsi devices
  2224. */
  2225. lpfc_register_remote_port(vport, ndlp);
  2226. }
  2227. if ((new_state == NLP_STE_MAPPED_NODE) &&
  2228. (vport->stat_data_enabled)) {
  2229. /*
  2230. * A new target is discovered, if there is no buffer for
  2231. * statistical data collection allocate buffer.
  2232. */
  2233. ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
  2234. sizeof(struct lpfc_scsicmd_bkt),
  2235. GFP_KERNEL);
  2236. if (!ndlp->lat_data)
  2237. lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
  2238. "0286 lpfc_nlp_state_cleanup failed to "
  2239. "allocate statistical data buffer DID "
  2240. "0x%x\n", ndlp->nlp_DID);
  2241. }
  2242. /*
  2243. * if we added to Mapped list, but the remote port
  2244. * registration failed or assigned a target id outside
  2245. * our presentable range - move the node to the
  2246. * Unmapped List
  2247. */
  2248. if (new_state == NLP_STE_MAPPED_NODE &&
  2249. (!ndlp->rport ||
  2250. ndlp->rport->scsi_target_id == -1 ||
  2251. ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
  2252. spin_lock_irq(shost->host_lock);
  2253. ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
  2254. spin_unlock_irq(shost->host_lock);
  2255. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  2256. }
  2257. }
  2258. static char *
  2259. lpfc_nlp_state_name(char *buffer, size_t size, int state)
  2260. {
  2261. static char *states[] = {
  2262. [NLP_STE_UNUSED_NODE] = "UNUSED",
  2263. [NLP_STE_PLOGI_ISSUE] = "PLOGI",
  2264. [NLP_STE_ADISC_ISSUE] = "ADISC",
  2265. [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
  2266. [NLP_STE_PRLI_ISSUE] = "PRLI",
  2267. [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
  2268. [NLP_STE_MAPPED_NODE] = "MAPPED",
  2269. [NLP_STE_NPR_NODE] = "NPR",
  2270. };
  2271. if (state < NLP_STE_MAX_STATE && states[state])
  2272. strlcpy(buffer, states[state], size);
  2273. else
  2274. snprintf(buffer, size, "unknown (%d)", state);
  2275. return buffer;
  2276. }
  2277. void
  2278. lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2279. int state)
  2280. {
  2281. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2282. int old_state = ndlp->nlp_state;
  2283. char name1[16], name2[16];
  2284. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2285. "0904 NPort state transition x%06x, %s -> %s\n",
  2286. ndlp->nlp_DID,
  2287. lpfc_nlp_state_name(name1, sizeof(name1), old_state),
  2288. lpfc_nlp_state_name(name2, sizeof(name2), state));
  2289. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2290. "node statechg did:x%x old:%d ste:%d",
  2291. ndlp->nlp_DID, old_state, state);
  2292. if (old_state == NLP_STE_NPR_NODE &&
  2293. state != NLP_STE_NPR_NODE)
  2294. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2295. if (old_state == NLP_STE_UNMAPPED_NODE) {
  2296. ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
  2297. ndlp->nlp_type &= ~NLP_FC_NODE;
  2298. }
  2299. if (list_empty(&ndlp->nlp_listp)) {
  2300. spin_lock_irq(shost->host_lock);
  2301. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  2302. spin_unlock_irq(shost->host_lock);
  2303. } else if (old_state)
  2304. lpfc_nlp_counters(vport, old_state, -1);
  2305. ndlp->nlp_state = state;
  2306. lpfc_nlp_counters(vport, state, 1);
  2307. lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
  2308. }
  2309. void
  2310. lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2311. {
  2312. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2313. if (list_empty(&ndlp->nlp_listp)) {
  2314. spin_lock_irq(shost->host_lock);
  2315. list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
  2316. spin_unlock_irq(shost->host_lock);
  2317. }
  2318. }
  2319. void
  2320. lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2321. {
  2322. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2323. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2324. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  2325. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  2326. spin_lock_irq(shost->host_lock);
  2327. list_del_init(&ndlp->nlp_listp);
  2328. spin_unlock_irq(shost->host_lock);
  2329. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  2330. NLP_STE_UNUSED_NODE);
  2331. }
  2332. static void
  2333. lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2334. {
  2335. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2336. if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
  2337. lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
  2338. lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
  2339. NLP_STE_UNUSED_NODE);
  2340. }
  2341. /**
  2342. * lpfc_initialize_node - Initialize all fields of node object
  2343. * @vport: Pointer to Virtual Port object.
  2344. * @ndlp: Pointer to FC node object.
  2345. * @did: FC_ID of the node.
  2346. *
  2347. * This function is always called when node object need to be initialized.
  2348. * It initializes all the fields of the node object. Although the reference
  2349. * to phba from @ndlp can be obtained indirectly through it's reference to
  2350. * @vport, a direct reference to phba is taken here by @ndlp. This is due
  2351. * to the life-span of the @ndlp might go beyond the existence of @vport as
  2352. * the final release of ndlp is determined by its reference count. And, the
  2353. * operation on @ndlp needs the reference to phba.
  2354. **/
  2355. static inline void
  2356. lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2357. uint32_t did)
  2358. {
  2359. INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
  2360. INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
  2361. init_timer(&ndlp->nlp_delayfunc);
  2362. ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
  2363. ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
  2364. ndlp->nlp_DID = did;
  2365. ndlp->vport = vport;
  2366. ndlp->phba = vport->phba;
  2367. ndlp->nlp_sid = NLP_NO_SID;
  2368. kref_init(&ndlp->kref);
  2369. NLP_INT_NODE_ACT(ndlp);
  2370. atomic_set(&ndlp->cmd_pending, 0);
  2371. ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
  2372. }
  2373. struct lpfc_nodelist *
  2374. lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2375. int state)
  2376. {
  2377. struct lpfc_hba *phba = vport->phba;
  2378. uint32_t did;
  2379. unsigned long flags;
  2380. if (!ndlp)
  2381. return NULL;
  2382. spin_lock_irqsave(&phba->ndlp_lock, flags);
  2383. /* The ndlp should not be in memory free mode */
  2384. if (NLP_CHK_FREE_REQ(ndlp)) {
  2385. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2386. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2387. "0277 lpfc_enable_node: ndlp:x%p "
  2388. "usgmap:x%x refcnt:%d\n",
  2389. (void *)ndlp, ndlp->nlp_usg_map,
  2390. atomic_read(&ndlp->kref.refcount));
  2391. return NULL;
  2392. }
  2393. /* The ndlp should not already be in active mode */
  2394. if (NLP_CHK_NODE_ACT(ndlp)) {
  2395. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2396. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2397. "0278 lpfc_enable_node: ndlp:x%p "
  2398. "usgmap:x%x refcnt:%d\n",
  2399. (void *)ndlp, ndlp->nlp_usg_map,
  2400. atomic_read(&ndlp->kref.refcount));
  2401. return NULL;
  2402. }
  2403. /* Keep the original DID */
  2404. did = ndlp->nlp_DID;
  2405. /* re-initialize ndlp except of ndlp linked list pointer */
  2406. memset((((char *)ndlp) + sizeof (struct list_head)), 0,
  2407. sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
  2408. lpfc_initialize_node(vport, ndlp, did);
  2409. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  2410. if (state != NLP_STE_UNUSED_NODE)
  2411. lpfc_nlp_set_state(vport, ndlp, state);
  2412. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  2413. "node enable: did:x%x",
  2414. ndlp->nlp_DID, 0, 0);
  2415. return ndlp;
  2416. }
  2417. void
  2418. lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2419. {
  2420. /*
  2421. * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
  2422. * be used if we wish to issue the "last" lpfc_nlp_put() to remove
  2423. * the ndlp from the vport. The ndlp marked as UNUSED on the list
  2424. * until ALL other outstanding threads have completed. We check
  2425. * that the ndlp not already in the UNUSED state before we proceed.
  2426. */
  2427. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  2428. return;
  2429. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
  2430. lpfc_nlp_put(ndlp);
  2431. return;
  2432. }
  2433. /*
  2434. * Start / ReStart rescue timer for Discovery / RSCN handling
  2435. */
  2436. void
  2437. lpfc_set_disctmo(struct lpfc_vport *vport)
  2438. {
  2439. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2440. struct lpfc_hba *phba = vport->phba;
  2441. uint32_t tmo;
  2442. if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
  2443. /* For FAN, timeout should be greater than edtov */
  2444. tmo = (((phba->fc_edtov + 999) / 1000) + 1);
  2445. } else {
  2446. /* Normal discovery timeout should be > than ELS/CT timeout
  2447. * FC spec states we need 3 * ratov for CT requests
  2448. */
  2449. tmo = ((phba->fc_ratov * 3) + 3);
  2450. }
  2451. if (!timer_pending(&vport->fc_disctmo)) {
  2452. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2453. "set disc timer: tmo:x%x state:x%x flg:x%x",
  2454. tmo, vport->port_state, vport->fc_flag);
  2455. }
  2456. mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
  2457. spin_lock_irq(shost->host_lock);
  2458. vport->fc_flag |= FC_DISC_TMO;
  2459. spin_unlock_irq(shost->host_lock);
  2460. /* Start Discovery Timer state <hba_state> */
  2461. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2462. "0247 Start Discovery Timer state x%x "
  2463. "Data: x%x x%lx x%x x%x\n",
  2464. vport->port_state, tmo,
  2465. (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
  2466. vport->fc_adisc_cnt);
  2467. return;
  2468. }
  2469. /*
  2470. * Cancel rescue timer for Discovery / RSCN handling
  2471. */
  2472. int
  2473. lpfc_can_disctmo(struct lpfc_vport *vport)
  2474. {
  2475. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2476. unsigned long iflags;
  2477. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  2478. "can disc timer: state:x%x rtry:x%x flg:x%x",
  2479. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  2480. /* Turn off discovery timer if its running */
  2481. if (vport->fc_flag & FC_DISC_TMO) {
  2482. spin_lock_irqsave(shost->host_lock, iflags);
  2483. vport->fc_flag &= ~FC_DISC_TMO;
  2484. spin_unlock_irqrestore(shost->host_lock, iflags);
  2485. del_timer_sync(&vport->fc_disctmo);
  2486. spin_lock_irqsave(&vport->work_port_lock, iflags);
  2487. vport->work_port_events &= ~WORKER_DISC_TMO;
  2488. spin_unlock_irqrestore(&vport->work_port_lock, iflags);
  2489. }
  2490. /* Cancel Discovery Timer state <hba_state> */
  2491. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2492. "0248 Cancel Discovery Timer state x%x "
  2493. "Data: x%x x%x x%x\n",
  2494. vport->port_state, vport->fc_flag,
  2495. vport->fc_plogi_cnt, vport->fc_adisc_cnt);
  2496. return 0;
  2497. }
  2498. /*
  2499. * Check specified ring for outstanding IOCB on the SLI queue
  2500. * Return true if iocb matches the specified nport
  2501. */
  2502. int
  2503. lpfc_check_sli_ndlp(struct lpfc_hba *phba,
  2504. struct lpfc_sli_ring *pring,
  2505. struct lpfc_iocbq *iocb,
  2506. struct lpfc_nodelist *ndlp)
  2507. {
  2508. struct lpfc_sli *psli = &phba->sli;
  2509. IOCB_t *icmd = &iocb->iocb;
  2510. struct lpfc_vport *vport = ndlp->vport;
  2511. if (iocb->vport != vport)
  2512. return 0;
  2513. if (pring->ringno == LPFC_ELS_RING) {
  2514. switch (icmd->ulpCommand) {
  2515. case CMD_GEN_REQUEST64_CR:
  2516. if (iocb->context_un.ndlp == ndlp)
  2517. return 1;
  2518. case CMD_ELS_REQUEST64_CR:
  2519. if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
  2520. return 1;
  2521. case CMD_XMIT_ELS_RSP64_CX:
  2522. if (iocb->context1 == (uint8_t *) ndlp)
  2523. return 1;
  2524. }
  2525. } else if (pring->ringno == psli->extra_ring) {
  2526. } else if (pring->ringno == psli->fcp_ring) {
  2527. /* Skip match check if waiting to relogin to FCP target */
  2528. if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
  2529. (ndlp->nlp_flag & NLP_DELAY_TMO)) {
  2530. return 0;
  2531. }
  2532. if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
  2533. return 1;
  2534. }
  2535. } else if (pring->ringno == psli->next_ring) {
  2536. }
  2537. return 0;
  2538. }
  2539. /*
  2540. * Free resources / clean up outstanding I/Os
  2541. * associated with nlp_rpi in the LPFC_NODELIST entry.
  2542. */
  2543. static int
  2544. lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  2545. {
  2546. LIST_HEAD(completions);
  2547. struct lpfc_sli *psli;
  2548. struct lpfc_sli_ring *pring;
  2549. struct lpfc_iocbq *iocb, *next_iocb;
  2550. uint32_t rpi, i;
  2551. lpfc_fabric_abort_nport(ndlp);
  2552. /*
  2553. * Everything that matches on txcmplq will be returned
  2554. * by firmware with a no rpi error.
  2555. */
  2556. psli = &phba->sli;
  2557. rpi = ndlp->nlp_rpi;
  2558. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  2559. /* Now process each ring */
  2560. for (i = 0; i < psli->num_rings; i++) {
  2561. pring = &psli->ring[i];
  2562. spin_lock_irq(&phba->hbalock);
  2563. list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
  2564. list) {
  2565. /*
  2566. * Check to see if iocb matches the nport we are
  2567. * looking for
  2568. */
  2569. if ((lpfc_check_sli_ndlp(phba, pring, iocb,
  2570. ndlp))) {
  2571. /* It matches, so deque and call compl
  2572. with an error */
  2573. list_move_tail(&iocb->list,
  2574. &completions);
  2575. pring->txq_cnt--;
  2576. }
  2577. }
  2578. spin_unlock_irq(&phba->hbalock);
  2579. }
  2580. }
  2581. /* Cancel all the IOCBs from the completions list */
  2582. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  2583. IOERR_SLI_ABORTED);
  2584. return 0;
  2585. }
  2586. /*
  2587. * Free rpi associated with LPFC_NODELIST entry.
  2588. * This routine is called from lpfc_freenode(), when we are removing
  2589. * a LPFC_NODELIST entry. It is also called if the driver initiates a
  2590. * LOGO that completes successfully, and we are waiting to PLOGI back
  2591. * to the remote NPort. In addition, it is called after we receive
  2592. * and unsolicated ELS cmd, send back a rsp, the rsp completes and
  2593. * we are waiting to PLOGI back to the remote NPort.
  2594. */
  2595. int
  2596. lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2597. {
  2598. struct lpfc_hba *phba = vport->phba;
  2599. LPFC_MBOXQ_t *mbox;
  2600. int rc;
  2601. if (ndlp->nlp_flag & NLP_RPI_VALID) {
  2602. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2603. if (mbox) {
  2604. lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
  2605. mbox->vport = vport;
  2606. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2607. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2608. if (rc == MBX_NOT_FINISHED)
  2609. mempool_free(mbox, phba->mbox_mem_pool);
  2610. }
  2611. lpfc_no_rpi(phba, ndlp);
  2612. ndlp->nlp_rpi = 0;
  2613. ndlp->nlp_flag &= ~NLP_RPI_VALID;
  2614. return 1;
  2615. }
  2616. return 0;
  2617. }
  2618. void
  2619. lpfc_unreg_all_rpis(struct lpfc_vport *vport)
  2620. {
  2621. struct lpfc_hba *phba = vport->phba;
  2622. LPFC_MBOXQ_t *mbox;
  2623. int rc;
  2624. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2625. if (mbox) {
  2626. lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
  2627. mbox->vport = vport;
  2628. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2629. mbox->context1 = NULL;
  2630. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  2631. if (rc != MBX_TIMEOUT)
  2632. mempool_free(mbox, phba->mbox_mem_pool);
  2633. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  2634. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2635. "1836 Could not issue "
  2636. "unreg_login(all_rpis) status %d\n", rc);
  2637. }
  2638. }
  2639. void
  2640. lpfc_unreg_default_rpis(struct lpfc_vport *vport)
  2641. {
  2642. struct lpfc_hba *phba = vport->phba;
  2643. LPFC_MBOXQ_t *mbox;
  2644. int rc;
  2645. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2646. if (mbox) {
  2647. lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
  2648. mbox->vport = vport;
  2649. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2650. mbox->context1 = NULL;
  2651. rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
  2652. if (rc != MBX_TIMEOUT)
  2653. mempool_free(mbox, phba->mbox_mem_pool);
  2654. if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
  2655. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
  2656. "1815 Could not issue "
  2657. "unreg_did (default rpis) status %d\n",
  2658. rc);
  2659. }
  2660. }
  2661. /*
  2662. * Free resources associated with LPFC_NODELIST entry
  2663. * so it can be freed.
  2664. */
  2665. static int
  2666. lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2667. {
  2668. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2669. struct lpfc_hba *phba = vport->phba;
  2670. LPFC_MBOXQ_t *mb, *nextmb;
  2671. struct lpfc_dmabuf *mp;
  2672. /* Cleanup node for NPort <nlp_DID> */
  2673. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2674. "0900 Cleanup node for NPort x%x "
  2675. "Data: x%x x%x x%x\n",
  2676. ndlp->nlp_DID, ndlp->nlp_flag,
  2677. ndlp->nlp_state, ndlp->nlp_rpi);
  2678. if (NLP_CHK_FREE_REQ(ndlp)) {
  2679. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2680. "0280 lpfc_cleanup_node: ndlp:x%p "
  2681. "usgmap:x%x refcnt:%d\n",
  2682. (void *)ndlp, ndlp->nlp_usg_map,
  2683. atomic_read(&ndlp->kref.refcount));
  2684. lpfc_dequeue_node(vport, ndlp);
  2685. } else {
  2686. lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
  2687. "0281 lpfc_cleanup_node: ndlp:x%p "
  2688. "usgmap:x%x refcnt:%d\n",
  2689. (void *)ndlp, ndlp->nlp_usg_map,
  2690. atomic_read(&ndlp->kref.refcount));
  2691. lpfc_disable_node(vport, ndlp);
  2692. }
  2693. /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
  2694. if ((mb = phba->sli.mbox_active)) {
  2695. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  2696. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  2697. mb->context2 = NULL;
  2698. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2699. }
  2700. }
  2701. spin_lock_irq(&phba->hbalock);
  2702. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  2703. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
  2704. (ndlp == (struct lpfc_nodelist *) mb->context2)) {
  2705. mp = (struct lpfc_dmabuf *) (mb->context1);
  2706. if (mp) {
  2707. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2708. kfree(mp);
  2709. }
  2710. list_del(&mb->list);
  2711. mempool_free(mb, phba->mbox_mem_pool);
  2712. /* We shall not invoke the lpfc_nlp_put to decrement
  2713. * the ndlp reference count as we are in the process
  2714. * of lpfc_nlp_release.
  2715. */
  2716. }
  2717. }
  2718. spin_unlock_irq(&phba->hbalock);
  2719. lpfc_els_abort(phba, ndlp);
  2720. spin_lock_irq(shost->host_lock);
  2721. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  2722. spin_unlock_irq(shost->host_lock);
  2723. ndlp->nlp_last_elscmd = 0;
  2724. del_timer_sync(&ndlp->nlp_delayfunc);
  2725. list_del_init(&ndlp->els_retry_evt.evt_listp);
  2726. list_del_init(&ndlp->dev_loss_evt.evt_listp);
  2727. lpfc_unreg_rpi(vport, ndlp);
  2728. return 0;
  2729. }
  2730. /*
  2731. * Check to see if we can free the nlp back to the freelist.
  2732. * If we are in the middle of using the nlp in the discovery state
  2733. * machine, defer the free till we reach the end of the state machine.
  2734. */
  2735. static void
  2736. lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2737. {
  2738. struct lpfc_hba *phba = vport->phba;
  2739. struct lpfc_rport_data *rdata;
  2740. LPFC_MBOXQ_t *mbox;
  2741. int rc;
  2742. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2743. if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
  2744. !(ndlp->nlp_flag & NLP_RPI_VALID)) {
  2745. /* For this case we need to cleanup the default rpi
  2746. * allocated by the firmware.
  2747. */
  2748. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
  2749. != NULL) {
  2750. rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
  2751. (uint8_t *) &vport->fc_sparam, mbox, 0);
  2752. if (rc) {
  2753. mempool_free(mbox, phba->mbox_mem_pool);
  2754. }
  2755. else {
  2756. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  2757. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  2758. mbox->vport = vport;
  2759. mbox->context2 = NULL;
  2760. rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2761. if (rc == MBX_NOT_FINISHED) {
  2762. mempool_free(mbox, phba->mbox_mem_pool);
  2763. }
  2764. }
  2765. }
  2766. }
  2767. lpfc_cleanup_node(vport, ndlp);
  2768. /*
  2769. * We can get here with a non-NULL ndlp->rport because when we
  2770. * unregister a rport we don't break the rport/node linkage. So if we
  2771. * do, make sure we don't leaving any dangling pointers behind.
  2772. */
  2773. if (ndlp->rport) {
  2774. rdata = ndlp->rport->dd_data;
  2775. rdata->pnode = NULL;
  2776. ndlp->rport = NULL;
  2777. }
  2778. }
  2779. static int
  2780. lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2781. uint32_t did)
  2782. {
  2783. D_ID mydid, ndlpdid, matchdid;
  2784. if (did == Bcast_DID)
  2785. return 0;
  2786. /* First check for Direct match */
  2787. if (ndlp->nlp_DID == did)
  2788. return 1;
  2789. /* Next check for area/domain identically equals 0 match */
  2790. mydid.un.word = vport->fc_myDID;
  2791. if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
  2792. return 0;
  2793. }
  2794. matchdid.un.word = did;
  2795. ndlpdid.un.word = ndlp->nlp_DID;
  2796. if (matchdid.un.b.id == ndlpdid.un.b.id) {
  2797. if ((mydid.un.b.domain == matchdid.un.b.domain) &&
  2798. (mydid.un.b.area == matchdid.un.b.area)) {
  2799. if ((ndlpdid.un.b.domain == 0) &&
  2800. (ndlpdid.un.b.area == 0)) {
  2801. if (ndlpdid.un.b.id)
  2802. return 1;
  2803. }
  2804. return 0;
  2805. }
  2806. matchdid.un.word = ndlp->nlp_DID;
  2807. if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
  2808. (mydid.un.b.area == ndlpdid.un.b.area)) {
  2809. if ((matchdid.un.b.domain == 0) &&
  2810. (matchdid.un.b.area == 0)) {
  2811. if (matchdid.un.b.id)
  2812. return 1;
  2813. }
  2814. }
  2815. }
  2816. return 0;
  2817. }
  2818. /* Search for a nodelist entry */
  2819. static struct lpfc_nodelist *
  2820. __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  2821. {
  2822. struct lpfc_nodelist *ndlp;
  2823. uint32_t data1;
  2824. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2825. if (lpfc_matchdid(vport, ndlp, did)) {
  2826. data1 = (((uint32_t) ndlp->nlp_state << 24) |
  2827. ((uint32_t) ndlp->nlp_xri << 16) |
  2828. ((uint32_t) ndlp->nlp_type << 8) |
  2829. ((uint32_t) ndlp->nlp_rpi & 0xff));
  2830. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2831. "0929 FIND node DID "
  2832. "Data: x%p x%x x%x x%x\n",
  2833. ndlp, ndlp->nlp_DID,
  2834. ndlp->nlp_flag, data1);
  2835. return ndlp;
  2836. }
  2837. }
  2838. /* FIND node did <did> NOT FOUND */
  2839. lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
  2840. "0932 FIND node did x%x NOT FOUND.\n", did);
  2841. return NULL;
  2842. }
  2843. struct lpfc_nodelist *
  2844. lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
  2845. {
  2846. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2847. struct lpfc_nodelist *ndlp;
  2848. spin_lock_irq(shost->host_lock);
  2849. ndlp = __lpfc_findnode_did(vport, did);
  2850. spin_unlock_irq(shost->host_lock);
  2851. return ndlp;
  2852. }
  2853. struct lpfc_nodelist *
  2854. lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
  2855. {
  2856. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2857. struct lpfc_nodelist *ndlp;
  2858. ndlp = lpfc_findnode_did(vport, did);
  2859. if (!ndlp) {
  2860. if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
  2861. lpfc_rscn_payload_check(vport, did) == 0)
  2862. return NULL;
  2863. ndlp = (struct lpfc_nodelist *)
  2864. mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
  2865. if (!ndlp)
  2866. return NULL;
  2867. lpfc_nlp_init(vport, ndlp, did);
  2868. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2869. spin_lock_irq(shost->host_lock);
  2870. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2871. spin_unlock_irq(shost->host_lock);
  2872. return ndlp;
  2873. } else if (!NLP_CHK_NODE_ACT(ndlp)) {
  2874. ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
  2875. if (!ndlp)
  2876. return NULL;
  2877. spin_lock_irq(shost->host_lock);
  2878. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2879. spin_unlock_irq(shost->host_lock);
  2880. return ndlp;
  2881. }
  2882. if ((vport->fc_flag & FC_RSCN_MODE) &&
  2883. !(vport->fc_flag & FC_NDISC_ACTIVE)) {
  2884. if (lpfc_rscn_payload_check(vport, did)) {
  2885. /* If we've already recieved a PLOGI from this NPort
  2886. * we don't need to try to discover it again.
  2887. */
  2888. if (ndlp->nlp_flag & NLP_RCV_PLOGI)
  2889. return NULL;
  2890. /* Since this node is marked for discovery,
  2891. * delay timeout is not needed.
  2892. */
  2893. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2894. spin_lock_irq(shost->host_lock);
  2895. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2896. spin_unlock_irq(shost->host_lock);
  2897. } else
  2898. ndlp = NULL;
  2899. } else {
  2900. /* If we've already recieved a PLOGI from this NPort,
  2901. * or we are already in the process of discovery on it,
  2902. * we don't need to try to discover it again.
  2903. */
  2904. if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
  2905. ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  2906. ndlp->nlp_flag & NLP_RCV_PLOGI)
  2907. return NULL;
  2908. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  2909. spin_lock_irq(shost->host_lock);
  2910. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  2911. spin_unlock_irq(shost->host_lock);
  2912. }
  2913. return ndlp;
  2914. }
  2915. /* Build a list of nodes to discover based on the loopmap */
  2916. void
  2917. lpfc_disc_list_loopmap(struct lpfc_vport *vport)
  2918. {
  2919. struct lpfc_hba *phba = vport->phba;
  2920. int j;
  2921. uint32_t alpa, index;
  2922. if (!lpfc_is_link_up(phba))
  2923. return;
  2924. if (phba->fc_topology != TOPOLOGY_LOOP)
  2925. return;
  2926. /* Check for loop map present or not */
  2927. if (phba->alpa_map[0]) {
  2928. for (j = 1; j <= phba->alpa_map[0]; j++) {
  2929. alpa = phba->alpa_map[j];
  2930. if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
  2931. continue;
  2932. lpfc_setup_disc_node(vport, alpa);
  2933. }
  2934. } else {
  2935. /* No alpamap, so try all alpa's */
  2936. for (j = 0; j < FC_MAXLOOP; j++) {
  2937. /* If cfg_scan_down is set, start from highest
  2938. * ALPA (0xef) to lowest (0x1).
  2939. */
  2940. if (vport->cfg_scan_down)
  2941. index = j;
  2942. else
  2943. index = FC_MAXLOOP - j - 1;
  2944. alpa = lpfcAlpaArray[index];
  2945. if ((vport->fc_myDID & 0xff) == alpa)
  2946. continue;
  2947. lpfc_setup_disc_node(vport, alpa);
  2948. }
  2949. }
  2950. return;
  2951. }
  2952. void
  2953. lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
  2954. {
  2955. LPFC_MBOXQ_t *mbox;
  2956. struct lpfc_sli *psli = &phba->sli;
  2957. struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
  2958. struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
  2959. struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
  2960. int rc;
  2961. /*
  2962. * if it's not a physical port or if we already send
  2963. * clear_la then don't send it.
  2964. */
  2965. if ((phba->link_state >= LPFC_CLEAR_LA) ||
  2966. (vport->port_type != LPFC_PHYSICAL_PORT) ||
  2967. (phba->sli_rev == LPFC_SLI_REV4))
  2968. return;
  2969. /* Link up discovery */
  2970. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
  2971. phba->link_state = LPFC_CLEAR_LA;
  2972. lpfc_clear_la(phba, mbox);
  2973. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  2974. mbox->vport = vport;
  2975. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2976. if (rc == MBX_NOT_FINISHED) {
  2977. mempool_free(mbox, phba->mbox_mem_pool);
  2978. lpfc_disc_flush_list(vport);
  2979. extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  2980. fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  2981. next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
  2982. phba->link_state = LPFC_HBA_ERROR;
  2983. }
  2984. }
  2985. }
  2986. /* Reg_vpi to tell firmware to resume normal operations */
  2987. void
  2988. lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  2989. {
  2990. LPFC_MBOXQ_t *regvpimbox;
  2991. regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2992. if (regvpimbox) {
  2993. lpfc_reg_vpi(vport, regvpimbox);
  2994. regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
  2995. regvpimbox->vport = vport;
  2996. if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
  2997. == MBX_NOT_FINISHED) {
  2998. mempool_free(regvpimbox, phba->mbox_mem_pool);
  2999. }
  3000. }
  3001. }
  3002. /* Start Link up / RSCN discovery on NPR nodes */
  3003. void
  3004. lpfc_disc_start(struct lpfc_vport *vport)
  3005. {
  3006. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3007. struct lpfc_hba *phba = vport->phba;
  3008. uint32_t num_sent;
  3009. uint32_t clear_la_pending;
  3010. int did_changed;
  3011. if (!lpfc_is_link_up(phba))
  3012. return;
  3013. if (phba->link_state == LPFC_CLEAR_LA)
  3014. clear_la_pending = 1;
  3015. else
  3016. clear_la_pending = 0;
  3017. if (vport->port_state < LPFC_VPORT_READY)
  3018. vport->port_state = LPFC_DISC_AUTH;
  3019. lpfc_set_disctmo(vport);
  3020. if (vport->fc_prevDID == vport->fc_myDID)
  3021. did_changed = 0;
  3022. else
  3023. did_changed = 1;
  3024. vport->fc_prevDID = vport->fc_myDID;
  3025. vport->num_disc_nodes = 0;
  3026. /* Start Discovery state <hba_state> */
  3027. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  3028. "0202 Start Discovery hba state x%x "
  3029. "Data: x%x x%x x%x\n",
  3030. vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
  3031. vport->fc_adisc_cnt);
  3032. /* First do ADISCs - if any */
  3033. num_sent = lpfc_els_disc_adisc(vport);
  3034. if (num_sent)
  3035. return;
  3036. /*
  3037. * For SLI3, cmpl_reg_vpi will set port_state to READY, and
  3038. * continue discovery.
  3039. */
  3040. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3041. !(vport->fc_flag & FC_PT2PT) &&
  3042. !(vport->fc_flag & FC_RSCN_MODE) &&
  3043. (phba->sli_rev < LPFC_SLI_REV4)) {
  3044. lpfc_issue_reg_vpi(phba, vport);
  3045. return;
  3046. }
  3047. /*
  3048. * For SLI2, we need to set port_state to READY and continue
  3049. * discovery.
  3050. */
  3051. if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
  3052. /* If we get here, there is nothing to ADISC */
  3053. if (vport->port_type == LPFC_PHYSICAL_PORT)
  3054. lpfc_issue_clear_la(phba, vport);
  3055. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  3056. vport->num_disc_nodes = 0;
  3057. /* go thru NPR nodes and issue ELS PLOGIs */
  3058. if (vport->fc_npr_cnt)
  3059. lpfc_els_disc_plogi(vport);
  3060. if (!vport->num_disc_nodes) {
  3061. spin_lock_irq(shost->host_lock);
  3062. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  3063. spin_unlock_irq(shost->host_lock);
  3064. lpfc_can_disctmo(vport);
  3065. }
  3066. }
  3067. vport->port_state = LPFC_VPORT_READY;
  3068. } else {
  3069. /* Next do PLOGIs - if any */
  3070. num_sent = lpfc_els_disc_plogi(vport);
  3071. if (num_sent)
  3072. return;
  3073. if (vport->fc_flag & FC_RSCN_MODE) {
  3074. /* Check to see if more RSCNs came in while we
  3075. * were processing this one.
  3076. */
  3077. if ((vport->fc_rscn_id_cnt == 0) &&
  3078. (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
  3079. spin_lock_irq(shost->host_lock);
  3080. vport->fc_flag &= ~FC_RSCN_MODE;
  3081. spin_unlock_irq(shost->host_lock);
  3082. lpfc_can_disctmo(vport);
  3083. } else
  3084. lpfc_els_handle_rscn(vport);
  3085. }
  3086. }
  3087. return;
  3088. }
  3089. /*
  3090. * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
  3091. * ring the match the sppecified nodelist.
  3092. */
  3093. static void
  3094. lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
  3095. {
  3096. LIST_HEAD(completions);
  3097. struct lpfc_sli *psli;
  3098. IOCB_t *icmd;
  3099. struct lpfc_iocbq *iocb, *next_iocb;
  3100. struct lpfc_sli_ring *pring;
  3101. psli = &phba->sli;
  3102. pring = &psli->ring[LPFC_ELS_RING];
  3103. /* Error matching iocb on txq or txcmplq
  3104. * First check the txq.
  3105. */
  3106. spin_lock_irq(&phba->hbalock);
  3107. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  3108. if (iocb->context1 != ndlp) {
  3109. continue;
  3110. }
  3111. icmd = &iocb->iocb;
  3112. if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
  3113. (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
  3114. list_move_tail(&iocb->list, &completions);
  3115. pring->txq_cnt--;
  3116. }
  3117. }
  3118. /* Next check the txcmplq */
  3119. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  3120. if (iocb->context1 != ndlp) {
  3121. continue;
  3122. }
  3123. icmd = &iocb->iocb;
  3124. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
  3125. icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
  3126. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  3127. }
  3128. }
  3129. spin_unlock_irq(&phba->hbalock);
  3130. /* Cancel all the IOCBs from the completions list */
  3131. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  3132. IOERR_SLI_ABORTED);
  3133. }
  3134. static void
  3135. lpfc_disc_flush_list(struct lpfc_vport *vport)
  3136. {
  3137. struct lpfc_nodelist *ndlp, *next_ndlp;
  3138. struct lpfc_hba *phba = vport->phba;
  3139. if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
  3140. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3141. nlp_listp) {
  3142. if (!NLP_CHK_NODE_ACT(ndlp))
  3143. continue;
  3144. if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
  3145. ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
  3146. lpfc_free_tx(phba, ndlp);
  3147. }
  3148. }
  3149. }
  3150. }
  3151. void
  3152. lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
  3153. {
  3154. lpfc_els_flush_rscn(vport);
  3155. lpfc_els_flush_cmd(vport);
  3156. lpfc_disc_flush_list(vport);
  3157. }
  3158. /*****************************************************************************/
  3159. /*
  3160. * NAME: lpfc_disc_timeout
  3161. *
  3162. * FUNCTION: Fibre Channel driver discovery timeout routine.
  3163. *
  3164. * EXECUTION ENVIRONMENT: interrupt only
  3165. *
  3166. * CALLED FROM:
  3167. * Timer function
  3168. *
  3169. * RETURNS:
  3170. * none
  3171. */
  3172. /*****************************************************************************/
  3173. void
  3174. lpfc_disc_timeout(unsigned long ptr)
  3175. {
  3176. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3177. struct lpfc_hba *phba = vport->phba;
  3178. uint32_t tmo_posted;
  3179. unsigned long flags = 0;
  3180. if (unlikely(!phba))
  3181. return;
  3182. spin_lock_irqsave(&vport->work_port_lock, flags);
  3183. tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
  3184. if (!tmo_posted)
  3185. vport->work_port_events |= WORKER_DISC_TMO;
  3186. spin_unlock_irqrestore(&vport->work_port_lock, flags);
  3187. if (!tmo_posted)
  3188. lpfc_worker_wake_up(phba);
  3189. return;
  3190. }
  3191. static void
  3192. lpfc_disc_timeout_handler(struct lpfc_vport *vport)
  3193. {
  3194. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3195. struct lpfc_hba *phba = vport->phba;
  3196. struct lpfc_sli *psli = &phba->sli;
  3197. struct lpfc_nodelist *ndlp, *next_ndlp;
  3198. LPFC_MBOXQ_t *initlinkmbox;
  3199. int rc, clrlaerr = 0;
  3200. if (!(vport->fc_flag & FC_DISC_TMO))
  3201. return;
  3202. spin_lock_irq(shost->host_lock);
  3203. vport->fc_flag &= ~FC_DISC_TMO;
  3204. spin_unlock_irq(shost->host_lock);
  3205. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3206. "disc timeout: state:x%x rtry:x%x flg:x%x",
  3207. vport->port_state, vport->fc_ns_retry, vport->fc_flag);
  3208. switch (vport->port_state) {
  3209. case LPFC_LOCAL_CFG_LINK:
  3210. /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
  3211. * FAN
  3212. */
  3213. /* FAN timeout */
  3214. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  3215. "0221 FAN timeout\n");
  3216. /* Start discovery by sending FLOGI, clean up old rpis */
  3217. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3218. nlp_listp) {
  3219. if (!NLP_CHK_NODE_ACT(ndlp))
  3220. continue;
  3221. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3222. continue;
  3223. if (ndlp->nlp_type & NLP_FABRIC) {
  3224. /* Clean up the ndlp on Fabric connections */
  3225. lpfc_drop_node(vport, ndlp);
  3226. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  3227. /* Fail outstanding IO now since device
  3228. * is marked for PLOGI.
  3229. */
  3230. lpfc_unreg_rpi(vport, ndlp);
  3231. }
  3232. }
  3233. if (vport->port_state != LPFC_FLOGI) {
  3234. lpfc_initial_flogi(vport);
  3235. return;
  3236. }
  3237. break;
  3238. case LPFC_FDISC:
  3239. case LPFC_FLOGI:
  3240. /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
  3241. /* Initial FLOGI timeout */
  3242. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3243. "0222 Initial %s timeout\n",
  3244. vport->vpi ? "FDISC" : "FLOGI");
  3245. /* Assume no Fabric and go on with discovery.
  3246. * Check for outstanding ELS FLOGI to abort.
  3247. */
  3248. /* FLOGI failed, so just use loop map to make discovery list */
  3249. lpfc_disc_list_loopmap(vport);
  3250. /* Start discovery */
  3251. lpfc_disc_start(vport);
  3252. break;
  3253. case LPFC_FABRIC_CFG_LINK:
  3254. /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
  3255. NameServer login */
  3256. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3257. "0223 Timeout while waiting for "
  3258. "NameServer login\n");
  3259. /* Next look for NameServer ndlp */
  3260. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3261. if (ndlp && NLP_CHK_NODE_ACT(ndlp))
  3262. lpfc_els_abort(phba, ndlp);
  3263. /* ReStart discovery */
  3264. goto restart_disc;
  3265. case LPFC_NS_QRY:
  3266. /* Check for wait for NameServer Rsp timeout */
  3267. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3268. "0224 NameServer Query timeout "
  3269. "Data: x%x x%x\n",
  3270. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  3271. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  3272. /* Try it one more time */
  3273. vport->fc_ns_retry++;
  3274. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  3275. vport->fc_ns_retry, 0);
  3276. if (rc == 0)
  3277. break;
  3278. }
  3279. vport->fc_ns_retry = 0;
  3280. restart_disc:
  3281. /*
  3282. * Discovery is over.
  3283. * set port_state to PORT_READY if SLI2.
  3284. * cmpl_reg_vpi will set port_state to READY for SLI3.
  3285. */
  3286. if (phba->sli_rev < LPFC_SLI_REV4) {
  3287. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3288. lpfc_issue_reg_vpi(phba, vport);
  3289. else { /* NPIV Not enabled */
  3290. lpfc_issue_clear_la(phba, vport);
  3291. vport->port_state = LPFC_VPORT_READY;
  3292. }
  3293. }
  3294. /* Setup and issue mailbox INITIALIZE LINK command */
  3295. initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3296. if (!initlinkmbox) {
  3297. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3298. "0206 Device Discovery "
  3299. "completion error\n");
  3300. phba->link_state = LPFC_HBA_ERROR;
  3301. break;
  3302. }
  3303. lpfc_linkdown(phba);
  3304. lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
  3305. phba->cfg_link_speed);
  3306. initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
  3307. initlinkmbox->vport = vport;
  3308. initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  3309. rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
  3310. lpfc_set_loopback_flag(phba);
  3311. if (rc == MBX_NOT_FINISHED)
  3312. mempool_free(initlinkmbox, phba->mbox_mem_pool);
  3313. break;
  3314. case LPFC_DISC_AUTH:
  3315. /* Node Authentication timeout */
  3316. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3317. "0227 Node Authentication timeout\n");
  3318. lpfc_disc_flush_list(vport);
  3319. /*
  3320. * set port_state to PORT_READY if SLI2.
  3321. * cmpl_reg_vpi will set port_state to READY for SLI3.
  3322. */
  3323. if (phba->sli_rev < LPFC_SLI_REV4) {
  3324. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  3325. lpfc_issue_reg_vpi(phba, vport);
  3326. else { /* NPIV Not enabled */
  3327. lpfc_issue_clear_la(phba, vport);
  3328. vport->port_state = LPFC_VPORT_READY;
  3329. }
  3330. }
  3331. break;
  3332. case LPFC_VPORT_READY:
  3333. if (vport->fc_flag & FC_RSCN_MODE) {
  3334. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3335. "0231 RSCN timeout Data: x%x "
  3336. "x%x\n",
  3337. vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
  3338. /* Cleanup any outstanding ELS commands */
  3339. lpfc_els_flush_cmd(vport);
  3340. lpfc_els_flush_rscn(vport);
  3341. lpfc_disc_flush_list(vport);
  3342. }
  3343. break;
  3344. default:
  3345. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3346. "0273 Unexpected discovery timeout, "
  3347. "vport State x%x\n", vport->port_state);
  3348. break;
  3349. }
  3350. switch (phba->link_state) {
  3351. case LPFC_CLEAR_LA:
  3352. /* CLEAR LA timeout */
  3353. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3354. "0228 CLEAR LA timeout\n");
  3355. clrlaerr = 1;
  3356. break;
  3357. case LPFC_LINK_UP:
  3358. lpfc_issue_clear_la(phba, vport);
  3359. /* Drop thru */
  3360. case LPFC_LINK_UNKNOWN:
  3361. case LPFC_WARM_START:
  3362. case LPFC_INIT_START:
  3363. case LPFC_INIT_MBX_CMDS:
  3364. case LPFC_LINK_DOWN:
  3365. case LPFC_HBA_ERROR:
  3366. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  3367. "0230 Unexpected timeout, hba link "
  3368. "state x%x\n", phba->link_state);
  3369. clrlaerr = 1;
  3370. break;
  3371. case LPFC_HBA_READY:
  3372. break;
  3373. }
  3374. if (clrlaerr) {
  3375. lpfc_disc_flush_list(vport);
  3376. psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3377. psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3378. psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
  3379. vport->port_state = LPFC_VPORT_READY;
  3380. }
  3381. return;
  3382. }
  3383. /*
  3384. * This routine handles processing a NameServer REG_LOGIN mailbox
  3385. * command upon completion. It is setup in the LPFC_MBOXQ
  3386. * as the completion routine when the command is
  3387. * handed off to the SLI layer.
  3388. */
  3389. void
  3390. lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3391. {
  3392. MAILBOX_t *mb = &pmb->u.mb;
  3393. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  3394. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3395. struct lpfc_vport *vport = pmb->vport;
  3396. pmb->context1 = NULL;
  3397. ndlp->nlp_rpi = mb->un.varWords[0];
  3398. ndlp->nlp_flag |= NLP_RPI_VALID;
  3399. ndlp->nlp_type |= NLP_FABRIC;
  3400. lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
  3401. /*
  3402. * Start issuing Fabric-Device Management Interface (FDMI) command to
  3403. * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
  3404. * fdmi-on=2 (supporting RPA/hostnmae)
  3405. */
  3406. if (vport->cfg_fdmi_on == 1)
  3407. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  3408. else
  3409. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  3410. /* decrement the node reference count held for this callback
  3411. * function.
  3412. */
  3413. lpfc_nlp_put(ndlp);
  3414. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3415. kfree(mp);
  3416. mempool_free(pmb, phba->mbox_mem_pool);
  3417. return;
  3418. }
  3419. static int
  3420. lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
  3421. {
  3422. uint16_t *rpi = param;
  3423. return ndlp->nlp_rpi == *rpi;
  3424. }
  3425. static int
  3426. lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
  3427. {
  3428. return memcmp(&ndlp->nlp_portname, param,
  3429. sizeof(ndlp->nlp_portname)) == 0;
  3430. }
  3431. static struct lpfc_nodelist *
  3432. __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
  3433. {
  3434. struct lpfc_nodelist *ndlp;
  3435. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  3436. if (filter(ndlp, param))
  3437. return ndlp;
  3438. }
  3439. return NULL;
  3440. }
  3441. /*
  3442. * This routine looks up the ndlp lists for the given RPI. If rpi found it
  3443. * returns the node list element pointer else return NULL.
  3444. */
  3445. struct lpfc_nodelist *
  3446. __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
  3447. {
  3448. return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
  3449. }
  3450. /*
  3451. * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
  3452. * returns the node element list pointer else return NULL.
  3453. */
  3454. struct lpfc_nodelist *
  3455. lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
  3456. {
  3457. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3458. struct lpfc_nodelist *ndlp;
  3459. spin_lock_irq(shost->host_lock);
  3460. ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
  3461. spin_unlock_irq(shost->host_lock);
  3462. return ndlp;
  3463. }
  3464. void
  3465. lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3466. uint32_t did)
  3467. {
  3468. memset(ndlp, 0, sizeof (struct lpfc_nodelist));
  3469. lpfc_initialize_node(vport, ndlp, did);
  3470. INIT_LIST_HEAD(&ndlp->nlp_listp);
  3471. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
  3472. "node init: did:x%x",
  3473. ndlp->nlp_DID, 0, 0);
  3474. return;
  3475. }
  3476. /* This routine releases all resources associated with a specifc NPort's ndlp
  3477. * and mempool_free's the nodelist.
  3478. */
  3479. static void
  3480. lpfc_nlp_release(struct kref *kref)
  3481. {
  3482. struct lpfc_hba *phba;
  3483. unsigned long flags;
  3484. struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
  3485. kref);
  3486. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3487. "node release: did:x%x flg:x%x type:x%x",
  3488. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
  3489. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
  3490. "0279 lpfc_nlp_release: ndlp:x%p "
  3491. "usgmap:x%x refcnt:%d\n",
  3492. (void *)ndlp, ndlp->nlp_usg_map,
  3493. atomic_read(&ndlp->kref.refcount));
  3494. /* remove ndlp from action. */
  3495. lpfc_nlp_remove(ndlp->vport, ndlp);
  3496. /* clear the ndlp active flag for all release cases */
  3497. phba = ndlp->phba;
  3498. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3499. NLP_CLR_NODE_ACT(ndlp);
  3500. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3501. /* free ndlp memory for final ndlp release */
  3502. if (NLP_CHK_FREE_REQ(ndlp)) {
  3503. kfree(ndlp->lat_data);
  3504. mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
  3505. }
  3506. }
  3507. /* This routine bumps the reference count for a ndlp structure to ensure
  3508. * that one discovery thread won't free a ndlp while another discovery thread
  3509. * is using it.
  3510. */
  3511. struct lpfc_nodelist *
  3512. lpfc_nlp_get(struct lpfc_nodelist *ndlp)
  3513. {
  3514. struct lpfc_hba *phba;
  3515. unsigned long flags;
  3516. if (ndlp) {
  3517. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3518. "node get: did:x%x flg:x%x refcnt:x%x",
  3519. ndlp->nlp_DID, ndlp->nlp_flag,
  3520. atomic_read(&ndlp->kref.refcount));
  3521. /* The check of ndlp usage to prevent incrementing the
  3522. * ndlp reference count that is in the process of being
  3523. * released.
  3524. */
  3525. phba = ndlp->phba;
  3526. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3527. if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
  3528. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3529. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3530. "0276 lpfc_nlp_get: ndlp:x%p "
  3531. "usgmap:x%x refcnt:%d\n",
  3532. (void *)ndlp, ndlp->nlp_usg_map,
  3533. atomic_read(&ndlp->kref.refcount));
  3534. return NULL;
  3535. } else
  3536. kref_get(&ndlp->kref);
  3537. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3538. }
  3539. return ndlp;
  3540. }
  3541. /* This routine decrements the reference count for a ndlp structure. If the
  3542. * count goes to 0, this indicates the the associated nodelist should be
  3543. * freed. Returning 1 indicates the ndlp resource has been released; on the
  3544. * other hand, returning 0 indicates the ndlp resource has not been released
  3545. * yet.
  3546. */
  3547. int
  3548. lpfc_nlp_put(struct lpfc_nodelist *ndlp)
  3549. {
  3550. struct lpfc_hba *phba;
  3551. unsigned long flags;
  3552. if (!ndlp)
  3553. return 1;
  3554. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3555. "node put: did:x%x flg:x%x refcnt:x%x",
  3556. ndlp->nlp_DID, ndlp->nlp_flag,
  3557. atomic_read(&ndlp->kref.refcount));
  3558. phba = ndlp->phba;
  3559. spin_lock_irqsave(&phba->ndlp_lock, flags);
  3560. /* Check the ndlp memory free acknowledge flag to avoid the
  3561. * possible race condition that kref_put got invoked again
  3562. * after previous one has done ndlp memory free.
  3563. */
  3564. if (NLP_CHK_FREE_ACK(ndlp)) {
  3565. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3566. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3567. "0274 lpfc_nlp_put: ndlp:x%p "
  3568. "usgmap:x%x refcnt:%d\n",
  3569. (void *)ndlp, ndlp->nlp_usg_map,
  3570. atomic_read(&ndlp->kref.refcount));
  3571. return 1;
  3572. }
  3573. /* Check the ndlp inactivate log flag to avoid the possible
  3574. * race condition that kref_put got invoked again after ndlp
  3575. * is already in inactivating state.
  3576. */
  3577. if (NLP_CHK_IACT_REQ(ndlp)) {
  3578. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3579. lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
  3580. "0275 lpfc_nlp_put: ndlp:x%p "
  3581. "usgmap:x%x refcnt:%d\n",
  3582. (void *)ndlp, ndlp->nlp_usg_map,
  3583. atomic_read(&ndlp->kref.refcount));
  3584. return 1;
  3585. }
  3586. /* For last put, mark the ndlp usage flags to make sure no
  3587. * other kref_get and kref_put on the same ndlp shall get
  3588. * in between the process when the final kref_put has been
  3589. * invoked on this ndlp.
  3590. */
  3591. if (atomic_read(&ndlp->kref.refcount) == 1) {
  3592. /* Indicate ndlp is put to inactive state. */
  3593. NLP_SET_IACT_REQ(ndlp);
  3594. /* Acknowledge ndlp memory free has been seen. */
  3595. if (NLP_CHK_FREE_REQ(ndlp))
  3596. NLP_SET_FREE_ACK(ndlp);
  3597. }
  3598. spin_unlock_irqrestore(&phba->ndlp_lock, flags);
  3599. /* Note, the kref_put returns 1 when decrementing a reference
  3600. * count that was 1, it invokes the release callback function,
  3601. * but it still left the reference count as 1 (not actually
  3602. * performs the last decrementation). Otherwise, it actually
  3603. * decrements the reference count and returns 0.
  3604. */
  3605. return kref_put(&ndlp->kref, lpfc_nlp_release);
  3606. }
  3607. /* This routine free's the specified nodelist if it is not in use
  3608. * by any other discovery thread. This routine returns 1 if the
  3609. * ndlp has been freed. A return value of 0 indicates the ndlp is
  3610. * not yet been released.
  3611. */
  3612. int
  3613. lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
  3614. {
  3615. lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
  3616. "node not used: did:x%x flg:x%x refcnt:x%x",
  3617. ndlp->nlp_DID, ndlp->nlp_flag,
  3618. atomic_read(&ndlp->kref.refcount));
  3619. if (atomic_read(&ndlp->kref.refcount) == 1)
  3620. if (lpfc_nlp_put(ndlp))
  3621. return 1;
  3622. return 0;
  3623. }
  3624. /**
  3625. * lpfc_fcf_inuse - Check if FCF can be unregistered.
  3626. * @phba: Pointer to hba context object.
  3627. *
  3628. * This function iterate through all FC nodes associated
  3629. * will all vports to check if there is any node with
  3630. * fc_rports associated with it. If there is an fc_rport
  3631. * associated with the node, then the node is either in
  3632. * discovered state or its devloss_timer is pending.
  3633. */
  3634. static int
  3635. lpfc_fcf_inuse(struct lpfc_hba *phba)
  3636. {
  3637. struct lpfc_vport **vports;
  3638. int i, ret = 0;
  3639. struct lpfc_nodelist *ndlp;
  3640. struct Scsi_Host *shost;
  3641. vports = lpfc_create_vport_work_array(phba);
  3642. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3643. shost = lpfc_shost_from_vport(vports[i]);
  3644. spin_lock_irq(shost->host_lock);
  3645. list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
  3646. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
  3647. (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  3648. ret = 1;
  3649. spin_unlock_irq(shost->host_lock);
  3650. goto out;
  3651. }
  3652. }
  3653. spin_unlock_irq(shost->host_lock);
  3654. }
  3655. out:
  3656. lpfc_destroy_vport_work_array(phba, vports);
  3657. return ret;
  3658. }
  3659. /**
  3660. * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
  3661. * @phba: Pointer to hba context object.
  3662. * @mboxq: Pointer to mailbox object.
  3663. *
  3664. * This function frees memory associated with the mailbox command.
  3665. */
  3666. static void
  3667. lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  3668. {
  3669. struct lpfc_vport *vport = mboxq->vport;
  3670. if (mboxq->u.mb.mbxStatus) {
  3671. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3672. "2555 UNREG_VFI mbxStatus error x%x "
  3673. "HBA state x%x\n",
  3674. mboxq->u.mb.mbxStatus, vport->port_state);
  3675. }
  3676. mempool_free(mboxq, phba->mbox_mem_pool);
  3677. return;
  3678. }
  3679. /**
  3680. * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
  3681. * @phba: Pointer to hba context object.
  3682. * @mboxq: Pointer to mailbox object.
  3683. *
  3684. * This function frees memory associated with the mailbox command.
  3685. */
  3686. static void
  3687. lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  3688. {
  3689. struct lpfc_vport *vport = mboxq->vport;
  3690. if (mboxq->u.mb.mbxStatus) {
  3691. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3692. "2550 UNREG_FCFI mbxStatus error x%x "
  3693. "HBA state x%x\n",
  3694. mboxq->u.mb.mbxStatus, vport->port_state);
  3695. }
  3696. mempool_free(mboxq, phba->mbox_mem_pool);
  3697. return;
  3698. }
  3699. /**
  3700. * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
  3701. * @phba: Pointer to hba context object.
  3702. *
  3703. * This function check if there are any connected remote port for the FCF and
  3704. * if all the devices are disconnected, this function unregister FCFI.
  3705. * This function also tries to use another FCF for discovery.
  3706. */
  3707. void
  3708. lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
  3709. {
  3710. LPFC_MBOXQ_t *mbox;
  3711. int rc;
  3712. struct lpfc_vport **vports;
  3713. int i;
  3714. spin_lock_irq(&phba->hbalock);
  3715. /*
  3716. * If HBA is not running in FIP mode or
  3717. * If HBA does not support FCoE or
  3718. * If FCF is not registered.
  3719. * do nothing.
  3720. */
  3721. if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
  3722. !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
  3723. (phba->cfg_enable_fip == 0)) {
  3724. spin_unlock_irq(&phba->hbalock);
  3725. return;
  3726. }
  3727. spin_unlock_irq(&phba->hbalock);
  3728. if (lpfc_fcf_inuse(phba))
  3729. return;
  3730. /* Unregister VPIs */
  3731. vports = lpfc_create_vport_work_array(phba);
  3732. if (vports &&
  3733. (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
  3734. for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
  3735. lpfc_mbx_unreg_vpi(vports[i]);
  3736. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3737. vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED;
  3738. }
  3739. lpfc_destroy_vport_work_array(phba, vports);
  3740. /* Unregister VFI */
  3741. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3742. if (!mbox) {
  3743. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3744. "2556 UNREG_VFI mbox allocation failed"
  3745. "HBA state x%x\n",
  3746. phba->pport->port_state);
  3747. return;
  3748. }
  3749. lpfc_unreg_vfi(mbox, phba->pport->vfi);
  3750. mbox->vport = phba->pport;
  3751. mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
  3752. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3753. if (rc == MBX_NOT_FINISHED) {
  3754. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3755. "2557 UNREG_VFI issue mbox failed rc x%x "
  3756. "HBA state x%x\n",
  3757. rc, phba->pport->port_state);
  3758. mempool_free(mbox, phba->mbox_mem_pool);
  3759. return;
  3760. }
  3761. /* Unregister FCF */
  3762. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3763. if (!mbox) {
  3764. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3765. "2551 UNREG_FCFI mbox allocation failed"
  3766. "HBA state x%x\n",
  3767. phba->pport->port_state);
  3768. return;
  3769. }
  3770. lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
  3771. mbox->vport = phba->pport;
  3772. mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
  3773. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  3774. if (rc == MBX_NOT_FINISHED) {
  3775. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3776. "2552 UNREG_FCFI issue mbox failed rc x%x "
  3777. "HBA state x%x\n",
  3778. rc, phba->pport->port_state);
  3779. mempool_free(mbox, phba->mbox_mem_pool);
  3780. return;
  3781. }
  3782. spin_lock_irq(&phba->hbalock);
  3783. phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_REGISTERED |
  3784. FCF_DISCOVERED | FCF_BOOT_ENABLE | FCF_IN_USE |
  3785. FCF_VALID_VLAN);
  3786. spin_unlock_irq(&phba->hbalock);
  3787. /*
  3788. * If driver is not unloading, check if there is any other
  3789. * FCF record that can be used for discovery.
  3790. */
  3791. if ((phba->pport->load_flag & FC_UNLOADING) ||
  3792. (phba->link_state < LPFC_LINK_UP))
  3793. return;
  3794. rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
  3795. if (rc)
  3796. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
  3797. "2553 lpfc_unregister_unused_fcf failed to read FCF"
  3798. " record HBA state x%x\n",
  3799. phba->pport->port_state);
  3800. }
  3801. /**
  3802. * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
  3803. * @phba: Pointer to hba context object.
  3804. * @buff: Buffer containing the FCF connection table as in the config
  3805. * region.
  3806. * This function create driver data structure for the FCF connection
  3807. * record table read from config region 23.
  3808. */
  3809. static void
  3810. lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
  3811. uint8_t *buff)
  3812. {
  3813. struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
  3814. struct lpfc_fcf_conn_hdr *conn_hdr;
  3815. struct lpfc_fcf_conn_rec *conn_rec;
  3816. uint32_t record_count;
  3817. int i;
  3818. /* Free the current connect table */
  3819. list_for_each_entry_safe(conn_entry, next_conn_entry,
  3820. &phba->fcf_conn_rec_list, list)
  3821. kfree(conn_entry);
  3822. conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
  3823. record_count = conn_hdr->length * sizeof(uint32_t)/
  3824. sizeof(struct lpfc_fcf_conn_rec);
  3825. conn_rec = (struct lpfc_fcf_conn_rec *)
  3826. (buff + sizeof(struct lpfc_fcf_conn_hdr));
  3827. for (i = 0; i < record_count; i++) {
  3828. if (!(conn_rec[i].flags & FCFCNCT_VALID))
  3829. continue;
  3830. conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
  3831. GFP_KERNEL);
  3832. if (!conn_entry) {
  3833. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3834. "2566 Failed to allocate connection"
  3835. " table entry\n");
  3836. return;
  3837. }
  3838. memcpy(&conn_entry->conn_rec, &conn_rec[i],
  3839. sizeof(struct lpfc_fcf_conn_rec));
  3840. conn_entry->conn_rec.vlan_tag =
  3841. le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
  3842. conn_entry->conn_rec.flags =
  3843. le16_to_cpu(conn_entry->conn_rec.flags);
  3844. list_add_tail(&conn_entry->list,
  3845. &phba->fcf_conn_rec_list);
  3846. }
  3847. }
  3848. /**
  3849. * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
  3850. * @phba: Pointer to hba context object.
  3851. * @buff: Buffer containing the FCoE parameter data structure.
  3852. *
  3853. * This function update driver data structure with config
  3854. * parameters read from config region 23.
  3855. */
  3856. static void
  3857. lpfc_read_fcoe_param(struct lpfc_hba *phba,
  3858. uint8_t *buff)
  3859. {
  3860. struct lpfc_fip_param_hdr *fcoe_param_hdr;
  3861. struct lpfc_fcoe_params *fcoe_param;
  3862. fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
  3863. buff;
  3864. fcoe_param = (struct lpfc_fcoe_params *)
  3865. buff + sizeof(struct lpfc_fip_param_hdr);
  3866. if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
  3867. (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
  3868. return;
  3869. if (bf_get(lpfc_fip_param_hdr_fipp_mode, fcoe_param_hdr) ==
  3870. FIPP_MODE_ON)
  3871. phba->cfg_enable_fip = 1;
  3872. if (bf_get(lpfc_fip_param_hdr_fipp_mode, fcoe_param_hdr) ==
  3873. FIPP_MODE_OFF)
  3874. phba->cfg_enable_fip = 0;
  3875. if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
  3876. phba->valid_vlan = 1;
  3877. phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
  3878. 0xFFF;
  3879. }
  3880. phba->fc_map[0] = fcoe_param->fc_map[0];
  3881. phba->fc_map[1] = fcoe_param->fc_map[1];
  3882. phba->fc_map[2] = fcoe_param->fc_map[2];
  3883. return;
  3884. }
  3885. /**
  3886. * lpfc_get_rec_conf23 - Get a record type in config region data.
  3887. * @buff: Buffer containing config region 23 data.
  3888. * @size: Size of the data buffer.
  3889. * @rec_type: Record type to be searched.
  3890. *
  3891. * This function searches config region data to find the begining
  3892. * of the record specified by record_type. If record found, this
  3893. * function return pointer to the record else return NULL.
  3894. */
  3895. static uint8_t *
  3896. lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
  3897. {
  3898. uint32_t offset = 0, rec_length;
  3899. if ((buff[0] == LPFC_REGION23_LAST_REC) ||
  3900. (size < sizeof(uint32_t)))
  3901. return NULL;
  3902. rec_length = buff[offset + 1];
  3903. /*
  3904. * One TLV record has one word header and number of data words
  3905. * specified in the rec_length field of the record header.
  3906. */
  3907. while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
  3908. <= size) {
  3909. if (buff[offset] == rec_type)
  3910. return &buff[offset];
  3911. if (buff[offset] == LPFC_REGION23_LAST_REC)
  3912. return NULL;
  3913. offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
  3914. rec_length = buff[offset + 1];
  3915. }
  3916. return NULL;
  3917. }
  3918. /**
  3919. * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
  3920. * @phba: Pointer to lpfc_hba data structure.
  3921. * @buff: Buffer containing config region 23 data.
  3922. * @size: Size of the data buffer.
  3923. *
  3924. * This fuction parse the FCoE config parameters in config region 23 and
  3925. * populate driver data structure with the parameters.
  3926. */
  3927. void
  3928. lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
  3929. uint8_t *buff,
  3930. uint32_t size)
  3931. {
  3932. uint32_t offset = 0, rec_length;
  3933. uint8_t *rec_ptr;
  3934. /*
  3935. * If data size is less than 2 words signature and version cannot be
  3936. * verified.
  3937. */
  3938. if (size < 2*sizeof(uint32_t))
  3939. return;
  3940. /* Check the region signature first */
  3941. if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
  3942. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3943. "2567 Config region 23 has bad signature\n");
  3944. return;
  3945. }
  3946. offset += 4;
  3947. /* Check the data structure version */
  3948. if (buff[offset] != LPFC_REGION23_VERSION) {
  3949. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  3950. "2568 Config region 23 has bad version\n");
  3951. return;
  3952. }
  3953. offset += 4;
  3954. rec_length = buff[offset + 1];
  3955. /* Read FCoE param record */
  3956. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  3957. size - offset, FCOE_PARAM_TYPE);
  3958. if (rec_ptr)
  3959. lpfc_read_fcoe_param(phba, rec_ptr);
  3960. /* Read FCF connection table */
  3961. rec_ptr = lpfc_get_rec_conf23(&buff[offset],
  3962. size - offset, FCOE_CONN_TBL_TYPE);
  3963. if (rec_ptr)
  3964. lpfc_read_fcf_conn_tbl(phba, rec_ptr);
  3965. }