lpfc_els.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2006 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <scsi/scsi.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_transport_fc.h>
  28. #include "lpfc_hw.h"
  29. #include "lpfc_sli.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_scsi.h"
  32. #include "lpfc.h"
  33. #include "lpfc_logmsg.h"
  34. #include "lpfc_crtn.h"
  35. static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
  36. struct lpfc_iocbq *);
  37. static int lpfc_max_els_tries = 3;
  38. static int
  39. lpfc_els_chk_latt(struct lpfc_hba * phba)
  40. {
  41. struct lpfc_sli *psli;
  42. LPFC_MBOXQ_t *mbox;
  43. uint32_t ha_copy;
  44. int rc;
  45. psli = &phba->sli;
  46. if ((phba->hba_state >= LPFC_HBA_READY) ||
  47. (phba->hba_state == LPFC_LINK_DOWN))
  48. return 0;
  49. /* Read the HBA Host Attention Register */
  50. spin_lock_irq(phba->host->host_lock);
  51. ha_copy = readl(phba->HAregaddr);
  52. spin_unlock_irq(phba->host->host_lock);
  53. if (!(ha_copy & HA_LATT))
  54. return 0;
  55. /* Pending Link Event during Discovery */
  56. lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
  57. "%d:0237 Pending Link Event during "
  58. "Discovery: State x%x\n",
  59. phba->brd_no, phba->hba_state);
  60. /* CLEAR_LA should re-enable link attention events and
  61. * we should then imediately take a LATT event. The
  62. * LATT processing should call lpfc_linkdown() which
  63. * will cleanup any left over in-progress discovery
  64. * events.
  65. */
  66. spin_lock_irq(phba->host->host_lock);
  67. phba->fc_flag |= FC_ABORT_DISCOVERY;
  68. spin_unlock_irq(phba->host->host_lock);
  69. if (phba->hba_state != LPFC_CLEAR_LA) {
  70. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
  71. phba->hba_state = LPFC_CLEAR_LA;
  72. lpfc_clear_la(phba, mbox);
  73. mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
  74. rc = lpfc_sli_issue_mbox (phba, mbox,
  75. (MBX_NOWAIT | MBX_STOP_IOCB));
  76. if (rc == MBX_NOT_FINISHED) {
  77. mempool_free(mbox, phba->mbox_mem_pool);
  78. phba->hba_state = LPFC_HBA_ERROR;
  79. }
  80. }
  81. }
  82. return 1;
  83. }
  84. static struct lpfc_iocbq *
  85. lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
  86. uint16_t cmdSize, uint8_t retry, struct lpfc_nodelist * ndlp,
  87. uint32_t did, uint32_t elscmd)
  88. {
  89. struct lpfc_sli_ring *pring;
  90. struct lpfc_iocbq *elsiocb;
  91. struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
  92. struct ulp_bde64 *bpl;
  93. IOCB_t *icmd;
  94. pring = &phba->sli.ring[LPFC_ELS_RING];
  95. if (phba->hba_state < LPFC_LINK_UP)
  96. return NULL;
  97. /* Allocate buffer for command iocb */
  98. spin_lock_irq(phba->host->host_lock);
  99. elsiocb = lpfc_sli_get_iocbq(phba);
  100. spin_unlock_irq(phba->host->host_lock);
  101. if (elsiocb == NULL)
  102. return NULL;
  103. icmd = &elsiocb->iocb;
  104. /* fill in BDEs for command */
  105. /* Allocate buffer for command payload */
  106. if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
  107. ((pcmd->virt = lpfc_mbuf_alloc(phba,
  108. MEM_PRI, &(pcmd->phys))) == 0)) {
  109. kfree(pcmd);
  110. spin_lock_irq(phba->host->host_lock);
  111. lpfc_sli_release_iocbq(phba, elsiocb);
  112. spin_unlock_irq(phba->host->host_lock);
  113. return NULL;
  114. }
  115. INIT_LIST_HEAD(&pcmd->list);
  116. /* Allocate buffer for response payload */
  117. if (expectRsp) {
  118. prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  119. if (prsp)
  120. prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  121. &prsp->phys);
  122. if (prsp == 0 || prsp->virt == 0) {
  123. kfree(prsp);
  124. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  125. kfree(pcmd);
  126. spin_lock_irq(phba->host->host_lock);
  127. lpfc_sli_release_iocbq(phba, elsiocb);
  128. spin_unlock_irq(phba->host->host_lock);
  129. return NULL;
  130. }
  131. INIT_LIST_HEAD(&prsp->list);
  132. } else {
  133. prsp = NULL;
  134. }
  135. /* Allocate buffer for Buffer ptr list */
  136. pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  137. if (pbuflist)
  138. pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  139. &pbuflist->phys);
  140. if (pbuflist == 0 || pbuflist->virt == 0) {
  141. spin_lock_irq(phba->host->host_lock);
  142. lpfc_sli_release_iocbq(phba, elsiocb);
  143. spin_unlock_irq(phba->host->host_lock);
  144. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  145. lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
  146. kfree(pcmd);
  147. kfree(prsp);
  148. kfree(pbuflist);
  149. return NULL;
  150. }
  151. INIT_LIST_HEAD(&pbuflist->list);
  152. icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
  153. icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
  154. icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
  155. if (expectRsp) {
  156. icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
  157. icmd->un.elsreq64.remoteID = did; /* DID */
  158. icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  159. icmd->ulpTimeout = phba->fc_ratov * 2;
  160. } else {
  161. icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
  162. icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  163. }
  164. icmd->ulpBdeCount = 1;
  165. icmd->ulpLe = 1;
  166. icmd->ulpClass = CLASS3;
  167. bpl = (struct ulp_bde64 *) pbuflist->virt;
  168. bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
  169. bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
  170. bpl->tus.f.bdeSize = cmdSize;
  171. bpl->tus.f.bdeFlags = 0;
  172. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  173. if (expectRsp) {
  174. bpl++;
  175. bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
  176. bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
  177. bpl->tus.f.bdeSize = FCELSSIZE;
  178. bpl->tus.f.bdeFlags = BUFF_USE_RCV;
  179. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  180. }
  181. /* Save for completion so we can release these resources */
  182. elsiocb->context1 = (uint8_t *) ndlp;
  183. elsiocb->context2 = (uint8_t *) pcmd;
  184. elsiocb->context3 = (uint8_t *) pbuflist;
  185. elsiocb->retry = retry;
  186. elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
  187. if (prsp) {
  188. list_add(&prsp->list, &pcmd->list);
  189. }
  190. if (expectRsp) {
  191. /* Xmit ELS command <elsCmd> to remote NPORT <did> */
  192. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  193. "%d:0116 Xmit ELS command x%x to remote "
  194. "NPORT x%x I/O tag: x%x, HBA state: x%x\n",
  195. phba->brd_no, elscmd,
  196. did, elsiocb->iotag, phba->hba_state);
  197. } else {
  198. /* Xmit ELS response <elsCmd> to remote NPORT <did> */
  199. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  200. "%d:0117 Xmit ELS response x%x to remote "
  201. "NPORT x%x I/O tag: x%x, size: x%x\n",
  202. phba->brd_no, elscmd,
  203. ndlp->nlp_DID, elsiocb->iotag, cmdSize);
  204. }
  205. return elsiocb;
  206. }
  207. static int
  208. lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  209. struct serv_parm *sp, IOCB_t *irsp)
  210. {
  211. LPFC_MBOXQ_t *mbox;
  212. struct lpfc_dmabuf *mp;
  213. int rc;
  214. spin_lock_irq(phba->host->host_lock);
  215. phba->fc_flag |= FC_FABRIC;
  216. spin_unlock_irq(phba->host->host_lock);
  217. phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
  218. if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
  219. phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
  220. phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
  221. if (phba->fc_topology == TOPOLOGY_LOOP) {
  222. spin_lock_irq(phba->host->host_lock);
  223. phba->fc_flag |= FC_PUBLIC_LOOP;
  224. spin_unlock_irq(phba->host->host_lock);
  225. } else {
  226. /*
  227. * If we are a N-port connected to a Fabric, fixup sparam's so
  228. * logins to devices on remote loops work.
  229. */
  230. phba->fc_sparam.cmn.altBbCredit = 1;
  231. }
  232. phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
  233. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
  234. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
  235. ndlp->nlp_class_sup = 0;
  236. if (sp->cls1.classValid)
  237. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  238. if (sp->cls2.classValid)
  239. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  240. if (sp->cls3.classValid)
  241. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  242. if (sp->cls4.classValid)
  243. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  244. ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  245. sp->cmn.bbRcvSizeLsb;
  246. memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
  247. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  248. if (!mbox)
  249. goto fail;
  250. phba->hba_state = LPFC_FABRIC_CFG_LINK;
  251. lpfc_config_link(phba, mbox);
  252. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  253. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
  254. if (rc == MBX_NOT_FINISHED)
  255. goto fail_free_mbox;
  256. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  257. if (!mbox)
  258. goto fail;
  259. if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0))
  260. goto fail_free_mbox;
  261. mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
  262. mbox->context2 = ndlp;
  263. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
  264. if (rc == MBX_NOT_FINISHED)
  265. goto fail_issue_reg_login;
  266. return 0;
  267. fail_issue_reg_login:
  268. mp = (struct lpfc_dmabuf *) mbox->context1;
  269. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  270. kfree(mp);
  271. fail_free_mbox:
  272. mempool_free(mbox, phba->mbox_mem_pool);
  273. fail:
  274. return -ENXIO;
  275. }
  276. /*
  277. * We FLOGIed into an NPort, initiate pt2pt protocol
  278. */
  279. static int
  280. lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  281. struct serv_parm *sp)
  282. {
  283. LPFC_MBOXQ_t *mbox;
  284. int rc;
  285. spin_lock_irq(phba->host->host_lock);
  286. phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  287. spin_unlock_irq(phba->host->host_lock);
  288. phba->fc_edtov = FF_DEF_EDTOV;
  289. phba->fc_ratov = FF_DEF_RATOV;
  290. rc = memcmp(&phba->fc_portname, &sp->portName,
  291. sizeof(struct lpfc_name));
  292. if (rc >= 0) {
  293. /* This side will initiate the PLOGI */
  294. spin_lock_irq(phba->host->host_lock);
  295. phba->fc_flag |= FC_PT2PT_PLOGI;
  296. spin_unlock_irq(phba->host->host_lock);
  297. /*
  298. * N_Port ID cannot be 0, set our to LocalID the other
  299. * side will be RemoteID.
  300. */
  301. /* not equal */
  302. if (rc)
  303. phba->fc_myDID = PT2PT_LocalID;
  304. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  305. if (!mbox)
  306. goto fail;
  307. lpfc_config_link(phba, mbox);
  308. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  309. rc = lpfc_sli_issue_mbox(phba, mbox,
  310. MBX_NOWAIT | MBX_STOP_IOCB);
  311. if (rc == MBX_NOT_FINISHED) {
  312. mempool_free(mbox, phba->mbox_mem_pool);
  313. goto fail;
  314. }
  315. mempool_free(ndlp, phba->nlp_mem_pool);
  316. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, PT2PT_RemoteID);
  317. if (!ndlp) {
  318. /*
  319. * Cannot find existing Fabric ndlp, so allocate a
  320. * new one
  321. */
  322. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  323. if (!ndlp)
  324. goto fail;
  325. lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID);
  326. }
  327. memcpy(&ndlp->nlp_portname, &sp->portName,
  328. sizeof(struct lpfc_name));
  329. memcpy(&ndlp->nlp_nodename, &sp->nodeName,
  330. sizeof(struct lpfc_name));
  331. lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
  332. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  333. } else {
  334. /* This side will wait for the PLOGI */
  335. mempool_free( ndlp, phba->nlp_mem_pool);
  336. }
  337. spin_lock_irq(phba->host->host_lock);
  338. phba->fc_flag |= FC_PT2PT;
  339. spin_unlock_irq(phba->host->host_lock);
  340. /* Start discovery - this should just do CLEAR_LA */
  341. lpfc_disc_start(phba);
  342. return 0;
  343. fail:
  344. return -ENXIO;
  345. }
  346. static void
  347. lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
  348. struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
  349. {
  350. IOCB_t *irsp = &rspiocb->iocb;
  351. struct lpfc_nodelist *ndlp = cmdiocb->context1;
  352. struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
  353. struct serv_parm *sp;
  354. int rc;
  355. /* Check to see if link went down during discovery */
  356. if (lpfc_els_chk_latt(phba)) {
  357. lpfc_nlp_remove(phba, ndlp);
  358. goto out;
  359. }
  360. if (irsp->ulpStatus) {
  361. /* Check for retry */
  362. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  363. /* ELS command is being retried */
  364. goto out;
  365. }
  366. /* FLOGI failed, so there is no fabric */
  367. spin_lock_irq(phba->host->host_lock);
  368. phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  369. spin_unlock_irq(phba->host->host_lock);
  370. /* If private loop, then allow max outstandting els to be
  371. * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
  372. * alpa map would take too long otherwise.
  373. */
  374. if (phba->alpa_map[0] == 0) {
  375. phba->cfg_discovery_threads =
  376. LPFC_MAX_DISC_THREADS;
  377. }
  378. /* FLOGI failure */
  379. lpfc_printf_log(phba,
  380. KERN_INFO,
  381. LOG_ELS,
  382. "%d:0100 FLOGI failure Data: x%x x%x x%x\n",
  383. phba->brd_no,
  384. irsp->ulpStatus, irsp->un.ulpWord[4],
  385. irsp->ulpTimeout);
  386. goto flogifail;
  387. }
  388. /*
  389. * The FLogI succeeded. Sync the data for the CPU before
  390. * accessing it.
  391. */
  392. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
  393. sp = prsp->virt + sizeof(uint32_t);
  394. /* FLOGI completes successfully */
  395. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  396. "%d:0101 FLOGI completes sucessfully "
  397. "Data: x%x x%x x%x x%x\n",
  398. phba->brd_no,
  399. irsp->un.ulpWord[4], sp->cmn.e_d_tov,
  400. sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
  401. if (phba->hba_state == LPFC_FLOGI) {
  402. /*
  403. * If Common Service Parameters indicate Nport
  404. * we are point to point, if Fport we are Fabric.
  405. */
  406. if (sp->cmn.fPort)
  407. rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp);
  408. else
  409. rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp);
  410. if (!rc)
  411. goto out;
  412. }
  413. flogifail:
  414. lpfc_nlp_remove(phba, ndlp);
  415. if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
  416. (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
  417. irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
  418. /* FLOGI failed, so just use loop map to make discovery list */
  419. lpfc_disc_list_loopmap(phba);
  420. /* Start discovery */
  421. lpfc_disc_start(phba);
  422. }
  423. out:
  424. lpfc_els_free_iocb(phba, cmdiocb);
  425. }
  426. static int
  427. lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  428. uint8_t retry)
  429. {
  430. struct serv_parm *sp;
  431. IOCB_t *icmd;
  432. struct lpfc_iocbq *elsiocb;
  433. struct lpfc_sli_ring *pring;
  434. uint8_t *pcmd;
  435. uint16_t cmdsize;
  436. uint32_t tmo;
  437. int rc;
  438. pring = &phba->sli.ring[LPFC_ELS_RING];
  439. cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
  440. elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
  441. ndlp->nlp_DID, ELS_CMD_FLOGI);
  442. if (!elsiocb)
  443. return 1;
  444. icmd = &elsiocb->iocb;
  445. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  446. /* For FLOGI request, remainder of payload is service parameters */
  447. *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
  448. pcmd += sizeof (uint32_t);
  449. memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
  450. sp = (struct serv_parm *) pcmd;
  451. /* Setup CSPs accordingly for Fabric */
  452. sp->cmn.e_d_tov = 0;
  453. sp->cmn.w2.r_a_tov = 0;
  454. sp->cls1.classValid = 0;
  455. sp->cls2.seqDelivery = 1;
  456. sp->cls3.seqDelivery = 1;
  457. if (sp->cmn.fcphLow < FC_PH3)
  458. sp->cmn.fcphLow = FC_PH3;
  459. if (sp->cmn.fcphHigh < FC_PH3)
  460. sp->cmn.fcphHigh = FC_PH3;
  461. tmo = phba->fc_ratov;
  462. phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
  463. lpfc_set_disctmo(phba);
  464. phba->fc_ratov = tmo;
  465. phba->fc_stat.elsXmitFLOGI++;
  466. elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
  467. spin_lock_irq(phba->host->host_lock);
  468. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  469. spin_unlock_irq(phba->host->host_lock);
  470. if (rc == IOCB_ERROR) {
  471. lpfc_els_free_iocb(phba, elsiocb);
  472. return 1;
  473. }
  474. return 0;
  475. }
  476. int
  477. lpfc_els_abort_flogi(struct lpfc_hba * phba)
  478. {
  479. struct lpfc_sli_ring *pring;
  480. struct lpfc_iocbq *iocb, *next_iocb;
  481. struct lpfc_nodelist *ndlp;
  482. IOCB_t *icmd;
  483. /* Abort outstanding I/O on NPort <nlp_DID> */
  484. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  485. "%d:0201 Abort outstanding I/O on NPort x%x\n",
  486. phba->brd_no, Fabric_DID);
  487. pring = &phba->sli.ring[LPFC_ELS_RING];
  488. /*
  489. * Check the txcmplq for an iocb that matches the nport the driver is
  490. * searching for.
  491. */
  492. spin_lock_irq(phba->host->host_lock);
  493. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
  494. icmd = &iocb->iocb;
  495. if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
  496. ndlp = (struct lpfc_nodelist *)(iocb->context1);
  497. if (ndlp && (ndlp->nlp_DID == Fabric_DID))
  498. lpfc_sli_issue_abort_iotag(phba, pring, iocb);
  499. }
  500. }
  501. spin_unlock_irq(phba->host->host_lock);
  502. return 0;
  503. }
  504. int
  505. lpfc_initial_flogi(struct lpfc_hba * phba)
  506. {
  507. struct lpfc_nodelist *ndlp;
  508. /* First look for the Fabric ndlp */
  509. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, Fabric_DID);
  510. if (!ndlp) {
  511. /* Cannot find existing Fabric ndlp, so allocate a new one */
  512. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  513. if (!ndlp)
  514. return 0;
  515. lpfc_nlp_init(phba, ndlp, Fabric_DID);
  516. } else {
  517. lpfc_dequeue_node(phba, ndlp);
  518. }
  519. if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
  520. mempool_free( ndlp, phba->nlp_mem_pool);
  521. }
  522. return 1;
  523. }
  524. static void
  525. lpfc_more_plogi(struct lpfc_hba * phba)
  526. {
  527. int sentplogi;
  528. if (phba->num_disc_nodes)
  529. phba->num_disc_nodes--;
  530. /* Continue discovery with <num_disc_nodes> PLOGIs to go */
  531. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  532. "%d:0232 Continue discovery with %d PLOGIs to go "
  533. "Data: x%x x%x x%x\n",
  534. phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
  535. phba->fc_flag, phba->hba_state);
  536. /* Check to see if there are more PLOGIs to be sent */
  537. if (phba->fc_flag & FC_NLP_MORE) {
  538. /* go thru NPR list and issue any remaining ELS PLOGIs */
  539. sentplogi = lpfc_els_disc_plogi(phba);
  540. }
  541. return;
  542. }
  543. static struct lpfc_nodelist *
  544. lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_dmabuf *prsp,
  545. struct lpfc_nodelist *ndlp)
  546. {
  547. struct lpfc_nodelist *new_ndlp;
  548. uint32_t *lp;
  549. struct serv_parm *sp;
  550. uint8_t name[sizeof (struct lpfc_name)];
  551. uint32_t rc;
  552. /* Fabric nodes can have the same WWPN so we don't bother searching
  553. * by WWPN. Just return the ndlp that was given to us.
  554. */
  555. if (ndlp->nlp_type & NLP_FABRIC)
  556. return ndlp;
  557. lp = (uint32_t *) prsp->virt;
  558. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  559. memset(name, 0, sizeof (struct lpfc_name));
  560. /* Now we to find out if the NPort we are logging into, matches the WWPN
  561. * we have for that ndlp. If not, we have some work to do.
  562. */
  563. new_ndlp = lpfc_findnode_wwpn(phba, NLP_SEARCH_ALL, &sp->portName);
  564. if (new_ndlp == ndlp)
  565. return ndlp;
  566. if (!new_ndlp) {
  567. rc =
  568. memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name));
  569. if (!rc)
  570. return ndlp;
  571. new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
  572. if (!new_ndlp)
  573. return ndlp;
  574. lpfc_nlp_init(phba, new_ndlp, ndlp->nlp_DID);
  575. }
  576. lpfc_unreg_rpi(phba, new_ndlp);
  577. new_ndlp->nlp_DID = ndlp->nlp_DID;
  578. new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
  579. lpfc_nlp_set_state(phba, new_ndlp, ndlp->nlp_state);
  580. /* Move this back to NPR list */
  581. if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
  582. lpfc_drop_node(phba, ndlp);
  583. else {
  584. lpfc_unreg_rpi(phba, ndlp);
  585. ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
  586. lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
  587. }
  588. return new_ndlp;
  589. }
  590. static void
  591. lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  592. struct lpfc_iocbq * rspiocb)
  593. {
  594. IOCB_t *irsp;
  595. struct lpfc_nodelist *ndlp;
  596. struct lpfc_dmabuf *prsp;
  597. int disc, rc, did, type;
  598. /* we pass cmdiocb to state machine which needs rspiocb as well */
  599. cmdiocb->context_un.rsp_iocb = rspiocb;
  600. irsp = &rspiocb->iocb;
  601. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL,
  602. irsp->un.elsreq64.remoteID);
  603. if (!ndlp)
  604. goto out;
  605. /* Since ndlp can be freed in the disc state machine, note if this node
  606. * is being used during discovery.
  607. */
  608. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  609. spin_lock_irq(phba->host->host_lock);
  610. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  611. spin_unlock_irq(phba->host->host_lock);
  612. rc = 0;
  613. /* PLOGI completes to NPort <nlp_DID> */
  614. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  615. "%d:0102 PLOGI completes to NPort x%x "
  616. "Data: x%x x%x x%x x%x x%x\n",
  617. phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
  618. irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
  619. phba->num_disc_nodes);
  620. /* Check to see if link went down during discovery */
  621. if (lpfc_els_chk_latt(phba)) {
  622. spin_lock_irq(phba->host->host_lock);
  623. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  624. spin_unlock_irq(phba->host->host_lock);
  625. goto out;
  626. }
  627. /* ndlp could be freed in DSM, save these values now */
  628. type = ndlp->nlp_type;
  629. did = ndlp->nlp_DID;
  630. if (irsp->ulpStatus) {
  631. /* Check for retry */
  632. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  633. /* ELS command is being retried */
  634. if (disc) {
  635. spin_lock_irq(phba->host->host_lock);
  636. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  637. spin_unlock_irq(phba->host->host_lock);
  638. }
  639. goto out;
  640. }
  641. /* PLOGI failed */
  642. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  643. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  644. ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
  645. (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
  646. (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
  647. rc = NLP_STE_FREED_NODE;
  648. } else {
  649. rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
  650. NLP_EVT_CMPL_PLOGI);
  651. }
  652. } else {
  653. /* Good status, call state machine */
  654. prsp = list_entry(((struct lpfc_dmabuf *)
  655. cmdiocb->context2)->list.next,
  656. struct lpfc_dmabuf, list);
  657. ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp);
  658. rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
  659. NLP_EVT_CMPL_PLOGI);
  660. }
  661. if (disc && phba->num_disc_nodes) {
  662. /* Check to see if there are more PLOGIs to be sent */
  663. lpfc_more_plogi(phba);
  664. if (phba->num_disc_nodes == 0) {
  665. spin_lock_irq(phba->host->host_lock);
  666. phba->fc_flag &= ~FC_NDISC_ACTIVE;
  667. spin_unlock_irq(phba->host->host_lock);
  668. lpfc_can_disctmo(phba);
  669. if (phba->fc_flag & FC_RSCN_MODE) {
  670. /*
  671. * Check to see if more RSCNs came in while
  672. * we were processing this one.
  673. */
  674. if ((phba->fc_rscn_id_cnt == 0) &&
  675. (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
  676. spin_lock_irq(phba->host->host_lock);
  677. phba->fc_flag &= ~FC_RSCN_MODE;
  678. spin_unlock_irq(phba->host->host_lock);
  679. } else {
  680. lpfc_els_handle_rscn(phba);
  681. }
  682. }
  683. }
  684. }
  685. out:
  686. lpfc_els_free_iocb(phba, cmdiocb);
  687. return;
  688. }
  689. int
  690. lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
  691. {
  692. struct serv_parm *sp;
  693. IOCB_t *icmd;
  694. struct lpfc_iocbq *elsiocb;
  695. struct lpfc_sli_ring *pring;
  696. struct lpfc_sli *psli;
  697. uint8_t *pcmd;
  698. uint16_t cmdsize;
  699. psli = &phba->sli;
  700. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  701. cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
  702. elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, NULL, did,
  703. ELS_CMD_PLOGI);
  704. if (!elsiocb)
  705. return 1;
  706. icmd = &elsiocb->iocb;
  707. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  708. /* For PLOGI request, remainder of payload is service parameters */
  709. *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
  710. pcmd += sizeof (uint32_t);
  711. memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
  712. sp = (struct serv_parm *) pcmd;
  713. if (sp->cmn.fcphLow < FC_PH_4_3)
  714. sp->cmn.fcphLow = FC_PH_4_3;
  715. if (sp->cmn.fcphHigh < FC_PH3)
  716. sp->cmn.fcphHigh = FC_PH3;
  717. phba->fc_stat.elsXmitPLOGI++;
  718. elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
  719. spin_lock_irq(phba->host->host_lock);
  720. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  721. spin_unlock_irq(phba->host->host_lock);
  722. lpfc_els_free_iocb(phba, elsiocb);
  723. return 1;
  724. }
  725. spin_unlock_irq(phba->host->host_lock);
  726. return 0;
  727. }
  728. static void
  729. lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  730. struct lpfc_iocbq * rspiocb)
  731. {
  732. IOCB_t *irsp;
  733. struct lpfc_sli *psli;
  734. struct lpfc_nodelist *ndlp;
  735. psli = &phba->sli;
  736. /* we pass cmdiocb to state machine which needs rspiocb as well */
  737. cmdiocb->context_un.rsp_iocb = rspiocb;
  738. irsp = &(rspiocb->iocb);
  739. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  740. spin_lock_irq(phba->host->host_lock);
  741. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  742. spin_unlock_irq(phba->host->host_lock);
  743. /* PRLI completes to NPort <nlp_DID> */
  744. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  745. "%d:0103 PRLI completes to NPort x%x "
  746. "Data: x%x x%x x%x x%x\n",
  747. phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
  748. irsp->un.ulpWord[4], irsp->ulpTimeout,
  749. phba->num_disc_nodes);
  750. phba->fc_prli_sent--;
  751. /* Check to see if link went down during discovery */
  752. if (lpfc_els_chk_latt(phba))
  753. goto out;
  754. if (irsp->ulpStatus) {
  755. /* Check for retry */
  756. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  757. /* ELS command is being retried */
  758. goto out;
  759. }
  760. /* PRLI failed */
  761. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  762. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  763. ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
  764. (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
  765. (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
  766. goto out;
  767. } else {
  768. lpfc_disc_state_machine(phba, ndlp, cmdiocb,
  769. NLP_EVT_CMPL_PRLI);
  770. }
  771. } else {
  772. /* Good status, call state machine */
  773. lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
  774. }
  775. out:
  776. lpfc_els_free_iocb(phba, cmdiocb);
  777. return;
  778. }
  779. int
  780. lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  781. uint8_t retry)
  782. {
  783. PRLI *npr;
  784. IOCB_t *icmd;
  785. struct lpfc_iocbq *elsiocb;
  786. struct lpfc_sli_ring *pring;
  787. struct lpfc_sli *psli;
  788. uint8_t *pcmd;
  789. uint16_t cmdsize;
  790. psli = &phba->sli;
  791. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  792. cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
  793. elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
  794. ndlp->nlp_DID, ELS_CMD_PRLI);
  795. if (!elsiocb)
  796. return 1;
  797. icmd = &elsiocb->iocb;
  798. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  799. /* For PRLI request, remainder of payload is service parameters */
  800. memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
  801. *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
  802. pcmd += sizeof (uint32_t);
  803. /* For PRLI, remainder of payload is PRLI parameter page */
  804. npr = (PRLI *) pcmd;
  805. /*
  806. * If our firmware version is 3.20 or later,
  807. * set the following bits for FC-TAPE support.
  808. */
  809. if (phba->vpd.rev.feaLevelHigh >= 0x02) {
  810. npr->ConfmComplAllowed = 1;
  811. npr->Retry = 1;
  812. npr->TaskRetryIdReq = 1;
  813. }
  814. npr->estabImagePair = 1;
  815. npr->readXferRdyDis = 1;
  816. /* For FCP support */
  817. npr->prliType = PRLI_FCP_TYPE;
  818. npr->initiatorFunc = 1;
  819. phba->fc_stat.elsXmitPRLI++;
  820. elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
  821. spin_lock_irq(phba->host->host_lock);
  822. ndlp->nlp_flag |= NLP_PRLI_SND;
  823. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  824. ndlp->nlp_flag &= ~NLP_PRLI_SND;
  825. spin_unlock_irq(phba->host->host_lock);
  826. lpfc_els_free_iocb(phba, elsiocb);
  827. return 1;
  828. }
  829. spin_unlock_irq(phba->host->host_lock);
  830. phba->fc_prli_sent++;
  831. return 0;
  832. }
  833. static void
  834. lpfc_more_adisc(struct lpfc_hba * phba)
  835. {
  836. int sentadisc;
  837. if (phba->num_disc_nodes)
  838. phba->num_disc_nodes--;
  839. /* Continue discovery with <num_disc_nodes> ADISCs to go */
  840. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  841. "%d:0210 Continue discovery with %d ADISCs to go "
  842. "Data: x%x x%x x%x\n",
  843. phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
  844. phba->fc_flag, phba->hba_state);
  845. /* Check to see if there are more ADISCs to be sent */
  846. if (phba->fc_flag & FC_NLP_MORE) {
  847. lpfc_set_disctmo(phba);
  848. /* go thru NPR list and issue any remaining ELS ADISCs */
  849. sentadisc = lpfc_els_disc_adisc(phba);
  850. }
  851. return;
  852. }
  853. static void
  854. lpfc_rscn_disc(struct lpfc_hba * phba)
  855. {
  856. /* RSCN discovery */
  857. /* go thru NPR list and issue ELS PLOGIs */
  858. if (phba->fc_npr_cnt) {
  859. if (lpfc_els_disc_plogi(phba))
  860. return;
  861. }
  862. if (phba->fc_flag & FC_RSCN_MODE) {
  863. /* Check to see if more RSCNs came in while we were
  864. * processing this one.
  865. */
  866. if ((phba->fc_rscn_id_cnt == 0) &&
  867. (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
  868. spin_lock_irq(phba->host->host_lock);
  869. phba->fc_flag &= ~FC_RSCN_MODE;
  870. spin_unlock_irq(phba->host->host_lock);
  871. } else {
  872. lpfc_els_handle_rscn(phba);
  873. }
  874. }
  875. }
  876. static void
  877. lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  878. struct lpfc_iocbq * rspiocb)
  879. {
  880. IOCB_t *irsp;
  881. struct lpfc_sli *psli;
  882. struct lpfc_nodelist *ndlp;
  883. LPFC_MBOXQ_t *mbox;
  884. int disc, rc;
  885. psli = &phba->sli;
  886. /* we pass cmdiocb to state machine which needs rspiocb as well */
  887. cmdiocb->context_un.rsp_iocb = rspiocb;
  888. irsp = &(rspiocb->iocb);
  889. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  890. /* Since ndlp can be freed in the disc state machine, note if this node
  891. * is being used during discovery.
  892. */
  893. disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
  894. spin_lock_irq(phba->host->host_lock);
  895. ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
  896. spin_unlock_irq(phba->host->host_lock);
  897. /* ADISC completes to NPort <nlp_DID> */
  898. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  899. "%d:0104 ADISC completes to NPort x%x "
  900. "Data: x%x x%x x%x x%x x%x\n",
  901. phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
  902. irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
  903. phba->num_disc_nodes);
  904. /* Check to see if link went down during discovery */
  905. if (lpfc_els_chk_latt(phba)) {
  906. spin_lock_irq(phba->host->host_lock);
  907. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  908. spin_unlock_irq(phba->host->host_lock);
  909. goto out;
  910. }
  911. if (irsp->ulpStatus) {
  912. /* Check for retry */
  913. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  914. /* ELS command is being retried */
  915. if (disc) {
  916. spin_lock_irq(phba->host->host_lock);
  917. ndlp->nlp_flag |= NLP_NPR_2B_DISC;
  918. spin_unlock_irq(phba->host->host_lock);
  919. lpfc_set_disctmo(phba);
  920. }
  921. goto out;
  922. }
  923. /* ADISC failed */
  924. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  925. if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  926. ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
  927. (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
  928. (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
  929. lpfc_disc_state_machine(phba, ndlp, cmdiocb,
  930. NLP_EVT_CMPL_ADISC);
  931. }
  932. } else {
  933. /* Good status, call state machine */
  934. lpfc_disc_state_machine(phba, ndlp, cmdiocb,
  935. NLP_EVT_CMPL_ADISC);
  936. }
  937. if (disc && phba->num_disc_nodes) {
  938. /* Check to see if there are more ADISCs to be sent */
  939. lpfc_more_adisc(phba);
  940. /* Check to see if we are done with ADISC authentication */
  941. if (phba->num_disc_nodes == 0) {
  942. lpfc_can_disctmo(phba);
  943. /* If we get here, there is nothing left to wait for */
  944. if ((phba->hba_state < LPFC_HBA_READY) &&
  945. (phba->hba_state != LPFC_CLEAR_LA)) {
  946. /* Link up discovery */
  947. if ((mbox = mempool_alloc(phba->mbox_mem_pool,
  948. GFP_KERNEL))) {
  949. phba->hba_state = LPFC_CLEAR_LA;
  950. lpfc_clear_la(phba, mbox);
  951. mbox->mbox_cmpl =
  952. lpfc_mbx_cmpl_clear_la;
  953. rc = lpfc_sli_issue_mbox
  954. (phba, mbox,
  955. (MBX_NOWAIT | MBX_STOP_IOCB));
  956. if (rc == MBX_NOT_FINISHED) {
  957. mempool_free(mbox,
  958. phba->mbox_mem_pool);
  959. lpfc_disc_flush_list(phba);
  960. psli->ring[(psli->extra_ring)].
  961. flag &=
  962. ~LPFC_STOP_IOCB_EVENT;
  963. psli->ring[(psli->fcp_ring)].
  964. flag &=
  965. ~LPFC_STOP_IOCB_EVENT;
  966. psli->ring[(psli->next_ring)].
  967. flag &=
  968. ~LPFC_STOP_IOCB_EVENT;
  969. phba->hba_state =
  970. LPFC_HBA_READY;
  971. }
  972. }
  973. } else {
  974. lpfc_rscn_disc(phba);
  975. }
  976. }
  977. }
  978. out:
  979. lpfc_els_free_iocb(phba, cmdiocb);
  980. return;
  981. }
  982. int
  983. lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  984. uint8_t retry)
  985. {
  986. ADISC *ap;
  987. IOCB_t *icmd;
  988. struct lpfc_iocbq *elsiocb;
  989. struct lpfc_sli_ring *pring;
  990. struct lpfc_sli *psli;
  991. uint8_t *pcmd;
  992. uint16_t cmdsize;
  993. psli = &phba->sli;
  994. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  995. cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
  996. elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
  997. ndlp->nlp_DID, ELS_CMD_ADISC);
  998. if (!elsiocb)
  999. return 1;
  1000. icmd = &elsiocb->iocb;
  1001. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1002. /* For ADISC request, remainder of payload is service parameters */
  1003. *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
  1004. pcmd += sizeof (uint32_t);
  1005. /* Fill in ADISC payload */
  1006. ap = (ADISC *) pcmd;
  1007. ap->hardAL_PA = phba->fc_pref_ALPA;
  1008. memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
  1009. memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
  1010. ap->DID = be32_to_cpu(phba->fc_myDID);
  1011. phba->fc_stat.elsXmitADISC++;
  1012. elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
  1013. spin_lock_irq(phba->host->host_lock);
  1014. ndlp->nlp_flag |= NLP_ADISC_SND;
  1015. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1016. ndlp->nlp_flag &= ~NLP_ADISC_SND;
  1017. spin_unlock_irq(phba->host->host_lock);
  1018. lpfc_els_free_iocb(phba, elsiocb);
  1019. return 1;
  1020. }
  1021. spin_unlock_irq(phba->host->host_lock);
  1022. return 0;
  1023. }
  1024. static void
  1025. lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  1026. struct lpfc_iocbq * rspiocb)
  1027. {
  1028. IOCB_t *irsp;
  1029. struct lpfc_sli *psli;
  1030. struct lpfc_nodelist *ndlp;
  1031. psli = &phba->sli;
  1032. /* we pass cmdiocb to state machine which needs rspiocb as well */
  1033. cmdiocb->context_un.rsp_iocb = rspiocb;
  1034. irsp = &(rspiocb->iocb);
  1035. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1036. spin_lock_irq(phba->host->host_lock);
  1037. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1038. spin_unlock_irq(phba->host->host_lock);
  1039. /* LOGO completes to NPort <nlp_DID> */
  1040. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1041. "%d:0105 LOGO completes to NPort x%x "
  1042. "Data: x%x x%x x%x x%x\n",
  1043. phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
  1044. irsp->un.ulpWord[4], irsp->ulpTimeout,
  1045. phba->num_disc_nodes);
  1046. /* Check to see if link went down during discovery */
  1047. if (lpfc_els_chk_latt(phba))
  1048. goto out;
  1049. if (irsp->ulpStatus) {
  1050. /* Check for retry */
  1051. if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
  1052. /* ELS command is being retried */
  1053. goto out;
  1054. }
  1055. /* LOGO failed */
  1056. /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
  1057. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  1058. ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
  1059. (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
  1060. (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
  1061. goto out;
  1062. } else {
  1063. lpfc_disc_state_machine(phba, ndlp, cmdiocb,
  1064. NLP_EVT_CMPL_LOGO);
  1065. }
  1066. } else {
  1067. /* Good status, call state machine.
  1068. * This will unregister the rpi if needed.
  1069. */
  1070. lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
  1071. }
  1072. out:
  1073. lpfc_els_free_iocb(phba, cmdiocb);
  1074. return;
  1075. }
  1076. int
  1077. lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  1078. uint8_t retry)
  1079. {
  1080. IOCB_t *icmd;
  1081. struct lpfc_iocbq *elsiocb;
  1082. struct lpfc_sli_ring *pring;
  1083. struct lpfc_sli *psli;
  1084. uint8_t *pcmd;
  1085. uint16_t cmdsize;
  1086. psli = &phba->sli;
  1087. pring = &psli->ring[LPFC_ELS_RING];
  1088. cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name);
  1089. elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
  1090. ndlp->nlp_DID, ELS_CMD_LOGO);
  1091. if (!elsiocb)
  1092. return 1;
  1093. icmd = &elsiocb->iocb;
  1094. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1095. *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
  1096. pcmd += sizeof (uint32_t);
  1097. /* Fill in LOGO payload */
  1098. *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
  1099. pcmd += sizeof (uint32_t);
  1100. memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
  1101. phba->fc_stat.elsXmitLOGO++;
  1102. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
  1103. spin_lock_irq(phba->host->host_lock);
  1104. ndlp->nlp_flag |= NLP_LOGO_SND;
  1105. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1106. ndlp->nlp_flag &= ~NLP_LOGO_SND;
  1107. spin_unlock_irq(phba->host->host_lock);
  1108. lpfc_els_free_iocb(phba, elsiocb);
  1109. return 1;
  1110. }
  1111. spin_unlock_irq(phba->host->host_lock);
  1112. return 0;
  1113. }
  1114. static void
  1115. lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  1116. struct lpfc_iocbq * rspiocb)
  1117. {
  1118. IOCB_t *irsp;
  1119. irsp = &rspiocb->iocb;
  1120. /* ELS cmd tag <ulpIoTag> completes */
  1121. lpfc_printf_log(phba,
  1122. KERN_INFO,
  1123. LOG_ELS,
  1124. "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
  1125. phba->brd_no,
  1126. irsp->ulpIoTag, irsp->ulpStatus,
  1127. irsp->un.ulpWord[4], irsp->ulpTimeout);
  1128. /* Check to see if link went down during discovery */
  1129. lpfc_els_chk_latt(phba);
  1130. lpfc_els_free_iocb(phba, cmdiocb);
  1131. return;
  1132. }
  1133. int
  1134. lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
  1135. {
  1136. IOCB_t *icmd;
  1137. struct lpfc_iocbq *elsiocb;
  1138. struct lpfc_sli_ring *pring;
  1139. struct lpfc_sli *psli;
  1140. uint8_t *pcmd;
  1141. uint16_t cmdsize;
  1142. struct lpfc_nodelist *ndlp;
  1143. psli = &phba->sli;
  1144. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1145. cmdsize = (sizeof (uint32_t) + sizeof (SCR));
  1146. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1147. if (!ndlp)
  1148. return 1;
  1149. lpfc_nlp_init(phba, ndlp, nportid);
  1150. elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
  1151. ndlp->nlp_DID, ELS_CMD_SCR);
  1152. if (!elsiocb) {
  1153. mempool_free( ndlp, phba->nlp_mem_pool);
  1154. return 1;
  1155. }
  1156. icmd = &elsiocb->iocb;
  1157. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1158. *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
  1159. pcmd += sizeof (uint32_t);
  1160. /* For SCR, remainder of payload is SCR parameter page */
  1161. memset(pcmd, 0, sizeof (SCR));
  1162. ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
  1163. phba->fc_stat.elsXmitSCR++;
  1164. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1165. spin_lock_irq(phba->host->host_lock);
  1166. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1167. spin_unlock_irq(phba->host->host_lock);
  1168. mempool_free( ndlp, phba->nlp_mem_pool);
  1169. lpfc_els_free_iocb(phba, elsiocb);
  1170. return 1;
  1171. }
  1172. spin_unlock_irq(phba->host->host_lock);
  1173. mempool_free( ndlp, phba->nlp_mem_pool);
  1174. return 0;
  1175. }
  1176. static int
  1177. lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
  1178. {
  1179. IOCB_t *icmd;
  1180. struct lpfc_iocbq *elsiocb;
  1181. struct lpfc_sli_ring *pring;
  1182. struct lpfc_sli *psli;
  1183. FARP *fp;
  1184. uint8_t *pcmd;
  1185. uint32_t *lp;
  1186. uint16_t cmdsize;
  1187. struct lpfc_nodelist *ondlp;
  1188. struct lpfc_nodelist *ndlp;
  1189. psli = &phba->sli;
  1190. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1191. cmdsize = (sizeof (uint32_t) + sizeof (FARP));
  1192. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  1193. if (!ndlp)
  1194. return 1;
  1195. lpfc_nlp_init(phba, ndlp, nportid);
  1196. elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
  1197. ndlp->nlp_DID, ELS_CMD_RNID);
  1198. if (!elsiocb) {
  1199. mempool_free( ndlp, phba->nlp_mem_pool);
  1200. return 1;
  1201. }
  1202. icmd = &elsiocb->iocb;
  1203. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1204. *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
  1205. pcmd += sizeof (uint32_t);
  1206. /* Fill in FARPR payload */
  1207. fp = (FARP *) (pcmd);
  1208. memset(fp, 0, sizeof (FARP));
  1209. lp = (uint32_t *) pcmd;
  1210. *lp++ = be32_to_cpu(nportid);
  1211. *lp++ = be32_to_cpu(phba->fc_myDID);
  1212. fp->Rflags = 0;
  1213. fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
  1214. memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
  1215. memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
  1216. if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
  1217. memcpy(&fp->OportName, &ondlp->nlp_portname,
  1218. sizeof (struct lpfc_name));
  1219. memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
  1220. sizeof (struct lpfc_name));
  1221. }
  1222. phba->fc_stat.elsXmitFARPR++;
  1223. elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
  1224. spin_lock_irq(phba->host->host_lock);
  1225. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  1226. spin_unlock_irq(phba->host->host_lock);
  1227. mempool_free( ndlp, phba->nlp_mem_pool);
  1228. lpfc_els_free_iocb(phba, elsiocb);
  1229. return 1;
  1230. }
  1231. spin_unlock_irq(phba->host->host_lock);
  1232. mempool_free( ndlp, phba->nlp_mem_pool);
  1233. return 0;
  1234. }
  1235. void
  1236. lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp)
  1237. {
  1238. nlp->nlp_flag &= ~NLP_DELAY_TMO;
  1239. del_timer_sync(&nlp->nlp_delayfunc);
  1240. nlp->nlp_last_elscmd = 0;
  1241. if (!list_empty(&nlp->els_retry_evt.evt_listp))
  1242. list_del_init(&nlp->els_retry_evt.evt_listp);
  1243. if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
  1244. nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1245. if (phba->num_disc_nodes) {
  1246. /* Check to see if there are more
  1247. * PLOGIs to be sent
  1248. */
  1249. lpfc_more_plogi(phba);
  1250. if (phba->num_disc_nodes == 0) {
  1251. phba->fc_flag &= ~FC_NDISC_ACTIVE;
  1252. lpfc_can_disctmo(phba);
  1253. if (phba->fc_flag & FC_RSCN_MODE) {
  1254. /*
  1255. * Check to see if more RSCNs
  1256. * came in while we were
  1257. * processing this one.
  1258. */
  1259. if((phba->fc_rscn_id_cnt==0) &&
  1260. !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
  1261. phba->fc_flag &= ~FC_RSCN_MODE;
  1262. }
  1263. else {
  1264. lpfc_els_handle_rscn(phba);
  1265. }
  1266. }
  1267. }
  1268. }
  1269. }
  1270. return;
  1271. }
  1272. void
  1273. lpfc_els_retry_delay(unsigned long ptr)
  1274. {
  1275. struct lpfc_nodelist *ndlp;
  1276. struct lpfc_hba *phba;
  1277. unsigned long iflag;
  1278. struct lpfc_work_evt *evtp;
  1279. ndlp = (struct lpfc_nodelist *)ptr;
  1280. phba = ndlp->nlp_phba;
  1281. evtp = &ndlp->els_retry_evt;
  1282. spin_lock_irqsave(phba->host->host_lock, iflag);
  1283. if (!list_empty(&evtp->evt_listp)) {
  1284. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1285. return;
  1286. }
  1287. evtp->evt_arg1 = ndlp;
  1288. evtp->evt = LPFC_EVT_ELS_RETRY;
  1289. list_add_tail(&evtp->evt_listp, &phba->work_list);
  1290. if (phba->work_wait)
  1291. wake_up(phba->work_wait);
  1292. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1293. return;
  1294. }
  1295. void
  1296. lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
  1297. {
  1298. struct lpfc_hba *phba;
  1299. uint32_t cmd;
  1300. uint32_t did;
  1301. uint8_t retry;
  1302. phba = ndlp->nlp_phba;
  1303. spin_lock_irq(phba->host->host_lock);
  1304. did = ndlp->nlp_DID;
  1305. cmd = ndlp->nlp_last_elscmd;
  1306. ndlp->nlp_last_elscmd = 0;
  1307. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1308. spin_unlock_irq(phba->host->host_lock);
  1309. return;
  1310. }
  1311. ndlp->nlp_flag &= ~NLP_DELAY_TMO;
  1312. spin_unlock_irq(phba->host->host_lock);
  1313. /*
  1314. * If a discovery event readded nlp_delayfunc after timer
  1315. * firing and before processing the timer, cancel the
  1316. * nlp_delayfunc.
  1317. */
  1318. del_timer_sync(&ndlp->nlp_delayfunc);
  1319. retry = ndlp->nlp_retry;
  1320. switch (cmd) {
  1321. case ELS_CMD_FLOGI:
  1322. lpfc_issue_els_flogi(phba, ndlp, retry);
  1323. break;
  1324. case ELS_CMD_PLOGI:
  1325. if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) {
  1326. ndlp->nlp_prev_state = ndlp->nlp_state;
  1327. lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
  1328. }
  1329. break;
  1330. case ELS_CMD_ADISC:
  1331. if (!lpfc_issue_els_adisc(phba, ndlp, retry)) {
  1332. ndlp->nlp_prev_state = ndlp->nlp_state;
  1333. lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
  1334. }
  1335. break;
  1336. case ELS_CMD_PRLI:
  1337. if (!lpfc_issue_els_prli(phba, ndlp, retry)) {
  1338. ndlp->nlp_prev_state = ndlp->nlp_state;
  1339. lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
  1340. }
  1341. break;
  1342. case ELS_CMD_LOGO:
  1343. if (!lpfc_issue_els_logo(phba, ndlp, retry)) {
  1344. ndlp->nlp_prev_state = ndlp->nlp_state;
  1345. lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
  1346. }
  1347. break;
  1348. }
  1349. return;
  1350. }
  1351. static int
  1352. lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  1353. struct lpfc_iocbq * rspiocb)
  1354. {
  1355. IOCB_t *irsp;
  1356. struct lpfc_dmabuf *pcmd;
  1357. struct lpfc_nodelist *ndlp;
  1358. uint32_t *elscmd;
  1359. struct ls_rjt stat;
  1360. int retry, maxretry;
  1361. int delay;
  1362. uint32_t cmd;
  1363. uint32_t did;
  1364. retry = 0;
  1365. delay = 0;
  1366. maxretry = lpfc_max_els_tries;
  1367. irsp = &rspiocb->iocb;
  1368. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1369. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  1370. cmd = 0;
  1371. /* Note: context2 may be 0 for internal driver abort
  1372. * of delays ELS command.
  1373. */
  1374. if (pcmd && pcmd->virt) {
  1375. elscmd = (uint32_t *) (pcmd->virt);
  1376. cmd = *elscmd++;
  1377. }
  1378. if(ndlp)
  1379. did = ndlp->nlp_DID;
  1380. else {
  1381. /* We should only hit this case for retrying PLOGI */
  1382. did = irsp->un.elsreq64.remoteID;
  1383. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
  1384. if (!ndlp && (cmd != ELS_CMD_PLOGI))
  1385. return 1;
  1386. }
  1387. switch (irsp->ulpStatus) {
  1388. case IOSTAT_FCP_RSP_ERROR:
  1389. case IOSTAT_REMOTE_STOP:
  1390. break;
  1391. case IOSTAT_LOCAL_REJECT:
  1392. switch ((irsp->un.ulpWord[4] & 0xff)) {
  1393. case IOERR_LOOP_OPEN_FAILURE:
  1394. if (cmd == ELS_CMD_PLOGI) {
  1395. if (cmdiocb->retry == 0) {
  1396. delay = 1;
  1397. }
  1398. }
  1399. retry = 1;
  1400. break;
  1401. case IOERR_SEQUENCE_TIMEOUT:
  1402. retry = 1;
  1403. break;
  1404. case IOERR_NO_RESOURCES:
  1405. if (cmd == ELS_CMD_PLOGI) {
  1406. delay = 1;
  1407. }
  1408. retry = 1;
  1409. break;
  1410. case IOERR_INVALID_RPI:
  1411. retry = 1;
  1412. break;
  1413. }
  1414. break;
  1415. case IOSTAT_NPORT_RJT:
  1416. case IOSTAT_FABRIC_RJT:
  1417. if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
  1418. retry = 1;
  1419. break;
  1420. }
  1421. break;
  1422. case IOSTAT_NPORT_BSY:
  1423. case IOSTAT_FABRIC_BSY:
  1424. retry = 1;
  1425. break;
  1426. case IOSTAT_LS_RJT:
  1427. stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
  1428. /* Added for Vendor specifc support
  1429. * Just keep retrying for these Rsn / Exp codes
  1430. */
  1431. switch (stat.un.b.lsRjtRsnCode) {
  1432. case LSRJT_UNABLE_TPC:
  1433. if (stat.un.b.lsRjtRsnCodeExp ==
  1434. LSEXP_CMD_IN_PROGRESS) {
  1435. if (cmd == ELS_CMD_PLOGI) {
  1436. delay = 1;
  1437. maxretry = 48;
  1438. }
  1439. retry = 1;
  1440. break;
  1441. }
  1442. if (cmd == ELS_CMD_PLOGI) {
  1443. delay = 1;
  1444. maxretry = lpfc_max_els_tries + 1;
  1445. retry = 1;
  1446. break;
  1447. }
  1448. break;
  1449. case LSRJT_LOGICAL_BSY:
  1450. if (cmd == ELS_CMD_PLOGI) {
  1451. delay = 1;
  1452. maxretry = 48;
  1453. }
  1454. retry = 1;
  1455. break;
  1456. }
  1457. break;
  1458. case IOSTAT_INTERMED_RSP:
  1459. case IOSTAT_BA_RJT:
  1460. break;
  1461. default:
  1462. break;
  1463. }
  1464. if (did == FDMI_DID)
  1465. retry = 1;
  1466. if ((++cmdiocb->retry) >= maxretry) {
  1467. phba->fc_stat.elsRetryExceeded++;
  1468. retry = 0;
  1469. }
  1470. if (retry) {
  1471. /* Retry ELS command <elsCmd> to remote NPORT <did> */
  1472. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1473. "%d:0107 Retry ELS command x%x to remote "
  1474. "NPORT x%x Data: x%x x%x\n",
  1475. phba->brd_no,
  1476. cmd, did, cmdiocb->retry, delay);
  1477. if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
  1478. /* If discovery / RSCN timer is running, reset it */
  1479. if (timer_pending(&phba->fc_disctmo) ||
  1480. (phba->fc_flag & FC_RSCN_MODE)) {
  1481. lpfc_set_disctmo(phba);
  1482. }
  1483. }
  1484. phba->fc_stat.elsXmitRetry++;
  1485. if (ndlp && delay) {
  1486. phba->fc_stat.elsDelayRetry++;
  1487. ndlp->nlp_retry = cmdiocb->retry;
  1488. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  1489. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1490. ndlp->nlp_prev_state = ndlp->nlp_state;
  1491. lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
  1492. ndlp->nlp_last_elscmd = cmd;
  1493. return 1;
  1494. }
  1495. switch (cmd) {
  1496. case ELS_CMD_FLOGI:
  1497. lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
  1498. return 1;
  1499. case ELS_CMD_PLOGI:
  1500. if (ndlp) {
  1501. ndlp->nlp_prev_state = ndlp->nlp_state;
  1502. lpfc_nlp_set_state(phba, ndlp,
  1503. NLP_STE_PLOGI_ISSUE);
  1504. }
  1505. lpfc_issue_els_plogi(phba, did, cmdiocb->retry);
  1506. return 1;
  1507. case ELS_CMD_ADISC:
  1508. ndlp->nlp_prev_state = ndlp->nlp_state;
  1509. lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
  1510. lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
  1511. return 1;
  1512. case ELS_CMD_PRLI:
  1513. ndlp->nlp_prev_state = ndlp->nlp_state;
  1514. lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
  1515. lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
  1516. return 1;
  1517. case ELS_CMD_LOGO:
  1518. ndlp->nlp_prev_state = ndlp->nlp_state;
  1519. lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
  1520. lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
  1521. return 1;
  1522. }
  1523. }
  1524. /* No retry ELS command <elsCmd> to remote NPORT <did> */
  1525. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1526. "%d:0108 No retry ELS command x%x to remote NPORT x%x "
  1527. "Data: x%x\n",
  1528. phba->brd_no,
  1529. cmd, did, cmdiocb->retry);
  1530. return 0;
  1531. }
  1532. int
  1533. lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
  1534. {
  1535. struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
  1536. /* context2 = cmd, context2->next = rsp, context3 = bpl */
  1537. if (elsiocb->context2) {
  1538. buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
  1539. /* Free the response before processing the command. */
  1540. if (!list_empty(&buf_ptr1->list)) {
  1541. list_remove_head(&buf_ptr1->list, buf_ptr,
  1542. struct lpfc_dmabuf,
  1543. list);
  1544. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1545. kfree(buf_ptr);
  1546. }
  1547. lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
  1548. kfree(buf_ptr1);
  1549. }
  1550. if (elsiocb->context3) {
  1551. buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
  1552. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  1553. kfree(buf_ptr);
  1554. }
  1555. spin_lock_irq(phba->host->host_lock);
  1556. lpfc_sli_release_iocbq(phba, elsiocb);
  1557. spin_unlock_irq(phba->host->host_lock);
  1558. return 0;
  1559. }
  1560. static void
  1561. lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  1562. struct lpfc_iocbq * rspiocb)
  1563. {
  1564. struct lpfc_nodelist *ndlp;
  1565. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1566. /* ACC to LOGO completes to NPort <nlp_DID> */
  1567. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1568. "%d:0109 ACC to LOGO completes to NPort x%x "
  1569. "Data: x%x x%x x%x\n",
  1570. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  1571. ndlp->nlp_state, ndlp->nlp_rpi);
  1572. switch (ndlp->nlp_state) {
  1573. case NLP_STE_UNUSED_NODE: /* node is just allocated */
  1574. lpfc_drop_node(phba, ndlp);
  1575. break;
  1576. case NLP_STE_NPR_NODE: /* NPort Recovery mode */
  1577. lpfc_unreg_rpi(phba, ndlp);
  1578. break;
  1579. default:
  1580. break;
  1581. }
  1582. lpfc_els_free_iocb(phba, cmdiocb);
  1583. return;
  1584. }
  1585. static void
  1586. lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  1587. struct lpfc_iocbq * rspiocb)
  1588. {
  1589. IOCB_t *irsp;
  1590. struct lpfc_nodelist *ndlp;
  1591. LPFC_MBOXQ_t *mbox = NULL;
  1592. struct lpfc_dmabuf *mp;
  1593. irsp = &rspiocb->iocb;
  1594. ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
  1595. if (cmdiocb->context_un.mbox)
  1596. mbox = cmdiocb->context_un.mbox;
  1597. /* Check to see if link went down during discovery */
  1598. if ((lpfc_els_chk_latt(phba)) || !ndlp) {
  1599. if (mbox) {
  1600. mp = (struct lpfc_dmabuf *) mbox->context1;
  1601. if (mp) {
  1602. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1603. kfree(mp);
  1604. }
  1605. mempool_free( mbox, phba->mbox_mem_pool);
  1606. }
  1607. goto out;
  1608. }
  1609. /* ELS response tag <ulpIoTag> completes */
  1610. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1611. "%d:0110 ELS response tag x%x completes "
  1612. "Data: x%x x%x x%x x%x x%x x%x x%x\n",
  1613. phba->brd_no,
  1614. cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
  1615. rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
  1616. ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
  1617. ndlp->nlp_rpi);
  1618. if (mbox) {
  1619. if ((rspiocb->iocb.ulpStatus == 0)
  1620. && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
  1621. lpfc_unreg_rpi(phba, ndlp);
  1622. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  1623. mbox->context2 = ndlp;
  1624. ndlp->nlp_prev_state = ndlp->nlp_state;
  1625. lpfc_nlp_set_state(phba, ndlp, NLP_STE_REG_LOGIN_ISSUE);
  1626. if (lpfc_sli_issue_mbox(phba, mbox,
  1627. (MBX_NOWAIT | MBX_STOP_IOCB))
  1628. != MBX_NOT_FINISHED) {
  1629. goto out;
  1630. }
  1631. /* NOTE: we should have messages for unsuccessful
  1632. reglogin */
  1633. } else {
  1634. /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */
  1635. if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  1636. ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
  1637. (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
  1638. (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) {
  1639. if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  1640. lpfc_drop_node(phba, ndlp);
  1641. ndlp = NULL;
  1642. }
  1643. }
  1644. }
  1645. mp = (struct lpfc_dmabuf *) mbox->context1;
  1646. if (mp) {
  1647. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1648. kfree(mp);
  1649. }
  1650. mempool_free(mbox, phba->mbox_mem_pool);
  1651. }
  1652. out:
  1653. if (ndlp) {
  1654. spin_lock_irq(phba->host->host_lock);
  1655. ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
  1656. spin_unlock_irq(phba->host->host_lock);
  1657. }
  1658. lpfc_els_free_iocb(phba, cmdiocb);
  1659. return;
  1660. }
  1661. int
  1662. lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
  1663. struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
  1664. LPFC_MBOXQ_t * mbox, uint8_t newnode)
  1665. {
  1666. IOCB_t *icmd;
  1667. IOCB_t *oldcmd;
  1668. struct lpfc_iocbq *elsiocb;
  1669. struct lpfc_sli_ring *pring;
  1670. struct lpfc_sli *psli;
  1671. uint8_t *pcmd;
  1672. uint16_t cmdsize;
  1673. int rc;
  1674. ELS_PKT *els_pkt_ptr;
  1675. psli = &phba->sli;
  1676. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1677. oldcmd = &oldiocb->iocb;
  1678. switch (flag) {
  1679. case ELS_CMD_ACC:
  1680. cmdsize = sizeof (uint32_t);
  1681. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
  1682. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  1683. if (!elsiocb) {
  1684. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  1685. return 1;
  1686. }
  1687. icmd = &elsiocb->iocb;
  1688. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1689. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1690. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  1691. pcmd += sizeof (uint32_t);
  1692. break;
  1693. case ELS_CMD_PLOGI:
  1694. cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
  1695. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
  1696. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  1697. if (!elsiocb)
  1698. return 1;
  1699. icmd = &elsiocb->iocb;
  1700. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1701. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1702. if (mbox)
  1703. elsiocb->context_un.mbox = mbox;
  1704. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  1705. pcmd += sizeof (uint32_t);
  1706. memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
  1707. break;
  1708. case ELS_CMD_PRLO:
  1709. cmdsize = sizeof (uint32_t) + sizeof (PRLO);
  1710. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
  1711. ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
  1712. if (!elsiocb)
  1713. return 1;
  1714. icmd = &elsiocb->iocb;
  1715. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1716. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1717. memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
  1718. sizeof (uint32_t) + sizeof (PRLO));
  1719. *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
  1720. els_pkt_ptr = (ELS_PKT *) pcmd;
  1721. els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
  1722. break;
  1723. default:
  1724. return 1;
  1725. }
  1726. if (newnode)
  1727. elsiocb->context1 = NULL;
  1728. /* Xmit ELS ACC response tag <ulpIoTag> */
  1729. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1730. "%d:0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
  1731. "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
  1732. phba->brd_no, elsiocb->iotag,
  1733. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  1734. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  1735. if (ndlp->nlp_flag & NLP_LOGO_ACC) {
  1736. spin_lock_irq(phba->host->host_lock);
  1737. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  1738. spin_unlock_irq(phba->host->host_lock);
  1739. elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
  1740. } else {
  1741. elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
  1742. }
  1743. phba->fc_stat.elsXmitACC++;
  1744. spin_lock_irq(phba->host->host_lock);
  1745. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1746. spin_unlock_irq(phba->host->host_lock);
  1747. if (rc == IOCB_ERROR) {
  1748. lpfc_els_free_iocb(phba, elsiocb);
  1749. return 1;
  1750. }
  1751. return 0;
  1752. }
  1753. int
  1754. lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
  1755. struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
  1756. {
  1757. IOCB_t *icmd;
  1758. IOCB_t *oldcmd;
  1759. struct lpfc_iocbq *elsiocb;
  1760. struct lpfc_sli_ring *pring;
  1761. struct lpfc_sli *psli;
  1762. uint8_t *pcmd;
  1763. uint16_t cmdsize;
  1764. int rc;
  1765. psli = &phba->sli;
  1766. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1767. cmdsize = 2 * sizeof (uint32_t);
  1768. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
  1769. ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
  1770. if (!elsiocb)
  1771. return 1;
  1772. icmd = &elsiocb->iocb;
  1773. oldcmd = &oldiocb->iocb;
  1774. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1775. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1776. *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
  1777. pcmd += sizeof (uint32_t);
  1778. *((uint32_t *) (pcmd)) = rejectError;
  1779. /* Xmit ELS RJT <err> response tag <ulpIoTag> */
  1780. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1781. "%d:0129 Xmit ELS RJT x%x response tag x%x xri x%x, "
  1782. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  1783. phba->brd_no, rejectError, elsiocb->iotag,
  1784. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  1785. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  1786. phba->fc_stat.elsXmitLSRJT++;
  1787. elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
  1788. spin_lock_irq(phba->host->host_lock);
  1789. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1790. spin_unlock_irq(phba->host->host_lock);
  1791. if (rc == IOCB_ERROR) {
  1792. lpfc_els_free_iocb(phba, elsiocb);
  1793. return 1;
  1794. }
  1795. return 0;
  1796. }
  1797. int
  1798. lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
  1799. struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
  1800. {
  1801. ADISC *ap;
  1802. IOCB_t *icmd;
  1803. IOCB_t *oldcmd;
  1804. struct lpfc_iocbq *elsiocb;
  1805. struct lpfc_sli_ring *pring;
  1806. struct lpfc_sli *psli;
  1807. uint8_t *pcmd;
  1808. uint16_t cmdsize;
  1809. int rc;
  1810. psli = &phba->sli;
  1811. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1812. cmdsize = sizeof (uint32_t) + sizeof (ADISC);
  1813. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
  1814. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  1815. if (!elsiocb)
  1816. return 1;
  1817. icmd = &elsiocb->iocb;
  1818. oldcmd = &oldiocb->iocb;
  1819. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1820. /* Xmit ADISC ACC response tag <ulpIoTag> */
  1821. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1822. "%d:0130 Xmit ADISC ACC response iotag x%x xri: "
  1823. "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
  1824. phba->brd_no, elsiocb->iotag,
  1825. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  1826. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  1827. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1828. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  1829. pcmd += sizeof (uint32_t);
  1830. ap = (ADISC *) (pcmd);
  1831. ap->hardAL_PA = phba->fc_pref_ALPA;
  1832. memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
  1833. memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
  1834. ap->DID = be32_to_cpu(phba->fc_myDID);
  1835. phba->fc_stat.elsXmitACC++;
  1836. elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
  1837. spin_lock_irq(phba->host->host_lock);
  1838. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1839. spin_unlock_irq(phba->host->host_lock);
  1840. if (rc == IOCB_ERROR) {
  1841. lpfc_els_free_iocb(phba, elsiocb);
  1842. return 1;
  1843. }
  1844. return 0;
  1845. }
  1846. int
  1847. lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb,
  1848. struct lpfc_nodelist *ndlp)
  1849. {
  1850. PRLI *npr;
  1851. lpfc_vpd_t *vpd;
  1852. IOCB_t *icmd;
  1853. IOCB_t *oldcmd;
  1854. struct lpfc_iocbq *elsiocb;
  1855. struct lpfc_sli_ring *pring;
  1856. struct lpfc_sli *psli;
  1857. uint8_t *pcmd;
  1858. uint16_t cmdsize;
  1859. int rc;
  1860. psli = &phba->sli;
  1861. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  1862. cmdsize = sizeof (uint32_t) + sizeof (PRLI);
  1863. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp,
  1864. ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
  1865. if (!elsiocb)
  1866. return 1;
  1867. icmd = &elsiocb->iocb;
  1868. oldcmd = &oldiocb->iocb;
  1869. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1870. /* Xmit PRLI ACC response tag <ulpIoTag> */
  1871. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1872. "%d:0131 Xmit PRLI ACC response tag x%x xri x%x, "
  1873. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  1874. phba->brd_no, elsiocb->iotag,
  1875. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  1876. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  1877. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1878. *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
  1879. pcmd += sizeof (uint32_t);
  1880. /* For PRLI, remainder of payload is PRLI parameter page */
  1881. memset(pcmd, 0, sizeof (PRLI));
  1882. npr = (PRLI *) pcmd;
  1883. vpd = &phba->vpd;
  1884. /*
  1885. * If our firmware version is 3.20 or later,
  1886. * set the following bits for FC-TAPE support.
  1887. */
  1888. if (vpd->rev.feaLevelHigh >= 0x02) {
  1889. npr->ConfmComplAllowed = 1;
  1890. npr->Retry = 1;
  1891. npr->TaskRetryIdReq = 1;
  1892. }
  1893. npr->acceptRspCode = PRLI_REQ_EXECUTED;
  1894. npr->estabImagePair = 1;
  1895. npr->readXferRdyDis = 1;
  1896. npr->ConfmComplAllowed = 1;
  1897. npr->prliType = PRLI_FCP_TYPE;
  1898. npr->initiatorFunc = 1;
  1899. phba->fc_stat.elsXmitACC++;
  1900. elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
  1901. spin_lock_irq(phba->host->host_lock);
  1902. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1903. spin_unlock_irq(phba->host->host_lock);
  1904. if (rc == IOCB_ERROR) {
  1905. lpfc_els_free_iocb(phba, elsiocb);
  1906. return 1;
  1907. }
  1908. return 0;
  1909. }
  1910. static int
  1911. lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
  1912. uint8_t format,
  1913. struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
  1914. {
  1915. RNID *rn;
  1916. IOCB_t *icmd;
  1917. IOCB_t *oldcmd;
  1918. struct lpfc_iocbq *elsiocb;
  1919. struct lpfc_sli_ring *pring;
  1920. struct lpfc_sli *psli;
  1921. uint8_t *pcmd;
  1922. uint16_t cmdsize;
  1923. int rc;
  1924. psli = &phba->sli;
  1925. pring = &psli->ring[LPFC_ELS_RING];
  1926. cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
  1927. + (2 * sizeof (struct lpfc_name));
  1928. if (format)
  1929. cmdsize += sizeof (RNID_TOP_DISC);
  1930. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
  1931. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  1932. if (!elsiocb)
  1933. return 1;
  1934. icmd = &elsiocb->iocb;
  1935. oldcmd = &oldiocb->iocb;
  1936. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  1937. /* Xmit RNID ACC response tag <ulpIoTag> */
  1938. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  1939. "%d:0132 Xmit RNID ACC response tag x%x "
  1940. "xri x%x\n",
  1941. phba->brd_no, elsiocb->iotag,
  1942. elsiocb->iocb.ulpContext);
  1943. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  1944. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  1945. pcmd += sizeof (uint32_t);
  1946. memset(pcmd, 0, sizeof (RNID));
  1947. rn = (RNID *) (pcmd);
  1948. rn->Format = format;
  1949. rn->CommonLen = (2 * sizeof (struct lpfc_name));
  1950. memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
  1951. memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
  1952. switch (format) {
  1953. case 0:
  1954. rn->SpecificLen = 0;
  1955. break;
  1956. case RNID_TOPOLOGY_DISC:
  1957. rn->SpecificLen = sizeof (RNID_TOP_DISC);
  1958. memcpy(&rn->un.topologyDisc.portName,
  1959. &phba->fc_portname, sizeof (struct lpfc_name));
  1960. rn->un.topologyDisc.unitType = RNID_HBA;
  1961. rn->un.topologyDisc.physPort = 0;
  1962. rn->un.topologyDisc.attachedNodes = 0;
  1963. break;
  1964. default:
  1965. rn->CommonLen = 0;
  1966. rn->SpecificLen = 0;
  1967. break;
  1968. }
  1969. phba->fc_stat.elsXmitACC++;
  1970. elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
  1971. elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
  1972. * it could be freed */
  1973. spin_lock_irq(phba->host->host_lock);
  1974. rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
  1975. spin_unlock_irq(phba->host->host_lock);
  1976. if (rc == IOCB_ERROR) {
  1977. lpfc_els_free_iocb(phba, elsiocb);
  1978. return 1;
  1979. }
  1980. return 0;
  1981. }
  1982. int
  1983. lpfc_els_disc_adisc(struct lpfc_hba * phba)
  1984. {
  1985. int sentadisc;
  1986. struct lpfc_nodelist *ndlp, *next_ndlp;
  1987. sentadisc = 0;
  1988. /* go thru NPR list and issue any remaining ELS ADISCs */
  1989. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1990. nlp_listp) {
  1991. if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
  1992. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1993. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1994. ndlp->nlp_prev_state = ndlp->nlp_state;
  1995. lpfc_nlp_set_state(phba, ndlp,
  1996. NLP_STE_ADISC_ISSUE);
  1997. lpfc_issue_els_adisc(phba, ndlp, 0);
  1998. sentadisc++;
  1999. phba->num_disc_nodes++;
  2000. if (phba->num_disc_nodes >=
  2001. phba->cfg_discovery_threads) {
  2002. spin_lock_irq(phba->host->host_lock);
  2003. phba->fc_flag |= FC_NLP_MORE;
  2004. spin_unlock_irq(phba->host->host_lock);
  2005. break;
  2006. }
  2007. }
  2008. }
  2009. }
  2010. if (sentadisc == 0) {
  2011. spin_lock_irq(phba->host->host_lock);
  2012. phba->fc_flag &= ~FC_NLP_MORE;
  2013. spin_unlock_irq(phba->host->host_lock);
  2014. }
  2015. return sentadisc;
  2016. }
  2017. int
  2018. lpfc_els_disc_plogi(struct lpfc_hba * phba)
  2019. {
  2020. int sentplogi;
  2021. struct lpfc_nodelist *ndlp, *next_ndlp;
  2022. sentplogi = 0;
  2023. /* go thru NPR list and issue any remaining ELS PLOGIs */
  2024. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  2025. nlp_listp) {
  2026. if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
  2027. (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
  2028. if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  2029. ndlp->nlp_prev_state = ndlp->nlp_state;
  2030. lpfc_nlp_set_state(phba, ndlp,
  2031. NLP_STE_PLOGI_ISSUE);
  2032. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  2033. sentplogi++;
  2034. phba->num_disc_nodes++;
  2035. if (phba->num_disc_nodes >=
  2036. phba->cfg_discovery_threads) {
  2037. spin_lock_irq(phba->host->host_lock);
  2038. phba->fc_flag |= FC_NLP_MORE;
  2039. spin_unlock_irq(phba->host->host_lock);
  2040. break;
  2041. }
  2042. }
  2043. }
  2044. }
  2045. if (sentplogi == 0) {
  2046. spin_lock_irq(phba->host->host_lock);
  2047. phba->fc_flag &= ~FC_NLP_MORE;
  2048. spin_unlock_irq(phba->host->host_lock);
  2049. }
  2050. return sentplogi;
  2051. }
  2052. int
  2053. lpfc_els_flush_rscn(struct lpfc_hba * phba)
  2054. {
  2055. struct lpfc_dmabuf *mp;
  2056. int i;
  2057. for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
  2058. mp = phba->fc_rscn_id_list[i];
  2059. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2060. kfree(mp);
  2061. phba->fc_rscn_id_list[i] = NULL;
  2062. }
  2063. phba->fc_rscn_id_cnt = 0;
  2064. spin_lock_irq(phba->host->host_lock);
  2065. phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
  2066. spin_unlock_irq(phba->host->host_lock);
  2067. lpfc_can_disctmo(phba);
  2068. return 0;
  2069. }
  2070. int
  2071. lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
  2072. {
  2073. D_ID ns_did;
  2074. D_ID rscn_did;
  2075. struct lpfc_dmabuf *mp;
  2076. uint32_t *lp;
  2077. uint32_t payload_len, cmd, i, match;
  2078. ns_did.un.word = did;
  2079. match = 0;
  2080. /* Never match fabric nodes for RSCNs */
  2081. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
  2082. return(0);
  2083. /* If we are doing a FULL RSCN rediscovery, match everything */
  2084. if (phba->fc_flag & FC_RSCN_DISCOVERY) {
  2085. return did;
  2086. }
  2087. for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
  2088. mp = phba->fc_rscn_id_list[i];
  2089. lp = (uint32_t *) mp->virt;
  2090. cmd = *lp++;
  2091. payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
  2092. payload_len -= sizeof (uint32_t); /* take off word 0 */
  2093. while (payload_len) {
  2094. rscn_did.un.word = *lp++;
  2095. rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
  2096. payload_len -= sizeof (uint32_t);
  2097. switch (rscn_did.un.b.resv) {
  2098. case 0: /* Single N_Port ID effected */
  2099. if (ns_did.un.word == rscn_did.un.word) {
  2100. match = did;
  2101. }
  2102. break;
  2103. case 1: /* Whole N_Port Area effected */
  2104. if ((ns_did.un.b.domain == rscn_did.un.b.domain)
  2105. && (ns_did.un.b.area == rscn_did.un.b.area))
  2106. {
  2107. match = did;
  2108. }
  2109. break;
  2110. case 2: /* Whole N_Port Domain effected */
  2111. if (ns_did.un.b.domain == rscn_did.un.b.domain)
  2112. {
  2113. match = did;
  2114. }
  2115. break;
  2116. case 3: /* Whole Fabric effected */
  2117. match = did;
  2118. break;
  2119. default:
  2120. /* Unknown Identifier in RSCN list */
  2121. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  2122. "%d:0217 Unknown Identifier in "
  2123. "RSCN payload Data: x%x\n",
  2124. phba->brd_no, rscn_did.un.word);
  2125. break;
  2126. }
  2127. if (match) {
  2128. break;
  2129. }
  2130. }
  2131. }
  2132. return match;
  2133. }
  2134. static int
  2135. lpfc_rscn_recovery_check(struct lpfc_hba * phba)
  2136. {
  2137. struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
  2138. struct list_head *listp;
  2139. struct list_head *node_list[7];
  2140. int i;
  2141. /* Look at all nodes effected by pending RSCNs and move
  2142. * them to NPR list.
  2143. */
  2144. node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
  2145. node_list[1] = &phba->fc_nlpmap_list;
  2146. node_list[2] = &phba->fc_nlpunmap_list;
  2147. node_list[3] = &phba->fc_prli_list;
  2148. node_list[4] = &phba->fc_reglogin_list;
  2149. node_list[5] = &phba->fc_adisc_list;
  2150. node_list[6] = &phba->fc_plogi_list;
  2151. for (i = 0; i < 7; i++) {
  2152. listp = node_list[i];
  2153. if (list_empty(listp))
  2154. continue;
  2155. list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
  2156. if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID)))
  2157. continue;
  2158. lpfc_disc_state_machine(phba, ndlp, NULL,
  2159. NLP_EVT_DEVICE_RECOVERY);
  2160. /* Make sure NLP_DELAY_TMO is NOT running
  2161. * after a device recovery event.
  2162. */
  2163. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  2164. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  2165. }
  2166. }
  2167. return 0;
  2168. }
  2169. static int
  2170. lpfc_els_rcv_rscn(struct lpfc_hba * phba,
  2171. struct lpfc_iocbq * cmdiocb,
  2172. struct lpfc_nodelist * ndlp, uint8_t newnode)
  2173. {
  2174. struct lpfc_dmabuf *pcmd;
  2175. uint32_t *lp;
  2176. IOCB_t *icmd;
  2177. uint32_t payload_len, cmd;
  2178. int i;
  2179. icmd = &cmdiocb->iocb;
  2180. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2181. lp = (uint32_t *) pcmd->virt;
  2182. cmd = *lp++;
  2183. payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
  2184. payload_len -= sizeof (uint32_t); /* take off word 0 */
  2185. cmd &= ELS_CMD_MASK;
  2186. /* RSCN received */
  2187. lpfc_printf_log(phba,
  2188. KERN_INFO,
  2189. LOG_DISCOVERY,
  2190. "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
  2191. phba->brd_no,
  2192. phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
  2193. for (i = 0; i < payload_len/sizeof(uint32_t); i++)
  2194. fc_host_post_event(phba->host, fc_get_event_number(),
  2195. FCH_EVT_RSCN, lp[i]);
  2196. /* If we are about to begin discovery, just ACC the RSCN.
  2197. * Discovery processing will satisfy it.
  2198. */
  2199. if (phba->hba_state <= LPFC_NS_QRY) {
  2200. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
  2201. newnode);
  2202. return 0;
  2203. }
  2204. /* If we are already processing an RSCN, save the received
  2205. * RSCN payload buffer, cmdiocb->context2 to process later.
  2206. */
  2207. if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
  2208. if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
  2209. !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
  2210. spin_lock_irq(phba->host->host_lock);
  2211. phba->fc_flag |= FC_RSCN_MODE;
  2212. spin_unlock_irq(phba->host->host_lock);
  2213. phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
  2214. /* If we zero, cmdiocb->context2, the calling
  2215. * routine will not try to free it.
  2216. */
  2217. cmdiocb->context2 = NULL;
  2218. /* Deferred RSCN */
  2219. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  2220. "%d:0235 Deferred RSCN "
  2221. "Data: x%x x%x x%x\n",
  2222. phba->brd_no, phba->fc_rscn_id_cnt,
  2223. phba->fc_flag, phba->hba_state);
  2224. } else {
  2225. spin_lock_irq(phba->host->host_lock);
  2226. phba->fc_flag |= FC_RSCN_DISCOVERY;
  2227. spin_unlock_irq(phba->host->host_lock);
  2228. /* ReDiscovery RSCN */
  2229. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  2230. "%d:0234 ReDiscovery RSCN "
  2231. "Data: x%x x%x x%x\n",
  2232. phba->brd_no, phba->fc_rscn_id_cnt,
  2233. phba->fc_flag, phba->hba_state);
  2234. }
  2235. /* Send back ACC */
  2236. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
  2237. newnode);
  2238. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2239. lpfc_rscn_recovery_check(phba);
  2240. return 0;
  2241. }
  2242. phba->fc_flag |= FC_RSCN_MODE;
  2243. phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
  2244. /*
  2245. * If we zero, cmdiocb->context2, the calling routine will
  2246. * not try to free it.
  2247. */
  2248. cmdiocb->context2 = NULL;
  2249. lpfc_set_disctmo(phba);
  2250. /* Send back ACC */
  2251. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
  2252. /* send RECOVERY event for ALL nodes that match RSCN payload */
  2253. lpfc_rscn_recovery_check(phba);
  2254. return lpfc_els_handle_rscn(phba);
  2255. }
  2256. int
  2257. lpfc_els_handle_rscn(struct lpfc_hba * phba)
  2258. {
  2259. struct lpfc_nodelist *ndlp;
  2260. /* Start timer for RSCN processing */
  2261. lpfc_set_disctmo(phba);
  2262. /* RSCN processed */
  2263. lpfc_printf_log(phba,
  2264. KERN_INFO,
  2265. LOG_DISCOVERY,
  2266. "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
  2267. phba->brd_no,
  2268. phba->fc_flag, 0, phba->fc_rscn_id_cnt,
  2269. phba->hba_state);
  2270. /* To process RSCN, first compare RSCN data with NameServer */
  2271. phba->fc_ns_retry = 0;
  2272. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, NameServer_DID);
  2273. if (ndlp) {
  2274. /* Good ndlp, issue CT Request to NameServer */
  2275. if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
  2276. /* Wait for NameServer query cmpl before we can
  2277. continue */
  2278. return 1;
  2279. }
  2280. } else {
  2281. /* If login to NameServer does not exist, issue one */
  2282. /* Good status, issue PLOGI to NameServer */
  2283. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
  2284. if (ndlp) {
  2285. /* Wait for NameServer login cmpl before we can
  2286. continue */
  2287. return 1;
  2288. }
  2289. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2290. if (!ndlp) {
  2291. lpfc_els_flush_rscn(phba);
  2292. return 0;
  2293. } else {
  2294. lpfc_nlp_init(phba, ndlp, NameServer_DID);
  2295. ndlp->nlp_type |= NLP_FABRIC;
  2296. ndlp->nlp_prev_state = ndlp->nlp_state;
  2297. lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
  2298. lpfc_issue_els_plogi(phba, NameServer_DID, 0);
  2299. /* Wait for NameServer login cmpl before we can
  2300. continue */
  2301. return 1;
  2302. }
  2303. }
  2304. lpfc_els_flush_rscn(phba);
  2305. return 0;
  2306. }
  2307. static int
  2308. lpfc_els_rcv_flogi(struct lpfc_hba * phba,
  2309. struct lpfc_iocbq * cmdiocb,
  2310. struct lpfc_nodelist * ndlp, uint8_t newnode)
  2311. {
  2312. struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2313. uint32_t *lp = (uint32_t *) pcmd->virt;
  2314. IOCB_t *icmd = &cmdiocb->iocb;
  2315. struct serv_parm *sp;
  2316. LPFC_MBOXQ_t *mbox;
  2317. struct ls_rjt stat;
  2318. uint32_t cmd, did;
  2319. int rc;
  2320. cmd = *lp++;
  2321. sp = (struct serv_parm *) lp;
  2322. /* FLOGI received */
  2323. lpfc_set_disctmo(phba);
  2324. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2325. /* We should never receive a FLOGI in loop mode, ignore it */
  2326. did = icmd->un.elsreq64.remoteID;
  2327. /* An FLOGI ELS command <elsCmd> was received from DID <did> in
  2328. Loop Mode */
  2329. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  2330. "%d:0113 An FLOGI ELS command x%x was received "
  2331. "from DID x%x in Loop Mode\n",
  2332. phba->brd_no, cmd, did);
  2333. return 1;
  2334. }
  2335. did = Fabric_DID;
  2336. if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
  2337. /* For a FLOGI we accept, then if our portname is greater
  2338. * then the remote portname we initiate Nport login.
  2339. */
  2340. rc = memcmp(&phba->fc_portname, &sp->portName,
  2341. sizeof (struct lpfc_name));
  2342. if (!rc) {
  2343. if ((mbox = mempool_alloc(phba->mbox_mem_pool,
  2344. GFP_KERNEL)) == 0) {
  2345. return 1;
  2346. }
  2347. lpfc_linkdown(phba);
  2348. lpfc_init_link(phba, mbox,
  2349. phba->cfg_topology,
  2350. phba->cfg_link_speed);
  2351. mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
  2352. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2353. rc = lpfc_sli_issue_mbox
  2354. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  2355. lpfc_set_loopback_flag(phba);
  2356. if (rc == MBX_NOT_FINISHED) {
  2357. mempool_free( mbox, phba->mbox_mem_pool);
  2358. }
  2359. return 1;
  2360. } else if (rc > 0) { /* greater than */
  2361. spin_lock_irq(phba->host->host_lock);
  2362. phba->fc_flag |= FC_PT2PT_PLOGI;
  2363. spin_unlock_irq(phba->host->host_lock);
  2364. }
  2365. phba->fc_flag |= FC_PT2PT;
  2366. phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
  2367. } else {
  2368. /* Reject this request because invalid parameters */
  2369. stat.un.b.lsRjtRsvd0 = 0;
  2370. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2371. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  2372. stat.un.b.vendorUnique = 0;
  2373. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  2374. return 1;
  2375. }
  2376. /* Send back ACC */
  2377. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
  2378. return 0;
  2379. }
  2380. static int
  2381. lpfc_els_rcv_rnid(struct lpfc_hba * phba,
  2382. struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
  2383. {
  2384. struct lpfc_dmabuf *pcmd;
  2385. uint32_t *lp;
  2386. IOCB_t *icmd;
  2387. RNID *rn;
  2388. struct ls_rjt stat;
  2389. uint32_t cmd, did;
  2390. icmd = &cmdiocb->iocb;
  2391. did = icmd->un.elsreq64.remoteID;
  2392. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2393. lp = (uint32_t *) pcmd->virt;
  2394. cmd = *lp++;
  2395. rn = (RNID *) lp;
  2396. /* RNID received */
  2397. switch (rn->Format) {
  2398. case 0:
  2399. case RNID_TOPOLOGY_DISC:
  2400. /* Send back ACC */
  2401. lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
  2402. break;
  2403. default:
  2404. /* Reject this request because format not supported */
  2405. stat.un.b.lsRjtRsvd0 = 0;
  2406. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2407. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2408. stat.un.b.vendorUnique = 0;
  2409. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  2410. }
  2411. return 0;
  2412. }
  2413. static int
  2414. lpfc_els_rcv_lirr(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  2415. struct lpfc_nodelist * ndlp)
  2416. {
  2417. struct ls_rjt stat;
  2418. /* For now, unconditionally reject this command */
  2419. stat.un.b.lsRjtRsvd0 = 0;
  2420. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2421. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2422. stat.un.b.vendorUnique = 0;
  2423. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  2424. return 0;
  2425. }
  2426. static void
  2427. lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  2428. {
  2429. struct lpfc_sli *psli;
  2430. struct lpfc_sli_ring *pring;
  2431. MAILBOX_t *mb;
  2432. IOCB_t *icmd;
  2433. RPS_RSP *rps_rsp;
  2434. uint8_t *pcmd;
  2435. struct lpfc_iocbq *elsiocb;
  2436. struct lpfc_nodelist *ndlp;
  2437. uint16_t xri, status;
  2438. uint32_t cmdsize;
  2439. psli = &phba->sli;
  2440. pring = &psli->ring[LPFC_ELS_RING];
  2441. mb = &pmb->mb;
  2442. ndlp = (struct lpfc_nodelist *) pmb->context2;
  2443. xri = (uint16_t) ((unsigned long)(pmb->context1));
  2444. pmb->context1 = NULL;
  2445. pmb->context2 = NULL;
  2446. if (mb->mbxStatus) {
  2447. mempool_free( pmb, phba->mbox_mem_pool);
  2448. return;
  2449. }
  2450. cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
  2451. mempool_free( pmb, phba->mbox_mem_pool);
  2452. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp,
  2453. ndlp->nlp_DID, ELS_CMD_ACC);
  2454. if (!elsiocb)
  2455. return;
  2456. icmd = &elsiocb->iocb;
  2457. icmd->ulpContext = xri;
  2458. pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2459. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2460. pcmd += sizeof (uint32_t); /* Skip past command */
  2461. rps_rsp = (RPS_RSP *)pcmd;
  2462. if (phba->fc_topology != TOPOLOGY_LOOP)
  2463. status = 0x10;
  2464. else
  2465. status = 0x8;
  2466. if (phba->fc_flag & FC_FABRIC)
  2467. status |= 0x4;
  2468. rps_rsp->rsvd1 = 0;
  2469. rps_rsp->portStatus = be16_to_cpu(status);
  2470. rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
  2471. rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
  2472. rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
  2473. rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
  2474. rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
  2475. rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
  2476. /* Xmit ELS RPS ACC response tag <ulpIoTag> */
  2477. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  2478. "%d:0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
  2479. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2480. phba->brd_no, elsiocb->iotag,
  2481. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  2482. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  2483. elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
  2484. phba->fc_stat.elsXmitACC++;
  2485. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  2486. lpfc_els_free_iocb(phba, elsiocb);
  2487. }
  2488. return;
  2489. }
  2490. static int
  2491. lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  2492. struct lpfc_nodelist * ndlp)
  2493. {
  2494. uint32_t *lp;
  2495. uint8_t flag;
  2496. LPFC_MBOXQ_t *mbox;
  2497. struct lpfc_dmabuf *pcmd;
  2498. RPS *rps;
  2499. struct ls_rjt stat;
  2500. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  2501. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  2502. stat.un.b.lsRjtRsvd0 = 0;
  2503. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2504. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2505. stat.un.b.vendorUnique = 0;
  2506. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  2507. }
  2508. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2509. lp = (uint32_t *) pcmd->virt;
  2510. flag = (be32_to_cpu(*lp++) & 0xf);
  2511. rps = (RPS *) lp;
  2512. if ((flag == 0) ||
  2513. ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
  2514. ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname,
  2515. sizeof (struct lpfc_name)) == 0))) {
  2516. if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
  2517. lpfc_read_lnk_stat(phba, mbox);
  2518. mbox->context1 =
  2519. (void *)((unsigned long)cmdiocb->iocb.ulpContext);
  2520. mbox->context2 = ndlp;
  2521. mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
  2522. if (lpfc_sli_issue_mbox (phba, mbox,
  2523. (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) {
  2524. /* Mbox completion will send ELS Response */
  2525. return 0;
  2526. }
  2527. mempool_free(mbox, phba->mbox_mem_pool);
  2528. }
  2529. }
  2530. stat.un.b.lsRjtRsvd0 = 0;
  2531. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2532. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2533. stat.un.b.vendorUnique = 0;
  2534. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  2535. return 0;
  2536. }
  2537. static int
  2538. lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
  2539. struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
  2540. {
  2541. IOCB_t *icmd;
  2542. IOCB_t *oldcmd;
  2543. RPL_RSP rpl_rsp;
  2544. struct lpfc_iocbq *elsiocb;
  2545. struct lpfc_sli_ring *pring;
  2546. struct lpfc_sli *psli;
  2547. uint8_t *pcmd;
  2548. psli = &phba->sli;
  2549. pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
  2550. elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
  2551. ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
  2552. if (!elsiocb)
  2553. return 1;
  2554. icmd = &elsiocb->iocb;
  2555. oldcmd = &oldiocb->iocb;
  2556. icmd->ulpContext = oldcmd->ulpContext; /* Xri */
  2557. pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
  2558. *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
  2559. pcmd += sizeof (uint16_t);
  2560. *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
  2561. pcmd += sizeof(uint16_t);
  2562. /* Setup the RPL ACC payload */
  2563. rpl_rsp.listLen = be32_to_cpu(1);
  2564. rpl_rsp.index = 0;
  2565. rpl_rsp.port_num_blk.portNum = 0;
  2566. rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID);
  2567. memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname,
  2568. sizeof(struct lpfc_name));
  2569. memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
  2570. /* Xmit ELS RPL ACC response tag <ulpIoTag> */
  2571. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  2572. "%d:0120 Xmit ELS RPL ACC response tag x%x xri x%x, "
  2573. "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
  2574. phba->brd_no, elsiocb->iotag,
  2575. elsiocb->iocb.ulpContext, ndlp->nlp_DID,
  2576. ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
  2577. elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
  2578. phba->fc_stat.elsXmitACC++;
  2579. if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
  2580. lpfc_els_free_iocb(phba, elsiocb);
  2581. return 1;
  2582. }
  2583. return 0;
  2584. }
  2585. static int
  2586. lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  2587. struct lpfc_nodelist * ndlp)
  2588. {
  2589. struct lpfc_dmabuf *pcmd;
  2590. uint32_t *lp;
  2591. uint32_t maxsize;
  2592. uint16_t cmdsize;
  2593. RPL *rpl;
  2594. struct ls_rjt stat;
  2595. if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  2596. (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
  2597. stat.un.b.lsRjtRsvd0 = 0;
  2598. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  2599. stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
  2600. stat.un.b.vendorUnique = 0;
  2601. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  2602. }
  2603. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2604. lp = (uint32_t *) pcmd->virt;
  2605. rpl = (RPL *) (lp + 1);
  2606. maxsize = be32_to_cpu(rpl->maxsize);
  2607. /* We support only one port */
  2608. if ((rpl->index == 0) &&
  2609. ((maxsize == 0) ||
  2610. ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
  2611. cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
  2612. } else {
  2613. cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
  2614. }
  2615. lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp);
  2616. return 0;
  2617. }
  2618. static int
  2619. lpfc_els_rcv_farp(struct lpfc_hba * phba,
  2620. struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
  2621. {
  2622. struct lpfc_dmabuf *pcmd;
  2623. uint32_t *lp;
  2624. IOCB_t *icmd;
  2625. FARP *fp;
  2626. uint32_t cmd, cnt, did;
  2627. icmd = &cmdiocb->iocb;
  2628. did = icmd->un.elsreq64.remoteID;
  2629. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2630. lp = (uint32_t *) pcmd->virt;
  2631. cmd = *lp++;
  2632. fp = (FARP *) lp;
  2633. /* FARP-REQ received from DID <did> */
  2634. lpfc_printf_log(phba,
  2635. KERN_INFO,
  2636. LOG_ELS,
  2637. "%d:0601 FARP-REQ received from DID x%x\n",
  2638. phba->brd_no, did);
  2639. /* We will only support match on WWPN or WWNN */
  2640. if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
  2641. return 0;
  2642. }
  2643. cnt = 0;
  2644. /* If this FARP command is searching for my portname */
  2645. if (fp->Mflags & FARP_MATCH_PORT) {
  2646. if (memcmp(&fp->RportName, &phba->fc_portname,
  2647. sizeof (struct lpfc_name)) == 0)
  2648. cnt = 1;
  2649. }
  2650. /* If this FARP command is searching for my nodename */
  2651. if (fp->Mflags & FARP_MATCH_NODE) {
  2652. if (memcmp(&fp->RnodeName, &phba->fc_nodename,
  2653. sizeof (struct lpfc_name)) == 0)
  2654. cnt = 1;
  2655. }
  2656. if (cnt) {
  2657. if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
  2658. (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
  2659. /* Log back into the node before sending the FARP. */
  2660. if (fp->Rflags & FARP_REQUEST_PLOGI) {
  2661. ndlp->nlp_prev_state = ndlp->nlp_state;
  2662. lpfc_nlp_set_state(phba, ndlp,
  2663. NLP_STE_PLOGI_ISSUE);
  2664. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  2665. }
  2666. /* Send a FARP response to that node */
  2667. if (fp->Rflags & FARP_REQUEST_FARPR) {
  2668. lpfc_issue_els_farpr(phba, did, 0);
  2669. }
  2670. }
  2671. }
  2672. return 0;
  2673. }
  2674. static int
  2675. lpfc_els_rcv_farpr(struct lpfc_hba * phba,
  2676. struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
  2677. {
  2678. struct lpfc_dmabuf *pcmd;
  2679. uint32_t *lp;
  2680. IOCB_t *icmd;
  2681. uint32_t cmd, did;
  2682. icmd = &cmdiocb->iocb;
  2683. did = icmd->un.elsreq64.remoteID;
  2684. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  2685. lp = (uint32_t *) pcmd->virt;
  2686. cmd = *lp++;
  2687. /* FARP-RSP received from DID <did> */
  2688. lpfc_printf_log(phba,
  2689. KERN_INFO,
  2690. LOG_ELS,
  2691. "%d:0600 FARP-RSP received from DID x%x\n",
  2692. phba->brd_no, did);
  2693. /* ACCEPT the Farp resp request */
  2694. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  2695. return 0;
  2696. }
  2697. static int
  2698. lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  2699. struct lpfc_nodelist * fan_ndlp)
  2700. {
  2701. struct lpfc_dmabuf *pcmd;
  2702. uint32_t *lp;
  2703. IOCB_t *icmd;
  2704. uint32_t cmd, did;
  2705. FAN *fp;
  2706. struct lpfc_nodelist *ndlp, *next_ndlp;
  2707. /* FAN received */
  2708. lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:0265 FAN received\n",
  2709. phba->brd_no);
  2710. icmd = &cmdiocb->iocb;
  2711. did = icmd->un.elsreq64.remoteID;
  2712. pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
  2713. lp = (uint32_t *)pcmd->virt;
  2714. cmd = *lp++;
  2715. fp = (FAN *)lp;
  2716. /* FAN received; Fan does not have a reply sequence */
  2717. if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
  2718. if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
  2719. sizeof(struct lpfc_name)) != 0) ||
  2720. (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
  2721. sizeof(struct lpfc_name)) != 0)) {
  2722. /*
  2723. * This node has switched fabrics. FLOGI is required
  2724. * Clean up the old rpi's
  2725. */
  2726. list_for_each_entry_safe(ndlp, next_ndlp,
  2727. &phba->fc_npr_list, nlp_listp) {
  2728. if (ndlp->nlp_type & NLP_FABRIC) {
  2729. /*
  2730. * Clean up old Fabric, Nameserver and
  2731. * other NLP_FABRIC logins
  2732. */
  2733. lpfc_drop_node(phba, ndlp);
  2734. } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
  2735. /* Fail outstanding I/O now since this
  2736. * device is marked for PLOGI
  2737. */
  2738. lpfc_unreg_rpi(phba, ndlp);
  2739. }
  2740. }
  2741. phba->hba_state = LPFC_FLOGI;
  2742. lpfc_set_disctmo(phba);
  2743. lpfc_initial_flogi(phba);
  2744. return 0;
  2745. }
  2746. /* Discovery not needed,
  2747. * move the nodes to their original state.
  2748. */
  2749. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  2750. nlp_listp) {
  2751. switch (ndlp->nlp_prev_state) {
  2752. case NLP_STE_UNMAPPED_NODE:
  2753. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  2754. lpfc_nlp_set_state(phba, ndlp,
  2755. NLP_STE_UNMAPPED_NODE);
  2756. break;
  2757. case NLP_STE_MAPPED_NODE:
  2758. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  2759. lpfc_nlp_set_state(phba, ndlp,
  2760. NLP_STE_MAPPED_NODE);
  2761. break;
  2762. default:
  2763. break;
  2764. }
  2765. }
  2766. /* Start discovery - this should just do CLEAR_LA */
  2767. lpfc_disc_start(phba);
  2768. }
  2769. return 0;
  2770. }
  2771. void
  2772. lpfc_els_timeout(unsigned long ptr)
  2773. {
  2774. struct lpfc_hba *phba;
  2775. unsigned long iflag;
  2776. phba = (struct lpfc_hba *)ptr;
  2777. if (phba == 0)
  2778. return;
  2779. spin_lock_irqsave(phba->host->host_lock, iflag);
  2780. if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
  2781. phba->work_hba_events |= WORKER_ELS_TMO;
  2782. if (phba->work_wait)
  2783. wake_up(phba->work_wait);
  2784. }
  2785. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  2786. return;
  2787. }
  2788. void
  2789. lpfc_els_timeout_handler(struct lpfc_hba *phba)
  2790. {
  2791. struct lpfc_sli_ring *pring;
  2792. struct lpfc_iocbq *tmp_iocb, *piocb;
  2793. IOCB_t *cmd = NULL;
  2794. struct lpfc_dmabuf *pcmd;
  2795. uint32_t *elscmd;
  2796. uint32_t els_command=0;
  2797. uint32_t timeout;
  2798. uint32_t remote_ID;
  2799. if (phba == 0)
  2800. return;
  2801. spin_lock_irq(phba->host->host_lock);
  2802. /* If the timer is already canceled do nothing */
  2803. if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
  2804. spin_unlock_irq(phba->host->host_lock);
  2805. return;
  2806. }
  2807. timeout = (uint32_t)(phba->fc_ratov << 1);
  2808. pring = &phba->sli.ring[LPFC_ELS_RING];
  2809. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  2810. cmd = &piocb->iocb;
  2811. if ((piocb->iocb_flag & LPFC_IO_LIBDFC) ||
  2812. (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN) ||
  2813. (piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)) {
  2814. continue;
  2815. }
  2816. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  2817. if (pcmd) {
  2818. elscmd = (uint32_t *) (pcmd->virt);
  2819. els_command = *elscmd;
  2820. }
  2821. if ((els_command == ELS_CMD_FARP)
  2822. || (els_command == ELS_CMD_FARPR)) {
  2823. continue;
  2824. }
  2825. if (piocb->drvrTimeout > 0) {
  2826. if (piocb->drvrTimeout >= timeout) {
  2827. piocb->drvrTimeout -= timeout;
  2828. } else {
  2829. piocb->drvrTimeout = 0;
  2830. }
  2831. continue;
  2832. }
  2833. if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
  2834. struct lpfc_nodelist *ndlp;
  2835. ndlp = __lpfc_findnode_rpi(phba, cmd->ulpContext);
  2836. remote_ID = ndlp->nlp_DID;
  2837. } else {
  2838. remote_ID = cmd->un.elsreq64.remoteID;
  2839. }
  2840. lpfc_printf_log(phba,
  2841. KERN_ERR,
  2842. LOG_ELS,
  2843. "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
  2844. phba->brd_no, els_command,
  2845. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  2846. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  2847. }
  2848. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  2849. mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
  2850. spin_unlock_irq(phba->host->host_lock);
  2851. }
  2852. void
  2853. lpfc_els_flush_cmd(struct lpfc_hba * phba)
  2854. {
  2855. LIST_HEAD(completions);
  2856. struct lpfc_sli_ring *pring;
  2857. struct lpfc_iocbq *tmp_iocb, *piocb;
  2858. IOCB_t *cmd = NULL;
  2859. pring = &phba->sli.ring[LPFC_ELS_RING];
  2860. spin_lock_irq(phba->host->host_lock);
  2861. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  2862. cmd = &piocb->iocb;
  2863. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  2864. continue;
  2865. }
  2866. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  2867. if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
  2868. (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
  2869. (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
  2870. (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
  2871. continue;
  2872. }
  2873. list_move_tail(&piocb->list, &completions);
  2874. pring->txq_cnt--;
  2875. }
  2876. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  2877. cmd = &piocb->iocb;
  2878. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  2879. continue;
  2880. }
  2881. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  2882. }
  2883. spin_unlock_irq(phba->host->host_lock);
  2884. while(!list_empty(&completions)) {
  2885. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  2886. cmd = &piocb->iocb;
  2887. list_del(&piocb->list);
  2888. if (piocb->iocb_cmpl) {
  2889. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  2890. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  2891. (piocb->iocb_cmpl) (phba, piocb, piocb);
  2892. } else
  2893. lpfc_sli_release_iocbq(phba, piocb);
  2894. }
  2895. return;
  2896. }
  2897. void
  2898. lpfc_els_unsol_event(struct lpfc_hba * phba,
  2899. struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
  2900. {
  2901. struct lpfc_sli *psli;
  2902. struct lpfc_nodelist *ndlp;
  2903. struct lpfc_dmabuf *mp;
  2904. uint32_t *lp;
  2905. IOCB_t *icmd;
  2906. struct ls_rjt stat;
  2907. uint32_t cmd;
  2908. uint32_t did;
  2909. uint32_t newnode;
  2910. uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
  2911. uint32_t rjt_err = 0;
  2912. psli = &phba->sli;
  2913. icmd = &elsiocb->iocb;
  2914. if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2915. ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
  2916. /* Not enough posted buffers; Try posting more buffers */
  2917. phba->fc_stat.NoRcvBuf++;
  2918. lpfc_post_buffer(phba, pring, 0, 1);
  2919. return;
  2920. }
  2921. /* If there are no BDEs associated with this IOCB,
  2922. * there is nothing to do.
  2923. */
  2924. if (icmd->ulpBdeCount == 0)
  2925. return;
  2926. /* type of ELS cmd is first 32bit word in packet */
  2927. mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
  2928. cont64[0].
  2929. addrHigh,
  2930. icmd->un.
  2931. cont64[0].addrLow));
  2932. if (mp == 0) {
  2933. drop_cmd = 1;
  2934. goto dropit;
  2935. }
  2936. newnode = 0;
  2937. lp = (uint32_t *) mp->virt;
  2938. cmd = *lp++;
  2939. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
  2940. if (icmd->ulpStatus) {
  2941. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2942. kfree(mp);
  2943. drop_cmd = 1;
  2944. goto dropit;
  2945. }
  2946. /* Check to see if link went down during discovery */
  2947. if (lpfc_els_chk_latt(phba)) {
  2948. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2949. kfree(mp);
  2950. drop_cmd = 1;
  2951. goto dropit;
  2952. }
  2953. did = icmd->un.rcvels.remoteID;
  2954. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
  2955. if (!ndlp) {
  2956. /* Cannot find existing Fabric ndlp, so allocate a new one */
  2957. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2958. if (!ndlp) {
  2959. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2960. kfree(mp);
  2961. drop_cmd = 1;
  2962. goto dropit;
  2963. }
  2964. lpfc_nlp_init(phba, ndlp, did);
  2965. newnode = 1;
  2966. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
  2967. ndlp->nlp_type |= NLP_FABRIC;
  2968. }
  2969. lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
  2970. }
  2971. phba->fc_stat.elsRcvFrame++;
  2972. elsiocb->context1 = ndlp;
  2973. elsiocb->context2 = mp;
  2974. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  2975. cmd &= ELS_CMD_MASK;
  2976. }
  2977. /* ELS command <elsCmd> received from NPORT <did> */
  2978. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  2979. "%d:0112 ELS command x%x received from NPORT x%x "
  2980. "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
  2981. switch (cmd) {
  2982. case ELS_CMD_PLOGI:
  2983. phba->fc_stat.elsRcvPLOGI++;
  2984. if (phba->hba_state < LPFC_DISC_AUTH) {
  2985. rjt_err = 1;
  2986. break;
  2987. }
  2988. ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp);
  2989. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
  2990. break;
  2991. case ELS_CMD_FLOGI:
  2992. phba->fc_stat.elsRcvFLOGI++;
  2993. lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
  2994. if (newnode)
  2995. lpfc_drop_node(phba, ndlp);
  2996. break;
  2997. case ELS_CMD_LOGO:
  2998. phba->fc_stat.elsRcvLOGO++;
  2999. if (phba->hba_state < LPFC_DISC_AUTH) {
  3000. rjt_err = 1;
  3001. break;
  3002. }
  3003. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  3004. break;
  3005. case ELS_CMD_PRLO:
  3006. phba->fc_stat.elsRcvPRLO++;
  3007. if (phba->hba_state < LPFC_DISC_AUTH) {
  3008. rjt_err = 1;
  3009. break;
  3010. }
  3011. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  3012. break;
  3013. case ELS_CMD_RSCN:
  3014. phba->fc_stat.elsRcvRSCN++;
  3015. lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
  3016. if (newnode)
  3017. lpfc_drop_node(phba, ndlp);
  3018. break;
  3019. case ELS_CMD_ADISC:
  3020. phba->fc_stat.elsRcvADISC++;
  3021. if (phba->hba_state < LPFC_DISC_AUTH) {
  3022. rjt_err = 1;
  3023. break;
  3024. }
  3025. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
  3026. break;
  3027. case ELS_CMD_PDISC:
  3028. phba->fc_stat.elsRcvPDISC++;
  3029. if (phba->hba_state < LPFC_DISC_AUTH) {
  3030. rjt_err = 1;
  3031. break;
  3032. }
  3033. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
  3034. break;
  3035. case ELS_CMD_FARPR:
  3036. phba->fc_stat.elsRcvFARPR++;
  3037. lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
  3038. break;
  3039. case ELS_CMD_FARP:
  3040. phba->fc_stat.elsRcvFARP++;
  3041. lpfc_els_rcv_farp(phba, elsiocb, ndlp);
  3042. break;
  3043. case ELS_CMD_FAN:
  3044. phba->fc_stat.elsRcvFAN++;
  3045. lpfc_els_rcv_fan(phba, elsiocb, ndlp);
  3046. break;
  3047. case ELS_CMD_PRLI:
  3048. phba->fc_stat.elsRcvPRLI++;
  3049. if (phba->hba_state < LPFC_DISC_AUTH) {
  3050. rjt_err = 1;
  3051. break;
  3052. }
  3053. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  3054. break;
  3055. case ELS_CMD_LIRR:
  3056. phba->fc_stat.elsRcvLIRR++;
  3057. lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
  3058. if (newnode)
  3059. lpfc_drop_node(phba, ndlp);
  3060. break;
  3061. case ELS_CMD_RPS:
  3062. phba->fc_stat.elsRcvRPS++;
  3063. lpfc_els_rcv_rps(phba, elsiocb, ndlp);
  3064. if (newnode)
  3065. lpfc_drop_node(phba, ndlp);
  3066. break;
  3067. case ELS_CMD_RPL:
  3068. phba->fc_stat.elsRcvRPL++;
  3069. lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
  3070. if (newnode)
  3071. lpfc_drop_node(phba, ndlp);
  3072. break;
  3073. case ELS_CMD_RNID:
  3074. phba->fc_stat.elsRcvRNID++;
  3075. lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
  3076. if (newnode)
  3077. lpfc_drop_node(phba, ndlp);
  3078. break;
  3079. default:
  3080. /* Unsupported ELS command, reject */
  3081. rjt_err = 1;
  3082. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  3083. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3084. "%d:0115 Unknown ELS command x%x received from "
  3085. "NPORT x%x\n", phba->brd_no, cmd, did);
  3086. if (newnode)
  3087. lpfc_drop_node(phba, ndlp);
  3088. break;
  3089. }
  3090. /* check if need to LS_RJT received ELS cmd */
  3091. if (rjt_err) {
  3092. stat.un.b.lsRjtRsvd0 = 0;
  3093. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3094. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  3095. stat.un.b.vendorUnique = 0;
  3096. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
  3097. }
  3098. if (elsiocb->context2) {
  3099. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3100. kfree(mp);
  3101. }
  3102. dropit:
  3103. /* check if need to drop received ELS cmd */
  3104. if (drop_cmd == 1) {
  3105. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3106. "%d:0111 Dropping received ELS cmd "
  3107. "Data: x%x x%x x%x\n", phba->brd_no,
  3108. icmd->ulpStatus, icmd->un.ulpWord[4],
  3109. icmd->ulpTimeout);
  3110. phba->fc_stat.elsRcvDrop++;
  3111. }
  3112. return;
  3113. }