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)
246 struct lpfc_dmabuf *mp;
249 spin_lock_irq(phba->host->host_lock);
250 phba->fc_flag |= FC_FABRIC;
251 spin_unlock_irq(phba->host->host_lock);
253 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
254 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
255 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
257 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
259 if (phba->fc_topology == TOPOLOGY_LOOP) {
260 spin_lock_irq(phba->host->host_lock);
261 phba->fc_flag |= FC_PUBLIC_LOOP;
262 spin_unlock_irq(phba->host->host_lock);
265 * If we are a N-port connected to a Fabric, fixup sparam's so
266 * logins to devices on remote loops work.
268 phba->fc_sparam.cmn.altBbCredit = 1;
271 phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
272 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
273 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
274 ndlp->nlp_class_sup = 0;
275 if (sp->cls1.classValid)
276 ndlp->nlp_class_sup |= FC_COS_CLASS1;
277 if (sp->cls2.classValid)
278 ndlp->nlp_class_sup |= FC_COS_CLASS2;
279 if (sp->cls3.classValid)
280 ndlp->nlp_class_sup |= FC_COS_CLASS3;
281 if (sp->cls4.classValid)
282 ndlp->nlp_class_sup |= FC_COS_CLASS4;
283 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
284 sp->cmn.bbRcvSizeLsb;
285 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
287 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
291 phba->hba_state = LPFC_FABRIC_CFG_LINK;
292 lpfc_config_link(phba, mbox);
293 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
295 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
296 if (rc == MBX_NOT_FINISHED)
299 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
303 if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0))
306 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
307 mbox->context2 = ndlp;
309 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
310 if (rc == MBX_NOT_FINISHED)
311 goto fail_issue_reg_login;
315 fail_issue_reg_login:
316 mp = (struct lpfc_dmabuf *) mbox->context1;
317 lpfc_mbuf_free(phba, mp->virt, mp->phys);
320 mempool_free(mbox, phba->mbox_mem_pool);
326 * We FLOGIed into an NPort, initiate pt2pt protocol
329 lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
330 struct serv_parm *sp)
335 spin_lock_irq(phba->host->host_lock);
336 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
337 spin_unlock_irq(phba->host->host_lock);
339 phba->fc_edtov = FF_DEF_EDTOV;
340 phba->fc_ratov = FF_DEF_RATOV;
341 rc = memcmp(&phba->fc_portname, &sp->portName,
342 sizeof(struct lpfc_name));
344 /* This side will initiate the PLOGI */
345 spin_lock_irq(phba->host->host_lock);
346 phba->fc_flag |= FC_PT2PT_PLOGI;
347 spin_unlock_irq(phba->host->host_lock);
350 * N_Port ID cannot be 0, set our to LocalID the other
351 * side will be RemoteID.
356 phba->fc_myDID = PT2PT_LocalID;
358 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
362 lpfc_config_link(phba, mbox);
364 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
365 rc = lpfc_sli_issue_mbox(phba, mbox,
366 MBX_NOWAIT | MBX_STOP_IOCB);
367 if (rc == MBX_NOT_FINISHED) {
368 mempool_free(mbox, phba->mbox_mem_pool);
371 mempool_free(ndlp, phba->nlp_mem_pool);
373 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, PT2PT_RemoteID);
376 * Cannot find existing Fabric ndlp, so allocate a
379 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
383 lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID);
386 memcpy(&ndlp->nlp_portname, &sp->portName,
387 sizeof(struct lpfc_name));
388 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
389 sizeof(struct lpfc_name));
390 ndlp->nlp_state = NLP_STE_NPR_NODE;
391 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
392 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
394 /* This side will wait for the PLOGI */
395 mempool_free( ndlp, phba->nlp_mem_pool);
398 spin_lock_irq(phba->host->host_lock);
399 phba->fc_flag |= FC_PT2PT;
400 spin_unlock_irq(phba->host->host_lock);
402 /* Start discovery - this should just do CLEAR_LA */
403 lpfc_disc_start(phba);
410 lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
411 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
413 IOCB_t *irsp = &rspiocb->iocb;
414 struct lpfc_nodelist *ndlp = cmdiocb->context1;
415 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
416 struct serv_parm *sp;
419 /* Check to see if link went down during discovery */
420 if (lpfc_els_chk_latt(phba)) {
421 lpfc_nlp_remove(phba, ndlp);
425 if (irsp->ulpStatus) {
426 /* Check for retry */
427 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
428 /* ELS command is being retried */
431 /* FLOGI failed, so there is no fabric */
432 spin_lock_irq(phba->host->host_lock);
433 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
434 spin_unlock_irq(phba->host->host_lock);
436 /* If private loop, then allow max outstandting els to be
437 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
438 * alpa map would take too long otherwise.
440 if (phba->alpa_map[0] == 0) {
441 phba->cfg_discovery_threads =
442 LPFC_MAX_DISC_THREADS;
446 lpfc_printf_log(phba,
449 "%d:0100 FLOGI failure Data: x%x x%x x%x\n",
451 irsp->ulpStatus, irsp->un.ulpWord[4],
457 * The FLogI succeeded. Sync the data for the CPU before
460 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
462 sp = prsp->virt + sizeof(uint32_t);
464 /* FLOGI completes successfully */
465 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
466 "%d:0101 FLOGI completes sucessfully "
467 "Data: x%x x%x x%x x%x\n",
469 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
470 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
472 if (phba->hba_state == LPFC_FLOGI) {
474 * If Common Service Parameters indicate Nport
475 * we are point to point, if Fport we are Fabric.
478 rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp);
480 rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp);
487 lpfc_nlp_remove(phba, ndlp);
489 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
490 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
491 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
492 /* FLOGI failed, so just use loop map to make discovery list */
493 lpfc_disc_list_loopmap(phba);
495 /* Start discovery */
496 lpfc_disc_start(phba);
500 lpfc_els_free_iocb(phba, cmdiocb);
504 lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
507 struct serv_parm *sp;
509 struct lpfc_iocbq *elsiocb;
510 struct lpfc_sli_ring *pring;
516 pring = &phba->sli.ring[LPFC_ELS_RING];
518 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
519 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
520 ndlp->nlp_DID, ELS_CMD_FLOGI);
524 icmd = &elsiocb->iocb;
525 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
527 /* For FLOGI request, remainder of payload is service parameters */
528 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
529 pcmd += sizeof (uint32_t);
530 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
531 sp = (struct serv_parm *) pcmd;
533 /* Setup CSPs accordingly for Fabric */
535 sp->cmn.w2.r_a_tov = 0;
536 sp->cls1.classValid = 0;
537 sp->cls2.seqDelivery = 1;
538 sp->cls3.seqDelivery = 1;
539 if (sp->cmn.fcphLow < FC_PH3)
540 sp->cmn.fcphLow = FC_PH3;
541 if (sp->cmn.fcphHigh < FC_PH3)
542 sp->cmn.fcphHigh = FC_PH3;
544 tmo = phba->fc_ratov;
545 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
546 lpfc_set_disctmo(phba);
547 phba->fc_ratov = tmo;
549 phba->fc_stat.elsXmitFLOGI++;
550 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
551 spin_lock_irq(phba->host->host_lock);
552 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
553 spin_unlock_irq(phba->host->host_lock);
554 if (rc == IOCB_ERROR) {
555 lpfc_els_free_iocb(phba, elsiocb);
562 lpfc_els_abort_flogi(struct lpfc_hba * phba)
564 struct lpfc_sli_ring *pring;
565 struct lpfc_iocbq *iocb, *next_iocb;
566 struct lpfc_nodelist *ndlp;
569 /* Abort outstanding I/O on NPort <nlp_DID> */
570 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
571 "%d:0201 Abort outstanding I/O on NPort x%x\n",
572 phba->brd_no, Fabric_DID);
574 pring = &phba->sli.ring[LPFC_ELS_RING];
577 * Check the txcmplq for an iocb that matches the nport the driver is
580 spin_lock_irq(phba->host->host_lock);
581 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
583 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
584 ndlp = (struct lpfc_nodelist *)(iocb->context1);
585 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
586 list_del(&iocb->list);
587 pring->txcmplq_cnt--;
589 if ((icmd->un.elsreq64.bdl.ulpIoTag32)) {
590 lpfc_sli_issue_abort_iotag32
593 if (iocb->iocb_cmpl) {
594 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
595 icmd->un.ulpWord[4] =
597 spin_unlock_irq(phba->host->host_lock);
598 (iocb->iocb_cmpl) (phba, iocb, iocb);
599 spin_lock_irq(phba->host->host_lock);
601 lpfc_sli_release_iocbq(phba, iocb);
605 spin_unlock_irq(phba->host->host_lock);
611 lpfc_initial_flogi(struct lpfc_hba * phba)
613 struct lpfc_nodelist *ndlp;
615 /* First look for the Fabric ndlp */
616 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, Fabric_DID);
618 /* Cannot find existing Fabric ndlp, so allocate a new one */
619 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
622 lpfc_nlp_init(phba, ndlp, Fabric_DID);
624 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
626 if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
627 mempool_free( ndlp, phba->nlp_mem_pool);
633 lpfc_more_plogi(struct lpfc_hba * phba)
637 if (phba->num_disc_nodes)
638 phba->num_disc_nodes--;
640 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
641 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
642 "%d:0232 Continue discovery with %d PLOGIs to go "
643 "Data: x%x x%x x%x\n",
644 phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
645 phba->fc_flag, phba->hba_state);
647 /* Check to see if there are more PLOGIs to be sent */
648 if (phba->fc_flag & FC_NLP_MORE) {
649 /* go thru NPR list and issue any remaining ELS PLOGIs */
650 sentplogi = lpfc_els_disc_plogi(phba);
655 static struct lpfc_nodelist *
656 lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_dmabuf *prsp,
657 struct lpfc_nodelist *ndlp)
659 struct lpfc_nodelist *new_ndlp;
661 struct serv_parm *sp;
662 uint8_t name[sizeof (struct lpfc_name)];
665 /* Fabric nodes can have the same WWPN so we don't bother searching
666 * by WWPN. Just return the ndlp that was given to us.
668 if (ndlp->nlp_type & NLP_FABRIC)
671 lp = (uint32_t *) prsp->virt;
672 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
673 memset(name, 0, sizeof (struct lpfc_name));
675 /* Now we to find out if the NPort we are logging into, matches the WWPN
676 * we have for that ndlp. If not, we have some work to do.
678 new_ndlp = lpfc_findnode_wwpn(phba, NLP_SEARCH_ALL, &sp->portName);
680 if (new_ndlp == ndlp)
685 memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name));
688 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
692 lpfc_nlp_init(phba, new_ndlp, ndlp->nlp_DID);
695 lpfc_unreg_rpi(phba, new_ndlp);
696 new_ndlp->nlp_DID = ndlp->nlp_DID;
697 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
698 new_ndlp->nlp_state = ndlp->nlp_state;
699 lpfc_nlp_list(phba, new_ndlp, ndlp->nlp_flag & NLP_LIST_MASK);
701 /* Move this back to NPR list */
702 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
703 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
706 lpfc_unreg_rpi(phba, ndlp);
707 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
708 ndlp->nlp_state = NLP_STE_NPR_NODE;
709 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
715 lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
716 struct lpfc_iocbq * rspiocb)
719 struct lpfc_nodelist *ndlp;
720 struct lpfc_dmabuf *prsp;
721 int disc, rc, did, type;
724 /* we pass cmdiocb to state machine which needs rspiocb as well */
725 cmdiocb->context_un.rsp_iocb = rspiocb;
727 irsp = &rspiocb->iocb;
728 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL,
729 irsp->un.elsreq64.remoteID);
733 /* Since ndlp can be freed in the disc state machine, note if this node
734 * is being used during discovery.
736 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
737 spin_lock_irq(phba->host->host_lock);
738 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
739 spin_unlock_irq(phba->host->host_lock);
742 /* PLOGI completes to NPort <nlp_DID> */
743 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
744 "%d:0102 PLOGI completes to NPort x%x "
745 "Data: x%x x%x x%x x%x x%x\n",
746 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
747 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
748 phba->num_disc_nodes);
750 /* Check to see if link went down during discovery */
751 if (lpfc_els_chk_latt(phba)) {
752 spin_lock_irq(phba->host->host_lock);
753 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
754 spin_unlock_irq(phba->host->host_lock);
758 /* ndlp could be freed in DSM, save these values now */
759 type = ndlp->nlp_type;
762 if (irsp->ulpStatus) {
763 /* Check for retry */
764 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
765 /* ELS command is being retried */
767 spin_lock_irq(phba->host->host_lock);
768 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
769 spin_unlock_irq(phba->host->host_lock);
775 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
776 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
777 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
778 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
779 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
780 rc = NLP_STE_FREED_NODE;
782 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
786 /* Good status, call state machine */
787 prsp = list_entry(((struct lpfc_dmabuf *)
788 cmdiocb->context2)->list.next,
789 struct lpfc_dmabuf, list);
790 ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp);
791 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
795 if (disc && phba->num_disc_nodes) {
796 /* Check to see if there are more PLOGIs to be sent */
797 lpfc_more_plogi(phba);
799 if (phba->num_disc_nodes == 0) {
800 spin_lock_irq(phba->host->host_lock);
801 phba->fc_flag &= ~FC_NDISC_ACTIVE;
802 spin_unlock_irq(phba->host->host_lock);
804 lpfc_can_disctmo(phba);
805 if (phba->fc_flag & FC_RSCN_MODE) {
807 * Check to see if more RSCNs came in while
808 * we were processing this one.
810 if ((phba->fc_rscn_id_cnt == 0) &&
811 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
812 spin_lock_irq(phba->host->host_lock);
813 phba->fc_flag &= ~FC_RSCN_MODE;
814 spin_unlock_irq(phba->host->host_lock);
816 lpfc_els_handle_rscn(phba);
823 lpfc_els_free_iocb(phba, cmdiocb);
828 lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
830 struct serv_parm *sp;
832 struct lpfc_iocbq *elsiocb;
833 struct lpfc_sli_ring *pring;
834 struct lpfc_sli *psli;
839 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
841 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
842 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, NULL, did,
847 icmd = &elsiocb->iocb;
848 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
850 /* For PLOGI request, remainder of payload is service parameters */
851 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
852 pcmd += sizeof (uint32_t);
853 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
854 sp = (struct serv_parm *) pcmd;
856 if (sp->cmn.fcphLow < FC_PH_4_3)
857 sp->cmn.fcphLow = FC_PH_4_3;
859 if (sp->cmn.fcphHigh < FC_PH3)
860 sp->cmn.fcphHigh = FC_PH3;
862 phba->fc_stat.elsXmitPLOGI++;
863 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
864 spin_lock_irq(phba->host->host_lock);
865 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
866 spin_unlock_irq(phba->host->host_lock);
867 lpfc_els_free_iocb(phba, elsiocb);
870 spin_unlock_irq(phba->host->host_lock);
875 lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
876 struct lpfc_iocbq * rspiocb)
879 struct lpfc_sli *psli;
880 struct lpfc_nodelist *ndlp;
883 /* we pass cmdiocb to state machine which needs rspiocb as well */
884 cmdiocb->context_un.rsp_iocb = rspiocb;
886 irsp = &(rspiocb->iocb);
887 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
888 spin_lock_irq(phba->host->host_lock);
889 ndlp->nlp_flag &= ~NLP_PRLI_SND;
890 spin_unlock_irq(phba->host->host_lock);
892 /* PRLI completes to NPort <nlp_DID> */
893 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
894 "%d:0103 PRLI completes to NPort x%x "
895 "Data: x%x x%x x%x x%x\n",
896 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
897 irsp->un.ulpWord[4], irsp->ulpTimeout,
898 phba->num_disc_nodes);
900 phba->fc_prli_sent--;
901 /* Check to see if link went down during discovery */
902 if (lpfc_els_chk_latt(phba))
905 if (irsp->ulpStatus) {
906 /* Check for retry */
907 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
908 /* ELS command is being retried */
912 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
913 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
914 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
915 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
916 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
919 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
923 /* Good status, call state machine */
924 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
928 lpfc_els_free_iocb(phba, cmdiocb);
933 lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
938 struct lpfc_iocbq *elsiocb;
939 struct lpfc_sli_ring *pring;
940 struct lpfc_sli *psli;
945 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
947 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
948 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
949 ndlp->nlp_DID, ELS_CMD_PRLI);
953 icmd = &elsiocb->iocb;
954 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
956 /* For PRLI request, remainder of payload is service parameters */
957 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
958 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
959 pcmd += sizeof (uint32_t);
961 /* For PRLI, remainder of payload is PRLI parameter page */
964 * If our firmware version is 3.20 or later,
965 * set the following bits for FC-TAPE support.
967 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
968 npr->ConfmComplAllowed = 1;
970 npr->TaskRetryIdReq = 1;
972 npr->estabImagePair = 1;
973 npr->readXferRdyDis = 1;
975 /* For FCP support */
976 npr->prliType = PRLI_FCP_TYPE;
977 npr->initiatorFunc = 1;
979 phba->fc_stat.elsXmitPRLI++;
980 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
981 spin_lock_irq(phba->host->host_lock);
982 ndlp->nlp_flag |= NLP_PRLI_SND;
983 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
984 ndlp->nlp_flag &= ~NLP_PRLI_SND;
985 spin_unlock_irq(phba->host->host_lock);
986 lpfc_els_free_iocb(phba, elsiocb);
989 spin_unlock_irq(phba->host->host_lock);
990 phba->fc_prli_sent++;
995 lpfc_more_adisc(struct lpfc_hba * phba)
999 if (phba->num_disc_nodes)
1000 phba->num_disc_nodes--;
1002 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1003 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1004 "%d:0210 Continue discovery with %d ADISCs to go "
1005 "Data: x%x x%x x%x\n",
1006 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
1007 phba->fc_flag, phba->hba_state);
1009 /* Check to see if there are more ADISCs to be sent */
1010 if (phba->fc_flag & FC_NLP_MORE) {
1011 lpfc_set_disctmo(phba);
1013 /* go thru NPR list and issue any remaining ELS ADISCs */
1014 sentadisc = lpfc_els_disc_adisc(phba);
1020 lpfc_rscn_disc(struct lpfc_hba * phba)
1022 /* RSCN discovery */
1023 /* go thru NPR list and issue ELS PLOGIs */
1024 if (phba->fc_npr_cnt) {
1025 if (lpfc_els_disc_plogi(phba))
1028 if (phba->fc_flag & FC_RSCN_MODE) {
1029 /* Check to see if more RSCNs came in while we were
1030 * processing this one.
1032 if ((phba->fc_rscn_id_cnt == 0) &&
1033 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1034 spin_lock_irq(phba->host->host_lock);
1035 phba->fc_flag &= ~FC_RSCN_MODE;
1036 spin_unlock_irq(phba->host->host_lock);
1038 lpfc_els_handle_rscn(phba);
1044 lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1045 struct lpfc_iocbq * rspiocb)
1048 struct lpfc_sli *psli;
1049 struct lpfc_nodelist *ndlp;
1055 /* we pass cmdiocb to state machine which needs rspiocb as well */
1056 cmdiocb->context_un.rsp_iocb = rspiocb;
1058 irsp = &(rspiocb->iocb);
1059 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1061 /* Since ndlp can be freed in the disc state machine, note if this node
1062 * is being used during discovery.
1064 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1065 spin_lock_irq(phba->host->host_lock);
1066 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1067 spin_unlock_irq(phba->host->host_lock);
1069 /* ADISC completes to NPort <nlp_DID> */
1070 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1071 "%d:0104 ADISC completes to NPort x%x "
1072 "Data: x%x x%x x%x x%x x%x\n",
1073 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1074 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
1075 phba->num_disc_nodes);
1077 /* Check to see if link went down during discovery */
1078 if (lpfc_els_chk_latt(phba)) {
1079 spin_lock_irq(phba->host->host_lock);
1080 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1081 spin_unlock_irq(phba->host->host_lock);
1085 if (irsp->ulpStatus) {
1086 /* Check for retry */
1087 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1088 /* ELS command is being retried */
1090 spin_lock_irq(phba->host->host_lock);
1091 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1092 spin_unlock_irq(phba->host->host_lock);
1093 lpfc_set_disctmo(phba);
1098 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1099 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1100 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1101 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
1102 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
1103 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1104 NLP_EVT_CMPL_ADISC);
1107 /* Good status, call state machine */
1108 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1109 NLP_EVT_CMPL_ADISC);
1112 if (disc && phba->num_disc_nodes) {
1113 /* Check to see if there are more ADISCs to be sent */
1114 lpfc_more_adisc(phba);
1116 /* Check to see if we are done with ADISC authentication */
1117 if (phba->num_disc_nodes == 0) {
1118 lpfc_can_disctmo(phba);
1119 /* If we get here, there is nothing left to wait for */
1120 if ((phba->hba_state < LPFC_HBA_READY) &&
1121 (phba->hba_state != LPFC_CLEAR_LA)) {
1122 /* Link up discovery */
1123 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
1125 phba->hba_state = LPFC_CLEAR_LA;
1126 lpfc_clear_la(phba, mbox);
1128 lpfc_mbx_cmpl_clear_la;
1129 rc = lpfc_sli_issue_mbox
1131 (MBX_NOWAIT | MBX_STOP_IOCB));
1132 if (rc == MBX_NOT_FINISHED) {
1134 phba->mbox_mem_pool);
1135 lpfc_disc_flush_list(phba);
1136 psli->ring[(psli->extra_ring)].
1138 ~LPFC_STOP_IOCB_EVENT;
1139 psli->ring[(psli->fcp_ring)].
1141 ~LPFC_STOP_IOCB_EVENT;
1142 psli->ring[(psli->next_ring)].
1144 ~LPFC_STOP_IOCB_EVENT;
1150 lpfc_rscn_disc(phba);
1155 lpfc_els_free_iocb(phba, cmdiocb);
1160 lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1165 struct lpfc_iocbq *elsiocb;
1166 struct lpfc_sli_ring *pring;
1167 struct lpfc_sli *psli;
1172 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1174 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
1175 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1176 ndlp->nlp_DID, ELS_CMD_ADISC);
1180 icmd = &elsiocb->iocb;
1181 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1183 /* For ADISC request, remainder of payload is service parameters */
1184 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1185 pcmd += sizeof (uint32_t);
1187 /* Fill in ADISC payload */
1188 ap = (ADISC *) pcmd;
1189 ap->hardAL_PA = phba->fc_pref_ALPA;
1190 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1191 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1192 ap->DID = be32_to_cpu(phba->fc_myDID);
1194 phba->fc_stat.elsXmitADISC++;
1195 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1196 spin_lock_irq(phba->host->host_lock);
1197 ndlp->nlp_flag |= NLP_ADISC_SND;
1198 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1199 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1200 spin_unlock_irq(phba->host->host_lock);
1201 lpfc_els_free_iocb(phba, elsiocb);
1204 spin_unlock_irq(phba->host->host_lock);
1209 lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1210 struct lpfc_iocbq * rspiocb)
1213 struct lpfc_sli *psli;
1214 struct lpfc_nodelist *ndlp;
1217 /* we pass cmdiocb to state machine which needs rspiocb as well */
1218 cmdiocb->context_un.rsp_iocb = rspiocb;
1220 irsp = &(rspiocb->iocb);
1221 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1222 spin_lock_irq(phba->host->host_lock);
1223 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1224 spin_unlock_irq(phba->host->host_lock);
1226 /* LOGO completes to NPort <nlp_DID> */
1227 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1228 "%d:0105 LOGO completes to NPort x%x "
1229 "Data: x%x x%x x%x x%x\n",
1230 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1231 irsp->un.ulpWord[4], irsp->ulpTimeout,
1232 phba->num_disc_nodes);
1234 /* Check to see if link went down during discovery */
1235 if (lpfc_els_chk_latt(phba))
1238 if (irsp->ulpStatus) {
1239 /* Check for retry */
1240 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1241 /* ELS command is being retried */
1245 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1246 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1247 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1248 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1249 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1252 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1256 /* Good status, call state machine.
1257 * This will unregister the rpi if needed.
1259 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
1263 lpfc_els_free_iocb(phba, cmdiocb);
1268 lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1272 struct lpfc_iocbq *elsiocb;
1273 struct lpfc_sli_ring *pring;
1274 struct lpfc_sli *psli;
1279 pring = &psli->ring[LPFC_ELS_RING];
1281 cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name);
1282 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1283 ndlp->nlp_DID, ELS_CMD_LOGO);
1287 icmd = &elsiocb->iocb;
1288 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1289 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1290 pcmd += sizeof (uint32_t);
1292 /* Fill in LOGO payload */
1293 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
1294 pcmd += sizeof (uint32_t);
1295 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
1297 phba->fc_stat.elsXmitLOGO++;
1298 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1299 spin_lock_irq(phba->host->host_lock);
1300 ndlp->nlp_flag |= NLP_LOGO_SND;
1301 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1302 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1303 spin_unlock_irq(phba->host->host_lock);
1304 lpfc_els_free_iocb(phba, elsiocb);
1307 spin_unlock_irq(phba->host->host_lock);
1312 lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1313 struct lpfc_iocbq * rspiocb)
1317 irsp = &rspiocb->iocb;
1319 /* ELS cmd tag <ulpIoTag> completes */
1320 lpfc_printf_log(phba,
1323 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1325 irsp->ulpIoTag, irsp->ulpStatus,
1326 irsp->un.ulpWord[4], irsp->ulpTimeout);
1328 /* Check to see if link went down during discovery */
1329 lpfc_els_chk_latt(phba);
1330 lpfc_els_free_iocb(phba, cmdiocb);
1335 lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1338 struct lpfc_iocbq *elsiocb;
1339 struct lpfc_sli_ring *pring;
1340 struct lpfc_sli *psli;
1343 struct lpfc_nodelist *ndlp;
1346 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1347 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
1348 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1352 lpfc_nlp_init(phba, ndlp, nportid);
1354 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1355 ndlp->nlp_DID, ELS_CMD_SCR);
1357 mempool_free( ndlp, phba->nlp_mem_pool);
1361 icmd = &elsiocb->iocb;
1362 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1364 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1365 pcmd += sizeof (uint32_t);
1367 /* For SCR, remainder of payload is SCR parameter page */
1368 memset(pcmd, 0, sizeof (SCR));
1369 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1371 phba->fc_stat.elsXmitSCR++;
1372 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1373 spin_lock_irq(phba->host->host_lock);
1374 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1375 spin_unlock_irq(phba->host->host_lock);
1376 mempool_free( ndlp, phba->nlp_mem_pool);
1377 lpfc_els_free_iocb(phba, elsiocb);
1380 spin_unlock_irq(phba->host->host_lock);
1381 mempool_free( ndlp, phba->nlp_mem_pool);
1386 lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1389 struct lpfc_iocbq *elsiocb;
1390 struct lpfc_sli_ring *pring;
1391 struct lpfc_sli *psli;
1396 struct lpfc_nodelist *ondlp;
1397 struct lpfc_nodelist *ndlp;
1400 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1401 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
1402 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1405 lpfc_nlp_init(phba, ndlp, nportid);
1407 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1408 ndlp->nlp_DID, ELS_CMD_RNID);
1410 mempool_free( ndlp, phba->nlp_mem_pool);
1414 icmd = &elsiocb->iocb;
1415 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1417 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1418 pcmd += sizeof (uint32_t);
1420 /* Fill in FARPR payload */
1421 fp = (FARP *) (pcmd);
1422 memset(fp, 0, sizeof (FARP));
1423 lp = (uint32_t *) pcmd;
1424 *lp++ = be32_to_cpu(nportid);
1425 *lp++ = be32_to_cpu(phba->fc_myDID);
1427 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1429 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1430 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1431 if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
1432 memcpy(&fp->OportName, &ondlp->nlp_portname,
1433 sizeof (struct lpfc_name));
1434 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1435 sizeof (struct lpfc_name));
1438 phba->fc_stat.elsXmitFARPR++;
1439 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1440 spin_lock_irq(phba->host->host_lock);
1441 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1442 spin_unlock_irq(phba->host->host_lock);
1443 mempool_free( ndlp, phba->nlp_mem_pool);
1444 lpfc_els_free_iocb(phba, elsiocb);
1447 spin_unlock_irq(phba->host->host_lock);
1448 mempool_free( ndlp, phba->nlp_mem_pool);
1453 lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp)
1455 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1456 del_timer_sync(&nlp->nlp_delayfunc);
1457 nlp->nlp_last_elscmd = 0;
1459 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1460 list_del_init(&nlp->els_retry_evt.evt_listp);
1462 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1463 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1464 if (phba->num_disc_nodes) {
1465 /* Check to see if there are more
1468 lpfc_more_plogi(phba);
1470 if (phba->num_disc_nodes == 0) {
1471 phba->fc_flag &= ~FC_NDISC_ACTIVE;
1472 lpfc_can_disctmo(phba);
1473 if (phba->fc_flag & FC_RSCN_MODE) {
1475 * Check to see if more RSCNs
1476 * came in while we were
1477 * processing this one.
1479 if((phba->fc_rscn_id_cnt==0) &&
1480 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
1481 phba->fc_flag &= ~FC_RSCN_MODE;
1484 lpfc_els_handle_rscn(phba);
1494 lpfc_els_retry_delay(unsigned long ptr)
1496 struct lpfc_nodelist *ndlp;
1497 struct lpfc_hba *phba;
1498 unsigned long iflag;
1499 struct lpfc_work_evt *evtp;
1501 ndlp = (struct lpfc_nodelist *)ptr;
1502 phba = ndlp->nlp_phba;
1503 evtp = &ndlp->els_retry_evt;
1505 spin_lock_irqsave(phba->host->host_lock, iflag);
1506 if (!list_empty(&evtp->evt_listp)) {
1507 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1511 evtp->evt_arg1 = ndlp;
1512 evtp->evt = LPFC_EVT_ELS_RETRY;
1513 list_add_tail(&evtp->evt_listp, &phba->work_list);
1514 if (phba->work_wait)
1515 wake_up(phba->work_wait);
1517 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1522 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1524 struct lpfc_hba *phba;
1529 phba = ndlp->nlp_phba;
1530 spin_lock_irq(phba->host->host_lock);
1531 did = ndlp->nlp_DID;
1532 cmd = ndlp->nlp_last_elscmd;
1533 ndlp->nlp_last_elscmd = 0;
1535 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1536 spin_unlock_irq(phba->host->host_lock);
1540 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1541 spin_unlock_irq(phba->host->host_lock);
1543 * If a discovery event readded nlp_delayfunc after timer
1544 * firing and before processing the timer, cancel the
1547 del_timer_sync(&ndlp->nlp_delayfunc);
1548 retry = ndlp->nlp_retry;
1552 lpfc_issue_els_flogi(phba, ndlp, retry);
1555 if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) {
1556 ndlp->nlp_prev_state = ndlp->nlp_state;
1557 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1558 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1562 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) {
1563 ndlp->nlp_prev_state = ndlp->nlp_state;
1564 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1565 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1569 if (!lpfc_issue_els_prli(phba, ndlp, retry)) {
1570 ndlp->nlp_prev_state = ndlp->nlp_state;
1571 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1572 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1576 if (!lpfc_issue_els_logo(phba, ndlp, retry)) {
1577 ndlp->nlp_prev_state = ndlp->nlp_state;
1578 ndlp->nlp_state = NLP_STE_NPR_NODE;
1579 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1587 lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1588 struct lpfc_iocbq * rspiocb)
1591 struct lpfc_dmabuf *pcmd;
1592 struct lpfc_nodelist *ndlp;
1595 int retry, maxretry;
1602 maxretry = lpfc_max_els_tries;
1603 irsp = &rspiocb->iocb;
1604 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1605 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1608 /* Note: context2 may be 0 for internal driver abort
1609 * of delays ELS command.
1612 if (pcmd && pcmd->virt) {
1613 elscmd = (uint32_t *) (pcmd->virt);
1618 did = ndlp->nlp_DID;
1620 /* We should only hit this case for retrying PLOGI */
1621 did = irsp->un.elsreq64.remoteID;
1622 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1623 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1627 switch (irsp->ulpStatus) {
1628 case IOSTAT_FCP_RSP_ERROR:
1629 case IOSTAT_REMOTE_STOP:
1632 case IOSTAT_LOCAL_REJECT:
1633 switch ((irsp->un.ulpWord[4] & 0xff)) {
1634 case IOERR_LOOP_OPEN_FAILURE:
1635 if (cmd == ELS_CMD_PLOGI) {
1636 if (cmdiocb->retry == 0) {
1643 case IOERR_SEQUENCE_TIMEOUT:
1647 case IOERR_NO_RESOURCES:
1648 if (cmd == ELS_CMD_PLOGI) {
1654 case IOERR_INVALID_RPI:
1660 case IOSTAT_NPORT_RJT:
1661 case IOSTAT_FABRIC_RJT:
1662 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1668 case IOSTAT_NPORT_BSY:
1669 case IOSTAT_FABRIC_BSY:
1674 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1675 /* Added for Vendor specifc support
1676 * Just keep retrying for these Rsn / Exp codes
1678 switch (stat.un.b.lsRjtRsnCode) {
1679 case LSRJT_UNABLE_TPC:
1680 if (stat.un.b.lsRjtRsnCodeExp ==
1681 LSEXP_CMD_IN_PROGRESS) {
1682 if (cmd == ELS_CMD_PLOGI) {
1689 if (cmd == ELS_CMD_PLOGI) {
1691 maxretry = lpfc_max_els_tries + 1;
1697 case LSRJT_LOGICAL_BSY:
1698 if (cmd == ELS_CMD_PLOGI) {
1707 case IOSTAT_INTERMED_RSP:
1715 if (did == FDMI_DID)
1718 if ((++cmdiocb->retry) >= maxretry) {
1719 phba->fc_stat.elsRetryExceeded++;
1725 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1726 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1727 "%d:0107 Retry ELS command x%x to remote "
1728 "NPORT x%x Data: x%x x%x\n",
1730 cmd, did, cmdiocb->retry, delay);
1732 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1733 /* If discovery / RSCN timer is running, reset it */
1734 if (timer_pending(&phba->fc_disctmo) ||
1735 (phba->fc_flag & FC_RSCN_MODE)) {
1736 lpfc_set_disctmo(phba);
1740 phba->fc_stat.elsXmitRetry++;
1741 if (ndlp && delay) {
1742 phba->fc_stat.elsDelayRetry++;
1743 ndlp->nlp_retry = cmdiocb->retry;
1745 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1746 ndlp->nlp_flag |= NLP_DELAY_TMO;
1748 ndlp->nlp_prev_state = ndlp->nlp_state;
1749 ndlp->nlp_state = NLP_STE_NPR_NODE;
1750 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1751 ndlp->nlp_last_elscmd = cmd;
1757 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
1761 ndlp->nlp_prev_state = ndlp->nlp_state;
1762 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1763 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1765 lpfc_issue_els_plogi(phba, did, cmdiocb->retry);
1768 ndlp->nlp_prev_state = ndlp->nlp_state;
1769 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1770 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1771 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
1774 ndlp->nlp_prev_state = ndlp->nlp_state;
1775 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1776 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1777 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
1780 ndlp->nlp_prev_state = ndlp->nlp_state;
1781 ndlp->nlp_state = NLP_STE_NPR_NODE;
1782 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1783 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
1788 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1789 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1790 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
1793 cmd, did, cmdiocb->retry);
1799 lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
1801 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1803 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1804 if (elsiocb->context2) {
1805 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1806 /* Free the response before processing the command. */
1807 if (!list_empty(&buf_ptr1->list)) {
1808 list_remove_head(&buf_ptr1->list, buf_ptr,
1811 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1814 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1818 if (elsiocb->context3) {
1819 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1820 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1823 spin_lock_irq(phba->host->host_lock);
1824 lpfc_sli_release_iocbq(phba, elsiocb);
1825 spin_unlock_irq(phba->host->host_lock);
1830 lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1831 struct lpfc_iocbq * rspiocb)
1833 struct lpfc_nodelist *ndlp;
1835 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1837 /* ACC to LOGO completes to NPort <nlp_DID> */
1838 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1839 "%d:0109 ACC to LOGO completes to NPort x%x "
1840 "Data: x%x x%x x%x\n",
1841 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1842 ndlp->nlp_state, ndlp->nlp_rpi);
1844 switch (ndlp->nlp_state) {
1845 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1846 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1848 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1849 lpfc_unreg_rpi(phba, ndlp);
1854 lpfc_els_free_iocb(phba, cmdiocb);
1859 lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1860 struct lpfc_iocbq * rspiocb)
1863 struct lpfc_nodelist *ndlp;
1864 LPFC_MBOXQ_t *mbox = NULL;
1865 struct lpfc_dmabuf *mp;
1867 irsp = &rspiocb->iocb;
1869 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1870 if (cmdiocb->context_un.mbox)
1871 mbox = cmdiocb->context_un.mbox;
1874 /* Check to see if link went down during discovery */
1875 if ((lpfc_els_chk_latt(phba)) || !ndlp) {
1877 mp = (struct lpfc_dmabuf *) mbox->context1;
1879 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1882 mempool_free( mbox, phba->mbox_mem_pool);
1887 /* ELS response tag <ulpIoTag> completes */
1888 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1889 "%d:0110 ELS response tag x%x completes "
1890 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
1892 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
1893 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1894 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
1898 if ((rspiocb->iocb.ulpStatus == 0)
1899 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
1900 lpfc_unreg_rpi(phba, ndlp);
1901 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1902 mbox->context2 = ndlp;
1903 ndlp->nlp_prev_state = ndlp->nlp_state;
1904 ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE;
1905 lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
1906 if (lpfc_sli_issue_mbox(phba, mbox,
1907 (MBX_NOWAIT | MBX_STOP_IOCB))
1908 != MBX_NOT_FINISHED) {
1911 /* NOTE: we should have messages for unsuccessful
1914 /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */
1915 if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1916 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1917 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1918 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) {
1919 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1920 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1925 mp = (struct lpfc_dmabuf *) mbox->context1;
1927 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1930 mempool_free(mbox, phba->mbox_mem_pool);
1934 spin_lock_irq(phba->host->host_lock);
1935 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1936 spin_unlock_irq(phba->host->host_lock);
1938 lpfc_els_free_iocb(phba, cmdiocb);
1943 lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1944 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
1945 LPFC_MBOXQ_t * mbox, uint8_t newnode)
1949 struct lpfc_iocbq *elsiocb;
1950 struct lpfc_sli_ring *pring;
1951 struct lpfc_sli *psli;
1955 ELS_PKT *els_pkt_ptr;
1958 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1959 oldcmd = &oldiocb->iocb;
1963 cmdsize = sizeof (uint32_t);
1964 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1965 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1967 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
1970 icmd = &elsiocb->iocb;
1971 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1972 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1973 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1974 pcmd += sizeof (uint32_t);
1977 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
1978 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1979 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1983 icmd = &elsiocb->iocb;
1984 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1985 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1988 elsiocb->context_un.mbox = mbox;
1990 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1991 pcmd += sizeof (uint32_t);
1992 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
1995 cmdsize = sizeof (uint32_t) + sizeof (PRLO);
1996 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1997 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2001 icmd = &elsiocb->iocb;
2002 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2003 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2005 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
2006 sizeof (uint32_t) + sizeof (PRLO));
2007 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2008 els_pkt_ptr = (ELS_PKT *) pcmd;
2009 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
2016 elsiocb->context1 = NULL;
2018 /* Xmit ELS ACC response tag <ulpIoTag> */
2019 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2020 "%d:0128 Xmit ELS ACC response tag x%x "
2021 "Data: x%x x%x x%x x%x x%x\n",
2023 elsiocb->iocb.ulpIoTag,
2024 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2025 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2027 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2028 spin_lock_irq(phba->host->host_lock);
2029 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2030 spin_unlock_irq(phba->host->host_lock);
2031 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2033 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2036 phba->fc_stat.elsXmitACC++;
2037 spin_lock_irq(phba->host->host_lock);
2038 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2039 spin_unlock_irq(phba->host->host_lock);
2040 if (rc == IOCB_ERROR) {
2041 lpfc_els_free_iocb(phba, elsiocb);
2048 lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
2049 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2053 struct lpfc_iocbq *elsiocb;
2054 struct lpfc_sli_ring *pring;
2055 struct lpfc_sli *psli;
2061 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2063 cmdsize = 2 * sizeof (uint32_t);
2064 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2065 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
2069 icmd = &elsiocb->iocb;
2070 oldcmd = &oldiocb->iocb;
2071 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2072 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2074 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2075 pcmd += sizeof (uint32_t);
2076 *((uint32_t *) (pcmd)) = rejectError;
2078 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2079 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2080 "%d:0129 Xmit ELS RJT x%x response tag x%x "
2081 "Data: x%x x%x x%x x%x x%x\n",
2083 rejectError, elsiocb->iocb.ulpIoTag,
2084 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2085 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2087 phba->fc_stat.elsXmitLSRJT++;
2088 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2089 spin_lock_irq(phba->host->host_lock);
2090 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2091 spin_unlock_irq(phba->host->host_lock);
2092 if (rc == IOCB_ERROR) {
2093 lpfc_els_free_iocb(phba, elsiocb);
2100 lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2101 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2106 struct lpfc_iocbq *elsiocb;
2107 struct lpfc_sli_ring *pring;
2108 struct lpfc_sli *psli;
2114 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2116 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
2117 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2118 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2122 /* Xmit ADISC ACC response tag <ulpIoTag> */
2123 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2124 "%d:0130 Xmit ADISC ACC response tag x%x "
2125 "Data: x%x x%x x%x x%x x%x\n",
2127 elsiocb->iocb.ulpIoTag,
2128 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2129 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2131 icmd = &elsiocb->iocb;
2132 oldcmd = &oldiocb->iocb;
2133 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2134 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2136 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2137 pcmd += sizeof (uint32_t);
2139 ap = (ADISC *) (pcmd);
2140 ap->hardAL_PA = phba->fc_pref_ALPA;
2141 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2142 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2143 ap->DID = be32_to_cpu(phba->fc_myDID);
2145 phba->fc_stat.elsXmitACC++;
2146 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2147 spin_lock_irq(phba->host->host_lock);
2148 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2149 spin_unlock_irq(phba->host->host_lock);
2150 if (rc == IOCB_ERROR) {
2151 lpfc_els_free_iocb(phba, elsiocb);
2158 lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2159 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2165 struct lpfc_iocbq *elsiocb;
2166 struct lpfc_sli_ring *pring;
2167 struct lpfc_sli *psli;
2173 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2175 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
2176 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp,
2177 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2181 /* Xmit PRLI ACC response tag <ulpIoTag> */
2182 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2183 "%d:0131 Xmit PRLI ACC response tag x%x "
2184 "Data: x%x x%x x%x x%x x%x\n",
2186 elsiocb->iocb.ulpIoTag,
2187 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2188 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2190 icmd = &elsiocb->iocb;
2191 oldcmd = &oldiocb->iocb;
2192 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2193 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2195 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2196 pcmd += sizeof (uint32_t);
2198 /* For PRLI, remainder of payload is PRLI parameter page */
2199 memset(pcmd, 0, sizeof (PRLI));
2201 npr = (PRLI *) pcmd;
2204 * If our firmware version is 3.20 or later,
2205 * set the following bits for FC-TAPE support.
2207 if (vpd->rev.feaLevelHigh >= 0x02) {
2208 npr->ConfmComplAllowed = 1;
2210 npr->TaskRetryIdReq = 1;
2213 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2214 npr->estabImagePair = 1;
2215 npr->readXferRdyDis = 1;
2216 npr->ConfmComplAllowed = 1;
2218 npr->prliType = PRLI_FCP_TYPE;
2219 npr->initiatorFunc = 1;
2221 phba->fc_stat.elsXmitACC++;
2222 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2224 spin_lock_irq(phba->host->host_lock);
2225 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2226 spin_unlock_irq(phba->host->host_lock);
2227 if (rc == IOCB_ERROR) {
2228 lpfc_els_free_iocb(phba, elsiocb);
2235 lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2237 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2242 struct lpfc_iocbq *elsiocb;
2243 struct lpfc_sli_ring *pring;
2244 struct lpfc_sli *psli;
2250 pring = &psli->ring[LPFC_ELS_RING];
2252 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2253 + (2 * sizeof (struct lpfc_name));
2255 cmdsize += sizeof (RNID_TOP_DISC);
2257 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2258 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2262 /* Xmit RNID ACC response tag <ulpIoTag> */
2263 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2264 "%d:0132 Xmit RNID ACC response tag x%x "
2267 elsiocb->iocb.ulpIoTag,
2268 elsiocb->iocb.ulpContext);
2270 icmd = &elsiocb->iocb;
2271 oldcmd = &oldiocb->iocb;
2272 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2273 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2275 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2276 pcmd += sizeof (uint32_t);
2278 memset(pcmd, 0, sizeof (RNID));
2279 rn = (RNID *) (pcmd);
2280 rn->Format = format;
2281 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2282 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2283 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2286 rn->SpecificLen = 0;
2288 case RNID_TOPOLOGY_DISC:
2289 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2290 memcpy(&rn->un.topologyDisc.portName,
2291 &phba->fc_portname, sizeof (struct lpfc_name));
2292 rn->un.topologyDisc.unitType = RNID_HBA;
2293 rn->un.topologyDisc.physPort = 0;
2294 rn->un.topologyDisc.attachedNodes = 0;
2298 rn->SpecificLen = 0;
2302 phba->fc_stat.elsXmitACC++;
2303 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2304 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2305 * it could be freed */
2307 spin_lock_irq(phba->host->host_lock);
2308 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2309 spin_unlock_irq(phba->host->host_lock);
2310 if (rc == IOCB_ERROR) {
2311 lpfc_els_free_iocb(phba, elsiocb);
2318 lpfc_els_disc_adisc(struct lpfc_hba * phba)
2321 struct lpfc_nodelist *ndlp, *next_ndlp;
2324 /* go thru NPR list and issue any remaining ELS ADISCs */
2325 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2327 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2328 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2329 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2330 ndlp->nlp_prev_state = ndlp->nlp_state;
2331 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
2332 lpfc_nlp_list(phba, ndlp,
2334 lpfc_issue_els_adisc(phba, ndlp, 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 (sentadisc == 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_disc_plogi(struct lpfc_hba * phba)
2359 struct lpfc_nodelist *ndlp, *next_ndlp;
2362 /* go thru NPR list and issue any remaining ELS PLOGIs */
2363 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2365 if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
2366 (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
2367 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2368 ndlp->nlp_prev_state = ndlp->nlp_state;
2369 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2370 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2371 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
2373 phba->num_disc_nodes++;
2374 if (phba->num_disc_nodes >=
2375 phba->cfg_discovery_threads) {
2376 spin_lock_irq(phba->host->host_lock);
2377 phba->fc_flag |= FC_NLP_MORE;
2378 spin_unlock_irq(phba->host->host_lock);
2384 if (sentplogi == 0) {
2385 spin_lock_irq(phba->host->host_lock);
2386 phba->fc_flag &= ~FC_NLP_MORE;
2387 spin_unlock_irq(phba->host->host_lock);
2393 lpfc_els_flush_rscn(struct lpfc_hba * phba)
2395 struct lpfc_dmabuf *mp;
2398 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2399 mp = phba->fc_rscn_id_list[i];
2400 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2402 phba->fc_rscn_id_list[i] = NULL;
2404 phba->fc_rscn_id_cnt = 0;
2405 spin_lock_irq(phba->host->host_lock);
2406 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2407 spin_unlock_irq(phba->host->host_lock);
2408 lpfc_can_disctmo(phba);
2413 lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2417 struct lpfc_dmabuf *mp;
2419 uint32_t payload_len, cmd, i, match;
2421 ns_did.un.word = did;
2424 /* Never match fabric nodes for RSCNs */
2425 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2428 /* If we are doing a FULL RSCN rediscovery, match everything */
2429 if (phba->fc_flag & FC_RSCN_DISCOVERY) {
2433 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2434 mp = phba->fc_rscn_id_list[i];
2435 lp = (uint32_t *) mp->virt;
2437 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2438 payload_len -= sizeof (uint32_t); /* take off word 0 */
2439 while (payload_len) {
2440 rscn_did.un.word = *lp++;
2441 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2442 payload_len -= sizeof (uint32_t);
2443 switch (rscn_did.un.b.resv) {
2444 case 0: /* Single N_Port ID effected */
2445 if (ns_did.un.word == rscn_did.un.word) {
2449 case 1: /* Whole N_Port Area effected */
2450 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2451 && (ns_did.un.b.area == rscn_did.un.b.area))
2456 case 2: /* Whole N_Port Domain effected */
2457 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2462 case 3: /* Whole Fabric effected */
2466 /* Unknown Identifier in RSCN list */
2467 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2468 "%d:0217 Unknown Identifier in "
2469 "RSCN payload Data: x%x\n",
2470 phba->brd_no, rscn_did.un.word);
2482 lpfc_rscn_recovery_check(struct lpfc_hba * phba)
2484 struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
2485 struct list_head *listp;
2486 struct list_head *node_list[7];
2489 /* Look at all nodes effected by pending RSCNs and move
2492 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
2493 node_list[1] = &phba->fc_nlpmap_list;
2494 node_list[2] = &phba->fc_nlpunmap_list;
2495 node_list[3] = &phba->fc_prli_list;
2496 node_list[4] = &phba->fc_reglogin_list;
2497 node_list[5] = &phba->fc_adisc_list;
2498 node_list[6] = &phba->fc_plogi_list;
2499 for (i = 0; i < 7; i++) {
2500 listp = node_list[i];
2501 if (list_empty(listp))
2504 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
2505 if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID)))
2508 lpfc_disc_state_machine(phba, ndlp, NULL,
2509 NLP_EVT_DEVICE_RECOVERY);
2511 /* Make sure NLP_DELAY_TMO is NOT running
2512 * after a device recovery event.
2514 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2515 lpfc_cancel_retry_delay_tmo(phba, ndlp);
2522 lpfc_els_rcv_rscn(struct lpfc_hba * phba,
2523 struct lpfc_iocbq * cmdiocb,
2524 struct lpfc_nodelist * ndlp, uint8_t newnode)
2526 struct lpfc_dmabuf *pcmd;
2529 uint32_t payload_len, cmd;
2532 icmd = &cmdiocb->iocb;
2533 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2534 lp = (uint32_t *) pcmd->virt;
2537 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2538 payload_len -= sizeof (uint32_t); /* take off word 0 */
2539 cmd &= ELS_CMD_MASK;
2542 lpfc_printf_log(phba,
2545 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2547 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2549 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2550 fc_host_post_event(phba->host, fc_get_event_number(),
2551 FCH_EVT_RSCN, lp[i]);
2553 /* If we are about to begin discovery, just ACC the RSCN.
2554 * Discovery processing will satisfy it.
2556 if (phba->hba_state <= LPFC_NS_QRY) {
2557 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2562 /* If we are already processing an RSCN, save the received
2563 * RSCN payload buffer, cmdiocb->context2 to process later.
2565 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2566 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2567 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
2568 spin_lock_irq(phba->host->host_lock);
2569 phba->fc_flag |= FC_RSCN_MODE;
2570 spin_unlock_irq(phba->host->host_lock);
2571 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2573 /* If we zero, cmdiocb->context2, the calling
2574 * routine will not try to free it.
2576 cmdiocb->context2 = NULL;
2579 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2580 "%d:0235 Deferred RSCN "
2581 "Data: x%x x%x x%x\n",
2582 phba->brd_no, phba->fc_rscn_id_cnt,
2583 phba->fc_flag, phba->hba_state);
2585 spin_lock_irq(phba->host->host_lock);
2586 phba->fc_flag |= FC_RSCN_DISCOVERY;
2587 spin_unlock_irq(phba->host->host_lock);
2588 /* ReDiscovery RSCN */
2589 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2590 "%d:0234 ReDiscovery RSCN "
2591 "Data: x%x x%x x%x\n",
2592 phba->brd_no, phba->fc_rscn_id_cnt,
2593 phba->fc_flag, phba->hba_state);
2596 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2599 /* send RECOVERY event for ALL nodes that match RSCN payload */
2600 lpfc_rscn_recovery_check(phba);
2604 phba->fc_flag |= FC_RSCN_MODE;
2605 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2607 * If we zero, cmdiocb->context2, the calling routine will
2608 * not try to free it.
2610 cmdiocb->context2 = NULL;
2612 lpfc_set_disctmo(phba);
2615 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2617 /* send RECOVERY event for ALL nodes that match RSCN payload */
2618 lpfc_rscn_recovery_check(phba);
2620 return lpfc_els_handle_rscn(phba);
2624 lpfc_els_handle_rscn(struct lpfc_hba * phba)
2626 struct lpfc_nodelist *ndlp;
2628 /* Start timer for RSCN processing */
2629 lpfc_set_disctmo(phba);
2631 /* RSCN processed */
2632 lpfc_printf_log(phba,
2635 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2637 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2640 /* To process RSCN, first compare RSCN data with NameServer */
2641 phba->fc_ns_retry = 0;
2642 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, NameServer_DID);
2644 /* Good ndlp, issue CT Request to NameServer */
2645 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2646 /* Wait for NameServer query cmpl before we can
2651 /* If login to NameServer does not exist, issue one */
2652 /* Good status, issue PLOGI to NameServer */
2653 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2655 /* Wait for NameServer login cmpl before we can
2659 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2661 lpfc_els_flush_rscn(phba);
2664 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2665 ndlp->nlp_type |= NLP_FABRIC;
2666 ndlp->nlp_prev_state = ndlp->nlp_state;
2667 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2668 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2669 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
2670 /* Wait for NameServer login cmpl before we can
2676 lpfc_els_flush_rscn(phba);
2681 lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2682 struct lpfc_iocbq * cmdiocb,
2683 struct lpfc_nodelist * ndlp, uint8_t newnode)
2685 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2686 uint32_t *lp = (uint32_t *) pcmd->virt;
2687 IOCB_t *icmd = &cmdiocb->iocb;
2688 struct serv_parm *sp;
2695 sp = (struct serv_parm *) lp;
2697 /* FLOGI received */
2699 lpfc_set_disctmo(phba);
2701 if (phba->fc_topology == TOPOLOGY_LOOP) {
2702 /* We should never receive a FLOGI in loop mode, ignore it */
2703 did = icmd->un.elsreq64.remoteID;
2705 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2707 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2708 "%d:0113 An FLOGI ELS command x%x was received "
2709 "from DID x%x in Loop Mode\n",
2710 phba->brd_no, cmd, did);
2716 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
2717 /* For a FLOGI we accept, then if our portname is greater
2718 * then the remote portname we initiate Nport login.
2721 rc = memcmp(&phba->fc_portname, &sp->portName,
2722 sizeof (struct lpfc_name));
2725 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
2726 GFP_KERNEL)) == 0) {
2729 lpfc_linkdown(phba);
2730 lpfc_init_link(phba, mbox,
2732 phba->cfg_link_speed);
2733 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2734 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2735 rc = lpfc_sli_issue_mbox
2736 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2737 if (rc == MBX_NOT_FINISHED) {
2738 mempool_free( mbox, phba->mbox_mem_pool);
2741 } else if (rc > 0) { /* greater than */
2742 spin_lock_irq(phba->host->host_lock);
2743 phba->fc_flag |= FC_PT2PT_PLOGI;
2744 spin_unlock_irq(phba->host->host_lock);
2746 phba->fc_flag |= FC_PT2PT;
2747 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2749 /* Reject this request because invalid parameters */
2750 stat.un.b.lsRjtRsvd0 = 0;
2751 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2752 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2753 stat.un.b.vendorUnique = 0;
2754 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2759 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2765 lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2766 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2768 struct lpfc_dmabuf *pcmd;
2775 icmd = &cmdiocb->iocb;
2776 did = icmd->un.elsreq64.remoteID;
2777 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2778 lp = (uint32_t *) pcmd->virt;
2785 switch (rn->Format) {
2787 case RNID_TOPOLOGY_DISC:
2789 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
2792 /* Reject this request because format not supported */
2793 stat.un.b.lsRjtRsvd0 = 0;
2794 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2795 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2796 stat.un.b.vendorUnique = 0;
2797 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2803 lpfc_els_rcv_lirr(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2804 struct lpfc_nodelist * ndlp)
2808 /* For now, unconditionally reject this command */
2809 stat.un.b.lsRjtRsvd0 = 0;
2810 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2811 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2812 stat.un.b.vendorUnique = 0;
2813 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2818 lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2820 struct lpfc_sli *psli;
2821 struct lpfc_sli_ring *pring;
2826 struct lpfc_iocbq *elsiocb;
2827 struct lpfc_nodelist *ndlp;
2828 uint16_t xri, status;
2832 pring = &psli->ring[LPFC_ELS_RING];
2835 ndlp = (struct lpfc_nodelist *) pmb->context2;
2836 xri = (uint16_t) ((unsigned long)(pmb->context1));
2837 pmb->context1 = NULL;
2838 pmb->context2 = NULL;
2840 if (mb->mbxStatus) {
2841 mempool_free( pmb, phba->mbox_mem_pool);
2845 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
2846 mempool_free( pmb, phba->mbox_mem_pool);
2847 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp,
2848 ndlp->nlp_DID, ELS_CMD_ACC);
2852 icmd = &elsiocb->iocb;
2853 icmd->ulpContext = xri;
2855 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2856 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2857 pcmd += sizeof (uint32_t); /* Skip past command */
2858 rps_rsp = (RPS_RSP *)pcmd;
2860 if (phba->fc_topology != TOPOLOGY_LOOP)
2864 if (phba->fc_flag & FC_FABRIC)
2868 rps_rsp->portStatus = be16_to_cpu(status);
2869 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
2870 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
2871 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
2872 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
2873 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
2874 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
2876 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2877 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2878 "%d:0118 Xmit ELS RPS ACC response tag x%x "
2879 "Data: x%x x%x x%x x%x x%x\n",
2881 elsiocb->iocb.ulpIoTag,
2882 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2883 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2885 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2886 phba->fc_stat.elsXmitACC++;
2887 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2888 lpfc_els_free_iocb(phba, elsiocb);
2894 lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2895 struct lpfc_nodelist * ndlp)
2900 struct lpfc_dmabuf *pcmd;
2904 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2905 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
2906 stat.un.b.lsRjtRsvd0 = 0;
2907 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2908 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2909 stat.un.b.vendorUnique = 0;
2910 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2913 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2914 lp = (uint32_t *) pcmd->virt;
2915 flag = (be32_to_cpu(*lp++) & 0xf);
2919 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2920 ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname,
2921 sizeof (struct lpfc_name)) == 0))) {
2922 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
2923 lpfc_read_lnk_stat(phba, mbox);
2925 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
2926 mbox->context2 = ndlp;
2927 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2928 if (lpfc_sli_issue_mbox (phba, mbox,
2929 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) {
2930 /* Mbox completion will send ELS Response */
2933 mempool_free(mbox, phba->mbox_mem_pool);
2936 stat.un.b.lsRjtRsvd0 = 0;
2937 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2938 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2939 stat.un.b.vendorUnique = 0;
2940 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2945 lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2946 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2951 struct lpfc_iocbq *elsiocb;
2952 struct lpfc_sli_ring *pring;
2953 struct lpfc_sli *psli;
2957 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2959 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2960 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2964 icmd = &elsiocb->iocb;
2965 oldcmd = &oldiocb->iocb;
2966 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2968 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2969 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2970 pcmd += sizeof (uint16_t);
2971 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2972 pcmd += sizeof(uint16_t);
2974 /* Setup the RPL ACC payload */
2975 rpl_rsp.listLen = be32_to_cpu(1);
2977 rpl_rsp.port_num_blk.portNum = 0;
2978 rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID);
2979 memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname,
2980 sizeof(struct lpfc_name));
2982 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
2985 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2986 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2987 "%d:0120 Xmit ELS RPL ACC response tag x%x "
2988 "Data: x%x x%x x%x x%x x%x\n",
2990 elsiocb->iocb.ulpIoTag,
2991 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2992 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2994 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2996 phba->fc_stat.elsXmitACC++;
2997 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2998 lpfc_els_free_iocb(phba, elsiocb);
3005 lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3006 struct lpfc_nodelist * ndlp)
3008 struct lpfc_dmabuf *pcmd;
3015 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3016 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
3017 stat.un.b.lsRjtRsvd0 = 0;
3018 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3019 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3020 stat.un.b.vendorUnique = 0;
3021 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
3024 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3025 lp = (uint32_t *) pcmd->virt;
3026 rpl = (RPL *) (lp + 1);
3028 maxsize = be32_to_cpu(rpl->maxsize);
3030 /* We support only one port */
3031 if ((rpl->index == 0) &&
3033 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3034 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
3036 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3038 lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp);
3044 lpfc_els_rcv_farp(struct lpfc_hba * phba,
3045 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3047 struct lpfc_dmabuf *pcmd;
3051 uint32_t cmd, cnt, did;
3053 icmd = &cmdiocb->iocb;
3054 did = icmd->un.elsreq64.remoteID;
3055 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3056 lp = (uint32_t *) pcmd->virt;
3061 /* FARP-REQ received from DID <did> */
3062 lpfc_printf_log(phba,
3065 "%d:0601 FARP-REQ received from DID x%x\n",
3068 /* We will only support match on WWPN or WWNN */
3069 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
3074 /* If this FARP command is searching for my portname */
3075 if (fp->Mflags & FARP_MATCH_PORT) {
3076 if (memcmp(&fp->RportName, &phba->fc_portname,
3077 sizeof (struct lpfc_name)) == 0)
3081 /* If this FARP command is searching for my nodename */
3082 if (fp->Mflags & FARP_MATCH_NODE) {
3083 if (memcmp(&fp->RnodeName, &phba->fc_nodename,
3084 sizeof (struct lpfc_name)) == 0)
3089 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3090 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3091 /* Log back into the node before sending the FARP. */
3092 if (fp->Rflags & FARP_REQUEST_PLOGI) {
3093 ndlp->nlp_prev_state = ndlp->nlp_state;
3094 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
3095 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
3096 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
3099 /* Send a FARP response to that node */
3100 if (fp->Rflags & FARP_REQUEST_FARPR) {
3101 lpfc_issue_els_farpr(phba, did, 0);
3109 lpfc_els_rcv_farpr(struct lpfc_hba * phba,
3110 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3112 struct lpfc_dmabuf *pcmd;
3117 icmd = &cmdiocb->iocb;
3118 did = icmd->un.elsreq64.remoteID;
3119 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3120 lp = (uint32_t *) pcmd->virt;
3123 /* FARP-RSP received from DID <did> */
3124 lpfc_printf_log(phba,
3127 "%d:0600 FARP-RSP received from DID x%x\n",
3130 /* ACCEPT the Farp resp request */
3131 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
3137 lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3138 struct lpfc_nodelist * fan_ndlp)
3140 struct lpfc_dmabuf *pcmd;
3145 struct lpfc_nodelist *ndlp, *next_ndlp;
3148 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:0265 FAN received\n",
3151 icmd = &cmdiocb->iocb;
3152 did = icmd->un.elsreq64.remoteID;
3153 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3154 lp = (uint32_t *)pcmd->virt;
3159 /* FAN received; Fan does not have a reply sequence */
3161 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
3162 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3163 sizeof(struct lpfc_name)) != 0) ||
3164 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3165 sizeof(struct lpfc_name)) != 0)) {
3167 * This node has switched fabrics. FLOGI is required
3168 * Clean up the old rpi's
3171 list_for_each_entry_safe(ndlp, next_ndlp,
3172 &phba->fc_npr_list, nlp_listp) {
3174 if (ndlp->nlp_type & NLP_FABRIC) {
3176 * Clean up old Fabric, Nameserver and
3177 * other NLP_FABRIC logins
3179 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3180 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3181 /* Fail outstanding I/O now since this
3182 * device is marked for PLOGI
3184 lpfc_unreg_rpi(phba, ndlp);
3188 phba->hba_state = LPFC_FLOGI;
3189 lpfc_set_disctmo(phba);
3190 lpfc_initial_flogi(phba);
3193 /* Discovery not needed,
3194 * move the nodes to their original state.
3196 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
3199 switch (ndlp->nlp_prev_state) {
3200 case NLP_STE_UNMAPPED_NODE:
3201 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3202 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
3203 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
3206 case NLP_STE_MAPPED_NODE:
3207 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3208 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
3209 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
3217 /* Start discovery - this should just do CLEAR_LA */
3218 lpfc_disc_start(phba);
3224 lpfc_els_timeout(unsigned long ptr)
3226 struct lpfc_hba *phba;
3227 unsigned long iflag;
3229 phba = (struct lpfc_hba *)ptr;
3232 spin_lock_irqsave(phba->host->host_lock, iflag);
3233 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3234 phba->work_hba_events |= WORKER_ELS_TMO;
3235 if (phba->work_wait)
3236 wake_up(phba->work_wait);
3238 spin_unlock_irqrestore(phba->host->host_lock, iflag);
3243 lpfc_els_timeout_handler(struct lpfc_hba *phba)
3245 struct lpfc_sli_ring *pring;
3246 struct lpfc_iocbq *tmp_iocb, *piocb;
3248 struct lpfc_dmabuf *pcmd;
3249 struct list_head *dlp;
3251 uint32_t els_command;
3257 spin_lock_irq(phba->host->host_lock);
3258 /* If the timer is already canceled do nothing */
3259 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3260 spin_unlock_irq(phba->host->host_lock);
3263 timeout = (uint32_t)(phba->fc_ratov << 1);
3265 pring = &phba->sli.ring[LPFC_ELS_RING];
3266 dlp = &pring->txcmplq;
3268 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3271 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3274 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3275 elscmd = (uint32_t *) (pcmd->virt);
3276 els_command = *elscmd;
3278 if ((els_command == ELS_CMD_FARP)
3279 || (els_command == ELS_CMD_FARPR)) {
3283 if (piocb->drvrTimeout > 0) {
3284 if (piocb->drvrTimeout >= timeout) {
3285 piocb->drvrTimeout -= timeout;
3287 piocb->drvrTimeout = 0;
3292 list_del(&piocb->list);
3293 pring->txcmplq_cnt--;
3295 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3296 struct lpfc_nodelist *ndlp;
3297 spin_unlock_irq(phba->host->host_lock);
3298 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
3299 spin_lock_irq(phba->host->host_lock);
3300 remote_ID = ndlp->nlp_DID;
3301 if (cmd->un.elsreq64.bdl.ulpIoTag32) {
3302 lpfc_sli_issue_abort_iotag32(phba,
3306 remote_ID = cmd->un.elsreq64.remoteID;
3309 lpfc_printf_log(phba,
3312 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
3313 phba->brd_no, els_command,
3314 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3317 * The iocb has timed out; abort it.
3319 if (piocb->iocb_cmpl) {
3320 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3321 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3322 spin_unlock_irq(phba->host->host_lock);
3323 (piocb->iocb_cmpl) (phba, piocb, piocb);
3324 spin_lock_irq(phba->host->host_lock);
3326 lpfc_sli_release_iocbq(phba, piocb);
3328 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3329 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
3331 spin_unlock_irq(phba->host->host_lock);
3335 lpfc_els_flush_cmd(struct lpfc_hba * phba)
3337 struct lpfc_sli_ring *pring;
3338 struct lpfc_iocbq *tmp_iocb, *piocb;
3340 struct lpfc_dmabuf *pcmd;
3342 uint32_t els_command;
3344 pring = &phba->sli.ring[LPFC_ELS_RING];
3345 spin_lock_irq(phba->host->host_lock);
3346 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3349 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3353 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3354 if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
3355 (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
3356 (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
3357 (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
3361 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3362 elscmd = (uint32_t *) (pcmd->virt);
3363 els_command = *elscmd;
3365 list_del(&piocb->list);
3366 pring->txcmplq_cnt--;
3368 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3369 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3371 if (piocb->iocb_cmpl) {
3372 spin_unlock_irq(phba->host->host_lock);
3373 (piocb->iocb_cmpl) (phba, piocb, piocb);
3374 spin_lock_irq(phba->host->host_lock);
3376 lpfc_sli_release_iocbq(phba, piocb);
3379 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3382 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3385 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3386 elscmd = (uint32_t *) (pcmd->virt);
3387 els_command = *elscmd;
3389 list_del(&piocb->list);
3390 pring->txcmplq_cnt--;
3392 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3393 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3395 if (piocb->iocb_cmpl) {
3396 spin_unlock_irq(phba->host->host_lock);
3397 (piocb->iocb_cmpl) (phba, piocb, piocb);
3398 spin_lock_irq(phba->host->host_lock);
3400 lpfc_sli_release_iocbq(phba, piocb);
3402 spin_unlock_irq(phba->host->host_lock);
3407 lpfc_els_unsol_event(struct lpfc_hba * phba,
3408 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
3410 struct lpfc_sli *psli;
3411 struct lpfc_nodelist *ndlp;
3412 struct lpfc_dmabuf *mp;
3419 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3420 uint32_t rjt_err = 0;
3423 icmd = &elsiocb->iocb;
3425 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3426 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3427 /* Not enough posted buffers; Try posting more buffers */
3428 phba->fc_stat.NoRcvBuf++;
3429 lpfc_post_buffer(phba, pring, 0, 1);
3433 /* If there are no BDEs associated with this IOCB,
3434 * there is nothing to do.
3436 if (icmd->ulpBdeCount == 0)
3439 /* type of ELS cmd is first 32bit word in packet */
3440 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3444 cont64[0].addrLow));
3451 lp = (uint32_t *) mp->virt;
3453 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3455 if (icmd->ulpStatus) {
3456 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3462 /* Check to see if link went down during discovery */
3463 if (lpfc_els_chk_latt(phba)) {
3464 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3470 did = icmd->un.rcvels.remoteID;
3471 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
3473 /* Cannot find existing Fabric ndlp, so allocate a new one */
3474 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3476 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3482 lpfc_nlp_init(phba, ndlp, did);
3484 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3485 ndlp->nlp_type |= NLP_FABRIC;
3487 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
3488 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
3491 phba->fc_stat.elsRcvFrame++;
3492 elsiocb->context1 = ndlp;
3493 elsiocb->context2 = mp;
3495 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3496 cmd &= ELS_CMD_MASK;
3498 /* ELS command <elsCmd> received from NPORT <did> */
3499 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3500 "%d:0112 ELS command x%x received from NPORT x%x "
3501 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
3505 phba->fc_stat.elsRcvPLOGI++;
3506 if (phba->hba_state < LPFC_DISC_AUTH) {
3510 ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp);
3511 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3514 phba->fc_stat.elsRcvFLOGI++;
3515 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3517 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3521 phba->fc_stat.elsRcvLOGO++;
3522 if (phba->hba_state < LPFC_DISC_AUTH) {
3526 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3529 phba->fc_stat.elsRcvPRLO++;
3530 if (phba->hba_state < LPFC_DISC_AUTH) {
3534 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3537 phba->fc_stat.elsRcvRSCN++;
3538 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3540 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3544 phba->fc_stat.elsRcvADISC++;
3545 if (phba->hba_state < LPFC_DISC_AUTH) {
3549 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
3552 phba->fc_stat.elsRcvPDISC++;
3553 if (phba->hba_state < LPFC_DISC_AUTH) {
3557 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
3560 phba->fc_stat.elsRcvFARPR++;
3561 lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
3564 phba->fc_stat.elsRcvFARP++;
3565 lpfc_els_rcv_farp(phba, elsiocb, ndlp);
3568 phba->fc_stat.elsRcvFAN++;
3569 lpfc_els_rcv_fan(phba, elsiocb, ndlp);
3572 phba->fc_stat.elsRcvPRLI++;
3573 if (phba->hba_state < LPFC_DISC_AUTH) {
3577 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3580 phba->fc_stat.elsRcvLIRR++;
3581 lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
3583 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3587 phba->fc_stat.elsRcvRPS++;
3588 lpfc_els_rcv_rps(phba, elsiocb, ndlp);
3590 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3594 phba->fc_stat.elsRcvRPL++;
3595 lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
3597 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3601 phba->fc_stat.elsRcvRNID++;
3602 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
3604 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3608 /* Unsupported ELS command, reject */
3611 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3612 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3613 "%d:0115 Unknown ELS command x%x received from "
3614 "NPORT x%x\n", phba->brd_no, cmd, did);
3616 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
3621 /* check if need to LS_RJT received ELS cmd */
3623 stat.un.b.lsRjtRsvd0 = 0;
3624 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3625 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
3626 stat.un.b.vendorUnique = 0;
3627 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3630 if (elsiocb->context2) {
3631 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3635 /* check if need to drop received ELS cmd */
3636 if (drop_cmd == 1) {
3637 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3638 "%d:0111 Dropping received ELS cmd "
3639 "Data: x%x x%x x%x\n", phba->brd_no,
3640 icmd->ulpStatus, icmd->un.ulpWord[4],
3642 phba->fc_stat.elsRcvDrop++;