lpfc_nportdisc.c 52 KB

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