lpfc_els.c 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572
  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=0;
  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. (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN) ||
  2817. (piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)) {
  2818. continue;
  2819. }
  2820. pcmd = (struct lpfc_dmabuf *) piocb->context2;
  2821. if (pcmd) {
  2822. elscmd = (uint32_t *) (pcmd->virt);
  2823. els_command = *elscmd;
  2824. }
  2825. if ((els_command == ELS_CMD_FARP)
  2826. || (els_command == ELS_CMD_FARPR)) {
  2827. continue;
  2828. }
  2829. if (piocb->drvrTimeout > 0) {
  2830. if (piocb->drvrTimeout >= timeout) {
  2831. piocb->drvrTimeout -= timeout;
  2832. } else {
  2833. piocb->drvrTimeout = 0;
  2834. }
  2835. continue;
  2836. }
  2837. if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
  2838. struct lpfc_nodelist *ndlp;
  2839. ndlp = __lpfc_findnode_rpi(phba, cmd->ulpContext);
  2840. remote_ID = ndlp->nlp_DID;
  2841. } else {
  2842. remote_ID = cmd->un.elsreq64.remoteID;
  2843. }
  2844. lpfc_printf_log(phba,
  2845. KERN_ERR,
  2846. LOG_ELS,
  2847. "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
  2848. phba->brd_no, els_command,
  2849. remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
  2850. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  2851. }
  2852. if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
  2853. mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
  2854. spin_unlock_irq(phba->host->host_lock);
  2855. }
  2856. void
  2857. lpfc_els_flush_cmd(struct lpfc_hba * phba)
  2858. {
  2859. LIST_HEAD(completions);
  2860. struct lpfc_sli_ring *pring;
  2861. struct lpfc_iocbq *tmp_iocb, *piocb;
  2862. IOCB_t *cmd = NULL;
  2863. pring = &phba->sli.ring[LPFC_ELS_RING];
  2864. spin_lock_irq(phba->host->host_lock);
  2865. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
  2866. cmd = &piocb->iocb;
  2867. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  2868. continue;
  2869. }
  2870. /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
  2871. if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
  2872. (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
  2873. (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
  2874. (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
  2875. continue;
  2876. }
  2877. list_move_tail(&piocb->list, &completions);
  2878. pring->txq_cnt--;
  2879. }
  2880. list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
  2881. cmd = &piocb->iocb;
  2882. if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
  2883. continue;
  2884. }
  2885. lpfc_sli_issue_abort_iotag(phba, pring, piocb);
  2886. }
  2887. spin_unlock_irq(phba->host->host_lock);
  2888. while(!list_empty(&completions)) {
  2889. piocb = list_get_first(&completions, struct lpfc_iocbq, list);
  2890. cmd = &piocb->iocb;
  2891. list_del(&piocb->list);
  2892. if (piocb->iocb_cmpl) {
  2893. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  2894. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  2895. (piocb->iocb_cmpl) (phba, piocb, piocb);
  2896. } else
  2897. lpfc_sli_release_iocbq(phba, piocb);
  2898. }
  2899. return;
  2900. }
  2901. void
  2902. lpfc_els_unsol_event(struct lpfc_hba * phba,
  2903. struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
  2904. {
  2905. struct lpfc_sli *psli;
  2906. struct lpfc_nodelist *ndlp;
  2907. struct lpfc_dmabuf *mp;
  2908. uint32_t *lp;
  2909. IOCB_t *icmd;
  2910. struct ls_rjt stat;
  2911. uint32_t cmd;
  2912. uint32_t did;
  2913. uint32_t newnode;
  2914. uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
  2915. uint32_t rjt_err = 0;
  2916. psli = &phba->sli;
  2917. icmd = &elsiocb->iocb;
  2918. if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  2919. ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
  2920. /* Not enough posted buffers; Try posting more buffers */
  2921. phba->fc_stat.NoRcvBuf++;
  2922. lpfc_post_buffer(phba, pring, 0, 1);
  2923. return;
  2924. }
  2925. /* If there are no BDEs associated with this IOCB,
  2926. * there is nothing to do.
  2927. */
  2928. if (icmd->ulpBdeCount == 0)
  2929. return;
  2930. /* type of ELS cmd is first 32bit word in packet */
  2931. mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
  2932. cont64[0].
  2933. addrHigh,
  2934. icmd->un.
  2935. cont64[0].addrLow));
  2936. if (mp == 0) {
  2937. drop_cmd = 1;
  2938. goto dropit;
  2939. }
  2940. newnode = 0;
  2941. lp = (uint32_t *) mp->virt;
  2942. cmd = *lp++;
  2943. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
  2944. if (icmd->ulpStatus) {
  2945. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2946. kfree(mp);
  2947. drop_cmd = 1;
  2948. goto dropit;
  2949. }
  2950. /* Check to see if link went down during discovery */
  2951. if (lpfc_els_chk_latt(phba)) {
  2952. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2953. kfree(mp);
  2954. drop_cmd = 1;
  2955. goto dropit;
  2956. }
  2957. did = icmd->un.rcvels.remoteID;
  2958. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
  2959. if (!ndlp) {
  2960. /* Cannot find existing Fabric ndlp, so allocate a new one */
  2961. ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
  2962. if (!ndlp) {
  2963. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2964. kfree(mp);
  2965. drop_cmd = 1;
  2966. goto dropit;
  2967. }
  2968. lpfc_nlp_init(phba, ndlp, did);
  2969. newnode = 1;
  2970. if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
  2971. ndlp->nlp_type |= NLP_FABRIC;
  2972. }
  2973. lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
  2974. }
  2975. phba->fc_stat.elsRcvFrame++;
  2976. elsiocb->context1 = ndlp;
  2977. elsiocb->context2 = mp;
  2978. if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
  2979. cmd &= ELS_CMD_MASK;
  2980. }
  2981. /* ELS command <elsCmd> received from NPORT <did> */
  2982. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  2983. "%d:0112 ELS command x%x received from NPORT x%x "
  2984. "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
  2985. switch (cmd) {
  2986. case ELS_CMD_PLOGI:
  2987. phba->fc_stat.elsRcvPLOGI++;
  2988. if (phba->hba_state < LPFC_DISC_AUTH) {
  2989. rjt_err = 1;
  2990. break;
  2991. }
  2992. ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp);
  2993. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
  2994. break;
  2995. case ELS_CMD_FLOGI:
  2996. phba->fc_stat.elsRcvFLOGI++;
  2997. lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
  2998. if (newnode)
  2999. lpfc_drop_node(phba, ndlp);
  3000. break;
  3001. case ELS_CMD_LOGO:
  3002. phba->fc_stat.elsRcvLOGO++;
  3003. if (phba->hba_state < LPFC_DISC_AUTH) {
  3004. rjt_err = 1;
  3005. break;
  3006. }
  3007. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
  3008. break;
  3009. case ELS_CMD_PRLO:
  3010. phba->fc_stat.elsRcvPRLO++;
  3011. if (phba->hba_state < LPFC_DISC_AUTH) {
  3012. rjt_err = 1;
  3013. break;
  3014. }
  3015. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
  3016. break;
  3017. case ELS_CMD_RSCN:
  3018. phba->fc_stat.elsRcvRSCN++;
  3019. lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
  3020. if (newnode)
  3021. lpfc_drop_node(phba, ndlp);
  3022. break;
  3023. case ELS_CMD_ADISC:
  3024. phba->fc_stat.elsRcvADISC++;
  3025. if (phba->hba_state < LPFC_DISC_AUTH) {
  3026. rjt_err = 1;
  3027. break;
  3028. }
  3029. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
  3030. break;
  3031. case ELS_CMD_PDISC:
  3032. phba->fc_stat.elsRcvPDISC++;
  3033. if (phba->hba_state < LPFC_DISC_AUTH) {
  3034. rjt_err = 1;
  3035. break;
  3036. }
  3037. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
  3038. break;
  3039. case ELS_CMD_FARPR:
  3040. phba->fc_stat.elsRcvFARPR++;
  3041. lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
  3042. break;
  3043. case ELS_CMD_FARP:
  3044. phba->fc_stat.elsRcvFARP++;
  3045. lpfc_els_rcv_farp(phba, elsiocb, ndlp);
  3046. break;
  3047. case ELS_CMD_FAN:
  3048. phba->fc_stat.elsRcvFAN++;
  3049. lpfc_els_rcv_fan(phba, elsiocb, ndlp);
  3050. break;
  3051. case ELS_CMD_PRLI:
  3052. phba->fc_stat.elsRcvPRLI++;
  3053. if (phba->hba_state < LPFC_DISC_AUTH) {
  3054. rjt_err = 1;
  3055. break;
  3056. }
  3057. lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
  3058. break;
  3059. case ELS_CMD_LIRR:
  3060. phba->fc_stat.elsRcvLIRR++;
  3061. lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
  3062. if (newnode)
  3063. lpfc_drop_node(phba, ndlp);
  3064. break;
  3065. case ELS_CMD_RPS:
  3066. phba->fc_stat.elsRcvRPS++;
  3067. lpfc_els_rcv_rps(phba, elsiocb, ndlp);
  3068. if (newnode)
  3069. lpfc_drop_node(phba, ndlp);
  3070. break;
  3071. case ELS_CMD_RPL:
  3072. phba->fc_stat.elsRcvRPL++;
  3073. lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
  3074. if (newnode)
  3075. lpfc_drop_node(phba, ndlp);
  3076. break;
  3077. case ELS_CMD_RNID:
  3078. phba->fc_stat.elsRcvRNID++;
  3079. lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
  3080. if (newnode)
  3081. lpfc_drop_node(phba, ndlp);
  3082. break;
  3083. default:
  3084. /* Unsupported ELS command, reject */
  3085. rjt_err = 1;
  3086. /* Unknown ELS command <elsCmd> received from NPORT <did> */
  3087. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3088. "%d:0115 Unknown ELS command x%x received from "
  3089. "NPORT x%x\n", phba->brd_no, cmd, did);
  3090. if (newnode)
  3091. lpfc_drop_node(phba, ndlp);
  3092. break;
  3093. }
  3094. /* check if need to LS_RJT received ELS cmd */
  3095. if (rjt_err) {
  3096. stat.un.b.lsRjtRsvd0 = 0;
  3097. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  3098. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  3099. stat.un.b.vendorUnique = 0;
  3100. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
  3101. }
  3102. if (elsiocb->context2) {
  3103. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  3104. kfree(mp);
  3105. }
  3106. dropit:
  3107. /* check if need to drop received ELS cmd */
  3108. if (drop_cmd == 1) {
  3109. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  3110. "%d:0111 Dropping received ELS cmd "
  3111. "Data: x%x x%x x%x\n", phba->brd_no,
  3112. icmd->ulpStatus, icmd->un.ulpWord[4],
  3113. icmd->ulpTimeout);
  3114. phba->fc_stat.elsRcvDrop++;
  3115. }
  3116. return;
  3117. }