1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
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 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
39 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
41 static int lpfc_max_els_tries = 3;
44 lpfc_els_chk_latt(struct lpfc_hba * phba)
46 struct lpfc_sli *psli;
53 if ((phba->hba_state >= LPFC_HBA_READY) ||
54 (phba->hba_state == LPFC_LINK_DOWN))
57 /* Read the HBA Host Attention Register */
58 spin_lock_irq(phba->host->host_lock);
59 ha_copy = readl(phba->HAregaddr);
60 spin_unlock_irq(phba->host->host_lock);
62 if (!(ha_copy & HA_LATT))
65 /* Pending Link Event during Discovery */
66 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
67 "%d:0237 Pending Link Event during "
68 "Discovery: State x%x\n",
69 phba->brd_no, phba->hba_state);
71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The
73 * LATT processing should call lpfc_linkdown() which
74 * will cleanup any left over in-progress discovery
77 spin_lock_irq(phba->host->host_lock);
78 phba->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(phba->host->host_lock);
81 if (phba->hba_state != LPFC_CLEAR_LA) {
82 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
83 phba->hba_state = LPFC_CLEAR_LA;
84 lpfc_clear_la(phba, mbox);
85 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
86 rc = lpfc_sli_issue_mbox (phba, mbox,
87 (MBX_NOWAIT | MBX_STOP_IOCB));
88 if (rc == MBX_NOT_FINISHED) {
89 mempool_free(mbox, phba->mbox_mem_pool);
90 phba->hba_state = LPFC_HBA_ERROR;
99 static struct lpfc_iocbq *
100 lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
101 uint16_t cmdSize, uint8_t retry, struct lpfc_nodelist * ndlp,
102 uint32_t did, uint32_t elscmd)
104 struct lpfc_sli_ring *pring;
105 struct lpfc_iocbq *elsiocb;
106 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
107 struct ulp_bde64 *bpl;
110 pring = &phba->sli.ring[LPFC_ELS_RING];
112 if (phba->hba_state < LPFC_LINK_UP)
115 /* Allocate buffer for command iocb */
116 spin_lock_irq(phba->host->host_lock);
117 elsiocb = lpfc_sli_get_iocbq(phba);
118 spin_unlock_irq(phba->host->host_lock);
122 icmd = &elsiocb->iocb;
124 /* fill in BDEs for command */
125 /* Allocate buffer for command payload */
126 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
127 ((pcmd->virt = lpfc_mbuf_alloc(phba,
128 MEM_PRI, &(pcmd->phys))) == 0)) {
131 spin_lock_irq(phba->host->host_lock);
132 lpfc_sli_release_iocbq(phba, elsiocb);
133 spin_unlock_irq(phba->host->host_lock);
137 INIT_LIST_HEAD(&pcmd->list);
139 /* Allocate buffer for response payload */
141 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
143 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
145 if (prsp == 0 || prsp->virt == 0) {
147 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
149 spin_lock_irq(phba->host->host_lock);
150 lpfc_sli_release_iocbq(phba, elsiocb);
151 spin_unlock_irq(phba->host->host_lock);
154 INIT_LIST_HEAD(&prsp->list);
159 /* Allocate buffer for Buffer ptr list */
160 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
162 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
164 if (pbuflist == 0 || pbuflist->virt == 0) {
165 spin_lock_irq(phba->host->host_lock);
166 lpfc_sli_release_iocbq(phba, elsiocb);
167 spin_unlock_irq(phba->host->host_lock);
168 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
169 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
176 INIT_LIST_HEAD(&pbuflist->list);
178 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
179 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
180 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
182 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
183 icmd->un.elsreq64.remoteID = did; /* DID */
184 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
186 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
187 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
190 icmd->ulpBdeCount = 1;
192 icmd->ulpClass = CLASS3;
194 bpl = (struct ulp_bde64 *) pbuflist->virt;
195 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
196 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
197 bpl->tus.f.bdeSize = cmdSize;
198 bpl->tus.f.bdeFlags = 0;
199 bpl->tus.w = le32_to_cpu(bpl->tus.w);
203 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
204 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
205 bpl->tus.f.bdeSize = FCELSSIZE;
206 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
207 bpl->tus.w = le32_to_cpu(bpl->tus.w);
210 /* Save for completion so we can release these resources */
211 elsiocb->context1 = (uint8_t *) ndlp;
212 elsiocb->context2 = (uint8_t *) pcmd;
213 elsiocb->context3 = (uint8_t *) pbuflist;
214 elsiocb->retry = retry;
215 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
218 list_add(&prsp->list, &pcmd->list);
222 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
223 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
224 "%d:0116 Xmit ELS command x%x to remote "
225 "NPORT x%x Data: x%x x%x\n",
226 phba->brd_no, elscmd,
227 did, icmd->ulpIoTag, phba->hba_state);
229 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
230 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
231 "%d:0117 Xmit ELS response x%x to remote "
232 "NPORT x%x Data: x%x x%x\n",
233 phba->brd_no, elscmd,
234 ndlp->nlp_DID, icmd->ulpIoTag, cmdSize);
242 lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
243 struct serv_parm *sp, IOCB_t *irsp)
248 spin_lock_irq(phba->host->host_lock);
249 phba->fc_flag |= FC_FABRIC;
250 spin_unlock_irq(phba->host->host_lock);
252 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
253 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
254 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
256 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
258 if (phba->fc_topology == TOPOLOGY_LOOP) {
259 spin_lock_irq(phba->host->host_lock);
260 phba->fc_flag |= FC_PUBLIC_LOOP;
261 spin_unlock_irq(phba->host->host_lock);
264 * If we are a N-port connected to a Fabric, fixup sparam's so
265 * logins to devices on remote loops work.
267 phba->fc_sparam.cmn.altBbCredit = 1;
270 phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
271 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
272 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
273 ndlp->nlp_class_sup = 0;
274 if (sp->cls1.classValid)
275 ndlp->nlp_class_sup |= FC_COS_CLASS1;
276 if (sp->cls2.classValid)
277 ndlp->nlp_class_sup |= FC_COS_CLASS2;
278 if (sp->cls3.classValid)
279 ndlp->nlp_class_sup |= FC_COS_CLASS3;
280 if (sp->cls4.classValid)
281 ndlp->nlp_class_sup |= FC_COS_CLASS4;
282 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
283 sp->cmn.bbRcvSizeLsb;
284 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
286 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
290 phba->hba_state = LPFC_FABRIC_CFG_LINK;
291 lpfc_config_link(phba, mbox);
292 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
294 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
295 if (rc == MBX_NOT_FINISHED)
298 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
302 if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0))
305 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
306 mbox->context2 = ndlp;
308 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
309 if (rc == MBX_NOT_FINISHED)
315 mempool_free(mbox, phba->mbox_mem_pool);
321 * We FLOGIed into an NPort, initiate pt2pt protocol
324 lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
325 struct serv_parm *sp)
330 spin_lock_irq(phba->host->host_lock);
331 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
332 spin_unlock_irq(phba->host->host_lock);
334 phba->fc_edtov = FF_DEF_EDTOV;
335 phba->fc_ratov = FF_DEF_RATOV;
336 rc = memcmp(&phba->fc_portname, &sp->portName,
337 sizeof(struct lpfc_name));
339 /* This side will initiate the PLOGI */
340 spin_lock_irq(phba->host->host_lock);
341 phba->fc_flag |= FC_PT2PT_PLOGI;
342 spin_unlock_irq(phba->host->host_lock);
345 * N_Port ID cannot be 0, set our to LocalID the other
346 * side will be RemoteID.
351 phba->fc_myDID = PT2PT_LocalID;
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
357 lpfc_config_link(phba, mbox);
359 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
360 rc = lpfc_sli_issue_mbox(phba, mbox,
361 MBX_NOWAIT | MBX_STOP_IOCB);
362 if (rc == MBX_NOT_FINISHED) {
363 mempool_free(mbox, phba->mbox_mem_pool);
366 mempool_free(ndlp, phba->nlp_mem_pool);
368 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, PT2PT_RemoteID);
371 * Cannot find existing Fabric ndlp, so allocate a
374 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
378 lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID);
381 memcpy(&ndlp->nlp_portname, &sp->portName,
382 sizeof(struct lpfc_name));
383 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
384 sizeof(struct lpfc_name));
385 ndlp->nlp_state = NLP_STE_NPR_NODE;
386 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
387 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
389 /* This side will wait for the PLOGI */
390 mempool_free( ndlp, phba->nlp_mem_pool);
393 spin_lock_irq(phba->host->host_lock);
394 phba->fc_flag |= FC_PT2PT;
395 spin_unlock_irq(phba->host->host_lock);
397 /* Start discovery - this should just do CLEAR_LA */
398 lpfc_disc_start(phba);
405 lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
406 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
408 IOCB_t *irsp = &rspiocb->iocb;
409 struct lpfc_nodelist *ndlp = cmdiocb->context1;
410 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
411 struct serv_parm *sp;
414 /* Check to see if link went down during discovery */
415 if (lpfc_els_chk_latt(phba)) {
416 lpfc_nlp_remove(phba, ndlp);
420 if (irsp->ulpStatus) {
421 /* Check for retry */
422 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
423 /* ELS command is being retried */
426 /* FLOGI failed, so there is no fabric */
427 spin_lock_irq(phba->host->host_lock);
428 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
429 spin_unlock_irq(phba->host->host_lock);
431 /* If private loop, then allow max outstandting els to be
432 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
433 * alpa map would take too long otherwise.
435 if (phba->alpa_map[0] == 0) {
436 phba->cfg_discovery_threads =
437 LPFC_MAX_DISC_THREADS;
441 lpfc_printf_log(phba,
444 "%d:0100 FLOGI failure Data: x%x x%x x%x\n",
446 irsp->ulpStatus, irsp->un.ulpWord[4],
452 * The FLogI succeeded. Sync the data for the CPU before
455 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
457 sp = prsp->virt + sizeof(uint32_t);
459 /* FLOGI completes successfully */
460 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
461 "%d:0101 FLOGI completes sucessfully "
462 "Data: x%x x%x x%x x%x\n",
464 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
465 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
467 if (phba->hba_state == LPFC_FLOGI) {
469 * If Common Service Parameters indicate Nport
470 * we are point to point, if Fport we are Fabric.
473 rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp);
475 rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp);
482 lpfc_nlp_remove(phba, ndlp);
484 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
485 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
486 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
487 /* FLOGI failed, so just use loop map to make discovery list */
488 lpfc_disc_list_loopmap(phba);
490 /* Start discovery */
491 lpfc_disc_start(phba);
495 lpfc_els_free_iocb(phba, cmdiocb);
499 lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
502 struct serv_parm *sp;
504 struct lpfc_iocbq *elsiocb;
505 struct lpfc_sli_ring *pring;
511 pring = &phba->sli.ring[LPFC_ELS_RING];
513 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
514 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
515 ndlp->nlp_DID, ELS_CMD_FLOGI);
519 icmd = &elsiocb->iocb;
520 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
522 /* For FLOGI request, remainder of payload is service parameters */
523 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
524 pcmd += sizeof (uint32_t);
525 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
526 sp = (struct serv_parm *) pcmd;
528 /* Setup CSPs accordingly for Fabric */
530 sp->cmn.w2.r_a_tov = 0;
531 sp->cls1.classValid = 0;
532 sp->cls2.seqDelivery = 1;
533 sp->cls3.seqDelivery = 1;
534 if (sp->cmn.fcphLow < FC_PH3)
535 sp->cmn.fcphLow = FC_PH3;
536 if (sp->cmn.fcphHigh < FC_PH3)
537 sp->cmn.fcphHigh = FC_PH3;
539 tmo = phba->fc_ratov;
540 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
541 lpfc_set_disctmo(phba);
542 phba->fc_ratov = tmo;
544 phba->fc_stat.elsXmitFLOGI++;
545 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
546 spin_lock_irq(phba->host->host_lock);
547 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
548 spin_unlock_irq(phba->host->host_lock);
549 if (rc == IOCB_ERROR) {
550 lpfc_els_free_iocb(phba, elsiocb);
557 lpfc_els_abort_flogi(struct lpfc_hba * phba)
559 struct lpfc_sli_ring *pring;
560 struct lpfc_iocbq *iocb, *next_iocb;
561 struct lpfc_nodelist *ndlp;
564 /* Abort outstanding I/O on NPort <nlp_DID> */
565 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
566 "%d:0201 Abort outstanding I/O on NPort x%x\n",
567 phba->brd_no, Fabric_DID);
569 pring = &phba->sli.ring[LPFC_ELS_RING];
572 * Check the txcmplq for an iocb that matches the nport the driver is
575 spin_lock_irq(phba->host->host_lock);
576 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
578 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
579 ndlp = (struct lpfc_nodelist *)(iocb->context1);
580 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
581 list_del(&iocb->list);
582 pring->txcmplq_cnt--;
584 if ((icmd->un.elsreq64.bdl.ulpIoTag32)) {
585 lpfc_sli_issue_abort_iotag32
588 if (iocb->iocb_cmpl) {
589 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
590 icmd->un.ulpWord[4] =
592 spin_unlock_irq(phba->host->host_lock);
593 (iocb->iocb_cmpl) (phba, iocb, iocb);
594 spin_lock_irq(phba->host->host_lock);
596 lpfc_sli_release_iocbq(phba, iocb);
600 spin_unlock_irq(phba->host->host_lock);
606 lpfc_initial_flogi(struct lpfc_hba * phba)
608 struct lpfc_nodelist *ndlp;
610 /* First look for the Fabric ndlp */
611 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, Fabric_DID);
613 /* Cannot find existing Fabric ndlp, so allocate a new one */
614 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
617 lpfc_nlp_init(phba, ndlp, Fabric_DID);
619 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
621 if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
622 mempool_free( ndlp, phba->nlp_mem_pool);
628 lpfc_more_plogi(struct lpfc_hba * phba)
632 if (phba->num_disc_nodes)
633 phba->num_disc_nodes--;
635 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
636 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
637 "%d:0232 Continue discovery with %d PLOGIs to go "
638 "Data: x%x x%x x%x\n",
639 phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
640 phba->fc_flag, phba->hba_state);
642 /* Check to see if there are more PLOGIs to be sent */
643 if (phba->fc_flag & FC_NLP_MORE) {
644 /* go thru NPR list and issue any remaining ELS PLOGIs */
645 sentplogi = lpfc_els_disc_plogi(phba);
650 static struct lpfc_nodelist *
651 lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
652 struct lpfc_nodelist *ndlp)
654 struct lpfc_nodelist *new_ndlp;
655 struct lpfc_dmabuf *pcmd, *prsp;
657 struct serv_parm *sp;
658 uint8_t name[sizeof (struct lpfc_name)];
661 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
662 prsp = (struct lpfc_dmabuf *) pcmd->list.next;
663 lp = (uint32_t *) prsp->virt;
664 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
666 /* Now we to find out if the NPort we are logging into, matches the WWPN
667 * we have for that ndlp. If not, we have some work to do.
669 new_ndlp = lpfc_findnode_wwpn(phba, NLP_SEARCH_ALL, &sp->portName);
671 memset(name, 0, sizeof (struct lpfc_name));
672 rc = memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name));
673 if (!rc || (new_ndlp == ndlp)) {
678 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
682 lpfc_nlp_init(phba, new_ndlp, ndlp->nlp_DID);
685 lpfc_unreg_rpi(phba, new_ndlp);
686 new_ndlp->nlp_prev_state = ndlp->nlp_state;
687 new_ndlp->nlp_DID = ndlp->nlp_DID;
688 new_ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
689 lpfc_nlp_list(phba, new_ndlp, NLP_PLOGI_LIST);
691 /* Move this back to NPR list */
692 lpfc_unreg_rpi(phba, ndlp);
693 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
694 ndlp->nlp_state = NLP_STE_NPR_NODE;
695 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
701 lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
702 struct lpfc_iocbq * rspiocb)
705 struct lpfc_nodelist *ndlp;
706 int disc, rc, did, type;
709 /* we pass cmdiocb to state machine which needs rspiocb as well */
710 cmdiocb->context_un.rsp_iocb = rspiocb;
712 irsp = &rspiocb->iocb;
713 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL,
714 irsp->un.elsreq64.remoteID);
718 /* Since ndlp can be freed in the disc state machine, note if this node
719 * is being used during discovery.
721 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
722 spin_lock_irq(phba->host->host_lock);
723 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
724 spin_unlock_irq(phba->host->host_lock);
727 /* PLOGI completes to NPort <nlp_DID> */
728 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
729 "%d:0102 PLOGI completes to NPort x%x "
730 "Data: x%x x%x x%x x%x x%x\n",
731 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
732 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
733 phba->num_disc_nodes);
735 /* Check to see if link went down during discovery */
736 if (lpfc_els_chk_latt(phba)) {
737 spin_lock_irq(phba->host->host_lock);
738 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
739 spin_unlock_irq(phba->host->host_lock);
743 /* ndlp could be freed in DSM, save these values now */
744 type = ndlp->nlp_type;
747 if (irsp->ulpStatus) {
748 /* Check for retry */
749 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
750 /* ELS command is being retried */
752 spin_lock_irq(phba->host->host_lock);
753 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
754 spin_unlock_irq(phba->host->host_lock);
760 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
761 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
762 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
763 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
764 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
765 rc = NLP_STE_FREED_NODE;
767 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
771 /* Good status, call state machine */
772 ndlp = lpfc_plogi_confirm_nport(phba, cmdiocb, ndlp);
773 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
777 if (disc && phba->num_disc_nodes) {
778 /* Check to see if there are more PLOGIs to be sent */
779 lpfc_more_plogi(phba);
781 if (phba->num_disc_nodes == 0) {
782 spin_lock_irq(phba->host->host_lock);
783 phba->fc_flag &= ~FC_NDISC_ACTIVE;
784 spin_unlock_irq(phba->host->host_lock);
786 lpfc_can_disctmo(phba);
787 if (phba->fc_flag & FC_RSCN_MODE) {
789 * Check to see if more RSCNs came in while
790 * we were processing this one.
792 if ((phba->fc_rscn_id_cnt == 0) &&
793 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
794 spin_lock_irq(phba->host->host_lock);
795 phba->fc_flag &= ~FC_RSCN_MODE;
796 spin_unlock_irq(phba->host->host_lock);
798 lpfc_els_handle_rscn(phba);
805 lpfc_els_free_iocb(phba, cmdiocb);
810 lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
812 struct serv_parm *sp;
814 struct lpfc_iocbq *elsiocb;
815 struct lpfc_sli_ring *pring;
816 struct lpfc_sli *psli;
821 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
823 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
824 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, NULL, did,
829 icmd = &elsiocb->iocb;
830 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
832 /* For PLOGI request, remainder of payload is service parameters */
833 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
834 pcmd += sizeof (uint32_t);
835 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
836 sp = (struct serv_parm *) pcmd;
838 if (sp->cmn.fcphLow < FC_PH_4_3)
839 sp->cmn.fcphLow = FC_PH_4_3;
841 if (sp->cmn.fcphHigh < FC_PH3)
842 sp->cmn.fcphHigh = FC_PH3;
844 phba->fc_stat.elsXmitPLOGI++;
845 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
846 spin_lock_irq(phba->host->host_lock);
847 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
848 spin_unlock_irq(phba->host->host_lock);
849 lpfc_els_free_iocb(phba, elsiocb);
852 spin_unlock_irq(phba->host->host_lock);
857 lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
858 struct lpfc_iocbq * rspiocb)
861 struct lpfc_sli *psli;
862 struct lpfc_nodelist *ndlp;
865 /* we pass cmdiocb to state machine which needs rspiocb as well */
866 cmdiocb->context_un.rsp_iocb = rspiocb;
868 irsp = &(rspiocb->iocb);
869 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
870 spin_lock_irq(phba->host->host_lock);
871 ndlp->nlp_flag &= ~NLP_PRLI_SND;
872 spin_unlock_irq(phba->host->host_lock);
874 /* PRLI completes to NPort <nlp_DID> */
875 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
876 "%d:0103 PRLI completes to NPort x%x "
877 "Data: x%x x%x x%x x%x\n",
878 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
879 irsp->un.ulpWord[4], irsp->ulpTimeout,
880 phba->num_disc_nodes);
882 phba->fc_prli_sent--;
883 /* Check to see if link went down during discovery */
884 if (lpfc_els_chk_latt(phba))
887 if (irsp->ulpStatus) {
888 /* Check for retry */
889 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
890 /* ELS command is being retried */
894 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
895 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
896 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
897 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
898 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
901 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
905 /* Good status, call state machine */
906 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
910 lpfc_els_free_iocb(phba, cmdiocb);
915 lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
920 struct lpfc_iocbq *elsiocb;
921 struct lpfc_sli_ring *pring;
922 struct lpfc_sli *psli;
927 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
929 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
930 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
931 ndlp->nlp_DID, ELS_CMD_PRLI);
935 icmd = &elsiocb->iocb;
936 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
938 /* For PRLI request, remainder of payload is service parameters */
939 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
940 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
941 pcmd += sizeof (uint32_t);
943 /* For PRLI, remainder of payload is PRLI parameter page */
946 * If our firmware version is 3.20 or later,
947 * set the following bits for FC-TAPE support.
949 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
950 npr->ConfmComplAllowed = 1;
952 npr->TaskRetryIdReq = 1;
954 npr->estabImagePair = 1;
955 npr->readXferRdyDis = 1;
957 /* For FCP support */
958 npr->prliType = PRLI_FCP_TYPE;
959 npr->initiatorFunc = 1;
961 phba->fc_stat.elsXmitPRLI++;
962 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
963 spin_lock_irq(phba->host->host_lock);
964 ndlp->nlp_flag |= NLP_PRLI_SND;
965 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
966 ndlp->nlp_flag &= ~NLP_PRLI_SND;
967 spin_unlock_irq(phba->host->host_lock);
968 lpfc_els_free_iocb(phba, elsiocb);
971 spin_unlock_irq(phba->host->host_lock);
972 phba->fc_prli_sent++;
977 lpfc_more_adisc(struct lpfc_hba * phba)
981 if (phba->num_disc_nodes)
982 phba->num_disc_nodes--;
984 /* Continue discovery with <num_disc_nodes> ADISCs to go */
985 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
986 "%d:0210 Continue discovery with %d ADISCs to go "
987 "Data: x%x x%x x%x\n",
988 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
989 phba->fc_flag, phba->hba_state);
991 /* Check to see if there are more ADISCs to be sent */
992 if (phba->fc_flag & FC_NLP_MORE) {
993 lpfc_set_disctmo(phba);
995 /* go thru NPR list and issue any remaining ELS ADISCs */
996 sentadisc = lpfc_els_disc_adisc(phba);
1002 lpfc_rscn_disc(struct lpfc_hba * phba)
1004 /* RSCN discovery */
1005 /* go thru NPR list and issue ELS PLOGIs */
1006 if (phba->fc_npr_cnt) {
1007 if (lpfc_els_disc_plogi(phba))
1010 if (phba->fc_flag & FC_RSCN_MODE) {
1011 /* Check to see if more RSCNs came in while we were
1012 * processing this one.
1014 if ((phba->fc_rscn_id_cnt == 0) &&
1015 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1016 spin_lock_irq(phba->host->host_lock);
1017 phba->fc_flag &= ~FC_RSCN_MODE;
1018 spin_unlock_irq(phba->host->host_lock);
1020 lpfc_els_handle_rscn(phba);
1026 lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1027 struct lpfc_iocbq * rspiocb)
1030 struct lpfc_sli *psli;
1031 struct lpfc_nodelist *ndlp;
1037 /* we pass cmdiocb to state machine which needs rspiocb as well */
1038 cmdiocb->context_un.rsp_iocb = rspiocb;
1040 irsp = &(rspiocb->iocb);
1041 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1043 /* Since ndlp can be freed in the disc state machine, note if this node
1044 * is being used during discovery.
1046 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1047 spin_lock_irq(phba->host->host_lock);
1048 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1049 spin_unlock_irq(phba->host->host_lock);
1051 /* ADISC completes to NPort <nlp_DID> */
1052 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1053 "%d:0104 ADISC completes to NPort x%x "
1054 "Data: x%x x%x x%x x%x x%x\n",
1055 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1056 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
1057 phba->num_disc_nodes);
1059 /* Check to see if link went down during discovery */
1060 if (lpfc_els_chk_latt(phba)) {
1061 spin_lock_irq(phba->host->host_lock);
1062 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1063 spin_unlock_irq(phba->host->host_lock);
1067 if (irsp->ulpStatus) {
1068 /* Check for retry */
1069 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1070 /* ELS command is being retried */
1072 spin_lock_irq(phba->host->host_lock);
1073 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1074 spin_unlock_irq(phba->host->host_lock);
1075 lpfc_set_disctmo(phba);
1080 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1081 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1082 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1083 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
1084 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
1085 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1086 NLP_EVT_CMPL_ADISC);
1089 /* Good status, call state machine */
1090 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1091 NLP_EVT_CMPL_ADISC);
1094 if (disc && phba->num_disc_nodes) {
1095 /* Check to see if there are more ADISCs to be sent */
1096 lpfc_more_adisc(phba);
1098 /* Check to see if we are done with ADISC authentication */
1099 if (phba->num_disc_nodes == 0) {
1100 lpfc_can_disctmo(phba);
1101 /* If we get here, there is nothing left to wait for */
1102 if ((phba->hba_state < LPFC_HBA_READY) &&
1103 (phba->hba_state != LPFC_CLEAR_LA)) {
1104 /* Link up discovery */
1105 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
1107 phba->hba_state = LPFC_CLEAR_LA;
1108 lpfc_clear_la(phba, mbox);
1110 lpfc_mbx_cmpl_clear_la;
1111 rc = lpfc_sli_issue_mbox
1113 (MBX_NOWAIT | MBX_STOP_IOCB));
1114 if (rc == MBX_NOT_FINISHED) {
1116 phba->mbox_mem_pool);
1117 lpfc_disc_flush_list(phba);
1118 psli->ring[(psli->ip_ring)].
1120 ~LPFC_STOP_IOCB_EVENT;
1121 psli->ring[(psli->fcp_ring)].
1123 ~LPFC_STOP_IOCB_EVENT;
1124 psli->ring[(psli->next_ring)].
1126 ~LPFC_STOP_IOCB_EVENT;
1132 lpfc_rscn_disc(phba);
1137 lpfc_els_free_iocb(phba, cmdiocb);
1142 lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1147 struct lpfc_iocbq *elsiocb;
1148 struct lpfc_sli_ring *pring;
1149 struct lpfc_sli *psli;
1154 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1156 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
1157 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1158 ndlp->nlp_DID, ELS_CMD_ADISC);
1162 icmd = &elsiocb->iocb;
1163 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1165 /* For ADISC request, remainder of payload is service parameters */
1166 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1167 pcmd += sizeof (uint32_t);
1169 /* Fill in ADISC payload */
1170 ap = (ADISC *) pcmd;
1171 ap->hardAL_PA = phba->fc_pref_ALPA;
1172 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1173 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1174 ap->DID = be32_to_cpu(phba->fc_myDID);
1176 phba->fc_stat.elsXmitADISC++;
1177 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1178 spin_lock_irq(phba->host->host_lock);
1179 ndlp->nlp_flag |= NLP_ADISC_SND;
1180 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1181 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1182 spin_unlock_irq(phba->host->host_lock);
1183 lpfc_els_free_iocb(phba, elsiocb);
1186 spin_unlock_irq(phba->host->host_lock);
1191 lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1192 struct lpfc_iocbq * rspiocb)
1195 struct lpfc_sli *psli;
1196 struct lpfc_nodelist *ndlp;
1199 /* we pass cmdiocb to state machine which needs rspiocb as well */
1200 cmdiocb->context_un.rsp_iocb = rspiocb;
1202 irsp = &(rspiocb->iocb);
1203 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1204 spin_lock_irq(phba->host->host_lock);
1205 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1206 spin_unlock_irq(phba->host->host_lock);
1208 /* LOGO completes to NPort <nlp_DID> */
1209 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1210 "%d:0105 LOGO completes to NPort x%x "
1211 "Data: x%x x%x x%x x%x\n",
1212 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1213 irsp->un.ulpWord[4], irsp->ulpTimeout,
1214 phba->num_disc_nodes);
1216 /* Check to see if link went down during discovery */
1217 if (lpfc_els_chk_latt(phba))
1220 if (irsp->ulpStatus) {
1221 /* Check for retry */
1222 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1223 /* ELS command is being retried */
1227 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1228 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1229 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1230 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1231 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1234 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1238 /* Good status, call state machine.
1239 * This will unregister the rpi if needed.
1241 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
1245 lpfc_els_free_iocb(phba, cmdiocb);
1250 lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1254 struct lpfc_iocbq *elsiocb;
1255 struct lpfc_sli_ring *pring;
1256 struct lpfc_sli *psli;
1261 pring = &psli->ring[LPFC_ELS_RING];
1263 cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name);
1264 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1265 ndlp->nlp_DID, ELS_CMD_LOGO);
1269 icmd = &elsiocb->iocb;
1270 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1271 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1272 pcmd += sizeof (uint32_t);
1274 /* Fill in LOGO payload */
1275 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
1276 pcmd += sizeof (uint32_t);
1277 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
1279 phba->fc_stat.elsXmitLOGO++;
1280 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1281 spin_lock_irq(phba->host->host_lock);
1282 ndlp->nlp_flag |= NLP_LOGO_SND;
1283 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1284 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1285 spin_unlock_irq(phba->host->host_lock);
1286 lpfc_els_free_iocb(phba, elsiocb);
1289 spin_unlock_irq(phba->host->host_lock);
1294 lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1295 struct lpfc_iocbq * rspiocb)
1299 irsp = &rspiocb->iocb;
1301 /* ELS cmd tag <ulpIoTag> completes */
1302 lpfc_printf_log(phba,
1305 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1307 irsp->ulpIoTag, irsp->ulpStatus,
1308 irsp->un.ulpWord[4], irsp->ulpTimeout);
1310 /* Check to see if link went down during discovery */
1311 lpfc_els_chk_latt(phba);
1312 lpfc_els_free_iocb(phba, cmdiocb);
1317 lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1320 struct lpfc_iocbq *elsiocb;
1321 struct lpfc_sli_ring *pring;
1322 struct lpfc_sli *psli;
1325 struct lpfc_nodelist *ndlp;
1328 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1329 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
1330 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1334 lpfc_nlp_init(phba, ndlp, nportid);
1336 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1337 ndlp->nlp_DID, ELS_CMD_SCR);
1339 mempool_free( ndlp, phba->nlp_mem_pool);
1343 icmd = &elsiocb->iocb;
1344 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1346 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1347 pcmd += sizeof (uint32_t);
1349 /* For SCR, remainder of payload is SCR parameter page */
1350 memset(pcmd, 0, sizeof (SCR));
1351 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1353 phba->fc_stat.elsXmitSCR++;
1354 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1355 spin_lock_irq(phba->host->host_lock);
1356 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1357 spin_unlock_irq(phba->host->host_lock);
1358 mempool_free( ndlp, phba->nlp_mem_pool);
1359 lpfc_els_free_iocb(phba, elsiocb);
1362 spin_unlock_irq(phba->host->host_lock);
1363 mempool_free( ndlp, phba->nlp_mem_pool);
1368 lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1371 struct lpfc_iocbq *elsiocb;
1372 struct lpfc_sli_ring *pring;
1373 struct lpfc_sli *psli;
1378 struct lpfc_nodelist *ondlp;
1379 struct lpfc_nodelist *ndlp;
1382 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1383 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
1384 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1387 lpfc_nlp_init(phba, ndlp, nportid);
1389 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1390 ndlp->nlp_DID, ELS_CMD_RNID);
1392 mempool_free( ndlp, phba->nlp_mem_pool);
1396 icmd = &elsiocb->iocb;
1397 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1399 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1400 pcmd += sizeof (uint32_t);
1402 /* Fill in FARPR payload */
1403 fp = (FARP *) (pcmd);
1404 memset(fp, 0, sizeof (FARP));
1405 lp = (uint32_t *) pcmd;
1406 *lp++ = be32_to_cpu(nportid);
1407 *lp++ = be32_to_cpu(phba->fc_myDID);
1409 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1411 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1412 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1413 if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
1414 memcpy(&fp->OportName, &ondlp->nlp_portname,
1415 sizeof (struct lpfc_name));
1416 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1417 sizeof (struct lpfc_name));
1420 phba->fc_stat.elsXmitFARPR++;
1421 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1422 spin_lock_irq(phba->host->host_lock);
1423 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1424 spin_unlock_irq(phba->host->host_lock);
1425 mempool_free( ndlp, phba->nlp_mem_pool);
1426 lpfc_els_free_iocb(phba, elsiocb);
1429 spin_unlock_irq(phba->host->host_lock);
1430 mempool_free( ndlp, phba->nlp_mem_pool);
1435 lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp)
1437 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1438 del_timer_sync(&nlp->nlp_delayfunc);
1439 nlp->nlp_last_elscmd = 0;
1441 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1442 list_del_init(&nlp->els_retry_evt.evt_listp);
1444 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1445 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1446 if (phba->num_disc_nodes) {
1447 /* Check to see if there are more
1450 lpfc_more_plogi(phba);
1452 if (phba->num_disc_nodes == 0) {
1453 phba->fc_flag &= ~FC_NDISC_ACTIVE;
1454 lpfc_can_disctmo(phba);
1455 if (phba->fc_flag & FC_RSCN_MODE) {
1457 * Check to see if more RSCNs
1458 * came in while we were
1459 * processing this one.
1461 if((phba->fc_rscn_id_cnt==0) &&
1462 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
1463 phba->fc_flag &= ~FC_RSCN_MODE;
1466 lpfc_els_handle_rscn(phba);
1476 lpfc_els_retry_delay(unsigned long ptr)
1478 struct lpfc_nodelist *ndlp;
1479 struct lpfc_hba *phba;
1480 unsigned long iflag;
1481 struct lpfc_work_evt *evtp;
1483 ndlp = (struct lpfc_nodelist *)ptr;
1484 phba = ndlp->nlp_phba;
1485 evtp = &ndlp->els_retry_evt;
1487 spin_lock_irqsave(phba->host->host_lock, iflag);
1488 if (!list_empty(&evtp->evt_listp)) {
1489 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1493 evtp->evt_arg1 = ndlp;
1494 evtp->evt = LPFC_EVT_ELS_RETRY;
1495 list_add_tail(&evtp->evt_listp, &phba->work_list);
1496 if (phba->work_wait)
1497 wake_up(phba->work_wait);
1499 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1504 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1506 struct lpfc_hba *phba;
1511 phba = ndlp->nlp_phba;
1512 spin_lock_irq(phba->host->host_lock);
1513 did = ndlp->nlp_DID;
1514 cmd = ndlp->nlp_last_elscmd;
1515 ndlp->nlp_last_elscmd = 0;
1517 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1518 spin_unlock_irq(phba->host->host_lock);
1522 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1523 spin_unlock_irq(phba->host->host_lock);
1525 * If a discovery event readded nlp_delayfunc after timer
1526 * firing and before processing the timer, cancel the
1529 del_timer_sync(&ndlp->nlp_delayfunc);
1530 retry = ndlp->nlp_retry;
1534 lpfc_issue_els_flogi(phba, ndlp, retry);
1537 if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) {
1538 ndlp->nlp_prev_state = ndlp->nlp_state;
1539 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1540 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1544 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) {
1545 ndlp->nlp_prev_state = ndlp->nlp_state;
1546 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1547 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1551 if (!lpfc_issue_els_prli(phba, ndlp, retry)) {
1552 ndlp->nlp_prev_state = ndlp->nlp_state;
1553 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1554 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1558 if (!lpfc_issue_els_logo(phba, ndlp, retry)) {
1559 ndlp->nlp_prev_state = ndlp->nlp_state;
1560 ndlp->nlp_state = NLP_STE_NPR_NODE;
1561 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1569 lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1570 struct lpfc_iocbq * rspiocb)
1573 struct lpfc_dmabuf *pcmd;
1574 struct lpfc_nodelist *ndlp;
1577 int retry, maxretry;
1584 maxretry = lpfc_max_els_tries;
1585 irsp = &rspiocb->iocb;
1586 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1587 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1590 /* Note: context2 may be 0 for internal driver abort
1591 * of delays ELS command.
1594 if (pcmd && pcmd->virt) {
1595 elscmd = (uint32_t *) (pcmd->virt);
1600 did = ndlp->nlp_DID;
1602 /* We should only hit this case for retrying PLOGI */
1603 did = irsp->un.elsreq64.remoteID;
1604 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1605 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1609 switch (irsp->ulpStatus) {
1610 case IOSTAT_FCP_RSP_ERROR:
1611 case IOSTAT_REMOTE_STOP:
1614 case IOSTAT_LOCAL_REJECT:
1615 switch ((irsp->un.ulpWord[4] & 0xff)) {
1616 case IOERR_LOOP_OPEN_FAILURE:
1617 if (cmd == ELS_CMD_PLOGI) {
1618 if (cmdiocb->retry == 0) {
1625 case IOERR_SEQUENCE_TIMEOUT:
1629 case IOERR_NO_RESOURCES:
1630 if (cmd == ELS_CMD_PLOGI) {
1636 case IOERR_INVALID_RPI:
1642 case IOSTAT_NPORT_RJT:
1643 case IOSTAT_FABRIC_RJT:
1644 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1650 case IOSTAT_NPORT_BSY:
1651 case IOSTAT_FABRIC_BSY:
1656 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1657 /* Added for Vendor specifc support
1658 * Just keep retrying for these Rsn / Exp codes
1660 switch (stat.un.b.lsRjtRsnCode) {
1661 case LSRJT_UNABLE_TPC:
1662 if (stat.un.b.lsRjtRsnCodeExp ==
1663 LSEXP_CMD_IN_PROGRESS) {
1664 if (cmd == ELS_CMD_PLOGI) {
1671 if (cmd == ELS_CMD_PLOGI) {
1673 maxretry = lpfc_max_els_tries + 1;
1679 case LSRJT_LOGICAL_BSY:
1680 if (cmd == ELS_CMD_PLOGI) {
1689 case IOSTAT_INTERMED_RSP:
1697 if (did == FDMI_DID)
1700 if ((++cmdiocb->retry) >= maxretry) {
1701 phba->fc_stat.elsRetryExceeded++;
1707 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1708 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1709 "%d:0107 Retry ELS command x%x to remote "
1710 "NPORT x%x Data: x%x x%x\n",
1712 cmd, did, cmdiocb->retry, delay);
1714 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1715 /* If discovery / RSCN timer is running, reset it */
1716 if (timer_pending(&phba->fc_disctmo) ||
1717 (phba->fc_flag & FC_RSCN_MODE)) {
1718 lpfc_set_disctmo(phba);
1722 phba->fc_stat.elsXmitRetry++;
1723 if (ndlp && delay) {
1724 phba->fc_stat.elsDelayRetry++;
1725 ndlp->nlp_retry = cmdiocb->retry;
1727 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1728 ndlp->nlp_flag |= NLP_DELAY_TMO;
1730 ndlp->nlp_prev_state = ndlp->nlp_state;
1731 ndlp->nlp_state = NLP_STE_NPR_NODE;
1732 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1733 ndlp->nlp_last_elscmd = cmd;
1739 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
1743 ndlp->nlp_prev_state = ndlp->nlp_state;
1744 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1745 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1747 lpfc_issue_els_plogi(phba, did, cmdiocb->retry);
1750 ndlp->nlp_prev_state = ndlp->nlp_state;
1751 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1752 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1753 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
1756 ndlp->nlp_prev_state = ndlp->nlp_state;
1757 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1758 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1759 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
1762 ndlp->nlp_prev_state = ndlp->nlp_state;
1763 ndlp->nlp_state = NLP_STE_NPR_NODE;
1764 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1765 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
1770 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1771 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1772 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
1775 cmd, did, cmdiocb->retry);
1781 lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
1783 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1785 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1786 if (elsiocb->context2) {
1787 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1788 /* Free the response before processing the command. */
1789 if (!list_empty(&buf_ptr1->list)) {
1790 list_remove_head(&buf_ptr1->list, buf_ptr,
1793 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1796 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1800 if (elsiocb->context3) {
1801 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1802 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1805 spin_lock_irq(phba->host->host_lock);
1806 lpfc_sli_release_iocbq(phba, elsiocb);
1807 spin_unlock_irq(phba->host->host_lock);
1812 lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1813 struct lpfc_iocbq * rspiocb)
1815 struct lpfc_nodelist *ndlp;
1817 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1819 /* ACC to LOGO completes to NPort <nlp_DID> */
1820 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1821 "%d:0109 ACC to LOGO completes to NPort x%x "
1822 "Data: x%x x%x x%x\n",
1823 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1824 ndlp->nlp_state, ndlp->nlp_rpi);
1826 switch (ndlp->nlp_state) {
1827 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1828 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1830 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1831 lpfc_unreg_rpi(phba, ndlp);
1836 lpfc_els_free_iocb(phba, cmdiocb);
1841 lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1842 struct lpfc_iocbq * rspiocb)
1844 struct lpfc_nodelist *ndlp;
1845 LPFC_MBOXQ_t *mbox = NULL;
1847 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1848 if (cmdiocb->context_un.mbox)
1849 mbox = cmdiocb->context_un.mbox;
1852 /* Check to see if link went down during discovery */
1853 if ((lpfc_els_chk_latt(phba)) || !ndlp) {
1855 mempool_free( mbox, phba->mbox_mem_pool);
1860 /* ELS response tag <ulpIoTag> completes */
1861 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1862 "%d:0110 ELS response tag x%x completes "
1863 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
1865 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
1866 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1867 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
1871 if ((rspiocb->iocb.ulpStatus == 0)
1872 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
1873 lpfc_unreg_rpi(phba, ndlp);
1874 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1875 mbox->context2 = ndlp;
1876 ndlp->nlp_prev_state = ndlp->nlp_state;
1877 ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE;
1878 lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
1879 if (lpfc_sli_issue_mbox(phba, mbox,
1880 (MBX_NOWAIT | MBX_STOP_IOCB))
1881 != MBX_NOT_FINISHED) {
1884 /* NOTE: we should have messages for unsuccessful
1886 mempool_free( mbox, phba->mbox_mem_pool);
1888 mempool_free( mbox, phba->mbox_mem_pool);
1889 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1890 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1897 spin_lock_irq(phba->host->host_lock);
1898 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1899 spin_unlock_irq(phba->host->host_lock);
1901 lpfc_els_free_iocb(phba, cmdiocb);
1906 lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1907 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
1908 LPFC_MBOXQ_t * mbox, uint8_t newnode)
1912 struct lpfc_iocbq *elsiocb;
1913 struct lpfc_sli_ring *pring;
1914 struct lpfc_sli *psli;
1918 ELS_PKT *els_pkt_ptr;
1921 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1922 oldcmd = &oldiocb->iocb;
1926 cmdsize = sizeof (uint32_t);
1927 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1928 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1930 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
1933 icmd = &elsiocb->iocb;
1934 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1935 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1936 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1937 pcmd += sizeof (uint32_t);
1940 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
1941 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1942 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1946 icmd = &elsiocb->iocb;
1947 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1948 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1951 elsiocb->context_un.mbox = mbox;
1953 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1954 pcmd += sizeof (uint32_t);
1955 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
1958 cmdsize = sizeof (uint32_t) + sizeof (PRLO);
1959 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1960 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
1964 icmd = &elsiocb->iocb;
1965 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1966 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1968 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
1969 sizeof (uint32_t) + sizeof (PRLO));
1970 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
1971 els_pkt_ptr = (ELS_PKT *) pcmd;
1972 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
1979 elsiocb->context1 = NULL;
1981 /* Xmit ELS ACC response tag <ulpIoTag> */
1982 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1983 "%d:0128 Xmit ELS ACC response tag x%x "
1984 "Data: x%x x%x x%x x%x x%x\n",
1986 elsiocb->iocb.ulpIoTag,
1987 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1988 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1990 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
1991 spin_lock_irq(phba->host->host_lock);
1992 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
1993 spin_unlock_irq(phba->host->host_lock);
1994 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
1996 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1999 phba->fc_stat.elsXmitACC++;
2000 spin_lock_irq(phba->host->host_lock);
2001 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2002 spin_unlock_irq(phba->host->host_lock);
2003 if (rc == IOCB_ERROR) {
2004 lpfc_els_free_iocb(phba, elsiocb);
2011 lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
2012 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2016 struct lpfc_iocbq *elsiocb;
2017 struct lpfc_sli_ring *pring;
2018 struct lpfc_sli *psli;
2024 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2026 cmdsize = 2 * sizeof (uint32_t);
2027 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2028 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
2032 icmd = &elsiocb->iocb;
2033 oldcmd = &oldiocb->iocb;
2034 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2035 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2037 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2038 pcmd += sizeof (uint32_t);
2039 *((uint32_t *) (pcmd)) = rejectError;
2041 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2042 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2043 "%d:0129 Xmit ELS RJT x%x response tag x%x "
2044 "Data: x%x x%x x%x x%x x%x\n",
2046 rejectError, elsiocb->iocb.ulpIoTag,
2047 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2048 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2050 phba->fc_stat.elsXmitLSRJT++;
2051 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2052 spin_lock_irq(phba->host->host_lock);
2053 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2054 spin_unlock_irq(phba->host->host_lock);
2055 if (rc == IOCB_ERROR) {
2056 lpfc_els_free_iocb(phba, elsiocb);
2063 lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2064 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2069 struct lpfc_iocbq *elsiocb;
2070 struct lpfc_sli_ring *pring;
2071 struct lpfc_sli *psli;
2077 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2079 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
2080 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2081 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2085 /* Xmit ADISC ACC response tag <ulpIoTag> */
2086 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2087 "%d:0130 Xmit ADISC ACC response tag x%x "
2088 "Data: x%x x%x x%x x%x x%x\n",
2090 elsiocb->iocb.ulpIoTag,
2091 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2092 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2094 icmd = &elsiocb->iocb;
2095 oldcmd = &oldiocb->iocb;
2096 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2097 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2099 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2100 pcmd += sizeof (uint32_t);
2102 ap = (ADISC *) (pcmd);
2103 ap->hardAL_PA = phba->fc_pref_ALPA;
2104 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2105 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2106 ap->DID = be32_to_cpu(phba->fc_myDID);
2108 phba->fc_stat.elsXmitACC++;
2109 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2110 spin_lock_irq(phba->host->host_lock);
2111 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2112 spin_unlock_irq(phba->host->host_lock);
2113 if (rc == IOCB_ERROR) {
2114 lpfc_els_free_iocb(phba, elsiocb);
2121 lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2122 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2128 struct lpfc_iocbq *elsiocb;
2129 struct lpfc_sli_ring *pring;
2130 struct lpfc_sli *psli;
2136 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2138 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
2139 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp,
2140 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2144 /* Xmit PRLI ACC response tag <ulpIoTag> */
2145 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2146 "%d:0131 Xmit PRLI ACC response tag x%x "
2147 "Data: x%x x%x x%x x%x x%x\n",
2149 elsiocb->iocb.ulpIoTag,
2150 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2151 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2153 icmd = &elsiocb->iocb;
2154 oldcmd = &oldiocb->iocb;
2155 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2156 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2158 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2159 pcmd += sizeof (uint32_t);
2161 /* For PRLI, remainder of payload is PRLI parameter page */
2162 memset(pcmd, 0, sizeof (PRLI));
2164 npr = (PRLI *) pcmd;
2167 * If our firmware version is 3.20 or later,
2168 * set the following bits for FC-TAPE support.
2170 if (vpd->rev.feaLevelHigh >= 0x02) {
2171 npr->ConfmComplAllowed = 1;
2173 npr->TaskRetryIdReq = 1;
2176 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2177 npr->estabImagePair = 1;
2178 npr->readXferRdyDis = 1;
2179 npr->ConfmComplAllowed = 1;
2181 npr->prliType = PRLI_FCP_TYPE;
2182 npr->initiatorFunc = 1;
2184 phba->fc_stat.elsXmitACC++;
2185 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2187 spin_lock_irq(phba->host->host_lock);
2188 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2189 spin_unlock_irq(phba->host->host_lock);
2190 if (rc == IOCB_ERROR) {
2191 lpfc_els_free_iocb(phba, elsiocb);
2198 lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2200 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2205 struct lpfc_iocbq *elsiocb;
2206 struct lpfc_sli_ring *pring;
2207 struct lpfc_sli *psli;
2213 pring = &psli->ring[LPFC_ELS_RING];
2215 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2216 + (2 * sizeof (struct lpfc_name));
2218 cmdsize += sizeof (RNID_TOP_DISC);
2220 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2221 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2225 /* Xmit RNID ACC response tag <ulpIoTag> */
2226 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2227 "%d:0132 Xmit RNID ACC response tag x%x "
2230 elsiocb->iocb.ulpIoTag,
2231 elsiocb->iocb.ulpContext);
2233 icmd = &elsiocb->iocb;
2234 oldcmd = &oldiocb->iocb;
2235 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2236 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2238 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2239 pcmd += sizeof (uint32_t);
2241 memset(pcmd, 0, sizeof (RNID));
2242 rn = (RNID *) (pcmd);
2243 rn->Format = format;
2244 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2245 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2246 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2249 rn->SpecificLen = 0;
2251 case RNID_TOPOLOGY_DISC:
2252 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2253 memcpy(&rn->un.topologyDisc.portName,
2254 &phba->fc_portname, sizeof (struct lpfc_name));
2255 rn->un.topologyDisc.unitType = RNID_HBA;
2256 rn->un.topologyDisc.physPort = 0;
2257 rn->un.topologyDisc.attachedNodes = 0;
2261 rn->SpecificLen = 0;
2265 phba->fc_stat.elsXmitACC++;
2266 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2267 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2268 * it could be freed */
2270 spin_lock_irq(phba->host->host_lock);
2271 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2272 spin_unlock_irq(phba->host->host_lock);
2273 if (rc == IOCB_ERROR) {
2274 lpfc_els_free_iocb(phba, elsiocb);
2281 lpfc_els_disc_adisc(struct lpfc_hba * phba)
2284 struct lpfc_nodelist *ndlp, *next_ndlp;
2287 /* go thru NPR list and issue any remaining ELS ADISCs */
2288 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2290 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2291 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2292 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2293 ndlp->nlp_prev_state = ndlp->nlp_state;
2294 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
2295 lpfc_nlp_list(phba, ndlp,
2297 lpfc_issue_els_adisc(phba, ndlp, 0);
2299 phba->num_disc_nodes++;
2300 if (phba->num_disc_nodes >=
2301 phba->cfg_discovery_threads) {
2302 spin_lock_irq(phba->host->host_lock);
2303 phba->fc_flag |= FC_NLP_MORE;
2304 spin_unlock_irq(phba->host->host_lock);
2310 if (sentadisc == 0) {
2311 spin_lock_irq(phba->host->host_lock);
2312 phba->fc_flag &= ~FC_NLP_MORE;
2313 spin_unlock_irq(phba->host->host_lock);
2319 lpfc_els_disc_plogi(struct lpfc_hba * phba)
2322 struct lpfc_nodelist *ndlp, *next_ndlp;
2325 /* go thru NPR list and issue any remaining ELS PLOGIs */
2326 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2328 if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
2329 (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
2330 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2331 ndlp->nlp_prev_state = ndlp->nlp_state;
2332 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2333 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2334 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
2336 phba->num_disc_nodes++;
2337 if (phba->num_disc_nodes >=
2338 phba->cfg_discovery_threads) {
2339 spin_lock_irq(phba->host->host_lock);
2340 phba->fc_flag |= FC_NLP_MORE;
2341 spin_unlock_irq(phba->host->host_lock);
2347 if (sentplogi == 0) {
2348 spin_lock_irq(phba->host->host_lock);
2349 phba->fc_flag &= ~FC_NLP_MORE;
2350 spin_unlock_irq(phba->host->host_lock);
2356 lpfc_els_flush_rscn(struct lpfc_hba * phba)
2358 struct lpfc_dmabuf *mp;
2361 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2362 mp = phba->fc_rscn_id_list[i];
2363 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2365 phba->fc_rscn_id_list[i] = NULL;
2367 phba->fc_rscn_id_cnt = 0;
2368 spin_lock_irq(phba->host->host_lock);
2369 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2370 spin_unlock_irq(phba->host->host_lock);
2371 lpfc_can_disctmo(phba);
2376 lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2380 struct lpfc_dmabuf *mp;
2382 uint32_t payload_len, cmd, i, match;
2384 ns_did.un.word = did;
2387 /* Never match fabric nodes for RSCNs */
2388 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2391 /* If we are doing a FULL RSCN rediscovery, match everything */
2392 if (phba->fc_flag & FC_RSCN_DISCOVERY) {
2396 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2397 mp = phba->fc_rscn_id_list[i];
2398 lp = (uint32_t *) mp->virt;
2400 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2401 payload_len -= sizeof (uint32_t); /* take off word 0 */
2402 while (payload_len) {
2403 rscn_did.un.word = *lp++;
2404 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2405 payload_len -= sizeof (uint32_t);
2406 switch (rscn_did.un.b.resv) {
2407 case 0: /* Single N_Port ID effected */
2408 if (ns_did.un.word == rscn_did.un.word) {
2412 case 1: /* Whole N_Port Area effected */
2413 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2414 && (ns_did.un.b.area == rscn_did.un.b.area))
2419 case 2: /* Whole N_Port Domain effected */
2420 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2425 case 3: /* Whole Fabric effected */
2429 /* Unknown Identifier in RSCN list */
2430 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2431 "%d:0217 Unknown Identifier in "
2432 "RSCN payload Data: x%x\n",
2433 phba->brd_no, rscn_did.un.word);
2445 lpfc_rscn_recovery_check(struct lpfc_hba * phba)
2447 struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
2448 struct list_head *listp;
2449 struct list_head *node_list[7];
2452 /* Look at all nodes effected by pending RSCNs and move
2455 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
2456 node_list[1] = &phba->fc_nlpmap_list;
2457 node_list[2] = &phba->fc_nlpunmap_list;
2458 node_list[3] = &phba->fc_prli_list;
2459 node_list[4] = &phba->fc_reglogin_list;
2460 node_list[5] = &phba->fc_adisc_list;
2461 node_list[6] = &phba->fc_plogi_list;
2462 for (i = 0; i < 7; i++) {
2463 listp = node_list[i];
2464 if (list_empty(listp))
2467 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
2468 if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID)))
2471 lpfc_disc_state_machine(phba, ndlp, NULL,
2472 NLP_EVT_DEVICE_RECOVERY);
2474 /* Make sure NLP_DELAY_TMO is NOT running
2475 * after a device recovery event.
2477 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2478 lpfc_cancel_retry_delay_tmo(phba, ndlp);
2485 lpfc_els_rcv_rscn(struct lpfc_hba * phba,
2486 struct lpfc_iocbq * cmdiocb,
2487 struct lpfc_nodelist * ndlp, uint8_t newnode)
2489 struct lpfc_dmabuf *pcmd;
2492 uint32_t payload_len, cmd;
2494 icmd = &cmdiocb->iocb;
2495 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2496 lp = (uint32_t *) pcmd->virt;
2499 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2500 payload_len -= sizeof (uint32_t); /* take off word 0 */
2501 cmd &= ELS_CMD_MASK;
2504 lpfc_printf_log(phba,
2507 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2509 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2511 /* If we are about to begin discovery, just ACC the RSCN.
2512 * Discovery processing will satisfy it.
2514 if (phba->hba_state <= LPFC_NS_QRY) {
2515 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2520 /* If we are already processing an RSCN, save the received
2521 * RSCN payload buffer, cmdiocb->context2 to process later.
2523 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2524 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2525 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
2526 spin_lock_irq(phba->host->host_lock);
2527 phba->fc_flag |= FC_RSCN_MODE;
2528 spin_unlock_irq(phba->host->host_lock);
2529 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2531 /* If we zero, cmdiocb->context2, the calling
2532 * routine will not try to free it.
2534 cmdiocb->context2 = NULL;
2537 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2538 "%d:0235 Deferred RSCN "
2539 "Data: x%x x%x x%x\n",
2540 phba->brd_no, phba->fc_rscn_id_cnt,
2541 phba->fc_flag, phba->hba_state);
2543 spin_lock_irq(phba->host->host_lock);
2544 phba->fc_flag |= FC_RSCN_DISCOVERY;
2545 spin_unlock_irq(phba->host->host_lock);
2546 /* ReDiscovery RSCN */
2547 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2548 "%d:0234 ReDiscovery RSCN "
2549 "Data: x%x x%x x%x\n",
2550 phba->brd_no, phba->fc_rscn_id_cnt,
2551 phba->fc_flag, phba->hba_state);
2554 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2557 /* send RECOVERY event for ALL nodes that match RSCN payload */
2558 lpfc_rscn_recovery_check(phba);
2562 phba->fc_flag |= FC_RSCN_MODE;
2563 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2565 * If we zero, cmdiocb->context2, the calling routine will
2566 * not try to free it.
2568 cmdiocb->context2 = NULL;
2570 lpfc_set_disctmo(phba);
2573 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2575 /* send RECOVERY event for ALL nodes that match RSCN payload */
2576 lpfc_rscn_recovery_check(phba);
2578 return lpfc_els_handle_rscn(phba);
2582 lpfc_els_handle_rscn(struct lpfc_hba * phba)
2584 struct lpfc_nodelist *ndlp;
2586 /* Start timer for RSCN processing */
2587 lpfc_set_disctmo(phba);
2589 /* RSCN processed */
2590 lpfc_printf_log(phba,
2593 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2595 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2598 /* To process RSCN, first compare RSCN data with NameServer */
2599 phba->fc_ns_retry = 0;
2600 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, NameServer_DID);
2602 /* Good ndlp, issue CT Request to NameServer */
2603 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2604 /* Wait for NameServer query cmpl before we can
2609 /* If login to NameServer does not exist, issue one */
2610 /* Good status, issue PLOGI to NameServer */
2611 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2613 /* Wait for NameServer login cmpl before we can
2617 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2619 lpfc_els_flush_rscn(phba);
2622 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2623 ndlp->nlp_type |= NLP_FABRIC;
2624 ndlp->nlp_prev_state = ndlp->nlp_state;
2625 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2626 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
2627 /* Wait for NameServer login cmpl before we can
2633 lpfc_els_flush_rscn(phba);
2638 lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2639 struct lpfc_iocbq * cmdiocb,
2640 struct lpfc_nodelist * ndlp, uint8_t newnode)
2642 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2643 uint32_t *lp = (uint32_t *) pcmd->virt;
2644 IOCB_t *icmd = &cmdiocb->iocb;
2645 struct serv_parm *sp;
2652 sp = (struct serv_parm *) lp;
2654 /* FLOGI received */
2656 lpfc_set_disctmo(phba);
2658 if (phba->fc_topology == TOPOLOGY_LOOP) {
2659 /* We should never receive a FLOGI in loop mode, ignore it */
2660 did = icmd->un.elsreq64.remoteID;
2662 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2664 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2665 "%d:0113 An FLOGI ELS command x%x was received "
2666 "from DID x%x in Loop Mode\n",
2667 phba->brd_no, cmd, did);
2673 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
2674 /* For a FLOGI we accept, then if our portname is greater
2675 * then the remote portname we initiate Nport login.
2678 rc = memcmp(&phba->fc_portname, &sp->portName,
2679 sizeof (struct lpfc_name));
2682 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
2683 GFP_KERNEL)) == 0) {
2686 lpfc_linkdown(phba);
2687 lpfc_init_link(phba, mbox,
2689 phba->cfg_link_speed);
2690 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2691 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2692 rc = lpfc_sli_issue_mbox
2693 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2694 if (rc == MBX_NOT_FINISHED) {
2695 mempool_free( mbox, phba->mbox_mem_pool);
2698 } else if (rc > 0) { /* greater than */
2699 spin_lock_irq(phba->host->host_lock);
2700 phba->fc_flag |= FC_PT2PT_PLOGI;
2701 spin_unlock_irq(phba->host->host_lock);
2703 phba->fc_flag |= FC_PT2PT;
2704 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2706 /* Reject this request because invalid parameters */
2707 stat.un.b.lsRjtRsvd0 = 0;
2708 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2709 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2710 stat.un.b.vendorUnique = 0;
2711 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2716 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2722 lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2723 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2725 struct lpfc_dmabuf *pcmd;
2732 icmd = &cmdiocb->iocb;
2733 did = icmd->un.elsreq64.remoteID;
2734 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2735 lp = (uint32_t *) pcmd->virt;
2742 switch (rn->Format) {
2744 case RNID_TOPOLOGY_DISC:
2746 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
2749 /* Reject this request because format not supported */
2750 stat.un.b.lsRjtRsvd0 = 0;
2751 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2752 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2753 stat.un.b.vendorUnique = 0;
2754 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2760 lpfc_els_rcv_lirr(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2761 struct lpfc_nodelist * ndlp)
2765 /* For now, unconditionally reject this command */
2766 stat.un.b.lsRjtRsvd0 = 0;
2767 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2768 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2769 stat.un.b.vendorUnique = 0;
2770 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2775 lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2777 struct lpfc_sli *psli;
2778 struct lpfc_sli_ring *pring;
2783 struct lpfc_iocbq *elsiocb;
2784 struct lpfc_nodelist *ndlp;
2785 uint16_t xri, status;
2789 pring = &psli->ring[LPFC_ELS_RING];
2792 ndlp = (struct lpfc_nodelist *) pmb->context2;
2793 xri = (uint16_t) ((unsigned long)(pmb->context1));
2794 pmb->context1 = NULL;
2795 pmb->context2 = NULL;
2797 if (mb->mbxStatus) {
2798 mempool_free( pmb, phba->mbox_mem_pool);
2802 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
2803 mempool_free( pmb, phba->mbox_mem_pool);
2804 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp,
2805 ndlp->nlp_DID, ELS_CMD_ACC);
2809 icmd = &elsiocb->iocb;
2810 icmd->ulpContext = xri;
2812 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2813 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2814 pcmd += sizeof (uint32_t); /* Skip past command */
2815 rps_rsp = (RPS_RSP *)pcmd;
2817 if (phba->fc_topology != TOPOLOGY_LOOP)
2821 if (phba->fc_flag & FC_FABRIC)
2825 rps_rsp->portStatus = be16_to_cpu(status);
2826 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
2827 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
2828 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
2829 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
2830 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
2831 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
2833 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2834 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2835 "%d:0128 Xmit ELS RPS ACC response tag x%x "
2836 "Data: x%x x%x x%x x%x x%x\n",
2838 elsiocb->iocb.ulpIoTag,
2839 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2840 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2842 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2843 phba->fc_stat.elsXmitACC++;
2844 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2845 lpfc_els_free_iocb(phba, elsiocb);
2851 lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2852 struct lpfc_nodelist * ndlp)
2857 struct lpfc_dmabuf *pcmd;
2861 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2862 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
2863 stat.un.b.lsRjtRsvd0 = 0;
2864 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2865 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2866 stat.un.b.vendorUnique = 0;
2867 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2870 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2871 lp = (uint32_t *) pcmd->virt;
2872 flag = (be32_to_cpu(*lp++) & 0xf);
2876 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2877 ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname,
2878 sizeof (struct lpfc_name)) == 0))) {
2879 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
2880 lpfc_read_lnk_stat(phba, mbox);
2882 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
2883 mbox->context2 = ndlp;
2884 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2885 if (lpfc_sli_issue_mbox (phba, mbox,
2886 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) {
2887 /* Mbox completion will send ELS Response */
2890 mempool_free(mbox, phba->mbox_mem_pool);
2893 stat.un.b.lsRjtRsvd0 = 0;
2894 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2895 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2896 stat.un.b.vendorUnique = 0;
2897 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2902 lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2903 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2908 struct lpfc_iocbq *elsiocb;
2909 struct lpfc_sli_ring *pring;
2910 struct lpfc_sli *psli;
2914 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2916 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2917 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2921 icmd = &elsiocb->iocb;
2922 oldcmd = &oldiocb->iocb;
2923 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2925 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2926 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2927 pcmd += sizeof (uint16_t);
2928 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2929 pcmd += sizeof(uint16_t);
2931 /* Setup the RPL ACC payload */
2932 rpl_rsp.listLen = be32_to_cpu(1);
2934 rpl_rsp.port_num_blk.portNum = 0;
2935 rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID);
2936 memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname,
2937 sizeof(struct lpfc_name));
2939 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
2942 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2943 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2944 "%d:0128 Xmit ELS RPL ACC response tag x%x "
2945 "Data: x%x x%x x%x x%x x%x\n",
2947 elsiocb->iocb.ulpIoTag,
2948 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2949 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2951 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2953 phba->fc_stat.elsXmitACC++;
2954 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2955 lpfc_els_free_iocb(phba, elsiocb);
2962 lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2963 struct lpfc_nodelist * ndlp)
2965 struct lpfc_dmabuf *pcmd;
2972 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2973 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
2974 stat.un.b.lsRjtRsvd0 = 0;
2975 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2976 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2977 stat.un.b.vendorUnique = 0;
2978 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2981 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2982 lp = (uint32_t *) pcmd->virt;
2983 rpl = (RPL *) (lp + 1);
2985 maxsize = be32_to_cpu(rpl->maxsize);
2987 /* We support only one port */
2988 if ((rpl->index == 0) &&
2990 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
2991 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
2993 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
2995 lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp);
3001 lpfc_els_rcv_farp(struct lpfc_hba * phba,
3002 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3004 struct lpfc_dmabuf *pcmd;
3008 uint32_t cmd, cnt, did;
3010 icmd = &cmdiocb->iocb;
3011 did = icmd->un.elsreq64.remoteID;
3012 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3013 lp = (uint32_t *) pcmd->virt;
3018 /* FARP-REQ received from DID <did> */
3019 lpfc_printf_log(phba,
3022 "%d:0601 FARP-REQ received from DID x%x\n",
3025 /* We will only support match on WWPN or WWNN */
3026 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
3031 /* If this FARP command is searching for my portname */
3032 if (fp->Mflags & FARP_MATCH_PORT) {
3033 if (memcmp(&fp->RportName, &phba->fc_portname,
3034 sizeof (struct lpfc_name)) == 0)
3038 /* If this FARP command is searching for my nodename */
3039 if (fp->Mflags & FARP_MATCH_NODE) {
3040 if (memcmp(&fp->RnodeName, &phba->fc_nodename,
3041 sizeof (struct lpfc_name)) == 0)
3046 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3047 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3048 /* Log back into the node before sending the FARP. */
3049 if (fp->Rflags & FARP_REQUEST_PLOGI) {
3050 ndlp->nlp_prev_state = ndlp->nlp_state;
3051 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
3052 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
3053 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
3056 /* Send a FARP response to that node */
3057 if (fp->Rflags & FARP_REQUEST_FARPR) {
3058 lpfc_issue_els_farpr(phba, did, 0);
3066 lpfc_els_rcv_farpr(struct lpfc_hba * phba,
3067 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3069 struct lpfc_dmabuf *pcmd;
3074 icmd = &cmdiocb->iocb;
3075 did = icmd->un.elsreq64.remoteID;
3076 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3077 lp = (uint32_t *) pcmd->virt;
3080 /* FARP-RSP received from DID <did> */
3081 lpfc_printf_log(phba,
3084 "%d:0600 FARP-RSP received from DID x%x\n",
3087 /* ACCEPT the Farp resp request */
3088 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
3094 lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3095 struct lpfc_nodelist * fan_ndlp)
3097 struct lpfc_dmabuf *pcmd;
3102 struct lpfc_nodelist *ndlp, *next_ndlp;
3105 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:265 FAN received\n",
3108 icmd = &cmdiocb->iocb;
3109 did = icmd->un.elsreq64.remoteID;
3110 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3111 lp = (uint32_t *)pcmd->virt;
3116 /* FAN received; Fan does not have a reply sequence */
3118 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
3119 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3120 sizeof(struct lpfc_name)) != 0) ||
3121 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3122 sizeof(struct lpfc_name)) != 0)) {
3124 * This node has switched fabrics. FLOGI is required
3125 * Clean up the old rpi's
3128 list_for_each_entry_safe(ndlp, next_ndlp,
3129 &phba->fc_npr_list, nlp_listp) {
3131 if (ndlp->nlp_type & NLP_FABRIC) {
3133 * Clean up old Fabric, Nameserver and
3134 * other NLP_FABRIC logins
3136 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3137 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3138 /* Fail outstanding I/O now since this
3139 * device is marked for PLOGI
3141 lpfc_unreg_rpi(phba, ndlp);
3145 phba->hba_state = LPFC_FLOGI;
3146 lpfc_set_disctmo(phba);
3147 lpfc_initial_flogi(phba);
3150 /* Discovery not needed,
3151 * move the nodes to their original state.
3153 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
3156 switch (ndlp->nlp_prev_state) {
3157 case NLP_STE_UNMAPPED_NODE:
3158 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3159 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
3160 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
3163 case NLP_STE_MAPPED_NODE:
3164 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3165 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
3166 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
3174 /* Start discovery - this should just do CLEAR_LA */
3175 lpfc_disc_start(phba);
3181 lpfc_els_timeout(unsigned long ptr)
3183 struct lpfc_hba *phba;
3184 unsigned long iflag;
3186 phba = (struct lpfc_hba *)ptr;
3189 spin_lock_irqsave(phba->host->host_lock, iflag);
3190 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3191 phba->work_hba_events |= WORKER_ELS_TMO;
3192 if (phba->work_wait)
3193 wake_up(phba->work_wait);
3195 spin_unlock_irqrestore(phba->host->host_lock, iflag);
3200 lpfc_els_timeout_handler(struct lpfc_hba *phba)
3202 struct lpfc_sli_ring *pring;
3203 struct lpfc_iocbq *tmp_iocb, *piocb;
3205 struct lpfc_dmabuf *pcmd;
3206 struct list_head *dlp;
3208 uint32_t els_command;
3214 spin_lock_irq(phba->host->host_lock);
3215 /* If the timer is already canceled do nothing */
3216 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3217 spin_unlock_irq(phba->host->host_lock);
3220 timeout = (uint32_t)(phba->fc_ratov << 1);
3222 pring = &phba->sli.ring[LPFC_ELS_RING];
3223 dlp = &pring->txcmplq;
3225 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3228 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3231 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3232 elscmd = (uint32_t *) (pcmd->virt);
3233 els_command = *elscmd;
3235 if ((els_command == ELS_CMD_FARP)
3236 || (els_command == ELS_CMD_FARPR)) {
3240 if (piocb->drvrTimeout > 0) {
3241 if (piocb->drvrTimeout >= timeout) {
3242 piocb->drvrTimeout -= timeout;
3244 piocb->drvrTimeout = 0;
3249 list_del(&piocb->list);
3250 pring->txcmplq_cnt--;
3252 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3253 struct lpfc_nodelist *ndlp;
3254 spin_unlock_irq(phba->host->host_lock);
3255 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
3256 spin_lock_irq(phba->host->host_lock);
3257 remote_ID = ndlp->nlp_DID;
3258 if (cmd->un.elsreq64.bdl.ulpIoTag32) {
3259 lpfc_sli_issue_abort_iotag32(phba,
3263 remote_ID = cmd->un.elsreq64.remoteID;
3266 lpfc_printf_log(phba,
3269 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
3270 phba->brd_no, els_command,
3271 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3274 * The iocb has timed out; abort it.
3276 if (piocb->iocb_cmpl) {
3277 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3278 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3279 spin_unlock_irq(phba->host->host_lock);
3280 (piocb->iocb_cmpl) (phba, piocb, piocb);
3281 spin_lock_irq(phba->host->host_lock);
3283 lpfc_sli_release_iocbq(phba, piocb);
3285 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) {
3286 phba->els_tmofunc.expires = jiffies + HZ * timeout;
3287 add_timer(&phba->els_tmofunc);
3289 spin_unlock_irq(phba->host->host_lock);
3293 lpfc_els_flush_cmd(struct lpfc_hba * phba)
3295 struct lpfc_sli_ring *pring;
3296 struct lpfc_iocbq *tmp_iocb, *piocb;
3298 struct lpfc_dmabuf *pcmd;
3300 uint32_t els_command;
3302 pring = &phba->sli.ring[LPFC_ELS_RING];
3303 spin_lock_irq(phba->host->host_lock);
3304 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3307 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3311 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3312 if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
3313 (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
3314 (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
3315 (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
3319 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3320 elscmd = (uint32_t *) (pcmd->virt);
3321 els_command = *elscmd;
3323 list_del(&piocb->list);
3324 pring->txcmplq_cnt--;
3326 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3327 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3329 if (piocb->iocb_cmpl) {
3330 spin_unlock_irq(phba->host->host_lock);
3331 (piocb->iocb_cmpl) (phba, piocb, piocb);
3332 spin_lock_irq(phba->host->host_lock);
3334 lpfc_sli_release_iocbq(phba, piocb);
3337 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3340 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3343 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3344 elscmd = (uint32_t *) (pcmd->virt);
3345 els_command = *elscmd;
3347 list_del(&piocb->list);
3348 pring->txcmplq_cnt--;
3350 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3351 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3353 if (piocb->iocb_cmpl) {
3354 spin_unlock_irq(phba->host->host_lock);
3355 (piocb->iocb_cmpl) (phba, piocb, piocb);
3356 spin_lock_irq(phba->host->host_lock);
3358 lpfc_sli_release_iocbq(phba, piocb);
3360 spin_unlock_irq(phba->host->host_lock);
3365 lpfc_els_unsol_event(struct lpfc_hba * phba,
3366 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
3368 struct lpfc_sli *psli;
3369 struct lpfc_nodelist *ndlp;
3370 struct lpfc_dmabuf *mp;
3377 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3378 uint32_t rjt_err = 0;
3381 icmd = &elsiocb->iocb;
3383 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3384 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3385 /* Not enough posted buffers; Try posting more buffers */
3386 phba->fc_stat.NoRcvBuf++;
3387 lpfc_post_buffer(phba, pring, 0, 1);
3391 /* If there are no BDEs associated with this IOCB,
3392 * there is nothing to do.
3394 if (icmd->ulpBdeCount == 0)
3397 /* type of ELS cmd is first 32bit word in packet */
3398 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3402 cont64[0].addrLow));
3409 lp = (uint32_t *) mp->virt;
3411 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3413 if (icmd->ulpStatus) {
3414 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3420 /* Check to see if link went down during discovery */
3421 if (lpfc_els_chk_latt(phba)) {
3422 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3428 did = icmd->un.rcvels.remoteID;
3429 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
3431 /* Cannot find existing Fabric ndlp, so allocate a new one */
3432 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3434 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3440 lpfc_nlp_init(phba, ndlp, did);
3442 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3443 ndlp->nlp_type |= NLP_FABRIC;
3447 phba->fc_stat.elsRcvFrame++;
3448 elsiocb->context1 = ndlp;
3449 elsiocb->context2 = mp;
3451 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3452 cmd &= ELS_CMD_MASK;
3454 /* ELS command <elsCmd> received from NPORT <did> */
3455 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3456 "%d:0112 ELS command x%x received from NPORT x%x "
3457 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
3461 phba->fc_stat.elsRcvPLOGI++;
3462 if (phba->hba_state < LPFC_DISC_AUTH) {
3466 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3469 phba->fc_stat.elsRcvFLOGI++;
3470 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3472 mempool_free( ndlp, phba->nlp_mem_pool);
3476 phba->fc_stat.elsRcvLOGO++;
3477 if (phba->hba_state < LPFC_DISC_AUTH) {
3481 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3484 phba->fc_stat.elsRcvPRLO++;
3485 if (phba->hba_state < LPFC_DISC_AUTH) {
3489 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3492 phba->fc_stat.elsRcvRSCN++;
3493 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3495 mempool_free( ndlp, phba->nlp_mem_pool);
3499 phba->fc_stat.elsRcvADISC++;
3500 if (phba->hba_state < LPFC_DISC_AUTH) {
3504 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
3507 phba->fc_stat.elsRcvPDISC++;
3508 if (phba->hba_state < LPFC_DISC_AUTH) {
3512 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
3515 phba->fc_stat.elsRcvFARPR++;
3516 lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
3519 phba->fc_stat.elsRcvFARP++;
3520 lpfc_els_rcv_farp(phba, elsiocb, ndlp);
3523 phba->fc_stat.elsRcvFAN++;
3524 lpfc_els_rcv_fan(phba, elsiocb, ndlp);
3527 phba->fc_stat.elsRcvPRLI++;
3528 if (phba->hba_state < LPFC_DISC_AUTH) {
3532 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3535 phba->fc_stat.elsRcvLIRR++;
3536 lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
3538 mempool_free( ndlp, phba->nlp_mem_pool);
3542 phba->fc_stat.elsRcvRPS++;
3543 lpfc_els_rcv_rps(phba, elsiocb, ndlp);
3545 mempool_free( ndlp, phba->nlp_mem_pool);
3549 phba->fc_stat.elsRcvRPL++;
3550 lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
3552 mempool_free( ndlp, phba->nlp_mem_pool);
3556 phba->fc_stat.elsRcvRNID++;
3557 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
3559 mempool_free( ndlp, phba->nlp_mem_pool);
3563 /* Unsupported ELS command, reject */
3566 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3567 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3568 "%d:0115 Unknown ELS command x%x received from "
3569 "NPORT x%x\n", phba->brd_no, cmd, did);
3571 mempool_free( ndlp, phba->nlp_mem_pool);
3576 /* check if need to LS_RJT received ELS cmd */
3578 stat.un.b.lsRjtRsvd0 = 0;
3579 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3580 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
3581 stat.un.b.vendorUnique = 0;
3582 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3585 if (elsiocb->context2) {
3586 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3590 /* check if need to drop received ELS cmd */
3591 if (drop_cmd == 1) {
3592 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3593 "%d:0111 Dropping received ELS cmd "
3594 "Data: x%x x%x x%x\n", phba->brd_no,
3595 icmd->ulpStatus, icmd->un.ulpWord[4],
3597 phba->fc_stat.elsRcvDrop++;