lpfc_nportdisc.c 52 KB

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