lpfc_els.c 92 KB

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