lpfc_els.c 131 KB

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