lpfc_nportdisc.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916
  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. /* Called to verify a rcv'ed ADISC was intended for us. */
  36. static int
  37. lpfc_check_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  38. struct lpfc_name * nn, struct lpfc_name * pn)
  39. {
  40. /* Compare the ADISC rsp WWNN / WWPN matches our internal node
  41. * table entry for that node.
  42. */
  43. if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)) != 0)
  44. return 0;
  45. if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)) != 0)
  46. return 0;
  47. /* we match, return success */
  48. return 1;
  49. }
  50. int
  51. lpfc_check_sparm(struct lpfc_hba * phba,
  52. struct lpfc_nodelist * ndlp, struct serv_parm * sp,
  53. uint32_t class)
  54. {
  55. volatile struct serv_parm *hsp = &phba->fc_sparam;
  56. uint16_t hsp_value, ssp_value = 0;
  57. /*
  58. * The receive data field size and buffer-to-buffer receive data field
  59. * size entries are 16 bits but are represented as two 8-bit fields in
  60. * the driver data structure to account for rsvd bits and other control
  61. * bits. Reconstruct and compare the fields as a 16-bit values before
  62. * correcting the byte values.
  63. */
  64. if (sp->cls1.classValid) {
  65. hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
  66. hsp->cls1.rcvDataSizeLsb;
  67. ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
  68. sp->cls1.rcvDataSizeLsb;
  69. if (ssp_value > hsp_value) {
  70. sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
  71. sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
  72. }
  73. } else if (class == CLASS1) {
  74. return 0;
  75. }
  76. if (sp->cls2.classValid) {
  77. hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
  78. hsp->cls2.rcvDataSizeLsb;
  79. ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
  80. sp->cls2.rcvDataSizeLsb;
  81. if (ssp_value > hsp_value) {
  82. sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
  83. sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
  84. }
  85. } else if (class == CLASS2) {
  86. return 0;
  87. }
  88. if (sp->cls3.classValid) {
  89. hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
  90. hsp->cls3.rcvDataSizeLsb;
  91. ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
  92. sp->cls3.rcvDataSizeLsb;
  93. if (ssp_value > hsp_value) {
  94. sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
  95. sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
  96. }
  97. } else if (class == CLASS3) {
  98. return 0;
  99. }
  100. /*
  101. * Preserve the upper four bits of the MSB from the PLOGI response.
  102. * These bits contain the Buffer-to-Buffer State Change Number
  103. * from the target and need to be passed to the FW.
  104. */
  105. hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
  106. ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
  107. if (ssp_value > hsp_value) {
  108. sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
  109. sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
  110. (hsp->cmn.bbRcvSizeMsb & 0x0F);
  111. }
  112. memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
  113. memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
  114. return 1;
  115. }
  116. static void *
  117. lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
  118. struct lpfc_iocbq *cmdiocb,
  119. struct lpfc_iocbq *rspiocb)
  120. {
  121. struct lpfc_dmabuf *pcmd, *prsp;
  122. uint32_t *lp;
  123. void *ptr = NULL;
  124. IOCB_t *irsp;
  125. irsp = &rspiocb->iocb;
  126. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  127. /* For lpfc_els_abort, context2 could be zero'ed to delay
  128. * freeing associated memory till after ABTS completes.
  129. */
  130. if (pcmd) {
  131. prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
  132. list);
  133. if (prsp) {
  134. lp = (uint32_t *) prsp->virt;
  135. ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
  136. }
  137. } else {
  138. /* Force ulpStatus error since we are returning NULL ptr */
  139. if (!(irsp->ulpStatus)) {
  140. irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
  141. irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
  142. }
  143. ptr = NULL;
  144. }
  145. return ptr;
  146. }
  147. /*
  148. * Free resources / clean up outstanding I/Os
  149. * associated with a LPFC_NODELIST entry. This
  150. * routine effectively results in a "software abort".
  151. */
  152. int
  153. lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  154. int send_abts)
  155. {
  156. struct lpfc_sli *psli;
  157. struct lpfc_sli_ring *pring;
  158. struct lpfc_iocbq *iocb, *next_iocb;
  159. IOCB_t *icmd;
  160. int found = 0;
  161. /* Abort outstanding I/O on NPort <nlp_DID> */
  162. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  163. "%d:0201 Abort outstanding I/O on NPort x%x "
  164. "Data: x%x x%x x%x\n",
  165. phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
  166. ndlp->nlp_state, ndlp->nlp_rpi);
  167. psli = &phba->sli;
  168. pring = &psli->ring[LPFC_ELS_RING];
  169. /* First check the txq */
  170. do {
  171. found = 0;
  172. spin_lock_irq(phba->host->host_lock);
  173. list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
  174. /* Check to see if iocb matches the nport we are looking
  175. for */
  176. if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) {
  177. found = 1;
  178. /* It matches, so deque and call compl with an
  179. error */
  180. list_del(&iocb->list);
  181. pring->txq_cnt--;
  182. if (iocb->iocb_cmpl) {
  183. icmd = &iocb->iocb;
  184. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  185. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  186. spin_unlock_irq(phba->host->host_lock);
  187. (iocb->iocb_cmpl) (phba, iocb, iocb);
  188. spin_lock_irq(phba->host->host_lock);
  189. } else
  190. lpfc_sli_release_iocbq(phba, iocb);
  191. break;
  192. }
  193. }
  194. spin_unlock_irq(phba->host->host_lock);
  195. } while (found);
  196. /* Everything on txcmplq will be returned by firmware
  197. * with a no rpi / linkdown / abort error. For ring 0,
  198. * ELS discovery, we want to get rid of it right here.
  199. */
  200. /* Next check the txcmplq */
  201. do {
  202. found = 0;
  203. spin_lock_irq(phba->host->host_lock);
  204. list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
  205. list) {
  206. /* Check to see if iocb matches the nport we are looking
  207. for */
  208. if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) {
  209. found = 1;
  210. /* It matches, so deque and call compl with an
  211. error */
  212. list_del(&iocb->list);
  213. pring->txcmplq_cnt--;
  214. icmd = &iocb->iocb;
  215. /* If the driver is completing an ELS
  216. * command early, flush it out of the firmware.
  217. */
  218. if (send_abts &&
  219. (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) &&
  220. (icmd->un.elsreq64.bdl.ulpIoTag32)) {
  221. lpfc_sli_issue_abort_iotag32(phba,
  222. pring, iocb);
  223. }
  224. if (iocb->iocb_cmpl) {
  225. icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  226. icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  227. spin_unlock_irq(phba->host->host_lock);
  228. (iocb->iocb_cmpl) (phba, iocb, iocb);
  229. spin_lock_irq(phba->host->host_lock);
  230. } else
  231. lpfc_sli_release_iocbq(phba, iocb);
  232. break;
  233. }
  234. }
  235. spin_unlock_irq(phba->host->host_lock);
  236. } while(found);
  237. /* If we are delaying issuing an ELS command, cancel it */
  238. if (ndlp->nlp_flag & NLP_DELAY_TMO)
  239. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  240. return 0;
  241. }
  242. static int
  243. lpfc_rcv_plogi(struct lpfc_hba * phba,
  244. struct lpfc_nodelist * ndlp,
  245. struct lpfc_iocbq *cmdiocb)
  246. {
  247. struct lpfc_dmabuf *pcmd;
  248. uint32_t *lp;
  249. IOCB_t *icmd;
  250. struct serv_parm *sp;
  251. LPFC_MBOXQ_t *mbox;
  252. struct ls_rjt stat;
  253. int rc;
  254. memset(&stat, 0, sizeof (struct ls_rjt));
  255. if (phba->hba_state <= LPFC_FLOGI) {
  256. /* Before responding to PLOGI, check for pt2pt mode.
  257. * If we are pt2pt, with an outstanding FLOGI, abort
  258. * the FLOGI and resend it first.
  259. */
  260. if (phba->fc_flag & FC_PT2PT) {
  261. lpfc_els_abort_flogi(phba);
  262. if (!(phba->fc_flag & FC_PT2PT_PLOGI)) {
  263. /* If the other side is supposed to initiate
  264. * the PLOGI anyway, just ACC it now and
  265. * move on with discovery.
  266. */
  267. phba->fc_edtov = FF_DEF_EDTOV;
  268. phba->fc_ratov = FF_DEF_RATOV;
  269. /* Start discovery - this should just do
  270. CLEAR_LA */
  271. lpfc_disc_start(phba);
  272. } else {
  273. lpfc_initial_flogi(phba);
  274. }
  275. } else {
  276. stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
  277. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  278. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb,
  279. ndlp);
  280. return 0;
  281. }
  282. }
  283. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  284. lp = (uint32_t *) pcmd->virt;
  285. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  286. if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3) == 0)) {
  287. /* Reject this request because invalid parameters */
  288. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  289. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  290. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  291. return 0;
  292. }
  293. icmd = &cmdiocb->iocb;
  294. /* PLOGI chkparm OK */
  295. lpfc_printf_log(phba,
  296. KERN_INFO,
  297. LOG_ELS,
  298. "%d:0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
  299. phba->brd_no,
  300. ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
  301. ndlp->nlp_rpi);
  302. if ((phba->cfg_fcp_class == 2) &&
  303. (sp->cls2.classValid)) {
  304. ndlp->nlp_fcp_info |= CLASS2;
  305. } else {
  306. ndlp->nlp_fcp_info |= CLASS3;
  307. }
  308. ndlp->nlp_class_sup = 0;
  309. if (sp->cls1.classValid)
  310. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  311. if (sp->cls2.classValid)
  312. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  313. if (sp->cls3.classValid)
  314. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  315. if (sp->cls4.classValid)
  316. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  317. ndlp->nlp_maxframe =
  318. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
  319. /* no need to reg_login if we are already in one of these states */
  320. switch (ndlp->nlp_state) {
  321. case NLP_STE_NPR_NODE:
  322. if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
  323. break;
  324. case NLP_STE_REG_LOGIN_ISSUE:
  325. case NLP_STE_PRLI_ISSUE:
  326. case NLP_STE_UNMAPPED_NODE:
  327. case NLP_STE_MAPPED_NODE:
  328. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, 0);
  329. return 1;
  330. }
  331. if ((phba->fc_flag & FC_PT2PT)
  332. && !(phba->fc_flag & FC_PT2PT_PLOGI)) {
  333. /* rcv'ed PLOGI decides what our NPortId will be */
  334. phba->fc_myDID = icmd->un.rcvels.parmRo;
  335. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  336. if (mbox == NULL)
  337. goto out;
  338. lpfc_config_link(phba, mbox);
  339. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  340. rc = lpfc_sli_issue_mbox
  341. (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
  342. if (rc == MBX_NOT_FINISHED) {
  343. mempool_free( mbox, phba->mbox_mem_pool);
  344. goto out;
  345. }
  346. lpfc_can_disctmo(phba);
  347. }
  348. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  349. if (mbox == NULL)
  350. goto out;
  351. if (lpfc_reg_login(phba, icmd->un.rcvels.remoteID,
  352. (uint8_t *) sp, mbox, 0)) {
  353. mempool_free( mbox, phba->mbox_mem_pool);
  354. goto out;
  355. }
  356. /* ACC PLOGI rsp command needs to execute first,
  357. * queue this mbox command to be processed later.
  358. */
  359. mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
  360. mbox->context2 = ndlp;
  361. ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
  362. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
  363. return 1;
  364. out:
  365. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  366. stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
  367. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  368. return 0;
  369. }
  370. static int
  371. lpfc_rcv_padisc(struct lpfc_hba * phba,
  372. struct lpfc_nodelist * ndlp,
  373. struct lpfc_iocbq *cmdiocb)
  374. {
  375. struct lpfc_dmabuf *pcmd;
  376. struct serv_parm *sp;
  377. struct lpfc_name *pnn, *ppn;
  378. struct ls_rjt stat;
  379. ADISC *ap;
  380. IOCB_t *icmd;
  381. uint32_t *lp;
  382. uint32_t cmd;
  383. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  384. lp = (uint32_t *) pcmd->virt;
  385. cmd = *lp++;
  386. if (cmd == ELS_CMD_ADISC) {
  387. ap = (ADISC *) lp;
  388. pnn = (struct lpfc_name *) & ap->nodeName;
  389. ppn = (struct lpfc_name *) & ap->portName;
  390. } else {
  391. sp = (struct serv_parm *) lp;
  392. pnn = (struct lpfc_name *) & sp->nodeName;
  393. ppn = (struct lpfc_name *) & sp->portName;
  394. }
  395. icmd = &cmdiocb->iocb;
  396. if ((icmd->ulpStatus == 0) &&
  397. (lpfc_check_adisc(phba, ndlp, pnn, ppn))) {
  398. if (cmd == ELS_CMD_ADISC) {
  399. lpfc_els_rsp_adisc_acc(phba, cmdiocb, ndlp);
  400. } else {
  401. lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp,
  402. NULL, 0);
  403. }
  404. return 1;
  405. }
  406. /* Reject this request because invalid parameters */
  407. stat.un.b.lsRjtRsvd0 = 0;
  408. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  409. stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
  410. stat.un.b.vendorUnique = 0;
  411. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  412. /* 1 sec timeout */
  413. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  414. spin_lock_irq(phba->host->host_lock);
  415. ndlp->nlp_flag |= NLP_DELAY_TMO;
  416. spin_unlock_irq(phba->host->host_lock);
  417. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  418. ndlp->nlp_prev_state = ndlp->nlp_state;
  419. ndlp->nlp_state = NLP_STE_NPR_NODE;
  420. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  421. return 0;
  422. }
  423. static int
  424. lpfc_rcv_logo(struct lpfc_hba * phba,
  425. struct lpfc_nodelist * ndlp,
  426. struct lpfc_iocbq *cmdiocb)
  427. {
  428. /* Put ndlp on NPR list with 1 sec timeout for plogi, ACC logo */
  429. /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
  430. * PLOGIs during LOGO storms from a device.
  431. */
  432. ndlp->nlp_flag |= NLP_LOGO_ACC;
  433. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  434. if (!(ndlp->nlp_type & NLP_FABRIC) ||
  435. (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
  436. /* Only try to re-login if this is NOT a Fabric Node */
  437. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  438. spin_lock_irq(phba->host->host_lock);
  439. ndlp->nlp_flag |= NLP_DELAY_TMO;
  440. spin_unlock_irq(phba->host->host_lock);
  441. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  442. ndlp->nlp_prev_state = ndlp->nlp_state;
  443. ndlp->nlp_state = NLP_STE_NPR_NODE;
  444. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  445. } else {
  446. ndlp->nlp_prev_state = ndlp->nlp_state;
  447. ndlp->nlp_state = NLP_STE_UNUSED_NODE;
  448. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  449. }
  450. spin_lock_irq(phba->host->host_lock);
  451. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  452. spin_unlock_irq(phba->host->host_lock);
  453. /* The driver has to wait until the ACC completes before it continues
  454. * processing the LOGO. The action will resume in
  455. * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
  456. * unreg_login, the driver waits so the ACC does not get aborted.
  457. */
  458. return 0;
  459. }
  460. static void
  461. lpfc_rcv_prli(struct lpfc_hba * phba,
  462. struct lpfc_nodelist * ndlp,
  463. struct lpfc_iocbq *cmdiocb)
  464. {
  465. struct lpfc_dmabuf *pcmd;
  466. uint32_t *lp;
  467. PRLI *npr;
  468. struct fc_rport *rport = ndlp->rport;
  469. u32 roles;
  470. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  471. lp = (uint32_t *) pcmd->virt;
  472. npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
  473. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  474. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  475. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  476. (npr->prliType == PRLI_FCP_TYPE)) {
  477. if (npr->initiatorFunc)
  478. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  479. if (npr->targetFunc)
  480. ndlp->nlp_type |= NLP_FCP_TARGET;
  481. if (npr->Retry)
  482. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  483. }
  484. if (rport) {
  485. /* We need to update the rport role values */
  486. roles = FC_RPORT_ROLE_UNKNOWN;
  487. if (ndlp->nlp_type & NLP_FCP_INITIATOR)
  488. roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  489. if (ndlp->nlp_type & NLP_FCP_TARGET)
  490. roles |= FC_RPORT_ROLE_FCP_TARGET;
  491. fc_remote_port_rolechg(rport, roles);
  492. }
  493. }
  494. static uint32_t
  495. lpfc_disc_set_adisc(struct lpfc_hba * phba,
  496. struct lpfc_nodelist * ndlp)
  497. {
  498. /* Check config parameter use-adisc or FCP-2 */
  499. if ((phba->cfg_use_adisc == 0) &&
  500. !(phba->fc_flag & FC_RSCN_MODE)) {
  501. if (!(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE))
  502. return 0;
  503. }
  504. spin_lock_irq(phba->host->host_lock);
  505. ndlp->nlp_flag |= NLP_NPR_ADISC;
  506. spin_unlock_irq(phba->host->host_lock);
  507. return 1;
  508. }
  509. static uint32_t
  510. lpfc_disc_illegal(struct lpfc_hba * phba,
  511. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  512. {
  513. lpfc_printf_log(phba,
  514. KERN_ERR,
  515. LOG_DISCOVERY,
  516. "%d:0253 Illegal State Transition: node x%x event x%x, "
  517. "state x%x Data: x%x x%x\n",
  518. phba->brd_no,
  519. ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
  520. ndlp->nlp_flag);
  521. return ndlp->nlp_state;
  522. }
  523. /* Start of Discovery State Machine routines */
  524. static uint32_t
  525. lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
  526. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  527. {
  528. struct lpfc_iocbq *cmdiocb;
  529. cmdiocb = (struct lpfc_iocbq *) arg;
  530. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  531. ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
  532. ndlp->nlp_state = NLP_STE_UNUSED_NODE;
  533. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  534. return ndlp->nlp_state;
  535. }
  536. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  537. return NLP_STE_FREED_NODE;
  538. }
  539. static uint32_t
  540. lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
  541. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  542. {
  543. lpfc_issue_els_logo(phba, ndlp, 0);
  544. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  545. return ndlp->nlp_state;
  546. }
  547. static uint32_t
  548. lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
  549. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  550. {
  551. struct lpfc_iocbq *cmdiocb;
  552. cmdiocb = (struct lpfc_iocbq *) arg;
  553. spin_lock_irq(phba->host->host_lock);
  554. ndlp->nlp_flag |= NLP_LOGO_ACC;
  555. spin_unlock_irq(phba->host->host_lock);
  556. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  557. lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
  558. return ndlp->nlp_state;
  559. }
  560. static uint32_t
  561. lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
  562. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  563. {
  564. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  565. return NLP_STE_FREED_NODE;
  566. }
  567. static uint32_t
  568. lpfc_device_rm_unused_node(struct lpfc_hba * phba,
  569. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  570. {
  571. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  572. return NLP_STE_FREED_NODE;
  573. }
  574. static uint32_t
  575. lpfc_rcv_plogi_plogi_issue(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
  576. void *arg, uint32_t evt)
  577. {
  578. struct lpfc_iocbq *cmdiocb = arg;
  579. struct lpfc_dmabuf *pcmd;
  580. struct serv_parm *sp;
  581. uint32_t *lp;
  582. struct ls_rjt stat;
  583. int port_cmp;
  584. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  585. lp = (uint32_t *) pcmd->virt;
  586. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  587. memset(&stat, 0, sizeof (struct ls_rjt));
  588. /* For a PLOGI, we only accept if our portname is less
  589. * than the remote portname.
  590. */
  591. phba->fc_stat.elsLogiCol++;
  592. port_cmp = memcmp(&phba->fc_portname, &sp->portName,
  593. sizeof (struct lpfc_name));
  594. if (port_cmp >= 0) {
  595. /* Reject this request because the remote node will accept
  596. ours */
  597. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  598. stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
  599. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  600. } else {
  601. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  602. } /* if our portname was less */
  603. return ndlp->nlp_state;
  604. }
  605. static uint32_t
  606. lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
  607. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  608. {
  609. struct lpfc_iocbq *cmdiocb;
  610. cmdiocb = (struct lpfc_iocbq *) arg;
  611. /* software abort outstanding PLOGI */
  612. lpfc_els_abort(phba, ndlp, 1);
  613. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  614. return ndlp->nlp_state;
  615. }
  616. static uint32_t
  617. lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
  618. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  619. {
  620. struct lpfc_iocbq *cmdiocb;
  621. cmdiocb = (struct lpfc_iocbq *) arg;
  622. /* software abort outstanding PLOGI */
  623. lpfc_els_abort(phba, ndlp, 1);
  624. if (evt == NLP_EVT_RCV_LOGO) {
  625. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  626. } else {
  627. lpfc_issue_els_logo(phba, ndlp, 0);
  628. }
  629. /* Put ndlp in npr list set plogi timer for 1 sec */
  630. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  631. spin_lock_irq(phba->host->host_lock);
  632. ndlp->nlp_flag |= NLP_DELAY_TMO;
  633. spin_unlock_irq(phba->host->host_lock);
  634. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  635. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  636. ndlp->nlp_state = NLP_STE_NPR_NODE;
  637. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  638. return ndlp->nlp_state;
  639. }
  640. static uint32_t
  641. lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
  642. struct lpfc_nodelist * ndlp, void *arg,
  643. uint32_t evt)
  644. {
  645. struct lpfc_iocbq *cmdiocb, *rspiocb;
  646. struct lpfc_dmabuf *pcmd, *prsp;
  647. uint32_t *lp;
  648. IOCB_t *irsp;
  649. struct serv_parm *sp;
  650. LPFC_MBOXQ_t *mbox;
  651. cmdiocb = (struct lpfc_iocbq *) arg;
  652. rspiocb = cmdiocb->context_un.rsp_iocb;
  653. if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
  654. /* Recovery from PLOGI collision logic */
  655. return ndlp->nlp_state;
  656. }
  657. irsp = &rspiocb->iocb;
  658. if (irsp->ulpStatus)
  659. goto out;
  660. pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
  661. prsp = list_get_first(&pcmd->list,
  662. struct lpfc_dmabuf,
  663. list);
  664. lp = (uint32_t *) prsp->virt;
  665. sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
  666. if (!lpfc_check_sparm(phba, ndlp, sp, CLASS3))
  667. goto out;
  668. /* PLOGI chkparm OK */
  669. lpfc_printf_log(phba,
  670. KERN_INFO,
  671. LOG_ELS,
  672. "%d:0121 PLOGI chkparm OK "
  673. "Data: x%x x%x x%x x%x\n",
  674. phba->brd_no,
  675. ndlp->nlp_DID, ndlp->nlp_state,
  676. ndlp->nlp_flag, ndlp->nlp_rpi);
  677. if ((phba->cfg_fcp_class == 2) &&
  678. (sp->cls2.classValid)) {
  679. ndlp->nlp_fcp_info |= CLASS2;
  680. } else {
  681. ndlp->nlp_fcp_info |= CLASS3;
  682. }
  683. ndlp->nlp_class_sup = 0;
  684. if (sp->cls1.classValid)
  685. ndlp->nlp_class_sup |= FC_COS_CLASS1;
  686. if (sp->cls2.classValid)
  687. ndlp->nlp_class_sup |= FC_COS_CLASS2;
  688. if (sp->cls3.classValid)
  689. ndlp->nlp_class_sup |= FC_COS_CLASS3;
  690. if (sp->cls4.classValid)
  691. ndlp->nlp_class_sup |= FC_COS_CLASS4;
  692. ndlp->nlp_maxframe =
  693. ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
  694. sp->cmn.bbRcvSizeLsb;
  695. if (!(mbox = mempool_alloc(phba->mbox_mem_pool,
  696. GFP_KERNEL)))
  697. goto out;
  698. lpfc_unreg_rpi(phba, ndlp);
  699. if (lpfc_reg_login
  700. (phba, irsp->un.elsreq64.remoteID,
  701. (uint8_t *) sp, mbox, 0) == 0) {
  702. /* set_slim mailbox command needs to
  703. * execute first, queue this command to
  704. * be processed later.
  705. */
  706. switch (ndlp->nlp_DID) {
  707. case NameServer_DID:
  708. mbox->mbox_cmpl =
  709. lpfc_mbx_cmpl_ns_reg_login;
  710. break;
  711. case FDMI_DID:
  712. mbox->mbox_cmpl =
  713. lpfc_mbx_cmpl_fdmi_reg_login;
  714. break;
  715. default:
  716. mbox->mbox_cmpl =
  717. lpfc_mbx_cmpl_reg_login;
  718. }
  719. mbox->context2 = ndlp;
  720. if (lpfc_sli_issue_mbox(phba, mbox,
  721. (MBX_NOWAIT | MBX_STOP_IOCB))
  722. != MBX_NOT_FINISHED) {
  723. ndlp->nlp_state =
  724. NLP_STE_REG_LOGIN_ISSUE;
  725. lpfc_nlp_list(phba, ndlp,
  726. NLP_REGLOGIN_LIST);
  727. return ndlp->nlp_state;
  728. }
  729. mempool_free(mbox, phba->mbox_mem_pool);
  730. } else {
  731. mempool_free(mbox, phba->mbox_mem_pool);
  732. }
  733. out:
  734. /* Free this node since the driver cannot login or has the wrong
  735. sparm */
  736. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  737. return NLP_STE_FREED_NODE;
  738. }
  739. static uint32_t
  740. lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
  741. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  742. {
  743. /* software abort outstanding PLOGI */
  744. lpfc_els_abort(phba, ndlp, 1);
  745. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  746. return NLP_STE_FREED_NODE;
  747. }
  748. static uint32_t
  749. lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
  750. struct lpfc_nodelist * ndlp, void *arg,
  751. uint32_t evt)
  752. {
  753. /* software abort outstanding PLOGI */
  754. lpfc_els_abort(phba, ndlp, 1);
  755. ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
  756. ndlp->nlp_state = NLP_STE_NPR_NODE;
  757. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  758. spin_lock_irq(phba->host->host_lock);
  759. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  760. spin_unlock_irq(phba->host->host_lock);
  761. return ndlp->nlp_state;
  762. }
  763. static uint32_t
  764. lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
  765. struct lpfc_nodelist * ndlp, void *arg,
  766. uint32_t evt)
  767. {
  768. struct lpfc_iocbq *cmdiocb;
  769. /* software abort outstanding ADISC */
  770. lpfc_els_abort(phba, ndlp, 1);
  771. cmdiocb = (struct lpfc_iocbq *) arg;
  772. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  773. return ndlp->nlp_state;
  774. }
  775. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  776. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  777. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  778. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  779. return ndlp->nlp_state;
  780. }
  781. static uint32_t
  782. lpfc_rcv_prli_adisc_issue(struct lpfc_hba * phba,
  783. struct lpfc_nodelist * ndlp, void *arg,
  784. uint32_t evt)
  785. {
  786. struct lpfc_iocbq *cmdiocb;
  787. cmdiocb = (struct lpfc_iocbq *) arg;
  788. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  789. return ndlp->nlp_state;
  790. }
  791. static uint32_t
  792. lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
  793. struct lpfc_nodelist * ndlp, void *arg,
  794. uint32_t evt)
  795. {
  796. struct lpfc_iocbq *cmdiocb;
  797. cmdiocb = (struct lpfc_iocbq *) arg;
  798. /* software abort outstanding ADISC */
  799. lpfc_els_abort(phba, ndlp, 0);
  800. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  801. return ndlp->nlp_state;
  802. }
  803. static uint32_t
  804. lpfc_rcv_padisc_adisc_issue(struct lpfc_hba * phba,
  805. struct lpfc_nodelist * ndlp, void *arg,
  806. uint32_t evt)
  807. {
  808. struct lpfc_iocbq *cmdiocb;
  809. cmdiocb = (struct lpfc_iocbq *) arg;
  810. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  811. return ndlp->nlp_state;
  812. }
  813. static uint32_t
  814. lpfc_rcv_prlo_adisc_issue(struct lpfc_hba * phba,
  815. struct lpfc_nodelist * ndlp, void *arg,
  816. uint32_t evt)
  817. {
  818. struct lpfc_iocbq *cmdiocb;
  819. cmdiocb = (struct lpfc_iocbq *) arg;
  820. /* Treat like rcv logo */
  821. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  822. return ndlp->nlp_state;
  823. }
  824. static uint32_t
  825. lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
  826. struct lpfc_nodelist * ndlp, void *arg,
  827. uint32_t evt)
  828. {
  829. struct lpfc_iocbq *cmdiocb, *rspiocb;
  830. IOCB_t *irsp;
  831. ADISC *ap;
  832. cmdiocb = (struct lpfc_iocbq *) arg;
  833. rspiocb = cmdiocb->context_un.rsp_iocb;
  834. ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  835. irsp = &rspiocb->iocb;
  836. if ((irsp->ulpStatus) ||
  837. (!lpfc_check_adisc(phba, ndlp, &ap->nodeName, &ap->portName))) {
  838. /* 1 sec timeout */
  839. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
  840. spin_lock_irq(phba->host->host_lock);
  841. ndlp->nlp_flag |= NLP_DELAY_TMO;
  842. spin_unlock_irq(phba->host->host_lock);
  843. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  844. memset(&ndlp->nlp_nodename, 0, sizeof (struct lpfc_name));
  845. memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
  846. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  847. ndlp->nlp_state = NLP_STE_NPR_NODE;
  848. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  849. lpfc_unreg_rpi(phba, ndlp);
  850. return ndlp->nlp_state;
  851. }
  852. if (ndlp->nlp_type & NLP_FCP_TARGET) {
  853. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  854. ndlp->nlp_state = NLP_STE_MAPPED_NODE;
  855. lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
  856. } else {
  857. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  858. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  859. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  860. }
  861. return ndlp->nlp_state;
  862. }
  863. static uint32_t
  864. lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
  865. struct lpfc_nodelist * ndlp, void *arg,
  866. uint32_t evt)
  867. {
  868. /* software abort outstanding ADISC */
  869. lpfc_els_abort(phba, ndlp, 1);
  870. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  871. return NLP_STE_FREED_NODE;
  872. }
  873. static uint32_t
  874. lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
  875. struct lpfc_nodelist * ndlp, void *arg,
  876. uint32_t evt)
  877. {
  878. /* software abort outstanding ADISC */
  879. lpfc_els_abort(phba, ndlp, 1);
  880. ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
  881. ndlp->nlp_state = NLP_STE_NPR_NODE;
  882. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  883. spin_lock_irq(phba->host->host_lock);
  884. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  885. ndlp->nlp_flag |= NLP_NPR_ADISC;
  886. spin_unlock_irq(phba->host->host_lock);
  887. return ndlp->nlp_state;
  888. }
  889. static uint32_t
  890. lpfc_rcv_plogi_reglogin_issue(struct lpfc_hba * phba,
  891. struct lpfc_nodelist * ndlp, void *arg,
  892. uint32_t evt)
  893. {
  894. struct lpfc_iocbq *cmdiocb;
  895. cmdiocb = (struct lpfc_iocbq *) arg;
  896. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  897. return ndlp->nlp_state;
  898. }
  899. static uint32_t
  900. lpfc_rcv_prli_reglogin_issue(struct lpfc_hba * phba,
  901. struct lpfc_nodelist * ndlp, void *arg,
  902. uint32_t evt)
  903. {
  904. struct lpfc_iocbq *cmdiocb;
  905. cmdiocb = (struct lpfc_iocbq *) arg;
  906. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  907. return ndlp->nlp_state;
  908. }
  909. static uint32_t
  910. lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
  911. struct lpfc_nodelist * ndlp, void *arg,
  912. uint32_t evt)
  913. {
  914. struct lpfc_iocbq *cmdiocb;
  915. cmdiocb = (struct lpfc_iocbq *) arg;
  916. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  917. return ndlp->nlp_state;
  918. }
  919. static uint32_t
  920. lpfc_rcv_padisc_reglogin_issue(struct lpfc_hba * phba,
  921. struct lpfc_nodelist * ndlp, void *arg,
  922. uint32_t evt)
  923. {
  924. struct lpfc_iocbq *cmdiocb;
  925. cmdiocb = (struct lpfc_iocbq *) arg;
  926. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  927. return ndlp->nlp_state;
  928. }
  929. static uint32_t
  930. lpfc_rcv_prlo_reglogin_issue(struct lpfc_hba * phba,
  931. struct lpfc_nodelist * ndlp, void *arg,
  932. uint32_t evt)
  933. {
  934. struct lpfc_iocbq *cmdiocb;
  935. cmdiocb = (struct lpfc_iocbq *) arg;
  936. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  937. return ndlp->nlp_state;
  938. }
  939. static uint32_t
  940. lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
  941. struct lpfc_nodelist * ndlp,
  942. void *arg, uint32_t evt)
  943. {
  944. LPFC_MBOXQ_t *pmb;
  945. MAILBOX_t *mb;
  946. uint32_t did;
  947. pmb = (LPFC_MBOXQ_t *) arg;
  948. mb = &pmb->mb;
  949. did = mb->un.varWords[1];
  950. if (mb->mbxStatus) {
  951. /* RegLogin failed */
  952. lpfc_printf_log(phba,
  953. KERN_ERR,
  954. LOG_DISCOVERY,
  955. "%d:0246 RegLogin failed Data: x%x x%x x%x\n",
  956. phba->brd_no,
  957. did, mb->mbxStatus, phba->hba_state);
  958. /* Put ndlp in npr list set plogi timer for 1 sec */
  959. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  960. spin_lock_irq(phba->host->host_lock);
  961. ndlp->nlp_flag |= NLP_DELAY_TMO;
  962. spin_unlock_irq(phba->host->host_lock);
  963. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  964. lpfc_issue_els_logo(phba, ndlp, 0);
  965. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  966. ndlp->nlp_state = NLP_STE_NPR_NODE;
  967. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  968. return ndlp->nlp_state;
  969. }
  970. ndlp->nlp_rpi = mb->un.varWords[0];
  971. /* Only if we are not a fabric nport do we issue PRLI */
  972. if (!(ndlp->nlp_type & NLP_FABRIC)) {
  973. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  974. ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
  975. lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
  976. lpfc_issue_els_prli(phba, ndlp, 0);
  977. } else {
  978. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  979. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  980. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  981. }
  982. return ndlp->nlp_state;
  983. }
  984. static uint32_t
  985. lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
  986. struct lpfc_nodelist * ndlp, void *arg,
  987. uint32_t evt)
  988. {
  989. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  990. return NLP_STE_FREED_NODE;
  991. }
  992. static uint32_t
  993. lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
  994. struct lpfc_nodelist * ndlp, void *arg,
  995. uint32_t evt)
  996. {
  997. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  998. ndlp->nlp_state = NLP_STE_NPR_NODE;
  999. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1000. spin_lock_irq(phba->host->host_lock);
  1001. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1002. spin_unlock_irq(phba->host->host_lock);
  1003. return ndlp->nlp_state;
  1004. }
  1005. static uint32_t
  1006. lpfc_rcv_plogi_prli_issue(struct lpfc_hba * phba,
  1007. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1008. {
  1009. struct lpfc_iocbq *cmdiocb;
  1010. cmdiocb = (struct lpfc_iocbq *) arg;
  1011. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1012. return ndlp->nlp_state;
  1013. }
  1014. static uint32_t
  1015. lpfc_rcv_prli_prli_issue(struct lpfc_hba * phba,
  1016. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1017. {
  1018. struct lpfc_iocbq *cmdiocb;
  1019. cmdiocb = (struct lpfc_iocbq *) arg;
  1020. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1021. return ndlp->nlp_state;
  1022. }
  1023. static uint32_t
  1024. lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
  1025. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1026. {
  1027. struct lpfc_iocbq *cmdiocb;
  1028. cmdiocb = (struct lpfc_iocbq *) arg;
  1029. /* Software abort outstanding PRLI before sending acc */
  1030. lpfc_els_abort(phba, ndlp, 1);
  1031. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1032. return ndlp->nlp_state;
  1033. }
  1034. static uint32_t
  1035. lpfc_rcv_padisc_prli_issue(struct lpfc_hba * phba,
  1036. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1037. {
  1038. struct lpfc_iocbq *cmdiocb;
  1039. cmdiocb = (struct lpfc_iocbq *) arg;
  1040. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1041. return ndlp->nlp_state;
  1042. }
  1043. /* This routine is envoked when we rcv a PRLO request from a nport
  1044. * we are logged into. We should send back a PRLO rsp setting the
  1045. * appropriate bits.
  1046. * NEXT STATE = PRLI_ISSUE
  1047. */
  1048. static uint32_t
  1049. lpfc_rcv_prlo_prli_issue(struct lpfc_hba * phba,
  1050. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1051. {
  1052. struct lpfc_iocbq *cmdiocb;
  1053. cmdiocb = (struct lpfc_iocbq *) arg;
  1054. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  1055. return ndlp->nlp_state;
  1056. }
  1057. static uint32_t
  1058. lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
  1059. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1060. {
  1061. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1062. IOCB_t *irsp;
  1063. PRLI *npr;
  1064. cmdiocb = (struct lpfc_iocbq *) arg;
  1065. rspiocb = cmdiocb->context_un.rsp_iocb;
  1066. npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
  1067. irsp = &rspiocb->iocb;
  1068. if (irsp->ulpStatus) {
  1069. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1070. ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
  1071. lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
  1072. return ndlp->nlp_state;
  1073. }
  1074. /* Check out PRLI rsp */
  1075. ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
  1076. ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
  1077. if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
  1078. (npr->prliType == PRLI_FCP_TYPE)) {
  1079. if (npr->initiatorFunc)
  1080. ndlp->nlp_type |= NLP_FCP_INITIATOR;
  1081. if (npr->targetFunc)
  1082. ndlp->nlp_type |= NLP_FCP_TARGET;
  1083. if (npr->Retry)
  1084. ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
  1085. }
  1086. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1087. ndlp->nlp_state = NLP_STE_MAPPED_NODE;
  1088. lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
  1089. return ndlp->nlp_state;
  1090. }
  1091. /*! lpfc_device_rm_prli_issue
  1092. *
  1093. * \pre
  1094. * \post
  1095. * \param phba
  1096. * \param ndlp
  1097. * \param arg
  1098. * \param evt
  1099. * \return uint32_t
  1100. *
  1101. * \b Description:
  1102. * This routine is envoked when we a request to remove a nport we are in the
  1103. * process of PRLIing. We should software abort outstanding prli, unreg
  1104. * login, send a logout. We will change node state to UNUSED_NODE, put it
  1105. * on plogi list so it can be freed when LOGO completes.
  1106. *
  1107. */
  1108. static uint32_t
  1109. lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
  1110. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1111. {
  1112. /* software abort outstanding PRLI */
  1113. lpfc_els_abort(phba, ndlp, 1);
  1114. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1115. return NLP_STE_FREED_NODE;
  1116. }
  1117. /*! lpfc_device_recov_prli_issue
  1118. *
  1119. * \pre
  1120. * \post
  1121. * \param phba
  1122. * \param ndlp
  1123. * \param arg
  1124. * \param evt
  1125. * \return uint32_t
  1126. *
  1127. * \b Description:
  1128. * The routine is envoked when the state of a device is unknown, like
  1129. * during a link down. We should remove the nodelist entry from the
  1130. * unmapped list, issue a UNREG_LOGIN, do a software abort of the
  1131. * outstanding PRLI command, then free the node entry.
  1132. */
  1133. static uint32_t
  1134. lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
  1135. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1136. {
  1137. /* software abort outstanding PRLI */
  1138. lpfc_els_abort(phba, ndlp, 1);
  1139. ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
  1140. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1141. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1142. spin_lock_irq(phba->host->host_lock);
  1143. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1144. spin_unlock_irq(phba->host->host_lock);
  1145. return ndlp->nlp_state;
  1146. }
  1147. static uint32_t
  1148. lpfc_rcv_plogi_unmap_node(struct lpfc_hba * phba,
  1149. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1150. {
  1151. struct lpfc_iocbq *cmdiocb;
  1152. cmdiocb = (struct lpfc_iocbq *) arg;
  1153. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1154. return ndlp->nlp_state;
  1155. }
  1156. static uint32_t
  1157. lpfc_rcv_prli_unmap_node(struct lpfc_hba * phba,
  1158. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1159. {
  1160. struct lpfc_iocbq *cmdiocb;
  1161. cmdiocb = (struct lpfc_iocbq *) arg;
  1162. lpfc_rcv_prli(phba, ndlp, cmdiocb);
  1163. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1164. return ndlp->nlp_state;
  1165. }
  1166. static uint32_t
  1167. lpfc_rcv_logo_unmap_node(struct lpfc_hba * phba,
  1168. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1169. {
  1170. struct lpfc_iocbq *cmdiocb;
  1171. cmdiocb = (struct lpfc_iocbq *) arg;
  1172. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1173. return ndlp->nlp_state;
  1174. }
  1175. static uint32_t
  1176. lpfc_rcv_padisc_unmap_node(struct lpfc_hba * phba,
  1177. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1178. {
  1179. struct lpfc_iocbq *cmdiocb;
  1180. cmdiocb = (struct lpfc_iocbq *) arg;
  1181. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1182. return ndlp->nlp_state;
  1183. }
  1184. static uint32_t
  1185. lpfc_rcv_prlo_unmap_node(struct lpfc_hba * phba,
  1186. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1187. {
  1188. struct lpfc_iocbq *cmdiocb;
  1189. cmdiocb = (struct lpfc_iocbq *) arg;
  1190. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  1191. return ndlp->nlp_state;
  1192. }
  1193. static uint32_t
  1194. lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
  1195. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1196. {
  1197. ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
  1198. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1199. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1200. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1201. lpfc_disc_set_adisc(phba, ndlp);
  1202. return ndlp->nlp_state;
  1203. }
  1204. static uint32_t
  1205. lpfc_rcv_plogi_mapped_node(struct lpfc_hba * phba,
  1206. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1207. {
  1208. struct lpfc_iocbq *cmdiocb;
  1209. cmdiocb = (struct lpfc_iocbq *) arg;
  1210. lpfc_rcv_plogi(phba, ndlp, cmdiocb);
  1211. return ndlp->nlp_state;
  1212. }
  1213. static uint32_t
  1214. lpfc_rcv_prli_mapped_node(struct lpfc_hba * phba,
  1215. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1216. {
  1217. struct lpfc_iocbq *cmdiocb;
  1218. cmdiocb = (struct lpfc_iocbq *) arg;
  1219. lpfc_els_rsp_prli_acc(phba, cmdiocb, ndlp);
  1220. return ndlp->nlp_state;
  1221. }
  1222. static uint32_t
  1223. lpfc_rcv_logo_mapped_node(struct lpfc_hba * phba,
  1224. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1225. {
  1226. struct lpfc_iocbq *cmdiocb;
  1227. cmdiocb = (struct lpfc_iocbq *) arg;
  1228. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1229. return ndlp->nlp_state;
  1230. }
  1231. static uint32_t
  1232. lpfc_rcv_padisc_mapped_node(struct lpfc_hba * phba,
  1233. struct lpfc_nodelist * ndlp, void *arg,
  1234. uint32_t evt)
  1235. {
  1236. struct lpfc_iocbq *cmdiocb;
  1237. cmdiocb = (struct lpfc_iocbq *) arg;
  1238. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1239. return ndlp->nlp_state;
  1240. }
  1241. static uint32_t
  1242. lpfc_rcv_prlo_mapped_node(struct lpfc_hba * phba,
  1243. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1244. {
  1245. struct lpfc_iocbq *cmdiocb;
  1246. cmdiocb = (struct lpfc_iocbq *) arg;
  1247. /* flush the target */
  1248. spin_lock_irq(phba->host->host_lock);
  1249. lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
  1250. ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
  1251. spin_unlock_irq(phba->host->host_lock);
  1252. /* Treat like rcv logo */
  1253. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1254. return ndlp->nlp_state;
  1255. }
  1256. static uint32_t
  1257. lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
  1258. struct lpfc_nodelist * ndlp, void *arg,
  1259. uint32_t evt)
  1260. {
  1261. ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
  1262. ndlp->nlp_state = NLP_STE_NPR_NODE;
  1263. lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
  1264. spin_lock_irq(phba->host->host_lock);
  1265. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1266. spin_unlock_irq(phba->host->host_lock);
  1267. lpfc_disc_set_adisc(phba, ndlp);
  1268. return ndlp->nlp_state;
  1269. }
  1270. static uint32_t
  1271. lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
  1272. struct lpfc_nodelist * ndlp, void *arg,
  1273. uint32_t evt)
  1274. {
  1275. struct lpfc_iocbq *cmdiocb;
  1276. cmdiocb = (struct lpfc_iocbq *) arg;
  1277. /* Ignore PLOGI if we have an outstanding LOGO */
  1278. if (ndlp->nlp_flag & NLP_LOGO_SND) {
  1279. return ndlp->nlp_state;
  1280. }
  1281. if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
  1282. spin_lock_irq(phba->host->host_lock);
  1283. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1284. spin_unlock_irq(phba->host->host_lock);
  1285. return ndlp->nlp_state;
  1286. }
  1287. /* send PLOGI immediately, move to PLOGI issue state */
  1288. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1289. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1290. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1291. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1292. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1293. }
  1294. return ndlp->nlp_state;
  1295. }
  1296. static uint32_t
  1297. lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
  1298. struct lpfc_nodelist * ndlp, void *arg,
  1299. uint32_t evt)
  1300. {
  1301. struct lpfc_iocbq *cmdiocb;
  1302. struct ls_rjt stat;
  1303. cmdiocb = (struct lpfc_iocbq *) arg;
  1304. memset(&stat, 0, sizeof (struct ls_rjt));
  1305. stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
  1306. stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
  1307. lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
  1308. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1309. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1310. spin_lock_irq(phba->host->host_lock);
  1311. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1312. spin_unlock_irq(phba->host->host_lock);
  1313. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1314. ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
  1315. lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
  1316. lpfc_issue_els_adisc(phba, ndlp, 0);
  1317. } else {
  1318. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1319. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1320. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1321. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1322. }
  1323. }
  1324. return ndlp->nlp_state;
  1325. }
  1326. static uint32_t
  1327. lpfc_rcv_logo_npr_node(struct lpfc_hba * phba,
  1328. struct lpfc_nodelist * ndlp, void *arg,
  1329. uint32_t evt)
  1330. {
  1331. struct lpfc_iocbq *cmdiocb;
  1332. cmdiocb = (struct lpfc_iocbq *) arg;
  1333. lpfc_rcv_logo(phba, ndlp, cmdiocb);
  1334. return ndlp->nlp_state;
  1335. }
  1336. static uint32_t
  1337. lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
  1338. struct lpfc_nodelist * ndlp, void *arg,
  1339. uint32_t evt)
  1340. {
  1341. struct lpfc_iocbq *cmdiocb;
  1342. cmdiocb = (struct lpfc_iocbq *) arg;
  1343. lpfc_rcv_padisc(phba, ndlp, cmdiocb);
  1344. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1345. if (ndlp->nlp_flag & NLP_NPR_ADISC) {
  1346. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1347. ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
  1348. lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
  1349. lpfc_issue_els_adisc(phba, ndlp, 0);
  1350. } else {
  1351. ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
  1352. ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
  1353. lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
  1354. lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
  1355. }
  1356. }
  1357. return ndlp->nlp_state;
  1358. }
  1359. static uint32_t
  1360. lpfc_rcv_prlo_npr_node(struct lpfc_hba * phba,
  1361. struct lpfc_nodelist * ndlp, void *arg,
  1362. uint32_t evt)
  1363. {
  1364. struct lpfc_iocbq *cmdiocb;
  1365. cmdiocb = (struct lpfc_iocbq *) arg;
  1366. spin_lock_irq(phba->host->host_lock);
  1367. ndlp->nlp_flag |= NLP_LOGO_ACC;
  1368. spin_unlock_irq(phba->host->host_lock);
  1369. lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
  1370. if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
  1371. mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
  1372. spin_lock_irq(phba->host->host_lock);
  1373. ndlp->nlp_flag |= NLP_DELAY_TMO;
  1374. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1375. spin_unlock_irq(phba->host->host_lock);
  1376. ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
  1377. } else {
  1378. spin_lock_irq(phba->host->host_lock);
  1379. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1380. spin_unlock_irq(phba->host->host_lock);
  1381. }
  1382. return ndlp->nlp_state;
  1383. }
  1384. static uint32_t
  1385. lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
  1386. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1387. {
  1388. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1389. cmdiocb = (struct lpfc_iocbq *) arg;
  1390. rspiocb = cmdiocb->context_un.rsp_iocb;
  1391. return ndlp->nlp_state;
  1392. }
  1393. static uint32_t
  1394. lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
  1395. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1396. {
  1397. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1398. cmdiocb = (struct lpfc_iocbq *) arg;
  1399. rspiocb = cmdiocb->context_un.rsp_iocb;
  1400. return ndlp->nlp_state;
  1401. }
  1402. static uint32_t
  1403. lpfc_cmpl_logo_npr_node(struct lpfc_hba * phba,
  1404. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1405. {
  1406. lpfc_unreg_rpi(phba, ndlp);
  1407. /* This routine does nothing, just return the current state */
  1408. return ndlp->nlp_state;
  1409. }
  1410. static uint32_t
  1411. lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
  1412. struct lpfc_nodelist * ndlp, void *arg,
  1413. uint32_t evt)
  1414. {
  1415. struct lpfc_iocbq *cmdiocb, *rspiocb;
  1416. cmdiocb = (struct lpfc_iocbq *) arg;
  1417. rspiocb = cmdiocb->context_un.rsp_iocb;
  1418. return ndlp->nlp_state;
  1419. }
  1420. static uint32_t
  1421. lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
  1422. struct lpfc_nodelist * ndlp, void *arg,
  1423. uint32_t evt)
  1424. {
  1425. LPFC_MBOXQ_t *pmb;
  1426. MAILBOX_t *mb;
  1427. pmb = (LPFC_MBOXQ_t *) arg;
  1428. mb = &pmb->mb;
  1429. if (!mb->mbxStatus)
  1430. ndlp->nlp_rpi = mb->un.varWords[0];
  1431. return ndlp->nlp_state;
  1432. }
  1433. static uint32_t
  1434. lpfc_device_rm_npr_node(struct lpfc_hba * phba,
  1435. struct lpfc_nodelist * ndlp, void *arg,
  1436. uint32_t evt)
  1437. {
  1438. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1439. return NLP_STE_FREED_NODE;
  1440. }
  1441. static uint32_t
  1442. lpfc_device_recov_npr_node(struct lpfc_hba * phba,
  1443. struct lpfc_nodelist * ndlp, void *arg,
  1444. uint32_t evt)
  1445. {
  1446. spin_lock_irq(phba->host->host_lock);
  1447. ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
  1448. spin_unlock_irq(phba->host->host_lock);
  1449. if (ndlp->nlp_flag & NLP_DELAY_TMO) {
  1450. lpfc_cancel_retry_delay_tmo(phba, ndlp);
  1451. }
  1452. return ndlp->nlp_state;
  1453. }
  1454. /* This next section defines the NPort Discovery State Machine */
  1455. /* There are 4 different double linked lists nodelist entries can reside on.
  1456. * The plogi list and adisc list are used when Link Up discovery or RSCN
  1457. * processing is needed. Each list holds the nodes that we will send PLOGI
  1458. * or ADISC on. These lists will keep track of what nodes will be effected
  1459. * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
  1460. * The unmapped_list will contain all nodes that we have successfully logged
  1461. * into at the Fibre Channel level. The mapped_list will contain all nodes
  1462. * that are mapped FCP targets.
  1463. */
  1464. /*
  1465. * The bind list is a list of undiscovered (potentially non-existent) nodes
  1466. * that we have saved binding information on. This information is used when
  1467. * nodes transition from the unmapped to the mapped list.
  1468. */
  1469. /* For UNUSED_NODE state, the node has just been allocated .
  1470. * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
  1471. * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
  1472. * and put on the unmapped list. For ADISC processing, the node is taken off
  1473. * the ADISC list and placed on either the mapped or unmapped list (depending
  1474. * on its previous state). Once on the unmapped list, a PRLI is issued and the
  1475. * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
  1476. * changed to UNMAPPED_NODE. If the completion indicates a mapped
  1477. * node, the node is taken off the unmapped list. The binding list is checked
  1478. * for a valid binding, or a binding is automatically assigned. If binding
  1479. * assignment is unsuccessful, the node is left on the unmapped list. If
  1480. * binding assignment is successful, the associated binding list entry (if
  1481. * any) is removed, and the node is placed on the mapped list.
  1482. */
  1483. /*
  1484. * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
  1485. * lists will receive a DEVICE_RECOVERY event. If the linkdown or nodev timers
  1486. * expire, all effected nodes will receive a DEVICE_RM event.
  1487. */
  1488. /*
  1489. * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
  1490. * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
  1491. * check, additional nodes may be added or removed (via DEVICE_RM) to / from
  1492. * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
  1493. * we will first process the ADISC list. 32 entries are processed initially and
  1494. * ADISC is initited for each one. Completions / Events for each node are
  1495. * funnelled thru the state machine. As each node finishes ADISC processing, it
  1496. * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
  1497. * waiting, and the ADISC list count is identically 0, then we are done. For
  1498. * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
  1499. * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
  1500. * list. 32 entries are processed initially and PLOGI is initited for each one.
  1501. * Completions / Events for each node are funnelled thru the state machine. As
  1502. * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
  1503. * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
  1504. * indentically 0, then we are done. We have now completed discovery / RSCN
  1505. * handling. Upon completion, ALL nodes should be on either the mapped or
  1506. * unmapped lists.
  1507. */
  1508. static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
  1509. (struct lpfc_hba *, struct lpfc_nodelist *, void *, uint32_t) = {
  1510. /* Action routine Event Current State */
  1511. lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
  1512. lpfc_rcv_els_unused_node, /* RCV_PRLI */
  1513. lpfc_rcv_logo_unused_node, /* RCV_LOGO */
  1514. lpfc_rcv_els_unused_node, /* RCV_ADISC */
  1515. lpfc_rcv_els_unused_node, /* RCV_PDISC */
  1516. lpfc_rcv_els_unused_node, /* RCV_PRLO */
  1517. lpfc_disc_illegal, /* CMPL_PLOGI */
  1518. lpfc_disc_illegal, /* CMPL_PRLI */
  1519. lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
  1520. lpfc_disc_illegal, /* CMPL_ADISC */
  1521. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1522. lpfc_device_rm_unused_node, /* DEVICE_RM */
  1523. lpfc_disc_illegal, /* DEVICE_RECOVERY */
  1524. lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
  1525. lpfc_rcv_els_plogi_issue, /* RCV_PRLI */
  1526. lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
  1527. lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
  1528. lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
  1529. lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
  1530. lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
  1531. lpfc_disc_illegal, /* CMPL_PRLI */
  1532. lpfc_disc_illegal, /* CMPL_LOGO */
  1533. lpfc_disc_illegal, /* CMPL_ADISC */
  1534. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1535. lpfc_device_rm_plogi_issue, /* DEVICE_RM */
  1536. lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
  1537. lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
  1538. lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
  1539. lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
  1540. lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
  1541. lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
  1542. lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
  1543. lpfc_disc_illegal, /* CMPL_PLOGI */
  1544. lpfc_disc_illegal, /* CMPL_PRLI */
  1545. lpfc_disc_illegal, /* CMPL_LOGO */
  1546. lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
  1547. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1548. lpfc_device_rm_adisc_issue, /* DEVICE_RM */
  1549. lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
  1550. lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
  1551. lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
  1552. lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
  1553. lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
  1554. lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
  1555. lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
  1556. lpfc_disc_illegal, /* CMPL_PLOGI */
  1557. lpfc_disc_illegal, /* CMPL_PRLI */
  1558. lpfc_disc_illegal, /* CMPL_LOGO */
  1559. lpfc_disc_illegal, /* CMPL_ADISC */
  1560. lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
  1561. lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
  1562. lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
  1563. lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
  1564. lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
  1565. lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
  1566. lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
  1567. lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
  1568. lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
  1569. lpfc_disc_illegal, /* CMPL_PLOGI */
  1570. lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
  1571. lpfc_disc_illegal, /* CMPL_LOGO */
  1572. lpfc_disc_illegal, /* CMPL_ADISC */
  1573. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1574. lpfc_device_rm_prli_issue, /* DEVICE_RM */
  1575. lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
  1576. lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
  1577. lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
  1578. lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
  1579. lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
  1580. lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
  1581. lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
  1582. lpfc_disc_illegal, /* CMPL_PLOGI */
  1583. lpfc_disc_illegal, /* CMPL_PRLI */
  1584. lpfc_disc_illegal, /* CMPL_LOGO */
  1585. lpfc_disc_illegal, /* CMPL_ADISC */
  1586. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1587. lpfc_disc_illegal, /* DEVICE_RM */
  1588. lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
  1589. lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
  1590. lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
  1591. lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
  1592. lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
  1593. lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
  1594. lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
  1595. lpfc_disc_illegal, /* CMPL_PLOGI */
  1596. lpfc_disc_illegal, /* CMPL_PRLI */
  1597. lpfc_disc_illegal, /* CMPL_LOGO */
  1598. lpfc_disc_illegal, /* CMPL_ADISC */
  1599. lpfc_disc_illegal, /* CMPL_REG_LOGIN */
  1600. lpfc_disc_illegal, /* DEVICE_RM */
  1601. lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
  1602. lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
  1603. lpfc_rcv_prli_npr_node, /* RCV_PRLI */
  1604. lpfc_rcv_logo_npr_node, /* RCV_LOGO */
  1605. lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
  1606. lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
  1607. lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
  1608. lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
  1609. lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
  1610. lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
  1611. lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
  1612. lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
  1613. lpfc_device_rm_npr_node, /* DEVICE_RM */
  1614. lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
  1615. };
  1616. int
  1617. lpfc_disc_state_machine(struct lpfc_hba * phba,
  1618. struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
  1619. {
  1620. uint32_t cur_state, rc;
  1621. uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
  1622. uint32_t);
  1623. ndlp->nlp_disc_refcnt++;
  1624. cur_state = ndlp->nlp_state;
  1625. /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
  1626. lpfc_printf_log(phba,
  1627. KERN_INFO,
  1628. LOG_DISCOVERY,
  1629. "%d:0211 DSM in event x%x on NPort x%x in state %d "
  1630. "Data: x%x\n",
  1631. phba->brd_no,
  1632. evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
  1633. func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
  1634. rc = (func) (phba, ndlp, arg, evt);
  1635. /* DSM out state <rc> on NPort <nlp_DID> */
  1636. lpfc_printf_log(phba,
  1637. KERN_INFO,
  1638. LOG_DISCOVERY,
  1639. "%d:0212 DSM out state %d on NPort x%x Data: x%x\n",
  1640. phba->brd_no,
  1641. rc, ndlp->nlp_DID, ndlp->nlp_flag);
  1642. ndlp->nlp_disc_refcnt--;
  1643. /* Check to see if ndlp removal is deferred */
  1644. if ((ndlp->nlp_disc_refcnt == 0)
  1645. && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
  1646. spin_lock_irq(phba->host->host_lock);
  1647. ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
  1648. spin_unlock_irq(phba->host->host_lock);
  1649. lpfc_nlp_remove(phba, ndlp);
  1650. return NLP_STE_FREED_NODE;
  1651. }
  1652. if (rc == NLP_STE_FREED_NODE)
  1653. return NLP_STE_FREED_NODE;
  1654. return rc;
  1655. }