lpfc_nportdisc.c 52 KB

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