lpfc_els.c 138 KB

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