lpfc_els.c 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2007 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/interrupt.h>
  24. #include <scsi/scsi.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_transport_fc.h>
  28. #include "lpfc_hw.h"
  29. #include "lpfc_sli.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_scsi.h"
  32. #include "lpfc.h"
  33. #include "lpfc_logmsg.h"
  34. #include "lpfc_crtn.h"
  35. #include "lpfc_vport.h"
  36. #include "lpfc_debugfs.h"
  37. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  38. struct lpfc_iocbq *);
  39. static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
  40. struct lpfc_iocbq *);
  41. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
  42. static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
  43. struct lpfc_nodelist *ndlp, uint8_t retry);
  44. static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
  45. struct lpfc_iocbq *iocb);
  46. static void lpfc_register_new_vport(struct lpfc_hba *phba,
  47. struct lpfc_vport *vport,
  48. struct lpfc_nodelist *ndlp);
  49. static int lpfc_max_els_tries = 3;
  50. int
  51. lpfc_els_chk_latt(struct lpfc_vport *vport)
  52. {
  53. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  54. struct lpfc_hba *phba = vport->phba;
  55. uint32_t ha_copy;
  56. if (vport->port_state >= LPFC_VPORT_READY ||
  57. phba->link_state == LPFC_LINK_DOWN)
  58. return 0;
  59. /* Read the HBA Host Attention Register */
  60. ha_copy = readl(phba->HAregaddr);
  61. if (!(ha_copy & HA_LATT))
  62. return 0;
  63. /* Pending Link Event during Discovery */
  64. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  65. "0237 Pending Link Event during "
  66. "Discovery: State x%x\n",
  67. phba->pport->port_state);
  68. /* CLEAR_LA should re-enable link attention events and
  69. * we should then imediately take a LATT event. The
  70. * LATT processing should call lpfc_linkdown() which
  71. * will cleanup any left over in-progress discovery
  72. * events.
  73. */
  74. spin_lock_irq(shost->host_lock);
  75. vport->fc_flag |= FC_ABORT_DISCOVERY;
  76. spin_unlock_irq(shost->host_lock);
  77. if (phba->link_state != LPFC_CLEAR_LA)
  78. lpfc_issue_clear_la(phba, vport);
  79. return 1;
  80. }
  81. static struct lpfc_iocbq *
  82. lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
  83. uint16_t cmdSize, uint8_t retry,
  84. struct lpfc_nodelist *ndlp, uint32_t did,
  85. uint32_t elscmd)
  86. {
  87. struct lpfc_hba *phba = vport->phba;
  88. struct lpfc_iocbq *elsiocb;
  89. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
  90. struct ulp_bde64 *bpl;
  91. IOCB_t *icmd;
  92. if (!lpfc_is_link_up(phba))
  93. return NULL;
  94. /* Allocate buffer for command iocb */
  95. elsiocb = lpfc_sli_get_iocbq(phba);
  96. if (elsiocb == NULL)
  97. return NULL;
  98. icmd = &elsiocb->iocb;
  99. /* fill in BDEs for command */
  100. /* Allocate buffer for command payload */
  101. pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  102. if (pcmd)
  103. pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
  104. if (!pcmd || !pcmd->virt) {
  105. kfree(pcmd);
  106. lpfc_sli_release_iocbq(phba, elsiocb);
  107. return NULL;
  108. }
  109. INIT_LIST_HEAD(&pcmd->list);
  110. /* Allocate buffer for response payload */
  111. if (expectRsp) {
  112. prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  113. if (prsp)
  114. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  115. &prsp->phys);
  116. if (!prsp || !prsp->virt) {
  117. kfree(prsp);
  118. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  119. kfree(pcmd);
  120. lpfc_sli_release_iocbq(phba, elsiocb);
  121. return NULL;
  122. }
  123. INIT_LIST_HEAD(&prsp->list);
  124. } else {
  125. prsp = NULL;
  126. }
  127. /* Allocate buffer for Buffer ptr list */
  128. pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  129. if (pbuflist)
  130. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  131. &pbuflist->phys);
  132. if (!pbuflist || !pbuflist->virt) {
  133. lpfc_sli_release_iocbq(phba, elsiocb);
  134. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  135. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  136. kfree(pcmd);
  137. kfree(prsp);
  138. kfree(pbuflist);
  139. return NULL;
  140. }
  141. INIT_LIST_HEAD(&pbuflist->list);
  142. icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  143. icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  144. icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
  145. icmd->un.elsreq64.remoteID = did; /* DID */
  146. if (expectRsp) {
  147. icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  148. icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  149. icmd->ulpTimeout = phba->fc_ratov * 2;
  150. } else {
  151. icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
  152. icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  153. }
  154. icmd->ulpBdeCount = 1;
  155. icmd->ulpLe = 1;
  156. icmd->ulpClass = CLASS3;
  157. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  158. icmd->un.elsreq64.myID = vport->fc_myDID;
  159. /* For ELS_REQUEST64_CR, use the VPI by default */
  160. icmd->ulpContext = vport->vpi;
  161. icmd->ulpCt_h = 0;
  162. icmd->ulpCt_l = 1;
  163. }
  164. bpl = (struct ulp_bde64 *) pbuflist->virt;
  165. bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
  166. bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
  167. bpl->tus.f.bdeSize = cmdSize;
  168. bpl->tus.f.bdeFlags = 0;
  169. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  170. if (expectRsp) {
  171. bpl++;
  172. bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
  173. bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
  174. bpl->tus.f.bdeSize = FCELSSIZE;
  175. bpl->tus.f.bdeFlags = BUFF_USE_RCV;
  176. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  177. }
  178. elsiocb->context1 = lpfc_nlp_get(ndlp);
  179. elsiocb->context2 = pcmd;
  180. elsiocb->context3 = pbuflist;
  181. elsiocb->retry = retry;
  182. elsiocb->vport = vport;
  183. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  184. if (prsp) {
  185. list_add(&prsp->list, &pcmd->list);
  186. }
  187. if (expectRsp) {
  188. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  189. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  190. "0116 Xmit ELS command x%x to remote "
  191. "NPORT x%x I/O tag: x%x, port state: x%x\n",
  192. elscmd, did, elsiocb->iotag,
  193. vport->port_state);
  194. } else {
  195. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  196. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  197. "0117 Xmit ELS response x%x to remote "
  198. "NPORT x%x I/O tag: x%x, size: x%x\n",
  199. elscmd, ndlp->nlp_DID, elsiocb->iotag,
  200. cmdSize);
  201. }
  202. return elsiocb;
  203. }
  204. static int
  205. lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
  206. {
  207. struct lpfc_hba *phba = vport->phba;
  208. LPFC_MBOXQ_t *mbox;
  209. struct lpfc_dmabuf *mp;
  210. struct lpfc_nodelist *ndlp;
  211. struct serv_parm *sp;
  212. int rc;
  213. int err = 0;
  214. sp = &phba->fc_fabparam;
  215. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  216. if (!ndlp) {
  217. err = 1;
  218. goto fail;
  219. }
  220. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  221. if (!mbox) {
  222. err = 2;
  223. goto fail;
  224. }
  225. vport->port_state = LPFC_FABRIC_CFG_LINK;
  226. lpfc_config_link(phba, mbox);
  227. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  228. mbox->vport = vport;
  229. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  230. if (rc == MBX_NOT_FINISHED) {
  231. err = 3;
  232. goto fail_free_mbox;
  233. }
  234. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  235. if (!mbox) {
  236. err = 4;
  237. goto fail;
  238. }
  239. rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
  240. 0);
  241. if (rc) {
  242. err = 5;
  243. goto fail_free_mbox;
  244. }
  245. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  246. mbox->vport = vport;
  247. mbox->context2 = lpfc_nlp_get(ndlp);
  248. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  249. if (rc == MBX_NOT_FINISHED) {
  250. err = 6;
  251. goto fail_issue_reg_login;
  252. }
  253. return 0;
  254. fail_issue_reg_login:
  255. lpfc_nlp_put(ndlp);
  256. mp = (struct lpfc_dmabuf *) mbox->context1;
  257. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  258. kfree(mp);
  259. fail_free_mbox:
  260. mempool_free(mbox, phba->mbox_mem_pool);
  261. fail:
  262. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  263. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  264. "0249 Cannot issue Register Fabric login: Err %d\n", err);
  265. return -ENXIO;
  266. }
  267. static int
  268. lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  269. struct serv_parm *sp, IOCB_t *irsp)
  270. {
  271. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  272. struct lpfc_hba *phba = vport->phba;
  273. struct lpfc_nodelist *np;
  274. struct lpfc_nodelist *next_np;
  275. spin_lock_irq(shost->host_lock);
  276. vport->fc_flag |= FC_FABRIC;
  277. spin_unlock_irq(shost->host_lock);
  278. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  279. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  280. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  281. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  282. if (phba->fc_topology == TOPOLOGY_LOOP) {
  283. spin_lock_irq(shost->host_lock);
  284. vport->fc_flag |= FC_PUBLIC_LOOP;
  285. spin_unlock_irq(shost->host_lock);
  286. } else {
  287. /*
  288. * If we are a N-port connected to a Fabric, fixup sparam's so
  289. * logins to devices on remote loops work.
  290. */
  291. vport->fc_sparam.cmn.altBbCredit = 1;
  292. }
  293. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  294. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  295. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
  296. ndlp->nlp_class_sup = 0;
  297. if (sp->cls1.classValid)
  298. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  299. if (sp->cls2.classValid)
  300. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  301. if (sp->cls3.classValid)
  302. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  303. if (sp->cls4.classValid)
  304. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  305. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  306. sp->cmn.bbRcvSizeLsb;
  307. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  308. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  309. if (sp->cmn.response_multiple_NPort) {
  310. lpfc_printf_vlog(vport, KERN_WARNING,
  311. LOG_ELS | LOG_VPORT,
  312. "1816 FLOGI NPIV supported, "
  313. "response data 0x%x\n",
  314. sp->cmn.response_multiple_NPort);
  315. phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
  316. } else {
  317. /* Because we asked f/w for NPIV it still expects us
  318. to call reg_vnpid atleast for the physcial host */
  319. lpfc_printf_vlog(vport, KERN_WARNING,
  320. LOG_ELS | LOG_VPORT,
  321. "1817 Fabric does not support NPIV "
  322. "- configuring single port mode.\n");
  323. phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
  324. }
  325. }
  326. if ((vport->fc_prevDID != vport->fc_myDID) &&
  327. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  328. /* If our NportID changed, we need to ensure all
  329. * remaining NPORTs get unreg_login'ed.
  330. */
  331. list_for_each_entry_safe(np, next_np,
  332. &vport->fc_nodes, nlp_listp) {
  333. if ((np->nlp_state != NLP_STE_NPR_NODE) ||
  334. !(np->nlp_flag & NLP_NPR_ADISC))
  335. continue;
  336. spin_lock_irq(shost->host_lock);
  337. np->nlp_flag &= ~NLP_NPR_ADISC;
  338. spin_unlock_irq(shost->host_lock);
  339. lpfc_unreg_rpi(vport, np);
  340. }
  341. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  342. lpfc_mbx_unreg_vpi(vport);
  343. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  344. }
  345. }
  346. ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
  347. lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  348. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
  349. vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
  350. lpfc_register_new_vport(phba, vport, ndlp);
  351. return 0;
  352. }
  353. lpfc_issue_fabric_reglogin(vport);
  354. return 0;
  355. }
  356. /*
  357. * We FLOGIed into an NPort, initiate pt2pt protocol
  358. */
  359. static int
  360. lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  361. struct serv_parm *sp)
  362. {
  363. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  364. struct lpfc_hba *phba = vport->phba;
  365. LPFC_MBOXQ_t *mbox;
  366. int rc;
  367. spin_lock_irq(shost->host_lock);
  368. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  369. spin_unlock_irq(shost->host_lock);
  370. phba->fc_edtov = FF_DEF_EDTOV;
  371. phba->fc_ratov = FF_DEF_RATOV;
  372. rc = memcmp(&vport->fc_portname, &sp->portName,
  373. sizeof(vport->fc_portname));
  374. if (rc >= 0) {
  375. /* This side will initiate the PLOGI */
  376. spin_lock_irq(shost->host_lock);
  377. vport->fc_flag |= FC_PT2PT_PLOGI;
  378. spin_unlock_irq(shost->host_lock);
  379. /*
  380. * N_Port ID cannot be 0, set our to LocalID the other
  381. * side will be RemoteID.
  382. */
  383. /* not equal */
  384. if (rc)
  385. vport->fc_myDID = PT2PT_LocalID;
  386. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  387. if (!mbox)
  388. goto fail;
  389. lpfc_config_link(phba, mbox);
  390. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  391. mbox->vport = vport;
  392. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  393. if (rc == MBX_NOT_FINISHED) {
  394. mempool_free(mbox, phba->mbox_mem_pool);
  395. goto fail;
  396. }
  397. lpfc_nlp_put(ndlp);
  398. ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
  399. if (!ndlp) {
  400. /*
  401. * Cannot find existing Fabric ndlp, so allocate a
  402. * new one
  403. */
  404. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  405. if (!ndlp)
  406. goto fail;
  407. lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
  408. }
  409. memcpy(&ndlp->nlp_portname, &sp->portName,
  410. sizeof(struct lpfc_name));
  411. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  412. sizeof(struct lpfc_name));
  413. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  414. spin_lock_irq(shost->host_lock);
  415. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  416. spin_unlock_irq(shost->host_lock);
  417. } else {
  418. /* This side will wait for the PLOGI */
  419. lpfc_nlp_put(ndlp);
  420. }
  421. spin_lock_irq(shost->host_lock);
  422. vport->fc_flag |= FC_PT2PT;
  423. spin_unlock_irq(shost->host_lock);
  424. /* Start discovery - this should just do CLEAR_LA */
  425. lpfc_disc_start(vport);
  426. return 0;
  427. fail:
  428. return -ENXIO;
  429. }
  430. static void
  431. lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  432. struct lpfc_iocbq *rspiocb)
  433. {
  434. struct lpfc_vport *vport = cmdiocb->vport;
  435. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  436. IOCB_t *irsp = &rspiocb->iocb;
  437. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  438. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  439. struct serv_parm *sp;
  440. int rc;
  441. /* Check to see if link went down during discovery */
  442. if (lpfc_els_chk_latt(vport)) {
  443. lpfc_nlp_put(ndlp);
  444. goto out;
  445. }
  446. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  447. "FLOGI cmpl: status:x%x/x%x state:x%x",
  448. irsp->ulpStatus, irsp->un.ulpWord[4],
  449. vport->port_state);
  450. if (irsp->ulpStatus) {
  451. /* Check for retry */
  452. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  453. goto out;
  454. /* FLOGI failed, so there is no fabric */
  455. spin_lock_irq(shost->host_lock);
  456. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  457. spin_unlock_irq(shost->host_lock);
  458. /* If private loop, then allow max outstanding els to be
  459. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  460. * alpa map would take too long otherwise.
  461. */
  462. if (phba->alpa_map[0] == 0) {
  463. vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
  464. }
  465. /* FLOGI failure */
  466. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  467. "0100 FLOGI failure Data: x%x x%x "
  468. "x%x\n",
  469. irsp->ulpStatus, irsp->un.ulpWord[4],
  470. irsp->ulpTimeout);
  471. goto flogifail;
  472. }
  473. /*
  474. * The FLogI succeeded. Sync the data for the CPU before
  475. * accessing it.
  476. */
  477. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  478. sp = prsp->virt + sizeof(uint32_t);
  479. /* FLOGI completes successfully */
  480. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  481. "0101 FLOGI completes sucessfully "
  482. "Data: x%x x%x x%x x%x\n",
  483. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  484. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
  485. if (vport->port_state == LPFC_FLOGI) {
  486. /*
  487. * If Common Service Parameters indicate Nport
  488. * we are point to point, if Fport we are Fabric.
  489. */
  490. if (sp->cmn.fPort)
  491. rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
  492. else
  493. rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
  494. if (!rc)
  495. goto out;
  496. }
  497. flogifail:
  498. lpfc_nlp_put(ndlp);
  499. if (!lpfc_error_lost_link(irsp)) {
  500. /* FLOGI failed, so just use loop map to make discovery list */
  501. lpfc_disc_list_loopmap(vport);
  502. /* Start discovery */
  503. lpfc_disc_start(vport);
  504. } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  505. ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
  506. (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
  507. (phba->link_state != LPFC_CLEAR_LA)) {
  508. /* If FLOGI failed enable link interrupt. */
  509. lpfc_issue_clear_la(phba, vport);
  510. }
  511. out:
  512. lpfc_els_free_iocb(phba, cmdiocb);
  513. }
  514. static int
  515. lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  516. uint8_t retry)
  517. {
  518. struct lpfc_hba *phba = vport->phba;
  519. struct serv_parm *sp;
  520. IOCB_t *icmd;
  521. struct lpfc_iocbq *elsiocb;
  522. struct lpfc_sli_ring *pring;
  523. uint8_t *pcmd;
  524. uint16_t cmdsize;
  525. uint32_t tmo;
  526. int rc;
  527. pring = &phba->sli.ring[LPFC_ELS_RING];
  528. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  529. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  530. ndlp->nlp_DID, ELS_CMD_FLOGI);
  531. if (!elsiocb)
  532. return 1;
  533. icmd = &elsiocb->iocb;
  534. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  535. /* For FLOGI request, remainder of payload is service parameters */
  536. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  537. pcmd += sizeof(uint32_t);
  538. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  539. sp = (struct serv_parm *) pcmd;
  540. /* Setup CSPs accordingly for Fabric */
  541. sp->cmn.e_d_tov = 0;
  542. sp->cmn.w2.r_a_tov = 0;
  543. sp->cls1.classValid = 0;
  544. sp->cls2.seqDelivery = 1;
  545. sp->cls3.seqDelivery = 1;
  546. if (sp->cmn.fcphLow < FC_PH3)
  547. sp->cmn.fcphLow = FC_PH3;
  548. if (sp->cmn.fcphHigh < FC_PH3)
  549. sp->cmn.fcphHigh = FC_PH3;
  550. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  551. sp->cmn.request_multiple_Nport = 1;
  552. /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
  553. icmd->ulpCt_h = 1;
  554. icmd->ulpCt_l = 0;
  555. }
  556. if (phba->fc_topology != TOPOLOGY_LOOP) {
  557. icmd->un.elsreq64.myID = 0;
  558. icmd->un.elsreq64.fl = 1;
  559. }
  560. tmo = phba->fc_ratov;
  561. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  562. lpfc_set_disctmo(vport);
  563. phba->fc_ratov = tmo;
  564. phba->fc_stat.elsXmitFLOGI++;
  565. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  566. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  567. "Issue FLOGI: opt:x%x",
  568. phba->sli3_options, 0, 0);
  569. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  570. if (rc == IOCB_ERROR) {
  571. lpfc_els_free_iocb(phba, elsiocb);
  572. return 1;
  573. }
  574. return 0;
  575. }
  576. int
  577. lpfc_els_abort_flogi(struct lpfc_hba *phba)
  578. {
  579. struct lpfc_sli_ring *pring;
  580. struct lpfc_iocbq *iocb, *next_iocb;
  581. struct lpfc_nodelist *ndlp;
  582. IOCB_t *icmd;
  583. /* Abort outstanding I/O on NPort <nlp_DID> */
  584. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  585. "0201 Abort outstanding I/O on NPort x%x\n",
  586. Fabric_DID);
  587. pring = &phba->sli.ring[LPFC_ELS_RING];
  588. /*
  589. * Check the txcmplq for an iocb that matches the nport the driver is
  590. * searching for.
  591. */
  592. spin_lock_irq(&phba->hbalock);
  593. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  594. icmd = &iocb->iocb;
  595. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
  596. icmd->un.elsreq64.bdl.ulpIoTag32) {
  597. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  598. if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
  599. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  600. }
  601. }
  602. }
  603. spin_unlock_irq(&phba->hbalock);
  604. return 0;
  605. }
  606. int
  607. lpfc_initial_flogi(struct lpfc_vport *vport)
  608. {
  609. struct lpfc_hba *phba = vport->phba;
  610. struct lpfc_nodelist *ndlp;
  611. vport->port_state = LPFC_FLOGI;
  612. lpfc_set_disctmo(vport);
  613. /* First look for the Fabric ndlp */
  614. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  615. if (!ndlp) {
  616. /* Cannot find existing Fabric ndlp, so allocate a new one */
  617. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  618. if (!ndlp)
  619. return 0;
  620. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  621. } else {
  622. lpfc_dequeue_node(vport, ndlp);
  623. }
  624. if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
  625. lpfc_nlp_put(ndlp);
  626. }
  627. return 1;
  628. }
  629. int
  630. lpfc_initial_fdisc(struct lpfc_vport *vport)
  631. {
  632. struct lpfc_hba *phba = vport->phba;
  633. struct lpfc_nodelist *ndlp;
  634. /* First look for the Fabric ndlp */
  635. ndlp = lpfc_findnode_did(vport, Fabric_DID);
  636. if (!ndlp) {
  637. /* Cannot find existing Fabric ndlp, so allocate a new one */
  638. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  639. if (!ndlp)
  640. return 0;
  641. lpfc_nlp_init(vport, ndlp, Fabric_DID);
  642. } else {
  643. lpfc_dequeue_node(vport, ndlp);
  644. }
  645. if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
  646. lpfc_nlp_put(ndlp);
  647. }
  648. return 1;
  649. }
  650. void
  651. lpfc_more_plogi(struct lpfc_vport *vport)
  652. {
  653. int sentplogi;
  654. if (vport->num_disc_nodes)
  655. vport->num_disc_nodes--;
  656. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  657. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  658. "0232 Continue discovery with %d PLOGIs to go "
  659. "Data: x%x x%x x%x\n",
  660. vport->num_disc_nodes, vport->fc_plogi_cnt,
  661. vport->fc_flag, vport->port_state);
  662. /* Check to see if there are more PLOGIs to be sent */
  663. if (vport->fc_flag & FC_NLP_MORE)
  664. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  665. sentplogi = lpfc_els_disc_plogi(vport);
  666. return;
  667. }
  668. static struct lpfc_nodelist *
  669. lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
  670. struct lpfc_nodelist *ndlp)
  671. {
  672. struct lpfc_vport *vport = ndlp->vport;
  673. struct lpfc_nodelist *new_ndlp;
  674. struct serv_parm *sp;
  675. uint8_t name[sizeof(struct lpfc_name)];
  676. uint32_t rc;
  677. /* Fabric nodes can have the same WWPN so we don't bother searching
  678. * by WWPN. Just return the ndlp that was given to us.
  679. */
  680. if (ndlp->nlp_type & NLP_FABRIC)
  681. return ndlp;
  682. sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
  683. memset(name, 0, sizeof(struct lpfc_name));
  684. /* Now we find out if the NPort we are logging into, matches the WWPN
  685. * we have for that ndlp. If not, we have some work to do.
  686. */
  687. new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
  688. if (new_ndlp == ndlp)
  689. return ndlp;
  690. if (!new_ndlp) {
  691. rc = memcmp(&ndlp->nlp_portname, name,
  692. sizeof(struct lpfc_name));
  693. if (!rc)
  694. return ndlp;
  695. new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  696. if (!new_ndlp)
  697. return ndlp;
  698. lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
  699. }
  700. lpfc_unreg_rpi(vport, new_ndlp);
  701. new_ndlp->nlp_DID = ndlp->nlp_DID;
  702. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  703. lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
  704. /* Move this back to NPR state */
  705. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
  706. /* The new_ndlp is replacing ndlp totally, so we need
  707. * to put ndlp on UNUSED list and try to free it.
  708. */
  709. lpfc_drop_node(vport, ndlp);
  710. }
  711. else {
  712. lpfc_unreg_rpi(vport, ndlp);
  713. ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
  714. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  715. }
  716. return new_ndlp;
  717. }
  718. void
  719. lpfc_end_rscn(struct lpfc_vport *vport)
  720. {
  721. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  722. if (vport->fc_flag & FC_RSCN_MODE) {
  723. /*
  724. * Check to see if more RSCNs came in while we were
  725. * processing this one.
  726. */
  727. if (vport->fc_rscn_id_cnt ||
  728. (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
  729. lpfc_els_handle_rscn(vport);
  730. else {
  731. spin_lock_irq(shost->host_lock);
  732. vport->fc_flag &= ~FC_RSCN_MODE;
  733. spin_unlock_irq(shost->host_lock);
  734. }
  735. }
  736. }
  737. static void
  738. lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  739. struct lpfc_iocbq *rspiocb)
  740. {
  741. struct lpfc_vport *vport = cmdiocb->vport;
  742. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  743. IOCB_t *irsp;
  744. struct lpfc_nodelist *ndlp;
  745. struct lpfc_dmabuf *prsp;
  746. int disc, rc, did, type;
  747. /* we pass cmdiocb to state machine which needs rspiocb as well */
  748. cmdiocb->context_un.rsp_iocb = rspiocb;
  749. irsp = &rspiocb->iocb;
  750. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  751. "PLOGI cmpl: status:x%x/x%x did:x%x",
  752. irsp->ulpStatus, irsp->un.ulpWord[4],
  753. irsp->un.elsreq64.remoteID);
  754. ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
  755. if (!ndlp) {
  756. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  757. "0136 PLOGI completes to NPort x%x "
  758. "with no ndlp. Data: x%x x%x x%x\n",
  759. irsp->un.elsreq64.remoteID,
  760. irsp->ulpStatus, irsp->un.ulpWord[4],
  761. irsp->ulpIoTag);
  762. goto out;
  763. }
  764. /* Since ndlp can be freed in the disc state machine, note if this node
  765. * is being used during discovery.
  766. */
  767. spin_lock_irq(shost->host_lock);
  768. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  769. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  770. spin_unlock_irq(shost->host_lock);
  771. rc = 0;
  772. /* PLOGI completes to NPort <nlp_DID> */
  773. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  774. "0102 PLOGI completes to NPort x%x "
  775. "Data: x%x x%x x%x x%x x%x\n",
  776. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  777. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  778. /* Check to see if link went down during discovery */
  779. if (lpfc_els_chk_latt(vport)) {
  780. spin_lock_irq(shost->host_lock);
  781. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  782. spin_unlock_irq(shost->host_lock);
  783. goto out;
  784. }
  785. /* ndlp could be freed in DSM, save these values now */
  786. type = ndlp->nlp_type;
  787. did = ndlp->nlp_DID;
  788. if (irsp->ulpStatus) {
  789. /* Check for retry */
  790. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  791. /* ELS command is being retried */
  792. if (disc) {
  793. spin_lock_irq(shost->host_lock);
  794. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  795. spin_unlock_irq(shost->host_lock);
  796. }
  797. goto out;
  798. }
  799. /* PLOGI failed */
  800. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  801. if (lpfc_error_lost_link(irsp)) {
  802. rc = NLP_STE_FREED_NODE;
  803. } else {
  804. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  805. NLP_EVT_CMPL_PLOGI);
  806. }
  807. } else {
  808. /* Good status, call state machine */
  809. prsp = list_entry(((struct lpfc_dmabuf *)
  810. cmdiocb->context2)->list.next,
  811. struct lpfc_dmabuf, list);
  812. ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
  813. rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  814. NLP_EVT_CMPL_PLOGI);
  815. }
  816. if (disc && vport->num_disc_nodes) {
  817. /* Check to see if there are more PLOGIs to be sent */
  818. lpfc_more_plogi(vport);
  819. if (vport->num_disc_nodes == 0) {
  820. spin_lock_irq(shost->host_lock);
  821. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  822. spin_unlock_irq(shost->host_lock);
  823. lpfc_can_disctmo(vport);
  824. lpfc_end_rscn(vport);
  825. }
  826. }
  827. out:
  828. lpfc_els_free_iocb(phba, cmdiocb);
  829. return;
  830. }
  831. int
  832. lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
  833. {
  834. struct lpfc_hba *phba = vport->phba;
  835. struct serv_parm *sp;
  836. IOCB_t *icmd;
  837. struct lpfc_nodelist *ndlp;
  838. struct lpfc_iocbq *elsiocb;
  839. struct lpfc_sli_ring *pring;
  840. struct lpfc_sli *psli;
  841. uint8_t *pcmd;
  842. uint16_t cmdsize;
  843. int ret;
  844. psli = &phba->sli;
  845. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  846. ndlp = lpfc_findnode_did(vport, did);
  847. /* If ndlp if not NULL, we will bump the reference count on it */
  848. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  849. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  850. ELS_CMD_PLOGI);
  851. if (!elsiocb)
  852. return 1;
  853. icmd = &elsiocb->iocb;
  854. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  855. /* For PLOGI request, remainder of payload is service parameters */
  856. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  857. pcmd += sizeof(uint32_t);
  858. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  859. sp = (struct serv_parm *) pcmd;
  860. if (sp->cmn.fcphLow < FC_PH_4_3)
  861. sp->cmn.fcphLow = FC_PH_4_3;
  862. if (sp->cmn.fcphHigh < FC_PH3)
  863. sp->cmn.fcphHigh = FC_PH3;
  864. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  865. "Issue PLOGI: did:x%x",
  866. did, 0, 0);
  867. phba->fc_stat.elsXmitPLOGI++;
  868. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  869. ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  870. if (ret == IOCB_ERROR) {
  871. lpfc_els_free_iocb(phba, elsiocb);
  872. return 1;
  873. }
  874. return 0;
  875. }
  876. static void
  877. lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  878. struct lpfc_iocbq *rspiocb)
  879. {
  880. struct lpfc_vport *vport = cmdiocb->vport;
  881. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  882. IOCB_t *irsp;
  883. struct lpfc_sli *psli;
  884. struct lpfc_nodelist *ndlp;
  885. psli = &phba->sli;
  886. /* we pass cmdiocb to state machine which needs rspiocb as well */
  887. cmdiocb->context_un.rsp_iocb = rspiocb;
  888. irsp = &(rspiocb->iocb);
  889. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  890. spin_lock_irq(shost->host_lock);
  891. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  892. spin_unlock_irq(shost->host_lock);
  893. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  894. "PRLI cmpl: status:x%x/x%x did:x%x",
  895. irsp->ulpStatus, irsp->un.ulpWord[4],
  896. ndlp->nlp_DID);
  897. /* PRLI completes to NPort <nlp_DID> */
  898. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  899. "0103 PRLI completes to NPort x%x "
  900. "Data: x%x x%x x%x x%x\n",
  901. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  902. irsp->ulpTimeout, vport->num_disc_nodes);
  903. vport->fc_prli_sent--;
  904. /* Check to see if link went down during discovery */
  905. if (lpfc_els_chk_latt(vport))
  906. goto out;
  907. if (irsp->ulpStatus) {
  908. /* Check for retry */
  909. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  910. /* ELS command is being retried */
  911. goto out;
  912. }
  913. /* PRLI failed */
  914. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  915. if (lpfc_error_lost_link(irsp)) {
  916. goto out;
  917. } else {
  918. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  919. NLP_EVT_CMPL_PRLI);
  920. }
  921. } else {
  922. /* Good status, call state machine */
  923. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  924. NLP_EVT_CMPL_PRLI);
  925. }
  926. out:
  927. lpfc_els_free_iocb(phba, cmdiocb);
  928. return;
  929. }
  930. int
  931. lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  932. uint8_t retry)
  933. {
  934. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  935. struct lpfc_hba *phba = vport->phba;
  936. PRLI *npr;
  937. IOCB_t *icmd;
  938. struct lpfc_iocbq *elsiocb;
  939. struct lpfc_sli_ring *pring;
  940. struct lpfc_sli *psli;
  941. uint8_t *pcmd;
  942. uint16_t cmdsize;
  943. psli = &phba->sli;
  944. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  945. cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
  946. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  947. ndlp->nlp_DID, ELS_CMD_PRLI);
  948. if (!elsiocb)
  949. return 1;
  950. icmd = &elsiocb->iocb;
  951. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  952. /* For PRLI request, remainder of payload is service parameters */
  953. memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
  954. *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
  955. pcmd += sizeof(uint32_t);
  956. /* For PRLI, remainder of payload is PRLI parameter page */
  957. npr = (PRLI *) pcmd;
  958. /*
  959. * If our firmware version is 3.20 or later,
  960. * set the following bits for FC-TAPE support.
  961. */
  962. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  963. npr->ConfmComplAllowed = 1;
  964. npr->Retry = 1;
  965. npr->TaskRetryIdReq = 1;
  966. }
  967. npr->estabImagePair = 1;
  968. npr->readXferRdyDis = 1;
  969. /* For FCP support */
  970. npr->prliType = PRLI_FCP_TYPE;
  971. npr->initiatorFunc = 1;
  972. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  973. "Issue PRLI: did:x%x",
  974. ndlp->nlp_DID, 0, 0);
  975. phba->fc_stat.elsXmitPRLI++;
  976. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  977. spin_lock_irq(shost->host_lock);
  978. ndlp->nlp_flag |= NLP_PRLI_SND;
  979. spin_unlock_irq(shost->host_lock);
  980. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  981. spin_lock_irq(shost->host_lock);
  982. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  983. spin_unlock_irq(shost->host_lock);
  984. lpfc_els_free_iocb(phba, elsiocb);
  985. return 1;
  986. }
  987. vport->fc_prli_sent++;
  988. return 0;
  989. }
  990. static void
  991. lpfc_more_adisc(struct lpfc_vport *vport)
  992. {
  993. int sentadisc;
  994. if (vport->num_disc_nodes)
  995. vport->num_disc_nodes--;
  996. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  997. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  998. "0210 Continue discovery with %d ADISCs to go "
  999. "Data: x%x x%x x%x\n",
  1000. vport->num_disc_nodes, vport->fc_adisc_cnt,
  1001. vport->fc_flag, vport->port_state);
  1002. /* Check to see if there are more ADISCs to be sent */
  1003. if (vport->fc_flag & FC_NLP_MORE) {
  1004. lpfc_set_disctmo(vport);
  1005. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  1006. sentadisc = lpfc_els_disc_adisc(vport);
  1007. }
  1008. return;
  1009. }
  1010. static void
  1011. lpfc_rscn_disc(struct lpfc_vport *vport)
  1012. {
  1013. lpfc_can_disctmo(vport);
  1014. /* RSCN discovery */
  1015. /* go thru NPR nodes and issue ELS PLOGIs */
  1016. if (vport->fc_npr_cnt)
  1017. if (lpfc_els_disc_plogi(vport))
  1018. return;
  1019. lpfc_end_rscn(vport);
  1020. }
  1021. static void
  1022. lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1023. struct lpfc_iocbq *rspiocb)
  1024. {
  1025. struct lpfc_vport *vport = cmdiocb->vport;
  1026. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1027. IOCB_t *irsp;
  1028. struct lpfc_nodelist *ndlp;
  1029. int disc;
  1030. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1031. cmdiocb->context_un.rsp_iocb = rspiocb;
  1032. irsp = &(rspiocb->iocb);
  1033. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1034. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1035. "ADISC cmpl: status:x%x/x%x did:x%x",
  1036. irsp->ulpStatus, irsp->un.ulpWord[4],
  1037. ndlp->nlp_DID);
  1038. /* Since ndlp can be freed in the disc state machine, note if this node
  1039. * is being used during discovery.
  1040. */
  1041. spin_lock_irq(shost->host_lock);
  1042. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  1043. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  1044. spin_unlock_irq(shost->host_lock);
  1045. /* ADISC completes to NPort <nlp_DID> */
  1046. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1047. "0104 ADISC completes to NPort x%x "
  1048. "Data: x%x x%x x%x x%x x%x\n",
  1049. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1050. irsp->ulpTimeout, disc, vport->num_disc_nodes);
  1051. /* Check to see if link went down during discovery */
  1052. if (lpfc_els_chk_latt(vport)) {
  1053. spin_lock_irq(shost->host_lock);
  1054. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1055. spin_unlock_irq(shost->host_lock);
  1056. goto out;
  1057. }
  1058. if (irsp->ulpStatus) {
  1059. /* Check for retry */
  1060. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1061. /* ELS command is being retried */
  1062. if (disc) {
  1063. spin_lock_irq(shost->host_lock);
  1064. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  1065. spin_unlock_irq(shost->host_lock);
  1066. lpfc_set_disctmo(vport);
  1067. }
  1068. goto out;
  1069. }
  1070. /* ADISC failed */
  1071. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1072. if (!lpfc_error_lost_link(irsp)) {
  1073. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1074. NLP_EVT_CMPL_ADISC);
  1075. }
  1076. } else {
  1077. /* Good status, call state machine */
  1078. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1079. NLP_EVT_CMPL_ADISC);
  1080. }
  1081. if (disc && vport->num_disc_nodes) {
  1082. /* Check to see if there are more ADISCs to be sent */
  1083. lpfc_more_adisc(vport);
  1084. /* Check to see if we are done with ADISC authentication */
  1085. if (vport->num_disc_nodes == 0) {
  1086. /* If we get here, there is nothing left to ADISC */
  1087. /*
  1088. * For NPIV, cmpl_reg_vpi will set port_state to READY,
  1089. * and continue discovery.
  1090. */
  1091. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1092. !(vport->fc_flag & FC_RSCN_MODE)) {
  1093. lpfc_issue_reg_vpi(phba, vport);
  1094. goto out;
  1095. }
  1096. /*
  1097. * For SLI2, we need to set port_state to READY
  1098. * and continue discovery.
  1099. */
  1100. if (vport->port_state < LPFC_VPORT_READY) {
  1101. /* If we get here, there is nothing to ADISC */
  1102. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1103. lpfc_issue_clear_la(phba, vport);
  1104. if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
  1105. vport->num_disc_nodes = 0;
  1106. /* go thru NPR list, issue ELS PLOGIs */
  1107. if (vport->fc_npr_cnt)
  1108. lpfc_els_disc_plogi(vport);
  1109. if (!vport->num_disc_nodes) {
  1110. spin_lock_irq(shost->host_lock);
  1111. vport->fc_flag &=
  1112. ~FC_NDISC_ACTIVE;
  1113. spin_unlock_irq(
  1114. shost->host_lock);
  1115. lpfc_can_disctmo(vport);
  1116. }
  1117. }
  1118. vport->port_state = LPFC_VPORT_READY;
  1119. } else {
  1120. lpfc_rscn_disc(vport);
  1121. }
  1122. }
  1123. }
  1124. out:
  1125. lpfc_els_free_iocb(phba, cmdiocb);
  1126. return;
  1127. }
  1128. int
  1129. lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1130. uint8_t retry)
  1131. {
  1132. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1133. struct lpfc_hba *phba = vport->phba;
  1134. ADISC *ap;
  1135. IOCB_t *icmd;
  1136. struct lpfc_iocbq *elsiocb;
  1137. struct lpfc_sli *psli = &phba->sli;
  1138. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  1139. uint8_t *pcmd;
  1140. uint16_t cmdsize;
  1141. cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
  1142. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1143. ndlp->nlp_DID, ELS_CMD_ADISC);
  1144. if (!elsiocb)
  1145. return 1;
  1146. icmd = &elsiocb->iocb;
  1147. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1148. /* For ADISC request, remainder of payload is service parameters */
  1149. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  1150. pcmd += sizeof(uint32_t);
  1151. /* Fill in ADISC payload */
  1152. ap = (ADISC *) pcmd;
  1153. ap->hardAL_PA = phba->fc_pref_ALPA;
  1154. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  1155. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  1156. ap->DID = be32_to_cpu(vport->fc_myDID);
  1157. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1158. "Issue ADISC: did:x%x",
  1159. ndlp->nlp_DID, 0, 0);
  1160. phba->fc_stat.elsXmitADISC++;
  1161. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  1162. spin_lock_irq(shost->host_lock);
  1163. ndlp->nlp_flag |= NLP_ADISC_SND;
  1164. spin_unlock_irq(shost->host_lock);
  1165. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1166. spin_lock_irq(shost->host_lock);
  1167. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  1168. spin_unlock_irq(shost->host_lock);
  1169. lpfc_els_free_iocb(phba, elsiocb);
  1170. return 1;
  1171. }
  1172. return 0;
  1173. }
  1174. static void
  1175. lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1176. struct lpfc_iocbq *rspiocb)
  1177. {
  1178. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1179. struct lpfc_vport *vport = ndlp->vport;
  1180. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1181. IOCB_t *irsp;
  1182. struct lpfc_sli *psli;
  1183. psli = &phba->sli;
  1184. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1185. cmdiocb->context_un.rsp_iocb = rspiocb;
  1186. irsp = &(rspiocb->iocb);
  1187. spin_lock_irq(shost->host_lock);
  1188. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1189. spin_unlock_irq(shost->host_lock);
  1190. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1191. "LOGO cmpl: status:x%x/x%x did:x%x",
  1192. irsp->ulpStatus, irsp->un.ulpWord[4],
  1193. ndlp->nlp_DID);
  1194. /* LOGO completes to NPort <nlp_DID> */
  1195. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1196. "0105 LOGO completes to NPort x%x "
  1197. "Data: x%x x%x x%x x%x\n",
  1198. ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
  1199. irsp->ulpTimeout, vport->num_disc_nodes);
  1200. /* Check to see if link went down during discovery */
  1201. if (lpfc_els_chk_latt(vport))
  1202. goto out;
  1203. if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
  1204. /* NLP_EVT_DEVICE_RM should unregister the RPI
  1205. * which should abort all outstanding IOs.
  1206. */
  1207. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1208. NLP_EVT_DEVICE_RM);
  1209. goto out;
  1210. }
  1211. if (irsp->ulpStatus) {
  1212. /* Check for retry */
  1213. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  1214. /* ELS command is being retried */
  1215. goto out;
  1216. /* LOGO failed */
  1217. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1218. if (lpfc_error_lost_link(irsp))
  1219. goto out;
  1220. else
  1221. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1222. NLP_EVT_CMPL_LOGO);
  1223. } else {
  1224. /* Good status, call state machine.
  1225. * This will unregister the rpi if needed.
  1226. */
  1227. lpfc_disc_state_machine(vport, ndlp, cmdiocb,
  1228. NLP_EVT_CMPL_LOGO);
  1229. }
  1230. out:
  1231. lpfc_els_free_iocb(phba, cmdiocb);
  1232. return;
  1233. }
  1234. int
  1235. lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  1236. uint8_t retry)
  1237. {
  1238. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1239. struct lpfc_hba *phba = vport->phba;
  1240. IOCB_t *icmd;
  1241. struct lpfc_iocbq *elsiocb;
  1242. struct lpfc_sli_ring *pring;
  1243. struct lpfc_sli *psli;
  1244. uint8_t *pcmd;
  1245. uint16_t cmdsize;
  1246. int rc;
  1247. psli = &phba->sli;
  1248. pring = &psli->ring[LPFC_ELS_RING];
  1249. spin_lock_irq(shost->host_lock);
  1250. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  1251. spin_unlock_irq(shost->host_lock);
  1252. return 0;
  1253. }
  1254. spin_unlock_irq(shost->host_lock);
  1255. cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
  1256. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1257. ndlp->nlp_DID, ELS_CMD_LOGO);
  1258. if (!elsiocb)
  1259. return 1;
  1260. icmd = &elsiocb->iocb;
  1261. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1262. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  1263. pcmd += sizeof(uint32_t);
  1264. /* Fill in LOGO payload */
  1265. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  1266. pcmd += sizeof(uint32_t);
  1267. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  1268. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1269. "Issue LOGO: did:x%x",
  1270. ndlp->nlp_DID, 0, 0);
  1271. phba->fc_stat.elsXmitLOGO++;
  1272. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  1273. spin_lock_irq(shost->host_lock);
  1274. ndlp->nlp_flag |= NLP_LOGO_SND;
  1275. spin_unlock_irq(shost->host_lock);
  1276. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1277. if (rc == IOCB_ERROR) {
  1278. spin_lock_irq(shost->host_lock);
  1279. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1280. spin_unlock_irq(shost->host_lock);
  1281. lpfc_els_free_iocb(phba, elsiocb);
  1282. return 1;
  1283. }
  1284. return 0;
  1285. }
  1286. static void
  1287. lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1288. struct lpfc_iocbq *rspiocb)
  1289. {
  1290. struct lpfc_vport *vport = cmdiocb->vport;
  1291. IOCB_t *irsp;
  1292. irsp = &rspiocb->iocb;
  1293. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1294. "ELS cmd cmpl: status:x%x/x%x did:x%x",
  1295. irsp->ulpStatus, irsp->un.ulpWord[4],
  1296. irsp->un.elsreq64.remoteID);
  1297. /* ELS cmd tag <ulpIoTag> completes */
  1298. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1299. "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  1300. irsp->ulpIoTag, irsp->ulpStatus,
  1301. irsp->un.ulpWord[4], irsp->ulpTimeout);
  1302. /* Check to see if link went down during discovery */
  1303. lpfc_els_chk_latt(vport);
  1304. lpfc_els_free_iocb(phba, cmdiocb);
  1305. return;
  1306. }
  1307. int
  1308. lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  1309. {
  1310. struct lpfc_hba *phba = vport->phba;
  1311. IOCB_t *icmd;
  1312. struct lpfc_iocbq *elsiocb;
  1313. struct lpfc_sli_ring *pring;
  1314. struct lpfc_sli *psli;
  1315. uint8_t *pcmd;
  1316. uint16_t cmdsize;
  1317. struct lpfc_nodelist *ndlp;
  1318. psli = &phba->sli;
  1319. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1320. cmdsize = (sizeof(uint32_t) + sizeof(SCR));
  1321. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1322. if (!ndlp)
  1323. return 1;
  1324. lpfc_nlp_init(vport, ndlp, nportid);
  1325. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1326. ndlp->nlp_DID, ELS_CMD_SCR);
  1327. if (!elsiocb) {
  1328. lpfc_nlp_put(ndlp);
  1329. return 1;
  1330. }
  1331. icmd = &elsiocb->iocb;
  1332. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1333. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  1334. pcmd += sizeof(uint32_t);
  1335. /* For SCR, remainder of payload is SCR parameter page */
  1336. memset(pcmd, 0, sizeof(SCR));
  1337. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  1338. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1339. "Issue SCR: did:x%x",
  1340. ndlp->nlp_DID, 0, 0);
  1341. phba->fc_stat.elsXmitSCR++;
  1342. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1343. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1344. lpfc_nlp_put(ndlp);
  1345. lpfc_els_free_iocb(phba, elsiocb);
  1346. return 1;
  1347. }
  1348. lpfc_nlp_put(ndlp);
  1349. return 0;
  1350. }
  1351. static int
  1352. lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
  1353. {
  1354. struct lpfc_hba *phba = vport->phba;
  1355. IOCB_t *icmd;
  1356. struct lpfc_iocbq *elsiocb;
  1357. struct lpfc_sli_ring *pring;
  1358. struct lpfc_sli *psli;
  1359. FARP *fp;
  1360. uint8_t *pcmd;
  1361. uint32_t *lp;
  1362. uint16_t cmdsize;
  1363. struct lpfc_nodelist *ondlp;
  1364. struct lpfc_nodelist *ndlp;
  1365. psli = &phba->sli;
  1366. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1367. cmdsize = (sizeof(uint32_t) + sizeof(FARP));
  1368. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1369. if (!ndlp)
  1370. return 1;
  1371. lpfc_nlp_init(vport, ndlp, nportid);
  1372. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
  1373. ndlp->nlp_DID, ELS_CMD_RNID);
  1374. if (!elsiocb) {
  1375. lpfc_nlp_put(ndlp);
  1376. return 1;
  1377. }
  1378. icmd = &elsiocb->iocb;
  1379. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1380. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  1381. pcmd += sizeof(uint32_t);
  1382. /* Fill in FARPR payload */
  1383. fp = (FARP *) (pcmd);
  1384. memset(fp, 0, sizeof(FARP));
  1385. lp = (uint32_t *) pcmd;
  1386. *lp++ = be32_to_cpu(nportid);
  1387. *lp++ = be32_to_cpu(vport->fc_myDID);
  1388. fp->Rflags = 0;
  1389. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  1390. memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
  1391. memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  1392. ondlp = lpfc_findnode_did(vport, nportid);
  1393. if (ondlp) {
  1394. memcpy(&fp->OportName, &ondlp->nlp_portname,
  1395. sizeof(struct lpfc_name));
  1396. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  1397. sizeof(struct lpfc_name));
  1398. }
  1399. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1400. "Issue FARPR: did:x%x",
  1401. ndlp->nlp_DID, 0, 0);
  1402. phba->fc_stat.elsXmitFARPR++;
  1403. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1404. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1405. lpfc_nlp_put(ndlp);
  1406. lpfc_els_free_iocb(phba, elsiocb);
  1407. return 1;
  1408. }
  1409. lpfc_nlp_put(ndlp);
  1410. return 0;
  1411. }
  1412. void
  1413. lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
  1414. {
  1415. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1416. spin_lock_irq(shost->host_lock);
  1417. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  1418. spin_unlock_irq(shost->host_lock);
  1419. del_timer_sync(&nlp->nlp_delayfunc);
  1420. nlp->nlp_last_elscmd = 0;
  1421. if (!list_empty(&nlp->els_retry_evt.evt_listp))
  1422. list_del_init(&nlp->els_retry_evt.evt_listp);
  1423. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  1424. spin_lock_irq(shost->host_lock);
  1425. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1426. spin_unlock_irq(shost->host_lock);
  1427. if (vport->num_disc_nodes) {
  1428. /* Check to see if there are more
  1429. * PLOGIs to be sent
  1430. */
  1431. lpfc_more_plogi(vport);
  1432. if (vport->num_disc_nodes == 0) {
  1433. spin_lock_irq(shost->host_lock);
  1434. vport->fc_flag &= ~FC_NDISC_ACTIVE;
  1435. spin_unlock_irq(shost->host_lock);
  1436. lpfc_can_disctmo(vport);
  1437. lpfc_end_rscn(vport);
  1438. }
  1439. }
  1440. }
  1441. return;
  1442. }
  1443. void
  1444. lpfc_els_retry_delay(unsigned long ptr)
  1445. {
  1446. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
  1447. struct lpfc_vport *vport = ndlp->vport;
  1448. struct lpfc_hba *phba = vport->phba;
  1449. unsigned long flags;
  1450. struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
  1451. ndlp = (struct lpfc_nodelist *) ptr;
  1452. phba = ndlp->vport->phba;
  1453. evtp = &ndlp->els_retry_evt;
  1454. spin_lock_irqsave(&phba->hbalock, flags);
  1455. if (!list_empty(&evtp->evt_listp)) {
  1456. spin_unlock_irqrestore(&phba->hbalock, flags);
  1457. return;
  1458. }
  1459. evtp->evt_arg1 = ndlp;
  1460. evtp->evt = LPFC_EVT_ELS_RETRY;
  1461. list_add_tail(&evtp->evt_listp, &phba->work_list);
  1462. if (phba->work_wait)
  1463. lpfc_worker_wake_up(phba);
  1464. spin_unlock_irqrestore(&phba->hbalock, flags);
  1465. return;
  1466. }
  1467. void
  1468. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  1469. {
  1470. struct lpfc_vport *vport = ndlp->vport;
  1471. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1472. uint32_t cmd, did, retry;
  1473. spin_lock_irq(shost->host_lock);
  1474. did = ndlp->nlp_DID;
  1475. cmd = ndlp->nlp_last_elscmd;
  1476. ndlp->nlp_last_elscmd = 0;
  1477. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1478. spin_unlock_irq(shost->host_lock);
  1479. return;
  1480. }
  1481. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1482. spin_unlock_irq(shost->host_lock);
  1483. /*
  1484. * If a discovery event readded nlp_delayfunc after timer
  1485. * firing and before processing the timer, cancel the
  1486. * nlp_delayfunc.
  1487. */
  1488. del_timer_sync(&ndlp->nlp_delayfunc);
  1489. retry = ndlp->nlp_retry;
  1490. switch (cmd) {
  1491. case ELS_CMD_FLOGI:
  1492. lpfc_issue_els_flogi(vport, ndlp, retry);
  1493. break;
  1494. case ELS_CMD_PLOGI:
  1495. if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
  1496. ndlp->nlp_prev_state = ndlp->nlp_state;
  1497. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  1498. }
  1499. break;
  1500. case ELS_CMD_ADISC:
  1501. if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
  1502. ndlp->nlp_prev_state = ndlp->nlp_state;
  1503. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1504. }
  1505. break;
  1506. case ELS_CMD_PRLI:
  1507. if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
  1508. ndlp->nlp_prev_state = ndlp->nlp_state;
  1509. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1510. }
  1511. break;
  1512. case ELS_CMD_LOGO:
  1513. if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
  1514. ndlp->nlp_prev_state = ndlp->nlp_state;
  1515. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1516. }
  1517. break;
  1518. case ELS_CMD_FDISC:
  1519. lpfc_issue_els_fdisc(vport, ndlp, retry);
  1520. break;
  1521. }
  1522. return;
  1523. }
  1524. static int
  1525. lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1526. struct lpfc_iocbq *rspiocb)
  1527. {
  1528. struct lpfc_vport *vport = cmdiocb->vport;
  1529. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1530. IOCB_t *irsp = &rspiocb->iocb;
  1531. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1532. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  1533. uint32_t *elscmd;
  1534. struct ls_rjt stat;
  1535. int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
  1536. int logerr = 0;
  1537. uint32_t cmd = 0;
  1538. uint32_t did;
  1539. /* Note: context2 may be 0 for internal driver abort
  1540. * of delays ELS command.
  1541. */
  1542. if (pcmd && pcmd->virt) {
  1543. elscmd = (uint32_t *) (pcmd->virt);
  1544. cmd = *elscmd++;
  1545. }
  1546. if (ndlp)
  1547. did = ndlp->nlp_DID;
  1548. else {
  1549. /* We should only hit this case for retrying PLOGI */
  1550. did = irsp->un.elsreq64.remoteID;
  1551. ndlp = lpfc_findnode_did(vport, did);
  1552. if (!ndlp && (cmd != ELS_CMD_PLOGI))
  1553. return 1;
  1554. }
  1555. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  1556. "Retry ELS: wd7:x%x wd4:x%x did:x%x",
  1557. *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
  1558. switch (irsp->ulpStatus) {
  1559. case IOSTAT_FCP_RSP_ERROR:
  1560. case IOSTAT_REMOTE_STOP:
  1561. break;
  1562. case IOSTAT_LOCAL_REJECT:
  1563. switch ((irsp->un.ulpWord[4] & 0xff)) {
  1564. case IOERR_LOOP_OPEN_FAILURE:
  1565. if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
  1566. delay = 1000;
  1567. retry = 1;
  1568. break;
  1569. case IOERR_ILLEGAL_COMMAND:
  1570. if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
  1571. (cmd == ELS_CMD_FDISC)) {
  1572. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1573. "0124 FDISC failed (3/6) "
  1574. "retrying...\n");
  1575. lpfc_mbx_unreg_vpi(vport);
  1576. retry = 1;
  1577. /* FDISC retry policy */
  1578. maxretry = 48;
  1579. if (cmdiocb->retry >= 32)
  1580. delay = 1000;
  1581. }
  1582. break;
  1583. case IOERR_NO_RESOURCES:
  1584. logerr = 1; /* HBA out of resources */
  1585. retry = 1;
  1586. if (cmdiocb->retry > 100)
  1587. delay = 100;
  1588. maxretry = 250;
  1589. break;
  1590. case IOERR_ILLEGAL_FRAME:
  1591. delay = 100;
  1592. retry = 1;
  1593. break;
  1594. case IOERR_SEQUENCE_TIMEOUT:
  1595. case IOERR_INVALID_RPI:
  1596. retry = 1;
  1597. break;
  1598. }
  1599. break;
  1600. case IOSTAT_NPORT_RJT:
  1601. case IOSTAT_FABRIC_RJT:
  1602. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  1603. retry = 1;
  1604. break;
  1605. }
  1606. break;
  1607. case IOSTAT_NPORT_BSY:
  1608. case IOSTAT_FABRIC_BSY:
  1609. logerr = 1; /* Fabric / Remote NPort out of resources */
  1610. retry = 1;
  1611. break;
  1612. case IOSTAT_LS_RJT:
  1613. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  1614. /* Added for Vendor specifc support
  1615. * Just keep retrying for these Rsn / Exp codes
  1616. */
  1617. switch (stat.un.b.lsRjtRsnCode) {
  1618. case LSRJT_UNABLE_TPC:
  1619. if (stat.un.b.lsRjtRsnCodeExp ==
  1620. LSEXP_CMD_IN_PROGRESS) {
  1621. if (cmd == ELS_CMD_PLOGI) {
  1622. delay = 1000;
  1623. maxretry = 48;
  1624. }
  1625. retry = 1;
  1626. break;
  1627. }
  1628. if (cmd == ELS_CMD_PLOGI) {
  1629. delay = 1000;
  1630. maxretry = lpfc_max_els_tries + 1;
  1631. retry = 1;
  1632. break;
  1633. }
  1634. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1635. (cmd == ELS_CMD_FDISC) &&
  1636. (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
  1637. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1638. "0125 FDISC Failed (x%x). "
  1639. "Fabric out of resources\n",
  1640. stat.un.lsRjtError);
  1641. lpfc_vport_set_state(vport,
  1642. FC_VPORT_NO_FABRIC_RSCS);
  1643. }
  1644. break;
  1645. case LSRJT_LOGICAL_BSY:
  1646. if ((cmd == ELS_CMD_PLOGI) ||
  1647. (cmd == ELS_CMD_PRLI)) {
  1648. delay = 1000;
  1649. maxretry = 48;
  1650. } else if (cmd == ELS_CMD_FDISC) {
  1651. /* FDISC retry policy */
  1652. maxretry = 48;
  1653. if (cmdiocb->retry >= 32)
  1654. delay = 1000;
  1655. }
  1656. retry = 1;
  1657. break;
  1658. case LSRJT_LOGICAL_ERR:
  1659. case LSRJT_PROTOCOL_ERR:
  1660. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  1661. (cmd == ELS_CMD_FDISC) &&
  1662. ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
  1663. (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
  1664. ) {
  1665. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1666. "0123 FDISC Failed (x%x). "
  1667. "Fabric Detected Bad WWN\n",
  1668. stat.un.lsRjtError);
  1669. lpfc_vport_set_state(vport,
  1670. FC_VPORT_FABRIC_REJ_WWN);
  1671. }
  1672. break;
  1673. }
  1674. break;
  1675. case IOSTAT_INTERMED_RSP:
  1676. case IOSTAT_BA_RJT:
  1677. break;
  1678. default:
  1679. break;
  1680. }
  1681. if (did == FDMI_DID)
  1682. retry = 1;
  1683. if ((cmd == ELS_CMD_FLOGI) &&
  1684. (phba->fc_topology != TOPOLOGY_LOOP)) {
  1685. /* FLOGI retry policy */
  1686. retry = 1;
  1687. maxretry = 48;
  1688. if (cmdiocb->retry >= 32)
  1689. delay = 1000;
  1690. }
  1691. if ((++cmdiocb->retry) >= maxretry) {
  1692. phba->fc_stat.elsRetryExceeded++;
  1693. retry = 0;
  1694. }
  1695. if ((vport->load_flag & FC_UNLOADING) != 0)
  1696. retry = 0;
  1697. if (retry) {
  1698. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  1699. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1700. "0107 Retry ELS command x%x to remote "
  1701. "NPORT x%x Data: x%x x%x\n",
  1702. cmd, did, cmdiocb->retry, delay);
  1703. if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
  1704. ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  1705. ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
  1706. /* Don't reset timer for no resources */
  1707. /* If discovery / RSCN timer is running, reset it */
  1708. if (timer_pending(&vport->fc_disctmo) ||
  1709. (vport->fc_flag & FC_RSCN_MODE))
  1710. lpfc_set_disctmo(vport);
  1711. }
  1712. phba->fc_stat.elsXmitRetry++;
  1713. if (ndlp && delay) {
  1714. phba->fc_stat.elsDelayRetry++;
  1715. ndlp->nlp_retry = cmdiocb->retry;
  1716. /* delay is specified in milliseconds */
  1717. mod_timer(&ndlp->nlp_delayfunc,
  1718. jiffies + msecs_to_jiffies(delay));
  1719. spin_lock_irq(shost->host_lock);
  1720. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1721. spin_unlock_irq(shost->host_lock);
  1722. ndlp->nlp_prev_state = ndlp->nlp_state;
  1723. if (cmd == ELS_CMD_PRLI)
  1724. lpfc_nlp_set_state(vport, ndlp,
  1725. NLP_STE_REG_LOGIN_ISSUE);
  1726. else
  1727. lpfc_nlp_set_state(vport, ndlp,
  1728. NLP_STE_NPR_NODE);
  1729. ndlp->nlp_last_elscmd = cmd;
  1730. return 1;
  1731. }
  1732. switch (cmd) {
  1733. case ELS_CMD_FLOGI:
  1734. lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
  1735. return 1;
  1736. case ELS_CMD_FDISC:
  1737. lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
  1738. return 1;
  1739. case ELS_CMD_PLOGI:
  1740. if (ndlp) {
  1741. ndlp->nlp_prev_state = ndlp->nlp_state;
  1742. lpfc_nlp_set_state(vport, ndlp,
  1743. NLP_STE_PLOGI_ISSUE);
  1744. }
  1745. lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
  1746. return 1;
  1747. case ELS_CMD_ADISC:
  1748. ndlp->nlp_prev_state = ndlp->nlp_state;
  1749. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  1750. lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
  1751. return 1;
  1752. case ELS_CMD_PRLI:
  1753. ndlp->nlp_prev_state = ndlp->nlp_state;
  1754. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  1755. lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
  1756. return 1;
  1757. case ELS_CMD_LOGO:
  1758. ndlp->nlp_prev_state = ndlp->nlp_state;
  1759. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  1760. lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
  1761. return 1;
  1762. }
  1763. }
  1764. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  1765. if (logerr) {
  1766. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1767. "0137 No retry ELS command x%x to remote "
  1768. "NPORT x%x: Out of Resources: Error:x%x/%x\n",
  1769. cmd, did, irsp->ulpStatus,
  1770. irsp->un.ulpWord[4]);
  1771. }
  1772. else {
  1773. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1774. "0108 No retry ELS command x%x to remote "
  1775. "NPORT x%x Retried:%d Error:x%x/%x\n",
  1776. cmd, did, cmdiocb->retry, irsp->ulpStatus,
  1777. irsp->un.ulpWord[4]);
  1778. }
  1779. return 0;
  1780. }
  1781. int
  1782. lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
  1783. {
  1784. struct lpfc_dmabuf *buf_ptr;
  1785. /* Free the response before processing the command. */
  1786. if (!list_empty(&buf_ptr1->list)) {
  1787. list_remove_head(&buf_ptr1->list, buf_ptr,
  1788. struct lpfc_dmabuf,
  1789. list);
  1790. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1791. kfree(buf_ptr);
  1792. }
  1793. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  1794. kfree(buf_ptr1);
  1795. return 0;
  1796. }
  1797. int
  1798. lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
  1799. {
  1800. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1801. kfree(buf_ptr);
  1802. return 0;
  1803. }
  1804. int
  1805. lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
  1806. {
  1807. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  1808. struct lpfc_nodelist *ndlp;
  1809. ndlp = (struct lpfc_nodelist *)elsiocb->context1;
  1810. if (ndlp) {
  1811. if (ndlp->nlp_flag & NLP_DEFER_RM) {
  1812. lpfc_nlp_put(ndlp);
  1813. /* If the ndlp is not being used by another discovery
  1814. * thread, free it.
  1815. */
  1816. if (!lpfc_nlp_not_used(ndlp)) {
  1817. /* If ndlp is being used by another discovery
  1818. * thread, just clear NLP_DEFER_RM
  1819. */
  1820. ndlp->nlp_flag &= ~NLP_DEFER_RM;
  1821. }
  1822. }
  1823. else
  1824. lpfc_nlp_put(ndlp);
  1825. elsiocb->context1 = NULL;
  1826. }
  1827. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  1828. if (elsiocb->context2) {
  1829. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  1830. lpfc_els_free_data(phba, buf_ptr1);
  1831. }
  1832. if (elsiocb->context3) {
  1833. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  1834. lpfc_els_free_bpl(phba, buf_ptr);
  1835. }
  1836. lpfc_sli_release_iocbq(phba, elsiocb);
  1837. return 0;
  1838. }
  1839. static void
  1840. lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1841. struct lpfc_iocbq *rspiocb)
  1842. {
  1843. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1844. struct lpfc_vport *vport = cmdiocb->vport;
  1845. IOCB_t *irsp;
  1846. irsp = &rspiocb->iocb;
  1847. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  1848. "ACC LOGO cmpl: status:x%x/x%x did:x%x",
  1849. irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
  1850. /* ACC to LOGO completes to NPort <nlp_DID> */
  1851. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1852. "0109 ACC to LOGO completes to NPort x%x "
  1853. "Data: x%x x%x x%x\n",
  1854. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  1855. ndlp->nlp_rpi);
  1856. if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
  1857. /* NPort Recovery mode or node is just allocated */
  1858. if (!lpfc_nlp_not_used(ndlp)) {
  1859. /* If the ndlp is being used by another discovery
  1860. * thread, just unregister the RPI.
  1861. */
  1862. lpfc_unreg_rpi(vport, ndlp);
  1863. }
  1864. }
  1865. lpfc_els_free_iocb(phba, cmdiocb);
  1866. return;
  1867. }
  1868. void
  1869. lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1870. {
  1871. struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
  1872. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  1873. pmb->context1 = NULL;
  1874. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1875. kfree(mp);
  1876. mempool_free(pmb, phba->mbox_mem_pool);
  1877. if (ndlp) {
  1878. lpfc_nlp_put(ndlp);
  1879. /* This is the end of the default RPI cleanup logic for this
  1880. * ndlp. If no other discovery threads are using this ndlp.
  1881. * we should free all resources associated with it.
  1882. */
  1883. lpfc_nlp_not_used(ndlp);
  1884. }
  1885. return;
  1886. }
  1887. static void
  1888. lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1889. struct lpfc_iocbq *rspiocb)
  1890. {
  1891. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1892. struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
  1893. struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
  1894. IOCB_t *irsp;
  1895. uint8_t *pcmd;
  1896. LPFC_MBOXQ_t *mbox = NULL;
  1897. struct lpfc_dmabuf *mp = NULL;
  1898. uint32_t ls_rjt = 0;
  1899. irsp = &rspiocb->iocb;
  1900. if (cmdiocb->context_un.mbox)
  1901. mbox = cmdiocb->context_un.mbox;
  1902. /* First determine if this is a LS_RJT cmpl */
  1903. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
  1904. if (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT) {
  1905. /* A LS_RJT associated with Default RPI cleanup
  1906. * has its own seperate code path.
  1907. */
  1908. if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  1909. ls_rjt = 1;
  1910. }
  1911. /* Check to see if link went down during discovery */
  1912. if (!ndlp || lpfc_els_chk_latt(vport)) {
  1913. if (mbox) {
  1914. mp = (struct lpfc_dmabuf *) mbox->context1;
  1915. if (mp) {
  1916. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1917. kfree(mp);
  1918. }
  1919. mempool_free(mbox, phba->mbox_mem_pool);
  1920. }
  1921. if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
  1922. if (lpfc_nlp_not_used(ndlp))
  1923. ndlp = NULL;
  1924. goto out;
  1925. }
  1926. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  1927. "ELS rsp cmpl: status:x%x/x%x did:x%x",
  1928. irsp->ulpStatus, irsp->un.ulpWord[4],
  1929. cmdiocb->iocb.un.elsreq64.remoteID);
  1930. /* ELS response tag <ulpIoTag> completes */
  1931. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  1932. "0110 ELS response tag x%x completes "
  1933. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  1934. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  1935. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  1936. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  1937. ndlp->nlp_rpi);
  1938. if (mbox) {
  1939. if ((rspiocb->iocb.ulpStatus == 0)
  1940. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  1941. lpfc_unreg_rpi(vport, ndlp);
  1942. mbox->context2 = lpfc_nlp_get(ndlp);
  1943. mbox->vport = vport;
  1944. if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
  1945. mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
  1946. mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  1947. }
  1948. else {
  1949. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  1950. ndlp->nlp_prev_state = ndlp->nlp_state;
  1951. lpfc_nlp_set_state(vport, ndlp,
  1952. NLP_STE_REG_LOGIN_ISSUE);
  1953. }
  1954. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  1955. != MBX_NOT_FINISHED) {
  1956. goto out;
  1957. }
  1958. /* ELS rsp: Cannot issue reg_login for <NPortid> */
  1959. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  1960. "0138 ELS rsp: Cannot issue reg_login for x%x "
  1961. "Data: x%x x%x x%x\n",
  1962. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  1963. ndlp->nlp_rpi);
  1964. if (lpfc_nlp_not_used(ndlp))
  1965. ndlp = NULL;
  1966. } else {
  1967. /* Do not drop node for lpfc_els_abort'ed ELS cmds */
  1968. if (!lpfc_error_lost_link(irsp) &&
  1969. ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  1970. if (lpfc_nlp_not_used(ndlp))
  1971. ndlp = NULL;
  1972. }
  1973. }
  1974. mp = (struct lpfc_dmabuf *) mbox->context1;
  1975. if (mp) {
  1976. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1977. kfree(mp);
  1978. }
  1979. mempool_free(mbox, phba->mbox_mem_pool);
  1980. }
  1981. out:
  1982. if (ndlp) {
  1983. spin_lock_irq(shost->host_lock);
  1984. ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
  1985. spin_unlock_irq(shost->host_lock);
  1986. /* If the node is not being used by another discovery thread,
  1987. * and we are sending a reject, we are done with it.
  1988. * Release driver reference count here and free associated
  1989. * resources.
  1990. */
  1991. if (ls_rjt)
  1992. lpfc_nlp_not_used(ndlp);
  1993. }
  1994. lpfc_els_free_iocb(phba, cmdiocb);
  1995. return;
  1996. }
  1997. int
  1998. lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
  1999. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2000. LPFC_MBOXQ_t *mbox)
  2001. {
  2002. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2003. struct lpfc_hba *phba = vport->phba;
  2004. IOCB_t *icmd;
  2005. IOCB_t *oldcmd;
  2006. struct lpfc_iocbq *elsiocb;
  2007. struct lpfc_sli_ring *pring;
  2008. struct lpfc_sli *psli;
  2009. uint8_t *pcmd;
  2010. uint16_t cmdsize;
  2011. int rc;
  2012. ELS_PKT *els_pkt_ptr;
  2013. psli = &phba->sli;
  2014. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2015. oldcmd = &oldiocb->iocb;
  2016. switch (flag) {
  2017. case ELS_CMD_ACC:
  2018. cmdsize = sizeof(uint32_t);
  2019. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2020. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2021. if (!elsiocb) {
  2022. spin_lock_irq(shost->host_lock);
  2023. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2024. spin_unlock_irq(shost->host_lock);
  2025. return 1;
  2026. }
  2027. icmd = &elsiocb->iocb;
  2028. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2029. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2030. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2031. pcmd += sizeof(uint32_t);
  2032. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2033. "Issue ACC: did:x%x flg:x%x",
  2034. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2035. break;
  2036. case ELS_CMD_PLOGI:
  2037. cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
  2038. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2039. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2040. if (!elsiocb)
  2041. return 1;
  2042. icmd = &elsiocb->iocb;
  2043. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2044. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2045. if (mbox)
  2046. elsiocb->context_un.mbox = mbox;
  2047. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2048. pcmd += sizeof(uint32_t);
  2049. memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
  2050. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2051. "Issue ACC PLOGI: did:x%x flg:x%x",
  2052. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2053. break;
  2054. case ELS_CMD_PRLO:
  2055. cmdsize = sizeof(uint32_t) + sizeof(PRLO);
  2056. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
  2057. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  2058. if (!elsiocb)
  2059. return 1;
  2060. icmd = &elsiocb->iocb;
  2061. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2062. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2063. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  2064. sizeof(uint32_t) + sizeof(PRLO));
  2065. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  2066. els_pkt_ptr = (ELS_PKT *) pcmd;
  2067. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  2068. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2069. "Issue ACC PRLO: did:x%x flg:x%x",
  2070. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2071. break;
  2072. default:
  2073. return 1;
  2074. }
  2075. /* Xmit ELS ACC response tag <ulpIoTag> */
  2076. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2077. "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  2078. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
  2079. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2080. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2081. ndlp->nlp_rpi);
  2082. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  2083. spin_lock_irq(shost->host_lock);
  2084. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2085. spin_unlock_irq(shost->host_lock);
  2086. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  2087. } else {
  2088. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2089. }
  2090. phba->fc_stat.elsXmitACC++;
  2091. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2092. if (rc == IOCB_ERROR) {
  2093. lpfc_els_free_iocb(phba, elsiocb);
  2094. return 1;
  2095. }
  2096. return 0;
  2097. }
  2098. int
  2099. lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
  2100. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
  2101. LPFC_MBOXQ_t *mbox)
  2102. {
  2103. struct lpfc_hba *phba = vport->phba;
  2104. IOCB_t *icmd;
  2105. IOCB_t *oldcmd;
  2106. struct lpfc_iocbq *elsiocb;
  2107. struct lpfc_sli_ring *pring;
  2108. struct lpfc_sli *psli;
  2109. uint8_t *pcmd;
  2110. uint16_t cmdsize;
  2111. int rc;
  2112. psli = &phba->sli;
  2113. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2114. cmdsize = 2 * sizeof(uint32_t);
  2115. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2116. ndlp->nlp_DID, ELS_CMD_LS_RJT);
  2117. if (!elsiocb)
  2118. return 1;
  2119. icmd = &elsiocb->iocb;
  2120. oldcmd = &oldiocb->iocb;
  2121. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2122. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2123. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  2124. pcmd += sizeof(uint32_t);
  2125. *((uint32_t *) (pcmd)) = rejectError;
  2126. if (mbox)
  2127. elsiocb->context_un.mbox = mbox;
  2128. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  2129. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2130. "0129 Xmit ELS RJT x%x response tag x%x "
  2131. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  2132. "rpi x%x\n",
  2133. rejectError, elsiocb->iotag,
  2134. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  2135. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  2136. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2137. "Issue LS_RJT: did:x%x flg:x%x err:x%x",
  2138. ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
  2139. phba->fc_stat.elsXmitLSRJT++;
  2140. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2141. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2142. if (rc == IOCB_ERROR) {
  2143. lpfc_els_free_iocb(phba, elsiocb);
  2144. return 1;
  2145. }
  2146. return 0;
  2147. }
  2148. int
  2149. lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2150. struct lpfc_nodelist *ndlp)
  2151. {
  2152. struct lpfc_hba *phba = vport->phba;
  2153. struct lpfc_sli *psli = &phba->sli;
  2154. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2155. ADISC *ap;
  2156. IOCB_t *icmd, *oldcmd;
  2157. struct lpfc_iocbq *elsiocb;
  2158. uint8_t *pcmd;
  2159. uint16_t cmdsize;
  2160. int rc;
  2161. cmdsize = sizeof(uint32_t) + sizeof(ADISC);
  2162. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2163. ndlp->nlp_DID, ELS_CMD_ACC);
  2164. if (!elsiocb)
  2165. return 1;
  2166. icmd = &elsiocb->iocb;
  2167. oldcmd = &oldiocb->iocb;
  2168. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2169. /* Xmit ADISC ACC response tag <ulpIoTag> */
  2170. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2171. "0130 Xmit ADISC ACC response iotag x%x xri: "
  2172. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  2173. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2174. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2175. ndlp->nlp_rpi);
  2176. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2177. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2178. pcmd += sizeof(uint32_t);
  2179. ap = (ADISC *) (pcmd);
  2180. ap->hardAL_PA = phba->fc_pref_ALPA;
  2181. memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2182. memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2183. ap->DID = be32_to_cpu(vport->fc_myDID);
  2184. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2185. "Issue ACC ADISC: did:x%x flg:x%x",
  2186. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2187. phba->fc_stat.elsXmitACC++;
  2188. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2189. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2190. if (rc == IOCB_ERROR) {
  2191. lpfc_els_free_iocb(phba, elsiocb);
  2192. return 1;
  2193. }
  2194. return 0;
  2195. }
  2196. int
  2197. lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
  2198. struct lpfc_nodelist *ndlp)
  2199. {
  2200. struct lpfc_hba *phba = vport->phba;
  2201. PRLI *npr;
  2202. lpfc_vpd_t *vpd;
  2203. IOCB_t *icmd;
  2204. IOCB_t *oldcmd;
  2205. struct lpfc_iocbq *elsiocb;
  2206. struct lpfc_sli_ring *pring;
  2207. struct lpfc_sli *psli;
  2208. uint8_t *pcmd;
  2209. uint16_t cmdsize;
  2210. int rc;
  2211. psli = &phba->sli;
  2212. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2213. cmdsize = sizeof(uint32_t) + sizeof(PRLI);
  2214. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2215. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  2216. if (!elsiocb)
  2217. return 1;
  2218. icmd = &elsiocb->iocb;
  2219. oldcmd = &oldiocb->iocb;
  2220. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2221. /* Xmit PRLI ACC response tag <ulpIoTag> */
  2222. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2223. "0131 Xmit PRLI ACC response tag x%x xri x%x, "
  2224. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2225. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2226. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2227. ndlp->nlp_rpi);
  2228. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2229. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  2230. pcmd += sizeof(uint32_t);
  2231. /* For PRLI, remainder of payload is PRLI parameter page */
  2232. memset(pcmd, 0, sizeof(PRLI));
  2233. npr = (PRLI *) pcmd;
  2234. vpd = &phba->vpd;
  2235. /*
  2236. * If our firmware version is 3.20 or later,
  2237. * set the following bits for FC-TAPE support.
  2238. */
  2239. if (vpd->rev.feaLevelHigh >= 0x02) {
  2240. npr->ConfmComplAllowed = 1;
  2241. npr->Retry = 1;
  2242. npr->TaskRetryIdReq = 1;
  2243. }
  2244. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  2245. npr->estabImagePair = 1;
  2246. npr->readXferRdyDis = 1;
  2247. npr->ConfmComplAllowed = 1;
  2248. npr->prliType = PRLI_FCP_TYPE;
  2249. npr->initiatorFunc = 1;
  2250. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2251. "Issue ACC PRLI: did:x%x flg:x%x",
  2252. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2253. phba->fc_stat.elsXmitACC++;
  2254. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2255. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2256. if (rc == IOCB_ERROR) {
  2257. lpfc_els_free_iocb(phba, elsiocb);
  2258. return 1;
  2259. }
  2260. return 0;
  2261. }
  2262. static int
  2263. lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
  2264. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  2265. {
  2266. struct lpfc_hba *phba = vport->phba;
  2267. RNID *rn;
  2268. IOCB_t *icmd, *oldcmd;
  2269. struct lpfc_iocbq *elsiocb;
  2270. struct lpfc_sli_ring *pring;
  2271. struct lpfc_sli *psli;
  2272. uint8_t *pcmd;
  2273. uint16_t cmdsize;
  2274. int rc;
  2275. psli = &phba->sli;
  2276. pring = &psli->ring[LPFC_ELS_RING];
  2277. cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
  2278. + (2 * sizeof(struct lpfc_name));
  2279. if (format)
  2280. cmdsize += sizeof(RNID_TOP_DISC);
  2281. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2282. ndlp->nlp_DID, ELS_CMD_ACC);
  2283. if (!elsiocb)
  2284. return 1;
  2285. icmd = &elsiocb->iocb;
  2286. oldcmd = &oldiocb->iocb;
  2287. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2288. /* Xmit RNID ACC response tag <ulpIoTag> */
  2289. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2290. "0132 Xmit RNID ACC response tag x%x xri x%x\n",
  2291. elsiocb->iotag, elsiocb->iocb.ulpContext);
  2292. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2293. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2294. pcmd += sizeof(uint32_t);
  2295. memset(pcmd, 0, sizeof(RNID));
  2296. rn = (RNID *) (pcmd);
  2297. rn->Format = format;
  2298. rn->CommonLen = (2 * sizeof(struct lpfc_name));
  2299. memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
  2300. memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
  2301. switch (format) {
  2302. case 0:
  2303. rn->SpecificLen = 0;
  2304. break;
  2305. case RNID_TOPOLOGY_DISC:
  2306. rn->SpecificLen = sizeof(RNID_TOP_DISC);
  2307. memcpy(&rn->un.topologyDisc.portName,
  2308. &vport->fc_portname, sizeof(struct lpfc_name));
  2309. rn->un.topologyDisc.unitType = RNID_HBA;
  2310. rn->un.topologyDisc.physPort = 0;
  2311. rn->un.topologyDisc.attachedNodes = 0;
  2312. break;
  2313. default:
  2314. rn->CommonLen = 0;
  2315. rn->SpecificLen = 0;
  2316. break;
  2317. }
  2318. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
  2319. "Issue ACC RNID: did:x%x flg:x%x",
  2320. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  2321. phba->fc_stat.elsXmitACC++;
  2322. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2323. lpfc_nlp_put(ndlp);
  2324. elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
  2325. * it could be freed */
  2326. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  2327. if (rc == IOCB_ERROR) {
  2328. lpfc_els_free_iocb(phba, elsiocb);
  2329. return 1;
  2330. }
  2331. return 0;
  2332. }
  2333. int
  2334. lpfc_els_disc_adisc(struct lpfc_vport *vport)
  2335. {
  2336. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2337. struct lpfc_nodelist *ndlp, *next_ndlp;
  2338. int sentadisc = 0;
  2339. /* go thru NPR nodes and issue any remaining ELS ADISCs */
  2340. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2341. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2342. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2343. (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
  2344. spin_lock_irq(shost->host_lock);
  2345. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  2346. spin_unlock_irq(shost->host_lock);
  2347. ndlp->nlp_prev_state = ndlp->nlp_state;
  2348. lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
  2349. lpfc_issue_els_adisc(vport, ndlp, 0);
  2350. sentadisc++;
  2351. vport->num_disc_nodes++;
  2352. if (vport->num_disc_nodes >=
  2353. vport->cfg_discovery_threads) {
  2354. spin_lock_irq(shost->host_lock);
  2355. vport->fc_flag |= FC_NLP_MORE;
  2356. spin_unlock_irq(shost->host_lock);
  2357. break;
  2358. }
  2359. }
  2360. }
  2361. if (sentadisc == 0) {
  2362. spin_lock_irq(shost->host_lock);
  2363. vport->fc_flag &= ~FC_NLP_MORE;
  2364. spin_unlock_irq(shost->host_lock);
  2365. }
  2366. return sentadisc;
  2367. }
  2368. int
  2369. lpfc_els_disc_plogi(struct lpfc_vport *vport)
  2370. {
  2371. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2372. struct lpfc_nodelist *ndlp, *next_ndlp;
  2373. int sentplogi = 0;
  2374. /* go thru NPR nodes and issue any remaining ELS PLOGIs */
  2375. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  2376. if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
  2377. (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
  2378. (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
  2379. (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
  2380. ndlp->nlp_prev_state = ndlp->nlp_state;
  2381. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2382. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2383. sentplogi++;
  2384. vport->num_disc_nodes++;
  2385. if (vport->num_disc_nodes >=
  2386. vport->cfg_discovery_threads) {
  2387. spin_lock_irq(shost->host_lock);
  2388. vport->fc_flag |= FC_NLP_MORE;
  2389. spin_unlock_irq(shost->host_lock);
  2390. break;
  2391. }
  2392. }
  2393. }
  2394. if (sentplogi) {
  2395. lpfc_set_disctmo(vport);
  2396. }
  2397. else {
  2398. spin_lock_irq(shost->host_lock);
  2399. vport->fc_flag &= ~FC_NLP_MORE;
  2400. spin_unlock_irq(shost->host_lock);
  2401. }
  2402. return sentplogi;
  2403. }
  2404. void
  2405. lpfc_els_flush_rscn(struct lpfc_vport *vport)
  2406. {
  2407. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2408. struct lpfc_hba *phba = vport->phba;
  2409. int i;
  2410. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2411. lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
  2412. vport->fc_rscn_id_list[i] = NULL;
  2413. }
  2414. spin_lock_irq(shost->host_lock);
  2415. vport->fc_rscn_id_cnt = 0;
  2416. vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  2417. spin_unlock_irq(shost->host_lock);
  2418. lpfc_can_disctmo(vport);
  2419. }
  2420. int
  2421. lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
  2422. {
  2423. D_ID ns_did;
  2424. D_ID rscn_did;
  2425. uint32_t *lp;
  2426. uint32_t payload_len, i;
  2427. ns_did.un.word = did;
  2428. /* Never match fabric nodes for RSCNs */
  2429. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  2430. return 0;
  2431. /* If we are doing a FULL RSCN rediscovery, match everything */
  2432. if (vport->fc_flag & FC_RSCN_DISCOVERY)
  2433. return did;
  2434. for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
  2435. lp = vport->fc_rscn_id_list[i]->virt;
  2436. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2437. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2438. while (payload_len) {
  2439. rscn_did.un.word = be32_to_cpu(*lp++);
  2440. payload_len -= sizeof(uint32_t);
  2441. switch (rscn_did.un.b.resv) {
  2442. case 0: /* Single N_Port ID effected */
  2443. if (ns_did.un.word == rscn_did.un.word)
  2444. return did;
  2445. break;
  2446. case 1: /* Whole N_Port Area effected */
  2447. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  2448. && (ns_did.un.b.area == rscn_did.un.b.area))
  2449. return did;
  2450. break;
  2451. case 2: /* Whole N_Port Domain effected */
  2452. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  2453. return did;
  2454. break;
  2455. default:
  2456. /* Unknown Identifier in RSCN node */
  2457. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  2458. "0217 Unknown Identifier in "
  2459. "RSCN payload Data: x%x\n",
  2460. rscn_did.un.word);
  2461. case 3: /* Whole Fabric effected */
  2462. return did;
  2463. }
  2464. }
  2465. }
  2466. return 0;
  2467. }
  2468. static int
  2469. lpfc_rscn_recovery_check(struct lpfc_vport *vport)
  2470. {
  2471. struct lpfc_nodelist *ndlp = NULL;
  2472. /* Look at all nodes effected by pending RSCNs and move
  2473. * them to NPR state.
  2474. */
  2475. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2476. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
  2477. lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
  2478. continue;
  2479. lpfc_disc_state_machine(vport, ndlp, NULL,
  2480. NLP_EVT_DEVICE_RECOVERY);
  2481. /*
  2482. * Make sure NLP_DELAY_TMO is NOT running after a device
  2483. * recovery event.
  2484. */
  2485. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  2486. lpfc_cancel_retry_delay_tmo(vport, ndlp);
  2487. }
  2488. return 0;
  2489. }
  2490. static int
  2491. lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2492. struct lpfc_nodelist *ndlp)
  2493. {
  2494. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2495. struct lpfc_hba *phba = vport->phba;
  2496. struct lpfc_dmabuf *pcmd;
  2497. uint32_t *lp, *datap;
  2498. IOCB_t *icmd;
  2499. uint32_t payload_len, length, nportid, *cmd;
  2500. int rscn_cnt = vport->fc_rscn_id_cnt;
  2501. int rscn_id = 0, hba_id = 0;
  2502. int i;
  2503. icmd = &cmdiocb->iocb;
  2504. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2505. lp = (uint32_t *) pcmd->virt;
  2506. payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
  2507. payload_len -= sizeof(uint32_t); /* take off word 0 */
  2508. /* RSCN received */
  2509. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2510. "0214 RSCN received Data: x%x x%x x%x x%x\n",
  2511. vport->fc_flag, payload_len, *lp, rscn_cnt);
  2512. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  2513. fc_host_post_event(shost, fc_get_event_number(),
  2514. FCH_EVT_RSCN, lp[i]);
  2515. /* If we are about to begin discovery, just ACC the RSCN.
  2516. * Discovery processing will satisfy it.
  2517. */
  2518. if (vport->port_state <= LPFC_NS_QRY) {
  2519. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2520. "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
  2521. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2522. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2523. return 0;
  2524. }
  2525. /* If this RSCN just contains NPortIDs for other vports on this HBA,
  2526. * just ACC and ignore it.
  2527. */
  2528. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  2529. !(vport->cfg_peer_port_login)) {
  2530. i = payload_len;
  2531. datap = lp;
  2532. while (i > 0) {
  2533. nportid = *datap++;
  2534. nportid = ((be32_to_cpu(nportid)) & Mask_DID);
  2535. i -= sizeof(uint32_t);
  2536. rscn_id++;
  2537. if (lpfc_find_vport_by_did(phba, nportid))
  2538. hba_id++;
  2539. }
  2540. if (rscn_id == hba_id) {
  2541. /* ALL NPortIDs in RSCN are on HBA */
  2542. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2543. "0214 Ignore RSCN "
  2544. "Data: x%x x%x x%x x%x\n",
  2545. vport->fc_flag, payload_len,
  2546. *lp, rscn_cnt);
  2547. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2548. "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
  2549. ndlp->nlp_DID, vport->port_state,
  2550. ndlp->nlp_flag);
  2551. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
  2552. ndlp, NULL);
  2553. return 0;
  2554. }
  2555. }
  2556. /* If we are already processing an RSCN, save the received
  2557. * RSCN payload buffer, cmdiocb->context2 to process later.
  2558. */
  2559. if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  2560. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2561. "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
  2562. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2563. vport->fc_flag |= FC_RSCN_DEFERRED;
  2564. if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
  2565. !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
  2566. spin_lock_irq(shost->host_lock);
  2567. vport->fc_flag |= FC_RSCN_MODE;
  2568. spin_unlock_irq(shost->host_lock);
  2569. if (rscn_cnt) {
  2570. cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
  2571. length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
  2572. }
  2573. if ((rscn_cnt) &&
  2574. (payload_len + length <= LPFC_BPL_SIZE)) {
  2575. *cmd &= ELS_CMD_MASK;
  2576. *cmd |= be32_to_cpu(payload_len + length);
  2577. memcpy(((uint8_t *)cmd) + length, lp,
  2578. payload_len);
  2579. } else {
  2580. vport->fc_rscn_id_list[rscn_cnt] = pcmd;
  2581. vport->fc_rscn_id_cnt++;
  2582. /* If we zero, cmdiocb->context2, the calling
  2583. * routine will not try to free it.
  2584. */
  2585. cmdiocb->context2 = NULL;
  2586. }
  2587. /* Deferred RSCN */
  2588. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2589. "0235 Deferred RSCN "
  2590. "Data: x%x x%x x%x\n",
  2591. vport->fc_rscn_id_cnt, vport->fc_flag,
  2592. vport->port_state);
  2593. } else {
  2594. spin_lock_irq(shost->host_lock);
  2595. vport->fc_flag |= FC_RSCN_DISCOVERY;
  2596. spin_unlock_irq(shost->host_lock);
  2597. /* ReDiscovery RSCN */
  2598. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2599. "0234 ReDiscovery RSCN "
  2600. "Data: x%x x%x x%x\n",
  2601. vport->fc_rscn_id_cnt, vport->fc_flag,
  2602. vport->port_state);
  2603. }
  2604. /* Send back ACC */
  2605. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2606. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2607. lpfc_rscn_recovery_check(vport);
  2608. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  2609. return 0;
  2610. }
  2611. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  2612. "RCV RSCN: did:x%x/ste:x%x flg:x%x",
  2613. ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
  2614. spin_lock_irq(shost->host_lock);
  2615. vport->fc_flag |= FC_RSCN_MODE;
  2616. spin_unlock_irq(shost->host_lock);
  2617. vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
  2618. /*
  2619. * If we zero, cmdiocb->context2, the calling routine will
  2620. * not try to free it.
  2621. */
  2622. cmdiocb->context2 = NULL;
  2623. lpfc_set_disctmo(vport);
  2624. /* Send back ACC */
  2625. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  2626. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2627. lpfc_rscn_recovery_check(vport);
  2628. return lpfc_els_handle_rscn(vport);
  2629. }
  2630. int
  2631. lpfc_els_handle_rscn(struct lpfc_vport *vport)
  2632. {
  2633. struct lpfc_nodelist *ndlp;
  2634. struct lpfc_hba *phba = vport->phba;
  2635. /* Ignore RSCN if the port is being torn down. */
  2636. if (vport->load_flag & FC_UNLOADING) {
  2637. lpfc_els_flush_rscn(vport);
  2638. return 0;
  2639. }
  2640. /* Start timer for RSCN processing */
  2641. lpfc_set_disctmo(vport);
  2642. /* RSCN processed */
  2643. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2644. "0215 RSCN processed Data: x%x x%x x%x x%x\n",
  2645. vport->fc_flag, 0, vport->fc_rscn_id_cnt,
  2646. vport->port_state);
  2647. /* To process RSCN, first compare RSCN data with NameServer */
  2648. vport->fc_ns_retry = 0;
  2649. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2650. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  2651. /* Good ndlp, issue CT Request to NameServer */
  2652. if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
  2653. /* Wait for NameServer query cmpl before we can
  2654. continue */
  2655. return 1;
  2656. } else {
  2657. /* If login to NameServer does not exist, issue one */
  2658. /* Good status, issue PLOGI to NameServer */
  2659. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  2660. if (ndlp)
  2661. /* Wait for NameServer login cmpl before we can
  2662. continue */
  2663. return 1;
  2664. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2665. if (!ndlp) {
  2666. lpfc_els_flush_rscn(vport);
  2667. return 0;
  2668. } else {
  2669. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  2670. ndlp->nlp_type |= NLP_FABRIC;
  2671. ndlp->nlp_prev_state = ndlp->nlp_state;
  2672. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  2673. lpfc_issue_els_plogi(vport, NameServer_DID, 0);
  2674. /* Wait for NameServer login cmpl before we can
  2675. continue */
  2676. return 1;
  2677. }
  2678. }
  2679. lpfc_els_flush_rscn(vport);
  2680. return 0;
  2681. }
  2682. static int
  2683. lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2684. struct lpfc_nodelist *ndlp)
  2685. {
  2686. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2687. struct lpfc_hba *phba = vport->phba;
  2688. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2689. uint32_t *lp = (uint32_t *) pcmd->virt;
  2690. IOCB_t *icmd = &cmdiocb->iocb;
  2691. struct serv_parm *sp;
  2692. LPFC_MBOXQ_t *mbox;
  2693. struct ls_rjt stat;
  2694. uint32_t cmd, did;
  2695. int rc;
  2696. cmd = *lp++;
  2697. sp = (struct serv_parm *) lp;
  2698. /* FLOGI received */
  2699. lpfc_set_disctmo(vport);
  2700. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2701. /* We should never receive a FLOGI in loop mode, ignore it */
  2702. did = icmd->un.elsreq64.remoteID;
  2703. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  2704. Loop Mode */
  2705. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  2706. "0113 An FLOGI ELS command x%x was "
  2707. "received from DID x%x in Loop Mode\n",
  2708. cmd, did);
  2709. return 1;
  2710. }
  2711. did = Fabric_DID;
  2712. if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
  2713. /* For a FLOGI we accept, then if our portname is greater
  2714. * then the remote portname we initiate Nport login.
  2715. */
  2716. rc = memcmp(&vport->fc_portname, &sp->portName,
  2717. sizeof(struct lpfc_name));
  2718. if (!rc) {
  2719. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2720. if (!mbox)
  2721. return 1;
  2722. lpfc_linkdown(phba);
  2723. lpfc_init_link(phba, mbox,
  2724. phba->cfg_topology,
  2725. phba->cfg_link_speed);
  2726. mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2727. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2728. mbox->vport = vport;
  2729. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2730. lpfc_set_loopback_flag(phba);
  2731. if (rc == MBX_NOT_FINISHED) {
  2732. mempool_free(mbox, phba->mbox_mem_pool);
  2733. }
  2734. return 1;
  2735. } else if (rc > 0) { /* greater than */
  2736. spin_lock_irq(shost->host_lock);
  2737. vport->fc_flag |= FC_PT2PT_PLOGI;
  2738. spin_unlock_irq(shost->host_lock);
  2739. }
  2740. spin_lock_irq(shost->host_lock);
  2741. vport->fc_flag |= FC_PT2PT;
  2742. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2743. spin_unlock_irq(shost->host_lock);
  2744. } else {
  2745. /* Reject this request because invalid parameters */
  2746. stat.un.b.lsRjtRsvd0 = 0;
  2747. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2748. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  2749. stat.un.b.vendorUnique = 0;
  2750. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2751. NULL);
  2752. return 1;
  2753. }
  2754. /* Send back ACC */
  2755. lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
  2756. return 0;
  2757. }
  2758. static int
  2759. lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2760. struct lpfc_nodelist *ndlp)
  2761. {
  2762. struct lpfc_dmabuf *pcmd;
  2763. uint32_t *lp;
  2764. IOCB_t *icmd;
  2765. RNID *rn;
  2766. struct ls_rjt stat;
  2767. uint32_t cmd, did;
  2768. icmd = &cmdiocb->iocb;
  2769. did = icmd->un.elsreq64.remoteID;
  2770. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2771. lp = (uint32_t *) pcmd->virt;
  2772. cmd = *lp++;
  2773. rn = (RNID *) lp;
  2774. /* RNID received */
  2775. switch (rn->Format) {
  2776. case 0:
  2777. case RNID_TOPOLOGY_DISC:
  2778. /* Send back ACC */
  2779. lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
  2780. break;
  2781. default:
  2782. /* Reject this request because format not supported */
  2783. stat.un.b.lsRjtRsvd0 = 0;
  2784. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2785. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2786. stat.un.b.vendorUnique = 0;
  2787. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2788. NULL);
  2789. }
  2790. return 0;
  2791. }
  2792. static int
  2793. lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2794. struct lpfc_nodelist *ndlp)
  2795. {
  2796. struct ls_rjt stat;
  2797. /* For now, unconditionally reject this command */
  2798. stat.un.b.lsRjtRsvd0 = 0;
  2799. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2800. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2801. stat.un.b.vendorUnique = 0;
  2802. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  2803. return 0;
  2804. }
  2805. static void
  2806. lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2807. {
  2808. struct lpfc_sli *psli = &phba->sli;
  2809. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2810. MAILBOX_t *mb;
  2811. IOCB_t *icmd;
  2812. RPS_RSP *rps_rsp;
  2813. uint8_t *pcmd;
  2814. struct lpfc_iocbq *elsiocb;
  2815. struct lpfc_nodelist *ndlp;
  2816. uint16_t xri, status;
  2817. uint32_t cmdsize;
  2818. mb = &pmb->mb;
  2819. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2820. xri = (uint16_t) ((unsigned long)(pmb->context1));
  2821. pmb->context1 = NULL;
  2822. pmb->context2 = NULL;
  2823. if (mb->mbxStatus) {
  2824. mempool_free(pmb, phba->mbox_mem_pool);
  2825. return;
  2826. }
  2827. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  2828. mempool_free(pmb, phba->mbox_mem_pool);
  2829. elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
  2830. lpfc_max_els_tries, ndlp,
  2831. ndlp->nlp_DID, ELS_CMD_ACC);
  2832. lpfc_nlp_put(ndlp);
  2833. if (!elsiocb)
  2834. return;
  2835. icmd = &elsiocb->iocb;
  2836. icmd->ulpContext = xri;
  2837. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2838. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2839. pcmd += sizeof(uint32_t); /* Skip past command */
  2840. rps_rsp = (RPS_RSP *)pcmd;
  2841. if (phba->fc_topology != TOPOLOGY_LOOP)
  2842. status = 0x10;
  2843. else
  2844. status = 0x8;
  2845. if (phba->pport->fc_flag & FC_FABRIC)
  2846. status |= 0x4;
  2847. rps_rsp->rsvd1 = 0;
  2848. rps_rsp->portStatus = be16_to_cpu(status);
  2849. rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
  2850. rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
  2851. rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
  2852. rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
  2853. rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
  2854. rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
  2855. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  2856. lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
  2857. "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  2858. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2859. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2860. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2861. ndlp->nlp_rpi);
  2862. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2863. phba->fc_stat.elsXmitACC++;
  2864. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
  2865. lpfc_els_free_iocb(phba, elsiocb);
  2866. return;
  2867. }
  2868. static int
  2869. lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2870. struct lpfc_nodelist *ndlp)
  2871. {
  2872. struct lpfc_hba *phba = vport->phba;
  2873. uint32_t *lp;
  2874. uint8_t flag;
  2875. LPFC_MBOXQ_t *mbox;
  2876. struct lpfc_dmabuf *pcmd;
  2877. RPS *rps;
  2878. struct ls_rjt stat;
  2879. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  2880. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  2881. stat.un.b.lsRjtRsvd0 = 0;
  2882. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2883. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2884. stat.un.b.vendorUnique = 0;
  2885. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2886. NULL);
  2887. }
  2888. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2889. lp = (uint32_t *) pcmd->virt;
  2890. flag = (be32_to_cpu(*lp++) & 0xf);
  2891. rps = (RPS *) lp;
  2892. if ((flag == 0) ||
  2893. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  2894. ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
  2895. sizeof(struct lpfc_name)) == 0))) {
  2896. printk("Fix me....\n");
  2897. dump_stack();
  2898. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
  2899. if (mbox) {
  2900. lpfc_read_lnk_stat(phba, mbox);
  2901. mbox->context1 =
  2902. (void *)((unsigned long) cmdiocb->iocb.ulpContext);
  2903. mbox->context2 = lpfc_nlp_get(ndlp);
  2904. mbox->vport = vport;
  2905. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  2906. if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT)
  2907. != MBX_NOT_FINISHED)
  2908. /* Mbox completion will send ELS Response */
  2909. return 0;
  2910. lpfc_nlp_put(ndlp);
  2911. mempool_free(mbox, phba->mbox_mem_pool);
  2912. }
  2913. }
  2914. stat.un.b.lsRjtRsvd0 = 0;
  2915. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2916. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2917. stat.un.b.vendorUnique = 0;
  2918. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
  2919. return 0;
  2920. }
  2921. static int
  2922. lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
  2923. struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
  2924. {
  2925. struct lpfc_hba *phba = vport->phba;
  2926. IOCB_t *icmd, *oldcmd;
  2927. RPL_RSP rpl_rsp;
  2928. struct lpfc_iocbq *elsiocb;
  2929. struct lpfc_sli *psli = &phba->sli;
  2930. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  2931. uint8_t *pcmd;
  2932. elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
  2933. ndlp->nlp_DID, ELS_CMD_ACC);
  2934. if (!elsiocb)
  2935. return 1;
  2936. icmd = &elsiocb->iocb;
  2937. oldcmd = &oldiocb->iocb;
  2938. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2939. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2940. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2941. pcmd += sizeof(uint16_t);
  2942. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  2943. pcmd += sizeof(uint16_t);
  2944. /* Setup the RPL ACC payload */
  2945. rpl_rsp.listLen = be32_to_cpu(1);
  2946. rpl_rsp.index = 0;
  2947. rpl_rsp.port_num_blk.portNum = 0;
  2948. rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
  2949. memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
  2950. sizeof(struct lpfc_name));
  2951. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  2952. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  2953. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  2954. "0120 Xmit ELS RPL ACC response tag x%x "
  2955. "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
  2956. "rpi x%x\n",
  2957. elsiocb->iotag, elsiocb->iocb.ulpContext,
  2958. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  2959. ndlp->nlp_rpi);
  2960. elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
  2961. phba->fc_stat.elsXmitACC++;
  2962. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  2963. lpfc_els_free_iocb(phba, elsiocb);
  2964. return 1;
  2965. }
  2966. return 0;
  2967. }
  2968. static int
  2969. lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  2970. struct lpfc_nodelist *ndlp)
  2971. {
  2972. struct lpfc_dmabuf *pcmd;
  2973. uint32_t *lp;
  2974. uint32_t maxsize;
  2975. uint16_t cmdsize;
  2976. RPL *rpl;
  2977. struct ls_rjt stat;
  2978. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  2979. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  2980. stat.un.b.lsRjtRsvd0 = 0;
  2981. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2982. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2983. stat.un.b.vendorUnique = 0;
  2984. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
  2985. NULL);
  2986. }
  2987. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2988. lp = (uint32_t *) pcmd->virt;
  2989. rpl = (RPL *) (lp + 1);
  2990. maxsize = be32_to_cpu(rpl->maxsize);
  2991. /* We support only one port */
  2992. if ((rpl->index == 0) &&
  2993. ((maxsize == 0) ||
  2994. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  2995. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  2996. } else {
  2997. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  2998. }
  2999. lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
  3000. return 0;
  3001. }
  3002. static int
  3003. lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3004. struct lpfc_nodelist *ndlp)
  3005. {
  3006. struct lpfc_dmabuf *pcmd;
  3007. uint32_t *lp;
  3008. IOCB_t *icmd;
  3009. FARP *fp;
  3010. uint32_t cmd, cnt, did;
  3011. icmd = &cmdiocb->iocb;
  3012. did = icmd->un.elsreq64.remoteID;
  3013. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3014. lp = (uint32_t *) pcmd->virt;
  3015. cmd = *lp++;
  3016. fp = (FARP *) lp;
  3017. /* FARP-REQ received from DID <did> */
  3018. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3019. "0601 FARP-REQ received from DID x%x\n", did);
  3020. /* We will only support match on WWPN or WWNN */
  3021. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  3022. return 0;
  3023. }
  3024. cnt = 0;
  3025. /* If this FARP command is searching for my portname */
  3026. if (fp->Mflags & FARP_MATCH_PORT) {
  3027. if (memcmp(&fp->RportName, &vport->fc_portname,
  3028. sizeof(struct lpfc_name)) == 0)
  3029. cnt = 1;
  3030. }
  3031. /* If this FARP command is searching for my nodename */
  3032. if (fp->Mflags & FARP_MATCH_NODE) {
  3033. if (memcmp(&fp->RnodeName, &vport->fc_nodename,
  3034. sizeof(struct lpfc_name)) == 0)
  3035. cnt = 1;
  3036. }
  3037. if (cnt) {
  3038. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  3039. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  3040. /* Log back into the node before sending the FARP. */
  3041. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  3042. ndlp->nlp_prev_state = ndlp->nlp_state;
  3043. lpfc_nlp_set_state(vport, ndlp,
  3044. NLP_STE_PLOGI_ISSUE);
  3045. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  3046. }
  3047. /* Send a FARP response to that node */
  3048. if (fp->Rflags & FARP_REQUEST_FARPR)
  3049. lpfc_issue_els_farpr(vport, did, 0);
  3050. }
  3051. }
  3052. return 0;
  3053. }
  3054. static int
  3055. lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3056. struct lpfc_nodelist *ndlp)
  3057. {
  3058. struct lpfc_dmabuf *pcmd;
  3059. uint32_t *lp;
  3060. IOCB_t *icmd;
  3061. uint32_t cmd, did;
  3062. icmd = &cmdiocb->iocb;
  3063. did = icmd->un.elsreq64.remoteID;
  3064. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  3065. lp = (uint32_t *) pcmd->virt;
  3066. cmd = *lp++;
  3067. /* FARP-RSP received from DID <did> */
  3068. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3069. "0600 FARP-RSP received from DID x%x\n", did);
  3070. /* ACCEPT the Farp resp request */
  3071. lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
  3072. return 0;
  3073. }
  3074. static int
  3075. lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
  3076. struct lpfc_nodelist *fan_ndlp)
  3077. {
  3078. struct lpfc_dmabuf *pcmd;
  3079. uint32_t *lp;
  3080. IOCB_t *icmd;
  3081. uint32_t cmd, did;
  3082. FAN *fp;
  3083. struct lpfc_nodelist *ndlp, *next_ndlp;
  3084. struct lpfc_hba *phba = vport->phba;
  3085. /* FAN received */
  3086. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3087. "0265 FAN received\n");
  3088. icmd = &cmdiocb->iocb;
  3089. did = icmd->un.elsreq64.remoteID;
  3090. pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
  3091. lp = (uint32_t *)pcmd->virt;
  3092. cmd = *lp++;
  3093. fp = (FAN *) lp;
  3094. /* FAN received; Fan does not have a reply sequence */
  3095. if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
  3096. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  3097. sizeof(struct lpfc_name)) != 0) ||
  3098. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  3099. sizeof(struct lpfc_name)) != 0)) {
  3100. /*
  3101. * This node has switched fabrics. FLOGI is required
  3102. * Clean up the old rpi's
  3103. */
  3104. list_for_each_entry_safe(ndlp, next_ndlp,
  3105. &vport->fc_nodes, nlp_listp) {
  3106. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3107. continue;
  3108. if (ndlp->nlp_type & NLP_FABRIC) {
  3109. /*
  3110. * Clean up old Fabric, Nameserver and
  3111. * other NLP_FABRIC logins
  3112. */
  3113. lpfc_drop_node(vport, ndlp);
  3114. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  3115. /* Fail outstanding I/O now since this
  3116. * device is marked for PLOGI
  3117. */
  3118. lpfc_unreg_rpi(vport, ndlp);
  3119. }
  3120. }
  3121. lpfc_initial_flogi(vport);
  3122. return 0;
  3123. }
  3124. /* Discovery not needed,
  3125. * move the nodes to their original state.
  3126. */
  3127. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
  3128. nlp_listp) {
  3129. if (ndlp->nlp_state != NLP_STE_NPR_NODE)
  3130. continue;
  3131. switch (ndlp->nlp_prev_state) {
  3132. case NLP_STE_UNMAPPED_NODE:
  3133. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  3134. lpfc_nlp_set_state(vport, ndlp,
  3135. NLP_STE_UNMAPPED_NODE);
  3136. break;
  3137. case NLP_STE_MAPPED_NODE:
  3138. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  3139. lpfc_nlp_set_state(vport, ndlp,
  3140. NLP_STE_MAPPED_NODE);
  3141. break;
  3142. default:
  3143. break;
  3144. }
  3145. }
  3146. /* Start discovery - this should just do CLEAR_LA */
  3147. lpfc_disc_start(vport);
  3148. }
  3149. return 0;
  3150. }
  3151. void
  3152. lpfc_els_timeout(unsigned long ptr)
  3153. {
  3154. struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
  3155. struct lpfc_hba *phba = vport->phba;
  3156. unsigned long iflag;
  3157. spin_lock_irqsave(&vport->work_port_lock, iflag);
  3158. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3159. vport->work_port_events |= WORKER_ELS_TMO;
  3160. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3161. spin_lock_irqsave(&phba->hbalock, iflag);
  3162. if (phba->work_wait)
  3163. lpfc_worker_wake_up(phba);
  3164. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3165. }
  3166. else
  3167. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  3168. return;
  3169. }
  3170. void
  3171. lpfc_els_timeout_handler(struct lpfc_vport *vport)
  3172. {
  3173. struct lpfc_hba *phba = vport->phba;
  3174. struct lpfc_sli_ring *pring;
  3175. struct lpfc_iocbq *tmp_iocb, *piocb;
  3176. IOCB_t *cmd = NULL;
  3177. struct lpfc_dmabuf *pcmd;
  3178. uint32_t els_command = 0;
  3179. uint32_t timeout;
  3180. uint32_t remote_ID = 0xffffffff;
  3181. /* If the timer is already canceled do nothing */
  3182. if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
  3183. return;
  3184. }
  3185. spin_lock_irq(&phba->hbalock);
  3186. timeout = (uint32_t)(phba->fc_ratov << 1);
  3187. pring = &phba->sli.ring[LPFC_ELS_RING];
  3188. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3189. cmd = &piocb->iocb;
  3190. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
  3191. piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
  3192. piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
  3193. continue;
  3194. if (piocb->vport != vport)
  3195. continue;
  3196. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  3197. if (pcmd)
  3198. els_command = *(uint32_t *) (pcmd->virt);
  3199. if (els_command == ELS_CMD_FARP ||
  3200. els_command == ELS_CMD_FARPR ||
  3201. els_command == ELS_CMD_FDISC)
  3202. continue;
  3203. if (vport != piocb->vport)
  3204. continue;
  3205. if (piocb->drvrTimeout > 0) {
  3206. if (piocb->drvrTimeout >= timeout)
  3207. piocb->drvrTimeout -= timeout;
  3208. else
  3209. piocb->drvrTimeout = 0;
  3210. continue;
  3211. }
  3212. remote_ID = 0xffffffff;
  3213. if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
  3214. remote_ID = cmd->un.elsreq64.remoteID;
  3215. else {
  3216. struct lpfc_nodelist *ndlp;
  3217. ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
  3218. if (ndlp)
  3219. remote_ID = ndlp->nlp_DID;
  3220. }
  3221. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3222. "0127 ELS timeout Data: x%x x%x x%x "
  3223. "x%x\n", els_command,
  3224. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  3225. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3226. }
  3227. spin_unlock_irq(&phba->hbalock);
  3228. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  3229. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  3230. }
  3231. void
  3232. lpfc_els_flush_cmd(struct lpfc_vport *vport)
  3233. {
  3234. LIST_HEAD(completions);
  3235. struct lpfc_hba *phba = vport->phba;
  3236. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3237. struct lpfc_iocbq *tmp_iocb, *piocb;
  3238. IOCB_t *cmd = NULL;
  3239. lpfc_fabric_abort_vport(vport);
  3240. spin_lock_irq(&phba->hbalock);
  3241. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3242. cmd = &piocb->iocb;
  3243. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3244. continue;
  3245. }
  3246. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3247. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3248. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3249. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3250. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3251. continue;
  3252. if (piocb->vport != vport)
  3253. continue;
  3254. list_move_tail(&piocb->list, &completions);
  3255. pring->txq_cnt--;
  3256. }
  3257. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3258. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  3259. continue;
  3260. }
  3261. if (piocb->vport != vport)
  3262. continue;
  3263. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3264. }
  3265. spin_unlock_irq(&phba->hbalock);
  3266. while (!list_empty(&completions)) {
  3267. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3268. cmd = &piocb->iocb;
  3269. list_del_init(&piocb->list);
  3270. if (!piocb->iocb_cmpl)
  3271. lpfc_sli_release_iocbq(phba, piocb);
  3272. else {
  3273. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3274. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3275. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3276. }
  3277. }
  3278. return;
  3279. }
  3280. void
  3281. lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
  3282. {
  3283. LIST_HEAD(completions);
  3284. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3285. struct lpfc_iocbq *tmp_iocb, *piocb;
  3286. IOCB_t *cmd = NULL;
  3287. lpfc_fabric_abort_hba(phba);
  3288. spin_lock_irq(&phba->hbalock);
  3289. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  3290. cmd = &piocb->iocb;
  3291. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3292. continue;
  3293. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  3294. if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
  3295. cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
  3296. cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
  3297. cmd->ulpCommand == CMD_ABORT_XRI_CN)
  3298. continue;
  3299. list_move_tail(&piocb->list, &completions);
  3300. pring->txq_cnt--;
  3301. }
  3302. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  3303. if (piocb->iocb_flag & LPFC_IO_LIBDFC)
  3304. continue;
  3305. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  3306. }
  3307. spin_unlock_irq(&phba->hbalock);
  3308. while (!list_empty(&completions)) {
  3309. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  3310. cmd = &piocb->iocb;
  3311. list_del_init(&piocb->list);
  3312. if (!piocb->iocb_cmpl)
  3313. lpfc_sli_release_iocbq(phba, piocb);
  3314. else {
  3315. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3316. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3317. (piocb->iocb_cmpl) (phba, piocb, piocb);
  3318. }
  3319. }
  3320. return;
  3321. }
  3322. static void
  3323. lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3324. struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
  3325. {
  3326. struct Scsi_Host *shost;
  3327. struct lpfc_nodelist *ndlp;
  3328. struct ls_rjt stat;
  3329. uint32_t *payload;
  3330. uint32_t cmd, did, newnode, rjt_err = 0;
  3331. IOCB_t *icmd = &elsiocb->iocb;
  3332. if (vport == NULL || elsiocb->context2 == NULL)
  3333. goto dropit;
  3334. newnode = 0;
  3335. payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
  3336. cmd = *payload;
  3337. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
  3338. lpfc_post_buffer(phba, pring, 1, 1);
  3339. did = icmd->un.rcvels.remoteID;
  3340. if (icmd->ulpStatus) {
  3341. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3342. "RCV Unsol ELS: status:x%x/x%x did:x%x",
  3343. icmd->ulpStatus, icmd->un.ulpWord[4], did);
  3344. goto dropit;
  3345. }
  3346. /* Check to see if link went down during discovery */
  3347. if (lpfc_els_chk_latt(vport))
  3348. goto dropit;
  3349. /* Ignore traffic recevied during vport shutdown. */
  3350. if (vport->load_flag & FC_UNLOADING)
  3351. goto dropit;
  3352. ndlp = lpfc_findnode_did(vport, did);
  3353. if (!ndlp) {
  3354. /* Cannot find existing Fabric ndlp, so allocate a new one */
  3355. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3356. if (!ndlp)
  3357. goto dropit;
  3358. lpfc_nlp_init(vport, ndlp, did);
  3359. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3360. newnode = 1;
  3361. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
  3362. ndlp->nlp_type |= NLP_FABRIC;
  3363. }
  3364. }
  3365. else {
  3366. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
  3367. /* This is simular to the new node path */
  3368. lpfc_nlp_get(ndlp);
  3369. lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
  3370. newnode = 1;
  3371. }
  3372. }
  3373. phba->fc_stat.elsRcvFrame++;
  3374. if (elsiocb->context1)
  3375. lpfc_nlp_put(elsiocb->context1);
  3376. elsiocb->context1 = lpfc_nlp_get(ndlp);
  3377. elsiocb->vport = vport;
  3378. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  3379. cmd &= ELS_CMD_MASK;
  3380. }
  3381. /* ELS command <elsCmd> received from NPORT <did> */
  3382. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3383. "0112 ELS command x%x received from NPORT x%x "
  3384. "Data: x%x\n", cmd, did, vport->port_state);
  3385. switch (cmd) {
  3386. case ELS_CMD_PLOGI:
  3387. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3388. "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
  3389. did, vport->port_state, ndlp->nlp_flag);
  3390. phba->fc_stat.elsRcvPLOGI++;
  3391. ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
  3392. if (vport->port_state < LPFC_DISC_AUTH) {
  3393. rjt_err = LSRJT_UNABLE_TPC;
  3394. break;
  3395. }
  3396. shost = lpfc_shost_from_vport(vport);
  3397. spin_lock_irq(shost->host_lock);
  3398. ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
  3399. spin_unlock_irq(shost->host_lock);
  3400. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3401. NLP_EVT_RCV_PLOGI);
  3402. break;
  3403. case ELS_CMD_FLOGI:
  3404. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3405. "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
  3406. did, vport->port_state, ndlp->nlp_flag);
  3407. phba->fc_stat.elsRcvFLOGI++;
  3408. lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
  3409. if (newnode)
  3410. lpfc_nlp_put(ndlp);
  3411. break;
  3412. case ELS_CMD_LOGO:
  3413. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3414. "RCV LOGO: did:x%x/ste:x%x flg:x%x",
  3415. did, vport->port_state, ndlp->nlp_flag);
  3416. phba->fc_stat.elsRcvLOGO++;
  3417. if (vport->port_state < LPFC_DISC_AUTH) {
  3418. rjt_err = LSRJT_UNABLE_TPC;
  3419. break;
  3420. }
  3421. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  3422. break;
  3423. case ELS_CMD_PRLO:
  3424. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3425. "RCV PRLO: did:x%x/ste:x%x flg:x%x",
  3426. did, vport->port_state, ndlp->nlp_flag);
  3427. phba->fc_stat.elsRcvPRLO++;
  3428. if (vport->port_state < LPFC_DISC_AUTH) {
  3429. rjt_err = LSRJT_UNABLE_TPC;
  3430. break;
  3431. }
  3432. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  3433. break;
  3434. case ELS_CMD_RSCN:
  3435. phba->fc_stat.elsRcvRSCN++;
  3436. lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
  3437. if (newnode)
  3438. lpfc_nlp_put(ndlp);
  3439. break;
  3440. case ELS_CMD_ADISC:
  3441. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3442. "RCV ADISC: did:x%x/ste:x%x flg:x%x",
  3443. did, vport->port_state, ndlp->nlp_flag);
  3444. phba->fc_stat.elsRcvADISC++;
  3445. if (vport->port_state < LPFC_DISC_AUTH) {
  3446. rjt_err = LSRJT_UNABLE_TPC;
  3447. break;
  3448. }
  3449. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3450. NLP_EVT_RCV_ADISC);
  3451. break;
  3452. case ELS_CMD_PDISC:
  3453. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3454. "RCV PDISC: did:x%x/ste:x%x flg:x%x",
  3455. did, vport->port_state, ndlp->nlp_flag);
  3456. phba->fc_stat.elsRcvPDISC++;
  3457. if (vport->port_state < LPFC_DISC_AUTH) {
  3458. rjt_err = LSRJT_UNABLE_TPC;
  3459. break;
  3460. }
  3461. lpfc_disc_state_machine(vport, ndlp, elsiocb,
  3462. NLP_EVT_RCV_PDISC);
  3463. break;
  3464. case ELS_CMD_FARPR:
  3465. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3466. "RCV FARPR: did:x%x/ste:x%x flg:x%x",
  3467. did, vport->port_state, ndlp->nlp_flag);
  3468. phba->fc_stat.elsRcvFARPR++;
  3469. lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
  3470. break;
  3471. case ELS_CMD_FARP:
  3472. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3473. "RCV FARP: did:x%x/ste:x%x flg:x%x",
  3474. did, vport->port_state, ndlp->nlp_flag);
  3475. phba->fc_stat.elsRcvFARP++;
  3476. lpfc_els_rcv_farp(vport, elsiocb, ndlp);
  3477. break;
  3478. case ELS_CMD_FAN:
  3479. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3480. "RCV FAN: did:x%x/ste:x%x flg:x%x",
  3481. did, vport->port_state, ndlp->nlp_flag);
  3482. phba->fc_stat.elsRcvFAN++;
  3483. lpfc_els_rcv_fan(vport, elsiocb, ndlp);
  3484. break;
  3485. case ELS_CMD_PRLI:
  3486. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3487. "RCV PRLI: did:x%x/ste:x%x flg:x%x",
  3488. did, vport->port_state, ndlp->nlp_flag);
  3489. phba->fc_stat.elsRcvPRLI++;
  3490. if (vport->port_state < LPFC_DISC_AUTH) {
  3491. rjt_err = LSRJT_UNABLE_TPC;
  3492. break;
  3493. }
  3494. lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  3495. break;
  3496. case ELS_CMD_LIRR:
  3497. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3498. "RCV LIRR: did:x%x/ste:x%x flg:x%x",
  3499. did, vport->port_state, ndlp->nlp_flag);
  3500. phba->fc_stat.elsRcvLIRR++;
  3501. lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
  3502. if (newnode)
  3503. lpfc_nlp_put(ndlp);
  3504. break;
  3505. case ELS_CMD_RPS:
  3506. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3507. "RCV RPS: did:x%x/ste:x%x flg:x%x",
  3508. did, vport->port_state, ndlp->nlp_flag);
  3509. phba->fc_stat.elsRcvRPS++;
  3510. lpfc_els_rcv_rps(vport, elsiocb, ndlp);
  3511. if (newnode)
  3512. lpfc_nlp_put(ndlp);
  3513. break;
  3514. case ELS_CMD_RPL:
  3515. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3516. "RCV RPL: did:x%x/ste:x%x flg:x%x",
  3517. did, vport->port_state, ndlp->nlp_flag);
  3518. phba->fc_stat.elsRcvRPL++;
  3519. lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
  3520. if (newnode)
  3521. lpfc_nlp_put(ndlp);
  3522. break;
  3523. case ELS_CMD_RNID:
  3524. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3525. "RCV RNID: did:x%x/ste:x%x flg:x%x",
  3526. did, vport->port_state, ndlp->nlp_flag);
  3527. phba->fc_stat.elsRcvRNID++;
  3528. lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
  3529. if (newnode)
  3530. lpfc_nlp_put(ndlp);
  3531. break;
  3532. default:
  3533. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
  3534. "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
  3535. cmd, did, vport->port_state);
  3536. /* Unsupported ELS command, reject */
  3537. rjt_err = LSRJT_INVALID_CMD;
  3538. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  3539. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3540. "0115 Unknown ELS command x%x "
  3541. "received from NPORT x%x\n", cmd, did);
  3542. if (newnode)
  3543. lpfc_nlp_put(ndlp);
  3544. break;
  3545. }
  3546. /* check if need to LS_RJT received ELS cmd */
  3547. if (rjt_err) {
  3548. memset(&stat, 0, sizeof(stat));
  3549. stat.un.b.lsRjtRsnCode = rjt_err;
  3550. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  3551. lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
  3552. NULL);
  3553. }
  3554. return;
  3555. dropit:
  3556. if (vport && !(vport->load_flag & FC_UNLOADING))
  3557. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3558. "(%d):0111 Dropping received ELS cmd "
  3559. "Data: x%x x%x x%x\n",
  3560. vport->vpi, icmd->ulpStatus,
  3561. icmd->un.ulpWord[4], icmd->ulpTimeout);
  3562. phba->fc_stat.elsRcvDrop++;
  3563. }
  3564. static struct lpfc_vport *
  3565. lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
  3566. {
  3567. struct lpfc_vport *vport;
  3568. unsigned long flags;
  3569. spin_lock_irqsave(&phba->hbalock, flags);
  3570. list_for_each_entry(vport, &phba->port_list, listentry) {
  3571. if (vport->vpi == vpi) {
  3572. spin_unlock_irqrestore(&phba->hbalock, flags);
  3573. return vport;
  3574. }
  3575. }
  3576. spin_unlock_irqrestore(&phba->hbalock, flags);
  3577. return NULL;
  3578. }
  3579. void
  3580. lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3581. struct lpfc_iocbq *elsiocb)
  3582. {
  3583. struct lpfc_vport *vport = phba->pport;
  3584. IOCB_t *icmd = &elsiocb->iocb;
  3585. dma_addr_t paddr;
  3586. struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
  3587. struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
  3588. elsiocb->context2 = NULL;
  3589. elsiocb->context3 = NULL;
  3590. if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
  3591. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  3592. } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
  3593. (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
  3594. phba->fc_stat.NoRcvBuf++;
  3595. /* Not enough posted buffers; Try posting more buffers */
  3596. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  3597. lpfc_post_buffer(phba, pring, 0, 1);
  3598. return;
  3599. }
  3600. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3601. (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  3602. icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  3603. if (icmd->unsli3.rcvsli3.vpi == 0xffff)
  3604. vport = phba->pport;
  3605. else {
  3606. uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
  3607. vport = lpfc_find_vport_by_vpid(phba, vpi);
  3608. }
  3609. }
  3610. /* If there are no BDEs associated
  3611. * with this IOCB, there is nothing to do.
  3612. */
  3613. if (icmd->ulpBdeCount == 0)
  3614. return;
  3615. /* type of ELS cmd is first 32bit word
  3616. * in packet
  3617. */
  3618. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3619. elsiocb->context2 = bdeBuf1;
  3620. } else {
  3621. paddr = getPaddr(icmd->un.cont64[0].addrHigh,
  3622. icmd->un.cont64[0].addrLow);
  3623. elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
  3624. paddr);
  3625. }
  3626. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3627. /*
  3628. * The different unsolicited event handlers would tell us
  3629. * if they are done with "mp" by setting context2 to NULL.
  3630. */
  3631. lpfc_nlp_put(elsiocb->context1);
  3632. elsiocb->context1 = NULL;
  3633. if (elsiocb->context2) {
  3634. lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
  3635. elsiocb->context2 = NULL;
  3636. }
  3637. /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
  3638. if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
  3639. icmd->ulpBdeCount == 2) {
  3640. elsiocb->context2 = bdeBuf2;
  3641. lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
  3642. /* free mp if we are done with it */
  3643. if (elsiocb->context2) {
  3644. lpfc_in_buf_free(phba, elsiocb->context2);
  3645. elsiocb->context2 = NULL;
  3646. }
  3647. }
  3648. }
  3649. void
  3650. lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
  3651. {
  3652. struct lpfc_nodelist *ndlp, *ndlp_fdmi;
  3653. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  3654. if (!ndlp) {
  3655. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  3656. if (!ndlp) {
  3657. if (phba->fc_topology == TOPOLOGY_LOOP) {
  3658. lpfc_disc_start(vport);
  3659. return;
  3660. }
  3661. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3662. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3663. "0251 NameServer login: no memory\n");
  3664. return;
  3665. }
  3666. lpfc_nlp_init(vport, ndlp, NameServer_DID);
  3667. ndlp->nlp_type |= NLP_FABRIC;
  3668. }
  3669. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
  3670. if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
  3671. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3672. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3673. "0252 Cannot issue NameServer login\n");
  3674. return;
  3675. }
  3676. if (vport->cfg_fdmi_on) {
  3677. ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
  3678. GFP_KERNEL);
  3679. if (ndlp_fdmi) {
  3680. lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
  3681. ndlp_fdmi->nlp_type |= NLP_FABRIC;
  3682. ndlp_fdmi->nlp_state =
  3683. NLP_STE_PLOGI_ISSUE;
  3684. lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
  3685. 0);
  3686. }
  3687. }
  3688. return;
  3689. }
  3690. static void
  3691. lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  3692. {
  3693. struct lpfc_vport *vport = pmb->vport;
  3694. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3695. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
  3696. MAILBOX_t *mb = &pmb->mb;
  3697. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3698. lpfc_nlp_put(ndlp);
  3699. if (mb->mbxStatus) {
  3700. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3701. "0915 Register VPI failed: 0x%x\n",
  3702. mb->mbxStatus);
  3703. switch (mb->mbxStatus) {
  3704. case 0x11: /* unsupported feature */
  3705. case 0x9603: /* max_vpi exceeded */
  3706. /* giving up on vport registration */
  3707. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3708. spin_lock_irq(shost->host_lock);
  3709. vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  3710. spin_unlock_irq(shost->host_lock);
  3711. lpfc_can_disctmo(vport);
  3712. break;
  3713. default:
  3714. /* Try to recover from this error */
  3715. lpfc_mbx_unreg_vpi(vport);
  3716. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3717. lpfc_initial_fdisc(vport);
  3718. break;
  3719. }
  3720. } else {
  3721. if (vport == phba->pport)
  3722. lpfc_issue_fabric_reglogin(vport);
  3723. else
  3724. lpfc_do_scr_ns_plogi(phba, vport);
  3725. }
  3726. mempool_free(pmb, phba->mbox_mem_pool);
  3727. return;
  3728. }
  3729. static void
  3730. lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
  3731. struct lpfc_nodelist *ndlp)
  3732. {
  3733. LPFC_MBOXQ_t *mbox;
  3734. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  3735. if (mbox) {
  3736. lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
  3737. mbox->vport = vport;
  3738. mbox->context2 = lpfc_nlp_get(ndlp);
  3739. mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
  3740. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
  3741. == MBX_NOT_FINISHED) {
  3742. mempool_free(mbox, phba->mbox_mem_pool);
  3743. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3744. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3745. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3746. "0253 Register VPI: Can't send mbox\n");
  3747. }
  3748. } else {
  3749. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3750. lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
  3751. "0254 Register VPI: no memory\n");
  3752. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  3753. lpfc_nlp_put(ndlp);
  3754. }
  3755. }
  3756. static void
  3757. lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3758. struct lpfc_iocbq *rspiocb)
  3759. {
  3760. struct lpfc_vport *vport = cmdiocb->vport;
  3761. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3762. struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  3763. struct lpfc_nodelist *np;
  3764. struct lpfc_nodelist *next_np;
  3765. IOCB_t *irsp = &rspiocb->iocb;
  3766. struct lpfc_iocbq *piocb;
  3767. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  3768. "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
  3769. irsp->ulpStatus, irsp->un.ulpWord[4],
  3770. vport->fc_prevDID);
  3771. /* Since all FDISCs are being single threaded, we
  3772. * must reset the discovery timer for ALL vports
  3773. * waiting to send FDISC when one completes.
  3774. */
  3775. list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
  3776. lpfc_set_disctmo(piocb->vport);
  3777. }
  3778. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3779. "FDISC cmpl: status:x%x/x%x prevdid:x%x",
  3780. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
  3781. if (irsp->ulpStatus) {
  3782. /* Check for retry */
  3783. if (lpfc_els_retry(phba, cmdiocb, rspiocb))
  3784. goto out;
  3785. /* FDISC failed */
  3786. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3787. "0124 FDISC failed. (%d/%d)\n",
  3788. irsp->ulpStatus, irsp->un.ulpWord[4]);
  3789. if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
  3790. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3791. lpfc_nlp_put(ndlp);
  3792. /* giving up on FDISC. Cancel discovery timer */
  3793. lpfc_can_disctmo(vport);
  3794. } else {
  3795. spin_lock_irq(shost->host_lock);
  3796. vport->fc_flag |= FC_FABRIC;
  3797. if (vport->phba->fc_topology == TOPOLOGY_LOOP)
  3798. vport->fc_flag |= FC_PUBLIC_LOOP;
  3799. spin_unlock_irq(shost->host_lock);
  3800. vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  3801. lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
  3802. if ((vport->fc_prevDID != vport->fc_myDID) &&
  3803. !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
  3804. /* If our NportID changed, we need to ensure all
  3805. * remaining NPORTs get unreg_login'ed so we can
  3806. * issue unreg_vpi.
  3807. */
  3808. list_for_each_entry_safe(np, next_np,
  3809. &vport->fc_nodes, nlp_listp) {
  3810. if (np->nlp_state != NLP_STE_NPR_NODE
  3811. || !(np->nlp_flag & NLP_NPR_ADISC))
  3812. continue;
  3813. spin_lock_irq(shost->host_lock);
  3814. np->nlp_flag &= ~NLP_NPR_ADISC;
  3815. spin_unlock_irq(shost->host_lock);
  3816. lpfc_unreg_rpi(vport, np);
  3817. }
  3818. lpfc_mbx_unreg_vpi(vport);
  3819. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  3820. }
  3821. if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
  3822. lpfc_register_new_vport(phba, vport, ndlp);
  3823. else
  3824. lpfc_do_scr_ns_plogi(phba, vport);
  3825. lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
  3826. }
  3827. out:
  3828. lpfc_els_free_iocb(phba, cmdiocb);
  3829. }
  3830. static int
  3831. lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  3832. uint8_t retry)
  3833. {
  3834. struct lpfc_hba *phba = vport->phba;
  3835. IOCB_t *icmd;
  3836. struct lpfc_iocbq *elsiocb;
  3837. struct serv_parm *sp;
  3838. uint8_t *pcmd;
  3839. uint16_t cmdsize;
  3840. int did = ndlp->nlp_DID;
  3841. int rc;
  3842. cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
  3843. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
  3844. ELS_CMD_FDISC);
  3845. if (!elsiocb) {
  3846. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3847. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3848. "0255 Issue FDISC: no IOCB\n");
  3849. return 1;
  3850. }
  3851. icmd = &elsiocb->iocb;
  3852. icmd->un.elsreq64.myID = 0;
  3853. icmd->un.elsreq64.fl = 1;
  3854. /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
  3855. icmd->ulpCt_h = 1;
  3856. icmd->ulpCt_l = 0;
  3857. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3858. *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
  3859. pcmd += sizeof(uint32_t); /* CSP Word 1 */
  3860. memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
  3861. sp = (struct serv_parm *) pcmd;
  3862. /* Setup CSPs accordingly for Fabric */
  3863. sp->cmn.e_d_tov = 0;
  3864. sp->cmn.w2.r_a_tov = 0;
  3865. sp->cls1.classValid = 0;
  3866. sp->cls2.seqDelivery = 1;
  3867. sp->cls3.seqDelivery = 1;
  3868. pcmd += sizeof(uint32_t); /* CSP Word 2 */
  3869. pcmd += sizeof(uint32_t); /* CSP Word 3 */
  3870. pcmd += sizeof(uint32_t); /* CSP Word 4 */
  3871. pcmd += sizeof(uint32_t); /* Port Name */
  3872. memcpy(pcmd, &vport->fc_portname, 8);
  3873. pcmd += sizeof(uint32_t); /* Node Name */
  3874. pcmd += sizeof(uint32_t); /* Node Name */
  3875. memcpy(pcmd, &vport->fc_nodename, 8);
  3876. lpfc_set_disctmo(vport);
  3877. phba->fc_stat.elsXmitFDISC++;
  3878. elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
  3879. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3880. "Issue FDISC: did:x%x",
  3881. did, 0, 0);
  3882. rc = lpfc_issue_fabric_iocb(phba, elsiocb);
  3883. if (rc == IOCB_ERROR) {
  3884. lpfc_els_free_iocb(phba, elsiocb);
  3885. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  3886. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  3887. "0256 Issue FDISC: Cannot send IOCB\n");
  3888. return 1;
  3889. }
  3890. lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
  3891. vport->port_state = LPFC_FDISC;
  3892. return 0;
  3893. }
  3894. static void
  3895. lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  3896. struct lpfc_iocbq *rspiocb)
  3897. {
  3898. struct lpfc_vport *vport = cmdiocb->vport;
  3899. IOCB_t *irsp;
  3900. irsp = &rspiocb->iocb;
  3901. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3902. "LOGO npiv cmpl: status:x%x/x%x did:x%x",
  3903. irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
  3904. lpfc_els_free_iocb(phba, cmdiocb);
  3905. vport->unreg_vpi_cmpl = VPORT_ERROR;
  3906. }
  3907. int
  3908. lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  3909. {
  3910. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  3911. struct lpfc_hba *phba = vport->phba;
  3912. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3913. IOCB_t *icmd;
  3914. struct lpfc_iocbq *elsiocb;
  3915. uint8_t *pcmd;
  3916. uint16_t cmdsize;
  3917. cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
  3918. elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
  3919. ELS_CMD_LOGO);
  3920. if (!elsiocb)
  3921. return 1;
  3922. icmd = &elsiocb->iocb;
  3923. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  3924. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  3925. pcmd += sizeof(uint32_t);
  3926. /* Fill in LOGO payload */
  3927. *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
  3928. pcmd += sizeof(uint32_t);
  3929. memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
  3930. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
  3931. "Issue LOGO npiv did:x%x flg:x%x",
  3932. ndlp->nlp_DID, ndlp->nlp_flag, 0);
  3933. elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
  3934. spin_lock_irq(shost->host_lock);
  3935. ndlp->nlp_flag |= NLP_LOGO_SND;
  3936. spin_unlock_irq(shost->host_lock);
  3937. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  3938. spin_lock_irq(shost->host_lock);
  3939. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  3940. spin_unlock_irq(shost->host_lock);
  3941. lpfc_els_free_iocb(phba, elsiocb);
  3942. return 1;
  3943. }
  3944. return 0;
  3945. }
  3946. void
  3947. lpfc_fabric_block_timeout(unsigned long ptr)
  3948. {
  3949. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  3950. unsigned long iflags;
  3951. uint32_t tmo_posted;
  3952. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  3953. tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
  3954. if (!tmo_posted)
  3955. phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
  3956. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  3957. if (!tmo_posted) {
  3958. spin_lock_irqsave(&phba->hbalock, iflags);
  3959. if (phba->work_wait)
  3960. lpfc_worker_wake_up(phba);
  3961. spin_unlock_irqrestore(&phba->hbalock, iflags);
  3962. }
  3963. }
  3964. static void
  3965. lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
  3966. {
  3967. struct lpfc_iocbq *iocb;
  3968. unsigned long iflags;
  3969. int ret;
  3970. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  3971. IOCB_t *cmd;
  3972. repeat:
  3973. iocb = NULL;
  3974. spin_lock_irqsave(&phba->hbalock, iflags);
  3975. /* Post any pending iocb to the SLI layer */
  3976. if (atomic_read(&phba->fabric_iocb_count) == 0) {
  3977. list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
  3978. list);
  3979. if (iocb)
  3980. atomic_inc(&phba->fabric_iocb_count);
  3981. }
  3982. spin_unlock_irqrestore(&phba->hbalock, iflags);
  3983. if (iocb) {
  3984. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  3985. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  3986. iocb->iocb_flag |= LPFC_IO_FABRIC;
  3987. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  3988. "Fabric sched1: ste:x%x",
  3989. iocb->vport->port_state, 0, 0);
  3990. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  3991. if (ret == IOCB_ERROR) {
  3992. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  3993. iocb->fabric_iocb_cmpl = NULL;
  3994. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  3995. cmd = &iocb->iocb;
  3996. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  3997. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  3998. iocb->iocb_cmpl(phba, iocb, iocb);
  3999. atomic_dec(&phba->fabric_iocb_count);
  4000. goto repeat;
  4001. }
  4002. }
  4003. return;
  4004. }
  4005. void
  4006. lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
  4007. {
  4008. clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4009. lpfc_resume_fabric_iocbs(phba);
  4010. return;
  4011. }
  4012. static void
  4013. lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
  4014. {
  4015. int blocked;
  4016. blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4017. /* Start a timer to unblock fabric
  4018. * iocbs after 100ms
  4019. */
  4020. if (!blocked)
  4021. mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
  4022. return;
  4023. }
  4024. static void
  4025. lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  4026. struct lpfc_iocbq *rspiocb)
  4027. {
  4028. struct ls_rjt stat;
  4029. if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
  4030. BUG();
  4031. switch (rspiocb->iocb.ulpStatus) {
  4032. case IOSTAT_NPORT_RJT:
  4033. case IOSTAT_FABRIC_RJT:
  4034. if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  4035. lpfc_block_fabric_iocbs(phba);
  4036. }
  4037. break;
  4038. case IOSTAT_NPORT_BSY:
  4039. case IOSTAT_FABRIC_BSY:
  4040. lpfc_block_fabric_iocbs(phba);
  4041. break;
  4042. case IOSTAT_LS_RJT:
  4043. stat.un.lsRjtError =
  4044. be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
  4045. if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
  4046. (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
  4047. lpfc_block_fabric_iocbs(phba);
  4048. break;
  4049. }
  4050. if (atomic_read(&phba->fabric_iocb_count) == 0)
  4051. BUG();
  4052. cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
  4053. cmdiocb->fabric_iocb_cmpl = NULL;
  4054. cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4055. cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
  4056. atomic_dec(&phba->fabric_iocb_count);
  4057. if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
  4058. /* Post any pending iocbs to HBA */
  4059. lpfc_resume_fabric_iocbs(phba);
  4060. }
  4061. }
  4062. static int
  4063. lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
  4064. {
  4065. unsigned long iflags;
  4066. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4067. int ready;
  4068. int ret;
  4069. if (atomic_read(&phba->fabric_iocb_count) > 1)
  4070. BUG();
  4071. spin_lock_irqsave(&phba->hbalock, iflags);
  4072. ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
  4073. !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
  4074. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4075. if (ready) {
  4076. iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
  4077. iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
  4078. iocb->iocb_flag |= LPFC_IO_FABRIC;
  4079. lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
  4080. "Fabric sched2: ste:x%x",
  4081. iocb->vport->port_state, 0, 0);
  4082. atomic_inc(&phba->fabric_iocb_count);
  4083. ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
  4084. if (ret == IOCB_ERROR) {
  4085. iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
  4086. iocb->fabric_iocb_cmpl = NULL;
  4087. iocb->iocb_flag &= ~LPFC_IO_FABRIC;
  4088. atomic_dec(&phba->fabric_iocb_count);
  4089. }
  4090. } else {
  4091. spin_lock_irqsave(&phba->hbalock, iflags);
  4092. list_add_tail(&iocb->list, &phba->fabric_iocb_list);
  4093. spin_unlock_irqrestore(&phba->hbalock, iflags);
  4094. ret = IOCB_SUCCESS;
  4095. }
  4096. return ret;
  4097. }
  4098. static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
  4099. {
  4100. LIST_HEAD(completions);
  4101. struct lpfc_hba *phba = vport->phba;
  4102. struct lpfc_iocbq *tmp_iocb, *piocb;
  4103. IOCB_t *cmd;
  4104. spin_lock_irq(&phba->hbalock);
  4105. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4106. list) {
  4107. if (piocb->vport != vport)
  4108. continue;
  4109. list_move_tail(&piocb->list, &completions);
  4110. }
  4111. spin_unlock_irq(&phba->hbalock);
  4112. while (!list_empty(&completions)) {
  4113. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4114. list_del_init(&piocb->list);
  4115. cmd = &piocb->iocb;
  4116. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4117. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4118. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4119. }
  4120. }
  4121. void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
  4122. {
  4123. LIST_HEAD(completions);
  4124. struct lpfc_hba *phba = ndlp->vport->phba;
  4125. struct lpfc_iocbq *tmp_iocb, *piocb;
  4126. struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
  4127. IOCB_t *cmd;
  4128. spin_lock_irq(&phba->hbalock);
  4129. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4130. list) {
  4131. if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
  4132. list_move_tail(&piocb->list, &completions);
  4133. }
  4134. }
  4135. spin_unlock_irq(&phba->hbalock);
  4136. while (!list_empty(&completions)) {
  4137. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4138. list_del_init(&piocb->list);
  4139. cmd = &piocb->iocb;
  4140. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4141. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4142. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4143. }
  4144. }
  4145. void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
  4146. {
  4147. LIST_HEAD(completions);
  4148. struct lpfc_iocbq *piocb;
  4149. IOCB_t *cmd;
  4150. spin_lock_irq(&phba->hbalock);
  4151. list_splice_init(&phba->fabric_iocb_list, &completions);
  4152. spin_unlock_irq(&phba->hbalock);
  4153. while (!list_empty(&completions)) {
  4154. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4155. list_del_init(&piocb->list);
  4156. cmd = &piocb->iocb;
  4157. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4158. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4159. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4160. }
  4161. }
  4162. #if 0
  4163. void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
  4164. {
  4165. LIST_HEAD(completions);
  4166. struct lpfc_iocbq *tmp_iocb, *piocb;
  4167. IOCB_t *cmd;
  4168. struct lpfc_nodelist *ndlp;
  4169. spin_lock_irq(&phba->hbalock);
  4170. list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
  4171. list) {
  4172. cmd = &piocb->iocb;
  4173. ndlp = (struct lpfc_nodelist *) piocb->context1;
  4174. if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
  4175. ndlp != NULL &&
  4176. ndlp->nlp_DID == Fabric_DID)
  4177. list_move_tail(&piocb->list, &completions);
  4178. }
  4179. spin_unlock_irq(&phba->hbalock);
  4180. while (!list_empty(&completions)) {
  4181. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  4182. list_del_init(&piocb->list);
  4183. cmd = &piocb->iocb;
  4184. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  4185. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  4186. (piocb->iocb_cmpl) (phba, piocb, piocb);
  4187. }
  4188. }
  4189. #endif /* 0 */