lpfc_hbadisc.c 126 KB

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